flash-sdk 12.0.3-alpha.0 → 12.0.3
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 +33 -7
- package/dist/PerpetualsClient.js +379 -25
- package/dist/PoolConfig.json +18 -18
- package/dist/backupOracle.js +23 -2
- package/dist/idl/perpetuals.d.ts +54 -211
- package/dist/idl/perpetuals.json +58 -215
- package/dist/remoraTokensWithPriceIds.js +5 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { Program, AnchorProvider, BN } from "@coral-xyz/anchor";
|
|
|
2
2
|
import { PublicKey, TransactionInstruction, Commitment, Signer, AddressLookupTableAccount, VersionedTransaction } from "@solana/web3.js";
|
|
3
3
|
import { PoolAccount } from "./PoolAccount";
|
|
4
4
|
import { PositionAccount } from "./PositionAccount";
|
|
5
|
-
import { AddLiquidityAmountAndFee, InternalPrice, BorrowRateParams, ExitPriceAndFee, Fees, OracleParams, Permissions, PricingParams, RemoveCollateralData, RemoveLiquidityAmountAndFee, Side, TokenRatios, MinAndMaxPrice, FeesAction, ContractOraclePrice, Privilege, PerpetualsAccount, EntryPriceAndFeeV2, TokenPermissions, TokenStake, InternalEmaPrice, Whitelist } from "./types";
|
|
5
|
+
import { AddLiquidityAmountAndFee, InternalPrice, BorrowRateParams, ExitPriceAndFee, Fees, OracleParams, Permissions, PricingParams, RemoveCollateralData, RemoveLiquidityAmountAndFee, Side, TokenRatios, MinAndMaxPrice, FeesAction, ContractOraclePrice, Privilege, PerpetualsAccount, EntryPriceAndFeeV2, TokenPermissions, TokenStake, InternalEmaPrice, Whitelist, VoltageMultiplier, MarketPermissions } from "./types";
|
|
6
6
|
import { OraclePrice } from "./OraclePrice";
|
|
7
7
|
import { CustodyAccount } from "./CustodyAccount";
|
|
8
8
|
import type { Perpetuals } from './idl/perpetuals';
|
|
@@ -21,8 +21,6 @@ export interface PositionMetrics {
|
|
|
21
21
|
profitUsd: BN;
|
|
22
22
|
lossUsd: BN;
|
|
23
23
|
priceImpactUsd: BN;
|
|
24
|
-
maxPriceImpactUsd: BN;
|
|
25
|
-
netProfitUsd: BN;
|
|
26
24
|
};
|
|
27
25
|
leverage: BN;
|
|
28
26
|
liquidationPrice: OraclePrice;
|
|
@@ -693,15 +691,11 @@ export declare class PerpetualsClient {
|
|
|
693
691
|
profitUsd: BN;
|
|
694
692
|
lossUsd: BN;
|
|
695
693
|
priceImpactUsd: BN;
|
|
696
|
-
maxPriceImpactUsd: BN;
|
|
697
|
-
netProfitUsd: BN;
|
|
698
694
|
};
|
|
699
695
|
getPnlContractHelper: (positionAccount: PositionAccount, targetTokenPrice: OraclePrice, targetTokenEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN, delay: BN, poolConfig: PoolConfig) => {
|
|
700
696
|
profitUsd: BN;
|
|
701
697
|
lossUsd: BN;
|
|
702
698
|
priceImpactUsd: BN;
|
|
703
|
-
maxPriceImpactUsd: BN;
|
|
704
|
-
netProfitUsd: BN;
|
|
705
699
|
};
|
|
706
700
|
getPositionMetrics: (positionAccount: PositionAccount, targetTokenPrice: OraclePrice, targetTokenEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN, poolConfig: PoolConfig) => PositionMetrics;
|
|
707
701
|
getPositionsMetricsBatch: (positions: Array<{
|
|
@@ -1049,4 +1043,36 @@ export declare class PerpetualsClient {
|
|
|
1049
1043
|
instructions: TransactionInstruction[];
|
|
1050
1044
|
additionalSigners: Signer[];
|
|
1051
1045
|
}>;
|
|
1046
|
+
setPerpetualsConfig: (allowUngatedTrading: boolean, voltageMultiplier: VoltageMultiplier, tradingDiscount: BN[], referralRebate: BN[], defaultRebate: BN, tradeLimit: number, triggerOrderLimit: number, rebateLimitUsd: number) => Promise<{
|
|
1047
|
+
instructions: TransactionInstruction[];
|
|
1048
|
+
additionalSigners: Signer[];
|
|
1049
|
+
}>;
|
|
1050
|
+
setPoolConfig: (name: string, permissions: Permissions, maxAumUsd: BN, oracleAuthority: PublicKey, stakingFeeShareBps: BN, vpVolumeFactor: number, stakingFeeBoostBps: BN[], minLpPriceUsd: BN, maxLpPriceUsd: BN, thresholdUsd: BN) => Promise<{
|
|
1051
|
+
instructions: TransactionInstruction[];
|
|
1052
|
+
additionalSigners: Signer[];
|
|
1053
|
+
}>;
|
|
1054
|
+
addCustodyToken22: (poolName: string, tokenMint: PublicKey, tokenAccountSpace: BN, token22: boolean) => Promise<{
|
|
1055
|
+
instructions: TransactionInstruction[];
|
|
1056
|
+
additionalSigners: Signer[];
|
|
1057
|
+
}>;
|
|
1058
|
+
addMarket: (poolName: string, targetCustody: PublicKey, collateralCustody: PublicKey, side: Side, correlation: boolean, maxPayoffBps: BN, permissions: MarketPermissions) => Promise<{
|
|
1059
|
+
instructions: TransactionInstruction[];
|
|
1060
|
+
additionalSigners: Signer[];
|
|
1061
|
+
}>;
|
|
1062
|
+
setCustody: (poolName: string, tokenMint: PublicKey, depegAdjustment: boolean, inversePrice: boolean, oracle: OracleParams, pricingConfig: PricingParams, permissions: Permissions, fees: Fees, borrowRate: BorrowRateParams, ratios: TokenRatios[], rewardThreshold: BN, minReserveUsd: BN, limitPriceBufferBps: BN, token22: boolean) => Promise<{
|
|
1063
|
+
instructions: TransactionInstruction[];
|
|
1064
|
+
additionalSigners: Signer[];
|
|
1065
|
+
}>;
|
|
1066
|
+
addInternalOracle: (exponent: number, tokenMint: PublicKey, intOracleAccount: PublicKey, extOracleAccount: PublicKey) => Promise<{
|
|
1067
|
+
instructions: TransactionInstruction[];
|
|
1068
|
+
additionalSigners: Signer[];
|
|
1069
|
+
}>;
|
|
1070
|
+
setMarket: (poolName: string, targetCustody: PublicKey, collateralCustody: PublicKey, marketAccount: PublicKey, maxPayoffBps: BN, permissions: MarketPermissions, correlation: boolean) => Promise<{
|
|
1071
|
+
instructions: TransactionInstruction[];
|
|
1072
|
+
additionalSigners: Signer[];
|
|
1073
|
+
}>;
|
|
1074
|
+
removeMarket: (poolName: string, market: PublicKey, targetMint: PublicKey, collateralMint: PublicKey) => Promise<{
|
|
1075
|
+
instructions: TransactionInstruction[];
|
|
1076
|
+
additionalSigners: Signer[];
|
|
1077
|
+
}>;
|
|
1052
1078
|
}
|
package/dist/PerpetualsClient.js
CHANGED
|
@@ -683,7 +683,7 @@ var PerpetualsClient = (function () {
|
|
|
683
683
|
currentMarginUsd = positionAccount.collateralUsd.sub(lossUsd);
|
|
684
684
|
}
|
|
685
685
|
else {
|
|
686
|
-
currentMarginUsd = positionAccount.collateralUsd.add(pnl.
|
|
686
|
+
currentMarginUsd = positionAccount.collateralUsd.add(pnl.profitUsd).sub(lossUsd);
|
|
687
687
|
}
|
|
688
688
|
if (currentMarginUsd.gt(constants_1.BN_ZERO)) {
|
|
689
689
|
return positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(currentMarginUsd);
|
|
@@ -1028,6 +1028,7 @@ var PerpetualsClient = (function () {
|
|
|
1028
1028
|
positionDelta.collateralUsd = (positionAccount.collateralUsd.mul(closeRatio)).div(decimalPower);
|
|
1029
1029
|
positionDelta.unsettledFeesUsd = (positionAccount.unsettledFeesUsd.mul(closeRatio)).div(decimalPower);
|
|
1030
1030
|
positionDelta.degenSizeUsd = positionAccount.degenSizeUsd.mul(closeRatio).div(decimalPower);
|
|
1031
|
+
positionDelta.priceImpactUsd = (positionAccount.priceImpactUsd.mul(closeRatio)).div(decimalPower);
|
|
1031
1032
|
var newPnl = _this.getPnlSync(positionDelta, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
|
1032
1033
|
var exitFeeUsd = positionDelta.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
1033
1034
|
if (discountBps.gt(constants_1.BN_ZERO)) {
|
|
@@ -1037,8 +1038,9 @@ var PerpetualsClient = (function () {
|
|
|
1037
1038
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionDelta, collateralCustodyAccount, currentTimestamp);
|
|
1038
1039
|
var totalFeesUsd = (exitFeeUsd.add(lockAndUnsettledFeeUsd));
|
|
1039
1040
|
var currentCollateralUsd = positionDelta.collateralUsd;
|
|
1040
|
-
var
|
|
1041
|
-
var
|
|
1041
|
+
var lossLiabilityUsd = newPnl.lossUsd.add(positionDelta.priceImpactUsd);
|
|
1042
|
+
var liabilityUsd = lossLiabilityUsd.add(totalFeesUsd);
|
|
1043
|
+
var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(currentCollateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionDelta.lockedAmount, collateralCustodyAccount.decimals));
|
|
1042
1044
|
if (debugLogs) {
|
|
1043
1045
|
console.log("assetsUsd.sub(liabilityUsd):", collateralCustodyAccount.decimals, assetsUsd.toString(), liabilityUsd.toString(), assetsUsd.sub(liabilityUsd).toString());
|
|
1044
1046
|
}
|
|
@@ -1066,6 +1068,7 @@ var PerpetualsClient = (function () {
|
|
|
1066
1068
|
newPosition.collateralUsd = positionAccount.collateralUsd.sub(positionDelta.collateralUsd);
|
|
1067
1069
|
newPosition.unsettledFeesUsd = positionAccount.unsettledFeesUsd.sub(positionDelta.unsettledFeesUsd);
|
|
1068
1070
|
newPosition.degenSizeUsd = positionAccount.degenSizeUsd.sub(positionDelta.degenSizeUsd);
|
|
1071
|
+
newPosition.priceImpactUsd = positionAccount.priceImpactUsd.sub(positionDelta.priceImpactUsd);
|
|
1069
1072
|
newPosition.collateralUsd = newPosition.collateralUsd.add(closeAmountUsd);
|
|
1070
1073
|
var feeUsdWithDiscount = constants_1.BN_ZERO;
|
|
1071
1074
|
var feeUsd = sizeDeltaUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
@@ -1133,7 +1136,8 @@ var PerpetualsClient = (function () {
|
|
|
1133
1136
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1134
1137
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
1135
1138
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
|
1136
|
-
var
|
|
1139
|
+
var lossLiabilityUsd = profitLoss.lossUsd.add(positionAccount.priceImpactUsd);
|
|
1140
|
+
var lossUsd = lossLiabilityUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
|
1137
1141
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
|
1138
1142
|
if (profitLoss.lossUsd.lt(positionAccount.collateralUsd)) {
|
|
1139
1143
|
availableInitMarginUsd = positionAccount.collateralUsd.sub(lossUsd);
|
|
@@ -1175,8 +1179,9 @@ var PerpetualsClient = (function () {
|
|
|
1175
1179
|
var collateralAmount = collateralPrice.getTokenAmount(positionAccount.collateralUsd, collateralCustodyAccount.decimals);
|
|
1176
1180
|
var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
|
|
1177
1181
|
var totalFeesUsd = (exitPriceAndFee.exitFeeUsd.add(exitPriceAndFee.borrowFeeUsd));
|
|
1178
|
-
var
|
|
1179
|
-
var
|
|
1182
|
+
var lossLiabilityUsd = newPnl.lossUsd.add(positionAccount.priceImpactUsd);
|
|
1183
|
+
var liabilityUsd = lossLiabilityUsd.add(totalFeesUsd);
|
|
1184
|
+
var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(positionAccount.collateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionAccount.lockedAmount, collateralCustodyAccount.decimals));
|
|
1180
1185
|
var closeAmountUsd, feesAmountUsd;
|
|
1181
1186
|
if (assetsUsd.gt(liabilityUsd)) {
|
|
1182
1187
|
closeAmountUsd = assetsUsd.sub(liabilityUsd);
|
|
@@ -1230,7 +1235,8 @@ var PerpetualsClient = (function () {
|
|
|
1230
1235
|
var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
|
|
1231
1236
|
var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
|
1232
1237
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
|
|
1233
|
-
var
|
|
1238
|
+
var lossLiabilityUsd = profitLoss.lossUsd.add(positionAccount.priceImpactUsd);
|
|
1239
|
+
var lossUsd = lossLiabilityUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
|
|
1234
1240
|
var currentCollateralUsd = positionAccount.collateralUsd;
|
|
1235
1241
|
var availableInitMarginUsd = constants_1.BN_ZERO;
|
|
1236
1242
|
if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
|
|
@@ -1593,8 +1599,6 @@ var PerpetualsClient = (function () {
|
|
|
1593
1599
|
profitUsd: constants_1.BN_ZERO,
|
|
1594
1600
|
lossUsd: constants_1.BN_ZERO,
|
|
1595
1601
|
priceImpactUsd: constants_1.BN_ZERO,
|
|
1596
|
-
maxPriceImpactUsd: constants_1.BN_ZERO,
|
|
1597
|
-
netProfitUsd: constants_1.BN_ZERO
|
|
1598
1602
|
};
|
|
1599
1603
|
}
|
|
1600
1604
|
var side = poolConfig.getMarketConfigByPk(positionAccount.market).side;
|
|
@@ -1658,28 +1662,20 @@ var PerpetualsClient = (function () {
|
|
|
1658
1662
|
if (!priceDiffProfit.exponent.eq(priceDiffLoss.exponent)) {
|
|
1659
1663
|
throw new Error("exponent mistach");
|
|
1660
1664
|
}
|
|
1661
|
-
var maxPriceImpactUsd = positionAccount.priceImpactUsd;
|
|
1662
1665
|
if (priceDiffProfit.price.gt(constants_1.BN_ZERO)) {
|
|
1663
1666
|
var grossProfitUsd = priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals);
|
|
1664
|
-
var priceImpactUsd = positionAccount.priceImpactUsd.gt(constants_1.BN_ZERO)
|
|
1665
|
-
? anchor_1.BN.min(positionAccount.priceImpactUsd, grossProfitUsd)
|
|
1666
|
-
: constants_1.BN_ZERO;
|
|
1667
|
-
var netProfitUsd = grossProfitUsd.sub(priceImpactUsd);
|
|
1668
1667
|
return {
|
|
1669
1668
|
profitUsd: grossProfitUsd,
|
|
1670
1669
|
lossUsd: constants_1.BN_ZERO,
|
|
1671
|
-
priceImpactUsd: priceImpactUsd,
|
|
1672
|
-
maxPriceImpactUsd: maxPriceImpactUsd,
|
|
1673
|
-
netProfitUsd: netProfitUsd,
|
|
1670
|
+
priceImpactUsd: positionAccount.priceImpactUsd,
|
|
1674
1671
|
};
|
|
1675
1672
|
}
|
|
1676
1673
|
else {
|
|
1674
|
+
var grossLossUsd = priceDiffLoss.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals);
|
|
1677
1675
|
return {
|
|
1678
1676
|
profitUsd: constants_1.BN_ZERO,
|
|
1679
|
-
lossUsd:
|
|
1680
|
-
priceImpactUsd:
|
|
1681
|
-
maxPriceImpactUsd: maxPriceImpactUsd,
|
|
1682
|
-
netProfitUsd: constants_1.BN_ZERO,
|
|
1677
|
+
lossUsd: grossLossUsd,
|
|
1678
|
+
priceImpactUsd: positionAccount.priceImpactUsd,
|
|
1683
1679
|
};
|
|
1684
1680
|
}
|
|
1685
1681
|
};
|
|
@@ -1692,7 +1688,7 @@ var PerpetualsClient = (function () {
|
|
|
1692
1688
|
timestamp: constants_1.BN_ZERO
|
|
1693
1689
|
});
|
|
1694
1690
|
return {
|
|
1695
|
-
pnl: { profitUsd: constants_1.BN_ZERO, lossUsd: constants_1.BN_ZERO, priceImpactUsd: constants_1.BN_ZERO
|
|
1691
|
+
pnl: { profitUsd: constants_1.BN_ZERO, lossUsd: constants_1.BN_ZERO, priceImpactUsd: constants_1.BN_ZERO },
|
|
1696
1692
|
leverage: constants_1.BN_ZERO,
|
|
1697
1693
|
liquidationPrice: zeroOraclePrice,
|
|
1698
1694
|
fees: { exitFeeUsd: constants_1.BN_ZERO, exitFeeAmount: constants_1.BN_ZERO, lockAndUnsettledFeeUsd: constants_1.BN_ZERO }
|
|
@@ -1717,13 +1713,11 @@ var PerpetualsClient = (function () {
|
|
|
1717
1713
|
profitUsd: pnlResult.profitUsd,
|
|
1718
1714
|
lossUsd: pnlResult.lossUsd,
|
|
1719
1715
|
priceImpactUsd: pnlResult.priceImpactUsd,
|
|
1720
|
-
maxPriceImpactUsd: pnlResult.maxPriceImpactUsd,
|
|
1721
|
-
netProfitUsd: pnlResult.netProfitUsd
|
|
1722
1716
|
};
|
|
1723
1717
|
var liquidationPrice = _this.getLiquidationPriceContractHelper(entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount);
|
|
1724
1718
|
var unsettledFeesUsd = exitFeeUsd.add(lockAndUnsettledFeeUsd);
|
|
1725
1719
|
var lossUsd = pnl.lossUsd.add(unsettledFeesUsd);
|
|
1726
|
-
var currentMarginUsd = positionAccount.collateralUsd.add(pnl.
|
|
1720
|
+
var currentMarginUsd = positionAccount.collateralUsd.add(pnl.profitUsd).sub(lossUsd);
|
|
1727
1721
|
var leverage;
|
|
1728
1722
|
if (currentMarginUsd.gt(constants_1.BN_ZERO)) {
|
|
1729
1723
|
leverage = positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(currentMarginUsd);
|
|
@@ -8248,6 +8242,366 @@ var PerpetualsClient = (function () {
|
|
|
8248
8242
|
}
|
|
8249
8243
|
});
|
|
8250
8244
|
}); };
|
|
8245
|
+
this.setPerpetualsConfig = function (allowUngatedTrading, voltageMultiplier, tradingDiscount, referralRebate, defaultRebate, tradeLimit, triggerOrderLimit, rebateLimitUsd) { return __awaiter(_this, void 0, void 0, function () {
|
|
8246
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPerpetualsConfigInstruction, err_68;
|
|
8247
|
+
return __generator(this, function (_a) {
|
|
8248
|
+
switch (_a.label) {
|
|
8249
|
+
case 0:
|
|
8250
|
+
publicKey = this.provider.wallet.publicKey;
|
|
8251
|
+
preInstructions = [];
|
|
8252
|
+
instructions = [];
|
|
8253
|
+
postInstructions = [];
|
|
8254
|
+
additionalSigners = [];
|
|
8255
|
+
_a.label = 1;
|
|
8256
|
+
case 1:
|
|
8257
|
+
_a.trys.push([1, 3, , 4]);
|
|
8258
|
+
return [4, this.program.methods
|
|
8259
|
+
.setPerpetualsConfig({
|
|
8260
|
+
allowUngatedTrading: allowUngatedTrading,
|
|
8261
|
+
tradingDiscount: tradingDiscount,
|
|
8262
|
+
referralRebate: referralRebate,
|
|
8263
|
+
defaultRebate: defaultRebate,
|
|
8264
|
+
voltageMultiplier: voltageMultiplier,
|
|
8265
|
+
tradeLimit: tradeLimit,
|
|
8266
|
+
triggerOrderLimit: triggerOrderLimit,
|
|
8267
|
+
rebateLimitUsd: rebateLimitUsd,
|
|
8268
|
+
})
|
|
8269
|
+
.accountsPartial({
|
|
8270
|
+
admin: publicKey,
|
|
8271
|
+
multisig: this.multisig.publicKey,
|
|
8272
|
+
perpetuals: this.perpetuals.publicKey,
|
|
8273
|
+
})
|
|
8274
|
+
.instruction()];
|
|
8275
|
+
case 2:
|
|
8276
|
+
setPerpetualsConfigInstruction = _a.sent();
|
|
8277
|
+
instructions.push(setPerpetualsConfigInstruction);
|
|
8278
|
+
return [3, 4];
|
|
8279
|
+
case 3:
|
|
8280
|
+
err_68 = _a.sent();
|
|
8281
|
+
console.log("perpClient setPerpetualsConfigInstruction error:: ", err_68);
|
|
8282
|
+
throw err_68;
|
|
8283
|
+
case 4: return [2, {
|
|
8284
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8285
|
+
additionalSigners: additionalSigners
|
|
8286
|
+
}];
|
|
8287
|
+
}
|
|
8288
|
+
});
|
|
8289
|
+
}); };
|
|
8290
|
+
this.setPoolConfig = function (name, permissions, maxAumUsd, oracleAuthority, stakingFeeShareBps, vpVolumeFactor, stakingFeeBoostBps, minLpPriceUsd, maxLpPriceUsd, thresholdUsd) { return __awaiter(_this, void 0, void 0, function () {
|
|
8291
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPoolConfigInstruction, err_69;
|
|
8292
|
+
return __generator(this, function (_a) {
|
|
8293
|
+
switch (_a.label) {
|
|
8294
|
+
case 0:
|
|
8295
|
+
publicKey = this.provider.wallet.publicKey;
|
|
8296
|
+
preInstructions = [];
|
|
8297
|
+
instructions = [];
|
|
8298
|
+
postInstructions = [];
|
|
8299
|
+
additionalSigners = [];
|
|
8300
|
+
_a.label = 1;
|
|
8301
|
+
case 1:
|
|
8302
|
+
_a.trys.push([1, 3, , 4]);
|
|
8303
|
+
console.log(vpVolumeFactor);
|
|
8304
|
+
return [4, this.program.methods
|
|
8305
|
+
.setPoolConfig({ permissions: permissions, oracleAuthority: oracleAuthority, maxAumUsd: maxAumUsd, stakingFeeShareBps: stakingFeeShareBps, vpVolumeFactor: vpVolumeFactor, stakingFeeBoostBps: stakingFeeBoostBps, minLpPriceUsd: minLpPriceUsd, maxLpPriceUsd: maxLpPriceUsd, thresholdUsd: thresholdUsd
|
|
8306
|
+
})
|
|
8307
|
+
.accountsPartial({
|
|
8308
|
+
admin: publicKey,
|
|
8309
|
+
multisig: this.multisig.publicKey,
|
|
8310
|
+
pool: this.getPoolKey(name),
|
|
8311
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
8312
|
+
})
|
|
8313
|
+
.instruction()];
|
|
8314
|
+
case 2:
|
|
8315
|
+
setPoolConfigInstruction = _a.sent();
|
|
8316
|
+
instructions.push(setPoolConfigInstruction);
|
|
8317
|
+
return [3, 4];
|
|
8318
|
+
case 3:
|
|
8319
|
+
err_69 = _a.sent();
|
|
8320
|
+
console.log("perpClient setPoolConfigInstruction error:: ", err_69);
|
|
8321
|
+
throw err_69;
|
|
8322
|
+
case 4: return [2, {
|
|
8323
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8324
|
+
additionalSigners: additionalSigners
|
|
8325
|
+
}];
|
|
8326
|
+
}
|
|
8327
|
+
});
|
|
8328
|
+
}); };
|
|
8329
|
+
this.addCustodyToken22 = function (poolName, tokenMint, tokenAccountSpace, token22) { return __awaiter(_this, void 0, void 0, function () {
|
|
8330
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, addCustodyToken22Instruction, err_70;
|
|
8331
|
+
return __generator(this, function (_a) {
|
|
8332
|
+
switch (_a.label) {
|
|
8333
|
+
case 0:
|
|
8334
|
+
publicKey = this.provider.wallet.publicKey;
|
|
8335
|
+
preInstructions = [];
|
|
8336
|
+
instructions = [];
|
|
8337
|
+
postInstructions = [];
|
|
8338
|
+
additionalSigners = [];
|
|
8339
|
+
_a.label = 1;
|
|
8340
|
+
case 1:
|
|
8341
|
+
_a.trys.push([1, 3, , 4]);
|
|
8342
|
+
return [4, this.program.methods
|
|
8343
|
+
.addCustodyToken22Account({
|
|
8344
|
+
tokenAccountSpace: tokenAccountSpace
|
|
8345
|
+
})
|
|
8346
|
+
.accountsPartial({
|
|
8347
|
+
admin: publicKey,
|
|
8348
|
+
multisig: this.multisig.publicKey,
|
|
8349
|
+
transferAuthority: this.authority.publicKey,
|
|
8350
|
+
perpetuals: this.perpetuals.publicKey,
|
|
8351
|
+
pool: this.getPoolKey(poolName),
|
|
8352
|
+
custodyTokenAccount: this.getCustodyTokenAccountKey(poolName, tokenMint),
|
|
8353
|
+
custodyTokenMint: tokenMint,
|
|
8354
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
8355
|
+
tokenProgram: token22 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
|
8356
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
8357
|
+
})
|
|
8358
|
+
.instruction()];
|
|
8359
|
+
case 2:
|
|
8360
|
+
addCustodyToken22Instruction = _a.sent();
|
|
8361
|
+
instructions.push(addCustodyToken22Instruction);
|
|
8362
|
+
return [3, 4];
|
|
8363
|
+
case 3:
|
|
8364
|
+
err_70 = _a.sent();
|
|
8365
|
+
console.log("perpClient addCustodyToken22Instruction error:: ", err_70);
|
|
8366
|
+
throw err_70;
|
|
8367
|
+
case 4: return [2, {
|
|
8368
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8369
|
+
additionalSigners: additionalSigners
|
|
8370
|
+
}];
|
|
8371
|
+
}
|
|
8372
|
+
});
|
|
8373
|
+
}); };
|
|
8374
|
+
this.addMarket = function (poolName, targetCustody, collateralCustody, side, correlation, maxPayoffBps, permissions) { return __awaiter(_this, void 0, void 0, function () {
|
|
8375
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, market, addMarketInstruction, err_71;
|
|
8376
|
+
return __generator(this, function (_a) {
|
|
8377
|
+
switch (_a.label) {
|
|
8378
|
+
case 0:
|
|
8379
|
+
publicKey = this.provider.wallet.publicKey;
|
|
8380
|
+
preInstructions = [];
|
|
8381
|
+
instructions = [];
|
|
8382
|
+
postInstructions = [];
|
|
8383
|
+
additionalSigners = [];
|
|
8384
|
+
_a.label = 1;
|
|
8385
|
+
case 1:
|
|
8386
|
+
_a.trys.push([1, 3, , 4]);
|
|
8387
|
+
market = web3_js_1.PublicKey.findProgramAddressSync([
|
|
8388
|
+
Buffer.from("market"),
|
|
8389
|
+
targetCustody.toBuffer(),
|
|
8390
|
+
collateralCustody.toBuffer(),
|
|
8391
|
+
(0, types_1.isVariant)(side, 'long') ? Buffer.from([1]) : Buffer.from([2]),
|
|
8392
|
+
], this.program.programId)[0];
|
|
8393
|
+
return [4, this.program.methods
|
|
8394
|
+
.addMarket({
|
|
8395
|
+
side: side === "long" ? { long: {} } : { short: {} },
|
|
8396
|
+
correlation: correlation,
|
|
8397
|
+
maxPayoffBps: maxPayoffBps,
|
|
8398
|
+
permissions: permissions
|
|
8399
|
+
})
|
|
8400
|
+
.accountsPartial({
|
|
8401
|
+
admin: publicKey,
|
|
8402
|
+
multisig: this.multisig.publicKey,
|
|
8403
|
+
transferAuthority: this.authority.publicKey,
|
|
8404
|
+
perpetuals: this.perpetuals.publicKey,
|
|
8405
|
+
pool: this.getPoolKey(poolName),
|
|
8406
|
+
market: market,
|
|
8407
|
+
targetCustody: targetCustody,
|
|
8408
|
+
collateralCustody: collateralCustody,
|
|
8409
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
8410
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
|
8411
|
+
})
|
|
8412
|
+
.instruction()];
|
|
8413
|
+
case 2:
|
|
8414
|
+
addMarketInstruction = _a.sent();
|
|
8415
|
+
instructions.push(addMarketInstruction);
|
|
8416
|
+
return [3, 4];
|
|
8417
|
+
case 3:
|
|
8418
|
+
err_71 = _a.sent();
|
|
8419
|
+
console.log("perpClient addMarketInstruction error:: ", err_71);
|
|
8420
|
+
throw err_71;
|
|
8421
|
+
case 4: return [2, {
|
|
8422
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8423
|
+
additionalSigners: additionalSigners
|
|
8424
|
+
}];
|
|
8425
|
+
}
|
|
8426
|
+
});
|
|
8427
|
+
}); };
|
|
8428
|
+
this.setCustody = function (poolName, tokenMint, depegAdjustment, inversePrice, oracle, pricingConfig, permissions, fees, borrowRate, ratios, rewardThreshold, minReserveUsd, limitPriceBufferBps, token22) { return __awaiter(_this, void 0, void 0, function () {
|
|
8429
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setCustodyConfigInstruction, err_72;
|
|
8430
|
+
return __generator(this, function (_a) {
|
|
8431
|
+
switch (_a.label) {
|
|
8432
|
+
case 0:
|
|
8433
|
+
publicKey = this.provider.wallet.publicKey;
|
|
8434
|
+
preInstructions = [];
|
|
8435
|
+
instructions = [];
|
|
8436
|
+
postInstructions = [];
|
|
8437
|
+
additionalSigners = [];
|
|
8438
|
+
_a.label = 1;
|
|
8439
|
+
case 1:
|
|
8440
|
+
_a.trys.push([1, 3, , 4]);
|
|
8441
|
+
return [4, this.program.methods
|
|
8442
|
+
.setCustodyConfig({
|
|
8443
|
+
depegAdjustment: depegAdjustment,
|
|
8444
|
+
inversePrice: inversePrice,
|
|
8445
|
+
oracle: oracle,
|
|
8446
|
+
pricing: pricingConfig,
|
|
8447
|
+
permissions: permissions,
|
|
8448
|
+
fees: fees,
|
|
8449
|
+
borrowRate: borrowRate,
|
|
8450
|
+
ratios: ratios,
|
|
8451
|
+
rewardThreshold: rewardThreshold,
|
|
8452
|
+
minReserveUsd: minReserveUsd,
|
|
8453
|
+
limitPriceBufferBps: limitPriceBufferBps,
|
|
8454
|
+
token22: token22
|
|
8455
|
+
})
|
|
8456
|
+
.accountsPartial({
|
|
8457
|
+
admin: this.admin,
|
|
8458
|
+
multisig: this.multisig.publicKey,
|
|
8459
|
+
pool: this.getPoolKey(poolName),
|
|
8460
|
+
custody: this.getCustodyKey(poolName, tokenMint),
|
|
8461
|
+
})
|
|
8462
|
+
.instruction()];
|
|
8463
|
+
case 2:
|
|
8464
|
+
setCustodyConfigInstruction = _a.sent();
|
|
8465
|
+
instructions.push(setCustodyConfigInstruction);
|
|
8466
|
+
return [3, 4];
|
|
8467
|
+
case 3:
|
|
8468
|
+
err_72 = _a.sent();
|
|
8469
|
+
console.log("perpClient setCustodyConfigInstruction error:: ", err_72);
|
|
8470
|
+
throw err_72;
|
|
8471
|
+
case 4: return [2, {
|
|
8472
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8473
|
+
additionalSigners: additionalSigners
|
|
8474
|
+
}];
|
|
8475
|
+
}
|
|
8476
|
+
});
|
|
8477
|
+
}); };
|
|
8478
|
+
this.addInternalOracle = function (exponent, tokenMint, intOracleAccount, extOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
|
|
8479
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, addInternalOracleInstruction, err_73;
|
|
8480
|
+
return __generator(this, function (_a) {
|
|
8481
|
+
switch (_a.label) {
|
|
8482
|
+
case 0:
|
|
8483
|
+
publicKey = this.provider.wallet.publicKey;
|
|
8484
|
+
preInstructions = [];
|
|
8485
|
+
instructions = [];
|
|
8486
|
+
postInstructions = [];
|
|
8487
|
+
additionalSigners = [];
|
|
8488
|
+
_a.label = 1;
|
|
8489
|
+
case 1:
|
|
8490
|
+
_a.trys.push([1, 3, , 4]);
|
|
8491
|
+
return [4, this.program.methods
|
|
8492
|
+
.addInternalOracle({
|
|
8493
|
+
expo: exponent,
|
|
8494
|
+
extOracle: extOracleAccount,
|
|
8495
|
+
})
|
|
8496
|
+
.accountsPartial({
|
|
8497
|
+
admin: this.admin,
|
|
8498
|
+
multisig: this.multisig.publicKey,
|
|
8499
|
+
custodyTokenMint: tokenMint,
|
|
8500
|
+
intOracleAccount: intOracleAccount,
|
|
8501
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
8502
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
|
8503
|
+
})
|
|
8504
|
+
.instruction()];
|
|
8505
|
+
case 2:
|
|
8506
|
+
addInternalOracleInstruction = _a.sent();
|
|
8507
|
+
instructions.push(addInternalOracleInstruction);
|
|
8508
|
+
return [3, 4];
|
|
8509
|
+
case 3:
|
|
8510
|
+
err_73 = _a.sent();
|
|
8511
|
+
console.log("perpClient setCustodyConfigInstruction error:: ", err_73);
|
|
8512
|
+
throw err_73;
|
|
8513
|
+
case 4: return [2, {
|
|
8514
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8515
|
+
additionalSigners: additionalSigners
|
|
8516
|
+
}];
|
|
8517
|
+
}
|
|
8518
|
+
});
|
|
8519
|
+
}); };
|
|
8520
|
+
this.setMarket = function (poolName, targetCustody, collateralCustody, marketAccount, maxPayoffBps, permissions, correlation) { return __awaiter(_this, void 0, void 0, function () {
|
|
8521
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setMarketConfigInstruction, err_74;
|
|
8522
|
+
return __generator(this, function (_a) {
|
|
8523
|
+
switch (_a.label) {
|
|
8524
|
+
case 0:
|
|
8525
|
+
publicKey = this.provider.wallet.publicKey;
|
|
8526
|
+
preInstructions = [];
|
|
8527
|
+
instructions = [];
|
|
8528
|
+
postInstructions = [];
|
|
8529
|
+
additionalSigners = [];
|
|
8530
|
+
_a.label = 1;
|
|
8531
|
+
case 1:
|
|
8532
|
+
_a.trys.push([1, 3, , 4]);
|
|
8533
|
+
return [4, this.program.methods
|
|
8534
|
+
.setMarketConfig({
|
|
8535
|
+
maxPayoffBps: maxPayoffBps,
|
|
8536
|
+
permissions: permissions,
|
|
8537
|
+
correlation: correlation
|
|
8538
|
+
})
|
|
8539
|
+
.accountsPartial({
|
|
8540
|
+
admin: this.admin,
|
|
8541
|
+
multisig: this.multisig.publicKey,
|
|
8542
|
+
market: marketAccount,
|
|
8543
|
+
targetCustody: targetCustody,
|
|
8544
|
+
collateralCustody: collateralCustody
|
|
8545
|
+
})
|
|
8546
|
+
.instruction()];
|
|
8547
|
+
case 2:
|
|
8548
|
+
setMarketConfigInstruction = _a.sent();
|
|
8549
|
+
instructions.push(setMarketConfigInstruction);
|
|
8550
|
+
return [3, 4];
|
|
8551
|
+
case 3:
|
|
8552
|
+
err_74 = _a.sent();
|
|
8553
|
+
console.log("perpClient setCustodyConfigInstruction error:: ", err_74);
|
|
8554
|
+
throw err_74;
|
|
8555
|
+
case 4: return [2, {
|
|
8556
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8557
|
+
additionalSigners: additionalSigners
|
|
8558
|
+
}];
|
|
8559
|
+
}
|
|
8560
|
+
});
|
|
8561
|
+
}); };
|
|
8562
|
+
this.removeMarket = function (poolName, market, targetMint, collateralMint) { return __awaiter(_this, void 0, void 0, function () {
|
|
8563
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, removeMarketInstruction, err_75;
|
|
8564
|
+
return __generator(this, function (_a) {
|
|
8565
|
+
switch (_a.label) {
|
|
8566
|
+
case 0:
|
|
8567
|
+
publicKey = this.provider.wallet.publicKey;
|
|
8568
|
+
preInstructions = [];
|
|
8569
|
+
instructions = [];
|
|
8570
|
+
postInstructions = [];
|
|
8571
|
+
additionalSigners = [];
|
|
8572
|
+
_a.label = 1;
|
|
8573
|
+
case 1:
|
|
8574
|
+
_a.trys.push([1, 3, , 4]);
|
|
8575
|
+
return [4, this.program.methods
|
|
8576
|
+
.removeMarket({})
|
|
8577
|
+
.accountsPartial({
|
|
8578
|
+
admin: this.admin,
|
|
8579
|
+
multisig: this.multisig.publicKey,
|
|
8580
|
+
transferAuthority: this.authority.publicKey,
|
|
8581
|
+
perpetuals: this.perpetuals.publicKey,
|
|
8582
|
+
pool: this.getPoolKey(poolName),
|
|
8583
|
+
market: market,
|
|
8584
|
+
targetCustody: this.getCustodyKey(poolName, targetMint),
|
|
8585
|
+
collateralCustody: this.getCustodyKey(poolName, collateralMint),
|
|
8586
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
8587
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
8588
|
+
})
|
|
8589
|
+
.instruction()];
|
|
8590
|
+
case 2:
|
|
8591
|
+
removeMarketInstruction = _a.sent();
|
|
8592
|
+
instructions.push(removeMarketInstruction);
|
|
8593
|
+
return [3, 4];
|
|
8594
|
+
case 3:
|
|
8595
|
+
err_75 = _a.sent();
|
|
8596
|
+
console.log("perpClient setCustodyConfigInstruction error:: ", err_75);
|
|
8597
|
+
throw err_75;
|
|
8598
|
+
case 4: return [2, {
|
|
8599
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
|
8600
|
+
additionalSigners: additionalSigners
|
|
8601
|
+
}];
|
|
8602
|
+
}
|
|
8603
|
+
});
|
|
8604
|
+
}); };
|
|
8251
8605
|
this.provider = provider;
|
|
8252
8606
|
(0, anchor_1.setProvider)(provider);
|
|
8253
8607
|
var idlWithAddress = __assign(__assign({}, perpetuals_json_1.default), { address: programId.toBase58() });
|