@mento-protocol/mento-sdk 3.2.3 → 3.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache/routes.d.ts +13 -0
- package/dist/cache/routes.js +14089 -0
- package/dist/cache/tokens.d.ts +68 -0
- package/dist/cache/tokens.js +460 -0
- package/dist/core/abis/activePool.d.ts +2 -0
- package/dist/core/abis/activePool.js +14 -0
- package/dist/core/abis/addressesRegistry.d.ts +2 -0
- package/dist/core/abis/addressesRegistry.js +26 -0
- package/dist/core/abis/bipoolmanager.d.ts +34 -0
- package/dist/core/abis/bipoolmanager.js +72 -0
- package/dist/core/abis/borrowerOperations.d.ts +9 -0
- package/dist/core/abis/borrowerOperations.js +89 -0
- package/dist/core/abis/breakerbox.d.ts +13 -0
- package/dist/core/abis/breakerbox.js +8 -0
- package/dist/core/abis/broker.d.ts +2 -0
- package/dist/core/abis/broker.js +9 -0
- package/dist/core/abis/erc20.d.ts +9 -0
- package/dist/core/abis/erc20.js +21 -0
- package/dist/core/abis/fpmm.d.ts +270 -0
- package/dist/core/abis/fpmm.js +49 -0
- package/dist/core/abis/fpmmFactory.d.ts +85 -0
- package/dist/core/abis/fpmmFactory.js +26 -0
- package/dist/core/abis/hintHelpers.d.ts +2 -0
- package/dist/core/abis/hintHelpers.js +14 -0
- package/dist/core/abis/index.d.ts +22 -0
- package/dist/core/abis/index.js +38 -0
- package/dist/core/abis/liquidityStrategy.d.ts +132 -0
- package/dist/core/abis/liquidityStrategy.js +10 -0
- package/dist/core/abis/multiTroveGetter.d.ts +8 -0
- package/dist/core/abis/multiTroveGetter.js +15 -0
- package/dist/core/abis/priceFeed.d.ts +7 -0
- package/dist/core/abis/priceFeed.js +16 -0
- package/dist/core/abis/pricingmodule.d.ts +2 -0
- package/dist/core/abis/pricingmodule.js +6 -0
- package/dist/core/abis/reserve.d.ts +3 -0
- package/dist/core/abis/reserve.js +18 -0
- package/dist/core/abis/router.d.ts +521 -0
- package/dist/core/abis/router.js +45 -0
- package/dist/core/abis/sortedTroves.d.ts +2 -0
- package/dist/core/abis/sortedTroves.js +15 -0
- package/dist/core/abis/systemParams.d.ts +2 -0
- package/dist/core/abis/systemParams.js +14 -0
- package/dist/core/abis/troveManager.d.ts +2 -0
- package/dist/core/abis/troveManager.js +27 -0
- package/dist/core/abis/troveNFT.d.ts +2 -0
- package/dist/core/abis/troveNFT.js +9 -0
- package/dist/core/abis/virtualPool.d.ts +50 -0
- package/dist/core/abis/virtualPool.js +11 -0
- package/dist/core/abis/virtualPoolFactory.d.ts +59 -0
- package/dist/core/abis/virtualPoolFactory.js +17 -0
- package/dist/core/constants/addresses.d.ts +18 -0
- package/dist/core/constants/addresses.js +113 -0
- package/dist/core/constants/borrowConstants.d.ts +10 -0
- package/dist/core/constants/borrowConstants.js +16 -0
- package/dist/core/constants/borrowRegistries.d.ts +7 -0
- package/dist/core/constants/borrowRegistries.js +30 -0
- package/dist/core/constants/chainId.d.ts +7 -0
- package/dist/{cjs/enums → core/constants}/chainId.js +4 -1
- package/dist/core/constants/contractNames.d.ts +21 -0
- package/dist/core/constants/contractNames.js +24 -0
- package/dist/core/constants/index.d.ts +6 -0
- package/dist/core/constants/index.js +22 -0
- package/dist/core/errors/base.d.ts +8 -0
- package/dist/core/errors/base.js +17 -0
- package/dist/core/errors/index.d.ts +4 -0
- package/dist/{cjs/constants → core/errors}/index.js +4 -4
- package/dist/core/errors/oracle.d.ts +9 -0
- package/dist/core/errors/oracle.js +15 -0
- package/dist/core/errors/router.d.ts +14 -0
- package/dist/core/errors/router.js +24 -0
- package/dist/core/types/borrow.d.ts +87 -0
- package/dist/{cjs/interfaces/tradingLimitsConfig.js → core/types/borrow.js} +1 -0
- package/dist/core/types/contractAddresses.d.ts +42 -0
- package/dist/{cjs → core}/types/contractAddresses.js +1 -0
- package/dist/core/types/index.d.ts +10 -0
- package/dist/core/types/index.js +26 -0
- package/dist/core/types/liquidity.d.ts +194 -0
- package/dist/core/types/liquidity.js +3 -0
- package/dist/core/types/pool.d.ts +208 -0
- package/dist/core/types/pool.js +14 -0
- package/dist/core/types/provider.d.ts +45 -0
- package/dist/{cjs/interfaces/tradingLimitsState.js → core/types/provider.js} +1 -0
- package/dist/core/types/route.d.ts +62 -0
- package/dist/{cjs/interfaces/IChainClient.js → core/types/route.js} +1 -0
- package/dist/core/types/token.d.ts +21 -0
- package/dist/{cjs/interfaces/tradingLimit.js → core/types/token.js} +1 -0
- package/dist/core/types/tradingLimits.d.ts +91 -0
- package/dist/core/types/tradingLimits.js +3 -0
- package/dist/core/types/tradingMode.d.ts +24 -0
- package/dist/core/types/tradingMode.js +31 -0
- package/dist/core/types/transaction.d.ts +45 -0
- package/dist/core/types/transaction.js +3 -0
- package/dist/esm/cache/routes.js +14084 -0
- package/dist/esm/cache/tokens.js +452 -0
- package/dist/esm/core/abis/activePool.js +10 -0
- package/dist/esm/core/abis/addressesRegistry.js +22 -0
- package/dist/esm/core/abis/bipoolmanager.js +68 -0
- package/dist/esm/core/abis/borrowerOperations.js +85 -0
- package/dist/esm/core/abis/breakerbox.js +4 -0
- package/dist/esm/core/abis/broker.js +5 -0
- package/dist/esm/core/abis/erc20.js +17 -0
- package/dist/esm/core/abis/fpmm.js +45 -0
- package/dist/esm/core/abis/fpmmFactory.js +22 -0
- package/dist/esm/core/abis/hintHelpers.js +10 -0
- package/dist/esm/core/abis/index.js +21 -0
- package/dist/esm/core/abis/liquidityStrategy.js +6 -0
- package/dist/esm/core/abis/multiTroveGetter.js +11 -0
- package/dist/esm/core/abis/priceFeed.js +12 -0
- package/dist/esm/core/abis/pricingmodule.js +2 -0
- package/dist/esm/core/abis/reserve.js +14 -0
- package/dist/esm/core/abis/router.js +41 -0
- package/dist/esm/core/abis/sortedTroves.js +11 -0
- package/dist/esm/core/abis/systemParams.js +10 -0
- package/dist/esm/core/abis/troveManager.js +23 -0
- package/dist/esm/core/abis/troveNFT.js +5 -0
- package/dist/esm/core/abis/virtualPool.js +7 -0
- package/dist/esm/core/abis/virtualPoolFactory.js +13 -0
- package/dist/esm/core/constants/addresses.js +107 -0
- package/dist/esm/core/constants/borrowConstants.js +12 -0
- package/dist/esm/core/constants/borrowRegistries.js +25 -0
- package/dist/esm/{enums → core/constants}/chainId.js +2 -0
- package/dist/esm/core/constants/contractNames.js +20 -0
- package/dist/esm/core/constants/index.js +5 -0
- package/dist/esm/core/errors/base.js +12 -0
- package/dist/esm/core/errors/index.js +3 -0
- package/dist/esm/core/errors/oracle.js +10 -0
- package/dist/esm/core/errors/router.js +18 -0
- package/dist/esm/core/types/index.js +9 -0
- package/dist/esm/core/types/pool.js +10 -0
- package/dist/esm/core/types/tradingLimits.js +1 -0
- package/dist/esm/core/types/tradingMode.js +26 -0
- package/dist/esm/core/types/transaction.js +1 -0
- package/dist/esm/index.js +138 -6
- package/dist/esm/package.json +1 -0
- package/dist/esm/services/borrow/BorrowService.js +455 -0
- package/dist/esm/services/borrow/borrowHelpers.js +3 -0
- package/dist/esm/services/borrow/borrowMath.js +127 -0
- package/dist/esm/services/borrow/index.js +3 -0
- package/dist/esm/services/borrow/internal/borrowApprovalService.js +48 -0
- package/dist/esm/services/borrow/internal/borrowContextStore.js +35 -0
- package/dist/esm/services/borrow/internal/borrowErc20.js +38 -0
- package/dist/esm/services/borrow/internal/borrowHints.js +27 -0
- package/dist/esm/services/borrow/internal/borrowPositionParser.js +82 -0
- package/dist/esm/services/borrow/internal/borrowReadService.js +271 -0
- package/dist/esm/services/borrow/internal/borrowRegistryReader.js +108 -0
- package/dist/esm/services/borrow/internal/borrowTransactionService.js +271 -0
- package/dist/esm/services/borrow/internal/borrowTypes.js +1 -0
- package/dist/esm/services/borrow/internal/borrowValidation.js +89 -0
- package/dist/esm/services/index.js +8 -0
- package/dist/esm/services/liquidity/LiquidityService.js +163 -0
- package/dist/esm/services/liquidity/basicLiquidity.js +162 -0
- package/dist/esm/services/liquidity/index.js +1 -0
- package/dist/esm/services/liquidity/liquidityHelpers.js +95 -0
- package/dist/esm/services/liquidity/rebalance.js +59 -0
- package/dist/esm/services/liquidity/zapHelpers.js +120 -0
- package/dist/esm/services/liquidity/zapIn.js +112 -0
- package/dist/esm/services/liquidity/zapOut.js +248 -0
- package/dist/esm/services/pools/PoolService.js +204 -0
- package/dist/esm/services/pools/index.js +1 -0
- package/dist/esm/services/pools/poolDetails.js +209 -0
- package/dist/esm/services/pools/poolDiscovery.js +112 -0
- package/dist/esm/services/pools/rebalancePreview.js +181 -0
- package/dist/esm/services/quotes/QuoteService.js +85 -0
- package/dist/esm/services/quotes/index.js +1 -0
- package/dist/esm/services/routes/RouteService.js +268 -0
- package/dist/esm/services/routes/index.js +1 -0
- package/dist/esm/services/swap/SwapService.js +247 -0
- package/dist/esm/services/swap/index.js +1 -0
- package/dist/esm/services/tokens/index.js +1 -0
- package/dist/esm/services/tokens/tokenService.js +285 -0
- package/dist/esm/services/trading/TradingLimitsService.js +154 -0
- package/dist/esm/services/trading/TradingService.js +222 -0
- package/dist/esm/services/trading/index.js +2 -0
- package/dist/esm/utils/chainConfig.js +118 -0
- package/dist/esm/utils/costUtils.js +56 -0
- package/dist/esm/utils/deadline.js +22 -0
- package/dist/esm/utils/index.js +9 -0
- package/dist/esm/utils/multicall.js +47 -0
- package/dist/esm/utils/pathEncoder.js +69 -0
- package/dist/esm/utils/rateFeed.js +23 -0
- package/dist/esm/utils/retry.js +24 -0
- package/dist/esm/{routeUtils.js → utils/routeUtils.js} +115 -116
- package/dist/esm/utils/routes.js +2 -0
- package/dist/esm/utils/sortUtils.js +33 -0
- package/dist/esm/utils/tokens.js +2 -0
- package/dist/esm/utils/tradingLimits.js +163 -0
- package/dist/esm/utils/validation.js +30 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +158 -0
- package/dist/services/borrow/BorrowService.d.ts +381 -0
- package/dist/services/borrow/BorrowService.js +460 -0
- package/dist/services/borrow/borrowHelpers.d.ts +4 -0
- package/dist/services/borrow/borrowHelpers.js +13 -0
- package/dist/services/borrow/borrowMath.d.ts +21 -0
- package/dist/services/borrow/borrowMath.js +137 -0
- package/dist/services/borrow/index.d.ts +4 -0
- package/dist/{cjs/interfaces → services/borrow}/index.js +4 -4
- package/dist/services/borrow/internal/borrowApprovalService.d.ts +14 -0
- package/dist/services/borrow/internal/borrowApprovalService.js +53 -0
- package/dist/services/borrow/internal/borrowContextStore.d.ts +11 -0
- package/dist/services/borrow/internal/borrowContextStore.js +40 -0
- package/dist/services/borrow/internal/borrowErc20.d.ts +5 -0
- package/dist/services/borrow/internal/borrowErc20.js +43 -0
- package/dist/services/borrow/internal/borrowHints.d.ts +7 -0
- package/dist/services/borrow/internal/borrowHints.js +31 -0
- package/dist/services/borrow/internal/borrowPositionParser.d.ts +4 -0
- package/dist/services/borrow/internal/borrowPositionParser.js +87 -0
- package/dist/services/borrow/internal/borrowReadService.d.ts +31 -0
- package/dist/services/borrow/internal/borrowReadService.js +276 -0
- package/dist/services/borrow/internal/borrowRegistryReader.d.ts +5 -0
- package/dist/services/borrow/internal/borrowRegistryReader.js +113 -0
- package/dist/services/borrow/internal/borrowTransactionService.d.ts +23 -0
- package/dist/services/borrow/internal/borrowTransactionService.js +276 -0
- package/dist/services/borrow/internal/borrowTypes.d.ts +15 -0
- package/dist/services/borrow/internal/borrowTypes.js +3 -0
- package/dist/services/borrow/internal/borrowValidation.d.ts +14 -0
- package/dist/services/borrow/internal/borrowValidation.js +104 -0
- package/dist/services/index.d.ts +9 -0
- package/dist/{cjs → services}/index.js +9 -7
- package/dist/services/liquidity/LiquidityService.d.ts +139 -0
- package/dist/services/liquidity/LiquidityService.js +168 -0
- package/dist/services/liquidity/basicLiquidity.d.ts +11 -0
- package/dist/services/liquidity/basicLiquidity.js +172 -0
- package/dist/services/liquidity/index.d.ts +2 -0
- package/dist/{cjs/types → services/liquidity}/index.js +2 -2
- package/dist/services/liquidity/liquidityHelpers.d.ts +19 -0
- package/dist/services/liquidity/liquidityHelpers.js +104 -0
- package/dist/services/liquidity/rebalance.d.ts +6 -0
- package/dist/services/liquidity/rebalance.js +64 -0
- package/dist/services/liquidity/zapHelpers.d.ts +66 -0
- package/dist/services/liquidity/zapHelpers.js +129 -0
- package/dist/services/liquidity/zapIn.d.ts +18 -0
- package/dist/services/liquidity/zapIn.js +119 -0
- package/dist/services/liquidity/zapOut.d.ts +9 -0
- package/dist/services/liquidity/zapOut.js +255 -0
- package/dist/services/pools/PoolService.d.ts +69 -0
- package/dist/services/pools/PoolService.js +209 -0
- package/dist/services/pools/index.d.ts +2 -0
- package/dist/{cjs/enums → services/pools}/index.js +2 -3
- package/dist/services/pools/poolDetails.d.ts +13 -0
- package/dist/services/pools/poolDetails.js +216 -0
- package/dist/services/pools/poolDiscovery.d.ts +12 -0
- package/dist/services/pools/poolDiscovery.js +117 -0
- package/dist/services/pools/rebalancePreview.d.ts +5 -0
- package/dist/services/pools/rebalancePreview.js +186 -0
- package/dist/services/quotes/QuoteService.d.ts +51 -0
- package/dist/services/quotes/QuoteService.js +91 -0
- package/dist/services/quotes/index.d.ts +2 -0
- package/dist/services/quotes/index.js +18 -0
- package/dist/services/routes/RouteService.d.ts +117 -0
- package/dist/services/routes/RouteService.js +306 -0
- package/dist/services/routes/index.d.ts +2 -0
- package/dist/services/routes/index.js +18 -0
- package/dist/services/swap/SwapService.d.ts +198 -0
- package/dist/services/swap/SwapService.js +252 -0
- package/dist/services/swap/index.d.ts +2 -0
- package/dist/services/swap/index.js +18 -0
- package/dist/services/tokens/index.d.ts +2 -0
- package/dist/services/tokens/index.js +18 -0
- package/dist/services/tokens/tokenService.d.ts +55 -0
- package/dist/services/tokens/tokenService.js +290 -0
- package/dist/services/trading/TradingLimitsService.d.ts +38 -0
- package/dist/services/trading/TradingLimitsService.js +159 -0
- package/dist/services/trading/TradingService.d.ts +115 -0
- package/dist/services/trading/TradingService.js +227 -0
- package/dist/services/trading/index.d.ts +3 -0
- package/dist/services/trading/index.js +19 -0
- package/dist/utils/chainConfig.d.ts +16 -0
- package/dist/utils/chainConfig.js +123 -0
- package/dist/utils/costUtils.d.ts +12 -0
- package/dist/utils/costUtils.js +60 -0
- package/dist/utils/deadline.d.ts +21 -0
- package/dist/utils/deadline.js +26 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.js +26 -0
- package/dist/utils/multicall.d.ts +30 -0
- package/dist/utils/multicall.js +52 -0
- package/dist/utils/pathEncoder.d.ts +34 -0
- package/dist/utils/pathEncoder.js +73 -0
- package/dist/utils/rateFeed.d.ts +18 -0
- package/dist/utils/rateFeed.js +27 -0
- package/dist/utils/retry.d.ts +12 -0
- package/dist/utils/retry.js +28 -0
- package/dist/{esm → utils}/routeUtils.d.ts +84 -93
- package/dist/{cjs → utils}/routeUtils.js +123 -124
- package/dist/utils/routes.d.ts +3 -0
- package/dist/utils/routes.js +8 -0
- package/dist/utils/sortUtils.d.ts +24 -0
- package/dist/utils/sortUtils.js +39 -0
- package/dist/utils/tokens.d.ts +2 -0
- package/dist/utils/tokens.js +13 -0
- package/dist/utils/tradingLimits.d.ts +41 -0
- package/dist/utils/tradingLimits.js +171 -0
- package/dist/utils/validation.d.ts +19 -0
- package/dist/utils/validation.js +34 -0
- package/package.json +1 -1
- package/dist/cjs/ChainClient.d.ts +0 -9
- package/dist/cjs/ChainClient.js +0 -58
- package/dist/cjs/TestChainClient.d.ts +0 -7
- package/dist/cjs/TestChainClient.js +0 -41
- package/dist/cjs/constants/addresses.d.ts +0 -4
- package/dist/cjs/constants/addresses.js +0 -59
- package/dist/cjs/constants/currencies.d.ts +0 -5
- package/dist/cjs/constants/currencies.js +0 -29
- package/dist/cjs/constants/index.d.ts +0 -4
- package/dist/cjs/constants/tokens.11142220.d.ts +0 -2
- package/dist/cjs/constants/tokens.11142220.js +0 -128
- package/dist/cjs/constants/tokens.42220.d.ts +0 -2
- package/dist/cjs/constants/tokens.42220.js +0 -128
- package/dist/cjs/constants/tokens.d.ts +0 -65
- package/dist/cjs/constants/tokens.js +0 -170
- package/dist/cjs/constants/tradablePairs.11142220.d.ts +0 -2
- package/dist/cjs/constants/tradablePairs.11142220.js +0 -7391
- package/dist/cjs/constants/tradablePairs.42220.d.ts +0 -2
- package/dist/cjs/constants/tradablePairs.42220.js +0 -7391
- package/dist/cjs/constants/tradablePairs.d.ts +0 -16
- package/dist/cjs/constants/tradablePairs.js +0 -53
- package/dist/cjs/enums/chainId.d.ts +0 -4
- package/dist/cjs/enums/index.d.ts +0 -3
- package/dist/cjs/enums/proposalState.d.ts +0 -10
- package/dist/cjs/enums/proposalState.js +0 -14
- package/dist/cjs/enums/tradingMode.d.ts +0 -17
- package/dist/cjs/enums/tradingMode.js +0 -21
- package/dist/cjs/governance.d.ts +0 -62
- package/dist/cjs/governance.js +0 -151
- package/dist/cjs/index.d.ts +0 -7
- package/dist/cjs/interfaces/IChainClient.d.ts +0 -6
- package/dist/cjs/interfaces/index.d.ts +0 -4
- package/dist/cjs/interfaces/tradingLimit.d.ts +0 -7
- package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +0 -10
- package/dist/cjs/interfaces/tradingLimitsState.d.ts +0 -9
- package/dist/cjs/limits.d.ts +0 -33
- package/dist/cjs/limits.js +0 -130
- package/dist/cjs/mento.d.ts +0 -287
- package/dist/cjs/mento.js +0 -699
- package/dist/cjs/routeUtils.d.ts +0 -304
- package/dist/cjs/types/contractAddressMap.d.ts +0 -4
- package/dist/cjs/types/contractAddressMap.js +0 -2
- package/dist/cjs/types/contractAddresses.d.ts +0 -23
- package/dist/cjs/types/index.d.ts +0 -2
- package/dist/cjs/utils.d.ts +0 -80
- package/dist/cjs/utils.js +0 -177
- package/dist/esm/ChainClient.d.ts +0 -9
- package/dist/esm/ChainClient.js +0 -54
- package/dist/esm/TestChainClient.d.ts +0 -7
- package/dist/esm/TestChainClient.js +0 -37
- package/dist/esm/constants/addresses.d.ts +0 -4
- package/dist/esm/constants/addresses.js +0 -55
- package/dist/esm/constants/currencies.d.ts +0 -5
- package/dist/esm/constants/currencies.js +0 -26
- package/dist/esm/constants/index.d.ts +0 -4
- package/dist/esm/constants/index.js +0 -4
- package/dist/esm/constants/tokens.11142220.d.ts +0 -2
- package/dist/esm/constants/tokens.11142220.js +0 -125
- package/dist/esm/constants/tokens.42220.d.ts +0 -2
- package/dist/esm/constants/tokens.42220.js +0 -125
- package/dist/esm/constants/tokens.d.ts +0 -65
- package/dist/esm/constants/tokens.js +0 -142
- package/dist/esm/constants/tradablePairs.11142220.d.ts +0 -2
- package/dist/esm/constants/tradablePairs.11142220.js +0 -7388
- package/dist/esm/constants/tradablePairs.42220.d.ts +0 -2
- package/dist/esm/constants/tradablePairs.42220.js +0 -7388
- package/dist/esm/constants/tradablePairs.d.ts +0 -16
- package/dist/esm/constants/tradablePairs.js +0 -26
- package/dist/esm/enums/chainId.d.ts +0 -4
- package/dist/esm/enums/index.d.ts +0 -3
- package/dist/esm/enums/index.js +0 -3
- package/dist/esm/enums/proposalState.d.ts +0 -10
- package/dist/esm/enums/proposalState.js +0 -11
- package/dist/esm/enums/tradingMode.d.ts +0 -17
- package/dist/esm/enums/tradingMode.js +0 -18
- package/dist/esm/governance.d.ts +0 -62
- package/dist/esm/governance.js +0 -147
- package/dist/esm/index.d.ts +0 -7
- package/dist/esm/interfaces/IChainClient.d.ts +0 -6
- package/dist/esm/interfaces/index.d.ts +0 -4
- package/dist/esm/interfaces/index.js +0 -4
- package/dist/esm/interfaces/tradingLimit.d.ts +0 -7
- package/dist/esm/interfaces/tradingLimitsConfig.d.ts +0 -10
- package/dist/esm/interfaces/tradingLimitsState.d.ts +0 -9
- package/dist/esm/limits.d.ts +0 -33
- package/dist/esm/limits.js +0 -123
- package/dist/esm/mento.d.ts +0 -287
- package/dist/esm/mento.js +0 -671
- package/dist/esm/types/contractAddressMap.d.ts +0 -4
- package/dist/esm/types/contractAddresses.d.ts +0 -23
- package/dist/esm/types/index.d.ts +0 -2
- package/dist/esm/types/index.js +0 -2
- package/dist/esm/utils.d.ts +0 -80
- package/dist/esm/utils.js +0 -162
- /package/dist/esm/{interfaces/IChainClient.js → core/types/borrow.js} +0 -0
- /package/dist/esm/{types → core/types}/contractAddresses.js +0 -0
- /package/dist/esm/{interfaces/tradingLimit.js → core/types/liquidity.js} +0 -0
- /package/dist/esm/{interfaces/tradingLimitsConfig.js → core/types/provider.js} +0 -0
- /package/dist/esm/{interfaces/tradingLimitsState.js → core/types/route.js} +0 -0
- /package/dist/esm/{types/contractAddressMap.js → core/types/token.js} +0 -0
|
@@ -0,0 +1,306 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.RouteService = void 0;
|
|
37
|
+
const abis_1 = require("../../core/abis");
|
|
38
|
+
const errors_1 = require("../../core/errors");
|
|
39
|
+
const routeUtils_1 = require("../../utils/routeUtils");
|
|
40
|
+
const sortUtils_1 = require("../../utils/sortUtils");
|
|
41
|
+
const multicall_1 = require("../../utils/multicall");
|
|
42
|
+
/**
|
|
43
|
+
* Service for discovering and managing trading routes in the Mento protocol.
|
|
44
|
+
* Handles route discovery for both direct (single-hop) and multi-hop trading paths.
|
|
45
|
+
*
|
|
46
|
+
* Routes are identified by their token pair and include the path of pools
|
|
47
|
+
* needed to execute the trade. Multi-hop routes (up to 2 hops) are automatically
|
|
48
|
+
* discovered when no direct route exists between two tokens.
|
|
49
|
+
*/
|
|
50
|
+
class RouteService {
|
|
51
|
+
constructor(publicClient, chainId, poolService) {
|
|
52
|
+
this.publicClient = publicClient;
|
|
53
|
+
this.chainId = chainId;
|
|
54
|
+
this.poolService = poolService;
|
|
55
|
+
this.symbolCache = new Map();
|
|
56
|
+
this.routeCache = new Map();
|
|
57
|
+
this.routeLookupCache = new Map();
|
|
58
|
+
this.routePromises = new Map();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generates all direct (single-hop) routes from available pools
|
|
62
|
+
* Routes are deduplicated and assets are sorted alphabetically by symbol
|
|
63
|
+
*
|
|
64
|
+
* @returns Array of direct routes with single-hop paths
|
|
65
|
+
* @throws {Error} If RPC calls fail
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const directRoutes = await routeService.getDirectRoutes()
|
|
70
|
+
* console.log(`Found ${directRoutes.length} direct routes`)
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
async getDirectRoutes() {
|
|
74
|
+
const pools = await this.poolService.getPools();
|
|
75
|
+
if (pools.length === 0) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
// Fetch all unique token addresses
|
|
79
|
+
const uniqueTokens = new Set();
|
|
80
|
+
pools.forEach((pool) => {
|
|
81
|
+
uniqueTokens.add(pool.token0);
|
|
82
|
+
uniqueTokens.add(pool.token1);
|
|
83
|
+
});
|
|
84
|
+
// Fetch symbols for all tokens in parallel. Used for the route ids
|
|
85
|
+
const tokenAddresses = Array.from(uniqueTokens);
|
|
86
|
+
await this.hydrateTokenSymbols(tokenAddresses);
|
|
87
|
+
const routes = [];
|
|
88
|
+
// Loop all pools
|
|
89
|
+
for (const pool of pools) {
|
|
90
|
+
const symbol0 = this.symbolCache.get(pool.token0);
|
|
91
|
+
const symbol1 = this.symbolCache.get(pool.token1);
|
|
92
|
+
if (!symbol0 || !symbol1) {
|
|
93
|
+
throw new Error(`Symbol not found for token ${pool.token0} or ${pool.token1}`);
|
|
94
|
+
}
|
|
95
|
+
// Create canonical route ID (alphabetically sorted symbols)
|
|
96
|
+
const routeId = (0, sortUtils_1.canonicalSymbolKey)(symbol0, symbol1);
|
|
97
|
+
// Sort tokens to match the canonical route ID order (alphabetical by symbol)
|
|
98
|
+
const sortedTokens = symbol0 < symbol1
|
|
99
|
+
? [
|
|
100
|
+
{ address: pool.token0, symbol: symbol0 },
|
|
101
|
+
{ address: pool.token1, symbol: symbol1 },
|
|
102
|
+
]
|
|
103
|
+
: [
|
|
104
|
+
{ address: pool.token1, symbol: symbol1 },
|
|
105
|
+
{ address: pool.token0, symbol: symbol0 },
|
|
106
|
+
];
|
|
107
|
+
routes.push({
|
|
108
|
+
id: routeId,
|
|
109
|
+
tokens: sortedTokens,
|
|
110
|
+
path: [pool],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return routes;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Discovers all tradable routes including multi-hop routes (up to 2 hops)
|
|
117
|
+
* Uses cached data by default for instant results, or generates fresh from blockchain
|
|
118
|
+
*
|
|
119
|
+
* @param options - Configuration options
|
|
120
|
+
* @param options.cached - Whether to use pre-generated cached routes (default: true)
|
|
121
|
+
* @param options.returnAllRoutes - Whether to return all possible routes or just the optimal one per pair (default: false)
|
|
122
|
+
* @returns Array of all tradable routes (direct + multi-hop routes)
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* // Fast: use pre-generated cache
|
|
127
|
+
* const cachedRoutes = await routeService.getRoutes({ cached: true })
|
|
128
|
+
*
|
|
129
|
+
* // Slower but fresh: generate from blockchain
|
|
130
|
+
* const freshRoutes = await routeService.getRoutes({ cached: false })
|
|
131
|
+
*
|
|
132
|
+
* // Get all route variants (useful for cache generation)
|
|
133
|
+
* const allRoutes = await routeService.getRoutes({ cached: false, returnAllRoutes: true })
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
async getRoutes(options) {
|
|
137
|
+
const cached = options?.cached ?? true;
|
|
138
|
+
const returnAllRoutes = options?.returnAllRoutes ?? false;
|
|
139
|
+
const cacheKey = this.getCacheKey(cached, returnAllRoutes);
|
|
140
|
+
const cachedRoutes = this.routeCache.get(cacheKey);
|
|
141
|
+
if (cachedRoutes) {
|
|
142
|
+
return cachedRoutes;
|
|
143
|
+
}
|
|
144
|
+
const inFlight = this.routePromises.get(cacheKey);
|
|
145
|
+
if (inFlight) {
|
|
146
|
+
return inFlight;
|
|
147
|
+
}
|
|
148
|
+
const promise = this.loadRoutes(cached, returnAllRoutes);
|
|
149
|
+
this.routePromises.set(cacheKey, promise);
|
|
150
|
+
try {
|
|
151
|
+
const routes = await promise;
|
|
152
|
+
this.routeCache.set(cacheKey, routes);
|
|
153
|
+
if (!returnAllRoutes) {
|
|
154
|
+
this.routeLookupCache.set(cacheKey, this.buildLookup(routes));
|
|
155
|
+
}
|
|
156
|
+
return routes;
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
this.routePromises.delete(cacheKey);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async warm(options) {
|
|
163
|
+
return this.getRoutes(options);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Looks up the tradable route between two tokens (direct or multi-hop)
|
|
167
|
+
*
|
|
168
|
+
* @param tokenIn - Input token address (direction matters for routing)
|
|
169
|
+
* @param tokenOut - Output token address (direction matters for routing)
|
|
170
|
+
* @param options - Optional configuration (e.g., cached)
|
|
171
|
+
* @returns The optimal tradable route connecting the two tokens
|
|
172
|
+
* @throws {RouteNotFoundError} If no route exists between the token pair
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const USDm = '0x765DE816845861e75A25fCA122bb6898B8B1282a'
|
|
177
|
+
* const BRLm = '0xE4D5...'
|
|
178
|
+
* const route = await routeService.findRoute(USDm, BRLm)
|
|
179
|
+
*
|
|
180
|
+
* if (route.path.length === 1) {
|
|
181
|
+
* console.log('Direct route available')
|
|
182
|
+
* } else {
|
|
183
|
+
* console.log('Two-hop route:', route.path)
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
async findRoute(tokenIn, tokenOut, options) {
|
|
188
|
+
const cached = options?.cached ?? true;
|
|
189
|
+
const cacheKey = this.getCacheKey(cached, false);
|
|
190
|
+
const routes = await this.getRoutes({ cached, returnAllRoutes: false });
|
|
191
|
+
const lookup = this.routeLookupCache.get(cacheKey) ?? this.buildLookup(routes);
|
|
192
|
+
this.routeLookupCache.set(cacheKey, lookup);
|
|
193
|
+
const matchingRoute = lookup.get(makeTokenPairKey(tokenIn, tokenOut));
|
|
194
|
+
if (!matchingRoute) {
|
|
195
|
+
throw new errors_1.RouteNotFoundError(tokenIn, tokenOut);
|
|
196
|
+
}
|
|
197
|
+
return matchingRoute;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Generate fresh tradable routes from blockchain data
|
|
201
|
+
* @param returnAllRoutes - Whether to return all routes or just optimal ones per pair
|
|
202
|
+
* @private
|
|
203
|
+
*/
|
|
204
|
+
async generateFreshRoutes(returnAllRoutes = false) {
|
|
205
|
+
// Get direct routes
|
|
206
|
+
const directRoutes = await this.getDirectRoutes();
|
|
207
|
+
if (directRoutes.length === 0) {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
// Build connectivity structures for route finding
|
|
211
|
+
const connectivity = (0, routeUtils_1.buildConnectivityStructures)(directRoutes);
|
|
212
|
+
// Generate all possible routes (direct + 2-hop)
|
|
213
|
+
const allRoutes = (0, routeUtils_1.generateAllRoutes)(connectivity);
|
|
214
|
+
// Select routes based on returnAllRoutes flag
|
|
215
|
+
const selectedRoutes = (0, routeUtils_1.selectOptimalRoutes)(allRoutes, returnAllRoutes, connectivity.addrToSymbol);
|
|
216
|
+
return selectedRoutes;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Load cached tradable routes for current chain
|
|
220
|
+
* @private
|
|
221
|
+
*/
|
|
222
|
+
async loadCachedRoutes() {
|
|
223
|
+
const { getCachedRoutes } = await Promise.resolve().then(() => __importStar(require('../../utils/routes')));
|
|
224
|
+
const cachedRoutes = await getCachedRoutes(this.chainId);
|
|
225
|
+
return cachedRoutes || [];
|
|
226
|
+
}
|
|
227
|
+
async loadRoutes(cached, returnAllRoutes) {
|
|
228
|
+
if (cached) {
|
|
229
|
+
try {
|
|
230
|
+
const cachedRoutes = await this.loadCachedRoutes();
|
|
231
|
+
if (cachedRoutes.length > 0) {
|
|
232
|
+
return returnAllRoutes ? cachedRoutes : cachedRoutes;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
// Cache miss or corrupt - silently fall through to fresh generation
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return this.generateFreshRoutes(returnAllRoutes);
|
|
240
|
+
}
|
|
241
|
+
getCacheKey(cached, returnAllRoutes) {
|
|
242
|
+
return `${cached ? 'cached' : 'fresh'}:${returnAllRoutes ? 'all' : 'best'}`;
|
|
243
|
+
}
|
|
244
|
+
buildLookup(routes) {
|
|
245
|
+
const lookup = new Map();
|
|
246
|
+
for (const route of routes) {
|
|
247
|
+
lookup.set(makeTokenPairKey(route.tokens[0].address, route.tokens[1].address), route);
|
|
248
|
+
}
|
|
249
|
+
return lookup;
|
|
250
|
+
}
|
|
251
|
+
async hydrateTokenSymbols(addresses) {
|
|
252
|
+
const missingAddresses = addresses.filter((address) => !this.symbolCache.has(address));
|
|
253
|
+
if (missingAddresses.length === 0) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const results = await (0, multicall_1.multicall)(this.publicClient, missingAddresses.map((address) => ({
|
|
257
|
+
address: address,
|
|
258
|
+
abi: abis_1.ERC20_ABI,
|
|
259
|
+
functionName: 'symbol',
|
|
260
|
+
args: [],
|
|
261
|
+
})));
|
|
262
|
+
for (const [index, address] of missingAddresses.entries()) {
|
|
263
|
+
const result = results[index];
|
|
264
|
+
if (!result || result.status === 'failure') {
|
|
265
|
+
this.symbolCache.set(address, address);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
this.symbolCache.set(address, result.result);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Helper: Fetch token symbol from on-chain
|
|
273
|
+
* Results are cached to avoid redundant RPC calls
|
|
274
|
+
* Falls back to address if symbol fetch fails
|
|
275
|
+
*
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
async fetchTokenSymbol(address) {
|
|
279
|
+
// Return cached symbol if available
|
|
280
|
+
if (this.symbolCache.has(address)) {
|
|
281
|
+
return this.symbolCache.get(address);
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
const symbol = (await this.publicClient.readContract({
|
|
285
|
+
address: address,
|
|
286
|
+
abi: abis_1.ERC20_ABI,
|
|
287
|
+
functionName: 'symbol',
|
|
288
|
+
args: [],
|
|
289
|
+
}));
|
|
290
|
+
// Cache the symbol
|
|
291
|
+
this.symbolCache.set(address, symbol);
|
|
292
|
+
return symbol;
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
// Fallback to address if symbol fetch fails
|
|
296
|
+
this.symbolCache.set(address, address);
|
|
297
|
+
return address;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.RouteService = RouteService;
|
|
302
|
+
function makeTokenPairKey(tokenA, tokenB) {
|
|
303
|
+
const [first, second] = [tokenA.toLowerCase(), tokenB.toLowerCase()].sort();
|
|
304
|
+
return `${first}:${second}`;
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=RouteService.js.map
|
|
@@ -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,198 @@
|
|
|
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
|
+
* Use `deadlineFromMinutes()` for convenience.
|
|
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
|
+
export interface PrepareSwapInput {
|
|
67
|
+
tokenIn: string;
|
|
68
|
+
tokenOut: string;
|
|
69
|
+
amountIn: bigint;
|
|
70
|
+
slippageTolerance: number;
|
|
71
|
+
recipient?: string;
|
|
72
|
+
owner?: string;
|
|
73
|
+
deadline?: bigint;
|
|
74
|
+
route?: Route;
|
|
75
|
+
}
|
|
76
|
+
export interface PreparedSwap {
|
|
77
|
+
route: Route;
|
|
78
|
+
routerRoutes: RouterRoute[];
|
|
79
|
+
expectedAmountOut: bigint;
|
|
80
|
+
amountOutMin: bigint;
|
|
81
|
+
approval?: CallParams | null;
|
|
82
|
+
params?: CallParams;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Service for building token swap transactions on the Mento protocol.
|
|
86
|
+
* Returns transaction parameters that can be executed by any wallet.
|
|
87
|
+
*/
|
|
88
|
+
export declare class SwapService {
|
|
89
|
+
private publicClient;
|
|
90
|
+
private chainId;
|
|
91
|
+
private routeService;
|
|
92
|
+
private quoteService;
|
|
93
|
+
constructor(publicClient: PublicClient, chainId: number, routeService: RouteService, quoteService: QuoteService);
|
|
94
|
+
/**
|
|
95
|
+
* Builds a complete swap transaction including approval if needed.
|
|
96
|
+
* This is the recommended method for most use cases.
|
|
97
|
+
*
|
|
98
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
99
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
100
|
+
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
101
|
+
* @param recipient - The address to receive the output tokens
|
|
102
|
+
* @param owner - The address that owns the input tokens (needed to check allowance)
|
|
103
|
+
* @param options - Swap configuration options (slippage, deadline)
|
|
104
|
+
* @param route - Optional pre-fetched route for better performance
|
|
105
|
+
* @returns Combined transaction with approval (if needed) and swap params
|
|
106
|
+
* @throws {Error} 'amountIn must be greater than zero' - if amountIn <= 0
|
|
107
|
+
* @throws {Error} 'Slippage tolerance cannot be negative' - if slippageTolerance < 0
|
|
108
|
+
* @throws {Error} 'Slippage tolerance exceeds maximum' - if slippageTolerance > 20%
|
|
109
|
+
* @throws {Error} 'Deadline must be in the future' - if deadline is not a future timestamp
|
|
110
|
+
* @throws {Error} Invalid address - if any address parameter is not a valid Ethereum address
|
|
111
|
+
* @throws {RouteNotFoundError} If no trading route exists between the token pair
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const { approval, swap } = await mento.swap.buildSwapTransaction(
|
|
116
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
117
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
118
|
+
* parseUnits('100', 18),
|
|
119
|
+
* '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // recipient
|
|
120
|
+
* '0x123...', // owner
|
|
121
|
+
* { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) }
|
|
122
|
+
* )
|
|
123
|
+
*
|
|
124
|
+
* // Execute approval if needed
|
|
125
|
+
* if (approval) {
|
|
126
|
+
* await walletClient.sendTransaction(approval)
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* // Execute swap
|
|
130
|
+
* await walletClient.sendTransaction(swap.params)
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
buildSwapTransaction(tokenIn: string, tokenOut: string, amountIn: bigint, recipient: string, owner: string, options: SwapOptions, route?: Route): Promise<SwapTransaction>;
|
|
134
|
+
/**
|
|
135
|
+
* Builds swap transaction parameters without executing the transaction.
|
|
136
|
+
* Does NOT check or handle token approval - use buildSwapTransaction for that.
|
|
137
|
+
*
|
|
138
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
139
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
140
|
+
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
141
|
+
* @param recipient - The address to receive the output tokens
|
|
142
|
+
* @param options - Swap configuration options (slippage, deadline)
|
|
143
|
+
* @param route - Optional pre-fetched route for better performance
|
|
144
|
+
* @returns Detailed swap parameters including transaction data
|
|
145
|
+
* @throws {Error} 'amountIn must be greater than zero' - if amountIn <= 0
|
|
146
|
+
* @throws {Error} 'Slippage tolerance cannot be negative' - if slippageTolerance < 0
|
|
147
|
+
* @throws {Error} 'Slippage tolerance exceeds maximum' - if slippageTolerance > 20%
|
|
148
|
+
* @throws {Error} 'Deadline must be in the future' - if deadline is not a future timestamp
|
|
149
|
+
* @throws {Error} Invalid address - if any address parameter is not a valid Ethereum address
|
|
150
|
+
* @throws {RouteNotFoundError} If no trading route exists between the token pair
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const swapDetails = await mento.swap.buildSwapParams(
|
|
155
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
156
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
157
|
+
* parseUnits('100', 18),
|
|
158
|
+
* '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // recipient
|
|
159
|
+
* { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) }
|
|
160
|
+
* )
|
|
161
|
+
*
|
|
162
|
+
* // Execute with any wallet (assumes approval already granted)
|
|
163
|
+
* await walletClient.sendTransaction(swapDetails.params)
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
buildSwapParams(tokenIn: string, tokenOut: string, amountIn: bigint, recipient: string, options: SwapOptions, route?: Route): Promise<SwapDetails>;
|
|
167
|
+
prepareSwap(input: PrepareSwapInput): Promise<PreparedSwap>;
|
|
168
|
+
/**
|
|
169
|
+
* Builds approval transaction params for the Router to spend tokenIn
|
|
170
|
+
* @private
|
|
171
|
+
*/
|
|
172
|
+
private buildApprovalParams;
|
|
173
|
+
/**
|
|
174
|
+
* Gets current allowance for the Router contract
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
private getAllowance;
|
|
178
|
+
/**
|
|
179
|
+
* Validates that the input amount is strictly positive.
|
|
180
|
+
* @private
|
|
181
|
+
*/
|
|
182
|
+
private validateAmountIn;
|
|
183
|
+
/**
|
|
184
|
+
* Calculates minimum output amount after applying slippage tolerance
|
|
185
|
+
* @param amountOut - Expected output amount
|
|
186
|
+
* @param slippageTolerance - Slippage tolerance as percentage (e.g., 0.5 for 0.5%)
|
|
187
|
+
* @returns Minimum acceptable output amount
|
|
188
|
+
* @throws Error if slippage tolerance is invalid
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
private calculateMinAmountOut;
|
|
192
|
+
/**
|
|
193
|
+
* Encodes the swapExactTokensForTokens function call
|
|
194
|
+
* @private
|
|
195
|
+
*/
|
|
196
|
+
private encodeSwapCall;
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=SwapService.d.ts.map
|