Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
feat: add multi-contract governance support (#1860)
Browse files Browse the repository at this point in the history
* Revert "feat: quick fix for new governor"
This reverts commit 5dd1249.

* support multiple governance contracts
  • Loading branch information
JFrankfurt authored Jun 16, 2021
1 parent 1b27d8d commit 014595c
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 167 deletions.
44 changes: 15 additions & 29 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
import { Trans } from '@lingui/macro'
import useScrollPosition from '@react-hook/window-scroll'
import React, { useState } from 'react'
import { Text } from 'rebass'
import { NavLink } from 'react-router-dom'
import { darken } from 'polished'
import { Trans } from '@lingui/macro'
import React, { useState } from 'react'
import { Moon, Sun } from 'react-feather'
import { NavLink } from 'react-router-dom'
import { Text } from 'rebass'
import { useShowClaimPopup, useToggleSelfClaimModal } from 'state/application/hooks'
import { useUserHasAvailableClaim } from 'state/claim/hooks'
import { useUserHasSubmittedClaim } from 'state/transactions/hooks'
import { useDarkModeManager } from 'state/user/hooks'
import { useETHBalances } from 'state/wallet/hooks'
import styled from 'styled-components/macro'

import Logo from '../../assets/svg/logo.svg'
import LogoDark from '../../assets/svg/logo_white.svg'
import { SupportedChainId } from '../../constants/chains'

import { NETWORK_LABELS, SupportedChainId } from '../../constants/chains'
import { useActiveWeb3React } from '../../hooks/web3'
import { useDarkModeManager } from '../../state/user/hooks'
import { useETHBalances } from '../../state/wallet/hooks'
import { CardNoise } from '../earn/styled'
import { TYPE, ExternalLink } from '../../theme'

import { ExternalLink, TYPE } from '../../theme'
import { YellowCard } from '../Card'
import ClaimModal from '../claim/ClaimModal'
import { CardNoise } from '../earn/styled'
import Menu from '../Menu'

import Modal from '../Modal'
import Row, { RowFixed } from '../Row'
import Web3Status from '../Web3Status'
import ClaimModal from '../claim/ClaimModal'
import { useToggleSelfClaimModal, useShowClaimPopup } from '../../state/application/hooks'
import { useUserHasAvailableClaim } from '../../state/claim/hooks'
import { useUserHasSubmittedClaim } from '../../state/transactions/hooks'
import { Dots } from '../swap/styleds'
import Modal from '../Modal'
import Web3Status from '../Web3Status'
import UniBalanceContent from './UniBalanceContent'

const HeaderFrame = styled.div<{ showBackground: boolean }>`
Expand Down Expand Up @@ -302,16 +298,6 @@ export const StyledMenuButton = styled.button`
}
`

const NETWORK_LABELS: { [chainId in SupportedChainId | number]: string } = {
[SupportedChainId.MAINNET]: 'Mainnet',
[SupportedChainId.RINKEBY]: 'Rinkeby',
[SupportedChainId.ROPSTEN]: 'Ropsten',
[SupportedChainId.GOERLI]: 'Görli',
[SupportedChainId.KOVAN]: 'Kovan',
[SupportedChainId.ARBITRUM_KOVAN]: 'kArbitrum',
[SupportedChainId.ARBITRUM_ONE]: 'Arbitrum One',
}

export default function Header() {
const { account, chainId } = useActiveWeb3React()

Expand Down
4 changes: 3 additions & 1 deletion src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export const V2_ROUTER_ADDRESS: AddressMap = constructSameAddressMap(
'0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
false
)

// most current governance contract address should always be the 0 index
export const GOVERNANCE_ADDRESSES: AddressMap[] = [
constructSameAddressMap('0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F', false),
{
[SupportedChainId.MAINNET]: '0xC4e172459f1E7939D522503B81AFAaC1014CE6F6',
},
constructSameAddressMap('0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F', false),
]
export const TIMELOCK_ADDRESS: AddressMap = constructSameAddressMap('0x1a9C8182C09F50C8318d769245beA52c32BE35BC', false)
export const MERKLE_DISTRIBUTOR_ADDRESS: AddressMap = {
Expand Down
10 changes: 10 additions & 0 deletions src/constants/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ export enum SupportedChainId {
ARBITRUM_KOVAN = 144545313136048,
ARBITRUM_ONE = 42161,
}

export const NETWORK_LABELS: { [chainId in SupportedChainId | number]: string } = {
[SupportedChainId.MAINNET]: 'Mainnet',
[SupportedChainId.RINKEBY]: 'Rinkeby',
[SupportedChainId.ROPSTEN]: 'Ropsten',
[SupportedChainId.GOERLI]: 'Görli',
[SupportedChainId.KOVAN]: 'Kovan',
[SupportedChainId.ARBITRUM_KOVAN]: 'kArbitrum',
[SupportedChainId.ARBITRUM_ONE]: 'Arbitrum One',
}
22 changes: 16 additions & 6 deletions src/constants/governance.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { GOVERNANCE_ADDRESSES, TIMELOCK_ADDRESS, UNI_ADDRESS } from './addresses'
import { SupportedChainId } from './chains'

export const COMMON_CONTRACT_NAMES: { [chainId: number]: { [address: string]: string } } = {
[1]: {
[UNI_ADDRESS[1]]: 'UNI',
[GOVERNANCE_ADDRESSES[0][1]]: 'Governance (V0)',
[GOVERNANCE_ADDRESSES[1][1]]: 'Governance',
[TIMELOCK_ADDRESS[1]]: 'Timelock',
// returns { [address]: `Governance (V${n})`} for each address in GOVERNANCE_ADDRESSES except the current, which gets no version indicator
const governanceContracts = (): Record<string, string> =>
GOVERNANCE_ADDRESSES.reduce(
(acc, addressMap, i) => ({
...acc,
[addressMap[SupportedChainId.MAINNET]]: `Governance${i === GOVERNANCE_ADDRESSES.length - 1 ? '' : ` (V${i})`}`,
}),
{}
)

export const COMMON_CONTRACT_NAMES: Record<number, { [address: string]: string }> = {
[SupportedChainId.MAINNET]: {
[UNI_ADDRESS[SupportedChainId.MAINNET]]: 'UNI',
[TIMELOCK_ADDRESS[SupportedChainId.MAINNET]]: 'Timelock',
...governanceContracts(),
},
}

Expand Down
2 changes: 2 additions & 0 deletions src/constants/proposals/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const UNISWAP_GRANTS_START_BLOCK = 11473815
export const EDUCATION_FUND_1_START_BLOCK = 12620175
46 changes: 36 additions & 10 deletions src/hooks/useContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,34 @@ import { useActiveWeb3React } from './web3'

// returns null on errors
export function useContract<T extends Contract = Contract>(
addressOrAddressMap: string | { [chainId: number]: string } | undefined,
addressOrAddressMap: string | { [chainId: number]: string } | { [chainId: number]: string }[] | undefined,
ABI: any,
withSignerIfPossible = true
): T | null {
const { library, account, chainId } = useActiveWeb3React()

return useMemo(() => {
if (!addressOrAddressMap || !ABI || !library || !chainId) return null
if (!addressOrAddressMap || !ABI || !library || !chainId) {
return null
}
let address: string | undefined
if (typeof addressOrAddressMap === 'string') address = addressOrAddressMap
else address = addressOrAddressMap[chainId]
if (!address) return null
if (typeof addressOrAddressMap === 'string') {
address = addressOrAddressMap
} else if (!Array.isArray(addressOrAddressMap)) {
address = addressOrAddressMap[chainId]
}
if (!address && !Array.isArray(addressOrAddressMap)) {
return null
}
try {
if (Array.isArray(addressOrAddressMap)) {
return addressOrAddressMap.map((addressMap) =>
getContract(addressMap[chainId], ABI, library, withSignerIfPossible && account ? account : undefined)
)
}
if (!address) {
return null
}
return getContract(address, ABI, library, withSignerIfPossible && account ? account : undefined)
} catch (error) {
console.error('Failed to get contract', error)
Expand Down Expand Up @@ -116,11 +131,22 @@ export function useMerkleDistributorContract() {
return useContract(MERKLE_DISTRIBUTOR_ADDRESS, MERKLE_DISTRIBUTOR_ABI, true)
}

export function useGovernanceContracts(): (Contract | null)[] {
return [
useContract(GOVERNANCE_ADDRESSES[0], GOVERNANCE_ABI, false),
useContract(GOVERNANCE_ADDRESSES[1], GOVERNANCE_ABI, true),
]
export function useGovernanceContracts(): Contract[] | null {
const { library, account, chainId } = useActiveWeb3React()

return useMemo(() => {
if (!library || !chainId) {
return null
}
try {
return GOVERNANCE_ADDRESSES.filter((addressMap) => Boolean(addressMap[chainId])).map((addressMap) =>
getContract(addressMap[chainId], GOVERNANCE_ABI, library, account ? account : undefined)
)
} catch (error) {
console.error('Failed to get contract', error)
return null
}
}, [library, chainId, account])
}

export function useUniContract() {
Expand Down
7 changes: 3 additions & 4 deletions src/pages/Vote/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ export default function Vote() {
const toggleDelegateModal = useToggleDelegateModal()

// get data to list all proposals
// TODO don't hardcode for first gov alpha
const allProposals: ProposalData[] = useAllProposalData()[0]
const allProposals: ProposalData[] = useAllProposalData()

// user data
const availableVotes: CurrencyAmount<Token> | undefined = useUserVotes()
Expand Down Expand Up @@ -249,7 +248,7 @@ export default function Vote() {
</TYPE.subHeader>
</EmptyProposals>
)}
{allProposals?.reverse()?.map((p: ProposalData, i) => {
{allProposals?.reverse().map((p: ProposalData, i) => {
return (
<Proposal as={Link} to={'/vote/' + p.id} key={i}>
<ProposalNumber>{p.id}</ProposalNumber>
Expand All @@ -260,7 +259,7 @@ export default function Vote() {
})}
</TopSection>
<TYPE.subHeader color="text3">
<Trans>A minimum threshold of 1% of the total UNI supply is required to submit proposals</Trans>
<Trans>A minimum threshold of 0.25% of the total UNI supply is required to submit proposals</Trans>
</TYPE.subHeader>
</PageWrapper>
<SwitchLocaleLink />
Expand Down
Loading

0 comments on commit 014595c

Please sign in to comment.