@picon-finance/dlmm-sdk 1.2.0 → 1.4.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.
- package/README.md +115 -16
- package/dist/entities/admin_config.d.ts +23 -0
- package/dist/entities/admin_config.d.ts.map +1 -0
- package/dist/entities/admin_config.js +54 -0
- package/dist/entities/bin_array.d.ts +37 -0
- package/dist/entities/bin_array.d.ts.map +1 -0
- package/dist/entities/bin_array.js +63 -0
- package/dist/entities/dlmm_program.d.ts +50 -0
- package/dist/entities/dlmm_program.d.ts.map +1 -0
- package/dist/entities/dlmm_program.js +73 -0
- package/dist/entities/index.d.ts +7 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +6 -0
- package/dist/entities/pool.d.ts +71 -0
- package/dist/entities/pool.d.ts.map +1 -0
- package/dist/entities/pool.js +189 -0
- package/dist/entities/position.d.ts +55 -0
- package/dist/entities/position.d.ts.map +1 -0
- package/dist/entities/position.js +277 -0
- package/dist/entities/position_pool.d.ts +7 -0
- package/dist/entities/position_pool.d.ts.map +1 -0
- package/dist/entities/position_pool.js +30 -0
- package/dist/entities/types.d.ts +5 -0
- package/dist/entities/types.d.ts.map +1 -0
- package/dist/entities/types.js +0 -0
- package/dist/events.d.ts +9 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +48 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/program_addresses.d.ts.map +1 -1
- package/dist/program_addresses.js +0 -5
- package/dist/utils/assert.d.ts +9 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +10 -0
- package/dist/utils/bin_location.d.ts +4 -0
- package/dist/utils/bin_location.d.ts.map +1 -1
- package/dist/utils/bin_location.js +0 -12
- package/dist/utils/chunk.d.ts +1 -0
- package/dist/utils/chunk.d.ts.map +1 -1
- package/dist/utils/chunk.js +4 -0
- package/dist/utils/type_guards.d.ts +2 -0
- package/dist/utils/type_guards.d.ts.map +1 -1
- package/dist/utils/type_guards.js +7 -0
- package/package.json +1 -2
- package/src/entities/admin_config.ts +122 -0
- package/src/entities/bin_array.ts +157 -0
- package/src/entities/dlmm_program.ts +210 -0
- package/src/entities/index.ts +6 -0
- package/src/entities/pool.ts +392 -0
- package/src/entities/position.ts +481 -0
- package/src/entities/position_pool.ts +68 -0
- package/src/entities/types.ts +3 -0
- package/src/events.ts +77 -0
- package/src/index.ts +2 -1
- package/src/program_addresses.ts +0 -6
- package/src/utils/assert.ts +25 -0
- package/src/utils/bin_location.ts +5 -12
- package/src/utils/chunk.ts +9 -0
- package/src/utils/type_guards.ts +12 -0
- package/dist/actions/accept_admin_authority.d.ts +0 -13
- package/dist/actions/accept_admin_authority.d.ts.map +0 -1
- package/dist/actions/accept_admin_authority.js +0 -7
- package/dist/actions/claim_fee.d.ts +0 -21
- package/dist/actions/claim_fee.d.ts.map +0 -1
- package/dist/actions/claim_fee.js +0 -40
- package/dist/actions/claim_multiple_fees.d.ts +0 -19
- package/dist/actions/claim_multiple_fees.d.ts.map +0 -1
- package/dist/actions/claim_multiple_fees.js +0 -81
- package/dist/actions/claim_protocol_fee.d.ts +0 -18
- package/dist/actions/claim_protocol_fee.d.ts.map +0 -1
- package/dist/actions/claim_protocol_fee.js +0 -33
- package/dist/actions/close_position.d.ts +0 -14
- package/dist/actions/close_position.d.ts.map +0 -1
- package/dist/actions/close_position.js +0 -14
- package/dist/actions/create_admin_config.d.ts +0 -15
- package/dist/actions/create_admin_config.d.ts.map +0 -1
- package/dist/actions/create_admin_config.js +0 -30
- package/dist/actions/create_bin_array.d.ts +0 -16
- package/dist/actions/create_bin_array.d.ts.map +0 -1
- package/dist/actions/create_bin_array.js +0 -10
- package/dist/actions/create_pool.d.ts +0 -21
- package/dist/actions/create_pool.d.ts.map +0 -1
- package/dist/actions/create_pool.js +0 -22
- package/dist/actions/delete_bin_array.d.ts +0 -16
- package/dist/actions/delete_bin_array.d.ts.map +0 -1
- package/dist/actions/delete_bin_array.js +0 -13
- package/dist/actions/deposit_by_weight.d.ts +0 -27
- package/dist/actions/deposit_by_weight.d.ts.map +0 -1
- package/dist/actions/deposit_by_weight.js +0 -52
- package/dist/actions/get_admin_config.d.ts +0 -4
- package/dist/actions/get_admin_config.d.ts.map +0 -1
- package/dist/actions/get_admin_config.js +0 -7
- package/dist/actions/get_bin_arrays_by_indices.d.ts +0 -5
- package/dist/actions/get_bin_arrays_by_indices.d.ts.map +0 -1
- package/dist/actions/get_bin_arrays_by_indices.js +0 -6
- package/dist/actions/get_pool.d.ts +0 -4
- package/dist/actions/get_pool.d.ts.map +0 -1
- package/dist/actions/get_pool.js +0 -5
- package/dist/actions/get_position.d.ts +0 -4
- package/dist/actions/get_position.d.ts.map +0 -1
- package/dist/actions/get_position.js +0 -5
- package/dist/actions/get_position_by_position_mint.d.ts +0 -4
- package/dist/actions/get_position_by_position_mint.d.ts.map +0 -1
- package/dist/actions/get_position_by_position_mint.js +0 -6
- package/dist/actions/get_positions_by_owner.d.ts +0 -5
- package/dist/actions/get_positions_by_owner.d.ts.map +0 -1
- package/dist/actions/get_positions_by_owner.js +0 -33
- package/dist/actions/get_positions_by_position_mints.d.ts +0 -5
- package/dist/actions/get_positions_by_position_mints.d.ts.map +0 -1
- package/dist/actions/get_positions_by_position_mints.js +0 -9
- package/dist/actions/helpers/build_swap_transaction_message.d.ts +0 -22
- package/dist/actions/helpers/build_swap_transaction_message.d.ts.map +0 -1
- package/dist/actions/helpers/build_swap_transaction_message.js +0 -50
- package/dist/actions/helpers/build_transaction_message.d.ts +0 -20
- package/dist/actions/helpers/build_transaction_message.d.ts.map +0 -1
- package/dist/actions/helpers/build_transaction_message.js +0 -5
- package/dist/actions/helpers/index.d.ts +0 -8
- package/dist/actions/helpers/index.d.ts.map +0 -1
- package/dist/actions/helpers/index.js +0 -7
- package/dist/actions/helpers/resolve_active_bin_and_mints.d.ts +0 -12
- package/dist/actions/helpers/resolve_active_bin_and_mints.d.ts.map +0 -1
- package/dist/actions/helpers/resolve_active_bin_and_mints.js +0 -13
- package/dist/actions/helpers/resolve_admin_config_address.d.ts +0 -3
- package/dist/actions/helpers/resolve_admin_config_address.d.ts.map +0 -1
- package/dist/actions/helpers/resolve_admin_config_address.js +0 -9
- package/dist/actions/helpers/resolve_mint_info.d.ts +0 -10
- package/dist/actions/helpers/resolve_mint_info.d.ts.map +0 -1
- package/dist/actions/helpers/resolve_mint_info.js +0 -20
- package/dist/actions/helpers/resolve_position_range.d.ts +0 -12
- package/dist/actions/helpers/resolve_position_range.d.ts.map +0 -1
- package/dist/actions/helpers/resolve_position_range.js +0 -12
- package/dist/actions/helpers/resolve_token_mints_and_programs.d.ts +0 -15
- package/dist/actions/helpers/resolve_token_mints_and_programs.d.ts.map +0 -1
- package/dist/actions/helpers/resolve_token_mints_and_programs.js +0 -29
- package/dist/actions/index.d.ts +0 -31
- package/dist/actions/index.d.ts.map +0 -1
- package/dist/actions/index.js +0 -28
- package/dist/actions/is_admin_config_active.d.ts +0 -4
- package/dist/actions/is_admin_config_active.d.ts.map +0 -1
- package/dist/actions/is_admin_config_active.js +0 -7
- package/dist/actions/on_event.d.ts +0 -11
- package/dist/actions/on_event.d.ts.map +0 -1
- package/dist/actions/on_event.js +0 -50
- package/dist/actions/open_position.d.ts +0 -17
- package/dist/actions/open_position.d.ts.map +0 -1
- package/dist/actions/open_position.js +0 -31
- package/dist/actions/quote.d.ts +0 -13
- package/dist/actions/quote.d.ts.map +0 -1
- package/dist/actions/quote.js +0 -43
- package/dist/actions/set_metadata_update_authority.d.ts +0 -14
- package/dist/actions/set_metadata_update_authority.d.ts.map +0 -1
- package/dist/actions/set_metadata_update_authority.js +0 -7
- package/dist/actions/set_pool_dynamic_fee_config.d.ts +0 -16
- package/dist/actions/set_pool_dynamic_fee_config.d.ts.map +0 -1
- package/dist/actions/set_pool_dynamic_fee_config.js +0 -7
- package/dist/actions/set_pool_protocol_share.d.ts +0 -15
- package/dist/actions/set_pool_protocol_share.d.ts.map +0 -1
- package/dist/actions/set_pool_protocol_share.js +0 -7
- package/dist/actions/swap.d.ts +0 -22
- package/dist/actions/swap.d.ts.map +0 -1
- package/dist/actions/swap.js +0 -19
- package/dist/actions/sync_pool.d.ts +0 -15
- package/dist/actions/sync_pool.d.ts.map +0 -1
- package/dist/actions/sync_pool.js +0 -26
- package/dist/actions/transfer_admin_authority.d.ts +0 -14
- package/dist/actions/transfer_admin_authority.d.ts.map +0 -1
- package/dist/actions/transfer_admin_authority.js +0 -7
- package/dist/actions/withdraw.d.ts +0 -22
- package/dist/actions/withdraw.d.ts.map +0 -1
- package/dist/actions/withdraw.js +0 -41
- package/dist/utils/admin_config.d.ts +0 -3
- package/dist/utils/admin_config.d.ts.map +0 -1
- package/dist/utils/admin_config.js +0 -4
- package/dist/utils/bin_array.d.ts +0 -8
- package/dist/utils/bin_array.d.ts.map +0 -1
- package/dist/utils/bin_array.js +0 -29
- package/dist/utils/compute_budget.d.ts +0 -11
- package/dist/utils/compute_budget.d.ts.map +0 -1
- package/dist/utils/compute_budget.js +0 -22
- package/src/actions/accept_admin_authority.ts +0 -17
- package/src/actions/claim_fee.ts +0 -84
- package/src/actions/claim_multiple_fees.ts +0 -123
- package/src/actions/claim_protocol_fee.ts +0 -68
- package/src/actions/close_position.ts +0 -21
- package/src/actions/create_admin_config.ts +0 -51
- package/src/actions/create_bin_array.ts +0 -30
- package/src/actions/create_pool.ts +0 -49
- package/src/actions/delete_bin_array.ts +0 -33
- package/src/actions/deposit_by_weight.ts +0 -107
- package/src/actions/get_admin_config.ts +0 -13
- package/src/actions/get_bin_arrays_by_indices.ts +0 -15
- package/src/actions/get_pool.ts +0 -8
- package/src/actions/get_position.ts +0 -8
- package/src/actions/get_position_by_position_mint.ts +0 -14
- package/src/actions/get_positions_by_owner.ts +0 -48
- package/src/actions/get_positions_by_position_mints.ts +0 -21
- package/src/actions/helpers/build_swap_transaction_message.ts +0 -86
- package/src/actions/helpers/build_transaction_message.ts +0 -45
- package/src/actions/helpers/index.ts +0 -7
- package/src/actions/helpers/resolve_active_bin_and_mints.ts +0 -21
- package/src/actions/helpers/resolve_admin_config_address.ts +0 -11
- package/src/actions/helpers/resolve_mint_info.ts +0 -36
- package/src/actions/helpers/resolve_position_range.ts +0 -21
- package/src/actions/helpers/resolve_token_mints_and_programs.ts +0 -56
- package/src/actions/index.ts +0 -34
- package/src/actions/is_admin_config_active.ts +0 -14
- package/src/actions/on_event.ts +0 -78
- package/src/actions/open_position.ts +0 -66
- package/src/actions/quote.ts +0 -70
- package/src/actions/set_metadata_update_authority.ts +0 -17
- package/src/actions/set_pool_dynamic_fee_config.ts +0 -17
- package/src/actions/set_pool_protocol_share.ts +0 -17
- package/src/actions/swap.ts +0 -56
- package/src/actions/sync_pool.ts +0 -35
- package/src/actions/transfer_admin_authority.ts +0 -17
- package/src/actions/withdraw.ts +0 -87
- package/src/utils/admin_config.ts +0 -6
- package/src/utils/bin_array.ts +0 -45
- package/src/utils/compute_budget.ts +0 -58
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { decodeAccount, assertAccountExists, fetchEncodedAccounts, } from "@solana/kit";
|
|
2
|
+
import { generated } from "..";
|
|
3
|
+
import { findPositionTokenAccount, processAssociatedTokenAccountPair, } from "../utils/ata";
|
|
4
|
+
import { getBinIndex, getBinArrayIndex, getPositionBinArrayIndices, } from "../utils/bin_location";
|
|
5
|
+
import { assertRangeWithinRange, assertPositionBelongsToPool, } from "../utils/assert";
|
|
6
|
+
import { isUndefined } from "../utils/type_guards";
|
|
7
|
+
import { fetchInChunks } from "../utils/chunk";
|
|
8
|
+
import { resolveAdminConfigAddress } from "./admin_config";
|
|
9
|
+
import { MAX_ACCOUNTS_PER_RPC_BATCH } from "../utils/constants";
|
|
10
|
+
import { BinArray, decodeAllBinArrays, createAllBinArrays, fetchAllBinArraysChunked, } from "./bin_array";
|
|
11
|
+
export class Position {
|
|
12
|
+
#pool;
|
|
13
|
+
#account;
|
|
14
|
+
#binArrays;
|
|
15
|
+
constructor(pool, account, binArrays) {
|
|
16
|
+
this.#pool = pool;
|
|
17
|
+
this.#account = account;
|
|
18
|
+
this.#binArrays = binArrays;
|
|
19
|
+
}
|
|
20
|
+
get address() { return this.#account.address; }
|
|
21
|
+
get data() { return this.#account.data; }
|
|
22
|
+
get positionMint() { return this.data.positionMint; }
|
|
23
|
+
get binArrayAddresses() {
|
|
24
|
+
const lowerBinArray = this.#binArrays[0].address;
|
|
25
|
+
const upperBinArray = this.#binArrays.length > 1 ? this.#binArrays[1].address : undefined;
|
|
26
|
+
return { lowerBinArray, upperBinArray };
|
|
27
|
+
}
|
|
28
|
+
getPendingFee() {
|
|
29
|
+
const { lowerBinId, upperBinId, feeStates } = this.data;
|
|
30
|
+
const lowerBinArrayIndex = getBinArrayIndex(lowerBinId);
|
|
31
|
+
return Array.from({ length: upperBinId - lowerBinId + 1 }, (_, i) => i)
|
|
32
|
+
.flatMap(i => {
|
|
33
|
+
const feeState = feeStates[i];
|
|
34
|
+
if (feeState.shares === 0n)
|
|
35
|
+
return [];
|
|
36
|
+
const binId = lowerBinId + i;
|
|
37
|
+
const binIndex = getBinIndex(binId);
|
|
38
|
+
const binArrayIndex = getBinArrayIndex(binId) - lowerBinArrayIndex;
|
|
39
|
+
const binArray = this.#binArrays[binArrayIndex];
|
|
40
|
+
const bin = binArray.bins[binIndex];
|
|
41
|
+
return bin.totalShares > 0n ? [{ feeState, bin }] : [];
|
|
42
|
+
})
|
|
43
|
+
.reduce((total, { feeState, bin }) => ({
|
|
44
|
+
amountX: total.amountX + earnedAmount(bin.feePerShareX, feeState.feePerShareCheckpointX, feeState.shares),
|
|
45
|
+
amountY: total.amountY + earnedAmount(bin.feePerShareY, feeState.feePerShareCheckpointY, feeState.shares),
|
|
46
|
+
}), { amountX: 0n, amountY: 0n });
|
|
47
|
+
}
|
|
48
|
+
async refresh(arg) {
|
|
49
|
+
if (!Array.isArray(arg)) {
|
|
50
|
+
arg = await fetchPositionWithBinArrays(this.#pool.rpc, this.address, this.#binArrays.map(b => b.address), arg);
|
|
51
|
+
}
|
|
52
|
+
const [position, binArrays] = arg;
|
|
53
|
+
this.#account = position;
|
|
54
|
+
this.#binArrays.forEach((b, i) => b.refresh(binArrays[i]));
|
|
55
|
+
}
|
|
56
|
+
async depositByWeight(owner, { amountX, amountY, lowerBinId, binWeights, maxActiveBinSlippage, distributionMode, }) {
|
|
57
|
+
const upperBinId = lowerBinId + binWeights.length - 1;
|
|
58
|
+
assertRangeWithinRange({ lowerBinId, upperBinId }, this.data);
|
|
59
|
+
const [positionTokenAccount, { ataX: tokenOwnerAccountX, ataY: tokenOwnerAccountY, preInstructions, postInstructions }] = await Promise.all([
|
|
60
|
+
findPositionTokenAccount({ owner: owner.address, positionMint: this.data.positionMint }),
|
|
61
|
+
processAssociatedTokenAccountPair({
|
|
62
|
+
owner,
|
|
63
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
64
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
65
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
66
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
67
|
+
amountX,
|
|
68
|
+
amountY,
|
|
69
|
+
}),
|
|
70
|
+
]);
|
|
71
|
+
const { lowerBinArray, upperBinArray } = this.binArrayAddresses;
|
|
72
|
+
const depositByWeightIx = generated.getDepositByWeightInstruction({
|
|
73
|
+
owner,
|
|
74
|
+
pool: this.#pool.address,
|
|
75
|
+
position: this.address,
|
|
76
|
+
positionTokenAccount,
|
|
77
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
78
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
79
|
+
tokenOwnerAccountX,
|
|
80
|
+
tokenOwnerAccountY,
|
|
81
|
+
tokenVaultX: this.#pool.tokenVaultX,
|
|
82
|
+
tokenVaultY: this.#pool.tokenVaultY,
|
|
83
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
84
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
85
|
+
lowerBinArray,
|
|
86
|
+
upperBinArray,
|
|
87
|
+
amountX,
|
|
88
|
+
amountY,
|
|
89
|
+
activeBinId: this.#pool.activeBinId,
|
|
90
|
+
maxActiveBinSlippage,
|
|
91
|
+
distributionMode,
|
|
92
|
+
lowerBinId,
|
|
93
|
+
binWeights,
|
|
94
|
+
}, {
|
|
95
|
+
programAddress: this.#pool.programAddress
|
|
96
|
+
});
|
|
97
|
+
return [...preInstructions, depositByWeightIx, ...postInstructions];
|
|
98
|
+
}
|
|
99
|
+
async claimFee(owner, range) {
|
|
100
|
+
const { lowerBinId, upperBinId } = range ?? this.data;
|
|
101
|
+
assertRangeWithinRange({ lowerBinId, upperBinId }, this.data);
|
|
102
|
+
const [positionTokenAccount, { ataX: tokenOwnerAccountX, ataY: tokenOwnerAccountY, preInstructions, postInstructions }] = await Promise.all([
|
|
103
|
+
findPositionTokenAccount({ owner: owner.address, positionMint: this.data.positionMint }),
|
|
104
|
+
processAssociatedTokenAccountPair({
|
|
105
|
+
owner,
|
|
106
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
107
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
108
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
109
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
110
|
+
}),
|
|
111
|
+
]);
|
|
112
|
+
const { lowerBinArray, upperBinArray } = this.binArrayAddresses;
|
|
113
|
+
const claimFeeIx = generated.getClaimFeeInstruction({
|
|
114
|
+
owner,
|
|
115
|
+
pool: this.#pool.address,
|
|
116
|
+
position: this.address,
|
|
117
|
+
positionTokenAccount,
|
|
118
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
119
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
120
|
+
tokenOwnerAccountX,
|
|
121
|
+
tokenOwnerAccountY,
|
|
122
|
+
tokenVaultX: this.#pool.tokenVaultX,
|
|
123
|
+
tokenVaultY: this.#pool.tokenVaultY,
|
|
124
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
125
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
126
|
+
lowerBinArray,
|
|
127
|
+
upperBinArray,
|
|
128
|
+
lowerBinId,
|
|
129
|
+
upperBinId,
|
|
130
|
+
}, {
|
|
131
|
+
programAddress: this.#pool.programAddress
|
|
132
|
+
});
|
|
133
|
+
return [...preInstructions, claimFeeIx, ...postInstructions];
|
|
134
|
+
}
|
|
135
|
+
async withdraw(owner, bpsToRemove, range) {
|
|
136
|
+
const { lowerBinId, upperBinId } = range ?? this.data;
|
|
137
|
+
assertRangeWithinRange({ lowerBinId, upperBinId }, this.data);
|
|
138
|
+
const [positionTokenAccount, { ataX: tokenOwnerAccountX, ataY: tokenOwnerAccountY, preInstructions, postInstructions }] = await Promise.all([
|
|
139
|
+
findPositionTokenAccount({ owner: owner.address, positionMint: this.data.positionMint }),
|
|
140
|
+
processAssociatedTokenAccountPair({
|
|
141
|
+
owner,
|
|
142
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
143
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
144
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
145
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
146
|
+
}),
|
|
147
|
+
]);
|
|
148
|
+
const { lowerBinArray, upperBinArray } = this.binArrayAddresses;
|
|
149
|
+
const withdrawIx = generated.getWithdrawInstruction({
|
|
150
|
+
owner,
|
|
151
|
+
pool: this.#pool.address,
|
|
152
|
+
position: this.address,
|
|
153
|
+
positionTokenAccount,
|
|
154
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
155
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
156
|
+
tokenOwnerAccountX,
|
|
157
|
+
tokenOwnerAccountY,
|
|
158
|
+
tokenVaultX: this.#pool.tokenVaultX,
|
|
159
|
+
tokenVaultY: this.#pool.tokenVaultY,
|
|
160
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
161
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
162
|
+
lowerBinArray,
|
|
163
|
+
upperBinArray,
|
|
164
|
+
lowerBinId,
|
|
165
|
+
upperBinId,
|
|
166
|
+
bpsToRemove,
|
|
167
|
+
}, {
|
|
168
|
+
programAddress: this.#pool.programAddress
|
|
169
|
+
});
|
|
170
|
+
return [...preInstructions, withdrawIx, ...postInstructions];
|
|
171
|
+
}
|
|
172
|
+
async close(owner) {
|
|
173
|
+
return await closePosition({ owner, positionMint: this.data.positionMint, position: this.address }, { programAddress: this.#pool.programAddress });
|
|
174
|
+
}
|
|
175
|
+
static async load(pool, address, config) {
|
|
176
|
+
const position = await generated.fetchPosition(pool.rpc, address, config);
|
|
177
|
+
assertPositionBelongsToPool(position.data, pool);
|
|
178
|
+
const { lowerBinId, upperBinId } = position.data;
|
|
179
|
+
const indices = [...new Set([
|
|
180
|
+
getBinArrayIndex(lowerBinId),
|
|
181
|
+
getBinArrayIndex(upperBinId),
|
|
182
|
+
])];
|
|
183
|
+
const binArrays = await BinArray.loadAll(pool.rpc, pool.address, indices, pool.programAddress, config);
|
|
184
|
+
return new Position(pool, position, binArrays);
|
|
185
|
+
}
|
|
186
|
+
static async loadAll(pool, addresses, config) {
|
|
187
|
+
const positions = await fetchAllPositionsChunked(pool.rpc, addresses, config);
|
|
188
|
+
const indicesByPosition = positions.map(position => [...new Set([getBinArrayIndex(position.data.lowerBinId), getBinArrayIndex(position.data.upperBinId)])]);
|
|
189
|
+
const binArrays = await BinArray.loadAll(pool.rpc, pool.address, [...new Set(indicesByPosition.flat())], pool.programAddress, config);
|
|
190
|
+
const binArrayByIndex = new Map(binArrays.map(binArray => [binArray.data.index, binArray]));
|
|
191
|
+
return positions.map((position, i) => {
|
|
192
|
+
assertPositionBelongsToPool(position.data, pool);
|
|
193
|
+
const positionBinArrays = indicesByPosition[i].map(index => binArrayByIndex.get(index));
|
|
194
|
+
return new Position(pool, position, positionBinArrays);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
static async refreshAll(rpc, positions, config) {
|
|
198
|
+
if (positions.length === 0) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const addresses = positions.map(position => position.address);
|
|
202
|
+
const positionAccounts = await fetchAllPositionsChunked(rpc, addresses, config);
|
|
203
|
+
const binArrayAddresses = [...new Set(positions.flatMap(position => position.#binArrays.map(binArray => binArray.address)))];
|
|
204
|
+
const binArrayAccounts = await fetchAllBinArraysChunked(rpc, binArrayAddresses, config);
|
|
205
|
+
const binArrayByAddress = new Map(binArrayAccounts.map(account => [account.address, account]));
|
|
206
|
+
await Promise.all(positions.map((position, i) => position.refresh([
|
|
207
|
+
positionAccounts[i],
|
|
208
|
+
position.#binArrays.map(binArray => binArrayByAddress.get(binArray.address)),
|
|
209
|
+
])));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
export async function findPositionAddress(seeds, config) {
|
|
213
|
+
const [address] = await generated.findPositionPda(seeds, config);
|
|
214
|
+
return address;
|
|
215
|
+
}
|
|
216
|
+
export async function findAllPositionAddresses({ positionMints }, config) {
|
|
217
|
+
return await Promise.all(positionMints.map(positionMint => findPositionAddress({ positionMint }, config)));
|
|
218
|
+
}
|
|
219
|
+
export async function openPosition(rpc, { owner, positionMint, pool, lowerBinId, upperBinId, }, config) {
|
|
220
|
+
const [adminConfig, position] = await Promise.all([
|
|
221
|
+
resolveAdminConfigAddress(config.programAddress),
|
|
222
|
+
findPositionAddress({ positionMint: positionMint.address }, config),
|
|
223
|
+
]);
|
|
224
|
+
const { metadataUpdateAuthority } = (await generated.fetchAdminConfig(rpc, adminConfig)).data;
|
|
225
|
+
const { lowerBinArrayIndex, upperBinArrayIndex } = getPositionBinArrayIndices(lowerBinId, upperBinId);
|
|
226
|
+
const indices = isUndefined(upperBinArrayIndex) ? [lowerBinArrayIndex] : [lowerBinArrayIndex, upperBinArrayIndex];
|
|
227
|
+
const createBinArraysIxs = await createAllBinArrays({ payer: owner, pool, indices, idempotent: true }, config);
|
|
228
|
+
const openPositionIx = await generated.getOpenPositionInstructionAsync({
|
|
229
|
+
pool,
|
|
230
|
+
lowerBinId,
|
|
231
|
+
upperBinId,
|
|
232
|
+
owner,
|
|
233
|
+
positionMint,
|
|
234
|
+
position,
|
|
235
|
+
adminConfig,
|
|
236
|
+
metadataUpdateAuthority,
|
|
237
|
+
}, config);
|
|
238
|
+
return [...createBinArraysIxs, openPositionIx];
|
|
239
|
+
}
|
|
240
|
+
export async function closePosition({ owner, positionMint, position, }, config) {
|
|
241
|
+
const [resolvedPosition, positionTokenAccount] = await Promise.all([
|
|
242
|
+
position ?? findPositionAddress({ positionMint }, config),
|
|
243
|
+
findPositionTokenAccount({ owner: owner.address, positionMint }),
|
|
244
|
+
]);
|
|
245
|
+
return await generated.getClosePositionInstructionAsync({
|
|
246
|
+
owner,
|
|
247
|
+
position: resolvedPosition,
|
|
248
|
+
positionMint,
|
|
249
|
+
positionTokenAccount,
|
|
250
|
+
}, config);
|
|
251
|
+
}
|
|
252
|
+
async function fetchPositionWithBinArrays(rpc, positionAddress, binArrayAddresses, config) {
|
|
253
|
+
const [positionAccount, ...binArrayAccounts] = await fetchEncodedAccounts(rpc, [
|
|
254
|
+
positionAddress, ...binArrayAddresses,
|
|
255
|
+
], config);
|
|
256
|
+
return [
|
|
257
|
+
decodePosition(positionAccount),
|
|
258
|
+
decodeAllBinArrays(binArrayAccounts)
|
|
259
|
+
];
|
|
260
|
+
}
|
|
261
|
+
async function fetchAllPositionsChunked(rpc, addresses, config) {
|
|
262
|
+
return await fetchInChunks(addresses, MAX_ACCOUNTS_PER_RPC_BATCH, chunkAddresses => generated.fetchAllPosition(rpc, chunkAddresses, config));
|
|
263
|
+
}
|
|
264
|
+
const positionDecoder = generated.getPositionDecoder();
|
|
265
|
+
function decodePosition(maybeAccount) {
|
|
266
|
+
assertAccountExists(maybeAccount);
|
|
267
|
+
return decodeAccount(maybeAccount, positionDecoder);
|
|
268
|
+
}
|
|
269
|
+
const U128_MODULUS = 1n << 128n;
|
|
270
|
+
const SCALE_OFFSET = 64n; // shares and fee-per-share are both Q64.64 — see fee_state.rs
|
|
271
|
+
// Mirrors fee_state.rs's earned_amount(): wrapping u128 subtraction (fee-per-share monotonically
|
|
272
|
+
// increases and wraps on overflow), then floor((current - checkpoint) * (shares >> 64) / 2^64).
|
|
273
|
+
function earnedAmount(feePerShareCurrent, feePerShareCheckpoint, shares) {
|
|
274
|
+
const delta = ((feePerShareCurrent - feePerShareCheckpoint) % U128_MODULUS + U128_MODULUS) % U128_MODULUS;
|
|
275
|
+
const naturalShares = shares >> SCALE_OFFSET;
|
|
276
|
+
return (delta * naturalShares) >> SCALE_OFFSET;
|
|
277
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createSolanaRpc, type Address, type FetchAccountsConfig } from "@solana/kit";
|
|
2
|
+
export type PositionPoolEntry = {
|
|
3
|
+
address: Address;
|
|
4
|
+
pool: Address;
|
|
5
|
+
};
|
|
6
|
+
export declare function fetchAllMaybePositionPoolsChunked(rpc: ReturnType<typeof createSolanaRpc>, addresses: Address[], config?: FetchAccountsConfig): Promise<(PositionPoolEntry | undefined)[]>;
|
|
7
|
+
//# sourceMappingURL=position_pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"position_pool.d.ts","sourceRoot":"","sources":["../../src/entities/position_pool.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAGf,KAAK,OAAO,EAEZ,KAAK,mBAAmB,EAEzB,MAAM,aAAa,CAAC;AAIrB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,EACvC,SAAS,EAAE,OAAO,EAAE,EACpB,MAAM,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,CAAC,iBAAiB,GAAG,SAAS,CAAC,EAAE,CAAC,CAM5C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getAddressDecoder, parseBase64RpcAccount, } from "@solana/kit";
|
|
2
|
+
import { fetchInChunks } from "../utils/chunk";
|
|
3
|
+
import { MAX_ACCOUNTS_PER_RPC_BATCH } from "../utils/constants";
|
|
4
|
+
export async function fetchAllMaybePositionPoolsChunked(rpc, addresses, config) {
|
|
5
|
+
return await fetchInChunks(addresses, MAX_ACCOUNTS_PER_RPC_BATCH, chunkAddresses => fetchAllMaybePositionPools(rpc, chunkAddresses, config));
|
|
6
|
+
}
|
|
7
|
+
const POSITION_POOL_SLICE = Object.freeze({ offset: 8, length: 32 });
|
|
8
|
+
async function fetchAllMaybePositionPools(rpc, addresses, config) {
|
|
9
|
+
const { abortSignal, ...rpcConfig } = config ?? {};
|
|
10
|
+
const { value: accounts } = await rpc.getMultipleAccounts(addresses, {
|
|
11
|
+
...rpcConfig,
|
|
12
|
+
dataSlice: POSITION_POOL_SLICE,
|
|
13
|
+
encoding: "base64",
|
|
14
|
+
}).send({ abortSignal });
|
|
15
|
+
return decodeAllMaybePositionPools(addresses, accounts);
|
|
16
|
+
}
|
|
17
|
+
const addressDecoder = getAddressDecoder();
|
|
18
|
+
function decodeMaybePositionPool(address, account) {
|
|
19
|
+
if (!account) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const pool = addressDecoder.decode(parseBase64RpcAccount(address, account).data);
|
|
23
|
+
return { address, pool };
|
|
24
|
+
}
|
|
25
|
+
function decodeAllMaybePositionPools(addresses, accounts) {
|
|
26
|
+
return accounts.map((account, i) => {
|
|
27
|
+
const address = addresses[i];
|
|
28
|
+
return decodeMaybePositionPool(address, account);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/entities/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,aAAa,GAAG;IAAE,cAAc,EAAE,OAAO,CAAA;CAAE,CAAC"}
|
|
File without changes
|
package/dist/events.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Address } from "@solana/kit";
|
|
1
|
+
import { type Address, type Commitment, type createSolanaRpcSubscriptions } from "@solana/kit";
|
|
2
2
|
export type CreatePoolEvent = {
|
|
3
3
|
pool: Address;
|
|
4
4
|
binStep: number;
|
|
@@ -90,4 +90,12 @@ export type DlmmEvent = {
|
|
|
90
90
|
};
|
|
91
91
|
export declare function decodeEventFromLogLine(logLine: string): DlmmEvent | undefined;
|
|
92
92
|
export declare function decodeEventsFromLogs(logs: readonly string[], programAddress?: Address): DlmmEvent[];
|
|
93
|
+
type RpcSubscriptions = ReturnType<typeof createSolanaRpcSubscriptions>;
|
|
94
|
+
export declare function onEvent(rpcSubscriptions: RpcSubscriptions, handler: (event: DlmmEvent) => void, { address, programAddress, commitment, onError, }?: {
|
|
95
|
+
address?: Address;
|
|
96
|
+
programAddress?: Address;
|
|
97
|
+
commitment?: Commitment;
|
|
98
|
+
onError?: (error: unknown) => void;
|
|
99
|
+
}): Promise<() => void>;
|
|
100
|
+
export {};
|
|
93
101
|
//# sourceMappingURL=events.d.ts.map
|
package/dist/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"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"}
|
package/dist/events.js
CHANGED
|
@@ -164,3 +164,51 @@ export function decodeEventsFromLogs(logs, programAddress = PICON_DLMM_PROGRAM_A
|
|
|
164
164
|
}
|
|
165
165
|
return events;
|
|
166
166
|
}
|
|
167
|
+
// `address` defaults to `programAddress` (every pool the program touches); pass a pool
|
|
168
|
+
// address to scope it. `programAddress` also scopes CPI-log filtering (see decodeEventsFromLogs
|
|
169
|
+
// above), so it should match whatever cluster's program this subscription is watching —
|
|
170
|
+
// defaults to mainnet. Resolves once the subscription is active, with an unsubscribe function.
|
|
171
|
+
// Errors — from the stream itself (e.g. a dropped websocket) or thrown by `handler` — are
|
|
172
|
+
// reported to `onError` instead of rejecting an unheld promise; a `handler` throw only drops
|
|
173
|
+
// that one event, the subscription keeps running.
|
|
174
|
+
export async function onEvent(rpcSubscriptions, handler, { address, programAddress = PICON_DLMM_PROGRAM_ADDRESS, commitment, onError, } = {}) {
|
|
175
|
+
const abortController = new AbortController();
|
|
176
|
+
const eventStream = await subscribeToEvents(rpcSubscriptions, {
|
|
177
|
+
address: address ?? programAddress,
|
|
178
|
+
programAddress,
|
|
179
|
+
commitment,
|
|
180
|
+
abortSignal: abortController.signal,
|
|
181
|
+
});
|
|
182
|
+
(async () => {
|
|
183
|
+
try {
|
|
184
|
+
for await (const event of eventStream) {
|
|
185
|
+
try {
|
|
186
|
+
handler(event);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
onError?.(error);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
if (!abortController.signal.aborted) {
|
|
195
|
+
onError?.(error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
})();
|
|
199
|
+
return () => abortController.abort();
|
|
200
|
+
}
|
|
201
|
+
// Resolves once the subscription is active, so callers know they won't miss anything.
|
|
202
|
+
async function subscribeToEvents(rpcSubscriptions, { address, programAddress, commitment = "confirmed", abortSignal, }) {
|
|
203
|
+
const notifications = await rpcSubscriptions
|
|
204
|
+
.logsNotifications({ mentions: [address] }, { commitment })
|
|
205
|
+
.subscribe({ abortSignal });
|
|
206
|
+
return (async function* () {
|
|
207
|
+
for await (const notification of notifications) {
|
|
208
|
+
if (notification.value.err != null) {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
yield* decodeEventsFromLogs(notification.value.logs, programAddress);
|
|
212
|
+
}
|
|
213
|
+
})();
|
|
214
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * as generated from "./generated";
|
|
2
2
|
export { DistributionMode } from "./generated/types/distributionMode";
|
|
3
3
|
export * as events from "./events";
|
|
4
|
+
export * from "./entities";
|
|
4
5
|
export * from "./utils/constants";
|
|
5
6
|
export { NATIVE_MINT_ADDRESS } from "./utils/ata";
|
|
6
|
-
export
|
|
7
|
+
export type { QuoteInput, QuoteOutput, PoolState, TransferFee } from "./quote";
|
|
7
8
|
export * from "./program_addresses";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC/E,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * as generated from "./generated";
|
|
2
2
|
export { DistributionMode } from "./generated/types/distributionMode";
|
|
3
3
|
export * as events from "./events";
|
|
4
|
+
export * from "./entities";
|
|
4
5
|
export * from "./utils/constants";
|
|
5
6
|
export { NATIVE_MINT_ADDRESS } from "./utils/ata";
|
|
6
|
-
export * from "./actions";
|
|
7
7
|
export * from "./program_addresses";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program_addresses.d.ts","sourceRoot":"","sources":["../src/program_addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"program_addresses.d.ts","sourceRoot":"","sources":["../src/program_addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,0BAA0B,IAAI,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACpF,eAAO,MAAM,sBAAsB,EAAoD,OAAO,CAAC"}
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
// SDK codegen always targets the mainnet IDL (see package.json's `copy-idl`), so this is the
|
|
2
|
-
// same value as `generated.PICON_DLMM_PROGRAM_ADDRESS` — exported under a clearer name here
|
|
3
|
-
// since it's meant to be read standalone, not discovered via the generated namespace.
|
|
4
1
|
export { PICON_DLMM_PROGRAM_ADDRESS as MAINNET_PROGRAM_ADDRESS } from "./generated";
|
|
5
|
-
// Not baked into codegen (the IDL's structure is identical across clusters — only the address
|
|
6
|
-
// differs) — pass this as the `programAddress` argument on any SDK action to target devnet.
|
|
7
2
|
export const DEVNET_PROGRAM_ADDRESS = "tDLMMKoxBt7UkZapYHsEgLGydmFvSQXh5mGzrRovoeM";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Address } from "@solana/kit";
|
|
2
|
+
import type { BinIdRange } from "./bin_location";
|
|
3
|
+
export declare function assertRangeWithinRange(inner: BinIdRange, outer: BinIdRange): void;
|
|
4
|
+
export declare function assertPositionBelongsToPool(position: {
|
|
5
|
+
pool: Address;
|
|
6
|
+
}, pool: {
|
|
7
|
+
address: Address;
|
|
8
|
+
}): void;
|
|
9
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +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;AAE3C,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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function assertRangeWithinRange(inner, outer) {
|
|
2
|
+
if (inner.lowerBinId < outer.lowerBinId || inner.upperBinId > outer.upperBinId) {
|
|
3
|
+
throw new RangeError(`Range (${inner.lowerBinId} to ${inner.upperBinId}) must be inside range (${outer.lowerBinId} to ${outer.upperBinId})`);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export function assertPositionBelongsToPool(position, pool) {
|
|
7
|
+
if (position.pool !== pool.address) {
|
|
8
|
+
throw new Error(`Position's pool (${position.pool}) does not match expected pool (${pool.address})`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export type BinIdRange = {
|
|
2
|
+
lowerBinId: number;
|
|
3
|
+
upperBinId: number;
|
|
4
|
+
};
|
|
1
5
|
export declare function getBinArrayIndex(binId: number): number;
|
|
2
6
|
export declare function getBinIndex(binId: number): number;
|
|
3
7
|
export declare function getBinId(binArrayIndex: number, binIndex: number): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin_location.d.ts","sourceRoot":"","sources":["../../src/utils/bin_location.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,wBAAgB,wBAAwB,CACtC,kBAAkB,EAAE,MAAM,EAC1B,kBAAkB,EAAE,MAAM,GACzB,MAAM,EAAE,CAKV;
|
|
1
|
+
{"version":3,"file":"bin_location.d.ts","sourceRoot":"","sources":["../../src/utils/bin_location.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,wBAAgB,wBAAwB,CACtC,kBAAkB,EAAE,MAAM,EAC1B,kBAAkB,EAAE,MAAM,GACzB,MAAM,EAAE,CAKV;AAED,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB;IAAE,kBAAkB,EAAE,MAAM,CAAC;IAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAAE,CAM7D;AAED,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,OAAO,EACb,YAAY,EAAE,MAAM,GACnB,MAAM,EAAE,CAMV;AAED,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,MAAM,EAAE,CAeV"}
|
|
@@ -11,10 +11,6 @@ export function getBinId(binArrayIndex, binIndex) {
|
|
|
11
11
|
export function getBinArrayIndexSequence(lowerBinArrayIndex, upperBinArrayIndex) {
|
|
12
12
|
return Array.from({ length: upperBinArrayIndex - lowerBinArrayIndex + 1 }, (_, i) => lowerBinArrayIndex + i);
|
|
13
13
|
}
|
|
14
|
-
// A position spans at most MAX_BIN_ARRAYS_PER_POSITION (2) bin arrays — the lower and
|
|
15
|
-
// (only if distinct) upper one covering its range. Shared by every position-scoped
|
|
16
|
-
// instruction that needs to enumerate exactly those arrays (open_position's bin-array
|
|
17
|
-
// bootstrap, withdraw/claim_fee's account derivation).
|
|
18
14
|
export function getPositionBinArrayIndices(lowerBinId, upperBinId) {
|
|
19
15
|
const lowerBinArrayIndex = getBinArrayIndex(lowerBinId);
|
|
20
16
|
const upperBinArrayIndex = getBinArrayIndex(upperBinId);
|
|
@@ -22,9 +18,6 @@ export function getPositionBinArrayIndices(lowerBinId, upperBinId) {
|
|
|
22
18
|
? { lowerBinArrayIndex }
|
|
23
19
|
: { lowerBinArrayIndex, upperBinArrayIndex };
|
|
24
20
|
}
|
|
25
|
-
// One bin array of margin is kept on the opposite side of travel: if the live active bin
|
|
26
|
-
// drifts one array against the expected direction between quote time and execution (e.g. a
|
|
27
|
-
// competing swap lands first), it's still covered by this range instead of reverting.
|
|
28
21
|
export function generateBinArrayIndicesForSwap(activeBinId, xToY, maxBinArrays) {
|
|
29
22
|
const activeBinArrayIndex = getBinArrayIndex(activeBinId);
|
|
30
23
|
const [lowerBinArrayIndex, upperBinArrayIndex] = xToY
|
|
@@ -32,11 +25,6 @@ export function generateBinArrayIndicesForSwap(activeBinId, xToY, maxBinArrays)
|
|
|
32
25
|
: [activeBinArrayIndex - 1, activeBinArrayIndex + (maxBinArrays - 2)];
|
|
33
26
|
return getBinArrayIndexSequence(lowerBinArrayIndex, upperBinArrayIndex);
|
|
34
27
|
}
|
|
35
|
-
// Spans from the live `activeBinId` to the caller's exact `desiredBinId` target, plus one
|
|
36
|
-
// bin array of margin beyond the active end (the side subject to drift — `desiredBinId` is
|
|
37
|
-
// a fixed target, but the live active bin could move further away from it before this tx
|
|
38
|
-
// lands). Capped at `maxBinArrays`, trimming from the `desiredBinId` end so the active+margin
|
|
39
|
-
// anchor stays intact — a sync toward a distant target simply converges partially in that case.
|
|
40
28
|
export function generateBinArrayIndicesForSync(activeBinId, desiredBinId, maxBinArrays) {
|
|
41
29
|
const activeBinArrayIndex = getBinArrayIndex(activeBinId);
|
|
42
30
|
const desiredBinArrayIndex = getBinArrayIndex(desiredBinId);
|
package/dist/utils/chunk.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../src/utils/chunk.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAMxD"}
|
|
1
|
+
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../src/utils/chunk.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAMxD;AAED,wBAAsB,aAAa,CAAC,CAAC,EAAE,CAAC,EACtC,KAAK,EAAE,CAAC,EAAE,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,CAAC,UAAU,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,GACzC,OAAO,CAAC,CAAC,EAAE,CAAC,CAGd"}
|
package/dist/utils/chunk.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type_guards.d.ts","sourceRoot":"","sources":["../../src/utils/type_guards.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,KAAK,IAAI,SAAS,CAEvE"}
|
|
1
|
+
{"version":3,"file":"type_guards.d.ts","sourceRoot":"","sources":["../../src/utils/type_guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,KAAK,IAAI,SAAS,CAEvE;AAED,wBAAgB,SAAS,CAAC,KAAK,SAAS,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,CAQnF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picon-finance/dlmm-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Typescript SDK for interacting with the Picon DLMM protocol",
|
|
5
5
|
"author": "Picon Finance",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"prepublishOnly": "bun run build"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@solana-program/compute-budget": "^0.17.0",
|
|
45
44
|
"@solana-program/system": "^0.13.0",
|
|
46
45
|
"@solana-program/token": "^0.15.0",
|
|
47
46
|
"@solana-program/token-2022": "^0.13.0",
|