@mento-protocol/mento-sdk 1.11.0 → 1.13.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 +6 -13
  2. package/dist/cjs/constants/index.d.ts +1 -0
  3. package/dist/cjs/constants/index.js +1 -0
  4. package/dist/cjs/constants/tokens.11142220.d.ts +2 -0
  5. package/dist/cjs/constants/tokens.11142220.js +127 -0
  6. package/dist/cjs/constants/tokens.42220.d.ts +2 -0
  7. package/dist/cjs/constants/tokens.42220.js +127 -0
  8. package/dist/cjs/constants/tokens.44787.d.ts +2 -0
  9. package/dist/cjs/constants/tokens.44787.js +127 -0
  10. package/dist/cjs/constants/tokens.d.ts +67 -0
  11. package/dist/cjs/constants/tokens.js +207 -0
  12. package/dist/cjs/constants/tradablePairs.js +2 -0
  13. package/dist/cjs/enums/chainId.d.ts +1 -2
  14. package/dist/cjs/enums/chainId.js +0 -1
  15. package/dist/cjs/mento.d.ts +28 -0
  16. package/dist/cjs/mento.js +64 -1
  17. package/dist/cjs/utils.d.ts +15 -1
  18. package/dist/cjs/utils.js +31 -3
  19. package/dist/esm/constants/index.d.ts +1 -0
  20. package/dist/esm/constants/index.js +1 -0
  21. package/dist/esm/constants/tokens.11142220.d.ts +2 -0
  22. package/dist/esm/constants/tokens.11142220.js +124 -0
  23. package/dist/esm/constants/tokens.42220.d.ts +2 -0
  24. package/dist/esm/constants/tokens.42220.js +124 -0
  25. package/dist/esm/constants/tokens.44787.d.ts +2 -0
  26. package/dist/esm/constants/tokens.44787.js +124 -0
  27. package/dist/esm/constants/tokens.d.ts +67 -0
  28. package/dist/esm/constants/tokens.js +177 -0
  29. package/dist/esm/constants/tradablePairs.js +2 -0
  30. package/dist/esm/enums/chainId.d.ts +1 -2
  31. package/dist/esm/enums/chainId.js +0 -1
  32. package/dist/esm/mento.d.ts +28 -0
  33. package/dist/esm/mento.js +65 -2
  34. package/dist/esm/utils.d.ts +15 -1
  35. package/dist/esm/utils.js +27 -1
  36. package/package.json +4 -2
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ // This file is auto-generated. Do not edit manually.
3
+ // Generated on 2025-10-02T13:52:20.430Z
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
26
+ };
27
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
28
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
+ return new (P || (P = Promise))(function (resolve, reject) {
30
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
34
+ });
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.findTokenBySymbol = exports.getTokenAddress = exports.TOKEN_ADDRESSES_BY_CHAIN = exports.TokenSymbol = exports.getCachedTokensSync = exports.getCachedTokens = void 0;
38
+ /**
39
+ * Gets cached tokens for a specific chain ID
40
+ * @param chainId - The chain ID to get cached tokens for
41
+ * @returns Promise resolving to the cached tokens or undefined if not available
42
+ */
43
+ function getCachedTokens(chainId) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ switch (chainId) {
46
+ case 42220:
47
+ return yield Promise.resolve().then(() => __importStar(require('./tokens.42220'))).then((module) => module.tokens42220);
48
+ case 44787:
49
+ return yield Promise.resolve().then(() => __importStar(require('./tokens.44787'))).then((module) => module.tokens44787);
50
+ case 11142220:
51
+ return yield Promise.resolve().then(() => __importStar(require('./tokens.11142220'))).then((module) => module.tokens11142220);
52
+ default:
53
+ return undefined;
54
+ }
55
+ });
56
+ }
57
+ exports.getCachedTokens = getCachedTokens;
58
+ /**
59
+ * Synchronously gets cached tokens for a specific chain ID
60
+ * Note: This function throws if no cached tokens are available.
61
+ * Use getCachedTokens() for async loading or when you want to handle missing cache gracefully.
62
+ *
63
+ * @param chainId - The chain ID to get cached tokens for
64
+ * @returns The cached tokens
65
+ * @throws Error if no cached tokens are available for the chain
66
+ */
67
+ function getCachedTokensSync(chainId) {
68
+ switch (chainId) {
69
+ case 42220:
70
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
71
+ return require('./tokens.42220').tokens42220;
72
+ case 44787:
73
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
74
+ return require('./tokens.44787').tokens44787;
75
+ case 11142220:
76
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
77
+ return require('./tokens.11142220').tokens11142220;
78
+ default:
79
+ throw new Error(`No cached tokens available for chain ID ${chainId}. ` +
80
+ `Supported chains: 42220 (Celo), 44787 (Alfajores), 11142220 (Celo Sepolia)`);
81
+ }
82
+ }
83
+ exports.getCachedTokensSync = getCachedTokensSync;
84
+ /**
85
+ * Type-safe token symbols available across all chains
86
+ * Note: Not all tokens are available on all chains - check TOKEN_ADDRESSES_BY_CHAIN
87
+ */
88
+ var TokenSymbol;
89
+ (function (TokenSymbol) {
90
+ TokenSymbol["BridgedEUROC"] = "BridgedEUROC";
91
+ TokenSymbol["BridgedUSDC"] = "BridgedUSDC";
92
+ TokenSymbol["CELO"] = "CELO";
93
+ TokenSymbol["PUSO"] = "PUSO";
94
+ TokenSymbol["USDC"] = "USDC";
95
+ TokenSymbol["USDT"] = "USDT";
96
+ TokenSymbol["USD_"] = "USD\u20AE";
97
+ TokenSymbol["axlEUROC"] = "axlEUROC";
98
+ TokenSymbol["axlUSDC"] = "axlUSDC";
99
+ TokenSymbol["cAUD"] = "cAUD";
100
+ TokenSymbol["cCAD"] = "cCAD";
101
+ TokenSymbol["cCHF"] = "cCHF";
102
+ TokenSymbol["cCOP"] = "cCOP";
103
+ TokenSymbol["cEUR"] = "cEUR";
104
+ TokenSymbol["cGBP"] = "cGBP";
105
+ TokenSymbol["cGHS"] = "cGHS";
106
+ TokenSymbol["cJPY"] = "cJPY";
107
+ TokenSymbol["cKES"] = "cKES";
108
+ TokenSymbol["cNGN"] = "cNGN";
109
+ TokenSymbol["cREAL"] = "cREAL";
110
+ TokenSymbol["cUSD"] = "cUSD";
111
+ TokenSymbol["cZAR"] = "cZAR";
112
+ TokenSymbol["eXOF"] = "eXOF";
113
+ })(TokenSymbol = exports.TokenSymbol || (exports.TokenSymbol = {}));
114
+ /**
115
+ * Token addresses mapped by chain ID and symbol
116
+ * Use this for type-safe token address lookups
117
+ */
118
+ exports.TOKEN_ADDRESSES_BY_CHAIN = {
119
+ 42220: {
120
+ [TokenSymbol.axlEUROC]: '0x061cc5a2C863E0C1Cb404006D559dB18A34C762d',
121
+ [TokenSymbol.axlUSDC]: '0xEB466342C4d449BC9f53A865D5Cb90586f405215',
122
+ [TokenSymbol.cAUD]: '0x7175504C455076F15c04A2F90a8e352281F492F9',
123
+ [TokenSymbol.cCAD]: '0xff4Ab19391af240c311c54200a492233052B6325',
124
+ [TokenSymbol.cCHF]: '0xb55a79F398E759E43C95b979163f30eC87Ee131D',
125
+ [TokenSymbol.cCOP]: '0x8A567e2aE79CA692Bd748aB832081C45de4041eA',
126
+ [TokenSymbol.CELO]: '0x471EcE3750Da237f93B8E339c536989b8978a438',
127
+ [TokenSymbol.cEUR]: '0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73',
128
+ [TokenSymbol.cGBP]: '0xCCF663b1fF11028f0b19058d0f7B674004a40746',
129
+ [TokenSymbol.cGHS]: '0xfAeA5F3404bbA20D3cc2f8C4B0A888F55a3c7313',
130
+ [TokenSymbol.cJPY]: '0xc45eCF20f3CD864B32D9794d6f76814aE8892e20',
131
+ [TokenSymbol.cKES]: '0x456a3D042C0DbD3db53D5489e98dFb038553B0d0',
132
+ [TokenSymbol.cNGN]: '0xE2702Bd97ee33c88c8f6f92DA3B733608aa76F71',
133
+ [TokenSymbol.cREAL]: '0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787',
134
+ [TokenSymbol.cUSD]: '0x765DE816845861e75A25fCA122bb6898B8B1282a',
135
+ [TokenSymbol.cZAR]: '0x4c35853A3B4e647fD266f4de678dCc8fEC410BF6',
136
+ [TokenSymbol.eXOF]: '0x73F93dcc49cB8A239e2032663e9475dd5ef29A08',
137
+ [TokenSymbol.PUSO]: '0x105d4A9306D2E55a71d2Eb95B81553AE1dC20d7B',
138
+ [TokenSymbol.USD_]: '0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e',
139
+ [TokenSymbol.USDC]: '0xcebA9300f2b948710d2653dD7B07f33A8B32118C',
140
+ },
141
+ 44787: {
142
+ [TokenSymbol.BridgedEUROC]: '0x6e673502c5b55F3169657C004e5797fFE5be6653',
143
+ [TokenSymbol.BridgedUSDC]: '0x87D61dA3d668797786D73BC674F053f87111570d',
144
+ [TokenSymbol.cAUD]: '0x84CBD49F5aE07632B6B88094E81Cce8236125Fe0',
145
+ [TokenSymbol.cCAD]: '0x02EC9E0D2Fd73e89168C1709e542a48f58d7B133',
146
+ [TokenSymbol.cCHF]: '0xADC57C2C34aD021Df4421230a6532F4e2E1dCE4F',
147
+ [TokenSymbol.cCOP]: '0xe6A57340f0df6E020c1c0a80bC6E13048601f0d4',
148
+ [TokenSymbol.CELO]: '0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9',
149
+ [TokenSymbol.cEUR]: '0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F',
150
+ [TokenSymbol.cGBP]: '0x47f2Fb88105155a18c390641C8a73f1402B2BB12',
151
+ [TokenSymbol.cGHS]: '0x295B66bE7714458Af45E6A6Ea142A5358A6cA375',
152
+ [TokenSymbol.cJPY]: '0x2E51F41238cA36a421C9B8b3e189e8Cc7653FE67',
153
+ [TokenSymbol.cKES]: '0x1E0433C1769271ECcF4CFF9FDdD515eefE6CdF92',
154
+ [TokenSymbol.cNGN]: '0x4a5b03B8b16122D330306c65e4CA4BC5Dd6511d0',
155
+ [TokenSymbol.cREAL]: '0xE4D517785D091D3c54818832dB6094bcc2744545',
156
+ [TokenSymbol.cUSD]: '0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1',
157
+ [TokenSymbol.cZAR]: '0x1e5b44015Ff90610b54000DAad31C89b3284df4d',
158
+ [TokenSymbol.eXOF]: '0xB0FA15e002516d0301884059c0aaC0F0C72b019D',
159
+ [TokenSymbol.PUSO]: '0x5E0E3c9419C42a1B04e2525991FB1A2C467AB8bF',
160
+ [TokenSymbol.USDC]: '0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B',
161
+ [TokenSymbol.USDT]: '0xBba91F588d031469ABCCA566FE80fB1Ad8Ee3287',
162
+ },
163
+ 11142220: {
164
+ [TokenSymbol.axlEUROC]: '0x9883d788d40F1C7595a780ed881Ea833C7743B4B',
165
+ [TokenSymbol.axlUSDC]: '0x6285De9DA7C1d329C0451628638908915002d9d1',
166
+ [TokenSymbol.cAUD]: '0x5873Faeb42F3563dcD77F0fbbdA818E6d6DA3139',
167
+ [TokenSymbol.cCAD]: '0xF151c9a13b78C84f93f50B8b3bC689fedc134F60',
168
+ [TokenSymbol.cCHF]: '0x284E9b7B623eAE866914b7FA0eB720C2Bb3C2980',
169
+ [TokenSymbol.cCOP]: '0x5F8d55c3627d2dc0a2B4afa798f877242F382F67',
170
+ [TokenSymbol.CELO]: '0x471EcE3750Da237f93B8E339c536989b8978a438',
171
+ [TokenSymbol.cEUR]: '0xA99dC247d6b7B2E3ab48a1fEE101b83cD6aCd82a',
172
+ [TokenSymbol.cGBP]: '0x85F5181Abdbf0e1814Fc4358582Ae07b8eBA3aF3',
173
+ [TokenSymbol.cGHS]: '0x5e94B8C872bD47BC4255E60ECBF44D5E66e7401C',
174
+ [TokenSymbol.cJPY]: '0x85Bee67D435A39f7467a8a9DE34a5B73D25Df426',
175
+ [TokenSymbol.cKES]: '0xC7e4635651E3e3Af82b61d3E23c159438daE3BbF',
176
+ [TokenSymbol.cNGN]: '0x3d5ae86F34E2a82771496D140daFAEf3789dF888',
177
+ [TokenSymbol.cREAL]: '0x2294298942fdc79417DE9E0D740A4957E0e7783a',
178
+ [TokenSymbol.cUSD]: '0xdE9e4C3ce781b4bA68120d6261cbad65ce0aB00b',
179
+ [TokenSymbol.cZAR]: '0x10CCfB235b0E1Ed394bACE4560C3ed016697687e',
180
+ [TokenSymbol.eXOF]: '0x5505b70207aE3B826c1A7607F19F3Bf73444A082',
181
+ [TokenSymbol.PUSO]: '0x0352976d940a2C3FBa0C3623198947Ee1d17869E',
182
+ [TokenSymbol.USDC]: '0xBD63e46Be8eF8D89dFde3054E7b9ECAEb8Ad83e9',
183
+ [TokenSymbol.USDT]: '0xCA53d9b72646B254d29EBeEb4c5cde7BB4bb59e0',
184
+ },
185
+ };
186
+ /**
187
+ * Helper function to get token address by symbol for a specific chain
188
+ * @param chainId - The chain ID
189
+ * @param symbol - The token symbol
190
+ * @returns The token address or undefined if not found
191
+ */
192
+ function getTokenAddress(chainId, symbol) {
193
+ var _a;
194
+ return (_a = exports.TOKEN_ADDRESSES_BY_CHAIN[chainId]) === null || _a === void 0 ? void 0 : _a[symbol];
195
+ }
196
+ exports.getTokenAddress = getTokenAddress;
197
+ /**
198
+ * Helper function to find a token by symbol in the cached tokens
199
+ * @param chainId - The chain ID
200
+ * @param symbol - The token symbol to search for
201
+ * @returns The token object or undefined if not found
202
+ */
203
+ function findTokenBySymbol(chainId, symbol) {
204
+ const tokens = getCachedTokensSync(chainId);
205
+ return tokens.find((token) => token.symbol === symbol);
206
+ }
207
+ exports.findTokenBySymbol = findTokenBySymbol;
@@ -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,28 @@ 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
+ * This method is synchronous and uses pre-cached token data.
103
+ * For runtime fetching from the blockchain, use getTokensAsync().
104
+ *
105
+ * @returns An array of unique Token objects from the static cache.
106
+ * @throws Error if no cached tokens are available for the current chain or if chainId is not yet initialized
107
+ */
108
+ getTokens(): Token[];
109
+ /**
110
+ * Fetches token metadata from the blockchain at runtime.
111
+ * This method is async and makes blockchain calls to get fresh token data.
112
+ * For synchronous access using cached data, use getTokens().
113
+ *
114
+ * @param options - Optional parameters
115
+ * @param options.cached - Whether to use cached data (default: true).
116
+ * If true, attempts to load from static cache first.
117
+ * @returns A Promise resolving to an array of unique Token objects.
118
+ */
119
+ getTokensAsync({ cached, }?: {
120
+ cached?: boolean;
121
+ }): Promise<Token[]>;
94
122
  /**
95
123
  * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut.
96
124
  * If the provided tradablePair has a single (direct) pricing path, then direct pricing is used.
package/dist/cjs/mento.js CHANGED
@@ -43,7 +43,10 @@ class Mento {
43
43
  static create(signerOrProvider) {
44
44
  return __awaiter(this, void 0, void 0, function* () {
45
45
  (0, utils_1.validateSignerOrProvider)(signerOrProvider);
46
- return new Mento(signerOrProvider, (0, addresses_1.getAddress)('Broker', yield (0, utils_1.getChainId)(signerOrProvider)), (0, addresses_1.getAddress)('MentoRouter', yield (0, utils_1.getChainId)(signerOrProvider)));
46
+ const chainId = yield (0, utils_1.getChainId)(signerOrProvider);
47
+ const instance = new Mento(signerOrProvider, (0, addresses_1.getAddress)('Broker', chainId), (0, addresses_1.getAddress)('MentoRouter', chainId));
48
+ instance.cachedChainId = chainId;
49
+ return instance;
47
50
  });
48
51
  }
49
52
  /**
@@ -160,6 +163,66 @@ class Mento {
160
163
  return yield (0, tradablePairs_1.getCachedTradablePairs)(chainId);
161
164
  });
162
165
  }
166
+ /**
167
+ * Returns a list of all unique tokens available on the current chain.
168
+ * This method is synchronous and uses pre-cached token data.
169
+ * For runtime fetching from the blockchain, use getTokensAsync().
170
+ *
171
+ * @returns An array of unique Token objects from the static cache.
172
+ * @throws Error if no cached tokens are available for the current chain or if chainId is not yet initialized
173
+ */
174
+ getTokens() {
175
+ if (this.cachedChainId === null) {
176
+ throw new Error('Chain ID not yet initialized. Use Mento.create() to initialize the SDK, or use getTokensAsync() instead.');
177
+ }
178
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
179
+ const { getCachedTokensSync } = require('./constants/tokens');
180
+ return Array.from(getCachedTokensSync(this.cachedChainId));
181
+ }
182
+ /**
183
+ * Fetches token metadata from the blockchain at runtime.
184
+ * This method is async and makes blockchain calls to get fresh token data.
185
+ * For synchronous access using cached data, use getTokens().
186
+ *
187
+ * @param options - Optional parameters
188
+ * @param options.cached - Whether to use cached data (default: true).
189
+ * If true, attempts to load from static cache first.
190
+ * @returns A Promise resolving to an array of unique Token objects.
191
+ */
192
+ getTokensAsync({ cached = true, } = {}) {
193
+ return __awaiter(this, void 0, void 0, function* () {
194
+ // If cached is true, try to use the static cache first
195
+ if (cached) {
196
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
197
+ const { getCachedTokens } = require('./constants/tokens');
198
+ const chainId = yield this.chainId();
199
+ const cachedTokens = yield getCachedTokens(chainId);
200
+ if (cachedTokens) {
201
+ return Array.from(cachedTokens);
202
+ }
203
+ }
204
+ // Fall back to fetching from blockchain
205
+ const tradablePairs = yield this.getTradablePairsWithPath({ cached: false });
206
+ // Collect unique token addresses
207
+ const uniqueAddresses = new Set(tradablePairs.flatMap((pair) => pair.assets.map((asset) => asset.address)));
208
+ // Fetch token metadata for each unique address
209
+ const tokens = yield Promise.all(Array.from(uniqueAddresses).map((address) => __awaiter(this, void 0, void 0, function* () {
210
+ const [symbol, name, decimals] = yield Promise.all([
211
+ (0, utils_1.getSymbolFromTokenAddress)(address, this.signerOrProvider),
212
+ (0, utils_1.getNameFromTokenAddress)(address, this.signerOrProvider),
213
+ (0, utils_1.getDecimalsFromTokenAddress)(address, this.signerOrProvider),
214
+ ]);
215
+ return {
216
+ address,
217
+ symbol,
218
+ name,
219
+ decimals,
220
+ };
221
+ })));
222
+ // Sort by symbol
223
+ return tokens.sort((a, b) => a.symbol.localeCompare(b.symbol));
224
+ });
225
+ }
163
226
  /**
164
227
  * Returns the amount of tokenIn to be sold to buy amountOut of tokenOut.
165
228
  * 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
@@ -41,5 +55,5 @@ export declare function increaseAllowance(tokenAddr: string, spender: string, am
41
55
  * @param symbol the token symbol to find (case-insensitive)
42
56
  * @returns the token address if found, null otherwise
43
57
  */
