Skip to content

Commit

Permalink
refactor : ERC20 transfer call using SafeERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh Sharma committed Sep 7, 2023
1 parent 8d397a7 commit 13fd8e1
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {AddressUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/Addr
import {ERC165Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol";
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {BytesLibrary} from "@manifoldxyz/royalty-registry-solidity/contracts/libraries/BytesLibrary.sol";
import {
IRoyaltySplitter,
Expand All @@ -34,6 +35,7 @@ contract RoyaltySplitter is
using AddressUpgradeable for address payable;
using AddressUpgradeable for address;
using SafeMath for uint256;
using SafeERC20 for IERC20;

uint256 internal constant TOTAL_BASIS_POINTS = 10000;
uint256 internal constant IERC20_APPROVE_SELECTOR =
Expand Down Expand Up @@ -164,20 +166,15 @@ contract RoyaltySplitter is

amountToSend /= TOTAL_BASIS_POINTS;
totalSent += amountToSend;
try erc20Contract.transfer(recipient.recipient, amountToSend) {
emit ERC20Transferred(address(erc20Contract), recipient.recipient, amountToSend);
} catch {
return false;
}

erc20Contract.safeTransfer(recipient.recipient, amountToSend);
emit ERC20Transferred(address(erc20Contract), recipient.recipient, amountToSend);
}
// Favor the 1st recipient if there are any rounding issues
amountToSend = balance - totalSent;
}
try erc20Contract.transfer(_recipients[0].recipient, amountToSend) {
emit ERC20Transferred(address(erc20Contract), _recipients[0].recipient, amountToSend);
} catch {
return false;
}
erc20Contract.safeTransfer(_recipients[0].recipient, amountToSend);
emit ERC20Transferred(address(erc20Contract), _recipients[0].recipient, amountToSend);
return true;
} catch {
return false;
Expand Down

1 comment on commit 13fd8e1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

96.30%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/asset/contracts
   Asset.sol94.53%89.58%96.43%98.08%103, 188, 293, 293–294, 65
   AssetCreate.sol94.51%83.33%100%100%130, 132, 165, 281, 68
   AssetReveal.sol94.35%86.21%96.55%98.89%143, 147, 181, 376, 416, 424, 441, 75, 98
   AuthSuperValidator.sol100%100%100%100%
   Catalyst.sol94.81%91.94%95.24%98.08%125, 127, 140, 152, 223, 80
packages/asset/contracts/interfaces
   IAsset.sol100%100%100%100%
   IAssetCreate.sol100%100%100%100%
   IAssetReveal.sol100%100%100%100%
   ICatalyst.sol100%100%100%100%
   ITokenUtils.sol100%100%100%100%
packages/asset/contracts/libraries
   TokenIdUtils.sol100%100%100%100%
packages/dependency-metatx/contracts
   ERC2771Handler.sol100%100%100%100%
   ERC2771HandlerAbstract.sol100%100%100%100%
   ERC2771HandlerUpgradeable.sol95.45%83.33%100%100%43
packages/dependency-metatx/contracts/test
   ERC2771HandlerTest.sol100%100%100%100%
   ERC2771HandlerUpgradeableTest.sol100%100%100%100%
   MockTrustedForwarder.sol0%0%0%0%15, 18–19, 19, 19–20
packages/dependency-operator-filter/contracts
   OperatorFiltererUpgradeable.sol82.35%85%71.43%83.33%17, 51–52, 61–62, 71, 87
   OperatorFilterSubscription.sol60%50%100%50%19–20
packages/dependency-operator-filter/contracts/interfaces
   IOperatorFilterRegistry.sol100%100%100%100%
packages/dependency-royalty-management/contracts
   MultiRoyaltyDistributor.sol85.33%65%90%93.33%106, 113, 153, 40, 40, 40, 40, 58–59, 75
   RoyaltyDistributor.sol76.92%50%75%85.71%45, 51
   RoyaltyManager.sol96.10%87.50%100%100%41, 91, 97
   RoyaltySplitter.sol92%75%91.67%97.06%111, 151, 180, 208, 59, 66, 76
packages/dependency-royalty-management/contracts/interfaces
   IERC20Approve.sol100%100%100%100%
   IMultiRoyaltyDistributor.sol100%100%100%100%
   IMultiRoyaltyRecipients.sol100%100%100%100%
   IRoyaltyManager.sol100%100%100%100%
   IRoyaltyUGC.sol100%100%100%100%

Please sign in to comment.