@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,60 @@
|
|
|
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
|
+
const multicall_1 = require("./multicall");
|
|
8
|
+
/**
|
|
9
|
+
* Calculate cost percentage for a pool based on its type
|
|
10
|
+
* Returns cost as a percentage (e.g., 0.5 = 0.5%)
|
|
11
|
+
*
|
|
12
|
+
* @param pool - The pool to calculate cost for
|
|
13
|
+
* @param publicClient - Viem public client for RPC calls
|
|
14
|
+
* @returns Cost percentage for the pool
|
|
15
|
+
*/
|
|
16
|
+
async function getPoolCostPercent(pool, publicClient) {
|
|
17
|
+
if (pool.poolType === types_1.PoolType.FPMM) {
|
|
18
|
+
return getFPMMCostPercent(pool.poolAddr, publicClient);
|
|
19
|
+
}
|
|
20
|
+
else if (pool.poolType === types_1.PoolType.Virtual) {
|
|
21
|
+
return getVirtualPoolCostPercent(pool.poolAddr, publicClient);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error('Invalid pool type');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Calculate cost for FPMM pools
|
|
29
|
+
* FPMM pools use lpFee + protocolFee in basis points (10000 = 100%)
|
|
30
|
+
*/
|
|
31
|
+
async function getFPMMCostPercent(poolAddress, publicClient) {
|
|
32
|
+
const results = await (0, multicall_1.multicall)(publicClient, [
|
|
33
|
+
{ address: poolAddress, abi: abis_1.FPMM_ABI, functionName: 'lpFee' },
|
|
34
|
+
{ address: poolAddress, abi: abis_1.FPMM_ABI, functionName: 'protocolFee' },
|
|
35
|
+
]);
|
|
36
|
+
if (results[0].status === 'failure' || results[1].status === 'failure') {
|
|
37
|
+
throw new Error(`Failed to read fees for pool ${poolAddress}`);
|
|
38
|
+
}
|
|
39
|
+
const lpFee = results[0].result;
|
|
40
|
+
const protocolFee = results[1].result;
|
|
41
|
+
// Convert from basis points to percentage using BigInt arithmetic to avoid precision loss
|
|
42
|
+
const totalBasisPoints = lpFee + protocolFee;
|
|
43
|
+
const scaled = totalBasisPoints * 1000000n;
|
|
44
|
+
return Number(scaled / 100n) / 1e6;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Calculate cost for Virtual pools
|
|
48
|
+
*/
|
|
49
|
+
async function getVirtualPoolCostPercent(poolAddress, publicClient) {
|
|
50
|
+
const results = await (0, multicall_1.multicall)(publicClient, [
|
|
51
|
+
{ address: poolAddress, abi: virtualPool_1.VIRTUAL_POOL_ABI, functionName: 'protocolFee' },
|
|
52
|
+
]);
|
|
53
|
+
if (results[0].status === 'failure') {
|
|
54
|
+
throw new Error(`Failed to read protocolFee for pool ${poolAddress}`);
|
|
55
|
+
}
|
|
56
|
+
// Convert from basis points to percentage using BigInt arithmetic to avoid precision loss
|
|
57
|
+
const scaled = results[0].result * 1000000n;
|
|
58
|
+
return Number(scaled / 100n) / 1e6;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=costUtils.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a deadline timestamp from a duration in minutes.
|
|
3
|
+
*
|
|
4
|
+
* @param minutes - Number of minutes from now
|
|
5
|
+
* @returns Unix timestamp as bigint suitable for router contract deadline parameter
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { deadlineFromMinutes } from '@mento-protocol/mento-sdk'
|
|
10
|
+
*
|
|
11
|
+
* // 5 minute deadline
|
|
12
|
+
* const deadline = deadlineFromMinutes(5)
|
|
13
|
+
*
|
|
14
|
+
* const swap = await mento.swap.buildSwapParams(
|
|
15
|
+
* tokenIn, tokenOut, amountIn, recipient,
|
|
16
|
+
* { slippageTolerance: 0.5, deadline }
|
|
17
|
+
* )
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function deadlineFromMinutes(minutes: number): bigint;
|
|
21
|
+
//# sourceMappingURL=deadline.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deadlineFromMinutes = deadlineFromMinutes;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a deadline timestamp from a duration in minutes.
|
|
6
|
+
*
|
|
7
|
+
* @param minutes - Number of minutes from now
|
|
8
|
+
* @returns Unix timestamp as bigint suitable for router contract deadline parameter
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { deadlineFromMinutes } from '@mento-protocol/mento-sdk'
|
|
13
|
+
*
|
|
14
|
+
* // 5 minute deadline
|
|
15
|
+
* const deadline = deadlineFromMinutes(5)
|
|
16
|
+
*
|
|
17
|
+
* const swap = await mento.swap.buildSwapParams(
|
|
18
|
+
* tokenIn, tokenOut, amountIn, recipient,
|
|
19
|
+
* { slippageTolerance: 0.5, deadline }
|
|
20
|
+
* )
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function deadlineFromMinutes(minutes) {
|
|
24
|
+
return BigInt(Date.now()) / 1000n + BigInt(minutes * 60);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=deadline.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
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';
|
|
9
|
+
export * from './deadline';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
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("./retry"), exports);
|
|
18
|
+
__exportStar(require("./chainConfig"), exports);
|
|
19
|
+
__exportStar(require("./routes"), exports);
|
|
20
|
+
__exportStar(require("./sortUtils"), exports);
|
|
21
|
+
__exportStar(require("./pathEncoder"), exports);
|
|
22
|
+
__exportStar(require("./tokens"), exports);
|
|
23
|
+
__exportStar(require("./rateFeed"), exports);
|
|
24
|
+
__exportStar(require("./tradingLimits"), exports);
|
|
25
|
+
__exportStar(require("./deadline"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Abi, PublicClient } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Standard Multicall3 contract address, deployed at the same address on all EVM chains.
|
|
4
|
+
* https://www.multicall3.com/
|
|
5
|
+
*/
|
|
6
|
+
export declare const MULTICALL3_ADDRESS: "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
7
|
+
type MulticallResult = {
|
|
8
|
+
status: 'success';
|
|
9
|
+
result: unknown;
|
|
10
|
+
} | {
|
|
11
|
+
status: 'failure';
|
|
12
|
+
error: Error;
|
|
13
|
+
};
|
|
14
|
+
interface ContractCall {
|
|
15
|
+
address: `0x${string}`;
|
|
16
|
+
abi: Abi | readonly unknown[];
|
|
17
|
+
functionName: string;
|
|
18
|
+
args?: readonly unknown[];
|
|
19
|
+
}
|
|
20
|
+
interface MulticallOptions {
|
|
21
|
+
allowFailure?: boolean;
|
|
22
|
+
batchSize?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Wrapper around viem's multicall that explicitly provides the Multicall3 address.
|
|
26
|
+
* This ensures multicall works even when the PublicClient was created without a `chain` config.
|
|
27
|
+
*/
|
|
28
|
+
export declare function multicall(publicClient: PublicClient, contracts: ContractCall[], options?: MulticallOptions): Promise<MulticallResult[]>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=multicall.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MULTICALL3_ADDRESS = void 0;
|
|
4
|
+
exports.multicall = multicall;
|
|
5
|
+
/**
|
|
6
|
+
* Standard Multicall3 contract address, deployed at the same address on all EVM chains.
|
|
7
|
+
* https://www.multicall3.com/
|
|
8
|
+
*/
|
|
9
|
+
exports.MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
|
|
10
|
+
/**
|
|
11
|
+
* Wrapper around viem's multicall that explicitly provides the Multicall3 address.
|
|
12
|
+
* This ensures multicall works even when the PublicClient was created without a `chain` config.
|
|
13
|
+
*/
|
|
14
|
+
async function multicall(publicClient, contracts, options = {}) {
|
|
15
|
+
const { allowFailure = true, batchSize } = options;
|
|
16
|
+
const client = publicClient;
|
|
17
|
+
if (typeof client.multicall !== 'function') {
|
|
18
|
+
if (typeof client.readContract !== 'function') {
|
|
19
|
+
throw new Error('Public client does not support multicall or readContract');
|
|
20
|
+
}
|
|
21
|
+
return Promise.all(contracts.map(async (contract) => {
|
|
22
|
+
try {
|
|
23
|
+
const result = await client.readContract({
|
|
24
|
+
...contract,
|
|
25
|
+
args: contract.args ?? [],
|
|
26
|
+
});
|
|
27
|
+
return { status: 'success', result };
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (!allowFailure) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
status: 'failure',
|
|
35
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
const raw = await client.multicall({
|
|
41
|
+
allowFailure,
|
|
42
|
+
batchSize,
|
|
43
|
+
contracts: contracts,
|
|
44
|
+
multicallAddress: exports.MULTICALL3_ADDRESS,
|
|
45
|
+
});
|
|
46
|
+
const results = raw;
|
|
47
|
+
if (!allowFailure) {
|
|
48
|
+
return results.map((result) => ({ status: 'success', result }));
|
|
49
|
+
}
|
|
50
|
+
return results;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=multicall.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { Pool } from '../core/types';
|
|
3
|
+
/**
|
|
4
|
+
* Route structure expected by the Router contract's getAmountsOut and swapTokensForTokens functions
|
|
5
|
+
*/
|
|
6
|
+
export interface RouterRoute {
|
|
7
|
+
from: Address;
|
|
8
|
+
to: Address;
|
|
9
|
+
factory: Address;
|
|
10
|
+
}
|
|
11
|
+
export type ReadonlyRouterRoutes = readonly {
|
|
12
|
+
from: Address;
|
|
13
|
+
to: Address;
|
|
14
|
+
factory: Address;
|
|
15
|
+
}[];
|
|
16
|
+
/**
|
|
17
|
+
* Converts a route path to the format expected by the Router contract.
|
|
18
|
+
* Used by both QuoteService (getAmountsOut) and SwapService (swapTokensForTokens).
|
|
19
|
+
*
|
|
20
|
+
* @param path - The route path (array of pools)
|
|
21
|
+
* @param tokenIn - The input token address (determines swap direction)
|
|
22
|
+
* @param _tokenOut - The output token address (unused but kept for API clarity)
|
|
23
|
+
* @returns Array of RouterRoute objects for the contract call
|
|
24
|
+
* @throws {Error} If path is empty, too long, or contains invalid pools
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const route = await routeService.findRoute(USDm, CELO)
|
|
29
|
+
* const routerRoutes = encodeRoutePath(route.path, USDm, CELO)
|
|
30
|
+
* // routerRoutes can now be passed to Router.getAmountsOut or Router.swapTokensForTokens
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function encodeRoutePath(path: Pool[], tokenIn: Address, _tokenOut: Address): RouterRoute[];
|
|
34
|
+
//# sourceMappingURL=pathEncoder.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeRoutePath = encodeRoutePath;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a route path to the format expected by the Router contract.
|
|
6
|
+
* Used by both QuoteService (getAmountsOut) and SwapService (swapTokensForTokens).
|
|
7
|
+
*
|
|
8
|
+
* @param path - The route path (array of pools)
|
|
9
|
+
* @param tokenIn - The input token address (determines swap direction)
|
|
10
|
+
* @param _tokenOut - The output token address (unused but kept for API clarity)
|
|
11
|
+
* @returns Array of RouterRoute objects for the contract call
|
|
12
|
+
* @throws {Error} If path is empty, too long, or contains invalid pools
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const route = await routeService.findRoute(USDm, CELO)
|
|
17
|
+
* const routerRoutes = encodeRoutePath(route.path, USDm, CELO)
|
|
18
|
+
* // routerRoutes can now be passed to Router.getAmountsOut or Router.swapTokensForTokens
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function encodeRoutePath(path, tokenIn, _tokenOut) {
|
|
22
|
+
// Validate path is not empty
|
|
23
|
+
if (!path || path.length === 0) {
|
|
24
|
+
throw new Error('Internal error: Route path is empty. This should not happen - routes are validated before encoding.');
|
|
25
|
+
}
|
|
26
|
+
// Validate all pools have required structure
|
|
27
|
+
for (let i = 0; i < path.length; i++) {
|
|
28
|
+
const pool = path[i];
|
|
29
|
+
if (!pool.token0 || !pool.token1 || !pool.factoryAddr) {
|
|
30
|
+
throw new Error(`Invalid pool structure at index ${i}: missing required fields. ` +
|
|
31
|
+
`Pool must have token0, token1, and factoryAddr. ` +
|
|
32
|
+
`Got: ${JSON.stringify(pool)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const routes = [];
|
|
36
|
+
const tokenInLower = tokenIn.toLowerCase();
|
|
37
|
+
// Check if we need to reverse the path
|
|
38
|
+
// The path is stored in canonical order, but we may need to traverse it backwards
|
|
39
|
+
const firstPool = path[0];
|
|
40
|
+
const startsWithTokenIn = firstPool.token0.toLowerCase() === tokenInLower || firstPool.token1.toLowerCase() === tokenInLower;
|
|
41
|
+
// If tokenIn isn't in the first pool, reverse the path
|
|
42
|
+
const orderedPath = startsWithTokenIn ? path : [...path].reverse();
|
|
43
|
+
let currentTokenIn = tokenInLower;
|
|
44
|
+
for (const pool of orderedPath) {
|
|
45
|
+
const token0 = pool.token0.toLowerCase();
|
|
46
|
+
const token1 = pool.token1.toLowerCase();
|
|
47
|
+
// Determine direction: which token is the input for this hop?
|
|
48
|
+
let from;
|
|
49
|
+
let to;
|
|
50
|
+
if (currentTokenIn === token0) {
|
|
51
|
+
from = pool.token0;
|
|
52
|
+
to = pool.token1;
|
|
53
|
+
}
|
|
54
|
+
else if (currentTokenIn === token1) {
|
|
55
|
+
from = pool.token1;
|
|
56
|
+
to = pool.token0;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error(`Route encoding error: Token ${currentTokenIn} not found in pool ${pool.poolAddr}. ` +
|
|
60
|
+
`Pool contains tokens: ${token0}, ${token1}. ` +
|
|
61
|
+
`This indicates the route path is invalid or tokens don't form a connected path.`);
|
|
62
|
+
}
|
|
63
|
+
routes.push({
|
|
64
|
+
from,
|
|
65
|
+
to,
|
|
66
|
+
factory: pool.factoryAddr,
|
|
67
|
+
});
|
|
68
|
+
// The output of this hop becomes the input of the next hop
|
|
69
|
+
currentTokenIn = to.toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
return routes;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=pathEncoder.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the rate feed ID from a rate feed identifier string.
|
|
3
|
+
* Follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
4
|
+
*
|
|
5
|
+
* @param rateFeed - The rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
6
|
+
* @returns The computed rate feed address as a hex string
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const rateFeedId = toRateFeedId('EURUSD')
|
|
11
|
+
* // Returns the computed address for the EURUSD rate feed
|
|
12
|
+
*
|
|
13
|
+
* const relayedRateFeedId = toRateFeedId('relayed:COPUSD')
|
|
14
|
+
* // Returns the computed address for the relayed COPUSD rate feed
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function toRateFeedId(rateFeed: string): `0x${string}`;
|
|
18
|
+
//# sourceMappingURL=rateFeed.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRateFeedId = toRateFeedId;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
/**
|
|
6
|
+
* Computes the rate feed ID from a rate feed identifier string.
|
|
7
|
+
* Follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
8
|
+
*
|
|
9
|
+
* @param rateFeed - The rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
10
|
+
* @returns The computed rate feed address as a hex string
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const rateFeedId = toRateFeedId('EURUSD')
|
|
15
|
+
* // Returns the computed address for the EURUSD rate feed
|
|
16
|
+
*
|
|
17
|
+
* const relayedRateFeedId = toRateFeedId('relayed:COPUSD')
|
|
18
|
+
* // Returns the computed address for the relayed COPUSD rate feed
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function toRateFeedId(rateFeed) {
|
|
22
|
+
const hashedBytes = (0, viem_1.keccak256)((0, viem_1.toBytes)(rateFeed));
|
|
23
|
+
const hashAsBigInt = BigInt(hashedBytes);
|
|
24
|
+
const maskedToUint160 = hashAsBigInt & ((1n << 160n) - 1n);
|
|
25
|
+
return `0x${maskedToUint160.toString(16).padStart(40, '0')}`;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=rateFeed.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface RetryOptions {
|
|
2
|
+
maxAttempts?: number;
|
|
3
|
+
initialDelayMs?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Retry an operation a number of times with exponential backoff.
|
|
7
|
+
* @param operation - The operation to retry
|
|
8
|
+
* @param options - The retry options
|
|
9
|
+
* @returns The result of the operation
|
|
10
|
+
*/
|
|
11
|
+
export declare function retryOperation<T>(operation: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
12
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retryOperation = retryOperation;
|
|
4
|
+
/**
|
|
5
|
+
* Retry an operation a number of times with exponential backoff.
|
|
6
|
+
* @param operation - The operation to retry
|
|
7
|
+
* @param options - The retry options
|
|
8
|
+
* @returns The result of the operation
|
|
9
|
+
*/
|
|
10
|
+
async function retryOperation(operation, options = {}) {
|
|
11
|
+
const maxAttempts = options.maxAttempts ?? 3;
|
|
12
|
+
const delayMs = options.initialDelayMs ?? 1000;
|
|
13
|
+
let lastError;
|
|
14
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
15
|
+
try {
|
|
16
|
+
return await operation();
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
lastError = error;
|
|
20
|
+
if (attempt === maxAttempts)
|
|
21
|
+
break;
|
|
22
|
+
// Exponential backoff
|
|
23
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs * attempt));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`Operation failed after ${maxAttempts} attempts: ${lastError?.message}`);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=retry.js.map
|