@across-protocol/sdk 4.2.9-alpha.1 → 4.2.9-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/arch/evm/SpokeUtils.d.ts +5 -2
- package/dist/cjs/arch/evm/SpokeUtils.js +22 -5
- package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/SpokeUtils.js +14 -11
- package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/utils.d.ts +1 -1
- package/dist/cjs/arch/svm/utils.js +15 -13
- package/dist/cjs/arch/svm/utils.js.map +1 -1
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +60 -56
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +13 -13
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +3 -2
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +3 -3
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +11 -8
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/cjs/clients/HubPoolClient.d.ts +21 -21
- package/dist/cjs/clients/HubPoolClient.js +83 -59
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -2
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +5 -3
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +55 -49
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +9 -9
- package/dist/cjs/clients/mocks/MockHubPoolClient.js +15 -9
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +9 -13
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +42 -56
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +2 -2
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
- package/dist/cjs/interfaces/HubPool.d.ts +19 -14
- package/dist/cjs/interfaces/SpokePool.d.ts +14 -16
- package/dist/cjs/interfaces/SpokePool.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +7 -7
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +4 -4
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +14 -15
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +7 -7
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +6 -3
- package/dist/cjs/utils/AddressUtils.js +42 -14
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.d.ts +3 -3
- package/dist/cjs/utils/SpokeUtils.js +4 -22
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/cjs/utils/TokenUtils.d.ts +4 -4
- package/dist/cjs/utils/TokenUtils.js +3 -3
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/esm/arch/evm/SpokeUtils.d.ts +5 -2
- package/dist/esm/arch/evm/SpokeUtils.js +23 -6
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.js +14 -11
- package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/utils.d.ts +1 -1
- package/dist/esm/arch/svm/utils.js +15 -13
- package/dist/esm/arch/svm/utils.js.map +1 -1
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +61 -57
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +14 -14
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +4 -3
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -4
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +12 -9
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +23 -22
- package/dist/esm/clients/HubPoolClient.js +96 -63
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +3 -3
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +5 -3
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +57 -50
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +9 -9
- package/dist/esm/clients/mocks/MockHubPoolClient.js +16 -10
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +9 -13
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +46 -60
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +3 -3
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
- package/dist/esm/interfaces/HubPool.d.ts +19 -14
- package/dist/esm/interfaces/SpokePool.d.ts +14 -16
- package/dist/esm/interfaces/SpokePool.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +8 -8
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +4 -4
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +15 -16
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +8 -8
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +7 -3
- package/dist/esm/utils/AddressUtils.js +52 -19
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.d.ts +3 -8
- package/dist/esm/utils/SpokeUtils.js +4 -26
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/TokenUtils.d.ts +18 -16
- package/dist/esm/utils/TokenUtils.js +3 -3
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/types/arch/evm/SpokeUtils.d.ts +5 -2
- package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/utils.d.ts +1 -1
- package/dist/types/arch/svm/utils.d.ts.map +1 -1
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +23 -22
- package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +5 -3
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts +9 -9
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +9 -13
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
- package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts.map +1 -1
- package/dist/types/interfaces/HubPool.d.ts +19 -14
- package/dist/types/interfaces/HubPool.d.ts.map +1 -1
- package/dist/types/interfaces/SpokePool.d.ts +14 -16
- package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +4 -4
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +7 -3
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/SpokeUtils.d.ts +3 -8
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/dist/types/utils/TokenUtils.d.ts +18 -16
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +1 -2
- package/src/arch/evm/SpokeUtils.ts +41 -11
- package/src/arch/svm/SpokeUtils.ts +23 -9
- package/src/arch/svm/utils.ts +3 -3
- package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
- package/src/clients/BundleDataClient/BundleDataClient.ts +54 -52
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +28 -13
- package/src/clients/BundleDataClient/utils/FillUtils.ts +6 -4
- package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +7 -1
- package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
- package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +13 -9
- package/src/clients/HubPoolClient.ts +122 -82
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +7 -1
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +113 -43
- package/src/clients/mocks/MockHubPoolClient.ts +24 -19
- package/src/clients/mocks/MockSpokePoolClient.ts +55 -74
- package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
- package/src/interfaces/HubPool.ts +23 -14
- package/src/interfaces/SpokePool.ts +14 -17
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +10 -8
- package/src/relayFeeCalculator/chain-queries/svmQuery.ts +16 -21
- package/src/relayFeeCalculator/relayFeeCalculator.ts +20 -12
- package/src/utils/AddressUtils.ts +56 -21
- package/src/utils/SpokeUtils.ts +11 -33
- package/src/utils/TokenUtils.ts +7 -7
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import { BytesLike, Contract, PopulatedTransaction, providers } from "ethers";
|
|
3
3
|
import { CHAIN_IDs } from "../../constants";
|
|
4
|
-
import { Deposit, FillStatus, FillWithBlock, RelayData } from "../../interfaces";
|
|
4
|
+
import { Deposit, FillStatus, FillWithBlock, RelayData, SortableEvent } from "../../interfaces";
|
|
5
5
|
import {
|
|
6
|
+
EvmAddress,
|
|
6
7
|
bnUint32Max,
|
|
7
8
|
BigNumber,
|
|
8
9
|
toBN,
|
|
@@ -13,11 +14,11 @@ import {
|
|
|
13
14
|
isDefined,
|
|
14
15
|
isUnsafeDepositId,
|
|
15
16
|
isZeroAddress,
|
|
16
|
-
getDepositRelayData,
|
|
17
17
|
getNetworkName,
|
|
18
18
|
paginatedEventQuery,
|
|
19
19
|
spreadEventWithBlockNumber,
|
|
20
|
-
|
|
20
|
+
Address,
|
|
21
|
+
toAddressType,
|
|
21
22
|
} from "../../utils";
|
|
22
23
|
|
|
23
24
|
type BlockTag = providers.BlockTag;
|
|
@@ -30,11 +31,31 @@ type BlockTag = providers.BlockTag;
|
|
|
30
31
|
*/
|
|
31
32
|
export function populateV3Relay(
|
|
32
33
|
spokePool: Contract,
|
|
33
|
-
deposit: Omit<Deposit, "messageHash"
|
|
34
|
-
|
|
34
|
+
deposit: Omit<Deposit, "messageHash" | "fromLiteChain" | "toLiteChain"> & {
|
|
35
|
+
recipient: EvmAddress;
|
|
36
|
+
exclusiveRelayer: EvmAddress;
|
|
37
|
+
},
|
|
38
|
+
relayer: Address,
|
|
35
39
|
repaymentChainId = deposit.destinationChainId
|
|
36
40
|
): Promise<PopulatedTransaction> {
|
|
37
|
-
|
|
41
|
+
assert(
|
|
42
|
+
relayer.isValidOn(repaymentChainId),
|
|
43
|
+
`Invalid repayment address for chain ${repaymentChainId}: ${relayer.toAddress()}.`
|
|
44
|
+
);
|
|
45
|
+
const relayData = {
|
|
46
|
+
depositor: deposit.depositor.toBytes32(),
|
|
47
|
+
recipient: deposit.recipient.toBytes32(),
|
|
48
|
+
inputToken: deposit.inputToken.toBytes32(),
|
|
49
|
+
outputToken: deposit.outputToken.toBytes32(),
|
|
50
|
+
inputAmount: deposit.inputAmount,
|
|
51
|
+
outputAmount: deposit.outputAmount,
|
|
52
|
+
originChainId: deposit.originChainId,
|
|
53
|
+
depositId: deposit.depositId,
|
|
54
|
+
fillDeadline: deposit.fillDeadline,
|
|
55
|
+
exclusivityDeadline: deposit.exclusivityDeadline,
|
|
56
|
+
message: deposit.message,
|
|
57
|
+
exclusiveRelayer: deposit.exclusiveRelayer.toBytes32(),
|
|
58
|
+
};
|
|
38
59
|
|
|
39
60
|
if (isDefined(deposit.speedUpSignature)) {
|
|
40
61
|
assert(isDefined(deposit.updatedRecipient) && !isZeroAddress(deposit.updatedRecipient));
|
|
@@ -43,16 +64,18 @@ export function populateV3Relay(
|
|
|
43
64
|
return spokePool.populateTransaction.fillRelayWithUpdatedDeposit(
|
|
44
65
|
relayData,
|
|
45
66
|
repaymentChainId,
|
|
46
|
-
toBytes32(
|
|
67
|
+
relayer.toBytes32(),
|
|
47
68
|
deposit.updatedOutputAmount,
|
|
48
|
-
|
|
69
|
+
deposit.updatedRecipient.toBytes32(),
|
|
49
70
|
deposit.updatedMessage,
|
|
50
71
|
deposit.speedUpSignature,
|
|
51
|
-
{ from: relayer }
|
|
72
|
+
{ from: relayer.toAddress() }
|
|
52
73
|
);
|
|
53
74
|
}
|
|
54
75
|
|
|
55
|
-
return spokePool.populateTransaction.fillRelay(relayData, repaymentChainId, toBytes32(
|
|
76
|
+
return spokePool.populateTransaction.fillRelay(relayData, repaymentChainId, relayer.toBytes32(), {
|
|
77
|
+
from: relayer.toAddress(),
|
|
78
|
+
});
|
|
56
79
|
}
|
|
57
80
|
|
|
58
81
|
/**
|
|
@@ -315,8 +338,15 @@ export async function findFillEvent(
|
|
|
315
338
|
const destinationChainId = Object.values(CHAIN_IDs).includes(relayData.originChainId)
|
|
316
339
|
? (await spokePool.provider.getNetwork()).chainId
|
|
317
340
|
: Number(await spokePool.chainId());
|
|
341
|
+
const fillEvent = spreadEventWithBlockNumber(event) as SortableEvent & Record<string, unknown>;
|
|
318
342
|
const fill = {
|
|
319
|
-
...
|
|
343
|
+
...fillEvent,
|
|
344
|
+
inputToken: toAddressType(fillEvent.inputToken as string, relayData.originChainId),
|
|
345
|
+
outputToken: toAddressType(fillEvent.outputToken as string, destinationChainId),
|
|
346
|
+
depositor: toAddressType(fillEvent.depositor as string, relayData.originChainId),
|
|
347
|
+
recipient: toAddressType(fillEvent.recipient as string, destinationChainId),
|
|
348
|
+
exclusiveRelayer: toAddressType(fillEvent.exclusiveRelayer as string, destinationChainId),
|
|
349
|
+
relayer: toAddressType(fillEvent.relayer as string, destinationChainId),
|
|
320
350
|
destinationChainId,
|
|
321
351
|
messageHash: getMessageHash(event.args.message),
|
|
322
352
|
} as FillWithBlock;
|
|
@@ -136,13 +136,19 @@ export async function findDeposit(
|
|
|
136
136
|
return undefined;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
const unwrappedDepositEvent = unwrapEventData(depositEvent.data) as Record<string, unknown>;
|
|
139
140
|
// Return the deposit event with block info
|
|
140
141
|
return {
|
|
141
142
|
txnRef: depositEvent.signature.toString(),
|
|
142
143
|
blockNumber: Number(depositEvent.slot),
|
|
143
144
|
txnIndex: 0,
|
|
144
145
|
logIndex: 0,
|
|
145
|
-
...
|
|
146
|
+
...unwrappedDepositEvent,
|
|
147
|
+
depositor: toAddressType(unwrappedDepositEvent.depositor as string),
|
|
148
|
+
recipient: toAddressType(unwrappedDepositEvent.recipient as string),
|
|
149
|
+
inputToken: toAddressType(unwrappedDepositEvent.inputToken as string),
|
|
150
|
+
outputToken: toAddressType(unwrappedDepositEvent.outputToken as string),
|
|
151
|
+
exclusiveRelayer: toAddressType(unwrappedDepositEvent.exclusiveRelayer as string),
|
|
146
152
|
} as DepositWithBlock;
|
|
147
153
|
}
|
|
148
154
|
|
|
@@ -318,13 +324,21 @@ export async function findFillEvent(
|
|
|
318
324
|
|
|
319
325
|
if (fillEvents.length > 0) {
|
|
320
326
|
const rawFillEvent = fillEvents[0];
|
|
327
|
+
const eventData = unwrapEventData(rawFillEvent.data) as Record<string, unknown>;
|
|
328
|
+
const originChainId = eventData.originChainId as number;
|
|
321
329
|
const parsedFillEvent = {
|
|
322
330
|
transactionHash: rawFillEvent.signature,
|
|
323
331
|
blockNumber: Number(rawFillEvent.slot),
|
|
324
332
|
transactionIndex: 0,
|
|
325
333
|
logIndex: 0,
|
|
326
334
|
destinationChainId,
|
|
327
|
-
...
|
|
335
|
+
...eventData,
|
|
336
|
+
inputToken: toAddressType(eventData.inputToken as string, originChainId),
|
|
337
|
+
outputToken: toAddressType(eventData.outputToken as string, destinationChainId),
|
|
338
|
+
relayer: toAddressType(eventData.relayer as string, destinationChainId),
|
|
339
|
+
exclusiveRelayer: toAddressType(eventData.exclusiveRelayer as string, destinationChainId),
|
|
340
|
+
depositor: toAddressType(eventData.depositor as string, originChainId),
|
|
341
|
+
recipient: toAddressType(eventData.recipient as string, destinationChainId),
|
|
328
342
|
} as unknown as FillWithBlock;
|
|
329
343
|
return parsedFillEvent;
|
|
330
344
|
}
|
|
@@ -357,7 +371,7 @@ export async function fillRelayInstruction(
|
|
|
357
371
|
deposit.exclusiveRelayer,
|
|
358
372
|
deposit.inputToken,
|
|
359
373
|
deposit.outputToken,
|
|
360
|
-
].map((addr) =>
|
|
374
|
+
].map((addr) => addr.forceSvmAddress());
|
|
361
375
|
|
|
362
376
|
const _relayDataHash = getRelayDataHash(deposit, deposit.destinationChainId);
|
|
363
377
|
const relayDataHash = new Uint8Array(Buffer.from(_relayDataHash.slice(2), "hex"));
|
|
@@ -368,7 +382,7 @@ export async function fillRelayInstruction(
|
|
|
368
382
|
const [statePda, fillStatusPda, eventAuthority] = await Promise.all([
|
|
369
383
|
getStatePda(spokePool.toV2Address()),
|
|
370
384
|
getFillStatusPda(spokePool.toV2Address(), deposit, deposit.destinationChainId),
|
|
371
|
-
getEventAuthority(),
|
|
385
|
+
getEventAuthority(spokePool.toV2Address()),
|
|
372
386
|
]);
|
|
373
387
|
const depositIdBuffer = new Uint8Array(32);
|
|
374
388
|
const shortenedBuffer = new Uint8Array(Buffer.from(deposit.depositId.toHexString().slice(2), "hex"));
|
|
@@ -591,11 +605,11 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId: numbe
|
|
|
591
605
|
assert(relayData.message.startsWith("0x"), "Message must be a hex string");
|
|
592
606
|
|
|
593
607
|
const contentToHash = Buffer.concat([
|
|
594
|
-
Uint8Array.from(addressEncoder.encode(
|
|
595
|
-
Uint8Array.from(addressEncoder.encode(
|
|
596
|
-
Uint8Array.from(addressEncoder.encode(
|
|
597
|
-
Uint8Array.from(addressEncoder.encode(
|
|
598
|
-
Uint8Array.from(addressEncoder.encode(
|
|
608
|
+
Uint8Array.from(addressEncoder.encode(address(relayData.depositor.toBase58()))),
|
|
609
|
+
Uint8Array.from(addressEncoder.encode(address(relayData.recipient.toBase58()))),
|
|
610
|
+
Uint8Array.from(addressEncoder.encode(address(relayData.exclusiveRelayer.toBase58()))),
|
|
611
|
+
Uint8Array.from(addressEncoder.encode(address(relayData.inputToken.toBase58()))),
|
|
612
|
+
Uint8Array.from(addressEncoder.encode(address(relayData.outputToken.toBase58()))),
|
|
599
613
|
Uint8Array.from(uint64Encoder.encode(BigInt(relayData.inputAmount.toString()))),
|
|
600
614
|
Uint8Array.from(uint64Encoder.encode(BigInt(relayData.outputAmount.toString()))),
|
|
601
615
|
Uint8Array.from(uint64Encoder.encode(BigInt(relayData.originChainId.toString()))),
|
package/src/arch/svm/utils.ts
CHANGED
|
@@ -268,13 +268,13 @@ export async function getInstructionParamsPda(programId: Address, signer: Addres
|
|
|
268
268
|
* Returns the PDA for the Event Authority.
|
|
269
269
|
* @returns The PDA for the Event Authority.
|
|
270
270
|
*/
|
|
271
|
-
export
|
|
271
|
+
export async function getEventAuthority(programId: Address): Promise<Address> {
|
|
272
272
|
const [eventAuthority] = await getProgramDerivedAddress({
|
|
273
|
-
programAddress:
|
|
273
|
+
programAddress: programId,
|
|
274
274
|
seeds: ["__event_authority"],
|
|
275
275
|
});
|
|
276
276
|
return eventAuthority;
|
|
277
|
-
}
|
|
277
|
+
}
|
|
278
278
|
|
|
279
279
|
/**
|
|
280
280
|
* Returns a random SVM address.
|
|
@@ -5,6 +5,7 @@ import winston from "winston";
|
|
|
5
5
|
import { isError } from "../../typeguards";
|
|
6
6
|
import {
|
|
7
7
|
EventSearchConfig,
|
|
8
|
+
EvmAddress,
|
|
8
9
|
MakeOptional,
|
|
9
10
|
isArrayOf,
|
|
10
11
|
isDefined,
|
|
@@ -107,7 +108,7 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
getRateModelForBlockNumber(
|
|
110
|
-
l1Token:
|
|
111
|
+
l1Token: EvmAddress,
|
|
111
112
|
originChainId: number | string,
|
|
112
113
|
destinationChainId: number | string,
|
|
113
114
|
blockNumber: number | undefined = undefined
|
|
@@ -121,7 +122,9 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
121
122
|
|
|
122
123
|
const defaultRateModelUpdate = sortEventsDescending(this.cumulativeRateModelUpdates).find(
|
|
123
124
|
(config) =>
|
|
124
|
-
config.blockNumber <= (blockNumber ?? 0) &&
|
|
125
|
+
config.blockNumber <= (blockNumber ?? 0) &&
|
|
126
|
+
config.l1Token === l1Token.toEvmAddress() &&
|
|
127
|
+
config.rateModel !== undefined
|
|
125
128
|
);
|
|
126
129
|
if (!defaultRateModelUpdate) {
|
|
127
130
|
throw new Error(`Could not find TokenConfig update for ${l1Token} at block ${blockNumber}`);
|
|
@@ -130,12 +133,12 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
getRouteRateModelForBlockNumber(
|
|
133
|
-
l1Token:
|
|
136
|
+
l1Token: EvmAddress,
|
|
134
137
|
route: string,
|
|
135
138
|
blockNumber: number | undefined = undefined
|
|
136
139
|
): RateModel | undefined {
|
|
137
140
|
const config = (sortEventsDescending(this.cumulativeRouteRateModelUpdates) as RouteRateModelUpdate[]).find(
|
|
138
|
-
(config) => config.blockNumber <= (blockNumber ?? 0) && config.l1Token === l1Token
|
|
141
|
+
(config) => config.blockNumber <= (blockNumber ?? 0) && config.l1Token === l1Token.toEvmAddress()
|
|
139
142
|
);
|
|
140
143
|
if (config?.routeRateModel[route] === undefined) {
|
|
141
144
|
return undefined;
|
|
@@ -40,9 +40,9 @@ import {
|
|
|
40
40
|
isZeroValueDeposit,
|
|
41
41
|
isZeroValueFillOrSlowFillRequest,
|
|
42
42
|
chainIsEvm,
|
|
43
|
-
isValidEvmAddress,
|
|
44
43
|
duplicateEvent,
|
|
45
44
|
invalidOutputToken,
|
|
45
|
+
Address,
|
|
46
46
|
} from "../../utils";
|
|
47
47
|
import winston from "winston";
|
|
48
48
|
import {
|
|
@@ -67,22 +67,20 @@ type DataCache = Record<string, Promise<LoadDataReturnValue>>;
|
|
|
67
67
|
// V3 dictionary helper functions
|
|
68
68
|
function updateExpiredDepositsV3(dict: ExpiredDepositsToRefundV3, deposit: V3DepositWithBlock): void {
|
|
69
69
|
// A deposit refund for a deposit is invalid if the depositor has a bytes32 address input for an EVM chain. It is valid otherwise.
|
|
70
|
-
if (chainIsEvm(deposit.originChainId) && !
|
|
70
|
+
if (chainIsEvm(deposit.originChainId) && !deposit.depositor.isValidEvmAddress()) {
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
const { originChainId, inputToken } = deposit;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
dict[originChainId][inputToken].push(deposit);
|
|
74
|
+
dict[originChainId] ??= {};
|
|
75
|
+
dict[originChainId][inputToken.toBytes32()] ??= [];
|
|
76
|
+
dict[originChainId][inputToken.toBytes32()].push(deposit);
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
function updateBundleDepositsV3(dict: BundleDepositsV3, deposit: V3DepositWithBlock): void {
|
|
81
80
|
const { originChainId, inputToken } = deposit;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
dict[originChainId][inputToken].push(deposit);
|
|
81
|
+
dict[originChainId] ??= {};
|
|
82
|
+
dict[originChainId][inputToken.toBytes32()] ??= [];
|
|
83
|
+
dict[originChainId][inputToken.toBytes32()].push(deposit);
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
function updateBundleFillsV3(
|
|
@@ -90,29 +88,28 @@ function updateBundleFillsV3(
|
|
|
90
88
|
fill: V3FillWithBlock,
|
|
91
89
|
lpFeePct: BigNumber,
|
|
92
90
|
repaymentChainId: number,
|
|
93
|
-
repaymentToken:
|
|
94
|
-
repaymentAddress:
|
|
91
|
+
repaymentToken: Address,
|
|
92
|
+
repaymentAddress: Address
|
|
95
93
|
): void {
|
|
96
94
|
// We shouldn't pass any unrepayable fills into this function, so we perform an extra safety check.
|
|
97
|
-
if (chainIsEvm(repaymentChainId) && !
|
|
95
|
+
if (chainIsEvm(repaymentChainId) && !fill.relayer.isValidEvmAddress()) {
|
|
98
96
|
return;
|
|
99
97
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
98
|
+
dict[repaymentChainId] ??= {};
|
|
99
|
+
dict[repaymentChainId][repaymentToken.toBytes32()] ??= {
|
|
100
|
+
fills: [],
|
|
101
|
+
totalRefundAmount: bnZero,
|
|
102
|
+
realizedLpFees: bnZero,
|
|
103
|
+
refunds: {},
|
|
104
|
+
};
|
|
108
105
|
|
|
109
106
|
const bundleFill: BundleFillV3 = { ...fill, lpFeePct, relayer: repaymentAddress };
|
|
110
107
|
|
|
111
108
|
// Add all fills, slow and fast, to dictionary.
|
|
112
|
-
assign(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
|
|
109
|
+
assign(dict, [repaymentChainId, repaymentToken.toBytes32(), "fills"], [bundleFill]);
|
|
113
110
|
|
|
114
111
|
// All fills update the bundle LP fees.
|
|
115
|
-
const refundObj = dict[repaymentChainId][repaymentToken];
|
|
112
|
+
const refundObj = dict[repaymentChainId][repaymentToken.toBytes32()];
|
|
116
113
|
const realizedLpFee = bundleFill.inputAmount.mul(bundleFill.lpFeePct).div(fixedPointAdjustment);
|
|
117
114
|
refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
|
|
118
115
|
|
|
@@ -126,10 +123,11 @@ function updateBundleFillsV3(
|
|
|
126
123
|
// Instantiate dictionary if it doesn't exist.
|
|
127
124
|
refundObj.refunds ??= {};
|
|
128
125
|
|
|
129
|
-
if (refundObj.refunds[bundleFill.relayer]) {
|
|
130
|
-
refundObj.refunds[bundleFill.relayer] =
|
|
126
|
+
if (refundObj.refunds[bundleFill.relayer.toBytes32()]) {
|
|
127
|
+
refundObj.refunds[bundleFill.relayer.toBytes32()] =
|
|
128
|
+
refundObj.refunds[bundleFill.relayer.toBytes32()].add(refundAmount);
|
|
131
129
|
} else {
|
|
132
|
-
refundObj.refunds[bundleFill.relayer] = refundAmount;
|
|
130
|
+
refundObj.refunds[bundleFill.relayer.toBytes32()] = refundAmount;
|
|
133
131
|
}
|
|
134
132
|
}
|
|
135
133
|
}
|
|
@@ -139,21 +137,19 @@ function updateBundleExcessSlowFills(
|
|
|
139
137
|
deposit: V3DepositWithBlock & { lpFeePct: BigNumber }
|
|
140
138
|
): void {
|
|
141
139
|
const { destinationChainId, outputToken } = deposit;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
dict[destinationChainId][outputToken].push(deposit);
|
|
140
|
+
dict[destinationChainId] ??= {};
|
|
141
|
+
dict[destinationChainId][outputToken.toBytes32()] ??= [];
|
|
142
|
+
dict[destinationChainId][outputToken.toBytes32()].push(deposit);
|
|
146
143
|
}
|
|
147
144
|
|
|
148
145
|
function updateBundleSlowFills(dict: BundleSlowFills, deposit: V3DepositWithBlock & { lpFeePct: BigNumber }): void {
|
|
149
|
-
if (chainIsEvm(deposit.destinationChainId) && !
|
|
146
|
+
if (chainIsEvm(deposit.destinationChainId) && !deposit.recipient.isValidEvmAddress()) {
|
|
150
147
|
return;
|
|
151
148
|
}
|
|
152
149
|
const { destinationChainId, outputToken } = deposit;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
dict[destinationChainId][outputToken].push(deposit);
|
|
150
|
+
dict[destinationChainId] ??= {};
|
|
151
|
+
dict[destinationChainId][outputToken.toBytes32()] ??= [];
|
|
152
|
+
dict[destinationChainId][outputToken.toBytes32()].push(deposit);
|
|
157
153
|
}
|
|
158
154
|
|
|
159
155
|
// @notice Shared client for computing data needed to construct or validate a bundle.
|
|
@@ -489,21 +485,23 @@ export class BundleDataClient {
|
|
|
489
485
|
// worst from the relayer's perspective.
|
|
490
486
|
const { relayer, inputAmount: refundAmount } = fill;
|
|
491
487
|
refundsForChain[chainToSendRefundTo] ??= {};
|
|
492
|
-
refundsForChain[chainToSendRefundTo][repaymentToken] ??= {};
|
|
493
|
-
const existingRefundAmount =
|
|
494
|
-
|
|
488
|
+
refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()] ??= {};
|
|
489
|
+
const existingRefundAmount =
|
|
490
|
+
refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()][relayer.toBytes32()] ?? bnZero;
|
|
491
|
+
refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()][relayer.toBytes32()] =
|
|
492
|
+
existingRefundAmount.add(refundAmount);
|
|
495
493
|
});
|
|
496
494
|
}
|
|
497
495
|
return refundsForChain;
|
|
498
496
|
}
|
|
499
497
|
|
|
500
|
-
getUpcomingDepositAmount(chainId: number, l2Token:
|
|
498
|
+
getUpcomingDepositAmount(chainId: number, l2Token: Address, latestBlockToSearch: number): BigNumber {
|
|
501
499
|
if (this.spokePoolClients[chainId] === undefined) {
|
|
502
500
|
return toBN(0);
|
|
503
501
|
}
|
|
504
502
|
return this.spokePoolClients[chainId]
|
|
505
503
|
.getDeposits()
|
|
506
|
-
.filter((deposit) => deposit.blockNumber > latestBlockToSearch && deposit.inputToken
|
|
504
|
+
.filter((deposit) => deposit.blockNumber > latestBlockToSearch && deposit.inputToken.eq(l2Token))
|
|
507
505
|
.reduce((acc, deposit) => {
|
|
508
506
|
return acc.add(deposit.inputAmount);
|
|
509
507
|
}, toBN(0));
|
|
@@ -626,18 +624,18 @@ export class BundleDataClient {
|
|
|
626
624
|
const executedRefunds: { [tokenAddress: string]: { [relayer: string]: BigNumber } } = {};
|
|
627
625
|
for (const refundLeaf of executedRefundLeaves) {
|
|
628
626
|
const tokenAddress = refundLeaf.l2TokenAddress;
|
|
629
|
-
if (executedRefunds[tokenAddress] === undefined) {
|
|
630
|
-
executedRefunds[tokenAddress] = {};
|
|
627
|
+
if (executedRefunds[tokenAddress.toBytes32()] === undefined) {
|
|
628
|
+
executedRefunds[tokenAddress.toBytes32()] = {};
|
|
631
629
|
}
|
|
632
|
-
const executedTokenRefunds = executedRefunds[tokenAddress];
|
|
630
|
+
const executedTokenRefunds = executedRefunds[tokenAddress.toBytes32()];
|
|
633
631
|
|
|
634
632
|
for (let i = 0; i < refundLeaf.refundAddresses.length; i++) {
|
|
635
633
|
const relayer = refundLeaf.refundAddresses[i];
|
|
636
634
|
const refundAmount = refundLeaf.refundAmounts[i];
|
|
637
|
-
if (executedTokenRefunds[relayer] === undefined) {
|
|
638
|
-
executedTokenRefunds[relayer] = bnZero;
|
|
635
|
+
if (executedTokenRefunds[relayer.toBytes32()] === undefined) {
|
|
636
|
+
executedTokenRefunds[relayer.toBytes32()] = bnZero;
|
|
639
637
|
}
|
|
640
|
-
executedTokenRefunds[relayer] = executedTokenRefunds[relayer].add(refundAmount);
|
|
638
|
+
executedTokenRefunds[relayer.toBytes32()] = executedTokenRefunds[relayer.toBytes32()].add(refundAmount);
|
|
641
639
|
}
|
|
642
640
|
}
|
|
643
641
|
return executedRefunds;
|
|
@@ -678,15 +676,15 @@ export class BundleDataClient {
|
|
|
678
676
|
return allRefunds;
|
|
679
677
|
}
|
|
680
678
|
|
|
681
|
-
getRefundsFor(bundleRefunds: CombinedRefunds, relayer:
|
|
682
|
-
if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token]) {
|
|
679
|
+
getRefundsFor(bundleRefunds: CombinedRefunds, relayer: Address, chainId: number, token: Address): BigNumber {
|
|
680
|
+
if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token.toBytes32()]) {
|
|
683
681
|
return BigNumber.from(0);
|
|
684
682
|
}
|
|
685
|
-
const allRefunds = bundleRefunds[chainId][token];
|
|
686
|
-
return allRefunds && allRefunds[relayer] ? allRefunds[relayer] : BigNumber.from(0);
|
|
683
|
+
const allRefunds = bundleRefunds[chainId][token.toBytes32()];
|
|
684
|
+
return allRefunds && allRefunds[relayer.toBytes32()] ? allRefunds[relayer.toBytes32()] : BigNumber.from(0);
|
|
687
685
|
}
|
|
688
686
|
|
|
689
|
-
getTotalRefund(refunds: CombinedRefunds[], relayer:
|
|
687
|
+
getTotalRefund(refunds: CombinedRefunds[], relayer: Address, chainId: number, refundToken: Address): BigNumber {
|
|
690
688
|
return refunds.reduce((totalRefund, refunds) => {
|
|
691
689
|
return totalRefund.add(this.getRefundsFor(refunds, relayer, chainId, refundToken));
|
|
692
690
|
}, bnZero);
|
|
@@ -899,7 +897,11 @@ export class BundleDataClient {
|
|
|
899
897
|
"Not using correct bundle deposit hash key"
|
|
900
898
|
);
|
|
901
899
|
if (deposit.blockNumber >= originChainBlockRange[0]) {
|
|
902
|
-
if (
|
|
900
|
+
if (
|
|
901
|
+
bundleDepositsV3?.[originChainId]?.[deposit.inputToken.toBytes32()]?.find((d) =>
|
|
902
|
+
duplicateEvent(deposit, d)
|
|
903
|
+
)
|
|
904
|
+
) {
|
|
903
905
|
this.logger.debug({
|
|
904
906
|
at: "BundleDataClient#loadData",
|
|
905
907
|
message: "Duplicate deposit detected",
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
fixedPointAdjustment,
|
|
18
18
|
count2DDictionaryValues,
|
|
19
19
|
count3DDictionaryValues,
|
|
20
|
+
toAddressType,
|
|
20
21
|
} from "../../../utils";
|
|
21
22
|
import {
|
|
22
23
|
addLastRunningBalance,
|
|
@@ -65,10 +66,10 @@ export function getRefundsFromBundle(
|
|
|
65
66
|
Object.entries(depositsForChain).forEach(([l2TokenAddress, deposits]) => {
|
|
66
67
|
deposits.forEach((deposit) => {
|
|
67
68
|
if (combinedRefunds[originChainId][l2TokenAddress] === undefined) {
|
|
68
|
-
combinedRefunds[originChainId][l2TokenAddress] = { [deposit.depositor]: deposit.inputAmount };
|
|
69
|
+
combinedRefunds[originChainId][l2TokenAddress] = { [deposit.depositor.toBytes32()]: deposit.inputAmount };
|
|
69
70
|
} else {
|
|
70
|
-
const existingRefundAmount = combinedRefunds[originChainId][l2TokenAddress][deposit.depositor];
|
|
71
|
-
combinedRefunds[originChainId][l2TokenAddress][deposit.depositor] = deposit.inputAmount.add(
|
|
71
|
+
const existingRefundAmount = combinedRefunds[originChainId][l2TokenAddress][deposit.depositor.toBytes32()];
|
|
72
|
+
combinedRefunds[originChainId][l2TokenAddress][deposit.depositor.toBytes32()] = deposit.inputAmount.add(
|
|
72
73
|
existingRefundAmount ?? bnZero
|
|
73
74
|
);
|
|
74
75
|
}
|
|
@@ -153,19 +154,23 @@ export function _buildPoolRebalanceRoot(
|
|
|
153
154
|
// If the repayment token and repayment chain ID do not map to a PoolRebalanceRoute graph, then
|
|
154
155
|
// there are no relevant L1 running balances.
|
|
155
156
|
if (
|
|
156
|
-
!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(
|
|
157
|
+
!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(
|
|
158
|
+
toAddressType(l2TokenAddress, repaymentChainId),
|
|
159
|
+
repaymentChainId,
|
|
160
|
+
mainnetBundleEndBlock
|
|
161
|
+
)
|
|
157
162
|
) {
|
|
158
163
|
chainWithRefundsOnly.add(repaymentChainId);
|
|
159
164
|
return;
|
|
160
165
|
}
|
|
161
166
|
const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
|
|
162
|
-
l2TokenAddress,
|
|
167
|
+
toAddressType(l2TokenAddress, repaymentChainId),
|
|
163
168
|
repaymentChainId,
|
|
164
169
|
mainnetBundleEndBlock
|
|
165
170
|
);
|
|
166
171
|
|
|
167
|
-
updateRunningBalance(runningBalances, repaymentChainId, l1TokenCounterpart, totalRefundAmount);
|
|
168
|
-
updateRunningBalance(realizedLpFees, repaymentChainId, l1TokenCounterpart, totalRealizedLpFee);
|
|
172
|
+
updateRunningBalance(runningBalances, repaymentChainId, l1TokenCounterpart.toEvmAddress(), totalRefundAmount);
|
|
173
|
+
updateRunningBalance(realizedLpFees, repaymentChainId, l1TokenCounterpart.toEvmAddress(), totalRealizedLpFee);
|
|
169
174
|
}
|
|
170
175
|
);
|
|
171
176
|
});
|
|
@@ -182,12 +187,17 @@ export function _buildPoolRebalanceRoot(
|
|
|
182
187
|
Object.entries(depositsForChain).forEach(([outputToken, deposits]) => {
|
|
183
188
|
deposits.forEach((deposit) => {
|
|
184
189
|
const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
|
|
185
|
-
outputToken,
|
|
190
|
+
toAddressType(outputToken, destinationChainId),
|
|
186
191
|
destinationChainId,
|
|
187
192
|
mainnetBundleEndBlock
|
|
188
193
|
);
|
|
189
194
|
const lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(fixedPointAdjustment);
|
|
190
|
-
updateRunningBalance(
|
|
195
|
+
updateRunningBalance(
|
|
196
|
+
runningBalances,
|
|
197
|
+
destinationChainId,
|
|
198
|
+
l1TokenCounterpart.toEvmAddress(),
|
|
199
|
+
deposit.inputAmount.sub(lpFee)
|
|
200
|
+
);
|
|
191
201
|
// Slow fill LP fees are accounted for when the slow fill executes and a V3FilledRelay is emitted. i.e. when
|
|
192
202
|
// the slow fill execution is included in bundleFillsV3.
|
|
193
203
|
});
|
|
@@ -206,12 +216,17 @@ export function _buildPoolRebalanceRoot(
|
|
|
206
216
|
Object.entries(slowFilledDepositsForChain).forEach(([outputToken, slowFilledDeposits]) => {
|
|
207
217
|
slowFilledDeposits.forEach((deposit) => {
|
|
208
218
|
const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
|
|
209
|
-
outputToken,
|
|
219
|
+
toAddressType(outputToken, destinationChainId),
|
|
210
220
|
destinationChainId,
|
|
211
221
|
mainnetBundleEndBlock
|
|
212
222
|
);
|
|
213
223
|
const lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(fixedPointAdjustment);
|
|
214
|
-
updateRunningBalance(
|
|
224
|
+
updateRunningBalance(
|
|
225
|
+
runningBalances,
|
|
226
|
+
destinationChainId,
|
|
227
|
+
l1TokenCounterpart.toEvmAddress(),
|
|
228
|
+
lpFee.sub(deposit.inputAmount)
|
|
229
|
+
);
|
|
215
230
|
// Slow fills don't add to lpFees, only when the slow fill is executed and a V3FilledRelay is emitted, so
|
|
216
231
|
// we don't need to subtract it here. Moreover, the HubPoole expects bundleLpFees to be > 0.
|
|
217
232
|
});
|
|
@@ -271,11 +286,11 @@ export function _buildPoolRebalanceRoot(
|
|
|
271
286
|
return;
|
|
272
287
|
}
|
|
273
288
|
const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
|
|
274
|
-
inputToken,
|
|
289
|
+
toAddressType(inputToken, originChainId),
|
|
275
290
|
originChainId,
|
|
276
291
|
mainnetBundleEndBlock
|
|
277
292
|
);
|
|
278
|
-
updateRunningBalance(runningBalances, originChainId, l1TokenCounterpart, deposit.inputAmount);
|
|
293
|
+
updateRunningBalance(runningBalances, originChainId, l1TokenCounterpart.toEvmAddress(), deposit.inputAmount);
|
|
279
294
|
});
|
|
280
295
|
});
|
|
281
296
|
});
|
|
@@ -2,7 +2,7 @@ import _ from "lodash";
|
|
|
2
2
|
import assert from "assert";
|
|
3
3
|
import { providers } from "ethers";
|
|
4
4
|
import { DepositWithBlock, Fill, FillWithBlock } from "../../../interfaces";
|
|
5
|
-
import { isSlowFill, isValidEvmAddress, isDefined, chainIsEvm } from "../../../utils";
|
|
5
|
+
import { isSlowFill, isValidEvmAddress, isDefined, chainIsEvm, Address, toAddressType } from "../../../utils";
|
|
6
6
|
import { HubPoolClient } from "../../HubPoolClient";
|
|
7
7
|
import { SVMProvider } from "../../../arch/svm";
|
|
8
8
|
|
|
@@ -25,7 +25,7 @@ export function getRefundInformationFromFill(
|
|
|
25
25
|
bundleEndBlockForMainnet: number
|
|
26
26
|
): {
|
|
27
27
|
chainToSendRefundTo: number;
|
|
28
|
-
repaymentToken:
|
|
28
|
+
repaymentToken: Address;
|
|
29
29
|
} {
|
|
30
30
|
const chainToSendRefundTo = _getRepaymentChainId(relayData, hubPoolClient, bundleEndBlockForMainnet);
|
|
31
31
|
if (chainToSendRefundTo === relayData.originChainId) {
|
|
@@ -49,6 +49,7 @@ export function getRefundInformationFromFill(
|
|
|
49
49
|
chainToSendRefundTo,
|
|
50
50
|
bundleEndBlockForMainnet
|
|
51
51
|
);
|
|
52
|
+
|
|
52
53
|
return {
|
|
53
54
|
chainToSendRefundTo,
|
|
54
55
|
repaymentToken,
|
|
@@ -125,7 +126,8 @@ export async function verifyFillRepayment(
|
|
|
125
126
|
return undefined;
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
|
-
fill.relayer = destinationRelayer;
|
|
129
|
+
fill.relayer = toAddressType(destinationRelayer);
|
|
130
|
+
assert(fill.relayer.isValidEvmAddress(), `Cannot re-assign fill to msg.sender: ${destinationRelayer}`);
|
|
129
131
|
} else {
|
|
130
132
|
return undefined;
|
|
131
133
|
}
|
|
@@ -200,5 +202,5 @@ function _repaymentAddressNeedsToBeOverwritten(fill: Fill): boolean {
|
|
|
200
202
|
// - i.e. If chainIsSvm && !isValidSvmAddress(fill.relayer) then return false
|
|
201
203
|
// If chainIsEvm && !isValidEvmAddress(fill.relayer) then return false
|
|
202
204
|
// If chainIsEvm && isValidEvmAddress(fill.relayer) then return true
|
|
203
|
-
return
|
|
205
|
+
return chainIsEvm(fill.repaymentChainId) && !fill.relayer.isValidEvmAddress();
|
|
204
206
|
}
|
|
@@ -21,6 +21,12 @@ export function buildPoolRebalanceLeafTree(poolRebalanceLeaves: PoolRebalanceLea
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const paramType = getParamType("MerkleLibTest", "verifyPoolRebalance", "rebalance");
|
|
24
|
-
const hashFn = (input: PoolRebalanceLeaf) =>
|
|
24
|
+
const hashFn = (input: PoolRebalanceLeaf) => {
|
|
25
|
+
const ethersLeaf = {
|
|
26
|
+
...input,
|
|
27
|
+
l1Tokens: input.l1Tokens.map((l1Token) => l1Token.toEvmAddress()),
|
|
28
|
+
};
|
|
29
|
+
return utils.keccak256(utils.defaultAbiCoder.encode([paramType], [ethersLeaf]));
|
|
30
|
+
};
|
|
25
31
|
return new MerkleTree<PoolRebalanceLeaf>(poolRebalanceLeaves, hashFn);
|
|
26
32
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MerkleTree } from "@across-protocol/contracts/dist/utils/MerkleTree";
|
|
2
2
|
import { RunningBalances, PoolRebalanceLeaf, Clients, SpokePoolTargetBalance } from "../../../interfaces";
|
|
3
3
|
import { SpokePoolClient } from "../../SpokePoolClient";
|
|
4
|
-
import { BigNumber, bnZero, compareAddresses } from "../../../utils";
|
|
4
|
+
import { BigNumber, bnZero, compareAddresses, EvmAddress } from "../../../utils";
|
|
5
5
|
import { HubPoolClient } from "../../HubPoolClient";
|
|
6
6
|
import { V3DepositWithBlock } from "./shims";
|
|
7
7
|
import { AcrossConfigStoreClient } from "../../AcrossConfigStoreClient";
|
|
@@ -151,7 +151,7 @@ export function addLastRunningBalance(
|
|
|
151
151
|
const { runningBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
|
|
152
152
|
latestMainnetBlock,
|
|
153
153
|
Number(repaymentChainId),
|
|
154
|
-
l1TokenAddress
|
|
154
|
+
EvmAddress.from(l1TokenAddress)
|
|
155
155
|
);
|
|
156
156
|
if (!runningBalance.eq(bnZero)) {
|
|
157
157
|
updateRunningBalance(runningBalances, Number(repaymentChainId), l1TokenAddress, runningBalance);
|
|
@@ -172,7 +172,7 @@ export function updateRunningBalanceForDeposit(
|
|
|
172
172
|
deposit.originChainId,
|
|
173
173
|
mainnetBundleEndBlock
|
|
174
174
|
);
|
|
175
|
-
updateRunningBalance(runningBalances, deposit.originChainId, l1TokenCounterpart, updateAmount);
|
|
175
|
+
updateRunningBalance(runningBalances, deposit.originChainId, l1TokenCounterpart.toEvmAddress(), updateAmount);
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
export function constructPoolRebalanceLeaves(
|
|
@@ -253,7 +253,7 @@ export function constructPoolRebalanceLeaves(
|
|
|
253
253
|
runningBalances: leafRunningBalances,
|
|
254
254
|
groupIndex: groupIndexForChainId++,
|
|
255
255
|
leafId: leaves.length,
|
|
256
|
-
l1Tokens: l1TokensToIncludeInThisLeaf,
|
|
256
|
+
l1Tokens: l1TokensToIncludeInThisLeaf.map((l1TokenAddr: string) => EvmAddress.from(l1TokenAddr)),
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
259
|
});
|