@across-protocol/sdk 4.1.47 → 4.1.48
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/HubPoolClient.d.ts +0 -1
- package/dist/cjs/clients/HubPoolClient.js +0 -4
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/coingecko/Coingecko.js +1 -1
- package/dist/cjs/coingecko/Coingecko.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -1
- package/dist/cjs/constants.js +4 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/gasPriceOracle/oracle.js +1 -0
- package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.d.ts +56 -0
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +56 -0
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +13 -6
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/TokenUtils.d.ts +118 -7
- package/dist/cjs/utils/TokenUtils.js +12 -20
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +0 -1
- package/dist/esm/clients/HubPoolClient.js +0 -4
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/coingecko/Coingecko.js +1 -1
- package/dist/esm/coingecko/Coingecko.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -1
- package/dist/esm/constants.js +3 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/gasPriceOracle/oracle.js +1 -0
- package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/factory.d.ts +56 -0
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +61 -11
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +14 -7
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/TokenUtils.d.ts +138 -15
- package/dist/esm/utils/TokenUtils.js +12 -19
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +0 -1
- package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts +56 -0
- package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +61 -11
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/TokenUtils.d.ts +138 -15
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/clients/HubPoolClient.ts +0 -5
- package/src/coingecko/Coingecko.ts +1 -1
- package/src/constants.ts +3 -0
- package/src/gasPriceOracle/oracle.ts +1 -0
- package/src/relayFeeCalculator/relayFeeCalculator.ts +21 -5
- package/src/utils/TokenUtils.ts +10 -19
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
TransactionCostEstimate,
|
|
9
9
|
bnZero,
|
|
10
10
|
fixedPointAdjustment,
|
|
11
|
-
|
|
11
|
+
getTokenInfo,
|
|
12
12
|
isDefined,
|
|
13
13
|
max,
|
|
14
14
|
min,
|
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
percent,
|
|
17
17
|
toBN,
|
|
18
18
|
toBNWei,
|
|
19
|
+
isZeroAddress,
|
|
20
|
+
compareAddressesSimple,
|
|
19
21
|
} from "../utils";
|
|
20
22
|
import { Transport } from "viem";
|
|
21
23
|
|
|
@@ -243,8 +245,20 @@ export class RelayFeeCalculator {
|
|
|
243
245
|
): Promise<BigNumber> {
|
|
244
246
|
if (toBN(amountToRelay).eq(bnZero)) return MAX_BIG_INT;
|
|
245
247
|
|
|
246
|
-
const { inputToken } = deposit;
|
|
247
|
-
|
|
248
|
+
const { inputToken, destinationChainId, originChainId } = deposit;
|
|
249
|
+
// It's fine if we resolve a destination token which is not the "canonical" L1 token (e.g. USDB for DAI or USDC.e for USDC), since `getTokenInfo` will re-map
|
|
250
|
+
// the output token to the canonical version. What matters here is that we find an entry in the token map which has defined addresses for BOTH the origin
|
|
251
|
+
// and destination chain. This prevents the call to `getTokenInfo` to mistakenly return token info for a token which has a defined address on origin and an
|
|
252
|
+
// undefined address on destination.
|
|
253
|
+
const destinationChainTokenDetails = Object.values(tokenMapping).find(
|
|
254
|
+
(details) =>
|
|
255
|
+
compareAddressesSimple(details.addresses[originChainId], inputToken) &&
|
|
256
|
+
isDefined(details.addresses[destinationChainId])
|
|
257
|
+
);
|
|
258
|
+
const outputToken = isZeroAddress(deposit.outputToken)
|
|
259
|
+
? destinationChainTokenDetails!.addresses[destinationChainId]
|
|
260
|
+
: deposit.outputToken;
|
|
261
|
+
const token = getTokenInfo(outputToken, destinationChainId, tokenMapping);
|
|
248
262
|
if (!isDefined(token)) {
|
|
249
263
|
throw new Error(`Could not find token information for ${inputToken}`);
|
|
250
264
|
}
|
|
@@ -369,8 +383,10 @@ export class RelayFeeCalculator {
|
|
|
369
383
|
// If the amount to relay is not provided, then we
|
|
370
384
|
// should use the full deposit amount.
|
|
371
385
|
amountToRelay ??= deposit.outputAmount;
|
|
372
|
-
const { inputToken } = deposit;
|
|
373
|
-
|
|
386
|
+
const { inputToken, originChainId } = deposit;
|
|
387
|
+
// We can perform a simple lookup with `getTokenInfo` here without resolving the exact token to resolve since we only need to
|
|
388
|
+
// resolve the L1 token symbol and not the L2 token decimals.
|
|
389
|
+
const token = getTokenInfo(inputToken, originChainId);
|
|
374
390
|
if (!isDefined(token)) {
|
|
375
391
|
throw new Error(`Could not find token information for ${inputToken}`);
|
|
376
392
|
}
|
package/src/utils/TokenUtils.ts
CHANGED
|
@@ -4,10 +4,10 @@ import * as constants from "../constants";
|
|
|
4
4
|
import { L1Token } from "../interfaces";
|
|
5
5
|
import { ERC20__factory } from "../typechain";
|
|
6
6
|
import { BigNumber } from "./BigNumberUtils";
|
|
7
|
-
import { getNetworkName } from "./NetworkUtils";
|
|
7
|
+
import { getNetworkName, chainIsL1 } from "./NetworkUtils";
|
|
8
8
|
import { isDefined } from "./TypeGuards";
|
|
9
9
|
import { compareAddressesSimple } from "./AddressUtils";
|
|
10
|
-
const { TOKEN_SYMBOLS_MAP, CHAIN_IDs } = constants;
|
|
10
|
+
const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
|
|
11
11
|
|
|
12
12
|
type SignerOrProvider = providers.Provider | Signer;
|
|
13
13
|
|
|
@@ -64,21 +64,8 @@ export const resolveContractFromSymbol = (
|
|
|
64
64
|
})?.addresses[Number(chainId)];
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
export function
|
|
68
|
-
const
|
|
69
|
-
return Object.values(details.addresses).some((t) => t.toLowerCase() === address.toLowerCase());
|
|
70
|
-
});
|
|
71
|
-
return isDefined(details)
|
|
72
|
-
? {
|
|
73
|
-
decimals: details.decimals,
|
|
74
|
-
symbol: details.symbol,
|
|
75
|
-
address,
|
|
76
|
-
}
|
|
77
|
-
: undefined;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function getCoingeckoTokenIdByAddress(contractAddress: string): string {
|
|
81
|
-
const token = getTokenInformationFromAddress(contractAddress);
|
|
67
|
+
export function getCoingeckoTokenIdByAddress(contractAddress: string, chainId: number): string {
|
|
68
|
+
const token = getTokenInfo(contractAddress, chainId);
|
|
82
69
|
if (!token) {
|
|
83
70
|
throw new Error(`Token with address ${contractAddress} not found in token mapping`);
|
|
84
71
|
}
|
|
@@ -115,15 +102,19 @@ export function isStablecoin(tokenSymbol: string): boolean {
|
|
|
115
102
|
);
|
|
116
103
|
}
|
|
117
104
|
|
|
118
|
-
export function getTokenInfo(l2TokenAddress: string, chainId: number): L1Token {
|
|
105
|
+
export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): L1Token {
|
|
119
106
|
// @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
|
|
120
107
|
// to get around this...
|
|
121
|
-
|
|
108
|
+
let tokenObject = Object.values(tokenMapping).find(({ addresses }) => addresses[chainId] === l2TokenAddress);
|
|
122
109
|
if (!tokenObject) {
|
|
123
110
|
throw new Error(
|
|
124
111
|
`TokenUtils#getTokenInfo: Unable to resolve token in TOKEN_SYMBOLS_MAP for ${l2TokenAddress} on chain ${chainId}`
|
|
125
112
|
);
|
|
126
113
|
}
|
|
114
|
+
if (chainIsL1(chainId)) {
|
|
115
|
+
const l1TokenSymbol = TOKEN_EQUIVALENCE_REMAPPING[tokenObject.symbol] ?? tokenObject.symbol;
|
|
116
|
+
tokenObject = tokenMapping[l1TokenSymbol as keyof typeof tokenMapping];
|
|
117
|
+
}
|
|
127
118
|
return {
|
|
128
119
|
address: l2TokenAddress,
|
|
129
120
|
symbol: tokenObject.symbol,
|