diff --git a/examples/4337-gas-metering/package.json b/examples/4337-gas-metering/package.json index 28b5256e..8c500411 100644 --- a/examples/4337-gas-metering/package.json +++ b/examples/4337-gas-metering/package.json @@ -52,13 +52,14 @@ "@alchemy/aa-accounts": "2.4.0", "@alchemy/aa-alchemy": "2.4.0", "@alchemy/aa-core": "2.3.1", + "@gelatonetwork/relay-sdk": "^5.5.6", "alchemy-sdk": "3.1.2", "dotenv": "16.4.5", + "ethers": "^6.12.1", "permissionless": "0.1.29", "viem": "2.10.8" }, "devDependencies": { - "@gelatonetwork/relay-sdk": "^5.5.6", "@types/node": "20.12.12", "tsx": "4.10.3", "typescript": "^5.4.5" diff --git a/examples/4337-gas-metering/pimlico/README.md b/examples/4337-gas-metering/pimlico/README.md index 52b3229f..8c8fe260 100644 --- a/examples/4337-gas-metering/pimlico/README.md +++ b/examples/4337-gas-metering/pimlico/README.md @@ -3,7 +3,7 @@ ## Safe Deployment With Pimlico (No Paymaster) ``` -npm run pimlico:account +pnpm run pimlico:account > @safe-global/safe-modules-example-4337-gas-metering@1.0.0 pimlico:account > tsx ./pimlico/pimlico.ts account @@ -12,8 +12,8 @@ Signer Extracted from Private Key. Init Code Created. -Counterfactual Sender Address Created: 0x967c56B4Bc5628Fd275b3d466Cc075BeB33Fc7Fc -Address Link: https://sepolia.etherscan.io/address/0x967c56B4Bc5628Fd275b3d466Cc075BeB33Fc7Fc +Counterfactual Sender Address Created: 0x90BFbCEf51C6b170D309C0A80B6062ffDfc8FbB8 +Address Link: https://sepolia.etherscan.io/address/0x90BFbCEf51C6b170D309C0A80B6062ffDfc8FbB8 Deploying a new Safe and executing calldata passed with it (if any). @@ -23,17 +23,17 @@ Appropriate calldata created. Sender ETH Balance: 0.0 -Required Prefund: 0.065434566830611091 -UserOperation submitted. Hash: 0x4d02a5c5b7f78843e392a0ba7ab3abc23e34ebcf9dbb89bcb48112805806d15a -UserOp Link: https://jiffyscan.xyz/userOpHash/0x4d02a5c5b7f78843e392a0ba7ab3abc23e34ebcf9dbb89bcb48112805806d15a?network=sepolia +Required Prefund: 0.071222563201076969 +UserOperation submitted. Hash: 0x1a2644dfcb8ba01986faf3fb7b6adde6945e7aa2410405541032a312071e6f8a +UserOp Link: https://jiffyscan.xyz/userOpHash/0x1a2644dfcb8ba01986faf3fb7b6adde6945e7aa2410405541032a312071e6f8a?network=sepolia Querying for receipts... Receipt found! -Transaction hash: 0x09c9cad7d6a4fe405531e132f3e53e02599a7a379f33fc3378d75a80ae80ef7f -Transaction Link: https://sepolia.etherscan.io/tx/0x09c9cad7d6a4fe405531e132f3e53e02599a7a379f33fc3378d75a80ae80ef7f +Transaction hash: 0xe3656d4b26c17871350e3c589d6afee340c538cfd4636c68dedd76706dbd08fd +Transaction Link: https://sepolia.etherscan.io/tx/0xe3656d4b26c17871350e3c589d6afee340c538cfd4636c68dedd76706dbd08fd -Gas Used (Account or Paymaster): 433672 -Gas Used (Transaction): 419491 +Gas Used (Account or Paymaster): 423757 +Gas Used (Transaction): 409872 ``` diff --git a/examples/4337-gas-metering/pimlico/pimlico.ts b/examples/4337-gas-metering/pimlico/pimlico.ts index 3c1ecf28..3a247ee8 100644 --- a/examples/4337-gas-metering/pimlico/pimlico.ts +++ b/examples/4337-gas-metering/pimlico/pimlico.ts @@ -3,7 +3,7 @@ import { ethers } from 'ethers' import { getAccountNonce, bundlerActions, ENTRYPOINT_ADDRESS_V07, getRequiredPrefund } from 'permissionless' import { pimlicoBundlerActions, pimlicoPaymasterActions } from 'permissionless/actions/pimlico' import { setTimeout } from 'timers/promises' -import { Client, Hash, createClient, createPublicClient, http, parseEther } from 'viem' +import { Client, Hash, createClient, createPublicClient, http, parseEther, zeroAddress } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { baseSepolia, sepolia } from 'viem/chains' import { getAccountAddress, getAccountInitCode } from '../utils/safe' @@ -44,15 +44,14 @@ const erc721TokenAddress = process.env.PIMLICO_ERC721_TOKEN_CONTRACT as `0x${str // Detecting Paymaster based transaction or not. const argv = process.argv.slice(2) -let usePaymaster!: boolean +let usePaymaster = false if (argv.length < 1 || argv.length > 2) { throw new Error('TX Type Argument not passed.') } else if (argv.length == 2 && argv[1] == 'paymaster=true') { if (policyID) { usePaymaster = true } else { - // throw new Error('Paymaster requires policyID to be set.') - usePaymaster = true + throw new Error('Paymaster requires policyID to be set.') } } @@ -114,8 +113,8 @@ const initCode = await getAccountInitCode({ safeSingletonAddress: chainAddresses.SAFE_SINGLETON_ADDRESS, saltNonce: saltNonce, multiSendAddress: multiSendAddress, - erc20TokenAddress: usdcTokenAddress, - paymasterAddress: erc20PaymasterAddress, + erc20TokenAddress: usePaymaster ? usdcTokenAddress : zeroAddress, + paymasterAddress: usePaymaster ? erc20PaymasterAddress : zeroAddress, }) console.log('\nInit Code Created.') @@ -129,8 +128,8 @@ const senderAddress = await getAccountAddress({ safeSingletonAddress: chainAddresses.SAFE_SINGLETON_ADDRESS, saltNonce: saltNonce, multiSendAddress: multiSendAddress, - erc20TokenAddress: usdcTokenAddress, - paymasterAddress: erc20PaymasterAddress, + erc20TokenAddress: usePaymaster ? usdcTokenAddress : zeroAddress, + paymasterAddress: usePaymaster ? erc20PaymasterAddress : zeroAddress, }) console.log('\nCounterfactual Sender Address Created:', senderAddress) if (chain == 'base-sepolia') { @@ -234,11 +233,11 @@ if (usePaymaster) { // Check Sender ETH Balance. let senderETHBalance = await publicClient.getBalance({ address: senderAddress }) - console.log('\nSender ETH Balance:', ethers.utils.formatEther(senderETHBalance)) + console.log('\nSender ETH Balance:', ethers.formatEther(senderETHBalance)) // Checking required preFund. const requiredPrefund = getRequiredPrefund({ userOperation: userOp, entryPoint: ENTRYPOINT_ADDRESS_V07 }) - console.log('\nRequired Prefund:', ethers.utils.formatEther(requiredPrefund)) + console.log('\nRequired Prefund:', ethers.formatEther(requiredPrefund)) const requiredBalance = requiredPrefund + (txType == 'native-transfer' ? parseEther('0.000001') : 0n) diff --git a/examples/4337-gas-metering/utils/safe.ts b/examples/4337-gas-metering/utils/safe.ts index 26d8bab0..92544eaa 100644 --- a/examples/4337-gas-metering/utils/safe.ts +++ b/examples/4337-gas-metering/utils/safe.ts @@ -164,12 +164,13 @@ const getInitializerCode = async ({ }) } - const multiSendCallData = encodeMultiSend(setupTxs) + const recipient = setupTxs.length > 1 ? multiSendAddress : safeModuleSetupAddress + const calldata = setupTxs.length > 1 ? encodeMultiSend(setupTxs) : setupTxs[0].data return encodeFunctionData({ abi: SAFE_SETUP_ABI, functionName: 'setup', - args: [[owner], 1n, multiSendAddress, multiSendCallData, safe4337ModuleAddress, zeroAddress, 0n, zeroAddress], + args: [[owner], 1n, recipient, calldata, safe4337ModuleAddress, zeroAddress, 0n, zeroAddress], }) } diff --git a/examples/4337-gas-metering/utils/userOps.ts b/examples/4337-gas-metering/utils/userOps.ts index 4f30f803..51a39fbc 100644 --- a/examples/4337-gas-metering/utils/userOps.ts +++ b/examples/4337-gas-metering/utils/userOps.ts @@ -412,6 +412,7 @@ export const createCallData = async ( value: weiToSend, }) } + console.log('\nAppropriate calldata created.') return txCallData } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3753c5ee..2d82567d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,12 +56,18 @@ importers: '@alchemy/aa-core': specifier: 2.3.1 version: 2.3.1(bufferutil@4.0.8)(typescript@5.4.5)(utf-8-validate@5.0.10) + '@gelatonetwork/relay-sdk': + specifier: ^5.5.6 + version: 5.5.6(bufferutil@4.0.8)(utf-8-validate@5.0.10) alchemy-sdk: specifier: 3.1.2 version: 3.1.2(bufferutil@4.0.8)(utf-8-validate@5.0.10) dotenv: specifier: 16.4.5 version: 16.4.5 + ethers: + specifier: ^6.12.1 + version: 6.12.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) permissionless: specifier: 0.1.29 version: 0.1.29(viem@2.10.8(bufferutil@4.0.8)(typescript@5.4.5)(utf-8-validate@5.0.10)(zod@3.23.8)) @@ -69,9 +75,6 @@ importers: specifier: 2.10.8 version: 2.10.8(bufferutil@4.0.8)(typescript@5.4.5)(utf-8-validate@5.0.10)(zod@3.23.8) devDependencies: - '@gelatonetwork/relay-sdk': - specifier: ^5.5.6 - version: 5.5.6(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@types/node': specifier: 20.12.12 version: 20.12.12 @@ -6103,7 +6106,7 @@ snapshots: '@scure/bip32@1.3.2': dependencies: '@noble/curves': 1.2.0 - '@noble/hashes': 1.3.2 + '@noble/hashes': 1.3.3 '@scure/base': 1.1.6 '@scure/bip32@1.3.3': @@ -6119,7 +6122,7 @@ snapshots: '@scure/bip39@1.2.1': dependencies: - '@noble/hashes': 1.3.2 + '@noble/hashes': 1.3.3 '@scure/base': 1.1.6 '@scure/bip39@1.2.2':