@whetstone-research/doppler-sdk 1.0.18 → 1.0.20
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/dist/chunk-BESE77DM.js +3840 -0
- package/dist/chunk-BESE77DM.js.map +1 -0
- package/dist/chunk-KJ6W44WF.cjs +4089 -0
- package/dist/chunk-KJ6W44WF.cjs.map +1 -0
- package/dist/{chunk-AKLS6T3R.cjs → chunk-Y6TJIH33.cjs} +36 -24
- package/dist/chunk-Y6TJIH33.cjs.map +1 -0
- package/dist/{chunk-6TOPYGOG.js → chunk-ZUJKBFXW.js} +35 -24
- package/dist/chunk-ZUJKBFXW.js.map +1 -0
- package/dist/{oracle-7PmpwwPx.d.ts → oracle-D1wPWydZ.d.cts} +1 -33
- package/dist/{oracle-7PmpwwPx.d.cts → oracle-D1wPWydZ.d.ts} +1 -33
- package/dist/{pda-PZRHQJMK.cjs → pda-A4PIAS5Y.cjs} +20 -16
- package/dist/pda-A4PIAS5Y.cjs.map +1 -0
- package/dist/{pda-N6ULJYLG.js → pda-JVAD45XJ.js} +3 -3
- package/dist/pda-JVAD45XJ.js.map +1 -0
- package/dist/solana/index.cjs +391 -3247
- package/dist/solana/index.cjs.map +1 -1
- package/dist/solana/index.d.cts +176 -207
- package/dist/solana/index.d.ts +176 -207
- package/dist/solana/index.js +67 -2923
- package/dist/solana/index.js.map +1 -1
- package/dist/solana/react/index.cjs +53 -85
- package/dist/solana/react/index.cjs.map +1 -1
- package/dist/solana/react/index.d.cts +7 -1
- package/dist/solana/react/index.d.ts +7 -1
- package/dist/solana/react/index.js +15 -47
- package/dist/solana/react/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-6TOPYGOG.js.map +0 -1
- package/dist/chunk-AKLS6T3R.cjs.map +0 -1
- package/dist/chunk-C2D7CIXP.js +0 -977
- package/dist/chunk-C2D7CIXP.js.map +0 -1
- package/dist/chunk-GUGN3EYX.cjs +0 -1069
- package/dist/chunk-GUGN3EYX.cjs.map +0 -1
- package/dist/pda-N6ULJYLG.js.map +0 -1
- package/dist/pda-PZRHQJMK.cjs.map +0 -1
|
@@ -0,0 +1,4089 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkY6TJIH33_cjs = require('./chunk-Y6TJIH33.cjs');
|
|
4
|
+
var kit = require('@solana/kit');
|
|
5
|
+
var programClientCore = require('@solana/program-client-core');
|
|
6
|
+
|
|
7
|
+
var addressCodec = kit.getAddressCodec();
|
|
8
|
+
var boolCodec = kit.getBooleanCodec();
|
|
9
|
+
var u8Codec = kit.getU8Codec();
|
|
10
|
+
var u16Codec = kit.getU16Codec();
|
|
11
|
+
var u32Codec = kit.getU32Codec();
|
|
12
|
+
var u64Codec = kit.getU64Codec();
|
|
13
|
+
var u128Codec = kit.getU128Codec();
|
|
14
|
+
var u256Codec = kit.transformCodec(
|
|
15
|
+
kit.getArrayCodec(u64Codec, { size: 4 }),
|
|
16
|
+
(value) => {
|
|
17
|
+
if (value < 0n) {
|
|
18
|
+
throw new Error("u256 cannot be negative");
|
|
19
|
+
}
|
|
20
|
+
if (value >> 256n !== 0n) {
|
|
21
|
+
throw new Error("u256 overflow");
|
|
22
|
+
}
|
|
23
|
+
const mask = (1n << 64n) - 1n;
|
|
24
|
+
return [
|
|
25
|
+
value & mask,
|
|
26
|
+
value >> 64n & mask,
|
|
27
|
+
value >> 128n & mask,
|
|
28
|
+
value >> 192n & mask
|
|
29
|
+
];
|
|
30
|
+
},
|
|
31
|
+
(value) => {
|
|
32
|
+
let out = 0n;
|
|
33
|
+
for (let i = 0; i < 4; i += 1) {
|
|
34
|
+
out |= value[i] << 64n * BigInt(i);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
var reservedBytesCodec = kit.transformCodec(
|
|
40
|
+
kit.fixCodecSize(kit.getBytesCodec(), 7),
|
|
41
|
+
(value) => value,
|
|
42
|
+
(value) => new Uint8Array(value)
|
|
43
|
+
);
|
|
44
|
+
var observationCodec = kit.getStructCodec([
|
|
45
|
+
["timestamp", u32Codec],
|
|
46
|
+
["price0Cumulative", u256Codec],
|
|
47
|
+
["price1Cumulative", u256Codec]
|
|
48
|
+
]);
|
|
49
|
+
var ammConfigDataCodec = kit.getStructCodec([
|
|
50
|
+
["admin", addressCodec],
|
|
51
|
+
["paused", boolCodec],
|
|
52
|
+
["hookAllowlistLen", u8Codec],
|
|
53
|
+
["hookAllowlist", kit.getArrayCodec(addressCodec, { size: chunkY6TJIH33_cjs.MAX_HOOK_ALLOWLIST })],
|
|
54
|
+
["maxSwapFeeBps", u16Codec],
|
|
55
|
+
["maxFeeSplitBps", u16Codec],
|
|
56
|
+
["protocolFeeEnabled", boolCodec],
|
|
57
|
+
["protocolFeeBps", u16Codec],
|
|
58
|
+
["version", u8Codec],
|
|
59
|
+
["reserved", reservedBytesCodec]
|
|
60
|
+
]);
|
|
61
|
+
var poolDataCodec = kit.getStructCodec([
|
|
62
|
+
["config", addressCodec],
|
|
63
|
+
["token0Mint", addressCodec],
|
|
64
|
+
["token1Mint", addressCodec],
|
|
65
|
+
["vault0", addressCodec],
|
|
66
|
+
["vault1", addressCodec],
|
|
67
|
+
["authority", addressCodec],
|
|
68
|
+
["bump", u8Codec],
|
|
69
|
+
["reserve0", u64Codec],
|
|
70
|
+
["reserve1", u64Codec],
|
|
71
|
+
["totalShares", u128Codec],
|
|
72
|
+
["swapFeeBps", u16Codec],
|
|
73
|
+
["feeSplitBps", u16Codec],
|
|
74
|
+
["feeGrowthGlobal0Q64", u128Codec],
|
|
75
|
+
["feeGrowthGlobal1Q64", u128Codec],
|
|
76
|
+
["feesUnclaimed0", u64Codec],
|
|
77
|
+
["feesUnclaimed1", u64Codec],
|
|
78
|
+
["hookProgram", addressCodec],
|
|
79
|
+
["hookFlags", u32Codec],
|
|
80
|
+
["liquidityMeasureTokenIndex", u8Codec],
|
|
81
|
+
["kLast", u128Codec],
|
|
82
|
+
["protocolFeePosition", addressCodec],
|
|
83
|
+
["locked", u8Codec],
|
|
84
|
+
["version", u8Codec],
|
|
85
|
+
["reserved", reservedBytesCodec]
|
|
86
|
+
]);
|
|
87
|
+
var positionDataCodec = kit.getStructCodec([
|
|
88
|
+
["pool", addressCodec],
|
|
89
|
+
["owner", addressCodec],
|
|
90
|
+
["positionId", u64Codec],
|
|
91
|
+
["shares", u128Codec],
|
|
92
|
+
["feeGrowthLast0Q64", u128Codec],
|
|
93
|
+
["feeGrowthLast1Q64", u128Codec],
|
|
94
|
+
["feeOwed0", u64Codec],
|
|
95
|
+
["feeOwed1", u64Codec],
|
|
96
|
+
["version", u8Codec],
|
|
97
|
+
["reserved", reservedBytesCodec]
|
|
98
|
+
]);
|
|
99
|
+
var oracleStateDataCodec = kit.getStructCodec([
|
|
100
|
+
["pool", addressCodec],
|
|
101
|
+
["initialized", boolCodec],
|
|
102
|
+
["maxPriceChangeRatioQ64", u128Codec],
|
|
103
|
+
["lastSlot", u64Codec],
|
|
104
|
+
["truncPrice0Q64", u128Codec],
|
|
105
|
+
["truncPrice1Q64", u128Codec],
|
|
106
|
+
["deviation0Q64", u128Codec],
|
|
107
|
+
["deviation1Q64", u128Codec],
|
|
108
|
+
["price0Cumulative", u256Codec],
|
|
109
|
+
["price1Cumulative", u256Codec],
|
|
110
|
+
["lastTimestamp", u32Codec],
|
|
111
|
+
["lastObservationTimestamp", u32Codec],
|
|
112
|
+
["observationIntervalSec", u32Codec],
|
|
113
|
+
["observationIndex", u16Codec],
|
|
114
|
+
[
|
|
115
|
+
"observations",
|
|
116
|
+
kit.getArrayCodec(observationCodec, { size: chunkY6TJIH33_cjs.MAX_ORACLE_OBSERVATIONS })
|
|
117
|
+
],
|
|
118
|
+
["version", u8Codec],
|
|
119
|
+
["reserved", reservedBytesCodec]
|
|
120
|
+
]);
|
|
121
|
+
var ammConfigDecoder = kit.getHiddenPrefixDecoder(ammConfigDataCodec, [
|
|
122
|
+
kit.getConstantDecoder(chunkY6TJIH33_cjs.ACCOUNT_DISCRIMINATORS.AmmConfig)
|
|
123
|
+
]);
|
|
124
|
+
var poolDecoder = kit.getHiddenPrefixDecoder(poolDataCodec, [
|
|
125
|
+
kit.getConstantDecoder(chunkY6TJIH33_cjs.ACCOUNT_DISCRIMINATORS.Pool)
|
|
126
|
+
]);
|
|
127
|
+
var positionDecoder = kit.getHiddenPrefixDecoder(positionDataCodec, [
|
|
128
|
+
kit.getConstantDecoder(chunkY6TJIH33_cjs.ACCOUNT_DISCRIMINATORS.Position)
|
|
129
|
+
]);
|
|
130
|
+
var oracleStateDecoder = kit.getHiddenPrefixDecoder(oracleStateDataCodec, [
|
|
131
|
+
kit.getConstantDecoder(chunkY6TJIH33_cjs.ACCOUNT_DISCRIMINATORS.OracleState)
|
|
132
|
+
]);
|
|
133
|
+
function decodeAmmConfig(data) {
|
|
134
|
+
return ammConfigDecoder.decode(data);
|
|
135
|
+
}
|
|
136
|
+
function decodePool(data) {
|
|
137
|
+
return poolDecoder.decode(data);
|
|
138
|
+
}
|
|
139
|
+
function decodePosition(data) {
|
|
140
|
+
return positionDecoder.decode(data);
|
|
141
|
+
}
|
|
142
|
+
function decodeOracleState(data) {
|
|
143
|
+
return oracleStateDecoder.decode(data);
|
|
144
|
+
}
|
|
145
|
+
function encodeInstructionData(discriminator, codec, args) {
|
|
146
|
+
const encodedArgs = (() => {
|
|
147
|
+
if (!codec) {
|
|
148
|
+
return new Uint8Array();
|
|
149
|
+
}
|
|
150
|
+
if (args === void 0) {
|
|
151
|
+
throw new Error("Instruction args are required for codec encoders");
|
|
152
|
+
}
|
|
153
|
+
return new Uint8Array(codec.encode(args));
|
|
154
|
+
})();
|
|
155
|
+
return kit.mergeBytes([discriminator, encodedArgs]);
|
|
156
|
+
}
|
|
157
|
+
var swapExactInArgsCodec = kit.getStructCodec([
|
|
158
|
+
["amountIn", u64Codec],
|
|
159
|
+
["minAmountOut", u64Codec],
|
|
160
|
+
["tradeDirection", u8Codec],
|
|
161
|
+
["updateOracle", boolCodec]
|
|
162
|
+
]);
|
|
163
|
+
var addLiquidityArgsWithOracleCodec = kit.getStructCodec([
|
|
164
|
+
["amount0Max", u64Codec],
|
|
165
|
+
["amount1Max", u64Codec],
|
|
166
|
+
["minSharesOut", u128Codec],
|
|
167
|
+
["updateOracle", boolCodec]
|
|
168
|
+
]);
|
|
169
|
+
var addLiquidityArgsCodec = kit.transformCodec(
|
|
170
|
+
addLiquidityArgsWithOracleCodec,
|
|
171
|
+
(value) => ({
|
|
172
|
+
...value,
|
|
173
|
+
updateOracle: value.updateOracle ?? false
|
|
174
|
+
}),
|
|
175
|
+
(value) => value
|
|
176
|
+
);
|
|
177
|
+
var removeLiquidityArgsCodec = kit.getStructCodec([
|
|
178
|
+
["sharesIn", u128Codec],
|
|
179
|
+
["minAmount0Out", u64Codec],
|
|
180
|
+
["minAmount1Out", u64Codec],
|
|
181
|
+
["updateOracle", boolCodec]
|
|
182
|
+
]);
|
|
183
|
+
var collectFeesArgsCodec = kit.getStructCodec([
|
|
184
|
+
["max0", u64Codec],
|
|
185
|
+
["max1", u64Codec]
|
|
186
|
+
]);
|
|
187
|
+
var collectProtocolFeesArgsCodec = kit.getStructCodec([
|
|
188
|
+
["max0", u64Codec],
|
|
189
|
+
["max1", u64Codec]
|
|
190
|
+
]);
|
|
191
|
+
var createPositionArgsCodec = kit.getStructCodec([["positionId", u64Codec]]);
|
|
192
|
+
var initializeConfigArgsCodec = kit.getStructCodec([
|
|
193
|
+
["admin", addressCodec],
|
|
194
|
+
["maxSwapFeeBps", u16Codec],
|
|
195
|
+
["maxFeeSplitBps", u16Codec],
|
|
196
|
+
["protocolFeeEnabled", boolCodec],
|
|
197
|
+
["protocolFeeBps", u16Codec],
|
|
198
|
+
["hookAllowlist", kit.getArrayCodec(addressCodec, { size: u32Codec })]
|
|
199
|
+
]);
|
|
200
|
+
var initializePoolArgsCodec = kit.getStructCodec([
|
|
201
|
+
["mintA", addressCodec],
|
|
202
|
+
["mintB", addressCodec],
|
|
203
|
+
["initialSwapFeeBps", u16Codec],
|
|
204
|
+
["initialFeeSplitBps", u16Codec],
|
|
205
|
+
["liquidityMeasureTokenIndex", u8Codec],
|
|
206
|
+
["hookProgram", addressCodec],
|
|
207
|
+
["hookFlags", u32Codec]
|
|
208
|
+
]);
|
|
209
|
+
var initializeOracleArgsCodec = kit.getStructCodec([
|
|
210
|
+
["maxPriceChangeRatioQ64", u128Codec],
|
|
211
|
+
["observationIntervalSec", u32Codec],
|
|
212
|
+
["numObservations", u16Codec]
|
|
213
|
+
]);
|
|
214
|
+
var setHookArgsCodec = kit.getStructCodec([
|
|
215
|
+
["hookProgram", addressCodec],
|
|
216
|
+
["hookFlags", u32Codec]
|
|
217
|
+
]);
|
|
218
|
+
var setFeesArgsCodec = kit.getStructCodec([
|
|
219
|
+
["swapFeeBps", u16Codec],
|
|
220
|
+
["feeSplitBps", u16Codec]
|
|
221
|
+
]);
|
|
222
|
+
var transferAdminArgsCodec = kit.getStructCodec([
|
|
223
|
+
["newAdmin", addressCodec]
|
|
224
|
+
]);
|
|
225
|
+
var oracleConsultArgsCodec = kit.getStructCodec([
|
|
226
|
+
["windowSeconds", u32Codec]
|
|
227
|
+
]);
|
|
228
|
+
function encodeSwapExactInArgs(args) {
|
|
229
|
+
return new Uint8Array(swapExactInArgsCodec.encode(args));
|
|
230
|
+
}
|
|
231
|
+
function encodeAddLiquidityArgs(args) {
|
|
232
|
+
return new Uint8Array(addLiquidityArgsCodec.encode(args));
|
|
233
|
+
}
|
|
234
|
+
function encodeRemoveLiquidityArgs(args) {
|
|
235
|
+
return new Uint8Array(removeLiquidityArgsCodec.encode(args));
|
|
236
|
+
}
|
|
237
|
+
function encodeCollectFeesArgs(args) {
|
|
238
|
+
return new Uint8Array(collectFeesArgsCodec.encode(args));
|
|
239
|
+
}
|
|
240
|
+
function encodeCollectProtocolFeesArgs(args) {
|
|
241
|
+
return new Uint8Array(collectProtocolFeesArgsCodec.encode(args));
|
|
242
|
+
}
|
|
243
|
+
function encodeCreatePositionArgs(args) {
|
|
244
|
+
return new Uint8Array(createPositionArgsCodec.encode(args));
|
|
245
|
+
}
|
|
246
|
+
function encodeInitializeConfigArgs(args) {
|
|
247
|
+
return new Uint8Array(initializeConfigArgsCodec.encode(args));
|
|
248
|
+
}
|
|
249
|
+
function encodeInitializePoolArgs(args) {
|
|
250
|
+
return new Uint8Array(initializePoolArgsCodec.encode(args));
|
|
251
|
+
}
|
|
252
|
+
function encodeInitializeOracleArgs(args) {
|
|
253
|
+
return new Uint8Array(initializeOracleArgsCodec.encode(args));
|
|
254
|
+
}
|
|
255
|
+
function encodeSetHookArgs(args) {
|
|
256
|
+
return new Uint8Array(setHookArgsCodec.encode(args));
|
|
257
|
+
}
|
|
258
|
+
function encodeSetFeesArgs(args) {
|
|
259
|
+
return new Uint8Array(setFeesArgsCodec.encode(args));
|
|
260
|
+
}
|
|
261
|
+
function encodeTransferAdminArgs(args) {
|
|
262
|
+
return new Uint8Array(transferAdminArgsCodec.encode(args));
|
|
263
|
+
}
|
|
264
|
+
function encodeOracleConsultArgs(args) {
|
|
265
|
+
return new Uint8Array(oracleConsultArgsCodec.encode(args));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/solana/core/math.ts
|
|
269
|
+
function q64ToNumber(q64) {
|
|
270
|
+
const intPart = q64 >> 64n;
|
|
271
|
+
const fracPart = q64 & (1n << 64n) - 1n;
|
|
272
|
+
return Number(intPart) + Number(fracPart) / Number(chunkY6TJIH33_cjs.Q64_ONE);
|
|
273
|
+
}
|
|
274
|
+
function numberToQ64(n) {
|
|
275
|
+
const intPart = Math.floor(n);
|
|
276
|
+
const fracPart = n - intPart;
|
|
277
|
+
return (BigInt(intPart) << 64n) + BigInt(Math.round(fracPart * Number(chunkY6TJIH33_cjs.Q64_ONE)));
|
|
278
|
+
}
|
|
279
|
+
function q64Mul(a, b) {
|
|
280
|
+
return a * b >> 64n;
|
|
281
|
+
}
|
|
282
|
+
function q64Div(a, b) {
|
|
283
|
+
return (a << 64n) / b;
|
|
284
|
+
}
|
|
285
|
+
function computePrice0Q64(reserve0, reserve1) {
|
|
286
|
+
if (reserve0 === 0n) return 0n;
|
|
287
|
+
return (reserve1 << 64n) / reserve0;
|
|
288
|
+
}
|
|
289
|
+
function computePrice1Q64(reserve0, reserve1) {
|
|
290
|
+
if (reserve1 === 0n) return 0n;
|
|
291
|
+
return (reserve0 << 64n) / reserve1;
|
|
292
|
+
}
|
|
293
|
+
function isqrt(n) {
|
|
294
|
+
if (n < 0n) throw new Error("isqrt: negative input");
|
|
295
|
+
if (n === 0n) return 0n;
|
|
296
|
+
let x = n;
|
|
297
|
+
let y = (x + 1n) / 2n;
|
|
298
|
+
while (y < x) {
|
|
299
|
+
x = y;
|
|
300
|
+
y = (x + n / x) / 2n;
|
|
301
|
+
}
|
|
302
|
+
return x;
|
|
303
|
+
}
|
|
304
|
+
function ceilDiv(a, b) {
|
|
305
|
+
return (a + b - 1n) / b;
|
|
306
|
+
}
|
|
307
|
+
function minBigInt(a, b) {
|
|
308
|
+
return a < b ? a : b;
|
|
309
|
+
}
|
|
310
|
+
function maxBigInt(a, b) {
|
|
311
|
+
return a > b ? a : b;
|
|
312
|
+
}
|
|
313
|
+
function ratioToNumber(numerator, denominator) {
|
|
314
|
+
if (denominator === 0n) return 0;
|
|
315
|
+
const q64 = (numerator << 64n) / denominator;
|
|
316
|
+
return q64ToNumber(q64);
|
|
317
|
+
}
|
|
318
|
+
function getSwapQuote(pool, amountIn, tradeDirection) {
|
|
319
|
+
if (amountIn === 0n) {
|
|
320
|
+
return {
|
|
321
|
+
amountOut: 0n,
|
|
322
|
+
feeTotal: 0n,
|
|
323
|
+
feeDist: 0n,
|
|
324
|
+
feeComp: 0n,
|
|
325
|
+
priceImpact: 0,
|
|
326
|
+
executionPrice: 0
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
const [reserveIn, reserveOut] = tradeDirection === 0 ? [pool.reserve0, pool.reserve1] : [pool.reserve1, pool.reserve0];
|
|
330
|
+
if (reserveIn === 0n || reserveOut === 0n) {
|
|
331
|
+
throw new Error("Pool has zero liquidity");
|
|
332
|
+
}
|
|
333
|
+
const feeTotal = amountIn * BigInt(pool.swapFeeBps) / chunkY6TJIH33_cjs.BPS_DENOM;
|
|
334
|
+
const feeDist = feeTotal * BigInt(pool.feeSplitBps) / chunkY6TJIH33_cjs.BPS_DENOM;
|
|
335
|
+
const feeComp = feeTotal - feeDist;
|
|
336
|
+
const amountInEff = amountIn - feeTotal;
|
|
337
|
+
const amountOut = amountInEff * reserveOut / (reserveIn + amountInEff);
|
|
338
|
+
const spotPrice = ratioToNumber(reserveOut, reserveIn);
|
|
339
|
+
const executionPrice = ratioToNumber(amountOut, amountIn);
|
|
340
|
+
const priceImpact = spotPrice === 0 ? 0 : Math.abs(spotPrice - executionPrice) / spotPrice;
|
|
341
|
+
return {
|
|
342
|
+
amountOut,
|
|
343
|
+
feeTotal,
|
|
344
|
+
feeDist,
|
|
345
|
+
feeComp,
|
|
346
|
+
priceImpact,
|
|
347
|
+
executionPrice
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function getSwapQuoteExactOut(pool, amountOut, tradeDirection) {
|
|
351
|
+
const [reserveIn, reserveOut] = tradeDirection === 0 ? [pool.reserve0, pool.reserve1] : [pool.reserve1, pool.reserve0];
|
|
352
|
+
if (reserveIn === 0n || reserveOut === 0n) {
|
|
353
|
+
throw new Error("Pool has zero liquidity");
|
|
354
|
+
}
|
|
355
|
+
if (amountOut >= reserveOut) {
|
|
356
|
+
throw new Error("Insufficient liquidity for output amount");
|
|
357
|
+
}
|
|
358
|
+
const amountInEff = ceilDiv(amountOut * reserveIn, reserveOut - amountOut);
|
|
359
|
+
const amountIn = ceilDiv(
|
|
360
|
+
amountInEff * chunkY6TJIH33_cjs.BPS_DENOM,
|
|
361
|
+
chunkY6TJIH33_cjs.BPS_DENOM - BigInt(pool.swapFeeBps)
|
|
362
|
+
);
|
|
363
|
+
const feeTotal = amountIn - amountInEff;
|
|
364
|
+
return { amountIn, feeTotal };
|
|
365
|
+
}
|
|
366
|
+
function getAddLiquidityQuote(pool, amount0Max, amount1Max) {
|
|
367
|
+
if (pool.totalShares === 0n) {
|
|
368
|
+
const rawShares = isqrt(amount0Max * amount1Max);
|
|
369
|
+
if (rawShares === 0n) {
|
|
370
|
+
throw new Error("Initial liquidity too small");
|
|
371
|
+
}
|
|
372
|
+
const sharesOut2 = rawShares;
|
|
373
|
+
return {
|
|
374
|
+
sharesOut: sharesOut2,
|
|
375
|
+
amount0: amount0Max,
|
|
376
|
+
amount1: amount1Max,
|
|
377
|
+
poolShare: ratioToNumber(sharesOut2, rawShares)
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
if (pool.reserve0 === 0n || pool.reserve1 === 0n) {
|
|
381
|
+
throw new Error("Invalid pool state: zero reserves with non-zero shares");
|
|
382
|
+
}
|
|
383
|
+
const shares0 = amount0Max * pool.totalShares / pool.reserve0;
|
|
384
|
+
const shares1 = amount1Max * pool.totalShares / pool.reserve1;
|
|
385
|
+
const sharesOut = minBigInt(shares0, shares1);
|
|
386
|
+
const amount0 = ceilDiv(sharesOut * pool.reserve0, pool.totalShares);
|
|
387
|
+
const amount1 = ceilDiv(sharesOut * pool.reserve1, pool.totalShares);
|
|
388
|
+
const newTotalShares = pool.totalShares + sharesOut;
|
|
389
|
+
const poolShare = ratioToNumber(sharesOut, newTotalShares);
|
|
390
|
+
return {
|
|
391
|
+
sharesOut,
|
|
392
|
+
amount0,
|
|
393
|
+
amount1,
|
|
394
|
+
poolShare
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
function getRemoveLiquidityQuote(pool, sharesIn) {
|
|
398
|
+
if (pool.totalShares === 0n) {
|
|
399
|
+
throw new Error("Pool has no shares");
|
|
400
|
+
}
|
|
401
|
+
if (sharesIn > pool.totalShares) {
|
|
402
|
+
throw new Error("Shares exceed total supply");
|
|
403
|
+
}
|
|
404
|
+
const amount0 = sharesIn * pool.reserve0 / pool.totalShares;
|
|
405
|
+
const amount1 = sharesIn * pool.reserve1 / pool.totalShares;
|
|
406
|
+
return { amount0, amount1 };
|
|
407
|
+
}
|
|
408
|
+
function calculateAccruedFees(shares, feeGrowthLastQ64, feeGrowthGlobalQ64) {
|
|
409
|
+
const delta = feeGrowthGlobalQ64 - feeGrowthLastQ64;
|
|
410
|
+
return shares * delta >> 64n;
|
|
411
|
+
}
|
|
412
|
+
function getPendingFees(pool, position) {
|
|
413
|
+
const accrued0 = calculateAccruedFees(
|
|
414
|
+
position.shares,
|
|
415
|
+
position.feeGrowthLast0Q64,
|
|
416
|
+
pool.feeGrowthGlobal0Q64
|
|
417
|
+
);
|
|
418
|
+
const accrued1 = calculateAccruedFees(
|
|
419
|
+
position.shares,
|
|
420
|
+
position.feeGrowthLast1Q64,
|
|
421
|
+
pool.feeGrowthGlobal1Q64
|
|
422
|
+
);
|
|
423
|
+
return {
|
|
424
|
+
pending0: position.feeOwed0 + accrued0,
|
|
425
|
+
pending1: position.feeOwed1 + accrued1
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function getSpotPrice0(pool) {
|
|
429
|
+
if (pool.reserve0 === 0n) return 0;
|
|
430
|
+
return q64ToNumber(computePrice0Q64(pool.reserve0, pool.reserve1));
|
|
431
|
+
}
|
|
432
|
+
function getSpotPrice1(pool) {
|
|
433
|
+
if (pool.reserve1 === 0n) return 0;
|
|
434
|
+
return q64ToNumber(computePrice1Q64(pool.reserve0, pool.reserve1));
|
|
435
|
+
}
|
|
436
|
+
function getK(pool) {
|
|
437
|
+
return pool.reserve0 * pool.reserve1;
|
|
438
|
+
}
|
|
439
|
+
function getTvl(pool, side = 0) {
|
|
440
|
+
if (side === 0) {
|
|
441
|
+
return 2n * pool.reserve0;
|
|
442
|
+
} else {
|
|
443
|
+
return 2n * pool.reserve1;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function calculateTwap(cumulativeStart, cumulativeEnd, timestampStart, timestampEnd) {
|
|
447
|
+
const dt = BigInt(timestampEnd - timestampStart);
|
|
448
|
+
if (dt === 0n) return 0n;
|
|
449
|
+
const cumulativeDiff = cumulativeEnd >= cumulativeStart ? cumulativeEnd - cumulativeStart : (1n << 256n) - cumulativeStart + cumulativeEnd;
|
|
450
|
+
return cumulativeDiff / dt;
|
|
451
|
+
}
|
|
452
|
+
function calculateTwapNumber(cumulativeStart, cumulativeEnd, timestampStart, timestampEnd) {
|
|
453
|
+
const twapQ64 = calculateTwap(
|
|
454
|
+
cumulativeStart,
|
|
455
|
+
cumulativeEnd,
|
|
456
|
+
timestampStart,
|
|
457
|
+
timestampEnd
|
|
458
|
+
);
|
|
459
|
+
return q64ToNumber(twapQ64);
|
|
460
|
+
}
|
|
461
|
+
var CLOSE_POSITION_DISCRIMINATOR = new Uint8Array([
|
|
462
|
+
123,
|
|
463
|
+
134,
|
|
464
|
+
81,
|
|
465
|
+
0,
|
|
466
|
+
49,
|
|
467
|
+
68,
|
|
468
|
+
98,
|
|
469
|
+
98
|
|
470
|
+
]);
|
|
471
|
+
function getClosePositionDiscriminatorBytes() {
|
|
472
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
473
|
+
CLOSE_POSITION_DISCRIMINATOR
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
function getClosePositionInstructionDataEncoder() {
|
|
477
|
+
return kit.transformEncoder(
|
|
478
|
+
kit.getStructEncoder([["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)]]),
|
|
479
|
+
(value) => ({ ...value, discriminator: CLOSE_POSITION_DISCRIMINATOR })
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
function getClosePositionInstructionDataDecoder() {
|
|
483
|
+
return kit.getStructDecoder([
|
|
484
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)]
|
|
485
|
+
]);
|
|
486
|
+
}
|
|
487
|
+
function getClosePositionInstructionDataCodec() {
|
|
488
|
+
return kit.combineCodec(
|
|
489
|
+
getClosePositionInstructionDataEncoder(),
|
|
490
|
+
getClosePositionInstructionDataDecoder()
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
function getClosePositionInstruction(input, config) {
|
|
494
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
495
|
+
const originalAccounts = {
|
|
496
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
497
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
498
|
+
owner: { value: input.owner ?? null, isWritable: false },
|
|
499
|
+
rentRecipient: { value: input.rentRecipient ?? null, isWritable: true }
|
|
500
|
+
};
|
|
501
|
+
const accounts = originalAccounts;
|
|
502
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
503
|
+
return Object.freeze({
|
|
504
|
+
accounts: [
|
|
505
|
+
getAccountMeta("pool", accounts.pool),
|
|
506
|
+
getAccountMeta("position", accounts.position),
|
|
507
|
+
getAccountMeta("owner", accounts.owner),
|
|
508
|
+
getAccountMeta("rentRecipient", accounts.rentRecipient)
|
|
509
|
+
],
|
|
510
|
+
data: getClosePositionInstructionDataEncoder().encode({}),
|
|
511
|
+
programAddress
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
function parseClosePositionInstruction(instruction) {
|
|
515
|
+
if (instruction.accounts.length < 4) {
|
|
516
|
+
throw new kit.SolanaError(
|
|
517
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
518
|
+
{
|
|
519
|
+
actualAccountMetas: instruction.accounts.length,
|
|
520
|
+
expectedAccountMetas: 4
|
|
521
|
+
}
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
let accountIndex = 0;
|
|
525
|
+
const getNextAccount = () => {
|
|
526
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
527
|
+
accountIndex += 1;
|
|
528
|
+
return accountMeta;
|
|
529
|
+
};
|
|
530
|
+
return {
|
|
531
|
+
programAddress: instruction.programAddress,
|
|
532
|
+
accounts: {
|
|
533
|
+
pool: getNextAccount(),
|
|
534
|
+
position: getNextAccount(),
|
|
535
|
+
owner: getNextAccount(),
|
|
536
|
+
rentRecipient: getNextAccount()
|
|
537
|
+
},
|
|
538
|
+
data: getClosePositionInstructionDataDecoder().decode(instruction.data)
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
var COLLECT_FEES_DISCRIMINATOR = new Uint8Array([
|
|
542
|
+
164,
|
|
543
|
+
152,
|
|
544
|
+
207,
|
|
545
|
+
99,
|
|
546
|
+
30,
|
|
547
|
+
186,
|
|
548
|
+
19,
|
|
549
|
+
182
|
|
550
|
+
]);
|
|
551
|
+
function getCollectFeesDiscriminatorBytes() {
|
|
552
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
553
|
+
COLLECT_FEES_DISCRIMINATOR
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
function getCollectFeesInstructionDataEncoder() {
|
|
557
|
+
return kit.transformEncoder(
|
|
558
|
+
kit.getStructEncoder([
|
|
559
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
560
|
+
["max0", kit.getU64Encoder()],
|
|
561
|
+
["max1", kit.getU64Encoder()]
|
|
562
|
+
]),
|
|
563
|
+
(value) => ({ ...value, discriminator: COLLECT_FEES_DISCRIMINATOR })
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
function getCollectFeesInstructionDataDecoder() {
|
|
567
|
+
return kit.getStructDecoder([
|
|
568
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
569
|
+
["max0", kit.getU64Decoder()],
|
|
570
|
+
["max1", kit.getU64Decoder()]
|
|
571
|
+
]);
|
|
572
|
+
}
|
|
573
|
+
function getCollectFeesInstructionDataCodec() {
|
|
574
|
+
return kit.combineCodec(
|
|
575
|
+
getCollectFeesInstructionDataEncoder(),
|
|
576
|
+
getCollectFeesInstructionDataDecoder()
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
async function getCollectFeesInstructionAsync(input, config) {
|
|
580
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
581
|
+
const originalAccounts = {
|
|
582
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
583
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
584
|
+
owner: { value: input.owner ?? null, isWritable: false },
|
|
585
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
586
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
587
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
588
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
589
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
590
|
+
user0: { value: input.user0 ?? null, isWritable: true },
|
|
591
|
+
user1: { value: input.user1 ?? null, isWritable: true },
|
|
592
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
593
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false }
|
|
594
|
+
};
|
|
595
|
+
const accounts = originalAccounts;
|
|
596
|
+
const args = { ...input };
|
|
597
|
+
if (!accounts.authority.value) {
|
|
598
|
+
accounts.authority.value = await kit.getProgramDerivedAddress({
|
|
599
|
+
programAddress,
|
|
600
|
+
seeds: [
|
|
601
|
+
kit.getBytesEncoder().encode(
|
|
602
|
+
new Uint8Array([97, 117, 116, 104, 111, 114, 105, 116, 121])
|
|
603
|
+
),
|
|
604
|
+
kit.getAddressEncoder().encode(
|
|
605
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
606
|
+
)
|
|
607
|
+
]
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
611
|
+
return Object.freeze({
|
|
612
|
+
accounts: [
|
|
613
|
+
getAccountMeta("pool", accounts.pool),
|
|
614
|
+
getAccountMeta("position", accounts.position),
|
|
615
|
+
getAccountMeta("owner", accounts.owner),
|
|
616
|
+
getAccountMeta("authority", accounts.authority),
|
|
617
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
618
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
619
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
620
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
621
|
+
getAccountMeta("user0", accounts.user0),
|
|
622
|
+
getAccountMeta("user1", accounts.user1),
|
|
623
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
624
|
+
getAccountMeta("token1Program", accounts.token1Program)
|
|
625
|
+
],
|
|
626
|
+
data: getCollectFeesInstructionDataEncoder().encode(
|
|
627
|
+
args
|
|
628
|
+
),
|
|
629
|
+
programAddress
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
function getCollectFeesInstruction(input, config) {
|
|
633
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
634
|
+
const originalAccounts = {
|
|
635
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
636
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
637
|
+
owner: { value: input.owner ?? null, isWritable: false },
|
|
638
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
639
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
640
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
641
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
642
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
643
|
+
user0: { value: input.user0 ?? null, isWritable: true },
|
|
644
|
+
user1: { value: input.user1 ?? null, isWritable: true },
|
|
645
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
646
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false }
|
|
647
|
+
};
|
|
648
|
+
const accounts = originalAccounts;
|
|
649
|
+
const args = { ...input };
|
|
650
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
651
|
+
return Object.freeze({
|
|
652
|
+
accounts: [
|
|
653
|
+
getAccountMeta("pool", accounts.pool),
|
|
654
|
+
getAccountMeta("position", accounts.position),
|
|
655
|
+
getAccountMeta("owner", accounts.owner),
|
|
656
|
+
getAccountMeta("authority", accounts.authority),
|
|
657
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
658
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
659
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
660
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
661
|
+
getAccountMeta("user0", accounts.user0),
|
|
662
|
+
getAccountMeta("user1", accounts.user1),
|
|
663
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
664
|
+
getAccountMeta("token1Program", accounts.token1Program)
|
|
665
|
+
],
|
|
666
|
+
data: getCollectFeesInstructionDataEncoder().encode(
|
|
667
|
+
args
|
|
668
|
+
),
|
|
669
|
+
programAddress
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
function parseCollectFeesInstruction(instruction) {
|
|
673
|
+
if (instruction.accounts.length < 12) {
|
|
674
|
+
throw new kit.SolanaError(
|
|
675
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
676
|
+
{
|
|
677
|
+
actualAccountMetas: instruction.accounts.length,
|
|
678
|
+
expectedAccountMetas: 12
|
|
679
|
+
}
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
let accountIndex = 0;
|
|
683
|
+
const getNextAccount = () => {
|
|
684
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
685
|
+
accountIndex += 1;
|
|
686
|
+
return accountMeta;
|
|
687
|
+
};
|
|
688
|
+
return {
|
|
689
|
+
programAddress: instruction.programAddress,
|
|
690
|
+
accounts: {
|
|
691
|
+
pool: getNextAccount(),
|
|
692
|
+
position: getNextAccount(),
|
|
693
|
+
owner: getNextAccount(),
|
|
694
|
+
authority: getNextAccount(),
|
|
695
|
+
vault0: getNextAccount(),
|
|
696
|
+
vault1: getNextAccount(),
|
|
697
|
+
token0Mint: getNextAccount(),
|
|
698
|
+
token1Mint: getNextAccount(),
|
|
699
|
+
user0: getNextAccount(),
|
|
700
|
+
user1: getNextAccount(),
|
|
701
|
+
token0Program: getNextAccount(),
|
|
702
|
+
token1Program: getNextAccount()
|
|
703
|
+
},
|
|
704
|
+
data: getCollectFeesInstructionDataDecoder().decode(instruction.data)
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
var COLLECT_PROTOCOL_FEES_DISCRIMINATOR = new Uint8Array([
|
|
708
|
+
22,
|
|
709
|
+
67,
|
|
710
|
+
23,
|
|
711
|
+
98,
|
|
712
|
+
150,
|
|
713
|
+
178,
|
|
714
|
+
70,
|
|
715
|
+
220
|
|
716
|
+
]);
|
|
717
|
+
function getCollectProtocolFeesDiscriminatorBytes() {
|
|
718
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
719
|
+
COLLECT_PROTOCOL_FEES_DISCRIMINATOR
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
function getCollectProtocolFeesInstructionDataEncoder() {
|
|
723
|
+
return kit.transformEncoder(
|
|
724
|
+
kit.getStructEncoder([
|
|
725
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
726
|
+
["max0", kit.getU64Encoder()],
|
|
727
|
+
["max1", kit.getU64Encoder()]
|
|
728
|
+
]),
|
|
729
|
+
(value) => ({
|
|
730
|
+
...value,
|
|
731
|
+
discriminator: COLLECT_PROTOCOL_FEES_DISCRIMINATOR
|
|
732
|
+
})
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
function getCollectProtocolFeesInstructionDataDecoder() {
|
|
736
|
+
return kit.getStructDecoder([
|
|
737
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
738
|
+
["max0", kit.getU64Decoder()],
|
|
739
|
+
["max1", kit.getU64Decoder()]
|
|
740
|
+
]);
|
|
741
|
+
}
|
|
742
|
+
function getCollectProtocolFeesInstructionDataCodec() {
|
|
743
|
+
return kit.combineCodec(
|
|
744
|
+
getCollectProtocolFeesInstructionDataEncoder(),
|
|
745
|
+
getCollectProtocolFeesInstructionDataDecoder()
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
async function getCollectProtocolFeesInstructionAsync(input, config) {
|
|
749
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
750
|
+
const originalAccounts = {
|
|
751
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
752
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
753
|
+
protocolFeePosition: {
|
|
754
|
+
value: input.protocolFeePosition ?? null,
|
|
755
|
+
isWritable: true
|
|
756
|
+
},
|
|
757
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
758
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
759
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
760
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
761
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
762
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
763
|
+
recipient0: { value: input.recipient0 ?? null, isWritable: true },
|
|
764
|
+
recipient1: { value: input.recipient1 ?? null, isWritable: true },
|
|
765
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
766
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false }
|
|
767
|
+
};
|
|
768
|
+
const accounts = originalAccounts;
|
|
769
|
+
const args = { ...input };
|
|
770
|
+
if (!accounts.authority.value) {
|
|
771
|
+
accounts.authority.value = await kit.getProgramDerivedAddress({
|
|
772
|
+
programAddress,
|
|
773
|
+
seeds: [
|
|
774
|
+
kit.getBytesEncoder().encode(
|
|
775
|
+
new Uint8Array([97, 117, 116, 104, 111, 114, 105, 116, 121])
|
|
776
|
+
),
|
|
777
|
+
kit.getAddressEncoder().encode(
|
|
778
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
779
|
+
)
|
|
780
|
+
]
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
784
|
+
return Object.freeze({
|
|
785
|
+
accounts: [
|
|
786
|
+
getAccountMeta("config", accounts.config),
|
|
787
|
+
getAccountMeta("pool", accounts.pool),
|
|
788
|
+
getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
|
|
789
|
+
getAccountMeta("admin", accounts.admin),
|
|
790
|
+
getAccountMeta("authority", accounts.authority),
|
|
791
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
792
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
793
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
794
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
795
|
+
getAccountMeta("recipient0", accounts.recipient0),
|
|
796
|
+
getAccountMeta("recipient1", accounts.recipient1),
|
|
797
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
798
|
+
getAccountMeta("token1Program", accounts.token1Program)
|
|
799
|
+
],
|
|
800
|
+
data: getCollectProtocolFeesInstructionDataEncoder().encode(
|
|
801
|
+
args
|
|
802
|
+
),
|
|
803
|
+
programAddress
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
function getCollectProtocolFeesInstruction(input, config) {
|
|
807
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
808
|
+
const originalAccounts = {
|
|
809
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
810
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
811
|
+
protocolFeePosition: {
|
|
812
|
+
value: input.protocolFeePosition ?? null,
|
|
813
|
+
isWritable: true
|
|
814
|
+
},
|
|
815
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
816
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
817
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
818
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
819
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
820
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
821
|
+
recipient0: { value: input.recipient0 ?? null, isWritable: true },
|
|
822
|
+
recipient1: { value: input.recipient1 ?? null, isWritable: true },
|
|
823
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
824
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false }
|
|
825
|
+
};
|
|
826
|
+
const accounts = originalAccounts;
|
|
827
|
+
const args = { ...input };
|
|
828
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
829
|
+
return Object.freeze({
|
|
830
|
+
accounts: [
|
|
831
|
+
getAccountMeta("config", accounts.config),
|
|
832
|
+
getAccountMeta("pool", accounts.pool),
|
|
833
|
+
getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
|
|
834
|
+
getAccountMeta("admin", accounts.admin),
|
|
835
|
+
getAccountMeta("authority", accounts.authority),
|
|
836
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
837
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
838
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
839
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
840
|
+
getAccountMeta("recipient0", accounts.recipient0),
|
|
841
|
+
getAccountMeta("recipient1", accounts.recipient1),
|
|
842
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
843
|
+
getAccountMeta("token1Program", accounts.token1Program)
|
|
844
|
+
],
|
|
845
|
+
data: getCollectProtocolFeesInstructionDataEncoder().encode(
|
|
846
|
+
args
|
|
847
|
+
),
|
|
848
|
+
programAddress
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
function parseCollectProtocolFeesInstruction(instruction) {
|
|
852
|
+
if (instruction.accounts.length < 13) {
|
|
853
|
+
throw new kit.SolanaError(
|
|
854
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
855
|
+
{
|
|
856
|
+
actualAccountMetas: instruction.accounts.length,
|
|
857
|
+
expectedAccountMetas: 13
|
|
858
|
+
}
|
|
859
|
+
);
|
|
860
|
+
}
|
|
861
|
+
let accountIndex = 0;
|
|
862
|
+
const getNextAccount = () => {
|
|
863
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
864
|
+
accountIndex += 1;
|
|
865
|
+
return accountMeta;
|
|
866
|
+
};
|
|
867
|
+
return {
|
|
868
|
+
programAddress: instruction.programAddress,
|
|
869
|
+
accounts: {
|
|
870
|
+
config: getNextAccount(),
|
|
871
|
+
pool: getNextAccount(),
|
|
872
|
+
protocolFeePosition: getNextAccount(),
|
|
873
|
+
admin: getNextAccount(),
|
|
874
|
+
authority: getNextAccount(),
|
|
875
|
+
vault0: getNextAccount(),
|
|
876
|
+
vault1: getNextAccount(),
|
|
877
|
+
token0Mint: getNextAccount(),
|
|
878
|
+
token1Mint: getNextAccount(),
|
|
879
|
+
recipient0: getNextAccount(),
|
|
880
|
+
recipient1: getNextAccount(),
|
|
881
|
+
token0Program: getNextAccount(),
|
|
882
|
+
token1Program: getNextAccount()
|
|
883
|
+
},
|
|
884
|
+
data: getCollectProtocolFeesInstructionDataDecoder().decode(
|
|
885
|
+
instruction.data
|
|
886
|
+
)
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
var CREATE_POSITION_DISCRIMINATOR = new Uint8Array([
|
|
890
|
+
48,
|
|
891
|
+
215,
|
|
892
|
+
197,
|
|
893
|
+
153,
|
|
894
|
+
96,
|
|
895
|
+
203,
|
|
896
|
+
180,
|
|
897
|
+
133
|
|
898
|
+
]);
|
|
899
|
+
function getCreatePositionDiscriminatorBytes() {
|
|
900
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
901
|
+
CREATE_POSITION_DISCRIMINATOR
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
function getCreatePositionInstructionDataEncoder() {
|
|
905
|
+
return kit.transformEncoder(
|
|
906
|
+
kit.getStructEncoder([
|
|
907
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
908
|
+
["positionId", kit.getU64Encoder()]
|
|
909
|
+
]),
|
|
910
|
+
(value) => ({ ...value, discriminator: CREATE_POSITION_DISCRIMINATOR })
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
function getCreatePositionInstructionDataDecoder() {
|
|
914
|
+
return kit.getStructDecoder([
|
|
915
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
916
|
+
["positionId", kit.getU64Decoder()]
|
|
917
|
+
]);
|
|
918
|
+
}
|
|
919
|
+
function getCreatePositionInstructionDataCodec() {
|
|
920
|
+
return kit.combineCodec(
|
|
921
|
+
getCreatePositionInstructionDataEncoder(),
|
|
922
|
+
getCreatePositionInstructionDataDecoder()
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
async function getCreatePositionInstructionAsync(input, config) {
|
|
926
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
927
|
+
const originalAccounts = {
|
|
928
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
929
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
930
|
+
owner: { value: input.owner ?? null, isWritable: false },
|
|
931
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
932
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false }
|
|
933
|
+
};
|
|
934
|
+
const accounts = originalAccounts;
|
|
935
|
+
const args = { ...input };
|
|
936
|
+
if (!accounts.position.value) {
|
|
937
|
+
accounts.position.value = await kit.getProgramDerivedAddress({
|
|
938
|
+
programAddress,
|
|
939
|
+
seeds: [
|
|
940
|
+
kit.getBytesEncoder().encode(
|
|
941
|
+
new Uint8Array([112, 111, 115, 105, 116, 105, 111, 110])
|
|
942
|
+
),
|
|
943
|
+
kit.getAddressEncoder().encode(
|
|
944
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
945
|
+
),
|
|
946
|
+
kit.getAddressEncoder().encode(
|
|
947
|
+
programClientCore.getAddressFromResolvedInstructionAccount(
|
|
948
|
+
"owner",
|
|
949
|
+
accounts.owner.value
|
|
950
|
+
)
|
|
951
|
+
),
|
|
952
|
+
kit.getU64Encoder().encode(
|
|
953
|
+
programClientCore.getNonNullResolvedInstructionInput("positionId", args.positionId)
|
|
954
|
+
)
|
|
955
|
+
]
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
if (!accounts.systemProgram.value) {
|
|
959
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
960
|
+
}
|
|
961
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
962
|
+
return Object.freeze({
|
|
963
|
+
accounts: [
|
|
964
|
+
getAccountMeta("pool", accounts.pool),
|
|
965
|
+
getAccountMeta("position", accounts.position),
|
|
966
|
+
getAccountMeta("owner", accounts.owner),
|
|
967
|
+
getAccountMeta("payer", accounts.payer),
|
|
968
|
+
getAccountMeta("systemProgram", accounts.systemProgram)
|
|
969
|
+
],
|
|
970
|
+
data: getCreatePositionInstructionDataEncoder().encode(
|
|
971
|
+
args
|
|
972
|
+
),
|
|
973
|
+
programAddress
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
function getCreatePositionInstruction(input, config) {
|
|
977
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
978
|
+
const originalAccounts = {
|
|
979
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
980
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
981
|
+
owner: { value: input.owner ?? null, isWritable: false },
|
|
982
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
983
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false }
|
|
984
|
+
};
|
|
985
|
+
const accounts = originalAccounts;
|
|
986
|
+
const args = { ...input };
|
|
987
|
+
if (!accounts.systemProgram.value) {
|
|
988
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
989
|
+
}
|
|
990
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
991
|
+
return Object.freeze({
|
|
992
|
+
accounts: [
|
|
993
|
+
getAccountMeta("pool", accounts.pool),
|
|
994
|
+
getAccountMeta("position", accounts.position),
|
|
995
|
+
getAccountMeta("owner", accounts.owner),
|
|
996
|
+
getAccountMeta("payer", accounts.payer),
|
|
997
|
+
getAccountMeta("systemProgram", accounts.systemProgram)
|
|
998
|
+
],
|
|
999
|
+
data: getCreatePositionInstructionDataEncoder().encode(
|
|
1000
|
+
args
|
|
1001
|
+
),
|
|
1002
|
+
programAddress
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
function parseCreatePositionInstruction(instruction) {
|
|
1006
|
+
if (instruction.accounts.length < 5) {
|
|
1007
|
+
throw new kit.SolanaError(
|
|
1008
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
1009
|
+
{
|
|
1010
|
+
actualAccountMetas: instruction.accounts.length,
|
|
1011
|
+
expectedAccountMetas: 5
|
|
1012
|
+
}
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
1015
|
+
let accountIndex = 0;
|
|
1016
|
+
const getNextAccount = () => {
|
|
1017
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
1018
|
+
accountIndex += 1;
|
|
1019
|
+
return accountMeta;
|
|
1020
|
+
};
|
|
1021
|
+
return {
|
|
1022
|
+
programAddress: instruction.programAddress,
|
|
1023
|
+
accounts: {
|
|
1024
|
+
pool: getNextAccount(),
|
|
1025
|
+
position: getNextAccount(),
|
|
1026
|
+
owner: getNextAccount(),
|
|
1027
|
+
payer: getNextAccount(),
|
|
1028
|
+
systemProgram: getNextAccount()
|
|
1029
|
+
},
|
|
1030
|
+
data: getCreatePositionInstructionDataDecoder().decode(instruction.data)
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
var INITIALIZE_CONFIG_DISCRIMINATOR = new Uint8Array([
|
|
1034
|
+
208,
|
|
1035
|
+
127,
|
|
1036
|
+
21,
|
|
1037
|
+
1,
|
|
1038
|
+
194,
|
|
1039
|
+
190,
|
|
1040
|
+
196,
|
|
1041
|
+
70
|
|
1042
|
+
]);
|
|
1043
|
+
function getInitializeConfigDiscriminatorBytes() {
|
|
1044
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
1045
|
+
INITIALIZE_CONFIG_DISCRIMINATOR
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
function getInitializeConfigInstructionDataEncoder() {
|
|
1049
|
+
return kit.transformEncoder(
|
|
1050
|
+
kit.getStructEncoder([
|
|
1051
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
1052
|
+
["admin", kit.getAddressEncoder()],
|
|
1053
|
+
["maxSwapFeeBps", kit.getU16Encoder()],
|
|
1054
|
+
["maxFeeSplitBps", kit.getU16Encoder()],
|
|
1055
|
+
["protocolFeeEnabled", kit.getBooleanEncoder()],
|
|
1056
|
+
["protocolFeeBps", kit.getU16Encoder()],
|
|
1057
|
+
["hookAllowlist", kit.getArrayEncoder(kit.getAddressEncoder())]
|
|
1058
|
+
]),
|
|
1059
|
+
(value) => ({ ...value, discriminator: INITIALIZE_CONFIG_DISCRIMINATOR })
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
function getInitializeConfigInstructionDataDecoder() {
|
|
1063
|
+
return kit.getStructDecoder([
|
|
1064
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
1065
|
+
["admin", kit.getAddressDecoder()],
|
|
1066
|
+
["maxSwapFeeBps", kit.getU16Decoder()],
|
|
1067
|
+
["maxFeeSplitBps", kit.getU16Decoder()],
|
|
1068
|
+
["protocolFeeEnabled", kit.getBooleanDecoder()],
|
|
1069
|
+
["protocolFeeBps", kit.getU16Decoder()],
|
|
1070
|
+
["hookAllowlist", kit.getArrayDecoder(kit.getAddressDecoder())]
|
|
1071
|
+
]);
|
|
1072
|
+
}
|
|
1073
|
+
function getInitializeConfigInstructionDataCodec() {
|
|
1074
|
+
return kit.combineCodec(
|
|
1075
|
+
getInitializeConfigInstructionDataEncoder(),
|
|
1076
|
+
getInitializeConfigInstructionDataDecoder()
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
async function getInitializeConfigInstructionAsync(input, config) {
|
|
1080
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1081
|
+
const originalAccounts = {
|
|
1082
|
+
config: { value: input.config ?? null, isWritable: true },
|
|
1083
|
+
programData: { value: input.programData ?? null, isWritable: false },
|
|
1084
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
1085
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false }
|
|
1086
|
+
};
|
|
1087
|
+
const accounts = originalAccounts;
|
|
1088
|
+
const args = { ...input };
|
|
1089
|
+
if (!accounts.config.value) {
|
|
1090
|
+
accounts.config.value = await kit.getProgramDerivedAddress({
|
|
1091
|
+
programAddress,
|
|
1092
|
+
seeds: [
|
|
1093
|
+
kit.getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103]))
|
|
1094
|
+
]
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
if (!accounts.systemProgram.value) {
|
|
1098
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
1099
|
+
}
|
|
1100
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1101
|
+
return Object.freeze({
|
|
1102
|
+
accounts: [
|
|
1103
|
+
getAccountMeta("config", accounts.config),
|
|
1104
|
+
getAccountMeta("programData", accounts.programData),
|
|
1105
|
+
getAccountMeta("payer", accounts.payer),
|
|
1106
|
+
getAccountMeta("systemProgram", accounts.systemProgram)
|
|
1107
|
+
],
|
|
1108
|
+
data: getInitializeConfigInstructionDataEncoder().encode(
|
|
1109
|
+
args
|
|
1110
|
+
),
|
|
1111
|
+
programAddress
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
function getInitializeConfigInstruction(input, config) {
|
|
1115
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1116
|
+
const originalAccounts = {
|
|
1117
|
+
config: { value: input.config ?? null, isWritable: true },
|
|
1118
|
+
programData: { value: input.programData ?? null, isWritable: false },
|
|
1119
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
1120
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false }
|
|
1121
|
+
};
|
|
1122
|
+
const accounts = originalAccounts;
|
|
1123
|
+
const args = { ...input };
|
|
1124
|
+
if (!accounts.systemProgram.value) {
|
|
1125
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
1126
|
+
}
|
|
1127
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1128
|
+
return Object.freeze({
|
|
1129
|
+
accounts: [
|
|
1130
|
+
getAccountMeta("config", accounts.config),
|
|
1131
|
+
getAccountMeta("programData", accounts.programData),
|
|
1132
|
+
getAccountMeta("payer", accounts.payer),
|
|
1133
|
+
getAccountMeta("systemProgram", accounts.systemProgram)
|
|
1134
|
+
],
|
|
1135
|
+
data: getInitializeConfigInstructionDataEncoder().encode(
|
|
1136
|
+
args
|
|
1137
|
+
),
|
|
1138
|
+
programAddress
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
function parseInitializeConfigInstruction(instruction) {
|
|
1142
|
+
if (instruction.accounts.length < 4) {
|
|
1143
|
+
throw new kit.SolanaError(
|
|
1144
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
1145
|
+
{
|
|
1146
|
+
actualAccountMetas: instruction.accounts.length,
|
|
1147
|
+
expectedAccountMetas: 4
|
|
1148
|
+
}
|
|
1149
|
+
);
|
|
1150
|
+
}
|
|
1151
|
+
let accountIndex = 0;
|
|
1152
|
+
const getNextAccount = () => {
|
|
1153
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
1154
|
+
accountIndex += 1;
|
|
1155
|
+
return accountMeta;
|
|
1156
|
+
};
|
|
1157
|
+
return {
|
|
1158
|
+
programAddress: instruction.programAddress,
|
|
1159
|
+
accounts: {
|
|
1160
|
+
config: getNextAccount(),
|
|
1161
|
+
programData: getNextAccount(),
|
|
1162
|
+
payer: getNextAccount(),
|
|
1163
|
+
systemProgram: getNextAccount()
|
|
1164
|
+
},
|
|
1165
|
+
data: getInitializeConfigInstructionDataDecoder().decode(instruction.data)
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
var INITIALIZE_ORACLE_DISCRIMINATOR = new Uint8Array([
|
|
1169
|
+
144,
|
|
1170
|
+
223,
|
|
1171
|
+
131,
|
|
1172
|
+
120,
|
|
1173
|
+
196,
|
|
1174
|
+
253,
|
|
1175
|
+
181,
|
|
1176
|
+
99
|
|
1177
|
+
]);
|
|
1178
|
+
function getInitializeOracleDiscriminatorBytes() {
|
|
1179
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
1180
|
+
INITIALIZE_ORACLE_DISCRIMINATOR
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
function getInitializeOracleInstructionDataEncoder() {
|
|
1184
|
+
return kit.transformEncoder(
|
|
1185
|
+
kit.getStructEncoder([
|
|
1186
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
1187
|
+
["maxPriceChangeRatioQ64", kit.getU128Encoder()],
|
|
1188
|
+
["observationIntervalSec", kit.getU32Encoder()]
|
|
1189
|
+
]),
|
|
1190
|
+
(value) => ({ ...value, discriminator: INITIALIZE_ORACLE_DISCRIMINATOR })
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
function getInitializeOracleInstructionDataDecoder() {
|
|
1194
|
+
return kit.getStructDecoder([
|
|
1195
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
1196
|
+
["maxPriceChangeRatioQ64", kit.getU128Decoder()],
|
|
1197
|
+
["observationIntervalSec", kit.getU32Decoder()]
|
|
1198
|
+
]);
|
|
1199
|
+
}
|
|
1200
|
+
function getInitializeOracleInstructionDataCodec() {
|
|
1201
|
+
return kit.combineCodec(
|
|
1202
|
+
getInitializeOracleInstructionDataEncoder(),
|
|
1203
|
+
getInitializeOracleInstructionDataDecoder()
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
async function getInitializeOracleInstructionAsync(input, config) {
|
|
1207
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1208
|
+
const originalAccounts = {
|
|
1209
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
1210
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
1211
|
+
oracle: { value: input.oracle ?? null, isWritable: true },
|
|
1212
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
1213
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
1214
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false }
|
|
1215
|
+
};
|
|
1216
|
+
const accounts = originalAccounts;
|
|
1217
|
+
const args = { ...input };
|
|
1218
|
+
if (!accounts.oracle.value) {
|
|
1219
|
+
accounts.oracle.value = await kit.getProgramDerivedAddress({
|
|
1220
|
+
programAddress,
|
|
1221
|
+
seeds: [
|
|
1222
|
+
kit.getBytesEncoder().encode(new Uint8Array([111, 114, 97, 99, 108, 101])),
|
|
1223
|
+
kit.getAddressEncoder().encode(
|
|
1224
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
1225
|
+
)
|
|
1226
|
+
]
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
if (!accounts.systemProgram.value) {
|
|
1230
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
1231
|
+
}
|
|
1232
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1233
|
+
return Object.freeze({
|
|
1234
|
+
accounts: [
|
|
1235
|
+
getAccountMeta("config", accounts.config),
|
|
1236
|
+
getAccountMeta("pool", accounts.pool),
|
|
1237
|
+
getAccountMeta("oracle", accounts.oracle),
|
|
1238
|
+
getAccountMeta("admin", accounts.admin),
|
|
1239
|
+
getAccountMeta("payer", accounts.payer),
|
|
1240
|
+
getAccountMeta("systemProgram", accounts.systemProgram)
|
|
1241
|
+
],
|
|
1242
|
+
data: getInitializeOracleInstructionDataEncoder().encode(
|
|
1243
|
+
args
|
|
1244
|
+
),
|
|
1245
|
+
programAddress
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
function getInitializeOracleInstruction(input, config) {
|
|
1249
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1250
|
+
const originalAccounts = {
|
|
1251
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
1252
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
1253
|
+
oracle: { value: input.oracle ?? null, isWritable: true },
|
|
1254
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
1255
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
1256
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false }
|
|
1257
|
+
};
|
|
1258
|
+
const accounts = originalAccounts;
|
|
1259
|
+
const args = { ...input };
|
|
1260
|
+
if (!accounts.systemProgram.value) {
|
|
1261
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
1262
|
+
}
|
|
1263
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1264
|
+
return Object.freeze({
|
|
1265
|
+
accounts: [
|
|
1266
|
+
getAccountMeta("config", accounts.config),
|
|
1267
|
+
getAccountMeta("pool", accounts.pool),
|
|
1268
|
+
getAccountMeta("oracle", accounts.oracle),
|
|
1269
|
+
getAccountMeta("admin", accounts.admin),
|
|
1270
|
+
getAccountMeta("payer", accounts.payer),
|
|
1271
|
+
getAccountMeta("systemProgram", accounts.systemProgram)
|
|
1272
|
+
],
|
|
1273
|
+
data: getInitializeOracleInstructionDataEncoder().encode(
|
|
1274
|
+
args
|
|
1275
|
+
),
|
|
1276
|
+
programAddress
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
function parseInitializeOracleInstruction(instruction) {
|
|
1280
|
+
if (instruction.accounts.length < 6) {
|
|
1281
|
+
throw new kit.SolanaError(
|
|
1282
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
1283
|
+
{
|
|
1284
|
+
actualAccountMetas: instruction.accounts.length,
|
|
1285
|
+
expectedAccountMetas: 6
|
|
1286
|
+
}
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
let accountIndex = 0;
|
|
1290
|
+
const getNextAccount = () => {
|
|
1291
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
1292
|
+
accountIndex += 1;
|
|
1293
|
+
return accountMeta;
|
|
1294
|
+
};
|
|
1295
|
+
return {
|
|
1296
|
+
programAddress: instruction.programAddress,
|
|
1297
|
+
accounts: {
|
|
1298
|
+
config: getNextAccount(),
|
|
1299
|
+
pool: getNextAccount(),
|
|
1300
|
+
oracle: getNextAccount(),
|
|
1301
|
+
admin: getNextAccount(),
|
|
1302
|
+
payer: getNextAccount(),
|
|
1303
|
+
systemProgram: getNextAccount()
|
|
1304
|
+
},
|
|
1305
|
+
data: getInitializeOracleInstructionDataDecoder().decode(instruction.data)
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
var INITIALIZE_POOL_DISCRIMINATOR = new Uint8Array([
|
|
1309
|
+
95,
|
|
1310
|
+
180,
|
|
1311
|
+
10,
|
|
1312
|
+
172,
|
|
1313
|
+
84,
|
|
1314
|
+
174,
|
|
1315
|
+
232,
|
|
1316
|
+
40
|
|
1317
|
+
]);
|
|
1318
|
+
function getInitializePoolDiscriminatorBytes() {
|
|
1319
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
1320
|
+
INITIALIZE_POOL_DISCRIMINATOR
|
|
1321
|
+
);
|
|
1322
|
+
}
|
|
1323
|
+
function getInitializePoolInstructionDataEncoder() {
|
|
1324
|
+
return kit.transformEncoder(
|
|
1325
|
+
kit.getStructEncoder([
|
|
1326
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
1327
|
+
["mintA", kit.getAddressEncoder()],
|
|
1328
|
+
["mintB", kit.getAddressEncoder()],
|
|
1329
|
+
["initialSwapFeeBps", kit.getU16Encoder()],
|
|
1330
|
+
["initialFeeSplitBps", kit.getU16Encoder()],
|
|
1331
|
+
["liquidityMeasureTokenIndex", kit.getU8Encoder()],
|
|
1332
|
+
["hookProgram", kit.getAddressEncoder()],
|
|
1333
|
+
["hookFlags", kit.getU32Encoder()]
|
|
1334
|
+
]),
|
|
1335
|
+
(value) => ({ ...value, discriminator: INITIALIZE_POOL_DISCRIMINATOR })
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
function getInitializePoolInstructionDataDecoder() {
|
|
1339
|
+
return kit.getStructDecoder([
|
|
1340
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
1341
|
+
["mintA", kit.getAddressDecoder()],
|
|
1342
|
+
["mintB", kit.getAddressDecoder()],
|
|
1343
|
+
["initialSwapFeeBps", kit.getU16Decoder()],
|
|
1344
|
+
["initialFeeSplitBps", kit.getU16Decoder()],
|
|
1345
|
+
["liquidityMeasureTokenIndex", kit.getU8Decoder()],
|
|
1346
|
+
["hookProgram", kit.getAddressDecoder()],
|
|
1347
|
+
["hookFlags", kit.getU32Decoder()]
|
|
1348
|
+
]);
|
|
1349
|
+
}
|
|
1350
|
+
function getInitializePoolInstructionDataCodec() {
|
|
1351
|
+
return kit.combineCodec(
|
|
1352
|
+
getInitializePoolInstructionDataEncoder(),
|
|
1353
|
+
getInitializePoolInstructionDataDecoder()
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
async function getInitializePoolInstructionAsync(input, config) {
|
|
1357
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1358
|
+
const originalAccounts = {
|
|
1359
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
1360
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
1361
|
+
protocolFeePosition: {
|
|
1362
|
+
value: input.protocolFeePosition ?? null,
|
|
1363
|
+
isWritable: true
|
|
1364
|
+
},
|
|
1365
|
+
protocolFeeOwner: {
|
|
1366
|
+
value: input.protocolFeeOwner ?? null,
|
|
1367
|
+
isWritable: false
|
|
1368
|
+
},
|
|
1369
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
1370
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
1371
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
1372
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
1373
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
1374
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
1375
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
1376
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false },
|
|
1377
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
1378
|
+
rent: { value: input.rent ?? null, isWritable: false },
|
|
1379
|
+
migrationAuthority: {
|
|
1380
|
+
value: input.migrationAuthority ?? null,
|
|
1381
|
+
isWritable: false
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
const accounts = originalAccounts;
|
|
1385
|
+
const args = { ...input };
|
|
1386
|
+
if (!accounts.pool.value) {
|
|
1387
|
+
accounts.pool.value = await kit.getProgramDerivedAddress({
|
|
1388
|
+
programAddress,
|
|
1389
|
+
seeds: [
|
|
1390
|
+
kit.getBytesEncoder().encode(new Uint8Array([112, 111, 111, 108])),
|
|
1391
|
+
kit.getAddressEncoder().encode(
|
|
1392
|
+
programClientCore.getAddressFromResolvedInstructionAccount(
|
|
1393
|
+
"token0Mint",
|
|
1394
|
+
accounts.token0Mint.value
|
|
1395
|
+
)
|
|
1396
|
+
),
|
|
1397
|
+
kit.getAddressEncoder().encode(
|
|
1398
|
+
programClientCore.getAddressFromResolvedInstructionAccount(
|
|
1399
|
+
"token1Mint",
|
|
1400
|
+
accounts.token1Mint.value
|
|
1401
|
+
)
|
|
1402
|
+
)
|
|
1403
|
+
]
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
if (!accounts.protocolFeeOwner.value) {
|
|
1407
|
+
accounts.protocolFeeOwner.value = await kit.getProgramDerivedAddress({
|
|
1408
|
+
programAddress,
|
|
1409
|
+
seeds: [
|
|
1410
|
+
kit.getBytesEncoder().encode(
|
|
1411
|
+
new Uint8Array([
|
|
1412
|
+
112,
|
|
1413
|
+
114,
|
|
1414
|
+
111,
|
|
1415
|
+
116,
|
|
1416
|
+
111,
|
|
1417
|
+
99,
|
|
1418
|
+
111,
|
|
1419
|
+
108,
|
|
1420
|
+
95,
|
|
1421
|
+
102,
|
|
1422
|
+
101,
|
|
1423
|
+
101,
|
|
1424
|
+
95,
|
|
1425
|
+
111,
|
|
1426
|
+
119,
|
|
1427
|
+
110,
|
|
1428
|
+
101,
|
|
1429
|
+
114
|
|
1430
|
+
])
|
|
1431
|
+
),
|
|
1432
|
+
kit.getAddressEncoder().encode(
|
|
1433
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
1434
|
+
)
|
|
1435
|
+
]
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
if (!accounts.protocolFeePosition.value) {
|
|
1439
|
+
accounts.protocolFeePosition.value = await kit.getProgramDerivedAddress({
|
|
1440
|
+
programAddress,
|
|
1441
|
+
seeds: [
|
|
1442
|
+
kit.getBytesEncoder().encode(
|
|
1443
|
+
new Uint8Array([112, 111, 115, 105, 116, 105, 111, 110])
|
|
1444
|
+
),
|
|
1445
|
+
kit.getAddressEncoder().encode(
|
|
1446
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
1447
|
+
),
|
|
1448
|
+
kit.getAddressEncoder().encode(
|
|
1449
|
+
programClientCore.getAddressFromResolvedInstructionAccount(
|
|
1450
|
+
"protocolFeeOwner",
|
|
1451
|
+
accounts.protocolFeeOwner.value
|
|
1452
|
+
)
|
|
1453
|
+
),
|
|
1454
|
+
kit.getBytesEncoder().encode(new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0]))
|
|
1455
|
+
]
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
if (!accounts.authority.value) {
|
|
1459
|
+
accounts.authority.value = await kit.getProgramDerivedAddress({
|
|
1460
|
+
programAddress,
|
|
1461
|
+
seeds: [
|
|
1462
|
+
kit.getBytesEncoder().encode(
|
|
1463
|
+
new Uint8Array([97, 117, 116, 104, 111, 114, 105, 116, 121])
|
|
1464
|
+
),
|
|
1465
|
+
kit.getAddressEncoder().encode(
|
|
1466
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
1467
|
+
)
|
|
1468
|
+
]
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
if (!accounts.vault0.value) {
|
|
1472
|
+
accounts.vault0.value = await kit.getProgramDerivedAddress({
|
|
1473
|
+
programAddress,
|
|
1474
|
+
seeds: [
|
|
1475
|
+
kit.getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116, 48])),
|
|
1476
|
+
kit.getAddressEncoder().encode(
|
|
1477
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
1478
|
+
)
|
|
1479
|
+
]
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
if (!accounts.vault1.value) {
|
|
1483
|
+
accounts.vault1.value = await kit.getProgramDerivedAddress({
|
|
1484
|
+
programAddress,
|
|
1485
|
+
seeds: [
|
|
1486
|
+
kit.getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116, 49])),
|
|
1487
|
+
kit.getAddressEncoder().encode(
|
|
1488
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
1489
|
+
)
|
|
1490
|
+
]
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
if (!accounts.systemProgram.value) {
|
|
1494
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
1495
|
+
}
|
|
1496
|
+
if (!accounts.rent.value) {
|
|
1497
|
+
accounts.rent.value = "SysvarRent111111111111111111111111111111111";
|
|
1498
|
+
}
|
|
1499
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1500
|
+
return Object.freeze({
|
|
1501
|
+
accounts: [
|
|
1502
|
+
getAccountMeta("config", accounts.config),
|
|
1503
|
+
getAccountMeta("pool", accounts.pool),
|
|
1504
|
+
getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
|
|
1505
|
+
getAccountMeta("protocolFeeOwner", accounts.protocolFeeOwner),
|
|
1506
|
+
getAccountMeta("authority", accounts.authority),
|
|
1507
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
1508
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
1509
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
1510
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
1511
|
+
getAccountMeta("payer", accounts.payer),
|
|
1512
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
1513
|
+
getAccountMeta("token1Program", accounts.token1Program),
|
|
1514
|
+
getAccountMeta("systemProgram", accounts.systemProgram),
|
|
1515
|
+
getAccountMeta("rent", accounts.rent),
|
|
1516
|
+
getAccountMeta("migrationAuthority", accounts.migrationAuthority)
|
|
1517
|
+
],
|
|
1518
|
+
data: getInitializePoolInstructionDataEncoder().encode(
|
|
1519
|
+
args
|
|
1520
|
+
),
|
|
1521
|
+
programAddress
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
function getInitializePoolInstruction(input, config) {
|
|
1525
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1526
|
+
const originalAccounts = {
|
|
1527
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
1528
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
1529
|
+
protocolFeePosition: {
|
|
1530
|
+
value: input.protocolFeePosition ?? null,
|
|
1531
|
+
isWritable: true
|
|
1532
|
+
},
|
|
1533
|
+
protocolFeeOwner: {
|
|
1534
|
+
value: input.protocolFeeOwner ?? null,
|
|
1535
|
+
isWritable: false
|
|
1536
|
+
},
|
|
1537
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
1538
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
1539
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
1540
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
1541
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
1542
|
+
payer: { value: input.payer ?? null, isWritable: true },
|
|
1543
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
1544
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false },
|
|
1545
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
1546
|
+
rent: { value: input.rent ?? null, isWritable: false },
|
|
1547
|
+
migrationAuthority: {
|
|
1548
|
+
value: input.migrationAuthority ?? null,
|
|
1549
|
+
isWritable: false
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
const accounts = originalAccounts;
|
|
1553
|
+
const args = { ...input };
|
|
1554
|
+
if (!accounts.systemProgram.value) {
|
|
1555
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
1556
|
+
}
|
|
1557
|
+
if (!accounts.rent.value) {
|
|
1558
|
+
accounts.rent.value = "SysvarRent111111111111111111111111111111111";
|
|
1559
|
+
}
|
|
1560
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1561
|
+
return Object.freeze({
|
|
1562
|
+
accounts: [
|
|
1563
|
+
getAccountMeta("config", accounts.config),
|
|
1564
|
+
getAccountMeta("pool", accounts.pool),
|
|
1565
|
+
getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
|
|
1566
|
+
getAccountMeta("protocolFeeOwner", accounts.protocolFeeOwner),
|
|
1567
|
+
getAccountMeta("authority", accounts.authority),
|
|
1568
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
1569
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
1570
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
1571
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
1572
|
+
getAccountMeta("payer", accounts.payer),
|
|
1573
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
1574
|
+
getAccountMeta("token1Program", accounts.token1Program),
|
|
1575
|
+
getAccountMeta("systemProgram", accounts.systemProgram),
|
|
1576
|
+
getAccountMeta("rent", accounts.rent),
|
|
1577
|
+
getAccountMeta("migrationAuthority", accounts.migrationAuthority)
|
|
1578
|
+
],
|
|
1579
|
+
data: getInitializePoolInstructionDataEncoder().encode(
|
|
1580
|
+
args
|
|
1581
|
+
),
|
|
1582
|
+
programAddress
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
function parseInitializePoolInstruction(instruction) {
|
|
1586
|
+
if (instruction.accounts.length < 15) {
|
|
1587
|
+
throw new kit.SolanaError(
|
|
1588
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
1589
|
+
{
|
|
1590
|
+
actualAccountMetas: instruction.accounts.length,
|
|
1591
|
+
expectedAccountMetas: 15
|
|
1592
|
+
}
|
|
1593
|
+
);
|
|
1594
|
+
}
|
|
1595
|
+
let accountIndex = 0;
|
|
1596
|
+
const getNextAccount = () => {
|
|
1597
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
1598
|
+
accountIndex += 1;
|
|
1599
|
+
return accountMeta;
|
|
1600
|
+
};
|
|
1601
|
+
return {
|
|
1602
|
+
programAddress: instruction.programAddress,
|
|
1603
|
+
accounts: {
|
|
1604
|
+
config: getNextAccount(),
|
|
1605
|
+
pool: getNextAccount(),
|
|
1606
|
+
protocolFeePosition: getNextAccount(),
|
|
1607
|
+
protocolFeeOwner: getNextAccount(),
|
|
1608
|
+
authority: getNextAccount(),
|
|
1609
|
+
vault0: getNextAccount(),
|
|
1610
|
+
vault1: getNextAccount(),
|
|
1611
|
+
token0Mint: getNextAccount(),
|
|
1612
|
+
token1Mint: getNextAccount(),
|
|
1613
|
+
payer: getNextAccount(),
|
|
1614
|
+
token0Program: getNextAccount(),
|
|
1615
|
+
token1Program: getNextAccount(),
|
|
1616
|
+
systemProgram: getNextAccount(),
|
|
1617
|
+
rent: getNextAccount(),
|
|
1618
|
+
migrationAuthority: getNextAccount()
|
|
1619
|
+
},
|
|
1620
|
+
data: getInitializePoolInstructionDataDecoder().decode(instruction.data)
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
var ORACLE_CONSULT_DISCRIMINATOR = new Uint8Array([
|
|
1624
|
+
239,
|
|
1625
|
+
237,
|
|
1626
|
+
255,
|
|
1627
|
+
177,
|
|
1628
|
+
142,
|
|
1629
|
+
72,
|
|
1630
|
+
96,
|
|
1631
|
+
175
|
|
1632
|
+
]);
|
|
1633
|
+
function getOracleConsultDiscriminatorBytes() {
|
|
1634
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
1635
|
+
ORACLE_CONSULT_DISCRIMINATOR
|
|
1636
|
+
);
|
|
1637
|
+
}
|
|
1638
|
+
function getOracleConsultInstructionDataEncoder() {
|
|
1639
|
+
return kit.transformEncoder(
|
|
1640
|
+
kit.getStructEncoder([
|
|
1641
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
1642
|
+
["windowSeconds", kit.getU32Encoder()]
|
|
1643
|
+
]),
|
|
1644
|
+
(value) => ({ ...value, discriminator: ORACLE_CONSULT_DISCRIMINATOR })
|
|
1645
|
+
);
|
|
1646
|
+
}
|
|
1647
|
+
function getOracleConsultInstructionDataDecoder() {
|
|
1648
|
+
return kit.getStructDecoder([
|
|
1649
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
1650
|
+
["windowSeconds", kit.getU32Decoder()]
|
|
1651
|
+
]);
|
|
1652
|
+
}
|
|
1653
|
+
function getOracleConsultInstructionDataCodec() {
|
|
1654
|
+
return kit.combineCodec(
|
|
1655
|
+
getOracleConsultInstructionDataEncoder(),
|
|
1656
|
+
getOracleConsultInstructionDataDecoder()
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
async function getOracleConsultInstructionAsync(input, config) {
|
|
1660
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1661
|
+
const originalAccounts = {
|
|
1662
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
1663
|
+
oracle: { value: input.oracle ?? null, isWritable: false }
|
|
1664
|
+
};
|
|
1665
|
+
const accounts = originalAccounts;
|
|
1666
|
+
const args = { ...input };
|
|
1667
|
+
if (!accounts.oracle.value) {
|
|
1668
|
+
accounts.oracle.value = await kit.getProgramDerivedAddress({
|
|
1669
|
+
programAddress,
|
|
1670
|
+
seeds: [
|
|
1671
|
+
kit.getBytesEncoder().encode(new Uint8Array([111, 114, 97, 99, 108, 101])),
|
|
1672
|
+
kit.getAddressEncoder().encode(
|
|
1673
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
1674
|
+
)
|
|
1675
|
+
]
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1679
|
+
return Object.freeze({
|
|
1680
|
+
accounts: [
|
|
1681
|
+
getAccountMeta("pool", accounts.pool),
|
|
1682
|
+
getAccountMeta("oracle", accounts.oracle)
|
|
1683
|
+
],
|
|
1684
|
+
data: getOracleConsultInstructionDataEncoder().encode(
|
|
1685
|
+
args
|
|
1686
|
+
),
|
|
1687
|
+
programAddress
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
function getOracleConsultInstruction(input, config) {
|
|
1691
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1692
|
+
const originalAccounts = {
|
|
1693
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
1694
|
+
oracle: { value: input.oracle ?? null, isWritable: false }
|
|
1695
|
+
};
|
|
1696
|
+
const accounts = originalAccounts;
|
|
1697
|
+
const args = { ...input };
|
|
1698
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1699
|
+
return Object.freeze({
|
|
1700
|
+
accounts: [
|
|
1701
|
+
getAccountMeta("pool", accounts.pool),
|
|
1702
|
+
getAccountMeta("oracle", accounts.oracle)
|
|
1703
|
+
],
|
|
1704
|
+
data: getOracleConsultInstructionDataEncoder().encode(
|
|
1705
|
+
args
|
|
1706
|
+
),
|
|
1707
|
+
programAddress
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
function parseOracleConsultInstruction(instruction) {
|
|
1711
|
+
if (instruction.accounts.length < 2) {
|
|
1712
|
+
throw new kit.SolanaError(
|
|
1713
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
1714
|
+
{
|
|
1715
|
+
actualAccountMetas: instruction.accounts.length,
|
|
1716
|
+
expectedAccountMetas: 2
|
|
1717
|
+
}
|
|
1718
|
+
);
|
|
1719
|
+
}
|
|
1720
|
+
let accountIndex = 0;
|
|
1721
|
+
const getNextAccount = () => {
|
|
1722
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
1723
|
+
accountIndex += 1;
|
|
1724
|
+
return accountMeta;
|
|
1725
|
+
};
|
|
1726
|
+
return {
|
|
1727
|
+
programAddress: instruction.programAddress,
|
|
1728
|
+
accounts: { pool: getNextAccount(), oracle: getNextAccount() },
|
|
1729
|
+
data: getOracleConsultInstructionDataDecoder().decode(instruction.data)
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
var ORACLE_UPDATE_DISCRIMINATOR = new Uint8Array([
|
|
1733
|
+
85,
|
|
1734
|
+
209,
|
|
1735
|
+
248,
|
|
1736
|
+
142,
|
|
1737
|
+
186,
|
|
1738
|
+
249,
|
|
1739
|
+
120,
|
|
1740
|
+
239
|
|
1741
|
+
]);
|
|
1742
|
+
function getOracleUpdateDiscriminatorBytes() {
|
|
1743
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
1744
|
+
ORACLE_UPDATE_DISCRIMINATOR
|
|
1745
|
+
);
|
|
1746
|
+
}
|
|
1747
|
+
function getOracleUpdateInstructionDataEncoder() {
|
|
1748
|
+
return kit.transformEncoder(
|
|
1749
|
+
kit.getStructEncoder([["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)]]),
|
|
1750
|
+
(value) => ({ ...value, discriminator: ORACLE_UPDATE_DISCRIMINATOR })
|
|
1751
|
+
);
|
|
1752
|
+
}
|
|
1753
|
+
function getOracleUpdateInstructionDataDecoder() {
|
|
1754
|
+
return kit.getStructDecoder([
|
|
1755
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)]
|
|
1756
|
+
]);
|
|
1757
|
+
}
|
|
1758
|
+
function getOracleUpdateInstructionDataCodec() {
|
|
1759
|
+
return kit.combineCodec(
|
|
1760
|
+
getOracleUpdateInstructionDataEncoder(),
|
|
1761
|
+
getOracleUpdateInstructionDataDecoder()
|
|
1762
|
+
);
|
|
1763
|
+
}
|
|
1764
|
+
async function getOracleUpdateInstructionAsync(input, config) {
|
|
1765
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1766
|
+
const originalAccounts = {
|
|
1767
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
1768
|
+
oracle: { value: input.oracle ?? null, isWritable: true }
|
|
1769
|
+
};
|
|
1770
|
+
const accounts = originalAccounts;
|
|
1771
|
+
if (!accounts.oracle.value) {
|
|
1772
|
+
accounts.oracle.value = await kit.getProgramDerivedAddress({
|
|
1773
|
+
programAddress,
|
|
1774
|
+
seeds: [
|
|
1775
|
+
kit.getBytesEncoder().encode(new Uint8Array([111, 114, 97, 99, 108, 101])),
|
|
1776
|
+
kit.getAddressEncoder().encode(
|
|
1777
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
1778
|
+
)
|
|
1779
|
+
]
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1783
|
+
return Object.freeze({
|
|
1784
|
+
accounts: [
|
|
1785
|
+
getAccountMeta("pool", accounts.pool),
|
|
1786
|
+
getAccountMeta("oracle", accounts.oracle)
|
|
1787
|
+
],
|
|
1788
|
+
data: getOracleUpdateInstructionDataEncoder().encode({}),
|
|
1789
|
+
programAddress
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
function getOracleUpdateInstruction(input, config) {
|
|
1793
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1794
|
+
const originalAccounts = {
|
|
1795
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
1796
|
+
oracle: { value: input.oracle ?? null, isWritable: true }
|
|
1797
|
+
};
|
|
1798
|
+
const accounts = originalAccounts;
|
|
1799
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1800
|
+
return Object.freeze({
|
|
1801
|
+
accounts: [
|
|
1802
|
+
getAccountMeta("pool", accounts.pool),
|
|
1803
|
+
getAccountMeta("oracle", accounts.oracle)
|
|
1804
|
+
],
|
|
1805
|
+
data: getOracleUpdateInstructionDataEncoder().encode({}),
|
|
1806
|
+
programAddress
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
function parseOracleUpdateInstruction(instruction) {
|
|
1810
|
+
if (instruction.accounts.length < 2) {
|
|
1811
|
+
throw new kit.SolanaError(
|
|
1812
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
1813
|
+
{
|
|
1814
|
+
actualAccountMetas: instruction.accounts.length,
|
|
1815
|
+
expectedAccountMetas: 2
|
|
1816
|
+
}
|
|
1817
|
+
);
|
|
1818
|
+
}
|
|
1819
|
+
let accountIndex = 0;
|
|
1820
|
+
const getNextAccount = () => {
|
|
1821
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
1822
|
+
accountIndex += 1;
|
|
1823
|
+
return accountMeta;
|
|
1824
|
+
};
|
|
1825
|
+
return {
|
|
1826
|
+
programAddress: instruction.programAddress,
|
|
1827
|
+
accounts: { pool: getNextAccount(), oracle: getNextAccount() },
|
|
1828
|
+
data: getOracleUpdateInstructionDataDecoder().decode(instruction.data)
|
|
1829
|
+
};
|
|
1830
|
+
}
|
|
1831
|
+
var PAUSE_DISCRIMINATOR = new Uint8Array([
|
|
1832
|
+
211,
|
|
1833
|
+
22,
|
|
1834
|
+
221,
|
|
1835
|
+
251,
|
|
1836
|
+
74,
|
|
1837
|
+
121,
|
|
1838
|
+
193,
|
|
1839
|
+
47
|
|
1840
|
+
]);
|
|
1841
|
+
function getPauseDiscriminatorBytes() {
|
|
1842
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(PAUSE_DISCRIMINATOR);
|
|
1843
|
+
}
|
|
1844
|
+
function getPauseInstructionDataEncoder() {
|
|
1845
|
+
return kit.transformEncoder(
|
|
1846
|
+
kit.getStructEncoder([["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)]]),
|
|
1847
|
+
(value) => ({ ...value, discriminator: PAUSE_DISCRIMINATOR })
|
|
1848
|
+
);
|
|
1849
|
+
}
|
|
1850
|
+
function getPauseInstructionDataDecoder() {
|
|
1851
|
+
return kit.getStructDecoder([
|
|
1852
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)]
|
|
1853
|
+
]);
|
|
1854
|
+
}
|
|
1855
|
+
function getPauseInstructionDataCodec() {
|
|
1856
|
+
return kit.combineCodec(
|
|
1857
|
+
getPauseInstructionDataEncoder(),
|
|
1858
|
+
getPauseInstructionDataDecoder()
|
|
1859
|
+
);
|
|
1860
|
+
}
|
|
1861
|
+
function getPauseInstruction(input, config) {
|
|
1862
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1863
|
+
const originalAccounts = {
|
|
1864
|
+
config: { value: input.config ?? null, isWritable: true },
|
|
1865
|
+
admin: { value: input.admin ?? null, isWritable: false }
|
|
1866
|
+
};
|
|
1867
|
+
const accounts = originalAccounts;
|
|
1868
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1869
|
+
return Object.freeze({
|
|
1870
|
+
accounts: [
|
|
1871
|
+
getAccountMeta("config", accounts.config),
|
|
1872
|
+
getAccountMeta("admin", accounts.admin)
|
|
1873
|
+
],
|
|
1874
|
+
data: getPauseInstructionDataEncoder().encode({}),
|
|
1875
|
+
programAddress
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
function parsePauseInstruction(instruction) {
|
|
1879
|
+
if (instruction.accounts.length < 2) {
|
|
1880
|
+
throw new kit.SolanaError(
|
|
1881
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
1882
|
+
{
|
|
1883
|
+
actualAccountMetas: instruction.accounts.length,
|
|
1884
|
+
expectedAccountMetas: 2
|
|
1885
|
+
}
|
|
1886
|
+
);
|
|
1887
|
+
}
|
|
1888
|
+
let accountIndex = 0;
|
|
1889
|
+
const getNextAccount = () => {
|
|
1890
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
1891
|
+
accountIndex += 1;
|
|
1892
|
+
return accountMeta;
|
|
1893
|
+
};
|
|
1894
|
+
return {
|
|
1895
|
+
programAddress: instruction.programAddress,
|
|
1896
|
+
accounts: { config: getNextAccount(), admin: getNextAccount() },
|
|
1897
|
+
data: getPauseInstructionDataDecoder().decode(instruction.data)
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1900
|
+
var PREVIEW_SWAP_EXACT_IN_DISCRIMINATOR = new Uint8Array([
|
|
1901
|
+
50,
|
|
1902
|
+
130,
|
|
1903
|
+
31,
|
|
1904
|
+
69,
|
|
1905
|
+
147,
|
|
1906
|
+
58,
|
|
1907
|
+
222,
|
|
1908
|
+
178
|
|
1909
|
+
]);
|
|
1910
|
+
function getPreviewSwapExactInDiscriminatorBytes() {
|
|
1911
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
1912
|
+
PREVIEW_SWAP_EXACT_IN_DISCRIMINATOR
|
|
1913
|
+
);
|
|
1914
|
+
}
|
|
1915
|
+
function getPreviewSwapExactInInstructionDataEncoder() {
|
|
1916
|
+
return kit.transformEncoder(
|
|
1917
|
+
kit.getStructEncoder([
|
|
1918
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
1919
|
+
["amountIn", kit.getU64Encoder()],
|
|
1920
|
+
["tradeDirection", kit.getU8Encoder()]
|
|
1921
|
+
]),
|
|
1922
|
+
(value) => ({
|
|
1923
|
+
...value,
|
|
1924
|
+
discriminator: PREVIEW_SWAP_EXACT_IN_DISCRIMINATOR
|
|
1925
|
+
})
|
|
1926
|
+
);
|
|
1927
|
+
}
|
|
1928
|
+
function getPreviewSwapExactInInstructionDataDecoder() {
|
|
1929
|
+
return kit.getStructDecoder([
|
|
1930
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
1931
|
+
["amountIn", kit.getU64Decoder()],
|
|
1932
|
+
["tradeDirection", kit.getU8Decoder()]
|
|
1933
|
+
]);
|
|
1934
|
+
}
|
|
1935
|
+
function getPreviewSwapExactInInstructionDataCodec() {
|
|
1936
|
+
return kit.combineCodec(
|
|
1937
|
+
getPreviewSwapExactInInstructionDataEncoder(),
|
|
1938
|
+
getPreviewSwapExactInInstructionDataDecoder()
|
|
1939
|
+
);
|
|
1940
|
+
}
|
|
1941
|
+
function getPreviewSwapExactInInstruction(input, config) {
|
|
1942
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
1943
|
+
const originalAccounts = {
|
|
1944
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
1945
|
+
pool: { value: input.pool ?? null, isWritable: false }
|
|
1946
|
+
};
|
|
1947
|
+
const accounts = originalAccounts;
|
|
1948
|
+
const args = { ...input };
|
|
1949
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
1950
|
+
return Object.freeze({
|
|
1951
|
+
accounts: [
|
|
1952
|
+
getAccountMeta("config", accounts.config),
|
|
1953
|
+
getAccountMeta("pool", accounts.pool)
|
|
1954
|
+
],
|
|
1955
|
+
data: getPreviewSwapExactInInstructionDataEncoder().encode(
|
|
1956
|
+
args
|
|
1957
|
+
),
|
|
1958
|
+
programAddress
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
function parsePreviewSwapExactInInstruction(instruction) {
|
|
1962
|
+
if (instruction.accounts.length < 2) {
|
|
1963
|
+
throw new kit.SolanaError(
|
|
1964
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
1965
|
+
{
|
|
1966
|
+
actualAccountMetas: instruction.accounts.length,
|
|
1967
|
+
expectedAccountMetas: 2
|
|
1968
|
+
}
|
|
1969
|
+
);
|
|
1970
|
+
}
|
|
1971
|
+
let accountIndex = 0;
|
|
1972
|
+
const getNextAccount = () => {
|
|
1973
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
1974
|
+
accountIndex += 1;
|
|
1975
|
+
return accountMeta;
|
|
1976
|
+
};
|
|
1977
|
+
return {
|
|
1978
|
+
programAddress: instruction.programAddress,
|
|
1979
|
+
accounts: { config: getNextAccount(), pool: getNextAccount() },
|
|
1980
|
+
data: getPreviewSwapExactInInstructionDataDecoder().decode(
|
|
1981
|
+
instruction.data
|
|
1982
|
+
)
|
|
1983
|
+
};
|
|
1984
|
+
}
|
|
1985
|
+
var REDEEM_PROTOCOL_SHARES_DISCRIMINATOR = new Uint8Array([
|
|
1986
|
+
143,
|
|
1987
|
+
253,
|
|
1988
|
+
251,
|
|
1989
|
+
77,
|
|
1990
|
+
213,
|
|
1991
|
+
178,
|
|
1992
|
+
0,
|
|
1993
|
+
225
|
|
1994
|
+
]);
|
|
1995
|
+
function getRedeemProtocolSharesDiscriminatorBytes() {
|
|
1996
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
1997
|
+
REDEEM_PROTOCOL_SHARES_DISCRIMINATOR
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
function getRedeemProtocolSharesInstructionDataEncoder() {
|
|
2001
|
+
return kit.transformEncoder(
|
|
2002
|
+
kit.getStructEncoder([
|
|
2003
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
2004
|
+
["sharesIn", kit.getU128Encoder()],
|
|
2005
|
+
["minAmount0Out", kit.getU64Encoder()],
|
|
2006
|
+
["minAmount1Out", kit.getU64Encoder()]
|
|
2007
|
+
]),
|
|
2008
|
+
(value) => ({
|
|
2009
|
+
...value,
|
|
2010
|
+
discriminator: REDEEM_PROTOCOL_SHARES_DISCRIMINATOR
|
|
2011
|
+
})
|
|
2012
|
+
);
|
|
2013
|
+
}
|
|
2014
|
+
function getRedeemProtocolSharesInstructionDataDecoder() {
|
|
2015
|
+
return kit.getStructDecoder([
|
|
2016
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
2017
|
+
["sharesIn", kit.getU128Decoder()],
|
|
2018
|
+
["minAmount0Out", kit.getU64Decoder()],
|
|
2019
|
+
["minAmount1Out", kit.getU64Decoder()]
|
|
2020
|
+
]);
|
|
2021
|
+
}
|
|
2022
|
+
function getRedeemProtocolSharesInstructionDataCodec() {
|
|
2023
|
+
return kit.combineCodec(
|
|
2024
|
+
getRedeemProtocolSharesInstructionDataEncoder(),
|
|
2025
|
+
getRedeemProtocolSharesInstructionDataDecoder()
|
|
2026
|
+
);
|
|
2027
|
+
}
|
|
2028
|
+
async function getRedeemProtocolSharesInstructionAsync(input, config) {
|
|
2029
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2030
|
+
const originalAccounts = {
|
|
2031
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
2032
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
2033
|
+
protocolFeePosition: {
|
|
2034
|
+
value: input.protocolFeePosition ?? null,
|
|
2035
|
+
isWritable: true
|
|
2036
|
+
},
|
|
2037
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
2038
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
2039
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
2040
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
2041
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
2042
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
2043
|
+
recipient0: { value: input.recipient0 ?? null, isWritable: true },
|
|
2044
|
+
recipient1: { value: input.recipient1 ?? null, isWritable: true },
|
|
2045
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
2046
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false }
|
|
2047
|
+
};
|
|
2048
|
+
const accounts = originalAccounts;
|
|
2049
|
+
const args = { ...input };
|
|
2050
|
+
if (!accounts.authority.value) {
|
|
2051
|
+
accounts.authority.value = await kit.getProgramDerivedAddress({
|
|
2052
|
+
programAddress,
|
|
2053
|
+
seeds: [
|
|
2054
|
+
kit.getBytesEncoder().encode(
|
|
2055
|
+
new Uint8Array([97, 117, 116, 104, 111, 114, 105, 116, 121])
|
|
2056
|
+
),
|
|
2057
|
+
kit.getAddressEncoder().encode(
|
|
2058
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
2059
|
+
)
|
|
2060
|
+
]
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2064
|
+
return Object.freeze({
|
|
2065
|
+
accounts: [
|
|
2066
|
+
getAccountMeta("config", accounts.config),
|
|
2067
|
+
getAccountMeta("pool", accounts.pool),
|
|
2068
|
+
getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
|
|
2069
|
+
getAccountMeta("admin", accounts.admin),
|
|
2070
|
+
getAccountMeta("authority", accounts.authority),
|
|
2071
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
2072
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
2073
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
2074
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
2075
|
+
getAccountMeta("recipient0", accounts.recipient0),
|
|
2076
|
+
getAccountMeta("recipient1", accounts.recipient1),
|
|
2077
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
2078
|
+
getAccountMeta("token1Program", accounts.token1Program)
|
|
2079
|
+
],
|
|
2080
|
+
data: getRedeemProtocolSharesInstructionDataEncoder().encode(
|
|
2081
|
+
args
|
|
2082
|
+
),
|
|
2083
|
+
programAddress
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
function getRedeemProtocolSharesInstruction(input, config) {
|
|
2087
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2088
|
+
const originalAccounts = {
|
|
2089
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
2090
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
2091
|
+
protocolFeePosition: {
|
|
2092
|
+
value: input.protocolFeePosition ?? null,
|
|
2093
|
+
isWritable: true
|
|
2094
|
+
},
|
|
2095
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
2096
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
2097
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
2098
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
2099
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
2100
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
2101
|
+
recipient0: { value: input.recipient0 ?? null, isWritable: true },
|
|
2102
|
+
recipient1: { value: input.recipient1 ?? null, isWritable: true },
|
|
2103
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
2104
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false }
|
|
2105
|
+
};
|
|
2106
|
+
const accounts = originalAccounts;
|
|
2107
|
+
const args = { ...input };
|
|
2108
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2109
|
+
return Object.freeze({
|
|
2110
|
+
accounts: [
|
|
2111
|
+
getAccountMeta("config", accounts.config),
|
|
2112
|
+
getAccountMeta("pool", accounts.pool),
|
|
2113
|
+
getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
|
|
2114
|
+
getAccountMeta("admin", accounts.admin),
|
|
2115
|
+
getAccountMeta("authority", accounts.authority),
|
|
2116
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
2117
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
2118
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
2119
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
2120
|
+
getAccountMeta("recipient0", accounts.recipient0),
|
|
2121
|
+
getAccountMeta("recipient1", accounts.recipient1),
|
|
2122
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
2123
|
+
getAccountMeta("token1Program", accounts.token1Program)
|
|
2124
|
+
],
|
|
2125
|
+
data: getRedeemProtocolSharesInstructionDataEncoder().encode(
|
|
2126
|
+
args
|
|
2127
|
+
),
|
|
2128
|
+
programAddress
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
function parseRedeemProtocolSharesInstruction(instruction) {
|
|
2132
|
+
if (instruction.accounts.length < 13) {
|
|
2133
|
+
throw new kit.SolanaError(
|
|
2134
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
2135
|
+
{
|
|
2136
|
+
actualAccountMetas: instruction.accounts.length,
|
|
2137
|
+
expectedAccountMetas: 13
|
|
2138
|
+
}
|
|
2139
|
+
);
|
|
2140
|
+
}
|
|
2141
|
+
let accountIndex = 0;
|
|
2142
|
+
const getNextAccount = () => {
|
|
2143
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
2144
|
+
accountIndex += 1;
|
|
2145
|
+
return accountMeta;
|
|
2146
|
+
};
|
|
2147
|
+
return {
|
|
2148
|
+
programAddress: instruction.programAddress,
|
|
2149
|
+
accounts: {
|
|
2150
|
+
config: getNextAccount(),
|
|
2151
|
+
pool: getNextAccount(),
|
|
2152
|
+
protocolFeePosition: getNextAccount(),
|
|
2153
|
+
admin: getNextAccount(),
|
|
2154
|
+
authority: getNextAccount(),
|
|
2155
|
+
vault0: getNextAccount(),
|
|
2156
|
+
vault1: getNextAccount(),
|
|
2157
|
+
token0Mint: getNextAccount(),
|
|
2158
|
+
token1Mint: getNextAccount(),
|
|
2159
|
+
recipient0: getNextAccount(),
|
|
2160
|
+
recipient1: getNextAccount(),
|
|
2161
|
+
token0Program: getNextAccount(),
|
|
2162
|
+
token1Program: getNextAccount()
|
|
2163
|
+
},
|
|
2164
|
+
data: getRedeemProtocolSharesInstructionDataDecoder().decode(
|
|
2165
|
+
instruction.data
|
|
2166
|
+
)
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
var REMOVE_LIQUIDITY_DISCRIMINATOR = new Uint8Array([
|
|
2170
|
+
80,
|
|
2171
|
+
85,
|
|
2172
|
+
209,
|
|
2173
|
+
72,
|
|
2174
|
+
24,
|
|
2175
|
+
206,
|
|
2176
|
+
177,
|
|
2177
|
+
108
|
|
2178
|
+
]);
|
|
2179
|
+
function getRemoveLiquidityDiscriminatorBytes() {
|
|
2180
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
2181
|
+
REMOVE_LIQUIDITY_DISCRIMINATOR
|
|
2182
|
+
);
|
|
2183
|
+
}
|
|
2184
|
+
function getRemoveLiquidityInstructionDataEncoder() {
|
|
2185
|
+
return kit.transformEncoder(
|
|
2186
|
+
kit.getStructEncoder([
|
|
2187
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
2188
|
+
["sharesIn", kit.getU128Encoder()],
|
|
2189
|
+
["minAmount0Out", kit.getU64Encoder()],
|
|
2190
|
+
["minAmount1Out", kit.getU64Encoder()],
|
|
2191
|
+
["updateOracle", kit.getBooleanEncoder()]
|
|
2192
|
+
]),
|
|
2193
|
+
(value) => ({ ...value, discriminator: REMOVE_LIQUIDITY_DISCRIMINATOR })
|
|
2194
|
+
);
|
|
2195
|
+
}
|
|
2196
|
+
function getRemoveLiquidityInstructionDataDecoder() {
|
|
2197
|
+
return kit.getStructDecoder([
|
|
2198
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
2199
|
+
["sharesIn", kit.getU128Decoder()],
|
|
2200
|
+
["minAmount0Out", kit.getU64Decoder()],
|
|
2201
|
+
["minAmount1Out", kit.getU64Decoder()],
|
|
2202
|
+
["updateOracle", kit.getBooleanDecoder()]
|
|
2203
|
+
]);
|
|
2204
|
+
}
|
|
2205
|
+
function getRemoveLiquidityInstructionDataCodec() {
|
|
2206
|
+
return kit.combineCodec(
|
|
2207
|
+
getRemoveLiquidityInstructionDataEncoder(),
|
|
2208
|
+
getRemoveLiquidityInstructionDataDecoder()
|
|
2209
|
+
);
|
|
2210
|
+
}
|
|
2211
|
+
async function getRemoveLiquidityInstructionAsync(input, config) {
|
|
2212
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2213
|
+
const originalAccounts = {
|
|
2214
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
2215
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
2216
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
2217
|
+
protocolFeePosition: {
|
|
2218
|
+
value: input.protocolFeePosition ?? null,
|
|
2219
|
+
isWritable: true
|
|
2220
|
+
},
|
|
2221
|
+
owner: { value: input.owner ?? null, isWritable: false },
|
|
2222
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
2223
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
2224
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
2225
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
2226
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
2227
|
+
user0: { value: input.user0 ?? null, isWritable: true },
|
|
2228
|
+
user1: { value: input.user1 ?? null, isWritable: true },
|
|
2229
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
2230
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false },
|
|
2231
|
+
oracle: { value: input.oracle ?? null, isWritable: true }
|
|
2232
|
+
};
|
|
2233
|
+
const accounts = originalAccounts;
|
|
2234
|
+
const args = { ...input };
|
|
2235
|
+
if (!accounts.authority.value) {
|
|
2236
|
+
accounts.authority.value = await kit.getProgramDerivedAddress({
|
|
2237
|
+
programAddress,
|
|
2238
|
+
seeds: [
|
|
2239
|
+
kit.getBytesEncoder().encode(
|
|
2240
|
+
new Uint8Array([97, 117, 116, 104, 111, 114, 105, 116, 121])
|
|
2241
|
+
),
|
|
2242
|
+
kit.getAddressEncoder().encode(
|
|
2243
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
2244
|
+
)
|
|
2245
|
+
]
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2249
|
+
return Object.freeze({
|
|
2250
|
+
accounts: [
|
|
2251
|
+
getAccountMeta("config", accounts.config),
|
|
2252
|
+
getAccountMeta("pool", accounts.pool),
|
|
2253
|
+
getAccountMeta("position", accounts.position),
|
|
2254
|
+
getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
|
|
2255
|
+
getAccountMeta("owner", accounts.owner),
|
|
2256
|
+
getAccountMeta("authority", accounts.authority),
|
|
2257
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
2258
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
2259
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
2260
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
2261
|
+
getAccountMeta("user0", accounts.user0),
|
|
2262
|
+
getAccountMeta("user1", accounts.user1),
|
|
2263
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
2264
|
+
getAccountMeta("token1Program", accounts.token1Program),
|
|
2265
|
+
getAccountMeta("oracle", accounts.oracle)
|
|
2266
|
+
],
|
|
2267
|
+
data: getRemoveLiquidityInstructionDataEncoder().encode(
|
|
2268
|
+
args
|
|
2269
|
+
),
|
|
2270
|
+
programAddress
|
|
2271
|
+
});
|
|
2272
|
+
}
|
|
2273
|
+
function getRemoveLiquidityInstruction(input, config) {
|
|
2274
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2275
|
+
const originalAccounts = {
|
|
2276
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
2277
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
2278
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
2279
|
+
protocolFeePosition: {
|
|
2280
|
+
value: input.protocolFeePosition ?? null,
|
|
2281
|
+
isWritable: true
|
|
2282
|
+
},
|
|
2283
|
+
owner: { value: input.owner ?? null, isWritable: false },
|
|
2284
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
2285
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
2286
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
2287
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
2288
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
2289
|
+
user0: { value: input.user0 ?? null, isWritable: true },
|
|
2290
|
+
user1: { value: input.user1 ?? null, isWritable: true },
|
|
2291
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
2292
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false },
|
|
2293
|
+
oracle: { value: input.oracle ?? null, isWritable: true }
|
|
2294
|
+
};
|
|
2295
|
+
const accounts = originalAccounts;
|
|
2296
|
+
const args = { ...input };
|
|
2297
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2298
|
+
return Object.freeze({
|
|
2299
|
+
accounts: [
|
|
2300
|
+
getAccountMeta("config", accounts.config),
|
|
2301
|
+
getAccountMeta("pool", accounts.pool),
|
|
2302
|
+
getAccountMeta("position", accounts.position),
|
|
2303
|
+
getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
|
|
2304
|
+
getAccountMeta("owner", accounts.owner),
|
|
2305
|
+
getAccountMeta("authority", accounts.authority),
|
|
2306
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
2307
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
2308
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
2309
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
2310
|
+
getAccountMeta("user0", accounts.user0),
|
|
2311
|
+
getAccountMeta("user1", accounts.user1),
|
|
2312
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
2313
|
+
getAccountMeta("token1Program", accounts.token1Program),
|
|
2314
|
+
getAccountMeta("oracle", accounts.oracle)
|
|
2315
|
+
],
|
|
2316
|
+
data: getRemoveLiquidityInstructionDataEncoder().encode(
|
|
2317
|
+
args
|
|
2318
|
+
),
|
|
2319
|
+
programAddress
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
function parseRemoveLiquidityInstruction(instruction) {
|
|
2323
|
+
if (instruction.accounts.length < 15) {
|
|
2324
|
+
throw new kit.SolanaError(
|
|
2325
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
2326
|
+
{
|
|
2327
|
+
actualAccountMetas: instruction.accounts.length,
|
|
2328
|
+
expectedAccountMetas: 15
|
|
2329
|
+
}
|
|
2330
|
+
);
|
|
2331
|
+
}
|
|
2332
|
+
let accountIndex = 0;
|
|
2333
|
+
const getNextAccount = () => {
|
|
2334
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
2335
|
+
accountIndex += 1;
|
|
2336
|
+
return accountMeta;
|
|
2337
|
+
};
|
|
2338
|
+
const getNextOptionalAccount = () => {
|
|
2339
|
+
const accountMeta = getNextAccount();
|
|
2340
|
+
return accountMeta.address === CPMM_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
2341
|
+
};
|
|
2342
|
+
return {
|
|
2343
|
+
programAddress: instruction.programAddress,
|
|
2344
|
+
accounts: {
|
|
2345
|
+
config: getNextAccount(),
|
|
2346
|
+
pool: getNextAccount(),
|
|
2347
|
+
position: getNextAccount(),
|
|
2348
|
+
protocolFeePosition: getNextAccount(),
|
|
2349
|
+
owner: getNextAccount(),
|
|
2350
|
+
authority: getNextAccount(),
|
|
2351
|
+
vault0: getNextAccount(),
|
|
2352
|
+
vault1: getNextAccount(),
|
|
2353
|
+
token0Mint: getNextAccount(),
|
|
2354
|
+
token1Mint: getNextAccount(),
|
|
2355
|
+
user0: getNextAccount(),
|
|
2356
|
+
user1: getNextAccount(),
|
|
2357
|
+
token0Program: getNextAccount(),
|
|
2358
|
+
token1Program: getNextAccount(),
|
|
2359
|
+
oracle: getNextOptionalAccount()
|
|
2360
|
+
},
|
|
2361
|
+
data: getRemoveLiquidityInstructionDataDecoder().decode(instruction.data)
|
|
2362
|
+
};
|
|
2363
|
+
}
|
|
2364
|
+
var SET_FEES_DISCRIMINATOR = new Uint8Array([
|
|
2365
|
+
137,
|
|
2366
|
+
178,
|
|
2367
|
+
49,
|
|
2368
|
+
58,
|
|
2369
|
+
0,
|
|
2370
|
+
245,
|
|
2371
|
+
242,
|
|
2372
|
+
190
|
|
2373
|
+
]);
|
|
2374
|
+
function getSetFeesDiscriminatorBytes() {
|
|
2375
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(SET_FEES_DISCRIMINATOR);
|
|
2376
|
+
}
|
|
2377
|
+
function getSetFeesInstructionDataEncoder() {
|
|
2378
|
+
return kit.transformEncoder(
|
|
2379
|
+
kit.getStructEncoder([
|
|
2380
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
2381
|
+
["swapFeeBps", kit.getU16Encoder()],
|
|
2382
|
+
["feeSplitBps", kit.getU16Encoder()]
|
|
2383
|
+
]),
|
|
2384
|
+
(value) => ({ ...value, discriminator: SET_FEES_DISCRIMINATOR })
|
|
2385
|
+
);
|
|
2386
|
+
}
|
|
2387
|
+
function getSetFeesInstructionDataDecoder() {
|
|
2388
|
+
return kit.getStructDecoder([
|
|
2389
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
2390
|
+
["swapFeeBps", kit.getU16Decoder()],
|
|
2391
|
+
["feeSplitBps", kit.getU16Decoder()]
|
|
2392
|
+
]);
|
|
2393
|
+
}
|
|
2394
|
+
function getSetFeesInstructionDataCodec() {
|
|
2395
|
+
return kit.combineCodec(
|
|
2396
|
+
getSetFeesInstructionDataEncoder(),
|
|
2397
|
+
getSetFeesInstructionDataDecoder()
|
|
2398
|
+
);
|
|
2399
|
+
}
|
|
2400
|
+
function getSetFeesInstruction(input, config) {
|
|
2401
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2402
|
+
const originalAccounts = {
|
|
2403
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
2404
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
2405
|
+
admin: { value: input.admin ?? null, isWritable: false }
|
|
2406
|
+
};
|
|
2407
|
+
const accounts = originalAccounts;
|
|
2408
|
+
const args = { ...input };
|
|
2409
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2410
|
+
return Object.freeze({
|
|
2411
|
+
accounts: [
|
|
2412
|
+
getAccountMeta("config", accounts.config),
|
|
2413
|
+
getAccountMeta("pool", accounts.pool),
|
|
2414
|
+
getAccountMeta("admin", accounts.admin)
|
|
2415
|
+
],
|
|
2416
|
+
data: getSetFeesInstructionDataEncoder().encode(
|
|
2417
|
+
args
|
|
2418
|
+
),
|
|
2419
|
+
programAddress
|
|
2420
|
+
});
|
|
2421
|
+
}
|
|
2422
|
+
function parseSetFeesInstruction(instruction) {
|
|
2423
|
+
if (instruction.accounts.length < 3) {
|
|
2424
|
+
throw new kit.SolanaError(
|
|
2425
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
2426
|
+
{
|
|
2427
|
+
actualAccountMetas: instruction.accounts.length,
|
|
2428
|
+
expectedAccountMetas: 3
|
|
2429
|
+
}
|
|
2430
|
+
);
|
|
2431
|
+
}
|
|
2432
|
+
let accountIndex = 0;
|
|
2433
|
+
const getNextAccount = () => {
|
|
2434
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
2435
|
+
accountIndex += 1;
|
|
2436
|
+
return accountMeta;
|
|
2437
|
+
};
|
|
2438
|
+
return {
|
|
2439
|
+
programAddress: instruction.programAddress,
|
|
2440
|
+
accounts: {
|
|
2441
|
+
config: getNextAccount(),
|
|
2442
|
+
pool: getNextAccount(),
|
|
2443
|
+
admin: getNextAccount()
|
|
2444
|
+
},
|
|
2445
|
+
data: getSetFeesInstructionDataDecoder().decode(instruction.data)
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
var SET_HOOK_DISCRIMINATOR = new Uint8Array([
|
|
2449
|
+
175,
|
|
2450
|
+
16,
|
|
2451
|
+
187,
|
|
2452
|
+
252,
|
|
2453
|
+
19,
|
|
2454
|
+
54,
|
|
2455
|
+
111,
|
|
2456
|
+
221
|
|
2457
|
+
]);
|
|
2458
|
+
function getSetHookDiscriminatorBytes() {
|
|
2459
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(SET_HOOK_DISCRIMINATOR);
|
|
2460
|
+
}
|
|
2461
|
+
function getSetHookInstructionDataEncoder() {
|
|
2462
|
+
return kit.transformEncoder(
|
|
2463
|
+
kit.getStructEncoder([
|
|
2464
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
2465
|
+
["hookProgram", kit.getAddressEncoder()],
|
|
2466
|
+
["hookFlags", kit.getU32Encoder()]
|
|
2467
|
+
]),
|
|
2468
|
+
(value) => ({ ...value, discriminator: SET_HOOK_DISCRIMINATOR })
|
|
2469
|
+
);
|
|
2470
|
+
}
|
|
2471
|
+
function getSetHookInstructionDataDecoder() {
|
|
2472
|
+
return kit.getStructDecoder([
|
|
2473
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
2474
|
+
["hookProgram", kit.getAddressDecoder()],
|
|
2475
|
+
["hookFlags", kit.getU32Decoder()]
|
|
2476
|
+
]);
|
|
2477
|
+
}
|
|
2478
|
+
function getSetHookInstructionDataCodec() {
|
|
2479
|
+
return kit.combineCodec(
|
|
2480
|
+
getSetHookInstructionDataEncoder(),
|
|
2481
|
+
getSetHookInstructionDataDecoder()
|
|
2482
|
+
);
|
|
2483
|
+
}
|
|
2484
|
+
function getSetHookInstruction(input, config) {
|
|
2485
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2486
|
+
const originalAccounts = {
|
|
2487
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
2488
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
2489
|
+
admin: { value: input.admin ?? null, isWritable: false }
|
|
2490
|
+
};
|
|
2491
|
+
const accounts = originalAccounts;
|
|
2492
|
+
const args = { ...input };
|
|
2493
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2494
|
+
return Object.freeze({
|
|
2495
|
+
accounts: [
|
|
2496
|
+
getAccountMeta("config", accounts.config),
|
|
2497
|
+
getAccountMeta("pool", accounts.pool),
|
|
2498
|
+
getAccountMeta("admin", accounts.admin)
|
|
2499
|
+
],
|
|
2500
|
+
data: getSetHookInstructionDataEncoder().encode(
|
|
2501
|
+
args
|
|
2502
|
+
),
|
|
2503
|
+
programAddress
|
|
2504
|
+
});
|
|
2505
|
+
}
|
|
2506
|
+
function parseSetHookInstruction(instruction) {
|
|
2507
|
+
if (instruction.accounts.length < 3) {
|
|
2508
|
+
throw new kit.SolanaError(
|
|
2509
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
2510
|
+
{
|
|
2511
|
+
actualAccountMetas: instruction.accounts.length,
|
|
2512
|
+
expectedAccountMetas: 3
|
|
2513
|
+
}
|
|
2514
|
+
);
|
|
2515
|
+
}
|
|
2516
|
+
let accountIndex = 0;
|
|
2517
|
+
const getNextAccount = () => {
|
|
2518
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
2519
|
+
accountIndex += 1;
|
|
2520
|
+
return accountMeta;
|
|
2521
|
+
};
|
|
2522
|
+
return {
|
|
2523
|
+
programAddress: instruction.programAddress,
|
|
2524
|
+
accounts: {
|
|
2525
|
+
config: getNextAccount(),
|
|
2526
|
+
pool: getNextAccount(),
|
|
2527
|
+
admin: getNextAccount()
|
|
2528
|
+
},
|
|
2529
|
+
data: getSetHookInstructionDataDecoder().decode(instruction.data)
|
|
2530
|
+
};
|
|
2531
|
+
}
|
|
2532
|
+
var SWAP_EXACT_IN_DISCRIMINATOR = new Uint8Array([
|
|
2533
|
+
104,
|
|
2534
|
+
104,
|
|
2535
|
+
131,
|
|
2536
|
+
86,
|
|
2537
|
+
161,
|
|
2538
|
+
189,
|
|
2539
|
+
180,
|
|
2540
|
+
216
|
|
2541
|
+
]);
|
|
2542
|
+
function getSwapExactInDiscriminatorBytes() {
|
|
2543
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
2544
|
+
SWAP_EXACT_IN_DISCRIMINATOR
|
|
2545
|
+
);
|
|
2546
|
+
}
|
|
2547
|
+
function getSwapExactInInstructionDataEncoder() {
|
|
2548
|
+
return kit.transformEncoder(
|
|
2549
|
+
kit.getStructEncoder([
|
|
2550
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
2551
|
+
["amountIn", kit.getU64Encoder()],
|
|
2552
|
+
["minAmountOut", kit.getU64Encoder()],
|
|
2553
|
+
["tradeDirection", kit.getU8Encoder()],
|
|
2554
|
+
["updateOracle", kit.getBooleanEncoder()]
|
|
2555
|
+
]),
|
|
2556
|
+
(value) => ({ ...value, discriminator: SWAP_EXACT_IN_DISCRIMINATOR })
|
|
2557
|
+
);
|
|
2558
|
+
}
|
|
2559
|
+
function getSwapExactInInstructionDataDecoder() {
|
|
2560
|
+
return kit.getStructDecoder([
|
|
2561
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
2562
|
+
["amountIn", kit.getU64Decoder()],
|
|
2563
|
+
["minAmountOut", kit.getU64Decoder()],
|
|
2564
|
+
["tradeDirection", kit.getU8Decoder()],
|
|
2565
|
+
["updateOracle", kit.getBooleanDecoder()]
|
|
2566
|
+
]);
|
|
2567
|
+
}
|
|
2568
|
+
function getSwapExactInInstructionDataCodec() {
|
|
2569
|
+
return kit.combineCodec(
|
|
2570
|
+
getSwapExactInInstructionDataEncoder(),
|
|
2571
|
+
getSwapExactInInstructionDataDecoder()
|
|
2572
|
+
);
|
|
2573
|
+
}
|
|
2574
|
+
async function getSwapExactInInstructionAsync(input, config) {
|
|
2575
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2576
|
+
const originalAccounts = {
|
|
2577
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
2578
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
2579
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
2580
|
+
vaultIn: { value: input.vaultIn ?? null, isWritable: true },
|
|
2581
|
+
vaultOut: { value: input.vaultOut ?? null, isWritable: true },
|
|
2582
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
2583
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
2584
|
+
userIn: { value: input.userIn ?? null, isWritable: true },
|
|
2585
|
+
userOut: { value: input.userOut ?? null, isWritable: true },
|
|
2586
|
+
trader: { value: input.trader ?? null, isWritable: false },
|
|
2587
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
2588
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false },
|
|
2589
|
+
oracle: { value: input.oracle ?? null, isWritable: true }
|
|
2590
|
+
};
|
|
2591
|
+
const accounts = originalAccounts;
|
|
2592
|
+
const args = { ...input };
|
|
2593
|
+
if (!accounts.authority.value) {
|
|
2594
|
+
accounts.authority.value = await kit.getProgramDerivedAddress({
|
|
2595
|
+
programAddress,
|
|
2596
|
+
seeds: [
|
|
2597
|
+
kit.getBytesEncoder().encode(
|
|
2598
|
+
new Uint8Array([97, 117, 116, 104, 111, 114, 105, 116, 121])
|
|
2599
|
+
),
|
|
2600
|
+
kit.getAddressEncoder().encode(
|
|
2601
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
2602
|
+
)
|
|
2603
|
+
]
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2606
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2607
|
+
return Object.freeze({
|
|
2608
|
+
accounts: [
|
|
2609
|
+
getAccountMeta("config", accounts.config),
|
|
2610
|
+
getAccountMeta("pool", accounts.pool),
|
|
2611
|
+
getAccountMeta("authority", accounts.authority),
|
|
2612
|
+
getAccountMeta("vaultIn", accounts.vaultIn),
|
|
2613
|
+
getAccountMeta("vaultOut", accounts.vaultOut),
|
|
2614
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
2615
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
2616
|
+
getAccountMeta("userIn", accounts.userIn),
|
|
2617
|
+
getAccountMeta("userOut", accounts.userOut),
|
|
2618
|
+
getAccountMeta("trader", accounts.trader),
|
|
2619
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
2620
|
+
getAccountMeta("token1Program", accounts.token1Program),
|
|
2621
|
+
getAccountMeta("oracle", accounts.oracle)
|
|
2622
|
+
],
|
|
2623
|
+
data: getSwapExactInInstructionDataEncoder().encode(
|
|
2624
|
+
args
|
|
2625
|
+
),
|
|
2626
|
+
programAddress
|
|
2627
|
+
});
|
|
2628
|
+
}
|
|
2629
|
+
function getSwapExactInInstruction(input, config) {
|
|
2630
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2631
|
+
const originalAccounts = {
|
|
2632
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
2633
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
2634
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
2635
|
+
vaultIn: { value: input.vaultIn ?? null, isWritable: true },
|
|
2636
|
+
vaultOut: { value: input.vaultOut ?? null, isWritable: true },
|
|
2637
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
2638
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
2639
|
+
userIn: { value: input.userIn ?? null, isWritable: true },
|
|
2640
|
+
userOut: { value: input.userOut ?? null, isWritable: true },
|
|
2641
|
+
trader: { value: input.trader ?? null, isWritable: false },
|
|
2642
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
2643
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false },
|
|
2644
|
+
oracle: { value: input.oracle ?? null, isWritable: true }
|
|
2645
|
+
};
|
|
2646
|
+
const accounts = originalAccounts;
|
|
2647
|
+
const args = { ...input };
|
|
2648
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2649
|
+
return Object.freeze({
|
|
2650
|
+
accounts: [
|
|
2651
|
+
getAccountMeta("config", accounts.config),
|
|
2652
|
+
getAccountMeta("pool", accounts.pool),
|
|
2653
|
+
getAccountMeta("authority", accounts.authority),
|
|
2654
|
+
getAccountMeta("vaultIn", accounts.vaultIn),
|
|
2655
|
+
getAccountMeta("vaultOut", accounts.vaultOut),
|
|
2656
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
2657
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
2658
|
+
getAccountMeta("userIn", accounts.userIn),
|
|
2659
|
+
getAccountMeta("userOut", accounts.userOut),
|
|
2660
|
+
getAccountMeta("trader", accounts.trader),
|
|
2661
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
2662
|
+
getAccountMeta("token1Program", accounts.token1Program),
|
|
2663
|
+
getAccountMeta("oracle", accounts.oracle)
|
|
2664
|
+
],
|
|
2665
|
+
data: getSwapExactInInstructionDataEncoder().encode(
|
|
2666
|
+
args
|
|
2667
|
+
),
|
|
2668
|
+
programAddress
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
function parseSwapExactInInstruction(instruction) {
|
|
2672
|
+
if (instruction.accounts.length < 13) {
|
|
2673
|
+
throw new kit.SolanaError(
|
|
2674
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
2675
|
+
{
|
|
2676
|
+
actualAccountMetas: instruction.accounts.length,
|
|
2677
|
+
expectedAccountMetas: 13
|
|
2678
|
+
}
|
|
2679
|
+
);
|
|
2680
|
+
}
|
|
2681
|
+
let accountIndex = 0;
|
|
2682
|
+
const getNextAccount = () => {
|
|
2683
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
2684
|
+
accountIndex += 1;
|
|
2685
|
+
return accountMeta;
|
|
2686
|
+
};
|
|
2687
|
+
const getNextOptionalAccount = () => {
|
|
2688
|
+
const accountMeta = getNextAccount();
|
|
2689
|
+
return accountMeta.address === CPMM_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
2690
|
+
};
|
|
2691
|
+
return {
|
|
2692
|
+
programAddress: instruction.programAddress,
|
|
2693
|
+
accounts: {
|
|
2694
|
+
config: getNextAccount(),
|
|
2695
|
+
pool: getNextAccount(),
|
|
2696
|
+
authority: getNextAccount(),
|
|
2697
|
+
vaultIn: getNextAccount(),
|
|
2698
|
+
vaultOut: getNextAccount(),
|
|
2699
|
+
token0Mint: getNextAccount(),
|
|
2700
|
+
token1Mint: getNextAccount(),
|
|
2701
|
+
userIn: getNextAccount(),
|
|
2702
|
+
userOut: getNextAccount(),
|
|
2703
|
+
trader: getNextAccount(),
|
|
2704
|
+
token0Program: getNextAccount(),
|
|
2705
|
+
token1Program: getNextAccount(),
|
|
2706
|
+
oracle: getNextOptionalAccount()
|
|
2707
|
+
},
|
|
2708
|
+
data: getSwapExactInInstructionDataDecoder().decode(instruction.data)
|
|
2709
|
+
};
|
|
2710
|
+
}
|
|
2711
|
+
var TRANSFER_ADMIN_DISCRIMINATOR = new Uint8Array([
|
|
2712
|
+
42,
|
|
2713
|
+
242,
|
|
2714
|
+
66,
|
|
2715
|
+
106,
|
|
2716
|
+
228,
|
|
2717
|
+
10,
|
|
2718
|
+
111,
|
|
2719
|
+
156
|
|
2720
|
+
]);
|
|
2721
|
+
function getTransferAdminDiscriminatorBytes() {
|
|
2722
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
2723
|
+
TRANSFER_ADMIN_DISCRIMINATOR
|
|
2724
|
+
);
|
|
2725
|
+
}
|
|
2726
|
+
function getTransferAdminInstructionDataEncoder() {
|
|
2727
|
+
return kit.transformEncoder(
|
|
2728
|
+
kit.getStructEncoder([
|
|
2729
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
2730
|
+
["newAdmin", kit.getAddressEncoder()]
|
|
2731
|
+
]),
|
|
2732
|
+
(value) => ({ ...value, discriminator: TRANSFER_ADMIN_DISCRIMINATOR })
|
|
2733
|
+
);
|
|
2734
|
+
}
|
|
2735
|
+
function getTransferAdminInstructionDataDecoder() {
|
|
2736
|
+
return kit.getStructDecoder([
|
|
2737
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
2738
|
+
["newAdmin", kit.getAddressDecoder()]
|
|
2739
|
+
]);
|
|
2740
|
+
}
|
|
2741
|
+
function getTransferAdminInstructionDataCodec() {
|
|
2742
|
+
return kit.combineCodec(
|
|
2743
|
+
getTransferAdminInstructionDataEncoder(),
|
|
2744
|
+
getTransferAdminInstructionDataDecoder()
|
|
2745
|
+
);
|
|
2746
|
+
}
|
|
2747
|
+
function getTransferAdminInstruction(input, config) {
|
|
2748
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2749
|
+
const originalAccounts = {
|
|
2750
|
+
config: { value: input.config ?? null, isWritable: true },
|
|
2751
|
+
admin: { value: input.admin ?? null, isWritable: false }
|
|
2752
|
+
};
|
|
2753
|
+
const accounts = originalAccounts;
|
|
2754
|
+
const args = { ...input };
|
|
2755
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2756
|
+
return Object.freeze({
|
|
2757
|
+
accounts: [
|
|
2758
|
+
getAccountMeta("config", accounts.config),
|
|
2759
|
+
getAccountMeta("admin", accounts.admin)
|
|
2760
|
+
],
|
|
2761
|
+
data: getTransferAdminInstructionDataEncoder().encode(
|
|
2762
|
+
args
|
|
2763
|
+
),
|
|
2764
|
+
programAddress
|
|
2765
|
+
});
|
|
2766
|
+
}
|
|
2767
|
+
function parseTransferAdminInstruction(instruction) {
|
|
2768
|
+
if (instruction.accounts.length < 2) {
|
|
2769
|
+
throw new kit.SolanaError(
|
|
2770
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
2771
|
+
{
|
|
2772
|
+
actualAccountMetas: instruction.accounts.length,
|
|
2773
|
+
expectedAccountMetas: 2
|
|
2774
|
+
}
|
|
2775
|
+
);
|
|
2776
|
+
}
|
|
2777
|
+
let accountIndex = 0;
|
|
2778
|
+
const getNextAccount = () => {
|
|
2779
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
2780
|
+
accountIndex += 1;
|
|
2781
|
+
return accountMeta;
|
|
2782
|
+
};
|
|
2783
|
+
return {
|
|
2784
|
+
programAddress: instruction.programAddress,
|
|
2785
|
+
accounts: { config: getNextAccount(), admin: getNextAccount() },
|
|
2786
|
+
data: getTransferAdminInstructionDataDecoder().decode(instruction.data)
|
|
2787
|
+
};
|
|
2788
|
+
}
|
|
2789
|
+
var UNPAUSE_DISCRIMINATOR = new Uint8Array([
|
|
2790
|
+
169,
|
|
2791
|
+
144,
|
|
2792
|
+
4,
|
|
2793
|
+
38,
|
|
2794
|
+
10,
|
|
2795
|
+
141,
|
|
2796
|
+
188,
|
|
2797
|
+
255
|
|
2798
|
+
]);
|
|
2799
|
+
function getUnpauseDiscriminatorBytes() {
|
|
2800
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(UNPAUSE_DISCRIMINATOR);
|
|
2801
|
+
}
|
|
2802
|
+
function getUnpauseInstructionDataEncoder() {
|
|
2803
|
+
return kit.transformEncoder(
|
|
2804
|
+
kit.getStructEncoder([["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)]]),
|
|
2805
|
+
(value) => ({ ...value, discriminator: UNPAUSE_DISCRIMINATOR })
|
|
2806
|
+
);
|
|
2807
|
+
}
|
|
2808
|
+
function getUnpauseInstructionDataDecoder() {
|
|
2809
|
+
return kit.getStructDecoder([
|
|
2810
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)]
|
|
2811
|
+
]);
|
|
2812
|
+
}
|
|
2813
|
+
function getUnpauseInstructionDataCodec() {
|
|
2814
|
+
return kit.combineCodec(
|
|
2815
|
+
getUnpauseInstructionDataEncoder(),
|
|
2816
|
+
getUnpauseInstructionDataDecoder()
|
|
2817
|
+
);
|
|
2818
|
+
}
|
|
2819
|
+
function getUnpauseInstruction(input, config) {
|
|
2820
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2821
|
+
const originalAccounts = {
|
|
2822
|
+
config: { value: input.config ?? null, isWritable: true },
|
|
2823
|
+
admin: { value: input.admin ?? null, isWritable: false }
|
|
2824
|
+
};
|
|
2825
|
+
const accounts = originalAccounts;
|
|
2826
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2827
|
+
return Object.freeze({
|
|
2828
|
+
accounts: [
|
|
2829
|
+
getAccountMeta("config", accounts.config),
|
|
2830
|
+
getAccountMeta("admin", accounts.admin)
|
|
2831
|
+
],
|
|
2832
|
+
data: getUnpauseInstructionDataEncoder().encode({}),
|
|
2833
|
+
programAddress
|
|
2834
|
+
});
|
|
2835
|
+
}
|
|
2836
|
+
function parseUnpauseInstruction(instruction) {
|
|
2837
|
+
if (instruction.accounts.length < 2) {
|
|
2838
|
+
throw new kit.SolanaError(
|
|
2839
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
2840
|
+
{
|
|
2841
|
+
actualAccountMetas: instruction.accounts.length,
|
|
2842
|
+
expectedAccountMetas: 2
|
|
2843
|
+
}
|
|
2844
|
+
);
|
|
2845
|
+
}
|
|
2846
|
+
let accountIndex = 0;
|
|
2847
|
+
const getNextAccount = () => {
|
|
2848
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
2849
|
+
accountIndex += 1;
|
|
2850
|
+
return accountMeta;
|
|
2851
|
+
};
|
|
2852
|
+
return {
|
|
2853
|
+
programAddress: instruction.programAddress,
|
|
2854
|
+
accounts: { config: getNextAccount(), admin: getNextAccount() },
|
|
2855
|
+
data: getUnpauseInstructionDataDecoder().decode(instruction.data)
|
|
2856
|
+
};
|
|
2857
|
+
}
|
|
2858
|
+
var UPDATE_CONFIG_DISCRIMINATOR = new Uint8Array([
|
|
2859
|
+
29,
|
|
2860
|
+
158,
|
|
2861
|
+
252,
|
|
2862
|
+
191,
|
|
2863
|
+
10,
|
|
2864
|
+
83,
|
|
2865
|
+
219,
|
|
2866
|
+
99
|
|
2867
|
+
]);
|
|
2868
|
+
function getUpdateConfigDiscriminatorBytes() {
|
|
2869
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
2870
|
+
UPDATE_CONFIG_DISCRIMINATOR
|
|
2871
|
+
);
|
|
2872
|
+
}
|
|
2873
|
+
function getUpdateConfigInstructionDataEncoder() {
|
|
2874
|
+
return kit.transformEncoder(
|
|
2875
|
+
kit.getStructEncoder([
|
|
2876
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
2877
|
+
["maxSwapFeeBps", kit.getU16Encoder()],
|
|
2878
|
+
["maxFeeSplitBps", kit.getU16Encoder()],
|
|
2879
|
+
["protocolFeeEnabled", kit.getBooleanEncoder()],
|
|
2880
|
+
["protocolFeeBps", kit.getU16Encoder()],
|
|
2881
|
+
["hookAllowlist", kit.getArrayEncoder(kit.getAddressEncoder())]
|
|
2882
|
+
]),
|
|
2883
|
+
(value) => ({ ...value, discriminator: UPDATE_CONFIG_DISCRIMINATOR })
|
|
2884
|
+
);
|
|
2885
|
+
}
|
|
2886
|
+
function getUpdateConfigInstructionDataDecoder() {
|
|
2887
|
+
return kit.getStructDecoder([
|
|
2888
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
2889
|
+
["maxSwapFeeBps", kit.getU16Decoder()],
|
|
2890
|
+
["maxFeeSplitBps", kit.getU16Decoder()],
|
|
2891
|
+
["protocolFeeEnabled", kit.getBooleanDecoder()],
|
|
2892
|
+
["protocolFeeBps", kit.getU16Decoder()],
|
|
2893
|
+
["hookAllowlist", kit.getArrayDecoder(kit.getAddressDecoder())]
|
|
2894
|
+
]);
|
|
2895
|
+
}
|
|
2896
|
+
function getUpdateConfigInstructionDataCodec() {
|
|
2897
|
+
return kit.combineCodec(
|
|
2898
|
+
getUpdateConfigInstructionDataEncoder(),
|
|
2899
|
+
getUpdateConfigInstructionDataDecoder()
|
|
2900
|
+
);
|
|
2901
|
+
}
|
|
2902
|
+
function getUpdateConfigInstruction(input, config) {
|
|
2903
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2904
|
+
const originalAccounts = {
|
|
2905
|
+
config: { value: input.config ?? null, isWritable: true },
|
|
2906
|
+
admin: { value: input.admin ?? null, isWritable: false }
|
|
2907
|
+
};
|
|
2908
|
+
const accounts = originalAccounts;
|
|
2909
|
+
const args = { ...input };
|
|
2910
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
2911
|
+
return Object.freeze({
|
|
2912
|
+
accounts: [
|
|
2913
|
+
getAccountMeta("config", accounts.config),
|
|
2914
|
+
getAccountMeta("admin", accounts.admin)
|
|
2915
|
+
],
|
|
2916
|
+
data: getUpdateConfigInstructionDataEncoder().encode(
|
|
2917
|
+
args
|
|
2918
|
+
),
|
|
2919
|
+
programAddress
|
|
2920
|
+
});
|
|
2921
|
+
}
|
|
2922
|
+
function parseUpdateConfigInstruction(instruction) {
|
|
2923
|
+
if (instruction.accounts.length < 2) {
|
|
2924
|
+
throw new kit.SolanaError(
|
|
2925
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
2926
|
+
{
|
|
2927
|
+
actualAccountMetas: instruction.accounts.length,
|
|
2928
|
+
expectedAccountMetas: 2
|
|
2929
|
+
}
|
|
2930
|
+
);
|
|
2931
|
+
}
|
|
2932
|
+
let accountIndex = 0;
|
|
2933
|
+
const getNextAccount = () => {
|
|
2934
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
2935
|
+
accountIndex += 1;
|
|
2936
|
+
return accountMeta;
|
|
2937
|
+
};
|
|
2938
|
+
return {
|
|
2939
|
+
programAddress: instruction.programAddress,
|
|
2940
|
+
accounts: { config: getNextAccount(), admin: getNextAccount() },
|
|
2941
|
+
data: getUpdateConfigInstructionDataDecoder().decode(instruction.data)
|
|
2942
|
+
};
|
|
2943
|
+
}
|
|
2944
|
+
var WITHDRAW_VAULT_EXCESS_DISCRIMINATOR = new Uint8Array([
|
|
2945
|
+
235,
|
|
2946
|
+
197,
|
|
2947
|
+
247,
|
|
2948
|
+
177,
|
|
2949
|
+
137,
|
|
2950
|
+
72,
|
|
2951
|
+
135,
|
|
2952
|
+
113
|
|
2953
|
+
]);
|
|
2954
|
+
function getWithdrawVaultExcessDiscriminatorBytes() {
|
|
2955
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
2956
|
+
WITHDRAW_VAULT_EXCESS_DISCRIMINATOR
|
|
2957
|
+
);
|
|
2958
|
+
}
|
|
2959
|
+
function getWithdrawVaultExcessInstructionDataEncoder() {
|
|
2960
|
+
return kit.transformEncoder(
|
|
2961
|
+
kit.getStructEncoder([["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)]]),
|
|
2962
|
+
(value) => ({
|
|
2963
|
+
...value,
|
|
2964
|
+
discriminator: WITHDRAW_VAULT_EXCESS_DISCRIMINATOR
|
|
2965
|
+
})
|
|
2966
|
+
);
|
|
2967
|
+
}
|
|
2968
|
+
function getWithdrawVaultExcessInstructionDataDecoder() {
|
|
2969
|
+
return kit.getStructDecoder([
|
|
2970
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)]
|
|
2971
|
+
]);
|
|
2972
|
+
}
|
|
2973
|
+
function getWithdrawVaultExcessInstructionDataCodec() {
|
|
2974
|
+
return kit.combineCodec(
|
|
2975
|
+
getWithdrawVaultExcessInstructionDataEncoder(),
|
|
2976
|
+
getWithdrawVaultExcessInstructionDataDecoder()
|
|
2977
|
+
);
|
|
2978
|
+
}
|
|
2979
|
+
async function getWithdrawVaultExcessInstructionAsync(input, config) {
|
|
2980
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
2981
|
+
const originalAccounts = {
|
|
2982
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
2983
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
2984
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
2985
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
2986
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
2987
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
2988
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
2989
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
2990
|
+
adminAta0: { value: input.adminAta0 ?? null, isWritable: true },
|
|
2991
|
+
adminAta1: { value: input.adminAta1 ?? null, isWritable: true },
|
|
2992
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
2993
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false }
|
|
2994
|
+
};
|
|
2995
|
+
const accounts = originalAccounts;
|
|
2996
|
+
if (!accounts.authority.value) {
|
|
2997
|
+
accounts.authority.value = await kit.getProgramDerivedAddress({
|
|
2998
|
+
programAddress,
|
|
2999
|
+
seeds: [
|
|
3000
|
+
kit.getBytesEncoder().encode(
|
|
3001
|
+
new Uint8Array([97, 117, 116, 104, 111, 114, 105, 116, 121])
|
|
3002
|
+
),
|
|
3003
|
+
kit.getAddressEncoder().encode(
|
|
3004
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
3005
|
+
)
|
|
3006
|
+
]
|
|
3007
|
+
});
|
|
3008
|
+
}
|
|
3009
|
+
if (!accounts.adminAta0.value) {
|
|
3010
|
+
accounts.adminAta0.value = await kit.getProgramDerivedAddress({
|
|
3011
|
+
programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
|
|
3012
|
+
seeds: [
|
|
3013
|
+
kit.getAddressEncoder().encode(
|
|
3014
|
+
programClientCore.getAddressFromResolvedInstructionAccount(
|
|
3015
|
+
"admin",
|
|
3016
|
+
accounts.admin.value
|
|
3017
|
+
)
|
|
3018
|
+
),
|
|
3019
|
+
kit.getAddressEncoder().encode(
|
|
3020
|
+
programClientCore.getAddressFromResolvedInstructionAccount(
|
|
3021
|
+
"token0Program",
|
|
3022
|
+
accounts.token0Program.value
|
|
3023
|
+
)
|
|
3024
|
+
),
|
|
3025
|
+
kit.getAddressEncoder().encode(
|
|
3026
|
+
programClientCore.getAddressFromResolvedInstructionAccount(
|
|
3027
|
+
"token0Mint",
|
|
3028
|
+
accounts.token0Mint.value
|
|
3029
|
+
)
|
|
3030
|
+
)
|
|
3031
|
+
]
|
|
3032
|
+
});
|
|
3033
|
+
}
|
|
3034
|
+
if (!accounts.adminAta1.value) {
|
|
3035
|
+
accounts.adminAta1.value = await kit.getProgramDerivedAddress({
|
|
3036
|
+
programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
|
|
3037
|
+
seeds: [
|
|
3038
|
+
kit.getAddressEncoder().encode(
|
|
3039
|
+
programClientCore.getAddressFromResolvedInstructionAccount(
|
|
3040
|
+
"admin",
|
|
3041
|
+
accounts.admin.value
|
|
3042
|
+
)
|
|
3043
|
+
),
|
|
3044
|
+
kit.getAddressEncoder().encode(
|
|
3045
|
+
programClientCore.getAddressFromResolvedInstructionAccount(
|
|
3046
|
+
"token1Program",
|
|
3047
|
+
accounts.token1Program.value
|
|
3048
|
+
)
|
|
3049
|
+
),
|
|
3050
|
+
kit.getAddressEncoder().encode(
|
|
3051
|
+
programClientCore.getAddressFromResolvedInstructionAccount(
|
|
3052
|
+
"token1Mint",
|
|
3053
|
+
accounts.token1Mint.value
|
|
3054
|
+
)
|
|
3055
|
+
)
|
|
3056
|
+
]
|
|
3057
|
+
});
|
|
3058
|
+
}
|
|
3059
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
3060
|
+
return Object.freeze({
|
|
3061
|
+
accounts: [
|
|
3062
|
+
getAccountMeta("config", accounts.config),
|
|
3063
|
+
getAccountMeta("pool", accounts.pool),
|
|
3064
|
+
getAccountMeta("admin", accounts.admin),
|
|
3065
|
+
getAccountMeta("authority", accounts.authority),
|
|
3066
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
3067
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
3068
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
3069
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
3070
|
+
getAccountMeta("adminAta0", accounts.adminAta0),
|
|
3071
|
+
getAccountMeta("adminAta1", accounts.adminAta1),
|
|
3072
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
3073
|
+
getAccountMeta("token1Program", accounts.token1Program)
|
|
3074
|
+
],
|
|
3075
|
+
data: getWithdrawVaultExcessInstructionDataEncoder().encode({}),
|
|
3076
|
+
programAddress
|
|
3077
|
+
});
|
|
3078
|
+
}
|
|
3079
|
+
function getWithdrawVaultExcessInstruction(input, config) {
|
|
3080
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
3081
|
+
const originalAccounts = {
|
|
3082
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
3083
|
+
pool: { value: input.pool ?? null, isWritable: false },
|
|
3084
|
+
admin: { value: input.admin ?? null, isWritable: false },
|
|
3085
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
3086
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
3087
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
3088
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
3089
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
3090
|
+
adminAta0: { value: input.adminAta0 ?? null, isWritable: true },
|
|
3091
|
+
adminAta1: { value: input.adminAta1 ?? null, isWritable: true },
|
|
3092
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
3093
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false }
|
|
3094
|
+
};
|
|
3095
|
+
const accounts = originalAccounts;
|
|
3096
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
3097
|
+
return Object.freeze({
|
|
3098
|
+
accounts: [
|
|
3099
|
+
getAccountMeta("config", accounts.config),
|
|
3100
|
+
getAccountMeta("pool", accounts.pool),
|
|
3101
|
+
getAccountMeta("admin", accounts.admin),
|
|
3102
|
+
getAccountMeta("authority", accounts.authority),
|
|
3103
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
3104
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
3105
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
3106
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
3107
|
+
getAccountMeta("adminAta0", accounts.adminAta0),
|
|
3108
|
+
getAccountMeta("adminAta1", accounts.adminAta1),
|
|
3109
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
3110
|
+
getAccountMeta("token1Program", accounts.token1Program)
|
|
3111
|
+
],
|
|
3112
|
+
data: getWithdrawVaultExcessInstructionDataEncoder().encode({}),
|
|
3113
|
+
programAddress
|
|
3114
|
+
});
|
|
3115
|
+
}
|
|
3116
|
+
function parseWithdrawVaultExcessInstruction(instruction) {
|
|
3117
|
+
if (instruction.accounts.length < 12) {
|
|
3118
|
+
throw new kit.SolanaError(
|
|
3119
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
3120
|
+
{
|
|
3121
|
+
actualAccountMetas: instruction.accounts.length,
|
|
3122
|
+
expectedAccountMetas: 12
|
|
3123
|
+
}
|
|
3124
|
+
);
|
|
3125
|
+
}
|
|
3126
|
+
let accountIndex = 0;
|
|
3127
|
+
const getNextAccount = () => {
|
|
3128
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
3129
|
+
accountIndex += 1;
|
|
3130
|
+
return accountMeta;
|
|
3131
|
+
};
|
|
3132
|
+
return {
|
|
3133
|
+
programAddress: instruction.programAddress,
|
|
3134
|
+
accounts: {
|
|
3135
|
+
config: getNextAccount(),
|
|
3136
|
+
pool: getNextAccount(),
|
|
3137
|
+
admin: getNextAccount(),
|
|
3138
|
+
authority: getNextAccount(),
|
|
3139
|
+
vault0: getNextAccount(),
|
|
3140
|
+
vault1: getNextAccount(),
|
|
3141
|
+
token0Mint: getNextAccount(),
|
|
3142
|
+
token1Mint: getNextAccount(),
|
|
3143
|
+
adminAta0: getNextAccount(),
|
|
3144
|
+
adminAta1: getNextAccount(),
|
|
3145
|
+
token0Program: getNextAccount(),
|
|
3146
|
+
token1Program: getNextAccount()
|
|
3147
|
+
},
|
|
3148
|
+
data: getWithdrawVaultExcessInstructionDataDecoder().decode(
|
|
3149
|
+
instruction.data
|
|
3150
|
+
)
|
|
3151
|
+
};
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
// src/solana/generated/cpmm/programs/cpmm.ts
|
|
3155
|
+
var CPMM_PROGRAM_ADDRESS = "9PSxVPoPfnbZ8Q1uQhgS6ZxvBjFboZtebNsu34umxkgQ";
|
|
3156
|
+
|
|
3157
|
+
// src/solana/generated/cpmm/instructions/addLiquidity.ts
|
|
3158
|
+
var ADD_LIQUIDITY_DISCRIMINATOR = new Uint8Array([
|
|
3159
|
+
181,
|
|
3160
|
+
157,
|
|
3161
|
+
89,
|
|
3162
|
+
67,
|
|
3163
|
+
143,
|
|
3164
|
+
182,
|
|
3165
|
+
52,
|
|
3166
|
+
72
|
|
3167
|
+
]);
|
|
3168
|
+
function getAddLiquidityDiscriminatorBytes() {
|
|
3169
|
+
return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
|
|
3170
|
+
ADD_LIQUIDITY_DISCRIMINATOR
|
|
3171
|
+
);
|
|
3172
|
+
}
|
|
3173
|
+
function getAddLiquidityInstructionDataEncoder() {
|
|
3174
|
+
return kit.transformEncoder(
|
|
3175
|
+
kit.getStructEncoder([
|
|
3176
|
+
["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
|
|
3177
|
+
["amount0Max", kit.getU64Encoder()],
|
|
3178
|
+
["amount1Max", kit.getU64Encoder()],
|
|
3179
|
+
["minSharesOut", kit.getU128Encoder()],
|
|
3180
|
+
["updateOracle", kit.getBooleanEncoder()]
|
|
3181
|
+
]),
|
|
3182
|
+
(value) => ({ ...value, discriminator: ADD_LIQUIDITY_DISCRIMINATOR })
|
|
3183
|
+
);
|
|
3184
|
+
}
|
|
3185
|
+
function getAddLiquidityInstructionDataDecoder() {
|
|
3186
|
+
return kit.getStructDecoder([
|
|
3187
|
+
["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
|
|
3188
|
+
["amount0Max", kit.getU64Decoder()],
|
|
3189
|
+
["amount1Max", kit.getU64Decoder()],
|
|
3190
|
+
["minSharesOut", kit.getU128Decoder()],
|
|
3191
|
+
["updateOracle", kit.getBooleanDecoder()]
|
|
3192
|
+
]);
|
|
3193
|
+
}
|
|
3194
|
+
function getAddLiquidityInstructionDataCodec() {
|
|
3195
|
+
return kit.combineCodec(
|
|
3196
|
+
getAddLiquidityInstructionDataEncoder(),
|
|
3197
|
+
getAddLiquidityInstructionDataDecoder()
|
|
3198
|
+
);
|
|
3199
|
+
}
|
|
3200
|
+
async function getAddLiquidityInstructionAsync(input, config) {
|
|
3201
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
3202
|
+
const originalAccounts = {
|
|
3203
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
3204
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
3205
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
3206
|
+
protocolFeePosition: {
|
|
3207
|
+
value: input.protocolFeePosition ?? null,
|
|
3208
|
+
isWritable: true
|
|
3209
|
+
},
|
|
3210
|
+
owner: { value: input.owner ?? null, isWritable: false },
|
|
3211
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
3212
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
3213
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
3214
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
3215
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
3216
|
+
user0: { value: input.user0 ?? null, isWritable: true },
|
|
3217
|
+
user1: { value: input.user1 ?? null, isWritable: true },
|
|
3218
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
3219
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false },
|
|
3220
|
+
oracle: { value: input.oracle ?? null, isWritable: true }
|
|
3221
|
+
};
|
|
3222
|
+
const accounts = originalAccounts;
|
|
3223
|
+
const args = { ...input };
|
|
3224
|
+
if (!accounts.authority.value) {
|
|
3225
|
+
accounts.authority.value = await kit.getProgramDerivedAddress({
|
|
3226
|
+
programAddress,
|
|
3227
|
+
seeds: [
|
|
3228
|
+
kit.getBytesEncoder().encode(
|
|
3229
|
+
new Uint8Array([97, 117, 116, 104, 111, 114, 105, 116, 121])
|
|
3230
|
+
),
|
|
3231
|
+
kit.getAddressEncoder().encode(
|
|
3232
|
+
programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
|
|
3233
|
+
)
|
|
3234
|
+
]
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3237
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
3238
|
+
return Object.freeze({
|
|
3239
|
+
accounts: [
|
|
3240
|
+
getAccountMeta("config", accounts.config),
|
|
3241
|
+
getAccountMeta("pool", accounts.pool),
|
|
3242
|
+
getAccountMeta("position", accounts.position),
|
|
3243
|
+
getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
|
|
3244
|
+
getAccountMeta("owner", accounts.owner),
|
|
3245
|
+
getAccountMeta("authority", accounts.authority),
|
|
3246
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
3247
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
3248
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
3249
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
3250
|
+
getAccountMeta("user0", accounts.user0),
|
|
3251
|
+
getAccountMeta("user1", accounts.user1),
|
|
3252
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
3253
|
+
getAccountMeta("token1Program", accounts.token1Program),
|
|
3254
|
+
getAccountMeta("oracle", accounts.oracle)
|
|
3255
|
+
],
|
|
3256
|
+
data: getAddLiquidityInstructionDataEncoder().encode(
|
|
3257
|
+
args
|
|
3258
|
+
),
|
|
3259
|
+
programAddress
|
|
3260
|
+
});
|
|
3261
|
+
}
|
|
3262
|
+
function getAddLiquidityInstruction(input, config) {
|
|
3263
|
+
const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
|
|
3264
|
+
const originalAccounts = {
|
|
3265
|
+
config: { value: input.config ?? null, isWritable: false },
|
|
3266
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
3267
|
+
position: { value: input.position ?? null, isWritable: true },
|
|
3268
|
+
protocolFeePosition: {
|
|
3269
|
+
value: input.protocolFeePosition ?? null,
|
|
3270
|
+
isWritable: true
|
|
3271
|
+
},
|
|
3272
|
+
owner: { value: input.owner ?? null, isWritable: false },
|
|
3273
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
3274
|
+
vault0: { value: input.vault0 ?? null, isWritable: true },
|
|
3275
|
+
vault1: { value: input.vault1 ?? null, isWritable: true },
|
|
3276
|
+
token0Mint: { value: input.token0Mint ?? null, isWritable: false },
|
|
3277
|
+
token1Mint: { value: input.token1Mint ?? null, isWritable: false },
|
|
3278
|
+
user0: { value: input.user0 ?? null, isWritable: true },
|
|
3279
|
+
user1: { value: input.user1 ?? null, isWritable: true },
|
|
3280
|
+
token0Program: { value: input.token0Program ?? null, isWritable: false },
|
|
3281
|
+
token1Program: { value: input.token1Program ?? null, isWritable: false },
|
|
3282
|
+
oracle: { value: input.oracle ?? null, isWritable: true }
|
|
3283
|
+
};
|
|
3284
|
+
const accounts = originalAccounts;
|
|
3285
|
+
const args = { ...input };
|
|
3286
|
+
const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
|
|
3287
|
+
return Object.freeze({
|
|
3288
|
+
accounts: [
|
|
3289
|
+
getAccountMeta("config", accounts.config),
|
|
3290
|
+
getAccountMeta("pool", accounts.pool),
|
|
3291
|
+
getAccountMeta("position", accounts.position),
|
|
3292
|
+
getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
|
|
3293
|
+
getAccountMeta("owner", accounts.owner),
|
|
3294
|
+
getAccountMeta("authority", accounts.authority),
|
|
3295
|
+
getAccountMeta("vault0", accounts.vault0),
|
|
3296
|
+
getAccountMeta("vault1", accounts.vault1),
|
|
3297
|
+
getAccountMeta("token0Mint", accounts.token0Mint),
|
|
3298
|
+
getAccountMeta("token1Mint", accounts.token1Mint),
|
|
3299
|
+
getAccountMeta("user0", accounts.user0),
|
|
3300
|
+
getAccountMeta("user1", accounts.user1),
|
|
3301
|
+
getAccountMeta("token0Program", accounts.token0Program),
|
|
3302
|
+
getAccountMeta("token1Program", accounts.token1Program),
|
|
3303
|
+
getAccountMeta("oracle", accounts.oracle)
|
|
3304
|
+
],
|
|
3305
|
+
data: getAddLiquidityInstructionDataEncoder().encode(
|
|
3306
|
+
args
|
|
3307
|
+
),
|
|
3308
|
+
programAddress
|
|
3309
|
+
});
|
|
3310
|
+
}
|
|
3311
|
+
function parseAddLiquidityInstruction(instruction) {
|
|
3312
|
+
if (instruction.accounts.length < 15) {
|
|
3313
|
+
throw new kit.SolanaError(
|
|
3314
|
+
kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
3315
|
+
{
|
|
3316
|
+
actualAccountMetas: instruction.accounts.length,
|
|
3317
|
+
expectedAccountMetas: 15
|
|
3318
|
+
}
|
|
3319
|
+
);
|
|
3320
|
+
}
|
|
3321
|
+
let accountIndex = 0;
|
|
3322
|
+
const getNextAccount = () => {
|
|
3323
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
3324
|
+
accountIndex += 1;
|
|
3325
|
+
return accountMeta;
|
|
3326
|
+
};
|
|
3327
|
+
const getNextOptionalAccount = () => {
|
|
3328
|
+
const accountMeta = getNextAccount();
|
|
3329
|
+
return accountMeta.address === CPMM_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
3330
|
+
};
|
|
3331
|
+
return {
|
|
3332
|
+
programAddress: instruction.programAddress,
|
|
3333
|
+
accounts: {
|
|
3334
|
+
config: getNextAccount(),
|
|
3335
|
+
pool: getNextAccount(),
|
|
3336
|
+
position: getNextAccount(),
|
|
3337
|
+
protocolFeePosition: getNextAccount(),
|
|
3338
|
+
owner: getNextAccount(),
|
|
3339
|
+
authority: getNextAccount(),
|
|
3340
|
+
vault0: getNextAccount(),
|
|
3341
|
+
vault1: getNextAccount(),
|
|
3342
|
+
token0Mint: getNextAccount(),
|
|
3343
|
+
token1Mint: getNextAccount(),
|
|
3344
|
+
user0: getNextAccount(),
|
|
3345
|
+
user1: getNextAccount(),
|
|
3346
|
+
token0Program: getNextAccount(),
|
|
3347
|
+
token1Program: getNextAccount(),
|
|
3348
|
+
oracle: getNextOptionalAccount()
|
|
3349
|
+
},
|
|
3350
|
+
data: getAddLiquidityInstructionDataDecoder().decode(instruction.data)
|
|
3351
|
+
};
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3354
|
+
// src/solana/client/pool.ts
|
|
3355
|
+
function bytesToBase64(bytes) {
|
|
3356
|
+
let binary = "";
|
|
3357
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
3358
|
+
binary += String.fromCharCode(bytes[i]);
|
|
3359
|
+
}
|
|
3360
|
+
return btoa(binary);
|
|
3361
|
+
}
|
|
3362
|
+
function base64ToBytes(base64) {
|
|
3363
|
+
const binary = atob(base64);
|
|
3364
|
+
const bytes = new Uint8Array(binary.length);
|
|
3365
|
+
for (let i = 0; i < binary.length; i++) {
|
|
3366
|
+
bytes[i] = binary.charCodeAt(i);
|
|
3367
|
+
}
|
|
3368
|
+
return bytes;
|
|
3369
|
+
}
|
|
3370
|
+
async function fetchPool(rpc, address, config) {
|
|
3371
|
+
const response = await rpc.getAccountInfo(address, {
|
|
3372
|
+
encoding: "base64",
|
|
3373
|
+
commitment: config?.commitment
|
|
3374
|
+
}).send();
|
|
3375
|
+
if (!response.value) {
|
|
3376
|
+
return null;
|
|
3377
|
+
}
|
|
3378
|
+
return decodePool(base64ToBytes(response.value.data[0]));
|
|
3379
|
+
}
|
|
3380
|
+
async function fetchAllPools(rpc, config) {
|
|
3381
|
+
const programId = config?.programId ?? chunkY6TJIH33_cjs.CPMM_PROGRAM_ID;
|
|
3382
|
+
const discriminatorFilter = {
|
|
3383
|
+
memcmp: {
|
|
3384
|
+
offset: 0n,
|
|
3385
|
+
bytes: bytesToBase64(chunkY6TJIH33_cjs.ACCOUNT_DISCRIMINATORS.Pool),
|
|
3386
|
+
encoding: "base64"
|
|
3387
|
+
}
|
|
3388
|
+
};
|
|
3389
|
+
const response = await rpc.getProgramAccounts(programId, {
|
|
3390
|
+
encoding: "base64",
|
|
3391
|
+
commitment: config?.commitment,
|
|
3392
|
+
filters: [discriminatorFilter]
|
|
3393
|
+
}).send();
|
|
3394
|
+
const accounts = Array.isArray(response) ? response : response.value;
|
|
3395
|
+
const pools = [];
|
|
3396
|
+
for (const account of accounts) {
|
|
3397
|
+
try {
|
|
3398
|
+
const pool = decodePool(base64ToBytes(account.account.data[0]));
|
|
3399
|
+
pools.push({
|
|
3400
|
+
address: account.pubkey,
|
|
3401
|
+
account: pool
|
|
3402
|
+
});
|
|
3403
|
+
} catch {
|
|
3404
|
+
console.warn(`Failed to decode pool account: ${account.pubkey}`);
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
return pools;
|
|
3408
|
+
}
|
|
3409
|
+
async function getPoolByMints(rpc, mint0, mint1, config) {
|
|
3410
|
+
const programId = config?.programId ?? chunkY6TJIH33_cjs.CPMM_PROGRAM_ID;
|
|
3411
|
+
const [poolAddress] = await chunkY6TJIH33_cjs.getPoolAddress(mint0, mint1, programId);
|
|
3412
|
+
const pool = await fetchPool(rpc, poolAddress, config);
|
|
3413
|
+
if (!pool) {
|
|
3414
|
+
return null;
|
|
3415
|
+
}
|
|
3416
|
+
return {
|
|
3417
|
+
address: poolAddress,
|
|
3418
|
+
account: pool
|
|
3419
|
+
};
|
|
3420
|
+
}
|
|
3421
|
+
async function fetchPoolsBatch(rpc, addresses, config) {
|
|
3422
|
+
const pools = /* @__PURE__ */ new Map();
|
|
3423
|
+
const results = await Promise.all(
|
|
3424
|
+
addresses.map((addr) => fetchPool(rpc, addr, config))
|
|
3425
|
+
);
|
|
3426
|
+
for (let i = 0; i < addresses.length; i++) {
|
|
3427
|
+
const pool = results[i];
|
|
3428
|
+
if (pool) {
|
|
3429
|
+
pools.set(addresses[i], pool);
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
return pools;
|
|
3433
|
+
}
|
|
3434
|
+
async function poolExists(rpc, mint0, mint1, config) {
|
|
3435
|
+
const result = await getPoolByMints(rpc, mint0, mint1, config);
|
|
3436
|
+
return result !== null;
|
|
3437
|
+
}
|
|
3438
|
+
async function getPoolAddressFromMints(mint0, mint1, programId = chunkY6TJIH33_cjs.CPMM_PROGRAM_ID) {
|
|
3439
|
+
const [token0, token1] = chunkY6TJIH33_cjs.sortMints(mint0, mint1);
|
|
3440
|
+
const [poolAddress] = await chunkY6TJIH33_cjs.getPoolAddress(mint0, mint1, programId);
|
|
3441
|
+
return {
|
|
3442
|
+
poolAddress,
|
|
3443
|
+
token0,
|
|
3444
|
+
token1
|
|
3445
|
+
};
|
|
3446
|
+
}
|
|
3447
|
+
function filterPoolsByMint(pools, mint) {
|
|
3448
|
+
return pools.filter(
|
|
3449
|
+
({ account }) => account.token0Mint === mint || account.token1Mint === mint
|
|
3450
|
+
);
|
|
3451
|
+
}
|
|
3452
|
+
function sortPoolsByReserves(pools, descending = true) {
|
|
3453
|
+
return [...pools].sort((a, b) => {
|
|
3454
|
+
const totalA = a.account.reserve0 + a.account.reserve1;
|
|
3455
|
+
const totalB = b.account.reserve0 + b.account.reserve1;
|
|
3456
|
+
const cmp = totalA < totalB ? -1 : totalA > totalB ? 1 : 0;
|
|
3457
|
+
return descending ? -cmp : cmp;
|
|
3458
|
+
});
|
|
3459
|
+
}
|
|
3460
|
+
|
|
3461
|
+
// src/solana/client/position.ts
|
|
3462
|
+
function bytesToBase642(bytes) {
|
|
3463
|
+
let binary = "";
|
|
3464
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
3465
|
+
binary += String.fromCharCode(bytes[i]);
|
|
3466
|
+
}
|
|
3467
|
+
return btoa(binary);
|
|
3468
|
+
}
|
|
3469
|
+
function base64ToBytes2(base64) {
|
|
3470
|
+
const binary = atob(base64);
|
|
3471
|
+
const bytes = new Uint8Array(binary.length);
|
|
3472
|
+
for (let i = 0; i < binary.length; i++) {
|
|
3473
|
+
bytes[i] = binary.charCodeAt(i);
|
|
3474
|
+
}
|
|
3475
|
+
return bytes;
|
|
3476
|
+
}
|
|
3477
|
+
async function fetchPosition(rpc, address, config) {
|
|
3478
|
+
const response = await rpc.getAccountInfo(address, {
|
|
3479
|
+
encoding: "base64",
|
|
3480
|
+
commitment: config?.commitment
|
|
3481
|
+
}).send();
|
|
3482
|
+
if (!response.value) {
|
|
3483
|
+
return null;
|
|
3484
|
+
}
|
|
3485
|
+
return decodePosition(base64ToBytes2(response.value.data[0]));
|
|
3486
|
+
}
|
|
3487
|
+
async function fetchUserPositions(rpc, owner, pool, config) {
|
|
3488
|
+
const programId = config?.programId ?? chunkY6TJIH33_cjs.CPMM_PROGRAM_ID;
|
|
3489
|
+
const filters = [
|
|
3490
|
+
// Discriminator filter (first 8 bytes)
|
|
3491
|
+
{
|
|
3492
|
+
memcmp: {
|
|
3493
|
+
offset: 0n,
|
|
3494
|
+
bytes: bytesToBase642(
|
|
3495
|
+
chunkY6TJIH33_cjs.ACCOUNT_DISCRIMINATORS.Position
|
|
3496
|
+
),
|
|
3497
|
+
encoding: "base64"
|
|
3498
|
+
}
|
|
3499
|
+
},
|
|
3500
|
+
// Owner filter (after 8-byte discriminator + 32-byte pool = offset 40)
|
|
3501
|
+
{
|
|
3502
|
+
memcmp: {
|
|
3503
|
+
offset: 40n,
|
|
3504
|
+
bytes: owner,
|
|
3505
|
+
encoding: "base58"
|
|
3506
|
+
}
|
|
3507
|
+
}
|
|
3508
|
+
];
|
|
3509
|
+
if (pool) {
|
|
3510
|
+
filters.push({
|
|
3511
|
+
memcmp: {
|
|
3512
|
+
offset: 8n,
|
|
3513
|
+
bytes: pool,
|
|
3514
|
+
encoding: "base58"
|
|
3515
|
+
}
|
|
3516
|
+
});
|
|
3517
|
+
}
|
|
3518
|
+
const response = await rpc.getProgramAccounts(programId, {
|
|
3519
|
+
encoding: "base64",
|
|
3520
|
+
commitment: config?.commitment,
|
|
3521
|
+
filters
|
|
3522
|
+
}).send();
|
|
3523
|
+
const accounts = Array.isArray(response) ? response : response.value;
|
|
3524
|
+
const positions = [];
|
|
3525
|
+
for (const account of accounts) {
|
|
3526
|
+
try {
|
|
3527
|
+
const position = decodePosition(base64ToBytes2(account.account.data[0]));
|
|
3528
|
+
positions.push({
|
|
3529
|
+
address: account.pubkey,
|
|
3530
|
+
account: position
|
|
3531
|
+
});
|
|
3532
|
+
} catch {
|
|
3533
|
+
console.warn(`Failed to decode position account: ${account.pubkey}`);
|
|
3534
|
+
}
|
|
3535
|
+
}
|
|
3536
|
+
return positions;
|
|
3537
|
+
}
|
|
3538
|
+
async function fetchPoolPositions(rpc, pool, config) {
|
|
3539
|
+
const programId = config?.programId ?? chunkY6TJIH33_cjs.CPMM_PROGRAM_ID;
|
|
3540
|
+
const filters = [
|
|
3541
|
+
// Discriminator filter
|
|
3542
|
+
{
|
|
3543
|
+
memcmp: {
|
|
3544
|
+
offset: 0n,
|
|
3545
|
+
bytes: bytesToBase642(
|
|
3546
|
+
chunkY6TJIH33_cjs.ACCOUNT_DISCRIMINATORS.Position
|
|
3547
|
+
),
|
|
3548
|
+
encoding: "base64"
|
|
3549
|
+
}
|
|
3550
|
+
},
|
|
3551
|
+
// Pool filter (after 8-byte discriminator = offset 8)
|
|
3552
|
+
{
|
|
3553
|
+
memcmp: {
|
|
3554
|
+
offset: 8n,
|
|
3555
|
+
bytes: pool,
|
|
3556
|
+
encoding: "base58"
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
];
|
|
3560
|
+
const response = await rpc.getProgramAccounts(programId, {
|
|
3561
|
+
encoding: "base64",
|
|
3562
|
+
commitment: config?.commitment,
|
|
3563
|
+
filters
|
|
3564
|
+
}).send();
|
|
3565
|
+
const accounts = Array.isArray(response) ? response : response.value;
|
|
3566
|
+
const positions = [];
|
|
3567
|
+
for (const account of accounts) {
|
|
3568
|
+
try {
|
|
3569
|
+
const position = decodePosition(base64ToBytes2(account.account.data[0]));
|
|
3570
|
+
positions.push({
|
|
3571
|
+
address: account.pubkey,
|
|
3572
|
+
account: position
|
|
3573
|
+
});
|
|
3574
|
+
} catch {
|
|
3575
|
+
console.warn(`Failed to decode position account: ${account.pubkey}`);
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
return positions;
|
|
3579
|
+
}
|
|
3580
|
+
function getPositionValue(pool, position) {
|
|
3581
|
+
if (pool.totalShares === 0n) {
|
|
3582
|
+
return {
|
|
3583
|
+
amount0: 0n,
|
|
3584
|
+
amount1: 0n,
|
|
3585
|
+
pendingFees0: 0n,
|
|
3586
|
+
pendingFees1: 0n,
|
|
3587
|
+
totalValue0: 0n,
|
|
3588
|
+
totalValue1: 0n,
|
|
3589
|
+
poolShare: 0
|
|
3590
|
+
};
|
|
3591
|
+
}
|
|
3592
|
+
const amount0 = position.shares * pool.reserve0 / pool.totalShares;
|
|
3593
|
+
const amount1 = position.shares * pool.reserve1 / pool.totalShares;
|
|
3594
|
+
const { pending0, pending1 } = getPendingFees(pool, position);
|
|
3595
|
+
const poolShare = ratioToNumber(position.shares, pool.totalShares);
|
|
3596
|
+
return {
|
|
3597
|
+
amount0,
|
|
3598
|
+
amount1,
|
|
3599
|
+
pendingFees0: pending0,
|
|
3600
|
+
pendingFees1: pending1,
|
|
3601
|
+
totalValue0: amount0 + pending0,
|
|
3602
|
+
totalValue1: amount1 + pending1,
|
|
3603
|
+
poolShare
|
|
3604
|
+
};
|
|
3605
|
+
}
|
|
3606
|
+
async function fetchPositionByParams(rpc, pool, owner, positionId, config) {
|
|
3607
|
+
const programId = config?.programId ?? chunkY6TJIH33_cjs.CPMM_PROGRAM_ID;
|
|
3608
|
+
const [address] = await chunkY6TJIH33_cjs.getPositionAddress(
|
|
3609
|
+
pool,
|
|
3610
|
+
owner,
|
|
3611
|
+
positionId,
|
|
3612
|
+
programId
|
|
3613
|
+
);
|
|
3614
|
+
const position = await fetchPosition(rpc, address, config);
|
|
3615
|
+
if (!position) {
|
|
3616
|
+
return null;
|
|
3617
|
+
}
|
|
3618
|
+
return {
|
|
3619
|
+
address,
|
|
3620
|
+
account: position
|
|
3621
|
+
};
|
|
3622
|
+
}
|
|
3623
|
+
async function getPositionAddressFromParams(pool, owner, positionId, programId = chunkY6TJIH33_cjs.CPMM_PROGRAM_ID) {
|
|
3624
|
+
const [address] = await chunkY6TJIH33_cjs.getPositionAddress(
|
|
3625
|
+
pool,
|
|
3626
|
+
owner,
|
|
3627
|
+
positionId,
|
|
3628
|
+
programId
|
|
3629
|
+
);
|
|
3630
|
+
return address;
|
|
3631
|
+
}
|
|
3632
|
+
async function fetchPositionsBatch(rpc, addresses, config) {
|
|
3633
|
+
const positions = /* @__PURE__ */ new Map();
|
|
3634
|
+
const results = await Promise.all(
|
|
3635
|
+
addresses.map((addr) => fetchPosition(rpc, addr, config))
|
|
3636
|
+
);
|
|
3637
|
+
for (let i = 0; i < addresses.length; i++) {
|
|
3638
|
+
const position = results[i];
|
|
3639
|
+
if (position) {
|
|
3640
|
+
positions.set(addresses[i], position);
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
return positions;
|
|
3644
|
+
}
|
|
3645
|
+
function filterActivePositions(positions) {
|
|
3646
|
+
return positions.filter(({ account }) => account.shares > 0n);
|
|
3647
|
+
}
|
|
3648
|
+
function sortPositionsByShares(positions, descending = true) {
|
|
3649
|
+
return [...positions].sort((a, b) => {
|
|
3650
|
+
const cmp = a.account.shares < b.account.shares ? -1 : a.account.shares > b.account.shares ? 1 : 0;
|
|
3651
|
+
return descending ? -cmp : cmp;
|
|
3652
|
+
});
|
|
3653
|
+
}
|
|
3654
|
+
|
|
3655
|
+
// src/solana/client/oracle.ts
|
|
3656
|
+
function base64ToBytes3(base64) {
|
|
3657
|
+
const binary = atob(base64);
|
|
3658
|
+
const bytes = new Uint8Array(binary.length);
|
|
3659
|
+
for (let i = 0; i < binary.length; i++) {
|
|
3660
|
+
bytes[i] = binary.charCodeAt(i);
|
|
3661
|
+
}
|
|
3662
|
+
return bytes;
|
|
3663
|
+
}
|
|
3664
|
+
async function fetchOracle(rpc, address, config) {
|
|
3665
|
+
const response = await rpc.getAccountInfo(address, {
|
|
3666
|
+
encoding: "base64",
|
|
3667
|
+
commitment: config?.commitment
|
|
3668
|
+
}).send();
|
|
3669
|
+
if (!response.value) {
|
|
3670
|
+
return null;
|
|
3671
|
+
}
|
|
3672
|
+
return decodeOracleState(base64ToBytes3(response.value.data[0]));
|
|
3673
|
+
}
|
|
3674
|
+
async function getOracleForPool(rpc, pool, config) {
|
|
3675
|
+
const programId = config?.programId ?? chunkY6TJIH33_cjs.CPMM_PROGRAM_ID;
|
|
3676
|
+
const [oracleAddress] = await chunkY6TJIH33_cjs.getOracleAddress(pool, programId);
|
|
3677
|
+
const oracle = await fetchOracle(rpc, oracleAddress, config);
|
|
3678
|
+
if (!oracle) {
|
|
3679
|
+
return null;
|
|
3680
|
+
}
|
|
3681
|
+
return {
|
|
3682
|
+
address: oracleAddress,
|
|
3683
|
+
account: oracle
|
|
3684
|
+
};
|
|
3685
|
+
}
|
|
3686
|
+
async function getOracleAddressFromPool(pool, programId = chunkY6TJIH33_cjs.CPMM_PROGRAM_ID) {
|
|
3687
|
+
const [address] = await chunkY6TJIH33_cjs.getOracleAddress(pool, programId);
|
|
3688
|
+
return address;
|
|
3689
|
+
}
|
|
3690
|
+
function consultTwap(oracle, windowSeconds, currentTimestamp) {
|
|
3691
|
+
if (!oracle.initialized || oracle.lastTimestamp === 0) {
|
|
3692
|
+
return null;
|
|
3693
|
+
}
|
|
3694
|
+
const nowTs = Math.max(0, Math.floor(currentTimestamp ?? Date.now() / 1e3));
|
|
3695
|
+
const dtSinceLast = Math.max(0, nowTs - oracle.lastTimestamp);
|
|
3696
|
+
const cum0Now = oracle.price0Cumulative + oracle.truncPrice0Q64 * BigInt(dtSinceLast);
|
|
3697
|
+
const cum1Now = oracle.price1Cumulative + oracle.truncPrice1Q64 * BigInt(dtSinceLast);
|
|
3698
|
+
if (windowSeconds === 0) {
|
|
3699
|
+
return {
|
|
3700
|
+
price0Q64: oracle.truncPrice0Q64,
|
|
3701
|
+
price1Q64: oracle.truncPrice1Q64,
|
|
3702
|
+
price0: q64ToNumber(oracle.truncPrice0Q64),
|
|
3703
|
+
price1: q64ToNumber(oracle.truncPrice1Q64)
|
|
3704
|
+
};
|
|
3705
|
+
}
|
|
3706
|
+
const targetTs = Math.max(0, nowTs - windowSeconds);
|
|
3707
|
+
const sample = selectSample(oracle, targetTs);
|
|
3708
|
+
if (!sample) {
|
|
3709
|
+
return null;
|
|
3710
|
+
}
|
|
3711
|
+
const dt = Math.max(0, nowTs - sample.timestamp);
|
|
3712
|
+
if (dt === 0) {
|
|
3713
|
+
return null;
|
|
3714
|
+
}
|
|
3715
|
+
const price0Q64 = (cum0Now - sample.price0Cumulative) / BigInt(dt);
|
|
3716
|
+
const price1Q64 = (cum1Now - sample.price1Cumulative) / BigInt(dt);
|
|
3717
|
+
return {
|
|
3718
|
+
price0Q64,
|
|
3719
|
+
price1Q64,
|
|
3720
|
+
price0: q64ToNumber(price0Q64),
|
|
3721
|
+
price1: q64ToNumber(price1Q64)
|
|
3722
|
+
};
|
|
3723
|
+
}
|
|
3724
|
+
function selectSample(oracle, targetTimestamp) {
|
|
3725
|
+
let best = null;
|
|
3726
|
+
const base = {
|
|
3727
|
+
timestamp: oracle.lastTimestamp,
|
|
3728
|
+
price0Cumulative: oracle.price0Cumulative,
|
|
3729
|
+
price1Cumulative: oracle.price1Cumulative
|
|
3730
|
+
};
|
|
3731
|
+
if (base.timestamp !== 0 && base.timestamp <= targetTimestamp) {
|
|
3732
|
+
best = base;
|
|
3733
|
+
}
|
|
3734
|
+
for (const obs of oracle.observations) {
|
|
3735
|
+
if (obs.timestamp === 0) {
|
|
3736
|
+
continue;
|
|
3737
|
+
}
|
|
3738
|
+
if (obs.timestamp <= targetTimestamp) {
|
|
3739
|
+
if (!best || obs.timestamp > best.timestamp) {
|
|
3740
|
+
best = obs;
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
if (best) {
|
|
3745
|
+
return best;
|
|
3746
|
+
}
|
|
3747
|
+
let oldest = base.timestamp !== 0 ? base : null;
|
|
3748
|
+
for (const obs of oracle.observations) {
|
|
3749
|
+
if (obs.timestamp === 0) {
|
|
3750
|
+
continue;
|
|
3751
|
+
}
|
|
3752
|
+
if (!oldest || obs.timestamp < oldest.timestamp) {
|
|
3753
|
+
oldest = obs;
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
return oldest;
|
|
3757
|
+
}
|
|
3758
|
+
function getOracleSpotPrices(oracle) {
|
|
3759
|
+
return {
|
|
3760
|
+
price0Q64: oracle.truncPrice0Q64,
|
|
3761
|
+
price1Q64: oracle.truncPrice1Q64,
|
|
3762
|
+
price0: q64ToNumber(oracle.truncPrice0Q64),
|
|
3763
|
+
price1: q64ToNumber(oracle.truncPrice1Q64)
|
|
3764
|
+
};
|
|
3765
|
+
}
|
|
3766
|
+
function getOracleDeviation(oracle) {
|
|
3767
|
+
return {
|
|
3768
|
+
deviation0Q64: oracle.deviation0Q64,
|
|
3769
|
+
deviation1Q64: oracle.deviation1Q64,
|
|
3770
|
+
deviation0: q64ToNumber(oracle.deviation0Q64),
|
|
3771
|
+
deviation1: q64ToNumber(oracle.deviation1Q64)
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
function getOracleAge(oracle, currentTimestamp) {
|
|
3775
|
+
const now = currentTimestamp ?? Math.floor(Date.now() / 1e3);
|
|
3776
|
+
return now - oracle.lastTimestamp;
|
|
3777
|
+
}
|
|
3778
|
+
function isOracleStale(oracle, maxAgeSeconds, currentTimestamp) {
|
|
3779
|
+
return getOracleAge(oracle, currentTimestamp) > maxAgeSeconds;
|
|
3780
|
+
}
|
|
3781
|
+
function getOracleBufferStats(oracle) {
|
|
3782
|
+
const observations = oracle.observations;
|
|
3783
|
+
const capacity = observations.length;
|
|
3784
|
+
const currentIndex = oracle.observationIndex;
|
|
3785
|
+
let filledCount = 0;
|
|
3786
|
+
let oldestTimestamp = 0;
|
|
3787
|
+
let newestTimestamp = 0;
|
|
3788
|
+
for (let i = 0; i < capacity; i++) {
|
|
3789
|
+
const obs = observations[i];
|
|
3790
|
+
if (obs.timestamp > 0) {
|
|
3791
|
+
filledCount++;
|
|
3792
|
+
if (oldestTimestamp === 0 || obs.timestamp < oldestTimestamp) {
|
|
3793
|
+
oldestTimestamp = obs.timestamp;
|
|
3794
|
+
}
|
|
3795
|
+
if (obs.timestamp > newestTimestamp) {
|
|
3796
|
+
newestTimestamp = obs.timestamp;
|
|
3797
|
+
}
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
return {
|
|
3801
|
+
capacity,
|
|
3802
|
+
filledCount,
|
|
3803
|
+
currentIndex,
|
|
3804
|
+
oldestTimestamp,
|
|
3805
|
+
newestTimestamp,
|
|
3806
|
+
timeSpanSeconds: newestTimestamp > oldestTimestamp ? newestTimestamp - oldestTimestamp : 0
|
|
3807
|
+
};
|
|
3808
|
+
}
|
|
3809
|
+
async function fetchOraclesBatch(rpc, pools, config) {
|
|
3810
|
+
const programId = config?.programId ?? chunkY6TJIH33_cjs.CPMM_PROGRAM_ID;
|
|
3811
|
+
const oracles = /* @__PURE__ */ new Map();
|
|
3812
|
+
const oracleAddresses = await Promise.all(
|
|
3813
|
+
pools.map((pool) => chunkY6TJIH33_cjs.getOracleAddress(pool, programId))
|
|
3814
|
+
);
|
|
3815
|
+
const results = await Promise.all(
|
|
3816
|
+
oracleAddresses.map(([addr]) => fetchOracle(rpc, addr, config))
|
|
3817
|
+
);
|
|
3818
|
+
for (let i = 0; i < pools.length; i++) {
|
|
3819
|
+
const oracle = results[i];
|
|
3820
|
+
if (oracle) {
|
|
3821
|
+
oracles.set(pools[i], {
|
|
3822
|
+
address: oracleAddresses[i][0],
|
|
3823
|
+
account: oracle
|
|
3824
|
+
});
|
|
3825
|
+
}
|
|
3826
|
+
}
|
|
3827
|
+
return oracles;
|
|
3828
|
+
}
|
|
3829
|
+
function comparePoolAndOraclePrices(pool, oracle) {
|
|
3830
|
+
const poolPrice0 = pool.reserve0 > 0n ? Number(pool.reserve1) / Number(pool.reserve0) : 0;
|
|
3831
|
+
const oraclePrice0 = q64ToNumber(oracle.truncPrice0Q64);
|
|
3832
|
+
const divergencePct = oraclePrice0 > 0 ? (poolPrice0 - oraclePrice0) / oraclePrice0 * 100 : 0;
|
|
3833
|
+
return {
|
|
3834
|
+
poolPrice0,
|
|
3835
|
+
oraclePrice0,
|
|
3836
|
+
divergencePct
|
|
3837
|
+
};
|
|
3838
|
+
}
|
|
3839
|
+
|
|
3840
|
+
exports.ADD_LIQUIDITY_DISCRIMINATOR = ADD_LIQUIDITY_DISCRIMINATOR;
|
|
3841
|
+
exports.CLOSE_POSITION_DISCRIMINATOR = CLOSE_POSITION_DISCRIMINATOR;
|
|
3842
|
+
exports.COLLECT_FEES_DISCRIMINATOR = COLLECT_FEES_DISCRIMINATOR;
|
|
3843
|
+
exports.COLLECT_PROTOCOL_FEES_DISCRIMINATOR = COLLECT_PROTOCOL_FEES_DISCRIMINATOR;
|
|
3844
|
+
exports.CPMM_PROGRAM_ADDRESS = CPMM_PROGRAM_ADDRESS;
|
|
3845
|
+
exports.CREATE_POSITION_DISCRIMINATOR = CREATE_POSITION_DISCRIMINATOR;
|
|
3846
|
+
exports.INITIALIZE_CONFIG_DISCRIMINATOR = INITIALIZE_CONFIG_DISCRIMINATOR;
|
|
3847
|
+
exports.INITIALIZE_ORACLE_DISCRIMINATOR = INITIALIZE_ORACLE_DISCRIMINATOR;
|
|
3848
|
+
exports.INITIALIZE_POOL_DISCRIMINATOR = INITIALIZE_POOL_DISCRIMINATOR;
|
|
3849
|
+
exports.ORACLE_CONSULT_DISCRIMINATOR = ORACLE_CONSULT_DISCRIMINATOR;
|
|
3850
|
+
exports.ORACLE_UPDATE_DISCRIMINATOR = ORACLE_UPDATE_DISCRIMINATOR;
|
|
3851
|
+
exports.PAUSE_DISCRIMINATOR = PAUSE_DISCRIMINATOR;
|
|
3852
|
+
exports.PREVIEW_SWAP_EXACT_IN_DISCRIMINATOR = PREVIEW_SWAP_EXACT_IN_DISCRIMINATOR;
|
|
3853
|
+
exports.REDEEM_PROTOCOL_SHARES_DISCRIMINATOR = REDEEM_PROTOCOL_SHARES_DISCRIMINATOR;
|
|
3854
|
+
exports.REMOVE_LIQUIDITY_DISCRIMINATOR = REMOVE_LIQUIDITY_DISCRIMINATOR;
|
|
3855
|
+
exports.SET_FEES_DISCRIMINATOR = SET_FEES_DISCRIMINATOR;
|
|
3856
|
+
exports.SET_HOOK_DISCRIMINATOR = SET_HOOK_DISCRIMINATOR;
|
|
3857
|
+
exports.SWAP_EXACT_IN_DISCRIMINATOR = SWAP_EXACT_IN_DISCRIMINATOR;
|
|
3858
|
+
exports.TRANSFER_ADMIN_DISCRIMINATOR = TRANSFER_ADMIN_DISCRIMINATOR;
|
|
3859
|
+
exports.UNPAUSE_DISCRIMINATOR = UNPAUSE_DISCRIMINATOR;
|
|
3860
|
+
exports.UPDATE_CONFIG_DISCRIMINATOR = UPDATE_CONFIG_DISCRIMINATOR;
|
|
3861
|
+
exports.WITHDRAW_VAULT_EXCESS_DISCRIMINATOR = WITHDRAW_VAULT_EXCESS_DISCRIMINATOR;
|
|
3862
|
+
exports.addLiquidityArgsCodec = addLiquidityArgsCodec;
|
|
3863
|
+
exports.ammConfigDataCodec = ammConfigDataCodec;
|
|
3864
|
+
exports.calculateAccruedFees = calculateAccruedFees;
|
|
3865
|
+
exports.calculateTwap = calculateTwap;
|
|
3866
|
+
exports.calculateTwapNumber = calculateTwapNumber;
|
|
3867
|
+
exports.ceilDiv = ceilDiv;
|
|
3868
|
+
exports.collectFeesArgsCodec = collectFeesArgsCodec;
|
|
3869
|
+
exports.collectProtocolFeesArgsCodec = collectProtocolFeesArgsCodec;
|
|
3870
|
+
exports.comparePoolAndOraclePrices = comparePoolAndOraclePrices;
|
|
3871
|
+
exports.computePrice0Q64 = computePrice0Q64;
|
|
3872
|
+
exports.computePrice1Q64 = computePrice1Q64;
|
|
3873
|
+
exports.consultTwap = consultTwap;
|
|
3874
|
+
exports.createPositionArgsCodec = createPositionArgsCodec;
|
|
3875
|
+
exports.decodeAmmConfig = decodeAmmConfig;
|
|
3876
|
+
exports.decodeOracleState = decodeOracleState;
|
|
3877
|
+
exports.decodePool = decodePool;
|
|
3878
|
+
exports.decodePosition = decodePosition;
|
|
3879
|
+
exports.encodeAddLiquidityArgs = encodeAddLiquidityArgs;
|
|
3880
|
+
exports.encodeCollectFeesArgs = encodeCollectFeesArgs;
|
|
3881
|
+
exports.encodeCollectProtocolFeesArgs = encodeCollectProtocolFeesArgs;
|
|
3882
|
+
exports.encodeCreatePositionArgs = encodeCreatePositionArgs;
|
|
3883
|
+
exports.encodeInitializeConfigArgs = encodeInitializeConfigArgs;
|
|
3884
|
+
exports.encodeInitializeOracleArgs = encodeInitializeOracleArgs;
|
|
3885
|
+
exports.encodeInitializePoolArgs = encodeInitializePoolArgs;
|
|
3886
|
+
exports.encodeInstructionData = encodeInstructionData;
|
|
3887
|
+
exports.encodeOracleConsultArgs = encodeOracleConsultArgs;
|
|
3888
|
+
exports.encodeRemoveLiquidityArgs = encodeRemoveLiquidityArgs;
|
|
3889
|
+
exports.encodeSetFeesArgs = encodeSetFeesArgs;
|
|
3890
|
+
exports.encodeSetHookArgs = encodeSetHookArgs;
|
|
3891
|
+
exports.encodeSwapExactInArgs = encodeSwapExactInArgs;
|
|
3892
|
+
exports.encodeTransferAdminArgs = encodeTransferAdminArgs;
|
|
3893
|
+
exports.fetchAllPools = fetchAllPools;
|
|
3894
|
+
exports.fetchOracle = fetchOracle;
|
|
3895
|
+
exports.fetchOraclesBatch = fetchOraclesBatch;
|
|
3896
|
+
exports.fetchPool = fetchPool;
|
|
3897
|
+
exports.fetchPoolPositions = fetchPoolPositions;
|
|
3898
|
+
exports.fetchPoolsBatch = fetchPoolsBatch;
|
|
3899
|
+
exports.fetchPosition = fetchPosition;
|
|
3900
|
+
exports.fetchPositionByParams = fetchPositionByParams;
|
|
3901
|
+
exports.fetchPositionsBatch = fetchPositionsBatch;
|
|
3902
|
+
exports.fetchUserPositions = fetchUserPositions;
|
|
3903
|
+
exports.filterActivePositions = filterActivePositions;
|
|
3904
|
+
exports.filterPoolsByMint = filterPoolsByMint;
|
|
3905
|
+
exports.getAddLiquidityDiscriminatorBytes = getAddLiquidityDiscriminatorBytes;
|
|
3906
|
+
exports.getAddLiquidityInstruction = getAddLiquidityInstruction;
|
|
3907
|
+
exports.getAddLiquidityInstructionAsync = getAddLiquidityInstructionAsync;
|
|
3908
|
+
exports.getAddLiquidityInstructionDataCodec = getAddLiquidityInstructionDataCodec;
|
|
3909
|
+
exports.getAddLiquidityInstructionDataDecoder = getAddLiquidityInstructionDataDecoder;
|
|
3910
|
+
exports.getAddLiquidityInstructionDataEncoder = getAddLiquidityInstructionDataEncoder;
|
|
3911
|
+
exports.getAddLiquidityQuote = getAddLiquidityQuote;
|
|
3912
|
+
exports.getClosePositionDiscriminatorBytes = getClosePositionDiscriminatorBytes;
|
|
3913
|
+
exports.getClosePositionInstruction = getClosePositionInstruction;
|
|
3914
|
+
exports.getClosePositionInstructionDataCodec = getClosePositionInstructionDataCodec;
|
|
3915
|
+
exports.getClosePositionInstructionDataDecoder = getClosePositionInstructionDataDecoder;
|
|
3916
|
+
exports.getClosePositionInstructionDataEncoder = getClosePositionInstructionDataEncoder;
|
|
3917
|
+
exports.getCollectFeesDiscriminatorBytes = getCollectFeesDiscriminatorBytes;
|
|
3918
|
+
exports.getCollectFeesInstruction = getCollectFeesInstruction;
|
|
3919
|
+
exports.getCollectFeesInstructionAsync = getCollectFeesInstructionAsync;
|
|
3920
|
+
exports.getCollectFeesInstructionDataCodec = getCollectFeesInstructionDataCodec;
|
|
3921
|
+
exports.getCollectFeesInstructionDataDecoder = getCollectFeesInstructionDataDecoder;
|
|
3922
|
+
exports.getCollectFeesInstructionDataEncoder = getCollectFeesInstructionDataEncoder;
|
|
3923
|
+
exports.getCollectProtocolFeesDiscriminatorBytes = getCollectProtocolFeesDiscriminatorBytes;
|
|
3924
|
+
exports.getCollectProtocolFeesInstruction = getCollectProtocolFeesInstruction;
|
|
3925
|
+
exports.getCollectProtocolFeesInstructionAsync = getCollectProtocolFeesInstructionAsync;
|
|
3926
|
+
exports.getCollectProtocolFeesInstructionDataCodec = getCollectProtocolFeesInstructionDataCodec;
|
|
3927
|
+
exports.getCollectProtocolFeesInstructionDataDecoder = getCollectProtocolFeesInstructionDataDecoder;
|
|
3928
|
+
exports.getCollectProtocolFeesInstructionDataEncoder = getCollectProtocolFeesInstructionDataEncoder;
|
|
3929
|
+
exports.getCreatePositionDiscriminatorBytes = getCreatePositionDiscriminatorBytes;
|
|
3930
|
+
exports.getCreatePositionInstruction = getCreatePositionInstruction;
|
|
3931
|
+
exports.getCreatePositionInstructionAsync = getCreatePositionInstructionAsync;
|
|
3932
|
+
exports.getCreatePositionInstructionDataCodec = getCreatePositionInstructionDataCodec;
|
|
3933
|
+
exports.getCreatePositionInstructionDataDecoder = getCreatePositionInstructionDataDecoder;
|
|
3934
|
+
exports.getCreatePositionInstructionDataEncoder = getCreatePositionInstructionDataEncoder;
|
|
3935
|
+
exports.getInitializeConfigDiscriminatorBytes = getInitializeConfigDiscriminatorBytes;
|
|
3936
|
+
exports.getInitializeConfigInstruction = getInitializeConfigInstruction;
|
|
3937
|
+
exports.getInitializeConfigInstructionAsync = getInitializeConfigInstructionAsync;
|
|
3938
|
+
exports.getInitializeConfigInstructionDataCodec = getInitializeConfigInstructionDataCodec;
|
|
3939
|
+
exports.getInitializeConfigInstructionDataDecoder = getInitializeConfigInstructionDataDecoder;
|
|
3940
|
+
exports.getInitializeConfigInstructionDataEncoder = getInitializeConfigInstructionDataEncoder;
|
|
3941
|
+
exports.getInitializeOracleDiscriminatorBytes = getInitializeOracleDiscriminatorBytes;
|
|
3942
|
+
exports.getInitializeOracleInstruction = getInitializeOracleInstruction;
|
|
3943
|
+
exports.getInitializeOracleInstructionAsync = getInitializeOracleInstructionAsync;
|
|
3944
|
+
exports.getInitializeOracleInstructionDataCodec = getInitializeOracleInstructionDataCodec;
|
|
3945
|
+
exports.getInitializeOracleInstructionDataDecoder = getInitializeOracleInstructionDataDecoder;
|
|
3946
|
+
exports.getInitializeOracleInstructionDataEncoder = getInitializeOracleInstructionDataEncoder;
|
|
3947
|
+
exports.getInitializePoolDiscriminatorBytes = getInitializePoolDiscriminatorBytes;
|
|
3948
|
+
exports.getInitializePoolInstruction = getInitializePoolInstruction;
|
|
3949
|
+
exports.getInitializePoolInstructionAsync = getInitializePoolInstructionAsync;
|
|
3950
|
+
exports.getInitializePoolInstructionDataCodec = getInitializePoolInstructionDataCodec;
|
|
3951
|
+
exports.getInitializePoolInstructionDataDecoder = getInitializePoolInstructionDataDecoder;
|
|
3952
|
+
exports.getInitializePoolInstructionDataEncoder = getInitializePoolInstructionDataEncoder;
|
|
3953
|
+
exports.getK = getK;
|
|
3954
|
+
exports.getOracleAddressFromPool = getOracleAddressFromPool;
|
|
3955
|
+
exports.getOracleAge = getOracleAge;
|
|
3956
|
+
exports.getOracleBufferStats = getOracleBufferStats;
|
|
3957
|
+
exports.getOracleConsultDiscriminatorBytes = getOracleConsultDiscriminatorBytes;
|
|
3958
|
+
exports.getOracleConsultInstruction = getOracleConsultInstruction;
|
|
3959
|
+
exports.getOracleConsultInstructionAsync = getOracleConsultInstructionAsync;
|
|
3960
|
+
exports.getOracleConsultInstructionDataCodec = getOracleConsultInstructionDataCodec;
|
|
3961
|
+
exports.getOracleConsultInstructionDataDecoder = getOracleConsultInstructionDataDecoder;
|
|
3962
|
+
exports.getOracleConsultInstructionDataEncoder = getOracleConsultInstructionDataEncoder;
|
|
3963
|
+
exports.getOracleDeviation = getOracleDeviation;
|
|
3964
|
+
exports.getOracleForPool = getOracleForPool;
|
|
3965
|
+
exports.getOracleSpotPrices = getOracleSpotPrices;
|
|
3966
|
+
exports.getOracleUpdateDiscriminatorBytes = getOracleUpdateDiscriminatorBytes;
|
|
3967
|
+
exports.getOracleUpdateInstruction = getOracleUpdateInstruction;
|
|
3968
|
+
exports.getOracleUpdateInstructionAsync = getOracleUpdateInstructionAsync;
|
|
3969
|
+
exports.getOracleUpdateInstructionDataCodec = getOracleUpdateInstructionDataCodec;
|
|
3970
|
+
exports.getOracleUpdateInstructionDataDecoder = getOracleUpdateInstructionDataDecoder;
|
|
3971
|
+
exports.getOracleUpdateInstructionDataEncoder = getOracleUpdateInstructionDataEncoder;
|
|
3972
|
+
exports.getPauseDiscriminatorBytes = getPauseDiscriminatorBytes;
|
|
3973
|
+
exports.getPauseInstruction = getPauseInstruction;
|
|
3974
|
+
exports.getPauseInstructionDataCodec = getPauseInstructionDataCodec;
|
|
3975
|
+
exports.getPauseInstructionDataDecoder = getPauseInstructionDataDecoder;
|
|
3976
|
+
exports.getPauseInstructionDataEncoder = getPauseInstructionDataEncoder;
|
|
3977
|
+
exports.getPendingFees = getPendingFees;
|
|
3978
|
+
exports.getPoolAddressFromMints = getPoolAddressFromMints;
|
|
3979
|
+
exports.getPoolByMints = getPoolByMints;
|
|
3980
|
+
exports.getPositionAddressFromParams = getPositionAddressFromParams;
|
|
3981
|
+
exports.getPositionValue = getPositionValue;
|
|
3982
|
+
exports.getPreviewSwapExactInDiscriminatorBytes = getPreviewSwapExactInDiscriminatorBytes;
|
|
3983
|
+
exports.getPreviewSwapExactInInstruction = getPreviewSwapExactInInstruction;
|
|
3984
|
+
exports.getPreviewSwapExactInInstructionDataCodec = getPreviewSwapExactInInstructionDataCodec;
|
|
3985
|
+
exports.getPreviewSwapExactInInstructionDataDecoder = getPreviewSwapExactInInstructionDataDecoder;
|
|
3986
|
+
exports.getPreviewSwapExactInInstructionDataEncoder = getPreviewSwapExactInInstructionDataEncoder;
|
|
3987
|
+
exports.getRedeemProtocolSharesDiscriminatorBytes = getRedeemProtocolSharesDiscriminatorBytes;
|
|
3988
|
+
exports.getRedeemProtocolSharesInstruction = getRedeemProtocolSharesInstruction;
|
|
3989
|
+
exports.getRedeemProtocolSharesInstructionAsync = getRedeemProtocolSharesInstructionAsync;
|
|
3990
|
+
exports.getRedeemProtocolSharesInstructionDataCodec = getRedeemProtocolSharesInstructionDataCodec;
|
|
3991
|
+
exports.getRedeemProtocolSharesInstructionDataDecoder = getRedeemProtocolSharesInstructionDataDecoder;
|
|
3992
|
+
exports.getRedeemProtocolSharesInstructionDataEncoder = getRedeemProtocolSharesInstructionDataEncoder;
|
|
3993
|
+
exports.getRemoveLiquidityDiscriminatorBytes = getRemoveLiquidityDiscriminatorBytes;
|
|
3994
|
+
exports.getRemoveLiquidityInstruction = getRemoveLiquidityInstruction;
|
|
3995
|
+
exports.getRemoveLiquidityInstructionAsync = getRemoveLiquidityInstructionAsync;
|
|
3996
|
+
exports.getRemoveLiquidityInstructionDataCodec = getRemoveLiquidityInstructionDataCodec;
|
|
3997
|
+
exports.getRemoveLiquidityInstructionDataDecoder = getRemoveLiquidityInstructionDataDecoder;
|
|
3998
|
+
exports.getRemoveLiquidityInstructionDataEncoder = getRemoveLiquidityInstructionDataEncoder;
|
|
3999
|
+
exports.getRemoveLiquidityQuote = getRemoveLiquidityQuote;
|
|
4000
|
+
exports.getSetFeesDiscriminatorBytes = getSetFeesDiscriminatorBytes;
|
|
4001
|
+
exports.getSetFeesInstruction = getSetFeesInstruction;
|
|
4002
|
+
exports.getSetFeesInstructionDataCodec = getSetFeesInstructionDataCodec;
|
|
4003
|
+
exports.getSetFeesInstructionDataDecoder = getSetFeesInstructionDataDecoder;
|
|
4004
|
+
exports.getSetFeesInstructionDataEncoder = getSetFeesInstructionDataEncoder;
|
|
4005
|
+
exports.getSetHookDiscriminatorBytes = getSetHookDiscriminatorBytes;
|
|
4006
|
+
exports.getSetHookInstruction = getSetHookInstruction;
|
|
4007
|
+
exports.getSetHookInstructionDataCodec = getSetHookInstructionDataCodec;
|
|
4008
|
+
exports.getSetHookInstructionDataDecoder = getSetHookInstructionDataDecoder;
|
|
4009
|
+
exports.getSetHookInstructionDataEncoder = getSetHookInstructionDataEncoder;
|
|
4010
|
+
exports.getSpotPrice0 = getSpotPrice0;
|
|
4011
|
+
exports.getSpotPrice1 = getSpotPrice1;
|
|
4012
|
+
exports.getSwapExactInDiscriminatorBytes = getSwapExactInDiscriminatorBytes;
|
|
4013
|
+
exports.getSwapExactInInstruction = getSwapExactInInstruction;
|
|
4014
|
+
exports.getSwapExactInInstructionAsync = getSwapExactInInstructionAsync;
|
|
4015
|
+
exports.getSwapExactInInstructionDataCodec = getSwapExactInInstructionDataCodec;
|
|
4016
|
+
exports.getSwapExactInInstructionDataDecoder = getSwapExactInInstructionDataDecoder;
|
|
4017
|
+
exports.getSwapExactInInstructionDataEncoder = getSwapExactInInstructionDataEncoder;
|
|
4018
|
+
exports.getSwapQuote = getSwapQuote;
|
|
4019
|
+
exports.getSwapQuoteExactOut = getSwapQuoteExactOut;
|
|
4020
|
+
exports.getTransferAdminDiscriminatorBytes = getTransferAdminDiscriminatorBytes;
|
|
4021
|
+
exports.getTransferAdminInstruction = getTransferAdminInstruction;
|
|
4022
|
+
exports.getTransferAdminInstructionDataCodec = getTransferAdminInstructionDataCodec;
|
|
4023
|
+
exports.getTransferAdminInstructionDataDecoder = getTransferAdminInstructionDataDecoder;
|
|
4024
|
+
exports.getTransferAdminInstructionDataEncoder = getTransferAdminInstructionDataEncoder;
|
|
4025
|
+
exports.getTvl = getTvl;
|
|
4026
|
+
exports.getUnpauseDiscriminatorBytes = getUnpauseDiscriminatorBytes;
|
|
4027
|
+
exports.getUnpauseInstruction = getUnpauseInstruction;
|
|
4028
|
+
exports.getUnpauseInstructionDataCodec = getUnpauseInstructionDataCodec;
|
|
4029
|
+
exports.getUnpauseInstructionDataDecoder = getUnpauseInstructionDataDecoder;
|
|
4030
|
+
exports.getUnpauseInstructionDataEncoder = getUnpauseInstructionDataEncoder;
|
|
4031
|
+
exports.getUpdateConfigDiscriminatorBytes = getUpdateConfigDiscriminatorBytes;
|
|
4032
|
+
exports.getUpdateConfigInstruction = getUpdateConfigInstruction;
|
|
4033
|
+
exports.getUpdateConfigInstructionDataCodec = getUpdateConfigInstructionDataCodec;
|
|
4034
|
+
exports.getUpdateConfigInstructionDataDecoder = getUpdateConfigInstructionDataDecoder;
|
|
4035
|
+
exports.getUpdateConfigInstructionDataEncoder = getUpdateConfigInstructionDataEncoder;
|
|
4036
|
+
exports.getWithdrawVaultExcessDiscriminatorBytes = getWithdrawVaultExcessDiscriminatorBytes;
|
|
4037
|
+
exports.getWithdrawVaultExcessInstruction = getWithdrawVaultExcessInstruction;
|
|
4038
|
+
exports.getWithdrawVaultExcessInstructionAsync = getWithdrawVaultExcessInstructionAsync;
|
|
4039
|
+
exports.getWithdrawVaultExcessInstructionDataCodec = getWithdrawVaultExcessInstructionDataCodec;
|
|
4040
|
+
exports.getWithdrawVaultExcessInstructionDataDecoder = getWithdrawVaultExcessInstructionDataDecoder;
|
|
4041
|
+
exports.getWithdrawVaultExcessInstructionDataEncoder = getWithdrawVaultExcessInstructionDataEncoder;
|
|
4042
|
+
exports.initializeConfigArgsCodec = initializeConfigArgsCodec;
|
|
4043
|
+
exports.initializeOracleArgsCodec = initializeOracleArgsCodec;
|
|
4044
|
+
exports.initializePoolArgsCodec = initializePoolArgsCodec;
|
|
4045
|
+
exports.isOracleStale = isOracleStale;
|
|
4046
|
+
exports.isqrt = isqrt;
|
|
4047
|
+
exports.maxBigInt = maxBigInt;
|
|
4048
|
+
exports.minBigInt = minBigInt;
|
|
4049
|
+
exports.numberToQ64 = numberToQ64;
|
|
4050
|
+
exports.observationCodec = observationCodec;
|
|
4051
|
+
exports.oracleConsultArgsCodec = oracleConsultArgsCodec;
|
|
4052
|
+
exports.oracleStateDataCodec = oracleStateDataCodec;
|
|
4053
|
+
exports.parseAddLiquidityInstruction = parseAddLiquidityInstruction;
|
|
4054
|
+
exports.parseClosePositionInstruction = parseClosePositionInstruction;
|
|
4055
|
+
exports.parseCollectFeesInstruction = parseCollectFeesInstruction;
|
|
4056
|
+
exports.parseCollectProtocolFeesInstruction = parseCollectProtocolFeesInstruction;
|
|
4057
|
+
exports.parseCreatePositionInstruction = parseCreatePositionInstruction;
|
|
4058
|
+
exports.parseInitializeConfigInstruction = parseInitializeConfigInstruction;
|
|
4059
|
+
exports.parseInitializeOracleInstruction = parseInitializeOracleInstruction;
|
|
4060
|
+
exports.parseInitializePoolInstruction = parseInitializePoolInstruction;
|
|
4061
|
+
exports.parseOracleConsultInstruction = parseOracleConsultInstruction;
|
|
4062
|
+
exports.parseOracleUpdateInstruction = parseOracleUpdateInstruction;
|
|
4063
|
+
exports.parsePauseInstruction = parsePauseInstruction;
|
|
4064
|
+
exports.parsePreviewSwapExactInInstruction = parsePreviewSwapExactInInstruction;
|
|
4065
|
+
exports.parseRedeemProtocolSharesInstruction = parseRedeemProtocolSharesInstruction;
|
|
4066
|
+
exports.parseRemoveLiquidityInstruction = parseRemoveLiquidityInstruction;
|
|
4067
|
+
exports.parseSetFeesInstruction = parseSetFeesInstruction;
|
|
4068
|
+
exports.parseSetHookInstruction = parseSetHookInstruction;
|
|
4069
|
+
exports.parseSwapExactInInstruction = parseSwapExactInInstruction;
|
|
4070
|
+
exports.parseTransferAdminInstruction = parseTransferAdminInstruction;
|
|
4071
|
+
exports.parseUnpauseInstruction = parseUnpauseInstruction;
|
|
4072
|
+
exports.parseUpdateConfigInstruction = parseUpdateConfigInstruction;
|
|
4073
|
+
exports.parseWithdrawVaultExcessInstruction = parseWithdrawVaultExcessInstruction;
|
|
4074
|
+
exports.poolDataCodec = poolDataCodec;
|
|
4075
|
+
exports.poolExists = poolExists;
|
|
4076
|
+
exports.positionDataCodec = positionDataCodec;
|
|
4077
|
+
exports.q64Div = q64Div;
|
|
4078
|
+
exports.q64Mul = q64Mul;
|
|
4079
|
+
exports.q64ToNumber = q64ToNumber;
|
|
4080
|
+
exports.ratioToNumber = ratioToNumber;
|
|
4081
|
+
exports.removeLiquidityArgsCodec = removeLiquidityArgsCodec;
|
|
4082
|
+
exports.setFeesArgsCodec = setFeesArgsCodec;
|
|
4083
|
+
exports.setHookArgsCodec = setHookArgsCodec;
|
|
4084
|
+
exports.sortPoolsByReserves = sortPoolsByReserves;
|
|
4085
|
+
exports.sortPositionsByShares = sortPositionsByShares;
|
|
4086
|
+
exports.swapExactInArgsCodec = swapExactInArgsCodec;
|
|
4087
|
+
exports.transferAdminArgsCodec = transferAdminArgsCodec;
|
|
4088
|
+
//# sourceMappingURL=chunk-KJ6W44WF.cjs.map
|
|
4089
|
+
//# sourceMappingURL=chunk-KJ6W44WF.cjs.map
|