Drop Embark, move to Hardhat, write fully automated deployment script
This commit is contained in:
parent
1f83763b70
commit
03f1b85170
2
eth-contracts/.gitignore
vendored
2
eth-contracts/.gitignore
vendored
@ -1,3 +1,3 @@
|
||||
node_modules
|
||||
artifacts
|
||||
artifacts/**
|
||||
cache
|
||||
|
@ -1,86 +0,0 @@
|
||||
// This file contains only the basic configuration you need to run Embark's node
|
||||
// For additional configurations, see: https://framework.embarklabs.io/docs/blockchain_configuration.html
|
||||
module.exports = {
|
||||
// default applies to all environments
|
||||
default: {
|
||||
enabled: true,
|
||||
client: "geth" // Can be ganache-cli, geth or parity (default: geth)
|
||||
},
|
||||
|
||||
development: {
|
||||
client: 'ganache-cli',
|
||||
clientConfig: {
|
||||
miningMode: 'dev' // Mode in which the node mines. Options: dev, auto, always, off
|
||||
},
|
||||
accounts: [
|
||||
{
|
||||
mnemonic: "magic lawn trumpet truth embody favorite radio saddle industry amount meadow vivid",
|
||||
balance: "1000 ether",
|
||||
numAddresses:"4"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
privatenet: {
|
||||
// Accounts to use as node accounts
|
||||
// The order here corresponds to the order of `web3.eth.getAccounts`, so the first one is the `defaultAccount`
|
||||
// For more account configurations, see: https://framework.embarklabs.io/docs/blockchain_accounts_configuration.html
|
||||
accounts: [
|
||||
{
|
||||
nodeAccounts: true, // Accounts use for the node
|
||||
numAddresses: "1", // Number of addresses/accounts (defaults to 1)
|
||||
password: "config/development/password" // Password file for the accounts
|
||||
}
|
||||
],
|
||||
clientConfig: {
|
||||
datadir: ".embark/privatenet/datadir", // Data directory for the databases and keystore
|
||||
miningMode: 'auto',
|
||||
genesisBlock: "config/privatenet/genesis.json" // Genesis block to initiate on first creation of a development node
|
||||
}
|
||||
},
|
||||
|
||||
privateparitynet: {
|
||||
client: "parity",
|
||||
genesisBlock: "config/privatenet/genesis-parity.json",
|
||||
datadir: ".embark/privatenet/datadir",
|
||||
miningMode: 'off'
|
||||
},
|
||||
|
||||
externalnode: {
|
||||
endpoint: "URL_OF_THE_NODE", // Endpoint of an node to connect to. Can be on localhost or on the internet
|
||||
accounts: [
|
||||
{
|
||||
mnemonic: "YOUR_MNEMONIC",
|
||||
hdpath: "m/44'/60'/0'/0/",
|
||||
numAddresses: "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
testnet: {
|
||||
networkType: "testnet", // Can be: testnet(ropsten), rinkeby, livenet or custom, in which case, it will use the specified networkId
|
||||
syncMode: "light",
|
||||
accounts: [
|
||||
{
|
||||
nodeAccounts: true,
|
||||
password: "config/testnet/password"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
livenet: {
|
||||
networkType: "livenet",
|
||||
syncMode: "light",
|
||||
accounts: [
|
||||
{
|
||||
nodeAccounts: true,
|
||||
password: "config/livenet/password"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// you can name an environment with specific settings and then specify with
|
||||
// "embark run custom_name" or "embark blockchain custom_name"
|
||||
//custom_name: {
|
||||
//}
|
||||
};
|
@ -1,78 +0,0 @@
|
||||
module.exports = {
|
||||
// default applies to all environments
|
||||
default: {
|
||||
// order of connections the dapp should connect to
|
||||
dappConnection: [
|
||||
"$WEB3", // uses pre existing web3 object if available (e.g in Mist)
|
||||
"ws://localhost:8546",
|
||||
"http://localhost:8545"
|
||||
],
|
||||
|
||||
// Automatically call `ethereum.enable` if true.
|
||||
// If false, the following code must run before sending any transaction: `await EmbarkJS.enableEthereum();`
|
||||
// Default value is true.
|
||||
// dappAutoEnable: true,
|
||||
|
||||
gas: "auto",
|
||||
|
||||
// Strategy for the deployment of the contracts:
|
||||
// - implicit will try to deploy all the contracts located inside the contracts directory
|
||||
// or the directory configured for the location of the contracts. This is default one
|
||||
// when not specified
|
||||
// - explicit will only attempt to deploy the contracts that are explicitly specified inside the
|
||||
// contracts section.
|
||||
// strategy: 'implicit',
|
||||
|
||||
// minimalContractSize, when set to true, tells Embark to generate contract files without the heavy bytecodes
|
||||
// Using filteredFields lets you customize which field you want to filter out of the contract file (requires minimalContractSize: true)
|
||||
// minimalContractSize: false,
|
||||
// filteredFields: [],
|
||||
|
||||
deploy: {
|
||||
DioneOracle: {
|
||||
args: ['$DioneStaking']
|
||||
},
|
||||
DioneDispute: {
|
||||
args: ['$DioneStaking']
|
||||
},
|
||||
DioneStaking: {
|
||||
args: ['$DioneToken', 10, 0, 5000]
|
||||
},
|
||||
ERC20: {
|
||||
deploy: false
|
||||
},
|
||||
Timelock: {
|
||||
deploy: false
|
||||
},
|
||||
SafeMath: {
|
||||
deploy: false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// default environment, merges with the settings in default
|
||||
// assumed to be the intended environment by `embark run`
|
||||
development: {
|
||||
dappConnection: [
|
||||
"ws://localhost:8546",
|
||||
"http://localhost:8545",
|
||||
"$WEB3" // uses pre existing web3 object if available (e.g in Mist)
|
||||
]
|
||||
},
|
||||
|
||||
// merges with the settings in default
|
||||
// used with "embark run privatenet"
|
||||
privatenet: {},
|
||||
|
||||
// merges with the settings in default
|
||||
// used with "embark run testnet"
|
||||
testnet: {},
|
||||
|
||||
// merges with the settings in default
|
||||
// used with "embark run livenet"
|
||||
livenet: {}
|
||||
|
||||
// you can name an environment with specific settings and then specify with
|
||||
// "embark run custom_name" or "embark blockchain custom_name"
|
||||
// custom_name: {}
|
||||
};
|
@ -1 +0,0 @@
|
||||
dev_password
|
File diff suppressed because one or more lines are too long
@ -1,20 +0,0 @@
|
||||
{
|
||||
"config": {
|
||||
"homesteadBlock": 0,
|
||||
"byzantiumBlock": 0,
|
||||
"eip155Block": 0,
|
||||
"eip158Block": 0,
|
||||
"daoForkSupport": true
|
||||
},
|
||||
"nonce": "0x0000000000000042",
|
||||
"difficulty": "0x0",
|
||||
"alloc": {
|
||||
"0x3333333333333333333333333333333333333333": {"balance": "15000000000000000000"}
|
||||
},
|
||||
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"coinbase": "0x3333333333333333333333333333333333333333",
|
||||
"timestamp": "0x00",
|
||||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"extraData": "0x",
|
||||
"gasLimit": "0x7a1200"
|
||||
}
|
@ -1 +0,0 @@
|
||||
dev_password
|
@ -1 +0,0 @@
|
||||
test_password
|
@ -54,14 +54,14 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
||||
uint256 _minimumStake
|
||||
) {
|
||||
dione = _dione;
|
||||
minerReward = _minerReward**18;
|
||||
minerReward = _minerReward;
|
||||
startBlock = _startBlock;
|
||||
minimumStake = _minimumStake**18;
|
||||
minimumStake = _minimumStake;
|
||||
}
|
||||
|
||||
// Mine new dione oracle task, only can be executed by aggregator contract
|
||||
function mine(address _minerAddr) public nonReentrant {
|
||||
require(msg.sender == dioneOracleAddress, "not aggregator contract");
|
||||
require(msg.sender == dioneOracleAddress, "not oracle contract");
|
||||
MinerInfo storage miner = minerInfo[_minerAddr];
|
||||
require(miner.amount >= minimumStake);
|
||||
dione.mint(_minerAddr, minerReward);
|
||||
@ -69,9 +69,9 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
||||
emit Mine(_minerAddr, block.number);
|
||||
}
|
||||
|
||||
// Mine new dione oracle task and stake miner reward, only can be executed by aggregator contract
|
||||
// Mine new dione oracle task and stake miner reward, only can be executed by oracle contract
|
||||
function mineAndStake(address _minerAddr) public nonReentrant {
|
||||
require(msg.sender == dioneOracleAddress, "not aggregator contract");
|
||||
require(msg.sender == dioneOracleAddress, "not oracle contract");
|
||||
MinerInfo storage miner = minerInfo[_minerAddr];
|
||||
require(miner.amount >= minimumStake);
|
||||
dione.mint(address(this), minerReward);
|
||||
|
@ -1,26 +0,0 @@
|
||||
{
|
||||
"contracts": [
|
||||
"contracts/**"
|
||||
],
|
||||
"app": {},
|
||||
"buildDir": "build/",
|
||||
"config": {
|
||||
"contracts": "config/contracts.js",
|
||||
"blockchain": "config/blockchain.js",
|
||||
"storage": false,
|
||||
"communication": false,
|
||||
"webserver": false
|
||||
},
|
||||
"versions": {
|
||||
"solc": "0.8.3"
|
||||
},
|
||||
"plugins": {
|
||||
"embark-geth": {}
|
||||
},
|
||||
"options": {
|
||||
"solc": {
|
||||
"optimize": true,
|
||||
"optimize-runs": 200
|
||||
}
|
||||
}
|
||||
}
|
14
eth-contracts/hardhat.config.ts
Normal file
14
eth-contracts/hardhat.config.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { task } from "hardhat/config";
|
||||
import "@nomiclabs/hardhat-ethers";
|
||||
|
||||
task("accounts", "Prints the list of accounts", async (args, hre) => {
|
||||
const accounts = await hre.ethers.getSigners();
|
||||
|
||||
for (const account of accounts) {
|
||||
console.log(await account.address);
|
||||
}
|
||||
});
|
||||
|
||||
export default {
|
||||
solidity: "0.8.3",
|
||||
};
|
28957
eth-contracts/package-lock.json
generated
28957
eth-contracts/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,19 +1,22 @@
|
||||
{
|
||||
"name": "dione",
|
||||
"version": "0.0.1",
|
||||
"name": "eth-contracts",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "embark test"
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"embark": "^6.0.0",
|
||||
"embark-geth": "^6.0.0",
|
||||
"embarkjs": "^6.0.0",
|
||||
"embarkjs-ens": "^6.0.0",
|
||||
"embarkjs-web3": "^6.0.0"
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
"@types/chai": "^4.2.16",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/node": "^14.14.39",
|
||||
"chai": "^4.3.4",
|
||||
"hardhat": "^2.1.2",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "^4.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@openzeppelin/contracts": "^4.0.0"
|
||||
|
55
eth-contracts/scripts/deploy.ts
Normal file
55
eth-contracts/scripts/deploy.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import { run, ethers } from "hardhat";
|
||||
|
||||
async function main() {
|
||||
await run("compile");
|
||||
|
||||
const DioneToken = await ethers.getContractFactory("DioneToken");
|
||||
const DioneOracle = await ethers.getContractFactory("DioneOracle");
|
||||
const DioneDispute = await ethers.getContractFactory("DioneDispute");
|
||||
const DioneStaking = await ethers.getContractFactory("DioneStaking");
|
||||
|
||||
const dioneToken = await DioneToken.deploy();
|
||||
await dioneToken.deployed();
|
||||
console.log("DioneToken deployed to:", dioneToken.address);
|
||||
|
||||
const dioneStaking = await DioneStaking.deploy(dioneToken.address, ethers.constants.WeiPerEther.mul(100), 0, ethers.constants.WeiPerEther.mul(5000));
|
||||
await dioneStaking.deployed();
|
||||
console.log("DioneStaking deployed to:", dioneStaking.address);
|
||||
|
||||
const dioneDispute = await DioneDispute.deploy(dioneStaking.address);
|
||||
await dioneDispute.deployed();
|
||||
console.log("DioneDispute deployed to:", dioneDispute.address);
|
||||
|
||||
const dioneOracle = await DioneOracle.deploy(dioneStaking.address);
|
||||
await dioneOracle.deployed();
|
||||
console.log("DioneOracle deployed to:", dioneOracle.address);
|
||||
|
||||
await dioneStaking.setOracleContractAddress(dioneOracle.address);
|
||||
await dioneStaking.setDisputeContractAddress(dioneOracle.address);
|
||||
|
||||
const addresses = ["0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC", "0x90F79bf6EB2c4f870365E785982E1f101E93b906"]
|
||||
await dioneToken.mint(addresses[0], ethers.constants.WeiPerEther.mul(50000));
|
||||
for (const address of addresses) {
|
||||
if(address == "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266") {
|
||||
continue;
|
||||
}
|
||||
await dioneToken.transfer(address, ethers.constants.WeiPerEther.mul(6000));
|
||||
}
|
||||
|
||||
const signers = await ethers.getSigners();
|
||||
for (var i = 0; i < addresses.length; i++) {
|
||||
const staking = dioneStaking.connect(signers[i]);
|
||||
const token = dioneToken.connect(signers[i]);
|
||||
await token.approve(dioneStaking.address, ethers.constants.WeiPerEther.mul(5000));
|
||||
await staking.stake(ethers.constants.WeiPerEther.mul(5000));
|
||||
const stake = await dioneStaking.minerStake(addresses[i]);
|
||||
console.log(addresses[i], stake.toString());
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
0
eth-contracts/test/.gitkeep
Normal file
0
eth-contracts/test/.gitkeep
Normal file
@ -1,41 +0,0 @@
|
||||
/*global artifacts, contract, it*/
|
||||
/*
|
||||
const SimpleStorage = artifacts.require('SimpleStorage');
|
||||
|
||||
let accounts;
|
||||
|
||||
// For documentation please see https://framework.embarklabs.io/docs/contracts_testing.html
|
||||
config({
|
||||
//deployment: {
|
||||
// accounts: [
|
||||
// // you can configure custom accounts with a custom balance
|
||||
// // see https://framework.embarklabs.io/docs/contracts_testing.html#Configuring-accounts
|
||||
// ]
|
||||
//},
|
||||
contracts: {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
}
|
||||
}
|
||||
}, (_err, web3_accounts) => {
|
||||
accounts = web3_accounts
|
||||
});*/
|
||||
|
||||
contract.skip("SimpleStorage", function () {
|
||||
|
||||
it("should set constructor value", async function () {
|
||||
let result = await SimpleStorage.methods.storedData().call();
|
||||
assert.strictEqual(parseInt(result, 10), 100);
|
||||
});
|
||||
|
||||
it("set storage value", async function () {
|
||||
await SimpleStorage.methods.set(150).send();
|
||||
let result = await SimpleStorage.methods.get().call();
|
||||
assert.strictEqual(parseInt(result, 10), 150);
|
||||
});
|
||||
|
||||
it("should have account with balance", async function() {
|
||||
let balance = await web3.eth.getBalance(accounts[0]);
|
||||
assert.ok(parseInt(balance, 10) > 0);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user