Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added goerli network and subgraph #904

Draft
wants to merge 4 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
node_modules
/public/aragon-ui
package-lock.json

.yalc
# production
/build

# misc
.yalc
.env
.DS_Store
.env.local
Expand Down
1 change: 1 addition & 0 deletions scripts/check_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 16 additions & 7 deletions src/components/Onboarding/Screens/HoneyswapLiquidity.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,22 @@ function HoneyswapLiquidity() {
)}
</div>
)}
<div
css={`
${textStyle('body3')};
`}
>
You must specify an amount worth at least {MIN_HNY_USD} USD
</div>
<>
<div
css={`
${textStyle('body3')};
`}
>
You must specify an amount worth at least {MIN_HNY_USD} USD
</div>
<div
css={`
${textStyle('body3')};
`}
>
{/* {hnyError} */}
</div>
</>
</div>
</div>
<div
Expand Down
10 changes: 9 additions & 1 deletion src/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/ethereum-providers/connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import env from '@/environment'
import { getPreferredChain } from '@/local-settings'

const RINKEBY_ETH_NODE = env('RINKEBY_ETH_NODE')
const GOERLI_ETH_NODE = env('GOERLI_ETH_NODE')
const XDAI_ETH_NODE = env('XDAI_ETH_NODE')
const POLYGON_ETH_NODE = env('POLYGON_ETH_NODE')

Expand All @@ -22,13 +23,19 @@ export const CONNECTORS: Array<ConnectorProviderType> = [
{
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
rpc: {
137: POLYGON_ETH_NODE,
100: XDAI_ETH_NODE,
4: RINKEBY_ETH_NODE,
5: GOERLI_ETH_NODE,
},
},
},
{
id: 'frame',
properties: {
chainId: [100, 4, 137, 31337],
chainId: [100, 4, 5, 137, 31337],
},
},
{
Expand All @@ -38,6 +45,7 @@ export const CONNECTORS: Array<ConnectorProviderType> = [
137: POLYGON_ETH_NODE,
100: XDAI_ETH_NODE,
4: RINKEBY_ETH_NODE,
5: GOERLI_ETH_NODE,
},
bridge: WALLET_CONNECT_BRIDGE_ENDPOINT,
pollingInterval: 12000,
Expand Down
21 changes: 18 additions & 3 deletions src/hooks/useHNYPriceOracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ 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<string | number>(-1)
const [loading, setLoading] = useState(true)
const [loading, setLoading] = useState<boolean>(true)
const [error, setError] = useState<string | null>(null)
const { chainId } = useWallet()

const { stableToken, honeyToken, honeyPriceOracle } = getNetwork(chainId)
Expand All @@ -24,6 +26,7 @@ export default function useHNYPriceOracle(amount: number) {

useEffect(() => {
if (!priceOracleContract) {
console.log(`priceOracleContract not found`)
setLoading(false)
return
}
Expand All @@ -35,19 +38,31 @@ 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) {
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}`)
} finally {
setLoading(false)
}
setLoading(false)
}

fetchConvertedAmount()
}, [amount, honeyToken, mounted, priceOracleContract, stableToken])

return [convertedAmount, loading]
return [convertedAmount, loading, error]
}
29 changes: 15 additions & 14 deletions src/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,31 @@ 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: '0x1f756cac140e1a22d9a2dd258a59d0bf2060d3f0',
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,
Expand Down Expand Up @@ -188,7 +189,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)
Expand Down
2 changes: 2 additions & 0 deletions src/utils/web3-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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'

Expand Down
3 changes: 2 additions & 1 deletion src/voided-gardens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}