Skip to content

Commit

Permalink
feat: make runepool great again post hardfork (#7711)
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre authored Sep 10, 2024
1 parent ce1ee51 commit f1d24d3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .env.base
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ REACT_APP_FEATURE_CUSTOM_TOKEN_IMPORT=true
REACT_APP_FEATURE_ARBITRUM_BRIDGE_CLAIMS=true
REACT_APP_FEATURE_USDT_APPROVAL_RESET=true
REACT_APP_FEATURE_PORTALS_SWAPPER=true
REACT_APP_FEATURE_RUNEPOOL=false
REACT_APP_FEATURE_RUNEPOOL=true
REACT_APP_FEATURE_MARKETS=false

# absolute URL prefix
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type AssetId, thorchainAssetId } from '@shapeshiftoss/caip'
import { type AssetId, fromAccountId, thorchainAssetId } from '@shapeshiftoss/caip'
import { poolAssetIdToAssetId } from '@shapeshiftoss/swapper/dist/swappers/ThorchainSwapper/utils/poolAssetHelpers/poolAssetHelpers'
import type { ThornodePoolResponse } from '@shapeshiftoss/swapper/src/swappers/ThorchainSwapper/types'
import { isSome, toBaseUnit } from '@shapeshiftoss/utils'
Expand All @@ -12,7 +12,6 @@ import {
RUNEPOOL_MINIMUM_WITHDRAW_BLOCKS,
thorchainBlockTimeMs,
} from 'lib/utils/thorchain/constants'
import type { ThorchainBlock } from 'lib/utils/thorchain/types'
import { selectAssetById } from 'state/slices/assetsSlice/selectors'
import { selectMarketDataByAssetIdUserCurrency } from 'state/slices/marketDataSlice/selectors'
import { selectFeatureFlags } from 'state/slices/preferencesSlice/selectors'
Expand All @@ -34,6 +33,7 @@ import type {
} from '../types'
import type {
ThorchainRunepoolInformationResponseSuccess,
ThorchainRunepoolMemberPositionResponse,
ThorchainRunepoolReservePositionsResponse,
} from './types'
import { getMidgardPools, getThorchainSaversPosition } from './utils'
Expand Down Expand Up @@ -342,21 +342,22 @@ export const thorchainSaversStakingOpportunitiesUserDataResolver = async ({

const maybeMaturity = await (async () => {
if (stakingOpportunityId !== thorchainAssetId) return {}
if (!accountPosition.last_add_height) return { maturity: undefined }

const blockParams = new URLSearchParams({
height: accountPosition.last_add_height?.toString(),
})
try {
const { data: userPosition } = await axios.get<[ThorchainRunepoolMemberPositionResponse]>(
`${getConfig().REACT_APP_MIDGARD_URL}/runepool/${fromAccountId(accountId).account}`,
)

const { data: blockDetails } = await axios.get<ThorchainBlock>(
`${getConfig().REACT_APP_THORCHAIN_NODE_URL}/lcd/thorchain/block?${blockParams}`,
)
const maturity =
userPosition[0].dateLastAdded + thorchainBlockTimeMs * RUNEPOOL_MINIMUM_WITHDRAW_BLOCKS

const maturity =
new Date(blockDetails.header.time).getTime() +
thorchainBlockTimeMs * RUNEPOOL_MINIMUM_WITHDRAW_BLOCKS

return { maturity }
return { maturity }
} catch (error) {
if (axios.isAxiosError(error) && error.response?.status === 404) {
return { maturity: undefined }
}
throw new Error('Error fetching RUNEpool maturity')
}
})()

stakingOpportunitiesUserDataByUserStakingId[userStakingId] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,13 @@ export type ThorchainRunepoolReservePositionsResponse = {
runeWithdrawn: string
}[]
}

export type ThorchainRunepoolMemberPositionResponse = {
runeAddress: string
units: string
runeAdded: string
runeDeposit: string
runeWithdrawn: string
dateFirstAdded: string
dateLastAdded: string
}

0 comments on commit f1d24d3

Please sign in to comment.