@mento-protocol/mento-sdk 1.10.3 → 1.12.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.
Files changed (36) hide show
  1. package/README.md +12 -17
  2. package/dist/cjs/constants/addresses.js +48 -32
  3. package/dist/cjs/constants/currencies.d.ts +5 -0
  4. package/dist/cjs/constants/currencies.js +29 -0
  5. package/dist/cjs/constants/index.d.ts +1 -0
  6. package/dist/cjs/constants/index.js +1 -0
  7. package/dist/cjs/constants/tradablePairs.11142220.d.ts +2 -0
  8. package/dist/cjs/constants/tradablePairs.11142220.js +7391 -0
  9. package/dist/cjs/constants/tradablePairs.42220.js +1 -1
  10. package/dist/cjs/constants/tradablePairs.44787.js +1 -1
  11. package/dist/cjs/constants/tradablePairs.js +2 -0
  12. package/dist/cjs/enums/chainId.d.ts +1 -0
  13. package/dist/cjs/enums/chainId.js +1 -0
  14. package/dist/cjs/mento.d.ts +20 -0
  15. package/dist/cjs/mento.js +45 -1
  16. package/dist/cjs/types/contractAddressMap.d.ts +1 -1
  17. package/dist/cjs/utils.d.ts +15 -6
  18. package/dist/cjs/utils.js +33 -22
  19. package/dist/esm/constants/addresses.js +48 -32
  20. package/dist/esm/constants/currencies.d.ts +5 -0
  21. package/dist/esm/constants/currencies.js +26 -0
  22. package/dist/esm/constants/index.d.ts +1 -0
  23. package/dist/esm/constants/index.js +1 -0
  24. package/dist/esm/constants/tradablePairs.11142220.d.ts +2 -0
  25. package/dist/esm/constants/tradablePairs.11142220.js +7388 -0
  26. package/dist/esm/constants/tradablePairs.42220.js +1 -1
  27. package/dist/esm/constants/tradablePairs.44787.js +1 -1
  28. package/dist/esm/constants/tradablePairs.js +2 -0
  29. package/dist/esm/enums/chainId.d.ts +1 -0
  30. package/dist/esm/enums/chainId.js +1 -0
  31. package/dist/esm/mento.d.ts +20 -0
  32. package/dist/esm/mento.js +46 -2
  33. package/dist/esm/types/contractAddressMap.d.ts +1 -1
  34. package/dist/esm/utils.d.ts +15 -6
  35. package/dist/esm/utils.js +29 -20
  36. package/package.json +12 -8
