@mento-protocol/mento-sdk 3.0.0-beta.3 → 3.0.0-beta.31
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 +132 -275
- package/dist/cache/routes.d.ts +13 -0
- package/dist/cache/routes.d.ts.map +1 -0
- package/dist/cache/routes.js +11483 -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/activePool.d.ts +2 -0
- package/dist/core/abis/activePool.d.ts.map +1 -0
- package/dist/core/abis/activePool.js +14 -0
- package/dist/core/abis/activePool.js.map +1 -0
- package/dist/core/abis/addressesRegistry.d.ts +2 -0
- package/dist/core/abis/addressesRegistry.d.ts.map +1 -0
- package/dist/core/abis/addressesRegistry.js +26 -0
- package/dist/core/abis/addressesRegistry.js.map +1 -0
- package/dist/core/abis/borrowerOperations.d.ts +9 -0
- package/dist/core/abis/borrowerOperations.d.ts.map +1 -0
- package/dist/core/abis/borrowerOperations.js +89 -0
- package/dist/core/abis/borrowerOperations.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/erc20.d.ts +7 -0
- package/dist/core/abis/erc20.d.ts.map +1 -1
- package/dist/core/abis/erc20.js +7 -0
- package/dist/core/abis/erc20.js.map +1 -1
- package/dist/core/abis/fpmm.d.ts +236 -0
- package/dist/core/abis/fpmm.d.ts.map +1 -1
- package/dist/core/abis/fpmm.js +38 -0
- package/dist/core/abis/fpmm.js.map +1 -1
- package/dist/core/abis/fpmmFactory.d.ts +64 -0
- package/dist/core/abis/fpmmFactory.d.ts.map +1 -1
- package/dist/core/abis/fpmmFactory.js +17 -0
- package/dist/core/abis/fpmmFactory.js.map +1 -1
- package/dist/core/abis/hintHelpers.d.ts +2 -0
- package/dist/core/abis/hintHelpers.d.ts.map +1 -0
- package/dist/core/abis/hintHelpers.js +14 -0
- package/dist/core/abis/hintHelpers.js.map +1 -0
- package/dist/core/abis/index.d.ts +12 -1
- package/dist/core/abis/index.d.ts.map +1 -1
- package/dist/core/abis/index.js +12 -1
- package/dist/core/abis/index.js.map +1 -1
- package/dist/core/abis/multiTroveGetter.d.ts +8 -0
- package/dist/core/abis/multiTroveGetter.d.ts.map +1 -0
- package/dist/core/abis/multiTroveGetter.js +15 -0
- package/dist/core/abis/multiTroveGetter.js.map +1 -0
- package/dist/core/abis/priceFeed.d.ts +7 -0
- package/dist/core/abis/priceFeed.d.ts.map +1 -0
- package/dist/core/abis/priceFeed.js +16 -0
- package/dist/core/abis/priceFeed.js.map +1 -0
- package/dist/core/abis/router.d.ts +520 -1
- package/dist/core/abis/router.d.ts.map +1 -1
- package/dist/core/abis/router.js +35 -0
- package/dist/core/abis/router.js.map +1 -1
- package/dist/core/abis/sortedTroves.d.ts +2 -0
- package/dist/core/abis/sortedTroves.d.ts.map +1 -0
- package/dist/core/abis/sortedTroves.js +15 -0
- package/dist/core/abis/sortedTroves.js.map +1 -0
- package/dist/core/abis/systemParams.d.ts +2 -0
- package/dist/core/abis/systemParams.d.ts.map +1 -0
- package/dist/core/abis/systemParams.js +14 -0
- package/dist/core/abis/systemParams.js.map +1 -0
- package/dist/core/abis/troveManager.d.ts +2 -0
- package/dist/core/abis/troveManager.d.ts.map +1 -0
- package/dist/core/abis/troveManager.js +27 -0
- package/dist/core/abis/troveManager.js.map +1 -0
- package/dist/core/abis/troveNFT.d.ts +2 -0
- package/dist/core/abis/troveNFT.d.ts.map +1 -0
- package/dist/core/abis/troveNFT.js +9 -0
- package/dist/core/abis/troveNFT.js.map +1 -0
- package/dist/core/abis/virtualPool.d.ts +40 -0
- package/dist/core/abis/virtualPool.d.ts.map +1 -1
- package/dist/core/abis/virtualPool.js +6 -1
- package/dist/core/abis/virtualPool.js.map +1 -1
- package/dist/core/abis/virtualPoolFactory.d.ts +32 -0
- package/dist/core/abis/virtualPoolFactory.d.ts.map +1 -1
- package/dist/core/abis/virtualPoolFactory.js +8 -0
- package/dist/core/abis/virtualPoolFactory.js.map +1 -1
- package/dist/core/constants/addresses.d.ts.map +1 -1
- package/dist/core/constants/addresses.js +12 -4
- package/dist/core/constants/addresses.js.map +1 -1
- package/dist/core/constants/borrowConstants.d.ts +10 -0
- package/dist/core/constants/borrowConstants.d.ts.map +1 -0
- package/dist/core/constants/borrowConstants.js +16 -0
- package/dist/core/constants/borrowConstants.js.map +1 -0
- package/dist/core/constants/borrowRegistries.d.ts +7 -0
- package/dist/core/constants/borrowRegistries.d.ts.map +1 -0
- package/dist/core/constants/borrowRegistries.js +30 -0
- package/dist/core/constants/borrowRegistries.js.map +1 -0
- package/dist/core/constants/index.d.ts +2 -3
- package/dist/core/constants/index.d.ts.map +1 -1
- package/dist/core/constants/index.js +2 -3
- package/dist/core/constants/index.js.map +1 -1
- package/dist/core/errors/index.d.ts +1 -0
- package/dist/core/errors/index.d.ts.map +1 -1
- package/dist/core/errors/index.js +1 -0
- package/dist/core/errors/index.js.map +1 -1
- package/dist/core/errors/oracle.d.ts +9 -0
- package/dist/core/errors/oracle.d.ts.map +1 -0
- package/dist/core/errors/oracle.js +15 -0
- package/dist/core/errors/oracle.js.map +1 -0
- package/dist/core/errors/router.d.ts +6 -0
- package/dist/core/errors/router.d.ts.map +1 -1
- package/dist/core/errors/router.js +11 -1
- package/dist/core/errors/router.js.map +1 -1
- package/dist/core/types/borrow.d.ts +87 -0
- package/dist/core/types/borrow.d.ts.map +1 -0
- package/dist/{services/tokens/supply/ISupplyCalculator.js → core/types/borrow.js} +1 -1
- package/dist/core/types/borrow.js.map +1 -0
- package/dist/core/types/contractAddresses.d.ts +2 -0
- package/dist/core/types/contractAddresses.d.ts.map +1 -1
- package/dist/core/types/index.d.ts +5 -1
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/core/types/index.js +5 -1
- package/dist/core/types/index.js.map +1 -1
- package/dist/core/types/liquidity.d.ts +117 -0
- package/dist/core/types/liquidity.d.ts.map +1 -0
- package/dist/{services/tokens/supply/calculatorFactory.js → core/types/liquidity.js} +1 -1
- package/dist/core/types/liquidity.js.map +1 -0
- package/dist/core/types/pool.d.ts +110 -0
- package/dist/core/types/pool.d.ts.map +1 -1
- package/dist/core/types/provider.d.ts.map +1 -1
- package/dist/core/types/provider.js +0 -1
- package/dist/core/types/provider.js.map +1 -1
- package/dist/core/types/route.d.ts +3 -3
- package/dist/core/types/route.d.ts.map +1 -1
- package/dist/core/types/token.d.ts +13 -17
- package/dist/core/types/token.d.ts.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 +35 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -14
- package/dist/index.js.map +1 -1
- package/dist/services/borrow/BorrowService.d.ts +54 -0
- package/dist/services/borrow/BorrowService.d.ts.map +1 -0
- package/dist/services/borrow/BorrowService.js +129 -0
- package/dist/services/borrow/BorrowService.js.map +1 -0
- package/dist/services/borrow/borrowHelpers.d.ts +4 -0
- package/dist/services/borrow/borrowHelpers.d.ts.map +1 -0
- package/dist/services/borrow/borrowHelpers.js +13 -0
- package/dist/services/borrow/borrowHelpers.js.map +1 -0
- package/dist/services/borrow/borrowMath.d.ts +13 -0
- package/dist/services/borrow/borrowMath.d.ts.map +1 -0
- package/dist/services/borrow/borrowMath.js +129 -0
- package/dist/services/borrow/borrowMath.js.map +1 -0
- package/dist/services/borrow/index.d.ts +2 -0
- package/dist/services/borrow/index.d.ts.map +1 -0
- package/dist/services/{tokens/supply → borrow}/index.js +1 -6
- package/dist/services/borrow/index.js.map +1 -0
- package/dist/services/borrow/internal/borrowApprovalService.d.ts +14 -0
- package/dist/services/borrow/internal/borrowApprovalService.d.ts.map +1 -0
- package/dist/services/borrow/internal/borrowApprovalService.js +53 -0
- package/dist/services/borrow/internal/borrowApprovalService.js.map +1 -0
- package/dist/services/borrow/internal/borrowContextStore.d.ts +11 -0
- package/dist/services/borrow/internal/borrowContextStore.d.ts.map +1 -0
- package/dist/services/borrow/internal/borrowContextStore.js +40 -0
- package/dist/services/borrow/internal/borrowContextStore.js.map +1 -0
- package/dist/services/borrow/internal/borrowErc20.d.ts +5 -0
- package/dist/services/borrow/internal/borrowErc20.d.ts.map +1 -0
- package/dist/services/borrow/internal/borrowErc20.js +43 -0
- package/dist/services/borrow/internal/borrowErc20.js.map +1 -0
- package/dist/services/borrow/internal/borrowHints.d.ts +7 -0
- package/dist/services/borrow/internal/borrowHints.d.ts.map +1 -0
- package/dist/services/borrow/internal/borrowHints.js +31 -0
- package/dist/services/borrow/internal/borrowHints.js.map +1 -0
- package/dist/services/borrow/internal/borrowPositionParser.d.ts +4 -0
- package/dist/services/borrow/internal/borrowPositionParser.d.ts.map +1 -0
- package/dist/services/borrow/internal/borrowPositionParser.js +87 -0
- package/dist/services/borrow/internal/borrowPositionParser.js.map +1 -0
- package/dist/services/borrow/internal/borrowReadService.d.ts +28 -0
- package/dist/services/borrow/internal/borrowReadService.d.ts.map +1 -0
- package/dist/services/borrow/internal/borrowReadService.js +218 -0
- package/dist/services/borrow/internal/borrowReadService.js.map +1 -0
- package/dist/services/borrow/internal/borrowRegistryReader.d.ts +5 -0
- package/dist/services/borrow/internal/borrowRegistryReader.d.ts.map +1 -0
- package/dist/services/borrow/internal/borrowRegistryReader.js +96 -0
- package/dist/services/borrow/internal/borrowRegistryReader.js.map +1 -0
- package/dist/services/borrow/internal/borrowTransactionService.d.ts +23 -0
- package/dist/services/borrow/internal/borrowTransactionService.d.ts.map +1 -0
- package/dist/services/borrow/internal/borrowTransactionService.js +276 -0
- package/dist/services/borrow/internal/borrowTransactionService.js.map +1 -0
- package/dist/services/borrow/internal/borrowTypes.d.ts +15 -0
- package/dist/services/borrow/internal/borrowTypes.d.ts.map +1 -0
- package/dist/services/borrow/internal/borrowTypes.js +3 -0
- package/dist/services/borrow/internal/borrowTypes.js.map +1 -0
- package/dist/services/borrow/internal/borrowValidation.d.ts +13 -0
- package/dist/services/borrow/internal/borrowValidation.d.ts.map +1 -0
- package/dist/services/borrow/internal/borrowValidation.js +96 -0
- package/dist/services/borrow/internal/borrowValidation.js.map +1 -0
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +2 -2
- package/dist/services/index.js.map +1 -1
- package/dist/services/liquidity/LiquidityService.d.ts +154 -0
- package/dist/services/liquidity/LiquidityService.d.ts.map +1 -0
- package/dist/services/liquidity/LiquidityService.js +184 -0
- package/dist/services/liquidity/LiquidityService.js.map +1 -0
- package/dist/services/liquidity/basicLiquidity.d.ts +11 -0
- package/dist/services/liquidity/basicLiquidity.d.ts.map +1 -0
- package/dist/services/liquidity/basicLiquidity.js +172 -0
- package/dist/services/liquidity/basicLiquidity.js.map +1 -0
- package/dist/services/liquidity/index.d.ts +2 -0
- package/dist/services/liquidity/index.d.ts.map +1 -0
- package/dist/services/liquidity/index.js +18 -0
- package/dist/services/liquidity/index.js.map +1 -0
- package/dist/services/liquidity/liquidityHelpers.d.ts +13 -0
- package/dist/services/liquidity/liquidityHelpers.d.ts.map +1 -0
- package/dist/services/liquidity/liquidityHelpers.js +74 -0
- package/dist/services/liquidity/liquidityHelpers.js.map +1 -0
- package/dist/services/liquidity/zapHelpers.d.ts +66 -0
- package/dist/services/liquidity/zapHelpers.d.ts.map +1 -0
- package/dist/services/liquidity/zapHelpers.js +133 -0
- package/dist/services/liquidity/zapHelpers.js.map +1 -0
- package/dist/services/liquidity/zapIn.d.ts +17 -0
- package/dist/services/liquidity/zapIn.d.ts.map +1 -0
- package/dist/services/liquidity/zapIn.js +125 -0
- package/dist/services/liquidity/zapIn.js.map +1 -0
- package/dist/services/liquidity/zapOut.d.ts +17 -0
- package/dist/services/liquidity/zapOut.d.ts.map +1 -0
- package/dist/services/liquidity/zapOut.js +242 -0
- package/dist/services/liquidity/zapOut.js.map +1 -0
- package/dist/services/pools/PoolService.d.ts +35 -10
- package/dist/services/pools/PoolService.d.ts.map +1 -1
- package/dist/services/pools/PoolService.js +61 -112
- package/dist/services/pools/PoolService.js.map +1 -1
- 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 +151 -0
- package/dist/services/pools/poolDetails.js.map +1 -0
- package/dist/services/pools/poolDiscovery.d.ts +12 -0
- package/dist/services/pools/poolDiscovery.d.ts.map +1 -0
- package/dist/services/pools/poolDiscovery.js +114 -0
- package/dist/services/pools/poolDiscovery.js.map +1 -0
- package/dist/services/quotes/QuoteService.d.ts +21 -12
- package/dist/services/quotes/QuoteService.d.ts.map +1 -1
- package/dist/services/quotes/QuoteService.js +44 -17
- package/dist/services/quotes/QuoteService.js.map +1 -1
- package/dist/services/routes/RouteService.d.ts +3 -3
- package/dist/services/routes/RouteService.d.ts.map +1 -1
- package/dist/services/routes/RouteService.js +3 -6
- package/dist/services/routes/RouteService.js.map +1 -1
- package/dist/services/swap/SwapService.d.ts +23 -19
- package/dist/services/swap/SwapService.d.ts.map +1 -1
- package/dist/services/swap/SwapService.js +42 -17
- package/dist/services/swap/SwapService.js.map +1 -1
- package/dist/services/tokens/tokenService.d.ts +3 -3
- package/dist/services/tokens/tokenService.d.ts.map +1 -1
- package/dist/services/tokens/tokenService.js +26 -37
- package/dist/services/tokens/tokenService.js.map +1 -1
- 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/costUtils.js +4 -4
- package/dist/utils/costUtils.js.map +1 -1
- package/dist/utils/deadline.d.ts +21 -0
- package/dist/utils/deadline.d.ts.map +1 -0
- package/dist/utils/deadline.js +26 -0
- package/dist/utils/deadline.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/pathEncoder.d.ts +8 -2
- package/dist/utils/pathEncoder.d.ts.map +1 -1
- package/dist/utils/pathEncoder.js +19 -3
- package/dist/utils/pathEncoder.js.map +1 -1
- 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 +53 -53
- package/dist/utils/routeUtils.d.ts.map +1 -1
- package/dist/utils/routeUtils.js +41 -41
- package/dist/utils/routeUtils.js.map +1 -1
- package/dist/utils/routes.d.ts +2 -8
- package/dist/utils/routes.d.ts.map +1 -1
- package/dist/utils/routes.js +5 -46
- package/dist/utils/routes.js.map +1 -1
- package/dist/utils/tokens.d.ts +1 -62
- package/dist/utils/tokens.d.ts.map +1 -1
- package/dist/utils/tokens.js +10 -163
- package/dist/utils/tokens.js.map +1 -1
- 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 +6 -6
- package/dist/cache/routes.42220.d.ts +0 -3
- package/dist/cache/routes.42220.d.ts.map +0 -1
- package/dist/cache/routes.42220.js +0 -112
- package/dist/cache/routes.42220.js.map +0 -1
- package/dist/cache/tokens.11142220.d.ts +0 -3
- package/dist/cache/tokens.11142220.d.ts.map +0 -1
- package/dist/cache/tokens.11142220.js +0 -129
- package/dist/cache/tokens.11142220.js.map +0 -1
- package/dist/cache/tokens.42220.d.ts +0 -3
- package/dist/cache/tokens.42220.d.ts.map +0 -1
- package/dist/cache/tokens.42220.js +0 -129
- package/dist/cache/tokens.42220.js.map +0 -1
- package/dist/core/abis/uniswapV3.d.ts +0 -4
- package/dist/core/abis/uniswapV3.d.ts.map +0 -1
- package/dist/core/abis/uniswapV3.js +0 -16
- package/dist/core/abis/uniswapV3.js.map +0 -1
- package/dist/core/constants/aaveConfig.d.ts +0 -7
- package/dist/core/constants/aaveConfig.d.ts.map +0 -1
- package/dist/core/constants/aaveConfig.js +0 -22
- package/dist/core/constants/aaveConfig.js.map +0 -1
- package/dist/core/constants/mentoAddresses.d.ts +0 -7
- package/dist/core/constants/mentoAddresses.d.ts.map +0 -1
- package/dist/core/constants/mentoAddresses.js +0 -10
- package/dist/core/constants/mentoAddresses.js.map +0 -1
- package/dist/core/constants/protocolAddresses.d.ts +0 -5
- package/dist/core/constants/protocolAddresses.d.ts.map +0 -1
- package/dist/core/constants/protocolAddresses.js +0 -8
- package/dist/core/constants/protocolAddresses.js.map +0 -1
- package/dist/services/tokens/supply/ISupplyCalculator.d.ts +0 -14
- package/dist/services/tokens/supply/ISupplyCalculator.d.ts.map +0 -1
- package/dist/services/tokens/supply/ISupplyCalculator.js.map +0 -1
- package/dist/services/tokens/supply/aaveSupplyCalculator.d.ts +0 -22
- package/dist/services/tokens/supply/aaveSupplyCalculator.d.ts.map +0 -1
- package/dist/services/tokens/supply/aaveSupplyCalculator.js +0 -46
- package/dist/services/tokens/supply/aaveSupplyCalculator.js.map +0 -1
- package/dist/services/tokens/supply/calculatorFactory.d.ts +0 -8
- package/dist/services/tokens/supply/calculatorFactory.d.ts.map +0 -1
- package/dist/services/tokens/supply/calculatorFactory.js.map +0 -1
- package/dist/services/tokens/supply/defaultCalculatorFactory.d.ts +0 -9
- package/dist/services/tokens/supply/defaultCalculatorFactory.d.ts.map +0 -1
- package/dist/services/tokens/supply/defaultCalculatorFactory.js +0 -28
- package/dist/services/tokens/supply/defaultCalculatorFactory.js.map +0 -1
- package/dist/services/tokens/supply/index.d.ts +0 -7
- package/dist/services/tokens/supply/index.d.ts.map +0 -1
- package/dist/services/tokens/supply/index.js.map +0 -1
- package/dist/services/tokens/supply/multisigSupplyCalculator.d.ts +0 -9
- package/dist/services/tokens/supply/multisigSupplyCalculator.d.ts.map +0 -1
- package/dist/services/tokens/supply/multisigSupplyCalculator.js +0 -33
- package/dist/services/tokens/supply/multisigSupplyCalculator.js.map +0 -1
- package/dist/services/tokens/supply/uniV3SupplyCalculator.d.ts +0 -21
- package/dist/services/tokens/supply/uniV3SupplyCalculator.d.ts.map +0 -1
- package/dist/services/tokens/supply/uniV3SupplyCalculator.js +0 -238
- package/dist/services/tokens/supply/uniV3SupplyCalculator.js.map +0 -1
- package/dist/services/tokens/supplyAdjustmentService.d.ts +0 -19
- package/dist/services/tokens/supplyAdjustmentService.d.ts.map +0 -1
- package/dist/services/tokens/supplyAdjustmentService.js +0 -49
- package/dist/services/tokens/supplyAdjustmentService.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PublicClient } from 'viem';
|
|
2
2
|
import { RouteService } from '../routes';
|
|
3
3
|
import { Route } from '../../core/types';
|
|
4
4
|
/**
|
|
@@ -13,8 +13,8 @@ export declare class QuoteService {
|
|
|
13
13
|
/**
|
|
14
14
|
* Calculates the expected output amount for a swap between two tokens.
|
|
15
15
|
*
|
|
16
|
-
* @param tokenIn - The address of the input token
|
|
17
|
-
* @param tokenOut - The address of the output token
|
|
16
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
17
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
18
18
|
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
19
19
|
* @param route - Optional pre-fetched route. If not provided, the optimal route will be found automatically.
|
|
20
20
|
* @returns The expected output amount (in wei/smallest unit)
|
|
@@ -23,19 +23,28 @@ export declare class QuoteService {
|
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
25
|
* ```typescript
|
|
26
|
-
*
|
|
27
|
-
* const
|
|
28
|
-
*
|
|
29
|
-
* //
|
|
30
|
-
*
|
|
31
|
-
*
|
|
26
|
+
* // Calculate output for 100 USDm
|
|
27
|
+
* const amountIn = BigInt(100) * BigInt(10 ** 18) // 100 USDm in wei
|
|
28
|
+
* const expectedOut = await quoteService.getAmountOut(
|
|
29
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
30
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
31
|
+
* amountIn
|
|
32
|
+
* )
|
|
32
33
|
* console.log(`Expected CELO output: ${expectedOut}`)
|
|
33
34
|
*
|
|
34
35
|
* // Or provide a pre-fetched route for better performance
|
|
35
|
-
* const route = await routeService.findRoute(
|
|
36
|
-
*
|
|
36
|
+
* const route = await routeService.findRoute(
|
|
37
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
38
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438'
|
|
39
|
+
* )
|
|
40
|
+
* const expectedOut2 = await quoteService.getAmountOut(
|
|
41
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
42
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438',
|
|
43
|
+
* amountIn,
|
|
44
|
+
* route
|
|
45
|
+
* )
|
|
37
46
|
* ```
|
|
38
47
|
*/
|
|
39
|
-
getAmountOut(tokenIn:
|
|
48
|
+
getAmountOut(tokenIn: string, tokenOut: string, amountIn: bigint, route?: Route): Promise<bigint>;
|
|
40
49
|
}
|
|
41
50
|
//# sourceMappingURL=QuoteService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteService.d.ts","sourceRoot":"","sources":["../../../src/services/quotes/QuoteService.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"QuoteService.d.ts","sourceRoot":"","sources":["../../../src/services/quotes/QuoteService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,YAAY,EAA4C,MAAM,MAAM,CAAA;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAOxC;;;GAGG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,YAAY;gBAFZ,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,YAAY;IAGpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;CAoCxG"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QuoteService = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
4
5
|
const abis_1 = require("../../core/abis");
|
|
5
6
|
const constants_1 = require("../../core/constants");
|
|
7
|
+
const errors_1 = require("../../core/errors");
|
|
6
8
|
const pathEncoder_1 = require("../../utils/pathEncoder");
|
|
9
|
+
const validation_1 = require("../../utils/validation");
|
|
7
10
|
/**
|
|
8
11
|
* Service for getting swap quotes from the Mento protocol.
|
|
9
12
|
* Calculates expected output amounts for trades without executing them.
|
|
@@ -17,8 +20,8 @@ class QuoteService {
|
|
|
17
20
|
/**
|
|
18
21
|
* Calculates the expected output amount for a swap between two tokens.
|
|
19
22
|
*
|
|
20
|
-
* @param tokenIn - The address of the input token
|
|
21
|
-
* @param tokenOut - The address of the output token
|
|
23
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
24
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
22
25
|
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
23
26
|
* @param route - Optional pre-fetched route. If not provided, the optimal route will be found automatically.
|
|
24
27
|
* @returns The expected output amount (in wei/smallest unit)
|
|
@@ -27,20 +30,32 @@ class QuoteService {
|
|
|
27
30
|
*
|
|
28
31
|
* @example
|
|
29
32
|
* ```typescript
|
|
30
|
-
*
|
|
31
|
-
* const
|
|
32
|
-
*
|
|
33
|
-
* //
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* // Calculate output for 100 USDm
|
|
34
|
+
* const amountIn = BigInt(100) * BigInt(10 ** 18) // 100 USDm in wei
|
|
35
|
+
* const expectedOut = await quoteService.getAmountOut(
|
|
36
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
37
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
38
|
+
* amountIn
|
|
39
|
+
* )
|
|
36
40
|
* console.log(`Expected CELO output: ${expectedOut}`)
|
|
37
41
|
*
|
|
38
42
|
* // Or provide a pre-fetched route for better performance
|
|
39
|
-
* const route = await routeService.findRoute(
|
|
40
|
-
*
|
|
43
|
+
* const route = await routeService.findRoute(
|
|
44
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
45
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438'
|
|
46
|
+
* )
|
|
47
|
+
* const expectedOut2 = await quoteService.getAmountOut(
|
|
48
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
49
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438',
|
|
50
|
+
* amountIn,
|
|
51
|
+
* route
|
|
52
|
+
* )
|
|
41
53
|
* ```
|
|
42
54
|
*/
|
|
43
55
|
async getAmountOut(tokenIn, tokenOut, amountIn, route) {
|
|
56
|
+
// Validate address inputs
|
|
57
|
+
(0, validation_1.validateAddress)(tokenIn, 'tokenIn');
|
|
58
|
+
(0, validation_1.validateAddress)(tokenOut, 'tokenOut');
|
|
44
59
|
// If the consumer does not provide a route then we find the best route.
|
|
45
60
|
if (!route) {
|
|
46
61
|
route = await this.routeService.findRoute(tokenIn, tokenOut);
|
|
@@ -48,13 +63,25 @@ class QuoteService {
|
|
|
48
63
|
// Convert route.path to Router contract's Route[] format
|
|
49
64
|
const routerRoutes = (0, pathEncoder_1.encodeRoutePath)(route.path, tokenIn, tokenOut);
|
|
50
65
|
const routerAddress = (0, constants_1.getContractAddress)(this.chainId, 'Router');
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
try {
|
|
67
|
+
const amounts = (await this.publicClient.readContract({
|
|
68
|
+
address: routerAddress,
|
|
69
|
+
abi: abis_1.ROUTER_ABI,
|
|
70
|
+
functionName: 'getAmountsOut',
|
|
71
|
+
args: [amountIn, routerRoutes],
|
|
72
|
+
}));
|
|
73
|
+
return amounts[amounts.length - 1];
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (error instanceof viem_1.BaseError) {
|
|
77
|
+
const revertError = error.walk((e) => e instanceof viem_1.ContractFunctionRevertedError);
|
|
78
|
+
if (revertError instanceof viem_1.ContractFunctionRevertedError &&
|
|
79
|
+
revertError.data?.errorName === 'FXMarketClosed') {
|
|
80
|
+
throw new errors_1.FXMarketClosedError();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
58
85
|
}
|
|
59
86
|
}
|
|
60
87
|
exports.QuoteService = QuoteService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteService.js","sourceRoot":"","sources":["../../../src/services/quotes/QuoteService.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"QuoteService.js","sourceRoot":"","sources":["../../../src/services/quotes/QuoteService.ts"],"names":[],"mappings":";;;AAAA,+BAAsF;AAGtF,0CAA4C;AAC5C,oDAAkE;AAClE,8CAAuD;AACvD,yDAA+E;AAC/E,uDAAwD;AAExD;;;GAGG;AACH,MAAa,YAAY;IACvB,YACU,YAA0B,EAC1B,OAAe,EACf,YAA0B;QAF1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,KAAK,CAAC,YAAY,CAAC,OAAe,EAAE,QAAgB,EAAE,QAAgB,EAAE,KAAa;QACnF,0BAA0B;QAC1B,IAAA,4BAAe,EAAC,OAAO,EAAE,SAAS,CAAC,CAAA;QACnC,IAAA,4BAAe,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;QAErC,wEAAwE;QACxE,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QAC9D,CAAC;QAED,yDAAyD;QACzD,MAAM,YAAY,GAAG,IAAA,6BAAe,EAAC,KAAK,CAAC,IAAI,EAAE,OAAkB,EAAE,QAAmB,CAAC,CAAA;QACzF,MAAM,aAAa,GAAG,IAAA,8BAAkB,EAAC,IAAI,CAAC,OAAkB,EAAE,QAAQ,CAAC,CAAA;QAE3E,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;gBACpD,OAAO,EAAE,aAA8B;gBACvC,GAAG,EAAE,iBAAU;gBACf,YAAY,EAAE,eAAe;gBAC7B,IAAI,EAAE,CAAC,QAAQ,EAAE,YAAoC,CAAC;aACvD,CAAC,CAAa,CAAA;YAEf,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QACpC,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,KAAK,YAAY,gBAAS,EAAE,CAAC;gBAC/B,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,oCAA6B,CAAC,CAAA;gBACjF,IACE,WAAW,YAAY,oCAA6B;oBACpD,WAAW,CAAC,IAAI,EAAE,SAAS,KAAK,gBAAgB,EAChD,CAAC;oBACD,MAAM,IAAI,4BAAmB,EAAE,CAAA;gBACjC,CAAC;YACH,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF;AA9ED,oCA8EC"}
|
|
@@ -72,9 +72,9 @@ export declare class RouteService {
|
|
|
72
72
|
*
|
|
73
73
|
* @example
|
|
74
74
|
* ```typescript
|
|
75
|
-
* const
|
|
76
|
-
* const
|
|
77
|
-
* const route = await routeService.findRoute(
|
|
75
|
+
* const USDm = '0x765DE816845861e75A25fCA122bb6898B8B1282a'
|
|
76
|
+
* const BRLm = '0xE4D5...'
|
|
77
|
+
* const route = await routeService.findRoute(USDm, BRLm)
|
|
78
78
|
*
|
|
79
79
|
* if (route.path.length === 1) {
|
|
80
80
|
* console.log('Direct route available')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteService.d.ts","sourceRoot":"","sources":["../../../src/services/routes/RouteService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGtC,OAAO,EAAE,KAAK,EAAiB,aAAa,
|
|
1
|
+
{"version":3,"file":"RouteService.d.ts","sourceRoot":"","sources":["../../../src/services/routes/RouteService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGtC,OAAO,EAAE,KAAK,EAAiB,aAAa,EAAc,MAAM,kBAAkB,CAAA;AAGlF,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAEnC,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;;;;;;;GAOG;AACH,qBAAa,YAAY;IAGX,OAAO,CAAC,YAAY;IAAgB,OAAO,CAAC,OAAO;IAAU,OAAO,CAAC,WAAW;IAF5F,OAAO,CAAC,WAAW,CAAiC;gBAEhC,YAAY,EAAE,YAAY,EAAU,OAAO,EAAE,MAAM,EAAU,WAAW,EAAE,WAAW;IAEzG;;;;;;;;;;;;OAYG;IACG,eAAe,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAsDzC;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,SAAS,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,GAAG,aAAa,CAAC,EAAE,CAAC;IAoBpF;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,KAAK,CAAC;IAuBlG;;;;OAIG;YACW,mBAAmB;IAoBjC;;;OAGG;YACW,gBAAgB;IAM9B;;;;;;OAMG;YACW,gBAAgB;CAuB/B"}
|
|
@@ -76,7 +76,6 @@ class RouteService {
|
|
|
76
76
|
const symbol0 = this.symbolCache.get(pool.token0);
|
|
77
77
|
const symbol1 = this.symbolCache.get(pool.token1);
|
|
78
78
|
if (!symbol0 || !symbol1) {
|
|
79
|
-
// TODO: Consider error handling across the codebase for better consumer experience.
|
|
80
79
|
throw new Error(`Symbol not found for token ${pool.token0} or ${pool.token1}`);
|
|
81
80
|
}
|
|
82
81
|
// Create canonical route ID (alphabetically sorted symbols)
|
|
@@ -149,9 +148,9 @@ class RouteService {
|
|
|
149
148
|
*
|
|
150
149
|
* @example
|
|
151
150
|
* ```typescript
|
|
152
|
-
* const
|
|
153
|
-
* const
|
|
154
|
-
* const route = await routeService.findRoute(
|
|
151
|
+
* const USDm = '0x765DE816845861e75A25fCA122bb6898B8B1282a'
|
|
152
|
+
* const BRLm = '0xE4D5...'
|
|
153
|
+
* const route = await routeService.findRoute(USDm, BRLm)
|
|
155
154
|
*
|
|
156
155
|
* if (route.path.length === 1) {
|
|
157
156
|
* console.log('Direct route available')
|
|
@@ -219,7 +218,6 @@ class RouteService {
|
|
|
219
218
|
}
|
|
220
219
|
try {
|
|
221
220
|
const symbol = (await this.publicClient.readContract({
|
|
222
|
-
// TODO: Consider using Address type from viem. Keep this consistent across the codebase
|
|
223
221
|
address: address,
|
|
224
222
|
abi: abis_1.ERC20_ABI,
|
|
225
223
|
functionName: 'symbol',
|
|
@@ -231,7 +229,6 @@ class RouteService {
|
|
|
231
229
|
}
|
|
232
230
|
catch {
|
|
233
231
|
// Fallback to address if symbol fetch fails
|
|
234
|
-
console.warn(`Failed to fetch symbol for token ${address}, using address as fallback`);
|
|
235
232
|
this.symbolCache.set(address, address);
|
|
236
233
|
return address;
|
|
237
234
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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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;AA/ND,oCA+NC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PublicClient } from 'viem';
|
|
2
2
|
import { RouteService } from '../routes';
|
|
3
3
|
import { QuoteService } from '../quotes';
|
|
4
4
|
import { Route, CallParams } from '../../core/types';
|
|
@@ -12,10 +12,10 @@ export interface SwapOptions {
|
|
|
12
12
|
*/
|
|
13
13
|
slippageTolerance: number;
|
|
14
14
|
/**
|
|
15
|
-
* Unix timestamp after which the transaction will revert
|
|
16
|
-
*
|
|
15
|
+
* Unix timestamp after which the transaction will revert.
|
|
16
|
+
* Use `deadlineFromMinutes()` for convenience.
|
|
17
17
|
*/
|
|
18
|
-
deadline
|
|
18
|
+
deadline: bigint;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Detailed swap parameters including decoded values for transparency
|
|
@@ -77,8 +77,8 @@ export declare class SwapService {
|
|
|
77
77
|
* Builds a complete swap transaction including approval if needed.
|
|
78
78
|
* This is the recommended method for most use cases.
|
|
79
79
|
*
|
|
80
|
-
* @param tokenIn - The address of the input token
|
|
81
|
-
* @param tokenOut - The address of the output token
|
|
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
82
|
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
83
83
|
* @param recipient - The address to receive the output tokens
|
|
84
84
|
* @param owner - The address that owns the input tokens (needed to check allowance)
|
|
@@ -89,12 +89,12 @@ export declare class SwapService {
|
|
|
89
89
|
* @example
|
|
90
90
|
* ```typescript
|
|
91
91
|
* const { approval, swap } = await mento.swap.buildSwapTransaction(
|
|
92
|
-
*
|
|
93
|
-
* CELO
|
|
92
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
93
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
94
94
|
* parseUnits('100', 18),
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* { slippageTolerance: 0.5 }
|
|
95
|
+
* '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // recipient
|
|
96
|
+
* '0x123...', // owner
|
|
97
|
+
* { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) }
|
|
98
98
|
* )
|
|
99
99
|
*
|
|
100
100
|
* // Execute approval if needed
|
|
@@ -106,13 +106,13 @@ export declare class SwapService {
|
|
|
106
106
|
* await walletClient.sendTransaction(swap.params)
|
|
107
107
|
* ```
|
|
108
108
|
*/
|
|
109
|
-
buildSwapTransaction(tokenIn:
|
|
109
|
+
buildSwapTransaction(tokenIn: string, tokenOut: string, amountIn: bigint, recipient: string, owner: string, options: SwapOptions, route?: Route): Promise<SwapTransaction>;
|
|
110
110
|
/**
|
|
111
111
|
* Builds swap transaction parameters without executing the transaction.
|
|
112
112
|
* Does NOT check or handle token approval - use buildSwapTransaction for that.
|
|
113
113
|
*
|
|
114
|
-
* @param tokenIn - The address of the input token
|
|
115
|
-
* @param tokenOut - The address of the output token
|
|
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
116
|
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
117
117
|
* @param recipient - The address to receive the output tokens
|
|
118
118
|
* @param options - Swap configuration options (slippage, deadline)
|
|
@@ -122,18 +122,18 @@ export declare class SwapService {
|
|
|
122
122
|
* @example
|
|
123
123
|
* ```typescript
|
|
124
124
|
* const swapDetails = await mento.swap.buildSwapParams(
|
|
125
|
-
*
|
|
126
|
-
* CELO
|
|
125
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
126
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
127
127
|
* parseUnits('100', 18),
|
|
128
|
-
*
|
|
129
|
-
* { slippageTolerance: 0.5 }
|
|
128
|
+
* '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // recipient
|
|
129
|
+
* { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) }
|
|
130
130
|
* )
|
|
131
131
|
*
|
|
132
132
|
* // Execute with any wallet (assumes approval already granted)
|
|
133
133
|
* await walletClient.sendTransaction(swapDetails.params)
|
|
134
134
|
* ```
|
|
135
135
|
*/
|
|
136
|
-
buildSwapParams(tokenIn:
|
|
136
|
+
buildSwapParams(tokenIn: string, tokenOut: string, amountIn: bigint, recipient: string, options: SwapOptions, route?: Route): Promise<SwapDetails>;
|
|
137
137
|
/**
|
|
138
138
|
* Builds approval transaction params for the Router to spend tokenIn
|
|
139
139
|
* @private
|
|
@@ -146,6 +146,10 @@ export declare class SwapService {
|
|
|
146
146
|
private getAllowance;
|
|
147
147
|
/**
|
|
148
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
|
|
149
153
|
* @private
|
|
150
154
|
*/
|
|
151
155
|
private calculateMinAmountOut;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapService.d.ts","sourceRoot":"","sources":["../../../src/services/swap/SwapService.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,EAAwB,MAAM,yBAAyB,CAAA;AAI5F;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAA;IACzB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAA;CACjB;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;IAsCvB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAU3B;;;OAGG;YACW,YAAY;IAY1B;;;;;;;OAOG;IACH,OAAO,CAAC,qBAAqB;IAkB7B;;;OAGG;IACH,OAAO,CAAC,cAAc;CAavB"}
|
|
@@ -5,6 +5,8 @@ const viem_1 = require("viem");
|
|
|
5
5
|
const abis_1 = require("../../core/abis");
|
|
6
6
|
const constants_1 = require("../../core/constants");
|
|
7
7
|
const pathEncoder_1 = require("../../utils/pathEncoder");
|
|
8
|
+
const validation_1 = require("../../utils/validation");
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
8
10
|
/**
|
|
9
11
|
* Service for building token swap transactions on the Mento protocol.
|
|
10
12
|
* Returns transaction parameters that can be executed by any wallet.
|
|
@@ -20,8 +22,8 @@ class SwapService {
|
|
|
20
22
|
* Builds a complete swap transaction including approval if needed.
|
|
21
23
|
* This is the recommended method for most use cases.
|
|
22
24
|
*
|
|
23
|
-
* @param tokenIn - The address of the input token
|
|
24
|
-
* @param tokenOut - The address of the output token
|
|
25
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
26
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
25
27
|
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
26
28
|
* @param recipient - The address to receive the output tokens
|
|
27
29
|
* @param owner - The address that owns the input tokens (needed to check allowance)
|
|
@@ -32,12 +34,12 @@ class SwapService {
|
|
|
32
34
|
* @example
|
|
33
35
|
* ```typescript
|
|
34
36
|
* const { approval, swap } = await mento.swap.buildSwapTransaction(
|
|
35
|
-
*
|
|
36
|
-
* CELO
|
|
37
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
38
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
37
39
|
* parseUnits('100', 18),
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* { slippageTolerance: 0.5 }
|
|
40
|
+
* '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // recipient
|
|
41
|
+
* '0x123...', // owner
|
|
42
|
+
* { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) }
|
|
41
43
|
* )
|
|
42
44
|
*
|
|
43
45
|
* // Execute approval if needed
|
|
@@ -50,6 +52,11 @@ class SwapService {
|
|
|
50
52
|
* ```
|
|
51
53
|
*/
|
|
52
54
|
async buildSwapTransaction(tokenIn, tokenOut, amountIn, recipient, owner, options, route) {
|
|
55
|
+
// Validate all address inputs
|
|
56
|
+
(0, validation_1.validateAddress)(tokenIn, 'tokenIn');
|
|
57
|
+
(0, validation_1.validateAddress)(tokenOut, 'tokenOut');
|
|
58
|
+
(0, validation_1.validateAddress)(recipient, 'recipient');
|
|
59
|
+
(0, validation_1.validateAddress)(owner, 'owner');
|
|
53
60
|
// Build swap params first
|
|
54
61
|
const swap = await this.buildSwapParams(tokenIn, tokenOut, amountIn, recipient, options, route);
|
|
55
62
|
// Check if approval is needed
|
|
@@ -61,8 +68,8 @@ class SwapService {
|
|
|
61
68
|
* Builds swap transaction parameters without executing the transaction.
|
|
62
69
|
* Does NOT check or handle token approval - use buildSwapTransaction for that.
|
|
63
70
|
*
|
|
64
|
-
* @param tokenIn - The address of the input token
|
|
65
|
-
* @param tokenOut - The address of the output token
|
|
71
|
+
* @param tokenIn - The address of the input token (e.g., '0x765DE816845861e75A25fCA122bb6898B8B1282a')
|
|
72
|
+
* @param tokenOut - The address of the output token (e.g., '0x471EcE3750Da237f93B8E339c536989b8978a438')
|
|
66
73
|
* @param amountIn - The amount of input tokens (in wei/smallest unit)
|
|
67
74
|
* @param recipient - The address to receive the output tokens
|
|
68
75
|
* @param options - Swap configuration options (slippage, deadline)
|
|
@@ -72,11 +79,11 @@ class SwapService {
|
|
|
72
79
|
* @example
|
|
73
80
|
* ```typescript
|
|
74
81
|
* const swapDetails = await mento.swap.buildSwapParams(
|
|
75
|
-
*
|
|
76
|
-
* CELO
|
|
82
|
+
* '0x765DE816845861e75A25fCA122bb6898B8B1282a', // USDm
|
|
83
|
+
* '0x471EcE3750Da237f93B8E339c536989b8978a438', // CELO
|
|
77
84
|
* parseUnits('100', 18),
|
|
78
|
-
*
|
|
79
|
-
* { slippageTolerance: 0.5 }
|
|
85
|
+
* '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', // recipient
|
|
86
|
+
* { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) }
|
|
80
87
|
* )
|
|
81
88
|
*
|
|
82
89
|
* // Execute with any wallet (assumes approval already granted)
|
|
@@ -84,14 +91,20 @@ class SwapService {
|
|
|
84
91
|
* ```
|
|
85
92
|
*/
|
|
86
93
|
async buildSwapParams(tokenIn, tokenOut, amountIn, recipient, options, route) {
|
|
94
|
+
// Validate all address inputs
|
|
95
|
+
(0, validation_1.validateAddress)(tokenIn, 'tokenIn');
|
|
96
|
+
(0, validation_1.validateAddress)(tokenOut, 'tokenOut');
|
|
97
|
+
(0, validation_1.validateAddress)(recipient, 'recipient');
|
|
87
98
|
// Find route if not provided
|
|
88
99
|
if (!route) {
|
|
89
100
|
route = await this.routeService.findRoute(tokenIn, tokenOut);
|
|
90
101
|
}
|
|
91
102
|
const expectedAmountOut = await this.quoteService.getAmountOut(tokenIn, tokenOut, amountIn, route);
|
|
92
103
|
const amountOutMin = this.calculateMinAmountOut(expectedAmountOut, options.slippageTolerance);
|
|
93
|
-
|
|
94
|
-
|
|
104
|
+
const deadline = options.deadline;
|
|
105
|
+
if (deadline <= BigInt(Math.floor(Date.now() / 1000))) {
|
|
106
|
+
throw new Error('Deadline must be in the future');
|
|
107
|
+
}
|
|
95
108
|
const routerRoutes = (0, pathEncoder_1.encodeRoutePath)(route.path, tokenIn, tokenOut);
|
|
96
109
|
const routerAddress = (0, constants_1.getContractAddress)(this.chainId, 'Router');
|
|
97
110
|
const data = this.encodeSwapCall(amountIn, amountOutMin, routerRoutes, recipient, deadline);
|
|
@@ -128,18 +141,30 @@ class SwapService {
|
|
|
128
141
|
*/
|
|
129
142
|
async getAllowance(tokenIn, owner) {
|
|
130
143
|
const routerAddress = (0, constants_1.getContractAddress)(this.chainId, 'Router');
|
|
131
|
-
return this.publicClient.readContract({
|
|
144
|
+
return (0, utils_1.retryOperation)(() => this.publicClient.readContract({
|
|
132
145
|
address: tokenIn,
|
|
133
146
|
abi: abis_1.ERC20_ABI,
|
|
134
147
|
functionName: 'allowance',
|
|
135
148
|
args: [owner, routerAddress],
|
|
136
|
-
});
|
|
149
|
+
}));
|
|
137
150
|
}
|
|
138
151
|
/**
|
|
139
152
|
* Calculates minimum output amount after applying slippage tolerance
|
|
153
|
+
* @param amountOut - Expected output amount
|
|
154
|
+
* @param slippageTolerance - Slippage tolerance as percentage (e.g., 0.5 for 0.5%)
|
|
155
|
+
* @returns Minimum acceptable output amount
|
|
156
|
+
* @throws Error if slippage tolerance is invalid
|
|
140
157
|
* @private
|
|
141
158
|
*/
|
|
142
159
|
calculateMinAmountOut(amountOut, slippageTolerance) {
|
|
160
|
+
const MAX_SLIPPAGE_TOLERANCE = 20; // 20% max
|
|
161
|
+
if (slippageTolerance < 0) {
|
|
162
|
+
throw new Error('Slippage tolerance cannot be negative');
|
|
163
|
+
}
|
|
164
|
+
if (slippageTolerance > MAX_SLIPPAGE_TOLERANCE) {
|
|
165
|
+
throw new Error(`Slippage tolerance ${slippageTolerance}% exceeds maximum of ${MAX_SLIPPAGE_TOLERANCE}%. ` +
|
|
166
|
+
'High slippage makes transactions vulnerable to sandwich attacks.');
|
|
167
|
+
}
|
|
143
168
|
const basisPoints = BigInt(Math.floor(slippageTolerance * 100));
|
|
144
169
|
const slippageMultiplier = 10000n - basisPoints;
|
|
145
170
|
return (amountOut * slippageMultiplier) / 10000n;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapService.js","sourceRoot":"","sources":["../../../src/services/swap/SwapService.ts"],"names":[],"mappings":";;;AAAA,+BAAgE;AAIhE,0CAAuD;AACvD,oDAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"SwapService.js","sourceRoot":"","sources":["../../../src/services/swap/SwapService.ts"],"names":[],"mappings":";;;AAAA,+BAAgE;AAIhE,0CAAuD;AACvD,oDAAkE;AAClE,yDAA4F;AAC5F,uDAAwD;AACxD,uCAA4C;AAiE5C;;;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,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B,OAAO,IAAA,yBAAkB,EAAC;YACxB,GAAG,EAAE,iBAAU;YACf,YAAY,EAAE,0BAA0B;YACxC,IAAI,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,MAA8B,EAAE,SAAS,EAAE,QAAQ,CAAC;SACpF,CAAC,CAAA;IACJ,CAAC;CACF;AAlND,kCAkNC"}
|
|
@@ -3,7 +3,6 @@ import type { PublicClient } from 'viem';
|
|
|
3
3
|
export declare class TokenService {
|
|
4
4
|
private publicClient;
|
|
5
5
|
private chainId;
|
|
6
|
-
private supplyAdjustmentService;
|
|
7
6
|
constructor(publicClient: PublicClient, chainId: number);
|
|
8
7
|
/**
|
|
9
8
|
* Get token metadata (name, symbol, decimals)
|
|
@@ -18,8 +17,9 @@ export declare class TokenService {
|
|
|
18
17
|
*/
|
|
19
18
|
private getTotalSupply;
|
|
20
19
|
/**
|
|
21
|
-
* Get all stable tokens from the Reserve contract
|
|
22
|
-
*
|
|
20
|
+
* Get all stable tokens from the Reserve contract.
|
|
21
|
+
* Returns the actual on-chain ERC20 totalSupply values without adjustments.
|
|
22
|
+
* @param includeSupply - Whether to fetch total supply
|
|
23
23
|
* @returns Array of stable tokens
|
|
24
24
|
*/
|
|
25
25
|
getStableTokens(includeSupply?: boolean): Promise<StableToken[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenService.d.ts","sourceRoot":"","sources":["../../../src/services/tokens/tokenService.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"tokenService.d.ts","sourceRoot":"","sources":["../../../src/services/tokens/tokenService.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAatE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC,qBAAa,YAAY;IACX,OAAO,CAAC,YAAY;IAAgB,OAAO,CAAC,OAAO;gBAA3C,YAAY,EAAE,YAAY,EAAU,OAAO,EAAE,MAAM;IAEvE;;;;OAIG;YACW,gBAAgB;IAqC9B;;;;OAIG;YACW,cAAc;IAa5B;;;;;OAKG;IACU,eAAe,CAAC,aAAa,UAAO,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IA6B1E;;;;OAIG;IACU,mBAAmB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CA2C/D"}
|