Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 7c0ed0a
Author: Wilhelm Thieme <[email protected]>
Date:   Tue Feb 11 14:58:03 2025 -0500

    Lint

commit b0e3949
Merge: 1d5f82f c29eed4
Author: Will <[email protected]>
Date:   Tue Feb 11 14:51:16 2025 -0500

    Merge branch 'main' into wjthieme/client-solana-v2

commit 1d5f82f
Author: Will <[email protected]>
Date:   Tue Feb 11 14:49:45 2025 -0500

    Update action.yml

commit 55311ec
Merge: 6c2b8a1 a2bf808
Author: Will <[email protected]>
Date:   Mon Feb 10 16:30:54 2025 -0500

    Merge branch 'main' into wjthieme/client-solana-v2

commit 6c2b8a1
Author: Wilhelm Thieme <[email protected]>
Date:   Sat Feb 8 14:15:29 2025 -0500

    Tweaks?

commit df24a19
Author: Wilhelm Thieme <[email protected]>
Date:   Fri Feb 7 17:26:02 2025 -0500

    Upgrade rustc

commit f584b2b
Author: Wilhelm Thieme <[email protected]>
Date:   Fri Feb 7 16:42:31 2025 -0500

    Build fix

commit eab285e
Author: Wilhelm Thieme <[email protected]>
Date:   Fri Feb 7 16:21:48 2025 -0500

    Fix changeset

commit 38a22a8
Author: Wilhelm Thieme <[email protected]>
Date:   Fri Feb 7 16:19:52 2025 -0500

    Build fix

commit c6e2edb
Author: Wilhelm Thieme <[email protected]>
Date:   Fri Feb 7 15:16:30 2025 -0500

    fmt

commit 43e0192
Author: Wilhelm Thieme <[email protected]>
Date:   Fri Feb 7 13:34:13 2025 -0500

    Tweaks

commit 85ef1e2
Author: Wilhelm Thieme <[email protected]>
Date:   Fri Feb 7 13:26:46 2025 -0500

    Changeset

commit 78e301d
Author: Wilhelm Thieme <[email protected]>
Date:   Thu Feb 6 09:50:18 2025 -0500

    Build fix

commit 38df812
Author: Wilhelm Thieme <[email protected]>
Date:   Thu Feb 6 09:31:08 2025 -0500

    Add support for solana v2 crates to rust client
  • Loading branch information
wjthieme committed Feb 11, 2025
1 parent c29eed4 commit bb778c4
Show file tree
Hide file tree
Showing 32 changed files with 309 additions and 121 deletions.
6 changes: 6 additions & 0 deletions .changeset/stupid-rats-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@orca-so/whirlpools-rust-client": major
"@orca-so/whirlpools-rust": major
---

Add support for solana v2 crates, to use solana v1 with orca_whirlpools_client please use the `solana-v1` feature
6 changes: 6 additions & 0 deletions .changeset/stupid-rats-laugh2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@orca-so/whirlpools-example-rust-repositioning-bot": minor
"@orca-so/whirlpools-rust-integration": minor
---

Add support for solana v2 crates
2 changes: 1 addition & 1 deletion docs/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"

[dependencies]
orca_whirlpools_core = { path = "../../rust-sdk/core", features = ["floats"] }
orca_whirlpools_client = { path = "../../rust-sdk/client", features = ["anchor", "core-types"] }
orca_whirlpools_client = { path = "../../rust-sdk/client" }
orca_whirlpools = { path = "../../rust-sdk/whirlpool" }

8 changes: 4 additions & 4 deletions examples/rust-sdk/whirlpool_repositioning_bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ orca_whirlpools = { path = '../../../rust-sdk/whirlpool' }
orca_whirlpools_client = { path = '../../../rust-sdk/client' }
orca_whirlpools_core = { path = '../../../rust-sdk/core' }
serde_json = { version = "^1.0" }
solana-client = { version = "^1.18" }
solana-sdk = { version = "^1.18" }
spl-token-2022 = { version = "^3.0" }
spl-associated-token-account = { version = "^3.0" }
solana-client = { version = "^2.1" }
solana-sdk = { version = "^2.1" }
spl-token-2022 = { version = "^7.0" }
spl-associated-token-account = { version = "^6.0" }
tokio = { version = "^1.41.1" }
tokio-retry = { version = "^0.3.0" }
dotenv = { version = "^0.15.0"}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct SwapTestFixtureInfo<'info> {
pub protocol_fee_rate: u16,
}

