@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
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.RouteService = void 0;
|
|
27
|
+
const abis_1 = require("../../core/abis");
|
|
28
|
+
const errors_1 = require("../../core/errors");
|
|
29
|
+
const routeUtils_1 = require("../../utils/routeUtils");
|
|
30
|
+
const sortUtils_1 = require("../../utils/sortUtils");
|
|
31
|
+
/**
|
|
32
|
+
* Service for discovering and managing trading routes in the Mento protocol.
|
|
33
|
+
* Handles route discovery for both direct (single-hop) and multi-hop trading paths.
|
|
34
|
+
*
|
|
35
|
+
* Routes are identified by their token pair and include the path of pools
|
|
36
|
+
* needed to execute the trade. Multi-hop routes (up to 2 hops) are automatically
|
|
37
|
+
* discovered when no direct route exists between two tokens.
|
|
38
|
+
*/
|
|
39
|
+
class RouteService {
|
|
40
|
+
constructor(publicClient, chainId, poolService) {
|
|
41
|
+
this.publicClient = publicClient;
|
|
42
|
+
this.chainId = chainId;
|
|
43
|
+
this.poolService = poolService;
|
|
44
|
+
this.symbolCache = new Map();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generates all direct (single-hop) routes from available pools
|
|
48
|
+
* Routes are deduplicated and assets are sorted alphabetically by symbol
|
|
49
|
+
*
|
|
50
|
+
* @returns Array of direct routes with single-hop paths
|
|
51
|
+
* @throws {Error} If RPC calls fail
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const directRoutes = await routeService.getDirectRoutes()
|
|
56
|
+
* console.log(`Found ${directRoutes.length} direct routes`)
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
async getDirectRoutes() {
|
|
60
|
+
const pools = await this.poolService.getPools();
|
|
61
|
+
if (pools.length === 0) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
// Fetch all unique token addresses
|
|
65
|
+
const uniqueTokens = new Set();
|
|
66
|
+
pools.forEach((pool) => {
|
|
67
|
+
uniqueTokens.add(pool.token0);
|
|
68
|
+
uniqueTokens.add(pool.token1);
|
|
69
|
+
});
|
|
70
|
+
// Fetch symbols for all tokens in parallel. Used for the route ids
|
|
71
|
+
const tokenAddresses = Array.from(uniqueTokens);
|
|
72
|
+
await Promise.all(tokenAddresses.map((addr) => this.fetchTokenSymbol(addr)));
|
|
73
|
+
const routes = [];
|
|
74
|
+
// Loop all pools
|
|
75
|
+
for (const pool of pools) {
|
|
76
|
+
const symbol0 = this.symbolCache.get(pool.token0);
|
|
77
|
+
const symbol1 = this.symbolCache.get(pool.token1);
|
|
78
|
+
if (!symbol0 || !symbol1) {
|
|
79
|
+
// TODO: Consider error handling across the codebase for better consumer experience.
|
|
80
|
+
throw new Error(`Symbol not found for token ${pool.token0} or ${pool.token1}`);
|
|
81
|
+
}
|
|
82
|
+
// Create canonical route ID (alphabetically sorted symbols)
|
|
83
|
+
const routeId = (0, sortUtils_1.canonicalSymbolKey)(symbol0, symbol1);
|
|
84
|
+
// Sort tokens to match the canonical route ID order (alphabetical by symbol)
|
|
85
|
+
const sortedTokens = symbol0 < symbol1
|
|
86
|
+
? [
|
|
87
|
+
{ address: pool.token0, symbol: symbol0 },
|
|
88
|
+
{ address: pool.token1, symbol: symbol1 },
|
|
89
|
+
]
|
|
90
|
+
: [
|
|
91
|
+
{ address: pool.token1, symbol: symbol1 },
|
|
92
|
+
{ address: pool.token0, symbol: symbol0 },
|
|
93
|
+
];
|
|
94
|
+
routes.push({
|
|
95
|
+
id: routeId,
|
|
96
|
+
tokens: sortedTokens,
|
|
97
|
+
path: [pool],
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return routes;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Discovers all tradable routes including multi-hop routes (up to 2 hops)
|
|
104
|
+
* Uses cached data by default for instant results, or generates fresh from blockchain
|
|
105
|
+
*
|
|
106
|
+
* @param options - Configuration options
|
|
107
|
+
* @param options.cached - Whether to use pre-generated cached routes (default: true)
|
|
108
|
+
* @param options.returnAllRoutes - Whether to return all possible routes or just the optimal one per pair (default: false)
|
|
109
|
+
* @returns Array of all tradable routes (direct + multi-hop routes)
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // Fast: use pre-generated cache
|
|
114
|
+
* const cachedRoutes = await routeService.getRoutes({ cached: true })
|
|
115
|
+
*
|
|
116
|
+
* // Slower but fresh: generate from blockchain
|
|
117
|
+
* const freshRoutes = await routeService.getRoutes({ cached: false })
|
|
118
|
+
*
|
|
119
|
+
* // Get all route variants (useful for cache generation)
|
|
120
|
+
* const allRoutes = await routeService.getRoutes({ cached: false, returnAllRoutes: true })
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
async getRoutes(options) {
|
|
124
|
+
const cached = options?.cached ?? true;
|
|
125
|
+
const returnAllRoutes = options?.returnAllRoutes ?? false;
|
|
126
|
+
if (cached) {
|
|
127
|
+
// Try to load from static cache
|
|
128
|
+
try {
|
|
129
|
+
const cachedRoutes = await this.loadCachedRoutes();
|
|
130
|
+
if (cachedRoutes.length > 0) {
|
|
131
|
+
return cachedRoutes;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
console.warn('Failed to load cached routes, falling back to fresh generation');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Generate fresh routes from blockchain
|
|
139
|
+
return this.generateFreshRoutes(returnAllRoutes);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Looks up the tradable route between two tokens (direct or multi-hop)
|
|
143
|
+
*
|
|
144
|
+
* @param tokenIn - Input token address (direction matters for routing)
|
|
145
|
+
* @param tokenOut - Output token address (direction matters for routing)
|
|
146
|
+
* @param options - Optional configuration (e.g., cached)
|
|
147
|
+
* @returns The optimal tradable route connecting the two tokens
|
|
148
|
+
* @throws {RouteNotFoundError} If no route exists between the token pair
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const USDm = '0x765DE816845861e75A25fCA122bb6898B8B1282a'
|
|
153
|
+
* const BRLm = '0xE4D5...'
|
|
154
|
+
* const route = await routeService.findRoute(USDm, BRLm)
|
|
155
|
+
*
|
|
156
|
+
* if (route.path.length === 1) {
|
|
157
|
+
* console.log('Direct route available')
|
|
158
|
+
* } else {
|
|
159
|
+
* console.log('Two-hop route:', route.path)
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
async findRoute(tokenIn, tokenOut, options) {
|
|
164
|
+
// Get all tradable routes
|
|
165
|
+
const allRoutes = await this.getRoutes(options);
|
|
166
|
+
const t0 = tokenIn.toLowerCase();
|
|
167
|
+
const t1 = tokenOut.toLowerCase();
|
|
168
|
+
// Search for matching route (bidirectional)
|
|
169
|
+
const matchingRoute = allRoutes.find((route) => {
|
|
170
|
+
const a0 = route.tokens[0].address.toLowerCase();
|
|
171
|
+
const a1 = route.tokens[1].address.toLowerCase();
|
|
172
|
+
// Match either direction: (t0,t1) or (t1,t0)
|
|
173
|
+
return (a0 === t0 && a1 === t1) || (a0 === t1 && a1 === t0);
|
|
174
|
+
});
|
|
175
|
+
if (!matchingRoute) {
|
|
176
|
+
throw new errors_1.RouteNotFoundError(tokenIn, tokenOut);
|
|
177
|
+
}
|
|
178
|
+
return matchingRoute;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Generate fresh tradable routes from blockchain data
|
|
182
|
+
* @param returnAllRoutes - Whether to return all routes or just optimal ones per pair
|
|
183
|
+
* @private
|
|
184
|
+
*/
|
|
185
|
+
async generateFreshRoutes(returnAllRoutes = false) {
|
|
186
|
+
// Get direct routes
|
|
187
|
+
const directRoutes = await this.getDirectRoutes();
|
|
188
|
+
if (directRoutes.length === 0) {
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
// Build connectivity structures for route finding
|
|
192
|
+
const connectivity = (0, routeUtils_1.buildConnectivityStructures)(directRoutes);
|
|
193
|
+
// Generate all possible routes (direct + 2-hop)
|
|
194
|
+
const allRoutes = (0, routeUtils_1.generateAllRoutes)(connectivity);
|
|
195
|
+
// Select routes based on returnAllRoutes flag
|
|
196
|
+
const selectedRoutes = (0, routeUtils_1.selectOptimalRoutes)(allRoutes, returnAllRoutes, connectivity.addrToSymbol);
|
|
197
|
+
return selectedRoutes;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Load cached tradable routes for current chain
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
async loadCachedRoutes() {
|
|
204
|
+
const { getCachedRoutes } = await Promise.resolve().then(() => __importStar(require('../../utils/routes')));
|
|
205
|
+
const cachedRoutes = await getCachedRoutes(this.chainId);
|
|
206
|
+
return cachedRoutes || [];
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Helper: Fetch token symbol from on-chain
|
|
210
|
+
* Results are cached to avoid redundant RPC calls
|
|
211
|
+
* Falls back to address if symbol fetch fails
|
|
212
|
+
*
|
|
213
|
+
* @private
|
|
214
|
+
*/
|
|
215
|
+
async fetchTokenSymbol(address) {
|
|
216
|
+
// Return cached symbol if available
|
|
217
|
+
if (this.symbolCache.has(address)) {
|
|
218
|
+
return this.symbolCache.get(address);
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
const symbol = (await this.publicClient.readContract({
|
|
222
|
+
address: address,
|
|
223
|
+
abi: abis_1.ERC20_ABI,
|
|
224
|
+
functionName: 'symbol',
|
|
225
|
+
args: [],
|
|
226
|
+
}));
|
|
227
|
+
// Cache the symbol
|
|
228
|
+
this.symbolCache.set(address, symbol);
|
|
229
|
+
return symbol;
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
// Fallback to address if symbol fetch fails
|
|
233
|
+
this.symbolCache.set(address, address);
|
|
234
|
+
return address;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.RouteService = RouteService;
|
|
239
|
+
//# sourceMappingURL=RouteService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteService.js","sourceRoot":"","sources":["../../../src/services/routes/RouteService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0CAA2C;AAC3C,8CAAsD;AAEtD,uDAA4G;AAC5G,qDAA0D;AAc1D;;;;;;;GAOG;AACH,MAAa,YAAY;IAGvB,YAAoB,YAA0B,EAAU,OAAe,EAAU,WAAwB;QAArF,iBAAY,GAAZ,YAAY,CAAc;QAAU,YAAO,GAAP,OAAO,CAAQ;QAAU,gBAAW,GAAX,WAAW,CAAa;QAFjG,gBAAW,GAAwB,IAAI,GAAG,EAAE,CAAA;IAEwD,CAAC;IAE7G;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAA;QAE/C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,EAAE,CAAA;QACX,CAAC;QAED,mCAAmC;QACnC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAA;QACtC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAU,EAAE,EAAE;YAC3B,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAC7B,YAAY,CAAC,GAAG,CAAC,IAA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G;IACK,KAAK,CAAC,gBAAgB,CAAC,OAAe;QAC5C,oCAAoC;QACpC,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAE,CAAA;QACvC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;gBACnD,OAAO,EAAE,OAAwB;gBACjC,GAAG,EAAE,gBAAS;gBACd,YAAY,EAAE,QAAQ;gBACtB,IAAI,EAAE,EAAE;aACT,CAAC,CAAW,CAAA;YAEb,mBAAmB;YACnB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;YACrC,OAAO,MAAM,CAAA;QACf,CAAC;QAAC,MAAM,CAAC;YACP,4CAA4C;YAC5C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YACtC,OAAO,OAAO,CAAA;QAChB,CAAC;IACH,CAAC;CACF;AAhOD,oCAgOC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/routes/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./RouteService"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/routes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { PublicClient } from 'viem';
|
|
2
|
+
import { RouteService } from '../routes';
|
|
3
|
+
import { QuoteService } from '../quotes';
|
|
4
|
+
import { Route, CallParams } from '../../core/types';
|
|
5
|
+
import { RouterRoute } from '../../utils/pathEncoder';
|
|
6
|
+
/**
|
|
7
|
+
* Options for configuring a swap transaction
|
|
8
|
+
*/
|
|
9
|
+
export interface SwapOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Maximum acceptable slippage as a percentage (e.g., 0.5 for 0.5%)
|
|
12
|
+
*/
|
|
13
|
+
slippageTolerance: number;
|
|
14
|
+
/**
|
|
15
|
+
* Unix timestamp after which the transaction will revert
|
|
16
|
+
* Defaults to 20 minutes from now if not provided
|
|
17
|
+
*/
|
|
18
|
+
deadline?: bigint;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Detailed swap parameters including decoded values for transparency
|
|
22
|
+
*/
|
|
23
|
+
export interface SwapDetails {
|
|
24
|
+
/**
|
|
25
|
+
* Transaction parameters ready to send
|
|
26
|
+
*/
|
|
27
|
+
params: CallParams;
|
|
28
|
+
/**
|
|
29
|
+
* The route being used for the swap
|
|
30
|
+
*/
|
|
31
|
+
route: Route;
|
|
32
|
+
/**
|
|
33
|
+
* Encoded route for the Router contract
|
|
34
|
+
*/
|
|
35
|
+
routerRoutes: RouterRoute[];
|
|
36
|
+
/**
|
|
37
|
+
* Input amount in wei
|
|
38
|
+
*/
|
|
39
|
+
amountIn: bigint;
|
|
40
|
+
/**
|
|
41
|
+
* Minimum output amount after slippage
|
|
42
|
+
*/
|
|
43
|
+
amountOutMin: bigint;
|
|
44
|
+
/**
|
|
45
|
+
* Expected output amount (before slippage)
|
|
46
|
+
*/
|
|
47
|
+
expectedAmountOut: bigint;
|
|
48
|
+
/**
|
|
49
|
+
* Transaction deadline
|
|
50
|
+
*/
|
|
51
|
+
deadline: bigint;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Combined swap transaction with optional approval
|
|
55
|
+
*/
|
|
56
|
+
export interface SwapTransaction {
|
|
57
|
+
/**
|
|
58
|
+
* Approval transaction params - null if approval not needed
|
|
59
|
+
*/
|
|
60
|
+
approval: CallParams | null;
|
|
61
|
+
/**
|
|
62
|
+
* Swap details including transaction params
|
|
63
|
+
*/
|
|
64
|
+
swap: SwapDetails;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Service for building token swap transactions on the Mento protocol.
|
|
68
|
+
* Returns transaction parameters that can be executed by any wallet.
|
|
69
|
+
*/
|
|
70
|
+
export declare class SwapService {
|
|
71
|
+
private publicClient;
|
|
72
|
+
private chainId;
|
|
73
|
+
private routeService;
|
|
74
|
+
private quoteService;
|
|
75
|
+
constructor(publicClient: PublicClient, chainId: number, routeService: RouteService, quoteService: QuoteService);
|
|
76
|
+
/**
|
|
77
|
+
* Builds a complete swap transaction including approval if needed.
|
|
78
|
+
* This is the recommended method for most use cases.
|
|
79
|
+
*
|
|
80
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
81
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
82
|
+
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
83
|
+
* @param recipient - The address to receive the output tokens
|
|
84
|
+
* @param owner - The address that owns the input tokens (needed to check allowance)
|
|
85
|
+
* @param options - Swap configuration options (slippage, deadline)
|
|
86
|
+
* @param route - Optional pre-fetched route for better performance
|
|
87
|
+
* @returns Combined transaction with approval (if needed) and swap params
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const { approval, swap } = await mento.swap.buildSwapTransaction(
|
|
92
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
93
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
94
|
+
* parseUnits('100', 18),
|
|
95
|
+
* '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // recipient
|
|
96
|
+
* '0x123...', // owner
|
|
97
|
+
* { slippageTolerance: 0.5 }
|
|
98
|
+
* )
|
|
99
|
+
*
|
|
100
|
+
* // Execute approval if needed
|
|
101
|
+
* if (approval) {
|
|
102
|
+
* await walletClient.sendTransaction(approval)
|
|
103
|
+
* }
|
|
104
|
+
*
|
|
105
|
+
* // Execute swap
|
|
106
|
+
* await walletClient.sendTransaction(swap.params)
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
buildSwapTransaction(tokenIn: string, tokenOut: string, amountIn: bigint, recipient: string, owner: string, options: SwapOptions, route?: Route): Promise<SwapTransaction>;
|
|
110
|
+
/**
|
|
111
|
+
* Builds swap transaction parameters without executing the transaction.
|
|
112
|
+
* Does NOT check or handle token approval - use buildSwapTransaction for that.
|
|
113
|
+
*
|
|
114
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
115
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
116
|
+
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
117
|
+
* @param recipient - The address to receive the output tokens
|
|
118
|
+
* @param options - Swap configuration options (slippage, deadline)
|
|
119
|
+
* @param route - Optional pre-fetched route for better performance
|
|
120
|
+
* @returns Detailed swap parameters including transaction data
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const swapDetails = await mento.swap.buildSwapParams(
|
|
125
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
126
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
127
|
+
* parseUnits('100', 18),
|
|
128
|
+
* '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // recipient
|
|
129
|
+
* { slippageTolerance: 0.5 }
|
|
130
|
+
* )
|
|
131
|
+
*
|
|
132
|
+
* // Execute with any wallet (assumes approval already granted)
|
|
133
|
+
* await walletClient.sendTransaction(swapDetails.params)
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
buildSwapParams(tokenIn: string, tokenOut: string, amountIn: bigint, recipient: string, options: SwapOptions, route?: Route): Promise<SwapDetails>;
|
|
137
|
+
/**
|
|
138
|
+
* Builds approval transaction params for the Router to spend tokenIn
|
|
139
|
+
* @private
|
|
140
|
+
*/
|
|
141
|
+
private buildApprovalParams;
|
|
142
|
+
/**
|
|
143
|
+
* Gets current allowance for the Router contract
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
private getAllowance;
|
|
147
|
+
/**
|
|
148
|
+
* Calculates minimum output amount after applying slippage tolerance
|
|
149
|
+
* @param amountOut - Expected output amount
|
|
150
|
+
* @param slippageTolerance - Slippage tolerance as percentage (e.g., 0.5 for 0.5%)
|
|
151
|
+
* @returns Minimum acceptable output amount
|
|
152
|
+
* @throws Error if slippage tolerance is invalid
|
|
153
|
+
* @private
|
|
154
|
+
*/
|
|
155
|
+
private calculateMinAmountOut;
|
|
156
|
+
/**
|
|
157
|
+
* Encodes the swapExactTokensForTokens function call
|
|
158
|
+
* @private
|
|
159
|
+
*/
|
|
160
|
+
private encodeSwapCall;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=SwapService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwapService.d.ts","sourceRoot":"","sources":["../../../src/services/swap/SwapService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAAsB,MAAM,MAAM,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAGpD,OAAO,EAAmB,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAGtE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAA;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,MAAM,EAAE,UAAU,CAAA;IAClB;;OAEG;IACH,KAAK,EAAE,KAAK,CAAA;IACZ;;OAEG;IACH,YAAY,EAAE,WAAW,EAAE,CAAA;IAC3B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAA;IACzB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,QAAQ,EAAE,UAAU,GAAG,IAAI,CAAA;IAC3B;;OAEG;IACH,IAAI,EAAE,WAAW,CAAA;CAClB;AAED;;;GAGG;AACH,qBAAa,WAAW;IAEpB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,YAAY;gBAHZ,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY;IAGpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACG,oBAAoB,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,KAAK,GACZ,OAAO,CAAC,eAAe,CAAC;IAiB3B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,eAAe,CACnB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,KAAK,GACZ,OAAO,CAAC,WAAW,CAAC;IAoCvB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;;OAGG;YACW,YAAY;IAU1B;;;;;;;OAOG;IACH,OAAO,CAAC,qBAAqB;IAa7B;;;OAGG;IACH,OAAO,CAAC,cAAc;CAavB"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapService = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const abis_1 = require("../../core/abis");
|
|
6
|
+
const constants_1 = require("../../core/constants");
|
|
7
|
+
const pathEncoder_1 = require("../../utils/pathEncoder");
|
|
8
|
+
const validation_1 = require("../../utils/validation");
|
|
9
|
+
/**
|
|
10
|
+
* Service for building token swap transactions on the Mento protocol.
|
|
11
|
+
* Returns transaction parameters that can be executed by any wallet.
|
|
12
|
+
*/
|
|
13
|
+
class SwapService {
|
|
14
|
+
constructor(publicClient, chainId, routeService, quoteService) {
|
|
15
|
+
this.publicClient = publicClient;
|
|
16
|
+
this.chainId = chainId;
|
|
17
|
+
this.routeService = routeService;
|
|
18
|
+
this.quoteService = quoteService;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Builds a complete swap transaction including approval if needed.
|
|
22
|
+
* This is the recommended method for most use cases.
|
|
23
|
+
*
|
|
24
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
25
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
26
|
+
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
27
|
+
* @param recipient - The address to receive the output tokens
|
|
28
|
+
* @param owner - The address that owns the input tokens (needed to check allowance)
|
|
29
|
+
* @param options - Swap configuration options (slippage, deadline)
|
|
30
|
+
* @param route - Optional pre-fetched route for better performance
|
|
31
|
+
* @returns Combined transaction with approval (if needed) and swap params
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const { approval, swap } = await mento.swap.buildSwapTransaction(
|
|
36
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
37
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
38
|
+
* parseUnits('100', 18),
|
|
39
|
+
* '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // recipient
|
|
40
|
+
* '0x123...', // owner
|
|
41
|
+
* { slippageTolerance: 0.5 }
|
|
42
|
+
* )
|
|
43
|
+
*
|
|
44
|
+
* // Execute approval if needed
|
|
45
|
+
* if (approval) {
|
|
46
|
+
* await walletClient.sendTransaction(approval)
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* // Execute swap
|
|
50
|
+
* await walletClient.sendTransaction(swap.params)
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
async buildSwapTransaction(tokenIn, tokenOut, amountIn, recipient, owner, options, route) {
|
|
54
|
+
// Validate all address inputs
|
|
55
|
+
(0, validation_1.validateAddress)(tokenIn, 'tokenIn');
|
|
56
|
+
(0, validation_1.validateAddress)(tokenOut, 'tokenOut');
|
|
57
|
+
(0, validation_1.validateAddress)(recipient, 'recipient');
|
|
58
|
+
(0, validation_1.validateAddress)(owner, 'owner');
|
|
59
|
+
// Build swap params first
|
|
60
|
+
const swap = await this.buildSwapParams(tokenIn, tokenOut, amountIn, recipient, options, route);
|
|
61
|
+
// Check if approval is needed
|
|
62
|
+
const currentAllowance = await this.getAllowance(tokenIn, owner);
|
|
63
|
+
const approval = currentAllowance < amountIn ? this.buildApprovalParams(tokenIn, amountIn) : null;
|
|
64
|
+
return { approval, swap };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Builds swap transaction parameters without executing the transaction.
|
|
68
|
+
* Does NOT check or handle token approval - use buildSwapTransaction for that.
|
|
69
|
+
*
|
|
70
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
71
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
72
|
+
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
73
|
+
* @param recipient - The address to receive the output tokens
|
|
74
|
+
* @param options - Swap configuration options (slippage, deadline)
|
|
75
|
+
* @param route - Optional pre-fetched route for better performance
|
|
76
|
+
* @returns Detailed swap parameters including transaction data
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const swapDetails = await mento.swap.buildSwapParams(
|
|
81
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
82
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
83
|
+
* parseUnits('100', 18),
|
|
84
|
+
* '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // recipient
|
|
85
|
+
* { slippageTolerance: 0.5 }
|
|
86
|
+
* )
|
|
87
|
+
*
|
|
88
|
+
* // Execute with any wallet (assumes approval already granted)
|
|
89
|
+
* await walletClient.sendTransaction(swapDetails.params)
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
async buildSwapParams(tokenIn, tokenOut, amountIn, recipient, options, route) {
|
|
93
|
+
// Validate all address inputs
|
|
94
|
+
(0, validation_1.validateAddress)(tokenIn, 'tokenIn');
|
|
95
|
+
(0, validation_1.validateAddress)(tokenOut, 'tokenOut');
|
|
96
|
+
(0, validation_1.validateAddress)(recipient, 'recipient');
|
|
97
|
+
// Find route if not provided
|
|
98
|
+
if (!route) {
|
|
99
|
+
route = await this.routeService.findRoute(tokenIn, tokenOut);
|
|
100
|
+
}
|
|
101
|
+
const expectedAmountOut = await this.quoteService.getAmountOut(tokenIn, tokenOut, amountIn, route);
|
|
102
|
+
const amountOutMin = this.calculateMinAmountOut(expectedAmountOut, options.slippageTolerance);
|
|
103
|
+
// Set deadline (default: 20 minutes from now)
|
|
104
|
+
const deadline = options.deadline ?? BigInt(Math.floor(Date.now() / 1000) + 20 * 60);
|
|
105
|
+
const routerRoutes = (0, pathEncoder_1.encodeRoutePath)(route.path, tokenIn, tokenOut);
|
|
106
|
+
const routerAddress = (0, constants_1.getContractAddress)(this.chainId, 'Router');
|
|
107
|
+
const data = this.encodeSwapCall(amountIn, amountOutMin, routerRoutes, recipient, deadline);
|
|
108
|
+
return {
|
|
109
|
+
params: {
|
|
110
|
+
to: routerAddress,
|
|
111
|
+
data,
|
|
112
|
+
value: '0',
|
|
113
|
+
},
|
|
114
|
+
route,
|
|
115
|
+
routerRoutes,
|
|
116
|
+
amountIn,
|
|
117
|
+
amountOutMin,
|
|
118
|
+
expectedAmountOut,
|
|
119
|
+
deadline,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Builds approval transaction params for the Router to spend tokenIn
|
|
124
|
+
* @private
|
|
125
|
+
*/
|
|
126
|
+
buildApprovalParams(tokenIn, amount) {
|
|
127
|
+
const routerAddress = (0, constants_1.getContractAddress)(this.chainId, 'Router');
|
|
128
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
129
|
+
abi: abis_1.ERC20_ABI,
|
|
130
|
+
functionName: 'approve',
|
|
131
|
+
args: [routerAddress, amount],
|
|
132
|
+
});
|
|
133
|
+
return { to: tokenIn, data, value: '0' };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Gets current allowance for the Router contract
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
async getAllowance(tokenIn, owner) {
|
|
140
|
+
const routerAddress = (0, constants_1.getContractAddress)(this.chainId, 'Router');
|
|
141
|
+
return this.publicClient.readContract({
|
|
142
|
+
address: tokenIn,
|
|
143
|
+
abi: abis_1.ERC20_ABI,
|
|
144
|
+
functionName: 'allowance',
|
|
145
|
+
args: [owner, routerAddress],
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Calculates minimum output amount after applying slippage tolerance
|
|
150
|
+
* @param amountOut - Expected output amount
|
|
151
|
+
* @param slippageTolerance - Slippage tolerance as percentage (e.g., 0.5 for 0.5%)
|
|
152
|
+
* @returns Minimum acceptable output amount
|
|
153
|
+
* @throws Error if slippage tolerance is invalid
|
|
154
|
+
* @private
|
|
155
|
+
*/
|
|
156
|
+
calculateMinAmountOut(amountOut, slippageTolerance) {
|
|
157
|
+
if (slippageTolerance < 0) {
|
|
158
|
+
throw new Error('Slippage tolerance cannot be negative');
|
|
159
|
+
}
|
|
160
|
+
if (slippageTolerance > 100) {
|
|
161
|
+
throw new Error('Slippage tolerance cannot exceed 100%');
|
|
162
|
+
}
|
|
163
|
+
const basisPoints = BigInt(Math.floor(slippageTolerance * 100));
|
|
164
|
+
const slippageMultiplier = 10000n - basisPoints;
|
|
165
|
+
return (amountOut * slippageMultiplier) / 10000n;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Encodes the swapExactTokensForTokens function call
|
|
169
|
+
* @private
|
|
170
|
+
*/
|
|
171
|
+
encodeSwapCall(amountIn, amountOutMin, routes, recipient, deadline) {
|
|
172
|
+
return (0, viem_1.encodeFunctionData)({
|
|
173
|
+
abi: abis_1.ROUTER_ABI,
|
|
174
|
+
functionName: 'swapExactTokensForTokens',
|
|
175
|
+
args: [amountIn, amountOutMin, routes, recipient, deadline],
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.SwapService = SwapService;
|
|
180
|
+
//# sourceMappingURL=SwapService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwapService.js","sourceRoot":"","sources":["../../../src/services/swap/SwapService.ts"],"names":[],"mappings":";;;AAAA,+BAAgE;AAIhE,0CAAuD;AACvD,oDAAkE;AAClE,yDAAsE;AACtE,uDAAwD;AAiExD;;;GAGG;AACH,MAAa,WAAW;IACtB,YACU,YAA0B,EAC1B,OAAe,EACf,YAA0B,EAC1B,YAA0B;QAH1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAc;QAC1B,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,KAAK,CAAC,oBAAoB,CACxB,OAAe,EACf,QAAgB,EAChB,QAAgB,EAChB,SAAiB,EACjB,KAAa,EACb,OAAoB,EACpB,KAAa;QAEb,8BAA8B;QAC9B,IAAA,4BAAe,EAAC,OAAO,EAAE,SAAS,CAAC,CAAA;QACnC,IAAA,4BAAe,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;QACrC,IAAA,4BAAe,EAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QACvC,IAAA,4BAAe,EAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAE/B,0BAA0B;QAC1B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC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ED;;;;;;;OAOG;IACK,qBAAqB,CAAC,SAAiB,EAAE,iBAAyB;QACxE,IAAI,iBAAiB,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;QAC1D,CAAC;QACD,IAAI,iBAAiB,GAAG,GAAG,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;QAC1D,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,GAAG,GAAG,CAAC,CAAC,CAAA;QAC/D,MAAM,kBAAkB,GAAG,MAAM,GAAG,WAAW,CAAA;QAC/C,OAAO,CAAC,SAAS,GAAG,kBAAkB,CAAC,GAAG,MAAM,CAAA;IAClD,CAAC;IAED;;;OAGG;IACK,cAAc,CACpB,QAAgB,EAChB,YAAoB,EACpB,MAAqB,EACrB,SAAkB,EAClB,QAAgB;QAEhB,OAAO,IAAA,yBAAkB,EAAC;YACxB,GAAG,EAAE,iBAAU;YACf,YAAY,EAAE,0BAA0B;YACxC,IAAI,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC;SAC5D,CAAC,CAAA;IACJ,CAAC;CACF;AAzMD,kCAyMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/swap/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./SwapService"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/swap/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B"}
|