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