Skip to content

Commit

Permalink
hardhat demo
Browse files Browse the repository at this point in the history
  • Loading branch information
liushooter committed Nov 18, 2020
1 parent b7a314d commit 97b2ddb
Show file tree
Hide file tree
Showing 7 changed files with 7,298 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,8 @@ dist

# TernJS port file
.tern-port


artifacts
cache

34 changes: 34 additions & 0 deletions contracts/Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pragma solidity 0.6.12;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Token is ERC20 {
bool public synthesis;
uint public created;
address public owner;

address[] public materials;
uint[] public amounts;

constructor (string memory name, string memory symbol) public ERC20(name, symbol) {
synthesis = true;
created = block.timestamp;
owner = msg.sender;
}

function fuse(address[] memory _materials, uint[] memory _amounts) public {
require(_materials.length == _amounts.length );
require(_materials.length > 0, "materials > 0" );

materials = _materials;
amounts = _amounts;
}

function mint(address to, uint256 amount) public {
_mint(to, amount);
}

function burn(address to, uint256 amount) public {
_burn(to, amount);
}
}
33 changes: 33 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require("@nomiclabs/hardhat-waffle");

task("accounts", "Prints the list of accounts", async () => {
const accounts = await ethers.getSigners();

for (const account of accounts) {
console.log(account.address);
}
});

module.exports = {
defaultNetwork: "localhost",
networks: {
localhost: {
url: "http://127.0.0.1:8545"
},
hardhat: {}
// rinkeby: {
// url: "https://rinkeby.infura.io/v3/<token>",
// accounts: ["privateKey1"]
// }
},
solidity: {
version: "0.6.12",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
}
};

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "eth-hardhat-demo",
"version": "0.0.1",
"description": "eth hardhat demo",
"main": "index.js",
"repository": "https://github.com/liushooter/eth-hardhat-demo",
"author": "Rebase Team",
"license": "BSD-3-Clause",
"dependencies": {
"@openzeppelin/contracts": "^3.2.0",
"hardhat": "^2.0.3"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"chai": "^4.2.0",
"ethereum-waffle": "^3.0.0",
"ethers": "^5.0.0"
}
}
14 changes: 14 additions & 0 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
async function main() {
const Token = await ethers.getContractFactory("Token");

const token = await Token.deploy("abc", "def");

console.log("Token deployed to:", token.address);
}

main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
35 changes: 35 additions & 0 deletions test/token.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { expect } = require("chai");

describe("Token", function() {
it("fuse", async function() {
const Token = await ethers.getContractFactory("Token");

const a = "0x" + "1".repeat(40)
const b = "0x" + "2".repeat(40)

const _tokens = [a, b]
const _amounts = [200, 130]
const token = await Token.deploy("rebase", "rebase");
await token.deployed();

console.log("Token deployed to:", token.address);

await token.fuse(_tokens, _amounts);

const synthesis = await token.synthesis()
const created = await token.created()
const owner = await token.owner()

const materials = await token.materials(0)
const amounts = await token.amounts(0)

console.log(synthesis)
console.log(created.toNumber())
console.log(owner)

console.log(materials)
console.log(amounts.toNumber())

expect(synthesis).to.equal(true);
});
});
Loading

0 comments on commit 97b2ddb

Please sign in to comment.