@gmx-io/sdk 1.5.0-alpha-13 → 1.5.0-alpha-15

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.
Files changed (61) hide show
  1. package/build/cjs/scripts/subsquid-codegen.js +1 -1
  2. package/build/cjs/src/clients/v1/modules/trades/trades.js +4 -0
  3. package/build/cjs/src/clients/v2/__tests__/decrease.spec.js +12 -12
  4. package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -0
  5. package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +122 -0
  6. package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +30 -0
  7. package/build/cjs/src/codegen/subsquid.js +30 -0
  8. package/build/cjs/src/configs/markets.js +14 -0
  9. package/build/cjs/src/configs/tokens.js +18 -0
  10. package/build/cjs/src/test/mock.js +1 -0
  11. package/build/cjs/src/utils/__tests__/markets.spec.js +88 -48
  12. package/build/cjs/src/utils/__tests__/positions.spec.js +93 -0
  13. package/build/cjs/src/utils/markets/utils.js +23 -14
  14. package/build/cjs/src/utils/orderTransactions/utils.js +2 -2
  15. package/build/cjs/src/utils/orderTransactions/validateTypedData.js +3 -3
  16. package/build/cjs/src/utils/positions/utils.js +34 -2
  17. package/build/cjs/src/utils/prices/utils.js +4 -4
  18. package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  19. package/build/cjs/src/utils/trade/decrease.js +1 -1
  20. package/build/cjs/src/utils/trade/increase.js +1 -1
  21. package/build/cjs/src/utils/trade/trade.js +0 -7
  22. package/build/cjs/src/utils/tradeHistory/utils.js +2 -0
  23. package/build/cjs/src/utils/twap/index.js +4 -10
  24. package/build/esm/scripts/subsquid-codegen.js +1 -1
  25. package/build/esm/src/clients/v1/modules/trades/trades.js +4 -0
  26. package/build/esm/src/clients/v2/__tests__/decrease.spec.js +12 -12
  27. package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -0
  28. package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +122 -0
  29. package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +30 -0
  30. package/build/esm/src/codegen/subsquid.js +30 -0
  31. package/build/esm/src/configs/markets.js +14 -0
  32. package/build/esm/src/configs/tokens.js +18 -0
  33. package/build/esm/src/test/mock.js +1 -0
  34. package/build/esm/src/utils/__tests__/markets.spec.js +90 -50
  35. package/build/esm/src/utils/__tests__/positions.spec.js +94 -1
  36. package/build/esm/src/utils/markets/utils.js +21 -13
  37. package/build/esm/src/utils/orderTransactions/utils.js +2 -2
  38. package/build/esm/src/utils/orderTransactions/validateTypedData.js +3 -3
  39. package/build/esm/src/utils/positions/utils.js +32 -2
  40. package/build/esm/src/utils/prices/utils.js +4 -4
  41. package/build/esm/src/utils/subaccount/index.js +2 -2
  42. package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  43. package/build/esm/src/utils/trade/decrease.js +1 -1
  44. package/build/esm/src/utils/trade/increase.js +1 -1
  45. package/build/esm/src/utils/trade/trade.js +0 -7
  46. package/build/esm/src/utils/tradeHistory/utils.js +2 -0
  47. package/build/esm/src/utils/twap/index.js +4 -10
  48. package/build/types/src/codegen/prebuilt/index.d.ts +168 -0
  49. package/build/types/src/codegen/subsquid.d.ts +77 -0
  50. package/build/types/src/utils/markets/utils.d.ts +6 -1
  51. package/build/types/src/utils/positions/types.d.ts +3 -0
  52. package/build/types/src/utils/positions/utils.d.ts +15 -0
  53. package/build/types/src/utils/prices/utils.d.ts +1 -1
  54. package/build/types/src/utils/subaccount/index.d.ts +2 -2
  55. package/build/types/src/utils/swap/types.d.ts +1 -1
  56. package/build/types/src/utils/trade/types.d.ts +4 -1
  57. package/build/types/src/utils/tradeHistory/types.d.ts +2 -0
  58. package/package.json +1 -1
  59. package/build/cjs/src/configs/marketHours.js +0 -27
  60. package/build/esm/src/configs/marketHours.js +0 -24
  61. package/build/types/src/configs/marketHours.d.ts +0 -7
@@ -368,6 +368,67 @@
368
368
  "virtualLongTokenId": "0x4dd17e45519b6398f395ed0297a67002668c720c17b5043a9623eec83970f300",
369
369
  "virtualShortTokenId": "0x4dd17e45519b6398f395ed0297a67002668c720c17b5043a9623eec83970f300"
370
370
  },
