@mento-protocol/mento-sdk 3.2.3 → 3.2.4
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 +196 -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 +113 -0
- package/dist/services/trading/TradingService.js +201 -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
package/dist/cjs/routeUtils.d.ts
DELETED
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { TradablePairWithSpread } from './constants';
|
|
2
|
-
import { Address } from './interfaces';
|
|
3
|
-
import { TradablePair, TradablePairID } from './mento';
|
|
4
|
-
type TokenSymbol = string;
|
|
5
|
-
interface ExchangeDetails {
|
|
6
|
-
providerAddr: Address;
|
|
7
|
-
id: string;
|
|
8
|
-
assets: [Address, Address];
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* =============================================================================
|
|
12
|
-
* ROUTE GENERATION UTILITIES
|
|
13
|
-
* =============================================================================
|
|
14
|
-
*
|
|
15
|
-
* Utilities for generating optimal trading routes in the Mento protocol.
|
|
16
|
-
*
|
|
17
|
-
* The main workflow is:
|
|
18
|
-
*
|
|
19
|
-
* 1. Build connectivity structures from direct trading pairs
|
|
20
|
-
* 2. Generate all possible routes (direct + two-hop)
|
|
21
|
-
* 3. Select optimal routes using spread data or heuristics
|
|
22
|
-
*
|
|
23
|
-
* ALGORITHM OVERVIEW:
|
|
24
|
-
* - Creates a graph where tokens are nodes and direct exchanges are edges
|
|
25
|
-
* - Uses graph traversal to find two-hop routes through intermediate tokens
|
|
26
|
-
* - Optimizes route selection based on spread costs when available
|
|
27
|
-
* - Falls back to heuristics (prefer direct routes, major stablecoins)
|
|
28
|
-
* =============================================================================
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
* Connectivity data structure that represents the token graph connecting all tokens.
|
|
32
|
-
* Helps to efficiently answer: "How can I trade from token A to token B?"
|
|
33
|
-
*
|
|
34
|
-
* CONCRETE EXAMPLE:
|
|
35
|
-
* Given these direct trading pairs:
|
|
36
|
-
* - cUSD ↔ CELO (direct exchange exists)
|
|
37
|
-
* - CELO ↔ cEUR (direct exchange exists)
|
|
38
|
-
* - cUSD ↔ cREAL (direct exchange exists)
|
|
39
|
-
*
|
|
40
|
-
* How route finding works:
|
|
41
|
-
* - Direct route: cUSD → cEUR? Check token graph: cUSD connects to [CELO, cREAL], none is cEUR → No direct route
|
|
42
|
-
* - Two-hop route: cUSD → ? → cEUR?
|
|
43
|
-
* - cUSD connects to CELO, CELO connects to cEUR → Found route: cUSD → CELO → cEUR
|
|
44
|
-
* - cUSD connects to cREAL, cREAL connects to [cUSD] → No route via cREAL
|
|
45
|
-
*
|
|
46
|
-
* The "connectivity" part means we can quickly traverse the network of
|
|
47
|
-
* token connections to find all possible trading paths.
|
|
48
|
-
*/
|
|
49
|
-
export interface ConnectivityData {
|
|
50
|
-
/** Maps token address to symbol for efficient lookups
|
|
51
|
-
*
|
|
52
|
-
* ```
|
|
53
|
-
* '0x765D...' → 'cUSD'
|
|
54
|
-
* '0x471E...' → 'CELO'
|
|
55
|
-
* '0xD876...' → 'cEUR'
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
addrToSymbol: Map<Address, TokenSymbol>;
|
|
59
|
-
/** Adjacency list mapping which tokens connect to which
|
|
60
|
-
* Used for finding two-hop routes by traversing token → neighbor → neighbor.
|
|
61
|
-
*
|
|
62
|
-
* Example for a cUSD => cEUR swap: First we find cUSD → [CELO, cKES, ...]
|
|
63
|
-
* Then we find CELO → [cUSD, cEUR, ...] = found route via cUSD → CELO → cEUR
|
|
64
|
-
*
|
|
65
|
-
* ```
|
|
66
|
-
* 'cUSD_addr' → Set(['CELO_addr', 'cKES_addr']) // cUSD connects to CELO and cKES
|
|
67
|
-
* 'CELO_addr' → Set(['cUSD_addr', 'cEUR_addr']) // CELO connects to cUSD and cEUR
|
|
68
|
-
* 'cEUR_addr' → Set(['CELO_addr']) // cEUR connects to CELO
|
|
69
|
-
* 'cKES_addr' → Set(['cUSD_addr']) // cKES connects to cUSD
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
tokenGraph: Map<Address, Set<Address>>;
|
|
73
|
-
/** Maps sorted token address pairs to their direct exchange hop details
|
|
74
|
-
* ```
|
|
75
|
-
* 'CELO_addr-cEUR_addr' → { exchange details for CELO ↔ cEUR }
|
|
76
|
-
* 'CELO_addr-cUSD_addr' → { exchange details for CELO ↔ cUSD }
|
|
77
|
-
* 'cUSD_addr-cKES_addr' → { exchange details for cUSD ↔ cKES }
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
directPathMap: Map<TradablePairID, ExchangeDetails>;
|
|
81
|
-
/** Original direct trading pairs from mento.getDirectPairs() for reference */
|
|
82
|
-
directPairs: TradablePair[];
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Builds the connectivity data structures needed for route generation.
|
|
86
|
-
*
|
|
87
|
-
* Transforms a list of direct trading pairs into our ConnectivityData
|
|
88
|
-
* that allow us to quickly find trading routes.
|
|
89
|
-
*
|
|
90
|
-
* **Construction Process:**
|
|
91
|
-
*
|
|
92
|
-
* ```
|
|
93
|
-
* Input: TradablePairs = [
|
|
94
|
-
* { id: 'cUSD-CELO', assets: [cUSD, CELO], path: [exchange1_CELO_cUSD] },
|
|
95
|
-
* { id: 'CELO-cEUR', assets: [CELO, cEUR], path: [exchange2_CELO_cEUR] }
|
|
96
|
-
* ]
|
|
97
|
-
*
|
|
98
|
-
* Step 1 - Build addrToSymbol map:
|
|
99
|
-
* cUSD.address → 'cUSD'
|
|
100
|
-
* CELO.address → 'CELO'
|
|
101
|
-
* cEUR.address → 'cEUR'
|
|
102
|
-
*
|
|
103
|
-
* Step 2 - Build directPathMap (sorted alphabetically for consistency):
|
|
104
|
-
* 'CELO_addr-cEUR_addr' → exchange2_CELO_cEUR
|
|
105
|
-
* 'CELO_addr-cUSD_addr' → exchange1_CELO_cUSD
|
|
106
|
-
*
|
|
107
|
-
* Step 3 - Build bidirectional tokenGraph:
|
|
108
|
-
* cUSD.address → Set([CELO.address])
|
|
109
|
-
* CELO.address → Set([cUSD.address, cEUR.address])
|
|
110
|
-
* cEUR.address → Set([CELO.address])
|
|
111
|
-
* ```
|
|
112
|
-
*
|
|
113
|
-
* **Result**: We can now efficiently answer:
|
|
114
|
-
* - "What's the symbol for address X?" → addrToSymbol.get(addr)
|
|
115
|
-
* - "What exchange connects tokens X and Y?" → directPathMap.get(sortedAddressPairKey)
|
|
116
|
-
* - "What tokens can I reach from token X?" → tokenGraph.get(X)
|
|
117
|
-
*
|
|
118
|
-
* @param directPairs - Array of direct trading pairs
|
|
119
|
-
* @returns Connectivity data structure for efficient route generation
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```typescript
|
|
123
|
-
* const directPairs = [
|
|
124
|
-
* { id: 'cUSD-CELO', assets: [cUSD, CELO], path: [exchange1] },
|
|
125
|
-
* { id: 'CELO-cEUR', assets: [CELO, cEUR], path: [exchange2] }
|
|
126
|
-
* ]
|
|
127
|
-
*
|
|
128
|
-
* const connectivityData = buildConnectivityStructures(directPairs)
|
|
129
|
-
*
|
|
130
|
-
* // Now we can efficiently find routes:
|
|
131
|
-
* // 1. Check if cUSD connects to anything: connectivityData.tokenGraph.get(cUSD.address) → [CELO.address]
|
|
132
|
-
* // 2. Check if CELO connects to cEUR: connectivityData.tokenGraph.get(CELO.address) → [cUSD.address, cEUR.address] ✓
|
|
133
|
-
* // 3. Get exchange details: connectivityData.directPathMap.get('CELO_addr-cEUR_addr') → exchange2_CELO_cEUR
|
|
134
|
-
* // Result: Found route cUSD → CELO → cEUR with exchange details
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
export declare function buildConnectivityStructures(directPairs: TradablePair[]): ConnectivityData;
|
|
138
|
-
/**
|
|
139
|
-
* Generates all possible routes (direct + two-hop) using connectivity data.
|
|
140
|
-
*
|
|
141
|
-
* This function implements a route discovery algorithm that:
|
|
142
|
-
*
|
|
143
|
-
* 1. **Adds all direct pairs** (single-hop routes)
|
|
144
|
-
* 2. **Discovers two-hop routes** using graph traversal:
|
|
145
|
-
* - For each token A, find its neighbors (tokens directly connected)
|
|
146
|
-
* - For each neighbor B, find B's neighbors
|
|
147
|
-
* - If B connects to token C (C ≠ A), then A->B->C is a valid route
|
|
148
|
-
*
|
|
149
|
-
* **Route Deduplication**: Multiple routes between the same token pair
|
|
150
|
-
* are collected in arrays, allowing the selection algorithm to choose
|
|
151
|
-
* the best one based on spread data or heuristics.
|
|
152
|
-
*
|
|
153
|
-
* **Canonical Pair IDs**: All pairs use alphabetically sorted symbols
|
|
154
|
-
* (e.g., 'cEUR-cUSD' not 'cUSD-cEUR') for consistent identification.
|
|
155
|
-
*
|
|
156
|
-
* @param connectivityData - The connectivity data from buildConnectivityStructures()
|
|
157
|
-
* @returns Map of pair ID -> array of possible routes for that pair
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* // Given direct pairs: cUSD-CELO, CELO-cEUR, cUSD-USDC
|
|
162
|
-
* const allRoutes = generateAllRoutes(connectivityData)
|
|
163
|
-
*
|
|
164
|
-
* // Results might include:
|
|
165
|
-
* // 'cUSD-CELO' -> [{ path: [cUSD->CELO] }] // direct route
|
|
166
|
-
* // 'cEUR-cUSD' -> [
|
|
167
|
-
* // { path: [cUSD->USDC, USDC->cEUR] } // two-hop via USDC
|
|
168
|
-
* // { path: [cUSD->CELO, CELO->cEUR] } // two-hop via CELO
|
|
169
|
-
* // ]
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
export declare function generateAllRoutes(connectivityData: ConnectivityData): Map<TradablePairID, TradablePair[]>;
|
|
173
|
-
/**
|
|
174
|
-
* Creates a two-hop tradable pair if valid exchange hops exist.
|
|
175
|
-
*
|
|
176
|
-
* 1. **Validates tokens exist** in the asset map
|
|
177
|
-
* 2. **Finds exchange hops** for both segments of the route
|
|
178
|
-
* 3. **Creates canonical pair structure** with sorted symbols
|
|
179
|
-
*
|
|
180
|
-
* **Route Structure**: The resulting pair represents trading from start->end
|
|
181
|
-
* via intermediate token, but the assets are ordered alphabetically by symbol
|
|
182
|
-
* for consistency (canonical form).
|
|
183
|
-
*
|
|
184
|
-
* **Path Representation**: The path array contains the actual exchange hops
|
|
185
|
-
* needed to execute the trade, preserving the routing information.
|
|
186
|
-
*
|
|
187
|
-
* @param startToken - Starting token address
|
|
188
|
-
* @param intermediate - Intermediate token address for routing
|
|
189
|
-
* @param end - Destination token address
|
|
190
|
-
* @param assetMap - Map of token address -> Asset details
|
|
191
|
-
* @param directPathMap - Map of token pairs -> exchange hop details
|
|
192
|
-
* @returns Route if valid route exists, null otherwise
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* ```typescript
|
|
196
|
-
* // Create route: cUSD -> CELO -> cEUR
|
|
197
|
-
* const pair = createTwoHopPair(
|
|
198
|
-
* '0x765D...', // cUSD address
|
|
199
|
-
* '0x471E...', // CELO address
|
|
200
|
-
* '0xD876...', // cEUR address
|
|
201
|
-
* addrToSymbol,
|
|
202
|
-
* directPathMap
|
|
203
|
-
* )
|
|
204
|
-
*
|
|
205
|
-
* // Result:
|
|
206
|
-
* // {
|
|
207
|
-
* // id: 'cEUR-cUSD', // alphabetical order
|
|
208
|
-
* // assets: [cEUR, cUSD], // alphabetical order
|
|
209
|
-
* // path: [ // actual routing path
|
|
210
|
-
* // { cUSD->CELO exchange },
|
|
211
|
-
* // { CELO->cEUR exchange }
|
|
212
|
-
* // ]
|
|
213
|
-
* // }
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
export declare function createTwoHopPair(startToken: Address, intermediateToken: Address, endToken: Address, addrToSymbol: Map<Address, TokenSymbol>, directPathMap: Map<string, {
|
|
217
|
-
providerAddr: Address;
|
|
218
|
-
id: string;
|
|
219
|
-
assets: [Address, Address];
|
|
220
|
-
}>): TradablePair | null;
|
|
221
|
-
/**
|
|
222
|
-
* Selects optimal routes from all candidates based on spread data or heuristics.
|
|
223
|
-
*
|
|
224
|
-
* This is the route optimization engine that implements the following logic:
|
|
225
|
-
*
|
|
226
|
-
* **For Single Route**: Use it directly (no optimization needed)
|
|
227
|
-
*
|
|
228
|
-
* **For Multiple Routes**:
|
|
229
|
-
* - If `returnAllRoutes=true`: Return all routes (used for cache generation)
|
|
230
|
-
* - If `returnAllRoutes=false`: Apply optimization to select the best route
|
|
231
|
-
*
|
|
232
|
-
* **Route Selection Strategy**: Delegates to `selectBestRoute()` which uses
|
|
233
|
-
* a multi-tier approach prioritizing cost efficiency and reliability.
|
|
234
|
-
*
|
|
235
|
-
* @param allRoutes - Map of pair ID -> array of possible routes
|
|
236
|
-
* @param returnAllRoutes - Whether to return all routes or optimize selection
|
|
237
|
-
* @param assetMap - Asset map for token symbol lookups during optimization
|
|
238
|
-
* @returns Array of selected optimal routes
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* ```typescript
|
|
242
|
-
* // Multiple routes for cUSD-cEUR pair
|
|
243
|
-
* const candidates = new Map([
|
|
244
|
-
* ['cEUR-cUSD', [
|
|
245
|
-
* { path: [cUSD->CELO->cEUR], spreadData: { totalSpreadPercent: 0.5 } },
|
|
246
|
-
* { path: [cUSD->cREAL->cEUR], spreadData: { totalSpreadPercent: 0.3 } },
|
|
247
|
-
* { path: [cUSD->cEUR] } // direct route, no spread data
|
|
248
|
-
* ]]
|
|
249
|
-
* ])
|
|
250
|
-
*
|
|
251
|
-
* const optimal = selectOptimalRoutes(candidates, false, assetMap)
|
|
252
|
-
* // Returns the cUSD->cREAL->cEUR route (lowest spread: 0.3%)
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
export declare function selectOptimalRoutes(allRoutes: Map<TradablePairID, TradablePair[]>, returnAllRoutes: boolean, addrToSymbol: Map<Address, TokenSymbol>): (TradablePair | TradablePairWithSpread)[];
|
|
256
|
-
/**
|
|
257
|
-
* Selects the best route from candidates using spread data or fallback heuristics.
|
|
258
|
-
*
|
|
259
|
-
* This function implements a sophisticated route selection algorithm with
|
|
260
|
-
* multiple optimization tiers:
|
|
261
|
-
*
|
|
262
|
-
* **Tier 1 - Spread-Based Optimization** (Preferred):
|
|
263
|
-
* - Use routes with spread data (actual cost information)
|
|
264
|
-
* - Select route with lowest `totalSpreadPercent`
|
|
265
|
-
* - This provides the most cost-efficient trading
|
|
266
|
-
*
|
|
267
|
-
* **Tier 2 - Direct Route Preference** (Fallback):
|
|
268
|
-
* - If no spread data available, prefer direct (single-hop) routes
|
|
269
|
-
* - Direct routes have lower execution risk and gas costs
|
|
270
|
-
*
|
|
271
|
-
* **Tier 3 - Major Stablecoin Preference** (Final Fallback):
|
|
272
|
-
* - For two-hop routes, prefer those going through major stablecoins
|
|
273
|
-
* - Major FX currencies like cUSD and cEUR typically have better liquidity
|
|
274
|
-
*
|
|
275
|
-
* **Tier 4 - First Available** (Last Resort):
|
|
276
|
-
* - If no other heuristics apply, use the first route found
|
|
277
|
-
*
|
|
278
|
-
* @param candidates - Array of possible routes for the same token pair
|
|
279
|
-
* @param assetMap - Asset map for token symbol lookups
|
|
280
|
-
* @returns The optimal route selected using the tier system
|
|
281
|
-
*
|
|
282
|
-
* @example
|
|
283
|
-
* ```typescript
|
|
284
|
-
* const candidates = [
|
|
285
|
-
* { path: [A->B->C], spreadData: { totalSpreadPercent: 0.8 } },
|
|
286
|
-
* { path: [A->D->C], spreadData: { totalSpreadPercent: 0.4 } }, // Winner: lowest spread
|
|
287
|
-
* { path: [A->C] }, // direct route, no spread data
|
|
288
|
-
* ]
|
|
289
|
-
*
|
|
290
|
-
* const best = selectBestRoute(candidates, assetMap)
|
|
291
|
-
* // Returns the A->D->C route (0.4% spread)
|
|
292
|
-
* ```
|
|
293
|
-
*/
|
|
294
|
-
export declare function selectBestRoute(candidates: TradablePair[], addrToSymbol: Map<Address, TokenSymbol>): TradablePair | TradablePairWithSpread;
|
|
295
|
-
/**
|
|
296
|
-
* Extracts the intermediate token address from a two-hop route.
|
|
297
|
-
* In a two-hop route A->B->C, this function finds token B (the intermediate).
|
|
298
|
-
*/
|
|
299
|
-
export declare function getIntermediateToken(route: TradablePair): Address | undefined;
|
|
300
|
-
/**
|
|
301
|
-
* Type guard to check if a Route has spread data.
|
|
302
|
-
*/
|
|
303
|
-
export declare function hasSpreadData(pair: TradablePair | TradablePairWithSpread): pair is TradablePairWithSpread;
|
|
304
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type ContractAddresses = {
|
|
2
|
-
GovernanceFactory: string;
|
|
3
|
-
Airgrab: string;
|
|
4
|
-
Emission: string;
|
|
5
|
-
MentoGovernor: string;
|
|
6
|
-
MentoToken: string;
|
|
7
|
-
TimelockController: string;
|
|
8
|
-
Locking: string;
|
|
9
|
-
MentoRouter: string;
|
|
10
|
-
Broker: string;
|
|
11
|
-
BiPoolManager: string;
|
|
12
|
-
BreakerBox: string;
|
|
13
|
-
Reserve: string;
|
|
14
|
-
ConstantSumPricingModule: string;
|
|
15
|
-
ConstantProductPricingModule: string;
|
|
16
|
-
MedianDeltaBreaker: string;
|
|
17
|
-
ValueDeltaBreaker: string;
|
|
18
|
-
StableToken: string;
|
|
19
|
-
StableTokenEUR: string;
|
|
20
|
-
StableTokenBRL: string;
|
|
21
|
-
StableTokenXOF: string;
|
|
22
|
-
SortedOracles: string;
|
|
23
|
-
};
|
package/dist/cjs/utils.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { BigNumberish, providers, Signer } from 'ethers';
|
|
2
|
-
import { TokenSymbol } from './constants';
|
|
3
|
-
import { Address } from './interfaces';
|
|
4
|
-
import { Token, TradablePair } from './mento';
|
|
5
|
-
/**
|
|
6
|
-
* Gets the chain ID from a signer or provider
|
|
7
|
-
* @param signerOrProvider an ethers provider or signer
|
|
8
|
-
* @returns the chain ID
|
|
9
|
-
*/
|
|
10
|
-
export declare function getChainId(signerOrProvider: Signer | providers.Provider): Promise<number>;
|
|
11
|
-
/**
|
|
12
|
-
* Ensures that given signer is truly a a connected signer
|
|
13
|
-
* @param signer an ethers signer
|
|
14
|
-
* @throws if signer is invalid or not connected
|
|
15
|
-
*/
|
|
16
|
-
export declare function validateSigner(signer: Signer): void;
|
|
17
|
-
/**
|
|
18
|
-
* Ensures that given signerOrProvider is truly a provider or a connected signer
|
|
19
|
-
* @param signerOrProvider an ethers provider or signer
|
|
20
|
-
* @throws if signerOrProvider is invalid or not connected
|
|
21
|
-
*/
|
|
22
|
-
export declare function validateSignerOrProvider(signerOrProvider: Signer | providers.Provider): void;
|
|
23
|
-
/**
|
|
24
|
-
* Returns the symbol of an erc20 token
|
|
25
|
-
* @param tokenAddr the address of the erc20 token
|
|
26
|
-
* @param signerOrProvider an ethers provider or signer
|
|
27
|
-
* @returns the symbol of the erc20 token
|
|
28
|
-
*/
|
|
29
|
-
export declare function getSymbolFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<TokenSymbol>;
|
|
30
|
-
/**
|
|
31
|
-
* Returns the name of an erc20 token
|
|
32
|
-
* @param tokenAddr the address of the erc20 token
|
|
33
|
-
* @param signerOrProvider an ethers provider or signer
|
|
34
|
-
* @returns the name of the erc20 token
|
|
35
|
-
*/
|
|
36
|
-
export declare function getNameFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<string>;
|
|
37
|
-
/**
|
|
38
|
-
* Returns the decimals of an erc20 token
|
|
39
|
-
* @param tokenAddr the address of the erc20 token
|
|
40
|
-
* @param signerOrProvider an ethers provider or signer
|
|
41
|
-
* @returns the decimals of the erc20 token
|
|
42
|
-
*/
|
|
43
|
-
export declare function getDecimalsFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<number>;
|
|
44
|
-
/**
|
|
45
|
-
* Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
|
|
46
|
-
* @param tokenAddr the address of the erc20 token
|
|
47
|
-
* @param spender the address of the spender
|
|
48
|
-
* @param amount the amount to increase the allowance by
|
|
49
|
-
* @param signerOrProvider an ethers signer or provider
|
|
50
|
-
* @returns the populated TransactionRequest object
|
|
51
|
-
*/
|
|
52
|
-
export declare function increaseAllowance(tokenAddr: string, spender: string, amount: BigNumberish, signerOrProvider: Signer | providers.Provider): Promise<providers.TransactionRequest>;
|
|
53
|
-
/**
|
|
54
|
-
* Find a token address by its symbol from tradable pairs
|
|
55
|
-
* @param pairs array of tradable pairs to search through
|
|
56
|
-
* @param symbol the token symbol to find (case-insensitive)
|
|
57
|
-
* @returns the token address if found, null otherwise
|
|
58
|
-
*/
|
|
59
|
-
export declare function findTokenAddressBySymbolInTradablePairs(symbol: TokenSymbol, pairs: readonly TradablePair[]): Address | null;
|
|
60
|
-
export declare function capitalize(str: string): string; /**
|
|
61
|
-
* Helper function to get token address by symbol for a specific chain
|
|
62
|
-
* @param symbol - The token symbol
|
|
63
|
-
* @param chainId - The chain ID
|
|
64
|
-
* @returns The token address or undefined if not found
|
|
65
|
-
*/
|
|
66
|
-
export declare function getTokenAddress(symbol: TokenSymbol, chainId: number): string | undefined;
|
|
67
|
-
/**
|
|
68
|
-
* Helper function to find a token by symbol in the cached tokens
|
|
69
|
-
* @param symbol - The token symbol to search for
|
|
70
|
-
* @param chainId - The chain ID
|
|
71
|
-
* @returns The token object or undefined if not found
|
|
72
|
-
*/
|
|
73
|
-
export declare function findTokenBySymbol(symbol: string, chainId: number): Token | undefined;
|
|
74
|
-
/**
|
|
75
|
-
* Computes the rate feed ID from a rate feed identifier string.
|
|
76
|
-
* This follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
77
|
-
* @param rateFeed the rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
78
|
-
* @returns the computed rate feed address
|
|
79
|
-
*/
|
|
80
|
-
export declare function toRateFeedId(rateFeed: string): Address;
|
package/dist/cjs/utils.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.toRateFeedId = exports.findTokenBySymbol = exports.getTokenAddress = exports.capitalize = exports.findTokenAddressBySymbolInTradablePairs = exports.increaseAllowance = exports.getDecimalsFromTokenAddress = exports.getNameFromTokenAddress = exports.getSymbolFromTokenAddress = exports.validateSignerOrProvider = exports.validateSigner = exports.getChainId = void 0;
|
|
13
|
-
const ethers_1 = require("ethers");
|
|
14
|
-
const tokens_1 = require("./constants/tokens");
|
|
15
|
-
/**
|
|
16
|
-
* Gets the chain ID from a signer or provider
|
|
17
|
-
* @param signerOrProvider an ethers provider or signer
|
|
18
|
-
* @returns the chain ID
|
|
19
|
-
*/
|
|
20
|
-
function getChainId(signerOrProvider) {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const provider = ethers_1.Signer.isSigner(signerOrProvider)
|
|
23
|
-
? signerOrProvider.provider
|
|
24
|
-
: signerOrProvider;
|
|
25
|
-
return (yield provider.getNetwork()).chainId;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
exports.getChainId = getChainId;
|
|
29
|
-
/**
|
|
30
|
-
* Ensures that given signer is truly a a connected signer
|
|
31
|
-
* @param signer an ethers signer
|
|
32
|
-
* @throws if signer is invalid or not connected
|
|
33
|
-
*/
|
|
34
|
-
function validateSigner(signer) {
|
|
35
|
-
if (!ethers_1.Signer.isSigner(signer)) {
|
|
36
|
-
throw new Error('A valid signer must be provided');
|
|
37
|
-
}
|
|
38
|
-
if (!ethers_1.providers.Provider.isProvider(signer.provider)) {
|
|
39
|
-
throw new Error('Signer must be connected to a provider');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.validateSigner = validateSigner;
|
|
43
|
-
/**
|
|
44
|
-
* Ensures that given signerOrProvider is truly a provider or a connected signer
|
|
45
|
-
* @param signerOrProvider an ethers provider or signer
|
|
46
|
-
* @throws if signerOrProvider is invalid or not connected
|
|
47
|
-
*/
|
|
48
|
-
function validateSignerOrProvider(signerOrProvider) {
|
|
49
|
-
const isSigner = ethers_1.Signer.isSigner(signerOrProvider);
|
|
50
|
-
const isProvider = ethers_1.providers.Provider.isProvider(signerOrProvider);
|
|
51
|
-
if (!isSigner && !isProvider) {
|
|
52
|
-
throw new Error('A valid signer or provider must be provided');
|
|
53
|
-
}
|
|
54
|
-
if (isSigner && !ethers_1.providers.Provider.isProvider(signerOrProvider.provider)) {
|
|
55
|
-
throw new Error('Signer must be connected to a provider');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.validateSignerOrProvider = validateSignerOrProvider;
|
|
59
|
-
/**
|
|
60
|
-
* Returns the symbol of an erc20 token
|
|
61
|
-
* @param tokenAddr the address of the erc20 token
|
|
62
|
-
* @param signerOrProvider an ethers provider or signer
|
|
63
|
-
* @returns the symbol of the erc20 token
|
|
64
|
-
*/
|
|
65
|
-
function getSymbolFromTokenAddress(tokenAddr, signerOrProvider) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
const erc20Abi = ['function symbol() external view returns (string memory)'];
|
|
68
|
-
const contract = new ethers_1.Contract(tokenAddr, erc20Abi, signerOrProvider);
|
|
69
|
-
return contract.symbol();
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
exports.getSymbolFromTokenAddress = getSymbolFromTokenAddress;
|
|
73
|
-
/**
|
|
74
|
-
* Returns the name of an erc20 token
|
|
75
|
-
* @param tokenAddr the address of the erc20 token
|
|
76
|
-
* @param signerOrProvider an ethers provider or signer
|
|
77
|
-
* @returns the name of the erc20 token
|
|
78
|
-
*/
|
|
79
|
-
function getNameFromTokenAddress(tokenAddr, signerOrProvider) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const erc20Abi = ['function name() external view returns (string memory)'];
|
|
82
|
-
const contract = new ethers_1.Contract(tokenAddr, erc20Abi, signerOrProvider);
|
|
83
|
-
return contract.name();
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
exports.getNameFromTokenAddress = getNameFromTokenAddress;
|
|
87
|
-
/**
|
|
88
|
-
* Returns the decimals of an erc20 token
|
|
89
|
-
* @param tokenAddr the address of the erc20 token
|
|
90
|
-
* @param signerOrProvider an ethers provider or signer
|
|
91
|
-
* @returns the decimals of the erc20 token
|
|
92
|
-
*/
|
|
93
|
-
function getDecimalsFromTokenAddress(tokenAddr, signerOrProvider) {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
const erc20Abi = ['function decimals() external view returns (uint8)'];
|
|
96
|
-
const contract = new ethers_1.Contract(tokenAddr, erc20Abi, signerOrProvider);
|
|
97
|
-
return contract.decimals();
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
exports.getDecimalsFromTokenAddress = getDecimalsFromTokenAddress;
|
|
101
|
-
/**
|
|
102
|
-
* Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
|
|
103
|
-
* @param tokenAddr the address of the erc20 token
|
|
104
|
-
* @param spender the address of the spender
|
|
105
|
-
* @param amount the amount to increase the allowance by
|
|
106
|
-
* @param signerOrProvider an ethers signer or provider
|
|
107
|
-
* @returns the populated TransactionRequest object
|
|
108
|
-
*/
|
|
109
|
-
function increaseAllowance(tokenAddr, spender, amount, signerOrProvider) {
|
|
110
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
const abi = [
|
|
112
|
-
'function increaseAllowance(address spender, uint256 value) external returns (bool)',
|
|
113
|
-
];
|
|
114
|
-
// TODO, not all ERC-20 contracts support increaseAllowance
|
|
115
|
-
// Add a check for that here
|
|
116
|
-
const contract = new ethers_1.Contract(tokenAddr, abi, signerOrProvider);
|
|
117
|
-
return yield contract.populateTransaction.increaseAllowance(spender, amount);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
exports.increaseAllowance = increaseAllowance;
|
|
121
|
-
/**
|
|
122
|
-
* Find a token address by its symbol from tradable pairs
|
|
123
|
-
* @param pairs array of tradable pairs to search through
|
|
124
|
-
* @param symbol the token symbol to find (case-insensitive)
|
|
125
|
-
* @returns the token address if found, null otherwise
|
|
126
|
-
*/
|
|
127
|
-
function findTokenAddressBySymbolInTradablePairs(symbol, pairs) {
|
|
128
|
-
var _a, _b;
|
|
129
|
-
return ((_b = (_a = pairs
|
|
130
|
-
.flatMap((pair) => pair.assets)
|
|
131
|
-
.find((asset) => asset.symbol.toLowerCase() === symbol.toLowerCase())) === null || _a === void 0 ? void 0 : _a.address) !== null && _b !== void 0 ? _b : null);
|
|
132
|
-
}
|
|
133
|
-
exports.findTokenAddressBySymbolInTradablePairs = findTokenAddressBySymbolInTradablePairs;
|
|
134
|
-
function capitalize(str) {
|
|
135
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
136
|
-
} /**
|
|
137
|
-
* Helper function to get token address by symbol for a specific chain
|
|
138
|
-
* @param symbol - The token symbol
|
|
139
|
-
* @param chainId - The chain ID
|
|
140
|
-
* @returns The token address or undefined if not found
|
|
141
|
-
*/
|
|
142
|
-
exports.capitalize = capitalize;
|
|
143
|
-
function getTokenAddress(symbol, chainId) {
|
|
144
|
-
var _a;
|
|
145
|
-
return (_a = tokens_1.TOKEN_ADDRESSES_BY_CHAIN[chainId]) === null || _a === void 0 ? void 0 : _a[symbol];
|
|
146
|
-
}
|
|
147
|
-
exports.getTokenAddress = getTokenAddress;
|
|
148
|
-
/**
|
|
149
|
-
* Helper function to find a token by symbol in the cached tokens
|
|
150
|
-
* @param symbol - The token symbol to search for
|
|
151
|
-
* @param chainId - The chain ID
|
|
152
|
-
* @returns The token object or undefined if not found
|
|
153
|
-
*/
|
|
154
|
-
function findTokenBySymbol(symbol, chainId) {
|
|
155
|
-
const tokens = (0, tokens_1.getCachedTokensSync)(chainId);
|
|
156
|
-
return tokens.find((token) => token.symbol === symbol);
|
|
157
|
-
}
|
|
158
|
-
exports.findTokenBySymbol = findTokenBySymbol;
|
|
159
|
-
/**
|
|
160
|
-
* Computes the rate feed ID from a rate feed identifier string.
|
|
161
|
-
* This follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
162
|
-
* @param rateFeed the rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
163
|
-
* @returns the computed rate feed address
|
|
164
|
-
*/
|
|
165
|
-
function toRateFeedId(rateFeed) {
|
|
166
|
-
// 1. Calculate keccak256 hash
|
|
167
|
-
const hashedBytes = ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.toUtf8Bytes(rateFeed));
|
|
168
|
-
// 2. Convert to BigInt (equivalent to uint256)
|
|
169
|
-
const hashAsBigInt = BigInt(hashedBytes);
|
|
170
|
-
// 3. Mask to 160 bits (equivalent to uint160)
|
|
171
|
-
const maskedToUint160 = hashAsBigInt & ((BigInt(1) << BigInt(160)) - BigInt(1));
|
|
172
|
-
// 4. Convert to address (hex string)
|
|
173
|
-
const addressHex = '0x' + maskedToUint160.toString(16).padStart(40, '0');
|
|
174
|
-
// 5. Return calculated rate feed ID
|
|
175
|
-
return addressHex;
|
|
176
|
-
}
|
|
177
|
-
exports.toRateFeedId = toRateFeedId;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { PopulatedTransaction, ethers, providers } from 'ethers';
|
|
2
|
-
import { IChainClient } from './interfaces';
|
|
3
|
-
export declare class ChainClient implements IChainClient {
|
|
4
|
-
private readonly signerOrProvider;
|
|
5
|
-
constructor(signerOrProvider: ethers.Signer | providers.Provider);
|
|
6
|
-
getSigner(): Promise<ethers.Signer | providers.Provider>;
|
|
7
|
-
getChainId(): Promise<number>;
|
|
8
|
-
populateTransaction(tx: PopulatedTransaction): Promise<providers.TransactionRequest>;
|
|
9
|
-
}
|
package/dist/esm/ChainClient.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Signer, providers } from 'ethers';
|
|
11
|
-
import { validateSignerOrProvider } from './utils';
|
|
12
|
-
export class ChainClient {
|
|
13
|
-
constructor(signerOrProvider) {
|
|
14
|
-
validateSignerOrProvider(signerOrProvider);
|
|
15
|
-
this.signerOrProvider = signerOrProvider;
|
|
16
|
-
}
|
|
17
|
-
getSigner() {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
return this.signerOrProvider;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
getChainId() {
|
|
23
|
-
var _a;
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
let chainId = 0;
|
|
26
|
-
if (Signer.isSigner(this.signerOrProvider)) {
|
|
27
|
-
const network = yield ((_a = this.signerOrProvider.provider) === null || _a === void 0 ? void 0 : _a.getNetwork());
|
|
28
|
-
if (network) {
|
|
29
|
-
chainId = network.chainId;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else if (providers.Provider.isProvider(this.signerOrProvider)) {
|
|
33
|
-
const network = yield this.signerOrProvider.getNetwork();
|
|
34
|
-
if (network) {
|
|
35
|
-
chainId = network.chainId;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (chainId === 0) {
|
|
39
|
-
throw new Error('Could not get chainId from signer or provider');
|
|
40
|
-
}
|
|
41
|
-
return chainId;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
populateTransaction(tx) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
if (Signer.isSigner(this.signerOrProvider)) {
|
|
47
|
-
return this.signerOrProvider.populateTransaction(tx);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
return tx;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { PopulatedTransaction, ethers, providers } from 'ethers';
|
|
2
|
-
import { IChainClient } from './interfaces';
|
|
3
|
-
export declare class TestChainClient implements IChainClient {
|
|
4
|
-
getSigner(): Promise<ethers.Signer | providers.Provider>;
|
|
5
|
-
getChainId(): Promise<number>;
|
|
6
|
-
populateTransaction(tx: PopulatedTransaction): Promise<providers.TransactionRequest>;
|
|
7
|
-
}
|