@gmx-io/sdk 0.1.1 → 0.2.0

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 (94) hide show
  1. package/README.md +31 -5
  2. package/build/src/configs/batch.d.ts +2 -3
  3. package/build/src/configs/chains.d.ts +5 -1
  4. package/build/src/configs/chains.js +9 -2
  5. package/build/src/configs/contracts.d.ts +220 -1
  6. package/build/src/configs/contracts.js +67 -8
  7. package/build/src/configs/markets.js +70 -0
  8. package/build/src/configs/tokens.js +128 -5
  9. package/build/src/modules/accounts/accounts.spec.js +1 -0
  10. package/build/src/modules/markets/index.js +2 -8
  11. package/build/src/modules/markets/markets.spec.js +1 -0
  12. package/build/src/modules/markets/query-builders.d.ts +1 -1
  13. package/build/src/modules/markets/query-builders.js +1 -1
  14. package/build/src/modules/markets/types.d.ts +4 -1
  15. package/build/src/modules/orders/orders.spec.js +1 -0
  16. package/build/src/modules/orders/utils.js +1 -1
  17. package/build/src/modules/positions/positions.d.ts +2 -2
  18. package/build/src/modules/positions/positions.js +21 -8
  19. package/build/src/modules/positions/positions.spec.js +2 -1
  20. package/build/src/modules/tokens/tokens.spec.js +1 -0
  21. package/build/src/modules/trades/trades.spec.js +1 -0
  22. package/build/src/modules/utils/utils.d.ts +1 -1
  23. package/build/src/modules/utils/utils.js +1 -1
  24. package/build/src/prebuilt/hashedKinkModelMarketRatesKeys.json +80 -0
  25. package/build/src/prebuilt/hashedMarketConfigKeys.json +500 -0
  26. package/build/src/prebuilt/hashedMarketValuesKeys.json +150 -0
  27. package/build/src/types/common.d.ts +1 -0
  28. package/build/src/types/fees.d.ts +2 -1
  29. package/build/src/types/markets.d.ts +7 -19
  30. package/build/src/types/orders.d.ts +3 -5
  31. package/build/src/types/positions.d.ts +11 -4
  32. package/build/src/types/trade.d.ts +1 -0
  33. package/build/src/types/tradeHistory.d.ts +4 -1
  34. package/build/src/utils/__tests__/LruCache.spec.d.ts +1 -0
  35. package/build/src/utils/__tests__/LruCache.spec.js +43 -0
  36. package/build/src/utils/__tests__/bigmath.spec.d.ts +1 -0
  37. package/build/src/utils/__tests__/bigmath.spec.js +38 -0
  38. package/build/src/utils/__tests__/fees.spec.d.ts +1 -0
  39. package/build/src/utils/__tests__/fees.spec.js +62 -0
  40. package/build/src/utils/__tests__/hash.spec.d.ts +1 -0
  41. package/build/src/utils/__tests__/hash.spec.js +41 -0
  42. package/build/src/utils/__tests__/markets.spec.d.ts +1 -0
  43. package/build/src/utils/__tests__/markets.spec.js +265 -0
  44. package/build/src/utils/__tests__/numbers.spec.d.ts +1 -0
  45. package/build/src/utils/__tests__/numbers.spec.js +81 -0
  46. package/build/src/utils/__tests__/objects.spec.d.ts +1 -0
  47. package/build/src/utils/__tests__/objects.spec.js +59 -0
  48. package/build/src/utils/__tests__/positions.spec.d.ts +1 -0
  49. package/build/src/utils/__tests__/positions.spec.js +178 -0
  50. package/build/src/utils/__tests__/prices.spec.d.ts +1 -0
  51. package/build/src/utils/__tests__/prices.spec.js +59 -0
  52. package/build/src/utils/__tests__/referrals.spec.d.ts +1 -0
  53. package/build/src/utils/__tests__/referrals.spec.js +18 -0
  54. package/build/src/utils/__tests__/subgraph.spec.d.ts +1 -0
  55. package/build/src/utils/__tests__/subgraph.spec.js +163 -0
  56. package/build/src/utils/__tests__/tokens.spec.d.ts +1 -0
  57. package/build/src/utils/__tests__/tokens.spec.js +83 -0
  58. package/build/src/utils/__tests__/trade.spec.d.ts +1 -0
  59. package/build/src/utils/__tests__/trade.spec.js +36 -0
  60. package/build/src/utils/bigmath.d.ts +1 -1
  61. package/build/src/utils/bigmath.js +6 -1
  62. package/build/src/utils/callContract.js +5 -1
  63. package/build/src/utils/common.d.ts +6 -1
  64. package/build/src/utils/common.js +9 -1
  65. package/build/src/utils/contracts.d.ts +4 -0
  66. package/build/src/utils/contracts.js +2 -0
  67. package/build/src/utils/fees/executionFee.d.ts +22 -21
  68. package/build/src/utils/fees/executionFee.js +26 -26
  69. package/build/src/utils/fees/executionFee.spec.d.ts +1 -0
  70. package/build/src/utils/fees/executionFee.spec.js +64 -0
  71. package/build/src/utils/fees/index.d.ts +2 -0
  72. package/build/src/utils/fees/index.js +21 -9
  73. package/build/src/utils/markets.d.ts +9 -2
  74. package/build/src/utils/markets.js +33 -10
  75. package/build/src/utils/multicall.js +4 -3
  76. package/build/src/utils/numbers.d.ts +2 -0
  77. package/build/src/utils/numbers.js +28 -0
  78. package/build/src/utils/orders.js +0 -8
  79. package/build/src/utils/positions.js +3 -3
  80. package/build/src/utils/prices.d.ts +1 -6
  81. package/build/src/utils/prices.js +0 -9
  82. package/build/src/utils/referrals.d.ts +2 -0
  83. package/build/src/utils/referrals.js +17 -15
  84. package/build/src/utils/swapStats.d.ts +1 -0
  85. package/build/src/utils/swapStats.js +12 -1
  86. package/build/src/utils/testUtil.d.ts +14314 -326
  87. package/build/src/utils/tokens.d.ts +4 -0
  88. package/build/src/utils/tokens.js +4 -0
  89. package/build/tsconfig.tsbuildinfo +1 -1
  90. package/package.json +6 -29
  91. package/build/src/types/amounts.d.ts +0 -223
  92. package/build/src/types/amounts.js +0 -17
  93. package/build/src/types/syntheticsEvents.d.ts +0 -88
  94. /package/build/src/types/{syntheticsEvents.js → common.js} +0 -0