371
+ "0x1b997cb4841c4cb360E384192fFd7fb26eb10e5f": {
372
+ "isDisabled": "0xd8fdace800a4c83103aac9891b4b0f603cacb5305c5076797aa485655594fbba",
373
+ "maxLongPoolAmount": "0xb52e46073affb270b6f5d2dc00e98cad8a137299a18a8e508586b2a7bcc35bd8",
374
+ "maxShortPoolAmount": "0xb52e46073affb270b6f5d2dc00e98cad8a137299a18a8e508586b2a7bcc35bd8",
375
+ "maxLongPoolUsdForDeposit": "0x94073087e28bbd60148240b2ce84a26e792b28e42c3b4bee84c72e6309e55cd2",
376
+ "maxShortPoolUsdForDeposit": "0x94073087e28bbd60148240b2ce84a26e792b28e42c3b4bee84c72e6309e55cd2",
377
+ "reserveFactorLong": "0x369dfbbd5bb64557fa36bc15ae1b8668c400cbc248d2917fe1d3a6f8f7219c33",
378
+ "reserveFactorShort": "0x9d21778e6afe89fdf514be686b911dc469d7bbcc272ceb3b728dff8c6725eced",
379
+ "openInterestReserveFactorLong": "0xd40ff444859dc18c5c99c2ad33d835171e96bbfba7e2dd1b621fec903bb5b26f",
380
+ "openInterestReserveFactorShort": "0x0aa887953050ac21e878045372a940f9cd5c7370a49659f4cec39e51608eb25b",
381
+ "maxOpenInterestLong": "0x9bf240e704d3a75ad35f37d325c02f9aa3e3bc02a0061819c157fbf99455b4b2",
382
+ "maxOpenInterestShort": "0x7015edd7708aad6bd8c52eeab753a1d43558e8a88141855c08da48cc025d752b",
383
+ "minPositionImpactPoolAmount": "0x59afbf7aab6b95a001ffc02754acccd335f43d8d73eeb1fc58097be04a65ad90",
384
+ "positionImpactPoolDistributionRate": "0x534fadcfe9045d76308222b719d22bfb4d7e0881458fd9cc9d95f79763549226",
385
+ "borrowingFactorLong": "0x484562949038cd0cbbe2beb697a8c563b25a9bee77f13c025b34c11eb1264d51",
386
+ "borrowingFactorShort": "0x101a7a04ac633c7478beb76e600ec8d6a27725084c97dc23c93821b6622ee5e6",
387
+ "borrowingExponentFactorLong": "0x054e13a201541edbefbb70d6ca8a7b9f14f513d5b7ab1dbe2d3e58ebf8767376",
388
+ "borrowingExponentFactorShort": "0x117b4960427b5ba19e22cf93bc9e0dc6d89426111b88a430b8e9fb6a9413495c",
389
+ "fundingFactor": "0xa18c4f5b34c81270b08e91be081b6040bad2514f1b12ac9f1da4e472185f9937",
390
+ "fundingExponentFactor": "0xa302c1dd3f51344f25a107b2903d4a45d2e709824a47a5ecd89b77830445ce21",
391
+ "fundingIncreaseFactorPerSecond": "0xfdf029005c5bbf7488cf5db211c03304d8623404c14b81adb0f38e982c39c7ab",
392
+ "fundingDecreaseFactorPerSecond": "0x054a421c8ecc4bfb234c69e84018b01d3f0d1953c48597d1facaa90bea8a6da1",
393
+ "thresholdForStableFunding": "0xd451f4dca402c5f7831b6aa93949eb90578cf3f29b6f9ca1c8d3ecca7dc24de8",
394
+ "thresholdForDecreaseFunding": "0x1cbf36f58c5c89089f8623b9e58833f6371ce29511f2527d0778f7d17d66442e",
395
+ "minFundingFactorPerSecond": "0xf4c570cac7658d1f41dbe1d8a4a2598ce64dd697b0d9c36a6c08b0460ea284b1",
396
+ "maxFundingFactorPerSecond": "0xbbdf760355c10d81f9c346cfa565a144b46661f4be1a5c935cf7b36aaa94f0d7",
397
+ "maxPnlFactorForTradersLong": "0xe9c8aa945fe362a35ee9c317c50f140c6a5df1352e216e6bc30482a9934d475b",
398
+ "maxPnlFactorForTradersShort": "0x28a5854c2725559105d5bca89fa9c7ceabf49430aed49f3d8dfc5a2833df7457",
399
+ "maxPnlFactorForDepositsLong": "0x377f3e2436e51f8bb7332330849c77996db1e76d229c2eb5a9f5f47fd91e65c3",
400
+ "maxPnlFactorForDepositsShort": "0xd731e8084bc74a0e994fac10db3654bd08f57f431dcc10cd2d5e6e9e9bccd0d0",
401
+ "maxPnlFactorForWithdrawalsLong": "0xc3052b80166d473af290a5768304eba8da1e5b462928e8db98ef2ef3e13c91a9",
402
+ "maxPnlFactorForWithdrawalsShort": "0xa9f2024c292786d21122e14295c43d240cbcc385c4af7f7ded06ed594000ece4",
403
+ "positionFeeFactorForBalanceWasImproved": "0xa849fe5cb11f7f9a1aaf701389c202932d3651423178cd6cede552bedb565e85",
404
+ "positionFeeFactorForBalanceWasNotImproved": "0x8095c13a6bc72dbb84db6a9eecb56d37430d29c6446ec655f622d767d7ae992b",
405
+ "positionImpactFactorPositive": "0x740cbf46e81788450458231e648ab3b7b6dc06471829b69fb8a54bc3de4933f4",
406
+ "positionImpactFactorNegative": "0xebc5abe9d1e4c055b0ab182e3a551da01cd828092262a6f07c49c028e209a813",
407
+ "maxPositionImpactFactorPositive": "0xd84068c13d3a491e6642477684c2ef451109403ed3ca9d039a14e78982be9368",
408
+ "maxPositionImpactFactorNegative": "0xaf5f3c3187540ff281a3d49e4e0afc5e8e308a604f70ad372f3023e0d5e4ffb4",
409
+ "maxPositionImpactFactorForLiquidations": "0xee97beca8510a130e1453e6a7c5379a8f7bd94e2a37ca53376272936066af40c",
410
+ "maxLendableImpactFactor": "0x81e965d17630c3f7dd83d54d0043d1e3bfd41e3e23e5f05a586ae5cb06fb2808",
411
+ "maxLendableImpactFactorForWithdrawals": "0xcdb2169f71d16c22b6e551c1ab0fc214aa479433fa4cb94aa89c009eea1a90ae",
412
+ "maxLendableImpactUsd": "0xe57be8dd7792c817a637e22edc476a5140f9e354ade4c031a797c2b47139aa14",
413
+ "lentPositionImpactPoolAmount": "0x68e288e46bd9c3ed97d759789c40371fe3b2c147ff5d037794deeb8bd4ca2662",
414
+ "minCollateralFactor": "0x060ba8a608ecb3021894ff1cff3acd35dcd83acc4d7981f35f355b8e1a076efb",
415
+ "minCollateralFactorForLiquidation": "0xe1578f327b7b4953642dad58e4f612cae1e391ca6e51b53634d09d605adb04df",
416
+ "minCollateralFactorForOpenInterestLong": "0x17d58eaa937f738d247a46f930afb3c3fa0de9540be3dca06d20a0183383f9f5",
417
+ "minCollateralFactorForOpenInterestShort": "0xbc94908e04903c9fbe6bd7c10a393f399f76309bed48b442700a22ac336b1328",
418
+ "positionImpactExponentFactorPositive": "0x507225ae0c269eb456c901de710d5ce0b705580247cdd3d7f16385e195c3f697",
419
+ "positionImpactExponentFactorNegative": "0x0ce571c47f1c3983d18f63d176fb4ab9d01939ab1c03bb84a80fddb63d62e336",
420
+ "swapFeeFactorForBalanceWasImproved": "0xeed9ff6954c0738b72ee0b621ccf6abb300c04144d26dedc84fb808347ab0ef9",
421
+ "swapFeeFactorForBalanceWasNotImproved": "0x8b73f0ed4e83703c38d5f3cff850400da1a662b66cb592721f88ef714e901511",
422
+ "atomicSwapFeeFactor": "0x9d3eeeb6b5fb7f0905214874c795d5b66904525cfcb3baf9bf733e2c815678c8",
423
+ "swapImpactFactorPositive": "0xca6c5e6f90beaecf6bf2c4cb9082e2d471801c1de7a8f7a91689445228106a43",
424
+ "swapImpactFactorNegative": "0xf74a4061682bd6d5aa64f8d08fd89c9d1ddced12e2e0475bc5c1f3f06fbb911f",
425
+ "swapImpactExponentFactor": "0x4b40eaab0e60f6d02e307833005e61fb34b6e39332230c89ae08bae39911c850",
426
+ "withdrawalFeeFactorBalanceWasImproved": "0xd3bd872399788f44b1e62e8073d472855c67cb110a4b8f59787fd6de42bb2345",
427
+ "withdrawalFeeFactorBalanceWasNotImproved": "0x9f5f46d8bdd1d690a8e165e5092b5b69f90a5f88342f9ed0626b67742f84383a",
428
+ "virtualMarketId": "0x0e87938496e6015d1c2770872fe2980107d17adbce91f327a9b79e3615c9d3ef",
429
+ "virtualLongTokenId": "0x4dd17e45519b6398f395ed0297a67002668c720c17b5043a9623eec83970f300",
430
+ "virtualShortTokenId": "0x4dd17e45519b6398f395ed0297a67002668c720c17b5043a9623eec83970f300"
431
+ },
371
432
  "0xc5c9B5E23810565763De41144741477eeCB25e2e": {
372
433
  "isDisabled": "0xa49e0fc2306a1447bc9bd8c575d55503e7c332ac97b4d679e428c7fe8fa9cf91",
373
434
  "maxLongPoolAmount": "0x95faa8ab4cb72d45ef4d4b5497dff66d75e31840f083692073d40a804384f3d4",
@@ -8482,6 +8543,67 @@
8482
8543
  "virtualMarketId": "0x0972819d24db7fb85b0d03ee48c64ce38c97f76b27b8c12da91c070c8604b4ef",
8483
8544
  "virtualLongTokenId": "0xaab37f889b9680dda34f58a689de3023cb22f7ae14d32a3c1d45798a973db1f5",
8484
8545
  "virtualShortTokenId": "0xd5258cb84f0039be58306488e8df941c05f3cf4f219e92aacb6561c736bbb960"
8546
+ },
8547
+ "0xE26E7b91143f367445f1c0a5dCf4f4aC8EaDcDb1": {
8548
+ "isDisabled": "0x89d68641baa8443dcff05c06834a08f6a7c1edef759f2e89505fe251b6411cb5",
8549
+ "maxLongPoolAmount": "0x5c7eb3fb9940700a0eb6d0bc4b2efcec205e4bcd85611f2e63a40fb71b48a68b",
8550
+ "maxShortPoolAmount": "0xe728cf4596862b756ee8448e5477a5e2fe86f4615e86dbf8c346f289601bed4e",
8551
+ "maxLongPoolUsdForDeposit": "0x2b6c1f929f22df9fb3fbc8be79bf3c13c295bbf901c86479bb72e13c6322f311",
8552
+ "maxShortPoolUsdForDeposit": "0xdf9340c2699bb63d0d94e1699f94b67e5ccdb02a196ae3564f0fa67407fd5e14",
8553
+ "reserveFactorLong": "0x942b7baddb60c077d5709214cd5016edaf9326f0a82bef4a44e49c5fca0bed1f",
8554
+ "reserveFactorShort": "0x2d0c83c7f490492743ff305ff8f74c9cb1b0e9d2aed4ea96701697e9f3341334",
8555
+ "openInterestReserveFactorLong": "0x6bfce544dd3b467e6fef0037c39c0c3f67bd864a120acac1613b082aa235b971",
8556
+ "openInterestReserveFactorShort": "0xd6b19d01cdaa02f545273ee699126b49bdd7873cfce6a08f05899cb6c325b565",
8557
+ "maxOpenInterestLong": "0xc1e39a6acef065c09d69a01bb7eb76fef233f9a18cc1b6b074a7d6749de8f73c",
8558
+ "maxOpenInterestShort": "0xc11f4f78c57d7038516959a3fe36ed21919629c78b9dc96d4816d8e62e94726b",
8559
+ "minPositionImpactPoolAmount": "0x1b19fc708a5e2bb9049340fd6b0c9082e4677cc3180085f5a5b6fb0f8d8ae2a6",
8560
+ "positionImpactPoolDistributionRate": "0x82c016e3ad8dc55a677aae0bf9c1e67c8eebd94c4ff89cc974f9309079560748",
8561
+ "borrowingFactorLong": "0x1c84d12dc97018270af71b43842ed10639ff72873e9fb6a90b3032f7112934f7",
8562
+ "borrowingFactorShort": "0x3e95c2ba01960e2493ad89e0338aa4de3013bcd9cb4a3a8cd57b3a4e45142184",
8563
+ "borrowingExponentFactorLong": "0x65835087ab6457e46152b877b5cd1c48195208eec5a3dbeeeeb2e67399541920",
8564
+ "borrowingExponentFactorShort": "0xaf117b7aa763361627572fd0fc9ade6f86574962938033a1dddcb315830728c6",
8565
+ "fundingFactor": "0x6907267fc1b40efd0baa3386f28bb4bf3d6acbc95a6ec68e2be14cd4717809bc",
8566
+ "fundingExponentFactor": "0x4e67a86568a3ede53741d8fc1a497bf0129737c45035ab8fe47b738f8a7f8817",
8567
+ "fundingIncreaseFactorPerSecond": "0xc523d172916b7d185a87546732859612302bcfa1350c2fcaf5969a92a1421220",
8568
+ "fundingDecreaseFactorPerSecond": "0x4df236653ce9022fc7d434b4030c13f8d8c29b26c4bdc840f2ac5402cac306e3",
8569
+ "thresholdForStableFunding": "0xb3e20cff381d08f506fdc80d7b297637d93a6f0af665ce35c830a6c40df05cfa",
8570
+ "thresholdForDecreaseFunding": "0xe66d926cf13dd61685065230c5e677277a6216e486c8b87e7f66a63edc65e763",
8571
+ "minFundingFactorPerSecond": "0x74889040fc831d355b2db59ca6ce334987ae4a0a239ea7a5a26a2a2f54b548f4",
8572
+ "maxFundingFactorPerSecond": "0x7c955ef7e4de4a1959a5d14bb2dd13740c69e6a5499cf641dca8623fe8ed6625",
8573
+ "maxPnlFactorForTradersLong": "0xc2c237f5732794e8b70391ca156529fd8c8d03ea8e6745f925235991046db9c0",
8574
+ "maxPnlFactorForTradersShort": "0x2803e3c558f0310f6695a1f7ea2d065dbdcaf93285819c8044241f1c710e86d2",
8575
+ "maxPnlFactorForDepositsLong": "0xe4ef00881de9d0d7f6859e056d5a2322da73d4bd5eff978b55124a74c012f22a",
8576
+ "maxPnlFactorForDepositsShort": "0xcc75b2513c89b534cfd96e83e3602c3a495348eb1b011289bcab35eb7199d9bc",
8577
+ "maxPnlFactorForWithdrawalsLong": "0xd8a9dd2bf131f01d79b3a6ae5ebf4c07a921a3de7fa51ed28d4ae9890db5cff2",
8578
+ "maxPnlFactorForWithdrawalsShort": "0xa20ea8793827abdebb98815ab39f78243d9767fc96f7e6ddad331dfb84074537",
8579
+ "positionFeeFactorForBalanceWasImproved": "0x2e53b5a6d4eb857bed982666571b5e9f5262f8e5547f3464d5ef31239644f359",
8580
+ "positionFeeFactorForBalanceWasNotImproved": "0x6598798bc9a742ad80e3a067aeb00d2424a148e7cdb8387b2590809918d36f03",
8581
+ "positionImpactFactorPositive": "0xa607759df0905173feec89316d1dc1870cb12771da02d98fa0b2da11f250591e",
8582
+ "positionImpactFactorNegative": "0xcc48be879067c2c1f3239969109e641aa7915b31a950f52a8f1188d0074307c7",
8583
+ "maxPositionImpactFactorPositive": "0xaa439c0da01e92726f3e3614854dd0c9ffe0f9e071ac9ee627c79d110d1d05f4",
8584
+ "maxPositionImpactFactorNegative": "0x07995cd17dad67176b276d778ceb73de0cf26154e9534b510182bb592a491bb2",
8585
+ "maxPositionImpactFactorForLiquidations": "0x04eca53675ea95c36b24e6e843e9e9fb9ee6973f62c05062c426d6f5021aa8aa",
8586
+ "maxLendableImpactFactor": "0x8ca83545dfede07c09ac1fc94a639437785ab14f4b093688e0969588dca6f47f",
8587
+ "maxLendableImpactFactorForWithdrawals": "0x99916a49999fd164beb6992efd4fedb8beeda13c7e88d91025166c8f399984fd",
8588
+ "maxLendableImpactUsd": "0xdc3e2b698a345ac01ab2414afafde24f515f1784565534b33ac0a1e5040b59c2",
8589
+ "lentPositionImpactPoolAmount": "0xb9d9b2f6fa8030ee74c62e7d379e2401e5a6611173f68177414cd37868378e37",
8590
+ "minCollateralFactor": "0xace080b8e8a0d464623d586df742acb186715348c1025fb6d57721c8ff4c1d95",
8591
+ "minCollateralFactorForLiquidation": "0x824059faab4ca34a6ded9708af7a4db6f8c4b808f56f8603e8500f209b0ff5d1",
8592
+ "minCollateralFactorForOpenInterestLong": "0x9b9d4c83bd445c665c57218f3479082ded3a92ace65be3043152b6531786e866",
8593
+ "minCollateralFactorForOpenInterestShort": "0x3335401ee45a10c6928f296e77d8e755d284a29043125cb087c41cd072aa8dda",
8594
+ "positionImpactExponentFactorPositive": "0x0fad9e8d6acccf7b405515de6ecbfdd5158a650667adedc3f292b50b20305359",
8595
+ "positionImpactExponentFactorNegative": "0x2a8d8c25729ceb36b9aef38a35db0fcf013a058ad7f1643cda26b4ba5d53e532",
8596
+ "swapFeeFactorForBalanceWasImproved": "0xc0e7bdcacb1e2981c4012b4ed5f11fd0ee07c179b0cb6da1ac57041c71950f87",
8597
+ "swapFeeFactorForBalanceWasNotImproved": "0x2ababd65bdc1464452c03ed15aa4607d49c72fbb3d1eded38643609f4313af9a",
8598
+ "atomicSwapFeeFactor": "0x79013af000f937998d0016f33cf82090058f5d663cd4d2db53744ff1edb19d38",
8599
+ "swapImpactFactorPositive": "0xf8267cf53897b70b2bc0dff5d39e0a28c4bad82556cc597940a1bfae9eb16fc6",
8600
+ "swapImpactFactorNegative": "0xc67f6d06654371fb91aa8823f26c12fbd0b7be50de1c1ec438565f137bc580cc",
8601
+ "swapImpactExponentFactor": "0x288492d67c0c4af79f66f4c9e6d59da6865e696e95ce05cf69603b4b02f839e1",
8602
+ "withdrawalFeeFactorBalanceWasImproved": "0x8a34a6299a67ed5da0fe36bdcaab5662cd34f0e10c61c4b1830cb7170bf5aa42",
8603
+ "withdrawalFeeFactorBalanceWasNotImproved": "0x70e8956ef08c0020b1299fa6217d82c7b901b341d63d9861a2db14fccdad8f08",
8604
+ "virtualMarketId": "0x22983d1eed32b611212a3a066d73445a81c16488d0eb108423d4fed1375530ff",
8605
+ "virtualLongTokenId": "0xaab37f889b9680dda34f58a689de3023cb22f7ae14d32a3c1d45798a973db1f5",
8606
+ "virtualShortTokenId": "0xd5258cb84f0039be58306488e8df941c05f3cf4f219e92aacb6561c736bbb960"
8485
8607
  }
