Skip to content

Commit 51097a0

Browse files
committed
fix: add comments
1 parent 2fc7a03 commit 51097a0

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

contracts/MultiSender.sol

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,82 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.24;
33

4+
// Import required modules
45
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
56
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
67
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
78

9+
// Define the contract
810
contract MultiSender is Initializable {
11+
// Initialize the contract
912
function initialize() public initializer {}
1013

14+
// Event definitions
1115
event SendETH(address token, address[] recipients, uint256[] amounts);
1216
event SendERC20(address token, address[] recipients, uint256[] amounts);
1317

18+
// Function to send ETH to multiple recipients
1419
function sendETH(
1520
address[] calldata _recipients,
1621
uint256[] calldata _amounts
1722
) external payable {
23+
// Check if the lengths of recipients and amounts arrays are equal
1824
require(
1925
_recipients.length == _amounts.length,
2026
"Must have the same length"
2127
);
2228

29+
// Calculate the total amount to be sent
2330
uint256 totalAmount = 0;
2431
for (uint256 i = 0; i < _amounts.length; i++) {
2532
totalAmount += _amounts[i];
2633
}
2734

35+
// Check if the sender has enough ETH
2836
require(msg.value >= totalAmount, "Not enough ETH");
2937

30-
// Send ETH
38+
// Send ETH to recipients
3139
for (uint256 i = 0; i < _recipients.length; i++) {
3240
payable(_recipients[i]).transfer(_amounts[i]);
3341
}
3442

43+
// Emit the SendETH event
3544
emit SendETH(address(0), _recipients, _amounts);
3645
}
3746

47+
// Function to send ERC20 tokens to multiple recipients
3848
function sendERC20(
3949
address _token,
4050
address[] calldata _recipients,
4151
uint256[] calldata _amounts
4252
) external payable {
53+
// Check if the lengths of recipients and amounts arrays are equal
4354
require(
4455
_recipients.length == _amounts.length,
4556
"Must have the same length"
4657
);
4758

59+
// Calculate the total amount to be sent
4860
uint256 totalAmount = 0;
4961
for (uint256 i = 0; i < _amounts.length; i++) {
5062
totalAmount += _amounts[i];
5163
}
5264

65+
// Create an instance of the ERC20 token contract
5366
IERC20Upgradeable token = IERC20Upgradeable(_token);
67+
68+
// Check if the sender has enough tokens
5469
require(
5570
token.balanceOf(msg.sender) >= totalAmount,
5671
"Not enough tokens"
5772
);
5873

59-
// Send ERC20 tokens
74+
// Send tokens to each recipient
6075
for (uint256 i = 0; i < _recipients.length; i++) {
6176
token.transferFrom(msg.sender, _recipients[i], _amounts[i]);
6277
}
78+
79+
// Emit the SendERC20 event
6380
emit SendERC20(_token, _recipients, _amounts);
6481
}
6582
}

scripts/deploy.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { ethers, run } from 'hardhat';
1+
import { ethers } from 'hardhat';
22

33
async function main() {
4+
// Get the first signer from
45
const [deployer] = await ethers.getSigners();
56

67
console.log(
@@ -10,9 +11,11 @@ async function main() {
1011

1112
console.log("Account balance:", (await deployer.getBalance()).toString());
1213

14+
// Get the contract factory for the MultiSender contract
1315
const MultiSender = await ethers.getContractFactory("MultiSender");
16+
17+
// Deploy the MultiSender contract
1418
const multiSender = await MultiSender.deploy();
15-
1619
await multiSender.deployed();
1720

1821
console.log("MultiSender contract deployed to:", multiSender.address);

scripts/sendERC20.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import { ethers } from 'hardhat';
22

3-
const deployedMultiSender = '0x8161Bc94E430C246bF8CbE9a1d45Ad082df82065'
3+
// Replace with the actual contract address
4+
const deployedMultiSender = '0x8161Bc94E430C246bF8CbE9a1d45Ad082df82065' // MultiSender contract address
5+
// Replace with the actual token address, recipients and amounts
6+
const tokenAddress = "0xFF3Ef745D9878AfE5934Ff0b130868AFDDbc58e8"; // USDC Testnet Contract address
7+
const address1 = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' // Recipient 1
8+
const address2 = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8' // Recipient 2
49

510
async function main() {
6-
const multiSender = await ethers.getContractAt("MultiSender", deployedMultiSender);
11+
// Get the first signer
712
const [deployer] = await ethers.getSigners();
813

9-
// Replace with the actual token address, recipients and amounts
10-
const tokenAddress = "0xFF3Ef745D9878AfE5934Ff0b130868AFDDbc58e8"; // USDC Testnet
14+
// read the deployed contract
15+
const multiSender = await ethers.getContractAt("MultiSender", deployedMultiSender);
16+
17+
// get the contract factory for the ERC20 token
1118
const token = await ethers.getContractAt("ERC20", tokenAddress);
12-
// Replace with the actual recipients and amounts
13-
const address1 = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
14-
const address2 = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'
19+
1520
const recipients = [address1, address2];
1621
const amounts = [ethers.utils.parseUnits("1", 5), ethers.utils.parseUnits("2", 5)];
1722

scripts/sendETH.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ethers } from 'hardhat';
22

3-
const deployedMultiSender = '0x8161Bc94E430C246bF8CbE9a1d45Ad082df82065'
4-
3+
const deployedMultiSender = '0x8161Bc94E430C246bF8CbE9a1d45Ad082df82065' // Deployed MultiSender contract address
4+
const address1 = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' // Recipient 1
5+
const address2 = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8' // Recipient 2
6+
57
async function main() {
68

79
// read the deployed contract
@@ -10,8 +12,6 @@ async function main() {
1012
console.log("MultiSender contract address:", multiSender.address);
1113

1214
// Replace with the actual recipients and amounts
13-
const address1 = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
14-
const address2 = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'
1515
const recipients = [address1, address2];
1616
const amounts = [ethers.utils.parseEther("0.000001"), ethers.utils.parseEther("0.000002")];
1717

0 commit comments

Comments
 (0)