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