From 3d7cecc558cbec8d0478693d2f2d1e72423b9bfd Mon Sep 17 00:00:00 2001 From: Will <82029448+wjthieme@users.noreply.github.com> Date: Mon, 16 Dec 2024 10:53:01 -0500 Subject: [PATCH] Add support for anchor v0.28 to rust client (#592) * Add support for anchor v0.28 to rust client * Lint * Relax libm --- rust-sdk/client/Cargo.toml | 10 ++-- rust-sdk/core/Cargo.toml | 2 +- .../client/anchor v0.28/Cargo.toml | 10 ++++ .../{anchor_v0.29 => anchor v0.29}/Cargo.toml | 2 +- .../{anchor_v0.30 => anchor v0.30}/Cargo.toml | 2 +- .../client/solana v1.16/Cargo.toml | 13 ++++++ .../{solana_v1.17 => solana v1.17}/Cargo.toml | 8 ++-- .../{solana_v1.18 => solana v1.18}/Cargo.toml | 8 ++-- .../{ethnum_1.1 => ethnum v1.1}/Cargo.toml | 2 +- .../{ethnum_1.2 => ethnum v1.2}/Cargo.toml | 2 +- .../{ethnum_1.3 => ethnum v1.3}/Cargo.toml | 2 +- .../{ethnum_1.4 => ethnum v1.4}/Cargo.toml | 2 +- .../{ethnum_1.5 => ethnum v1.5}/Cargo.toml | 2 +- .../integration/core/libm v0.1/Cargo.toml | 10 ++++ .../integration/core/libm v0.2/Cargo.toml | 10 ++++ rust-sdk/integration/core/libm_0.1/Cargo.toml | 10 ---- rust-sdk/integration/core/libm_0.2/Cargo.toml | 10 ---- rust-sdk/integration/index.test.ts | 46 ++++++++++++++----- rust-sdk/integration/package.json | 3 +- .../whirlpool/solana v1.18/Cargo.toml | 8 ++-- rust-sdk/whirlpool/Cargo.toml | 4 +- rust-sdk/whirlpool/src/pool.rs | 1 - rust-sdk/whirlpool/src/tests/program.rs | 2 +- rust-sdk/whirlpool/src/token.rs | 13 +++--- 24 files changed, 114 insertions(+), 68 deletions(-) create mode 100644 rust-sdk/integration/client/anchor v0.28/Cargo.toml rename rust-sdk/integration/client/{anchor_v0.29 => anchor v0.29}/Cargo.toml (84%) rename rust-sdk/integration/client/{anchor_v0.30 => anchor v0.30}/Cargo.toml (84%) create mode 100644 rust-sdk/integration/client/solana v1.16/Cargo.toml rename rust-sdk/integration/client/{solana_v1.17 => solana v1.17}/Cargo.toml (52%) rename rust-sdk/integration/client/{solana_v1.18 => solana v1.18}/Cargo.toml (51%) rename rust-sdk/integration/core/{ethnum_1.1 => ethnum v1.1}/Cargo.toml (84%) rename rust-sdk/integration/core/{ethnum_1.2 => ethnum v1.2}/Cargo.toml (84%) rename rust-sdk/integration/core/{ethnum_1.3 => ethnum v1.3}/Cargo.toml (84%) rename rust-sdk/integration/core/{ethnum_1.4 => ethnum v1.4}/Cargo.toml (84%) rename rust-sdk/integration/core/{ethnum_1.5 => ethnum v1.5}/Cargo.toml (84%) create mode 100644 rust-sdk/integration/core/libm v0.1/Cargo.toml create mode 100644 rust-sdk/integration/core/libm v0.2/Cargo.toml delete mode 100644 rust-sdk/integration/core/libm_0.1/Cargo.toml delete mode 100644 rust-sdk/integration/core/libm_0.2/Cargo.toml diff --git a/rust-sdk/client/Cargo.toml b/rust-sdk/client/Cargo.toml index 57f32931b..80e8f1971 100644 --- a/rust-sdk/client/Cargo.toml +++ b/rust-sdk/client/Cargo.toml @@ -20,15 +20,15 @@ serde = ["dep:serde", "dep:serde_with"] fetch = ["dep:solana-client", "dep:solana-sdk", "dep:solana-account-decoder"] [dependencies] -anchor-lang = { version = "^0.29", optional = true } +anchor-lang = { version = ">=0.28, <0.31", optional = true } borsh = { version = "^0.10" } num-derive = { version = "^0.4" } num-traits = { version = "^0.2" } orca_whirlpools_core = { path = "../core", optional = true } serde = { version = "^1.0", features = ["derive"], optional = true } serde_with = { version = "^3.10", optional = true } -solana-program = { version = "^1.17" } -solana-sdk = { version = "^1.17", optional = true } -solana-client = { version = "^1.17", optional = true } -solana-account-decoder = { version = "^1.17", optional = true } +solana-program = { version = "^1.16" } +solana-sdk = { version = "^1.16", optional = true } +solana-client = { version = "^1.16", optional = true } +solana-account-decoder = { version = "^1.16", optional = true } thiserror = { version = "^2.0" } diff --git a/rust-sdk/core/Cargo.toml b/rust-sdk/core/Cargo.toml index fa4900714..ec27bc029 100644 --- a/rust-sdk/core/Cargo.toml +++ b/rust-sdk/core/Cargo.toml @@ -18,7 +18,7 @@ floats = ["dep:libm"] [dependencies] ethnum = { version = "^1.1" } -libm = { version = "^0.1", optional = true } +libm = { version = ">=0.1, <0.3", optional = true } orca_whirlpools_macros = { path = "../macros" } wasm-bindgen = { version = "^0.2", optional = true } serde = { version = "^1.0", features = ["derive"], optional = true } diff --git a/rust-sdk/integration/client/anchor v0.28/Cargo.toml b/rust-sdk/integration/client/anchor v0.28/Cargo.toml new file mode 100644 index 000000000..a8b193ced --- /dev/null +++ b/rust-sdk/integration/client/anchor v0.28/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "orca_whirlpools_client_integration_anchor_v0_28" +edition = "2021" + +[lib] +path = "../../lib.rs" + +[dependencies] +anchor-lang = { version = "~0.28.0" } +orca_whirlpools_client = { path = "../../../client", features = ["anchor"] } diff --git a/rust-sdk/integration/client/anchor_v0.29/Cargo.toml b/rust-sdk/integration/client/anchor v0.29/Cargo.toml similarity index 84% rename from rust-sdk/integration/client/anchor_v0.29/Cargo.toml rename to rust-sdk/integration/client/anchor v0.29/Cargo.toml index c14070c2a..b2097b8f7 100644 --- a/rust-sdk/integration/client/anchor_v0.29/Cargo.toml +++ b/rust-sdk/integration/client/anchor v0.29/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" path = "../../lib.rs" [dependencies] -anchor-lang = { version = "~0.29" } +anchor-lang = { version = "~0.29.0" } orca_whirlpools_client = { path = "../../../client", features = ["anchor"] } diff --git a/rust-sdk/integration/client/anchor_v0.30/Cargo.toml b/rust-sdk/integration/client/anchor v0.30/Cargo.toml similarity index 84% rename from rust-sdk/integration/client/anchor_v0.30/Cargo.toml rename to rust-sdk/integration/client/anchor v0.30/Cargo.toml index 8cb52d53c..5ce7099a0 100644 --- a/rust-sdk/integration/client/anchor_v0.30/Cargo.toml +++ b/rust-sdk/integration/client/anchor v0.30/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" path = "../../lib.rs" [dependencies] -anchor-lang = { version = "~0.30" } +anchor-lang = { version = "~0.30.1" } orca_whirlpools_client = { path = "../../../client", features = ["anchor"] } diff --git a/rust-sdk/integration/client/solana v1.16/Cargo.toml b/rust-sdk/integration/client/solana v1.16/Cargo.toml new file mode 100644 index 000000000..3d3b31c56 --- /dev/null +++ b/rust-sdk/integration/client/solana v1.16/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "orca_whirlpools_client_integration_solana_v1_16" +edition = "2021" + +[lib] +path = "../../lib.rs" + +[dependencies] +solana-program = { version = "~1.16.27" } +solana-sdk = { version = "~1.16.27" } +solana-client = { version = "~1.16.27" } +solana-account-decoder = { version = "~1.16.27" } +orca_whirlpools_client = { path = "../../../client" } diff --git a/rust-sdk/integration/client/solana_v1.17/Cargo.toml b/rust-sdk/integration/client/solana v1.17/Cargo.toml similarity index 52% rename from rust-sdk/integration/client/solana_v1.17/Cargo.toml rename to rust-sdk/integration/client/solana v1.17/Cargo.toml index 5ac320273..851577054 100644 --- a/rust-sdk/integration/client/solana_v1.17/Cargo.toml +++ b/rust-sdk/integration/client/solana v1.17/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" path = "../../lib.rs" [dependencies] -solana-program = { version = "~1.17" } -solana-sdk = { version = "~1.17" } -solana-client = { version = "~1.17" } -solana-account-decoder = { version = "~1.17" } +solana-program = { version = "~1.17.3" } +solana-sdk = { version = "~1.17.3" } +solana-client = { version = "~1.17.3" } +solana-account-decoder = { version = "~1.17.3" } orca_whirlpools_client = { path = "../../../client" } diff --git a/rust-sdk/integration/client/solana_v1.18/Cargo.toml b/rust-sdk/integration/client/solana v1.18/Cargo.toml similarity index 51% rename from rust-sdk/integration/client/solana_v1.18/Cargo.toml rename to rust-sdk/integration/client/solana v1.18/Cargo.toml index e8c38238a..4556c3311 100644 --- a/rust-sdk/integration/client/solana_v1.18/Cargo.toml +++ b/rust-sdk/integration/client/solana v1.18/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" path = "../../lib.rs" [dependencies] -solana-program = { version = "~1.18" } -solana-sdk = { version = "~1.18" } -solana-client = { version = "~1.18" } -solana-account-decoder = { version = "~1.18" } +solana-program = { version = "~1.18.26" } +solana-sdk = { version = "~1.18.26" } +solana-client = { version = "~1.18.26" } +solana-account-decoder = { version = "~1.18.26" } orca_whirlpools_client = { path = "../../../client" } diff --git a/rust-sdk/integration/core/ethnum_1.1/Cargo.toml b/rust-sdk/integration/core/ethnum v1.1/Cargo.toml similarity index 84% rename from rust-sdk/integration/core/ethnum_1.1/Cargo.toml rename to rust-sdk/integration/core/ethnum v1.1/Cargo.toml index 9d4bcd394..3b0571648 100644 --- a/rust-sdk/integration/core/ethnum_1.1/Cargo.toml +++ b/rust-sdk/integration/core/ethnum v1.1/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" path = "../../lib.rs" [dependencies] -ethnum = { version = "~1.1" } +ethnum = { version = "~1.1.1" } orca_whirlpools_core = { path = "../../../core" } diff --git a/rust-sdk/integration/core/ethnum_1.2/Cargo.toml b/rust-sdk/integration/core/ethnum v1.2/Cargo.toml similarity index 84% rename from rust-sdk/integration/core/ethnum_1.2/Cargo.toml rename to rust-sdk/integration/core/ethnum v1.2/Cargo.toml index 20ce81bdc..352b0a654 100644 --- a/rust-sdk/integration/core/ethnum_1.2/Cargo.toml +++ b/rust-sdk/integration/core/ethnum v1.2/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" path = "../../lib.rs" [dependencies] -ethnum = { version = "~1.2" } +ethnum = { version = "~1.2.2" } orca_whirlpools_core = { path = "../../../core" } diff --git a/rust-sdk/integration/core/ethnum_1.3/Cargo.toml b/rust-sdk/integration/core/ethnum v1.3/Cargo.toml similarity index 84% rename from rust-sdk/integration/core/ethnum_1.3/Cargo.toml rename to rust-sdk/integration/core/ethnum v1.3/Cargo.toml index 347cdc9a3..e6133c2a5 100644 --- a/rust-sdk/integration/core/ethnum_1.3/Cargo.toml +++ b/rust-sdk/integration/core/ethnum v1.3/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" path = "../../lib.rs" [dependencies] -ethnum = { version = "~1.3" } +ethnum = { version = "~1.3.2" } orca_whirlpools_core = { path = "../../../core" } diff --git a/rust-sdk/integration/core/ethnum_1.4/Cargo.toml b/rust-sdk/integration/core/ethnum v1.4/Cargo.toml similarity index 84% rename from rust-sdk/integration/core/ethnum_1.4/Cargo.toml rename to rust-sdk/integration/core/ethnum v1.4/Cargo.toml index ef1b18eeb..f8a048ad3 100644 --- a/rust-sdk/integration/core/ethnum_1.4/Cargo.toml +++ b/rust-sdk/integration/core/ethnum v1.4/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" path = "../../lib.rs" [dependencies] -ethnum = { version = "~1.4" } +ethnum = { version = "~1.4.0" } orca_whirlpools_core = { path = "../../../core" } diff --git a/rust-sdk/integration/core/ethnum_1.5/Cargo.toml b/rust-sdk/integration/core/ethnum v1.5/Cargo.toml similarity index 84% rename from rust-sdk/integration/core/ethnum_1.5/Cargo.toml rename to rust-sdk/integration/core/ethnum v1.5/Cargo.toml index 752c3f3c7..329275f72 100644 --- a/rust-sdk/integration/core/ethnum_1.5/Cargo.toml +++ b/rust-sdk/integration/core/ethnum v1.5/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" path = "../../lib.rs" [dependencies] -ethnum = { version = "~1.5" } +ethnum = { version = "~1.5.0" } orca_whirlpools_core = { path = "../../../core" } diff --git a/rust-sdk/integration/core/libm v0.1/Cargo.toml b/rust-sdk/integration/core/libm v0.1/Cargo.toml new file mode 100644 index 000000000..d94d819f3 --- /dev/null +++ b/rust-sdk/integration/core/libm v0.1/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "orca_whirlpools_core_integration_libm_v0_1" +edition = "2021" + +[lib] +path = "../../lib.rs" + +[dependencies] +libm = { version = "~0.1.4" } +orca_whirlpools_core = { path = "../../../core" } diff --git a/rust-sdk/integration/core/libm v0.2/Cargo.toml b/rust-sdk/integration/core/libm v0.2/Cargo.toml new file mode 100644 index 000000000..d2e6f5db6 --- /dev/null +++ b/rust-sdk/integration/core/libm v0.2/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "orca_whirlpools_core_integration_libm_v0_2" +edition = "2021" + +[lib] +path = "../../lib.rs" + +[dependencies] +libm = { version = "~0.2.11" } +orca_whirlpools_core = { path = "../../../core" } diff --git a/rust-sdk/integration/core/libm_0.1/Cargo.toml b/rust-sdk/integration/core/libm_0.1/Cargo.toml deleted file mode 100644 index 4ff7dc6ea..000000000 --- a/rust-sdk/integration/core/libm_0.1/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "orca_whirlpools_core_integration_libm_v0_1" -edition = "2021" - -[lib] -path = "../../lib.rs" - -[dependencies] -libm = { version = "~0.1" } -orca_whirlpools_core = { path = "../../../core", features = ["floats"] } diff --git a/rust-sdk/integration/core/libm_0.2/Cargo.toml b/rust-sdk/integration/core/libm_0.2/Cargo.toml deleted file mode 100644 index 47298dc0f..000000000 --- a/rust-sdk/integration/core/libm_0.2/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "orca_whirlpools_core_integration_libm_v0_2" -edition = "2021" - -[lib] -path = "../../lib.rs" - -[dependencies] -libm = { version = "~0.2" } -orca_whirlpools_core = { path = "../../../core", features = ["floats"] } diff --git a/rust-sdk/integration/index.test.ts b/rust-sdk/integration/index.test.ts index 0c49a00eb..f5e3c8b4a 100644 --- a/rust-sdk/integration/index.test.ts +++ b/rust-sdk/integration/index.test.ts @@ -7,30 +7,54 @@ const clientConfigs = readdirSync("./client"); const coreConfigs = readdirSync("./core"); const whirlpoolConfigs = readdirSync("./whirlpool"); -function exec(command: string) { +function exec(...command: string[]) { try { - return execSync(command); + return execSync(command.join(" && ")).toString(); } catch (error) { assert.fail(`${error}`); } } +function check(path: string) { + const versions = exec(`awk '/version = "[^"]*"/' '${path}/Cargo.toml'`); + exec(`cargo generate-lockfile --manifest-path '${path}/Cargo.toml'`); + for (const version of versions.split("\n")) { + const match = version.match( + /([a-zA-Z0-9-_]+)\s*=\s*{\s*version\s*=\s*"~([^"]+)"/, + ); + if (!match) continue; + const rawExistingVersions = exec( + `awk '/"${match[1]} [0-9]+.[0-9]+.[0-9]+"/' '${path}/Cargo.lock'`, + ); + const existingVersions = new Set( + rawExistingVersions.split("\n").filter((x) => x), + ); + for (const existingVersion of existingVersions) { + const specifier = existingVersion.slice(2, -2).replaceAll(" ", ":"); + exec( + `cargo update ${specifier} --precise ${match[2]} --manifest-path '${path}/Cargo.toml'`, + ); + } + } + exec(`cargo check --manifest-path '${path}/Cargo.toml' --locked`); +} + describe("Integration", () => { clientConfigs.forEach((config) => { - it.concurrent(`Build client using ${config}`, () => { - exec(`cargo check --manifest-path './client/${config}/Cargo.toml'`); - }); + it.concurrent(`Build client using ${config}`, () => + check(`./client/${config}`), + ); }); coreConfigs.forEach((config) => { - it.concurrent(`Build core using ${config}`, () => { - exec(`cargo check --manifest-path './core/${config}/Cargo.toml'`); - }); + it.concurrent(`Build core using ${config}`, () => + check(`./core/${config}`), + ); }); whirlpoolConfigs.forEach((config) => { - it.concurrent(`Build whirlpool using ${config}`, () => { - exec(`cargo check --manifest-path './whirlpool/${config}/Cargo.toml'`); - }); + it.concurrent(`Build whirlpool using ${config}`, () => + check(`./whirlpool/${config}`), + ); }); }); diff --git a/rust-sdk/integration/package.json b/rust-sdk/integration/package.json index cb2e8a096..ea0ec5b7b 100644 --- a/rust-sdk/integration/package.json +++ b/rust-sdk/integration/package.json @@ -4,7 +4,8 @@ "type": "module", "scripts": { "build": "tsc --noEmit", - "test": "vitest run index.test.ts" + "test": "vitest run index.test.ts", + "clean": "rimraf --glob ./**/Cargo.lock ./**/target" }, "devDependencies": { "@orca-so/whirlpools-rust": "*", diff --git a/rust-sdk/integration/whirlpool/solana v1.18/Cargo.toml b/rust-sdk/integration/whirlpool/solana v1.18/Cargo.toml index 0a120d8b1..72b244771 100644 --- a/rust-sdk/integration/whirlpool/solana v1.18/Cargo.toml +++ b/rust-sdk/integration/whirlpool/solana v1.18/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" path = "../../lib.rs" [dependencies] -solana-program = { version = "~1.18" } -solana-sdk = { version = "~1.18" } -solana-client = { version = "~1.18" } -solana-account-decoder = { version = "~1.18" } +solana-program = { version = "~1.18.26" } +solana-sdk = { version = "~1.18.26" } +solana-client = { version = "~1.18.26" } +solana-account-decoder = { version = "~1.18.26" } orca_whirlpools = { path = "../../../whirlpool" } diff --git a/rust-sdk/whirlpool/Cargo.toml b/rust-sdk/whirlpool/Cargo.toml index ff07c400b..a624a37bb 100644 --- a/rust-sdk/whirlpool/Cargo.toml +++ b/rust-sdk/whirlpool/Cargo.toml @@ -36,5 +36,5 @@ solana-version = { version = "^1.18" } async-trait = { version = "^0.1" } base64 = { version = "^0.20" } toml = { version = "^0.7" } -tokio = { version = "1.0", features = ["sync"] } -spl-pod = "0.1.0" +tokio = { version = "^1.0", features = ["sync"] } +spl-pod = { version = "^0.1" } diff --git a/rust-sdk/whirlpool/src/pool.rs b/rust-sdk/whirlpool/src/pool.rs index 12dec558e..ae461ed8a 100644 --- a/rust-sdk/whirlpool/src/pool.rs +++ b/rust-sdk/whirlpool/src/pool.rs @@ -389,7 +389,6 @@ mod tests { }; use serial_test::serial; use solana_program_test::tokio; - use solana_sdk::signer::Signer; struct TestContext { ctx: RpcContext, diff --git a/rust-sdk/whirlpool/src/tests/program.rs b/rust-sdk/whirlpool/src/tests/program.rs index 5c6086e05..81d735c44 100644 --- a/rust-sdk/whirlpool/src/tests/program.rs +++ b/rust-sdk/whirlpool/src/tests/program.rs @@ -5,7 +5,7 @@ use orca_whirlpools_client::{ get_fee_tier_address, get_token_badge_address, get_whirlpool_address, InitializePoolV2, InitializePoolV2InstructionArgs, }; -use orca_whirlpools_core::{price_to_sqrt_price, tick_index_to_sqrt_price}; +use orca_whirlpools_core::tick_index_to_sqrt_price; use solana_program::sysvar::rent::ID as RENT_PROGRAM_ID; use crate::WHIRLPOOLS_CONFIG_ADDRESS; diff --git a/rust-sdk/whirlpool/src/token.rs b/rust-sdk/whirlpool/src/token.rs index efe604b77..da9277f79 100644 --- a/rust-sdk/whirlpool/src/token.rs +++ b/rust-sdk/whirlpool/src/token.rs @@ -6,16 +6,14 @@ use solana_sdk::program_error::ProgramError; use solana_sdk::signature::Keypair; use solana_sdk::signer::Signer; use solana_sdk::system_instruction::{create_account, create_account_with_seed, transfer}; -use solana_sdk::{instruction::Instruction, pubkey::Pubkey, system_instruction}; +use solana_sdk::{instruction::Instruction, pubkey::Pubkey}; use spl_associated_token_account::{ - get_associated_token_address_with_program_id, - instruction::{create_associated_token_account, create_associated_token_account_idempotent}, + get_associated_token_address_with_program_id, instruction::create_associated_token_account, }; use spl_token::instruction::{close_account, initialize_account3, sync_native}; use spl_token::solana_program::program_pack::Pack; use spl_token::{native_mint, ID as TOKEN_PROGRAM_ID}; use spl_token_2022::extension::transfer_fee::TransferFeeConfig; -use spl_token_2022::extension::ExtensionType; use spl_token_2022::extension::{BaseStateWithExtensions, StateWithExtensions}; use spl_token_2022::state::{Account, Mint}; use spl_token_2022::ID as TOKEN_2022_PROGRAM_ID; @@ -331,11 +329,12 @@ mod tests { use super::*; use crate::tests::{ setup_ata, setup_ata_te, setup_ata_with_amount, setup_mint, setup_mint_te, - setup_mint_te_fee, setup_mint_with_decimals, RpcContext, + setup_mint_te_fee, RpcContext, }; use serial_test::serial; - use solana_program::program_option::COption; - use spl_token_2022::extension::ExtensionType; + + use spl_associated_token_account::instruction::create_associated_token_account_idempotent; + use std::str::FromStr; // 1. Basic Utility Tests