@gmx-io/sdk 1.3.1 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -37
- package/build/cjs/src/abis/ArbitrumNodeInterface.js +105 -0
- package/build/cjs/src/abis/ClaimHandler.js +424 -0
- package/build/cjs/src/abis/CustomErrors.js +1884 -0
- package/build/cjs/src/abis/DataStore.js +639 -0
- package/build/cjs/src/abis/ERC20PermitInterface.js +54 -0
- package/build/cjs/src/abis/ERC721.js +196 -0
- package/build/cjs/src/abis/EventEmitter.js +1228 -0
- package/build/cjs/src/abis/ExchangeRouter.js +1590 -0
- package/build/cjs/src/abis/GelatoRelayRouter.js +1579 -0
- package/build/cjs/src/abis/GlpManager.js +246 -0
- package/build/cjs/src/abis/GlvReader.js +1471 -0
- package/build/cjs/src/abis/GlvRouter.js +764 -0
- package/build/cjs/src/abis/GmxMigrator.js +269 -0
- package/build/cjs/src/abis/GovToken.js +325 -0
- package/build/cjs/src/abis/IStargate.js +603 -0
- package/build/cjs/src/abis/LayerZeroProvider.js +388 -0
- package/build/cjs/src/abis/MintableBaseToken.js +323 -0
- package/build/cjs/src/abis/Multicall.js +231 -0
- package/build/cjs/src/abis/MultichainClaimsRouter.js +1266 -0
- package/build/cjs/src/abis/MultichainGlvRouter.js +1150 -0
- package/build/cjs/src/abis/MultichainGmRouter.js +1449 -0
- package/build/cjs/src/abis/MultichainOrderRouter.js +2009 -0
- package/build/cjs/src/abis/MultichainSubaccountRouter.js +2069 -0
- package/build/cjs/src/abis/MultichainTransferRouter.js +915 -0
- package/build/cjs/src/abis/MultichainVault.js +275 -0
- package/build/cjs/src/abis/Reader.js +140 -0
- package/build/cjs/src/abis/ReaderV2.js +259 -0
- package/build/cjs/src/abis/ReferralStorage.js +261 -0
- package/build/cjs/src/abis/RelayParams.js +55 -0
- package/build/cjs/src/abis/RewardReader.js +35 -0
- package/build/cjs/src/abis/RewardRouter.js +460 -0
- package/build/cjs/src/abis/RewardTracker.js +415 -0
- package/build/cjs/src/abis/SmartAccount.js +14 -0
- package/build/cjs/src/abis/StBTC.js +513 -0
- package/build/cjs/src/abis/SubaccountApproval.js +17 -0
- package/build/cjs/src/abis/SubaccountGelatoRelayRouter.js +2019 -0
- package/build/cjs/src/abis/SubaccountRouter.js +602 -0
- package/build/cjs/src/abis/SyntheticsReader.js +4905 -0
- package/build/cjs/src/abis/SyntheticsRouter.js +72 -0
- package/build/cjs/src/abis/Timelock.js +778 -0
- package/build/cjs/src/abis/Token.js +150 -0
- package/build/cjs/src/abis/Treasury.js +206 -0
- package/build/cjs/src/abis/UniPool.js +36 -0
- package/build/cjs/src/abis/UniswapV2.js +287 -0
- package/build/cjs/src/abis/UniswapV3Factory.js +200 -0
- package/build/cjs/src/abis/UniswapV3Pool.js +985 -0
- package/build/cjs/src/abis/UniswapV3PositionManager.js +991 -0
- package/build/cjs/src/abis/Vault.js +1308 -0
- package/build/cjs/src/abis/VaultReader.js +30 -0
- package/build/cjs/src/abis/VaultV2.js +1222 -0
- package/build/cjs/src/abis/VaultV2b.js +1308 -0
- package/build/cjs/src/abis/VenusVToken.js +49 -0
- package/build/cjs/src/abis/Vester.js +456 -0
- package/build/cjs/src/abis/WETH.js +137 -0
- package/build/cjs/src/abis/index.js +106 -118
- package/build/cjs/src/configs/batch.js +31 -92
- package/build/cjs/src/configs/chainIds.js +17 -0
- package/build/cjs/src/configs/chains.js +251 -161
- package/build/cjs/src/configs/contracts.js +60 -85
- package/build/cjs/src/configs/dataStore.js +8 -11
- package/build/cjs/src/configs/express.js +17 -4
- package/build/cjs/src/configs/factors.js +2 -3
- package/build/cjs/src/configs/gasLimits.js +41 -0
- package/build/cjs/src/configs/markets.js +193 -1
- package/build/cjs/src/configs/multichain.js +27 -0
- package/build/cjs/src/configs/oracleKeeper.js +15 -2
- package/build/cjs/src/configs/tokens.js +162 -18
- package/build/cjs/src/configs/uniswapV3.js +18 -0
- package/build/cjs/src/configs/venus.js +58 -0
- package/build/cjs/src/modules/markets/index.js +42 -16
- package/build/cjs/src/modules/markets/markets.spec.js +5 -5
- package/build/cjs/src/modules/markets/query-builders.js +14 -10
- package/build/cjs/src/modules/orders/helpers.js +3 -2
- package/build/cjs/src/modules/orders/helpers.spec.js +1 -1
- package/build/cjs/src/modules/orders/orders.spec.js +1 -1
- package/build/cjs/src/modules/positions/positions.js +10 -2
- package/build/cjs/src/modules/positions/positions.spec.js +2 -2
- package/build/cjs/src/modules/tokens/tokens.spec.js +2 -2
- package/build/cjs/src/modules/trades/trades.js +2 -2
- package/build/cjs/src/modules/trades/trades.spec.js +1 -1
- package/build/cjs/src/modules/utils/utils.js +7 -6
- package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +112 -0
- package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +1402 -453
- package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +210 -0
- package/build/cjs/src/test/mock.js +5 -3
- package/build/cjs/src/types/chains.js +2 -0
- package/build/cjs/src/types/orders.js +8 -2
- package/build/cjs/src/types/subsquid.js +433 -217
- package/build/cjs/src/types/tokens.js +7 -0
- package/build/cjs/src/types/tradeHistory.js +9 -1
- package/build/cjs/src/utils/LruCache.js +21 -17
- package/build/cjs/src/utils/__tests__/LruCache.spec.js +11 -0
- package/build/cjs/src/utils/__tests__/abort.spec.js +122 -0
- package/build/cjs/src/utils/__tests__/fees.spec.js +4 -4
- package/build/cjs/src/utils/__tests__/{subgraph.spec.js → indexers.spec.js} +18 -18
- package/build/cjs/src/utils/__tests__/numbers.spec.js +95 -15
- package/build/cjs/src/utils/abort.js +31 -0
- package/build/cjs/src/utils/bigmath.js +3 -0
- package/build/cjs/src/utils/buildUrl.js +1 -0
- package/build/cjs/src/utils/callContract.js +4 -4
- package/build/cjs/src/utils/errors/transactionsErrors.js +1 -0
- package/build/cjs/src/utils/fees/executionFee.js +14 -11
- package/build/cjs/src/utils/fees/index.js +13 -8
- package/build/cjs/src/utils/fees/priceImpact.js +29 -19
- package/build/cjs/src/utils/{subgraph.js → indexers.js} +17 -1
- package/build/cjs/src/utils/marketKeysAndConfigs.js +15 -11
- package/build/cjs/src/utils/markets.js +16 -1
- package/build/cjs/src/utils/multicall.js +54 -17
- package/build/cjs/src/utils/numbers.js +34 -18
- package/build/cjs/src/utils/orderTransactions.js +5 -5
- package/build/cjs/src/utils/orders.js +11 -3
- package/build/cjs/src/utils/prices.js +0 -2
- package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +7 -6
- package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +5 -4
- package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +10 -9
- package/build/cjs/src/utils/swap/botanixStaking.js +3 -3
- package/build/cjs/src/utils/swap/buildSwapStrategy.js +10 -9
- package/build/cjs/src/utils/swap/swapPath.js +6 -15
- package/build/cjs/src/utils/swap/swapRouting.js +8 -4
- package/build/cjs/src/utils/swap/swapStats.js +6 -6
- package/build/cjs/src/utils/swap/swapValues.js +19 -15
- package/build/cjs/src/utils/tokens.js +17 -1
- package/build/cjs/src/utils/trade/decrease.js +7 -10
- package/build/cjs/src/utils/trade/increase.js +9 -8
- package/build/cjs/src/utils/tradeHistory.js +3 -0
- package/build/esm/src/abis/ArbitrumNodeInterface.js +103 -0
- package/build/esm/src/abis/ClaimHandler.js +422 -0
- package/build/esm/src/abis/CustomErrors.js +1882 -0
- package/build/esm/src/abis/DataStore.js +637 -0
- package/build/esm/src/abis/ERC20PermitInterface.js +52 -0
- package/build/esm/src/abis/ERC721.js +194 -0
- package/build/esm/src/abis/EventEmitter.js +1226 -0
- package/build/esm/src/abis/ExchangeRouter.js +1588 -0
- package/build/esm/src/abis/GelatoRelayRouter.js +1577 -0
- package/build/esm/src/abis/GlpManager.js +244 -0
- package/build/esm/src/abis/GlvReader.js +1469 -0
- package/build/esm/src/abis/GlvRouter.js +762 -0
- package/build/esm/src/abis/GmxMigrator.js +267 -0
- package/build/esm/src/abis/GovToken.js +323 -0
- package/build/esm/src/abis/IStargate.js +601 -0
- package/build/esm/src/abis/LayerZeroProvider.js +386 -0
- package/build/esm/src/abis/MintableBaseToken.js +321 -0
- package/build/esm/src/abis/Multicall.js +229 -0
- package/build/esm/src/abis/MultichainClaimsRouter.js +1264 -0
- package/build/esm/src/abis/MultichainGlvRouter.js +1148 -0
- package/build/esm/src/abis/MultichainGmRouter.js +1447 -0
- package/build/esm/src/abis/MultichainOrderRouter.js +2007 -0
- package/build/esm/src/abis/MultichainSubaccountRouter.js +2067 -0
- package/build/esm/src/abis/MultichainTransferRouter.js +913 -0
- package/build/esm/src/abis/MultichainVault.js +273 -0
- package/build/esm/src/abis/Reader.js +138 -0
- package/build/esm/src/abis/ReaderV2.js +257 -0
- package/build/esm/src/abis/ReferralStorage.js +259 -0
- package/build/esm/src/abis/RelayParams.js +53 -0
- package/build/esm/src/abis/RewardReader.js +33 -0
- package/build/esm/src/abis/RewardRouter.js +458 -0
- package/build/esm/src/abis/RewardTracker.js +413 -0
- package/build/esm/src/abis/SmartAccount.js +12 -0
- package/build/esm/src/abis/StBTC.js +511 -0
- package/build/esm/src/abis/SubaccountApproval.js +15 -0
- package/build/esm/src/abis/SubaccountGelatoRelayRouter.js +2017 -0
- package/build/esm/src/abis/SubaccountRouter.js +600 -0
- package/build/esm/src/abis/SyntheticsReader.js +4903 -0
- package/build/esm/src/abis/SyntheticsRouter.js +70 -0
- package/build/esm/src/abis/Timelock.js +776 -0
- package/build/esm/src/abis/Token.js +148 -0
- package/build/esm/src/abis/Treasury.js +204 -0
- package/build/esm/src/abis/UniPool.js +34 -0
- package/build/esm/src/abis/UniswapV2.js +285 -0
- package/build/esm/src/abis/UniswapV3Factory.js +198 -0
- package/build/esm/src/abis/UniswapV3Pool.js +983 -0
- package/build/esm/src/abis/UniswapV3PositionManager.js +989 -0
- package/build/esm/src/abis/Vault.js +1306 -0
- package/build/esm/src/abis/VaultReader.js +28 -0
- package/build/esm/src/abis/VaultV2.js +1220 -0
- package/build/esm/src/abis/VaultV2b.js +1306 -0
- package/build/esm/src/abis/VenusVToken.js +47 -0
- package/build/esm/src/abis/Vester.js +454 -0
- package/build/esm/src/abis/WETH.js +135 -0
- package/build/esm/src/abis/index.js +106 -118
- package/build/esm/src/configs/batch.js +31 -92
- package/build/esm/src/configs/chainIds.js +14 -0
- package/build/esm/src/configs/chains.js +215 -149
- package/build/esm/src/configs/contracts.js +60 -85
- package/build/esm/src/configs/dataStore.js +4 -6
- package/build/esm/src/configs/express.js +16 -3
- package/build/esm/src/configs/factors.js +1 -2
- package/build/esm/src/configs/gasLimits.js +38 -0
- package/build/esm/src/configs/markets.js +183 -0
- package/build/esm/src/configs/multichain.js +22 -0
- package/build/esm/src/configs/oracleKeeper.js +14 -1
- package/build/esm/src/configs/tokens.js +160 -17
- package/build/esm/src/configs/uniswapV3.js +13 -0
- package/build/esm/src/configs/venus.js +53 -0
- package/build/esm/src/modules/markets/index.js +42 -16
- package/build/esm/src/modules/markets/markets.spec.js +5 -5
- package/build/esm/src/modules/markets/query-builders.js +14 -10
- package/build/esm/src/modules/orders/helpers.js +4 -3
- package/build/esm/src/modules/orders/helpers.spec.js +1 -1
- package/build/esm/src/modules/orders/orders.spec.js +1 -1
- package/build/esm/src/modules/positions/positions.js +10 -2
- package/build/esm/src/modules/positions/positions.spec.js +2 -2
- package/build/esm/src/modules/tokens/tokens.spec.js +2 -2
- package/build/esm/src/modules/trades/trades.js +1 -1
- package/build/esm/src/modules/trades/trades.spec.js +1 -1
- package/build/esm/src/modules/utils/utils.js +7 -6
- package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +112 -0
- package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +1402 -453
- package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +210 -0
- package/build/esm/src/test/mock.js +5 -3
- package/build/esm/src/types/orders.js +8 -2
- package/build/esm/src/types/subsquid.js +432 -216
- package/build/esm/src/types/tokens.js +6 -1
- package/build/esm/src/types/tradeHistory.js +6 -0
- package/build/esm/src/utils/LruCache.js +21 -17
- package/build/esm/src/utils/__tests__/LruCache.spec.js +11 -0
- package/build/esm/src/utils/__tests__/abort.spec.js +120 -0
- package/build/esm/src/utils/__tests__/fees.spec.js +4 -4
- package/build/esm/src/utils/__tests__/{subgraph.spec.js → indexers.spec.js} +1 -1
- package/build/esm/src/utils/__tests__/numbers.spec.js +96 -16
- package/build/esm/src/utils/abort.js +27 -0
- package/build/esm/src/utils/bigmath.js +3 -0
- package/build/esm/src/utils/buildUrl.js +1 -0
- package/build/esm/src/utils/callContract.js +5 -5
- package/build/esm/src/utils/errors/transactionsErrors.js +1 -0
- package/build/esm/src/utils/fees/executionFee.js +15 -12
- package/build/esm/src/utils/fees/index.js +13 -8
- package/build/esm/src/utils/fees/priceImpact.js +28 -19
- package/build/esm/src/utils/{subgraph.js → indexers.js} +15 -0
- package/build/esm/src/utils/marketKeysAndConfigs.js +16 -12
- package/build/esm/src/utils/markets.js +13 -0
- package/build/esm/src/utils/multicall.js +53 -16
- package/build/esm/src/utils/numbers.js +29 -16
- package/build/esm/src/utils/orderTransactions.js +5 -5
- package/build/esm/src/utils/orders.js +11 -4
- package/build/esm/src/utils/prices.js +0 -2
- package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +7 -6
- package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +5 -4
- package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +10 -9
- package/build/esm/src/utils/swap/botanixStaking.js +3 -3
- package/build/esm/src/utils/swap/buildSwapStrategy.js +10 -9
- package/build/esm/src/utils/swap/swapPath.js +6 -15
- package/build/esm/src/utils/swap/swapRouting.js +8 -4
- package/build/esm/src/utils/swap/swapStats.js +6 -6
- package/build/esm/src/utils/swap/swapValues.js +19 -15
- package/build/esm/src/utils/tokens.js +15 -1
- package/build/esm/src/utils/trade/decrease.js +8 -11
- package/build/esm/src/utils/trade/increase.js +9 -8
- package/build/esm/src/utils/tradeHistory.js +3 -0
- package/build/types/src/abis/ArbitrumNodeInterface.d.ts +214 -0
- package/build/types/src/abis/ClaimHandler.d.ts +322 -0
- package/build/types/src/abis/CustomErrors.d.ts +3330 -0
- package/build/types/src/abis/DataStore.d.ts +1098 -0
- package/build/types/src/abis/ERC20PermitInterface.d.ts +90 -0
- package/build/types/src/abis/ERC721.d.ts +334 -0
- package/build/types/src/abis/EventEmitter.d.ts +1564 -0
- package/build/types/src/abis/ExchangeRouter.d.ts +1224 -0
- package/build/types/src/abis/GelatoRelayRouter.d.ts +1222 -0
- package/build/types/src/abis/GlpManager.d.ts +452 -0
- package/build/types/src/abis/GlvReader.d.ts +1131 -0
- package/build/types/src/abis/GlvRouter.d.ts +588 -0
- package/build/types/src/abis/GmxMigrator.d.ts +497 -0
- package/build/types/src/abis/GovToken.d.ts +588 -0
- package/build/types/src/abis/IStargate.d.ts +464 -0
- package/build/types/src/abis/LayerZeroProvider.d.ts +297 -0
- package/build/types/src/abis/MintableBaseToken.d.ts +526 -0
- package/build/types/src/abis/Multicall.d.ts +323 -0
- package/build/types/src/abis/MultichainClaimsRouter.d.ts +973 -0
- package/build/types/src/abis/MultichainGlvRouter.d.ts +886 -0
- package/build/types/src/abis/MultichainGmRouter.d.ts +1118 -0
- package/build/types/src/abis/MultichainOrderRouter.d.ts +1557 -0
- package/build/types/src/abis/MultichainSubaccountRouter.d.ts +1606 -0
- package/build/types/src/abis/MultichainTransferRouter.d.ts +702 -0
- package/build/types/src/abis/MultichainVault.d.ts +208 -0
- package/build/types/src/abis/Reader.d.ts +264 -0
- package/build/types/src/abis/ReaderV2.d.ts +474 -0
- package/build/types/src/abis/ReferralStorage.d.ts +429 -0
- package/build/types/src/abis/RelayParams.d.ts +114 -0
- package/build/types/src/abis/RewardReader.d.ts +60 -0
- package/build/types/src/abis/RewardRouter.d.ts +790 -0
- package/build/types/src/abis/RewardTracker.d.ts +695 -0
- package/build/types/src/abis/SmartAccount.d.ts +20 -0
- package/build/types/src/abis/StBTC.d.ts +932 -0
- package/build/types/src/abis/SubaccountApproval.d.ts +29 -0
- package/build/types/src/abis/SubaccountGelatoRelayRouter.d.ts +1567 -0
- package/build/types/src/abis/SubaccountRouter.d.ts +465 -0
- package/build/types/src/abis/SyntheticsReader.d.ts +3780 -0
- package/build/types/src/abis/SyntheticsRouter.d.ts +54 -0
- package/build/types/src/abis/Timelock.d.ts +1356 -0
- package/build/types/src/abis/Token.d.ts +260 -0
- package/build/types/src/abis/Treasury.d.ts +312 -0
- package/build/types/src/abis/UniPool.d.ts +64 -0
- package/build/types/src/abis/UniswapV2.d.ts +511 -0
- package/build/types/src/abis/UniswapV3Factory.d.ts +154 -0
- package/build/types/src/abis/UniswapV3Pool.d.ts +771 -0
- package/build/types/src/abis/UniswapV3PositionManager.d.ts +767 -0
- package/build/types/src/abis/Vault.d.ts +2482 -0
- package/build/types/src/abis/VaultReader.d.ts +62 -0
- package/build/types/src/abis/VaultV2.d.ts +2327 -0
- package/build/types/src/abis/VaultV2b.d.ts +2482 -0
- package/build/types/src/abis/VenusVToken.d.ts +36 -0
- package/build/types/src/abis/Vester.d.ts +782 -0
- package/build/types/src/abis/WETH.d.ts +240 -0
- package/build/types/src/abis/index.d.ts +43664 -23
- package/build/types/src/configs/batch.d.ts +1 -0
- package/build/types/src/configs/chainIds.d.ts +10 -0
- package/build/types/src/configs/chains.d.ts +171 -33
- package/build/types/src/configs/contracts.d.ts +0 -25
- package/build/types/src/configs/dataStore.d.ts +3 -3
- package/build/types/src/configs/express.d.ts +5 -1
- package/build/types/src/configs/factors.d.ts +1 -2
- package/build/types/src/configs/gasLimits.d.ts +4 -0
- package/build/types/src/configs/markets.d.ts +13 -1
- package/build/types/src/configs/multichain.d.ts +5 -0
- package/build/types/src/configs/oracleKeeper.d.ts +13 -0
- package/build/types/src/configs/tokens.d.ts +4 -0
- package/build/types/src/configs/uniswapV3.d.ts +7 -0
- package/build/types/src/configs/venus.d.ts +16 -0
- package/build/types/src/index.d.ts +3 -3
- package/build/types/src/modules/base.d.ts +2 -2
- package/build/types/src/modules/markets/index.d.ts +3 -0
- package/build/types/src/modules/markets/query-builders.d.ts +2 -2
- package/build/types/src/modules/markets/types.d.ts +2 -2
- package/build/types/src/modules/orders/orders.d.ts +2 -2
- package/build/types/src/modules/orders/transactions/cancelOrdersTxn.d.ts +2 -2
- package/build/types/src/modules/orders/transactions/createDecreaseOrderTxn.d.ts +1 -1
- package/build/types/src/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +1 -1
- package/build/types/src/modules/orders/transactions/updateOrderTxn.d.ts +1 -1
- package/build/types/src/modules/orders/utils.d.ts +2 -2
- package/build/types/src/modules/positions/positions.d.ts +1 -1
- package/build/types/src/modules/utils/utils.d.ts +2 -3
- package/build/types/src/types/chains.d.ts +57 -0
- package/build/types/src/types/markets.d.ts +5 -3
- package/build/types/src/types/orders.d.ts +9 -2
- package/build/types/src/types/positions.d.ts +1 -0
- package/build/types/src/types/subsquid.d.ts +6232 -5089
- package/build/types/src/types/tokens.d.ts +26 -7
- package/build/types/src/types/trade.d.ts +6 -0
- package/build/types/src/types/tradeHistory.d.ts +5 -0
- package/build/types/src/utils/LruCache.d.ts +2 -2
- package/build/types/src/utils/abort.d.ts +1 -0
- package/build/types/src/utils/bigmath.d.ts +1 -0
- package/build/types/src/utils/callContract.d.ts +1 -1
- package/build/types/src/utils/fees/estimateOraclePriceCount.d.ts +2 -2
- package/build/types/src/utils/fees/executionFee.d.ts +6 -6
- package/build/types/src/utils/fees/index.d.ts +2 -1
- package/build/types/src/utils/fees/priceImpact.d.ts +9 -3
- package/build/types/src/utils/hash.d.ts +1 -1
- package/build/types/src/utils/{subgraph.d.ts → indexers.d.ts} +1 -0
- package/build/types/src/utils/marketKeysAndConfigs.d.ts +4 -3
- package/build/types/src/utils/markets.d.ts +5 -2
- package/build/types/src/utils/multicall.d.ts +4 -2
- package/build/types/src/utils/numbers.d.ts +12 -1
- package/build/types/src/utils/orderTransactions.d.ts +7 -7
- package/build/types/src/utils/orders.d.ts +1 -0
- package/build/types/src/utils/prices.d.ts +0 -2
- package/build/types/src/utils/swap/buildSwapStrategy.d.ts +6 -3
- package/build/types/src/utils/swap/swapPath.d.ts +2 -2
- package/build/types/src/utils/swap/swapRouting.d.ts +7 -2
- package/build/types/src/utils/swap/swapStats.d.ts +3 -2
- package/build/types/src/utils/swap/swapValues.d.ts +1 -1
- package/build/types/src/utils/tokens.d.ts +3 -0
- package/build/types/src/utils/trade/decrease.d.ts +1 -0
- package/build/types/src/utils/trade/increase.d.ts +1 -0
- package/build/types/src/utils/tradeHistory.d.ts +1 -2
- package/package.json +13 -3
- package/build/cjs/src/abis/ArbitrumNodeInterface.json +0 -105
- package/build/cjs/src/abis/ClaimHandler.json +0 -424
- package/build/cjs/src/abis/CustomErrors.json +0 -4432
- package/build/cjs/src/abis/DataStore.json +0 -1459
- package/build/cjs/src/abis/ERC20PermitInterface.json +0 -118
- package/build/cjs/src/abis/ERC721.json +0 -442
- package/build/cjs/src/abis/EventEmitter.json +0 -2060
- package/build/cjs/src/abis/ExchangeRouter.json +0 -1706
- package/build/cjs/src/abis/GMT.json +0 -522
- package/build/cjs/src/abis/GelatoRelayRouter.json +0 -1579
- package/build/cjs/src/abis/GlpManager.json +0 -591
- package/build/cjs/src/abis/GlvReader.json +0 -1471
- package/build/cjs/src/abis/GlvRouter.json +0 -764
- package/build/cjs/src/abis/GmxMigrator.json +0 -657
- package/build/cjs/src/abis/GovToken.json +0 -768
- package/build/cjs/src/abis/LayerZeroProvider.json +0 -372
- package/build/cjs/src/abis/MintableBaseToken.json +0 -696
- package/build/cjs/src/abis/Multicall.json +0 -429
- package/build/cjs/src/abis/MultichainClaimsRouter.json +0 -1266
- package/build/cjs/src/abis/MultichainGlvRouter.json +0 -1150
- package/build/cjs/src/abis/MultichainGmRouter.json +0 -1449
- package/build/cjs/src/abis/MultichainOrderRouter.json +0 -1820
- package/build/cjs/src/abis/MultichainSubaccountRouter.json +0 -2069
- package/build/cjs/src/abis/MultichainTransferRouter.json +0 -915
- package/build/cjs/src/abis/MultichainUtils.json +0 -133
- package/build/cjs/src/abis/MultichainVault.json +0 -275
- package/build/cjs/src/abis/OrderBook.json +0 -1997
- package/build/cjs/src/abis/OrderBookReader.json +0 -111
- package/build/cjs/src/abis/OrderExecutor.json +0 -122
- package/build/cjs/src/abis/PositionManager.json +0 -1165
- package/build/cjs/src/abis/PositionRouter.json +0 -2030
- package/build/cjs/src/abis/Reader.json +0 -355
- package/build/cjs/src/abis/ReaderV2.json +0 -630
- package/build/cjs/src/abis/ReferralStorage.json +0 -557
- package/build/cjs/src/abis/RelayParams.json +0 -147
- package/build/cjs/src/abis/RewardReader.json +0 -86
- package/build/cjs/src/abis/RewardRouter.json +0 -1024
- package/build/cjs/src/abis/RewardTracker.json +0 -918
- package/build/cjs/src/abis/Router-v2.json +0 -605
- package/build/cjs/src/abis/Router.json +0 -605
- package/build/cjs/src/abis/SmartAccount.json +0 -28
- package/build/cjs/src/abis/StBTC.json +0 -1225
- package/build/cjs/src/abis/SubaccountApproval.json +0 -17
- package/build/cjs/src/abis/SubaccountGelatoRelayRouter.json +0 -2019
- package/build/cjs/src/abis/SubaccountRouter.json +0 -602
- package/build/cjs/src/abis/SyntheticsReader.json +0 -4905
- package/build/cjs/src/abis/SyntheticsRouter.json +0 -72
- package/build/cjs/src/abis/Timelock.json +0 -1737
- package/build/cjs/src/abis/Token.json +0 -345
- package/build/cjs/src/abis/Treasury.json +0 -411
- package/build/cjs/src/abis/UniPool.json +0 -89
- package/build/cjs/src/abis/UniswapV2.json +0 -1
- package/build/cjs/src/abis/Vault.json +0 -3220
- package/build/cjs/src/abis/VaultReader.json +0 -87
- package/build/cjs/src/abis/VaultV2.json +0 -3019
- package/build/cjs/src/abis/VaultV2b.json +0 -3220
- package/build/cjs/src/abis/Vester.json +0 -1031
- package/build/cjs/src/abis/WETH.json +0 -320
- package/build/cjs/src/abis/YieldFarm.json +0 -599
- package/build/cjs/src/abis/YieldToken.json +0 -560
- package/build/cjs/src/abis/__tests__/abis.spec.js +0 -40
- package/build/cjs/src/configs/__tests__/permits.spec.js +0 -109
- package/build/esm/src/abis/ArbitrumNodeInterface.json +0 -105
- package/build/esm/src/abis/ClaimHandler.json +0 -424
- package/build/esm/src/abis/CustomErrors.json +0 -4432
- package/build/esm/src/abis/DataStore.json +0 -1459
- package/build/esm/src/abis/ERC20PermitInterface.json +0 -118
- package/build/esm/src/abis/ERC721.json +0 -442
- package/build/esm/src/abis/EventEmitter.json +0 -2060
- package/build/esm/src/abis/ExchangeRouter.json +0 -1706
- package/build/esm/src/abis/GMT.json +0 -522
- package/build/esm/src/abis/GelatoRelayRouter.json +0 -1579
- package/build/esm/src/abis/GlpManager.json +0 -591
- package/build/esm/src/abis/GlvReader.json +0 -1471
- package/build/esm/src/abis/GlvRouter.json +0 -764
- package/build/esm/src/abis/GmxMigrator.json +0 -657
- package/build/esm/src/abis/GovToken.json +0 -768
- package/build/esm/src/abis/LayerZeroProvider.json +0 -372
- package/build/esm/src/abis/MintableBaseToken.json +0 -696
- package/build/esm/src/abis/Multicall.json +0 -429
- package/build/esm/src/abis/MultichainClaimsRouter.json +0 -1266
- package/build/esm/src/abis/MultichainGlvRouter.json +0 -1150
- package/build/esm/src/abis/MultichainGmRouter.json +0 -1449
- package/build/esm/src/abis/MultichainOrderRouter.json +0 -1820
- package/build/esm/src/abis/MultichainSubaccountRouter.json +0 -2069
- package/build/esm/src/abis/MultichainTransferRouter.json +0 -915
- package/build/esm/src/abis/MultichainUtils.json +0 -133
- package/build/esm/src/abis/MultichainVault.json +0 -275
- package/build/esm/src/abis/OrderBook.json +0 -1997
- package/build/esm/src/abis/OrderBookReader.json +0 -111
- package/build/esm/src/abis/OrderExecutor.json +0 -122
- package/build/esm/src/abis/PositionManager.json +0 -1165
- package/build/esm/src/abis/PositionRouter.json +0 -2030
- package/build/esm/src/abis/Reader.json +0 -355
- package/build/esm/src/abis/ReaderV2.json +0 -630
- package/build/esm/src/abis/ReferralStorage.json +0 -557
- package/build/esm/src/abis/RelayParams.json +0 -147
- package/build/esm/src/abis/RewardReader.json +0 -86
- package/build/esm/src/abis/RewardRouter.json +0 -1024
- package/build/esm/src/abis/RewardTracker.json +0 -918
- package/build/esm/src/abis/Router-v2.json +0 -605
- package/build/esm/src/abis/Router.json +0 -605
- package/build/esm/src/abis/SmartAccount.json +0 -28
- package/build/esm/src/abis/StBTC.json +0 -1225
- package/build/esm/src/abis/SubaccountApproval.json +0 -17
- package/build/esm/src/abis/SubaccountGelatoRelayRouter.json +0 -2019
- package/build/esm/src/abis/SubaccountRouter.json +0 -602
- package/build/esm/src/abis/SyntheticsReader.json +0 -4905
- package/build/esm/src/abis/SyntheticsRouter.json +0 -72
- package/build/esm/src/abis/Timelock.json +0 -1737
- package/build/esm/src/abis/Token.json +0 -345
- package/build/esm/src/abis/Treasury.json +0 -411
- package/build/esm/src/abis/UniPool.json +0 -89
- package/build/esm/src/abis/UniswapV2.json +0 -1
- package/build/esm/src/abis/Vault.json +0 -3220
- package/build/esm/src/abis/VaultReader.json +0 -87
- package/build/esm/src/abis/VaultV2.json +0 -3019
- package/build/esm/src/abis/VaultV2b.json +0 -3220
- package/build/esm/src/abis/Vester.json +0 -1031
- package/build/esm/src/abis/WETH.json +0 -320
- package/build/esm/src/abis/YieldFarm.json +0 -599
- package/build/esm/src/abis/YieldToken.json +0 -560
- package/build/esm/src/abis/__tests__/abis.spec.js +0 -35
- package/build/esm/src/configs/__tests__/permits.spec.js +0 -107
- /package/build/{types/src/abis/__tests__/abis.spec.d.ts → esm/src/types/chains.js} +0 -0
- /package/build/types/src/{configs/__tests__/permits.spec.d.ts → utils/__tests__/abort.spec.d.ts} +0 -0
- /package/build/types/src/utils/__tests__/{subgraph.spec.d.ts → indexers.spec.d.ts} +0 -0
|
@@ -1 +1,6 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var TokenBalanceType;
|
|
2
|
+
(function (TokenBalanceType) {
|
|
3
|
+
TokenBalanceType[TokenBalanceType["Wallet"] = 0] = "Wallet";
|
|
4
|
+
TokenBalanceType[TokenBalanceType["GmxAccount"] = 1] = "GmxAccount";
|
|
5
|
+
TokenBalanceType[TokenBalanceType["SourceChain"] = 2] = "SourceChain";
|
|
6
|
+
})(TokenBalanceType || (TokenBalanceType = {}));
|
|
@@ -6,3 +6,9 @@ export var TradeActionType;
|
|
|
6
6
|
TradeActionType["OrderUpdated"] = "OrderUpdated";
|
|
7
7
|
TradeActionType["OrderFrozen"] = "OrderFrozen";
|
|
8
8
|
})(TradeActionType || (TradeActionType = {}));
|
|
9
|
+
export function isPositionTradeAction(tradeAction) {
|
|
10
|
+
return tradeAction.type === "position";
|
|
11
|
+
}
|
|
12
|
+
export function isSwapTradeAction(tradeAction) {
|
|
13
|
+
return tradeAction.type === "swap";
|
|
14
|
+
}
|
|
@@ -2,16 +2,17 @@ export class LRUCache {
|
|
|
2
2
|
constructor(capacity) {
|
|
3
3
|
this.capacity = capacity;
|
|
4
4
|
this.cache = new Map();
|
|
5
|
-
this.recentKeys = [];
|
|
6
5
|
}
|
|
7
6
|
has(key) {
|
|
8
7
|
return this.cache.has(key);
|
|
9
8
|
}
|
|
10
9
|
get(key) {
|
|
11
10
|
if (this.cache.has(key)) {
|
|
12
|
-
//
|
|
13
|
-
this.
|
|
14
|
-
|
|
11
|
+
// Move to end (most recently used) by deleting and re-inserting
|
|
12
|
+
const value = this.cache.get(key);
|
|
13
|
+
this.cache.delete(key);
|
|
14
|
+
this.cache.set(key, value);
|
|
15
|
+
return value;
|
|
15
16
|
}
|
|
16
17
|
return undefined;
|
|
17
18
|
}
|
|
@@ -19,31 +20,34 @@ export class LRUCache {
|
|
|
19
20
|
if (typeof key !== "string") {
|
|
20
21
|
throw new Error("Key must be a string");
|
|
21
22
|
}
|
|
22
|
-
// If key exists, update its value and move it to the front of recentKeys
|
|
23
23
|
if (this.cache.has(key)) {
|
|
24
|
+
// Update existing key: delete and re-insert to move to end (most recently used)
|
|
25
|
+
this.cache.delete(key);
|
|
24
26
|
this.cache.set(key, value);
|
|
25
|
-
this.updateRecentKeys(key);
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
|
-
// If capacity is
|
|
29
|
+
// If capacity is 0, don't store anything
|
|
30
|
+
if (this.capacity === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// If capacity is reached, remove least recently used (first entry)
|
|
29
34
|
if (this.cache.size === this.capacity) {
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
this.cache.delete(
|
|
35
|
+
const firstKey = this.cache.keys().next().value;
|
|
36
|
+
if (firstKey !== undefined) {
|
|
37
|
+
this.cache.delete(firstKey);
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
|
-
// Add the new key-value pair
|
|
40
|
+
// Add the new key-value pair (inserted at end = most recently used)
|
|
36
41
|
this.cache.set(key, value);
|
|
37
|
-
this.recentKeys.push(key);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
delete(key) {
|
|
41
45
|
this.cache.delete(key);
|
|
42
|
-
this.recentKeys = this.recentKeys.filter((k) => k !== key);
|
|
43
46
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
getKeys() {
|
|
48
|
+
return Array.from(this.cache.keys());
|
|
49
|
+
}
|
|
50
|
+
clean() {
|
|
51
|
+
this.cache.clear();
|
|
48
52
|
}
|
|
49
53
|
}
|
|
@@ -58,4 +58,15 @@ describe("LruCache", () => {
|
|
|
58
58
|
expect(cache.has("a")).toBe(true);
|
|
59
59
|
expect(cache.get("a")).toBe(1);
|
|
60
60
|
});
|
|
61
|
+
it("should clear all entries when clean is called", () => {
|
|
62
|
+
const cache = new LRUCache(2);
|
|
63
|
+
cache.set("a", 1);
|
|
64
|
+
cache.set("b", 2);
|
|
65
|
+
expect(cache.has("a")).toBe(true);
|
|
66
|
+
expect(cache.has("b")).toBe(true);
|
|
67
|
+
cache.clean();
|
|
68
|
+
expect(cache.has("a")).toBe(false);
|
|
69
|
+
expect(cache.has("b")).toBe(false);
|
|
70
|
+
expect(cache.getKeys().length).toBe(0);
|
|
71
|
+
});
|
|
61
72
|
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { combineAbortSignals } from "../abort";
|
|
3
|
+
describe("combineAbortSignals", () => {
|
|
4
|
+
it("should return an AbortController", () => {
|
|
5
|
+
const controller1 = new AbortController();
|
|
6
|
+
const controller2 = new AbortController();
|
|
7
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal);
|
|
8
|
+
expect(combined).toBeInstanceOf(AbortController);
|
|
9
|
+
expect(combined.signal.aborted).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
it("should abort combined controller when first signal is aborted", () => {
|
|
12
|
+
const controller1 = new AbortController();
|
|
13
|
+
const controller2 = new AbortController();
|
|
14
|
+
controller1.abort();
|
|
15
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal);
|
|
16
|
+
expect(combined.signal.aborted).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
it("should abort combined controller when second signal is aborted", () => {
|
|
19
|
+
const controller1 = new AbortController();
|
|
20
|
+
const controller2 = new AbortController();
|
|
21
|
+
controller2.abort();
|
|
22
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal);
|
|
23
|
+
expect(combined.signal.aborted).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
it("should abort combined controller when any signal is aborted after creation", () => {
|
|
26
|
+
const controller1 = new AbortController();
|
|
27
|
+
const controller2 = new AbortController();
|
|
28
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal);
|
|
29
|
+
expect(combined.signal.aborted).toBe(false);
|
|
30
|
+
controller1.abort();
|
|
31
|
+
expect(combined.signal.aborted).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
it("should abort combined controller when multiple signals are aborted", () => {
|
|
34
|
+
const controller1 = new AbortController();
|
|
35
|
+
const controller2 = new AbortController();
|
|
36
|
+
const controller3 = new AbortController();
|
|
37
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal, controller3.signal);
|
|
38
|
+
expect(combined.signal.aborted).toBe(false);
|
|
39
|
+
controller2.abort();
|
|
40
|
+
expect(combined.signal.aborted).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
it("should clean up event listeners when combined controller is aborted", () => {
|
|
43
|
+
const controller1 = new AbortController();
|
|
44
|
+
const controller2 = new AbortController();
|
|
45
|
+
const removeEventListener1 = vi.spyOn(controller1.signal, "removeEventListener");
|
|
46
|
+
const removeEventListener2 = vi.spyOn(controller2.signal, "removeEventListener");
|
|
47
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal);
|
|
48
|
+
combined.abort();
|
|
49
|
+
expect(removeEventListener1).toHaveBeenCalled();
|
|
50
|
+
expect(removeEventListener2).toHaveBeenCalled();
|
|
51
|
+
});
|
|
52
|
+
it("should clean up event listeners when source signal is aborted", () => {
|
|
53
|
+
const controller1 = new AbortController();
|
|
54
|
+
const controller2 = new AbortController();
|
|
55
|
+
const removeEventListener1 = vi.spyOn(controller1.signal, "removeEventListener");
|
|
56
|
+
const removeEventListener2 = vi.spyOn(controller2.signal, "removeEventListener");
|
|
57
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal);
|
|
58
|
+
controller1.abort();
|
|
59
|
+
expect(combined.signal.aborted).toBe(true);
|
|
60
|
+
expect(removeEventListener1).toHaveBeenCalled();
|
|
61
|
+
expect(removeEventListener2).toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
it("should work with single signal", () => {
|
|
64
|
+
const controller = new AbortController();
|
|
65
|
+
const combined = combineAbortSignals(controller.signal);
|
|
66
|
+
expect(combined.signal.aborted).toBe(false);
|
|
67
|
+
controller.abort();
|
|
68
|
+
expect(combined.signal.aborted).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
it("should work with empty array", () => {
|
|
71
|
+
const combined = combineAbortSignals();
|
|
72
|
+
expect(combined).toBeInstanceOf(AbortController);
|
|
73
|
+
expect(combined.signal.aborted).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
it("should handle multiple aborts gracefully", () => {
|
|
76
|
+
const controller1 = new AbortController();
|
|
77
|
+
const controller2 = new AbortController();
|
|
78
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal);
|
|
79
|
+
controller1.abort();
|
|
80
|
+
controller2.abort();
|
|
81
|
+
expect(combined.signal.aborted).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
it("should not leak memory when signals are aborted multiple times", () => {
|
|
84
|
+
const controller1 = new AbortController();
|
|
85
|
+
const controller2 = new AbortController();
|
|
86
|
+
const removeEventListener1 = vi.spyOn(controller1.signal, "removeEventListener");
|
|
87
|
+
const removeEventListener2 = vi.spyOn(controller2.signal, "removeEventListener");
|
|
88
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal);
|
|
89
|
+
controller1.abort();
|
|
90
|
+
controller2.abort();
|
|
91
|
+
combined.abort();
|
|
92
|
+
const callCount1 = removeEventListener1.mock.calls.length;
|
|
93
|
+
const callCount2 = removeEventListener2.mock.calls.length;
|
|
94
|
+
expect(callCount1).toBeGreaterThan(0);
|
|
95
|
+
expect(callCount2).toBeGreaterThan(0);
|
|
96
|
+
});
|
|
97
|
+
it("should clean up listeners when later signal is already aborted", () => {
|
|
98
|
+
const controller1 = new AbortController();
|
|
99
|
+
const controller2 = new AbortController();
|
|
100
|
+
controller2.abort();
|
|
101
|
+
const removeEventListener1 = vi.spyOn(controller1.signal, "removeEventListener");
|
|
102
|
+
const addEventListener1 = vi.spyOn(controller1.signal, "addEventListener");
|
|
103
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal);
|
|
104
|
+
expect(combined.signal.aborted).toBe(true);
|
|
105
|
+
expect(addEventListener1).toHaveBeenCalled();
|
|
106
|
+
expect(removeEventListener1).toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
it("should clean up listeners when middle signal is already aborted", () => {
|
|
109
|
+
const controller1 = new AbortController();
|
|
110
|
+
const controller2 = new AbortController();
|
|
111
|
+
const controller3 = new AbortController();
|
|
112
|
+
controller2.abort();
|
|
113
|
+
const removeEventListener1 = vi.spyOn(controller1.signal, "removeEventListener");
|
|
114
|
+
const addEventListener1 = vi.spyOn(controller1.signal, "addEventListener");
|
|
115
|
+
const combined = combineAbortSignals(controller1.signal, controller2.signal, controller3.signal);
|
|
116
|
+
expect(combined.signal.aborted).toBe(true);
|
|
117
|
+
expect(addEventListener1).toHaveBeenCalled();
|
|
118
|
+
expect(removeEventListener1).toHaveBeenCalled();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -31,9 +31,9 @@ describe("getFundingFactorPerPeriod", () => {
|
|
|
31
31
|
shortInterestUsd: eightMillion * dollar,
|
|
32
32
|
};
|
|
33
33
|
const forLongs = getFundingFactorPerPeriod(marketInfo, true, second);
|
|
34
|
-
expect(forLongs.toString()).toBe(toFactor("
|
|
34
|
+
expect(forLongs.toString()).toBe(toFactor("40%").toString());
|
|
35
35
|
const forShorts = getFundingFactorPerPeriod(marketInfo, false, second);
|
|
36
|
-
expect(forShorts.toString()).toBe(toFactor("-
|
|
36
|
+
expect(forShorts.toString()).toBe(toFactor("-50%").toString());
|
|
37
37
|
});
|
|
38
38
|
it("works when long pay, shorts OI bigger", () => {
|
|
39
39
|
const marketInfo = {
|
|
@@ -43,9 +43,9 @@ describe("getFundingFactorPerPeriod", () => {
|
|
|
43
43
|
shortInterestUsd: tenMillion * dollar,
|
|
44
44
|
};
|
|
45
45
|
const forLongs = getFundingFactorPerPeriod(marketInfo, true, second);
|
|
46
|
-
expect(forLongs.toString()).toBe(toFactor("-
|
|
46
|
+
expect(forLongs.toString()).toBe(toFactor("-50%").toString());
|
|
47
47
|
const forShorts = getFundingFactorPerPeriod(marketInfo, false, second);
|
|
48
|
-
expect(forShorts.toString()).toBe(toFactor("
|
|
48
|
+
expect(forShorts.toString()).toBe(toFactor("40%").toString());
|
|
49
49
|
});
|
|
50
50
|
it("works when long pay, longs OI bigger", () => {
|
|
51
51
|
const marketInfo = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { BASIS_POINTS_DIVISOR_BIGINT, USD_DECIMALS } from "../../configs/factors";
|
|
3
3
|
const ONE_USD = 1000000000000000000000000000000n;
|
|
4
|
-
import { applyFactor, basisPointsToFloat, bigintToNumber, BN_NEGATIVE_ONE, BN_ONE, BN_ZERO, expandDecimals, formatAmount, formatAmountHuman, formatBalanceAmount, formatFactor, formatPercentage, formatUsdPrice, getBasisPoints, numberToBigint, PERCENT_PRECISION_DECIMALS, PRECISION, PRECISION_DECIMALS, roundWithDecimals, roundUpMagnitudeDivision, toBigNumberWithDecimals, } from "../numbers";
|
|
4
|
+
import { applyFactor, basisPointsToFloat, bigintToNumber, BN_NEGATIVE_ONE, BN_ONE, BN_ZERO, expandDecimals, formatAmount, formatAmountHuman, formatBalanceAmount, formatFactor, formatPercentage, formatTokenAmount, formatUsdPrice, getBasisPoints, numberToBigint, PERCENT_PRECISION_DECIMALS, PRECISION, PRECISION_DECIMALS, roundWithDecimals, roundUpMagnitudeDivision, toBigNumberWithDecimals, } from "../numbers";
|
|
5
5
|
describe("numbers utils", () => {
|
|
6
6
|
it("constants", () => {
|
|
7
7
|
// Just to confirm they exist and have no unexpected changes
|
|
@@ -203,7 +203,7 @@ describe("formatUsdPrice", () => {
|
|
|
203
203
|
expect(formatUsdPrice(ONE_USD / 10000n)).toBe("$\u200a0.0001000");
|
|
204
204
|
expect(formatUsdPrice(ONE_USD / 100000n)).toBe("$\u200a0.00001000");
|
|
205
205
|
expect(formatUsdPrice(ONE_USD / 1000000000n)).toBe("$\u200a0.000000001");
|
|
206
|
-
expect(formatUsdPrice(ONE_USD / 10000000000n)).toBe("
|
|
206
|
+
expect(formatUsdPrice(ONE_USD / 10000000000n)).toBe("<\u00a0$\u200a0.000000001");
|
|
207
207
|
});
|
|
208
208
|
});
|
|
209
209
|
describe("formatAmountHuman", () => {
|
|
@@ -229,38 +229,39 @@ describe("formatAmountHuman", () => {
|
|
|
229
229
|
});
|
|
230
230
|
});
|
|
231
231
|
describe("formatBalanceAmount", () => {
|
|
232
|
+
const NBSP = "\u00a0";
|
|
232
233
|
it("should display balance amount", () => {
|
|
233
|
-
expect(formatBalanceAmount(ONE_USD * 1000n, USD_DECIMALS)).toBe("1,000.
|
|
234
|
+
expect(formatBalanceAmount(ONE_USD * 1000n, USD_DECIMALS)).toBe("1,000.00");
|
|
234
235
|
expect(formatBalanceAmount(0n, USD_DECIMALS)).toBe("-");
|
|
235
236
|
expect(formatBalanceAmount(0n, USD_DECIMALS, undefined, { showZero: true })).toBe("0.0000");
|
|
236
237
|
expect(formatBalanceAmount(ONE_USD * 1n, USD_DECIMALS)).toBe("1.0000");
|
|
237
238
|
expect(formatBalanceAmount(ONE_USD / 10n, USD_DECIMALS)).toBe("0.10000");
|
|
238
239
|
expect(formatBalanceAmount(ONE_USD / 100n, USD_DECIMALS)).toBe("0.010000");
|
|
239
240
|
expect(formatBalanceAmount(ONE_USD / 1000n, USD_DECIMALS)).toBe("0.0010000");
|
|
240
|
-
expect(formatBalanceAmount(ONE_USD / 10000n, USD_DECIMALS)).toBe("0.
|
|
241
|
+
expect(formatBalanceAmount(ONE_USD / 10000n, USD_DECIMALS)).toBe("0.0001000");
|
|
241
242
|
expect(formatBalanceAmount(ONE_USD / 100000n, USD_DECIMALS)).toBe("0.00001000");
|
|
242
|
-
expect(formatBalanceAmount(ONE_USD / 1000000n, USD_DECIMALS)).toBe("0.
|
|
243
|
-
expect(formatBalanceAmount(ONE_USD / 10000000n, USD_DECIMALS)).toBe("0.
|
|
244
|
-
expect(formatBalanceAmount(ONE_USD / 100000000n, USD_DECIMALS)).toBe("0.
|
|
243
|
+
expect(formatBalanceAmount(ONE_USD / 1000000n, USD_DECIMALS)).toBe("0.000001000");
|
|
244
|
+
expect(formatBalanceAmount(ONE_USD / 10000000n, USD_DECIMALS)).toBe("0.000000100");
|
|
245
|
+
expect(formatBalanceAmount(ONE_USD / 100000000n, USD_DECIMALS)).toBe("0.000000010");
|
|
245
246
|
expect(formatBalanceAmount(ONE_USD / 1000000000n, USD_DECIMALS)).toBe("1.00e-9");
|
|
246
247
|
expect(formatBalanceAmount(ONE_USD / 1000000000000n, USD_DECIMALS)).toBe("1.00e-12");
|
|
247
248
|
expect(formatBalanceAmount(ONE_USD * -1n, USD_DECIMALS)).toBe("-1.0000");
|
|
248
249
|
});
|
|
249
250
|
it("should display balance amount with symbol", () => {
|
|
250
|
-
expect(formatBalanceAmount(ONE_USD, USD_DECIMALS, "USDC")).toBe(
|
|
251
|
-
expect(formatBalanceAmount(0n, USD_DECIMALS, "USDC", { showZero: true })).toBe(
|
|
251
|
+
expect(formatBalanceAmount(ONE_USD, USD_DECIMALS, "USDC")).toBe(`1.0000${NBSP}USDC`);
|
|
252
|
+
expect(formatBalanceAmount(0n, USD_DECIMALS, "USDC", { showZero: true })).toBe(`0.0000${NBSP}USDC`);
|
|
252
253
|
expect(formatBalanceAmount(0n, USD_DECIMALS, "USDC", { showZero: false })).toBe("-");
|
|
253
254
|
});
|
|
254
255
|
it("should display balance of stable token correctly", () => {
|
|
255
256
|
expect(formatBalanceAmount(ONE_USD, USD_DECIMALS, undefined, { isStable: true })).toBe("1.00");
|
|
256
|
-
expect(formatBalanceAmount(ONE_USD / 10n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.
|
|
257
|
-
expect(formatBalanceAmount(ONE_USD / 100n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.
|
|
258
|
-
expect(formatBalanceAmount(ONE_USD / 1000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.
|
|
259
|
-
expect(formatBalanceAmount(ONE_USD / 10000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.
|
|
260
|
-
expect(formatBalanceAmount(ONE_USD / 100000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.
|
|
261
|
-
expect(formatBalanceAmount(ONE_USD / 1000000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.
|
|
257
|
+
expect(formatBalanceAmount(ONE_USD / 10n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.10");
|
|
258
|
+
expect(formatBalanceAmount(ONE_USD / 100n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.010");
|
|
259
|
+
expect(formatBalanceAmount(ONE_USD / 1000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.0010");
|
|
260
|
+
expect(formatBalanceAmount(ONE_USD / 10000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.00010");
|
|
261
|
+
expect(formatBalanceAmount(ONE_USD / 100000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.000010");
|
|
262
|
+
expect(formatBalanceAmount(ONE_USD / 1000000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.0000010");
|
|
262
263
|
expect(formatBalanceAmount(ONE_USD / 10000000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.00000010");
|
|
263
|
-
expect(formatBalanceAmount(ONE_USD / 100000000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.
|
|
264
|
+
expect(formatBalanceAmount(ONE_USD / 100000000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.000000010");
|
|
264
265
|
expect(formatBalanceAmount(ONE_USD / 1000000000n, USD_DECIMALS, undefined, { isStable: true })).toBe("1.00e-9");
|
|
265
266
|
expect(formatBalanceAmount(0n, USD_DECIMALS, undefined, { isStable: true, showZero: true })).toBe("0.00");
|
|
266
267
|
expect(formatBalanceAmount(ONE_USD, USD_DECIMALS, undefined, { isStable: true, signed: true })).toBe("+1.00");
|
|
@@ -306,3 +307,82 @@ describe("formatPercentage", () => {
|
|
|
306
307
|
expect(formatPercentage(toBigNumberWithDecimals("0.999", PERCENT_PRECISION_DECIMALS), { bps: false, displayDecimals: 5 })).toBe("0.99900%");
|
|
307
308
|
});
|
|
308
309
|
});
|
|
310
|
+
describe("formatTokenAmount", () => {
|
|
311
|
+
const TOKEN_DECIMALS = 18;
|
|
312
|
+
const ONE_TOKEN = expandDecimals(1, TOKEN_DECIMALS);
|
|
313
|
+
const NBSP = "\u00a0";
|
|
314
|
+
it("should return undefined for undefined amount without fallbackToZero", () => {
|
|
315
|
+
expect(formatTokenAmount(undefined, TOKEN_DECIMALS)).toBeUndefined();
|
|
316
|
+
expect(formatTokenAmount(undefined, TOKEN_DECIMALS, "ETH")).toBeUndefined();
|
|
317
|
+
});
|
|
318
|
+
it("should return zero with fallbackToZero", () => {
|
|
319
|
+
expect(formatTokenAmount(undefined, TOKEN_DECIMALS, undefined, { fallbackToZero: true })).toBe("0.0000");
|
|
320
|
+
expect(formatTokenAmount(undefined, TOKEN_DECIMALS, "ETH", { fallbackToZero: true })).toBe(`0.0000${NBSP}ETH`);
|
|
321
|
+
});
|
|
322
|
+
it("should format token amount with symbol", () => {
|
|
323
|
+
expect(formatTokenAmount(ONE_TOKEN, TOKEN_DECIMALS, "ETH")).toBe(`1.0000${NBSP}ETH`);
|
|
324
|
+
expect(formatTokenAmount(ONE_TOKEN * 100n, TOKEN_DECIMALS, "ETH")).toBe(`100.000${NBSP}ETH`);
|
|
325
|
+
});
|
|
326
|
+
it("should format token amount without symbol", () => {
|
|
327
|
+
expect(formatTokenAmount(ONE_TOKEN, TOKEN_DECIMALS)).toBe("1.0000");
|
|
328
|
+
expect(formatTokenAmount(ONE_TOKEN * 1000n, TOKEN_DECIMALS)).toBe("1000.00");
|
|
329
|
+
});
|
|
330
|
+
it("should adjust decimals based on amount magnitude (non-stable)", () => {
|
|
331
|
+
expect(formatTokenAmount(ONE_TOKEN * 1000n, TOKEN_DECIMALS)).toBe("1000.00");
|
|
332
|
+
expect(formatTokenAmount(ONE_TOKEN * 100n, TOKEN_DECIMALS)).toBe("100.000");
|
|
333
|
+
expect(formatTokenAmount(ONE_TOKEN * 10n, TOKEN_DECIMALS)).toBe("10.0000");
|
|
334
|
+
expect(formatTokenAmount(ONE_TOKEN, TOKEN_DECIMALS)).toBe("1.0000");
|
|
335
|
+
expect(formatTokenAmount(ONE_TOKEN / 10n, TOKEN_DECIMALS)).toBe("0.10000");
|
|
336
|
+
expect(formatTokenAmount(ONE_TOKEN / 100n, TOKEN_DECIMALS)).toBe("0.010000");
|
|
337
|
+
expect(formatTokenAmount(ONE_TOKEN / 1000n, TOKEN_DECIMALS)).toBe("0.0010000");
|
|
338
|
+
expect(formatTokenAmount(ONE_TOKEN / 10000n, TOKEN_DECIMALS)).toBe("0.0001000");
|
|
339
|
+
});
|
|
340
|
+
it("should adjust decimals based on amount magnitude (stable)", () => {
|
|
341
|
+
expect(formatTokenAmount(ONE_TOKEN * 1000n, TOKEN_DECIMALS, undefined, { isStable: true })).toBe("1000.00");
|
|
342
|
+
expect(formatTokenAmount(ONE_TOKEN * 100n, TOKEN_DECIMALS, undefined, { isStable: true })).toBe("100.00");
|
|
343
|
+
expect(formatTokenAmount(ONE_TOKEN * 10n, TOKEN_DECIMALS, undefined, { isStable: true })).toBe("10.00");
|
|
344
|
+
expect(formatTokenAmount(ONE_TOKEN, TOKEN_DECIMALS, undefined, { isStable: true })).toBe("1.00");
|
|
345
|
+
expect(formatTokenAmount(ONE_TOKEN / 10n, TOKEN_DECIMALS, undefined, { isStable: true })).toBe("0.10");
|
|
346
|
+
expect(formatTokenAmount(ONE_TOKEN / 100n, TOKEN_DECIMALS, undefined, { isStable: true })).toBe("0.010");
|
|
347
|
+
expect(formatTokenAmount(ONE_TOKEN / 1000n, TOKEN_DECIMALS, undefined, { isStable: true })).toBe("0.0010");
|
|
348
|
+
expect(formatTokenAmount(ONE_TOKEN / 10000n, TOKEN_DECIMALS, undefined, { isStable: true })).toBe("0.00010");
|
|
349
|
+
});
|
|
350
|
+
it("should respect explicit displayDecimals override", () => {
|
|
351
|
+
expect(formatTokenAmount(ONE_TOKEN, TOKEN_DECIMALS, undefined, { displayDecimals: 2 })).toBe("1.00");
|
|
352
|
+
expect(formatTokenAmount(ONE_TOKEN, TOKEN_DECIMALS, undefined, { displayDecimals: 6 })).toBe("1.000000");
|
|
353
|
+
expect(formatTokenAmount(ONE_TOKEN / 10n, TOKEN_DECIMALS, undefined, { displayDecimals: 2 })).toBe("0.10");
|
|
354
|
+
});
|
|
355
|
+
it("should format with commas when useCommas is true", () => {
|
|
356
|
+
expect(formatTokenAmount(ONE_TOKEN * 1000000n, TOKEN_DECIMALS, undefined, { useCommas: true })).toBe("1,000,000.00");
|
|
357
|
+
expect(formatTokenAmount(ONE_TOKEN * 123456n, TOKEN_DECIMALS, "ETH", { useCommas: true })).toBe(`123,456.00${NBSP}ETH`);
|
|
358
|
+
});
|
|
359
|
+
it("should show all significant digits with showAllSignificant", () => {
|
|
360
|
+
const preciseAmount = ONE_TOKEN + ONE_TOKEN / 123456789n;
|
|
361
|
+
expect(formatTokenAmount(preciseAmount, TOKEN_DECIMALS, undefined, { showAllSignificant: true })).not.toContain("...");
|
|
362
|
+
});
|
|
363
|
+
it("should display plus sign for positive values with displayPlus", () => {
|
|
364
|
+
expect(formatTokenAmount(ONE_TOKEN, TOKEN_DECIMALS, undefined, { displayPlus: true })).toBe("+1.0000");
|
|
365
|
+
expect(formatTokenAmount(-ONE_TOKEN, TOKEN_DECIMALS, undefined, { displayPlus: true })).toBe("-1.0000");
|
|
366
|
+
});
|
|
367
|
+
it("should handle negative amounts", () => {
|
|
368
|
+
expect(formatTokenAmount(-ONE_TOKEN, TOKEN_DECIMALS)).toBe("-1.0000");
|
|
369
|
+
expect(formatTokenAmount(-ONE_TOKEN * 100n, TOKEN_DECIMALS, "ETH")).toBe(`-100.000${NBSP}ETH`);
|
|
370
|
+
});
|
|
371
|
+
it("should handle zero amount", () => {
|
|
372
|
+
expect(formatTokenAmount(0n, TOKEN_DECIMALS)).toBe("0.00");
|
|
373
|
+
expect(formatTokenAmount(0n, TOKEN_DECIMALS, "ETH")).toBe(`0.00${NBSP}ETH`);
|
|
374
|
+
expect(formatTokenAmount(0n, TOKEN_DECIMALS, undefined, { isStable: true })).toBe("0.00");
|
|
375
|
+
});
|
|
376
|
+
it("should handle maxThreshold", () => {
|
|
377
|
+
const result = formatTokenAmount(ONE_TOKEN * 10000000000n, TOKEN_DECIMALS, undefined, {
|
|
378
|
+
maxThreshold: "1000000000",
|
|
379
|
+
});
|
|
380
|
+
expect(result).toContain(">");
|
|
381
|
+
});
|
|
382
|
+
it("should handle minThreshold", () => {
|
|
383
|
+
const result = formatTokenAmount(ONE_TOKEN / 1000000000n, TOKEN_DECIMALS, undefined, {
|
|
384
|
+
minThreshold: "0.00000001",
|
|
385
|
+
});
|
|
386
|
+
expect(result).toContain("<");
|
|
387
|
+
});
|
|
388
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function combineAbortSignals(...signals) {
|
|
2
|
+
const controller = new AbortController();
|
|
3
|
+
const abortHandler = () => {
|
|
4
|
+
for (const signal of signals) {
|
|
5
|
+
signal.removeEventListener("abort", abortHandler);
|
|
6
|
+
}
|
|
7
|
+
controller.abort();
|
|
8
|
+
};
|
|
9
|
+
const signalsWithListeners = [];
|
|
10
|
+
for (const signal of signals) {
|
|
11
|
+
if (signal.aborted) {
|
|
12
|
+
for (const signalWithListener of signalsWithListeners) {
|
|
13
|
+
signalWithListener.removeEventListener("abort", abortHandler);
|
|
14
|
+
}
|
|
15
|
+
controller.abort();
|
|
16
|
+
return controller;
|
|
17
|
+
}
|
|
18
|
+
signal.addEventListener("abort", abortHandler);
|
|
19
|
+
signalsWithListeners.push(signal);
|
|
20
|
+
}
|
|
21
|
+
controller.signal.addEventListener("abort", () => {
|
|
22
|
+
for (const signal of signals) {
|
|
23
|
+
signal.removeEventListener("abort", abortHandler);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return controller;
|
|
27
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { encodeFunctionData, withRetry } from "viem";
|
|
2
|
-
import {
|
|
2
|
+
import { getGasPriceBuffer, getGasPricePremium, getMaxFeePerGas, getMaxPriorityFeePerGas, getViemChain, } from "../configs/chains";
|
|
3
3
|
import { BASIS_POINTS_DIVISOR_BIGINT } from "../configs/factors";
|
|
4
4
|
import { bigMath } from "./bigmath";
|
|
5
5
|
export async function getGasPrice(client, chainId) {
|
|
6
|
-
let maxFeePerGas =
|
|
7
|
-
const premium =
|
|
6
|
+
let maxFeePerGas = getMaxFeePerGas(chainId);
|
|
7
|
+
const premium = getGasPricePremium(chainId) || 0n;
|
|
8
8
|
const feeData = await withRetry(() => client.estimateFeesPerGas({
|
|
9
9
|
type: "legacy",
|
|
10
10
|
chain: getViemChain(chainId),
|
|
@@ -25,7 +25,7 @@ export async function getGasPrice(client, chainId) {
|
|
|
25
25
|
const block = await client.getBlock({ blockTag: "pending" });
|
|
26
26
|
if (block.baseFeePerGas !== undefined && block.baseFeePerGas !== null) {
|
|
27
27
|
const baseFeePerGas = block.baseFeePerGas;
|
|
28
|
-
const maxPriorityFeePerGas = bigMath.max(
|
|
28
|
+
const maxPriorityFeePerGas = bigMath.max(getMaxPriorityFeePerGas(chainId) || 0n, premium);
|
|
29
29
|
// Calculate maxFeePerGas
|
|
30
30
|
const calculatedMaxFeePerGas = baseFeePerGas + maxPriorityFeePerGas + premium;
|
|
31
31
|
return {
|
|
@@ -37,7 +37,7 @@ export async function getGasPrice(client, chainId) {
|
|
|
37
37
|
if (gasPrice === null || gasPrice === undefined) {
|
|
38
38
|
throw new Error("Can't fetch gas price");
|
|
39
39
|
}
|
|
40
|
-
const bufferBps =
|
|
40
|
+
const bufferBps = getGasPriceBuffer(chainId) || 0n;
|
|
41
41
|
const buffer = bigMath.mulDiv(gasPrice, bufferBps, BASIS_POINTS_DIVISOR_BIGINT);
|
|
42
42
|
return {
|
|
43
43
|
gasPrice: gasPrice + buffer + premium,
|
|
@@ -12,6 +12,7 @@ const TX_ERROR_PATTERNS = {
|
|
|
12
12
|
{ msg: "insufficient funds for gas" },
|
|
13
13
|
{ msg: "not enough funds for gas" },
|
|
14
14
|
{ msg: "failed to execute call with revert code InsufficientGasFunds" },
|
|
15
|
+
{ msg: "insufficient funds for transfer" },
|
|
15
16
|
],
|
|
16
17
|
[TxErrorType.UserDenied]: [
|
|
17
18
|
{ msg: "User denied transaction signature" },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getExcessiveExecutionFee, getHighExecutionFee,
|
|
1
|
+
import { getExcessiveExecutionFee, getHighExecutionFee, getMinExecutionFeeUsd } from "../../configs/chains";
|
|
2
2
|
import { USD_DECIMALS } from "../../configs/factors";
|
|
3
3
|
import { NATIVE_TOKEN_ADDRESS } from "../../configs/tokens";
|
|
4
4
|
import { DecreasePositionSwapType } from "../../types/orders";
|
|
@@ -18,7 +18,7 @@ tokensData, estimatedGasLimit, gasPrice, oraclePriceCount, numberOfParts) {
|
|
|
18
18
|
const gasLimit = baseGasLimit + applyFactor(estimatedGasLimit, multiplierFactor);
|
|
19
19
|
// #endregion
|
|
20
20
|
// avoid botanix gas spikes when chain is not actively used
|
|
21
|
-
const minGasCostUsd =
|
|
21
|
+
const minGasCostUsd = getMinExecutionFeeUsd(chainId);
|
|
22
22
|
const minGasCost = convertToTokenAmount(minGasCostUsd, nativeToken.decimals, nativeToken.prices.minPrice);
|
|
23
23
|
let feeTokenAmountPerExecution = gasLimit * gasPrice;
|
|
24
24
|
if (minGasCost) {
|
|
@@ -117,11 +117,11 @@ export function estimateExecuteSwapOrderGasLimit(gasLimits, order) {
|
|
|
117
117
|
*/
|
|
118
118
|
export function estimateExecuteDepositGasLimit(gasLimits, deposit) {
|
|
119
119
|
const gasPerSwap = gasLimits.singleSwap;
|
|
120
|
-
const swapsCount = BigInt(
|
|
120
|
+
const swapsCount = BigInt(deposit.swapsCount ?? 0);
|
|
121
121
|
const gasForSwaps = swapsCount * gasPerSwap;
|
|
122
122
|
return gasLimits.depositToken + (deposit.callbackGasLimit ?? 0n) + gasForSwaps;
|
|
123
123
|
}
|
|
124
|
-
export function estimateExecuteGlvDepositGasLimit(gasLimits, { marketsCount, isMarketTokenDeposit, }) {
|
|
124
|
+
export function estimateExecuteGlvDepositGasLimit(gasLimits, { marketsCount, isMarketTokenDeposit, swapsCount, }) {
|
|
125
125
|
const gasPerGlvPerMarket = gasLimits.glvPerMarketGasLimit;
|
|
126
126
|
const gasForGlvMarkets = gasPerGlvPerMarket * marketsCount;
|
|
127
127
|
const glvDepositGasLimit = gasLimits.glvDepositGasLimit;
|
|
@@ -129,14 +129,18 @@ export function estimateExecuteGlvDepositGasLimit(gasLimits, { marketsCount, isM
|
|
|
129
129
|
if (isMarketTokenDeposit) {
|
|
130
130
|
return gasLimit;
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
const gasPerSwap = gasLimits.singleSwap;
|
|
133
|
+
const gasForSwaps = swapsCount * gasPerSwap;
|
|
134
|
+
return gasLimit + gasLimits.depositToken + gasForSwaps;
|
|
133
135
|
}
|
|
134
|
-
export function estimateExecuteGlvWithdrawalGasLimit(gasLimits, { marketsCount, }) {
|
|
136
|
+
export function estimateExecuteGlvWithdrawalGasLimit(gasLimits, { marketsCount, swapsCount, }) {
|
|
135
137
|
const gasPerGlvPerMarket = gasLimits.glvPerMarketGasLimit;
|
|
136
138
|
const gasForGlvMarkets = gasPerGlvPerMarket * marketsCount;
|
|
137
139
|
const glvWithdrawalGasLimit = gasLimits.glvWithdrawalGasLimit;
|
|
138
140
|
const gasLimit = glvWithdrawalGasLimit + gasForGlvMarkets;
|
|
139
|
-
|
|
141
|
+
const gasPerSwap = gasLimits.singleSwap;
|
|
142
|
+
const gasForSwaps = swapsCount * gasPerSwap;
|
|
143
|
+
return gasLimit + gasLimits.withdrawalMultiToken + gasForSwaps;
|
|
140
144
|
}
|
|
141
145
|
/**
|
|
142
146
|
* Only GM withdrawals. Do not confuse with decrease with zero delta size.
|
|
@@ -144,11 +148,10 @@ export function estimateExecuteGlvWithdrawalGasLimit(gasLimits, { marketsCount,
|
|
|
144
148
|
* Copy from contract: `estimateExecuteWithdrawalGasLimit`
|
|
145
149
|
*/
|
|
146
150
|
export function estimateExecuteWithdrawalGasLimit(gasLimits, withdrawal) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return gasLimits.withdrawalMultiToken + (withdrawal.callbackGasLimit ?? 0n);
|
|
151
|
+
const gasPerSwap = gasLimits.singleSwap;
|
|
152
|
+
const swapsCount = withdrawal.swapsCount ?? 0n;
|
|
153
|
+
const gasForSwaps = swapsCount * gasPerSwap;
|
|
154
|
+
return gasLimits.withdrawalMultiToken + (withdrawal.callbackGasLimit ?? 0n) + gasForSwaps;
|
|
152
155
|
}
|
|
153
156
|
/**
|
|
154
157
|
* Copy from contract: `estimateExecuteShiftGasLimit`
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { HIGH_PRICE_IMPACT_BPS } from "../../configs/factors";
|
|
2
|
+
import { SwapPricingType } from "../../types/orders";
|
|
2
3
|
import { bigMath } from "../bigmath";
|
|
4
|
+
import { getOpenInterestForBalance } from "../markets";
|
|
3
5
|
import { applyFactor, getBasisPoints, PRECISION } from "../numbers";
|
|
4
6
|
export * from "./estimateOraclePriceCount";
|
|
5
7
|
export * from "./executionFee";
|
|
6
8
|
export * from "./priceImpact";
|
|
7
|
-
export function getSwapFee(marketInfo, swapAmount, balanceWasImproved,
|
|
9
|
+
export function getSwapFee(marketInfo, swapAmount, balanceWasImproved, swapPricingType) {
|
|
8
10
|
let factor;
|
|
9
|
-
if (
|
|
11
|
+
if (swapPricingType === SwapPricingType.AtomicSwap) {
|
|
10
12
|
factor = marketInfo.atomicSwapFeeFactor;
|
|
11
13
|
}
|
|
14
|
+
else if (swapPricingType === SwapPricingType.Withdrawal) {
|
|
15
|
+
factor = balanceWasImproved
|
|
16
|
+
? marketInfo.withdrawalFeeFactorBalanceWasImproved ?? marketInfo.swapFeeFactorForBalanceWasImproved
|
|
17
|
+
: marketInfo.withdrawalFeeFactorBalanceWasNotImproved ?? marketInfo.swapFeeFactorForBalanceWasNotImproved;
|
|
18
|
+
}
|
|
12
19
|
else {
|
|
13
20
|
factor = balanceWasImproved
|
|
14
21
|
? marketInfo.swapFeeFactorForBalanceWasImproved
|
|
@@ -36,14 +43,12 @@ export function getPositionFee(marketInfo, sizeDeltaUsd, balanceWasImproved, ref
|
|
|
36
43
|
};
|
|
37
44
|
}
|
|
38
45
|
export function getFundingFactorPerPeriod(marketInfo, isLong, periodInSeconds) {
|
|
39
|
-
const { fundingFactorPerSecond, longsPayShorts
|
|
40
|
-
const
|
|
46
|
+
const { fundingFactorPerSecond, longsPayShorts } = marketInfo;
|
|
47
|
+
const longInterestUsd = getOpenInterestForBalance(marketInfo, true);
|
|
48
|
+
const shortInterestUsd = getOpenInterestForBalance(marketInfo, false);
|
|
41
49
|
const payingInterestUsd = longsPayShorts ? longInterestUsd : shortInterestUsd;
|
|
42
50
|
const receivingInterestUsd = longsPayShorts ? shortInterestUsd : longInterestUsd;
|
|
43
|
-
|
|
44
|
-
if (payingInterestUsd !== 0n) {
|
|
45
|
-
fundingForPayingSide = bigMath.mulDiv(fundingFactorPerSecond, largerInterestUsd, payingInterestUsd);
|
|
46
|
-
}
|
|
51
|
+
const fundingForPayingSide = fundingFactorPerSecond;
|
|
47
52
|
let fundingForReceivingSide = 0n;
|
|
48
53
|
if (receivingInterestUsd !== 0n) {
|
|
49
54
|
fundingForReceivingSide = bigMath.mulDiv(fundingForPayingSide, payingInterestUsd, receivingInterestUsd);
|