Skip to content

Commit

Permalink
updated ipfs data structure checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight committed Jan 9, 2025
1 parent a76e5d1 commit ab46a12
Show file tree
Hide file tree
Showing 38 changed files with 422 additions and 329 deletions.
2 changes: 1 addition & 1 deletion packages/contracts/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const TS_AGGREGATOR_TOKEN_TRANSFER_PROXY_CONTRACT_MAINNET =
// export const RFOX_PROXY_CONTRACT: Address = '0x1094c4a99fce60e69ffe75849309408f1262d304'
// export const RFOX_LP_PROXY_CONTRACT: Address = '0x4843373F380aDf80C779cD4dEDC6452E414f7634'

export const RFOX_PROXY_CONTRACT: Address = '0xac2a4fd70bcd8bab0662960455c363735f0e2b56'
export const RFOX_PROXY_CONTRACT: Address = '0xaC2a4fD70BCD8Bab0662960455c363735f0e2b56'
export const RFOX_LP_PROXY_CONTRACT: Address = '0x83B51B7605d2E277E03A7D6451B1efc0e5253A2F'
export const RFOX_REWARD_RATE = 1n * 10n ** 27n
export const RFOX_WAD = 1n * 10n ** 18n
Expand Down
13 changes: 7 additions & 6 deletions src/assets/translations/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2645,15 +2645,15 @@
"noSupportedChainsDescription": "Add %{chainLabel} or connect to a wallet that supports it.",
"confirmAndBridge": "Confirm & Bridge",
"myStakedBalance": "My Staked Balance",
"myStakedBalanceHelper": "The amount of FOX you have staked",
"myStakedBalanceHelper": "The amount of %{symbol} you have staked",
"pendingRewardsBalance": "Pending Rewards Balance",
"pendingRewardsBalanceHelper": "This is only an estimate of your pending rewards based on epoch to date revenues. All accounting is done at epoch end and cannot be calculated exactly before the end of the month",
"lifetimeRewards": "Lifetime Rewards",
"lifetimeRewardsHelper": "Lifetime rewards is the cumulative rewards from staking your FOX",
"lifetimeRewardsHelper": "The total rewards you have earned from staking your %{symbol} to date",
"timeInPool": "Time in Pool",
"timeInPoolHelper": "Time in pool is the longest living deposit into rFOX",
"myPosition": "My Position",
"positionDetails": "Position details",
"positionDetails": "Position Details",
"mySymbolPosition": "My %{symbol} Position",
"faq": {
"title": "FAQ",
Expand Down Expand Up @@ -2687,10 +2687,11 @@
}
},
"totals": "rFOX Totals",
"totalStaked": "Total FOX Staked",
"totalStaked": "Total %{symbol} Staked",
"totalStakedHelper": "The total amount of %{symbol} staked",
"totalFeesCollected": "Total Fees Collected (This Epoch)",
"emissionsPool": "Emissions Pool (This Epoch)",
"emissionsPoolHelper": "Emissions Pool (This Epoch)",
"emissionsPool": "%{symbol} Emissions Pool (This Epoch)",
"emissionsPoolHelper": "The total amount of rewards to be distributed %{symbol} stakers",
"foxBurnAmount": "FOX Burn Amount (This Epoch)",
"pendingDistribution": "Pending Distribution"
},
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Fox/components/RFOXSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const RFOXSection = () => {
isLoading: isStakingBalanceCryptoPrecisionQueryLoading,
isFetching: isStakingBalanceCryptoPrecisionFetching,
} = useStakingInfoQuery({
stakingAssetId,
stakingAssetAccountAddress,
select: selectStakingBalanceCryptoPrecision,
})
Expand All @@ -159,6 +160,7 @@ export const RFOXSection = () => {
isLoading: isCurrentEpochRewardsCryptoBaseUnitQueryLoading,
isFetching: isCurrentEpochRewardsCryptoBaseUnitFetching,
} = useCurrentEpochRewardsQuery({
stakingAssetId,
stakingAssetAccountAddress,
currentEpochMetadata: currentEpochMetadataResult.data,
})
Expand All @@ -179,6 +181,7 @@ export const RFOXSection = () => {
isLoading: isLifetimeRewardsQueryLoading,
isFetching: isLifetimeRewardsFetching,
} = useLifetimeRewardsQuery({
stakingAssetId,
stakingAssetAccountAddress,
})

