From fb22d3c4e3ac7963cb6544b46a33c44b86c4c333 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Mon, 19 Apr 2021 22:46:49 +0300 Subject: [PATCH] Return Mediator contract back --- eth-contracts/contracts/Mediator.sol | 26 +++++++++++++++++++ .../contracts/interfaces/IDioneOracle.sol | 6 +++++ eth-contracts/hardhat.config.ts | 8 ++++++ eth-contracts/scripts/deploy.ts | 13 +++++++--- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 eth-contracts/contracts/Mediator.sol create mode 100644 eth-contracts/contracts/interfaces/IDioneOracle.sol diff --git a/eth-contracts/contracts/Mediator.sol b/eth-contracts/contracts/Mediator.sol new file mode 100644 index 0000000..73eee90 --- /dev/null +++ b/eth-contracts/contracts/Mediator.sol @@ -0,0 +1,26 @@ +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/access/Ownable.sol"; +import "./interfaces/IDioneOracle.sol"; + +contract Mediator { + event DataReceived( + uint256 reqID, + string data + ); + + IDioneOracle dioneOracle; + + constructor(IDioneOracle _dioneOracle) { + dioneOracle = _dioneOracle; + } + + function request(uint8 originChain, string memory requestType, string memory requestParams) public returns (uint256) { + return dioneOracle.requestOracles(originChain, requestType, requestParams, address(this), bytes4(keccak256("_receiveDataCallback(uint256, string)"))); + } + + function _receiveDataCallback(uint256 reqID, string memory data) public { + require(msg.sender == address(dioneOracle)); + emit DataReceived(reqID, data); + } +} \ No newline at end of file diff --git a/eth-contracts/contracts/interfaces/IDioneOracle.sol b/eth-contracts/contracts/interfaces/IDioneOracle.sol new file mode 100644 index 0000000..c4f208e --- /dev/null +++ b/eth-contracts/contracts/interfaces/IDioneOracle.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.8.0; + +interface IDioneOracle { + function requestOracles(uint8 _originChain, string memory _requestType, string memory _requestParams, address _callbackAddress, bytes4 _callbackMethodID) external returns (uint256); + function cancelOracleRequest(uint256 _reqID) external; +} \ No newline at end of file diff --git a/eth-contracts/hardhat.config.ts b/eth-contracts/hardhat.config.ts index 1082291..4f46c1f 100644 --- a/eth-contracts/hardhat.config.ts +++ b/eth-contracts/hardhat.config.ts @@ -11,4 +11,12 @@ task("accounts", "Prints the list of accounts", async (args, hre) => { export default { solidity: "0.8.3", + networks: { + ganache: { + url: `http://localhost:7545`, + accounts: { + mnemonic: "test test test test test test test test test test test junk" + } + } + } }; \ No newline at end of file diff --git a/eth-contracts/scripts/deploy.ts b/eth-contracts/scripts/deploy.ts index e877cf4..b292e49 100644 --- a/eth-contracts/scripts/deploy.ts +++ b/eth-contracts/scripts/deploy.ts @@ -8,6 +8,7 @@ async function main() { const DioneOracle = await ethers.getContractFactory("DioneOracle"); const DioneDispute = await ethers.getContractFactory("DioneDispute"); const DioneStaking = await ethers.getContractFactory("DioneStaking"); + const Mediator = await ethers.getContractFactory("Mediator"); const dioneToken = await DioneToken.deploy(); await dioneToken.deployed(); @@ -15,15 +16,19 @@ async function main() { 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); + console.log("staking_contract_address = \"" + dioneStaking.address+ "\""); const dioneDispute = await DioneDispute.deploy(dioneStaking.address); await dioneDispute.deployed(); - console.log("DioneDispute deployed to:", dioneDispute.address); + console.log("dispute_contract_address = \"" + dioneDispute.address+ "\""); const dioneOracle = await DioneOracle.deploy(dioneStaking.address); await dioneOracle.deployed(); - console.log("DioneOracle deployed to:", dioneOracle.address); + console.log("oracle_contract_address = \"" + dioneOracle.address+ "\""); + + const mediator = await Mediator.deploy(dioneOracle.address); + await mediator.deployed(); + console.log("mediator_contract_address = \"" + mediator.address +"\"") await dioneStaking.setOracleContractAddress(dioneOracle.address); await dioneStaking.setDisputeContractAddress(dioneOracle.address); @@ -37,6 +42,8 @@ async function main() { await dioneToken.transfer(address, ethers.constants.WeiPerEther.mul(6000)); } + await dioneToken.transferOwnership(dioneStaking.address); + const signers = await ethers.getSigners(); for (var i = 0; i < addresses.length; i++) { const staking = dioneStaking.connect(signers[i]);