From ae7ded3a7ccfc975e3f782cc1f2badcd6d62b914 Mon Sep 17 00:00:00 2001 From: hans Date: Sun, 28 Nov 2021 00:11:52 +0000 Subject: [PATCH 1/6] added: DAI (pos) on Polygon --- packages/hardhat/hardhat.config.js | 12 ++++---- packages/react-app/src/dips/helpers.js | 38 +++++++++++++------------ packages/react-app/src/views/Create.jsx | 9 ++++++ 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/packages/hardhat/hardhat.config.js b/packages/hardhat/hardhat.config.js index dd8a0b59..a14d2886 100644 --- a/packages/hardhat/hardhat.config.js +++ b/packages/hardhat/hardhat.config.js @@ -78,13 +78,11 @@ module.exports = { gasPrice: 1000000000, accounts: [`${process.env.POLYGON_DEPLOYER_PRIV_KEY}`], }, - // matic: { - // url: "https://rpc-mainnet.maticvigil.com/", - // gasPrice: 1000000000, - // accounts: { - // mnemonic: mnemonic(), - // }, - // }, + matic: { + url: "https://rpc-mainnet.maticvigil.com/", + gasPrice: 1000000000, + accounts: [`${process.env.POLYGON_DEPLOYER_PRIV_KEY}`], + }, // rinkebyArbitrum: { // url: "https://rinkeby.arbitrum.io/rpc", // gasPrice: 0, diff --git a/packages/react-app/src/dips/helpers.js b/packages/react-app/src/dips/helpers.js index a6ce057e..eb5f3f4a 100644 --- a/packages/react-app/src/dips/helpers.js +++ b/packages/react-app/src/dips/helpers.js @@ -10,6 +10,8 @@ export const CERAMIC_PREFIX = "ceramic://"; const CURRENCY = "ETH"; const TOKEN = process.env.REACT_APP_TOKEN_SYMBOL; const TOKEN_ADR = process.env.REACT_APP_TOKEN_ADDRESS; +const STABLE = process.env.REACT_APP_STABLE_TOKEN; +const STABLE_ADR = process.env.REACT_APP_STABLE_ADDRESS; //// PASTE HERE export const getAllCeramicElections = async (contract, ceramic) => { @@ -187,24 +189,24 @@ export const getCeramicElectionIds = async diplomatContract => { return elections; }; -// export const getNetwork = async () => { -// const web3Modal = new Web3Modal(); -// const connection = await web3Modal.connect(); -// const provider = new ethers.providers.Web3Provider(connection); -// const signer = provider.getSigner(); -// let network = await provider.getNetwork(); -// // console.log(network); -// if (network.chainId === 31337 || network.chainId === 1337) { -// network = { name: "localhost", chainId: 31337 }; -// } -// if (network.name === "homestead") { -// network = { name: "mainnet", chainId: 1 }; -// } -// if (network.chainId === 137) { -// network = { name: "polygon", chainId: 137 }; -// } -// return { network, signer, provider }; -// }; +export const getNetwork = async () => { + const web3Modal = new Web3Modal(); + const connection = await web3Modal.connect(); + const provider = new ethers.providers.Web3Provider(connection); + const signer = provider.getSigner(); + let network = await provider.getNetwork(); + // console.log(network); + if (network.chainId === 31337 || network.chainId === 1337) { + network = { name: "localhost", chainId: 31337 }; + } + if (network.name === "homestead") { + network = { name: "mainnet", chainId: 1 }; + } + if (network.chainId === 137) { + network = { name: "polygon", chainId: 137 }; + } + return { network, signer, provider }; +}; export const toCeramicId = id => (id.startsWith(CERAMIC_PREFIX) ? id : CERAMIC_PREFIX + id); diff --git a/packages/react-app/src/views/Create.jsx b/packages/react-app/src/views/Create.jsx index 4d5394e2..d3956c3f 100644 --- a/packages/react-app/src/views/Create.jsx +++ b/packages/react-app/src/views/Create.jsx @@ -49,6 +49,8 @@ import { CERAMIC_PREFIX } from "../dips/helpers"; const CURRENCY = "ETH"; const TOKEN = process.env.REACT_APP_TOKEN_SYMBOL; const TOKEN_ADR = process.env.REACT_APP_TOKEN_ADDRESS; +const STABLE = process.env.REACT_APP_STABLE_TOKEN_SYMBOL; +const STABLE_ADR = process.env.REACT_APP_STABLE_ADDRESS; const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, writeContracts, targetNetwork }) => { /***** Routes *****/ @@ -228,6 +230,12 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write tokenAdr: TOKEN_ADR, })); } + if (e.target.value === STABLE) { + setNewElection(prevState => ({ + ...prevState, + tokenAdr: STABLE_ADR, + })); + } }; const updateFundAmount = e => { @@ -417,6 +425,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write > + From 8c76430bf0e3b0705edb86014604f70d0d145fc8 Mon Sep 17 00:00:00 2001 From: hans Date: Sun, 28 Nov 2021 16:16:10 +0000 Subject: [PATCH 2/6] added: polygon and DAI support, fixed ens resolve --- packages/hardhat/hardhat.config.js | 12 ++++++------ .../react-app/src/components/Cards/SideCard.jsx | 1 + .../react-app/src/contracts/external_contracts.js | 4 ++++ .../react-app/src/contracts/hardhat_contracts.json | 8 ++++---- packages/react-app/src/dips/ceramicHandler.js | 2 ++ packages/react-app/src/dips/helpers.js | 14 ++++++++++---- packages/react-app/src/views/Create.jsx | 8 ++++---- packages/react-app/src/views/Election.jsx | 2 +- 8 files changed, 32 insertions(+), 19 deletions(-) diff --git a/packages/hardhat/hardhat.config.js b/packages/hardhat/hardhat.config.js index a14d2886..28d3a413 100644 --- a/packages/hardhat/hardhat.config.js +++ b/packages/hardhat/hardhat.config.js @@ -73,16 +73,16 @@ module.exports = { gasPrice: 1000000000, accounts: [`${process.env.XDAI_DEPLOYER_PRIV_KEY}`], }, - polygon: { - url: `https://polygon-mainnet.infura.io/v3/${process.env.POLYGON_INFURA_KEY}`, // <---- YOUR MORALIS ID! (not limited to infura) - gasPrice: 1000000000, - accounts: [`${process.env.POLYGON_DEPLOYER_PRIV_KEY}`], - }, matic: { - url: "https://rpc-mainnet.maticvigil.com/", + url: `https://polygon-mainnet.infura.io/v3/${process.env.POLYGON_INFURA_KEY}`, // <---- YOUR MORALIS ID! (not limited to infura) gasPrice: 1000000000, accounts: [`${process.env.POLYGON_DEPLOYER_PRIV_KEY}`], }, + // matic: { + // url: "https://rpc-mainnet.maticvigil.com/", + // gasPrice: 1000000000, + // accounts: [`${process.env.POLYGON_DEPLOYER_PRIV_KEY}`], + // }, // rinkebyArbitrum: { // url: "https://rinkeby.arbitrum.io/rpc", // gasPrice: 0, diff --git a/packages/react-app/src/components/Cards/SideCard.jsx b/packages/react-app/src/components/Cards/SideCard.jsx index c1be78b1..017547ac 100644 --- a/packages/react-app/src/components/Cards/SideCard.jsx +++ b/packages/react-app/src/components/Cards/SideCard.jsx @@ -26,6 +26,7 @@ function ElectionCard({ function goBack() { routeHistory.push("/"); } + // console.log({electionState}) return ( diff --git a/packages/react-app/src/contracts/external_contracts.js b/packages/react-app/src/contracts/external_contracts.js index 166b1753..6e9d1c6a 100644 --- a/packages/react-app/src/contracts/external_contracts.js +++ b/packages/react-app/src/contracts/external_contracts.js @@ -824,6 +824,10 @@ module.exports = { address: "0xdb95f9188479575F3F718a245EcA1B3BF74567EC", abi: ERC20ABI, }, + DAI: { + address: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063", + abi: ERC20ABI, + }, }, }, }; diff --git a/packages/react-app/src/contracts/hardhat_contracts.json b/packages/react-app/src/contracts/hardhat_contracts.json index 18b8e84f..4eb23721 100644 --- a/packages/react-app/src/contracts/hardhat_contracts.json +++ b/packages/react-app/src/contracts/hardhat_contracts.json @@ -504,7 +504,7 @@ "chainId": "4", "contracts": { "Diplomat": { - "address": "0x057d7CFaC1FA6D1CEd591A448DA94525c5289f2F", + "address": "0x7658Eac3D619B0c141937ddEeC0E5a638F961427", "abi": [ { "inputs": [], @@ -998,12 +998,12 @@ } }, "137": { - "polygon": { - "name": "polygon", + "matic": { + "name": "matic", "chainId": "137", "contracts": { "Diplomat": { - "address": "0xea99c58645f897ac8bf530538e36e6d651ff8bf7", + "address": "0x8486D6959d4e01aAd3d3D14A0e679160239FE463", "abi": [ { "inputs": [], diff --git a/packages/react-app/src/dips/ceramicHandler.js b/packages/react-app/src/dips/ceramicHandler.js index 688d25be..1ff88955 100644 --- a/packages/react-app/src/dips/ceramicHandler.js +++ b/packages/react-app/src/dips/ceramicHandler.js @@ -73,6 +73,8 @@ export default function CeramicHandler( const electionId = electionDoc.id.toUrl(); + // console.log({ targetNetwork }); + /* CREATE ELECTION ON-CHAIN (push the ceramic commitId to elections array) */ let contract = new ethers.Contract( Diplomat[targetNetwork.chainId][targetNetwork.name].contracts.Diplomat.address, diff --git a/packages/react-app/src/dips/helpers.js b/packages/react-app/src/dips/helpers.js index eb5f3f4a..5b781968 100644 --- a/packages/react-app/src/dips/helpers.js +++ b/packages/react-app/src/dips/helpers.js @@ -10,8 +10,8 @@ export const CERAMIC_PREFIX = "ceramic://"; const CURRENCY = "ETH"; const TOKEN = process.env.REACT_APP_TOKEN_SYMBOL; const TOKEN_ADR = process.env.REACT_APP_TOKEN_ADDRESS; -const STABLE = process.env.REACT_APP_STABLE_TOKEN; -const STABLE_ADR = process.env.REACT_APP_STABLE_ADDRESS; +const STABLE = process.env.REACT_APP_STABLE_TOKEN_SYMBOL; +const STABLE_ADR = process.env.REACT_APP_STABLE_TOKEN_ADDRESS; //// PASTE HERE export const getAllCeramicElections = async (contract, ceramic) => { @@ -139,10 +139,13 @@ export const newSerializeCeramicElection = async ({ id, electionDoc, address, ce }); } } - let tokenSymbol = "ETH"; + let tokenSymbol = CURRENCY; if (electionDoc.content.tokenAddress == TOKEN_ADR) { tokenSymbol = TOKEN; } + if (electionDoc.content.tokenAddress == STABLE_ADR) { + tokenSymbol = STABLE; + } console.log({ content: electionDoc.content, tags }); const serializedElection = { id, @@ -335,10 +338,13 @@ export const serializeCeramicElection = async (ceramicElectionId, address, ceram }); } } - let tokenSymbol = "ETH"; + let tokenSymbol = CURRENCY; if (electionDoc.content.tokenAddress == TOKEN_ADR) { tokenSymbol = TOKEN; } + if (electionDoc.content.tokenAddress == STABLE_ADR) { + tokenSymbol = STABLE; + } console.log({ content: electionDoc.content, tags }); const serializedElection = { id, diff --git a/packages/react-app/src/views/Create.jsx b/packages/react-app/src/views/Create.jsx index d3956c3f..cfba47ae 100644 --- a/packages/react-app/src/views/Create.jsx +++ b/packages/react-app/src/views/Create.jsx @@ -46,11 +46,11 @@ import { ethers } from "ethers"; import { CERAMIC_PREFIX } from "../dips/helpers"; -const CURRENCY = "ETH"; +const CURRENCY = process.env.REACT_APP_NETWORK_SYMBOL; const TOKEN = process.env.REACT_APP_TOKEN_SYMBOL; const TOKEN_ADR = process.env.REACT_APP_TOKEN_ADDRESS; const STABLE = process.env.REACT_APP_STABLE_TOKEN_SYMBOL; -const STABLE_ADR = process.env.REACT_APP_STABLE_ADDRESS; +const STABLE_ADR = process.env.REACT_APP_STABLE_TOKEN_ADDRESS; const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, writeContracts, targetNetwork }) => { /***** Routes *****/ @@ -69,7 +69,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write const [newElection, setNewElection] = useState({ name: "", description: "", - tokenSym: "ETH", + tokenSym: CURRENCY, tokenAdr: "0x0000000000000000000000000000000000000000", fundAmount: 0.1, fundAmountInWei: toWei("0.1"), @@ -178,7 +178,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write setNewElection({ name: "", description: "", - tokenSym: "ETH", + tokenSym: CURRENCY, fundAmount: 0.1, fundAmountInWei: toWei("0.1"), voteAllocation: 1, diff --git a/packages/react-app/src/views/Election.jsx b/packages/react-app/src/views/Election.jsx index b66c592f..8dae3b36 100644 --- a/packages/react-app/src/views/Election.jsx +++ b/packages/react-app/src/views/Election.jsx @@ -223,7 +223,7 @@ export default function Election({ )} - {!electionState.isPaid && !electionState.active && electionState.isAdmin && ( + {address && spender && electionState && !electionState.isPaid && !electionState.active && electionState.isAdmin && ( Date: Mon, 29 Nov 2021 18:40:53 +0000 Subject: [PATCH 3/6] updated: max token amount --- packages/react-app/src/views/Create.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-app/src/views/Create.jsx b/packages/react-app/src/views/Create.jsx index cfba47ae..8f66e62e 100644 --- a/packages/react-app/src/views/Create.jsx +++ b/packages/react-app/src/views/Create.jsx @@ -398,7 +398,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write - + Date: Tue, 30 Nov 2021 10:24:58 +0000 Subject: [PATCH 4/6] updated: rm max and min to 1wei --- packages/react-app/src/views/Create.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-app/src/views/Create.jsx b/packages/react-app/src/views/Create.jsx index 8f66e62e..07f0c85a 100644 --- a/packages/react-app/src/views/Create.jsx +++ b/packages/react-app/src/views/Create.jsx @@ -398,7 +398,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write - + - + Date: Tue, 30 Nov 2021 14:32:32 +0000 Subject: [PATCH 5/6] updated: DAI token address --- packages/react-app/src/contracts/external_contracts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-app/src/contracts/external_contracts.js b/packages/react-app/src/contracts/external_contracts.js index 6e9d1c6a..4edfe0c1 100644 --- a/packages/react-app/src/contracts/external_contracts.js +++ b/packages/react-app/src/contracts/external_contracts.js @@ -801,7 +801,7 @@ module.exports = { 4: { contracts: { DAI: { - address: "0x6B175474E89094C44Da98b954EedeAC495271d0F", + address: "0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea", abi: DAIABI, }, UNI: { From a5631326c36181c2f408aa169aec6d1e6af8d49f Mon Sep 17 00:00:00 2001 From: hans Date: Tue, 30 Nov 2021 14:38:51 +0000 Subject: [PATCH 6/6] updated: currency to env var --- packages/react-app/src/dips/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-app/src/dips/helpers.js b/packages/react-app/src/dips/helpers.js index 5b781968..a283a152 100644 --- a/packages/react-app/src/dips/helpers.js +++ b/packages/react-app/src/dips/helpers.js @@ -7,7 +7,7 @@ import { makeCeramicClient } from "../helpers"; export const CERAMIC_PREFIX = "ceramic://"; -const CURRENCY = "ETH"; +const CURRENCY = process.env.REACT_APP_NETWORK_SYMBOL; const TOKEN = process.env.REACT_APP_TOKEN_SYMBOL; const TOKEN_ADR = process.env.REACT_APP_TOKEN_ADDRESS; const STABLE = process.env.REACT_APP_STABLE_TOKEN_SYMBOL;