@mento-protocol/mento-sdk 3.2.2-beta1 → 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,4 +1,3 @@
|
|
|
1
|
-
import { canonicalSymbolKey } from './sortUtils';
|
|
2
1
|
/**
|
|
3
2
|
* Builds the connectivity data structures needed for route generation.
|
|
4
3
|
*
|
|
@@ -9,23 +8,23 @@ import { canonicalSymbolKey } from './sortUtils';
|
|
|
9
8
|
*
|
|
10
9
|
* ```
|
|
11
10
|
* Input: TradablePairs = [
|
|
12
|
-
* { id: '
|
|
13
|
-
* { id: 'CELO-
|
|
11
|
+
* { id: 'cUSD-CELO', assets: [cUSD, CELO], path: [exchange1_CELO_cUSD] },
|
|
12
|
+
* { id: 'CELO-cEUR', assets: [CELO, cEUR], path: [exchange2_CELO_cEUR] }
|
|
14
13
|
* ]
|
|
15
14
|
*
|
|
16
15
|
* Step 1 - Build addrToSymbol map:
|
|
17
|
-
*
|
|
16
|
+
* cUSD.address → 'cUSD'
|
|
18
17
|
* CELO.address → 'CELO'
|
|
19
|
-
*
|
|
18
|
+
* cEUR.address → 'cEUR'
|
|
20
19
|
*
|
|
21
20
|
* Step 2 - Build directPathMap (sorted alphabetically for consistency):
|
|
22
|
-
* 'CELO_addr-
|
|
23
|
-
* 'CELO_addr-
|
|
21
|
+
* 'CELO_addr-cEUR_addr' → exchange2_CELO_cEUR
|
|
22
|
+
* 'CELO_addr-cUSD_addr' → exchange1_CELO_cUSD
|
|
24
23
|
*
|
|
25
24
|
* Step 3 - Build bidirectional tokenGraph:
|
|
26
|
-
*
|
|
27
|
-
* CELO.address → Set([
|
|
28
|
-
*
|
|
25
|
+
* cUSD.address → Set([CELO.address])
|
|
26
|
+
* CELO.address → Set([cUSD.address, cEUR.address])
|
|
27
|
+
* cEUR.address → Set([CELO.address])
|
|
29
28
|
* ```
|
|
30
29
|
*
|
|
31
30
|
* **Result**: We can now efficiently answer:
|
|
@@ -33,57 +32,59 @@ import { canonicalSymbolKey } from './sortUtils';
|
|
|
33
32
|
* - "What exchange connects tokens X and Y?" → directPathMap.get(sortedAddressPairKey)
|
|
34
33
|
* - "What tokens can I reach from token X?" → tokenGraph.get(X)
|
|
35
34
|
*
|
|
36
|
-
* @param
|
|
35
|
+
* @param directPairs - Array of direct trading pairs
|
|
37
36
|
* @returns Connectivity data structure for efficient route generation
|
|
38
37
|
*
|
|
39
38
|
* @example
|
|
40
39
|
* ```typescript
|
|
41
40
|
* const directPairs = [
|
|
42
|
-
* { id: '
|
|
43
|
-
* { id: 'CELO-
|
|
41
|
+
* { id: 'cUSD-CELO', assets: [cUSD, CELO], path: [exchange1] },
|
|
42
|
+
* { id: 'CELO-cEUR', assets: [CELO, cEUR], path: [exchange2] }
|
|
44
43
|
* ]
|
|
45
44
|
*
|
|
46
45
|
* const connectivityData = buildConnectivityStructures(directPairs)
|
|
47
46
|
*
|
|
48
47
|
* // Now we can efficiently find routes:
|
|
49
|
-
* // 1. Check if
|
|
50
|
-
* // 2. Check if CELO connects to
|
|
51
|
-
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-
|
|
52
|
-
* // Result: Found route
|
|
48
|
+
* // 1. Check if cUSD connects to anything: connectivityData.tokenGraph.get(cUSD.address) → [CELO.address]
|
|
49
|
+
* // 2. Check if CELO connects to cEUR: connectivityData.tokenGraph.get(CELO.address) → [cUSD.address, cEUR.address] ✓
|
|
50
|
+
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-cEUR_addr') → exchange2_CELO_cEUR
|
|
51
|
+
* // Result: Found route cUSD → CELO → cEUR with exchange details
|
|
53
52
|
* ```
|
|
54
53
|
*/
|
|
55
|
-
export function buildConnectivityStructures(
|
|
54
|
+
export function buildConnectivityStructures(directPairs) {
|
|
56
55
|
const addrToSymbol = new Map();
|
|
57
|
-
const
|
|
56
|
+
const directPathMap = new Map();
|
|
58
57
|
const tokenGraph = new Map();
|
|
59
|
-
for (const
|
|
60
|
-
const [
|
|
58
|
+
for (const pair of directPairs) {
|
|
59
|
+
const [assetA, assetB] = pair.assets;
|
|
61
60
|
// Build address-to-symbol map for quick symbol lookups
|
|
62
|
-
addrToSymbol.set(
|
|
63
|
-
addrToSymbol.set(
|
|
61
|
+
addrToSymbol.set(assetA.address, assetA.symbol);
|
|
62
|
+
addrToSymbol.set(assetB.address, assetB.symbol);
|
|
64
63
|
// Build direct path map (sorted addresses as key for consistency)
|
|
65
64
|
// for quick lookup of exchange details for any token pair
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const sortedAddresses = [assetA.address, assetB.address]
|
|
66
|
+
.sort()
|
|
67
|
+
.join('-');
|
|
68
|
+
if (!directPathMap.has(sortedAddresses)) {
|
|
69
|
+
directPathMap.set(sortedAddresses, pair.path[0]);
|
|
69
70
|
}
|
|
70
71
|
// Build bidirectional connectivity graph for route traversal
|
|
71
72
|
// Each token can reach its directly connected tokens
|
|
72
|
-
if (!tokenGraph.has(
|
|
73
|
-
tokenGraph.set(
|
|
74
|
-
if (!tokenGraph.has(
|
|
75
|
-
tokenGraph.set(
|
|
76
|
-
tokenGraph.get(
|
|
77
|
-
tokenGraph.get(
|
|
73
|
+
if (!tokenGraph.has(assetA.address))
|
|
74
|
+
tokenGraph.set(assetA.address, new Set());
|
|
75
|
+
if (!tokenGraph.has(assetB.address))
|
|
76
|
+
tokenGraph.set(assetB.address, new Set());
|
|
77
|
+
tokenGraph.get(assetA.address).add(assetB.address);
|
|
78
|
+
tokenGraph.get(assetB.address).add(assetA.address);
|
|
78
79
|
}
|
|
79
|
-
return { addrToSymbol,
|
|
80
|
+
return { addrToSymbol, directPathMap, tokenGraph, directPairs };
|
|
80
81
|
}
|
|
81
82
|
/**
|
|
82
83
|
* Generates all possible routes (direct + two-hop) using connectivity data.
|
|
83
84
|
*
|
|
84
85
|
* This function implements a route discovery algorithm that:
|
|
85
86
|
*
|
|
86
|
-
* 1. **Adds all direct
|
|
87
|
+
* 1. **Adds all direct pairs** (single-hop routes)
|
|
87
88
|
* 2. **Discovers two-hop routes** using graph traversal:
|
|
88
89
|
* - For each token A, find its neighbors (tokens directly connected)
|
|
89
90
|
* - For each neighbor B, find B's neighbors
|
|
@@ -91,64 +92,64 @@ export function buildConnectivityStructures(directRoutes) {
|
|
|
91
92
|
*
|
|
92
93
|
* **Route Deduplication**: Multiple routes between the same token pair
|
|
93
94
|
* are collected in arrays, allowing the selection algorithm to choose
|
|
94
|
-
* the best one based on
|
|
95
|
+
* the best one based on spread data or heuristics.
|
|
95
96
|
*
|
|
96
|
-
* **Canonical
|
|
97
|
-
* (e.g., '
|
|
97
|
+
* **Canonical Pair IDs**: All pairs use alphabetically sorted symbols
|
|
98
|
+
* (e.g., 'cEUR-cUSD' not 'cUSD-cEUR') for consistent identification.
|
|
98
99
|
*
|
|
99
100
|
* @param connectivityData - The connectivity data from buildConnectivityStructures()
|
|
100
|
-
* @returns Map of
|
|
101
|
+
* @returns Map of pair ID -> array of possible routes for that pair
|
|
101
102
|
*
|
|
102
103
|
* @example
|
|
103
104
|
* ```typescript
|
|
104
|
-
* // Given direct
|
|
105
|
+
* // Given direct pairs: cUSD-CELO, CELO-cEUR, cUSD-USDC
|
|
105
106
|
* const allRoutes = generateAllRoutes(connectivityData)
|
|
106
107
|
*
|
|
107
108
|
* // Results might include:
|
|
108
|
-
* // '
|
|
109
|
-
* // '
|
|
110
|
-
* // { path: [
|
|
111
|
-
* // { path: [
|
|
109
|
+
* // 'cUSD-CELO' -> [{ path: [cUSD->CELO] }] // direct route
|
|
110
|
+
* // 'cEUR-cUSD' -> [
|
|
111
|
+
* // { path: [cUSD->USDC, USDC->cEUR] } // two-hop via USDC
|
|
112
|
+
* // { path: [cUSD->CELO, CELO->cEUR] } // two-hop via CELO
|
|
112
113
|
* // ]
|
|
113
114
|
* ```
|
|
114
115
|
*/
|
|
115
116
|
export function generateAllRoutes(connectivityData) {
|
|
116
|
-
const { addrToSymbol,
|
|
117
|
+
const { addrToSymbol, directPathMap, tokenGraph, directPairs } = connectivityData;
|
|
117
118
|
const allRoutes = new Map();
|
|
118
119
|
// Step 1: Add all direct pairs (single-hop routes)
|
|
119
|
-
for (const
|
|
120
|
-
if (!allRoutes.has(
|
|
121
|
-
allRoutes.set(
|
|
120
|
+
for (const pair of directPairs) {
|
|
121
|
+
if (!allRoutes.has(pair.id)) {
|
|
122
|
+
allRoutes.set(pair.id, []);
|
|
122
123
|
}
|
|
123
|
-
allRoutes.get(
|
|
124
|
+
allRoutes.get(pair.id).push(pair);
|
|
124
125
|
}
|
|
125
|
-
// Step 2: Generate two-hop
|
|
126
|
+
// Step 2: Generate two-hop pairs using graph traversal
|
|
126
127
|
// Algorithm: For each token, explore all paths of length 2
|
|
127
|
-
// OUTER LOOP: "For each starting token..." (e.g.,
|
|
128
|
+
// OUTER LOOP: "For each starting token..." (e.g., cUSD, CELO, cEUR, etc.)
|
|
128
129
|
for (const [start, neighbors] of tokenGraph.entries()) {
|
|
129
130
|
// MIDDLE LOOP: "Where can I go from the starting token?" (first hop)
|
|
130
|
-
// Example: If start =
|
|
131
|
+
// Example: If start = cUSD, neighbors might be [CELO, USDC, cKES]
|
|
131
132
|
for (const intermediate of neighbors) {
|
|
132
133
|
// Get all tokens reachable from this intermediate token (second hop destinations)
|
|
133
134
|
const secondHopNeighbors = tokenGraph.get(intermediate);
|
|
134
135
|
if (!secondHopNeighbors)
|
|
135
136
|
continue;
|
|
136
137
|
// INNER LOOP: "From the intermediate token, where can I go?" (second hop)
|
|
137
|
-
// Example: If intermediate = CELO, secondHopNeighbors might be [
|
|
138
|
+
// Example: If intermediate = CELO, secondHopNeighbors might be [cUSD, cEUR, cBRL]
|
|
138
139
|
for (const end of secondHopNeighbors) {
|
|
139
|
-
// Skip circular routes like
|
|
140
|
+
// Skip circular routes like cUSD → CELO → cUSD (pointless)
|
|
140
141
|
if (end === start)
|
|
141
142
|
continue;
|
|
142
143
|
// At this point we have a potential route: start → intermediate → end
|
|
143
|
-
// Example:
|
|
144
|
+
// Example: cUSD → CELO → cEUR
|
|
144
145
|
// Try to create a valid two-hop trading pair from this route
|
|
145
|
-
const
|
|
146
|
+
const twoHopPair = createTwoHopPair(start, intermediate, end, addrToSymbol, directPathMap);
|
|
146
147
|
// If we successfully created the pair, add it to our collection
|
|
147
|
-
if (
|
|
148
|
-
if (!allRoutes.has(
|
|
149
|
-
allRoutes.set(
|
|
148
|
+
if (twoHopPair) {
|
|
149
|
+
if (!allRoutes.has(twoHopPair.id)) {
|
|
150
|
+
allRoutes.set(twoHopPair.id, []);
|
|
150
151
|
}
|
|
151
|
-
allRoutes.get(
|
|
152
|
+
allRoutes.get(twoHopPair.id).push(twoHopPair);
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
}
|
|
@@ -178,52 +179,52 @@ export function generateAllRoutes(connectivityData) {
|
|
|
178
179
|
*
|
|
179
180
|
* @example
|
|
180
181
|
* ```typescript
|
|
181
|
-
* // Create route:
|
|
182
|
+
* // Create route: cUSD -> CELO -> cEUR
|
|
182
183
|
* const pair = createTwoHopPair(
|
|
183
|
-
* '0x765D...', //
|
|
184
|
+
* '0x765D...', // cUSD address
|
|
184
185
|
* '0x471E...', // CELO address
|
|
185
|
-
* '0xD876...', //
|
|
186
|
+
* '0xD876...', // cEUR address
|
|
186
187
|
* addrToSymbol,
|
|
187
188
|
* directPathMap
|
|
188
189
|
* )
|
|
189
190
|
*
|
|
190
191
|
* // Result:
|
|
191
192
|
* // {
|
|
192
|
-
* // id: '
|
|
193
|
-
* // assets: [
|
|
193
|
+
* // id: 'cEUR-cUSD', // alphabetical order
|
|
194
|
+
* // assets: [cEUR, cUSD], // alphabetical order
|
|
194
195
|
* // path: [ // actual routing path
|
|
195
|
-
* // {
|
|
196
|
-
* // { CELO->
|
|
196
|
+
* // { cUSD->CELO exchange },
|
|
197
|
+
* // { CELO->cEUR exchange }
|
|
197
198
|
* // ]
|
|
198
199
|
* // }
|
|
199
200
|
* ```
|
|
200
201
|
*/
|
|
201
|
-
export function
|
|
202
|
-
// Validate that both
|
|
203
|
-
const startSymbol = addrToSymbol.get(
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
if (!startSymbol || !intermediateSymbol || !endSymbol)
|
|
202
|
+
export function createTwoHopPair(startToken, intermediateToken, endToken, addrToSymbol, directPathMap) {
|
|
203
|
+
// Validate that both start and end tokens exist in our address-to-symbol map
|
|
204
|
+
const startSymbol = addrToSymbol.get(startToken);
|
|
205
|
+
const endSymbol = addrToSymbol.get(endToken);
|
|
206
|
+
if (!startSymbol || !endSymbol)
|
|
207
207
|
return null;
|
|
208
|
+
// Create Asset objects from address and symbol
|
|
209
|
+
const startAsset = { address: startToken, symbol: startSymbol };
|
|
210
|
+
const endAsset = { address: endToken, symbol: endSymbol };
|
|
208
211
|
// Find exchange hops for both segments of the two-hop route
|
|
209
212
|
// Keys are sorted token addresses for consistent lookup
|
|
210
|
-
const hop1Key =
|
|
211
|
-
const hop2Key =
|
|
212
|
-
const hop1 =
|
|
213
|
-
const hop2 =
|
|
213
|
+
const hop1Key = [startToken, intermediateToken].sort().join('-');
|
|
214
|
+
const hop2Key = [intermediateToken, endToken].sort().join('-');
|
|
215
|
+
const hop1 = directPathMap.get(hop1Key);
|
|
216
|
+
const hop2 = directPathMap.get(hop2Key);
|
|
214
217
|
// If either hop doesn't exist, this route is invalid
|
|
215
218
|
if (!hop1 || !hop2)
|
|
216
219
|
return null;
|
|
217
220
|
// Create canonical pair structure (alphabetical symbol ordering)
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
// Token array follows alphabetical ordering for consistency
|
|
223
|
-
const tokens = startSymbol <= endSymbol ? [startToken, endToken] : [endToken, startToken];
|
|
221
|
+
const sortedSymbols = [startSymbol, endSymbol].sort();
|
|
222
|
+
const pairId = `${sortedSymbols[0]}-${sortedSymbols[1]}`;
|
|
223
|
+
// Assets array follows alphabetical ordering for consistency
|
|
224
|
+
const assets = startSymbol <= endSymbol ? [startAsset, endAsset] : [endAsset, startAsset];
|
|
224
225
|
return {
|
|
225
|
-
id:
|
|
226
|
-
|
|
226
|
+
id: pairId,
|
|
227
|
+
assets,
|
|
227
228
|
path: [hop1, hop2], // Preserves actual routing path for execution
|
|
228
229
|
};
|
|
229
230
|
}
|
|
@@ -248,58 +249,58 @@ export function createTwoHopRoute(startAddr, intermediateAddr, endAddr, addrToSy
|
|
|
248
249
|
*
|
|
249
250
|
* @example
|
|
250
251
|
* ```typescript
|
|
251
|
-
* // Multiple routes for
|
|
252
|
+
* // Multiple routes for cUSD-cEUR pair
|
|
252
253
|
* const candidates = new Map([
|
|
253
|
-
* ['
|
|
254
|
-
* { path: [
|
|
255
|
-
* { path: [
|
|
256
|
-
* { path: [
|
|
254
|
+
* ['cEUR-cUSD', [
|
|
255
|
+
* { path: [cUSD->CELO->cEUR], spreadData: { totalSpreadPercent: 0.5 } },
|
|
256
|
+
* { path: [cUSD->cREAL->cEUR], spreadData: { totalSpreadPercent: 0.3 } },
|
|
257
|
+
* { path: [cUSD->cEUR] } // direct route, no spread data
|
|
257
258
|
* ]]
|
|
258
259
|
* ])
|
|
259
260
|
*
|
|
260
261
|
* const optimal = selectOptimalRoutes(candidates, false, assetMap)
|
|
261
|
-
* // Returns the
|
|
262
|
+
* // Returns the cUSD->cREAL->cEUR route (lowest spread: 0.3%)
|
|
262
263
|
* ```
|
|
263
264
|
*/
|
|
264
265
|
export function selectOptimalRoutes(allRoutes, returnAllRoutes, addrToSymbol) {
|
|
265
266
|
const result = new Map();
|
|
266
|
-
for (const [
|
|
267
|
+
for (const [pairId, routes] of allRoutes) {
|
|
267
268
|
if (routes.length === 1) {
|
|
268
269
|
// Only one route available - use it directly
|
|
269
|
-
result.set(
|
|
270
|
+
result.set(pairId, routes[0]);
|
|
270
271
|
}
|
|
271
272
|
else if (returnAllRoutes) {
|
|
272
273
|
// Return all routes with unique keys (used for cache generation)
|
|
273
274
|
routes.forEach((route, index) => {
|
|
274
|
-
result.set(`${
|
|
275
|
+
result.set(`${pairId}_${index}`, route);
|
|
275
276
|
});
|
|
276
277
|
}
|
|
277
278
|
else {
|
|
278
279
|
// Multiple routes - select the best one using optimization logic
|
|
279
280
|
const bestRoute = selectBestRoute(routes, addrToSymbol);
|
|
280
|
-
result.set(
|
|
281
|
+
result.set(pairId, bestRoute);
|
|
281
282
|
}
|
|
282
283
|
}
|
|
283
284
|
return Array.from(result.values());
|
|
284
285
|
}
|
|
285
286
|
/**
|
|
286
|
-
* Selects the best route from candidates using
|
|
287
|
+
* Selects the best route from candidates using spread data or fallback heuristics.
|
|
287
288
|
*
|
|
288
289
|
* This function implements a sophisticated route selection algorithm with
|
|
289
290
|
* multiple optimization tiers:
|
|
290
291
|
*
|
|
291
|
-
* **Tier 1 -
|
|
292
|
-
* - Use routes with
|
|
293
|
-
* - Select route with lowest `
|
|
292
|
+
* **Tier 1 - Spread-Based Optimization** (Preferred):
|
|
293
|
+
* - Use routes with spread data (actual cost information)
|
|
294
|
+
* - Select route with lowest `totalSpreadPercent`
|
|
294
295
|
* - This provides the most cost-efficient trading
|
|
295
296
|
*
|
|
296
297
|
* **Tier 2 - Direct Route Preference** (Fallback):
|
|
297
|
-
* - If no
|
|
298
|
+
* - If no spread data available, prefer direct (single-hop) routes
|
|
298
299
|
* - Direct routes have lower execution risk and gas costs
|
|
299
300
|
*
|
|
300
301
|
* **Tier 3 - Major Stablecoin Preference** (Final Fallback):
|
|
301
302
|
* - For two-hop routes, prefer those going through major stablecoins
|
|
302
|
-
* - Major FX currencies like
|
|
303
|
+
* - Major FX currencies like cUSD and cEUR typically have better liquidity
|
|
303
304
|
*
|
|
304
305
|
* **Tier 4 - First Available** (Last Resort):
|
|
305
306
|
* - If no other heuristics apply, use the first route found
|
|
@@ -311,27 +312,29 @@ export function selectOptimalRoutes(allRoutes, returnAllRoutes, addrToSymbol) {
|
|
|
311
312
|
* @example
|
|
312
313
|
* ```typescript
|
|
313
314
|
* const candidates = [
|
|
314
|
-
* { path: [A->B->C],
|
|
315
|
-
* { path: [A->D->C],
|
|
316
|
-
* { path: [A->C] }, // direct route, no
|
|
315
|
+
* { path: [A->B->C], spreadData: { totalSpreadPercent: 0.8 } },
|
|
316
|
+
* { path: [A->D->C], spreadData: { totalSpreadPercent: 0.4 } }, // Winner: lowest spread
|
|
317
|
+
* { path: [A->C] }, // direct route, no spread data
|
|
317
318
|
* ]
|
|
318
319
|
*
|
|
319
320
|
* const best = selectBestRoute(candidates, assetMap)
|
|
320
|
-
* // Returns the A->D->C route (0.4%
|
|
321
|
+
* // Returns the A->D->C route (0.4% spread)
|
|
321
322
|
* ```
|
|
322
323
|
*/
|
|
323
324
|
export function selectBestRoute(candidates, addrToSymbol) {
|
|
324
|
-
// Tier 1: Prefer routes with
|
|
325
|
-
const
|
|
326
|
-
if (
|
|
327
|
-
return
|
|
325
|
+
// Tier 1: Prefer routes with spread data (lowest spread wins)
|
|
326
|
+
const candidatesWithSpread = candidates.filter(hasSpreadData);
|
|
327
|
+
if (candidatesWithSpread.length > 0) {
|
|
328
|
+
return candidatesWithSpread.reduce((best, current) => current.spreadData.totalSpreadPercent < best.spreadData.totalSpreadPercent
|
|
329
|
+
? current
|
|
330
|
+
: best);
|
|
328
331
|
}
|
|
329
332
|
// Tier 2: Prefer direct routes (single-hop, lower risk)
|
|
330
333
|
const directRoute = candidates.find((c) => c.path.length === 1);
|
|
331
334
|
if (directRoute)
|
|
332
335
|
return directRoute;
|
|
333
336
|
// Tier 3: Prefer routes through major stablecoins (better liquidity)
|
|
334
|
-
const stablecoins = ['
|
|
337
|
+
const stablecoins = ['cUSD', 'cEUR', 'USDC', 'USDT'];
|
|
335
338
|
const routeWithStablecoin = candidates.find((candidate) => {
|
|
336
339
|
const intermediateToken = getIntermediateToken(candidate);
|
|
337
340
|
if (!intermediateToken)
|
|
@@ -349,13 +352,11 @@ export function selectBestRoute(candidates, addrToSymbol) {
|
|
|
349
352
|
export function getIntermediateToken(route) {
|
|
350
353
|
// Find the common token between the two hops
|
|
351
354
|
const [hop1, hop2] = route.path;
|
|
352
|
-
|
|
353
|
-
const hop2Tokens = [hop2.token0, hop2.token1];
|
|
354
|
-
return hop1Tokens.find((addr) => hop2Tokens.includes(addr));
|
|
355
|
+
return hop1.assets.find((addr) => hop2.assets.includes(addr));
|
|
355
356
|
}
|
|
356
357
|
/**
|
|
357
|
-
* Type guard to check if a Route has
|
|
358
|
+
* Type guard to check if a Route has spread data.
|
|
358
359
|
*/
|
|
359
|
-
export function
|
|
360
|
-
return '
|
|
360
|
+
export function hasSpreadData(pair) {
|
|
361
|
+
return 'spreadData' in pair && pair.spreadData !== undefined;
|
|
361
362
|
}
|
|
@@ -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
|
+
};
|
|
@@ -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;
|