Skip to content

Commit 4b4bbd4

Browse files
committed
autouse 9ruq as fee receiver when creating reserve
1 parent dc26dd7 commit 4b4bbd4

File tree

1 file changed

+47
-29
lines changed

1 file changed

+47
-29
lines changed

token-lending/cli/src/main.rs

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use solana_client::rpc_config::{RpcProgramAccountsConfig, RpcSendTransactionConf
66
use solana_client::{rpc_config::RpcAccountInfoConfig, rpc_filter::RpcFilterType};
77
use solana_sdk::bs58;
88
use solana_sdk::instruction::Instruction;
9+
use solana_sdk::pubkey;
910
use solana_sdk::{commitment_config::CommitmentLevel, compute_budget::ComputeBudgetInstruction};
1011
use solend_program::{
1112
instruction::set_lending_market_owner_and_config,
@@ -1237,7 +1238,6 @@ fn main() {
12371238
let borrow_fee_wad = (borrow_fee * WAD as f64) as u64;
12381239
let flash_loan_fee_wad = (flash_loan_fee * WAD as f64) as u64;
12391240

1240-
let liquidity_fee_receiver_keypair = Keypair::new();
12411241
let protocol_liquidation_fee =
12421242
value_of(arg_matches, "protocol_liquidation_fee").unwrap();
12431243
let protocol_take_rate = value_of(arg_matches, "protocol_take_rate").unwrap();
@@ -1254,6 +1254,11 @@ fn main() {
12541254
.unwrap();
12551255
let source_liquidity_mint =
12561256
Mint::unpack_from_slice(source_liquidity_mint_account.data.borrow()).unwrap();
1257+
let fee_receiver = get_or_create_associated_token_address_for_pubkey(
1258+
&pubkey!("9RuqAN42PTUi9ya59k9suGATrkqzvb9gk2QABJtQzGP5"),
1259+
&config,
1260+
&source_liquidity.mint,
1261+
);
12571262

12581263
let liquidity_amount = ui_amount_to_amount(ui_amount, source_liquidity_mint.decimals);
12591264
let deposit_limit = ui_amount_to_amount(deposit_limit, source_liquidity_mint.decimals);
@@ -1281,7 +1286,7 @@ fn main() {
12811286
},
12821287
deposit_limit,
12831288
borrow_limit,
1284-
fee_receiver: liquidity_fee_receiver_keypair.pubkey(),
1289+
fee_receiver,
12851290
protocol_liquidation_fee,
12861291
protocol_take_rate,
12871292
added_borrow_weight_bps,
@@ -1298,7 +1303,6 @@ fn main() {
12981303
pyth_product_pubkey,
12991304
pyth_price_pubkey,
13001305
switchboard_feed_pubkey,
1301-
liquidity_fee_receiver_keypair,
13021306
source_liquidity,
13031307
)
13041308
}
@@ -1719,7 +1723,6 @@ fn command_add_reserve(
17191723
pyth_product_pubkey: Pubkey,
17201724
pyth_price_pubkey: Pubkey,
17211725
switchboard_feed_pubkey: Pubkey,
1722-
liquidity_fee_receiver_keypair: Keypair,
17231726
source_liquidity: Token,
17241727
) -> CommandResult {
17251728
let reserve_keypair = Keypair::new();
@@ -1743,10 +1746,6 @@ fn command_add_reserve(
17431746
"Adding liquidity supply {}",
17441747
liquidity_supply_keypair.pubkey()
17451748
);
1746-
println!(
1747-
"Adding liquidity fee receiver {}",
1748-
liquidity_fee_receiver_keypair.pubkey()
1749-
);
17501749
println!(
17511750
"Adding user collateral {}",
17521751
user_collateral_keypair.pubkey()
@@ -1815,22 +1814,13 @@ fn command_add_reserve(
18151814
);
18161815

18171816
let message_2 = Message::new_with_blockhash(
1818-
&[
1819-
create_account(
1820-
&config.fee_payer.pubkey(),
1821-
&liquidity_supply_keypair.pubkey(),
1822-
liquidity_supply_balance,
1823-
Token::LEN as u64,
1824-
&spl_token::id(),
1825-
),
1826-
create_account(
1827-
&config.fee_payer.pubkey(),
1828-
&liquidity_fee_receiver_keypair.pubkey(),
1829-
liquidity_fee_receiver_balance,
1830-
Token::LEN as u64,
1831-
&spl_token::id(),
1832-
),
1833-
],
1817+
&[create_account(
1818+
&config.fee_payer.pubkey(),
1819+
&liquidity_supply_keypair.pubkey(),
1820+
liquidity_supply_balance,
1821+
Token::LEN as u64,
1822+
&spl_token::id(),
1823+
)],
18341824
Some(&config.fee_payer.pubkey()),
18351825
&recent_blockhash,
18361826
);
@@ -1899,11 +1889,7 @@ fn command_add_reserve(
18991889
);
19001890
// send_transaction(config, transaction_1)?;
19011891
let transaction_2 = Transaction::new(
1902-
&vec![
1903-
config.fee_payer.as_ref(),
1904-
&liquidity_supply_keypair,
1905-
&liquidity_fee_receiver_keypair,
1906-
],
1892+
&vec![config.fee_payer.as_ref(), &liquidity_supply_keypair],
19071893
message_2,
19081894
recent_blockhash,
19091895
);
@@ -2636,3 +2622,35 @@ fn get_or_create_associated_token_address(config: &Config, mint: &Pubkey) -> Pub
26362622

26372623
ata
26382624
}
2625+
2626+
fn get_or_create_associated_token_address_for_pubkey(
2627+
pubkey: &Pubkey,
2628+
config: &Config,
2629+
mint: &Pubkey,
2630+
) -> Pubkey {
2631+
let ata = get_associated_token_address(pubkey, mint);
2632+
2633+
if config.rpc_client.get_account(&ata).is_err() {
2634+
println!("Creating ATA for mint {:?}", mint);
2635+
2636+
let recent_blockhash = config.rpc_client.get_latest_blockhash().unwrap();
2637+
let transaction = Transaction::new(
2638+
&vec![config.fee_payer.as_ref()],
2639+
Message::new_with_blockhash(
2640+
&[create_associated_token_account(
2641+
&config.fee_payer.pubkey(),
2642+
pubkey,
2643+
mint,
2644+
&spl_associated_token_account::id(),
2645+
)],
2646+
Some(&config.fee_payer.pubkey()),
2647+
&recent_blockhash,
2648+
),
2649+
recent_blockhash,
2650+
);
2651+
2652+
send_transaction(config, transaction).unwrap();
2653+
}
2654+
2655+
ata
2656+
}

0 commit comments

Comments
 (0)