@@ -1,5 +1,5 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- // Generated on 2025-07-11T11:11:56.576Z
2
+ // Generated on 2025-09-12T16:06:28.873Z
3
3
  export const tradablePairs42220 = [
4
4
  {
5
5
  "id": "USDC-cUSD",
@@ -1,5 +1,5 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- // Generated on 2025-07-11T11:12:19.594Z
2
+ // Generated on 2025-09-12T16:07:04.390Z
3
3
  export const tradablePairs44787 = [
4
4
  {
5
5
  "id": "USDC-cUSD",
@@ -19,6 +19,8 @@ export function getCachedTradablePairs(chainId) {
19
19
  return yield import('./tradablePairs.42220').then((module) => module.tradablePairs42220);
20
20
  case 44787:
21
21
  return yield import('./tradablePairs.44787').then((module) => module.tradablePairs44787);
22
+ case 11142220:
23
+ return yield import('./tradablePairs.11142220').then((module) => module.tradablePairs11142220);
22
24
  default:
23
25
  return undefined;
24
26
  }
@@ -1,4 +1,5 @@
1
1
  export declare enum ChainId {
2
2
  CELO = 42220,
3
+ CELO_SEPOLIA = 11142220,
3
4
  ALFAJORES = 44787
4
5
  }
@@ -1,5 +1,6 @@
1
1
  export var ChainId;
2
2
  (function (ChainId) {
3
3
  ChainId[ChainId["CELO"] = 42220] = "CELO";
4
+ ChainId[ChainId["CELO_SEPOLIA"] = 11142220] = "CELO_SEPOLIA";
4
5
  ChainId[ChainId["ALFAJORES"] = 44787] = "ALFAJORES";
5
6
  })(ChainId || (ChainId = {}));
@@ -1,6 +1,7 @@
1
1
  import { IBroker } from '@mento-protocol/mento-core-ts';
2
2
  import { BigNumber, BigNumberish, providers, Signer } from 'ethers';
3
3
  import { Address, TradingLimit, TradingLimitsConfig, TradingLimitsState } from './interfaces';
4
+ import { Identifier } from './constants/addresses';
4
5
  import { TradablePairWithSpread } from './constants/tradablePairs';
5
6
  export interface Exchange {
6
7
  providerAddr: Address;
@@ -11,6 +12,12 @@ export interface Asset {
11
12
  address: Address;
12
13
  symbol: string;
13
14
  }
15
+ export interface Token {
16
+ address: Address;
17
+ symbol: string;
18
+ name: string;
19
+ decimals: number;
20
+ }
14
21
  export type TradablePairID = `${Address}-${Address}`;
15
22
  export interface TradablePair {
16
23
  id: TradablePairID;
@@ -26,6 +33,7 @@ export declare class Mento {
26
33
  private readonly broker;
27
34
  private readonly router;
28
35
  private exchanges;
36
+ private cachedChainId;
29
37
  /**
30
38
  * This constructor is private, use the static create or createWithParams methods
31
39
  * to create a new Mento instance
@@ -89,6 +97,16 @@ export declare class Mento {
89
97
  * Attempts to get cached tradable pairs for the current chain
90
98
  */
91
99
  private getCachedTradablePairs;
100
+ /**
101
+ * Returns a list of all unique tokens available on the current chain.
102
+ * Each token includes its address, symbol, name, and decimals.
103
+ * @param options - Optional parameters
104
+ * @param options.cached - Whether to use cached data (default: true)
105
+ * @returns An array of unique Token objects.
106
+ */
107
+ getTokens({ cached, }?: {
108
+ cached?: boolean;
109
+ }): Promise<Token[]>;
92
110
  /**
93
111
  * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut.
94
112
  * If the provided tradablePair has a single (direct) pricing path, then direct pricing is used.
@@ -235,4 +253,6 @@ export declare class Mento {
235
253
  * @returns the trading limits state
236
254
  */
237
255
  getTradingLimitState(exchangeId: string): Promise<TradingLimitsState[]>;
256
+ getAddress(identifier: Identifier): Promise<Address>;
257
+ chainId(): Promise<number>;
238
258
  }
package/dist/esm/mento.js CHANGED
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { BiPoolManager__factory, Broker__factory, IBreakerBox__factory, IBroker__factory, IExchangeProvider__factory, } from '@mento-protocol/mento-core-ts';
11
11
  import { Signer } from 'ethers';
12
12
  import { getLimits, getLimitsConfig, getLimitsState } from './limits';
13
- import { getBrokerAddressFromRegistry, getChainId, getSymbolFromTokenAddress, increaseAllowance, validateSigner, validateSignerOrProvider, } from './utils';
13
+ import { getChainId, getDecimalsFromTokenAddress, getNameFromTokenAddress, getSymbolFromTokenAddress, increaseAllowance, validateSigner, validateSignerOrProvider, } from './utils';
14
14
  import { strict as assert } from 'assert';
15
15
  import { IMentoRouter__factory } from 'mento-router-ts';
16
16
  import { getAddress } from './constants/addresses';
@@ -25,6 +25,7 @@ export class Mento {
25
25
  * @param exchanges exchange data for the broker
26
26
  */
27
27
  constructor(signerOrProvider, brokerAddress, routerAddress, exchanges) {
28
+ this.cachedChainId = null;
28
29
  this.signerOrProvider = signerOrProvider;
29
30
  this.broker = IBroker__factory.connect(brokerAddress, signerOrProvider);
30
31
  this.router = IMentoRouter__factory.connect(routerAddress, signerOrProvider);
@@ -39,7 +40,7 @@ export class Mento {
39
40
  static create(signerOrProvider) {
40
41
  return __awaiter(this, void 0, void 0, function* () {
41
42
  validateSignerOrProvider(signerOrProvider);
42
- return new Mento(signerOrProvider, yield getBrokerAddressFromRegistry(signerOrProvider), yield getAddress('MentoRouter', yield getChainId(signerOrProvider)));
43
+ return new Mento(signerOrProvider, getAddress('Broker', yield getChainId(signerOrProvider)), getAddress('MentoRouter', yield getChainId(signerOrProvider)));
43
44
  });
44
45
  }
45
46
  /**
@@ -156,6 +157,36 @@ export class Mento {
156
157
  return yield getCachedTradablePairs(chainId);
157
158
  });
158
159
  }
160
+ /**
161
+ * Returns a list of all unique tokens available on the current chain.
162
+ * Each token includes its address, symbol, name, and decimals.
163
+ * @param options - Optional parameters
164
+ * @param options.cached - Whether to use cached data (default: true)
165
+ * @returns An array of unique Token objects.
166
+ */
167
+ getTokens({ cached = true, } = {}) {
168
+ return __awaiter(this, void 0, void 0, function* () {
169
+ const tradablePairs = yield this.getTradablePairsWithPath({ cached });
170
+ // Collect unique token addresses
171
+ const uniqueAddresses = new Set(tradablePairs.flatMap(pair => pair.assets.map(asset => asset.address)));
172
+ // Fetch token metadata for each unique address
173
+ const tokens = yield Promise.all(Array.from(uniqueAddresses).map((address) => __awaiter(this, void 0, void 0, function* () {
174
+ const [symbol, name, decimals] = yield Promise.all([
175
+ getSymbolFromTokenAddress(address, this.signerOrProvider),
176
+ getNameFromTokenAddress(address, this.signerOrProvider),
177
+ getDecimalsFromTokenAddress(address, this.signerOrProvider),
178
+ ]);
179
+ return {
180
+ address,
181
+ symbol,
182
+ name,
183
+ decimals,
184
+ };
185
+ })));
186
+ // Sort by symbol
187
+ return tokens.sort((a, b) => a.symbol.localeCompare(b.symbol));
188
+ });
189
+ }
159
190
  /**
160
191
  * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut.
161
192
  * If the provided tradablePair has a single (direct) pricing path, then direct pricing is used.
@@ -552,4 +583,17 @@ export class Mento {
552
583
  return yield Promise.all(configuredLimitCfgs.map((cfg) => __awaiter(this, void 0, void 0, function* () { return yield getLimitsState(broker, exchangeId, cfg.asset); })));
553
584
  });
554
585
  }
586
+ getAddress(identifier) {
587
+ return __awaiter(this, void 0, void 0, function* () {
588
+ return getAddress(identifier, yield this.chainId());
589
+ });
590
+ }
591
+ chainId() {
592
+ return __awaiter(this, void 0, void 0, function* () {
593
+ if (this.cachedChainId == null) {
594
+ this.cachedChainId = yield getChainId(this.signerOrProvider);
595
+ }
596
+ return this.cachedChainId;
597
+ });
598
+ }
555
599
  }
@@ -1,4 +1,4 @@
1
1
  import { ContractAddresses } from '.';
2
2
  export type ContractAddressMap = {
3
- [chainId: number]: ContractAddresses;
3
+ [chainId: number]: Partial<ContractAddresses>;
4
4
  };
@@ -19,12 +19,6 @@ export declare function validateSigner(signer: Signer): void;
19
19
  * @throws if signerOrProvider is invalid or not connected
20
20
  */
21
21
  export declare function validateSignerOrProvider(signerOrProvider: Signer | providers.Provider): void;
22
- /**
23
- * Returns the broker address from the Celo registry
24
- * @param signerOrProvider an ethers provider or signer
25
- * @returns the broker address
26
- */
27
- export declare function getBrokerAddressFromRegistry(signerOrProvider: Signer | providers.Provider): Promise<Address>;
28
22
  /**
29
23
  * Returns the symbol of an erc20 token
30
24
  * @param tokenAddr the address of the erc20 token
@@ -32,6 +26,20 @@ export declare function getBrokerAddressFromRegistry(signerOrProvider: Signer |
32
26
  * @returns the symbol of the erc20 token
33
27
  */
34
28
  export declare function getSymbolFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<string>;
29
+ /**
30
+ * Returns the name of an erc20 token
31
+ * @param tokenAddr the address of the erc20 token
32
+ * @param signerOrProvider an ethers provider or signer
33
+ * @returns the name of the erc20 token
34
+ */
35
+ export declare function getNameFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<string>;
36
+ /**
37
+ * Returns the decimals of an erc20 token
38
+ * @param tokenAddr the address of the erc20 token
39
+ * @param signerOrProvider an ethers provider or signer
40
+ * @returns the decimals of the erc20 token
41
+ */
42
+ export declare function getDecimalsFromTokenAddress(tokenAddr: Address, signerOrProvider: Signer | providers.Provider): Promise<number>;
35
43
  /**
36
44
  * Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
37
45
  * @param tokenAddr the address of the erc20 token
@@ -48,3 +56,4 @@ export declare function increaseAllowance(tokenAddr: string, spender: string, am
48
56
  * @returns the token address if found, null otherwise
49
57
  */
50
58
  export declare function findTokenBySymbol(pairs: readonly TradablePair[], symbol: string): string | null;
59
+ export declare function capitalize(str: string): string;
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 { constants, Contract, providers, Signer } from 'ethers';
10
+ import { Contract, providers, Signer } from 'ethers';
11
11
  /**
12
12
  * Gets the chain ID from a signer or provider
13
13
  * @param signerOrProvider an ethers provider or signer
@@ -50,36 +50,42 @@ export function validateSignerOrProvider(signerOrProvider) {
50
50
  }
51
51
  }
52
52
  /**
53
- * Returns the broker address from the Celo registry
53
+ * Returns the symbol of an erc20 token
54
+ * @param tokenAddr the address of the erc20 token
54
55
  * @param signerOrProvider an ethers provider or signer
55
- * @returns the broker address
56
+ * @returns the symbol of the erc20 token
56
57
  */
57
- export function getBrokerAddressFromRegistry(signerOrProvider) {
58
+ export function getSymbolFromTokenAddress(tokenAddr, signerOrProvider) {
58
59
  return __awaiter(this, void 0, void 0, function* () {
59
- const celoRegistryAddress = '0x000000000000000000000000000000000000ce10';
60
- const brokerIdentifier = 'Broker';
61
- const registryAbi = [
62
- 'function getAddressForString(string calldata identifier) external view returns (address)',
63
- ];
64
- const contract = new Contract(celoRegistryAddress, registryAbi, signerOrProvider);
65
- const brokerAddress = yield contract.getAddressForString(brokerIdentifier);
66
- if (brokerAddress === constants.AddressZero) {
67
- throw Error('Broker address not found in the registry');
68
- }
69
- return brokerAddress;
60
+ const erc20Abi = ['function symbol() external view returns (string memory)'];
61
+ const contract = new Contract(tokenAddr, erc20Abi, signerOrProvider);
62
+ return contract.symbol();
70
63
  });
71
64
  }
72
65
  /**
73
- * Returns the symbol of an erc20 token
66
+ * Returns the name of an erc20 token
74
67
  * @param tokenAddr the address of the erc20 token
75
68
  * @param signerOrProvider an ethers provider or signer
76
- * @returns the symbol of the erc20 token
69
+ * @returns the name of the erc20 token
77
70
  */
78
- export function getSymbolFromTokenAddress(tokenAddr, signerOrProvider) {
71
+ export function getNameFromTokenAddress(tokenAddr, signerOrProvider) {
79
72
  return __awaiter(this, void 0, void 0, function* () {
80
- const erc20Abi = ['function symbol() external view returns (string memory)'];
73
+ const erc20Abi = ['function name() external view returns (string memory)'];
81
74
  const contract = new Contract(tokenAddr, erc20Abi, signerOrProvider);
82
- return contract.symbol();
75
+ return contract.name();
76
+ });
77
+ }
78
+ /**
79
+ * Returns the decimals of an erc20 token
80
+ * @param tokenAddr the address of the erc20 token
81
+ * @param signerOrProvider an ethers provider or signer
82
+ * @returns the decimals of the erc20 token
83
+ */
84
+ export function getDecimalsFromTokenAddress(tokenAddr, signerOrProvider) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const erc20Abi = ['function decimals() external view returns (uint8)'];
87
+ const contract = new Contract(tokenAddr, erc20Abi, signerOrProvider);
88
+ return contract.decimals();
83
89
  });
84
90
  }
85
91
  /**
@@ -117,3 +123,6 @@ export function findTokenBySymbol(pairs, symbol) {
117
123
  }
118
124
  return null;
119
125
  }
126
+ export function capitalize(str) {
127
+ return str.charAt(0).toUpperCase() + str.slice(1);
128
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mento-protocol/mento-sdk",
3
3
  "description": "Official SDK for interacting with the Mento Protocol",
4
- "version": "1.10.3",
4
+ "version": "1.12.0",
5
5
  "license": "MIT",
6
6
  "author": "Mento Labs",
7
7
  "keywords": [
@@ -22,12 +22,12 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "analyze": "size-limit --why",
25
- "build": "yarn build:cjs && yarn build:esm",
25
+ "build": "yarn build:cjs && yarn build:esm && yarn check:scripts",
26
26
  "build:cjs": "tsc --project ./tsconfig.json",
27
27
  "build:esm": "tsc --project ./tsconfig.esm.json",
28
28
  "clean": "rm -rf ./dist",
29
- "lint": "eslint --config ./.eslintrc.json 'src/**/*.ts' 'scripts/**/*.ts'",
30
- "type-check": "tsc --noEmit --project ./tsconfig.eslint.json",
29
+ "lint": "eslint --fix --config ./.eslintrc.json 'src/**/*.ts' 'scripts/**/*.ts'",
30
+ "check:scripts": "tsc --project ./tsconfig.scripts.json",
31
31
  "prettier": "prettier --config ./.prettierrc.json --write **/*.{json,md,js,ts,yml}",
32
32
  "size": "size-limit",
33
33
  "test": "jest --runInBand --verbose",
@@ -35,10 +35,14 @@
35
35
  "cacheTradablePairs": "ts-node scripts/cacheTradablePairs.ts",
36
36
  "printTradablePairs": "ts-node scripts/printTradablePairs.ts",
37
37
  "tradingLimits": "ts-node scripts/printTradingLimits.ts",
38
+ "limits": "yarn tradingLimits",
38
39
  "poolConfigs": "ts-node scripts/printPoolConfigs.ts",
40
+ "pools": "ts-node scripts/printPoolConfigs.ts",
39
41
  "breakerBox": "ts-node scripts/printBreakerBox.ts",
42
+ "breakers": "yarn breakerBox",
40
43
  "quote": "ts-node scripts/quotes/index.ts",
41
- "getTokenGraph": "ts-node scripts/visualizeTokenGraph.ts"
44
+ "getTokenGraph": "ts-node scripts/visualizeTokenGraph.ts",
45
+ "tokens": "ts-node scripts/printTokens.ts"
42
46
  },
43
47
  "husky": {
44
48
  "hooks": {
@@ -54,6 +58,7 @@
54
58
  "engines": {
55
59
  "node": ">=22"
56
60
  },
61
+ "packageManager": "yarn@3",
57
62
  "size-limit": [
58
63
  {
59
64
  "path": "dist/sdk.cjs.production.min.js",
@@ -91,11 +96,10 @@
91
96
  "yargs-parser": "^21.1.1"
92
97
  },
93
98
  "dependencies": {
94
- "@mento-protocol/mento-core-ts": "^0.2.0",
99
+ "@mento-protocol/mento-core-ts": "2.6.5-rc3",
95
100
  "mento-router-ts": "^0.2.0"
96
101
  },
97
102
  "peerDependencies": {
98
103
  "ethers": "^5.7"
99
- },
100
- "packageManager": "yarn@3.3.1"
104
+ }
101
105
  }