@@ -899,6 +899,126 @@
899
899
  "longInterestInTokensUsingShortToken": "0x14f339c76f04621b9ba15768d956b9a222125ad2b853794298c5c7eecd4e22f0",
900
900
  "shortInterestInTokensUsingLongToken": "0x781c00d9f9a188b6173b99ed7a04104754daf7bcc9bda9f9227e5cb787c0e0cc",
901
901
  "shortInterestInTokensUsingShortToken": "0x62d44383e14f1701c86a8900747d74284de95144d266b776d5037ca0d0426b1a"
902
+ },
903
+ "0x467C4A46287F6C4918dDF780D4fd7b46419c2291": {
904
+ "longPoolAmount": "0xed2a44283e5b723607e9f2024b3502e6bb8f61b2ac3245978b0da7f63636970c",
905
+ "shortPoolAmount": "0x3d7a43632386c44a5981a6cf24522d343f823868ffa05fed04f75d49e0c97907",
906
+ "positionImpactPoolAmount": "0x471f73a9671f6887a87a301e2f2bc1ab883b21c4d1035801225fa58523733756",
907
+ "swapImpactPoolAmountLong": "0x687a328d60932d3ac69f7810b263b1c07ec99c0e37bfd01a9c17c666bc8c6110",
908
+ "swapImpactPoolAmountShort": "0xb84694866ac2a61e4d84d7a354d0c7dc2d6760b5bf2950afea404b1c31e8f0f2",
909
+ "longInterestUsingLongToken": "0xc2dda98062f969440629a5c6f6a5fca3222956090f5f315648356101a49c1a87",
910
+ "longInterestUsingShortToken": "0xff2966344db8d78bf4c02adb695514d0163f84dc5fd9fb67f497982de8dfac9e",
911
+ "shortInterestUsingLongToken": "0xf93df38dc031f2c31cf490c394f3ea19a0c293992e57985602feca70834d0811",
912
+ "shortInterestUsingShortToken": "0x5bfcd9e0bb32a72c0012b1bca0285e1e1a7539da1f65339e05597d35006a4c9f",
913
+ "longInterestInTokensUsingLongToken": "0xe4391da2db8603da20de593ef4ffb4942ca7f2a7a68d5c5153334b483272d548",
914
+ "longInterestInTokensUsingShortToken": "0x85c979ceff7627c1dc697698ffb801cf4e43cac7aa41ebb02a1cb2f9c44419d0",
915
+ "shortInterestInTokensUsingLongToken": "0xb7de073113438300ef9d0b4e24149ced70eb5d04c644be98e268469d36d389a6",
916
+ "shortInterestInTokensUsingShortToken": "0xff62257ef67048abc448c8d0449eed2b8f08edd8dc0a7dcc5b167a2f54bc28f2"
917
+ },
918
+ "0x16466a03449CB9218EB6A980Aa4a44aaCEd27C25": {
919
+ "longPoolAmount": "0x0ecb8edaa2832d50c0c830f32e245070bf349ba6743287a175038b6bc6d00683",
920
+ "shortPoolAmount": "0xd7afc9563364ce8a2f36a288be6fa8ae7a81b573115e4d6d53b48360adbfdd35",
921
+ "positionImpactPoolAmount": "0x4aeda8ea6156723440606890aa6c5757bba22d3a8eb9409513eafb62567c4f90",
922
+ "swapImpactPoolAmountLong": "0xa6c434f9c2d761c4d4f15da3a91f737c23148686c0d80cb9960759cbb0a8ab07",
923
+ "swapImpactPoolAmountShort": "0x64db2d4159c309ed40e72fb7cdfff533995ef96e76e8ed0cd94ea75901fe4fbf",
924
+ "longInterestUsingLongToken": "0xdd3adf73d0abf54fd9abdce40a85a186d67332c9243489e4dbbdf934434ef807",
925
+ "longInterestUsingShortToken": "0xdaa066ec159484d8c956dcf395dc82088712d34ec3075ef91c5b7b2900a2fbc5",
926
+ "shortInterestUsingLongToken": "0xfbf3063e9909c1b72fdea2c6874a3f63797b959c5543f7e119ca53d2b130b11b",
927
+ "shortInterestUsingShortToken": "0xbe8c41944b45076535be05314622ea6f2b8d86cb03befb01aed93b529bd7fc8a",
928
+ "longInterestInTokensUsingLongToken": "0x59712b99752c154054e328b264eab231b6217ad70be24ad017fe1ba6760e9d92",
929
+ "longInterestInTokensUsingShortToken": "0x60bb5a56bfec8db56c94c97fc1fa228a87523379609015edd2088d97afd1c0fa",
930
+ "shortInterestInTokensUsingLongToken": "0x1793772d09dd54f5c5fcd10d9ed7b33e03049c07c9b5005292ed5060cb72a90a",
931
+ "shortInterestInTokensUsingShortToken": "0xaa4b8343388d5ecb9e0e7659c31dd342129613204041f28a3dcc9c5a85791850"
932
+ },
933
+ "0xFec8f404FBCa3b11aFD3b3f0c57507C2a06dE636": {
934
+ "longPoolAmount": "0x73217b63b4a69bee4c252852083e99804bca3b471f01f3f2f3edaabc47a03643",
935
+ "shortPoolAmount": "0xe9c70149ca7f02ad97d85e91874d2e70b54dc59969825a85493d9917b41b3e93",
936
+ "positionImpactPoolAmount": "0x0a2060ea89187db3328465d2bc785773c4b8dcc152bc4fc57b6e95a47e504086",
937
+ "swapImpactPoolAmountLong": "0x233f987515691f930df2a626538ce398922ad0da64c7d10bbd7358689321c3af",
938
+ "swapImpactPoolAmountShort": "0x322c63f0ff2848f25f6d2a4538fceb9db04b6e83d2c4aa565cf3d43c84ae84ac",
939
+ "longInterestUsingLongToken": "0x366ad27932e92134b9f10581ac520d05de620b36bdaf7dea61c67e56121bc74c",
940
+ "longInterestUsingShortToken": "0x05e9c38e53dc892732c2b817d74135fc9229c2f98d52bce9433778cf2a468e9b",
941
+ "shortInterestUsingLongToken": "0xa8eb5e1252507f4c8d2ac3b0368f62ca7ef978a305c63d4b25b4eae21a922f6f",
942
+ "shortInterestUsingShortToken": "0xaeaca5d0ca8eae5ef4afe4dcbe0efc6cb883bde66e059cf495df0786357ab119",
943
+ "longInterestInTokensUsingLongToken": "0x587d0d8409a46fa95470aafd91fde6c89b872f321fb839dd14f52c64408495ed",
944
+ "longInterestInTokensUsingShortToken": "0xac05607608380033b3b4356da109b71a10cf29bd62e14d5f0f5e52a584bf77eb",
945
+ "shortInterestInTokensUsingLongToken": "0xcf86f3b4d131437311906ed2d208eca8ed56411d2e654f28de2d8be3e138bce8",
946
+ "shortInterestInTokensUsingShortToken": "0xd26d263362d6035fa3b019af2e662c8b46321fc9b1a5c8d842b4c77b8985770d"
947
+ },
948
+ "0x12fD1A4BdB96219E637180Ff5293409502b2951D": {
949
+ "longPoolAmount": "0xb32821fbf7feea34f18a6d23f5ee93a22c6f7101fbde0cc43acda7ed44b96a67",
950
+ "shortPoolAmount": "0xcfc4fb3d09178d1acdd43c646c3b6e5c248e643feb946bdc62d36072292f35ae",
951
+ "positionImpactPoolAmount": "0x081c97ecd9ea2f3edfbda30123b798a0ae15d024c89b491e23f33a37bc4ce426",
952
+ "swapImpactPoolAmountLong": "0x7f5f9bb45b9c275449ddaa5297b5ec384dfa838c2fc538308037bb2c8dd592f1",
953
+ "swapImpactPoolAmountShort": "0x72c2063dc100ba3837ac224e5135809efc8aa8e37367d59d9eec7ddfdb5c3541",
954
+ "longInterestUsingLongToken": "0x21f1d65e9cfcec6d7667a1dd0dfa05989dd55fc64dad2244b8a3ffaeede093cc",
955
+ "longInterestUsingShortToken": "0x7953f65c97266237a3bebba6edce9a73ca602ad98fa5b1af3ef8136924e0c5af",
956
+ "shortInterestUsingLongToken": "0xa1516716703fd8c2ae82cd9ced3220cf71c6e2e25f57c6793508337fa65ed98a",
957
+ "shortInterestUsingShortToken": "0xdfcf7133df28eb2582ccd3a0e5f89245a4c2127636ef05f1565ded7feb27ff5d",
958
+ "longInterestInTokensUsingLongToken": "0xb4b49b1f78b0b34846ca02c6bc47b2b00a88ccff7a2a5e1af36c535e4993eb69",
959
+ "longInterestInTokensUsingShortToken": "0x9d44a10613913549df27a04a2144c70dd7c090271a73325afc94d1e63df9a71a",
960
+ "shortInterestInTokensUsingLongToken": "0xb650ecfd1aeb7e38c21a0e52f55efcd9affd3fdb5b44bb9eb4a75e182a50e7a8",
961
+ "shortInterestInTokensUsingShortToken": "0xe76983281c0ac239e1ed1c3879c40e3db42233cdf621337bb90fb5ece9250b23"
962
+ },
963
+ "0x9F159014CC218e942E9E9481742fE5BFa9ac5A2C": {
964
+ "longPoolAmount": "0x33696a1cc2e509be5f638ae154be5aa7ed6021392cd06b16ce6737b3dc3667ab",
965
+ "shortPoolAmount": "0x3a1da24e86cb6e6a6282396e80ee211c9b8aa2af9349433abc9cc0e464b8f655",
966
+ "positionImpactPoolAmount": "0x87e605de9985d58040acea6f2d667b774c68860f9dfc1e5d031fd0a7297ba22b",
967
+ "swapImpactPoolAmountLong": "0x2bf6a71edab345a8cfbaadae6de2d263fc8ba3c96c6f0ffaadabbfeb70fb66ac",
968
+ "swapImpactPoolAmountShort": "0x39ded1d5914f4fe0ea014d1c8e5b03084becb7bc5d8ad696e12e52f68a1de62f",
969
+ "longInterestUsingLongToken": "0x3176b42f4e12cea5a5f286c5155a4553c101cf2dd04a6dab916d51f89e3750d4",
970
+ "longInterestUsingShortToken": "0x5e3372ad933188919d28f8072a6fa0e1c4b89b2e2cef547577856cc9c975d6e4",
971
+ "shortInterestUsingLongToken": "0x4a70af7a8c7624981aa4256242db6bca9bf0a7f5d2501bae19d8f0def0e47d8e",
972
+ "shortInterestUsingShortToken": "0x6b82aa8ae3bd0ef79e5dd15eb2f86f65470b9901d9edd94df71f49b18b7529b7",
973
+ "longInterestInTokensUsingLongToken": "0xa9d73abf615e30ea9fcd87a4464bd63746de3c6fce31aa5f055bd85e8a6bae02",
974
+ "longInterestInTokensUsingShortToken": "0xb9c3a9477c1670bca2eb07feea70e17eac62bdf355cae3a3cd9c9bd9cfbb4524",
975
+ "shortInterestInTokensUsingLongToken": "0x4ee4b14ea376789f2c13b2ebf2b0553aafa93f1a474fdff95729bec79634e7d1",
976
+ "shortInterestInTokensUsingShortToken": "0x873b3434e1f40be00cdf1cd2bd632668797937ac8a1cd3a156cba0117eb09910"
977
+ },
978
+ "0xD60f1BA6a76979eFfE706BF090372Ebc0A5bF169": {
979
+ "longPoolAmount": "0x2e968dbe5c24230a2ae86ab00aa28dd1712b36f05d23320cbe25706772f4ad93",
980
+ "shortPoolAmount": "0x2dcab505f325fb5e2310545b45e04cb7c6a3b7b67d2b922e8a8d28a4677af662",
981
+ "positionImpactPoolAmount": "0xa956c5480a4f53b7da50d2d81de36f48f2f827cf473306af15e5fd995472ac11",
982
+ "swapImpactPoolAmountLong": "0x0450082403a659c37528274fe2e231ddd22e6c85f4d9784831d3c60cdaea28db",
983
+ "swapImpactPoolAmountShort": "0xa6902c562648855ce1d987543ae32445ed24bc460b7ff277acfc37804e08aee0",
984
+ "longInterestUsingLongToken": "0x36c25110e5077ab5c9d19ab0d71d11c29bd91ab36ba9a66f47b7f02da5490279",
985
+ "longInterestUsingShortToken": "0x994a83db58be8742a09f5831298539040027096f21a5d16c2166aad193c353cd",
986
+ "shortInterestUsingLongToken": "0x972b87c9d1a4cf74bcb6876cc13bfaf1109c91707be51d597da1c48125629c4e",
987
+ "shortInterestUsingShortToken": "0xaf485bdb8468e4b6e2336ce459251452d8dd2af7aa24307c2af29f603896c29e",
988
+ "longInterestInTokensUsingLongToken": "0x802436cd7e36c7b74a5b8e7b398097eb6c7a479858534cf3db3428acf6b2f23a",
989
+ "longInterestInTokensUsingShortToken": "0x9cd8e29a7237ddc1ec549a9c860c7111910efd39adf613f40a7b0db6b36d5665",
990
+ "shortInterestInTokensUsingLongToken": "0xf62a5afb7091a2f8b12570cec798f32c2c1c6fbcb4f367171682acf97f646114",
991
+ "shortInterestInTokensUsingShortToken": "0x76e3acce664d64e0976a5a18709a885eda1d43524c5ba0ca74657fe86cff7e68"
992
+ },
993
+ "0x5707673D95a8fD317e2745C4217aCD64ca021B68": {
994
+ "longPoolAmount": "0x0239025aeebf914b0bc76d79686a3e338719dd1829da3cd814c237c7b038a05a",
995
+ "shortPoolAmount": "0x34c9704179a5340d35deb5e35fa5cc42efe572759d28c8910e37f3257a493c56",
996
+ "positionImpactPoolAmount": "0x848c015126f7ca8289f8da1df2d491c12df2943bda0afa242dd1e9f8323cb965",
997
+ "swapImpactPoolAmountLong": "0x9e008ca9df39bd82a25a675ee2653c6f93105d0312eb957c216a9ebe87e39a5e",
998
+ "swapImpactPoolAmountShort": "0xb86a73b0cd7a436c58092366f60db4f4758a3e290c2c5f2744dafd4d006b3aa0",
999
+ "longInterestUsingLongToken": "0x13805a71f0819581e3437c6435c8f1c56b5d24fa0c459b8aff416911ff491d5c",
1000
+ "longInterestUsingShortToken": "0xfd651aceb0f524187392629aa7910b224e517dd6130e34863ddab94ae4d10242",
1001
+ "shortInterestUsingLongToken": "0xe82b96561dbfd2806aae2b10608cd14cd1492de8d4798a684b8238262681533b",
1002
+ "shortInterestUsingShortToken": "0xd20e751f7ab1704419f7cfaf15468575521c2cac03143a4066b62b1e5d202330",
1003
+ "longInterestInTokensUsingLongToken": "0x982cfb4d6d33733aa97952265e00f3e28363c912094cec7a5ad4808f955aa1bf",
1004
+ "longInterestInTokensUsingShortToken": "0x2127de18eda99ea0d0791b323c452e5fb202c860bd4cbf41f05a728783dfa70e",
1005
+ "shortInterestInTokensUsingLongToken": "0x4a9e5a67e155959099fd57ea7786b8f857383d7579bf35f89ab13e6ee5e00a9f",
1006
+ "shortInterestInTokensUsingShortToken": "0x74c8ac7423d77afa101d4c945beb94b8bf41f4b5383567b54c8aefc852e7ba7f"
1007
+ },
1008
+ "0xe2730Ffe2136aA549327EBce93D58160df7821CB": {
1009
+ "longPoolAmount": "0x7bb052a0723d0ceb09f42146fa8e3f29d986cd37a9bb80cdc0187dd6d8751f22",
1010
+ "shortPoolAmount": "0x3acd31503271d4cef1b05273b74327facb0a279f90003322660cbe26ca69d13c",
1011
+ "positionImpactPoolAmount": "0xf2360947e9be406cedaa787861f849c082f143a49713eca1fcb13a45d9dae0c6",
1012
+ "swapImpactPoolAmountLong": "0x9248afe4fca824e4b46ce3f30fb0c06766552cbb3b225ef02019f0dfa114aca0",
1013
+ "swapImpactPoolAmountShort": "0xbd35684e60a2c561f87fa9a4127e6274c5cc8ce07afa5455fa1b3ea0cce72c17",
1014
+ "longInterestUsingLongToken": "0xab31877e58f76414d09c6de5268ef14b7ffbf31022b83d75a47fea5a29d608f1",
1015
+ "longInterestUsingShortToken": "0xf853edb55527ff2159bd439f0713eb679b70138393b5f639c41116018cd0f29d",
1016
+ "shortInterestUsingLongToken": "0x79628a668dad119e6e2ddbf8d5058deeaa0a77c02a310004b1bd1431726257b5",
1017
+ "shortInterestUsingShortToken": "0xe17944faa4c60b38bd52e0c68564fdefaa995a28aeee620aa4b395d0d0d791ad",
1018
+ "longInterestInTokensUsingLongToken": "0x03b108918dc70c59579b0909992d3d62a3ac5fb5ce2e9cb5e2071550e175c038",
1019
+ "longInterestInTokensUsingShortToken": "0x4e55b6204b9e180c53acfd18b5918bc427097f19ff2c7b83285bb24b490764b4",
1020
+ "shortInterestInTokensUsingLongToken": "0x000cd2871e77012d7b506e4be838f5ac57c561ec9d693e7e0d0384830bf45cd4",
1021
+ "shortInterestInTokensUsingShortToken": "0x9ae61c8ea2d344d1ce64388885eb99429ab2490e7f0ccc83c0e51f557054f6ff"
902
1022
  }
