@across-protocol/sdk 4.3.1 → 4.3.3
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/cjs/clients/BundleDataClient/BundleDataClient.js +4 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +8 -5
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/cjs/clients/HubPoolClient.d.ts +1 -1
- package/dist/cjs/clients/HubPoolClient.js +3 -3
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +1 -0
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +6 -0
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +5 -5
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/typeguards/error.d.ts +2 -0
- package/dist/cjs/typeguards/error.js +4 -1
- package/dist/cjs/typeguards/error.js.map +1 -1
- package/dist/cjs/utils/TokenUtils.d.ts +5 -4
- package/dist/cjs/utils/TokenUtils.js +15 -23
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +5 -2
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +9 -6
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +1 -1
- package/dist/esm/clients/HubPoolClient.js +3 -4
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +1 -0
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +7 -0
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +11 -10
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +6 -6
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/typeguards/error.d.ts +2 -0
- package/dist/esm/typeguards/error.js +2 -0
- package/dist/esm/typeguards/error.js.map +1 -1
- package/dist/esm/utils/TokenUtils.d.ts +31 -10
- package/dist/esm/utils/TokenUtils.js +20 -28
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +1 -1
- package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +1 -0
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +11 -10
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/typeguards/error.d.ts +2 -0
- package/dist/types/typeguards/error.d.ts.map +1 -1
- package/dist/types/utils/TokenUtils.d.ts +31 -10
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/clients/BundleDataClient/BundleDataClient.ts +4 -1
- package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +10 -6
- package/src/clients/HubPoolClient.ts +3 -4
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +8 -0
- package/src/relayFeeCalculator/relayFeeCalculator.ts +6 -5
- package/src/typeguards/error.ts +3 -0
- package/src/utils/TokenUtils.ts +30 -34
package/src/utils/TokenUtils.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { ERC20__factory } from "../typechain";
|
|
|
7
7
|
import { BigNumber } from "./BigNumberUtils";
|
|
8
8
|
import { getNetworkName, chainIsL1, chainIsProd } from "./NetworkUtils";
|
|
9
9
|
import { isDefined } from "./TypeGuards";
|
|
10
|
-
import {
|
|
10
|
+
import { Address, EvmAddress, toAddressType } from "./AddressUtils";
|
|
11
11
|
const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
|
|
12
12
|
|
|
13
13
|
type SignerOrProvider = providers.Provider | Signer;
|
|
@@ -66,11 +66,8 @@ export const resolveContractFromSymbol = (
|
|
|
66
66
|
})?.addresses[Number(chainId)];
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
export function getCoingeckoTokenIdByAddress(
|
|
70
|
-
const token = getTokenInfo(
|
|
71
|
-
if (!token) {
|
|
72
|
-
throw new Error(`Token with address ${contractAddress} not found in token mapping`);
|
|
73
|
-
}
|
|
69
|
+
export function getCoingeckoTokenIdByAddress(address: string, chainId: number): string {
|
|
70
|
+
const token = getTokenInfo(toAddressType(address, chainId), chainId);
|
|
74
71
|
return TOKEN_SYMBOLS_MAP[token.symbol as keyof typeof TOKEN_SYMBOLS_MAP].coingeckoId;
|
|
75
72
|
}
|
|
76
73
|
|
|
@@ -108,31 +105,26 @@ export function isStablecoin(tokenSymbol: string): boolean {
|
|
|
108
105
|
* @notice Returns the Token info for the token mapping in TOKEN_SYMBOLS_MAP matching the given l2TokenAddress
|
|
109
106
|
* and chainId. If the chain is the hub chain, then will remap the L1 token to its equivalent L1 token symbol for example
|
|
110
107
|
* it will always return a token info with symbol USDC and never USDC.e if chainId = mainnet.
|
|
111
|
-
* @param
|
|
112
|
-
* @param chainId
|
|
113
|
-
* @param tokenMapping
|
|
114
|
-
* @returns
|
|
108
|
+
* @param l2Token Address instance.
|
|
109
|
+
* @param chainId ChainId for l2Token address.
|
|
110
|
+
* @param tokenMapping Optional custom token mapping.
|
|
111
|
+
* @returns TokenInfo object.
|
|
115
112
|
*/
|
|
116
|
-
export function getTokenInfo(
|
|
117
|
-
const
|
|
113
|
+
export function getTokenInfo(l2Token: Address, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): TokenInfo {
|
|
114
|
+
const address = l2Token.toNative();
|
|
118
115
|
|
|
119
116
|
// @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
|
|
120
117
|
// to get around this...
|
|
121
|
-
let tokenObject = Object.values(tokenMapping).find(({ addresses }) => addresses[chainId] ===
|
|
118
|
+
let tokenObject = Object.values(tokenMapping).find(({ addresses }) => addresses[chainId] === address);
|
|
122
119
|
if (!tokenObject) {
|
|
123
|
-
throw new Error(
|
|
124
|
-
`TokenUtils#getTokenInfo: Unable to resolve token in TOKEN_SYMBOLS_MAP for ${l2TokenAddress} on chain ${chainId}`
|
|
125
|
-
);
|
|
120
|
+
throw new Error(`Unable to resolve token info for ${address} on chain ${chainId}`);
|
|
126
121
|
}
|
|
127
122
|
if (chainIsL1(chainId)) {
|
|
128
123
|
const l1TokenSymbol = TOKEN_EQUIVALENCE_REMAPPING[tokenObject.symbol] ?? tokenObject.symbol;
|
|
129
124
|
tokenObject = tokenMapping[l1TokenSymbol as keyof typeof tokenMapping];
|
|
130
125
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
symbol: tokenObject.symbol,
|
|
134
|
-
decimals: tokenObject.decimals,
|
|
135
|
-
};
|
|
126
|
+
|
|
127
|
+
return { address: l2Token, symbol: tokenObject.symbol, decimals: tokenObject.decimals };
|
|
136
128
|
}
|
|
137
129
|
|
|
138
130
|
/**
|
|
@@ -141,26 +133,30 @@ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMappi
|
|
|
141
133
|
* @param chainId A chain Id to reference
|
|
142
134
|
* @returns Either USDC (if native) or USDbC/USDC.e (if bridged) or undefined if the token address is not recognized.
|
|
143
135
|
*/
|
|
144
|
-
export function getUsdcSymbol(l2Token:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)
|
|
136
|
+
export function getUsdcSymbol(l2Token: Address, chainId: number): string | undefined {
|
|
137
|
+
type TokenRecord = Record<string, { addresses?: Record<number, string> }>;
|
|
138
|
+
const IterableTokenSymbolsMap = TOKEN_SYMBOLS_MAP as TokenRecord;
|
|
139
|
+
return ["USDC", "USDbC", "USDC.e"].find(
|
|
140
|
+
(token) => IterableTokenSymbolsMap[token]?.addresses?.[chainId] === l2Token.toNative()
|
|
150
141
|
);
|
|
151
142
|
}
|
|
152
143
|
|
|
153
144
|
/**
|
|
154
145
|
* @notice Returns the l1 token address matching the given l2TokenAddress and chainId.
|
|
155
146
|
*/
|
|
156
|
-
export function getL1TokenAddress(l2TokenAddress:
|
|
157
|
-
if (chainIsL1(chainId))
|
|
158
|
-
|
|
147
|
+
export function getL1TokenAddress(l2TokenAddress: Address, chainId: number): EvmAddress {
|
|
148
|
+
if (chainIsL1(chainId)) {
|
|
149
|
+
assert(l2TokenAddress.isEVM());
|
|
150
|
+
return l2TokenAddress;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const tokenObject = Object.values(TOKEN_SYMBOLS_MAP).find(
|
|
154
|
+
({ addresses }) => l2TokenAddress.toNative() === addresses[chainId]
|
|
155
|
+
);
|
|
159
156
|
const l1TokenAddress = tokenObject?.addresses[chainIsProd(chainId) ? CHAIN_IDs.MAINNET : CHAIN_IDs.SEPOLIA];
|
|
160
157
|
if (!l1TokenAddress) {
|
|
161
|
-
throw new Error(
|
|
162
|
-
`TokenUtils#getL1TokenInfo: Unable to resolve l1 token address in TOKEN_SYMBOLS_MAP for L2 token ${l2TokenAddress} on chain ${chainId}`
|
|
163
|
-
);
|
|
158
|
+
throw new Error(`getL1TokenAddress: Unable to resolve l1 token for L2 token ${l2TokenAddress} on chain ${chainId}`);
|
|
164
159
|
}
|
|
165
|
-
|
|
160
|
+
|
|
161
|
+
return EvmAddress.from(l1TokenAddress);
|
|
166
162
|
}
|