@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
|
@@ -447,15 +447,6 @@ export const TOKENS = {
|
|
|
447
447
|
imageUrl: "https://assets.coingecko.com/coins/images/1094/standard/tron-logo.png?1696502193",
|
|
448
448
|
isSynthetic: true,
|
|
449
449
|
},
|
|
450
|
-
{
|
|
451
|
-
name: "TON",
|
|
452
|
-
symbol: "TON",
|
|
453
|
-
address: "0xB2f7cefaeEb08Aa347705ac829a7b8bE2FB560f3",
|
|
454
|
-
decimals: 9,
|
|
455
|
-
categories: ["layer1"],
|
|
456
|
-
imageUrl: "https://assets.coingecko.com/coins/images/17980/standard/photo_2024-09-10_17.09.00.jpeg?1725963446",
|
|
457
|
-
isSynthetic: true,
|
|
458
|
-
},
|
|
459
450
|
{
|
|
460
451
|
name: "WLD",
|
|
461
452
|
symbol: "WLD",
|
|
@@ -624,15 +615,6 @@ export const TOKENS = {
|
|
|
624
615
|
imageUrl: "https://assets.coingecko.com/coins/images/53746/standard/trump.png?1737171561",
|
|
625
616
|
isSynthetic: true,
|
|
626
617
|
},
|
|
627
|
-
{
|
|
628
|
-
name: "Melania Meme",
|
|
629
|
-
symbol: "MELANIA",
|
|
630
|
-
address: "0xfa4F8E582214eBCe1A08eB2a65e08082053E441F",
|
|
631
|
-
decimals: 6,
|
|
632
|
-
categories: ["meme"],
|
|
633
|
-
imageUrl: "https://assets.coingecko.com/coins/images/53775/standard/melania-meme.png?1737329885",
|
|
634
|
-
isSynthetic: true,
|
|
635
|
-
},
|
|
636
618
|
{
|
|
637
619
|
name: "Ethena Governance Token",
|
|
638
620
|
symbol: "ENA",
|
|
@@ -642,15 +624,6 @@ export const TOKENS = {
|
|
|
642
624
|
imageUrl: "https://assets.coingecko.com/coins/images/36530/standard/ethena.png?1711701436",
|
|
643
625
|
isSynthetic: true,
|
|
644
626
|
},
|
|
645
|
-
{
|
|
646
|
-
name: "ai16z",
|
|
647
|
-
symbol: "AI16Z",
|
|
648
|
-
address: "0xBb69bd9dc152C2c0F083507641a46193d2B61EBb",
|
|
649
|
-
decimals: 9,
|
|
650
|
-
categories: ["meme", "ai"],
|
|
651
|
-
imageUrl: "https://assets.coingecko.com/coins/images/51090/standard/AI16Z.jpg?1730027175",
|
|
652
|
-
isSynthetic: true,
|
|
653
|
-
},
|
|
654
627
|
{
|
|
655
628
|
name: "Animecoin",
|
|
656
629
|
symbol: "ANIME",
|
|
@@ -768,24 +741,6 @@ export const TOKENS = {
|
|
|
768
741
|
imageUrl: "https://assets.coingecko.com/coins/images/34188/standard/jup.png?1704266489",
|
|
769
742
|
isSynthetic: true,
|
|
770
743
|
},
|
|
771
|
-
{
|
|
772
|
-
name: "Maker",
|
|
773
|
-
symbol: "MKR",
|
|
774
|
-
address: "0x8904De84c3bB3B7D2383F934Af40FcB3Ef82F28b",
|
|
775
|
-
decimals: 18,
|
|
776
|
-
categories: ["defi"],
|
|
777
|
-
imageUrl: "https://assets.coingecko.com/coins/images/1364/standard/Mark_Maker.png?1696502423",
|
|
778
|
-
isSynthetic: true,
|
|
779
|
-
},
|
|
780
|
-
{
|
|
781
|
-
name: "MANTRA",
|
|
782
|
-
symbol: "OM",
|
|
783
|
-
address: "0x1f3407Ea067DfBDF6dEb6bBFdA4869215fB0ab77",
|
|
784
|
-
decimals: 18,
|
|
785
|
-
categories: ["layer1"],
|
|
786
|
-
imageUrl: "https://assets.coingecko.com/coins/images/12151/standard/OM_Token.png?1696511991",
|
|
787
|
-
isSynthetic: true,
|
|
788
|
-
},
|
|
789
744
|
{
|
|
790
745
|
name: "Dolomite",
|
|
791
746
|
symbol: "DOLO",
|
|
@@ -822,15 +777,6 @@ export const TOKENS = {
|
|
|
822
777
|
imageUrl: "https://assets.coingecko.com/coins/images/69/standard/monero_logo.png?1696501460",
|
|
823
778
|
categories: ["layer1"],
|
|
824
779
|
},
|
|
825
|
-
{
|
|
826
|
-
name: "Pi Network",
|
|
827
|
-
symbol: "PI",
|
|
828
|
-
address: "0xd1738d37401a0A71f7E382d2cFeCD3ab69687017",
|
|
829
|
-
decimals: 18,
|
|
830
|
-
isSynthetic: true,
|
|
831
|
-
imageUrl: "https://assets.coingecko.com/coins/images/54342/standard/pi_network.jpg?1739347576",
|
|
832
|
-
categories: ["layer1"],
|
|
833
|
-
},
|
|
834
780
|
{
|
|
835
781
|
name: "Curve DAO Token",
|
|
836
782
|
symbol: "CRV",
|
|
@@ -992,24 +938,6 @@ export const TOKENS = {
|
|
|
992
938
|
categories: ["ai"],
|
|
993
939
|
imageUrl: "https://assets.coingecko.com/coins/images/54023/standard/VVV_Token_Transparent.png?1741856877",
|
|
994
940
|
},
|
|
995
|
-
{
|
|
996
|
-
name: "Moonwell",
|
|
997
|
-
symbol: "WELL",
|
|
998
|
-
address: "0x465A31E5bA29b8EAcC860d499D714a6f07e56E85",
|
|
999
|
-
decimals: 18,
|
|
1000
|
-
isSynthetic: true,
|
|
1001
|
-
categories: ["defi"],
|
|
1002
|
-
imageUrl: "https://assets.coingecko.com/coins/images/26133/standard/WELL.png?1696525221",
|
|
1003
|
-
},
|
|
1004
|
-
{
|
|
1005
|
-
name: "KTA",
|
|
1006
|
-
symbol: "KTA",
|
|
1007
|
-
decimals: 18,
|
|
1008
|
-
address: "0x96Ee343E36E8642627FAEa235D57a9FEC8a6e34f",
|
|
1009
|
-
isSynthetic: true,
|
|
1010
|
-
categories: ["layer1"],
|
|
1011
|
-
imageUrl: "https://assets.coingecko.com/coins/images/54693/standard/zora.jpg?1741094751",
|
|
1012
|
-
},
|
|
1013
941
|
{
|
|
1014
942
|
name: "Zora",
|
|
1015
943
|
symbol: "ZORA",
|
|
@@ -1156,15 +1084,6 @@ export const TOKENS = {
|
|
|
1156
1084
|
categories: ["defi"],
|
|
1157
1085
|
imageUrl: "https://assets.coingecko.com/coins/images/71121/standard/lighter.png?1765888098",
|
|
1158
1086
|
},
|
|
1159
|
-
{
|
|
1160
|
-
name: "Story",
|
|
1161
|
-
symbol: "IP",
|
|
1162
|
-
address: "0xe7304E9F4ca383BD6312a5179cdC7B40B96A6F5a",
|
|
1163
|
-
isSynthetic: true,
|
|
1164
|
-
decimals: 18,
|
|
1165
|
-
categories: ["layer1"],
|
|
1166
|
-
imageUrl: "https://assets.coingecko.com/coins/images/54035/standard/Transparent_bg.png?1738075331",
|
|
1167
|
-
},
|
|
1168
1087
|
{
|
|
1169
1088
|
name: "Canton",
|
|
1170
1089
|
symbol: "CC",
|
|
@@ -1247,6 +1166,26 @@ export const TOKENS = {
|
|
|
1247
1166
|
searchAliases: ["Space", "X"],
|
|
1248
1167
|
explorerUrl: "https://arbiscan.io/token/0x8CBd0d5d81e7957123E6D8fFaE657a40bDC5691b",
|
|
1249
1168
|
},
|
|
1169
|
+
{
|
|
1170
|
+
name: "Invesco QQQ Trust",
|
|
1171
|
+
symbol: "QQQ",
|
|
1172
|
+
address: "0xfe71D55D0080b6995Ec2C3f48b7702c86e200766",
|
|
1173
|
+
isSynthetic: true,
|
|
1174
|
+
decimals: 18,
|
|
1175
|
+
categories: ["tradfi", "indices"],
|
|
1176
|
+
searchAliases: ["Nasdaq", "Nasdaq-100", "NDX", "Invesco"],
|
|
1177
|
+
explorerUrl: "https://arbiscan.io/token/0xfe71D55D0080b6995Ec2C3f48b7702c86e200766",
|
|
1178
|
+
},
|
|
1179
|
+
{
|
|
1180
|
+
name: "SPDR S&P 500 ETF",
|
|
1181
|
+
symbol: "SPY",
|
|
1182
|
+
address: "0x0315441076FF6d3eA09814a2F90a1f980cF03e9e",
|
|
1183
|
+
isSynthetic: true,
|
|
1184
|
+
decimals: 18,
|
|
1185
|
+
categories: ["tradfi", "indices"],
|
|
1186
|
+
searchAliases: ["S&P", "S&P 500", "SPX", "SPDR"],
|
|
1187
|
+
explorerUrl: "https://arbiscan.io/token/0x0315441076FF6d3eA09814a2F90a1f980cF03e9e",
|
|
1188
|
+
},
|
|
1250
1189
|
{
|
|
1251
1190
|
name: "MegaETH",
|
|
1252
1191
|
symbol: "MEGA",
|
|
@@ -1359,15 +1298,6 @@ export const TOKENS = {
|
|
|
1359
1298
|
imageUrl: "https://assets.coingecko.com/coins/images/325/small/Tether-logo.png",
|
|
1360
1299
|
explorerUrl: "https://snowtrace.io/address/0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
|
|
1361
1300
|
},
|
|
1362
|
-
{
|
|
1363
|
-
name: "Dai",
|
|
1364
|
-
symbol: "DAI.E",
|
|
1365
|
-
address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
|
|
1366
|
-
decimals: 18,
|
|
1367
|
-
isStable: true,
|
|
1368
|
-
imageUrl: "https://assets.coingecko.com/coins/images/9956/thumb/4943.png?1636636734",
|
|
1369
|
-
explorerUrl: "https://snowtrace.io/address/0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
|
|
1370
|
-
},
|
|
1371
1301
|
{
|
|
1372
1302
|
name: "Magic Internet Money",
|
|
1373
1303
|
symbol: "MIM",
|
|
@@ -1995,6 +1925,8 @@ export const TOKEN_COLOR_MAP = {
|
|
|
1995
1925
|
GOLD: "#D69A00",
|
|
1996
1926
|
SILVER: "#ADABB8",
|
|
1997
1927
|
SPCX: "#1A1E21",
|
|
1928
|
+
QQQ: "#000AD2",
|
|
1929
|
+
SPY: "#273F33",
|
|
1998
1930
|
XPT: "#C2B8AB",
|
|
1999
1931
|
XPD: "#A9ACB6",
|
|
2000
1932
|
default: "#6062a6",
|
|
@@ -549,15 +549,6 @@
|
|
|
549
549
|
"isListed": true,
|
|
550
550
|
"listingDate": "2024-11-22T00:00:00.000Z"
|
|
551
551
|
},
|
|
552
|
-
{
|
|
553
|
-
"name": "MKR/USD [ETH-USDC]",
|
|
554
|
-
"marketToken": "0x2aE5c5Cd4843cf588AA8D1289894318130acc823",
|
|
555
|
-
"indexToken": "0x8904De84c3bB3B7D2383F934Af40FcB3Ef82F28b",
|
|
556
|
-
"longToken": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
557
|
-
"shortToken": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
558
|
-
"isListed": true,
|
|
559
|
-
"listingDate": "2025-03-13T00:00:00.000Z"
|
|
560
|
-
},
|
|
561
552
|
{
|
|
562
553
|
"name": "ETH/USD [ETH-USDC]",
|
|
563
554
|
"marketToken": "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336",
|
|
@@ -657,24 +648,6 @@
|
|
|
657
648
|
"isListed": true,
|
|
658
649
|
"listingDate": "2024-11-21T00:00:00.000Z"
|
|
659
650
|
},
|
|
660
|
-
{
|
|
661
|
-
"name": "SWAP-ONLY [USDC-DAI]",
|
|
662
|
-
"marketToken": "0xe2fEDb9e6139a182B98e7C2688ccFa3e9A53c665",
|
|
663
|
-
"indexToken": "0x0000000000000000000000000000000000000000",
|
|
664
|
-
"longToken": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
665
|
-
"shortToken": "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
|
|
666
|
-
"isListed": true,
|
|
667
|
-
"listingDate": "2023-08-08T00:00:00.000Z"
|
|
668
|
-
},
|
|
669
|
-
{
|
|
670
|
-
"name": "KTA/USD [ETH-USDC]",
|
|
671
|
-
"marketToken": "0x970b730b5dD18de53A230eE8F4af088dBC3a6F8d",
|
|
672
|
-
"indexToken": "0x96Ee343E36E8642627FAEa235D57a9FEC8a6e34f",
|
|
673
|
-
"longToken": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
674
|
-
"shortToken": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
675
|
-
"isListed": true,
|
|
676
|
-
"listingDate": "2025-09-18T00:00:00.000Z"
|
|
677
|
-
},
|
|
678
651
|
{
|
|
679
652
|
"name": "CHZ/USD [ETH-USDC]",
|
|
680
653
|
"marketToken": "0x3600592DdEd7e6E0B05029DfB637fFc5A85D6f6B",
|
|
@@ -756,15 +729,6 @@
|
|
|
756
729
|
"isListed": true,
|
|
757
730
|
"listingDate": "2024-07-17T00:00:00.000Z"
|
|
758
731
|
},
|
|
759
|
-
{
|
|
760
|
-
"name": "AI16Z/USD [WBTC.b-USDC]",
|
|
761
|
-
"marketToken": "0xD60f1BA6a76979eFfE706BF090372Ebc0A5bF169",
|
|
762
|
-
"indexToken": "0xBb69bd9dc152C2c0F083507641a46193d2B61EBb",
|
|
763
|
-
"longToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
764
|
-
"shortToken": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
765
|
-
"isListed": true,
|
|
766
|
-
"listingDate": "2025-01-30T00:00:00.000Z"
|
|
767
|
-
},
|
|
768
732
|
{
|
|
769
733
|
"name": "CVX/USD [ETH-USDC]",
|
|
770
734
|
"marketToken": "0x41E3bC5B72384C8B26b559B7d16C2B81Fd36fbA2",
|
|
@@ -810,15 +774,6 @@
|
|
|
810
774
|
"isListed": true,
|
|
811
775
|
"listingDate": "2025-08-21T00:00:00.000Z"
|
|
812
776
|
},
|
|
813
|
-
{
|
|
814
|
-
"name": "MELANIA/USD [ETH-USDC]",
|
|
815
|
-
"marketToken": "0x12fD1A4BdB96219E637180Ff5293409502b2951D",
|
|
816
|
-
"indexToken": "0xfa4F8E582214eBCe1A08eB2a65e08082053E441F",
|
|
817
|
-
"longToken": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
818
|
-
"shortToken": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
819
|
-
"isListed": true,
|
|
820
|
-
"listingDate": "2025-01-23T00:00:00.000Z"
|
|
821
|
-
},
|
|
822
777
|
{
|
|
823
778
|
"name": "AVNT/USD [ETH-USDC]",
|
|
824
779
|
"marketToken": "0xCEff9D261A96Cb78Df35f9333ba9F2F4CFcb8a68",
|
|
@@ -828,15 +783,6 @@
|
|
|
828
783
|
"isListed": true,
|
|
829
784
|
"listingDate": "2025-10-09T00:00:00.000Z"
|
|
830
785
|
},
|
|
831
|
-
{
|
|
832
|
-
"name": "IP/USD [WBTC.b-USDC]",
|
|
833
|
-
"marketToken": "0x5ff52BE1968107D7886a8E9A64874A45c8F5D96a",
|
|
834
|
-
"indexToken": "0xe7304E9F4ca383BD6312a5179cdC7B40B96A6F5a",
|
|
835
|
-
"longToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
836
|
-
"shortToken": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
837
|
-
"isListed": true,
|
|
838
|
-
"listingDate": "2026-01-23T00:00:00.000Z"
|
|
839
|
-
},
|
|
840
786
|
{
|
|
841
787
|
"name": "LINK/USD [ETH-USDC]",
|
|
842
788
|
"marketToken": "0xF913B4748031EF569898ED91e5BA0d602bB93298",
|
|
@@ -1008,15 +954,6 @@
|
|
|
1008
954
|
"isListed": true,
|
|
1009
955
|
"listingDate": "2024-03-03T00:00:00.000Z"
|
|
1010
956
|
},
|
|
1011
|
-
{
|
|
1012
|
-
"name": "PI/USD [WBTC.b-USDC]",
|
|
1013
|
-
"marketToken": "0x39AC3C494950A4363D739201BA5A0861265C9ae5",
|
|
1014
|
-
"indexToken": "0xd1738d37401a0A71f7E382d2cFeCD3ab69687017",
|
|
1015
|
-
"longToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
1016
|
-
"shortToken": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
1017
|
-
"isListed": true,
|
|
1018
|
-
"listingDate": "2025-06-02T00:00:00.000Z"
|
|
1019
|
-
},
|
|
1020
957
|
{
|
|
1021
958
|
"name": "APT/USD [ETH-USDC]",
|
|
1022
959
|
"marketToken": "0x66A69c8eb98A7efE22A22611d1967dfec786a708",
|
|
@@ -1098,15 +1035,6 @@
|
|
|
1098
1035
|
"isListed": true,
|
|
1099
1036
|
"listingDate": "2025-03-06T00:00:00.000Z"
|
|
1100
1037
|
},
|
|
1101
|
-
{
|
|
1102
|
-
"name": "TON/USD [ETH-USDC]",
|
|
1103
|
-
"marketToken": "0x15c6eBD4175ffF9EE3c2615c556fCf62D2d9499c",
|
|
1104
|
-
"indexToken": "0xB2f7cefaeEb08Aa347705ac829a7b8bE2FB560f3",
|
|
1105
|
-
"longToken": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
1106
|
-
"shortToken": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
1107
|
-
"isListed": true,
|
|
1108
|
-
"listingDate": "2024-11-07T00:00:00.000Z"
|
|
1109
|
-
},
|
|
1110
1038
|
{
|
|
1111
1039
|
"name": "OP/USD [OP-USDC]",
|
|
1112
1040
|
"marketToken": "0x4fDd333FF9cA409df583f306B6F5a7fFdE790739",
|
|
@@ -155,3 +155,13 @@ data = "0x1", to = "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64", receiver = "0x1
|
|
|
155
155
|
},
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
|
+
/** Deterministic PRNG for property-style specs: a fixed seed keeps a failing case reproducible from the run alone. */
|
|
159
|
+
export function createSeededRandom(seed) {
|
|
160
|
+
let a = seed >>> 0;
|
|
161
|
+
return () => {
|
|
162
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
163
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
164
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
165
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
@@ -2,7 +2,7 @@ import { zeroHash } from "viem";
|
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { USD_DECIMALS } from "../../configs/factors";
|
|
4
4
|
import { mockMarketsInfoData, mockTokensData, usdToToken } from "../../test/mock";
|
|
5
|
-
import { getFundingFactorPerPeriod, getPriceImpactForPosition, getPriceImpactForSwap, getPriceImpactUsd, } from "../fees";
|
|
5
|
+
import { getFundingFactorPerPeriod, getPositionFee, getPriceImpactForPosition, getPriceImpactForSwap, getPriceImpactUsd, } from "../fees";
|
|
6
6
|
import { numberToBigint } from "../numbers";
|
|
7
7
|
import { convertToTokenAmountForIncrease } from "../tokens";
|
|
8
8
|
import { getDecreasePositionSizeDeltaInTokens } from "../trade/decrease";
|
|
@@ -324,3 +324,39 @@ describe("position price impact", () => {
|
|
|
324
324
|
expect(getPriceImpactForSwap(marketWithPositionInventoryChanges, marketWithPositionInventoryChanges.longToken, marketWithPositionInventoryChanges.shortToken, 100n * dollar, -100n * dollar)).toEqual(expected);
|
|
325
325
|
});
|
|
326
326
|
});
|
|
327
|
+
describe("getPositionFee", () => {
|
|
328
|
+
// 0.1% of 100 000 → 100 of opening fee
|
|
329
|
+
const marketInfo = {
|
|
330
|
+
positionFeeFactorForBalanceWasImproved: toFactor("0.05%"),
|
|
331
|
+
positionFeeFactorForBalanceWasNotImproved: toFactor("0.1%"),
|
|
332
|
+
};
|
|
333
|
+
const sizeDeltaUsd = 100000n * dollar;
|
|
334
|
+
// 10% of the fee is rebated, half of it goes back to the trader → 5 of discount
|
|
335
|
+
const referralInfo = { totalRebateFactor: toFactor("10%"), discountFactor: toFactor("50%") };
|
|
336
|
+
it("keeps the referral discount when no pro tier is set", () => {
|
|
337
|
+
const noPro = getPositionFee(marketInfo, sizeDeltaUsd, false, referralInfo);
|
|
338
|
+
const zeroPro = getPositionFee(marketInfo, sizeDeltaUsd, false, referralInfo, undefined, 0n);
|
|
339
|
+
expect(noPro.discountUsd).toBe(5n * dollar);
|
|
340
|
+
expect(noPro.positionFeeUsd).toBe(95n * dollar);
|
|
341
|
+
expect(zeroPro).toEqual(noPro);
|
|
342
|
+
});
|
|
343
|
+
it("takes the bigger of the pro and referral discounts, never their sum", () => {
|
|
344
|
+
const bigPro = getPositionFee(marketInfo, sizeDeltaUsd, false, referralInfo, undefined, toFactor("10%"));
|
|
345
|
+
expect(bigPro.discountUsd).toBe(10n * dollar);
|
|
346
|
+
expect(bigPro.positionFeeUsd).toBe(90n * dollar);
|
|
347
|
+
const smallPro = getPositionFee(marketInfo, sizeDeltaUsd, false, referralInfo, undefined, toFactor("3%"));
|
|
348
|
+
expect(smallPro.discountUsd).toBe(5n * dollar);
|
|
349
|
+
expect(smallPro.positionFeeUsd).toBe(95n * dollar);
|
|
350
|
+
});
|
|
351
|
+
it("is indifferent when the pro discount equals the referral one", () => {
|
|
352
|
+
const equalPro = getPositionFee(marketInfo, sizeDeltaUsd, false, referralInfo, undefined, toFactor("5%"));
|
|
353
|
+
expect(equalPro.discountUsd).toBe(5n * dollar);
|
|
354
|
+
expect(equalPro.positionFeeUsd).toBe(95n * dollar);
|
|
355
|
+
});
|
|
356
|
+
it("applies the pro discount without a referral code", () => {
|
|
357
|
+
const proOnly = getPositionFee(marketInfo, sizeDeltaUsd, false, undefined, undefined, toFactor("10%"));
|
|
358
|
+
expect(proOnly.totalRebateUsd).toBe(0n);
|
|
359
|
+
expect(proOnly.discountUsd).toBe(10n * dollar);
|
|
360
|
+
expect(proOnly.positionFeeUsd).toBe(90n * dollar);
|
|
361
|
+
});
|
|
362
|
+
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { ARBITRUM } from "../../configs/chains";
|
|
3
3
|
import { TOKENS } from "../../configs/tokens";
|
|
4
|
-
import {
|
|
4
|
+
import { mockMarketsInfoData, mockTokensData } from "../../test/mock";
|
|
5
|
+
import { getMarketFullName, getMarketIndexName, getMarketPoolName, getContractMarketPrices, getTokenPoolType, getPoolUsdWithoutPnl, getCappedPoolPnl, getMaxLeverageByMinCollateralFactor, getMaxAllowedLeverage, getOppositeCollateral, getAvailableUsdLiquidityForCollateral, getReservedUsd, getMarketDivisor, getMarketPnl, getOpenInterestUsd, getOpenInterestInTokens, getPositiveMarketPnl, getPriceForPnl, getMarketInfoWithOpenInterestDelta, getOpenInterestForBalance, } from "../markets";
|
|
5
6
|
import { BASIS_POINTS_DIVISOR, expandDecimals } from "../numbers";
|
|
7
|
+
import { convertToUsd } from "../tokens";
|
|
6
8
|
function getToken(symbol) {
|
|
7
9
|
return TOKENS[ARBITRUM].find((token) => token.symbol === symbol);
|
|
8
10
|
}
|
|
@@ -438,3 +440,234 @@ describe("getPriceForPnl", () => {
|
|
|
438
440
|
expect(getPriceForPnl({ minPrice: 1000n, maxPrice: 2000n }, false, false)).toBe(2000n);
|
|
439
441
|
});
|
|
440
442
|
});
|
|
443
|
+
describe("getMarketInfoWithOpenInterestDelta", () => {
|
|
444
|
+
const tokensData = mockTokensData();
|
|
445
|
+
function buildMarket(overrides = {}) {
|
|
446
|
+
return mockMarketsInfoData(tokensData, ["ETH-ETH-USDC"], {
|
|
447
|
+
"ETH-ETH-USDC": {
|
|
448
|
+
longInterestUsd: expandDecimals(1000, 30),
|
|
449
|
+
shortInterestUsd: expandDecimals(2000, 30),
|
|
450
|
+
longInterestInTokens: expandDecimals(1, 18),
|
|
451
|
+
shortInterestInTokens: expandDecimals(2, 18),
|
|
452
|
+
...overrides,
|
|
453
|
+
},
|
|
454
|
+
})["ETH-ETH-USDC"];
|
|
455
|
+
}
|
|
456
|
+
it("returns the market unchanged when there is no delta", () => {
|
|
457
|
+
const marketInfo = buildMarket();
|
|
458
|
+
expect(getMarketInfoWithOpenInterestDelta({
|
|
459
|
+
marketInfo,
|
|
460
|
+
collateralToken: marketInfo.shortToken,
|
|
461
|
+
isLong: true,
|
|
462
|
+
sizeDeltaUsd: 0n,
|
|
463
|
+
sizeDeltaInTokens: 0n,
|
|
464
|
+
})).toBe(marketInfo);
|
|
465
|
+
});
|
|
466
|
+
it("shifts only the long side for a long increase", () => {
|
|
467
|
+
const marketInfo = buildMarket();
|
|
468
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
469
|
+
marketInfo,
|
|
470
|
+
collateralToken: marketInfo.shortToken,
|
|
471
|
+
isLong: true,
|
|
472
|
+
sizeDeltaUsd: expandDecimals(500, 30),
|
|
473
|
+
sizeDeltaInTokens: expandDecimals(5, 17),
|
|
474
|
+
});
|
|
475
|
+
expect(next.longInterestUsd).toBe(expandDecimals(1500, 30));
|
|
476
|
+
expect(next.longInterestInTokens).toBe(expandDecimals(15, 17));
|
|
477
|
+
expect(next.shortInterestUsd).toBe(marketInfo.shortInterestUsd);
|
|
478
|
+
expect(next.shortInterestInTokens).toBe(marketInfo.shortInterestInTokens);
|
|
479
|
+
// the source market must not be mutated, it is shared across selectors
|
|
480
|
+
expect(marketInfo.longInterestUsd).toBe(expandDecimals(1000, 30));
|
|
481
|
+
});
|
|
482
|
+
it("shifts only the short side for a short increase", () => {
|
|
483
|
+
const marketInfo = buildMarket();
|
|
484
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
485
|
+
marketInfo,
|
|
486
|
+
collateralToken: marketInfo.shortToken,
|
|
487
|
+
isLong: false,
|
|
488
|
+
sizeDeltaUsd: expandDecimals(500, 30),
|
|
489
|
+
sizeDeltaInTokens: expandDecimals(5, 17),
|
|
490
|
+
});
|
|
491
|
+
expect(next.shortInterestUsd).toBe(expandDecimals(2500, 30));
|
|
492
|
+
expect(next.shortInterestInTokens).toBe(expandDecimals(25, 17));
|
|
493
|
+
expect(next.longInterestUsd).toBe(marketInfo.longInterestUsd);
|
|
494
|
+
expect(next.longInterestInTokens).toBe(marketInfo.longInterestInTokens);
|
|
495
|
+
});
|
|
496
|
+
it("carries the delta into the open interest used for balance in both modes", () => {
|
|
497
|
+
const sizeDeltaUsd = expandDecimals(500, 30);
|
|
498
|
+
const sizeDeltaInTokens = expandDecimals(5, 17);
|
|
499
|
+
const usdMarket = buildMarket({ useOpenInterestInTokensForBalance: false });
|
|
500
|
+
const usdNext = getMarketInfoWithOpenInterestDelta({
|
|
501
|
+
marketInfo: usdMarket,
|
|
502
|
+
collateralToken: usdMarket.shortToken,
|
|
503
|
+
isLong: true,
|
|
504
|
+
sizeDeltaUsd,
|
|
505
|
+
sizeDeltaInTokens,
|
|
506
|
+
});
|
|
507
|
+
expect(getOpenInterestForBalance(usdNext, true) - getOpenInterestForBalance(usdMarket, true)).toBe(sizeDeltaUsd);
|
|
508
|
+
const tokensMarket = buildMarket({ useOpenInterestInTokensForBalance: true });
|
|
509
|
+
const tokensNext = getMarketInfoWithOpenInterestDelta({
|
|
510
|
+
marketInfo: tokensMarket,
|
|
511
|
+
collateralToken: tokensMarket.shortToken,
|
|
512
|
+
isLong: true,
|
|
513
|
+
sizeDeltaUsd,
|
|
514
|
+
sizeDeltaInTokens,
|
|
515
|
+
});
|
|
516
|
+
const midPrice = (tokensMarket.indexToken.prices.minPrice + tokensMarket.indexToken.prices.maxPrice) / 2n;
|
|
517
|
+
expect(getOpenInterestForBalance(tokensNext, true) - getOpenInterestForBalance(tokensMarket, true)).toBe(convertToUsd(sizeDeltaInTokens, tokensMarket.indexToken.decimals, midPrice));
|
|
518
|
+
});
|
|
519
|
+
describe("per-collateral open interest projection", () => {
|
|
520
|
+
const sizeDeltaUsd = expandDecimals(500, 30);
|
|
521
|
+
const sizeDeltaInTokens = expandDecimals(5, 17);
|
|
522
|
+
const split = {
|
|
523
|
+
longInterestUsdUsingLongToken: expandDecimals(300, 30),
|
|
524
|
+
longInterestUsdUsingShortToken: expandDecimals(700, 30),
|
|
525
|
+
shortInterestUsdUsingLongToken: expandDecimals(1200, 30),
|
|
526
|
+
shortInterestUsdUsingShortToken: expandDecimals(800, 30),
|
|
527
|
+
longInterestInTokensUsingLongToken: expandDecimals(3, 17),
|
|
528
|
+
longInterestInTokensUsingShortToken: expandDecimals(7, 17),
|
|
529
|
+
shortInterestInTokensUsingLongToken: expandDecimals(12, 17),
|
|
530
|
+
shortInterestInTokensUsingShortToken: expandDecimals(8, 17),
|
|
531
|
+
};
|
|
532
|
+
it("moves a long increase with short-token collateral into the short-token leg", () => {
|
|
533
|
+
const marketInfo = buildMarket(split);
|
|
534
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
535
|
+
marketInfo,
|
|
536
|
+
collateralToken: marketInfo.shortToken,
|
|
537
|
+
isLong: true,
|
|
538
|
+
sizeDeltaUsd,
|
|
539
|
+
sizeDeltaInTokens,
|
|
540
|
+
});
|
|
541
|
+
expect(next.longInterestUsdUsingShortToken).toBe(expandDecimals(1200, 30));
|
|
542
|
+
expect(next.longInterestInTokensUsingShortToken).toBe(expandDecimals(12, 17));
|
|
543
|
+
expect(next.longInterestUsdUsingLongToken).toBe(split.longInterestUsdUsingLongToken);
|
|
544
|
+
expect(next.longInterestInTokensUsingLongToken).toBe(split.longInterestInTokensUsingLongToken);
|
|
545
|
+
expect(next.longInterestUsd).toBe(next.longInterestUsdUsingLongToken + next.longInterestUsdUsingShortToken);
|
|
546
|
+
expect(next.longInterestInTokens).toBe(next.longInterestInTokensUsingLongToken + next.longInterestInTokensUsingShortToken);
|
|
547
|
+
expect(next.shortInterestUsdUsingLongToken).toBe(split.shortInterestUsdUsingLongToken);
|
|
548
|
+
expect(next.shortInterestUsdUsingShortToken).toBe(split.shortInterestUsdUsingShortToken);
|
|
549
|
+
});
|
|
550
|
+
it("moves a long increase with long-token collateral into the long-token leg", () => {
|
|
551
|
+
const marketInfo = buildMarket(split);
|
|
552
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
553
|
+
marketInfo,
|
|
554
|
+
collateralToken: marketInfo.longToken,
|
|
555
|
+
isLong: true,
|
|
556
|
+
sizeDeltaUsd,
|
|
557
|
+
sizeDeltaInTokens,
|
|
558
|
+
});
|
|
559
|
+
expect(next.longInterestUsdUsingLongToken).toBe(expandDecimals(800, 30));
|
|
560
|
+
expect(next.longInterestInTokensUsingLongToken).toBe(expandDecimals(8, 17));
|
|
561
|
+
expect(next.longInterestUsdUsingShortToken).toBe(split.longInterestUsdUsingShortToken);
|
|
562
|
+
expect(next.longInterestInTokensUsingShortToken).toBe(split.longInterestInTokensUsingShortToken);
|
|
563
|
+
expect(next.longInterestUsd).toBe(next.longInterestUsdUsingLongToken + next.longInterestUsdUsingShortToken);
|
|
564
|
+
});
|
|
565
|
+
it("moves a short increase into the collateral leg of the short side", () => {
|
|
566
|
+
const marketInfo = buildMarket(split);
|
|
567
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
568
|
+
marketInfo,
|
|
569
|
+
collateralToken: marketInfo.shortToken,
|
|
570
|
+
isLong: false,
|
|
571
|
+
sizeDeltaUsd,
|
|
572
|
+
sizeDeltaInTokens,
|
|
573
|
+
});
|
|
574
|
+
expect(next.shortInterestUsdUsingShortToken).toBe(expandDecimals(1300, 30));
|
|
575
|
+
expect(next.shortInterestInTokensUsingShortToken).toBe(expandDecimals(13, 17));
|
|
576
|
+
expect(next.shortInterestUsdUsingLongToken).toBe(split.shortInterestUsdUsingLongToken);
|
|
577
|
+
expect(next.shortInterestInTokensUsingLongToken).toBe(split.shortInterestInTokensUsingLongToken);
|
|
578
|
+
expect(next.shortInterestUsd).toBe(next.shortInterestUsdUsingLongToken + next.shortInterestUsdUsingShortToken);
|
|
579
|
+
expect(next.shortInterestInTokens).toBe(next.shortInterestInTokensUsingLongToken + next.shortInterestInTokensUsingShortToken);
|
|
580
|
+
expect(next.longInterestUsdUsingShortToken).toBe(split.longInterestUsdUsingShortToken);
|
|
581
|
+
});
|
|
582
|
+
it("keeps the per-collateral pnl split consistent with the projected totals", () => {
|
|
583
|
+
const marketInfo = buildMarket(split);
|
|
584
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
585
|
+
marketInfo,
|
|
586
|
+
collateralToken: marketInfo.shortToken,
|
|
587
|
+
isLong: true,
|
|
588
|
+
sizeDeltaUsd,
|
|
589
|
+
sizeDeltaInTokens,
|
|
590
|
+
});
|
|
591
|
+
expect(getPositiveMarketPnl(next, true, false)).toBe(getMarketPnl(next, true, false));
|
|
592
|
+
});
|
|
593
|
+
it("leaves the per-collateral fields undefined when the market does not carry them", () => {
|
|
594
|
+
const marketInfo = buildMarket();
|
|
595
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
596
|
+
marketInfo,
|
|
597
|
+
collateralToken: marketInfo.shortToken,
|
|
598
|
+
isLong: true,
|
|
599
|
+
sizeDeltaUsd,
|
|
600
|
+
sizeDeltaInTokens,
|
|
601
|
+
});
|
|
602
|
+
expect(next.longInterestUsdUsingShortToken).toBeUndefined();
|
|
603
|
+
expect(next.longInterestInTokensUsingShortToken).toBeUndefined();
|
|
604
|
+
expect(next.longInterestUsd).toBe(expandDecimals(1500, 30));
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
describe("virtual inventory projection", () => {
|
|
608
|
+
// the contract's `applyDeltaToVirtualInventoryForPositions` no-ops on a zero virtualTokenId
|
|
609
|
+
const VIRTUAL_INDEX_TOKEN_ID = `0x${"1".repeat(64)}`;
|
|
610
|
+
const sizeDeltaUsd = expandDecimals(500, 30);
|
|
611
|
+
const sizeDeltaInTokens = expandDecimals(5, 17);
|
|
612
|
+
it("decreases the net-short virtual inventory for a long increase on a usd-OI market", () => {
|
|
613
|
+
const marketInfo = buildMarket({
|
|
614
|
+
virtualIndexTokenId: VIRTUAL_INDEX_TOKEN_ID,
|
|
615
|
+
useOpenInterestInTokensForBalance: false,
|
|
616
|
+
virtualInventoryForPositions: expandDecimals(300, 30),
|
|
617
|
+
});
|
|
618
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
619
|
+
marketInfo,
|
|
620
|
+
collateralToken: marketInfo.shortToken,
|
|
621
|
+
isLong: true,
|
|
622
|
+
sizeDeltaUsd,
|
|
623
|
+
sizeDeltaInTokens,
|
|
624
|
+
});
|
|
625
|
+
expect(next.virtualInventoryForPositions).toBe(-expandDecimals(200, 30));
|
|
626
|
+
expect(next.virtualInventoryForPositionsInTokens).toBe(marketInfo.virtualInventoryForPositionsInTokens);
|
|
627
|
+
});
|
|
628
|
+
it("increases the net-short virtual inventory for a short increase on a usd-OI market", () => {
|
|
629
|
+
const marketInfo = buildMarket({
|
|
630
|
+
virtualIndexTokenId: VIRTUAL_INDEX_TOKEN_ID,
|
|
631
|
+
useOpenInterestInTokensForBalance: false,
|
|
632
|
+
virtualInventoryForPositions: expandDecimals(300, 30),
|
|
633
|
+
});
|
|
634
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
635
|
+
marketInfo,
|
|
636
|
+
collateralToken: marketInfo.shortToken,
|
|
637
|
+
isLong: false,
|
|
638
|
+
sizeDeltaUsd,
|
|
639
|
+
sizeDeltaInTokens,
|
|
640
|
+
});
|
|
641
|
+
expect(next.virtualInventoryForPositions).toBe(expandDecimals(800, 30));
|
|
642
|
+
});
|
|
643
|
+
it("shifts the token-denominated virtual inventory on a token-OI market", () => {
|
|
644
|
+
const marketInfo = buildMarket({
|
|
645
|
+
virtualIndexTokenId: VIRTUAL_INDEX_TOKEN_ID,
|
|
646
|
+
useOpenInterestInTokensForBalance: true,
|
|
647
|
+
virtualInventoryForPositionsInTokens: expandDecimals(1, 18),
|
|
648
|
+
});
|
|
649
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
650
|
+
marketInfo,
|
|
651
|
+
collateralToken: marketInfo.shortToken,
|
|
652
|
+
isLong: true,
|
|
653
|
+
sizeDeltaUsd,
|
|
654
|
+
sizeDeltaInTokens,
|
|
655
|
+
});
|
|
656
|
+
expect(next.virtualInventoryForPositionsInTokens).toBe(expandDecimals(5, 17));
|
|
657
|
+
expect(next.virtualInventoryForPositions).toBe(marketInfo.virtualInventoryForPositions);
|
|
658
|
+
});
|
|
659
|
+
it("leaves the virtual inventory untouched when the market has none configured", () => {
|
|
660
|
+
// the default mock has virtualIndexTokenId = zeroHash and zero inventory
|
|
661
|
+
const marketInfo = buildMarket();
|
|
662
|
+
const next = getMarketInfoWithOpenInterestDelta({
|
|
663
|
+
marketInfo,
|
|
664
|
+
collateralToken: marketInfo.shortToken,
|
|
665
|
+
isLong: true,
|
|
666
|
+
sizeDeltaUsd,
|
|
667
|
+
sizeDeltaInTokens,
|
|
668
|
+
});
|
|
669
|
+
expect(next.virtualInventoryForPositions).toBe(0n);
|
|
670
|
+
expect(next.virtualInventoryForPositionsInTokens).toBe(0n);
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
});
|
|
@@ -42,10 +42,37 @@ function getLongPositionPnl(marketInfo) {
|
|
|
42
42
|
isLong: true,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
+
describe("per-position pnl cap — pool pnl price side", () => {
|
|
46
|
+
// the contract passes maximize = true into getPositivePnl: a long's pool pnl is valued at the index
|
|
47
|
+
// max price, so with a spread the cap ratio is smaller than at the min price
|
|
48
|
+
const ETH_MAX_PRICE = usd(2200);
|
|
49
|
+
function createSpreadMarketInfo() {
|
|
50
|
+
const tokensData = mockTokensData({ ETH: { prices: { minPrice: ETH_PRICE, maxPrice: ETH_MAX_PRICE } } });
|
|
51
|
+
return mockMarketsInfoData(tokensData, [MARKET_KEY], {
|
|
52
|
+
[MARKET_KEY]: {
|
|
53
|
+
longPoolAmount: eth(500),
|
|
54
|
+
maxPnlFactorForTradersLong: expandDecimals(9, 29),
|
|
55
|
+
longInterestUsd: usd(1000000),
|
|
56
|
+
longInterestInTokens: eth(1000),
|
|
57
|
+
longInterestUsdUsingLongToken: usd(1000000),
|
|
58
|
+
longInterestInTokensUsingLongToken: eth(1000),
|
|
59
|
+
longInterestUsdUsingShortToken: 0n,
|
|
60
|
+
longInterestInTokensUsingShortToken: 0n,
|
|
61
|
+
},
|
|
62
|
+
})[MARKET_KEY];
|
|
63
|
+
}
|
|
64
|
+
it("values a long's pool pnl at the index max price, as the contract does", () => {
|
|
65
|
+
// pool pnl: 1 000 ETH bought for $1 000 000 → +$1 000 000 at the min price, +$1 200 000 at the max price;
|
|
66
|
+
// the cap is 90% of the $1 000 000 pool → the position keeps 900/1200 of its pnl, not 900/1000
|
|
67
|
+
const pnl = getLongPositionPnl(createSpreadMarketInfo());
|
|
68
|
+
expect(pnl).toBe(usd(75000));
|
|
69
|
+
expect(pnl).not.toBe(usd(90000));
|
|
70
|
+
});
|
|
71
|
+
});
|
|
45
72
|
describe("per-position pnl cap (v2.2c parity)", () => {
|
|
46
73
|
it("caps against the positive-only pool pnl", () => {
|
|
47
74
|
const marketInfo = createMarketInfo();
|
|
48
|
-
expect(getPositiveMarketPnl(marketInfo, true,
|
|
75
|
+
expect(getPositiveMarketPnl(marketInfo, true, false)).toBe(usd(1000000));
|
|
49
76
|
expect(getLongPositionPnl(marketInfo)).toBe(usd(90000));
|
|
50
77
|
});
|
|
51
78
|
it("leaves the net pool pnl used by gm pool value untouched", () => {
|
|
@@ -59,7 +86,7 @@ describe("per-position pnl cap (v2.2c parity)", () => {
|
|
|
59
86
|
longInterestUsdUsingShortToken: undefined,
|
|
60
87
|
longInterestInTokensUsingShortToken: undefined,
|
|
61
88
|
});
|
|
62
|
-
expect(getPositiveMarketPnl(marketInfo, true,
|
|
89
|
+
expect(getPositiveMarketPnl(marketInfo, true, false)).toBe(usd(500000));
|
|
63
90
|
expect(getLongPositionPnl(marketInfo)).toBe(usd(100000));
|
|
64
91
|
});
|
|
65
92
|
it("matches the net pool pnl when both collateral buckets are winning", () => {
|
|
@@ -69,7 +96,7 @@ describe("per-position pnl cap (v2.2c parity)", () => {
|
|
|
69
96
|
longInterestUsd: usd(2000000),
|
|
70
97
|
longInterestInTokens: eth(1600),
|
|
71
98
|
});
|
|
72
|
-
expect(getPositiveMarketPnl(marketInfo, true,
|
|
99
|
+
expect(getPositiveMarketPnl(marketInfo, true, false)).toBe(usd(1200000));
|
|
73
100
|
expect(getMarketPnl(marketInfo, true, true)).toBe(usd(1200000));
|
|
74
101
|
expect(getLongPositionPnl(marketInfo)).toBe(usd(75000));
|
|
75
102
|
});
|