Skip to content

Commit

Permalink
Merge branch 'master' into feat/raw-diff
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Jan 28, 2025
2 parents 759cc5d + 066f216 commit 456c863
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 91 deletions.
27 changes: 27 additions & 0 deletions src/GovV3Helpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {GovernanceV3Gnosis} from 'aave-address-book/GovernanceV3Gnosis.sol';
import {GovernanceV3Scroll} from 'aave-address-book/GovernanceV3Scroll.sol';
import {GovernanceV3PolygonZkEvm} from 'aave-address-book/GovernanceV3PolygonZkEvm.sol';
import {GovernanceV3ZkSync} from 'aave-address-book/GovernanceV3ZkSync.sol';
import {GovernanceV3Linea} from 'aave-address-book/GovernanceV3Linea.sol';
import {MiscEthereum} from 'aave-address-book/MiscEthereum.sol';
import {Address} from 'solidity-utils/contracts/oz-common/Address.sol';
import {Create2Utils} from 'solidity-utils/contracts/utils/ScriptUtils.sol';
Expand Down Expand Up @@ -696,6 +697,30 @@ library GovV3Helpers {
return _buildPayload(vm, ChainIds.ZKSYNC, action);
}

/**
* Builds a payload to be executed via governance
* @param vm Vm
* @param actions actions array
*/
function buildLineaPayload(
Vm vm,
IPayloadsControllerCore.ExecutionAction[] memory actions
) internal returns (PayloadsControllerUtils.Payload memory) {
return _buildPayload(vm, ChainIds.LINEA, actions);
}

/**
* Builds a payload to be executed via governance
* @param vm Vm
* @param action single action struct
*/
function buildLineaPayload(
Vm vm,
IPayloadsControllerCore.ExecutionAction memory action
) internal returns (PayloadsControllerUtils.Payload memory) {
return _buildPayload(vm, ChainIds.LINEA, action);
}

/**
* @dev creates a proposal with multiple payloads
* @param vm Vm
Expand Down Expand Up @@ -777,6 +802,8 @@ library GovV3Helpers {
return GovernanceV3PolygonZkEvm.PAYLOADS_CONTROLLER;
} else if (chainId == ChainIds.ZKSYNC) {
return GovernanceV3ZkSync.PAYLOADS_CONTROLLER;
} else if (chainId == ChainIds.LINEA) {
return GovernanceV3Linea.PAYLOADS_CONTROLLER;
}

revert CannotFindPayloadsController();
Expand Down
4 changes: 2 additions & 2 deletions src/asset-manager/AaveWstethWithdrawer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ contract AaveWstethWithdrawer is

/// @inheritdoc IRescuableBase
function maxRescue(
address erc20Token
) public view override(RescuableBase, IRescuableBase) returns (uint256) {
address
) public pure override(RescuableBase, IRescuableBase) returns (uint256) {
return type(uint256).max;
}

Expand Down
4 changes: 2 additions & 2 deletions src/bridges/arbitrum/AaveArbEthERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ contract AaveArbEthERC20Bridge is Ownable, Rescuable, IAaveArbEthERC20Bridge {

/// @inheritdoc IRescuableBase
function maxRescue(
address erc20Token
) public view override(RescuableBase, IRescuableBase) returns (uint256) {
address
) public pure override(RescuableBase, IRescuableBase) returns (uint256) {
return type(uint256).max;
}
}
4 changes: 2 additions & 2 deletions src/bridges/optimism/AaveOpEthERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ contract AaveOpEthERC20Bridge is Ownable, Rescuable, IAaveOpEthERC20Bridge {

/// @inheritdoc IRescuableBase
function maxRescue(
address erc20Token
) public view override(RescuableBase, IRescuableBase) returns (uint256) {
address
) public pure override(RescuableBase, IRescuableBase) returns (uint256) {
return type(uint256).max;
}
}
4 changes: 2 additions & 2 deletions src/bridges/polygon/AavePolEthERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ contract AavePolEthERC20Bridge is Ownable, Rescuable, IAavePolEthERC20Bridge {

/// @inheritdoc IRescuableBase
function maxRescue(
address erc20Token
) public view override(RescuableBase, IRescuableBase) returns (uint256) {
address
) public pure override(RescuableBase, IRescuableBase) returns (uint256) {
return type(uint256).max;
}

Expand Down
4 changes: 2 additions & 2 deletions src/bridges/polygon/AavePolEthPlasmaBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ contract AavePolEthPlasmaBridge is Ownable, Rescuable, IAavePolEthPlasmaBridge {

/// @inheritdoc IRescuableBase
function maxRescue(
address erc20Token
) public view override(RescuableBase, IRescuableBase) returns (uint256) {
address
) public pure override(RescuableBase, IRescuableBase) returns (uint256) {
return type(uint256).max;
}

Expand Down
2 changes: 1 addition & 1 deletion src/swaps/AaveSwapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ contract AaveSwapper is IAaveSwapper, Initializable, OwnableWithGuardian, Rescua

/// @inheritdoc IRescuableBase
function maxRescue(
address erc20Token
address
) public pure override(RescuableBase, IRescuableBase) returns (uint256) {
return type(uint256).max;
}
Expand Down
15 changes: 15 additions & 0 deletions src/v3-config-engine/AaveV3PayloadLinea.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {AaveV3Linea} from 'aave-address-book/AaveV3Linea.sol';
import 'aave-v3-origin/contracts/extensions/v3-config-engine/AaveV3Payload.sol';

/**
* @dev Base smart contract for an Aave v3.2.0 listing on v3 Linea.
* @author BGD Labs
*/
abstract contract AaveV3PayloadLinea is AaveV3Payload(IEngine(AaveV3Linea.CONFIG_ENGINE)) {
function getPoolContext() public pure override returns (IEngine.PoolContext memory) {
return IEngine.PoolContext({networkName: 'Linea', networkAbbreviation: 'Lin'});
}
}
31 changes: 24 additions & 7 deletions tests/GovV3Test.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.0;

