@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
|
@@ -450,15 +450,6 @@ exports.TOKENS = {
|
|
|
450
450
|
imageUrl: "https://assets.coingecko.com/coins/images/1094/standard/tron-logo.png?1696502193",
|
|
451
451
|
isSynthetic: true,
|
|
452
452
|
},
|
|
453
|
-
{
|
|
454
|
-
name: "TON",
|
|
455
|
-
symbol: "TON",
|
|
456
|
-
address: "0xB2f7cefaeEb08Aa347705ac829a7b8bE2FB560f3",
|
|
457
|
-
decimals: 9,
|
|
458
|
-
categories: ["layer1"],
|
|
459
|
-
imageUrl: "https://assets.coingecko.com/coins/images/17980/standard/photo_2024-09-10_17.09.00.jpeg?1725963446",
|
|
460
|
-
isSynthetic: true,
|
|
461
|
-
},
|
|
462
453
|
{
|
|
463
454
|
name: "WLD",
|
|
464
455
|
symbol: "WLD",
|
|
@@ -627,15 +618,6 @@ exports.TOKENS = {
|
|
|
627
618
|
imageUrl: "https://assets.coingecko.com/coins/images/53746/standard/trump.png?1737171561",
|
|
628
619
|
isSynthetic: true,
|
|
629
620
|
},
|
|
630
|
-
{
|
|
631
|
-
name: "Melania Meme",
|
|
632
|
-
symbol: "MELANIA",
|
|
633
|
-
address: "0xfa4F8E582214eBCe1A08eB2a65e08082053E441F",
|
|
634
|
-
decimals: 6,
|
|
635
|
-
categories: ["meme"],
|
|
636
|
-
imageUrl: "https://assets.coingecko.com/coins/images/53775/standard/melania-meme.png?1737329885",
|
|
637
|
-
isSynthetic: true,
|
|
638
|
-
},
|
|
639
621
|
{
|
|
640
622
|
name: "Ethena Governance Token",
|
|
641
623
|
symbol: "ENA",
|
|
@@ -645,15 +627,6 @@ exports.TOKENS = {
|
|
|
645
627
|
imageUrl: "https://assets.coingecko.com/coins/images/36530/standard/ethena.png?1711701436",
|
|
646
628
|
isSynthetic: true,
|
|
647
629
|
},
|
|
648
|
-
{
|
|
649
|
-
name: "ai16z",
|
|
650
|
-
symbol: "AI16Z",
|
|
651
|
-
address: "0xBb69bd9dc152C2c0F083507641a46193d2B61EBb",
|
|
652
|
-
decimals: 9,
|
|
653
|
-
categories: ["meme", "ai"],
|
|
654
|
-
imageUrl: "https://assets.coingecko.com/coins/images/51090/standard/AI16Z.jpg?1730027175",
|
|
655
|
-
isSynthetic: true,
|
|
656
|
-
},
|
|
657
630
|
{
|
|
658
631
|
name: "Animecoin",
|
|
659
632
|
symbol: "ANIME",
|
|
@@ -771,24 +744,6 @@ exports.TOKENS = {
|
|
|
771
744
|
imageUrl: "https://assets.coingecko.com/coins/images/34188/standard/jup.png?1704266489",
|
|
772
745
|
isSynthetic: true,
|
|
773
746
|
},
|
|
774
|
-
{
|
|
775
|
-
name: "Maker",
|
|
776
|
-
symbol: "MKR",
|
|
777
|
-
address: "0x8904De84c3bB3B7D2383F934Af40FcB3Ef82F28b",
|
|
778
|
-
decimals: 18,
|
|
779
|
-
categories: ["defi"],
|
|
780
|
-
imageUrl: "https://assets.coingecko.com/coins/images/1364/standard/Mark_Maker.png?1696502423",
|
|
781
|
-
isSynthetic: true,
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
name: "MANTRA",
|
|
785
|
-
symbol: "OM",
|
|
786
|
-
address: "0x1f3407Ea067DfBDF6dEb6bBFdA4869215fB0ab77",
|
|
787
|
-
decimals: 18,
|
|
788
|
-
categories: ["layer1"],
|
|
789
|
-
imageUrl: "https://assets.coingecko.com/coins/images/12151/standard/OM_Token.png?1696511991",
|
|
790
|
-
isSynthetic: true,
|
|
791
|
-
},
|
|
792
747
|
{
|
|
793
748
|
name: "Dolomite",
|
|
794
749
|
symbol: "DOLO",
|
|
@@ -825,15 +780,6 @@ exports.TOKENS = {
|
|
|
825
780
|
imageUrl: "https://assets.coingecko.com/coins/images/69/standard/monero_logo.png?1696501460",
|
|
826
781
|
categories: ["layer1"],
|
|
827
782
|
},
|
|
828
|
-
{
|
|
829
|
-
name: "Pi Network",
|
|
830
|
-
symbol: "PI",
|
|
831
|
-
address: "0xd1738d37401a0A71f7E382d2cFeCD3ab69687017",
|
|
832
|
-
decimals: 18,
|
|
833
|
-
isSynthetic: true,
|
|
834
|
-
imageUrl: "https://assets.coingecko.com/coins/images/54342/standard/pi_network.jpg?1739347576",
|
|
835
|
-
categories: ["layer1"],
|
|
836
|
-
},
|
|
837
783
|
{
|
|
838
784
|
name: "Curve DAO Token",
|
|
839
785
|
symbol: "CRV",
|
|
@@ -995,24 +941,6 @@ exports.TOKENS = {
|
|
|
995
941
|
categories: ["ai"],
|
|
996
942
|
imageUrl: "https://assets.coingecko.com/coins/images/54023/standard/VVV_Token_Transparent.png?1741856877",
|
|
997
943
|
},
|
|
998
|
-
{
|
|
999
|
-
name: "Moonwell",
|
|
1000
|
-
symbol: "WELL",
|
|
1001
|
-
address: "0x465A31E5bA29b8EAcC860d499D714a6f07e56E85",
|
|
1002
|
-
decimals: 18,
|
|
1003
|
-
isSynthetic: true,
|
|
1004
|
-
categories: ["defi"],
|
|
1005
|
-
imageUrl: "https://assets.coingecko.com/coins/images/26133/standard/WELL.png?1696525221",
|
|
1006
|
-
},
|
|
1007
|
-
{
|
|
1008
|
-
name: "KTA",
|
|
1009
|
-
symbol: "KTA",
|
|
1010
|
-
decimals: 18,
|
|
1011
|
-
address: "0x96Ee343E36E8642627FAEa235D57a9FEC8a6e34f",
|
|
1012
|
-
isSynthetic: true,
|
|
1013
|
-
categories: ["layer1"],
|
|
1014
|
-
imageUrl: "https://assets.coingecko.com/coins/images/54693/standard/zora.jpg?1741094751",
|
|
1015
|
-
},
|
|
1016
944
|
{
|
|
1017
945
|
name: "Zora",
|
|
1018
946
|
symbol: "ZORA",
|
|
@@ -1159,15 +1087,6 @@ exports.TOKENS = {
|
|
|
1159
1087
|
categories: ["defi"],
|
|
1160
1088
|
imageUrl: "https://assets.coingecko.com/coins/images/71121/standard/lighter.png?1765888098",
|
|
1161
1089
|
},
|
|
1162
|
-
{
|
|
1163
|
-
name: "Story",
|
|
1164
|
-
symbol: "IP",
|
|
1165
|
-
address: "0xe7304E9F4ca383BD6312a5179cdC7B40B96A6F5a",
|
|
1166
|
-
isSynthetic: true,
|
|
1167
|
-
decimals: 18,
|
|
1168
|
-
categories: ["layer1"],
|
|
1169
|
-
imageUrl: "https://assets.coingecko.com/coins/images/54035/standard/Transparent_bg.png?1738075331",
|
|
1170
|
-
},
|
|
1171
1090
|
{
|
|
1172
1091
|
name: "Canton",
|
|
1173
1092
|
symbol: "CC",
|
|
@@ -1250,6 +1169,26 @@ exports.TOKENS = {
|
|
|
1250
1169
|
searchAliases: ["Space", "X"],
|
|
1251
1170
|
explorerUrl: "https://arbiscan.io/token/0x8CBd0d5d81e7957123E6D8fFaE657a40bDC5691b",
|
|
1252
1171
|
},
|
|
1172
|
+
{
|
|
1173
|
+
name: "Invesco QQQ Trust",
|
|
1174
|
+
symbol: "QQQ",
|
|
1175
|
+
address: "0xfe71D55D0080b6995Ec2C3f48b7702c86e200766",
|
|
1176
|
+
isSynthetic: true,
|
|
1177
|
+
decimals: 18,
|
|
1178
|
+
categories: ["tradfi", "indices"],
|
|
1179
|
+
searchAliases: ["Nasdaq", "Nasdaq-100", "NDX", "Invesco"],
|
|
1180
|
+
explorerUrl: "https://arbiscan.io/token/0xfe71D55D0080b6995Ec2C3f48b7702c86e200766",
|
|
1181
|
+
},
|
|
1182
|
+
{
|
|
1183
|
+
name: "SPDR S&P 500 ETF",
|
|
1184
|
+
symbol: "SPY",
|
|
1185
|
+
address: "0x0315441076FF6d3eA09814a2F90a1f980cF03e9e",
|
|
1186
|
+
isSynthetic: true,
|
|
1187
|
+
decimals: 18,
|
|
1188
|
+
categories: ["tradfi", "indices"],
|
|
1189
|
+
searchAliases: ["S&P", "S&P 500", "SPX", "SPDR"],
|
|
1190
|
+
explorerUrl: "https://arbiscan.io/token/0x0315441076FF6d3eA09814a2F90a1f980cF03e9e",
|
|
1191
|
+
},
|
|
1253
1192
|
{
|
|
1254
1193
|
name: "MegaETH",
|
|
1255
1194
|
symbol: "MEGA",
|
|
@@ -1362,15 +1301,6 @@ exports.TOKENS = {
|
|
|
1362
1301
|
imageUrl: "https://assets.coingecko.com/coins/images/325/small/Tether-logo.png",
|
|
1363
1302
|
explorerUrl: "https://snowtrace.io/address/0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
|
|
1364
1303
|
},
|
|
1365
|
-
{
|
|
1366
|
-
name: "Dai",
|
|
1367
|
-
symbol: "DAI.E",
|
|
1368
|
-
address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
|
|
1369
|
-
decimals: 18,
|
|
1370
|
-
isStable: true,
|
|
1371
|
-
imageUrl: "https://assets.coingecko.com/coins/images/9956/thumb/4943.png?1636636734",
|
|
1372
|
-
explorerUrl: "https://snowtrace.io/address/0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
|
|
1373
|
-
},
|
|
1374
1304
|
{
|
|
1375
1305
|
name: "Magic Internet Money",
|
|
1376
1306
|
symbol: "MIM",
|
|
@@ -1998,6 +1928,8 @@ exports.TOKEN_COLOR_MAP = {
|
|
|
1998
1928
|
GOLD: "#D69A00",
|
|
1999
1929
|
SILVER: "#ADABB8",
|
|
2000
1930
|
SPCX: "#1A1E21",
|
|
1931
|
+
QQQ: "#000AD2",
|
|
1932
|
+
SPY: "#273F33",
|
|
2001
1933
|
XPT: "#C2B8AB",
|
|
2002
1934
|
XPD: "#A9ACB6",
|
|
2003
1935
|
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",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockExternalSwap = exports.mockMarketsInfoData = exports.mockMarketsData = exports.mockTokensData = exports.mockMarketKeys = exports.MOCK_GAS_PRICE = exports.usdToToken = void 0;
|
|
3
|
+
exports.createSeededRandom = exports.mockExternalSwap = exports.mockMarketsInfoData = exports.mockMarketsData = exports.mockTokensData = exports.mockMarketKeys = exports.MOCK_GAS_PRICE = exports.usdToToken = void 0;
|
|
4
4
|
const factors_1 = require("../configs/factors");
|
|
5
5
|
const numbers_1 = require("../utils/numbers");
|
|
6
6
|
const tokens_1 = require("../utils/tokens");
|
|
@@ -164,3 +164,14 @@ data = "0x1", to = "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64", receiver = "0x1
|
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
166
|
exports.mockExternalSwap = mockExternalSwap;
|
|
167
|
+
/** Deterministic PRNG for property-style specs: a fixed seed keeps a failing case reproducible from the run alone. */
|
|
168
|
+
function createSeededRandom(seed) {
|
|
169
|
+
let a = seed >>> 0;
|
|
170
|
+
return () => {
|
|
171
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
172
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
173
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
174
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
exports.createSeededRandom = createSeededRandom;
|
|
@@ -326,3 +326,39 @@ function makePriceImpactMarket(overrides = {}) {
|
|
|
326
326
|
(0, vitest_1.expect)((0, fees_1.getPriceImpactForSwap)(marketWithPositionInventoryChanges, marketWithPositionInventoryChanges.longToken, marketWithPositionInventoryChanges.shortToken, 100n * dollar, -100n * dollar)).toEqual(expected);
|
|
327
327
|
});
|
|
328
328
|
});
|
|
329
|
+
(0, vitest_1.describe)("getPositionFee", () => {
|
|
330
|
+
// 0.1% of 100 000 → 100 of opening fee
|
|
331
|
+
const marketInfo = {
|
|
332
|
+
positionFeeFactorForBalanceWasImproved: toFactor("0.05%"),
|
|
333
|
+
positionFeeFactorForBalanceWasNotImproved: toFactor("0.1%"),
|
|
334
|
+
};
|
|
335
|
+
const sizeDeltaUsd = 100000n * dollar;
|
|
336
|
+
// 10% of the fee is rebated, half of it goes back to the trader → 5 of discount
|
|
337
|
+
const referralInfo = { totalRebateFactor: toFactor("10%"), discountFactor: toFactor("50%") };
|
|
338
|
+
(0, vitest_1.it)("keeps the referral discount when no pro tier is set", () => {
|
|
339
|
+
const noPro = (0, fees_1.getPositionFee)(marketInfo, sizeDeltaUsd, false, referralInfo);
|
|
340
|
+
const zeroPro = (0, fees_1.getPositionFee)(marketInfo, sizeDeltaUsd, false, referralInfo, undefined, 0n);
|
|
341
|
+
(0, vitest_1.expect)(noPro.discountUsd).toBe(5n * dollar);
|
|
342
|
+
(0, vitest_1.expect)(noPro.positionFeeUsd).toBe(95n * dollar);
|
|
343
|
+
(0, vitest_1.expect)(zeroPro).toEqual(noPro);
|
|
344
|
+
});
|
|
345
|
+
(0, vitest_1.it)("takes the bigger of the pro and referral discounts, never their sum", () => {
|
|
346
|
+
const bigPro = (0, fees_1.getPositionFee)(marketInfo, sizeDeltaUsd, false, referralInfo, undefined, toFactor("10%"));
|
|
347
|
+
(0, vitest_1.expect)(bigPro.discountUsd).toBe(10n * dollar);
|
|
348
|
+
(0, vitest_1.expect)(bigPro.positionFeeUsd).toBe(90n * dollar);
|
|
349
|
+
const smallPro = (0, fees_1.getPositionFee)(marketInfo, sizeDeltaUsd, false, referralInfo, undefined, toFactor("3%"));
|
|
350
|
+
(0, vitest_1.expect)(smallPro.discountUsd).toBe(5n * dollar);
|
|
351
|
+
(0, vitest_1.expect)(smallPro.positionFeeUsd).toBe(95n * dollar);
|
|
352
|
+
});
|
|
353
|
+
(0, vitest_1.it)("is indifferent when the pro discount equals the referral one", () => {
|
|
354
|
+
const equalPro = (0, fees_1.getPositionFee)(marketInfo, sizeDeltaUsd, false, referralInfo, undefined, toFactor("5%"));
|
|
355
|
+
(0, vitest_1.expect)(equalPro.discountUsd).toBe(5n * dollar);
|
|
356
|
+
(0, vitest_1.expect)(equalPro.positionFeeUsd).toBe(95n * dollar);
|
|
357
|
+
});
|
|
358
|
+
(0, vitest_1.it)("applies the pro discount without a referral code", () => {
|
|
359
|
+
const proOnly = (0, fees_1.getPositionFee)(marketInfo, sizeDeltaUsd, false, undefined, undefined, toFactor("10%"));
|
|
360
|
+
(0, vitest_1.expect)(proOnly.totalRebateUsd).toBe(0n);
|
|
361
|
+
(0, vitest_1.expect)(proOnly.discountUsd).toBe(10n * dollar);
|
|
362
|
+
(0, vitest_1.expect)(proOnly.positionFeeUsd).toBe(90n * dollar);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const chains_1 = require("../../configs/chains");
|
|
5
5
|
const tokens_1 = require("../../configs/tokens");
|
|
6
|
+
const mock_1 = require("../../test/mock");
|
|
6
7
|
const markets_1 = require("../markets");
|
|
7
8
|
const numbers_1 = require("../numbers");
|
|
9
|
+
const tokens_2 = require("../tokens");
|
|
8
10
|
function getToken(symbol) {
|
|
9
11
|
return tokens_1.TOKENS[chains_1.ARBITRUM].find((token) => token.symbol === symbol);
|
|
10
12
|
}
|
|
@@ -440,3 +442,234 @@ function getToken(symbol) {
|
|
|
440
442
|
(0, vitest_1.expect)((0, markets_1.getPriceForPnl)({ minPrice: 1000n, maxPrice: 2000n }, false, false)).toBe(2000n);
|
|
441
443
|
});
|
|
442
444
|
});
|
|
445
|
+
(0, vitest_1.describe)("getMarketInfoWithOpenInterestDelta", () => {
|
|
446
|
+
const tokensData = (0, mock_1.mockTokensData)();
|
|
447
|
+
function buildMarket(overrides = {}) {
|
|
448
|
+
return (0, mock_1.mockMarketsInfoData)(tokensData, ["ETH-ETH-USDC"], {
|
|
449
|
+
"ETH-ETH-USDC": {
|
|
450
|
+
longInterestUsd: (0, numbers_1.expandDecimals)(1000, 30),
|
|
451
|
+
shortInterestUsd: (0, numbers_1.expandDecimals)(2000, 30),
|
|
452
|
+
longInterestInTokens: (0, numbers_1.expandDecimals)(1, 18),
|
|
453
|
+
shortInterestInTokens: (0, numbers_1.expandDecimals)(2, 18),
|
|
454
|
+
...overrides,
|
|
455
|
+
},
|
|
456
|
+
})["ETH-ETH-USDC"];
|
|
457
|
+
}
|
|
458
|
+
(0, vitest_1.it)("returns the market unchanged when there is no delta", () => {
|
|
459
|
+
const marketInfo = buildMarket();
|
|
460
|
+
(0, vitest_1.expect)((0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
461
|
+
marketInfo,
|
|
462
|
+
collateralToken: marketInfo.shortToken,
|
|
463
|
+
isLong: true,
|
|
464
|
+
sizeDeltaUsd: 0n,
|
|
465
|
+
sizeDeltaInTokens: 0n,
|
|
466
|
+
})).toBe(marketInfo);
|
|
467
|
+
});
|
|
468
|
+
(0, vitest_1.it)("shifts only the long side for a long increase", () => {
|
|
469
|
+
const marketInfo = buildMarket();
|
|
470
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
471
|
+
marketInfo,
|
|
472
|
+
collateralToken: marketInfo.shortToken,
|
|
473
|
+
isLong: true,
|
|
474
|
+
sizeDeltaUsd: (0, numbers_1.expandDecimals)(500, 30),
|
|
475
|
+
sizeDeltaInTokens: (0, numbers_1.expandDecimals)(5, 17),
|
|
476
|
+
});
|
|
477
|
+
(0, vitest_1.expect)(next.longInterestUsd).toBe((0, numbers_1.expandDecimals)(1500, 30));
|
|
478
|
+
(0, vitest_1.expect)(next.longInterestInTokens).toBe((0, numbers_1.expandDecimals)(15, 17));
|
|
479
|
+
(0, vitest_1.expect)(next.shortInterestUsd).toBe(marketInfo.shortInterestUsd);
|
|
480
|
+
(0, vitest_1.expect)(next.shortInterestInTokens).toBe(marketInfo.shortInterestInTokens);
|
|
481
|
+
// the source market must not be mutated, it is shared across selectors
|
|
482
|
+
(0, vitest_1.expect)(marketInfo.longInterestUsd).toBe((0, numbers_1.expandDecimals)(1000, 30));
|
|
483
|
+
});
|
|
484
|
+
(0, vitest_1.it)("shifts only the short side for a short increase", () => {
|
|
485
|
+
const marketInfo = buildMarket();
|
|
486
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
487
|
+
marketInfo,
|
|
488
|
+
collateralToken: marketInfo.shortToken,
|
|
489
|
+
isLong: false,
|
|
490
|
+
sizeDeltaUsd: (0, numbers_1.expandDecimals)(500, 30),
|
|
491
|
+
sizeDeltaInTokens: (0, numbers_1.expandDecimals)(5, 17),
|
|
492
|
+
});
|
|
493
|
+
(0, vitest_1.expect)(next.shortInterestUsd).toBe((0, numbers_1.expandDecimals)(2500, 30));
|
|
494
|
+
(0, vitest_1.expect)(next.shortInterestInTokens).toBe((0, numbers_1.expandDecimals)(25, 17));
|
|
495
|
+
(0, vitest_1.expect)(next.longInterestUsd).toBe(marketInfo.longInterestUsd);
|
|
496
|
+
(0, vitest_1.expect)(next.longInterestInTokens).toBe(marketInfo.longInterestInTokens);
|
|
497
|
+
});
|
|
498
|
+
(0, vitest_1.it)("carries the delta into the open interest used for balance in both modes", () => {
|
|
499
|
+
const sizeDeltaUsd = (0, numbers_1.expandDecimals)(500, 30);
|
|
500
|
+
const sizeDeltaInTokens = (0, numbers_1.expandDecimals)(5, 17);
|
|
501
|
+
const usdMarket = buildMarket({ useOpenInterestInTokensForBalance: false });
|
|
502
|
+
const usdNext = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
503
|
+
marketInfo: usdMarket,
|
|
504
|
+
collateralToken: usdMarket.shortToken,
|
|
505
|
+
isLong: true,
|
|
506
|
+
sizeDeltaUsd,
|
|
507
|
+
sizeDeltaInTokens,
|
|
508
|
+
});
|
|
509
|
+
(0, vitest_1.expect)((0, markets_1.getOpenInterestForBalance)(usdNext, true) - (0, markets_1.getOpenInterestForBalance)(usdMarket, true)).toBe(sizeDeltaUsd);
|
|
510
|
+
const tokensMarket = buildMarket({ useOpenInterestInTokensForBalance: true });
|
|
511
|
+
const tokensNext = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
512
|
+
marketInfo: tokensMarket,
|
|
513
|
+
collateralToken: tokensMarket.shortToken,
|
|
514
|
+
isLong: true,
|
|
515
|
+
sizeDeltaUsd,
|
|
516
|
+
sizeDeltaInTokens,
|
|
517
|
+
});
|
|
518
|
+
const midPrice = (tokensMarket.indexToken.prices.minPrice + tokensMarket.indexToken.prices.maxPrice) / 2n;
|
|
519
|
+
(0, vitest_1.expect)((0, markets_1.getOpenInterestForBalance)(tokensNext, true) - (0, markets_1.getOpenInterestForBalance)(tokensMarket, true)).toBe((0, tokens_2.convertToUsd)(sizeDeltaInTokens, tokensMarket.indexToken.decimals, midPrice));
|
|
520
|
+
});
|
|
521
|
+
(0, vitest_1.describe)("per-collateral open interest projection", () => {
|
|
522
|
+
const sizeDeltaUsd = (0, numbers_1.expandDecimals)(500, 30);
|
|
523
|
+
const sizeDeltaInTokens = (0, numbers_1.expandDecimals)(5, 17);
|
|
524
|
+
const split = {
|
|
525
|
+
longInterestUsdUsingLongToken: (0, numbers_1.expandDecimals)(300, 30),
|
|
526
|
+
longInterestUsdUsingShortToken: (0, numbers_1.expandDecimals)(700, 30),
|
|
527
|
+
shortInterestUsdUsingLongToken: (0, numbers_1.expandDecimals)(1200, 30),
|
|
528
|
+
shortInterestUsdUsingShortToken: (0, numbers_1.expandDecimals)(800, 30),
|
|
529
|
+
longInterestInTokensUsingLongToken: (0, numbers_1.expandDecimals)(3, 17),
|
|
530
|
+
longInterestInTokensUsingShortToken: (0, numbers_1.expandDecimals)(7, 17),
|
|
531
|
+
shortInterestInTokensUsingLongToken: (0, numbers_1.expandDecimals)(12, 17),
|
|
532
|
+
shortInterestInTokensUsingShortToken: (0, numbers_1.expandDecimals)(8, 17),
|
|
533
|
+
};
|
|
534
|
+
(0, vitest_1.it)("moves a long increase with short-token collateral into the short-token leg", () => {
|
|
535
|
+
const marketInfo = buildMarket(split);
|
|
536
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
537
|
+
marketInfo,
|
|
538
|
+
collateralToken: marketInfo.shortToken,
|
|
539
|
+
isLong: true,
|
|
540
|
+
sizeDeltaUsd,
|
|
541
|
+
sizeDeltaInTokens,
|
|
542
|
+
});
|
|
543
|
+
(0, vitest_1.expect)(next.longInterestUsdUsingShortToken).toBe((0, numbers_1.expandDecimals)(1200, 30));
|
|
544
|
+
(0, vitest_1.expect)(next.longInterestInTokensUsingShortToken).toBe((0, numbers_1.expandDecimals)(12, 17));
|
|
545
|
+
(0, vitest_1.expect)(next.longInterestUsdUsingLongToken).toBe(split.longInterestUsdUsingLongToken);
|
|
546
|
+
(0, vitest_1.expect)(next.longInterestInTokensUsingLongToken).toBe(split.longInterestInTokensUsingLongToken);
|
|
547
|
+
(0, vitest_1.expect)(next.longInterestUsd).toBe(next.longInterestUsdUsingLongToken + next.longInterestUsdUsingShortToken);
|
|
548
|
+
(0, vitest_1.expect)(next.longInterestInTokens).toBe(next.longInterestInTokensUsingLongToken + next.longInterestInTokensUsingShortToken);
|
|
549
|
+
(0, vitest_1.expect)(next.shortInterestUsdUsingLongToken).toBe(split.shortInterestUsdUsingLongToken);
|
|
550
|
+
(0, vitest_1.expect)(next.shortInterestUsdUsingShortToken).toBe(split.shortInterestUsdUsingShortToken);
|
|
551
|
+
});
|
|
552
|
+
(0, vitest_1.it)("moves a long increase with long-token collateral into the long-token leg", () => {
|
|
553
|
+
const marketInfo = buildMarket(split);
|
|
554
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
555
|
+
marketInfo,
|
|
556
|
+
collateralToken: marketInfo.longToken,
|
|
557
|
+
isLong: true,
|
|
558
|
+
sizeDeltaUsd,
|
|
559
|
+
sizeDeltaInTokens,
|
|
560
|
+
});
|
|
561
|
+
(0, vitest_1.expect)(next.longInterestUsdUsingLongToken).toBe((0, numbers_1.expandDecimals)(800, 30));
|
|
562
|
+
(0, vitest_1.expect)(next.longInterestInTokensUsingLongToken).toBe((0, numbers_1.expandDecimals)(8, 17));
|
|
563
|
+
(0, vitest_1.expect)(next.longInterestUsdUsingShortToken).toBe(split.longInterestUsdUsingShortToken);
|
|
564
|
+
(0, vitest_1.expect)(next.longInterestInTokensUsingShortToken).toBe(split.longInterestInTokensUsingShortToken);
|
|
565
|
+
(0, vitest_1.expect)(next.longInterestUsd).toBe(next.longInterestUsdUsingLongToken + next.longInterestUsdUsingShortToken);
|
|
566
|
+
});
|
|
567
|
+
(0, vitest_1.it)("moves a short increase into the collateral leg of the short side", () => {
|
|
568
|
+
const marketInfo = buildMarket(split);
|
|
569
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
570
|
+
marketInfo,
|
|
571
|
+
collateralToken: marketInfo.shortToken,
|
|
572
|
+
isLong: false,
|
|
573
|
+
sizeDeltaUsd,
|
|
574
|
+
sizeDeltaInTokens,
|
|
575
|
+
});
|
|
576
|
+
(0, vitest_1.expect)(next.shortInterestUsdUsingShortToken).toBe((0, numbers_1.expandDecimals)(1300, 30));
|
|
577
|
+
(0, vitest_1.expect)(next.shortInterestInTokensUsingShortToken).toBe((0, numbers_1.expandDecimals)(13, 17));
|
|
578
|
+
(0, vitest_1.expect)(next.shortInterestUsdUsingLongToken).toBe(split.shortInterestUsdUsingLongToken);
|
|
579
|
+
(0, vitest_1.expect)(next.shortInterestInTokensUsingLongToken).toBe(split.shortInterestInTokensUsingLongToken);
|
|
580
|
+
(0, vitest_1.expect)(next.shortInterestUsd).toBe(next.shortInterestUsdUsingLongToken + next.shortInterestUsdUsingShortToken);
|
|
581
|
+
(0, vitest_1.expect)(next.shortInterestInTokens).toBe(next.shortInterestInTokensUsingLongToken + next.shortInterestInTokensUsingShortToken);
|
|
582
|
+
(0, vitest_1.expect)(next.longInterestUsdUsingShortToken).toBe(split.longInterestUsdUsingShortToken);
|
|
583
|
+
});
|
|
584
|
+
(0, vitest_1.it)("keeps the per-collateral pnl split consistent with the projected totals", () => {
|
|
585
|
+
const marketInfo = buildMarket(split);
|
|
586
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
587
|
+
marketInfo,
|
|
588
|
+
collateralToken: marketInfo.shortToken,
|
|
589
|
+
isLong: true,
|
|
590
|
+
sizeDeltaUsd,
|
|
591
|
+
sizeDeltaInTokens,
|
|
592
|
+
});
|
|
593
|
+
(0, vitest_1.expect)((0, markets_1.getPositiveMarketPnl)(next, true, false)).toBe((0, markets_1.getMarketPnl)(next, true, false));
|
|
594
|
+
});
|
|
595
|
+
(0, vitest_1.it)("leaves the per-collateral fields undefined when the market does not carry them", () => {
|
|
596
|
+
const marketInfo = buildMarket();
|
|
597
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
598
|
+
marketInfo,
|
|
599
|
+
collateralToken: marketInfo.shortToken,
|
|
600
|
+
isLong: true,
|
|
601
|
+
sizeDeltaUsd,
|
|
602
|
+
sizeDeltaInTokens,
|
|
603
|
+
});
|
|
604
|
+
(0, vitest_1.expect)(next.longInterestUsdUsingShortToken).toBeUndefined();
|
|
605
|
+
(0, vitest_1.expect)(next.longInterestInTokensUsingShortToken).toBeUndefined();
|
|
606
|
+
(0, vitest_1.expect)(next.longInterestUsd).toBe((0, numbers_1.expandDecimals)(1500, 30));
|
|
607
|
+
});
|
|
608
|
+
});
|
|
609
|
+
(0, vitest_1.describe)("virtual inventory projection", () => {
|
|
610
|
+
// the contract's `applyDeltaToVirtualInventoryForPositions` no-ops on a zero virtualTokenId
|
|
611
|
+
const VIRTUAL_INDEX_TOKEN_ID = `0x${"1".repeat(64)}`;
|
|
612
|
+
const sizeDeltaUsd = (0, numbers_1.expandDecimals)(500, 30);
|
|
613
|
+
const sizeDeltaInTokens = (0, numbers_1.expandDecimals)(5, 17);
|
|
614
|
+
(0, vitest_1.it)("decreases the net-short virtual inventory for a long increase on a usd-OI market", () => {
|
|
615
|
+
const marketInfo = buildMarket({
|
|
616
|
+
virtualIndexTokenId: VIRTUAL_INDEX_TOKEN_ID,
|
|
617
|
+
useOpenInterestInTokensForBalance: false,
|
|
618
|
+
virtualInventoryForPositions: (0, numbers_1.expandDecimals)(300, 30),
|
|
619
|
+
});
|
|
620
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
621
|
+
marketInfo,
|
|
622
|
+
collateralToken: marketInfo.shortToken,
|
|
623
|
+
isLong: true,
|
|
624
|
+
sizeDeltaUsd,
|
|
625
|
+
sizeDeltaInTokens,
|
|
626
|
+
});
|
|
627
|
+
(0, vitest_1.expect)(next.virtualInventoryForPositions).toBe(-(0, numbers_1.expandDecimals)(200, 30));
|
|
628
|
+
(0, vitest_1.expect)(next.virtualInventoryForPositionsInTokens).toBe(marketInfo.virtualInventoryForPositionsInTokens);
|
|
629
|
+
});
|
|
630
|
+
(0, vitest_1.it)("increases the net-short virtual inventory for a short increase on a usd-OI market", () => {
|
|
631
|
+
const marketInfo = buildMarket({
|
|
632
|
+
virtualIndexTokenId: VIRTUAL_INDEX_TOKEN_ID,
|
|
633
|
+
useOpenInterestInTokensForBalance: false,
|
|
634
|
+
virtualInventoryForPositions: (0, numbers_1.expandDecimals)(300, 30),
|
|
635
|
+
});
|
|
636
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
637
|
+
marketInfo,
|
|
638
|
+
collateralToken: marketInfo.shortToken,
|
|
639
|
+
isLong: false,
|
|
640
|
+
sizeDeltaUsd,
|
|
641
|
+
sizeDeltaInTokens,
|
|
642
|
+
});
|
|
643
|
+
(0, vitest_1.expect)(next.virtualInventoryForPositions).toBe((0, numbers_1.expandDecimals)(800, 30));
|
|
644
|
+
});
|
|
645
|
+
(0, vitest_1.it)("shifts the token-denominated virtual inventory on a token-OI market", () => {
|
|
646
|
+
const marketInfo = buildMarket({
|
|
647
|
+
virtualIndexTokenId: VIRTUAL_INDEX_TOKEN_ID,
|
|
648
|
+
useOpenInterestInTokensForBalance: true,
|
|
649
|
+
virtualInventoryForPositionsInTokens: (0, numbers_1.expandDecimals)(1, 18),
|
|
650
|
+
});
|
|
651
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
652
|
+
marketInfo,
|
|
653
|
+
collateralToken: marketInfo.shortToken,
|
|
654
|
+
isLong: true,
|
|
655
|
+
sizeDeltaUsd,
|
|
656
|
+
sizeDeltaInTokens,
|
|
657
|
+
});
|
|
658
|
+
(0, vitest_1.expect)(next.virtualInventoryForPositionsInTokens).toBe((0, numbers_1.expandDecimals)(5, 17));
|
|
659
|
+
(0, vitest_1.expect)(next.virtualInventoryForPositions).toBe(marketInfo.virtualInventoryForPositions);
|
|
660
|
+
});
|
|
661
|
+
(0, vitest_1.it)("leaves the virtual inventory untouched when the market has none configured", () => {
|
|
662
|
+
// the default mock has virtualIndexTokenId = zeroHash and zero inventory
|
|
663
|
+
const marketInfo = buildMarket();
|
|
664
|
+
const next = (0, markets_1.getMarketInfoWithOpenInterestDelta)({
|
|
665
|
+
marketInfo,
|
|
666
|
+
collateralToken: marketInfo.shortToken,
|
|
667
|
+
isLong: true,
|
|
668
|
+
sizeDeltaUsd,
|
|
669
|
+
sizeDeltaInTokens,
|
|
670
|
+
});
|
|
671
|
+
(0, vitest_1.expect)(next.virtualInventoryForPositions).toBe(0n);
|
|
672
|
+
(0, vitest_1.expect)(next.virtualInventoryForPositionsInTokens).toBe(0n);
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
});
|
|
@@ -44,10 +44,37 @@ function getLongPositionPnl(marketInfo) {
|
|
|
44
44
|
isLong: true,
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
+
(0, vitest_1.describe)("per-position pnl cap — pool pnl price side", () => {
|
|
48
|
+
// the contract passes maximize = true into getPositivePnl: a long's pool pnl is valued at the index
|
|
49
|
+
// max price, so with a spread the cap ratio is smaller than at the min price
|
|
50
|
+
const ETH_MAX_PRICE = usd(2200);
|
|
51
|
+
function createSpreadMarketInfo() {
|
|
52
|
+
const tokensData = (0, mock_1.mockTokensData)({ ETH: { prices: { minPrice: ETH_PRICE, maxPrice: ETH_MAX_PRICE } } });
|
|
53
|
+
return (0, mock_1.mockMarketsInfoData)(tokensData, [MARKET_KEY], {
|
|
54
|
+
[MARKET_KEY]: {
|
|
55
|
+
longPoolAmount: eth(500),
|
|
56
|
+
maxPnlFactorForTradersLong: (0, numbers_1.expandDecimals)(9, 29),
|
|
57
|
+
longInterestUsd: usd(1000000),
|
|
58
|
+
longInterestInTokens: eth(1000),
|
|
59
|
+
longInterestUsdUsingLongToken: usd(1000000),
|
|
60
|
+
longInterestInTokensUsingLongToken: eth(1000),
|
|
61
|
+
longInterestUsdUsingShortToken: 0n,
|
|
62
|
+
longInterestInTokensUsingShortToken: 0n,
|
|
63
|
+
},
|
|
64
|
+
})[MARKET_KEY];
|
|
65
|
+
}
|
|
66
|
+
(0, vitest_1.it)("values a long's pool pnl at the index max price, as the contract does", () => {
|
|
67
|
+
// pool pnl: 1 000 ETH bought for $1 000 000 → +$1 000 000 at the min price, +$1 200 000 at the max price;
|
|
68
|
+
// the cap is 90% of the $1 000 000 pool → the position keeps 900/1200 of its pnl, not 900/1000
|
|
69
|
+
const pnl = getLongPositionPnl(createSpreadMarketInfo());
|
|
70
|
+
(0, vitest_1.expect)(pnl).toBe(usd(75000));
|
|
71
|
+
(0, vitest_1.expect)(pnl).not.toBe(usd(90000));
|
|
72
|
+
});
|
|
73
|
+
});
|
|
47
74
|
(0, vitest_1.describe)("per-position pnl cap (v2.2c parity)", () => {
|
|
48
75
|
(0, vitest_1.it)("caps against the positive-only pool pnl", () => {
|
|
49
76
|
const marketInfo = createMarketInfo();
|
|
50
|
-
(0, vitest_1.expect)((0, markets_1.getPositiveMarketPnl)(marketInfo, true,
|
|
77
|
+
(0, vitest_1.expect)((0, markets_1.getPositiveMarketPnl)(marketInfo, true, false)).toBe(usd(1000000));
|
|
51
78
|
(0, vitest_1.expect)(getLongPositionPnl(marketInfo)).toBe(usd(90000));
|
|
52
79
|
});
|
|
53
80
|
(0, vitest_1.it)("leaves the net pool pnl used by gm pool value untouched", () => {
|
|
@@ -61,7 +88,7 @@ function getLongPositionPnl(marketInfo) {
|
|
|
61
88
|
longInterestUsdUsingShortToken: undefined,
|
|
62
89
|
longInterestInTokensUsingShortToken: undefined,
|
|
63
90
|
});
|
|
64
|
-
(0, vitest_1.expect)((0, markets_1.getPositiveMarketPnl)(marketInfo, true,
|
|
91
|
+
(0, vitest_1.expect)((0, markets_1.getPositiveMarketPnl)(marketInfo, true, false)).toBe(usd(500000));
|
|
65
92
|
(0, vitest_1.expect)(getLongPositionPnl(marketInfo)).toBe(usd(100000));
|
|
66
93
|
});
|
|
67
94
|
(0, vitest_1.it)("matches the net pool pnl when both collateral buckets are winning", () => {
|
|
@@ -71,7 +98,7 @@ function getLongPositionPnl(marketInfo) {
|
|
|
71
98
|
longInterestUsd: usd(2000000),
|
|
72
99
|
longInterestInTokens: eth(1600),
|
|
73
100
|
});
|
|
74
|
-
(0, vitest_1.expect)((0, markets_1.getPositiveMarketPnl)(marketInfo, true,
|
|
101
|
+
(0, vitest_1.expect)((0, markets_1.getPositiveMarketPnl)(marketInfo, true, false)).toBe(usd(1200000));
|
|
75
102
|
(0, vitest_1.expect)((0, markets_1.getMarketPnl)(marketInfo, true, true)).toBe(usd(1200000));
|
|
76
103
|
(0, vitest_1.expect)(getLongPositionPnl(marketInfo)).toBe(usd(75000));
|
|
77
104
|
});
|