From 53d26d9bdec526c78641b8d9297ff73021849d28 Mon Sep 17 00:00:00 2001 From: farque65 Date: Wed, 13 Jul 2022 18:35:19 -0400 Subject: [PATCH 1/5] feat(react-app): updates the UI and adds more rows --- packages/hardhat/hardhat.config.js | 18 +++++++------- packages/react-app/src/App.jsx | 4 ++-- packages/react-app/src/components/Account.jsx | 17 ++++--------- packages/react-app/src/components/Header.jsx | 10 +++++--- packages/react-app/src/constants.js | 6 ++--- packages/react-app/src/views/Home.jsx | 24 ++++++++++++++----- yarn.lock | 4 ++-- 7 files changed, 45 insertions(+), 38 deletions(-) diff --git a/packages/hardhat/hardhat.config.js b/packages/hardhat/hardhat.config.js index ab6e3cd..effaf91 100644 --- a/packages/hardhat/hardhat.config.js +++ b/packages/hardhat/hardhat.config.js @@ -27,7 +27,7 @@ const { isAddress, getAddress, formatUnits, parseUnits } = utils; // // Select the network you want to deploy to here: // -const defaultNetwork = "localhost"; +const defaultNetwork = "rinkeby"; const mainnetGwei = 21; @@ -231,56 +231,56 @@ module.exports = { }, }, moonbeam: { - url: 'https://rpc.api.moonbeam.network', + url: "https://rpc.api.moonbeam.network", chainId: 1284, accounts: { mnemonic: mnemonic(), }, }, moonriver: { - url: 'https://rpc.api.moonriver.moonbeam.network', + url: "https://rpc.api.moonriver.moonbeam.network", chainId: 1285, accounts: { mnemonic: mnemonic(), }, }, moonbaseAlpha: { - url: 'https://rpc.api.moonbase.moonbeam.network', + url: "https://rpc.api.moonbase.moonbeam.network", chainId: 1287, accounts: { mnemonic: mnemonic(), }, }, moonbeamDevNode: { - url: 'http://127.0.0.1:9933', + url: "http://127.0.0.1:9933", chainId: 1281, accounts: { mnemonic: mnemonic(), }, }, godwoken: { - url: 'https://godwoken-testnet-v1.ckbapp.dev', + url: "https://godwoken-testnet-v1.ckbapp.dev", chainId: 71401, accounts: { mnemonic: mnemonic(), }, }, arbitrum: { - url: 'https://arb1.arbitrum.io/rpc', + url: "https://arb1.arbitrum.io/rpc", chainId: 42161, accounts: { mnemonic: mnemonic(), }, }, rinkebyArbitrum: { - url: 'https://rinkeby.arbitrum.io/rpc', + url: "https://rinkeby.arbitrum.io/rpc", chainId: 421611, accounts: { mnemonic: mnemonic(), }, }, devnetArbitrum: { - url: 'https://nitro-devnet.arbitrum.io/rpc', + url: "https://nitro-devnet.arbitrum.io/rpc", chainId: 421612, accounts: { mnemonic: mnemonic(), diff --git a/packages/react-app/src/App.jsx b/packages/react-app/src/App.jsx index 03893d0..fd719b5 100644 --- a/packages/react-app/src/App.jsx +++ b/packages/react-app/src/App.jsx @@ -73,11 +73,11 @@ const providers = [ function App(props) { // specify all the chains your app is available on. Eg: ['localhost', 'mainnet', ...otherNetworks ] // reference './constants.js' for other networks - const networkOptions = [initialNetwork.name, "mainnet", "rinkeby"]; + const networkOptions = [initialNetwork.name, "mainnet", "rinkeby", "goerli"]; const [injectedProvider, setInjectedProvider] = useState(); const [address, setAddress] = useState(); - const [selectedNetwork, setSelectedNetwork] = useState(networkOptions[0]); + const [selectedNetwork, setSelectedNetwork] = useState(networkOptions[3]); const location = useLocation(); const targetNetwork = NETWORKS[selectedNetwork]; diff --git a/packages/react-app/src/components/Account.jsx b/packages/react-app/src/components/Account.jsx index cb7b7c3..aba9bfd 100644 --- a/packages/react-app/src/components/Account.jsx +++ b/packages/react-app/src/components/Account.jsx @@ -58,20 +58,15 @@ export default function Account({ let accountButtonInfo; if (web3Modal?.cachedProvider) { - accountButtonInfo = { name: 'Logout', action: logoutOfWeb3Modal }; + accountButtonInfo = { name: "Logout", action: logoutOfWeb3Modal }; } else { - accountButtonInfo = { name: 'Connect', action: loadWeb3Modal }; + accountButtonInfo = { name: "Connect", action: loadWeb3Modal }; } const display = !minimized && ( {address && ( -
+
)} {!isContract && ( @@ -93,11 +88,7 @@ export default function Account({
{display} {web3Modal && ( - )} diff --git a/packages/react-app/src/components/Header.jsx b/packages/react-app/src/components/Header.jsx index 3e3d965..4af6f4d 100644 --- a/packages/react-app/src/components/Header.jsx +++ b/packages/react-app/src/components/Header.jsx @@ -8,11 +8,15 @@ const { Title, Text } = Typography; export default function Header({ link, title, subTitle, ...props }) { return (
-
+
- {title} + + {title} + - {subTitle} + + {subTitle} +
{props.children}
diff --git a/packages/react-app/src/constants.js b/packages/react-app/src/constants.js index bb21a68..809bbb8 100644 --- a/packages/react-app/src/constants.js +++ b/packages/react-app/src/constants.js @@ -124,21 +124,21 @@ export const NETWORKS = { color: "#28a0f0", chainId: 421611, blockExplorer: "https://testnet.arbiscan.io/", - rpcUrl: 'https://rinkeby.arbitrum.io/rpc', + rpcUrl: "https://rinkeby.arbitrum.io/rpc", }, arbitrum: { name: "arbitrum", color: "#28a0f0", chainId: 42161, blockExplorer: "https://arbiscan.io/", - rpcUrl: 'https://arb1.arbitrum.io/rpc', + rpcUrl: "https://arb1.arbitrum.io/rpc", }, devnetArbitrum: { name: "devnetArbitrum", color: "#28a0f0", chainId: 421612, blockExplorer: "https://nitro-devnet-explorer.arbitrum.io/", - rpcUrl: 'https://nitro-devnet.arbitrum.io/rpc', + rpcUrl: "https://nitro-devnet.arbitrum.io/rpc", }, localAvalanche: { name: "localAvalanche", diff --git a/packages/react-app/src/views/Home.jsx b/packages/react-app/src/views/Home.jsx index ad7754f..5100077 100644 --- a/packages/react-app/src/views/Home.jsx +++ b/packages/react-app/src/views/Home.jsx @@ -60,20 +60,32 @@ function Home({ tx, readContracts, address, writeContracts, mainnetProvider }) {
Staked Balance: {stakedBalance} {tokenSymbol}
-
+ {/*
Stake Locked:{" "} {stakes.locked ? "Yes" : "No"}{" "} -
+
*/}
- Stake + Get GTC Tokens
+
+
+ +
+ Approve Token For Stake +
+
+
+ +
+ Stake +
@@ -83,7 +95,7 @@ function Home({ tx, readContracts, address, writeContracts, mainnetProvider }) {
-
+
Unstake
-
+ {/*
Challenge
-
+
*/}
); } diff --git a/yarn.lock b/yarn.lock index 0b05ec7..73acbd5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11829,9 +11829,9 @@ glogg@^1.0.0: dependencies: sparkles "^1.0.0" -"gluegun@git+https://github.com/edgeandnode/gluegun.git#v4.3.1-pin-colors-dep": +"gluegun@https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep": version "4.3.1" - resolved "git+https://github.com/edgeandnode/gluegun.git#b34b9003d7bf556836da41b57ef36eb21570620a" + resolved "https://github.com/edgeandnode/gluegun#b34b9003d7bf556836da41b57ef36eb21570620a" dependencies: apisauce "^1.0.1" app-module-path "^2.2.0" From abed49700d7c9ab8fe78c1deb89b64304a7e3a61 Mon Sep 17 00:00:00 2001 From: Bliss Da Sailor Date: Thu, 14 Jul 2022 22:20:03 -0500 Subject: [PATCH 2/5] contract stake and unstake logic --- packages/hardhat/contracts/IStaking.sol | 79 ---------- packages/hardhat/contracts/Staking.sol | 149 ++---------------- ..._your_contract.js => 00_deploy_staking.js} | 2 +- packages/hardhat/hardhat.config.js | 2 +- 4 files changed, 18 insertions(+), 214 deletions(-) delete mode 100644 packages/hardhat/contracts/IStaking.sol rename packages/hardhat/deploy/{00_deploy_your_contract.js => 00_deploy_staking.js} (94%) diff --git a/packages/hardhat/contracts/IStaking.sol b/packages/hardhat/contracts/IStaking.sol deleted file mode 100644 index 8faaf6d..0000000 --- a/packages/hardhat/contracts/IStaking.sol +++ /dev/null @@ -1,79 +0,0 @@ -//SPDX-License-Identifier: MIT -pragma solidity >=0.8.0 <0.9.0; - -abstract contract IStaking { - uint256 public quorum; - - struct Stake { - uint256 balance; - bool locked; - } - - struct Challenge { - uint256 start; - bool resolved; - uint256 votes; - uint256 amount; - address challenger; - address[] stakers; - address[] voters; - mapping(address => bool) stakerList; - mapping(address => bool) voted; - } - - mapping(address => bool) jurors; - mapping(address => Stake) stakes; - mapping(bytes32 => Challenge) challenges; - - event jurorAction(address juror, bool added); - event tokenStaked(address staker, uint256 amount); - event tokenWithdrawn(address staker, uint256 amount); - event challenged(address challenger, bytes32 id); - event challengeVoted(bytes32 id, address juror); - event challengeFinalized(bytes32 id); - - modifier onlyJuror() { - require(jurors[msg.sender], "Jurors only allowed here"); - _; - } - - modifier challengeExists(bytes32 id) { - require( - !challenges[id].resolved && - challenges[id].challenger != address(0) && - challenges[id].amount > 0, - "Challenge has been resolved" - ); - _; - } - - // update Juror - function updateJuror(address juror, bool active) public virtual {} - - // stake - function stake(uint256 amount) public virtual {} - - // unstake - function unstake(uint256 amount) public virtual {} - - // challenge - function challenge(address[] memory stakers) - public - virtual - returns (bytes32 id) - {} - - // vote challenge - function voteChallenge(bytes32 id) public virtual {} - - // penalize - function finalizeChallenge(bytes32 id) public virtual {} - - // View functions - function getStakeFor(address user) public virtual returns (Stake memory) {} - - // to support receiving ETH by default - receive() external payable {} - - fallback() external payable {} -} diff --git a/packages/hardhat/contracts/Staking.sol b/packages/hardhat/contracts/Staking.sol index a2d5dfd..9dae2e9 100644 --- a/packages/hardhat/contracts/Staking.sol +++ b/packages/hardhat/contracts/Staking.sol @@ -1,159 +1,42 @@ -pragma solidity >=0.8.0 <0.9.0; - //SPDX-License-Identifier: MIT +pragma solidity >=0.8.0 <0.9.0; -import {IStaking} from "./IStaking.sol"; - -// import "hardhat/console.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -contract Staking is IStaking, Ownable { +contract Staking is Ownable { IERC20 public token; - uint256 public fee; - - constructor( - IERC20 _token, - uint256 _quorum, - uint256 _fee - ) payable { - token = _token; - fee = _fee; - quorum = _quorum; - } + mapping(address => uint256) stakes; - function updateJuror(address juror, bool active) - public - virtual - override - onlyOwner - { - jurors[juror] = active; + event tokenStaked(address staker, uint256 amount); + event tokenUnstaked(address staker, uint256 amount); - emit jurorAction(juror, active); + constructor(IERC20 _token) payable { + token = _token; } // stake - function stake(uint256 amount) public virtual override { + function stake(uint256 amount) public { token.transferFrom(msg.sender, address(this), amount); - stakes[msg.sender].balance += amount; + stakes[msg.sender] += amount; emit tokenStaked(msg.sender, amount); } - function unstake(uint256 amount) public virtual override { - require( - stakes[msg.sender].balance >= amount, - "Not enough balance to withdraw" - ); - require(!stakes[msg.sender].locked, "Your stakes are currently locked"); + // unstake + function unstake(uint256 amount) public { + require(stakes[msg.sender] >= amount, "Not enough balance to withdraw"); - stakes[msg.sender].balance -= amount; + stakes[msg.sender] -= amount; token.transfer(msg.sender, amount); - emit tokenWithdrawn(msg.sender, amount); - } - - function challenge(address[] memory stakers) - public - virtual - override - returns (bytes32 id) - { - // create challenge ID - id = keccak256(abi.encodePacked(msg.sender, block.number)); - uint256 totalStakers = stakers.length; - - require( - totalStakers > 0 && totalStakers < 255, - "Stakers out of bounds" - ); - require(challenges[id].challenger == address(0), "Non-unique ID"); - - // pay challenge fee - token.transferFrom(msg.sender, address(this), fee); - - // initiate challenge - challenges[id].amount = fee; - challenges[id].challenger = msg.sender; - - for (uint256 i = 0; i < totalStakers; i++) { - address currentStaker = stakers[i]; - require( - stakes[currentStaker].balance > 0, - "Not enough balance staked" - ); - require( - !challenges[id].stakerList[currentStaker], - "Duplicate staker in array" - ); - - stakes[currentStaker].locked = true; - challenges[id].stakers.push(currentStaker); - challenges[id].stakerList[currentStaker] = true; - } - - emit challenged(msg.sender, id); - } - - function voteChallenge(bytes32 id) - public - virtual - override - onlyJuror - challengeExists(id) - { - challenges[id].voted[msg.sender] = true; - challenges[id].votes += 1; - challenges[id].voters.push(msg.sender); - - emit challengeVoted(id, msg.sender); - } - - function finalizeChallenge(bytes32 id) - public - virtual - override - challengeExists(id) - { - challenges[id].resolved = true; - - uint256 amount = challenges[id].amount; - challenges[id].amount = 0; - address[] memory challengedAddresses = challenges[id].stakers; - - // slashes & payout - for (uint256 i = 0; i < challengedAddresses.length; i++) { - amount += stakes[challengedAddresses[i]].balance; - stakes[challengedAddresses[i]].balance = 0; - } - - uint256 totalVoters = challenges[id].voters.length; - - // split token among voters and challenger - uint256 share = ((amount * 80) / 100) / totalVoters; - token.transferFrom( - address(this), - challenges[id].challenger, - (amount * 20) / 100 - ); - - for (uint256 i = 0; i < totalVoters; i++) { - token.transferFrom(address(this), challenges[id].voters[i], share); - } - - emit challengeFinalized(id); + emit tokenUnstaked(msg.sender, amount); } - function getStakeFor(address user) - public - view - virtual - override - returns (Stake memory) - { + // view for stake amount + function getStakeFor(address user) public view returns (uint256) { return stakes[user]; } } diff --git a/packages/hardhat/deploy/00_deploy_your_contract.js b/packages/hardhat/deploy/00_deploy_staking.js similarity index 94% rename from packages/hardhat/deploy/00_deploy_your_contract.js rename to packages/hardhat/deploy/00_deploy_staking.js index 7d73d8d..8022965 100644 --- a/packages/hardhat/deploy/00_deploy_your_contract.js +++ b/packages/hardhat/deploy/00_deploy_staking.js @@ -17,7 +17,7 @@ module.exports = async ({ getNamedAccounts, deployments, getChainId }) => { const Token = await ethers.getContract("Token", deployer); - const stakingArgs = [Token.address, 3, ethers.utils.parseEther("20")]; + const stakingArgs = [Token.address]; await deploy("Staking", { // Learn more about args here: https://www.npmjs.com/package/hardhat-deploy#deploymentsdeploy diff --git a/packages/hardhat/hardhat.config.js b/packages/hardhat/hardhat.config.js index effaf91..8e21fc7 100644 --- a/packages/hardhat/hardhat.config.js +++ b/packages/hardhat/hardhat.config.js @@ -27,7 +27,7 @@ const { isAddress, getAddress, formatUnits, parseUnits } = utils; // // Select the network you want to deploy to here: // -const defaultNetwork = "rinkeby"; +const defaultNetwork = "localhost"; const mainnetGwei = 21; From 4c6857e59dd7b1e2836e89e2fdb77142a13f8289 Mon Sep 17 00:00:00 2001 From: Bliss Da Sailor Date: Thu, 14 Jul 2022 22:20:17 -0500 Subject: [PATCH 3/5] UI update for stake and unstake --- packages/react-app/src/App.jsx | 11 ++--------- packages/react-app/src/views/Home.jsx | 28 ++++++++------------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/packages/react-app/src/App.jsx b/packages/react-app/src/App.jsx index fd719b5..da1b195 100644 --- a/packages/react-app/src/App.jsx +++ b/packages/react-app/src/App.jsx @@ -1,13 +1,6 @@ import { Button, Col, Menu, Row } from "antd"; import "antd/dist/antd.css"; -import { - useBalance, - useContractLoader, - useContractReader, - useGasPrice, - useOnBlock, - useUserProviderAndSigner, -} from "eth-hooks"; +import { useBalance, useContractLoader, useGasPrice, useOnBlock, useUserProviderAndSigner } from "eth-hooks"; import { useExchangeEthPrice } from "eth-hooks/dapps/dex"; import React, { useCallback, useEffect, useState } from "react"; import { Link, Route, Switch, useLocation } from "react-router-dom"; @@ -77,7 +70,7 @@ function App(props) { const [injectedProvider, setInjectedProvider] = useState(); const [address, setAddress] = useState(); - const [selectedNetwork, setSelectedNetwork] = useState(networkOptions[3]); + const [selectedNetwork, setSelectedNetwork] = useState(networkOptions[0]); const location = useLocation(); const targetNetwork = NETWORKS[selectedNetwork]; diff --git a/packages/react-app/src/views/Home.jsx b/packages/react-app/src/views/Home.jsx index 5100077..bc6dd2f 100644 --- a/packages/react-app/src/views/Home.jsx +++ b/packages/react-app/src/views/Home.jsx @@ -1,23 +1,20 @@ -import React, { useState } from "react"; +import React from "react"; import { useContractReader } from "eth-hooks"; import { ethers } from "ethers"; -import { Button, Divider, Typography } from "antd"; -import { MultiAddressInput } from "../components"; -// import { Link } from "react-router-dom"; +import { Button, Divider } from "antd"; // TODO : Stake, unstake, challenge const zero = ethers.BigNumber.from("0"); function Home({ tx, readContracts, address, writeContracts, mainnetProvider }) { - const [challengeAddresses, setChallengeAddresses] = useState([]); - const tokenBalance = ethers.utils.formatUnits( useContractReader(readContracts, "Token", "balanceOf", [address]) || zero, ); const tokenSymbol = useContractReader(readContracts, "Token", "symbol"); - const stakes = useContractReader(readContracts, "Staking", "getStakeFor", [address]) || {}; - const stakedBalance = ethers.utils.formatUnits(stakes.balance || zero); + const stakedBalance = ethers.utils.formatUnits( + useContractReader(readContracts, "Staking", "getStakeFor", [address]) || zero, + ); const mintToken = async () => { tx(writeContracts.Token.mintAmount(ethers.utils.parseUnits("100"))); @@ -34,16 +31,11 @@ function Home({ tx, readContracts, address, writeContracts, mainnetProvider }) { }; const unstake = async amount => { - amount = amount || tokenBalance; + amount = amount || stakedBalance; tx(writeContracts.Staking.unstake(ethers.utils.parseUnits(amount))); }; - const challenge = async () => { - console.log(writeContracts.Staking.challenge); - tx(writeContracts.Staking.challenge(challengeAddresses)); - }; - return (
Staked Balance: {stakedBalance} {tokenSymbol}
- {/*
- Stake Locked:{" "} - {stakes.locked ? "Yes" : "No"}{" "} -
*/}
Get GTC Tokens @@ -98,10 +86,10 @@ function Home({ tx, readContracts, address, writeContracts, mainnetProvider }) {
Unstake
- -
From 8623200bbfdc40c530e9d9fec7c6d1fd2580d77b Mon Sep 17 00:00:00 2001 From: Bliss Da Sailor Date: Fri, 15 Jul 2022 16:20:13 -0500 Subject: [PATCH 4/5] added stake lock logic --- packages/hardhat/contracts/Staking.sol | 47 +++++++++++++++++++- packages/hardhat/deploy/00_deploy_staking.js | 3 ++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/hardhat/contracts/Staking.sol b/packages/hardhat/contracts/Staking.sol index 9dae2e9..3ad7b0d 100644 --- a/packages/hardhat/contracts/Staking.sol +++ b/packages/hardhat/contracts/Staking.sol @@ -6,15 +6,60 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; contract Staking is Ownable { IERC20 public token; + uint256 public start; + uint256 public duration; mapping(address => uint256) stakes; event tokenStaked(address staker, uint256 amount); event tokenUnstaked(address staker, uint256 amount); + modifier canUnstake() { + require( + (start == 0 && duration == 0) || + (start > block.timestamp) || + (start < block.timestamp && block.timestamp > start + duration), + "Can't unstake during an active round" + ); + _; + } + constructor(IERC20 _token) payable { token = _token; } + function updateMeta(uint256 _start, uint256 _duration) public onlyOwner { + require( + _start > 0 && _duration > 0, + "start and duration has to be > 0" + ); + require( + start + duration < block.timestamp, + "A round is currently active" + ); + require( + _start > block.timestamp, + "start point should be in the future" + ); + start = _start; + duration = _duration; + } + + function fetchMeta() + public + view + returns ( + uint256 _start, + uint256 _duration, + bool isActiveRound + ) + { + return ( + start, + duration, + start < block.timestamp && block.timestamp < (start + duration) + ); + } + // stake function stake(uint256 amount) public { token.transferFrom(msg.sender, address(this), amount); @@ -25,7 +70,7 @@ contract Staking is Ownable { } // unstake - function unstake(uint256 amount) public { + function unstake(uint256 amount) public canUnstake { require(stakes[msg.sender] >= amount, "Not enough balance to withdraw"); stakes[msg.sender] -= amount; diff --git a/packages/hardhat/deploy/00_deploy_staking.js b/packages/hardhat/deploy/00_deploy_staking.js index 8022965..a7622f1 100644 --- a/packages/hardhat/deploy/00_deploy_staking.js +++ b/packages/hardhat/deploy/00_deploy_staking.js @@ -9,6 +9,8 @@ module.exports = async ({ getNamedAccounts, deployments, getChainId }) => { const { deployer } = await getNamedAccounts(); const chainId = await getChainId(); + const admin = "0x77B8A624b2e8f6772C0f20c683b075E2bf778d64"; + await deploy("Token", { from: deployer, log: true, @@ -29,6 +31,7 @@ module.exports = async ({ getNamedAccounts, deployments, getChainId }) => { // Getting a previously deployed contract const Staking = await ethers.getContract("Staking", deployer); + await Staking.transferOwnership(admin); // Verify from the command line by running `yarn verify` From c57321ed439e30b7a0ac116901d44a6c80059ea7 Mon Sep 17 00:00:00 2001 From: Bliss Da Sailor Date: Fri, 15 Jul 2022 16:21:43 -0500 Subject: [PATCH 5/5] stake lock init UI --- packages/react-app/package.json | 1 + packages/react-app/src/views/Home.jsx | 70 +++++++++++++++++++++------ 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/packages/react-app/package.json b/packages/react-app/package.json index 0c3c7f1..e960e6b 100644 --- a/packages/react-app/package.json +++ b/packages/react-app/package.json @@ -44,6 +44,7 @@ "graphql": "^15.3.0", "ipfs-http-client": "^55.0.0", "isomorphic-fetch": "^3.0.0", + "moment": "^2.29.4", "node-watch": "^0.7.1", "postcss": "^8.2.6", "qrcode.react": "^1.0.0", diff --git a/packages/react-app/src/views/Home.jsx b/packages/react-app/src/views/Home.jsx index bc6dd2f..35421c8 100644 --- a/packages/react-app/src/views/Home.jsx +++ b/packages/react-app/src/views/Home.jsx @@ -1,13 +1,16 @@ import React from "react"; import { useContractReader } from "eth-hooks"; import { ethers } from "ethers"; -import { Button, Divider } from "antd"; +import { Button, Divider, Form, InputNumber } from "antd"; +import moment, { duration } from "moment"; // TODO : Stake, unstake, challenge const zero = ethers.BigNumber.from("0"); function Home({ tx, readContracts, address, writeContracts, mainnetProvider }) { + const [form] = Form.useForm(); + const tokenBalance = ethers.utils.formatUnits( useContractReader(readContracts, "Token", "balanceOf", [address]) || zero, ); @@ -15,6 +18,17 @@ function Home({ tx, readContracts, address, writeContracts, mainnetProvider }) { const stakedBalance = ethers.utils.formatUnits( useContractReader(readContracts, "Staking", "getStakeFor", [address]) || zero, ); + const [start, duration, isActiveRound] = useContractReader(readContracts, "Staking", "fetchMeta", []) || []; + + console.log({ isActiveRound }); + + const initialize = async v => { + const durationInSeconds = 86400 * parseInt(v.duration); + // const startInSeconds = Math.floor(Date.now() / 1000) + 120; + const startInSeconds = Math.floor(Date.now() / 1000) + 60; + + tx(writeContracts.Staking.updateMeta(startInSeconds, durationInSeconds)); + }; const mintToken = async () => { tx(writeContracts.Token.mintAmount(ethers.utils.parseUnits("100"))); @@ -52,6 +66,45 @@ function Home({ tx, readContracts, address, writeContracts, mainnetProvider }) {
Staked Balance: {stakedBalance} {tokenSymbol}
+ {start && start.gt(zero) && ( +
Start: {moment.unix(start.toString()).format("dddd, MMMM Do YYYY, h:mm:ss a")}
+ )} + {duration && duration.gt(zero) && ( +
End: {moment.unix(start.add(duration)).format("dddd, MMMM Do YYYY, h:mm:ss a")}
+ )} +
Is active round: {isActiveRound ? "Yes" : "No"}
+ +
+ Start New Staking Round +
+
+ 0", + }, + ]} + label="Duration (in days)" + > + + + + + +
+
+
Get GTC Tokens @@ -94,21 +147,6 @@ function Home({ tx, readContracts, address, writeContracts, mainnetProvider }) {
- - {/*
- Challenge -
- setChallengeAddresses(adds)} - /> - - -
-
*/}
); }