Skip to content

Commit

Permalink
DAO-611: Update contract addresses (#99)
Browse files Browse the repository at this point in the history
* update addresses

* change to RBTC

* rename some contracts constants

* fix e2e
  • Loading branch information
rodrigoncalves authored Aug 8, 2024
1 parent 3dfb3f4 commit b2bc59e
Show file tree
Hide file tree
Showing 25 changed files with 143 additions and 149 deletions.
9 changes: 9 additions & 0 deletions .env.prod
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
NEXT_PUBLIC_ENV=mainnet
NEXT_PUBLIC_RIF_WALLET_SERVICES=https://dao-backend.testnet.rifcomputing.net
NEXT_PUBLIC_EXPLORER=https://explorer.rootstock.io

NEXT_PUBLIC_RIF_ADDRESS=0x2acc95758f8b5f583470ba265eb685a8f45fc9d5
NEXT_PUBLIC_STRIF_ADDRESS=
NEXT_PUBLIC_GOVERNOR_ADDRESS=
NEXT_PUBLIC_EA_NFT_ADDRESS=
NEXT_PUBLIC_MULTICALL_ADDRESS=
NEXT_PUBLIC_BUCKET1_ADDRESS=
NEXT_PUBLIC_BUCKET2_ADDRESS=
NEXT_PUBLIC_BUCKET3_ADDRESS=
9 changes: 9 additions & 0 deletions .env.testnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
NEXT_PUBLIC_ENV=testnet
NEXT_PUBLIC_RIF_WALLET_SERVICES=https://dao-backend.testnet.rifcomputing.net
NEXT_PUBLIC_EXPLORER=https://explorer.testnet.rootstock.io

NEXT_PUBLIC_RIF_ADDRESS=0x19f64674d8a5b4e652319f5e239efd3bc969a1fe
NEXT_PUBLIC_STRIF_ADDRESS=0xd6Eb12591559C42e28d672197265b331B1ad867d
NEXT_PUBLIC_GOVERNOR_ADDRESS=0xEc6bd0C8117b74904849af2CED73f30090DB6cd1
NEXT_PUBLIC_EA_NFT_ADDRESS=0xf24761C1B57b14EeA270B1485294D93494164246
NEXT_PUBLIC_MULTICALL_ADDRESS=0xcA11bde05977b3631167028862bE2a173976CA11
NEXT_PUBLIC_BUCKET1_ADDRESS=0xf5b9Ccfe0F695195C4F2E2b5A99b9b5d79EB8089
NEXT_PUBLIC_BUCKET2_ADDRESS=0x8d90a8f30fBC93D9BB62758502bBCB640e59d0f4
NEXT_PUBLIC_BUCKET3_ADDRESS=0x1E6406ddcf3c9Ab882686d4c9d80d184e7f3bF02
4 changes: 2 additions & 2 deletions src/app/communities/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MainContainer } from '@/components/MainContainer/MainContainer'
import Image from 'next/image'
import { CommunityItem } from '@/app/communities/CommunityItem'
import { firstNft } from '@/app/communities/communityUtils'
import { currentEnvNFTContracts } from '@/lib/contracts'
import { nftContracts } from '@/lib/contracts'

