flash-sdk 2.13.9 → 2.14.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/PerpetualsClient.d.ts +6 -10
- package/dist/PerpetualsClient.js +271 -333
- package/dist/idl/perpetuals.d.ts +0 -155
- package/dist/idl/perpetuals.js +0 -155
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -2220,7 +2220,10 @@ var PerpetualsClient = (function () {
|
|
2220
2220
|
}
|
2221
2221
|
});
|
2222
2222
|
}); };
|
2223
|
-
this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount,
|
2223
|
+
this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, skipBalanceChecks) {
|
2224
|
+
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
2225
|
+
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
2226
|
+
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
2224
2227
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2225
2228
|
return __awaiter(_this, void 0, void 0, function () {
|
2226
2229
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
@@ -2325,7 +2328,10 @@ var PerpetualsClient = (function () {
|
|
2325
2328
|
});
|
2326
2329
|
});
|
2327
2330
|
};
|
2328
|
-
this.openPositionWithSwap = function (targetSymbol, collateralSymbol, inputSymbol, amountIn, minAmountOut, priceWithSlippage, size, side, swapPoolConfig, positionPoolConfig, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount,
|
2331
|
+
this.openPositionWithSwap = function (targetSymbol, collateralSymbol, inputSymbol, amountIn, minAmountOut, priceWithSlippage, size, side, swapPoolConfig, positionPoolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, skipBalanceChecks) {
|
2332
|
+
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
2333
|
+
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
2334
|
+
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
2329
2335
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2330
2336
|
return __awaiter(_this, void 0, void 0, function () {
|
2331
2337
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, swapOutCustodyConfig, swapInCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userOutputTokenAccount, marketAccount, positionAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, instruction;
|
@@ -2463,7 +2469,10 @@ var PerpetualsClient = (function () {
|
|
2463
2469
|
});
|
2464
2470
|
});
|
2465
2471
|
};
|
2466
|
-
this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount,
|
2472
|
+
this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, createUserATA, closeUsersWSOLATA) {
|
2473
|
+
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
2474
|
+
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
2475
|
+
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
2467
2476
|
if (createUserATA === void 0) { createUserATA = true; }
|
2468
2477
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2469
2478
|
return __awaiter(_this, void 0, void 0, function () {
|
@@ -2565,121 +2574,126 @@ var PerpetualsClient = (function () {
|
|
2565
2574
|
});
|
2566
2575
|
});
|
2567
2576
|
};
|
2568
|
-
this.closePositionWithSwap = function (targetSymbol, outputSymbol, collateralSymbol, minAmountOut, priceAfterSlippage, side, swapPoolConfig, positionPoolConfig, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount
|
2569
|
-
|
2570
|
-
|
2571
|
-
|
2572
|
-
|
2573
|
-
|
2574
|
-
|
2575
|
-
|
2576
|
-
|
2577
|
-
|
2578
|
-
|
2579
|
-
|
2580
|
-
|
2581
|
-
|
2582
|
-
|
2583
|
-
|
2584
|
-
|
2585
|
-
|
2586
|
-
|
2587
|
-
|
2588
|
-
|
2589
|
-
|
2590
|
-
|
2591
|
-
|
2592
|
-
|
2593
|
-
|
2594
|
-
|
2595
|
-
|
2596
|
-
|
2597
|
-
|
2598
|
-
|
2599
|
-
|
2600
|
-
|
2601
|
-
|
2602
|
-
|
2603
|
-
|
2604
|
-
|
2605
|
-
|
2606
|
-
|
2607
|
-
|
2608
|
-
|
2609
|
-
|
2610
|
-
|
2611
|
-
|
2612
|
-
|
2613
|
-
|
2614
|
-
|
2615
|
-
|
2616
|
-
|
2617
|
-
|
2618
|
-
|
2619
|
-
|
2620
|
-
|
2621
|
-
|
2622
|
-
|
2623
|
-
|
2624
|
-
|
2625
|
-
|
2626
|
-
|
2627
|
-
|
2628
|
-
custodyAccountMetas
|
2629
|
-
|
2630
|
-
|
2631
|
-
|
2632
|
-
|
2633
|
-
|
2634
|
-
|
2635
|
-
|
2636
|
-
|
2637
|
-
|
2638
|
-
|
2639
|
-
|
2640
|
-
|
2641
|
-
|
2642
|
-
|
2643
|
-
|
2644
|
-
|
2645
|
-
|
2646
|
-
|
2647
|
-
|
2648
|
-
|
2649
|
-
|
2650
|
-
|
2651
|
-
|
2652
|
-
|
2653
|
-
|
2654
|
-
|
2655
|
-
|
2656
|
-
|
2657
|
-
|
2658
|
-
|
2659
|
-
|
2660
|
-
|
2661
|
-
|
2662
|
-
|
2663
|
-
|
2664
|
-
|
2665
|
-
|
2666
|
-
|
2667
|
-
|
2668
|
-
|
2669
|
-
|
2670
|
-
|
2671
|
-
|
2672
|
-
|
2673
|
-
|
2674
|
-
|
2675
|
-
|
2676
|
-
|
2677
|
-
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2577
|
+
this.closePositionWithSwap = function (targetSymbol, outputSymbol, collateralSymbol, minAmountOut, priceAfterSlippage, side, swapPoolConfig, positionPoolConfig, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount) {
|
2578
|
+
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
2579
|
+
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
2580
|
+
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
2581
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2582
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, swapInCustodyConfig, swapOutCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody, instruction;
|
2583
|
+
return __generator(this, function (_b) {
|
2584
|
+
switch (_b.label) {
|
2585
|
+
case 0:
|
2586
|
+
publicKey = this.provider.wallet.publicKey;
|
2587
|
+
targetCustodyConfig = positionPoolConfig.custodies.find(function (i) { return i.mintKey.equals(positionPoolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
2588
|
+
collateralCustodyConfig = positionPoolConfig.custodies.find(function (i) { return i.mintKey.equals(positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
2589
|
+
swapInCustodyConfig = swapPoolConfig.custodies.find(function (i) { return i.mintKey.equals(swapPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
2590
|
+
swapOutCustodyConfig = swapPoolConfig.custodies.find(function (i) { return i.mintKey.equals(swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey); });
|
2591
|
+
if (swapOutCustodyConfig.mintKey.equals(collateralCustodyConfig.mintKey)) {
|
2592
|
+
throw "Dont use swap, just call close position";
|
2593
|
+
}
|
2594
|
+
preInstructions = [];
|
2595
|
+
instructions = [];
|
2596
|
+
postInstructions = [];
|
2597
|
+
additionalSigners = [];
|
2598
|
+
if (!(outputSymbol == 'SOL')) return [3, 2];
|
2599
|
+
console.log("outputSymbol === SOL", outputSymbol);
|
2600
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
2601
|
+
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
2602
|
+
case 1:
|
2603
|
+
lamports = (_b.sent());
|
2604
|
+
preInstructions = [
|
2605
|
+
web3_js_1.SystemProgram.createAccount({
|
2606
|
+
fromPubkey: publicKey,
|
2607
|
+
newAccountPubkey: wrappedSolAccount.publicKey,
|
2608
|
+
lamports: lamports,
|
2609
|
+
space: 165,
|
2610
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
2611
|
+
}),
|
2612
|
+
(0, spl_token_1.createInitializeAccount3Instruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, publicKey),
|
2613
|
+
];
|
2614
|
+
postInstructions = [
|
2615
|
+
(0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, publicKey, publicKey),
|
2616
|
+
];
|
2617
|
+
additionalSigners.push(wrappedSolAccount);
|
2618
|
+
return [3, 5];
|
2619
|
+
case 2: return [4, (0, spl_token_1.getAssociatedTokenAddress)(swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey)];
|
2620
|
+
case 3:
|
2621
|
+
userReceivingTokenAccount = _b.sent();
|
2622
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
2623
|
+
case 4:
|
2624
|
+
if (!(_b.sent())) {
|
2625
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, swapPoolConfig.getTokenFromSymbol(outputSymbol).mintKey));
|
2626
|
+
}
|
2627
|
+
_b.label = 5;
|
2628
|
+
case 5:
|
2629
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
2630
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2631
|
+
case 6:
|
2632
|
+
if (!(_b.sent())) {
|
2633
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, positionPoolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
2634
|
+
}
|
2635
|
+
marketAccount = positionPoolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2636
|
+
positionAccount = positionPoolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
2637
|
+
custodyAccountMetas = [];
|
2638
|
+
custodyOracleAccountMetas = [];
|
2639
|
+
for (_i = 0, _a = swapPoolConfig.custodies; _i < _a.length; _i++) {
|
2640
|
+
custody = _a[_i];
|
2641
|
+
custodyAccountMetas.push({
|
2642
|
+
pubkey: custody.custodyAccount,
|
2643
|
+
isSigner: false,
|
2644
|
+
isWritable: false,
|
2645
|
+
});
|
2646
|
+
custodyOracleAccountMetas.push({
|
2647
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
2648
|
+
isSigner: false,
|
2649
|
+
isWritable: false,
|
2650
|
+
});
|
2651
|
+
}
|
2652
|
+
return [4, this.programPerpComposability.methods
|
2653
|
+
.closeAndSwap({
|
2654
|
+
minAmountOut: minAmountOut,
|
2655
|
+
closePriceWithSlippage: priceAfterSlippage,
|
2656
|
+
privilege: privilege,
|
2657
|
+
})
|
2658
|
+
.accounts({
|
2659
|
+
perpProgram: this.programId,
|
2660
|
+
owner: publicKey,
|
2661
|
+
fundingAccount: userCollateralTokenAccount,
|
2662
|
+
receivingAccount: outputSymbol == 'SOL' ? wrappedSolAccount.publicKey : userReceivingTokenAccount,
|
2663
|
+
transferAuthority: swapPoolConfig.transferAuthority,
|
2664
|
+
perpetuals: swapPoolConfig.perpetuals,
|
2665
|
+
swapPool: swapPoolConfig.poolAddress,
|
2666
|
+
receivingCustody: swapInCustodyConfig.custodyAccount,
|
2667
|
+
receivingCustodyOracleAccount: this.useExtOracleAccount ? swapInCustodyConfig.extOracleAccount : swapInCustodyConfig.intOracleAccount,
|
2668
|
+
receivingCustodyTokenAccount: swapInCustodyConfig.tokenAccount,
|
2669
|
+
dispensingCustody: swapOutCustodyConfig.custodyAccount,
|
2670
|
+
dispensingCustodyOracleAccount: this.useExtOracleAccount ? swapOutCustodyConfig.extOracleAccount : swapOutCustodyConfig.intOracleAccount,
|
2671
|
+
dispensingCustodyTokenAccount: swapOutCustodyConfig.tokenAccount,
|
2672
|
+
positionPool: positionPoolConfig.poolAddress,
|
2673
|
+
position: positionAccount,
|
2674
|
+
market: marketAccount,
|
2675
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
2676
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
2677
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
2678
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
2679
|
+
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2680
|
+
eventAuthority: this.eventAuthority.publicKey,
|
2681
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2682
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2683
|
+
})
|
2684
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true), custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
2685
|
+
.instruction()];
|
2686
|
+
case 7:
|
2687
|
+
instruction = _b.sent();
|
2688
|
+
instructions.push(instruction);
|
2689
|
+
return [2, {
|
2690
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
2691
|
+
additionalSigners: additionalSigners
|
2692
|
+
}];
|
2693
|
+
}
|
2694
|
+
});
|
2681
2695
|
});
|
2682
|
-
}
|
2696
|
+
};
|
2683
2697
|
this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks) {
|
2684
2698
|
if (useFeesPool === void 0) { useFeesPool = false; }
|
2685
2699
|
if (createUserATA === void 0) { createUserATA = true; }
|
@@ -3413,116 +3427,126 @@ var PerpetualsClient = (function () {
|
|
3413
3427
|
}
|
3414
3428
|
});
|
3415
3429
|
}); };
|
3416
|
-
this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount
|
3417
|
-
|
3418
|
-
|
3419
|
-
|
3420
|
-
|
3421
|
-
|
3422
|
-
|
3423
|
-
|
3424
|
-
|
3425
|
-
|
3426
|
-
|
3427
|
-
|
3428
|
-
|
3429
|
-
|
3430
|
-
|
3431
|
-
|
3432
|
-
|
3433
|
-
|
3434
|
-
|
3435
|
-
|
3436
|
-
|
3437
|
-
|
3438
|
-
|
3439
|
-
|
3440
|
-
|
3441
|
-
|
3442
|
-
|
3443
|
-
|
3444
|
-
|
3445
|
-
|
3446
|
-
|
3447
|
-
|
3448
|
-
|
3449
|
-
|
3450
|
-
|
3451
|
-
|
3452
|
-
|
3453
|
-
|
3454
|
-
|
3455
|
-
|
3456
|
-
|
3457
|
-
|
3458
|
-
|
3459
|
-
|
3460
|
-
|
3461
|
-
|
3462
|
-
|
3463
|
-
|
3464
|
-
|
3465
|
-
|
3466
|
-
|
3467
|
-
|
3468
|
-
|
3430
|
+
this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount) {
|
3431
|
+
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
3432
|
+
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
3433
|
+
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
3434
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3435
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3436
|
+
return __generator(this, function (_a) {
|
3437
|
+
switch (_a.label) {
|
3438
|
+
case 0:
|
3439
|
+
publicKey = this.provider.wallet.publicKey;
|
3440
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
3441
|
+
return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey);
|
3442
|
+
});
|
3443
|
+
targetCustodyConfig = poolConfig.custodies.find(function (i) {
|
3444
|
+
return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey);
|
3445
|
+
});
|
3446
|
+
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3447
|
+
if (!collateralCustodyConfig || !targetCustodyConfig) {
|
3448
|
+
throw "collateralCustodyConfig/marketCustodyConfig not found";
|
3449
|
+
}
|
3450
|
+
preInstructions = [];
|
3451
|
+
instructions = [];
|
3452
|
+
postInstructions = [];
|
3453
|
+
additionalSigners = [];
|
3454
|
+
return [4, this.program.methods
|
3455
|
+
.increaseSize({
|
3456
|
+
priceWithSlippage: priceWithSlippage,
|
3457
|
+
sizeDelta: sizeDelta,
|
3458
|
+
privilege: privilege
|
3459
|
+
})
|
3460
|
+
.accounts({
|
3461
|
+
owner: publicKey,
|
3462
|
+
transferAuthority: poolConfig.transferAuthority,
|
3463
|
+
perpetuals: poolConfig.perpetuals,
|
3464
|
+
pool: poolConfig.poolAddress,
|
3465
|
+
position: positionPubKey,
|
3466
|
+
market: marketAccount,
|
3467
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
3468
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3469
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3470
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3471
|
+
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3472
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3473
|
+
eventAuthority: this.eventAuthority.publicKey,
|
3474
|
+
program: this.programId,
|
3475
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3476
|
+
})
|
3477
|
+
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
3478
|
+
.instruction()];
|
3479
|
+
case 1:
|
3480
|
+
instruction = _a.sent();
|
3481
|
+
instructions.push(instruction);
|
3482
|
+
return [2, {
|
3483
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3484
|
+
additionalSigners: additionalSigners
|
3485
|
+
}];
|
3486
|
+
}
|
3487
|
+
});
|
3469
3488
|
});
|
3470
|
-
}
|
3471
|
-
this.decreaseSize = function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount
|
3472
|
-
|
3473
|
-
|
3474
|
-
|
3475
|
-
|
3476
|
-
|
3477
|
-
|
3478
|
-
|
3479
|
-
|
3480
|
-
|
3481
|
-
|
3482
|
-
|
3483
|
-
|
3484
|
-
|
3485
|
-
|
3486
|
-
|
3487
|
-
|
3488
|
-
|
3489
|
-
|
3490
|
-
|
3491
|
-
|
3492
|
-
|
3493
|
-
|
3494
|
-
|
3495
|
-
|
3496
|
-
|
3497
|
-
|
3498
|
-
|
3499
|
-
|
3500
|
-
|
3501
|
-
|
3502
|
-
|
3503
|
-
|
3504
|
-
|
3505
|
-
|
3506
|
-
|
3507
|
-
|
3508
|
-
|
3509
|
-
|
3510
|
-
|
3511
|
-
|
3512
|
-
|
3513
|
-
|
3514
|
-
|
3515
|
-
|
3516
|
-
|
3517
|
-
|
3518
|
-
|
3519
|
-
|
3520
|
-
|
3521
|
-
|
3522
|
-
|
3523
|
-
|
3489
|
+
};
|
3490
|
+
this.decreaseSize = function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount) {
|
3491
|
+
if (nftTradingAccount === void 0) { nftTradingAccount = web3_js_1.PublicKey.default; }
|
3492
|
+
if (nftReferralAccount === void 0) { nftReferralAccount = web3_js_1.PublicKey.default; }
|
3493
|
+
if (nftRebateTokenAccount === void 0) { nftRebateTokenAccount = web3_js_1.PublicKey.default; }
|
3494
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3495
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3496
|
+
return __generator(this, function (_a) {
|
3497
|
+
switch (_a.label) {
|
3498
|
+
case 0:
|
3499
|
+
publicKey = this.provider.wallet.publicKey;
|
3500
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (i) {
|
3501
|
+
return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey);
|
3502
|
+
});
|
3503
|
+
targetCustodyConfig = poolConfig.custodies.find(function (i) {
|
3504
|
+
return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey);
|
3505
|
+
});
|
3506
|
+
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3507
|
+
if (!collateralCustodyConfig || !targetCustodyConfig) {
|
3508
|
+
throw "collateralCustodyConfig/marketCustodyConfig not found";
|
3509
|
+
}
|
3510
|
+
preInstructions = [];
|
3511
|
+
instructions = [];
|
3512
|
+
postInstructions = [];
|
3513
|
+
additionalSigners = [];
|
3514
|
+
return [4, this.program.methods
|
3515
|
+
.decreaseSize({
|
3516
|
+
priceWithSlippage: priceWithSlippage,
|
3517
|
+
sizeDelta: sizeDelta,
|
3518
|
+
privilege: privilege
|
3519
|
+
})
|
3520
|
+
.accounts({
|
3521
|
+
owner: publicKey,
|
3522
|
+
transferAuthority: poolConfig.transferAuthority,
|
3523
|
+
perpetuals: poolConfig.perpetuals,
|
3524
|
+
pool: poolConfig.poolAddress,
|
3525
|
+
position: positionPubKey,
|
3526
|
+
market: marketAccount,
|
3527
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
3528
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3529
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3530
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3531
|
+
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3532
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3533
|
+
eventAuthority: this.eventAuthority.publicKey,
|
3534
|
+
program: this.programId,
|
3535
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3536
|
+
})
|
3537
|
+
.remainingAccounts(__spreadArray([], (0, getNftAccounts_1.getNftAccounts)(nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege), true))
|
3538
|
+
.instruction()];
|
3539
|
+
case 1:
|
3540
|
+
instruction = _a.sent();
|
3541
|
+
instructions.push(instruction);
|
3542
|
+
return [2, {
|
3543
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3544
|
+
additionalSigners: additionalSigners
|
3545
|
+
}];
|
3546
|
+
}
|
3547
|
+
});
|
3524
3548
|
});
|
3525
|
-
}
|
3549
|
+
};
|
3526
3550
|
this.addLiquidity = function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks) {
|
3527
3551
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3528
3552
|
return __awaiter(_this, void 0, void 0, function () {
|
@@ -5617,7 +5641,7 @@ var PerpetualsClient = (function () {
|
|
5617
5641
|
pool: poolConfig.poolAddress,
|
5618
5642
|
flpStakeAccount: flpStakeAccount,
|
5619
5643
|
rewardCustody: rewardCustody.custodyAccount,
|
5620
|
-
rewardCustodyOracleAccount:
|
5644
|
+
rewardCustodyOracleAccount: rewardCustody.intOracleAccount,
|
5621
5645
|
poolStakedLpVault: poolStakedLpVault,
|
5622
5646
|
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
5623
5647
|
lpTokenMint: lpTokenMint,
|
@@ -5645,96 +5669,10 @@ var PerpetualsClient = (function () {
|
|
5645
5669
|
});
|
5646
5670
|
});
|
5647
5671
|
};
|
5648
|
-
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5649
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, compoundingLpVault, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_33;
|
5650
|
-
return __generator(this, function (_d) {
|
5651
|
-
switch (_d.label) {
|
5652
|
-
case 0:
|
5653
|
-
publicKey = this.provider.wallet.publicKey;
|
5654
|
-
preInstructions = [];
|
5655
|
-
instructions = [];
|
5656
|
-
postInstructions = [];
|
5657
|
-
additionalSigners = [];
|
5658
|
-
rewardCustody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardTokenMint); });
|
5659
|
-
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5660
|
-
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
5661
|
-
return [4, (0, spl_token_1.getAssociatedTokenAddress)(compoundingTokenMint, publicKey)];
|
5662
|
-
case 1:
|
5663
|
-
compoudingTokenAccount = _d.sent();
|
5664
|
-
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
5665
|
-
compoundingLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("compounding_token_account"), poolConfig.poolAddress.toBuffer(), poolConfig.stakedLpTokenMint.toBuffer()], this.programId)[0];
|
5666
|
-
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
5667
|
-
custodyAccountMetas = [];
|
5668
|
-
custodyOracleAccountMetas = [];
|
5669
|
-
markets = [];
|
5670
|
-
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
5671
|
-
custody = _a[_i];
|
5672
|
-
custodyAccountMetas.push({
|
5673
|
-
pubkey: custody.custodyAccount,
|
5674
|
-
isSigner: false,
|
5675
|
-
isWritable: false,
|
5676
|
-
});
|
5677
|
-
custodyOracleAccountMetas.push({
|
5678
|
-
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
5679
|
-
isSigner: false,
|
5680
|
-
isWritable: false,
|
5681
|
-
});
|
5682
|
-
}
|
5683
|
-
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
5684
|
-
market = _c[_b];
|
5685
|
-
markets.push({
|
5686
|
-
pubkey: market.marketAccount,
|
5687
|
-
isSigner: false,
|
5688
|
-
isWritable: false,
|
5689
|
-
});
|
5690
|
-
}
|
5691
|
-
_d.label = 2;
|
5692
|
-
case 2:
|
5693
|
-
_d.trys.push([2, 4, , 5]);
|
5694
|
-
return [4, this.program.methods
|
5695
|
-
.migrateFlp({
|
5696
|
-
compoundingTokenAmount: amount
|
5697
|
-
})
|
5698
|
-
.accounts({
|
5699
|
-
owner: publicKey,
|
5700
|
-
compoundingTokenAccount: compoudingTokenAccount,
|
5701
|
-
transferAuthority: poolConfig.transferAuthority,
|
5702
|
-
perpetuals: poolConfig.perpetuals,
|
5703
|
-
pool: poolConfig.poolAddress,
|
5704
|
-
flpStakeAccount: flpStakeAccount,
|
5705
|
-
rewardCustody: rewardCustody.custodyAccount,
|
5706
|
-
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
5707
|
-
poolStakedLpVault: poolStakedLpVault,
|
5708
|
-
poolCompoundingLpVault: compoundingLpVault,
|
5709
|
-
lpTokenMint: lpTokenMint,
|
5710
|
-
compoundingTokenMint: compoundingTokenMint,
|
5711
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
5712
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5713
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5714
|
-
program: this.program.programId,
|
5715
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5716
|
-
})
|
5717
|
-
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5718
|
-
.instruction()];
|
5719
|
-
case 3:
|
5720
|
-
migrateFlp = _d.sent();
|
5721
|
-
instructions.push(migrateFlp);
|
5722
|
-
return [3, 5];
|
5723
|
-
case 4:
|
5724
|
-
err_33 = _d.sent();
|
5725
|
-
console.log("perpClient migrateFlp error:: ", err_33);
|
5726
|
-
return [3, 5];
|
5727
|
-
case 5: return [2, {
|
5728
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5729
|
-
additionalSigners: additionalSigners
|
5730
|
-
}];
|
5731
|
-
}
|
5732
|
-
});
|
5733
|
-
}); };
|
5734
5672
|
this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
|
5735
5673
|
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
5736
5674
|
return __awaiter(_this, void 0, void 0, function () {
|
5737
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee,
|
5675
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_33;
|
5738
5676
|
return __generator(this, function (_d) {
|
5739
5677
|
switch (_d.label) {
|
5740
5678
|
case 0:
|
@@ -5791,8 +5729,8 @@ var PerpetualsClient = (function () {
|
|
5791
5729
|
instructions.push(compoundingFee);
|
5792
5730
|
return [3, 4];
|
5793
5731
|
case 3:
|
5794
|
-
|
5795
|
-
console.log("perpClient compoundingFee error:: ",
|
5732
|
+
err_33 = _d.sent();
|
5733
|
+
console.log("perpClient compoundingFee error:: ", err_33);
|
5796
5734
|
return [3, 4];
|
5797
5735
|
case 4: return [2, {
|
5798
5736
|
instructions: __spreadArray([], instructions, true),
|
@@ -5803,7 +5741,7 @@ var PerpetualsClient = (function () {
|
|
5803
5741
|
});
|
5804
5742
|
};
|
5805
5743
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5806
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
5744
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_34;
|
5807
5745
|
return __generator(this, function (_a) {
|
5808
5746
|
switch (_a.label) {
|
5809
5747
|
case 0:
|
@@ -5841,8 +5779,8 @@ var PerpetualsClient = (function () {
|
|
5841
5779
|
instructions.push(renameFlp);
|
5842
5780
|
return [3, 4];
|
5843
5781
|
case 3:
|
5844
|
-
|
5845
|
-
console.log("perpClient renameFlp error:: ",
|
5782
|
+
err_34 = _a.sent();
|
5783
|
+
console.log("perpClient renameFlp error:: ", err_34);
|
5846
5784
|
return [3, 4];
|
5847
5785
|
case 4: return [2, {
|
5848
5786
|
instructions: __spreadArray([], instructions, true),
|
@@ -5852,7 +5790,7 @@ var PerpetualsClient = (function () {
|
|
5852
5790
|
});
|
5853
5791
|
}); };
|
5854
5792
|
this.initRewardDistribution = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5855
|
-
var publicKey, rewardMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, transferAuthority, initRewardVault,
|
5793
|
+
var publicKey, rewardMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, transferAuthority, initRewardVault, err_35;
|
5856
5794
|
return __generator(this, function (_a) {
|
5857
5795
|
switch (_a.label) {
|
5858
5796
|
case 0:
|
@@ -5886,9 +5824,9 @@ var PerpetualsClient = (function () {
|
|
5886
5824
|
instructions.push(initRewardVault);
|
5887
5825
|
return [3, 4];
|
5888
5826
|
case 3:
|
5889
|
-
|
5890
|
-
console.log("rewardDistribution InitRewardVault error:: ",
|
5891
|
-
throw
|
5827
|
+
err_35 = _a.sent();
|
5828
|
+
console.log("rewardDistribution InitRewardVault error:: ", err_35);
|
5829
|
+
throw err_35;
|
5892
5830
|
case 4: return [2, {
|
5893
5831
|
instructions: __spreadArray([], instructions, true),
|
5894
5832
|
additionalSigners: additionalSigners
|
@@ -5897,7 +5835,7 @@ var PerpetualsClient = (function () {
|
|
5897
5835
|
});
|
5898
5836
|
}); };
|
5899
5837
|
this.updateCounterReward = function () { return __awaiter(_this, void 0, void 0, function () {
|
5900
|
-
var publicKey, instructions, additionalSigners, rewardVault, updateCounter,
|
5838
|
+
var publicKey, instructions, additionalSigners, rewardVault, updateCounter, err_36;
|
5901
5839
|
return __generator(this, function (_a) {
|
5902
5840
|
switch (_a.label) {
|
5903
5841
|
case 0:
|
@@ -5920,9 +5858,9 @@ var PerpetualsClient = (function () {
|
|
5920
5858
|
instructions.push(updateCounter);
|
5921
5859
|
return [3, 4];
|
5922
5860
|
case 3:
|
5923
|
-
|
5924
|
-
console.log("rewardDistribution updateCounter error:: ",
|
5925
|
-
throw
|
5861
|
+
err_36 = _a.sent();
|
5862
|
+
console.log("rewardDistribution updateCounter error:: ", err_36);
|
5863
|
+
throw err_36;
|
5926
5864
|
case 4: return [2, {
|
5927
5865
|
instructions: __spreadArray([], instructions, true),
|
5928
5866
|
additionalSigners: additionalSigners
|
@@ -5931,7 +5869,7 @@ var PerpetualsClient = (function () {
|
|
5931
5869
|
});
|
5932
5870
|
}); };
|
5933
5871
|
this.rewardDistribution = function (counter, owner, rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5934
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward,
|
5872
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, rewardRecord, distributeReward, err_37;
|
5935
5873
|
return __generator(this, function (_a) {
|
5936
5874
|
switch (_a.label) {
|
5937
5875
|
case 0:
|
@@ -5972,9 +5910,9 @@ var PerpetualsClient = (function () {
|
|
5972
5910
|
instructions.push(distributeReward);
|
5973
5911
|
return [3, 5];
|
5974
5912
|
case 4:
|
5975
|
-
|
5976
|
-
console.log("rewardDistribution distributeReward error:: ",
|
5977
|
-
throw
|
5913
|
+
err_37 = _a.sent();
|
5914
|
+
console.log("rewardDistribution distributeReward error:: ", err_37);
|
5915
|
+
throw err_37;
|
5978
5916
|
case 5: return [2, {
|
5979
5917
|
instructions: __spreadArray([], instructions, true),
|
5980
5918
|
additionalSigners: additionalSigners
|
@@ -5985,7 +5923,7 @@ var PerpetualsClient = (function () {
|
|
5985
5923
|
this.collectReward = function (counter, owner, rewardSymbol, poolConfig, createUserATA) {
|
5986
5924
|
if (createUserATA === void 0) { createUserATA = true; }
|
5987
5925
|
return __awaiter(_this, void 0, void 0, function () {
|
5988
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectNftReward,
|
5926
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, receivingTokenAccount, _a, rewardVault, rewardTokenAccount, rewardRecord, transferAuthority, collectNftReward, err_38;
|
5989
5927
|
return __generator(this, function (_b) {
|
5990
5928
|
switch (_b.label) {
|
5991
5929
|
case 0:
|
@@ -6033,8 +5971,8 @@ var PerpetualsClient = (function () {
|
|
6033
5971
|
instructions.push(collectNftReward);
|
6034
5972
|
return [3, 7];
|
6035
5973
|
case 6:
|
6036
|
-
|
6037
|
-
throw
|
5974
|
+
err_38 = _b.sent();
|
5975
|
+
throw err_38;
|
6038
5976
|
case 7: return [2, {
|
6039
5977
|
instructions: __spreadArray([], instructions, true),
|
6040
5978
|
additionalSigners: additionalSigners
|