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

Add PCV Deposit to PCV Guardian #355

Merged
merged 5 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions contracts/pcv/IPCVGuardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ interface IPCVGuardian {
/// @param safeAddress the destination address to withdraw to
/// @param amount the amount to withdraw
/// @param pauseAfter if true, the pcv contract will be paused after the withdraw
kryptoklob marked this conversation as resolved.
Show resolved Hide resolved
function withdrawToSafeAddress(address pcvDeposit, address safeAddress, uint256 amount, bool pauseAfter) external;
function withdrawToSafeAddress(address pcvDeposit, address safeAddress, uint256 amount, bool pauseAfter, bool depositAfter) external;

/// @notice governor-or-guardian-only method to withdraw funds from a pcv deposit, by calling the withdraw() method on it
/// @param pcvDeposit the address of the pcv deposit contract
/// @param safeAddress the destination address to withdraw to
/// @param amount the amount of tokens to withdraw
/// @param pauseAfter if true, the pcv contract will be paused after the withdraw
function withdrawETHToSafeAddress(address pcvDeposit, address payable safeAddress, uint256 amount, bool pauseAfter) external;
function withdrawETHToSafeAddress(address pcvDeposit, address payable safeAddress, uint256 amount, bool pauseAfter, bool depositAfter) external;
kryptoklob marked this conversation as resolved.
Show resolved Hide resolved

/// @notice governor-or-guardian-only method to withdraw funds from a pcv deposit, by calling the withdraw() method on it
/// @param pcvDeposit the deposit to pull funds from
/// @param safeAddress the destination address to withdraw to
/// @param token the token to withdraw
/// @param amount the amount of funds to withdraw
/// @param pauseAfter whether to pause the pcv after withdrawing
function withdrawERC20ToSafeAddress(address pcvDeposit, address safeAddress, address token, uint256 amount, bool pauseAfter) external;
function withdrawERC20ToSafeAddress(address pcvDeposit, address safeAddress, address token, uint256 amount, bool pauseAfter, bool depositAfter) external;
kryptoklob marked this conversation as resolved.
Show resolved Hide resolved
}
53 changes: 42 additions & 11 deletions contracts/pcv/PCVGuardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
) CoreRef(_core) {
_setContractAdminRole(keccak256("PCV_GUARDIAN_ADMIN_ROLE"));

for(uint256 i=0; i<_safeAddresses.length; i++) {
for (uint256 i = 0; i < _safeAddresses.length; i++) {
_setSafeAddress(_safeAddresses[i]);
}
}
Expand All @@ -42,14 +42,14 @@ contract PCVGuardian is IPCVGuardian, CoreRef {

/// @notice governor-only method to set an address as "safe" to withdraw funds to
/// @param pcvDeposit the address to set as safe
function setSafeAddress(address pcvDeposit) external override onlyGovernorOrAdmin() {
function setSafeAddress(address pcvDeposit) external override onlyGovernorOrAdmin {
_setSafeAddress(pcvDeposit);
}

/// @notice batch version of setSafeAddress
/// @param _safeAddresses the addresses to set as safe, as calldata
function setSafeAddresses(address[] calldata _safeAddresses) external override onlyGovernorOrAdmin() {
for(uint256 i=0; i<_safeAddresses.length; i++) {
function setSafeAddresses(address[] calldata _safeAddresses) external override onlyGovernorOrAdmin {
for (uint256 i = 0; i < _safeAddresses.length; i++) {
_setSafeAddress(_safeAddresses[i]);
}
}
Expand All @@ -58,14 +58,14 @@ contract PCVGuardian is IPCVGuardian, CoreRef {

/// @notice governor-or-guardian-only method to un-set an address as "safe" to withdraw funds to
/// @param pcvDeposit the address to un-set as safe
function unsetSafeAddress(address pcvDeposit) external override isGovernorOrGuardianOrAdmin() {
function unsetSafeAddress(address pcvDeposit) external override isGovernorOrGuardianOrAdmin {
_unsetSafeAddress(pcvDeposit);
}

/// @notice batch version of unsetSafeAddresses
/// @param _safeAddresses the addresses to un-set as safe
function unsetSafeAddresses(address[] calldata _safeAddresses) external override isGovernorOrGuardianOrAdmin() {
for(uint256 i=0; i<_safeAddresses.length; i++) {
function unsetSafeAddresses(address[] calldata _safeAddresses) external override isGovernorOrGuardianOrAdmin {
for (uint256 i = 0; i < _safeAddresses.length; i++) {
_unsetSafeAddress(_safeAddresses[i]);
}
}
Expand All @@ -75,7 +75,13 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
/// @param safeAddress the destination address to withdraw to
/// @param amount the amount to withdraw
/// @param pauseAfter if true, the pcv contract will be paused after the withdraw
kryptoklob marked this conversation as resolved.
Show resolved Hide resolved
function withdrawToSafeAddress(address pcvDeposit, address safeAddress, uint256 amount, bool pauseAfter) external override isGovernorOrGuardianOrAdmin() {
function withdrawToSafeAddress(
address pcvDeposit,
address safeAddress,
uint256 amount,
bool pauseAfter,
bool depositAfter
) external override isGovernorOrGuardianOrAdmin {
require(isSafeAddress(safeAddress), "Provided address is not a safe address!");

pcvDeposit._ensureUnpaused();
Expand All @@ -86,6 +92,10 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
pcvDeposit._pause();
}

if (depositAfter) {
IPCVDeposit(safeAddress).deposit();
kryptoklob marked this conversation as resolved.
Show resolved Hide resolved
}

emit PCVGuardianWithdrawal(pcvDeposit, safeAddress, amount);
}

Expand All @@ -94,7 +104,13 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
/// @param safeAddress the destination address to withdraw to
/// @param amount the amount of tokens to withdraw
/// @param pauseAfter if true, the pcv contract will be paused after the withdraw
kryptoklob marked this conversation as resolved.
Show resolved Hide resolved
function withdrawETHToSafeAddress(address pcvDeposit, address payable safeAddress, uint256 amount, bool pauseAfter) external override isGovernorOrGuardianOrAdmin() {
function withdrawETHToSafeAddress(
address pcvDeposit,
address payable safeAddress,
uint256 amount,
bool pauseAfter,
bool depositAfter
) external override isGovernorOrGuardianOrAdmin {
require(isSafeAddress(safeAddress), "Provided address is not a safe address!");

pcvDeposit._ensureUnpaused();
Expand All @@ -105,6 +121,10 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
pcvDeposit._pause();
}

if (depositAfter) {
IPCVDeposit(safeAddress).deposit();
kryptoklob marked this conversation as resolved.
Show resolved Hide resolved
}

emit PCVGuardianETHWithdrawal(pcvDeposit, safeAddress, amount);
}

Expand All @@ -113,7 +133,14 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
/// @param safeAddress the destination address to withdraw to
/// @param amount the amount of funds to withdraw
/// @param pauseAfter whether to pause the pcv after withdrawing
kryptoklob marked this conversation as resolved.
Show resolved Hide resolved
function withdrawERC20ToSafeAddress(address pcvDeposit, address safeAddress, address token, uint256 amount, bool pauseAfter) external override isGovernorOrGuardianOrAdmin() {
function withdrawERC20ToSafeAddress(
address pcvDeposit,
address safeAddress,
address token,
uint256 amount,
bool pauseAfter,
bool depositAfter
) external override isGovernorOrGuardianOrAdmin {
require(isSafeAddress(safeAddress), "Provided address is not a safe address!");

pcvDeposit._ensureUnpaused();
Expand All @@ -124,6 +151,10 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
pcvDeposit._pause();
}

if (depositAfter) {
IPCVDeposit(safeAddress).deposit();
kryptoklob marked this conversation as resolved.
Show resolved Hide resolved
}

emit PCVGuardianERC20Withdrawal(pcvDeposit, safeAddress, token, amount);
}

Expand All @@ -138,4 +169,4 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
safeAddresses.remove(anAddress);
emit SafeAddressRemoved(anAddress);
}
}
}