From e3a7cf8e383ce598e5dbb4150484774aa5cc3227 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:24:51 +0200 Subject: [PATCH] feat: make runepool great again post hardfork (#7711) (#7715) --- .env.base | 2 +- .../resolvers/thorchainsavers/index.ts | 29 ++++++++++--------- .../resolvers/thorchainsavers/types.ts | 10 +++++++ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.env.base b/.env.base index 1e7dd210a7e..a9aa6e69ad9 100644 --- a/.env.base +++ b/.env.base @@ -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 diff --git a/src/state/slices/opportunitiesSlice/resolvers/thorchainsavers/index.ts b/src/state/slices/opportunitiesSlice/resolvers/thorchainsavers/index.ts index 62ceab1a2f0..bdf9977f9e4 100644 --- a/src/state/slices/opportunitiesSlice/resolvers/thorchainsavers/index.ts +++ b/src/state/slices/opportunitiesSlice/resolvers/thorchainsavers/index.ts @@ -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' @@ -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' @@ -34,6 +33,7 @@ import type { } from '../types' import type { ThorchainRunepoolInformationResponseSuccess, + ThorchainRunepoolMemberPositionResponse, ThorchainRunepoolReservePositionsResponse, } from './types' import { getMidgardPools, getThorchainSaversPosition } from './utils' @@ -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( - `${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] = { diff --git a/src/state/slices/opportunitiesSlice/resolvers/thorchainsavers/types.ts b/src/state/slices/opportunitiesSlice/resolvers/thorchainsavers/types.ts index 1c6d5274a26..d5799a4f7cd 100644 --- a/src/state/slices/opportunitiesSlice/resolvers/thorchainsavers/types.ts +++ b/src/state/slices/opportunitiesSlice/resolvers/thorchainsavers/types.ts @@ -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 +}