8486
8608
  },
8487
8609
  "43113": {
@@ -92,6 +92,21 @@
92
92
  "shortInterestInTokensUsingLongToken": "0xc9d6814f7afb11ad28efba7548a877fd702ce6f20100a22028aefd13bcdda320",
93
93
  "shortInterestInTokensUsingShortToken": "0xc9d6814f7afb11ad28efba7548a877fd702ce6f20100a22028aefd13bcdda320"
94
94
  },
95
+ "0x1b997cb4841c4cb360E384192fFd7fb26eb10e5f": {
96
+ "longPoolAmount": "0x6eeeebce2fdf38617ec29eb9959a0de16d48501756a021f6c8f6b731f3edc62d",
97
+ "shortPoolAmount": "0x6eeeebce2fdf38617ec29eb9959a0de16d48501756a021f6c8f6b731f3edc62d",
98
+ "positionImpactPoolAmount": "0x7a957c51406a0e27c1d5d2f992a1c051446ab02e989a1b3d67d1a2f86c372b08",
99
+ "swapImpactPoolAmountLong": "0x833a94ae64a7067956d648375e65ab64a1f2adf4a59af1eaef16428704e70018",
100
+ "swapImpactPoolAmountShort": "0x833a94ae64a7067956d648375e65ab64a1f2adf4a59af1eaef16428704e70018",
101
+ "longInterestUsingLongToken": "0x4e2ed563c2d7531f4e5cfaa2ae66d3c12c943cc9076506f76da61486d6f7651d",
102
+ "longInterestUsingShortToken": "0x4e2ed563c2d7531f4e5cfaa2ae66d3c12c943cc9076506f76da61486d6f7651d",
103
+ "shortInterestUsingLongToken": "0x280211af20306cf74c0c753973fb9a0f4d981c61d99013e3ac558945a4fd3a9d",
104
+ "shortInterestUsingShortToken": "0x280211af20306cf74c0c753973fb9a0f4d981c61d99013e3ac558945a4fd3a9d",
105
+ "longInterestInTokensUsingLongToken": "0xd1128cc54a30352bb652afa395628af45f450cad1496a04c65e532192be6903d",
106
+ "longInterestInTokensUsingShortToken": "0xd1128cc54a30352bb652afa395628af45f450cad1496a04c65e532192be6903d",
107
+ "shortInterestInTokensUsingLongToken": "0x3c97178a46fe7f37a87f5e318ca388132595870b4c7d306ba42e93d1e51b7e6a",
108
+ "shortInterestInTokensUsingShortToken": "0x3c97178a46fe7f37a87f5e318ca388132595870b4c7d306ba42e93d1e51b7e6a"
109
+ },
95
110
  "0xc5c9B5E23810565763De41144741477eeCB25e2e": {
96
111
  "longPoolAmount": "0x7c7a0a88c4e728b99ea46549faef00dc7f38dd06cc788aa991683ec87fa9d5da",
97
112
  "shortPoolAmount": "0xacce4845b7ef6fa3cf28e16cef47786c1759e08039fb6a65196ff8b50c1c051d",
@@ -2088,6 +2103,21 @@
2088
2103
  "longInterestInTokensUsingShortToken": "0x5cabb84debcb7263087ca7ef71e167a8048527739991483f2793bb6079554a50",
2089
2104
  "shortInterestInTokensUsingLongToken": "0xccb072d4c5cf74a4a1d0e6f80b7628dba861d6c95037409fc42800e72a935d7c",
2090
2105
  "shortInterestInTokensUsingShortToken": "0x3e1a9a944352a0080a281988fbf04a6b9c44a82767c10d16eb11ad80b1fb5d65"
2106
+ },
2107
+ "0xE26E7b91143f367445f1c0a5dCf4f4aC8EaDcDb1": {
2108
+ "longPoolAmount": "0x265452d70a411300a2535b1c9c212a3dcea8eb2793c66aec2fcd595776ba2c0b",
2109
+ "shortPoolAmount": "0x24f88d54e73a74c9c029fff00404272e44a15d9f931be2df1433f43ef5e5e428",
2110
+ "positionImpactPoolAmount": "0xddede8ea2450c8952f4d63ca76b41cbff50ac70ff33ad7ffb5af687ece60b6a4",
2111
+ "swapImpactPoolAmountLong": "0x247f293d3ac9f0a364133a52951a65b6c787d4c7bae97dc3b6df050992cdd0d1",
2112
+ "swapImpactPoolAmountShort": "0x7404361cc3b3fef3355b1a5909d966d710da23a6ccbb373c0c055ac93c46fd2f",
2113
+ "longInterestUsingLongToken": "0x3c1d9cbb6e868a0898d95ae2995937e5e688c959765c6011e6a311ff9f201271",
2114
+ "longInterestUsingShortToken": "0x558ce2e2477897307ba2936aa2f8c0dfbd33127aa678ce3848a0f7c2eb3364ec",
2115
+ "shortInterestUsingLongToken": "0x6c78cf314490bc2be23b69fcd0b6151271013acdc842d5825d6dc6142e2f68b6",
2116
+ "shortInterestUsingShortToken": "0x3273042e581026f84dbf62a47104addd7a4c737c96b49a6dced865d8fbacaba1",
2117
+ "longInterestInTokensUsingLongToken": "0x856d71ce9e06098ad8f41521a612499936c6f3f4c2ca09cbe4a0df90220b02e9",
2118
+ "longInterestInTokensUsingShortToken": "0xeaeddb563c71424272116a2849ba68f14386e2a137879fb04dd18ee62516aea9",
2119
+ "shortInterestInTokensUsingLongToken": "0x298283e2a61c186b0a633f3057050bcfefe43863e0a9326815324c4221c151f2",
2120
+ "shortInterestInTokensUsingShortToken": "0x87222648559c2801d1b6b6b0eda191128979ab67acbee2fab701e8a8c0313196"
2091
2121
  }
