@across-protocol/sdk 4.2.7 → 4.2.9-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/arch/evm/SpokeUtils.d.ts +2 -2
- package/dist/cjs/arch/evm/SpokeUtils.js +18 -3
- package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/SpokeUtils.js +7 -7
- 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 +2 -2
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +57 -53
- 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/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 +20 -20
- package/dist/cjs/clients/HubPoolClient.js +78 -57
- 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 +35 -29
- 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 +40 -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 +18 -13
- 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 +3 -3
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +10 -10
- 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 +7 -4
- package/dist/cjs/utils/AddressUtils.js +21 -8
- 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 +2 -2
- package/dist/esm/arch/evm/SpokeUtils.js +19 -4
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.js +8 -8
- 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 +2 -2
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +58 -54
- 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/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 +22 -21
- package/dist/esm/clients/HubPoolClient.js +91 -61
- 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 +37 -30
- 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 +44 -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 +18 -13
- 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 +3 -3
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +10 -10
- 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 -4
- package/dist/esm/utils/AddressUtils.js +25 -10
- 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 +4 -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 +2 -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 +2 -2
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +22 -21
- 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 +18 -13
- 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 +3 -3
- 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 -4
- 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 +4 -16
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/arch/evm/SpokeUtils.ts +22 -8
- package/src/arch/svm/SpokeUtils.ts +7 -8
- package/src/arch/svm/utils.ts +3 -3
- package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
- package/src/clients/BundleDataClient/BundleDataClient.ts +49 -47
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +28 -13
- package/src/clients/BundleDataClient/utils/FillUtils.ts +6 -4
- package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
- package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +13 -9
- package/src/clients/HubPoolClient.ts +113 -79
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +7 -1
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +104 -37
- package/src/clients/mocks/MockHubPoolClient.ts +24 -19
- package/src/clients/mocks/MockSpokePoolClient.ts +53 -74
- package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
- package/src/interfaces/HubPool.ts +22 -13
- package/src/interfaces/SpokePool.ts +14 -17
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +10 -8
- package/src/relayFeeCalculator/chain-queries/svmQuery.ts +10 -10
- package/src/relayFeeCalculator/relayFeeCalculator.ts +11 -9
- package/src/utils/AddressUtils.ts +32 -14
- package/src/utils/SpokeUtils.ts +11 -33
- package/src/utils/TokenUtils.ts +7 -7
|
@@ -2,7 +2,15 @@ import winston from "winston";
|
|
|
2
2
|
import { SvmSpokeClient } from "@across-protocol/contracts";
|
|
3
3
|
import { Address } from "@solana/kit";
|
|
4
4
|
import { DepositWithBlock, RelayerRefundExecution, SortableEvent, SlowFillLeaf, Log } from "../../interfaces";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getCurrentTime,
|
|
7
|
+
bnZero,
|
|
8
|
+
MakeOptional,
|
|
9
|
+
EventSearchConfig,
|
|
10
|
+
Address as SDKAddress,
|
|
11
|
+
toAddressType,
|
|
12
|
+
isDefined,
|
|
13
|
+
} from "../../utils";
|
|
6
14
|
import { SpokePoolUpdate, SVMSpokePoolClient } from "../SpokePoolClient";
|
|
7
15
|
import { HubPoolClient } from "../HubPoolClient";
|
|
8
16
|
import { EventOverrides } from "./MockEvents";
|
|
@@ -46,8 +54,9 @@ export class MockSvmSpokePoolClient extends SVMSpokePoolClient {
|
|
|
46
54
|
this.destinationTokenForChainOverride[chainId] = token;
|
|
47
55
|
}
|
|
48
56
|
|
|
49
|
-
getDestinationTokenForDeposit(deposit: DepositWithBlock):
|
|
50
|
-
|
|
57
|
+
getDestinationTokenForDeposit(deposit: DepositWithBlock): SDKAddress {
|
|
58
|
+
const override = this.destinationTokenForChainOverride[deposit.originChainId];
|
|
59
|
+
return isDefined(override) ? toAddressType(override) : super.getDestinationTokenForDeposit(deposit);
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
setLatestBlockNumber(blockNumber: number): void {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BigNumber } from "../utils";
|
|
1
|
+
import { Address, BigNumber, EvmAddress } from "../utils";
|
|
2
2
|
import { SortableEvent } from "./Common";
|
|
3
3
|
|
|
4
4
|
export interface PoolRebalanceLeaf {
|
|
@@ -8,7 +8,7 @@ export interface PoolRebalanceLeaf {
|
|
|
8
8
|
netSendAmounts: BigNumber[];
|
|
9
9
|
runningBalances: BigNumber[];
|
|
10
10
|
leafId: number;
|
|
11
|
-
l1Tokens:
|
|
11
|
+
l1Tokens: EvmAddress[];
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export interface RelayerRefundLeaf {
|
|
@@ -16,8 +16,8 @@ export interface RelayerRefundLeaf {
|
|
|
16
16
|
chainId: number;
|
|
17
17
|
refundAmounts: BigNumber[];
|
|
18
18
|
leafId: number;
|
|
19
|
-
l2TokenAddress:
|
|
20
|
-
refundAddresses:
|
|
19
|
+
l2TokenAddress: Address;
|
|
20
|
+
refundAddresses: Address[];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface ProposedRootBundle extends SortableEvent {
|
|
@@ -55,7 +55,7 @@ export interface ExecutedRootBundle extends SortableEvent {
|
|
|
55
55
|
netSendAmounts: BigNumber[];
|
|
56
56
|
runningBalances: BigNumber[];
|
|
57
57
|
leafId: number;
|
|
58
|
-
l1Tokens:
|
|
58
|
+
l1Tokens: EvmAddress[];
|
|
59
59
|
proof: string[];
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -76,8 +76,14 @@ export interface RelayerRefundLeafWithGroup extends RelayerRefundLeaf {
|
|
|
76
76
|
groupIndex: number;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export interface
|
|
80
|
-
address:
|
|
79
|
+
export interface L1TokenInfo {
|
|
80
|
+
address: EvmAddress;
|
|
81
|
+
symbol: string;
|
|
82
|
+
decimals: number;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface TokenInfo {
|
|
86
|
+
address: Address;
|
|
81
87
|
symbol: string;
|
|
82
88
|
decimals: number;
|
|
83
89
|
}
|
|
@@ -87,27 +93,30 @@ export interface LpToken {
|
|
|
87
93
|
liquidReserves: BigNumber;
|
|
88
94
|
}
|
|
89
95
|
|
|
96
|
+
// TODO: I think I don't change string -> Address in the Events. I change right after the event is read
|
|
90
97
|
export interface CrossChainContractsSet extends SortableEvent {
|
|
91
98
|
l2ChainId: number;
|
|
92
|
-
spokePool:
|
|
99
|
+
spokePool: Address;
|
|
93
100
|
}
|
|
94
101
|
|
|
102
|
+
// TODO: I think I don't change string -> Address in the Events. I change right after the event is read
|
|
95
103
|
export interface DestinationTokenWithBlock extends SortableEvent {
|
|
96
|
-
l2Token:
|
|
97
|
-
l1Token:
|
|
104
|
+
l2Token: Address;
|
|
105
|
+
l1Token: EvmAddress;
|
|
98
106
|
}
|
|
99
107
|
|
|
108
|
+
// TODO: I think I don't change string -> Address in the Events. I change right after the event is read
|
|
100
109
|
export interface SetPoolRebalanceRoot extends SortableEvent {
|
|
101
110
|
destinationChainId: number;
|
|
102
|
-
l1Token:
|
|
103
|
-
destinationToken:
|
|
111
|
+
l1Token: EvmAddress;
|
|
112
|
+
destinationToken: Address;
|
|
104
113
|
}
|
|
105
114
|
|
|
106
115
|
export interface PendingRootBundle {
|
|
107
116
|
poolRebalanceRoot: string;
|
|
108
117
|
relayerRefundRoot: string;
|
|
109
118
|
slowRelayRoot: string;
|
|
110
|
-
proposer:
|
|
119
|
+
proposer: EvmAddress;
|
|
111
120
|
unclaimedPoolRebalanceLeafCount: number;
|
|
112
121
|
challengePeriodEndTimestamp: number;
|
|
113
122
|
bundleEvaluationBlockNumbers: number[];
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { SortableEvent } from "./Common";
|
|
2
|
-
import { FilledV3RelayEvent, V3FundsDepositedEvent } from "../typechain";
|
|
3
2
|
import { SpokePoolClient } from "../clients";
|
|
4
|
-
import { BigNumber } from "../utils";
|
|
3
|
+
import { BigNumber, Address, EvmAddress } from "../utils";
|
|
5
4
|
import { RelayerRefundLeaf } from "./HubPool";
|
|
6
5
|
|
|
7
|
-
export type { FilledV3RelayEvent, V3FundsDepositedEvent };
|
|
8
|
-
|
|
9
6
|
export interface RelayData {
|
|
10
7
|
originChainId: number;
|
|
11
|
-
depositor:
|
|
12
|
-
recipient:
|
|
8
|
+
depositor: Address;
|
|
9
|
+
recipient: Address;
|
|
13
10
|
depositId: BigNumber;
|
|
14
|
-
inputToken:
|
|
11
|
+
inputToken: Address;
|
|
15
12
|
inputAmount: BigNumber;
|
|
16
|
-
outputToken:
|
|
13
|
+
outputToken: Address;
|
|
17
14
|
outputAmount: BigNumber;
|
|
18
15
|
message: string;
|
|
19
16
|
fillDeadline: number;
|
|
20
|
-
exclusiveRelayer:
|
|
17
|
+
exclusiveRelayer: Address;
|
|
21
18
|
exclusivityDeadline: number;
|
|
22
19
|
}
|
|
23
20
|
|
|
@@ -26,7 +23,7 @@ export interface Deposit extends RelayData {
|
|
|
26
23
|
destinationChainId: number;
|
|
27
24
|
quoteTimestamp: number;
|
|
28
25
|
speedUpSignature?: string;
|
|
29
|
-
updatedRecipient?:
|
|
26
|
+
updatedRecipient?: Address;
|
|
30
27
|
updatedOutputAmount?: BigNumber;
|
|
31
28
|
updatedMessage?: string;
|
|
32
29
|
fromLiteChain: boolean;
|
|
@@ -54,7 +51,7 @@ export enum FillType {
|
|
|
54
51
|
}
|
|
55
52
|
|
|
56
53
|
export interface RelayExecutionEventInfo {
|
|
57
|
-
updatedRecipient:
|
|
54
|
+
updatedRecipient: Address;
|
|
58
55
|
updatedOutputAmount: BigNumber;
|
|
59
56
|
updatedMessage?: string;
|
|
60
57
|
updatedMessageHash: string;
|
|
@@ -64,7 +61,7 @@ export interface RelayExecutionEventInfo {
|
|
|
64
61
|
export interface Fill extends Omit<RelayData, "message"> {
|
|
65
62
|
messageHash: string;
|
|
66
63
|
destinationChainId: number;
|
|
67
|
-
relayer:
|
|
64
|
+
relayer: Address;
|
|
68
65
|
repaymentChainId: number;
|
|
69
66
|
relayExecutionInfo: RelayExecutionEventInfo;
|
|
70
67
|
}
|
|
@@ -75,25 +72,25 @@ export interface FillWithTime extends Fill, SortableEvent {
|
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
export interface EnabledDepositRoute {
|
|
78
|
-
originToken:
|
|
75
|
+
originToken: Address;
|
|
79
76
|
destinationChainId: number;
|
|
80
77
|
enabled: boolean;
|
|
81
78
|
}
|
|
82
79
|
|
|
83
80
|
export interface EnabledDepositRouteWithBlock extends EnabledDepositRoute, SortableEvent {}
|
|
84
81
|
export interface SpeedUp {
|
|
85
|
-
depositor:
|
|
82
|
+
depositor: EvmAddress;
|
|
86
83
|
depositorSignature: string;
|
|
87
84
|
depositId: BigNumber;
|
|
88
85
|
originChainId: number;
|
|
89
|
-
updatedRecipient:
|
|
86
|
+
updatedRecipient: Address;
|
|
90
87
|
updatedOutputAmount: BigNumber;
|
|
91
88
|
updatedMessage: string;
|
|
92
89
|
}
|
|
93
90
|
|
|
94
91
|
export interface SpeedUpWithBlock extends SpeedUp, SortableEvent {}
|
|
95
92
|
|
|
96
|
-
export interface SlowFillRequest extends RelayData {
|
|
93
|
+
export interface SlowFillRequest extends Omit<RelayData, "message"> {
|
|
97
94
|
messageHash: string;
|
|
98
95
|
destinationChainId: number;
|
|
99
96
|
}
|
|
@@ -133,7 +130,7 @@ export interface TokensBridged extends SortableEvent {
|
|
|
133
130
|
amountToReturn: BigNumber;
|
|
134
131
|
chainId: number;
|
|
135
132
|
leafId: number;
|
|
136
|
-
l2TokenAddress:
|
|
133
|
+
l2TokenAddress: Address;
|
|
137
134
|
}
|
|
138
135
|
|
|
139
136
|
export interface SpokePoolClientsByChain {
|
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
bnZero,
|
|
16
16
|
chainIsOPStack,
|
|
17
17
|
fixedPointAdjustment,
|
|
18
|
+
toAddressType,
|
|
19
|
+
Address,
|
|
18
20
|
} from "../../utils";
|
|
19
21
|
import assert from "assert";
|
|
20
22
|
import { Logger, QueryInterface, getDefaultSimulatedRelayerAddress } from "../relayFeeCalculator";
|
|
@@ -72,7 +74,7 @@ export class QueryBase implements QueryInterface {
|
|
|
72
74
|
*/
|
|
73
75
|
async getGasCosts(
|
|
74
76
|
deposit: Omit<Deposit, "messageHash">,
|
|
75
|
-
relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
77
|
+
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId)),
|
|
76
78
|
options: Partial<{
|
|
77
79
|
gasPrice: BigNumberish;
|
|
78
80
|
gasUnits: BigNumberish;
|
|
@@ -122,7 +124,7 @@ export class QueryBase implements QueryInterface {
|
|
|
122
124
|
*/
|
|
123
125
|
getUnsignedTxFromDeposit(
|
|
124
126
|
deposit: Omit<Deposit, "messageHash">,
|
|
125
|
-
relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
|
|
127
|
+
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId))
|
|
126
128
|
): Promise<PopulatedTransaction> {
|
|
127
129
|
return populateV3Relay(this.spokePool, deposit, relayer);
|
|
128
130
|
}
|
|
@@ -135,10 +137,10 @@ export class QueryBase implements QueryInterface {
|
|
|
135
137
|
*/
|
|
136
138
|
async getNativeGasCost(
|
|
137
139
|
deposit: Omit<Deposit, "messageHash">,
|
|
138
|
-
relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
|
|
140
|
+
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId))
|
|
139
141
|
): Promise<BigNumber> {
|
|
140
142
|
const unsignedTx = await this.getUnsignedTxFromDeposit(deposit, relayer);
|
|
141
|
-
const voidSigner = new VoidSigner(relayer, this.provider);
|
|
143
|
+
const voidSigner = new VoidSigner(relayer.toEvmAddress(), this.provider);
|
|
142
144
|
return voidSigner.estimateGas(unsignedTx);
|
|
143
145
|
}
|
|
144
146
|
|
|
@@ -152,7 +154,7 @@ export class QueryBase implements QueryInterface {
|
|
|
152
154
|
*/
|
|
153
155
|
async getOpStackL1DataFee(
|
|
154
156
|
unsignedTx: PopulatedTransaction,
|
|
155
|
-
relayer = getDefaultSimulatedRelayerAddress(unsignedTx.chainId),
|
|
157
|
+
relayer = toAddressType(getDefaultSimulatedRelayerAddress(unsignedTx.chainId)),
|
|
156
158
|
options: Partial<{
|
|
157
159
|
opStackL2GasUnits: BigNumberish;
|
|
158
160
|
opStackL1DataFeeMultiplier: BigNumber;
|
|
@@ -161,7 +163,7 @@ export class QueryBase implements QueryInterface {
|
|
|
161
163
|
const { opStackL2GasUnits, opStackL1DataFeeMultiplier = toBNWei("1") } = options || {};
|
|
162
164
|
const { chainId } = await this.provider.getNetwork();
|
|
163
165
|
assert(isOptimismL2Provider(this.provider), `Unexpected provider for chain ID ${chainId}.`);
|
|
164
|
-
const voidSigner = new VoidSigner(relayer, this.provider);
|
|
166
|
+
const voidSigner = new VoidSigner(relayer.toEvmAddress(), this.provider);
|
|
165
167
|
const populatedTransaction = await voidSigner.populateTransaction({
|
|
166
168
|
...unsignedTx,
|
|
167
169
|
gasLimit: opStackL2GasUnits, // prevents additional gas estimation call
|
|
@@ -183,7 +185,7 @@ export class QueryBase implements QueryInterface {
|
|
|
183
185
|
*/
|
|
184
186
|
async estimateGas(
|
|
185
187
|
unsignedTx: PopulatedTransaction,
|
|
186
|
-
senderAddress:
|
|
188
|
+
senderAddress: Address,
|
|
187
189
|
provider: providers.Provider | L2Provider<providers.Provider>,
|
|
188
190
|
options: Partial<{
|
|
189
191
|
gasPrice: BigNumberish;
|
|
@@ -204,7 +206,7 @@ export class QueryBase implements QueryInterface {
|
|
|
204
206
|
} = options || {};
|
|
205
207
|
|
|
206
208
|
const { chainId } = await provider.getNetwork();
|
|
207
|
-
const voidSigner = new VoidSigner(senderAddress, provider);
|
|
209
|
+
const voidSigner = new VoidSigner(senderAddress.toEvmAddress(), provider);
|
|
208
210
|
|
|
209
211
|
// Estimate the Gas units required to submit this transaction.
|
|
210
212
|
const queries = [
|
|
@@ -79,7 +79,7 @@ export class SvmQuery implements QueryInterface {
|
|
|
79
79
|
*/
|
|
80
80
|
async getGasCosts(
|
|
81
81
|
deposit: Omit<Deposit, "messageHash">,
|
|
82
|
-
_relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
82
|
+
_relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId)),
|
|
83
83
|
options: Partial<{
|
|
84
84
|
gasPrice: BigNumberish;
|
|
85
85
|
gasUnits: BigNumberish;
|
|
@@ -87,9 +87,9 @@ export class SvmQuery implements QueryInterface {
|
|
|
87
87
|
priorityFeeMultiplier: BigNumber;
|
|
88
88
|
}> = {}
|
|
89
89
|
): Promise<TransactionCostEstimate> {
|
|
90
|
-
const relayer = _relayer ?
|
|
90
|
+
const relayer = _relayer ? _relayer.forceSvmAddress() : this.simulatedRelayerAddress;
|
|
91
91
|
|
|
92
|
-
const fillRelayTx = await this.getFillRelayTx(deposit, relayer
|
|
92
|
+
const fillRelayTx = await this.getFillRelayTx(deposit, relayer);
|
|
93
93
|
|
|
94
94
|
const [computeUnitsConsumed, _gasPriceEstimate] = await Promise.all([
|
|
95
95
|
toBN(await this.computeUnitEstimator(fillRelayTx)),
|
|
@@ -122,7 +122,7 @@ export class SvmQuery implements QueryInterface {
|
|
|
122
122
|
*/
|
|
123
123
|
async getNativeGasCost(
|
|
124
124
|
deposit: Omit<Deposit, "messageHash">,
|
|
125
|
-
_relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
|
|
125
|
+
_relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId))
|
|
126
126
|
): Promise<BigNumber> {
|
|
127
127
|
const fillRelayTx = await this.getFillRelayTx(deposit, _relayer);
|
|
128
128
|
const computeUnitsConsumed = toBN(await this.computeUnitEstimator(fillRelayTx));
|
|
@@ -137,12 +137,12 @@ export class SvmQuery implements QueryInterface {
|
|
|
137
137
|
*/
|
|
138
138
|
async getFillRelayTx(
|
|
139
139
|
deposit: Omit<Deposit, "messageHash">,
|
|
140
|
-
_relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
|
|
140
|
+
_relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId))
|
|
141
141
|
) {
|
|
142
|
-
const relayer = _relayer ?
|
|
142
|
+
const relayer = isDefined(_relayer) ? _relayer : this.simulatedRelayerAddress;
|
|
143
143
|
// If the user did not have a token account created on destination, then we need to include this as a gas cost.
|
|
144
|
-
const mint =
|
|
145
|
-
const owner =
|
|
144
|
+
const mint = deposit.outputToken.forceSvmAddress();
|
|
145
|
+
const owner = deposit.recipient.forceSvmAddress();
|
|
146
146
|
const associatedToken = await getAssociatedTokenAddress(owner, mint);
|
|
147
147
|
const simulatedSigner = SolanaVoidSigner(relayer.toBase58());
|
|
148
148
|
|
|
@@ -174,7 +174,7 @@ export class SvmQuery implements QueryInterface {
|
|
|
174
174
|
const [createTokenAccountsIx, approveIx, fillIx] = await Promise.all([
|
|
175
175
|
createTokenAccountsInstruction(mint, simulatedSigner),
|
|
176
176
|
createApproveInstruction(
|
|
177
|
-
mint,
|
|
177
|
+
mint.forceSvmAddress(),
|
|
178
178
|
deposit.outputAmount,
|
|
179
179
|
this.simulatedRelayerAddress,
|
|
180
180
|
this.spokePoolAddress,
|
|
@@ -187,7 +187,7 @@ export class SvmQuery implements QueryInterface {
|
|
|
187
187
|
const recentBlockhash = await this.provider.getLatestBlockhash().send();
|
|
188
188
|
const fillRelayTx = pipe(
|
|
189
189
|
createTransactionMessage({ version: 0 }),
|
|
190
|
-
(tx) => setTransactionMessageFeePayer(relayer.toV2Address(), tx),
|
|
190
|
+
(tx) => setTransactionMessageFeePayer(relayer.forceSvmAddress().toV2Address(), tx),
|
|
191
191
|
(tx) => setTransactionMessageLifetimeUsingBlockhash(recentBlockhash.value, tx),
|
|
192
192
|
(tx) =>
|
|
193
193
|
isDefined(recipientCreateTokenAccountInstructions)
|
|
@@ -24,6 +24,8 @@ import {
|
|
|
24
24
|
compareAddressesSimple,
|
|
25
25
|
ConvertDecimals,
|
|
26
26
|
chainIsSvm,
|
|
27
|
+
toAddressType,
|
|
28
|
+
Address,
|
|
27
29
|
} from "../utils";
|
|
28
30
|
import { Transport } from "viem";
|
|
29
31
|
|
|
@@ -31,7 +33,7 @@ import { Transport } from "viem";
|
|
|
31
33
|
export interface QueryInterface {
|
|
32
34
|
getGasCosts: (
|
|
33
35
|
deposit: Omit<Deposit, "messageHash">,
|
|
34
|
-
relayer:
|
|
36
|
+
relayer: Address,
|
|
35
37
|
options?: Partial<{
|
|
36
38
|
gasPrice: BigNumberish;
|
|
37
39
|
gasUnits: BigNumberish;
|
|
@@ -42,7 +44,7 @@ export interface QueryInterface {
|
|
|
42
44
|
}>
|
|
43
45
|
) => Promise<TransactionCostEstimate>;
|
|
44
46
|
getTokenPrice: (tokenSymbol: string) => Promise<number>;
|
|
45
|
-
getNativeGasCost: (deposit: Omit<Deposit, "messageHash">, relayer:
|
|
47
|
+
getNativeGasCost: (deposit: Omit<Deposit, "messageHash">, relayer: Address) => Promise<BigNumber>;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
export const expectedCapitalCostsKeys = ["lowerBound", "upperBound", "cutoff", "decimals"];
|
|
@@ -254,7 +256,7 @@ export class RelayFeeCalculator {
|
|
|
254
256
|
deposit: Deposit,
|
|
255
257
|
outputAmount: BigNumberish,
|
|
256
258
|
simulateZeroFill = false,
|
|
257
|
-
relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
259
|
+
relayerAddress = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId)),
|
|
258
260
|
_tokenPrice?: number,
|
|
259
261
|
tokenMapping = TOKEN_SYMBOLS_MAP,
|
|
260
262
|
gasPrice?: BigNumberish,
|
|
@@ -271,14 +273,14 @@ export class RelayFeeCalculator {
|
|
|
271
273
|
// undefined address on destination.
|
|
272
274
|
const destinationChainTokenDetails = Object.values(tokenMapping).find(
|
|
273
275
|
(details) =>
|
|
274
|
-
compareAddressesSimple(details.addresses[originChainId], inputToken) &&
|
|
276
|
+
compareAddressesSimple(details.addresses[originChainId], inputToken.toAddress()) &&
|
|
275
277
|
isDefined(details.addresses[destinationChainId])
|
|
276
278
|
);
|
|
277
279
|
const outputToken = isZeroAddress(deposit.outputToken)
|
|
278
280
|
? destinationChainTokenDetails!.addresses[destinationChainId]
|
|
279
|
-
: deposit.outputToken;
|
|
281
|
+
: deposit.outputToken.toAddress();
|
|
280
282
|
const outputTokenInfo = getTokenInfo(outputToken, destinationChainId, tokenMapping);
|
|
281
|
-
const inputTokenInfo = getTokenInfo(inputToken, originChainId, tokenMapping);
|
|
283
|
+
const inputTokenInfo = getTokenInfo(inputToken.toAddress(), originChainId, tokenMapping);
|
|
282
284
|
if (!isDefined(outputTokenInfo) || !isDefined(inputTokenInfo)) {
|
|
283
285
|
throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
|
|
284
286
|
}
|
|
@@ -493,7 +495,7 @@ export class RelayFeeCalculator {
|
|
|
493
495
|
deposit: Deposit,
|
|
494
496
|
outputAmount?: BigNumberish,
|
|
495
497
|
simulateZeroFill = false,
|
|
496
|
-
relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
498
|
+
relayerAddress = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId)),
|
|
497
499
|
_tokenPrice?: number,
|
|
498
500
|
gasPrice?: BigNumberish,
|
|
499
501
|
gasUnits?: BigNumberish,
|
|
@@ -505,8 +507,8 @@ export class RelayFeeCalculator {
|
|
|
505
507
|
const { inputToken, originChainId, outputToken, destinationChainId } = deposit;
|
|
506
508
|
// We can perform a simple lookup with `getTokenInfo` here without resolving the exact token to resolve since we only need to
|
|
507
509
|
// resolve the L1 token symbol and not the L2 token decimals.
|
|
508
|
-
const inputTokenInfo = getTokenInfo(inputToken, originChainId);
|
|
509
|
-
const outputTokenInfo = getTokenInfo(outputToken, destinationChainId);
|
|
510
|
+
const inputTokenInfo = getTokenInfo(inputToken.toAddress(), originChainId);
|
|
511
|
+
const outputTokenInfo = getTokenInfo(outputToken.toAddress(), destinationChainId);
|
|
510
512
|
if (!isDefined(inputTokenInfo) || !isDefined(outputTokenInfo)) {
|
|
511
513
|
throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
|
|
512
514
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { providers, utils } from "ethers";
|
|
2
|
+
import assert from "assert";
|
|
2
3
|
import bs58 from "bs58";
|
|
3
4
|
import { Address as V2Address } from "@solana/kit";
|
|
4
5
|
import { BigNumber, chainIsEvm } from "./";
|
|
@@ -87,7 +88,9 @@ export function toAddressType(address: string): Address | EvmAddress | SvmAddres
|
|
|
87
88
|
} catch (e) {
|
|
88
89
|
// If we hit this block, then the validation for one of the child address classes failed. We still may want to keep this address in our state, so
|
|
89
90
|
// return an unchecked address type.
|
|
90
|
-
|
|
91
|
+
assert(utils.isHexString(address));
|
|
92
|
+
assert(utils.hexDataLength(address) === 32);
|
|
93
|
+
return Address.__unsafeConstruct(utils.arrayify(address));
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
|
|
@@ -113,12 +116,24 @@ export class Address {
|
|
|
113
116
|
this.rawAddress = utils.zeroPad(_rawAddress, 32);
|
|
114
117
|
}
|
|
115
118
|
|
|
119
|
+
static __unsafeConstruct(_rawAddress: Uint8Array): Address {
|
|
120
|
+
return new this(_rawAddress);
|
|
121
|
+
}
|
|
122
|
+
|
|
116
123
|
// Converts the address into a bytes32 string. Note that the output bytes will be lowercase so that it matches ethers event data. This function will never
|
|
117
124
|
// throw since address length validation was done at construction time.
|
|
118
125
|
toBytes32(): string {
|
|
119
126
|
return (this.bytes32Address ??= utils.hexZeroPad(utils.hexlify(this.rawAddress), 32).toLowerCase());
|
|
120
127
|
}
|
|
121
128
|
|
|
129
|
+
// Returns last 20 bytes of Address as a hex string. Truncates if necessary. This function is useful for comparing some longer addresses(e.g. Solana) to Solidity events
|
|
130
|
+
// that contain truncated `address` type as one of the fields
|
|
131
|
+
truncateToBytes20(): string {
|
|
132
|
+
// Take the last 20 bytes
|
|
133
|
+
const bytes20 = this.rawAddress.slice(-20);
|
|
134
|
+
return toAddress(utils.hexlify(bytes20));
|
|
135
|
+
}
|
|
136
|
+
|
|
122
137
|
// Converts the address (can be bytes32 or bytes20) to its base58 counterpart. This conversion will always succeed, even if the input address is not valid on Solana,
|
|
123
138
|
// as this address may be needed to represent an EVM address on Solana.
|
|
124
139
|
toBase58(): string {
|
|
@@ -160,7 +175,7 @@ export class Address {
|
|
|
160
175
|
// Checks if this address can be coerced into a bytes20 evm address. Returns true if it is possible and false otherwise.
|
|
161
176
|
isValidEvmAddress(): boolean {
|
|
162
177
|
try {
|
|
163
|
-
this.
|
|
178
|
+
this.toEvmAddress();
|
|
164
179
|
return true;
|
|
165
180
|
} catch {
|
|
166
181
|
return false;
|
|
@@ -191,6 +206,11 @@ export class Address {
|
|
|
191
206
|
return utils.stripZeros(this.rawAddress).length === 0;
|
|
192
207
|
}
|
|
193
208
|
|
|
209
|
+
// Small utility to convert an Address to a Solana Kit branded type.
|
|
210
|
+
toV2Address(): V2Address<string> {
|
|
211
|
+
return this.toBase58() as V2Address<string>;
|
|
212
|
+
}
|
|
213
|
+
|
|
194
214
|
// Forces `rawAddress` to become an SvmAddress type. This will only throw if `rawAddress.length > 32`.
|
|
195
215
|
forceSvmAddress(): SvmAddress {
|
|
196
216
|
return SvmAddress.from(this.toBase58());
|
|
@@ -220,12 +240,20 @@ export class Address {
|
|
|
220
240
|
return 0;
|
|
221
241
|
}
|
|
222
242
|
}
|
|
243
|
+
|
|
244
|
+
static isEvmAddress(address: Address): boolean {
|
|
245
|
+
return address instanceof EvmAddress;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
static isSvmAddress(address: Address): boolean {
|
|
249
|
+
return address instanceof SvmAddress;
|
|
250
|
+
}
|
|
223
251
|
}
|
|
224
252
|
|
|
225
253
|
// Subclass of address which strictly deals with 20-byte addresses. These addresses are guaranteed to be valid EVM addresses, so `toAddress` will always succeed.
|
|
226
254
|
export class EvmAddress extends Address {
|
|
227
255
|
// On construction, validate that the address can indeed be coerced into an EVM address. Throw immediately if it cannot.
|
|
228
|
-
constructor(rawAddress: Uint8Array) {
|
|
256
|
+
private constructor(rawAddress: Uint8Array) {
|
|
229
257
|
super(rawAddress);
|
|
230
258
|
const hexString = utils.hexlify(rawAddress);
|
|
231
259
|
if (!this.isValidEvmAddress()) {
|
|
@@ -259,7 +287,7 @@ export class EvmAddress extends Address {
|
|
|
259
287
|
// Subclass of address which strictly deals SVM addresses. These addresses are guaranteed to be valid SVM addresses, so `toBase58` will always produce a valid Solana address.
|
|
260
288
|
export class SvmAddress extends Address {
|
|
261
289
|
// On construction, validate that the address is a point on Curve25519. Throw immediately if it is not.
|
|
262
|
-
constructor(rawAddress: Uint8Array) {
|
|
290
|
+
private constructor(rawAddress: Uint8Array) {
|
|
263
291
|
super(rawAddress);
|
|
264
292
|
}
|
|
265
293
|
|
|
@@ -269,16 +297,6 @@ export class SvmAddress extends Address {
|
|
|
269
297
|
return this.toBase58();
|
|
270
298
|
}
|
|
271
299
|
|
|
272
|
-
// Small utility to convert an SvmAddress to a Solana Kit branded type.
|
|
273
|
-
toV2Address(): V2Address<string> {
|
|
274
|
-
return this.toBase58() as V2Address<string>;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// Forces an SvmAddress to an EVM address string by truncating the leading 12 bytes.
|
|
278
|
-
override toEvmAddress(): string {
|
|
279
|
-
return toAddress(`0x${this.toBytes32().slice(-40)}`);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
300
|
// Constructs a new SvmAddress type.
|
|
283
301
|
static from(address: string, encoding: "base58" | "base16" = "base58"): SvmAddress {
|
|
284
302
|
if (encoding === "base58") {
|
package/src/utils/SpokeUtils.ts
CHANGED
|
@@ -1,34 +1,12 @@
|
|
|
1
1
|
import { encodeAbiParameters, Hex, keccak256 } from "viem";
|
|
2
|
-
import { MAX_SAFE_DEPOSIT_ID,
|
|
3
|
-
import {
|
|
4
|
-
import { toBytes32 } from "./AddressUtils";
|
|
2
|
+
import { MAX_SAFE_DEPOSIT_ID, ZERO_BYTES } from "../constants";
|
|
3
|
+
import { RelayData } from "../interfaces";
|
|
5
4
|
import { BigNumber } from "./BigNumberUtils";
|
|
5
|
+
import { Address } from "./AddressUtils";
|
|
6
6
|
import { isMessageEmpty } from "./DepositUtils";
|
|
7
7
|
import { chainIsSvm } from "./NetworkUtils";
|
|
8
8
|
import { svm } from "../arch";
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Produce the RelayData for a Deposit.
|
|
12
|
-
* @param deposit Deposit instance.
|
|
13
|
-
* @returns The corresponding RelayData object.
|
|
14
|
-
*/
|
|
15
|
-
export function getDepositRelayData(deposit: Omit<Deposit, "messageHash">): RelayData {
|
|
16
|
-
return {
|
|
17
|
-
depositor: toBytes32(deposit.depositor),
|
|
18
|
-
recipient: toBytes32(deposit.recipient),
|
|
19
|
-
exclusiveRelayer: toBytes32(deposit.exclusiveRelayer),
|
|
20
|
-
inputToken: toBytes32(deposit.inputToken),
|
|
21
|
-
outputToken: toBytes32(deposit.outputToken),
|
|
22
|
-
inputAmount: deposit.inputAmount,
|
|
23
|
-
outputAmount: deposit.outputAmount,
|
|
24
|
-
originChainId: deposit.originChainId,
|
|
25
|
-
depositId: deposit.depositId,
|
|
26
|
-
fillDeadline: deposit.fillDeadline,
|
|
27
|
-
exclusivityDeadline: deposit.exclusivityDeadline,
|
|
28
|
-
message: deposit.message,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
10
|
/**
|
|
33
11
|
* Compute the RelayData hash for a fill. This can be used to determine the fill status.
|
|
34
12
|
* @param relayData RelayData information that is used to complete a fill.
|
|
@@ -59,14 +37,14 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId: numbe
|
|
|
59
37
|
|
|
60
38
|
const _relayData = {
|
|
61
39
|
...relayData,
|
|
62
|
-
depositor:
|
|
63
|
-
recipient:
|
|
64
|
-
inputToken:
|
|
65
|
-
outputToken:
|
|
66
|
-
exclusiveRelayer:
|
|
40
|
+
depositor: relayData.depositor.toBytes32(),
|
|
41
|
+
recipient: relayData.recipient.toBytes32(),
|
|
42
|
+
inputToken: relayData.inputToken.toBytes32(),
|
|
43
|
+
outputToken: relayData.outputToken.toBytes32(),
|
|
44
|
+
exclusiveRelayer: relayData.exclusiveRelayer.toBytes32(),
|
|
67
45
|
};
|
|
68
46
|
if (chainIsSvm(destinationChainId)) {
|
|
69
|
-
return svm.getRelayDataHash(
|
|
47
|
+
return svm.getRelayDataHash(relayData, destinationChainId);
|
|
70
48
|
}
|
|
71
49
|
return keccak256(encodeAbiParameters(abi, [_relayData, destinationChainId]));
|
|
72
50
|
}
|
|
@@ -86,8 +64,8 @@ export function isUnsafeDepositId(depositId: BigNumber): boolean {
|
|
|
86
64
|
}
|
|
87
65
|
|
|
88
66
|
// Determines if the input address (either a bytes32 or bytes20) is the zero address.
|
|
89
|
-
export function isZeroAddress(address:
|
|
90
|
-
return address ===
|
|
67
|
+
export function isZeroAddress(address: Address): boolean {
|
|
68
|
+
return address.toBytes32() === ZERO_BYTES;
|
|
91
69
|
}
|
|
92
70
|
|
|
93
71
|
export function getMessageHash(message: string): string {
|
package/src/utils/TokenUtils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BlockTag } from "@ethersproject/abstract-provider";
|
|
2
2
|
import { Contract, providers, Signer } from "ethers";
|
|
3
3
|
import * as constants from "../constants";
|
|
4
|
-
import {
|
|
4
|
+
import { TokenInfo } from "../interfaces";
|
|
5
5
|
import { ERC20__factory } from "../typechain";
|
|
6
6
|
import { BigNumber } from "./BigNumberUtils";
|
|
7
7
|
import { getNetworkName, chainIsL1, chainIsProd, chainIsSvm } from "./NetworkUtils";
|
|
@@ -11,10 +11,10 @@ const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
|
|
|
11
11
|
|
|
12
12
|
type SignerOrProvider = providers.Provider | Signer;
|
|
13
13
|
|
|
14
|
-
export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<
|
|
14
|
+
export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<TokenInfo> {
|
|
15
15
|
const token = new Contract(address, ERC20__factory.abi, signerOrProvider);
|
|
16
16
|
const [symbol, decimals] = await Promise.all([token.symbol(), token.decimals()]);
|
|
17
|
-
return { address, symbol, decimals };
|
|
17
|
+
return { address: toAddressType(address), symbol, decimals };
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export const getL2TokenAddresses = (
|
|
@@ -33,7 +33,7 @@ export const getL2TokenAddresses = (
|
|
|
33
33
|
* @param chainId Chain ID to query on.
|
|
34
34
|
* @returns Symbol, decimals and contract address on the requested chain.
|
|
35
35
|
*/
|
|
36
|
-
export function resolveSymbolOnChain(chainId: number, symbol: string):
|
|
36
|
+
export function resolveSymbolOnChain(chainId: number, symbol: string): TokenInfo {
|
|
37
37
|
// @dev Suppress tsc complaints by casting symbol to the expected type.
|
|
38
38
|
const token = TOKEN_SYMBOLS_MAP[symbol as keyof typeof TOKEN_SYMBOLS_MAP];
|
|
39
39
|
if (!isDefined(token) || !isDefined(token.addresses[chainId])) {
|
|
@@ -44,7 +44,7 @@ export function resolveSymbolOnChain(chainId: number, symbol: string): L1Token {
|
|
|
44
44
|
const { decimals, addresses } = token;
|
|
45
45
|
const address = addresses[chainId];
|
|
46
46
|
|
|
47
|
-
return { symbol, decimals, address };
|
|
47
|
+
return { symbol, decimals, address: toAddressType(address) };
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -111,7 +111,7 @@ export function isStablecoin(tokenSymbol: string): boolean {
|
|
|
111
111
|
* @param tokenMapping
|
|
112
112
|
* @returns
|
|
113
113
|
*/
|
|
114
|
-
export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP):
|
|
114
|
+
export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): TokenInfo {
|
|
115
115
|
const parsedAddress = chainIsSvm(chainId)
|
|
116
116
|
? toAddressType(l2TokenAddress).toBase58()
|
|
117
117
|
: toAddressType(l2TokenAddress).toEvmAddress();
|
|
@@ -128,7 +128,7 @@ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMappi
|
|
|
128
128
|
tokenObject = tokenMapping[l1TokenSymbol as keyof typeof tokenMapping];
|
|
129
129
|
}
|
|
130
130
|
return {
|
|
131
|
-
address: l2TokenAddress,
|
|
131
|
+
address: toAddressType(l2TokenAddress),
|
|
132
132
|
symbol: tokenObject.symbol,
|
|
133
133
|
decimals: tokenObject.decimals,
|
|
134
134
|
};
|