diff --git a/.env.prod b/.env.prod index 08a33619..42cb6005 100644 --- a/.env.prod +++ b/.env.prod @@ -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= diff --git a/.env.testnet b/.env.testnet index 7c7f30f0..42381850 100644 --- a/.env.testnet +++ b/.env.testnet @@ -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 diff --git a/src/app/communities/page.tsx b/src/app/communities/page.tsx index ffb1f248..d754734c 100644 --- a/src/app/communities/page.tsx +++ b/src/app/communities/page.tsx @@ -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 = { @@ -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, } diff --git a/src/app/proposals/hooks/useCreateProposal.ts b/src/app/proposals/hooks/useCreateProposal.ts index 5e6f55f8..fbcf301f 100644 --- a/src/app/proposals/hooks/useCreateProposal.ts +++ b/src/app/proposals/hooks/useCreateProposal.ts @@ -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' @@ -23,7 +23,7 @@ const createProposalForStRifTransfer = ( calldata: ReturnType, 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 { diff --git a/src/app/proposals/hooks/useVotingPower.ts b/src/app/proposals/hooks/useVotingPower.ts index 0b4c51e9..d1a57756 100644 --- a/src/app/proposals/hooks/useVotingPower.ts +++ b/src/app/proposals/hooks/useVotingPower.ts @@ -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' @@ -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' }, diff --git a/src/app/treasury/TokenHoldingsStRIF.tsx b/src/app/treasury/TokenHoldingsStRIF.tsx index d77ae641..4a85056d 100644 --- a/src/app/treasury/TokenHoldingsStRIF.tsx +++ b/src/app/treasury/TokenHoldingsStRIF.tsx @@ -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', }) diff --git a/src/app/treasury/TotalTokenHoldingsSection.tsx b/src/app/treasury/TotalTokenHoldingsSection.tsx index 6d982115..2fafae78 100644 --- a/src/app/treasury/TotalTokenHoldingsSection.tsx +++ b/src/app/treasury/TotalTokenHoldingsSection.tsx @@ -13,9 +13,9 @@ const tableData = [ }, { token: 'Rootstock Bitcoin', - symbol: 'rBTC', - price: , - holdings: , + symbol: 'RBTC', + price: , + holdings: , }, { token: 'Staked Rootstock Infrastructure Framework', diff --git a/src/app/treasury/TreasuryContext.tsx b/src/app/treasury/TreasuryContext.tsx index df4ef369..116d7341 100644 --- a/src/app/treasury/TreasuryContext.tsx +++ b/src/app/treasury/TreasuryContext.tsx @@ -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' @@ -13,7 +13,7 @@ type BucketItem = { type Bucket = { RIF: BucketItem - rBTC: BucketItem + RBTC: BucketItem } interface TreasuryContextProps { @@ -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({ buckets: [], - bucketsTotal: { RIF: 0, rBTC: 0 }, + bucketsTotal: { RIF: 0, RBTC: 0 }, }) interface Props { @@ -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), diff --git a/src/app/treasury/TreasurySection.tsx b/src/app/treasury/TreasurySection.tsx index 166006d9..f611e569 100644 --- a/src/app/treasury/TreasurySection.tsx +++ b/src/app/treasury/TreasurySection.tsx @@ -25,19 +25,19 @@ export const TreasurySection = () => { fiatAmount={`= USD ${bucketThree.RIF.fiatAmount}`} /> diff --git a/src/app/treasury/hooks/useGetTreasuryBucketBalance.ts b/src/app/treasury/hooks/useGetTreasuryBucketBalance.ts index 186faeb2..89a12b00 100644 --- a/src/app/treasury/hooks/useGetTreasuryBucketBalance.ts +++ b/src/app/treasury/hooks/useGetTreasuryBucketBalance.ts @@ -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), } } diff --git a/src/app/user/Balances/BalancesSection.tsx b/src/app/user/Balances/BalancesSection.tsx index 386ff0e2..b3eeee26 100644 --- a/src/app/user/Balances/BalancesSection.tsx +++ b/src/app/user/Balances/BalancesSection.tsx @@ -26,9 +26,9 @@ const data = [ }, { token: 'Rootstock Bitcoin', - symbol: , - 'Token Price': , - 'Total Balance': , + symbol: , + 'Token Price': , + 'Total Balance': , actions: '', }, ] diff --git a/src/app/user/Balances/RenderTokenSymbol.tsx b/src/app/user/Balances/RenderTokenSymbol.tsx index 8df21e5a..8c0bff3e 100644 --- a/src/app/user/Balances/RenderTokenSymbol.tsx +++ b/src/app/user/Balances/RenderTokenSymbol.tsx @@ -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 { @@ -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, }, diff --git a/src/app/user/Balances/actions.ts b/src/app/user/Balances/actions.ts index f20f1715..814d4175 100644 --- a/src/app/user/Balances/actions.ts +++ b/src/app/user/Balances/actions.ts @@ -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 @@ -21,15 +21,15 @@ export const fetchPrices = () => axiosInstance .get( 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 - ).find(contractName => currentEnvContracts[contractName] === contract) + const contractFromEnv = (Object.keys(tokenContracts) as Array).find( + contractName => tokenContracts[contractName] === contract, + ) if (contractFromEnv) { pricesReturn[contractFromEnv] = prices[contract] } diff --git a/src/app/user/Balances/balanceUtils.ts b/src/app/user/Balances/balanceUtils.ts index 31f1602b..564c47c9 100644 --- a/src/app/user/Balances/balanceUtils.ts +++ b/src/app/user/Balances/balanceUtils.ts @@ -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 diff --git a/src/app/user/Balances/hooks/useGetAddressBalances.ts b/src/app/user/Balances/hooks/useGetAddressBalances.ts index a78b4fc2..b2274ad8 100644 --- a/src/app/user/Balances/hooks/useGetAddressBalances.ts +++ b/src/app/user/Balances/hooks/useGetAddressBalances.ts @@ -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], diff --git a/src/app/user/Balances/hooks/useGetAddressTokens.ts b/src/app/user/Balances/hooks/useGetAddressTokens.ts index b4489c5b..71574f33 100644 --- a/src/app/user/Balances/hooks/useGetAddressTokens.ts +++ b/src/app/user/Balances/hooks/useGetAddressTokens.ts @@ -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' @@ -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, }, @@ -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, }, diff --git a/src/app/user/Balances/hooks/useGetSpecificPrices.ts b/src/app/user/Balances/hooks/useGetSpecificPrices.ts index 594d7588..b15fa6b0 100644 --- a/src/app/user/Balances/hooks/useGetSpecificPrices.ts +++ b/src/app/user/Balances/hooks/useGetSpecificPrices.ts @@ -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], diff --git a/src/app/user/Stake/StakingSteps.tsx b/src/app/user/Stake/StakingSteps.tsx index c676fd8b..68ac1d39 100644 --- a/src/app/user/Stake/StakingSteps.tsx +++ b/src/app/user/Stake/StakingSteps.tsx @@ -4,7 +4,7 @@ import { useSteps } from '@/app/user/Stake/hooks/useSteps' import { Modal } from '@/components/Modal/Modal' import { useBalancesContext } from '@/app/user/Balances/context/BalancesContext' import { StakingToken } from '@/app/user/Stake/types' -import { currentEnvContracts } from '@/lib/contracts' +import { tokenContracts } from '@/lib/contracts' import { stakingSteps } from './Steps/stepsUtils' import { useStakeRIF } from '@/app/user/Stake/hooks/useStakeRIF' @@ -26,7 +26,7 @@ const StakingSteps = ({ onCloseModal }: StakingStepsProps) => { () => ({ balance: balances.RIF.balance, symbol: balances.RIF.symbol, - contract: currentEnvContracts.RIF, + contract: tokenContracts.RIF, price: prices.RIF?.price.toString(), }), [balances.RIF.balance, balances.RIF.symbol, prices.RIF?.price], @@ -36,7 +36,7 @@ const StakingSteps = ({ onCloseModal }: StakingStepsProps) => { () => ({ balance: balances.stRIF.balance, symbol: balances.stRIF.symbol, - contract: currentEnvContracts.stRIF, + contract: tokenContracts.stRIF, price: prices.stRIF?.price.toString(), }), [balances.stRIF.balance, balances.stRIF.symbol, prices.stRIF?.price], diff --git a/src/app/user/Stake/UnStakingSteps.tsx b/src/app/user/Stake/UnStakingSteps.tsx index 0f6d6336..4ff6a151 100644 --- a/src/app/user/Stake/UnStakingSteps.tsx +++ b/src/app/user/Stake/UnStakingSteps.tsx @@ -3,7 +3,7 @@ import { useBalancesContext } from '@/app/user/Balances/context/BalancesContext' import { useMemo } from 'react' import { steps } from '@/app/user/Stake/Steps/stepsUtils' import { StakingToken } from '@/app/user/Stake/types' -import { currentEnvContracts } from '@/lib/contracts' +import { tokenContracts } from '@/lib/contracts' import { StakingProvider } from '@/app/user/Stake/StakingContext' import { Modal } from '@/components/Modal/Modal' import { useUnstakeStRIF } from '@/app/user/Stake/hooks/useUnstakeStRIF' @@ -26,7 +26,7 @@ const UnStakingSteps = ({ onCloseModal }: StakingStepsProps) => { () => ({ balance: balances.stRIF.balance, symbol: balances.stRIF.symbol, - contract: currentEnvContracts.stRIF, + contract: tokenContracts.stRIF, price: prices.stRIF?.price.toString(), }), [balances.stRIF.balance, balances.stRIF.symbol, prices.stRIF?.price], @@ -36,7 +36,7 @@ const UnStakingSteps = ({ onCloseModal }: StakingStepsProps) => { () => ({ balance: balances.RIF.balance, symbol: balances.RIF.symbol, - contract: currentEnvContracts.RIF, + contract: tokenContracts.RIF, price: prices.RIF?.price.toString(), }), [balances.RIF.balance, balances.RIF.symbol, prices.RIF?.price], diff --git a/src/app/user/Stake/hooks/useStakeRIF.tsx b/src/app/user/Stake/hooks/useStakeRIF.tsx index 362eae0e..b73ceeeb 100644 --- a/src/app/user/Stake/hooks/useStakeRIF.tsx +++ b/src/app/user/Stake/hooks/useStakeRIF.tsx @@ -1,6 +1,6 @@ import { useAccount, useReadContract, useWriteContract, useWaitForTransactionReceipt } from 'wagmi' import { RIFTokenAbi } from '@/lib/abis/RIFTokenAbi' -import { currentEnvContracts } from '@/lib/contracts' +import { tokenContracts } from '@/lib/contracts' import { Address, parseEther } from 'viem' import { useCallback, useMemo } from 'react' import { StRIFTokenAbi } from '@/lib/abis/StRIFTokenAbi' @@ -22,7 +22,7 @@ export const useStakeRIF: ActionHookToUse = ( const { data: allowanceBalance, isLoading: isAllowanceReadLoading } = useReadContract({ abi: RIFTokenAbi, - address: currentEnvContracts.RIF as Address, + address: tokenContracts.RIF, functionName: 'allowance', args: [address!, tokenToReceiveContract as Address], query: { diff --git a/src/components/LeftSidebar/links.tsx b/src/components/LeftSidebar/links.tsx index 70b02d83..640c6e84 100644 --- a/src/components/LeftSidebar/links.tsx +++ b/src/components/LeftSidebar/links.tsx @@ -1,3 +1,5 @@ +import { ENV } from '@/lib/constants' + const testnet = { registerRns: 'https://testnet.manager.rns.rifos.org/', tokenBridge: 'https://testnet.tokenbridge.rsk.co/', @@ -17,4 +19,4 @@ const environments = { mainnet, } // @ts-ignore -export const currentLinks = environments[process.env.NEXT_PUBLIC_ENV] as typeof testnet +export const currentLinks = environments[ENV] as typeof testnet diff --git a/src/lib/constants.ts b/src/lib/constants.ts new file mode 100644 index 00000000..c9e5173d --- /dev/null +++ b/src/lib/constants.ts @@ -0,0 +1,14 @@ +import { Address } from 'viem' + +export const ENV = process.env.NEXT_PUBLIC_ENV +export const RIF_WALLET_SERVICES_URL = process.env.NEXT_PUBLIC_RIF_WALLET_SERVICES +export const EXPLORER_URL = process.env.NEXT_PUBLIC_EXPLORER + +export const RIF_ADDRESS = process.env.NEXT_PUBLIC_RIF_ADDRESS as Address +export const STRIF_ADDRESS = process.env.NEXT_PUBLIC_STRIF_ADDRESS as Address +export const GOVERNOR_ADDRESS = process.env.NEXT_PUBLIC_GOVERNOR_ADDRESS as Address +export const EA_NFT_ADDRESS = process.env.NEXT_PUBLIC_EA_NFT_ADDRESS as Address +export const MULTICALL_ADDRESS = process.env.NEXT_PUBLIC_MULTICALL_ADDRESS as Address +export const BUCKET1_ADDRESS = process.env.NEXT_PUBLIC_BUCKET1_ADDRESS as Address +export const BUCKET2_ADDRESS = process.env.NEXT_PUBLIC_BUCKET2_ADDRESS as Address +export const BUCKET3_ADDRESS = process.env.NEXT_PUBLIC_BUCKET3_ADDRESS as Address diff --git a/src/lib/contracts.ts b/src/lib/contracts.ts index 3bad31ad..b9462c51 100644 --- a/src/lib/contracts.ts +++ b/src/lib/contracts.ts @@ -1,87 +1,48 @@ +import { ZeroAddress } from 'ethers' import { Address } from 'viem' import { EarlyAdoptersNFTAbi } from './abis/EarlyAdoptersNFTAbi' +import { + BUCKET1_ADDRESS, + BUCKET2_ADDRESS, + BUCKET3_ADDRESS, + EA_NFT_ADDRESS, + GOVERNOR_ADDRESS, + MULTICALL_ADDRESS, + RIF_ADDRESS, + STRIF_ADDRESS, +} from './constants' -const testnet = { - RIF: '0x19f64674d8a5b4e652319f5e239efd3bc969a1fe', // tRIF - stRIF: '0xAF17f7A0124E9F360ffA484b13566b041C0f5023', - rBTC: '0x0000000000000000000000000000000000000000', - multicall: '0xcA11bde05977b3631167028862bE2a173976CA11', +const tokenContracts = { + RIF: RIF_ADDRESS, + stRIF: STRIF_ADDRESS, + RBTC: ZeroAddress as Address, } +export type SupportedTokens = keyof typeof tokenContracts -const mainnet = { - RIF: '0x2acc95758f8b5f583470ba265eb685a8f45fc9d5', - stRIF: '', // @TODO get DAO mainnet - rBTC: '0x0000000000000000000000000000000000000000', - multicall: '', +const nftContracts = { + EA: EA_NFT_ADDRESS, // Early Adopters } -const contracts = { - testnet, - mainnet, +const abiContractsMap: { [key: string]: any } = { + [nftContracts.EA?.toLowerCase()]: EarlyAdoptersNFTAbi, } -export type SupportedTokens = keyof typeof testnet | keyof typeof mainnet -// @ts-ignore -export const currentEnvContracts = contracts[process.env.NEXT_PUBLIC_ENV] as typeof testnet - -const testnetNft = { - RDEA: '0xa3076bcaCc7112B7fa7c5A87CF32275296d85D64' as Address, // RIF DAO Early Adopters - EA: '0xf24761C1B57b14EeA270B1485294D93494164246' as Address, // Early Adopters -} - -const mainnetNft = { - // TODO - RDEA: '', - EA: '', -} - -const contractsNFT = { - testnet: testnetNft, - mainnet: mainnetNft, -} -// @ts-ignore -export const currentEnvNFTContracts = contractsNFT[process.env.NEXT_PUBLIC_ENV] as typeof testnetNft - -export const abiContractsMap: { [key: string]: any } = { - [currentEnvNFTContracts?.EA.toLowerCase()]: EarlyAdoptersNFTAbi, -} - -const treasuryContractsTestnet = [ +const treasuryContracts = [ { name: 'Bucket 1', - address: '0xf5b9Ccfe0F695195C4F2E2b5A99b9b5d79EB8089', + address: BUCKET1_ADDRESS, }, { name: 'Bucket 2', - address: '0x8d90a8f30fBC93D9BB62758502bBCB640e59d0f4', + address: BUCKET2_ADDRESS, }, { name: 'Bucket 3', - address: '0x1E6406ddcf3c9Ab882686d4c9d80d184e7f3bF02', + address: BUCKET3_ADDRESS, }, ] -const contractsTreasury = { - testnet: treasuryContractsTestnet, -} - -export const currentEnvTreasuryContracts = contractsTreasury[ - // @ts-ignore - process.env.NEXT_PUBLIC_ENV -] as typeof treasuryContractsTestnet - -const testnetGovernor = { - value: '0x00ca74491D9493bFe5451246C8c72849Ba4A7F9D', -} -const mainnetGovernor = { - value: '', -} - -const governorContracts = { - testnet: testnetGovernor, - mainnet: mainnetGovernor, -} +const GovernorAddress = GOVERNOR_ADDRESS +const MulticallAddress = MULTICALL_ADDRESS -// @ts-ignore -export const GovernorAddress = (governorContracts[process.env.NEXT_PUBLIC_ENV] as typeof testnetGovernor) - ?.value as Address +export { tokenContracts, nftContracts, abiContractsMap, treasuryContracts, GovernorAddress, MulticallAddress } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 55439712..73f498a7 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,6 +1,7 @@ -import { twMerge } from 'tailwind-merge' -import { clsx, ClassValue } from 'clsx' import axios from 'axios' +import { ClassValue, clsx } from 'clsx' +import { twMerge } from 'tailwind-merge' +import { EXPLORER_URL, RIF_WALLET_SERVICES_URL } from './constants' /** * Merges Tailwind and clsx classes in order to avoid classes conflicts. @@ -24,7 +25,7 @@ export const shortAddress = (address: string | undefined, amount = 5): string => } export const axiosInstance = axios.create({ - baseURL: process.env.NEXT_PUBLIC_RIF_WALLET_SERVICES, + baseURL: RIF_WALLET_SERVICES_URL, }) /** @@ -56,15 +57,13 @@ export const truncateMiddle = (str: string, start = 10, end = 10): string => { return str.slice(0, start) + '...' + str.slice(-end) } -export const explorerURL = process.env.NEXT_PUBLIC_EXPLORER - export const isValidNumber = (value: string) => { // Regular expression to check if the input is a number with one allowed decimal const regex = /^\d*\.?\d{0,18}$/ return regex.test(value) } -export const goToExplorerWithTxHash = (hash: string) => window.open(`${explorerURL}/tx/${hash}`, '_blank') +export const goToExplorerWithTxHash = (hash: string) => window.open(`${EXPLORER_URL}/tx/${hash}`, '_blank') /** * Sanitizes a number to a string representation diff --git a/src/pages/proposals/create.tsx b/src/pages/proposals/create.tsx index 80c06ae6..557d68e7 100644 --- a/src/pages/proposals/create.tsx +++ b/src/pages/proposals/create.tsx @@ -21,9 +21,8 @@ import { MainContainer } from '@/components/MainContainer/MainContainer' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/Select' import { Textarea } from '@/components/Textarea' import { Header, Paragraph } from '@/components/Typography' -import { currentEnvContracts } from '@/lib/contracts' +import { tokenContracts } from '@/lib/contracts' import { formatCurrency } from '@/lib/utils' -import { usePricesContext } from '@/shared/context/PricesContext' import { zodResolver } from '@hookform/resolvers/zod' import Image from 'next/image' import { useRouter } from 'next/navigation' @@ -62,7 +61,7 @@ export default function CreateProposal() { proposalName: '', description: '', toAddress: '', - tokenAddress: currentEnvContracts.RIF as Address, + tokenAddress: tokenContracts.RIF, amount: undefined, }, }) @@ -74,7 +73,7 @@ export default function CreateProposal() { watch, } = form - const pricesMap = useMemo(() => ({ [currentEnvContracts.RIF]: prices.RIF }), [prices]) + const pricesMap = useMemo(() => ({ [tokenContracts.RIF]: prices.RIF }), [prices]) const isProposalNameValid = !errors.proposalName && touchedFields.proposalName const isDescriptionValid = !errors.description && touchedFields.description @@ -225,7 +224,7 @@ export default function CreateProposal() { RBTC */} - +