flash-sdk 2.47.3 → 2.48.0-alpha.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 +158 -28
- package/dist/PerpetualsClient.js +701 -658
- package/dist/PoolConfig.d.ts +4 -1
- package/dist/PoolConfig.js +5 -2
- package/dist/PoolConfig.json +40 -0
- package/dist/TokenVaultAccount.d.ts +6 -0
- package/dist/ViewHelper.js +3 -3
- package/dist/backupOracle.js +3 -3
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +2 -1
- package/dist/idl/perpetuals.d.ts +451 -8
- package/dist/idl/perpetuals.js +451 -8
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/utils/alt.d.ts +1 -0
- package/dist/utils/rpc.js +50 -50
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -2149,40 +2149,36 @@ var PerpetualsClient = (function () {
|
|
2149
2149
|
}
|
2150
2150
|
});
|
2151
2151
|
}); };
|
2152
|
-
this.getAddLiquidityAmountAndFeeView = function (
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
var _e;
|
2160
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2161
|
-
return __generator(this, function (_f) {
|
2162
|
-
switch (_f.label) {
|
2152
|
+
this.getAddLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
2153
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2154
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2155
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_5, token, _a, custodies_6, custody, _b, _c, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
2156
|
+
var _d;
|
2157
|
+
return __generator(this, function (_e) {
|
2158
|
+
switch (_e.label) {
|
2163
2159
|
case 0:
|
2164
2160
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2165
2161
|
custodies = POOL_CONFIG.custodies;
|
2166
2162
|
custodyMetas = [];
|
2167
2163
|
marketMetas = [];
|
2168
|
-
for (
|
2169
|
-
token = custodies_5[
|
2164
|
+
for (_i = 0, custodies_5 = custodies; _i < custodies_5.length; _i++) {
|
2165
|
+
token = custodies_5[_i];
|
2170
2166
|
custodyMetas.push({
|
2171
2167
|
isSigner: false,
|
2172
2168
|
isWritable: false,
|
2173
2169
|
pubkey: token.custodyAccount,
|
2174
2170
|
});
|
2175
2171
|
}
|
2176
|
-
for (
|
2177
|
-
custody = custodies_6[
|
2172
|
+
for (_a = 0, custodies_6 = custodies; _a < custodies_6.length; _a++) {
|
2173
|
+
custody = custodies_6[_a];
|
2178
2174
|
custodyMetas.push({
|
2179
2175
|
isSigner: false,
|
2180
2176
|
isWritable: false,
|
2181
2177
|
pubkey: custody.intOracleAccount,
|
2182
2178
|
});
|
2183
2179
|
}
|
2184
|
-
for (
|
2185
|
-
market =
|
2180
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2181
|
+
market = _c[_b];
|
2186
2182
|
marketMetas.push({
|
2187
2183
|
pubkey: market.marketAccount,
|
2188
2184
|
isSigner: false,
|
@@ -2205,14 +2201,14 @@ var PerpetualsClient = (function () {
|
|
2205
2201
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2206
2202
|
.transaction()];
|
2207
2203
|
case 1:
|
2208
|
-
transaction =
|
2204
|
+
transaction = _e.sent();
|
2209
2205
|
return [4, backUpOracleInstructionPromise];
|
2210
2206
|
case 2:
|
2211
|
-
backUpOracleInstruction =
|
2212
|
-
(
|
2207
|
+
backUpOracleInstruction = _e.sent();
|
2208
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2213
2209
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2214
2210
|
case 3:
|
2215
|
-
result =
|
2211
|
+
result = _e.sent();
|
2216
2212
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
|
2217
2213
|
res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
|
2218
2214
|
return [2, {
|
@@ -2223,40 +2219,36 @@ var PerpetualsClient = (function () {
|
|
2223
2219
|
});
|
2224
2220
|
});
|
2225
2221
|
};
|
2226
|
-
this.getRemoveLiquidityAmountAndFeeView = function (
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
var _e;
|
2234
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2235
|
-
return __generator(this, function (_f) {
|
2236
|
-
switch (_f.label) {
|
2222
|
+
this.getRemoveLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
2223
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2224
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2225
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_7, token, _a, custodies_8, custody, _b, _c, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
2226
|
+
var _d;
|
2227
|
+
return __generator(this, function (_e) {
|
2228
|
+
switch (_e.label) {
|
2237
2229
|
case 0:
|
2238
2230
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2239
2231
|
custodies = POOL_CONFIG.custodies;
|
2240
2232
|
custodyMetas = [];
|
2241
2233
|
marketMetas = [];
|
2242
|
-
for (
|
2243
|
-
token = custodies_7[
|
2234
|
+
for (_i = 0, custodies_7 = custodies; _i < custodies_7.length; _i++) {
|
2235
|
+
token = custodies_7[_i];
|
2244
2236
|
custodyMetas.push({
|
2245
2237
|
isSigner: false,
|
2246
2238
|
isWritable: false,
|
2247
2239
|
pubkey: token.custodyAccount,
|
2248
2240
|
});
|
2249
2241
|
}
|
2250
|
-
for (
|
2251
|
-
custody = custodies_8[
|
2242
|
+
for (_a = 0, custodies_8 = custodies; _a < custodies_8.length; _a++) {
|
2243
|
+
custody = custodies_8[_a];
|
2252
2244
|
custodyMetas.push({
|
2253
2245
|
isSigner: false,
|
2254
2246
|
isWritable: false,
|
2255
2247
|
pubkey: custody.intOracleAccount,
|
2256
2248
|
});
|
2257
2249
|
}
|
2258
|
-
for (
|
2259
|
-
market =
|
2250
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2251
|
+
market = _c[_b];
|
2260
2252
|
marketMetas.push({
|
2261
2253
|
pubkey: market.marketAccount,
|
2262
2254
|
isSigner: false,
|
@@ -2279,14 +2271,14 @@ var PerpetualsClient = (function () {
|
|
2279
2271
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2280
2272
|
.transaction()];
|
2281
2273
|
case 1:
|
2282
|
-
transaction =
|
2274
|
+
transaction = _e.sent();
|
2283
2275
|
return [4, backUpOracleInstructionPromise];
|
2284
2276
|
case 2:
|
2285
|
-
backUpOracleInstruction =
|
2286
|
-
(
|
2277
|
+
backUpOracleInstruction = _e.sent();
|
2278
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2287
2279
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2288
2280
|
case 3:
|
2289
|
-
result =
|
2281
|
+
result = _e.sent();
|
2290
2282
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
|
2291
2283
|
if (result.value.err) {
|
2292
2284
|
return [2, {
|
@@ -2362,40 +2354,36 @@ var PerpetualsClient = (function () {
|
|
2362
2354
|
}
|
2363
2355
|
});
|
2364
2356
|
}); };
|
2365
|
-
this.getAddCompoundingLiquidityAmountAndFeeView = function (
|
2366
|
-
|
2367
|
-
|
2368
|
-
|
2369
|
-
|
2370
|
-
|
2371
|
-
|
2372
|
-
var _e;
|
2373
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2374
|
-
return __generator(this, function (_f) {
|
2375
|
-
switch (_f.label) {
|
2357
|
+
this.getAddCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
2358
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2359
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2360
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_11, token, _a, custodies_12, custody, _b, _c, market, depositCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
|
2361
|
+
var _d;
|
2362
|
+
return __generator(this, function (_e) {
|
2363
|
+
switch (_e.label) {
|
2376
2364
|
case 0:
|
2377
2365
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2378
2366
|
custodies = POOL_CONFIG.custodies;
|
2379
2367
|
custodyMetas = [];
|
2380
2368
|
marketMetas = [];
|
2381
|
-
for (
|
2382
|
-
token = custodies_11[
|
2369
|
+
for (_i = 0, custodies_11 = custodies; _i < custodies_11.length; _i++) {
|
2370
|
+
token = custodies_11[_i];
|
2383
2371
|
custodyMetas.push({
|
2384
2372
|
isSigner: false,
|
2385
2373
|
isWritable: false,
|
2386
2374
|
pubkey: token.custodyAccount,
|
2387
2375
|
});
|
2388
2376
|
}
|
2389
|
-
for (
|
2390
|
-
custody = custodies_12[
|
2377
|
+
for (_a = 0, custodies_12 = custodies; _a < custodies_12.length; _a++) {
|
2378
|
+
custody = custodies_12[_a];
|
2391
2379
|
custodyMetas.push({
|
2392
2380
|
isSigner: false,
|
2393
2381
|
isWritable: false,
|
2394
2382
|
pubkey: custody.intOracleAccount,
|
2395
2383
|
});
|
2396
2384
|
}
|
2397
|
-
for (
|
2398
|
-
market =
|
2385
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2386
|
+
market = _c[_b];
|
2399
2387
|
marketMetas.push({
|
2400
2388
|
pubkey: market.marketAccount,
|
2401
2389
|
isSigner: false,
|
@@ -2406,7 +2394,7 @@ var PerpetualsClient = (function () {
|
|
2406
2394
|
rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
2407
2395
|
return [4, backUpOracleInstructionPromise];
|
2408
2396
|
case 1:
|
2409
|
-
backUpOracleInstruction =
|
2397
|
+
backUpOracleInstruction = _e.sent();
|
2410
2398
|
return [4, this.program.methods
|
2411
2399
|
.getAddCompoundingLiquidityAmountAndFee({
|
2412
2400
|
amountIn: amount,
|
@@ -2425,11 +2413,11 @@ var PerpetualsClient = (function () {
|
|
2425
2413
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2426
2414
|
.transaction()];
|
2427
2415
|
case 2:
|
2428
|
-
transaction =
|
2429
|
-
(
|
2416
|
+
transaction = _e.sent();
|
2417
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2430
2418
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2431
2419
|
case 3:
|
2432
|
-
result =
|
2420
|
+
result = _e.sent();
|
2433
2421
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
|
2434
2422
|
res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
|
2435
2423
|
return [2, {
|
@@ -2440,40 +2428,36 @@ var PerpetualsClient = (function () {
|
|
2440
2428
|
});
|
2441
2429
|
});
|
2442
2430
|
};
|
2443
|
-
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (
|
2444
|
-
|
2445
|
-
|
2446
|
-
|
2447
|
-
|
2448
|
-
|
2449
|
-
|
2450
|
-
var _e;
|
2451
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2452
|
-
return __generator(this, function (_f) {
|
2453
|
-
switch (_f.label) {
|
2431
|
+
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
2432
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2433
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2434
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_13, token, _a, custodies_14, custody, _b, _c, market, removeCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
|
2435
|
+
var _d;
|
2436
|
+
return __generator(this, function (_e) {
|
2437
|
+
switch (_e.label) {
|
2454
2438
|
case 0:
|
2455
2439
|
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2456
2440
|
custodies = POOL_CONFIG.custodies;
|
2457
2441
|
custodyMetas = [];
|
2458
2442
|
marketMetas = [];
|
2459
|
-
for (
|
2460
|
-
token = custodies_13[
|
2443
|
+
for (_i = 0, custodies_13 = custodies; _i < custodies_13.length; _i++) {
|
2444
|
+
token = custodies_13[_i];
|
2461
2445
|
custodyMetas.push({
|
2462
2446
|
isSigner: false,
|
2463
2447
|
isWritable: false,
|
2464
2448
|
pubkey: token.custodyAccount,
|
2465
2449
|
});
|
2466
2450
|
}
|
2467
|
-
for (
|
2468
|
-
custody = custodies_14[
|
2451
|
+
for (_a = 0, custodies_14 = custodies; _a < custodies_14.length; _a++) {
|
2452
|
+
custody = custodies_14[_a];
|
2469
2453
|
custodyMetas.push({
|
2470
2454
|
isSigner: false,
|
2471
2455
|
isWritable: false,
|
2472
2456
|
pubkey: custody.intOracleAccount,
|
2473
2457
|
});
|
2474
2458
|
}
|
2475
|
-
for (
|
2476
|
-
market =
|
2459
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2460
|
+
market = _c[_b];
|
2477
2461
|
marketMetas.push({
|
2478
2462
|
pubkey: market.marketAccount,
|
2479
2463
|
isSigner: false,
|
@@ -2484,7 +2468,7 @@ var PerpetualsClient = (function () {
|
|
2484
2468
|
rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
2485
2469
|
return [4, backUpOracleInstructionPromise];
|
2486
2470
|
case 1:
|
2487
|
-
backUpOracleInstruction =
|
2471
|
+
backUpOracleInstruction = _e.sent();
|
2488
2472
|
return [4, this.program.methods
|
2489
2473
|
.getRemoveCompoundingLiquidityAmountAndFee({
|
2490
2474
|
compoundingAmountIn: amount,
|
@@ -2503,11 +2487,11 @@ var PerpetualsClient = (function () {
|
|
2503
2487
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2504
2488
|
.transaction()];
|
2505
2489
|
case 2:
|
2506
|
-
transaction =
|
2507
|
-
(
|
2490
|
+
transaction = _e.sent();
|
2491
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2508
2492
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2509
2493
|
case 3:
|
2510
|
-
result =
|
2494
|
+
result = _e.sent();
|
2511
2495
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
|
2512
2496
|
if (result.value.err) {
|
2513
2497
|
return [2, {
|
@@ -2646,18 +2630,14 @@ var PerpetualsClient = (function () {
|
|
2646
2630
|
}
|
2647
2631
|
});
|
2648
2632
|
}); };
|
2649
|
-
this.openPosition = function (
|
2650
|
-
|
2651
|
-
|
2652
|
-
|
2653
|
-
}
|
2654
|
-
|
2633
|
+
this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2634
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2635
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2636
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2637
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2638
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2639
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2655
2640
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2656
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2657
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2658
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2659
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2660
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2661
2641
|
return __generator(this, function (_c) {
|
2662
2642
|
switch (_c.label) {
|
2663
2643
|
case 0:
|
@@ -2761,19 +2741,15 @@ var PerpetualsClient = (function () {
|
|
2761
2741
|
});
|
2762
2742
|
});
|
2763
2743
|
};
|
2764
|
-
this.closePosition = function (
|
2765
|
-
|
2766
|
-
|
2767
|
-
|
2768
|
-
}
|
2769
|
-
|
2744
|
+
this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
2745
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2746
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2747
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2748
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
2749
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2750
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2751
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2770
2752
|
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
|
2771
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2772
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2773
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2774
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
2775
|
-
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2776
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2777
2753
|
return __generator(this, function (_b) {
|
2778
2754
|
switch (_b.label) {
|
2779
2755
|
case 0:
|
@@ -2870,18 +2846,14 @@ var PerpetualsClient = (function () {
|
|
2870
2846
|
});
|
2871
2847
|
});
|
2872
2848
|
};
|
2873
|
-
this.swapAndOpen = function (
|
2874
|
-
|
2875
|
-
|
2876
|
-
|
2877
|
-
}
|
2878
|
-
|
2849
|
+
this.swapAndOpen = function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2850
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2851
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2852
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2853
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2854
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2855
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2879
2856
|
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_2;
|
2880
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2881
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2882
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2883
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2884
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2885
2857
|
return __generator(this, function (_c) {
|
2886
2858
|
switch (_c.label) {
|
2887
2859
|
case 0:
|
@@ -3021,17 +2993,13 @@ var PerpetualsClient = (function () {
|
|
3021
2993
|
});
|
3022
2994
|
});
|
3023
2995
|
};
|
3024
|
-
this.closeAndSwap = function (
|
3025
|
-
|
3026
|
-
|
3027
|
-
|
3028
|
-
}
|
3029
|
-
return __awaiter(_this,
|
2996
|
+
this.closeAndSwap = function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
|
2997
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2998
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2999
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3000
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3001
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3030
3002
|
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_3;
|
3031
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3032
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3033
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3034
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3035
3003
|
return __generator(this, function (_a) {
|
3036
3004
|
switch (_a.label) {
|
3037
3005
|
case 0:
|
@@ -3145,20 +3113,16 @@ var PerpetualsClient = (function () {
|
|
3145
3113
|
});
|
3146
3114
|
});
|
3147
3115
|
};
|
3148
|
-
this.swap = function (
|
3149
|
-
|
3150
|
-
|
3151
|
-
|
3152
|
-
}
|
3153
|
-
|
3154
|
-
|
3155
|
-
|
3156
|
-
|
3157
|
-
|
3158
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3159
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3160
|
-
return __generator(this, function (_g) {
|
3161
|
-
switch (_g.label) {
|
3116
|
+
this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
|
3117
|
+
if (useFeesPool === void 0) { useFeesPool = false; }
|
3118
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3119
|
+
if (unWrapSol === void 0) { unWrapSol = false; }
|
3120
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3121
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3122
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3123
|
+
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, _i, _e, custody, params, inx, closeWsolATAIns, err_4;
|
3124
|
+
return __generator(this, function (_f) {
|
3125
|
+
switch (_f.label) {
|
3162
3126
|
case 0:
|
3163
3127
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
3164
3128
|
if (!userInputCustodyConfig) {
|
@@ -3176,10 +3140,10 @@ var PerpetualsClient = (function () {
|
|
3176
3140
|
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
3177
3141
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
3178
3142
|
case 1:
|
3179
|
-
wsolAssociatedTokenAccount =
|
3143
|
+
wsolAssociatedTokenAccount = _f.sent();
|
3180
3144
|
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
3181
3145
|
case 2:
|
3182
|
-
wsolATAExist =
|
3146
|
+
wsolATAExist = _f.sent();
|
3183
3147
|
if (!wsolATAExist) {
|
3184
3148
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
3185
3149
|
}
|
@@ -3187,11 +3151,11 @@ var PerpetualsClient = (function () {
|
|
3187
3151
|
_a = anchor_1.BN.bind;
|
3188
3152
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3189
3153
|
case 3:
|
3190
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
3154
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3191
3155
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3192
3156
|
throw "Insufficient SOL Funds";
|
3193
3157
|
}
|
3194
|
-
|
3158
|
+
_f.label = 4;
|
3195
3159
|
case 4:
|
3196
3160
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
3197
3161
|
fromPubkey: publicKey,
|
@@ -3213,20 +3177,20 @@ var PerpetualsClient = (function () {
|
|
3213
3177
|
additionalSigners: additionalSigners
|
3214
3178
|
}];
|
3215
3179
|
}
|
3216
|
-
|
3180
|
+
_f.label = 6;
|
3217
3181
|
case 6:
|
3218
|
-
|
3182
|
+
_f.trys.push([6, 19, , 20]);
|
3219
3183
|
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
3220
3184
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
3221
3185
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3222
3186
|
case 7:
|
3223
|
-
accCreationLamports = (
|
3187
|
+
accCreationLamports = (_f.sent());
|
3224
3188
|
console.log("accCreationLamports:", accCreationLamports);
|
3225
3189
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3226
3190
|
_b = anchor_1.BN.bind;
|
3227
3191
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3228
3192
|
case 8:
|
3229
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0,
|
3193
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3230
3194
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3231
3195
|
throw "Insufficient SOL Funds";
|
3232
3196
|
}
|
@@ -3253,18 +3217,18 @@ var PerpetualsClient = (function () {
|
|
3253
3217
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
3254
3218
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3255
3219
|
case 10:
|
3256
|
-
if (!(
|
3220
|
+
if (!(_f.sent())) {
|
3257
3221
|
throw "Insufficient Funds , Token Account doesn't exist";
|
3258
3222
|
}
|
3259
3223
|
if (!!skipBalanceChecks) return [3, 12];
|
3260
3224
|
_c = anchor_1.BN.bind;
|
3261
3225
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3262
3226
|
case 11:
|
3263
|
-
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (
|
3227
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
3264
3228
|
if (tokenAccountBalance.lt(amountIn)) {
|
3265
3229
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3266
3230
|
}
|
3267
|
-
|
3231
|
+
_f.label = 12;
|
3268
3232
|
case 12:
|
3269
3233
|
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
3270
3234
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
@@ -3289,23 +3253,23 @@ var PerpetualsClient = (function () {
|
|
3289
3253
|
return [3, 17];
|
3290
3254
|
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
3291
3255
|
case 14:
|
3292
|
-
userOutputTokenAccount =
|
3256
|
+
userOutputTokenAccount = _f.sent();
|
3293
3257
|
_d = createUserATA;
|
3294
3258
|
if (!_d) return [3, 16];
|
3295
3259
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
3296
3260
|
case 15:
|
3297
|
-
_d = !(
|
3298
|
-
|
3261
|
+
_d = !(_f.sent());
|
3262
|
+
_f.label = 16;
|
3299
3263
|
case 16:
|
3300
3264
|
if (_d) {
|
3301
3265
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
3302
3266
|
}
|
3303
|
-
|
3267
|
+
_f.label = 17;
|
3304
3268
|
case 17:
|
3305
3269
|
custodyAccountMetas = [];
|
3306
3270
|
custodyOracleAccountMetas = [];
|
3307
|
-
for (
|
3308
|
-
custody =
|
3271
|
+
for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
|
3272
|
+
custody = _e[_i];
|
3309
3273
|
custodyAccountMetas.push({
|
3310
3274
|
pubkey: custody.custodyAccount,
|
3311
3275
|
isSigner: false,
|
@@ -3345,7 +3309,7 @@ var PerpetualsClient = (function () {
|
|
3345
3309
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3346
3310
|
.instruction()];
|
3347
3311
|
case 18:
|
3348
|
-
inx =
|
3312
|
+
inx = _f.sent();
|
3349
3313
|
instructions.push(inx);
|
3350
3314
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
3351
3315
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
@@ -3353,7 +3317,7 @@ var PerpetualsClient = (function () {
|
|
3353
3317
|
}
|
3354
3318
|
return [3, 20];
|
3355
3319
|
case 19:
|
3356
|
-
err_4 =
|
3320
|
+
err_4 = _f.sent();
|
3357
3321
|
console.error("perpClient Swap error:: ", err_4);
|
3358
3322
|
throw err_4;
|
3359
3323
|
case 20: return [2, {
|
@@ -3435,15 +3399,11 @@ var PerpetualsClient = (function () {
|
|
3435
3399
|
}
|
3436
3400
|
});
|
3437
3401
|
}); };
|
3438
|
-
this.addCollateral = function (
|
3439
|
-
|
3440
|
-
|
3441
|
-
|
3442
|
-
}
|
3443
|
-
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) {
|
3402
|
+
this.addCollateral = function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3403
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3404
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3405
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3444
3406
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
3445
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3446
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3447
3407
|
return __generator(this, function (_c) {
|
3448
3408
|
switch (_c.label) {
|
3449
3409
|
case 0:
|
@@ -3537,15 +3497,11 @@ var PerpetualsClient = (function () {
|
|
3537
3497
|
});
|
3538
3498
|
});
|
3539
3499
|
};
|
3540
|
-
this.swapAndAddCollateral = function (
|
3541
|
-
|
3542
|
-
|
3543
|
-
|
3544
|
-
}
|
3545
|
-
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) {
|
3500
|
+
this.swapAndAddCollateral = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3501
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3502
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3503
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3546
3504
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
3547
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3548
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3549
3505
|
return __generator(this, function (_c) {
|
3550
3506
|
switch (_c.label) {
|
3551
3507
|
case 0:
|
@@ -3656,16 +3612,12 @@ var PerpetualsClient = (function () {
|
|
3656
3612
|
});
|
3657
3613
|
});
|
3658
3614
|
};
|
3659
|
-
this.removeCollateral = function (
|
3660
|
-
|
3661
|
-
|
3662
|
-
|
3663
|
-
|
3664
|
-
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) {
|
3615
|
+
this.removeCollateral = function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3616
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3617
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3618
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3619
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3665
3620
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_3;
|
3666
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
3667
|
-
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3668
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3669
3621
|
return __generator(this, function (_b) {
|
3670
3622
|
switch (_b.label) {
|
3671
3623
|
case 0:
|
@@ -3766,14 +3718,10 @@ var PerpetualsClient = (function () {
|
|
3766
3718
|
});
|
3767
3719
|
});
|
3768
3720
|
};
|
3769
|
-
this.removeCollateralAndSwap = function (
|
3770
|
-
|
3771
|
-
|
3772
|
-
args_1[_i - 7] = arguments[_i];
|
3773
|
-
}
|
3774
|
-
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) {
|
3721
|
+
this.removeCollateralAndSwap = function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
|
3722
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3723
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3775
3724
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
|
3776
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3777
3725
|
return __generator(this, function (_a) {
|
3778
3726
|
switch (_a.label) {
|
3779
3727
|
case 0:
|
@@ -3866,16 +3814,12 @@ var PerpetualsClient = (function () {
|
|
3866
3814
|
});
|
3867
3815
|
});
|
3868
3816
|
};
|
3869
|
-
this.increaseSize = function (
|
3870
|
-
|
3871
|
-
|
3872
|
-
|
3873
|
-
|
3874
|
-
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) {
|
3817
|
+
this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3818
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3819
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3820
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3821
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3875
3822
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3876
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3877
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3878
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3879
3823
|
return __generator(this, function (_a) {
|
3880
3824
|
switch (_a.label) {
|
3881
3825
|
case 0:
|
@@ -3930,16 +3874,12 @@ var PerpetualsClient = (function () {
|
|
3930
3874
|
});
|
3931
3875
|
});
|
3932
3876
|
};
|
3933
|
-
this.decreaseSize = function (
|
3934
|
-
|
3935
|
-
|
3936
|
-
|
3937
|
-
|
3938
|
-
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) {
|
3877
|
+
this.decreaseSize = function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3878
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3879
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3880
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3881
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3939
3882
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3940
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3941
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3942
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3943
3883
|
return __generator(this, function (_a) {
|
3944
3884
|
switch (_a.label) {
|
3945
3885
|
case 0:
|
@@ -3994,17 +3934,13 @@ var PerpetualsClient = (function () {
|
|
3994
3934
|
});
|
3995
3935
|
});
|
3996
3936
|
};
|
3997
|
-
this.addLiquidity = function (
|
3998
|
-
|
3999
|
-
|
4000
|
-
|
4001
|
-
|
4002
|
-
|
4003
|
-
|
4004
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4005
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4006
|
-
return __generator(this, function (_g) {
|
4007
|
-
switch (_g.label) {
|
3937
|
+
this.addLiquidity = function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3938
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3939
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3940
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3941
|
+
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_6;
|
3942
|
+
return __generator(this, function (_f) {
|
3943
|
+
switch (_f.label) {
|
4008
3944
|
case 0:
|
4009
3945
|
publicKey = this.provider.wallet.publicKey;
|
4010
3946
|
payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
|
@@ -4015,16 +3951,16 @@ var PerpetualsClient = (function () {
|
|
4015
3951
|
instructions = [];
|
4016
3952
|
postInstructions = [];
|
4017
3953
|
additionalSigners = [];
|
4018
|
-
|
3954
|
+
_f.label = 1;
|
4019
3955
|
case 1:
|
4020
|
-
|
3956
|
+
_f.trys.push([1, 10, , 11]);
|
4021
3957
|
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
|
4022
3958
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4023
3959
|
custodyAccountMetas = [];
|
4024
3960
|
custodyOracleAccountMetas = [];
|
4025
3961
|
markets = [];
|
4026
|
-
for (
|
4027
|
-
custody =
|
3962
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
3963
|
+
custody = _a[_i];
|
4028
3964
|
custodyAccountMetas.push({
|
4029
3965
|
pubkey: custody.custodyAccount,
|
4030
3966
|
isSigner: false,
|
@@ -4036,8 +3972,8 @@ var PerpetualsClient = (function () {
|
|
4036
3972
|
isWritable: false,
|
4037
3973
|
});
|
4038
3974
|
}
|
4039
|
-
for (
|
4040
|
-
market =
|
3975
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
3976
|
+
market = _c[_b];
|
4041
3977
|
markets.push({
|
4042
3978
|
pubkey: market.marketAccount,
|
4043
3979
|
isSigner: false,
|
@@ -4046,21 +3982,21 @@ var PerpetualsClient = (function () {
|
|
4046
3982
|
}
|
4047
3983
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4048
3984
|
case 2:
|
4049
|
-
if (!(
|
3985
|
+
if (!(_f.sent())) {
|
4050
3986
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4051
3987
|
}
|
4052
3988
|
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
4053
3989
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
4054
3990
|
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
4055
3991
|
if (!!skipBalanceChecks) return [3, 4];
|
4056
|
-
|
3992
|
+
_d = anchor_1.BN.bind;
|
4057
3993
|
return [4, this.provider.connection.getBalance(publicKey)];
|
4058
3994
|
case 3:
|
4059
|
-
unWrappedSolBalance = new (
|
3995
|
+
unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
4060
3996
|
if (unWrappedSolBalance.lt(lamports)) {
|
4061
3997
|
throw "Insufficient SOL Funds";
|
4062
3998
|
}
|
4063
|
-
|
3999
|
+
_f.label = 4;
|
4064
4000
|
case 4:
|
4065
4001
|
if (!ephemeralSignerPubkey) {
|
4066
4002
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -4084,17 +4020,17 @@ var PerpetualsClient = (function () {
|
|
4084
4020
|
if (!!skipBalanceChecks) return [3, 8];
|
4085
4021
|
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
4086
4022
|
case 6:
|
4087
|
-
if (!(
|
4023
|
+
if (!(_f.sent())) {
|
4088
4024
|
throw "Insufficient Funds , token Account doesn't exist";
|
4089
4025
|
}
|
4090
|
-
|
4026
|
+
_e = anchor_1.BN.bind;
|
4091
4027
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
4092
4028
|
case 7:
|
4093
|
-
tokenAccountBalance = new (
|
4029
|
+
tokenAccountBalance = new (_e.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
4094
4030
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
4095
4031
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
4096
4032
|
}
|
4097
|
-
|
4033
|
+
_f.label = 8;
|
4098
4034
|
case 8: return [4, this.program.methods
|
4099
4035
|
.addLiquidity({
|
4100
4036
|
amountIn: tokenAmountIn,
|
@@ -4119,11 +4055,11 @@ var PerpetualsClient = (function () {
|
|
4119
4055
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4120
4056
|
.instruction()];
|
4121
4057
|
case 9:
|
4122
|
-
instruction =
|
4058
|
+
instruction = _f.sent();
|
4123
4059
|
instructions.push(instruction);
|
4124
4060
|
return [3, 11];
|
4125
4061
|
case 10:
|
4126
|
-
err_6 =
|
4062
|
+
err_6 = _f.sent();
|
4127
4063
|
console.error("perpClient addLiquidity error:: ", err_6);
|
4128
4064
|
throw err_6;
|
4129
4065
|
case 11: return [2, {
|
@@ -4134,18 +4070,14 @@ var PerpetualsClient = (function () {
|
|
4134
4070
|
});
|
4135
4071
|
});
|
4136
4072
|
};
|
4137
|
-
this.addLiquidityAndStake = function (
|
4138
|
-
|
4139
|
-
|
4140
|
-
|
4141
|
-
|
4142
|
-
|
4143
|
-
|
4144
|
-
|
4145
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4146
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4147
|
-
return __generator(this, function (_g) {
|
4148
|
-
switch (_g.label) {
|
4073
|
+
this.addLiquidityAndStake = function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
4074
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4075
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4076
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4077
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4078
|
+
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, instruction;
|
4079
|
+
return __generator(this, function (_f) {
|
4080
|
+
switch (_f.label) {
|
4149
4081
|
case 0:
|
4150
4082
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4151
4083
|
preInstructions = [];
|
@@ -4165,14 +4097,14 @@ var PerpetualsClient = (function () {
|
|
4165
4097
|
_a = anchor_1.BN.bind;
|
4166
4098
|
return [4, this.provider.connection.getBalance(publicKey)];
|
4167
4099
|
case 1:
|
4168
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
4100
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
4169
4101
|
if (unWrappedSolBalance.lt(lamports)) {
|
4170
4102
|
throw "Insufficient SOL Funds";
|
4171
4103
|
}
|
4172
|
-
|
4104
|
+
_f.label = 2;
|
4173
4105
|
case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4174
4106
|
case 3:
|
4175
|
-
if (!(
|
4107
|
+
if (!(_f.sent())) {
|
4176
4108
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4177
4109
|
}
|
4178
4110
|
if (!ephemeralSignerPubkey) {
|
@@ -4198,23 +4130,23 @@ var PerpetualsClient = (function () {
|
|
4198
4130
|
if (!!skipBalanceChecks) return [3, 7];
|
4199
4131
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
4200
4132
|
case 5:
|
4201
|
-
if (!(
|
4133
|
+
if (!(_f.sent())) {
|
4202
4134
|
throw "Insufficient Funds , token Account doesn't exist";
|
4203
4135
|
}
|
4204
4136
|
_b = anchor_1.BN.bind;
|
4205
4137
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
4206
4138
|
case 6:
|
4207
|
-
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (
|
4139
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
4208
4140
|
if (tokenAccountBalance.lt(amountIn)) {
|
4209
4141
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
4210
4142
|
}
|
4211
|
-
|
4143
|
+
_f.label = 7;
|
4212
4144
|
case 7:
|
4213
4145
|
custodyAccountMetas = [];
|
4214
4146
|
custodyOracleAccountMetas = [];
|
4215
4147
|
markets = [];
|
4216
|
-
for (
|
4217
|
-
custody =
|
4148
|
+
for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
|
4149
|
+
custody = _c[_i];
|
4218
4150
|
custodyAccountMetas.push({
|
4219
4151
|
pubkey: custody.custodyAccount,
|
4220
4152
|
isSigner: false,
|
@@ -4226,8 +4158,8 @@ var PerpetualsClient = (function () {
|
|
4226
4158
|
isWritable: false,
|
4227
4159
|
});
|
4228
4160
|
}
|
4229
|
-
for (
|
4230
|
-
market =
|
4161
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
4162
|
+
market = _e[_d];
|
4231
4163
|
markets.push({
|
4232
4164
|
pubkey: market.marketAccount,
|
4233
4165
|
isSigner: false,
|
@@ -4259,7 +4191,7 @@ var PerpetualsClient = (function () {
|
|
4259
4191
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4260
4192
|
.instruction()];
|
4261
4193
|
case 8:
|
4262
|
-
instruction =
|
4194
|
+
instruction = _f.sent();
|
4263
4195
|
instructions.push(instruction);
|
4264
4196
|
return [2, {
|
4265
4197
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4269,20 +4201,16 @@ var PerpetualsClient = (function () {
|
|
4269
4201
|
});
|
4270
4202
|
});
|
4271
4203
|
};
|
4272
|
-
this.removeLiquidity = function (
|
4273
|
-
|
4274
|
-
|
4275
|
-
|
4276
|
-
}
|
4277
|
-
|
4278
|
-
|
4279
|
-
|
4280
|
-
|
4281
|
-
|
4282
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4283
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4284
|
-
return __generator(this, function (_f) {
|
4285
|
-
switch (_f.label) {
|
4204
|
+
this.removeLiquidity = function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
|
4205
|
+
if (closeLpATA === void 0) { closeLpATA = false; }
|
4206
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4207
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
4208
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4209
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4210
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4211
|
+
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, _d, removeLiquidityTx, closeInx, closeWsolATAIns, err_7;
|
4212
|
+
return __generator(this, function (_e) {
|
4213
|
+
switch (_e.label) {
|
4286
4214
|
case 0:
|
4287
4215
|
recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
|
4288
4216
|
if (!recieveTokenCustodyConfig) {
|
@@ -4293,15 +4221,15 @@ var PerpetualsClient = (function () {
|
|
4293
4221
|
instructions = [];
|
4294
4222
|
postInstructions = [];
|
4295
4223
|
additionalSigners = [];
|
4296
|
-
|
4224
|
+
_e.label = 1;
|
4297
4225
|
case 1:
|
4298
|
-
|
4226
|
+
_e.trys.push([1, 7, , 8]);
|
4299
4227
|
stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4300
4228
|
custodyAccountMetas = [];
|
4301
4229
|
custodyOracleAccountMetas = [];
|
4302
4230
|
markets = [];
|
4303
|
-
for (
|
4304
|
-
custody =
|
4231
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
4232
|
+
custody = _a[_i];
|
4305
4233
|
custodyAccountMetas.push({
|
4306
4234
|
pubkey: custody.custodyAccount,
|
4307
4235
|
isSigner: false,
|
@@ -4313,8 +4241,8 @@ var PerpetualsClient = (function () {
|
|
4313
4241
|
isWritable: false,
|
4314
4242
|
});
|
4315
4243
|
}
|
4316
|
-
for (
|
4317
|
-
market =
|
4244
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
4245
|
+
market = _c[_b];
|
4318
4246
|
markets.push({
|
4319
4247
|
pubkey: market.marketAccount,
|
4320
4248
|
isSigner: false,
|
@@ -4343,17 +4271,17 @@ var PerpetualsClient = (function () {
|
|
4343
4271
|
return [3, 5];
|
4344
4272
|
case 2:
|
4345
4273
|
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
|
4346
|
-
|
4347
|
-
if (!
|
4274
|
+
_d = createUserATA;
|
4275
|
+
if (!_d) return [3, 4];
|
4348
4276
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
4349
4277
|
case 3:
|
4350
|
-
|
4351
|
-
|
4278
|
+
_d = !(_e.sent());
|
4279
|
+
_e.label = 4;
|
4352
4280
|
case 4:
|
4353
|
-
if (
|
4281
|
+
if (_d) {
|
4354
4282
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
|
4355
4283
|
}
|
4356
|
-
|
4284
|
+
_e.label = 5;
|
4357
4285
|
case 5: return [4, this.program.methods
|
4358
4286
|
.removeLiquidity({
|
4359
4287
|
lpAmountIn: liquidityAmountIn,
|
@@ -4378,7 +4306,7 @@ var PerpetualsClient = (function () {
|
|
4378
4306
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4379
4307
|
.instruction()];
|
4380
4308
|
case 6:
|
4381
|
-
removeLiquidityTx =
|
4309
|
+
removeLiquidityTx = _e.sent();
|
4382
4310
|
instructions.push(removeLiquidityTx);
|
4383
4311
|
if (closeLpATA) {
|
4384
4312
|
closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
|
@@ -4390,7 +4318,7 @@ var PerpetualsClient = (function () {
|
|
4390
4318
|
}
|
4391
4319
|
return [3, 8];
|
4392
4320
|
case 7:
|
4393
|
-
err_7 =
|
4321
|
+
err_7 = _e.sent();
|
4394
4322
|
console.log("perpClient removeLiquidity error:: ", err_7);
|
4395
4323
|
throw err_7;
|
4396
4324
|
case 8: return [2, {
|
@@ -4808,26 +4736,22 @@ var PerpetualsClient = (function () {
|
|
4808
4736
|
}
|
4809
4737
|
});
|
4810
4738
|
}); };
|
4811
|
-
this.refreshStakeWithTokenStake = function (
|
4812
|
-
|
4813
|
-
|
4814
|
-
|
4815
|
-
|
4816
|
-
|
4817
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_16;
|
4818
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4819
|
-
return __generator(this, function (_c) {
|
4820
|
-
switch (_c.label) {
|
4739
|
+
this.refreshStakeWithTokenStake = function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4740
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4741
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4742
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_16;
|
4743
|
+
return __generator(this, function (_b) {
|
4744
|
+
switch (_b.label) {
|
4821
4745
|
case 0:
|
4822
|
-
|
4746
|
+
_b.trys.push([0, 2, , 3]);
|
4823
4747
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4824
4748
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
4825
4749
|
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
4826
4750
|
pool = poolConfig.poolAddress;
|
4827
4751
|
feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
|
4828
4752
|
custodyAccountMetas = [];
|
4829
|
-
for (
|
4830
|
-
custody =
|
4753
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
4754
|
+
custody = _a[_i];
|
4831
4755
|
custodyAccountMetas.push({
|
4832
4756
|
pubkey: custody.custodyAccount,
|
4833
4757
|
isSigner: false,
|
@@ -4859,10 +4783,10 @@ var PerpetualsClient = (function () {
|
|
4859
4783
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
|
4860
4784
|
.instruction()];
|
4861
4785
|
case 1:
|
4862
|
-
refreshStakeInstruction =
|
4786
|
+
refreshStakeInstruction = _b.sent();
|
4863
4787
|
return [2, refreshStakeInstruction];
|
4864
4788
|
case 2:
|
4865
|
-
err_16 =
|
4789
|
+
err_16 = _b.sent();
|
4866
4790
|
console.log("perpClient refreshStaking error:: ", err_16);
|
4867
4791
|
throw err_16;
|
4868
4792
|
case 3: return [2];
|
@@ -5029,16 +4953,12 @@ var PerpetualsClient = (function () {
|
|
5029
4953
|
}
|
5030
4954
|
});
|
5031
4955
|
}); };
|
5032
|
-
this.withdrawStake = function (
|
5033
|
-
|
5034
|
-
|
5035
|
-
|
5036
|
-
|
5037
|
-
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA) {
|
4956
|
+
this.withdrawStake = function (poolConfig, pendingActivation, deactivated, createUserLPTA) {
|
4957
|
+
if (pendingActivation === void 0) { pendingActivation = true; }
|
4958
|
+
if (deactivated === void 0) { deactivated = true; }
|
4959
|
+
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
4960
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5038
4961
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_20;
|
5039
|
-
if (pendingActivation === void 0) { pendingActivation = true; }
|
5040
|
-
if (deactivated === void 0) { deactivated = true; }
|
5041
|
-
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
5042
4962
|
return __generator(this, function (_b) {
|
5043
4963
|
switch (_b.label) {
|
5044
4964
|
case 0:
|
@@ -5100,14 +5020,10 @@ var PerpetualsClient = (function () {
|
|
5100
5020
|
});
|
5101
5021
|
});
|
5102
5022
|
};
|
5103
|
-
this.collectStakeFees = function (
|
5104
|
-
|
5105
|
-
|
5106
|
-
args_1[_i - 3] = arguments[_i];
|
5107
|
-
}
|
5108
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
5023
|
+
this.collectStakeFees = function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
5024
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5025
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5109
5026
|
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_21;
|
5110
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5111
5027
|
return __generator(this, function (_b) {
|
5112
5028
|
switch (_b.label) {
|
5113
5029
|
case 0:
|
@@ -5253,6 +5169,7 @@ var PerpetualsClient = (function () {
|
|
5253
5169
|
admin: publicKey,
|
5254
5170
|
multisig: this.multisig.publicKey,
|
5255
5171
|
tokenVault: poolConfig.tokenVault,
|
5172
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
5256
5173
|
})
|
5257
5174
|
.instruction()];
|
5258
5175
|
case 2:
|
@@ -5319,8 +5236,56 @@ var PerpetualsClient = (function () {
|
|
5319
5236
|
}
|
5320
5237
|
});
|
5321
5238
|
}); };
|
5239
|
+
this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5240
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_25;
|
5241
|
+
return __generator(this, function (_a) {
|
5242
|
+
switch (_a.label) {
|
5243
|
+
case 0:
|
5244
|
+
publicKey = this.provider.wallet.publicKey;
|
5245
|
+
preInstructions = [];
|
5246
|
+
instructions = [];
|
5247
|
+
postInstructions = [];
|
5248
|
+
additionalSigners = [];
|
5249
|
+
_a.label = 1;
|
5250
|
+
case 1:
|
5251
|
+
_a.trys.push([1, 3, , 4]);
|
5252
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5253
|
+
return [4, this.program.methods
|
5254
|
+
.initRevenueTokenAccount({
|
5255
|
+
feeShareBps: feeShareBps
|
5256
|
+
})
|
5257
|
+
.accounts({
|
5258
|
+
admin: publicKey,
|
5259
|
+
multisig: this.multisig.publicKey,
|
5260
|
+
perpetuals: this.perpetuals.publicKey,
|
5261
|
+
transferAuthority: poolConfig.transferAuthority,
|
5262
|
+
tokenVault: poolConfig.tokenVault,
|
5263
|
+
rewardMint: rewardCustodyMint,
|
5264
|
+
revenueTokenAccount: poolConfig.revenueTokenAccount,
|
5265
|
+
protocolVault: poolConfig.protocolVault,
|
5266
|
+
protocolTokenAccount: poolConfig.protocolTokenAccount,
|
5267
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
5268
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5269
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
5270
|
+
})
|
5271
|
+
.instruction()];
|
5272
|
+
case 2:
|
5273
|
+
initRevenueTokenAccountInstruction = _a.sent();
|
5274
|
+
instructions.push(initRevenueTokenAccountInstruction);
|
5275
|
+
return [3, 4];
|
5276
|
+
case 3:
|
5277
|
+
err_25 = _a.sent();
|
5278
|
+
console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_25);
|
5279
|
+
throw err_25;
|
5280
|
+
case 4: return [2, {
|
5281
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5282
|
+
additionalSigners: additionalSigners
|
5283
|
+
}];
|
5284
|
+
}
|
5285
|
+
});
|
5286
|
+
}); };
|
5322
5287
|
this.burnAndClaim = function (owner, nftMint, poolConfig, createAta) { return __awaiter(_this, void 0, void 0, function () {
|
5323
|
-
var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction,
|
5288
|
+
var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction, err_26;
|
5324
5289
|
return __generator(this, function (_b) {
|
5325
5290
|
switch (_b.label) {
|
5326
5291
|
case 0:
|
@@ -5384,9 +5349,9 @@ var PerpetualsClient = (function () {
|
|
5384
5349
|
instructions.push(burnAndClaimInstruction);
|
5385
5350
|
return [3, 8];
|
5386
5351
|
case 7:
|
5387
|
-
|
5388
|
-
console.log("perpClient burnAndClaimInstruction error:: ",
|
5389
|
-
throw
|
5352
|
+
err_26 = _b.sent();
|
5353
|
+
console.log("perpClient burnAndClaimInstruction error:: ", err_26);
|
5354
|
+
throw err_26;
|
5390
5355
|
case 8: return [2, {
|
5391
5356
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5392
5357
|
additionalSigners: additionalSigners
|
@@ -5395,7 +5360,7 @@ var PerpetualsClient = (function () {
|
|
5395
5360
|
});
|
5396
5361
|
}); };
|
5397
5362
|
this.burnAndStake = function (owner, feePayer, nftMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5398
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction,
|
5363
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction, err_27;
|
5399
5364
|
return __generator(this, function (_a) {
|
5400
5365
|
switch (_a.label) {
|
5401
5366
|
case 0:
|
@@ -5446,9 +5411,9 @@ var PerpetualsClient = (function () {
|
|
5446
5411
|
instructions.push(burnAndStakeInstruction);
|
5447
5412
|
return [3, 4];
|
5448
5413
|
case 3:
|
5449
|
-
|
5450
|
-
console.log("perpClient burnAndStakeInstruction error:: ",
|
5451
|
-
throw
|
5414
|
+
err_27 = _a.sent();
|
5415
|
+
console.log("perpClient burnAndStakeInstruction error:: ", err_27);
|
5416
|
+
throw err_27;
|
5452
5417
|
case 4: return [2, {
|
5453
5418
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5454
5419
|
additionalSigners: additionalSigners
|
@@ -5457,7 +5422,7 @@ var PerpetualsClient = (function () {
|
|
5457
5422
|
});
|
5458
5423
|
}); };
|
5459
5424
|
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5460
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction,
|
5425
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_28;
|
5461
5426
|
return __generator(this, function (_a) {
|
5462
5427
|
switch (_a.label) {
|
5463
5428
|
case 0:
|
@@ -5498,9 +5463,9 @@ var PerpetualsClient = (function () {
|
|
5498
5463
|
instructions.push(depositTokenStakeInstruction);
|
5499
5464
|
return [3, 5];
|
5500
5465
|
case 4:
|
5501
|
-
|
5502
|
-
console.log("perpClient depositStakingInstruction error:: ",
|
5503
|
-
throw
|
5466
|
+
err_28 = _a.sent();
|
5467
|
+
console.log("perpClient depositStakingInstruction error:: ", err_28);
|
5468
|
+
throw err_28;
|
5504
5469
|
case 5: return [2, {
|
5505
5470
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5506
5471
|
additionalSigners: additionalSigners
|
@@ -5509,7 +5474,7 @@ var PerpetualsClient = (function () {
|
|
5509
5474
|
});
|
5510
5475
|
}); };
|
5511
5476
|
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5512
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction,
|
5477
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_29;
|
5513
5478
|
return __generator(this, function (_a) {
|
5514
5479
|
switch (_a.label) {
|
5515
5480
|
case 0:
|
@@ -5538,9 +5503,9 @@ var PerpetualsClient = (function () {
|
|
5538
5503
|
instructions.push(unstakeTokenRequestInstruction);
|
5539
5504
|
return [3, 4];
|
5540
5505
|
case 3:
|
5541
|
-
|
5542
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
5543
|
-
throw
|
5506
|
+
err_29 = _a.sent();
|
5507
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_29);
|
5508
|
+
throw err_29;
|
5544
5509
|
case 4: return [2, {
|
5545
5510
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5546
5511
|
additionalSigners: additionalSigners
|
@@ -5549,7 +5514,7 @@ var PerpetualsClient = (function () {
|
|
5549
5514
|
});
|
5550
5515
|
}); };
|
5551
5516
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5552
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
5517
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_30;
|
5553
5518
|
return __generator(this, function (_a) {
|
5554
5519
|
switch (_a.label) {
|
5555
5520
|
case 0:
|
@@ -5589,9 +5554,9 @@ var PerpetualsClient = (function () {
|
|
5589
5554
|
instructions.push(unstakeTokenInstantInstruction);
|
5590
5555
|
return [3, 5];
|
5591
5556
|
case 4:
|
5592
|
-
|
5593
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
5594
|
-
throw
|
5557
|
+
err_30 = _a.sent();
|
5558
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_30);
|
5559
|
+
throw err_30;
|
5595
5560
|
case 5: return [2, {
|
5596
5561
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5597
5562
|
additionalSigners: additionalSigners
|
@@ -5600,7 +5565,7 @@ var PerpetualsClient = (function () {
|
|
5600
5565
|
});
|
5601
5566
|
}); };
|
5602
5567
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5603
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
5568
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_31;
|
5604
5569
|
return __generator(this, function (_a) {
|
5605
5570
|
switch (_a.label) {
|
5606
5571
|
case 0:
|
@@ -5640,9 +5605,9 @@ var PerpetualsClient = (function () {
|
|
5640
5605
|
instructions.push(withdrawTokenInstruction);
|
5641
5606
|
return [3, 5];
|
5642
5607
|
case 4:
|
5643
|
-
|
5644
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
5645
|
-
throw
|
5608
|
+
err_31 = _a.sent();
|
5609
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_31);
|
5610
|
+
throw err_31;
|
5646
5611
|
case 5: return [2, {
|
5647
5612
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5648
5613
|
additionalSigners: additionalSigners
|
@@ -5651,7 +5616,7 @@ var PerpetualsClient = (function () {
|
|
5651
5616
|
});
|
5652
5617
|
}); };
|
5653
5618
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5654
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
5619
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_32;
|
5655
5620
|
return __generator(this, function (_a) {
|
5656
5621
|
switch (_a.label) {
|
5657
5622
|
case 0:
|
@@ -5680,9 +5645,9 @@ var PerpetualsClient = (function () {
|
|
5680
5645
|
instructions.push(cancelUnstakeRequestInstruction);
|
5681
5646
|
return [3, 4];
|
5682
5647
|
case 3:
|
5683
|
-
|
5684
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
5685
|
-
throw
|
5648
|
+
err_32 = _a.sent();
|
5649
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_32);
|
5650
|
+
throw err_32;
|
5686
5651
|
case 4: return [2, {
|
5687
5652
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5688
5653
|
additionalSigners: additionalSigners
|
@@ -5690,8 +5655,8 @@ var PerpetualsClient = (function () {
|
|
5690
5655
|
}
|
5691
5656
|
});
|
5692
5657
|
}); };
|
5693
|
-
this.distributeTokenReward = function (amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5694
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, fundingTokenAccount, distributeTokenRewardInstruction,
|
5658
|
+
this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5659
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_33;
|
5695
5660
|
return __generator(this, function (_a) {
|
5696
5661
|
switch (_a.label) {
|
5697
5662
|
case 0:
|
@@ -5703,7 +5668,9 @@ var PerpetualsClient = (function () {
|
|
5703
5668
|
_a.label = 1;
|
5704
5669
|
case 1:
|
5705
5670
|
_a.trys.push([1, 3, , 4]);
|
5671
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5706
5672
|
fundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, publicKey, true);
|
5673
|
+
revenueFundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5707
5674
|
return [4, this.program.methods
|
5708
5675
|
.distributeTokenReward({
|
5709
5676
|
amount: amount,
|
@@ -5727,9 +5694,9 @@ var PerpetualsClient = (function () {
|
|
5727
5694
|
instructions.push(distributeTokenRewardInstruction);
|
5728
5695
|
return [3, 4];
|
5729
5696
|
case 3:
|
5730
|
-
|
5731
|
-
console.log("perpClient distributeTokenRewardInstruction error:: ",
|
5732
|
-
throw
|
5697
|
+
err_33 = _a.sent();
|
5698
|
+
console.log("perpClient distributeTokenRewardInstruction error:: ", err_33);
|
5699
|
+
throw err_33;
|
5733
5700
|
case 4: return [2, {
|
5734
5701
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5735
5702
|
additionalSigners: additionalSigners
|
@@ -5738,7 +5705,7 @@ var PerpetualsClient = (function () {
|
|
5738
5705
|
});
|
5739
5706
|
}); };
|
5740
5707
|
this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5741
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction,
|
5708
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_34;
|
5742
5709
|
return __generator(this, function (_a) {
|
5743
5710
|
switch (_a.label) {
|
5744
5711
|
case 0:
|
@@ -5770,9 +5737,9 @@ var PerpetualsClient = (function () {
|
|
5770
5737
|
instructions.push(setTokenRewardInstruction);
|
5771
5738
|
return [3, 4];
|
5772
5739
|
case 3:
|
5773
|
-
|
5774
|
-
console.log("perpClient setTokenRewardInstruction error:: ",
|
5775
|
-
throw
|
5740
|
+
err_34 = _a.sent();
|
5741
|
+
console.log("perpClient setTokenRewardInstruction error:: ", err_34);
|
5742
|
+
throw err_34;
|
5776
5743
|
case 4: return [2, {
|
5777
5744
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5778
5745
|
additionalSigners: additionalSigners
|
@@ -5780,14 +5747,10 @@ var PerpetualsClient = (function () {
|
|
5780
5747
|
}
|
5781
5748
|
});
|
5782
5749
|
}); };
|
5783
|
-
this.collectTokenReward = function (
|
5784
|
-
|
5785
|
-
|
5786
|
-
|
5787
|
-
}
|
5788
|
-
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5789
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_34;
|
5790
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5750
|
+
this.collectTokenReward = function (owner, poolConfig, createUserATA) {
|
5751
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5752
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5753
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_35;
|
5791
5754
|
return __generator(this, function (_b) {
|
5792
5755
|
switch (_b.label) {
|
5793
5756
|
case 0:
|
@@ -5831,9 +5794,68 @@ var PerpetualsClient = (function () {
|
|
5831
5794
|
instructions.push(collectTokenRewardInstruction);
|
5832
5795
|
return [3, 6];
|
5833
5796
|
case 5:
|
5834
|
-
|
5835
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
5836
|
-
throw
|
5797
|
+
err_35 = _b.sent();
|
5798
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_35);
|
5799
|
+
throw err_35;
|
5800
|
+
case 6: return [2, {
|
5801
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5802
|
+
additionalSigners: additionalSigners
|
5803
|
+
}];
|
5804
|
+
}
|
5805
|
+
});
|
5806
|
+
});
|
5807
|
+
};
|
5808
|
+
this.collectRevenue = function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5809
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5810
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5811
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_36;
|
5812
|
+
return __generator(this, function (_b) {
|
5813
|
+
switch (_b.label) {
|
5814
|
+
case 0:
|
5815
|
+
publicKey = this.provider.wallet.publicKey;
|
5816
|
+
preInstructions = [];
|
5817
|
+
instructions = [];
|
5818
|
+
postInstructions = [];
|
5819
|
+
additionalSigners = [];
|
5820
|
+
_b.label = 1;
|
5821
|
+
case 1:
|
5822
|
+
_b.trys.push([1, 5, , 6]);
|
5823
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5824
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5825
|
+
userTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, owner, true);
|
5826
|
+
_a = createUserATA;
|
5827
|
+
if (!_a) return [3, 3];
|
5828
|
+
return [4, (0, utils_1.checkIfAccountExists)(userTokenAccount, this.provider.connection)];
|
5829
|
+
case 2:
|
5830
|
+
_a = !(_b.sent());
|
5831
|
+
_b.label = 3;
|
5832
|
+
case 3:
|
5833
|
+
if (_a) {
|
5834
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userTokenAccount, publicKey, poolConfig.tokenMint));
|
5835
|
+
}
|
5836
|
+
return [4, this.program.methods
|
5837
|
+
.collectRevenue({})
|
5838
|
+
.accounts({
|
5839
|
+
owner: owner,
|
5840
|
+
receivingRevenueAccount: userTokenAccount,
|
5841
|
+
perpetuals: this.perpetuals.publicKey,
|
5842
|
+
transferAuthority: poolConfig.transferAuthority,
|
5843
|
+
tokenVault: poolConfig.tokenVault,
|
5844
|
+
revenueTokenAccount: poolConfig.revenueTokenAccount,
|
5845
|
+
tokenStakeAccount: tokenStakeAccount,
|
5846
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5847
|
+
eventAuthority: this.eventAuthority.publicKey,
|
5848
|
+
program: this.programId
|
5849
|
+
})
|
5850
|
+
.instruction()];
|
5851
|
+
case 4:
|
5852
|
+
collectRevenueInstruction = _b.sent();
|
5853
|
+
instructions.push(collectRevenueInstruction);
|
5854
|
+
return [3, 6];
|
5855
|
+
case 5:
|
5856
|
+
err_36 = _b.sent();
|
5857
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_36);
|
5858
|
+
throw err_36;
|
5837
5859
|
case 6: return [2, {
|
5838
5860
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5839
5861
|
additionalSigners: additionalSigners
|
@@ -5843,7 +5865,7 @@ var PerpetualsClient = (function () {
|
|
5843
5865
|
});
|
5844
5866
|
};
|
5845
5867
|
this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
|
5846
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction,
|
5868
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_37;
|
5847
5869
|
return __generator(this, function (_a) {
|
5848
5870
|
switch (_a.label) {
|
5849
5871
|
case 0:
|
@@ -5871,9 +5893,9 @@ var PerpetualsClient = (function () {
|
|
5871
5893
|
instructions.push(setTokenStakeLevelInstruction);
|
5872
5894
|
return [3, 4];
|
5873
5895
|
case 3:
|
5874
|
-
|
5875
|
-
console.log("perpClient setTokenStakeLevelInstruction error:: ",
|
5876
|
-
throw
|
5896
|
+
err_37 = _a.sent();
|
5897
|
+
console.log("perpClient setTokenStakeLevelInstruction error:: ", err_37);
|
5898
|
+
throw err_37;
|
5877
5899
|
case 4: return [2, {
|
5878
5900
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5879
5901
|
additionalSigners: additionalSigners
|
@@ -5882,7 +5904,7 @@ var PerpetualsClient = (function () {
|
|
5882
5904
|
});
|
5883
5905
|
}); };
|
5884
5906
|
this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5885
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault,
|
5907
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_38;
|
5886
5908
|
return __generator(this, function (_a) {
|
5887
5909
|
switch (_a.label) {
|
5888
5910
|
case 0:
|
@@ -5919,9 +5941,9 @@ var PerpetualsClient = (function () {
|
|
5919
5941
|
instructions.push(initRewardVault);
|
5920
5942
|
return [3, 4];
|
5921
5943
|
case 3:
|
5922
|
-
|
5923
|
-
console.log("perpClient InitRewardVault error:: ",
|
5924
|
-
throw
|
5944
|
+
err_38 = _a.sent();
|
5945
|
+
console.log("perpClient InitRewardVault error:: ", err_38);
|
5946
|
+
throw err_38;
|
5925
5947
|
case 4: return [2, {
|
5926
5948
|
instructions: __spreadArray([], instructions, true),
|
5927
5949
|
additionalSigners: additionalSigners
|
@@ -5930,7 +5952,7 @@ var PerpetualsClient = (function () {
|
|
5930
5952
|
});
|
5931
5953
|
}); };
|
5932
5954
|
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5933
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward,
|
5955
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_39;
|
5934
5956
|
return __generator(this, function (_a) {
|
5935
5957
|
switch (_a.label) {
|
5936
5958
|
case 0:
|
@@ -5961,9 +5983,9 @@ var PerpetualsClient = (function () {
|
|
5961
5983
|
instructions.push(distributeReward);
|
5962
5984
|
return [3, 4];
|
5963
5985
|
case 3:
|
5964
|
-
|
5965
|
-
console.log("perpClient distributeReward error:: ",
|
5966
|
-
throw
|
5986
|
+
err_39 = _a.sent();
|
5987
|
+
console.log("perpClient distributeReward error:: ", err_39);
|
5988
|
+
throw err_39;
|
5967
5989
|
case 4: return [2, {
|
5968
5990
|
instructions: __spreadArray([], instructions, true),
|
5969
5991
|
additionalSigners: additionalSigners
|
@@ -5971,14 +5993,10 @@ var PerpetualsClient = (function () {
|
|
5971
5993
|
}
|
5972
5994
|
});
|
5973
5995
|
}); };
|
5974
|
-
this.collectNftReward = function (
|
5975
|
-
|
5976
|
-
|
5977
|
-
|
5978
|
-
}
|
5979
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5980
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_38;
|
5981
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5996
|
+
this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5997
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5998
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5999
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_40;
|
5982
6000
|
return __generator(this, function (_b) {
|
5983
6001
|
switch (_b.label) {
|
5984
6002
|
case 0:
|
@@ -6028,8 +6046,8 @@ var PerpetualsClient = (function () {
|
|
6028
6046
|
instructions.push(collectNftReward);
|
6029
6047
|
return [3, 6];
|
6030
6048
|
case 5:
|
6031
|
-
|
6032
|
-
throw
|
6049
|
+
err_40 = _b.sent();
|
6050
|
+
throw err_40;
|
6033
6051
|
case 6: return [2, {
|
6034
6052
|
instructions: __spreadArray([], instructions, true),
|
6035
6053
|
additionalSigners: additionalSigners
|
@@ -6038,14 +6056,10 @@ var PerpetualsClient = (function () {
|
|
6038
6056
|
});
|
6039
6057
|
});
|
6040
6058
|
};
|
6041
|
-
this.collectAndDistributeFee = function (
|
6042
|
-
|
6043
|
-
|
6044
|
-
|
6045
|
-
}
|
6046
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
6047
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_39;
|
6048
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
6059
|
+
this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
6060
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6061
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6062
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_41;
|
6049
6063
|
return __generator(this, function (_b) {
|
6050
6064
|
switch (_b.label) {
|
6051
6065
|
case 0:
|
@@ -6109,9 +6123,9 @@ var PerpetualsClient = (function () {
|
|
6109
6123
|
instructions.push(withdrawStakeInstruction);
|
6110
6124
|
return [3, 6];
|
6111
6125
|
case 5:
|
6112
|
-
|
6113
|
-
console.log("perpClient withdrawStake error:: ",
|
6114
|
-
throw
|
6126
|
+
err_41 = _b.sent();
|
6127
|
+
console.log("perpClient withdrawStake error:: ", err_41);
|
6128
|
+
throw err_41;
|
6115
6129
|
case 6: return [2, {
|
6116
6130
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6117
6131
|
additionalSigners: additionalSigners
|
@@ -6121,7 +6135,7 @@ var PerpetualsClient = (function () {
|
|
6121
6135
|
});
|
6122
6136
|
};
|
6123
6137
|
this.setTriggerPrice = function (targetSymbol, collateralSymbol, side, triggerPrice, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6124
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice,
|
6138
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice, err_42;
|
6125
6139
|
return __generator(this, function (_a) {
|
6126
6140
|
switch (_a.label) {
|
6127
6141
|
case 0:
|
@@ -6160,9 +6174,9 @@ var PerpetualsClient = (function () {
|
|
6160
6174
|
instructions.push(setTriggerPrice);
|
6161
6175
|
return [3, 4];
|
6162
6176
|
case 3:
|
6163
|
-
|
6164
|
-
console.log("perpClient setTriggerPrice error:: ",
|
6165
|
-
throw
|
6177
|
+
err_42 = _a.sent();
|
6178
|
+
console.log("perpClient setTriggerPrice error:: ", err_42);
|
6179
|
+
throw err_42;
|
6166
6180
|
case 4: return [2, {
|
6167
6181
|
instructions: __spreadArray([], instructions, true),
|
6168
6182
|
additionalSigners: additionalSigners
|
@@ -6170,16 +6184,12 @@ var PerpetualsClient = (function () {
|
|
6170
6184
|
}
|
6171
6185
|
});
|
6172
6186
|
}); };
|
6173
|
-
this.forceClosePosition = function (
|
6174
|
-
|
6175
|
-
|
6176
|
-
|
6177
|
-
|
6178
|
-
|
6179
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_41;
|
6180
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
6181
|
-
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
6182
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6187
|
+
this.forceClosePosition = function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
6188
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6189
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
6190
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6191
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6192
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_43;
|
6183
6193
|
return __generator(this, function (_b) {
|
6184
6194
|
switch (_b.label) {
|
6185
6195
|
case 0:
|
@@ -6240,9 +6250,9 @@ var PerpetualsClient = (function () {
|
|
6240
6250
|
}
|
6241
6251
|
return [3, 7];
|
6242
6252
|
case 6:
|
6243
|
-
|
6244
|
-
console.log("perpClient forceClosePosition error:: ",
|
6245
|
-
throw
|
6253
|
+
err_43 = _b.sent();
|
6254
|
+
console.log("perpClient forceClosePosition error:: ", err_43);
|
6255
|
+
throw err_43;
|
6246
6256
|
case 7: return [2, {
|
6247
6257
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6248
6258
|
additionalSigners: additionalSigners
|
@@ -6251,15 +6261,11 @@ var PerpetualsClient = (function () {
|
|
6251
6261
|
});
|
6252
6262
|
});
|
6253
6263
|
};
|
6254
|
-
this.placeLimitOrder = function (
|
6255
|
-
|
6256
|
-
|
6257
|
-
|
6258
|
-
|
6259
|
-
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) {
|
6260
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_42;
|
6261
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6262
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6264
|
+
this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
6265
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6266
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6267
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6268
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_44;
|
6263
6269
|
return __generator(this, function (_c) {
|
6264
6270
|
switch (_c.label) {
|
6265
6271
|
case 0:
|
@@ -6364,9 +6370,9 @@ var PerpetualsClient = (function () {
|
|
6364
6370
|
instructions.push(placeLimitOrder);
|
6365
6371
|
return [3, 11];
|
6366
6372
|
case 10:
|
6367
|
-
|
6368
|
-
console.log("perpClient placeLimitOrder error:: ",
|
6369
|
-
throw
|
6373
|
+
err_44 = _c.sent();
|
6374
|
+
console.log("perpClient placeLimitOrder error:: ", err_44);
|
6375
|
+
throw err_44;
|
6370
6376
|
case 11: return [2, {
|
6371
6377
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6372
6378
|
additionalSigners: additionalSigners
|
@@ -6375,15 +6381,11 @@ var PerpetualsClient = (function () {
|
|
6375
6381
|
});
|
6376
6382
|
});
|
6377
6383
|
};
|
6378
|
-
this.editLimitOrder = function (
|
6379
|
-
|
6380
|
-
|
6381
|
-
|
6382
|
-
|
6383
|
-
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) {
|
6384
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_43;
|
6385
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
6386
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6384
|
+
this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
|
6385
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6386
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6387
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6388
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_45;
|
6387
6389
|
return __generator(this, function (_b) {
|
6388
6390
|
switch (_b.label) {
|
6389
6391
|
case 0:
|
@@ -6471,9 +6473,9 @@ var PerpetualsClient = (function () {
|
|
6471
6473
|
instructions.push(editLimitOrder);
|
6472
6474
|
return [3, 8];
|
6473
6475
|
case 7:
|
6474
|
-
|
6475
|
-
console.log("perpClient editLimitOrder error:: ",
|
6476
|
-
throw
|
6476
|
+
err_45 = _b.sent();
|
6477
|
+
console.log("perpClient editLimitOrder error:: ", err_45);
|
6478
|
+
throw err_45;
|
6477
6479
|
case 8: return [2, {
|
6478
6480
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6479
6481
|
additionalSigners: additionalSigners
|
@@ -6482,16 +6484,12 @@ var PerpetualsClient = (function () {
|
|
6482
6484
|
});
|
6483
6485
|
});
|
6484
6486
|
};
|
6485
|
-
this.executeLimitOrder = function (
|
6486
|
-
|
6487
|
-
|
6488
|
-
|
6489
|
-
|
6490
|
-
|
6491
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_44;
|
6492
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6493
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6494
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6487
|
+
this.executeLimitOrder = function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6488
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6489
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6490
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6491
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6492
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_46;
|
6495
6493
|
return __generator(this, function (_a) {
|
6496
6494
|
switch (_a.label) {
|
6497
6495
|
case 0:
|
@@ -6540,9 +6538,9 @@ var PerpetualsClient = (function () {
|
|
6540
6538
|
instructions.push(executeLimitOrder);
|
6541
6539
|
return [3, 4];
|
6542
6540
|
case 3:
|
6543
|
-
|
6544
|
-
console.log("perpClient executeLimitOrder error:: ",
|
6545
|
-
throw
|
6541
|
+
err_46 = _a.sent();
|
6542
|
+
console.log("perpClient executeLimitOrder error:: ", err_46);
|
6543
|
+
throw err_46;
|
6546
6544
|
case 4: return [2, {
|
6547
6545
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6548
6546
|
additionalSigners: additionalSigners
|
@@ -6551,16 +6549,12 @@ var PerpetualsClient = (function () {
|
|
6551
6549
|
});
|
6552
6550
|
});
|
6553
6551
|
};
|
6554
|
-
this.executeLimitWithSwap = function (
|
6555
|
-
|
6556
|
-
|
6557
|
-
|
6558
|
-
|
6559
|
-
|
6560
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_45;
|
6561
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6562
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6563
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6552
|
+
this.executeLimitWithSwap = function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6553
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6554
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6555
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6556
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6557
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_47;
|
6564
6558
|
return __generator(this, function (_a) {
|
6565
6559
|
switch (_a.label) {
|
6566
6560
|
case 0:
|
@@ -6612,9 +6606,9 @@ var PerpetualsClient = (function () {
|
|
6612
6606
|
instructions.push(executeLimitWithSwap);
|
6613
6607
|
return [3, 4];
|
6614
6608
|
case 3:
|
6615
|
-
|
6616
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
6617
|
-
throw
|
6609
|
+
err_47 = _a.sent();
|
6610
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_47);
|
6611
|
+
throw err_47;
|
6618
6612
|
case 4: return [2, {
|
6619
6613
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6620
6614
|
additionalSigners: additionalSigners
|
@@ -6624,7 +6618,7 @@ var PerpetualsClient = (function () {
|
|
6624
6618
|
});
|
6625
6619
|
};
|
6626
6620
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6627
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder,
|
6621
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_48;
|
6628
6622
|
return __generator(this, function (_a) {
|
6629
6623
|
switch (_a.label) {
|
6630
6624
|
case 0:
|
@@ -6672,9 +6666,9 @@ var PerpetualsClient = (function () {
|
|
6672
6666
|
instructions.push(placeTriggerOrder);
|
6673
6667
|
return [3, 4];
|
6674
6668
|
case 3:
|
6675
|
-
|
6676
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
6677
|
-
throw
|
6669
|
+
err_48 = _a.sent();
|
6670
|
+
console.log("perpClient placeTriggerOrder error:: ", err_48);
|
6671
|
+
throw err_48;
|
6678
6672
|
case 4: return [2, {
|
6679
6673
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6680
6674
|
additionalSigners: additionalSigners
|
@@ -6683,7 +6677,7 @@ var PerpetualsClient = (function () {
|
|
6683
6677
|
});
|
6684
6678
|
}); };
|
6685
6679
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6686
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder,
|
6680
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_49;
|
6687
6681
|
return __generator(this, function (_a) {
|
6688
6682
|
switch (_a.label) {
|
6689
6683
|
case 0:
|
@@ -6730,9 +6724,9 @@ var PerpetualsClient = (function () {
|
|
6730
6724
|
instructions.push(editTriggerOrder);
|
6731
6725
|
return [3, 4];
|
6732
6726
|
case 3:
|
6733
|
-
|
6734
|
-
console.log("perpClient editTriggerOrder error:: ",
|
6735
|
-
throw
|
6727
|
+
err_49 = _a.sent();
|
6728
|
+
console.log("perpClient editTriggerOrder error:: ", err_49);
|
6729
|
+
throw err_49;
|
6736
6730
|
case 4: return [2, {
|
6737
6731
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6738
6732
|
additionalSigners: additionalSigners
|
@@ -6741,7 +6735,7 @@ var PerpetualsClient = (function () {
|
|
6741
6735
|
});
|
6742
6736
|
}); };
|
6743
6737
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6744
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder,
|
6738
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_50;
|
6745
6739
|
return __generator(this, function (_a) {
|
6746
6740
|
switch (_a.label) {
|
6747
6741
|
case 0:
|
@@ -6774,9 +6768,9 @@ var PerpetualsClient = (function () {
|
|
6774
6768
|
instructions.push(cancelTriggerOrder);
|
6775
6769
|
return [3, 4];
|
6776
6770
|
case 3:
|
6777
|
-
|
6778
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
6779
|
-
throw
|
6771
|
+
err_50 = _a.sent();
|
6772
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_50);
|
6773
|
+
throw err_50;
|
6780
6774
|
case 4: return [2, {
|
6781
6775
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6782
6776
|
additionalSigners: additionalSigners
|
@@ -6785,7 +6779,7 @@ var PerpetualsClient = (function () {
|
|
6785
6779
|
});
|
6786
6780
|
}); };
|
6787
6781
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6788
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders,
|
6782
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_51;
|
6789
6783
|
return __generator(this, function (_a) {
|
6790
6784
|
switch (_a.label) {
|
6791
6785
|
case 0:
|
@@ -6816,9 +6810,9 @@ var PerpetualsClient = (function () {
|
|
6816
6810
|
instructions.push(cancelAllTriggerOrders);
|
6817
6811
|
return [3, 4];
|
6818
6812
|
case 3:
|
6819
|
-
|
6820
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
6821
|
-
throw
|
6813
|
+
err_51 = _a.sent();
|
6814
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_51);
|
6815
|
+
throw err_51;
|
6822
6816
|
case 4: return [2, {
|
6823
6817
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6824
6818
|
additionalSigners: additionalSigners
|
@@ -6826,20 +6820,16 @@ var PerpetualsClient = (function () {
|
|
6826
6820
|
}
|
6827
6821
|
});
|
6828
6822
|
}); };
|
6829
|
-
this.executeTriggerWithSwap = function (
|
6830
|
-
|
6831
|
-
|
6832
|
-
|
6833
|
-
}
|
6834
|
-
|
6835
|
-
|
6836
|
-
|
6837
|
-
|
6838
|
-
|
6839
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6840
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6841
|
-
return __generator(this, function (_e) {
|
6842
|
-
switch (_e.label) {
|
6823
|
+
this.executeTriggerWithSwap = function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6824
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6825
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6826
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6827
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6828
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6829
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6830
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, executeTriggerWithSwap, err_52;
|
6831
|
+
return __generator(this, function (_d) {
|
6832
|
+
switch (_d.label) {
|
6843
6833
|
case 0:
|
6844
6834
|
payerPubkey = this.provider.wallet.publicKey;
|
6845
6835
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
@@ -6850,9 +6840,9 @@ var PerpetualsClient = (function () {
|
|
6850
6840
|
instructions = [];
|
6851
6841
|
postInstructions = [];
|
6852
6842
|
additionalSigners = [];
|
6853
|
-
|
6843
|
+
_d.label = 1;
|
6854
6844
|
case 1:
|
6855
|
-
|
6845
|
+
_d.trys.push([1, 9, , 10]);
|
6856
6846
|
if (!false) return [3, 2];
|
6857
6847
|
return [3, 7];
|
6858
6848
|
case 2:
|
@@ -6861,8 +6851,8 @@ var PerpetualsClient = (function () {
|
|
6861
6851
|
if (!_a) return [3, 4];
|
6862
6852
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
6863
6853
|
case 3:
|
6864
|
-
_a = !(
|
6865
|
-
|
6854
|
+
_a = !(_d.sent());
|
6855
|
+
_d.label = 4;
|
6866
6856
|
case 4:
|
6867
6857
|
if (_a) {
|
6868
6858
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
@@ -6872,20 +6862,20 @@ var PerpetualsClient = (function () {
|
|
6872
6862
|
if (!_b) return [3, 6];
|
6873
6863
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
|
6874
6864
|
case 5:
|
6875
|
-
_b = !(
|
6876
|
-
|
6865
|
+
_b = !(_d.sent());
|
6866
|
+
_d.label = 6;
|
6877
6867
|
case 6:
|
6878
6868
|
if (_b) {
|
6879
6869
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6880
6870
|
}
|
6881
|
-
|
6871
|
+
_d.label = 7;
|
6882
6872
|
case 7:
|
6883
6873
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
6884
6874
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
6885
6875
|
custodyAccountMetas = [];
|
6886
6876
|
custodyOracleAccountMetas = [];
|
6887
|
-
for (
|
6888
|
-
custody =
|
6877
|
+
for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
|
6878
|
+
custody = _c[_i];
|
6889
6879
|
custodyAccountMetas.push({
|
6890
6880
|
pubkey: custody.custodyAccount,
|
6891
6881
|
isSigner: false,
|
@@ -6930,13 +6920,13 @@ var PerpetualsClient = (function () {
|
|
6930
6920
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
6931
6921
|
.instruction()];
|
6932
6922
|
case 8:
|
6933
|
-
executeTriggerWithSwap =
|
6923
|
+
executeTriggerWithSwap = _d.sent();
|
6934
6924
|
instructions.push(executeTriggerWithSwap);
|
6935
6925
|
return [3, 10];
|
6936
6926
|
case 9:
|
6937
|
-
|
6938
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
6939
|
-
throw
|
6927
|
+
err_52 = _d.sent();
|
6928
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_52);
|
6929
|
+
throw err_52;
|
6940
6930
|
case 10: return [2, {
|
6941
6931
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6942
6932
|
additionalSigners: additionalSigners
|
@@ -6945,18 +6935,14 @@ var PerpetualsClient = (function () {
|
|
6945
6935
|
});
|
6946
6936
|
});
|
6947
6937
|
};
|
6948
|
-
this.executeTriggerOrder = function (
|
6949
|
-
|
6950
|
-
|
6951
|
-
|
6952
|
-
}
|
6953
|
-
|
6954
|
-
|
6955
|
-
|
6956
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6957
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6958
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6959
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6938
|
+
this.executeTriggerOrder = function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6939
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6940
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6941
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6942
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6943
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6944
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6945
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_53;
|
6960
6946
|
return __generator(this, function (_b) {
|
6961
6947
|
switch (_b.label) {
|
6962
6948
|
case 0:
|
@@ -7022,9 +7008,9 @@ var PerpetualsClient = (function () {
|
|
7022
7008
|
instructions.push(executeTriggerOrder);
|
7023
7009
|
return [3, 8];
|
7024
7010
|
case 7:
|
7025
|
-
|
7026
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
7027
|
-
throw
|
7011
|
+
err_53 = _b.sent();
|
7012
|
+
console.log("perpClient executeTriggerOrder error:: ", err_53);
|
7013
|
+
throw err_53;
|
7028
7014
|
case 8: return [2, {
|
7029
7015
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7030
7016
|
additionalSigners: additionalSigners
|
@@ -7034,7 +7020,7 @@ var PerpetualsClient = (function () {
|
|
7034
7020
|
});
|
7035
7021
|
};
|
7036
7022
|
this.migrateTriggerOrder = function (owner, marketAccount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7037
|
-
var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder,
|
7023
|
+
var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder, err_54;
|
7038
7024
|
return __generator(this, function (_a) {
|
7039
7025
|
switch (_a.label) {
|
7040
7026
|
case 0:
|
@@ -7064,9 +7050,9 @@ var PerpetualsClient = (function () {
|
|
7064
7050
|
instructions.push(migrateTriggerOrder);
|
7065
7051
|
return [3, 4];
|
7066
7052
|
case 3:
|
7067
|
-
|
7068
|
-
console.log("perpClient migrateTriggerOrder error:: ",
|
7069
|
-
throw
|
7053
|
+
err_54 = _a.sent();
|
7054
|
+
console.log("perpClient migrateTriggerOrder error:: ", err_54);
|
7055
|
+
throw err_54;
|
7070
7056
|
case 4: return [2, {
|
7071
7057
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7072
7058
|
additionalSigners: additionalSigners
|
@@ -7075,7 +7061,7 @@ var PerpetualsClient = (function () {
|
|
7075
7061
|
});
|
7076
7062
|
}); };
|
7077
7063
|
this.getPositionData = function (position, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7078
|
-
var marketConfig, targetCustodyConfig, collateralCustodyConfig, getPositionData,
|
7064
|
+
var marketConfig, targetCustodyConfig, collateralCustodyConfig, getPositionData, err_55;
|
7079
7065
|
return __generator(this, function (_a) {
|
7080
7066
|
switch (_a.label) {
|
7081
7067
|
case 0:
|
@@ -7104,15 +7090,15 @@ var PerpetualsClient = (function () {
|
|
7104
7090
|
console.log(getPositionData);
|
7105
7091
|
return [2, getPositionData];
|
7106
7092
|
case 3:
|
7107
|
-
|
7108
|
-
console.log("perpClient setPool error:: ",
|
7109
|
-
throw
|
7093
|
+
err_55 = _a.sent();
|
7094
|
+
console.log("perpClient setPool error:: ", err_55);
|
7095
|
+
throw err_55;
|
7110
7096
|
case 4: return [2];
|
7111
7097
|
}
|
7112
7098
|
});
|
7113
7099
|
}); };
|
7114
7100
|
this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7115
|
-
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx,
|
7101
|
+
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_56;
|
7116
7102
|
return __generator(this, function (_a) {
|
7117
7103
|
switch (_a.label) {
|
7118
7104
|
case 0:
|
@@ -7133,9 +7119,8 @@ var PerpetualsClient = (function () {
|
|
7133
7119
|
multisig: this.multisig.publicKey,
|
7134
7120
|
transferAuthority: this.authority.publicKey,
|
7135
7121
|
perpetuals: this.perpetuals.publicKey,
|
7136
|
-
|
7137
|
-
|
7138
|
-
custodyTokenAccount: custodyConfig.tokenAccount,
|
7122
|
+
protocolVault: poolConfig.protocolVault,
|
7123
|
+
protocolTokenAccount: poolConfig.protocolTokenAccount,
|
7139
7124
|
receivingTokenAccount: receivingTokenAccount,
|
7140
7125
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
7141
7126
|
})
|
@@ -7145,9 +7130,9 @@ var PerpetualsClient = (function () {
|
|
7145
7130
|
instructions.push(withdrawFeesIx);
|
7146
7131
|
return [3, 5];
|
7147
7132
|
case 4:
|
7148
|
-
|
7149
|
-
console.log("perpClient setPool error:: ",
|
7150
|
-
throw
|
7133
|
+
err_56 = _a.sent();
|
7134
|
+
console.log("perpClient setPool error:: ", err_56);
|
7135
|
+
throw err_56;
|
7151
7136
|
case 5: return [2, {
|
7152
7137
|
instructions: __spreadArray([], instructions, true),
|
7153
7138
|
additionalSigners: additionalSigners
|
@@ -7155,8 +7140,82 @@ var PerpetualsClient = (function () {
|
|
7155
7140
|
}
|
7156
7141
|
});
|
7157
7142
|
}); };
|
7143
|
+
this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7144
|
+
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_57;
|
7145
|
+
return __generator(this, function (_a) {
|
7146
|
+
switch (_a.label) {
|
7147
|
+
case 0:
|
7148
|
+
publicKey = this.provider.wallet.publicKey;
|
7149
|
+
custodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
7150
|
+
instructions = [];
|
7151
|
+
additionalSigners = [];
|
7152
|
+
_a.label = 1;
|
7153
|
+
case 1:
|
7154
|
+
_a.trys.push([1, 3, , 4]);
|
7155
|
+
return [4, this.program.methods
|
7156
|
+
.moveProtocolFees({})
|
7157
|
+
.accounts({
|
7158
|
+
admin: publicKey,
|
7159
|
+
multisig: this.multisig.publicKey,
|
7160
|
+
transferAuthority: this.authority.publicKey,
|
7161
|
+
perpetuals: this.perpetuals.publicKey,
|
7162
|
+
tokenVault: poolConfig.tokenVault,
|
7163
|
+
pool: poolConfig.poolAddress,
|
7164
|
+
custody: custodyConfig.custodyAccount,
|
7165
|
+
custodyTokenAccount: custodyConfig.tokenAccount,
|
7166
|
+
revenueTokenAccount: poolConfig.revenueTokenAccount,
|
7167
|
+
protocolVault: poolConfig.protocolVault,
|
7168
|
+
protocolTokenAccount: poolConfig.protocolTokenAccount,
|
7169
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7170
|
+
eventAuthority: this.eventAuthority.publicKey,
|
7171
|
+
program: this.program.programId,
|
7172
|
+
})
|
7173
|
+
.instruction()];
|
7174
|
+
case 2:
|
7175
|
+
moveProtocolFeesIx = _a.sent();
|
7176
|
+
instructions.push(moveProtocolFeesIx);
|
7177
|
+
return [3, 4];
|
7178
|
+
case 3:
|
7179
|
+
err_57 = _a.sent();
|
7180
|
+
console.log("perpClient setPool error:: ", err_57);
|
7181
|
+
throw err_57;
|
7182
|
+
case 4: return [2, {
|
7183
|
+
instructions: __spreadArray([], instructions, true),
|
7184
|
+
additionalSigners: additionalSigners
|
7185
|
+
}];
|
7186
|
+
}
|
7187
|
+
});
|
7188
|
+
}); };
|
7189
|
+
this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7190
|
+
var publicKey, setProtocolFeeShareBpsIx, err_58;
|
7191
|
+
return __generator(this, function (_a) {
|
7192
|
+
switch (_a.label) {
|
7193
|
+
case 0:
|
7194
|
+
_a.trys.push([0, 2, , 3]);
|
7195
|
+
publicKey = this.provider.wallet.publicKey;
|
7196
|
+
return [4, this.program.methods
|
7197
|
+
.setProtocolFeeShare({
|
7198
|
+
feeShareBps: feeShareBps
|
7199
|
+
})
|
7200
|
+
.accounts({
|
7201
|
+
admin: publicKey,
|
7202
|
+
multisig: this.multisig.publicKey,
|
7203
|
+
protocolVault: poolConfig.protocolVault,
|
7204
|
+
})
|
7205
|
+
.instruction()];
|
7206
|
+
case 1:
|
7207
|
+
setProtocolFeeShareBpsIx = _a.sent();
|
7208
|
+
return [2, setProtocolFeeShareBpsIx];
|
7209
|
+
case 2:
|
7210
|
+
err_58 = _a.sent();
|
7211
|
+
console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_58);
|
7212
|
+
throw err_58;
|
7213
|
+
case 3: return [2];
|
7214
|
+
}
|
7215
|
+
});
|
7216
|
+
}); };
|
7158
7217
|
this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
|
7159
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction,
|
7218
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_59;
|
7160
7219
|
return __generator(this, function (_a) {
|
7161
7220
|
switch (_a.label) {
|
7162
7221
|
case 0:
|
@@ -7183,9 +7242,9 @@ var PerpetualsClient = (function () {
|
|
7183
7242
|
instructions.push(setPermissionsInstruction);
|
7184
7243
|
return [3, 4];
|
7185
7244
|
case 3:
|
7186
|
-
|
7187
|
-
console.log("perpClient setPool error:: ",
|
7188
|
-
throw
|
7245
|
+
err_59 = _a.sent();
|
7246
|
+
console.log("perpClient setPool error:: ", err_59);
|
7247
|
+
throw err_59;
|
7189
7248
|
case 4: return [2, {
|
7190
7249
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7191
7250
|
additionalSigners: additionalSigners
|
@@ -7194,7 +7253,7 @@ var PerpetualsClient = (function () {
|
|
7194
7253
|
});
|
7195
7254
|
}); };
|
7196
7255
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7197
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e,
|
7256
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_60;
|
7198
7257
|
var _f;
|
7199
7258
|
return __generator(this, function (_g) {
|
7200
7259
|
switch (_g.label) {
|
@@ -7254,9 +7313,9 @@ var PerpetualsClient = (function () {
|
|
7254
7313
|
instructions.push(reimburse);
|
7255
7314
|
return [3, 5];
|
7256
7315
|
case 4:
|
7257
|
-
|
7258
|
-
console.log("perpClient setPool error:: ",
|
7259
|
-
throw
|
7316
|
+
err_60 = _g.sent();
|
7317
|
+
console.log("perpClient setPool error:: ", err_60);
|
7318
|
+
throw err_60;
|
7260
7319
|
case 5: return [2, {
|
7261
7320
|
instructions: __spreadArray([], instructions, true),
|
7262
7321
|
additionalSigners: additionalSigners
|
@@ -7265,7 +7324,7 @@ var PerpetualsClient = (function () {
|
|
7265
7324
|
});
|
7266
7325
|
}); };
|
7267
7326
|
this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7268
|
-
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice,
|
7327
|
+
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_61;
|
7269
7328
|
return __generator(this, function (_a) {
|
7270
7329
|
switch (_a.label) {
|
7271
7330
|
case 0:
|
@@ -7298,9 +7357,9 @@ var PerpetualsClient = (function () {
|
|
7298
7357
|
instructions.push(setInternalOraclePrice);
|
7299
7358
|
return [3, 4];
|
7300
7359
|
case 3:
|
7301
|
-
|
7302
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7303
|
-
throw
|
7360
|
+
err_61 = _a.sent();
|
7361
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_61);
|
7362
|
+
throw err_61;
|
7304
7363
|
case 4: return [2, {
|
7305
7364
|
instructions: __spreadArray([], instructions, true),
|
7306
7365
|
additionalSigners: additionalSigners
|
@@ -7308,18 +7367,14 @@ var PerpetualsClient = (function () {
|
|
7308
7367
|
}
|
7309
7368
|
});
|
7310
7369
|
}); };
|
7311
|
-
this.addCompoundingLiquidity = function (
|
7312
|
-
|
7313
|
-
|
7314
|
-
|
7315
|
-
|
7316
|
-
|
7317
|
-
|
7318
|
-
|
7319
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7320
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7321
|
-
return __generator(this, function (_f) {
|
7322
|
-
switch (_f.label) {
|
7370
|
+
this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
7371
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
7372
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7373
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7374
|
+
return __awaiter(_this, void 0, void 0, function () {
|
7375
|
+
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_62;
|
7376
|
+
return __generator(this, function (_e) {
|
7377
|
+
switch (_e.label) {
|
7323
7378
|
case 0:
|
7324
7379
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
7325
7380
|
preInstructions = [];
|
@@ -7336,8 +7391,8 @@ var PerpetualsClient = (function () {
|
|
7336
7391
|
custodyAccountMetas = [];
|
7337
7392
|
custodyOracleAccountMetas = [];
|
7338
7393
|
markets = [];
|
7339
|
-
for (
|
7340
|
-
custody =
|
7394
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
7395
|
+
custody = _a[_i];
|
7341
7396
|
custodyAccountMetas.push({
|
7342
7397
|
pubkey: custody.custodyAccount,
|
7343
7398
|
isSigner: false,
|
@@ -7349,8 +7404,8 @@ var PerpetualsClient = (function () {
|
|
7349
7404
|
isWritable: false,
|
7350
7405
|
});
|
7351
7406
|
}
|
7352
|
-
for (
|
7353
|
-
market =
|
7407
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
7408
|
+
market = _c[_b];
|
7354
7409
|
markets.push({
|
7355
7410
|
pubkey: market.marketAccount,
|
7356
7411
|
isSigner: false,
|
@@ -7359,26 +7414,26 @@ var PerpetualsClient = (function () {
|
|
7359
7414
|
}
|
7360
7415
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
7361
7416
|
case 1:
|
7362
|
-
if (!(
|
7417
|
+
if (!(_e.sent())) {
|
7363
7418
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
7364
7419
|
}
|
7365
7420
|
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
7366
7421
|
case 2:
|
7367
|
-
if (!(
|
7422
|
+
if (!(_e.sent())) {
|
7368
7423
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
7369
7424
|
}
|
7370
7425
|
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
7371
7426
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
7372
7427
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
7373
7428
|
if (!!skipBalanceChecks) return [3, 4];
|
7374
|
-
|
7429
|
+
_d = anchor_1.BN.bind;
|
7375
7430
|
return [4, this.provider.connection.getBalance(publicKey)];
|
7376
7431
|
case 3:
|
7377
|
-
unWrappedSolBalance = new (
|
7432
|
+
unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
|
7378
7433
|
if (unWrappedSolBalance.lt(lamports)) {
|
7379
7434
|
throw "Insufficient SOL Funds";
|
7380
7435
|
}
|
7381
|
-
|
7436
|
+
_e.label = 4;
|
7382
7437
|
case 4:
|
7383
7438
|
if (!ephemeralSignerPubkey) {
|
7384
7439
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -7402,12 +7457,12 @@ var PerpetualsClient = (function () {
|
|
7402
7457
|
if (!!skipBalanceChecks) return [3, 7];
|
7403
7458
|
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
7404
7459
|
case 6:
|
7405
|
-
if (!(
|
7460
|
+
if (!(_e.sent())) {
|
7406
7461
|
throw "Insufficient Funds , token Account doesn't exist";
|
7407
7462
|
}
|
7408
|
-
|
7463
|
+
_e.label = 7;
|
7409
7464
|
case 7:
|
7410
|
-
|
7465
|
+
_e.trys.push([7, 9, , 10]);
|
7411
7466
|
return [4, this.program.methods
|
7412
7467
|
.addCompoundingLiquidity({
|
7413
7468
|
amountIn: amountIn,
|
@@ -7436,12 +7491,12 @@ var PerpetualsClient = (function () {
|
|
7436
7491
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7437
7492
|
.instruction()];
|
7438
7493
|
case 8:
|
7439
|
-
addCompoundingLiquidity =
|
7494
|
+
addCompoundingLiquidity = _e.sent();
|
7440
7495
|
instructions.push(addCompoundingLiquidity);
|
7441
7496
|
return [3, 10];
|
7442
7497
|
case 9:
|
7443
|
-
|
7444
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
7498
|
+
err_62 = _e.sent();
|
7499
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_62);
|
7445
7500
|
return [3, 10];
|
7446
7501
|
case 10: return [2, {
|
7447
7502
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7451,18 +7506,14 @@ var PerpetualsClient = (function () {
|
|
7451
7506
|
});
|
7452
7507
|
});
|
7453
7508
|
};
|
7454
|
-
this.removeCompoundingLiquidity = function (
|
7455
|
-
|
7456
|
-
|
7457
|
-
|
7458
|
-
|
7459
|
-
|
7460
|
-
|
7461
|
-
|
7462
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7463
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7464
|
-
return __generator(this, function (_f) {
|
7465
|
-
switch (_f.label) {
|
7509
|
+
this.removeCompoundingLiquidity = function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
|
7510
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
7511
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7512
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7513
|
+
return __awaiter(_this, void 0, void 0, function () {
|
7514
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount, removeCompoundingLiquidity, err_63;
|
7515
|
+
return __generator(this, function (_e) {
|
7516
|
+
switch (_e.label) {
|
7466
7517
|
case 0:
|
7467
7518
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
7468
7519
|
preInstructions = [];
|
@@ -7499,19 +7550,19 @@ var PerpetualsClient = (function () {
|
|
7499
7550
|
if (!_a) return [3, 3];
|
7500
7551
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
7501
7552
|
case 2:
|
7502
|
-
_a = !(
|
7503
|
-
|
7553
|
+
_a = !(_e.sent());
|
7554
|
+
_e.label = 3;
|
7504
7555
|
case 3:
|
7505
7556
|
if (_a) {
|
7506
7557
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
7507
7558
|
}
|
7508
|
-
|
7559
|
+
_e.label = 4;
|
7509
7560
|
case 4:
|
7510
7561
|
custodyAccountMetas = [];
|
7511
7562
|
custodyOracleAccountMetas = [];
|
7512
7563
|
markets = [];
|
7513
|
-
for (
|
7514
|
-
custody =
|
7564
|
+
for (_i = 0, _b = poolConfig.custodies; _i < _b.length; _i++) {
|
7565
|
+
custody = _b[_i];
|
7515
7566
|
custodyAccountMetas.push({
|
7516
7567
|
pubkey: custody.custodyAccount,
|
7517
7568
|
isSigner: false,
|
@@ -7523,8 +7574,8 @@ var PerpetualsClient = (function () {
|
|
7523
7574
|
isWritable: false,
|
7524
7575
|
});
|
7525
7576
|
}
|
7526
|
-
for (
|
7527
|
-
market =
|
7577
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
7578
|
+
market = _d[_c];
|
7528
7579
|
markets.push({
|
7529
7580
|
pubkey: market.marketAccount,
|
7530
7581
|
isSigner: false,
|
@@ -7532,9 +7583,9 @@ var PerpetualsClient = (function () {
|
|
7532
7583
|
});
|
7533
7584
|
}
|
7534
7585
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
7535
|
-
|
7586
|
+
_e.label = 5;
|
7536
7587
|
case 5:
|
7537
|
-
|
7588
|
+
_e.trys.push([5, 7, , 8]);
|
7538
7589
|
return [4, this.program.methods
|
7539
7590
|
.removeCompoundingLiquidity({
|
7540
7591
|
compoundingAmountIn: compoundingAmountIn,
|
@@ -7563,12 +7614,12 @@ var PerpetualsClient = (function () {
|
|
7563
7614
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7564
7615
|
.instruction()];
|
7565
7616
|
case 6:
|
7566
|
-
removeCompoundingLiquidity =
|
7617
|
+
removeCompoundingLiquidity = _e.sent();
|
7567
7618
|
instructions.push(removeCompoundingLiquidity);
|
7568
7619
|
return [3, 8];
|
7569
7620
|
case 7:
|
7570
|
-
|
7571
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
7621
|
+
err_63 = _e.sent();
|
7622
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_63);
|
7572
7623
|
return [3, 8];
|
7573
7624
|
case 8: return [2, {
|
7574
7625
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7578,16 +7629,12 @@ var PerpetualsClient = (function () {
|
|
7578
7629
|
});
|
7579
7630
|
});
|
7580
7631
|
};
|
7581
|
-
this.migrateStake = function (
|
7582
|
-
|
7583
|
-
|
7584
|
-
|
7585
|
-
|
7586
|
-
|
7587
|
-
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_60;
|
7588
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
7589
|
-
return __generator(this, function (_g) {
|
7590
|
-
switch (_g.label) {
|
7632
|
+
this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
7633
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
7634
|
+
return __awaiter(_this, void 0, void 0, function () {
|
7635
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, migrateStake, err_64;
|
7636
|
+
return __generator(this, function (_f) {
|
7637
|
+
switch (_f.label) {
|
7591
7638
|
case 0:
|
7592
7639
|
publicKey = this.provider.wallet.publicKey;
|
7593
7640
|
preInstructions = [];
|
@@ -7602,8 +7649,8 @@ var PerpetualsClient = (function () {
|
|
7602
7649
|
if (!_a) return [3, 2];
|
7603
7650
|
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
7604
7651
|
case 1:
|
7605
|
-
_a = !(
|
7606
|
-
|
7652
|
+
_a = !(_f.sent());
|
7653
|
+
_f.label = 2;
|
7607
7654
|
case 2:
|
7608
7655
|
if (_a) {
|
7609
7656
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
@@ -7615,8 +7662,8 @@ var PerpetualsClient = (function () {
|
|
7615
7662
|
if (!_b) return [3, 4];
|
7616
7663
|
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
7617
7664
|
case 3:
|
7618
|
-
_b = (
|
7619
|
-
|
7665
|
+
_b = (_f.sent());
|
7666
|
+
_f.label = 4;
|
7620
7667
|
case 4:
|
7621
7668
|
if (_b) {
|
7622
7669
|
tokenStakeAccounts.push({
|
@@ -7629,8 +7676,8 @@ var PerpetualsClient = (function () {
|
|
7629
7676
|
custodyAccountMetas = [];
|
7630
7677
|
custodyOracleAccountMetas = [];
|
7631
7678
|
markets = [];
|
7632
|
-
for (
|
7633
|
-
custody =
|
7679
|
+
for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
|
7680
|
+
custody = _c[_i];
|
7634
7681
|
custodyAccountMetas.push({
|
7635
7682
|
pubkey: custody.custodyAccount,
|
7636
7683
|
isSigner: false,
|
@@ -7642,17 +7689,17 @@ var PerpetualsClient = (function () {
|
|
7642
7689
|
isWritable: false,
|
7643
7690
|
});
|
7644
7691
|
}
|
7645
|
-
for (
|
7646
|
-
market =
|
7692
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
7693
|
+
market = _e[_d];
|
7647
7694
|
markets.push({
|
7648
7695
|
pubkey: market.marketAccount,
|
7649
7696
|
isSigner: false,
|
7650
7697
|
isWritable: false,
|
7651
7698
|
});
|
7652
7699
|
}
|
7653
|
-
|
7700
|
+
_f.label = 5;
|
7654
7701
|
case 5:
|
7655
|
-
|
7702
|
+
_f.trys.push([5, 7, , 8]);
|
7656
7703
|
return [4, this.program.methods
|
7657
7704
|
.migrateStake({
|
7658
7705
|
amount: amount
|
@@ -7678,12 +7725,12 @@ var PerpetualsClient = (function () {
|
|
7678
7725
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
7679
7726
|
.instruction()];
|
7680
7727
|
case 6:
|
7681
|
-
migrateStake =
|
7728
|
+
migrateStake = _f.sent();
|
7682
7729
|
instructions.push(migrateStake);
|
7683
7730
|
return [3, 8];
|
7684
7731
|
case 7:
|
7685
|
-
|
7686
|
-
console.log("perpClient migrateStake error:: ",
|
7732
|
+
err_64 = _f.sent();
|
7733
|
+
console.log("perpClient migrateStake error:: ", err_64);
|
7687
7734
|
return [3, 8];
|
7688
7735
|
case 8: return [2, {
|
7689
7736
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7694,7 +7741,7 @@ var PerpetualsClient = (function () {
|
|
7694
7741
|
});
|
7695
7742
|
};
|
7696
7743
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7697
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
7744
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_65;
|
7698
7745
|
return __generator(this, function (_d) {
|
7699
7746
|
switch (_d.label) {
|
7700
7747
|
case 0:
|
@@ -7766,8 +7813,8 @@ var PerpetualsClient = (function () {
|
|
7766
7813
|
instructions.push(migrateFlp);
|
7767
7814
|
return [3, 4];
|
7768
7815
|
case 3:
|
7769
|
-
|
7770
|
-
console.log("perpClient migrateFlp error:: ",
|
7816
|
+
err_65 = _d.sent();
|
7817
|
+
console.log("perpClient migrateFlp error:: ", err_65);
|
7771
7818
|
return [3, 4];
|
7772
7819
|
case 4: return [2, {
|
7773
7820
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -7776,16 +7823,12 @@ var PerpetualsClient = (function () {
|
|
7776
7823
|
}
|
7777
7824
|
});
|
7778
7825
|
}); };
|
7779
|
-
this.compoundingFee = function (
|
7780
|
-
|
7781
|
-
|
7782
|
-
|
7783
|
-
|
7784
|
-
|
7785
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_62;
|
7786
|
-
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
7787
|
-
return __generator(this, function (_e) {
|
7788
|
-
switch (_e.label) {
|
7826
|
+
this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
|
7827
|
+
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
7828
|
+
return __awaiter(_this, void 0, void 0, function () {
|
7829
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_66;
|
7830
|
+
return __generator(this, function (_d) {
|
7831
|
+
switch (_d.label) {
|
7789
7832
|
case 0:
|
7790
7833
|
instructions = [];
|
7791
7834
|
additionalSigners = [];
|
@@ -7794,8 +7837,8 @@ var PerpetualsClient = (function () {
|
|
7794
7837
|
custodyAccountMetas = [];
|
7795
7838
|
custodyOracleAccountMetas = [];
|
7796
7839
|
markets = [];
|
7797
|
-
for (
|
7798
|
-
custody =
|
7840
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
7841
|
+
custody = _a[_i];
|
7799
7842
|
custodyAccountMetas.push({
|
7800
7843
|
pubkey: custody.custodyAccount,
|
7801
7844
|
isSigner: false,
|
@@ -7807,17 +7850,17 @@ var PerpetualsClient = (function () {
|
|
7807
7850
|
isWritable: false,
|
7808
7851
|
});
|
7809
7852
|
}
|
7810
|
-
for (
|
7811
|
-
market =
|
7853
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
7854
|
+
market = _c[_b];
|
7812
7855
|
markets.push({
|
7813
7856
|
pubkey: market.marketAccount,
|
7814
7857
|
isSigner: false,
|
7815
7858
|
isWritable: false,
|
7816
7859
|
});
|
7817
7860
|
}
|
7818
|
-
|
7861
|
+
_d.label = 1;
|
7819
7862
|
case 1:
|
7820
|
-
|
7863
|
+
_d.trys.push([1, 3, , 4]);
|
7821
7864
|
return [4, this.program.methods
|
7822
7865
|
.compoundFees({})
|
7823
7866
|
.accounts({
|
@@ -7836,12 +7879,12 @@ var PerpetualsClient = (function () {
|
|
7836
7879
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7837
7880
|
.instruction()];
|
7838
7881
|
case 2:
|
7839
|
-
compoundingFee =
|
7882
|
+
compoundingFee = _d.sent();
|
7840
7883
|
instructions.push(compoundingFee);
|
7841
7884
|
return [3, 4];
|
7842
7885
|
case 3:
|
7843
|
-
|
7844
|
-
console.log("perpClient compoundingFee error:: ",
|
7886
|
+
err_66 = _d.sent();
|
7887
|
+
console.log("perpClient compoundingFee error:: ", err_66);
|
7845
7888
|
return [3, 4];
|
7846
7889
|
case 4: return [2, {
|
7847
7890
|
instructions: __spreadArray([], instructions, true),
|
@@ -7852,7 +7895,7 @@ var PerpetualsClient = (function () {
|
|
7852
7895
|
});
|
7853
7896
|
};
|
7854
7897
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7855
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
7898
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_67;
|
7856
7899
|
return __generator(this, function (_a) {
|
7857
7900
|
switch (_a.label) {
|
7858
7901
|
case 0:
|
@@ -7890,8 +7933,8 @@ var PerpetualsClient = (function () {
|
|
7890
7933
|
instructions.push(renameFlp);
|
7891
7934
|
return [3, 4];
|
7892
7935
|
case 3:
|
7893
|
-
|
7894
|
-
console.log("perpClient renameFlp error:: ",
|
7936
|
+
err_67 = _a.sent();
|
7937
|
+
console.log("perpClient renameFlp error:: ", err_67);
|
7895
7938
|
return [3, 4];
|
7896
7939
|
case 4: return [2, {
|
7897
7940
|
instructions: __spreadArray([], instructions, true),
|
@@ -8001,9 +8044,9 @@ var PerpetualsClient = (function () {
|
|
8001
8044
|
}
|
8002
8045
|
}
|
8003
8046
|
};
|
8004
|
-
PerpetualsClient.prototype.sendTransaction = function (
|
8005
|
-
|
8006
|
-
|
8047
|
+
PerpetualsClient.prototype.sendTransaction = function (ixs, opts) {
|
8048
|
+
if (opts === void 0) { opts = {}; }
|
8049
|
+
return __awaiter(this, void 0, void 0, function () {
|
8007
8050
|
return __generator(this, function (_a) {
|
8008
8051
|
switch (_a.label) {
|
8009
8052
|
case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|
@@ -8012,9 +8055,9 @@ var PerpetualsClient = (function () {
|
|
8012
8055
|
});
|
8013
8056
|
});
|
8014
8057
|
};
|
8015
|
-
PerpetualsClient.prototype.sendTransactionV3 = function (
|
8016
|
-
|
8017
|
-
|
8058
|
+
PerpetualsClient.prototype.sendTransactionV3 = function (ixs, opts) {
|
8059
|
+
if (opts === void 0) { opts = {}; }
|
8060
|
+
return __awaiter(this, void 0, void 0, function () {
|
8018
8061
|
return __generator(this, function (_a) {
|
8019
8062
|
switch (_a.label) {
|
8020
8063
|
case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|