Skip to content

Commit

Permalink
fix(api): estimating transaction fees when inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
hbriese committed Jul 28, 2024
1 parent 976fcff commit 5f46f1f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions api/src/feat/transactions/transactions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,29 @@ export class TransactionsService {
const network = this.networks.get(chain);
const paymaster = this.paymasters.for(chain);

const isActive = !!(await network.getCode({ address: asAddress(account) }))?.length;

const getGas = async () =>
gasInput ??
(
await network.estimateFee({
type: 'eip712',
account: asAddress(account),
paymaster,
paymasterInput: encodePaymasterInput({
token: feeToken,
amount: 0n,
maxAmount: 0n,
}),
...encodeOperations(operations),
// Only active accounts can estimate paymaster fees. Inactive accounts use EOA account code and throw 'Unsupported paymaster flow'
...(isActive
? {
paymaster,
paymasterInput: encodePaymasterInput({
token: feeToken,
amount: 0n,
maxAmount: 0n,
}),
}
: {
paymaster: undefined,
paymasterInput: undefined,
}),
})
).gasLimit;

Expand Down

0 comments on commit 5f46f1f

Please sign in to comment.