Skip to content

Commit

Permalink
Merge branch 'main' of github.com:safe-global/safe-modules into 288-i…
Browse files Browse the repository at this point in the history
…mplement-a-passkey-signaturevalidator-factory
  • Loading branch information
mmv08 committed Mar 5, 2024
2 parents 2116f6d + f03be94 commit 56a7060
Show file tree
Hide file tree
Showing 75 changed files with 2,685 additions and 580 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci_4337_gas_metering.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
paths:
- 'modules/4337/**'
- 'modules/4337-gas-metering/**'
- 'examples/4337-gas-metering/**'

jobs:
checks:
Expand All @@ -16,6 +16,6 @@ jobs:
cache: npm
cache-dependency-path: package-lock.json
- run: npm ci
- run: npm run fmt:check -w modules/4337-gas-metering
- run: npm run lint -w modules/4337-gas-metering
- run: npm run build -w modules/4337-gas-metering
- run: npm run fmt:check -w examples/4337-gas-metering
- run: npm run lint -w examples/4337-gas-metering
- run: npm run build -w examples/4337-gas-metering
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: safe-modules-examples
on: [push]
name: safe-modules-4337-passkey-example
on:
push:
paths:
- 'modules/4337/**'
- 'modules/passkey/**'
- 'examples/safe-4337-passkeys/**'

