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

OWRFactory deployment script #63

Merged
merged 4 commits into from
Aug 11, 2023
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ This command generates compilation output into the `out` directory.

### Deployment

This repo can be deployed with `forge create`.
This repo can be deployed with `forge create` or running the deployment scripts.

#### Goerli

OptimisticWithdrawalRecipient: https://goerli.etherscan.io/address/0x7b4b2cbbdac4f9b70252503a411574f4ff960e68

OptimisticWithdrawalRecipientFactory: https://goerli.etherscan.io/address/0xBB3b6CC2882B73eeFb32284Ecc9035839fb2C908

### Versioning

Expand Down
14 changes: 14 additions & 0 deletions script/OWRFactoryScript.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity =0.8.17;

import "forge-std/Script.sol";
import {OptimisticWithdrawalRecipientFactory} from "src/waterfall/OptimisticWithdrawalRecipientFactory.sol";

contract OWRFactoryScript is Script {
function run() external {
uint256 privKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(privKey);
new OptimisticWithdrawalRecipientFactory{salt: keccak256("obol.owrFactory.v1")}();
vm.stopBroadcast();
}
}
30 changes: 15 additions & 15 deletions src/test/waterfall/OptimisticWithdrawalRecipient.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ contract OptimisticWithdrawalRecipientTest is OWRTestHelper, Test {
emit RecoverNonOWRecipientFunds(
address(mERC20), recoveryAddress, 1 ether
);
owrETH.recoverNonOWRecipientFunds(address(mERC20), recoveryAddress);
owrETH.recoverFunds(address(mERC20), recoveryAddress);
assertEq(address(owrETH).balance, 1 ether);
assertEq(mERC20.balanceOf(address(owrETH)), 0 ether);
assertEq(mERC20.balanceOf(recoveryAddress), 1 ether);
Expand All @@ -138,7 +138,7 @@ contract OptimisticWithdrawalRecipientTest is OWRTestHelper, Test {
emit RecoverNonOWRecipientFunds(
address(mERC20), principalRecipient, 1 ether
);
owrETH_OR.recoverNonOWRecipientFunds(address(mERC20), principalRecipient);
owrETH_OR.recoverFunds(address(mERC20), principalRecipient);
assertEq(address(owrETH_OR).balance, 1 ether);
assertEq(mERC20.balanceOf(address(owrETH_OR)), 0 ether);
assertEq(mERC20.balanceOf(principalRecipient), 1 ether);
Expand All @@ -149,7 +149,7 @@ contract OptimisticWithdrawalRecipientTest is OWRTestHelper, Test {
emit RecoverNonOWRecipientFunds(
address(mERC20), rewardRecipient, 1 ether
);
owrETH_OR.recoverNonOWRecipientFunds(address(mERC20), rewardRecipient);
owrETH_OR.recoverFunds(address(mERC20), rewardRecipient);
assertEq(address(owrETH_OR).balance, 1 ether);
assertEq(mERC20.balanceOf(address(owrETH_OR)), 0 ether);
assertEq(mERC20.balanceOf(rewardRecipient), 1 ether);
Expand All @@ -163,7 +163,7 @@ contract OptimisticWithdrawalRecipientTest is OWRTestHelper, Test {
emit RecoverNonOWRecipientFunds(
ETH_ADDRESS, recoveryAddress, 1 ether
);
owrERC20.recoverNonOWRecipientFunds(ETH_ADDRESS, recoveryAddress);
owrERC20.recoverFunds(ETH_ADDRESS, recoveryAddress);
assertEq(mERC20.balanceOf(address(owrERC20)), 1 ether);
assertEq(address(owrERC20).balance, 0 ether);
assertEq(recoveryAddress.balance, 1 ether);
Expand All @@ -176,61 +176,61 @@ contract OptimisticWithdrawalRecipientTest is OWRTestHelper, Test {
emit RecoverNonOWRecipientFunds(
ETH_ADDRESS, principalRecipient, 1 ether
);
owrERC20_OR.recoverNonOWRecipientFunds(ETH_ADDRESS, principalRecipient);
owrERC20_OR.recoverFunds(ETH_ADDRESS, principalRecipient);
assertEq(mERC20.balanceOf(address(owrERC20_OR)), 1 ether);
assertEq(address(owrERC20_OR).balance, 0 ether);
assertEq(principalRecipient.balance, 1 ether);

address(owrERC20_OR).safeTransferETH(1 ether);

owrERC20_OR.recoverNonOWRecipientFunds(ETH_ADDRESS, rewardRecipient);
owrERC20_OR.recoverFunds(ETH_ADDRESS, rewardRecipient);
assertEq(mERC20.balanceOf(address(owrERC20_OR)), 1 ether);
assertEq(address(owrERC20_OR).balance, 0 ether, "invalid erc20 balance");
assertEq(rewardRecipient.balance, 1 ether, "invalid eth balance");
}

function testCannot_recoverNonOWRecipientFundsToNonRecipient() public {
function testCannot_recoverFundsToNonRecipient() public {
vm.expectRevert(
OptimisticWithdrawalRecipient.InvalidTokenRecovery_InvalidRecipient.selector
);
owrETH.recoverNonOWRecipientFunds(address(mERC20), address(1));
owrETH.recoverFunds(address(mERC20), address(1));

vm.expectRevert(
OptimisticWithdrawalRecipient.InvalidTokenRecovery_InvalidRecipient.selector
);
owrERC20_OR.recoverNonOWRecipientFunds(ETH_ADDRESS, address(1));
owrERC20_OR.recoverFunds(ETH_ADDRESS, address(1));

vm.expectRevert(
OptimisticWithdrawalRecipient.InvalidTokenRecovery_InvalidRecipient.selector
);
owrETH_OR.recoverNonOWRecipientFunds(address(mERC20), address(2));
owrETH_OR.recoverFunds(address(mERC20), address(2));

vm.expectRevert(
OptimisticWithdrawalRecipient.InvalidTokenRecovery_InvalidRecipient.selector
);
owrERC20_OR.recoverNonOWRecipientFunds(ETH_ADDRESS, address(2));
owrERC20_OR.recoverFunds(ETH_ADDRESS, address(2));
}

function testCannot_recoverOWRFunds() public {
vm.expectRevert(
OptimisticWithdrawalRecipient.InvalidTokenRecovery_OWRToken.selector
);
owrETH.recoverNonOWRecipientFunds(ETH_ADDRESS, recoveryAddress);
owrETH.recoverFunds(ETH_ADDRESS, recoveryAddress);

vm.expectRevert(
OptimisticWithdrawalRecipient.InvalidTokenRecovery_OWRToken.selector
);
owrERC20_OR.recoverNonOWRecipientFunds(address(mERC20), recoveryAddress);
owrERC20_OR.recoverFunds(address(mERC20), recoveryAddress);

vm.expectRevert(
OptimisticWithdrawalRecipient.InvalidTokenRecovery_OWRToken.selector
);
owrETH_OR.recoverNonOWRecipientFunds(ETH_ADDRESS, address(1));
owrETH_OR.recoverFunds(ETH_ADDRESS, address(1));

vm.expectRevert(
OptimisticWithdrawalRecipient.InvalidTokenRecovery_OWRToken.selector
);
owrERC20_OR.recoverNonOWRecipientFunds(address(mERC20), address(1));
owrERC20_OR.recoverFunds(address(mERC20), address(1));
}

function testCan_OWRIsPayable() public {
Expand Down
8 changes: 4 additions & 4 deletions src/waterfall/OptimisticWithdrawalRecipient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ contract OptimisticWithdrawalRecipient is Clone {
// 0; first item
uint256 internal constant TOKEN_OFFSET = 0;
// 20 = token_offset (0) + token_size (address, 20 bytes)
uint256 internal constant NON_OWRECIPIENT_OFFSET = 20;
uint256 internal constant RECOVERY_ADDRESS_OFFSET = 20;
// 40 = recoveryAddress_offset (20) + recoveryAddress_size (address, 20 bytes)
uint256 internal constant TRANCHES_OFFSET = 40;

Expand All @@ -109,7 +109,7 @@ contract OptimisticWithdrawalRecipient is Clone {
/// Address to recover non-OWR tokens to
/// @dev equivalent to address public immutable recoveryAddress;
function recoveryAddress() public pure returns (address) {
return _getArgAddress(NON_OWRECIPIENT_OFFSET);
return _getArgAddress(RECOVERY_ADDRESS_OFFSET);
}

/// Get OWR tranche `i`
Expand Down Expand Up @@ -178,7 +178,7 @@ contract OptimisticWithdrawalRecipient is Clone {
/// Recover non-OWR tokens to a recipient
/// @param nonOWRToken Token to recover (cannot be OWR token)
/// @param recipient Address to receive recovered token
function recoverNonOWRecipientFunds(
function recoverFunds(
address nonOWRToken,
address recipient
) external payable {
Expand All @@ -192,7 +192,7 @@ contract OptimisticWithdrawalRecipient is Clone {
// if recoveryAddress is set, recipient must match it
// else, recipient must be one of the OWR recipients

address _recoveryAddress= recoveryAddress();
address _recoveryAddress = recoveryAddress();
if (_recoveryAddress == address(0)) {
// ensure txn recipient is a valid OWR recipient
(address[] memory recipients,) = getTranches();
Expand Down
Loading