@mento-protocol/mento-sdk 2.0.0-beta.9 → 3.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +204 -132
- package/dist/cache/routes.d.ts +13 -0
- package/dist/cache/routes.d.ts.map +1 -0
- package/dist/cache/routes.js +130 -0
- package/dist/cache/routes.js.map +1 -0
- package/dist/cache/tokens.d.ts +67 -0
- package/dist/cache/tokens.d.ts.map +1 -0
- package/dist/cache/tokens.js +379 -0
- package/dist/cache/tokens.js.map +1 -0
- package/dist/core/abis/bipoolmanager.d.ts +34 -0
- package/dist/core/abis/bipoolmanager.d.ts.map +1 -0
- package/dist/core/abis/bipoolmanager.js +72 -0
- package/dist/core/abis/bipoolmanager.js.map +1 -0
- package/dist/core/abis/breakerbox.d.ts +13 -0
- package/dist/core/abis/breakerbox.d.ts.map +1 -0
- package/dist/core/abis/breakerbox.js +8 -0
- package/dist/core/abis/breakerbox.js.map +1 -0
- package/dist/core/abis/broker.d.ts +2 -0
- package/dist/core/abis/broker.d.ts.map +1 -0
- package/dist/core/abis/broker.js +9 -0
- package/dist/core/abis/broker.js.map +1 -0
- package/dist/core/abis/erc20.d.ts +9 -0
- package/dist/core/abis/erc20.d.ts.map +1 -0
- package/dist/core/abis/erc20.js +21 -0
- package/dist/core/abis/erc20.js.map +1 -0
- package/dist/core/abis/fpmm.d.ts +160 -0
- package/dist/core/abis/fpmm.d.ts.map +1 -0
- package/dist/core/abis/fpmm.js +21 -0
- package/dist/core/abis/fpmm.js.map +1 -0
- package/dist/core/abis/fpmmFactory.d.ts +21 -0
- package/dist/core/abis/fpmmFactory.d.ts.map +1 -0
- package/dist/core/abis/fpmmFactory.js +9 -0
- package/dist/core/abis/fpmmFactory.js.map +1 -0
- package/dist/core/abis/index.d.ts +12 -0
- package/dist/core/abis/index.d.ts.map +1 -0
- package/dist/{abis → core/abis}/index.js +6 -0
- package/dist/core/abis/index.js.map +1 -0
- package/dist/core/abis/pricingmodule.d.ts +2 -0
- package/dist/core/abis/pricingmodule.d.ts.map +1 -0
- package/dist/core/abis/pricingmodule.js +6 -0
- package/dist/core/abis/pricingmodule.js.map +1 -0
- package/dist/core/abis/reserve.d.ts +2 -0
- package/dist/core/abis/reserve.d.ts.map +1 -0
- package/dist/core/abis/reserve.js +10 -0
- package/dist/core/abis/reserve.js.map +1 -0
- package/dist/core/abis/router.d.ts +2 -0
- package/dist/core/abis/router.d.ts.map +1 -0
- package/dist/core/abis/router.js +10 -0
- package/dist/core/abis/router.js.map +1 -0
- package/dist/core/abis/uniswapV3.d.ts +4 -0
- package/dist/core/abis/uniswapV3.d.ts.map +1 -0
- package/dist/{abis → core/abis}/uniswapV3.js +7 -6
- package/dist/core/abis/uniswapV3.js.map +1 -0
- package/dist/core/abis/virtualPool.d.ts +40 -0
- package/dist/core/abis/virtualPool.d.ts.map +1 -0
- package/dist/core/abis/virtualPool.js +10 -0
- package/dist/core/abis/virtualPool.js.map +1 -0
- package/dist/core/abis/virtualPoolFactory.d.ts +27 -0
- package/dist/core/abis/virtualPoolFactory.d.ts.map +1 -0
- package/dist/core/abis/virtualPoolFactory.js +9 -0
- package/dist/core/abis/virtualPoolFactory.js.map +1 -0
- package/dist/core/constants/aaveConfig.d.ts.map +1 -0
- package/dist/{constants → core/constants}/aaveConfig.js +2 -2
- package/dist/core/constants/aaveConfig.js.map +1 -0
- package/dist/{constants → core/constants}/addresses.d.ts +4 -5
- package/dist/core/constants/addresses.d.ts.map +1 -0
- package/dist/core/constants/addresses.js +78 -0
- package/dist/core/constants/addresses.js.map +1 -0
- package/dist/core/constants/chainId.d.ts +5 -0
- package/dist/core/constants/chainId.d.ts.map +1 -0
- package/dist/{constants → core/constants}/chainId.js +1 -1
- package/dist/core/constants/chainId.js.map +1 -0
- package/dist/core/constants/contractNames.d.ts.map +1 -0
- package/dist/core/constants/contractNames.js.map +1 -0
- package/dist/{constants → core/constants}/index.d.ts +0 -2
- package/dist/core/constants/index.d.ts.map +1 -0
- package/dist/{constants → core/constants}/index.js +0 -2
- package/dist/core/constants/index.js.map +1 -0
- package/dist/{constants → core/constants}/mentoAddresses.d.ts +2 -0
- package/dist/core/constants/mentoAddresses.d.ts.map +1 -0
- package/dist/{constants → core/constants}/mentoAddresses.js +2 -0
- package/dist/core/constants/mentoAddresses.js.map +1 -0
- package/dist/core/constants/protocolAddresses.d.ts.map +1 -0
- package/dist/core/constants/protocolAddresses.js.map +1 -0
- package/dist/core/errors/base.d.ts +8 -0
- package/dist/core/errors/base.d.ts.map +1 -0
- package/dist/core/errors/base.js +17 -0
- package/dist/core/errors/base.js.map +1 -0
- package/dist/core/errors/index.d.ts +3 -0
- package/dist/core/errors/index.d.ts.map +1 -0
- package/dist/{types → core/errors}/index.js +2 -4
- package/dist/core/errors/index.js.map +1 -0
- package/dist/core/errors/router.d.ts +8 -0
- package/dist/core/errors/router.d.ts.map +1 -0
- package/dist/core/errors/router.js +14 -0
- package/dist/core/errors/router.js.map +1 -0
- package/dist/core/types/contractAddresses.d.ts +41 -0
- package/dist/core/types/contractAddresses.d.ts.map +1 -0
- package/dist/core/types/contractAddresses.js.map +1 -0
- package/dist/core/types/index.d.ts +8 -0
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/core/types/index.js +24 -0
- package/dist/core/types/index.js.map +1 -0
- package/dist/core/types/pool.d.ts +145 -0
- package/dist/core/types/pool.d.ts.map +1 -0
- package/dist/core/types/pool.js +14 -0
- package/dist/core/types/pool.js.map +1 -0
- package/dist/core/types/provider.d.ts +45 -0
- package/dist/core/types/provider.d.ts.map +1 -0
- package/dist/{types → core/types}/provider.js.map +1 -1
- package/dist/core/types/route.d.ts +62 -0
- package/dist/core/types/route.d.ts.map +1 -0
- package/dist/{types/exchange.js → core/types/route.js} +1 -1
- package/dist/core/types/route.js.map +1 -0
- package/dist/{types → core/types}/token.d.ts +16 -6
- package/dist/core/types/token.d.ts.map +1 -0
- package/dist/{types → core/types}/token.js.map +1 -1
- package/dist/core/types/tradingLimits.d.ts +91 -0
- package/dist/core/types/tradingLimits.d.ts.map +1 -0
- package/dist/core/types/tradingLimits.js +3 -0
- package/dist/core/types/tradingLimits.js.map +1 -0
- package/dist/core/types/tradingMode.d.ts +24 -0
- package/dist/core/types/tradingMode.d.ts.map +1 -0
- package/dist/core/types/tradingMode.js +31 -0
- package/dist/core/types/tradingMode.js.map +1 -0
- package/dist/core/types/transaction.d.ts +45 -0
- package/dist/core/types/transaction.d.ts.map +1 -0
- package/dist/core/types/transaction.js +3 -0
- package/dist/core/types/transaction.js.map +1 -0
- package/dist/index.d.ts +50 -109
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -152
- package/dist/index.js.map +1 -1
- package/dist/services/index.d.ts +7 -6
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +7 -6
- package/dist/services/index.js.map +1 -1
- package/dist/services/pools/PoolService.d.ts +49 -0
- package/dist/services/pools/PoolService.d.ts.map +1 -0
- package/dist/services/pools/PoolService.js +92 -0
- package/dist/services/pools/PoolService.js.map +1 -0
- package/dist/services/pools/index.d.ts +2 -0
- package/dist/services/pools/index.d.ts.map +1 -0
- package/dist/services/pools/index.js +18 -0
- package/dist/services/pools/index.js.map +1 -0
- package/dist/services/pools/poolDetails.d.ts +11 -0
- package/dist/services/pools/poolDetails.d.ts.map +1 -0
- package/dist/services/pools/poolDetails.js +136 -0
- package/dist/services/pools/poolDetails.js.map +1 -0
- package/dist/services/pools/poolDiscovery.d.ts +13 -0
- package/dist/services/pools/poolDiscovery.d.ts.map +1 -0
- package/dist/services/pools/poolDiscovery.js +115 -0
- package/dist/services/pools/poolDiscovery.js.map +1 -0
- package/dist/services/quotes/QuoteService.d.ts +50 -0
- package/dist/services/quotes/QuoteService.d.ts.map +1 -0
- package/dist/services/quotes/QuoteService.js +74 -0
- package/dist/services/quotes/QuoteService.js.map +1 -0
- package/dist/services/quotes/index.d.ts +2 -0
- package/dist/services/quotes/index.d.ts.map +1 -0
- package/dist/services/quotes/index.js +18 -0
- package/dist/services/quotes/index.js.map +1 -0
- package/dist/services/routes/RouteService.d.ts +109 -0
- package/dist/services/routes/RouteService.d.ts.map +1 -0
- package/dist/services/routes/RouteService.js +239 -0
- package/dist/services/routes/RouteService.js.map +1 -0
- package/dist/services/routes/index.d.ts +2 -0
- package/dist/services/routes/index.d.ts.map +1 -0
- package/dist/services/routes/index.js +18 -0
- package/dist/services/routes/index.js.map +1 -0
- package/dist/services/swap/SwapService.d.ts +162 -0
- package/dist/services/swap/SwapService.d.ts.map +1 -0
- package/dist/services/swap/SwapService.js +180 -0
- package/dist/services/swap/SwapService.js.map +1 -0
- package/dist/services/swap/index.d.ts +2 -0
- package/dist/services/swap/index.d.ts.map +1 -0
- package/dist/services/swap/index.js +18 -0
- package/dist/services/swap/index.js.map +1 -0
- package/dist/services/tokens/index.d.ts +2 -0
- package/dist/services/tokens/index.d.ts.map +1 -0
- package/dist/services/tokens/index.js +18 -0
- package/dist/services/tokens/index.js.map +1 -0
- package/dist/services/tokens/supply/ISupplyCalculator.d.ts.map +1 -0
- package/dist/services/tokens/supply/ISupplyCalculator.js.map +1 -0
- package/dist/services/{supply → tokens/supply}/aaveSupplyCalculator.d.ts +4 -3
- package/dist/services/tokens/supply/aaveSupplyCalculator.d.ts.map +1 -0
- package/dist/services/{supply → tokens/supply}/aaveSupplyCalculator.js +7 -7
- package/dist/services/tokens/supply/aaveSupplyCalculator.js.map +1 -0
- package/dist/services/tokens/supply/calculatorFactory.d.ts +8 -0
- package/dist/services/tokens/supply/calculatorFactory.d.ts.map +1 -0
- package/dist/services/tokens/supply/calculatorFactory.js.map +1 -0
- package/dist/services/tokens/supply/defaultCalculatorFactory.d.ts +9 -0
- package/dist/services/tokens/supply/defaultCalculatorFactory.d.ts.map +1 -0
- package/dist/services/{supply → tokens/supply}/defaultCalculatorFactory.js +12 -7
- package/dist/services/tokens/supply/defaultCalculatorFactory.js.map +1 -0
- package/dist/services/tokens/supply/index.d.ts.map +1 -0
- package/dist/services/tokens/supply/index.js.map +1 -0
- package/dist/services/tokens/supply/multisigSupplyCalculator.d.ts +9 -0
- package/dist/services/tokens/supply/multisigSupplyCalculator.d.ts.map +1 -0
- package/dist/services/tokens/supply/multisigSupplyCalculator.js +33 -0
- package/dist/services/tokens/supply/multisigSupplyCalculator.js.map +1 -0
- package/dist/services/{supply → tokens/supply}/uniV3SupplyCalculator.d.ts +3 -3
- package/dist/services/tokens/supply/uniV3SupplyCalculator.d.ts.map +1 -0
- package/dist/services/{supply → tokens/supply}/uniV3SupplyCalculator.js +11 -6
- package/dist/services/tokens/supply/uniV3SupplyCalculator.js.map +1 -0
- package/dist/services/{supplyAdjustmentService.d.ts → tokens/supplyAdjustmentService.d.ts} +3 -2
- package/dist/services/tokens/supplyAdjustmentService.d.ts.map +1 -0
- package/dist/services/{supplyAdjustmentService.js → tokens/supplyAdjustmentService.js} +11 -13
- package/dist/services/tokens/supplyAdjustmentService.js.map +1 -0
- package/dist/services/tokens/tokenService.d.ts +33 -0
- package/dist/services/tokens/tokenService.d.ts.map +1 -0
- package/dist/services/tokens/tokenService.js +136 -0
- package/dist/services/tokens/tokenService.js.map +1 -0
- package/dist/services/trading/TradingLimitsService.d.ts +38 -0
- package/dist/services/trading/TradingLimitsService.d.ts.map +1 -0
- package/dist/services/trading/TradingLimitsService.js +157 -0
- package/dist/services/trading/TradingLimitsService.js.map +1 -0
- package/dist/services/trading/TradingService.d.ts +110 -0
- package/dist/services/trading/TradingService.d.ts.map +1 -0
- package/dist/services/trading/TradingService.js +162 -0
- package/dist/services/trading/TradingService.js.map +1 -0
- package/dist/services/trading/index.d.ts +3 -0
- package/dist/services/trading/index.d.ts.map +1 -0
- package/dist/services/trading/index.js +19 -0
- package/dist/services/trading/index.js.map +1 -0
- package/dist/utils/chainConfig.d.ts +16 -0
- package/dist/utils/chainConfig.d.ts.map +1 -0
- package/dist/utils/chainConfig.js +62 -0
- package/dist/utils/chainConfig.js.map +1 -0
- package/dist/utils/costUtils.d.ts +12 -0
- package/dist/utils/costUtils.d.ts.map +1 -0
- package/dist/utils/costUtils.js +59 -0
- package/dist/utils/costUtils.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/pathEncoder.d.ts +29 -0
- package/dist/utils/pathEncoder.d.ts.map +1 -0
- package/dist/utils/pathEncoder.js +73 -0
- package/dist/utils/pathEncoder.js.map +1 -0
- package/dist/utils/rateFeed.d.ts +18 -0
- package/dist/utils/rateFeed.d.ts.map +1 -0
- package/dist/utils/rateFeed.js +27 -0
- package/dist/utils/rateFeed.js.map +1 -0
- package/dist/utils/routeUtils.d.ts +295 -0
- package/dist/utils/routeUtils.d.ts.map +1 -0
- package/dist/utils/routeUtils.js +371 -0
- package/dist/utils/routeUtils.js.map +1 -0
- package/dist/utils/routes.d.ts +3 -0
- package/dist/utils/routes.d.ts.map +1 -0
- package/dist/utils/routes.js +8 -0
- package/dist/utils/routes.js.map +1 -0
- package/dist/utils/sortUtils.d.ts +24 -0
- package/dist/utils/sortUtils.d.ts.map +1 -0
- package/dist/utils/sortUtils.js +39 -0
- package/dist/utils/sortUtils.js.map +1 -0
- package/dist/utils/tokens.d.ts +2 -0
- package/dist/utils/tokens.d.ts.map +1 -0
- package/dist/utils/tokens.js +13 -0
- package/dist/utils/tokens.js.map +1 -0
- package/dist/utils/tradingLimits.d.ts +41 -0
- package/dist/utils/tradingLimits.d.ts.map +1 -0
- package/dist/utils/tradingLimits.js +171 -0
- package/dist/utils/tradingLimits.js.map +1 -0
- package/dist/utils/validation.d.ts +19 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +34 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +10 -23
- package/dist/abis/bipoolmanager.d.ts +0 -15
- package/dist/abis/bipoolmanager.d.ts.map +0 -1
- package/dist/abis/bipoolmanager.js +0 -26
- package/dist/abis/bipoolmanager.js.map +0 -1
- package/dist/abis/broker.d.ts +0 -2
- package/dist/abis/broker.d.ts.map +0 -1
- package/dist/abis/broker.js +0 -15
- package/dist/abis/broker.js.map +0 -1
- package/dist/abis/erc20.d.ts +0 -2
- package/dist/abis/erc20.d.ts.map +0 -1
- package/dist/abis/erc20.js +0 -11
- package/dist/abis/erc20.js.map +0 -1
- package/dist/abis/index.d.ts +0 -6
- package/dist/abis/index.d.ts.map +0 -1
- package/dist/abis/index.js.map +0 -1
- package/dist/abis/pricingmodule.d.ts +0 -2
- package/dist/abis/pricingmodule.d.ts.map +0 -1
- package/dist/abis/pricingmodule.js +0 -5
- package/dist/abis/pricingmodule.js.map +0 -1
- package/dist/abis/reserve.d.ts +0 -2
- package/dist/abis/reserve.d.ts.map +0 -1
- package/dist/abis/reserve.js +0 -9
- package/dist/abis/reserve.js.map +0 -1
- package/dist/abis/uniswapV3.d.ts +0 -4
- package/dist/abis/uniswapV3.d.ts.map +0 -1
- package/dist/abis/uniswapV3.js.map +0 -1
- package/dist/adapters/implementations/ethersAdapter.d.ts +0 -13
- package/dist/adapters/implementations/ethersAdapter.d.ts.map +0 -1
- package/dist/adapters/implementations/ethersAdapter.js +0 -92
- package/dist/adapters/implementations/ethersAdapter.js.map +0 -1
- package/dist/adapters/implementations/ethersV5Adapter.d.ts +0 -13
- package/dist/adapters/implementations/ethersV5Adapter.d.ts.map +0 -1
- package/dist/adapters/implementations/ethersV5Adapter.js +0 -92
- package/dist/adapters/implementations/ethersV5Adapter.js.map +0 -1
- package/dist/adapters/implementations/viemAdapter.d.ts +0 -18
- package/dist/adapters/implementations/viemAdapter.d.ts.map +0 -1
- package/dist/adapters/implementations/viemAdapter.js +0 -126
- package/dist/adapters/implementations/viemAdapter.js.map +0 -1
- package/dist/adapters/index.d.ts +0 -5
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/index.js +0 -10
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/proxies/ethersAdapterProxy.d.ts +0 -26
- package/dist/adapters/proxies/ethersAdapterProxy.d.ts.map +0 -1
- package/dist/adapters/proxies/ethersAdapterProxy.js +0 -78
- package/dist/adapters/proxies/ethersAdapterProxy.js.map +0 -1
- package/dist/adapters/proxies/ethersV5AdapterProxy.d.ts +0 -26
- package/dist/adapters/proxies/ethersV5AdapterProxy.d.ts.map +0 -1
- package/dist/adapters/proxies/ethersV5AdapterProxy.js +0 -78
- package/dist/adapters/proxies/ethersV5AdapterProxy.js.map +0 -1
- package/dist/adapters/proxies/viemAdapterProxy.d.ts +0 -29
- package/dist/adapters/proxies/viemAdapterProxy.d.ts.map +0 -1
- package/dist/adapters/proxies/viemAdapterProxy.js +0 -78
- package/dist/adapters/proxies/viemAdapterProxy.js.map +0 -1
- package/dist/constants/aaveConfig.d.ts.map +0 -1
- package/dist/constants/aaveConfig.js.map +0 -1
- package/dist/constants/addresses.d.ts.map +0 -1
- package/dist/constants/addresses.js +0 -61
- package/dist/constants/addresses.js.map +0 -1
- package/dist/constants/chainId.d.ts +0 -5
- package/dist/constants/chainId.d.ts.map +0 -1
- package/dist/constants/chainId.js.map +0 -1
- package/dist/constants/contractNames.d.ts.map +0 -1
- package/dist/constants/contractNames.js.map +0 -1
- package/dist/constants/index.d.ts.map +0 -1
- package/dist/constants/index.js.map +0 -1
- package/dist/constants/mentoAddresses.d.ts.map +0 -1
- package/dist/constants/mentoAddresses.js.map +0 -1
- package/dist/constants/proposalState.d.ts +0 -11
- package/dist/constants/proposalState.d.ts.map +0 -1
- package/dist/constants/proposalState.js +0 -15
- package/dist/constants/proposalState.js.map +0 -1
- package/dist/constants/protocolAddresses.d.ts.map +0 -1
- package/dist/constants/protocolAddresses.js.map +0 -1
- package/dist/constants/stableTokenMetadata.d.ts +0 -12
- package/dist/constants/stableTokenMetadata.d.ts.map +0 -1
- package/dist/constants/stableTokenMetadata.js +0 -14
- package/dist/constants/stableTokenMetadata.js.map +0 -1
- package/dist/services/collateralAssetService.d.ts +0 -8
- package/dist/services/collateralAssetService.d.ts.map +0 -1
- package/dist/services/collateralAssetService.js +0 -47
- package/dist/services/collateralAssetService.js.map +0 -1
- package/dist/services/stableTokenService.d.ts +0 -9
- package/dist/services/stableTokenService.d.ts.map +0 -1
- package/dist/services/stableTokenService.js +0 -40
- package/dist/services/stableTokenService.js.map +0 -1
- package/dist/services/supply/ISupplyCalculator.d.ts.map +0 -1
- package/dist/services/supply/ISupplyCalculator.js.map +0 -1
- package/dist/services/supply/aaveSupplyCalculator.d.ts.map +0 -1
- package/dist/services/supply/aaveSupplyCalculator.js.map +0 -1
- package/dist/services/supply/calculatorFactory.d.ts +0 -8
- package/dist/services/supply/calculatorFactory.d.ts.map +0 -1
- package/dist/services/supply/calculatorFactory.js.map +0 -1
- package/dist/services/supply/defaultCalculatorFactory.d.ts +0 -9
- package/dist/services/supply/defaultCalculatorFactory.d.ts.map +0 -1
- package/dist/services/supply/defaultCalculatorFactory.js.map +0 -1
- package/dist/services/supply/index.d.ts.map +0 -1
- package/dist/services/supply/index.js.map +0 -1
- package/dist/services/supply/multisigSupplyCalculator.d.ts +0 -9
- package/dist/services/supply/multisigSupplyCalculator.d.ts.map +0 -1
- package/dist/services/supply/multisigSupplyCalculator.js +0 -21
- package/dist/services/supply/multisigSupplyCalculator.js.map +0 -1
- package/dist/services/supply/uniV3SupplyCalculator.d.ts.map +0 -1
- package/dist/services/supply/uniV3SupplyCalculator.js.map +0 -1
- package/dist/services/supplyAdjustmentService.d.ts.map +0 -1
- package/dist/services/supplyAdjustmentService.js.map +0 -1
- package/dist/services/swapService.d.ts +0 -70
- package/dist/services/swapService.d.ts.map +0 -1
- package/dist/services/swapService.js +0 -134
- package/dist/services/swapService.js.map +0 -1
- package/dist/services/tokenMetadataService.d.ts +0 -8
- package/dist/services/tokenMetadataService.d.ts.map +0 -1
- package/dist/services/tokenMetadataService.js +0 -44
- package/dist/services/tokenMetadataService.js.map +0 -1
- package/dist/types/contractAddresses.d.ts +0 -23
- package/dist/types/contractAddresses.d.ts.map +0 -1
- package/dist/types/contractAddresses.js.map +0 -1
- package/dist/types/exchange.d.ts +0 -6
- package/dist/types/exchange.d.ts.map +0 -1
- package/dist/types/exchange.js.map +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/provider.d.ts +0 -29
- package/dist/types/provider.d.ts.map +0 -1
- package/dist/types/token.d.ts.map +0 -1
- /package/dist/{constants → core/constants}/aaveConfig.d.ts +0 -0
- /package/dist/{constants → core/constants}/contractNames.d.ts +0 -0
- /package/dist/{constants → core/constants}/contractNames.js +0 -0
- /package/dist/{constants → core/constants}/protocolAddresses.d.ts +0 -0
- /package/dist/{constants → core/constants}/protocolAddresses.js +0 -0
- /package/dist/{types → core/types}/contractAddresses.js +0 -0
- /package/dist/{types → core/types}/provider.js +0 -0
- /package/dist/{types → core/types}/token.js +0 -0
- /package/dist/services/{supply → tokens/supply}/ISupplyCalculator.d.ts +0 -0
- /package/dist/services/{supply → tokens/supply}/ISupplyCalculator.js +0 -0
- /package/dist/services/{supply → tokens/supply}/calculatorFactory.js +0 -0
- /package/dist/services/{supply → tokens/supply}/index.d.ts +0 -0
- /package/dist/services/{supply → tokens/supply}/index.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
|
package/dist/utils/index.js
CHANGED
|
@@ -15,4 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./retry"), exports);
|
|
18
|
+
__exportStar(require("./chainConfig"), exports);
|
|
19
|
+
__exportStar(require("./routes"), exports);
|
|
20
|
+
__exportStar(require("./sortUtils"), exports);
|
|
21
|
+
__exportStar(require("./pathEncoder"), exports);
|
|
22
|
+
__exportStar(require("./tokens"), exports);
|
|
23
|
+
__exportStar(require("./rateFeed"), exports);
|
|
24
|
+
__exportStar(require("./tradingLimits"), exports);
|
|
18
25
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,gDAA6B;AAC7B,2CAAwB;AACxB,8CAA2B;AAC3B,gDAA6B;AAC7B,2CAAwB;AACxB,6CAA0B;AAC1B,kDAA+B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { Pool } from '../core/types';
|
|
3
|
+
/**
|
|
4
|
+
* Route structure expected by the Router contract's getAmountsOut and swapTokensForTokens functions
|
|
5
|
+
*/
|
|
6
|
+
export interface RouterRoute {
|
|
7
|
+
from: Address;
|
|
8
|
+
to: Address;
|
|
9
|
+
factory: Address;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Converts a route path to the format expected by the Router contract.
|
|
13
|
+
* Used by both QuoteService (getAmountsOut) and SwapService (swapTokensForTokens).
|
|
14
|
+
*
|
|
15
|
+
* @param path - The route path (array of pools)
|
|
16
|
+
* @param tokenIn - The input token address (determines swap direction)
|
|
17
|
+
* @param _tokenOut - The output token address (unused but kept for API clarity)
|
|
18
|
+
* @returns Array of RouterRoute objects for the contract call
|
|
19
|
+
* @throws {Error} If path is empty, too long, or contains invalid pools
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const route = await routeService.findRoute(USDm, CELO)
|
|
24
|
+
* const routerRoutes = encodeRoutePath(route.path, USDm, CELO)
|
|
25
|
+
* // routerRoutes can now be passed to Router.getAmountsOut or Router.swapTokensForTokens
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function encodeRoutePath(path: Pool[], tokenIn: Address, _tokenOut: Address): RouterRoute[];
|
|
29
|
+
//# sourceMappingURL=pathEncoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathEncoder.d.ts","sourceRoot":"","sources":["../../src/utils/pathEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEpC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,CAAA;IACb,EAAE,EAAE,OAAO,CAAA;IACX,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,GAAG,WAAW,EAAE,CAmEjG"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeRoutePath = encodeRoutePath;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a route path to the format expected by the Router contract.
|
|
6
|
+
* Used by both QuoteService (getAmountsOut) and SwapService (swapTokensForTokens).
|
|
7
|
+
*
|
|
8
|
+
* @param path - The route path (array of pools)
|
|
9
|
+
* @param tokenIn - The input token address (determines swap direction)
|
|
10
|
+
* @param _tokenOut - The output token address (unused but kept for API clarity)
|
|
11
|
+
* @returns Array of RouterRoute objects for the contract call
|
|
12
|
+
* @throws {Error} If path is empty, too long, or contains invalid pools
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const route = await routeService.findRoute(USDm, CELO)
|
|
17
|
+
* const routerRoutes = encodeRoutePath(route.path, USDm, CELO)
|
|
18
|
+
* // routerRoutes can now be passed to Router.getAmountsOut or Router.swapTokensForTokens
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function encodeRoutePath(path, tokenIn, _tokenOut) {
|
|
22
|
+
// Validate path is not empty
|
|
23
|
+
if (!path || path.length === 0) {
|
|
24
|
+
throw new Error('Internal error: Route path is empty. This should not happen - routes are validated before encoding.');
|
|
25
|
+
}
|
|
26
|
+
// Validate all pools have required structure
|
|
27
|
+
for (let i = 0; i < path.length; i++) {
|
|
28
|
+
const pool = path[i];
|
|
29
|
+
if (!pool.token0 || !pool.token1 || !pool.factoryAddr) {
|
|
30
|
+
throw new Error(`Invalid pool structure at index ${i}: missing required fields. ` +
|
|
31
|
+
`Pool must have token0, token1, and factoryAddr. ` +
|
|
32
|
+
`Got: ${JSON.stringify(pool)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const routes = [];
|
|
36
|
+
const tokenInLower = tokenIn.toLowerCase();
|
|
37
|
+
// Check if we need to reverse the path
|
|
38
|
+
// The path is stored in canonical order, but we may need to traverse it backwards
|
|
39
|
+
const firstPool = path[0];
|
|
40
|
+
const startsWithTokenIn = firstPool.token0.toLowerCase() === tokenInLower || firstPool.token1.toLowerCase() === tokenInLower;
|
|
41
|
+
// If tokenIn isn't in the first pool, reverse the path
|
|
42
|
+
const orderedPath = startsWithTokenIn ? path : [...path].reverse();
|
|
43
|
+
let currentTokenIn = tokenInLower;
|
|
44
|
+
for (const pool of orderedPath) {
|
|
45
|
+
const token0 = pool.token0.toLowerCase();
|
|
46
|
+
const token1 = pool.token1.toLowerCase();
|
|
47
|
+
// Determine direction: which token is the input for this hop?
|
|
48
|
+
let from;
|
|
49
|
+
let to;
|
|
50
|
+
if (currentTokenIn === token0) {
|
|
51
|
+
from = pool.token0;
|
|
52
|
+
to = pool.token1;
|
|
53
|
+
}
|
|
54
|
+
else if (currentTokenIn === token1) {
|
|
55
|
+
from = pool.token1;
|
|
56
|
+
to = pool.token0;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error(`Route encoding error: Token ${currentTokenIn} not found in pool ${pool.poolAddr}. ` +
|
|
60
|
+
`Pool contains tokens: ${token0}, ${token1}. ` +
|
|
61
|
+
`This indicates the route path is invalid or tokens don't form a connected path.`);
|
|
62
|
+
}
|
|
63
|
+
routes.push({
|
|
64
|
+
from,
|
|
65
|
+
to,
|
|
66
|
+
factory: pool.factoryAddr,
|
|
67
|
+
});
|
|
68
|
+
// The output of this hop becomes the input of the next hop
|
|
69
|
+
currentTokenIn = to.toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
return routes;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=pathEncoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathEncoder.js","sourceRoot":"","sources":["../../src/utils/pathEncoder.ts"],"names":[],"mappings":";;AA6BA,0CAmEC;AApFD;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,eAAe,CAAC,IAAY,EAAE,OAAgB,EAAE,SAAkB;IAChF,6BAA6B;IAC7B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,qGAAqG,CACtG,CAAA;IACH,CAAC;IAED,6CAA6C;IAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;QACpB,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CACb,mCAAmC,CAAC,6BAA6B;gBACjE,kDAAkD;gBAClD,QAAQ,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAC/B,CAAA;QACH,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAkB,EAAE,CAAA;IAChC,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;IAE1C,uCAAuC;IACvC,kFAAkF;IAClF,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACzB,MAAM,iBAAiB,GACrB,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,YAAY,IAAI,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,YAAY,CAAA;IAEpG,uDAAuD;IACvD,MAAM,WAAW,GAAG,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,OAAO,EAAE,CAAA;IAElE,IAAI,cAAc,GAAG,YAAY,CAAA;IAEjC,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAA;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAA;QAExC,8DAA8D;QAC9D,IAAI,IAAa,CAAA;QACjB,IAAI,EAAW,CAAA;QAEf,IAAI,cAAc,KAAK,MAAM,EAAE,CAAC;YAC9B,IAAI,GAAG,IAAI,CAAC,MAAiB,CAAA;YAC7B,EAAE,GAAG,IAAI,CAAC,MAAiB,CAAA;QAC7B,CAAC;aAAM,IAAI,cAAc,KAAK,MAAM,EAAE,CAAC;YACrC,IAAI,GAAG,IAAI,CAAC,MAAiB,CAAA;YAC7B,EAAE,GAAG,IAAI,CAAC,MAAiB,CAAA;QAC7B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,+BAA+B,cAAc,sBAAsB,IAAI,CAAC,QAAQ,IAAI;gBACpF,yBAAyB,MAAM,KAAK,MAAM,IAAI;gBAC9C,iFAAiF,CAClF,CAAA;QACH,CAAC;QAED,MAAM,CAAC,IAAI,CAAC;YACV,IAAI;YACJ,EAAE;YACF,OAAO,EAAE,IAAI,CAAC,WAAsB;SACrC,CAAC,CAAA;QAEF,2DAA2D;QAC3D,cAAc,GAAG,EAAE,CAAC,WAAW,EAAE,CAAA;IACnC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the rate feed ID from a rate feed identifier string.
|
|
3
|
+
* Follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
4
|
+
*
|
|
5
|
+
* @param rateFeed - The rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
6
|
+
* @returns The computed rate feed address as a hex string
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const rateFeedId = toRateFeedId('EURUSD')
|
|
11
|
+
* // Returns the computed address for the EURUSD rate feed
|
|
12
|
+
*
|
|
13
|
+
* const relayedRateFeedId = toRateFeedId('relayed:COPUSD')
|
|
14
|
+
* // Returns the computed address for the relayed COPUSD rate feed
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function toRateFeedId(rateFeed: string): `0x${string}`;
|
|
18
|
+
//# sourceMappingURL=rateFeed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateFeed.d.ts","sourceRoot":"","sources":["../../src/utils/rateFeed.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAM5D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRateFeedId = toRateFeedId;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
/**
|
|
6
|
+
* Computes the rate feed ID from a rate feed identifier string.
|
|
7
|
+
* Follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
8
|
+
*
|
|
9
|
+
* @param rateFeed - The rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
10
|
+
* @returns The computed rate feed address as a hex string
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const rateFeedId = toRateFeedId('EURUSD')
|
|
15
|
+
* // Returns the computed address for the EURUSD rate feed
|
|
16
|
+
*
|
|
17
|
+
* const relayedRateFeedId = toRateFeedId('relayed:COPUSD')
|
|
18
|
+
* // Returns the computed address for the relayed COPUSD rate feed
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function toRateFeedId(rateFeed) {
|
|
22
|
+
const hashedBytes = (0, viem_1.keccak256)((0, viem_1.toBytes)(rateFeed));
|
|
23
|
+
const hashAsBigInt = BigInt(hashedBytes);
|
|
24
|
+
const maskedToUint160 = hashAsBigInt & ((1n << 160n) - 1n);
|
|
25
|
+
return `0x${maskedToUint160.toString(16).padStart(40, '0')}`;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=rateFeed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateFeed.js","sourceRoot":"","sources":["../../src/utils/rateFeed.ts"],"names":[],"mappings":";;AAkBA,oCAMC;AAxBD,+BAAyC;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,YAAY,CAAC,QAAgB;IAC3C,MAAM,WAAW,GAAG,IAAA,gBAAS,EAAC,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC,CAAA;IAChD,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;IACxC,MAAM,eAAe,GAAG,YAAY,GAAG,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IAE1D,OAAO,KAAK,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAA;AAC9D,CAAC"}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import type { Route, RouteID, RouteWithCost, Pool } from '../core/types';
|
|
2
|
+
type TokenSymbol = string;
|
|
3
|
+
type Address = string;
|
|
4
|
+
/**
|
|
5
|
+
* =============================================================================
|
|
6
|
+
* ROUTE GENERATION UTILITIES
|
|
7
|
+
* =============================================================================
|
|
8
|
+
*
|
|
9
|
+
* Utilities for generating optimal trading routes in the Mento protocol.
|
|
10
|
+
*
|
|
11
|
+
* The main workflow is:
|
|
12
|
+
*
|
|
13
|
+
* 1. Build connectivity structures from direct trading pairs
|
|
14
|
+
* 2. Generate all possible routes (direct + two-hop)
|
|
15
|
+
* 3. Select optimal routes using cost data or heuristics
|
|
16
|
+
*
|
|
17
|
+
* ALGORITHM OVERVIEW:
|
|
18
|
+
* - Creates a graph where tokens are nodes and direct exchanges are edges
|
|
19
|
+
* - Uses graph traversal to find two-hop routes through intermediate tokens
|
|
20
|
+
* - Optimizes route selection based on cost data when available
|
|
21
|
+
* - Falls back to heuristics (prefer direct routes, major stablecoins)
|
|
22
|
+
* =============================================================================
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Connectivity data structure that represents the token graph connecting all tokens.
|
|
26
|
+
* Helps to efficiently answer: "How can I trade from token A to token B?"
|
|
27
|
+
*
|
|
28
|
+
* CONCRETE EXAMPLE:
|
|
29
|
+
* Given these direct trading pairs:
|
|
30
|
+
* - USDm ↔ CELO (direct exchange exists)
|
|
31
|
+
* - CELO ↔ EURm (direct exchange exists)
|
|
32
|
+
* - USDm ↔ BRLm (direct exchange exists)
|
|
33
|
+
*
|
|
34
|
+
* How route finding works:
|
|
35
|
+
* - Direct route: USDm → EURm? Check token graph: USDm connects to [CELO, BRLm], none is EURm → No direct route
|
|
36
|
+
* - Two-hop route: USDm → ? → EURm?
|
|
37
|
+
* - USDm connects to CELO, CELO connects to EURm → Found route: USDm → CELO → EURm
|
|
38
|
+
* - USDm connects to BRLm, BRLm connects to [USDm] → No route via BRLm
|
|
39
|
+
*
|
|
40
|
+
* The "connectivity" part means we can quickly traverse the network of
|
|
41
|
+
* token connections to find all possible trading paths.
|
|
42
|
+
*/
|
|
43
|
+
export interface ConnectivityData {
|
|
44
|
+
/** Maps token address to symbol for efficient lookups
|
|
45
|
+
*
|
|
46
|
+
* ```
|
|
47
|
+
* '0x765D...' → 'USDm'
|
|
48
|
+
* '0x471E...' → 'CELO'
|
|
49
|
+
* '0xD876...' → 'EURm'
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
addrToSymbol: Map<Address, TokenSymbol>;
|
|
53
|
+
/** Adjacency list mapping which tokens connect to which
|
|
54
|
+
* Used for finding two-hop routes by traversing token → neighbor → neighbor.
|
|
55
|
+
*
|
|
56
|
+
* Example for a USDm => EURm swap: First we find USDm → [CELO, KESm, ...]
|
|
57
|
+
* Then we find CELO → [USDm, EURm, ...] = found route via USDm → CELO → EURm
|
|
58
|
+
*
|
|
59
|
+
* ```
|
|
60
|
+
* 'USDm_addr' → Set(['CELO_addr', 'KESm_addr']) // USDm connects to CELO and KESm
|
|
61
|
+
* 'CELO_addr' → Set(['USDm_addr', 'EURm_addr']) // CELO connects to USDm and EURm
|
|
62
|
+
* 'EURm_addr' → Set(['CELO_addr']) // EURm connects to CELO
|
|
63
|
+
* 'KESm_addr' → Set(['USDm_addr']) // KESm connects to USDm
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
tokenGraph: Map<Address, Set<Address>>;
|
|
67
|
+
/** Maps sorted token address pairs to their direct route details
|
|
68
|
+
* ```
|
|
69
|
+
* 'CELO_addr-EURm_addr' → { route details for CELO ↔ EURm }
|
|
70
|
+
* 'CELO_addr-USDm_addr' → { route details for CELO ↔ USDm }
|
|
71
|
+
* 'USDm_addr-KESm_addr' → { route details for USDm ↔ KESm }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
directRouteMap: Map<RouteID, Pool>;
|
|
75
|
+
/** Original direct routes from mento.getDirectRoutes() for reference */
|
|
76
|
+
directRoutes: Route[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Builds the connectivity data structures needed for route generation.
|
|
80
|
+
*
|
|
81
|
+
* Transforms a list of direct trading pairs into our ConnectivityData
|
|
82
|
+
* that allow us to quickly find trading routes.
|
|
83
|
+
*
|
|
84
|
+
* **Construction Process:**
|
|
85
|
+
*
|
|
86
|
+
* ```
|
|
87
|
+
* Input: TradablePairs = [
|
|
88
|
+
* { id: 'USDm-CELO', assets: [USDm, CELO], path: [exchange1_CELO_USDm] },
|
|
89
|
+
* { id: 'CELO-EURm', assets: [CELO, EURm], path: [exchange2_CELO_EURm] }
|
|
90
|
+
* ]
|
|
91
|
+
*
|
|
92
|
+
* Step 1 - Build addrToSymbol map:
|
|
93
|
+
* USDm.address → 'USDm'
|
|
94
|
+
* CELO.address → 'CELO'
|
|
95
|
+
* EURm.address → 'EURm'
|
|
96
|
+
*
|
|
97
|
+
* Step 2 - Build directPathMap (sorted alphabetically for consistency):
|
|
98
|
+
* 'CELO_addr-EURm_addr' → exchange2_CELO_EURm
|
|
99
|
+
* 'CELO_addr-USDm_addr' → exchange1_CELO_USDm
|
|
100
|
+
*
|
|
101
|
+
* Step 3 - Build bidirectional tokenGraph:
|
|
102
|
+
* USDm.address → Set([CELO.address])
|
|
103
|
+
* CELO.address → Set([USDm.address, EURm.address])
|
|
104
|
+
* EURm.address → Set([CELO.address])
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* **Result**: We can now efficiently answer:
|
|
108
|
+
* - "What's the symbol for address X?" → addrToSymbol.get(addr)
|
|
109
|
+
* - "What exchange connects tokens X and Y?" → directPathMap.get(sortedAddressPairKey)
|
|
110
|
+
* - "What tokens can I reach from token X?" → tokenGraph.get(X)
|
|
111
|
+
*
|
|
112
|
+
* @param directRoutes - Array of direct trading pairs
|
|
113
|
+
* @returns Connectivity data structure for efficient route generation
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const directPairs = [
|
|
118
|
+
* { id: 'USDm-CELO', assets: [USDm, CELO], path: [exchange1] },
|
|
119
|
+
* { id: 'CELO-EURm', assets: [CELO, EURm], path: [exchange2] }
|
|
120
|
+
* ]
|
|
121
|
+
*
|
|
122
|
+
* const connectivityData = buildConnectivityStructures(directPairs)
|
|
123
|
+
*
|
|
124
|
+
* // Now we can efficiently find routes:
|
|
125
|
+
* // 1. Check if USDm connects to anything: connectivityData.tokenGraph.get(USDm.address) → [CELO.address]
|
|
126
|
+
* // 2. Check if CELO connects to EURm: connectivityData.tokenGraph.get(CELO.address) → [USDm.address, EURm.address] ✓
|
|
127
|
+
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-EURm_addr') → exchange2_CELO_EURm
|
|
128
|
+
* // Result: Found route USDm → CELO → EURm with exchange details
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare function buildConnectivityStructures(directRoutes: Route[]): ConnectivityData;
|
|
132
|
+
/**
|
|
133
|
+
* Generates all possible routes (direct + two-hop) using connectivity data.
|
|
134
|
+
*
|
|
135
|
+
* This function implements a route discovery algorithm that:
|
|
136
|
+
*
|
|
137
|
+
* 1. **Adds all direct routes** (single-hop routes)
|
|
138
|
+
* 2. **Discovers two-hop routes** using graph traversal:
|
|
139
|
+
* - For each token A, find its neighbors (tokens directly connected)
|
|
140
|
+
* - For each neighbor B, find B's neighbors
|
|
141
|
+
* - If B connects to token C (C ≠ A), then A->B->C is a valid route
|
|
142
|
+
*
|
|
143
|
+
* **Route Deduplication**: Multiple routes between the same token pair
|
|
144
|
+
* are collected in arrays, allowing the selection algorithm to choose
|
|
145
|
+
* the best one based on cost data or heuristics.
|
|
146
|
+
*
|
|
147
|
+
* **Canonical Route IDs**: All routes use alphabetically sorted symbols
|
|
148
|
+
* (e.g., 'EURm-USDm' not 'USDm-EURm') for consistent identification.
|
|
149
|
+
*
|
|
150
|
+
* @param connectivityData - The connectivity data from buildConnectivityStructures()
|
|
151
|
+
* @returns Map of route ID -> array of possible routes for that token pair
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* // Given direct routes: USDm-CELO, CELO-EURm, USDm-USDC
|
|
156
|
+
* const allRoutes = generateAllRoutes(connectivityData)
|
|
157
|
+
*
|
|
158
|
+
* // Results might include:
|
|
159
|
+
* // 'USDm-CELO' -> [{ path: [USDm->CELO] }] // direct route
|
|
160
|
+
* // 'EURm-USDm' -> [
|
|
161
|
+
* // { path: [USDm->USDC, USDC->EURm] } // two-hop via USDC
|
|
162
|
+
* // { path: [USDm->CELO, CELO->EURm] } // two-hop via CELO
|
|
163
|
+
* // ]
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export declare function generateAllRoutes(connectivityData: ConnectivityData): Map<RouteID, Route[]>;
|
|
167
|
+
/**
|
|
168
|
+
* Creates a two-hop tradable pair if valid exchange hops exist.
|
|
169
|
+
*
|
|
170
|
+
* 1. **Validates tokens exist** in the asset map
|
|
171
|
+
* 2. **Finds exchange hops** for both segments of the route
|
|
172
|
+
* 3. **Creates canonical pair structure** with sorted symbols
|
|
173
|
+
*
|
|
174
|
+
* **Route Structure**: The resulting pair represents trading from start->end
|
|
175
|
+
* via intermediate token, but the assets are ordered alphabetically by symbol
|
|
176
|
+
* for consistency (canonical form).
|
|
177
|
+
*
|
|
178
|
+
* **Path Representation**: The path array contains the actual exchange hops
|
|
179
|
+
* needed to execute the trade, preserving the routing information.
|
|
180
|
+
*
|
|
181
|
+
* @param startToken - Starting token address
|
|
182
|
+
* @param intermediate - Intermediate token address for routing
|
|
183
|
+
* @param end - Destination token address
|
|
184
|
+
* @param assetMap - Map of token address -> Asset details
|
|
185
|
+
* @param directPathMap - Map of token pairs -> exchange hop details
|
|
186
|
+
* @returns Route if valid route exists, null otherwise
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* // Create route: USDm -> CELO -> EURm
|
|
191
|
+
* const pair = createTwoHopPair(
|
|
192
|
+
* '0x765D...', // USDm address
|
|
193
|
+
* '0x471E...', // CELO address
|
|
194
|
+
* '0xD876...', // EURm address
|
|
195
|
+
* addrToSymbol,
|
|
196
|
+
* directPathMap
|
|
197
|
+
* )
|
|
198
|
+
*
|
|
199
|
+
* // Result:
|
|
200
|
+
* // {
|
|
201
|
+
* // id: 'EURm-USDm', // alphabetical order
|
|
202
|
+
* // assets: [EURm, USDm], // alphabetical order
|
|
203
|
+
* // path: [ // actual routing path
|
|
204
|
+
* // { USDm->CELO exchange },
|
|
205
|
+
* // { CELO->EURm exchange }
|
|
206
|
+
* // ]
|
|
207
|
+
* // }
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export declare function createTwoHopRoute(startAddr: Address, intermediateAddr: Address, endAddr: Address, addrToSymbol: Map<Address, TokenSymbol>, directRouteMap: Map<RouteID, Pool>): Route | null;
|
|
211
|
+
/**
|
|
212
|
+
* Selects optimal routes from all candidates based on spread data or heuristics.
|
|
213
|
+
*
|
|
214
|
+
* This is the route optimization engine that implements the following logic:
|
|
215
|
+
*
|
|
216
|
+
* **For Single Route**: Use it directly (no optimization needed)
|
|
217
|
+
*
|
|
218
|
+
* **For Multiple Routes**:
|
|
219
|
+
* - If `returnAllRoutes=true`: Return all routes (used for cache generation)
|
|
220
|
+
* - If `returnAllRoutes=false`: Apply optimization to select the best route
|
|
221
|
+
*
|
|
222
|
+
* **Route Selection Strategy**: Delegates to `selectBestRoute()` which uses
|
|
223
|
+
* a multi-tier approach prioritizing cost efficiency and reliability.
|
|
224
|
+
*
|
|
225
|
+
* @param allRoutes - Map of pair ID -> array of possible routes
|
|
226
|
+
* @param returnAllRoutes - Whether to return all routes or optimize selection
|
|
227
|
+
* @param assetMap - Asset map for token symbol lookups during optimization
|
|
228
|
+
* @returns Array of selected optimal routes
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* // Multiple routes for USDm-EURm pair
|
|
233
|
+
* const candidates = new Map([
|
|
234
|
+
* ['EURm-USDm', [
|
|
235
|
+
* { path: [USDm->CELO->EURm], costData: { totalCostPercent: 0.5 } },
|
|
236
|
+
* { path: [USDm->BRLm->EURm], costData: { totalCostPercent: 0.3 } },
|
|
237
|
+
* { path: [USDm->EURm] } // direct route, no cost data
|
|
238
|
+
* ]]
|
|
239
|
+
* ])
|
|
240
|
+
*
|
|
241
|
+
* const optimal = selectOptimalRoutes(candidates, false, assetMap)
|
|
242
|
+
* // Returns the USDm->BRLm->EURm route (lowest cost: 0.3%)
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
export declare function selectOptimalRoutes(allRoutes: Map<RouteID, Route[]>, returnAllRoutes: boolean, addrToSymbol: Map<Address, TokenSymbol>): (Route | RouteWithCost)[];
|
|
246
|
+
/**
|
|
247
|
+
* Selects the best route from candidates using cost data or fallback heuristics.
|
|
248
|
+
*
|
|
249
|
+
* This function implements a sophisticated route selection algorithm with
|
|
250
|
+
* multiple optimization tiers:
|
|
251
|
+
*
|
|
252
|
+
* **Tier 1 - Cost-Based Optimization** (Preferred):
|
|
253
|
+
* - Use routes with cost data (actual cost information)
|
|
254
|
+
* - Select route with lowest `totalCostPercent`
|
|
255
|
+
* - This provides the most cost-efficient trading
|
|
256
|
+
*
|
|
257
|
+
* **Tier 2 - Direct Route Preference** (Fallback):
|
|
258
|
+
* - If no cost data available, prefer direct (single-hop) routes
|
|
259
|
+
* - Direct routes have lower execution risk and gas costs
|
|
260
|
+
*
|
|
261
|
+
* **Tier 3 - Major Stablecoin Preference** (Final Fallback):
|
|
262
|
+
* - For two-hop routes, prefer those going through major stablecoins
|
|
263
|
+
* - Major FX currencies like USDm and EURm typically have better liquidity
|
|
264
|
+
*
|
|
265
|
+
* **Tier 4 - First Available** (Last Resort):
|
|
266
|
+
* - If no other heuristics apply, use the first route found
|
|
267
|
+
*
|
|
268
|
+
* @param candidates - Array of possible routes for the same token pair
|
|
269
|
+
* @param assetMap - Asset map for token symbol lookups
|
|
270
|
+
* @returns The optimal route selected using the tier system
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* const candidates = [
|
|
275
|
+
* { path: [A->B->C], costData: { totalCostPercent: 0.8 } },
|
|
276
|
+
* { path: [A->D->C], costData: { totalCostPercent: 0.4 } }, // Winner: lowest cost
|
|
277
|
+
* { path: [A->C] }, // direct route, no cost data
|
|
278
|
+
* ]
|
|
279
|
+
*
|
|
280
|
+
* const best = selectBestRoute(candidates, assetMap)
|
|
281
|
+
* // Returns the A->D->C route (0.4% cost)
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
export declare function selectBestRoute(candidates: Route[], addrToSymbol: Map<Address, TokenSymbol>): Route | RouteWithCost;
|
|
285
|
+
/**
|
|
286
|
+
* Extracts the intermediate token address from a two-hop route.
|
|
287
|
+
* In a two-hop route A->B->C, this function finds token B (the intermediate).
|
|
288
|
+
*/
|
|
289
|
+
export declare function getIntermediateToken(route: Route): Address | undefined;
|
|
290
|
+
/**
|
|
291
|
+
* Type guard to check if a Route has cost data.
|
|
292
|
+
*/
|
|
293
|
+
export declare function hasCostData(pair: Route | RouteWithCost): pair is RouteWithCost;
|
|
294
|
+
export {};
|
|
295
|
+
//# sourceMappingURL=routeUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routeUtils.d.ts","sourceRoot":"","sources":["../../src/utils/routeUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAc,aAAa,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAIpF,KAAK,WAAW,GAAG,MAAM,CAAA;AACzB,KAAK,OAAO,GAAG,MAAM,CAAA;AAErB;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,YAAY,EAAE,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IAEvC;;;;;;;;;;;;OAYG;IACH,UAAU,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IAEtC;;;;;;OAMG;IACH,cAAc,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAElC,wEAAwE;IACxE,YAAY,EAAE,KAAK,EAAE,CAAA;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,KAAK,EAAE,GAAG,gBAAgB,CA4BnF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAgD3F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,OAAO,EAClB,gBAAgB,EAAE,OAAO,EACzB,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,EACvC,cAAc,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,GACjC,KAAK,GAAG,IAAI,CAgCd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,EAChC,eAAe,EAAE,OAAO,EACxB,YAAY,EAAE,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,GACtC,CAAC,KAAK,GAAG,aAAa,CAAC,EAAE,CAoB3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,KAAK,GAAG,aAAa,CAwBnH;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,GAAG,SAAS,CAMtE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,aAAa,GAAG,IAAI,IAAI,aAAa,CAE9E"}
|