@mento-protocol/mento-sdk 1.15.5 → 1.16.1-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/cjs/constants/tokens.44787.d.ts +2 -0
- package/dist/cjs/constants/tokens.44787.js +128 -0
- package/dist/cjs/constants/tradablePairs.44787.d.ts +2 -0
- package/dist/cjs/constants/tradablePairs.44787.js +7391 -0
- package/dist/cjs/enums/index.d.ts +2 -1
- package/dist/cjs/enums/index.js +2 -1
- package/dist/cjs/enums/tradingMode.d.ts +17 -0
- package/dist/cjs/enums/tradingMode.js +21 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/mento.d.ts +15 -0
- package/dist/cjs/mento.js +38 -0
- package/dist/cjs/utils.d.ts +7 -0
- package/dist/cjs/utils.js +20 -1
- package/dist/esm/constants/tokens.44787.d.ts +2 -0
- package/dist/esm/constants/tokens.44787.js +125 -0
- package/dist/esm/constants/tradablePairs.44787.d.ts +2 -0
- package/dist/esm/constants/tradablePairs.44787.js +7388 -0
- package/dist/esm/enums/index.d.ts +2 -1
- package/dist/esm/enums/index.js +2 -1
- package/dist/esm/enums/tradingMode.d.ts +17 -0
- package/dist/esm/enums/tradingMode.js +18 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/mento.d.ts +15 -0
- package/dist/esm/mento.js +38 -0
- package/dist/esm/utils.d.ts +7 -0
- package/dist/esm/utils.js +19 -1
- package/package.json +1 -1
package/dist/esm/enums/index.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading modes for rate feeds in the BreakerBox
|
|
3
|
+
*/
|
|
4
|
+
export declare enum TradingMode {
|
|
5
|
+
/**
|
|
6
|
+
* Bidirectional trading is enabled
|
|
7
|
+
*/
|
|
8
|
+
BIDIRECTIONAL = 0,
|
|
9
|
+
/**
|
|
10
|
+
* Trading is temporarily halted (circuit breaker tripped)
|
|
11
|
+
*/
|
|
12
|
+
HALTED = 1,
|
|
13
|
+
/**
|
|
14
|
+
* Trading is permanently disabled
|
|
15
|
+
*/
|
|
16
|
+
DISABLED = 2
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading modes for rate feeds in the BreakerBox
|
|
3
|
+
*/
|
|
4
|
+
export var TradingMode;
|
|
5
|
+
(function (TradingMode) {
|
|
6
|
+
/**
|
|
7
|
+
* Bidirectional trading is enabled
|
|
8
|
+
*/
|
|
9
|
+
TradingMode[TradingMode["BIDIRECTIONAL"] = 0] = "BIDIRECTIONAL";
|
|
10
|
+
/**
|
|
11
|
+
* Trading is temporarily halted (circuit breaker tripped)
|
|
12
|
+
*/
|
|
13
|
+
TradingMode[TradingMode["HALTED"] = 1] = "HALTED";
|
|
14
|
+
/**
|
|
15
|
+
* Trading is permanently disabled
|
|
16
|
+
*/
|
|
17
|
+
TradingMode[TradingMode["DISABLED"] = 2] = "DISABLED";
|
|
18
|
+
})(TradingMode || (TradingMode = {}));
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/mento.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Address, TradingLimit, TradingLimitsConfig, TradingLimitsState } from '
|
|
|
4
4
|
import { Identifier } from './constants/addresses';
|
|
5
5
|
import { TokenSymbol } from './constants/tokens';
|
|
6
6
|
import { TradablePairWithSpread } from './constants/tradablePairs';
|
|
7
|
+
import { TradingMode } from './enums';
|
|
7
8
|
export { TokenSymbol } from './constants/tokens';
|
|
8
9
|
export interface Exchange {
|
|
9
10
|
providerAddr: Address;
|
|
@@ -245,6 +246,20 @@ export declare class Mento {
|
|
|
245
246
|
* @returns true if trading is enabled in the given mode, false otherwise
|
|
246
247
|
*/
|
|
247
248
|
isTradingEnabled(exchangeId: string): Promise<boolean>;
|
|
249
|
+
/**
|
|
250
|
+
* Returns the current trading mode for a given rate feed
|
|
251
|
+
* @param rateFeedId the address of the rate feed
|
|
252
|
+
* @returns the current trading mode (BIDIRECTIONAL, HALTED, or DISABLED)
|
|
253
|
+
*/
|
|
254
|
+
getRateFeedTradingMode(rateFeedId: Address): Promise<TradingMode>;
|
|
255
|
+
/**
|
|
256
|
+
* Checks if a trading pair is currently tradable (i.e., all rate feeds in the path are in BIDIRECTIONAL mode)
|
|
257
|
+
* For multi-hop routes (e.g., CELO → cUSD → USDT), checks that all intermediate rate feeds are tradable
|
|
258
|
+
* @param tokenIn the address of the token to sell
|
|
259
|
+
* @param tokenOut the address of the token to buy
|
|
260
|
+
* @returns true if the pair is tradable (all rate feeds in BIDIRECTIONAL mode), false otherwise
|
|
261
|
+
*/
|
|
262
|
+
isPairTradable(tokenIn: Address, tokenOut: Address): Promise<boolean>;
|
|
248
263
|
/**
|
|
249
264
|
* Return the trading limits for a given exchange id. Each limit is an object with the following fields:
|
|
250
265
|
* asset: the address of the asset with the limit
|
package/dist/esm/mento.js
CHANGED
|
@@ -15,6 +15,7 @@ import { strict as assert } from 'assert';
|
|
|
15
15
|
import { IMentoRouter__factory } from 'mento-router-ts';
|
|
16
16
|
import { getAddress } from './constants/addresses';
|
|
17
17
|
import { getCachedTradablePairs, } from './constants/tradablePairs';
|
|
18
|
+
import { TradingMode } from './enums';
|
|
18
19
|
import { buildConnectivityStructures, generateAllRoutes, selectOptimalRoutes, } from './routeUtils';
|
|
19
20
|
// Re-export TokenSymbol for use in auto-generated files and consuming packages
|
|
20
21
|
export { TokenSymbol } from './constants/tokens';
|
|
@@ -567,6 +568,43 @@ export class Mento {
|
|
|
567
568
|
return currentMode == BI_DIRECTIONAL_TRADING_MODE;
|
|
568
569
|
});
|
|
569
570
|
}
|
|
571
|
+
/**
|
|
572
|
+
* Returns the current trading mode for a given rate feed
|
|
573
|
+
* @param rateFeedId the address of the rate feed
|
|
574
|
+
* @returns the current trading mode (BIDIRECTIONAL, HALTED, or DISABLED)
|
|
575
|
+
*/
|
|
576
|
+
getRateFeedTradingMode(rateFeedId) {
|
|
577
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
578
|
+
const breakerBoxAddr = yield this.getAddress('BreakerBox');
|
|
579
|
+
const breakerBox = IBreakerBox__factory.connect(breakerBoxAddr, this.signerOrProvider);
|
|
580
|
+
const currentMode = yield breakerBox.getRateFeedTradingMode(rateFeedId);
|
|
581
|
+
return currentMode;
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Checks if a trading pair is currently tradable (i.e., all rate feeds in the path are in BIDIRECTIONAL mode)
|
|
586
|
+
* For multi-hop routes (e.g., CELO → cUSD → USDT), checks that all intermediate rate feeds are tradable
|
|
587
|
+
* @param tokenIn the address of the token to sell
|
|
588
|
+
* @param tokenOut the address of the token to buy
|
|
589
|
+
* @returns true if the pair is tradable (all rate feeds in BIDIRECTIONAL mode), false otherwise
|
|
590
|
+
*/
|
|
591
|
+
isPairTradable(tokenIn, tokenOut) {
|
|
592
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
593
|
+
// Find the tradable pair (which includes the routing path)
|
|
594
|
+
const pair = yield this.findPairForTokens(tokenIn, tokenOut);
|
|
595
|
+
// For each hop in the path, check if the rate feed is tradable
|
|
596
|
+
const biPoolManager = BiPoolManager__factory.connect(pair.path[0].providerAddr, this.signerOrProvider);
|
|
597
|
+
// Get all rate feed IDs for each hop in the path
|
|
598
|
+
const rateFeedChecks = yield Promise.all(pair.path.map((hop) => __awaiter(this, void 0, void 0, function* () {
|
|
599
|
+
const exchangeConfig = yield biPoolManager.getPoolExchange(hop.id);
|
|
600
|
+
const rateFeedId = exchangeConfig.config.referenceRateFeedID;
|
|
601
|
+
const tradingMode = yield this.getRateFeedTradingMode(rateFeedId);
|
|
602
|
+
return tradingMode === TradingMode.BIDIRECTIONAL;
|
|
603
|
+
})));
|
|
604
|
+
// All rate feeds must be in BIDIRECTIONAL mode for the pair to be tradable
|
|
605
|
+
return rateFeedChecks.every((isTradable) => isTradable);
|
|
606
|
+
});
|
|
607
|
+
}
|
|
570
608
|
/**
|
|
571
609
|
* Return the trading limits for a given exchange id. Each limit is an object with the following fields:
|
|
572
610
|
* asset: the address of the asset with the limit
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -71,3 +71,10 @@ export declare function getTokenAddress(symbol: TokenSymbol, chainId: number): s
|
|
|
71
71
|
* @returns The token object or undefined if not found
|
|
72
72
|
*/
|
|
73
73
|
export declare function findTokenBySymbol(symbol: string, chainId: number): Token | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Computes the rate feed ID from a rate feed identifier string.
|
|
76
|
+
* This follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
77
|
+
* @param rateFeed the rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
78
|
+
* @returns the computed rate feed address
|
|
79
|
+
*/
|
|
80
|
+
export declare function toRateFeedId(rateFeed: string): Address;
|
package/dist/esm/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { Contract, providers, Signer } from 'ethers';
|
|
10
|
+
import { Contract, ethers, providers, Signer } from 'ethers';
|
|
11
11
|
import { getCachedTokensSync, TOKEN_ADDRESSES_BY_CHAIN } from './constants/tokens';
|
|
12
12
|
/**
|
|
13
13
|
* Gets the chain ID from a signer or provider
|
|
@@ -142,3 +142,21 @@ export function findTokenBySymbol(symbol, chainId) {
|
|
|
142
142
|
const tokens = getCachedTokensSync(chainId);
|
|
143
143
|
return tokens.find((token) => token.symbol === symbol);
|
|
144
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Computes the rate feed ID from a rate feed identifier string.
|
|
147
|
+
* This follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
|
|
148
|
+
* @param rateFeed the rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
|
|
149
|
+
* @returns the computed rate feed address
|
|
150
|
+
*/
|
|
151
|
+
export function toRateFeedId(rateFeed) {
|
|
152
|
+
// 1. Calculate keccak256 hash
|
|
153
|
+
const hashedBytes = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(rateFeed));
|
|
154
|
+
// 2. Convert to BigInt (equivalent to uint256)
|
|
155
|
+
const hashAsBigInt = BigInt(hashedBytes);
|
|
156
|
+
// 3. Mask to 160 bits (equivalent to uint160)
|
|
157
|
+
const maskedToUint160 = hashAsBigInt & ((BigInt(1) << BigInt(160)) - BigInt(1));
|
|
158
|
+
// 4. Convert to address (hex string)
|
|
159
|
+
const addressHex = '0x' + maskedToUint160.toString(16).padStart(40, '0');
|
|
160
|
+
// 5. Return calculated rate feed ID
|
|
161
|
+
return addressHex;
|
|
162
|
+
}
|