Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit e7c57b9

Browse files
committed
convert to ethers v6
1 parent 530598a commit e7c57b9

19 files changed

+577
-419
lines changed

evm/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build:esm": "tsc -p tsconfig.esm.json",
1515
"build:cjs": "tsc -p tsconfig.cjs.json",
1616
"build": "npm run build:esm && npm run build:cjs",
17-
"generate": "typechain --target=ethers-v5 --out-dir=ts/src/types out/[!build-info]*/*.json",
17+
"generate": "typechain --target=ethers-v6 --out-dir=ts/src/types out/[!build-info]*/*.json",
1818
"clean": "rm -rf dist && rm -rf node_modules && rm -f ./*.tsbuildinfo"
1919
},
2020
"exports": {
@@ -34,11 +34,11 @@
3434
"@wormhole-foundation/sdk-definitions": "^0.7.0-beta.6",
3535
"@wormhole-foundation/sdk-evm": "^0.7.0-beta.6",
3636
"@wormhole-foundation/example-liquidity-layer-definitions": "0.0.1",
37-
"ethers": "^5.7.2"
37+
"ethers": "^6.5.1"
3838
},
3939
"devDependencies": {
4040
"envfile": "^7.1.0",
41-
"@typechain/ethers-v5": "^10.2.0",
41+
"@typechain/ethers-v6":"0.5.1",
4242
"@types/chai": "^4.3.4",
4343
"@types/mocha": "^10.0.1",
4444
"@types/node": "^18.14.5",

evm/ts/src/MatchingEngine/evm.ts

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChainId } from "@wormhole-foundation/sdk-base";
1+
import { ChainId, asChainId } from "@wormhole-foundation/sdk-base";
22
import { ethers } from "ethers";
33
import { RouterEndpoint, LiveAuctionData, MatchingEngine, RedeemParameters } from ".";
44
import { LiquidityLayerTransactionResult } from "..";
@@ -23,74 +23,66 @@ export class EvmMatchingEngine implements MatchingEngine<ethers.ContractTransact
2323
};
2424

2525
constructor(
26-
connection: ethers.Signer | ethers.providers.Provider,
27-
contractAddress: string,
28-
circleBridge: string,
26+
private connection: ethers.Provider,
27+
readonly contractAddress: string,
28+
readonly circleBridge: string,
2929
) {
3030
this.contract = IMatchingEngine__factory.connect(contractAddress, connection);
3131
this.circle = ITokenMessenger__factory.connect(circleBridge, connection);
3232
}
3333

3434
get address(): string {
35-
return this.contract.address;
35+
return this.contractAddress;
3636
}
3737

