@picon-finance/dlmm-sdk 1.16.2 → 1.16.4
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.
- package/README.md +13 -8
- package/dist/entities/bin_array.d.ts +2 -0
- package/dist/entities/bin_array.d.ts.map +1 -1
- package/dist/entities/bin_array.js +10 -0
- package/dist/entities/pool.d.ts +2 -0
- package/dist/entities/pool.d.ts.map +1 -1
- package/dist/entities/pool.js +10 -2
- package/dist/quote/wasm-node/picon_dlmm_quote_bg.wasm +0 -0
- package/dist/quote/wasm-web/picon_dlmm_quote_bg.wasm +0 -0
- package/dist/utils/assert.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/entities/bin_array.ts +30 -0
- package/src/entities/pool.ts +18 -1
- package/src/quote/wasm-node/picon_dlmm_quote_bg.wasm +0 -0
- package/src/quote/wasm-web/picon_dlmm_quote_bg.wasm +0 -0
- package/src/utils/assert.ts +0 -1
package/README.md
CHANGED
|
@@ -5,9 +5,22 @@ TypeScript SDK for the [Picon DLMM](https://github.com/picon-finance) protocol o
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
bun add @picon-finance/dlmm-sdk
|
|
9
|
+
yarn add @picon-finance/dlmm-sdk
|
|
8
10
|
npm install @picon-finance/dlmm-sdk
|
|
9
11
|
```
|
|
10
12
|
|
|
13
|
+
## Environments
|
|
14
|
+
|
|
15
|
+
The package targets ESM (`"type": "module"`), but its ESM resolution has limitations —
|
|
16
|
+
supported consumption splits into two scenarios:
|
|
17
|
+
|
|
18
|
+
- **Server-side (Node scripts, tests, tooling): use [Bun](https://bun.sh).**
|
|
19
|
+
- **Client-side / anything bundler-fronted (webpack, Vite, Rollup, ...): works as-is.** Webpack
|
|
20
|
+
needs `resolve.fullySpecified: false` on `.m?js$`; most other bundlers are lenient by default.
|
|
21
|
+
|
|
22
|
+
**Not currently supported: bare `node` with no Bun and no bundler in front of it.**
|
|
23
|
+
|
|
11
24
|
## Usage
|
|
12
25
|
|
|
13
26
|
The SDK is built around stateful classes (`DlmmProgram`, `Pool`, `Position`, `BinArray`) that cache on-chain state to avoid redundant RPC round trips. Every method returns unsigned `Instruction`s (never signs or sends) — build, sign, and send the transaction yourself with `@solana/kit`.
|
|
@@ -188,14 +201,6 @@ for (const claimIxs of claimTxs) {
|
|
|
188
201
|
}
|
|
189
202
|
```
|
|
190
203
|
|
|
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
204
|
### Price math
|
|
200
205
|
|
|
201
206
|
`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`:
|
|
@@ -10,6 +10,7 @@ export declare class BinArray {
|
|
|
10
10
|
refresh(data: Account<generated.BinArray>): Promise<void>;
|
|
11
11
|
refresh(config?: FetchAccountConfig): Promise<void>;
|
|
12
12
|
static loadAll(rpc: ReturnType<typeof createSolanaRpc>, pool: Address, indices: number[], programAddress: Address, config?: FetchAccountsConfig): Promise<BinArray[]>;
|
|
13
|
+
static loadAllMaybe(rpc: ReturnType<typeof createSolanaRpc>, pool: Address, indices: number[], programAddress: Address, config?: FetchAccountsConfig): Promise<Array<BinArray | undefined>>;
|
|
13
14
|
delete(authority: TransactionSigner): Promise<Instruction>;
|
|
14
15
|
}
|
|
15
16
|
export declare function createBinArray({ payer, pool, index, idempotent, }: {
|
|
@@ -33,5 +34,6 @@ export declare function findAllBinArrayAddresses({ pool, indices }: {
|
|
|
33
34
|
indices: number[];
|
|
34
35
|
}, config: ProgramConfig): Promise<Address[]>;
|
|
35
36
|
export declare function fetchAllBinArraysChunked(rpc: ReturnType<typeof createSolanaRpc>, addresses: Address[], config?: FetchAccountsConfig): Promise<Account<generated.BinArray>[]>;
|
|
37
|
+
export declare function fetchAllMaybeBinArraysChunked(rpc: ReturnType<typeof createSolanaRpc>, addresses: Address[], config?: FetchAccountsConfig): Promise<import("@solana/accounts").MaybeAccount<generated.BinArray>[]>;
|
|
36
38
|
export declare function decodeAllBinArrays(maybeAccounts: MaybeEncodedAccount<string>[]): Account<generated.BinArray>[];
|
|
37
39
|
//# sourceMappingURL=bin_array.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin_array.d.ts","sourceRoot":"","sources":["../../src/entities/bin_array.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEf,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAK/B,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,qBAAa,QAAQ;;IAKnB,OAAO,eAQN;IAED,IAAW,OAAO,oBAAoC;IACtD,IAAW,IAAI,uBAAiC;IAChD,IAAW,IAAI,oBAA6B;IAE/B,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,OAAO,C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aAAa,GACpB,OAAO,CAAC,OAAO,EAAE,CAAC,CAIpB;AAED,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,EACvC,SAAS,EAAE,OAAO,EAAE,EACpB,MAAM,CAAC,EAAE,mBAAmB,0CAO7B;AAED,wBAAsB,6BAA6B,CACjD,GAAG,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,EACvC,SAAS,EAAE,OAAO,EAAE,EACpB,MAAM,CAAC,EAAE,mBAAmB,0EAO7B;AAID,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,mBAAmB,CAAC,MAAM,CAAC,EAAE,GAC3C,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAG/B"}
|
|
@@ -27,6 +27,13 @@ export class BinArray {
|
|
|
27
27
|
const accounts = await fetchAllBinArraysChunked(rpc, addresses, config);
|
|
28
28
|
return accounts.map(account => new BinArray(rpc, account, programAddress));
|
|
29
29
|
}
|
|
30
|
+
// Same as loadAll, but for a caller-chosen index range that may include bin arrays nobody has
|
|
31
|
+
// created on-chain yet (e.g. a UI-selected price range) — undefined in place of throwing.
|
|
32
|
+
static async loadAllMaybe(rpc, pool, indices, programAddress, config) {
|
|
33
|
+
const addresses = await findAllBinArrayAddresses({ indices, pool }, { programAddress });
|
|
34
|
+
const maybeAccounts = await fetchAllMaybeBinArraysChunked(rpc, addresses, config);
|
|
35
|
+
return maybeAccounts.map(maybeAccount => maybeAccount.exists ? new BinArray(rpc, maybeAccount, programAddress) : undefined);
|
|
36
|
+
}
|
|
30
37
|
async delete(authority) {
|
|
31
38
|
const adminConfig = await resolveAdminConfigAddress(this.#programAddress);
|
|
32
39
|
return await generated.getDeleteBinArrayInstructionAsync({
|
|
@@ -56,6 +63,9 @@ export async function findAllBinArrayAddresses({ pool, indices }, config) {
|
|
|
56
63
|
export async function fetchAllBinArraysChunked(rpc, addresses, config) {
|
|
57
64
|
return await fetchInChunks(addresses, MAX_ACCOUNTS_PER_RPC_BATCH, chunkAddresses => generated.fetchAllBinArray(rpc, chunkAddresses, config));
|
|
58
65
|
}
|
|
66
|
+
export async function fetchAllMaybeBinArraysChunked(rpc, addresses, config) {
|
|
67
|
+
return await fetchInChunks(addresses, MAX_ACCOUNTS_PER_RPC_BATCH, chunkAddresses => generated.fetchAllMaybeBinArray(rpc, chunkAddresses, config));
|
|
68
|
+
}
|
|
59
69
|
const binArrayDecoder = generated.getBinArrayDecoder();
|
|
60
70
|
export function decodeAllBinArrays(maybeAccounts) {
|
|
61
71
|
assertAccountsExist(maybeAccounts);
|
package/dist/entities/pool.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { generated } from "..";
|
|
|
3
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
|
+
import { BinArray } from "./bin_array";
|
|
6
7
|
import { type ProgramConfig } from "./types";
|
|
7
8
|
export declare class Pool {
|
|
8
9
|
#private;
|
|
@@ -30,6 +31,7 @@ export declare class Pool {
|
|
|
30
31
|
getPosition(address: Address, config?: FetchAccountsConfig): Promise<Position>;
|
|
31
32
|
getPositionByPositionMint(positionMint: Address, config?: FetchAccountsConfig): Promise<Position>;
|
|
32
33
|
getAllPositionsByPositionMints(positionMints: Address[], config?: FetchAccountsConfig): Promise<Position[]>;
|
|
34
|
+
getBinArraysForRange(lowerBinId: number, upperBinId: number, config?: FetchAccountsConfig): Promise<Array<BinArray | undefined>>;
|
|
33
35
|
openPosition(owner: TransactionSigner, positionMint: TransactionSigner, { lowerBinId, upperBinId }: {
|
|
34
36
|
lowerBinId: number;
|
|
35
37
|
upperBinId: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/entities/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe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B,OAAO,CAAC,WAAW,CAAC,CAkBtB"}
|
package/dist/entities/pool.js
CHANGED
|
@@ -5,12 +5,12 @@ 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";
|
|
8
|
-
import { getBinArrayIndex, generateBinArrayIndicesForSwap, generateBinArrayIndicesForSync, } from "../utils/bin_location";
|
|
8
|
+
import { getBinArrayIndex, getBinArrayIndexSequence, generateBinArrayIndicesForSwap, generateBinArrayIndicesForSync, } from "../utils/bin_location";
|
|
9
9
|
import { resolveTransferFee } from "../utils/transfer_fee";
|
|
10
10
|
import { resolveTransferHookProgram, resolveTransferHookExtraAccounts, toRemainingAccountMeta, } from "../utils/transfer_hook";
|
|
11
11
|
import { MAX_BIN_ARRAYS_PER_TRAVERSAL } from "../utils/constants";
|
|
12
12
|
import { Position, openPosition, closePosition, findPositionAddress, findAllPositionAddresses, } from "./position";
|
|
13
|
-
import { findAllBinArrayAddresses } from "./bin_array";
|
|
13
|
+
import { BinArray, findAllBinArrayAddresses } from "./bin_array";
|
|
14
14
|
export class Pool {
|
|
15
15
|
#programAddress;
|
|
16
16
|
#rpc;
|
|
@@ -64,6 +64,14 @@ export class Pool {
|
|
|
64
64
|
const addresses = await findAllPositionAddresses({ positionMints }, { programAddress: this.#programAddress });
|
|
65
65
|
return await Position.loadAll(this, addresses, config);
|
|
66
66
|
}
|
|
67
|
+
// Unlike #resolveSwapBinArrays (bounded to a fixed traversal window around the active bin) or
|
|
68
|
+
// a position's own bin arrays (bounded to that position's range), this covers a caller-chosen
|
|
69
|
+
// [lowerBinId, upperBinId] — e.g. a UI-selected price range that may extend past what's
|
|
70
|
+
// already loaded. undefined entries mean no bin array has been created there yet.
|
|
71
|
+
async getBinArraysForRange(lowerBinId, upperBinId, config) {
|
|
72
|
+
const indices = getBinArrayIndexSequence(getBinArrayIndex(lowerBinId), getBinArrayIndex(upperBinId));
|
|
73
|
+
return await BinArray.loadAllMaybe(this.#rpc, this.address, indices, this.#programAddress, config);
|
|
74
|
+
}
|
|
67
75
|
async openPosition(owner, positionMint, { lowerBinId, upperBinId }) {
|
|
68
76
|
return await openPosition(this.#rpc, { owner, positionMint, pool: this.address, lowerBinId, upperBinId }, { programAddress: this.#programAddress });
|
|
69
77
|
}
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/utils/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/utils/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,UAAU,GAChB,IAAI,CAMN;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,EAC3B,IAAI,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GACzB,IAAI,CAMN"}
|
package/package.json
CHANGED
|
@@ -61,6 +61,24 @@ export class BinArray {
|
|
|
61
61
|
return accounts.map(account => new BinArray(rpc, account, programAddress));
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
// Same as loadAll, but for a caller-chosen index range that may include bin arrays nobody has
|
|
65
|
+
// created on-chain yet (e.g. a UI-selected price range) — undefined in place of throwing.
|
|
66
|
+
public static async loadAllMaybe(
|
|
67
|
+
rpc: ReturnType<typeof createSolanaRpc>,
|
|
68
|
+
pool: Address,
|
|
69
|
+
indices: number[],
|
|
70
|
+
programAddress: Address,
|
|
71
|
+
config?: FetchAccountsConfig,
|
|
72
|
+
): Promise<Array<BinArray | undefined>> {
|
|
73
|
+
const addresses = await findAllBinArrayAddresses(
|
|
74
|
+
{ indices, pool },
|
|
75
|
+
{ programAddress },
|
|
76
|
+
);
|
|
77
|
+
const maybeAccounts = await fetchAllMaybeBinArraysChunked(rpc, addresses, config);
|
|
78
|
+
return maybeAccounts.map(maybeAccount =>
|
|
79
|
+
maybeAccount.exists ? new BinArray(rpc, maybeAccount, programAddress) : undefined);
|
|
80
|
+
}
|
|
81
|
+
|
|
64
82
|
public async delete(authority: TransactionSigner): Promise<Instruction> {
|
|
65
83
|
const adminConfig = await resolveAdminConfigAddress(this.#programAddress);
|
|
66
84
|
return await generated.getDeleteBinArrayInstructionAsync({
|
|
@@ -147,6 +165,18 @@ export async function fetchAllBinArraysChunked(
|
|
|
147
165
|
);
|
|
148
166
|
}
|
|
149
167
|
|
|
168
|
+
export async function fetchAllMaybeBinArraysChunked(
|
|
169
|
+
rpc: ReturnType<typeof createSolanaRpc>,
|
|
170
|
+
addresses: Address[],
|
|
171
|
+
config?: FetchAccountsConfig,
|
|
172
|
+
) {
|
|
173
|
+
return await fetchInChunks(
|
|
174
|
+
addresses,
|
|
175
|
+
MAX_ACCOUNTS_PER_RPC_BATCH,
|
|
176
|
+
chunkAddresses => generated.fetchAllMaybeBinArray(rpc, chunkAddresses, config),
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
150
180
|
const binArrayDecoder = generated.getBinArrayDecoder();
|
|
151
181
|
|
|
152
182
|
export function decodeAllBinArrays(
|
package/src/entities/pool.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { resolveAdminConfigAddress } from "./admin_config";
|
|
|
28
28
|
import { processAssociatedTokenAccountPair } from "../utils/ata";
|
|
29
29
|
import {
|
|
30
30
|
getBinArrayIndex,
|
|
31
|
+
getBinArrayIndexSequence,
|
|
31
32
|
generateBinArrayIndicesForSwap,
|
|
32
33
|
generateBinArrayIndicesForSync,
|
|
33
34
|
} from "../utils/bin_location";
|
|
@@ -47,7 +48,7 @@ import {
|
|
|
47
48
|
findPositionAddress,
|
|
48
49
|
findAllPositionAddresses,
|
|
49
50
|
} from "./position";
|
|
50
|
-
import { findAllBinArrayAddresses } from "./bin_array";
|
|
51
|
+
import { BinArray, findAllBinArrayAddresses } from "./bin_array";
|
|
51
52
|
import { type ProgramConfig } from "./types";
|
|
52
53
|
|
|
53
54
|
export class Pool {
|
|
@@ -141,6 +142,22 @@ export class Pool {
|
|
|
141
142
|
return await Position.loadAll(this, addresses, config);
|
|
142
143
|
}
|
|
143
144
|
|
|
145
|
+
// Unlike #resolveSwapBinArrays (bounded to a fixed traversal window around the active bin) or
|
|
146
|
+
// a position's own bin arrays (bounded to that position's range), this covers a caller-chosen
|
|
147
|
+
// [lowerBinId, upperBinId] — e.g. a UI-selected price range that may extend past what's
|
|
148
|
+
// already loaded. undefined entries mean no bin array has been created there yet.
|
|
149
|
+
public async getBinArraysForRange(
|
|
150
|
+
lowerBinId: number,
|
|
151
|
+
upperBinId: number,
|
|
152
|
+
config?: FetchAccountsConfig,
|
|
153
|
+
): Promise<Array<BinArray | undefined>> {
|
|
154
|
+
const indices = getBinArrayIndexSequence(
|
|
155
|
+
getBinArrayIndex(lowerBinId),
|
|
156
|
+
getBinArrayIndex(upperBinId),
|
|
157
|
+
);
|
|
158
|
+
return await BinArray.loadAllMaybe(this.#rpc, this.address, indices, this.#programAddress, config);
|
|
159
|
+
}
|
|
160
|
+
|
|
144
161
|
public async openPosition(
|
|
145
162
|
owner: TransactionSigner,
|
|
146
163
|
positionMint: TransactionSigner,
|
|
Binary file
|
|
Binary file
|