@mento-protocol/mento-sdk 3.2.3 → 3.2.4
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/dist/cache/routes.d.ts +13 -0
- package/dist/cache/routes.js +14089 -0
- package/dist/cache/tokens.d.ts +68 -0
- package/dist/cache/tokens.js +460 -0
- package/dist/core/abis/activePool.d.ts +2 -0
- package/dist/core/abis/activePool.js +14 -0
- package/dist/core/abis/addressesRegistry.d.ts +2 -0
- package/dist/core/abis/addressesRegistry.js +26 -0
- package/dist/core/abis/bipoolmanager.d.ts +34 -0
- package/dist/core/abis/bipoolmanager.js +72 -0
- package/dist/core/abis/borrowerOperations.d.ts +9 -0
- package/dist/core/abis/borrowerOperations.js +89 -0
- package/dist/core/abis/breakerbox.d.ts +13 -0
- package/dist/core/abis/breakerbox.js +8 -0
- package/dist/core/abis/broker.d.ts +2 -0
- package/dist/core/abis/broker.js +9 -0
- package/dist/core/abis/erc20.d.ts +9 -0
- package/dist/core/abis/erc20.js +21 -0
- package/dist/core/abis/fpmm.d.ts +270 -0
- package/dist/core/abis/fpmm.js +49 -0
- package/dist/core/abis/fpmmFactory.d.ts +85 -0
- package/dist/core/abis/fpmmFactory.js +26 -0
- package/dist/core/abis/hintHelpers.d.ts +2 -0
- package/dist/core/abis/hintHelpers.js +14 -0
- package/dist/core/abis/index.d.ts +22 -0
- package/dist/core/abis/index.js +38 -0
- package/dist/core/abis/liquidityStrategy.d.ts +132 -0
- package/dist/core/abis/liquidityStrategy.js +10 -0
- package/dist/core/abis/multiTroveGetter.d.ts +8 -0
- package/dist/core/abis/multiTroveGetter.js +15 -0
- package/dist/core/abis/priceFeed.d.ts +7 -0
- package/dist/core/abis/priceFeed.js +16 -0
- package/dist/core/abis/pricingmodule.d.ts +2 -0
- package/dist/core/abis/pricingmodule.js +6 -0
- package/dist/core/abis/reserve.d.ts +3 -0
- package/dist/core/abis/reserve.js +18 -0
- package/dist/core/abis/router.d.ts +521 -0
- package/dist/core/abis/router.js +45 -0
- package/dist/core/abis/sortedTroves.d.ts +2 -0
- package/dist/core/abis/sortedTroves.js +15 -0
- package/dist/core/abis/systemParams.d.ts +2 -0
- package/dist/core/abis/systemParams.js +14 -0
- package/dist/core/abis/troveManager.d.ts +2 -0
- package/dist/core/abis/troveManager.js +27 -0
- package/dist/core/abis/troveNFT.d.ts +2 -0
- package/dist/core/abis/troveNFT.js +9 -0
- package/dist/core/abis/virtualPool.d.ts +50 -0
- package/dist/core/abis/virtualPool.js +11 -0
- package/dist/core/abis/virtualPoolFactory.d.ts +59 -0
- package/dist/core/abis/virtualPoolFactory.js +17 -0
- package/dist/core/constants/addresses.d.ts +18 -0
- package/dist/core/constants/addresses.js +113 -0
- package/dist/core/constants/borrowConstants.d.ts +10 -0
- package/dist/core/constants/borrowConstants.js +16 -0
- package/dist/core/constants/borrowRegistries.d.ts +7 -0
- package/dist/core/constants/borrowRegistries.js +30 -0
- package/dist/core/constants/chainId.d.ts +7 -0
- package/dist/{cjs/enums → core/constants}/chainId.js +4 -1
- package/dist/core/constants/contractNames.d.ts +21 -0
- package/dist/core/constants/contractNames.js +24 -0
- package/dist/core/constants/index.d.ts +6 -0
- package/dist/core/constants/index.js +22 -0
- package/dist/core/errors/base.d.ts +8 -0
- package/dist/core/errors/base.js +17 -0
- package/dist/core/errors/index.d.ts +4 -0
- package/dist/{cjs/constants → core/errors}/index.js +4 -4
- package/dist/core/errors/oracle.d.ts +9 -0
- package/dist/core/errors/oracle.js +15 -0
- package/dist/core/errors/router.d.ts +14 -0
- package/dist/core/errors/router.js +24 -0
- package/dist/core/types/borrow.d.ts +87 -0
- package/dist/{cjs/interfaces/tradingLimitsConfig.js → core/types/borrow.js} +1 -0
- package/dist/core/types/contractAddresses.d.ts +42 -0
- package/dist/{cjs → core}/types/contractAddresses.js +1 -0
- package/dist/core/types/index.d.ts +10 -0
- package/dist/core/types/index.js +26 -0
- package/dist/core/types/liquidity.d.ts +194 -0
- package/dist/core/types/liquidity.js +3 -0
- package/dist/core/types/pool.d.ts +208 -0
- package/dist/core/types/pool.js +14 -0
- package/dist/core/types/provider.d.ts +45 -0
- package/dist/{cjs/interfaces/tradingLimitsState.js → core/types/provider.js} +1 -0
- package/dist/core/types/route.d.ts +62 -0
- package/dist/{cjs/interfaces/IChainClient.js → core/types/route.js} +1 -0
- package/dist/core/types/token.d.ts +21 -0
- package/dist/{cjs/interfaces/tradingLimit.js → core/types/token.js} +1 -0
- package/dist/core/types/tradingLimits.d.ts +91 -0
- package/dist/core/types/tradingLimits.js +3 -0
- package/dist/core/types/tradingMode.d.ts +24 -0
- package/dist/core/types/tradingMode.js +31 -0
- package/dist/core/types/transaction.d.ts +45 -0
- package/dist/core/types/transaction.js +3 -0
- package/dist/esm/cache/routes.js +14084 -0
- package/dist/esm/cache/tokens.js +452 -0
- package/dist/esm/core/abis/activePool.js +10 -0
- package/dist/esm/core/abis/addressesRegistry.js +22 -0
- package/dist/esm/core/abis/bipoolmanager.js +68 -0
- package/dist/esm/core/abis/borrowerOperations.js +85 -0
- package/dist/esm/core/abis/breakerbox.js +4 -0
- package/dist/esm/core/abis/broker.js +5 -0
- package/dist/esm/core/abis/erc20.js +17 -0
- package/dist/esm/core/abis/fpmm.js +45 -0
- package/dist/esm/core/abis/fpmmFactory.js +22 -0
- package/dist/esm/core/abis/hintHelpers.js +10 -0
- package/dist/esm/core/abis/index.js +21 -0
- package/dist/esm/core/abis/liquidityStrategy.js +6 -0
- package/dist/esm/core/abis/multiTroveGetter.js +11 -0
- package/dist/esm/core/abis/priceFeed.js +12 -0
- package/dist/esm/core/abis/pricingmodule.js +2 -0
- package/dist/esm/core/abis/reserve.js +14 -0
- package/dist/esm/core/abis/router.js +41 -0
- package/dist/esm/core/abis/sortedTroves.js +11 -0
- package/dist/esm/core/abis/systemParams.js +10 -0
- package/dist/esm/core/abis/troveManager.js +23 -0
- package/dist/esm/core/abis/troveNFT.js +5 -0
- package/dist/esm/core/abis/virtualPool.js +7 -0
- package/dist/esm/core/abis/virtualPoolFactory.js +13 -0
- package/dist/esm/core/constants/addresses.js +107 -0
- package/dist/esm/core/constants/borrowConstants.js +12 -0
- package/dist/esm/core/constants/borrowRegistries.js +25 -0
- package/dist/esm/{enums → core/constants}/chainId.js +2 -0
- package/dist/esm/core/constants/contractNames.js +20 -0
- package/dist/esm/core/constants/index.js +5 -0
- package/dist/esm/core/errors/base.js +12 -0
- package/dist/esm/core/errors/index.js +3 -0
- package/dist/esm/core/errors/oracle.js +10 -0
- package/dist/esm/core/errors/router.js +18 -0
- package/dist/esm/core/types/index.js +9 -0
- package/dist/esm/core/types/pool.js +10 -0
- package/dist/esm/core/types/tradingLimits.js +1 -0
- package/dist/esm/core/types/tradingMode.js +26 -0
- package/dist/esm/core/types/transaction.js +1 -0
- package/dist/esm/index.js +138 -6
- package/dist/esm/package.json +1 -0
- package/dist/esm/services/borrow/BorrowService.js +455 -0
- package/dist/esm/services/borrow/borrowHelpers.js +3 -0
- package/dist/esm/services/borrow/borrowMath.js +127 -0
- package/dist/esm/services/borrow/index.js +3 -0
- package/dist/esm/services/borrow/internal/borrowApprovalService.js +48 -0
- package/dist/esm/services/borrow/internal/borrowContextStore.js +35 -0
- package/dist/esm/services/borrow/internal/borrowErc20.js +38 -0
- package/dist/esm/services/borrow/internal/borrowHints.js +27 -0
- package/dist/esm/services/borrow/internal/borrowPositionParser.js +82 -0
- package/dist/esm/services/borrow/internal/borrowReadService.js +271 -0
- package/dist/esm/services/borrow/internal/borrowRegistryReader.js +108 -0
- package/dist/esm/services/borrow/internal/borrowTransactionService.js +271 -0
- package/dist/esm/services/borrow/internal/borrowTypes.js +1 -0
- package/dist/esm/services/borrow/internal/borrowValidation.js +89 -0
- package/dist/esm/services/index.js +8 -0
- package/dist/esm/services/liquidity/LiquidityService.js +163 -0
- package/dist/esm/services/liquidity/basicLiquidity.js +162 -0
- package/dist/esm/services/liquidity/index.js +1 -0
- package/dist/esm/services/liquidity/liquidityHelpers.js +95 -0
- package/dist/esm/services/liquidity/rebalance.js +59 -0
- package/dist/esm/services/liquidity/zapHelpers.js +120 -0
- package/dist/esm/services/liquidity/zapIn.js +112 -0
- package/dist/esm/services/liquidity/zapOut.js +248 -0
- package/dist/esm/services/pools/PoolService.js +204 -0
- package/dist/esm/services/pools/index.js +1 -0
- package/dist/esm/services/pools/poolDetails.js +209 -0
- package/dist/esm/services/pools/poolDiscovery.js +112 -0
- package/dist/esm/services/pools/rebalancePreview.js +181 -0
- package/dist/esm/services/quotes/QuoteService.js +85 -0
- package/dist/esm/services/quotes/index.js +1 -0
- package/dist/esm/services/routes/RouteService.js +268 -0
- package/dist/esm/services/routes/index.js +1 -0
- package/dist/esm/services/swap/SwapService.js +247 -0
- package/dist/esm/services/swap/index.js +1 -0
- package/dist/esm/services/tokens/index.js +1 -0
- package/dist/esm/services/tokens/tokenService.js +285 -0
- package/dist/esm/services/trading/TradingLimitsService.js +154 -0
- package/dist/esm/services/trading/TradingService.js +196 -0
- package/dist/esm/services/trading/index.js +2 -0
- package/dist/esm/utils/chainConfig.js +118 -0
- package/dist/esm/utils/costUtils.js +56 -0
- package/dist/esm/utils/deadline.js +22 -0
- package/dist/esm/utils/index.js +9 -0
- package/dist/esm/utils/multicall.js +47 -0
- package/dist/esm/utils/pathEncoder.js +69 -0
- package/dist/esm/utils/rateFeed.js +23 -0
- package/dist/esm/utils/retry.js +24 -0
- package/dist/esm/{routeUtils.js → utils/routeUtils.js} +115 -116
- package/dist/esm/utils/routes.js +2 -0
- package/dist/esm/utils/sortUtils.js +33 -0
- package/dist/esm/utils/tokens.js +2 -0
- package/dist/esm/utils/tradingLimits.js +163 -0
- package/dist/esm/utils/validation.js +30 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +158 -0
- package/dist/services/borrow/BorrowService.d.ts +381 -0
- package/dist/services/borrow/BorrowService.js +460 -0
- package/dist/services/borrow/borrowHelpers.d.ts +4 -0
- package/dist/services/borrow/borrowHelpers.js +13 -0
- package/dist/services/borrow/borrowMath.d.ts +21 -0
- package/dist/services/borrow/borrowMath.js +137 -0
- package/dist/services/borrow/index.d.ts +4 -0
- package/dist/{cjs/interfaces → services/borrow}/index.js +4 -4
- package/dist/services/borrow/internal/borrowApprovalService.d.ts +14 -0
- package/dist/services/borrow/internal/borrowApprovalService.js +53 -0
- package/dist/services/borrow/internal/borrowContextStore.d.ts +11 -0
- package/dist/services/borrow/internal/borrowContextStore.js +40 -0
- package/dist/services/borrow/internal/borrowErc20.d.ts +5 -0
- package/dist/services/borrow/internal/borrowErc20.js +43 -0
- package/dist/services/borrow/internal/borrowHints.d.ts +7 -0
- package/dist/services/borrow/internal/borrowHints.js +31 -0
- package/dist/services/borrow/internal/borrowPositionParser.d.ts +4 -0
- package/dist/services/borrow/internal/borrowPositionParser.js +87 -0
- package/dist/services/borrow/internal/borrowReadService.d.ts +31 -0
- package/dist/services/borrow/internal/borrowReadService.js +276 -0
- package/dist/services/borrow/internal/borrowRegistryReader.d.ts +5 -0
- package/dist/services/borrow/internal/borrowRegistryReader.js +113 -0
- package/dist/services/borrow/internal/borrowTransactionService.d.ts +23 -0
- package/dist/services/borrow/internal/borrowTransactionService.js +276 -0
- package/dist/services/borrow/internal/borrowTypes.d.ts +15 -0
- package/dist/services/borrow/internal/borrowTypes.js +3 -0
- package/dist/services/borrow/internal/borrowValidation.d.ts +14 -0
- package/dist/services/borrow/internal/borrowValidation.js +104 -0
- package/dist/services/index.d.ts +9 -0
- package/dist/{cjs → services}/index.js +9 -7
- package/dist/services/liquidity/LiquidityService.d.ts +139 -0
- package/dist/services/liquidity/LiquidityService.js +168 -0
- package/dist/services/liquidity/basicLiquidity.d.ts +11 -0
- package/dist/services/liquidity/basicLiquidity.js +172 -0
- package/dist/services/liquidity/index.d.ts +2 -0
- package/dist/{cjs/types → services/liquidity}/index.js +2 -2
- package/dist/services/liquidity/liquidityHelpers.d.ts +19 -0
- package/dist/services/liquidity/liquidityHelpers.js +104 -0
- package/dist/services/liquidity/rebalance.d.ts +6 -0
- package/dist/services/liquidity/rebalance.js +64 -0
- package/dist/services/liquidity/zapHelpers.d.ts +66 -0
- package/dist/services/liquidity/zapHelpers.js +129 -0
- package/dist/services/liquidity/zapIn.d.ts +18 -0
- package/dist/services/liquidity/zapIn.js +119 -0
- package/dist/services/liquidity/zapOut.d.ts +9 -0
- package/dist/services/liquidity/zapOut.js +255 -0
- package/dist/services/pools/PoolService.d.ts +69 -0
- package/dist/services/pools/PoolService.js +209 -0
- package/dist/services/pools/index.d.ts +2 -0
- package/dist/{cjs/enums → services/pools}/index.js +2 -3
- package/dist/services/pools/poolDetails.d.ts +13 -0
- package/dist/services/pools/poolDetails.js +216 -0
- package/dist/services/pools/poolDiscovery.d.ts +12 -0
- package/dist/services/pools/poolDiscovery.js +117 -0
- package/dist/services/pools/rebalancePreview.d.ts +5 -0
- package/dist/services/pools/rebalancePreview.js +186 -0
- package/dist/services/quotes/QuoteService.d.ts +51 -0
- package/dist/services/quotes/QuoteService.js +91 -0
- package/dist/services/quotes/index.d.ts +2 -0
- package/dist/services/quotes/index.js +18 -0
- package/dist/services/routes/RouteService.d.ts +117 -0
- package/dist/services/routes/RouteService.js +306 -0
- package/dist/services/routes/index.d.ts +2 -0
- package/dist/services/routes/index.js +18 -0
- package/dist/services/swap/SwapService.d.ts +198 -0
- package/dist/services/swap/SwapService.js +252 -0
- package/dist/services/swap/index.d.ts +2 -0
- package/dist/services/swap/index.js +18 -0
- package/dist/services/tokens/index.d.ts +2 -0
- package/dist/services/tokens/index.js +18 -0
- package/dist/services/tokens/tokenService.d.ts +55 -0
- package/dist/services/tokens/tokenService.js +290 -0
- package/dist/services/trading/TradingLimitsService.d.ts +38 -0
- package/dist/services/trading/TradingLimitsService.js +159 -0
- package/dist/services/trading/TradingService.d.ts +113 -0
- package/dist/services/trading/TradingService.js +201 -0
- package/dist/services/trading/index.d.ts +3 -0
- package/dist/services/trading/index.js +19 -0
- package/dist/utils/chainConfig.d.ts +16 -0
- package/dist/utils/chainConfig.js +123 -0
- package/dist/utils/costUtils.d.ts +12 -0
- package/dist/utils/costUtils.js +60 -0
- package/dist/utils/deadline.d.ts +21 -0
- package/dist/utils/deadline.js +26 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.js +26 -0
- package/dist/utils/multicall.d.ts +30 -0
- package/dist/utils/multicall.js +52 -0
- package/dist/utils/pathEncoder.d.ts +34 -0
- package/dist/utils/pathEncoder.js +73 -0
- package/dist/utils/rateFeed.d.ts +18 -0
- package/dist/utils/rateFeed.js +27 -0
- package/dist/utils/retry.d.ts +12 -0
- package/dist/utils/retry.js +28 -0
- package/dist/{esm → utils}/routeUtils.d.ts +84 -93
- package/dist/{cjs → utils}/routeUtils.js +123 -124
- package/dist/utils/routes.d.ts +3 -0
- package/dist/utils/routes.js +8 -0
- package/dist/utils/sortUtils.d.ts +24 -0
- package/dist/utils/sortUtils.js +39 -0
- package/dist/utils/tokens.d.ts +2 -0
- package/dist/utils/tokens.js +13 -0
- package/dist/utils/tradingLimits.d.ts +41 -0
- package/dist/utils/tradingLimits.js +171 -0
- package/dist/utils/validation.d.ts +19 -0
- package/dist/utils/validation.js +34 -0
- package/package.json +1 -1
- package/dist/cjs/ChainClient.d.ts +0 -9
- package/dist/cjs/ChainClient.js +0 -58
- package/dist/cjs/TestChainClient.d.ts +0 -7
- package/dist/cjs/TestChainClient.js +0 -41
- package/dist/cjs/constants/addresses.d.ts +0 -4
- package/dist/cjs/constants/addresses.js +0 -59
- package/dist/cjs/constants/currencies.d.ts +0 -5
- package/dist/cjs/constants/currencies.js +0 -29
- package/dist/cjs/constants/index.d.ts +0 -4
- package/dist/cjs/constants/tokens.11142220.d.ts +0 -2
- package/dist/cjs/constants/tokens.11142220.js +0 -128
- package/dist/cjs/constants/tokens.42220.d.ts +0 -2
- package/dist/cjs/constants/tokens.42220.js +0 -128
- package/dist/cjs/constants/tokens.d.ts +0 -65
- package/dist/cjs/constants/tokens.js +0 -170
- package/dist/cjs/constants/tradablePairs.11142220.d.ts +0 -2
- package/dist/cjs/constants/tradablePairs.11142220.js +0 -7391
- package/dist/cjs/constants/tradablePairs.42220.d.ts +0 -2
- package/dist/cjs/constants/tradablePairs.42220.js +0 -7391
- package/dist/cjs/constants/tradablePairs.d.ts +0 -16
- package/dist/cjs/constants/tradablePairs.js +0 -53
- package/dist/cjs/enums/chainId.d.ts +0 -4
- package/dist/cjs/enums/index.d.ts +0 -3
- package/dist/cjs/enums/proposalState.d.ts +0 -10
- package/dist/cjs/enums/proposalState.js +0 -14
- package/dist/cjs/enums/tradingMode.d.ts +0 -17
- package/dist/cjs/enums/tradingMode.js +0 -21
- package/dist/cjs/governance.d.ts +0 -62
- package/dist/cjs/governance.js +0 -151
- package/dist/cjs/index.d.ts +0 -7
- package/dist/cjs/interfaces/IChainClient.d.ts +0 -6
- package/dist/cjs/interfaces/index.d.ts +0 -4
- package/dist/cjs/interfaces/tradingLimit.d.ts +0 -7
- package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +0 -10
- package/dist/cjs/interfaces/tradingLimitsState.d.ts +0 -9
- package/dist/cjs/limits.d.ts +0 -33
- package/dist/cjs/limits.js +0 -130
- package/dist/cjs/mento.d.ts +0 -287
- package/dist/cjs/mento.js +0 -699
- package/dist/cjs/routeUtils.d.ts +0 -304
- package/dist/cjs/types/contractAddressMap.d.ts +0 -4
- package/dist/cjs/types/contractAddressMap.js +0 -2
- package/dist/cjs/types/contractAddresses.d.ts +0 -23
- package/dist/cjs/types/index.d.ts +0 -2
- package/dist/cjs/utils.d.ts +0 -80
- package/dist/cjs/utils.js +0 -177
- package/dist/esm/ChainClient.d.ts +0 -9
- package/dist/esm/ChainClient.js +0 -54
- package/dist/esm/TestChainClient.d.ts +0 -7
- package/dist/esm/TestChainClient.js +0 -37
- package/dist/esm/constants/addresses.d.ts +0 -4
- package/dist/esm/constants/addresses.js +0 -55
- package/dist/esm/constants/currencies.d.ts +0 -5
- package/dist/esm/constants/currencies.js +0 -26
- package/dist/esm/constants/index.d.ts +0 -4
- package/dist/esm/constants/index.js +0 -4
- package/dist/esm/constants/tokens.11142220.d.ts +0 -2
- package/dist/esm/constants/tokens.11142220.js +0 -125
- package/dist/esm/constants/tokens.42220.d.ts +0 -2
- package/dist/esm/constants/tokens.42220.js +0 -125
- package/dist/esm/constants/tokens.d.ts +0 -65
- package/dist/esm/constants/tokens.js +0 -142
- package/dist/esm/constants/tradablePairs.11142220.d.ts +0 -2
- package/dist/esm/constants/tradablePairs.11142220.js +0 -7388
- package/dist/esm/constants/tradablePairs.42220.d.ts +0 -2
- package/dist/esm/constants/tradablePairs.42220.js +0 -7388
- package/dist/esm/constants/tradablePairs.d.ts +0 -16
- package/dist/esm/constants/tradablePairs.js +0 -26
- package/dist/esm/enums/chainId.d.ts +0 -4
- package/dist/esm/enums/index.d.ts +0 -3
- package/dist/esm/enums/index.js +0 -3
- package/dist/esm/enums/proposalState.d.ts +0 -10
- package/dist/esm/enums/proposalState.js +0 -11
- package/dist/esm/enums/tradingMode.d.ts +0 -17
- package/dist/esm/enums/tradingMode.js +0 -18
- package/dist/esm/governance.d.ts +0 -62
- package/dist/esm/governance.js +0 -147
- package/dist/esm/index.d.ts +0 -7
- package/dist/esm/interfaces/IChainClient.d.ts +0 -6
- package/dist/esm/interfaces/index.d.ts +0 -4
- package/dist/esm/interfaces/index.js +0 -4
- package/dist/esm/interfaces/tradingLimit.d.ts +0 -7
- package/dist/esm/interfaces/tradingLimitsConfig.d.ts +0 -10
- package/dist/esm/interfaces/tradingLimitsState.d.ts +0 -9
- package/dist/esm/limits.d.ts +0 -33
- package/dist/esm/limits.js +0 -123
- package/dist/esm/mento.d.ts +0 -287
- package/dist/esm/mento.js +0 -671
- package/dist/esm/types/contractAddressMap.d.ts +0 -4
- package/dist/esm/types/contractAddresses.d.ts +0 -23
- package/dist/esm/types/index.d.ts +0 -2
- package/dist/esm/types/index.js +0 -2
- package/dist/esm/utils.d.ts +0 -80
- package/dist/esm/utils.js +0 -162
- /package/dist/esm/{interfaces/IChainClient.js → core/types/borrow.js} +0 -0
- /package/dist/esm/{types → core/types}/contractAddresses.js +0 -0
- /package/dist/esm/{interfaces/tradingLimit.js → core/types/liquidity.js} +0 -0
- /package/dist/esm/{interfaces/tradingLimitsConfig.js → core/types/provider.js} +0 -0
- /package/dist/esm/{interfaces/tradingLimitsState.js → core/types/route.js} +0 -0
- /package/dist/esm/{types/contractAddressMap.js → core/types/token.js} +0 -0
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.buildConnectivityStructures = buildConnectivityStructures;
|
|
4
|
+
exports.generateAllRoutes = generateAllRoutes;
|
|
5
|
+
exports.createTwoHopRoute = createTwoHopRoute;
|
|
6
|
+
exports.selectOptimalRoutes = selectOptimalRoutes;
|
|
7
|
+
exports.selectBestRoute = selectBestRoute;
|
|
8
|
+
exports.getIntermediateToken = getIntermediateToken;
|
|
9
|
+
exports.hasCostData = hasCostData;
|
|
10
|
+
const sortUtils_1 = require("./sortUtils");
|
|
4
11
|
/**
|
|
5
12
|
* Builds the connectivity data structures needed for route generation.
|
|
6
13
|
*
|
|
@@ -11,23 +18,23 @@ exports.hasSpreadData = exports.getIntermediateToken = exports.selectBestRoute =
|
|
|
11
18
|
*
|
|
12
19
|
* ```
|
|
13
20
|
* Input: TradablePairs = [
|
|
14
|
-
* { id: '
|
|
15
|
-
* { id: 'CELO-
|
|
21
|
+
* { id: 'USDm-CELO', assets: [USDm, CELO], path: [exchange1_CELO_USDm] },
|
|
22
|
+
* { id: 'CELO-EURm', assets: [CELO, EURm], path: [exchange2_CELO_EURm] }
|
|
16
23
|
* ]
|
|
17
24
|
*
|
|
18
25
|
* Step 1 - Build addrToSymbol map:
|
|
19
|
-
*
|
|
26
|
+
* USDm.address → 'USDm'
|
|
20
27
|
* CELO.address → 'CELO'
|
|
21
|
-
*
|
|
28
|
+
* EURm.address → 'EURm'
|
|
22
29
|
*
|
|
23
30
|
* Step 2 - Build directPathMap (sorted alphabetically for consistency):
|
|
24
|
-
* 'CELO_addr-
|
|
25
|
-
* 'CELO_addr-
|
|
31
|
+
* 'CELO_addr-EURm_addr' → exchange2_CELO_EURm
|
|
32
|
+
* 'CELO_addr-USDm_addr' → exchange1_CELO_USDm
|
|
26
33
|
*
|
|
27
34
|
* Step 3 - Build bidirectional tokenGraph:
|
|
28
|
-
*
|
|
29
|
-
* CELO.address → Set([
|
|
30
|
-
*
|
|
35
|
+
* USDm.address → Set([CELO.address])
|
|
36
|
+
* CELO.address → Set([USDm.address, EURm.address])
|
|
37
|
+
* EURm.address → Set([CELO.address])
|
|
31
38
|
* ```
|
|
32
39
|
*
|
|
33
40
|
* **Result**: We can now efficiently answer:
|
|
@@ -35,60 +42,57 @@ exports.hasSpreadData = exports.getIntermediateToken = exports.selectBestRoute =
|
|
|
35
42
|
* - "What exchange connects tokens X and Y?" → directPathMap.get(sortedAddressPairKey)
|
|
36
43
|
* - "What tokens can I reach from token X?" → tokenGraph.get(X)
|
|
37
44
|
*
|
|
38
|
-
* @param
|
|
45
|
+
* @param directRoutes - Array of direct trading pairs
|
|
39
46
|
* @returns Connectivity data structure for efficient route generation
|
|
40
47
|
*
|
|
41
48
|
* @example
|
|
42
49
|
* ```typescript
|
|
43
50
|
* const directPairs = [
|
|
44
|
-
* { id: '
|
|
45
|
-
* { id: 'CELO-
|
|
51
|
+
* { id: 'USDm-CELO', assets: [USDm, CELO], path: [exchange1] },
|
|
52
|
+
* { id: 'CELO-EURm', assets: [CELO, EURm], path: [exchange2] }
|
|
46
53
|
* ]
|
|
47
54
|
*
|
|
48
55
|
* const connectivityData = buildConnectivityStructures(directPairs)
|
|
49
56
|
*
|
|
50
57
|
* // Now we can efficiently find routes:
|
|
51
|
-
* // 1. Check if
|
|
52
|
-
* // 2. Check if CELO connects to
|
|
53
|
-
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-
|
|
54
|
-
* // Result: Found route
|
|
58
|
+
* // 1. Check if USDm connects to anything: connectivityData.tokenGraph.get(USDm.address) → [CELO.address]
|
|
59
|
+
* // 2. Check if CELO connects to EURm: connectivityData.tokenGraph.get(CELO.address) → [USDm.address, EURm.address] ✓
|
|
60
|
+
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-EURm_addr') → exchange2_CELO_EURm
|
|
61
|
+
* // Result: Found route USDm → CELO → EURm with exchange details
|
|
55
62
|
* ```
|
|
56
63
|
*/
|
|
57
|
-
function buildConnectivityStructures(
|
|
64
|
+
function buildConnectivityStructures(directRoutes) {
|
|
58
65
|
const addrToSymbol = new Map();
|
|
59
|
-
const
|
|
66
|
+
const directRouteMap = new Map();
|
|
60
67
|
const tokenGraph = new Map();
|
|
61
|
-
for (const
|
|
62
|
-
const [
|
|
68
|
+
for (const route of directRoutes) {
|
|
69
|
+
const [tokenA, tokenB] = route.tokens;
|
|
63
70
|
// Build address-to-symbol map for quick symbol lookups
|
|
64
|
-
addrToSymbol.set(
|
|
65
|
-
addrToSymbol.set(
|
|
71
|
+
addrToSymbol.set(tokenA.address, tokenA.symbol);
|
|
72
|
+
addrToSymbol.set(tokenB.address, tokenB.symbol);
|
|
66
73
|
// Build direct path map (sorted addresses as key for consistency)
|
|
67
74
|
// for quick lookup of exchange details for any token pair
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
if (!directPathMap.has(sortedAddresses)) {
|
|
72
|
-
directPathMap.set(sortedAddresses, pair.path[0]);
|
|
75
|
+
const routeId = (0, sortUtils_1.canonicalSymbolKey)(tokenA.symbol, tokenB.symbol);
|
|
76
|
+
if (!directRouteMap.has(routeId)) {
|
|
77
|
+
directRouteMap.set(routeId, route.path[0]);
|
|
73
78
|
}
|
|
74
79
|
// Build bidirectional connectivity graph for route traversal
|
|
75
80
|
// Each token can reach its directly connected tokens
|
|
76
|
-
if (!tokenGraph.has(
|
|
77
|
-
tokenGraph.set(
|
|
78
|
-
if (!tokenGraph.has(
|
|
79
|
-
tokenGraph.set(
|
|
80
|
-
tokenGraph.get(
|
|
81
|
-
tokenGraph.get(
|
|
81
|
+
if (!tokenGraph.has(tokenA.address))
|
|
82
|
+
tokenGraph.set(tokenA.address, new Set());
|
|
83
|
+
if (!tokenGraph.has(tokenB.address))
|
|
84
|
+
tokenGraph.set(tokenB.address, new Set());
|
|
85
|
+
tokenGraph.get(tokenA.address).add(tokenB.address);
|
|
86
|
+
tokenGraph.get(tokenB.address).add(tokenA.address);
|
|
82
87
|
}
|
|
83
|
-
return { addrToSymbol,
|
|
88
|
+
return { addrToSymbol, directRouteMap, tokenGraph, directRoutes };
|
|
84
89
|
}
|
|
85
|
-
exports.buildConnectivityStructures = buildConnectivityStructures;
|
|
86
90
|
/**
|
|
87
91
|
* Generates all possible routes (direct + two-hop) using connectivity data.
|
|
88
92
|
*
|
|
89
93
|
* This function implements a route discovery algorithm that:
|
|
90
94
|
*
|
|
91
|
-
* 1. **Adds all direct
|
|
95
|
+
* 1. **Adds all direct routes** (single-hop routes)
|
|
92
96
|
* 2. **Discovers two-hop routes** using graph traversal:
|
|
93
97
|
* - For each token A, find its neighbors (tokens directly connected)
|
|
94
98
|
* - For each neighbor B, find B's neighbors
|
|
@@ -96,71 +100,70 @@ exports.buildConnectivityStructures = buildConnectivityStructures;
|
|
|
96
100
|
*
|
|
97
101
|
* **Route Deduplication**: Multiple routes between the same token pair
|
|
98
102
|
* are collected in arrays, allowing the selection algorithm to choose
|
|
99
|
-
* the best one based on
|
|
103
|
+
* the best one based on cost data or heuristics.
|
|
100
104
|
*
|
|
101
|
-
* **Canonical
|
|
102
|
-
* (e.g., '
|
|
105
|
+
* **Canonical Route IDs**: All routes use alphabetically sorted symbols
|
|
106
|
+
* (e.g., 'EURm-USDm' not 'USDm-EURm') for consistent identification.
|
|
103
107
|
*
|
|
104
108
|
* @param connectivityData - The connectivity data from buildConnectivityStructures()
|
|
105
|
-
* @returns Map of
|
|
109
|
+
* @returns Map of route ID -> array of possible routes for that token pair
|
|
106
110
|
*
|
|
107
111
|
* @example
|
|
108
112
|
* ```typescript
|
|
109
|
-
* // Given direct
|
|
113
|
+
* // Given direct routes: USDm-CELO, CELO-EURm, USDm-USDC
|
|
110
114
|
* const allRoutes = generateAllRoutes(connectivityData)
|
|
111
115
|
*
|
|
112
116
|
* // Results might include:
|
|
113
|
-
* // '
|
|
114
|
-
* // '
|
|
115
|
-
* // { path: [
|
|
116
|
-
* // { path: [
|
|
117
|
+
* // 'USDm-CELO' -> [{ path: [USDm->CELO] }] // direct route
|
|
118
|
+
* // 'EURm-USDm' -> [
|
|
119
|
+
* // { path: [USDm->USDC, USDC->EURm] } // two-hop via USDC
|
|
120
|
+
* // { path: [USDm->CELO, CELO->EURm] } // two-hop via CELO
|
|
117
121
|
* // ]
|
|
118
122
|
* ```
|
|
119
123
|
*/
|
|
120
124
|
function generateAllRoutes(connectivityData) {
|
|
121
|
-
const { addrToSymbol,
|
|
125
|
+
const { addrToSymbol, directRouteMap, tokenGraph, directRoutes } = connectivityData;
|
|
122
126
|
const allRoutes = new Map();
|
|
123
127
|
// Step 1: Add all direct pairs (single-hop routes)
|
|
124
|
-
for (const
|
|
125
|
-
if (!allRoutes.has(
|
|
126
|
-
allRoutes.set(
|
|
128
|
+
for (const route of directRoutes) {
|
|
129
|
+
if (!allRoutes.has(route.id)) {
|
|
130
|
+
allRoutes.set(route.id, []);
|
|
127
131
|
}
|
|
128
|
-
allRoutes.get(
|
|
132
|
+
allRoutes.get(route.id).push(route);
|
|
129
133
|
}
|
|
130
|
-
// Step 2: Generate two-hop
|
|
134
|
+
// Step 2: Generate two-hop routes using graph traversal
|
|
131
135
|
// Algorithm: For each token, explore all paths of length 2
|
|
132
|
-
// OUTER LOOP: "For each starting token..." (e.g.,
|
|
136
|
+
// OUTER LOOP: "For each starting token..." (e.g., USDm, CELO, EURm, etc.)
|
|
133
137
|
for (const [start, neighbors] of tokenGraph.entries()) {
|
|
134
138
|
// MIDDLE LOOP: "Where can I go from the starting token?" (first hop)
|
|
135
|
-
// Example: If start =
|
|
139
|
+
// Example: If start = USDm, neighbors might be [CELO, USDC, KESm]
|
|
136
140
|
for (const intermediate of neighbors) {
|
|
137
141
|
// Get all tokens reachable from this intermediate token (second hop destinations)
|
|
138
142
|
const secondHopNeighbors = tokenGraph.get(intermediate);
|
|
139
143
|
if (!secondHopNeighbors)
|
|
140
144
|
continue;
|
|
141
145
|
// INNER LOOP: "From the intermediate token, where can I go?" (second hop)
|
|
142
|
-
// Example: If intermediate = CELO, secondHopNeighbors might be [
|
|
146
|
+
// Example: If intermediate = CELO, secondHopNeighbors might be [USDm, EURm, BRLm]
|
|
143
147
|
for (const end of secondHopNeighbors) {
|
|
144
|
-
// Skip circular routes like
|
|
148
|
+
// Skip circular routes like USDm → CELO → USDm (pointless)
|
|
145
149
|
if (end === start)
|
|
146
150
|
continue;
|
|
147
151
|
// At this point we have a potential route: start → intermediate → end
|
|
148
|
-
// Example:
|
|
152
|
+
// Example: USDm → CELO → EURm
|
|
149
153
|
// Try to create a valid two-hop trading pair from this route
|
|
150
|
-
const
|
|
154
|
+
const twoHopRoute = createTwoHopRoute(start, intermediate, end, addrToSymbol, directRouteMap);
|
|
151
155
|
// If we successfully created the pair, add it to our collection
|
|
152
|
-
if (
|
|
153
|
-
if (!allRoutes.has(
|
|
154
|
-
allRoutes.set(
|
|
156
|
+
if (twoHopRoute) {
|
|
157
|
+
if (!allRoutes.has(twoHopRoute.id)) {
|
|
158
|
+
allRoutes.set(twoHopRoute.id, []);
|
|
155
159
|
}
|
|
156
|
-
allRoutes.get(
|
|
160
|
+
allRoutes.get(twoHopRoute.id).push(twoHopRoute);
|
|
157
161
|
}
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
165
|
return allRoutes;
|
|
162
166
|
}
|
|
163
|
-
exports.generateAllRoutes = generateAllRoutes;
|
|
164
167
|
/**
|
|
165
168
|
* Creates a two-hop tradable pair if valid exchange hops exist.
|
|
166
169
|
*
|
|
@@ -184,56 +187,55 @@ exports.generateAllRoutes = generateAllRoutes;
|
|
|
184
187
|
*
|
|
185
188
|
* @example
|
|
186
189
|
* ```typescript
|
|
187
|
-
* // Create route:
|
|
190
|
+
* // Create route: USDm -> CELO -> EURm
|
|
188
191
|
* const pair = createTwoHopPair(
|
|
189
|
-
* '0x765D...', //
|
|
192
|
+
* '0x765D...', // USDm address
|
|
190
193
|
* '0x471E...', // CELO address
|
|
191
|
-
* '0xD876...', //
|
|
194
|
+
* '0xD876...', // EURm address
|
|
192
195
|
* addrToSymbol,
|
|
193
196
|
* directPathMap
|
|
194
197
|
* )
|
|
195
198
|
*
|
|
196
199
|
* // Result:
|
|
197
200
|
* // {
|
|
198
|
-
* // id: '
|
|
199
|
-
* // assets: [
|
|
201
|
+
* // id: 'EURm-USDm', // alphabetical order
|
|
202
|
+
* // assets: [EURm, USDm], // alphabetical order
|
|
200
203
|
* // path: [ // actual routing path
|
|
201
|
-
* // {
|
|
202
|
-
* // { CELO->
|
|
204
|
+
* // { USDm->CELO exchange },
|
|
205
|
+
* // { CELO->EURm exchange }
|
|
203
206
|
* // ]
|
|
204
207
|
* // }
|
|
205
208
|
* ```
|
|
206
209
|
*/
|
|
207
|
-
function
|
|
208
|
-
// Validate that both
|
|
209
|
-
const startSymbol = addrToSymbol.get(
|
|
210
|
-
const
|
|
211
|
-
|
|
210
|
+
function createTwoHopRoute(startAddr, intermediateAddr, endAddr, addrToSymbol, directRouteMap) {
|
|
211
|
+
// Validate that both all tokens exist in our address-to-symbol map
|
|
212
|
+
const startSymbol = addrToSymbol.get(startAddr);
|
|
213
|
+
const intermediateSymbol = addrToSymbol.get(intermediateAddr);
|
|
214
|
+
const endSymbol = addrToSymbol.get(endAddr);
|
|
215
|
+
if (!startSymbol || !intermediateSymbol || !endSymbol)
|
|
212
216
|
return null;
|
|
213
|
-
// Create Asset objects from address and symbol
|
|
214
|
-
const startAsset = { address: startToken, symbol: startSymbol };
|
|
215
|
-
const endAsset = { address: endToken, symbol: endSymbol };
|
|
216
217
|
// Find exchange hops for both segments of the two-hop route
|
|
217
218
|
// Keys are sorted token addresses for consistent lookup
|
|
218
|
-
const hop1Key =
|
|
219
|
-
const hop2Key =
|
|
220
|
-
const hop1 =
|
|
221
|
-
const hop2 =
|
|
219
|
+
const hop1Key = (0, sortUtils_1.canonicalSymbolKey)(startSymbol, intermediateSymbol);
|
|
220
|
+
const hop2Key = (0, sortUtils_1.canonicalSymbolKey)(intermediateSymbol, endSymbol);
|
|
221
|
+
const hop1 = directRouteMap.get(hop1Key);
|
|
222
|
+
const hop2 = directRouteMap.get(hop2Key);
|
|
222
223
|
// If either hop doesn't exist, this route is invalid
|
|
223
224
|
if (!hop1 || !hop2)
|
|
224
225
|
return null;
|
|
225
226
|
// Create canonical pair structure (alphabetical symbol ordering)
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const
|
|
227
|
+
const routeId = (0, sortUtils_1.canonicalSymbolKey)(startSymbol, endSymbol);
|
|
228
|
+
// Create Token objects from address and symbol
|
|
229
|
+
const startToken = { address: startAddr, symbol: startSymbol };
|
|
230
|
+
const endToken = { address: endAddr, symbol: endSymbol };
|
|
231
|
+
// Token array follows alphabetical ordering for consistency
|
|
232
|
+
const tokens = startSymbol <= endSymbol ? [startToken, endToken] : [endToken, startToken];
|
|
230
233
|
return {
|
|
231
|
-
id:
|
|
232
|
-
|
|
234
|
+
id: routeId,
|
|
235
|
+
tokens,
|
|
233
236
|
path: [hop1, hop2], // Preserves actual routing path for execution
|
|
234
237
|
};
|
|
235
238
|
}
|
|
236
|
-
exports.createTwoHopPair = createTwoHopPair;
|
|
237
239
|
/**
|
|
238
240
|
* Selects optimal routes from all candidates based on spread data or heuristics.
|
|
239
241
|
*
|
|
@@ -255,59 +257,58 @@ exports.createTwoHopPair = createTwoHopPair;
|
|
|
255
257
|
*
|
|
256
258
|
* @example
|
|
257
259
|
* ```typescript
|
|
258
|
-
* // Multiple routes for
|
|
260
|
+
* // Multiple routes for USDm-EURm pair
|
|
259
261
|
* const candidates = new Map([
|
|
260
|
-
* ['
|
|
261
|
-
* { path: [
|
|
262
|
-
* { path: [
|
|
263
|
-
* { path: [
|
|
262
|
+
* ['EURm-USDm', [
|
|
263
|
+
* { path: [USDm->CELO->EURm], costData: { totalCostPercent: 0.5 } },
|
|
264
|
+
* { path: [USDm->BRLm->EURm], costData: { totalCostPercent: 0.3 } },
|
|
265
|
+
* { path: [USDm->EURm] } // direct route, no cost data
|
|
264
266
|
* ]]
|
|
265
267
|
* ])
|
|
266
268
|
*
|
|
267
269
|
* const optimal = selectOptimalRoutes(candidates, false, assetMap)
|
|
268
|
-
* // Returns the
|
|
270
|
+
* // Returns the USDm->BRLm->EURm route (lowest cost: 0.3%)
|
|
269
271
|
* ```
|
|
270
272
|
*/
|
|
271
273
|
function selectOptimalRoutes(allRoutes, returnAllRoutes, addrToSymbol) {
|
|
272
274
|
const result = new Map();
|
|
273
|
-
for (const [
|
|
275
|
+
for (const [routeId, routes] of allRoutes) {
|
|
274
276
|
if (routes.length === 1) {
|
|
275
277
|
// Only one route available - use it directly
|
|
276
|
-
result.set(
|
|
278
|
+
result.set(routeId, routes[0]);
|
|
277
279
|
}
|
|
278
280
|
else if (returnAllRoutes) {
|
|
279
281
|
// Return all routes with unique keys (used for cache generation)
|
|
280
282
|
routes.forEach((route, index) => {
|
|
281
|
-
result.set(`${
|
|
283
|
+
result.set(`${routeId}_${index}`, route);
|
|
282
284
|
});
|
|
283
285
|
}
|
|
284
286
|
else {
|
|
285
287
|
// Multiple routes - select the best one using optimization logic
|
|
286
288
|
const bestRoute = selectBestRoute(routes, addrToSymbol);
|
|
287
|
-
result.set(
|
|
289
|
+
result.set(routeId, bestRoute);
|
|
288
290
|
}
|
|
289
291
|
}
|
|
290
292
|
return Array.from(result.values());
|
|
291
293
|
}
|
|
292
|
-
exports.selectOptimalRoutes = selectOptimalRoutes;
|
|
293
294
|
/**
|
|
294
|
-
* Selects the best route from candidates using
|
|
295
|
+
* Selects the best route from candidates using cost data or fallback heuristics.
|
|
295
296
|
*
|
|
296
297
|
* This function implements a sophisticated route selection algorithm with
|
|
297
298
|
* multiple optimization tiers:
|
|
298
299
|
*
|
|
299
|
-
* **Tier 1 -
|
|
300
|
-
* - Use routes with
|
|
301
|
-
* - Select route with lowest `
|
|
300
|
+
* **Tier 1 - Cost-Based Optimization** (Preferred):
|
|
301
|
+
* - Use routes with cost data (actual cost information)
|
|
302
|
+
* - Select route with lowest `totalCostPercent`
|
|
302
303
|
* - This provides the most cost-efficient trading
|
|
303
304
|
*
|
|
304
305
|
* **Tier 2 - Direct Route Preference** (Fallback):
|
|
305
|
-
* - If no
|
|
306
|
+
* - If no cost data available, prefer direct (single-hop) routes
|
|
306
307
|
* - Direct routes have lower execution risk and gas costs
|
|
307
308
|
*
|
|
308
309
|
* **Tier 3 - Major Stablecoin Preference** (Final Fallback):
|
|
309
310
|
* - For two-hop routes, prefer those going through major stablecoins
|
|
310
|
-
* - Major FX currencies like
|
|
311
|
+
* - Major FX currencies like USDm and EURm typically have better liquidity
|
|
311
312
|
*
|
|
312
313
|
* **Tier 4 - First Available** (Last Resort):
|
|
313
314
|
* - If no other heuristics apply, use the first route found
|
|
@@ -319,29 +320,27 @@ exports.selectOptimalRoutes = selectOptimalRoutes;
|
|
|
319
320
|
* @example
|
|
320
321
|
* ```typescript
|
|
321
322
|
* const candidates = [
|
|
322
|
-
* { path: [A->B->C],
|
|
323
|
-
* { path: [A->D->C],
|
|
324
|
-
* { path: [A->C] }, // direct route, no
|
|
323
|
+
* { path: [A->B->C], costData: { totalCostPercent: 0.8 } },
|
|
324
|
+
* { path: [A->D->C], costData: { totalCostPercent: 0.4 } }, // Winner: lowest cost
|
|
325
|
+
* { path: [A->C] }, // direct route, no cost data
|
|
325
326
|
* ]
|
|
326
327
|
*
|
|
327
328
|
* const best = selectBestRoute(candidates, assetMap)
|
|
328
|
-
* // Returns the A->D->C route (0.4%
|
|
329
|
+
* // Returns the A->D->C route (0.4% cost)
|
|
329
330
|
* ```
|
|
330
331
|
*/
|
|
331
332
|
function selectBestRoute(candidates, addrToSymbol) {
|
|
332
|
-
// Tier 1: Prefer routes with
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
335
|
-
return
|
|
336
|
-
? current
|
|
337
|
-
: best);
|
|
333
|
+
// Tier 1: Prefer routes with cost data (lowest cost wins)
|
|
334
|
+
const candidatesWithCost = candidates.filter(hasCostData);
|
|
335
|
+
if (candidatesWithCost.length > 0) {
|
|
336
|
+
return candidatesWithCost.reduce((best, current) => current.costData.totalCostPercent < best.costData.totalCostPercent ? current : best);
|
|
338
337
|
}
|
|
339
338
|
// Tier 2: Prefer direct routes (single-hop, lower risk)
|
|
340
339
|
const directRoute = candidates.find((c) => c.path.length === 1);
|
|
341
340
|
if (directRoute)
|
|
342
341
|
return directRoute;
|
|
343
342
|
// Tier 3: Prefer routes through major stablecoins (better liquidity)
|
|
344
|
-
const stablecoins = ['
|
|
343
|
+
const stablecoins = ['USDm', 'EURm', 'USDC', 'USDT'];
|
|
345
344
|
const routeWithStablecoin = candidates.find((candidate) => {
|
|
346
345
|
const intermediateToken = getIntermediateToken(candidate);
|
|
347
346
|
if (!intermediateToken)
|
|
@@ -352,7 +351,6 @@ function selectBestRoute(candidates, addrToSymbol) {
|
|
|
352
351
|
// Tier 4: Use first available route as last resort
|
|
353
352
|
return routeWithStablecoin || candidates[0];
|
|
354
353
|
}
|
|
355
|
-
exports.selectBestRoute = selectBestRoute;
|
|
356
354
|
/**
|
|
357
355
|
* Extracts the intermediate token address from a two-hop route.
|
|
358
356
|
* In a two-hop route A->B->C, this function finds token B (the intermediate).
|
|
@@ -360,13 +358,14 @@ exports.selectBestRoute = selectBestRoute;
|
|
|
360
358
|
function getIntermediateToken(route) {
|
|
361
359
|
// Find the common token between the two hops
|
|
362
360
|
const [hop1, hop2] = route.path;
|
|
363
|
-
|
|
361
|
+
const hop1Tokens = [hop1.token0, hop1.token1];
|
|
362
|
+
const hop2Tokens = [hop2.token0, hop2.token1];
|
|
363
|
+
return hop1Tokens.find((addr) => hop2Tokens.includes(addr));
|
|
364
364
|
}
|
|
365
|
-
exports.getIntermediateToken = getIntermediateToken;
|
|
366
365
|
/**
|
|
367
|
-
* Type guard to check if a Route has
|
|
366
|
+
* Type guard to check if a Route has cost data.
|
|
368
367
|
*/
|
|
369
|
-
function
|
|
370
|
-
return '
|
|
368
|
+
function hasCostData(pair) {
|
|
369
|
+
return 'costData' in pair && pair.costData !== undefined;
|
|
371
370
|
}
|
|
372
|
-
|
|
371
|
+
//# sourceMappingURL=routeUtils.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cachedRoutes = exports.getCachedRoutes = void 0;
|
|
4
|
+
// Re-export from consolidated cache
|
|
5
|
+
var routes_1 = require("../cache/routes");
|
|
6
|
+
Object.defineProperty(exports, "getCachedRoutes", { enumerable: true, get: function () { return routes_1.getCachedRoutes; } });
|
|
7
|
+
Object.defineProperty(exports, "cachedRoutes", { enumerable: true, get: function () { return routes_1.cachedRoutes; } });
|
|
8
|
+
//# sourceMappingURL=routes.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Sorts two token addresses to match the smart contract's _sortTokens behavior.
|
|
4
|
+
* Compares addresses as numeric values (BigInt), matching Solidity's address comparison.
|
|
5
|
+
*
|
|
6
|
+
* Solidity reference:
|
|
7
|
+
* ```solidity
|
|
8
|
+
* function _sortTokens(address a, address b) private pure returns (address, address) {
|
|
9
|
+
* return (a < b) ? (a, b) : (b, a);
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function sortTokenAddresses(tokenA: Address, tokenB: Address): [Address, Address];
|
|
14
|
+
/**
|
|
15
|
+
* Creates a canonical route ID from two addresses.
|
|
16
|
+
* Uses numeric address comparison to match contract behavior.
|
|
17
|
+
*/
|
|
18
|
+
export declare function canonicalAddressKey(addressA: Address, addressB: Address, separator?: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a canonical pair key from two symbols.
|
|
21
|
+
* Uses standard string comparison for human-readable IDs.
|
|
22
|
+
*/
|
|
23
|
+
export declare function canonicalSymbolKey(symbolA: string, symbolB: string, separator?: string): string;
|
|
24
|
+
//# sourceMappingURL=sortUtils.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortTokenAddresses = sortTokenAddresses;
|
|
4
|
+
exports.canonicalAddressKey = canonicalAddressKey;
|
|
5
|
+
exports.canonicalSymbolKey = canonicalSymbolKey;
|
|
6
|
+
/**
|
|
7
|
+
* Sorts two token addresses to match the smart contract's _sortTokens behavior.
|
|
8
|
+
* Compares addresses as numeric values (BigInt), matching Solidity's address comparison.
|
|
9
|
+
*
|
|
10
|
+
* Solidity reference:
|
|
11
|
+
* ```solidity
|
|
12
|
+
* function _sortTokens(address a, address b) private pure returns (address, address) {
|
|
13
|
+
* return (a < b) ? (a, b) : (b, a);
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
function sortTokenAddresses(tokenA, tokenB) {
|
|
18
|
+
return BigInt(tokenA) < BigInt(tokenB)
|
|
19
|
+
? [tokenA, tokenB]
|
|
20
|
+
: [tokenB, tokenA];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a canonical route ID from two addresses.
|
|
24
|
+
* Uses numeric address comparison to match contract behavior.
|
|
25
|
+
*/
|
|
26
|
+
function canonicalAddressKey(addressA, addressB, separator = '-') {
|
|
27
|
+
const [first, second] = sortTokenAddresses(addressA, addressB);
|
|
28
|
+
return `${first}${separator}${second}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a canonical pair key from two symbols.
|
|
32
|
+
* Uses standard string comparison for human-readable IDs.
|
|
33
|
+
*/
|
|
34
|
+
function canonicalSymbolKey(symbolA, symbolB, separator = '-') {
|
|
35
|
+
return symbolA < symbolB
|
|
36
|
+
? `${symbolA}${separator}${symbolB}`
|
|
37
|
+
: `${symbolB}${separator}${symbolA}`;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=sortUtils.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TOKEN_ADDRESSES_BY_CHAIN = exports.findTokenBySymbol = exports.getTokenAddress = exports.getCachedTokensSync = exports.getCachedTokens = exports.cachedTokens = exports.TokenSymbol = void 0;
|
|
4
|
+
// Re-export from consolidated cache
|
|
5
|
+
var tokens_1 = require("../cache/tokens");
|
|
6
|
+
Object.defineProperty(exports, "TokenSymbol", { enumerable: true, get: function () { return tokens_1.TokenSymbol; } });
|
|
7
|
+
Object.defineProperty(exports, "cachedTokens", { enumerable: true, get: function () { return tokens_1.cachedTokens; } });
|
|
8
|
+
Object.defineProperty(exports, "getCachedTokens", { enumerable: true, get: function () { return tokens_1.getCachedTokens; } });
|
|
9
|
+
Object.defineProperty(exports, "getCachedTokensSync", { enumerable: true, get: function () { return tokens_1.getCachedTokensSync; } });
|
|
10
|
+
Object.defineProperty(exports, "getTokenAddress", { enumerable: true, get: function () { return tokens_1.getTokenAddress; } });
|
|
11
|
+
Object.defineProperty(exports, "findTokenBySymbol", { enumerable: true, get: function () { return tokens_1.findTokenBySymbol; } });
|
|
12
|
+
Object.defineProperty(exports, "TOKEN_ADDRESSES_BY_CHAIN", { enumerable: true, get: function () { return tokens_1.TOKEN_ADDRESSES_BY_CHAIN; } });
|
|
13
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { TradingLimit, TradingLimitsConfigV1, TradingLimitsStateV1, TradingLimitsConfigV2, TradingLimitsStateV2 } from '../core/types';
|
|
2
|
+
/**
|
|
3
|
+
* Compute limit ID for Broker (V1) trading limits.
|
|
4
|
+
* limitId = exchangeId XOR bytes32(uint256(uint160(token)))
|
|
5
|
+
*
|
|
6
|
+
* @param exchangeId - The exchange ID (bytes32)
|
|
7
|
+
* @param token - The token address
|
|
8
|
+
* @returns The limit ID as hex string
|
|
9
|
+
*/
|
|
10
|
+
export declare function computeLimitId(exchangeId: string, token: string): `0x${string}`;
|
|
11
|
+
/**
|
|
12
|
+
* Calculate trading limits from V1 config and state (Broker/Virtual pools).
|
|
13
|
+
* Returns human-friendly TradingLimit objects with maxIn/maxOut/until.
|
|
14
|
+
*
|
|
15
|
+
* @param config - V1 trading limits configuration
|
|
16
|
+
* @param state - V1 trading limits state
|
|
17
|
+
* @param asset - Token address
|
|
18
|
+
* @param tokenDecimals - Token decimals for consumer reference
|
|
19
|
+
* @returns Array of TradingLimit objects
|
|
20
|
+
*/
|
|
21
|
+
export declare function calculateTradingLimitsV1(config: TradingLimitsConfigV1, state: TradingLimitsStateV1, asset: string, tokenDecimals: number): TradingLimit[];
|
|
22
|
+
/**
|
|
23
|
+
* Calculate trading limits from V2 config and state (FPMM pools).
|
|
24
|
+
* V2 uses fixed timeframes: 5 min for L0, 1 day for L1.
|
|
25
|
+
* Values are stored with 15 decimals precision.
|
|
26
|
+
*
|
|
27
|
+
* @param config - V2 trading limits configuration
|
|
28
|
+
* @param state - V2 trading limits state
|
|
29
|
+
* @param asset - Token address
|
|
30
|
+
* @returns Array of TradingLimit objects
|
|
31
|
+
*/
|
|
32
|
+
export declare function calculateTradingLimitsV2(config: TradingLimitsConfigV2, state: TradingLimitsStateV2, asset: string): TradingLimit[];
|
|
33
|
+
/**
|
|
34
|
+
* Check if any trading limits are configured (flags > 0 for V1, or limit0/limit1 > 0 for V2)
|
|
35
|
+
*/
|
|
36
|
+
export declare function hasConfiguredLimitsV1(config: TradingLimitsConfigV1): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Check if any trading limits are configured for V2
|
|
39
|
+
*/
|
|
40
|
+
export declare function hasConfiguredLimitsV2(config: TradingLimitsConfigV2): boolean;
|
|
41
|
+
//# sourceMappingURL=tradingLimits.d.ts.map
|