Skip to content

Commit

Permalink
Contracts/garden (#75)
Browse files Browse the repository at this point in the history
* removed resolvers

* added etherscan to foundry and .env
updated rpc urls to alchemy RPC

* added tokenbound constants and interface for registry
created lib for deploying tokenbound accounts on multiple chains

* created garden token and account
added methods for adding gardners and operators to account
created minting method only Green Goods can access

* removed openzeppelin using tokenbound lib
fixed rempaaing issues when building

* imported tokenbound deploy script as template foe deploying rba

* removed action registry being worked on in different branch

* deleted common sol file not needed

* added base test for garden account

* deleted gardener file not needed for now
  • Loading branch information
Oba-One authored Aug 18, 2024
1 parent ccd83ae commit 26620c3
Show file tree
Hide file tree
Showing 20 changed files with 639 additions and 938 deletions.
1 change: 1 addition & 0 deletions packages/contracts/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export API_KEY_ALCHEMY="YOUR_API_KEY_ALCHEMY"
export API_KEY_ARBISCAN="YOUR_API_KEY_ARBISCAN"
export API_KEY_ETHERSCAN="YOUR_API_KEY_ETHERSCAN"
export API_KEY_INFURA="YOUR_API_KEY_INFURA"
export PRIVATE_KEY="YOUR_MNEMONIC"
export FOUNDRY_PROFILE="default"
10 changes: 6 additions & 4 deletions packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test = 'test'
verbosity = 4

[etherscan]
sepolia = { key = "${API_KEY_ETHERSCAN}"}
arbitrum = { key = "${API_KEY_ARBISCAN}" }

[fmt]
Expand All @@ -37,13 +38,14 @@ extra_output_files = [
"abi",
"evm.bytecode"
]

fs_permissions = [{ access = "read", path = "./"}]
eth_rpc_url = "http://localhost:8545"

[profile.arbitrum]
eth_rpc_url = "https://arb1.arbitrum.io/rpc"
[profile.sepolia]
eth_rpc_url = "https://arb-mainnet.g.alchemy.com/v2/i2qnBKk5GQ8pVGPLA-G3D9il5o0ULQO3"

[profile.arbitrum-sepolia]
eth_rpc_url = "https://sepolia-rollup.arbitrum.io/rpc"
[profile.arbitrum]
eth_rpc_url = "https://arb-mainnet.g.alchemy.com/v2/i2qnBKk5GQ8pVGPLA-G3D9il5o0ULQO3"

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
1 change: 0 additions & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"dependencies": {
"@ethereum-attestation-service/eas-contracts": "1.7.1",
"@openzeppelin/contracts": "4.8.3",
"@openzeppelin/contracts-upgradeable": "4.8.3"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ds-test=./node_modules/ds-test/src/
forge-std=./node_modules/forge-std/src/
@openzeppelin/contracts=./node_modules/@openzeppelin/contracts/
@openzeppelin/contracts=lib/tokenbound/lib/openzeppelin-contracts/contracts/
@openzeppelin/contracts-upgradeable=./node_modules/@openzeppelin/contracts-upgradeable/
@eas=./node_modules/@ethereum-attestation-service/eas-contracts/contracts/
@tokenbound=./lib/tokenbound/src/
erc6551/=lib/tokenbound/lib/erc6551/src/
2 changes: 1 addition & 1 deletion packages/contracts/script/Counter.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.21;
pragma solidity ^0.8.25;

import "forge-std/Script.sol";

Expand Down
130 changes: 130 additions & 0 deletions packages/contracts/script/DeployGardenAccount.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// SPDX-License-Identifier: UNLICENSED
/* solhint-disable max-line-length */

pragma solidity ^0.8.25;

import { Script, console } from "forge-std/Script.sol";
import { AccountProxy } from "@tokenbound/AccountProxy.sol";
import { AccountGuardian } from "@tokenbound/AccountGuardian.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { Create2 } from "@openzeppelin/contracts/utils/Create2.sol";

import { GardenToken } from "../src/tokens/Garden.sol";
import { GardenAccount } from "../src/accounts/Garden.sol";
import { TOKENBOUND_REGISTRY } from "../src/Constants.sol";

contract Deploy is Script {
function run() external {
bytes32 salt = 0x6551655165516551655165516551655165516551655165516551655165516551;
address factory = 0x4e59b44847b379578588920cA78FbF26c0B4956C;

address tokenboundSafe = 0x1B9Ac97Ea62f69521A14cbe6F45eb24aD6612C19; // ToDo: Deploy with same address on Sepolia
address erc4337EntryPoint = 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789;
address multicallForwarder = 0xcA11bde05977b3631167028862bE2a173976CA11;

address guardian = Create2.computeAddress(
salt,
keccak256(
abi.encodePacked(type(AccountGuardian).creationCode, abi.encode(tokenboundSafe))
),
factory
);
address implementation = Create2.computeAddress(
salt,
keccak256(
abi.encodePacked(
type(GardenAccount).creationCode,
abi.encode(erc4337EntryPoint, multicallForwarder, TOKENBOUND_REGISTRY, guardian)
)
),
factory
);
address proxy = Create2.computeAddress(
salt,
keccak256(
abi.encodePacked(
type(AccountProxy).creationCode, abi.encode(guardian, implementation)
)
),
factory
);

// Deploy AccountGuardian
if (guardian.code.length == 0) {
vm.startBroadcast();
new AccountGuardian{salt: salt}(tokenboundSafe);
vm.stopBroadcast();

console.log("AccountGuardian:", guardian, "(deployed)");
} else {
console.log("AccountGuardian:", guardian, "(exists)");
}

// Deploy Account implementation
if (implementation.code.length == 0) {
vm.startBroadcast();
new GardenAccount{salt: salt}(
erc4337EntryPoint,
multicallForwarder,
TOKENBOUND_REGISTRY,
guardian
);
vm.stopBroadcast();

console.log("GardenAccount:", implementation, "(deployed)");
} else {
console.log("GardenAccount:", implementation, "(exists)");
}

// Deploy AccountProxy
if (proxy.code.length == 0) {
vm.startBroadcast();
new AccountProxy{salt: salt}(guardian, implementation);
vm.stopBroadcast();

console.log("AccountProxy:", proxy, "(deployed)");
} else {
console.log("AccountProxy:", proxy, "(exists)");
}

console.log("\nVerification Commands:\n");
console.log(
"AccountGuardian: forge verify-contract --num-of-optimizations 200 --chain-id",
block.chainid,
guardian,
string.concat(
"src/AccountGuardian.sol:AccountGuardian --constructor-args $(cast abi-encode \"constructor(address)\" ",
Strings.toHexString(tokenboundSafe),
")\n"
)
);
console.log(
"GardenAccount: forge verify-contract --num-of-optimizations 200 --chain-id",
block.chainid,
implementation,
string.concat(
"src/GardenAccount.sol:GardenAccount --constructor-args $(cast abi-encode \"constructor(address,address,address,address)\" ",
Strings.toHexString(erc4337EntryPoint),
" ",
Strings.toHexString(multicallForwarder),
" ",
Strings.toHexString(TOKENBOUND_REGISTRY),
" ",
Strings.toHexString(guardian),
")\n"
)
);
console.log(
"AccountProxy: forge verify-contract --num-of-optimizations 200 --chain-id",
block.chainid,
proxy,
string.concat(
"src/AccountProxy.sol:AccountProxy --constructor-args $(cast abi-encode \"constructor(address,address)\" ",
Strings.toHexString(guardian),
" ",
Strings.toHexString(implementation),
")\n"
)
);
}
}
177 changes: 0 additions & 177 deletions packages/contracts/script/DeployScript.s.sol

This file was deleted.

Loading

0 comments on commit 26620c3

Please sign in to comment.