@mento-protocol/mento-sdk 1.11.0 → 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.
package/README.md CHANGED
@@ -26,7 +26,6 @@ The `yarn cacheTradablePairs` script generates a TypeScript file containing a li
26
26
  yarn cacheTradablePairs
27
27
  ```
28
28
 
29
-
30
29
  ## Token Graph Visualization
31
30
 
32
31
  Current token connectivity on Celo Mainnet (last updated: 2025-09-19):
@@ -59,7 +58,5 @@ graph TD
59
58
  **Network Stats:** 20 tokens, 19 direct trading pairs
60
59
 
61
60
  > 💡 This graph shows direct trading pairs only. The SDK automatically finds optimal routes including multi-hop paths.
62
- >
61
+ >
63
62
  > To regenerate: `yarn getTokenGraph`
64
-
65
-
@@ -45,6 +45,8 @@ function getCachedTradablePairs(chainId) {
45
45
  return yield Promise.resolve().then(() => __importStar(require('./tradablePairs.42220'))).then((module) => module.tradablePairs42220);
46
46
  case 44787:
47
47
  return yield Promise.resolve().then(() => __importStar(require('./tradablePairs.44787'))).then((module) => module.tradablePairs44787);
48
+ case 11142220:
49
+ return yield Promise.resolve().then(() => __importStar(require('./tradablePairs.11142220'))).then((module) => module.tradablePairs11142220);
48
50
  default:
49
51
  return undefined;
50
52
  }
@@ -1,6 +1,5 @@
1
1
  export declare enum ChainId {
2
2
  CELO = 42220,
3
3
  CELO_SEPOLIA = 11142220,
4
- ALFAJORES = 44787,
5
- BASE = 8453
4
+ ALFAJORES = 44787
6
5
  }
@@ -6,5 +6,4 @@ var ChainId;
6
6
  ChainId[ChainId["CELO"] = 42220] = "CELO";
7
7
  ChainId[ChainId["CELO_SEPOLIA"] = 11142220] = "CELO_SEPOLIA";
8
8
  ChainId[ChainId["ALFAJORES"] = 44787] = "ALFAJORES";
9
- ChainId[ChainId["BASE"] = 8453] = "BASE";
10
9
  })(ChainId = exports.ChainId || (exports.ChainId = {}));
@@ -12,6 +12,12 @@ export interface Asset {
12
12
  address: Address;
13
13
  symbol: string;
14
14
  }
15
+ export interface Token {
16
+ address: Address;
17
+ symbol: string;
18
+ name: string;
19
+ decimals: number;
20
+ }
15
21
  export type TradablePairID = `${Address}-${Address}`;
16
22
  export interface TradablePair {
17
23
  id: TradablePairID;
@@ -91,6 +97,16 @@ export declare class Mento {
91
97
  * Attempts to get cached tradable pairs for the current chain
92
98
  */
93
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[]>;
94
110
  /**
95
111
  * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut.
96
112
  * If the provided tradablePair has a single (direct) pricing path, then direct pricing is used.
package/dist/cjs/mento.js CHANGED
@@ -160,6 +160,36 @@ class Mento {
160
160
  return yield (0, tradablePairs_1.getCachedTradablePairs)(chainId);
161
161
  });
162
162
  }
163
+ /**
164
+ * Returns a list of all unique tokens available on the current chain.
165
+ * Each token includes its address, symbol, name, and decimals.
166
+ * @param options - Optional parameters
167
+ * @param options.cached - Whether to use cached data (default: true)
168
+ * @returns An array of unique Token objects.
169
+ */
170
+ getTokens({ cached = true, } = {}) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ const tradablePairs = yield this.getTradablePairsWithPath({ cached });
173
+ // Collect unique token addresses
174
+ const uniqueAddresses = new Set(tradablePairs.flatMap(pair => pair.assets.map(asset => asset.address)));
175
+ // Fetch token metadata for each unique address
176
+ const tokens = yield Promise.all(Array.from(uniqueAddresses).map((address) => __awaiter(this, void 0, void 0, function* () {
177
+ const [symbol, name, decimals] = yield Promise.all([
178
+ (0, utils_1.getSymbolFromTokenAddress)(address, this.signerOrProvider),
179
+ (0, utils_1.getNameFromTokenAddress)(address, this.signerOrProvider),
180
+ (0, utils_1.getDecimalsFromTokenAddress)(address, this.signerOrProvider),
181
+ ]);
182
+ return {
183
+ address,
184
+ symbol,
185
+ name,
186
+ decimals,
187
+ };
188
+ })));
189
+ // Sort by symbol
190
+ return tokens.sort((a, b) => a.symbol.localeCompare(b.symbol));
191
+ });
192
+ }
163
193
  /**
164
194
  * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut.
165
195
  * If the provided tradablePair has a single (direct) pricing path, then direct pricing is used.
@@ -26,6 +26,20 @@ export declare function validateSignerOrProvider(signerOrProvider: Signer | prov
26
26
  * @returns the symbol of the erc20 token
27
27
  */
28
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>;
29
43
  /**
30
44
  * Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
31
45
  * @param tokenAddr the address of the erc20 token
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.capitalize = exports.findTokenBySymbol = exports.increaseAllowance = exports.getSymbolFromTokenAddress = exports.validateSignerOrProvider = exports.validateSigner = exports.getChainId = void 0;
12
+ exports.capitalize = exports.findTokenBySymbol = 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
  /**
15
15
  * Gets the chain ID from a signer or provider
@@ -69,6 +69,34 @@ function getSymbolFromTokenAddress(tokenAddr, signerOrProvider) {
69
69
  });
70
70
  }
71
71
  exports.getSymbolFromTokenAddress = getSymbolFromTokenAddress;
72
+ /**
73
+ * Returns the name of an erc20 token
74
+ * @param tokenAddr the address of the erc20 token
75
+ * @param signerOrProvider an ethers provider or signer
76
+ * @returns the name of the erc20 token
77
+ */
78
+ function getNameFromTokenAddress(tokenAddr, signerOrProvider) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ const erc20Abi = ['function name() external view returns (string memory)'];
81
+ const contract = new ethers_1.Contract(tokenAddr, erc20Abi, signerOrProvider);
82
+ return contract.name();
83
+ });
84
+ }
85
+ exports.getNameFromTokenAddress = getNameFromTokenAddress;
86
+ /**
87
+ * Returns the decimals of an erc20 token
88
+ * @param tokenAddr the address of the erc20 token
89
+ * @param signerOrProvider an ethers provider or signer
90
+ * @returns the decimals of the erc20 token
91
+ */
92
+ function getDecimalsFromTokenAddress(tokenAddr, signerOrProvider) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const erc20Abi = ['function decimals() external view returns (uint8)'];
95
+ const contract = new ethers_1.Contract(tokenAddr, erc20Abi, signerOrProvider);
96
+ return contract.decimals();
97
+ });
98
+ }
99
+ exports.getDecimalsFromTokenAddress = getDecimalsFromTokenAddress;
72
100
  /**
73
101
  * Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
74
102
  * @param tokenAddr the address of the erc20 token
@@ -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,6 +1,5 @@
1
1
  export declare enum ChainId {
2
2
  CELO = 42220,
3
3
  CELO_SEPOLIA = 11142220,
4
- ALFAJORES = 44787,
5
- BASE = 8453
4
+ ALFAJORES = 44787
6
5
  }
@@ -3,5 +3,4 @@ export var ChainId;
3
3
  ChainId[ChainId["CELO"] = 42220] = "CELO";
4
4
  ChainId[ChainId["CELO_SEPOLIA"] = 11142220] = "CELO_SEPOLIA";
5
5
  ChainId[ChainId["ALFAJORES"] = 44787] = "ALFAJORES";
6
- ChainId[ChainId["BASE"] = 8453] = "BASE";
7
6
  })(ChainId || (ChainId = {}));
@@ -12,6 +12,12 @@ export interface Asset {
12
12
  address: Address;
13
13
  symbol: string;
14
14
  }
15
+ export interface Token {
16
+ address: Address;
17
+ symbol: string;
18
+ name: string;
19
+ decimals: number;
20
+ }
15
21
  export type TradablePairID = `${Address}-${Address}`;
16
22
  export interface TradablePair {
17
23
  id: TradablePairID;
@@ -91,6 +97,16 @@ export declare class Mento {
91
97
  * Attempts to get cached tradable pairs for the current chain
92
98
  */
93
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[]>;
94
110
  /**
95
111
  * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut.
96
112
  * If the provided tradablePair has a single (direct) pricing path, then direct pricing is used.
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 { 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';
@@ -157,6 +157,36 @@ export class Mento {
157
157
  return yield getCachedTradablePairs(chainId);
158
158
  });
159
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
+ }
160
190
  /**
161
191
  * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut.
162
192
  * If the provided tradablePair has a single (direct) pricing path, then direct pricing is used.
@@ -26,6 +26,20 @@ export declare function validateSignerOrProvider(signerOrProvider: Signer | prov
26
26
  * @returns the symbol of the erc20 token
27
27
  */
28
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>;
29
43
  /**
30
44
  * Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
31
45
  * @param tokenAddr the address of the erc20 token
package/dist/esm/utils.js CHANGED
@@ -62,6 +62,32 @@ export function getSymbolFromTokenAddress(tokenAddr, signerOrProvider) {
62
62
  return contract.symbol();
63
63
  });
64
64
  }
65
+ /**
66
+ * Returns the name of an erc20 token
67
+ * @param tokenAddr the address of the erc20 token
68
+ * @param signerOrProvider an ethers provider or signer
69
+ * @returns the name of the erc20 token
70
+ */
71
+ export function getNameFromTokenAddress(tokenAddr, signerOrProvider) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const erc20Abi = ['function name() external view returns (string memory)'];
74
+ const contract = new Contract(tokenAddr, erc20Abi, signerOrProvider);
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();
89
+ });
90
+ }
65
91
  /**
66
92
  * Returns a populated tx obj for increasing the allowance of a spender for a given erc20 token by a given amount
67
93
  * @param tokenAddr the address of the erc20 token
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.11.0",
4
+ "version": "1.12.0",
5
5
  "license": "MIT",
6
6
  "author": "Mento Labs",
7
7
  "keywords": [
@@ -41,7 +41,8 @@
41
41
  "breakerBox": "ts-node scripts/printBreakerBox.ts",
42
42
  "breakers": "yarn breakerBox",
43
43
  "quote": "ts-node scripts/quotes/index.ts",
44
- "getTokenGraph": "ts-node scripts/visualizeTokenGraph.ts"
44
+ "getTokenGraph": "ts-node scripts/visualizeTokenGraph.ts",
45
+ "tokens": "ts-node scripts/printTokens.ts"
45
46
  },
46
47
  "husky": {
47
48
  "hooks": {