Skip to content

Commit

Permalink
Remove remaining references to PRE
Browse files Browse the repository at this point in the history
  • Loading branch information
theref committed Oct 19, 2023
1 parent d9b7899 commit b89a4b6
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 146 deletions.
42 changes: 1 addition & 41 deletions src/hooks/useCheckBonusEligibility.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { useEffect } from "react"
import { BigNumber, BigNumberish, Event, constants } from "ethers"
import {
PRE_DEPLOYMENT_BLOCK,
T_STAKING_CONTRACT_DEPLOYMENT_BLOCK,
usePREContract,
useTStakingContract,
} from "../web3/hooks"
import { getAddress, getContractPastEvents } from "../web3/utils"
Expand All @@ -29,7 +27,6 @@ export const useCheckBonusEligibility = () => {
(state: RootState) => state.rewards.stakingBonus
)
const dispatch = useDispatch()
const preContract = usePREContract()
const merkleDropContract = useMerkleDropContract()
const tStakingContract = useTStakingContract()

Expand All @@ -38,7 +35,6 @@ export const useCheckBonusEligibility = () => {
if (
!stakingProviders ||
stakingProviders.length === 0 ||
!preContract ||
!tStakingContract ||
!merkleDropContract ||
(hasFetched && !isFetching)
Expand All @@ -56,11 +52,6 @@ export const useCheckBonusEligibility = () => {
).map((_) => getAddress(_.args?.stakingProvider as string))
)

const operatorConfirmedEvents = await getContractPastEvents(preContract, {
eventName: "OperatorConfirmed",
fromBlock: PRE_DEPLOYMENT_BLOCK,
filterParams: [stakingProviders],
})
const stakedEvents = await getContractPastEvents(tStakingContract, {
eventName: "Staked",
fromBlock: T_STAKING_CONTRACT_DEPLOYMENT_BLOCK,
Expand All @@ -79,10 +70,6 @@ export const useCheckBonusEligibility = () => {
filterParams: [stakingProviders],
})

const stakingProviderToPREConfig = getStakingProviderToPREConfig(
operatorConfirmedEvents
)

const stakingProviderToStakedAmount =
getStakingProviderToStakedInfo(stakedEvents)

Expand Down Expand Up @@ -124,9 +111,7 @@ export const useCheckBonusEligibility = () => {
eligibleStakeAmount,
reward: calculateStakingBonusReward(eligibleStakeAmount),
isRewardClaimed: claimedRewards.has(stakingProviderAddress),
isEligible: Boolean(
hasActiveStake && !hasUnstakeAfterBonusDeadline
),
isEligible: Boolean(hasActiveStake && !hasUnstakeAfterBonusDeadline),
}
}
dispatch(setStakingBonus(stakingProvidersInfo))
Expand Down Expand Up @@ -167,31 +152,6 @@ const getStakingProviderToStakedInfo = (
return stakingProviderToStakedAmount
}

interface StakingProviderToPREConfig {
[address: string]: {
operator: string
operatorConfirmedAtBlock: number
transactionHash: string
}
}

const getStakingProviderToPREConfig = (
events: Event[]
): StakingProviderToPREConfig => {
const stakingProviderToPREConfig: StakingProviderToPREConfig = {}
for (const event of events) {
const stakingProvider = getAddress(event.args?.stakingProvider)

stakingProviderToPREConfig[stakingProvider] = {
operator: event.args?.operator,
operatorConfirmedAtBlock: event.blockNumber,
transactionHash: event.transactionHash,
}
}

return stakingProviderToPREConfig
}

interface StakingProviderToTopUps {
[address: string]: {
amount: BigNumberish
Expand Down
6 changes: 1 addition & 5 deletions src/hooks/useFetchOwnerStakes.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { useCallback } from "react"
import { StakeData } from "../types/staking"
import { setStakes } from "../store/staking"
import { useFetchPreConfigData } from "./useFetchPreConfigData"
import { useThreshold } from "../contexts/ThresholdContext"
import { useAppDispatch } from "./store"

export const useFetchOwnerStakes = () => {
const threshold = useThreshold()
const dispatch = useAppDispatch()
const fetchPreConfigData = useFetchPreConfigData()

return useCallback(
async (address?: string): Promise<StakeData[]> => {
Expand All @@ -19,7 +17,6 @@ export const useFetchOwnerStakes = () => {
const stakes = await threshold.staking.getOwnerStakes(address)

const stakingProviders = stakes.map((stake) => stake.stakingProvider)
const preConfigData = await fetchPreConfigData(stakingProviders)

const _stakes: StakeData[] = stakes.map((stake) => ({
...stake,
Expand All @@ -29,13 +26,12 @@ export const useFetchOwnerStakes = () => {
totalInTStake: stake.totalInTStake.toString(),
possibleKeepTopUpInT: stake.possibleKeepTopUpInT.toString(),
possibleNuTopUpInT: stake.possibleNuTopUpInT.toString(),
preConfig: preConfigData[stake.stakingProvider],
}))

dispatch(setStakes(_stakes))

return _stakes
},
[threshold, fetchPreConfigData, dispatch]
[threshold, dispatch]
)
}
43 changes: 0 additions & 43 deletions src/hooks/useFetchPreConfigData.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/hooks/useFetchTvl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface TvlRawData {
keepStakingTvl: string
tStakingTvl: string
tBTC: string
// TODO: add PRE and NU TVL
}

interface TvlData {
Expand Down
5 changes: 0 additions & 5 deletions src/store/staking/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ const fetchStake = async (
keepInTStake: stake.keepInTStake.toString(),
nuInTStake: stake.nuInTStake.toString(),
totalInTStake: stake.totalInTStake.toString(),
preConfig: {
operator: AddressZero,
isOperatorConfirmed: false,
operatorStartTimestamp: "0",
},
possibleKeepTopUpInT: "0",
possibleNuTopUpInT: "0",
} as StakeData,
Expand Down
6 changes: 0 additions & 6 deletions src/store/staking/stakingSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ export const stakingSlice = createSlice({
newStake.possibleKeepTopUpInT = "0"
newStake.possibleNuTopUpInT = "0"

newStake.preConfig = {
operator: AddressZero,
isOperatorConfirmed: false,
operatorStartTimestamp: "0",
}

state.stakes = [newStake, ...state.stakes]
state.stakedBalance = calculateStakedBalance(state.stakes)
},
Expand Down
18 changes: 2 additions & 16 deletions src/types/staking.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumberish } from "@ethersproject/bignumber"
import { StakeType, TopUpType, UnstakeType } from "../enums"
import { TopUpType, UnstakeType } from "../enums"
import { Stake } from "../threshold-ts/staking"
import { UpdateStateActionPayload } from "./state"

Expand All @@ -26,20 +26,7 @@ export interface UseStakingState {
}
}

export interface PreConfig {
// TODO THEREF
operator: string
isOperatorConfirmed: boolean
operatorStartTimestamp: string
}

export interface PreConfigData {
[stakingProvider: string]: PreConfig
}

export interface StakeData extends Stake<string> {
preConfig: PreConfig
}
export interface StakeData extends Stake<string> {}

export interface ProviderStakedEvent {
stakeType: number
Expand All @@ -59,7 +46,6 @@ export type ProviderStakedActionPayload = ProviderStakedEvent &
| "tStake"
| "amount"
| "totalInTStake"
| "preConfig"
| "possibleKeepTopUpInT"
| "possibleNuTopUpInT"
>
Expand Down
1 change: 0 additions & 1 deletion src/web3/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ export * from "./useKeepAssetPoolContract"
export * from "./useTBTCTokenContract"
export * from "./useTStakingContract"
export * from "./useKeepTokenStakingContract"
export * from "./usePREContract"
export * from "./useClaimMerkleRewardsTransaction"
export * from "./useGetBlock"
28 changes: 0 additions & 28 deletions src/web3/hooks/usePREContract.ts

This file was deleted.

0 comments on commit b89a4b6

Please sign in to comment.