903
1023
  },
904
1024
  "43113": {
@@ -1413,6 +1533,36 @@
1413
1533
  "longInterestInTokensUsingShortToken": "0xb7f3f037e09c16698a54b0dd3602b7c179985fb2489b3447b2be1939fffcbb2d",
1414
1534
  "shortInterestInTokensUsingLongToken": "0x8354ede027b1822d4509b9d00c915d4b016cdeb827fa331aee01da14cac86e64",
1415
1535
  "shortInterestInTokensUsingShortToken": "0x8354ede027b1822d4509b9d00c915d4b016cdeb827fa331aee01da14cac86e64"
1536
+ },
1537
+ "0xfB626c4e3E153947A6A94041814c25E449064dAD": {
1538
+ "longPoolAmount": "0xdb41e477f9f2c58f74419e54873adca920c8c09bca080fcb453d9f544925a8a0",
1539
+ "shortPoolAmount": "0xf2790cb0ebcd386130be0805626dbbf86f55def3e643da400eebeab7bd26d670",
1540
+ "positionImpactPoolAmount": "0x07456fcd2b42abffad656c4326a09e7ae6882fa149485659b74e9dae770cda70",
1541
+ "swapImpactPoolAmountLong": "0xb7852402c2fc9f0a5022c821b536365b11ad5a392dc1b4fc35f1e98121c8603f",
1542
+ "swapImpactPoolAmountShort": "0xc086fbd44e41535eff0905f497fd419e83f2a1754ea7a3743eb4d39aca5f09bd",
1543
+ "longInterestUsingLongToken": "0xbf03a9c446b558d1798349d274a330c6033d9cec2fbc5b24d32e23b608f15b33",
1544
+ "longInterestUsingShortToken": "0xb78f4ca16d9f5284546089393f87cb2f7ab451007602a25d40666c6d70daea9c",
1545
+ "shortInterestUsingLongToken": "0x2eff06d135647b07d4073af205904363b10dae13ab079242a2af295b9b28647c",
1546
+ "shortInterestUsingShortToken": "0x020fdefe183d8395c277a5854a0a6f8658a612e30c065ad9e3980c6e93579d40",
1547
+ "longInterestInTokensUsingLongToken": "0x76efcd7a1cbc8b172bffa86255e802efe23725a5f6a3803430eb0266411f6a5b",
1548
+ "longInterestInTokensUsingShortToken": "0xe307718b388cc83cb46c28e3da33a165e0e2a769139e854f38aff534b5eb3a84",
1549
+ "shortInterestInTokensUsingLongToken": "0x38f7ed606b75bf4a5a09e6b6d12fe3a249bd9bf727f4eaa32531095b53be72e0",
1550
+ "shortInterestInTokensUsingShortToken": "0x8b12e3094cec1f77605d7161f758b27cfd9745521b33104ea66e999278946fd7"
1551
+ },
1552
+ "0xe19da27Bf9733c429445E289B662bECDCa6ce10b": {
1553
+ "longPoolAmount": "0x46ccffb18fc764abf84a9df3a470de2072f1ca891ee58a86c09d820e7ba60f9a",
1554
+ "shortPoolAmount": "0x897403f9f1faeca64a7bc4754152cbeb1941358522de959b4e326b087e5cf00c",
1555
+ "positionImpactPoolAmount": "0x3f053e231fd75b0e63a3cc5bdc91ff1b929904b4526a0b0dd7cc017c50799007",
1556
+ "swapImpactPoolAmountLong": "0x045f8c8c6129d3d0aa4f2017ebcc8c4ce721927d3e295e19d9d542f1d08c6728",
1557
+ "swapImpactPoolAmountShort": "0x4052d007055610ee7292ed825370f897d50d9102a3736a1ff1215274118d3b19",
1558
+ "longInterestUsingLongToken": "0xf7a0d943fa74397edcccf178186a84a0031ed7cb8d2df1a33430439dd659fabc",
1559
+ "longInterestUsingShortToken": "0x6825e04bb6514ebdebaf2f8fcb7f65242761b1adb1498017eec64120a1a42b58",
1560
+ "shortInterestUsingLongToken": "0x1aa30f17231d4faa1582902cf7922561e93befe9c96b247b8ffa7b8a59681c47",
1561
+ "shortInterestUsingShortToken": "0xd3dbed0489cd270df26efd40d6c36e3147d582722173c0ef7d960458b17ab9cb",
1562
+ "longInterestInTokensUsingLongToken": "0xcfebfb7dfb13c2411f2448ffeaf01ffd16c16bc261a59ca7a69fe5bb7e3f115b",
1563
+ "longInterestInTokensUsingShortToken": "0xaf01e4f4a7b0884f217695d374acc70a5904db6d460bc5c5d31591557300f689",
1564
+ "shortInterestInTokensUsingLongToken": "0x562b9a09cca894aa54f6d4b17a72fe7e9c4ddc4686516dcfd15a597f3eec7ee3",
1565
+ "shortInterestInTokensUsingShortToken": "0xc563cc005593b275e1c8e42f993a0b8df38c5d1634f6867ece778bea7be36823"
1416
1566
  }
