flash-sdk 3.2.2-alpha.1 → 3.2.2-alpha.11
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 +21 -17
- package/dist/PerpetualsClient.js +42 -39
- package/dist/PoolConfig.d.ts +1 -0
- package/dist/PoolConfig.js +1 -1
- package/dist/PoolConfig.json +113 -35
- package/dist/PositionAccount.d.ts +1 -0
- package/dist/PositionAccount.js +1 -2
- package/dist/idl/perpetuals.d.ts +30 -6
- package/dist/idl/perpetuals.js +30 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.js +2 -1
- package/package.json +1 -1
@@ -202,7 +202,7 @@ export declare class PerpetualsClient {
|
|
202
202
|
reservedAmount: BN;
|
203
203
|
minReserveUsd: BN;
|
204
204
|
limitPriceBufferBps: BN;
|
205
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
205
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
206
206
|
owner: PublicKey;
|
207
207
|
stakeStats: {
|
208
208
|
pendingActivation: BN;
|
@@ -539,7 +539,7 @@ export declare class PerpetualsClient {
|
|
539
539
|
reservedAmount: BN;
|
540
540
|
minReserveUsd: BN;
|
541
541
|
limitPriceBufferBps: BN;
|
542
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
542
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
543
543
|
owner: PublicKey;
|
544
544
|
stakeStats: {
|
545
545
|
pendingActivation: BN;
|
@@ -875,7 +875,7 @@ export declare class PerpetualsClient {
|
|
875
875
|
reservedAmount: BN;
|
876
876
|
minReserveUsd: BN;
|
877
877
|
limitPriceBufferBps: BN;
|
878
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
878
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
879
879
|
owner: PublicKey;
|
880
880
|
stakeStats: {
|
881
881
|
pendingActivation: BN;
|
@@ -1215,7 +1215,7 @@ export declare class PerpetualsClient {
|
|
1215
1215
|
reservedAmount: BN;
|
1216
1216
|
minReserveUsd: BN;
|
1217
1217
|
limitPriceBufferBps: BN;
|
1218
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
1218
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
1219
1219
|
owner: PublicKey;
|
1220
1220
|
stakeStats: {
|
1221
1221
|
pendingActivation: BN;
|
@@ -1554,7 +1554,7 @@ export declare class PerpetualsClient {
|
|
1554
1554
|
reservedAmount: BN;
|
1555
1555
|
minReserveUsd: BN;
|
1556
1556
|
limitPriceBufferBps: BN;
|
1557
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
1557
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
1558
1558
|
owner: PublicKey;
|
1559
1559
|
stakeStats: {
|
1560
1560
|
pendingActivation: BN;
|
@@ -1891,7 +1891,7 @@ export declare class PerpetualsClient {
|
|
1891
1891
|
reservedAmount: BN;
|
1892
1892
|
minReserveUsd: BN;
|
1893
1893
|
limitPriceBufferBps: BN;
|
1894
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
1894
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
1895
1895
|
owner: PublicKey;
|
1896
1896
|
stakeStats: {
|
1897
1897
|
pendingActivation: BN;
|
@@ -2227,7 +2227,7 @@ export declare class PerpetualsClient {
|
|
2227
2227
|
reservedAmount: BN;
|
2228
2228
|
minReserveUsd: BN;
|
2229
2229
|
limitPriceBufferBps: BN;
|
2230
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
2230
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
2231
2231
|
owner: PublicKey;
|
2232
2232
|
stakeStats: {
|
2233
2233
|
pendingActivation: BN;
|
@@ -2563,7 +2563,7 @@ export declare class PerpetualsClient {
|
|
2563
2563
|
reservedAmount: BN;
|
2564
2564
|
minReserveUsd: BN;
|
2565
2565
|
limitPriceBufferBps: BN;
|
2566
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
2566
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
2567
2567
|
owner: PublicKey;
|
2568
2568
|
stakeStats: {
|
2569
2569
|
pendingActivation: BN;
|
@@ -2793,6 +2793,7 @@ export declare class PerpetualsClient {
|
|
2793
2793
|
lockedDecimals: number;
|
2794
2794
|
collateralDecimals: number;
|
2795
2795
|
bump: number;
|
2796
|
+
padding: number[];
|
2796
2797
|
pubkey: PublicKey;
|
2797
2798
|
}[]>;
|
2798
2799
|
getUserOrderAccounts: (wallet: PublicKey, poolConfig: PoolConfig) => Promise<{
|
@@ -2943,7 +2944,7 @@ export declare class PerpetualsClient {
|
|
2943
2944
|
reservedAmount: BN;
|
2944
2945
|
minReserveUsd: BN;
|
2945
2946
|
limitPriceBufferBps: BN;
|
2946
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
2947
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
2947
2948
|
owner: PublicKey;
|
2948
2949
|
stakeStats: {
|
2949
2950
|
pendingActivation: BN;
|
@@ -3279,7 +3280,7 @@ export declare class PerpetualsClient {
|
|
3279
3280
|
reservedAmount: BN;
|
3280
3281
|
minReserveUsd: BN;
|
3281
3282
|
limitPriceBufferBps: BN;
|
3282
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
3283
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
3283
3284
|
owner: PublicKey;
|
3284
3285
|
stakeStats: {
|
3285
3286
|
pendingActivation: BN;
|
@@ -3615,7 +3616,7 @@ export declare class PerpetualsClient {
|
|
3615
3616
|
reservedAmount: BN;
|
3616
3617
|
minReserveUsd: BN;
|
3617
3618
|
limitPriceBufferBps: BN;
|
3618
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
3619
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
3619
3620
|
owner: PublicKey;
|
3620
3621
|
stakeStats: {
|
3621
3622
|
pendingActivation: BN;
|
@@ -3951,7 +3952,7 @@ export declare class PerpetualsClient {
|
|
3951
3952
|
reservedAmount: BN;
|
3952
3953
|
minReserveUsd: BN;
|
3953
3954
|
limitPriceBufferBps: BN;
|
3954
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
3955
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
3955
3956
|
owner: PublicKey;
|
3956
3957
|
stakeStats: {
|
3957
3958
|
pendingActivation: BN;
|
@@ -4287,7 +4288,7 @@ export declare class PerpetualsClient {
|
|
4287
4288
|
reservedAmount: BN;
|
4288
4289
|
minReserveUsd: BN;
|
4289
4290
|
limitPriceBufferBps: BN;
|
4290
|
-
padding: number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
4291
|
+
padding: number[] | number[] | number[] | BN[] | number[] | BN[] | number[] | number[] | BN[] | BN[];
|
4291
4292
|
owner: PublicKey;
|
4292
4293
|
stakeStats: {
|
4293
4294
|
pendingActivation: BN;
|
@@ -4515,22 +4516,25 @@ export declare class PerpetualsClient {
|
|
4515
4516
|
getLeverageAtAmountEntryWithSwapSync: (positionAccount: PositionAccount | null, inputDeltaAmount: BN, sizeDeltaAmount: BN, side: Side, poolAccount: PoolAccount, inputTokenPrice: OraclePrice, inputTokenEmaPrice: OraclePrice, inputTokenCustodyAccount: CustodyAccount, swapOutTokenPrice: OraclePrice, swapOutTokenEmaPrice: OraclePrice, swapOutTokenCustodyAccount: CustodyAccount, collateralTokenPrice: OraclePrice, collateralTokenEmaPrice: OraclePrice, collateralTokenCustodyAccount: CustodyAccount, targetTokenPrice: OraclePrice, targetTokenEmaPrice: OraclePrice, targetTokenCustodyAccount: CustodyAccount, swapPoolAumUsdMax: BN, poolConfigPosition: PoolConfig, poolConfigSwap: PoolConfig, pnlUsd: BN) => BN;
|
4516
4517
|
getEntryPriceAndFeeSync: (positionAccount: PositionAccount | null, marketCorrelation: boolean, collateralDeltaAmount: BN, sizeDeltaAmount: BN, side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN, discountBps?: BN) => EntryPriceAndFee;
|
4517
4518
|
getEntryPriceAndFeeSyncV2: (positionAccount: PositionAccount | null, marketCorrelation: boolean, collateralDeltaAmount: BN, sizeDeltaAmount: BN, side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN, discountBps?: BN, enableLogs?: boolean) => EntryPriceAndFeeV2;
|
4518
|
-
getEntryPriceUsdSync: (side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount,
|
4519
|
+
getEntryPriceUsdSync: (side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, sizeUsd: BN) => OraclePrice;
|
4519
4520
|
getPriceAfterSlippage(isEntry: boolean, slippageBps: BN, targetPrice: OraclePrice, side: Side): ContractOraclePrice;
|
4520
4521
|
getExitFeeSync: (positionAccount: PositionAccount, targetCustody: CustodyAccount, collateralCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, discountBps?: BN) => {
|
4521
4522
|
exitFeeAmount: BN;
|
4522
4523
|
exitFeeUsd: BN;
|
4523
4524
|
};
|
4524
4525
|
getExitPriceAndFeeSync: (positionAccount: PositionAccount, marketCorrelation: boolean, collateralDeltaAmount: BN, sizeDeltaAmount: BN, side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN, discountBps?: BN) => ExitPriceAndFee;
|
4525
|
-
getTradeSpread: (targetCustodyAccount: CustodyAccount,
|
4526
|
-
getExitOraclePriceSync: (side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount,
|
4526
|
+
getTradeSpread: (targetCustodyAccount: CustodyAccount, sizeUsd: BN) => BN;
|
4527
|
+
getExitOraclePriceSync: (side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, sizeUsd: BN) => OraclePrice;
|
4527
4528
|
getExitOraclePriceWithoutSpreadSync: (side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount) => OraclePrice;
|
4528
4529
|
getSizeAmountFromLeverageAndCollateral: (collateralAmtWithFee: BN, leverage: string, marketToken: Token, collateralToken: Token, side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, discountBps?: BN) => BN;
|
4529
4530
|
getSizeAmountWithSwapSync: (amountIn: BN, leverage: string, side: Side, poolAccount: PoolAccount, inputTokenPrice: OraclePrice, inputTokenEmaPrice: OraclePrice, inputTokenCustodyAccount: CustodyAccount, collateralTokenPrice: OraclePrice, collateralTokenEmaPrice: OraclePrice, collateralTokenCustodyAccount: CustodyAccount, swapOutTokenPrice: OraclePrice, swapOutTokenEmaPrice: OraclePrice, swapOutTokenCustodyAccount: CustodyAccount, targetTokenPrice: OraclePrice, targetTokenEmaPrice: OraclePrice, targetTokenCustodyAccount: CustodyAccount, swapPoolAumUsdMax: BN, poolConfigSwap: PoolConfig, discountBps?: BN) => BN;
|
4530
4531
|
getCollateralAmountWithFeeFromLeverageAndSize: (sizeAmount: BN, leverage: string, marketToken: Token, collateralToken: Token, side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, discountBps?: BN) => BN;
|
4531
4532
|
getCollateralAmountWithSwapSync: (sizeAmount: BN, leverage: string, side: Side, poolAccount: PoolAccount, inputTokenPrice: OraclePrice, inputTokenEmaPrice: OraclePrice, inputTokenCustodyAccount: CustodyAccount, swapOutTokenPrice: OraclePrice, swapOutTokenEmaPrice: OraclePrice, swapOutTokenCustodyAccount: CustodyAccount, collateralTokenPrice: OraclePrice, collateralTokenEmaPrice: OraclePrice, collateralTokenCustodyAccount: CustodyAccount, targetTokenPrice: OraclePrice, targetTokenEmaPrice: OraclePrice, targetTokenCustodyAccount: CustodyAccount, swapPoolAumUsdMax: BN, poolConfigPosition: PoolConfig, poolConfigSwap: PoolConfig) => BN;
|
4532
4533
|
getDecreaseSizeCollateralAndFeeSync: (positionAccount: PositionAccount, marketCorrelation: boolean, sizeDeltaUsd: BN, keepLevSame: boolean, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, marketConfig: MarketConfig, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN, side: Side, poolConfig: PoolConfig, discountBps?: BN, debugLogs?: boolean) => RemoveCollateralData;
|
4533
|
-
getMaxWithdrawableAmountSyncInternal: (positionAccount: PositionAccount, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN, poolConfig: PoolConfig, closeAmount?: BN, errorBandwidthPercentageUi?: number) =>
|
4534
|
+
getMaxWithdrawableAmountSyncInternal: (positionAccount: PositionAccount, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN, poolConfig: PoolConfig, closeAmount?: BN, errorBandwidthPercentageUi?: number) => {
|
4535
|
+
maxWithdrawableAmount: BN;
|
4536
|
+
diff: BN;
|
4537
|
+
};
|
4534
4538
|
getFinalCloseAmountSync: (positionAccount: PositionAccount, marketCorrelation: boolean, side: Side, targetPrice: OraclePrice, targetEmaPrice: OraclePrice, targetCustodyAccount: CustodyAccount, collateralPrice: OraclePrice, collateralEmaPrice: OraclePrice, collateralCustodyAccount: CustodyAccount, currentTimestamp: BN, poolConfig: PoolConfig) => {
|
4535
4539
|
closeAmount: BN;
|
4536
4540
|
feesAmount: BN;
|
package/dist/PerpetualsClient.js
CHANGED
@@ -659,8 +659,8 @@ var PerpetualsClient = (function () {
|
|
659
659
|
finalCollateralAmount = swapAmountOut;
|
660
660
|
}
|
661
661
|
}
|
662
|
-
var
|
663
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount,
|
662
|
+
var sizeUsd = targetTokenPrice.getAssetAmountUsd(sizeDeltaAmount, targetTokenCustodyAccount.decimals);
|
663
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, sizeUsd);
|
664
664
|
var openFeeUsd = constants_1.BN_ZERO;
|
665
665
|
if (sizeDeltaAmount != constants_1.BN_ZERO) {
|
666
666
|
var sizeDeltaUsd = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetTokenCustodyAccount.decimals);
|
@@ -698,13 +698,13 @@ var PerpetualsClient = (function () {
|
|
698
698
|
if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
|
699
699
|
throw new Error("Delta Amounts cannot be negative.");
|
700
700
|
}
|
701
|
-
var
|
702
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount,
|
701
|
+
var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
702
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
703
703
|
if (positionAccount === null) {
|
704
704
|
var data = __assign({}, types_1.DEFAULT_POSITION);
|
705
705
|
positionAccount = PositionAccount_1.PositionAccount.from(web3_js_1.PublicKey.default, data);
|
706
|
-
var
|
707
|
-
positionAccount.sizeUsd =
|
706
|
+
var sizeUsd_1 = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
707
|
+
positionAccount.sizeUsd = sizeUsd_1;
|
708
708
|
positionAccount.sizeDecimals = targetCustodyAccount.decimals;
|
709
709
|
positionAccount.collateralDecimals = collateralCustodyAccount.decimals;
|
710
710
|
positionAccount.lockedDecimals = collateralCustodyAccount.decimals;
|
@@ -761,13 +761,13 @@ var PerpetualsClient = (function () {
|
|
761
761
|
if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
|
762
762
|
throw new Error("Delta Amounts cannot be negative.");
|
763
763
|
}
|
764
|
-
var
|
765
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount,
|
764
|
+
var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
765
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
766
766
|
if (positionAccount === null) {
|
767
767
|
var data = __assign({}, types_1.DEFAULT_POSITION);
|
768
768
|
positionAccount = PositionAccount_1.PositionAccount.from(web3_js_1.PublicKey.default, data);
|
769
|
-
var
|
770
|
-
positionAccount.sizeUsd =
|
769
|
+
var sizeUsd_2 = entryOraclePrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
770
|
+
positionAccount.sizeUsd = sizeUsd_2;
|
771
771
|
positionAccount.sizeDecimals = targetCustodyAccount.decimals;
|
772
772
|
positionAccount.collateralDecimals = collateralCustodyAccount.decimals;
|
773
773
|
positionAccount.lockedDecimals = collateralCustodyAccount.decimals;
|
@@ -831,9 +831,9 @@ var PerpetualsClient = (function () {
|
|
831
831
|
liquidationPrice: liquidationPrice
|
832
832
|
};
|
833
833
|
};
|
834
|
-
this.getEntryPriceUsdSync = function (side, targetPrice, targetEmaPrice, targetCustodyAccount,
|
834
|
+
this.getEntryPriceUsdSync = function (side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd) {
|
835
835
|
var _a = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount), minPrice = _a.min, maxPrice = _a.max;
|
836
|
-
var spread = _this.getTradeSpread(targetCustodyAccount,
|
836
|
+
var spread = _this.getTradeSpread(targetCustodyAccount, sizeUsd);
|
837
837
|
var USD_POWER = (new anchor_1.BN(10)).pow(new anchor_1.BN(constants_1.USD_DECIMALS));
|
838
838
|
var entryPriceBN = (0, types_1.isVariant)(side, 'long') ?
|
839
839
|
maxPrice.price.add(maxPrice.price.mul(spread).div(USD_POWER)) :
|
@@ -866,8 +866,8 @@ var PerpetualsClient = (function () {
|
|
866
866
|
if (resultingPositionAccount.collateralAmount.isNeg() || resultingPositionAccount.sizeAmount.isNeg()) {
|
867
867
|
throw new Error("cannot remove/close more than collateral/Size");
|
868
868
|
}
|
869
|
-
var
|
870
|
-
var exitOraclePrice = _this.getExitOraclePriceSync(side, targetPrice, targetEmaPrice, targetCustodyAccount,
|
869
|
+
var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
870
|
+
var exitOraclePrice = _this.getExitOraclePriceSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
871
871
|
var _a = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount), collateralTokenMinOraclePrice = _a.min, collateralTokenMaxOraclePrice = _a.max;
|
872
872
|
var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(resultingPositionAccount, collateralCustodyAccount, currentTimestamp);
|
873
873
|
var lockAndUnsettledFee = collateralTokenMinOraclePrice.getTokenAmount(lockAndUnsettledFeeUsd, collateralCustodyAccount.decimals);
|
@@ -901,21 +901,21 @@ var PerpetualsClient = (function () {
|
|
901
901
|
liquidationPrice: liquidationPrice
|
902
902
|
};
|
903
903
|
};
|
904
|
-
this.getTradeSpread = function (targetCustodyAccount,
|
904
|
+
this.getTradeSpread = function (targetCustodyAccount, sizeUsd) {
|
905
905
|
if (targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin).isZero()
|
906
906
|
||
|
907
|
-
|
907
|
+
sizeUsd.isZero()) {
|
908
908
|
return constants_1.BN_ZERO;
|
909
909
|
}
|
910
910
|
var slope = ((targetCustodyAccount.pricing.tradeSpreadMax.sub(targetCustodyAccount.pricing.tradeSpreadMin)).mul(new anchor_1.BN(Math.pow(10, (constants_1.RATE_DECIMALS + constants_1.BPS_DECIMALS)))))
|
911
911
|
.div(targetCustodyAccount.pricing.maxPositionLockedUsd);
|
912
|
-
var variable = (slope.mul(
|
912
|
+
var variable = (slope.mul(sizeUsd)).div(new anchor_1.BN(Math.pow(10, (constants_1.RATE_DECIMALS + constants_1.BPS_DECIMALS))));
|
913
913
|
var finalSpread = targetCustodyAccount.pricing.tradeSpreadMin.add(variable);
|
914
914
|
return finalSpread;
|
915
915
|
};
|
916
|
-
this.getExitOraclePriceSync = function (side, targetPrice, targetEmaPrice, targetCustodyAccount,
|
916
|
+
this.getExitOraclePriceSync = function (side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd) {
|
917
917
|
var _a = _this.getMinAndMaxOraclePriceSync(targetPrice, targetEmaPrice, targetCustodyAccount), minPrice = _a.min, maxPrice = _a.max;
|
918
|
-
var spread = _this.getTradeSpread(targetCustodyAccount,
|
918
|
+
var spread = _this.getTradeSpread(targetCustodyAccount, sizeUsd);
|
919
919
|
var USD_POWER = (new anchor_1.BN(10)).pow(new anchor_1.BN(constants_1.USD_DECIMALS));
|
920
920
|
var exitPriceBN = (0, types_1.isVariant)(side, 'long') ?
|
921
921
|
maxPrice.price.sub(maxPrice.price.mul(spread).div(USD_POWER)) :
|
@@ -944,7 +944,7 @@ var PerpetualsClient = (function () {
|
|
944
944
|
openPosFeeRateUi = openPosFeeRateUi.multipliedBy(new bignumber_js_1.default(1).minus(discountBpsUi));
|
945
945
|
}
|
946
946
|
var sizeUsdUi = collateralAmtMinUsdUi.multipliedBy(leverage)
|
947
|
-
.dividedBy(new bignumber_js_1.default(1).plus(openPosFeeRateUi.multipliedBy(leverage)));
|
947
|
+
.dividedBy(new bignumber_js_1.default(1).plus((new bignumber_js_1.default(2).multipliedBy(openPosFeeRateUi)).multipliedBy(leverage)));
|
948
948
|
var lockedUsd = (0, utils_1.uiDecimalsToNative)(sizeUsdUi.toString(), constants_1.USD_DECIMALS);
|
949
949
|
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, lockedUsd);
|
950
950
|
var entryPriceUsdUi = new bignumber_js_1.default(entryOraclePrice.toUiPrice(constants_1.ORACLE_EXPONENT));
|
@@ -971,7 +971,7 @@ var PerpetualsClient = (function () {
|
|
971
971
|
openPosFeeRateUi = openPosFeeRateUi.multipliedBy(new bignumber_js_1.default(1).minus(discountBpsUi));
|
972
972
|
}
|
973
973
|
var sizeUsdUi = collateralAmtMinUsdUi.multipliedBy(leverage)
|
974
|
-
.dividedBy(new bignumber_js_1.default(1).plus(openPosFeeRateUi.multipliedBy(leverage)));
|
974
|
+
.dividedBy(new bignumber_js_1.default(1).plus((new bignumber_js_1.default(2).multipliedBy(openPosFeeRateUi)).multipliedBy(leverage)));
|
975
975
|
var lockedUsd = (0, utils_1.uiDecimalsToNative)(sizeUsdUi.toFixed(constants_1.USD_DECIMALS), constants_1.USD_DECIMALS);
|
976
976
|
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, lockedUsd);
|
977
977
|
var entryPriceUsdUi = new bignumber_js_1.default(entryOraclePrice.toUiPrice(constants_1.ORACLE_EXPONENT));
|
@@ -982,8 +982,8 @@ var PerpetualsClient = (function () {
|
|
982
982
|
if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
|
983
983
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
|
984
984
|
var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
|
985
|
-
var
|
986
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount,
|
985
|
+
var sizeUsd = targetPrice.getAssetAmountUsd(sizeAmount, targetCustodyAccount.decimals);
|
986
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetPrice, targetEmaPrice, targetCustodyAccount, sizeUsd);
|
987
987
|
var entryPriceUsdUi = new bignumber_js_1.default(entryOraclePrice.toUiPrice(constants_1.ORACLE_EXPONENT));
|
988
988
|
var openPosFeeRateUi = new bignumber_js_1.default(targetCustodyAccount.fees.openPosition.toString()).dividedBy(Math.pow(10, constants_1.RATE_DECIMALS));
|
989
989
|
if (!discountBps.isZero()) {
|
@@ -992,20 +992,20 @@ var PerpetualsClient = (function () {
|
|
992
992
|
}
|
993
993
|
var sizeAmountUi = new bignumber_js_1.default(sizeAmount.toString()).dividedBy(Math.pow(10, marketToken.decimals));
|
994
994
|
var sizeUsdUi = entryPriceUsdUi.multipliedBy(sizeAmountUi);
|
995
|
-
var collateralWithFeeUsdUi = sizeUsdUi.multipliedBy(new bignumber_js_1.default(1).plus(openPosFeeRateUi.multipliedBy(leverage))).dividedBy(leverage);
|
995
|
+
var collateralWithFeeUsdUi = sizeUsdUi.multipliedBy(new bignumber_js_1.default(1).plus((new bignumber_js_1.default(2).multipliedBy(openPosFeeRateUi)).multipliedBy(leverage))).dividedBy(leverage);
|
996
996
|
var collateralAmtWithFeeUi = collateralWithFeeUsdUi.dividedBy(collateralTokenMinPriceUi);
|
997
997
|
return (0, utils_1.uiDecimalsToNative)(collateralAmtWithFeeUi.toFixed(collateralToken.decimals, bignumber_js_1.default.ROUND_DOWN), collateralToken.decimals);
|
998
998
|
};
|
999
999
|
this.getCollateralAmountWithSwapSync = function (sizeAmount, leverage, side, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, swapOutTokenPrice, swapOutTokenEmaPrice, swapOutTokenCustodyAccount, collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, swapPoolAumUsdMax, poolConfigPosition, poolConfigSwap) {
|
1000
1000
|
var collateralTokenMinPrice = _this.getMinAndMaxPriceSync(collateralTokenPrice, collateralTokenEmaPrice, collateralTokenCustodyAccount).min;
|
1001
1001
|
var collateralTokenMinPriceUi = new bignumber_js_1.default(collateralTokenMinPrice.toString()).dividedBy(Math.pow(10, constants_1.USD_DECIMALS));
|
1002
|
-
var
|
1003
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount,
|
1002
|
+
var sizeUsd = targetTokenPrice.getAssetAmountUsd(sizeAmount, targetTokenCustodyAccount.decimals);
|
1003
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetTokenCustodyAccount, sizeUsd);
|
1004
1004
|
var entryPriceUsdUi = new bignumber_js_1.default(entryOraclePrice.toUiPrice(constants_1.ORACLE_EXPONENT));
|
1005
1005
|
var openPosFeeRateUi = new bignumber_js_1.default(targetTokenCustodyAccount.fees.openPosition.toString()).dividedBy(Math.pow(10, constants_1.RATE_DECIMALS));
|
1006
1006
|
var sizeAmountUi = new bignumber_js_1.default(sizeAmount.toString()).dividedBy(Math.pow(10, targetTokenCustodyAccount.decimals));
|
1007
1007
|
var sizeUsdUi = entryPriceUsdUi.multipliedBy(sizeAmountUi);
|
1008
|
-
var collateralWithFeeUsdUi = sizeUsdUi.multipliedBy(new bignumber_js_1.default(1).plus(openPosFeeRateUi.multipliedBy(leverage))).dividedBy(leverage);
|
1008
|
+
var collateralWithFeeUsdUi = sizeUsdUi.multipliedBy(new bignumber_js_1.default(1).plus((new bignumber_js_1.default(2).multipliedBy(openPosFeeRateUi)).multipliedBy(leverage))).dividedBy(leverage);
|
1009
1009
|
var collateralAmtWithFeeUi = collateralWithFeeUsdUi.dividedBy(collateralTokenMinPriceUi);
|
1010
1010
|
var collateralAmountWithFee = (0, utils_1.uiDecimalsToNative)(collateralAmtWithFeeUi.toFixed(collateralTokenCustodyAccount.decimals, bignumber_js_1.default.ROUND_DOWN), collateralTokenCustodyAccount.decimals);
|
1011
1011
|
var collateralInInputToken;
|
@@ -1043,6 +1043,7 @@ var PerpetualsClient = (function () {
|
|
1043
1043
|
positionDelta.lockedAmount = (positionAccount.lockedAmount.mul(closeRatio)).div(decimalPower);
|
1044
1044
|
positionDelta.lockedUsd = (positionAccount.lockedUsd.mul(closeRatio)).div(decimalPower);
|
1045
1045
|
positionDelta.collateralAmount = (positionAccount.collateralAmount.mul(closeRatio)).div(decimalPower);
|
1046
|
+
positionDelta.degenSizeUsd = positionAccount.degenSizeUsd.mul(closeRatio).div(decimalPower);
|
1046
1047
|
var newPnl = _this.getPnlSync(positionDelta, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
|
1047
1048
|
var exitFeeUsd = positionDelta.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1048
1049
|
if (discountBps.gt(constants_1.BN_ZERO)) {
|
@@ -1074,6 +1075,7 @@ var PerpetualsClient = (function () {
|
|
1074
1075
|
newPosition.collateralAmount = positionAccount.collateralAmount.sub(positionDelta.collateralAmount);
|
1075
1076
|
newPosition.unsettledFeesUsd = positionAccount.unsettledFeesUsd.sub(positionDelta.unsettledFeesUsd);
|
1076
1077
|
newPosition.collateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(newPosition.collateralAmount, collateralCustodyAccount.decimals);
|
1078
|
+
newPosition.degenSizeUsd = positionAccount.degenSizeUsd.sub(positionDelta.degenSizeUsd);
|
1077
1079
|
var feeUsdWithDiscount = constants_1.BN_ZERO;
|
1078
1080
|
var feeUsd = sizeDeltaUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
|
1079
1081
|
if (discountBps.gt(constants_1.BN_ZERO)) {
|
@@ -1088,7 +1090,7 @@ var PerpetualsClient = (function () {
|
|
1088
1090
|
if (keepLevSame) {
|
1089
1091
|
var collateralAmountReceived = closeAmount;
|
1090
1092
|
var collateralAmountRecievedUsd = collateralMinMaxPrice.min.getAssetAmountUsd(collateralAmountReceived, collateralCustodyAccount.decimals);
|
1091
|
-
var
|
1093
|
+
var _a = _this.getMaxWithdrawableAmountSyncInternal(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, closeAmount), maxWithdrawableAmount = _a.maxWithdrawableAmount, diff = _a.diff;
|
1092
1094
|
if (debugLogs) {
|
1093
1095
|
console.log("maxWithdrawableAmount ", maxWithdrawableAmount.toString(), keepLevSame);
|
1094
1096
|
console.log("collateralAmountReceived ", collateralAmountReceived.toString(), keepLevSame);
|
@@ -1118,7 +1120,7 @@ var PerpetualsClient = (function () {
|
|
1118
1120
|
newLev: newLev,
|
1119
1121
|
liquidationPrice: finalLiquidationPrice,
|
1120
1122
|
collateralAmountRecieved: collateralAmountReceived,
|
1121
|
-
newCollateralAmount: newPosition.collateralAmount,
|
1123
|
+
newCollateralAmount: newPosition.collateralAmount.add(diff),
|
1122
1124
|
newPnl: finalPnlUsd
|
1123
1125
|
};
|
1124
1126
|
}
|
@@ -1144,20 +1146,21 @@ var PerpetualsClient = (function () {
|
|
1144
1146
|
}
|
1145
1147
|
else {
|
1146
1148
|
console.log("profitLoss.lossUsd > coll :: should have been liquidated");
|
1147
|
-
return constants_1.BN_ZERO;
|
1149
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
1148
1150
|
}
|
1149
1151
|
var maxRemovableCollateralUsd = availableInitMarginUsd.sub(positionAccount.sizeUsd.muln(constants_1.BPS_POWER).div(MAX_INIT_LEVERAGE));
|
1150
1152
|
if (maxRemovableCollateralUsd.isNeg()) {
|
1151
|
-
return constants_1.BN_ZERO;
|
1153
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
1152
1154
|
}
|
1153
1155
|
var maxWithdrawableAmount;
|
1156
|
+
var diff;
|
1154
1157
|
var remainingCollateralUsd = availableInitMarginUsd.sub(maxRemovableCollateralUsd);
|
1155
1158
|
var isDegenMode = positionAccount.isDegenMode();
|
1156
1159
|
if (remainingCollateralUsd.lt(new anchor_1.BN(isDegenMode ? targetCustodyAccount.pricing.minDegenCollateralUsd : targetCustodyAccount.pricing.minCollateralUsd))) {
|
1157
|
-
|
1160
|
+
diff = (new anchor_1.BN(isDegenMode ? targetCustodyAccount.pricing.minDegenCollateralUsd : targetCustodyAccount.pricing.minCollateralUsd)).sub(remainingCollateralUsd);
|
1158
1161
|
var updatedMaxRemovableCollateralUsd = maxRemovableCollateralUsd.sub(diff);
|
1159
1162
|
if (updatedMaxRemovableCollateralUsd.isNeg()) {
|
1160
|
-
return constants_1.BN_ZERO;
|
1163
|
+
return { maxWithdrawableAmount: constants_1.BN_ZERO, diff: constants_1.BN_ZERO };
|
1161
1164
|
}
|
1162
1165
|
else {
|
1163
1166
|
maxWithdrawableAmount = collateralMaxPrice.getTokenAmount(updatedMaxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
@@ -1166,7 +1169,7 @@ var PerpetualsClient = (function () {
|
|
1166
1169
|
else {
|
1167
1170
|
maxWithdrawableAmount = collateralMaxPrice.getTokenAmount(maxRemovableCollateralUsd, collateralCustodyAccount.decimals);
|
1168
1171
|
}
|
1169
|
-
return maxWithdrawableAmount;
|
1172
|
+
return { maxWithdrawableAmount: maxWithdrawableAmount, diff: diff };
|
1170
1173
|
};
|
1171
1174
|
this.getFinalCloseAmountSync = function (positionAccount, marketCorrelation, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig) {
|
1172
1175
|
var position = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
|
@@ -1196,7 +1199,7 @@ var PerpetualsClient = (function () {
|
|
1196
1199
|
var MAX_INIT_LEVERAGE = positionAccount.isDegenMode() ?
|
1197
1200
|
(new anchor_1.BN(targetCustodyAccount.pricing.maxInitDegenLeverage)).mul(new anchor_1.BN(100 - errorBandwidthPercentageUi)).div(new anchor_1.BN(100))
|
1198
1201
|
: (new anchor_1.BN(targetCustodyAccount.pricing.maxInitLeverage)).mul(new anchor_1.BN(100 - errorBandwidthPercentageUi)).div(new anchor_1.BN(100));
|
1199
|
-
var maxRemoveableCollateralUsdAfterMinRequired = positionAccount.collateralUsd.sub((new anchor_1.BN(targetCustodyAccount.pricing.minCollateralUsd)).mul(new anchor_1.BN(100 + errorBandwidthPercentageUi)).div(new anchor_1.BN(100)));
|
1202
|
+
var maxRemoveableCollateralUsdAfterMinRequired = positionAccount.collateralUsd.sub((positionAccount.isDegenMode() ? new anchor_1.BN(targetCustodyAccount.pricing.minDegenCollateralUsd) : new anchor_1.BN(targetCustodyAccount.pricing.minCollateralUsd)).mul(new anchor_1.BN(100 + errorBandwidthPercentageUi)).div(new anchor_1.BN(100)));
|
1200
1203
|
if (maxRemoveableCollateralUsdAfterMinRequired.isNeg()) {
|
1201
1204
|
console.log("THIS cannot happen but still");
|
1202
1205
|
return constants_1.BN_ZERO;
|
@@ -1503,8 +1506,8 @@ var PerpetualsClient = (function () {
|
|
1503
1506
|
if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
|
1504
1507
|
throw new Error("Delta Amounts cannot be negative.");
|
1505
1508
|
}
|
1506
|
-
var
|
1507
|
-
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount,
|
1509
|
+
var sizeUsd = targetTokenEmaPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
|
1510
|
+
var entryOraclePrice = _this.getEntryPriceUsdSync(side, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, sizeUsd);
|
1508
1511
|
if (positionAccount === null) {
|
1509
1512
|
var data = __assign({}, types_1.DEFAULT_POSITION);
|
1510
1513
|
positionAccount = PositionAccount_1.PositionAccount.from(web3_js_1.PublicKey.default, data);
|
@@ -1611,8 +1614,8 @@ var PerpetualsClient = (function () {
|
|
1611
1614
|
};
|
1612
1615
|
}
|
1613
1616
|
var side = poolConfig.getMarketConfigByPk(positionAccount.market).side;
|
1614
|
-
var
|
1615
|
-
var exitOraclePrice = _this.getExitOraclePriceSync(side, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount,
|
1617
|
+
var sizeUsd = targetTokenPrice.getAssetAmountUsd(positionAccount.sizeAmount, targetCustodyAccount.decimals);
|
1618
|
+
var exitOraclePrice = _this.getExitOraclePriceSync(side, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, sizeUsd);
|
1616
1619
|
var collateralMinPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount).min;
|
1617
1620
|
var priceDiffProfit, priceDiffLoss;
|
1618
1621
|
var positionEntryPrice = OraclePrice_1.OraclePrice.from({
|
package/dist/PoolConfig.d.ts
CHANGED
package/dist/PoolConfig.js
CHANGED
@@ -173,7 +173,7 @@ var PoolConfig = (function () {
|
|
173
173
|
var markets;
|
174
174
|
try {
|
175
175
|
markets = poolConfig['markets'].map(function (i) {
|
176
|
-
return __assign(__assign({}, i), { marketAccount: new web3_js_1.PublicKey(i.marketAccount), marketCorrelation: i.marketCorrelation, pool: new web3_js_1.PublicKey(i.pool), targetCustody: new web3_js_1.PublicKey(i.targetCustody), collateralCustody: new web3_js_1.PublicKey(i.collateralCustody), side: i.side === 'long' ? types_1.Side.Long : types_1.Side.Short, maxLev: i.maxLev, targetMint: new web3_js_1.PublicKey(i.targetMint), collateralMint: new web3_js_1.PublicKey(i.collateralMint) });
|
176
|
+
return __assign(__assign({}, i), { marketAccount: new web3_js_1.PublicKey(i.marketAccount), marketCorrelation: i.marketCorrelation, pool: new web3_js_1.PublicKey(i.pool), targetCustody: new web3_js_1.PublicKey(i.targetCustody), collateralCustody: new web3_js_1.PublicKey(i.collateralCustody), side: i.side === 'long' ? types_1.Side.Long : types_1.Side.Short, maxLev: i.maxLev, degenMinLev: i.degenMinLev, degenMaxLev: i.degenMaxLev, targetMint: new web3_js_1.PublicKey(i.targetMint), collateralMint: new web3_js_1.PublicKey(i.collateralMint) });
|
177
177
|
});
|
178
178
|
}
|
179
179
|
catch (error) {
|