mirror of
https://github.com/placeholder-soft/tokenbound.git
synced 2026-04-29 04:15:01 +08:00
Switched to immutable account proxy, modified deploy scripts
This commit is contained in:
@@ -4,19 +4,24 @@ pragma solidity ^0.8.13;
|
||||
import "forge-std/Script.sol";
|
||||
|
||||
import "../src/Account.sol";
|
||||
import "../src/AccountProxy.sol";
|
||||
|
||||
contract DeployAccount is Script {
|
||||
function run() external {
|
||||
uint256 deployerPrivateKey = vm.envUint("TESTNET_ACCOUNT_DEPLOYER");
|
||||
vm.startBroadcast(deployerPrivateKey);
|
||||
|
||||
new Account{
|
||||
Account implementation = new Account{
|
||||
salt: 0x6551655165516551655165516551655165516551655165516551655165516551
|
||||
}(
|
||||
0xB0219b60f0535FB3B62eeEC51EC4C765d138Ac0A, // guardian
|
||||
0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 // entry point
|
||||
);
|
||||
|
||||
new AccountProxy{
|
||||
salt: 0x6551655165516551655165516551655165516551655165516551655165516551
|
||||
}(address(implementation));
|
||||
|
||||
vm.stopBroadcast();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import "../src/AccountGuardian.sol";
|
||||
|
||||
contract DeployGuardian is Script {
|
||||
function run() external {
|
||||
uint256 deployerPrivateKey = vm.envUint("TESTNET_GUARDIAN_DEPLOYER");
|
||||
// DON'T FORGET TO CHANGE DEPLOYER KEY
|
||||
uint256 deployerPrivateKey = vm.envUint("TESTNET_ACCOUNT_DEPLOYER");
|
||||
vm.startBroadcast(deployerPrivateKey);
|
||||
|
||||
new AccountGuardian();
|
||||
|
||||
@@ -39,7 +39,7 @@ contract Account is
|
||||
using ECDSA for bytes32;
|
||||
|
||||
/// @dev ERC-4337 entry point address
|
||||
address immutable _entryPoint;
|
||||
address public immutable _entryPoint;
|
||||
|
||||
/// @dev AccountGuardian contract address
|
||||
address public immutable guardian;
|
||||
|
||||
@@ -5,27 +5,15 @@ import "openzeppelin-contracts/access/Ownable2Step.sol";
|
||||
|
||||
// @dev manages upgrade and cross-chain execution settings for accounts
|
||||
contract AccountGuardian is Ownable2Step {
|
||||
// @dev the default implementation that will be used by all new accounts
|
||||
address public defaultImplementation;
|
||||
|
||||
// @dev mapping from cross-chain executor => is trusted
|
||||
mapping(address => bool) public isTrustedImplementation;
|
||||
|
||||
// @dev mapping from implementation => is trusted
|
||||
mapping(address => bool) public isTrustedExecutor;
|
||||
|
||||
event DefaultImplementationUpdated(address implementation);
|
||||
event TrustedImplementationUpdated(address implementation, bool trusted);
|
||||
event TrustedExecutorUpdated(address executor, bool trusted);
|
||||
|
||||
function setDefaultImplementation(address implementation)
|
||||
external
|
||||
onlyOwner
|
||||
{
|
||||
defaultImplementation = implementation;
|
||||
emit DefaultImplementationUpdated(implementation);
|
||||
}
|
||||
|
||||
function setTrustedImplementation(address implementation, bool trusted)
|
||||
external
|
||||
onlyOwner
|
||||
|
||||
@@ -6,20 +6,18 @@ import "forge-std/console.sol";
|
||||
import "openzeppelin-contracts/proxy/ERC1967/ERC1967Upgrade.sol";
|
||||
import "openzeppelin-contracts/proxy/Proxy.sol";
|
||||
|
||||
import "./interfaces/IAccountGuardian.sol";
|
||||
|
||||
contract AccountProxy is Proxy, ERC1967Upgrade {
|
||||
IAccountGuardian immutable guardian;
|
||||
address immutable defaultImplementation;
|
||||
|
||||
constructor(address _guardian) {
|
||||
guardian = IAccountGuardian(_guardian);
|
||||
constructor(address _defaultImplementation) {
|
||||
defaultImplementation = _defaultImplementation;
|
||||
}
|
||||
|
||||
function initialize() external {
|
||||
address implementation = ERC1967Upgrade._getImplementation();
|
||||
|
||||
if (implementation == address(0)) {
|
||||
ERC1967Upgrade._upgradeTo(guardian.defaultImplementation());
|
||||
ERC1967Upgrade._upgradeTo(defaultImplementation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,9 +33,7 @@ contract AccountTest is Test {
|
||||
entryPoint = new EntryPoint();
|
||||
guardian = new AccountGuardian();
|
||||
implementation = new Account(address(guardian), address(entryPoint));
|
||||
proxy = new AccountProxy(address(guardian));
|
||||
|
||||
guardian.setDefaultImplementation(address(implementation));
|
||||
proxy = new AccountProxy(address(implementation));
|
||||
|
||||
registry = new ERC6551Registry();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user