Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 16b441e

Browse files
committed
Step 1: Update all instruction interfaces
1 parent 730b628 commit 16b441e

File tree

2 files changed

+73
-17
lines changed

2 files changed

+73
-17
lines changed

token-swap/program/src/instruction.rs

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub enum SwapInstruction {
105105
/// Must be empty, not owned by swap authority
106106
/// 6. `[writable]` Pool Token Account to deposit the initial pool token
107107
/// supply. Must be empty, not owned by swap authority.
108-
/// 7. `[]` Token program id
108+
/// 7. `[]` Pool Token program id
109109
Initialize(Initialize),
110110

111111
/// Swap the tokens in the pool.
@@ -119,8 +119,10 @@ pub enum SwapInstruction {
119119
/// 6. `[writable]` token_(A|B) DESTINATION Account assigned to USER as the owner.
120120
/// 7. `[writable]` Pool token mint, to generate trading fees
121121
/// 8. `[writable]` Fee account, to receive trading fees
122-
/// 9. `[]` Token program id
123-
/// 10. `[optional, writable]` Host fee account to receive additional trading fees
122+
/// 9. `[]` Token (A|B) SOURCE program id
123+
/// 10. `[]` Token (A|B) DESTINATION program id
124+
/// 11. `[]` Pool Token program id
125+
/// 12. `[optional, writable]` Host fee account to receive additional trading fees
124126
Swap(Swap),
125127

126128
/// Deposit both types of tokens into the pool. The output is a "pool"
@@ -136,7 +138,9 @@ pub enum SwapInstruction {
136138
/// 6. `[writable]` token_b Base Account to deposit into.
137139
/// 7. `[writable]` Pool MINT account, swap authority is the owner.
138140
/// 8. `[writable]` Pool Account to deposit the generated tokens, user is the owner.
139-
/// 9. `[]` Token program id
141+
/// 9. `[]` Token A program id
142+
/// 10. `[]` Token B program id
143+
/// 11. `[]` Pool Token program id
140144
DepositAllTokenTypes(DepositAllTokenTypes),
141145

142146
/// Withdraw both types of tokens from the pool at the current ratio, given
@@ -153,7 +157,9 @@ pub enum SwapInstruction {
153157
/// 7. `[writable]` token_a user Account to credit.
154158
/// 8. `[writable]` token_b user Account to credit.
155159
/// 9. `[writable]` Fee account, to receive withdrawal fees
156-
/// 10. `[]` Token program id
160+
/// 10. `[]` Pool Token program id
161+
/// 11. `[]` Token A program id
162+
/// 12. `[]` Token B program id
157163
WithdrawAllTokenTypes(WithdrawAllTokenTypes),
158164

159165
/// Deposit one type of tokens into the pool. The output is a "pool" token
@@ -168,7 +174,8 @@ pub enum SwapInstruction {
168174
/// 5. `[writable]` token_b Swap Account, may deposit INTO.
169175
/// 6. `[writable]` Pool MINT account, swap authority is the owner.
170176
/// 7. `[writable]` Pool Account to deposit the generated tokens, user is the owner.
171-
/// 8. `[]` Token program id
177+
/// 8. `[]` Token (A|B) SOURCE program id
178+
/// 9. `[]` Pool Token program id
172179
DepositSingleTokenTypeExactAmountIn(DepositSingleTokenTypeExactAmountIn),
173180

174181
/// Withdraw one token type from the pool at the current ratio given the
@@ -183,7 +190,8 @@ pub enum SwapInstruction {
183190
/// 6. `[writable]` token_b Swap Account to potentially withdraw from.
184191
/// 7. `[writable]` token_(A|B) User Account to credit
185192
/// 8. `[writable]` Fee account, to receive withdrawal fees
186-
/// 9. `[]` Token program id
193+
/// 9. `[]` Pool Token program id
194+
/// 10. `[]` Token (A|B) DESTINATION program id
187195
WithdrawSingleTokenTypeExactAmountOut(WithdrawSingleTokenTypeExactAmountOut),
188196
}
189197

@@ -366,7 +374,9 @@ pub fn initialize(
366374
/// Creates a 'deposit_all_token_types' instruction.
367375
pub fn deposit_all_token_types(
368376
program_id: &Pubkey,
369-
token_program_id: &Pubkey,
377+
token_a_program_id: &Pubkey,
378+
token_b_program_id: &Pubkey,
379+
pool_token_program_id: &Pubkey,
370380
swap_pubkey: &Pubkey,
371381
authority_pubkey: &Pubkey,
372382
user_transfer_authority_pubkey: &Pubkey,
@@ -390,7 +400,9 @@ pub fn deposit_all_token_types(
390400
AccountMeta::new(*swap_token_b_pubkey, false),
391401
AccountMeta::new(*pool_mint_pubkey, false),
392402
AccountMeta::new(*destination_pubkey, false),
393-
AccountMeta::new_readonly(*token_program_id, false),
403+
AccountMeta::new_readonly(*token_a_program_id, false),
404+
AccountMeta::new_readonly(*token_b_program_id, false),
405+
AccountMeta::new_readonly(*pool_token_program_id, false),
394406
];
395407

396408
Ok(Instruction {
@@ -403,7 +415,9 @@ pub fn deposit_all_token_types(
403415
/// Creates a 'withdraw_all_token_types' instruction.
404416
pub fn withdraw_all_token_types(
405417
program_id: &Pubkey,
406-
token_program_id: &Pubkey,
418+
pool_token_program_id: &Pubkey,
419+
token_a_program_id: &Pubkey,
420+
token_b_program_id: &Pubkey,
407421
swap_pubkey: &Pubkey,
408422
authority_pubkey: &Pubkey,
409423
user_transfer_authority_pubkey: &Pubkey,
@@ -429,7 +443,9 @@ pub fn withdraw_all_token_types(
429443
AccountMeta::new(*destination_token_a_pubkey, false),
430444
AccountMeta::new(*destination_token_b_pubkey, false),
431445
AccountMeta::new(*fee_account_pubkey, false),
432-
AccountMeta::new_readonly(*token_program_id, false),
446+
AccountMeta::new_readonly(*pool_token_program_id, false),
447+
AccountMeta::new_readonly(*token_a_program_id, false),
448+
AccountMeta::new_readonly(*token_b_program_id, false),
433449
];
434450

435451
Ok(Instruction {
@@ -442,7 +458,8 @@ pub fn withdraw_all_token_types(
442458
/// Creates a 'deposit_single_token_type_exact_amount_in' instruction.
443459
pub fn deposit_single_token_type_exact_amount_in(
444460
program_id: &Pubkey,
445-
token_program_id: &Pubkey,
461+
source_token_program_id: &Pubkey,
462+
pool_token_program_id: &Pubkey,
446463
swap_pubkey: &Pubkey,
447464
authority_pubkey: &Pubkey,
448465
user_transfer_authority_pubkey: &Pubkey,
@@ -464,7 +481,8 @@ pub fn deposit_single_token_type_exact_amount_in(
464481
AccountMeta::new(*swap_token_b_pubkey, false),
465482
AccountMeta::new(*pool_mint_pubkey, false),
466483
AccountMeta::new(*destination_pubkey, false),
467-
AccountMeta::new_readonly(*token_program_id, false),
484+
AccountMeta::new_readonly(*source_token_program_id, false),
485+
AccountMeta::new_readonly(*pool_token_program_id, false),
468486
];
469487

470488
Ok(Instruction {
@@ -477,7 +495,8 @@ pub fn deposit_single_token_type_exact_amount_in(
477495
/// Creates a 'withdraw_single_token_type_exact_amount_out' instruction.
478496
pub fn withdraw_single_token_type_exact_amount_out(
479497
program_id: &Pubkey,
480-
token_program_id: &Pubkey,
498+
pool_token_program_id: &Pubkey,
499+
destination_token_program_id: &Pubkey,
481500
swap_pubkey: &Pubkey,
482501
authority_pubkey: &Pubkey,
483502
user_transfer_authority_pubkey: &Pubkey,
@@ -501,7 +520,8 @@ pub fn withdraw_single_token_type_exact_amount_out(
501520
AccountMeta::new(*swap_token_b_pubkey, false),
502521
AccountMeta::new(*destination_pubkey, false),
503522
AccountMeta::new(*fee_account_pubkey, false),
504-
AccountMeta::new_readonly(*token_program_id, false),
523+
AccountMeta::new_readonly(*pool_token_program_id, false),
524+
AccountMeta::new_readonly(*destination_token_program_id, false),
505525
];
506526

507527
Ok(Instruction {
@@ -514,7 +534,9 @@ pub fn withdraw_single_token_type_exact_amount_out(
514534
/// Creates a 'swap' instruction.
515535
pub fn swap(
516536
program_id: &Pubkey,
517-
token_program_id: &Pubkey,
537+
source_token_program_id: &Pubkey,
538+
destination_token_program_id: &Pubkey,
539+
pool_token_program_id: &Pubkey,
518540
swap_pubkey: &Pubkey,
519541
authority_pubkey: &Pubkey,
520542
user_transfer_authority_pubkey: &Pubkey,
@@ -539,7 +561,9 @@ pub fn swap(
539561
AccountMeta::new(*destination_pubkey, false),
540562
AccountMeta::new(*pool_mint_pubkey, false),
541563
AccountMeta::new(*pool_fee_pubkey, false),
542-
AccountMeta::new_readonly(*token_program_id, false),
564+
AccountMeta::new_readonly(*source_token_program_id, false),
565+
AccountMeta::new_readonly(*destination_token_program_id, false),
566+
AccountMeta::new_readonly(*pool_token_program_id, false),
543567
];
544568
if let Some(host_fee_pubkey) = host_fee_pubkey {
545569
accounts.push(AccountMeta::new(*host_fee_pubkey, false));

token-swap/program/src/processor.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,8 @@ mod tests {
14401440
swap(
14411441
&SWAP_PROGRAM_ID,
14421442
&self.token_program_id,
1443+
&self.token_program_id,
1444+
&self.token_program_id,
14431445
&self.swap_key,
14441446
&self.authority_key,
14451447
&user_transfer_key,
@@ -1531,6 +1533,8 @@ mod tests {
15311533
deposit_all_token_types(
15321534
&SWAP_PROGRAM_ID,
15331535
&self.token_program_id,
1536+
&self.token_program_id,
1537+
&self.token_program_id,
15341538
&self.swap_key,
15351539
&self.authority_key,
15361540
&user_transfer_authority,
@@ -1601,6 +1605,8 @@ mod tests {
16011605
withdraw_all_token_types(
16021606
&SWAP_PROGRAM_ID,
16031607
&self.token_program_id,
1608+
&self.token_program_id,
1609+
&self.token_program_id,
16041610
&self.swap_key,
16051611
&self.authority_key,
16061612
&user_transfer_authority_key,
@@ -1668,6 +1674,7 @@ mod tests {
16681674
deposit_single_token_type_exact_amount_in(
16691675
&SWAP_PROGRAM_ID,
16701676
&self.token_program_id,
1677+
&self.token_program_id,
16711678
&self.swap_key,
16721679
&self.authority_key,
16731680
&user_transfer_authority_key,
@@ -1731,6 +1738,7 @@ mod tests {
17311738
withdraw_single_token_type_exact_amount_out(
17321739
&SWAP_PROGRAM_ID,
17331740
&self.token_program_id,
1741+
&self.token_program_id,
17341742
&self.swap_key,
17351743
&self.authority_key,
17361744
&user_transfer_authority_key,
@@ -3223,6 +3231,8 @@ mod tests {
32233231
deposit_all_token_types(
32243232
&SWAP_PROGRAM_ID,
32253233
&token_program_id,
3234+
&token_program_id,
3235+
&token_program_id,
32263236
&accounts.swap_key,
32273237
&accounts.authority_key,
32283238
&user_transfer_authority_key,
@@ -3272,6 +3282,8 @@ mod tests {
32723282
deposit_all_token_types(
32733283
&SWAP_PROGRAM_ID,
32743284
&wrong_key,
3285+
&wrong_key,
3286+
&wrong_key,
32753287
&accounts.swap_key,
32763288
&accounts.authority_key,
32773289
&accounts.authority_key,
@@ -3888,6 +3900,8 @@ mod tests {
38883900
withdraw_all_token_types(
38893901
&SWAP_PROGRAM_ID,
38903902
&token_program_id,
3903+
&token_program_id,
3904+
&token_program_id,
38913905
&accounts.swap_key,
38923906
&accounts.authority_key,
38933907
&user_transfer_authority_key,
@@ -3945,6 +3959,8 @@ mod tests {
39453959
withdraw_all_token_types(
39463960
&SWAP_PROGRAM_ID,
39473961
&wrong_key,
3962+
&wrong_key,
3963+
&wrong_key,
39483964
&accounts.swap_key,
39493965
&accounts.authority_key,
39503966
&accounts.authority_key,
@@ -4585,6 +4601,7 @@ mod tests {
45854601
deposit_single_token_type_exact_amount_in(
45864602
&SWAP_PROGRAM_ID,
45874603
&token_program_id,
4604+
&token_program_id,
45884605
&accounts.swap_key,
45894606
&accounts.authority_key,
45904607
&user_transfer_authority_key,
@@ -4631,6 +4648,7 @@ mod tests {
46314648
deposit_single_token_type_exact_amount_in(
46324649
&SWAP_PROGRAM_ID,
46334650
&wrong_key,
4651+
&wrong_key,
46344652
&accounts.swap_key,
46354653
&accounts.authority_key,
46364654
&accounts.authority_key,
@@ -5158,6 +5176,7 @@ mod tests {
51585176
withdraw_single_token_type_exact_amount_out(
51595177
&SWAP_PROGRAM_ID,
51605178
&token_program_id,
5179+
&token_program_id,
51615180
&accounts.swap_key,
51625181
&accounts.authority_key,
51635182
&user_transfer_authority_key,
@@ -5212,6 +5231,7 @@ mod tests {
52125231
withdraw_single_token_type_exact_amount_out(
52135232
&SWAP_PROGRAM_ID,
52145233
&wrong_key,
5234+
&wrong_key,
52155235
&accounts.swap_key,
52165236
&accounts.authority_key,
52175237
&accounts.authority_key,
@@ -5948,6 +5968,8 @@ mod tests {
59485968
swap(
59495969
&SWAP_PROGRAM_ID,
59505970
&token_program_id,
5971+
&token_program_id,
5972+
&token_program_id,
59515973
&accounts.swap_key,
59525974
&accounts.authority_key,
59535975
&accounts.authority_key,
@@ -6149,6 +6171,8 @@ mod tests {
61496171
swap(
61506172
&SWAP_PROGRAM_ID,
61516173
&wrong_program_id,
6174+
&wrong_program_id,
6175+
&wrong_program_id,
61526176
&accounts.swap_key,
61536177
&accounts.authority_key,
61546178
&accounts.authority_key,
@@ -6224,6 +6248,8 @@ mod tests {
62246248
swap(
62256249
&SWAP_PROGRAM_ID,
62266250
&token_program_id,
6251+
&token_program_id,
6252+
&token_program_id,
62276253
&accounts.swap_key,
62286254
&accounts.authority_key,
62296255
&user_transfer_key,
@@ -6393,6 +6419,8 @@ mod tests {
63936419
swap(
63946420
&SWAP_PROGRAM_ID,
63956421
&token_program_id,
6422+
&token_program_id,
6423+
&token_program_id,
63966424
&accounts.swap_key,
63976425
&accounts.authority_key,
63986426
&user_transfer_key,
@@ -6551,6 +6579,8 @@ mod tests {
65516579
swap(
65526580
&SWAP_PROGRAM_ID,
65536581
&token_program_id,
6582+
&token_program_id,
6583+
&token_program_id,
65546584
&accounts.swap_key,
65556585
&accounts.authority_key,
65566586
&accounts.authority_key,
@@ -6625,6 +6655,8 @@ mod tests {
66256655
swap(
66266656
&SWAP_PROGRAM_ID,
66276657
&token_program_id,
6658+
&token_program_id,
6659+
&token_program_id,
66286660
&accounts.swap_key,
66296661
&accounts.authority_key,
66306662
&accounts.authority_key,

0 commit comments

Comments
 (0)