@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
|
@@ -14,8 +14,8 @@ import {
|
|
|
14
14
|
union,
|
|
15
15
|
type,
|
|
16
16
|
} from "superstruct";
|
|
17
|
-
import {
|
|
18
|
-
import { BigNumber
|
|
17
|
+
import { UNDEFINED_MESSAGE_HASH } from "../../../constants";
|
|
18
|
+
import { BigNumber } from "../../../utils";
|
|
19
19
|
|
|
20
20
|
const PositiveIntegerStringSS = pattern(string(), /\d+/);
|
|
21
21
|
const Web3AddressSS = pattern(string(), /^0x[a-fA-F0-9]{40}$/);
|
|
@@ -31,31 +31,19 @@ const BigNumberType = coerce(instance(BigNumber), union([string(), number()]), (
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
// Accept any concrete implementation of `Address` (Evm, Svm, or Raw) but avoid using the
|
|
35
|
-
// abstract `Address` class directly to keep TypeScript happy.
|
|
36
|
-
const AddressInstanceSS = union([instance(EvmAddress), instance(SvmAddress), instance(RawAddress)]);
|
|
37
|
-
|
|
38
|
-
const AddressType = coerce(AddressInstanceSS, string(), (value) => {
|
|
39
|
-
// Addresses are posted to arweave in their native format (base16 for EVM, base58 for SVM). The chainId for
|
|
40
|
-
// for the event data is not directly available, so infer it based on the shape of the address. RawAddress
|
|
41
|
-
// will be instantiated if the address format does not match the expected family.
|
|
42
|
-
const chainId = value.startsWith("0x") ? CHAIN_IDs.MAINNET : CHAIN_IDs.SOLANA;
|
|
43
|
-
return toAddressType(value, chainId);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
34
|
const FillTypeSS = number();
|
|
47
35
|
|
|
48
36
|
const V3RelayDataSS = {
|
|
49
|
-
inputToken:
|
|
37
|
+
inputToken: string(),
|
|
50
38
|
inputAmount: BigNumberType,
|
|
51
|
-
outputToken:
|
|
39
|
+
outputToken: string(),
|
|
52
40
|
outputAmount: BigNumberType,
|
|
53
41
|
fillDeadline: number(),
|
|
54
|
-
exclusiveRelayer:
|
|
42
|
+
exclusiveRelayer: string(),
|
|
55
43
|
exclusivityDeadline: number(),
|
|
56
44
|
originChainId: number(),
|
|
57
|
-
depositor:
|
|
58
|
-
recipient:
|
|
45
|
+
depositor: string(),
|
|
46
|
+
recipient: string(),
|
|
59
47
|
depositId: BigNumberType,
|
|
60
48
|
message: string(),
|
|
61
49
|
};
|
|
@@ -79,7 +67,7 @@ const V3DepositSS = {
|
|
|
79
67
|
quoteTimestamp: number(),
|
|
80
68
|
relayerFeePct: optional(BigNumberType),
|
|
81
69
|
speedUpSignature: optional(string()),
|
|
82
|
-
updatedRecipient: optional(
|
|
70
|
+
updatedRecipient: optional(string()),
|
|
83
71
|
updatedOutputAmount: optional(BigNumberType),
|
|
84
72
|
updatedMessage: optional(string()),
|
|
85
73
|
};
|
|
@@ -100,7 +88,7 @@ const V3DepositWithBlockLpFeeSS = object({
|
|
|
100
88
|
const V3RelayExecutionEventInfoSS = object({
|
|
101
89
|
updatedOutputAmount: BigNumberType,
|
|
102
90
|
fillType: FillTypeSS,
|
|
103
|
-
updatedRecipient:
|
|
91
|
+
updatedRecipient: string(),
|
|
104
92
|
updatedMessage: optional(string()),
|
|
105
93
|
updatedMessageHash: defaulted(string(), UNDEFINED_MESSAGE_HASH),
|
|
106
94
|
});
|
|
@@ -110,7 +98,7 @@ const V3FillSS = {
|
|
|
110
98
|
message: optional(string()),
|
|
111
99
|
messageHash: defaulted(string(), UNDEFINED_MESSAGE_HASH),
|
|
112
100
|
destinationChainId: number(),
|
|
113
|
-
relayer:
|
|
101
|
+
relayer: string(),
|
|
114
102
|
repaymentChainId: number(),
|
|
115
103
|
relayExecutionInfo: V3RelayExecutionEventInfoSS,
|
|
116
104
|
quoteTimestamp: number(),
|
|
@@ -2,7 +2,7 @@ import assert from "assert";
|
|
|
2
2
|
import { Contract, EventFilter } from "ethers";
|
|
3
3
|
import _ from "lodash";
|
|
4
4
|
import winston from "winston";
|
|
5
|
-
import { DEFAULT_CACHING_SAFE_LAG, DEFAULT_CACHING_TTL, TOKEN_SYMBOLS_MAP } from "../constants";
|
|
5
|
+
import { DEFAULT_CACHING_SAFE_LAG, DEFAULT_CACHING_TTL, TOKEN_SYMBOLS_MAP, ZERO_ADDRESS } from "../constants";
|
|
6
6
|
import {
|
|
7
7
|
CachingMechanismInterface,
|
|
8
8
|
CancelledRootBundle,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
DestinationTokenWithBlock,
|
|
13
13
|
DisputedRootBundle,
|
|
14
14
|
ExecutedRootBundle,
|
|
15
|
-
|
|
15
|
+
L1Token,
|
|
16
16
|
Log,
|
|
17
17
|
LpToken,
|
|
18
18
|
PendingRootBundle,
|
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
RealizedLpFee,
|
|
21
21
|
SetPoolRebalanceRoot,
|
|
22
22
|
TokenRunningBalance,
|
|
23
|
-
L1TokenInfo,
|
|
24
23
|
} from "../interfaces";
|
|
25
24
|
import * as lpFeeCalculator from "../lpFeeCalculator";
|
|
26
25
|
import { EVMBlockFinder } from "../arch/evm";
|
|
@@ -44,12 +43,10 @@ import {
|
|
|
44
43
|
toBN,
|
|
45
44
|
getTokenInfo,
|
|
46
45
|
getUsdcSymbol,
|
|
46
|
+
compareAddressesSimple,
|
|
47
47
|
chainIsSvm,
|
|
48
48
|
getDeployedAddress,
|
|
49
49
|
SvmAddress,
|
|
50
|
-
EvmAddress,
|
|
51
|
-
Address,
|
|
52
|
-
toAddressType,
|
|
53
50
|
} from "../utils";
|
|
54
51
|
import { AcrossConfigStoreClient as ConfigStoreClient } from "./AcrossConfigStoreClient/AcrossConfigStoreClient";
|
|
55
52
|
import { BaseAbstractClient, isUpdateFailureReason, UpdateFailureReason } from "./BaseAbstractClient";
|
|
@@ -87,8 +84,7 @@ export type LpFeeRequest = Pick<Deposit, "originChainId" | "inputToken" | "input
|
|
|
87
84
|
export class HubPoolClient extends BaseAbstractClient {
|
|
88
85
|
// L1Token -> destinationChainId -> destinationToken
|
|
89
86
|
protected l1TokensToDestinationTokens: L1TokensToDestinationTokens = {};
|
|
90
|
-
protected l1Tokens:
|
|
91
|
-
// @dev `token` here is a 20-byte hex sting
|
|
87
|
+
protected l1Tokens: L1Token[] = []; // L1Tokens and their associated info.
|
|
92
88
|
protected lpTokens: { [token: string]: LpToken } = {};
|
|
93
89
|
protected proposedRootBundles: ProposedRootBundle[] = [];
|
|
94
90
|
protected canceledRootBundles: CancelledRootBundle[] = [];
|
|
@@ -96,7 +92,6 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
96
92
|
protected executedRootBundles: ExecutedRootBundle[] = [];
|
|
97
93
|
protected crossChainContracts: { [l2ChainId: number]: CrossChainContractsSet[] } = {};
|
|
98
94
|
protected l1TokensToDestinationTokensWithBlock: {
|
|
99
|
-
// @dev `l1Token` here is a 20-byte hex sting
|
|
100
95
|
[l1Token: string]: { [destinationChainId: number]: DestinationTokenWithBlock[] };
|
|
101
96
|
} = {};
|
|
102
97
|
protected pendingRootBundle: PendingRootBundle | undefined;
|
|
@@ -165,7 +160,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
165
160
|
return this.executedRootBundles;
|
|
166
161
|
}
|
|
167
162
|
|
|
168
|
-
getSpokePoolForBlock(chain: number, block: number = Number.MAX_SAFE_INTEGER):
|
|
163
|
+
getSpokePoolForBlock(chain: number, block: number = Number.MAX_SAFE_INTEGER): string {
|
|
169
164
|
if (!this.crossChainContracts[chain]) {
|
|
170
165
|
throw new Error(`No cross chain contracts set for ${chain}`);
|
|
171
166
|
}
|
|
@@ -179,33 +174,33 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
179
174
|
}
|
|
180
175
|
}
|
|
181
176
|
|
|
182
|
-
getSpokePoolActivationBlock(chain: number, spokePool:
|
|
177
|
+
getSpokePoolActivationBlock(chain: number, spokePool: string): number | undefined {
|
|
183
178
|
// Return first time that this spoke pool was registered in the HubPool as a cross chain contract. We can use
|
|
184
179
|
// this block as the oldest block that we should query for SpokePoolClient purposes.
|
|
185
|
-
const mostRecentSpokePoolUpdateBeforeBlock = this.crossChainContracts[chain].find(
|
|
186
|
-
crossChainContract.spokePool
|
|
180
|
+
const mostRecentSpokePoolUpdateBeforeBlock = this.crossChainContracts[chain].find(
|
|
181
|
+
(crossChainContract) => crossChainContract.spokePool === spokePool
|
|
187
182
|
);
|
|
188
183
|
return mostRecentSpokePoolUpdateBeforeBlock?.blockNumber;
|
|
189
184
|
}
|
|
190
185
|
|
|
191
186
|
// Returns the latest L2 token to use for an L1 token as of the input hub block.
|
|
192
187
|
getL2TokenForL1TokenAtBlock(
|
|
193
|
-
l1Token:
|
|
188
|
+
l1Token: string,
|
|
194
189
|
destinationChainId: number,
|
|
195
190
|
latestHubBlock = Number.MAX_SAFE_INTEGER
|
|
196
|
-
):
|
|
197
|
-
if (!this.l1TokensToDestinationTokensWithBlock?.[l1Token
|
|
191
|
+
): string {
|
|
192
|
+
if (!this.l1TokensToDestinationTokensWithBlock?.[l1Token]?.[destinationChainId]) {
|
|
198
193
|
const chain = getNetworkName(destinationChainId);
|
|
199
|
-
const { symbol } = this.l1Tokens.find(({ address }) => address
|
|
194
|
+
const { symbol } = this.l1Tokens.find(({ address }) => address === l1Token) ?? { symbol: l1Token };
|
|
200
195
|
throw new Error(`Could not find SpokePool mapping for ${symbol} on ${chain} and L1 token ${l1Token}`);
|
|
201
196
|
}
|
|
202
197
|
// Find the last mapping published before the target block.
|
|
203
198
|
const l2Token: DestinationTokenWithBlock | undefined = sortEventsDescending(
|
|
204
|
-
this.l1TokensToDestinationTokensWithBlock[l1Token
|
|
199
|
+
this.l1TokensToDestinationTokensWithBlock[l1Token][destinationChainId]
|
|
205
200
|
).find((mapping: DestinationTokenWithBlock) => mapping.blockNumber <= latestHubBlock);
|
|
206
201
|
if (!l2Token) {
|
|
207
202
|
const chain = getNetworkName(destinationChainId);
|
|
208
|
-
const { symbol } = this.l1Tokens.find(({ address }) => address
|
|
203
|
+
const { symbol } = this.l1Tokens.find(({ address }) => address === l1Token) ?? { symbol: l1Token };
|
|
209
204
|
throw new Error(
|
|
210
205
|
`Could not find SpokePool mapping for ${symbol} on ${chain} at or before HubPool block ${latestHubBlock}!`
|
|
211
206
|
);
|
|
@@ -213,23 +208,18 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
213
208
|
return l2Token.l2Token;
|
|
214
209
|
}
|
|
215
210
|
|
|
216
|
-
// TODO: this might have to deal with truncated Solana addresses? Depends on what input is given actually
|
|
217
|
-
// TODO: might craete `getL1TokenForL2EVMTokenAtBlock` and some other fn
|
|
218
211
|
// Returns the latest L1 token to use for an L2 token as of the input hub block.
|
|
219
212
|
getL1TokenForL2TokenAtBlock(
|
|
220
|
-
l2Token:
|
|
213
|
+
l2Token: string,
|
|
221
214
|
destinationChainId: number,
|
|
222
215
|
latestHubBlock = Number.MAX_SAFE_INTEGER
|
|
223
|
-
):
|
|
216
|
+
): string {
|
|
224
217
|
const l2Tokens = Object.keys(this.l1TokensToDestinationTokensWithBlock)
|
|
225
|
-
.filter((l1Token) => this.l2TokenEnabledForL1Token(
|
|
218
|
+
.filter((l1Token) => this.l2TokenEnabledForL1Token(l1Token, destinationChainId))
|
|
226
219
|
.map((l1Token) => {
|
|
227
220
|
// Return all matching L2 token mappings that are equal to or earlier than the target block.
|
|
228
221
|
return this.l1TokensToDestinationTokensWithBlock[l1Token][destinationChainId].filter(
|
|
229
|
-
|
|
230
|
-
// ! TODO: Considering this, this filtering should be a bit different. If .isSvmAddress => check not for equality, but for *truncated equality*. If .isEvmAddress, check for equality
|
|
231
|
-
(dstTokenWithBlock) =>
|
|
232
|
-
dstTokenWithBlock.l2Token.eq(l2Token) && dstTokenWithBlock.blockNumber <= latestHubBlock
|
|
222
|
+
(mapping) => mapping.l2Token === l2Token && mapping.blockNumber <= latestHubBlock
|
|
233
223
|
);
|
|
234
224
|
})
|
|
235
225
|
.flat();
|
|
@@ -245,33 +235,32 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
245
235
|
|
|
246
236
|
protected getL1TokenForDeposit(
|
|
247
237
|
deposit: Pick<DepositWithBlock, "originChainId" | "inputToken" | "quoteBlockNumber">
|
|
248
|
-
):
|
|
238
|
+
): string {
|
|
249
239
|
// L1-->L2 token mappings are set via PoolRebalanceRoutes which occur on mainnet,
|
|
250
240
|
// so we use the latest token mapping. This way if a very old deposit is filled, the relayer can use the
|
|
251
241
|
// latest L2 token mapping to find the L1 token counterpart.
|
|
252
242
|
return this.getL1TokenForL2TokenAtBlock(deposit.inputToken, deposit.originChainId, deposit.quoteBlockNumber);
|
|
253
243
|
}
|
|
254
244
|
|
|
255
|
-
l2TokenEnabledForL1Token(l1Token:
|
|
256
|
-
return this.l1TokensToDestinationTokens?.[l1Token
|
|
245
|
+
l2TokenEnabledForL1Token(l1Token: string, destinationChainId: number): boolean {
|
|
246
|
+
return this.l1TokensToDestinationTokens?.[l1Token]?.[destinationChainId] != undefined;
|
|
257
247
|
}
|
|
258
248
|
|
|
259
|
-
l2TokenEnabledForL1TokenAtBlock(l1Token:
|
|
249
|
+
l2TokenEnabledForL1TokenAtBlock(l1Token: string, destinationChainId: number, hubBlockNumber: number): boolean {
|
|
260
250
|
// Find the last mapping published before the target block.
|
|
261
251
|
const l2Token: DestinationTokenWithBlock | undefined = sortEventsDescending(
|
|
262
|
-
this.l1TokensToDestinationTokensWithBlock?.[l1Token
|
|
252
|
+
this.l1TokensToDestinationTokensWithBlock?.[l1Token]?.[destinationChainId] ?? []
|
|
263
253
|
).find((mapping: DestinationTokenWithBlock) => mapping.blockNumber <= hubBlockNumber);
|
|
264
254
|
return l2Token !== undefined;
|
|
265
255
|
}
|
|
266
256
|
|
|
267
|
-
l2TokenHasPoolRebalanceRoute(l2Token:
|
|
257
|
+
l2TokenHasPoolRebalanceRoute(l2Token: string, l2ChainId: number, hubPoolBlock = this.latestHeightSearched): boolean {
|
|
268
258
|
return Object.values(this.l1TokensToDestinationTokensWithBlock).some((destinationTokenMapping) => {
|
|
269
259
|
return Object.entries(destinationTokenMapping).some(([_l2ChainId, setPoolRebalanceRouteEvents]) => {
|
|
270
260
|
return setPoolRebalanceRouteEvents.some((e) => {
|
|
271
261
|
return (
|
|
272
262
|
e.blockNumber <= hubPoolBlock &&
|
|
273
|
-
|
|
274
|
-
e.l2Token.eq(l2Token) &&
|
|
263
|
+
compareAddressesSimple(e.l2Token, l2Token) &&
|
|
275
264
|
Number(_l2ChainId) === l2ChainId
|
|
276
265
|
);
|
|
277
266
|
});
|
|
@@ -282,16 +271,15 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
282
271
|
/**
|
|
283
272
|
* @dev If tokenAddress + chain do not exist in TOKEN_SYMBOLS_MAP then this will throw.
|
|
284
273
|
* @param tokenAddress Token address on `chain`
|
|
285
|
-
* @param
|
|
274
|
+
* @param chain Chain where the `tokenAddress` exists in TOKEN_SYMBOLS_MAP.
|
|
286
275
|
* @returns Token info for the given token address on the L2 chain including symbol and decimal.
|
|
287
276
|
*/
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const tokenInfo = getTokenInfo(tokenAddress, chainId);
|
|
277
|
+
getTokenInfoForAddress(tokenAddress: string, chain: number): L1Token {
|
|
278
|
+
const tokenInfo = getTokenInfo(tokenAddress, chain);
|
|
291
279
|
// @dev Temporarily handle case where an L2 token for chain ID can map to more than one TOKEN_SYMBOLS_MAP
|
|
292
280
|
// entry. For example, L2 Bridged USDC maps to both the USDC and USDC.e/USDbC entries in TOKEN_SYMBOLS_MAP.
|
|
293
|
-
if (tokenInfo.symbol.toLowerCase() === "usdc" &&
|
|
294
|
-
tokenInfo.symbol = getUsdcSymbol(tokenAddress,
|
|
281
|
+
if (tokenInfo.symbol.toLowerCase() === "usdc" && chain !== this.chainId) {
|
|
282
|
+
tokenInfo.symbol = getUsdcSymbol(tokenAddress, chain) ?? "UNKNOWN";
|
|
295
283
|
}
|
|
296
284
|
return tokenInfo;
|
|
297
285
|
}
|
|
@@ -323,7 +311,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
323
311
|
return blockNumbers;
|
|
324
312
|
}
|
|
325
313
|
|
|
326
|
-
async getCurrentPoolUtilization(l1Token:
|
|
314
|
+
async getCurrentPoolUtilization(l1Token: string): Promise<BigNumber> {
|
|
327
315
|
const blockNumber = this.latestHeightSearched ?? (await this.hubPool.provider.getBlockNumber());
|
|
328
316
|
return await this.getUtilization(l1Token, blockNumber, bnZero, getCurrentTime(), 0);
|
|
329
317
|
}
|
|
@@ -338,7 +326,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
338
326
|
* @returns HubPool utilization at `blockNumber` after optional `amount` increase in utilization.
|
|
339
327
|
*/
|
|
340
328
|
protected async getUtilization(
|
|
341
|
-
hubPoolToken:
|
|
329
|
+
hubPoolToken: string,
|
|
342
330
|
blockNumber: number,
|
|
343
331
|
depositAmount: BigNumber,
|
|
344
332
|
timestamp: number,
|
|
@@ -349,14 +337,10 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
349
337
|
const overrides = { blockTag: blockNumber };
|
|
350
338
|
if (depositAmount.eq(0)) {
|
|
351
339
|
// For zero amount, just get the utilisation at `blockNumber`.
|
|
352
|
-
return await this.hubPool.callStatic.liquidityUtilizationCurrent(hubPoolToken
|
|
340
|
+
return await this.hubPool.callStatic.liquidityUtilizationCurrent(hubPoolToken, overrides);
|
|
353
341
|
}
|
|
354
342
|
|
|
355
|
-
return await this.hubPool.callStatic.liquidityUtilizationPostRelay(
|
|
356
|
-
hubPoolToken.toEvmAddress(),
|
|
357
|
-
depositAmount,
|
|
358
|
-
overrides
|
|
359
|
-
);
|
|
343
|
+
return await this.hubPool.callStatic.liquidityUtilizationPostRelay(hubPoolToken, depositAmount, overrides);
|
|
360
344
|
};
|
|
361
345
|
|
|
362
346
|
// Resolve the cache locally so that we can appease typescript
|
|
@@ -371,8 +355,8 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
371
355
|
// @note Avoid collisions with pre-existing cache keys by appending an underscore (_) for post-relay utilization.
|
|
372
356
|
// @fixme This can be removed once the existing keys have been ejected from the cache (i.e. 7 days).
|
|
373
357
|
const key = depositAmount.eq(0)
|
|
374
|
-
? `utilization_${hubPoolToken
|
|
375
|
-
: `utilization_${hubPoolToken
|
|
358
|
+
? `utilization_${hubPoolToken}_${blockNumber}`
|
|
359
|
+
: `utilization_${hubPoolToken}_${blockNumber}_${depositAmount.toString()}_`;
|
|
376
360
|
const result = await cache.get<string>(key);
|
|
377
361
|
if (isDefined(result)) {
|
|
378
362
|
return BigNumber.from(result);
|
|
@@ -409,14 +393,14 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
409
393
|
|
|
410
394
|
// Map SpokePool token addresses to HubPool token addresses.
|
|
411
395
|
// Note: Should only be accessed via `getHubPoolToken()` or `getHubPoolTokens()`.
|
|
412
|
-
const hubPoolTokens: { [k: string]:
|
|
413
|
-
const getHubPoolToken = (deposit: LpFeeRequest, quoteBlockNumber: number):
|
|
396
|
+
const hubPoolTokens: { [k: string]: string } = {};
|
|
397
|
+
const getHubPoolToken = (deposit: LpFeeRequest, quoteBlockNumber: number): string | undefined => {
|
|
414
398
|
const tokenKey = `${deposit.originChainId}-${deposit.inputToken}`;
|
|
415
399
|
if (this.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, quoteBlockNumber)) {
|
|
416
400
|
return (hubPoolTokens[tokenKey] ??= this.getL1TokenForDeposit({ ...deposit, quoteBlockNumber }));
|
|
417
401
|
} else return undefined;
|
|
418
402
|
};
|
|
419
|
-
const getHubPoolTokens = ():
|
|
403
|
+
const getHubPoolTokens = (): string[] => dedupArray(Object.values(hubPoolTokens).filter(isDefined));
|
|
420
404
|
|
|
421
405
|
// Helper to resolve the unqiue hubPoolToken & quoteTimestamp mappings.
|
|
422
406
|
const resolveUniqueQuoteTimestamps = (deposit: LpFeeRequest): void => {
|
|
@@ -430,17 +414,17 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
430
414
|
}
|
|
431
415
|
|
|
432
416
|
// Append the quoteTimestamp for this HubPool token, if it isn't already enqueued.
|
|
433
|
-
utilizationTimestamps[hubPoolToken
|
|
434
|
-
if (!utilizationTimestamps[hubPoolToken
|
|
435
|
-
utilizationTimestamps[hubPoolToken
|
|
417
|
+
utilizationTimestamps[hubPoolToken] ??= [];
|
|
418
|
+
if (!utilizationTimestamps[hubPoolToken].includes(quoteTimestamp)) {
|
|
419
|
+
utilizationTimestamps[hubPoolToken].push(quoteTimestamp);
|
|
436
420
|
}
|
|
437
421
|
};
|
|
438
422
|
|
|
439
423
|
// Helper to resolve existing HubPool token utilisation for an array of unique block numbers.
|
|
440
424
|
// Produces a mapping of blockNumber -> utilization for a specific token.
|
|
441
|
-
const resolveUtilization = async (hubPoolToken:
|
|
425
|
+
const resolveUtilization = async (hubPoolToken: string): Promise<Record<number, BigNumber>> => {
|
|
442
426
|
return Object.fromEntries(
|
|
443
|
-
await mapAsync(utilizationTimestamps[hubPoolToken
|
|
427
|
+
await mapAsync(utilizationTimestamps[hubPoolToken], async (quoteTimestamp) => {
|
|
444
428
|
const blockNumber = quoteBlocks[quoteTimestamp];
|
|
445
429
|
const utilization = await this.getUtilization(
|
|
446
430
|
hubPoolToken,
|
|
@@ -476,7 +460,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
476
460
|
quoteBlock
|
|
477
461
|
);
|
|
478
462
|
|
|
479
|
-
const preUtilization = utilization[hubPoolToken
|
|
463
|
+
const preUtilization = utilization[hubPoolToken][quoteBlock];
|
|
480
464
|
const postUtilization = await this.getUtilization(
|
|
481
465
|
hubPoolToken,
|
|
482
466
|
quoteBlock,
|
|
@@ -504,10 +488,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
504
488
|
// For each token / quoteBlock pair, resolve the utilisation for each quoted block.
|
|
505
489
|
// This can be reused for each deposit with the same HubPool token and quoteTimestamp pair.
|
|
506
490
|
utilization = Object.fromEntries(
|
|
507
|
-
await mapAsync(getHubPoolTokens(), async (hubPoolToken) => [
|
|
508
|
-
hubPoolToken.toEvmAddress(),
|
|
509
|
-
await resolveUtilization(hubPoolToken),
|
|
510
|
-
])
|
|
491
|
+
await mapAsync(getHubPoolTokens(), async (hubPoolToken) => [hubPoolToken, await resolveUtilization(hubPoolToken)])
|
|
511
492
|
);
|
|
512
493
|
|
|
513
494
|
// For each deposit, compute the post-relay HubPool utilisation independently.
|
|
@@ -525,22 +506,22 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
525
506
|
});
|
|
526
507
|
}
|
|
527
508
|
|
|
528
|
-
getL1Tokens():
|
|
509
|
+
getL1Tokens(): L1Token[] {
|
|
529
510
|
return this.l1Tokens;
|
|
530
511
|
}
|
|
531
512
|
|
|
532
|
-
getTokenInfoForL1Token(l1Token:
|
|
533
|
-
return this.l1Tokens.find((token) => token.address
|
|
513
|
+
getTokenInfoForL1Token(l1Token: string): L1Token | undefined {
|
|
514
|
+
return this.l1Tokens.find((token) => token.address === l1Token);
|
|
534
515
|
}
|
|
535
516
|
|
|
536
|
-
getLpTokenInfoForL1Token(l1Token:
|
|
537
|
-
return this.lpTokens[l1Token
|
|
517
|
+
getLpTokenInfoForL1Token(l1Token: string): LpToken | undefined {
|
|
518
|
+
return this.lpTokens[l1Token];
|
|
538
519
|
}
|
|
539
520
|
|
|
540
521
|
areTokensEquivalent(
|
|
541
|
-
tokenA:
|
|
522
|
+
tokenA: string,
|
|
542
523
|
chainIdA: number,
|
|
543
|
-
tokenB:
|
|
524
|
+
tokenB: string,
|
|
544
525
|
chainIdB: number,
|
|
545
526
|
hubPoolBlock = this.latestHeightSearched
|
|
546
527
|
): boolean {
|
|
@@ -553,14 +534,14 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
553
534
|
// Resolve both SpokePool tokens back to their respective HubPool tokens and verify that they match.
|
|
554
535
|
const l1TokenA = this.getL1TokenForL2TokenAtBlock(tokenA, chainIdA, hubPoolBlock);
|
|
555
536
|
const l1TokenB = this.getL1TokenForL2TokenAtBlock(tokenB, chainIdB, hubPoolBlock);
|
|
556
|
-
if (
|
|
537
|
+
if (l1TokenA !== l1TokenB) {
|
|
557
538
|
return false;
|
|
558
539
|
}
|
|
559
540
|
|
|
560
541
|
// Resolve both HubPool tokens back to a current SpokePool token and verify that they match.
|
|
561
542
|
const _tokenA = this.getL2TokenForL1TokenAtBlock(l1TokenA, chainIdA, hubPoolBlock);
|
|
562
543
|
const _tokenB = this.getL2TokenForL1TokenAtBlock(l1TokenB, chainIdB, hubPoolBlock);
|
|
563
|
-
return tokenA
|
|
544
|
+
return tokenA === _tokenA && tokenB === _tokenB;
|
|
564
545
|
}
|
|
565
546
|
|
|
566
547
|
getSpokeActivationBlockForChain(chainId: number): number {
|
|
@@ -797,35 +778,34 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
797
778
|
getLatestExecutedRootBundleContainingL1Token(
|
|
798
779
|
block: number,
|
|
799
780
|
chain: number,
|
|
800
|
-
l1Token:
|
|
781
|
+
l1Token: string
|
|
801
782
|
): ExecutedRootBundle | undefined {
|
|
802
783
|
// Search ExecutedRootBundles in descending block order to find the most recent event before the target block.
|
|
803
784
|
return sortEventsDescending(this.executedRootBundles).find((executedLeaf: ExecutedRootBundle) => {
|
|
804
785
|
return (
|
|
805
786
|
executedLeaf.blockNumber <= block &&
|
|
806
787
|
executedLeaf.chainId === chain &&
|
|
807
|
-
executedLeaf.l1Tokens.some((token) => token.
|
|
788
|
+
executedLeaf.l1Tokens.some((token) => token.toLowerCase() === l1Token.toLowerCase())
|
|
808
789
|
);
|
|
809
790
|
});
|
|
810
791
|
}
|
|
811
792
|
|
|
812
|
-
getRunningBalanceBeforeBlockForChain(block: number, chain: number, l1Token:
|
|
793
|
+
getRunningBalanceBeforeBlockForChain(block: number, chain: number, l1Token: string): TokenRunningBalance {
|
|
813
794
|
const executedRootBundle = this.getLatestExecutedRootBundleContainingL1Token(block, chain, l1Token);
|
|
814
795
|
|
|
815
796
|
return this.getRunningBalanceForToken(l1Token, executedRootBundle);
|
|
816
797
|
}
|
|
817
798
|
|
|
818
799
|
public getRunningBalanceForToken(
|
|
819
|
-
l1Token:
|
|
800
|
+
l1Token: string,
|
|
820
801
|
executedRootBundle: ExecutedRootBundle | undefined
|
|
821
802
|
): TokenRunningBalance {
|
|
822
803
|
let runningBalance = toBN(0);
|
|
823
804
|
if (executedRootBundle) {
|
|
824
|
-
const indexOfL1Token = executedRootBundle.l1Tokens
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
}
|
|
805
|
+
const indexOfL1Token = executedRootBundle.l1Tokens
|
|
806
|
+
.map((l1Token) => l1Token.toLowerCase())
|
|
807
|
+
.indexOf(l1Token.toLowerCase());
|
|
808
|
+
runningBalance = executedRootBundle.runningBalances[indexOfL1Token];
|
|
829
809
|
}
|
|
830
810
|
|
|
831
811
|
return { runningBalance };
|
|
@@ -893,10 +873,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
893
873
|
return {
|
|
894
874
|
success: true,
|
|
895
875
|
currentTime,
|
|
896
|
-
pendingRootBundleProposal
|
|
897
|
-
...pendingRootBundleProposal,
|
|
898
|
-
proposer: toAddressType(pendingRootBundleProposal.proposer, this.chainId),
|
|
899
|
-
},
|
|
876
|
+
pendingRootBundleProposal,
|
|
900
877
|
searchEndBlock: searchConfig.to,
|
|
901
878
|
events: _events,
|
|
902
879
|
};
|
|
@@ -921,9 +898,9 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
921
898
|
|
|
922
899
|
if (eventsToQuery.includes("CrossChainContractsSet")) {
|
|
923
900
|
for (const event of events["CrossChainContractsSet"]) {
|
|
924
|
-
const args = spreadEventWithBlockNumber(event) as CrossChainContractsSet
|
|
901
|
+
const args = spreadEventWithBlockNumber(event) as CrossChainContractsSet;
|
|
925
902
|
const dataToAdd: CrossChainContractsSet = {
|
|
926
|
-
spokePool:
|
|
903
|
+
spokePool: args.spokePool,
|
|
927
904
|
blockNumber: args.blockNumber,
|
|
928
905
|
txnRef: args.txnRef,
|
|
929
906
|
logIndex: args.logIndex,
|
|
@@ -939,8 +916,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
939
916
|
if (!solanaSpokePool) {
|
|
940
917
|
throw new Error(`SVM spoke pool not found for chain ${args.l2ChainId}`);
|
|
941
918
|
}
|
|
942
|
-
const
|
|
943
|
-
const truncatedAddress = svmSpoke.truncateToBytes20();
|
|
919
|
+
const truncatedAddress = SvmAddress.from(solanaSpokePool).truncateToBytes20();
|
|
944
920
|
// Verify the event address matches our expected truncated address
|
|
945
921
|
if (args.spokePool.toLowerCase() !== truncatedAddress.toLowerCase()) {
|
|
946
922
|
throw new Error(
|
|
@@ -948,7 +924,8 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
948
924
|
`Expected ${truncatedAddress}, got ${args.spokePool}`
|
|
949
925
|
);
|
|
950
926
|
}
|
|
951
|
-
|
|
927
|
+
// Store the full Solana address
|
|
928
|
+
dataToAdd.spokePool = SvmAddress.from(solanaSpokePool).toBytes32();
|
|
952
929
|
}
|
|
953
930
|
assign(this.crossChainContracts, [args.l2ChainId], [dataToAdd]);
|
|
954
931
|
}
|
|
@@ -956,37 +933,34 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
956
933
|
|
|
957
934
|
if (eventsToQuery.includes("SetPoolRebalanceRoute")) {
|
|
958
935
|
for (const event of events["SetPoolRebalanceRoute"]) {
|
|
959
|
-
const args = spreadEventWithBlockNumber(event) as SetPoolRebalanceRoot
|
|
960
|
-
l1Token: string;
|
|
961
|
-
destinationToken: string;
|
|
962
|
-
};
|
|
936
|
+
const args = spreadEventWithBlockNumber(event) as SetPoolRebalanceRoot;
|
|
963
937
|
|
|
964
938
|
// If the destination chain is SVM, then we need to convert the destination token to the Solana address.
|
|
965
939
|
// This is because the HubPool contract only holds a truncated address for the USDC token and currently
|
|
966
940
|
// only supports USDC as a destination token for Solana.
|
|
967
|
-
let destinationToken =
|
|
941
|
+
let destinationToken = args.destinationToken;
|
|
968
942
|
if (chainIsSvm(args.destinationChainId)) {
|
|
969
943
|
const usdcTokenSol = TOKEN_SYMBOLS_MAP.USDC.addresses[args.destinationChainId];
|
|
970
|
-
const
|
|
971
|
-
if (destinationToken.
|
|
944
|
+
const truncatedAddress = SvmAddress.from(usdcTokenSol).truncateToBytes20();
|
|
945
|
+
if (destinationToken.toLowerCase() !== truncatedAddress.toLowerCase()) {
|
|
972
946
|
throw new Error(
|
|
973
947
|
`SVM USDC address mismatch for chain ${args.destinationChainId}. ` +
|
|
974
|
-
`Expected ${
|
|
948
|
+
`Expected ${truncatedAddress}, got ${destinationToken}`
|
|
975
949
|
);
|
|
976
950
|
}
|
|
977
|
-
destinationToken =
|
|
951
|
+
destinationToken = SvmAddress.from(usdcTokenSol).toBytes32();
|
|
978
952
|
}
|
|
979
953
|
|
|
980
954
|
// If the destination token is set to the zero address in an event, then this means Across should no longer
|
|
981
955
|
// rebalance to this chain.
|
|
982
|
-
if (
|
|
956
|
+
if (destinationToken !== ZERO_ADDRESS) {
|
|
983
957
|
assign(this.l1TokensToDestinationTokens, [args.l1Token, args.destinationChainId], destinationToken);
|
|
984
958
|
assign(
|
|
985
959
|
this.l1TokensToDestinationTokensWithBlock,
|
|
986
960
|
[args.l1Token, args.destinationChainId],
|
|
987
961
|
[
|
|
988
962
|
{
|
|
989
|
-
l1Token:
|
|
963
|
+
l1Token: args.l1Token,
|
|
990
964
|
l2Token: destinationToken,
|
|
991
965
|
blockNumber: args.blockNumber,
|
|
992
966
|
txnIndex: args.txnIndex,
|
|
@@ -1008,15 +982,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
1008
982
|
);
|
|
1009
983
|
|
|
1010
984
|
const [tokenInfo, lpTokenInfo] = await Promise.all([
|
|
1011
|
-
Promise.all(
|
|
1012
|
-
uniqueL1Tokens.map(async (l1Token: string) => {
|
|
1013
|
-
const tokenInfo = await fetchTokenInfo(l1Token, this.hubPool.provider);
|
|
1014
|
-
return {
|
|
1015
|
-
...tokenInfo,
|
|
1016
|
-
address: EvmAddress.from(l1Token),
|
|
1017
|
-
};
|
|
1018
|
-
})
|
|
1019
|
-
),
|
|
985
|
+
Promise.all(uniqueL1Tokens.map((l1Token: string) => fetchTokenInfo(l1Token, this.hubPool.provider))),
|
|
1020
986
|
Promise.all(
|
|
1021
987
|
uniqueL1Tokens.map(
|
|
1022
988
|
async (l1Token: string) => await this.hubPool.pooledTokens(l1Token, { blockTag: update.searchEndBlock })
|
|
@@ -1024,7 +990,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
1024
990
|
),
|
|
1025
991
|
]);
|
|
1026
992
|
for (const info of tokenInfo) {
|
|
1027
|
-
if (!this.l1Tokens.find((token) => token.address
|
|
993
|
+
if (!this.l1Tokens.find((token) => compareAddressesSimple(token.address, info.address))) {
|
|
1028
994
|
if (info.decimals > 0 && info.decimals <= 18) {
|
|
1029
995
|
this.l1Tokens.push(info);
|
|
1030
996
|
} else {
|
|
@@ -1045,13 +1011,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
1045
1011
|
this.proposedRootBundles.push(
|
|
1046
1012
|
...events["ProposeRootBundle"]
|
|
1047
1013
|
.filter((event) => !this.configOverride.ignoredHubProposedBundles.includes(event.blockNumber))
|
|
1048
|
-
.map((
|
|
1049
|
-
const args = spreadEventWithBlockNumber(_event) as ProposedRootBundle & { proposer: string };
|
|
1050
|
-
return {
|
|
1051
|
-
...args,
|
|
1052
|
-
proposer: EvmAddress.from(args.proposer),
|
|
1053
|
-
};
|
|
1054
|
-
})
|
|
1014
|
+
.map((event) => spreadEventWithBlockNumber(event) as ProposedRootBundle)
|
|
1055
1015
|
);
|
|
1056
1016
|
}
|
|
1057
1017
|
|
|
@@ -1074,7 +1034,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
1074
1034
|
}
|
|
1075
1035
|
|
|
1076
1036
|
// Set running balances and incentive balances for this bundle.
|
|
1077
|
-
const executedRootBundle = spreadEventWithBlockNumber(event) as ExecutedRootBundle
|
|
1037
|
+
const executedRootBundle = spreadEventWithBlockNumber(event) as ExecutedRootBundle;
|
|
1078
1038
|
const { l1Tokens, runningBalances } = executedRootBundle;
|
|
1079
1039
|
const nTokens = l1Tokens.length;
|
|
1080
1040
|
|
|
@@ -1086,12 +1046,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
1086
1046
|
);
|
|
1087
1047
|
}
|
|
1088
1048
|
executedRootBundle.runningBalances = runningBalances.slice(0, nTokens);
|
|
1089
|
-
this.executedRootBundles.push(
|
|
1090
|
-
...executedRootBundle,
|
|
1091
|
-
l1Tokens: l1Tokens.map((token: string) => {
|
|
1092
|
-
return EvmAddress.from(token, "base16");
|
|
1093
|
-
}),
|
|
1094
|
-
});
|
|
1049
|
+
this.executedRootBundles.push(executedRootBundle);
|
|
1095
1050
|
}
|
|
1096
1051
|
}
|
|
1097
1052
|
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
MakeOptional,
|
|
18
18
|
toBN,
|
|
19
19
|
EvmAddress,
|
|
20
|
-
toAddressType,
|
|
21
20
|
} from "../../utils";
|
|
22
21
|
import {
|
|
23
22
|
EventSearchConfig,
|
|
@@ -195,11 +194,6 @@ export class EVMSpokePoolClient extends SpokePoolClient {
|
|
|
195
194
|
|
|
196
195
|
deposit = {
|
|
197
196
|
...spreadEventWithBlockNumber(event),
|
|
198
|
-
inputToken: toAddressType(event.args.inputToken, this.chainId),
|
|
199
|
-
outputToken: toAddressType(event.args.outputToken, event.args.destinationChainId),
|
|
200
|
-
depositor: toAddressType(event.args.depositor, this.chainId),
|
|
201
|
-
recipient: toAddressType(event.args.recipient, event.args.destinationChainId),
|
|
202
|
-
exclusiveRelayer: toAddressType(event.args.exclusiveRelayer, event.args.destinationChainId),
|
|
203
197
|
originChainId: this.chainId,
|
|
204
198
|
quoteBlockNumber: await this.getBlockNumber(Number(event.args["quoteTimestamp"])),
|
|
205
199
|
fromLiteChain: true, // To be updated immediately afterwards.
|