@thru/programs 0.3.15 → 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.js
CHANGED
|
@@ -1845,6 +1845,31 @@ function __tnCheckedAdd2(lhs, rhs) {
|
|
|
1845
1845
|
}
|
|
1846
1846
|
return sum;
|
|
1847
1847
|
}
|
|
1848
|
+
function __tnCheckedSub(lhs, rhs) {
|
|
1849
|
+
if (__tnHasNativeBigInt2) {
|
|
1850
|
+
const result = lhs - rhs;
|
|
1851
|
+
if (result < BigInt(0)) {
|
|
1852
|
+
__tnRaiseIrError2(
|
|
1853
|
+
"tn.ir.overflow",
|
|
1854
|
+
"IR runtime detected negative size via subtraction"
|
|
1855
|
+
);
|
|
1856
|
+
}
|
|
1857
|
+
return result;
|
|
1858
|
+
}
|
|
1859
|
+
const left = lhs;
|
|
1860
|
+
const right = rhs;
|
|
1861
|
+
const diff = left - right;
|
|
1862
|
+
if (diff < 0 || !Number.isFinite(diff)) {
|
|
1863
|
+
__tnRaiseIrError2(
|
|
1864
|
+
"tn.ir.overflow",
|
|
1865
|
+
"IR runtime detected invalid subtraction result"
|
|
1866
|
+
);
|
|
1867
|
+
}
|
|
1868
|
+
if (!Number.isSafeInteger(diff)) {
|
|
1869
|
+
__tnWarnOnce2("[thru-net] Precision loss while polyfilling BigInt subtraction");
|
|
1870
|
+
}
|
|
1871
|
+
return diff;
|
|
1872
|
+
}
|
|
1848
1873
|
function __tnCheckedMul2(lhs, rhs) {
|
|
1849
1874
|
if (__tnHasNativeBigInt2) {
|
|
1850
1875
|
const result = lhs * rhs;
|
|
@@ -1872,6 +1897,55 @@ function __tnCheckedMul2(lhs, rhs) {
|
|
|
1872
1897
|
}
|
|
1873
1898
|
return product;
|
|
1874
1899
|
}
|
|
1900
|
+
function __tnCheckedDiv(lhs, rhs) {
|
|
1901
|
+
if (__tnBigIntEquals2(rhs, __tnToBigInt2(0))) {
|
|
1902
|
+
__tnRaiseIrError2("tn.ir.overflow", "IR runtime division by zero");
|
|
1903
|
+
}
|
|
1904
|
+
if (__tnHasNativeBigInt2) return lhs / rhs;
|
|
1905
|
+
const quotient = Math.floor(lhs / rhs);
|
|
1906
|
+
return quotient;
|
|
1907
|
+
}
|
|
1908
|
+
function __tnCheckedMod(lhs, rhs) {
|
|
1909
|
+
if (__tnBigIntEquals2(rhs, __tnToBigInt2(0))) {
|
|
1910
|
+
__tnRaiseIrError2("tn.ir.overflow", "IR runtime modulo by zero");
|
|
1911
|
+
}
|
|
1912
|
+
if (__tnHasNativeBigInt2) return lhs % rhs;
|
|
1913
|
+
return lhs % rhs;
|
|
1914
|
+
}
|
|
1915
|
+
function __tnBitwise(lhs, rhs, op) {
|
|
1916
|
+
if (__tnHasNativeBigInt2) {
|
|
1917
|
+
if (op === "and") return lhs & rhs;
|
|
1918
|
+
if (op === "or") return lhs | rhs;
|
|
1919
|
+
return lhs ^ rhs;
|
|
1920
|
+
}
|
|
1921
|
+
const left = lhs;
|
|
1922
|
+
const right = rhs;
|
|
1923
|
+
const maxU32 = 4294967295;
|
|
1924
|
+
if (!Number.isInteger(left) || !Number.isInteger(right) || left < 0 || right < 0 || left > maxU32 || right > maxU32) {
|
|
1925
|
+
__tnRaiseIrError2(
|
|
1926
|
+
"tn.ir.overflow",
|
|
1927
|
+
"IR runtime bitwise operation requires BigInt for values outside u32 range"
|
|
1928
|
+
);
|
|
1929
|
+
}
|
|
1930
|
+
const result = op === "and" ? left & right : op === "or" ? left | right : left ^ right;
|
|
1931
|
+
return result >>> 0;
|
|
1932
|
+
}
|
|
1933
|
+
function __tnCheckedShift(lhs, rhs, direction) {
|
|
1934
|
+
const amount = __tnBigIntToNumber2(rhs, "IR shift amount");
|
|
1935
|
+
if (amount < 0 || amount >= 64 || !Number.isInteger(amount)) {
|
|
1936
|
+
__tnRaiseIrError2("tn.ir.overflow", "IR runtime invalid shift amount");
|
|
1937
|
+
}
|
|
1938
|
+
if (__tnHasNativeBigInt2) {
|
|
1939
|
+
const shift = BigInt(amount);
|
|
1940
|
+
return direction === "left" ? lhs << shift : lhs >> shift;
|
|
1941
|
+
}
|
|
1942
|
+
const value = lhs;
|
|
1943
|
+
const result = direction === "left" ? value * 2 ** amount : Math.floor(value / 2 ** amount);
|
|
1944
|
+
if (!Number.isSafeInteger(result)) {
|
|
1945
|
+
__tnWarnOnce2("[thru-net] Precision loss while polyfilling BigInt shift");
|
|
1946
|
+
}
|
|
1947
|
+
return result;
|
|
1948
|
+
}
|
|
1875
1949
|
function __tnAlign2(value, alignment) {
|
|
1876
1950
|
if (alignment <= 1) return value;
|
|
1877
1951
|
const alignBig = __tnToBigInt2(alignment);
|
|
@@ -2065,6 +2139,9 @@ function __tnEvalIrNode2(node, ctx, baseOffset) {
|
|
|
2065
2139
|
case "const":
|
|
2066
2140
|
return node.value;
|
|
2067
2141
|
case "field": {
|
|
2142
|
+
if (node.param === "__buffer_size" && ctx.buffer) {
|
|
2143
|
+
return __tnToBigInt2(ctx.buffer.length);
|
|
2144
|
+
}
|
|
2068
2145
|
const val = ctx.params[node.param];
|
|
2069
2146
|
if (val === void 0) {
|
|
2070
2147
|
const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
|
|
@@ -2084,11 +2161,56 @@ function __tnEvalIrNode2(node, ctx, baseOffset) {
|
|
|
2084
2161
|
);
|
|
2085
2162
|
return __tnCheckedAdd2(left, right);
|
|
2086
2163
|
}
|
|
2164
|
+
case "sub":
|
|
2165
|
+
return __tnCheckedSub(
|
|
2166
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2167
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset)
|
|
2168
|
+
);
|
|
2087
2169
|
case "mul":
|
|
2088
2170
|
return __tnCheckedMul2(
|
|
2089
2171
|
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2090
2172
|
__tnEvalIrNode2(node.right, ctx, baseOffset)
|
|
2091
2173
|
);
|
|
2174
|
+
case "div":
|
|
2175
|
+
return __tnCheckedDiv(
|
|
2176
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2177
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset)
|
|
2178
|
+
);
|
|
2179
|
+
case "mod":
|
|
2180
|
+
return __tnCheckedMod(
|
|
2181
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2182
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset)
|
|
2183
|
+
);
|
|
2184
|
+
case "bitAnd":
|
|
2185
|
+
return __tnBitwise(
|
|
2186
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2187
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset),
|
|
2188
|
+
"and"
|
|
2189
|
+
);
|
|
2190
|
+
case "bitOr":
|
|
2191
|
+
return __tnBitwise(
|
|
2192
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2193
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset),
|
|
2194
|
+
"or"
|
|
2195
|
+
);
|
|
2196
|
+
case "bitXor":
|
|
2197
|
+
return __tnBitwise(
|
|
2198
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2199
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset),
|
|
2200
|
+
"xor"
|
|
2201
|
+
);
|
|
2202
|
+
case "leftShift":
|
|
2203
|
+
return __tnCheckedShift(
|
|
2204
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2205
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset),
|
|
2206
|
+
"left"
|
|
2207
|
+
);
|
|
2208
|
+
case "rightShift":
|
|
2209
|
+
return __tnCheckedShift(
|
|
2210
|
+
__tnEvalIrNode2(node.left, ctx, baseOffset),
|
|
2211
|
+
__tnEvalIrNode2(node.right, ctx, baseOffset),
|
|
2212
|
+
"right"
|
|
2213
|
+
);
|
|
2092
2214
|
case "align":
|
|
2093
2215
|
return __tnAlign2(__tnEvalIrNode2(node.node, ctx, baseOffset), node.alignment);
|
|
2094
2216
|
case "switch": {
|
|
@@ -2208,7 +2330,7 @@ __tnRegisterDynamicValidate2("Pubkey", (buffer) => {
|
|
|
2208
2330
|
});
|
|
2209
2331
|
var __tn_ir_AmmAddLiquidityInstruction = {
|
|
2210
2332
|
typeName: "AmmAddLiquidityInstruction",
|
|
2211
|
-
root: { op: "const", value:
|
|
2333
|
+
root: { op: "const", value: 42n }
|
|
2212
2334
|
};
|
|
2213
2335
|
var AmmAddLiquidityInstruction = class _AmmAddLiquidityInstruction {
|
|
2214
2336
|
constructor(buffer) {
|
|
@@ -2380,6 +2502,20 @@ var AmmAddLiquidityInstruction = class _AmmAddLiquidityInstruction {
|
|
|
2380
2502
|
set max_amount_mint_two(value) {
|
|
2381
2503
|
this.set_max_amount_mint_two(value);
|
|
2382
2504
|
}
|
|
2505
|
+
get_min_lp_out() {
|
|
2506
|
+
const offset = 34;
|
|
2507
|
+
return this.view.getBigUint64(offset, true);
|
|
2508
|
+
}
|
|
2509
|
+
set_min_lp_out(value) {
|
|
2510
|
+
const offset = 34;
|
|
2511
|
+
this.view.setBigUint64(offset, value, true);
|
|
2512
|
+
}
|
|
2513
|
+
get min_lp_out() {
|
|
2514
|
+
return this.get_min_lp_out();
|
|
2515
|
+
}
|
|
2516
|
+
set min_lp_out(value) {
|
|
2517
|
+
this.set_min_lp_out(value);
|
|
2518
|
+
}
|
|
2383
2519
|
static __tnFootprintInternal(__tnParams) {
|
|
2384
2520
|
return __tnEvalFootprint2(__tn_ir_AmmAddLiquidityInstruction.root, { params: __tnParams });
|
|
2385
2521
|
}
|
|
@@ -2404,11 +2540,11 @@ var AmmAddLiquidityInstruction = class _AmmAddLiquidityInstruction {
|
|
|
2404
2540
|
return __tnBigIntToNumber2(irResult, "AmmAddLiquidityInstruction::footprint");
|
|
2405
2541
|
}
|
|
2406
2542
|
static validate(buffer, _opts) {
|
|
2407
|
-
if (buffer.length <
|
|
2408
|
-
return { ok: true, consumed:
|
|
2543
|
+
if (buffer.length < 42) return { ok: false, code: "tn.buffer_too_small", consumed: 42 };
|
|
2544
|
+
return { ok: true, consumed: 42 };
|
|
2409
2545
|
}
|
|
2410
|
-
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) {
|
|
2411
|
-
const buffer = new Uint8Array(
|
|
2546
|
+
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) {
|
|
2547
|
+
const buffer = new Uint8Array(42);
|
|
2412
2548
|
const view = new DataView(buffer.buffer);
|
|
2413
2549
|
view.setUint16(0, pool_account_idx, true);
|
|
2414
2550
|
view.setUint16(2, depositor_account_idx, true);
|
|
@@ -2421,6 +2557,7 @@ var AmmAddLiquidityInstruction = class _AmmAddLiquidityInstruction {
|
|
|
2421
2557
|
view.setUint16(16, token_program_account_idx, true);
|
|
2422
2558
|
view.setBigUint64(18, max_amount_mint_one, true);
|
|
2423
2559
|
view.setBigUint64(26, max_amount_mint_two, true);
|
|
2560
|
+
view.setBigUint64(34, min_lp_out, true);
|
|
2424
2561
|
return new _AmmAddLiquidityInstruction(buffer);
|
|
2425
2562
|
}
|
|
2426
2563
|
static from_array(buffer) {
|
|
@@ -2437,7 +2574,7 @@ var AmmAddLiquidityInstruction = class _AmmAddLiquidityInstruction {
|
|
|
2437
2574
|
};
|
|
2438
2575
|
var AmmAddLiquidityInstructionBuilder = class {
|
|
2439
2576
|
constructor() {
|
|
2440
|
-
this.buffer = new Uint8Array(
|
|
2577
|
+
this.buffer = new Uint8Array(42);
|
|
2441
2578
|
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2442
2579
|
}
|
|
2443
2580
|
set_pool_account_idx(value) {
|
|
@@ -2486,6 +2623,11 @@ var AmmAddLiquidityInstructionBuilder = class {
|
|
|
2486
2623
|
this.view.setBigUint64(26, cast, true);
|
|
2487
2624
|
return this;
|
|
2488
2625
|
}
|
|
2626
|
+
set_min_lp_out(value) {
|
|
2627
|
+
const cast = __tnToBigInt2(value);
|
|
2628
|
+
this.view.setBigUint64(34, cast, true);
|
|
2629
|
+
return this;
|
|
2630
|
+
}
|
|
2489
2631
|
build() {
|
|
2490
2632
|
return this.buffer.slice();
|
|
2491
2633
|
}
|
|
@@ -2619,7 +2761,7 @@ __tnRegisterDynamicValidate2("AmmError", (buffer) => {
|
|
|
2619
2761
|
});
|
|
2620
2762
|
var __tn_ir_AmmSwapInstruction = {
|
|
2621
2763
|
typeName: "AmmSwapInstruction",
|
|
2622
|
-
root: { op: "const", value:
|
|
2764
|
+
root: { op: "const", value: 32n }
|
|
2623
2765
|
};
|
|
2624
2766
|
var AmmSwapInstruction = class _AmmSwapInstruction {
|
|
2625
2767
|
constructor(buffer) {
|
|
@@ -2763,6 +2905,20 @@ var AmmSwapInstruction = class _AmmSwapInstruction {
|
|
|
2763
2905
|
set amount_in(value) {
|
|
2764
2906
|
this.set_amount_in(value);
|
|
2765
2907
|
}
|
|
2908
|
+
get_min_amount_out() {
|
|
2909
|
+
const offset = 24;
|
|
2910
|
+
return this.view.getBigUint64(offset, true);
|
|
2911
|
+
}
|
|
2912
|
+
set_min_amount_out(value) {
|
|
2913
|
+
const offset = 24;
|
|
2914
|
+
this.view.setBigUint64(offset, value, true);
|
|
2915
|
+
}
|
|
2916
|
+
get min_amount_out() {
|
|
2917
|
+
return this.get_min_amount_out();
|
|
2918
|
+
}
|
|
2919
|
+
set min_amount_out(value) {
|
|
2920
|
+
this.set_min_amount_out(value);
|
|
2921
|
+
}
|
|
2766
2922
|
static __tnFootprintInternal(__tnParams) {
|
|
2767
2923
|
return __tnEvalFootprint2(__tn_ir_AmmSwapInstruction.root, { params: __tnParams });
|
|
2768
2924
|
}
|
|
@@ -2787,11 +2943,11 @@ var AmmSwapInstruction = class _AmmSwapInstruction {
|
|
|
2787
2943
|
return __tnBigIntToNumber2(irResult, "AmmSwapInstruction::footprint");
|
|
2788
2944
|
}
|
|
2789
2945
|
static validate(buffer, _opts) {
|
|
2790
|
-
if (buffer.length <
|
|
2791
|
-
return { ok: true, consumed:
|
|
2946
|
+
if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
|
|
2947
|
+
return { ok: true, consumed: 32 };
|
|
2792
2948
|
}
|
|
2793
|
-
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) {
|
|
2794
|
-
const buffer = new Uint8Array(
|
|
2949
|
+
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) {
|
|
2950
|
+
const buffer = new Uint8Array(32);
|
|
2795
2951
|
const view = new DataView(buffer.buffer);
|
|
2796
2952
|
view.setUint16(0, pool_account_idx, true);
|
|
2797
2953
|
view.setUint16(2, user_transfer_authority_idx, true);
|
|
@@ -2802,6 +2958,7 @@ var AmmSwapInstruction = class _AmmSwapInstruction {
|
|
|
2802
2958
|
view.setUint16(12, lp_mint_account_idx, true);
|
|
2803
2959
|
view.setUint16(14, token_program_account_idx, true);
|
|
2804
2960
|
view.setBigUint64(16, amount_in, true);
|
|
2961
|
+
view.setBigUint64(24, min_amount_out, true);
|
|
2805
2962
|
return new _AmmSwapInstruction(buffer);
|
|
2806
2963
|
}
|
|
2807
2964
|
static from_array(buffer) {
|
|
@@ -2818,7 +2975,7 @@ var AmmSwapInstruction = class _AmmSwapInstruction {
|
|
|
2818
2975
|
};
|
|
2819
2976
|
var AmmSwapInstructionBuilder = class {
|
|
2820
2977
|
constructor() {
|
|
2821
|
-
this.buffer = new Uint8Array(
|
|
2978
|
+
this.buffer = new Uint8Array(32);
|
|
2822
2979
|
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2823
2980
|
}
|
|
2824
2981
|
set_pool_account_idx(value) {
|
|
@@ -2858,6 +3015,11 @@ var AmmSwapInstructionBuilder = class {
|
|
|
2858
3015
|
this.view.setBigUint64(16, cast, true);
|
|
2859
3016
|
return this;
|
|
2860
3017
|
}
|
|
3018
|
+
set_min_amount_out(value) {
|
|
3019
|
+
const cast = __tnToBigInt2(value);
|
|
3020
|
+
this.view.setBigUint64(24, cast, true);
|
|
3021
|
+
return this;
|
|
3022
|
+
}
|
|
2861
3023
|
build() {
|
|
2862
3024
|
return this.buffer.slice();
|
|
2863
3025
|
}
|
|
@@ -2881,7 +3043,7 @@ __tnRegisterDynamicValidate2("AmmSwapInstruction", (buffer) => {
|
|
|
2881
3043
|
});
|
|
2882
3044
|
var __tn_ir_AmmWithdrawLiquidityInstruction = {
|
|
2883
3045
|
typeName: "AmmWithdrawLiquidityInstruction",
|
|
2884
|
-
root: { op: "const", value:
|
|
3046
|
+
root: { op: "const", value: 42n }
|
|
2885
3047
|
};
|
|
2886
3048
|
var AmmWithdrawLiquidityInstruction = class _AmmWithdrawLiquidityInstruction {
|
|
2887
3049
|
constructor(buffer) {
|
|
@@ -3039,6 +3201,34 @@ var AmmWithdrawLiquidityInstruction = class _AmmWithdrawLiquidityInstruction {
|
|
|
3039
3201
|
set lp_amount(value) {
|
|
3040
3202
|
this.set_lp_amount(value);
|
|
3041
3203
|
}
|
|
3204
|
+
get_min_amount_one_out() {
|
|
3205
|
+
const offset = 26;
|
|
3206
|
+
return this.view.getBigUint64(offset, true);
|
|
3207
|
+
}
|
|
3208
|
+
set_min_amount_one_out(value) {
|
|
3209
|
+
const offset = 26;
|
|
3210
|
+
this.view.setBigUint64(offset, value, true);
|
|
3211
|
+
}
|
|
3212
|
+
get min_amount_one_out() {
|
|
3213
|
+
return this.get_min_amount_one_out();
|
|
3214
|
+
}
|
|
3215
|
+
set min_amount_one_out(value) {
|
|
3216
|
+
this.set_min_amount_one_out(value);
|
|
3217
|
+
}
|
|
3218
|
+
get_min_amount_two_out() {
|
|
3219
|
+
const offset = 34;
|
|
3220
|
+
return this.view.getBigUint64(offset, true);
|
|
3221
|
+
}
|
|
3222
|
+
set_min_amount_two_out(value) {
|
|
3223
|
+
const offset = 34;
|
|
3224
|
+
this.view.setBigUint64(offset, value, true);
|
|
3225
|
+
}
|
|
3226
|
+
get min_amount_two_out() {
|
|
3227
|
+
return this.get_min_amount_two_out();
|
|
3228
|
+
}
|
|
3229
|
+
set min_amount_two_out(value) {
|
|
3230
|
+
this.set_min_amount_two_out(value);
|
|
3231
|
+
}
|
|
3042
3232
|
static __tnFootprintInternal(__tnParams) {
|
|
3043
3233
|
return __tnEvalFootprint2(__tn_ir_AmmWithdrawLiquidityInstruction.root, { params: __tnParams });
|
|
3044
3234
|
}
|
|
@@ -3063,11 +3253,11 @@ var AmmWithdrawLiquidityInstruction = class _AmmWithdrawLiquidityInstruction {
|
|
|
3063
3253
|
return __tnBigIntToNumber2(irResult, "AmmWithdrawLiquidityInstruction::footprint");
|
|
3064
3254
|
}
|
|
3065
3255
|
static validate(buffer, _opts) {
|
|
3066
|
-
if (buffer.length <
|
|
3067
|
-
return { ok: true, consumed:
|
|
3256
|
+
if (buffer.length < 42) return { ok: false, code: "tn.buffer_too_small", consumed: 42 };
|
|
3257
|
+
return { ok: true, consumed: 42 };
|
|
3068
3258
|
}
|
|
3069
|
-
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) {
|
|
3070
|
-
const buffer = new Uint8Array(
|
|
3259
|
+
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) {
|
|
3260
|
+
const buffer = new Uint8Array(42);
|
|
3071
3261
|
const view = new DataView(buffer.buffer);
|
|
3072
3262
|
view.setUint16(0, pool_account_idx, true);
|
|
3073
3263
|
view.setUint16(2, withdrawer_account_idx, true);
|
|
@@ -3079,6 +3269,8 @@ var AmmWithdrawLiquidityInstruction = class _AmmWithdrawLiquidityInstruction {
|
|
|
3079
3269
|
view.setUint16(14, lp_mint_account_idx, true);
|
|
3080
3270
|
view.setUint16(16, token_program_account_idx, true);
|
|
3081
3271
|
view.setBigUint64(18, lp_amount, true);
|
|
3272
|
+
view.setBigUint64(26, min_amount_one_out, true);
|
|
3273
|
+
view.setBigUint64(34, min_amount_two_out, true);
|
|
3082
3274
|
return new _AmmWithdrawLiquidityInstruction(buffer);
|
|
3083
3275
|
}
|
|
3084
3276
|
static from_array(buffer) {
|
|
@@ -3095,7 +3287,7 @@ var AmmWithdrawLiquidityInstruction = class _AmmWithdrawLiquidityInstruction {
|
|
|
3095
3287
|
};
|
|
3096
3288
|
var AmmWithdrawLiquidityInstructionBuilder = class {
|
|
3097
3289
|
constructor() {
|
|
3098
|
-
this.buffer = new Uint8Array(
|
|
3290
|
+
this.buffer = new Uint8Array(42);
|
|
3099
3291
|
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
3100
3292
|
}
|
|
3101
3293
|
set_pool_account_idx(value) {
|
|
@@ -3139,6 +3331,16 @@ var AmmWithdrawLiquidityInstructionBuilder = class {
|
|
|
3139
3331
|
this.view.setBigUint64(18, cast, true);
|
|
3140
3332
|
return this;
|
|
3141
3333
|
}
|
|
3334
|
+
set_min_amount_one_out(value) {
|
|
3335
|
+
const cast = __tnToBigInt2(value);
|
|
3336
|
+
this.view.setBigUint64(26, cast, true);
|
|
3337
|
+
return this;
|
|
3338
|
+
}
|
|
3339
|
+
set_min_amount_two_out(value) {
|
|
3340
|
+
const cast = __tnToBigInt2(value);
|
|
3341
|
+
this.view.setBigUint64(34, cast, true);
|
|
3342
|
+
return this;
|
|
3343
|
+
}
|
|
3142
3344
|
build() {
|
|
3143
3345
|
return this.buffer.slice();
|
|
3144
3346
|
}
|
|
@@ -4707,21 +4909,21 @@ _AmmInstruction.payloadVariantDescriptors = Object.freeze([
|
|
|
4707
4909
|
{
|
|
4708
4910
|
name: "add_liquidity",
|
|
4709
4911
|
tag: 1,
|
|
4710
|
-
payloadSize:
|
|
4912
|
+
payloadSize: 42,
|
|
4711
4913
|
payloadType: "AmmInstruction::payload::add_liquidity",
|
|
4712
4914
|
createPayloadBuilder: () => __tnMaybeCallBuilder(AmmAddLiquidityInstruction)
|
|
4713
4915
|
},
|
|
4714
4916
|
{
|
|
4715
4917
|
name: "withdraw_liquidity",
|
|
4716
4918
|
tag: 2,
|
|
4717
|
-
payloadSize:
|
|
4919
|
+
payloadSize: 42,
|
|
4718
4920
|
payloadType: "AmmInstruction::payload::withdraw_liquidity",
|
|
4719
4921
|
createPayloadBuilder: () => __tnMaybeCallBuilder(AmmWithdrawLiquidityInstruction)
|
|
4720
4922
|
},
|
|
4721
4923
|
{
|
|
4722
4924
|
name: "swap",
|
|
4723
4925
|
tag: 3,
|
|
4724
|
-
payloadSize:
|
|
4926
|
+
payloadSize: 32,
|
|
4725
4927
|
payloadType: "AmmInstruction::payload::swap",
|
|
4726
4928
|
createPayloadBuilder: () => __tnMaybeCallBuilder(AmmSwapInstruction)
|
|
4727
4929
|
}
|
|
@@ -4770,7 +4972,7 @@ var AmmInstructionBuilder = class {
|
|
|
4770
4972
|
this.__tnLastParams = null;
|
|
4771
4973
|
}
|
|
4772
4974
|
__tnAssign_discriminant(value) {
|
|
4773
|
-
this.__tnField_discriminant = value
|
|
4975
|
+
this.__tnField_discriminant = value;
|
|
4774
4976
|
this.__tnInvalidate();
|
|
4775
4977
|
}
|
|
4776
4978
|
set_discriminant(value) {
|
|
@@ -6064,7 +6266,7 @@ var AmmEventBuilder = class {
|
|
|
6064
6266
|
this.__tnLastParams = null;
|
|
6065
6267
|
}
|
|
6066
6268
|
__tnAssign_event_type(value) {
|
|
6067
|
-
this.__tnField_event_type = value
|
|
6269
|
+
this.__tnField_event_type = value;
|
|
6068
6270
|
this.__tnInvalidate();
|
|
6069
6271
|
}
|
|
6070
6272
|
set_event_type(value) {
|
|
@@ -6193,7 +6395,8 @@ var AMM_ERROR_LABELS = {
|
|
|
6193
6395
|
16: "Vault two init failed",
|
|
6194
6396
|
17: "Liquidity bounds",
|
|
6195
6397
|
18: "Vault mismatch",
|
|
6196
|
-
19: "LP mint mismatch"
|
|
6398
|
+
19: "LP mint mismatch",
|
|
6399
|
+
20: "Slippage exceeded"
|
|
6197
6400
|
};
|
|
6198
6401
|
var PUBKEY_LENGTH = 32;
|
|
6199
6402
|
var LP_MINT_SEED_LABEL = asciiBytes("lp_mint");
|
|
@@ -6268,21 +6471,25 @@ function createAddLiquidityInstruction(args) {
|
|
|
6268
6471
|
return async (context) => {
|
|
6269
6472
|
assertU64(args.maxAmountMintOne, "maxAmountMintOne");
|
|
6270
6473
|
assertU64(args.maxAmountMintTwo, "maxAmountMintTwo");
|
|
6271
|
-
|
|
6474
|
+
assertU64(args.minLpOut, "minLpOut");
|
|
6475
|
+
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();
|
|
6272
6476
|
return buildAmmInstruction("add_liquidity", payload);
|
|
6273
6477
|
};
|
|
6274
6478
|
}
|
|
6275
6479
|
function createWithdrawLiquidityInstruction(args) {
|
|
6276
6480
|
return async (context) => {
|
|
6277
6481
|
assertU64(args.lpAmount, "lpAmount");
|
|
6278
|
-
|
|
6482
|
+
assertU64(args.minAmountOneOut, "minAmountOneOut");
|
|
6483
|
+
assertU64(args.minAmountTwoOut, "minAmountTwoOut");
|
|
6484
|
+
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();
|
|
6279
6485
|
return buildAmmInstruction("withdraw_liquidity", payload);
|
|
6280
6486
|
};
|
|
6281
6487
|
}
|
|
6282
6488
|
function createSwapInstruction(args) {
|
|
6283
6489
|
return async (context) => {
|
|
6284
6490
|
assertU64(args.amountIn, "amountIn");
|
|
6285
|
-
|
|
6491
|
+
assertU64(args.minAmountOut, "minAmountOut");
|
|
6492
|
+
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();
|
|
6286
6493
|
return buildAmmInstruction("swap", payload);
|
|
6287
6494
|
};
|
|
6288
6495
|
}
|
|
@@ -6330,7 +6537,7 @@ function assertU16(value, label) {
|
|
|
6330
6537
|
}
|
|
6331
6538
|
}
|
|
6332
6539
|
function assertU64(value, label) {
|
|
6333
|
-
if (value < 0n || value > 0xffffffffffffffffn) {
|
|
6540
|
+
if (typeof value !== "bigint" || value < 0n || value > 0xffffffffffffffffn) {
|
|
6334
6541
|
throw new Error(`${label} must be between 0 and 18446744073709551615`);
|
|
6335
6542
|
}
|
|
6336
6543
|
}
|