@across-protocol/sdk 4.2.9-alpha.1 → 4.2.9-alpha.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/arch/evm/SpokeUtils.d.ts +5 -2
- package/dist/cjs/arch/evm/SpokeUtils.js +22 -5
- package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/SpokeUtils.js +14 -11
- package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/utils.d.ts +1 -1
- package/dist/cjs/arch/svm/utils.js +15 -13
- package/dist/cjs/arch/svm/utils.js.map +1 -1
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +60 -56
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +13 -13
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +3 -2
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +3 -3
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +11 -8
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/cjs/clients/HubPoolClient.d.ts +21 -21
- package/dist/cjs/clients/HubPoolClient.js +83 -59
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -2
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +5 -3
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +55 -49
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +9 -9
- package/dist/cjs/clients/mocks/MockHubPoolClient.js +15 -9
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +9 -13
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +42 -56
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +2 -2
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
- package/dist/cjs/interfaces/HubPool.d.ts +19 -14
- package/dist/cjs/interfaces/SpokePool.d.ts +14 -16
- package/dist/cjs/interfaces/SpokePool.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +7 -7
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +4 -4
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +14 -15
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +7 -7
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +6 -3
- package/dist/cjs/utils/AddressUtils.js +42 -14
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.d.ts +3 -3
- package/dist/cjs/utils/SpokeUtils.js +4 -22
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/cjs/utils/TokenUtils.d.ts +4 -4
- package/dist/cjs/utils/TokenUtils.js +3 -3
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/esm/arch/evm/SpokeUtils.d.ts +5 -2
- package/dist/esm/arch/evm/SpokeUtils.js +23 -6
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.js +14 -11
- package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/utils.d.ts +1 -1
- package/dist/esm/arch/svm/utils.js +15 -13
- package/dist/esm/arch/svm/utils.js.map +1 -1
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +61 -57
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +14 -14
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +4 -3
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -4
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +12 -9
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +23 -22
- package/dist/esm/clients/HubPoolClient.js +96 -63
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +3 -3
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +5 -3
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +57 -50
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +9 -9
- package/dist/esm/clients/mocks/MockHubPoolClient.js +16 -10
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +9 -13
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +46 -60
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +3 -3
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
- package/dist/esm/interfaces/HubPool.d.ts +19 -14
- package/dist/esm/interfaces/SpokePool.d.ts +14 -16
- package/dist/esm/interfaces/SpokePool.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +8 -8
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +4 -4
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +15 -16
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +8 -8
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +7 -3
- package/dist/esm/utils/AddressUtils.js +52 -19
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.d.ts +3 -8
- package/dist/esm/utils/SpokeUtils.js +4 -26
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/TokenUtils.d.ts +18 -16
- package/dist/esm/utils/TokenUtils.js +3 -3
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/types/arch/evm/SpokeUtils.d.ts +5 -2
- package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/utils.d.ts +1 -1
- package/dist/types/arch/svm/utils.d.ts.map +1 -1
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +23 -22
- package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +5 -3
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts +9 -9
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +9 -13
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
- package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts.map +1 -1
- package/dist/types/interfaces/HubPool.d.ts +19 -14
- package/dist/types/interfaces/HubPool.d.ts.map +1 -1
- package/dist/types/interfaces/SpokePool.d.ts +14 -16
- package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +4 -4
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +7 -3
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/SpokeUtils.d.ts +3 -8
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/dist/types/utils/TokenUtils.d.ts +18 -16
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +1 -2
- package/src/arch/evm/SpokeUtils.ts +41 -11
- package/src/arch/svm/SpokeUtils.ts +23 -9
- package/src/arch/svm/utils.ts +3 -3
- package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
- package/src/clients/BundleDataClient/BundleDataClient.ts +54 -52
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +28 -13
- package/src/clients/BundleDataClient/utils/FillUtils.ts +6 -4
- package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +7 -1
- package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
- package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +13 -9
- package/src/clients/HubPoolClient.ts +122 -82
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +7 -1
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +113 -43
- package/src/clients/mocks/MockHubPoolClient.ts +24 -19
- package/src/clients/mocks/MockSpokePoolClient.ts +55 -74
- package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
- package/src/interfaces/HubPool.ts +23 -14
- package/src/interfaces/SpokePool.ts +14 -17
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +10 -8
- package/src/relayFeeCalculator/chain-queries/svmQuery.ts +16 -21
- package/src/relayFeeCalculator/relayFeeCalculator.ts +20 -12
- package/src/utils/AddressUtils.ts +56 -21
- package/src/utils/SpokeUtils.ts +11 -33
- package/src/utils/TokenUtils.ts +7 -7
|
@@ -9,12 +9,9 @@ import { Deposit } from "../interfaces";
|
|
|
9
9
|
import {
|
|
10
10
|
BigNumber,
|
|
11
11
|
BigNumberish,
|
|
12
|
-
ConvertDecimals,
|
|
13
12
|
MAX_BIG_INT,
|
|
14
13
|
TransactionCostEstimate,
|
|
15
14
|
bnZero,
|
|
16
|
-
chainIsSvm,
|
|
17
|
-
compareAddressesSimple,
|
|
18
15
|
fixedPointAdjustment,
|
|
19
16
|
getTokenInfo,
|
|
20
17
|
isDefined,
|
|
@@ -25,13 +22,18 @@ import {
|
|
|
25
22
|
percent,
|
|
26
23
|
toBN,
|
|
27
24
|
toBNWei,
|
|
25
|
+
compareAddressesSimple,
|
|
26
|
+
ConvertDecimals,
|
|
27
|
+
chainIsSvm,
|
|
28
|
+
toAddressType,
|
|
29
|
+
Address,
|
|
28
30
|
} from "../utils";
|
|
29
31
|
|
|
30
32
|
// This needs to be implemented for every chain and passed into RelayFeeCalculator
|
|
31
33
|
export interface QueryInterface {
|
|
32
34
|
getGasCosts: (
|
|
33
35
|
deposit: Omit<Deposit, "messageHash">,
|
|
34
|
-
relayer:
|
|
36
|
+
relayer: Address,
|
|
35
37
|
options?: Partial<{
|
|
36
38
|
gasPrice: BigNumberish;
|
|
37
39
|
gasUnits: BigNumberish;
|
|
@@ -42,7 +44,7 @@ export interface QueryInterface {
|
|
|
42
44
|
}>
|
|
43
45
|
) => Promise<TransactionCostEstimate>;
|
|
44
46
|
getTokenPrice: (tokenSymbol: string) => Promise<number>;
|
|
45
|
-
getNativeGasCost: (deposit: Omit<Deposit, "messageHash">, relayer:
|
|
47
|
+
getNativeGasCost: (deposit: Omit<Deposit, "messageHash">, relayer: Address) => Promise<BigNumber>;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
export const expectedCapitalCostsKeys = ["lowerBound", "upperBound", "cutoff", "decimals"];
|
|
@@ -254,7 +256,10 @@ export class RelayFeeCalculator {
|
|
|
254
256
|
deposit: Deposit,
|
|
255
257
|
outputAmount: BigNumberish,
|
|
256
258
|
simulateZeroFill = false,
|
|
257
|
-
relayerAddress =
|
|
259
|
+
relayerAddress = toAddressType(
|
|
260
|
+
getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
261
|
+
deposit.destinationChainId
|
|
262
|
+
),
|
|
258
263
|
_tokenPrice?: number,
|
|
259
264
|
tokenMapping = TOKEN_SYMBOLS_MAP,
|
|
260
265
|
gasPrice?: BigNumberish,
|
|
@@ -271,14 +276,14 @@ export class RelayFeeCalculator {
|
|
|
271
276
|
// undefined address on destination.
|
|
272
277
|
const destinationChainTokenDetails = Object.values(tokenMapping).find(
|
|
273
278
|
(details) =>
|
|
274
|
-
compareAddressesSimple(details.addresses[originChainId], inputToken) &&
|
|
279
|
+
compareAddressesSimple(details.addresses[originChainId], inputToken.toAddress()) &&
|
|
275
280
|
isDefined(details.addresses[destinationChainId])
|
|
276
281
|
);
|
|
277
282
|
const outputToken = isZeroAddress(deposit.outputToken)
|
|
278
283
|
? destinationChainTokenDetails!.addresses[destinationChainId]
|
|
279
|
-
: deposit.outputToken;
|
|
284
|
+
: deposit.outputToken.toAddress();
|
|
280
285
|
const outputTokenInfo = getTokenInfo(outputToken, destinationChainId, tokenMapping);
|
|
281
|
-
const inputTokenInfo = getTokenInfo(inputToken, originChainId, tokenMapping);
|
|
286
|
+
const inputTokenInfo = getTokenInfo(inputToken.toAddress(), originChainId, tokenMapping);
|
|
282
287
|
if (!isDefined(outputTokenInfo) || !isDefined(inputTokenInfo)) {
|
|
283
288
|
throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
|
|
284
289
|
}
|
|
@@ -493,7 +498,10 @@ export class RelayFeeCalculator {
|
|
|
493
498
|
deposit: Deposit,
|
|
494
499
|
outputAmount?: BigNumberish,
|
|
495
500
|
simulateZeroFill = false,
|
|
496
|
-
relayerAddress =
|
|
501
|
+
relayerAddress = toAddressType(
|
|
502
|
+
getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
503
|
+
deposit.destinationChainId
|
|
504
|
+
),
|
|
497
505
|
_tokenPrice?: number,
|
|
498
506
|
gasPrice?: BigNumberish,
|
|
499
507
|
gasUnits?: BigNumberish,
|
|
@@ -505,8 +513,8 @@ export class RelayFeeCalculator {
|
|
|
505
513
|
const { inputToken, originChainId, outputToken, destinationChainId } = deposit;
|
|
506
514
|
// We can perform a simple lookup with `getTokenInfo` here without resolving the exact token to resolve since we only need to
|
|
507
515
|
// resolve the L1 token symbol and not the L2 token decimals.
|
|
508
|
-
const inputTokenInfo = getTokenInfo(inputToken, originChainId);
|
|
509
|
-
const outputTokenInfo = getTokenInfo(outputToken, destinationChainId);
|
|
516
|
+
const inputTokenInfo = getTokenInfo(inputToken.toAddress(), originChainId);
|
|
517
|
+
const outputTokenInfo = getTokenInfo(outputToken.toAddress(), destinationChainId);
|
|
510
518
|
if (!isDefined(inputTokenInfo) || !isDefined(outputTokenInfo)) {
|
|
511
519
|
throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
|
|
512
520
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { providers, utils } from "ethers";
|
|
2
|
+
import assert from "assert";
|
|
2
3
|
import bs58 from "bs58";
|
|
3
4
|
import { Address as V2Address } from "@solana/kit";
|
|
4
|
-
import { BigNumber, chainIsEvm } from "./";
|
|
5
|
+
import { BigNumber, chainIsEvm, isDefined } from "./";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Checks if a contract is deployed at the given address
|
|
@@ -75,20 +76,39 @@ export function isValidEvmAddress(address: string): boolean {
|
|
|
75
76
|
* Creates the proper address type given the input chain ID corresponding to the address's origin network.
|
|
76
77
|
* @param address Stringified address type to convert. Can be either hex encoded or base58 encoded.
|
|
77
78
|
* @param chainId Network ID corresponding to the input address, used to determine which address type to output.
|
|
79
|
+
* If no chain ID is specified, then fallback to inference via the structure of the address string.
|
|
78
80
|
* @returns a child `Address` type most fitting for the chain ID.
|
|
79
81
|
* @todo: Change this to `toAddress` once we remove the other `toAddress` function.
|
|
80
82
|
*/
|
|
81
|
-
export function toAddressType(address: string): Address | EvmAddress | SvmAddress {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
export function toAddressType(address: string, chainId?: number): Address | EvmAddress | SvmAddress {
|
|
84
|
+
const parseAddress = (address: string) => {
|
|
85
|
+
try {
|
|
86
|
+
if (utils.isHexString(address)) {
|
|
87
|
+
return EvmAddress.from(address);
|
|
88
|
+
}
|
|
89
|
+
return SvmAddress.from(address);
|
|
90
|
+
} catch (e) {
|
|
91
|
+
// If we hit this block, then the validation for one of the child address classes failed. We still may want to keep this address in our state, so
|
|
92
|
+
// return an unchecked address type.
|
|
93
|
+
assert(utils.isHexString(address));
|
|
94
|
+
assert(utils.hexDataLength(address) === 32);
|
|
95
|
+
return Address.__unsafeConstruct(utils.arrayify(address));
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
// If there is no network ID, then infer the address by the string format.
|
|
99
|
+
const addressType = parseAddress(address);
|
|
100
|
+
if (!isDefined(chainId)) {
|
|
101
|
+
return addressType;
|
|
102
|
+
}
|
|
103
|
+
// Wrap this in a try/catch in case we are trying to force an invalid EVM address to an EvmAddress type.
|
|
104
|
+
if (chainIsEvm(chainId)) {
|
|
105
|
+
try {
|
|
106
|
+
return addressType.forceEvmAddress();
|
|
107
|
+
} catch {
|
|
108
|
+
return addressType;
|
|
85
109
|
}
|
|
86
|
-
return SvmAddress.from(address);
|
|
87
|
-
} catch (e) {
|
|
88
|
-
// If we hit this block, then the validation for one of the child address classes failed. We still may want to keep this address in our state, so
|
|
89
|
-
// return an unchecked address type.
|
|
90
|
-
return new Address(utils.arrayify(address));
|
|
91
110
|
}
|
|
111
|
+
return addressType.forceSvmAddress();
|
|
92
112
|
}
|
|
93
113
|
|
|
94
114
|
// The Address class can contain any address type. It is up to the subclasses to determine how to format the address's internal representation,
|
|
@@ -113,12 +133,24 @@ export class Address {
|
|
|
113
133
|
this.rawAddress = utils.zeroPad(_rawAddress, 32);
|
|
114
134
|
}
|
|
115
135
|
|
|
136
|
+
static __unsafeConstruct(_rawAddress: Uint8Array): Address {
|
|
137
|
+
return new this(_rawAddress);
|
|
138
|
+
}
|
|
139
|
+
|
|
116
140
|
// Converts the address into a bytes32 string. Note that the output bytes will be lowercase so that it matches ethers event data. This function will never
|
|
117
141
|
// throw since address length validation was done at construction time.
|
|
118
142
|
toBytes32(): string {
|
|
119
143
|
return (this.bytes32Address ??= utils.hexZeroPad(utils.hexlify(this.rawAddress), 32).toLowerCase());
|
|
120
144
|
}
|
|
121
145
|
|
|
146
|
+
// Returns last 20 bytes of Address as a hex string. Truncates if necessary. This function is useful for comparing some longer addresses(e.g. Solana) to Solidity events
|
|
147
|
+
// that contain truncated `address` type as one of the fields
|
|
148
|
+
truncateToBytes20(): string {
|
|
149
|
+
// Take the last 20 bytes
|
|
150
|
+
const bytes20 = this.rawAddress.slice(-20);
|
|
151
|
+
return toAddress(utils.hexlify(bytes20));
|
|
152
|
+
}
|
|
153
|
+
|
|
122
154
|
// Converts the address (can be bytes32 or bytes20) to its base58 counterpart. This conversion will always succeed, even if the input address is not valid on Solana,
|
|
123
155
|
// as this address may be needed to represent an EVM address on Solana.
|
|
124
156
|
toBase58(): string {
|
|
@@ -160,7 +192,7 @@ export class Address {
|
|
|
160
192
|
// Checks if this address can be coerced into a bytes20 evm address. Returns true if it is possible and false otherwise.
|
|
161
193
|
isValidEvmAddress(): boolean {
|
|
162
194
|
try {
|
|
163
|
-
this.
|
|
195
|
+
this.toEvmAddress();
|
|
164
196
|
return true;
|
|
165
197
|
} catch {
|
|
166
198
|
return false;
|
|
@@ -191,6 +223,11 @@ export class Address {
|
|
|
191
223
|
return utils.stripZeros(this.rawAddress).length === 0;
|
|
192
224
|
}
|
|
193
225
|
|
|
226
|
+
// Small utility to convert an Address to a Solana Kit branded type.
|
|
227
|
+
toV2Address(): V2Address<string> {
|
|
228
|
+
return this.toBase58() as V2Address<string>;
|
|
229
|
+
}
|
|
230
|
+
|
|
194
231
|
// Forces `rawAddress` to become an SvmAddress type. This will only throw if `rawAddress.length > 32`.
|
|
195
232
|
forceSvmAddress(): SvmAddress {
|
|
196
233
|
return SvmAddress.from(this.toBase58());
|
|
@@ -220,6 +257,14 @@ export class Address {
|
|
|
220
257
|
return 0;
|
|
221
258
|
}
|
|
222
259
|
}
|
|
260
|
+
|
|
261
|
+
static isEvmAddress(address: Address): boolean {
|
|
262
|
+
return address instanceof EvmAddress;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
static isSvmAddress(address: Address): boolean {
|
|
266
|
+
return address instanceof SvmAddress;
|
|
267
|
+
}
|
|
223
268
|
}
|
|
224
269
|
|
|
225
270
|
// Subclass of address which strictly deals with 20-byte addresses. These addresses are guaranteed to be valid EVM addresses, so `toAddress` will always succeed.
|
|
@@ -269,16 +314,6 @@ export class SvmAddress extends Address {
|
|
|
269
314
|
return this.toBase58();
|
|
270
315
|
}
|
|
271
316
|
|
|
272
|
-
// Small utility to convert an SvmAddress to a Solana Kit branded type.
|
|
273
|
-
toV2Address(): V2Address<string> {
|
|
274
|
-
return this.toBase58() as V2Address<string>;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// Forces an SvmAddress to an EVM address string by truncating the leading 12 bytes.
|
|
278
|
-
override toEvmAddress(): string {
|
|
279
|
-
return toAddress(`0x${this.toBytes32().slice(-40)}`);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
317
|
// Constructs a new SvmAddress type.
|
|
283
318
|
static from(address: string, encoding: "base58" | "base16" = "base58"): SvmAddress {
|
|
284
319
|
if (encoding === "base58") {
|
package/src/utils/SpokeUtils.ts
CHANGED
|
@@ -1,34 +1,12 @@
|
|
|
1
1
|
import { encodeAbiParameters, Hex, keccak256 } from "viem";
|
|
2
|
-
import { MAX_SAFE_DEPOSIT_ID,
|
|
3
|
-
import {
|
|
4
|
-
import { toBytes32 } from "./AddressUtils";
|
|
2
|
+
import { MAX_SAFE_DEPOSIT_ID, ZERO_BYTES } from "../constants";
|
|
3
|
+
import { RelayData } from "../interfaces";
|
|
5
4
|
import { BigNumber } from "./BigNumberUtils";
|
|
5
|
+
import { Address } from "./AddressUtils";
|
|
6
6
|
import { isMessageEmpty } from "./DepositUtils";
|
|
7
7
|
import { chainIsSvm } from "./NetworkUtils";
|
|
8
8
|
import { svm } from "../arch";
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Produce the RelayData for a Deposit.
|
|
12
|
-
* @param deposit Deposit instance.
|
|
13
|
-
* @returns The corresponding RelayData object.
|
|
14
|
-
*/
|
|
15
|
-
export function getDepositRelayData(deposit: Omit<Deposit, "messageHash">): RelayData {
|
|
16
|
-
return {
|
|
17
|
-
depositor: toBytes32(deposit.depositor),
|
|
18
|
-
recipient: toBytes32(deposit.recipient),
|
|
19
|
-
exclusiveRelayer: toBytes32(deposit.exclusiveRelayer),
|
|
20
|
-
inputToken: toBytes32(deposit.inputToken),
|
|
21
|
-
outputToken: toBytes32(deposit.outputToken),
|
|
22
|
-
inputAmount: deposit.inputAmount,
|
|
23
|
-
outputAmount: deposit.outputAmount,
|
|
24
|
-
originChainId: deposit.originChainId,
|
|
25
|
-
depositId: deposit.depositId,
|
|
26
|
-
fillDeadline: deposit.fillDeadline,
|
|
27
|
-
exclusivityDeadline: deposit.exclusivityDeadline,
|
|
28
|
-
message: deposit.message,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
10
|
/**
|
|
33
11
|
* Compute the RelayData hash for a fill. This can be used to determine the fill status.
|
|
34
12
|
* @param relayData RelayData information that is used to complete a fill.
|
|
@@ -59,14 +37,14 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId: numbe
|
|
|
59
37
|
|
|
60
38
|
const _relayData = {
|
|
61
39
|
...relayData,
|
|
62
|
-
depositor:
|
|
63
|
-
recipient:
|
|
64
|
-
inputToken:
|
|
65
|
-
outputToken:
|
|
66
|
-
exclusiveRelayer:
|
|
40
|
+
depositor: relayData.depositor.toBytes32(),
|
|
41
|
+
recipient: relayData.recipient.toBytes32(),
|
|
42
|
+
inputToken: relayData.inputToken.toBytes32(),
|
|
43
|
+
outputToken: relayData.outputToken.toBytes32(),
|
|
44
|
+
exclusiveRelayer: relayData.exclusiveRelayer.toBytes32(),
|
|
67
45
|
};
|
|
68
46
|
if (chainIsSvm(destinationChainId)) {
|
|
69
|
-
return svm.getRelayDataHash(
|
|
47
|
+
return svm.getRelayDataHash(relayData, destinationChainId);
|
|
70
48
|
}
|
|
71
49
|
return keccak256(encodeAbiParameters(abi, [_relayData, destinationChainId]));
|
|
72
50
|
}
|
|
@@ -86,8 +64,8 @@ export function isUnsafeDepositId(depositId: BigNumber): boolean {
|
|
|
86
64
|
}
|
|
87
65
|
|
|
88
66
|
// Determines if the input address (either a bytes32 or bytes20) is the zero address.
|
|
89
|
-
export function isZeroAddress(address:
|
|
90
|
-
return address ===
|
|
67
|
+
export function isZeroAddress(address: Address): boolean {
|
|
68
|
+
return address.toBytes32() === ZERO_BYTES;
|
|
91
69
|
}
|
|
92
70
|
|
|
93
71
|
export function getMessageHash(message: string): string {
|
package/src/utils/TokenUtils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BlockTag } from "@ethersproject/abstract-provider";
|
|
2
2
|
import { Contract, providers, Signer } from "ethers";
|
|
3
3
|
import * as constants from "../constants";
|
|
4
|
-
import {
|
|
4
|
+
import { TokenInfo } from "../interfaces";
|
|
5
5
|
import { ERC20__factory } from "../typechain";
|
|
6
6
|
import { BigNumber } from "./BigNumberUtils";
|
|
7
7
|
import { getNetworkName, chainIsL1, chainIsProd, chainIsSvm } from "./NetworkUtils";
|
|
@@ -11,10 +11,10 @@ const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
|
|
|
11
11
|
|
|
12
12
|
type SignerOrProvider = providers.Provider | Signer;
|
|
13
13
|
|
|
14
|
-
export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<
|
|
14
|
+
export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<TokenInfo> {
|
|
15
15
|
const token = new Contract(address, ERC20__factory.abi, signerOrProvider);
|
|
16
16
|
const [symbol, decimals] = await Promise.all([token.symbol(), token.decimals()]);
|
|
17
|
-
return { address, symbol, decimals };
|
|
17
|
+
return { address: toAddressType(address).forceEvmAddress(), symbol, decimals };
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export const getL2TokenAddresses = (
|
|
@@ -33,7 +33,7 @@ export const getL2TokenAddresses = (
|
|
|
33
33
|
* @param chainId Chain ID to query on.
|
|
34
34
|
* @returns Symbol, decimals and contract address on the requested chain.
|
|
35
35
|
*/
|
|
36
|
-
export function resolveSymbolOnChain(chainId: number, symbol: string):
|
|
36
|
+
export function resolveSymbolOnChain(chainId: number, symbol: string): TokenInfo {
|
|
37
37
|
// @dev Suppress tsc complaints by casting symbol to the expected type.
|
|
38
38
|
const token = TOKEN_SYMBOLS_MAP[symbol as keyof typeof TOKEN_SYMBOLS_MAP];
|
|
39
39
|
if (!isDefined(token) || !isDefined(token.addresses[chainId])) {
|
|
@@ -44,7 +44,7 @@ export function resolveSymbolOnChain(chainId: number, symbol: string): L1Token {
|
|
|
44
44
|
const { decimals, addresses } = token;
|
|
45
45
|
const address = addresses[chainId];
|
|
46
46
|
|
|
47
|
-
return { symbol, decimals, address };
|
|
47
|
+
return { symbol, decimals, address: toAddressType(address, chainId) };
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -111,7 +111,7 @@ export function isStablecoin(tokenSymbol: string): boolean {
|
|
|
111
111
|
* @param tokenMapping
|
|
112
112
|
* @returns
|
|
113
113
|
*/
|
|
114
|
-
export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP):
|
|
114
|
+
export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): TokenInfo {
|
|
115
115
|
const parsedAddress = chainIsSvm(chainId)
|
|
116
116
|
? toAddressType(l2TokenAddress).toBase58()
|
|
117
117
|
: toAddressType(l2TokenAddress).toEvmAddress();
|
|
@@ -128,7 +128,7 @@ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMappi
|
|
|
128
128
|
tokenObject = tokenMapping[l1TokenSymbol as keyof typeof tokenMapping];
|
|
129
129
|
}
|
|
130
130
|
return {
|
|
131
|
-
address: l2TokenAddress,
|
|
131
|
+
address: toAddressType(l2TokenAddress, chainId),
|
|
132
132
|
symbol: tokenObject.symbol,
|
|
133
133
|
decimals: tokenObject.decimals,
|
|
134
134
|
};
|