1- import { ChainId } from "@wormhole-foundation/sdk-base" ;
1+ import { ChainId , asChainId } from "@wormhole-foundation/sdk-base" ;
22import { ethers } from "ethers" ;
33import { RouterEndpoint , LiveAuctionData , MatchingEngine , RedeemParameters } from "." ;
44import { 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 ;
0 commit comments