@picon-finance/dlmm-sdk 1.13.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +43 -7
  2. package/dist/entities/dlmm_program.d.ts +18 -5
  3. package/dist/entities/dlmm_program.d.ts.map +1 -1
  4. package/dist/entities/dlmm_program.js +12 -4
  5. package/dist/entities/pool.d.ts +18 -5
  6. package/dist/entities/pool.d.ts.map +1 -1
  7. package/dist/entities/pool.js +107 -18
  8. package/dist/entities/position.js +5 -5
  9. package/dist/generated/instructions/index.d.ts +2 -1
  10. package/dist/generated/instructions/index.d.ts.map +1 -1
  11. package/dist/generated/instructions/index.js +2 -1
  12. package/dist/generated/instructions/swapExactIn.d.ts +78 -0
  13. package/dist/generated/instructions/swapExactIn.d.ts.map +1 -0
  14. package/dist/generated/instructions/{swap.js → swapExactIn.js} +13 -13
  15. package/dist/generated/instructions/swapExactOut.d.ts +78 -0
  16. package/dist/generated/instructions/swapExactOut.d.ts.map +1 -0
  17. package/dist/generated/instructions/swapExactOut.js +111 -0
  18. package/dist/generated/programs/piconDlmm.d.ts +12 -8
  19. package/dist/generated/programs/piconDlmm.d.ts.map +1 -1
  20. package/dist/generated/programs/piconDlmm.js +23 -11
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -0
  24. package/dist/picon_dlmm.json +101 -12
  25. package/dist/quote/index.d.ts +6 -4
  26. package/dist/quote/index.d.ts.map +1 -1
  27. package/dist/quote/index.js +12 -4
  28. package/dist/quote/wasm-node/picon_dlmm_quote.d.ts +49 -6
  29. package/dist/quote/wasm-node/picon_dlmm_quote.js +34 -9
  30. package/dist/quote/wasm-node/picon_dlmm_quote_bg.wasm +0 -0
  31. package/dist/quote/wasm-node/picon_dlmm_quote_bg.wasm.d.ts +4 -2
  32. package/dist/quote/wasm-web/picon_dlmm_quote.d.ts +53 -8
  33. package/dist/quote/wasm-web/picon_dlmm_quote.js +34 -9
  34. package/dist/quote/wasm-web/picon_dlmm_quote_bg.wasm +0 -0
  35. package/dist/quote/wasm-web/picon_dlmm_quote_bg.wasm.d.ts +4 -2
  36. package/dist/utils/price.d.ts +4 -0
  37. package/dist/utils/price.d.ts.map +1 -0
  38. package/dist/utils/price.js +27 -0
  39. package/dist/utils/u64x64.d.ts +6 -0
  40. package/dist/utils/u64x64.d.ts.map +1 -0
  41. package/dist/utils/u64x64.js +25 -0
  42. package/package.json +1 -1
  43. package/src/entities/dlmm_program.ts +26 -7
  44. package/src/entities/pool.ts +171 -25
  45. package/src/entities/position.ts +5 -5
  46. package/src/generated/instructions/index.ts +2 -1
  47. package/src/generated/instructions/{swap.ts → swapExactIn.ts} +33 -31
  48. package/src/generated/instructions/swapExactOut.ts +349 -0
  49. package/src/generated/programs/piconDlmm.ts +54 -17
  50. package/src/index.ts +2 -1
  51. package/src/picon_dlmm.json +101 -12
  52. package/src/quote/index.ts +34 -8
  53. package/src/quote/wasm-node/picon_dlmm_quote.d.ts +49 -6
  54. package/src/quote/wasm-node/picon_dlmm_quote.js +34 -9
  55. package/src/quote/wasm-node/picon_dlmm_quote_bg.wasm +0 -0
  56. package/src/quote/wasm-node/picon_dlmm_quote_bg.wasm.d.ts +4 -2
  57. package/src/quote/wasm-web/picon_dlmm_quote.d.ts +53 -8
  58. package/src/quote/wasm-web/picon_dlmm_quote.js +34 -9
  59. package/src/quote/wasm-web/picon_dlmm_quote_bg.wasm +0 -0
  60. package/src/quote/wasm-web/picon_dlmm_quote_bg.wasm.d.ts +4 -2
  61. package/src/utils/price.ts +32 -0
  62. package/src/utils/u64x64.ts +28 -0
  63. package/dist/generated/instructions/swap.d.ts +0 -78
  64. package/dist/generated/instructions/swap.d.ts.map +0 -1
package/README.md CHANGED
@@ -36,8 +36,10 @@ const dlmmProgram = new DlmmProgram(rpc, DEVNET_PROGRAM_ADDRESS);
36
36
  // Fetch and cache a pool's account data, mints, and token programs in one call.
37
37
  const pool = await dlmmProgram.getPool(poolAddress);
38
38
 
