Skip to content

Commit 2f2e795

Browse files
committed
First Commit
1 parent 8ce6b1a commit 2f2e795

File tree

13 files changed

+445
-124
lines changed

13 files changed

+445
-124
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
[submodule "lib/forge-std"]
22
path = lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/account-abstraction"]
5+
path = lib/account-abstraction
6+
url = https://github.com/eth-infinitism/account-abstraction
7+
[submodule "lib/openzeppelin-contracts"]
8+
path = lib/openzeppelin-contracts
9+
url = https://github.com/openzeppelin/openzeppelin-contracts

README.md

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +0,0 @@
1-
## Foundry
2-
3-
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
4-
5-
Foundry consists of:
6-
7-
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
8-
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
9-
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
10-
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
11-
12-
## Documentation
13-
14-
https://book.getfoundry.sh/
15-
16-
## Usage
17-
18-
### Build
19-
20-
```shell
21-
$ forge build
22-
```
23-
24-
### Test
25-
26-
```shell
27-
$ forge test
28-
```
29-
30-
### Format
31-
32-
```shell
33-
$ forge fmt
34-
```
35-
36-
### Gas Snapshots
37-
38-
```shell
39-
$ forge snapshot
40-
```
41-
42-
### Anvil
43-
44-
```shell
45-
$ anvil
46-
```
47-
48-
### Deploy
49-
50-
```shell
51-
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
52-
```
53-
54-
### Cast
55-
56-
```shell
57-
$ cast <subcommand>
58-
```
59-
60-
### Help
61-
62-
```shell
63-
$ forge --help
64-
$ anvil --help
65-
$ cast --help
66-
```

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
src = "src"
33
out = "out"
44
libs = ["lib"]
5-
5+
remappings=["@openzeppelin/contracts=lib/openzeppelin-contracts/contracts"]
66
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

lib/account-abstraction

Submodule account-abstraction added at 7af70c8

lib/openzeppelin-contracts

Submodule openzeppelin-contracts added at acd4ff7

script/Counter.s.sol

Lines changed: 0 additions & 19 deletions
This file was deleted.

script/DeployMinimal.s.sol

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
2+
pragma solidity ^0.8.28;
3+
4+
import {Script, console} from "forge-std/Script.sol";
5+
import {MinimalAccount} from "./../src/Ethereum/Minimal-Account.sol";
6+
import {HelperConfig} from "./HelperConfig.s.sol";
7+
8+
contract DeployMinimal is Script {
9+
function run() public {}
10+
11+
function deployMinimalAccount()
12+
public
13+
returns (HelperConfig, MinimalAccount)
14+
{
15+
HelperConfig helperConfig = new HelperConfig();
16+
HelperConfig.NetworkConfig memory config = helperConfig.getConfig();
17+
18+
// console.log("This is the fucking cause: ", config.account);
19+
20+
vm.startBroadcast(config.account);
21+
22+
MinimalAccount minimalAccount = new MinimalAccount(config.entryPoint);
23+
24+
// console.log("This is the msg.sender", msg.sender);
25+
minimalAccount.transferOwnership(config.account);
26+
27+
vm.stopBroadcast();
28+
29+
return (helperConfig, minimalAccount);
30+
}
31+
}

script/HelperConfig.s.sol

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
2+
pragma solidity ^0.8.28;
3+
4+
import {Script, console, console2} from "forge-std/Script.sol";
5+
import {EntryPoint} from "lib/account-abstraction/contracts/core/EntryPoint.sol";
6+
7+
contract HelperConfig is Script {
8+
error HelperConfig__InvalidChainId();
9+
10+
struct NetworkConfig {
11+
address entryPoint;
12+
address account;
13+
}
14+
15+
uint256 constant AMOY = 80002;
16+
uint256 constant ZK = 300;
17+
uint256 constant LOCAL = 31337;
18+
19+
address constant BURNER_WALLET = 0x4910A3E9f7d9A04eEed15093F33f9Ec26d480F2D;
20+
// address constant FOUNDRY_DEFAULT_WALLET =
21+
// 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38;
22+
23+
address constant ANVIL_DEFAULT_ACCOUNT =
24+
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
25+
26+
NetworkConfig public localNetworkConfig;
27+
mapping(uint256 chainId => NetworkConfig) public networkConfigs;
28+
29+
constructor() {
30+
networkConfigs[AMOY] = getAMOYConfig();
31+
}
32+
33+
function getConfig() public returns (NetworkConfig memory) {
34+
return getConfigByChainId(block.chainid);
35+
}
36+
37+
function getConfigByChainId(
38+
uint256 chainId
39+
) public returns (NetworkConfig memory) {
40+
if (chainId == LOCAL) {
41+
return getOrCreateAnvilEthConfig();
42+
} else if (networkConfigs[chainId].account != address(0)) {
43+
return networkConfigs[chainId];
44+
} else {
45+
revert HelperConfig__InvalidChainId();
46+
}
47+
}
48+
49+
function getAMOYConfig() public pure returns (NetworkConfig memory) {
50+
return
51+
NetworkConfig({
52+
entryPoint: 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789,
53+
account: BURNER_WALLET
54+
});
55+
}
56+
57+
function ZKConfig() public pure returns (NetworkConfig memory) {
58+
return NetworkConfig({entryPoint: address(0), account: BURNER_WALLET});
59+
}
60+
61+
function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) {
62+
if (localNetworkConfig.account == address(0)) {
63+
console2.log("Deploying Mocks...");
64+
65+
// vm.startBroadcast(FOUNDRY_DEFAULT_WALLET);
66+
vm.startBroadcast(ANVIL_DEFAULT_ACCOUNT);
67+
EntryPoint entryPoint = new EntryPoint();
68+
vm.stopBroadcast();
69+
70+
localNetworkConfig = NetworkConfig({
71+
entryPoint: address(entryPoint),
72+
// account: FOUNDRY_DEFAULT_WALLET
73+
account: ANVIL_DEFAULT_ACCOUNT
74+
});
75+
76+
console2.log(localNetworkConfig.entryPoint);
77+
}
78+
79+
return localNetworkConfig;
80+
}
81+
}

