@picon-finance/dlmm-sdk 1.14.0 → 1.16.1

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 (56) 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 +103 -39
  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 +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/picon_dlmm.json +101 -12
  24. package/dist/quote/index.d.ts +6 -4
  25. package/dist/quote/index.d.ts.map +1 -1
  26. package/dist/quote/index.js +12 -4
  27. package/dist/quote/wasm-node/picon_dlmm_quote.d.ts +49 -6
  28. package/dist/quote/wasm-node/picon_dlmm_quote.js +34 -9
  29. package/dist/quote/wasm-node/picon_dlmm_quote_bg.wasm +0 -0
  30. package/dist/quote/wasm-node/picon_dlmm_quote_bg.wasm.d.ts +4 -2
  31. package/dist/quote/wasm-web/picon_dlmm_quote.d.ts +53 -8
  32. package/dist/quote/wasm-web/picon_dlmm_quote.js +34 -9
  33. package/dist/quote/wasm-web/picon_dlmm_quote_bg.wasm +0 -0
  34. package/dist/quote/wasm-web/picon_dlmm_quote_bg.wasm.d.ts +4 -2
  35. package/package.json +1 -1
  36. package/src/entities/dlmm_program.ts +26 -7
  37. package/src/entities/pool.ts +182 -47
  38. package/src/entities/position.ts +5 -5
  39. package/src/generated/instructions/index.ts +2 -1
  40. package/src/generated/instructions/{swap.ts → swapExactIn.ts} +33 -31
  41. package/src/generated/instructions/swapExactOut.ts +349 -0
  42. package/src/generated/programs/piconDlmm.ts +54 -17
  43. package/src/index.ts +1 -1
  44. package/src/picon_dlmm.json +101 -12
  45. package/src/quote/index.ts +34 -8
  46. package/src/quote/wasm-node/picon_dlmm_quote.d.ts +49 -6
  47. package/src/quote/wasm-node/picon_dlmm_quote.js +34 -9
  48. package/src/quote/wasm-node/picon_dlmm_quote_bg.wasm +0 -0
  49. package/src/quote/wasm-node/picon_dlmm_quote_bg.wasm.d.ts +4 -2
  50. package/src/quote/wasm-web/picon_dlmm_quote.d.ts +53 -8
  51. package/src/quote/wasm-web/picon_dlmm_quote.js +34 -9
  52. package/src/quote/wasm-web/picon_dlmm_quote_bg.wasm +0 -0
  53. package/src/quote/wasm-web/picon_dlmm_quote_bg.wasm.d.ts +4 -2
  54. package/src/utils/price.ts +15 -15
  55. package/dist/generated/instructions/swap.d.ts +0 -78
  56. 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,eAAe,CAAC,EACvC,cAAc,GAAE,OAAiC,EAIlD;IAED,IAAW,GAAG,+5nBAAwB;IACtC,IAAW,cAAc,YAAmC;IAE/C,OAAO,CAClB,OAAO,EAAE,OAAO,EAChB,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAEf;IAEY,UAAU,CACrB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M,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,CAAC;AAEpB,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,qBAAa,IAAI;;IAQf,OAAO,eAYN;IAED,IAAW,GAAG,+5nBAAwB;IAEtC,IAAW,cAAc,YAAmC;IAC5D,IAAW,OAAO,oBAAoC;IACtD,IAAW,IAAI,mBAAiC;IAChD,IAAW,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AC;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,19 +70,65 @@ 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
