Skip to content

Commit

Permalink
token-swap: Add version to state (#985)
Browse files Browse the repository at this point in the history
* Add version to token swap state

* Fix fuzz

* Cargo fmt

* Revert solana localnet version

* Update enum dispatch
  • Loading branch information
joncinque authored Feb 4, 2021
1 parent d16da5b commit b264915
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 180 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions token-swap/js/client/token-swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class Numberu64 extends BN {
*/
export const TokenSwapLayout: typeof BufferLayout.Structure = BufferLayout.struct(
[
BufferLayout.u8('version'),
BufferLayout.u8('isInitialized'),
BufferLayout.u8('nonce'),
Layout.publicKey('tokenProgramId'),
Expand Down
1 change: 1 addition & 0 deletions token-swap/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fuzz = ["arbitrary"]

[dependencies]
arrayref = "0.3.6"
enum_dispatch = "0.3.4"
num-derive = "0.3"
num-traits = "0.2"
solana-program = "1.5.1"
Expand Down
9 changes: 4 additions & 5 deletions token-swap/program/fuzz/src/native_token_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ use spl_token_swap::{
self, DepositAllTokenTypes, DepositSingleTokenTypeExactAmountIn, Swap,
WithdrawAllTokenTypes, WithdrawSingleTokenTypeExactAmountOut,
},
state::SwapInfo,
state::SwapVersion,
};

use spl_token::instruction::approve;

use solana_program::{
bpf_loader, entrypoint::ProgramResult, program_pack::Pack, pubkey::Pubkey, system_program,
};
use solana_program::{bpf_loader, entrypoint::ProgramResult, pubkey::Pubkey, system_program};

pub struct NativeTokenSwap {
pub user_account: NativeAccountData,
Expand Down Expand Up @@ -51,7 +49,8 @@ impl NativeTokenSwap {
) -> Self {
let mut user_account = NativeAccountData::new(0, system_program::id());
user_account.is_signer = true;
let mut swap_account = NativeAccountData::new(SwapInfo::LEN, spl_token_swap::id());
let mut swap_account =
NativeAccountData::new(SwapVersion::LATEST_LEN, spl_token_swap::id());
let (authority_key, nonce) = Pubkey::find_program_address(
&[&swap_account.key.to_bytes()[..]],
&spl_token_swap::id(),
Expand Down
4 changes: 2 additions & 2 deletions token-swap/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ pub struct WithdrawSingleTokenTypeExactAmountOut {
pub maximum_pool_token_amount: u64,
}

/// Instructions supported by the SwapInfo program.
/// Instructions supported by the token swap program.
#[repr(C)]
#[derive(Debug, PartialEq)]
pub enum SwapInstruction {
/// Initializes a new SwapInfo.
/// Initializes a new swap
///
/// 0. `[writable, signer]` New Token-swap to create.
/// 1. `[]` swap authority derived from `create_program_address(&[Token-swap account])`
Expand Down
Loading

0 comments on commit b264915

Please sign in to comment.