5
5
UUID ,
6
6
asAddress ,
7
7
asApproval ,
8
+ asFp ,
8
9
asHex ,
9
10
asScheduledSystemTransaction ,
10
11
asSystemTransaction ,
@@ -24,7 +25,6 @@ import { ProposalEvent } from '~/feat/proposals/proposals.input';
24
25
import { QueueReturnType , TypedJob , createQueue } from '~/core/bull/bull.util' ;
25
26
import { Worker } from '~/core/bull/Worker' ;
26
27
import { UnrecoverableError } from 'bullmq' ;
27
- import { utils as zkUtils } from 'zksync-ethers' ;
28
28
import { TokensService } from '~/feat/tokens/tokens.service' ;
29
29
import { PricesService } from '~/feat/prices/prices.service' ;
30
30
import Decimal from 'decimal.js' ;
@@ -119,12 +119,12 @@ export class ExecutionsWorker extends Worker<ExecutionsQueue> {
119
119
paymasterEthFees : totalPaymasterEthFees ( newPaymasterFees ) ,
120
120
ignoreSimulation,
121
121
executeParams : {
122
- ...asSystemTransaction ( { tx } ) ,
123
122
customSignature : encodeTransactionSignature ( {
124
123
tx,
125
124
policy : policyStateAsPolicy ( proposal . policy ) ,
126
125
approvals,
127
126
} ) ,
127
+ ...asSystemTransaction ( { tx } ) ,
128
128
} ,
129
129
} ) ;
130
130
}
@@ -175,22 +175,36 @@ export class ExecutionsWorker extends Worker<ExecutionsQueue> {
175
175
. plus ( paymasterEthFees ?? '0' ) ;
176
176
const amount = await this . tokens . asFp ( feeToken , totalFeeTokenFees ) ;
177
177
const maxAmount = await this . tokens . asFp ( feeToken , new Decimal ( proposal . maxAmount ) ) ;
178
- if ( amount > maxAmount ) throw new Error ( 'Amount > maxAmount' ) ; // TODO: handle
178
+ if ( amount > maxAmount ) throw new Error ( 'Amount > maxAmount' ) ; // TODO: add to failed submission result TODO: fail due to insufficient funds -- re-submit for re-simulation (forced)
179
179
180
180
await this . prices . updatePriceFeedsIfNecessary ( network . chain . key , [
181
181
ETH . pythUsdPriceId ,
182
182
asHex ( proposal . feeToken . pythUsdPriceId ! ) ,
183
183
] ) ;
184
184
185
+ const paymaster = asAddress ( proposal . paymaster ) ;
186
+ const paymasterInput = encodePaymasterInput ( {
187
+ token : asAddress ( feeToken ) ,
188
+ amount,
189
+ maxAmount,
190
+ } ) ;
191
+ const estimatedFee = await network . estimateFee ( {
192
+ type : 'eip712' ,
193
+ account : asAddress ( account ) ,
194
+ paymaster,
195
+ paymasterInput,
196
+ ...executeParams ,
197
+ } ) ;
198
+
199
+ // if (executeParams.gas && executeParams.gas < estimatedFee.gasLimit) throw new Error('gas less than estimated gasLimit');
200
+
185
201
const execution = await network . sendAccountTransaction ( {
186
202
from : asAddress ( account ) ,
187
- paymaster : asAddress ( proposal . paymaster ) ,
188
- paymasterInput : encodePaymasterInput ( {
189
- token : asAddress ( feeToken ) ,
190
- amount,
191
- maxAmount,
192
- } ) ,
193
- gasPerPubdata : BigInt ( zkUtils . DEFAULT_GAS_PER_PUBDATA_LIMIT ) ,
203
+ paymaster,
204
+ paymasterInput,
205
+ maxFeePerGas : asFp ( maxFeePerGas , ETH ) ,
206
+ maxPriorityFeePerGas : estimatedFee . maxPriorityFeePerGas ,
207
+ gasPerPubdata : estimatedFee . gasPerPubdataLimit , // This should ideally be signed during proposal creation
194
208
...executeParams ,
195
209
} ) ;
196
210
@@ -210,6 +224,9 @@ export class ExecutionsWorker extends Worker<ExecutionsQueue> {
210
224
211
225
return hash ;
212
226
} /* execution isErr */ else {
227
+
228
+ // TODO: adds failed submission result
229
+
213
230
// Validation failed
214
231
// const err = execution.error;
215
232
// await this.db.query(
0 commit comments