Skip to content

Commit eb8a38c

Browse files
committed
update legacy-sdk
1 parent e887400 commit eb8a38c

26 files changed

+144
-143
lines changed

.changeset/smooth-cups-visit.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@orca-so/whirlpools-sdk-integration": minor
3+
"@orca-so/whirlpools-sdk": minor
4+
"@orca-so/common-sdk": minor
5+
"@orca-so/whirlpools-sdk-cli": minor
6+
---
7+
8+
Update dependencies to support contract upgrade to Anchor 0.29->0.31.1 and Solana Program 1.17->2.1

legacy-sdk/cli/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"start": "tsx src/index.ts"
99
},
1010
"dependencies": {
11-
"@coral-xyz/anchor": "0.29.0",
11+
"@coral-xyz/anchor": "0.31.0",
1212
"@orca-so/common-sdk": "*",
1313
"@orca-so/whirlpools-sdk": "*",
14-
"@solana/spl-token": "0.4.13",
15-
"@solana/web3.js": "^1.90.0",
14+
"@solana/spl-token": "^0.4.14",
15+
"@solana/web3.js": "^1.98.4",
1616
"@types/bn.js": "^5.1.0",
1717
"bs58": "^6.0.0",
1818
"decimal.js": "^10.5.0",
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { AnchorProvider } from "@coral-xyz/anchor";
2-
import {
3-
ORCA_WHIRLPOOL_PROGRAM_ID,
4-
WhirlpoolContext,
5-
} from "@orca-so/whirlpools-sdk";
2+
import { WhirlpoolContext } from "@orca-so/whirlpools-sdk";
63

74
// export ANCHOR_PROVIDER_URL=http://localhost:8899
85
// export ANCHOR_WALLET=~/.config/solana/id.json
@@ -11,8 +8,4 @@ export const provider = AnchorProvider.env();
118
console.info("connection endpoint", provider.connection.rpcEndpoint);
129
console.info("wallet", provider.wallet.publicKey.toBase58());
1310

14-
export const ctx = WhirlpoolContext.from(
15-
provider.connection,
16-
provider.wallet,
17-
ORCA_WHIRLPOOL_PROGRAM_ID,
18-
);
11+
export const ctx = WhirlpoolContext.from(provider.connection, provider.wallet);

legacy-sdk/common/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
"main": "dist/index.js",
99
"types": "dist/index.d.ts",
1010
"peerDependencies": {
11-
"@solana/spl-token": "^0.4.13",
12-
"@solana/web3.js": "^1.90.0"
11+
"@solana/spl-token": "^0.4.14",
12+
"@solana/web3.js": "^1.98.4"
1313
},
1414
"dependencies": {
1515
"decimal.js": "^10.5.0",
1616
"tiny-invariant": "^1.3.1"
1717
},
1818
"devDependencies": {
19-
"@solana/spl-token": "^0.4.13",
20-
"@solana/web3.js": "^1.90.0",
19+
"@solana/spl-token": "^0.4.14",
20+
"@solana/web3.js": "^1.98.4",
2121
"typescript": "^5.8.2"
2222
},
2323
"scripts": {

legacy-sdk/integration/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"@orca-so/whirlpools-sdk": "*"
77
},
88
"scripts": {
9-
"build": "RUSTUP_TOOLCHAIN=1.78.0 anchor build",
10-
"test": "RUSTUP_TOOLCHAIN=1.78.0 anchor test --skip-build"
9+
"build": "anchor build",
10+
"test": "anchor test --skip-build"
1111
}
1212
}