impl<'info> Default for SwapTestFixtureInfo<'info> {
impl Default for SwapTestFixtureInfo<'_> {
fn default() -> Self {
SwapTestFixtureInfo {
tick_spacing: TS_128,
Expand Down
14 changes: 8 additions & 6 deletions rust-sdk/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ authors = ["[email protected]"]
edition = "2021"

[features]
default = ["core-types", "fetch"]
default = ["core-types"]
anchor = ["dep:anchor-lang"]
anchor-idl-build = []
core-types = ["dep:orca_whirlpools_core"]
serde = ["dep:serde", "dep:serde_with"]
serde = ["dep:serde", "dep:serde_with", "dep:serde-big-array"]
fetch = ["dep:solana-client", "dep:solana-sdk", "dep:solana-account-decoder"]
solana-v1 = []

[dependencies]
anchor-lang = { version = ">=0.28, <0.31", optional = true }
Expand All @@ -27,8 +28,9 @@ 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.16" }
solana-sdk = { version = "^1.16", optional = true }
solana-client = { version = "^1.16", optional = true }
solana-account-decoder = { version = "^1.16", optional = true }
serde-big-array = { version = "^0.5", optional = true }
solana-program = { version = ">=1.16, <3.0" }
solana-sdk = { version = ">=1.16, <3.0", optional = true }
solana-client = { version = ">=1.16, <3.0", optional = true }
solana-account-decoder = { version = ">=1.16, <3.0", optional = true }
thiserror = { version = "^2.0" }
43 changes: 30 additions & 13 deletions rust-sdk/client/src/gpa/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,41 @@ use solana_client::{

use crate::{generated::shared::DecodedAccount, WHIRLPOOL_ID};

#[cfg(feature = "solana-v1")]
pub(crate) fn rpc_program_accounts_config(filters: Vec<RpcFilterType>) -> RpcProgramAccountsConfig {
RpcProgramAccountsConfig {
filters: Some(filters),
account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64),
data_slice: None,
commitment: None,
min_context_slot: None,
},
with_context: None,
}
}

#[cfg(not(feature = "solana-v1"))]
pub(crate) fn rpc_program_accounts_config(filters: Vec<RpcFilterType>) -> RpcProgramAccountsConfig {
RpcProgramAccountsConfig {
filters: Some(filters),
account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64),
data_slice: None,
commitment: None,
min_context_slot: None,
},
with_context: None,
sort_results: None,
}
}

