@mento-protocol/mento-sdk 2.0.0-beta.9 → 3.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +204 -132
- package/dist/cache/routes.d.ts +13 -0
- package/dist/cache/routes.d.ts.map +1 -0
- package/dist/cache/routes.js +130 -0
- package/dist/cache/routes.js.map +1 -0
- package/dist/cache/tokens.d.ts +67 -0
- package/dist/cache/tokens.d.ts.map +1 -0
- package/dist/cache/tokens.js +379 -0
- package/dist/cache/tokens.js.map +1 -0
- package/dist/core/abis/bipoolmanager.d.ts +34 -0
- package/dist/core/abis/bipoolmanager.d.ts.map +1 -0
- package/dist/core/abis/bipoolmanager.js +72 -0
- package/dist/core/abis/bipoolmanager.js.map +1 -0
- package/dist/core/abis/breakerbox.d.ts +13 -0
- package/dist/core/abis/breakerbox.d.ts.map +1 -0
- package/dist/core/abis/breakerbox.js +8 -0
- package/dist/core/abis/breakerbox.js.map +1 -0
- package/dist/core/abis/broker.d.ts +2 -0
- package/dist/core/abis/broker.d.ts.map +1 -0
- package/dist/core/abis/broker.js +9 -0
- package/dist/core/abis/broker.js.map +1 -0
- package/dist/core/abis/erc20.d.ts +9 -0
- package/dist/core/abis/erc20.d.ts.map +1 -0
- package/dist/core/abis/erc20.js +21 -0
- package/dist/core/abis/erc20.js.map +1 -0
- package/dist/core/abis/fpmm.d.ts +160 -0
- package/dist/core/abis/fpmm.d.ts.map +1 -0
- package/dist/core/abis/fpmm.js +21 -0
- package/dist/core/abis/fpmm.js.map +1 -0
- package/dist/core/abis/fpmmFactory.d.ts +21 -0
- package/dist/core/abis/fpmmFactory.d.ts.map +1 -0
- package/dist/core/abis/fpmmFactory.js +9 -0
- package/dist/core/abis/fpmmFactory.js.map +1 -0
- package/dist/core/abis/index.d.ts +12 -0
- package/dist/core/abis/index.d.ts.map +1 -0
- package/dist/{abis → core/abis}/index.js +6 -0
- package/dist/core/abis/index.js.map +1 -0
- package/dist/core/abis/pricingmodule.d.ts +2 -0
- package/dist/core/abis/pricingmodule.d.ts.map +1 -0
- package/dist/core/abis/pricingmodule.js +6 -0
- package/dist/core/abis/pricingmodule.js.map +1 -0
- package/dist/core/abis/reserve.d.ts +2 -0
- package/dist/core/abis/reserve.d.ts.map +1 -0
- package/dist/core/abis/reserve.js +10 -0
- package/dist/core/abis/reserve.js.map +1 -0
- package/dist/core/abis/router.d.ts +2 -0
- package/dist/core/abis/router.d.ts.map +1 -0
- package/dist/core/abis/router.js +10 -0
- package/dist/core/abis/router.js.map +1 -0
- package/dist/core/abis/uniswapV3.d.ts +4 -0
- package/dist/core/abis/uniswapV3.d.ts.map +1 -0
- package/dist/{abis → core/abis}/uniswapV3.js +7 -6
- package/dist/core/abis/uniswapV3.js.map +1 -0
- package/dist/core/abis/virtualPool.d.ts +40 -0
- package/dist/core/abis/virtualPool.d.ts.map +1 -0
- package/dist/core/abis/virtualPool.js +10 -0
- package/dist/core/abis/virtualPool.js.map +1 -0
- package/dist/core/abis/virtualPoolFactory.d.ts +27 -0
- package/dist/core/abis/virtualPoolFactory.d.ts.map +1 -0
- package/dist/core/abis/virtualPoolFactory.js +9 -0
- package/dist/core/abis/virtualPoolFactory.js.map +1 -0
- package/dist/core/constants/aaveConfig.d.ts.map +1 -0
- package/dist/{constants → core/constants}/aaveConfig.js +2 -2
- package/dist/core/constants/aaveConfig.js.map +1 -0
- package/dist/{constants → core/constants}/addresses.d.ts +4 -5
- package/dist/core/constants/addresses.d.ts.map +1 -0
- package/dist/core/constants/addresses.js +78 -0
- package/dist/core/constants/addresses.js.map +1 -0
- package/dist/core/constants/chainId.d.ts +5 -0
- package/dist/core/constants/chainId.d.ts.map +1 -0
- package/dist/{constants → core/constants}/chainId.js +1 -1
- package/dist/core/constants/chainId.js.map +1 -0
- package/dist/core/constants/contractNames.d.ts.map +1 -0
- package/dist/core/constants/contractNames.js.map +1 -0
- package/dist/{constants → core/constants}/index.d.ts +0 -2
- package/dist/core/constants/index.d.ts.map +1 -0
- package/dist/{constants → core/constants}/index.js +0 -2
- package/dist/core/constants/index.js.map +1 -0
- package/dist/{constants → core/constants}/mentoAddresses.d.ts +2 -0
- package/dist/core/constants/mentoAddresses.d.ts.map +1 -0
- package/dist/{constants → core/constants}/mentoAddresses.js +2 -0
- package/dist/core/constants/mentoAddresses.js.map +1 -0
- package/dist/core/constants/protocolAddresses.d.ts.map +1 -0
- package/dist/core/constants/protocolAddresses.js.map +1 -0
- package/dist/core/errors/base.d.ts +8 -0
- package/dist/core/errors/base.d.ts.map +1 -0
- package/dist/core/errors/base.js +17 -0
- package/dist/core/errors/base.js.map +1 -0
- package/dist/core/errors/index.d.ts +3 -0
- package/dist/core/errors/index.d.ts.map +1 -0
- package/dist/{types → core/errors}/index.js +2 -4
- package/dist/core/errors/index.js.map +1 -0
- package/dist/core/errors/router.d.ts +8 -0
- package/dist/core/errors/router.d.ts.map +1 -0
- package/dist/core/errors/router.js +14 -0
- package/dist/core/errors/router.js.map +1 -0
- package/dist/core/types/contractAddresses.d.ts +41 -0
- package/dist/core/types/contractAddresses.d.ts.map +1 -0
- package/dist/core/types/contractAddresses.js.map +1 -0
- package/dist/core/types/index.d.ts +8 -0
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/core/types/index.js +24 -0
- package/dist/core/types/index.js.map +1 -0
- package/dist/core/types/pool.d.ts +145 -0
- package/dist/core/types/pool.d.ts.map +1 -0
- package/dist/core/types/pool.js +14 -0
- package/dist/core/types/pool.js.map +1 -0
- package/dist/core/types/provider.d.ts +45 -0
- package/dist/core/types/provider.d.ts.map +1 -0
- package/dist/{types → core/types}/provider.js.map +1 -1
- package/dist/core/types/route.d.ts +62 -0
- package/dist/core/types/route.d.ts.map +1 -0
- package/dist/{types/exchange.js → core/types/route.js} +1 -1
- package/dist/core/types/route.js.map +1 -0
- package/dist/{types → core/types}/token.d.ts +16 -6
- package/dist/core/types/token.d.ts.map +1 -0
- package/dist/{types → core/types}/token.js.map +1 -1
- package/dist/core/types/tradingLimits.d.ts +91 -0
- package/dist/core/types/tradingLimits.d.ts.map +1 -0
- package/dist/core/types/tradingLimits.js +3 -0
- package/dist/core/types/tradingLimits.js.map +1 -0
- package/dist/core/types/tradingMode.d.ts +24 -0
- package/dist/core/types/tradingMode.d.ts.map +1 -0
- package/dist/core/types/tradingMode.js +31 -0
- package/dist/core/types/tradingMode.js.map +1 -0
- package/dist/core/types/transaction.d.ts +45 -0
- package/dist/core/types/transaction.d.ts.map +1 -0
- package/dist/core/types/transaction.js +3 -0
- package/dist/core/types/transaction.js.map +1 -0
- package/dist/index.d.ts +50 -109
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -152
- package/dist/index.js.map +1 -1
- package/dist/services/index.d.ts +7 -6
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +7 -6
- package/dist/services/index.js.map +1 -1
- package/dist/services/pools/PoolService.d.ts +49 -0
- package/dist/services/pools/PoolService.d.ts.map +1 -0
- package/dist/services/pools/PoolService.js +92 -0
- package/dist/services/pools/PoolService.js.map +1 -0
- package/dist/services/pools/index.d.ts +2 -0
- package/dist/services/pools/index.d.ts.map +1 -0
- package/dist/services/pools/index.js +18 -0
- package/dist/services/pools/index.js.map +1 -0
- package/dist/services/pools/poolDetails.d.ts +11 -0
- package/dist/services/pools/poolDetails.d.ts.map +1 -0
- package/dist/services/pools/poolDetails.js +136 -0
- package/dist/services/pools/poolDetails.js.map +1 -0
- package/dist/services/pools/poolDiscovery.d.ts +13 -0
- package/dist/services/pools/poolDiscovery.d.ts.map +1 -0
- package/dist/services/pools/poolDiscovery.js +115 -0
- package/dist/services/pools/poolDiscovery.js.map +1 -0
- package/dist/services/quotes/QuoteService.d.ts +50 -0
- package/dist/services/quotes/QuoteService.d.ts.map +1 -0
- package/dist/services/quotes/QuoteService.js +74 -0
- package/dist/services/quotes/QuoteService.js.map +1 -0
- package/dist/services/quotes/index.d.ts +2 -0
- package/dist/services/quotes/index.d.ts.map +1 -0
- package/dist/services/quotes/index.js +18 -0
- package/dist/services/quotes/index.js.map +1 -0
- package/dist/services/routes/RouteService.d.ts +109 -0
- package/dist/services/routes/RouteService.d.ts.map +1 -0
- package/dist/services/routes/RouteService.js +239 -0
- package/dist/services/routes/RouteService.js.map +1 -0
- package/dist/services/routes/index.d.ts +2 -0
- package/dist/services/routes/index.d.ts.map +1 -0
- package/dist/services/routes/index.js +18 -0
- package/dist/services/routes/index.js.map +1 -0
- package/dist/services/swap/SwapService.d.ts +162 -0
- package/dist/services/swap/SwapService.d.ts.map +1 -0
- package/dist/services/swap/SwapService.js +180 -0
- package/dist/services/swap/SwapService.js.map +1 -0
- package/dist/services/swap/index.d.ts +2 -0
- package/dist/services/swap/index.d.ts.map +1 -0
- package/dist/services/swap/index.js +18 -0
- package/dist/services/swap/index.js.map +1 -0
- package/dist/services/tokens/index.d.ts +2 -0
- package/dist/services/tokens/index.d.ts.map +1 -0
- package/dist/services/tokens/index.js +18 -0
- package/dist/services/tokens/index.js.map +1 -0
- package/dist/services/tokens/supply/ISupplyCalculator.d.ts.map +1 -0
- package/dist/services/tokens/supply/ISupplyCalculator.js.map +1 -0
- package/dist/services/{supply → tokens/supply}/aaveSupplyCalculator.d.ts +4 -3
- package/dist/services/tokens/supply/aaveSupplyCalculator.d.ts.map +1 -0
- package/dist/services/{supply → tokens/supply}/aaveSupplyCalculator.js +7 -7
- package/dist/services/tokens/supply/aaveSupplyCalculator.js.map +1 -0
- package/dist/services/tokens/supply/calculatorFactory.d.ts +8 -0
- package/dist/services/tokens/supply/calculatorFactory.d.ts.map +1 -0
- package/dist/services/tokens/supply/calculatorFactory.js.map +1 -0
- package/dist/services/tokens/supply/defaultCalculatorFactory.d.ts +9 -0
- package/dist/services/tokens/supply/defaultCalculatorFactory.d.ts.map +1 -0
- package/dist/services/{supply → tokens/supply}/defaultCalculatorFactory.js +12 -7
- package/dist/services/tokens/supply/defaultCalculatorFactory.js.map +1 -0
- package/dist/services/tokens/supply/index.d.ts.map +1 -0
- package/dist/services/tokens/supply/index.js.map +1 -0
- package/dist/services/tokens/supply/multisigSupplyCalculator.d.ts +9 -0
- package/dist/services/tokens/supply/multisigSupplyCalculator.d.ts.map +1 -0
- package/dist/services/tokens/supply/multisigSupplyCalculator.js +33 -0
- package/dist/services/tokens/supply/multisigSupplyCalculator.js.map +1 -0
- package/dist/services/{supply → tokens/supply}/uniV3SupplyCalculator.d.ts +3 -3
- package/dist/services/tokens/supply/uniV3SupplyCalculator.d.ts.map +1 -0
- package/dist/services/{supply → tokens/supply}/uniV3SupplyCalculator.js +11 -6
- package/dist/services/tokens/supply/uniV3SupplyCalculator.js.map +1 -0
- package/dist/services/{supplyAdjustmentService.d.ts → tokens/supplyAdjustmentService.d.ts} +3 -2
- package/dist/services/tokens/supplyAdjustmentService.d.ts.map +1 -0
- package/dist/services/{supplyAdjustmentService.js → tokens/supplyAdjustmentService.js} +11 -13
- package/dist/services/tokens/supplyAdjustmentService.js.map +1 -0
- package/dist/services/tokens/tokenService.d.ts +33 -0
- package/dist/services/tokens/tokenService.d.ts.map +1 -0
- package/dist/services/tokens/tokenService.js +136 -0
- package/dist/services/tokens/tokenService.js.map +1 -0
- package/dist/services/trading/TradingLimitsService.d.ts +38 -0
- package/dist/services/trading/TradingLimitsService.d.ts.map +1 -0
- package/dist/services/trading/TradingLimitsService.js +157 -0
- package/dist/services/trading/TradingLimitsService.js.map +1 -0
- package/dist/services/trading/TradingService.d.ts +110 -0
- package/dist/services/trading/TradingService.d.ts.map +1 -0
- package/dist/services/trading/TradingService.js +162 -0
- package/dist/services/trading/TradingService.js.map +1 -0
- package/dist/services/trading/index.d.ts +3 -0
- package/dist/services/trading/index.d.ts.map +1 -0
- package/dist/services/trading/index.js +19 -0
- package/dist/services/trading/index.js.map +1 -0
- package/dist/utils/chainConfig.d.ts +16 -0
- package/dist/utils/chainConfig.d.ts.map +1 -0
- package/dist/utils/chainConfig.js +62 -0
- package/dist/utils/chainConfig.js.map +1 -0
- package/dist/utils/costUtils.d.ts +12 -0
- package/dist/utils/costUtils.d.ts.map +1 -0
- package/dist/utils/costUtils.js +59 -0
- package/dist/utils/costUtils.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/pathEncoder.d.ts +29 -0
- package/dist/utils/pathEncoder.d.ts.map +1 -0
- package/dist/utils/pathEncoder.js +73 -0
- package/dist/utils/pathEncoder.js.map +1 -0
- package/dist/utils/rateFeed.d.ts +18 -0
- package/dist/utils/rateFeed.d.ts.map +1 -0
- package/dist/utils/rateFeed.js +27 -0
- package/dist/utils/rateFeed.js.map +1 -0
- package/dist/utils/routeUtils.d.ts +295 -0
- package/dist/utils/routeUtils.d.ts.map +1 -0
- package/dist/utils/routeUtils.js +371 -0
- package/dist/utils/routeUtils.js.map +1 -0
- package/dist/utils/routes.d.ts +3 -0
- package/dist/utils/routes.d.ts.map +1 -0
- package/dist/utils/routes.js +8 -0
- package/dist/utils/routes.js.map +1 -0
- package/dist/utils/sortUtils.d.ts +24 -0
- package/dist/utils/sortUtils.d.ts.map +1 -0
- package/dist/utils/sortUtils.js +39 -0
- package/dist/utils/sortUtils.js.map +1 -0
- package/dist/utils/tokens.d.ts +2 -0
- package/dist/utils/tokens.d.ts.map +1 -0
- package/dist/utils/tokens.js +13 -0
- package/dist/utils/tokens.js.map +1 -0
- package/dist/utils/tradingLimits.d.ts +41 -0
- package/dist/utils/tradingLimits.d.ts.map +1 -0
- package/dist/utils/tradingLimits.js +171 -0
- package/dist/utils/tradingLimits.js.map +1 -0
- package/dist/utils/validation.d.ts +19 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +34 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +10 -23
- package/dist/abis/bipoolmanager.d.ts +0 -15
- package/dist/abis/bipoolmanager.d.ts.map +0 -1
- package/dist/abis/bipoolmanager.js +0 -26
- package/dist/abis/bipoolmanager.js.map +0 -1
- package/dist/abis/broker.d.ts +0 -2
- package/dist/abis/broker.d.ts.map +0 -1
- package/dist/abis/broker.js +0 -15
- package/dist/abis/broker.js.map +0 -1
- package/dist/abis/erc20.d.ts +0 -2
- package/dist/abis/erc20.d.ts.map +0 -1
- package/dist/abis/erc20.js +0 -11
- package/dist/abis/erc20.js.map +0 -1
- package/dist/abis/index.d.ts +0 -6
- package/dist/abis/index.d.ts.map +0 -1
- package/dist/abis/index.js.map +0 -1
- package/dist/abis/pricingmodule.d.ts +0 -2
- package/dist/abis/pricingmodule.d.ts.map +0 -1
- package/dist/abis/pricingmodule.js +0 -5
- package/dist/abis/pricingmodule.js.map +0 -1
- package/dist/abis/reserve.d.ts +0 -2
- package/dist/abis/reserve.d.ts.map +0 -1
- package/dist/abis/reserve.js +0 -9
- package/dist/abis/reserve.js.map +0 -1
- package/dist/abis/uniswapV3.d.ts +0 -4
- package/dist/abis/uniswapV3.d.ts.map +0 -1
- package/dist/abis/uniswapV3.js.map +0 -1
- package/dist/adapters/implementations/ethersAdapter.d.ts +0 -13
- package/dist/adapters/implementations/ethersAdapter.d.ts.map +0 -1
- package/dist/adapters/implementations/ethersAdapter.js +0 -92
- package/dist/adapters/implementations/ethersAdapter.js.map +0 -1
- package/dist/adapters/implementations/ethersV5Adapter.d.ts +0 -13
- package/dist/adapters/implementations/ethersV5Adapter.d.ts.map +0 -1
- package/dist/adapters/implementations/ethersV5Adapter.js +0 -92
- package/dist/adapters/implementations/ethersV5Adapter.js.map +0 -1
- package/dist/adapters/implementations/viemAdapter.d.ts +0 -18
- package/dist/adapters/implementations/viemAdapter.d.ts.map +0 -1
- package/dist/adapters/implementations/viemAdapter.js +0 -126
- package/dist/adapters/implementations/viemAdapter.js.map +0 -1
- package/dist/adapters/index.d.ts +0 -5
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/index.js +0 -10
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/proxies/ethersAdapterProxy.d.ts +0 -26
- package/dist/adapters/proxies/ethersAdapterProxy.d.ts.map +0 -1
- package/dist/adapters/proxies/ethersAdapterProxy.js +0 -78
- package/dist/adapters/proxies/ethersAdapterProxy.js.map +0 -1
- package/dist/adapters/proxies/ethersV5AdapterProxy.d.ts +0 -26
- package/dist/adapters/proxies/ethersV5AdapterProxy.d.ts.map +0 -1
- package/dist/adapters/proxies/ethersV5AdapterProxy.js +0 -78
- package/dist/adapters/proxies/ethersV5AdapterProxy.js.map +0 -1
- package/dist/adapters/proxies/viemAdapterProxy.d.ts +0 -29
- package/dist/adapters/proxies/viemAdapterProxy.d.ts.map +0 -1
- package/dist/adapters/proxies/viemAdapterProxy.js +0 -78
- package/dist/adapters/proxies/viemAdapterProxy.js.map +0 -1
- package/dist/constants/aaveConfig.d.ts.map +0 -1
- package/dist/constants/aaveConfig.js.map +0 -1
- package/dist/constants/addresses.d.ts.map +0 -1
- package/dist/constants/addresses.js +0 -61
- package/dist/constants/addresses.js.map +0 -1
- package/dist/constants/chainId.d.ts +0 -5
- package/dist/constants/chainId.d.ts.map +0 -1
- package/dist/constants/chainId.js.map +0 -1
- package/dist/constants/contractNames.d.ts.map +0 -1
- package/dist/constants/contractNames.js.map +0 -1
- package/dist/constants/index.d.ts.map +0 -1
- package/dist/constants/index.js.map +0 -1
- package/dist/constants/mentoAddresses.d.ts.map +0 -1
- package/dist/constants/mentoAddresses.js.map +0 -1
- package/dist/constants/proposalState.d.ts +0 -11
- package/dist/constants/proposalState.d.ts.map +0 -1
- package/dist/constants/proposalState.js +0 -15
- package/dist/constants/proposalState.js.map +0 -1
- package/dist/constants/protocolAddresses.d.ts.map +0 -1
- package/dist/constants/protocolAddresses.js.map +0 -1
- package/dist/constants/stableTokenMetadata.d.ts +0 -12
- package/dist/constants/stableTokenMetadata.d.ts.map +0 -1
- package/dist/constants/stableTokenMetadata.js +0 -14
- package/dist/constants/stableTokenMetadata.js.map +0 -1
- package/dist/services/collateralAssetService.d.ts +0 -8
- package/dist/services/collateralAssetService.d.ts.map +0 -1
- package/dist/services/collateralAssetService.js +0 -47
- package/dist/services/collateralAssetService.js.map +0 -1
- package/dist/services/stableTokenService.d.ts +0 -9
- package/dist/services/stableTokenService.d.ts.map +0 -1
- package/dist/services/stableTokenService.js +0 -40
- package/dist/services/stableTokenService.js.map +0 -1
- package/dist/services/supply/ISupplyCalculator.d.ts.map +0 -1
- package/dist/services/supply/ISupplyCalculator.js.map +0 -1
- package/dist/services/supply/aaveSupplyCalculator.d.ts.map +0 -1
- package/dist/services/supply/aaveSupplyCalculator.js.map +0 -1
- package/dist/services/supply/calculatorFactory.d.ts +0 -8
- package/dist/services/supply/calculatorFactory.d.ts.map +0 -1
- package/dist/services/supply/calculatorFactory.js.map +0 -1
- package/dist/services/supply/defaultCalculatorFactory.d.ts +0 -9
- package/dist/services/supply/defaultCalculatorFactory.d.ts.map +0 -1
- package/dist/services/supply/defaultCalculatorFactory.js.map +0 -1
- package/dist/services/supply/index.d.ts.map +0 -1
- package/dist/services/supply/index.js.map +0 -1
- package/dist/services/supply/multisigSupplyCalculator.d.ts +0 -9
- package/dist/services/supply/multisigSupplyCalculator.d.ts.map +0 -1
- package/dist/services/supply/multisigSupplyCalculator.js +0 -21
- package/dist/services/supply/multisigSupplyCalculator.js.map +0 -1
- package/dist/services/supply/uniV3SupplyCalculator.d.ts.map +0 -1
- package/dist/services/supply/uniV3SupplyCalculator.js.map +0 -1
- package/dist/services/supplyAdjustmentService.d.ts.map +0 -1
- package/dist/services/supplyAdjustmentService.js.map +0 -1
- package/dist/services/swapService.d.ts +0 -70
- package/dist/services/swapService.d.ts.map +0 -1
- package/dist/services/swapService.js +0 -134
- package/dist/services/swapService.js.map +0 -1
- package/dist/services/tokenMetadataService.d.ts +0 -8
- package/dist/services/tokenMetadataService.d.ts.map +0 -1
- package/dist/services/tokenMetadataService.js +0 -44
- package/dist/services/tokenMetadataService.js.map +0 -1
- package/dist/types/contractAddresses.d.ts +0 -23
- package/dist/types/contractAddresses.d.ts.map +0 -1
- package/dist/types/contractAddresses.js.map +0 -1
- package/dist/types/exchange.d.ts +0 -6
- package/dist/types/exchange.d.ts.map +0 -1
- package/dist/types/exchange.js.map +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/provider.d.ts +0 -29
- package/dist/types/provider.d.ts.map +0 -1
- package/dist/types/token.d.ts.map +0 -1
- /package/dist/{constants → core/constants}/aaveConfig.d.ts +0 -0
- /package/dist/{constants → core/constants}/contractNames.d.ts +0 -0
- /package/dist/{constants → core/constants}/contractNames.js +0 -0
- /package/dist/{constants → core/constants}/protocolAddresses.d.ts +0 -0
- /package/dist/{constants → core/constants}/protocolAddresses.js +0 -0
- /package/dist/{types → core/types}/contractAddresses.js +0 -0
- /package/dist/{types → core/types}/provider.js +0 -0
- /package/dist/{types → core/types}/token.js +0 -0
- /package/dist/services/{supply → tokens/supply}/ISupplyCalculator.d.ts +0 -0
- /package/dist/services/{supply → tokens/supply}/ISupplyCalculator.js +0 -0
- /package/dist/services/{supply → tokens/supply}/calculatorFactory.js +0 -0
- /package/dist/services/{supply → tokens/supply}/index.d.ts +0 -0
- /package/dist/services/{supply → tokens/supply}/index.js +0 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TradingLimitsService = void 0;
|
|
4
|
+
const types_1 = require("../../core/types");
|
|
5
|
+
const abis_1 = require("../../core/abis");
|
|
6
|
+
const constants_1 = require("../../core/constants");
|
|
7
|
+
const tradingLimits_1 = require("../../utils/tradingLimits");
|
|
8
|
+
/**
|
|
9
|
+
* Service for querying trading limits from the Mento protocol.
|
|
10
|
+
* Supports both FPMM pools (TradingLimitsV2) and Virtual pools (TradingLimitsV1).
|
|
11
|
+
*/
|
|
12
|
+
class TradingLimitsService {
|
|
13
|
+
constructor(publicClient, chainId) {
|
|
14
|
+
this.publicClient = publicClient;
|
|
15
|
+
this.chainId = chainId;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get trading limits for a pool.
|
|
19
|
+
* Returns an array of TradingLimit objects for each configured limit.
|
|
20
|
+
*
|
|
21
|
+
* @param pool - The pool to get trading limits for
|
|
22
|
+
* @returns Array of TradingLimit objects with maxIn/maxOut/until
|
|
23
|
+
*/
|
|
24
|
+
async getPoolTradingLimits(pool) {
|
|
25
|
+
if (pool.poolType === types_1.PoolType.FPMM) {
|
|
26
|
+
return this.getFPMMTradingLimits(pool);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return this.getVirtualPoolTradingLimits(pool);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get trading limits for an FPMM pool.
|
|
34
|
+
* FPMM pools use TradingLimitsV2 with fixed timeframes.
|
|
35
|
+
*/
|
|
36
|
+
async getFPMMTradingLimits(pool) {
|
|
37
|
+
const limits = [];
|
|
38
|
+
// Get trading limits for both tokens
|
|
39
|
+
const [token0Limits, token1Limits] = await Promise.all([
|
|
40
|
+
this.getFPMMTokenLimits(pool.poolAddr, pool.token0),
|
|
41
|
+
this.getFPMMTokenLimits(pool.poolAddr, pool.token1),
|
|
42
|
+
]);
|
|
43
|
+
limits.push(...token0Limits);
|
|
44
|
+
limits.push(...token1Limits);
|
|
45
|
+
return limits;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get trading limits for a specific token in an FPMM pool.
|
|
49
|
+
*/
|
|
50
|
+
async getFPMMTokenLimits(poolAddr, token) {
|
|
51
|
+
try {
|
|
52
|
+
const result = await this.publicClient.readContract({
|
|
53
|
+
address: poolAddr,
|
|
54
|
+
abi: abis_1.FPMM_ABI,
|
|
55
|
+
functionName: 'getTradingLimits',
|
|
56
|
+
args: [token],
|
|
57
|
+
});
|
|
58
|
+
// Result is a tuple: [config, state]
|
|
59
|
+
const [configTuple, stateTuple] = result;
|
|
60
|
+
const config = {
|
|
61
|
+
limit0: configTuple.limit0,
|
|
62
|
+
limit1: configTuple.limit1,
|
|
63
|
+
decimals: configTuple.decimals,
|
|
64
|
+
};
|
|
65
|
+
const state = {
|
|
66
|
+
lastUpdated0: Number(stateTuple.lastUpdated0),
|
|
67
|
+
lastUpdated1: Number(stateTuple.lastUpdated1),
|
|
68
|
+
netflow0: stateTuple.netflow0,
|
|
69
|
+
netflow1: stateTuple.netflow1,
|
|
70
|
+
};
|
|
71
|
+
if (!(0, tradingLimits_1.hasConfiguredLimitsV2)(config)) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
return (0, tradingLimits_1.calculateTradingLimitsV2)(config, state, token);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Token may not have limits configured, or invalid token
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get trading limits for a Virtual pool.
|
|
83
|
+
* Virtual pools use TradingLimitsV1 via the Broker contract.
|
|
84
|
+
*/
|
|
85
|
+
async getVirtualPoolTradingLimits(pool) {
|
|
86
|
+
if (!pool.exchangeId) {
|
|
87
|
+
console.warn(`Virtual pool ${pool.poolAddr} missing exchangeId - cannot query trading limits`);
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
const limits = [];
|
|
91
|
+
// Get trading limits for both tokens
|
|
92
|
+
const [token0Limits, token1Limits] = await Promise.all([
|
|
93
|
+
this.getVirtualPoolTokenLimits(pool.exchangeId, pool.token0),
|
|
94
|
+
this.getVirtualPoolTokenLimits(pool.exchangeId, pool.token1),
|
|
95
|
+
]);
|
|
96
|
+
limits.push(...token0Limits);
|
|
97
|
+
limits.push(...token1Limits);
|
|
98
|
+
return limits;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get trading limits for a specific token in a Virtual pool.
|
|
102
|
+
*/
|
|
103
|
+
async getVirtualPoolTokenLimits(exchangeId, token) {
|
|
104
|
+
const brokerAddr = (0, constants_1.getContractAddress)(this.chainId, 'Broker');
|
|
105
|
+
const limitId = (0, tradingLimits_1.computeLimitId)(exchangeId, token);
|
|
106
|
+
try {
|
|
107
|
+
// Fetch config and state in parallel
|
|
108
|
+
const [configResult, stateResult] = await Promise.all([
|
|
109
|
+
this.publicClient.readContract({
|
|
110
|
+
address: brokerAddr,
|
|
111
|
+
abi: abis_1.BROKER_ABI,
|
|
112
|
+
functionName: 'tradingLimitsConfig',
|
|
113
|
+
args: [limitId],
|
|
114
|
+
}),
|
|
115
|
+
this.publicClient.readContract({
|
|
116
|
+
address: brokerAddr,
|
|
117
|
+
abi: abis_1.BROKER_ABI,
|
|
118
|
+
functionName: 'tradingLimitsState',
|
|
119
|
+
args: [limitId],
|
|
120
|
+
}),
|
|
121
|
+
]);
|
|
122
|
+
// Parse config result
|
|
123
|
+
const configTuple = configResult;
|
|
124
|
+
const config = {
|
|
125
|
+
timestep0: Number(configTuple[0]),
|
|
126
|
+
timestep1: Number(configTuple[1]),
|
|
127
|
+
limit0: configTuple[2],
|
|
128
|
+
limit1: configTuple[3],
|
|
129
|
+
limitGlobal: configTuple[4],
|
|
130
|
+
flags: Number(configTuple[5]),
|
|
131
|
+
};
|
|
132
|
+
// Parse state result
|
|
133
|
+
const stateTuple = stateResult;
|
|
134
|
+
const state = {
|
|
135
|
+
lastUpdated0: Number(stateTuple[0]),
|
|
136
|
+
lastUpdated1: Number(stateTuple[1]),
|
|
137
|
+
netflow0: stateTuple[2],
|
|
138
|
+
netflow1: stateTuple[3],
|
|
139
|
+
netflowGlobal: stateTuple[4],
|
|
140
|
+
};
|
|
141
|
+
// Only return limits if configured
|
|
142
|
+
if (!(0, tradingLimits_1.hasConfiguredLimitsV1)(config)) {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
// Get token decimals (V1 uses 0 decimals internally, but we track token decimals for display)
|
|
146
|
+
// For now, return 0 as the reference - consumers should query token decimals separately
|
|
147
|
+
const tokenDecimals = 0; // V1 stores values with 0 decimal precision
|
|
148
|
+
return (0, tradingLimits_1.calculateTradingLimitsV1)(config, state, token, tokenDecimals);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// Trading limits may not be configured for this token
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.TradingLimitsService = TradingLimitsService;
|
|
157
|
+
//# sourceMappingURL=TradingLimitsService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TradingLimitsService.js","sourceRoot":"","sources":["../../../src/services/trading/TradingLimitsService.ts"],"names":[],"mappings":";;;AASA,4CAA2C;AAC3C,0CAAsD;AACtD,oDAAkE;AAClE,6DAMkC;AAElC;;;GAGG;AACH,MAAa,oBAAoB;IAC/B,YACU,YAA0B,EAC1B,OAAe;QADf,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAQ;IACtB,CAAC;IAEJ;;;;;;OAMG;IACH,KAAK,CAAC,oBAAoB,CAAC,IAAU;QACnC,IAAI,IAAI,CAAC,QAAQ,KAAK,gBAAQ,CAAC,IAAI,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAA;QACxC,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,oBAAoB,CAAC,IAAU;QAC3C,MAAM,MAAM,GAAmB,EAAE,CAAA;QAEjC,qCAAqC;QACrC,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACrD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC;YACnD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC;SACpD,C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@@
|
|
|
1
|
+
import { PublicClient } from 'viem';
|
|
2
|
+
import { Route, Pool, TradingLimit, PoolTradabilityStatus } from '../../core/types';
|
|
3
|
+
import { RouteService } from '../routes';
|
|
4
|
+
/**
|
|
5
|
+
* Service for checking trading status and circuit breaker state in the Mento protocol.
|
|
6
|
+
* Provides methods to query whether trading is enabled for specific rate feeds,
|
|
7
|
+
* token pairs, or routes. Also integrates trading limit checks.
|
|
8
|
+
*/
|
|
9
|
+
export declare class TradingService {
|
|
10
|
+
private publicClient;
|
|
11
|
+
private chainId;
|
|
12
|
+
private routeService;
|
|
13
|
+
private tradingLimitsService;
|
|
14
|
+
constructor(publicClient: PublicClient, chainId: number, routeService: RouteService);
|
|
15
|
+
/**
|
|
16
|
+
* Returns the current trading mode for a given rate feed.
|
|
17
|
+
*
|
|
18
|
+
* The BreakerBox uses a bitmask approach where 0 means bidirectional trading
|
|
19
|
+
* is enabled, and any non-zero value means trading is suspended.
|
|
20
|
+
*
|
|
21
|
+
* @param rateFeedId - The address of the rate feed
|
|
22
|
+
* @returns The raw trading mode value from BreakerBox (0 = enabled, non-zero = suspended)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const mode = await tradingService.getRateFeedTradingMode(rateFeedId)
|
|
27
|
+
* if (mode === TradingMode.BIDIRECTIONAL) {
|
|
28
|
+
* console.log('Trading is enabled')
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
getRateFeedTradingMode(rateFeedId: string): Promise<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a trading pair is currently tradable.
|
|
35
|
+
* For multi-hop routes (e.g., CELO → USDm → USDT), checks that ALL
|
|
36
|
+
* intermediate rate feeds are in BIDIRECTIONAL mode.
|
|
37
|
+
*
|
|
38
|
+
* @param tokenIn - Input token address
|
|
39
|
+
* @param tokenOut - Output token address
|
|
40
|
+
* @returns true if the pair is tradable (all rate feeds BIDIRECTIONAL), false otherwise
|
|
41
|
+
* @throws {RouteNotFoundError} If no route exists between the token pair
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const isTradable = await tradingService.isPairTradable(USDm, CELO)
|
|
46
|
+
* if (!isTradable) {
|
|
47
|
+
* console.log('Trading is currently suspended for this pair')
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
isPairTradable(tokenIn: string, tokenOut: string): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Checks if a route is currently tradable.
|
|
54
|
+
* Verifies that all pools in the route's path have their rate feeds
|
|
55
|
+
* in BIDIRECTIONAL mode.
|
|
56
|
+
*
|
|
57
|
+
* @param route - The route to check
|
|
58
|
+
* @returns true if all pools in the route are tradable, false otherwise
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const route = await routeService.findRoute(tokenIn, tokenOut)
|
|
63
|
+
* const isRouteTradable = await tradingService.isRouteTradable(route)
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
isRouteTradable(route: Route): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Get trading limits for a pool.
|
|
69
|
+
*
|
|
70
|
+
* @param pool - The pool to get trading limits for
|
|
71
|
+
* @returns Array of TradingLimit objects with maxIn/maxOut/until
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const limits = await tradingService.getPoolTradingLimits(pool)
|
|
76
|
+
* limits.forEach(limit => {
|
|
77
|
+
* console.log(`${limit.asset}: maxIn=${limit.maxIn}, maxOut=${limit.maxOut}`)
|
|
78
|
+
* })
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
getPoolTradingLimits(pool: Pool): Promise<TradingLimit[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Get complete tradability status for a pool.
|
|
84
|
+
* Returns separate flags for circuit breaker and trading limits,
|
|
85
|
+
* allowing frontends to show different messages for each condition.
|
|
86
|
+
*
|
|
87
|
+
* @param pool - The pool to check
|
|
88
|
+
* @returns PoolTradabilityStatus with tradable, circuitBreakerOk, limitsOk, and limits
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const status = await tradingService.getPoolTradabilityStatus(pool)
|
|
93
|
+
* if (!status.circuitBreakerOk) {
|
|
94
|
+
* showModal("Trading temporarily suspended (circuit breaker)")
|
|
95
|
+
* } else if (!status.limitsOk) {
|
|
96
|
+
* showModal("Trading limit reached", status.limits)
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
getPoolTradabilityStatus(pool: Pool): Promise<PoolTradabilityStatus>;
|
|
101
|
+
/**
|
|
102
|
+
* Get the reference rate feed ID for a pool.
|
|
103
|
+
* Both FPMM and Virtual pools expose this via the referenceRateFeedID() view function.
|
|
104
|
+
*
|
|
105
|
+
* @param pool - The pool to get rate feed ID for
|
|
106
|
+
* @returns The rate feed ID address
|
|
107
|
+
*/
|
|
108
|
+
getPoolRateFeedId(pool: Pool): Promise<string>;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=TradingService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TradingService.d.ts","sourceRoot":"","sources":["../../../src/services/trading/TradingService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EAEL,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,qBAAqB,EACtB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAKxC;;;;GAIG;AACH,qBAAa,cAAc;IAIvB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,YAAY;IALtB,OAAO,CAAC,oBAAoB,CAAsB;gBAGxC,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,YAAY;IAKpC;;;;;;;;;;;;;;;;OAgBG;IACG,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAajE;;;;;;;;;;;;;;;;;OAiBG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKzE;;;;;;;;;;;;;OAaG;IACG,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;IAcrD;;;;;;;;;;;;;OAaG;IACG,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAI/D;;;;;;;;;;;;;;;;;OAiBG;IACG,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAqB1E;;;;;;OAMG;IACG,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;CASrD"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TradingService = void 0;
|
|
4
|
+
const types_1 = require("../../core/types");
|
|
5
|
+
const TradingLimitsService_1 = require("./TradingLimitsService");
|
|
6
|
+
const abis_1 = require("../../core/abis");
|
|
7
|
+
const constants_1 = require("../../core/constants");
|
|
8
|
+
/**
|
|
9
|
+
* Service for checking trading status and circuit breaker state in the Mento protocol.
|
|
10
|
+
* Provides methods to query whether trading is enabled for specific rate feeds,
|
|
11
|
+
* token pairs, or routes. Also integrates trading limit checks.
|
|
12
|
+
*/
|
|
13
|
+
class TradingService {
|
|
14
|
+
constructor(publicClient, chainId, routeService) {
|
|
15
|
+
this.publicClient = publicClient;
|
|
16
|
+
this.chainId = chainId;
|
|
17
|
+
this.routeService = routeService;
|
|
18
|
+
this.tradingLimitsService = new TradingLimitsService_1.TradingLimitsService(publicClient, chainId);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns the current trading mode for a given rate feed.
|
|
22
|
+
*
|
|
23
|
+
* The BreakerBox uses a bitmask approach where 0 means bidirectional trading
|
|
24
|
+
* is enabled, and any non-zero value means trading is suspended.
|
|
25
|
+
*
|
|
26
|
+
* @param rateFeedId - The address of the rate feed
|
|
27
|
+
* @returns The raw trading mode value from BreakerBox (0 = enabled, non-zero = suspended)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const mode = await tradingService.getRateFeedTradingMode(rateFeedId)
|
|
32
|
+
* if (mode === TradingMode.BIDIRECTIONAL) {
|
|
33
|
+
* console.log('Trading is enabled')
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
async getRateFeedTradingMode(rateFeedId) {
|
|
38
|
+
const breakerBoxAddr = (0, constants_1.getContractAddress)(this.chainId, 'BreakerBox');
|
|
39
|
+
const mode = await this.publicClient.readContract({
|
|
40
|
+
address: breakerBoxAddr,
|
|
41
|
+
abi: abis_1.BREAKERBOX_ABI,
|
|
42
|
+
functionName: 'getRateFeedTradingMode',
|
|
43
|
+
args: [rateFeedId],
|
|
44
|
+
});
|
|
45
|
+
return Number(mode);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a trading pair is currently tradable.
|
|
49
|
+
* For multi-hop routes (e.g., CELO → USDm → USDT), checks that ALL
|
|
50
|
+
* intermediate rate feeds are in BIDIRECTIONAL mode.
|
|
51
|
+
*
|
|
52
|
+
* @param tokenIn - Input token address
|
|
53
|
+
* @param tokenOut - Output token address
|
|
54
|
+
* @returns true if the pair is tradable (all rate feeds BIDIRECTIONAL), false otherwise
|
|
55
|
+
* @throws {RouteNotFoundError} If no route exists between the token pair
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const isTradable = await tradingService.isPairTradable(USDm, CELO)
|
|
60
|
+
* if (!isTradable) {
|
|
61
|
+
* console.log('Trading is currently suspended for this pair')
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
async isPairTradable(tokenIn, tokenOut) {
|
|
66
|
+
const route = await this.routeService.findRoute(tokenIn, tokenOut);
|
|
67
|
+
return this.isRouteTradable(route);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Checks if a route is currently tradable.
|
|
71
|
+
* Verifies that all pools in the route's path have their rate feeds
|
|
72
|
+
* in BIDIRECTIONAL mode.
|
|
73
|
+
*
|
|
74
|
+
* @param route - The route to check
|
|
75
|
+
* @returns true if all pools in the route are tradable, false otherwise
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const route = await routeService.findRoute(tokenIn, tokenOut)
|
|
80
|
+
* const isRouteTradable = await tradingService.isRouteTradable(route)
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
async isRouteTradable(route) {
|
|
84
|
+
// Get rate feed IDs for each pool in the path and check trading modes
|
|
85
|
+
const rateFeedChecks = await Promise.all(route.path.map(async (pool) => {
|
|
86
|
+
const rateFeedId = await this.getPoolRateFeedId(pool);
|
|
87
|
+
const tradingMode = await this.getRateFeedTradingMode(rateFeedId);
|
|
88
|
+
return (0, types_1.isTradingEnabled)(tradingMode);
|
|
89
|
+
}));
|
|
90
|
+
// All rate feeds must have trading enabled for the route to be tradable
|
|
91
|
+
return rateFeedChecks.every((isEnabled) => isEnabled);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get trading limits for a pool.
|
|
95
|
+
*
|
|
96
|
+
* @param pool - The pool to get trading limits for
|
|
97
|
+
* @returns Array of TradingLimit objects with maxIn/maxOut/until
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const limits = await tradingService.getPoolTradingLimits(pool)
|
|
102
|
+
* limits.forEach(limit => {
|
|
103
|
+
* console.log(`${limit.asset}: maxIn=${limit.maxIn}, maxOut=${limit.maxOut}`)
|
|
104
|
+
* })
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
async getPoolTradingLimits(pool) {
|
|
108
|
+
return this.tradingLimitsService.getPoolTradingLimits(pool);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get complete tradability status for a pool.
|
|
112
|
+
* Returns separate flags for circuit breaker and trading limits,
|
|
113
|
+
* allowing frontends to show different messages for each condition.
|
|
114
|
+
*
|
|
115
|
+
* @param pool - The pool to check
|
|
116
|
+
* @returns PoolTradabilityStatus with tradable, circuitBreakerOk, limitsOk, and limits
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const status = await tradingService.getPoolTradabilityStatus(pool)
|
|
121
|
+
* if (!status.circuitBreakerOk) {
|
|
122
|
+
* showModal("Trading temporarily suspended (circuit breaker)")
|
|
123
|
+
* } else if (!status.limitsOk) {
|
|
124
|
+
* showModal("Trading limit reached", status.limits)
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
async getPoolTradabilityStatus(pool) {
|
|
129
|
+
const [rateFeedId, limits] = await Promise.all([
|
|
130
|
+
this.getPoolRateFeedId(pool),
|
|
131
|
+
this.tradingLimitsService.getPoolTradingLimits(pool),
|
|
132
|
+
]);
|
|
133
|
+
const tradingMode = await this.getRateFeedTradingMode(rateFeedId);
|
|
134
|
+
const circuitBreakerOk = (0, types_1.isTradingEnabled)(tradingMode);
|
|
135
|
+
// Limits are OK if no limits configured OR all limits have capacity
|
|
136
|
+
const limitsOk = limits.length === 0 || limits.every((l) => l.maxIn > 0n && l.maxOut > 0n);
|
|
137
|
+
return {
|
|
138
|
+
tradable: circuitBreakerOk && limitsOk,
|
|
139
|
+
circuitBreakerOk,
|
|
140
|
+
tradingMode,
|
|
141
|
+
limitsOk,
|
|
142
|
+
limits,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get the reference rate feed ID for a pool.
|
|
147
|
+
* Both FPMM and Virtual pools expose this via the referenceRateFeedID() view function.
|
|
148
|
+
*
|
|
149
|
+
* @param pool - The pool to get rate feed ID for
|
|
150
|
+
* @returns The rate feed ID address
|
|
151
|
+
*/
|
|
152
|
+
async getPoolRateFeedId(pool) {
|
|
153
|
+
const rateFeedId = await this.publicClient.readContract({
|
|
154
|
+
address: pool.poolAddr,
|
|
155
|
+
abi: abis_1.FPMM_ABI,
|
|
156
|
+
functionName: 'referenceRateFeedID',
|
|
157
|
+
});
|
|
158
|
+
return rateFeedId;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.TradingService = TradingService;
|
|
162
|
+
//# sourceMappingURL=TradingService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TradingService.js","sourceRoot":"","sources":["../../../src/services/trading/TradingService.ts"],"names":[],"mappings":";;;AACA,4CAMyB;AAEzB,iEAA6D;AAC7D,0CAA0D;AAC1D,oDAAkE;AAElE;;;;GAIG;AACH,MAAa,cAAc;IAGzB,YACU,YAA0B,EAC1B,OAAe,EACf,YAA0B;QAF1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAc;QAElC,IAAI,CAAC,oBAAoB,GAAG,IAAI,2CAAoB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;IAC7E,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,sBAAsB,CAAC,UAAkB;QAC7C,MAAM,cAAc,GAAG,IAAA,8BAAkB,EAAC,IAAI,CAAC,OAAkB,EAAE,YAAY,CAAC,CAAA;QAEhF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;YAChD,OAAO,EAAE,cAA+B;YACxC,GAA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AI,CAAC,iBAAiB,CAAC,IAAI,CAAC;YAC5B,IAAI,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,IAAI,CAAC;SACrD,CAAC,CAAA;QAEF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,UAAU,CAAC,CAAA;QACjE,MAAM,gBAAgB,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAA;QAEtD,oEAAoE;QACpE,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,IAAI,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;QAE1F,OAAO;YACL,QAAQ,EAAE,gBAAgB,IAAI,QAAQ;YACtC,gBAAgB;YAChB,WAAW;YACX,QAAQ;YACR,MAAM;SACP,CAAA;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,iBAAiB,CAAC,IAAU;QAChC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;YACtD,OAAO,EAAE,IAAI,CAAC,QAAyB;YACvC,GAAG,EAAE,eAAQ;YACb,YAAY,EAAE,qBAAqB;SACpC,CAAC,CAAA;QAEF,OAAO,UAAoB,CAAA;IAC7B,CAAC;CACF;AArKD,wCAqKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/trading/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./TradingService"), exports);
|
|
18
|
+
__exportStar(require("./TradingLimitsService"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/trading/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,yDAAsC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Chain } from 'viem/chains';
|
|
2
|
+
/**
|
|
3
|
+
* Get the default RPC URL for a given chain ID
|
|
4
|
+
* @param chainId - The chain ID
|
|
5
|
+
* @returns The default RPC URL for the chain
|
|
6
|
+
* @throws Error if chain ID is not supported
|
|
7
|
+
*/
|
|
8
|
+
export declare function getDefaultRpcUrl(chainId: number): string;
|
|
9
|
+
/**
|
|
10
|
+
* Get the viem chain configuration for a given chain ID
|
|
11
|
+
* @param chainId - The chain ID
|
|
12
|
+
* @returns The viem chain configuration
|
|
13
|
+
* @throws Error if chain ID is not supported
|
|
14
|
+
*/
|
|
15
|
+
export declare function getChainConfig(chainId: number): Chain;
|
|
16
|
+
//# sourceMappingURL=chainConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chainConfig.d.ts","sourceRoot":"","sources":["../../src/utils/chainConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,KAAK,EAAE,MAAM,aAAa,CAAA;AA2B9C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CASxD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CASrD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultRpcUrl = getDefaultRpcUrl;
|
|
4
|
+
exports.getChainConfig = getChainConfig;
|
|
5
|
+
const chains_1 = require("viem/chains");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const chainId_1 = require("../core/constants/chainId");
|
|
8
|
+
// Celo Sepolia chain definition (not available in viem/chains yet)
|
|
9
|
+
const celoSepolia = (0, viem_1.defineChain)({
|
|
10
|
+
id: 11142220,
|
|
11
|
+
name: 'Celo Sepolia',
|
|
12
|
+
nativeCurrency: {
|
|
13
|
+
decimals: 18,
|
|
14
|
+
name: 'CELO',
|
|
15
|
+
symbol: 'CELO',
|
|
16
|
+
},
|
|
17
|
+
rpcUrls: {
|
|
18
|
+
default: {
|
|
19
|
+
http: ['https://forno.celo-sepolia.celo-testnet.org'],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
blockExplorers: {
|
|
23
|
+
default: {
|
|
24
|
+
name: 'Celo Explorer',
|
|
25
|
+
url: 'https://sepolia.celoscan.io',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
testnet: true,
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Get the default RPC URL for a given chain ID
|
|
32
|
+
* @param chainId - The chain ID
|
|
33
|
+
* @returns The default RPC URL for the chain
|
|
34
|
+
* @throws Error if chain ID is not supported
|
|
35
|
+
*/
|
|
36
|
+
function getDefaultRpcUrl(chainId) {
|
|
37
|
+
switch (chainId) {
|
|
38
|
+
case chainId_1.ChainId.CELO:
|
|
39
|
+
return 'https://forno.celo.org';
|
|
40
|
+
case chainId_1.ChainId.CELO_SEPOLIA:
|
|
41
|
+
return 'https://forno.celo-sepolia.celo-testnet.org';
|
|
42
|
+
default:
|
|
43
|
+
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the viem chain configuration for a given chain ID
|
|
48
|
+
* @param chainId - The chain ID
|
|
49
|
+
* @returns The viem chain configuration
|
|
50
|
+
* @throws Error if chain ID is not supported
|
|
51
|
+
*/
|
|
52
|
+
function getChainConfig(chainId) {
|
|
53
|
+
switch (chainId) {
|
|
54
|
+
case chainId_1.ChainId.CELO:
|
|
55
|
+
return chains_1.celo;
|
|
56
|
+
case chainId_1.ChainId.CELO_SEPOLIA:
|
|
57
|
+
return celoSepolia;
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=chainConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chainConfig.js","sourceRoot":"","sources":["../../src/utils/chainConfig.ts"],"names":[],"mappings":";;AAiCA,4CASC;AAQD,wCASC;AA3DD,wCAA8C;AAC9C,+BAAkC;AAClC,uDAAmD;AAEnD,mEAAmE;AACnE,MAAM,WAAW,GAAG,IAAA,kBAAW,EAAC;IAC9B,EAAE,EAAE,QAAQ;IACZ,IAAI,EAAE,cAAc;IACpB,cAAc,EAAE;QACd,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,MAAM;KACf;IACD,OAAO,EAAE;QACP,OAAO,EAAE;YACP,IAAI,EAAE,CAAC,6CAA6C,CAAC;SACtD;KACF;IACD,cAAc,EAAE;QACd,OAAO,EAAE;YACP,IAAI,EAAE,eAAe;YACrB,GAAG,EAAE,6BAA6B;SACnC;KACF;IACD,OAAO,EAAE,IAAI;CACd,CAAC,CAAA;AAEF;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,iBAAO,CAAC,IAAI;YACf,OAAO,wBAAwB,CAAA;QACjC,KAAK,iBAAO,CAAC,YAAY;YACvB,OAAO,6CAA6C,CAAA;QACtD;YACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAA;IACvD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,OAAe;IAC5C,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,iBAAO,CAAC,IAAI;YACf,OAAO,aAAI,CAAA;QACb,KAAK,iBAAO,CAAC,YAAY;YACvB,OAAO,WAAW,CAAA;QACpB;YACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAA;IACvD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Pool } from '../core/types';
|
|
2
|
+
import type { PublicClient } from 'viem';
|
|
3
|
+
/**
|
|
4
|
+
* Calculate cost percentage for a pool based on its type
|
|
5
|
+
* Returns cost as a percentage (e.g., 0.5 = 0.5%)
|
|
6
|
+
*
|
|
7
|
+
* @param pool - The pool to calculate cost for
|
|
8
|
+
* @param publicClient - Viem public client for RPC calls
|
|
9
|
+
* @returns Cost percentage for the pool
|
|
10
|
+
*/
|
|
11
|
+
export declare function getPoolCostPercent(pool: Pool, publicClient: PublicClient): Promise<number>;
|
|
12
|
+
//# sourceMappingURL=costUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"costUtils.d.ts","sourceRoot":"","sources":["../../src/utils/costUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,IAAI,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAGxC;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAQhG"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPoolCostPercent = getPoolCostPercent;
|
|
4
|
+
const types_1 = require("../core/types");
|
|
5
|
+
const abis_1 = require("../core/abis");
|
|
6
|
+
const virtualPool_1 = require("../core/abis/virtualPool");
|
|
7
|
+
/**
|
|
8
|
+
* Calculate cost percentage for a pool based on its type
|
|
9
|
+
* Returns cost as a percentage (e.g., 0.5 = 0.5%)
|
|
10
|
+
*
|
|
11
|
+
* @param pool - The pool to calculate cost for
|
|
12
|
+
* @param publicClient - Viem public client for RPC calls
|
|
13
|
+
* @returns Cost percentage for the pool
|
|
14
|
+
*/
|
|
15
|
+
async function getPoolCostPercent(pool, publicClient) {
|
|
16
|
+
if (pool.poolType === types_1.PoolType.FPMM) {
|
|
17
|
+
return getFPMMCostPercent(pool.poolAddr, publicClient);
|
|
18
|
+
}
|
|
19
|
+
else if (pool.poolType === types_1.PoolType.Virtual) {
|
|
20
|
+
return getVirtualPoolCostPercent(pool.poolAddr, publicClient);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error('Invalid pool type');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Calculate cost for FPMM pools
|
|
28
|
+
* FPMM pools use lpFee + protocolFee in basis points (10000 = 100%)
|
|
29
|
+
*/
|
|
30
|
+
async function getFPMMCostPercent(poolAddress, publicClient) {
|
|
31
|
+
const [lpFee, protocolFee] = await Promise.all([
|
|
32
|
+
publicClient.readContract({
|
|
33
|
+
address: poolAddress,
|
|
34
|
+
abi: abis_1.FPMM_ABI,
|
|
35
|
+
functionName: 'lpFee',
|
|
36
|
+
}),
|
|
37
|
+
publicClient.readContract({
|
|
38
|
+
address: poolAddress,
|
|
39
|
+
abi: abis_1.FPMM_ABI,
|
|
40
|
+
functionName: 'protocolFee',
|
|
41
|
+
}),
|
|
42
|
+
]);
|
|
43
|
+
// Convert from basis points to percentage, rounded to 8dp for precision
|
|
44
|
+
const totalBasisPoints = Number(lpFee) + Number(protocolFee);
|
|
45
|
+
return Math.round((totalBasisPoints / 100) * 1e8) / 1e8;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Calculate cost for Virtual pools
|
|
49
|
+
*/
|
|
50
|
+
async function getVirtualPoolCostPercent(poolAddress, publicClient) {
|
|
51
|
+
const protocolFee = await publicClient.readContract({
|
|
52
|
+
address: poolAddress,
|
|
53
|
+
abi: virtualPool_1.VIRTUAL_POOL_ABI,
|
|
54
|
+
functionName: 'protocolFee',
|
|
55
|
+
});
|
|
56
|
+
// Convert from basis points to percentage, rounded to 8dp for precision
|
|
57
|
+
return Math.round((Number(protocolFee) / 100) * 1e8) / 1e8;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=costUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"costUtils.js","sourceRoot":"","sources":["../../src/utils/costUtils.ts"],"names":[],"mappings":";;AAaA,gDAQC;AArBD,yCAA8C;AAC9C,uCAAuC;AAEvC,0DAA2D;AAE3D;;;;;;;GAOG;AACI,KAAK,UAAU,kBAAkB,CAAC,IAAU,EAAE,YAA0B;IAC7E,IAAI,IAAI,CAAC,QAAQ,KAAK,gBAAQ,CAAC,IAAI,EAAE,CAAC;QACpC,OAAO,kBAAkB,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;IACxD,CAAC;SAAM,IAAI,IAAI,CAAC,QAAQ,KAAK,gBAAQ,CAAC,OAAO,EAAE,CAAC;QAC9C,OAAO,yBAAyB,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;IAC/D,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;IACtC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,kBAAkB,CAAC,WAAmB,EAAE,YAA0B;IAC/E,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC7C,YAAY,CAAC,YAAY,CAAC;YACxB,OAAO,EAAE,WAA4B;YACrC,GAAG,EAAE,eAAQ;YACb,YAAY,EAAE,OAAO;SACtB,CAAoB;QACrB,YAAY,CAAC,YAAY,CAAC;YACxB,OAAO,EAAE,WAA4B;YACrC,GAAG,EAAE,eAAQ;YACb,YAAY,EAAE,aAAa;SAC5B,CAAoB;KACtB,CAAC,CAAA;IAEF,wEAAwE;IACxE,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;IAC5D,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,gBAAgB,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;AACzD,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,yBAAyB,CAAC,WAAmB,EAAE,YAA0B;IACtF,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC;QAClD,OAAO,EAAE,WAA4B;QACrC,GAAG,EAAE,8BAAgB;QACrB,YAAY,EAAE,aAAa;KAC5B,CAAC,CAAA;IAEF,wEAAwE;IACxE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;AAC5D,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export * from './retry';
|
|
2
|
+
export * from './chainConfig';
|
|
3
|
+
export * from './routes';
|
|
4
|
+
export * from './sortUtils';
|
|
5
|
+
export * from './pathEncoder';
|
|
6
|
+
export * from './tokens';
|
|
7
|
+
export * from './rateFeed';
|
|
8
|
+
export * from './tradingLimits';
|
|
2
9
|
//# sourceMappingURL=index.d.ts.map
|