Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure owner is assigned correctly when created by an EOA #24

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions script/test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ contract KintoDeployTestCounter is AASetup, KYCSignature, UserOp {
address computed =
_walletFactory.getContractAddress(bytes32(0), keccak256(abi.encodePacked(type(Counter).creationCode)));
if (!isContract(computed)) {
address created = _walletFactory.deployContract(0, abi.encodePacked(type(Counter).creationCode), bytes32(0));
address created = _walletFactory.deployContract(
deployerPublicKey, 0, abi.encodePacked(type(Counter).creationCode), bytes32(0)
);
console.log("Deployed Counter contract at", created);
} else {
console.log("Counter already deployed at", computed);
Expand Down Expand Up @@ -201,8 +203,9 @@ contract KintoDeployETHPriceIsRight is AASetup, KYCSignature, UserOp {
bytes32(0), keccak256(abi.encodePacked(type(ETHPriceIsRight).creationCode))
);
if (!isContract(computed)) {
address created =
_walletFactory.deployContract(0, abi.encodePacked(type(ETHPriceIsRight).creationCode), bytes32(0));
address created = _walletFactory.deployContract(
deployerPublicKey, 0, abi.encodePacked(type(ETHPriceIsRight).creationCode), bytes32(0)
);
console.log("Deployed ETHPriceIsRight contract at", created);
} else {
console.log("ETHPriceIsRight already deployed at", computed);
Expand Down
5 changes: 4 additions & 1 deletion src/interfaces/IKintoWalletFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ interface IKintoWalletFactory {

function createAccount(address owner, address recoverer, uint256 salt) external returns (IKintoWallet ret);

function deployContract(uint256 amount, bytes memory bytecode, bytes32 salt) external payable returns (address);
function deployContract(address contractOwner, uint256 amount, bytes memory bytecode, bytes32 salt)
external
payable
returns (address);

function deployContractByWallet(uint256 amount, bytes memory bytecode, bytes32 salt)
external
Expand Down
17 changes: 12 additions & 5 deletions src/wallet/KintoWalletFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,29 @@
* - `salt` must have not been used for `bytecode` already.
* - the factory must have a balance of at least `amount`.
* - if `amount` is non-zero, `bytecode` must have a `payable` constructor.
* @param contractOwner The address to be set as owner
* @param amount The amount of wei to send with the contract creation
* @param bytecode The bytecode of the contract to deploy
* @param salt The salt to use for the calculation
*/
function deployContract(uint256 amount, bytes calldata bytecode, bytes32 salt)
function deployContract(address contractOwner, uint256 amount, bytes calldata bytecode, bytes32 salt)
external
payable
override
returns (address)
{
require(kintoID.isKYC(msg.sender), "KYC required");
return _deployAndAssignOwnership(amount, bytecode, salt);
return _deployAndAssignOwnership(contractOwner, amount, bytecode, salt);
}

/**
* @dev Deploys a contract using `CREATE2`. The address where the contract
* will be deployed can be known in advance via {computeAddress}.
*
* Same as above but this one goes through the Kinto Wallet.
* @param amount The amount of wei to send with the contract creation
* @param bytecode The bytecode of the contract to deploy
* @param salt The salt to use for the calculation
*/
function deployContractByWallet(uint256 amount, bytes calldata bytecode, bytes32 salt)
external
Expand All @@ -186,7 +193,7 @@
returns (address)
{
require(walletTs[msg.sender] > 0 && kintoID.isKYC(KintoWallet(payable(msg.sender)).owners(0)), "KYC required");
return _deployAndAssignOwnership(amount, bytecode, salt);
return _deployAndAssignOwnership(msg.sender, amount, bytecode, salt);

Check warning on line 196 in src/wallet/KintoWalletFactory.sol

View check run for this annotation

Codecov / codecov/patch

src/wallet/KintoWalletFactory.sol#L196

Added line #L196 was not covered by tests
}

/**
Expand Down Expand Up @@ -262,7 +269,7 @@
}
}

function _deployAndAssignOwnership(uint256 amount, bytes calldata bytecode, bytes32 salt)
function _deployAndAssignOwnership(address newOwner, uint256 amount, bytes calldata bytecode, bytes32 salt)
internal
returns (address)
{
Expand All @@ -272,7 +279,7 @@
// Assign ownership to the deployer if needed
try OwnableUpgradeable(created).owner() returns (address owner) {
if (owner == address(this)) {
OwnableUpgradeable(created).transferOwnership(msg.sender);
OwnableUpgradeable(created).transferOwnership(newOwner);
}
} catch {}
return created;
Expand Down
8 changes: 5 additions & 3 deletions test/DeployTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ contract DeveloperDeployTest is Create2Helper, UserOp, AATestScaffolding {
deployAAScaffolding(_owner, _kycProvider, _recoverer);
vm.startPrank(_owner);

address created = _walletFactory.deployContract(0, abi.encodePacked(type(Counter).creationCode), bytes32(0));
address created =
_walletFactory.deployContract(_owner, 0, abi.encodePacked(type(Counter).creationCode), bytes32(0));
_counter = Counter(created);

created =
_walletFactory.deployContract(0, abi.encodePacked(type(CounterInitializable).creationCode), bytes32(0));
created = _walletFactory.deployContract(
_owner, 0, abi.encodePacked(type(CounterInitializable).creationCode), bytes32(0)
);

// deploy _proxy contract and point it to _implementation
_proxyc = new UUPSProxy{salt: 0}(address(created), "");
Expand Down
4 changes: 3 additions & 1 deletion test/KintoWalletFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ contract KintoWalletFactoryTest is Create2Helper, UserOp, AATestScaffolding {
vm.startPrank(_owner);
address computed =
_walletFactory.getContractAddress(bytes32(0), keccak256(abi.encodePacked(type(Counter).creationCode)));
address created = _walletFactory.deployContract(0, abi.encodePacked(type(Counter).creationCode), bytes32(0));
address created =
_walletFactory.deployContract(_owner, 0, abi.encodePacked(type(Counter).creationCode), bytes32(0));
assertEq(computed, created);
assertEq(Counter(created).count(), 0);
Counter(created).increment();
Expand All @@ -145,6 +146,7 @@ contract KintoWalletFactoryTest is Create2Helper, UserOp, AATestScaffolding {
vm.startPrank(_owner);
bytes memory a = abi.encodeWithSelector(KintoWallet.initialize.selector, _owner, _owner);
_walletFactory.deployContract(
_owner,
0,
abi.encodePacked(type(SafeBeaconProxy).creationCode, abi.encode(address(_walletFactory.beacon()), a)),
bytes32(0)
Expand Down
Loading