@mento-protocol/mento-sdk 3.2.7 → 3.3.0-beta.0
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 +14588 -0
- package/dist/cache/tokens.d.ts +68 -0
- package/dist/cache/tokens.js +514 -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 +125 -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 +34 -0
- package/dist/core/constants/chainId.d.ts +8 -0
- package/dist/core/constants/chainId.js +12 -0
- 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/core/errors/index.js +20 -0
- 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/core/types/borrow.js +3 -0
- package/dist/core/types/contractAddresses.d.ts +42 -0
- package/dist/core/types/contractAddresses.js +3 -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/core/types/provider.js +3 -0
- package/dist/core/types/route.d.ts +62 -0
- package/dist/core/types/route.js +3 -0
- package/dist/core/types/token.d.ts +21 -0
- package/dist/core/types/token.js +3 -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 +14583 -0
- package/dist/esm/cache/tokens.js +506 -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 +119 -0
- package/dist/esm/core/constants/borrowConstants.js +12 -0
- package/dist/esm/core/constants/borrowRegistries.js +29 -0
- package/dist/esm/core/constants/chainId.js +8 -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/borrow.js +1 -0
- package/dist/esm/core/types/contractAddresses.js +1 -0
- package/dist/esm/core/types/index.js +9 -0
- package/dist/esm/core/types/liquidity.js +1 -0
- package/dist/esm/core/types/pool.js +10 -0
- package/dist/esm/core/types/provider.js +1 -0
- package/dist/esm/core/types/route.js +1 -0
- package/dist/esm/core/types/token.js +1 -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 +139 -0
- 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 +181 -0
- package/dist/esm/services/liquidity/zapIn.js +131 -0
- package/dist/esm/services/liquidity/zapOut.js +248 -0
- package/dist/esm/services/pools/PoolService.js +204 -0
- package/dist/esm/services/pools/index.js +1 -0
- package/dist/esm/services/pools/poolDetails.js +209 -0
- package/dist/esm/services/pools/poolDiscovery.js +112 -0
- package/dist/esm/services/pools/rebalancePreview.js +181 -0
- package/dist/esm/services/quotes/QuoteService.js +85 -0
- package/dist/esm/services/quotes/index.js +1 -0
- package/dist/esm/services/routes/RouteService.js +268 -0
- package/dist/esm/services/routes/index.js +1 -0
- package/dist/esm/services/swap/SwapService.js +247 -0
- package/dist/esm/services/swap/index.js +1 -0
- package/dist/esm/services/tokens/index.js +1 -0
- package/dist/esm/services/tokens/tokenService.js +285 -0
- package/dist/esm/services/trading/TradingLimitsService.js +154 -0
- package/dist/esm/services/trading/TradingService.js +222 -0
- package/dist/esm/services/trading/index.js +2 -0
- package/dist/esm/utils/chainConfig.js +122 -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/utils/routeUtils.js +361 -0
- 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/services/borrow/index.js +20 -0
- 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/services/index.js +25 -0
- 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/services/liquidity/index.js +18 -0
- 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 +100 -0
- package/dist/services/liquidity/zapHelpers.js +192 -0
- package/dist/services/liquidity/zapIn.d.ts +18 -0
- package/dist/services/liquidity/zapIn.js +138 -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/services/pools/index.js +18 -0
- package/dist/services/pools/poolDetails.d.ts +13 -0
- package/dist/services/pools/poolDetails.js +216 -0
- package/dist/services/pools/poolDiscovery.d.ts +12 -0
- package/dist/services/pools/poolDiscovery.js +117 -0
- package/dist/services/pools/rebalancePreview.d.ts +5 -0
- package/dist/services/pools/rebalancePreview.js +186 -0
- package/dist/services/quotes/QuoteService.d.ts +51 -0
- package/dist/services/quotes/QuoteService.js +91 -0
- package/dist/services/quotes/index.d.ts +2 -0
- package/dist/services/quotes/index.js +18 -0
- package/dist/services/routes/RouteService.d.ts +117 -0
- package/dist/services/routes/RouteService.js +306 -0
- package/dist/services/routes/index.d.ts +2 -0
- package/dist/services/routes/index.js +18 -0
- package/dist/services/swap/SwapService.d.ts +198 -0
- package/dist/services/swap/SwapService.js +252 -0
- package/dist/services/swap/index.d.ts +2 -0
- package/dist/services/swap/index.js +18 -0
- package/dist/services/tokens/index.d.ts +2 -0
- package/dist/services/tokens/index.js +18 -0
- package/dist/services/tokens/tokenService.d.ts +55 -0
- package/dist/services/tokens/tokenService.js +290 -0
- package/dist/services/trading/TradingLimitsService.d.ts +38 -0
- package/dist/services/trading/TradingLimitsService.js +159 -0
- package/dist/services/trading/TradingService.d.ts +115 -0
- package/dist/services/trading/TradingService.js +227 -0
- package/dist/services/trading/index.d.ts +3 -0
- package/dist/services/trading/index.js +19 -0
- package/dist/utils/chainConfig.d.ts +16 -0
- package/dist/utils/chainConfig.js +127 -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/utils/routeUtils.d.ts +295 -0
- package/dist/utils/routeUtils.js +371 -0
- 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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MentoError } from './base';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when no tradable route exists between two tokens.
|
|
4
|
+
*/
|
|
5
|
+
export class RouteNotFoundError extends MentoError {
|
|
6
|
+
constructor(tokenIn, tokenOut) {
|
|
7
|
+
super(`No route found for tokens ${tokenIn} and ${tokenOut}. They may not have a tradable path.`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when no executable zap-out route exists for the requested amount.
|
|
12
|
+
*/
|
|
13
|
+
export class ZapOutRouteNotViableError extends MentoError {
|
|
14
|
+
constructor(poolAddress, tokenOut) {
|
|
15
|
+
super(`No viable zap-out route for pool ${poolAddress} to ${tokenOut}. ` +
|
|
16
|
+
'Try reducing the amount or removing liquidity in balanced mode.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './contractAddresses';
|
|
2
|
+
export * from './transaction';
|
|
3
|
+
export * from './token';
|
|
4
|
+
export * from './route';
|
|
5
|
+
export * from './pool';
|
|
6
|
+
export * from './tradingMode';
|
|
7
|
+
export * from './tradingLimits';
|
|
8
|
+
export * from './liquidity';
|
|
9
|
+
export * from './borrow';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of liquidity pools supported in the Mento protocol
|
|
3
|
+
*/
|
|
4
|
+
export var PoolType;
|
|
5
|
+
(function (PoolType) {
|
|
6
|
+
/** FPMM (Fixed Product Market Maker) pools - v3 native pools */
|
|
7
|
+
PoolType["FPMM"] = "FPMM";
|
|
8
|
+
/** Virtual pools - wrapper around v2 BiPoolManager exchanges */
|
|
9
|
+
PoolType["Virtual"] = "Virtual";
|
|
10
|
+
})(PoolType || (PoolType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading modes for rate feeds in the BreakerBox circuit breaker.
|
|
3
|
+
*
|
|
4
|
+
* The BreakerBox uses a bitmask approach where multiple breakers can
|
|
5
|
+
* contribute to the final trading mode. In practice:
|
|
6
|
+
* - 0 = Bidirectional (trading enabled)
|
|
7
|
+
* - Any non-zero value = Trading suspended
|
|
8
|
+
*
|
|
9
|
+
* For SDK consumers, use isTradingEnabled() helper to check if trading
|
|
10
|
+
* is allowed.
|
|
11
|
+
*/
|
|
12
|
+
export var TradingMode;
|
|
13
|
+
(function (TradingMode) {
|
|
14
|
+
/** Bidirectional trading is enabled (normal operation) */
|
|
15
|
+
TradingMode[TradingMode["BIDIRECTIONAL"] = 0] = "BIDIRECTIONAL";
|
|
16
|
+
/** Trading is suspended (circuit breaker tripped) - any non-zero value */
|
|
17
|
+
TradingMode[TradingMode["SUSPENDED"] = 1] = "SUSPENDED";
|
|
18
|
+
})(TradingMode || (TradingMode = {}));
|
|
19
|
+
/**
|
|
20
|
+
* Check if trading is enabled for a given trading mode.
|
|
21
|
+
* @param mode - The trading mode value from BreakerBox
|
|
22
|
+
* @returns true if trading is enabled (mode === 0)
|
|
23
|
+
*/
|
|
24
|
+
export function isTradingEnabled(mode) {
|
|
25
|
+
return mode === TradingMode.BIDIRECTIONAL;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createPublicClient, http } from 'viem';
|
|
2
|
+
import { ChainId } from './core/constants/chainId';
|
|
3
|
+
import { getContractAddress } from './core/constants/addresses';
|
|
4
|
+
import { getDefaultRpcUrl, getChainConfig } from './utils/chainConfig';
|
|
5
|
+
import { TokenService } from './services/tokens';
|
|
6
|
+
import { PoolService } from './services/pools';
|
|
7
|
+
import { RouteService } from './services/routes';
|
|
8
|
+
import { QuoteService } from './services/quotes';
|
|
9
|
+
import { SwapService } from './services/swap';
|
|
10
|
+
import { TradingService } from './services/trading';
|
|
11
|
+
import { LiquidityService } from './services/liquidity';
|
|
12
|
+
import { BorrowService } from './services/borrow';
|
|
13
|
+
const DEFAULT_HTTP_BATCH_OPTIONS = {
|
|
14
|
+
batchSize: 1000,
|
|
15
|
+
wait: 8,
|
|
16
|
+
};
|
|
17
|
+
const DEFAULT_MULTICALL_BATCH_OPTIONS = {
|
|
18
|
+
batchSize: 1024,
|
|
19
|
+
wait: 8,
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @class Mento
|
|
23
|
+
* @description The main class for the Mento SDK. Initializes a viem PublicClient internally
|
|
24
|
+
* and provides a public API for interacting with the Mento Protocol.
|
|
25
|
+
* @dev example usage:
|
|
26
|
+
* const mento = await Mento.create(ChainId.CELO);
|
|
27
|
+
* // or with custom RPC URL
|
|
28
|
+
* const mento = await Mento.create(ChainId.CELO, 'https://custom-rpc-url.com');
|
|
29
|
+
* // or with an existing viem PublicClient
|
|
30
|
+
* const mento = await Mento.create(ChainId.CELO, myPublicClient);
|
|
31
|
+
*
|
|
32
|
+
* // Get all stable tokens
|
|
33
|
+
* const stableTokens = await mento.tokens.getStableTokens();
|
|
34
|
+
*
|
|
35
|
+
* // Get all collateral assets
|
|
36
|
+
* const collateralAssets = await mento.tokens.getCollateralAssets();
|
|
37
|
+
*
|
|
38
|
+
* // Get all pools
|
|
39
|
+
* const pools = await mento.pools.getPools();
|
|
40
|
+
*
|
|
41
|
+
* // Find a route between tokens
|
|
42
|
+
* const route = await mento.routes.findRoute(USDm, CELO);
|
|
43
|
+
*
|
|
44
|
+
* // Get a quote for a swap
|
|
45
|
+
* const amountOut = await mento.quotes.getAmountOut(USDm, CELO, amountIn);
|
|
46
|
+
*
|
|
47
|
+
* // Build swap parameters
|
|
48
|
+
* const swapDetails = await mento.swap.buildSwapParams(USDm, CELO, amountIn, recipient, { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) });
|
|
49
|
+
*
|
|
50
|
+
* // Check if a pair is tradable (circuit breaker check)
|
|
51
|
+
* const isTradable = await mento.trading.isPairTradable(USDm, CELO);
|
|
52
|
+
*
|
|
53
|
+
* // Get trading limits for a pool
|
|
54
|
+
* const limits = await mento.trading.getPoolTradingLimits(pool);
|
|
55
|
+
*
|
|
56
|
+
* // Get full tradability status (circuit breaker + limits)
|
|
57
|
+
* const status = await mento.trading.getPoolTradabilityStatus(pool);
|
|
58
|
+
*
|
|
59
|
+
* // Add liquidity to a pool
|
|
60
|
+
* const { approval0, approval1, addLiquidity } = await mento.liquidity.buildAddLiquidityTransaction(
|
|
61
|
+
* poolAddress, amount0, amount1, recipient, owner, { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) }
|
|
62
|
+
* );
|
|
63
|
+
*
|
|
64
|
+
* // Add liquidity using a single token (zap in)
|
|
65
|
+
* const { approval, zapIn } = await mento.liquidity.buildZapInTransaction(
|
|
66
|
+
* poolAddress, tokenIn, amountIn, 0.5, recipient, owner, { slippageTolerance: 0.5, deadline: deadlineFromMinutes(5) }
|
|
67
|
+
* );
|
|
68
|
+
*/
|
|
69
|
+
export class Mento {
|
|
70
|
+
constructor(chainId, tokens, pools, routes, quotes, swap, trading, liquidity, borrow) {
|
|
71
|
+
this.chainId = chainId;
|
|
72
|
+
this.tokens = tokens;
|
|
73
|
+
this.pools = pools;
|
|
74
|
+
this.routes = routes;
|
|
75
|
+
this.quotes = quotes;
|
|
76
|
+
this.swap = swap;
|
|
77
|
+
this.trading = trading;
|
|
78
|
+
this.liquidity = liquidity;
|
|
79
|
+
this.borrow = borrow;
|
|
80
|
+
}
|
|
81
|
+
static async create(chainId, rpcUrlOrClient, options) {
|
|
82
|
+
// Validate chainId is supported
|
|
83
|
+
const supportedChainIds = Object.values(ChainId).filter((v) => typeof v === 'number');
|
|
84
|
+
if (!supportedChainIds.includes(chainId)) {
|
|
85
|
+
throw new Error(`ChainId ${chainId} is not supported. ` +
|
|
86
|
+
`Supported chains: ${supportedChainIds.map((id) => `${id} (${ChainId[id]})`).join(', ')}`);
|
|
87
|
+
}
|
|
88
|
+
let publicClient;
|
|
89
|
+
if (rpcUrlOrClient && typeof rpcUrlOrClient !== 'string') {
|
|
90
|
+
publicClient = rpcUrlOrClient;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const transport = http(rpcUrlOrClient || getDefaultRpcUrl(chainId), {
|
|
94
|
+
batch: options?.httpBatch === false
|
|
95
|
+
? false
|
|
96
|
+
: {
|
|
97
|
+
...DEFAULT_HTTP_BATCH_OPTIONS,
|
|
98
|
+
...(options?.httpBatch ?? {}),
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
publicClient = createPublicClient({
|
|
102
|
+
batch: {
|
|
103
|
+
multicall: options?.multicallBatch === false
|
|
104
|
+
? false
|
|
105
|
+
: {
|
|
106
|
+
...DEFAULT_MULTICALL_BATCH_OPTIONS,
|
|
107
|
+
...(options?.multicallBatch ?? {}),
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
chain: getChainConfig(chainId),
|
|
111
|
+
transport,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const tokenService = new TokenService(publicClient, chainId);
|
|
115
|
+
const poolService = new PoolService(publicClient, chainId);
|
|
116
|
+
const routeService = new RouteService(publicClient, chainId, poolService);
|
|
117
|
+
const quoteService = new QuoteService(publicClient, chainId, routeService);
|
|
118
|
+
const swapService = new SwapService(publicClient, chainId, routeService, quoteService);
|
|
119
|
+
const tradingService = new TradingService(publicClient, chainId, routeService);
|
|
120
|
+
const liquidityService = new LiquidityService(publicClient, chainId, poolService, routeService);
|
|
121
|
+
const borrowService = new BorrowService(publicClient, chainId);
|
|
122
|
+
// Return new mento
|
|
123
|
+
return new Mento(chainId, tokenService, poolService, routeService, quoteService, swapService, tradingService, liquidityService, borrowService);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get the address of a contract for the current chain
|
|
127
|
+
* @param contractName - The contract name
|
|
128
|
+
* @returns The contract address
|
|
129
|
+
*/
|
|
130
|
+
getContractAddress(contractName) {
|
|
131
|
+
return getContractAddress(this.chainId, contractName);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export * from './core/constants';
|
|
135
|
+
export * from './core/errors';
|
|
136
|
+
export * from './core/types';
|
|
137
|
+
export * from './core/abis';
|
|
138
|
+
export * from './services';
|
|
139
|
+
export * from './utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|