2092
2122
  },
2093
2123
  "43113": {
@@ -96,6 +96,12 @@ export var AccountStatOrderByInput;
96
96
  AccountStatOrderByInput["realizedPriceImpact_DESC"] = "realizedPriceImpact_DESC";
97
97
  AccountStatOrderByInput["realizedPriceImpact_DESC_NULLS_FIRST"] = "realizedPriceImpact_DESC_NULLS_FIRST";
98
98
  AccountStatOrderByInput["realizedPriceImpact_DESC_NULLS_LAST"] = "realizedPriceImpact_DESC_NULLS_LAST";
99
+ AccountStatOrderByInput["realizedSwapFees_ASC"] = "realizedSwapFees_ASC";
100
+ AccountStatOrderByInput["realizedSwapFees_ASC_NULLS_FIRST"] = "realizedSwapFees_ASC_NULLS_FIRST";
101
+ AccountStatOrderByInput["realizedSwapFees_ASC_NULLS_LAST"] = "realizedSwapFees_ASC_NULLS_LAST";
102
+ AccountStatOrderByInput["realizedSwapFees_DESC"] = "realizedSwapFees_DESC";
103
+ AccountStatOrderByInput["realizedSwapFees_DESC_NULLS_FIRST"] = "realizedSwapFees_DESC_NULLS_FIRST";
104
+ AccountStatOrderByInput["realizedSwapFees_DESC_NULLS_LAST"] = "realizedSwapFees_DESC_NULLS_LAST";
99
105
  AccountStatOrderByInput["realizedSwapImpact_ASC"] = "realizedSwapImpact_ASC";
100
106
  AccountStatOrderByInput["realizedSwapImpact_ASC_NULLS_FIRST"] = "realizedSwapImpact_ASC_NULLS_FIRST";
101
107
  AccountStatOrderByInput["realizedSwapImpact_ASC_NULLS_LAST"] = "realizedSwapImpact_ASC_NULLS_LAST";
@@ -1096,6 +1102,12 @@ export var MarketInfoOrderByInput;
1096
1102
  MarketInfoOrderByInput["maxShortPoolUsdForDeposit_DESC"] = "maxShortPoolUsdForDeposit_DESC";
1097
1103
  MarketInfoOrderByInput["maxShortPoolUsdForDeposit_DESC_NULLS_FIRST"] = "maxShortPoolUsdForDeposit_DESC_NULLS_FIRST";
1098
1104
  MarketInfoOrderByInput["maxShortPoolUsdForDeposit_DESC_NULLS_LAST"] = "maxShortPoolUsdForDeposit_DESC_NULLS_LAST";
1105
+ MarketInfoOrderByInput["minCollateralFactorForLiquidation_ASC"] = "minCollateralFactorForLiquidation_ASC";
1106
+ MarketInfoOrderByInput["minCollateralFactorForLiquidation_ASC_NULLS_FIRST"] = "minCollateralFactorForLiquidation_ASC_NULLS_FIRST";
1107
+ MarketInfoOrderByInput["minCollateralFactorForLiquidation_ASC_NULLS_LAST"] = "minCollateralFactorForLiquidation_ASC_NULLS_LAST";
1108
+ MarketInfoOrderByInput["minCollateralFactorForLiquidation_DESC"] = "minCollateralFactorForLiquidation_DESC";
1109
+ MarketInfoOrderByInput["minCollateralFactorForLiquidation_DESC_NULLS_FIRST"] = "minCollateralFactorForLiquidation_DESC_NULLS_FIRST";
1110
+ MarketInfoOrderByInput["minCollateralFactorForLiquidation_DESC_NULLS_LAST"] = "minCollateralFactorForLiquidation_DESC_NULLS_LAST";
1099
1111
  MarketInfoOrderByInput["minCollateralFactorForOpenInterestLong_ASC"] = "minCollateralFactorForOpenInterestLong_ASC";
1100
1112
  MarketInfoOrderByInput["minCollateralFactorForOpenInterestLong_ASC_NULLS_FIRST"] = "minCollateralFactorForOpenInterestLong_ASC_NULLS_FIRST";
1101
1113
  MarketInfoOrderByInput["minCollateralFactorForOpenInterestLong_ASC_NULLS_LAST"] = "minCollateralFactorForOpenInterestLong_ASC_NULLS_LAST";
@@ -2045,6 +2057,12 @@ export var PositionChangeOrderByInput;
2045
2057
  PositionChangeOrderByInput["sizeInUsd_DESC"] = "sizeInUsd_DESC";
2046
2058
  PositionChangeOrderByInput["sizeInUsd_DESC_NULLS_FIRST"] = "sizeInUsd_DESC_NULLS_FIRST";
2047
2059
  PositionChangeOrderByInput["sizeInUsd_DESC_NULLS_LAST"] = "sizeInUsd_DESC_NULLS_LAST";
2060
+ PositionChangeOrderByInput["swapFeeUsd_ASC"] = "swapFeeUsd_ASC";
2061
+ PositionChangeOrderByInput["swapFeeUsd_ASC_NULLS_FIRST"] = "swapFeeUsd_ASC_NULLS_FIRST";
2062
+ PositionChangeOrderByInput["swapFeeUsd_ASC_NULLS_LAST"] = "swapFeeUsd_ASC_NULLS_LAST";
2063
+ PositionChangeOrderByInput["swapFeeUsd_DESC"] = "swapFeeUsd_DESC";
2064
+ PositionChangeOrderByInput["swapFeeUsd_DESC_NULLS_FIRST"] = "swapFeeUsd_DESC_NULLS_FIRST";
2065
+ PositionChangeOrderByInput["swapFeeUsd_DESC_NULLS_LAST"] = "swapFeeUsd_DESC_NULLS_LAST";
2048
2066
  PositionChangeOrderByInput["swapImpactUsd_ASC"] = "swapImpactUsd_ASC";
2049
2067
  PositionChangeOrderByInput["swapImpactUsd_ASC_NULLS_FIRST"] = "swapImpactUsd_ASC_NULLS_FIRST";
2050
2068
  PositionChangeOrderByInput["swapImpactUsd_ASC_NULLS_LAST"] = "swapImpactUsd_ASC_NULLS_LAST";
@@ -2364,6 +2382,12 @@ export var PositionOrderByInput;
2364
2382
  PositionOrderByInput["accountStat_realizedPriceImpact_DESC"] = "accountStat_realizedPriceImpact_DESC";
2365
2383
  PositionOrderByInput["accountStat_realizedPriceImpact_DESC_NULLS_FIRST"] = "accountStat_realizedPriceImpact_DESC_NULLS_FIRST";
2366
2384
  PositionOrderByInput["accountStat_realizedPriceImpact_DESC_NULLS_LAST"] = "accountStat_realizedPriceImpact_DESC_NULLS_LAST";
2385
+ PositionOrderByInput["accountStat_realizedSwapFees_ASC"] = "accountStat_realizedSwapFees_ASC";
2386
+ PositionOrderByInput["accountStat_realizedSwapFees_ASC_NULLS_FIRST"] = "accountStat_realizedSwapFees_ASC_NULLS_FIRST";
2387
+ PositionOrderByInput["accountStat_realizedSwapFees_ASC_NULLS_LAST"] = "accountStat_realizedSwapFees_ASC_NULLS_LAST";
2388
+ PositionOrderByInput["accountStat_realizedSwapFees_DESC"] = "accountStat_realizedSwapFees_DESC";
2389
+ PositionOrderByInput["accountStat_realizedSwapFees_DESC_NULLS_FIRST"] = "accountStat_realizedSwapFees_DESC_NULLS_FIRST";
2390
+ PositionOrderByInput["accountStat_realizedSwapFees_DESC_NULLS_LAST"] = "accountStat_realizedSwapFees_DESC_NULLS_LAST";
2367
2391
  PositionOrderByInput["accountStat_realizedSwapImpact_ASC"] = "accountStat_realizedSwapImpact_ASC";
2368
2392
  PositionOrderByInput["accountStat_realizedSwapImpact_ASC_NULLS_FIRST"] = "accountStat_realizedSwapImpact_ASC_NULLS_FIRST";
2369
2393
  PositionOrderByInput["accountStat_realizedSwapImpact_ASC_NULLS_LAST"] = "accountStat_realizedSwapImpact_ASC_NULLS_LAST";
@@ -3157,6 +3181,12 @@ export var TradeActionOrderByInput;
3157
3181
  TradeActionOrderByInput["srcChainId_DESC"] = "srcChainId_DESC";
3158
3182
  TradeActionOrderByInput["srcChainId_DESC_NULLS_FIRST"] = "srcChainId_DESC_NULLS_FIRST";
3159
3183
  TradeActionOrderByInput["srcChainId_DESC_NULLS_LAST"] = "srcChainId_DESC_NULLS_LAST";
3184
+ TradeActionOrderByInput["swapFeeUsd_ASC"] = "swapFeeUsd_ASC";
3185
+ TradeActionOrderByInput["swapFeeUsd_ASC_NULLS_FIRST"] = "swapFeeUsd_ASC_NULLS_FIRST";
3186
+ TradeActionOrderByInput["swapFeeUsd_ASC_NULLS_LAST"] = "swapFeeUsd_ASC_NULLS_LAST";
3187
+ TradeActionOrderByInput["swapFeeUsd_DESC"] = "swapFeeUsd_DESC";
3188
+ TradeActionOrderByInput["swapFeeUsd_DESC_NULLS_FIRST"] = "swapFeeUsd_DESC_NULLS_FIRST";
3189
+ TradeActionOrderByInput["swapFeeUsd_DESC_NULLS_LAST"] = "swapFeeUsd_DESC_NULLS_LAST";
3160
3190
  TradeActionOrderByInput["swapImpactUsd_ASC"] = "swapImpactUsd_ASC";
3161
3191
  TradeActionOrderByInput["swapImpactUsd_ASC_NULLS_FIRST"] = "swapImpactUsd_ASC_NULLS_FIRST";
3162
3192
  TradeActionOrderByInput["swapImpactUsd_ASC_NULLS_LAST"] = "swapImpactUsd_ASC_NULLS_LAST";
@@ -936,6 +936,13 @@ export const MARKETS = {
936
936
  longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
937
937
  shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
938
938
  },
939
+ // MEGA/USD [WETH-USDC]
940
+ "0xE26E7b91143f367445f1c0a5dCf4f4aC8EaDcDb1": {
941
+ marketTokenAddress: "0xE26E7b91143f367445f1c0a5dCf4f4aC8EaDcDb1",
942
+ indexTokenAddress: "0x13983f27Ce9365055a6a553233c49fE28e70103e",
943
+ longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
944
+ shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
945
+ },
939
946
  },