jobs:
checks:
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
modules/**
examples/**
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions examples/4337-gas-metering/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NOTE: If you run a paymaster analysis twice or more without changing the salt fo

| | **With 4337?** | **Account Creation** | **Account Creation + Native Transfer** | **Native Transfer** | **Account Creation + ERC20 Transfer** | **ERC20 Transfer** | **Account Creation + ERC721 Minting** | **ERC721 Minting** |
| :---------------------------------------------------: | :------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| **[Without Paymaster](../4337/test/gas/Gas.spec.ts)** | Yes | 359756 | 364687 | 88471 | 370661 | 94445 | 412448 | 136232 |
| **[Without Paymaster](../4337/test/gas/Gas.spec.ts)** | Yes | 415213 | 447632 | 182081 | 426139 | 160575 | 467926 | 202374 |
| **Gelato (4337 Compatible - 1Balance)** | Yes | 397421 ([TX](https://sepolia.etherscan.io/tx/0x21205216b55d0f48aa09ff4289ae982c3b16e7a9905494815cabd1fb01a0d505)) ([Gas](https://dashboard.tenderly.co/tx/sepolia/0x21205216b55d0f48aa09ff4289ae982c3b16e7a9905494815cabd1fb01a0d505/gas-usage)) | 404828 ([TX](https://sepolia.etherscan.io/tx/0x7bb36c93d21c911a2c1bdc7e50f55030cc7f006a1f7e2e651251dca9651383e0)) ([Gas](https://dashboard.tenderly.co/tx/sepolia/0x7bb36c93d21c911a2c1bdc7e50f55030cc7f006a1f7e2e651251dca9651383e0/gas-usage)) | 114692 ([TX](https://sepolia.etherscan.io/tx/0xefa122224466e9f1d09d42683aaec2b37f9871f7f5569099f0cc066961b39f15)) ([Gas](https://dashboard.tenderly.co/tx/sepolia/0xefa122224466e9f1d09d42683aaec2b37f9871f7f5569099f0cc066961b39f15/gas-usage)) | 408160 ([TX](https://sepolia.etherscan.io/tx/0x4f55488ecc542be4effc2d7a4743345db6790ef80e7ca94f3e939a290738fa2d)) ([Gas](https://dashboard.tenderly.co/tx/sepolia/0x4f55488ecc542be4effc2d7a4743345db6790ef80e7ca94f3e939a290738fa2d/gas-usage)) | 118033 ([TX](https://sepolia.etherscan.io/tx/0x152c78871b6940215ba37cac5f5231fa2bd4bcf40742ebcf741903ce64adc405)) ([Gas](https://dashboard.tenderly.co/tx/sepolia/0x152c78871b6940215ba37cac5f5231fa2bd4bcf40742ebcf741903ce64adc405/gas-usage)) | 437372 ([TX](https://sepolia.etherscan.io/tx/0x4aa37845d5c9fc0ad0713caefbbc9931263040d1502f076a98c993282257e51d)) ([Gas](https://dashboard.tenderly.co/tx/sepolia/0x4aa37845d5c9fc0ad0713caefbbc9931263040d1502f076a98c993282257e51d/gas-usage)) | 147232 ([TX](https://sepolia.etherscan.io/tx/0xfac73b16d0932ba97a93f12ddc230024b102e581a37a53625dfe8108ca581bb5)) ([Gas](https://dashboard.tenderly.co/tx/sepolia/0xfac73b16d0932ba97a93f12ddc230024b102e581a37a53625dfe8108ca581bb5/gas-usage)) |
| **Pimlico (USDC Paymaster)** | Yes | 506573 ([TX](https://mumbai.polygonscan.com/tx/0x3c6284e4df1686d699d2bc4cca04a25ecc76d68a73665ca53d466e6bd6bedf28)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0x3c6284e4df1686d699d2bc4cca04a25ecc76d68a73665ca53d466e6bd6bedf28/gas-usage)) | 511055 ([TX](https://mumbai.polygonscan.com/tx/0x8bc4e42b076d22e0fc3418eba40c65caab6e3a10c1fbb10cbeee4a7fbfa8b4b3)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0x8bc4e42b076d22e0fc3418eba40c65caab6e3a10c1fbb10cbeee4a7fbfa8b4b3/gas-usage)) | 199262 ([TX](https://mumbai.polygonscan.com/tx/0x46cdfc14649087609f69411fc41f5feb4dc23a6ea9255928b932841858e5f186)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0x46cdfc14649087609f69411fc41f5feb4dc23a6ea9255928b932841858e5f186/gas-usage)) | 514156 ([TX](https://mumbai.polygonscan.com/tx/0xa5cf461800341c2e9934608ff55aeda26d1a3e7da4f5bc9f3cce3fd185409623)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0xa5cf461800341c2e9934608ff55aeda26d1a3e7da4f5bc9f3cce3fd185409623/gas-usage)) | 202387 ([TX](https://mumbai.polygonscan.com/tx/0xdc21ae13dc92eb48851fa62f57c74f3a0085acf81343d9aaaa14fcc3c6911f91)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0xdc21ae13dc92eb48851fa62f57c74f3a0085acf81343d9aaaa14fcc3c6911f91/gas-usage)) | 543411 ([TX](https://mumbai.polygonscan.com/tx/0xcd6c137474be4f002822498e032ad9b78b0505bd4db495ee65fc602ec1a7f006)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0xcd6c137474be4f002822498e032ad9b78b0505bd4db495ee65fc602ec1a7f006/gas-usage)) | 231619 ([TX](https://mumbai.polygonscan.com/tx/0x31732175d3f3b35c9c2a38e841bcd485085edf79e7f3c532ec7997c4993c0192)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0x31732175d3f3b35c9c2a38e841bcd485085edf79e7f3c532ec7997c4993c0192/gas-usage)) |
| **Pimlico (MATIC - Gas Policy)** | Yes | 448172 ([TX](https://mumbai.polygonscan.com/tx/0xd51d026ecfa6dbafa8aac8a138badc6e3b397683117878e360bae9051a3b733a)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0xd51d026ecfa6dbafa8aac8a138badc6e3b397683117878e360bae9051a3b733a/gas-usage)) | 455615 ([TX](https://mumbai.polygonscan.com/tx/0xdd966b95b6625be33ae37f6c5bb1ad33798afbbd899089acad1180005d0637c4)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0xdd966b95b6625be33ae37f6c5bb1ad33798afbbd899089acad1180005d0637c4/gas-usage)) | 123064 ([TX](https://mumbai.polygonscan.com/tx/0xca2e41e24c6206011fe0d932f27a2786c7d9486c93f63d96c131c5007e2b275e)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0xca2e41e24c6206011fe0d932f27a2786c7d9486c93f63d96c131c5007e2b275e/gas-usage)) | 459014 ([TX](https://mumbai.polygonscan.com/tx/0xbd4c79d876ae928bbc721501029b01dbc5fc94d91d6299f548f19289f7c1c271)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0xbd4c79d876ae928bbc721501029b01dbc5fc94d91d6299f548f19289f7c1c271/gas-usage)) | 126461 ([TX](https://mumbai.polygonscan.com/tx/0xd2b130bc2f26cfe43041f7102601425674e2cd22a6b74672b907b28e70686496)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0xd2b130bc2f26cfe43041f7102601425674e2cd22a6b74672b907b28e70686496/gas-usage)) | 488186 ([TX](https://mumbai.polygonscan.com/tx/0x454a3a5a39432f7b01a70fcddfef948d20c70d2d719aea30d402d693447fa535)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0x454a3a5a39432f7b01a70fcddfef948d20c70d2d719aea30d402d693447fa535/gas-usage)) | 155645 ([TX](https://mumbai.polygonscan.com/tx/0xa148a4938de9883b2fbcd512e3c7161e78ca695843b6e535fdb5054b88872652)) ([Gas](https://dashboard.tenderly.co/tx/mumbai/0xa148a4938de9883b2fbcd512e3c7161e78ca695843b6e535fdb5054b88872652/gas-usage)) |
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"outDir": "./dist" /* Redirect output structure to the directory. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
},
"exclude": ["node_modules"]
"exclude": ["node_modules"],
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/safe-4337-passkeys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@web3modal/ethers": "^4.0.5",
"@safe-global/safe-erc4337": "^0.2.0",
"@safe-global/safe-erc4337": "^0.3.0",
"ethers": "^6.11.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
12 changes: 6 additions & 6 deletions examples/safe-4337-passkeys/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ConnectButton from './components/ConnectButton.tsx'
import { useState } from 'react'
import { useWeb3ModalProvider, useWeb3ModalAccount } from '@web3modal/ethers/react'
import { APP_CHAIN_ID } from './config.ts'
import { switchToMumbai } from './logic/wallets.ts'
import { switchToSepolia } from './logic/wallets.ts'
import { PasskeyCard } from './components/PasskeyCard.tsx'
import { SafeCard } from './components/SafeCard.tsx'

Expand Down Expand Up @@ -34,17 +34,17 @@ function App() {
}
}

const handleSwitchToMumbaiClick = () => {
const handleSwitchToSepoliaClick = () => {
if (!walletProvider) return

setError(undefined)
try {
switchToMumbai(walletProvider)
switchToSepolia(walletProvider)
} catch (error) {
if (error instanceof Error) {
setError(error.message)
} else {
setError('Unknown error when switching to Mumbai network')
setError('Unknown error when switching to Ethereum Sepolia test network')
}
}
}
Expand Down Expand Up @@ -72,8 +72,8 @@ function App() {
if (connectedToWrongChain) {
content = (
<div className="card">
<p>Please switch to Mumbai network to continue</p>
<button onClick={handleSwitchToMumbaiClick}>Switch to Mumbai</button>
<p>Please switch to Ethereum Sepolia test network to continue</p>
<button onClick={handleSwitchToSepoliaClick}>Switch to Sepolia</button>
</div>
)
}
Expand Down
32 changes: 20 additions & 12 deletions examples/safe-4337-passkeys/src/components/SafeCard.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { useMemo, useState } from 'react'
import { ethers } from 'ethers'
import { encodeAddModuleLibCall } from '../logic/safe'
import { encodeSafeModuleSetupCall } from '../logic/safe'
import type { SafeInitializer } from '../logic/safe'
import {
ADD_MODULES_LIB_ADDRESS,
SAFE_4337_MODULE_ADDRESS,
SAFE_MODULE_SETUP_ADDRESS,
SAFE_PROXY_FACTORY_ADDRESS,
SAFE_SINGLETON_ADDRESS,
WEBAUTHN_SIGNER_FACTORY_ADDRESS,
WEBAUTHN_VERIFIER_ADDRESS,
} from '../config'
import { PasskeyLocalStorageFormat } from '../logic/passkeys'
import { UnsignedUserOperation, getRequiredPrefund, prepareUserOperationWithInitialisation, signAndSendUserOp } from '../logic/userOp'
import {
UnsignedPackedUserOperation,
getRequiredPrefund,
packGasParameters,
prepareUserOperationWithInitialisation,
signAndSendUserOp,
} from '../logic/userOp'
import { useUserOpGasLimitEstimation } from '../hooks/useUserOpGasEstimation'
import { RequestStatus } from '../utils'
import { PrefundCard } from './OpPrefundCard'
Expand All @@ -29,8 +35,8 @@ function SafeCard({ passkey, provider }: { passkey: PasskeyLocalStorageFormat; p
['uint256', 'uint256', 'address'],
[passkey.pubkeyCoordinates.x, passkey.pubkeyCoordinates.y, WEBAUTHN_VERIFIER_ADDRESS],
),
setupTo: ADD_MODULES_LIB_ADDRESS,
setupData: encodeAddModuleLibCall([SAFE_4337_MODULE_ADDRESS]),
setupTo: SAFE_MODULE_SETUP_ADDRESS,
setupData: encodeSafeModuleSetupCall([SAFE_4337_MODULE_ADDRESS]),
}),
[passkey.pubkeyCoordinates.x, passkey.pubkeyCoordinates.y],
)
Expand Down Expand Up @@ -64,13 +70,15 @@ function SafeCard({ passkey, provider }: { passkey: PasskeyLocalStorageFormat; p
const handleDeploySafeClick = async () => {
if (!gasParametersReady) return

const userOpToSign: UnsignedUserOperation = {
const userOpToSign: UnsignedPackedUserOperation = {
...unsignedUserOperation,
verificationGasLimit: userOpGasLimitEstimation.verificationGasLimit,
...packGasParameters({
verificationGasLimit: userOpGasLimitEstimation.verificationGasLimit,
callGasLimit: userOpGasLimitEstimation.callGasLimit,
maxPriorityFeePerGas: feeData?.maxPriorityFeePerGas,
maxFeePerGas: feeData?.maxFeePerGas,
}),
preVerificationGas: userOpGasLimitEstimation.preVerificationGas,
callGasLimit: userOpGasLimitEstimation.callGasLimit,
maxFeePerGas: '0x' + feeData?.maxFeePerGas.toString(16),
maxPriorityFeePerGas: '0x' + feeData?.maxPriorityFeePerGas.toString(16),
}

const bundlerUserOpHash = await signAndSendUserOp(userOpToSign, passkey)
Expand All @@ -84,14 +92,14 @@ function SafeCard({ passkey, provider }: { passkey: PasskeyLocalStorageFormat; p
{userOpHash && (
<p>
Your Safe is being deployed. Track the user operation on{' '}
<a href={`https://jiffyscan.xyz/userOpHash/${userOpHash}?network=mumbai`}>jiffyscan</a>
<a href={`https://jiffyscan.xyz/userOpHash/${userOpHash}?network=sepolia`}>jiffyscan</a>
</p>
)}

{deployed && (
<p>
Your Safe has been deployed. More info on{' '}
<a href={`https://jiffyscan.xyz/account/${unsignedUserOperation.sender}?network=mumbai`}>jiffyscan</a>
<a href={`https://jiffyscan.xyz/account/${unsignedUserOperation.sender}?network=sepolia`}>jiffyscan</a>
</p>
)}

Expand Down
Loading

0 comments on commit 56a7060

Please sign in to comment.