import 'forge-std/Test.sol';
import {Vm} from 'forge-std/Vm.sol';
import {IVotingMachineWithProofs, GovV3Helpers, PayloadsControllerUtils, IPayloadsControllerCore, GovV3StorageHelpers, IGovernanceCore} from '../src/GovV3Helpers.sol';
import {ProtocolV3TestBase} from '../src/ProtocolV3TestBase.sol';
import {MiscEthereum} from 'aave-address-book/MiscEthereum.sol';
Expand All @@ -17,7 +18,6 @@ interface Mock {

contract GovernanceV3Test is ProtocolV3TestBase {
event TestEvent();
error CannotFindPayload();

PayloadWithEmit payload;

Expand Down Expand Up @@ -92,7 +92,7 @@ contract GovernanceV3Test is ProtocolV3TestBase {
GovV3StorageHelpers.readyPayloadId(vm, payloadsController, payloadId);
IPayloadsControllerCore.Payload memory pl = payloadsController.getPayloadById(payloadId);
assertEq(uint256(pl.state), uint256(IPayloadsControllerCore.PayloadState.Queued));
assertEq(pl.queuedAt, block.timestamp - pl.delay -1);
assertEq(pl.queuedAt, block.timestamp - pl.delay - 1);
assertEq(uint256(pl.maximumAccessLevelRequired), 1);
assertEq(pl.createdAt, block.timestamp);
assertEq(pl.creator, address(this));
Expand Down Expand Up @@ -124,7 +124,7 @@ contract GovernanceV3Test is ProtocolV3TestBase {

function test_expectRevertOnNonExistingPayload() public {
vm.expectRevert();
GovV3Helpers.executePayload(vm, address(1));
this.selfExternalCallToExecutePayload(vm, address(1));
}

/**
Expand All @@ -151,7 +151,7 @@ contract GovernanceV3Test is ProtocolV3TestBase {
vm.stopPrank();
}

function xtest_payloadCreationWhenPayloadAlreadyCreated() public {
function test_payloadCreationWhenPayloadAlreadyCreated() public {
// 1. deploy payloads
PayloadWithEmit pl1 = new PayloadWithEmit();
PayloadWithEmit pl2 = new PayloadWithEmit();
Expand All @@ -165,20 +165,37 @@ contract GovernanceV3Test is ProtocolV3TestBase {

// 3. create same payload
vm.expectRevert(GovV3Helpers.PayloadAlreadyCreated.selector);
GovV3Helpers.createPayload(actions);
this.selfExternalCallToCreatePayload(actions);
}

function test_helpers() public {
defaultTest('default', AaveV3Ethereum.POOL, address(payload));
}

function testFail_findPayload() public {
function test_findPayload() public {
IPayloadsControllerCore.ExecutionAction[]
memory actions = new IPayloadsControllerCore.ExecutionAction[](1);
actions[0] = GovV3Helpers.buildAction(address(42));

// should revert as payload 0x42 does not exist
vm.expectRevert(CannotFindPayload.selector);
vm.expectRevert(GovV3Helpers.CannotFindPayload.selector);
this.selfExternalCallToBuildMainnetPayload(vm, actions);
}

function selfExternalCallToBuildMainnetPayload(
Vm vm,
IPayloadsControllerCore.ExecutionAction[] memory actions
) external {
GovV3Helpers.buildMainnetPayload(vm, actions);
}

function selfExternalCallToCreatePayload(
IPayloadsControllerCore.ExecutionAction[] memory actions
) external {
GovV3Helpers.createPayload(actions);
}

function selfExternalCallToExecutePayload(Vm vm, address payloadAddress) external {
GovV3Helpers.executePayload(vm, payloadAddress);
}
}
78 changes: 18 additions & 60 deletions tests/asset-manager/AaveWstethWithdrawerTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {AaveWstethWithdrawer} from '../../src/asset-manager/AaveWstethWithdrawer

contract AaveWstethWithdrawerTest is Test {
using stdStorage for StdStorage;

event StartedWithdrawal(uint256[] amounts, uint256 indexed index);

event FinalizedWithdrawal(uint256 amount, uint256 indexed index);

uint256 public constant EXISTING_UNSTETH_TOKENID = 46283;
uint256 public constant WITHDRAWAL_AMOUNT = 999999999900;
uint256 public constant FINALIZED_WITHDRAWAL_AMOUNT = 1173102309960;
Expand All @@ -30,7 +30,6 @@ contract AaveWstethWithdrawerTest is Test {

AaveWstethWithdrawer public withdrawer;


/// At current block oldWithdrawer (UNSTETH_OWNER) has an Lido withdrawal NFT
/// this NFT represents an WITHDRAWAL_AMOUNT of STETH that
/// yields FINALIZED_WITHDRAWAL_AMOUNT of ETH when completed.
Expand All @@ -45,19 +44,15 @@ contract AaveWstethWithdrawerTest is Test {
address(withdrawer),
46283
);

/// start an withdrawal to create the storage slot
AaveV3Ethereum.COLLECTOR.transfer(
address(WSTETH),
address(withdrawer),
WITHDRAWAL_AMOUNT
);
AaveV3Ethereum.COLLECTOR.transfer(address(WSTETH), address(withdrawer), WITHDRAWAL_AMOUNT);
uint256[] memory amounts = new uint256[](1);
amounts[0] = WITHDRAWAL_AMOUNT;
withdrawer.startWithdraw(amounts);
vm.stopPrank();
/// override the storage slot to the requestId respective to the unSTETH NFT

/// override the storage slot to the requestId respective to the unSTETH NFT
/// and the minCheckpointIndex
AaveWstethWithdrawer oldWithdrawer = AaveWstethWithdrawer(payable(UNSTETH_OWNER));
uint256 key = 0;
Expand All @@ -70,10 +65,7 @@ contract AaveWstethWithdrawerTest is Test {
.with_key(key)
.checked_write(reqId);

stdstore
.target(address(withdrawer))
.sig('minCheckpointIndex()')
.checked_write(minIndex);
stdstore.target(address(withdrawer)).sig('minCheckpointIndex()').checked_write(minIndex);
_;
}

Expand Down Expand Up @@ -119,11 +111,7 @@ contract UpdateGuardian is AaveWstethWithdrawerTest {
contract StartWithdrawal is AaveWstethWithdrawerTest {
function test_revertsIf_invalidCaller() public {
vm.prank(OWNER);
AaveV3Ethereum.COLLECTOR.transfer(
address(WSTETH),
address(withdrawer),
WITHDRAWAL_AMOUNT
);
AaveV3Ethereum.COLLECTOR.transfer(address(WSTETH), address(withdrawer), WITHDRAWAL_AMOUNT);
uint256[] memory amounts = new uint256[](1);
amounts[0] = WITHDRAWAL_AMOUNT;
vm.expectRevert('ONLY_BY_OWNER_OR_GUARDIAN');
Expand All @@ -136,11 +124,7 @@ contract StartWithdrawal is AaveWstethWithdrawerTest {
uint256 nextIndex = withdrawer.nextIndex();

vm.startPrank(OWNER);
AaveV3Ethereum.COLLECTOR.transfer(
address(WSTETH),
address(withdrawer),
WITHDRAWAL_AMOUNT
);
AaveV3Ethereum.COLLECTOR.transfer(address(WSTETH), address(withdrawer), WITHDRAWAL_AMOUNT);
uint256[] memory amounts = new uint256[](1);
amounts[0] = WITHDRAWAL_AMOUNT;
vm.expectEmit(address(withdrawer));
Expand All @@ -161,11 +145,7 @@ contract StartWithdrawal is AaveWstethWithdrawerTest {
uint256 nextIndex = withdrawer.nextIndex();

vm.prank(OWNER);
AaveV3Ethereum.COLLECTOR.transfer(
address(WSTETH),
address(withdrawer),
WITHDRAWAL_AMOUNT
);
AaveV3Ethereum.COLLECTOR.transfer(address(WSTETH), address(withdrawer), WITHDRAWAL_AMOUNT);
uint256[] memory amounts = new uint256[](1);
amounts[0] = WITHDRAWAL_AMOUNT;
vm.expectEmit(address(withdrawer));
Expand Down Expand Up @@ -207,7 +187,7 @@ contract FinalizeWithdrawal is AaveWstethWithdrawerTest {

assertEq(collectorBalanceAfter, collectorBalanceBefore + FINALIZED_WITHDRAWAL_AMOUNT);
}

function test_finalizeWithdrawalWithExtraFunds() public withUnsteth {
uint256 collectorBalanceBefore = WETH.balanceOf(COLLECTOR);

Expand All @@ -230,58 +210,36 @@ contract EmergencyTokenTransfer is AaveWstethWithdrawerTest {
function test_revertsIf_invalidCaller() public {
deal(address(WSTETH), address(withdrawer), WITHDRAWAL_AMOUNT);
vm.expectRevert('ONLY_RESCUE_GUARDIAN');
withdrawer.emergencyTokenTransfer(
address(WSTETH),
COLLECTOR,
WITHDRAWAL_AMOUNT
);
withdrawer.emergencyTokenTransfer(address(WSTETH), COLLECTOR, WITHDRAWAL_AMOUNT);
}

function test_successful_governanceCaller() public {
uint256 initialCollectorBalance = WSTETH.balanceOf(COLLECTOR);
deal(address(WSTETH), address(withdrawer), WITHDRAWAL_AMOUNT);
vm.startPrank(OWNER);
withdrawer.emergencyTokenTransfer(
address(WSTETH),
COLLECTOR,
WITHDRAWAL_AMOUNT
);
withdrawer.emergencyTokenTransfer(address(WSTETH), COLLECTOR, WITHDRAWAL_AMOUNT);
vm.stopPrank();

assertEq(
WSTETH.balanceOf(COLLECTOR),
initialCollectorBalance + WITHDRAWAL_AMOUNT
);
assertEq(WSTETH.balanceOf(COLLECTOR), initialCollectorBalance + WITHDRAWAL_AMOUNT);
assertEq(WSTETH.balanceOf(address(withdrawer)), 0);
}
}

contract Emergency721TokenTransfer is AaveWstethWithdrawerTest {
function test_revertsIf_invalidCaller() public withUnsteth {
vm.expectRevert('ONLY_RESCUE_GUARDIAN');
withdrawer.emergency721TokenTransfer(
address(UNSTETH),
COLLECTOR,
EXISTING_UNSTETH_TOKENID
);
withdrawer.emergency721TokenTransfer(address(UNSTETH), COLLECTOR, EXISTING_UNSTETH_TOKENID);
}

function test_successful_governanceCaller() public withUnsteth {
uint256 lidoNftBalanceBefore = UNSTETH.balanceOf(address(withdrawer));
vm.startPrank(OWNER);
withdrawer.emergency721TokenTransfer(
address(UNSTETH),
COLLECTOR,
EXISTING_UNSTETH_TOKENID
);
withdrawer.emergency721TokenTransfer(address(UNSTETH), COLLECTOR, EXISTING_UNSTETH_TOKENID);
vm.stopPrank();

uint256 lidoNftBalanceAfter = UNSTETH.balanceOf(address(withdrawer));

assertEq(
UNSTETH.balanceOf(COLLECTOR),
1
);
assertEq(UNSTETH.balanceOf(COLLECTOR), 1);
assertEq(lidoNftBalanceAfter, lidoNftBalanceBefore - 1);
}
}
}
Loading

0 comments on commit 456c863

Please sign in to comment.