@thru/programs 0.3.16 → 0.3.17
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/amm/index.cjs +235 -28
- package/dist/amm/index.cjs.map +1 -1
- package/dist/amm/index.d.cts +34 -6
- package/dist/amm/index.d.ts +34 -6
- package/dist/amm/index.js +235 -28
- package/dist/amm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/amm/abi/thru/program/amm/types.ts +282 -23
- package/src/amm/index.test.ts +93 -3
- package/src/amm/index.ts +18 -1
package/dist/amm/index.cjs
CHANGED
|
@@ -1953,6 +1953,31 @@ function __tnCheckedAdd2(lhs, rhs) {
|
|
|
1953
1953
|
}
|
|
1954
1954
|
return sum;
|
|
1955
1955
|
}
|
|
1956
|
+
function __tnCheckedSub(lhs, rhs) {
|
|
1957
|
+
if (__tnHasNativeBigInt2) {
|
|
1958
|
+
const result = lhs - rhs;
|
|
1959
|
+
if (result < BigInt(0)) {
|
|
1960
|
+
__tnRaiseIrError2(
|
|
1961
|
+
"tn.ir.overflow",
|
|
1962
|
+
"IR runtime detected negative size via subtraction"
|
|
1963
|
+
);
|
|
1964
|
+
}
|
|
1965
|
+
return result;
|
|
1966
|
+
}
|
|
1967
|
+
const left = lhs;
|
|
1968
|
+
const right = rhs;
|
|
1969
|
+
const diff = left - right;
|
|
1970
|
+
if (diff < 0 || !Number.isFinite(diff)) {
|
|
1971
|
+
__tnRaiseIrError2(
|
|
1972
|
+
"tn.ir.overflow",
|
|
1973
|
+
"IR runtime detected invalid subtraction result"
|
|
1974
|
+
);
|
|
1975
|
+
}
|
|
1976
|
+
if (!Number.isSafeInteger(diff)) {
|
|
1977
|
+
__tnWarnOnce2("[thru-net] Precision loss while polyfilling BigInt subtraction");
|
|
1978
|
+
}
|
|
1979
|
+
return diff;
|
|
1980
|
+
}
|
|
1956
1981
|
function __tnCheckedMul2(lhs, rhs) {
|
|
1957
1982
|
if (__tnHasNativeBigInt2) {
|
|
1958
1983
|
const result = lhs * rhs;
|
|
@@ -1980,6 +2005,55 @@ function __tnCheckedMul2(lhs, rhs) {
|
|
|
1980
2005
|
}
|
|
1981
2006
|
return product;
|
|
1982
2007
|
}
|
|
2008
|
+
function __tnCheckedDiv(lhs, rhs) {
|
|
2009
|
+
if (__tnBigIntEquals2(rhs, __tnToBigInt2(0))) {
|
|
2010
|
+
__tnRaiseIrError2("tn.ir.overflow", "IR runtime division by zero");
|
|
2011
|
+
}
|
|
2012
|
+
if (__tnHasNativeBigInt2) return lhs / rhs;
|
|
2013
|
+
const quotient = Math.floor(lhs / rhs);
|
|
2014
|
+
return quotient;
|
|
2015
|
+
}
|
|
2016
|
+
function __tnCheckedMod(lhs, rhs) {
|
|
2017
|
+
if (__tnBigIntEquals2(rhs, __tnToBigInt2(0))) {
|
|
2018
|
+
__tnRaiseIrError2("tn.ir.overflow", "IR runtime modulo by zero");
|
|
2019
|
+
}
|
|
2020
|
+
if (__tnHasNativeBigInt2) return lhs % rhs;
|
|
2021
|
+
return lhs % rhs;
|
|
2022
|
+
}
|
|
2023
|
+
function __tnBitwise(lhs, rhs, op) {
|
|
2024
|
+
if (__tnHasNativeBigInt2) {
|
|
2025
|
+
if (op === "and") return lhs & rhs;
|
|
2026
|
+
if (op === "or") return lhs | rhs;
|
|
2027
|
+
return lhs ^ rhs;
|
|
2028
|
+
}
|
|
2029
|
+
const left = lhs;
|
|
2030
|
+
const right = rhs;
|
|
2031
|
+
const maxU32 = 4294967295;
|
|
2032
|
+
if (!Number.isInteger(left) || !Number.isInteger(right) || left < 0 || right < 0 || left > maxU32 || right > maxU32) {
|
|
2033
|
+
__tnRaiseIrError2(
|
|
2034
|
+
"tn.ir.overflow",
|
|
2035
|
+
"IR runtime bitwise operation requires BigInt for values outside u32 range"
|
|
2036
|
+
);
|
|
2037
|
+
}
|
|
2038
|
+
const result = op === "and" ? left & right : op === "or" ? left | right : left ^ right;
|
|
2039
|
+
return result >>> 0;
|
|
2040
|
+
}
|
|
2041
|
+
function __tnCheckedShift(lhs, rhs, direction) {
|
|
2042
|
+
const amount = __tnBigIntToNumber2(rhs, "IR shift amount");
|
|
2043
|
+
if (amount < 0 || amount >= 64 || !Number.isInteger(amount)) {
|
|
2044
|
+
__tnRaiseIrError2("tn.ir.overflow", "IR runtime invalid shift amount");
|
|
2045
|
+
}
|
|
2046
|
+
if (__tnHasNativeBigInt2) {
|
|
2047
|
+
const shift = BigInt(amount);
|
|
2048
|
+
return direction === "left" ? lhs << shift : lhs >> shift;
|
|
2049
|
+
}
|
|
2050
|
+
const value = lhs;
|
|
2051
|
+
const result = direction === "left" ? value * 2 ** amount : Math.floor(value / 2 ** amount);
|
|
2052
|
+
if (!Number.isSafeInteger(result)) {
|
|
2053
|
+
__tnWarnOnce2("[thru-net] Precision loss while polyfilling BigInt shift");
|
|
2054
|
+
}
|
|
2055
|
+
return result;
|
|
2056
|
+
}
|
|
1983
2057
|
function __tnAlign2(value, alignment) {
|
|
1984
2058
|
if (alignment <= 1) return value;
|
|
1985
2059
|
const alignBig = __tnToBigInt2(alignment);
|
|
@@ -2173,6 +2247,9 @@ function __tnEvalIrNode2(node, ctx, baseOffset) {
|
|
|
2173
2247
|
case "const":
|
|
2174
2248
|
return node.value;
|
|
2175
2249
|
case "field": {
|
|
2250
|
+
if (node.param === "__buffer_size" && ctx.buffer) {
|
|
2251
|
+
return __tnToBigInt2(ctx.buffer.length);
|
|
2252
|
+
}
|
|
2176
2253
|
const val = ctx.params[node.param];
|
|
2177
2254
|
if (val === void 0) {
|
|
2178
2255
|
const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
|
|
@@ -2192,11 +2269,56 @@ function __tnEvalIrNode2(node, ctx, baseOffset) {
|
|
|
2192
2269
|
);
|
|
2193
2270
|
return __tnCheckedAdd2(left, right);
|
|
2194
2271
|
}
|
|
2272
|
+
case "sub":
|
|
2273
|
+
return __tnCheckedSub(
|
|
2274
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2275
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset)
|
|
2276
|
+
);
|
|
2195
2277
|
case "mul":
|
|
2196
2278
|
return __tnCheckedMul2(
|
|
2197
2279
|
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2198
2280
|
__tnEvalIrNode2(node.right, ctx, baseOffset)
|
|
2199
2281
|
);
|
|
2282
|
+
case "div":
|
|
2283
|
+
return __tnCheckedDiv(
|
|
2284
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2285
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset)
|
|
2286
|
+
);
|
|
2287
|
+
case "mod":
|
|
2288
|
+
return __tnCheckedMod(
|
|
2289
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2290
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset)
|
|
2291
|
+
);
|
|
2292
|
+
case "bitAnd":
|
|
2293
|
+
return __tnBitwise(
|
|
2294
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2295
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset),
|
|
2296
|
+
"and"
|
|
2297
|
+
);
|
|
2298
|
+
case "bitOr":
|
|
2299
|
+
return __tnBitwise(
|
|
2300
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2301
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset),
|
|
2302
|
+
"or"
|
|
2303
|
+
);
|
|
2304
|
+
case "bitXor":
|
|
2305
|
+
return __tnBitwise(
|
|
2306
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2307
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset),
|
|
2308
|
+
"xor"
|
|
2309
|
+
);
|
|
2310
|
+
case "leftShift":
|
|
2311
|
+
return __tnCheckedShift(
|
|
2312
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2313
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset),
|
|
2314
|
+
"left"
|
|
2315
|
+
);
|
|
2316
|
+
case "rightShift":
|
|
2317
|
+
return __tnCheckedShift(
|
|
2318
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2319
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset),
|
|
2320
|
+
"right"
|
|
2321
|
+
);
|
|
2200
2322
|
case "align":
|
|
2201
2323
|
return __tnAlign2(__tnEvalIrNode2(node.node, ctx, baseOffset), node.alignment);
|
|
2202
2324
|
case "switch": {
|
|
@@ -2316,7 +2438,7 @@ __tnRegisterDynamicValidate2("Pubkey", (buffer) => {
|
|
|
2316
2438
|
});
|
|
2317
2439
|
var __tn_ir_AmmAddLiquidityInstruction = {
|
|
2318
2440
|
typeName: "AmmAddLiquidityInstruction",
|
|
2319
|
-
root: { op: "const", value:
|
|
2441
|
+
root: { op: "const", value: 42n }
|
|
2320
2442
|
};
|
|
2321
2443
|
var AmmAddLiquidityInstruction = class _AmmAddLiquidityInstruction {
|
|
2322
2444
|
constructor(buffer) {
|
|
@@ -2488,6 +2610,20 @@ var AmmAddLiquidityInstruction = class _AmmAddLiquidityInstruction {
|
|
|
2488
2610
|
set max_amount_mint_two(value) {
|
|
2489
2611
|
this.set_max_amount_mint_two(value);
|
|
2490
2612
|
}
|
|
2613
|
+
get_min_lp_out() {
|
|
2614
|
+
const offset = 34;
|
|
2615
|
+
return this.view.getBigUint64(offset, true);
|
|
2616
|
+
}
|
|
2617
|
+
set_min_lp_out(value) {
|
|
2618
|
+
const offset = 34;
|
|
2619
|
+
this.view.setBigUint64(offset, value, true);
|
|
2620
|
+
}
|
|
2621
|
+
get min_lp_out() {
|
|
2622
|
+
return this.get_min_lp_out();
|
|
2623
|
+
}
|
|
2624
|
+
set min_lp_out(value) {
|
|
2625
|
+
this.set_min_lp_out(value);
|
|
2626
|
+
}
|
|
2491
2627
|
static __tnFootprintInternal(__tnParams) {
|
|
2492
2628
|
return __tnEvalFootprint2(__tn_ir_AmmAddLiquidityInstruction.root, { params: __tnParams });
|
|
2493
2629
|
}
|
|
@@ -2512,11 +2648,11 @@ var AmmAddLiquidityInstruction = class _AmmAddLiquidityInstruction {
|
|
|
2512
2648
|
return __tnBigIntToNumber2(irResult, "AmmAddLiquidityInstruction::footprint");
|
|
2513
2649
|
}
|
|
2514
2650
|
static validate(buffer, _opts) {
|
|
2515
|
-
if (buffer.length <
|
|
2516
|
-
return { ok: true, consumed:
|
|
2651
|
+
if (buffer.length < 42) return { ok: false, code: "tn.buffer_too_small", consumed: 42 };
|
|
2652
|
+
return { ok: true, consumed: 42 };
|
|
2517
2653
|
}
|
|
2518
|
-
static new(pool_account_idx, depositor_account_idx, depositor_token_one_account_idx, depositor_token_two_account_idx, depositor_lp_account_idx, vault_one_account_idx, vault_two_account_idx, lp_mint_account_idx, token_program_account_idx, max_amount_mint_one, max_amount_mint_two) {
|
|
2519
|
-
const buffer = new Uint8Array(
|
|
2654
|
+
static new(pool_account_idx, depositor_account_idx, depositor_token_one_account_idx, depositor_token_two_account_idx, depositor_lp_account_idx, vault_one_account_idx, vault_two_account_idx, lp_mint_account_idx, token_program_account_idx, max_amount_mint_one, max_amount_mint_two, min_lp_out) {
|
|
2655
|
+
const buffer = new Uint8Array(42);
|
|
2520
2656
|
const view = new DataView(buffer.buffer);
|
|
2521
2657
|
view.setUint16(0, pool_account_idx, true);
|
|
2522
2658
|
view.setUint16(2, depositor_account_idx, true);
|
|
@@ -2529,6 +2665,7 @@ var AmmAddLiquidityInstruction = class _AmmAddLiquidityInstruction {
|
|
|
2529
2665
|
view.setUint16(16, token_program_account_idx, true);
|
|
2530
2666
|
view.setBigUint64(18, max_amount_mint_one, true);
|
|
2531
2667
|
view.setBigUint64(26, max_amount_mint_two, true);
|
|
2668
|
+
view.setBigUint64(34, min_lp_out, true);
|
|
2532
2669
|
return new _AmmAddLiquidityInstruction(buffer);
|
|
2533
2670
|
}
|
|
2534
2671
|
static from_array(buffer) {
|
|
@@ -2545,7 +2682,7 @@ var AmmAddLiquidityInstruction = class _AmmAddLiquidityInstruction {
|
|
|
2545
2682
|
};
|
|
2546
2683
|
var AmmAddLiquidityInstructionBuilder = class {
|
|
2547
2684
|
constructor() {
|
|
2548
|
-
this.buffer = new Uint8Array(
|
|
2685
|
+
this.buffer = new Uint8Array(42);
|
|
2549
2686
|
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2550
2687
|
}
|
|
2551
2688
|
set_pool_account_idx(value) {
|
|
@@ -2594,6 +2731,11 @@ var AmmAddLiquidityInstructionBuilder = class {
|
|
|
2594
2731
|
this.view.setBigUint64(26, cast, true);
|
|
2595
2732
|
return this;
|
|
2596
2733
|
}
|
|
2734
|
+
set_min_lp_out(value) {
|
|
2735
|
+
const cast = __tnToBigInt2(value);
|
|
2736
|
+
this.view.setBigUint64(34, cast, true);
|
|
2737
|
+
return this;
|
|
2738
|
+
}
|
|
2597
2739
|
build() {
|
|
2598
2740
|
return this.buffer.slice();
|
|
2599
2741
|
}
|
|
@@ -2727,7 +2869,7 @@ __tnRegisterDynamicValidate2("AmmError", (buffer) => {
|
|
|
2727
2869
|
});
|
|
2728
2870
|
var __tn_ir_AmmSwapInstruction = {
|
|
2729
2871
|
typeName: "AmmSwapInstruction",
|
|
2730
|
-
root: { op: "const", value:
|
|
2872
|
+
root: { op: "const", value: 32n }
|
|
2731
2873
|
};
|
|
2732
2874
|
var AmmSwapInstruction = class _AmmSwapInstruction {
|
|
2733
2875
|
constructor(buffer) {
|
|
@@ -2871,6 +3013,20 @@ var AmmSwapInstruction = class _AmmSwapInstruction {
|
|
|
2871
3013
|
set amount_in(value) {
|
|
2872
3014
|
this.set_amount_in(value);
|
|
2873
3015
|
}
|
|
3016
|
+
get_min_amount_out() {
|
|
3017
|
+
const offset = 24;
|
|
3018
|
+
return this.view.getBigUint64(offset, true);
|
|
3019
|
+
}
|
|
3020
|
+
set_min_amount_out(value) {
|
|
3021
|
+
const offset = 24;
|
|
3022
|
+
this.view.setBigUint64(offset, value, true);
|
|
3023
|
+
}
|
|
3024
|
+
get min_amount_out() {
|
|
3025
|
+
return this.get_min_amount_out();
|
|
3026
|
+
}
|
|
3027
|
+
set min_amount_out(value) {
|
|
3028
|
+
this.set_min_amount_out(value);
|
|
3029
|
+
}
|
|
2874
3030
|
static __tnFootprintInternal(__tnParams) {
|
|
2875
3031
|
return __tnEvalFootprint2(__tn_ir_AmmSwapInstruction.root, { params: __tnParams });
|
|
2876
3032
|
}
|
|
@@ -2895,11 +3051,11 @@ var AmmSwapInstruction = class _AmmSwapInstruction {
|
|
|
2895
3051
|
return __tnBigIntToNumber2(irResult, "AmmSwapInstruction::footprint");
|
|
2896
3052
|
}
|
|
2897
3053
|
static validate(buffer, _opts) {
|
|
2898
|
-
if (buffer.length <
|
|
2899
|
-
return { ok: true, consumed:
|
|
3054
|
+
if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
|
|
3055
|
+
return { ok: true, consumed: 32 };
|
|
2900
3056
|
}
|
|
2901
|
-
static new(pool_account_idx, user_transfer_authority_idx, user_input_account_idx, user_output_account_idx, vault_input_account_idx, vault_output_account_idx, lp_mint_account_idx, token_program_account_idx, amount_in) {
|
|
2902
|
-
const buffer = new Uint8Array(
|
|
3057
|
+
static new(pool_account_idx, user_transfer_authority_idx, user_input_account_idx, user_output_account_idx, vault_input_account_idx, vault_output_account_idx, lp_mint_account_idx, token_program_account_idx, amount_in, min_amount_out) {
|
|
3058
|
+
const buffer = new Uint8Array(32);
|
|
2903
3059
|
const view = new DataView(buffer.buffer);
|
|
2904
3060
|
view.setUint16(0, pool_account_idx, true);
|
|
2905
3061
|
view.setUint16(2, user_transfer_authority_idx, true);
|
|
@@ -2910,6 +3066,7 @@ var AmmSwapInstruction = class _AmmSwapInstruction {
|
|
|
2910
3066
|
view.setUint16(12, lp_mint_account_idx, true);
|
|
2911
3067
|
view.setUint16(14, token_program_account_idx, true);
|
|
2912
3068
|
view.setBigUint64(16, amount_in, true);
|
|
3069
|
+
view.setBigUint64(24, min_amount_out, true);
|
|
2913
3070
|
return new _AmmSwapInstruction(buffer);
|
|
2914
3071
|
}
|
|
2915
3072
|
static from_array(buffer) {
|
|
@@ -2926,7 +3083,7 @@ var AmmSwapInstruction = class _AmmSwapInstruction {
|
|
|
2926
3083
|
};
|
|
2927
3084
|
var AmmSwapInstructionBuilder = class {
|
|
2928
3085
|
constructor() {
|
|
2929
|
-
this.buffer = new Uint8Array(
|
|
3086
|
+
this.buffer = new Uint8Array(32);
|
|
2930
3087
|
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2931
3088
|
}
|
|
2932
3089
|
set_pool_account_idx(value) {
|
|
@@ -2966,6 +3123,11 @@ var AmmSwapInstructionBuilder = class {
|
|
|
2966
3123
|
this.view.setBigUint64(16, cast, true);
|
|
2967
3124
|
return this;
|
|
2968
3125
|
}
|
|
3126
|
+
set_min_amount_out(value) {
|
|
3127
|
+
const cast = __tnToBigInt2(value);
|
|
3128
|
+
this.view.setBigUint64(24, cast, true);
|
|
3129
|
+
return this;
|
|
3130
|
+
}
|
|
2969
3131
|
build() {
|
|
2970
3132
|
return this.buffer.slice();
|
|
2971
3133
|
}
|
|
@@ -2989,7 +3151,7 @@ __tnRegisterDynamicValidate2("AmmSwapInstruction", (buffer) => {
|
|
|
2989
3151
|
});
|
|
2990
3152
|
var __tn_ir_AmmWithdrawLiquidityInstruction = {
|
|
2991
3153
|
typeName: "AmmWithdrawLiquidityInstruction",
|
|
2992
|
-
root: { op: "const", value:
|
|
3154
|
+
root: { op: "const", value: 42n }
|
|
2993
3155
|
};
|
|
2994
3156
|
var AmmWithdrawLiquidityInstruction = class _AmmWithdrawLiquidityInstruction {
|
|
2995
3157
|
constructor(buffer) {
|
|
@@ -3147,6 +3309,34 @@ var AmmWithdrawLiquidityInstruction = class _AmmWithdrawLiquidityInstruction {
|
|
|
3147
3309
|
set lp_amount(value) {
|
|
3148
3310
|
this.set_lp_amount(value);
|
|
3149
3311
|
}
|
|
3312
|
+
get_min_amount_one_out() {
|
|
3313
|
+
const offset = 26;
|
|
3314
|
+
return this.view.getBigUint64(offset, true);
|
|
3315
|
+
}
|
|
3316
|
+
set_min_amount_one_out(value) {
|
|
3317
|
+
const offset = 26;
|
|
3318
|
+
this.view.setBigUint64(offset, value, true);
|
|
3319
|
+
}
|
|
3320
|
+
get min_amount_one_out() {
|
|
3321
|
+
return this.get_min_amount_one_out();
|
|
3322
|
+
}
|
|
3323
|
+
set min_amount_one_out(value) {
|
|
3324
|
+
this.set_min_amount_one_out(value);
|
|
3325
|
+
}
|
|
3326
|
+
get_min_amount_two_out() {
|
|
3327
|
+
const offset = 34;
|
|
3328
|
+
return this.view.getBigUint64(offset, true);
|
|
3329
|
+
}
|
|
3330
|
+
set_min_amount_two_out(value) {
|
|
3331
|
+
const offset = 34;
|
|
3332
|
+
this.view.setBigUint64(offset, value, true);
|
|
3333
|
+
}
|
|
3334
|
+
get min_amount_two_out() {
|
|
3335
|
+
return this.get_min_amount_two_out();
|
|
3336
|
+
}
|
|
3337
|
+
set min_amount_two_out(value) {
|
|
3338
|
+
this.set_min_amount_two_out(value);
|
|
3339
|
+
}
|
|
3150
3340
|
static __tnFootprintInternal(__tnParams) {
|
|
3151
3341
|
return __tnEvalFootprint2(__tn_ir_AmmWithdrawLiquidityInstruction.root, { params: __tnParams });
|
|
3152
3342
|
}
|
|
@@ -3171,11 +3361,11 @@ var AmmWithdrawLiquidityInstruction = class _AmmWithdrawLiquidityInstruction {
|
|
|
3171
3361
|
return __tnBigIntToNumber2(irResult, "AmmWithdrawLiquidityInstruction::footprint");
|
|
3172
3362
|
}
|
|
3173
3363
|
static validate(buffer, _opts) {
|
|
3174
|
-
if (buffer.length <
|
|
3175
|
-
return { ok: true, consumed:
|
|
3364
|
+
if (buffer.length < 42) return { ok: false, code: "tn.buffer_too_small", consumed: 42 };
|
|
3365
|
+
return { ok: true, consumed: 42 };
|
|
3176
3366
|
}
|
|
3177
|
-
static new(pool_account_idx, withdrawer_account_idx, withdrawer_token_one_account_idx, withdrawer_token_two_account_idx, withdrawer_lp_account_idx, vault_one_account_idx, vault_two_account_idx, lp_mint_account_idx, token_program_account_idx, lp_amount) {
|
|
3178
|
-
const buffer = new Uint8Array(
|
|
3367
|
+
static new(pool_account_idx, withdrawer_account_idx, withdrawer_token_one_account_idx, withdrawer_token_two_account_idx, withdrawer_lp_account_idx, vault_one_account_idx, vault_two_account_idx, lp_mint_account_idx, token_program_account_idx, lp_amount, min_amount_one_out, min_amount_two_out) {
|
|
3368
|
+
const buffer = new Uint8Array(42);
|
|
3179
3369
|
const view = new DataView(buffer.buffer);
|
|
3180
3370
|
view.setUint16(0, pool_account_idx, true);
|
|
3181
3371
|
view.setUint16(2, withdrawer_account_idx, true);
|
|
@@ -3187,6 +3377,8 @@ var AmmWithdrawLiquidityInstruction = class _AmmWithdrawLiquidityInstruction {
|
|
|
3187
3377
|
view.setUint16(14, lp_mint_account_idx, true);
|
|
3188
3378
|
view.setUint16(16, token_program_account_idx, true);
|
|
3189
3379
|
view.setBigUint64(18, lp_amount, true);
|
|
3380
|
+
view.setBigUint64(26, min_amount_one_out, true);
|
|
3381
|
+
view.setBigUint64(34, min_amount_two_out, true);
|
|
3190
3382
|
return new _AmmWithdrawLiquidityInstruction(buffer);
|
|
3191
3383
|
}
|
|
3192
3384
|
static from_array(buffer) {
|
|
@@ -3203,7 +3395,7 @@ var AmmWithdrawLiquidityInstruction = class _AmmWithdrawLiquidityInstruction {
|
|
|
3203
3395
|
};
|
|
3204
3396
|
var AmmWithdrawLiquidityInstructionBuilder = class {
|
|
3205
3397
|
constructor() {
|
|
3206
|
-
this.buffer = new Uint8Array(
|
|
3398
|
+
this.buffer = new Uint8Array(42);
|
|
3207
3399
|
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
3208
3400
|
}
|
|
3209
3401
|
set_pool_account_idx(value) {
|
|
@@ -3247,6 +3439,16 @@ var AmmWithdrawLiquidityInstructionBuilder = class {
|
|
|
3247
3439
|
this.view.setBigUint64(18, cast, true);
|
|
3248
3440
|
return this;
|
|
3249
3441
|
}
|
|
3442
|
+
set_min_amount_one_out(value) {
|
|
3443
|
+
const cast = __tnToBigInt2(value);
|
|
3444
|
+
this.view.setBigUint64(26, cast, true);
|
|
3445
|
+
return this;
|
|
3446
|
+
}
|
|
3447
|
+
set_min_amount_two_out(value) {
|
|
3448
|
+
const cast = __tnToBigInt2(value);
|
|
3449
|
+
this.view.setBigUint64(34, cast, true);
|
|
3450
|
+
return this;
|
|
3451
|
+
}
|
|
3250
3452
|
build() {
|
|
3251
3453
|
return this.buffer.slice();
|
|
3252
3454
|
}
|
|
@@ -4815,21 +5017,21 @@ _AmmInstruction.payloadVariantDescriptors = Object.freeze([
|
|
|
4815
5017
|
{
|
|
4816
5018
|
name: "add_liquidity",
|
|
4817
5019
|
tag: 1,
|
|
4818
|
-
payloadSize:
|
|
5020
|
+
payloadSize: 42,
|
|
4819
5021
|
payloadType: "AmmInstruction::payload::add_liquidity",
|
|
4820
5022
|
createPayloadBuilder: () => __tnMaybeCallBuilder(AmmAddLiquidityInstruction)
|
|
4821
5023
|
},
|
|
4822
5024
|
{
|
|
4823
5025
|
name: "withdraw_liquidity",
|
|
4824
5026
|
tag: 2,
|
|
4825
|
-
payloadSize:
|
|
5027
|
+
payloadSize: 42,
|
|
4826
5028
|
payloadType: "AmmInstruction::payload::withdraw_liquidity",
|
|
4827
5029
|
createPayloadBuilder: () => __tnMaybeCallBuilder(AmmWithdrawLiquidityInstruction)
|
|
4828
5030
|
},
|
|
4829
5031
|
{
|
|
4830
5032
|
name: "swap",
|
|
4831
5033
|
tag: 3,
|
|
4832
|
-
payloadSize:
|
|
5034
|
+
payloadSize: 32,
|
|
4833
5035
|
payloadType: "AmmInstruction::payload::swap",
|
|
4834
5036
|
createPayloadBuilder: () => __tnMaybeCallBuilder(AmmSwapInstruction)
|
|
4835
5037
|
}
|
|
@@ -4878,7 +5080,7 @@ var AmmInstructionBuilder = class {
|
|
|
4878
5080
|
this.__tnLastParams = null;
|
|
4879
5081
|
}
|
|
4880
5082
|
__tnAssign_discriminant(value) {
|
|
4881
|
-
this.__tnField_discriminant = value
|
|
5083
|
+
this.__tnField_discriminant = value;
|
|
4882
5084
|
this.__tnInvalidate();
|
|
4883
5085
|
}
|
|
4884
5086
|
set_discriminant(value) {
|
|
@@ -6172,7 +6374,7 @@ var AmmEventBuilder = class {
|
|
|
6172
6374
|
this.__tnLastParams = null;
|
|
6173
6375
|
}
|
|
6174
6376
|
__tnAssign_event_type(value) {
|
|
6175
|
-
this.__tnField_event_type = value
|
|
6377
|
+
this.__tnField_event_type = value;
|
|
6176
6378
|
this.__tnInvalidate();
|
|
6177
6379
|
}
|
|
6178
6380
|
set_event_type(value) {
|
|
@@ -6301,7 +6503,8 @@ var AMM_ERROR_LABELS = {
|
|
|
6301
6503
|
16: "Vault two init failed",
|
|
6302
6504
|
17: "Liquidity bounds",
|
|
6303
6505
|
18: "Vault mismatch",
|
|
6304
|
-
19: "LP mint mismatch"
|
|
6506
|
+
19: "LP mint mismatch",
|
|
6507
|
+
20: "Slippage exceeded"
|
|
6305
6508
|
};
|
|
6306
6509
|
var PUBKEY_LENGTH2 = 32;
|
|
6307
6510
|
var LP_MINT_SEED_LABEL = asciiBytes("lp_mint");
|
|
@@ -6376,21 +6579,25 @@ function createAddLiquidityInstruction(args) {
|
|
|
6376
6579
|
return async (context) => {
|
|
6377
6580
|
assertU64(args.maxAmountMintOne, "maxAmountMintOne");
|
|
6378
6581
|
assertU64(args.maxAmountMintTwo, "maxAmountMintTwo");
|
|
6379
|
-
|
|
6582
|
+
assertU64(args.minLpOut, "minLpOut");
|
|
6583
|
+
const payload = new AmmAddLiquidityInstructionBuilder().set_pool_account_idx(accountIndex(context, args.poolAccountBytes)).set_depositor_account_idx(accountIndex(context, args.depositorAccountBytes)).set_depositor_token_one_account_idx(accountIndex(context, args.depositorTokenOneAccountBytes)).set_depositor_token_two_account_idx(accountIndex(context, args.depositorTokenTwoAccountBytes)).set_depositor_lp_account_idx(accountIndex(context, args.depositorLpAccountBytes)).set_vault_one_account_idx(accountIndex(context, args.vaultOneAccountBytes)).set_vault_two_account_idx(accountIndex(context, args.vaultTwoAccountBytes)).set_lp_mint_account_idx(accountIndex(context, args.lpMintAccountBytes)).set_token_program_account_idx(accountIndex(context, args.tokenProgramAccountBytes)).set_max_amount_mint_one(args.maxAmountMintOne).set_max_amount_mint_two(args.maxAmountMintTwo).set_min_lp_out(args.minLpOut).build();
|
|
6380
6584
|
return buildAmmInstruction("add_liquidity", payload);
|
|
6381
6585
|
};
|
|
6382
6586
|
}
|
|
6383
6587
|
function createWithdrawLiquidityInstruction(args) {
|
|
6384
6588
|
return async (context) => {
|
|
6385
6589
|
assertU64(args.lpAmount, "lpAmount");
|
|
6386
|
-
|
|
6590
|
+
assertU64(args.minAmountOneOut, "minAmountOneOut");
|
|
6591
|
+
assertU64(args.minAmountTwoOut, "minAmountTwoOut");
|
|
6592
|
+
const payload = new AmmWithdrawLiquidityInstructionBuilder().set_pool_account_idx(accountIndex(context, args.poolAccountBytes)).set_withdrawer_account_idx(accountIndex(context, args.withdrawerAccountBytes)).set_withdrawer_token_one_account_idx(accountIndex(context, args.withdrawerTokenOneAccountBytes)).set_withdrawer_token_two_account_idx(accountIndex(context, args.withdrawerTokenTwoAccountBytes)).set_withdrawer_lp_account_idx(accountIndex(context, args.withdrawerLpAccountBytes)).set_vault_one_account_idx(accountIndex(context, args.vaultOneAccountBytes)).set_vault_two_account_idx(accountIndex(context, args.vaultTwoAccountBytes)).set_lp_mint_account_idx(accountIndex(context, args.lpMintAccountBytes)).set_token_program_account_idx(accountIndex(context, args.tokenProgramAccountBytes)).set_lp_amount(args.lpAmount).set_min_amount_one_out(args.minAmountOneOut).set_min_amount_two_out(args.minAmountTwoOut).build();
|
|
6387
6593
|
return buildAmmInstruction("withdraw_liquidity", payload);
|
|
6388
6594
|
};
|
|
6389
6595
|
}
|
|
6390
6596
|
function createSwapInstruction(args) {
|
|
6391
6597
|
return async (context) => {
|
|
6392
6598
|
assertU64(args.amountIn, "amountIn");
|
|
6393
|
-
|
|
6599
|
+
assertU64(args.minAmountOut, "minAmountOut");
|
|
6600
|
+
const payload = new AmmSwapInstructionBuilder().set_pool_account_idx(accountIndex(context, args.poolAccountBytes)).set_user_transfer_authority_idx(accountIndex(context, args.userTransferAuthorityBytes)).set_user_input_account_idx(accountIndex(context, args.userInputAccountBytes)).set_user_output_account_idx(accountIndex(context, args.userOutputAccountBytes)).set_vault_input_account_idx(accountIndex(context, args.vaultInputAccountBytes)).set_vault_output_account_idx(accountIndex(context, args.vaultOutputAccountBytes)).set_lp_mint_account_idx(accountIndex(context, args.lpMintAccountBytes)).set_token_program_account_idx(accountIndex(context, args.tokenProgramAccountBytes)).set_amount_in(args.amountIn).set_min_amount_out(args.minAmountOut).build();
|
|
6394
6601
|
return buildAmmInstruction("swap", payload);
|
|
6395
6602
|
};
|
|
6396
6603
|
}
|
|
@@ -6438,7 +6645,7 @@ function assertU16(value, label) {
|
|
|
6438
6645
|
}
|
|
6439
6646
|
}
|
|
6440
6647
|
function assertU64(value, label) {
|
|
6441
|
-
if (value < 0n || value > 0xffffffffffffffffn) {
|
|
6648
|
+
if (typeof value !== "bigint" || value < 0n || value > 0xffffffffffffffffn) {
|
|
6442
6649
|
throw new Error(`${label} must be between 0 and 18446744073709551615`);
|
|
6443
6650
|
}
|
|
6444
6651
|
}
|