// @TODO remove and dynamically fetch the community
const firstCommunity = {
Expand All @@ -12,7 +12,7 @@ const firstCommunity = {
subtitle: 'DeFi',
description: `Crypto ipsum bitcoin ethereum dogecoin litecoin. Hedera USD kadena chainlink arweave hive binance.
Shiba-inu terra ICON IOTA ICON livepeer velas uniswap. Kadena kusama IOTA horizen.`,
nftAddress: currentEnvNFTContracts.EA,
nftAddress: nftContracts.EA,
numberOfMembers: 0,
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/proposals/hooks/useCreateProposal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useVotingPower } from '@/app/proposals/hooks/useVotingPower'
import { GovernorAbi } from '@/lib/abis/Governor'
import { StRIFTokenAbi } from '@/lib/abis/StRIFTokenAbi'
import { currentEnvContracts, GovernorAddress } from '@/lib/contracts'
import { tokenContracts, GovernorAddress } from '@/lib/contracts'
import { solidityPackedKeccak256 } from 'ethers'
import { Address, encodeFunctionData, parseEther } from 'viem'
import { useWriteContract } from 'wagmi'
Expand All @@ -23,7 +23,7 @@ const createProposalForStRifTransfer = (
calldata: ReturnType<typeof encodeFunctionData>,
description: string,
) => {
const proposal = [[currentEnvContracts.stRIF as Address], [0n], [calldata], description]
const proposal = [[tokenContracts.stRIF], [0n], [calldata], description]
const descriptionHash = solidityPackedKeccak256(['string'], [description])
const proposalToRunHash = [...proposal.slice(3), descriptionHash]
return {
Expand Down
6 changes: 3 additions & 3 deletions src/app/proposals/hooks/useVotingPower.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GovernorAbi } from '@/lib/abis/Governor'
import { StRIFTokenAbi } from '@/lib/abis/StRIFTokenAbi'
import { currentEnvContracts, GovernorAddress } from '@/lib/contracts'
import { tokenContracts, GovernorAddress } from '@/lib/contracts'
import { Address, formatUnits } from 'viem'
import { useAccount, useReadContracts } from 'wagmi'

Expand All @@ -12,13 +12,13 @@ export const useVotingPower = () => {
contracts: [
{
abi: StRIFTokenAbi,
address: currentEnvContracts.stRIF as Address,
address: tokenContracts.stRIF,
functionName: 'balanceOf',
args: [address!],
},
{
abi: StRIFTokenAbi,
address: currentEnvContracts.stRIF as Address,
address: tokenContracts.stRIF,
functionName: 'decimals',
},
{ abi: GovernorAbi, address: GovernorAddress, functionName: 'proposalThreshold' },
Expand Down
8 changes: 4 additions & 4 deletions src/app/treasury/TokenHoldingsStRIF.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useReadContract } from 'wagmi'
import { StRIFTokenAbi } from '@/lib/abis/StRIFTokenAbi'
import { currentEnvContracts } from '@/lib/contracts'
import { Address, formatEther, parseEther } from 'viem'
import { tokenContracts } from '@/lib/contracts'
import { useMemo } from 'react'
import { formatEther } from 'viem'
import { useReadContract } from 'wagmi'

export const TokenHoldingsStRIF = () => {
const { data } = useReadContract({
abi: StRIFTokenAbi,
address: currentEnvContracts.stRIF as Address,
address: tokenContracts.stRIF,
functionName: 'totalSupply',
})

Expand Down
6 changes: 3 additions & 3 deletions src/app/treasury/TotalTokenHoldingsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const tableData = [
},
{
token: 'Rootstock Bitcoin',
symbol: 'rBTC',
price: <RenderTokenPrice symbol="rBTC" contextToUse="prices" />,
holdings: <TokenHoldings symbol="rBTC" />,
symbol: 'RBTC',
price: <RenderTokenPrice symbol="RBTC" contextToUse="prices" />,
holdings: <TokenHoldings symbol="RBTC" />,
},
{
token: 'Staked Rootstock Infrastructure Framework',
Expand Down
22 changes: 11 additions & 11 deletions src/app/treasury/TreasuryContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, ReactNode, useContext, useMemo } from 'react'
import { usePricesContext, withPricesContextProvider } from '@/shared/context/PricesContext'
import { useGetTreasuryBucketBalance } from '@/app/treasury/hooks/useGetTreasuryBucketBalance'
import { currentEnvTreasuryContracts } from '@/lib/contracts'
import { treasuryContracts } from '@/lib/contracts'
import { Address } from 'viem'
import { GetPricesResult } from '@/app/user/types'
import { formatCurrency } from '@/lib/utils'
Expand All @@ -13,7 +13,7 @@ type BucketItem = {

type Bucket = {
RIF: BucketItem
rBTC: BucketItem
RBTC: BucketItem
}

interface TreasuryContextProps {
Expand All @@ -24,19 +24,19 @@ interface TreasuryContextProps {
const getAllBucketsHoldings = (buckets: Bucket[]) => {
const totalBalance = {
RIF: 0,
rBTC: 0,
RBTC: 0,
}

buckets.forEach(bucket => {
totalBalance.RIF += Number(bucket.RIF.amount)
totalBalance.rBTC += Number(bucket.rBTC.amount)
totalBalance.RBTC += Number(bucket.RBTC.amount)
})
return totalBalance
}

const TreasuryContext = createContext<TreasuryContextProps>({
buckets: [],
bucketsTotal: { RIF: 0, rBTC: 0 },
bucketsTotal: { RIF: 0, RBTC: 0 },
})

interface Props {
Expand All @@ -53,18 +53,18 @@ const getBucketBalance = (
amount: bucketBalance.RIF.balance,
fiatAmount: formatCurrency(Number(bucketBalance.RIF.balance) * (prices.RIF?.price ?? 0)),
},
rBTC: {
amount: bucketBalance.rBTC.balance,
fiatAmount: formatCurrency(Number(bucketBalance.rBTC.balance) * (prices.rBTC?.price ?? 0)),
RBTC: {
amount: bucketBalance.RBTC.balance,
fiatAmount: formatCurrency(Number(bucketBalance.RBTC.balance) * (prices.RBTC?.price ?? 0)),
},
})

const TreasuryContextProvider = ({ children }: Props) => {
const { prices } = usePricesContext()

const bucketOneBalance = useGetTreasuryBucketBalance(currentEnvTreasuryContracts[0].address as Address)
const bucketTwoBalance = useGetTreasuryBucketBalance(currentEnvTreasuryContracts[1].address as Address)
const bucketThreeBalance = useGetTreasuryBucketBalance(currentEnvTreasuryContracts[2].address as Address)
const bucketOneBalance = useGetTreasuryBucketBalance(treasuryContracts[0].address)
const bucketTwoBalance = useGetTreasuryBucketBalance(treasuryContracts[1].address)
const bucketThreeBalance = useGetTreasuryBucketBalance(treasuryContracts[2].address)

const bucketOne: Bucket = useMemo(
() => getBucketBalance(bucketOneBalance, prices),
Expand Down
18 changes: 9 additions & 9 deletions src/app/treasury/TreasurySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ export const TreasurySection = () => {
fiatAmount={`= USD ${bucketThree.RIF.fiatAmount}`}
/>
<MetricsCard
title="Treasury 1 rBTC Holdings"
amount={bucketOne.rBTC.amount}
fiatAmount={`= USD ${bucketOne.rBTC.fiatAmount}`}
title="Treasury 1 RBTC Holdings"
amount={bucketOne.RBTC.amount}
fiatAmount={`= USD ${bucketOne.RBTC.fiatAmount}`}
/>
<MetricsCard
title="Treasury 2 rBTC Holdings"
amount={bucketTwo.rBTC.amount}
fiatAmount={`= USD ${bucketTwo.rBTC.fiatAmount}`}
title="Treasury 2 RBTC Holdings"
amount={bucketTwo.RBTC.amount}
fiatAmount={`= USD ${bucketTwo.RBTC.fiatAmount}`}
/>
<MetricsCard
title="Treasury 3 rBTC Holdings"
amount={bucketThree.rBTC.amount}
fiatAmount={`= USD ${bucketThree.rBTC.fiatAmount}`}
title="Treasury 3 RBTC Holdings"
amount={bucketThree.RBTC.amount}
fiatAmount={`= USD ${bucketThree.RBTC.fiatAmount}`}
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/treasury/hooks/useGetTreasuryBucketBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export const useGetTreasuryBucketBalance = (address: Address) => {

return {
RIF: getTokenBalance('RIF', query.data),
rBTC: getTokenBalance('rBTC', query.data),
RBTC: getTokenBalance('RBTC', query.data),
}
}
6 changes: 3 additions & 3 deletions src/app/user/Balances/BalancesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const data = [
},
{
token: 'Rootstock Bitcoin',
symbol: <RenderTokenSymbol symbol="rBTC" />,
'Token Price': <RenderTokenPrice symbol="rBTC" />,
'Total Balance': <RenderTotalBalance symbol="rBTC" />,
symbol: <RenderTokenSymbol symbol="RBTC" />,
'Token Price': <RenderTokenPrice symbol="RBTC" />,
'Total Balance': <RenderTotalBalance symbol="RBTC" />,
actions: '',
},
]
Expand Down
4 changes: 2 additions & 2 deletions src/app/user/Balances/RenderTokenSymbol.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useBalancesContext } from '@/app/user/Balances/context/BalancesContext'
import { currentEnvContracts, SupportedTokens } from '@/lib/contracts'
import { tokenContracts, SupportedTokens } from '@/lib/contracts'
import { useWalletClient } from 'wagmi'

interface Props {
Expand All @@ -15,7 +15,7 @@ export const RenderTokenSymbol = ({ symbol }: Props) => {
walletClient.watchAsset({
type: 'ERC20',
options: {
address: currentEnvContracts[symbol],
address: tokenContracts[symbol],
decimals: 18,
symbol: balances[symbol].symbol,
},
Expand Down
10 changes: 5 additions & 5 deletions src/app/user/Balances/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
fetchPricesEndpoint,
fetchProposalsCreatedByGovernorAddress,
} from '@/lib/endpoints'
import { currentEnvContracts, GovernorAddress } from '@/lib/contracts'
import { tokenContracts, GovernorAddress } from '@/lib/contracts'

export const fetchAddressTokens = (address: string, chainId = 31) =>
axiosInstance
Expand All @@ -21,15 +21,15 @@ export const fetchPrices = () =>
axiosInstance
.get<GetPricesResult>(
fetchPricesEndpoint
.replace('{{addresses}}', Object.values(currentEnvContracts).join(','))
.replace('{{addresses}}', Object.values(tokenContracts).join(','))
.replace('{{convert}}', 'USD'),
)
.then(({ data: prices }) => {
const pricesReturn: GetPricesResult = {}
for (const contract in prices) {
const contractFromEnv = (
Object.keys(currentEnvContracts) as Array<keyof typeof currentEnvContracts>
).find(contractName => currentEnvContracts[contractName] === contract)
const contractFromEnv = (Object.keys(tokenContracts) as Array<keyof typeof tokenContracts>).find(
contractName => tokenContracts[contractName] === contract,
)
if (contractFromEnv) {
pricesReturn[contractFromEnv] = prices[contract]
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/user/Balances/balanceUtils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { BigNumberish, ethers } from 'ethers'
import { GetAddressTokenResult, TokenBalance } from '@/app/user/types'
import { currentEnvContracts } from '@/lib/contracts'
import { tokenContracts } from '@/lib/contracts'

export const formatBalanceToHuman = (balance: BigNumberish, decimal = 18) =>
ethers.formatUnits(balance, decimal)

const symbolsToGetFromArray = {
RIF: { equivalentSymbols: ['tRIF', 'RIF'], currentContract: currentEnvContracts.RIF },
rBTC: { equivalentSymbols: ['rBTC', 'tRBTC'], currentContract: currentEnvContracts.rBTC },
stRIF: { equivalentSymbols: ['stRIF'], currentContract: currentEnvContracts.stRIF },
RIF: { equivalentSymbols: ['tRIF', 'RIF'], currentContract: tokenContracts.RIF },
RBTC: { equivalentSymbols: ['RBTC', 'tRBTC'], currentContract: tokenContracts.RBTC },
stRIF: { equivalentSymbols: ['stRIF'], currentContract: tokenContracts.stRIF },
}

export type SymbolsEquivalentKeys = keyof typeof symbolsToGetFromArray
Expand Down
5 changes: 3 additions & 2 deletions src/app/user/Balances/hooks/useGetAddressBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { useMemo } from 'react'
import { getTokenBalance } from '@/app/user/Balances/balanceUtils'
import { TokenBalanceRecord } from '@/app/user/types'
import { useAccount } from 'wagmi'
import { Address } from 'viem'

export const useGetAddressBalances = (): TokenBalanceRecord => {
const { address, chainId } = useAccount()

const query = useGetAddressTokens(address as string, chainId as number)
const query = useGetAddressTokens(address as Address, chainId as number)

return useMemo(
() => ({
RIF: getTokenBalance('RIF', query.data),
rBTC: getTokenBalance('rBTC', query.data),
RBTC: getTokenBalance('RBTC', query.data),
stRIF: getTokenBalance('stRIF', query.data),
}),
[query.data],
Expand Down
22 changes: 11 additions & 11 deletions src/app/user/Balances/hooks/useGetAddressTokens.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useBalance, useReadContracts } from 'wagmi'
import { Address } from 'viem'
import { RIFTokenAbi } from '@/lib/abis/RIFTokenAbi'
import { currentEnvContracts } from '@/lib/contracts'
import { tokenContracts, MulticallAddress } from '@/lib/contracts'
import { ZeroAddress } from 'ethers'
import { AddressToken } from '@/app/user/types'

Expand All @@ -15,22 +15,22 @@ const getTokenFunction = (tokenAddress: string, userAddress: string, functionNam

type TokenData = [{ result: string | bigint }, { result: string | bigint }]

const buildTokenBalanceObject = (symbol: keyof typeof currentEnvContracts, tokenData?: TokenData) => ({
const buildTokenBalanceObject = (symbol: keyof typeof tokenContracts, tokenData?: TokenData) => ({
symbol: tokenData ? tokenData?.[1]?.result : symbol,
contractAddress: currentEnvContracts[symbol],
contractAddress: tokenContracts[symbol],
balance: tokenData?.[0]?.result ? tokenData[0].result.toString() : '0',
})

export const useGetAddressTokens = (address: string, chainId: number) => {
const { data: RBTC } = useBalance({ address: address as Address, chainId })
export const useGetAddressTokens = (address: Address, chainId: number) => {
const { data: RBTC } = useBalance({ address, chainId })
const { data } = useReadContracts({
contracts: [
getTokenFunction(currentEnvContracts.RIF, address, 'balanceOf'),
getTokenFunction(currentEnvContracts.RIF, address, 'symbol'),
getTokenFunction(currentEnvContracts.stRIF, address, 'balanceOf'),
getTokenFunction(currentEnvContracts.stRIF, address, 'symbol'),
getTokenFunction(tokenContracts.RIF, address, 'balanceOf'),
getTokenFunction(tokenContracts.RIF, address, 'symbol'),
getTokenFunction(tokenContracts.stRIF, address, 'balanceOf'),
getTokenFunction(tokenContracts.stRIF, address, 'symbol'),
],
multicallAddress: currentEnvContracts.multicall as Address,
multicallAddress: MulticallAddress,
query: {
refetchInterval: 5000,
},
Expand All @@ -43,7 +43,7 @@ export const useGetAddressTokens = (address: string, chainId: number) => {
buildTokenBalanceObject('stRIF', stRIF as TokenData),
buildTokenBalanceObject('RIF', RIF as TokenData),
{
symbol: RBTC?.symbol || 'rBTC',
symbol: RBTC?.symbol || 'RBTC',
balance: RBTC?.value.toString() || '0',
contractAddress: ZeroAddress,
},
Expand Down
2 changes: 1 addition & 1 deletion src/app/user/Balances/hooks/useGetSpecificPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useGetSpecificPrices = (): GetPricesResult => {
return useMemo(
() => ({
RIF: getDefaultPriceObject('RIF', query.data),
rBTC: getDefaultPriceObject('rBTC', query.data),
RBTC: getDefaultPriceObject('RBTC', query.data),
stRIF: getDefaultPriceObject('RIF', query.data), // stRIF price is the same as RIF
}),
[query.data],
Expand Down
Loading

0 comments on commit b2bc59e

Please sign in to comment.