@across-protocol/sdk 4.2.15 → 4.2.16-alpha.2
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 +6 -2
- package/dist/cjs/arch/evm/SpokeUtils.js +21 -6
- package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/SpokeUtils.d.ts +6 -2
- package/dist/cjs/arch/svm/SpokeUtils.js +66 -67
- package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/utils.d.ts +3 -1
- package/dist/cjs/arch/svm/utils.js +20 -14
- package/dist/cjs/arch/svm/utils.js.map +1 -1
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +60 -56
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +13 -13
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +3 -2
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +3 -3
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +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 -58
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +64 -45
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +9 -9
- package/dist/cjs/clients/mocks/MockHubPoolClient.js +15 -9
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +5 -3
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +40 -36
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/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 +13 -13
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +10 -10
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +5 -5
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +41 -48
- 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 +12 -13
- package/dist/cjs/utils/AddressUtils.js +44 -46
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/EventUtils.js +1 -1
- package/dist/cjs/utils/EventUtils.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 +4 -6
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/esm/arch/evm/SpokeUtils.d.ts +6 -2
- package/dist/esm/arch/evm/SpokeUtils.js +22 -7
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.d.ts +6 -2
- package/dist/esm/arch/svm/SpokeUtils.js +70 -71
- package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/utils.d.ts +6 -1
- package/dist/esm/arch/svm/utils.js +21 -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 +5 -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 +97 -63
- 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 +67 -47
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +9 -9
- package/dist/esm/clients/mocks/MockHubPoolClient.js +16 -10
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +5 -3
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +42 -38
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/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 +13 -13
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +11 -11
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -6
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +43 -50
- 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 +13 -14
- package/dist/esm/utils/AddressUtils.js +50 -56
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/EventUtils.js +2 -2
- package/dist/esm/utils/EventUtils.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 +5 -7
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/types/arch/evm/SpokeUtils.d.ts +6 -2
- package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/SpokeUtils.d.ts +6 -2
- package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/svm/utils.d.ts +6 -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 +2 -2
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts +9 -9
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +5 -3
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/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 +13 -13
- 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 +6 -6
- 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 +13 -14
- 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 -2
- package/src/arch/evm/SpokeUtils.ts +52 -12
- package/src/arch/svm/SpokeUtils.ts +102 -51
- package/src/arch/svm/utils.ts +11 -4
- package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
- package/src/clients/BundleDataClient/BundleDataClient.ts +57 -53
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +28 -13
- package/src/clients/BundleDataClient/utils/FillUtils.ts +10 -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 +126 -82
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +6 -0
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +118 -35
- package/src/clients/mocks/MockHubPoolClient.ts +24 -19
- package/src/clients/mocks/MockSpokePoolClient.ts +39 -27
- package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
- package/src/interfaces/HubPool.ts +23 -14
- package/src/interfaces/SpokePool.ts +13 -13
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +14 -12
- package/src/relayFeeCalculator/chain-queries/svmQuery.ts +41 -44
- package/src/relayFeeCalculator/relayFeeCalculator.ts +20 -12
- package/src/utils/AddressUtils.ts +58 -60
- package/src/utils/EventUtils.ts +2 -2
- package/src/utils/SpokeUtils.ts +11 -33
- package/src/utils/TokenUtils.ts +10 -11
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { SortableEvent } from "./Common";
|
|
2
2
|
import { SpokePoolClient } from "../clients";
|
|
3
|
-
import { BigNumber } from "../utils";
|
|
3
|
+
import { BigNumber, Address, EvmAddress } from "../utils";
|
|
4
4
|
import { RelayerRefundLeaf } from "./HubPool";
|
|
5
5
|
|
|
6
6
|
export interface RelayData {
|
|
7
7
|
originChainId: number;
|
|
8
|
-
depositor:
|
|
9
|
-
recipient:
|
|
8
|
+
depositor: Address;
|
|
9
|
+
recipient: Address;
|
|
10
10
|
depositId: BigNumber;
|
|
11
|
-
inputToken:
|
|
11
|
+
inputToken: Address;
|
|
12
12
|
inputAmount: BigNumber;
|
|
13
|
-
outputToken:
|
|
13
|
+
outputToken: Address;
|
|
14
14
|
outputAmount: BigNumber;
|
|
15
15
|
message: string;
|
|
16
16
|
fillDeadline: number;
|
|
17
|
-
exclusiveRelayer:
|
|
17
|
+
exclusiveRelayer: Address;
|
|
18
18
|
exclusivityDeadline: number;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -23,7 +23,7 @@ export interface Deposit extends RelayData {
|
|
|
23
23
|
destinationChainId: number;
|
|
24
24
|
quoteTimestamp: number;
|
|
25
25
|
speedUpSignature?: string;
|
|
26
|
-
updatedRecipient?:
|
|
26
|
+
updatedRecipient?: Address;
|
|
27
27
|
updatedOutputAmount?: BigNumber;
|
|
28
28
|
updatedMessage?: string;
|
|
29
29
|
fromLiteChain: boolean;
|
|
@@ -51,7 +51,7 @@ export enum FillType {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export interface RelayExecutionEventInfo {
|
|
54
|
-
updatedRecipient:
|
|
54
|
+
updatedRecipient: Address;
|
|
55
55
|
updatedOutputAmount: BigNumber;
|
|
56
56
|
updatedMessage?: string;
|
|
57
57
|
updatedMessageHash: string;
|
|
@@ -61,7 +61,7 @@ export interface RelayExecutionEventInfo {
|
|
|
61
61
|
export interface Fill extends Omit<RelayData, "message"> {
|
|
62
62
|
messageHash: string;
|
|
63
63
|
destinationChainId: number;
|
|
64
|
-
relayer:
|
|
64
|
+
relayer: Address;
|
|
65
65
|
repaymentChainId: number;
|
|
66
66
|
relayExecutionInfo: RelayExecutionEventInfo;
|
|
67
67
|
}
|
|
@@ -72,18 +72,18 @@ export interface FillWithTime extends Fill, SortableEvent {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export interface EnabledDepositRoute {
|
|
75
|
-
originToken:
|
|
75
|
+
originToken: Address;
|
|
76
76
|
destinationChainId: number;
|
|
77
77
|
enabled: boolean;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export interface EnabledDepositRouteWithBlock extends EnabledDepositRoute, SortableEvent {}
|
|
81
81
|
export interface SpeedUp {
|
|
82
|
-
depositor:
|
|
82
|
+
depositor: EvmAddress;
|
|
83
83
|
depositorSignature: string;
|
|
84
84
|
depositId: BigNumber;
|
|
85
85
|
originChainId: number;
|
|
86
|
-
updatedRecipient:
|
|
86
|
+
updatedRecipient: Address;
|
|
87
87
|
updatedOutputAmount: BigNumber;
|
|
88
88
|
updatedMessage: string;
|
|
89
89
|
}
|
|
@@ -130,7 +130,7 @@ export interface TokensBridged extends SortableEvent {
|
|
|
130
130
|
amountToReturn: BigNumber;
|
|
131
131
|
chainId: number;
|
|
132
132
|
leafId: number;
|
|
133
|
-
l2TokenAddress:
|
|
133
|
+
l2TokenAddress: Address;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
export interface ClaimedRelayerRefundWithBlock extends SortableEvent {
|
|
@@ -15,11 +15,13 @@ 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";
|
|
21
23
|
import { Transport } from "viem";
|
|
22
|
-
import { getGasPriceEstimate
|
|
24
|
+
import { getGasPriceEstimate } from "../../gasPriceOracle";
|
|
23
25
|
import { EvmProvider } from "../../arch/evm/types";
|
|
24
26
|
|
|
25
27
|
export type SymbolMappingType = Record<
|
|
@@ -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), 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), 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), 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), CHAIN_IDs.MAINNET),
|
|
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 = [
|
|
@@ -213,9 +215,9 @@ export class QueryBase implements QueryInterface {
|
|
|
213
215
|
? Promise.resolve({ maxFeePerGas: _gasPrice })
|
|
214
216
|
: getGasPriceEstimate(provider, { chainId, baseFeeMultiplier, priorityFeeMultiplier, transport, unsignedTx }),
|
|
215
217
|
] as const;
|
|
216
|
-
const [nativeGasCost,
|
|
217
|
-
|
|
218
|
-
const gasPrice =
|
|
218
|
+
const [nativeGasCost, gasPriceEstimate] = await Promise.all(queries);
|
|
219
|
+
|
|
220
|
+
const gasPrice = gasPriceEstimate.maxFeePerGas;
|
|
219
221
|
assert(nativeGasCost.gt(bnZero), "Gas cost should not be 0");
|
|
220
222
|
let tokenGasCost: BigNumber;
|
|
221
223
|
|
|
@@ -12,10 +12,11 @@ import {
|
|
|
12
12
|
getFillRelayDelegatePda,
|
|
13
13
|
getFillStatusPda,
|
|
14
14
|
getStatePda,
|
|
15
|
+
toAddress,
|
|
15
16
|
} from "../../arch/svm";
|
|
16
17
|
import { Coingecko } from "../../coingecko";
|
|
17
18
|
import { CHAIN_IDs } from "../../constants";
|
|
18
|
-
import {
|
|
19
|
+
import { getGasPriceEstimate } from "../../gasPriceOracle";
|
|
19
20
|
import { Deposit } from "../../interfaces";
|
|
20
21
|
import {
|
|
21
22
|
BigNumber,
|
|
@@ -40,7 +41,7 @@ export class SvmQuery implements QueryInterface {
|
|
|
40
41
|
* Instantiates a SvmQuery instance
|
|
41
42
|
* @param provider A valid solana/kit rpc client.
|
|
42
43
|
* @param symbolMapping A mapping to valid ERC20 tokens and their respective characteristics
|
|
43
|
-
* @param
|
|
44
|
+
* @param spokePool The valid address of the Spoke Pool deployment
|
|
44
45
|
* @param simulatedRelayerAddress The address that these queries will reference as the sender. Note: This address must be approved for USDC
|
|
45
46
|
* @param logger A logging utility to report logs
|
|
46
47
|
* @param coingeckoProApiKey An optional CoinGecko API key that links to a PRO account
|
|
@@ -50,7 +51,7 @@ export class SvmQuery implements QueryInterface {
|
|
|
50
51
|
constructor(
|
|
51
52
|
readonly provider: SVMProvider,
|
|
52
53
|
readonly symbolMapping: SymbolMappingType,
|
|
53
|
-
readonly
|
|
54
|
+
readonly spokePool: SvmAddress,
|
|
54
55
|
readonly simulatedRelayerAddress: SvmAddress,
|
|
55
56
|
readonly logger: Logger,
|
|
56
57
|
readonly coingeckoProApiKey?: string,
|
|
@@ -74,7 +75,7 @@ export class SvmQuery implements QueryInterface {
|
|
|
74
75
|
*/
|
|
75
76
|
async getGasCosts(
|
|
76
77
|
deposit: Omit<Deposit, "messageHash">,
|
|
77
|
-
|
|
78
|
+
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
|
|
78
79
|
options: Partial<{
|
|
79
80
|
gasPrice: BigNumberish;
|
|
80
81
|
gasUnits: BigNumberish;
|
|
@@ -82,10 +83,9 @@ export class SvmQuery implements QueryInterface {
|
|
|
82
83
|
priorityFeeMultiplier: BigNumber;
|
|
83
84
|
}> = {}
|
|
84
85
|
): Promise<TransactionCostEstimate> {
|
|
85
|
-
const
|
|
86
|
-
const fillRelayTx = await this.getFillRelayTx(deposit, relayer.toBase58());
|
|
86
|
+
const fillRelayTx = await this.getFillRelayTx(deposit, relayer);
|
|
87
87
|
|
|
88
|
-
const [computeUnitsConsumed,
|
|
88
|
+
const [computeUnitsConsumed, gasPriceEstimate] = await Promise.all([
|
|
89
89
|
toBN(await this.computeUnitEstimator(fillRelayTx)),
|
|
90
90
|
getGasPriceEstimate(this.provider, {
|
|
91
91
|
unsignedTx: fillRelayTx,
|
|
@@ -96,7 +96,6 @@ export class SvmQuery implements QueryInterface {
|
|
|
96
96
|
|
|
97
97
|
// We can cast the gas price estimate to an SvmGasPriceEstimate here since the oracle should always
|
|
98
98
|
// query the Solana adapter.
|
|
99
|
-
const gasPriceEstimate = _gasPriceEstimate as SvmGasPriceEstimate;
|
|
100
99
|
const gasPrice = gasPriceEstimate.baseFee.add(
|
|
101
100
|
gasPriceEstimate.microLamportsPerComputeUnit.mul(computeUnitsConsumed).div(toBN(1_000_000)) // 1_000_000 microLamports/lamport.
|
|
102
101
|
);
|
|
@@ -116,7 +115,7 @@ export class SvmQuery implements QueryInterface {
|
|
|
116
115
|
*/
|
|
117
116
|
async getNativeGasCost(
|
|
118
117
|
deposit: Omit<Deposit, "messageHash">,
|
|
119
|
-
_relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
|
|
118
|
+
_relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
|
|
120
119
|
): Promise<BigNumber> {
|
|
121
120
|
const fillRelayTx = await this.getFillRelayTx(deposit, _relayer);
|
|
122
121
|
return toBN(await this.computeUnitEstimator(fillRelayTx));
|
|
@@ -130,42 +129,40 @@ export class SvmQuery implements QueryInterface {
|
|
|
130
129
|
*/
|
|
131
130
|
async getFillRelayTx(
|
|
132
131
|
deposit: Omit<Deposit, "messageHash">,
|
|
133
|
-
|
|
132
|
+
relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
|
|
134
133
|
repaymentChainId = deposit.destinationChainId,
|
|
135
|
-
repaymentAddress =
|
|
134
|
+
repaymentAddress = toAddressType(
|
|
135
|
+
getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
136
|
+
deposit.destinationChainId
|
|
137
|
+
)
|
|
136
138
|
) {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
const _relayDataHash = getRelayDataHash(deposit,
|
|
139
|
+
const { depositor, recipient, inputToken, outputToken, exclusiveRelayer, destinationChainId } = deposit;
|
|
140
|
+
|
|
141
|
+
const program = toAddress(this.spokePool);
|
|
142
|
+
const _relayDataHash = getRelayDataHash(deposit, destinationChainId);
|
|
141
143
|
const relayDataHash = new Uint8Array(Buffer.from(_relayDataHash.slice(2), "hex"));
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const mint =
|
|
149
|
-
const mintInfo = await fetchMint(this.provider, mint
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
mintInfo.programAddress
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
mint,
|
|
158
|
-
mintInfo.programAddress
|
|
159
|
-
);
|
|
160
|
-
const fillStatus = await getFillStatusPda(this.spokePoolAddress.toV2Address(), deposit, deposit.destinationChainId);
|
|
161
|
-
const eventAuthority = await getEventAuthority();
|
|
144
|
+
|
|
145
|
+
const [state, delegate] = await Promise.all([
|
|
146
|
+
getStatePda(program),
|
|
147
|
+
getFillRelayDelegatePda(relayDataHash, BigInt(repaymentChainId), toAddress(repaymentAddress), program),
|
|
148
|
+
]);
|
|
149
|
+
|
|
150
|
+
const mint = toAddress(outputToken);
|
|
151
|
+
const mintInfo = await fetchMint(this.provider, mint);
|
|
152
|
+
|
|
153
|
+
const [recipientAta, relayerAta, fillStatus, eventAuthority] = await Promise.all([
|
|
154
|
+
getAssociatedTokenAddress(deposit.recipient, outputToken, mintInfo.programAddress),
|
|
155
|
+
getAssociatedTokenAddress(SvmAddress.from(relayer.toBase58()), outputToken, mintInfo.programAddress),
|
|
156
|
+
getFillStatusPda(program, deposit, destinationChainId),
|
|
157
|
+
getEventAuthority(program),
|
|
158
|
+
]);
|
|
162
159
|
|
|
163
160
|
const relayData: SvmSpokeClient.FillRelayInput["relayData"] = {
|
|
164
|
-
depositor:
|
|
165
|
-
recipient:
|
|
166
|
-
exclusiveRelayer:
|
|
167
|
-
inputToken:
|
|
168
|
-
outputToken: mint
|
|
161
|
+
depositor: toAddress(depositor),
|
|
162
|
+
recipient: toAddress(recipient),
|
|
163
|
+
exclusiveRelayer: toAddress(exclusiveRelayer),
|
|
164
|
+
inputToken: toAddress(inputToken),
|
|
165
|
+
outputToken: mint,
|
|
169
166
|
inputAmount: deposit.inputAmount.toBigInt(),
|
|
170
167
|
outputAmount: deposit.outputAmount.toBigInt(),
|
|
171
168
|
originChainId: deposit.originChainId,
|
|
@@ -180,19 +177,19 @@ export class SvmQuery implements QueryInterface {
|
|
|
180
177
|
signer: simulatedSigner,
|
|
181
178
|
state,
|
|
182
179
|
delegate,
|
|
183
|
-
mint
|
|
180
|
+
mint,
|
|
184
181
|
relayerTokenAccount: relayerAta,
|
|
185
182
|
recipientTokenAccount: recipientAta,
|
|
186
183
|
fillStatus,
|
|
187
184
|
tokenProgram: mintInfo.programAddress,
|
|
188
185
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
189
186
|
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
190
|
-
eventAuthority
|
|
191
|
-
program
|
|
187
|
+
eventAuthority,
|
|
188
|
+
program,
|
|
192
189
|
relayHash: relayDataHash,
|
|
193
190
|
relayData,
|
|
194
191
|
repaymentChainId: BigInt(repaymentChainId),
|
|
195
|
-
repaymentAddress:
|
|
192
|
+
repaymentAddress: toAddress(repaymentAddress),
|
|
196
193
|
};
|
|
197
194
|
// Pass createRecipientAtaIfNeeded =true to the createFillInstruction function to create the recipient token account
|
|
198
195
|
// if it doesn't exist.
|
|
@@ -9,12 +9,9 @@ import { Deposit } from "../interfaces";
|
|
|
9
9
|
import {
|
|
10
10
|
BigNumber,
|
|
11
11
|
BigNumberish,
|
|
12
|
-
ConvertDecimals,
|
|
13
12
|
MAX_BIG_INT,
|
|
14
13
|
TransactionCostEstimate,
|
|
15
14
|
bnZero,
|
|
16
|
-
chainIsSvm,
|
|
17
|
-
compareAddressesSimple,
|
|
18
15
|
fixedPointAdjustment,
|
|
19
16
|
getTokenInfo,
|
|
20
17
|
isDefined,
|
|
@@ -25,13 +22,18 @@ import {
|
|
|
25
22
|
percent,
|
|
26
23
|
toBN,
|
|
27
24
|
toBNWei,
|
|
25
|
+
compareAddressesSimple,
|
|
26
|
+
ConvertDecimals,
|
|
27
|
+
chainIsSvm,
|
|
28
|
+
toAddressType,
|
|
29
|
+
Address,
|
|
28
30
|
} from "../utils";
|
|
29
31
|
|
|
30
32
|
// This needs to be implemented for every chain and passed into RelayFeeCalculator
|
|
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,10 @@ export class RelayFeeCalculator {
|
|
|
254
256
|
deposit: Deposit,
|
|
255
257
|
outputAmount: BigNumberish,
|
|
256
258
|
simulateZeroFill = false,
|
|
257
|
-
relayerAddress =
|
|
259
|
+
relayerAddress = toAddressType(
|
|
260
|
+
getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
261
|
+
deposit.destinationChainId
|
|
262
|
+
),
|
|
258
263
|
_tokenPrice?: number,
|
|
259
264
|
tokenMapping = TOKEN_SYMBOLS_MAP,
|
|
260
265
|
gasPrice?: BigNumberish,
|
|
@@ -271,14 +276,14 @@ export class RelayFeeCalculator {
|
|
|
271
276
|
// undefined address on destination.
|
|
272
277
|
const destinationChainTokenDetails = Object.values(tokenMapping).find(
|
|
273
278
|
(details) =>
|
|
274
|
-
compareAddressesSimple(details.addresses[originChainId], inputToken) &&
|
|
279
|
+
compareAddressesSimple(details.addresses[originChainId], inputToken.toNative()) &&
|
|
275
280
|
isDefined(details.addresses[destinationChainId])
|
|
276
281
|
);
|
|
277
282
|
const outputToken = isZeroAddress(deposit.outputToken)
|
|
278
283
|
? destinationChainTokenDetails!.addresses[destinationChainId]
|
|
279
|
-
: deposit.outputToken;
|
|
284
|
+
: deposit.outputToken.toNative();
|
|
280
285
|
const outputTokenInfo = getTokenInfo(outputToken, destinationChainId, tokenMapping);
|
|
281
|
-
const inputTokenInfo = getTokenInfo(inputToken, originChainId, tokenMapping);
|
|
286
|
+
const inputTokenInfo = getTokenInfo(inputToken.toNative(), originChainId, tokenMapping);
|
|
282
287
|
if (!isDefined(outputTokenInfo) || !isDefined(inputTokenInfo)) {
|
|
283
288
|
throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
|
|
284
289
|
}
|
|
@@ -493,7 +498,10 @@ export class RelayFeeCalculator {
|
|
|
493
498
|
deposit: Deposit,
|
|
494
499
|
outputAmount?: BigNumberish,
|
|
495
500
|
simulateZeroFill = false,
|
|
496
|
-
relayerAddress =
|
|
501
|
+
relayerAddress = toAddressType(
|
|
502
|
+
getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
503
|
+
deposit.destinationChainId
|
|
504
|
+
),
|
|
497
505
|
_tokenPrice?: number,
|
|
498
506
|
gasPrice?: BigNumberish,
|
|
499
507
|
gasUnits?: BigNumberish,
|
|
@@ -505,8 +513,8 @@ export class RelayFeeCalculator {
|
|
|
505
513
|
const { inputToken, originChainId, outputToken, destinationChainId } = deposit;
|
|
506
514
|
// We can perform a simple lookup with `getTokenInfo` here without resolving the exact token to resolve since we only need to
|
|
507
515
|
// resolve the L1 token symbol and not the L2 token decimals.
|
|
508
|
-
const inputTokenInfo = getTokenInfo(inputToken, originChainId);
|
|
509
|
-
const outputTokenInfo = getTokenInfo(outputToken, destinationChainId);
|
|
516
|
+
const inputTokenInfo = getTokenInfo(inputToken.toNative(), originChainId);
|
|
517
|
+
const outputTokenInfo = getTokenInfo(outputToken.toNative(), destinationChainId);
|
|
510
518
|
if (!isDefined(inputTokenInfo) || !isDefined(outputTokenInfo)) {
|
|
511
519
|
throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
|
|
512
520
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { providers, utils } from "ethers";
|
|
2
2
|
import bs58 from "bs58";
|
|
3
|
-
import {
|
|
4
|
-
import { BigNumber, chainIsEvm } from "./";
|
|
3
|
+
import { BigNumber, chainIsEvm, chainIsSvm } from "./";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Checks if a contract is deployed at the given address
|
|
@@ -48,8 +47,9 @@ export function toBytes32(address: string): string {
|
|
|
48
47
|
return utils.hexZeroPad(address, 32).toLowerCase();
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
//
|
|
52
|
-
|
|
50
|
+
// Constructs a 20-byte checksummed EVM address from a hex string input.
|
|
51
|
+
// Throws an error if the underlying address length is longer than 20 bytes or incorrectly checksummed.
|
|
52
|
+
export function toEvmAddress(hexString: string): string {
|
|
53
53
|
// rawAddress is the address which is not properly checksummed.
|
|
54
54
|
const rawAddress = utils.hexZeroPad(utils.hexStripZeros(hexString), 20);
|
|
55
55
|
return utils.getAddress(rawAddress);
|
|
@@ -74,21 +74,17 @@ export function isValidEvmAddress(address: string): boolean {
|
|
|
74
74
|
/**
|
|
75
75
|
* Creates the proper address type given the input chain ID corresponding to the address's origin network.
|
|
76
76
|
* @param address Stringified address type to convert. Can be either hex encoded or base58 encoded.
|
|
77
|
-
* @param chainId
|
|
77
|
+
* @param chainId Chain ID for the intended use of the address.
|
|
78
78
|
* @returns a child `Address` type most fitting for the chain ID.
|
|
79
79
|
* @todo: Change this to `toAddress` once we remove the other `toAddress` function.
|
|
80
80
|
*/
|
|
81
|
-
export function toAddressType(address: string): Address
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// 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
|
-
// return an unchecked address type.
|
|
90
|
-
return new Address(utils.arrayify(address));
|
|
91
|
-
}
|
|
81
|
+
export function toAddressType(address: string, chainId: number): Address {
|
|
82
|
+
const rawAddress = address.startsWith("0x") ? utils.arrayify(address) : bs58.decode(address);
|
|
83
|
+
|
|
84
|
+
const isEvm = chainIsEvm(chainId);
|
|
85
|
+
if (isEvm && EvmAddress.validate(rawAddress)) return new EvmAddress(rawAddress);
|
|
86
|
+
if (!isEvm && SvmAddress.validate(rawAddress)) return new SvmAddress(rawAddress);
|
|
87
|
+
return new Address(rawAddress);
|
|
92
88
|
}
|
|
93
89
|
|
|
94
90
|
// The Address class can contain any address type. It is up to the subclasses to determine how to format the address's internal representation,
|
|
@@ -113,12 +109,24 @@ export class Address {
|
|
|
113
109
|
this.rawAddress = utils.zeroPad(_rawAddress, 32);
|
|
114
110
|
}
|
|
115
111
|
|
|
112
|
+
static __unsafeConstruct(_rawAddress: Uint8Array): Address {
|
|
113
|
+
return new this(_rawAddress);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
116
|
// Converts the address into a bytes32 string. Note that the output bytes will be lowercase so that it matches ethers event data. This function will never
|
|
117
117
|
// throw since address length validation was done at construction time.
|
|
118
118
|
toBytes32(): string {
|
|
119
119
|
return (this.bytes32Address ??= utils.hexZeroPad(utils.hexlify(this.rawAddress), 32).toLowerCase());
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
// 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
|
|
123
|
+
// that contain truncated `address` type as one of the fields
|
|
124
|
+
truncateToBytes20(): string {
|
|
125
|
+
// Take the last 20 bytes
|
|
126
|
+
const bytes20 = this.rawAddress.slice(-20);
|
|
127
|
+
return toEvmAddress(utils.hexlify(bytes20));
|
|
128
|
+
}
|
|
129
|
+
|
|
122
130
|
// 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
131
|
// as this address may be needed to represent an EVM address on Solana.
|
|
124
132
|
toBase58(): string {
|
|
@@ -126,7 +134,7 @@ export class Address {
|
|
|
126
134
|
}
|
|
127
135
|
|
|
128
136
|
// Converts the address to a BigNumber type.
|
|
129
|
-
toBigNumber(): BigNumber {
|
|
137
|
+
private toBigNumber(): BigNumber {
|
|
130
138
|
return (this.bnAddress ??= BigNumber.from(this.toBytes32()));
|
|
131
139
|
}
|
|
132
140
|
|
|
@@ -143,37 +151,20 @@ export class Address {
|
|
|
143
151
|
|
|
144
152
|
// Converts the address to a hex string. This method should be overriden by subclasses to obtain more meaningful
|
|
145
153
|
// address representations for the target chain ID.
|
|
146
|
-
|
|
154
|
+
toNative(): string {
|
|
147
155
|
return this.toBytes32();
|
|
148
156
|
}
|
|
149
157
|
|
|
150
|
-
// Converts the address to a Buffer type.
|
|
151
|
-
toBuffer(): Buffer {
|
|
152
|
-
return Buffer.from(this.rawAddress);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
158
|
// Implements `Hexable` for `Address`. Needed for encoding purposes. This class is treated by default as a bytes32 primitive type, but can change for subclasses.
|
|
156
159
|
toHexString(): string {
|
|
157
160
|
return this.toBytes32();
|
|
158
161
|
}
|
|
159
162
|
|
|
160
|
-
// Checks if this address can be coerced into a bytes20 evm address. Returns true if it is possible and false otherwise.
|
|
161
|
-
isValidEvmAddress(): boolean {
|
|
162
|
-
try {
|
|
163
|
-
this.toAddress();
|
|
164
|
-
return true;
|
|
165
|
-
} catch {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
163
|
// Checks if the address is valid on the given chain ID.
|
|
171
164
|
isValidOn(chainId: number): boolean {
|
|
172
|
-
if (chainIsEvm(chainId))
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
// Assume the address is always valid on Solana.
|
|
176
|
-
return true;
|
|
165
|
+
if (chainIsEvm(chainId)) return EvmAddress.validate(this.rawAddress);
|
|
166
|
+
if (chainIsSvm(chainId)) return SvmAddress.validate(this.rawAddress);
|
|
167
|
+
return false;
|
|
177
168
|
}
|
|
178
169
|
|
|
179
170
|
// Checks if the object is an address by looking at whether it has an Address constructor.
|
|
@@ -183,7 +174,7 @@ export class Address {
|
|
|
183
174
|
|
|
184
175
|
// Converts the input address to a 32-byte hex data string.
|
|
185
176
|
toString(): string {
|
|
186
|
-
return this.
|
|
177
|
+
return this.toNative();
|
|
187
178
|
}
|
|
188
179
|
|
|
189
180
|
// Checks if the address is the zero address.
|
|
@@ -196,11 +187,6 @@ export class Address {
|
|
|
196
187
|
return SvmAddress.from(this.toBase58());
|
|
197
188
|
}
|
|
198
189
|
|
|
199
|
-
// Forces `rawAddress` to become an EvmAddress type. This will throw if `rawAddress.length > 20`.
|
|
200
|
-
forceEvmAddress(): EvmAddress {
|
|
201
|
-
return EvmAddress.from(this.toEvmAddress());
|
|
202
|
-
}
|
|
203
|
-
|
|
204
190
|
// Checks if the other address is equivalent to this address.
|
|
205
191
|
eq(other: Address): boolean {
|
|
206
192
|
return this.toString() === other.toString();
|
|
@@ -220,21 +206,35 @@ export class Address {
|
|
|
220
206
|
return 0;
|
|
221
207
|
}
|
|
222
208
|
}
|
|
209
|
+
|
|
210
|
+
static isEvmAddress(address: Address): boolean {
|
|
211
|
+
return address instanceof EvmAddress;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static isSvmAddress(address: Address): boolean {
|
|
215
|
+
return address instanceof SvmAddress;
|
|
216
|
+
}
|
|
223
217
|
}
|
|
224
218
|
|
|
225
219
|
// Subclass of address which strictly deals with 20-byte addresses. These addresses are guaranteed to be valid EVM addresses, so `toAddress` will always succeed.
|
|
226
220
|
export class EvmAddress extends Address {
|
|
227
221
|
// On construction, validate that the address can indeed be coerced into an EVM address. Throw immediately if it cannot.
|
|
228
222
|
constructor(rawAddress: Uint8Array) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (!this.isValidEvmAddress()) {
|
|
232
|
-
throw new Error(`${hexString} is not a valid EVM address`);
|
|
223
|
+
if (!EvmAddress.validate(rawAddress)) {
|
|
224
|
+
throw new Error(`${utils.hexlify(rawAddress)} is not a valid EVM address`);
|
|
233
225
|
}
|
|
226
|
+
|
|
227
|
+
super(rawAddress);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
static validate(rawAddress: Uint8Array): boolean {
|
|
231
|
+
return (
|
|
232
|
+
rawAddress.length == 20 || (rawAddress.length === 32 && rawAddress.slice(0, 12).every((field) => field === 0))
|
|
233
|
+
);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
// Override `toAddress` to return the 20-byte representation address.
|
|
237
|
-
override
|
|
237
|
+
override toNative(): string {
|
|
238
238
|
return this.toEvmAddress();
|
|
239
239
|
}
|
|
240
240
|
|
|
@@ -260,25 +260,23 @@ export class EvmAddress extends Address {
|
|
|
260
260
|
export class SvmAddress extends Address {
|
|
261
261
|
// On construction, validate that the address is a point on Curve25519. Throw immediately if it is not.
|
|
262
262
|
constructor(rawAddress: Uint8Array) {
|
|
263
|
+
if (!SvmAddress.validate(rawAddress)) {
|
|
264
|
+
throw new Error(`${utils.hexlify(rawAddress)} is not a valid SVM address`); // @todo: Display as Base58?
|
|
265
|
+
}
|
|
266
|
+
|
|
263
267
|
super(rawAddress);
|
|
264
268
|
}
|
|
265
269
|
|
|
270
|
+
static validate(rawAddress: Uint8Array): boolean {
|
|
271
|
+
return rawAddress.length === 32;
|
|
272
|
+
}
|
|
273
|
+
|
|
266
274
|
// Override the toAddress function for SVM addresses only since while they will never have a defined 20-byte representation. The base58 encoded addresses are also the encodings
|
|
267
275
|
// used in TOKEN_SYMBOLS_MAP.
|
|
268
|
-
override
|
|
276
|
+
override toNative(): string {
|
|
269
277
|
return this.toBase58();
|
|
270
278
|
}
|
|
271
279
|
|
|
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
280
|
// Constructs a new SvmAddress type.
|
|
283
281
|
static from(address: string, encoding: "base58" | "base16" = "base58"): SvmAddress {
|
|
284
282
|
if (encoding === "base58") {
|
package/src/utils/EventUtils.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Result } from "@ethersproject/abi";
|
|
|
3
3
|
import { Contract, Event, EventFilter } from "ethers";
|
|
4
4
|
import { Log, SortableEvent } from "../interfaces";
|
|
5
5
|
import { delay } from "./common";
|
|
6
|
-
import { isDefined, toBN, BigNumberish,
|
|
6
|
+
import { isDefined, toBN, BigNumberish, toEvmAddress } from "./";
|
|
7
7
|
|
|
8
8
|
const maxRetries = 3;
|
|
9
9
|
const retrySleepTime = 10;
|
|
@@ -88,7 +88,7 @@ export function spreadEvent(args: Result | Record<string, unknown>): { [key: str
|
|
|
88
88
|
if (isDefined(returnedObject[field])) {
|
|
89
89
|
let address = String(returnedObject[field]);
|
|
90
90
|
try {
|
|
91
|
-
address =
|
|
91
|
+
address = toEvmAddress(address);
|
|
92
92
|
// eslint-disable-next-line no-empty
|
|
93
93
|
} catch (_) {}
|
|
94
94
|
returnedObject[field] = address;
|