Step 1: Update all instruction interfaces

This commit is contained in:
Jon Cinque 2022-08-10 13:41:17 +02:00
parent 730b628c57
commit 16b441edb8
2 changed files with 73 additions and 17 deletions

View File

@ -105,7 +105,7 @@ pub enum SwapInstruction {
/// Must be empty, not owned by swap authority /// Must be empty, not owned by swap authority
/// 6. `[writable]` Pool Token Account to deposit the initial pool token /// 6. `[writable]` Pool Token Account to deposit the initial pool token
/// supply. Must be empty, not owned by swap authority. /// supply. Must be empty, not owned by swap authority.
/// 7. `[]` Token program id /// 7. `[]` Pool Token program id
Initialize(Initialize), Initialize(Initialize),
/// Swap the tokens in the pool. /// Swap the tokens in the pool.
@ -119,8 +119,10 @@ pub enum SwapInstruction {
/// 6. `[writable]` token_(A|B) DESTINATION Account assigned to USER as the owner. /// 6. `[writable]` token_(A|B) DESTINATION Account assigned to USER as the owner.
/// 7. `[writable]` Pool token mint, to generate trading fees /// 7. `[writable]` Pool token mint, to generate trading fees
/// 8. `[writable]` Fee account, to receive trading fees /// 8. `[writable]` Fee account, to receive trading fees
/// 9. `[]` Token program id /// 9. `[]` Token (A|B) SOURCE program id
/// 10. `[optional, writable]` Host fee account to receive additional trading fees /// 10. `[]` Token (A|B) DESTINATION program id
/// 11. `[]` Pool Token program id
/// 12. `[optional, writable]` Host fee account to receive additional trading fees
Swap(Swap), Swap(Swap),
/// Deposit both types of tokens into the pool. The output is a "pool" /// Deposit both types of tokens into the pool. The output is a "pool"
@ -136,7 +138,9 @@ pub enum SwapInstruction {
/// 6. `[writable]` token_b Base Account to deposit into. /// 6. `[writable]` token_b Base Account to deposit into.
/// 7. `[writable]` Pool MINT account, swap authority is the owner. /// 7. `[writable]` Pool MINT account, swap authority is the owner.
/// 8. `[writable]` Pool Account to deposit the generated tokens, user is the owner. /// 8. `[writable]` Pool Account to deposit the generated tokens, user is the owner.
/// 9. `[]` Token program id /// 9. `[]` Token A program id
/// 10. `[]` Token B program id
/// 11. `[]` Pool Token program id
DepositAllTokenTypes(DepositAllTokenTypes), DepositAllTokenTypes(DepositAllTokenTypes),
/// Withdraw both types of tokens from the pool at the current ratio, given /// Withdraw both types of tokens from the pool at the current ratio, given
@ -153,7 +157,9 @@ pub enum SwapInstruction {
/// 7. `[writable]` token_a user Account to credit. /// 7. `[writable]` token_a user Account to credit.
/// 8. `[writable]` token_b user Account to credit. /// 8. `[writable]` token_b user Account to credit.
/// 9. `[writable]` Fee account, to receive withdrawal fees /// 9. `[writable]` Fee account, to receive withdrawal fees
/// 10. `[]` Token program id /// 10. `[]` Pool Token program id
/// 11. `[]` Token A program id
/// 12. `[]` Token B program id
WithdrawAllTokenTypes(WithdrawAllTokenTypes), WithdrawAllTokenTypes(WithdrawAllTokenTypes),
/// Deposit one type of tokens into the pool. The output is a "pool" token /// Deposit one type of tokens into the pool. The output is a "pool" token
@ -168,7 +174,8 @@ pub enum SwapInstruction {
/// 5. `[writable]` token_b Swap Account, may deposit INTO. /// 5. `[writable]` token_b Swap Account, may deposit INTO.
/// 6. `[writable]` Pool MINT account, swap authority is the owner. /// 6. `[writable]` Pool MINT account, swap authority is the owner.
/// 7. `[writable]` Pool Account to deposit the generated tokens, user is the owner. /// 7. `[writable]` Pool Account to deposit the generated tokens, user is the owner.
/// 8. `[]` Token program id /// 8. `[]` Token (A|B) SOURCE program id
/// 9. `[]` Pool Token program id
DepositSingleTokenTypeExactAmountIn(DepositSingleTokenTypeExactAmountIn), DepositSingleTokenTypeExactAmountIn(DepositSingleTokenTypeExactAmountIn),
/// Withdraw one token type from the pool at the current ratio given the /// Withdraw one token type from the pool at the current ratio given the
@ -183,7 +190,8 @@ pub enum SwapInstruction {
/// 6. `[writable]` token_b Swap Account to potentially withdraw from. /// 6. `[writable]` token_b Swap Account to potentially withdraw from.
/// 7. `[writable]` token_(A|B) User Account to credit /// 7. `[writable]` token_(A|B) User Account to credit
/// 8. `[writable]` Fee account, to receive withdrawal fees /// 8. `[writable]` Fee account, to receive withdrawal fees
/// 9. `[]` Token program id /// 9. `[]` Pool Token program id
/// 10. `[]` Token (A|B) DESTINATION program id
WithdrawSingleTokenTypeExactAmountOut(WithdrawSingleTokenTypeExactAmountOut), WithdrawSingleTokenTypeExactAmountOut(WithdrawSingleTokenTypeExactAmountOut),
} }
@ -366,7 +374,9 @@ pub fn initialize(
/// Creates a 'deposit_all_token_types' instruction. /// Creates a 'deposit_all_token_types' instruction.
pub fn deposit_all_token_types( pub fn deposit_all_token_types(
program_id: &Pubkey, program_id: &Pubkey,
token_program_id: &Pubkey, token_a_program_id: &Pubkey,
token_b_program_id: &Pubkey,
pool_token_program_id: &Pubkey,
swap_pubkey: &Pubkey, swap_pubkey: &Pubkey,
authority_pubkey: &Pubkey, authority_pubkey: &Pubkey,
user_transfer_authority_pubkey: &Pubkey, user_transfer_authority_pubkey: &Pubkey,
@ -390,7 +400,9 @@ pub fn deposit_all_token_types(
AccountMeta::new(*swap_token_b_pubkey, false), AccountMeta::new(*swap_token_b_pubkey, false),
AccountMeta::new(*pool_mint_pubkey, false), AccountMeta::new(*pool_mint_pubkey, false),
AccountMeta::new(*destination_pubkey, false), AccountMeta::new(*destination_pubkey, false),
AccountMeta::new_readonly(*token_program_id, false), AccountMeta::new_readonly(*token_a_program_id, false),
AccountMeta::new_readonly(*token_b_program_id, false),
AccountMeta::new_readonly(*pool_token_program_id, false),
]; ];
Ok(Instruction { Ok(Instruction {
@ -403,7 +415,9 @@ pub fn deposit_all_token_types(
/// Creates a 'withdraw_all_token_types' instruction. /// Creates a 'withdraw_all_token_types' instruction.
pub fn withdraw_all_token_types( pub fn withdraw_all_token_types(
program_id: &Pubkey, program_id: &Pubkey,
token_program_id: &Pubkey, pool_token_program_id: &Pubkey,
token_a_program_id: &Pubkey,
token_b_program_id: &Pubkey,
swap_pubkey: &Pubkey, swap_pubkey: &Pubkey,
authority_pubkey: &Pubkey, authority_pubkey: &Pubkey,
user_transfer_authority_pubkey: &Pubkey, user_transfer_authority_pubkey: &Pubkey,
@ -429,7 +443,9 @@ pub fn withdraw_all_token_types(
AccountMeta::new(*destination_token_a_pubkey, false), AccountMeta::new(*destination_token_a_pubkey, false),
AccountMeta::new(*destination_token_b_pubkey, false), AccountMeta::new(*destination_token_b_pubkey, false),
AccountMeta::new(*fee_account_pubkey, false), AccountMeta::new(*fee_account_pubkey, false),
AccountMeta::new_readonly(*token_program_id, false), AccountMeta::new_readonly(*pool_token_program_id, false),
AccountMeta::new_readonly(*token_a_program_id, false),
AccountMeta::new_readonly(*token_b_program_id, false),
]; ];
Ok(Instruction { Ok(Instruction {
@ -442,7 +458,8 @@ pub fn withdraw_all_token_types(
/// Creates a 'deposit_single_token_type_exact_amount_in' instruction. /// Creates a 'deposit_single_token_type_exact_amount_in' instruction.
pub fn deposit_single_token_type_exact_amount_in( pub fn deposit_single_token_type_exact_amount_in(
program_id: &Pubkey, program_id: &Pubkey,
token_program_id: &Pubkey, source_token_program_id: &Pubkey,
pool_token_program_id: &Pubkey,
swap_pubkey: &Pubkey, swap_pubkey: &Pubkey,
authority_pubkey: &Pubkey, authority_pubkey: &Pubkey,
user_transfer_authority_pubkey: &Pubkey, user_transfer_authority_pubkey: &Pubkey,
@ -464,7 +481,8 @@ pub fn deposit_single_token_type_exact_amount_in(
AccountMeta::new(*swap_token_b_pubkey, false), AccountMeta::new(*swap_token_b_pubkey, false),
AccountMeta::new(*pool_mint_pubkey, false), AccountMeta::new(*pool_mint_pubkey, false),
AccountMeta::new(*destination_pubkey, false), AccountMeta::new(*destination_pubkey, false),
AccountMeta::new_readonly(*token_program_id, false), AccountMeta::new_readonly(*source_token_program_id, false),
AccountMeta::new_readonly(*pool_token_program_id, false),
]; ];
Ok(Instruction { Ok(Instruction {
@ -477,7 +495,8 @@ pub fn deposit_single_token_type_exact_amount_in(
/// Creates a 'withdraw_single_token_type_exact_amount_out' instruction. /// Creates a 'withdraw_single_token_type_exact_amount_out' instruction.
pub fn withdraw_single_token_type_exact_amount_out( pub fn withdraw_single_token_type_exact_amount_out(
program_id: &Pubkey, program_id: &Pubkey,
token_program_id: &Pubkey, pool_token_program_id: &Pubkey,
destination_token_program_id: &Pubkey,
swap_pubkey: &Pubkey, swap_pubkey: &Pubkey,
authority_pubkey: &Pubkey, authority_pubkey: &Pubkey,
user_transfer_authority_pubkey: &Pubkey, user_transfer_authority_pubkey: &Pubkey,
@ -501,7 +520,8 @@ pub fn withdraw_single_token_type_exact_amount_out(
AccountMeta::new(*swap_token_b_pubkey, false), AccountMeta::new(*swap_token_b_pubkey, false),
AccountMeta::new(*destination_pubkey, false), AccountMeta::new(*destination_pubkey, false),
AccountMeta::new(*fee_account_pubkey, false), AccountMeta::new(*fee_account_pubkey, false),
AccountMeta::new_readonly(*token_program_id, false), AccountMeta::new_readonly(*pool_token_program_id, false),
AccountMeta::new_readonly(*destination_token_program_id, false),
]; ];
Ok(Instruction { Ok(Instruction {
@ -514,7 +534,9 @@ pub fn withdraw_single_token_type_exact_amount_out(
/// Creates a 'swap' instruction. /// Creates a 'swap' instruction.
pub fn swap( pub fn swap(
program_id: &Pubkey, program_id: &Pubkey,
token_program_id: &Pubkey, source_token_program_id: &Pubkey,
destination_token_program_id: &Pubkey,
pool_token_program_id: &Pubkey,
swap_pubkey: &Pubkey, swap_pubkey: &Pubkey,
authority_pubkey: &Pubkey, authority_pubkey: &Pubkey,
user_transfer_authority_pubkey: &Pubkey, user_transfer_authority_pubkey: &Pubkey,
@ -539,7 +561,9 @@ pub fn swap(
AccountMeta::new(*destination_pubkey, false), AccountMeta::new(*destination_pubkey, false),
AccountMeta::new(*pool_mint_pubkey, false), AccountMeta::new(*pool_mint_pubkey, false),
AccountMeta::new(*pool_fee_pubkey, false), AccountMeta::new(*pool_fee_pubkey, false),
AccountMeta::new_readonly(*token_program_id, false), AccountMeta::new_readonly(*source_token_program_id, false),
AccountMeta::new_readonly(*destination_token_program_id, false),
AccountMeta::new_readonly(*pool_token_program_id, false),
]; ];
if let Some(host_fee_pubkey) = host_fee_pubkey { if let Some(host_fee_pubkey) = host_fee_pubkey {
accounts.push(AccountMeta::new(*host_fee_pubkey, false)); accounts.push(AccountMeta::new(*host_fee_pubkey, false));

View File

@ -1440,6 +1440,8 @@ mod tests {
swap( swap(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&self.token_program_id, &self.token_program_id,
&self.token_program_id,
&self.token_program_id,
&self.swap_key, &self.swap_key,
&self.authority_key, &self.authority_key,
&user_transfer_key, &user_transfer_key,
@ -1531,6 +1533,8 @@ mod tests {
deposit_all_token_types( deposit_all_token_types(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&self.token_program_id, &self.token_program_id,
&self.token_program_id,
&self.token_program_id,
&self.swap_key, &self.swap_key,
&self.authority_key, &self.authority_key,
&user_transfer_authority, &user_transfer_authority,
@ -1601,6 +1605,8 @@ mod tests {
withdraw_all_token_types( withdraw_all_token_types(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&self.token_program_id, &self.token_program_id,
&self.token_program_id,
&self.token_program_id,
&self.swap_key, &self.swap_key,
&self.authority_key, &self.authority_key,
&user_transfer_authority_key, &user_transfer_authority_key,
@ -1668,6 +1674,7 @@ mod tests {
deposit_single_token_type_exact_amount_in( deposit_single_token_type_exact_amount_in(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&self.token_program_id, &self.token_program_id,
&self.token_program_id,
&self.swap_key, &self.swap_key,
&self.authority_key, &self.authority_key,
&user_transfer_authority_key, &user_transfer_authority_key,
@ -1731,6 +1738,7 @@ mod tests {
withdraw_single_token_type_exact_amount_out( withdraw_single_token_type_exact_amount_out(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&self.token_program_id, &self.token_program_id,
&self.token_program_id,
&self.swap_key, &self.swap_key,
&self.authority_key, &self.authority_key,
&user_transfer_authority_key, &user_transfer_authority_key,
@ -3223,6 +3231,8 @@ mod tests {
deposit_all_token_types( deposit_all_token_types(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&token_program_id, &token_program_id,
&token_program_id,
&token_program_id,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&user_transfer_authority_key, &user_transfer_authority_key,
@ -3272,6 +3282,8 @@ mod tests {
deposit_all_token_types( deposit_all_token_types(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&wrong_key, &wrong_key,
&wrong_key,
&wrong_key,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&accounts.authority_key, &accounts.authority_key,
@ -3888,6 +3900,8 @@ mod tests {
withdraw_all_token_types( withdraw_all_token_types(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&token_program_id, &token_program_id,
&token_program_id,
&token_program_id,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&user_transfer_authority_key, &user_transfer_authority_key,
@ -3945,6 +3959,8 @@ mod tests {
withdraw_all_token_types( withdraw_all_token_types(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&wrong_key, &wrong_key,
&wrong_key,
&wrong_key,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&accounts.authority_key, &accounts.authority_key,
@ -4585,6 +4601,7 @@ mod tests {
deposit_single_token_type_exact_amount_in( deposit_single_token_type_exact_amount_in(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&token_program_id, &token_program_id,
&token_program_id,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&user_transfer_authority_key, &user_transfer_authority_key,
@ -4631,6 +4648,7 @@ mod tests {
deposit_single_token_type_exact_amount_in( deposit_single_token_type_exact_amount_in(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&wrong_key, &wrong_key,
&wrong_key,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&accounts.authority_key, &accounts.authority_key,
@ -5158,6 +5176,7 @@ mod tests {
withdraw_single_token_type_exact_amount_out( withdraw_single_token_type_exact_amount_out(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&token_program_id, &token_program_id,
&token_program_id,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&user_transfer_authority_key, &user_transfer_authority_key,
@ -5212,6 +5231,7 @@ mod tests {
withdraw_single_token_type_exact_amount_out( withdraw_single_token_type_exact_amount_out(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&wrong_key, &wrong_key,
&wrong_key,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&accounts.authority_key, &accounts.authority_key,
@ -5948,6 +5968,8 @@ mod tests {
swap( swap(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&token_program_id, &token_program_id,
&token_program_id,
&token_program_id,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&accounts.authority_key, &accounts.authority_key,
@ -6149,6 +6171,8 @@ mod tests {
swap( swap(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&wrong_program_id, &wrong_program_id,
&wrong_program_id,
&wrong_program_id,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&accounts.authority_key, &accounts.authority_key,
@ -6224,6 +6248,8 @@ mod tests {
swap( swap(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&token_program_id, &token_program_id,
&token_program_id,
&token_program_id,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&user_transfer_key, &user_transfer_key,
@ -6393,6 +6419,8 @@ mod tests {
swap( swap(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&token_program_id, &token_program_id,
&token_program_id,
&token_program_id,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&user_transfer_key, &user_transfer_key,
@ -6551,6 +6579,8 @@ mod tests {
swap( swap(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&token_program_id, &token_program_id,
&token_program_id,
&token_program_id,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&accounts.authority_key, &accounts.authority_key,
@ -6625,6 +6655,8 @@ mod tests {
swap( swap(
&SWAP_PROGRAM_ID, &SWAP_PROGRAM_ID,
&token_program_id, &token_program_id,
&token_program_id,
&token_program_id,
&accounts.swap_key, &accounts.swap_key,
&accounts.authority_key, &accounts.authority_key,
&accounts.authority_key, &accounts.authority_key,