pub(crate) async fn fetch_decoded_program_accounts<T: BorshDeserialize>(
rpc: &RpcClient,
filters: Vec<RpcFilterType>,
) -> Result<Vec<DecodedAccount<T>>, Box<dyn Error>> {
let accounts = rpc
.get_program_accounts_with_config(
&WHIRLPOOL_ID,
RpcProgramAccountsConfig {
filters: Some(filters),
account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64),
data_slice: None,
commitment: None,
min_context_slot: None,
},
with_context: None,
},
)
.get_program_accounts_with_config(&WHIRLPOOL_ID, rpc_program_accounts_config(filters))
.await?;
let mut decoded_accounts: Vec<DecodedAccount<T>> = Vec::new();
for (address, account) in accounts {
Expand Down
6 changes: 5 additions & 1 deletion rust-sdk/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ pub use generated::errors::*;
pub use generated::instructions::*;
pub use generated::programs::WHIRLPOOL_ID as ID;
pub use generated::programs::*;
pub use generated::shared::*;
pub use generated::types::*;

#[cfg(feature = "fetch")]
pub use generated::shared::*;

#[cfg(feature = "fetch")]
pub(crate) use generated::*;

pub use pda::*;
Expand Down
1 change: 1 addition & 0 deletions rust-sdk/integration/client/anchor v0.28/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ path = "../../lib.rs"

[dependencies]
anchor-lang = { version = "~0.28.0" }
solana-program = { version = "~1.16.25" }
orca_whirlpools_client = { path = "../../../client", features = ["anchor"] }
1 change: 1 addition & 0 deletions rust-sdk/integration/client/anchor v0.29/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ path = "../../lib.rs"

[dependencies]
anchor-lang = { version = "~0.29.0" }
solana-program = { version = "~1.18.26" }
orca_whirlpools_client = { path = "../../../client", features = ["anchor"] }
1 change: 1 addition & 0 deletions rust-sdk/integration/client/anchor v0.30/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ path = "../../lib.rs"

[dependencies]
anchor-lang = { version = "~0.30.1" }
solana-program = { version = "~1.18.26" }
orca_whirlpools_client = { path = "../../../client", features = ["anchor"] }
5 changes: 1 addition & 4 deletions rust-sdk/integration/client/solana v1.16/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ 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" }
orca_whirlpools_client = { path = "../../../client", features = ["solana-v1"] }
5 changes: 1 addition & 4 deletions rust-sdk/integration/client/solana v1.17/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ path = "../../lib.rs"

[dependencies]
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" }
orca_whirlpools_client = { path = "../../../client", features = ["solana-v1"] }
5 changes: 1 addition & 4 deletions rust-sdk/integration/client/solana v1.18/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ path = "../../lib.rs"

[dependencies]
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" }
orca_whirlpools_client = { path = "../../../client", features = ["solana-v1"] }
10 changes: 10 additions & 0 deletions rust-sdk/integration/client/solana v2.0/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "orca_whirlpools_client_integration_solana_v2_0"
edition = "2021"

[lib]
path = "../../lib.rs"

[dependencies]
solana-program = { version = "~2.0.25" }
orca_whirlpools_client = { path = "../../../client" }
10 changes: 10 additions & 0 deletions rust-sdk/integration/client/solana v2.1/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "orca_whirlpools_client_integration_solana_v2_1"
edition = "2021"

[lib]
path = "../../lib.rs"

[dependencies]
solana-program = { version = "~2.1.13" }
orca_whirlpools_client = { path = "../../../client" }
10 changes: 10 additions & 0 deletions rust-sdk/integration/client/solana v2.2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "orca_whirlpools_client_integration_solana_v2_2"
edition = "2021"

[lib]
path = "../../lib.rs"

[dependencies]
solana-program = { version = "~2.2.0" }
orca_whirlpools_client = { path = "../../../client" }
79 changes: 60 additions & 19 deletions rust-sdk/integration/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,79 @@
import assert from "assert";
import { execSync } from "child_process";
import { readdirSync } from "fs";
import { existsSync, readdirSync, readFileSync, rmSync } from "fs";
import { describe, it } from "vitest";
import { parse } from "smol-toml";
import { coerce } from "semver";

const clientConfigs = readdirSync("./client");
const coreConfigs = readdirSync("./core");
const whirlpoolConfigs = readdirSync("./whirlpool");
type Cargofile = {
dependencies: Record<string, string | { version?: string }>;
};

type Lockfile = {
package: {
name: string;
version: string;
}[];
};

function configs(path: string) {
return readdirSync(path).filter((folder) =>
existsSync(`${path}/${folder}/Cargo.toml`),
);
}

const clientConfigs = configs("./client");
const coreConfigs = configs("./core");
const whirlpoolConfigs = configs("./whirlpool");

function exec(...command: string[]) {
try {
return execSync(command.join(" && ")).toString();
return execSync(command.join(" ")).toString();
} catch (error) {
assert.fail(`${error}`);
}
}

function normalizeVersion(version: string) {
return coerce(version)?.version ?? version;
}

function getOverwrites(path: string): Map<string, string> {
const toml = parse(readFileSync(`${path}/Cargo.toml`, "utf-8")) as Cargofile;
const overwrites: Map<string, string> = new Map();
for (const [name, spec] of Object.entries(toml.dependencies)) {
if (typeof spec === "string") {
overwrites.set(name, normalizeVersion(spec));
}
if (typeof spec === "object" && spec.version) {
overwrites.set(name, normalizeVersion(spec.version));
}
}
return overwrites;
}

function findExistingVersions(path: string, name: string): Set<string> {
const toml = parse(readFileSync(`${path}/Cargo.lock`, "utf-8")) as Lockfile;
const existingVersions: Set<string> = new Set();
for (const dep of toml.package) {
if (dep.name !== name) continue;
existingVersions.add(normalizeVersion(dep.version));
}
return existingVersions;
}

function check(path: string) {
const versions = exec(`awk '/version = "[^"]*"/' '${path}/Cargo.toml'`);
const overwrites = getOverwrites(path);
if (existsSync(`${path}/Cargo.lock`)) {
rmSync(`${path}/Cargo.lock`);
}
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 [name, version] of overwrites) {
const existingVersions = findExistingVersions(path, name);
existingVersions.delete(version);
for (const existingVersion of existingVersions) {
const specifier = existingVersion.slice(2, -2).replaceAll(" ", ":");
exec(
`cargo update ${specifier} --precise ${match[2]} --manifest-path '${path}/Cargo.toml'`,
`cargo update ${name}:${existingVersion} --precise ${version} --manifest-path '${path}/Cargo.toml'`,
);
}
}
Expand Down
6 changes: 4 additions & 2 deletions rust-sdk/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"private": true,
"scripts": {
"build": "tsc --noEmit",
"test": "vitest run index.test.ts --test-timeout 60000",
"clean": "rimraf --glob ./**/Cargo.lock ./**/target || true"
"test": "vitest run index.test.ts --test-timeout 60000"
},
"devDependencies": {
"@orca-so/whirlpools-rust": "*",
"@orca-so/whirlpools-rust-client": "*",
"@orca-so/whirlpools-rust-core": "*",
"@types/semver": "^7.5.8",
"semver": "^7.7.1",
"smol-toml": "^1.3.1",
"typescript": "^5.7.3"
}
}
16 changes: 16 additions & 0 deletions rust-sdk/integration/whirlpool/solana v1.17/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "orca_whirlpools_integration_solana_v1_17"
edition = "2021"