44
- export declare function findTokenBySymbol(pairs: readonly TradablePair[], symbol: string): string | null;
58
+ export declare function findTokenBySymbolInTradablePairs(pairs: readonly TradablePair[], symbol: string): string | null;
45
59
  export declare function capitalize(str: string): string;
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.findTokenBySymbolInTradablePairs = 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
@@ -95,7 +123,7 @@ exports.increaseAllowance = increaseAllowance;
95
123
  * @param symbol the token symbol to find (case-insensitive)
96
124
  * @returns the token address if found, null otherwise
97
125
  */
98
- function findTokenBySymbol(pairs, symbol) {
126
+ function findTokenBySymbolInTradablePairs(pairs, symbol) {
99
127
  for (const pair of pairs) {
100
128
  for (const asset of pair.assets) {
101
129
  if (asset.symbol.toLowerCase() === symbol.toLowerCase()) {
@@ -105,7 +133,7 @@ function findTokenBySymbol(pairs, symbol) {
105
133
  }
106
134
  return null;
107
135
  }
108
- exports.findTokenBySymbol = findTokenBySymbol;
136
+ exports.findTokenBySymbolInTradablePairs = findTokenBySymbolInTradablePairs;
109
137
  function capitalize(str) {
110
138
  return str.charAt(0).toUpperCase() + str.slice(1);
111
139
  }
@@ -1,3 +1,4 @@
1
1
  export * from './addresses';
2
2
  export * from './currencies';
3
+ export * from './tokens';
3
4
  export * from './tradablePairs';
@@ -1,3 +1,4 @@
1
1
  export * from './addresses';
2
2
  export * from './currencies';
3
+ export * from './tokens';
3
4
  export * from './tradablePairs';
@@ -0,0 +1,2 @@
1
+ import { Token } from '../mento';
2
+ export declare const tokens11142220: readonly Token[];
@@ -0,0 +1,124 @@
1
+ // This file is auto-generated. Do not edit manually.
2
+ // Generated on 2025-10-02T13:52:20.427Z
3
+ export const tokens11142220 = [
4
+ {
5
+ "address": "0x9883d788d40F1C7595a780ed881Ea833C7743B4B",
6
+ "symbol": "axlEUROC",
7
+ "name": "Mento Mock axlEUROC",
8
+ "decimals": 18
9
+ },
10
+ {
11
+ "address": "0x6285De9DA7C1d329C0451628638908915002d9d1",
12
+ "symbol": "axlUSDC",
13
+ "name": "Mento Mock axlUSDC",
14
+ "decimals": 18
15
+ },
16
+ {
17
+ "address": "0x5873Faeb42F3563dcD77F0fbbdA818E6d6DA3139",
18
+ "symbol": "cAUD",
19
+ "name": "Celo Australian Dollar",
20
+ "decimals": 18
21
+ },
22
+ {
23
+ "address": "0xF151c9a13b78C84f93f50B8b3bC689fedc134F60",
24
+ "symbol": "cCAD",
25
+ "name": "Celo Canadian Dollar",
26
+ "decimals": 18
27
+ },
28
+ {
29
+ "address": "0x284E9b7B623eAE866914b7FA0eB720C2Bb3C2980",
30
+ "symbol": "cCHF",
31
+ "name": "Celo Swiss Franc",
32
+ "decimals": 18
33
+ },
34
+ {
35
+ "address": "0x5F8d55c3627d2dc0a2B4afa798f877242F382F67",
36
+ "symbol": "cCOP",
37
+ "name": "Celo Colombian Peso",
38
+ "decimals": 18
39
+ },
40
+ {
41
+ "address": "0x471EcE3750Da237f93B8E339c536989b8978a438",
42
+ "symbol": "CELO",
43
+ "name": "Celo native asset",
44
+ "decimals": 18
45
+ },
46
+ {
47
+ "address": "0xA99dC247d6b7B2E3ab48a1fEE101b83cD6aCd82a",
48
+ "symbol": "cEUR",
49
+ "name": "Celo Euro",
50
+ "decimals": 18
51
+ },
52
+ {
53
+ "address": "0x85F5181Abdbf0e1814Fc4358582Ae07b8eBA3aF3",
54
+ "symbol": "cGBP",
55
+ "name": "Celo British Pound",
56
+ "decimals": 18
57
+ },
58
+ {
59
+ "address": "0x5e94B8C872bD47BC4255E60ECBF44D5E66e7401C",
60
+ "symbol": "cGHS",
61
+ "name": "Celo Ghanaian Cedi",
62
+ "decimals": 18
63
+ },
64
+ {
65
+ "address": "0x85Bee67D435A39f7467a8a9DE34a5B73D25Df426",
66
+ "symbol": "cJPY",
67
+ "name": "Celo Japanese Yen",
68
+ "decimals": 18
69
+ },
70
+ {
71
+ "address": "0xC7e4635651E3e3Af82b61d3E23c159438daE3BbF",
72
+ "symbol": "cKES",
73
+ "name": "Celo Kenyan Shilling",
74
+ "decimals": 18
75
+ },
76
+ {
77
+ "address": "0x3d5ae86F34E2a82771496D140daFAEf3789dF888",
78
+ "symbol": "cNGN",
79
+ "name": "Celo Nigerian Naira",
80
+ "decimals": 18
81
+ },
82
+ {
83
+ "address": "0x2294298942fdc79417DE9E0D740A4957E0e7783a",
84
+ "symbol": "cREAL",
85
+ "name": "Celo Brazilian Real",
86
+ "decimals": 18
87
+ },
88
+ {
89
+ "address": "0xdE9e4C3ce781b4bA68120d6261cbad65ce0aB00b",
90
+ "symbol": "cUSD",
91
+ "name": "Celo Dollar",
92
+ "decimals": 18
93
+ },
94
+ {
95
+ "address": "0x10CCfB235b0E1Ed394bACE4560C3ed016697687e",
96
+ "symbol": "cZAR",
97
+ "name": "Celo South African Rand",
98
+ "decimals": 18
99
+ },
100
+ {
101
+ "address": "0x5505b70207aE3B826c1A7607F19F3Bf73444A082",
102
+ "symbol": "eXOF",
103
+ "name": "ECO CFA",
104
+ "decimals": 18
105
+ },
106
+ {
107
+ "address": "0x0352976d940a2C3FBa0C3623198947Ee1d17869E",
108
+ "symbol": "PUSO",
109
+ "name": "PUSO",
110
+ "decimals": 18
111
+ },
112
+ {
113
+ "address": "0xBD63e46Be8eF8D89dFde3054E7b9ECAEb8Ad83e9",
114
+ "symbol": "USDC",
115
+ "name": "Mento Mock USDC",
116
+ "decimals": 18
117
+ },
118
+ {
119
+ "address": "0xCA53d9b72646B254d29EBeEb4c5cde7BB4bb59e0",
120
+ "symbol": "USDT",
121
+ "name": "Mento Mock USDT",
122
+ "decimals": 18
123
+ }
124
+ ];
@@ -0,0 +1,2 @@
1
+ import { Token } from '../mento';
2
+ export declare const tokens42220: readonly Token[];