1
- import { ChainId } from "@wormhole-foundation/sdk-base" ;
1
+ import { ChainId , asChainId } from "@wormhole-foundation/sdk-base" ;
2
2
import { ethers } from "ethers" ;
3
3
import { RouterEndpoint , LiveAuctionData , MatchingEngine , RedeemParameters } from "." ;
4
4
import { LiquidityLayerTransactionResult } from ".." ;
@@ -23,74 +23,66 @@ export class EvmMatchingEngine implements MatchingEngine<ethers.ContractTransact
23
23
} ;
24
24
25
25
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 ,
29
29
) {
30
30
this . contract = IMatchingEngine__factory . connect ( contractAddress , connection ) ;
31
31
this . circle = ITokenMessenger__factory . connect ( circleBridge , connection ) ;
32
32
}
33
33
34
34
get address ( ) : string {
35
- return this . contract . address ;
35
+ return this . contractAddress ;
36
36
}
37
37
38
- get signer ( ) : ethers . Signer {
39
- return this . contract . signer ;
38
+ get provider ( ) : ethers . Provider {
39
+ return this . connection ;
40
40
}
41
41
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 ) ;
52
44
}
53
45
54
46
async addRouterEndpoint (
55
47
chain : number ,
56
48
endpoint : RouterEndpoint ,
57
49
domain : number ,
58
50
) : Promise < ethers . ContractTransaction > {
59
- return this . contract . addRouterEndpoint ( chain , endpoint , domain ) ;
51
+ return this . contract . addRouterEndpoint . populateTransaction ( chain , endpoint , domain ) ;
60
52
}
61
53
62
54
async placeInitialBid (
63
55
fastTransferVaa : Buffer | Uint8Array ,
64
56
feeBid : bigint | ethers . BigNumberish ,
65
57
) : Promise < ethers . ContractTransaction > {
66
- return this . contract . placeInitialBid ( fastTransferVaa , feeBid ) ;
58
+ return this . contract . placeInitialBid . populateTransaction ( fastTransferVaa , feeBid ) ;
67
59
}
68
60
69
61
async improveBid (
70
62
auctionId : Buffer | Uint8Array ,
71
63
feeBid : bigint | ethers . BigNumberish ,
72
64
) : Promise < ethers . ContractTransaction > {
73
- return this . contract . improveBid ( auctionId , feeBid ) ;
65
+ return this . contract . improveBid . populateTransaction ( auctionId , feeBid ) ;
74
66
}
75
67
76
68
async executeFastOrder (
77
69
fastTransferVaa : Buffer | Uint8Array ,
78
70
) : Promise < ethers . ContractTransaction > {
79
- return this . contract . executeFastOrder ( fastTransferVaa ) ;
71
+ return this . contract . executeFastOrder . populateTransaction ( fastTransferVaa ) ;
80
72
}
81
73
82
74
async executeSlowOrderAndRedeem (
83
75
fastTransferVaa : Buffer | Uint8Array ,
84
76
params : RedeemParameters ,
85
77
) : Promise < ethers . ContractTransaction > {
86
- return this . contract . executeSlowOrderAndRedeem ( fastTransferVaa , params ) ;
78
+ return this . contract . executeSlowOrderAndRedeem . populateTransaction ( fastTransferVaa , params ) ;
87
79
}
88
80
89
81
async calculateDynamicPenalty (
90
82
auctionId ?: Buffer | Uint8Array ,
91
83
amount ?: bigint | ethers . BigNumberish ,
92
84
blocksElapsed ?: bigint | ethers . BigNumberish ,
93
- ) : Promise < [ ethers . BigNumberish , ethers . BigNumberish ] > {
85
+ ) : Promise < [ bigint , bigint ] > {
94
86
if ( auctionId !== undefined ) {
95
87
return this . contract [ "calculateDynamicPenalty(bytes32)" ] ( auctionId ) ;
96
88
} else if ( amount !== undefined && blocksElapsed !== undefined ) {
@@ -104,27 +96,27 @@ export class EvmMatchingEngine implements MatchingEngine<ethers.ContractTransact
104
96
return this . contract . liveAuctionInfo ( auctionId ) ;
105
97
}
106
98
107
- async auctionStatus ( auctionId : Buffer | Uint8Array ) : Promise < number > {
99
+ async auctionStatus ( auctionId : Buffer | Uint8Array ) {
108
100
return this . contract . liveAuctionInfo ( auctionId ) . then ( ( res ) => res . status ) ;
109
101
}
110
102
111
- async getAuctionGracePeriod ( ) : Promise < number > {
103
+ async getAuctionGracePeriod ( ) {
112
104
return this . contract . getAuctionGracePeriod ( ) ;
113
105
}
114
106
115
- async getAuctionDuration ( ) : Promise < number > {
107
+ async getAuctionDuration ( ) {
116
108
return this . contract . getAuctionDuration ( ) ;
117
109
}
118
110
119
- async getPenaltyBlocks ( ) : Promise < number > {
111
+ async getPenaltyBlocks ( ) {
120
112
return this . contract . getAuctionPenaltyBlocks ( ) ;
121
113
}
122
114
123
- async getInitialPenaltyBps ( ) : Promise < number > {
115
+ async getInitialPenaltyBps ( ) {
124
116
return this . contract . getInitialPenaltyBps ( ) ;
125
117
}
126
118
127
- async getUserPenaltyRewardBps ( ) : Promise < number > {
119
+ async getUserPenaltyRewardBps ( ) {
128
120
return this . contract . getUserPenaltyRewardBps ( ) ;
129
121
}
130
122
@@ -136,35 +128,33 @@ export class EvmMatchingEngine implements MatchingEngine<ethers.ContractTransact
136
128
// Check cached contracts.
137
129
const { chainId, coreBridge, circleTransmitterAddress } = await this . _cacheIfNeeded ( ) ;
138
130
139
- return this . contract . provider
140
- . getTransactionReceipt ( txHash )
131
+ const coreAddress = await coreBridge . getAddress ( ) ;
132
+
133
+ return this . connection
134
+ . provider ! . getTransactionReceipt ( txHash )
141
135
. then ( ( txReceipt ) =>
142
136
LiquidityLayerTransactionResult . fromEthersTransactionReceipt (
143
137
chainId ,
144
138
this . address ,
145
- coreBridge . address ,
146
- txReceipt ,
139
+ coreAddress ,
140
+ txReceipt ! ,
147
141
circleTransmitterAddress ,
148
142
) ,
149
143
) ;
150
144
}
151
145
152
146
private async _cacheIfNeeded ( ) {
153
147
if ( this . cache === undefined ) {
154
- const provider = this . contract . provider ;
148
+ const provider = this . connection ;
155
149
const coreBridge = await this . contract
156
150
. wormhole ( )
157
151
. then ( ( addr ) => IWormhole__factory . connect ( addr , provider ) ) ;
158
152
const circleTransmitterAddress = await this . circle . localMessageTransmitter ( ) ;
159
153
160
154
// If this isn't a recognized ChainId, we have problems.
161
- const chainId = await coreBridge . chainId ( ) ;
155
+ const chainId = asChainId ( Number ( await coreBridge . chainId ( ) ) ) ;
162
156
163
- this . cache = {
164
- chainId : chainId as ChainId ,
165
- coreBridge,
166
- circleTransmitterAddress,
167
- } ;
157
+ this . cache = { chainId, coreBridge, circleTransmitterAddress } ;
168
158
}
169
159
170
160
return this . cache ;
0 commit comments