Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"typescript": "^4.3.5",
"typescript": "^5.3.0",
"prettier": "^2.6.2",
"@coral-xyz/anchor-errors": "^0.30.1",
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @coral-xyz/anchor-errors version constraint ^0.30.1 is inconsistent with the upgraded @coral-xyz/anchor version ^0.31.0, which depends on @coral-xyz/anchor-errors@^0.31.1. While yarn's lockfile will resolve this to 0.31.1 (as seen in yarn.lock), it's better to keep the version constraint in package.json aligned with the main dependency to avoid confusion. Consider updating this to ^0.31.1.

Suggested change
"@coral-xyz/anchor-errors": "^0.30.1",
"@coral-xyz/anchor-errors": "^0.31.1",

Copilot uses AI. Check for mistakes.
"@solana/spl-token": "^0.4.13",
"@solana/web3.js": "^1.95.3",
"@solana/web3.js": "^1.98.0",
"solana-bankrun": "^0.3.1",
"@solana/spl-token-metadata": "^0.1.6"
},
"resolutions": {
"@solana/web3.js": "1.98.0",
"**/@solana/web3.js": "1.98.0"
}
}
}
31 changes: 31 additions & 0 deletions programs/cp-amm/src/tests/extract_vectors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::curve;

#[test]
fn extract_and_print_reserve_vectors() {
// Vectors to extract: (liquidity, sqrt_min, sqrt_price, sqrt_max)
let vectors: &[(u128, u128, u128, u128)] = &[
(1_000_000_000u128, 1u128 << 64, 2u128 << 64, 4u128 << 64),
(
5_000_000_000u128,
(3u128 << 64) / 2u128,
2u128 << 64,
8u128 << 64,
),
(10_000_000_000u128, 1u128 << 64, 3u128 << 64, 6u128 << 64),
// additional vectors for coverage
(1_000_000_000u128, 1u128 << 64, 1u128 << 64, 2u128 << 64),
(
2_000_000_000u128,
(5u128 << 64) / 4u128,
(7u128 << 64) / 4u128,
4u128 << 64,
),
];

for (i, (liquidity, smin, sp, smax)) in vectors.iter().enumerate() {
match curve::get_initialize_amounts(*smin, *smax, *sp, *liquidity) {
Ok((a, b)) => println!("V{}: liquidity={} sqrt_min={} sqrt_price={} sqrt_max={} => reserve_a={} reserve_b={}", i, liquidity, smin, sp, smax, a, b),
Err(e) => println!("V{}: error computing reserves: {:?}", i, e),
}
}
}
3 changes: 3 additions & 0 deletions programs/cp-amm/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ mod test_rate_limiter;

#[cfg(test)]
mod layout_test;

#[cfg(test)]
mod extract_vectors;
6 changes: 3 additions & 3 deletions tests/addLiquidity.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AccountLayout } from "@solana/spl-token";
import { ProgramTestContext } from "solana-bankrun";
import { BanksClient, ProgramTestContext } from "solana-bankrun";
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BanksClient import is unused. It's only accessed via context.banksClient and there are no type annotations using BanksClient directly in this file. Consider removing it from the import statement.

Suggested change
import { BanksClient, ProgramTestContext } from "solana-bankrun";
import { ProgramTestContext } from "solana-bankrun";

Copilot uses AI. Check for mistakes.
import { convertToByteArray, generateKpAndFund, randomID, startTest } from "./bankrun-utils/common";
import { Keypair, PublicKey } from "@solana/web3.js";
import BN from "bn.js";
import { expect } from "chai";
Expand All @@ -19,7 +20,6 @@ import {
mintSplTokenTo,
U64_MAX,
} from "./bankrun-utils";
import { generateKpAndFund, randomID, startTest, convertToByteArray } from "./bankrun-utils/common";
import {
createToken2022,
createTransferFeeExtensionWithInstruction,
Expand Down Expand Up @@ -487,4 +487,4 @@ describe("Add liquidity", () => {
expect(preTokenAVaultBalance).eq(postTokenAVaultBalance);
});
});
});
});
16 changes: 1 addition & 15 deletions tests/bankrun-utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,7 @@ export async function expectThrowsAsync(
throw new Error("Expected an error but didn't get one");
}

