Skip to content

Commit

Permalink
PCVGuardian v3: remove pauseAfter param
Browse files Browse the repository at this point in the history
  • Loading branch information
eswak committed Jul 8, 2022
1 parent 531415d commit 9428149
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 195 deletions.
12 changes: 0 additions & 12 deletions contracts/pcv/IPCVGuardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ interface IPCVGuardian {
/// @param pcvDeposit the address of the pcv deposit contract
/// @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
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawToSafeAddress(
address pcvDeposit,
address safeAddress,
uint256 amount,
bool pauseAfter,
bool depositAfter
) external;

Expand All @@ -69,27 +67,23 @@ interface IPCVGuardian {
/// @param pcvDeposit the address of the pcv deposit contract
/// @param safeAddress the destination address to withdraw to
/// @param basisPoints the percent in basis points [1-10000] if the deposit's balance to withdraw
/// @param pauseAfter if true, the pcv contract will be paused after the withdraw
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawRatioToSafeAddress(
address pcvDeposit,
address safeAddress,
uint256 basisPoints,
bool pauseAfter,
bool depositAfter
) external;

/// @notice withdraw funds from a pcv deposit, by calling the withdrawETH() 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
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawETHToSafeAddress(
address pcvDeposit,
address payable safeAddress,
uint256 amount,
bool pauseAfter,
bool depositAfter
) external;

Expand All @@ -98,13 +92,11 @@ interface IPCVGuardian {
/// @param pcvDeposit the address of the pcv deposit contract
/// @param safeAddress the destination address to withdraw to
/// @param basisPoints the percent in basis points [1-10000] if the deposit's balance to withdraw
/// @param pauseAfter if true, the pcv contract will be paused after the withdraw
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawETHRatioToSafeAddress(
address pcvDeposit,
address payable safeAddress,
uint256 basisPoints,
bool pauseAfter,
bool depositAfter
) external;

Expand All @@ -113,14 +105,12 @@ interface IPCVGuardian {
/// @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
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawERC20ToSafeAddress(
address pcvDeposit,
address safeAddress,
address token,
uint256 amount,
bool pauseAfter,
bool depositAfter
) external;

Expand All @@ -130,14 +120,12 @@ interface IPCVGuardian {
/// @param safeAddress the destination address to withdraw to
/// @param token the token to withdraw
/// @param basisPoints the percent in basis points [1-10000] if the deposit's balance to withdraw
/// @param pauseAfter whether to pause the pcv after withdrawing
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawERC20RatioToSafeAddress(
address pcvDeposit,
address safeAddress,
address token,
uint256 basisPoints,
bool pauseAfter,
bool depositAfter
) external;
}
29 changes: 8 additions & 21 deletions contracts/pcv/PCVGuardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
/// @notice modifier to factorize the logic in all withdrawals :
/// - first, ensure the deposit to withdraw from is unpaused
/// - second, perform withdrawal
/// - third, re-pause deposit if it was paused or if pauseAfter = true
/// - third, re-pause deposit if it was paused
/// - finally, call pcvDeposit.deposit() if depositAfter = true
modifier beforeAndAfterWithdrawal(
address pcvDeposit,
address safeAddress,
bool pauseAfter,
bool depositAfter
) {
{
Expand All @@ -117,7 +116,7 @@ contract PCVGuardian is IPCVGuardian, CoreRef {

_;

if (paused || pauseAfter) {
if (paused) {
pcvDeposit._pause();
}

Expand All @@ -130,15 +129,13 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
/// @param pcvDeposit the address of the pcv deposit contract
/// @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
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawToSafeAddress(
address pcvDeposit,
address safeAddress,
uint256 amount,
bool pauseAfter,
bool depositAfter
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, pauseAfter, depositAfter) {
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, depositAfter) {
IPCVDeposit(pcvDeposit).withdraw(safeAddress, amount);
emit PCVGuardianWithdrawal(pcvDeposit, safeAddress, amount);
}
Expand All @@ -147,15 +144,13 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
/// @param pcvDeposit the address of the pcv deposit contract
/// @param safeAddress the destination address to withdraw to
/// @param basisPoints the percent in basis points [1-10000] if the deposit's balance to withdraw
/// @param pauseAfter if true, the pcv contract will be paused after the withdraw
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawRatioToSafeAddress(
address pcvDeposit,
address safeAddress,
uint256 basisPoints,
bool pauseAfter,
bool depositAfter
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, pauseAfter, depositAfter) {
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, depositAfter) {
require(basisPoints <= Constants.BASIS_POINTS_GRANULARITY, "PCVGuardian: basisPoints too high");
uint256 amount = (IPCVDeposit(pcvDeposit).balance() * basisPoints) / Constants.BASIS_POINTS_GRANULARITY;
require(amount != 0, "PCVGuardian: no value to withdraw");
Expand All @@ -168,15 +163,13 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
/// @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
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawETHToSafeAddress(
address pcvDeposit,
address payable safeAddress,
uint256 amount,
bool pauseAfter,
bool depositAfter
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, pauseAfter, depositAfter) {
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, depositAfter) {
IPCVDeposit(pcvDeposit).withdrawETH(safeAddress, amount);
emit PCVGuardianETHWithdrawal(pcvDeposit, safeAddress, amount);
}
Expand All @@ -185,15 +178,13 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
/// @param pcvDeposit the address of the pcv deposit contract
/// @param safeAddress the destination address to withdraw to
/// @param basisPoints the percent in basis points [1-10000] if the deposit's balance to withdraw
/// @param pauseAfter if true, the pcv contract will be paused after the withdraw
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawETHRatioToSafeAddress(
address pcvDeposit,
address payable safeAddress,
uint256 basisPoints,
bool pauseAfter,
bool depositAfter
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, pauseAfter, depositAfter) {
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, depositAfter) {
require(basisPoints <= Constants.BASIS_POINTS_GRANULARITY, "PCVGuardian: basisPoints too high");
uint256 amount = (pcvDeposit.balance * basisPoints) / Constants.BASIS_POINTS_GRANULARITY;
require(amount != 0, "PCVGuardian: no value to withdraw");
Expand All @@ -206,16 +197,14 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
/// @param pcvDeposit the deposit to pull funds from
/// @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
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawERC20ToSafeAddress(
address pcvDeposit,
address safeAddress,
address token,
uint256 amount,
bool pauseAfter,
bool depositAfter
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, pauseAfter, depositAfter) {
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, depositAfter) {
IPCVDeposit(pcvDeposit).withdrawERC20(token, safeAddress, amount);
emit PCVGuardianERC20Withdrawal(pcvDeposit, safeAddress, token, amount);
}
Expand All @@ -224,16 +213,14 @@ contract PCVGuardian is IPCVGuardian, CoreRef {
/// @param pcvDeposit the deposit to pull funds from
/// @param safeAddress the destination address to withdraw to
/// @param basisPoints the percent in basis points [1-10000] if the deposit's balance to withdraw
/// @param pauseAfter whether to pause the pcv after withdrawing
/// @param depositAfter if true, attempts to deposit to the target PCV deposit
function withdrawERC20RatioToSafeAddress(
address pcvDeposit,
address safeAddress,
address token,
uint256 basisPoints,
bool pauseAfter,
bool depositAfter
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, pauseAfter, depositAfter) {
) external override beforeAndAfterWithdrawal(pcvDeposit, safeAddress, depositAfter) {
require(basisPoints <= Constants.BASIS_POINTS_GRANULARITY, "PCVGuardian: basisPoints too high");
uint256 amount = (IERC20(token).balanceOf(pcvDeposit) * basisPoints) / Constants.BASIS_POINTS_GRANULARITY;
require(amount != 0, "PCVGuardian: no value to withdraw");
Expand Down
2 changes: 1 addition & 1 deletion contracts/sentinel/guards/FuseWithdrawalGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract FuseWithdrawalGuard is IGuard, CoreRef {
EnumerableSet.AddressSet private fuseDeposits;

/// @notice the PCV mover contract exposed to guardian role
PCVGuardian public constant pcvGuardian = PCVGuardian(0x02435948F84d7465FB71dE45ABa6098Fc6eC2993);
PCVGuardian public constant pcvGuardian = PCVGuardian(0x0000000000000000000000000000000000000000); // TODO update

/// @notice the minimum amount of underlying which can be withdrawn from a cToken that registers in the guard.
/// i.e. if the min is 100 FEI but the amount in the contract is 1 FEI, the amountToWithdraw will return 0 and the check will fail
Expand Down
1 change: 0 additions & 1 deletion contracts/test/integration/fixtures/MainnetAddresses.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ library MainnetAddresses {
address public constant LUSD_PSM = 0xb0e731F036AdfDeC12da77c15aaB0F90E8e45A0e;
address public constant DAI_PSM = 0x2A188F9EB761F70ECEa083bA6c2A40145078dfc2;

address public constant PCV_GUARDIAN_NEW = 0x02435948F84d7465FB71dE45ABa6098Fc6eC2993;
address payable public constant PCV_SENTINEL = payable(0xC297705Acf50134d256187c754B92FA37826C019);

address public constant LUSD = 0x5f98805A4E8be255a32880FDeC7F6728C6568bA0;
Expand Down
6 changes: 4 additions & 2 deletions contracts/test/integration/sentinel/FuseWithdrawalGuard.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ contract FuseWithdrawalGuardIntegrationTest is DSTest, StdLib {
sentinel.knight(address(guard));
}

function testGuardCanProtec() public {
// TODO: update Fuse withdrawal guard PCV_GUARDIAN address,
// and then uncomment this integration test file
/*function testGuardCanProtec() public {
// 1. Check preconditions of FEI pool 8 withdraw
assertTrue(guard.check());
uint256 feiCTokenBalanceBefore = fei.balanceOf(MainnetAddresses.RARI_POOL_8_FEI);
Expand Down Expand Up @@ -97,5 +99,5 @@ contract FuseWithdrawalGuardIntegrationTest is DSTest, StdLib {
// 6. Check no more withdrawals
assertFalse(guard.check());
}
}*/
}
Loading

0 comments on commit 9428149

Please sign in to comment.