From ef7f3ab62576d5979996770912377f3d0f571f87 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Mon, 19 Sep 2022 16:29:17 +0300 Subject: [PATCH 1/3] updated multisender tests --- contracts/MultiSender/MultiSender.sol | 34 ++++++++++++++++++++++----- package.json | 2 +- test/16_MultiSender.js | 27 +++++++++++++++++++++ 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/contracts/MultiSender/MultiSender.sol b/contracts/MultiSender/MultiSender.sol index 21221df..695a5ee 100644 --- a/contracts/MultiSender/MultiSender.sol +++ b/contracts/MultiSender/MultiSender.sol @@ -8,6 +8,13 @@ import "./MultiManageable.sol"; /// @title main multi transfer settings /// @author The-Poolz contract team contract MultiSender is MultiManageable { + event MultiTransferredERC20( + address token, + uint256 userCount, + uint256 totalAmount + ); + event MultiTransferredETH(uint256 userCount, uint256 totalAmount); + constructor() { UserLimit = 500; } @@ -17,6 +24,11 @@ contract MultiSender is MultiManageable { _; } + modifier notZeroLength(uint256 _length) { + require(_length != 0, "array can't be zero length"); + _; + } + modifier checkUserLimit(uint256 _userLength) { require(UserLimit >= _userLength, "Invalid user limit"); _; @@ -30,37 +42,47 @@ contract MultiSender is MultiManageable { payable whenNotPaused checkArrLength(_users.length, _balances.length) + notZeroLength(_users.length) checkUserLimit(_users.length) { uint256 fee = _calcFee(); uint256 value = msg.value; PayFee(fee); if (fee > 0 && FeeToken == address(0)) value -= fee; - require( - value >= Array.getArraySum(_balances), - "Insufficient eth value sent!" - ); + uint256 amount = Array.getArraySum(_balances); + require(value == amount, "Insufficient eth value sent!"); for (uint256 i; i < _users.length; i++) { _users[i].transfer(_balances[i]); } + emit MultiTransferredETH(_users.length, amount); } function MultiSendERC20( address _token, - address payable[] memory _users, + address[] memory _users, uint256[] calldata _balances ) public payable whenNotPaused checkArrLength(_users.length, _balances.length) + notZeroLength(_users.length) checkUserLimit(_users.length) { require(_token != address(0), "Invalid token address"); - PayFee(_calcFee()); + uint256 fee = _calcFee(); + PayFee(fee); + if (FeeToken == address(0)) { + require(msg.value == fee, "Insufficient eth value sent!"); + } for (uint256 i; i < _users.length; i++) { IERC20(_token).transferFrom(msg.sender, _users[i], _balances[i]); } + emit MultiTransferredERC20( + _token, + _users.length, + Array.getArraySum(_balances) + ); } function _calcFee() internal returns (uint256) { diff --git a/package.json b/package.json index 5d726d8..9e58fdb 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "poolz-whitelist": "^1.0.5", "poolz-whitelist-converter": "^1.0.2", "uniswap-v2-test": "^1.0.2", - "poolz-multi-sender": "1.0.2", + "poolz-multi-sender": "1.0.4", "poolz-delay-vault": "1.0.2" }, "devDependencies": { diff --git a/test/16_MultiSender.js b/test/16_MultiSender.js index c26735a..b000972 100644 --- a/test/16_MultiSender.js +++ b/test/16_MultiSender.js @@ -102,4 +102,31 @@ contract("MultiSender and WhiteList integration tests", (accounts) => { const ethBal = await web3.eth.getBalance(instance.address) assert.equal(parseInt(oldEthBal) + discount, ethBal) }) + + it('should pass MultiSendEth', async () => { + await truffleAssert.passes(instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length + discount * 2})) + await instance.SetFeeAmount(0) + await truffleAssert.passes(instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length})) + await instance.SetFeeToken(feeToken.address) + await truffleAssert.passes(instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length})) + }) + + it("should pass MultiSendERC20", async () => { + await instance.SetFeeToken(constants.ZERO_ADDRESS) + await token.approve(instance.address, amount * amounts.length) + await truffleAssert.passes(instance.MultiSendERC20(token.address, accounts, amounts)) + await instance.SetFeeAmount(amount) + await token.approve(instance.address, amount * amounts.length) + await truffleAssert.passes(instance.MultiSendERC20(token.address, accounts, amounts, {value: amount})) + }) + + it("should revert MultiSendERC20 when sending the wrong fee", async () => { + await truffleAssert.reverts(instance.MultiSendERC20(token.address, accounts, amounts, {value: amount + 1}), "Insufficient eth value sent!") + await truffleAssert.reverts(instance.MultiSendERC20(token.address, accounts, amounts, {value: amount - 1}), "Not Enough Fee Provided") + }) + + it("should revert MultiSendETH when sending the wrong fee", async () => { + await truffleAssert.reverts(instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length + amount + 1}), "Insufficient eth value sent!") + await truffleAssert.reverts(instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length + amount - 1}), "Insufficient eth value sent!") + }) }) From 90ab8d3729957734c6fd71370f67983f532700aa Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Wed, 21 Sep 2022 12:11:22 +0300 Subject: [PATCH 2/3] updated MultiSender tests --- bin/build.sh | 46 +++++++++++++-------------- contracts/MultiSender/MultiSender.sol | 16 ++++++++-- package.json | 2 +- test/16_MultiSender.js | 11 ++++--- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/bin/build.sh b/bin/build.sh index 71b456d..2942465 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,49 +1,49 @@ -cp -a ./node_modules/poolz-back/contracts/. ./contracts/PoolzBack +# cp -a ./node_modules/poolz-back/contracts/. ./contracts/PoolzBack -cp -a ./node_modules/poolz-locked-deal/contracts/. ./contracts/LockedDeal +# cp -a ./node_modules/poolz-locked-deal/contracts/. ./contracts/LockedDeal -cp -a ./node_modules/poolz-locked-deal-v2/contracts/. ./contracts/LockedDealV2 +# cp -a ./node_modules/poolz-locked-deal-v2/contracts/. ./contracts/LockedDealV2 -cp -a ./node_modules/poolz-whitelist/contracts/. ./contracts/WhiteList +# cp -a ./node_modules/poolz-whitelist/contracts/. ./contracts/WhiteList -cp -a ./node_modules/poolz-benefit/contracts/. ./contracts/Benefit +# cp -a ./node_modules/poolz-benefit/contracts/. ./contracts/Benefit -cp -a ./node_modules/poolz-hodlers-whitelist/contracts/. ./contracts/HodlersWhitelist +# cp -a ./node_modules/poolz-hodlers-whitelist/contracts/. ./contracts/HodlersWhitelist -cp -a ./node_modules/poolz-envelop-token/contracts/. ./contracts/EnvelopToken +# cp -a ./node_modules/poolz-envelop-token/contracts/. ./contracts/EnvelopToken -cp -a ./node_modules/@uniswap/v2-core/contracts/. ./contracts/Uniswap-V2-Core +# cp -a ./node_modules/@uniswap/v2-core/contracts/. ./contracts/Uniswap-V2-Core -cp -a ./node_modules/poolz-whitelist-converter/contracts/. ./contracts/WhitelistConvertor +# cp -a ./node_modules/poolz-whitelist-converter/contracts/. ./contracts/WhitelistConvertor -cp -a ./node_modules/poolz-flex-staking/contracts/. ./contracts/FlexStaking +# cp -a ./node_modules/poolz-flex-staking/contracts/. ./contracts/FlexStaking cp -a ./node_modules/poolz-multi-sender/contracts/. ./contracts/MultiSender -cp -a ./node_modules/poolz-delay-vault/contracts/. ./contracts/DelayVault +# cp -a ./node_modules/poolz-delay-vault/contracts/. ./contracts/DelayVault -cp -a ./node_modules/poolz-back/test/General/. ./test/01_PoolzBack +# cp -a ./node_modules/poolz-back/test/General/. ./test/01_PoolzBack -cp -a ./node_modules/poolz-whitelist/test/. ./test/02_WhiteList +# cp -a ./node_modules/poolz-whitelist/test/. ./test/02_WhiteList -cp -a ./node_modules/poolz-locked-deal/test/. ./test/03_LockedDeal +# cp -a ./node_modules/poolz-locked-deal/test/. ./test/03_LockedDeal -cp -a ./node_modules/poolz-benefit/test/. ./test/04_Benefit +# cp -a ./node_modules/poolz-benefit/test/. ./test/04_Benefit -cp -a ./node_modules/poolz-hodlers-whitelist/test/. ./test/05_HodlersWhitelist +# cp -a ./node_modules/poolz-hodlers-whitelist/test/. ./test/05_HodlersWhitelist -cp -a ./node_modules/poolz-envelop-token/test/. ./test/06_EnvelopToken +# cp -a ./node_modules/poolz-envelop-token/test/. ./test/06_EnvelopToken -cp -a ./node_modules/uniswap-v2-test/. ./test/00_Uniswap-V2-Core +# cp -a ./node_modules/uniswap-v2-test/. ./test/00_Uniswap-V2-Core -cp -a ./node_modules/poolz-whitelist-converter/test/. ./test/12_WhitelistConverter +# cp -a ./node_modules/poolz-whitelist-converter/test/. ./test/12_WhitelistConverter -cp -a ./node_modules/poolz-locked-deal-v2/test/. ./test/14_LockedDealV2 +# cp -a ./node_modules/poolz-locked-deal-v2/test/. ./test/14_LockedDealV2 -cp -a ./node_modules/poolz-flex-staking/test/. ./test/FlexStaking +# cp -a ./node_modules/poolz-flex-staking/test/. ./test/FlexStaking -cp -a ./node_modules/poolz-multi-sender/test/. ./test/MultiSender +# cp -a ./node_modules/poolz-multi-sender/test/. ./test/MultiSender -cp -a ./node_modules/poolz-delay-vault/test/. ./test/DelayVault +# cp -a ./node_modules/poolz-delay-vault/test/. ./test/DelayVault #temporary fix for naming error of TestToken in Benefit tests #sed -i 's/"TestToken"/"Token"/g' test/4_Benefit/test.js \ No newline at end of file diff --git a/contracts/MultiSender/MultiSender.sol b/contracts/MultiSender/MultiSender.sol index 695a5ee..5b41ebb 100644 --- a/contracts/MultiSender/MultiSender.sol +++ b/contracts/MultiSender/MultiSender.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/utils/Strings.sol"; import "poolz-helper-v2/contracts/Array.sol"; import "./MultiManageable.sol"; @@ -50,7 +51,15 @@ contract MultiSender is MultiManageable { PayFee(fee); if (fee > 0 && FeeToken == address(0)) value -= fee; uint256 amount = Array.getArraySum(_balances); - require(value == amount, "Insufficient eth value sent!"); + require( + value == amount, + string.concat( + "Reqired Amount=", + Strings.toString(amount), + " Fee=", + Strings.toString(fee) + ) + ); for (uint256 i; i < _users.length; i++) { _users[i].transfer(_balances[i]); } @@ -73,7 +82,10 @@ contract MultiSender is MultiManageable { uint256 fee = _calcFee(); PayFee(fee); if (FeeToken == address(0)) { - require(msg.value == fee, "Insufficient eth value sent!"); + require( + msg.value == fee, + string.concat("Reqired ETH fee=", Strings.toString(fee)) + ); } for (uint256 i; i < _users.length; i++) { IERC20(_token).transferFrom(msg.sender, _users[i], _balances[i]); diff --git a/package.json b/package.json index 9e58fdb..f6ce453 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "poolz-whitelist": "^1.0.5", "poolz-whitelist-converter": "^1.0.2", "uniswap-v2-test": "^1.0.2", - "poolz-multi-sender": "1.0.4", + "poolz-multi-sender": "1.0.5", "poolz-delay-vault": "1.0.2" }, "devDependencies": { diff --git a/test/16_MultiSender.js b/test/16_MultiSender.js index b000972..91f9ed0 100644 --- a/test/16_MultiSender.js +++ b/test/16_MultiSender.js @@ -95,7 +95,7 @@ contract("MultiSender and WhiteList integration tests", (accounts) => { it('(multi ETH) pay with eth dicount', async () => { await instance.SetFeeToken(constants.ZERO_ADDRESS) await truffleAssert.reverts(instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length + discount}), - "Insufficient eth value sent!") + "Reqired Amount=" + amount * amounts.length + " Fee=" + amount) await whiteList.AddAddress(whiteListId, [accounts[0]], [discount]) const oldEthBal = await web3.eth.getBalance(instance.address) await instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length + discount}) @@ -121,12 +121,15 @@ contract("MultiSender and WhiteList integration tests", (accounts) => { }) it("should revert MultiSendERC20 when sending the wrong fee", async () => { - await truffleAssert.reverts(instance.MultiSendERC20(token.address, accounts, amounts, {value: amount + 1}), "Insufficient eth value sent!") + await truffleAssert.reverts(instance.MultiSendERC20(token.address, accounts, amounts, {value: amount + 1}), + "Reqired ETH fee=" + amount) await truffleAssert.reverts(instance.MultiSendERC20(token.address, accounts, amounts, {value: amount - 1}), "Not Enough Fee Provided") }) it("should revert MultiSendETH when sending the wrong fee", async () => { - await truffleAssert.reverts(instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length + amount + 1}), "Insufficient eth value sent!") - await truffleAssert.reverts(instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length + amount - 1}), "Insufficient eth value sent!") + await truffleAssert.reverts(instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length + amount + 1}), + "Reqired Amount=" + amount * amounts.length + " Fee=" + amount) + await truffleAssert.reverts(instance.MultiSendEth(accounts, amounts, {value: amount * amounts.length + amount - 1}), + "Reqired Amount=" + amount * amounts.length + " Fee=" + amount) }) }) From 2172db358eff4d97bad41bc7d67275a3651108d9 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Wed, 21 Sep 2022 12:12:31 +0300 Subject: [PATCH 3/3] uncomment build.sh --- bin/build.sh | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/bin/build.sh b/bin/build.sh index 2942465..71b456d 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,49 +1,49 @@ -# cp -a ./node_modules/poolz-back/contracts/. ./contracts/PoolzBack +cp -a ./node_modules/poolz-back/contracts/. ./contracts/PoolzBack -# cp -a ./node_modules/poolz-locked-deal/contracts/. ./contracts/LockedDeal +cp -a ./node_modules/poolz-locked-deal/contracts/. ./contracts/LockedDeal -# cp -a ./node_modules/poolz-locked-deal-v2/contracts/. ./contracts/LockedDealV2 +cp -a ./node_modules/poolz-locked-deal-v2/contracts/. ./contracts/LockedDealV2 -# cp -a ./node_modules/poolz-whitelist/contracts/. ./contracts/WhiteList +cp -a ./node_modules/poolz-whitelist/contracts/. ./contracts/WhiteList -# cp -a ./node_modules/poolz-benefit/contracts/. ./contracts/Benefit +cp -a ./node_modules/poolz-benefit/contracts/. ./contracts/Benefit -# cp -a ./node_modules/poolz-hodlers-whitelist/contracts/. ./contracts/HodlersWhitelist +cp -a ./node_modules/poolz-hodlers-whitelist/contracts/. ./contracts/HodlersWhitelist -# cp -a ./node_modules/poolz-envelop-token/contracts/. ./contracts/EnvelopToken +cp -a ./node_modules/poolz-envelop-token/contracts/. ./contracts/EnvelopToken -# cp -a ./node_modules/@uniswap/v2-core/contracts/. ./contracts/Uniswap-V2-Core +cp -a ./node_modules/@uniswap/v2-core/contracts/. ./contracts/Uniswap-V2-Core -# cp -a ./node_modules/poolz-whitelist-converter/contracts/. ./contracts/WhitelistConvertor +cp -a ./node_modules/poolz-whitelist-converter/contracts/. ./contracts/WhitelistConvertor -# cp -a ./node_modules/poolz-flex-staking/contracts/. ./contracts/FlexStaking +cp -a ./node_modules/poolz-flex-staking/contracts/. ./contracts/FlexStaking cp -a ./node_modules/poolz-multi-sender/contracts/. ./contracts/MultiSender -# cp -a ./node_modules/poolz-delay-vault/contracts/. ./contracts/DelayVault +cp -a ./node_modules/poolz-delay-vault/contracts/. ./contracts/DelayVault -# cp -a ./node_modules/poolz-back/test/General/. ./test/01_PoolzBack +cp -a ./node_modules/poolz-back/test/General/. ./test/01_PoolzBack -# cp -a ./node_modules/poolz-whitelist/test/. ./test/02_WhiteList +cp -a ./node_modules/poolz-whitelist/test/. ./test/02_WhiteList -# cp -a ./node_modules/poolz-locked-deal/test/. ./test/03_LockedDeal +cp -a ./node_modules/poolz-locked-deal/test/. ./test/03_LockedDeal -# cp -a ./node_modules/poolz-benefit/test/. ./test/04_Benefit +cp -a ./node_modules/poolz-benefit/test/. ./test/04_Benefit -# cp -a ./node_modules/poolz-hodlers-whitelist/test/. ./test/05_HodlersWhitelist +cp -a ./node_modules/poolz-hodlers-whitelist/test/. ./test/05_HodlersWhitelist -# cp -a ./node_modules/poolz-envelop-token/test/. ./test/06_EnvelopToken +cp -a ./node_modules/poolz-envelop-token/test/. ./test/06_EnvelopToken -# cp -a ./node_modules/uniswap-v2-test/. ./test/00_Uniswap-V2-Core +cp -a ./node_modules/uniswap-v2-test/. ./test/00_Uniswap-V2-Core -# cp -a ./node_modules/poolz-whitelist-converter/test/. ./test/12_WhitelistConverter +cp -a ./node_modules/poolz-whitelist-converter/test/. ./test/12_WhitelistConverter -# cp -a ./node_modules/poolz-locked-deal-v2/test/. ./test/14_LockedDealV2 +cp -a ./node_modules/poolz-locked-deal-v2/test/. ./test/14_LockedDealV2 -# cp -a ./node_modules/poolz-flex-staking/test/. ./test/FlexStaking +cp -a ./node_modules/poolz-flex-staking/test/. ./test/FlexStaking -# cp -a ./node_modules/poolz-multi-sender/test/. ./test/MultiSender +cp -a ./node_modules/poolz-multi-sender/test/. ./test/MultiSender -# cp -a ./node_modules/poolz-delay-vault/test/. ./test/DelayVault +cp -a ./node_modules/poolz-delay-vault/test/. ./test/DelayVault #temporary fix for naming error of TestToken in Benefit tests #sed -i 's/"TestToken"/"Token"/g' test/4_Benefit/test.js \ No newline at end of file