-
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
ccd87af
commit f871058
Showing
7 changed files
with
1,632 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,4 @@ | |
"@zetachain/protocol-contracts": "^4.0.1", | ||
"ethers": "5.6.8" | ||
} | ||
} | ||
} |
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
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
34 changes: 34 additions & 0 deletions
34
packages/zevm-app-contracts/scripts/withdrawERC20/withdraw.ts
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,34 @@ | ||
import { isProtocolNetworkName } from "@zetachain/protocol-contracts"; | ||
import { ethers, network } from "hardhat"; | ||
|
||
import { ERC20__factory, WithdrawERC20__factory } from "../../typechain-types"; | ||
import { saveAddress } from "../address.helpers"; | ||
|
||
const networkName = network.name; | ||
|
||
async function main() { | ||
if (!isProtocolNetworkName(networkName)) throw new Error("Invalid network name"); | ||
|
||
const WithdrawERC20Factory = (await ethers.getContractFactory("WithdrawERC20")) as WithdrawERC20__factory; | ||
|
||
// const withdrawERC20 = await WithdrawERC20Factory.deploy(); | ||
// await withdrawERC20.deployed(); | ||
// console.log("WithdrawERC20 deployed to:", withdrawERC20.address); | ||
// saveAddress("withdrawERC20", withdrawERC20.address); | ||
|
||
const WithdrawERC20 = WithdrawERC20Factory.attach("0x16a790cf206bbcd30cb2e36cc7b1f890d260b80c"); | ||
const ERC20Factory = (await ethers.getContractFactory("ERC20")) as ERC20__factory; | ||
const erc20 = ERC20Factory.attach("0x0cbe0dF132a6c6B4a2974Fa1b7Fb953CF0Cc798a"); | ||
|
||
await erc20.approve(WithdrawERC20.address, ethers.utils.parseUnits("5", 6)); | ||
await WithdrawERC20.withdraw( | ||
erc20.address, | ||
ethers.utils.parseUnits("5", 6), | ||
"0x19caCb4c0A7fC25598CC44564ED0eCA01249fc31" | ||
); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
105 changes: 105 additions & 0 deletions
105
packages/zevm-app-contracts/test/withdrawERC20/withdrawERC20.ts
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,105 @@ | ||
import { parseUnits } from "@ethersproject/units"; | ||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; | ||
import { expect } from "chai"; | ||
import { parseEther } from "ethers/lib/utils"; | ||
import { ethers, network } from "hardhat"; | ||
|
||
import { Disperse, Disperse__factory, MockZRC20, MockZRC20__factory } from "../typechain-types"; | ||
|
||
describe("WithdrawERC20 tests", () => { | ||
let withdrawERC20Contract: WithdrawERC20; | ||
|
||
let accounts: SignerWithAddress[]; | ||
let deployer: SignerWithAddress; | ||
|
||
beforeEach(async () => { | ||
[deployer, ...accounts] = await ethers.getSigners(); | ||
|
||
await network.provider.send("hardhat_setBalance", [deployer.address, parseUnits("1000000").toHexString()]); | ||
|
||
const DisperseFactory = (await ethers.getContractFactory("Disperse")) as Disperse__factory; | ||
withdrawERC20Contract = (await DisperseFactory.deploy()) as Disperse; | ||
await withdrawERC20Contract.deployed(); | ||
}); | ||
|
||
describe("Disperse", () => { | ||
it("Should disperse ETH", async () => { | ||
const count = 500; | ||
const amount = parseEther("0.01"); | ||
const balance0 = await ethers.provider.getBalance(accounts[0].address); | ||
const balance1 = await ethers.provider.getBalance(accounts[1].address); | ||
|
||
const bigArrayAddress = new Array(count).fill(accounts[0].address); | ||
const bigArrayAmount = new Array(count).fill(amount); | ||
|
||
await withdrawERC20Contract.disperseEther(bigArrayAddress, bigArrayAmount, { | ||
value: amount.mul(count), | ||
}); | ||
|
||
const balance0After = await ethers.provider.getBalance(accounts[0].address); | ||
const balance1After = await ethers.provider.getBalance(accounts[1].address); | ||
|
||
expect(balance0After.sub(balance0)).to.be.eq(amount.mul(count)); | ||
expect(balance1After.sub(balance1)).to.be.eq(0); | ||
}); | ||
|
||
it("Should disperse ETH with surplus", async () => { | ||
const amount = parseUnits("10"); | ||
const balance0 = await ethers.provider.getBalance(accounts[0].address); | ||
const balance1 = await ethers.provider.getBalance(accounts[1].address); | ||
await withdrawERC20Contract.disperseEther([accounts[0].address, accounts[1].address], [amount, amount.mul(2)], { | ||
value: amount.mul(4), | ||
}); | ||
|
||
const balance0After = await ethers.provider.getBalance(accounts[0].address); | ||
const balance1After = await ethers.provider.getBalance(accounts[1].address); | ||
|
||
expect(balance0After.sub(balance0)).to.be.eq(amount); | ||
expect(balance1After.sub(balance1)).to.be.eq(amount.mul(2)); | ||
}); | ||
|
||
it("Should disperse token", async () => { | ||
const MockTokenFactory = (await ethers.getContractFactory("MockZRC20")) as MockZRC20__factory; | ||
const mockTokenContract = (await MockTokenFactory.deploy(1_000_000, "MOCK", "MOCK")) as MockZRC20; | ||
await mockTokenContract.deployed(); | ||
await mockTokenContract.approve(withdrawERC20Contract.address, parseUnits("1000000")); | ||
|
||
const amount = parseUnits("10"); | ||
const balance0 = await mockTokenContract.balanceOf(accounts[0].address); | ||
const balance1 = await mockTokenContract.balanceOf(accounts[1].address); | ||
await withdrawERC20Contract.disperseToken( | ||
mockTokenContract.address, | ||
[accounts[0].address, accounts[1].address], | ||
[amount, amount.mul(2)] | ||
); | ||
|
||
const balance0After = await mockTokenContract.balanceOf(accounts[0].address); | ||
const balance1After = await mockTokenContract.balanceOf(accounts[1].address); | ||
|
||
expect(balance0After.sub(balance0)).to.be.eq(amount); | ||
expect(balance1After.sub(balance1)).to.be.eq(amount.mul(2)); | ||
}); | ||
|
||
it("Should disperse token simple", async () => { | ||
const MockTokenFactory = (await ethers.getContractFactory("MockZRC20")) as MockZRC20__factory; | ||
const mockTokenContract = (await MockTokenFactory.deploy(1_000_000, "MOCK", "MOCK")) as MockZRC20; | ||
await mockTokenContract.deployed(); | ||
await mockTokenContract.approve(withdrawERC20Contract.address, parseUnits("1000000")); | ||
|
||
const amount = parseUnits("10"); | ||
const balance0 = await mockTokenContract.balanceOf(accounts[0].address); | ||
const balance1 = await mockTokenContract.balanceOf(accounts[1].address); | ||
await withdrawERC20Contract.disperseTokenSimple( | ||
mockTokenContract.address, | ||
[accounts[0].address, accounts[1].address], | ||
[amount, amount.mul(2)] | ||
); | ||
|
||
const balance0After = await mockTokenContract.balanceOf(accounts[0].address); | ||
const balance1After = await mockTokenContract.balanceOf(accounts[1].address); | ||
|
||
expect(balance0After.sub(balance0)).to.be.eq(amount); | ||
expect(balance1After.sub(balance1)).to.be.eq(amount.mul(2)); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.