2
2
Address ,
3
3
Hash ,
4
4
Abi ,
5
+ Account ,
5
6
InferFunctionName ,
6
7
GetFunctionArgs ,
7
8
SimulateContractParameters ,
@@ -108,13 +109,19 @@ export class ProtocolContracts<
108
109
txSubject ?: string ,
109
110
) : Promise < TransactionReceipt > {
110
111
try {
111
- if ( ! walletClient && ! this . walletClient ) {
112
+ walletClient = walletClient ?? this . walletClient ;
113
+
114
+ if ( ! walletClient ) {
112
115
throw new Error ( 'Invalid walletClient configuration' ) ;
113
116
}
114
117
115
- walletClient = walletClient ?? this . walletClient ;
118
+ let account = walletClient . account ;
119
+
120
+ if ( ! account || account ?. type !== 'local' ) {
121
+ const [ accountAddress ] = await walletClient . getAddresses ( ) ;
122
+ account = accountAddress as unknown as Account ;
123
+ }
116
124
117
- const [ account ] = await walletClient . getAddresses ( ) ;
118
125
const requestOptions = {
119
126
address,
120
127
abi,
@@ -129,12 +136,17 @@ export class ProtocolContracts<
129
136
130
137
const hash = await walletClient . writeContract ( request ) ;
131
138
139
+ logger . trace ( `Tx: ${ hash } , subject: "${ txSubject ?? '' } "` ) ;
140
+
132
141
if ( txCallback ) {
133
142
txCallback ( hash , txSubject ) ;
134
- logger . trace ( `Tx: ${ hash } , subject: "${ txSubject ?? '' } "` ) ;
135
143
}
136
144
137
- return await this . publicClient . waitForTransactionReceipt ( { hash } ) ;
145
+ const receipt = await this . publicClient . waitForTransactionReceipt ( { hash } ) ;
146
+
147
+ logger . trace ( 'Tx receipt:' , receipt ) ;
148
+
149
+ return receipt ;
138
150
} catch ( error ) {
139
151
logger . error ( error ) ;
140
152
@@ -193,13 +205,15 @@ export class ProtocolContracts<
193
205
// Will throw a error if invalid payment Id provided
194
206
const paymentOption = getPaymentOption ( offer . payment , paymentId ) ;
195
207
196
- if ( ! walletClient && ! this . walletClient ) {
197
- throw new Error ( `Invalid walletClient configuration` ) ;
208
+ walletClient = walletClient ?? this . walletClient ;
209
+
210
+ if ( ! walletClient ) {
211
+ throw new Error ( 'Invalid walletClient configuration' ) ;
198
212
}
199
213
200
214
// Asset must be allowed to Market in the proper amount
201
215
// This function will check allowance and send `approve` transaction if required
202
- const [ owner ] = await ( walletClient ?? this . walletClient ) . getAddresses ( ) ;
216
+ const [ owner ] = await walletClient . getAddresses ( ) ;
203
217
204
218
const allowance = await this . publicClient . readContract ( {
205
219
address : paymentOption . asset ,
0 commit comments