From 2ad190e4d2781d65b7f6cda16362f93ec98cb229 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 2 Aug 2022 14:59:08 +0200 Subject: [PATCH] chore: removed dysfunctional Set bridge --- package.json | 4 +- src/bridges/set/IssuanceBridge.sol | 127 --------------- src/test/bridges/set/SetUnit.t.sol | 240 ----------------------------- 3 files changed, 2 insertions(+), 369 deletions(-) delete mode 100644 src/bridges/set/IssuanceBridge.sol delete mode 100644 src/test/bridges/set/SetUnit.t.sol diff --git a/package.json b/package.json index 2d1969d3a..3b5b6b3a5 100644 --- a/package.json +++ b/package.json @@ -15,14 +15,14 @@ "clean": "rm -rf ./cache ./dest ./out ./artifacts ./typechain-types ./client-dest", "test": "yarn test:contracts && yarn test:clients", "test:clients": "yarn compile:typechain && jest test", - "test:pinned:14000000": "forge test --fork-block-number 14000000 --match-contract 'Element|Set|OracleHelper' -vvv --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c", + "test:pinned:14000000": "forge test --fork-block-number 14000000 --match-contract 'Element|OracleHelper' -vvv --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c", "test:pinned:14970000": "forge test --fork-block-number 14970000 -m 'testRedistributionSuccessfulSwap|testRedistributionExitWhenICREqualsMCR' -vvv --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c", "test:pinned:14972000": "forge test --fork-block-number 14972000 -m 'testRedistributionFailingSwap' -vvv --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c", "test:pinned:15000000": "forge test --fork-block-number 15220000 --match-contract 'StabilityPoolBridge' -vvv --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c", "test:pinned": "yarn test:pinned:14000000 && yarn test:pinned:14970000 && yarn test:pinned:14972000 && yarn test:pinned:15000000", "test:contracts:block": "forge test --fork-block-number", "cast": "cast", - "test:contracts": "forge test --no-match-contract 'Element|Set|AceOfZk|StabilityPoolBridge' --no-match-test 'testRedistribution' -vvv && yarn test:pinned", + "test:contracts": "forge test --no-match-contract 'Element|AceOfZk|StabilityPoolBridge' --no-match-test 'testRedistribution' -vvv && yarn test:pinned", "build": "yarn clean && yarn compile:typechain && yarn compile:client-dest", "formatting": "yarn prettier --write .", "formatting:check": "prettier --check .", diff --git a/src/bridges/set/IssuanceBridge.sol b/src/bridges/set/IssuanceBridge.sol deleted file mode 100644 index cdd9fbdf1..000000000 --- a/src/bridges/set/IssuanceBridge.sol +++ /dev/null @@ -1,127 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2022 Aztec. -pragma solidity >=0.8.4; - -import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; - -import {AztecTypes} from "../../aztec/libraries/AztecTypes.sol"; - -import {ISetToken} from "../../interfaces/set/ISetToken.sol"; -import {IController} from "../../interfaces/set/IController.sol"; -import {IExchangeIssuance} from "../../interfaces/set/IExchangeIssuance.sol"; -import {IRollupProcessor} from "../../aztec/interfaces/IRollupProcessor.sol"; - -import {BridgeBase} from "../base/BridgeBase.sol"; -import {ErrorLib} from "../base/ErrorLib.sol"; - -contract IssuanceBridge is BridgeBase { - using SafeERC20 for IERC20; - - IExchangeIssuance public constant EXCHANGE_ISSUANCE = IExchangeIssuance(0xc8C85A3b4d03FB3451e7248Ff94F780c92F884fD); - IController public constant SET_CONTROLLER = IController(0xa4c8d221d8BB851f83aadd0223a8900A6921A349); - - /** - * @notice Sets the addresses of RollupProcessor - * @param _rollupProcessor Address of the RollupProcessor.sol - */ - constructor(address _rollupProcessor) BridgeBase(_rollupProcessor) {} - - // Empty receive function for the contract to be able to receive ETH - receive() external payable {} - - /** - * @notice Sets all the important approvals. - * @param _tokens An array of token addresses to set approvals for. - * @dev This bridge never holds any ERC20s before or after an invocation of any of its functions. - * For this reason the following is not a security risk and makes the convert() function more gas efficient. - */ - function approveTokens(address[] calldata _tokens) external { - uint256 tokensLength = _tokens.length; - for (uint256 i; i < tokensLength; ) { - IERC20(_tokens[i]).safeIncreaseAllowance(ROLLUP_PROCESSOR, type(uint256).max); - IERC20(_tokens[i]).safeIncreaseAllowance(address(EXCHANGE_ISSUANCE), type(uint256).max); - unchecked { - ++i; - } - } - } - - /** - * @notice Function that allows to ISSUE or REDEEM SetToken in exchange for ETH or ERC20 - * @param _inputAssetA - If ISSUE SET: ETH or ERC20 | If REDEEM SET: SetToken - * @param _outputAssetA - If ISSUE SET: setToken | If REDEEM SET: ETH or ERC20 - * @param _inputValue - If ISSUE SET: ETH or ERC20 amount | If REDEEM SET: SetToken amount - * @param _auxData - minimum token amount received during redemption or minting - * @return outputValueA - If ISSUE SET: SetToken amount | If REDEEM SET: ETH or ERC20 amount - * @return isAsync a flag to toggle if this bridge interaction will return assets at a later - date after some third party contract has interacted with it via finalise() - */ - - function convert( - AztecTypes.AztecAsset calldata _inputAssetA, - AztecTypes.AztecAsset calldata, - AztecTypes.AztecAsset calldata _outputAssetA, - AztecTypes.AztecAsset calldata, - uint256 _inputValue, - uint256 _interactionNonce, - uint64 _auxData, - address - ) - external - payable - override(BridgeBase) - onlyRollup - returns ( - uint256 outputValueA, - uint256, - bool - ) - { - if (_inputValue == 0) revert ErrorLib.InvalidInput(); - - if (SET_CONTROLLER.isSet(address(_inputAssetA.erc20Address))) { - // User wants to redeem the underlying asset - if (_outputAssetA.assetType == AztecTypes.AztecAssetType.ETH) { - // redeem in exchange for ETH - outputValueA = EXCHANGE_ISSUANCE.redeemExactSetForETH( - ISetToken(address(_inputAssetA.erc20Address)), - _inputValue, // _amountSetToken - _auxData // __minEthOut - ); - IRollupProcessor(ROLLUP_PROCESSOR).receiveEthFromBridge{value: outputValueA}(_interactionNonce); - } else if (_outputAssetA.assetType == AztecTypes.AztecAssetType.ERC20) { - // redeem in exchange for ERC20 - outputValueA = EXCHANGE_ISSUANCE.redeemExactSetForToken( - ISetToken(address(_inputAssetA.erc20Address)), // _setToken, - IERC20(address(_outputAssetA.erc20Address)), // _outputToken, - _inputValue, // _amountSetToken, - _auxData // _minOutputReceive - ); - } else { - revert ErrorLib.InvalidInputA(); - } - } else if (SET_CONTROLLER.isSet(address(_outputAssetA.erc20Address))) { - // User wants to issue SetToken - if (_inputAssetA.assetType == AztecTypes.AztecAssetType.ETH) { - // User supplies ETH - outputValueA = EXCHANGE_ISSUANCE.issueSetForExactETH{value: _inputValue}( - ISetToken(address(_outputAssetA.erc20Address)), - _auxData // _minSetReceive - ); - } else if (_inputAssetA.assetType == AztecTypes.AztecAssetType.ERC20) { - // User supplies ERC20 - outputValueA = EXCHANGE_ISSUANCE.issueSetForExactToken( - ISetToken(address(_outputAssetA.erc20Address)), - IERC20(address(_inputAssetA.erc20Address)), - _inputValue, // _amountInput - _auxData // _minSetReceive - ); - } else { - revert ErrorLib.InvalidInputA(); - } - } else { - revert ErrorLib.InvalidInputA(); - } - } -} diff --git a/src/test/bridges/set/SetUnit.t.sol b/src/test/bridges/set/SetUnit.t.sol deleted file mode 100644 index 865e8d4c0..000000000 --- a/src/test/bridges/set/SetUnit.t.sol +++ /dev/null @@ -1,240 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2022 Aztec. -pragma solidity >=0.8.4; - -import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; - -import {IssuanceBridge} from "../../../bridges/set/IssuanceBridge.sol"; -import {IController} from "../../../interfaces/set/IController.sol"; -import {ISetToken} from "../../../interfaces/set/ISetToken.sol"; -import {AztecTypes} from "../../../aztec/libraries/AztecTypes.sol"; - -import {ErrorLib} from "../../../bridges/base/ErrorLib.sol"; - -import {Test} from "forge-std/Test.sol"; - -contract SetUnitTest is Test { - IERC20 public constant DAI = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F); - IERC20 public constant DPI = IERC20(0x1494CA1F11D487c2bBe4543E90080AeBa4BA3C2b); - - AztecTypes.AztecAsset internal emptyAsset; - - address private rollupProcessor; - - IssuanceBridge internal bridge; - - // @dev This method exists on RollupProcessor.sol. It's defined here in order to be able to receive ETH like a real - // rollup processor would. - function receiveEthFromBridge(uint256 _interactionNonce) external payable {} - - function setUp() public { - // In unit tests we set address of rollupProcessor to the address of this test contract - rollupProcessor = address(this); - - bridge = new IssuanceBridge(rollupProcessor); - - address[] memory tokens = new address[](2); - tokens[0] = address(DAI); - tokens[1] = address(DPI); - bridge.approveTokens(tokens); - - vm.label(tokens[0], "DAI"); - vm.label(tokens[1], "DPI"); - } - - function testInvalidCaller() public { - vm.prank(address(124)); - vm.expectRevert(ErrorLib.InvalidCaller.selector); - bridge.convert(emptyAsset, emptyAsset, emptyAsset, emptyAsset, 0, 0, 0, address(0)); - } - - function test0InputValue() public { - vm.expectRevert(ErrorLib.InvalidInput.selector); - bridge.convert(emptyAsset, emptyAsset, emptyAsset, emptyAsset, 0, 0, 0, address(0)); - } - - function testSetBridge() public { - // test if we can prefund rollup with tokens and ETH - uint256 depositAmountDai = 1e9; - uint256 depositAmountDpi = 2e9; - uint256 depositAmountEth = 1 ether; - - deal(address(DAI), rollupProcessor, depositAmountDai); - deal(address(DPI), rollupProcessor, depositAmountDpi); - deal(rollupProcessor, depositAmountEth); - - uint256 rollupBalanceDai = DAI.balanceOf(rollupProcessor); - uint256 rollupBalanceDpi = DPI.balanceOf(rollupProcessor); - uint256 rollupBalanceEth = rollupProcessor.balance; - - assertEq(depositAmountDai, rollupBalanceDai, "DAI balance must match"); - - assertEq(depositAmountDpi, rollupBalanceDpi, "DPI balance must match"); - - assertEq(depositAmountEth, rollupBalanceEth, "ETH balance must match"); - } - - function testIssueSetForExactToken() public { - // Pre-fund contract with DAI - uint256 depositAmountDai = 1e21; // 1000 DAI - deal(address(DAI), address(bridge), depositAmountDai); - - // DAI is input - AztecTypes.AztecAsset memory inputAsset = AztecTypes.AztecAsset({ - id: 1, - erc20Address: address(DAI), - assetType: AztecTypes.AztecAssetType.ERC20 - }); - - // DPI is output - AztecTypes.AztecAsset memory outputAsset = AztecTypes.AztecAsset({ - id: 1, - erc20Address: address(DPI), - assetType: AztecTypes.AztecAssetType.ERC20 - }); - - // Call bridge's convert function - (uint256 outputValueA, , ) = bridge.convert( - inputAsset, - emptyAsset, - outputAsset, - emptyAsset, - depositAmountDai, - 0, - 0, - address(0) - ); - - IERC20(outputAsset.erc20Address).transferFrom(address(bridge), rollupProcessor, outputValueA); - - uint256 rollupBalanceAfterDai = DAI.balanceOf(rollupProcessor); - uint256 rollupBalanceAfterDpi = DPI.balanceOf(rollupProcessor); - - assertEq(0, rollupBalanceAfterDai, "DAI balance after convert must match"); - - assertEq(outputValueA, rollupBalanceAfterDpi, "DPI balance after convert must match"); - - assertGt(rollupBalanceAfterDpi, 0, "DPI balance after must be > 0"); - } - - function testIssueSetForExactEth() public { - // Pre-fund contract with ETH - uint256 depositAmountEth = 1e17; // 0.1 ETH - deal(address(bridge), depositAmountEth); - - // DAI is input - AztecTypes.AztecAsset memory inputAsset = AztecTypes.AztecAsset({ - id: 1, - erc20Address: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, - assetType: AztecTypes.AztecAssetType.ETH - }); - - // DAI is output - AztecTypes.AztecAsset memory outputAsset = AztecTypes.AztecAsset({ - id: 1, - erc20Address: address(DPI), - assetType: AztecTypes.AztecAssetType.ERC20 - }); - - (uint256 outputValueA, , ) = bridge.convert( - inputAsset, - emptyAsset, - outputAsset, - emptyAsset, - depositAmountEth, - 0, - 0, - address(0) - ); - - IERC20(outputAsset.erc20Address).transferFrom(address(bridge), rollupProcessor, outputValueA); - - uint256 rollupBalanceAfterDpi = DPI.balanceOf(rollupProcessor); - - assertEq(outputValueA, rollupBalanceAfterDpi, "DPI balance after convert must match"); - - assertGt(rollupBalanceAfterDpi, 0, "DPI balance after must be > 0"); - } - - function testRedeemExactSetForToken() public { - // Pre-fund bridge contract DPI - uint256 depositAmountDpi = 1e20; // 100 DPI - deal(address(DPI), address(bridge), depositAmountDpi); - - // DPI is input - AztecTypes.AztecAsset memory inputAsset = AztecTypes.AztecAsset({ - id: 1, - erc20Address: address(DPI), - assetType: AztecTypes.AztecAssetType.ERC20 - }); - - // DAI is output - AztecTypes.AztecAsset memory outputAsset = AztecTypes.AztecAsset({ - id: 1, - erc20Address: address(DAI), - assetType: AztecTypes.AztecAssetType.ERC20 - }); - - // Call bridge's convert function - (uint256 outputValueA, , ) = bridge.convert( - inputAsset, - emptyAsset, - outputAsset, - emptyAsset, - depositAmountDpi, - 0, - 0, - address(0) - ); - - IERC20(outputAsset.erc20Address).transferFrom(address(bridge), rollupProcessor, outputValueA); - - uint256 rollupBalanceAfterDai = DAI.balanceOf(rollupProcessor); - uint256 rollupBalanceAfterDpi = DPI.balanceOf(rollupProcessor); - - // Checks after - assertEq(outputValueA, rollupBalanceAfterDai, "DAI balance after convert must match"); - - assertEq(rollupBalanceAfterDpi, 0, "DPI balance after convert must match"); - - assertGt(rollupBalanceAfterDai, 0, "DAI balance after must be > 0"); - } - - function testRedeemExactSetForEth() public { - // prefund bridge with tokens - uint256 depositAmountDpi = 1e20; // 100 DPI - deal(address(DPI), address(bridge), depositAmountDpi); - - // Maker sure rollupProcessor's ETH balance is 0 - deal(rollupProcessor, 0); - - // DPI is input - AztecTypes.AztecAsset memory inputAsset = AztecTypes.AztecAsset({ - id: 1, - erc20Address: address(DPI), - assetType: AztecTypes.AztecAssetType.ERC20 - }); - - // ETH is output - AztecTypes.AztecAsset memory outputAsset = AztecTypes.AztecAsset({ - id: 1, - erc20Address: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, - assetType: AztecTypes.AztecAssetType.ETH - }); - - (uint256 outputValueA, , ) = bridge.convert( - inputAsset, - emptyAsset, - outputAsset, - emptyAsset, - depositAmountDpi, - 0, - 0, - address(0) - ); - - // Checks after - assertEq(DPI.balanceOf(rollupProcessor), 0, "DPI balance after convert must be 0"); - assertEq(outputValueA, rollupProcessor.balance, "ETH balance after convert must match"); - } -}