Prepare eth contracts for Solidity 0.8.X, migrate to Embark framework

This commit is contained in:
ChronosX88 2021-04-14 00:22:30 +03:00
parent 4006a2effa
commit 8618f631f4
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
27 changed files with 27322 additions and 3702 deletions

View File

@ -1,6 +0,0 @@
# Ropsten
WEB3_NETWORK_ID=3
WEB3_INFURA_ID=please provide
MNEMONIC=please provide
ACCOUNT_ADDR=please provide
PRIVATE_KEY=please provie

View File

@ -1 +1,8 @@
*.abi
.embark
chains.json
config/livenet/password
config/production/password
coverage
dist
embarkArtifacts
node_modules

View File

@ -1,2 +0,0 @@
node_modules
contracts/Migrations.sol

View File

@ -1,20 +0,0 @@
{
"extends": "solium:recommended",
"plugins": [
"security"
],
"rules": {
"quotes": [
"error",
"double"
],
"indentation": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
]
}
}

View File

@ -1,3 +0,0 @@
# Dione Smart Contracts
Smart contracts to work with Secured Finance Dione oracle network.

View File

@ -0,0 +1,79 @@
// 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
}
},
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: {
//}
};

View File

@ -0,0 +1,75 @@
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
}
}
},
// 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: {}
};

View File

@ -0,0 +1 @@
dev_password

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,20 @@
{
"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"
}

View File

@ -0,0 +1 @@
dev_password

View File

@ -0,0 +1 @@
test_password

View File