+ // The input leg is fixed, so it funds the wSOL leg (if any) directly.
76
+ const instructions = await this.#assembleSwapInstructions(user, xToY, amountIn, binArrayAddresses, ({ tokenUserAccountX, tokenUserAccountY, remainingAccountsScheme }) => generated.getSwapExactInInstruction({
77
+ user,
78
+ pool: this.address,
79
+ tokenMintX: this.tokenMintX,
80
+ tokenMintY: this.tokenMintY,
81
+ tokenUserAccountX,
82
+ tokenUserAccountY,
83
+ tokenVaultX: this.tokenVaultX,
84
+ tokenVaultY: this.tokenVaultY,
85
+ tokenProgramX: this.tokenProgramX,
86
+ tokenProgramY: this.tokenProgramY,
87
+ amountIn,
88
+ minAmountOut: quoteOutput.minAmountOut,
89
+ xToY,
90
+ remainingAccountsScheme,
91
+ }, { programAddress: this.#programAddress }));
92
+ return { quoteOutput, instructions };
93
+ }
94
+ async swapExactOut(user, { xToY, amountOut, slippageToleranceBps, }) {
95
+ const { quoteOutput, binArrayAddresses } = await this.#quoteExactOut({ xToY, amountOut, slippageToleranceBps });
96
+ // The real input isn't known until the swap executes, so the wSOL leg (if any) is funded with
97
+ // the worst-case maxAmountIn — any excess is unwrapped back to the owner in postInstructions.
98
+ const instructions = await this.#assembleSwapInstructions(user, xToY, quoteOutput.maxAmountIn, binArrayAddresses, ({ tokenUserAccountX, tokenUserAccountY, remainingAccountsScheme }) => generated.getSwapExactOutInstruction({
99
+ user,
100
+ pool: this.address,
101
+ tokenMintX: this.tokenMintX,
102
+ tokenMintY: this.tokenMintY,
103
+ tokenUserAccountX,
104
+ tokenUserAccountY,
105
+ tokenVaultX: this.tokenVaultX,
106
+ tokenVaultY: this.tokenVaultY,
107
+ tokenProgramX: this.tokenProgramX,
108
+ tokenProgramY: this.tokenProgramY,
109
+ amountOut,
110
+ maxAmountIn: quoteOutput.maxAmountIn,
111
+ xToY,
112
+ remainingAccountsScheme,
113
+ }, { programAddress: this.#programAddress }));
114
+ return { quoteOutput, instructions };
115
+ }
116
+ // Shared tail of both swap directions: sets up the user's X/Y ATAs (funding the wSOL leg, if
117
+ // any, with `fundingAmount`), resolves each mint's transfer-hook accounts against the role it
118
+ // plays in this swap — input (user -> vault, owner = user) or output (vault -> user, owner =
119
+ // pool PDA) — builds the remaining-accounts scheme, and splices the bin arrays + resolved hook
120
+ // accounts onto the instruction `buildSwapIx` produces. Only the funding amount and the
121
+ // instruction itself differ between exact-in and exact-out.
122
+ async #assembleSwapInstructions(user, xToY, fundingAmount, binArrayAddresses, buildSwapIx) {
75
123
  const { ataX: tokenUserAccountX, ataY: tokenUserAccountY, preInstructions, postInstructions, } = await processAssociatedTokenAccountPair({
76
124
  owner: user,
77
125
  tokenMintX: this.tokenMintX,
78
126
  tokenMintY: this.tokenMintY,
79
127
  tokenProgramX: this.tokenProgramX,
80
128
  tokenProgramY: this.tokenProgramY,
81
- amountX: xToY ? amountIn : undefined,
82
- amountY: xToY ? undefined : amountIn,
129
+ amountX: xToY ? fundingAmount : undefined,
130
+ amountY: xToY ? undefined : fundingAmount,
83
131
  });
84
- // Each mint's hook accounts are resolved against whichever role it plays in this swap —
85
- // input (user -> vault, owner = user) or output (vault -> user, owner = pool PDA).
86
132
  const xTransferAccounts = xToY
87
133
  ? { source: tokenUserAccountX, mint: this.tokenMintX, destination: this.tokenVaultX, owner: user.address }
88
134
  : { source: this.tokenVaultX, mint: this.tokenMintX, destination: tokenUserAccountX, owner: this.address };
@@ -105,26 +151,13 @@ export class Pool {
105
151
  groups.push({ kind: generated.AccountKind.TransferHookY, count: transferHookYAccounts.length });
106
152
  remainingAccounts.push(...transferHookYAccounts.map(toRemainingAccountMeta));
107
153
  }