38-
get signer(): ethers.Signer {
39-
return this.contract.signer;
38+
get provider(): ethers.Provider {
39+
return this.connection;
4040
}
4141

42-
get signerAddress(): Promise<string> {
43-
return this.contract.signer.getAddress();
44-
}
45-
46-
get provider(): ethers.providers.Provider {
47-
return this.contract.provider;
48-
}
49-
50-
connect(connection: ethers.Signer | ethers.providers.Provider): EvmMatchingEngine {
51-
return new EvmMatchingEngine(connection, this.address, this.circle.address);
42+
connect(connection: ethers.Provider): EvmMatchingEngine {
43+
return new EvmMatchingEngine(connection, this.address, this.circleBridge);
5244
}
5345

5446
async addRouterEndpoint(
5547
chain: number,
5648
endpoint: RouterEndpoint,
5749
domain: number,
5850
): Promise<ethers.ContractTransaction> {
59-
return this.contract.addRouterEndpoint(chain, endpoint, domain);
51+
return this.contract.addRouterEndpoint.populateTransaction(chain, endpoint, domain);
6052
}
6153

6254
async placeInitialBid(
6355
fastTransferVaa: Buffer | Uint8Array,
6456
feeBid: bigint | ethers.BigNumberish,
6557
): Promise<ethers.ContractTransaction> {
66-
return this.contract.placeInitialBid(fastTransferVaa, feeBid);
58+
return this.contract.placeInitialBid.populateTransaction(fastTransferVaa, feeBid);
6759
}
6860

6961
async improveBid(
7062
auctionId: Buffer | Uint8Array,
7163
feeBid: bigint | ethers.BigNumberish,
7264
): Promise<ethers.ContractTransaction> {
73-
return this.contract.improveBid(auctionId, feeBid);
65+
return this.contract.improveBid.populateTransaction(auctionId, feeBid);
7466
}
7567

7668
async executeFastOrder(
7769
fastTransferVaa: Buffer | Uint8Array,
7870
): Promise<ethers.ContractTransaction> {
79-
return this.contract.executeFastOrder(fastTransferVaa);
71+
return this.contract.executeFastOrder.populateTransaction(fastTransferVaa);
8072
}
8173

8274
async executeSlowOrderAndRedeem(
8375
fastTransferVaa: Buffer | Uint8Array,
8476
params: RedeemParameters,
8577
): Promise<ethers.ContractTransaction> {
86-
return this.contract.executeSlowOrderAndRedeem(fastTransferVaa, params);
78+
return this.contract.executeSlowOrderAndRedeem.populateTransaction(fastTransferVaa, params);
8779
}
8880

8981
async calculateDynamicPenalty(
9082
auctionId?: Buffer | Uint8Array,
9183
amount?: bigint | ethers.BigNumberish,
9284
blocksElapsed?: bigint | ethers.BigNumberish,
93-
): Promise<[ethers.BigNumberish, ethers.BigNumberish]> {
85+
): Promise<[bigint, bigint]> {
9486
if (auctionId !== undefined) {
9587
return this.contract["calculateDynamicPenalty(bytes32)"](auctionId);
9688
} else if (amount !== undefined && blocksElapsed !== undefined) {
@@ -104,27 +96,27 @@ export class EvmMatchingEngine implements MatchingEngine<ethers.ContractTransact
10496
return this.contract.liveAuctionInfo(auctionId);
10597
}
10698

107-
async auctionStatus(auctionId: Buffer | Uint8Array): Promise<number> {
99+
async auctionStatus(auctionId: Buffer | Uint8Array) {
108100
return this.contract.liveAuctionInfo(auctionId).then((res) => res.status);
109101
}
110102

111-
async getAuctionGracePeriod(): Promise<number> {
103+
async getAuctionGracePeriod() {
112104
return this.contract.getAuctionGracePeriod();
113105
}
114106

115-
async getAuctionDuration(): Promise<number> {
107+
async getAuctionDuration() {
116108
return this.contract.getAuctionDuration();
117109
}
118110

119-
async getPenaltyBlocks(): Promise<number> {
111+
async getPenaltyBlocks() {
120112
return this.contract.getAuctionPenaltyBlocks();
121113
}
122114

123-
async getInitialPenaltyBps(): Promise<number> {
115+
async getInitialPenaltyBps() {
124116
return this.contract.getInitialPenaltyBps();
125117
}
126118

127-
async getUserPenaltyRewardBps(): Promise<number> {
119+
async getUserPenaltyRewardBps() {
128120
return this.contract.getUserPenaltyRewardBps();
129121
}
130122

@@ -136,35 +128,33 @@ export class EvmMatchingEngine implements MatchingEngine<ethers.ContractTransact
136128
// Check cached contracts.
137129
const { chainId, coreBridge, circleTransmitterAddress } = await this._cacheIfNeeded();
138130

139-
return this.contract.provider
140-
.getTransactionReceipt(txHash)
131+
const coreAddress = await coreBridge.getAddress();
132+
133+
return this.connection
134+
.provider!.getTransactionReceipt(txHash)
141135
.then((txReceipt) =>
142136
LiquidityLayerTransactionResult.fromEthersTransactionReceipt(
143137
chainId,
144138
this.address,
145-
coreBridge.address,
146-
txReceipt,
139+
coreAddress,
140+
txReceipt!,
147141
circleTransmitterAddress,
148142
),
149143
);
150144
}
151145

152146
private async _cacheIfNeeded() {
153147
if (this.cache === undefined) {
154-
const provider = this.contract.provider;
148+
const provider = this.connection;
155149
const coreBridge = await this.contract
156150
.wormhole()
157151
.then((addr) => IWormhole__factory.connect(addr, provider));
158152
const circleTransmitterAddress = await this.circle.localMessageTransmitter();
159153

160154
// If this isn't a recognized ChainId, we have problems.
161-
const chainId = await coreBridge.chainId();
155+
const chainId = asChainId(Number(await coreBridge.chainId()));
162156

163-
this.cache = {
164-
chainId: chainId as ChainId,
165-
coreBridge,
166-
circleTransmitterAddress,
167-
};
157+
this.cache = { chainId, coreBridge, circleTransmitterAddress };
168158
}
169159

170160
return this.cache;

evm/ts/src/MatchingEngine/index.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export type RedeemParameters = {
1010
};
1111

1212
export type LiveAuctionData = {
13-
status: number;
14-
startBlock: bigint | ethers.BigNumberish;
13+
status: bigint;
14+
startBlock: bigint;
1515
highestBidder: string;
1616
initialBidder: string;
17-
amount: bigint | ethers.BigNumberish;
18-
securityDeposit: bigint | ethers.BigNumberish;
19-
bidPrice: bigint | ethers.BigNumberish;
17+
amount: bigint;
18+
securityDeposit: bigint;
19+
bidPrice: bigint;
2020
};
2121

2222
export type RouterEndpoint = {
@@ -30,47 +30,47 @@ export abstract class MatchingEngine<PreparedTransactionType extends PreparedIns
3030
abstract addRouterEndpoint(
3131
chain: number,
3232
endpoint: RouterEndpoint,
33-
domain: number
33+
domain: number,
3434
): Promise<PreparedTransactionType>;
3535

3636
abstract liveAuctionInfo(auctionId: Buffer | Uint8Array): Promise<LiveAuctionData>;
3737

38-
abstract auctionStatus(auctionId: Buffer | Uint8Array): Promise<number>;
38+
abstract auctionStatus(auctionId: Buffer | Uint8Array): Promise<bigint>;
3939

4040
abstract placeInitialBid(
4141
fastTransferVaa: Buffer | Uint8Array,
42-
feeBid: bigint
42+
feeBid: bigint,
4343
): Promise<PreparedTransactionType>;
4444

4545
abstract improveBid(
4646
auctionId: Buffer | Uint8Array,
47-
feeBid: bigint
47+
feeBid: bigint,
4848
): Promise<PreparedTransactionType>;
4949

5050
abstract executeFastOrder(
51-
fastTransferVaa: Buffer | Uint8Array
51+
fastTransferVaa: Buffer | Uint8Array,
5252
): Promise<PreparedTransactionType>;
5353

5454
abstract executeSlowOrderAndRedeem(
5555
fastTransferVaa: Buffer | Uint8Array,
56-
params: RedeemParameters
56+
params: RedeemParameters,
5757
): Promise<PreparedTransactionType>;
5858

5959
abstract calculateDynamicPenalty(
6060
auctionId?: Buffer | Uint8Array,
6161
amount?: bigint,
62-
blocksElapsed?: bigint
62+
blocksElapsed?: bigint,
6363
): Promise<[ethers.BigNumberish, ethers.BigNumberish]>;
6464

65-
abstract getAuctionGracePeriod(): Promise<number>;
65+
abstract getAuctionGracePeriod(): Promise<bigint>;
6666

67-
abstract getAuctionDuration(): Promise<number>;
67+
abstract getAuctionDuration(): Promise<bigint>;
6868

69-
abstract getPenaltyBlocks(): Promise<number>;
69+
abstract getPenaltyBlocks(): Promise<bigint>;
7070

71-
abstract getInitialPenaltyBps(): Promise<number>;
71+
abstract getInitialPenaltyBps(): Promise<bigint>;
7272

73-
abstract getInitialPenaltyBps(): Promise<number>;
73+
abstract getInitialPenaltyBps(): Promise<bigint>;
7474

7575
abstract wormhole(): Promise<string>;
7676

0 commit comments

Comments
 (0)