From e7e13bf44d208bebeef8c4fc5d92cfb72d05f1ee Mon Sep 17 00:00:00 2001 From: Sowmay Jain Date: Thu, 27 Aug 2020 16:56:36 +1000 Subject: [PATCH 1/7] removed an extra parameter from event --- contracts/flusher.sol | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/contracts/flusher.sol b/contracts/flusher.sol index 3ca6504..29beaab 100644 --- a/contracts/flusher.sol +++ b/contracts/flusher.sol @@ -37,27 +37,9 @@ contract Flusher { event LogInit(address indexed owner); event LogSwitch(bool indexed shieldState); - - event LogDeposit( - address indexed caller, - address indexed token, - address indexed tokenPool, - uint amount - ); - - event LogWithdraw( - address indexed caller, - address indexed token, - address indexed tokenPool, - uint amount - ); - - event LogWithdrawToOwner( - address indexed caller, - address indexed token, - address indexed owner, - uint amount - ); + event LogDeposit(address indexed token, address indexed tokenPool, uint amount); + event LogWithdraw(address indexed token, address indexed tokenPool,uint amount); + event LogWithdrawToOwner(address indexed token, address indexed owner, uint amount); function deposit(address token) public payable isSigner { require(address(token) != address(0), "invalid-token"); @@ -82,7 +64,7 @@ contract Flusher { } else { uint amt = tokenContract.balanceOf(address(this)); tokenContract.safeTransfer(owner, amt); - emit LogWithdrawToOwner(msg.sender, token, owner, amt); + emit LogWithdrawToOwner(token, owner, amt); } } @@ -92,7 +74,7 @@ contract Flusher { require(poolToken != address(0), "invalid-pool"); _amount = YieldPool(poolToken).withdraw(amount, owner); - emit LogWithdraw(msg.sender, token, poolToken, _amount); + emit LogWithdraw(token, poolToken, _amount); } /** @@ -110,7 +92,7 @@ contract Flusher { amount = tokenContract.balanceOf(address(this)); tokenContract.safeTransfer(address(owner), amount); } - emit LogWithdrawToOwner(msg.sender, token, owner, amount); + emit LogWithdrawToOwner(token, owner, amount); } function setBasic(address newOwner, address token) external { From 85bd5774b84fb3314e041b69a454e7438b2164e7 Mon Sep 17 00:00:00 2001 From: Sowmay Jain Date: Thu, 27 Aug 2020 16:57:27 +1000 Subject: [PATCH 2/7] removed "withdraw to owner" from deposit() method --- contracts/flusher.sol | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/contracts/flusher.sol b/contracts/flusher.sol index 29beaab..73ce97e 100644 --- a/contracts/flusher.sol +++ b/contracts/flusher.sol @@ -46,26 +46,20 @@ contract Flusher { address poolToken = registry.poolToken(token); IERC20 tokenContract = IERC20(token); - - if (poolToken != address(0)) { - YieldPool poolContract = YieldPool(poolToken); - uint amt; - if (address(tokenContract) == address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)) { - amt = address(this).balance; - poolContract.deposit{value: amt}(amt); - } else { - amt = tokenContract.balanceOf(address(this)); - if (tokenContract.allowance(address(this), address(poolContract)) == 0) - tokenContract.approve(address(poolContract), uint(-1)); - poolContract.deposit(amt); - } - emit LogDeposit(msg.sender, token, address(poolContract), amt); + YieldPool poolContract = YieldPool(poolToken); + uint amt; + if (address(tokenContract) == address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)) { + amt = address(this).balance; + poolContract.deposit{value: amt}(amt); } else { - uint amt = tokenContract.balanceOf(address(this)); - tokenContract.safeTransfer(owner, amt); - emit LogWithdrawToOwner(token, owner, amt); + amt = tokenContract.balanceOf(address(this)); + if (tokenContract.allowance(address(this), address(poolContract)) == 0) + tokenContract.approve(address(poolContract), uint(-1)); + + poolContract.deposit(amt); } + emit LogDeposit(msg.sender, token, address(poolContract), amt); } function withdraw(address token, uint amount) external isSigner returns (uint _amount) { From 51f2867cf1c15327e949f33d0b21eff52d33c4c3 Mon Sep 17 00:00:00 2001 From: Sowmay Jain Date: Thu, 27 Aug 2020 16:57:57 +1000 Subject: [PATCH 3/7] an open end to change owner via spell() --- contracts/flusher.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/contracts/flusher.sol b/contracts/flusher.sol index 73ce97e..e0b1a91 100644 --- a/contracts/flusher.sol +++ b/contracts/flusher.sol @@ -116,7 +116,6 @@ contract Flusher { require(_target != address(0), "target-invalid"); require(_data.length > 0, "data-invalid"); bytes memory _callData = _data; - address _owner = owner; assembly { let succeeded := delegatecall(gas(), _target, add(_callData, 0x20), mload(_callData), 0, 0) switch iszero(succeeded) @@ -127,7 +126,6 @@ contract Flusher { revert(0x00, size) } } - require(_owner == owner, "owner-change-denied"); } receive() external payable {} From 3582cf30ec5dd566fe6772b4473b94382905edb7 Mon Sep 17 00:00:00 2001 From: Sowmay Jain Date: Thu, 27 Aug 2020 17:00:02 +1000 Subject: [PATCH 4/7] revert: can't change flusher owner in any case --- contracts/flusher.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/flusher.sol b/contracts/flusher.sol index e0b1a91..73ce97e 100644 --- a/contracts/flusher.sol +++ b/contracts/flusher.sol @@ -116,6 +116,7 @@ contract Flusher { require(_target != address(0), "target-invalid"); require(_data.length > 0, "data-invalid"); bytes memory _callData = _data; + address _owner = owner; assembly { let succeeded := delegatecall(gas(), _target, add(_callData, 0x20), mload(_callData), 0, 0) switch iszero(succeeded) @@ -126,6 +127,7 @@ contract Flusher { revert(0x00, size) } } + require(_owner == owner, "owner-change-denied"); } receive() external payable {} From 56bfe94a643920a6fdc2d189161d6e68bd4e8305 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Thu, 27 Aug 2020 12:33:44 +0530 Subject: [PATCH 5/7] Added more require statement in `setBasic()` func --- contracts/flusher.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/flusher.sol b/contracts/flusher.sol index e0b1a91..d93636b 100644 --- a/contracts/flusher.sol +++ b/contracts/flusher.sol @@ -91,6 +91,8 @@ contract Flusher { function setBasic(address newOwner, address token) external { require(owner == address(0), "already-an-owner"); + require(newOwner != address(0), "not-vaild-owner-address"); + require(token != address(0), "not-vaild-token-address"); owner = payable(newOwner); deposit(token); emit LogInit(newOwner); From 1964045812a38555db9379385576bdb3e5f8a68e Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Thu, 27 Aug 2020 12:34:30 +0530 Subject: [PATCH 6/7] Fixed deposit event error --- contracts/flusher.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/flusher.sol b/contracts/flusher.sol index 6412226..875ed82 100644 --- a/contracts/flusher.sol +++ b/contracts/flusher.sol @@ -59,7 +59,7 @@ contract Flusher { poolContract.deposit(amt); } - emit LogDeposit(msg.sender, token, address(poolContract), amt); + emit LogDeposit(token, address(poolContract), amt); } function withdraw(address token, uint amount) external isSigner returns (uint _amount) { From 66bee61f9f0a3ba564f051c47657c1b334318aaa Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Thu, 27 Aug 2020 12:35:41 +0530 Subject: [PATCH 7/7] checking is there is token pool or not --- contracts/flusher.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/flusher.sol b/contracts/flusher.sol index 875ed82..9da72af 100644 --- a/contracts/flusher.sol +++ b/contracts/flusher.sol @@ -45,6 +45,8 @@ contract Flusher { require(address(token) != address(0), "invalid-token"); address poolToken = registry.poolToken(token); + require(poolToken != address(0), "invalid-pool"); + IERC20 tokenContract = IERC20(token); YieldPool poolContract = YieldPool(poolToken);