flash-sdk 2.51.6 → 2.52.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 +56 -55
- package/dist/PerpetualsClient.js +1596 -1540
- package/dist/TokenStakeAccount.d.ts +40 -0
- package/dist/TokenStakeAccount.js +47 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -79,6 +79,8 @@ var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
79
79
|
var backupOracle_1 = require("./backupOracle");
|
80
80
|
var getReferralAccounts_1 = require("./utils/getReferralAccounts");
|
81
81
|
var ViewHelper_1 = require("./ViewHelper");
|
82
|
+
var TokenStakeAccount_1 = require("./TokenStakeAccount");
|
83
|
+
var TokenVaultAccount_1 = require("./TokenVaultAccount");
|
82
84
|
var PerpetualsClient = (function () {
|
83
85
|
function PerpetualsClient(provider, programId, composabilityProgramId, fbNftRewardProgramId, rewardDistributionProgramId, opts, useExtOracleAccount) {
|
84
86
|
if (useExtOracleAccount === void 0) { useExtOracleAccount = false; }
|
@@ -230,6 +232,43 @@ var PerpetualsClient = (function () {
|
|
230
232
|
return [2, this.program.account.position.fetch(postionKey)];
|
231
233
|
});
|
232
234
|
}); };
|
235
|
+
this.getPositionData = function (position, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
236
|
+
var marketConfig, targetCustodyConfig, collateralCustodyConfig, getPositionData, err_1;
|
237
|
+
return __generator(this, function (_a) {
|
238
|
+
switch (_a.label) {
|
239
|
+
case 0:
|
240
|
+
marketConfig = poolConfig.markets.find(function (i) { return i.marketAccount.equals(position.market); });
|
241
|
+
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.custodyAccount.equals(marketConfig.targetCustody); });
|
242
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.custodyAccount.equals(marketConfig.collateralCustody); });
|
243
|
+
_a.label = 1;
|
244
|
+
case 1:
|
245
|
+
_a.trys.push([1, 3, , 4]);
|
246
|
+
return [4, this.program.methods
|
247
|
+
.getPositionData({})
|
248
|
+
.accounts({
|
249
|
+
perpetuals: this.perpetuals.publicKey,
|
250
|
+
pool: poolConfig.poolAddress,
|
251
|
+
position: position.publicKey,
|
252
|
+
market: marketConfig.marketAccount,
|
253
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
254
|
+
custodyOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
255
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
256
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
257
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
258
|
+
})
|
259
|
+
.view()];
|
260
|
+
case 2:
|
261
|
+
getPositionData = _a.sent();
|
262
|
+
console.log(getPositionData);
|
263
|
+
return [2, getPositionData];
|
264
|
+
case 3:
|
265
|
+
err_1 = _a.sent();
|
266
|
+
console.log("perpClient setPool error:: ", err_1);
|
267
|
+
throw err_1;
|
268
|
+
case 4: return [2];
|
269
|
+
}
|
270
|
+
});
|
271
|
+
}); };
|
233
272
|
this.getOrderAccount = function (orderAccountKey) { return __awaiter(_this, void 0, void 0, function () {
|
234
273
|
return __generator(this, function (_a) {
|
235
274
|
return [2, this.program.account.order.fetch(orderAccountKey)];
|
@@ -362,375 +401,115 @@ var PerpetualsClient = (function () {
|
|
362
401
|
this.prettyPrint = function (object) {
|
363
402
|
console.log(JSON.stringify(object, null, 2));
|
364
403
|
};
|
365
|
-
this.
|
366
|
-
var
|
404
|
+
this.liquidate = function (positionAccount, poolConfig, tokenMint, collateralMint, marketPk) { return __awaiter(_this, void 0, void 0, function () {
|
405
|
+
var targetCustodyConfig, collateralCustodyConfig;
|
367
406
|
return __generator(this, function (_a) {
|
368
407
|
switch (_a.label) {
|
369
408
|
case 0:
|
370
|
-
|
371
|
-
|
372
|
-
for (_i = 0, admins_1 = admins; _i < admins_1.length; _i++) {
|
373
|
-
admin = admins_1[_i];
|
374
|
-
adminMetas.push({
|
375
|
-
isSigner: false,
|
376
|
-
isWritable: false,
|
377
|
-
pubkey: admin,
|
378
|
-
});
|
379
|
-
}
|
409
|
+
targetCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(tokenMint); });
|
410
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(collateralMint); });
|
380
411
|
return [4, this.program.methods
|
381
|
-
.
|
412
|
+
.liquidate({})
|
382
413
|
.accounts({
|
383
|
-
|
384
|
-
multisig: this.multisig.publicKey,
|
385
|
-
transferAuthority: this.authority.publicKey,
|
414
|
+
signer: this.provider.wallet.publicKey,
|
386
415
|
perpetuals: this.perpetuals.publicKey,
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
416
|
+
pool: poolConfig.poolAddress,
|
417
|
+
position: positionAccount,
|
418
|
+
market: marketPk,
|
419
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
420
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
421
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
422
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
423
|
+
eventAuthority: this.eventAuthority.publicKey,
|
424
|
+
program: this.program.programId,
|
425
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
391
426
|
})
|
392
|
-
.
|
393
|
-
|
394
|
-
.catch(function (err) {
|
395
|
-
console.error(err);
|
396
|
-
throw err;
|
397
|
-
})];
|
398
|
-
case 1:
|
399
|
-
_a.sent();
|
400
|
-
return [2];
|
427
|
+
.instruction()];
|
428
|
+
case 1: return [2, _a.sent()];
|
401
429
|
}
|
402
430
|
});
|
403
431
|
}); };
|
404
|
-
this.
|
405
|
-
var
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
432
|
+
this.getApyPercentageUi = function (rewardCustodyAccount, previousSnapShotRewardPerLpStaked, lpTokenUsdPrice) {
|
433
|
+
var currentRewardPerLpStaked = rewardCustodyAccount.feesStats.rewardPerLpStaked;
|
434
|
+
var difference = currentRewardPerLpStaked.sub(previousSnapShotRewardPerLpStaked);
|
435
|
+
var anualizedRewardUi = new bignumber_js_1.default(difference.toString()).multipliedBy(365).dividedBy(lpTokenUsdPrice.toString());
|
436
|
+
var percentage = anualizedRewardUi.multipliedBy(100);
|
437
|
+
return percentage.toString();
|
438
|
+
};
|
439
|
+
this.getAddLiquidityAmountAndFeeSync = function (amountIn, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, lpTokenSupplyAmount, poolAumUsdMax, poolConfig) {
|
440
|
+
if (inputTokenCustodyAccount.isVirtual) {
|
441
|
+
throw new Error("Virtual custody, cannot add liquidity");
|
442
|
+
}
|
443
|
+
if (!inputTokenPrice.exponent.eq(inputTokenEmaPrice.exponent)) {
|
444
|
+
throw new Error("exponent mistach");
|
445
|
+
}
|
446
|
+
var minMaxPrice = _this.getMinAndMaxOraclePriceSync(inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount);
|
447
|
+
var fee = _this.getFeeHelper(types_1.FeesAction.AddLiquidity, amountIn, constants_1.BN_ZERO, inputTokenCustodyAccount, minMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
|
448
|
+
var tokenAmountUsd = minMaxPrice.min.getAssetAmountUsd((amountIn.sub(fee)), inputTokenCustodyAccount.decimals);
|
449
|
+
var lpTokenOut;
|
450
|
+
if (poolAumUsdMax.isZero()) {
|
451
|
+
lpTokenOut = tokenAmountUsd;
|
452
|
+
}
|
453
|
+
else {
|
454
|
+
lpTokenOut = (tokenAmountUsd.mul(lpTokenSupplyAmount)).div(poolAumUsdMax);
|
455
|
+
}
|
456
|
+
return {
|
457
|
+
lpAmountOut: lpTokenOut,
|
458
|
+
fee: fee
|
459
|
+
};
|
460
|
+
};
|
461
|
+
this.getRemoveLiquidityAmountAndFeeSync = function (lpAmountIn, poolAccount, outputTokenPrice, outputTokenEmaPrice, outputTokenCustodyAccount, lpTokenSupply, poolAumUsdMax, poolConfig) {
|
462
|
+
if (!outputTokenPrice.exponent.eq(outputTokenEmaPrice.exponent)) {
|
463
|
+
throw new Error("exponent mistach");
|
464
|
+
}
|
465
|
+
var minMaxPrice = _this.getMinAndMaxOraclePriceSync(outputTokenPrice, outputTokenEmaPrice, outputTokenCustodyAccount);
|
466
|
+
var removeAmountUsd = (poolAumUsdMax.mul(lpAmountIn)).div(lpTokenSupply);
|
467
|
+
var removeAmount;
|
468
|
+
var oneOracle = OraclePrice_1.OraclePrice.from({ price: new anchor_1.BN(Math.pow(10, 8)), exponent: new anchor_1.BN(-8), confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
|
469
|
+
if (outputTokenCustodyAccount.isStable && minMaxPrice.min != minMaxPrice.max && minMaxPrice.max.price.lt(oneOracle.price)) {
|
470
|
+
removeAmount = oneOracle.getTokenAmount(removeAmountUsd, outputTokenCustodyAccount.decimals);
|
471
|
+
}
|
472
|
+
else {
|
473
|
+
removeAmount = minMaxPrice.max.getTokenAmount(removeAmountUsd, outputTokenCustodyAccount.decimals);
|
474
|
+
}
|
475
|
+
var fee = _this.getFeeHelper(types_1.FeesAction.RemoveLiquidity, constants_1.BN_ZERO, removeAmount, outputTokenCustodyAccount, minMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
|
476
|
+
return {
|
477
|
+
tokenAmountOut: removeAmount.sub(fee),
|
478
|
+
fee: fee,
|
479
|
+
};
|
480
|
+
};
|
481
|
+
this.getFeeHelper = function (action, amountAdd, amountRemove, inputTokenCustodyAccount, maxOraclePrice, poolAumUsdMax, poolAccount, poolConfig) {
|
482
|
+
var fees;
|
483
|
+
switch (action) {
|
484
|
+
case types_1.FeesAction.AddLiquidity:
|
485
|
+
fees = inputTokenCustodyAccount.fees.addLiquidity;
|
486
|
+
break;
|
487
|
+
case types_1.FeesAction.RemoveLiquidity:
|
488
|
+
fees = inputTokenCustodyAccount.fees.removeLiquidity;
|
489
|
+
break;
|
490
|
+
case types_1.FeesAction.SwapIn:
|
491
|
+
fees = inputTokenCustodyAccount.fees.swapIn;
|
492
|
+
break;
|
493
|
+
case types_1.FeesAction.SwapOut:
|
494
|
+
fees = inputTokenCustodyAccount.fees.swapOut;
|
495
|
+
break;
|
496
|
+
}
|
497
|
+
if (inputTokenCustodyAccount.fees.mode == types_1.FeesMode.Fixed) {
|
498
|
+
return { feeBps: fees.minFee, feeAmount: anchor_1.BN.max(amountAdd, amountRemove).mul(fees.minFee).div(new anchor_1.BN(constants_1.RATE_POWER)) };
|
499
|
+
}
|
500
|
+
var newRatio = _this.getNewRatioHelper(amountAdd, amountRemove, inputTokenCustodyAccount, maxOraclePrice, poolAumUsdMax);
|
501
|
+
var index = poolAccount.custodies.findIndex(function (c) { return c.equals(inputTokenCustodyAccount.publicKey); });
|
502
|
+
var ratios = poolAccount.ratios[index];
|
503
|
+
var fee = constants_1.BN_ZERO;
|
504
|
+
if (action == types_1.FeesAction.AddLiquidity || action == types_1.FeesAction.SwapIn || action == types_1.FeesAction.StableSwapIn) {
|
505
|
+
if (newRatio.lte(ratios.min)) {
|
506
|
+
fee = fees.minFee;
|
441
507
|
}
|
442
|
-
|
443
|
-
|
444
|
-
this.addPool = function (name, maxAumUsd, permissions, metadataSymbol, metadataTitle, metadataUri, stakingFeeShareBps, vpVolumeFactor) { return __awaiter(_this, void 0, void 0, function () {
|
445
|
-
return __generator(this, function (_a) {
|
446
|
-
switch (_a.label) {
|
447
|
-
case 0: return [4, this.program.methods
|
448
|
-
.addPool({
|
449
|
-
name: name,
|
450
|
-
maxAumUsd: maxAumUsd,
|
451
|
-
permissions: permissions,
|
452
|
-
metadataSymbol: metadataSymbol,
|
453
|
-
metadataTitle: metadataTitle,
|
454
|
-
metadataUri: metadataUri,
|
455
|
-
stakingFeeShareBps: stakingFeeShareBps,
|
456
|
-
vpVolumeFactor: vpVolumeFactor
|
457
|
-
})
|
458
|
-
.accounts({
|
459
|
-
admin: this.provider.wallet.publicKey,
|
460
|
-
multisig: this.multisig.publicKey,
|
461
|
-
transferAuthority: this.authority.publicKey,
|
462
|
-
perpetuals: this.perpetuals.publicKey,
|
463
|
-
pool: this.getPoolKey(name),
|
464
|
-
lpTokenMint: this.getPoolLpTokenKey(name),
|
465
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
466
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
467
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
468
|
-
})
|
469
|
-
.rpc()
|
470
|
-
.catch(function (err) {
|
471
|
-
console.error(err);
|
472
|
-
throw err;
|
473
|
-
})];
|
474
|
-
case 1:
|
475
|
-
_a.sent();
|
476
|
-
return [2];
|
508
|
+
else if (newRatio.lte(ratios.target) && ratios.target.gt(ratios.min)) {
|
509
|
+
fee = fees.minFee.add((newRatio.sub(ratios.min)).mul(fees.targetFee.sub(fees.minFee)).div(ratios.target.sub(ratios.min)));
|
477
510
|
}
|
478
|
-
|
479
|
-
|
480
|
-
this.removePool = function (name) { return __awaiter(_this, void 0, void 0, function () {
|
481
|
-
return __generator(this, function (_a) {
|
482
|
-
switch (_a.label) {
|
483
|
-
case 0: return [4, this.program.methods
|
484
|
-
.removePool({})
|
485
|
-
.accounts({
|
486
|
-
admin: this.admin,
|
487
|
-
multisig: this.multisig.publicKey,
|
488
|
-
transferAuthority: this.authority.publicKey,
|
489
|
-
perpetuals: this.perpetuals.publicKey,
|
490
|
-
pool: this.getPoolKey(name),
|
491
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
492
|
-
})
|
493
|
-
.rpc()
|
494
|
-
.catch(function (err) {
|
495
|
-
console.error(err);
|
496
|
-
throw err;
|
497
|
-
})];
|
498
|
-
case 1:
|
499
|
-
_a.sent();
|
500
|
-
return [2];
|
501
|
-
}
|
502
|
-
});
|
503
|
-
}); };
|
504
|
-
this.addCustody = function (poolName, tokenMint, isStable, isVirtual, oracle, pricing, permissions, fees, borrowRate, ratios, depegAdjustment) { return __awaiter(_this, void 0, void 0, function () {
|
505
|
-
var trx_id, error_1;
|
506
|
-
return __generator(this, function (_a) {
|
507
|
-
switch (_a.label) {
|
508
|
-
case 0:
|
509
|
-
_a.trys.push([0, 2, , 3]);
|
510
|
-
return [4, this.program.methods
|
511
|
-
.addCustody({
|
512
|
-
isStable: isStable,
|
513
|
-
isVirtual: isVirtual,
|
514
|
-
oracle: oracle,
|
515
|
-
pricing: pricing,
|
516
|
-
permissions: permissions,
|
517
|
-
fees: fees,
|
518
|
-
borrowRate: borrowRate,
|
519
|
-
ratios: ratios,
|
520
|
-
depegAdjustment: depegAdjustment
|
521
|
-
})
|
522
|
-
.accounts({
|
523
|
-
admin: this.admin,
|
524
|
-
multisig: this.multisig.publicKey,
|
525
|
-
transferAuthority: this.authority.publicKey,
|
526
|
-
perpetuals: this.perpetuals.publicKey,
|
527
|
-
pool: this.getPoolKey(poolName),
|
528
|
-
custody: this.getCustodyKey(poolName, tokenMint),
|
529
|
-
custodyTokenAccount: this.getCustodyTokenAccountKey(poolName, tokenMint),
|
530
|
-
custodyTokenMint: tokenMint,
|
531
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
532
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
533
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
534
|
-
})
|
535
|
-
.rpc()
|
536
|
-
.catch(function (err) {
|
537
|
-
console.error(err);
|
538
|
-
throw err;
|
539
|
-
})];
|
540
|
-
case 1:
|
541
|
-
trx_id = _a.sent();
|
542
|
-
console.log("trx_id:", "https://explorer.solana.com/tx/".concat(trx_id, "?cluster=devnet"));
|
543
|
-
return [3, 3];
|
544
|
-
case 2:
|
545
|
-
error_1 = _a.sent();
|
546
|
-
console.error("cli error :", error_1);
|
547
|
-
throw error_1;
|
548
|
-
case 3: return [2];
|
549
|
-
}
|
550
|
-
});
|
551
|
-
}); };
|
552
|
-
this.editCustody = function (poolName, tokenMint, isStable, oracle, pricing, permissions, fees, borrowRate, ratios) { return __awaiter(_this, void 0, void 0, function () {
|
553
|
-
var trx_id;
|
554
|
-
return __generator(this, function (_a) {
|
555
|
-
switch (_a.label) {
|
556
|
-
case 0: return [4, this.program.methods
|
557
|
-
.testingEditCustody({
|
558
|
-
isStable: isStable,
|
559
|
-
oracle: oracle,
|
560
|
-
pricing: pricing,
|
561
|
-
permissions: permissions,
|
562
|
-
fees: fees,
|
563
|
-
borrowRate: borrowRate,
|
564
|
-
ratios: ratios,
|
565
|
-
})
|
566
|
-
.accounts({
|
567
|
-
admin: this.admin,
|
568
|
-
multisig: this.multisig.publicKey,
|
569
|
-
transferAuthority: this.authority.publicKey,
|
570
|
-
perpetuals: this.perpetuals.publicKey,
|
571
|
-
pool: this.getPoolKey(poolName),
|
572
|
-
custody: this.getCustodyKey(poolName, tokenMint),
|
573
|
-
custodyTokenAccount: this.getCustodyTokenAccountKey(poolName, tokenMint),
|
574
|
-
custodyTokenMint: tokenMint,
|
575
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
576
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
577
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
578
|
-
})
|
579
|
-
.rpc()
|
580
|
-
.catch(function (err) {
|
581
|
-
console.error(err);
|
582
|
-
throw err;
|
583
|
-
})];
|
584
|
-
case 1:
|
585
|
-
trx_id = _a.sent();
|
586
|
-
console.log("trx_id:", "https://explorer.solana.com/tx/".concat(trx_id, "?cluster=devnet"));
|
587
|
-
return [2];
|
588
|
-
}
|
589
|
-
});
|
590
|
-
}); };
|
591
|
-
this.removeCustody = function (poolName, tokenMint, ratios, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
592
|
-
var custodyConfig, userReceivingTokenAccount;
|
593
|
-
return __generator(this, function (_a) {
|
594
|
-
switch (_a.label) {
|
595
|
-
case 0:
|
596
|
-
custodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(tokenMint); });
|
597
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, this.admin, true);
|
598
|
-
return [4, this.program.methods
|
599
|
-
.removeCustody({ ratios: ratios })
|
600
|
-
.accounts({
|
601
|
-
admin: this.admin,
|
602
|
-
receivingAccount: userReceivingTokenAccount,
|
603
|
-
multisig: this.multisig.publicKey,
|
604
|
-
transferAuthority: this.authority.publicKey,
|
605
|
-
perpetuals: this.perpetuals.publicKey,
|
606
|
-
pool: this.getPoolKey(poolName),
|
607
|
-
custody: this.getCustodyKey(poolName, tokenMint),
|
608
|
-
custodyTokenAccount: this.getCustodyTokenAccountKey(poolName, tokenMint),
|
609
|
-
custodyOracleAccount: this.useExtOracleAccount ? custodyConfig.extOracleAccount : custodyConfig.intOracleAccount,
|
610
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
611
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
612
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
613
|
-
})
|
614
|
-
.rpc()
|
615
|
-
.catch(function (err) {
|
616
|
-
console.error(err);
|
617
|
-
throw err;
|
618
|
-
})];
|
619
|
-
case 1:
|
620
|
-
_a.sent();
|
621
|
-
return [2];
|
622
|
-
}
|
623
|
-
});
|
624
|
-
}); };
|
625
|
-
this.liquidate = function (positionAccount, poolConfig, tokenMint, collateralMint, marketPk) { return __awaiter(_this, void 0, void 0, function () {
|
626
|
-
var targetCustodyConfig, collateralCustodyConfig;
|
627
|
-
return __generator(this, function (_a) {
|
628
|
-
switch (_a.label) {
|
629
|
-
case 0:
|
630
|
-
targetCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(tokenMint); });
|
631
|
-
collateralCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(collateralMint); });
|
632
|
-
return [4, this.program.methods
|
633
|
-
.liquidate({})
|
634
|
-
.accounts({
|
635
|
-
signer: this.provider.wallet.publicKey,
|
636
|
-
perpetuals: this.perpetuals.publicKey,
|
637
|
-
pool: poolConfig.poolAddress,
|
638
|
-
position: positionAccount,
|
639
|
-
market: marketPk,
|
640
|
-
targetCustody: targetCustodyConfig.custodyAccount,
|
641
|
-
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
642
|
-
collateralCustody: collateralCustodyConfig.custodyAccount,
|
643
|
-
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
644
|
-
eventAuthority: this.eventAuthority.publicKey,
|
645
|
-
program: this.program.programId,
|
646
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
647
|
-
})
|
648
|
-
.instruction()];
|
649
|
-
case 1: return [2, _a.sent()];
|
650
|
-
}
|
651
|
-
});
|
652
|
-
}); };
|
653
|
-
this.getApyPercentageUi = function (rewardCustodyAccount, previousSnapShotRewardPerLpStaked, lpTokenUsdPrice) {
|
654
|
-
var currentRewardPerLpStaked = rewardCustodyAccount.feesStats.rewardPerLpStaked;
|
655
|
-
var difference = currentRewardPerLpStaked.sub(previousSnapShotRewardPerLpStaked);
|
656
|
-
var anualizedRewardUi = new bignumber_js_1.default(difference.toString()).multipliedBy(365).dividedBy(lpTokenUsdPrice.toString());
|
657
|
-
var percentage = anualizedRewardUi.multipliedBy(100);
|
658
|
-
return percentage.toString();
|
659
|
-
};
|
660
|
-
this.getAddLiquidityAmountAndFeeSync = function (amountIn, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, lpTokenSupplyAmount, poolAumUsdMax, poolConfig) {
|
661
|
-
if (inputTokenCustodyAccount.isVirtual) {
|
662
|
-
throw new Error("Virtual custody, cannot add liquidity");
|
663
|
-
}
|
664
|
-
if (!inputTokenPrice.exponent.eq(inputTokenEmaPrice.exponent)) {
|
665
|
-
throw new Error("exponent mistach");
|
666
|
-
}
|
667
|
-
var minMaxPrice = _this.getMinAndMaxOraclePriceSync(inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount);
|
668
|
-
var fee = _this.getFeeHelper(types_1.FeesAction.AddLiquidity, amountIn, constants_1.BN_ZERO, inputTokenCustodyAccount, minMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
|
669
|
-
var tokenAmountUsd = minMaxPrice.min.getAssetAmountUsd((amountIn.sub(fee)), inputTokenCustodyAccount.decimals);
|
670
|
-
var lpTokenOut;
|
671
|
-
if (poolAumUsdMax.isZero()) {
|
672
|
-
lpTokenOut = tokenAmountUsd;
|
673
|
-
}
|
674
|
-
else {
|
675
|
-
lpTokenOut = (tokenAmountUsd.mul(lpTokenSupplyAmount)).div(poolAumUsdMax);
|
676
|
-
}
|
677
|
-
return {
|
678
|
-
lpAmountOut: lpTokenOut,
|
679
|
-
fee: fee
|
680
|
-
};
|
681
|
-
};
|
682
|
-
this.getRemoveLiquidityAmountAndFeeSync = function (lpAmountIn, poolAccount, outputTokenPrice, outputTokenEmaPrice, outputTokenCustodyAccount, lpTokenSupply, poolAumUsdMax, poolConfig) {
|
683
|
-
if (!outputTokenPrice.exponent.eq(outputTokenEmaPrice.exponent)) {
|
684
|
-
throw new Error("exponent mistach");
|
685
|
-
}
|
686
|
-
var minMaxPrice = _this.getMinAndMaxOraclePriceSync(outputTokenPrice, outputTokenEmaPrice, outputTokenCustodyAccount);
|
687
|
-
var removeAmountUsd = (poolAumUsdMax.mul(lpAmountIn)).div(lpTokenSupply);
|
688
|
-
var removeAmount;
|
689
|
-
var oneOracle = OraclePrice_1.OraclePrice.from({ price: new anchor_1.BN(Math.pow(10, 8)), exponent: new anchor_1.BN(-8), confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
|
690
|
-
if (outputTokenCustodyAccount.isStable && minMaxPrice.min != minMaxPrice.max && minMaxPrice.max.price.lt(oneOracle.price)) {
|
691
|
-
removeAmount = oneOracle.getTokenAmount(removeAmountUsd, outputTokenCustodyAccount.decimals);
|
692
|
-
}
|
693
|
-
else {
|
694
|
-
removeAmount = minMaxPrice.max.getTokenAmount(removeAmountUsd, outputTokenCustodyAccount.decimals);
|
695
|
-
}
|
696
|
-
var fee = _this.getFeeHelper(types_1.FeesAction.RemoveLiquidity, constants_1.BN_ZERO, removeAmount, outputTokenCustodyAccount, minMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
|
697
|
-
return {
|
698
|
-
tokenAmountOut: removeAmount.sub(fee),
|
699
|
-
fee: fee,
|
700
|
-
};
|
701
|
-
};
|
702
|
-
this.getFeeHelper = function (action, amountAdd, amountRemove, inputTokenCustodyAccount, maxOraclePrice, poolAumUsdMax, poolAccount, poolConfig) {
|
703
|
-
var fees;
|
704
|
-
switch (action) {
|
705
|
-
case types_1.FeesAction.AddLiquidity:
|
706
|
-
fees = inputTokenCustodyAccount.fees.addLiquidity;
|
707
|
-
break;
|
708
|
-
case types_1.FeesAction.RemoveLiquidity:
|
709
|
-
fees = inputTokenCustodyAccount.fees.removeLiquidity;
|
710
|
-
break;
|
711
|
-
case types_1.FeesAction.SwapIn:
|
712
|
-
fees = inputTokenCustodyAccount.fees.swapIn;
|
713
|
-
break;
|
714
|
-
case types_1.FeesAction.SwapOut:
|
715
|
-
fees = inputTokenCustodyAccount.fees.swapOut;
|
716
|
-
break;
|
717
|
-
}
|
718
|
-
if (inputTokenCustodyAccount.fees.mode == types_1.FeesMode.Fixed) {
|
719
|
-
return { feeBps: fees.minFee, feeAmount: anchor_1.BN.max(amountAdd, amountRemove).mul(fees.minFee).div(new anchor_1.BN(constants_1.RATE_POWER)) };
|
720
|
-
}
|
721
|
-
var newRatio = _this.getNewRatioHelper(amountAdd, amountRemove, inputTokenCustodyAccount, maxOraclePrice, poolAumUsdMax);
|
722
|
-
var index = poolAccount.custodies.findIndex(function (c) { return c.equals(inputTokenCustodyAccount.publicKey); });
|
723
|
-
var ratios = poolAccount.ratios[index];
|
724
|
-
var fee = constants_1.BN_ZERO;
|
725
|
-
if (action == types_1.FeesAction.AddLiquidity || action == types_1.FeesAction.SwapIn || action == types_1.FeesAction.StableSwapIn) {
|
726
|
-
if (newRatio.lte(ratios.min)) {
|
727
|
-
fee = fees.minFee;
|
728
|
-
}
|
729
|
-
else if (newRatio.lte(ratios.target) && ratios.target.gt(ratios.min)) {
|
730
|
-
fee = fees.minFee.add((newRatio.sub(ratios.min)).mul(fees.targetFee.sub(fees.minFee)).div(ratios.target.sub(ratios.min)));
|
731
|
-
}
|
732
|
-
else if (newRatio.lte(ratios.max) && ratios.max.gt(ratios.target)) {
|
733
|
-
fee = fees.targetFee.add((newRatio.sub(ratios.target)).mul(fees.maxFee.sub(fees.targetFee)).div(ratios.max.sub(ratios.target)));
|
511
|
+
else if (newRatio.lte(ratios.max) && ratios.max.gt(ratios.target)) {
|
512
|
+
fee = fees.targetFee.add((newRatio.sub(ratios.target)).mul(fees.maxFee.sub(fees.targetFee)).div(ratios.max.sub(ratios.target)));
|
734
513
|
}
|
735
514
|
else {
|
736
515
|
fee = fees.maxFee;
|
@@ -1177,7 +956,6 @@ var PerpetualsClient = (function () {
|
|
1177
956
|
var finalCollateralAmount = constants_1.BN_ZERO;
|
1178
957
|
if (inputTokenCustodyAccount.publicKey.equals(collateralTokenCustodyAccount.publicKey)) {
|
1179
958
|
finalCollateralAmount = amountIn;
|
1180
|
-
console.log("no swap needed");
|
1181
959
|
}
|
1182
960
|
else {
|
1183
961
|
var swapAmountOut = _this.getSwapAmountAndFeesSync(amountIn, constants_1.BN_ZERO, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, swapPoolAumUsdMax, poolConfigSwap).minAmountOut;
|
@@ -1232,7 +1010,6 @@ var PerpetualsClient = (function () {
|
|
1232
1010
|
var collateralAmountWithFee = (0, utils_1.uiDecimalsToNative)(collateralAmtWithFeeUi.toFixed(collateralTokenCustodyAccount.decimals, bignumber_js_1.default.ROUND_DOWN), collateralTokenCustodyAccount.decimals);
|
1233
1011
|
var collateralInInputToken;
|
1234
1012
|
if (inputTokenCustodyAccount.publicKey.equals(collateralTokenCustodyAccount.publicKey)) {
|
1235
|
-
console.log("no swap needed");
|
1236
1013
|
collateralInInputToken = collateralAmountWithFee;
|
1237
1014
|
}
|
1238
1015
|
else {
|
@@ -2039,6 +1816,62 @@ var PerpetualsClient = (function () {
|
|
2039
1816
|
}
|
2040
1817
|
return finalIndexPriceAtT1.toString();
|
2041
1818
|
};
|
1819
|
+
this.getUserClaimableRevenueAmount = function (POOL_CONFIG_1, userPublicKey_1) {
|
1820
|
+
var args_1 = [];
|
1821
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
1822
|
+
args_1[_i - 2] = arguments[_i];
|
1823
|
+
}
|
1824
|
+
return __awaiter(_this, __spreadArray([POOL_CONFIG_1, userPublicKey_1], args_1, true), void 0, function (POOL_CONFIG, userPublicKey, enableDebuglogs) {
|
1825
|
+
var fafTokenVaultPk, fafTokenVaultAccountInfo, fafTokenVaultAccount, fafTokenVault, tokenStakeAccount, accountInfo, fafStakeData, tokenStakeFafAccount, activeStakeAmount, revenuePerFafStaked, revenueWatermark, revenueSnapshot, unclaimedRevenue, revenueAmount;
|
1826
|
+
var _a, _b, _c, _d;
|
1827
|
+
if (enableDebuglogs === void 0) { enableDebuglogs = false; }
|
1828
|
+
return __generator(this, function (_e) {
|
1829
|
+
switch (_e.label) {
|
1830
|
+
case 0:
|
1831
|
+
fafTokenVaultPk = POOL_CONFIG.tokenVault;
|
1832
|
+
return [4, this.provider.connection.getAccountInfo(fafTokenVaultPk)];
|
1833
|
+
case 1:
|
1834
|
+
fafTokenVaultAccountInfo = _e.sent();
|
1835
|
+
fafTokenVaultAccount = null;
|
1836
|
+
if (fafTokenVaultAccountInfo) {
|
1837
|
+
fafTokenVault = this.program.coder.accounts.decode('tokenVault', fafTokenVaultAccountInfo.data);
|
1838
|
+
fafTokenVaultAccount = TokenVaultAccount_1.TokenVaultAccount.from(fafTokenVaultPk, fafTokenVault);
|
1839
|
+
}
|
1840
|
+
else {
|
1841
|
+
console.log('No account info found for fafTokenVaultPk:', fafTokenVaultPk.toBase58());
|
1842
|
+
throw new Error('No account info found for fafTokenVaultPk');
|
1843
|
+
}
|
1844
|
+
if (!fafTokenVaultAccount) {
|
1845
|
+
return [2, constants_1.BN_ZERO];
|
1846
|
+
}
|
1847
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('token_stake'), userPublicKey.toBuffer()], POOL_CONFIG.programId)[0];
|
1848
|
+
return [4, this.provider.connection.getAccountInfo(tokenStakeAccount)];
|
1849
|
+
case 2:
|
1850
|
+
accountInfo = _e.sent();
|
1851
|
+
if (accountInfo) {
|
1852
|
+
fafStakeData = this.program.coder.accounts.decode('tokenStake', accountInfo.data);
|
1853
|
+
tokenStakeFafAccount = TokenStakeAccount_1.TokenStakeAccount.from(fafStakeData);
|
1854
|
+
activeStakeAmount = (_a = tokenStakeFafAccount === null || tokenStakeFafAccount === void 0 ? void 0 : tokenStakeFafAccount.activeStakeAmount) !== null && _a !== void 0 ? _a : constants_1.BN_ZERO;
|
1855
|
+
revenuePerFafStaked = (_b = fafTokenVaultAccount === null || fafTokenVaultAccount === void 0 ? void 0 : fafTokenVaultAccount.revenuePerFafStaked) !== null && _b !== void 0 ? _b : constants_1.BN_ZERO;
|
1856
|
+
revenueWatermark = activeStakeAmount
|
1857
|
+
.mul(revenuePerFafStaked)
|
1858
|
+
.div(new anchor_1.BN(10).pow(new anchor_1.BN(constants_1.FAF_DECIMALS)));
|
1859
|
+
revenueSnapshot = (_c = tokenStakeFafAccount === null || tokenStakeFafAccount === void 0 ? void 0 : tokenStakeFafAccount.revenueSnapshot) !== null && _c !== void 0 ? _c : constants_1.BN_ZERO;
|
1860
|
+
unclaimedRevenue = (_d = tokenStakeFafAccount === null || tokenStakeFafAccount === void 0 ? void 0 : tokenStakeFafAccount.unclaimedRevenueAmount) !== null && _d !== void 0 ? _d : constants_1.BN_ZERO;
|
1861
|
+
revenueAmount = revenueWatermark.sub(revenueSnapshot).add(unclaimedRevenue);
|
1862
|
+
if (revenueAmount.lt(constants_1.BN_ZERO)) {
|
1863
|
+
revenueAmount = constants_1.BN_ZERO;
|
1864
|
+
}
|
1865
|
+
return [2, revenueAmount];
|
1866
|
+
}
|
1867
|
+
else {
|
1868
|
+
return [2, constants_1.BN_ZERO];
|
1869
|
+
}
|
1870
|
+
return [2];
|
1871
|
+
}
|
1872
|
+
});
|
1873
|
+
});
|
1874
|
+
};
|
2042
1875
|
this.getStakedLpTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
2043
1876
|
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, result, index, res;
|
2044
1877
|
var _d;
|
@@ -2784,7 +2617,7 @@ var PerpetualsClient = (function () {
|
|
2784
2617
|
args_1[_i - 6] = arguments[_i];
|
2785
2618
|
}
|
2786
2619
|
return __awaiter(_this, __spreadArray([marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
2787
|
-
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns,
|
2620
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
|
2788
2621
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2789
2622
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2790
2623
|
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
@@ -2876,9 +2709,9 @@ var PerpetualsClient = (function () {
|
|
2876
2709
|
}
|
2877
2710
|
return [3, 8];
|
2878
2711
|
case 7:
|
2879
|
-
|
2880
|
-
console.error("perpclient closePosition error:",
|
2881
|
-
throw
|
2712
|
+
error_1 = _b.sent();
|
2713
|
+
console.error("perpclient closePosition error:", error_1);
|
2714
|
+
throw error_1;
|
2882
2715
|
case 8: return [2, {
|
2883
2716
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
2884
2717
|
additionalSigners: additionalSigners
|
@@ -3679,7 +3512,7 @@ var PerpetualsClient = (function () {
|
|
3679
3512
|
args_1[_i - 6] = arguments[_i];
|
3680
3513
|
}
|
3681
3514
|
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) {
|
3682
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns,
|
3515
|
+
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_2;
|
3683
3516
|
if (createUserATA === void 0) { createUserATA = true; }
|
3684
3517
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3685
3518
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
@@ -3772,9 +3605,9 @@ var PerpetualsClient = (function () {
|
|
3772
3605
|
}
|
3773
3606
|
return [3, 8];
|
3774
3607
|
case 7:
|
3775
|
-
|
3776
|
-
console.error("perpclient removeCollateral error:",
|
3777
|
-
throw
|
3608
|
+
error_2 = _b.sent();
|
3609
|
+
console.error("perpclient removeCollateral error:", error_2);
|
3610
|
+
throw error_2;
|
3778
3611
|
case 8: return [2, {
|
3779
3612
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3780
3613
|
additionalSigners: additionalSigners
|
@@ -4613,123 +4446,18 @@ var PerpetualsClient = (function () {
|
|
4613
4446
|
}
|
4614
4447
|
});
|
4615
4448
|
}); };
|
4616
|
-
this.
|
4617
|
-
var
|
4449
|
+
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4450
|
+
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_13;
|
4618
4451
|
return __generator(this, function (_a) {
|
4619
4452
|
switch (_a.label) {
|
4620
4453
|
case 0:
|
4621
|
-
publicKey = this.provider.wallet.publicKey;
|
4622
4454
|
preInstructions = [];
|
4623
4455
|
instructions = [];
|
4624
4456
|
postInstructions = [];
|
4625
4457
|
additionalSigners = [];
|
4626
4458
|
_a.label = 1;
|
4627
4459
|
case 1:
|
4628
|
-
_a.trys.push([1,
|
4629
|
-
lpTokenMint = poolConfig.stakedLpTokenMint;
|
4630
|
-
stakedLpTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
4631
|
-
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
4632
|
-
return [4, this.program.methods
|
4633
|
-
.initStaking({
|
4634
|
-
stakingFeeShareBps: stakingFeeShareBps
|
4635
|
-
})
|
4636
|
-
.accounts({
|
4637
|
-
admin: publicKey,
|
4638
|
-
multisig: this.multisig.publicKey,
|
4639
|
-
transferAuthority: poolConfig.transferAuthority,
|
4640
|
-
perpetuals: this.perpetuals.publicKey,
|
4641
|
-
pool: poolConfig.poolAddress,
|
4642
|
-
custody: rewardCustodyConfig.custodyAccount,
|
4643
|
-
lpTokenMint: lpTokenMint,
|
4644
|
-
stakedLpTokenAccount: stakedLpTokenAccount,
|
4645
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
4646
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4647
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
4648
|
-
})
|
4649
|
-
.instruction()];
|
4650
|
-
case 2:
|
4651
|
-
initStakeInstruction = _a.sent();
|
4652
|
-
instructions.push(initStakeInstruction);
|
4653
|
-
return [3, 4];
|
4654
|
-
case 3:
|
4655
|
-
err_13 = _a.sent();
|
4656
|
-
console.log("perpClient InitStaking error:: ", err_13);
|
4657
|
-
throw err_13;
|
4658
|
-
case 4: return [2, {
|
4659
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4660
|
-
additionalSigners: additionalSigners
|
4661
|
-
}];
|
4662
|
-
}
|
4663
|
-
});
|
4664
|
-
}); };
|
4665
|
-
this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4666
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_14;
|
4667
|
-
return __generator(this, function (_a) {
|
4668
|
-
switch (_a.label) {
|
4669
|
-
case 0:
|
4670
|
-
publicKey = this.provider.wallet.publicKey;
|
4671
|
-
preInstructions = [];
|
4672
|
-
instructions = [];
|
4673
|
-
postInstructions = [];
|
4674
|
-
additionalSigners = [];
|
4675
|
-
_a.label = 1;
|
4676
|
-
case 1:
|
4677
|
-
_a.trys.push([1, 3, , 4]);
|
4678
|
-
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
4679
|
-
compoundingTokenMint = this.getPoolCompoundingTokenKey(poolConfig.poolName);
|
4680
|
-
compoundingVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("compounding_token_account"), poolConfig.poolAddress.toBuffer(), poolConfig.stakedLpTokenMint.toBuffer()], this.programId)[0];
|
4681
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), compoundingTokenMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
4682
|
-
return [4, this.program.methods
|
4683
|
-
.initCompounding({
|
4684
|
-
feeShareBps: feeShareBps,
|
4685
|
-
metadataTitle: metadataTitle,
|
4686
|
-
metadataSymbol: metadataSymbol,
|
4687
|
-
metadataUri: metadataUri
|
4688
|
-
})
|
4689
|
-
.accounts({
|
4690
|
-
admin: publicKey,
|
4691
|
-
multisig: this.multisig.publicKey,
|
4692
|
-
transferAuthority: poolConfig.transferAuthority,
|
4693
|
-
perpetuals: this.perpetuals.publicKey,
|
4694
|
-
pool: poolConfig.poolAddress,
|
4695
|
-
custody: rewardCustodyConfig.custodyAccount,
|
4696
|
-
lpTokenMint: poolConfig.stakedLpTokenMint,
|
4697
|
-
compoundingVault: compoundingVault,
|
4698
|
-
compoundingTokenMint: compoundingTokenMint,
|
4699
|
-
metadataAccount: metadataAccount,
|
4700
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
4701
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4702
|
-
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
4703
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
4704
|
-
})
|
4705
|
-
.instruction()];
|
4706
|
-
case 2:
|
4707
|
-
initCompoundingInstruction = _a.sent();
|
4708
|
-
instructions.push(initCompoundingInstruction);
|
4709
|
-
return [3, 4];
|
4710
|
-
case 3:
|
4711
|
-
err_14 = _a.sent();
|
4712
|
-
console.log("perpClient initCompounding error:: ", err_14);
|
4713
|
-
throw err_14;
|
4714
|
-
case 4: return [2, {
|
4715
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4716
|
-
additionalSigners: additionalSigners
|
4717
|
-
}];
|
4718
|
-
}
|
4719
|
-
});
|
4720
|
-
}); };
|
4721
|
-
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4722
|
-
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_15;
|
4723
|
-
return __generator(this, function (_a) {
|
4724
|
-
switch (_a.label) {
|
4725
|
-
case 0:
|
4726
|
-
preInstructions = [];
|
4727
|
-
instructions = [];
|
4728
|
-
postInstructions = [];
|
4729
|
-
additionalSigners = [];
|
4730
|
-
_a.label = 1;
|
4731
|
-
case 1:
|
4732
|
-
_a.trys.push([1, 4, , 5]);
|
4460
|
+
_a.trys.push([1, 4, , 5]);
|
4733
4461
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
4734
4462
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
4735
4463
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), owner.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
@@ -4760,9 +4488,9 @@ var PerpetualsClient = (function () {
|
|
4760
4488
|
instructions.push(depositStakeInstruction);
|
4761
4489
|
return [3, 5];
|
4762
4490
|
case 4:
|
4763
|
-
|
4764
|
-
console.log("perpClient depositStaking error:: ",
|
4765
|
-
throw
|
4491
|
+
err_13 = _a.sent();
|
4492
|
+
console.log("perpClient depositStaking error:: ", err_13);
|
4493
|
+
throw err_13;
|
4766
4494
|
case 5: return [2, {
|
4767
4495
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4768
4496
|
additionalSigners: additionalSigners
|
@@ -4771,7 +4499,7 @@ var PerpetualsClient = (function () {
|
|
4771
4499
|
});
|
4772
4500
|
}); };
|
4773
4501
|
this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4774
|
-
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction,
|
4502
|
+
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_14;
|
4775
4503
|
return __generator(this, function (_c) {
|
4776
4504
|
switch (_c.label) {
|
4777
4505
|
case 0:
|
@@ -4818,9 +4546,9 @@ var PerpetualsClient = (function () {
|
|
4818
4546
|
refreshStakeInstruction = _c.sent();
|
4819
4547
|
return [2, refreshStakeInstruction];
|
4820
4548
|
case 2:
|
4821
|
-
|
4822
|
-
console.log("perpClient refreshStaking error:: ",
|
4823
|
-
throw
|
4549
|
+
err_14 = _c.sent();
|
4550
|
+
console.log("perpClient refreshStaking error:: ", err_14);
|
4551
|
+
throw err_14;
|
4824
4552
|
case 3: return [2];
|
4825
4553
|
}
|
4826
4554
|
});
|
@@ -4831,7 +4559,7 @@ var PerpetualsClient = (function () {
|
|
4831
4559
|
args_1[_i - 3] = arguments[_i];
|
4832
4560
|
}
|
4833
4561
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4834
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction,
|
4562
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_15;
|
4835
4563
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4836
4564
|
return __generator(this, function (_c) {
|
4837
4565
|
switch (_c.label) {
|
@@ -4879,9 +4607,9 @@ var PerpetualsClient = (function () {
|
|
4879
4607
|
refreshStakeInstruction = _c.sent();
|
4880
4608
|
return [2, refreshStakeInstruction];
|
4881
4609
|
case 2:
|
4882
|
-
|
4883
|
-
console.log("perpClient refreshStaking error:: ",
|
4884
|
-
throw
|
4610
|
+
err_15 = _c.sent();
|
4611
|
+
console.log("perpClient refreshStaking error:: ", err_15);
|
4612
|
+
throw err_15;
|
4885
4613
|
case 3: return [2];
|
4886
4614
|
}
|
4887
4615
|
});
|
@@ -4893,7 +4621,7 @@ var PerpetualsClient = (function () {
|
|
4893
4621
|
args_1[_i - 3] = arguments[_i];
|
4894
4622
|
}
|
4895
4623
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4896
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction,
|
4624
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_16;
|
4897
4625
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4898
4626
|
return __generator(this, function (_b) {
|
4899
4627
|
switch (_b.label) {
|
@@ -4945,9 +4673,9 @@ var PerpetualsClient = (function () {
|
|
4945
4673
|
instructions.push(unstakeInstantInstruction);
|
4946
4674
|
return [3, 6];
|
4947
4675
|
case 5:
|
4948
|
-
|
4949
|
-
console.log("perpClient unstakeInstant error:: ",
|
4950
|
-
throw
|
4676
|
+
err_16 = _b.sent();
|
4677
|
+
console.log("perpClient unstakeInstant error:: ", err_16);
|
4678
|
+
throw err_16;
|
4951
4679
|
case 6: return [2, {
|
4952
4680
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4953
4681
|
additionalSigners: additionalSigners
|
@@ -4957,7 +4685,7 @@ var PerpetualsClient = (function () {
|
|
4957
4685
|
});
|
4958
4686
|
};
|
4959
4687
|
this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4960
|
-
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction,
|
4688
|
+
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_17;
|
4961
4689
|
return __generator(this, function (_c) {
|
4962
4690
|
switch (_c.label) {
|
4963
4691
|
case 0:
|
@@ -5001,15 +4729,15 @@ var PerpetualsClient = (function () {
|
|
5001
4729
|
refreshStakeInstruction = _c.sent();
|
5002
4730
|
return [2, refreshStakeInstruction];
|
5003
4731
|
case 2:
|
5004
|
-
|
5005
|
-
console.log("perpClient refreshStaking error:: ",
|
5006
|
-
throw
|
4732
|
+
err_17 = _c.sent();
|
4733
|
+
console.log("perpClient refreshStaking error:: ", err_17);
|
4734
|
+
throw err_17;
|
5007
4735
|
case 3: return [2];
|
5008
4736
|
}
|
5009
4737
|
});
|
5010
4738
|
}); };
|
5011
4739
|
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5012
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction,
|
4740
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_18;
|
5013
4741
|
return __generator(this, function (_a) {
|
5014
4742
|
switch (_a.label) {
|
5015
4743
|
case 0:
|
@@ -5043,9 +4771,9 @@ var PerpetualsClient = (function () {
|
|
5043
4771
|
instructions.push(unstakeRequestInstruction);
|
5044
4772
|
return [3, 4];
|
5045
4773
|
case 3:
|
5046
|
-
|
5047
|
-
console.log("perpClient unstakeRequest error:: ",
|
5048
|
-
throw
|
4774
|
+
err_18 = _a.sent();
|
4775
|
+
console.log("perpClient unstakeRequest error:: ", err_18);
|
4776
|
+
throw err_18;
|
5049
4777
|
case 4: return [2, {
|
5050
4778
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5051
4779
|
additionalSigners: additionalSigners
|
@@ -5059,7 +4787,7 @@ var PerpetualsClient = (function () {
|
|
5059
4787
|
args_1[_i - 1] = arguments[_i];
|
5060
4788
|
}
|
5061
4789
|
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
5062
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction,
|
4790
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_19;
|
5063
4791
|
if (pendingActivation === void 0) { pendingActivation = true; }
|
5064
4792
|
if (deactivated === void 0) { deactivated = true; }
|
5065
4793
|
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
@@ -5114,9 +4842,9 @@ var PerpetualsClient = (function () {
|
|
5114
4842
|
instructions.push(withdrawStakeInstruction);
|
5115
4843
|
return [3, 6];
|
5116
4844
|
case 5:
|
5117
|
-
|
5118
|
-
console.log("perpClient withdrawStake error:: ",
|
5119
|
-
throw
|
4845
|
+
err_19 = _b.sent();
|
4846
|
+
console.log("perpClient withdrawStake error:: ", err_19);
|
4847
|
+
throw err_19;
|
5120
4848
|
case 6: return [2, {
|
5121
4849
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5122
4850
|
additionalSigners: additionalSigners
|
@@ -5131,7 +4859,7 @@ var PerpetualsClient = (function () {
|
|
5131
4859
|
args_1[_i - 3] = arguments[_i];
|
5132
4860
|
}
|
5133
4861
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
5134
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction,
|
4862
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_20;
|
5135
4863
|
if (createUserATA === void 0) { createUserATA = true; }
|
5136
4864
|
return __generator(this, function (_b) {
|
5137
4865
|
switch (_b.label) {
|
@@ -5191,9 +4919,9 @@ var PerpetualsClient = (function () {
|
|
5191
4919
|
instructions.push(withdrawStakeInstruction);
|
5192
4920
|
return [3, 6];
|
5193
4921
|
case 5:
|
5194
|
-
|
5195
|
-
console.log("perpClient withdrawStake error:: ",
|
5196
|
-
throw
|
4922
|
+
err_20 = _b.sent();
|
4923
|
+
console.log("perpClient withdrawStake error:: ", err_20);
|
4924
|
+
throw err_20;
|
5197
4925
|
case 6: return [2, {
|
5198
4926
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5199
4927
|
additionalSigners: additionalSigners
|
@@ -5202,190 +4930,467 @@ var PerpetualsClient = (function () {
|
|
5202
4930
|
});
|
5203
4931
|
});
|
5204
4932
|
};
|
5205
|
-
this.
|
5206
|
-
var
|
5207
|
-
|
5208
|
-
|
5209
|
-
|
5210
|
-
|
5211
|
-
|
5212
|
-
|
5213
|
-
|
5214
|
-
|
5215
|
-
|
5216
|
-
|
5217
|
-
|
5218
|
-
|
5219
|
-
|
5220
|
-
|
5221
|
-
|
5222
|
-
|
5223
|
-
|
5224
|
-
|
5225
|
-
|
5226
|
-
|
5227
|
-
|
5228
|
-
|
5229
|
-
|
5230
|
-
|
5231
|
-
|
5232
|
-
|
5233
|
-
|
5234
|
-
|
5235
|
-
|
5236
|
-
|
5237
|
-
|
5238
|
-
|
5239
|
-
|
5240
|
-
|
5241
|
-
|
5242
|
-
|
5243
|
-
|
5244
|
-
|
5245
|
-
|
5246
|
-
|
5247
|
-
|
5248
|
-
|
5249
|
-
|
5250
|
-
|
5251
|
-
|
5252
|
-
|
5253
|
-
|
5254
|
-
|
5255
|
-
|
5256
|
-
|
5257
|
-
|
5258
|
-
|
5259
|
-
|
5260
|
-
|
5261
|
-
|
5262
|
-
|
5263
|
-
|
5264
|
-
|
5265
|
-
|
5266
|
-
|
5267
|
-
|
5268
|
-
|
5269
|
-
|
5270
|
-
|
5271
|
-
|
5272
|
-
|
5273
|
-
|
5274
|
-
|
5275
|
-
|
5276
|
-
|
5277
|
-
|
5278
|
-
|
5279
|
-
|
5280
|
-
|
5281
|
-
|
5282
|
-
|
5283
|
-
|
5284
|
-
|
5285
|
-
|
5286
|
-
|
5287
|
-
|
5288
|
-
|
5289
|
-
|
5290
|
-
|
5291
|
-
|
5292
|
-
|
5293
|
-
|
5294
|
-
|
5295
|
-
|
5296
|
-
|
5297
|
-
|
5298
|
-
|
5299
|
-
|
5300
|
-
|
5301
|
-
|
5302
|
-
|
5303
|
-
|
5304
|
-
|
5305
|
-
|
5306
|
-
|
5307
|
-
|
5308
|
-
|
5309
|
-
|
5310
|
-
|
5311
|
-
|
5312
|
-
|
5313
|
-
|
5314
|
-
|
5315
|
-
|
5316
|
-
|
5317
|
-
|
5318
|
-
|
5319
|
-
|
5320
|
-
|
5321
|
-
|
5322
|
-
|
5323
|
-
|
5324
|
-
|
5325
|
-
|
5326
|
-
|
5327
|
-
|
5328
|
-
|
5329
|
-
|
5330
|
-
|
5331
|
-
|
5332
|
-
|
5333
|
-
|
5334
|
-
|
5335
|
-
|
5336
|
-
|
5337
|
-
|
5338
|
-
|
5339
|
-
|
5340
|
-
|
5341
|
-
|
5342
|
-
|
5343
|
-
|
5344
|
-
|
5345
|
-
}
|
5346
|
-
});
|
5347
|
-
}
|
5348
|
-
this.
|
5349
|
-
var
|
5350
|
-
|
5351
|
-
|
5352
|
-
|
5353
|
-
|
5354
|
-
|
5355
|
-
|
5356
|
-
|
5357
|
-
|
5358
|
-
|
5359
|
-
|
5360
|
-
|
5361
|
-
|
5362
|
-
|
5363
|
-
|
5364
|
-
|
5365
|
-
|
5366
|
-
|
5367
|
-
|
5368
|
-
|
5369
|
-
|
5370
|
-
|
5371
|
-
|
5372
|
-
|
5373
|
-
|
5374
|
-
|
5375
|
-
|
4933
|
+
this.addCompoundingLiquidity = function (amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
|
4934
|
+
var args_1 = [];
|
4935
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
4936
|
+
args_1[_i - 5] = arguments[_i];
|
4937
|
+
}
|
4938
|
+
return __awaiter(_this, __spreadArray([amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
4939
|
+
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity, err_21;
|
4940
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4941
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4942
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4943
|
+
return __generator(this, function (_f) {
|
4944
|
+
switch (_f.label) {
|
4945
|
+
case 0:
|
4946
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4947
|
+
preInstructions = [];
|
4948
|
+
instructions = [];
|
4949
|
+
additionalSigners = [];
|
4950
|
+
postInstructions = [];
|
4951
|
+
rewardCustody = poolConfig.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
4952
|
+
inCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inTokenSymbol).mintKey); });
|
4953
|
+
lpTokenMint = poolConfig.stakedLpTokenMint;
|
4954
|
+
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
4955
|
+
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4956
|
+
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
4957
|
+
fundingAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inCustodyConfig.mintKey, publicKey, true);
|
4958
|
+
custodyAccountMetas = [];
|
4959
|
+
custodyOracleAccountMetas = [];
|
4960
|
+
markets = [];
|
4961
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4962
|
+
custody = _b[_a];
|
4963
|
+
custodyAccountMetas.push({
|
4964
|
+
pubkey: custody.custodyAccount,
|
4965
|
+
isSigner: false,
|
4966
|
+
isWritable: false,
|
4967
|
+
});
|
4968
|
+
custodyOracleAccountMetas.push({
|
4969
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
4970
|
+
isSigner: false,
|
4971
|
+
isWritable: false,
|
4972
|
+
});
|
4973
|
+
}
|
4974
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
4975
|
+
market = _d[_c];
|
4976
|
+
markets.push({
|
4977
|
+
pubkey: market.marketAccount,
|
4978
|
+
isSigner: false,
|
4979
|
+
isWritable: false,
|
4980
|
+
});
|
4981
|
+
}
|
4982
|
+
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4983
|
+
case 1:
|
4984
|
+
if (!(_f.sent())) {
|
4985
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4986
|
+
}
|
4987
|
+
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
4988
|
+
case 2:
|
4989
|
+
if (!(_f.sent())) {
|
4990
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
4991
|
+
}
|
4992
|
+
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
4993
|
+
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
4994
|
+
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
4995
|
+
if (!!skipBalanceChecks) return [3, 4];
|
4996
|
+
_e = anchor_1.BN.bind;
|
4997
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
4998
|
+
case 3:
|
4999
|
+
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
5000
|
+
if (unWrappedSolBalance.lt(lamports)) {
|
5001
|
+
throw "Insufficient SOL Funds";
|
5002
|
+
}
|
5003
|
+
_f.label = 4;
|
5004
|
+
case 4:
|
5005
|
+
if (!ephemeralSignerPubkey) {
|
5006
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
5007
|
+
additionalSigners.push(wrappedSolAccount);
|
5008
|
+
}
|
5009
|
+
preInstructions = [
|
5010
|
+
web3_js_1.SystemProgram.createAccount({
|
5011
|
+
fromPubkey: publicKey,
|
5012
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
5013
|
+
lamports: lamports.toNumber(),
|
5014
|
+
space: 165,
|
5015
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
5016
|
+
}),
|
5017
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
5018
|
+
];
|
5019
|
+
postInstructions = [
|
5020
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
5021
|
+
];
|
5022
|
+
return [3, 7];
|
5023
|
+
case 5:
|
5024
|
+
if (!!skipBalanceChecks) return [3, 7];
|
5025
|
+
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
5026
|
+
case 6:
|
5027
|
+
if (!(_f.sent())) {
|
5028
|
+
throw "Insufficient Funds , token Account doesn't exist";
|
5029
|
+
}
|
5030
|
+
_f.label = 7;
|
5031
|
+
case 7:
|
5032
|
+
_f.trys.push([7, 9, , 10]);
|
5033
|
+
return [4, this.program.methods
|
5034
|
+
.addCompoundingLiquidity({
|
5035
|
+
amountIn: amountIn,
|
5036
|
+
minCompoundingAmountOut: minCompoundingAmountOut
|
5037
|
+
})
|
5038
|
+
.accounts({
|
5039
|
+
owner: publicKey,
|
5040
|
+
fundingAccount: inTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : fundingAccount,
|
5041
|
+
compoundingTokenAccount: compoundingTokenAccount,
|
5042
|
+
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
5043
|
+
transferAuthority: poolConfig.transferAuthority,
|
5044
|
+
perpetuals: poolConfig.perpetuals,
|
5045
|
+
pool: poolConfig.poolAddress,
|
5046
|
+
inCustody: inCustodyConfig.custodyAccount,
|
5047
|
+
inCustodyOracleAccount: this.useExtOracleAccount ? inCustodyConfig.extOracleAccount : inCustodyConfig.intOracleAccount,
|
5048
|
+
inCustodyTokenAccount: inCustodyConfig.tokenAccount,
|
5049
|
+
rewardCustody: rewardCustody.custodyAccount,
|
5050
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
5051
|
+
lpTokenMint: lpTokenMint,
|
5052
|
+
compoundingTokenMint: compoundingTokenMint,
|
5053
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5054
|
+
eventAuthority: this.eventAuthority.publicKey,
|
5055
|
+
program: this.program.programId,
|
5056
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5057
|
+
})
|
5058
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5059
|
+
.instruction()];
|
5060
|
+
case 8:
|
5061
|
+
addCompoundingLiquidity = _f.sent();
|
5062
|
+
instructions.push(addCompoundingLiquidity);
|
5063
|
+
return [3, 10];
|
5064
|
+
case 9:
|
5065
|
+
err_21 = _f.sent();
|
5066
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_21);
|
5067
|
+
return [3, 10];
|
5068
|
+
case 10: return [2, {
|
5069
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5070
|
+
additionalSigners: additionalSigners
|
5071
|
+
}];
|
5072
|
+
}
|
5073
|
+
});
|
5074
|
+
});
|
5075
|
+
};
|
5076
|
+
this.removeCompoundingLiquidity = function (compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
|
5077
|
+
var args_1 = [];
|
5078
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
5079
|
+
args_1[_i - 5] = arguments[_i];
|
5080
|
+
}
|
5081
|
+
return __awaiter(_this, __spreadArray([compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
|
5082
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity, err_22;
|
5083
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5084
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5085
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
5086
|
+
return __generator(this, function (_f) {
|
5087
|
+
switch (_f.label) {
|
5088
|
+
case 0:
|
5089
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
5090
|
+
preInstructions = [];
|
5091
|
+
instructions = [];
|
5092
|
+
postInstructions = [];
|
5093
|
+
additionalSigners = [];
|
5094
|
+
rewardCustody = poolConfig.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
5095
|
+
outCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(outTokenSymbol).mintKey); });
|
5096
|
+
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5097
|
+
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
5098
|
+
if (!(outCustodyConfig.symbol == 'SOL')) return [3, 1];
|
5099
|
+
lamports = this.minimumBalanceForRentExemptAccountLamports;
|
5100
|
+
if (!ephemeralSignerPubkey) {
|
5101
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
5102
|
+
additionalSigners.push(wrappedSolAccount);
|
5103
|
+
}
|
5104
|
+
preInstructions = [
|
5105
|
+
web3_js_1.SystemProgram.createAccount({
|
5106
|
+
fromPubkey: publicKey,
|
5107
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
5108
|
+
lamports: lamports,
|
5109
|
+
space: 165,
|
5110
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
5111
|
+
}),
|
5112
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
5113
|
+
];
|
5114
|
+
postInstructions = [
|
5115
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
5116
|
+
];
|
5117
|
+
return [3, 4];
|
5118
|
+
case 1:
|
5119
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(outCustodyConfig.mintKey, publicKey, true);
|
5120
|
+
_a = createUserATA;
|
5121
|
+
if (!_a) return [3, 3];
|
5122
|
+
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
5123
|
+
case 2:
|
5124
|
+
_a = !(_f.sent());
|
5125
|
+
_f.label = 3;
|
5126
|
+
case 3:
|
5127
|
+
if (_a) {
|
5128
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
5129
|
+
}
|
5130
|
+
_f.label = 4;
|
5131
|
+
case 4:
|
5132
|
+
custodyAccountMetas = [];
|
5133
|
+
custodyOracleAccountMetas = [];
|
5134
|
+
markets = [];
|
5135
|
+
for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
|
5136
|
+
custody = _c[_b];
|
5137
|
+
custodyAccountMetas.push({
|
5138
|
+
pubkey: custody.custodyAccount,
|
5139
|
+
isSigner: false,
|
5140
|
+
isWritable: false,
|
5141
|
+
});
|
5142
|
+
custodyOracleAccountMetas.push({
|
5143
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
5144
|
+
isSigner: false,
|
5145
|
+
isWritable: false,
|
5146
|
+
});
|
5147
|
+
}
|
5148
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
5149
|
+
market = _e[_d];
|
5150
|
+
markets.push({
|
5151
|
+
pubkey: market.marketAccount,
|
5152
|
+
isSigner: false,
|
5153
|
+
isWritable: false,
|
5154
|
+
});
|
5155
|
+
}
|
5156
|
+
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
5157
|
+
_f.label = 5;
|
5158
|
+
case 5:
|
5159
|
+
_f.trys.push([5, 7, , 8]);
|
5160
|
+
return [4, this.program.methods
|
5161
|
+
.removeCompoundingLiquidity({
|
5162
|
+
compoundingAmountIn: compoundingAmountIn,
|
5163
|
+
minAmountOut: minAmountOut
|
5164
|
+
})
|
5165
|
+
.accounts({
|
5166
|
+
owner: publicKey,
|
5167
|
+
receivingAccount: outCustodyConfig.symbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
|
5168
|
+
compoundingTokenAccount: compoundingTokenAccount,
|
5169
|
+
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
5170
|
+
transferAuthority: poolConfig.transferAuthority,
|
5171
|
+
perpetuals: poolConfig.perpetuals,
|
5172
|
+
pool: poolConfig.poolAddress,
|
5173
|
+
outCustody: outCustodyConfig.custodyAccount,
|
5174
|
+
outCustodyOracleAccount: this.useExtOracleAccount ? outCustodyConfig.extOracleAccount : outCustodyConfig.intOracleAccount,
|
5175
|
+
outCustodyTokenAccount: outCustodyConfig.tokenAccount,
|
5176
|
+
rewardCustody: rewardCustody.custodyAccount,
|
5177
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
5178
|
+
lpTokenMint: lpTokenMint,
|
5179
|
+
compoundingTokenMint: compoundingTokenMint,
|
5180
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5181
|
+
eventAuthority: this.eventAuthority.publicKey,
|
5182
|
+
program: this.program.programId,
|
5183
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5184
|
+
})
|
5185
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5186
|
+
.instruction()];
|
5187
|
+
case 6:
|
5188
|
+
removeCompoundingLiquidity = _f.sent();
|
5189
|
+
instructions.push(removeCompoundingLiquidity);
|
5190
|
+
return [3, 8];
|
5191
|
+
case 7:
|
5192
|
+
err_22 = _f.sent();
|
5193
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_22);
|
5194
|
+
return [3, 8];
|
5195
|
+
case 8: return [2, {
|
5196
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5197
|
+
additionalSigners: additionalSigners
|
5198
|
+
}];
|
5199
|
+
}
|
5200
|
+
});
|
5201
|
+
});
|
5202
|
+
};
|
5203
|
+
this.migrateStake = function (amount_1, rewardTokenMint_1, poolConfig_1) {
|
5204
|
+
var args_1 = [];
|
5205
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
5206
|
+
args_1[_i - 3] = arguments[_i];
|
5207
|
+
}
|
5208
|
+
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
5209
|
+
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_23;
|
5210
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5211
|
+
return __generator(this, function (_g) {
|
5212
|
+
switch (_g.label) {
|
5213
|
+
case 0:
|
5214
|
+
publicKey = this.provider.wallet.publicKey;
|
5215
|
+
preInstructions = [];
|
5216
|
+
instructions = [];
|
5217
|
+
postInstructions = [];
|
5218
|
+
additionalSigners = [];
|
5219
|
+
rewardCustody = poolConfig.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
5220
|
+
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5221
|
+
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
5222
|
+
compoudingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
5223
|
+
_a = createUserATA;
|
5224
|
+
if (!_a) return [3, 2];
|
5225
|
+
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
5226
|
+
case 1:
|
5227
|
+
_a = !(_g.sent());
|
5228
|
+
_g.label = 2;
|
5229
|
+
case 2:
|
5230
|
+
if (_a) {
|
5231
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
5232
|
+
}
|
5233
|
+
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
5234
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), publicKey.toBuffer()], this.programId)[0];
|
5235
|
+
tokenStakeAccounts = [];
|
5236
|
+
_b = tokenStakeAccount;
|
5237
|
+
if (!_b) return [3, 4];
|
5238
|
+
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
5239
|
+
case 3:
|
5240
|
+
_b = (_g.sent());
|
5241
|
+
_g.label = 4;
|
5242
|
+
case 4:
|
5243
|
+
if (_b) {
|
5244
|
+
tokenStakeAccounts.push({
|
5245
|
+
pubkey: tokenStakeAccount,
|
5246
|
+
isSigner: false,
|
5247
|
+
isWritable: true,
|
5248
|
+
});
|
5249
|
+
}
|
5250
|
+
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
5251
|
+
custodyAccountMetas = [];
|
5252
|
+
custodyOracleAccountMetas = [];
|
5253
|
+
markets = [];
|
5254
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
5255
|
+
custody = _d[_c];
|
5256
|
+
custodyAccountMetas.push({
|
5257
|
+
pubkey: custody.custodyAccount,
|
5258
|
+
isSigner: false,
|
5259
|
+
isWritable: false,
|
5260
|
+
});
|
5261
|
+
custodyOracleAccountMetas.push({
|
5262
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
5263
|
+
isSigner: false,
|
5264
|
+
isWritable: false,
|
5265
|
+
});
|
5266
|
+
}
|
5267
|
+
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
5268
|
+
market = _f[_e];
|
5269
|
+
markets.push({
|
5270
|
+
pubkey: market.marketAccount,
|
5271
|
+
isSigner: false,
|
5272
|
+
isWritable: false,
|
5273
|
+
});
|
5274
|
+
}
|
5275
|
+
_g.label = 5;
|
5276
|
+
case 5:
|
5277
|
+
_g.trys.push([5, 7, , 8]);
|
5278
|
+
return [4, this.program.methods
|
5279
|
+
.migrateStake({
|
5280
|
+
amount: amount
|
5281
|
+
})
|
5282
|
+
.accounts({
|
5283
|
+
owner: publicKey,
|
5284
|
+
compoundingTokenAccount: compoudingTokenAccount,
|
5285
|
+
transferAuthority: poolConfig.transferAuthority,
|
5286
|
+
perpetuals: poolConfig.perpetuals,
|
5287
|
+
pool: poolConfig.poolAddress,
|
5288
|
+
flpStakeAccount: flpStakeAccount,
|
5289
|
+
rewardCustody: rewardCustody.custodyAccount,
|
5290
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
5291
|
+
poolStakedLpVault: poolStakedLpVault,
|
5292
|
+
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
5293
|
+
lpTokenMint: lpTokenMint,
|
5294
|
+
compoundingTokenMint: compoundingTokenMint,
|
5295
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5296
|
+
eventAuthority: this.eventAuthority.publicKey,
|
5297
|
+
program: this.program.programId,
|
5298
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5299
|
+
})
|
5300
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
5301
|
+
.instruction()];
|
5302
|
+
case 6:
|
5303
|
+
migrateStake = _g.sent();
|
5304
|
+
instructions.push(migrateStake);
|
5305
|
+
return [3, 8];
|
5306
|
+
case 7:
|
5307
|
+
err_23 = _g.sent();
|
5308
|
+
console.log("perpClient migrateStake error:: ", err_23);
|
5309
|
+
return [3, 8];
|
5310
|
+
case 8: return [2, {
|
5311
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5312
|
+
additionalSigners: additionalSigners
|
5313
|
+
}];
|
5314
|
+
}
|
5315
|
+
});
|
5316
|
+
});
|
5317
|
+
};
|
5318
|
+
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5319
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_24;
|
5320
|
+
return __generator(this, function (_d) {
|
5321
|
+
switch (_d.label) {
|
5322
|
+
case 0:
|
5323
|
+
publicKey = this.provider.wallet.publicKey;
|
5324
|
+
preInstructions = [];
|
5325
|
+
instructions = [];
|
5326
|
+
postInstructions = [];
|
5327
|
+
additionalSigners = [];
|
5328
|
+
rewardCustody = poolConfig.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
5329
|
+
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5330
|
+
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
5331
|
+
compoudingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
5332
|
+
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
5333
|
+
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
5334
|
+
custodyAccountMetas = [];
|
5335
|
+
custodyOracleAccountMetas = [];
|
5336
|
+
markets = [];
|
5337
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
5338
|
+
custody = _a[_i];
|
5339
|
+
custodyAccountMetas.push({
|
5340
|
+
pubkey: custody.custodyAccount,
|
5341
|
+
isSigner: false,
|
5342
|
+
isWritable: false,
|
5343
|
+
});
|
5344
|
+
custodyOracleAccountMetas.push({
|
5345
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
5346
|
+
isSigner: false,
|
5347
|
+
isWritable: false,
|
5348
|
+
});
|
5349
|
+
}
|
5350
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
5351
|
+
market = _c[_b];
|
5352
|
+
markets.push({
|
5353
|
+
pubkey: market.marketAccount,
|
5354
|
+
isSigner: false,
|
5355
|
+
isWritable: false,
|
5356
|
+
});
|
5357
|
+
}
|
5358
|
+
_d.label = 1;
|
5359
|
+
case 1:
|
5360
|
+
_d.trys.push([1, 3, , 4]);
|
5361
|
+
return [4, this.program.methods
|
5362
|
+
.migrateFlp({
|
5363
|
+
compoundingTokenAmount: amount
|
5364
|
+
})
|
5365
|
+
.accounts({
|
5366
|
+
owner: publicKey,
|
5367
|
+
compoundingTokenAccount: compoudingTokenAccount,
|
5368
|
+
transferAuthority: poolConfig.transferAuthority,
|
5369
|
+
perpetuals: poolConfig.perpetuals,
|
5370
|
+
pool: poolConfig.poolAddress,
|
5371
|
+
flpStakeAccount: flpStakeAccount,
|
5372
|
+
rewardCustody: rewardCustody.custodyAccount,
|
5373
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
5374
|
+
poolStakedLpVault: poolStakedLpVault,
|
5375
|
+
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
5376
|
+
lpTokenMint: lpTokenMint,
|
5377
|
+
compoundingTokenMint: compoundingTokenMint,
|
5376
5378
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5377
5379
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5378
|
-
|
5380
|
+
eventAuthority: this.eventAuthority.publicKey,
|
5381
|
+
program: this.program.programId,
|
5382
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5379
5383
|
})
|
5384
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5380
5385
|
.instruction()];
|
5381
5386
|
case 2:
|
5382
|
-
|
5383
|
-
instructions.push(
|
5387
|
+
migrateFlp = _d.sent();
|
5388
|
+
instructions.push(migrateFlp);
|
5384
5389
|
return [3, 4];
|
5385
5390
|
case 3:
|
5386
|
-
|
5387
|
-
console.log("perpClient
|
5388
|
-
|
5391
|
+
err_24 = _d.sent();
|
5392
|
+
console.log("perpClient migrateFlp error:: ", err_24);
|
5393
|
+
return [3, 4];
|
5389
5394
|
case 4: return [2, {
|
5390
5395
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5391
5396
|
additionalSigners: additionalSigners
|
@@ -5393,8 +5398,83 @@ var PerpetualsClient = (function () {
|
|
5393
5398
|
}
|
5394
5399
|
});
|
5395
5400
|
}); };
|
5401
|
+
this.compoundingFee = function (poolConfig_1) {
|
5402
|
+
var args_1 = [];
|
5403
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
5404
|
+
args_1[_i - 1] = arguments[_i];
|
5405
|
+
}
|
5406
|
+
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
5407
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_25;
|
5408
|
+
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
5409
|
+
return __generator(this, function (_e) {
|
5410
|
+
switch (_e.label) {
|
5411
|
+
case 0:
|
5412
|
+
instructions = [];
|
5413
|
+
additionalSigners = [];
|
5414
|
+
rewardCustody = poolConfig.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
5415
|
+
lpTokenMint = poolConfig.stakedLpTokenMint;
|
5416
|
+
custodyAccountMetas = [];
|
5417
|
+
custodyOracleAccountMetas = [];
|
5418
|
+
markets = [];
|
5419
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
5420
|
+
custody = _b[_a];
|
5421
|
+
custodyAccountMetas.push({
|
5422
|
+
pubkey: custody.custodyAccount,
|
5423
|
+
isSigner: false,
|
5424
|
+
isWritable: false,
|
5425
|
+
});
|
5426
|
+
custodyOracleAccountMetas.push({
|
5427
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
5428
|
+
isSigner: false,
|
5429
|
+
isWritable: false,
|
5430
|
+
});
|
5431
|
+
}
|
5432
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
5433
|
+
market = _d[_c];
|
5434
|
+
markets.push({
|
5435
|
+
pubkey: market.marketAccount,
|
5436
|
+
isSigner: false,
|
5437
|
+
isWritable: false,
|
5438
|
+
});
|
5439
|
+
}
|
5440
|
+
_e.label = 1;
|
5441
|
+
case 1:
|
5442
|
+
_e.trys.push([1, 3, , 4]);
|
5443
|
+
return [4, this.program.methods
|
5444
|
+
.compoundFees({})
|
5445
|
+
.accounts({
|
5446
|
+
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
5447
|
+
transferAuthority: poolConfig.transferAuthority,
|
5448
|
+
perpetuals: poolConfig.perpetuals,
|
5449
|
+
pool: poolConfig.poolAddress,
|
5450
|
+
rewardCustody: rewardCustody.custodyAccount,
|
5451
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
5452
|
+
lpTokenMint: lpTokenMint,
|
5453
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5454
|
+
eventAuthority: this.eventAuthority.publicKey,
|
5455
|
+
program: this.program.programId,
|
5456
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5457
|
+
})
|
5458
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5459
|
+
.instruction()];
|
5460
|
+
case 2:
|
5461
|
+
compoundingFee = _e.sent();
|
5462
|
+
instructions.push(compoundingFee);
|
5463
|
+
return [3, 4];
|
5464
|
+
case 3:
|
5465
|
+
err_25 = _e.sent();
|
5466
|
+
console.log("perpClient compoundingFee error:: ", err_25);
|
5467
|
+
return [3, 4];
|
5468
|
+
case 4: return [2, {
|
5469
|
+
instructions: __spreadArray([], instructions, true),
|
5470
|
+
additionalSigners: additionalSigners
|
5471
|
+
}];
|
5472
|
+
}
|
5473
|
+
});
|
5474
|
+
});
|
5475
|
+
};
|
5396
5476
|
this.burnAndClaim = function (owner, nftMint, poolConfig, createAta) { return __awaiter(_this, void 0, void 0, function () {
|
5397
|
-
var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction,
|
5477
|
+
var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction, err_26;
|
5398
5478
|
return __generator(this, function (_b) {
|
5399
5479
|
switch (_b.label) {
|
5400
5480
|
case 0:
|
@@ -5458,9 +5538,9 @@ var PerpetualsClient = (function () {
|
|
5458
5538
|
instructions.push(burnAndClaimInstruction);
|
5459
5539
|
return [3, 8];
|
5460
5540
|
case 7:
|
5461
|
-
|
5462
|
-
console.log("perpClient burnAndClaimInstruction error:: ",
|
5463
|
-
throw
|
5541
|
+
err_26 = _b.sent();
|
5542
|
+
console.log("perpClient burnAndClaimInstruction error:: ", err_26);
|
5543
|
+
throw err_26;
|
5464
5544
|
case 8: return [2, {
|
5465
5545
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5466
5546
|
additionalSigners: additionalSigners
|
@@ -5469,7 +5549,7 @@ var PerpetualsClient = (function () {
|
|
5469
5549
|
});
|
5470
5550
|
}); };
|
5471
5551
|
this.burnAndStake = function (owner, feePayer, nftMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5472
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction,
|
5552
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction, err_27;
|
5473
5553
|
return __generator(this, function (_a) {
|
5474
5554
|
switch (_a.label) {
|
5475
5555
|
case 0:
|
@@ -5520,9 +5600,9 @@ var PerpetualsClient = (function () {
|
|
5520
5600
|
instructions.push(burnAndStakeInstruction);
|
5521
5601
|
return [3, 4];
|
5522
5602
|
case 3:
|
5523
|
-
|
5524
|
-
console.log("perpClient burnAndStakeInstruction error:: ",
|
5525
|
-
throw
|
5603
|
+
err_27 = _a.sent();
|
5604
|
+
console.log("perpClient burnAndStakeInstruction error:: ", err_27);
|
5605
|
+
throw err_27;
|
5526
5606
|
case 4: return [2, {
|
5527
5607
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5528
5608
|
additionalSigners: additionalSigners
|
@@ -5531,7 +5611,7 @@ var PerpetualsClient = (function () {
|
|
5531
5611
|
});
|
5532
5612
|
}); };
|
5533
5613
|
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5534
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction,
|
5614
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_28;
|
5535
5615
|
return __generator(this, function (_a) {
|
5536
5616
|
switch (_a.label) {
|
5537
5617
|
case 0:
|
@@ -5572,9 +5652,9 @@ var PerpetualsClient = (function () {
|
|
5572
5652
|
instructions.push(depositTokenStakeInstruction);
|
5573
5653
|
return [3, 5];
|
5574
5654
|
case 4:
|
5575
|
-
|
5576
|
-
console.log("perpClient depositStakingInstruction error:: ",
|
5577
|
-
throw
|
5655
|
+
err_28 = _a.sent();
|
5656
|
+
console.log("perpClient depositStakingInstruction error:: ", err_28);
|
5657
|
+
throw err_28;
|
5578
5658
|
case 5: return [2, {
|
5579
5659
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5580
5660
|
additionalSigners: additionalSigners
|
@@ -5583,7 +5663,7 @@ var PerpetualsClient = (function () {
|
|
5583
5663
|
});
|
5584
5664
|
}); };
|
5585
5665
|
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5586
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction,
|
5666
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_29;
|
5587
5667
|
return __generator(this, function (_a) {
|
5588
5668
|
switch (_a.label) {
|
5589
5669
|
case 0:
|
@@ -5612,9 +5692,9 @@ var PerpetualsClient = (function () {
|
|
5612
5692
|
instructions.push(unstakeTokenRequestInstruction);
|
5613
5693
|
return [3, 4];
|
5614
5694
|
case 3:
|
5615
|
-
|
5616
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
5617
|
-
throw
|
5695
|
+
err_29 = _a.sent();
|
5696
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_29);
|
5697
|
+
throw err_29;
|
5618
5698
|
case 4: return [2, {
|
5619
5699
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5620
5700
|
additionalSigners: additionalSigners
|
@@ -5623,7 +5703,7 @@ var PerpetualsClient = (function () {
|
|
5623
5703
|
});
|
5624
5704
|
}); };
|
5625
5705
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5626
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
5706
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_30;
|
5627
5707
|
return __generator(this, function (_a) {
|
5628
5708
|
switch (_a.label) {
|
5629
5709
|
case 0:
|
@@ -5663,9 +5743,9 @@ var PerpetualsClient = (function () {
|
|
5663
5743
|
instructions.push(unstakeTokenInstantInstruction);
|
5664
5744
|
return [3, 5];
|
5665
5745
|
case 4:
|
5666
|
-
|
5667
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
5668
|
-
throw
|
5746
|
+
err_30 = _a.sent();
|
5747
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_30);
|
5748
|
+
throw err_30;
|
5669
5749
|
case 5: return [2, {
|
5670
5750
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5671
5751
|
additionalSigners: additionalSigners
|
@@ -5674,7 +5754,7 @@ var PerpetualsClient = (function () {
|
|
5674
5754
|
});
|
5675
5755
|
}); };
|
5676
5756
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5677
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
5757
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_31;
|
5678
5758
|
return __generator(this, function (_a) {
|
5679
5759
|
switch (_a.label) {
|
5680
5760
|
case 0:
|
@@ -5714,9 +5794,9 @@ var PerpetualsClient = (function () {
|
|
5714
5794
|
instructions.push(withdrawTokenInstruction);
|
5715
5795
|
return [3, 5];
|
5716
5796
|
case 4:
|
5717
|
-
|
5718
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
5719
|
-
throw
|
5797
|
+
err_31 = _a.sent();
|
5798
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_31);
|
5799
|
+
throw err_31;
|
5720
5800
|
case 5: return [2, {
|
5721
5801
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5722
5802
|
additionalSigners: additionalSigners
|
@@ -5725,7 +5805,7 @@ var PerpetualsClient = (function () {
|
|
5725
5805
|
});
|
5726
5806
|
}); };
|
5727
5807
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5728
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
5808
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_32;
|
5729
5809
|
return __generator(this, function (_a) {
|
5730
5810
|
switch (_a.label) {
|
5731
5811
|
case 0:
|
@@ -5754,101 +5834,9 @@ var PerpetualsClient = (function () {
|
|
5754
5834
|
instructions.push(cancelUnstakeRequestInstruction);
|
5755
5835
|
return [3, 4];
|
5756
5836
|
case 3:
|
5757
|
-
|
5758
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
5759
|
-
throw
|
5760
|
-
case 4: return [2, {
|
5761
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5762
|
-
additionalSigners: additionalSigners
|
5763
|
-
}];
|
5764
|
-
}
|
5765
|
-
});
|
5766
|
-
}); };
|
5767
|
-
this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5768
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_34;
|
5769
|
-
return __generator(this, function (_a) {
|
5770
|
-
switch (_a.label) {
|
5771
|
-
case 0:
|
5772
|
-
publicKey = this.provider.wallet.publicKey;
|
5773
|
-
preInstructions = [];
|
5774
|
-
instructions = [];
|
5775
|
-
postInstructions = [];
|
5776
|
-
additionalSigners = [];
|
5777
|
-
_a.label = 1;
|
5778
|
-
case 1:
|
5779
|
-
_a.trys.push([1, 3, , 4]);
|
5780
|
-
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
5781
|
-
fundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, publicKey, true);
|
5782
|
-
revenueFundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5783
|
-
return [4, this.program.methods
|
5784
|
-
.distributeTokenReward({
|
5785
|
-
amount: amount,
|
5786
|
-
epochCount: epochCount,
|
5787
|
-
})
|
5788
|
-
.accounts({
|
5789
|
-
admin: publicKey,
|
5790
|
-
multisig: this.multisig.publicKey,
|
5791
|
-
perpetuals: this.perpetuals.publicKey,
|
5792
|
-
transferAuthority: poolConfig.transferAuthority,
|
5793
|
-
fundingTokenAccount: fundingTokenAccount,
|
5794
|
-
tokenVault: poolConfig.tokenVault,
|
5795
|
-
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
5796
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5797
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5798
|
-
program: this.programId
|
5799
|
-
})
|
5800
|
-
.instruction()];
|
5801
|
-
case 2:
|
5802
|
-
distributeTokenRewardInstruction = _a.sent();
|
5803
|
-
instructions.push(distributeTokenRewardInstruction);
|
5804
|
-
return [3, 4];
|
5805
|
-
case 3:
|
5806
|
-
err_34 = _a.sent();
|
5807
|
-
console.log("perpClient distributeTokenRewardInstruction error:: ", err_34);
|
5808
|
-
throw err_34;
|
5809
|
-
case 4: return [2, {
|
5810
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5811
|
-
additionalSigners: additionalSigners
|
5812
|
-
}];
|
5813
|
-
}
|
5814
|
-
});
|
5815
|
-
}); };
|
5816
|
-
this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5817
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_35;
|
5818
|
-
return __generator(this, function (_a) {
|
5819
|
-
switch (_a.label) {
|
5820
|
-
case 0:
|
5821
|
-
publicKey = this.provider.wallet.publicKey;
|
5822
|
-
preInstructions = [];
|
5823
|
-
instructions = [];
|
5824
|
-
postInstructions = [];
|
5825
|
-
additionalSigners = [];
|
5826
|
-
_a.label = 1;
|
5827
|
-
case 1:
|
5828
|
-
_a.trys.push([1, 3, , 4]);
|
5829
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5830
|
-
return [4, this.program.methods
|
5831
|
-
.setTokenReward({
|
5832
|
-
amount: amount,
|
5833
|
-
epochCount: epochCount,
|
5834
|
-
})
|
5835
|
-
.accounts({
|
5836
|
-
admin: publicKey,
|
5837
|
-
multisig: this.multisig.publicKey,
|
5838
|
-
tokenVault: poolConfig.tokenVault,
|
5839
|
-
tokenStakeAccount: tokenStakeAccount,
|
5840
|
-
eventAuthority: this.eventAuthority.publicKey,
|
5841
|
-
program: this.programId
|
5842
|
-
})
|
5843
|
-
.instruction()];
|
5844
|
-
case 2:
|
5845
|
-
setTokenRewardInstruction = _a.sent();
|
5846
|
-
instructions.push(setTokenRewardInstruction);
|
5847
|
-
return [3, 4];
|
5848
|
-
case 3:
|
5849
|
-
err_35 = _a.sent();
|
5850
|
-
console.log("perpClient setTokenRewardInstruction error:: ", err_35);
|
5851
|
-
throw err_35;
|
5837
|
+
err_32 = _a.sent();
|
5838
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_32);
|
5839
|
+
throw err_32;
|
5852
5840
|
case 4: return [2, {
|
5853
5841
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5854
5842
|
additionalSigners: additionalSigners
|
@@ -5862,7 +5850,7 @@ var PerpetualsClient = (function () {
|
|
5862
5850
|
args_1[_i - 2] = arguments[_i];
|
5863
5851
|
}
|
5864
5852
|
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5865
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction,
|
5853
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_33;
|
5866
5854
|
if (createUserATA === void 0) { createUserATA = true; }
|
5867
5855
|
return __generator(this, function (_b) {
|
5868
5856
|
switch (_b.label) {
|
@@ -5907,9 +5895,9 @@ var PerpetualsClient = (function () {
|
|
5907
5895
|
instructions.push(collectTokenRewardInstruction);
|
5908
5896
|
return [3, 6];
|
5909
5897
|
case 5:
|
5910
|
-
|
5911
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
5912
|
-
throw
|
5898
|
+
err_33 = _b.sent();
|
5899
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_33);
|
5900
|
+
throw err_33;
|
5913
5901
|
case 6: return [2, {
|
5914
5902
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5915
5903
|
additionalSigners: additionalSigners
|
@@ -5924,7 +5912,7 @@ var PerpetualsClient = (function () {
|
|
5924
5912
|
args_1[_i - 3] = arguments[_i];
|
5925
5913
|
}
|
5926
5914
|
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5927
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction,
|
5915
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_34;
|
5928
5916
|
if (createUserATA === void 0) { createUserATA = true; }
|
5929
5917
|
return __generator(this, function (_b) {
|
5930
5918
|
switch (_b.label) {
|
@@ -5970,58 +5958,19 @@ var PerpetualsClient = (function () {
|
|
5970
5958
|
instructions.push(collectRevenueInstruction);
|
5971
5959
|
return [3, 6];
|
5972
5960
|
case 5:
|
5973
|
-
|
5974
|
-
console.log("perpClient collectRevenueInstruction error:: ",
|
5975
|
-
throw
|
5961
|
+
err_34 = _b.sent();
|
5962
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_34);
|
5963
|
+
throw err_34;
|
5976
5964
|
case 6: return [2, {
|
5977
5965
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5978
|
-
additionalSigners: additionalSigners
|
5979
|
-
}];
|
5980
|
-
}
|
5981
|
-
});
|
5982
|
-
});
|
5983
|
-
};
|
5984
|
-
this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
|
5985
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_38;
|
5986
|
-
return __generator(this, function (_a) {
|
5987
|
-
switch (_a.label) {
|
5988
|
-
case 0:
|
5989
|
-
publicKey = this.provider.wallet.publicKey;
|
5990
|
-
preInstructions = [];
|
5991
|
-
instructions = [];
|
5992
|
-
postInstructions = [];
|
5993
|
-
additionalSigners = [];
|
5994
|
-
_a.label = 1;
|
5995
|
-
case 1:
|
5996
|
-
_a.trys.push([1, 3, , 4]);
|
5997
|
-
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
5998
|
-
return [4, this.program.methods
|
5999
|
-
.setTokenStakeLevel({
|
6000
|
-
level: stakeLevel,
|
6001
|
-
})
|
6002
|
-
.accounts({
|
6003
|
-
admin: publicKey,
|
6004
|
-
multisig: this.multisig.publicKey,
|
6005
|
-
tokenStakeAccount: tokenStakeAccount,
|
6006
|
-
})
|
6007
|
-
.instruction()];
|
6008
|
-
case 2:
|
6009
|
-
setTokenStakeLevelInstruction = _a.sent();
|
6010
|
-
instructions.push(setTokenStakeLevelInstruction);
|
6011
|
-
return [3, 4];
|
6012
|
-
case 3:
|
6013
|
-
err_38 = _a.sent();
|
6014
|
-
console.log("perpClient setTokenStakeLevelInstruction error:: ", err_38);
|
6015
|
-
throw err_38;
|
6016
|
-
case 4: return [2, {
|
6017
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6018
|
-
additionalSigners: additionalSigners
|
6019
|
-
}];
|
6020
|
-
}
|
5966
|
+
additionalSigners: additionalSigners
|
5967
|
+
}];
|
5968
|
+
}
|
5969
|
+
});
|
6021
5970
|
});
|
6022
|
-
}
|
5971
|
+
};
|
6023
5972
|
this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6024
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault,
|
5973
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_35;
|
6025
5974
|
return __generator(this, function (_a) {
|
6026
5975
|
switch (_a.label) {
|
6027
5976
|
case 0:
|
@@ -6058,9 +6007,9 @@ var PerpetualsClient = (function () {
|
|
6058
6007
|
instructions.push(initRewardVault);
|
6059
6008
|
return [3, 4];
|
6060
6009
|
case 3:
|
6061
|
-
|
6062
|
-
console.log("perpClient InitRewardVault error:: ",
|
6063
|
-
throw
|
6010
|
+
err_35 = _a.sent();
|
6011
|
+
console.log("perpClient InitRewardVault error:: ", err_35);
|
6012
|
+
throw err_35;
|
6064
6013
|
case 4: return [2, {
|
6065
6014
|
instructions: __spreadArray([], instructions, true),
|
6066
6015
|
additionalSigners: additionalSigners
|
@@ -6069,7 +6018,7 @@ var PerpetualsClient = (function () {
|
|
6069
6018
|
});
|
6070
6019
|
}); };
|
6071
6020
|
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6072
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward,
|
6021
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_36;
|
6073
6022
|
return __generator(this, function (_a) {
|
6074
6023
|
switch (_a.label) {
|
6075
6024
|
case 0:
|
@@ -6100,9 +6049,9 @@ var PerpetualsClient = (function () {
|
|
6100
6049
|
instructions.push(distributeReward);
|
6101
6050
|
return [3, 4];
|
6102
6051
|
case 3:
|
6103
|
-
|
6104
|
-
console.log("perpClient distributeReward error:: ",
|
6105
|
-
throw
|
6052
|
+
err_36 = _a.sent();
|
6053
|
+
console.log("perpClient distributeReward error:: ", err_36);
|
6054
|
+
throw err_36;
|
6106
6055
|
case 4: return [2, {
|
6107
6056
|
instructions: __spreadArray([], instructions, true),
|
6108
6057
|
additionalSigners: additionalSigners
|
@@ -6116,7 +6065,7 @@ var PerpetualsClient = (function () {
|
|
6116
6065
|
args_1[_i - 3] = arguments[_i];
|
6117
6066
|
}
|
6118
6067
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
6119
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward,
|
6068
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_37;
|
6120
6069
|
if (createUserATA === void 0) { createUserATA = true; }
|
6121
6070
|
return __generator(this, function (_b) {
|
6122
6071
|
switch (_b.label) {
|
@@ -6167,8 +6116,8 @@ var PerpetualsClient = (function () {
|
|
6167
6116
|
instructions.push(collectNftReward);
|
6168
6117
|
return [3, 6];
|
6169
6118
|
case 5:
|
6170
|
-
|
6171
|
-
throw
|
6119
|
+
err_37 = _b.sent();
|
6120
|
+
throw err_37;
|
6172
6121
|
case 6: return [2, {
|
6173
6122
|
instructions: __spreadArray([], instructions, true),
|
6174
6123
|
additionalSigners: additionalSigners
|
@@ -6183,7 +6132,7 @@ var PerpetualsClient = (function () {
|
|
6183
6132
|
args_1[_i - 2] = arguments[_i];
|
6184
6133
|
}
|
6185
6134
|
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
6186
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction,
|
6135
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_38;
|
6187
6136
|
if (createUserATA === void 0) { createUserATA = true; }
|
6188
6137
|
return __generator(this, function (_b) {
|
6189
6138
|
switch (_b.label) {
|
@@ -6248,9 +6197,9 @@ var PerpetualsClient = (function () {
|
|
6248
6197
|
instructions.push(withdrawStakeInstruction);
|
6249
6198
|
return [3, 6];
|
6250
6199
|
case 5:
|
6251
|
-
|
6252
|
-
console.log("perpClient withdrawStake error:: ",
|
6253
|
-
throw
|
6200
|
+
err_38 = _b.sent();
|
6201
|
+
console.log("perpClient withdrawStake error:: ", err_38);
|
6202
|
+
throw err_38;
|
6254
6203
|
case 6: return [2, {
|
6255
6204
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6256
6205
|
additionalSigners: additionalSigners
|
@@ -6260,7 +6209,7 @@ var PerpetualsClient = (function () {
|
|
6260
6209
|
});
|
6261
6210
|
};
|
6262
6211
|
this.setTriggerPrice = function (targetSymbol, collateralSymbol, side, triggerPrice, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6263
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice,
|
6212
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice, err_39;
|
6264
6213
|
return __generator(this, function (_a) {
|
6265
6214
|
switch (_a.label) {
|
6266
6215
|
case 0:
|
@@ -6299,9 +6248,9 @@ var PerpetualsClient = (function () {
|
|
6299
6248
|
instructions.push(setTriggerPrice);
|
6300
6249
|
return [3, 4];
|
6301
6250
|
case 3:
|
6302
|
-
|
6303
|
-
console.log("perpClient setTriggerPrice error:: ",
|
6304
|
-
throw
|
6251
|
+
err_39 = _a.sent();
|
6252
|
+
console.log("perpClient setTriggerPrice error:: ", err_39);
|
6253
|
+
throw err_39;
|
6305
6254
|
case 4: return [2, {
|
6306
6255
|
instructions: __spreadArray([], instructions, true),
|
6307
6256
|
additionalSigners: additionalSigners
|
@@ -6315,7 +6264,7 @@ var PerpetualsClient = (function () {
|
|
6315
6264
|
args_1[_i - 6] = arguments[_i];
|
6316
6265
|
}
|
6317
6266
|
return __awaiter(_this, __spreadArray([positionAccount_2, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1], args_1, true), void 0, function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
6318
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns,
|
6267
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_40;
|
6319
6268
|
if (createUserATA === void 0) { createUserATA = true; }
|
6320
6269
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
6321
6270
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
@@ -6379,9 +6328,9 @@ var PerpetualsClient = (function () {
|
|
6379
6328
|
}
|
6380
6329
|
return [3, 7];
|
6381
6330
|
case 6:
|
6382
|
-
|
6383
|
-
console.log("perpClient forceClosePosition error:: ",
|
6384
|
-
throw
|
6331
|
+
err_40 = _b.sent();
|
6332
|
+
console.log("perpClient forceClosePosition error:: ", err_40);
|
6333
|
+
throw err_40;
|
6385
6334
|
case 7: return [2, {
|
6386
6335
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6387
6336
|
additionalSigners: additionalSigners
|
@@ -6396,7 +6345,7 @@ var PerpetualsClient = (function () {
|
|
6396
6345
|
args_1[_i - 11] = arguments[_i];
|
6397
6346
|
}
|
6398
6347
|
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) {
|
6399
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder,
|
6348
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_41;
|
6400
6349
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6401
6350
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6402
6351
|
return __generator(this, function (_c) {
|
@@ -6503,9 +6452,9 @@ var PerpetualsClient = (function () {
|
|
6503
6452
|
instructions.push(placeLimitOrder);
|
6504
6453
|
return [3, 11];
|
6505
6454
|
case 10:
|
6506
|
-
|
6507
|
-
console.log("perpClient placeLimitOrder error:: ",
|
6508
|
-
throw
|
6455
|
+
err_41 = _c.sent();
|
6456
|
+
console.log("perpClient placeLimitOrder error:: ", err_41);
|
6457
|
+
throw err_41;
|
6509
6458
|
case 11: return [2, {
|
6510
6459
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6511
6460
|
additionalSigners: additionalSigners
|
@@ -6520,7 +6469,7 @@ var PerpetualsClient = (function () {
|
|
6520
6469
|
args_1[_i - 11] = arguments[_i];
|
6521
6470
|
}
|
6522
6471
|
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) {
|
6523
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder,
|
6472
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_42;
|
6524
6473
|
if (createUserATA === void 0) { createUserATA = true; }
|
6525
6474
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6526
6475
|
return __generator(this, function (_b) {
|
@@ -6610,9 +6559,9 @@ var PerpetualsClient = (function () {
|
|
6610
6559
|
instructions.push(editLimitOrder);
|
6611
6560
|
return [3, 8];
|
6612
6561
|
case 7:
|
6613
|
-
|
6614
|
-
console.log("perpClient editLimitOrder error:: ",
|
6615
|
-
throw
|
6562
|
+
err_42 = _b.sent();
|
6563
|
+
console.log("perpClient editLimitOrder error:: ", err_42);
|
6564
|
+
throw err_42;
|
6616
6565
|
case 8: return [2, {
|
6617
6566
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6618
6567
|
additionalSigners: additionalSigners
|
@@ -6627,7 +6576,7 @@ var PerpetualsClient = (function () {
|
|
6627
6576
|
args_1[_i - 7] = arguments[_i];
|
6628
6577
|
}
|
6629
6578
|
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6630
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder,
|
6579
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_43;
|
6631
6580
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6632
6581
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6633
6582
|
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
@@ -6679,9 +6628,9 @@ var PerpetualsClient = (function () {
|
|
6679
6628
|
instructions.push(executeLimitOrder);
|
6680
6629
|
return [3, 4];
|
6681
6630
|
case 3:
|
6682
|
-
|
6683
|
-
console.log("perpClient executeLimitOrder error:: ",
|
6684
|
-
throw
|
6631
|
+
err_43 = _a.sent();
|
6632
|
+
console.log("perpClient executeLimitOrder error:: ", err_43);
|
6633
|
+
throw err_43;
|
6685
6634
|
case 4: return [2, {
|
6686
6635
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6687
6636
|
additionalSigners: additionalSigners
|
@@ -6696,7 +6645,7 @@ var PerpetualsClient = (function () {
|
|
6696
6645
|
args_1[_i - 8] = arguments[_i];
|
6697
6646
|
}
|
6698
6647
|
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6699
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap,
|
6648
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_44;
|
6700
6649
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6701
6650
|
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6702
6651
|
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
@@ -6751,9 +6700,9 @@ var PerpetualsClient = (function () {
|
|
6751
6700
|
instructions.push(executeLimitWithSwap);
|
6752
6701
|
return [3, 4];
|
6753
6702
|
case 3:
|
6754
|
-
|
6755
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
6756
|
-
throw
|
6703
|
+
err_44 = _a.sent();
|
6704
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_44);
|
6705
|
+
throw err_44;
|
6757
6706
|
case 4: return [2, {
|
6758
6707
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6759
6708
|
additionalSigners: additionalSigners
|
@@ -6763,7 +6712,7 @@ var PerpetualsClient = (function () {
|
|
6763
6712
|
});
|
6764
6713
|
};
|
6765
6714
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6766
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder,
|
6715
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_45;
|
6767
6716
|
return __generator(this, function (_a) {
|
6768
6717
|
switch (_a.label) {
|
6769
6718
|
case 0:
|
@@ -6811,9 +6760,9 @@ var PerpetualsClient = (function () {
|
|
6811
6760
|
instructions.push(placeTriggerOrder);
|
6812
6761
|
return [3, 4];
|
6813
6762
|
case 3:
|
6814
|
-
|
6815
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
6816
|
-
throw
|
6763
|
+
err_45 = _a.sent();
|
6764
|
+
console.log("perpClient placeTriggerOrder error:: ", err_45);
|
6765
|
+
throw err_45;
|
6817
6766
|
case 4: return [2, {
|
6818
6767
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6819
6768
|
additionalSigners: additionalSigners
|
@@ -6822,7 +6771,7 @@ var PerpetualsClient = (function () {
|
|
6822
6771
|
});
|
6823
6772
|
}); };
|
6824
6773
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6825
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder,
|
6774
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_46;
|
6826
6775
|
return __generator(this, function (_a) {
|
6827
6776
|
switch (_a.label) {
|
6828
6777
|
case 0:
|
@@ -6869,9 +6818,9 @@ var PerpetualsClient = (function () {
|
|
6869
6818
|
instructions.push(editTriggerOrder);
|
6870
6819
|
return [3, 4];
|
6871
6820
|
case 3:
|
6872
|
-
|
6873
|
-
console.log("perpClient editTriggerOrder error:: ",
|
6874
|
-
throw
|
6821
|
+
err_46 = _a.sent();
|
6822
|
+
console.log("perpClient editTriggerOrder error:: ", err_46);
|
6823
|
+
throw err_46;
|
6875
6824
|
case 4: return [2, {
|
6876
6825
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6877
6826
|
additionalSigners: additionalSigners
|
@@ -6880,7 +6829,7 @@ var PerpetualsClient = (function () {
|
|
6880
6829
|
});
|
6881
6830
|
}); };
|
6882
6831
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6883
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder,
|
6832
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_47;
|
6884
6833
|
return __generator(this, function (_a) {
|
6885
6834
|
switch (_a.label) {
|
6886
6835
|
case 0:
|
@@ -6913,9 +6862,9 @@ var PerpetualsClient = (function () {
|
|
6913
6862
|
instructions.push(cancelTriggerOrder);
|
6914
6863
|
return [3, 4];
|
6915
6864
|
case 3:
|
6916
|
-
|
6917
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
6918
|
-
throw
|
6865
|
+
err_47 = _a.sent();
|
6866
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_47);
|
6867
|
+
throw err_47;
|
6919
6868
|
case 4: return [2, {
|
6920
6869
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6921
6870
|
additionalSigners: additionalSigners
|
@@ -6924,7 +6873,7 @@ var PerpetualsClient = (function () {
|
|
6924
6873
|
});
|
6925
6874
|
}); };
|
6926
6875
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6927
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders,
|
6876
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_48;
|
6928
6877
|
return __generator(this, function (_a) {
|
6929
6878
|
switch (_a.label) {
|
6930
6879
|
case 0:
|
@@ -6955,9 +6904,9 @@ var PerpetualsClient = (function () {
|
|
6955
6904
|
instructions.push(cancelAllTriggerOrders);
|
6956
6905
|
return [3, 4];
|
6957
6906
|
case 3:
|
6958
|
-
|
6959
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
6960
|
-
throw
|
6907
|
+
err_48 = _a.sent();
|
6908
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_48);
|
6909
|
+
throw err_48;
|
6961
6910
|
case 4: return [2, {
|
6962
6911
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6963
6912
|
additionalSigners: additionalSigners
|
@@ -6971,7 +6920,7 @@ var PerpetualsClient = (function () {
|
|
6971
6920
|
args_1[_i - 9] = arguments[_i];
|
6972
6921
|
}
|
6973
6922
|
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6974
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap,
|
6923
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_49;
|
6975
6924
|
if (createUserATA === void 0) { createUserATA = true; }
|
6976
6925
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6977
6926
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
@@ -7073,9 +7022,9 @@ var PerpetualsClient = (function () {
|
|
7073
7022
|
instructions.push(executeTriggerWithSwap);
|
7074
7023
|
return [3, 10];
|
7075
7024
|
case 9:
|
7076
|
-
|
7077
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
7078
|
-
throw
|
7025
|
+
err_49 = _e.sent();
|
7026
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_49);
|
7027
|
+
throw err_49;
|
7079
7028
|
case 10: return [2, {
|
7080
7029
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7081
7030
|
additionalSigners: additionalSigners
|
@@ -7090,7 +7039,7 @@ var PerpetualsClient = (function () {
|
|
7090
7039
|
args_1[_i - 8] = arguments[_i];
|
7091
7040
|
}
|
7092
7041
|
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
7093
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder,
|
7042
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_50;
|
7094
7043
|
if (createUserATA === void 0) { createUserATA = true; }
|
7095
7044
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7096
7045
|
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
@@ -7161,9 +7110,9 @@ var PerpetualsClient = (function () {
|
|
7161
7110
|
instructions.push(executeTriggerOrder);
|
7162
7111
|
return [3, 8];
|
7163
7112
|
case 7:
|
7164
|
-
|
7165
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
7166
|
-
throw
|
7113
|
+
err_50 = _b.sent();
|
7114
|
+
console.log("perpClient executeTriggerOrder error:: ", err_50);
|
7115
|
+
throw err_50;
|
7167
7116
|
case 8: return [2, {
|
7168
7117
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7169
7118
|
additionalSigners: additionalSigners
|
@@ -7173,7 +7122,7 @@ var PerpetualsClient = (function () {
|
|
7173
7122
|
});
|
7174
7123
|
};
|
7175
7124
|
this.migrateTriggerOrder = function (owner, marketAccount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7176
|
-
var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder,
|
7125
|
+
var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder, err_51;
|
7177
7126
|
return __generator(this, function (_a) {
|
7178
7127
|
switch (_a.label) {
|
7179
7128
|
case 0:
|
@@ -7184,74 +7133,297 @@ var PerpetualsClient = (function () {
|
|
7184
7133
|
additionalSigners = [];
|
7185
7134
|
_a.label = 1;
|
7186
7135
|
case 1:
|
7187
|
-
_a.trys.push([1, 3, , 4]);
|
7188
|
-
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
7189
|
-
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
7190
|
-
return [4, this.program.methods
|
7191
|
-
.migrateTriggerOrder()
|
7192
|
-
.accounts({
|
7193
|
-
owner: owner,
|
7194
|
-
feePayer: payerPubkey,
|
7195
|
-
position: positionAccount,
|
7196
|
-
order: orderAccount,
|
7197
|
-
market: marketAccount,
|
7198
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
7199
|
-
})
|
7200
|
-
.instruction()];
|
7201
|
-
case 2:
|
7202
|
-
migrateTriggerOrder = _a.sent();
|
7203
|
-
instructions.push(migrateTriggerOrder);
|
7204
|
-
return [3, 4];
|
7205
|
-
case 3:
|
7206
|
-
|
7207
|
-
console.log("perpClient migrateTriggerOrder error:: ",
|
7208
|
-
throw
|
7209
|
-
case 4: return [2, {
|
7210
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7211
|
-
additionalSigners: additionalSigners
|
7212
|
-
}];
|
7136
|
+
_a.trys.push([1, 3, , 4]);
|
7137
|
+
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
7138
|
+
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
7139
|
+
return [4, this.program.methods
|
7140
|
+
.migrateTriggerOrder()
|
7141
|
+
.accounts({
|
7142
|
+
owner: owner,
|
7143
|
+
feePayer: payerPubkey,
|
7144
|
+
position: positionAccount,
|
7145
|
+
order: orderAccount,
|
7146
|
+
market: marketAccount,
|
7147
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7148
|
+
})
|
7149
|
+
.instruction()];
|
7150
|
+
case 2:
|
7151
|
+
migrateTriggerOrder = _a.sent();
|
7152
|
+
instructions.push(migrateTriggerOrder);
|
7153
|
+
return [3, 4];
|
7154
|
+
case 3:
|
7155
|
+
err_51 = _a.sent();
|
7156
|
+
console.log("perpClient migrateTriggerOrder error:: ", err_51);
|
7157
|
+
throw err_51;
|
7158
|
+
case 4: return [2, {
|
7159
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7160
|
+
additionalSigners: additionalSigners
|
7161
|
+
}];
|
7162
|
+
}
|
7163
|
+
});
|
7164
|
+
}); };
|
7165
|
+
this.init = function (admins, config) { return __awaiter(_this, void 0, void 0, function () {
|
7166
|
+
var perpetualsProgramData, adminMetas, _i, admins_1, admin;
|
7167
|
+
return __generator(this, function (_a) {
|
7168
|
+
switch (_a.label) {
|
7169
|
+
case 0:
|
7170
|
+
perpetualsProgramData = web3_js_1.PublicKey.findProgramAddressSync([this.program.programId.toBuffer()], new web3_js_1.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111"))[0];
|
7171
|
+
adminMetas = [];
|
7172
|
+
for (_i = 0, admins_1 = admins; _i < admins_1.length; _i++) {
|
7173
|
+
admin = admins_1[_i];
|
7174
|
+
adminMetas.push({
|
7175
|
+
isSigner: false,
|
7176
|
+
isWritable: false,
|
7177
|
+
pubkey: admin,
|
7178
|
+
});
|
7179
|
+
}
|
7180
|
+
return [4, this.program.methods
|
7181
|
+
.init(config)
|
7182
|
+
.accounts({
|
7183
|
+
upgradeAuthority: this.provider.wallet.publicKey,
|
7184
|
+
multisig: this.multisig.publicKey,
|
7185
|
+
transferAuthority: this.authority.publicKey,
|
7186
|
+
perpetuals: this.perpetuals.publicKey,
|
7187
|
+
perpetualsProgram: this.program.programId,
|
7188
|
+
perpetualsProgramData: perpetualsProgramData,
|
7189
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7190
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7191
|
+
})
|
7192
|
+
.remainingAccounts(adminMetas)
|
7193
|
+
.rpc()
|
7194
|
+
.catch(function (err) {
|
7195
|
+
console.error(err);
|
7196
|
+
throw err;
|
7197
|
+
})];
|
7198
|
+
case 1:
|
7199
|
+
_a.sent();
|
7200
|
+
return [2];
|
7201
|
+
}
|
7202
|
+
});
|
7203
|
+
}); };
|
7204
|
+
this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
|
7205
|
+
var adminMetas, _i, admins_2, admin, err_52;
|
7206
|
+
return __generator(this, function (_a) {
|
7207
|
+
switch (_a.label) {
|
7208
|
+
case 0:
|
7209
|
+
adminMetas = [];
|
7210
|
+
for (_i = 0, admins_2 = admins; _i < admins_2.length; _i++) {
|
7211
|
+
admin = admins_2[_i];
|
7212
|
+
adminMetas.push({
|
7213
|
+
isSigner: false,
|
7214
|
+
isWritable: false,
|
7215
|
+
pubkey: admin,
|
7216
|
+
});
|
7217
|
+
}
|
7218
|
+
_a.label = 1;
|
7219
|
+
case 1:
|
7220
|
+
_a.trys.push([1, 3, , 4]);
|
7221
|
+
return [4, this.program.methods
|
7222
|
+
.setAdminSigners({
|
7223
|
+
minSignatures: minSignatures,
|
7224
|
+
})
|
7225
|
+
.accounts({
|
7226
|
+
admin: this.admin,
|
7227
|
+
multisig: this.multisig.publicKey,
|
7228
|
+
})
|
7229
|
+
.remainingAccounts(adminMetas)
|
7230
|
+
.rpc()];
|
7231
|
+
case 2:
|
7232
|
+
_a.sent();
|
7233
|
+
return [3, 4];
|
7234
|
+
case 3:
|
7235
|
+
err_52 = _a.sent();
|
7236
|
+
if (this.printErrors) {
|
7237
|
+
console.error("setAdminSigners err:", err_52);
|
7238
|
+
}
|
7239
|
+
throw err_52;
|
7240
|
+
case 4: return [2];
|
7241
|
+
}
|
7242
|
+
});
|
7243
|
+
}); };
|
7244
|
+
this.addPool = function (name, maxAumUsd, permissions, metadataSymbol, metadataTitle, metadataUri, stakingFeeShareBps, vpVolumeFactor) { return __awaiter(_this, void 0, void 0, function () {
|
7245
|
+
return __generator(this, function (_a) {
|
7246
|
+
switch (_a.label) {
|
7247
|
+
case 0: return [4, this.program.methods
|
7248
|
+
.addPool({
|
7249
|
+
name: name,
|
7250
|
+
maxAumUsd: maxAumUsd,
|
7251
|
+
permissions: permissions,
|
7252
|
+
metadataSymbol: metadataSymbol,
|
7253
|
+
metadataTitle: metadataTitle,
|
7254
|
+
metadataUri: metadataUri,
|
7255
|
+
stakingFeeShareBps: stakingFeeShareBps,
|
7256
|
+
vpVolumeFactor: vpVolumeFactor
|
7257
|
+
})
|
7258
|
+
.accounts({
|
7259
|
+
admin: this.provider.wallet.publicKey,
|
7260
|
+
multisig: this.multisig.publicKey,
|
7261
|
+
transferAuthority: this.authority.publicKey,
|
7262
|
+
perpetuals: this.perpetuals.publicKey,
|
7263
|
+
pool: this.getPoolKey(name),
|
7264
|
+
lpTokenMint: this.getPoolLpTokenKey(name),
|
7265
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7266
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7267
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
7268
|
+
})
|
7269
|
+
.rpc()
|
7270
|
+
.catch(function (err) {
|
7271
|
+
console.error(err);
|
7272
|
+
throw err;
|
7273
|
+
})];
|
7274
|
+
case 1:
|
7275
|
+
_a.sent();
|
7276
|
+
return [2];
|
7277
|
+
}
|
7278
|
+
});
|
7279
|
+
}); };
|
7280
|
+
this.removePool = function (name) { return __awaiter(_this, void 0, void 0, function () {
|
7281
|
+
return __generator(this, function (_a) {
|
7282
|
+
switch (_a.label) {
|
7283
|
+
case 0: return [4, this.program.methods
|
7284
|
+
.removePool({})
|
7285
|
+
.accounts({
|
7286
|
+
admin: this.admin,
|
7287
|
+
multisig: this.multisig.publicKey,
|
7288
|
+
transferAuthority: this.authority.publicKey,
|
7289
|
+
perpetuals: this.perpetuals.publicKey,
|
7290
|
+
pool: this.getPoolKey(name),
|
7291
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7292
|
+
})
|
7293
|
+
.rpc()
|
7294
|
+
.catch(function (err) {
|
7295
|
+
console.error(err);
|
7296
|
+
throw err;
|
7297
|
+
})];
|
7298
|
+
case 1:
|
7299
|
+
_a.sent();
|
7300
|
+
return [2];
|
7301
|
+
}
|
7302
|
+
});
|
7303
|
+
}); };
|
7304
|
+
this.addCustody = function (poolName, tokenMint, isStable, isVirtual, oracle, pricing, permissions, fees, borrowRate, ratios, depegAdjustment) { return __awaiter(_this, void 0, void 0, function () {
|
7305
|
+
var trx_id, error_3;
|
7306
|
+
return __generator(this, function (_a) {
|
7307
|
+
switch (_a.label) {
|
7308
|
+
case 0:
|
7309
|
+
_a.trys.push([0, 2, , 3]);
|
7310
|
+
return [4, this.program.methods
|
7311
|
+
.addCustody({
|
7312
|
+
isStable: isStable,
|
7313
|
+
isVirtual: isVirtual,
|
7314
|
+
oracle: oracle,
|
7315
|
+
pricing: pricing,
|
7316
|
+
permissions: permissions,
|
7317
|
+
fees: fees,
|
7318
|
+
borrowRate: borrowRate,
|
7319
|
+
ratios: ratios,
|
7320
|
+
depegAdjustment: depegAdjustment
|
7321
|
+
})
|
7322
|
+
.accounts({
|
7323
|
+
admin: this.admin,
|
7324
|
+
multisig: this.multisig.publicKey,
|
7325
|
+
transferAuthority: this.authority.publicKey,
|
7326
|
+
perpetuals: this.perpetuals.publicKey,
|
7327
|
+
pool: this.getPoolKey(poolName),
|
7328
|
+
custody: this.getCustodyKey(poolName, tokenMint),
|
7329
|
+
custodyTokenAccount: this.getCustodyTokenAccountKey(poolName, tokenMint),
|
7330
|
+
custodyTokenMint: tokenMint,
|
7331
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7332
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7333
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
7334
|
+
})
|
7335
|
+
.rpc()
|
7336
|
+
.catch(function (err) {
|
7337
|
+
console.error(err);
|
7338
|
+
throw err;
|
7339
|
+
})];
|
7340
|
+
case 1:
|
7341
|
+
trx_id = _a.sent();
|
7342
|
+
console.log("trx_id:", "https://explorer.solana.com/tx/".concat(trx_id, "?cluster=devnet"));
|
7343
|
+
return [3, 3];
|
7344
|
+
case 2:
|
7345
|
+
error_3 = _a.sent();
|
7346
|
+
console.error("cli error :", error_3);
|
7347
|
+
throw error_3;
|
7348
|
+
case 3: return [2];
|
7349
|
+
}
|
7350
|
+
});
|
7351
|
+
}); };
|
7352
|
+
this.editCustody = function (poolName, tokenMint, isStable, oracle, pricing, permissions, fees, borrowRate, ratios) { return __awaiter(_this, void 0, void 0, function () {
|
7353
|
+
var trx_id;
|
7354
|
+
return __generator(this, function (_a) {
|
7355
|
+
switch (_a.label) {
|
7356
|
+
case 0: return [4, this.program.methods
|
7357
|
+
.testingEditCustody({
|
7358
|
+
isStable: isStable,
|
7359
|
+
oracle: oracle,
|
7360
|
+
pricing: pricing,
|
7361
|
+
permissions: permissions,
|
7362
|
+
fees: fees,
|
7363
|
+
borrowRate: borrowRate,
|
7364
|
+
ratios: ratios,
|
7365
|
+
})
|
7366
|
+
.accounts({
|
7367
|
+
admin: this.admin,
|
7368
|
+
multisig: this.multisig.publicKey,
|
7369
|
+
transferAuthority: this.authority.publicKey,
|
7370
|
+
perpetuals: this.perpetuals.publicKey,
|
7371
|
+
pool: this.getPoolKey(poolName),
|
7372
|
+
custody: this.getCustodyKey(poolName, tokenMint),
|
7373
|
+
custodyTokenAccount: this.getCustodyTokenAccountKey(poolName, tokenMint),
|
7374
|
+
custodyTokenMint: tokenMint,
|
7375
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7376
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7377
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
7378
|
+
})
|
7379
|
+
.rpc()
|
7380
|
+
.catch(function (err) {
|
7381
|
+
console.error(err);
|
7382
|
+
throw err;
|
7383
|
+
})];
|
7384
|
+
case 1:
|
7385
|
+
trx_id = _a.sent();
|
7386
|
+
console.log("trx_id:", "https://explorer.solana.com/tx/".concat(trx_id, "?cluster=devnet"));
|
7387
|
+
return [2];
|
7213
7388
|
}
|
7214
7389
|
});
|
7215
7390
|
}); };
|
7216
|
-
this.
|
7217
|
-
var
|
7391
|
+
this.removeCustody = function (poolName, tokenMint, ratios, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7392
|
+
var custodyConfig, userReceivingTokenAccount;
|
7218
7393
|
return __generator(this, function (_a) {
|
7219
7394
|
switch (_a.label) {
|
7220
7395
|
case 0:
|
7221
|
-
|
7222
|
-
|
7223
|
-
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.custodyAccount.equals(marketConfig.collateralCustody); });
|
7224
|
-
_a.label = 1;
|
7225
|
-
case 1:
|
7226
|
-
_a.trys.push([1, 3, , 4]);
|
7396
|
+
custodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(tokenMint); });
|
7397
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, this.admin, true);
|
7227
7398
|
return [4, this.program.methods
|
7228
|
-
.
|
7399
|
+
.removeCustody({ ratios: ratios })
|
7229
7400
|
.accounts({
|
7401
|
+
admin: this.admin,
|
7402
|
+
receivingAccount: userReceivingTokenAccount,
|
7403
|
+
multisig: this.multisig.publicKey,
|
7404
|
+
transferAuthority: this.authority.publicKey,
|
7230
7405
|
perpetuals: this.perpetuals.publicKey,
|
7231
|
-
pool:
|
7232
|
-
|
7233
|
-
|
7234
|
-
|
7235
|
-
|
7236
|
-
|
7237
|
-
|
7238
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
7406
|
+
pool: this.getPoolKey(poolName),
|
7407
|
+
custody: this.getCustodyKey(poolName, tokenMint),
|
7408
|
+
custodyTokenAccount: this.getCustodyTokenAccountKey(poolName, tokenMint),
|
7409
|
+
custodyOracleAccount: this.useExtOracleAccount ? custodyConfig.extOracleAccount : custodyConfig.intOracleAccount,
|
7410
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7411
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7412
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
7239
7413
|
})
|
7240
|
-
.
|
7241
|
-
|
7242
|
-
|
7243
|
-
|
7244
|
-
|
7245
|
-
case
|
7246
|
-
|
7247
|
-
|
7248
|
-
throw err_56;
|
7249
|
-
case 4: return [2];
|
7414
|
+
.rpc()
|
7415
|
+
.catch(function (err) {
|
7416
|
+
console.error(err);
|
7417
|
+
throw err;
|
7418
|
+
})];
|
7419
|
+
case 1:
|
7420
|
+
_a.sent();
|
7421
|
+
return [2];
|
7250
7422
|
}
|
7251
7423
|
});
|
7252
7424
|
}); };
|
7253
7425
|
this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7254
|
-
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx,
|
7426
|
+
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_53;
|
7255
7427
|
return __generator(this, function (_a) {
|
7256
7428
|
switch (_a.label) {
|
7257
7429
|
case 0:
|
@@ -7283,9 +7455,9 @@ var PerpetualsClient = (function () {
|
|
7283
7455
|
instructions.push(withdrawFeesIx);
|
7284
7456
|
return [3, 5];
|
7285
7457
|
case 4:
|
7286
|
-
|
7287
|
-
console.log("perpClient setPool error:: ",
|
7288
|
-
throw
|
7458
|
+
err_53 = _a.sent();
|
7459
|
+
console.log("perpClient setPool error:: ", err_53);
|
7460
|
+
throw err_53;
|
7289
7461
|
case 5: return [2, {
|
7290
7462
|
instructions: __spreadArray([], instructions, true),
|
7291
7463
|
additionalSigners: additionalSigners
|
@@ -7294,7 +7466,7 @@ var PerpetualsClient = (function () {
|
|
7294
7466
|
});
|
7295
7467
|
}); };
|
7296
7468
|
this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7297
|
-
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx,
|
7469
|
+
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_54;
|
7298
7470
|
return __generator(this, function (_a) {
|
7299
7471
|
switch (_a.label) {
|
7300
7472
|
case 0:
|
@@ -7327,9 +7499,9 @@ var PerpetualsClient = (function () {
|
|
7327
7499
|
instructions.push(moveProtocolFeesIx);
|
7328
7500
|
return [3, 4];
|
7329
7501
|
case 3:
|
7330
|
-
|
7331
|
-
console.log("perpClient setPool error:: ",
|
7332
|
-
throw
|
7502
|
+
err_54 = _a.sent();
|
7503
|
+
console.log("perpClient setPool error:: ", err_54);
|
7504
|
+
throw err_54;
|
7333
7505
|
case 4: return [2, {
|
7334
7506
|
instructions: __spreadArray([], instructions, true),
|
7335
7507
|
additionalSigners: additionalSigners
|
@@ -7338,7 +7510,7 @@ var PerpetualsClient = (function () {
|
|
7338
7510
|
});
|
7339
7511
|
}); };
|
7340
7512
|
this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7341
|
-
var publicKey, setProtocolFeeShareBpsIx,
|
7513
|
+
var publicKey, setProtocolFeeShareBpsIx, err_55;
|
7342
7514
|
return __generator(this, function (_a) {
|
7343
7515
|
switch (_a.label) {
|
7344
7516
|
case 0:
|
@@ -7358,15 +7530,15 @@ var PerpetualsClient = (function () {
|
|
7358
7530
|
setProtocolFeeShareBpsIx = _a.sent();
|
7359
7531
|
return [2, setProtocolFeeShareBpsIx];
|
7360
7532
|
case 2:
|
7361
|
-
|
7362
|
-
console.log("perpClient setProtocolFeeShareBpsIx error:: ",
|
7363
|
-
throw
|
7533
|
+
err_55 = _a.sent();
|
7534
|
+
console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_55);
|
7535
|
+
throw err_55;
|
7364
7536
|
case 3: return [2];
|
7365
7537
|
}
|
7366
7538
|
});
|
7367
7539
|
}); };
|
7368
7540
|
this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
|
7369
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction,
|
7541
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_56;
|
7370
7542
|
return __generator(this, function (_a) {
|
7371
7543
|
switch (_a.label) {
|
7372
7544
|
case 0:
|
@@ -7393,9 +7565,9 @@ var PerpetualsClient = (function () {
|
|
7393
7565
|
instructions.push(setPermissionsInstruction);
|
7394
7566
|
return [3, 4];
|
7395
7567
|
case 3:
|
7396
|
-
|
7397
|
-
console.log("perpClient setPool error:: ",
|
7398
|
-
throw
|
7568
|
+
err_56 = _a.sent();
|
7569
|
+
console.log("perpClient setPool error:: ", err_56);
|
7570
|
+
throw err_56;
|
7399
7571
|
case 4: return [2, {
|
7400
7572
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7401
7573
|
additionalSigners: additionalSigners
|
@@ -7404,7 +7576,7 @@ var PerpetualsClient = (function () {
|
|
7404
7576
|
});
|
7405
7577
|
}); };
|
7406
7578
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7407
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e,
|
7579
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_57;
|
7408
7580
|
var _f;
|
7409
7581
|
return __generator(this, function (_g) {
|
7410
7582
|
switch (_g.label) {
|
@@ -7464,9 +7636,9 @@ var PerpetualsClient = (function () {
|
|
7464
7636
|
instructions.push(reimburse);
|
7465
7637
|
return [3, 5];
|
7466
7638
|
case 4:
|
7467
|
-
|
7468
|
-
console.log("perpClient setPool error:: ",
|
7469
|
-
throw
|
7639
|
+
err_57 = _g.sent();
|
7640
|
+
console.log("perpClient setPool error:: ", err_57);
|
7641
|
+
throw err_57;
|
7470
7642
|
case 5: return [2, {
|
7471
7643
|
instructions: __spreadArray([], instructions, true),
|
7472
7644
|
additionalSigners: additionalSigners
|
@@ -7475,7 +7647,7 @@ var PerpetualsClient = (function () {
|
|
7475
7647
|
});
|
7476
7648
|
}); };
|
7477
7649
|
this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7478
|
-
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice,
|
7650
|
+
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_58;
|
7479
7651
|
return __generator(this, function (_a) {
|
7480
7652
|
switch (_a.label) {
|
7481
7653
|
case 0:
|
@@ -7508,9 +7680,9 @@ var PerpetualsClient = (function () {
|
|
7508
7680
|
instructions.push(setInternalOraclePrice);
|
7509
7681
|
return [3, 4];
|
7510
7682
|
case 3:
|
7511
|
-
|
7512
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7513
|
-
throw
|
7683
|
+
err_58 = _a.sent();
|
7684
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_58);
|
7685
|
+
throw err_58;
|
7514
7686
|
case 4: return [2, {
|
7515
7687
|
instructions: __spreadArray([], instructions, true),
|
7516
7688
|
additionalSigners: additionalSigners
|
@@ -7519,7 +7691,7 @@ var PerpetualsClient = (function () {
|
|
7519
7691
|
});
|
7520
7692
|
}); };
|
7521
7693
|
this.setInternalOraclePriceBatch = function (tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7522
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
7694
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_59;
|
7523
7695
|
return __generator(this, function (_a) {
|
7524
7696
|
switch (_a.label) {
|
7525
7697
|
case 0:
|
@@ -7569,9 +7741,9 @@ var PerpetualsClient = (function () {
|
|
7569
7741
|
instructions.push(setInternalOraclePrice);
|
7570
7742
|
return [3, 4];
|
7571
7743
|
case 3:
|
7572
|
-
|
7573
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7574
|
-
throw
|
7744
|
+
err_59 = _a.sent();
|
7745
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_59);
|
7746
|
+
throw err_59;
|
7575
7747
|
case 4: return [2, {
|
7576
7748
|
instructions: __spreadArray([], instructions, true),
|
7577
7749
|
additionalSigners: additionalSigners
|
@@ -7580,7 +7752,7 @@ var PerpetualsClient = (function () {
|
|
7580
7752
|
});
|
7581
7753
|
}); };
|
7582
7754
|
this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7583
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
7755
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_60;
|
7584
7756
|
return __generator(this, function (_a) {
|
7585
7757
|
switch (_a.label) {
|
7586
7758
|
case 0:
|
@@ -7630,9 +7802,9 @@ var PerpetualsClient = (function () {
|
|
7630
7802
|
instructions.push(setInternalOraclePrice);
|
7631
7803
|
return [3, 4];
|
7632
7804
|
case 3:
|
7633
|
-
|
7634
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7635
|
-
throw
|
7805
|
+
err_60 = _a.sent();
|
7806
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_60);
|
7807
|
+
throw err_60;
|
7636
7808
|
case 4: return [2, {
|
7637
7809
|
instructions: __spreadArray([], instructions, true),
|
7638
7810
|
additionalSigners: additionalSigners
|
@@ -7640,467 +7812,344 @@ var PerpetualsClient = (function () {
|
|
7640
7812
|
}
|
7641
7813
|
});
|
7642
7814
|
}); };
|
7643
|
-
this.
|
7644
|
-
var
|
7645
|
-
|
7646
|
-
|
7647
|
-
|
7648
|
-
|
7649
|
-
|
7650
|
-
|
7651
|
-
|
7652
|
-
|
7653
|
-
|
7654
|
-
|
7655
|
-
|
7656
|
-
|
7657
|
-
|
7658
|
-
|
7659
|
-
|
7660
|
-
|
7661
|
-
|
7662
|
-
|
7663
|
-
|
7664
|
-
|
7665
|
-
|
7666
|
-
|
7667
|
-
|
7668
|
-
|
7669
|
-
|
7670
|
-
|
7671
|
-
|
7672
|
-
|
7673
|
-
|
7674
|
-
|
7675
|
-
|
7676
|
-
|
7677
|
-
|
7678
|
-
|
7679
|
-
|
7680
|
-
|
7681
|
-
|
7682
|
-
|
7683
|
-
|
7684
|
-
|
7685
|
-
|
7686
|
-
|
7687
|
-
|
7688
|
-
|
7689
|
-
|
7690
|
-
});
|
7691
|
-
}
|
7692
|
-
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
7693
|
-
case 1:
|
7694
|
-
if (!(_f.sent())) {
|
7695
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
7696
|
-
}
|
7697
|
-
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
7698
|
-
case 2:
|
7699
|
-
if (!(_f.sent())) {
|
7700
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
7701
|
-
}
|
7702
|
-
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
7703
|
-
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
7704
|
-
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
7705
|
-
if (!!skipBalanceChecks) return [3, 4];
|
7706
|
-
_e = anchor_1.BN.bind;
|
7707
|
-
return [4, this.provider.connection.getBalance(publicKey)];
|
7708
|
-
case 3:
|
7709
|
-
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
7710
|
-
if (unWrappedSolBalance.lt(lamports)) {
|
7711
|
-
throw "Insufficient SOL Funds";
|
7712
|
-
}
|
7713
|
-
_f.label = 4;
|
7714
|
-
case 4:
|
7715
|
-
if (!ephemeralSignerPubkey) {
|
7716
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
7717
|
-
additionalSigners.push(wrappedSolAccount);
|
7718
|
-
}
|
7719
|
-
preInstructions = [
|
7720
|
-
web3_js_1.SystemProgram.createAccount({
|
7721
|
-
fromPubkey: publicKey,
|
7722
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
7723
|
-
lamports: lamports.toNumber(),
|
7724
|
-
space: 165,
|
7725
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
7726
|
-
}),
|
7727
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
7728
|
-
];
|
7729
|
-
postInstructions = [
|
7730
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
7731
|
-
];
|
7732
|
-
return [3, 7];
|
7733
|
-
case 5:
|
7734
|
-
if (!!skipBalanceChecks) return [3, 7];
|
7735
|
-
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
7736
|
-
case 6:
|
7737
|
-
if (!(_f.sent())) {
|
7738
|
-
throw "Insufficient Funds , token Account doesn't exist";
|
7739
|
-
}
|
7740
|
-
_f.label = 7;
|
7741
|
-
case 7:
|
7742
|
-
_f.trys.push([7, 9, , 10]);
|
7743
|
-
return [4, this.program.methods
|
7744
|
-
.addCompoundingLiquidity({
|
7745
|
-
amountIn: amountIn,
|
7746
|
-
minCompoundingAmountOut: minCompoundingAmountOut
|
7747
|
-
})
|
7748
|
-
.accounts({
|
7749
|
-
owner: publicKey,
|
7750
|
-
fundingAccount: inTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : fundingAccount,
|
7751
|
-
compoundingTokenAccount: compoundingTokenAccount,
|
7752
|
-
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
7753
|
-
transferAuthority: poolConfig.transferAuthority,
|
7754
|
-
perpetuals: poolConfig.perpetuals,
|
7755
|
-
pool: poolConfig.poolAddress,
|
7756
|
-
inCustody: inCustodyConfig.custodyAccount,
|
7757
|
-
inCustodyOracleAccount: this.useExtOracleAccount ? inCustodyConfig.extOracleAccount : inCustodyConfig.intOracleAccount,
|
7758
|
-
inCustodyTokenAccount: inCustodyConfig.tokenAccount,
|
7759
|
-
rewardCustody: rewardCustody.custodyAccount,
|
7760
|
-
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
7761
|
-
lpTokenMint: lpTokenMint,
|
7762
|
-
compoundingTokenMint: compoundingTokenMint,
|
7763
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7764
|
-
eventAuthority: this.eventAuthority.publicKey,
|
7765
|
-
program: this.program.programId,
|
7766
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
7767
|
-
})
|
7768
|
-
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7769
|
-
.instruction()];
|
7770
|
-
case 8:
|
7771
|
-
addCompoundingLiquidity = _f.sent();
|
7772
|
-
instructions.push(addCompoundingLiquidity);
|
7773
|
-
return [3, 10];
|
7774
|
-
case 9:
|
7775
|
-
err_65 = _f.sent();
|
7776
|
-
console.log("perpClient addCompoundingLiquidity error:: ", err_65);
|
7777
|
-
return [3, 10];
|
7778
|
-
case 10: return [2, {
|
7779
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7780
|
-
additionalSigners: additionalSigners
|
7781
|
-
}];
|
7782
|
-
}
|
7783
|
-
});
|
7815
|
+
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7816
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_61;
|
7817
|
+
return __generator(this, function (_a) {
|
7818
|
+
switch (_a.label) {
|
7819
|
+
case 0:
|
7820
|
+
publicKey = this.provider.wallet.publicKey;
|
7821
|
+
instructions = [];
|
7822
|
+
additionalSigners = [];
|
7823
|
+
lpTokenMint = poolConfig.stakedLpTokenMint;
|
7824
|
+
lpMetadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), lpTokenMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
7825
|
+
_a.label = 1;
|
7826
|
+
case 1:
|
7827
|
+
_a.trys.push([1, 3, , 4]);
|
7828
|
+
return [4, this.program.methods
|
7829
|
+
.renameFlp({
|
7830
|
+
flag: flag,
|
7831
|
+
lpTokenName: lpTokenName,
|
7832
|
+
lpTokenSymbol: lpTokenSymbol,
|
7833
|
+
lpTokenUri: lpTokenUri,
|
7834
|
+
})
|
7835
|
+
.accounts({
|
7836
|
+
admin: publicKey,
|
7837
|
+
multisig: this.multisig.publicKey,
|
7838
|
+
transferAuthority: poolConfig.transferAuthority,
|
7839
|
+
perpetuals: poolConfig.perpetuals,
|
7840
|
+
pool: poolConfig.poolAddress,
|
7841
|
+
lpTokenMint: lpTokenMint,
|
7842
|
+
lpMetadataAccount: lpMetadataAccount,
|
7843
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7844
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7845
|
+
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
7846
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
7847
|
+
})
|
7848
|
+
.instruction()];
|
7849
|
+
case 2:
|
7850
|
+
renameFlp = _a.sent();
|
7851
|
+
instructions.push(renameFlp);
|
7852
|
+
return [3, 4];
|
7853
|
+
case 3:
|
7854
|
+
err_61 = _a.sent();
|
7855
|
+
console.log("perpClient renameFlp error:: ", err_61);
|
7856
|
+
return [3, 4];
|
7857
|
+
case 4: return [2, {
|
7858
|
+
instructions: __spreadArray([], instructions, true),
|
7859
|
+
additionalSigners: additionalSigners
|
7860
|
+
}];
|
7861
|
+
}
|
7784
7862
|
});
|
7785
|
-
};
|
7786
|
-
this.
|
7787
|
-
var
|
7788
|
-
|
7789
|
-
|
7790
|
-
|
7791
|
-
|
7792
|
-
|
7793
|
-
|
7794
|
-
|
7795
|
-
|
7796
|
-
|
7797
|
-
|
7798
|
-
|
7799
|
-
|
7800
|
-
|
7801
|
-
|
7802
|
-
|
7803
|
-
|
7804
|
-
|
7805
|
-
|
7806
|
-
|
7807
|
-
|
7808
|
-
|
7809
|
-
|
7810
|
-
|
7811
|
-
|
7812
|
-
|
7813
|
-
|
7814
|
-
|
7815
|
-
web3_js_1.SystemProgram.
|
7816
|
-
|
7817
|
-
|
7818
|
-
|
7819
|
-
|
7820
|
-
|
7821
|
-
|
7822
|
-
|
7823
|
-
|
7824
|
-
|
7825
|
-
|
7826
|
-
|
7827
|
-
|
7828
|
-
|
7829
|
-
|
7830
|
-
|
7831
|
-
|
7832
|
-
|
7833
|
-
|
7834
|
-
|
7835
|
-
|
7836
|
-
|
7837
|
-
|
7838
|
-
|
7839
|
-
|
7840
|
-
|
7841
|
-
|
7842
|
-
|
7843
|
-
|
7844
|
-
|
7845
|
-
|
7846
|
-
|
7847
|
-
|
7848
|
-
|
7849
|
-
|
7850
|
-
|
7851
|
-
|
7852
|
-
|
7853
|
-
|
7854
|
-
|
7855
|
-
|
7856
|
-
|
7857
|
-
|
7858
|
-
|
7859
|
-
|
7860
|
-
|
7861
|
-
|
7862
|
-
|
7863
|
-
|
7864
|
-
|
7865
|
-
|
7866
|
-
|
7867
|
-
|
7868
|
-
|
7869
|
-
|
7870
|
-
|
7871
|
-
|
7872
|
-
|
7873
|
-
|
7874
|
-
|
7875
|
-
|
7876
|
-
|
7877
|
-
|
7878
|
-
|
7879
|
-
|
7880
|
-
|
7881
|
-
|
7882
|
-
|
7883
|
-
|
7884
|
-
|
7885
|
-
|
7886
|
-
|
7887
|
-
|
7888
|
-
|
7889
|
-
compoundingTokenMint: compoundingTokenMint,
|
7890
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7891
|
-
eventAuthority: this.eventAuthority.publicKey,
|
7892
|
-
program: this.program.programId,
|
7893
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
7894
|
-
})
|
7895
|
-
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7896
|
-
.instruction()];
|
7897
|
-
case 6:
|
7898
|
-
removeCompoundingLiquidity = _f.sent();
|
7899
|
-
instructions.push(removeCompoundingLiquidity);
|
7900
|
-
return [3, 8];
|
7901
|
-
case 7:
|
7902
|
-
err_66 = _f.sent();
|
7903
|
-
console.log("perpClient removeCompoundingLiquidity error:: ", err_66);
|
7904
|
-
return [3, 8];
|
7905
|
-
case 8: return [2, {
|
7906
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7907
|
-
additionalSigners: additionalSigners
|
7908
|
-
}];
|
7909
|
-
}
|
7910
|
-
});
|
7863
|
+
}); };
|
7864
|
+
this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7865
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_62;
|
7866
|
+
return __generator(this, function (_a) {
|
7867
|
+
switch (_a.label) {
|
7868
|
+
case 0:
|
7869
|
+
publicKey = this.provider.wallet.publicKey;
|
7870
|
+
preInstructions = [];
|
7871
|
+
instructions = [];
|
7872
|
+
postInstructions = [];
|
7873
|
+
additionalSigners = [];
|
7874
|
+
_a.label = 1;
|
7875
|
+
case 1:
|
7876
|
+
_a.trys.push([1, 3, , 4]);
|
7877
|
+
lpTokenMint = poolConfig.stakedLpTokenMint;
|
7878
|
+
stakedLpTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
7879
|
+
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
7880
|
+
return [4, this.program.methods
|
7881
|
+
.initStaking({
|
7882
|
+
stakingFeeShareBps: stakingFeeShareBps
|
7883
|
+
})
|
7884
|
+
.accounts({
|
7885
|
+
admin: publicKey,
|
7886
|
+
multisig: this.multisig.publicKey,
|
7887
|
+
transferAuthority: poolConfig.transferAuthority,
|
7888
|
+
perpetuals: this.perpetuals.publicKey,
|
7889
|
+
pool: poolConfig.poolAddress,
|
7890
|
+
custody: rewardCustodyConfig.custodyAccount,
|
7891
|
+
lpTokenMint: lpTokenMint,
|
7892
|
+
stakedLpTokenAccount: stakedLpTokenAccount,
|
7893
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7894
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7895
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
7896
|
+
})
|
7897
|
+
.instruction()];
|
7898
|
+
case 2:
|
7899
|
+
initStakeInstruction = _a.sent();
|
7900
|
+
instructions.push(initStakeInstruction);
|
7901
|
+
return [3, 4];
|
7902
|
+
case 3:
|
7903
|
+
err_62 = _a.sent();
|
7904
|
+
console.log("perpClient InitStaking error:: ", err_62);
|
7905
|
+
throw err_62;
|
7906
|
+
case 4: return [2, {
|
7907
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7908
|
+
additionalSigners: additionalSigners
|
7909
|
+
}];
|
7910
|
+
}
|
7911
|
+
});
|
7912
|
+
}); };
|
7913
|
+
this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7914
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_63;
|
7915
|
+
return __generator(this, function (_a) {
|
7916
|
+
switch (_a.label) {
|
7917
|
+
case 0:
|
7918
|
+
publicKey = this.provider.wallet.publicKey;
|
7919
|
+
preInstructions = [];
|
7920
|
+
instructions = [];
|
7921
|
+
postInstructions = [];
|
7922
|
+
additionalSigners = [];
|
7923
|
+
_a.label = 1;
|
7924
|
+
case 1:
|
7925
|
+
_a.trys.push([1, 3, , 4]);
|
7926
|
+
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
7927
|
+
compoundingTokenMint = this.getPoolCompoundingTokenKey(poolConfig.poolName);
|
7928
|
+
compoundingVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("compounding_token_account"), poolConfig.poolAddress.toBuffer(), poolConfig.stakedLpTokenMint.toBuffer()], this.programId)[0];
|
7929
|
+
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), compoundingTokenMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
7930
|
+
return [4, this.program.methods
|
7931
|
+
.initCompounding({
|
7932
|
+
feeShareBps: feeShareBps,
|
7933
|
+
metadataTitle: metadataTitle,
|
7934
|
+
metadataSymbol: metadataSymbol,
|
7935
|
+
metadataUri: metadataUri
|
7936
|
+
})
|
7937
|
+
.accounts({
|
7938
|
+
admin: publicKey,
|
7939
|
+
multisig: this.multisig.publicKey,
|
7940
|
+
transferAuthority: poolConfig.transferAuthority,
|
7941
|
+
perpetuals: this.perpetuals.publicKey,
|
7942
|
+
pool: poolConfig.poolAddress,
|
7943
|
+
custody: rewardCustodyConfig.custodyAccount,
|
7944
|
+
lpTokenMint: poolConfig.stakedLpTokenMint,
|
7945
|
+
compoundingVault: compoundingVault,
|
7946
|
+
compoundingTokenMint: compoundingTokenMint,
|
7947
|
+
metadataAccount: metadataAccount,
|
7948
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
7949
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7950
|
+
metadataProgram: constants_1.METAPLEX_PROGRAM_ID,
|
7951
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
7952
|
+
})
|
7953
|
+
.instruction()];
|
7954
|
+
case 2:
|
7955
|
+
initCompoundingInstruction = _a.sent();
|
7956
|
+
instructions.push(initCompoundingInstruction);
|
7957
|
+
return [3, 4];
|
7958
|
+
case 3:
|
7959
|
+
err_63 = _a.sent();
|
7960
|
+
console.log("perpClient initCompounding error:: ", err_63);
|
7961
|
+
throw err_63;
|
7962
|
+
case 4: return [2, {
|
7963
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7964
|
+
additionalSigners: additionalSigners
|
7965
|
+
}];
|
7966
|
+
}
|
7911
7967
|
});
|
7912
|
-
};
|
7913
|
-
this.
|
7914
|
-
var
|
7915
|
-
|
7916
|
-
|
7917
|
-
|
7918
|
-
|
7919
|
-
|
7920
|
-
|
7921
|
-
|
7922
|
-
|
7923
|
-
|
7924
|
-
|
7925
|
-
|
7926
|
-
|
7927
|
-
|
7928
|
-
|
7929
|
-
|
7930
|
-
|
7931
|
-
|
7932
|
-
|
7933
|
-
|
7934
|
-
|
7935
|
-
|
7936
|
-
|
7937
|
-
|
7938
|
-
|
7939
|
-
|
7940
|
-
|
7941
|
-
|
7942
|
-
|
7943
|
-
|
7944
|
-
|
7945
|
-
|
7946
|
-
|
7947
|
-
|
7948
|
-
|
7949
|
-
|
7950
|
-
|
7951
|
-
|
7952
|
-
|
7953
|
-
|
7954
|
-
|
7955
|
-
|
7956
|
-
|
7957
|
-
|
7958
|
-
|
7959
|
-
|
7960
|
-
|
7961
|
-
|
7962
|
-
|
7963
|
-
markets = [];
|
7964
|
-
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
7965
|
-
custody = _d[_c];
|
7966
|
-
custodyAccountMetas.push({
|
7967
|
-
pubkey: custody.custodyAccount,
|
7968
|
-
isSigner: false,
|
7969
|
-
isWritable: false,
|
7970
|
-
});
|
7971
|
-
custodyOracleAccountMetas.push({
|
7972
|
-
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
7973
|
-
isSigner: false,
|
7974
|
-
isWritable: false,
|
7975
|
-
});
|
7976
|
-
}
|
7977
|
-
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
7978
|
-
market = _f[_e];
|
7979
|
-
markets.push({
|
7980
|
-
pubkey: market.marketAccount,
|
7981
|
-
isSigner: false,
|
7982
|
-
isWritable: false,
|
7983
|
-
});
|
7984
|
-
}
|
7985
|
-
_g.label = 5;
|
7986
|
-
case 5:
|
7987
|
-
_g.trys.push([5, 7, , 8]);
|
7988
|
-
return [4, this.program.methods
|
7989
|
-
.migrateStake({
|
7990
|
-
amount: amount
|
7991
|
-
})
|
7992
|
-
.accounts({
|
7993
|
-
owner: publicKey,
|
7994
|
-
compoundingTokenAccount: compoudingTokenAccount,
|
7995
|
-
transferAuthority: poolConfig.transferAuthority,
|
7996
|
-
perpetuals: poolConfig.perpetuals,
|
7997
|
-
pool: poolConfig.poolAddress,
|
7998
|
-
flpStakeAccount: flpStakeAccount,
|
7999
|
-
rewardCustody: rewardCustody.custodyAccount,
|
8000
|
-
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
8001
|
-
poolStakedLpVault: poolStakedLpVault,
|
8002
|
-
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
8003
|
-
lpTokenMint: lpTokenMint,
|
8004
|
-
compoundingTokenMint: compoundingTokenMint,
|
8005
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
8006
|
-
eventAuthority: this.eventAuthority.publicKey,
|
8007
|
-
program: this.program.programId,
|
8008
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
8009
|
-
})
|
8010
|
-
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
8011
|
-
.instruction()];
|
8012
|
-
case 6:
|
8013
|
-
migrateStake = _g.sent();
|
8014
|
-
instructions.push(migrateStake);
|
8015
|
-
return [3, 8];
|
8016
|
-
case 7:
|
8017
|
-
err_67 = _g.sent();
|
8018
|
-
console.log("perpClient migrateStake error:: ", err_67);
|
8019
|
-
return [3, 8];
|
8020
|
-
case 8: return [2, {
|
8021
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8022
|
-
additionalSigners: additionalSigners
|
8023
|
-
}];
|
8024
|
-
}
|
8025
|
-
});
|
7968
|
+
}); };
|
7969
|
+
this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7970
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_64;
|
7971
|
+
return __generator(this, function (_a) {
|
7972
|
+
switch (_a.label) {
|
7973
|
+
case 0:
|
7974
|
+
publicKey = this.provider.wallet.publicKey;
|
7975
|
+
preInstructions = [];
|
7976
|
+
instructions = [];
|
7977
|
+
postInstructions = [];
|
7978
|
+
additionalSigners = [];
|
7979
|
+
_a.label = 1;
|
7980
|
+
case 1:
|
7981
|
+
_a.trys.push([1, 3, , 4]);
|
7982
|
+
tokenMint = poolConfig.tokenMint;
|
7983
|
+
fundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, publicKey, true);
|
7984
|
+
return [4, this.program.methods
|
7985
|
+
.initTokenVault({
|
7986
|
+
tokenPermissions: token_permissions,
|
7987
|
+
amount: tokens_to_distribute,
|
7988
|
+
withdrawTimeLimit: withdrawTimeLimit,
|
7989
|
+
withdrawInstantFee: withdrawInstantFee,
|
7990
|
+
stakeLevel: stakeLevel,
|
7991
|
+
})
|
7992
|
+
.accounts({
|
7993
|
+
admin: publicKey,
|
7994
|
+
multisig: this.multisig.publicKey,
|
7995
|
+
perpetuals: this.perpetuals.publicKey,
|
7996
|
+
transferAuthority: poolConfig.transferAuthority,
|
7997
|
+
fundingTokenAccount: fundingTokenAccount,
|
7998
|
+
tokenMint: tokenMint,
|
7999
|
+
tokenVault: poolConfig.tokenVault,
|
8000
|
+
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
8001
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
8002
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
8003
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
8004
|
+
})
|
8005
|
+
.instruction()];
|
8006
|
+
case 2:
|
8007
|
+
initTokenVaultInstruction = _a.sent();
|
8008
|
+
instructions.push(initTokenVaultInstruction);
|
8009
|
+
return [3, 4];
|
8010
|
+
case 3:
|
8011
|
+
err_64 = _a.sent();
|
8012
|
+
console.log("perpClient InitTokenVaultInstruction error:: ", err_64);
|
8013
|
+
throw err_64;
|
8014
|
+
case 4: return [2, {
|
8015
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8016
|
+
additionalSigners: additionalSigners
|
8017
|
+
}];
|
8018
|
+
}
|
8026
8019
|
});
|
8027
|
-
};
|
8028
|
-
this.
|
8029
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners,
|
8030
|
-
return __generator(this, function (
|
8031
|
-
switch (
|
8020
|
+
}); };
|
8021
|
+
this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8022
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_65;
|
8023
|
+
return __generator(this, function (_a) {
|
8024
|
+
switch (_a.label) {
|
8025
|
+
case 0:
|
8026
|
+
publicKey = this.provider.wallet.publicKey;
|
8027
|
+
preInstructions = [];
|
8028
|
+
instructions = [];
|
8029
|
+
postInstructions = [];
|
8030
|
+
additionalSigners = [];
|
8031
|
+
_a.label = 1;
|
8032
|
+
case 1:
|
8033
|
+
_a.trys.push([1, 3, , 4]);
|
8034
|
+
return [4, this.program.methods
|
8035
|
+
.setTokenVaultConfig({
|
8036
|
+
tokenPermissions: token_permissions,
|
8037
|
+
withdrawTimeLimit: withdrawTimeLimit,
|
8038
|
+
withdrawInstantFee: withdrawInstantFee,
|
8039
|
+
stakeLevel: stakeLevel,
|
8040
|
+
})
|
8041
|
+
.accounts({
|
8042
|
+
admin: publicKey,
|
8043
|
+
multisig: this.multisig.publicKey,
|
8044
|
+
tokenVault: poolConfig.tokenVault,
|
8045
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
8046
|
+
})
|
8047
|
+
.instruction()];
|
8048
|
+
case 2:
|
8049
|
+
setTokenVaultConfigInstruction = _a.sent();
|
8050
|
+
instructions.push(setTokenVaultConfigInstruction);
|
8051
|
+
return [3, 4];
|
8052
|
+
case 3:
|
8053
|
+
err_65 = _a.sent();
|
8054
|
+
console.log("perpClient setTokenVaultConfigInstruction error:: ", err_65);
|
8055
|
+
throw err_65;
|
8056
|
+
case 4: return [2, {
|
8057
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8058
|
+
additionalSigners: additionalSigners
|
8059
|
+
}];
|
8060
|
+
}
|
8061
|
+
});
|
8062
|
+
}); };
|
8063
|
+
this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8064
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_66;
|
8065
|
+
return __generator(this, function (_a) {
|
8066
|
+
switch (_a.label) {
|
8067
|
+
case 0:
|
8068
|
+
publicKey = this.provider.wallet.publicKey;
|
8069
|
+
preInstructions = [];
|
8070
|
+
instructions = [];
|
8071
|
+
postInstructions = [];
|
8072
|
+
additionalSigners = [];
|
8073
|
+
_a.label = 1;
|
8074
|
+
case 1:
|
8075
|
+
_a.trys.push([1, 5, , 6]);
|
8076
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.tokenMint, publicKey, true)];
|
8077
|
+
case 2:
|
8078
|
+
receivingTokenAccount = _a.sent();
|
8079
|
+
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
8080
|
+
case 3:
|
8081
|
+
if (!(_a.sent())) {
|
8082
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, poolConfig.tokenMint));
|
8083
|
+
}
|
8084
|
+
return [4, this.program.methods
|
8085
|
+
.withdrawInstantFees({})
|
8086
|
+
.accounts({
|
8087
|
+
admin: publicKey,
|
8088
|
+
multisig: this.multisig.publicKey,
|
8089
|
+
perpetuals: this.perpetuals.publicKey,
|
8090
|
+
transferAuthority: poolConfig.transferAuthority,
|
8091
|
+
tokenVault: poolConfig.tokenVault,
|
8092
|
+
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
8093
|
+
receivingTokenAccount: receivingTokenAccount,
|
8094
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
8095
|
+
})
|
8096
|
+
.instruction()];
|
8097
|
+
case 4:
|
8098
|
+
withdrawInstantFeeInstruction = _a.sent();
|
8099
|
+
instructions.push(withdrawInstantFeeInstruction);
|
8100
|
+
return [3, 6];
|
8101
|
+
case 5:
|
8102
|
+
err_66 = _a.sent();
|
8103
|
+
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_66);
|
8104
|
+
throw err_66;
|
8105
|
+
case 6: return [2, {
|
8106
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8107
|
+
additionalSigners: additionalSigners
|
8108
|
+
}];
|
8109
|
+
}
|
8110
|
+
});
|
8111
|
+
}); };
|
8112
|
+
this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8113
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_67;
|
8114
|
+
return __generator(this, function (_a) {
|
8115
|
+
switch (_a.label) {
|
8032
8116
|
case 0:
|
8033
8117
|
publicKey = this.provider.wallet.publicKey;
|
8034
8118
|
preInstructions = [];
|
8035
8119
|
instructions = [];
|
8036
8120
|
postInstructions = [];
|
8037
8121
|
additionalSigners = [];
|
8038
|
-
|
8039
|
-
lpTokenMint = poolConfig.stakedLpTokenMint;
|
8040
|
-
compoundingTokenMint = poolConfig.compoundingTokenMint;
|
8041
|
-
compoudingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
8042
|
-
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
8043
|
-
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
8044
|
-
custodyAccountMetas = [];
|
8045
|
-
custodyOracleAccountMetas = [];
|
8046
|
-
markets = [];
|
8047
|
-
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
8048
|
-
custody = _a[_i];
|
8049
|
-
custodyAccountMetas.push({
|
8050
|
-
pubkey: custody.custodyAccount,
|
8051
|
-
isSigner: false,
|
8052
|
-
isWritable: false,
|
8053
|
-
});
|
8054
|
-
custodyOracleAccountMetas.push({
|
8055
|
-
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
8056
|
-
isSigner: false,
|
8057
|
-
isWritable: false,
|
8058
|
-
});
|
8059
|
-
}
|
8060
|
-
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
8061
|
-
market = _c[_b];
|
8062
|
-
markets.push({
|
8063
|
-
pubkey: market.marketAccount,
|
8064
|
-
isSigner: false,
|
8065
|
-
isWritable: false,
|
8066
|
-
});
|
8067
|
-
}
|
8068
|
-
_d.label = 1;
|
8122
|
+
_a.label = 1;
|
8069
8123
|
case 1:
|
8070
|
-
|
8124
|
+
_a.trys.push([1, 3, , 4]);
|
8125
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
8071
8126
|
return [4, this.program.methods
|
8072
|
-
.
|
8073
|
-
|
8127
|
+
.initRevenueTokenAccount({
|
8128
|
+
feeShareBps: feeShareBps
|
8074
8129
|
})
|
8075
8130
|
.accounts({
|
8076
|
-
|
8077
|
-
|
8131
|
+
admin: publicKey,
|
8132
|
+
multisig: this.multisig.publicKey,
|
8133
|
+
perpetuals: this.perpetuals.publicKey,
|
8078
8134
|
transferAuthority: poolConfig.transferAuthority,
|
8079
|
-
|
8080
|
-
|
8081
|
-
|
8082
|
-
|
8083
|
-
|
8084
|
-
poolStakedLpVault: poolStakedLpVault,
|
8085
|
-
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
8086
|
-
lpTokenMint: lpTokenMint,
|
8087
|
-
compoundingTokenMint: compoundingTokenMint,
|
8135
|
+
tokenVault: poolConfig.tokenVault,
|
8136
|
+
rewardMint: rewardCustodyMint,
|
8137
|
+
revenueTokenAccount: poolConfig.revenueTokenAccount,
|
8138
|
+
protocolVault: poolConfig.protocolVault,
|
8139
|
+
protocolTokenAccount: poolConfig.protocolTokenAccount,
|
8088
8140
|
systemProgram: web3_js_1.SystemProgram.programId,
|
8089
8141
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
8090
|
-
|
8091
|
-
program: this.program.programId,
|
8092
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
8142
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
8093
8143
|
})
|
8094
|
-
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
8095
8144
|
.instruction()];
|
8096
8145
|
case 2:
|
8097
|
-
|
8098
|
-
instructions.push(
|
8146
|
+
initRevenueTokenAccountInstruction = _a.sent();
|
8147
|
+
instructions.push(initRevenueTokenAccountInstruction);
|
8099
8148
|
return [3, 4];
|
8100
8149
|
case 3:
|
8101
|
-
|
8102
|
-
console.log("perpClient
|
8103
|
-
|
8150
|
+
err_67 = _a.sent();
|
8151
|
+
console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_67);
|
8152
|
+
throw err_67;
|
8104
8153
|
case 4: return [2, {
|
8105
8154
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8106
8155
|
additionalSigners: additionalSigners
|
@@ -8108,125 +8157,132 @@ var PerpetualsClient = (function () {
|
|
8108
8157
|
}
|
8109
8158
|
});
|
8110
8159
|
}); };
|
8111
|
-
this.
|
8112
|
-
var
|
8113
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
8114
|
-
args_1[_i - 1] = arguments[_i];
|
8115
|
-
}
|
8116
|
-
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
8117
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_69;
|
8118
|
-
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
8119
|
-
return __generator(this, function (_e) {
|
8120
|
-
switch (_e.label) {
|
8121
|
-
case 0:
|
8122
|
-
instructions = [];
|
8123
|
-
additionalSigners = [];
|
8124
|
-
rewardCustody = poolConfig.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
8125
|
-
lpTokenMint = poolConfig.stakedLpTokenMint;
|
8126
|
-
custodyAccountMetas = [];
|
8127
|
-
custodyOracleAccountMetas = [];
|
8128
|
-
markets = [];
|
8129
|
-
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
8130
|
-
custody = _b[_a];
|
8131
|
-
custodyAccountMetas.push({
|
8132
|
-
pubkey: custody.custodyAccount,
|
8133
|
-
isSigner: false,
|
8134
|
-
isWritable: false,
|
8135
|
-
});
|
8136
|
-
custodyOracleAccountMetas.push({
|
8137
|
-
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
8138
|
-
isSigner: false,
|
8139
|
-
isWritable: false,
|
8140
|
-
});
|
8141
|
-
}
|
8142
|
-
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
8143
|
-
market = _d[_c];
|
8144
|
-
markets.push({
|
8145
|
-
pubkey: market.marketAccount,
|
8146
|
-
isSigner: false,
|
8147
|
-
isWritable: false,
|
8148
|
-
});
|
8149
|
-
}
|
8150
|
-
_e.label = 1;
|
8151
|
-
case 1:
|
8152
|
-
_e.trys.push([1, 3, , 4]);
|
8153
|
-
return [4, this.program.methods
|
8154
|
-
.compoundFees({})
|
8155
|
-
.accounts({
|
8156
|
-
poolCompoundingLpVault: poolConfig.compoundingLpVault,
|
8157
|
-
transferAuthority: poolConfig.transferAuthority,
|
8158
|
-
perpetuals: poolConfig.perpetuals,
|
8159
|
-
pool: poolConfig.poolAddress,
|
8160
|
-
rewardCustody: rewardCustody.custodyAccount,
|
8161
|
-
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
8162
|
-
lpTokenMint: lpTokenMint,
|
8163
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
8164
|
-
eventAuthority: this.eventAuthority.publicKey,
|
8165
|
-
program: this.program.programId,
|
8166
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
8167
|
-
})
|
8168
|
-
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
8169
|
-
.instruction()];
|
8170
|
-
case 2:
|
8171
|
-
compoundingFee = _e.sent();
|
8172
|
-
instructions.push(compoundingFee);
|
8173
|
-
return [3, 4];
|
8174
|
-
case 3:
|
8175
|
-
err_69 = _e.sent();
|
8176
|
-
console.log("perpClient compoundingFee error:: ", err_69);
|
8177
|
-
return [3, 4];
|
8178
|
-
case 4: return [2, {
|
8179
|
-
instructions: __spreadArray([], instructions, true),
|
8180
|
-
additionalSigners: additionalSigners
|
8181
|
-
}];
|
8182
|
-
}
|
8183
|
-
});
|
8184
|
-
});
|
8185
|
-
};
|
8186
|
-
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8187
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_70;
|
8160
|
+
this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8161
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_68;
|
8188
8162
|
return __generator(this, function (_a) {
|
8189
8163
|
switch (_a.label) {
|
8190
8164
|
case 0:
|
8191
8165
|
publicKey = this.provider.wallet.publicKey;
|
8166
|
+
preInstructions = [];
|
8192
8167
|
instructions = [];
|
8168
|
+
postInstructions = [];
|
8193
8169
|
additionalSigners = [];
|
8194
|
-
lpTokenMint = poolConfig.stakedLpTokenMint;
|
8195
|
-
lpMetadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), lpTokenMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
8196
8170
|
_a.label = 1;
|
8197
8171
|
case 1:
|
8198
8172
|
_a.trys.push([1, 3, , 4]);
|
8173
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
8174
|
+
fundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.tokenMint, publicKey, true);
|
8175
|
+
revenueFundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
8199
8176
|
return [4, this.program.methods
|
8200
|
-
.
|
8201
|
-
|
8202
|
-
|
8203
|
-
lpTokenSymbol: lpTokenSymbol,
|
8204
|
-
lpTokenUri: lpTokenUri,
|
8177
|
+
.distributeTokenReward({
|
8178
|
+
amount: amount,
|
8179
|
+
epochCount: epochCount,
|
8205
8180
|
})
|
8206
8181
|
.accounts({
|
8207
8182
|
admin: publicKey,
|
8208
8183
|
multisig: this.multisig.publicKey,
|
8184
|
+
perpetuals: this.perpetuals.publicKey,
|
8209
8185
|
transferAuthority: poolConfig.transferAuthority,
|
8210
|
-
|
8211
|
-
|
8212
|
-
|
8213
|
-
lpMetadataAccount: lpMetadataAccount,
|
8214
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
8186
|
+
fundingTokenAccount: fundingTokenAccount,
|
8187
|
+
tokenVault: poolConfig.tokenVault,
|
8188
|
+
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
8215
8189
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
8216
|
-
|
8217
|
-
|
8190
|
+
eventAuthority: this.eventAuthority.publicKey,
|
8191
|
+
program: this.programId
|
8218
8192
|
})
|
8219
8193
|
.instruction()];
|
8220
8194
|
case 2:
|
8221
|
-
|
8222
|
-
instructions.push(
|
8195
|
+
distributeTokenRewardInstruction = _a.sent();
|
8196
|
+
instructions.push(distributeTokenRewardInstruction);
|
8223
8197
|
return [3, 4];
|
8224
8198
|
case 3:
|
8225
|
-
|
8226
|
-
console.log("perpClient
|
8199
|
+
err_68 = _a.sent();
|
8200
|
+
console.log("perpClient distributeTokenRewardInstruction error:: ", err_68);
|
8201
|
+
throw err_68;
|
8202
|
+
case 4: return [2, {
|
8203
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8204
|
+
additionalSigners: additionalSigners
|
8205
|
+
}];
|
8206
|
+
}
|
8207
|
+
});
|
8208
|
+
}); };
|
8209
|
+
this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
|
8210
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_69;
|
8211
|
+
return __generator(this, function (_a) {
|
8212
|
+
switch (_a.label) {
|
8213
|
+
case 0:
|
8214
|
+
publicKey = this.provider.wallet.publicKey;
|
8215
|
+
preInstructions = [];
|
8216
|
+
instructions = [];
|
8217
|
+
postInstructions = [];
|
8218
|
+
additionalSigners = [];
|
8219
|
+
_a.label = 1;
|
8220
|
+
case 1:
|
8221
|
+
_a.trys.push([1, 3, , 4]);
|
8222
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
8223
|
+
return [4, this.program.methods
|
8224
|
+
.setTokenStakeLevel({
|
8225
|
+
level: stakeLevel,
|
8226
|
+
})
|
8227
|
+
.accounts({
|
8228
|
+
admin: publicKey,
|
8229
|
+
multisig: this.multisig.publicKey,
|
8230
|
+
tokenStakeAccount: tokenStakeAccount,
|
8231
|
+
})
|
8232
|
+
.instruction()];
|
8233
|
+
case 2:
|
8234
|
+
setTokenStakeLevelInstruction = _a.sent();
|
8235
|
+
instructions.push(setTokenStakeLevelInstruction);
|
8227
8236
|
return [3, 4];
|
8237
|
+
case 3:
|
8238
|
+
err_69 = _a.sent();
|
8239
|
+
console.log("perpClient setTokenStakeLevelInstruction error:: ", err_69);
|
8240
|
+
throw err_69;
|
8228
8241
|
case 4: return [2, {
|
8229
|
-
instructions: __spreadArray([], instructions, true),
|
8242
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8243
|
+
additionalSigners: additionalSigners
|
8244
|
+
}];
|
8245
|
+
}
|
8246
|
+
});
|
8247
|
+
}); };
|
8248
|
+
this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8249
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_70;
|
8250
|
+
return __generator(this, function (_a) {
|
8251
|
+
switch (_a.label) {
|
8252
|
+
case 0:
|
8253
|
+
publicKey = this.provider.wallet.publicKey;
|
8254
|
+
preInstructions = [];
|
8255
|
+
instructions = [];
|
8256
|
+
postInstructions = [];
|
8257
|
+
additionalSigners = [];
|
8258
|
+
_a.label = 1;
|
8259
|
+
case 1:
|
8260
|
+
_a.trys.push([1, 3, , 4]);
|
8261
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), owner.toBuffer()], this.programId)[0];
|
8262
|
+
return [4, this.program.methods
|
8263
|
+
.setTokenReward({
|
8264
|
+
amount: amount,
|
8265
|
+
epochCount: epochCount,
|
8266
|
+
})
|
8267
|
+
.accounts({
|
8268
|
+
admin: publicKey,
|
8269
|
+
multisig: this.multisig.publicKey,
|
8270
|
+
tokenVault: poolConfig.tokenVault,
|
8271
|
+
tokenStakeAccount: tokenStakeAccount,
|
8272
|
+
eventAuthority: this.eventAuthority.publicKey,
|
8273
|
+
program: this.programId
|
8274
|
+
})
|
8275
|
+
.instruction()];
|
8276
|
+
case 2:
|
8277
|
+
setTokenRewardInstruction = _a.sent();
|
8278
|
+
instructions.push(setTokenRewardInstruction);
|
8279
|
+
return [3, 4];
|
8280
|
+
case 3:
|
8281
|
+
err_70 = _a.sent();
|
8282
|
+
console.log("perpClient setTokenRewardInstruction error:: ", err_70);
|
8283
|
+
throw err_70;
|
8284
|
+
case 4: return [2, {
|
8285
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8230
8286
|
additionalSigners: additionalSigners
|
8231
8287
|
}];
|
8232
8288
|
}
|