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