legacy-sdk/whirlpool/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
"main": "dist/index.js",
77
"types": "dist/index.d.ts",
88
"peerDependencies": {
9-
"@coral-xyz/anchor": "~0.29.0",
10-
"@solana/spl-token": "^0.4.13",
11-
"@solana/web3.js": "^1.90.0"
9+
"@coral-xyz/anchor": "~0.31.0",
10+
"@solana/spl-token": "^0.4.14",
11+
"@solana/web3.js": "^1.98.4"
1212
},
1313
"dependencies": {
1414
"@orca-so/common-sdk": "*",
1515
"decimal.js": "^10.5.0",
1616
"tiny-invariant": "^1.3.1"
1717
},
1818
"devDependencies": {
19-
"@coral-xyz/anchor": "~0.29.0",
19+
"@coral-xyz/anchor": "~0.31.0",
2020
"@orca-so/whirlpools-program": "*",
21-
"@solana/spl-token": "^0.4.13",
22-
"@solana/web3.js": "^1.90.0",
21+
"@solana/spl-token": "^0.4.14",
22+
"@solana/web3.js": "^1.98.4",
2323
"@types/bn.js": "~5.1.6",
2424
"@types/jest": "^29.5.14",
2525
"typescript": "^5.8.2"

legacy-sdk/whirlpool/src/context.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ import type {
77
Wallet,
88
WrappedSolAccountCreateMethod,
99
} from "@orca-so/common-sdk";
10-
import type {
11-
Commitment,
12-
Connection,
13-
PublicKey,
14-
SendOptions,
15-
} from "@solana/web3.js";
10+
import type { Commitment, Connection, SendOptions } from "@solana/web3.js";
1611
import type { Whirlpool } from "./artifacts/whirlpool";
1712
import WhirlpoolIDL from "./artifacts/whirlpool.json";
1813
import type { WhirlpoolAccountFetcherInterface } from "./network/public";
@@ -62,7 +57,6 @@ export class WhirlpoolContext {
6257
public static from(
6358
connection: Connection,
6459
wallet: Wallet,
65-
programId: PublicKey,
6660
fetcher: WhirlpoolAccountFetcherInterface = buildDefaultAccountFetcher(
6761
connection,
6862
),
@@ -73,7 +67,7 @@ export class WhirlpoolContext {
7367
commitment: opts.userDefaultConfirmCommitment || "confirmed",
7468
preflightCommitment: opts.userDefaultConfirmCommitment || "confirmed",
7569
});
76-
const program = new Program(WhirlpoolIDL as Idl, programId, anchorProvider);
70+
const program = new Program(WhirlpoolIDL as Idl, anchorProvider);
7771
return new WhirlpoolContext(
7872
anchorProvider,
7973
anchorProvider.wallet,
@@ -105,14 +99,13 @@ export class WhirlpoolContext {
10599

106100
public static withProvider(
107101
provider: AnchorProvider,
108-
programId: PublicKey,
109102
fetcher: WhirlpoolAccountFetcherInterface = buildDefaultAccountFetcher(
110103
provider.connection,
111104
),
112105
lookupTableFetcher?: LookupTableFetcher,
113106
opts: WhirlpoolContextOpts = {},
114107
): WhirlpoolContext {
115-
const program = new Program(WhirlpoolIDL as Idl, programId, provider);
108+
const program = new Program(WhirlpoolIDL as Idl, provider);
116109
return new WhirlpoolContext(
117110
provider,
118111
provider.wallet,

legacy-sdk/whirlpool/src/network/public/parsing.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import type { Idl } from "@coral-xyz/anchor";
21
import { BorshAccountsCoder } from "@coral-xyz/anchor";
2+
import { convertIdlToCamelCase } from "@coral-xyz/anchor/dist/cjs/idl";
33
import type { ParsableEntity } from "@orca-so/common-sdk";
44
import { staticImplements } from "@orca-so/common-sdk";
55
import type { AccountInfo, PublicKey } from "@solana/web3.js";
6-
import * as WhirlpoolIDL from "../../artifacts/whirlpool.json";
76
import type {
87
FeeTierData,
98
LockConfigData,
@@ -18,7 +17,7 @@ import type {
1817
AdaptiveFeeTierData,
1918
OracleData,
2019
} from "../../types/public";
21-
import { AccountName, toTick } from "../../types/public";
20+
import { AccountName, toTick, WHIRLPOOL_IDL } from "../../types/public";
2221

2322
/**
2423
* @category Network
@@ -102,7 +101,7 @@ export class ParsableTickArray {
102101
const discriminator = accountData.data.subarray(0, 8);
103102
if (
104103
discriminator.equals(
105-
BorshAccountsCoder.accountDiscriminator(AccountName.DynamicTickArray),
104+
WhirlpoolCoder.accountDiscriminator(AccountName.DynamicTickArray),
106105
)
107106
) {
108107
try {
@@ -124,7 +123,7 @@ export class ParsableTickArray {
124123

125124
if (
126125
discriminator.equals(
127-
BorshAccountsCoder.accountDiscriminator(AccountName.TickArray),
126+
WhirlpoolCoder.accountDiscriminator(AccountName.TickArray),
128127
)
129128
) {
130129
try {
@@ -297,15 +296,17 @@ export class ParsableOracle {
297296
}
298297
}
299298

300-
const WhirlpoolCoder = new BorshAccountsCoder(WhirlpoolIDL as Idl);
299+
const WhirlpoolCoder = new BorshAccountsCoder(
300+
convertIdlToCamelCase(WHIRLPOOL_IDL),
301+
);
301302

302303
function parseAnchorAccount(
303304
accountName: AccountName,
304305
accountData: AccountInfo<Buffer>,
305306
) {
306307
const data = accountData.data;
307-
const discriminator = BorshAccountsCoder.accountDiscriminator(accountName);
308-
if (discriminator.compare(data.slice(0, 8))) {
308+
const discriminator = WhirlpoolCoder.accountDiscriminator(accountName);
309+
if (discriminator.compare(data.subarray(0, 8))) {
309310
console.error("incorrect account name during parsing");
310311
return null;
311312
}

legacy-sdk/whirlpool/src/types/public/anchor-types.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Idl } from "@coral-xyz/anchor";
22
import { BN } from "@coral-xyz/anchor";
33
import { BorshAccountsCoder } from "@coral-xyz/anchor";
4+
import { convertIdlToCamelCase } from "@coral-xyz/anchor/dist/cjs/idl";
45
import type { PublicKey } from "@solana/web3.js";
56
import WhirlpoolIDL from "../../artifacts/whirlpool.json";
67

@@ -17,37 +18,41 @@ import WhirlpoolIDL from "../../artifacts/whirlpool.json";
1718
* @category Network
1819
*/
1920
export enum AccountName {
20-
WhirlpoolsConfig = "WhirlpoolsConfig",
21-
Position = "Position",
22-
TickArray = "TickArray",
23-
DynamicTickArray = "DynamicTickArray",
24-
Whirlpool = "Whirlpool",
25-
FeeTier = "FeeTier",
26-
PositionBundle = "PositionBundle",
27-
WhirlpoolsConfigExtension = "WhirlpoolsConfigExtension",
28-
TokenBadge = "TokenBadge",
29-
LockConfig = "LockConfig",
30-
Oracle = "Oracle",
31-
AdaptiveFeeTier = "AdaptiveFeeTier",
21+
WhirlpoolsConfig = "whirlpoolsConfig",
22+
Position = "position",
23+
TickArray = "tickArray",
24+
DynamicTickArray = "dynamicTickArray",
25+
Whirlpool = "whirlpool",
26+
FeeTier = "feeTier",
27+
PositionBundle = "positionBundle",
28+
WhirlpoolsConfigExtension = "whirlpoolsConfigExtension",
29+
TokenBadge = "tokenBadge",
30+
LockConfig = "lockConfig",
31+
Oracle = "oracle",
32+
AdaptiveFeeTier = "adaptiveFeeTier",
3233
}
3334

3435
export const WHIRLPOOL_IDL = WhirlpoolIDL as Idl;
3536

3637
/**
3738
* The Anchor coder for the Whirlpool program.
3839
* @category Solana Accounts
40+
*
41+
* BorshAccountsCoder does not handle the snake -> camel case
42+
* mapping handled internally by the normal Anchor coder, so
43+
* we must handle ourselves.
3944
*/
40-
export const WHIRLPOOL_CODER = new BorshAccountsCoder(WHIRLPOOL_IDL);
45+
export const WHIRLPOOL_CODER = new BorshAccountsCoder(
46+
convertIdlToCamelCase(WHIRLPOOL_IDL),
47+
);
4148

4249
/**
4350
* Get the size of an account owned by the Whirlpool program in bytes.
4451
* @param accountName Whirlpool account name
4552
* @returns Size in bytes of the account
4653
*/
4754
export function getAccountSize(accountName: AccountName) {
48-
const size = WHIRLPOOL_CODER.size(
49-
WHIRLPOOL_IDL.accounts!.find((account) => account.name === accountName)!,
50-
);
55+
const size = WHIRLPOOL_CODER.size(accountName);
5156
return size + RESERVED_BYTES[accountName];
5257
}
5358

legacy-sdk/whirlpool/tests/integration/adaptive-fee/initialize_pool_with_adaptive_fee.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2619,7 +2619,7 @@ describe("initialize_pool_with_adaptive_fee", () => {
26192619
let eventVerified = false;
26202620
let detectedSignature = null;
26212621
const listener = ctx.program.addEventListener(
2622-
"PoolInitialized",
2622+
"poolInitialized",
26232623
(event, _slot, signature) => {
26242624
detectedSignature = signature;
26252625
// verify

0 commit comments

Comments
 (0)