@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,481 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeAccount,
|
|
3
|
+
createSolanaRpc,
|
|
4
|
+
assertAccountExists,
|
|
5
|
+
fetchEncodedAccounts,
|
|
6
|
+
type Address,
|
|
7
|
+
type Account,
|
|
8
|
+
type Instruction,
|
|
9
|
+
type TransactionSigner,
|
|
10
|
+
type FetchAccountsConfig,
|
|
11
|
+
type MaybeEncodedAccount,
|
|
12
|
+
} from "@solana/kit";
|
|
13
|
+
|
|
14
|
+
import { generated } from "..";
|
|
15
|
+
import {
|
|
16
|
+
findPositionTokenAccount,
|
|
17
|
+
processAssociatedTokenAccountPair,
|
|
18
|
+
} from "../utils/ata";
|
|
19
|
+
import {
|
|
20
|
+
getBinIndex,
|
|
21
|
+
getBinArrayIndex,
|
|
22
|
+
getPositionBinArrayIndices,
|
|
23
|
+
type BinIdRange,
|
|
24
|
+
} from "../utils/bin_location";
|
|
25
|
+
import {
|
|
26
|
+
assertRangeWithinRange,
|
|
27
|
+
assertPositionBelongsToPool,
|
|
28
|
+
} from "../utils/assert";
|
|
29
|
+
import { isUndefined } from "../utils/type_guards";
|
|
30
|
+
import { fetchInChunks } from "../utils/chunk";
|
|
31
|
+
import { resolveAdminConfigAddress } from "./admin_config";
|
|
32
|
+
import { MAX_ACCOUNTS_PER_RPC_BATCH } from "../utils/constants";
|
|
33
|
+
|
|
34
|
+
import { Pool } from "./pool";
|
|
35
|
+
import {
|
|
36
|
+
BinArray,
|
|
37
|
+
decodeAllBinArrays,
|
|
38
|
+
createAllBinArrays,
|
|
39
|
+
fetchAllBinArraysChunked,
|
|
40
|
+
} from "./bin_array";
|
|
41
|
+
import { type ProgramConfig } from "./types";
|
|
42
|
+
|
|
43
|
+
export class Position {
|
|
44
|
+
#pool: Pool;
|
|
45
|
+
#account: Account<generated.Position>;
|
|
46
|
+
#binArrays: BinArray[];
|
|
47
|
+
|
|
48
|
+
private constructor(
|
|
49
|
+
pool: Pool,
|
|
50
|
+
account: Account<generated.Position>,
|
|
51
|
+
binArrays: BinArray[],
|
|
52
|
+
) {
|
|
53
|
+
this.#pool = pool;
|
|
54
|
+
this.#account = account;
|
|
55
|
+
this.#binArrays = binArrays;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public get address() { return this.#account.address; }
|
|
59
|
+
public get data() { return this.#account.data; }
|
|
60
|
+
public get positionMint() { return this.data.positionMint; }
|
|
61
|
+
|
|
62
|
+
public get binArrayAddresses(): { lowerBinArray: Address, upperBinArray?: Address | undefined } {
|
|
63
|
+
const lowerBinArray = this.#binArrays[0].address;
|
|
64
|
+
const upperBinArray = this.#binArrays.length > 1 ? this.#binArrays[1].address : undefined;
|
|
65
|
+
return { lowerBinArray, upperBinArray };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public getPendingFee(): { amountX: bigint, amountY: bigint } {
|
|
69
|
+
const { lowerBinId, upperBinId, feeStates } = this.data;
|
|
70
|
+
const lowerBinArrayIndex = getBinArrayIndex(lowerBinId);
|
|
71
|
+
|
|
72
|
+
return Array.from({ length: upperBinId - lowerBinId + 1 }, (_, i) => i)
|
|
73
|
+
.flatMap(i => {
|
|
74
|
+
const feeState = feeStates[i]!;
|
|
75
|
+
if (feeState.shares === 0n) return [];
|
|
76
|
+
|
|
77
|
+
const binId = lowerBinId + i;
|
|
78
|
+
|
|
79
|
+
const binIndex = getBinIndex(binId);
|
|
80
|
+
const binArrayIndex = getBinArrayIndex(binId) - lowerBinArrayIndex;
|
|
81
|
+
|
|
82
|
+
const binArray = this.#binArrays[binArrayIndex];
|
|
83
|
+
const bin = binArray.bins[binIndex];
|
|
84
|
+
|
|
85
|
+
return bin.totalShares > 0n ? [{ feeState, bin }] : [];
|
|
86
|
+
})
|
|
87
|
+
.reduce((total, { feeState, bin }) => ({
|
|
88
|
+
amountX: total.amountX + earnedAmount(bin.feePerShareX, feeState.feePerShareCheckpointX, feeState.shares),
|
|
89
|
+
amountY: total.amountY + earnedAmount(bin.feePerShareY, feeState.feePerShareCheckpointY, feeState.shares),
|
|
90
|
+
}), { amountX: 0n, amountY: 0n });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public async refresh(data: [Account<generated.Position>, Account<generated.BinArray>[]]): Promise<void>;
|
|
94
|
+
public async refresh(config?: FetchAccountsConfig): Promise<void>;
|
|
95
|
+
public async refresh(arg?: [Account<generated.Position>, Account<generated.BinArray>[]] | FetchAccountsConfig) {
|
|
96
|
+
if (!Array.isArray(arg)) {
|
|
97
|
+
arg = await fetchPositionWithBinArrays(
|
|
98
|
+
this.#pool.rpc,
|
|
99
|
+
this.address,
|
|
100
|
+
this.#binArrays.map(b => b.address),
|
|
101
|
+
arg,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const [position, binArrays] = arg;
|
|
105
|
+
this.#account = position;
|
|
106
|
+
this.#binArrays.forEach((b, i) => b.refresh(binArrays[i]));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public async depositByWeight(owner: TransactionSigner, {
|
|
110
|
+
amountX,
|
|
111
|
+
amountY,
|
|
112
|
+
lowerBinId,
|
|
113
|
+
binWeights,
|
|
114
|
+
maxActiveBinSlippage,
|
|
115
|
+
distributionMode,
|
|
116
|
+
}: {
|
|
117
|
+
amountX: bigint,
|
|
118
|
+
amountY: bigint,
|
|
119
|
+
lowerBinId: number,
|
|
120
|
+
binWeights: number[],
|
|
121
|
+
maxActiveBinSlippage: number,
|
|
122
|
+
distributionMode: generated.DistributionMode,
|
|
123
|
+
}): Promise<Instruction[]> {
|
|
124
|
+
const upperBinId = lowerBinId + binWeights.length - 1;
|
|
125
|
+
assertRangeWithinRange({ lowerBinId, upperBinId }, this.data);
|
|
126
|
+
|
|
127
|
+
const [positionTokenAccount, {
|
|
128
|
+
ataX: tokenOwnerAccountX,
|
|
129
|
+
ataY: tokenOwnerAccountY,
|
|
130
|
+
preInstructions,
|
|
131
|
+
postInstructions
|
|
132
|
+
}] = await Promise.all([
|
|
133
|
+
findPositionTokenAccount({ owner: owner.address, positionMint: this.data.positionMint }),
|
|
134
|
+
processAssociatedTokenAccountPair({
|
|
135
|
+
owner,
|
|
136
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
137
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
138
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
139
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
140
|
+
amountX,
|
|
141
|
+
amountY,
|
|
142
|
+
}),
|
|
143
|
+
]);
|
|
144
|
+
|
|
145
|
+
const { lowerBinArray, upperBinArray } = this.binArrayAddresses;
|
|
146
|
+
const depositByWeightIx = generated.getDepositByWeightInstruction({
|
|
147
|
+
owner,
|
|
148
|
+
pool: this.#pool.address,
|
|
149
|
+
position: this.address,
|
|
150
|
+
positionTokenAccount,
|
|
151
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
152
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
153
|
+
tokenOwnerAccountX,
|
|
154
|
+
tokenOwnerAccountY,
|
|
155
|
+
tokenVaultX: this.#pool.tokenVaultX,
|
|
156
|
+
tokenVaultY: this.#pool.tokenVaultY,
|
|
157
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
158
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
159
|
+
lowerBinArray,
|
|
160
|
+
upperBinArray,
|
|
161
|
+
amountX,
|
|
162
|
+
amountY,
|
|
163
|
+
activeBinId: this.#pool.activeBinId,
|
|
164
|
+
maxActiveBinSlippage,
|
|
165
|
+
distributionMode,
|
|
166
|
+
lowerBinId,
|
|
167
|
+
binWeights,
|
|
168
|
+
}, {
|
|
169
|
+
programAddress: this.#pool.programAddress
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return [...preInstructions, depositByWeightIx, ...postInstructions];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public async claimFee(
|
|
176
|
+
owner: TransactionSigner,
|
|
177
|
+
range?: BinIdRange,
|
|
178
|
+
): Promise<Instruction[]> {
|
|
179
|
+
const { lowerBinId, upperBinId } = range ?? this.data;
|
|
180
|
+
assertRangeWithinRange({ lowerBinId, upperBinId }, this.data);
|
|
181
|
+
|
|
182
|
+
const [positionTokenAccount, {
|
|
183
|
+
ataX: tokenOwnerAccountX,
|
|
184
|
+
ataY: tokenOwnerAccountY,
|
|
185
|
+
preInstructions,
|
|
186
|
+
postInstructions
|
|
187
|
+
}] = await Promise.all([
|
|
188
|
+
findPositionTokenAccount({ owner: owner.address, positionMint: this.data.positionMint }),
|
|
189
|
+
processAssociatedTokenAccountPair({
|
|
190
|
+
owner,
|
|
191
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
192
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
193
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
194
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
195
|
+
}),
|
|
196
|
+
]);
|
|
197
|
+
|
|
198
|
+
const { lowerBinArray, upperBinArray } = this.binArrayAddresses;
|
|
199
|
+
const claimFeeIx = generated.getClaimFeeInstruction({
|
|
200
|
+
owner,
|
|
201
|
+
pool: this.#pool.address,
|
|
202
|
+
position: this.address,
|
|
203
|
+
positionTokenAccount,
|
|
204
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
205
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
206
|
+
tokenOwnerAccountX,
|
|
207
|
+
tokenOwnerAccountY,
|
|
208
|
+
tokenVaultX: this.#pool.tokenVaultX,
|
|
209
|
+
tokenVaultY: this.#pool.tokenVaultY,
|
|
210
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
211
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
212
|
+
lowerBinArray,
|
|
213
|
+
upperBinArray,
|
|
214
|
+
lowerBinId,
|
|
215
|
+
upperBinId,
|
|
216
|
+
}, {
|
|
217
|
+
programAddress: this.#pool.programAddress
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
return [...preInstructions, claimFeeIx, ...postInstructions];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public async withdraw(
|
|
224
|
+
owner: TransactionSigner,
|
|
225
|
+
bpsToRemove: number,
|
|
226
|
+
range?: BinIdRange,
|
|
227
|
+
): Promise<Instruction[]> {
|
|
228
|
+
const { lowerBinId, upperBinId } = range ?? this.data;
|
|
229
|
+
assertRangeWithinRange({ lowerBinId, upperBinId }, this.data);
|
|
230
|
+
|
|
231
|
+
const [positionTokenAccount, {
|
|
232
|
+
ataX: tokenOwnerAccountX,
|
|
233
|
+
ataY: tokenOwnerAccountY,
|
|
234
|
+
preInstructions,
|
|
235
|
+
postInstructions
|
|
236
|
+
}] = await Promise.all([
|
|
237
|
+
findPositionTokenAccount({ owner: owner.address, positionMint: this.data.positionMint }),
|
|
238
|
+
processAssociatedTokenAccountPair({
|
|
239
|
+
owner,
|
|
240
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
241
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
242
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
243
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
244
|
+
}),
|
|
245
|
+
]);
|
|
246
|
+
|
|
247
|
+
const { lowerBinArray, upperBinArray } = this.binArrayAddresses;
|
|
248
|
+
const withdrawIx = generated.getWithdrawInstruction({
|
|
249
|
+
owner,
|
|
250
|
+
pool: this.#pool.address,
|
|
251
|
+
position: this.address,
|
|
252
|
+
positionTokenAccount,
|
|
253
|
+
tokenMintX: this.#pool.tokenMintX,
|
|
254
|
+
tokenMintY: this.#pool.tokenMintY,
|
|
255
|
+
tokenOwnerAccountX,
|
|
256
|
+
tokenOwnerAccountY,
|
|
257
|
+
tokenVaultX: this.#pool.tokenVaultX,
|
|
258
|
+
tokenVaultY: this.#pool.tokenVaultY,
|
|
259
|
+
tokenProgramX: this.#pool.tokenProgramX,
|
|
260
|
+
tokenProgramY: this.#pool.tokenProgramY,
|
|
261
|
+
lowerBinArray,
|
|
262
|
+
upperBinArray,
|
|
263
|
+
lowerBinId,
|
|
264
|
+
upperBinId,
|
|
265
|
+
bpsToRemove,
|
|
266
|
+
}, {
|
|
267
|
+
programAddress: this.#pool.programAddress
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
return [...preInstructions, withdrawIx, ...postInstructions];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
public async close(owner: TransactionSigner): Promise<Instruction> {
|
|
274
|
+
return await closePosition(
|
|
275
|
+
{ owner, positionMint: this.data.positionMint, position: this.address },
|
|
276
|
+
{ programAddress: this.#pool.programAddress },
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public static async load(
|
|
281
|
+
pool: Pool,
|
|
282
|
+
address: Address,
|
|
283
|
+
config?: FetchAccountsConfig,
|
|
284
|
+
): Promise<Position> {
|
|
285
|
+
const position = await generated.fetchPosition(pool.rpc, address, config);
|
|
286
|
+
assertPositionBelongsToPool(position.data, pool);
|
|
287
|
+
|
|
288
|
+
const { lowerBinId, upperBinId } = position.data;
|
|
289
|
+
const indices = [...new Set([
|
|
290
|
+
getBinArrayIndex(lowerBinId),
|
|
291
|
+
getBinArrayIndex(upperBinId),
|
|
292
|
+
])];
|
|
293
|
+
const binArrays = await BinArray.loadAll(
|
|
294
|
+
pool.rpc,
|
|
295
|
+
pool.address,
|
|
296
|
+
indices,
|
|
297
|
+
pool.programAddress,
|
|
298
|
+
config,
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
return new Position(pool, position, binArrays);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public static async loadAll(
|
|
305
|
+
pool: Pool,
|
|
306
|
+
addresses: Address[],
|
|
307
|
+
config?: FetchAccountsConfig,
|
|
308
|
+
): Promise<Position[]> {
|
|
309
|
+
const positions = await fetchAllPositionsChunked(pool.rpc, addresses, config);
|
|
310
|
+
|
|
311
|
+
const indicesByPosition = positions.map(position =>
|
|
312
|
+
[...new Set([getBinArrayIndex(position.data.lowerBinId), getBinArrayIndex(position.data.upperBinId)])]);
|
|
313
|
+
const binArrays = await BinArray.loadAll(
|
|
314
|
+
pool.rpc,
|
|
315
|
+
pool.address,
|
|
316
|
+
[...new Set(indicesByPosition.flat())],
|
|
317
|
+
pool.programAddress, config,
|
|
318
|
+
);
|
|
319
|
+
const binArrayByIndex = new Map(binArrays.map(binArray => [binArray.data.index, binArray]));
|
|
320
|
+
|
|
321
|
+
return positions.map((position, i) => {
|
|
322
|
+
assertPositionBelongsToPool(position.data, pool);
|
|
323
|
+
const positionBinArrays = indicesByPosition[i].map(index => binArrayByIndex.get(index)!);
|
|
324
|
+
return new Position(pool, position, positionBinArrays);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
public static async refreshAll(
|
|
329
|
+
rpc: ReturnType<typeof createSolanaRpc>,
|
|
330
|
+
positions: Position[],
|
|
331
|
+
config?: FetchAccountsConfig,
|
|
332
|
+
): Promise<void> {
|
|
333
|
+
if (positions.length === 0) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const addresses = positions.map(position => position.address);
|
|
338
|
+
const positionAccounts = await fetchAllPositionsChunked(rpc, addresses, config);
|
|
339
|
+
|
|
340
|
+
const binArrayAddresses = [...new Set(positions.flatMap(position =>
|
|
341
|
+
position.#binArrays.map(binArray => binArray.address)))];
|
|
342
|
+
const binArrayAccounts = await fetchAllBinArraysChunked(rpc, binArrayAddresses, config);
|
|
343
|
+
const binArrayByAddress = new Map(binArrayAccounts.map(account => [account.address, account]));
|
|
344
|
+
|
|
345
|
+
await Promise.all(positions.map((position, i) => position.refresh([
|
|
346
|
+
positionAccounts[i],
|
|
347
|
+
position.#binArrays.map(binArray => binArrayByAddress.get(binArray.address)!),
|
|
348
|
+
])));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export async function findPositionAddress(
|
|
353
|
+
seeds: { positionMint: Address },
|
|
354
|
+
config: ProgramConfig,
|
|
355
|
+
): Promise<Address> {
|
|
356
|
+
const [address] = await generated.findPositionPda(seeds, config);
|
|
357
|
+
return address;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export async function findAllPositionAddresses(
|
|
361
|
+
{ positionMints }: { positionMints: Address[] },
|
|
362
|
+
config: ProgramConfig,
|
|
363
|
+
): Promise<Address[]> {
|
|
364
|
+
return await Promise.all(
|
|
365
|
+
positionMints.map(positionMint => findPositionAddress({ positionMint }, config))
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export async function openPosition(
|
|
370
|
+
rpc: ReturnType<typeof createSolanaRpc>,
|
|
371
|
+
{
|
|
372
|
+
owner,
|
|
373
|
+
positionMint,
|
|
374
|
+
pool,
|
|
375
|
+
lowerBinId,
|
|
376
|
+
upperBinId,
|
|
377
|
+
}: {
|
|
378
|
+
owner: TransactionSigner,
|
|
379
|
+
positionMint: TransactionSigner,
|
|
380
|
+
pool: Address,
|
|
381
|
+
lowerBinId: number,
|
|
382
|
+
upperBinId: number,
|
|
383
|
+
},
|
|
384
|
+
config: ProgramConfig,
|
|
385
|
+
): Promise<Instruction[]> {
|
|
386
|
+
const [adminConfig, position] = await Promise.all([
|
|
387
|
+
resolveAdminConfigAddress(config.programAddress),
|
|
388
|
+
findPositionAddress({ positionMint: positionMint.address }, config),
|
|
389
|
+
]);
|
|
390
|
+
const { metadataUpdateAuthority } = (await generated.fetchAdminConfig(rpc, adminConfig)).data;
|
|
391
|
+
const { lowerBinArrayIndex, upperBinArrayIndex } = getPositionBinArrayIndices(lowerBinId, upperBinId);
|
|
392
|
+
const indices = isUndefined(upperBinArrayIndex) ? [lowerBinArrayIndex] : [lowerBinArrayIndex, upperBinArrayIndex];
|
|
393
|
+
const createBinArraysIxs = await createAllBinArrays(
|
|
394
|
+
{ payer: owner, pool, indices, idempotent: true },
|
|
395
|
+
config,
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
const openPositionIx = await generated.getOpenPositionInstructionAsync({
|
|
399
|
+
pool,
|
|
400
|
+
lowerBinId,
|
|
401
|
+
upperBinId,
|
|
402
|
+
owner,
|
|
403
|
+
positionMint,
|
|
404
|
+
position,
|
|
405
|
+
adminConfig,
|
|
406
|
+
metadataUpdateAuthority,
|
|
407
|
+
}, config);
|
|
408
|
+
|
|
409
|
+
return [...createBinArraysIxs, openPositionIx];
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export async function closePosition(
|
|
413
|
+
{
|
|
414
|
+
owner,
|
|
415
|
+
positionMint,
|
|
416
|
+
position,
|
|
417
|
+
}: {
|
|
418
|
+
owner: TransactionSigner,
|
|
419
|
+
positionMint: Address,
|
|
420
|
+
position?: Address,
|
|
421
|
+
},
|
|
422
|
+
config: ProgramConfig,
|
|
423
|
+
): Promise<Instruction> {
|
|
424
|
+
const [resolvedPosition, positionTokenAccount] = await Promise.all([
|
|
425
|
+
position ?? findPositionAddress({ positionMint }, config),
|
|
426
|
+
findPositionTokenAccount({ owner: owner.address, positionMint }),
|
|
427
|
+
]);
|
|
428
|
+
return await generated.getClosePositionInstructionAsync({
|
|
429
|
+
owner,
|
|
430
|
+
position: resolvedPosition,
|
|
431
|
+
positionMint,
|
|
432
|
+
positionTokenAccount,
|
|
433
|
+
}, config);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
async function fetchPositionWithBinArrays(
|
|
437
|
+
rpc: ReturnType<typeof createSolanaRpc>,
|
|
438
|
+
positionAddress: Address,
|
|
439
|
+
binArrayAddresses: Address[],
|
|
440
|
+
config?: FetchAccountsConfig,
|
|
441
|
+
): Promise<[Account<generated.Position>, Account<generated.BinArray>[]]> {
|
|
442
|
+
const [positionAccount, ...binArrayAccounts] = await fetchEncodedAccounts(rpc, [
|
|
443
|
+
positionAddress, ...binArrayAddresses,
|
|
444
|
+
], config);
|
|
445
|
+
return [
|
|
446
|
+
decodePosition(positionAccount),
|
|
447
|
+
decodeAllBinArrays(binArrayAccounts)
|
|
448
|
+
];
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
async function fetchAllPositionsChunked(
|
|
452
|
+
rpc: ReturnType<typeof createSolanaRpc>,
|
|
453
|
+
addresses: Address[],
|
|
454
|
+
config?: FetchAccountsConfig,
|
|
455
|
+
) {
|
|
456
|
+
return await fetchInChunks(
|
|
457
|
+
addresses,
|
|
458
|
+
MAX_ACCOUNTS_PER_RPC_BATCH,
|
|
459
|
+
chunkAddresses => generated.fetchAllPosition(rpc, chunkAddresses, config),
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const positionDecoder = generated.getPositionDecoder();
|
|
464
|
+
|
|
465
|
+
function decodePosition(
|
|
466
|
+
maybeAccount: MaybeEncodedAccount<string>,
|
|
467
|
+
): Account<generated.Position> {
|
|
468
|
+
assertAccountExists(maybeAccount);
|
|
469
|
+
return decodeAccount(maybeAccount, positionDecoder);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const U128_MODULUS = 1n << 128n;
|
|
473
|
+
const SCALE_OFFSET = 64n; // shares and fee-per-share are both Q64.64 — see fee_state.rs
|
|
474
|
+
|
|
475
|
+
// Mirrors fee_state.rs's earned_amount(): wrapping u128 subtraction (fee-per-share monotonically
|
|
476
|
+
// increases and wraps on overflow), then floor((current - checkpoint) * (shares >> 64) / 2^64).
|
|
477
|
+
function earnedAmount(feePerShareCurrent: bigint, feePerShareCheckpoint: bigint, shares: bigint): bigint {
|
|
478
|
+
const delta = ((feePerShareCurrent - feePerShareCheckpoint) % U128_MODULUS + U128_MODULUS) % U128_MODULUS;
|
|
479
|
+
const naturalShares = shares >> SCALE_OFFSET;
|
|
480
|
+
return (delta * naturalShares) >> SCALE_OFFSET;
|
|
481
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSolanaRpc,
|
|
3
|
+
getAddressDecoder,
|
|
4
|
+
parseBase64RpcAccount,
|
|
5
|
+
type Address,
|
|
6
|
+
type AccountInfoBase,
|
|
7
|
+
type FetchAccountsConfig,
|
|
8
|
+
type AccountInfoWithBase64EncodedData,
|
|
9
|
+
} from "@solana/kit";
|
|
10
|
+
import { fetchInChunks } from "../utils/chunk";
|
|
11
|
+
import { MAX_ACCOUNTS_PER_RPC_BATCH } from "../utils/constants";
|
|
12
|
+
|
|
13
|
+
export type PositionPoolEntry = {
|
|
14
|
+
address: Address,
|
|
15
|
+
pool: Address,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export async function fetchAllMaybePositionPoolsChunked(
|
|
19
|
+
rpc: ReturnType<typeof createSolanaRpc>,
|
|
20
|
+
addresses: Address[],
|
|
21
|
+
config?: FetchAccountsConfig,
|
|
22
|
+
): Promise<(PositionPoolEntry | undefined)[]> {
|
|
23
|
+
return await fetchInChunks(
|
|
24
|
+
addresses,
|
|
25
|
+
MAX_ACCOUNTS_PER_RPC_BATCH,
|
|
26
|
+
chunkAddresses => fetchAllMaybePositionPools(rpc, chunkAddresses, config),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const POSITION_POOL_SLICE = Object.freeze({ offset: 8, length: 32 });
|
|
31
|
+
|
|
32
|
+
async function fetchAllMaybePositionPools(
|
|
33
|
+
rpc: ReturnType<typeof createSolanaRpc>,
|
|
34
|
+
addresses: Address[],
|
|
35
|
+
config?: FetchAccountsConfig,
|
|
36
|
+
): Promise<(PositionPoolEntry | undefined)[]> {
|
|
37
|
+
const { abortSignal, ...rpcConfig } = config ?? {};
|
|
38
|
+
const { value: accounts } = await rpc.getMultipleAccounts(addresses, {
|
|
39
|
+
...rpcConfig,
|
|
40
|
+
dataSlice: POSITION_POOL_SLICE,
|
|
41
|
+
encoding: "base64",
|
|
42
|
+
}).send({ abortSignal });
|
|
43
|
+
|
|
44
|
+
return decodeAllMaybePositionPools(addresses, accounts);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const addressDecoder = getAddressDecoder();
|
|
48
|
+
|
|
49
|
+
function decodeMaybePositionPool(
|
|
50
|
+
address: Address,
|
|
51
|
+
account: (AccountInfoBase & AccountInfoWithBase64EncodedData | null),
|
|
52
|
+
): PositionPoolEntry | undefined {
|
|
53
|
+
if (!account) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const pool = addressDecoder.decode(parseBase64RpcAccount(address, account).data);
|
|
57
|
+
return { address, pool };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function decodeAllMaybePositionPools(
|
|
61
|
+
addresses: Address[],
|
|
62
|
+
accounts: (AccountInfoBase & AccountInfoWithBase64EncodedData | null)[],
|
|
63
|
+
): (PositionPoolEntry | undefined)[] {
|
|
64
|
+
return accounts.map((account, i) => {
|
|
65
|
+
const address = addresses[i];
|
|
66
|
+
return decodeMaybePositionPool(address, account);
|
|
67
|
+
});
|
|
68
|
+
}
|
package/src/events.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
// `generated/types/*.ts` exactly for that reason.
|
|
7
7
|
import {
|
|
8
8
|
type Address,
|
|
9
|
+
type Commitment,
|
|
10
|
+
type createSolanaRpcSubscriptions,
|
|
9
11
|
getAddressDecoder,
|
|
10
12
|
getBase64Encoder,
|
|
11
13
|
getBooleanDecoder,
|
|
@@ -277,3 +279,78 @@ export function decodeEventsFromLogs(logs: readonly string[], programAddress: Ad
|
|
|
277
279
|
}
|
|
278
280
|
return events;
|
|
279
281
|
}
|
|
282
|
+
|
|
283
|
+
type RpcSubscriptions = ReturnType<typeof createSolanaRpcSubscriptions>;
|
|
284
|
+
|
|
285
|
+
// `address` defaults to `programAddress` (every pool the program touches); pass a pool
|
|
286
|
+
// address to scope it. `programAddress` also scopes CPI-log filtering (see decodeEventsFromLogs
|
|
287
|
+
// above), so it should match whatever cluster's program this subscription is watching —
|
|
288
|
+
// defaults to mainnet. Resolves once the subscription is active, with an unsubscribe function.
|
|
289
|
+
// Errors — from the stream itself (e.g. a dropped websocket) or thrown by `handler` — are
|
|
290
|
+
// reported to `onError` instead of rejecting an unheld promise; a `handler` throw only drops
|
|
291
|
+
// that one event, the subscription keeps running.
|
|
292
|
+
export async function onEvent(
|
|
293
|
+
rpcSubscriptions: RpcSubscriptions,
|
|
294
|
+
handler: (event: DlmmEvent) => void,
|
|
295
|
+
{
|
|
296
|
+
address,
|
|
297
|
+
programAddress = PICON_DLMM_PROGRAM_ADDRESS,
|
|
298
|
+
commitment,
|
|
299
|
+
onError,
|
|
300
|
+
}: { address?: Address, programAddress?: Address, commitment?: Commitment, onError?: (error: unknown) => void } = {},
|
|
301
|
+
): Promise<() => void> {
|
|
302
|
+
const abortController = new AbortController();
|
|
303
|
+
const eventStream = await subscribeToEvents(rpcSubscriptions, {
|
|
304
|
+
address: address ?? programAddress,
|
|
305
|
+
programAddress,
|
|
306
|
+
commitment,
|
|
307
|
+
abortSignal: abortController.signal,
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
(async () => {
|
|
311
|
+
try {
|
|
312
|
+
for await (const event of eventStream) {
|
|
313
|
+
try {
|
|
314
|
+
handler(event);
|
|
315
|
+
} catch (error) {
|
|
316
|
+
onError?.(error);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
} catch (error) {
|
|
320
|
+
if (!abortController.signal.aborted) {
|
|
321
|
+
onError?.(error);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
})();
|
|
325
|
+
|
|
326
|
+
return () => abortController.abort();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Resolves once the subscription is active, so callers know they won't miss anything.
|
|
330
|
+
async function subscribeToEvents(
|
|
331
|
+
rpcSubscriptions: RpcSubscriptions,
|
|
332
|
+
{
|
|
333
|
+
address,
|
|
334
|
+
programAddress,
|
|
335
|
+
commitment = "confirmed",
|
|
336
|
+
abortSignal,
|
|
337
|
+
}: {
|
|
338
|
+
address: Address,
|
|
339
|
+
programAddress: Address,
|
|
340
|
+
commitment?: Commitment,
|
|
341
|
+
abortSignal: AbortSignal,
|
|
342
|
+
},
|
|
343
|
+
): Promise<AsyncIterable<DlmmEvent>> {
|
|
344
|
+
const notifications = await rpcSubscriptions
|
|
345
|
+
.logsNotifications({ mentions: [address] }, { commitment })
|
|
346
|
+
.subscribe({ abortSignal });
|
|
347
|
+
|
|
348
|
+
return (async function* () {
|
|
349
|
+
for await (const notification of notifications) {
|
|
350
|
+
if (notification.value.err != null) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
yield* decodeEventsFromLogs(notification.value.logs, programAddress);
|
|
354
|
+
}
|
|
355
|
+
})();
|
|
356
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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";
|
package/src/program_addresses.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { type Address } from "@solana/kit";
|
|
2
2
|
|
|
3
|
-
// SDK codegen always targets the mainnet IDL (see package.json's `copy-idl`), so this is the
|
|
4
|
-
// same value as `generated.PICON_DLMM_PROGRAM_ADDRESS` — exported under a clearer name here
|
|
5
|
-
// since it's meant to be read standalone, not discovered via the generated namespace.
|
|
6
3
|
export { PICON_DLMM_PROGRAM_ADDRESS as MAINNET_PROGRAM_ADDRESS } from "./generated";
|
|
7
|
-
|
|
8
|
-
// Not baked into codegen (the IDL's structure is identical across clusters — only the address
|
|
9
|
-
// differs) — pass this as the `programAddress` argument on any SDK action to target devnet.
|
|
10
4
|
export const DEVNET_PROGRAM_ADDRESS = "tDLMMKoxBt7UkZapYHsEgLGydmFvSQXh5mGzrRovoeM" as Address;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Address } from "@solana/kit";
|
|
2
|
+
|
|
3
|
+
import type { BinIdRange } from "./bin_location";
|
|
4
|
+
|
|
5
|
+
export function assertRangeWithinRange(
|
|
6
|
+
inner: BinIdRange,
|
|
7
|
+
outer: BinIdRange,
|
|
8
|
+
): void {
|
|
9
|
+
if (inner.lowerBinId < outer.lowerBinId || inner.upperBinId > outer.upperBinId) {
|
|
10
|
+
throw new RangeError(
|
|
11
|
+
`Range (${inner.lowerBinId} to ${inner.upperBinId}) must be inside range (${outer.lowerBinId} to ${outer.upperBinId})`,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function assertPositionBelongsToPool(
|
|
17
|
+
position: { pool: Address },
|
|
18
|
+
pool: { address: Address },
|
|
19
|
+
): void {
|
|
20
|
+
if (position.pool !== pool.address) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Position's pool (${position.pool}) does not match expected pool (${pool.address})`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|