@@ -43,9 +43,8 @@ use spl_associated_token_account::{
43
43
} ;
44
44
use spl_token_2022:: {
45
45
extension:: {
46
- interest_bearing_mint, interest_bearing_mint:: InterestBearingConfig ,
47
- memo_transfer:: MemoTransfer , mint_close_authority:: MintCloseAuthority , ExtensionType ,
48
- StateWithExtensionsOwned ,
46
+ interest_bearing_mint:: InterestBearingConfig , memo_transfer:: MemoTransfer ,
47
+ mint_close_authority:: MintCloseAuthority , ExtensionType , StateWithExtensionsOwned ,
49
48
} ,
50
49
instruction:: * ,
51
50
state:: { Account , Mint , Multisig } ,
@@ -450,6 +449,8 @@ async fn command_set_interest_rate(
450
449
rate_bps : i16 ,
451
450
bulk_signers : Vec < Arc < dyn Signer > > ,
452
451
) -> CommandResult {
452
+ let token = token_client_from_config ( config, & token_pubkey) ;
453
+
453
454
if !config. sign_only {
454
455
let mint_account = config. get_account_checked ( & token_pubkey) . await ?;
455
456
@@ -484,25 +485,11 @@ async fn command_set_interest_rate(
484
485
) ,
485
486
) ;
486
487
487
- let instructions = vec ! [ interest_bearing_mint:: instruction:: update_rate(
488
- & config. program_id,
489
- & token_pubkey,
490
- & rate_authority,
491
- & [ & rate_authority] ,
492
- rate_bps,
493
- ) ?] ;
494
-
495
- let tx_return = handle_tx (
496
- & CliSignerInfo {
497
- signers : bulk_signers,
498
- } ,
499
- config,
500
- false ,
501
- 0 ,
502
- instructions,
503
- )
504
- . await ?;
488
+ let res = token
489
+ . update_interest_rate ( & rate_authority, rate_bps, & bulk_signers)
490
+ . await ?;
505
491
492
+ let tx_return = finish_tx ( config, & res, false ) . await ?;
506
493
Ok ( match tx_return {
507
494
TransactionReturnData :: CliSignature ( signature) => {
508
495
config. output_format . formatted_string ( & signature)
@@ -1871,11 +1858,14 @@ async fn command_required_transfer_memos(
1871
1858
if config. sign_only {
1872
1859
panic ! ( "Config can not be sign only for enabling/disabling required transfer memos." ) ;
1873
1860
}
1861
+
1874
1862
let account = config. get_account_checked ( & token_account_address) . await ?;
1875
- let mut instructions: Vec < Instruction > = Vec :: new ( ) ;
1876
- // Reallocation (if needed)
1877
1863
let current_account_len = account. data . len ( ) ;
1864
+
1878
1865
let state_with_extension = StateWithExtensionsOwned :: < Account > :: unpack ( account. data ) ?;
1866
+ let token = token_client_from_config ( config, & state_with_extension. base . mint ) ;
1867
+
1868
+ // Reallocation (if needed)
1879
1869
let mut existing_extensions: Vec < ExtensionType > = state_with_extension. get_extension_types ( ) ?;
1880
1870
if existing_extensions. contains ( & ExtensionType :: MemoTransfer ) {
1881
1871
let extension_data: bool = state_with_extension
@@ -1896,45 +1886,28 @@ async fn command_required_transfer_memos(
1896
1886
existing_extensions. push ( ExtensionType :: MemoTransfer ) ;
1897
1887
let needed_account_len = ExtensionType :: get_account_len :: < Account > ( & existing_extensions) ;
1898
1888
if needed_account_len > current_account_len {
1899
- instructions . push ( reallocate (
1900
- & config . program_id ,
1901
- & token_account_address,
1902
- & config . fee_payer . pubkey ( ) ,
1903
- & owner ,
1904
- & config . multisigner_pubkeys ,
1905
- & existing_extensions ,
1906
- ) ? ) ;
1889
+ token
1890
+ . reallocate (
1891
+ & token_account_address,
1892
+ & owner ,
1893
+ & [ ExtensionType :: MemoTransfer ] ,
1894
+ & bulk_signers ,
1895
+ )
1896
+ . await ? ;
1907
1897
}
1908
1898
}
1909
- if enable_memos {
1910
- instructions. push (
1911
- spl_token_2022:: extension:: memo_transfer:: instruction:: enable_required_transfer_memos (
1912
- & config. program_id ,
1913
- & token_account_address,
1914
- & owner,
1915
- & config. multisigner_pubkeys ,
1916
- ) ?,
1917
- ) ;
1899
+
1900
+ let res = if enable_memos {
1901
+ token
1902
+ . enable_required_transfer_memos ( & token_account_address, & owner, & bulk_signers)
1903
+ . await
1918
1904
} else {
1919
- instructions. push (
1920
- spl_token_2022:: extension:: memo_transfer:: instruction:: disable_required_transfer_memos (
1921
- & config. program_id ,
1922
- & token_account_address,
1923
- & owner,
1924
- & config. multisigner_pubkeys ,
1925
- ) ?,
1926
- ) ;
1927
- }
1928
- let tx_return = handle_tx (
1929
- & CliSignerInfo {
1930
- signers : bulk_signers,
1931
- } ,
1932
- config,
1933
- false ,
1934
- 0 ,
1935
- instructions,
1936
- )
1937
- . await ?;
1905
+ token
1906
+ . disable_required_transfer_memos ( & token_account_address, & owner, & bulk_signers)
1907
+ . await
1908
+ } ?;
1909
+
1910
+ let tx_return = finish_tx ( config, & res, false ) . await ?;
1938
1911
Ok ( match tx_return {
1939
1912
TransactionReturnData :: CliSignature ( signature) => {
1940
1913
config. output_format . formatted_string ( & signature)
@@ -2929,7 +2902,6 @@ fn app<'a, 'b>(
2929
2902
)
2930
2903
. arg ( multisig_signer_arg ( ) )
2931
2904
. nonce_args ( true )
2932
- . offline_args ( )
2933
2905
)
2934
2906
. subcommand (
2935
2907
SubCommand :: with_name ( CommandName :: DisableRequiredTransferMemos . into ( ) )
@@ -2948,7 +2920,6 @@ fn app<'a, 'b>(
2948
2920
)
2949
2921
. arg ( multisig_signer_arg ( ) )
2950
2922
. nonce_args ( true )
2951
- . offline_args ( )
2952
2923
)
2953
2924
}
2954
2925
@@ -3933,7 +3904,7 @@ mod tests {
3933
3904
let mint_account =
3934
3905
StateWithExtensionsOwned :: < spl_token_2022:: state:: Mint > :: unpack ( account. data ) . unwrap ( ) ;
3935
3906
let extension = mint_account
3936
- . get_extension :: < interest_bearing_mint :: InterestBearingConfig > ( )
3907
+ . get_extension :: < InterestBearingConfig > ( )
3937
3908
. unwrap ( ) ;
3938
3909
assert_eq ! ( account. owner, spl_token_2022:: id( ) ) ;
3939
3910
assert_eq ! ( i16 :: from( extension. current_rate) , rate_bps) ;
@@ -3955,7 +3926,7 @@ mod tests {
3955
3926
let mint_account =
3956
3927
StateWithExtensionsOwned :: < spl_token_2022:: state:: Mint > :: unpack ( account. data ) . unwrap ( ) ;
3957
3928
let extension = mint_account
3958
- . get_extension :: < interest_bearing_mint :: InterestBearingConfig > ( )
3929
+ . get_extension :: < InterestBearingConfig > ( )
3959
3930
. unwrap ( ) ;
3960
3931
assert_eq ! ( account. owner, spl_token_2022:: id( ) ) ;
3961
3932
assert_eq ! ( i16 :: from( extension. current_rate) , initial_rate) ;
@@ -3976,7 +3947,7 @@ mod tests {
3976
3947
let mint_account =
3977
3948
StateWithExtensionsOwned :: < spl_token_2022:: state:: Mint > :: unpack ( account. data ) . unwrap ( ) ;
3978
3949
let extension = mint_account
3979
- . get_extension :: < interest_bearing_mint :: InterestBearingConfig > ( )
3950
+ . get_extension :: < InterestBearingConfig > ( )
3980
3951
. unwrap ( ) ;
3981
3952
assert_eq ! ( i16 :: from( extension. current_rate) , new_rate) ;
3982
3953
}
0 commit comments