Skip to content

Commit

Permalink
fix: double fill (#8944)
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbinrui committed Mar 6, 2023
1 parent 1bf3ddf commit cad58c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Expand Up @@ -75,7 +75,7 @@ export class SmartPayAccountAPI implements AbstractAccountAPI.Provider<NetworkPl
return
}

await userTransaction.fillUserOperation(this.web3.getWeb3(chainId), await getOverrides())
await userTransaction.assetUserOperation(this.web3.getWeb3(chainId), await getOverrides())
return this.bundler.sendUserOperation(chainId, await userTransaction.signUserOperation(signer))
}

Expand Down
40 changes: 29 additions & 11 deletions packages/web3-shared/evm/src/libs/UserTransaction.ts
Expand Up @@ -169,24 +169,42 @@ export class UserTransaction {
return contract
}

async assetUserOperation(web3: Web3, overrides?: Required<Pick<UserOperation, 'initCode' | 'nonce'>>) {
// from overrides
if (overrides) {
this.userOperation.nonce = overrides.nonce
this.userOperation.initCode = overrides.initCode
}

const { initCode, nonce, sender, callData, callGas, preVerificationGas, maxFeePerGas, maxPriorityFeePerGas } =
this.userOperation

if (!isEmptyHex(initCode) && nonce === 0) throw new Error('Missing init code.')

if (!isValidAddress(sender)) throw new Error('Invalid sentry address.')

if (!isEmptyHex(callData)) throw new Error('Missing call data.')

if (isZeroString(callGas)) throw new Error('Missing call gas.')

if (isZeroString(preVerificationGas)) throw new Error('Missing pre-verification gas.')

if (isZeroString(maxFeePerGas)) throw new Error('Missing max fee per gas.')

if (isZeroString(maxPriorityFeePerGas)) throw new Error('Missing max priority fee per gas.')

return this
}

async fillUserOperation(web3: Web3, overrides?: Required<Pick<UserOperation, 'initCode' | 'nonce'>>) {
// from overrides
if (overrides) {
this.userOperation.nonce = overrides.nonce
this.userOperation.initCode = overrides.initCode
}

const {
initCode,
nonce,
sender,
callData,
callGas,
preVerificationGas,
maxFeePerGas,
maxPriorityFeePerGas,
paymaster,
} = this.userOperation
const { initCode, nonce, sender, callData, callGas, preVerificationGas, maxFeePerGas, maxPriorityFeePerGas } =
this.userOperation

// add sender
if (!isEmptyHex(initCode) && !isValidAddress(sender)) {
Expand Down

0 comments on commit cad58c9

Please sign in to comment.