2021-01-29 05:26:28 +00:00
|
|
|
const hre = require("hardhat");
|
|
|
|
|
|
|
|
async function main() {
|
2021-02-02 05:07:16 +00:00
|
|
|
// Basic setup and definitions
|
2021-02-01 04:32:01 +00:00
|
|
|
var signers = await ethers.getSigners();
|
2021-02-02 05:07:16 +00:00
|
|
|
var aliceSigner = signers[0];
|
|
|
|
var bobSigner = signers[0];
|
2021-02-02 04:26:10 +00:00
|
|
|
var aliceAddress = signers[0].address;
|
|
|
|
var bobAddress = signers[1].address;
|
2021-02-01 04:32:01 +00:00
|
|
|
var DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT = ethers.BigNumber.from(86400)
|
|
|
|
|
2021-02-02 04:26:10 +00:00
|
|
|
// Deploy ERC20 Token
|
2021-01-29 05:26:28 +00:00
|
|
|
const ERC20 = await hre.ethers.getContractFactory("ERC20PresetMinterPauser");
|
|
|
|
var erc20 = await ERC20.deploy("TestToken", "TEST");
|
|
|
|
await erc20.deployed();
|
|
|
|
|
2021-01-29 05:27:31 +00:00
|
|
|
// Deploy SwapFactory
|
|
|
|
const SimpleSwapFactory = await hre.ethers.getContractFactory("SimpleSwapFactory");
|
|
|
|
var simpleSwapFactory = await SimpleSwapFactory.deploy(erc20.address);
|
|
|
|
await simpleSwapFactory.deployed();
|
2021-02-01 04:32:01 +00:00
|
|
|
|
2021-02-02 04:26:10 +00:00
|
|
|
// Setup Swap contract interface to parse logs
|
2021-02-01 04:32:01 +00:00
|
|
|
var swapFactoryArtifact = await artifacts.readArtifact("SimpleSwapFactory");
|
|
|
|
var swapFactoryInterface = new ethers.utils.Interface(swapFactoryArtifact.abi);
|
2021-02-02 04:26:10 +00:00
|
|
|
|
|
|
|
// Deploy Alice Swap and get address
|
|
|
|
var resp = await simpleSwapFactory.deploySimpleSwap(aliceAddress, DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT)
|
|
|
|
var logs = await ethers.provider.getLogs({address: simpleSwapFactory.address});
|
2021-02-03 05:04:01 +00:00
|
|
|
var aliceSwapAddress = swapFactoryInterface.parseLog(logs[0]).args.contractAddress;
|
2021-02-02 04:26:10 +00:00
|
|
|
|
|
|
|
// Deploy Bob Swap and get address
|
|
|
|
var resp = await simpleSwapFactory.deploySimpleSwap(bobAddress, DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT)
|
|
|
|
var logs = await ethers.provider.getLogs({address: simpleSwapFactory.address});
|
2021-02-03 05:04:01 +00:00
|
|
|
var bobSwapAddress = swapFactoryInterface.parseLog(logs[0]).args.contractAddress;
|
2021-02-02 05:07:16 +00:00
|
|
|
|
|
|
|
// Mint ERC20 tokens
|
|
|
|
// Alice is default account so issuer, which means she can mint tokens
|
|
|
|
// XXX Difference with getContractFactory above?
|
|
|
|
var erc20artifact = await artifacts.readArtifact("ERC20PresetMinterPauser");
|
|
|
|
var erc20contract = new ethers.Contract(erc20.address, erc20artifact.abi, aliceSigner);
|
|
|
|
await erc20contract.mint(aliceAddress, 10000);
|
|
|
|
await erc20contract.mint(bobAddress, 10000);
|
2021-02-02 04:26:10 +00:00
|
|
|
|
2021-02-02 05:07:16 +00:00
|
|
|
// Get ERC20 Balance
|
|
|
|
var aliceBalance = (await erc20contract.balanceOf(aliceAddress)).toNumber();
|
|
|
|
var bobBalance = (await erc20contract.balanceOf(bobAddress)).toNumber();
|
|
|
|
|
2021-02-03 03:53:40 +00:00
|
|
|
// Transfer money to Alice Swap address
|
|
|
|
await erc20contract.transfer(aliceSwapAddress, 5000);
|
|
|
|
var aliceSwapBalance = (await erc20contract.balanceOf(aliceSwapAddress)).toNumber();
|
|
|
|
|
2021-02-02 05:07:16 +00:00
|
|
|
// Print stuff
|
|
|
|
console.log("ERC20:", erc20.address);
|
|
|
|
console.log("SimpleSwapFactory:", simpleSwapFactory.address);
|
2021-02-02 04:26:10 +00:00
|
|
|
console.log("Alice address:", aliceAddress);
|
|
|
|
console.log("Bob address:", bobAddress);
|
2021-02-03 05:04:01 +00:00
|
|
|
console.log("AliceSwapAddress:", aliceSwapAddress)
|
|
|
|
console.log("BobSwapAddress:", bobSwapAddress)
|
2021-02-02 05:07:16 +00:00
|
|
|
console.log("Alice ERC20 balance:", aliceBalance);
|
|
|
|
console.log("Bob ERC20 balance:", bobBalance);
|
2021-02-03 03:53:40 +00:00
|
|
|
console.log("Alice Swap balance:", aliceSwapBalance);
|
2021-01-29 05:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We recommend this pattern to be able to use async/await everywhere
|
|
|
|
// and properly handle errors.
|
|
|
|
main()
|
|
|
|
.then(() => process.exit(0))
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|