export function getCpAmmProgramErrorCodeHexString(errorMessage: String) {
const error = CpAmmIdl.errors.find(
(e) =>
e.name.toLowerCase() === errorMessage.toLowerCase() ||
e.msg.toLowerCase() === errorMessage.toLowerCase()
);

if (!error) {
throw new Error(
`Unknown stake for fee error message / name: ${errorMessage}`
);
}

return "0x" + error.code.toString(16);
}
// getCpAmmProgramErrorCodeHexString moved to cpAmm.ts to avoid duplicate exports

export async function generateKpAndFund(
banksClient: BanksClient,
Expand Down
2 changes: 1 addition & 1 deletion tests/rateLimiter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
convertToRateLimiterSecondFactor,
expectThrowsAsync,
generateKpAndFund,
getCpAmmProgramErrorCodeHexString,
processTransactionMaybeThrow,
randomID,
startTest,
warpSlotBy,
} from "./bankrun-utils/common";
import { getCpAmmProgramErrorCodeHexString } from "./bankrun-utils";
import {
Keypair,
LAMPORTS_PER_SOL,
Expand Down
19 changes: 14 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
{
"compilerOptions": {
"types": ["mocha", "chai"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"skipLibCheck": true,
"types": [
"mocha",
"chai"
],
"typeRoots": [
"./node_modules/@types"
],
"lib": [
"es2020",
"es2020.bigint"
],
"module": "commonjs",
"target": "es6",
"target": "es2020",
"esModuleInterop": true,
"resolveJsonModule": true
}
}
}
113 changes: 32 additions & 81 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,34 @@
resolved "https://registry.yarnpkg.com/@coral-xyz/anchor-errors/-/anchor-errors-0.30.1.tgz#bdfd3a353131345244546876eb4afc0e125bec30"
integrity sha512-9Mkradf5yS5xiLWrl9WrpjqOrAV+/W2RQHDlbnAZBivoGpOs1ECjoDCkVk4aRG8ZdiFiB8zQEVlxf+8fKkmSfQ==

"@coral-xyz/anchor@^0.29.0":
version "0.29.0"
resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.29.0.tgz#bd0be95bedfb30a381c3e676e5926124c310ff12"
integrity sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA==
dependencies:
"@coral-xyz/borsh" "^0.29.0"
"@coral-xyz/anchor-errors@^0.31.1":
version "0.31.1"
resolved "https://registry.yarnpkg.com/@coral-xyz/anchor-errors/-/anchor-errors-0.31.1.tgz#d635cbac2533973ae6bfb5d3ba1de89ce5aece2d"
integrity sha512-NhNEku4F3zzUSBtrYz84FzYWm48+9OvmT1Hhnwr6GnPQry2dsEqH/ti/7ASjjpoFTWRnPXrjAIT1qM6Isop+LQ==

"@coral-xyz/anchor@^0.31.0":
version "0.31.1"
resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.31.1.tgz#0fdeebf45a3cb2e47e8ebbb815ca98542152962c"
integrity sha512-QUqpoEK+gi2S6nlYc2atgT2r41TT3caWr/cPUEL8n8Md9437trZ68STknq897b82p5mW0XrTBNOzRbmIRJtfsA==
dependencies:
"@coral-xyz/anchor-errors" "^0.31.1"
"@coral-xyz/borsh" "^0.31.1"
"@noble/hashes" "^1.3.1"
"@solana/web3.js" "^1.68.0"
"@solana/web3.js" "^1.69.0"
bn.js "^5.1.2"
bs58 "^4.0.1"
buffer-layout "^1.2.2"
camelcase "^6.3.0"
cross-fetch "^3.1.5"
crypto-hash "^1.3.0"
eventemitter3 "^4.0.7"
pako "^2.0.3"
snake-case "^3.0.4"
superstruct "^0.15.4"
toml "^3.0.0"

"@coral-xyz/borsh@^0.29.0":
version "0.29.0"
resolved "https://registry.yarnpkg.com/@coral-xyz/borsh/-/borsh-0.29.0.tgz#79f7045df2ef66da8006d47f5399c7190363e71f"
integrity sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ==
"@coral-xyz/borsh@^0.31.1":
version "0.31.1"
resolved "https://registry.yarnpkg.com/@coral-xyz/borsh/-/borsh-0.31.1.tgz#5328e1e0921b75d7f4a62dd3f61885a938bc7241"
integrity sha512-9N8AU9F0ubriKfNE3g1WF0/4dtlGXoBN/hd1PvbNBamBNwRgHxH4P+o3Zt7rSEloW1HUs6LfZEchlx9fW7POYw==
dependencies:
bn.js "^5.1.2"
buffer-layout "^1.2.0"
Expand Down Expand Up @@ -148,18 +152,18 @@
dependencies:
"@solana/codecs" "2.0.0-rc.1"

"@solana/spl-token@^0.4.8":
version "0.4.12"
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.4.12.tgz#09361f9c8116f277b177dbcae7e3a273a19cd48a"
integrity sha512-K6CxzSoO1vC+WBys25zlSDaW0w4UFZO/IvEZquEI35A/PjqXNQHeVigmDCZYEJfESvYarKwsr8tYr/29lPtvaw==
"@solana/spl-token@^0.4.13":
version "0.4.14"
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.4.14.tgz#b86bc8a17f50e9680137b585eca5f5eb9d55c025"
integrity sha512-u09zr96UBpX4U685MnvQsNzlvw9TiY005hk1vJmJr7gMJldoPG1eYU5/wNEyOA5lkMLiR/gOi9SFD4MefOYEsA==
dependencies:
"@solana/buffer-layout" "^4.0.0"
"@solana/buffer-layout-utils" "^0.2.0"
"@solana/spl-token-group" "^0.0.7"
"@solana/spl-token-metadata" "^0.1.6"
buffer "^6.0.3"

"@solana/web3.js@^1.32.0", "@solana/web3.js@^1.68.0", "@solana/web3.js@^1.95.3":
"@solana/web3.js@1.98.0", "@solana/web3.js@^1.32.0", "@solana/web3.js@^1.68.0", "@solana/web3.js@^1.69.0", "@solana/web3.js@^1.98.0":
version "1.98.0"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.98.0.tgz#21ecfe8198c10831df6f0cfde7f68370d0405917"
integrity sha512-nz3Q5OeyGFpFCR+erX2f6JPt3sKhzhYcSycBCSPkWjzSVDh/Rr1FqTVMRe58FKO16/ivTUcuJjeS5MyBvpkbzA==
Expand Down Expand Up @@ -216,14 +220,7 @@
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.1.1.tgz#e7c4f1001eefa4b8afbd1eee27a237fee3bf29c4"
integrity sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==

"@types/node@*":
version "22.13.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.13.1.tgz#a2a3fefbdeb7ba6b89f40371842162fac0934f33"
integrity sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew==
dependencies:
undici-types "~6.20.0"

"@types/node@^12.12.54":
"@types/node@*", "@types/node@^12.12.54":
version "12.20.55"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240"
integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==
Expand Down Expand Up @@ -441,9 +438,9 @@ chalk@^4.1.0:
supports-color "^7.1.0"

chalk@^5.3.0:
version "5.4.1"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.4.1.tgz#1b48bf0963ec158dce2aacf69c093ae2dd2092d8"
integrity sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w==
version "5.6.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.6.2.tgz#b1238b6e23ea337af71c7f8a295db5af0c158aea"
integrity sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==

check-error@^1.0.3:
version "1.0.3"
Expand Down Expand Up @@ -510,11 +507,6 @@ cross-fetch@^3.1.5:
dependencies:
node-fetch "^2.7.0"

crypto-hash@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/crypto-hash/-/crypto-hash-1.3.0.tgz#b402cb08f4529e9f4f09346c3e275942f845e247"
integrity sha512-lyAZ0EMyjDkVvz8WOeVnuCPvKVBXcMv1l5SVqO1yC7PzTwrD/pPje/BIRbWhMoPe436U+Y2nD7f5bFx0kt+Sbg==

debug@4.3.3:
version "4.3.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
Expand Down Expand Up @@ -549,14 +541,6 @@ diff@^3.1.0:
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==

dot-case@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/dot-case/-/dot-case-3.0.4.tgz#9b2b670d00a431667a8a75ba29cd1b98809ce751"
integrity sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==
dependencies:
no-case "^3.0.4"
tslib "^2.0.3"

emoji-regex@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
Expand Down Expand Up @@ -821,13 +805,6 @@ loupe@^2.3.6:
dependencies:
get-func-name "^2.0.1"

lower-case@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/lower-case/-/lower-case-2.0.2.tgz#6fa237c63dbdc4a82ca0fd882e4722dc5e634e28"
integrity sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==
dependencies:
tslib "^2.0.3"

make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
Expand Down Expand Up @@ -904,14 +881,6 @@ nanoid@3.3.1:
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.1.tgz#6347a18cac88af88f58af0b3594b723d5e99bb35"
integrity sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw==

no-case@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/no-case/-/no-case-3.0.4.tgz#d361fd5c9800f558551a8369fc0dcd4662b6124d"
integrity sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==
dependencies:
lower-case "^2.0.2"
tslib "^2.0.3"

node-fetch@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
Expand Down Expand Up @@ -1032,14 +1001,6 @@ serialize-javascript@6.0.0:
dependencies:
randombytes "^2.1.0"

snake-case@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/snake-case/-/snake-case-3.0.4.tgz#4f2bbd568e9935abdfd593f34c691dadb49c452c"
integrity sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==
dependencies:
dot-case "^3.0.4"
tslib "^2.0.3"

solana-bankrun-darwin-arm64@0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/solana-bankrun-darwin-arm64/-/solana-bankrun-darwin-arm64-0.3.1.tgz#65ab6cd2e74eef260c38251f4c53721cf5b9030f"
Expand Down Expand Up @@ -1202,7 +1163,7 @@ tsconfig-paths@^3.5.0:
minimist "^1.2.6"
strip-bom "^3.0.0"

tslib@^2.0.3, tslib@^2.8.0:
tslib@^2.8.0:
version "2.8.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==
Expand All @@ -1212,15 +1173,10 @@ type-detect@^4.0.0, type-detect@^4.1.0:
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.1.0.tgz#deb2453e8f08dcae7ae98c626b13dddb0155906c"
integrity sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==

typescript@^4.3.5:
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

undici-types@~6.20.0:
version "6.20.0"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.20.0.tgz#8171bf22c1f588d1554d55bf204bc624af388433"
integrity sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==
typescript@^5.3.0:
version "5.9.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.9.3.tgz#5b4f59e15310ab17a216f5d6cf53ee476ede670f"
integrity sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==

utf-8-validate@^5.0.2:
version "5.0.10"
Expand Down Expand Up @@ -1288,16 +1244,11 @@ y18n@^5.0.5:
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==

yargs-parser@20.2.4:
yargs-parser@20.2.4, yargs-parser@^20.2.2:
version "20.2.4"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54"
integrity sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==

yargs-parser@^20.2.2:
version "20.2.9"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee"
integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==

yargs-unparser@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz#f131f9226911ae5d9ad38c432fe809366c2325eb"
Expand Down