Skip to content

Commit

Permalink
Gelato using execTransaction for gas metering (#326)
Browse files Browse the repository at this point in the history
This PR converts the gas metering check from using 4337 `EntryPoint
v0.6` to using `execTransaction` directly in Safe.

Package Lock has been updated due to the addition of the Gelato relay
kit package.

Changes:
- Allow execution of Gelato-based transactions in `base-sepolia` as
well.
- Updating gas metering in README's from Gelato based on
`execTransaction`.
- Introduction of abi, address and types files into its location.
- Changing from `userOp` of 4337 to `execTransaction` of Safe for
Gelato-based transactions.
- Installation of Gelato Relay Kit. (Earlier RPC calls were used
directly for `userOps`).
- Additional functions for Gelato-based operations in `safe.ts`
(Creating calldata, init code, etc.).
- Removal of `userOp` related functions of Gelato.

Closes #296
  • Loading branch information
remedcu authored Mar 19, 2024
1 parent 1e96cdc commit 1675523
Show file tree
Hide file tree
Showing 17 changed files with 14,093 additions and 688 deletions.
16 changes: 8 additions & 8 deletions examples/4337-gas-metering/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@ ALCHEMY_ERC20_TOKEN_CONTRACT = "0x255de08fb52fde17a3aab145de8e2ffb7fd0310f"
ALCHEMY_ERC721_TOKEN_CONTRACT = "0x16bc5fba06f3f5875e915c0ba6963377eb6651e1"

# Gelato Values
GELATO_CHAIN = "sepolia"
GELATO_CHAIN_ID = "11155111"
GELATO_RPC_URL = "https://rpc.ankr.com/eth_sepolia"
GELATO_API_KEY = "" # Sponsor API Key
GELATO_GAS_POLICY = ""
GELATO_ENTRYPOINT_ADDRESS = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
GELATO_CHAIN = "base-sepolia" # "base-sepolia" or "sepolia"
GELATO_CHAIN_ID = "84532" # "84532" or "11155111"
GELATO_RPC_URL = "https://rpc.ankr.com/base_sepolia" # "https://rpc.ankr.com/base_sepolia" or "https://rpc.ankr.com/eth_sepolia"
GELATO_API_KEY = "" # Sponsor API Key: https://app.gelato.network/relay?networkGroup=testnets
GELATO_MULTISEND_ADDRESS = "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526" # https://github.com/safe-global/safe-deployments/blob/main/src/assets/v1.4.1/multi_send.json
# Make sure all nonce are unique for it to deploy account when run initially.
GELATO_NONCE = "3"
# Gelato Token Operation Values (Based on the chain selected, these values should also change accordingly.)
GELATO_ERC20_TOKEN_CONTRACT = "0x255de08fb52fde17a3aab145de8e2ffb7fd0310f"
GELATO_ERC721_TOKEN_CONTRACT = "0x16bc5fba06f3f5875e915c0ba6963377eb6651e1"
GELATO_ERC20_TOKEN_CONTRACT = "0x0b3ff6382bd1a8a74f23d39b4d131a08cea2502a"
GELATO_ERC721_TOKEN_CONTRACT = "0xf13eca34092D27cbF91cD377eFB261704C687a05"

# Safe Values
SAFE_VERSION = "1.4.1"
Expand All @@ -55,3 +53,5 @@ SAFE_VERSION = "1.4.1"
# ERC721 Token Sepolia: https://sepolia.etherscan.io/token/0x16bc5fba06f3f5875e915c0ba6963377eb6651e1
# ERC20 Token Mumbai: https://mumbai.polygonscan.com/address/0x255de08fb52fde17a3aab145de8e2ffb7fd0310f
# ERC721 Token Mumbai: https://mumbai.polygonscan.com/address/0x16bc5fba06f3f5875e915c0ba6963377eb6651e1
# ERC20 Token Base Sepolia: https://sepolia.basescan.org/address/0x0b3ff6382bd1a8a74f23d39b4d131a08cea2502a
# ERC721 Token Base Sepolia: https://sepolia.basescan.org/address/0xf13eca34092D27cbF91cD377eFB261704C687a05
28 changes: 8 additions & 20 deletions examples/4337-gas-metering/README.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions examples/4337-gas-metering/alchemy/alchemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { setTimeout } from 'timers/promises'
import { PublicClient, Hash, Transport, createPublicClient, formatEther, http, parseEther, zeroAddress } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { goerli, sepolia } from 'viem/chains'
import { SAFE_ADDRESSES_MAP, getAccountAddress, getAccountInitCode } from '../utils/safe'
import { getAccountAddress, getAccountInitCode } from '../utils/safe'
import { SAFE_ADDRESSES_MAP } from '../utils/address'
import {
UserOperation,
signUserOperation,
Expand Down Expand Up @@ -115,7 +116,7 @@ const initCode = await getAccountInitCode({
console.log('\nInit Code Created.')

const senderAddress = await getAccountAddress({
client: publicClient,
publicClient: publicClient,
owner: signer.address,
addModuleLibAddress: chainAddresses.ADD_MODULES_LIB_ADDRESS,
safe4337ModuleAddress: chainAddresses.SAFE_4337_MODULE_ADDRESS,
Expand Down
Loading

0 comments on commit 1675523

Please sign in to comment.