From 2f7da5a6152b0d901353932f91a647991ec7c616 Mon Sep 17 00:00:00 2001 From: Felipe Novaes F Rocha Date: Mon, 16 Jan 2023 17:26:55 -0300 Subject: [PATCH 1/4] feat: added goerli network and subgraph (wip) --- .gitignore | 2 +- .../Onboarding/Screens/HoneyswapLiquidity.js | 27 ++++++++++++----- src/ethereum-providers/connectors.ts | 6 ++-- src/hooks/useHNYPriceOracle.ts | 17 +++++++++-- src/networks.js | 30 ++++++++++--------- src/utils/web3-utils.js | 2 ++ src/voided-gardens.ts | 3 +- 7 files changed, 59 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 26fc743ef..a7a32f511 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ node_modules /public/aragon-ui package-lock.json - +.yalc # production /build diff --git a/src/components/Onboarding/Screens/HoneyswapLiquidity.js b/src/components/Onboarding/Screens/HoneyswapLiquidity.js index cc4c75c67..373710321 100644 --- a/src/components/Onboarding/Screens/HoneyswapLiquidity.js +++ b/src/components/Onboarding/Screens/HoneyswapLiquidity.js @@ -38,7 +38,9 @@ function HoneyswapLiquidity() { honeyTokenLiquidityStable, tokenLiquidity, } = config.liquidity - const [hnyPrice, hnyPriceLoading] = useHNYPriceOracle(toDecimals('1', 18)) + const [hnyPrice, hnyPriceLoading, hnyError] = useHNYPriceOracle( + toDecimals('1', 18) + ) // State vars const [denom, setDenom] = useState(denomination) // 0 HNY, 1 USD @@ -281,13 +283,22 @@ function HoneyswapLiquidity() { )} )} -
- You must specify an amount worth at least {MIN_HNY_USD} USD -
+ <> +
+ You must specify an amount worth at least {MIN_HNY_USD} USD +
+
+ {/* {hnyError} */} +
+
= [ { id: 'injected', properties: { - chainId: [100, 4, 137, 31337], // add here to handle more injected chains + chainId: [100, 4, 5, 137, 31337], // add here to handle more injected chains }, }, { id: 'frame', properties: { - chainId: [100, 4, 137, 31337], + chainId: [100, 4, 5, 137, 31337], }, }, { @@ -38,6 +39,7 @@ export const CONNECTORS: Array = [ 137: POLYGON_ETH_NODE, 100: XDAI_ETH_NODE, 4: RINKEBY_ETH_NODE, + 5: GOERLI_ETH_NODE, }, bridge: WALLET_CONNECT_BRIDGE_ENDPOINT, pollingInterval: 12000, diff --git a/src/hooks/useHNYPriceOracle.ts b/src/hooks/useHNYPriceOracle.ts index 48f3911a6..5257190b0 100644 --- a/src/hooks/useHNYPriceOracle.ts +++ b/src/hooks/useHNYPriceOracle.ts @@ -10,6 +10,7 @@ import priceOracleAbi from '@abis/priceOracle.json' export default function useHNYPriceOracle(amount: number) { const [convertedAmount, setConvertedAmount] = useState(-1) const [loading, setLoading] = useState(true) + const [error, setError] = useState(null) const { chainId } = useWallet() const { stableToken, honeyToken, honeyPriceOracle } = getNetwork(chainId) @@ -24,6 +25,7 @@ export default function useHNYPriceOracle(amount: number) { useEffect(() => { if (!priceOracleContract) { + console.log(`priceOracleContract not found`) setLoading(false) return } @@ -35,19 +37,30 @@ export default function useHNYPriceOracle(amount: number) { amount.toString(10), stableToken ) + console.log(`consult ${result}`) if (mounted()) { setConvertedAmount( parseFloat(fromDecimals(result.toString(), 18)).toFixed(2) ) } } catch (err) { + setLoading(false) + let msgError = 'Error unknown' + const errAny = err as any + if ('reason' in errAny) { + if (errAny.reason.includes('MISSING_HISTORICAL_OBSERVATION')) { + msgError = `PriceOracle need be updated at ${honeyPriceOracle}` + console.log(msgError) + setError(msgError) + } + } + console.error(`Error consulting converted amount ${err}`) } - setLoading(false) } fetchConvertedAmount() }, [amount, honeyToken, mounted, priceOracleContract, stableToken]) - return [convertedAmount, loading] + return [convertedAmount, loading, error] } diff --git a/src/networks.js b/src/networks.js index 7f3522267..1dde31303 100644 --- a/src/networks.js +++ b/src/networks.js @@ -10,30 +10,32 @@ const XDAI_ETH_NODE = env('XDAI_ETH_NODE') const POLYGON_ETH_NODE = env('POLYGON_ETH_NODE') const networks = { - rinkeby: { - chainId: 4, - ensRegistry: '0x98df287b6c145399aaa709692c8d308357bc085d', - name: 'Rinkeby', - type: 'rinkeby', + goerli: { + chainId: 5, + ensRegistry: '0x8cf5a255ed61f403837f040b8d9f052857469273', + name: 'Goerli', + type: 'goerli', hiveGarden: '0x7777cd7c9c6d3537244871ac8e73b3cb9710d45a', - arbitrator: '0xc2224d785d4e4bc92d5be6767a82d026ca2813fd', - disputeManager: '0xe87d5c7501ccc6a32126601d94d36c0d0cce2c18', - template: '0x832a29b1d6c1dfca7075c62d222b40c05183aaae', + arbitrator: '0x15ea6e0ab085b8d7d899672f10f213d53ce02150', + disputeManager: '0x15ea6e0ab085b8d7d899672f10f213d53ce02150', + template: + '0x1f756cac140e1a22d9a2dd258a59d0bf2060d3f0QMRM6VT582IBNY8GPI9XB1N5DSFRJ4YHTP', explorer: 'etherscan', - honeyToken: '0x3050e20fabe19f8576865811c9f28e85b96fa4f9', - honeyPriceOracle: '0xa87f58dbbe3a4d01d7f776e02b4dd3237f598095', - stableToken: '0x531eab8bb6a2359fe52ca5d308d85776549a0af9', + honeyToken: '0x2d467a24095b262787f58ce97d9b130ce7232b57', + honeyPriceOracle: '0x732cf7ff8a3df9daedc283587be2051dc67ac6c3', + stableToken: '0xdc31ee1784292379fbb2964b3b9c4124d8f89c60', subgraphs: { agreement: 'https://api.thegraph.com/subgraphs/name/1hive/agreement-rinkeby', aragon: 'https://api.thegraph.com/subgraphs/name/1hive/aragon-rinkeby', celeste: 'https://api.thegraph.com/subgraphs/name/1hive/celeste-rinkeby', - gardens: 'https://api.thegraph.com/subgraphs/name/1hive/gardens-rinkeby', + gardens: + 'https://api.studio.thegraph.com/query/29898/gardens-goerli/v2.0.0', }, - legacyNetworkType: 'rinkeby', + legacyNetworkType: 'goerli', // TODO Looks like not used }, xdai: { chainId: 100, @@ -188,7 +190,7 @@ export function getAgreementConnectorConfig(chainId) { } } -export const SUPPORTED_CHAINS = [4, 100, 137] // Add arbitrum chains id + fill the network json with the data +export const SUPPORTED_CHAINS = [4, 5, 100, 137] // Add arbitrum chains id + fill the network json with the data export function isSupportedChain(chainId) { return SUPPORTED_CHAINS.includes(chainId) diff --git a/src/utils/web3-utils.js b/src/utils/web3-utils.js index 125ed5036..8d941daf5 100644 --- a/src/utils/web3-utils.js +++ b/src/utils/web3-utils.js @@ -32,6 +32,7 @@ export function getNetworkType(chainId = getPreferredChain()) { if (chainId === '1') return 'mainnet' if (chainId === '4') return 'rinkeby' + if (chainId === '5') return 'goerli' // TODO FIXME Another way to be easy to add new networks if (chainId === '100') return 'xdai' if (chainId === '137') return 'polygon' @@ -43,6 +44,7 @@ export function getNetworkName(chainId = getPreferredChain()) { if (chainId === '1') return 'Mainnet' if (chainId === '4') return 'Rinkeby' + if (chainId === '5') return 'Goerli' // TODO FIXME Another way to be easy to add new networks if (chainId === '100') return 'Gnosis' if (chainId === '137') return 'Polygon' diff --git a/src/voided-gardens.ts b/src/voided-gardens.ts index 718d4a99d..4e54928ae 100644 --- a/src/voided-gardens.ts +++ b/src/voided-gardens.ts @@ -6,8 +6,9 @@ const VOIDED_GARDENS: { polygon: new Map([]), xdai: new Map([['0x9ceac080e12ab6700eef58c45fa02a50e8e2cd4b', '_']]), rinkeby: new Map([]), + goerli: new Map([]), } export function getVoidedGardensByNetwork() { - return VOIDED_GARDENS[getNetworkType()] + return VOIDED_GARDENS[getNetworkType()] // TODO Improv with if and return default value } From 56e0c0974bed71d9a8e49d8c4a64e3a3a517a0f7 Mon Sep 17 00:00:00 2001 From: Felipe Novaes F Rocha Date: Wed, 18 Jan 2023 11:37:01 -0300 Subject: [PATCH 2/4] fix template address --- src/networks.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/networks.js b/src/networks.js index 1dde31303..2f237aaf5 100644 --- a/src/networks.js +++ b/src/networks.js @@ -19,8 +19,7 @@ const networks = { hiveGarden: '0x7777cd7c9c6d3537244871ac8e73b3cb9710d45a', arbitrator: '0x15ea6e0ab085b8d7d899672f10f213d53ce02150', disputeManager: '0x15ea6e0ab085b8d7d899672f10f213d53ce02150', - template: - '0x1f756cac140e1a22d9a2dd258a59d0bf2060d3f0QMRM6VT582IBNY8GPI9XB1N5DSFRJ4YHTP', + template: '0x1f756cac140e1a22d9a2dd258a59d0bf2060d3f0', explorer: 'etherscan', honeyToken: '0x2d467a24095b262787f58ce97d9b130ce7232b57', From 331a3e95d0e9f0f153193986f65b7026a0462581 Mon Sep 17 00:00:00 2001 From: Felipe Novaes F Rocha Date: Thu, 19 Jan 2023 01:35:19 -0300 Subject: [PATCH 3/4] fixing price oracle loading, rpc goerli --- .../Onboarding/Screens/HoneyswapLiquidity.js | 4 +--- src/environment.js | 10 +++++++++- src/ethereum-providers/connectors.ts | 6 ++++++ src/hooks/useHNYPriceOracle.ts | 6 ++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/components/Onboarding/Screens/HoneyswapLiquidity.js b/src/components/Onboarding/Screens/HoneyswapLiquidity.js index 373710321..0a77481cf 100644 --- a/src/components/Onboarding/Screens/HoneyswapLiquidity.js +++ b/src/components/Onboarding/Screens/HoneyswapLiquidity.js @@ -38,9 +38,7 @@ function HoneyswapLiquidity() { honeyTokenLiquidityStable, tokenLiquidity, } = config.liquidity - const [hnyPrice, hnyPriceLoading, hnyError] = useHNYPriceOracle( - toDecimals('1', 18) - ) + const [hnyPrice, hnyPriceLoading] = useHNYPriceOracle(toDecimals('1', 18)) // State vars const [denom, setDenom] = useState(denomination) // 0 HNY, 1 USD diff --git a/src/environment.js b/src/environment.js index 747b17c26..cb4cf19d4 100644 --- a/src/environment.js +++ b/src/environment.js @@ -7,6 +7,7 @@ const DEFAULT_VOTING_APP_NAME = 'disputable-voting' const DEFAULT_XDAI_ETH_NODE_ENDPOINT = 'https://rpc.gnosischain.com' const DEFAULT_POLYGON_ETH_NODE_ENDPOINT = 'https://polygon-rpc.com' +const DEFAULT_GOERLI_ETH_NODE_ENDPOINT = 'https://eth-goerli.public.blastapi.io' const ENV_VARS = { AGREEMENT_APP_NAME() { @@ -34,6 +35,11 @@ const ENV_VARS = { DEFAULT_POLYGON_ETH_NODE_ENDPOINT ) }, + GOERLI_ETH_NODE() { + return ( + process.env.REACT_APP_GOERLI_ETH_NODE || DEFAULT_GOERLI_ETH_NODE_ENDPOINT + ) + }, ETHERSCAN_API_KEY() { return process.env.REACT_APP_ETHERSCAN_API_KEY || null }, @@ -65,7 +71,9 @@ const ENV_VARS = { return process.env.REACT_APP_POCKET_API_KEY || null }, MIDDLEWARE_ENDPOINT() { - return process.env.REACT_APP_MIDDLEWARE_ENDPOINT || DEFAULT_MIDDLEWARE_ENDPOINT + return ( + process.env.REACT_APP_MIDDLEWARE_ENDPOINT || DEFAULT_MIDDLEWARE_ENDPOINT + ) }, VERCEL_ENV() { return process.env.REACT_APP_VERCEL_ENV || null diff --git a/src/ethereum-providers/connectors.ts b/src/ethereum-providers/connectors.ts index 50cc392c4..42b9c49eb 100644 --- a/src/ethereum-providers/connectors.ts +++ b/src/ethereum-providers/connectors.ts @@ -24,6 +24,12 @@ export const CONNECTORS: Array = [ id: 'injected', properties: { chainId: [100, 4, 5, 137, 31337], // add here to handle more injected chains + rpc: { + 137: POLYGON_ETH_NODE, + 100: XDAI_ETH_NODE, + 4: RINKEBY_ETH_NODE, + 5: GOERLI_ETH_NODE, + }, }, }, { diff --git a/src/hooks/useHNYPriceOracle.ts b/src/hooks/useHNYPriceOracle.ts index 5257190b0..1acc27908 100644 --- a/src/hooks/useHNYPriceOracle.ts +++ b/src/hooks/useHNYPriceOracle.ts @@ -6,10 +6,11 @@ import { getNetwork } from '../networks' import { fromDecimals } from '@utils/math-utils' import priceOracleAbi from '@abis/priceOracle.json' +import { setDebugLog } from 'clipboard-polyfill' export default function useHNYPriceOracle(amount: number) { const [convertedAmount, setConvertedAmount] = useState(-1) - const [loading, setLoading] = useState(true) + const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const { chainId } = useWallet() @@ -44,7 +45,6 @@ export default function useHNYPriceOracle(amount: number) { ) } } catch (err) { - setLoading(false) let msgError = 'Error unknown' const errAny = err as any if ('reason' in errAny) { @@ -56,6 +56,8 @@ export default function useHNYPriceOracle(amount: number) { } console.error(`Error consulting converted amount ${err}`) + } finally { + setLoading(false) } } From 148807c8cec68bad789768b36af56775c9022e10 Mon Sep 17 00:00:00 2001 From: Felipe Novaes F Rocha Date: Mon, 3 Apr 2023 08:46:08 -0300 Subject: [PATCH 4/4] chore: minor improvments --- .gitignore | 1 + scripts/check_env.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a7a32f511..fe68cdf95 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ package-lock.json /build # misc +.yalc .env .DS_Store .env.local diff --git a/scripts/check_env.ts b/scripts/check_env.ts index c2a7f1f44..4c6cb30b9 100644 --- a/scripts/check_env.ts +++ b/scripts/check_env.ts @@ -44,6 +44,7 @@ async function check_env() { logCheckEnv( `First clone '${ENV_TEMPLATE_PATH}' to '${ENV_PATH}' and run it again` ) + throw new Error('') } if (arrMissingEnvs.length > 0 && THROW_ERROR_REQUIRED) {