Expand All @@ -191,6 +194,7 @@ export const RFOXSection = () => {
isLoading: isTimeInPoolQueryLoading,
isFetching: isTimeInPoolFetching,
} = useTimeInPoolQuery({
stakingAssetId,
stakingAssetAccountAddress,
select: timeInPoolSeconds =>
timeInPoolSeconds === 0n ? 'N/A' : formatSecondsToDuration(Number(timeInPoolSeconds)),
Expand Down
11 changes: 7 additions & 4 deletions src/pages/Fox/components/RFOXSimulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Amount } from 'components/Amount/Amount'
import { Text } from 'components/Text'
import { bnOrZero } from 'lib/bignumber/bignumber'
import { fromBaseUnit } from 'lib/math'
import { selectLastEpoch } from 'pages/RFOX/helpers'
import { getStakingContract, selectLastEpoch } from 'pages/RFOX/helpers'
import { useEpochHistoryQuery } from 'pages/RFOX/hooks/useEpochHistoryQuery'
import { useTotalStakedQuery } from 'pages/RFOX/hooks/useGetTotalStaked'
import { selectAssetById, selectUsdRateByAssetId } from 'state/slices/selectors'
Expand Down Expand Up @@ -44,6 +44,7 @@ export const RFOXSimulator = ({ stakingAssetId }: RFOXSimulatorProps) => {
const runeAsset = useAppSelector(state => selectAssetById(state, thorchainAssetId))

const totalStakedCryptoResult = useTotalStakedQuery<string>({
stakingAssetId,
select: (totalStaked: bigint) => {
return bnOrZero(fromBaseUnit(totalStaked.toString(), stakingAsset?.precision ?? 0)).toFixed(2)
},
Expand Down Expand Up @@ -72,16 +73,18 @@ export const RFOXSimulator = ({ stakingAssetId }: RFOXSimulatorProps) => {

const estimatedRewards = useMemo(() => {
if (!lastEpoch) return
if (!stakingAsset) return
if (!poolShare) return
if (!runeUsdPrice) return

const distributionRate =
lastEpoch.detailsByStakingContract[getStakingContract(stakingAssetId)].distributionRate

return bnOrZero(shapeShiftRevenue)
.times(lastEpoch.distributionRate)
.times(distributionRate)
.times(poolShare)
.div(runeUsdPrice)
.toFixed(2)
}, [lastEpoch, shapeShiftRevenue, runeUsdPrice, stakingAsset, poolShare])
}, [lastEpoch, shapeShiftRevenue, runeUsdPrice, stakingAssetId, poolShare])

if (!(runeAsset && stakingAsset)) return null

Expand Down
37 changes: 13 additions & 24 deletions src/pages/RFOX/RFOX.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { StackDirection } from '@chakra-ui/react'
import { Stack } from '@chakra-ui/react'
import { foxOnArbitrumOneAssetId } from '@shapeshiftoss/caip'
import { Main } from 'components/Layout/Main'
import { selectAssetById } from 'state/slices/selectors'
import { useAppSelector } from 'state/store'

import { Faq } from './components/Faq/Faq'
import { Overview } from './components/Overview/Overview'
Expand All @@ -15,27 +12,19 @@ const direction: StackDirection = { base: 'column-reverse', xl: 'row' }
const maxWidth = { base: '100%', md: '450px' }
const mainPaddingBottom = { base: 16, md: 8 }

const stakingAssetId = foxOnArbitrumOneAssetId

const rFOXHeader = <RFOXHeader />

export const RFOX: React.FC = () => {
const stakingAsset = useAppSelector(state => selectAssetById(state, stakingAssetId))

if (!stakingAsset) return null

return (
<Main pb={mainPaddingBottom} headerComponent={rFOXHeader} px={4} isSubPage>
<Stack alignItems='flex-start' spacing={4} mx='auto' direction={direction}>
<Stack spacing={4} flex='1 1 0%' width='full'>
<Overview />
<TxHistory />
<Faq />
</Stack>
<Stack flex={1} width='full' maxWidth={maxWidth} spacing={4}>
<Widget />
</Stack>
export const RFOX: React.FC = () => (
<Main pb={mainPaddingBottom} headerComponent={rFOXHeader} px={4} isSubPage>
<Stack alignItems='flex-start' spacing={4} mx='auto' direction={direction}>
<Stack spacing={4} flex='1 1 0%' width='full'>
<Overview />
<TxHistory />
<Faq />
</Stack>
<Stack flex={1} width='full' maxWidth={maxWidth} spacing={4}>
<Widget />
</Stack>
</Main>
)
}
</Stack>
</Main>
)
1 change: 1 addition & 0 deletions src/pages/RFOX/components/AddressSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const AddressSelection: FC<AddressSelectionProps> = ({

const { stakingAssetId, stakingAssetAccountId } = useRFOXContext()
const { data: currentRuneAddress } = useStakingInfoQuery({
stakingAssetId,
stakingAssetAccountAddress: stakingAssetAccountId
? fromAccountId(stakingAssetAccountId).account
: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
buildAndBroadcast,
createBuildCustomTxInput,
} from 'lib/utils/evm'
import { getRfoxProxyContract } from 'pages/RFOX/helpers'
import { getStakingContract } from 'pages/RFOX/helpers'
import {
selectAccountNumberByAccountId,
selectAssetById,
Expand Down Expand Up @@ -154,7 +154,7 @@ export const ChangeAddressConfirm: React.FC<
adapter,
data: callData,
value: '0',
to: getRfoxProxyContract(confirmedQuote.stakingAssetId),
to: getStakingContract(confirmedQuote.stakingAssetId),
wallet,
})

Expand Down
6 changes: 3 additions & 3 deletions src/pages/RFOX/components/Claim/ClaimConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
buildAndBroadcast,
createBuildCustomTxInput,
} from 'lib/utils/evm'
import { getRfoxProxyContract } from 'pages/RFOX/helpers'
import { getStakingContract } from 'pages/RFOX/helpers'
import {
selectAccountNumberByAccountId,
selectAssetById,
Expand Down Expand Up @@ -133,7 +133,7 @@ export const ClaimConfirm: FC<Pick<ClaimRouteProps, 'headerComponent'> & ClaimCo
adapter,
data: callData,
value: '0',
to: getRfoxProxyContract(stakingAsset.assetId),
to: getStakingContract(stakingAsset.assetId),
wallet,
})

Expand All @@ -156,7 +156,7 @@ export const ClaimConfirm: FC<Pick<ClaimRouteProps, 'headerComponent'> & ClaimCo

const claimFeesQueryInput = useMemo(
() => ({
to: getRfoxProxyContract(claimQuote.stakingAssetId),
to: getStakingContract(claimQuote.stakingAssetId),
from: stakingAssetAccountAddress,
chainId: fromAssetId(claimQuote.stakingAssetId).chainId,
accountNumber: stakingAssetAccountNumber,
Expand Down
61 changes: 61 additions & 0 deletions src/pages/RFOX/components/Overview/EmissionsPool.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { AssetId } from '@shapeshiftoss/caip'
import { thorchainAssetId } from '@shapeshiftoss/caip'
import { bn } from '@shapeshiftoss/chain-adapters'
import { useMemo } from 'react'
import { useTranslate } from 'react-polyglot'
import { fromBaseUnit } from 'lib/math'
import { getStakingContract } from 'pages/RFOX/helpers'
import { useAffiliateRevenueQuery } from 'pages/RFOX/hooks/useAffiliateRevenueQuery'
import { useCurrentEpochMetadataQuery } from 'pages/RFOX/hooks/useCurrentEpochMetadataQuery'
import { selectAssetById, selectMarketDataByAssetIdUserCurrency } from 'state/slices/selectors'
import { useAppSelector } from 'state/store'

import { StatItem } from './StatItem'

type EmissionsPoolProps = {
stakingAssetId: AssetId
}

export const EmissionsPool: React.FC<EmissionsPoolProps> = ({ stakingAssetId }) => {
const translate = useTranslate()

const runeAsset = useAppSelector(state => selectAssetById(state, thorchainAssetId))
const runeAssetMarketData = useAppSelector(state =>
selectMarketDataByAssetIdUserCurrency(state, thorchainAssetId),
)

const stakingAsset = useAppSelector(state => selectAssetById(state, stakingAssetId))

const currentEpochMetadataResult = useCurrentEpochMetadataQuery()

const affiliateRevenueResult = useAffiliateRevenueQuery<string>({
startTimestamp: currentEpochMetadataResult.data?.epochStartTimestamp,
endTimestamp: currentEpochMetadataResult.data?.epochEndTimestamp,
select: (totalRevenue: bigint) => {
return bn(fromBaseUnit(totalRevenue.toString(), runeAsset?.precision ?? 0))
.times(runeAssetMarketData.price)
.toFixed(2)
},
})

const emissionsPoolUserCurrency = useMemo(() => {
if (!affiliateRevenueResult.data) return
if (!currentEpochMetadataResult.data) return

const distributionRate =
currentEpochMetadataResult.data.distributionRateByStakingContract[
getStakingContract(stakingAssetId)
]

return bn(affiliateRevenueResult.data).times(distributionRate).toFixed(2)
}, [affiliateRevenueResult, currentEpochMetadataResult, stakingAssetId])

return (
<StatItem
description={translate('RFOX.emissionsPool', { symbol: stakingAsset?.symbol })}
helperDescription={translate('RFOX.emissionsPoolHelper', { symbol: stakingAsset?.symbol })}
amountUserCurrency={emissionsPoolUserCurrency}
isLoading={affiliateRevenueResult.isLoading || currentEpochMetadataResult.isLoading}
/>
)
}
63 changes: 15 additions & 48 deletions src/pages/RFOX/components/Overview/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,37 @@
import { Card, CardBody, CardHeader, Divider } from '@chakra-ui/react'
import { foxEthLpArbitrumAssetId, fromAccountId } from '@shapeshiftoss/caip'
import { fromAccountId } from '@shapeshiftoss/caip'
import { useMemo } from 'react'
import { selectStakingBalance } from 'pages/RFOX/helpers'
import { RFOX_STAKING_ASSET_IDS } from 'pages/RFOX/constants'
import { useRFOXContext } from 'pages/RFOX/hooks/useRfoxContext'
import { useStakingInfoQuery } from 'pages/RFOX/hooks/useStakingInfoQuery'
import { selectAssetById } from 'state/slices/selectors'
import { useAppSelector } from 'state/store'

import { StakingInfo } from './StakingInfo'
import { Stats } from './Stats'

export const Overview: React.FC = () => {
const { stakingAssetId, stakingAssetAccountId } = useRFOXContext()
const stakingAsset = useAppSelector(state => selectAssetById(state, stakingAssetId))
const { stakingAssetAccountId } = useRFOXContext()

const stakingAssetAccountAddress = useMemo(
() => (stakingAssetAccountId ? fromAccountId(stakingAssetAccountId).account : undefined),
[stakingAssetAccountId],
)

const stakingBalanceCryptoBaseUnitResult = useStakingInfoQuery({
stakingAssetAccountAddress,
stakingAssetId,
select: selectStakingBalance,
})

const lpStakingBalanceCryptoBaseUnitResult = useStakingInfoQuery({
stakingAssetAccountAddress,
stakingAssetId: foxEthLpArbitrumAssetId,
select: selectStakingBalance,
})

const stakingBalanceCryptoBaseUnitLoading = useMemo(() => {
return (
stakingBalanceCryptoBaseUnitResult.isLoading || stakingBalanceCryptoBaseUnitResult.isFetching
)
}, [stakingBalanceCryptoBaseUnitResult])

const lpStakingBalanceCryptoBaseUnitLoading = useMemo(() => {
return (
lpStakingBalanceCryptoBaseUnitResult.isLoading ||
lpStakingBalanceCryptoBaseUnitResult.isFetching
)
}, [lpStakingBalanceCryptoBaseUnitResult])

if (!stakingAsset) return null

return (
<Card>
<CardHeader pt={6} borderBottomWidth={1} borderColor='border.base'>
<StakingInfo
stakingAssetId={stakingAssetId}
stakingAssetAccountAddress={stakingAssetAccountAddress}
stakingBalanceCryptoBaseUnit={stakingBalanceCryptoBaseUnitResult.data}
isStakingBalanceCryptoBaseUnitLoading={stakingBalanceCryptoBaseUnitLoading}
/>
<Divider my={4} mx={-6} width='calc(100% + 42px)' />
<StakingInfo
stakingAssetId={foxEthLpArbitrumAssetId}
stakingAssetAccountAddress={stakingAssetAccountAddress}
stakingBalanceCryptoBaseUnit={lpStakingBalanceCryptoBaseUnitResult.data}
isStakingBalanceCryptoBaseUnitLoading={lpStakingBalanceCryptoBaseUnitLoading}
/>
{RFOX_STAKING_ASSET_IDS.map((stakingAssetId, i) => (
<>
<StakingInfo
stakingAssetId={stakingAssetId}
stakingAssetAccountAddress={stakingAssetAccountAddress}
/>
{i < RFOX_STAKING_ASSET_IDS.length - 1 && (
<Divider my={4} mx={-6} width='calc(100% + 42px)' />
)}
</>
))}
</CardHeader>
<CardBody pb={6}>
<Stats stakingAssetId={stakingAssetId} />
<Stats />
</CardBody>
</Card>
)
Expand Down
Loading

0 comments on commit ab46a12

Please sign in to comment.