@gmx-io/sdk 1.8.0 → 1.9.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/README.md +1 -1
- package/build/cjs/scripts/subsquid-codegen.js +1 -1
- package/build/cjs/src/abis/ArbSys.js +11 -0
- package/build/cjs/src/abis/index.js +2 -0
- package/build/cjs/src/clients/v1/testUtil.js +1 -1
- package/build/cjs/src/clients/v2/index.js +8 -1
- package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -88
- package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +136 -748
- package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +30 -165
- package/build/cjs/src/configs/__tests__/markets.spec.js +1 -16
- package/build/cjs/src/configs/api.js +10 -1
- package/build/cjs/src/configs/contracts.js +2 -0
- package/build/cjs/src/configs/dataStore.js +13 -3
- package/build/cjs/src/configs/express.js +1 -0
- package/build/cjs/src/configs/markets.js +14 -77
- package/build/cjs/src/configs/tokens.js +22 -90
- package/build/cjs/src/test/fixtures/arbitrumMarkets.json +0 -72
- package/build/cjs/src/test/mock.js +12 -1
- package/build/cjs/src/utils/__tests__/fees.spec.js +36 -0
- package/build/cjs/src/utils/__tests__/markets.spec.js +233 -0
- package/build/cjs/src/utils/__tests__/positionPnlCap.spec.js +30 -3
- package/build/cjs/src/utils/__tests__/positions.spec.js +5 -5
- package/build/cjs/src/utils/__tests__/prices.spec.js +97 -0
- package/build/cjs/src/utils/express/utils/gelatoRelayUtils.js +2 -0
- package/build/cjs/src/utils/express/utils/gmxRelayUtils.js +145 -0
- package/build/cjs/src/utils/express/utils/gmxRelayUtils.spec.js +163 -0
- package/build/cjs/src/utils/express/utils/index.js +1 -0
- package/build/cjs/src/utils/fees/index.js +8 -5
- package/build/cjs/src/utils/fees/priceImpact.js +4 -9
- package/build/cjs/src/utils/markets/utils.js +57 -1
- package/build/cjs/src/utils/numbers/index.js +1 -0
- package/build/cjs/src/utils/numbers/prbMath.js +154 -0
- package/build/cjs/src/utils/positions/utils.js +66 -43
- package/build/cjs/src/utils/prices/utils.js +28 -1
- package/build/cjs/src/utils/stats/__tests__/api.spec.js +100 -0
- package/build/cjs/src/utils/stats/api.js +32 -0
- package/build/cjs/src/utils/stats/types.js +4 -0
- package/build/cjs/src/utils/trade/__tests__/increase.spec.js +580 -0
- package/build/cjs/src/utils/trade/__tests__/increaseInvariants.spec.js +258 -0
- package/build/cjs/src/utils/trade/__tests__/increaseMarginCheck.spec.js +837 -0
- package/build/cjs/src/utils/trade/increase.js +255 -32
- package/build/cjs/src/utils/trade/increaseMarginCheck.js +179 -0
- package/build/cjs/src/utils/trade/index.js +1 -0
- package/build/cjs/src/utils/trade/trade.js +11 -1
- package/build/cjs/src/utils/tradeHistory/utils.js +3 -0
- package/build/cjs/src/utils/yield/api.js +9 -1
- package/build/esm/scripts/subsquid-codegen.js +1 -1
- package/build/esm/src/abis/ArbSys.js +9 -0
- package/build/esm/src/abis/index.js +2 -0
- package/build/esm/src/clients/v1/testUtil.js +1 -1
- package/build/esm/src/clients/v2/index.js +5 -1
- package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -88
- package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +136 -748
- package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +30 -165
- package/build/esm/src/configs/__tests__/markets.spec.js +2 -17
- package/build/esm/src/configs/api.js +8 -0
- package/build/esm/src/configs/contracts.js +2 -0
- package/build/esm/src/configs/dataStore.js +8 -0
- package/build/esm/src/configs/express.js +1 -0
- package/build/esm/src/configs/markets.js +14 -77
- package/build/esm/src/configs/tokens.js +22 -90
- package/build/esm/src/test/fixtures/arbitrumMarkets.json +0 -72
- package/build/esm/src/test/mock.js +10 -0
- package/build/esm/src/utils/__tests__/fees.spec.js +37 -1
- package/build/esm/src/utils/__tests__/markets.spec.js +234 -1
- package/build/esm/src/utils/__tests__/positionPnlCap.spec.js +30 -3
- package/build/esm/src/utils/__tests__/positions.spec.js +5 -5
- package/build/esm/src/utils/__tests__/prices.spec.js +98 -1
- package/build/esm/src/utils/express/utils/gelatoRelayUtils.js +2 -0
- package/build/esm/src/utils/express/utils/gmxRelayUtils.js +137 -0
- package/build/esm/src/utils/express/utils/gmxRelayUtils.spec.js +161 -0
- package/build/esm/src/utils/express/utils/index.js +1 -0
- package/build/esm/src/utils/fees/index.js +8 -5
- package/build/esm/src/utils/fees/priceImpact.js +5 -10
- package/build/esm/src/utils/markets/utils.js +57 -2
- package/build/esm/src/utils/numbers/index.js +1 -0
- package/build/esm/src/utils/numbers/prbMath.js +149 -0
- package/build/esm/src/utils/positions/utils.js +63 -42
- package/build/esm/src/utils/prices/utils.js +25 -0
- package/build/esm/src/utils/stats/__tests__/api.spec.js +98 -0
- package/build/esm/src/utils/stats/api.js +26 -0
- package/build/esm/src/utils/stats/types.js +1 -0
- package/build/esm/src/utils/trade/__tests__/increase.spec.js +578 -0
- package/build/esm/src/utils/trade/__tests__/increaseInvariants.spec.js +256 -0
- package/build/esm/src/utils/trade/__tests__/increaseMarginCheck.spec.js +835 -0
- package/build/esm/src/utils/trade/increase.js +243 -20
- package/build/esm/src/utils/trade/increaseMarginCheck.js +173 -0
- package/build/esm/src/utils/trade/index.js +1 -0
- package/build/esm/src/utils/trade/trade.js +10 -1
- package/build/esm/src/utils/tradeHistory/utils.js +3 -0
- package/build/esm/src/utils/yield/api.js +7 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/src/abis/ArbSys.d.ts +12 -0
- package/build/types/src/abis/index.d.ts +11 -0
- package/build/types/src/clients/v2/index.d.ts +6 -3
- package/build/types/src/codegen/prebuilt/index.d.ts +170 -989
- package/build/types/src/configs/api.d.ts +1 -0
- package/build/types/src/configs/contracts.d.ts +2 -0
- package/build/types/src/configs/dataStore.d.ts +4 -0
- package/build/types/src/configs/express.d.ts +1 -0
- package/build/types/src/test/mock.d.ts +2 -0
- package/build/types/src/utils/buildUrl/utils.d.ts +1 -1
- package/build/types/src/utils/buyback/types.d.ts +7 -0
- package/build/types/src/utils/express/utils/gelatoRelayUtils.d.ts +2 -0
- package/build/types/src/utils/express/utils/gmxRelayUtils.d.ts +61 -0
- package/build/types/src/utils/express/utils/gmxRelayUtils.spec.d.ts +1 -0
- package/build/types/src/utils/express/utils/index.d.ts +1 -0
- package/build/types/src/utils/fees/index.d.ts +1 -1
- package/build/types/src/utils/markets/utils.d.ts +7 -0
- package/build/types/src/utils/numbers/index.d.ts +1 -0
- package/build/types/src/utils/numbers/prbMath.d.ts +7 -0
- package/build/types/src/utils/positions/utils.d.ts +9 -0
- package/build/types/src/utils/prices/utils.d.ts +10 -0
- package/build/types/src/utils/stats/__tests__/api.spec.d.ts +1 -0
- package/build/types/src/utils/stats/api.d.ts +11 -0
- package/build/types/src/utils/stats/types.d.ts +106 -0
- package/build/types/src/utils/trade/__tests__/increase.spec.d.ts +1 -0
- package/build/types/src/utils/trade/__tests__/increaseInvariants.spec.d.ts +1 -0
- package/build/types/src/utils/trade/__tests__/increaseMarginCheck.spec.d.ts +1 -0
- package/build/types/src/utils/trade/increase.d.ts +3 -0
- package/build/types/src/utils/trade/increaseMarginCheck.d.ts +61 -0
- package/build/types/src/utils/trade/index.d.ts +1 -0
- package/build/types/src/utils/trade/trade.d.ts +2 -0
- package/build/types/src/utils/tradeHistory/types.d.ts +2 -1
- package/build/types/src/utils/yield/api.d.ts +4 -1
- package/build/types/src/utils/yield/types.d.ts +18 -0
- package/package.json +3 -3
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { ARBITRUM } from "../../../configs/chains";
|
|
3
|
+
import { BASIS_POINTS_DIVISOR_BIGINT } from "../../../configs/factors";
|
|
4
|
+
import { createSeededRandom, mockMarketsInfoData, mockTokensData } from "../../../test/mock";
|
|
5
|
+
import { USD_DECIMALS, expandDecimals } from "../../numbers";
|
|
6
|
+
import { OrderType } from "../../orders/types";
|
|
7
|
+
import { getIncreaseEvaluationIndexPrice, getMarkPrice } from "../../prices";
|
|
8
|
+
import { convertToTokenAmount, convertToTokenAmountForIncrease, convertToUsd } from "../../tokens";
|
|
9
|
+
import { getIncreasePositionAmounts, getNextPositionValuesForIncreaseTrade } from "../increase";
|
|
10
|
+
const SEED = 20260820;
|
|
11
|
+
const ORDER_TYPES = [OrderType.MarketIncrease, OrderType.LimitIncrease, OrderType.StopIncrease];
|
|
12
|
+
describe("getIncreasePositionAmounts — one price for sizing and for evaluation", () => {
|
|
13
|
+
// a spread makes the long/short sides of the mark price distinguishable
|
|
14
|
+
const tokensData = mockTokensData({
|
|
15
|
+
ETH: { prices: { minPrice: expandDecimals(1180, USD_DECIMALS), maxPrice: expandDecimals(1220, USD_DECIMALS) } },
|
|
16
|
+
});
|
|
17
|
+
const marketsInfoData = mockMarketsInfoData(tokensData, ["ETH-ETH-USDC"]);
|
|
18
|
+
const marketInfo = marketsInfoData["ETH-ETH-USDC"];
|
|
19
|
+
const eth = tokensData.ETH;
|
|
20
|
+
const usdc = tokensData.USDC;
|
|
21
|
+
function getAmounts(p) {
|
|
22
|
+
const limitOrderType = p.orderType === OrderType.MarketIncrease ? undefined : p.orderType;
|
|
23
|
+
return getIncreasePositionAmounts({
|
|
24
|
+
marketInfo,
|
|
25
|
+
indexToken: eth,
|
|
26
|
+
initialCollateralToken: usdc,
|
|
27
|
+
collateralToken: usdc,
|
|
28
|
+
isLong: p.isLong,
|
|
29
|
+
initialCollateralAmount: p.initialCollateralAmount,
|
|
30
|
+
indexTokenAmount: p.indexTokenAmount,
|
|
31
|
+
position: undefined,
|
|
32
|
+
externalSwapQuote: undefined,
|
|
33
|
+
userReferralInfo: undefined,
|
|
34
|
+
strategy: p.strategy,
|
|
35
|
+
leverage: p.strategy === "leverageByCollateral" ? p.leverage : undefined,
|
|
36
|
+
triggerPrice: p.triggerPrice,
|
|
37
|
+
limitOrderType,
|
|
38
|
+
findSwapPath: (() => undefined),
|
|
39
|
+
uiFeeFactor: 0n,
|
|
40
|
+
marketsInfoData,
|
|
41
|
+
chainId: ARBITRUM,
|
|
42
|
+
externalSwapQuoteParams: undefined,
|
|
43
|
+
isSetAcceptablePriceImpactEnabled: false,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
it("sizes every order at the price its resulting position is evaluated at", () => {
|
|
47
|
+
const random = createSeededRandom(SEED);
|
|
48
|
+
let checked = 0;
|
|
49
|
+
for (let i = 0; i < 400; i++) {
|
|
50
|
+
const orderType = ORDER_TYPES[i % ORDER_TYPES.length];
|
|
51
|
+
const isLong = random() < 0.5;
|
|
52
|
+
const strategy = random() < 0.5 ? "independent" : "leverageByCollateral";
|
|
53
|
+
const markPrice = getMarkPrice({ prices: eth.prices, isIncrease: true, isLong });
|
|
54
|
+
// ±10% around the mark, so both the executable-now and the resting side are hit
|
|
55
|
+
const triggerFactorBps = 9000n + BigInt(Math.floor(random() * 2001));
|
|
56
|
+
const triggerPrice = orderType === OrderType.MarketIncrease ? undefined : (markPrice * triggerFactorBps) / 10000n;
|
|
57
|
+
const initialCollateralAmount = expandDecimals(100 + Math.floor(random() * 9900), usdc.decimals);
|
|
58
|
+
const indexTokenAmount = convertToTokenAmount(expandDecimals(500 + Math.floor(random() * 50000), USD_DECIMALS), eth.decimals, markPrice);
|
|
59
|
+
const leverage = BigInt(2 + Math.floor(random() * 30)) * BASIS_POINTS_DIVISOR_BIGINT;
|
|
60
|
+
const values = getAmounts({
|
|
61
|
+
orderType,
|
|
62
|
+
triggerPrice,
|
|
63
|
+
isLong,
|
|
64
|
+
strategy,
|
|
65
|
+
initialCollateralAmount,
|
|
66
|
+
indexTokenAmount,
|
|
67
|
+
leverage,
|
|
68
|
+
});
|
|
69
|
+
const evaluationPrice = getIncreaseEvaluationIndexPrice({
|
|
70
|
+
orderType,
|
|
71
|
+
triggerPrice,
|
|
72
|
+
}) ?? markPrice;
|
|
73
|
+
const context = `${OrderType[orderType]} ${isLong ? "long" : "short"} ${strategy} trigger=${triggerPrice}`;
|
|
74
|
+
expect(values.indexPrice, context).toBe(evaluationPrice);
|
|
75
|
+
expect(values.sizeDeltaInTokens, context).toBe(convertToTokenAmountForIncrease(values.sizeDeltaUsd, eth.decimals, evaluationPrice, isLong));
|
|
76
|
+
expect(values.sizeDeltaUsd, context).toBeGreaterThan(0n);
|
|
77
|
+
checked++;
|
|
78
|
+
}
|
|
79
|
+
expect(checked).toBe(400);
|
|
80
|
+
});
|
|
81
|
+
it("keeps the resting limit sized at its trigger while the mark has crossed it", () => {
|
|
82
|
+
// the executable-now window: a long limit whose trigger sits above the current mark
|
|
83
|
+
const markPrice = getMarkPrice({ prices: eth.prices, isIncrease: true, isLong: true });
|
|
84
|
+
const triggerPrice = (markPrice * 110n) / 100n;
|
|
85
|
+
const values = getAmounts({
|
|
86
|
+
orderType: OrderType.LimitIncrease,
|
|
87
|
+
triggerPrice,
|
|
88
|
+
isLong: true,
|
|
89
|
+
strategy: "independent",
|
|
90
|
+
initialCollateralAmount: expandDecimals(1000, usdc.decimals),
|
|
91
|
+
indexTokenAmount: convertToTokenAmount(expandDecimals(10000, USD_DECIMALS), eth.decimals, markPrice),
|
|
92
|
+
leverage: 10n * BASIS_POINTS_DIVISOR_BIGINT,
|
|
93
|
+
});
|
|
94
|
+
expect(getIncreaseEvaluationIndexPrice({ orderType: OrderType.LimitIncrease, triggerPrice })).toBe(triggerPrice);
|
|
95
|
+
expect(values.indexPrice).toBe(triggerPrice);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
describe("getIncreasePositionAmounts — both swap-strategy paths agree on equivalent tokens", () => {
|
|
99
|
+
/**
|
|
100
|
+
* The tradebox always passes `externalSwapQuoteParams` (→ `buildSwapStrategy`), the order
|
|
101
|
+
* editor and the orders list never do (→ `getSwapAmountsByFromValueDefault`). For tokens that
|
|
102
|
+
* need no route the two must value the deposit identically — the contract credits it whole.
|
|
103
|
+
*/
|
|
104
|
+
function getAmounts(p) {
|
|
105
|
+
const marketsInfoData = mockMarketsInfoData(p.tokensData, [p.marketKey]);
|
|
106
|
+
return getIncreasePositionAmounts({
|
|
107
|
+
marketInfo: marketsInfoData[p.marketKey],
|
|
108
|
+
indexToken: p.indexToken,
|
|
109
|
+
initialCollateralToken: p.initialCollateralToken,
|
|
110
|
+
collateralToken: p.collateralToken,
|
|
111
|
+
isLong: p.isLong,
|
|
112
|
+
initialCollateralAmount: p.initialCollateralAmount,
|
|
113
|
+
indexTokenAmount: p.indexTokenAmount,
|
|
114
|
+
position: undefined,
|
|
115
|
+
externalSwapQuote: undefined,
|
|
116
|
+
userReferralInfo: undefined,
|
|
117
|
+
strategy: p.strategy,
|
|
118
|
+
leverage: p.strategy === "leverageByCollateral" ? p.leverage : undefined,
|
|
119
|
+
findSwapPath: (() => undefined),
|
|
120
|
+
uiFeeFactor: p.uiFeeFactor,
|
|
121
|
+
marketsInfoData,
|
|
122
|
+
chainId: ARBITRUM,
|
|
123
|
+
externalSwapQuoteParams: p.externalSwapQuoteParams,
|
|
124
|
+
isSetAcceptablePriceImpactEnabled: false,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
it("values the deposit the same with and without the external-swap params", () => {
|
|
128
|
+
const random = createSeededRandom(SEED + 1);
|
|
129
|
+
let sameToken = 0;
|
|
130
|
+
let nativeToWrapped = 0;
|
|
131
|
+
for (let i = 0; i < 200; i++) {
|
|
132
|
+
// a spread is what a re-valuation haircut would show up as
|
|
133
|
+
const spreadBps = BigInt(Math.floor(random() * 500));
|
|
134
|
+
const ethMin = expandDecimals(1200, USD_DECIMALS);
|
|
135
|
+
const ethMax = ethMin + (ethMin * spreadBps) / 10000n;
|
|
136
|
+
const avaxMin = expandDecimals(12, USD_DECIMALS);
|
|
137
|
+
const avaxMax = avaxMin + (avaxMin * spreadBps) / 10000n;
|
|
138
|
+
const tokensData = mockTokensData({
|
|
139
|
+
ETH: { prices: { minPrice: ethMin, maxPrice: ethMax } },
|
|
140
|
+
// the mock spreads the AVAX override onto WAVAX too, so both sides of the pair move
|
|
141
|
+
AVAX: { prices: { minPrice: avaxMin, maxPrice: avaxMax } },
|
|
142
|
+
});
|
|
143
|
+
const isNativePair = i % 2 === 0;
|
|
144
|
+
const marketKey = isNativePair ? "AVAX-AVAX-USDC" : "ETH-ETH-USDC";
|
|
145
|
+
const indexToken = isNativePair ? tokensData.AVAX : tokensData.ETH;
|
|
146
|
+
// AVAX is native with `wrappedAddress: WAVAX` — equivalent, so no route is needed
|
|
147
|
+
const initialCollateralToken = isNativePair ? tokensData.AVAX : tokensData.ETH;
|
|
148
|
+
const collateralToken = isNativePair ? tokensData.WAVAX : tokensData.ETH;
|
|
149
|
+
const isLong = random() < 0.5;
|
|
150
|
+
const strategy = random() < 0.5 ? "independent" : "leverageByCollateral";
|
|
151
|
+
const uiFeeFactor = random() < 0.5 ? 0n : expandDecimals(1, 27);
|
|
152
|
+
const depositTargetUsd = expandDecimals(1000 + Math.floor(random() * 20000), USD_DECIMALS);
|
|
153
|
+
const initialCollateralAmount = convertToTokenAmount(depositTargetUsd, initialCollateralToken.decimals, initialCollateralToken.prices.minPrice);
|
|
154
|
+
const indexTokenAmount = convertToTokenAmount(depositTargetUsd * BigInt(2 + Math.floor(random() * 20)), indexToken.decimals, indexToken.prices.maxPrice);
|
|
155
|
+
const leverage = BigInt(2 + Math.floor(random() * 30)) * BASIS_POINTS_DIVISOR_BIGINT;
|
|
156
|
+
const shared = {
|
|
157
|
+
tokensData,
|
|
158
|
+
marketKey,
|
|
159
|
+
indexToken,
|
|
160
|
+
initialCollateralToken,
|
|
161
|
+
collateralToken,
|
|
162
|
+
initialCollateralAmount,
|
|
163
|
+
indexTokenAmount,
|
|
164
|
+
isLong,
|
|
165
|
+
strategy,
|
|
166
|
+
leverage,
|
|
167
|
+
uiFeeFactor,
|
|
168
|
+
};
|
|
169
|
+
const withParams = getAmounts({ ...shared, externalSwapQuoteParams: {} });
|
|
170
|
+
const withoutParams = getAmounts({ ...shared, externalSwapQuoteParams: undefined });
|
|
171
|
+
const depositUsd = convertToUsd(initialCollateralAmount, initialCollateralToken.decimals, initialCollateralToken.prices.minPrice);
|
|
172
|
+
const context = `${isNativePair ? "native→wrapped" : "same-token"} ${strategy} spread=${spreadBps}`;
|
|
173
|
+
expect(withParams.collateralDeltaUsd, context).toBe(withoutParams.collateralDeltaUsd);
|
|
174
|
+
expect(withParams.sizeDeltaUsd, context).toBe(withoutParams.sizeDeltaUsd);
|
|
175
|
+
// no haircut: the whole deposit reaches the position, minus the position-level fees only
|
|
176
|
+
expect(withParams.collateralDeltaUsd, context).toBe(depositUsd - withParams.positionFeeUsd - withParams.uiFeeUsd);
|
|
177
|
+
expect(withParams.swapUiFeeUsd, context).toBe(0n);
|
|
178
|
+
if (isNativePair) {
|
|
179
|
+
nativeToWrapped++;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
sameToken++;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
expect(sameToken).toBeGreaterThan(0);
|
|
186
|
+
expect(nativeToWrapped).toBeGreaterThan(0);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
describe("one price base in next-position values", () => {
|
|
190
|
+
const tokensData = mockTokensData({
|
|
191
|
+
ETH: { prices: { minPrice: expandDecimals(1180, USD_DECIMALS), maxPrice: expandDecimals(1220, USD_DECIMALS) } },
|
|
192
|
+
});
|
|
193
|
+
const marketsInfoData = mockMarketsInfoData(tokensData, ["ETH-ETH-USDC"]);
|
|
194
|
+
const marketInfo = marketsInfoData["ETH-ETH-USDC"];
|
|
195
|
+
const eth = tokensData.ETH;
|
|
196
|
+
// 2 WETH of collateral booked at the 1 180 min price
|
|
197
|
+
const position = {
|
|
198
|
+
sizeInUsd: expandDecimals(6000, USD_DECIMALS),
|
|
199
|
+
sizeInTokens: expandDecimals(5, eth.decimals),
|
|
200
|
+
collateralAmount: expandDecimals(2, eth.decimals),
|
|
201
|
+
collateralUsd: expandDecimals(2360, USD_DECIMALS),
|
|
202
|
+
pendingBorrowingFeesUsd: 0n,
|
|
203
|
+
fundingFeeAmount: 0n,
|
|
204
|
+
pendingImpactAmount: 0n,
|
|
205
|
+
pendingImpactUsd: 0n,
|
|
206
|
+
};
|
|
207
|
+
const triggerPrice = expandDecimals(1100, USD_DECIMALS);
|
|
208
|
+
it.each([
|
|
209
|
+
{ name: "long limit below the market", isLong: true, limitOrderType: OrderType.LimitIncrease },
|
|
210
|
+
{ name: "short stop below the market", isLong: false, limitOrderType: OrderType.StopIncrease },
|
|
211
|
+
])("$name: the existing collateral and the delta share the evaluation price", ({ isLong, limitOrderType }) => {
|
|
212
|
+
const increaseAmounts = getIncreasePositionAmounts({
|
|
213
|
+
marketInfo,
|
|
214
|
+
indexToken: eth,
|
|
215
|
+
initialCollateralToken: eth,
|
|
216
|
+
collateralToken: eth,
|
|
217
|
+
isLong,
|
|
218
|
+
initialCollateralAmount: expandDecimals(1, eth.decimals),
|
|
219
|
+
indexTokenAmount: expandDecimals(5, eth.decimals),
|
|
220
|
+
position,
|
|
221
|
+
externalSwapQuote: undefined,
|
|
222
|
+
userReferralInfo: undefined,
|
|
223
|
+
strategy: "independent",
|
|
224
|
+
triggerPrice,
|
|
225
|
+
limitOrderType,
|
|
226
|
+
findSwapPath: (() => undefined),
|
|
227
|
+
uiFeeFactor: 0n,
|
|
228
|
+
marketsInfoData,
|
|
229
|
+
chainId: ARBITRUM,
|
|
230
|
+
externalSwapQuoteParams: undefined,
|
|
231
|
+
isSetAcceptablePriceImpactEnabled: false,
|
|
232
|
+
});
|
|
233
|
+
const evaluationPrice = getIncreaseEvaluationIndexPrice({ orderType: limitOrderType, triggerPrice });
|
|
234
|
+
expect(increaseAmounts.collateralPrice).toBe(evaluationPrice);
|
|
235
|
+
const nextValues = getNextPositionValuesForIncreaseTrade({
|
|
236
|
+
marketInfo,
|
|
237
|
+
collateralToken: eth,
|
|
238
|
+
existingPosition: position,
|
|
239
|
+
isLong,
|
|
240
|
+
collateralDeltaUsd: increaseAmounts.collateralDeltaUsd,
|
|
241
|
+
collateralDeltaAmount: increaseAmounts.collateralDeltaAmount,
|
|
242
|
+
sizeDeltaUsd: increaseAmounts.sizeDeltaUsd,
|
|
243
|
+
sizeDeltaInTokens: increaseAmounts.sizeDeltaInTokens,
|
|
244
|
+
positionPriceImpactDeltaUsd: increaseAmounts.positionPriceImpactDeltaUsd,
|
|
245
|
+
indexPrice: increaseAmounts.indexPrice,
|
|
246
|
+
showPnlInLeverage: false,
|
|
247
|
+
minCollateralUsd: expandDecimals(1, USD_DECIMALS),
|
|
248
|
+
userReferralInfo: undefined,
|
|
249
|
+
collateralPrice: increaseAmounts.collateralPrice,
|
|
250
|
+
});
|
|
251
|
+
const nextCollateralAmount = position.collateralAmount + increaseAmounts.collateralDeltaAmount;
|
|
252
|
+
expect(nextValues.nextCollateralUsd).toBe(convertToUsd(nextCollateralAmount, eth.decimals, evaluationPrice));
|
|
253
|
+
// 2 ETH at 1 100 + (1 ETH at 1 100 − 0.05% of the 5 500 of size) = 2 200 + 1 097.25
|
|
254
|
+
expect(nextValues.nextCollateralUsd).toBe(expandDecimals(329725, USD_DECIMALS - 2));
|
|
255
|
+
});
|
|
256
|
+
});
|