108
- const remainingAccountsScheme = { groups };
109
- const swapIx = generated.getSwapInstruction({
110
- user,
111
- pool: this.address,
112
- tokenMintX: this.tokenMintX,
113
- tokenMintY: this.tokenMintY,
154
+ const swapIx = buildSwapIx({
114
155
  tokenUserAccountX,
115
156
  tokenUserAccountY,
116
- tokenVaultX: this.tokenVaultX,
117
- tokenVaultY: this.tokenVaultY,
118
- tokenProgramX: this.tokenProgramX,
119
- tokenProgramY: this.tokenProgramY,
120
- amountIn,
121
- minAmountOut: quoteOutput.minAmountOut,
122
- xToY,
123
- remainingAccountsScheme,
124
- }, { programAddress: this.#programAddress });
125
- const swapIxWithBinArrays = { ...swapIx, accounts: [...swapIx.accounts, ...remainingAccounts] };
126
- const instructions = [...preInstructions, swapIxWithBinArrays, ...postInstructions];
127
- return { quoteOutput, instructions };
157
+ remainingAccountsScheme: { groups },
158
+ });
159
+ const swapIxWithBinArrays = { ...swapIx, accounts: [...(swapIx.accounts ?? []), ...remainingAccounts] };
160
+ return [...preInstructions, swapIxWithBinArrays, ...postInstructions];
128
161
  }
129
162
  // Public so Position (which only holds a reference to this Pool, not its private mint data)
130
163
  // can resolve hook accounts for its own deposit/withdraw/claimFee instructions without ever
@@ -142,19 +175,17 @@ export class Pool {
142
175
  return [];
143
176
  return await resolveTransferHookExtraAccounts(this.#rpc, hookProgram, transferAccounts);
144
177
  }
145
- async quote(params) {
146
- const { quoteOutput } = await this.#quote(params);
178
+ async quoteExactIn(params) {
179
+ const { quoteOutput } = await this.#quoteExactIn(params);
147
180
  return quoteOutput;
148
181
  }
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({
182
+ async quoteExactOut(params) {
183
+ const { quoteOutput } = await this.#quoteExactOut(params);
184
+ return quoteOutput;
185
+ }
186
+ async #quoteExactIn({ xToY, amountIn, slippageToleranceBps, }) {
187
+ const { indices, maxBinArrayAddresses, binArrays, transferFeeX, transferFeeY } = await this.#resolveSwapBinArrays(xToY);
188
+ const quoteOutput = await quoteExactIn({
158
189
  amountIn,
159
190
  xToY,
160
191
  slippageToleranceBps,
@@ -164,13 +195,46 @@ export class Pool {
164
195
  outputTransferFee: xToY ? transferFeeY : transferFeeX,
165
196
  binArrays,
166
197
  });
198
+ const binArrayAddresses = this.#binArrayAddressesForQuote(xToY, indices, maxBinArrayAddresses, quoteOutput.postActiveBinId);
199
+ return { quoteOutput, binArrayAddresses };
200
+ }
201
+ async #quoteExactOut({ xToY, amountOut, slippageToleranceBps, }) {
202
+ const { indices, maxBinArrayAddresses, binArrays, transferFeeX, transferFeeY } = await this.#resolveSwapBinArrays(xToY);
203
+ const quoteOutput = await quoteExactOut({
204
+ amountOut,
205
+ xToY,
206
+ slippageToleranceBps,
207
+ now: BigInt(Math.floor(Date.now() / 1000)),
208
+ poolState: this.data,
209
+ inputTransferFee: xToY ? transferFeeX : transferFeeY,
210
+ outputTransferFee: xToY ? transferFeeY : transferFeeX,
211
+ binArrays,
212
+ });
213
+ const binArrayAddresses = this.#binArrayAddressesForQuote(xToY, indices, maxBinArrayAddresses, quoteOutput.postActiveBinId);
214
+ return { quoteOutput, binArrayAddresses };
215
+ }
216
+ // The bin array window a quote might touch, before the quote itself narrows down how much of
217
+ // it was actually crossed — shared by both quote directions, which differ only in which
218
+ // `quoteExact{In,Out}` call they make against this same window.
219
+ async #resolveSwapBinArrays(xToY) {
220
+ const indices = generateBinArrayIndicesForSwap(this.activeBinId, xToY, MAX_BIN_ARRAYS_PER_TRAVERSAL);
221
+ const maxBinArrayAddresses = await findAllBinArrayAddresses({ pool: this.address, indices }, { programAddress: this.#programAddress });
222
+ const [maybeBinArrays, { transferFeeX, transferFeeY }] = await Promise.all([
223
+ generated.fetchAllMaybeBinArray(this.#rpc, maxBinArrayAddresses),
224
+ this.getTransferFees(),
225
+ ]);
226
+ const binArrays = maybeBinArrays.map(maybeBinArray => maybeBinArray.exists ? maybeBinArray.data : undefined);
227
+ return { indices, maxBinArrayAddresses, binArrays, transferFeeX, transferFeeY };
228
+ }
229
+ // Narrows the bin array window down to what a quote (already run against the full window)
230
+ // actually needs to re-traverse at swap time, based on where it left the active bin.
231
+ #binArrayAddressesForQuote(xToY, indices, maxBinArrayAddresses, postActiveBinId) {
167
232
  const safeOffset = xToY ? -1 : 1;
168
- const targetBinArrayIndex = getBinArrayIndex(quoteOutput.postActiveBinId) + safeOffset;
233
+ const targetBinArrayIndex = getBinArrayIndex(postActiveBinId) + safeOffset;
169
234
  const localTargetBinArrayIndex = targetBinArrayIndex - indices[0];
170
- const binArrayAddresses = xToY
235
+ return xToY
171
236
  ? maxBinArrayAddresses.slice(Math.max(0, localTargetBinArrayIndex))
172
237
  : maxBinArrayAddresses.slice(0, localTargetBinArrayIndex + 1);
173
- return { quoteOutput, binArrayAddresses };
174
238
  }
175
239
  async sync(user, desiredBinId) {
176
240
  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,e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