@mento-protocol/mento-sdk 1.15.1 → 1.15.4

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/dist/esm/mento.js CHANGED
@@ -16,6 +16,8 @@ import { IMentoRouter__factory } from 'mento-router-ts';
16
16
  import { getAddress } from './constants/addresses';
17
17
  import { getCachedTradablePairs, } from './constants/tradablePairs';
18
18
  import { buildConnectivityStructures, generateAllRoutes, selectOptimalRoutes, } from './routeUtils';
19
+ // Re-export TokenSymbol for use in auto-generated files and consuming packages
20
+ export { TokenSymbol } from './constants/tokens';
19
21
  export class Mento {
20
22
  /**
21
23
  * This constructor is private, use the static create or createWithParams methods
@@ -169,7 +171,7 @@ export class Mento {
169
171
  * @throws Error if no cached tokens are available for the current chain or if chainId is not yet initialized
170
172
  */
171
173
  getTokens() {
172
- if (this.cachedChainId === null) {
174
+ if (!this.cachedChainId) {
173
175
  throw new Error('Chain ID not yet initialized. Use Mento.create() to initialize the SDK, or use getTokensAsync() instead.');
174
176
  }
175
177
  // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -190,8 +192,7 @@ export class Mento {
190
192
  return __awaiter(this, void 0, void 0, function* () {
191
193
  // If cached is true, try to use the static cache first
192
194
  if (cached) {
193
- // eslint-disable-next-line @typescript-eslint/no-var-requires
194
- const { getCachedTokens } = require('./constants/tokens');
195
+ const { getCachedTokens } = yield import('./constants/tokens');
195
196
  const chainId = yield this.chainId();
196
197
  const cachedTokens = yield getCachedTokens(chainId);
197
198
  if (cachedTokens) {
@@ -623,7 +624,7 @@ export class Mento {
623
624
  }
624
625
  chainId() {
625
626
  return __awaiter(this, void 0, void 0, function* () {
626
- if (this.cachedChainId == null) {
627
+ if (!this.cachedChainId) {
627
628
  this.cachedChainId = yield getChainId(this.signerOrProvider);
628
629
  }
629
630
  return this.cachedChainId;
@@ -1,7 +1,7 @@
1
1
  import { BigNumberish, providers, Signer } from 'ethers';
2
2
  import { TokenSymbol } from './constants';
3
3
  import { Address } from './interfaces';
4
- import { TradablePair } from './mento';
4
+ import { Token, TradablePair } from './mento';
5
5
  /**
6
6
  * Gets the chain ID from a signer or provider
7
7
  * @param signerOrProvider an ethers provider or signer
@@ -56,5 +56,18 @@ export declare function increaseAllowance(tokenAddr: string, spender: string, am
56
56
  * @param symbol the token symbol to find (case-insensitive)
57
57
  * @returns the token address if found, null otherwise
58
58
  */
59
- export declare function findTokenBySymbolInTradablePairs(pairs: readonly TradablePair[], symbol: string): string | null;
60
- export declare function capitalize(str: string): string;
59
+ export declare function findTokenAddressBySymbolInTradablePairs(symbol: TokenSymbol, pairs: readonly TradablePair[]): Address | null;
60
+ export declare function capitalize(str: string): string; /**
61
+ * Helper function to get token address by symbol for a specific chain
62
+ * @param symbol - The token symbol
63
+ * @param chainId - The chain ID
64
+ * @returns The token address or undefined if not found
65
+ */
66
+ export declare function getTokenAddress(symbol: TokenSymbol, chainId: number): string | undefined;
67
+ /**
68
+ * Helper function to find a token by symbol in the cached tokens
69
+ * @param symbol - The token symbol to search for
70
+ * @param chainId - The chain ID
71
+ * @returns The token object or undefined if not found
72
+ */
73
+ export declare function findTokenBySymbol(symbol: string, chainId: number): Token | undefined;
package/dist/esm/utils.js CHANGED
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { Contract, providers, Signer } from 'ethers';
11
+ import { getCachedTokensSync, TOKEN_ADDRESSES_BY_CHAIN } from './constants/tokens';
11
12
  /**
12
13
  * Gets the chain ID from a signer or provider
13
14
  * @param signerOrProvider an ethers provider or signer
@@ -113,16 +114,31 @@ export function increaseAllowance(tokenAddr, spender, amount, signerOrProvider)
113
114
  * @param symbol the token symbol to find (case-insensitive)
114
115
  * @returns the token address if found, null otherwise
115
116
  */
116
- export function findTokenBySymbolInTradablePairs(pairs, symbol) {
117
- for (const pair of pairs) {
118
- for (const asset of pair.assets) {
119
- if (asset.symbol.toLowerCase() === symbol.toLowerCase()) {
120
- return asset.address;
121
- }
122
- }
123
- }
124
- return null;
117
+ export function findTokenAddressBySymbolInTradablePairs(symbol, pairs) {
118
+ var _a, _b;
119
+ return ((_b = (_a = pairs
120
+ .flatMap((pair) => pair.assets)
121
+ .find((asset) => asset.symbol.toLowerCase() === symbol.toLowerCase())) === null || _a === void 0 ? void 0 : _a.address) !== null && _b !== void 0 ? _b : null);
125
122
  }
126
123
  export function capitalize(str) {
127
124
  return str.charAt(0).toUpperCase() + str.slice(1);
125
+ } /**
126
+ * Helper function to get token address by symbol for a specific chain
127
+ * @param symbol - The token symbol
128
+ * @param chainId - The chain ID
129
+ * @returns The token address or undefined if not found
130
+ */
131
+ export function getTokenAddress(symbol, chainId) {
132
+ var _a;
133
+ return (_a = TOKEN_ADDRESSES_BY_CHAIN[chainId]) === null || _a === void 0 ? void 0 : _a[symbol];
134
+ }
135
+ /**
136
+ * Helper function to find a token by symbol in the cached tokens
137
+ * @param symbol - The token symbol to search for
138
+ * @param chainId - The chain ID
139
+ * @returns The token object or undefined if not found
140
+ */
141
+ export function findTokenBySymbol(symbol, chainId) {
142
+ const tokens = getCachedTokensSync(chainId);
143
+ return tokens.find((token) => token.symbol === symbol);
128
144
  }
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.15.1",
4
+ "version": "1.15.4",
5
5
  "license": "MIT",
6
6
  "author": "Mento Labs",
7
7
  "keywords": [