[lib]
path = "../../lib.rs"

[dependencies]
solana-account-decoder = { version = "~1.17.3" }
solana-sdk = { version = "~1.17.3" }
spl-associated-token-account = { version = "~2.3.0" }
spl-token = { version = "~3.5.0" }
spl-memo = { version = "~3.0.1" }
spl-token-2022 = { version = "~1.0.0" }
solana-program = { version = "~1.17.3" }
orca_whirlpools = { path = "../../../whirlpool", features = ["solana-v1"] }
11 changes: 7 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,11 @@ edition = "2021"
path = "../../lib.rs"

[dependencies]
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" }
solana-sdk = { version = "~1.18.26" }
spl-associated-token-account = { version = "~3.0.4" }
spl-token = { version = "~4.0.0" }
spl-memo = { version = "~4.0.4" }
spl-token-2022 = { version = "~3.0.5" }
solana-program = { version = "~1.18.26" }
orca_whirlpools = { path = "../../../whirlpool", features = ["solana-v1"] }
16 changes: 16 additions & 0 deletions rust-sdk/integration/whirlpool/solana v2.0/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "orca_whirlpools_integration_solana_v2_0"
edition = "2021"

[lib]
path = "../../lib.rs"

[dependencies]
solana-account-decoder = { version = "~2.0.25" }
solana-sdk = { version = "~2.0.25" }
spl-associated-token-account = { version = "~4.0.0" }
spl-token = { version = "~6.0.0" }
spl-memo = { version = "~5.0.0" }
spl-token-2022 = { version = "~4.0.0" }
solana-program = { version = "~2.0.25" }
orca_whirlpools = { path = "../../../whirlpool" }
Loading

0 comments on commit bb778c4

Please sign in to comment.