From 4f1e95c93ea659423a8fcede2930f9387b3f7841 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 25 Jul 2023 09:02:07 +0800 Subject: [PATCH] use safeApprove & replace while loop for block rotations; --- contracts/core/index-fund/IndexFund.sol | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/contracts/core/index-fund/IndexFund.sol b/contracts/core/index-fund/IndexFund.sol index f46363750..fd595105a 100644 --- a/contracts/core/index-fund/IndexFund.sol +++ b/contracts/core/index-fund/IndexFund.sol @@ -262,10 +262,7 @@ contract IndexFund is IIndexFund, Storage, OwnableUpgradeable, ReentrancyGuard { // tokens must be transfered from the sender to this contract IERC20(token).safeTransferFrom(msg.sender, address(this), amount); // we give allowance to accounts contract - require( - IERC20(token).approve(registrarConfig.accountsContract, amount), - "Approval needed for Accounts Contract to spend" - ); + IERC20(token).safeApprove(registrarConfig.accountsContract, amount); if (fundId != 0) { // Depositor has chosen a specific fund to send tokens to. Send 100% to that fund. @@ -294,9 +291,8 @@ contract IndexFund is IIndexFund, Storage, OwnableUpgradeable, ReentrancyGuard { state.activeFund = nextActiveFund(); state.roundDonations = 0; - while (block.number >= state.nextRotationBlock) { - state.nextRotationBlock += state.config.fundRotation; - } + uint256 addIters = (block.number - state.nextRotationBlock).div(state.config.fundRotation); + state.nextRotationBlock += state.config.fundRotation.mul(addIters); } // send donation messages to Accounts contract processDonations(