39
- // Quote, then build the matching swap instructions against that same quote.
40
- const { quoteOutput, instructions } = await pool.quoteAndSwap(userSigner, {
39
+ // Pool.swapExactIn() quotes internally (right-sizing exactly which bin arrays it needs) and
40
+ // returns both the quote and the matching swap instructions built against it no separate
41
+ // quote step. Pool.swapExactOut() is the mirror image, fixing the output instead of the input.
42
+ const { quoteOutput, instructions } = await pool.swapExactIn(userSigner, {
41
43
  xToY: true,
42
44
  amountIn: 1_000_000n,
43
45
  slippageToleranceBps: 50,
@@ -123,17 +125,33 @@ const { transferFeeX, transferFeeY } = await pool.getTransferFees();
123
125
  const { baseFeeRate, dynamicFeeRate, totalFeeRate } = await pool.getFeeRates();
124
126
  ```
125
127
 
126
- `swap`/`quote`/`quoteAndSwap`/`sync` all accept an optional `binArrayCount` (default: the protocol max for that instruction) to cap how many bin arrays get included useful for capping compute/account budget on a swap you know won't need the full range. It must be at least 2 (one below the active bin array's index and the active bin array itself, or vice versa the active bin array is always required):
128
+ `swapExactIn`/`swapExactOut`/`quoteExactIn`/`quoteExactOut`/`sync` don't take a bin-array-count parameter the quote methods always quote against the protocol max traversal window (`MAX_BIN_ARRAYS_PER_TRAVERSAL`) internally, then the matching swap method trims the bin-array set down to only what the quote says it actually needs (plus a one-array drift margin), so you never pay for more accounts than the trade is likely to touch:
127
129
 
128
130
  ```ts
129
- const instructions = await pool.swap(userSigner, {
131
+ // quoteExactIn() is a thin wrapper — same internal fetch/simulate/trim as swapExactIn(), just
132
+ // returns the QuoteExactInOutput without building instructions.
133
+ const quoteOutput = await pool.quoteExactIn({ xToY: true, amountIn: 1_000_000n, slippageToleranceBps: 50 });
134
+
135
+ const { quoteOutput: sameQuote, instructions } = await pool.swapExactIn(userSigner, {
130
136
  xToY: true,
131
137
  amountIn: 1_000_000n,
132
- minAmountOut: 0n,
133
- binArrayCount: 4,
138
+ slippageToleranceBps: 50,
139
+ });
140
+
141
+ // swapExactOut()/quoteExactOut() fix the output amount instead — the trader specifies exactly
142
+ // what they want to receive, and pays whatever gross input that requires (capped by
143
+ // slippageToleranceBps via QuoteExactOutOutput.maxAmountIn).
144
+ const { quoteOutput: exactOutQuote, instructions: exactOutInstructions } = await pool.swapExactOut(userSigner, {
145
+ xToY: true,
146
+ amountOut: 1_000_000n,
147
+ slippageToleranceBps: 50,
134
148
  });
135
149
  ```
136
150
 
151
+ `Pool.sync(user, desiredBinId)` repositions the pool's active bin toward `desiredBinId` across empty bins only — also always uses the max traversal window, no count parameter.
152
+
153
+ If either mint carries an active Token-2022 `TransferHook` extension, `swapExactIn()`/`swapExactOut()` (and every position method below) resolve and append its extra accounts automatically — nothing to configure. `Pool.resolveTransferHookAccountsX(transferAccounts)`/`resolveTransferHookAccountsY(transferAccounts)` are exposed publicly if you need to resolve them yourself for a custom instruction.
154
+
137
155
  Refresh a position's cached state after it changes on-chain (e.g. after a deposit lands):
138
156
 
139
157
  ```ts
@@ -159,7 +177,7 @@ Or fetch a single position directly if you already know its address:
159
177
  const positionByAddress = await pool.getPosition(positionAddress);
160
178
  ```
161
179
 
162
- Claim fees across many positions at once with `Position.claimAllFees()` — it skips positions with nothing pending (checked locally, no extra RPC) and batches the rest into `MAX_POSITIONS_PER_CLAIM`-sized (overridable via a third argument) instruction groups, one per transaction, sharing a single set of ATA setup/teardown instructions across the whole batch rather than repeating them per position. All positions must belong to the same pool:
180
+ Claim fees across many positions at once with `Position.claimAllFees()` — it skips positions with nothing pending (checked locally, no extra RPC) and batches the rest into `DEFAULT_POSITIONS_PER_CLAIM`-sized (overridable via a third argument) instruction groups, one per transaction, sharing a single set of ATA setup/teardown instructions across the whole batch rather than repeating them per position. All positions must belong to the same pool:
163
181
 
164
182
  ```ts
165
183
  const positions = await pool.getAllPositionsByPositionMints(positionMints);
@@ -170,6 +188,24 @@ for (const claimIxs of claimTxs) {
170
188
  }
171
189
  ```
172
190
 
191
+ ### Admin
192
+
193
+ `Pool.claimProtocolFee(authority)` drains `pool.data.protocolFeeX`/`protocolFeeY` to the admin's associated token accounts — `authority` must match `AdminConfig.authority`. `Pool.setProtocolShare(authority, protocolShare)` and `Pool.setDynamicFeeConfig(authority, config)` are similarly admin-gated single instructions:
194
+
195
+ ```ts
196
+ const claimProtocolFeeIxs = await pool.claimProtocolFee(adminSigner);
197
+ ```
198
+
199
+ ### Price math
200
+
201
+ `getBaseBinPrice(binStep)`, `getBinPrice(baseBinPrice, binId)`, and `getBinPriceFromStep(binStep, binId)` are direct `bigint` ports of the on-chain Q64.64 price math (`bin_math.rs`'s `base_bin_price`/`bin_price`/`bin_price_from_step`) — useful for computing a bin's price without an RPC round trip, e.g. when picking `lowerBinId`/`upperBinId` for a new position before it exists on-chain. `getBinPrice`/`getBinPriceFromStep` return `undefined` (mirroring the Rust `Option`) if `binId` is outside the representable range for that `binStep`:
202
+
203
+ ```ts
204
+ import { getBinPriceFromStep } from "@picon-finance/dlmm-sdk";
205
+
206
+ const rawPrice = getBinPriceFromStep(pool.data.binStep, pool.activeBinId); // Q64.64, or undefined
207
+ ```
208
+
173
209
  ### Events
174
210
 
175
211
  Event decoding and subscriptions are a separate, opt-in feature under the `events` namespace — independent of `DlmmProgram`/`Pool`/`Position`/`BinArray`:
@@ -1,5 +1,5 @@
1
1
  import { createSolanaRpc, type Address, type Account, type Instruction, type TransactionSigner, type FetchAccountConfig, type FetchAccountsConfig } from "@solana/kit";
2
- import type { QuoteOutput } from "../quote";
2
+ import type { QuoteExactInOutput, QuoteExactOutOutput } from "../quote";
3
3
  import { Pool } from "./pool";
4
4
  import { generated } from "..";
5
5
  export declare class DlmmProgram {
@@ -18,19 +18,32 @@ export declare class DlmmProgram {
18
18
  tokenProgramX: Address;
19
19
  tokenProgramY: Address;
20
20
  }): Promise<Instruction>;
21
- swap(user: TransactionSigner, poolAddress: Address, params: {
21
+ swapExactIn(user: TransactionSigner, poolAddress: Address, params: {
22
22
  xToY: boolean;
23
23
  amountIn: bigint;
24
24
  slippageToleranceBps: number;
25
25
  }, config?: FetchAccountConfig): Promise<{
26
- quoteOutput: QuoteOutput;
26
+ quoteOutput: QuoteExactInOutput;
27
27
  instructions: Instruction[];
28
28
  }>;
29
- quote(poolAddress: Address, params: {
29
+ swapExactOut(user: TransactionSigner, poolAddress: Address, params: {
30
+ xToY: boolean;
31
+ amountOut: bigint;
32
+ slippageToleranceBps: number;
33
+ }, config?: FetchAccountConfig): Promise<{
34
+ quoteOutput: QuoteExactOutOutput;
35
+ instructions: Instruction[];
36
+ }>;
37
+ quoteExactIn(poolAddress: Address, params: {
30
38
  xToY: boolean;
31
39
  amountIn: bigint;
32
40
  slippageToleranceBps: number;
33
- }, config?: FetchAccountConfig): Promise<QuoteOutput>;
41
+ }, config?: FetchAccountConfig): Promise<QuoteExactInOutput>;
42
+ quoteExactOut(poolAddress: Address, params: {
43
+ xToY: boolean;
44
+ amountOut: bigint;
45
+ slippageToleranceBps: number;
46
+ }, config?: FetchAccountConfig): Promise<QuoteExactOutOutput>;
34
47
  getAllPositionMintsByOwner(owner: Address, config?: FetchAccountsConfig): Promise<Map<Address, Address[]>>;
35
48
  createAdminConfig(deployer: TransactionSigner): Promise<Instruction>;
36
49
  resetAdminAuthority(deployer: TransactionSigner): Promise<Instruction>;
@@ -1 +1 @@
1
- {"version":3,"file":"dlmm_program.d.ts","sourceRoot":"","sources":["../../src/entities/dlmm_program.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,WAAW,EAEhB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EAGzB,MAAM,aAAa,CAAC;AAOrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EACL,IAAI,EAEL,MAAM,QAAQ,CAAC;AAYhB,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/B,qBAAa,WAAW;;IAItB,YACE,GAAG,EAAE,UAAU,CAAC,OAAO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AAA;KAAE,EACzE,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CAG7B;IAEY,aAAa,CACxB,WAAW,EAAE,OAAO,EACpB,MAAM,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,oBAAoB,EAAE,MAAM,CAAA;KAAE,EAC1E,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CAG9B;IAEY,0BAA0B,CACrC,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CA+BlC;IAEY,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAKhF;IAEY,mBAAmB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAKlF;IAEY,sBAAsB,CACjC,SAAS,EAAE,iBAAiB,EAC5B,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC,WAAW,CAAC,CAKtB;IAEY,oBAAoB,CAC/B,gBAAgB,EAAE,iBAAiB,GAClC,OAAO,CAAC,WAAW,CAAC,CAKtB;IAEY,0BAA0B,CACrC,SAAS,EAAE,iBAAiB,EAC5B,uBAAuB,EAAE,OAAO,GAC/B,OAAO,CAAC,WAAW,CAAC,CAKtB;IAEY,cAAc,CACzB,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAKzC;IAEY,mBAAmB,CAC9B,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,OAAO,CAAC,CAKlB;CACF"}
@@ -20,13 +20,21 @@ export class DlmmProgram {
20
20
  async createPool(authority, params) {
21
21
  return await createPool({ authority, ...params }, { programAddress: this.#programAddress });
22
22
  }
23
- async swap(user, poolAddress, params, config) {
23
+ async swapExactIn(user, poolAddress, params, config) {
24
24
  const pool = await this.getPool(poolAddress, config);
25
- return await pool.swap(user, params);
25
+ return await pool.swapExactIn(user, params);
26
26
  }
27
- async quote(poolAddress, params, config) {
27
+ async swapExactOut(user, poolAddress, params, config) {
28
28
  const pool = await this.getPool(poolAddress, config);
29
- return await pool.quote(params);
29
+ return await pool.swapExactOut(user, params);
30
+ }
31
+ async quoteExactIn(poolAddress, params, config) {
32
+ const pool = await this.getPool(poolAddress, config);
33
+ return await pool.quoteExactIn(params);
34
+ }
35
+ async quoteExactOut(poolAddress, params, config) {
36
+ const pool = await this.getPool(poolAddress, config);
37
+ return await pool.quoteExactOut(params);
30
38
  }
31
39
  async getAllPositionMintsByOwner(owner, config) {
32
40
  const { commitment, minContextSlot, abortSignal } = config ?? {};
@@ -1,6 +1,6 @@
1
1
  import { createSolanaRpc, type Address, type Account, type Instruction, type TransactionSigner, type FetchAccountConfig, type FetchAccountsConfig } from "@solana/kit";
2
2
  import { generated } from "..";
3
- import { type FeeRates, type QuoteOutput, type TransferFee } from "../quote";
3
+ import { type FeeRates, type QuoteExactInOutput, type QuoteExactOutOutput, type TransferFee } from "../quote";
4
4
  import { type ExtraAccount, type TransferAccounts as TransferHookAccounts } from "../utils/transfer_hook";
5
5
  import { Position } from "./position";
6
6
  import { type ProgramConfig } from "./types";
@@ -35,21 +35,34 @@ export declare class Pool {
35
35
  upperBinId: number;
36
36
  }): Promise<Instruction[]>;
37
37
  closePosition(owner: TransactionSigner, positionMint: Address): Promise<Instruction>;
38
- swap(user: TransactionSigner, { xToY, amountIn, slippageToleranceBps, }: {
38
+ swapExactIn(user: TransactionSigner, { xToY, amountIn, slippageToleranceBps, }: {
39
39
  xToY: boolean;
40
40
  amountIn: bigint;
41
41
  slippageToleranceBps: number;
42
42
  }): Promise<{
43
- quoteOutput: QuoteOutput;
43
+ quoteOutput: QuoteExactInOutput;
44
+ instructions: Instruction[];
45
+ }>;
46
+ swapExactOut(user: TransactionSigner, { xToY, amountOut, slippageToleranceBps, }: {
47
+ xToY: boolean;
48
+ amountOut: bigint;
49
+ slippageToleranceBps: number;
50
+ }): Promise<{
51
+ quoteOutput: QuoteExactOutOutput;
44
52
  instructions: Instruction[];
45
53
  }>;
46
54
  resolveTransferHookAccountsX(transferAccounts: TransferHookAccounts): Promise<ExtraAccount[]>;
47
55
  resolveTransferHookAccountsY(transferAccounts: TransferHookAccounts): Promise<ExtraAccount[]>;
48
- quote(params: {
56
+ quoteExactIn(params: {
49
57
  xToY: boolean;
50
58
  amountIn: bigint;
51
59
  slippageToleranceBps: number;
52
- }): Promise<QuoteOutput>;
60
+ }): Promise<QuoteExactInOutput>;
61
+ quoteExactOut(params: {
62
+ xToY: boolean;
63
+ amountOut: bigint;
64
+ slippageToleranceBps: number;
65
+ }): Promise<QuoteExactOutOutput>;
53
66
  sync(user: TransactionSigner, desiredBinId: number): Promise<Instruction[]>;
54
67
  setDynamicFeeConfig(authority: TransactionSigner, dynamicFeeConfig: generated.DynamicFeeConfig): Promise<Instruction>;
55
68
  setProtocolShare(authority: TransactionSigner, protocolShare: number): Promise<Instruction>;
@@ -1 +1 @@
1
- {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/entities/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAMrB,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,WAAW,EACjB,MAAM,UAAU,CAAC;AAUlB,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,gBAAgB,IAAI,oBAAoB,EAC9C,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,QAAQ,EAKT,MAAM,YAAY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ED,wBAAsB,UAAU,CAC9B,EACE,SAAS,EACT,OAAO,EACP,OAAO,EACP,aAAa,EACb,WAAW,EACX,UAAU,EACV,UAAU,EACV,aAAa,EACb,aAAa,GACd,EAAE;IACD,SAAS,EAAE,iBAAiB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;CACxB,EACD,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,WAAW,CAAC,CAkBtB"}
@@ -1,7 +1,7 @@
1
1
  import { AccountRole, } from "@solana/kit";
2
2
  import { fetchAllMint, } from "@solana-program/token-2022";
3
3
  import { generated } from "..";
4
- import { quote, getPoolFeeRates, } from "../quote";
4
+ import { quoteExactIn, quoteExactOut, getPoolFeeRates, } from "../quote";
5
5
  import { isAccount } from "../utils/type_guards";
6
6
  import { resolveAdminConfigAddress } from "./admin_config";
7
7
  import { processAssociatedTokenAccountPair } from "../utils/ata";
@@ -70,8 +70,8 @@ export class Pool {
70
70
  async closePosition(owner, positionMint) {
71
71
  return await closePosition({ owner, positionMint }, { programAddress: this.#programAddress });
72
72
  }
73
- async swap(user, { xToY, amountIn, slippageToleranceBps, }) {
74
- const { quoteOutput, binArrayAddresses } = await this.#quote({ xToY, amountIn, slippageToleranceBps });
73
+ async swapExactIn(user, { xToY, amountIn, slippageToleranceBps, }) {
74
+ const { quoteOutput, binArrayAddresses } = await this.#quoteExactIn({ xToY, amountIn, slippageToleranceBps });
75
75
  const { ataX: tokenUserAccountX, ataY: tokenUserAccountY, preInstructions, postInstructions, } = await processAssociatedTokenAccountPair({
76
76
  owner: user,
77
77
  tokenMintX: this.tokenMintX,
@@ -106,7 +106,7 @@ export class Pool {
106
106
  remainingAccounts.push(...transferHookYAccounts.map(toRemainingAccountMeta));
107
107
  }
108
108
  const remainingAccountsScheme = { groups };
109
- const swapIx = generated.getSwapInstruction({
109
+ const swapIx = generated.getSwapExactInInstruction({
110
110
  user,
111
111
  pool: this.address,
112
112
  tokenMintX: this.tokenMintX,
@@ -126,6 +126,64 @@ export class Pool {
126
126
  const instructions = [...preInstructions, swapIxWithBinArrays, ...postInstructions];
127
127
  return { quoteOutput, instructions };
128
128
  }
129
+ async swapExactOut(user, { xToY, amountOut, slippageToleranceBps, }) {
130
+ const { quoteOutput, binArrayAddresses } = await this.#quoteExactOut({ xToY, amountOut, slippageToleranceBps });
131
+ const { ataX: tokenUserAccountX, ataY: tokenUserAccountY, preInstructions, postInstructions, } = await processAssociatedTokenAccountPair({
132
+ owner: user,
133
+ tokenMintX: this.tokenMintX,
134
+ tokenMintY: this.tokenMintY,
135
+ tokenProgramX: this.tokenProgramX,
136
+ tokenProgramY: this.tokenProgramY,
137
+ // Funds the wSOL leg (if any) with the worst-case input, since the real amount isn't known
138
+ // until the swap executes — any excess is unwrapped back to the owner in postInstructions.
139
+ amountX: xToY ? quoteOutput.maxAmountIn : undefined,
140
+ amountY: xToY ? undefined : quoteOutput.maxAmountIn,
141
+ });
142
+ // Each mint's hook accounts are resolved against whichever role it plays in this swap —
143
+ // input (user -> vault, owner = user) or output (vault -> user, owner = pool PDA).
144
+ const xTransferAccounts = xToY
145
+ ? { source: tokenUserAccountX, mint: this.tokenMintX, destination: this.tokenVaultX, owner: user.address }
146
+ : { source: this.tokenVaultX, mint: this.tokenMintX, destination: tokenUserAccountX, owner: this.address };
147
+ const yTransferAccounts = xToY
148
+ ? { source: this.tokenVaultY, mint: this.tokenMintY, destination: tokenUserAccountY, owner: this.address }
149
+ : { source: tokenUserAccountY, mint: this.tokenMintY, destination: this.tokenVaultY, owner: user.address };
150
+ const [transferHookXAccounts, transferHookYAccounts] = await Promise.all([
151
+ this.resolveTransferHookAccountsX(xTransferAccounts),
152
+ this.resolveTransferHookAccountsY(yTransferAccounts),
153
+ ]);
154
+ const groups = [
155
+ { kind: generated.AccountKind.BinArray, count: binArrayAddresses.length },
156
+ ];
157
+ const remainingAccounts = binArrayAddresses.map(address => ({ address, role: AccountRole.WRITABLE }));
158
+ if (transferHookXAccounts.length > 0) {
159
+ groups.push({ kind: generated.AccountKind.TransferHookX, count: transferHookXAccounts.length });
160
+ remainingAccounts.push(...transferHookXAccounts.map(toRemainingAccountMeta));
161
+ }
162
+ if (transferHookYAccounts.length > 0) {
163
+ groups.push({ kind: generated.AccountKind.TransferHookY, count: transferHookYAccounts.length });
164
+ remainingAccounts.push(...transferHookYAccounts.map(toRemainingAccountMeta));
165
+ }
166
+ const remainingAccountsScheme = { groups };
167
+ const swapIx = generated.getSwapExactOutInstruction({
168
+ user,
169
+ pool: this.address,
170
+ tokenMintX: this.tokenMintX,
171
+ tokenMintY: this.tokenMintY,
172
+ tokenUserAccountX,
173
+ tokenUserAccountY,
174
+ tokenVaultX: this.tokenVaultX,
175
+ tokenVaultY: this.tokenVaultY,
176
+ tokenProgramX: this.tokenProgramX,
177
+ tokenProgramY: this.tokenProgramY,
178
+ amountOut,
179
+ maxAmountIn: quoteOutput.maxAmountIn,
180
+ xToY,
181
+ remainingAccountsScheme,
182
+ }, { programAddress: this.#programAddress });
183
+ const swapIxWithBinArrays = { ...swapIx, accounts: [...swapIx.accounts, ...remainingAccounts] };
184
+ const instructions = [...preInstructions, swapIxWithBinArrays, ...postInstructions];
185
+ return { quoteOutput, instructions };
186
+ }
129
187
  // Public so Position (which only holds a reference to this Pool, not its private mint data)
130
188
  // can resolve hook accounts for its own deposit/withdraw/claimFee instructions without ever
131
189
  // needing a Mint account itself — empty when that mint has no active transfer hook, in which
@@ -142,19 +200,17 @@ export class Pool {
142
200
  return [];
143
201
  return await resolveTransferHookExtraAccounts(this.#rpc, hookProgram, transferAccounts);
144
202
  }
145
- async quote(params) {
146
- const { quoteOutput } = await this.#quote(params);
203
+ async quoteExactIn(params) {
204
+ const { quoteOutput } = await this.#quoteExactIn(params);
147
205
  return quoteOutput;
148
206
  }
149
- async #quote({ xToY, amountIn, slippageToleranceBps, }) {
150
- const indices = generateBinArrayIndicesForSwap(this.activeBinId, xToY, MAX_BIN_ARRAYS_PER_TRAVERSAL);
151
- const maxBinArrayAddresses = await findAllBinArrayAddresses({ pool: this.address, indices }, { programAddress: this.#programAddress });
152
- const [maybeBinArrays, { transferFeeX, transferFeeY }] = await Promise.all([
153
- generated.fetchAllMaybeBinArray(this.#rpc, maxBinArrayAddresses),
154
- this.getTransferFees(),
155
- ]);
156
- const binArrays = maybeBinArrays.map(maybeBinArray => maybeBinArray.exists ? maybeBinArray.data : undefined);
157
- const quoteOutput = await quote({
207
+ async quoteExactOut(params) {
208
+ const { quoteOutput } = await this.#quoteExactOut(params);
209
+ return quoteOutput;
210
+ }
211
+ async #quoteExactIn({ xToY, amountIn, slippageToleranceBps, }) {
212
+ const { indices, maxBinArrayAddresses, binArrays, transferFeeX, transferFeeY } = await this.#resolveSwapBinArrays(xToY);
213
+ const quoteOutput = await quoteExactIn({
158
214
  amountIn,
159
215
  xToY,
160
216
  slippageToleranceBps,
@@ -164,13 +220,46 @@ export class Pool {
164
220
  outputTransferFee: xToY ? transferFeeY : transferFeeX,
165
221
  binArrays,
166
222
  });
223
+ const binArrayAddresses = this.#binArrayAddressesForQuote(xToY, indices, maxBinArrayAddresses, quoteOutput.postActiveBinId);
224
+ return { quoteOutput, binArrayAddresses };
225
+ }
226
+ async #quoteExactOut({ xToY, amountOut, slippageToleranceBps, }) {
227
+ const { indices, maxBinArrayAddresses, binArrays, transferFeeX, transferFeeY } = await this.#resolveSwapBinArrays(xToY);
228
+ const quoteOutput = await quoteExactOut({
229
+ amountOut,
230
+ xToY,
231
+ slippageToleranceBps,
232
+ now: BigInt(Math.floor(Date.now() / 1000)),
233
+ poolState: this.data,
234
+ inputTransferFee: xToY ? transferFeeX : transferFeeY,
235
+ outputTransferFee: xToY ? transferFeeY : transferFeeX,
236
+ binArrays,
237
+ });
238
+ const binArrayAddresses = this.#binArrayAddressesForQuote(xToY, indices, maxBinArrayAddresses, quoteOutput.postActiveBinId);
239
+ return { quoteOutput, binArrayAddresses };
240
+ }
241
+ // The bin array window a quote might touch, before the quote itself narrows down how much of
242
+ // it was actually crossed — shared by both quote directions, which differ only in which
243
+ // `quoteExact{In,Out}` call they make against this same window.
244
+ async #resolveSwapBinArrays(xToY) {
245
+ const indices = generateBinArrayIndicesForSwap(this.activeBinId, xToY, MAX_BIN_ARRAYS_PER_TRAVERSAL);
246
+ const maxBinArrayAddresses = await findAllBinArrayAddresses({ pool: this.address, indices }, { programAddress: this.#programAddress });
247
+ const [maybeBinArrays, { transferFeeX, transferFeeY }] = await Promise.all([
248
+ generated.fetchAllMaybeBinArray(this.#rpc, maxBinArrayAddresses),
249
+ this.getTransferFees(),
250
+ ]);
251
+ const binArrays = maybeBinArrays.map(maybeBinArray => maybeBinArray.exists ? maybeBinArray.data : undefined);
252
+ return { indices, maxBinArrayAddresses, binArrays, transferFeeX, transferFeeY };
253
+ }
254
+ // Narrows the bin array window down to what a quote (already run against the full window)
255
+ // actually needs to re-traverse at swap time, based on where it left the active bin.
256
+ #binArrayAddressesForQuote(xToY, indices, maxBinArrayAddresses, postActiveBinId) {
167
257
  const safeOffset = xToY ? -1 : 1;
168
- const targetBinArrayIndex = getBinArrayIndex(quoteOutput.postActiveBinId) + safeOffset;
258
+ const targetBinArrayIndex = getBinArrayIndex(postActiveBinId) + safeOffset;
169
259
  const localTargetBinArrayIndex = targetBinArrayIndex - indices[0];
170
- const binArrayAddresses = xToY
260
+ return xToY
171
261
  ? maxBinArrayAddresses.slice(Math.max(0, localTargetBinArrayIndex))
172
262
  : maxBinArrayAddresses.slice(0, localTargetBinArrayIndex + 1);
173
- return { quoteOutput, binArrayAddresses };
174
263
  }
175
264
  async sync(user, desiredBinId) {
176
265
  const indices = generateBinArrayIndicesForSync(this.activeBinId, desiredBinId, MAX_BIN_ARRAYS_PER_TRAVERSAL);
@@ -1,6 +1,6 @@
1
1
  import { decodeAccount, assertAccountExists, fetchEncodedAccounts, } from "@solana/kit";
2
2
  import { generated } from "..";
3
- import { applyTransferFee } from "../quote";
3
+ import { getAmountAfterTransferFee } from "../quote";
4
4
  import { findPositionTokenAccount, processAssociatedTokenAccountPair, } from "../utils/ata";
5
5
  import { toRemainingAccountMeta } from "../utils/transfer_hook";
6
6
  import { getBinIndex, getBinArrayIndex, getPositionBinArrayIndices, } from "../utils/bin_location";
@@ -74,10 +74,10 @@ export class Position {
74
74
  }), { amountX: 0n, amountY: 0n, feeX: 0n, feeY: 0n });
75
75
  const { transferFeeX, transferFeeY } = await this.#pool.getTransferFees();
76
76
  const [netAmountX, netAmountY, netFeeX, netFeeY] = await Promise.all([
77
- applyTransferFee(gross.amountX, transferFeeX),
78
- applyTransferFee(gross.amountY, transferFeeY),
79
- applyTransferFee(gross.feeX, transferFeeX),
80
- applyTransferFee(gross.feeY, transferFeeY),
77
+ getAmountAfterTransferFee(gross.amountX, transferFeeX),
78
+ getAmountAfterTransferFee(gross.amountY, transferFeeY),
79
+ getAmountAfterTransferFee(gross.feeX, transferFeeX),
80
+ getAmountAfterTransferFee(gross.feeY, transferFeeY),
81
81
  ]);
82
82
  return {
83
83
  bins,
@@ -19,7 +19,8 @@ export * from "./resetAdminAuthority";
19
19
  export * from "./setMetadataUpdateAuthority";
20
20
  export * from "./setPoolDynamicFeeConfig";
21
21
  export * from "./setPoolProtocolShare";
22
- export * from "./swap";
22
+ export * from "./swapExactIn";
23
+ export * from "./swapExactOut";
23
24
  export * from "./syncPool";
24
25
  export * from "./transferAdminAuthority";
25
26
  export * from "./withdraw";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC"}
@@ -19,7 +19,8 @@ export * from "./resetAdminAuthority";
19
19
  export * from "./setMetadataUpdateAuthority";
20
20
  export * from "./setPoolDynamicFeeConfig";
21
21
  export * from "./setPoolProtocolShare";
22
- export * from "./swap";
22
+ export * from "./swapExactIn";
23
+ export * from "./swapExactOut";
23
24
  export * from "./syncPool";
24
25
  export * from "./transferAdminAuthority";
25
26
  export * from "./withdraw";
@@ -0,0 +1,78 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+ import { type AccountMeta, type AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from "@solana/kit";
9
+ import { PICON_DLMM_PROGRAM_ADDRESS } from "../programs";
10
+ import { type RemainingAccountsScheme, type RemainingAccountsSchemeArgs } from "../types";
11
+ export declare const SWAP_EXACT_IN_DISCRIMINATOR: ReadonlyUint8Array;
12
+ export declare function getSwapExactInDiscriminatorBytes(): ReadonlyUint8Array;
13
+ export type SwapExactInInstruction<TProgram extends string = typeof PICON_DLMM_PROGRAM_ADDRESS, TAccountUser extends string | AccountMeta<string> = string, TAccountPool extends string | AccountMeta<string> = string, TAccountTokenMintX extends string | AccountMeta<string> = string, TAccountTokenMintY extends string | AccountMeta<string> = string, TAccountTokenUserAccountX extends string | AccountMeta<string> = string, TAccountTokenUserAccountY extends string | AccountMeta<string> = string, TAccountTokenVaultX extends string | AccountMeta<string> = string, TAccountTokenVaultY extends string | AccountMeta<string> = string, TAccountTokenProgramX extends string | AccountMeta<string> = string, TAccountTokenProgramY extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[
14
+ TAccountUser extends string ? ReadonlySignerAccount<TAccountUser> & AccountSignerMeta<TAccountUser> : TAccountUser,
15
+ TAccountPool extends string ? WritableAccount<TAccountPool> : TAccountPool,
16
+ TAccountTokenMintX extends string ? ReadonlyAccount<TAccountTokenMintX> : TAccountTokenMintX,
17
+ TAccountTokenMintY extends string ? ReadonlyAccount<TAccountTokenMintY> : TAccountTokenMintY,
18
+ TAccountTokenUserAccountX extends string ? WritableAccount<TAccountTokenUserAccountX> : TAccountTokenUserAccountX,
19
+ TAccountTokenUserAccountY extends string ? WritableAccount<TAccountTokenUserAccountY> : TAccountTokenUserAccountY,
20
+ TAccountTokenVaultX extends string ? WritableAccount<TAccountTokenVaultX> : TAccountTokenVaultX,
21
+ TAccountTokenVaultY extends string ? WritableAccount<TAccountTokenVaultY> : TAccountTokenVaultY,
22
+ TAccountTokenProgramX extends string ? ReadonlyAccount<TAccountTokenProgramX> : TAccountTokenProgramX,
23
+ TAccountTokenProgramY extends string ? ReadonlyAccount<TAccountTokenProgramY> : TAccountTokenProgramY,
24
+ ...TRemainingAccounts
25
+ ]>;
26
+ export type SwapExactInInstructionData = {
27
+ discriminator: ReadonlyUint8Array;
28
+ amountIn: bigint;
29
+ minAmountOut: bigint;
30
+ xToY: boolean;
31
+ remainingAccountsScheme: RemainingAccountsScheme;
32
+ };
33
+ export type SwapExactInInstructionDataArgs = {
34
+ amountIn: number | bigint;
35
+ minAmountOut: number | bigint;
36
+ xToY: boolean;
37
+ remainingAccountsScheme: RemainingAccountsSchemeArgs;
38
+ };
39
+ export declare function getSwapExactInInstructionDataEncoder(): Encoder<SwapExactInInstructionDataArgs>;
40
+ export declare function getSwapExactInInstructionDataDecoder(): Decoder<SwapExactInInstructionData>;
41
+ export declare function getSwapExactInInstructionDataCodec(): Codec<SwapExactInInstructionDataArgs, SwapExactInInstructionData>;
42
+ export type SwapExactInInput<TAccountUser extends string = string, TAccountPool extends string = string, TAccountTokenMintX extends string = string, TAccountTokenMintY extends string = string, TAccountTokenUserAccountX extends string = string, TAccountTokenUserAccountY extends string = string, TAccountTokenVaultX extends string = string, TAccountTokenVaultY extends string = string, TAccountTokenProgramX extends string = string, TAccountTokenProgramY extends string = string> = {
43
+ user: TransactionSigner<TAccountUser>;
44
+ pool: Address<TAccountPool>;
45
+ tokenMintX: Address<TAccountTokenMintX>;
46
+ tokenMintY: Address<TAccountTokenMintY>;
47
+ tokenUserAccountX: Address<TAccountTokenUserAccountX>;
48
+ tokenUserAccountY: Address<TAccountTokenUserAccountY>;
49
+ tokenVaultX: Address<TAccountTokenVaultX>;
50
+ tokenVaultY: Address<TAccountTokenVaultY>;
51
+ tokenProgramX: Address<TAccountTokenProgramX>;
52
+ tokenProgramY: Address<TAccountTokenProgramY>;
53
+ amountIn: SwapExactInInstructionDataArgs["amountIn"];
54
+ minAmountOut: SwapExactInInstructionDataArgs["minAmountOut"];
55
+ xToY: SwapExactInInstructionDataArgs["xToY"];
56
+ remainingAccountsScheme: SwapExactInInstructionDataArgs["remainingAccountsScheme"];
57
+ };
58
+ export declare function getSwapExactInInstruction<TAccountUser extends string, TAccountPool extends string, TAccountTokenMintX extends string, TAccountTokenMintY extends string, TAccountTokenUserAccountX extends string, TAccountTokenUserAccountY extends string, TAccountTokenVaultX extends string, TAccountTokenVaultY extends string, TAccountTokenProgramX extends string, TAccountTokenProgramY extends string, TProgramAddress extends Address = typeof PICON_DLMM_PROGRAM_ADDRESS>(input: SwapExactInInput<TAccountUser, TAccountPool, TAccountTokenMintX, TAccountTokenMintY, TAccountTokenUserAccountX, TAccountTokenUserAccountY, TAccountTokenVaultX, TAccountTokenVaultY, TAccountTokenProgramX, TAccountTokenProgramY>, config?: {
59
+ programAddress?: TProgramAddress;
60
+ }): SwapExactInInstruction<TProgramAddress, TAccountUser, TAccountPool, TAccountTokenMintX, TAccountTokenMintY, TAccountTokenUserAccountX, TAccountTokenUserAccountY, TAccountTokenVaultX, TAccountTokenVaultY, TAccountTokenProgramX, TAccountTokenProgramY>;
61
+ export type ParsedSwapExactInInstruction<TProgram extends string = typeof PICON_DLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = {
62
+ programAddress: Address<TProgram>;
63
+ accounts: {
64
+ user: TAccountMetas[0];
65
+ pool: TAccountMetas[1];
66
+ tokenMintX: TAccountMetas[2];
67
+ tokenMintY: TAccountMetas[3];
68
+ tokenUserAccountX: TAccountMetas[4];
69
+ tokenUserAccountY: TAccountMetas[5];
70
+ tokenVaultX: TAccountMetas[6];
71
+ tokenVaultY: TAccountMetas[7];
72
+ tokenProgramX: TAccountMetas[8];
73
+ tokenProgramY: TAccountMetas[9];
74
+ };
75
+ data: SwapExactInInstructionData;
76
+ };
77
+ export declare function parseSwapExactInInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSwapExactInInstruction<TProgram, TAccountMetas>;
78
+ //# sourceMappingURL=swapExactIn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swapExactIn.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/swapExactIn.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAeL,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAKrB,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EACjC,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,2BAA2B,EAAE,kBAExC,CAAC;AAEH,wBAAgB,gCAAgC,IAAI,kBAAkB,CAIrE;AAED,MAAM,MAAM,sBAAsB,CAChC,QAAQ,SAAS,MAAM,GAAG,OAAO,0BAA0B,EAC3D,YAAY,SAAS,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,EAC1D,YAAY,SAAS,MAAM,GAAG,WAAW,CAAC,M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,CAAC,aAAa,CAAC,GACtC,mBAAmB,CAAC,kBAAkB,CAAC,GACxC,4BAA4B,CAAC,QAAQ,EAAE,aAAa,CAAC,CAgCvD"}
@@ -9,22 +9,22 @@ import { combineCodec, fixDecoderSize, fixEncoderSize, getBooleanDecoder, getBoo
9
9
  import { getAccountMetaFactory, } from "@solana/program-client-core";
10
10
  import { PICON_DLMM_PROGRAM_ADDRESS } from "../programs";
11
11
  import { getRemainingAccountsSchemeDecoder, getRemainingAccountsSchemeEncoder, } from "../types";
12
- export const SWAP_DISCRIMINATOR = new Uint8Array([
13
- 248, 198, 158, 145, 225, 117, 135, 200,
12
+ export const SWAP_EXACT_IN_DISCRIMINATOR = new Uint8Array([
13
+ 104, 104, 131, 86, 161, 189, 180, 216,
14
14
  ]);
15
- export function getSwapDiscriminatorBytes() {
16
- return fixEncoderSize(getBytesEncoder(), 8).encode(SWAP_DISCRIMINATOR);
15
+ export function getSwapExactInDiscriminatorBytes() {
16
+ return fixEncoderSize(getBytesEncoder(), 8).encode(SWAP_EXACT_IN_DISCRIMINATOR);
17
17
  }
18
- export function getSwapInstructionDataEncoder() {
18
+ export function getSwapExactInInstructionDataEncoder() {
19
19
  return transformEncoder(getStructEncoder([
20
20
  ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
21
21
  ["amountIn", getU64Encoder()],
22
22
  ["minAmountOut", getU64Encoder()],
23
23
  ["xToY", getBooleanEncoder()],
24
24
  ["remainingAccountsScheme", getRemainingAccountsSchemeEncoder()],
25
- ]), (value) => ({ ...value, discriminator: SWAP_DISCRIMINATOR }));
25
+ ]), (value) => ({ ...value, discriminator: SWAP_EXACT_IN_DISCRIMINATOR }));
26
26
  }
27
- export function getSwapInstructionDataDecoder() {
27
+ export function getSwapExactInInstructionDataDecoder() {
28
28
  return getStructDecoder([
29
29
  ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
30
30
  ["amountIn", getU64Decoder()],
@@ -33,10 +33,10 @@ export function getSwapInstructionDataDecoder() {
33
33
  ["remainingAccountsScheme", getRemainingAccountsSchemeDecoder()],
34
34
  ]);
35
35
  }
36
- export function getSwapInstructionDataCodec() {
37
- return combineCodec(getSwapInstructionDataEncoder(), getSwapInstructionDataDecoder());
36
+ export function getSwapExactInInstructionDataCodec() {
37
+ return combineCodec(getSwapExactInInstructionDataEncoder(), getSwapExactInInstructionDataDecoder());
38
38
  }
39
- export function getSwapInstruction(input, config) {
39
+ export function getSwapExactInInstruction(input, config) {
40
40
  // Program address.
41
41
  const programAddress = config?.programAddress ?? PICON_DLMM_PROGRAM_ADDRESS;
42
42
  // Original accounts.
@@ -75,11 +75,11 @@ export function getSwapInstruction(input, config) {
75
75
  getAccountMeta("tokenProgramX", accounts.tokenProgramX),
76
76
  getAccountMeta("tokenProgramY", accounts.tokenProgramY),
77
77
  ],
78
- data: getSwapInstructionDataEncoder().encode(args),
78
+ data: getSwapExactInInstructionDataEncoder().encode(args),
79
79
  programAddress,
80
80
  });
81
81
  }
82
- export function parseSwapInstruction(instruction) {
82
+ export function parseSwapExactInInstruction(instruction) {
83
83
  if (instruction.accounts.length < 10) {
84
84
  throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
85
85
  actualAccountMetas: instruction.accounts.length,
@@ -106,6 +106,6 @@ export function parseSwapInstruction(instruction) {
106
106
  tokenProgramX: getNextAccount(),
107
107
  tokenProgramY: getNextAccount(),
108
108
  },
109
- data: getSwapInstructionDataDecoder().decode(instruction.data),
109
+ data: getSwapExactInInstructionDataDecoder().decode(instruction.data),
110
110
  };
111
111
  }