Created
January 17, 2023 06:34
-
-
Save kricha/3618b8cebb6676192c09a82a695a7d98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.0; | |
interface IERC20 { | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address account) external view returns (uint256); | |
function transfer(address to, uint256 amount) external returns (bool); | |
function allowance(address owner, address spender) external view returns (uint256); | |
function approve(address spender, uint256 amount) external returns (bool); | |
function transferFrom(address from, address to, uint256 amount ) external returns (bool); | |
} | |
contract BulkTransfer { | |
constructor () {} | |
function execute(IERC20 _token, address[] memory _recipients, uint256[] memory _amounts) external { | |
uint256 total = 0; | |
for (uint256 i = 0; i < _amounts.length; i++) { | |
total += _amounts[i]; | |
} | |
_token.approve(msg.sender, total); | |
_token.transferFrom(msg.sender, address(this), total); | |
require(_recipients.length == _amounts.length, "Invalid recipient and amount arrays"); | |
for (uint256 i = 0; i < _recipients.length; i++) { | |
_token.transfer(_recipients[i], _amounts[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment