Skip to content

Commit

Permalink
Add support for anchor v0.28 to rust client (#592)
Browse files Browse the repository at this point in the history
* Add support for anchor v0.28 to rust client

* Lint

* Relax libm
  • Loading branch information
wjthieme authored Dec 16, 2024
1 parent a70501f commit 3d7cecc
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 68 deletions.
10 changes: 5 additions & 5 deletions rust-sdk/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion rust-sdk/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
10 changes: 10 additions & 0 deletions rust-sdk/integration/client/anchor v0.28/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
13 changes: 13 additions & 0 deletions rust-sdk/integration/client/solana v1.16/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" }
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
path = "../../lib.rs"

[dependencies]
ethnum = { version = "~1.1" }
ethnum = { version = "~1.1.1" }
orca_whirlpools_core = { path = "../../../core" }
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
path = "../../lib.rs"

[dependencies]
ethnum = { version = "~1.2" }
ethnum = { version = "~1.2.2" }
orca_whirlpools_core = { path = "../../../core" }
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
path = "../../lib.rs"

[dependencies]
ethnum = { version = "~1.3" }
ethnum = { version = "~1.3.2" }
orca_whirlpools_core = { path = "../../../core" }
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
path = "../../lib.rs"

[dependencies]
ethnum = { version = "~1.4" }
ethnum = { version = "~1.4.0" }
orca_whirlpools_core = { path = "../../../core" }
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
path = "../../lib.rs"

[dependencies]
ethnum = { version = "~1.5" }
ethnum = { version = "~1.5.0" }
orca_whirlpools_core = { path = "../../../core" }
10 changes: 10 additions & 0 deletions rust-sdk/integration/core/libm v0.1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" }
10 changes: 10 additions & 0 deletions rust-sdk/integration/core/libm v0.2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" }
10 changes: 0 additions & 10 deletions rust-sdk/integration/core/libm_0.1/Cargo.toml

This file was deleted.

10 changes: 0 additions & 10 deletions rust-sdk/integration/core/libm_0.2/Cargo.toml

This file was deleted.

46 changes: 35 additions & 11 deletions rust-sdk/integration/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`),
);
});
});
3 changes: 2 additions & 1 deletion rust-sdk/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
8 changes: 4 additions & 4 deletions rust-sdk/integration/whirlpool/solana v1.18/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
4 changes: 2 additions & 2 deletions rust-sdk/whirlpool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
1 change: 0 additions & 1 deletion rust-sdk/whirlpool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ mod tests {
};
use serial_test::serial;
use solana_program_test::tokio;
use solana_sdk::signer::Signer;

struct TestContext {
ctx: RpcContext,
Expand Down
2 changes: 1 addition & 1 deletion rust-sdk/whirlpool/src/tests/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 6 additions & 7 deletions rust-sdk/whirlpool/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d7cecc

Please sign in to comment.