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

PolEthBridge: Update bridge owner and README as well as add missing natspec #166

Merged
merged 16 commits into from
Nov 21, 2023
Merged
7 changes: 4 additions & 3 deletions scripts/DeployBridges.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ pragma solidity ^0.8.0;

import {EthereumScript, PolygonScript} from 'src/ScriptUtils.sol';
import {AavePolEthERC20Bridge} from 'src/bridges/AavePolEthERC20Bridge.sol';
import {AaveGovernanceV2} from 'aave-address-book/AaveGovernanceV2.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import {GovernanceV3Polygon} from 'aave-address-book/GovernanceV3Polygon.sol';

contract DeployEthereum is EthereumScript {
function run() external broadcast {
bytes32 salt = 'Aave Treasury Bridge';
new AavePolEthERC20Bridge{salt: salt}(AaveGovernanceV2.SHORT_EXECUTOR);
new AavePolEthERC20Bridge{salt: salt}(GovernanceV3Ethereum.EXECUTOR_LVL_1);
}
}

contract DeployPolygon is PolygonScript {
function run() external broadcast {
bytes32 salt = 'Aave Treasury Bridge';
new AavePolEthERC20Bridge{salt: salt}(AaveGovernanceV2.POLYGON_BRIDGE_EXECUTOR);
new AavePolEthERC20Bridge{salt: salt}(GovernanceV3Polygon.EXECUTOR_LVL_1);
}
}
37 changes: 17 additions & 20 deletions src/bridges/AavePolEthERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract AavePolEthERC20Bridge is Ownable, Rescuable, IAavePolEthERC20Bridge {

error InvalidChain();

event Exit();
event Exit(bytes proof);
event Bridge(address token, uint256 amount);
event WithdrawToCollector(address token, uint256 amount);

Expand All @@ -44,38 +44,34 @@ contract AavePolEthERC20Bridge is Ownable, Rescuable, IAavePolEthERC20Bridge {
_transferOwnership(_owner);
sendra marked this conversation as resolved.
Show resolved Hide resolved
}

/*
* This function withdraws an ERC20 token from Polygon to Mainnet. exit() needs
* to be called on mainnet with the corresponding burnProof in order to complete.
* @notice Polygon only. Function will revert if called from other network.
* @param token Polygon address of ERC20 token to withdraw
* @param amount Amount of tokens to withdraw
*/
/// @inheritdoc IAavePolEthERC20Bridge
function bridge(address token, uint256 amount) external onlyOwner {
if (block.chainid != ChainIds.POLYGON) revert InvalidChain();

IERC20Polygon(token).withdraw(amount);
emit Bridge(token, amount);
}

/*
* This function completes the withdrawal process from Polygon to Mainnet.
* Burn proof is generated via API. Please see README.md
* @notice Mainnet only. Function will revert if called from other network.
* @param burnProof Burn proof generated via API.
*/
/// @inheritdoc IAavePolEthERC20Bridge
function exit(bytes calldata burnProof) external {
if (block.chainid != ChainIds.MAINNET) revert InvalidChain();

IRootChainManager(ROOT_CHAIN_MANAGER).exit(burnProof);
emit Exit();
emit Exit(burnProof);
}

/*
* Withdraws tokens on Mainnet contract to Aave V3 Collector.
* @notice Mainnet only. Function will revert if called from other network.
* @param token Mainnet address of token to withdraw to Collector
*/
/// @inheritdoc IAavePolEthERC20Bridge
function exit(bytes[] calldata burnProofs) external {
if (block.chainid != ChainIds.MAINNET) revert InvalidChain();

uint256 proofsLength = burnProofs.length;
for (uint256 i = 0; i < proofsLength; ++i) {
IRootChainManager(ROOT_CHAIN_MANAGER).exit(burnProofs[i]);
emit Exit(burnProofs[i]);
}
}

/// @inheritdoc IAavePolEthERC20Bridge
function withdrawToCollector(address token) external {
if (block.chainid != ChainIds.MAINNET) revert InvalidChain();

Expand All @@ -85,6 +81,7 @@ contract AavePolEthERC20Bridge is Ownable, Rescuable, IAavePolEthERC20Bridge {
emit WithdrawToCollector(token, balance);
}

/// @inheritdoc Rescuable
function whoCanRescue() public view override returns (address) {
return owner();
}
Expand Down
26 changes: 26 additions & 0 deletions src/bridges/IAavePolEthERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,35 @@
pragma solidity ^0.8.0;

interface IAavePolEthERC20Bridge {
/*
* This function withdraws an ERC20 token from Polygon to Mainnet. exit() needs
* to be called on mainnet with the corresponding burnProof in order to complete.
* @notice Polygon only. Function will revert if called from other network.
* @param token Polygon address of ERC20 token to withdraw
* @param amount Amount of tokens to withdraw
*/
function bridge(address token, uint256 amount) external;

/*
* This function completes the withdrawal process from Polygon to Mainnet.
* Burn proof is generated via API. Please see README.md
* @notice Mainnet only. Function will revert if called from other network.
* @param burnProof Burn proof generated via API.
*/
function exit(bytes calldata burnProof) external;

/*
* This function completes the withdrawal process from Polygon to Mainnet.
* Burn proofs are generated via API. Please see README.md
* @notice Mainnet only. Function will revert if called from other network.
* @param burnProofs Array of burn proofs generated via API.
*/
function exit(bytes[] calldata burnProofs) external;

/*
* Withdraws tokens on Mainnet contract to Aave V3 Collector.
* @notice Mainnet only. Function will revert if called from other network.
* @param token Mainnet address of token to withdraw to Collector
*/
function withdrawToCollector(address token) external;
}
2 changes: 2 additions & 0 deletions src/bridges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ And the generated proof: https://proof-generator.polygon.technology/api/v1/matic

The result is the bytes data that is later passed to `exit()`.

If doing multiple burns in one transaction, each has to be processed individually via exit. To get a specific logIndex to generate the correct proof when doing multiple, you can append to the API URL `&tokenIndex=[INDEX_OF_TARGET_LOG]`.

## Deployed Addresses

Mainnet:
Expand Down
68 changes: 62 additions & 6 deletions tests/bridges/AavePolEthERC20BridgeTest.t.sol

Large diffs are not rendered by default.