940
947
  [AVALANCHE]: {
941
948
  // BTC/USD [BTC-USDC]
@@ -1331,6 +1338,13 @@ export const MARKETS = {
1331
1338
  longTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
1332
1339
  shortTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
1333
1340
  },
1341
+ // MEGA/USD [USDM-USDM]
1342
+ "0x1b997cb4841c4cb360E384192fFd7fb26eb10e5f": {
1343
+ marketTokenAddress: "0x1b997cb4841c4cb360E384192fFd7fb26eb10e5f",
1344
+ indexTokenAddress: "0x28B7E77f82B25B95953825F1E3eA0E36c1c29861",
1345
+ longTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
1346
+ shortTokenAddress: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
1347
+ },
1334
1348
  // SWAP-ONLY [ETH-USDM]
1335
1349
  "0xc5c9B5E23810565763De41144741477eeCB25e2e": {
1336
1350
  marketTokenAddress: "0xc5c9B5E23810565763De41144741477eeCB25e2e",
@@ -1229,6 +1229,16 @@ export const TOKENS = {
1229
1229
  imageUrl: "https://s2.coinmarketcap.com/static/img/coins/64x64/39464.png",
1230
1230
  explorerUrl: "https://arbiscan.io/token/0x620aC65BE29066Bb9D1E92C65b35B9fD321Fb963",
1231
1231
  },
1232
+ {
1233
+ name: "MegaETH",
1234
+ symbol: "MEGA",
1235
+ address: "0x13983f27Ce9365055a6a553233c49fE28e70103e",
1236
+ isSynthetic: true,
1237
+ decimals: 18,
1238
+ categories: ["layer2", "defi"],
1239
+ imageUrl: "https://assets.coingecko.com/coins/images/69995/standard/ICON.png?1760337992",
1240
+ explorerUrl: "https://arbiscan.io/token/0x13983f27Ce9365055a6a553233c49fE28e70103e",
1241
+ },
1232
1242
  ],
1233
1243
  [AVALANCHE]: [
1234
1244
  {
@@ -1977,6 +1987,14 @@ export const TOKENS = {
1977
1987
  isStable: true,
1978
1988
  imageUrl: "https://assets.coingecko.com/coins/images/69955/standard/USDm.png?1760170136",
1979
1989
  },
1990
+ {
1991
+ name: "MegaETH",
1992
+ symbol: "MEGA",
1993
+ address: "0x28B7E77f82B25B95953825F1E3eA0E36c1c29861",
1994
+ decimals: 18,
1995
+ categories: ["layer2", "defi"],
1996
+ imageUrl: "https://assets.coingecko.com/coins/images/69995/standard/ICON.png?1760337992",
1997
+ },
1980
1998
  {
1981
1999
  name: "GMX",
1982
2000
  symbol: "GMX",
@@ -145,6 +145,7 @@ data = "0x1", to = "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64", receiver = "0x1
145
145
  priceIn,
146
146
  priceOut,
147
147
  feesUsd,
148
+ slippage: 0,
148
149
  txnData: {
149
150
  to,
150
151
  data,
@@ -1,9 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { ARBITRUM } from "../../configs/chains";
3
- import { BASIS_POINTS_DIVISOR } from "../../configs/factors";
4
3
  import { TOKENS } from "../../configs/tokens";
5
- import { getMarketFullName, getMarketIndexName, getMarketPoolName, getContractMarketPrices, getTokenPoolType, getPoolUsdWithoutPnl, getCappedPoolPnl, getMaxLeverageByMinCollateralFactor, getMaxAllowedLeverageByMinCollateralFactor, getOppositeCollateral, getAvailableUsdLiquidityForCollateral, getReservedUsd, getMarketDivisor, getMarketPnl, getOpenInterestUsd, getOpenInterestInTokens, getPriceForPnl, } from "../markets";
6
- import { expandDecimals, numberToBigint, PRECISION_DECIMALS } from "../numbers";
4
+ import { getMarketFullName, getMarketIndexName, getMarketPoolName, getContractMarketPrices, getTokenPoolType, getPoolUsdWithoutPnl, getCappedPoolPnl, getMaxLeverageByMinCollateralFactor, getMaxAllowedLeverage, getOppositeCollateral, getAvailableUsdLiquidityForCollateral, getReservedUsd, getMarketDivisor, getMarketPnl, getOpenInterestUsd, getOpenInterestInTokens, getPriceForPnl, } from "../markets";
5
+ import { BASIS_POINTS_DIVISOR, expandDecimals } from "../numbers";
7
6
  function getToken(symbol) {
8
7
  return TOKENS[ARBITRUM].find((token) => token.symbol === symbol);
9
8
  }
@@ -140,53 +139,94 @@ describe("getMaxLeverageByMinCollateralFactor", () => {
140
139
  expect(getMaxLeverageByMinCollateralFactor(1000000000000000000n)).toBe(10000000000000000);
141
140
  });
142
141
  });
143
- describe("getMaxAllowedLeverageByMinCollateralFactor", () => {
144
- const GOLD_MARKET = "0x0Df2BE76F517BCF0000AbfFcB6344B3b2aC4Cc4f";
145
- const SILVER_MARKET = "0x448Fa722717df299ee197E2F6d8EB7911EFF6cEc";
146
- const WTIOIL_MARKET = "0xda81cdd397210C08cFc567f93982E148A3aac8a6";
147
- const BRENTOIL_MARKET = "0x6F287D071800BfA847B4a7a7104BE33F87Ce9E74";
148
- const NATGAS_MARKET = "0x2Ce2bc8B0f9d000f359d756a5816C125474Bb39b";
149
- const NON_MARKET_HOURS_MARKET = "0x1234567890abcdef1234567890abcdef12345678";
150
- it("returns half of max leverage when no market address is provided", () => {
151
- expect(getMaxAllowedLeverageByMinCollateralFactor(1000000000000000000n, undefined)).toBe(5000000000000000);
152
- });
153
- it("returns half of max leverage for a regular market", () => {
154
- expect(getMaxAllowedLeverageByMinCollateralFactor(1000000000000000000n, NON_MARKET_HOURS_MARKET)).toBe(5000000000000000);
155
- });
156
- it("returns 100x for GOLD on on-hours MCF (0.009 → 110x contract max)", () => {
157
- const onHoursFactor = 9n * 10n ** 27n;
158
- expect(getMaxAllowedLeverageByMinCollateralFactor(onHoursFactor, GOLD_MARKET)).toBe(100 * BASIS_POINTS_DIVISOR);
159
- });
160
- it("returns 25x for GOLD on off-hours MCF (0.035 → 30x contract max)", () => {
161
- const offHoursFactor = 35n * 10n ** 27n;
162
- expect(getMaxAllowedLeverageByMinCollateralFactor(offHoursFactor, GOLD_MARKET)).toBe(25 * BASIS_POINTS_DIVISOR);
163
- });
164
- it("returns 100x / 25x for SILVER with the same GOLD MCFs", () => {
165
- expect(getMaxAllowedLeverageByMinCollateralFactor(9n * 10n ** 27n, SILVER_MARKET)).toBe(100 * BASIS_POINTS_DIVISOR);
166
- expect(getMaxAllowedLeverageByMinCollateralFactor(35n * 10n ** 27n, SILVER_MARKET)).toBe(25 * BASIS_POINTS_DIVISOR);
167
- });
168
- it("returns 100x for WTIOIL on-hours MCF and 25x for off-hours MCF", () => {
169
- expect(getMaxAllowedLeverageByMinCollateralFactor(9n * 10n ** 27n, WTIOIL_MARKET)).toBe(100 * BASIS_POINTS_DIVISOR);
170
- expect(getMaxAllowedLeverageByMinCollateralFactor(35n * 10n ** 27n, WTIOIL_MARKET)).toBe(25 * BASIS_POINTS_DIVISOR);
171
- });
172
- it("returns 100x for BRENTOIL on-hours MCF and 25x for off-hours MCF", () => {
173
- expect(getMaxAllowedLeverageByMinCollateralFactor(9n * 10n ** 27n, BRENTOIL_MARKET)).toBe(100 * BASIS_POINTS_DIVISOR);
174
- expect(getMaxAllowedLeverageByMinCollateralFactor(35n * 10n ** 27n, BRENTOIL_MARKET)).toBe(25 * BASIS_POINTS_DIVISOR);
175
- });
176
- it("returns 40x for NATGAS on-hours MCF and 20x for off-hours MCF", () => {
177
- expect(getMaxAllowedLeverageByMinCollateralFactor(22n * 10n ** 27n, NATGAS_MARKET)).toBe(40 * BASIS_POINTS_DIVISOR);
178
- expect(getMaxAllowedLeverageByMinCollateralFactor(40n * 10n ** 27n, NATGAS_MARKET)).toBe(20 * BASIS_POINTS_DIVISOR);
179
- });
180
- it("does not apply market-hours overrides to other markets with same MCF", () => {
181
- const onHoursFactor = 9n * 10n ** 27n;
182
- const offHoursFactor = 35n * 10n ** 27n;
183
- expect(getMaxAllowedLeverageByMinCollateralFactor(onHoursFactor, NON_MARKET_HOURS_MARKET)).toBe(55.5 * BASIS_POINTS_DIVISOR);
184
- expect(getMaxAllowedLeverageByMinCollateralFactor(offHoursFactor, NON_MARKET_HOURS_MARKET)).toBe(14.5 * BASIS_POINTS_DIVISOR);
185
- });
186
- it("rounds allowed leverage to nearest .0 or .5", () => {
187
- expect(getMaxAllowedLeverageByMinCollateralFactor(numberToBigint(1 / 24, PRECISION_DECIMALS), undefined)).toBe(12 * BASIS_POINTS_DIVISOR);
188
- expect(getMaxAllowedLeverageByMinCollateralFactor(numberToBigint(1 / 25, PRECISION_DECIMALS), undefined)).toBe(12.5 * BASIS_POINTS_DIVISOR);
189
- expect(getMaxAllowedLeverageByMinCollateralFactor(numberToBigint(1 / 50, PRECISION_DECIMALS), undefined)).toBe(25 * BASIS_POINTS_DIVISOR);
142
+ describe("getMaxAllowedLeverage", () => {
143
+ // Factors are expressed in PRECISION units (1e30 == 100%).
144
+ const pct = (percent) => expandDecimals(percent * 100, 26); // 0.5% → 5e27
145
+ const bps = (lev) => lev * BASIS_POINTS_DIVISOR;
146
+ it("returns default 100x when any factor is undefined or zero", () => {
147
+ expect(getMaxAllowedLeverage({
148
+ minCollateralFactor: undefined,
149
+ minCollateralFactorForLiquidation: undefined,
150
+ positionFeeFactorForBalanceWasNotImproved: undefined,
151
+ })).toBe(bps(100));
152
+ expect(getMaxAllowedLeverage({
153
+ minCollateralFactor: 0n,
154
+ minCollateralFactorForLiquidation: pct(0.5),
155
+ positionFeeFactorForBalanceWasNotImproved: pct(0.05),
156
+ })).toBe(bps(100));
157
+ expect(getMaxAllowedLeverage({
158
+ minCollateralFactor: pct(0.5),
159
+ minCollateralFactorForLiquidation: 0n,
160
+ positionFeeFactorForBalanceWasNotImproved: pct(0.05),
161
+ })).toBe(bps(100));
162
+ expect(getMaxAllowedLeverage({
163
+ minCollateralFactor: pct(0.5),
164
+ minCollateralFactorForLiquidation: pct(0.5),
165
+ positionFeeFactorForBalanceWasNotImproved: undefined,
166
+ })).toBe(bps(100));
167
+ });
168
+ it("returns 100x for BTC/ETH (equal MCF and liqMCF, liquidation bound dominates)", () => {
169
+ // MCF = liqMCF = 0.5%, fee = 0.05%
170
+ // opening = 1 / (0.005 + 0.001) ≈ 166.67x
171
+ // liquidation = 1 / (2 × 0.005) = 100x
172
+ // min floored to 5x = 100x
173
+ expect(getMaxAllowedLeverage({
174
+ minCollateralFactor: pct(0.5),
175
+ minCollateralFactorForLiquidation: pct(0.5),
176
+ positionFeeFactorForBalanceWasNotImproved: pct(0.05),
177
+ })).toBe(bps(100));
178
+ });
179
+ it("returns 85x for ZEC (opening bound dominates, floors to 5x)", () => {
180
+ // MCF = 1%, liqMCF = 0.5%, fee = 0.06%
181
+ // opening = 1 / (0.01 + 0.0012) ≈ 89.29x
182
+ // liquidation = 1 / (2 × 0.005) = 100x
183
+ // min floored to 5x = 85x
184
+ expect(getMaxAllowedLeverage({
185
+ minCollateralFactor: pct(1),
186
+ minCollateralFactorForLiquidation: pct(0.5),
187
+ positionFeeFactorForBalanceWasNotImproved: pct(0.06),
188
+ })).toBe(bps(85));
189
+ });
190
+ it("returns 100x for GOLD on-hours (split factors)", () => {
191
+ // MCF = 0.9%, liqMCF = 0.5%, fee = 0.05%
192
+ // opening = 1 / (0.009 + 0.001) = 100x
193
+ // liquidation = 1 / (2 × 0.005) = 100x
194
+ expect(getMaxAllowedLeverage({
195
+ minCollateralFactor: 9n * 10n ** 27n,
196
+ minCollateralFactorForLiquidation: pct(0.5),
197
+ positionFeeFactorForBalanceWasNotImproved: pct(0.05),
198
+ })).toBe(bps(100));
199
+ });
200
+ it("returns 25x for GOLD off-hours (split factors, opening bound dominates)", () => {
201
+ // MCF = 3.5%, liqMCF = 1%, fee = 0.05%
202
+ // opening = 1 / (0.035 + 0.001) ≈ 27.78x
203
+ // liquidation = 1 / (2 × 0.01) = 50x
204
+ // min floored to 5x = 25x
205
+ expect(getMaxAllowedLeverage({
206
+ minCollateralFactor: 35n * 10n ** 27n,
207
+ minCollateralFactorForLiquidation: pct(1),
208
+ positionFeeFactorForBalanceWasNotImproved: pct(0.05),
209
+ })).toBe(bps(25));
210
+ });
211
+ it("floors to the nearest 5x", () => {
212
+ // Choose factors so opening = 47.17x exactly, should floor to 45x
213
+ // 1 / (MCF + 2×fee) = 47.17 → MCF + 2×fee ≈ 0.0212
214
+ // MCF = 2%, fee = 0.06% → 0.02 + 0.0012 = 0.0212 → 1/0.0212 ≈ 47.17
215
+ expect(getMaxAllowedLeverage({
216
+ minCollateralFactor: pct(2),
217
+ minCollateralFactorForLiquidation: pct(0.5),
218
+ positionFeeFactorForBalanceWasNotImproved: pct(0.06),
219
+ })).toBe(bps(45));
220
+ });
221
+ it("liquidation bound dominates when MCF-for-liquidation is relatively high", () => {
222
+ // MCF = 0.5%, liqMCF = 2%, fee = 0.05%
223
+ // opening = 1 / (0.005 + 0.001) ≈ 166.67x
224
+ // liquidation = 1 / (2 × 0.02) = 25x → min 25x
225
+ expect(getMaxAllowedLeverage({
226
+ minCollateralFactor: pct(0.5),
227
+ minCollateralFactorForLiquidation: pct(2),
228
+ positionFeeFactorForBalanceWasNotImproved: pct(0.05),
229
+ })).toBe(bps(25));
190
230
  });
191
231
  });
192
232
  describe("getOppositeCollateral", () => {
@@ -3,7 +3,7 @@ import { bigMath } from "../bigmath";
3
3
  import { getPositionFee, getPriceImpactForPosition } from "../fees";
4
4
  import { getCappedPoolPnl, getMarketPnl, getPoolUsdWithoutPnl } from "../markets";
5
5
  import { expandDecimals, USD_DECIMALS } from "../numbers";
6
- import { getEntryPrice, getLeverage, getLiquidationPrice, getPositionKey, getPositionNetValue, getPositionPendingFeesUsd, getPositionPnlAfterFees, getPositionPnlUsd, getPositionValueUsd, parsePositionKey, } from "../positions";
6
+ import { getEntryPrice, getLeverage, getLiquidationPrice, getPositionKey, getPositionNetValue, getPositionNetValueAfterAllFees, getPositionPendingFeesUsd, getPositionPnlAfterAllFees, getPositionPnlAfterFees, getPositionPnlUsd, getPositionValueUsd, parsePositionKey, } from "../positions";
7
7
  import { convertToUsd, getIsEquivalentTokens } from "../tokens";
8
8
  vi.mock("../markets", () => ({
9
9
  ...vi.importActual("../markets"),
@@ -148,6 +148,99 @@ describe("getPositionPnlAfterFees", () => {
148
148
  expect(result).toBe(-70n);
149
149
  });
150
150
  });
151
+ describe("getPositionNetValueAfterAllFees", () => {
152
+ it("subtracts all fees and adds signed price impact (adverse)", () => {
153
+ const result = getPositionNetValueAfterAllFees({
154
+ collateralUsd: 1000n,
155
+ pnl: 200n,
156
+ pendingBorrowingFeesUsd: 15n,
157
+ pendingFundingFeesUsd: 10n,
158
+ netPriceImpactDeltaUsd: -50n,
159
+ closingFeeUsd: 30n,
160
+ });
161
+ // 1000 + 200 - 15 - 10 + (-50) - 30 = 1095
162
+ expect(result).toBe(1095n);
163
+ });
164
+ it("adds favorable price impact", () => {
165
+ const result = getPositionNetValueAfterAllFees({
166
+ collateralUsd: 1000n,
167
+ pnl: 200n,
168
+ pendingBorrowingFeesUsd: 0n,
169
+ pendingFundingFeesUsd: 0n,
170
+ netPriceImpactDeltaUsd: 25n,
171
+ closingFeeUsd: 0n,
172
+ });
173
+ // 1000 + 200 + 25 = 1225
174
+ expect(result).toBe(1225n);
175
+ });
176
+ it("reduces to collateral when pnl, fees, and impact are zero", () => {
177
+ const result = getPositionNetValueAfterAllFees({
178
+ collateralUsd: 500n,
179
+ pnl: 0n,
180
+ pendingBorrowingFeesUsd: 0n,
181
+ pendingFundingFeesUsd: 0n,
182
+ netPriceImpactDeltaUsd: 0n,
183
+ closingFeeUsd: 0n,
184
+ });
185
+ expect(result).toBe(500n);
186
+ });
187
+ it("handles negative pnl with adverse impact", () => {
188
+ const result = getPositionNetValueAfterAllFees({
189
+ collateralUsd: 1000n,
190
+ pnl: -300n,
191
+ pendingBorrowingFeesUsd: 5n,
192
+ pendingFundingFeesUsd: 5n,
193
+ netPriceImpactDeltaUsd: -20n,
194
+ closingFeeUsd: 10n,
195
+ });
196
+ // 1000 - 300 - 5 - 5 - 20 - 10 = 660
197
+ expect(result).toBe(660n);
198
+ });
199
+ });
200
+ describe("getPositionPnlAfterAllFees", () => {
201
+ it("subtracts all fees and adds signed price impact (adverse) from pnl", () => {
202
+ const result = getPositionPnlAfterAllFees({
203
+ pnl: 500n,
204
+ pendingBorrowingFeesUsd: 30n,
205
+ pendingFundingFeesUsd: 20n,
206
+ netPriceImpactDeltaUsd: -40n,
207
+ closingFeeUsd: 50n,
208
+ });
209
+ // 500 - 30 - 20 - 40 - 50 = 360
210
+ expect(result).toBe(360n);
211
+ });
212
+ it("adds favorable price impact to pnl", () => {
213
+ const result = getPositionPnlAfterAllFees({
214
+ pnl: 100n,
215
+ pendingBorrowingFeesUsd: 0n,
216
+ pendingFundingFeesUsd: 0n,
217
+ netPriceImpactDeltaUsd: 50n,
218
+ closingFeeUsd: 0n,
219
+ });
220
+ expect(result).toBe(150n);
221
+ });
222
+ it("returns pnl when fees and impact are zero", () => {
223
+ const result = getPositionPnlAfterAllFees({
224
+ pnl: 200n,
225
+ pendingBorrowingFeesUsd: 0n,
226
+ pendingFundingFeesUsd: 0n,
227
+ netPriceImpactDeltaUsd: 0n,
228
+ closingFeeUsd: 0n,
229
+ });
230
+ expect(result).toBe(200n);
231
+ });
232
+ it("handles negative pnl with adverse impact", () => {
233
+ const result = getPositionPnlAfterAllFees({
234
+ pnl: -100n,
235
+ pendingBorrowingFeesUsd: 10n,
236
+ pendingFundingFeesUsd: 5n,
237
+ netPriceImpactDeltaUsd: -20n,
238
+ closingFeeUsd: 30n,
239
+ });
240
+ // -100 - 10 - 5 - 20 - 30 = -165
241
+ expect(result).toBe(-165n);
242
+ });
243
+ });
151
244
  describe("getLeverage", () => {
152
245
  it("returns undefined if remainingCollateralUsd <= 0", () => {
153
246
  const result = getLeverage({