@mento-protocol/mento-sdk 1.15.5 → 1.16.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.
@@ -1,2 +1,3 @@
1
- export * from './proposalState';
2
1
  export * from './chainId';
2
+ export * from './proposalState';
3
+ export * from './tradingMode';
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./proposalState"), exports);
18
17
  __exportStar(require("./chainId"), exports);
18
+ __exportStar(require("./proposalState"), exports);
19
+ __exportStar(require("./tradingMode"), exports);
@@ -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,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TradingMode = void 0;
4
+ /**
5
+ * Trading modes for rate feeds in the BreakerBox
6
+ */
7
+ var TradingMode;
8
+ (function (TradingMode) {
9
+ /**
10
+ * Bidirectional trading is enabled
11
+ */
12
+ TradingMode[TradingMode["BIDIRECTIONAL"] = 0] = "BIDIRECTIONAL";
13
+ /**
14
+ * Trading is temporarily halted (circuit breaker tripped)
15
+ */
16
+ TradingMode[TradingMode["HALTED"] = 1] = "HALTED";
17
+ /**
18
+ * Trading is permanently disabled
19
+ */
20
+ TradingMode[TradingMode["DISABLED"] = 2] = "DISABLED";
21
+ })(TradingMode = exports.TradingMode || (exports.TradingMode = {}));
@@ -1,4 +1,5 @@
1
1
  export * from './constants';
2
+ export * from './enums';
2
3
  export * from './governance';
3
4
  export * from './mento';
4
5
  export * from './routeUtils';
package/dist/cjs/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./constants"), exports);
19
+ __exportStar(require("./enums"), exports);
19
20
  __exportStar(require("./governance"), exports);
20
21
  __exportStar(require("./mento"), exports);
21
22
  __exportStar(require("./routeUtils"), exports);
