Skip to content

Commit

Permalink
All tests working after big refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
eloi010 committed Nov 20, 2023
1 parent a1e24d7 commit 043ae2d
Show file tree
Hide file tree
Showing 10 changed files with 4,684 additions and 4,431 deletions.
7 changes: 0 additions & 7 deletions contracts/core/base/BaseRecoverableAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ abstract contract BaseRecoverableAccount is BaseOpenfortAccount, Ownable2StepUpg
emit GuardianAdded(_openfortGuardian);
}

/**
* Return the current EntryPoint
*/
function entryPoint() public view override returns (IEntryPoint) {
return IEntryPoint(entrypointContract);
}

function owner() public view virtual override(BaseOpenfortAccount, OwnableUpgradeable) returns (address) {
return OwnableUpgradeable.owner();
}
Expand Down
9 changes: 1 addition & 8 deletions contracts/core/managed/ManagedOpenfortFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,10 @@ contract ManagedOpenfortFactory is BaseOpenfortFactory, UpgradeableBeacon {
function getAddressWithNonce(address _admin, bytes32 _nonce) public view returns (address) {
bytes32 salt = keccak256(abi.encode(_admin, _nonce));
return Create2.computeAddress(
salt,
keccak256(
abi.encodePacked(
type(OpenfortManagedProxy).creationCode,
abi.encode(address(this), "")
)
)
salt, keccak256(abi.encodePacked(type(OpenfortManagedProxy).creationCode, abi.encode(address(this), "")))
);
}


/**
* @dev {See BaseOpenfortFactory}
*/
Expand Down
15 changes: 9 additions & 6 deletions contracts/core/upgradeable/UpgradeableOpenfortAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/U
* - UUPSUpgradeable
*/
contract UpgradeableOpenfortAccount is BaseRecoverableAccount, UUPSUpgradeable {
event EntryPointUpdated(address oldEntryPoint, address newEntryPoint);

function _authorizeUpgrade(address) internal override onlyOwner {}

function owner() public view virtual override(BaseRecoverableAccount, OwnableUpgradeable) returns (address) {
return OwnableUpgradeable.owner();
function owner() public view virtual override returns (address) {
return super.owner();
}

/**
* Return the current EntryPoint
*/
function entryPoint() public view override returns (IEntryPoint) {
return IEntryPoint(entrypointContract);
}

/**
Expand All @@ -35,6 +40,4 @@ contract UpgradeableOpenfortAccount is BaseRecoverableAccount, UUPSUpgradeable {
emit EntryPointUpdated(entrypointContract, _newEntrypoint);
entrypointContract = _newEntrypoint;
}

function _authorizeUpgrade(address) internal override onlyOwner {}
}
88 changes: 44 additions & 44 deletions script/deployManagedAccounts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@ import {ManagedOpenfortAccount} from "../contracts/core/managed/ManagedOpenfortA
import {ManagedOpenfortFactory} from "../contracts/core/managed/ManagedOpenfortFactory.sol";
// import {MockedV2ManagedOpenfortAccount} from "../contracts/mock/MockedV2ManagedOpenfortAccount.sol";

contract ManagedOpenfortDeploy is Script {
uint256 internal deployPrivKey = vm.deriveKey(vm.envString("MNEMONIC"), 0);
address internal deployAddress = vm.addr(deployPrivKey);
IEntryPoint internal entryPoint = IEntryPoint((payable(vm.envAddress("ENTRY_POINT_ADDRESS"))));

function run() public {
bytes32 versionSalt = vm.envBytes32("VERSION_SALT");
vm.startBroadcast(deployPrivKey);

// Create an acccount to server as implementation
ManagedOpenfortAccount managedOpenfortAccount = new ManagedOpenfortAccount{salt: versionSalt}();

// OpenfortBeacon openfortBeacon = new OpenfortBeacon(address(managedOpenfortAccount)); // not needed anymore

// Create a factory to deploy cloned accounts
ManagedOpenfortFactory managedOpenfortFactory =
new ManagedOpenfortFactory{salt: versionSalt}(deployAddress, address(entryPoint), address(managedOpenfortAccount));
(managedOpenfortFactory);
// address account1 = managedOpenfortFactory.accountImplementation();

// The first call should create a new account, while the second will just return the corresponding account address
// address account2 = managedOpenfortFactory.createAccountWithNonce(deployAddress, "1");
// console.log(
// "Factory at address %s has created an account at address %s", address(managedOpenfortFactory), account2
// );

// MockedV2ManagedOpenfortAccount mockedOpenfortAccount = new MockedV2ManagedOpenfortAccount{salt: versionSalt}();
// (mockedOpenfortAccount);

// assert(account1 != account2);
// address account3 = managedOpenfortFactory.createAccountWithNonce(deployAddress, 3);
// console.log(
// "Factory at address %s has created an account at address %s", address(managedOpenfortFactory), account3
// );
// assert(account2 != account3);
// address account4 = managedOpenfortFactory.createAccountWithNonce(deployAddress, 4);
// console.log(
// "Factory at address %s has created an account at address %s", address(managedOpenfortFactory), account4
// );
// assert(account3 != account4);

vm.stopBroadcast();
}
}
// contract ManagedOpenfortDeploy is Script {
// uint256 internal deployPrivKey = vm.deriveKey(vm.envString("MNEMONIC"), 0);
// address internal deployAddress = vm.addr(deployPrivKey);
// IEntryPoint internal entryPoint = IEntryPoint((payable(vm.envAddress("ENTRY_POINT_ADDRESS"))));

// function run() public {
// bytes32 versionSalt = vm.envBytes32("VERSION_SALT");
// vm.startBroadcast(deployPrivKey);

// // Create an acccount to server as implementation
// ManagedOpenfortAccount managedOpenfortAccount = new ManagedOpenfortAccount{salt: versionSalt}();

// // OpenfortBeacon openfortBeacon = new OpenfortBeacon(address(managedOpenfortAccount)); // not needed anymore

// // Create a factory to deploy cloned accounts
// ManagedOpenfortFactory managedOpenfortFactory =
// new ManagedOpenfortFactory{salt: versionSalt}(deployAddress, address(entryPoint), address(managedOpenfortAccount));
// (managedOpenfortFactory);
// // address account1 = managedOpenfortFactory.accountImplementation();

// // The first call should create a new account, while the second will just return the corresponding account address
// // address account2 = managedOpenfortFactory.createAccountWithNonce(deployAddress, "1");
// // console.log(
// // "Factory at address %s has created an account at address %s", address(managedOpenfortFactory), account2
// // );

// // MockedV2ManagedOpenfortAccount mockedOpenfortAccount = new MockedV2ManagedOpenfortAccount{salt: versionSalt}();
// // (mockedOpenfortAccount);

// // assert(account1 != account2);
// // address account3 = managedOpenfortFactory.createAccountWithNonce(deployAddress, 3);
// // console.log(
// // "Factory at address %s has created an account at address %s", address(managedOpenfortFactory), account3
// // );
// // assert(account2 != account3);
// // address account4 = managedOpenfortFactory.createAccountWithNonce(deployAddress, 4);
// // console.log(
// // "Factory at address %s has created an account at address %s", address(managedOpenfortFactory), account4
// // );
// // assert(account3 != account4);

// vm.stopBroadcast();
// }
// }
94 changes: 47 additions & 47 deletions script/deployUpgradeableAccounts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,50 @@ import {IEntryPoint} from "lib/account-abstraction/contracts/interfaces/IEntryPo
import {UpgradeableOpenfortAccount} from "../contracts/core/upgradeable/UpgradeableOpenfortAccount.sol";
import {UpgradeableOpenfortFactory} from "../contracts/core/upgradeable/UpgradeableOpenfortFactory.sol";

contract UpgradeableOpenfortDeploy is Script {
uint256 internal deployPrivKey = vm.deriveKey(vm.envString("MNEMONIC_MC"), 0);
// uint256 internal deployPrivKey = vm.envUint("PK");
address internal deployAddress = vm.addr(deployPrivKey);
IEntryPoint internal entryPoint = IEntryPoint((payable(vm.envAddress("ENTRY_POINT_ADDRESS"))));

function run() public {
bytes32 versionSalt = vm.envBytes32("VERSION_SALT");
vm.startBroadcast(deployPrivKey);

UpgradeableOpenfortAccount upgradeableOpenfortAccount = new UpgradeableOpenfortAccount{salt: versionSalt}();

UpgradeableOpenfortFactory upgradeableOpenfortFactory =
new UpgradeableOpenfortFactory{salt: versionSalt}(address(entryPoint), address(upgradeableOpenfortAccount));
(upgradeableOpenfortFactory);
// address account1 = upgradeableOpenfortFactory.accountImplementation();

// The first call should create a new account, while the second will just return the corresponding account address
address account2 = upgradeableOpenfortFactory.createAccountWithNonce(deployAddress, "1");
console.log(
"Factory at address %s has created an account at address %s", address(upgradeableOpenfortFactory), account2
);

// assert(account1 != account2);
// address account3 = upgradeableOpenfortFactory.createAccountWithNonce(deployAddress, 3);
// console.log(
// "Factory at address %s has created an account at address %s", address(upgradeableOpenfortFactory), account3
// );
// assert(account2 != account3);
// address account4 = upgradeableOpenfortFactory.createAccountWithNonce(deployAddress, 4);
// console.log(
// "Factory at address %s has created an account at address %s", address(upgradeableOpenfortFactory), account4
// );
// assert(account3 != account4);

//address account3 = upgradeableOpenfortFactory.createAccount(deployAddress, bytes(""));

//assert(account1 != account2);
//assert(account2 == account3);

//UpgradeableOpenfortAccount newAccount = new UpgradeableOpenfortAccount();

//UpgradeableOpenfortAccount(payable(account2)).upgradeTo(address(newAccount));

vm.stopBroadcast();
}
}
// contract UpgradeableOpenfortDeploy is Script {
// uint256 internal deployPrivKey = vm.deriveKey(vm.envString("MNEMONIC_MC"), 0);
// // uint256 internal deployPrivKey = vm.envUint("PK");
// address internal deployAddress = vm.addr(deployPrivKey);
// IEntryPoint internal entryPoint = IEntryPoint((payable(vm.envAddress("ENTRY_POINT_ADDRESS"))));

// function run() public {
// bytes32 versionSalt = vm.envBytes32("VERSION_SALT");
// vm.startBroadcast(deployPrivKey);

// UpgradeableOpenfortAccount upgradeableOpenfortAccount = new UpgradeableOpenfortAccount{salt: versionSalt}();

// UpgradeableOpenfortFactory upgradeableOpenfortFactory =
// new UpgradeableOpenfortFactory{salt: versionSalt}(address(entryPoint), address(upgradeableOpenfortAccount));
// (upgradeableOpenfortFactory);
// // address account1 = upgradeableOpenfortFactory.accountImplementation();

// // The first call should create a new account, while the second will just return the corresponding account address
// address account2 = upgradeableOpenfortFactory.createAccountWithNonce(deployAddress, "1");
// console.log(
// "Factory at address %s has created an account at address %s", address(upgradeableOpenfortFactory), account2
// );

// // assert(account1 != account2);
// // address account3 = upgradeableOpenfortFactory.createAccountWithNonce(deployAddress, 3);
// // console.log(
// // "Factory at address %s has created an account at address %s", address(upgradeableOpenfortFactory), account3
// // );
// // assert(account2 != account3);
// // address account4 = upgradeableOpenfortFactory.createAccountWithNonce(deployAddress, 4);
// // console.log(
// // "Factory at address %s has created an account at address %s", address(upgradeableOpenfortFactory), account4
// // );
// // assert(account3 != account4);

// //address account3 = upgradeableOpenfortFactory.createAccount(deployAddress, bytes(""));

// //assert(account1 != account2);
// //assert(account2 == account3);

// //UpgradeableOpenfortAccount newAccount = new UpgradeableOpenfortAccount();

// //UpgradeableOpenfortAccount(payable(account2)).upgradeTo(address(newAccount));

// vm.stopBroadcast();
// }
// }
Loading

0 comments on commit 043ae2d

Please sign in to comment.