Skip to content

Commit

Permalink
Upgrade stable-swap-anchor-client to Anchor 0.22.0 (#133)
Browse files Browse the repository at this point in the history
* Bump anchor

* ProgramResult -> Result<()>

* Fix more breaking changes
  • Loading branch information
michaelhly authored Feb 26, 2022
1 parent 3bcf30d commit 9c93edf
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
anchor_version = "0.20.1"
anchor_version = "0.22.0"
solana_version = "1.8.14"

[workspace]
Expand Down
44 changes: 22 additions & 22 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
name = "ci";
paths = with pkgs;
(pkgs.lib.optionals pkgs.stdenv.isLinux ([ libudev ])) ++ [
anchor-0_20_1
anchor-0_22_0
cargo-workspaces
cargo-fuzz

Expand Down
2 changes: 1 addition & 1 deletion stable-swap-anchor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ edition = "2021"
keywords = ["solana", "saber", "anchor"]

[dependencies]
anchor-lang = ">=0.17"
anchor-lang = ">=0.22.0"
stable-swap-client = { path = "../stable-swap-client", version = "^1" }
65 changes: 39 additions & 26 deletions stable-swap-anchor/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn initialize<'a, 'b, 'c, 'info>(
nonce: u8,
amp_factor: u64,
fees: stable_swap_client::fees::Fees,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::initialize(
// token program ID is verified by the stable swap program
ctx.accounts.token_program.key,
Expand Down Expand Up @@ -54,7 +54,8 @@ pub fn initialize<'a, 'b, 'c, 'info>(
ctx.accounts.token_program,
],
ctx.signer_seeds,
)
)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::deposit] instruction.
Expand All @@ -71,7 +72,7 @@ pub fn deposit<'a, 'b, 'c, 'info>(
token_a_amount: u64,
token_b_amount: u64,
min_mint_amount: u64,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::deposit(
// token program ID is verified by the stable swap program
ctx.accounts.user.token_program.key,
Expand Down Expand Up @@ -105,7 +106,8 @@ pub fn deposit<'a, 'b, 'c, 'info>(
ctx.accounts.output_lp,
],
ctx.signer_seeds,
)
)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::swap] instruction.
Expand All @@ -120,7 +122,7 @@ pub fn swap<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, Swap<'info>>,
amount_in: u64,
minimum_amount_out: u64,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::swap(
ctx.accounts.user.token_program.key,
ctx.accounts.user.swap.key,
Expand Down Expand Up @@ -150,7 +152,8 @@ pub fn swap<'a, 'b, 'c, 'info>(
ctx.accounts.output.fees,
],
ctx.signer_seeds,
)
)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::withdraw_one] instruction.
Expand All @@ -165,7 +168,7 @@ pub fn withdraw_one<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, WithdrawOne<'info>>,
pool_token_amount: u64,
minimum_token_amount: u64,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::withdraw_one(
ctx.accounts.user.token_program.key,
ctx.accounts.user.swap.key,
Expand Down Expand Up @@ -197,7 +200,8 @@ pub fn withdraw_one<'a, 'b, 'c, 'info>(
ctx.accounts.output.fees,
],
ctx.signer_seeds,
)
)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::withdraw] instruction.
Expand All @@ -214,7 +218,7 @@ pub fn withdraw<'a, 'b, 'c, 'info>(
pool_token_amount: u64,
minimum_token_a_amount: u64,
minimum_token_b_amount: u64,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::withdraw(
// token program ID is verified by the stable swap program
ctx.accounts.user.token_program.key,
Expand All @@ -234,7 +238,8 @@ pub fn withdraw<'a, 'b, 'c, 'info>(
minimum_token_a_amount,
minimum_token_b_amount,
)?;
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::ramp_a] instruction.
Expand All @@ -249,53 +254,58 @@ pub fn ramp_a<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, AdminUserContext<'info>>,
target_amp: u64,
stop_ramp_ts: i64,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::ramp_a(
ctx.accounts.swap.key,
ctx.accounts.admin.key,
target_amp,
stop_ramp_ts,
)?;
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::stop_ramp_a] instruction.
pub fn stop_ramp_a<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, AdminUserContext<'info>>,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::stop_ramp_a(
ctx.accounts.swap.key,
ctx.accounts.admin.key,
)?;
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::pause] instruction.
pub fn pause<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, AdminUserContext<'info>>,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::pause(ctx.accounts.swap.key, ctx.accounts.admin.key)?;
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::unpause] instruction.
pub fn unpause<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, AdminUserContext<'info>>,
) -> ProgramResult {
) -> Result<()> {
let ix =
stable_swap_client::instruction::unpause(ctx.accounts.swap.key, ctx.accounts.admin.key)?;
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::apply_new_admin] instruction.
pub fn apply_new_admin<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, AdminUserContext<'info>>,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::apply_new_admin(
ctx.accounts.swap.key,
ctx.accounts.admin.key,
)?;
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::commit_new_admin] instruction
Expand All @@ -305,26 +315,28 @@ pub fn apply_new_admin<'a, 'b, 'c, 'info>(
/// * `new_admin` - Public key of the new admin.
pub fn commit_new_admin<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, CommitNewAdmin<'info>>,
) -> ProgramResult {
) -> Result<()> {
let admin_ctx = &ctx.accounts.admin_ctx;
let ix = stable_swap_client::instruction::commit_new_admin(
admin_ctx.swap.key,
admin_ctx.admin.key,
ctx.accounts.new_admin.key,
)?;
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::set_fee_account] instruction.
pub fn set_fee_account<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, SetFeeAccount<'info>>,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::set_fee_account(
ctx.accounts.admin_ctx.swap.key,
ctx.accounts.admin_ctx.admin.key,
ctx.accounts.fee_account.to_account_info().key,
)?;
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)?;
Ok(())
}

/// Creates and invokes a [stable_swap_client::instruction::set_new_fees] instruction.
Expand All @@ -335,11 +347,12 @@ pub fn set_fee_account<'a, 'b, 'c, 'info>(
pub fn set_new_fees<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, AdminUserContext<'info>>,
fees: stable_swap_client::fees::Fees,
) -> ProgramResult {
) -> Result<()> {
let ix = stable_swap_client::instruction::set_new_fees(
ctx.accounts.swap.key,
ctx.accounts.admin.key,
fees,
)?;
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)
solana_program::program::invoke_signed(&ix, &ctx.to_account_infos(), ctx.signer_seeds)?;
Ok(())
}
4 changes: 2 additions & 2 deletions stable-swap-anchor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ declare_id!("SSwpkEEcbUqx4vtoEByFjSkhKdCT862DNVb52nZg1UZ");
pub struct StableSwap;

impl anchor_lang::AccountDeserialize for StableSwap {
fn try_deserialize(buf: &mut &[u8]) -> Result<Self, ProgramError> {
fn try_deserialize(buf: &mut &[u8]) -> Result<Self> {
StableSwap::try_deserialize_unchecked(buf)
}

fn try_deserialize_unchecked(_buf: &mut &[u8]) -> Result<Self, ProgramError> {
fn try_deserialize_unchecked(_buf: &mut &[u8]) -> Result<Self> {
Ok(StableSwap)
}
}
Expand Down
Loading

0 comments on commit 9c93edf

Please sign in to comment.