@gmx-io/sdk 1.0.5 → 1.1.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.
- package/build/cjs/src/abis/ArbitrumNodeInterface.json +105 -0
- package/build/cjs/src/abis/CustomErrors.json +613 -16
- package/build/cjs/src/abis/ERC20PermitInterface.json +118 -0
- package/build/cjs/src/abis/GelatoRelayRouter.json +1426 -0
- package/build/cjs/src/abis/RelayParams.json +110 -0
- package/build/cjs/src/abis/SubaccountApproval.json +17 -0
- package/build/cjs/src/abis/SubaccountGelatoRelayRouter.json +1885 -0
- package/build/cjs/src/abis/SyntheticsReader.json +1 -131
- package/build/cjs/src/abis/__tests__/abis.spec.js +40 -0
- package/build/cjs/src/abis/index.js +8 -0
- package/build/cjs/src/configs/__tests__/permits.spec.js +109 -0
- package/build/cjs/src/configs/__tests__/tokens.spec.js +1 -1
- package/build/cjs/src/configs/chains.js +36 -5
- package/build/cjs/src/configs/contracts.js +15 -3
- package/build/cjs/src/configs/dataStore.js +26 -4
- package/build/cjs/src/configs/express.js +35 -0
- package/build/cjs/src/configs/factors.js +4 -3
- package/build/cjs/src/configs/markets.js +28 -0
- package/build/cjs/src/configs/tokens.js +90 -0
- package/build/cjs/src/configs/twap.js +10 -0
- package/build/cjs/src/index.js +3 -3
- package/build/cjs/src/modules/markets/index.js +1 -0
- package/build/cjs/src/modules/markets/query-builders.js +4 -0
- package/build/cjs/src/modules/orders/helpers.js +2 -0
- package/build/cjs/src/modules/utils/utils.js +11 -1
- package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +32 -0
- package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +323 -0
- package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +60 -0
- package/build/cjs/src/test/mock.js +30 -1
- package/build/cjs/src/types/twap.js +2 -0
- package/build/cjs/src/utils/__tests__/numbers.spec.js +217 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +241 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +595 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +296 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/externalCalls.spec.js +118 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +762 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +469 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +80 -0
- package/build/cjs/src/utils/__tests__/parseError.spec.js +263 -0
- package/build/cjs/src/utils/__tests__/uiFeeReceiver.spec.js +45 -0
- package/build/cjs/src/utils/bigmath.js +3 -0
- package/build/cjs/src/utils/callContract.js +2 -2
- package/build/cjs/src/utils/errors/index.js +18 -0
- package/build/cjs/src/utils/errors/parseError.js +150 -0
- package/build/cjs/src/utils/{contracts.js → errors/transactionsErrors.js} +35 -3
- package/build/cjs/src/utils/fees/executionFee.js +52 -1
- package/build/cjs/src/utils/fees/index.js +8 -4
- package/build/cjs/src/utils/gelatoRelay.js +5 -0
- package/build/cjs/src/utils/hash.js +6 -1
- package/build/cjs/src/utils/marketKeysAndConfigs.js +4 -0
- package/build/cjs/src/utils/markets.js +5 -1
- package/build/cjs/src/utils/numbers.js +559 -5
- package/build/cjs/src/utils/orderTransactions.js +638 -0
- package/build/cjs/src/utils/orders.js +7 -1
- package/build/cjs/src/utils/simulateExecuteOrder.js +6 -2
- package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +11 -6
- package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +4 -4
- package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +9 -0
- package/build/cjs/src/utils/swap/swapPath.js +30 -13
- package/build/cjs/src/utils/swap/swapRouting.js +4 -2
- package/build/cjs/src/utils/swap/swapStats.js +6 -5
- package/build/cjs/src/utils/testUtil.js +1 -1
- package/build/cjs/src/utils/time.js +30 -0
- package/build/cjs/src/utils/tokens.js +16 -2
- package/build/cjs/src/utils/twap/index.js +53 -0
- package/build/cjs/src/utils/twap/uiFeeReceiver.js +31 -0
- package/build/cjs/src/utils/types.js +13 -0
- package/build/esm/src/abis/ArbitrumNodeInterface.json +105 -0
- package/build/esm/src/abis/CustomErrors.json +613 -16
- package/build/esm/src/abis/ERC20PermitInterface.json +118 -0
- package/build/esm/src/abis/GelatoRelayRouter.json +1426 -0
- package/build/esm/src/abis/RelayParams.json +110 -0
- package/build/esm/src/abis/SubaccountApproval.json +17 -0
- package/build/esm/src/abis/SubaccountGelatoRelayRouter.json +1885 -0
- package/build/esm/src/abis/SyntheticsReader.json +1 -131
- package/build/esm/src/abis/__tests__/abis.spec.js +35 -0
- package/build/esm/src/abis/index.js +8 -0
- package/build/esm/src/configs/__tests__/permits.spec.js +107 -0
- package/build/esm/src/configs/__tests__/tokens.spec.js +3 -3
- package/build/esm/src/configs/chains.js +33 -3
- package/build/esm/src/configs/contracts.js +15 -3
- package/build/esm/src/configs/dataStore.js +19 -1
- package/build/esm/src/configs/express.js +29 -0
- package/build/esm/src/configs/factors.js +1 -3
- package/build/esm/src/configs/markets.js +28 -0
- package/build/esm/src/configs/tokens.js +90 -0
- package/build/esm/src/configs/twap.js +7 -0
- package/build/esm/src/index.js +4 -4
- package/build/esm/src/modules/markets/index.js +1 -0
- package/build/esm/src/modules/markets/query-builders.js +4 -0
- package/build/esm/src/modules/orders/helpers.js +2 -0
- package/build/esm/src/modules/utils/utils.js +13 -3
- package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +32 -0
- package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +323 -0
- package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +60 -0
- package/build/esm/src/test/mock.js +28 -0
- package/build/esm/src/types/twap.js +1 -0
- package/build/esm/src/utils/__tests__/numbers.spec.js +219 -2
- package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +239 -0
- package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +593 -0
- package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +294 -0
- package/build/esm/src/utils/__tests__/orderTransactions/externalCalls.spec.js +116 -0
- package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +760 -0
- package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +467 -0
- package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +78 -0
- package/build/esm/src/utils/__tests__/parseError.spec.js +261 -0
- package/build/esm/src/utils/__tests__/uiFeeReceiver.spec.js +43 -0
- package/build/esm/src/utils/bigmath.js +3 -0
- package/build/esm/src/utils/callContract.js +3 -3
- package/build/esm/src/utils/errors/index.js +2 -0
- package/build/esm/src/utils/errors/parseError.js +141 -0
- package/build/esm/src/utils/{contracts.js → errors/transactionsErrors.js} +30 -1
- package/build/esm/src/utils/fees/executionFee.js +48 -1
- package/build/esm/src/utils/fees/index.js +8 -4
- package/build/esm/src/utils/gelatoRelay.js +2 -0
- package/build/esm/src/utils/hash.js +5 -1
- package/build/esm/src/utils/marketKeysAndConfigs.js +5 -1
- package/build/esm/src/utils/markets.js +3 -0
- package/build/esm/src/utils/numbers.js +516 -1
- package/build/esm/src/utils/orderTransactions.js +607 -0
- package/build/esm/src/utils/orders.js +5 -0
- package/build/esm/src/utils/simulateExecuteOrder.js +6 -2
- package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +11 -6
- package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +4 -4
- package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +9 -0
- package/build/esm/src/utils/swap/swapPath.js +30 -13
- package/build/esm/src/utils/swap/swapRouting.js +4 -2
- package/build/esm/src/utils/swap/swapStats.js +6 -5
- package/build/esm/src/utils/testUtil.js +2 -2
- package/build/esm/src/utils/time.js +23 -0
- package/build/esm/src/utils/tokens.js +14 -1
- package/build/esm/src/utils/twap/index.js +44 -0
- package/build/esm/src/utils/twap/uiFeeReceiver.js +24 -0
- package/build/esm/src/utils/types.js +8 -0
- package/build/types/src/abis/__tests__/abis.spec.d.ts +1 -0
- package/build/types/src/abis/index.d.ts +1 -1
- package/build/types/src/configs/__tests__/permits.spec.d.ts +1 -0
- package/build/types/src/configs/chains.d.ts +29 -1
- package/build/types/src/configs/contracts.d.ts +238 -1
- package/build/types/src/configs/dataStore.d.ts +10 -0
- package/build/types/src/configs/express.d.ts +12 -0
- package/build/types/src/configs/factors.d.ts +1 -3
- package/build/types/src/configs/tokens.d.ts +2 -2
- package/build/types/src/configs/twap.d.ts +7 -0
- package/build/types/src/modules/markets/query-builders.d.ts +1 -1
- package/build/types/src/modules/markets/types.d.ts +2 -2
- package/build/types/src/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -1
- package/build/types/src/test/mock.d.ts +16 -1
- package/build/types/src/types/fees.d.ts +9 -0
- package/build/types/src/types/markets.d.ts +1 -0
- package/build/types/src/types/orders.d.ts +3 -0
- package/build/types/src/types/tokens.d.ts +27 -0
- package/build/types/src/types/trade.d.ts +2 -19
- package/build/types/src/types/twap.d.ts +11 -0
- package/build/types/src/utils/__tests__/orderTransactions/batchUtils.spec.d.ts +1 -0
- package/build/types/src/utils/__tests__/orderTransactions/decreaseOrders.spec.d.ts +1 -0
- package/build/types/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.d.ts +1 -0
- package/build/types/src/utils/__tests__/orderTransactions/externalCalls.spec.d.ts +1 -0
- package/build/types/src/utils/__tests__/orderTransactions/increaseOrders.spec.d.ts +1 -0
- package/build/types/src/utils/__tests__/orderTransactions/swapOrders.spec.d.ts +1 -0
- package/build/types/src/utils/__tests__/orderTransactions/updateOrder.spec.d.ts +1 -0
- package/build/types/src/utils/__tests__/parseError.spec.d.ts +1 -0
- package/build/types/src/utils/__tests__/uiFeeReceiver.spec.d.ts +1 -0
- package/build/types/src/utils/bigmath.d.ts +1 -0
- package/build/types/src/utils/errors/index.d.ts +2 -0
- package/build/types/src/utils/errors/parseError.d.ts +50 -0
- package/build/types/src/utils/errors/transactionsErrors.d.ts +34 -0
- package/build/types/src/utils/fees/executionFee.d.ts +35 -2
- package/build/types/src/utils/fees/index.d.ts +1 -1
- package/build/types/src/utils/gelatoRelay.d.ts +2 -0
- package/build/types/src/utils/hash.d.ts +2 -0
- package/build/types/src/utils/marketKeysAndConfigs.d.ts +1 -0
- package/build/types/src/utils/markets.d.ts +1 -0
- package/build/types/src/utils/numbers.d.ts +110 -1
- package/build/types/src/utils/orderTransactions.d.ts +231 -0
- package/build/types/src/utils/orders.d.ts +2 -1
- package/build/types/src/utils/simulateExecuteOrder.d.ts +4 -0
- package/build/types/src/utils/swap/swapPath.d.ts +5 -5
- package/build/types/src/utils/swap/swapRouting.d.ts +2 -2
- package/build/types/src/utils/swap/swapStats.d.ts +2 -0
- package/build/types/src/utils/time.d.ts +14 -0
- package/build/types/src/utils/tokens.d.ts +6 -5
- package/build/types/src/utils/twap/index.d.ts +17 -0
- package/build/types/src/utils/twap/uiFeeReceiver.d.ts +9 -0
- package/build/types/src/utils/types.d.ts +5 -0
- package/package.json +3 -1
- package/build/types/src/utils/contracts.d.ts +0 -19
|
@@ -1244,6 +1244,66 @@
|
|
|
1244
1244
|
"longInterestInTokensUsingShortToken": "0x401b4f7fe4e249488787c5e8ed3d5b0b097ac08e418f45b7cb148b2c9fed9f43",
|
|
1245
1245
|
"shortInterestInTokensUsingLongToken": "0xd30216795b710aa170af3198f18a117b7bd846a98051fdd9d73b9a80002223b9",
|
|
1246
1246
|
"shortInterestInTokensUsingShortToken": "0xdfddd1e52c69cfcb2242fe606793a01faa8fa0bbbf2e482c89f600e74dd24f09"
|
|
1247
|
+
},
|
|
1248
|
+
"0x0e46941F9bfF8d0784BFfa3d0D7883CDb82D7aE7": {
|
|
1249
|
+
"longPoolAmount": "0x76339270fdf9fe51d24e487304213bdb0e24389b875d0e7d3f7398a8c92de8b5",
|
|
1250
|
+
"shortPoolAmount": "0xa1210429f9581af23981f66de5daca169404b4e37c8daca06dc62fe56a947cf4",
|
|
1251
|
+
"positionImpactPoolAmount": "0x89e555a84a9efa20e5ce28cb2a0df69557d180ab3da7cb1cc925162dd833cfc2",
|
|
1252
|
+
"swapImpactPoolAmountLong": "0xfbcb206ea4f7f1710bed958a5c148695f00afa1483f7f239f123720fe3d7c04e",
|
|
1253
|
+
"swapImpactPoolAmountShort": "0x86edc84a8c9ee6a09d745337c03d8005efd194acdddef85e36054d8313d36980",
|
|
1254
|
+
"longInterestUsingLongToken": "0xc99f3886c7d51b7d601686086b17ce369710a8d8af5c841a04a9eee87168fa68",
|
|
1255
|
+
"longInterestUsingShortToken": "0x839a0605a5833c4bf23d839f9753ad7b7f527d1d70fd49e229829e81d1b0e75b",
|
|
1256
|
+
"shortInterestUsingLongToken": "0xaf71d1be4d68c93f86dd1231424dc8978f28799e03e76aee5b3b1d8e219735d1",
|
|
1257
|
+
"shortInterestUsingShortToken": "0x77ea0d9da2ae89c287618474189f7d0cbd002043bf9e1524b3a20ed9097ec4cf",
|
|
1258
|
+
"longInterestInTokensUsingLongToken": "0xa9c8c0075d6b9f7ea3257f5868d91a1066be9c72cbfd79c3378398677fc454e9",
|
|
1259
|
+
"longInterestInTokensUsingShortToken": "0x990383f8aeebd168f8a25a52959bac05b31864a40946078e9c1821cc31997f17",
|
|
1260
|
+
"shortInterestInTokensUsingLongToken": "0x5f86375e18d3884992954c21ebe2191fc875d5d7514d830c967296d98ad22e03",
|
|
1261
|
+
"shortInterestInTokensUsingShortToken": "0xdef08d11b573ba8e3b6d919c724a60bbed677501313332e2d09bf3ef4e4a057f"
|
|
1262
|
+
},
|
|
1263
|
+
"0x2523B89298908FEf4c5e5bd6F55F20926e22058f": {
|
|
1264
|
+
"longPoolAmount": "0xc1cb4d3d87e1401e8b451df65d5bb41d628a71fce88be244b1be8a137ca5390a",
|
|
1265
|
+
"shortPoolAmount": "0x47e03c22f82ad390e58372207fd4c6d5a1685935568a343d2967fc263447ff4b",
|
|
1266
|
+
"positionImpactPoolAmount": "0x789583d3f45ef3e09b31e99fc1b3b47d1bdc3c179d4133b04e8f6a2810a171b4",
|
|
1267
|
+
"swapImpactPoolAmountLong": "0xc196aa2876aed0daa4a963857bf348cfc35acbfb7f5b3131c43cb63ddc104f58",
|
|
1268
|
+
"swapImpactPoolAmountShort": "0x37f0eabb9281ed4c4e87eb6c8b1a8264733d74deb3a2736908ee2e1d332bacb2",
|
|
1269
|
+
"longInterestUsingLongToken": "0x197bac785d03ea078e0b1fec22575baa8fdac1acd38fa15aefdfe092b2095477",
|
|
1270
|
+
"longInterestUsingShortToken": "0x28c25793551271bd5b21b8c86f31e16060dfe01e3ad6046c6f4be2bfbedd437c",
|
|
1271
|
+
"shortInterestUsingLongToken": "0xcb64f5ea4b0fffa761f1e828104bc0f49a7f887cf54731cec3634a4b7631427d",
|
|
1272
|
+
"shortInterestUsingShortToken": "0x585a446a024173ef0268da647ad0df5d5644b39235073e6d4e6da49f4c71deef",
|
|
1273
|
+
"longInterestInTokensUsingLongToken": "0x26e7ea7037b83a38bafbd2a65ca4a96371b56d6549ae8255a8aa820e2c5112e5",
|
|
1274
|
+
"longInterestInTokensUsingShortToken": "0x53cabdd1589982ca208ed4eccb26b9a4c84f02219b3097d7bfa348de853c1f15",
|
|
1275
|
+
"shortInterestInTokensUsingLongToken": "0xdd32f7b3d7add0fce0abaae3bef28acffc2e581605a60f6f272781352ddea05e",
|
|
1276
|
+
"shortInterestInTokensUsingShortToken": "0x713b5c0f4d0910279e8d3bad2e6d80f784c6d0ba3fb55ce6e0327937d4b81bc5"
|
|
1277
|
+
},
|
|
1278
|
+
"0x7c54D547FAD72f8AFbf6E5b04403A0168b654C6f": {
|
|
1279
|
+
"longPoolAmount": "0xead0643a2dc9e50fd5d68a68feee0b1bab6f98c5acc68e480bbec9ae7ee920f2",
|
|
1280
|
+
"shortPoolAmount": "0x3c6786065166f7f8a3829b4d978a706c91c622febcbfa56eb8308bd23fa1d352",
|
|
1281
|
+
"positionImpactPoolAmount": "0xd59fbf1f47b4fa2fb02b36548fae94bbf1e3a3d26fa5e0c5250066dc583c0839",
|
|
1282
|
+
"swapImpactPoolAmountLong": "0xbf213e14458ad58545aea523ec0105609069dad6b6b017eda8f0024daf63422b",
|
|
1283
|
+
"swapImpactPoolAmountShort": "0xf45fc23e8e69e28a9fa3a184fb43f255defdde09b840bfbca5192cda38b4f960",
|
|
1284
|
+
"longInterestUsingLongToken": "0x185834a73a6749224b3fcb782fc3ef073266aa5d77e39857125524964b2764b6",
|
|
1285
|
+
"longInterestUsingShortToken": "0xf2c5529f9011666344b81373a841fd14bb1b97f7562b761fd8b678302906eb4c",
|
|
1286
|
+
"shortInterestUsingLongToken": "0x33d0f93fc2126fe4d94c308eae266696b2b13adf7c0221d89f4e62020af79584",
|
|
1287
|
+
"shortInterestUsingShortToken": "0x466523fd838cf12da1d164b26cfb2eccec195bd29d8aecbf49cdd60ed06c56d8",
|
|
1288
|
+
"longInterestInTokensUsingLongToken": "0x5c1f450df618dc8dd4e3f46d6ddfa8f8e27a857ba2934ec5d4cec14182cd7b34",
|
|
1289
|
+
"longInterestInTokensUsingShortToken": "0xebd0844d77cf10b0a53213d880054e84a66dfd57853c583cbce83e124dc24a96",
|
|
1290
|
+
"shortInterestInTokensUsingLongToken": "0x09467669e73c2ebad9ae4ce2aa06ca52348ae5da2d25be4c35b608e4dff0e2bc",
|
|
1291
|
+
"shortInterestInTokensUsingShortToken": "0x4f4bacd66cdf5d93d6c55dd2c019d75653b63183bef9db11f98764fdd8cc60c7"
|
|
1292
|
+
},
|
|
1293
|
+
"0x39AC3C494950A4363D739201BA5A0861265C9ae5": {
|
|
1294
|
+
"longPoolAmount": "0x8b35db61cf1d679856d17037bff17b6d5909ef3d237ec5fddb6e9c45a2553c95",
|
|
1295
|
+
"shortPoolAmount": "0x74b22e46171010c4d6867a3420af82b00c739ec3bbeb295a4cf625bcdbfe07b5",
|
|
1296
|
+
"positionImpactPoolAmount": "0x9435975a828122df0431350d47a44d4700715d393c9d5f55a4fe7d1972f1d95f",
|
|
1297
|
+
"swapImpactPoolAmountLong": "0x9113211843bb2a4695cb03f9350950920a54e63b8a69010a2a9b440fc41d6ef8",
|
|
1298
|
+
"swapImpactPoolAmountShort": "0xa9a4df803ab35db2d17f39f87fd42b18a2830e58416f919391481f6d2e31a3c2",
|
|
1299
|
+
"longInterestUsingLongToken": "0x4e71590171ab7ef030cafac110a7385d65ce24f61c6c2edb04898654f04ec898",
|
|
1300
|
+
"longInterestUsingShortToken": "0x915ae07505869779440f15749260d59c6ea24880abd0d72c343b52d2b86b8f40",
|
|
1301
|
+
"shortInterestUsingLongToken": "0x829c7683ed83c5cff99e9e5313aff403cd26085ba4a43964d011d6bd4977efcd",
|
|
1302
|
+
"shortInterestUsingShortToken": "0xd193c75ba20a56756011040cfd14a59b30a569e75a1ac818c598210db4459c52",
|
|
1303
|
+
"longInterestInTokensUsingLongToken": "0x30d45feb138a7c16fa2eb74acaee67e95e1c60bc1e10c30301d3762b64883834",
|
|
1304
|
+
"longInterestInTokensUsingShortToken": "0x270eaf7ded63283fe668107dae6e74b2f65611f2ce8ac93f7587aa42690e726a",
|
|
1305
|
+
"shortInterestInTokensUsingLongToken": "0xba25770c0d2c19cb82136ca008f7f59e3f0a6273159a121852ef001e7fcf5cd4",
|
|
1306
|
+
"shortInterestInTokensUsingShortToken": "0x434a95fd250b7b15239714a1a92599a7706c946310e7cc999a66202318a3b9d5"
|
|
1247
1307
|
}
|
|
1248
1308
|
},
|
|
1249
1309
|
"43113": {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockMarketsInfoData = exports.mockMarketsData = exports.mockTokensData = exports.mockMarketKeys = exports.usdToToken = void 0;
|
|
3
|
+
exports.mockExternalSwap = exports.mockMarketsInfoData = exports.mockMarketsData = exports.mockTokensData = exports.mockMarketKeys = exports.MOCK_GAS_PRICE = exports.usdToToken = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const factors_1 = require("../configs/factors");
|
|
6
|
+
const trade_1 = require("../types/trade");
|
|
6
7
|
const markets_1 = require("../utils/markets");
|
|
7
8
|
const numbers_1 = require("../utils/numbers");
|
|
8
9
|
const tokens_1 = require("../utils/tokens");
|
|
@@ -10,6 +11,7 @@ function usdToToken(usd, token) {
|
|
|
10
11
|
return (0, tokens_1.convertToTokenAmount)((0, numbers_1.expandDecimals)(usd, factors_1.USD_DECIMALS), token.decimals, token.prices?.minPrice);
|
|
11
12
|
}
|
|
12
13
|
exports.usdToToken = usdToToken;
|
|
14
|
+
exports.MOCK_GAS_PRICE = 100000000n; // (0.1 gwei)
|
|
13
15
|
function mockMarketKeys() {
|
|
14
16
|
return [
|
|
15
17
|
"AVAX-AVAX-USDC",
|
|
@@ -199,6 +201,7 @@ function mockMarketsInfoData(tokensData, marketKeys, overrides = {}) {
|
|
|
199
201
|
positionImpactExponentFactor: (0, numbers_1.expandDecimals)(2, 30),
|
|
200
202
|
swapFeeFactorForPositiveImpact: (0, numbers_1.expandDecimals)(2, 27),
|
|
201
203
|
swapFeeFactorForNegativeImpact: (0, numbers_1.expandDecimals)(2, 27),
|
|
204
|
+
atomicSwapFeeFactor: (0, numbers_1.expandDecimals)(2, 27),
|
|
202
205
|
swapImpactFactorPositive: (0, numbers_1.expandDecimals)(2, 23),
|
|
203
206
|
swapImpactFactorNegative: (0, numbers_1.expandDecimals)(1, 23),
|
|
204
207
|
swapImpactExponentFactor: (0, numbers_1.expandDecimals)(2, 30),
|
|
@@ -244,3 +247,29 @@ function mockMarketsInfoData(tokensData, marketKeys, overrides = {}) {
|
|
|
244
247
|
}, {});
|
|
245
248
|
}
|
|
246
249
|
exports.mockMarketsInfoData = mockMarketsInfoData;
|
|
250
|
+
function mockExternalSwap({ inToken, outToken, amountIn, amountOut, priceIn, priceOut, feesUsd = (0, numbers_1.expandDecimals)(5, factors_1.USD_DECIMALS), // $5 default fee
|
|
251
|
+
data = "0x1", to = "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64", receiver = "0x1234567890123456789012345678901234567890", }) {
|
|
252
|
+
const usdIn = (amountIn * priceIn) / (0, numbers_1.expandDecimals)(1, inToken.decimals);
|
|
253
|
+
const usdOut = (amountOut * priceOut) / (0, numbers_1.expandDecimals)(1, outToken.decimals);
|
|
254
|
+
return {
|
|
255
|
+
aggregator: trade_1.ExternalSwapAggregator.OpenOcean,
|
|
256
|
+
inTokenAddress: inToken.address,
|
|
257
|
+
outTokenAddress: outToken.address,
|
|
258
|
+
receiver,
|
|
259
|
+
usdIn,
|
|
260
|
+
usdOut,
|
|
261
|
+
amountIn,
|
|
262
|
+
amountOut,
|
|
263
|
+
priceIn,
|
|
264
|
+
priceOut,
|
|
265
|
+
feesUsd,
|
|
266
|
+
txnData: {
|
|
267
|
+
to,
|
|
268
|
+
data,
|
|
269
|
+
value: 0n,
|
|
270
|
+
estimatedGas: 100000n,
|
|
271
|
+
estimatedExecutionFee: 100000n,
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
exports.mockExternalSwap = mockExternalSwap;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const factors_1 = require("../../configs/factors");
|
|
5
|
+
const ONE_USD = 1000000000000000000000000000000n;
|
|
5
6
|
const numbers_1 = require("../numbers");
|
|
6
7
|
(0, vitest_1.describe)("numbers utils", () => {
|
|
7
8
|
(0, vitest_1.it)("constants", () => {
|
|
@@ -81,3 +82,219 @@ const numbers_1 = require("../numbers");
|
|
|
81
82
|
(0, vitest_1.expect)((0, numbers_1.numberToBigint)(-1.123456789, 6)).toEqual(-1123456n);
|
|
82
83
|
});
|
|
83
84
|
});
|
|
85
|
+
(0, vitest_1.describe)("toBigNumberWithDecimals", () => {
|
|
86
|
+
(0, vitest_1.it)("should convert string to big number with decimals", () => {
|
|
87
|
+
(0, vitest_1.expect)((0, numbers_1.toBigNumberWithDecimals)("0", numbers_1.PRECISION_DECIMALS)).toBe(0n);
|
|
88
|
+
(0, vitest_1.expect)((0, numbers_1.toBigNumberWithDecimals)("1", numbers_1.PRECISION_DECIMALS)).toBe(1000000000000000000000000000000n);
|
|
89
|
+
(0, vitest_1.expect)((0, numbers_1.toBigNumberWithDecimals)("123.456", numbers_1.PRECISION_DECIMALS)).toBe(123456000000000000000000000000000n);
|
|
90
|
+
(0, vitest_1.expect)((0, numbers_1.toBigNumberWithDecimals)("123.456789", numbers_1.PRECISION_DECIMALS)).toBe(123456789000000000000000000000000n);
|
|
91
|
+
(0, vitest_1.expect)((0, numbers_1.toBigNumberWithDecimals)("-1.5", numbers_1.PRECISION_DECIMALS)).toBe(-1500000000000000000000000000000n);
|
|
92
|
+
(0, vitest_1.expect)((0, numbers_1.toBigNumberWithDecimals)("0.000001", numbers_1.PRECISION_DECIMALS)).toBe(1000000000000000000000000n);
|
|
93
|
+
});
|
|
94
|
+
(0, vitest_1.it)("should handle strings with more decimals than token decimals parameter", () => {
|
|
95
|
+
(0, vitest_1.expect)((0, numbers_1.toBigNumberWithDecimals)("0.123456789012345678901234567890", 5)).toBe(12345n);
|
|
96
|
+
});
|
|
97
|
+
(0, vitest_1.it)("should handle cases with different token decimals ", () => {
|
|
98
|
+
(0, vitest_1.expect)((0, numbers_1.toBigNumberWithDecimals)("0.1234567890123456789012345678901", 18)).toBe(123456789012345678n);
|
|
99
|
+
(0, vitest_1.expect)((0, numbers_1.toBigNumberWithDecimals)("0.12345", 5)).toBe(12345n);
|
|
100
|
+
(0, vitest_1.expect)((0, numbers_1.toBigNumberWithDecimals)("0.1", 1)).toBe(1n);
|
|
101
|
+
});
|
|
102
|
+
(0, vitest_1.it)("should be compatible with formatAmount", () => {
|
|
103
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmount)((0, numbers_1.toBigNumberWithDecimals)("123.456", numbers_1.PRECISION_DECIMALS), factors_1.USD_DECIMALS, 3)).toBe("123.456");
|
|
104
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmount)((0, numbers_1.toBigNumberWithDecimals)("0.789", numbers_1.PRECISION_DECIMALS), factors_1.USD_DECIMALS, 2)).toBe("0.79");
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
(0, vitest_1.describe)("roundWithDecimals", () => {
|
|
108
|
+
(0, vitest_1.it)("should round small numbers correctly", () => {
|
|
109
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("0.0000001", numbers_1.PRECISION_DECIMALS), {
|
|
110
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
111
|
+
displayDecimals: 0,
|
|
112
|
+
})).toBe(0n);
|
|
113
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("0.5", numbers_1.PRECISION_DECIMALS), {
|
|
114
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
115
|
+
displayDecimals: 0,
|
|
116
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("1", numbers_1.PRECISION_DECIMALS));
|
|
117
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("0.499", numbers_1.PRECISION_DECIMALS), {
|
|
118
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
119
|
+
displayDecimals: 0,
|
|
120
|
+
})).toBe(0n);
|
|
121
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("1", numbers_1.PRECISION_DECIMALS), {
|
|
122
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
123
|
+
displayDecimals: 1,
|
|
124
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("1", numbers_1.PRECISION_DECIMALS));
|
|
125
|
+
});
|
|
126
|
+
(0, vitest_1.it)("should round numbers at specific decimal places", () => {
|
|
127
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("1.49", numbers_1.PRECISION_DECIMALS), {
|
|
128
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
129
|
+
displayDecimals: 1,
|
|
130
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("1.5", numbers_1.PRECISION_DECIMALS));
|
|
131
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("1.44", numbers_1.PRECISION_DECIMALS), {
|
|
132
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
133
|
+
displayDecimals: 1,
|
|
134
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("1.4", numbers_1.PRECISION_DECIMALS));
|
|
135
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("1.499", numbers_1.PRECISION_DECIMALS), {
|
|
136
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
137
|
+
displayDecimals: 2,
|
|
138
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("1.50", numbers_1.PRECISION_DECIMALS));
|
|
139
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("1.495", numbers_1.PRECISION_DECIMALS), {
|
|
140
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
141
|
+
displayDecimals: 2,
|
|
142
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("1.50", numbers_1.PRECISION_DECIMALS));
|
|
143
|
+
});
|
|
144
|
+
(0, vitest_1.it)("should round large numbers correctly", () => {
|
|
145
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("499.999999", numbers_1.PRECISION_DECIMALS), {
|
|
146
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
147
|
+
displayDecimals: 5,
|
|
148
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("500.00000", numbers_1.PRECISION_DECIMALS));
|
|
149
|
+
});
|
|
150
|
+
(0, vitest_1.it)("should handle complex rounding cases", () => {
|
|
151
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("0.0000000000000000000000000001", numbers_1.PRECISION_DECIMALS), {
|
|
152
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
153
|
+
displayDecimals: 25,
|
|
154
|
+
})).toBe(0n);
|
|
155
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("0.4999999999999999999999999999", numbers_1.PRECISION_DECIMALS), {
|
|
156
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
157
|
+
displayDecimals: 25,
|
|
158
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("0.5", numbers_1.PRECISION_DECIMALS));
|
|
159
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("123.456789", numbers_1.PRECISION_DECIMALS), {
|
|
160
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
161
|
+
displayDecimals: 4,
|
|
162
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("123.4568", numbers_1.PRECISION_DECIMALS));
|
|
163
|
+
});
|
|
164
|
+
(0, vitest_1.it)("should round numbers with different token decimals correctly", () => {
|
|
165
|
+
const differentTokenDecimals = [18, 5, 1, 22];
|
|
166
|
+
for (const tokenDecimals of differentTokenDecimals) {
|
|
167
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("123.456789", tokenDecimals), {
|
|
168
|
+
decimals: tokenDecimals,
|
|
169
|
+
displayDecimals: 4,
|
|
170
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("123.4568", tokenDecimals));
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
(0, vitest_1.it)("should handle edge cases", () => {
|
|
174
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)(0n, { decimals: numbers_1.PRECISION_DECIMALS, displayDecimals: 10 })).toBe(0n);
|
|
175
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("-1.5", numbers_1.PRECISION_DECIMALS), {
|
|
176
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
177
|
+
displayDecimals: 0,
|
|
178
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("-2", numbers_1.PRECISION_DECIMALS));
|
|
179
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("-1.4", numbers_1.PRECISION_DECIMALS), {
|
|
180
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
181
|
+
displayDecimals: 0,
|
|
182
|
+
})).toBe((0, numbers_1.toBigNumberWithDecimals)("-1", numbers_1.PRECISION_DECIMALS));
|
|
183
|
+
(0, vitest_1.expect)((0, numbers_1.roundWithDecimals)((0, numbers_1.toBigNumberWithDecimals)("0.0000001", numbers_1.PRECISION_DECIMALS), {
|
|
184
|
+
decimals: numbers_1.PRECISION_DECIMALS,
|
|
185
|
+
displayDecimals: 5,
|
|
186
|
+
})).toBe(0n);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
(0, vitest_1.describe)("formatUsdPrice", () => {
|
|
190
|
+
(0, vitest_1.it)("should tolerate undefined", () => {
|
|
191
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)()).toBeUndefined();
|
|
192
|
+
});
|
|
193
|
+
(0, vitest_1.it)("should return NA if negative", () => {
|
|
194
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(-1n)).toBe("NA");
|
|
195
|
+
});
|
|
196
|
+
(0, vitest_1.it)("should calculate correct decimals if displayDecimals not passed", () => {
|
|
197
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD * 10000n)).toBe("$10,000.00");
|
|
198
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD * 1000n)).toBe("$1,000.00");
|
|
199
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD * 100n)).toBe("$100.000");
|
|
200
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD * 10n)).toBe("$10.0000");
|
|
201
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD)).toBe("$1.0000");
|
|
202
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD / 10n)).toBe("$0.10000");
|
|
203
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD / 100n)).toBe("$0.010000");
|
|
204
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD / 1000n)).toBe("$0.0010000");
|
|
205
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD / 10000n)).toBe("$0.0001000");
|
|
206
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD / 100000n)).toBe("$0.00001000");
|
|
207
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD / 1000000000n)).toBe("$0.000000001");
|
|
208
|
+
(0, vitest_1.expect)((0, numbers_1.formatUsdPrice)(ONE_USD / 10000000000n)).toBe("< $0.000000001");
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
(0, vitest_1.describe)("formatAmountHuman", () => {
|
|
212
|
+
(0, vitest_1.it)("positive", () => {
|
|
213
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(ONE_USD, factors_1.USD_DECIMALS)).toBe("1.0");
|
|
214
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(ONE_USD * 1000n, factors_1.USD_DECIMALS)).toBe("1.0k");
|
|
215
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(ONE_USD * 1000000n, factors_1.USD_DECIMALS)).toBe("1.0m");
|
|
216
|
+
});
|
|
217
|
+
(0, vitest_1.it)("negative", () => {
|
|
218
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(-1n * ONE_USD, factors_1.USD_DECIMALS)).toBe("-1.0");
|
|
219
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(-1n * ONE_USD * 1000n, factors_1.USD_DECIMALS)).toBe("-1.0k");
|
|
220
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(-1n * ONE_USD * 1000000n, factors_1.USD_DECIMALS)).toBe("-1.0m");
|
|
221
|
+
});
|
|
222
|
+
(0, vitest_1.it)("should display dollar sign", () => {
|
|
223
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(ONE_USD, factors_1.USD_DECIMALS, true)).toBe("$1.0");
|
|
224
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(-1n * ONE_USD, factors_1.USD_DECIMALS, true)).toBe("-$1.0");
|
|
225
|
+
});
|
|
226
|
+
(0, vitest_1.it)("should display decimals", () => {
|
|
227
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(ONE_USD * 1000n, factors_1.USD_DECIMALS, false, 2)).toBe("1.00k");
|
|
228
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(ONE_USD * 1500000n, factors_1.USD_DECIMALS, false, 2)).toBe("1.50m");
|
|
229
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(ONE_USD * 1000n, factors_1.USD_DECIMALS, false, 0)).toBe("1k");
|
|
230
|
+
(0, vitest_1.expect)((0, numbers_1.formatAmountHuman)(ONE_USD * 1500000n, factors_1.USD_DECIMALS, false, 0)).toBe("2m");
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
(0, vitest_1.describe)("formatBalanceAmount", () => {
|
|
234
|
+
(0, vitest_1.it)("should display balance amount", () => {
|
|
235
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD * 1000n, factors_1.USD_DECIMALS)).toBe("1,000.0000");
|
|
236
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(0n, factors_1.USD_DECIMALS)).toBe("-");
|
|
237
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(0n, factors_1.USD_DECIMALS, undefined, true)).toBe("0.0000");
|
|
238
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD * 1n, factors_1.USD_DECIMALS)).toBe("1.0000");
|
|
239
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD / 10n, factors_1.USD_DECIMALS)).toBe("0.10000");
|
|
240
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD / 100n, factors_1.USD_DECIMALS)).toBe("0.010000");
|
|
241
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD / 1000n, factors_1.USD_DECIMALS)).toBe("0.0010000");
|
|
242
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD / 10000n, factors_1.USD_DECIMALS)).toBe("0.00010000");
|
|
243
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD / 100000n, factors_1.USD_DECIMALS)).toBe("0.00001000");
|
|
244
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD / 1000000n, factors_1.USD_DECIMALS)).toBe("0.00000100");
|
|
245
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD / 10000000n, factors_1.USD_DECIMALS)).toBe("0.00000010");
|
|
246
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD / 100000000n, factors_1.USD_DECIMALS)).toBe("0.00000001");
|
|
247
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD / 1000000000n, factors_1.USD_DECIMALS)).toBe("1.00e-9");
|
|
248
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD / 1000000000000n, factors_1.USD_DECIMALS)).toBe("1.00e-12");
|
|
249
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD * -1n, factors_1.USD_DECIMALS)).toBe("-1.0000");
|
|
250
|
+
});
|
|
251
|
+
(0, vitest_1.it)("should display balance amount with symbol", () => {
|
|
252
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(ONE_USD, factors_1.USD_DECIMALS, "USDC")).toBe("1.0000 USDC");
|
|
253
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(0n, factors_1.USD_DECIMALS, "USDC", true)).toBe("0.0000 USDC");
|
|
254
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmount)(0n, factors_1.USD_DECIMALS, "USDC", false)).toBe("-");
|
|
255
|
+
});
|
|
256
|
+
(0, vitest_1.it)("should display balance amount with usd", () => {
|
|
257
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmountWithUsd)(ONE_USD, ONE_USD, factors_1.USD_DECIMALS)).toBe("1.0000 ($1.00)");
|
|
258
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmountWithUsd)(ONE_USD, ONE_USD, factors_1.USD_DECIMALS, "USDC")).toBe("1.0000 USDC ($1.00)");
|
|
259
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmountWithUsd)(0n, 0n, factors_1.USD_DECIMALS, "USDC")).toBe("-");
|
|
260
|
+
(0, vitest_1.expect)((0, numbers_1.formatBalanceAmountWithUsd)(0n, 0n, factors_1.USD_DECIMALS, "USDC", true)).toBe("0.0000 USDC ($0.00)");
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
(0, vitest_1.describe)("formatFactor", () => {
|
|
264
|
+
(0, vitest_1.it)("should format factor", () => {
|
|
265
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(0n)).toBe("0");
|
|
266
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1n)).toBe("0.000000000000000000000000000001");
|
|
267
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1000n)).toBe("0.000000000000000000000000001");
|
|
268
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1000000n)).toBe("0.000000000000000000000001");
|
|
269
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1000000000n)).toBe("0.000000000000000000001");
|
|
270
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1000000000000n)).toBe("0.000000000000000001");
|
|
271
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1000000000000000n)).toBe("0.000000000000001");
|
|
272
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1000000000000000000n)).toBe("0.000000000001");
|
|
273
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1000000000000000000000n)).toBe("0.000000001");
|
|
274
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1000000000000000000000000n)).toBe("0.000001");
|
|
275
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1000000000000000000000000000n)).toBe("0.001");
|
|
276
|
+
(0, vitest_1.expect)((0, numbers_1.formatFactor)(1000000000000000000000000000000n)).toBe("1");
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
(0, vitest_1.describe)("formatPercentage", () => {
|
|
280
|
+
(0, vitest_1.it)("should format a basic percentage", () => {
|
|
281
|
+
(0, vitest_1.expect)((0, numbers_1.formatPercentage)(100n, { displayDecimals: 4 })).toBe("1.0000%");
|
|
282
|
+
(0, vitest_1.expect)((0, numbers_1.formatPercentage)(2500n)).toBe("25.00%");
|
|
283
|
+
(0, vitest_1.expect)((0, numbers_1.formatPercentage)(123456n)).toBe("1234.56%");
|
|
284
|
+
});
|
|
285
|
+
(0, vitest_1.it)("should handle undefined input with fallbackToZero", () => {
|
|
286
|
+
(0, vitest_1.expect)((0, numbers_1.formatPercentage)(undefined, { fallbackToZero: true })).toBe("0.00%");
|
|
287
|
+
});
|
|
288
|
+
(0, vitest_1.it)("should display signed percentage", () => {
|
|
289
|
+
(0, vitest_1.expect)((0, numbers_1.formatPercentage)(100n, { signed: true })).toBe("+1.00%");
|
|
290
|
+
(0, vitest_1.expect)((0, numbers_1.formatPercentage)(-100n, { signed: true })).toBe("-1.00%");
|
|
291
|
+
});
|
|
292
|
+
(0, vitest_1.it)("should format with different displayDecimals", () => {
|
|
293
|
+
(0, vitest_1.expect)((0, numbers_1.formatPercentage)(100n, { displayDecimals: 2 })).toBe("1.00%");
|
|
294
|
+
(0, vitest_1.expect)((0, numbers_1.formatPercentage)(123456n, { displayDecimals: 1 })).toBe("1234.6%");
|
|
295
|
+
});
|
|
296
|
+
(0, vitest_1.it)("should handle basis points (bps) formatting", () => {
|
|
297
|
+
(0, vitest_1.expect)((0, numbers_1.formatPercentage)((0, numbers_1.toBigNumberWithDecimals)("1", numbers_1.PERCENT_PRECISION_DECIMALS), { bps: false, displayDecimals: 4 })).toBe("1.0000%");
|
|
298
|
+
(0, vitest_1.expect)((0, numbers_1.formatPercentage)((0, numbers_1.toBigNumberWithDecimals)("0.999", numbers_1.PERCENT_PRECISION_DECIMALS), { bps: false, displayDecimals: 5 })).toBe("0.99900%");
|
|
299
|
+
});
|
|
300
|
+
});
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const viem_1 = require("viem");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
const chains_1 = require("../../../configs/chains");
|
|
6
|
+
const tokens_1 = require("../../../configs/tokens");
|
|
7
|
+
const orders_1 = require("../../../types/orders");
|
|
8
|
+
const numbers_1 = require("../../numbers");
|
|
9
|
+
const orderTransactions_1 = require("../../orderTransactions");
|
|
10
|
+
const mock_1 = require("../../../test/mock");
|
|
11
|
+
// Common tokens and addresses
|
|
12
|
+
const CHAIN_ID = chains_1.ARBITRUM;
|
|
13
|
+
const ACCOUNT = "0x1234567890123456789012345678901234567890";
|
|
14
|
+
const WETH = (0, tokens_1.getWrappedToken)(CHAIN_ID);
|
|
15
|
+
const USDC = (0, tokens_1.getTokenBySymbol)(CHAIN_ID, "USDC");
|
|
16
|
+
const USDT = (0, tokens_1.getTokenBySymbol)(CHAIN_ID, "USDT");
|
|
17
|
+
// Common MarketIncrease params
|
|
18
|
+
const commonMarketIncreaseParams = {
|
|
19
|
+
chainId: CHAIN_ID,
|
|
20
|
+
receiver: ACCOUNT,
|
|
21
|
+
executionGasLimit: 0n,
|
|
22
|
+
payTokenAddress: WETH.address,
|
|
23
|
+
payTokenAmount: (0, numbers_1.parseValue)("1", WETH.decimals),
|
|
24
|
+
marketAddress: "0x1111111111111111111111111111111111111111",
|
|
25
|
+
indexTokenAddress: WETH.address,
|
|
26
|
+
isLong: true,
|
|
27
|
+
sizeDeltaUsd: (0, numbers_1.parseValue)("1000", numbers_1.USD_DECIMALS),
|
|
28
|
+
sizeDeltaInTokens: (0, numbers_1.parseValue)("1", WETH.decimals),
|
|
29
|
+
acceptablePrice: (0, numbers_1.parseValue)("1200", numbers_1.USD_DECIMALS),
|
|
30
|
+
collateralTokenAddress: WETH.address,
|
|
31
|
+
collateralDeltaAmount: (0, numbers_1.parseValue)("1", WETH.decimals),
|
|
32
|
+
swapPath: [WETH.address],
|
|
33
|
+
externalSwapQuote: undefined,
|
|
34
|
+
minOutputAmount: 0n,
|
|
35
|
+
triggerPrice: undefined,
|
|
36
|
+
referralCode: viem_1.zeroHash,
|
|
37
|
+
autoCancel: false,
|
|
38
|
+
allowedSlippage: 100,
|
|
39
|
+
executionFeeAmount: (0, numbers_1.parseValue)("0.1", WETH.decimals),
|
|
40
|
+
validFromTime: 0n,
|
|
41
|
+
orderType: orders_1.OrderType.MarketIncrease,
|
|
42
|
+
uiFeeReceiver: viem_1.zeroAddress,
|
|
43
|
+
};
|
|
44
|
+
// Helper to build a batch with multiple increase orders
|
|
45
|
+
function buildMultiIncreaseBatch(paramsList) {
|
|
46
|
+
return {
|
|
47
|
+
createOrderParams: paramsList.map((p) => (0, orderTransactions_1.buildIncreaseOrderPayload)(p)),
|
|
48
|
+
updateOrderParams: [],
|
|
49
|
+
cancelOrderParams: [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
(0, vitest_1.describe)("Batch Utils", () => {
|
|
53
|
+
(0, vitest_1.describe)("getIsEmptyBatch", () => {
|
|
54
|
+
(0, vitest_1.it)("undefined batch", () => {
|
|
55
|
+
(0, vitest_1.expect)((0, orderTransactions_1.getIsEmptyBatch)(undefined)).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
(0, vitest_1.it)("zero actions batch", () => {
|
|
58
|
+
(0, vitest_1.expect)((0, orderTransactions_1.getIsEmptyBatch)({ createOrderParams: [], updateOrderParams: [], cancelOrderParams: [] })).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
(0, vitest_1.it)("multiple orders batch with one empty order", () => {
|
|
61
|
+
const emptyOrder = (0, orderTransactions_1.buildIncreaseOrderPayload)({
|
|
62
|
+
...commonMarketIncreaseParams,
|
|
63
|
+
payTokenAmount: 0n,
|
|
64
|
+
sizeDeltaUsd: 0n,
|
|
65
|
+
sizeDeltaInTokens: 0n,
|
|
66
|
+
collateralDeltaAmount: 0n,
|
|
67
|
+
});
|
|
68
|
+
const nonEmptyOrder = (0, orderTransactions_1.buildIncreaseOrderPayload)(commonMarketIncreaseParams);
|
|
69
|
+
const batch = {
|
|
70
|
+
createOrderParams: [emptyOrder, nonEmptyOrder],
|
|
71
|
+
updateOrderParams: [],
|
|
72
|
+
cancelOrderParams: [],
|
|
73
|
+
};
|
|
74
|
+
(0, vitest_1.expect)((0, orderTransactions_1.getIsEmptyBatch)(batch)).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.it)("multiple non-empty orders batch", () => {
|
|
77
|
+
const batch = buildMultiIncreaseBatch([commonMarketIncreaseParams, commonMarketIncreaseParams]);
|
|
78
|
+
(0, vitest_1.expect)((0, orderTransactions_1.getIsEmptyBatch)(batch)).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
(0, vitest_1.describe)("getBatchIsNativePayment", () => {
|
|
82
|
+
(0, vitest_1.it)("returns true if any order has native payment", () => {
|
|
83
|
+
const nativeParams = { ...commonMarketIncreaseParams, payTokenAddress: tokens_1.NATIVE_TOKEN_ADDRESS };
|
|
84
|
+
const batch = buildMultiIncreaseBatch([nativeParams]);
|
|
85
|
+
(0, vitest_1.expect)((0, orderTransactions_1.getBatchIsNativePayment)(batch)).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
(0, vitest_1.it)("returns false if no orders have native payment", () => {
|
|
88
|
+
const batch = buildMultiIncreaseBatch([commonMarketIncreaseParams]);
|
|
89
|
+
(0, vitest_1.expect)((0, orderTransactions_1.getBatchIsNativePayment)(batch)).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
(0, vitest_1.describe)("getIsInvalidBatchReceiver", () => {
|
|
93
|
+
(0, vitest_1.it)("returns true if orders have different receivers", () => {
|
|
94
|
+
const params1 = { ...commonMarketIncreaseParams, receiver: ACCOUNT };
|
|
95
|
+
const params2 = {
|
|
96
|
+
...commonMarketIncreaseParams,
|
|
97
|
+
receiver: "0x9999999999999999999999999999999999999999",
|
|
98
|
+
};
|
|
99
|
+
const batch = buildMultiIncreaseBatch([params1, params2]);
|
|
100
|
+
(0, vitest_1.expect)((0, orderTransactions_1.getIsInvalidBatchReceiver)(batch, ACCOUNT)).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
(0, vitest_1.it)("returns false if all orders have the same receiver", () => {
|
|
103
|
+
const batch = buildMultiIncreaseBatch([commonMarketIncreaseParams, commonMarketIncreaseParams]);
|
|
104
|
+
(0, vitest_1.expect)((0, orderTransactions_1.getIsInvalidBatchReceiver)(batch, ACCOUNT)).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
(0, vitest_1.describe)("getBatchExternalCalls", () => {
|
|
108
|
+
(0, vitest_1.it)("combines external calls from multiple orders", () => {
|
|
109
|
+
const params1 = {
|
|
110
|
+
...commonMarketIncreaseParams,
|
|
111
|
+
payTokenAddress: WETH.address,
|
|
112
|
+
payTokenAmount: (0, numbers_1.parseValue)("1", WETH.decimals),
|
|
113
|
+
externalSwapQuote: (0, mock_1.mockExternalSwap)({
|
|
114
|
+
inToken: WETH,
|
|
115
|
+
outToken: USDC,
|
|
116
|
+
to: "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64",
|
|
117
|
+
data: "0x1",
|
|
118
|
+
amountIn: (0, numbers_1.parseValue)("1", WETH.decimals),
|
|
119
|
+
amountOut: (0, numbers_1.parseValue)("1000", USDC.decimals),
|
|
120
|
+
priceIn: (0, numbers_1.expandDecimals)(1000, numbers_1.USD_DECIMALS),
|
|
121
|
+
priceOut: (0, numbers_1.expandDecimals)(1, numbers_1.USD_DECIMALS),
|
|
122
|
+
}),
|
|
123
|
+
};
|
|
124
|
+
const params2 = {
|
|
125
|
+
...commonMarketIncreaseParams,
|
|
126
|
+
payTokenAddress: USDC.address,
|
|
127
|
+
payTokenAmount: (0, numbers_1.parseValue)("1000", USDC.decimals),
|
|
128
|
+
externalSwapQuote: (0, mock_1.mockExternalSwap)({
|
|
129
|
+
inToken: USDC,
|
|
130
|
+
outToken: WETH,
|
|
131
|
+
to: "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64",
|
|
132
|
+
data: "0x2",
|
|
133
|
+
amountIn: (0, numbers_1.parseValue)("1000", USDC.decimals),
|
|
134
|
+
amountOut: (0, numbers_1.parseValue)("0.5", WETH.decimals),
|
|
135
|
+
priceIn: (0, numbers_1.expandDecimals)(1, numbers_1.USD_DECIMALS),
|
|
136
|
+
priceOut: (0, numbers_1.expandDecimals)(2000, numbers_1.USD_DECIMALS),
|
|
137
|
+
}),
|
|
138
|
+
};
|
|
139
|
+
const batch = buildMultiIncreaseBatch([params1, params2]);
|
|
140
|
+
const result = (0, orderTransactions_1.getBatchExternalCalls)(batch);
|
|
141
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
142
|
+
sendTokens: [WETH.address, USDC.address],
|
|
143
|
+
sendAmounts: [(0, numbers_1.parseValue)("1", WETH.decimals), (0, numbers_1.parseValue)("1000", USDC.decimals)],
|
|
144
|
+
externalCallTargets: [
|
|
145
|
+
"0x6352a56caadC4F1E25CD6c75970Fa768A3304e64",
|
|
146
|
+
"0x6352a56caadC4F1E25CD6c75970Fa768A3304e64",
|
|
147
|
+
],
|
|
148
|
+
externalCallDataList: ["0x1", "0x2"],
|
|
149
|
+
refundTokens: [WETH.address, USDC.address],
|
|
150
|
+
refundReceivers: [ACCOUNT, ACCOUNT],
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
(0, vitest_1.describe)("getBatchTotalPayCollateralAmount", () => {
|
|
155
|
+
(0, vitest_1.it)("sums pay amounts across orders", () => {
|
|
156
|
+
const params1 = {
|
|
157
|
+
...commonMarketIncreaseParams,
|
|
158
|
+
externalSwapQuote: undefined,
|
|
159
|
+
payTokenAmount: (0, numbers_1.parseValue)("1", WETH.decimals),
|
|
160
|
+
};
|
|
161
|
+
const params2 = {
|
|
162
|
+
...commonMarketIncreaseParams,
|
|
163
|
+
externalSwapQuote: undefined,
|
|
164
|
+
payTokenAmount: (0, numbers_1.parseValue)("2", WETH.decimals),
|
|
165
|
+
};
|
|
166
|
+
const params3 = {
|
|
167
|
+
...commonMarketIncreaseParams,
|
|
168
|
+
externalSwapQuote: undefined,
|
|
169
|
+
payTokenAddress: USDC.address,
|
|
170
|
+
payTokenAmount: (0, numbers_1.parseValue)("3", USDC.decimals),
|
|
171
|
+
};
|
|
172
|
+
const batch = buildMultiIncreaseBatch([params1, params2, params3]);
|
|
173
|
+
const result = (0, orderTransactions_1.getBatchTotalPayCollateralAmount)(batch);
|
|
174
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
175
|
+
[WETH.address]: (0, numbers_1.parseValue)("3", WETH.decimals),
|
|
176
|
+
[USDC.address]: (0, numbers_1.parseValue)("3", USDC.decimals),
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
(0, vitest_1.describe)("getBatchTotalExecutionFee", () => {
|
|
181
|
+
(0, vitest_1.it)("calculates total execution fee including top-ups", () => {
|
|
182
|
+
const params5 = {
|
|
183
|
+
...commonMarketIncreaseParams,
|
|
184
|
+
externalSwapQuote: undefined,
|
|
185
|
+
executionFeeAmount: (0, numbers_1.parseValue)("0.1", WETH.decimals),
|
|
186
|
+
};
|
|
187
|
+
const batch = buildMultiIncreaseBatch([params5]);
|
|
188
|
+
batch.updateOrderParams = [{ updatePayload: { executionFeeTopUp: (0, numbers_1.parseValue)("0.05", WETH.decimals) } }];
|
|
189
|
+
const tokensData = {
|
|
190
|
+
[WETH.address]: {
|
|
191
|
+
...WETH,
|
|
192
|
+
prices: {
|
|
193
|
+
minPrice: (0, numbers_1.expandDecimals)(2000, numbers_1.USD_DECIMALS),
|
|
194
|
+
maxPrice: (0, numbers_1.expandDecimals)(2000, numbers_1.USD_DECIMALS),
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
const result = (0, orderTransactions_1.getBatchTotalExecutionFee)({ batchParams: batch, tokensData, chainId: CHAIN_ID });
|
|
199
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
200
|
+
feeTokenAmount: (0, numbers_1.parseValue)("0.15", WETH.decimals),
|
|
201
|
+
gasLimit: 0n,
|
|
202
|
+
feeUsd: (0, numbers_1.expandDecimals)(300, numbers_1.USD_DECIMALS),
|
|
203
|
+
feeToken: tokensData[WETH.address],
|
|
204
|
+
isFeeHigh: true,
|
|
205
|
+
isFeeVeryHigh: true,
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
(0, vitest_1.describe)("getBatchExternalSwapGasLimit", () => {
|
|
210
|
+
(0, vitest_1.it)("sums gas limits from external swap quotes", () => {
|
|
211
|
+
const quote1 = (0, mock_1.mockExternalSwap)({
|
|
212
|
+
inToken: WETH,
|
|
213
|
+
outToken: USDC,
|
|
214
|
+
amountIn: (0, numbers_1.parseValue)("1", WETH.decimals),
|
|
215
|
+
amountOut: (0, numbers_1.parseValue)("1000", USDC.decimals),
|
|
216
|
+
priceIn: (0, numbers_1.expandDecimals)(1000, numbers_1.USD_DECIMALS),
|
|
217
|
+
priceOut: (0, numbers_1.expandDecimals)(1, numbers_1.USD_DECIMALS),
|
|
218
|
+
});
|
|
219
|
+
const quote2 = (0, mock_1.mockExternalSwap)({
|
|
220
|
+
inToken: USDC,
|
|
221
|
+
outToken: USDT,
|
|
222
|
+
amountIn: (0, numbers_1.parseValue)("1000", USDC.decimals),
|
|
223
|
+
amountOut: (0, numbers_1.parseValue)("1000", USDT.decimals),
|
|
224
|
+
priceIn: (0, numbers_1.expandDecimals)(1, numbers_1.USD_DECIMALS),
|
|
225
|
+
priceOut: (0, numbers_1.expandDecimals)(1, numbers_1.USD_DECIMALS),
|
|
226
|
+
});
|
|
227
|
+
const params6 = {
|
|
228
|
+
...commonMarketIncreaseParams,
|
|
229
|
+
externalSwapQuote: quote1,
|
|
230
|
+
};
|
|
231
|
+
const params7 = {
|
|
232
|
+
...commonMarketIncreaseParams,
|
|
233
|
+
externalSwapQuote: quote2,
|
|
234
|
+
payTokenAddress: USDC.address,
|
|
235
|
+
};
|
|
236
|
+
const batch = buildMultiIncreaseBatch([params6, params7]);
|
|
237
|
+
const result = (0, orderTransactions_1.getBatchExternalSwapGasLimit)(batch);
|
|
238
|
+
(0, vitest_1.expect)(result).toBe(quote1.txnData.estimatedGas + quote2.txnData.estimatedGas);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|