Skip to content

Commit 61a12e1

Browse files
committed
Generalize token program id
1 parent 6e900ae commit 61a12e1

File tree

3 files changed

+59
-29
lines changed

3 files changed

+59
-29
lines changed

src/bin/sys-lend.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,10 @@ async fn build_instructions_for_ops(
453453
&address,
454454
&address,
455455
&token.mint(),
456-
&spl_token::id(),
456+
&token.program_id(),
457457
),
458458
system_instruction::transfer(&address, &token.ata(&address), amount),
459-
spl_token::instruction::sync_native(&spl_token::id(), &token.ata(&address)).unwrap(),
459+
spl_token::instruction::sync_native(&token.program_id(), &token.ata(&address)).unwrap(),
460460
]);
461461
required_compute_units += 20_000;
462462
}
@@ -468,7 +468,7 @@ async fn build_instructions_for_ops(
468468
&address,
469469
&address,
470470
&token.mint(),
471-
&spl_token::id(),
471+
&token.program_id(),
472472
),
473473
);
474474
required_compute_units += 25_000;
@@ -487,7 +487,7 @@ async fn build_instructions_for_ops(
487487

488488
let seed = &Keypair::new().pubkey().to_string()[..31];
489489
let ephemeral_token_account =
490-
Pubkey::create_with_seed(&address, seed, &spl_token::id()).unwrap();
490+
Pubkey::create_with_seed(&address, seed, &token.program_id()).unwrap();
491491

492492
instructions.extend(vec![
493493
system_instruction::create_account_with_seed(
@@ -497,17 +497,17 @@ async fn build_instructions_for_ops(
497497
seed,
498498
TOKEN_ACCOUNT_REQUIRED_LAMPORTS,
499499
spl_token::state::Account::LEN as u64,
500-
&spl_token::id(),
500+
&token.program_id(),
501501
),
502502
spl_token::instruction::initialize_account(
503-
&spl_token::id(),
503+
&token.program_id(),
504504
&ephemeral_token_account,
505505
&token.mint(),
506506
&address,
507507
)
508508
.unwrap(),
509509
spl_token::instruction::transfer_checked(
510-
&spl_token::id(),
510+
&token.program_id(),
511511
&token.ata(&address),
512512
&token.mint(),
513513
&ephemeral_token_account,
@@ -518,7 +518,7 @@ async fn build_instructions_for_ops(
518518
)
519519
.unwrap(),
520520
spl_token::instruction::close_account(
521-
&spl_token::id(),
521+
&token.program_id(),
522522
&ephemeral_token_account,
523523
&address,
524524
&address,
@@ -1894,7 +1894,7 @@ async fn mfi_deposit_or_withdraw(
18941894
// Bank Liquidity Vault
18951895
AccountMeta::new(bank.liquidity_vault, false),
18961896
// Token Program
1897-
AccountMeta::new_readonly(spl_token::id(), false),
1897+
AccountMeta::new_readonly(token.program_id(), false),
18981898
],
18991899
);
19001900

@@ -1941,7 +1941,7 @@ async fn mfi_deposit_or_withdraw(
19411941
// Bank Liquidity Vault
19421942
AccountMeta::new(bank.liquidity_vault, false),
19431943
// Token Program
1944-
AccountMeta::new_readonly(spl_token::id(), false),
1944+
AccountMeta::new_readonly(token.program_id(), false),
19451945
];
19461946

19471947
for balance in &user_account.lending_account.balances {
@@ -1961,7 +1961,7 @@ async fn mfi_deposit_or_withdraw(
19611961
&wallet_address,
19621962
&wallet_address,
19631963
&bank.mint,
1964-
&spl_token::id(),
1964+
&token.program_id(),
19651965
),
19661966

19671967
Instruction::new_with_bytes(
@@ -2407,9 +2407,9 @@ fn kamino_deposit_or_withdraw(
24072407
// User Destination Collateral
24082408
AccountMeta::new_readonly(KAMINO_LEND_PROGRAM, false),
24092409
// Token Program
2410-
AccountMeta::new_readonly(spl_token::id(), false),
2410+
AccountMeta::new_readonly(token.program_id(), false),
24112411
// Token Program
2412-
AccountMeta::new_readonly(spl_token::id(), false),
2412+
AccountMeta::new_readonly(token.program_id(), false),
24132413
// Sysvar: Instructions
24142414
AccountMeta::new_readonly(sysvar::instructions::ID, false),
24152415
],
@@ -2458,9 +2458,9 @@ fn kamino_deposit_or_withdraw(
24582458
// User Destination Collateral
24592459
AccountMeta::new_readonly(KAMINO_LEND_PROGRAM, false),
24602460
// Token Program
2461-
AccountMeta::new_readonly(spl_token::id(), false),
2461+
AccountMeta::new_readonly(token.program_id(), false),
24622462
// Token Program
2463-
AccountMeta::new_readonly(spl_token::id(), false),
2463+
AccountMeta::new_readonly(token.program_id(), false),
24642464
// Sysvar: Instructions
24652465
AccountMeta::new_readonly(sysvar::instructions::ID, false),
24662466
],
@@ -2729,7 +2729,7 @@ fn solend_deposit_or_withdraw(
27292729
&wallet_address,
27302730
&wallet_address,
27312731
&reserve.collateral.mint_pubkey,
2732-
&spl_token::id(),
2732+
&token.program_id(),
27332733
),
27342734
);
27352735
}
@@ -2773,7 +2773,7 @@ fn solend_deposit_or_withdraw(
27732773
// User Transfer Authority
27742774
AccountMeta::new(wallet_address, true),
27752775
// Token Program
2776-
AccountMeta::new_readonly(spl_token::id(), false),
2776+
AccountMeta::new_readonly(token.program_id(), false),
27772777
],
27782778
));
27792779
(amount, 200_000)
@@ -2885,7 +2885,7 @@ fn solend_deposit_or_withdraw(
28852885
// User Transfer Authority
28862886
AccountMeta::new(wallet_address, true),
28872887
// Token Program
2888-
AccountMeta::new_readonly(spl_token::id(), false),
2888+
AccountMeta::new_readonly(token.program_id(), false),
28892889
];
28902890

28912891
for reserve_address in &obligation_market_reserves {
@@ -3088,7 +3088,7 @@ fn drift_deposit_or_withdraw(
30883088
false,
30893089
),
30903090
// Token Program
3091-
AccountMeta::new_readonly(spl_token::id(), false),
3091+
AccountMeta::new_readonly(token.program_id(), false),
30923092
// Spot Market Oracle
30933093
AccountMeta::new_readonly(spot_market.oracle, false),
30943094
// Spot Market
@@ -3138,7 +3138,7 @@ fn drift_deposit_or_withdraw(
31383138
false,
31393139
),
31403140
// Token Program
3141-
AccountMeta::new_readonly(spl_token::id(), false),
3141+
AccountMeta::new_readonly(token.program_id(), false),
31423142
// Spot Market Oracle
31433143
AccountMeta::new_readonly(spot_market.oracle, false),
31443144
// Spot Market

src/bin/sys.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -588,15 +588,15 @@ async fn process_exchange_deposit<T: Signers>(
588588
&authority_address,
589589
&deposit_address,
590590
&token.mint(),
591-
&spl_token::id(),
591+
&token.program_id(),
592592
),
593593
);
594594
compute_units += 20_000
595595
}
596596

597597
instructions.push(
598598
spl_token::instruction::transfer_checked(
599-
&spl_token::id(),
599+
&token.program_id(),
600600
&token.ata(&from_address),
601601
&token.mint(),
602602
&token.ata(&deposit_address),
@@ -3040,7 +3040,7 @@ async fn process_account_sweep<T: Signers>(
30403040

30413041
(
30423042
vec![spl_token::instruction::transfer_checked(
3043-
&spl_token::id(),
3043+
&token.program_id(),
30443044
&token.ata(&from_address),
30453045
&token.mint(),
30463046
&token.ata(&to_address),
@@ -3759,10 +3759,10 @@ async fn process_account_wrap<T: Signers>(
37593759
&authority_address,
37603760
&address,
37613761
&wsol.mint(),
3762-
&spl_token::id(),
3762+
&wsol.program_id(),
37633763
),
37643764
system_instruction::transfer(&address, &wsol_address, amount),
3765-
spl_token::instruction::sync_native(&spl_token::id(), &wsol_address).unwrap(),
3765+
spl_token::instruction::sync_native(&wsol.program_id(), &wsol_address).unwrap(),
37663766
]);
37673767

37683768
apply_priority_fee(rpc_clients, &mut instructions, 30_000, priority_fee)?;
@@ -3842,10 +3842,10 @@ async fn process_account_unwrap<T: Signers>(
38423842
&authority_address,
38433843
&ephemeral_token_account.pubkey(),
38443844
&wsol.mint(),
3845-
&spl_token::id(),
3845+
&wsol.program_id(),
38463846
),
38473847
spl_token::instruction::transfer_checked(
3848-
&spl_token::id(),
3848+
&wsol.program_id(),
38493849
&wsol.ata(&address),
38503850
&wsol.mint(),
38513851
&wsol.ata(&ephemeral_token_account.pubkey()),
@@ -3856,7 +3856,7 @@ async fn process_account_unwrap<T: Signers>(
38563856
)
38573857
.unwrap(),
38583858
spl_token::instruction::close_account(
3859-
&spl_token::id(),
3859+
&wsol.program_id(),
38603860
&wsol.ata(&ephemeral_token_account.pubkey()),
38613861
&address,
38623862
&ephemeral_token_account.pubkey(),

src/token.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,38 @@ impl Token {
8383
}
8484
}
8585

86+
pub fn program_id(&self) -> Pubkey {
87+
match self {
88+
Token::USDC
89+
| Token::USDS
90+
| Token::USDT
91+
| Token::UXD
92+
| Token::tuUSDC
93+
| Token::bSOL
94+
| Token::hSOL
95+
| Token::mSOL
96+
| Token::stSOL
97+
| Token::JitoSOL
98+
| Token::tuSOL
99+
| Token::tumSOL
100+
| Token::tustSOL
101+
| Token::wSOL
102+
| Token::JLP
103+
| Token::JUP
104+
| Token::JTO
105+
| Token::BONK
106+
| Token::KMNO
107+
| Token::PYTH
108+
| Token::WEN
109+
| Token::WIF => spl_token::id(),
110+
}
111+
}
86112
pub fn ata(&self, wallet_address: &Pubkey) -> Pubkey {
87-
spl_associated_token_account::get_associated_token_address(wallet_address, &self.mint())
113+
spl_associated_token_account::get_associated_token_address_with_program_id(
114+
wallet_address,
115+
&self.mint(),
116+
&self.program_id(),
117+
)
88118
}
89119

90120
pub fn symbol(&self) -> &'static str {

0 commit comments

Comments
 (0)