1417
1567
  }
1418
1568
  }
@@ -0,0 +1 @@
1
+ export type BytesLike = string | Uint8Array;
@@ -3,13 +3,14 @@ export type ExecutionFee = {
3
3
  feeUsd: bigint;
4
4
  feeTokenAmount: bigint;
5
5
  feeToken: Token;
6
- warning?: string;
6
+ gasLimit: bigint;
7
7
  isFeeHigh: boolean;
8
8
  isFeeVeryHigh: boolean;
9
9
  };
10
10
  export type FeeItem = {
11
11
  deltaUsd: bigint;
12
12
  bps: bigint;
13
+ precisePercentage: bigint;
13
14
  };
14
15
  export type SwapFeeItem = FeeItem & {
15
16
  marketAddress: string;
@@ -34,12 +34,6 @@ export type MarketInfo = Market & MarketPoolTokens & {
34
34
  shortPoolAmountAdjustment: bigint;
35
35
  poolValueMax: bigint;
36
36
  poolValueMin: bigint;
37
- pnlLongMin: bigint;
38
- pnlLongMax: bigint;
39
- pnlShortMin: bigint;
40
- pnlShortMax: bigint;
41
- netPnlMin: bigint;
42
- netPnlMax: bigint;
43
37
  reserveFactorLong: bigint;
44
38
  reserveFactorShort: bigint;
45
39
  openInterestReserveFactorLong: bigint;
@@ -99,19 +93,6 @@ export type MarketInfo = Market & MarketPoolTokens & {
99
93
  virtualLongTokenId: string;
100
94
  virtualShortTokenId: string;
101
95
  };
102
- export type FastMarketInfo = Omit<MarketInfo, keyof MarketPoolTokens | keyof Market> & {
103
- marketTokenAddress: string;
104
- longTokenAddress: string;
105
- shortTokenAddress: string;
106
- indexTokenAddress: string;
107
- };
108
- export type ClaimableFunding = {
109
- claimableFundingAmountLong: bigint;
110
- claimableFundingAmountShort: bigint;
111
- };
112
- export type ClaimableFundingData = {
113
- [marketAddress: string]: ClaimableFunding;
114
- };
115
96
  export type MarketsData = {
116
97
  [marketTokenAddress: string]: Market;
117
98
  };
@@ -148,3 +129,10 @@ export type ContractMarketPrices = {
148
129
  max: bigint;
149
130
  };
150
131
  };
132
+ export type ClaimableFunding = {
133
+ claimableFundingAmountLong: bigint;
134
+ claimableFundingAmountShort: bigint;
135
+ };
136
+ export type ClaimableFundingData = {
137
+ [marketAddress: string]: ClaimableFunding;
138
+ };
@@ -1,4 +1,3 @@
1
- import { Address } from "viem";
2
1
  import { MarketInfo } from "./markets";
3
2
  import { TokenData, TokensRatio } from "./tokens";
4
3
  import { SwapPathStats, TriggerThresholdType } from "./trade";
@@ -26,7 +25,7 @@ export type Order = {
26
25
  key: string;
27
26
  account: string;
28
27
  callbackContract: string;
29
- initialCollateralTokenAddress: Address;
28
+ initialCollateralTokenAddress: string;
30
29
  marketAddress: string;
31
30
  decreasePositionSwapType: DecreasePositionSwapType;
32
31
  receiver: string;
@@ -43,18 +42,17 @@ export type Order = {
43
42
  isLong: boolean;
44
43
  orderType: OrderType;
45
44
  shouldUnwrapNativeToken: boolean;
46
- data: string;
47
45
  autoCancel: boolean;
46
+ data: string;
47
+ title?: string;
48
48
  };
49
49
  export type SwapOrderInfo = Order & {
50
- title?: string;
51
50
  swapPathStats?: SwapPathStats;
52
51
  triggerRatio?: TokensRatio;
53
52
  initialCollateralToken: TokenData;
54
53
  targetCollateralToken: TokenData;
55
54
  };
56
55
  export type PositionOrderInfo = Order & {
57
- title: string;
58
56
  marketInfo: MarketInfo;
59
57
  swapPathStats?: SwapPathStats;
60
58
  indexToken: TokenData;
@@ -1,5 +1,4 @@
1
- import { MarketInfo } from "./markets";
2
- import { PendingPositionUpdate } from "./syntheticsEvents";
1
+ import { Market, MarketInfo } from "./markets";
3
2
  import { TokenData } from "./tokens";
4
3
  export type Position = {
5
4
  key: string;
@@ -18,12 +17,20 @@ export type Position = {
18
17
  claimableLongTokenAmount: bigint;
19
18
  claimableShortTokenAmount: bigint;
20
19
  isOpening?: boolean;
21
- pendingUpdate?: PendingPositionUpdate;
20
+ pnl: bigint;
21
+ positionFeeAmount: bigint;
22
+ traderDiscountAmount: bigint;
23
+ uiFeeAmount: bigint;
22
24
  data: string;
23
25
  };
24
26
  export type PositionInfo = Position & {
25
- marketInfo: MarketInfo;
27
+ marketInfo: MarketInfo | undefined;
28
+ market: Market;
26
29
  indexToken: TokenData;
30
+ longToken: TokenData;
31
+ shortToken: TokenData;
32
+ indexName: string;
33
+ poolName: string;
27
34
  collateralToken: TokenData;
28
35
  pnlToken: TokenData;
29
36
  markPrice: bigint;
@@ -143,6 +143,7 @@ export type SwapStats = {
143
143
  isWrap: boolean;
144
144
  isUnwrap: boolean;
145
145
  isOutLiquidity?: boolean;
146
+ isOutCapacity?: boolean;
146
147
  swapFeeAmount: bigint;
147
148
  swapFeeUsd: bigint;
148
149
  priceImpactDeltaUsd: bigint;
@@ -1,3 +1,4 @@
1
+ import { BytesLike } from "./common";
1
2
  import { MarketInfo } from "./markets";
2
3
  import { OrderType } from "./orders";
3
4
  import { TokenData } from "./tokens";
@@ -27,6 +28,7 @@ export type RawTradeAction = {
27
28
  positionFeeAmount?: string;
28
29
  borrowingFeeAmount?: string;
29
30
  fundingFeeAmount?: string;
31
+ liquidationFeeAmount?: string;
30
32
  pnlUsd?: string;
31
33
  basePnlUsd?: string;
32
34
  collateralTokenPriceMax?: string;
@@ -38,7 +40,7 @@ export type RawTradeAction = {
38
40
  isLong?: boolean;
39
41
  shouldUnwrapNativeToken?: boolean;
40
42
  reason?: string;
41
- reasonBytes?: string | Uint8Array;
43
+ reasonBytes?: BytesLike;
42
44
  transaction: {
43
45
  timestamp: number;
44
46
  hash: string;
@@ -78,6 +80,7 @@ export type PositionTradeAction = {
78
80
  reason?: string;
79
81
  reasonBytes?: string | Uint8Array;
80
82
  shouldUnwrapNativeToken: boolean;
83
+ liquidationFeeAmount?: bigint;
81
84
  transaction: {
82
85
  timestamp: number;
83
86
  hash: string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { LRUCache } from "../LruCache";
3
+ describe("LruCache", () => {
4
+ it("should store and retrieve values", () => {
5
+ const cache = new LRUCache(2);
6
+ cache.set("a", 1);
7
+ expect(cache.get("a")).toBe(1);
8
+ });
9
+ it("should return undefined for non-existing keys", () => {
10
+ const cache = new LRUCache(2);
11
+ expect(cache.get("x")).toBeUndefined();
12
+ });
13
+ it("should update recent usage when getting a key", () => {
14
+ const cache = new LRUCache(2);
15
+ cache.set("a", 1);
16
+ cache.set("b", 2);
17
+ cache.get("a"); // 'a' is now the most recently used
18
+ cache.set("c", 3); // 'b' should be evicted
19
+ expect(cache.has("b")).toBe(false);
20
+ expect(cache.has("a")).toBe(true);
21
+ });
22
+ it("should evict the least recently used key when capacity is exceeded", () => {
23
+ const cache = new LRUCache(2);
24
+ cache.set("a", 1);
25
+ cache.set("b", 2);
26
+ cache.set("c", 3); // 'a' is removed
27
+ expect(cache.has("a")).toBe(false);
28
+ expect(cache.has("b")).toBe(true);
29
+ expect(cache.get("c")).toBe(3);
30
+ });
31
+ it("should update existing keys without eviction", () => {
32
+ const cache = new LRUCache(2);
33
+ cache.set("a", 1);
34
+ cache.set("b", 2);
35
+ cache.set("a", 10); // update 'a'
36
+ expect(cache.get("a")).toBe(10);
37
+ expect(cache.has("b")).toBe(true);
38
+ });
39
+ it("should throw error if key is not a string", () => {
40
+ const cache = new LRUCache(2);
41
+ expect(() => cache.set(123, 1)).toThrow("Key must be a string");
42
+ });
43
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ import { bigMath } from "../bigmath";
2
+ import { describe, expect, it } from "vitest";
3
+ describe("bigMath", () => {
4
+ describe("abs", () => {
5
+ it("should return the absolute value of a number", () => {
6
+ expect(bigMath.abs(10n)).toBe(10n);
7
+ expect(bigMath.abs(-10n)).toBe(10n);
8
+ });
9
+ });
10
+ describe("mulDiv", () => {
11
+ it("should return the result of multiplying two numbers and dividing by a third", () => {
12
+ expect(bigMath.mulDiv(10n, 10n, 2n)).toBe(50n);
13
+ expect(bigMath.mulDiv(10n, 10n, 3n)).toBe(33n);
14
+ });
15
+ });
16
+ describe("max", () => {
17
+ it("should return the maximum value of a list of numbers", () => {
18
+ expect(bigMath.max(10n, 20n, -30n)).toBe(20n);
19
+ expect(bigMath.max(30n, 20n, 10n)).toBe(30n);
20
+ });
21
+ });
22
+ describe("min", () => {
23
+ it("should return the minimum value of a list of numbers", () => {
24
+ expect(bigMath.min(10n, 20n, -30n)).toBe(-30n);
25
+ expect(bigMath.min(30n, 20n, 10n)).toBe(10n);
26
+ });
27
+ });
28
+ describe("avg", () => {
29
+ it("should return the average value of a list of numbers", () => {
30
+ expect(bigMath.avg(10n, 20n, 30n)).toBe(20n);
31
+ expect(bigMath.avg(10n, 20n, 30n, 40n, undefined)).toBe(25n);
32
+ });
33
+ it("should return undefined if no values are provided", () => {
34
+ expect(bigMath.avg()).toBe(undefined);
35
+ expect(bigMath.avg(undefined, undefined)).toBe(undefined);
36
+ });
37
+ });
38
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { USD_DECIMALS } from "../../configs/factors";
3
+ import { getFundingFactorPerPeriod } from "../fees";
4
+ import { numberToBigint } from "../numbers";
5
+ const dollar = 10n ** BigInt(USD_DECIMALS);
6
+ const eightMillion = 8000000n;
7
+ const tenMillion = 10000000n;
8
+ function toFactor(percent) {
9
+ const value = parseFloat(percent.replace("%", ""));
10
+ return numberToBigint(value, 30 - 2);
11
+ }
12
+ const second = 1;
13
+ describe("getFundingFactorPerPeriod", () => {
14
+ it("works when short pay, shorts OI bigger", () => {
15
+ const marketInfo = {
16
+ fundingFactorPerSecond: toFactor("50%"),
17
+ longsPayShorts: false,
18
+ longInterestUsd: eightMillion * dollar,
19
+ shortInterestUsd: tenMillion * dollar,
20
+ };
21
+ const forLongs = getFundingFactorPerPeriod(marketInfo, true, second);
22
+ expect(forLongs.toString()).toBe(toFactor("62.5%").toString());
23
+ const forShorts = getFundingFactorPerPeriod(marketInfo, false, second);
24
+ expect(forShorts.toString()).toBe(toFactor("-50%").toString());
25
+ });
26
+ it("works when short pay, longs OI bigger", () => {
27
+ const marketInfo = {
28
+ fundingFactorPerSecond: toFactor("50%"),
29
+ longsPayShorts: false,
30
+ longInterestUsd: tenMillion * dollar,
31
+ shortInterestUsd: eightMillion * dollar,
32
+ };
33
+ const forLongs = getFundingFactorPerPeriod(marketInfo, true, second);
34
+ expect(forLongs.toString()).toBe(toFactor("50%").toString());
35
+ const forShorts = getFundingFactorPerPeriod(marketInfo, false, second);
36
+ expect(forShorts.toString()).toBe(toFactor("-62.5%").toString());
37
+ });
38
+ it("works when long pay, shorts OI bigger", () => {
39
+ const marketInfo = {
40
+ fundingFactorPerSecond: toFactor("50%"),
41
+ longsPayShorts: true,
42
+ longInterestUsd: eightMillion * dollar,
43
+ shortInterestUsd: tenMillion * dollar,
44
+ };
45
+ const forLongs = getFundingFactorPerPeriod(marketInfo, true, second);
46
+ expect(forLongs.toString()).toBe(toFactor("-62.5%").toString());
47
+ const forShorts = getFundingFactorPerPeriod(marketInfo, false, second);
48
+ expect(forShorts.toString()).toBe(toFactor("50%").toString());
49
+ });
50
+ it("works when long pay, longs OI bigger", () => {
51
+ const marketInfo = {
52
+ fundingFactorPerSecond: toFactor("50%"),
53
+ longsPayShorts: true,
54
+ longInterestUsd: tenMillion * dollar,
55
+ shortInterestUsd: eightMillion * dollar,
56
+ };
57
+ const forLongs = getFundingFactorPerPeriod(marketInfo, true, second);
58
+ expect(forLongs.toString()).toBe(toFactor("-50%").toString());
59
+ const forShorts = getFundingFactorPerPeriod(marketInfo, false, second);
60
+ expect(forShorts.toString()).toBe(toFactor("62.5%").toString());
61
+ });
62
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import { hashData, hashString, hashDataMap } from "../hash";
2
+ import { LRUCache } from "../LruCache";
3
+ import { describe, expect, it } from "vitest";
4
+ describe("hashData", () => {
5
+ it("returns a valid hash and caches it", () => {
6
+ const inputTypes = ["uint256", "string"];
7
+ const inputValues = [123n, "hello"];
8
+ const result = hashData(inputTypes, inputValues);
9
+ expect(result).toBe("0x18a25ed45d79546dfca2565caa2ee3102fb46159dea4fde1d0a9c0cc78ce94e3");
10
+ // Check cache
11
+ const key = JSON.stringify({ dataTypes: inputTypes, dataValues: ["123", "hello"] });
12
+ expect(new LRUCache(10000).has(key)).toBe(false);
13
+ });
14
+ it("returns cached hash if already computed", () => {
15
+ const inputTypes = ["bool"];
16
+ const inputValues = [true];
17
+ const result1 = hashData(inputTypes, inputValues);
18
+ const result2 = hashData(inputTypes, inputValues);
19
+ expect(result1).toBe(result2);
20
+ });
21
+ });
22
+ describe("hashString", () => {
23
+ it("returns a valid hash for a string and caches it", () => {
24
+ const str = "test-string";
25
+ const hash1 = hashString(str);
26
+ const hash2 = hashString(str);
27
+ expect(hash1).toBe(hash2);
28
+ });
29
+ });
30
+ describe("hashDataMap", () => {
31
+ it("returns hashes for a given record map", () => {
32
+ const result = hashDataMap({
33
+ first: [["string"], ["hello"]],
34
+ second: [["uint256"], [42n]],
35
+ empty: undefined,
36
+ });
37
+ expect(Object.keys(result)).toContain("first");
38
+ expect(Object.keys(result)).toContain("second");
39
+ expect(Object.keys(result)).not.toContain("empty");
40
+ });
41
+ });
@@ -0,0 +1 @@
1
+ export {};