@@ -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,19 @@ 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., its rate feed trading mode is BIDIRECTIONAL)
257
+ * @param tokenIn the address of the token to sell
258
+ * @param tokenOut the address of the token to buy
259
+ * @returns true if the pair is tradable (trading mode is BIDIRECTIONAL), false otherwise
260
+ */
261
+ isPairTradable(tokenIn: Address, tokenOut: Address): Promise<boolean>;
248
262
  /**
249
263
  * Return the trading limits for a given exchange id. Each limit is an object with the following fields:
250
264
  * asset: the address of the asset with the limit
package/dist/cjs/mento.js CHANGED
@@ -41,6 +41,7 @@ const assert_1 = require("assert");
41
41
  const mento_router_ts_1 = require("mento-router-ts");
42
42
  const addresses_1 = require("./constants/addresses");
43
43
  const tradablePairs_1 = require("./constants/tradablePairs");
44
+ const enums_1 = require("./enums");
44
45
  const routeUtils_1 = require("./routeUtils");
45
46
  // Re-export TokenSymbol for use in auto-generated files and consuming packages
46
47
  var tokens_1 = require("./constants/tokens");
@@ -594,6 +595,35 @@ class Mento {
594
595
  return currentMode == BI_DIRECTIONAL_TRADING_MODE;
595
596
  });
596
597
  }
598
+ /**
599
+ * Returns the current trading mode for a given rate feed
600
+ * @param rateFeedId the address of the rate feed
601
+ * @returns the current trading mode (BIDIRECTIONAL, HALTED, or DISABLED)
602
+ */
603
+ getRateFeedTradingMode(rateFeedId) {
604
+ return __awaiter(this, void 0, void 0, function* () {
605
+ const breakerBoxAddr = yield this.getAddress('BreakerBox');
606
+ const breakerBox = mento_core_ts_1.IBreakerBox__factory.connect(breakerBoxAddr, this.signerOrProvider);
607
+ const currentMode = yield breakerBox.getRateFeedTradingMode(rateFeedId);
608
+ return currentMode;
609
+ });
610
+ }
611
+ /**
612
+ * Checks if a trading pair is currently tradable (i.e., its rate feed trading mode is BIDIRECTIONAL)
613
+ * @param tokenIn the address of the token to sell
614
+ * @param tokenOut the address of the token to buy
615
+ * @returns true if the pair is tradable (trading mode is BIDIRECTIONAL), false otherwise
616
+ */
617
+ isPairTradable(tokenIn, tokenOut) {
618
+ return __awaiter(this, void 0, void 0, function* () {
619
+ const exchange = yield this.getExchangeForTokens(tokenIn, tokenOut);
620
+ const biPoolManager = mento_core_ts_1.BiPoolManager__factory.connect(exchange.providerAddr, this.signerOrProvider);
621
+ const exchangeConfig = yield biPoolManager.getPoolExchange(exchange.id);
622
+ const rateFeedId = exchangeConfig.config.referenceRateFeedID;
623
+ const tradingMode = yield this.getRateFeedTradingMode(rateFeedId);
624
+ return tradingMode === enums_1.TradingMode.BIDIRECTIONAL;
625
+ });
626
+ }
597
627
  /**
598
628
  * Return the trading limits for a given exchange id. Each limit is an object with the following fields:
599
629
  * asset: the address of the asset with the limit
@@ -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/cjs/utils.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.findTokenBySymbol = exports.getTokenAddress = exports.capitalize = exports.findTokenAddressBySymbolInTradablePairs = exports.increaseAllowance = exports.getDecimalsFromTokenAddress = exports.getNameFromTokenAddress = exports.getSymbolFromTokenAddress = exports.validateSignerOrProvider = exports.validateSigner = exports.getChainId = void 0;
12
+ exports.toRateFeedId = exports.findTokenBySymbol = exports.getTokenAddress = exports.capitalize = exports.findTokenAddressBySymbolInTradablePairs = exports.increaseAllowance = exports.getDecimalsFromTokenAddress = exports.getNameFromTokenAddress = exports.getSymbolFromTokenAddress = exports.validateSignerOrProvider = exports.validateSigner = exports.getChainId = void 0;
13
13
  const ethers_1 = require("ethers");
14
14
  const tokens_1 = require("./constants/tokens");
15
15
  /**
@@ -156,3 +156,22 @@ function findTokenBySymbol(symbol, chainId) {
156
156
  return tokens.find((token) => token.symbol === symbol);
157
157
  }
158
158
  exports.findTokenBySymbol = findTokenBySymbol;
159
+ /**
160
+ * Computes the rate feed ID from a rate feed identifier string.
161
+ * This follows the Solidity formula: address(uint160(uint256(keccak256(abi.encodePacked(rateFeed)))))
162
+ * @param rateFeed the rate feed identifier string (e.g., "EURUSD", "relayed:COPUSD")
163
+ * @returns the computed rate feed address
164
+ */
165
+ function toRateFeedId(rateFeed) {
166
+ // 1. Calculate keccak256 hash
167
+ const hashedBytes = ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.toUtf8Bytes(rateFeed));
168
+ // 2. Convert to BigInt (equivalent to uint256)
169
+ const hashAsBigInt = BigInt(hashedBytes);
170
+ // 3. Mask to 160 bits (equivalent to uint160)
171
+ const maskedToUint160 = hashAsBigInt & ((BigInt(1) << BigInt(160)) - BigInt(1));
172
+ // 4. Convert to address (hex string)
173
+ const addressHex = '0x' + maskedToUint160.toString(16).padStart(40, '0');
174
+ // 5. Return calculated rate feed ID
175
+ return addressHex;
176
+ }
177
+ exports.toRateFeedId = toRateFeedId;
@@ -0,0 +1,2 @@
1
+ import { Token } from '../mento';
2
+ export declare const tokens44787: readonly Token[];
@@ -0,0 +1,125 @@
1
+ // This file is auto-generated. Do not edit manually.
2
+ // Generated on 2025-10-06T16:08:33.900Z
3
+ import { TokenSymbol } from '../mento';
4
+ export const tokens44787 = [
5
+ {
6
+ address: '0x6e673502c5b55F3169657C004e5797fFE5be6653',
7
+ symbol: TokenSymbol.BridgedEUROC,
8
+ name: 'mockBridgedEUROC',
9
+ decimals: 6,
10
+ },
11
+ {
12
+ address: '0x87D61dA3d668797786D73BC674F053f87111570d',
13
+ symbol: TokenSymbol.BridgedUSDC,
14
+ name: 'mockBridgedUSDC',
15
+ decimals: 6,
16
+ },
17
+ {
18
+ address: '0x84CBD49F5aE07632B6B88094E81Cce8236125Fe0',
19
+ symbol: TokenSymbol.cAUD,
20
+ name: 'Celo Australian Dollar',
21
+ decimals: 18,
22
+ },
23
+ {
24
+ address: '0x02EC9E0D2Fd73e89168C1709e542a48f58d7B133',
25
+ symbol: TokenSymbol.cCAD,
26
+ name: 'Celo Canadian Dollar',
27
+ decimals: 18,
28
+ },
29
+ {
30
+ address: '0xADC57C2C34aD021Df4421230a6532F4e2E1dCE4F',
31
+ symbol: TokenSymbol.cCHF,
32
+ name: 'Celo Swiss Franc',
33
+ decimals: 18,
34
+ },
35
+ {
36
+ address: '0xe6A57340f0df6E020c1c0a80bC6E13048601f0d4',
37
+ symbol: TokenSymbol.cCOP,
38
+ name: 'Celo Colombian Peso',
39
+ decimals: 18,
40
+ },
41
+ {
42
+ address: '0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9',
43
+ symbol: TokenSymbol.CELO,
44
+ name: 'Celo native asset',
45
+ decimals: 18,
46
+ },
47
+ {
48
+ address: '0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F',
49
+ symbol: TokenSymbol.cEUR,
50
+ name: 'Celo Euro',
51
+ decimals: 18,
52
+ },
53
+ {
54
+ address: '0x47f2Fb88105155a18c390641C8a73f1402B2BB12',
55
+ symbol: TokenSymbol.cGBP,
56
+ name: 'Celo British Pound',
57
+ decimals: 18,
58
+ },
59
+ {
60
+ address: '0x295B66bE7714458Af45E6A6Ea142A5358A6cA375',
61
+ symbol: TokenSymbol.cGHS,
62
+ name: 'cGHS',
63
+ decimals: 18,
64
+ },
65
+ {
66
+ address: '0x2E51F41238cA36a421C9B8b3e189e8Cc7653FE67',
67
+ symbol: TokenSymbol.cJPY,
68
+ name: 'Celo Japanese Yen',
69
+ decimals: 18,
70
+ },
71
+ {
72
+ address: '0x1E0433C1769271ECcF4CFF9FDdD515eefE6CdF92',
73
+ symbol: TokenSymbol.cKES,
74
+ name: 'Celo Kenyan Shilling',
75
+ decimals: 18,
76
+ },
77
+ {
78
+ address: '0x4a5b03B8b16122D330306c65e4CA4BC5Dd6511d0',
79
+ symbol: TokenSymbol.cNGN,
80
+ name: 'Celo Nigerian Naira',
81
+ decimals: 18,
82
+ },
83
+ {
84
+ address: '0xE4D517785D091D3c54818832dB6094bcc2744545',
85
+ symbol: TokenSymbol.cREAL,
86
+ name: 'Celo Brazilian Real',
87
+ decimals: 18,
88
+ },
89
+ {
90
+ address: '0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1',
91
+ symbol: TokenSymbol.cUSD,
92
+ name: 'Celo Dollar',
93
+ decimals: 18,
94
+ },
95
+ {
96
+ address: '0x1e5b44015Ff90610b54000DAad31C89b3284df4d',
97
+ symbol: TokenSymbol.cZAR,
98
+ name: 'Celo South African Rand',
99
+ decimals: 18,
100
+ },
101
+ {
102
+ address: '0xB0FA15e002516d0301884059c0aaC0F0C72b019D',
103
+ symbol: TokenSymbol.eXOF,
104
+ name: 'ECO CFA',
105
+ decimals: 18,
106
+ },
107
+ {
108
+ address: '0x5E0E3c9419C42a1B04e2525991FB1A2C467AB8bF',
109
+ symbol: TokenSymbol.PUSO,
110
+ name: 'PUSO',
111
+ decimals: 18,
112
+ },
113
+ {
114
+ address: '0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B',
115
+ symbol: TokenSymbol.USDC,
116
+ name: 'USDC',
117
+ decimals: 6,
118
+ },
119
+ {
120
+ address: '0xBba91F588d031469ABCCA566FE80fB1Ad8Ee3287',
121
+ symbol: TokenSymbol.USDT,
122
+ name: 'mockNativeUSDT',
123
+ decimals: 6,
124
+ },
125
+ ];
@@ -0,0 +1,2 @@
1
+ import { TradablePairWithSpread } from './tradablePairs';
2
+ export declare const tradablePairs44787: TradablePairWithSpread[];