-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20bf86d
commit b0129ae
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
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
24 changes: 24 additions & 0 deletions
24
packages/zevm-app-contracts/contracts/disperse/Disperse.sol
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.7; | ||
|
||
import "@openzeppelin/contracts/interfaces/IERC20.sol"; | ||
|
||
contract Disperse { | ||
function disperseEther(address[] calldata recipients, uint256[] calldata values) external payable { | ||
for (uint256 i = 0; i < recipients.length; i++) payable(recipients[i]).transfer(values[i]); | ||
uint256 balance = address(this).balance; | ||
if (balance > 0) payable(msg.sender).transfer(balance); | ||
} | ||
|
||
function disperseToken(IERC20 token, address[] calldata recipients, uint256[] calldata values) external { | ||
uint256 total = 0; | ||
for (uint256 i = 0; i < recipients.length; i++) total += values[i]; | ||
require(token.transferFrom(msg.sender, address(this), total)); | ||
for (uint256 i = 0; i < recipients.length; i++) require(token.transfer(recipients[i], values[i])); | ||
} | ||
|
||
function disperseTokenSimple(IERC20 token, address[] calldata recipients, uint256[] calldata values) external { | ||
for (uint256 i = 0; i < recipients.length; i++) | ||
require(token.transferFrom(msg.sender, recipients[i], values[i])); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isNetworkName } from "@zetachain/addresses"; | ||
import { saveAddress } from "@zetachain/addresses-tools"; | ||
import { ethers, network } from "hardhat"; | ||
|
||
import { Disperse__factory } from "../../typechain-types"; | ||
|
||
const networkName = network.name; | ||
|
||
async function main() { | ||
if (!isNetworkName(networkName)) throw new Error("Invalid network name"); | ||
|
||
const DisperseFactory = (await ethers.getContractFactory("Disperse")) as Disperse__factory; | ||
|
||
const disperseFactory = await DisperseFactory.deploy(); | ||
await disperseFactory.deployed(); | ||
console.log("Disperse deployed to:", disperseFactory.address); | ||
saveAddress("disperse", disperseFactory.address); | ||
} | ||
|
||
main().catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |