@mento-protocol/mento-sdk 3.2.2 → 3.2.3
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/cjs/ChainClient.d.ts +9 -0
- package/dist/cjs/ChainClient.js +58 -0
- package/dist/cjs/TestChainClient.d.ts +7 -0
- package/dist/cjs/TestChainClient.js +41 -0
- package/dist/cjs/constants/addresses.d.ts +4 -0
- package/dist/cjs/constants/addresses.js +59 -0
- package/dist/cjs/constants/currencies.d.ts +5 -0
- package/dist/cjs/constants/currencies.js +29 -0
- package/dist/cjs/constants/index.d.ts +4 -0
- package/dist/{services/borrow → cjs/constants}/index.js +4 -4
- package/dist/cjs/constants/tokens.11142220.d.ts +2 -0
- package/dist/cjs/constants/tokens.11142220.js +128 -0
- package/dist/cjs/constants/tokens.42220.d.ts +2 -0
- package/dist/cjs/constants/tokens.42220.js +128 -0
- package/dist/cjs/constants/tokens.d.ts +65 -0
- package/dist/cjs/constants/tokens.js +170 -0
- package/dist/cjs/constants/tradablePairs.11142220.d.ts +2 -0
- package/dist/cjs/constants/tradablePairs.11142220.js +7391 -0
- package/dist/cjs/constants/tradablePairs.42220.d.ts +2 -0
- package/dist/cjs/constants/tradablePairs.42220.js +7391 -0
- package/dist/cjs/constants/tradablePairs.d.ts +16 -0
- package/dist/cjs/constants/tradablePairs.js +53 -0
- package/dist/cjs/enums/chainId.d.ts +4 -0
- package/dist/{core/constants → cjs/enums}/chainId.js +1 -4
- package/dist/cjs/enums/index.d.ts +3 -0
- package/dist/{services/liquidity → cjs/enums}/index.js +3 -2
- package/dist/cjs/enums/proposalState.d.ts +10 -0
- package/dist/cjs/enums/proposalState.js +14 -0
- package/dist/cjs/enums/tradingMode.d.ts +17 -0
- package/dist/cjs/enums/tradingMode.js +21 -0
- package/dist/cjs/governance.d.ts +62 -0
- package/dist/cjs/governance.js +151 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/{core/constants → cjs}/index.js +7 -6
- package/dist/cjs/interfaces/IChainClient.d.ts +6 -0
- package/dist/{core/types/route.js → cjs/interfaces/IChainClient.js} +0 -1
- package/dist/cjs/interfaces/index.d.ts +4 -0
- package/dist/{core/errors → cjs/interfaces}/index.js +4 -4
- package/dist/cjs/interfaces/tradingLimit.d.ts +7 -0
- package/dist/{core/types/token.js → cjs/interfaces/tradingLimit.js} +0 -1
- package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +10 -0
- package/dist/{core/types/borrow.js → cjs/interfaces/tradingLimitsConfig.js} +0 -1
- package/dist/cjs/interfaces/tradingLimitsState.d.ts +9 -0
- package/dist/{core/types/provider.js → cjs/interfaces/tradingLimitsState.js} +0 -1
- package/dist/cjs/limits.d.ts +33 -0
- package/dist/cjs/limits.js +130 -0
- package/dist/cjs/mento.d.ts +287 -0
- package/dist/cjs/mento.js +699 -0
- package/dist/{utils → cjs}/routeUtils.d.ts +93 -84
- package/dist/{utils → cjs}/routeUtils.js +124 -123
- package/dist/cjs/types/contractAddressMap.d.ts +4 -0
- package/dist/cjs/types/contractAddressMap.js +2 -0
- package/dist/cjs/types/contractAddresses.d.ts +23 -0
- package/dist/cjs/types/contractAddresses.js +2 -0
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/{services/pools → cjs/types}/index.js +2 -2
- package/dist/cjs/utils.d.ts +80 -0
- package/dist/cjs/utils.js +177 -0
- package/dist/esm/ChainClient.d.ts +9 -0
- package/dist/esm/ChainClient.js +54 -0
- package/dist/esm/TestChainClient.d.ts +7 -0
- package/dist/esm/TestChainClient.js +37 -0
- package/dist/esm/constants/addresses.d.ts +4 -0
- package/dist/esm/constants/addresses.js +55 -0
- package/dist/esm/constants/currencies.d.ts +5 -0
- package/dist/esm/constants/currencies.js +26 -0
- package/dist/esm/constants/index.d.ts +4 -0
- package/dist/esm/constants/index.js +4 -0
- package/dist/esm/constants/tokens.11142220.d.ts +2 -0
- package/dist/esm/constants/tokens.11142220.js +125 -0
- package/dist/esm/constants/tokens.42220.d.ts +2 -0
- package/dist/esm/constants/tokens.42220.js +125 -0
- package/dist/esm/constants/tokens.d.ts +65 -0
- package/dist/esm/constants/tokens.js +142 -0
- package/dist/esm/constants/tradablePairs.11142220.d.ts +2 -0
- package/dist/esm/constants/tradablePairs.11142220.js +7388 -0
- package/dist/esm/constants/tradablePairs.42220.d.ts +2 -0
- package/dist/esm/constants/tradablePairs.42220.js +7388 -0
- package/dist/esm/constants/tradablePairs.d.ts +16 -0
- package/dist/esm/constants/tradablePairs.js +26 -0
- package/dist/esm/enums/chainId.d.ts +4 -0
- package/dist/esm/{core/constants → enums}/chainId.js +0 -2
- package/dist/esm/enums/index.d.ts +3 -0
- package/dist/esm/enums/index.js +3 -0
- package/dist/esm/enums/proposalState.d.ts +10 -0
- package/dist/esm/enums/proposalState.js +11 -0
- package/dist/esm/enums/tradingMode.d.ts +17 -0
- package/dist/esm/enums/tradingMode.js +18 -0
- package/dist/esm/governance.d.ts +62 -0
- package/dist/esm/governance.js +147 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +6 -138
- package/dist/esm/interfaces/IChainClient.d.ts +6 -0
- package/dist/esm/interfaces/index.d.ts +4 -0
- package/dist/esm/interfaces/index.js +4 -0
- package/dist/esm/interfaces/tradingLimit.d.ts +7 -0
- package/dist/esm/interfaces/tradingLimitsConfig.d.ts +10 -0
- package/dist/esm/interfaces/tradingLimitsState.d.ts +9 -0
- package/dist/esm/limits.d.ts +33 -0
- package/dist/esm/limits.js +123 -0
- package/dist/esm/mento.d.ts +287 -0
- package/dist/esm/mento.js +671 -0
- package/dist/esm/routeUtils.d.ts +304 -0
- package/dist/esm/{utils/routeUtils.js → routeUtils.js} +116 -115
- package/dist/esm/types/contractAddressMap.d.ts +4 -0
- package/dist/esm/types/contractAddresses.d.ts +23 -0
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/utils.d.ts +80 -0
- package/dist/esm/utils.js +162 -0
- package/package.json +1 -1
- package/dist/cache/routes.d.ts +0 -13
- package/dist/cache/routes.js +0 -13733
- package/dist/cache/tokens.d.ts +0 -68
- package/dist/cache/tokens.js +0 -446
- package/dist/core/abis/activePool.d.ts +0 -2
- package/dist/core/abis/activePool.js +0 -14
- package/dist/core/abis/addressesRegistry.d.ts +0 -2
- package/dist/core/abis/addressesRegistry.js +0 -26
- package/dist/core/abis/bipoolmanager.d.ts +0 -34
- package/dist/core/abis/bipoolmanager.js +0 -72
- package/dist/core/abis/borrowerOperations.d.ts +0 -9
- package/dist/core/abis/borrowerOperations.js +0 -89
- package/dist/core/abis/breakerbox.d.ts +0 -13
- package/dist/core/abis/breakerbox.js +0 -8
- package/dist/core/abis/broker.d.ts +0 -2
- package/dist/core/abis/broker.js +0 -9
- package/dist/core/abis/erc20.d.ts +0 -9
- package/dist/core/abis/erc20.js +0 -21
- package/dist/core/abis/fpmm.d.ts +0 -270
- package/dist/core/abis/fpmm.js +0 -49
- package/dist/core/abis/fpmmFactory.d.ts +0 -85
- package/dist/core/abis/fpmmFactory.js +0 -26
- package/dist/core/abis/hintHelpers.d.ts +0 -2
- package/dist/core/abis/hintHelpers.js +0 -14
- package/dist/core/abis/index.d.ts +0 -22
- package/dist/core/abis/index.js +0 -38
- package/dist/core/abis/liquidityStrategy.d.ts +0 -132
- package/dist/core/abis/liquidityStrategy.js +0 -10
- package/dist/core/abis/multiTroveGetter.d.ts +0 -8
- package/dist/core/abis/multiTroveGetter.js +0 -15
- package/dist/core/abis/priceFeed.d.ts +0 -7
- package/dist/core/abis/priceFeed.js +0 -16
- package/dist/core/abis/pricingmodule.d.ts +0 -2
- package/dist/core/abis/pricingmodule.js +0 -6
- package/dist/core/abis/reserve.d.ts +0 -3
- package/dist/core/abis/reserve.js +0 -18
- package/dist/core/abis/router.d.ts +0 -521
- package/dist/core/abis/router.js +0 -45
- package/dist/core/abis/sortedTroves.d.ts +0 -2
- package/dist/core/abis/sortedTroves.js +0 -15
- package/dist/core/abis/systemParams.d.ts +0 -2
- package/dist/core/abis/systemParams.js +0 -14
- package/dist/core/abis/troveManager.d.ts +0 -2
- package/dist/core/abis/troveManager.js +0 -27
- package/dist/core/abis/troveNFT.d.ts +0 -2
- package/dist/core/abis/troveNFT.js +0 -9
- package/dist/core/abis/virtualPool.d.ts +0 -50
- package/dist/core/abis/virtualPool.js +0 -11
- package/dist/core/abis/virtualPoolFactory.d.ts +0 -59
- package/dist/core/abis/virtualPoolFactory.js +0 -17
- package/dist/core/constants/addresses.d.ts +0 -18
- package/dist/core/constants/addresses.js +0 -113
- package/dist/core/constants/borrowConstants.d.ts +0 -10
- package/dist/core/constants/borrowConstants.js +0 -16
- package/dist/core/constants/borrowRegistries.d.ts +0 -7
- package/dist/core/constants/borrowRegistries.js +0 -30
- package/dist/core/constants/chainId.d.ts +0 -7
- package/dist/core/constants/contractNames.d.ts +0 -21
- package/dist/core/constants/contractNames.js +0 -24
- package/dist/core/constants/index.d.ts +0 -6
- package/dist/core/errors/base.d.ts +0 -8
- package/dist/core/errors/base.js +0 -17
- package/dist/core/errors/index.d.ts +0 -4
- package/dist/core/errors/oracle.d.ts +0 -9
- package/dist/core/errors/oracle.js +0 -15
- package/dist/core/errors/router.d.ts +0 -14
- package/dist/core/errors/router.js +0 -24
- package/dist/core/types/borrow.d.ts +0 -87
- package/dist/core/types/contractAddresses.d.ts +0 -42
- package/dist/core/types/contractAddresses.js +0 -3
- package/dist/core/types/index.d.ts +0 -10
- package/dist/core/types/index.js +0 -26
- package/dist/core/types/liquidity.d.ts +0 -194
- package/dist/core/types/liquidity.js +0 -3
- package/dist/core/types/pool.d.ts +0 -208
- package/dist/core/types/pool.js +0 -14
- package/dist/core/types/provider.d.ts +0 -45
- package/dist/core/types/route.d.ts +0 -62
- package/dist/core/types/token.d.ts +0 -21
- package/dist/core/types/tradingLimits.d.ts +0 -91
- package/dist/core/types/tradingLimits.js +0 -3
- package/dist/core/types/tradingMode.d.ts +0 -24
- package/dist/core/types/tradingMode.js +0 -31
- package/dist/core/types/transaction.d.ts +0 -45
- package/dist/core/types/transaction.js +0 -3
- package/dist/esm/cache/routes.js +0 -13728
- package/dist/esm/cache/tokens.js +0 -438
- package/dist/esm/core/abis/activePool.js +0 -10
- package/dist/esm/core/abis/addressesRegistry.js +0 -22
- package/dist/esm/core/abis/bipoolmanager.js +0 -68
- package/dist/esm/core/abis/borrowerOperations.js +0 -85
- package/dist/esm/core/abis/breakerbox.js +0 -4
- package/dist/esm/core/abis/broker.js +0 -5
- package/dist/esm/core/abis/erc20.js +0 -17
- package/dist/esm/core/abis/fpmm.js +0 -45
- package/dist/esm/core/abis/fpmmFactory.js +0 -22
- package/dist/esm/core/abis/hintHelpers.js +0 -10
- package/dist/esm/core/abis/index.js +0 -21
- package/dist/esm/core/abis/liquidityStrategy.js +0 -6
- package/dist/esm/core/abis/multiTroveGetter.js +0 -11
- package/dist/esm/core/abis/priceFeed.js +0 -12
- package/dist/esm/core/abis/pricingmodule.js +0 -2
- package/dist/esm/core/abis/reserve.js +0 -14
- package/dist/esm/core/abis/router.js +0 -41
- package/dist/esm/core/abis/sortedTroves.js +0 -11
- package/dist/esm/core/abis/systemParams.js +0 -10
- package/dist/esm/core/abis/troveManager.js +0 -23
- package/dist/esm/core/abis/troveNFT.js +0 -5
- package/dist/esm/core/abis/virtualPool.js +0 -7
- package/dist/esm/core/abis/virtualPoolFactory.js +0 -13
- package/dist/esm/core/constants/addresses.js +0 -107
- package/dist/esm/core/constants/borrowConstants.js +0 -12
- package/dist/esm/core/constants/borrowRegistries.js +0 -25
- package/dist/esm/core/constants/contractNames.js +0 -20
- package/dist/esm/core/constants/index.js +0 -5
- package/dist/esm/core/errors/base.js +0 -12
- package/dist/esm/core/errors/index.js +0 -3
- package/dist/esm/core/errors/oracle.js +0 -10
- package/dist/esm/core/errors/router.js +0 -18
- package/dist/esm/core/types/index.js +0 -9
- package/dist/esm/core/types/pool.js +0 -10
- package/dist/esm/core/types/tradingLimits.js +0 -1
- package/dist/esm/core/types/tradingMode.js +0 -26
- package/dist/esm/core/types/transaction.js +0 -1
- package/dist/esm/package.json +0 -1
- package/dist/esm/services/borrow/BorrowService.js +0 -455
- package/dist/esm/services/borrow/borrowHelpers.js +0 -3
- package/dist/esm/services/borrow/borrowMath.js +0 -127
- package/dist/esm/services/borrow/index.js +0 -3
- package/dist/esm/services/borrow/internal/borrowApprovalService.js +0 -48
- package/dist/esm/services/borrow/internal/borrowContextStore.js +0 -35
- package/dist/esm/services/borrow/internal/borrowErc20.js +0 -38
- package/dist/esm/services/borrow/internal/borrowHints.js +0 -27
- package/dist/esm/services/borrow/internal/borrowPositionParser.js +0 -82
- package/dist/esm/services/borrow/internal/borrowReadService.js +0 -271
- package/dist/esm/services/borrow/internal/borrowRegistryReader.js +0 -108
- package/dist/esm/services/borrow/internal/borrowTransactionService.js +0 -271
- package/dist/esm/services/borrow/internal/borrowTypes.js +0 -1
- package/dist/esm/services/borrow/internal/borrowValidation.js +0 -89
- package/dist/esm/services/index.js +0 -8
- package/dist/esm/services/liquidity/LiquidityService.js +0 -163
- package/dist/esm/services/liquidity/basicLiquidity.js +0 -162
- package/dist/esm/services/liquidity/index.js +0 -1
- package/dist/esm/services/liquidity/liquidityHelpers.js +0 -95
- package/dist/esm/services/liquidity/rebalance.js +0 -59
- package/dist/esm/services/liquidity/zapHelpers.js +0 -120
- package/dist/esm/services/liquidity/zapIn.js +0 -112
- package/dist/esm/services/liquidity/zapOut.js +0 -248
- package/dist/esm/services/pools/PoolService.js +0 -204
- package/dist/esm/services/pools/index.js +0 -1
- package/dist/esm/services/pools/poolDetails.js +0 -209
- package/dist/esm/services/pools/poolDiscovery.js +0 -112
- package/dist/esm/services/pools/rebalancePreview.js +0 -181
- package/dist/esm/services/quotes/QuoteService.js +0 -85
- package/dist/esm/services/quotes/index.js +0 -1
- package/dist/esm/services/routes/RouteService.js +0 -268
- package/dist/esm/services/routes/index.js +0 -1
- package/dist/esm/services/swap/SwapService.js +0 -247
- package/dist/esm/services/swap/index.js +0 -1
- package/dist/esm/services/tokens/index.js +0 -1
- package/dist/esm/services/tokens/tokenService.js +0 -285
- package/dist/esm/services/trading/TradingLimitsService.js +0 -154
- package/dist/esm/services/trading/TradingService.js +0 -196
- package/dist/esm/services/trading/index.js +0 -2
- package/dist/esm/utils/chainConfig.js +0 -118
- package/dist/esm/utils/costUtils.js +0 -56
- package/dist/esm/utils/deadline.js +0 -22
- package/dist/esm/utils/index.js +0 -9
- package/dist/esm/utils/multicall.js +0 -47
- package/dist/esm/utils/pathEncoder.js +0 -69
- package/dist/esm/utils/rateFeed.js +0 -23
- package/dist/esm/utils/retry.js +0 -24
- package/dist/esm/utils/routes.js +0 -2
- package/dist/esm/utils/sortUtils.js +0 -33
- package/dist/esm/utils/tokens.js +0 -2
- package/dist/esm/utils/tradingLimits.js +0 -163
- package/dist/esm/utils/validation.js +0 -30
- package/dist/index.d.ts +0 -101
- package/dist/index.js +0 -158
- package/dist/services/borrow/BorrowService.d.ts +0 -381
- package/dist/services/borrow/BorrowService.js +0 -460
- package/dist/services/borrow/borrowHelpers.d.ts +0 -4
- package/dist/services/borrow/borrowHelpers.js +0 -13
- package/dist/services/borrow/borrowMath.d.ts +0 -21
- package/dist/services/borrow/borrowMath.js +0 -137
- package/dist/services/borrow/index.d.ts +0 -4
- package/dist/services/borrow/internal/borrowApprovalService.d.ts +0 -14
- package/dist/services/borrow/internal/borrowApprovalService.js +0 -53
- package/dist/services/borrow/internal/borrowContextStore.d.ts +0 -11
- package/dist/services/borrow/internal/borrowContextStore.js +0 -40
- package/dist/services/borrow/internal/borrowErc20.d.ts +0 -5
- package/dist/services/borrow/internal/borrowErc20.js +0 -43
- package/dist/services/borrow/internal/borrowHints.d.ts +0 -7
- package/dist/services/borrow/internal/borrowHints.js +0 -31
- package/dist/services/borrow/internal/borrowPositionParser.d.ts +0 -4
- package/dist/services/borrow/internal/borrowPositionParser.js +0 -87
- package/dist/services/borrow/internal/borrowReadService.d.ts +0 -31
- package/dist/services/borrow/internal/borrowReadService.js +0 -276
- package/dist/services/borrow/internal/borrowRegistryReader.d.ts +0 -5
- package/dist/services/borrow/internal/borrowRegistryReader.js +0 -113
- package/dist/services/borrow/internal/borrowTransactionService.d.ts +0 -23
- package/dist/services/borrow/internal/borrowTransactionService.js +0 -276
- package/dist/services/borrow/internal/borrowTypes.d.ts +0 -15
- package/dist/services/borrow/internal/borrowTypes.js +0 -3
- package/dist/services/borrow/internal/borrowValidation.d.ts +0 -14
- package/dist/services/borrow/internal/borrowValidation.js +0 -104
- package/dist/services/index.d.ts +0 -9
- package/dist/services/index.js +0 -25
- package/dist/services/liquidity/LiquidityService.d.ts +0 -139
- package/dist/services/liquidity/LiquidityService.js +0 -168
- package/dist/services/liquidity/basicLiquidity.d.ts +0 -11
- package/dist/services/liquidity/basicLiquidity.js +0 -172
- package/dist/services/liquidity/index.d.ts +0 -2
- package/dist/services/liquidity/liquidityHelpers.d.ts +0 -19
- package/dist/services/liquidity/liquidityHelpers.js +0 -104
- package/dist/services/liquidity/rebalance.d.ts +0 -6
- package/dist/services/liquidity/rebalance.js +0 -64
- package/dist/services/liquidity/zapHelpers.d.ts +0 -66
- package/dist/services/liquidity/zapHelpers.js +0 -129
- package/dist/services/liquidity/zapIn.d.ts +0 -18
- package/dist/services/liquidity/zapIn.js +0 -119
- package/dist/services/liquidity/zapOut.d.ts +0 -9
- package/dist/services/liquidity/zapOut.js +0 -255
- package/dist/services/pools/PoolService.d.ts +0 -69
- package/dist/services/pools/PoolService.js +0 -209
- package/dist/services/pools/index.d.ts +0 -2
- package/dist/services/pools/poolDetails.d.ts +0 -13
- package/dist/services/pools/poolDetails.js +0 -216
- package/dist/services/pools/poolDiscovery.d.ts +0 -12
- package/dist/services/pools/poolDiscovery.js +0 -117
- package/dist/services/pools/rebalancePreview.d.ts +0 -5
- package/dist/services/pools/rebalancePreview.js +0 -186
- package/dist/services/quotes/QuoteService.d.ts +0 -51
- package/dist/services/quotes/QuoteService.js +0 -91
- package/dist/services/quotes/index.d.ts +0 -2
- package/dist/services/quotes/index.js +0 -18
- package/dist/services/routes/RouteService.d.ts +0 -117
- package/dist/services/routes/RouteService.js +0 -306
- package/dist/services/routes/index.d.ts +0 -2
- package/dist/services/routes/index.js +0 -18
- package/dist/services/swap/SwapService.d.ts +0 -198
- package/dist/services/swap/SwapService.js +0 -252
- package/dist/services/swap/index.d.ts +0 -2
- package/dist/services/swap/index.js +0 -18
- package/dist/services/tokens/index.d.ts +0 -2
- package/dist/services/tokens/index.js +0 -18
- package/dist/services/tokens/tokenService.d.ts +0 -55
- package/dist/services/tokens/tokenService.js +0 -290
- package/dist/services/trading/TradingLimitsService.d.ts +0 -38
- package/dist/services/trading/TradingLimitsService.js +0 -159
- package/dist/services/trading/TradingService.d.ts +0 -113
- package/dist/services/trading/TradingService.js +0 -201
- package/dist/services/trading/index.d.ts +0 -3
- package/dist/services/trading/index.js +0 -19
- package/dist/utils/chainConfig.d.ts +0 -16
- package/dist/utils/chainConfig.js +0 -123
- package/dist/utils/costUtils.d.ts +0 -12
- package/dist/utils/costUtils.js +0 -60
- package/dist/utils/deadline.d.ts +0 -21
- package/dist/utils/deadline.js +0 -26
- package/dist/utils/index.d.ts +0 -10
- package/dist/utils/index.js +0 -26
- package/dist/utils/multicall.d.ts +0 -30
- package/dist/utils/multicall.js +0 -52
- package/dist/utils/pathEncoder.d.ts +0 -34
- package/dist/utils/pathEncoder.js +0 -73
- package/dist/utils/rateFeed.d.ts +0 -18
- package/dist/utils/rateFeed.js +0 -27
- package/dist/utils/retry.d.ts +0 -12
- package/dist/utils/retry.js +0 -28
- package/dist/utils/routes.d.ts +0 -3
- package/dist/utils/routes.js +0 -8
- package/dist/utils/sortUtils.d.ts +0 -24
- package/dist/utils/sortUtils.js +0 -39
- package/dist/utils/tokens.d.ts +0 -2
- package/dist/utils/tokens.js +0 -13
- package/dist/utils/tradingLimits.d.ts +0 -41
- package/dist/utils/tradingLimits.js +0 -171
- package/dist/utils/validation.d.ts +0 -19
- package/dist/utils/validation.js +0 -34
- /package/dist/esm/{core/types/borrow.js → interfaces/IChainClient.js} +0 -0
- /package/dist/esm/{core/types/contractAddresses.js → interfaces/tradingLimit.js} +0 -0
- /package/dist/esm/{core/types/liquidity.js → interfaces/tradingLimitsConfig.js} +0 -0
- /package/dist/esm/{core/types/provider.js → interfaces/tradingLimitsState.js} +0 -0
- /package/dist/esm/{core/types/route.js → types/contractAddressMap.js} +0 -0
- /package/dist/esm/{core/types/token.js → types/contractAddresses.js} +0 -0
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.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");
|
|
3
|
+
exports.hasSpreadData = exports.getIntermediateToken = exports.selectBestRoute = exports.selectOptimalRoutes = exports.createTwoHopPair = exports.generateAllRoutes = exports.buildConnectivityStructures = void 0;
|
|
11
4
|
/**
|
|
12
5
|
* Builds the connectivity data structures needed for route generation.
|
|
13
6
|
*
|
|
@@ -18,23 +11,23 @@ const sortUtils_1 = require("./sortUtils");
|
|
|
18
11
|
*
|
|
19
12
|
* ```
|
|
20
13
|
* Input: TradablePairs = [
|
|
21
|
-
* { id: '
|
|
22
|
-
* { id: 'CELO-
|
|
14
|
+
* { id: 'cUSD-CELO', assets: [cUSD, CELO], path: [exchange1_CELO_cUSD] },
|
|
15
|
+
* { id: 'CELO-cEUR', assets: [CELO, cEUR], path: [exchange2_CELO_cEUR] }
|
|
23
16
|
* ]
|
|
24
17
|
*
|
|
25
18
|
* Step 1 - Build addrToSymbol map:
|
|
26
|
-
*
|
|
19
|
+
* cUSD.address → 'cUSD'
|
|
27
20
|
* CELO.address → 'CELO'
|
|
28
|
-
*
|
|
21
|
+
* cEUR.address → 'cEUR'
|
|
29
22
|
*
|
|
30
23
|
* Step 2 - Build directPathMap (sorted alphabetically for consistency):
|
|
31
|
-
* 'CELO_addr-
|
|
32
|
-
* 'CELO_addr-
|
|
24
|
+
* 'CELO_addr-cEUR_addr' → exchange2_CELO_cEUR
|
|
25
|
+
* 'CELO_addr-cUSD_addr' → exchange1_CELO_cUSD
|
|
33
26
|
*
|
|
34
27
|
* Step 3 - Build bidirectional tokenGraph:
|
|
35
|
-
*
|
|
36
|
-
* CELO.address → Set([
|
|
37
|
-
*
|
|
28
|
+
* cUSD.address → Set([CELO.address])
|
|
29
|
+
* CELO.address → Set([cUSD.address, cEUR.address])
|
|
30
|
+
* cEUR.address → Set([CELO.address])
|
|
38
31
|
* ```
|
|
39
32
|
*
|
|
40
33
|
* **Result**: We can now efficiently answer:
|
|
@@ -42,57 +35,60 @@ const sortUtils_1 = require("./sortUtils");
|
|
|
42
35
|
* - "What exchange connects tokens X and Y?" → directPathMap.get(sortedAddressPairKey)
|
|
43
36
|
* - "What tokens can I reach from token X?" → tokenGraph.get(X)
|
|
44
37
|
*
|
|
45
|
-
* @param
|
|
38
|
+
* @param directPairs - Array of direct trading pairs
|
|
46
39
|
* @returns Connectivity data structure for efficient route generation
|
|
47
40
|
*
|
|
48
41
|
* @example
|
|
49
42
|
* ```typescript
|
|
50
43
|
* const directPairs = [
|
|
51
|
-
* { id: '
|
|
52
|
-
* { id: 'CELO-
|
|
44
|
+
* { id: 'cUSD-CELO', assets: [cUSD, CELO], path: [exchange1] },
|
|
45
|
+
* { id: 'CELO-cEUR', assets: [CELO, cEUR], path: [exchange2] }
|
|
53
46
|
* ]
|
|
54
47
|
*
|
|
55
48
|
* const connectivityData = buildConnectivityStructures(directPairs)
|
|
56
49
|
*
|
|
57
50
|
* // Now we can efficiently find routes:
|
|
58
|
-
* // 1. Check if
|
|
59
|
-
* // 2. Check if CELO connects to
|
|
60
|
-
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-
|
|
61
|
-
* // Result: Found route
|
|
51
|
+
* // 1. Check if cUSD connects to anything: connectivityData.tokenGraph.get(cUSD.address) → [CELO.address]
|
|
52
|
+
* // 2. Check if CELO connects to cEUR: connectivityData.tokenGraph.get(CELO.address) → [cUSD.address, cEUR.address] ✓
|
|
53
|
+
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-cEUR_addr') → exchange2_CELO_cEUR
|
|
54
|
+
* // Result: Found route cUSD → CELO → cEUR with exchange details
|
|
62
55
|
* ```
|
|
63
56
|
*/
|
|
64
|
-
function buildConnectivityStructures(
|
|
57
|
+
function buildConnectivityStructures(directPairs) {
|
|
65
58
|
const addrToSymbol = new Map();
|
|
66
|
-
const
|
|
59
|
+
const directPathMap = new Map();
|
|
67
60
|
const tokenGraph = new Map();
|
|
68
|
-
for (const
|
|
69
|
-
const [
|
|
61
|
+
for (const pair of directPairs) {
|
|
62
|
+
const [assetA, assetB] = pair.assets;
|
|
70
63
|
// Build address-to-symbol map for quick symbol lookups
|
|
71
|
-
addrToSymbol.set(
|
|
72
|
-
addrToSymbol.set(
|
|
64
|
+
addrToSymbol.set(assetA.address, assetA.symbol);
|
|
65
|
+
addrToSymbol.set(assetB.address, assetB.symbol);
|
|
73
66
|
// Build direct path map (sorted addresses as key for consistency)
|
|
74
67
|
// for quick lookup of exchange details for any token pair
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
const sortedAddresses = [assetA.address, assetB.address]
|
|
69
|
+
.sort()
|
|
70
|
+
.join('-');
|
|
71
|
+
if (!directPathMap.has(sortedAddresses)) {
|
|
72
|
+
directPathMap.set(sortedAddresses, pair.path[0]);
|
|
78
73
|
}
|
|
79
74
|
// Build bidirectional connectivity graph for route traversal
|
|
80
75
|
// Each token can reach its directly connected tokens
|
|
81
|
-
if (!tokenGraph.has(
|
|
82
|
-
tokenGraph.set(
|
|
83
|
-
if (!tokenGraph.has(
|
|
84
|
-
tokenGraph.set(
|
|
85
|
-
tokenGraph.get(
|
|
86
|
-
tokenGraph.get(
|
|
76
|
+
if (!tokenGraph.has(assetA.address))
|
|
77
|
+
tokenGraph.set(assetA.address, new Set());
|
|
78
|
+
if (!tokenGraph.has(assetB.address))
|
|
79
|
+
tokenGraph.set(assetB.address, new Set());
|
|
80
|
+
tokenGraph.get(assetA.address).add(assetB.address);
|
|
81
|
+
tokenGraph.get(assetB.address).add(assetA.address);
|
|
87
82
|
}
|
|
88
|
-
return { addrToSymbol,
|
|
83
|
+
return { addrToSymbol, directPathMap, tokenGraph, directPairs };
|
|
89
84
|
}
|
|
85
|
+
exports.buildConnectivityStructures = buildConnectivityStructures;
|
|
90
86
|
/**
|
|
91
87
|
* Generates all possible routes (direct + two-hop) using connectivity data.
|
|
92
88
|
*
|
|
93
89
|
* This function implements a route discovery algorithm that:
|
|
94
90
|
*
|
|
95
|
-
* 1. **Adds all direct
|
|
91
|
+
* 1. **Adds all direct pairs** (single-hop routes)
|
|
96
92
|
* 2. **Discovers two-hop routes** using graph traversal:
|
|
97
93
|
* - For each token A, find its neighbors (tokens directly connected)
|
|
98
94
|
* - For each neighbor B, find B's neighbors
|
|
@@ -100,70 +96,71 @@ function buildConnectivityStructures(directRoutes) {
|
|
|
100
96
|
*
|
|
101
97
|
* **Route Deduplication**: Multiple routes between the same token pair
|
|
102
98
|
* are collected in arrays, allowing the selection algorithm to choose
|
|
103
|
-
* the best one based on
|
|
99
|
+
* the best one based on spread data or heuristics.
|
|
104
100
|
*
|
|
105
|
-
* **Canonical
|
|
106
|
-
* (e.g., '
|
|
101
|
+
* **Canonical Pair IDs**: All pairs use alphabetically sorted symbols
|
|
102
|
+
* (e.g., 'cEUR-cUSD' not 'cUSD-cEUR') for consistent identification.
|
|
107
103
|
*
|
|
108
104
|
* @param connectivityData - The connectivity data from buildConnectivityStructures()
|
|
109
|
-
* @returns Map of
|
|
105
|
+
* @returns Map of pair ID -> array of possible routes for that pair
|
|
110
106
|
*
|
|
111
107
|
* @example
|
|
112
108
|
* ```typescript
|
|
113
|
-
* // Given direct
|
|
109
|
+
* // Given direct pairs: cUSD-CELO, CELO-cEUR, cUSD-USDC
|
|
114
110
|
* const allRoutes = generateAllRoutes(connectivityData)
|
|
115
111
|
*
|
|
116
112
|
* // Results might include:
|
|
117
|
-
* // '
|
|
118
|
-
* // '
|
|
119
|
-
* // { path: [
|
|
120
|
-
* // { path: [
|
|
113
|
+
* // 'cUSD-CELO' -> [{ path: [cUSD->CELO] }] // direct route
|
|
114
|
+
* // 'cEUR-cUSD' -> [
|
|
115
|
+
* // { path: [cUSD->USDC, USDC->cEUR] } // two-hop via USDC
|
|
116
|
+
* // { path: [cUSD->CELO, CELO->cEUR] } // two-hop via CELO
|
|
121
117
|
* // ]
|
|
122
118
|
* ```
|
|
123
119
|
*/
|
|
124
120
|
function generateAllRoutes(connectivityData) {
|
|
125
|
-
const { addrToSymbol,
|
|
121
|
+
const { addrToSymbol, directPathMap, tokenGraph, directPairs } = connectivityData;
|
|
126
122
|
const allRoutes = new Map();
|
|
127
123
|
// Step 1: Add all direct pairs (single-hop routes)
|
|
128
|
-
for (const
|
|
129
|
-
if (!allRoutes.has(
|
|
130
|
-
allRoutes.set(
|
|
124
|
+
for (const pair of directPairs) {
|
|
125
|
+
if (!allRoutes.has(pair.id)) {
|
|
126
|
+
allRoutes.set(pair.id, []);
|
|
131
127
|
}
|
|
132
|
-
allRoutes.get(
|
|
128
|
+
allRoutes.get(pair.id).push(pair);
|
|
133
129
|
}
|
|
134
|
-
// Step 2: Generate two-hop
|
|
130
|
+
// Step 2: Generate two-hop pairs using graph traversal
|
|
135
131
|
// Algorithm: For each token, explore all paths of length 2
|
|
136
|
-
// OUTER LOOP: "For each starting token..." (e.g.,
|
|
132
|
+
// OUTER LOOP: "For each starting token..." (e.g., cUSD, CELO, cEUR, etc.)
|
|
137
133
|
for (const [start, neighbors] of tokenGraph.entries()) {
|
|
138
134
|
// MIDDLE LOOP: "Where can I go from the starting token?" (first hop)
|
|
139
|
-
// Example: If start =
|
|
135
|
+
// Example: If start = cUSD, neighbors might be [CELO, USDC, cKES]
|
|
140
136
|
for (const intermediate of neighbors) {
|
|
141
137
|
// Get all tokens reachable from this intermediate token (second hop destinations)
|
|
142
138
|
const secondHopNeighbors = tokenGraph.get(intermediate);
|
|
143
139
|
if (!secondHopNeighbors)
|
|
144
140
|
continue;
|
|
145
141
|
// INNER LOOP: "From the intermediate token, where can I go?" (second hop)
|
|
146
|
-
// Example: If intermediate = CELO, secondHopNeighbors might be [
|
|
142
|
+
// Example: If intermediate = CELO, secondHopNeighbors might be [cUSD, cEUR, cBRL]
|
|
147
143
|
for (const end of secondHopNeighbors) {
|
|
148
|
-
// Skip circular routes like
|
|
144
|
+
// Skip circular routes like cUSD → CELO → cUSD (pointless)
|
|
149
145
|
if (end === start)
|
|
150
146
|
continue;
|
|
151
147
|
// At this point we have a potential route: start → intermediate → end
|
|
152
|
-
// Example:
|
|
148
|
+
// Example: cUSD → CELO → cEUR
|
|
153
149
|
// Try to create a valid two-hop trading pair from this route
|
|
154
|
-
const
|
|
150
|
+
const twoHopPair = createTwoHopPair(start, intermediate, end, addrToSymbol, directPathMap);
|
|
155
151
|
// If we successfully created the pair, add it to our collection
|
|
156
|
-
if (
|
|
157
|
-
if (!allRoutes.has(
|
|
158
|
-
allRoutes.set(
|
|
152
|
+
if (twoHopPair) {
|
|
153
|
+
if (!allRoutes.has(twoHopPair.id)) {
|
|
154
|
+
allRoutes.set(twoHopPair.id, []);
|
|
159
155
|
}
|
|
160
|
-
allRoutes.get(
|
|
156
|
+
allRoutes.get(twoHopPair.id).push(twoHopPair);
|
|
161
157
|
}
|
|
162
158
|
}
|
|
163
159
|
}
|
|
164
160
|
}
|
|
165
161
|
return allRoutes;
|
|
166
162
|
}
|
|
163
|
+
exports.generateAllRoutes = generateAllRoutes;
|
|
167
164
|
/**
|
|
168
165
|
* Creates a two-hop tradable pair if valid exchange hops exist.
|
|
169
166
|
*
|
|
@@ -187,55 +184,56 @@ function generateAllRoutes(connectivityData) {
|
|
|
187
184
|
*
|
|
188
185
|
* @example
|
|
189
186
|
* ```typescript
|
|
190
|
-
* // Create route:
|
|
187
|
+
* // Create route: cUSD -> CELO -> cEUR
|
|
191
188
|
* const pair = createTwoHopPair(
|
|
192
|
-
* '0x765D...', //
|
|
189
|
+
* '0x765D...', // cUSD address
|
|
193
190
|
* '0x471E...', // CELO address
|
|
194
|
-
* '0xD876...', //
|
|
191
|
+
* '0xD876...', // cEUR address
|
|
195
192
|
* addrToSymbol,
|
|
196
193
|
* directPathMap
|
|
197
194
|
* )
|
|
198
195
|
*
|
|
199
196
|
* // Result:
|
|
200
197
|
* // {
|
|
201
|
-
* // id: '
|
|
202
|
-
* // assets: [
|
|
198
|
+
* // id: 'cEUR-cUSD', // alphabetical order
|
|
199
|
+
* // assets: [cEUR, cUSD], // alphabetical order
|
|
203
200
|
* // path: [ // actual routing path
|
|
204
|
-
* // {
|
|
205
|
-
* // { CELO->
|
|
201
|
+
* // { cUSD->CELO exchange },
|
|
202
|
+
* // { CELO->cEUR exchange }
|
|
206
203
|
* // ]
|
|
207
204
|
* // }
|
|
208
205
|
* ```
|
|
209
206
|
*/
|
|
210
|
-
function
|
|
211
|
-
// Validate that both
|
|
212
|
-
const startSymbol = addrToSymbol.get(
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
if (!startSymbol || !intermediateSymbol || !endSymbol)
|
|
207
|
+
function createTwoHopPair(startToken, intermediateToken, endToken, addrToSymbol, directPathMap) {
|
|
208
|
+
// Validate that both start and end tokens exist in our address-to-symbol map
|
|
209
|
+
const startSymbol = addrToSymbol.get(startToken);
|
|
210
|
+
const endSymbol = addrToSymbol.get(endToken);
|
|
211
|
+
if (!startSymbol || !endSymbol)
|
|
216
212
|
return null;
|
|
213
|
+
// Create Asset objects from address and symbol
|
|
214
|
+
const startAsset = { address: startToken, symbol: startSymbol };
|
|
215
|
+
const endAsset = { address: endToken, symbol: endSymbol };
|
|
217
216
|
// Find exchange hops for both segments of the two-hop route
|
|
218
217
|
// Keys are sorted token addresses for consistent lookup
|
|
219
|
-
const hop1Key =
|
|
220
|
-
const hop2Key =
|
|
221
|
-
const hop1 =
|
|
222
|
-
const hop2 =
|
|
218
|
+
const hop1Key = [startToken, intermediateToken].sort().join('-');
|
|
219
|
+
const hop2Key = [intermediateToken, endToken].sort().join('-');
|
|
220
|
+
const hop1 = directPathMap.get(hop1Key);
|
|
221
|
+
const hop2 = directPathMap.get(hop2Key);
|
|
223
222
|
// If either hop doesn't exist, this route is invalid
|
|
224
223
|
if (!hop1 || !hop2)
|
|
225
224
|
return null;
|
|
226
225
|
// Create canonical pair structure (alphabetical symbol ordering)
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const
|
|
231
|
-
// Token array follows alphabetical ordering for consistency
|
|
232
|
-
const tokens = startSymbol <= endSymbol ? [startToken, endToken] : [endToken, startToken];
|
|
226
|
+
const sortedSymbols = [startSymbol, endSymbol].sort();
|
|
227
|
+
const pairId = `${sortedSymbols[0]}-${sortedSymbols[1]}`;
|
|
228
|
+
// Assets array follows alphabetical ordering for consistency
|
|
229
|
+
const assets = startSymbol <= endSymbol ? [startAsset, endAsset] : [endAsset, startAsset];
|
|
233
230
|
return {
|
|
234
|
-
id:
|
|
235
|
-
|
|
231
|
+
id: pairId,
|
|
232
|
+
assets,
|
|
236
233
|
path: [hop1, hop2], // Preserves actual routing path for execution
|
|
237
234
|
};
|
|
238
235
|
}
|
|
236
|
+
exports.createTwoHopPair = createTwoHopPair;
|
|
239
237
|
/**
|
|
240
238
|
* Selects optimal routes from all candidates based on spread data or heuristics.
|
|
241
239
|
*
|
|
@@ -257,58 +255,59 @@ function createTwoHopRoute(startAddr, intermediateAddr, endAddr, addrToSymbol, d
|
|
|
257
255
|
*
|
|
258
256
|
* @example
|
|
259
257
|
* ```typescript
|
|
260
|
-
* // Multiple routes for
|
|
258
|
+
* // Multiple routes for cUSD-cEUR pair
|
|
261
259
|
* const candidates = new Map([
|
|
262
|
-
* ['
|
|
263
|
-
* { path: [
|
|
264
|
-
* { path: [
|
|
265
|
-
* { path: [
|
|
260
|
+
* ['cEUR-cUSD', [
|
|
261
|
+
* { path: [cUSD->CELO->cEUR], spreadData: { totalSpreadPercent: 0.5 } },
|
|
262
|
+
* { path: [cUSD->cREAL->cEUR], spreadData: { totalSpreadPercent: 0.3 } },
|
|
263
|
+
* { path: [cUSD->cEUR] } // direct route, no spread data
|
|
266
264
|
* ]]
|
|
267
265
|
* ])
|
|
268
266
|
*
|
|
269
267
|
* const optimal = selectOptimalRoutes(candidates, false, assetMap)
|
|
270
|
-
* // Returns the
|
|
268
|
+
* // Returns the cUSD->cREAL->cEUR route (lowest spread: 0.3%)
|
|
271
269
|
* ```
|
|
272
270
|
*/
|
|
273
271
|
function selectOptimalRoutes(allRoutes, returnAllRoutes, addrToSymbol) {
|
|
274
272
|
const result = new Map();
|
|
275
|
-
for (const [
|
|
273
|
+
for (const [pairId, routes] of allRoutes) {
|
|
276
274
|
if (routes.length === 1) {
|
|
277
275
|
// Only one route available - use it directly
|
|
278
|
-
result.set(
|
|
276
|
+
result.set(pairId, routes[0]);
|
|
279
277
|
}
|
|
280
278
|
else if (returnAllRoutes) {
|
|
281
279
|
// Return all routes with unique keys (used for cache generation)
|
|
282
280
|
routes.forEach((route, index) => {
|
|
283
|
-
result.set(`${
|
|
281
|
+
result.set(`${pairId}_${index}`, route);
|
|
284
282
|
});
|
|
285
283
|
}
|
|
286
284
|
else {
|
|
287
285
|
// Multiple routes - select the best one using optimization logic
|
|
288
286
|
const bestRoute = selectBestRoute(routes, addrToSymbol);
|
|
289
|
-
result.set(
|
|
287
|
+
result.set(pairId, bestRoute);
|
|
290
288
|
}
|
|
291
289
|
}
|
|
292
290
|
return Array.from(result.values());
|
|
293
291
|
}
|
|
292
|
+
exports.selectOptimalRoutes = selectOptimalRoutes;
|
|
294
293
|
/**
|
|
295
|
-
* Selects the best route from candidates using
|
|
294
|
+
* Selects the best route from candidates using spread data or fallback heuristics.
|
|
296
295
|
*
|
|
297
296
|
* This function implements a sophisticated route selection algorithm with
|
|
298
297
|
* multiple optimization tiers:
|
|
299
298
|
*
|
|
300
|
-
* **Tier 1 -
|
|
301
|
-
* - Use routes with
|
|
302
|
-
* - Select route with lowest `
|
|
299
|
+
* **Tier 1 - Spread-Based Optimization** (Preferred):
|
|
300
|
+
* - Use routes with spread data (actual cost information)
|
|
301
|
+
* - Select route with lowest `totalSpreadPercent`
|
|
303
302
|
* - This provides the most cost-efficient trading
|
|
304
303
|
*
|
|
305
304
|
* **Tier 2 - Direct Route Preference** (Fallback):
|
|
306
|
-
* - If no
|
|
305
|
+
* - If no spread data available, prefer direct (single-hop) routes
|
|
307
306
|
* - Direct routes have lower execution risk and gas costs
|
|
308
307
|
*
|
|
309
308
|
* **Tier 3 - Major Stablecoin Preference** (Final Fallback):
|
|
310
309
|
* - For two-hop routes, prefer those going through major stablecoins
|
|
311
|
-
* - Major FX currencies like
|
|
310
|
+
* - Major FX currencies like cUSD and cEUR typically have better liquidity
|
|
312
311
|
*
|
|
313
312
|
* **Tier 4 - First Available** (Last Resort):
|
|
314
313
|
* - If no other heuristics apply, use the first route found
|
|
@@ -320,27 +319,29 @@ function selectOptimalRoutes(allRoutes, returnAllRoutes, addrToSymbol) {
|
|
|
320
319
|
* @example
|
|
321
320
|
* ```typescript
|
|
322
321
|
* const candidates = [
|
|
323
|
-
* { path: [A->B->C],
|
|
324
|
-
* { path: [A->D->C],
|
|
325
|
-
* { path: [A->C] }, // direct route, no
|
|
322
|
+
* { path: [A->B->C], spreadData: { totalSpreadPercent: 0.8 } },
|
|
323
|
+
* { path: [A->D->C], spreadData: { totalSpreadPercent: 0.4 } }, // Winner: lowest spread
|
|
324
|
+
* { path: [A->C] }, // direct route, no spread data
|
|
326
325
|
* ]
|
|
327
326
|
*
|
|
328
327
|
* const best = selectBestRoute(candidates, assetMap)
|
|
329
|
-
* // Returns the A->D->C route (0.4%
|
|
328
|
+
* // Returns the A->D->C route (0.4% spread)
|
|
330
329
|
* ```
|
|
331
330
|
*/
|
|
332
331
|
function selectBestRoute(candidates, addrToSymbol) {
|
|
333
|
-
// Tier 1: Prefer routes with
|
|
334
|
-
const
|
|
335
|
-
if (
|
|
336
|
-
return
|
|
332
|
+
// Tier 1: Prefer routes with spread data (lowest spread wins)
|
|
333
|
+
const candidatesWithSpread = candidates.filter(hasSpreadData);
|
|
334
|
+
if (candidatesWithSpread.length > 0) {
|
|
335
|
+
return candidatesWithSpread.reduce((best, current) => current.spreadData.totalSpreadPercent < best.spreadData.totalSpreadPercent
|
|
336
|
+
? current
|
|
337
|
+
: best);
|
|
337
338
|
}
|
|
338
339
|
// Tier 2: Prefer direct routes (single-hop, lower risk)
|
|
339
340
|
const directRoute = candidates.find((c) => c.path.length === 1);
|
|
340
341
|
if (directRoute)
|
|
341
342
|
return directRoute;
|
|
342
343
|
// Tier 3: Prefer routes through major stablecoins (better liquidity)
|
|
343
|
-
const stablecoins = ['
|
|
344
|
+
const stablecoins = ['cUSD', 'cEUR', 'USDC', 'USDT'];
|
|
344
345
|
const routeWithStablecoin = candidates.find((candidate) => {
|
|
345
346
|
const intermediateToken = getIntermediateToken(candidate);
|
|
346
347
|
if (!intermediateToken)
|
|
@@ -351,6 +352,7 @@ function selectBestRoute(candidates, addrToSymbol) {
|
|
|
351
352
|
// Tier 4: Use first available route as last resort
|
|
352
353
|
return routeWithStablecoin || candidates[0];
|
|
353
354
|
}
|
|
355
|
+
exports.selectBestRoute = selectBestRoute;
|
|
354
356
|
/**
|
|
355
357
|
* Extracts the intermediate token address from a two-hop route.
|
|
356
358
|
* In a two-hop route A->B->C, this function finds token B (the intermediate).
|
|
@@ -358,14 +360,13 @@ function selectBestRoute(candidates, addrToSymbol) {
|
|
|
358
360
|
function getIntermediateToken(route) {
|
|
359
361
|
// Find the common token between the two hops
|
|
360
362
|
const [hop1, hop2] = route.path;
|
|
361
|
-
|
|
362
|
-
const hop2Tokens = [hop2.token0, hop2.token1];
|
|
363
|
-
return hop1Tokens.find((addr) => hop2Tokens.includes(addr));
|
|
363
|
+
return hop1.assets.find((addr) => hop2.assets.includes(addr));
|
|
364
364
|
}
|
|
365
|
+
exports.getIntermediateToken = getIntermediateToken;
|
|
365
366
|
/**
|
|
366
|
-
* Type guard to check if a Route has
|
|
367
|
+
* Type guard to check if a Route has spread data.
|
|
367
368
|
*/
|
|
368
|
-
function
|
|
369
|
-
return '
|
|
369
|
+
function hasSpreadData(pair) {
|
|
370
|
+
return 'spreadData' in pair && pair.spreadData !== undefined;
|
|
370
371
|
}
|
|
371
|
-
|
|
372
|
+
exports.hasSpreadData = hasSpreadData;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ContractAddresses = {
|
|
2
|
+
GovernanceFactory: string;
|
|
3
|
+
Airgrab: string;
|
|
4
|
+
Emission: string;
|
|
5
|
+
MentoGovernor: string;
|
|
6
|
+
MentoToken: string;
|
|
7
|
+
TimelockController: string;
|
|
8
|
+
Locking: string;
|
|
9
|
+
MentoRouter: string;
|
|
10
|
+
Broker: string;
|
|
11
|
+
BiPoolManager: string;
|
|
12
|
+
BreakerBox: string;
|
|
13
|
+
Reserve: string;
|
|
14
|
+
ConstantSumPricingModule: string;
|
|
15
|
+
ConstantProductPricingModule: string;
|
|
16
|
+
MedianDeltaBreaker: string;
|
|
17
|
+
ValueDeltaBreaker: string;
|
|
18
|
+
StableToken: string;
|
|
19
|
+
StableTokenEUR: string;
|
|
20
|
+
StableTokenBRL: string;
|
|
21
|
+
StableTokenXOF: string;
|
|
22
|
+
SortedOracles: string;
|
|
23
|
+
};
|
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
|
|
17
|
+
__exportStar(require("./contractAddresses"), exports);
|
|
18
|
+
__exportStar(require("./contractAddressMap"), exports);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { BigNumberish, providers, Signer } from 'ethers';
|
|
2
|
+
import { TokenSymbol } from './constants';
|
|
3
|
+
import { Address } from './interfaces';
|
|
4
|
+
import { Token, TradablePair } from './mento';
|
|
5
|
+
/**
|
|
6
|
+
* Gets the chain ID from a signer or provider
|
|
7
|
+
* @param signerOrProvider an ethers provider or signer
|
|
8
|
+
* @returns the chain ID
|
|
9
|
+
*/
|
|
10
|
+
export declare function getChainId(signerOrProvider: Signer | providers.Provider): Promise<number>;
|
|
11
|
+
/**
|
|
12
|
+
* Ensures that given signer is truly a a connected signer
|
|
13
|
+
* @param signer an ethers signer
|
|
14
|
+
* @throws if signer is invalid or not connected
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateSigner(signer: Signer): void;
|
|
17
|
+
/**
|
|
18
|
+
* Ensures that given signerOrProvider is truly a provider or a connected signer
|
|
19
|
+
* @param signerOrProvider an ethers provider or signer
|
|
20
|
+
* @throws if signerOrProvider is invalid or not connected
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateSignerOrProvider(signerOrProvider: Signer | providers.Provider): void;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the symbol of an erc20 token
|
|
25
|
+
* @param tokenAddr the address of the erc20 token
|
|
26
|
+
* @param signerOrProvider an ethers provider or signer
|
|
27
|
+
* @returns the symbol of the erc20 token
|
|
28
|
+
*/
|
|
29
|
+
export declare function getSymbolFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<TokenSymbol>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the name of an erc20 token
|
|
32
|
+
* @param tokenAddr the address of the erc20 token
|
|
33
|
+
* @param signerOrProvider an ethers provider or signer
|
|
34
|
+
* @returns the name of the erc20 token
|
|
35
|
+
*/
|
|
36
|
+
export declare function getNameFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the decimals of an erc20 token
|
|
39
|
+
* @param tokenAddr the address of the erc20 token
|
|
40
|
+
* @param signerOrProvider an ethers provider or signer
|
|
41
|
+
* @returns the decimals of the erc20 token
|
|
42
|
+
*/
|
|
43
|
+
export declare function getDecimalsFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<number>;
|
|
44
|
+
/**
|
|
45
|
+
* Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
|
|
46
|
+
* @param tokenAddr the address of the erc20 token
|
|
47
|
+
* @param spender the address of the spender
|
|
48
|
+
* @param amount the amount to increase the allowance by
|
|
49
|
+
* @param signerOrProvider an ethers signer or provider
|
|
50
|
+
* @returns the populated TransactionRequest object
|
|
51
|
+
*/
|
|
52
|
+
export declare function increaseAllowance(tokenAddr: string, spender: string, amount: BigNumberish, signerOrProvider: Signer | providers.Provider): Promise<providers.TransactionRequest>;
|
|
53
|
+
/**
|
|
54
|
+
* Find a token address by its symbol from tradable pairs
|
|
55
|
+
* @param pairs array of tradable pairs to search through
|
|
56
|
+
* @param symbol the token symbol to find (case-insensitive)
|
|
57
|
+
* @returns the token address if found, null otherwise
|
|
58
|
+
*/
|
|
59
|
+
export declare function findTokenAddressBySymbolInTradablePairs(symbol: TokenSymbol, pairs: readonly TradablePair[]): Address | null;
|
|
60
|
+
export declare function capitalize(str: string): string; /**
|
|
61
|
+
* Helper function to get token address by symbol for a specific chain
|
|
62
|
+
* @param symbol - The token symbol
|
|
63
|
+
* @param chainId - The chain ID
|
|
64
|
+
* @returns The token address or undefined if not found
|
|
65
|
+
*/
|
|
66
|
+
export declare function getTokenAddress(symbol: TokenSymbol, chainId: number): string | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Helper function to find a token by symbol in the cached tokens
|
|
69
|
+
* @param symbol - The token symbol to search for
|
|
70
|
+
* @param chainId - The chain ID
|
|
71
|
+
* @returns The token object or undefined if not found
|
|
72
|
+
*/
|
|
73
|
+
export declare function findTokenBySymbol(symbol: string, chainId: number): Token | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Computes the rate feed ID from a rate feed identifier string.
|
|
76
|
+
* This follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
77
|
+
* @param rateFeed the rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
78
|
+
* @returns the computed rate feed address
|
|
79
|
+
*/
|
|
80
|
+
export declare function toRateFeedId(rateFeed: string): Address;
|