flash-sdk 2.49.1 → 2.50.1
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/PerpetualsClient.d.ts +2 -10
- package/dist/PerpetualsClient.js +541 -516
- package/dist/PoolConfig.json +110 -0
- package/dist/ViewHelper.js +3 -3
- package/dist/backupOracle.js +3 -3
- package/dist/idl/perpetuals.d.ts +1 -112
- package/dist/idl/perpetuals.js +1 -112
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/utils/alt.d.ts +0 -1
- package/dist/utils/rpc.js +50 -50
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -719,8 +719,7 @@ var PerpetualsClient = (function () {
|
|
719
719
|
return { feeBps: fees.minFee, feeAmount: anchor_1.BN.max(amountAdd, amountRemove).mul(fees.minFee).div(new anchor_1.BN(constants_1.RATE_POWER)) };
|
720
720
|
}
|
721
721
|
var newRatio = _this.getNewRatioHelper(amountAdd, amountRemove, inputTokenCustodyAccount, maxOraclePrice, poolAumUsdMax);
|
722
|
-
var
|
723
|
-
var index = inputCustodyConfig.custodyId;
|
722
|
+
var index = poolAccount.custodies.findIndex(function (c) { return c.equals(inputTokenCustodyAccount.publicKey); });
|
724
723
|
var ratios = poolAccount.ratios[index];
|
725
724
|
var fee = constants_1.BN_ZERO;
|
726
725
|
if (action == types_1.FeesAction.AddLiquidity || action == types_1.FeesAction.SwapIn || action == types_1.FeesAction.StableSwapIn) {
|
@@ -2149,36 +2148,40 @@ var PerpetualsClient = (function () {
|
|
2149
2148
|
}
|
2150
2149
|
});
|
2151
2150
|
}); };
|
2152
|
-
this.getAddLiquidityAmountAndFeeView = function (
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2151
|
+
this.getAddLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
|
2152
|
+
var args_1 = [];
|
2153
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2154
|
+
args_1[_i - 4] = arguments[_i];
|
2155
|
+
}
|
2156
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
2157
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
2158
|
+
var _e;
|
2159
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2160
|
+
return __generator(this, function (_f) {
|
2161
|
+
switch (_f.label) {
|
2159
2162
|
case 0:
|
2160
2163
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2161
2164
|
custodies = POOL_CONFIG.custodies;
|
2162
2165
|
custodyMetas = [];
|
2163
2166
|
marketMetas = [];
|
2164
|
-
for (
|
2165
|
-
token = custodies_5[
|
2167
|
+
for (_a = 0, custodies_5 = custodies; _a < custodies_5.length; _a++) {
|
2168
|
+
token = custodies_5[_a];
|
2166
2169
|
custodyMetas.push({
|
2167
2170
|
isSigner: false,
|
2168
2171
|
isWritable: false,
|
2169
2172
|
pubkey: token.custodyAccount,
|
2170
2173
|
});
|
2171
2174
|
}
|
2172
|
-
for (
|
2173
|
-
custody = custodies_6[
|
2175
|
+
for (_b = 0, custodies_6 = custodies; _b < custodies_6.length; _b++) {
|
2176
|
+
custody = custodies_6[_b];
|
2174
2177
|
custodyMetas.push({
|
2175
2178
|
isSigner: false,
|
2176
2179
|
isWritable: false,
|
2177
2180
|
pubkey: custody.intOracleAccount,
|
2178
2181
|
});
|
2179
2182
|
}
|
2180
|
-
for (
|
2181
|
-
market = _c
|
2183
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2184
|
+
market = _d[_c];
|
2182
2185
|
marketMetas.push({
|
2183
2186
|
pubkey: market.marketAccount,
|
2184
2187
|
isSigner: false,
|
@@ -2201,14 +2204,14 @@ var PerpetualsClient = (function () {
|
|
2201
2204
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2202
2205
|
.transaction()];
|
2203
2206
|
case 1:
|
2204
|
-
transaction =
|
2207
|
+
transaction = _f.sent();
|
2205
2208
|
return [4, backUpOracleInstructionPromise];
|
2206
2209
|
case 2:
|
2207
|
-
backUpOracleInstruction =
|
2208
|
-
(
|
2210
|
+
backUpOracleInstruction = _f.sent();
|
2211
|
+
(_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
|
2209
2212
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2210
2213
|
case 3:
|
2211
|
-
result =
|
2214
|
+
result = _f.sent();
|
2212
2215
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
|
2213
2216
|
res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
|
2214
2217
|
return [2, {
|
@@ -2219,36 +2222,40 @@ var PerpetualsClient = (function () {
|
|
2219
2222
|
});
|
2220
2223
|
});
|
2221
2224
|
};
|
2222
|
-
this.getRemoveLiquidityAmountAndFeeView = function (
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2225
|
+
this.getRemoveLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
|
2226
|
+
var args_1 = [];
|
2227
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2228
|
+
args_1[_i - 4] = arguments[_i];
|
2229
|
+
}
|
2230
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
2231
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
2232
|
+
var _e;
|
2233
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2234
|
+
return __generator(this, function (_f) {
|
2235
|
+
switch (_f.label) {
|
2229
2236
|
case 0:
|
2230
2237
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2231
2238
|
custodies = POOL_CONFIG.custodies;
|
2232
2239
|
custodyMetas = [];
|
2233
2240
|
marketMetas = [];
|
2234
|
-
for (
|
2235
|
-
token = custodies_7[
|
2241
|
+
for (_a = 0, custodies_7 = custodies; _a < custodies_7.length; _a++) {
|
2242
|
+
token = custodies_7[_a];
|
2236
2243
|
custodyMetas.push({
|
2237
2244
|
isSigner: false,
|
2238
2245
|
isWritable: false,
|
2239
2246
|
pubkey: token.custodyAccount,
|
2240
2247
|
});
|
2241
2248
|
}
|
2242
|
-
for (
|
2243
|
-
custody = custodies_8[
|
2249
|
+
for (_b = 0, custodies_8 = custodies; _b < custodies_8.length; _b++) {
|
2250
|
+
custody = custodies_8[_b];
|
2244
2251
|
custodyMetas.push({
|
2245
2252
|
isSigner: false,
|
2246
2253
|
isWritable: false,
|
2247
2254
|
pubkey: custody.intOracleAccount,
|
2248
2255
|
});
|
2249
2256
|
}
|
2250
|
-
for (
|
2251
|
-
market = _c
|
2257
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2258
|
+
market = _d[_c];
|
2252
2259
|
marketMetas.push({
|
2253
2260
|
pubkey: market.marketAccount,
|
2254
2261
|
isSigner: false,
|
@@ -2271,14 +2278,14 @@ var PerpetualsClient = (function () {
|
|
2271
2278
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2272
2279
|
.transaction()];
|
2273
2280
|
case 1:
|
2274
|
-
transaction =
|
2281
|
+
transaction = _f.sent();
|
2275
2282
|
return [4, backUpOracleInstructionPromise];
|
2276
2283
|
case 2:
|
2277
|
-
backUpOracleInstruction =
|
2278
|
-
(
|
2284
|
+
backUpOracleInstruction = _f.sent();
|
2285
|
+
(_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
|
2279
2286
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2280
2287
|
case 3:
|
2281
|
-
result =
|
2288
|
+
result = _f.sent();
|
2282
2289
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
|
2283
2290
|
if (result.value.err) {
|
2284
2291
|
return [2, {
|
@@ -2354,36 +2361,40 @@ var PerpetualsClient = (function () {
|
|
2354
2361
|
}
|
2355
2362
|
});
|
2356
2363
|
}); };
|
2357
|
-
this.getAddCompoundingLiquidityAmountAndFeeView = function (
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
|
2364
|
+
this.getAddCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
|
2365
|
+
var args_1 = [];
|
2366
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2367
|
+
args_1[_i - 4] = arguments[_i];
|
2368
|
+
}
|
2369
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
2370
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
|
2371
|
+
var _e;
|
2372
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2373
|
+
return __generator(this, function (_f) {
|
2374
|
+
switch (_f.label) {
|
2364
2375
|
case 0:
|
2365
2376
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2366
2377
|
custodies = POOL_CONFIG.custodies;
|
2367
2378
|
custodyMetas = [];
|
2368
2379
|
marketMetas = [];
|
2369
|
-
for (
|
2370
|
-
token = custodies_11[
|
2380
|
+
for (_a = 0, custodies_11 = custodies; _a < custodies_11.length; _a++) {
|
2381
|
+
token = custodies_11[_a];
|
2371
2382
|
custodyMetas.push({
|
2372
2383
|
isSigner: false,
|
2373
2384
|
isWritable: false,
|
2374
2385
|
pubkey: token.custodyAccount,
|
2375
2386
|
});
|
2376
2387
|
}
|
2377
|
-
for (
|
2378
|
-
custody = custodies_12[
|
2388
|
+
for (_b = 0, custodies_12 = custodies; _b < custodies_12.length; _b++) {
|
2389
|
+
custody = custodies_12[_b];
|
2379
2390
|
custodyMetas.push({
|
2380
2391
|
isSigner: false,
|
2381
2392
|
isWritable: false,
|
2382
2393
|
pubkey: custody.intOracleAccount,
|
2383
2394
|
});
|
2384
2395
|
}
|
2385
|
-
for (
|
2386
|
-
market = _c
|
2396
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2397
|
+
market = _d[_c];
|
2387
2398
|
marketMetas.push({
|
2388
2399
|
pubkey: market.marketAccount,
|
2389
2400
|
isSigner: false,
|
@@ -2394,7 +2405,7 @@ var PerpetualsClient = (function () {
|
|
2394
2405
|
rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
2395
2406
|
return [4, backUpOracleInstructionPromise];
|
2396
2407
|
case 1:
|
2397
|
-
backUpOracleInstruction =
|
2408
|
+
backUpOracleInstruction = _f.sent();
|
2398
2409
|
return [4, this.program.methods
|
2399
2410
|
.getAddCompoundingLiquidityAmountAndFee({
|
2400
2411
|
amountIn: amount,
|
@@ -2413,11 +2424,11 @@ var PerpetualsClient = (function () {
|
|
2413
2424
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2414
2425
|
.transaction()];
|
2415
2426
|
case 2:
|
2416
|
-
transaction =
|
2417
|
-
(
|
2427
|
+
transaction = _f.sent();
|
2428
|
+
(_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
|
2418
2429
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2419
2430
|
case 3:
|
2420
|
-
result =
|
2431
|
+
result = _f.sent();
|
2421
2432
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
|
2422
2433
|
res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
|
2423
2434
|
return [2, {
|
@@ -2428,36 +2439,40 @@ var PerpetualsClient = (function () {
|
|
2428
2439
|
});
|
2429
2440
|
});
|
2430
2441
|
};
|
2431
|
-
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (
|
2432
|
-
|
2433
|
-
|
2434
|
-
|
2435
|
-
|
2436
|
-
|
2437
|
-
|
2442
|
+
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
|
2443
|
+
var args_1 = [];
|
2444
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2445
|
+
args_1[_i - 4] = arguments[_i];
|
2446
|
+
}
|
2447
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
2448
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
|
2449
|
+
var _e;
|
2450
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2451
|
+
return __generator(this, function (_f) {
|
2452
|
+
switch (_f.label) {
|
2438
2453
|
case 0:
|
2439
2454
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2440
2455
|
custodies = POOL_CONFIG.custodies;
|
2441
2456
|
custodyMetas = [];
|
2442
2457
|
marketMetas = [];
|
2443
|
-
for (
|
2444
|
-
token = custodies_13[
|
2458
|
+
for (_a = 0, custodies_13 = custodies; _a < custodies_13.length; _a++) {
|
2459
|
+
token = custodies_13[_a];
|
2445
2460
|
custodyMetas.push({
|
2446
2461
|
isSigner: false,
|
2447
2462
|
isWritable: false,
|
2448
2463
|
pubkey: token.custodyAccount,
|
2449
2464
|
});
|
2450
2465
|
}
|
2451
|
-
for (
|
2452
|
-
custody = custodies_14[
|
2466
|
+
for (_b = 0, custodies_14 = custodies; _b < custodies_14.length; _b++) {
|
2467
|
+
custody = custodies_14[_b];
|
2453
2468
|
custodyMetas.push({
|
2454
2469
|
isSigner: false,
|
2455
2470
|
isWritable: false,
|
2456
2471
|
pubkey: custody.intOracleAccount,
|
2457
2472
|
});
|
2458
2473
|
}
|
2459
|
-
for (
|
2460
|
-
market = _c
|
2474
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2475
|
+
market = _d[_c];
|
2461
2476
|
marketMetas.push({
|
2462
2477
|
pubkey: market.marketAccount,
|
2463
2478
|
isSigner: false,
|
@@ -2468,7 +2483,7 @@ var PerpetualsClient = (function () {
|
|
2468
2483
|
rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
2469
2484
|
return [4, backUpOracleInstructionPromise];
|
2470
2485
|
case 1:
|
2471
|
-
backUpOracleInstruction =
|
2486
|
+
backUpOracleInstruction = _f.sent();
|
2472
2487
|
return [4, this.program.methods
|
2473
2488
|
.getRemoveCompoundingLiquidityAmountAndFee({
|
2474
2489
|
compoundingAmountIn: amount,
|
@@ -2487,11 +2502,11 @@ var PerpetualsClient = (function () {
|
|
2487
2502
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2488
2503
|
.transaction()];
|
2489
2504
|
case 2:
|
2490
|
-
transaction =
|
2491
|
-
(
|
2505
|
+
transaction = _f.sent();
|
2506
|
+
(_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
|
2492
2507
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2493
2508
|
case 3:
|
2494
|
-
result =
|
2509
|
+
result = _f.sent();
|
2495
2510
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
|
2496
2511
|
if (result.value.err) {
|
2497
2512
|
return [2, {
|
@@ -2630,14 +2645,18 @@ var PerpetualsClient = (function () {
|
|
2630
2645
|
}
|
2631
2646
|
});
|
2632
2647
|
}); };
|
2633
|
-
this.openPosition = function (
|
2634
|
-
|
2635
|
-
|
2636
|
-
|
2637
|
-
|
2638
|
-
|
2639
|
-
return __awaiter(_this, void 0, void 0, function () {
|
2648
|
+
this.openPosition = function (targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1) {
|
2649
|
+
var args_1 = [];
|
2650
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
2651
|
+
args_1[_i - 8] = arguments[_i];
|
2652
|
+
}
|
2653
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2640
2654
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2655
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2656
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2657
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2658
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2659
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2641
2660
|
return __generator(this, function (_c) {
|
2642
2661
|
switch (_c.label) {
|
2643
2662
|
case 0:
|
@@ -2741,15 +2760,19 @@ var PerpetualsClient = (function () {
|
|
2741
2760
|
});
|
2742
2761
|
});
|
2743
2762
|
};
|
2744
|
-
this.closePosition = function (
|
2745
|
-
|
2746
|
-
|
2747
|
-
|
2748
|
-
|
2749
|
-
|
2750
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2751
|
-
return __awaiter(_this, void 0, void 0, function () {
|
2763
|
+
this.closePosition = function (marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
2764
|
+
var args_1 = [];
|
2765
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
2766
|
+
args_1[_i - 6] = arguments[_i];
|
2767
|
+
}
|
2768
|
+
return __awaiter(_this, __spreadArray([marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
2752
2769
|
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
|
2770
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2771
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2772
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2773
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
2774
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2775
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2753
2776
|
return __generator(this, function (_b) {
|
2754
2777
|
switch (_b.label) {
|
2755
2778
|
case 0:
|
@@ -2846,14 +2869,18 @@ var PerpetualsClient = (function () {
|
|
2846
2869
|
});
|
2847
2870
|
});
|
2848
2871
|
};
|
2849
|
-
this.swapAndOpen = function (
|
2850
|
-
|
2851
|
-
|
2852
|
-
|
2853
|
-
|
2854
|
-
|
2855
|
-
return __awaiter(_this, void 0, void 0, function () {
|
2872
|
+
this.swapAndOpen = function (targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1) {
|
2873
|
+
var args_1 = [];
|
2874
|
+
for (var _i = 10; _i < arguments.length; _i++) {
|
2875
|
+
args_1[_i - 10] = arguments[_i];
|
2876
|
+
}
|
2877
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2856
2878
|
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_2;
|
2879
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2880
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2881
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2882
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2883
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2857
2884
|
return __generator(this, function (_c) {
|
2858
2885
|
switch (_c.label) {
|
2859
2886
|
case 0:
|
@@ -2993,13 +3020,17 @@ var PerpetualsClient = (function () {
|
|
2993
3020
|
});
|
2994
3021
|
});
|
2995
3022
|
};
|
2996
|
-
this.closeAndSwap = function (
|
2997
|
-
|
2998
|
-
|
2999
|
-
|
3000
|
-
|
3001
|
-
return __awaiter(_this,
|
3023
|
+
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
3024
|
+
var args_1 = [];
|
3025
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3026
|
+
args_1[_i - 8] = arguments[_i];
|
3027
|
+
}
|
3028
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
|
3002
3029
|
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_3;
|
3030
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3031
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3032
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3033
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3003
3034
|
return __generator(this, function (_a) {
|
3004
3035
|
switch (_a.label) {
|
3005
3036
|
case 0:
|
@@ -3113,16 +3144,20 @@ var PerpetualsClient = (function () {
|
|
3113
3144
|
});
|
3114
3145
|
});
|
3115
3146
|
};
|
3116
|
-
this.swap = function (
|
3117
|
-
|
3118
|
-
|
3119
|
-
|
3120
|
-
|
3121
|
-
|
3122
|
-
|
3123
|
-
|
3124
|
-
|
3125
|
-
|
3147
|
+
this.swap = function (userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1) {
|
3148
|
+
var args_1 = [];
|
3149
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
3150
|
+
args_1[_i - 5] = arguments[_i];
|
3151
|
+
}
|
3152
|
+
return __awaiter(_this, __spreadArray([userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1], args_1, true), void 0, function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
|
3153
|
+
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _e, _f, custody, params, inx, closeWsolATAIns, err_4;
|
3154
|
+
if (useFeesPool === void 0) { useFeesPool = false; }
|
3155
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3156
|
+
if (unWrapSol === void 0) { unWrapSol = false; }
|
3157
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3158
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3159
|
+
return __generator(this, function (_g) {
|
3160
|
+
switch (_g.label) {
|
3126
3161
|
case 0:
|
3127
3162
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
3128
3163
|
if (!userInputCustodyConfig) {
|
@@ -3140,10 +3175,10 @@ var PerpetualsClient = (function () {
|
|
3140
3175
|
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
3141
3176
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
3142
3177
|
case 1:
|
3143
|
-
wsolAssociatedTokenAccount =
|
3178
|
+
wsolAssociatedTokenAccount = _g.sent();
|
3144
3179
|
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
3145
3180
|
case 2:
|
3146
|
-
wsolATAExist =
|
3181
|
+
wsolATAExist = _g.sent();
|
3147
3182
|
if (!wsolATAExist) {
|
3148
3183
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
3149
3184
|
}
|
@@ -3151,11 +3186,11 @@ var PerpetualsClient = (function () {
|
|
3151
3186
|
_a = anchor_1.BN.bind;
|
3152
3187
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3153
3188
|
case 3:
|
3154
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
3189
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3155
3190
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3156
3191
|
throw "Insufficient SOL Funds";
|
3157
3192
|
}
|
3158
|
-
|
3193
|
+
_g.label = 4;
|
3159
3194
|
case 4:
|
3160
3195
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
3161
3196
|
fromPubkey: publicKey,
|
@@ -3177,20 +3212,20 @@ var PerpetualsClient = (function () {
|
|
3177
3212
|
additionalSigners: additionalSigners
|
3178
3213
|
}];
|
3179
3214
|
}
|
3180
|
-
|
3215
|
+
_g.label = 6;
|
3181
3216
|
case 6:
|
3182
|
-
|
3217
|
+
_g.trys.push([6, 19, , 20]);
|
3183
3218
|
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
3184
3219
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
3185
3220
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3186
3221
|
case 7:
|
3187
|
-
accCreationLamports = (
|
3222
|
+
accCreationLamports = (_g.sent());
|
3188
3223
|
console.log("accCreationLamports:", accCreationLamports);
|
3189
3224
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3190
3225
|
_b = anchor_1.BN.bind;
|
3191
3226
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3192
3227
|
case 8:
|
3193
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0,
|
3228
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3194
3229
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3195
3230
|
throw "Insufficient SOL Funds";
|
3196
3231
|
}
|
@@ -3217,18 +3252,18 @@ var PerpetualsClient = (function () {
|
|
3217
3252
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
3218
3253
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3219
3254
|
case 10:
|
3220
|
-
if (!(
|
3255
|
+
if (!(_g.sent())) {
|
3221
3256
|
throw "Insufficient Funds , Token Account doesn't exist";
|
3222
3257
|
}
|
3223
3258
|
if (!!skipBalanceChecks) return [3, 12];
|
3224
3259
|
_c = anchor_1.BN.bind;
|
3225
3260
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3226
3261
|
case 11:
|
3227
|
-
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (
|
3262
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
3228
3263
|
if (tokenAccountBalance.lt(amountIn)) {
|
3229
3264
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3230
3265
|
}
|
3231
|
-
|
3266
|
+
_g.label = 12;
|
3232
3267
|
case 12:
|
3233
3268
|
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
3234
3269
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
@@ -3253,23 +3288,23 @@ var PerpetualsClient = (function () {
|
|
3253
3288
|
return [3, 17];
|
3254
3289
|
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
3255
3290
|
case 14:
|
3256
|
-
userOutputTokenAccount =
|
3291
|
+
userOutputTokenAccount = _g.sent();
|
3257
3292
|
_d = createUserATA;
|
3258
3293
|
if (!_d) return [3, 16];
|
3259
3294
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
3260
3295
|
case 15:
|
3261
|
-
_d = !(
|
3262
|
-
|
3296
|
+
_d = !(_g.sent());
|
3297
|
+
_g.label = 16;
|
3263
3298
|
case 16:
|
3264
3299
|
if (_d) {
|
3265
3300
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
3266
3301
|
}
|
3267
|
-
|
3302
|
+
_g.label = 17;
|
3268
3303
|
case 17:
|
3269
3304
|
custodyAccountMetas = [];
|
3270
3305
|
custodyOracleAccountMetas = [];
|
3271
|
-
for (
|
3272
|
-
custody = _e
|
3306
|
+
for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
|
3307
|
+
custody = _f[_e];
|
3273
3308
|
custodyAccountMetas.push({
|
3274
3309
|
pubkey: custody.custodyAccount,
|
3275
3310
|
isSigner: false,
|
@@ -3309,7 +3344,7 @@ var PerpetualsClient = (function () {
|
|
3309
3344
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3310
3345
|
.instruction()];
|
3311
3346
|
case 18:
|
3312
|
-
inx =
|
3347
|
+
inx = _g.sent();
|
3313
3348
|
instructions.push(inx);
|
3314
3349
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
3315
3350
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
@@ -3317,7 +3352,7 @@ var PerpetualsClient = (function () {
|
|
3317
3352
|
}
|
3318
3353
|
return [3, 20];
|
3319
3354
|
case 19:
|
3320
|
-
err_4 =
|
3355
|
+
err_4 = _g.sent();
|
3321
3356
|
console.error("perpClient Swap error:: ", err_4);
|
3322
3357
|
throw err_4;
|
3323
3358
|
case 20: return [2, {
|
@@ -3399,11 +3434,15 @@ var PerpetualsClient = (function () {
|
|
3399
3434
|
}
|
3400
3435
|
});
|
3401
3436
|
}); };
|
3402
|
-
this.addCollateral = function (
|
3403
|
-
|
3404
|
-
|
3405
|
-
|
3437
|
+
this.addCollateral = function (collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
3438
|
+
var args_1 = [];
|
3439
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
3440
|
+
args_1[_i - 6] = arguments[_i];
|
3441
|
+
}
|
3442
|
+
return __awaiter(_this, __spreadArray([collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3406
3443
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
3444
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3445
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3407
3446
|
return __generator(this, function (_c) {
|
3408
3447
|
switch (_c.label) {
|
3409
3448
|
case 0:
|
@@ -3497,11 +3536,15 @@ var PerpetualsClient = (function () {
|
|
3497
3536
|
});
|
3498
3537
|
});
|
3499
3538
|
};
|
3500
|
-
this.swapAndAddCollateral = function (
|
3501
|
-
|
3502
|
-
|
3503
|
-
|
3539
|
+
this.swapAndAddCollateral = function (targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1) {
|
3540
|
+
var args_1 = [];
|
3541
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3542
|
+
args_1[_i - 8] = arguments[_i];
|
3543
|
+
}
|
3544
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3504
3545
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
3546
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3547
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3505
3548
|
return __generator(this, function (_c) {
|
3506
3549
|
switch (_c.label) {
|
3507
3550
|
case 0:
|
@@ -3612,12 +3655,16 @@ var PerpetualsClient = (function () {
|
|
3612
3655
|
});
|
3613
3656
|
});
|
3614
3657
|
};
|
3615
|
-
this.removeCollateral = function (
|
3616
|
-
|
3617
|
-
|
3618
|
-
|
3619
|
-
|
3658
|
+
this.removeCollateral = function (collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
3659
|
+
var args_1 = [];
|
3660
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
3661
|
+
args_1[_i - 6] = arguments[_i];
|
3662
|
+
}
|
3663
|
+
return __awaiter(_this, __spreadArray([collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3620
3664
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_3;
|
3665
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3666
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3667
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3621
3668
|
return __generator(this, function (_b) {
|
3622
3669
|
switch (_b.label) {
|
3623
3670
|
case 0:
|
@@ -3718,10 +3765,14 @@ var PerpetualsClient = (function () {
|
|
3718
3765
|
});
|
3719
3766
|
});
|
3720
3767
|
};
|
3721
|
-
this.removeCollateralAndSwap = function (
|
3722
|
-
|
3723
|
-
|
3768
|
+
this.removeCollateralAndSwap = function (targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1) {
|
3769
|
+
var args_1 = [];
|
3770
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
3771
|
+
args_1[_i - 7] = arguments[_i];
|
3772
|
+
}
|
3773
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
|
3724
3774
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
|
3775
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3725
3776
|
return __generator(this, function (_a) {
|
3726
3777
|
switch (_a.label) {
|
3727
3778
|
case 0:
|
@@ -3814,12 +3865,16 @@ var PerpetualsClient = (function () {
|
|
3814
3865
|
});
|
3815
3866
|
});
|
3816
3867
|
};
|
3817
|
-
this.increaseSize = function (
|
3818
|
-
|
3819
|
-
|
3820
|
-
|
3821
|
-
|
3868
|
+
this.increaseSize = function (targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
|
3869
|
+
var args_1 = [];
|
3870
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3871
|
+
args_1[_i - 8] = arguments[_i];
|
3872
|
+
}
|
3873
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3822
3874
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3875
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3876
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3877
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3823
3878
|
return __generator(this, function (_a) {
|
3824
3879
|
switch (_a.label) {
|
3825
3880
|
case 0:
|
@@ -3874,12 +3929,16 @@ var PerpetualsClient = (function () {
|
|
3874
3929
|
});
|
3875
3930
|
});
|
3876
3931
|
};
|
3877
|
-
this.decreaseSize = function (
|
3878
|
-
|
3879
|
-
|
3880
|
-
|
3881
|
-
|
3932
|
+
this.decreaseSize = function (targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
|
3933
|
+
var args_1 = [];
|
3934
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3935
|
+
args_1[_i - 8] = arguments[_i];
|
3936
|
+
}
|
3937
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3882
3938
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3939
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3940
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3941
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3883
3942
|
return __generator(this, function (_a) {
|
3884
3943
|
switch (_a.label) {
|
3885
3944
|
case 0:
|
@@ -3934,13 +3993,17 @@ var PerpetualsClient = (function () {
|
|
3934
3993
|
});
|
3935
3994
|
});
|
3936
3995
|
};
|
3937
|
-
this.addLiquidity = function (
|
3938
|
-
|
3939
|
-
|
3940
|
-
|
3941
|
-
|
3942
|
-
|
3943
|
-
|
3996
|
+
this.addLiquidity = function (payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1) {
|
3997
|
+
var args_1 = [];
|
3998
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
3999
|
+
args_1[_i - 4] = arguments[_i];
|
4000
|
+
}
|
4001
|
+
return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
4002
|
+
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, tokenAccountBalance, _f, instruction, err_6;
|
4003
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4004
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4005
|
+
return __generator(this, function (_g) {
|
4006
|
+
switch (_g.label) {
|
3944
4007
|
case 0:
|
3945
4008
|
publicKey = this.provider.wallet.publicKey;
|
3946
4009
|
payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
|
@@ -3951,16 +4014,16 @@ var PerpetualsClient = (function () {
|
|
3951
4014
|
instructions = [];
|
3952
4015
|
postInstructions = [];
|
3953
4016
|
additionalSigners = [];
|
3954
|
-
|
4017
|
+
_g.label = 1;
|
3955
4018
|
case 1:
|
3956
|
-
|
4019
|
+
_g.trys.push([1, 10, , 11]);
|
3957
4020
|
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
|
3958
4021
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
3959
4022
|
custodyAccountMetas = [];
|
3960
4023
|
custodyOracleAccountMetas = [];
|
3961
4024
|
markets = [];
|
3962
|
-
for (
|
3963
|
-
custody = _a
|
4025
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4026
|
+
custody = _b[_a];
|
3964
4027
|
custodyAccountMetas.push({
|
3965
4028
|
pubkey: custody.custodyAccount,
|
3966
4029
|
isSigner: false,
|
@@ -3972,8 +4035,8 @@ var PerpetualsClient = (function () {
|
|
3972
4035
|
isWritable: false,
|
3973
4036
|
});
|
3974
4037
|
}
|
3975
|
-
for (
|
3976
|
-
market = _c
|
4038
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
4039
|
+
market = _d[_c];
|
3977
4040
|
markets.push({
|
3978
4041
|
pubkey: market.marketAccount,
|
3979
4042
|
isSigner: false,
|
@@ -3982,21 +4045,21 @@ var PerpetualsClient = (function () {
|
|
3982
4045
|
}
|
3983
4046
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
3984
4047
|
case 2:
|
3985
|
-
if (!(
|
4048
|
+
if (!(_g.sent())) {
|
3986
4049
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3987
4050
|
}
|
3988
4051
|
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
3989
4052
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
3990
4053
|
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3991
4054
|
if (!!skipBalanceChecks) return [3, 4];
|
3992
|
-
|
4055
|
+
_e = anchor_1.BN.bind;
|
3993
4056
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3994
4057
|
case 3:
|
3995
|
-
unWrappedSolBalance = new (
|
4058
|
+
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3996
4059
|
if (unWrappedSolBalance.lt(lamports)) {
|
3997
4060
|
throw "Insufficient SOL Funds";
|
3998
4061
|
}
|
3999
|
-
|
4062
|
+
_g.label = 4;
|
4000
4063
|
case 4:
|
4001
4064
|
if (!ephemeralSignerPubkey) {
|
4002
4065
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -4020,17 +4083,17 @@ var PerpetualsClient = (function () {
|
|
4020
4083
|
if (!!skipBalanceChecks) return [3, 8];
|
4021
4084
|
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
4022
4085
|
case 6:
|
4023
|
-
if (!(
|
4086
|
+
if (!(_g.sent())) {
|
4024
4087
|
throw "Insufficient Funds , token Account doesn't exist";
|
4025
4088
|
}
|
4026
|
-
|
4089
|
+
_f = anchor_1.BN.bind;
|
4027
4090
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
4028
4091
|
case 7:
|
4029
|
-
tokenAccountBalance = new (
|
4092
|
+
tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
4030
4093
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
4031
4094
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
4032
4095
|
}
|
4033
|
-
|
4096
|
+
_g.label = 8;
|
4034
4097
|
case 8: return [4, this.program.methods
|
4035
4098
|
.addLiquidity({
|
4036
4099
|
amountIn: tokenAmountIn,
|
@@ -4055,11 +4118,11 @@ var PerpetualsClient = (function () {
|
|
4055
4118
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4056
4119
|
.instruction()];
|
4057
4120
|
case 9:
|
4058
|
-
instruction =
|
4121
|
+
instruction = _g.sent();
|
4059
4122
|
instructions.push(instruction);
|
4060
4123
|
return [3, 11];
|
4061
4124
|
case 10:
|
4062
|
-
err_6 =
|
4125
|
+
err_6 = _g.sent();
|
4063
4126
|
console.error("perpClient addLiquidity error:: ", err_6);
|
4064
4127
|
throw err_6;
|
4065
4128
|
case 11: return [2, {
|
@@ -4070,14 +4133,18 @@ var PerpetualsClient = (function () {
|
|
4070
4133
|
});
|
4071
4134
|
});
|
4072
4135
|
};
|
4073
|
-
this.addLiquidityAndStake = function (
|
4074
|
-
|
4075
|
-
|
4076
|
-
|
4077
|
-
|
4078
|
-
|
4079
|
-
|
4080
|
-
|
4136
|
+
this.addLiquidityAndStake = function (inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1) {
|
4137
|
+
var args_1 = [];
|
4138
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
4139
|
+
args_1[_i - 4] = arguments[_i];
|
4140
|
+
}
|
4141
|
+
return __awaiter(_this, __spreadArray([inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
4142
|
+
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, instruction;
|
4143
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4144
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4145
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4146
|
+
return __generator(this, function (_g) {
|
4147
|
+
switch (_g.label) {
|
4081
4148
|
case 0:
|
4082
4149
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4083
4150
|
preInstructions = [];
|
@@ -4097,14 +4164,14 @@ var PerpetualsClient = (function () {
|
|
4097
4164
|
_a = anchor_1.BN.bind;
|
4098
4165
|
return [4, this.provider.connection.getBalance(publicKey)];
|
4099
4166
|
case 1:
|
4100
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
4167
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
4101
4168
|
if (unWrappedSolBalance.lt(lamports)) {
|
4102
4169
|
throw "Insufficient SOL Funds";
|
4103
4170
|
}
|
4104
|
-
|
4171
|
+
_g.label = 2;
|
4105
4172
|
case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4106
4173
|
case 3:
|
4107
|
-
if (!(
|
4174
|
+
if (!(_g.sent())) {
|
4108
4175
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4109
4176
|
}
|
4110
4177
|
if (!ephemeralSignerPubkey) {
|
@@ -4130,23 +4197,23 @@ var PerpetualsClient = (function () {
|
|
4130
4197
|
if (!!skipBalanceChecks) return [3, 7];
|
4131
4198
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
4132
4199
|
case 5:
|
4133
|
-
if (!(
|
4200
|
+
if (!(_g.sent())) {
|
4134
4201
|
throw "Insufficient Funds , token Account doesn't exist";
|
4135
4202
|
}
|
4136
4203
|
_b = anchor_1.BN.bind;
|
4137
4204
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
4138
4205
|
case 6:
|
4139
|
-
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (
|
4206
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
4140
4207
|
if (tokenAccountBalance.lt(amountIn)) {
|
4141
4208
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
4142
4209
|
}
|
4143
|
-
|
4210
|
+
_g.label = 7;
|
4144
4211
|
case 7:
|
4145
4212
|
custodyAccountMetas = [];
|
4146
4213
|
custodyOracleAccountMetas = [];
|
4147
4214
|
markets = [];
|
4148
|
-
for (
|
4149
|
-
custody = _c
|
4215
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
4216
|
+
custody = _d[_c];
|
4150
4217
|
custodyAccountMetas.push({
|
4151
4218
|
pubkey: custody.custodyAccount,
|
4152
4219
|
isSigner: false,
|
@@ -4158,8 +4225,8 @@ var PerpetualsClient = (function () {
|
|
4158
4225
|
isWritable: false,
|
4159
4226
|
});
|
4160
4227
|
}
|
4161
|
-
for (
|
4162
|
-
market = _e
|
4228
|
+
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
4229
|
+
market = _f[_e];
|
4163
4230
|
markets.push({
|
4164
4231
|
pubkey: market.marketAccount,
|
4165
4232
|
isSigner: false,
|
@@ -4191,7 +4258,7 @@ var PerpetualsClient = (function () {
|
|
4191
4258
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4192
4259
|
.instruction()];
|
4193
4260
|
case 8:
|
4194
|
-
instruction =
|
4261
|
+
instruction = _g.sent();
|
4195
4262
|
instructions.push(instruction);
|
4196
4263
|
return [2, {
|
4197
4264
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4201,16 +4268,20 @@ var PerpetualsClient = (function () {
|
|
4201
4268
|
});
|
4202
4269
|
});
|
4203
4270
|
};
|
4204
|
-
this.removeLiquidity = function (
|
4205
|
-
|
4206
|
-
|
4207
|
-
|
4208
|
-
|
4209
|
-
|
4210
|
-
|
4211
|
-
|
4212
|
-
|
4213
|
-
|
4271
|
+
this.removeLiquidity = function (recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1) {
|
4272
|
+
var args_1 = [];
|
4273
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
4274
|
+
args_1[_i - 4] = arguments[_i];
|
4275
|
+
}
|
4276
|
+
return __awaiter(_this, __spreadArray([recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1], args_1, true), void 0, function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
|
4277
|
+
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, _e, removeLiquidityTx, closeInx, closeWsolATAIns, err_7;
|
4278
|
+
if (closeLpATA === void 0) { closeLpATA = false; }
|
4279
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4280
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
4281
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4282
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4283
|
+
return __generator(this, function (_f) {
|
4284
|
+
switch (_f.label) {
|
4214
4285
|
case 0:
|
4215
4286
|
recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
|
4216
4287
|
if (!recieveTokenCustodyConfig) {
|
@@ -4221,15 +4292,15 @@ var PerpetualsClient = (function () {
|
|
4221
4292
|
instructions = [];
|
4222
4293
|
postInstructions = [];
|
4223
4294
|
additionalSigners = [];
|
4224
|
-
|
4295
|
+
_f.label = 1;
|
4225
4296
|
case 1:
|
4226
|
-
|
4297
|
+
_f.trys.push([1, 7, , 8]);
|
4227
4298
|
stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4228
4299
|
custodyAccountMetas = [];
|
4229
4300
|
custodyOracleAccountMetas = [];
|
4230
4301
|
markets = [];
|
4231
|
-
for (
|
4232
|
-
custody = _a
|
4302
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4303
|
+
custody = _b[_a];
|
4233
4304
|
custodyAccountMetas.push({
|
4234
4305
|
pubkey: custody.custodyAccount,
|
4235
4306
|
isSigner: false,
|
@@ -4241,8 +4312,8 @@ var PerpetualsClient = (function () {
|
|
4241
4312
|
isWritable: false,
|
4242
4313
|
});
|
4243
4314
|
}
|
4244
|
-
for (
|
4245
|
-
market = _c
|
4315
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
4316
|
+
market = _d[_c];
|
4246
4317
|
markets.push({
|
4247
4318
|
pubkey: market.marketAccount,
|
4248
4319
|
isSigner: false,
|
@@ -4271,17 +4342,17 @@ var PerpetualsClient = (function () {
|
|
4271
4342
|
return [3, 5];
|
4272
4343
|
case 2:
|
4273
4344
|
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
|
4274
|
-
|
4275
|
-
if (!
|
4345
|
+
_e = createUserATA;
|
4346
|
+
if (!_e) return [3, 4];
|
4276
4347
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
4277
4348
|
case 3:
|
4278
|
-
|
4279
|
-
|
4349
|
+
_e = !(_f.sent());
|
4350
|
+
_f.label = 4;
|
4280
4351
|
case 4:
|
4281
|
-
if (
|
4352
|
+
if (_e) {
|
4282
4353
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
|
4283
4354
|
}
|
4284
|
-
|
4355
|
+
_f.label = 5;
|
4285
4356
|
case 5: return [4, this.program.methods
|
4286
4357
|
.removeLiquidity({
|
4287
4358
|
lpAmountIn: liquidityAmountIn,
|
@@ -4306,7 +4377,7 @@ var PerpetualsClient = (function () {
|
|
4306
4377
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4307
4378
|
.instruction()];
|
4308
4379
|
case 6:
|
4309
|
-
removeLiquidityTx =
|
4380
|
+
removeLiquidityTx = _f.sent();
|
4310
4381
|
instructions.push(removeLiquidityTx);
|
4311
4382
|
if (closeLpATA) {
|
4312
4383
|
closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
|
@@ -4318,7 +4389,7 @@ var PerpetualsClient = (function () {
|
|
4318
4389
|
}
|
4319
4390
|
return [3, 8];
|
4320
4391
|
case 7:
|
4321
|
-
err_7 =
|
4392
|
+
err_7 = _f.sent();
|
4322
4393
|
console.log("perpClient removeLiquidity error:: ", err_7);
|
4323
4394
|
throw err_7;
|
4324
4395
|
case 8: return [2, {
|
@@ -4736,22 +4807,26 @@ var PerpetualsClient = (function () {
|
|
4736
4807
|
}
|
4737
4808
|
});
|
4738
4809
|
}); };
|
4739
|
-
this.refreshStakeWithTokenStake = function (
|
4740
|
-
|
4741
|
-
|
4742
|
-
|
4743
|
-
|
4744
|
-
|
4810
|
+
this.refreshStakeWithTokenStake = function (rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1) {
|
4811
|
+
var args_1 = [];
|
4812
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4813
|
+
args_1[_i - 3] = arguments[_i];
|
4814
|
+
}
|
4815
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4816
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_16;
|
4817
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4818
|
+
return __generator(this, function (_c) {
|
4819
|
+
switch (_c.label) {
|
4745
4820
|
case 0:
|
4746
|
-
|
4821
|
+
_c.trys.push([0, 2, , 3]);
|
4747
4822
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4748
4823
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
4749
4824
|
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
4750
4825
|
pool = poolConfig.poolAddress;
|
4751
4826
|
feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
|
4752
4827
|
custodyAccountMetas = [];
|
4753
|
-
for (
|
4754
|
-
custody = _a
|
4828
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4829
|
+
custody = _b[_a];
|
4755
4830
|
custodyAccountMetas.push({
|
4756
4831
|
pubkey: custody.custodyAccount,
|
4757
4832
|
isSigner: false,
|
@@ -4783,10 +4858,10 @@ var PerpetualsClient = (function () {
|
|
4783
4858
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
|
4784
4859
|
.instruction()];
|
4785
4860
|
case 1:
|
4786
|
-
refreshStakeInstruction =
|
4861
|
+
refreshStakeInstruction = _c.sent();
|
4787
4862
|
return [2, refreshStakeInstruction];
|
4788
4863
|
case 2:
|
4789
|
-
err_16 =
|
4864
|
+
err_16 = _c.sent();
|
4790
4865
|
console.log("perpClient refreshStaking error:: ", err_16);
|
4791
4866
|
throw err_16;
|
4792
4867
|
case 3: return [2];
|
@@ -4794,10 +4869,14 @@ var PerpetualsClient = (function () {
|
|
4794
4869
|
});
|
4795
4870
|
});
|
4796
4871
|
};
|
4797
|
-
this.unstakeInstant = function (
|
4798
|
-
|
4799
|
-
|
4872
|
+
this.unstakeInstant = function (rewardSymbol_1, unstakeAmount_1, poolConfig_1) {
|
4873
|
+
var args_1 = [];
|
4874
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4875
|
+
args_1[_i - 3] = arguments[_i];
|
4876
|
+
}
|
4877
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4800
4878
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_17;
|
4879
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4801
4880
|
return __generator(this, function (_b) {
|
4802
4881
|
switch (_b.label) {
|
4803
4882
|
case 0:
|
@@ -4956,13 +5035,17 @@ var PerpetualsClient = (function () {
|
|
4956
5035
|
}
|
4957
5036
|
});
|
4958
5037
|
}); };
|
4959
|
-
this.withdrawStake = function (
|
4960
|
-
|
4961
|
-
|
4962
|
-
|
4963
|
-
|
4964
|
-
return __awaiter(_this,
|
5038
|
+
this.withdrawStake = function (poolConfig_1) {
|
5039
|
+
var args_1 = [];
|
5040
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
5041
|
+
args_1[_i - 1] = arguments[_i];
|
5042
|
+
}
|
5043
|
+
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
4965
5044
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_20;
|
5045
|
+
if (pendingActivation === void 0) { pendingActivation = true; }
|
5046
|
+
if (deactivated === void 0) { deactivated = true; }
|
5047
|
+
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
5048
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4966
5049
|
return __generator(this, function (_b) {
|
4967
5050
|
switch (_b.label) {
|
4968
5051
|
case 0:
|
@@ -5024,10 +5107,14 @@ var PerpetualsClient = (function () {
|
|
5024
5107
|
});
|
5025
5108
|
});
|
5026
5109
|
};
|
5027
|
-
this.collectStakeFees = function (
|
5028
|
-
|
5029
|
-
|
5110
|
+
this.collectStakeFees = function (rewardSymbol_1, poolConfig_1, tokenStakeAccount_1) {
|
5111
|
+
var args_1 = [];
|
5112
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
5113
|
+
args_1[_i - 3] = arguments[_i];
|
5114
|
+
}
|
5115
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
5030
5116
|
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_21;
|
5117
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5031
5118
|
return __generator(this, function (_b) {
|
5032
5119
|
switch (_b.label) {
|
5033
5120
|
case 0:
|
@@ -5751,10 +5838,14 @@ var PerpetualsClient = (function () {
|
|
5751
5838
|
}
|
5752
5839
|
});
|
5753
5840
|
}); };
|
5754
|
-
this.collectTokenReward = function (
|
5755
|
-
|
5756
|
-
|
5841
|
+
this.collectTokenReward = function (owner_1, poolConfig_1) {
|
5842
|
+
var args_1 = [];
|
5843
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
5844
|
+
args_1[_i - 2] = arguments[_i];
|
5845
|
+
}
|
5846
|
+
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5757
5847
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_35;
|
5848
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5758
5849
|
return __generator(this, function (_b) {
|
5759
5850
|
switch (_b.label) {
|
5760
5851
|
case 0:
|
@@ -5809,10 +5900,14 @@ var PerpetualsClient = (function () {
|
|
5809
5900
|
});
|
5810
5901
|
});
|
5811
5902
|
};
|
5812
|
-
this.collectRevenue = function (
|
5813
|
-
|
5814
|
-
|
5903
|
+
this.collectRevenue = function (owner_1, rewardSymbol_1, poolConfig_1) {
|
5904
|
+
var args_1 = [];
|
5905
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
5906
|
+
args_1[_i - 3] = arguments[_i];
|
5907
|
+
}
|
5908
|
+
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5815
5909
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_36;
|
5910
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5816
5911
|
return __generator(this, function (_b) {
|
5817
5912
|
switch (_b.label) {
|
5818
5913
|
case 0:
|
@@ -5997,10 +6092,14 @@ var PerpetualsClient = (function () {
|
|
5997
6092
|
}
|
5998
6093
|
});
|
5999
6094
|
}); };
|
6000
|
-
this.collectNftReward = function (
|
6001
|
-
|
6002
|
-
|
6095
|
+
this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
|
6096
|
+
var args_1 = [];
|
6097
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
6098
|
+
args_1[_i - 3] = arguments[_i];
|
6099
|
+
}
|
6100
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
6003
6101
|
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_40;
|
6102
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6004
6103
|
return __generator(this, function (_b) {
|
6005
6104
|
switch (_b.label) {
|
6006
6105
|
case 0:
|
@@ -6060,10 +6159,14 @@ var PerpetualsClient = (function () {
|
|
6060
6159
|
});
|
6061
6160
|
});
|
6062
6161
|
};
|
6063
|
-
this.collectAndDistributeFee = function (
|
6064
|
-
|
6065
|
-
|
6162
|
+
this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
|
6163
|
+
var args_1 = [];
|
6164
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
6165
|
+
args_1[_i - 2] = arguments[_i];
|
6166
|
+
}
|
6167
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
6066
6168
|
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_41;
|
6169
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6067
6170
|
return __generator(this, function (_b) {
|
6068
6171
|
switch (_b.label) {
|
6069
6172
|
case 0:
|
@@ -6188,12 +6291,16 @@ var PerpetualsClient = (function () {
|
|
6188
6291
|
}
|
6189
6292
|
});
|
6190
6293
|
}); };
|
6191
|
-
this.forceClosePosition = function (
|
6192
|
-
|
6193
|
-
|
6194
|
-
|
6195
|
-
|
6294
|
+
this.forceClosePosition = function (positionAccount_1, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1) {
|
6295
|
+
var args_1 = [];
|
6296
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
6297
|
+
args_1[_i - 6] = arguments[_i];
|
6298
|
+
}
|
6299
|
+
return __awaiter(_this, __spreadArray([positionAccount_1, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1], args_1, true), void 0, function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
6196
6300
|
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_43;
|
6301
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6302
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
6303
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6197
6304
|
return __generator(this, function (_b) {
|
6198
6305
|
switch (_b.label) {
|
6199
6306
|
case 0:
|
@@ -6265,11 +6372,15 @@ var PerpetualsClient = (function () {
|
|
6265
6372
|
});
|
6266
6373
|
});
|
6267
6374
|
};
|
6268
|
-
this.placeLimitOrder = function (
|
6269
|
-
|
6270
|
-
|
6271
|
-
|
6375
|
+
this.placeLimitOrder = function (targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1) {
|
6376
|
+
var args_1 = [];
|
6377
|
+
for (var _i = 11; _i < arguments.length; _i++) {
|
6378
|
+
args_1[_i - 11] = arguments[_i];
|
6379
|
+
}
|
6380
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
6272
6381
|
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_44;
|
6382
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6383
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6273
6384
|
return __generator(this, function (_c) {
|
6274
6385
|
switch (_c.label) {
|
6275
6386
|
case 0:
|
@@ -6385,11 +6496,15 @@ var PerpetualsClient = (function () {
|
|
6385
6496
|
});
|
6386
6497
|
});
|
6387
6498
|
};
|
6388
|
-
this.editLimitOrder = function (
|
6389
|
-
|
6390
|
-
|
6391
|
-
|
6499
|
+
this.editLimitOrder = function (targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1) {
|
6500
|
+
var args_1 = [];
|
6501
|
+
for (var _i = 11; _i < arguments.length; _i++) {
|
6502
|
+
args_1[_i - 11] = arguments[_i];
|
6503
|
+
}
|
6504
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
|
6392
6505
|
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_45;
|
6506
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6507
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6393
6508
|
return __generator(this, function (_b) {
|
6394
6509
|
switch (_b.label) {
|
6395
6510
|
case 0:
|
@@ -6488,12 +6603,16 @@ var PerpetualsClient = (function () {
|
|
6488
6603
|
});
|
6489
6604
|
});
|
6490
6605
|
};
|
6491
|
-
this.executeLimitOrder = function (
|
6492
|
-
|
6493
|
-
|
6494
|
-
|
6495
|
-
|
6606
|
+
this.executeLimitOrder = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
|
6607
|
+
var args_1 = [];
|
6608
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
6609
|
+
args_1[_i - 7] = arguments[_i];
|
6610
|
+
}
|
6611
|
+
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6496
6612
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_46;
|
6613
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6614
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6615
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6497
6616
|
return __generator(this, function (_a) {
|
6498
6617
|
switch (_a.label) {
|
6499
6618
|
case 0:
|
@@ -6553,12 +6672,16 @@ var PerpetualsClient = (function () {
|
|
6553
6672
|
});
|
6554
6673
|
});
|
6555
6674
|
};
|
6556
|
-
this.executeLimitWithSwap = function (
|
6557
|
-
|
6558
|
-
|
6559
|
-
|
6560
|
-
|
6675
|
+
this.executeLimitWithSwap = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
|
6676
|
+
var args_1 = [];
|
6677
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
6678
|
+
args_1[_i - 8] = arguments[_i];
|
6679
|
+
}
|
6680
|
+
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6561
6681
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_47;
|
6682
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6683
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6684
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6562
6685
|
return __generator(this, function (_a) {
|
6563
6686
|
switch (_a.label) {
|
6564
6687
|
case 0:
|
@@ -6824,16 +6947,20 @@ var PerpetualsClient = (function () {
|
|
6824
6947
|
}
|
6825
6948
|
});
|
6826
6949
|
}); };
|
6827
|
-
this.executeTriggerWithSwap = function (
|
6828
|
-
|
6829
|
-
|
6830
|
-
|
6831
|
-
|
6832
|
-
|
6833
|
-
|
6834
|
-
|
6835
|
-
|
6836
|
-
|
6950
|
+
this.executeTriggerWithSwap = function (owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
|
6951
|
+
var args_1 = [];
|
6952
|
+
for (var _i = 9; _i < arguments.length; _i++) {
|
6953
|
+
args_1[_i - 9] = arguments[_i];
|
6954
|
+
}
|
6955
|
+
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6956
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_52;
|
6957
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6958
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6959
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6960
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6961
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6962
|
+
return __generator(this, function (_e) {
|
6963
|
+
switch (_e.label) {
|
6837
6964
|
case 0:
|
6838
6965
|
payerPubkey = this.provider.wallet.publicKey;
|
6839
6966
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
@@ -6844,9 +6971,9 @@ var PerpetualsClient = (function () {
|
|
6844
6971
|
instructions = [];
|
6845
6972
|
postInstructions = [];
|
6846
6973
|
additionalSigners = [];
|
6847
|
-
|
6974
|
+
_e.label = 1;
|
6848
6975
|
case 1:
|
6849
|
-
|
6976
|
+
_e.trys.push([1, 9, , 10]);
|
6850
6977
|
if (!false) return [3, 2];
|
6851
6978
|
return [3, 7];
|
6852
6979
|
case 2:
|
@@ -6855,8 +6982,8 @@ var PerpetualsClient = (function () {
|
|
6855
6982
|
if (!_a) return [3, 4];
|
6856
6983
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
6857
6984
|
case 3:
|
6858
|
-
_a = !(
|
6859
|
-
|
6985
|
+
_a = !(_e.sent());
|
6986
|
+
_e.label = 4;
|
6860
6987
|
case 4:
|
6861
6988
|
if (_a) {
|
6862
6989
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
@@ -6866,20 +6993,20 @@ var PerpetualsClient = (function () {
|
|
6866
6993
|
if (!_b) return [3, 6];
|
6867
6994
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
|
6868
6995
|
case 5:
|
6869
|
-
_b = !(
|
6870
|
-
|
6996
|
+
_b = !(_e.sent());
|
6997
|
+
_e.label = 6;
|
6871
6998
|
case 6:
|
6872
6999
|
if (_b) {
|
6873
7000
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6874
7001
|
}
|
6875
|
-
|
7002
|
+
_e.label = 7;
|
6876
7003
|
case 7:
|
6877
7004
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
6878
7005
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
6879
7006
|
custodyAccountMetas = [];
|
6880
7007
|
custodyOracleAccountMetas = [];
|
6881
|
-
for (
|
6882
|
-
custody = _c
|
7008
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
7009
|
+
custody = _d[_c];
|
6883
7010
|
custodyAccountMetas.push({
|
6884
7011
|
pubkey: custody.custodyAccount,
|
6885
7012
|
isSigner: false,
|
@@ -6924,11 +7051,11 @@ var PerpetualsClient = (function () {
|
|
6924
7051
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
6925
7052
|
.instruction()];
|
6926
7053
|
case 8:
|
6927
|
-
executeTriggerWithSwap =
|
7054
|
+
executeTriggerWithSwap = _e.sent();
|
6928
7055
|
instructions.push(executeTriggerWithSwap);
|
6929
7056
|
return [3, 10];
|
6930
7057
|
case 9:
|
6931
|
-
err_52 =
|
7058
|
+
err_52 = _e.sent();
|
6932
7059
|
console.log("perpClient executeTriggerWithSwap error:: ", err_52);
|
6933
7060
|
throw err_52;
|
6934
7061
|
case 10: return [2, {
|
@@ -6939,14 +7066,18 @@ var PerpetualsClient = (function () {
|
|
6939
7066
|
});
|
6940
7067
|
});
|
6941
7068
|
};
|
6942
|
-
this.executeTriggerOrder = function (
|
6943
|
-
|
6944
|
-
|
6945
|
-
|
6946
|
-
|
6947
|
-
|
6948
|
-
return __awaiter(_this, void 0, void 0, function () {
|
7069
|
+
this.executeTriggerOrder = function (owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
|
7070
|
+
var args_1 = [];
|
7071
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
7072
|
+
args_1[_i - 8] = arguments[_i];
|
7073
|
+
}
|
7074
|
+
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6949
7075
|
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_53;
|
7076
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
7077
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7078
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
7079
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
7080
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6950
7081
|
return __generator(this, function (_b) {
|
6951
7082
|
switch (_b.label) {
|
6952
7083
|
case 0:
|
@@ -7369,136 +7500,18 @@ var PerpetualsClient = (function () {
|
|
7369
7500
|
}
|
7370
7501
|
});
|
7371
7502
|
}); };
|
7372
|
-
this.
|
7373
|
-
var
|
7374
|
-
|
7375
|
-
|
7376
|
-
|
7377
|
-
|
7378
|
-
|
7379
|
-
|
7380
|
-
|
7381
|
-
|
7382
|
-
|
7383
|
-
|
7384
|
-
accountMetas.push({
|
7385
|
-
pubkey: custody.custodyAccount,
|
7386
|
-
isSigner: false,
|
7387
|
-
isWritable: false,
|
7388
|
-
});
|
7389
|
-
accountMetas.push({
|
7390
|
-
pubkey: custody.intOracleAccount,
|
7391
|
-
isSigner: false,
|
7392
|
-
isWritable: true,
|
7393
|
-
});
|
7394
|
-
accountMetas.push({
|
7395
|
-
pubkey: custody.extOracleAccount,
|
7396
|
-
isSigner: false,
|
7397
|
-
isWritable: false,
|
7398
|
-
});
|
7399
|
-
};
|
7400
|
-
for (_i = 0, tokenMintList_1 = tokenMintList; _i < tokenMintList_1.length; _i++) {
|
7401
|
-
tokenMint = tokenMintList_1[_i];
|
7402
|
-
_loop_1(tokenMint);
|
7403
|
-
}
|
7404
|
-
instructions = [];
|
7405
|
-
additionalSigners = [];
|
7406
|
-
_a.label = 1;
|
7407
|
-
case 1:
|
7408
|
-
_a.trys.push([1, 3, , 4]);
|
7409
|
-
return [4, this.program.methods
|
7410
|
-
.setInternalCurrentPrice({
|
7411
|
-
prices: tokenInternalPrices
|
7412
|
-
})
|
7413
|
-
.accounts({
|
7414
|
-
authority: POOL_CONFIGS[0].backupOracle,
|
7415
|
-
})
|
7416
|
-
.remainingAccounts(__spreadArray([], accountMetas, true))
|
7417
|
-
.instruction()];
|
7418
|
-
case 2:
|
7419
|
-
setInternalOraclePrice = _a.sent();
|
7420
|
-
instructions.push(setInternalOraclePrice);
|
7421
|
-
return [3, 4];
|
7422
|
-
case 3:
|
7423
|
-
err_62 = _a.sent();
|
7424
|
-
console.log("perpClient setInternalOracleAccount error:: ", err_62);
|
7425
|
-
throw err_62;
|
7426
|
-
case 4: return [2, {
|
7427
|
-
instructions: __spreadArray([], instructions, true),
|
7428
|
-
additionalSigners: additionalSigners
|
7429
|
-
}];
|
7430
|
-
}
|
7431
|
-
});
|
7432
|
-
}); };
|
7433
|
-
this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7434
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_63;
|
7435
|
-
return __generator(this, function (_a) {
|
7436
|
-
switch (_a.label) {
|
7437
|
-
case 0:
|
7438
|
-
if (tokenMintList.length !== tokenInternalEmaPrices.length) {
|
7439
|
-
throw new Error("tokenMintList and tokenInternalPrices length mismatch");
|
7440
|
-
}
|
7441
|
-
ALL_CUSTODY_CONFIGS = POOL_CONFIGS.map(function (f) { return f.custodies; }).flat();
|
7442
|
-
accountMetas = [];
|
7443
|
-
_loop_2 = function (tokenMint) {
|
7444
|
-
var custody = ALL_CUSTODY_CONFIGS.find(function (i) { return i.mintKey.equals(tokenMint); });
|
7445
|
-
accountMetas.push({
|
7446
|
-
pubkey: custody.custodyAccount,
|
7447
|
-
isSigner: false,
|
7448
|
-
isWritable: false,
|
7449
|
-
});
|
7450
|
-
accountMetas.push({
|
7451
|
-
pubkey: custody.intOracleAccount,
|
7452
|
-
isSigner: false,
|
7453
|
-
isWritable: true,
|
7454
|
-
});
|
7455
|
-
accountMetas.push({
|
7456
|
-
pubkey: custody.extOracleAccount,
|
7457
|
-
isSigner: false,
|
7458
|
-
isWritable: false,
|
7459
|
-
});
|
7460
|
-
};
|
7461
|
-
for (_i = 0, tokenMintList_2 = tokenMintList; _i < tokenMintList_2.length; _i++) {
|
7462
|
-
tokenMint = tokenMintList_2[_i];
|
7463
|
-
_loop_2(tokenMint);
|
7464
|
-
}
|
7465
|
-
instructions = [];
|
7466
|
-
additionalSigners = [];
|
7467
|
-
_a.label = 1;
|
7468
|
-
case 1:
|
7469
|
-
_a.trys.push([1, 3, , 4]);
|
7470
|
-
return [4, this.program.methods
|
7471
|
-
.setInternalEmaPrice({
|
7472
|
-
prices: tokenInternalEmaPrices
|
7473
|
-
})
|
7474
|
-
.accounts({
|
7475
|
-
authority: POOL_CONFIGS[0].backupOracle,
|
7476
|
-
})
|
7477
|
-
.remainingAccounts(__spreadArray([], accountMetas, true))
|
7478
|
-
.instruction()];
|
7479
|
-
case 2:
|
7480
|
-
setInternalOraclePrice = _a.sent();
|
7481
|
-
instructions.push(setInternalOraclePrice);
|
7482
|
-
return [3, 4];
|
7483
|
-
case 3:
|
7484
|
-
err_63 = _a.sent();
|
7485
|
-
console.log("perpClient setInternalOracleAccount error:: ", err_63);
|
7486
|
-
throw err_63;
|
7487
|
-
case 4: return [2, {
|
7488
|
-
instructions: __spreadArray([], instructions, true),
|
7489
|
-
additionalSigners: additionalSigners
|
7490
|
-
}];
|
7491
|
-
}
|
7492
|
-
});
|
7493
|
-
}); };
|
7494
|
-
this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
7495
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
7496
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7497
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7498
|
-
return __awaiter(_this, void 0, void 0, function () {
|
7499
|
-
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_64;
|
7500
|
-
return __generator(this, function (_e) {
|
7501
|
-
switch (_e.label) {
|
7503
|
+
this.addCompoundingLiquidity = function (amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
|
7504
|
+
var args_1 = [];
|
7505
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
7506
|
+
args_1[_i - 5] = arguments[_i];
|
7507
|
+
}
|
7508
|
+
return __awaiter(_this, __spreadArray([amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
7509
|
+
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity, err_62;
|
7510
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
7511
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7512
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7513
|
+
return __generator(this, function (_f) {
|
7514
|
+
switch (_f.label) {
|
7502
7515
|
case 0:
|
7503
7516
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
7504
7517
|
preInstructions = [];
|
@@ -7515,8 +7528,8 @@ var PerpetualsClient = (function () {
|
|
7515
7528
|
custodyAccountMetas = [];
|
7516
7529
|
custodyOracleAccountMetas = [];
|
7517
7530
|
markets = [];
|
7518
|
-
for (
|
7519
|
-
custody = _a
|
7531
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
7532
|
+
custody = _b[_a];
|
7520
7533
|
custodyAccountMetas.push({
|
7521
7534
|
pubkey: custody.custodyAccount,
|
7522
7535
|
isSigner: false,
|
@@ -7528,8 +7541,8 @@ var PerpetualsClient = (function () {
|
|
7528
7541
|
isWritable: false,
|
7529
7542
|
});
|
7530
7543
|
}
|
7531
|
-
for (
|
7532
|
-
market = _c
|
7544
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
7545
|
+
market = _d[_c];
|
7533
7546
|
markets.push({
|
7534
7547
|
pubkey: market.marketAccount,
|
7535
7548
|
isSigner: false,
|
@@ -7538,26 +7551,26 @@ var PerpetualsClient = (function () {
|
|
7538
7551
|
}
|
7539
7552
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
7540
7553
|
case 1:
|
7541
|
-
if (!(
|
7554
|
+
if (!(_f.sent())) {
|
7542
7555
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
7543
7556
|
}
|
7544
7557
|
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
7545
7558
|
case 2:
|
7546
|
-
if (!(
|
7559
|
+
if (!(_f.sent())) {
|
7547
7560
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
7548
7561
|
}
|
7549
7562
|
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
7550
7563
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
7551
7564
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
7552
7565
|
if (!!skipBalanceChecks) return [3, 4];
|
7553
|
-
|
7566
|
+
_e = anchor_1.BN.bind;
|
7554
7567
|
return [4, this.provider.connection.getBalance(publicKey)];
|
7555
7568
|
case 3:
|
7556
|
-
unWrappedSolBalance = new (
|
7569
|
+
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
7557
7570
|
if (unWrappedSolBalance.lt(lamports)) {
|
7558
7571
|
throw "Insufficient SOL Funds";
|
7559
7572
|
}
|
7560
|
-
|
7573
|
+
_f.label = 4;
|
7561
7574
|
case 4:
|
7562
7575
|
if (!ephemeralSignerPubkey) {
|
7563
7576
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -7581,12 +7594,12 @@ var PerpetualsClient = (function () {
|
|
7581
7594
|
if (!!skipBalanceChecks) return [3, 7];
|
7582
7595
|
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
7583
7596
|
case 6:
|
7584
|
-
if (!(
|
7597
|
+
if (!(_f.sent())) {
|
7585
7598
|
throw "Insufficient Funds , token Account doesn't exist";
|
7586
7599
|
}
|
7587
|
-
|
7600
|
+
_f.label = 7;
|
7588
7601
|
case 7:
|
7589
|
-
|
7602
|
+
_f.trys.push([7, 9, , 10]);
|
7590
7603
|
return [4, this.program.methods
|
7591
7604
|
.addCompoundingLiquidity({
|
7592
7605
|
amountIn: amountIn,
|
@@ -7615,12 +7628,12 @@ var PerpetualsClient = (function () {
|
|
7615
7628
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7616
7629
|
.instruction()];
|
7617
7630
|
case 8:
|
7618
|
-
addCompoundingLiquidity =
|
7631
|
+
addCompoundingLiquidity = _f.sent();
|
7619
7632
|
instructions.push(addCompoundingLiquidity);
|
7620
7633
|
return [3, 10];
|
7621
7634
|
case 9:
|
7622
|
-
|
7623
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
7635
|
+
err_62 = _f.sent();
|
7636
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_62);
|
7624
7637
|
return [3, 10];
|
7625
7638
|
case 10: return [2, {
|
7626
7639
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7630,14 +7643,18 @@ var PerpetualsClient = (function () {
|
|
7630
7643
|
});
|
7631
7644
|
});
|
7632
7645
|
};
|
7633
|
-
this.removeCompoundingLiquidity = function (
|
7634
|
-
|
7635
|
-
|
7636
|
-
|
7637
|
-
|
7638
|
-
|
7639
|
-
|
7640
|
-
|
7646
|
+
this.removeCompoundingLiquidity = function (compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
|
7647
|
+
var args_1 = [];
|
7648
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
7649
|
+
args_1[_i - 5] = arguments[_i];
|
7650
|
+
}
|
7651
|
+
return __awaiter(_this, __spreadArray([compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
|
7652
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity, err_63;
|
7653
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
7654
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7655
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7656
|
+
return __generator(this, function (_f) {
|
7657
|
+
switch (_f.label) {
|
7641
7658
|
case 0:
|
7642
7659
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
7643
7660
|
preInstructions = [];
|
@@ -7674,19 +7691,19 @@ var PerpetualsClient = (function () {
|
|
7674
7691
|
if (!_a) return [3, 3];
|
7675
7692
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
7676
7693
|
case 2:
|
7677
|
-
_a = !(
|
7678
|
-
|
7694
|
+
_a = !(_f.sent());
|
7695
|
+
_f.label = 3;
|
7679
7696
|
case 3:
|
7680
7697
|
if (_a) {
|
7681
7698
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
7682
7699
|
}
|
7683
|
-
|
7700
|
+
_f.label = 4;
|
7684
7701
|
case 4:
|
7685
7702
|
custodyAccountMetas = [];
|
7686
7703
|
custodyOracleAccountMetas = [];
|
7687
7704
|
markets = [];
|
7688
|
-
for (
|
7689
|
-
custody = _b
|
7705
|
+
for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
|
7706
|
+
custody = _c[_b];
|
7690
7707
|
custodyAccountMetas.push({
|
7691
7708
|
pubkey: custody.custodyAccount,
|
7692
7709
|
isSigner: false,
|
@@ -7698,8 +7715,8 @@ var PerpetualsClient = (function () {
|
|
7698
7715
|
isWritable: false,
|
7699
7716
|
});
|
7700
7717
|
}
|
7701
|
-
for (
|
7702
|
-
market = _d
|
7718
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
7719
|
+
market = _e[_d];
|
7703
7720
|
markets.push({
|
7704
7721
|
pubkey: market.marketAccount,
|
7705
7722
|
isSigner: false,
|
@@ -7707,9 +7724,9 @@ var PerpetualsClient = (function () {
|
|
7707
7724
|
});
|
7708
7725
|
}
|
7709
7726
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
7710
|
-
|
7727
|
+
_f.label = 5;
|
7711
7728
|
case 5:
|
7712
|
-
|
7729
|
+
_f.trys.push([5, 7, , 8]);
|
7713
7730
|
return [4, this.program.methods
|
7714
7731
|
.removeCompoundingLiquidity({
|
7715
7732
|
compoundingAmountIn: compoundingAmountIn,
|
@@ -7738,12 +7755,12 @@ var PerpetualsClient = (function () {
|
|
7738
7755
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7739
7756
|
.instruction()];
|
7740
7757
|
case 6:
|
7741
|
-
removeCompoundingLiquidity =
|
7758
|
+
removeCompoundingLiquidity = _f.sent();
|
7742
7759
|
instructions.push(removeCompoundingLiquidity);
|
7743
7760
|
return [3, 8];
|
7744
7761
|
case 7:
|
7745
|
-
|
7746
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
7762
|
+
err_63 = _f.sent();
|
7763
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_63);
|
7747
7764
|
return [3, 8];
|
7748
7765
|
case 8: return [2, {
|
7749
7766
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7753,12 +7770,16 @@ var PerpetualsClient = (function () {
|
|
7753
7770
|
});
|
7754
7771
|
});
|
7755
7772
|
};
|
7756
|
-
this.migrateStake = function (
|
7757
|
-
|
7758
|
-
|
7759
|
-
|
7760
|
-
|
7761
|
-
|
7773
|
+
this.migrateStake = function (amount_1, rewardTokenMint_1, poolConfig_1) {
|
7774
|
+
var args_1 = [];
|
7775
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
7776
|
+
args_1[_i - 3] = arguments[_i];
|
7777
|
+
}
|
7778
|
+
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
7779
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake, err_64;
|
7780
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
7781
|
+
return __generator(this, function (_g) {
|
7782
|
+
switch (_g.label) {
|
7762
7783
|
case 0:
|
7763
7784
|
publicKey = this.provider.wallet.publicKey;
|
7764
7785
|
preInstructions = [];
|
@@ -7773,8 +7794,8 @@ var PerpetualsClient = (function () {
|
|
7773
7794
|
if (!_a) return [3, 2];
|
7774
7795
|
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
7775
7796
|
case 1:
|
7776
|
-
_a = !(
|
7777
|
-
|
7797
|
+
_a = !(_g.sent());
|
7798
|
+
_g.label = 2;
|
7778
7799
|
case 2:
|
7779
7800
|
if (_a) {
|
7780
7801
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
@@ -7786,8 +7807,8 @@ var PerpetualsClient = (function () {
|
|
7786
7807
|
if (!_b) return [3, 4];
|
7787
7808
|
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
7788
7809
|
case 3:
|
7789
|
-
_b = (
|
7790
|
-
|
7810
|
+
_b = (_g.sent());
|
7811
|
+
_g.label = 4;
|
7791
7812
|
case 4:
|
7792
7813
|
if (_b) {
|
7793
7814
|
tokenStakeAccounts.push({
|
@@ -7800,8 +7821,8 @@ var PerpetualsClient = (function () {
|
|
7800
7821
|
custodyAccountMetas = [];
|
7801
7822
|
custodyOracleAccountMetas = [];
|
7802
7823
|
markets = [];
|
7803
|
-
for (
|
7804
|
-
custody = _c
|
7824
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
7825
|
+
custody = _d[_c];
|
7805
7826
|
custodyAccountMetas.push({
|
7806
7827
|
pubkey: custody.custodyAccount,
|
7807
7828
|
isSigner: false,
|
@@ -7813,17 +7834,17 @@ var PerpetualsClient = (function () {
|
|
7813
7834
|
isWritable: false,
|
7814
7835
|
});
|
7815
7836
|
}
|
7816
|
-
for (
|
7817
|
-
market = _e
|
7837
|
+
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
7838
|
+
market = _f[_e];
|
7818
7839
|
markets.push({
|
7819
7840
|
pubkey: market.marketAccount,
|
7820
7841
|
isSigner: false,
|
7821
7842
|
isWritable: false,
|
7822
7843
|
});
|
7823
7844
|
}
|
7824
|
-
|
7845
|
+
_g.label = 5;
|
7825
7846
|
case 5:
|
7826
|
-
|
7847
|
+
_g.trys.push([5, 7, , 8]);
|
7827
7848
|
return [4, this.program.methods
|
7828
7849
|
.migrateStake({
|
7829
7850
|
amount: amount
|
@@ -7849,12 +7870,12 @@ var PerpetualsClient = (function () {
|
|
7849
7870
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
7850
7871
|
.instruction()];
|
7851
7872
|
case 6:
|
7852
|
-
migrateStake =
|
7873
|
+
migrateStake = _g.sent();
|
7853
7874
|
instructions.push(migrateStake);
|
7854
7875
|
return [3, 8];
|
7855
7876
|
case 7:
|
7856
|
-
|
7857
|
-
console.log("perpClient migrateStake error:: ",
|
7877
|
+
err_64 = _g.sent();
|
7878
|
+
console.log("perpClient migrateStake error:: ", err_64);
|
7858
7879
|
return [3, 8];
|
7859
7880
|
case 8: return [2, {
|
7860
7881
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7865,7 +7886,7 @@ var PerpetualsClient = (function () {
|
|
7865
7886
|
});
|
7866
7887
|
};
|
7867
7888
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7868
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
7889
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_65;
|
7869
7890
|
return __generator(this, function (_d) {
|
7870
7891
|
switch (_d.label) {
|
7871
7892
|
case 0:
|
@@ -7937,8 +7958,8 @@ var PerpetualsClient = (function () {
|
|
7937
7958
|
instructions.push(migrateFlp);
|
7938
7959
|
return [3, 4];
|
7939
7960
|
case 3:
|
7940
|
-
|
7941
|
-
console.log("perpClient migrateFlp error:: ",
|
7961
|
+
err_65 = _d.sent();
|
7962
|
+
console.log("perpClient migrateFlp error:: ", err_65);
|
7942
7963
|
return [3, 4];
|
7943
7964
|
case 4: return [2, {
|
7944
7965
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7947,12 +7968,16 @@ var PerpetualsClient = (function () {
|
|
7947
7968
|
}
|
7948
7969
|
});
|
7949
7970
|
}); };
|
7950
|
-
this.compoundingFee = function (
|
7951
|
-
|
7952
|
-
|
7953
|
-
|
7954
|
-
|
7955
|
-
|
7971
|
+
this.compoundingFee = function (poolConfig_1) {
|
7972
|
+
var args_1 = [];
|
7973
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
7974
|
+
args_1[_i - 1] = arguments[_i];
|
7975
|
+
}
|
7976
|
+
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
7977
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_66;
|
7978
|
+
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
7979
|
+
return __generator(this, function (_e) {
|
7980
|
+
switch (_e.label) {
|
7956
7981
|
case 0:
|
7957
7982
|
instructions = [];
|
7958
7983
|
additionalSigners = [];
|
@@ -7961,8 +7986,8 @@ var PerpetualsClient = (function () {
|
|
7961
7986
|
custodyAccountMetas = [];
|
7962
7987
|
custodyOracleAccountMetas = [];
|
7963
7988
|
markets = [];
|
7964
|
-
for (
|
7965
|
-
custody = _a
|
7989
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
7990
|
+
custody = _b[_a];
|
7966
7991
|
custodyAccountMetas.push({
|
7967
7992
|
pubkey: custody.custodyAccount,
|
7968
7993
|
isSigner: false,
|
@@ -7974,17 +7999,17 @@ var PerpetualsClient = (function () {
|
|
7974
7999
|
isWritable: false,
|
7975
8000
|
});
|
7976
8001
|
}
|
7977
|
-
for (
|
7978
|
-
market = _c
|
8002
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
8003
|
+
market = _d[_c];
|
7979
8004
|
markets.push({
|
7980
8005
|
pubkey: market.marketAccount,
|
7981
8006
|
isSigner: false,
|
7982
8007
|
isWritable: false,
|
7983
8008
|
});
|
7984
8009
|
}
|
7985
|
-
|
8010
|
+
_e.label = 1;
|
7986
8011
|
case 1:
|
7987
|
-
|
8012
|
+
_e.trys.push([1, 3, , 4]);
|
7988
8013
|
return [4, this.program.methods
|
7989
8014
|
.compoundFees({})
|
7990
8015
|
.accounts({
|
@@ -8003,12 +8028,12 @@ var PerpetualsClient = (function () {
|
|
8003
8028
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
8004
8029
|
.instruction()];
|
8005
8030
|
case 2:
|
8006
|
-
compoundingFee =
|
8031
|
+
compoundingFee = _e.sent();
|
8007
8032
|
instructions.push(compoundingFee);
|
8008
8033
|
return [3, 4];
|
8009
8034
|
case 3:
|
8010
|
-
|
8011
|
-
console.log("perpClient compoundingFee error:: ",
|
8035
|
+
err_66 = _e.sent();
|
8036
|
+
console.log("perpClient compoundingFee error:: ", err_66);
|
8012
8037
|
return [3, 4];
|
8013
8038
|
case 4: return [2, {
|
8014
8039
|
instructions: __spreadArray([], instructions, true),
|
@@ -8019,7 +8044,7 @@ var PerpetualsClient = (function () {
|
|
8019
8044
|
});
|
8020
8045
|
};
|
8021
8046
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8022
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
8047
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_67;
|
8023
8048
|
return __generator(this, function (_a) {
|
8024
8049
|
switch (_a.label) {
|
8025
8050
|
case 0:
|
@@ -8057,8 +8082,8 @@ var PerpetualsClient = (function () {
|
|
8057
8082
|
instructions.push(renameFlp);
|
8058
8083
|
return [3, 4];
|
8059
8084
|
case 3:
|
8060
|
-
|
8061
|
-
console.log("perpClient renameFlp error:: ",
|
8085
|
+
err_67 = _a.sent();
|
8086
|
+
console.log("perpClient renameFlp error:: ", err_67);
|
8062
8087
|
return [3, 4];
|
8063
8088
|
case 4: return [2, {
|
8064
8089
|
instructions: __spreadArray([], instructions, true),
|
@@ -8168,9 +8193,9 @@ var PerpetualsClient = (function () {
|
|
8168
8193
|
}
|
8169
8194
|
}
|
8170
8195
|
};
|
8171
|
-
PerpetualsClient.prototype.sendTransaction = function (
|
8172
|
-
|
8173
|
-
|
8196
|
+
PerpetualsClient.prototype.sendTransaction = function (ixs_1) {
|
8197
|
+
return __awaiter(this, arguments, void 0, function (ixs, opts) {
|
8198
|
+
if (opts === void 0) { opts = {}; }
|
8174
8199
|
return __generator(this, function (_a) {
|
8175
8200
|
switch (_a.label) {
|
8176
8201
|
case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|
@@ -8179,9 +8204,9 @@ var PerpetualsClient = (function () {
|
|
8179
8204
|
});
|
8180
8205
|
});
|
8181
8206
|
};
|
8182
|
-
PerpetualsClient.prototype.sendTransactionV3 = function (
|
8183
|
-
|
8184
|
-
|
8207
|
+
PerpetualsClient.prototype.sendTransactionV3 = function (ixs_1) {
|
8208
|
+
return __awaiter(this, arguments, void 0, function (ixs, opts) {
|
8209
|
+
if (opts === void 0) { opts = {}; }
|
8185
8210
|
return __generator(this, function (_a) {
|
8186
8211
|
switch (_a.label) {
|
8187
8212
|
case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|