From 72b5da643bbebbe25b35d056f9c4bba0ac70a239 Mon Sep 17 00:00:00 2001 From: miguelmtzinf Date: Thu, 29 Jul 2021 18:20:43 +0200 Subject: [PATCH] feat: Replace non-available solidity instructions on OVM --- contracts/dependencies/openzeppelin/contracts/Address.sol | 6 +++++- contracts/misc/WalletBalanceProvider.sol | 3 ++- contracts/mocks/attacks/SefldestructTransfer.sol | 2 +- contracts/mocks/dependencies/weth/WETH9.sol | 5 ++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/contracts/dependencies/openzeppelin/contracts/Address.sol b/contracts/dependencies/openzeppelin/contracts/Address.sol index 3e0c92ac..a1466f1c 100644 --- a/contracts/dependencies/openzeppelin/contracts/Address.sol +++ b/contracts/dependencies/openzeppelin/contracts/Address.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; +import {IERC20} from './IERC20.sol'; + /** * @dev Collection of functions related to the address type */ @@ -52,7 +54,9 @@ library Address { * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { - require(address(this).balance >= amount, 'Address: insufficient balance'); + // require(address(this).balance >= amount, 'Address: insufficient balance'); + uint256 balance = IERC20(0x4200000000000000000000000000000000000006).balanceOf(address(this)); + require(balance >= amount, 'Address: insufficient balance'); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{value: amount}(''); diff --git a/contracts/misc/WalletBalanceProvider.sol b/contracts/misc/WalletBalanceProvider.sol index 22a6f55e..41b0c110 100644 --- a/contracts/misc/WalletBalanceProvider.sol +++ b/contracts/misc/WalletBalanceProvider.sol @@ -43,7 +43,8 @@ contract WalletBalanceProvider { **/ function balanceOf(address user, address token) public view returns (uint256) { if (token == MOCK_ETH_ADDRESS) { - return user.balance; // ETH balance + // return user.balance; // ETH balance + return IERC20(0x4200000000000000000000000000000000000006).balanceOf(user); // check if token is actually a contract } else if (token.isContract()) { return IERC20(token).balanceOf(user); diff --git a/contracts/mocks/attacks/SefldestructTransfer.sol b/contracts/mocks/attacks/SefldestructTransfer.sol index 6fe8e059..e052d739 100644 --- a/contracts/mocks/attacks/SefldestructTransfer.sol +++ b/contracts/mocks/attacks/SefldestructTransfer.sol @@ -3,6 +3,6 @@ pragma solidity 0.6.12; contract SelfdestructTransfer { function destroyAndTransfer(address payable to) external payable { - selfdestruct(to); + // selfdestruct(to); } } diff --git a/contracts/mocks/dependencies/weth/WETH9.sol b/contracts/mocks/dependencies/weth/WETH9.sol index b4b16281..2ba8a0c4 100644 --- a/contracts/mocks/dependencies/weth/WETH9.sol +++ b/contracts/mocks/dependencies/weth/WETH9.sol @@ -15,6 +15,8 @@ pragma solidity >=0.4.22 <=0.6.12; +import {IERC20} from '../../../dependencies/openzeppelin/contracts/IERC20.sol'; + contract WETH9 { string public name = 'Wrapped Ether'; string public symbol = 'WETH'; @@ -45,7 +47,8 @@ contract WETH9 { } function totalSupply() public view returns (uint256) { - return address(this).balance; + // return address(this).balance; + return IERC20(0x4200000000000000000000000000000000000006).balanceOf(address(this)); } function approve(address guy, uint256 wad) public returns (bool) {