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

Commit b264915

Browse files
authored
token-swap: Add version to state (#985)
* Add version to token swap state * Fix fuzz * Cargo fmt * Revert solana localnet version * Update enum dispatch
1 parent d16da5b commit b264915

File tree

7 files changed

+344
-180
lines changed

7 files changed

+344
-180
lines changed

Cargo.lock

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token-swap/js/client/token-swap.js

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class Numberu64 extends BN {
5858
*/
5959
export const TokenSwapLayout: typeof BufferLayout.Structure = BufferLayout.struct(
6060
[
61+
BufferLayout.u8('version'),
6162
BufferLayout.u8('isInitialized'),
6263
BufferLayout.u8('nonce'),
6364
Layout.publicKey('tokenProgramId'),

token-swap/program/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fuzz = ["arbitrary"]
1414

1515
[dependencies]
1616
arrayref = "0.3.6"
17+
enum_dispatch = "0.3.4"
1718
num-derive = "0.3"
1819
num-traits = "0.2"
1920
solana-program = "1.5.1"

token-swap/program/fuzz/src/native_token_swap.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ use spl_token_swap::{
1010
self, DepositAllTokenTypes, DepositSingleTokenTypeExactAmountIn, Swap,
1111
WithdrawAllTokenTypes, WithdrawSingleTokenTypeExactAmountOut,
1212
},
13-
state::SwapInfo,
13+
state::SwapVersion,
1414
};
1515

1616
use spl_token::instruction::approve;
1717

18-
use solana_program::{
19-
bpf_loader, entrypoint::ProgramResult, program_pack::Pack, pubkey::Pubkey, system_program,
20-
};
18+
use solana_program::{bpf_loader, entrypoint::ProgramResult, pubkey::Pubkey, system_program};
2119

2220
pub struct NativeTokenSwap {
2321
pub user_account: NativeAccountData,
@@ -51,7 +49,8 @@ impl NativeTokenSwap {
5149
) -> Self {
5250
let mut user_account = NativeAccountData::new(0, system_program::id());
5351
user_account.is_signer = true;
54-
let mut swap_account = NativeAccountData::new(SwapInfo::LEN, spl_token_swap::id());
52+
let mut swap_account =
53+
NativeAccountData::new(SwapVersion::LATEST_LEN, spl_token_swap::id());
5554
let (authority_key, nonce) = Pubkey::find_program_address(
5655
&[&swap_account.key.to_bytes()[..]],
5756
&spl_token_swap::id(),

token-swap/program/src/instruction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ pub struct WithdrawSingleTokenTypeExactAmountOut {
9292
pub maximum_pool_token_amount: u64,
9393
}
9494

95-
/// Instructions supported by the SwapInfo program.
95+
/// Instructions supported by the token swap program.
9696
#[repr(C)]
9797
#[derive(Debug, PartialEq)]
9898
pub enum SwapInstruction {
99-
/// Initializes a new SwapInfo.
99+
/// Initializes a new swap
100100
///
101101
/// 0. `[writable, signer]` New Token-swap to create.
102102
/// 1. `[]` swap authority derived from `create_program_address(&[Token-swap account])`

0 commit comments

Comments
 (0)