@across-protocol/sdk 4.2.16 → 4.3.0
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 +8 -3
- package/dist/cjs/arch/evm/SpokeUtils.js +26 -11
- package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/SpokeUtils.d.ts +8 -2
- package/dist/cjs/arch/svm/SpokeUtils.js +41 -50
- package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/eventsClient.js +4 -2
- package/dist/cjs/arch/svm/eventsClient.js.map +1 -1
- package/dist/cjs/arch/svm/utils.d.ts +3 -3
- package/dist/cjs/arch/svm/utils.js +16 -14
- 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 +71 -71
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +13 -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 +85 -58
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +65 -45
- 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 +5 -3
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +40 -36
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +6 -4
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.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 +18 -19
- package/dist/cjs/interfaces/SpokePool.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +15 -7
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +24 -15
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +12 -4
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +46 -44
- 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 +10 -10
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +12 -8
- package/dist/cjs/utils/AddressUtils.js +33 -36
- 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 +5 -3
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/esm/arch/evm/SpokeUtils.d.ts +9 -4
- package/dist/esm/arch/evm/SpokeUtils.js +29 -14
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.d.ts +9 -3
- package/dist/esm/arch/svm/SpokeUtils.js +42 -55
- package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/eventsClient.js +5 -3
- package/dist/esm/arch/svm/eventsClient.js.map +1 -1
- package/dist/esm/arch/svm/utils.d.ts +3 -3
- package/dist/esm/arch/svm/utils.js +17 -15
- 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 +7 -7
- 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 +71 -71
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +20 -10
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +22 -22
- package/dist/esm/clients/HubPoolClient.js +91 -62
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -2
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +68 -47
- 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 +5 -3
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +42 -38
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +7 -5
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.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 +18 -19
- package/dist/esm/interfaces/SpokePool.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +18 -10
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +29 -20
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/factory.js +2 -2
- package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +14 -6
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +51 -48
- 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 +9 -9
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +12 -8
- package/dist/esm/utils/AddressUtils.js +36 -38
- 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 +22 -18
- package/dist/esm/utils/TokenUtils.js +6 -4
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/types/arch/evm/SpokeUtils.d.ts +9 -4
- package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/SpokeUtils.d.ts +9 -3
- package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/eventsClient.d.ts.map +1 -1
- package/dist/types/arch/svm/utils.d.ts +3 -3
- 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 +71 -71
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +22 -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 +2 -2
- 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 +5 -3
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
- package/dist/types/clients/mocks/MockSvmCpiEventsClient.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 +18 -19
- package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +18 -10
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +14 -6
- 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 +12 -8
- 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 +22 -18
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +1 -2
- package/src/arch/evm/SpokeUtils.ts +72 -22
- package/src/arch/svm/SpokeUtils.ts +67 -53
- package/src/arch/svm/eventsClient.ts +40 -8
- package/src/arch/svm/utils.ts +6 -6
- package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
- package/src/clients/BundleDataClient/BundleDataClient.ts +57 -53
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +28 -13
- package/src/clients/BundleDataClient/utils/FillUtils.ts +12 -8
- 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 +22 -10
- package/src/clients/HubPoolClient.ts +123 -82
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +6 -0
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +121 -35
- package/src/clients/mocks/MockHubPoolClient.ts +24 -19
- package/src/clients/mocks/MockSpokePoolClient.ts +39 -27
- package/src/clients/mocks/MockSvmCpiEventsClient.ts +8 -5
- package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
- package/src/interfaces/HubPool.ts +20 -14
- package/src/interfaces/SpokePool.ts +19 -19
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +39 -20
- package/src/relayFeeCalculator/chain-queries/factory.ts +2 -2
- package/src/relayFeeCalculator/chain-queries/svmQuery.ts +57 -56
- package/src/relayFeeCalculator/relayFeeCalculator.ts +15 -13
- package/src/utils/AddressUtils.ts +39 -51
- package/src/utils/SpokeUtils.ts +11 -33
- package/src/utils/TokenUtils.ts +10 -8
|
@@ -81,15 +81,15 @@ export function isValidEvmAddress(address: string): boolean {
|
|
|
81
81
|
export function toAddressType(address: string, chainId: number): Address {
|
|
82
82
|
const rawAddress = address.startsWith("0x") ? utils.arrayify(address) : bs58.decode(address);
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
return new
|
|
84
|
+
if (chainIsEvm(chainId) && EvmAddress.validate(rawAddress)) return new EvmAddress(rawAddress);
|
|
85
|
+
else if (chainIsSvm(chainId) && SvmAddress.validate(rawAddress)) return new SvmAddress(rawAddress);
|
|
86
|
+
|
|
87
|
+
return new RawAddress(rawAddress);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
// The Address class can contain any address type. It is up to the subclasses to determine how to format the address's internal representation,
|
|
91
91
|
// which for this class, is a bytes32 hex string.
|
|
92
|
-
export class Address {
|
|
92
|
+
export abstract class Address {
|
|
93
93
|
readonly rawAddress: Uint8Array;
|
|
94
94
|
|
|
95
95
|
// Keep all address types in cache so that we may lazily evaluate them when necessary.
|
|
@@ -109,10 +109,6 @@ export class Address {
|
|
|
109
109
|
this.rawAddress = utils.zeroPad(_rawAddress, 32);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
static __unsafeConstruct(_rawAddress: Uint8Array): Address {
|
|
113
|
-
return new this(_rawAddress);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
112
|
// 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
113
|
// throw since address length validation was done at construction time.
|
|
118
114
|
toBytes32(): string {
|
|
@@ -167,11 +163,6 @@ export class Address {
|
|
|
167
163
|
return false;
|
|
168
164
|
}
|
|
169
165
|
|
|
170
|
-
// Checks if the object is an address by looking at whether it has an Address constructor.
|
|
171
|
-
static isAddress(obj: unknown): boolean {
|
|
172
|
-
return obj instanceof this;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
166
|
// Converts the input address to a 32-byte hex data string.
|
|
176
167
|
toString(): string {
|
|
177
168
|
return this.toNative();
|
|
@@ -193,6 +184,7 @@ export class Address {
|
|
|
193
184
|
}
|
|
194
185
|
|
|
195
186
|
// Compares Addresses by first converting them to BigNumbers.
|
|
187
|
+
// note: Intended for use when sorting like addresses.
|
|
196
188
|
compare(otherAddress: Address): 1 | -1 | 0 {
|
|
197
189
|
// Convert address strings to BigNumbers and then sort numerical value of the BigNumber, which sorts the addresses
|
|
198
190
|
// effectively by their hex value.
|
|
@@ -207,20 +199,18 @@ export class Address {
|
|
|
207
199
|
}
|
|
208
200
|
}
|
|
209
201
|
|
|
210
|
-
|
|
211
|
-
return
|
|
202
|
+
isEVM(): this is EvmAddress {
|
|
203
|
+
return false;
|
|
212
204
|
}
|
|
213
205
|
|
|
214
|
-
|
|
215
|
-
return
|
|
206
|
+
isSVM(): this is SvmAddress {
|
|
207
|
+
return false;
|
|
216
208
|
}
|
|
217
209
|
}
|
|
218
210
|
|
|
219
211
|
// Subclass of address which strictly deals with 20-byte addresses. These addresses are guaranteed to be valid EVM addresses, so `toAddress` will always succeed.
|
|
220
212
|
export class EvmAddress extends Address {
|
|
221
|
-
|
|
222
|
-
// Otherwise it lets any of these to use in place where other is expected.
|
|
223
|
-
private readonly _brandEvmAddress!: void;
|
|
213
|
+
private readonly _type = "evm";
|
|
224
214
|
|
|
225
215
|
// On construction, validate that the address can indeed be coerced into an EVM address. Throw immediately if it cannot.
|
|
226
216
|
constructor(rawAddress: Uint8Array) {
|
|
@@ -229,8 +219,7 @@ export class EvmAddress extends Address {
|
|
|
229
219
|
}
|
|
230
220
|
|
|
231
221
|
super(rawAddress);
|
|
232
|
-
//
|
|
233
|
-
this._brandEvmAddress;
|
|
222
|
+
this._type; // tsc noUnusedLocals appeasement.
|
|
234
223
|
}
|
|
235
224
|
|
|
236
225
|
static validate(rawAddress: Uint8Array): boolean {
|
|
@@ -239,34 +228,24 @@ export class EvmAddress extends Address {
|
|
|
239
228
|
);
|
|
240
229
|
}
|
|
241
230
|
|
|
231
|
+
override isEVM(): this is EvmAddress {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
|
|
242
235
|
// Override `toAddress` to return the 20-byte representation address.
|
|
243
236
|
override toNative(): string {
|
|
244
237
|
return this.toEvmAddress();
|
|
245
238
|
}
|
|
246
239
|
|
|
247
240
|
// Constructs a new EvmAddress type.
|
|
248
|
-
static from(address: string, encoding: "
|
|
249
|
-
|
|
250
|
-
return new this(utils.arrayify(address));
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const decodedAddress = bs58.decode(address);
|
|
254
|
-
const padding = decodedAddress.subarray(0, 12);
|
|
255
|
-
const evmAddress = decodedAddress.subarray(12);
|
|
256
|
-
|
|
257
|
-
if (padding.length !== 12 || utils.stripZeros(padding).length !== 0 || evmAddress.length !== 20) {
|
|
258
|
-
throw new Error(`Not a valid base58-encoded EVM address: ${address}`);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return new this(evmAddress);
|
|
241
|
+
static from(address: string, encoding: "base58" | "base16" = "base16"): EvmAddress {
|
|
242
|
+
return encoding === "base16" ? new this(utils.arrayify(address)) : new this(bs58.decode(address));
|
|
262
243
|
}
|
|
263
244
|
}
|
|
264
245
|
|
|
265
246
|
// 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.
|
|
266
247
|
export class SvmAddress extends Address {
|
|
267
|
-
|
|
268
|
-
// Otherwise it lets any of these to use in place where other is expected.
|
|
269
|
-
private readonly _brandSvmAddress!: void;
|
|
248
|
+
private readonly _type = "svm";
|
|
270
249
|
|
|
271
250
|
// On construction, validate that the address is a point on Curve25519. Throw immediately if it is not.
|
|
272
251
|
constructor(rawAddress: Uint8Array) {
|
|
@@ -275,12 +254,21 @@ export class SvmAddress extends Address {
|
|
|
275
254
|
}
|
|
276
255
|
|
|
277
256
|
super(rawAddress);
|
|
278
|
-
//
|
|
279
|
-
this._brandSvmAddress;
|
|
257
|
+
this._type; // tsc noUnusedLocals appeasement.
|
|
280
258
|
}
|
|
281
259
|
|
|
282
260
|
static validate(rawAddress: Uint8Array): boolean {
|
|
283
|
-
|
|
261
|
+
// Deliberately invalidate SVM addresses w/ the upper 12 bytes zeroed. These addresses are technically valid
|
|
262
|
+
// but highly improbable and are much more likely to be a mistaken interpretation of an EVM address. Err on
|
|
263
|
+
// the side of caution for the time being. Exception: Permit the zero address (i.e. for exclusiverRelayer).
|
|
264
|
+
return (
|
|
265
|
+
rawAddress.length === 32 &&
|
|
266
|
+
(!rawAddress.slice(0, 12).every((field) => field === 0) || rawAddress.every((field) => field === 0))
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
override isSVM(): this is SvmAddress {
|
|
271
|
+
return true;
|
|
284
272
|
}
|
|
285
273
|
|
|
286
274
|
// Override the toAddress function for SVM addresses only since while they will never have a defined 20-byte representation. The base58 encoded addresses are also the encodings
|
|
@@ -291,15 +279,15 @@ export class SvmAddress extends Address {
|
|
|
291
279
|
|
|
292
280
|
// Constructs a new SvmAddress type.
|
|
293
281
|
static from(address: string, encoding: "base58" | "base16" = "base58"): SvmAddress {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
282
|
+
return encoding === "base58" ? new this(bs58.decode(address)) : new this(utils.arrayify(address));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
297
285
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
throw new Error(`Not a valid base16-encoded SVM address: ${address}`);
|
|
301
|
-
}
|
|
286
|
+
export class RawAddress extends Address {
|
|
287
|
+
private readonly _type = "raw";
|
|
302
288
|
|
|
303
|
-
|
|
289
|
+
constructor(rawAddress: Uint8Array) {
|
|
290
|
+
super(rawAddress);
|
|
291
|
+
this._type; // tsc noUnusedLocals appeasement.
|
|
304
292
|
}
|
|
305
293
|
}
|
package/src/utils/SpokeUtils.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { encodeAbiParameters, Hex, keccak256 } from "viem";
|
|
2
2
|
import { fixedPointAdjustment as fixedPoint } from "./common";
|
|
3
|
-
import { MAX_SAFE_DEPOSIT_ID,
|
|
4
|
-
import {
|
|
5
|
-
import { toBytes32 } from "./AddressUtils";
|
|
3
|
+
import { MAX_SAFE_DEPOSIT_ID, ZERO_BYTES } from "../constants";
|
|
4
|
+
import { Fill, FillType, RelayData, SlowFillLeaf } from "../interfaces";
|
|
6
5
|
import { BigNumber } from "./BigNumberUtils";
|
|
6
|
+
import { Address } from "./AddressUtils";
|
|
7
7
|
import { isMessageEmpty } from "./DepositUtils";
|
|
8
8
|
import { chainIsSvm } from "./NetworkUtils";
|
|
9
9
|
import { svm } from "../arch";
|
|
@@ -16,28 +16,6 @@ export function getSlowFillLeafLpFeePct(leaf: SlowFillLeaf): BigNumber {
|
|
|
16
16
|
const { relayData, updatedOutputAmount } = leaf;
|
|
17
17
|
return relayData.inputAmount.sub(updatedOutputAmount).mul(fixedPoint).div(relayData.inputAmount);
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Produce the RelayData for a Deposit.
|
|
21
|
-
* @param deposit Deposit instance.
|
|
22
|
-
* @returns The corresponding RelayData object.
|
|
23
|
-
*/
|
|
24
|
-
export function getDepositRelayData(deposit: Omit<Deposit, "messageHash">): RelayData {
|
|
25
|
-
return {
|
|
26
|
-
depositor: toBytes32(deposit.depositor),
|
|
27
|
-
recipient: toBytes32(deposit.recipient),
|
|
28
|
-
exclusiveRelayer: toBytes32(deposit.exclusiveRelayer),
|
|
29
|
-
inputToken: toBytes32(deposit.inputToken),
|
|
30
|
-
outputToken: toBytes32(deposit.outputToken),
|
|
31
|
-
inputAmount: deposit.inputAmount,
|
|
32
|
-
outputAmount: deposit.outputAmount,
|
|
33
|
-
originChainId: deposit.originChainId,
|
|
34
|
-
depositId: deposit.depositId,
|
|
35
|
-
fillDeadline: deposit.fillDeadline,
|
|
36
|
-
exclusivityDeadline: deposit.exclusivityDeadline,
|
|
37
|
-
message: deposit.message,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
19
|
/**
|
|
42
20
|
* Compute the RelayData hash for a fill. This can be used to determine the fill status.
|
|
43
21
|
* @param relayData RelayData information that is used to complete a fill.
|
|
@@ -68,14 +46,14 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId: numbe
|
|
|
68
46
|
|
|
69
47
|
const _relayData = {
|
|
70
48
|
...relayData,
|
|
71
|
-
depositor:
|
|
72
|
-
recipient:
|
|
73
|
-
inputToken:
|
|
74
|
-
outputToken:
|
|
75
|
-
exclusiveRelayer:
|
|
49
|
+
depositor: relayData.depositor.toBytes32(),
|
|
50
|
+
recipient: relayData.recipient.toBytes32(),
|
|
51
|
+
inputToken: relayData.inputToken.toBytes32(),
|
|
52
|
+
outputToken: relayData.outputToken.toBytes32(),
|
|
53
|
+
exclusiveRelayer: relayData.exclusiveRelayer.toBytes32(),
|
|
76
54
|
};
|
|
77
55
|
if (chainIsSvm(destinationChainId)) {
|
|
78
|
-
return svm.getRelayDataHash(
|
|
56
|
+
return svm.getRelayDataHash(relayData, destinationChainId);
|
|
79
57
|
}
|
|
80
58
|
return keccak256(encodeAbiParameters(abi, [_relayData, destinationChainId]));
|
|
81
59
|
}
|
|
@@ -95,8 +73,8 @@ export function isUnsafeDepositId(depositId: BigNumber): boolean {
|
|
|
95
73
|
}
|
|
96
74
|
|
|
97
75
|
// Determines if the input address (either a bytes32 or bytes20) is the zero address.
|
|
98
|
-
export function isZeroAddress(address:
|
|
99
|
-
return address ===
|
|
76
|
+
export function isZeroAddress(address: Address): boolean {
|
|
77
|
+
return address.toBytes32() === ZERO_BYTES;
|
|
100
78
|
}
|
|
101
79
|
|
|
102
80
|
export function getMessageHash(message: string): string {
|
package/src/utils/TokenUtils.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
+
import assert from "assert";
|
|
1
2
|
import { BlockTag } from "@ethersproject/abstract-provider";
|
|
2
3
|
import { Contract, providers, Signer } from "ethers";
|
|
3
4
|
import * as constants from "../constants";
|
|
4
|
-
import {
|
|
5
|
+
import { TokenInfo } from "../interfaces";
|
|
5
6
|
import { ERC20__factory } from "../typechain";
|
|
6
7
|
import { BigNumber } from "./BigNumberUtils";
|
|
7
8
|
import { getNetworkName, chainIsL1, chainIsProd } from "./NetworkUtils";
|
|
8
9
|
import { isDefined } from "./TypeGuards";
|
|
9
|
-
import { compareAddressesSimple, toAddressType } from "./AddressUtils";
|
|
10
|
+
import { compareAddressesSimple, EvmAddress, toAddressType } from "./AddressUtils";
|
|
10
11
|
const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
|
|
11
12
|
|
|
12
13
|
type SignerOrProvider = providers.Provider | Signer;
|
|
13
14
|
|
|
14
|
-
export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<
|
|
15
|
+
export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<TokenInfo> {
|
|
15
16
|
const token = new Contract(address, ERC20__factory.abi, signerOrProvider);
|
|
16
17
|
const [symbol, decimals] = await Promise.all([token.symbol(), token.decimals()]);
|
|
17
|
-
return { address, symbol, decimals };
|
|
18
|
+
return { address: EvmAddress.from(address), symbol, decimals };
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export const getL2TokenAddresses = (
|
|
@@ -33,7 +34,7 @@ export const getL2TokenAddresses = (
|
|
|
33
34
|
* @param chainId Chain ID to query on.
|
|
34
35
|
* @returns Symbol, decimals and contract address on the requested chain.
|
|
35
36
|
*/
|
|
36
|
-
export function resolveSymbolOnChain(chainId: number, symbol: string):
|
|
37
|
+
export function resolveSymbolOnChain(chainId: number, symbol: string): TokenInfo {
|
|
37
38
|
// @dev Suppress tsc complaints by casting symbol to the expected type.
|
|
38
39
|
const token = TOKEN_SYMBOLS_MAP[symbol as keyof typeof TOKEN_SYMBOLS_MAP];
|
|
39
40
|
if (!isDefined(token) || !isDefined(token.addresses[chainId])) {
|
|
@@ -42,7 +43,8 @@ export function resolveSymbolOnChain(chainId: number, symbol: string): L1Token {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
const { decimals, addresses } = token;
|
|
45
|
-
const address = addresses[chainId];
|
|
46
|
+
const address = toAddressType(addresses[chainId], chainId);
|
|
47
|
+
assert(address.isEVM() || address.isSVM());
|
|
46
48
|
|
|
47
49
|
return { symbol, decimals, address };
|
|
48
50
|
}
|
|
@@ -111,7 +113,7 @@ export function isStablecoin(tokenSymbol: string): boolean {
|
|
|
111
113
|
* @param tokenMapping
|
|
112
114
|
* @returns
|
|
113
115
|
*/
|
|
114
|
-
export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP):
|
|
116
|
+
export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): TokenInfo {
|
|
115
117
|
const parsedAddress = toAddressType(l2TokenAddress, chainId).toNative();
|
|
116
118
|
|
|
117
119
|
// @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
|
|
@@ -127,7 +129,7 @@ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMappi
|
|
|
127
129
|
tokenObject = tokenMapping[l1TokenSymbol as keyof typeof tokenMapping];
|
|
128
130
|
}
|
|
129
131
|
return {
|
|
130
|
-
address: l2TokenAddress,
|
|
132
|
+
address: toAddressType(l2TokenAddress, chainId),
|
|
131
133
|
symbol: tokenObject.symbol,
|
|
132
134
|
decimals: tokenObject.decimals,
|
|
133
135
|
};
|