script/SendPackedUserOp.s.sol

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.28;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {MinimalAccount} from "./../src/Ethereum/Minimal-Account.sol";
6+
import {PackedUserOperation} from "lib/account-abstraction/contracts/interfaces/PackedUserOperation.sol";
7+
import {HelperConfig} from "script/HelperConfig.s.sol";
8+
import {IEntryPoint} from "lib/account-abstraction/contracts/interfaces/IEntryPoint.sol";
9+
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
10+
11+
contract SendPackedUserOp is Script {
12+
using MessageHashUtils for bytes32;
13+
14+
function run() public {}
15+
16+
function generateSignedUserOperation(
17+
bytes memory callData,
18+
HelperConfig.NetworkConfig memory config
19+
) public view returns (PackedUserOperation memory, bytes32) {
20+
// 1 . Generate the unsigned data
21+
uint256 nonce = vm.getNonce(config.account);
22+
PackedUserOperation memory userOp = _generateUnsignedUserOperation(
23+
callData,
24+
config.account,
25+
nonce
26+
);
27+
// 2. Get the userOpHash
28+
bytes32 userOpHash = IEntryPoint(config.entryPoint).getUserOpHash(
29+
userOp
30+
);
31+
32+
bytes32 digest = userOpHash.toEthSignedMessageHash();
33+
34+
uint8 v;
35+
bytes32 r;
36+
bytes32 s;
37+
38+
uint256 ANVIL_DEFAULT_KEY = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;
39+
if (block.chainid == 31337) {
40+
(v, r, s) = vm.sign(ANVIL_DEFAULT_KEY, digest);
41+
} else {
42+
// 3. Sign it and return it
43+
(v, r, s) = vm.sign(config.account, digest);
44+
userOp.signature = abi.encodePacked(r, s, v); // Note the order
45+
}
46+
47+
return (userOp, digest);
48+
}
49+
50+
/*
51+
struct PackedUserOperation {
52+
address sender;
53+
uint256 nonce;
54+
bytes initCode;
55+
bytes callData;
56+
bytes32 accountGasLimits;
57+
uint256 preVerificationGas;
58+
bytes32 gasFees;
59+
bytes paymasterAndData; // if paymaster is setUp we will send
60+
bytes signature;
61+
}
62+
*/
63+
64+
function _generateUnsignedUserOperation(
65+
bytes memory callData,
66+
address sender,
67+
uint256 nonce
68+
) internal pure returns (PackedUserOperation memory) {
69+
uint128 verificationGasLimit = 16777216;
70+
uint128 callGasLimit = verificationGasLimit;
71+
72+
uint128 maxPriorityFeePerGas = 256;
73+
uint128 maxFeePerGas = maxPriorityFeePerGas;
74+
return
75+
PackedUserOperation({
76+
sender: sender,
77+
nonce: nonce,
78+
initCode: hex"",
79+
callData: callData,
80+
accountGasLimits: bytes32(
81+
(uint256(verificationGasLimit) << 128) | callGasLimit
82+
),
83+
preVerificationGas: verificationGasLimit,
84+
gasFees: bytes32(
85+
(uint256(maxPriorityFeePerGas) << 128) | maxFeePerGas
86+
),
87+
paymasterAndData: hex"",
88+
signature: hex""
89+
});
90+
}
91+
}

src/Counter.sol

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)