@ -1,6 +1,6 @@
pragma solidity ^0.6.12;
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./interfaces/IDioneStaking.sol";
contract DioneDispute {
@ -25,12 +25,12 @@ contract DioneDispute {
event NewVote(bytes32 dhash, address indexed votedMiner);
event DisputeFinished(bytes32 dhash, bool status);
constructor(IDioneStaking _dioneStaking) public {
constructor(IDioneStaking _dioneStaking) {
dioneStaking = _dioneStaking;
}
function beginDispute(address miner, uint256 requestID) public {
bytes32 dhash = keccak256(abi.encodePacked(miner, requestID, now));
bytes32 dhash = keccak256(abi.encodePacked(miner, requestID, block.timestamp));
require(disputes[dhash].dhash.length != 0, "dispute already exists");
Dispute storage dispute = disputes[dhash];
dispute.dhash = dhash;
@ -38,7 +38,7 @@ contract DioneDispute {
dispute.finished = false;
dispute.disputeResult = false;
dispute.miner = miner;
dispute.timestamp = now;
dispute.timestamp = block.timestamp;
dispute.disputeInitiator = msg.sender;
disputes[dhash] = dispute;
@ -65,7 +65,7 @@ contract DioneDispute {
function finishDispute(bytes32 dhash) public {
require(disputes[dhash].dhash.length == 0, "dispute doesn't exist");
Dispute storage dispute = disputes[dhash];
require((now - dispute.timestamp) >= 2 hours, "vote window must be two hours");
require((block.timestamp - dispute.timestamp) >= 2 hours, "vote window must be two hours");
require(dispute.finished == false, "dispute already finished");
require(dispute.disputeInitiator == msg.sender, "only dispute initiator can call this function");
if (dispute.sum < 0) {

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IDioneStaking.sol";
@ -59,14 +59,14 @@ contract DioneOracle is Ownable {
_;
}
constructor(IDioneStaking _dioneStaking) public {
constructor(IDioneStaking _dioneStaking) {
dioneStaking = _dioneStaking;
}
function requestOracles(uint8 _originChain, string memory _requestType, string memory _requestParams, address _callbackAddress, bytes4 _callbackMethodID) public returns (uint256) {
requestCounter += 1;
require(pendingRequests[requestCounter] == 0, "This counter is not unique");
uint256 requestDeadline = now.add(MAXIMUM_DELAY);
uint256 requestDeadline = block.timestamp.add(MAXIMUM_DELAY);
pendingRequests[requestCounter] = keccak256(abi.encodePacked(_requestParams, _callbackAddress, _callbackMethodID, requestCounter, requestDeadline));
emit NewOracleRequest(_originChain, _requestType, _requestParams, _callbackAddress, _callbackMethodID, requestCounter, requestDeadline);
@ -76,7 +76,7 @@ contract DioneOracle is Ownable {
function cancelOracleRequest(string memory _requestParams, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline) public {
bytes32 requestHash = keccak256(abi.encodePacked(_requestParams, msg.sender, _callbackMethodID, _reqID, _requestDeadline));
require(requestHash == pendingRequests[_reqID], "Request hash do not match it's origin");
require(_requestDeadline <= now, "Request didn't reached it's deadline");
require(_requestDeadline <= block.timestamp, "Request didn't reached it's deadline");
delete pendingRequests[_reqID];
emit CancelOracleRequest(_reqID);

View File

@ -1,9 +1,9 @@
pragma solidity 0.6.12;
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./DioneToken.sol";
// DioneStaking is the main contract for Dione oracle network Proof-of-Stake mechanism
@ -22,8 +22,8 @@ contract DioneStaking is Ownable, ReentrancyGuard {
}
DioneToken public dione;
// Aggregator contract address.
address public aggregatorAddr;
// DioneOracle contract address.
address public dioneOracleAddress;
// Dispute contract address.
address public disputeContractAddr;
// Miner rewards in DIONE tokens.
@ -52,16 +52,16 @@ contract DioneStaking is Ownable, ReentrancyGuard {
uint256 _minerReward,
uint256 _startBlock,
uint256 _minimumStake
) public {
) {
dione = _dione;
minerReward = _minerReward;
minerReward = _minerReward**18;
startBlock = _startBlock;
minimumStake = _minimumStake;
minimumStake = _minimumStake**18;
}
// Mine new dione oracle task, only can be executed by aggregator contract
function mine(address _minerAddr) public nonReentrant {
require(msg.sender == aggregatorAddr, "not aggregator contract");
require(msg.sender == dioneOracleAddress, "not aggregator contract");
MinerInfo storage miner = minerInfo[_minerAddr];
require(miner.amount >= minimumStake);
dione.mint(_minerAddr, minerReward);
@ -71,7 +71,7 @@ contract DioneStaking is Ownable, ReentrancyGuard {
// Mine new dione oracle task and stake miner reward, only can be executed by aggregator contract
function mineAndStake(address _minerAddr) public nonReentrant {
require(msg.sender == aggregatorAddr, "not aggregator contract");
require(msg.sender == dioneOracleAddress, "not aggregator contract");
MinerInfo storage miner = minerInfo[_minerAddr];
require(miner.amount >= minimumStake);
dione.mint(address(this), minerReward);
@ -131,8 +131,12 @@ contract DioneStaking is Ownable, ReentrancyGuard {
minimumStake = _minimumStake;
}
function setAggregator(address _aggregatorAddr) public onlyOwner {
aggregatorAddr = _aggregatorAddr;
function setOracleContractAddress(address _addr) public onlyOwner {
dioneOracleAddress = _addr;
}
function setDisputeContractAddress(address _addr) public onlyOwner {
disputeContractAddr = _addr;
}
function slashMiner(address miner, address[] memory receipentMiners) public {
@ -144,4 +148,4 @@ contract DioneStaking is Ownable, ReentrancyGuard {
minerInfo[receipentMiners[i]].amount += share;
}
}
}
}

View File

@ -1,10 +1,13 @@
pragma solidity 0.6.12;
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
// DioneToken with Governance.
contract DioneToken is ERC20("DioneToken", "DIONE"), Ownable {
using SafeMath for uint256;
/// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
@ -17,7 +20,7 @@ contract DioneToken is ERC20("DioneToken", "DIONE"), Ownable {
// Which is copied and modified from COMPOUND:
// https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
/// @notice A record of each accounts delegate
// A record of each accounts delegate
mapping (address => address) internal _delegates;
/// @notice A checkpoint for marking number of votes from a given block
@ -115,7 +118,7 @@ contract DioneToken is ERC20("DioneToken", "DIONE"), Ownable {
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "DIONE::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "DIONE::delegateBySig: invalid nonce");
require(now <= expiry, "DIONE::delegateBySig: signature expired");
require(block.timestamp <= expiry, "DIONE::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
@ -235,9 +238,9 @@ contract DioneToken is ERC20("DioneToken", "DIONE"), Ownable {
return uint32(n);
}
function getChainId() internal pure returns (uint) {
function getChainId() internal view returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
}
}

View File

@ -9,10 +9,10 @@
// Ctrl+f for XXX to see all the modifications.
// XXX: pragma solidity ^0.5.16;
pragma solidity 0.6.12;
pragma solidity ^0.8.0;
// XXX: import "./SafeMath.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
contract Timelock {
using SafeMath for uint;
@ -36,7 +36,7 @@ contract Timelock {
mapping (bytes32 => bool) public queuedTransactions;
constructor(address admin_, uint delay_) public {
constructor(address admin_, uint delay_) {
require(delay_ >= MINIMUM_DELAY, "Timelock::constructor: Delay must exceed minimum delay.");
require(delay_ <= MAXIMUM_DELAY, "Timelock::constructor: Delay must not exceed maximum delay.");
@ -129,4 +129,4 @@ contract Timelock {
// solium-disable-next-line security/no-block-members
return block.timestamp;
}
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
pragma solidity ^0.8.0;
interface IDioneStaking {
function mine(address _minerAddr) external;
@ -13,5 +13,5 @@ interface IDioneStaking {
function isMiner(address _minerAddr) external view returns (bool);
function setMinimumStake(uint256 _minimumStake) external;
function setAggregator(address _aggregatorAddr) external;
function slashMiner(address miner, address[] memory receipentMiners) external;
}
function slashMiner(address miner, address[] calldata receipentMiners) external;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.

View File

@ -1,5 +1,5 @@
//SPDX-License-Identifier: MIT
pragma solidity >= 0.5.0 < 0.7.0;
pragma solidity ^0.8.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
@ -20,7 +20,7 @@ contract Ownable {
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
constructor () {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
@ -63,4 +63,4 @@ contract Ownable {
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
}

26
eth-contracts/embark.json Normal file
View File

@ -0,0 +1,26 @@
{
"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
}
}
}

View File

@ -1,18 +1,18 @@
const Whitelist = artifacts.require("Whitelist");
const OracleEmitter = artifacts.require("OracleEmitter");
const Aggregator = artifacts.require("Aggregator");
const Mediator = artifacts.require("Mediator");
const DioneToken = artifacts.require("DioneToken");
const DioneOracle = artifacts.require("DioneOracle");
const DioneDispute = artifacts.require("DioneDispute");
const DioneStaking = artifacts.require("DioneStaking");
module.exports = function (deployer) {
return deployer
.then(() => {
return deployer.deploy(Whitelist);
return deployer.deploy(DioneToken);
})
.then(() => {
return deployer.deploy(OracleEmitter);
return deployer.deploy(DioneStaking, DioneToken.address, web3.utils.toBN("10000000000000000000"), 0, web3.utils.toBN("5000000000000000000000"));
}).then(() => {
return deployer.deploy(Aggregator, Whitelist.address);
return deployer.deploy(DioneOracle, DioneStaking.address);
}).then(() => {
return deployer.deploy(Mediator, OracleEmitter.address, Aggregator.address);
return deployer.deploy(DioneDispute, DioneStaking.address);
});
};

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,21 @@
{
"name": "dione-smart-contracts",
"name": "dione",
"version": "0.0.1",
"description": "Smart contracts for Dione network",
"main": "truffle-config.js",
"directories": {
"test": "test"
},
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"compile": "truffle compile",
"fix-lint": "solium -d contracts/ --fix"
"test": "embark test"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"@truffle/hdwallet-provider": "^1.0.40",
"dotenv": "^8.2.0",
"ethlint": "^1.2.5",
"truffle": "^5.1.37",
"truffle-export-abi": "^1.0.1",
"truffle-flattener": "^1.5.0"
},
"devDependencies": {
"@openzeppelin/contracts": "^3.2.0"
"embark": "^6.0.0",
"embark-geth": "^6.0.0",
"embarkjs": "^6.0.0",
"embarkjs-ens": "^6.0.0",
"embarkjs-web3": "^6.0.0"
},
"dependencies": {
"@openzeppelin/contracts": "^4.0.0"
}
}

View File

@ -0,0 +1,41 @@
/*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);
});
});

View File

@ -1,41 +0,0 @@
require('dotenv').config();
const customProvider = (mnemonic, rpcEndpoint) => () =>
new HDWalletProvider(mnemonic, rpcEndpoint);
const infuraProvider = (network) =>
customProvider(
process.env.MNEMONIC || process.env.PRIVATE_KEY || '',
`https://${network}.infura.io/v3/${process.env.WEB3_INFURA_ID}`,
);
const ropstenProvider = infuraProvider('ropsten');
module.exports = {
networks: {
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 7545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},
ropsten: {
provider: ropstenProvider,
network_id: 3,
// gasPrice: 5000000000,
// gas: 4500000,
// gasPrice: 10000000000,
// confirmations: 0, // # of confs to wait between deployments. (default: 0)
skipDryRun: true,
},
},
compilers: {
solc: {
version: '0.6.12',
settings: {
optimizer: {
enabled: true, // Default: false
runs: 200, // Default: 200
},
},
},
}
};