@across-protocol/sdk 4.2.9-alpha.0 → 4.2.9-alpha.1
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 +2 -2
- package/dist/cjs/arch/evm/SpokeUtils.js +3 -18
- package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/SpokeUtils.d.ts +16 -1
- package/dist/cjs/arch/svm/SpokeUtils.js +135 -34
- package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/utils.d.ts +5 -1
- package/dist/cjs/arch/svm/utils.js +26 -16
- 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 +2 -4
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +2 -2
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +53 -57
- 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 +1 -2
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +2 -3
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.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 +8 -11
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/cjs/clients/HubPoolClient.d.ts +20 -20
- package/dist/cjs/clients/HubPoolClient.js +57 -78
- 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 +3 -5
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +29 -35
- 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 +9 -15
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +13 -9
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +56 -40
- 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 +13 -18
- package/dist/cjs/interfaces/SpokePool.d.ts +16 -14
- 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 +7 -8
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +73 -64
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +6 -6
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +7 -7
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +4 -7
- package/dist/cjs/utils/AddressUtils.js +8 -21
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.d.ts +3 -3
- package/dist/cjs/utils/SpokeUtils.js +22 -4
- 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 +2 -2
- package/dist/esm/arch/evm/SpokeUtils.js +4 -19
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.d.ts +46 -6
- package/dist/esm/arch/svm/SpokeUtils.js +164 -43
- package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/utils.d.ts +11 -1
- package/dist/esm/arch/svm/utils.js +31 -16
- 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 +2 -4
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +2 -2
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +54 -58
- 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 +1 -2
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +3 -4
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.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 +9 -12
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +21 -22
- package/dist/esm/clients/HubPoolClient.js +61 -91
- 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 +3 -5
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +30 -37
- 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 +10 -16
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +13 -9
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +60 -44
- 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 +13 -18
- package/dist/esm/interfaces/SpokePool.d.ts +16 -14
- 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 +8 -9
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +77 -66
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +6 -6
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +8 -8
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +4 -7
- package/dist/esm/utils/AddressUtils.js +10 -25
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.d.ts +8 -3
- package/dist/esm/utils/SpokeUtils.js +26 -4
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/TokenUtils.d.ts +16 -4
- 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 +2 -2
- package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/SpokeUtils.d.ts +46 -6
- package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/utils.d.ts +11 -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 +2 -2
- 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 +1 -2
- package/dist/types/clients/BundleDataClient/utils/FillUtils.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 +21 -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 +3 -5
- 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 +13 -9
- 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 +13 -18
- package/dist/types/interfaces/HubPool.d.ts.map +1 -1
- package/dist/types/interfaces/SpokePool.d.ts +16 -14
- 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 +8 -9
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +6 -6
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +4 -7
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/SpokeUtils.d.ts +8 -3
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/dist/types/utils/TokenUtils.d.ts +16 -4
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/arch/evm/SpokeUtils.ts +8 -22
- package/src/arch/svm/SpokeUtils.ts +156 -49
- package/src/arch/svm/utils.ts +22 -3
- package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +4 -7
- package/src/clients/BundleDataClient/BundleDataClient.ts +47 -49
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +13 -28
- package/src/clients/BundleDataClient/utils/FillUtils.ts +4 -6
- package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
- package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +9 -13
- package/src/clients/HubPoolClient.ts +79 -113
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +1 -7
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +37 -104
- package/src/clients/mocks/MockHubPoolClient.ts +19 -24
- package/src/clients/mocks/MockSpokePoolClient.ts +74 -53
- package/src/clients/mocks/MockSvmSpokePoolClient.ts +3 -12
- package/src/interfaces/HubPool.ts +13 -22
- package/src/interfaces/SpokePool.ts +17 -14
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +8 -10
- package/src/relayFeeCalculator/chain-queries/svmQuery.ts +92 -91
- package/src/relayFeeCalculator/relayFeeCalculator.ts +14 -16
- package/src/utils/AddressUtils.ts +14 -32
- package/src/utils/SpokeUtils.ts +33 -11
- package/src/utils/TokenUtils.ts +7 -7
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { providers, utils } from "ethers";
|
|
2
|
-
import assert from "assert";
|
|
3
2
|
import bs58 from "bs58";
|
|
4
3
|
import { Address as V2Address } from "@solana/kit";
|
|
5
4
|
import { BigNumber, chainIsEvm } from "./";
|
|
@@ -88,9 +87,7 @@ export function toAddressType(address: string): Address | EvmAddress | SvmAddres
|
|
|
88
87
|
} catch (e) {
|
|
89
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
|
|
90
89
|
// return an unchecked address type.
|
|
91
|
-
|
|
92
|
-
assert(utils.hexDataLength(address) === 32);
|
|
93
|
-
return Address.__unsafeConstruct(utils.arrayify(address));
|
|
90
|
+
return new Address(utils.arrayify(address));
|
|
94
91
|
}
|
|
95
92
|
}
|
|
96
93
|
|
|
@@ -116,24 +113,12 @@ export class Address {
|
|
|
116
113
|
this.rawAddress = utils.zeroPad(_rawAddress, 32);
|
|
117
114
|
}
|
|
118
115
|
|
|
119
|
-
static __unsafeConstruct(_rawAddress: Uint8Array): Address {
|
|
120
|
-
return new this(_rawAddress);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
116
|
// 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
|
|
124
117
|
// throw since address length validation was done at construction time.
|
|
125
118
|
toBytes32(): string {
|
|
126
119
|
return (this.bytes32Address ??= utils.hexZeroPad(utils.hexlify(this.rawAddress), 32).toLowerCase());
|
|
127
120
|
}
|
|
128
121
|
|
|
129
|
-
// 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
|
|
130
|
-
// that contain truncated `address` type as one of the fields
|
|
131
|
-
truncateToBytes20(): string {
|
|
132
|
-
// Take the last 20 bytes
|
|
133
|
-
const bytes20 = this.rawAddress.slice(-20);
|
|
134
|
-
return toAddress(utils.hexlify(bytes20));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
122
|
// 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,
|
|
138
123
|
// as this address may be needed to represent an EVM address on Solana.
|
|
139
124
|
toBase58(): string {
|
|
@@ -175,7 +160,7 @@ export class Address {
|
|
|
175
160
|
// Checks if this address can be coerced into a bytes20 evm address. Returns true if it is possible and false otherwise.
|
|
176
161
|
isValidEvmAddress(): boolean {
|
|
177
162
|
try {
|
|
178
|
-
this.
|
|
163
|
+
this.toAddress();
|
|
179
164
|
return true;
|
|
180
165
|
} catch {
|
|
181
166
|
return false;
|
|
@@ -206,11 +191,6 @@ export class Address {
|
|
|
206
191
|
return utils.stripZeros(this.rawAddress).length === 0;
|
|
207
192
|
}
|
|
208
193
|
|
|
209
|
-
// Small utility to convert an Address to a Solana Kit branded type.
|
|
210
|
-
toV2Address(): V2Address<string> {
|
|
211
|
-
return this.toBase58() as V2Address<string>;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
194
|
// Forces `rawAddress` to become an SvmAddress type. This will only throw if `rawAddress.length > 32`.
|
|
215
195
|
forceSvmAddress(): SvmAddress {
|
|
216
196
|
return SvmAddress.from(this.toBase58());
|
|
@@ -240,20 +220,12 @@ export class Address {
|
|
|
240
220
|
return 0;
|
|
241
221
|
}
|
|
242
222
|
}
|
|
243
|
-
|
|
244
|
-
static isEvmAddress(address: Address): boolean {
|
|
245
|
-
return address instanceof EvmAddress;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
static isSvmAddress(address: Address): boolean {
|
|
249
|
-
return address instanceof SvmAddress;
|
|
250
|
-
}
|
|
251
223
|
}
|
|
252
224
|
|
|
253
225
|
// Subclass of address which strictly deals with 20-byte addresses. These addresses are guaranteed to be valid EVM addresses, so `toAddress` will always succeed.
|
|
254
226
|
export class EvmAddress extends Address {
|
|
255
227
|
// On construction, validate that the address can indeed be coerced into an EVM address. Throw immediately if it cannot.
|
|
256
|
-
|
|
228
|
+
constructor(rawAddress: Uint8Array) {
|
|
257
229
|
super(rawAddress);
|
|
258
230
|
const hexString = utils.hexlify(rawAddress);
|
|
259
231
|
if (!this.isValidEvmAddress()) {
|
|
@@ -287,7 +259,7 @@ export class EvmAddress extends Address {
|
|
|
287
259
|
// Subclass of address which strictly deals SVM addresses. These addresses are guaranteed to be valid SVM addresses, so `toBase58` will always produce a valid Solana address.
|
|
288
260
|
export class SvmAddress extends Address {
|
|
289
261
|
// On construction, validate that the address is a point on Curve25519. Throw immediately if it is not.
|
|
290
|
-
|
|
262
|
+
constructor(rawAddress: Uint8Array) {
|
|
291
263
|
super(rawAddress);
|
|
292
264
|
}
|
|
293
265
|
|
|
@@ -297,6 +269,16 @@ export class SvmAddress extends Address {
|
|
|
297
269
|
return this.toBase58();
|
|
298
270
|
}
|
|
299
271
|
|
|
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
|
+
|
|
300
282
|
// Constructs a new SvmAddress type.
|
|
301
283
|
static from(address: string, encoding: "base58" | "base16" = "base58"): SvmAddress {
|
|
302
284
|
if (encoding === "base58") {
|
package/src/utils/SpokeUtils.ts
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
import { encodeAbiParameters, Hex, keccak256 } from "viem";
|
|
2
|
-
import { MAX_SAFE_DEPOSIT_ID, ZERO_BYTES } from "../constants";
|
|
3
|
-
import { RelayData } from "../interfaces";
|
|
2
|
+
import { MAX_SAFE_DEPOSIT_ID, ZERO_ADDRESS, ZERO_BYTES } from "../constants";
|
|
3
|
+
import { Deposit, RelayData } from "../interfaces";
|
|
4
|
+
import { toBytes32 } from "./AddressUtils";
|
|
4
5
|
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
|
+
|
|
10
32
|
/**
|
|
11
33
|
* Compute the RelayData hash for a fill. This can be used to determine the fill status.
|
|
12
34
|
* @param relayData RelayData information that is used to complete a fill.
|
|
@@ -37,14 +59,14 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId: numbe
|
|
|
37
59
|
|
|
38
60
|
const _relayData = {
|
|
39
61
|
...relayData,
|
|
40
|
-
depositor: relayData.depositor
|
|
41
|
-
recipient: relayData.recipient
|
|
42
|
-
inputToken: relayData.inputToken
|
|
43
|
-
outputToken: relayData.outputToken
|
|
44
|
-
exclusiveRelayer: relayData.exclusiveRelayer
|
|
62
|
+
depositor: toBytes32(relayData.depositor),
|
|
63
|
+
recipient: toBytes32(relayData.recipient),
|
|
64
|
+
inputToken: toBytes32(relayData.inputToken),
|
|
65
|
+
outputToken: toBytes32(relayData.outputToken),
|
|
66
|
+
exclusiveRelayer: toBytes32(relayData.exclusiveRelayer),
|
|
45
67
|
};
|
|
46
68
|
if (chainIsSvm(destinationChainId)) {
|
|
47
|
-
return svm.getRelayDataHash(
|
|
69
|
+
return svm.getRelayDataHash(_relayData, destinationChainId);
|
|
48
70
|
}
|
|
49
71
|
return keccak256(encodeAbiParameters(abi, [_relayData, destinationChainId]));
|
|
50
72
|
}
|
|
@@ -64,8 +86,8 @@ export function isUnsafeDepositId(depositId: BigNumber): boolean {
|
|
|
64
86
|
}
|
|
65
87
|
|
|
66
88
|
// Determines if the input address (either a bytes32 or bytes20) is the zero address.
|
|
67
|
-
export function isZeroAddress(address:
|
|
68
|
-
return address
|
|
89
|
+
export function isZeroAddress(address: string): boolean {
|
|
90
|
+
return address === ZERO_ADDRESS || address === ZERO_BYTES;
|
|
69
91
|
}
|
|
70
92
|
|
|
71
93
|
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 { L1Token } 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<L1Token> {
|
|
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
|
|
17
|
+
return { address, 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): L1Token {
|
|
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): TokenInfo
|
|
|
44
44
|
const { decimals, addresses } = token;
|
|
45
45
|
const address = addresses[chainId];
|
|
46
46
|
|
|
47
|
-
return { symbol, decimals, address
|
|
47
|
+
return { symbol, decimals, address };
|
|
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): L1Token {
|
|
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:
|
|
131
|
+
address: l2TokenAddress,
|
|
132
132
|
symbol: tokenObject.symbol,
|
|
133
133
|
decimals: tokenObject.decimals,
|
|
134
134
|
};
|