From 4fa80a1fd18fd23f2b28e5194a2b15ea4c66a6fc Mon Sep 17 00:00:00 2001 From: Linkie Link Date: Tue, 22 Aug 2023 15:50:12 +0200 Subject: [PATCH] v1.6.3 --- package.json | 4 ++-- .../fields/getClosePositionActions.ts | 15 +++++++++++++-- src/hooks/queries/useClosePosition.tsx | 8 +++++++- src/libs/pyth.ts | 5 +++++ .../[address]/account/[id]/close/index.tsx | 1 + src/store/slices/redBank.ts | 18 ++++++++++++++++-- 6 files changed, 44 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index bc70dbe..1f480c2 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "mars", "homepage": "./", - "version": "1.6.1", - "license": "SEE LICENSE IN LICENSE FILE", + "version": "1.6.3", "private": false, + "license": "SEE LICENSE IN LICENSE FILE", "scripts": { "dev": "next dev -p 3001", "build": "yarn test && next build", diff --git a/src/functions/fields/getClosePositionActions.ts b/src/functions/fields/getClosePositionActions.ts index cd0c7ea..c3ba68f 100644 --- a/src/functions/fields/getClosePositionActions.ts +++ b/src/functions/fields/getClosePositionActions.ts @@ -1,10 +1,12 @@ import BigNumber from 'bignumber.js' +import { findByDenom } from 'functions/findByDenom' import { Action, ActionAmount } from 'types/generated/mars-credit-manager/MarsCreditManager.types' export const getClosePositionActions = ( vault: ActiveVault, primaryToSecondaryRate: number, slippage: number, + whitelistedAssets: Asset[], ): Action[] => { const swapMessage: Action[] = [] @@ -18,16 +20,25 @@ export const getClosePositionActions = ( ? 'primary' : 'secondary' - const availableAmountForRepay = vault.position.amounts.lp[borrowType] + const supplyType = borrowType === 'primary' ? 'secondary' : 'primary' + const borrowAsset = findByDenom(whitelistedAssets, vault.denoms[borrowType]) + const supplyAsset = findByDenom(whitelistedAssets, vault.denoms[supplyType]) + const additionalDecimals = Number(borrowAsset?.decimals ?? 6) - Number(supplyAsset?.decimals ?? 6) + const availableAmountForRepay = vault.position.amounts.lp[borrowType] if (availableAmountForRepay < borrowAmount) { const swapTargetAmount = borrowAmount - availableAmountForRepay const exchangeRate = borrowType === 'secondary' ? new BigNumber(1).div(primaryToSecondaryRate) : new BigNumber(primaryToSecondaryRate) + const swapAmount = Math.max( - exchangeRate.times(swapTargetAmount).integerValue(BigNumber.ROUND_CEIL).toNumber(), + exchangeRate + .times(swapTargetAmount) + .shiftedBy(-additionalDecimals) + .integerValue(BigNumber.ROUND_CEIL) + .toNumber(), 10, ) diff --git a/src/hooks/queries/useClosePosition.tsx b/src/hooks/queries/useClosePosition.tsx index 4ad1661..9b74618 100644 --- a/src/hooks/queries/useClosePosition.tsx +++ b/src/hooks/queries/useClosePosition.tsx @@ -12,6 +12,7 @@ interface Props { export const useClosePosition = (props: Props) => { const getExchangeRate = useStore((s) => s.getExchangeRate) const slippage = useStore((s) => s.slippage) + const whitelistedAssets = useStore((s) => s.whitelistedAssets) const actions = useMemo(() => { if (!props.activeVault) return [] @@ -19,7 +20,12 @@ export const useClosePosition = (props: Props) => { props.activeVault.denoms.primary, props.activeVault.denoms.secondary, ) - return getClosePositionActions(props.activeVault, primaryToSecondaryRate, slippage) + return getClosePositionActions( + props.activeVault, + primaryToSecondaryRate, + slippage, + whitelistedAssets, + ) }, [props.activeVault, getExchangeRate, slippage]) const { data: fee } = useEstimateFarmFee({ diff --git a/src/libs/pyth.ts b/src/libs/pyth.ts index 0f06283..f29c02e 100644 --- a/src/libs/pyth.ts +++ b/src/libs/pyth.ts @@ -7,6 +7,10 @@ export const getPythVaaMessage = ( pythContractAddress?: string, sender?: string, ): MsgExecuteContract | undefined => { + // Disabled until further notice + return + + /* if (!sender || pythVaa.data.length === 0 || !pythContractAddress || isLedger) return return new MsgExecuteContract({ @@ -15,4 +19,5 @@ export const getPythVaaMessage = ( msg: { update_price_feeds: { data: pythVaa.data } }, funds: [{ denom: baseCurrencyDenom, amount: String(pythVaa.data.length) }], }) + */ } diff --git a/src/pages/farm/vault/[address]/account/[id]/close/index.tsx b/src/pages/farm/vault/[address]/account/[id]/close/index.tsx index 3aee63e..05055d7 100644 --- a/src/pages/farm/vault/[address]/account/[id]/close/index.tsx +++ b/src/pages/farm/vault/[address]/account/[id]/close/index.tsx @@ -17,6 +17,7 @@ const CloseVaultPosition = () => { activeVault, isLoading: isLoading || !!data || !!error, }) + const isValidVault = vaultConfigs.find((vault) => vault.address === vaultAddress) const ref = useRef(activeVault) diff --git a/src/store/slices/redBank.ts b/src/store/slices/redBank.ts index 2a2e5e9..a7e1ce2 100644 --- a/src/store/slices/redBank.ts +++ b/src/store/slices/redBank.ts @@ -7,6 +7,7 @@ import isEqual from 'lodash.isequal' import moment from 'moment' import { RedBankSlice } from 'store/interfaces/redBank.interface' import { Store } from 'store/interfaces/store.interface' +import colors from 'styles/_assets.module.scss' import { State } from 'types/enums' import { GetState } from 'zustand' import { NamedSet } from 'zustand/middleware' @@ -31,7 +32,21 @@ const redBankSlice = (set: NamedSet, get: GetState): RedBankSlice const incentiveAssetsInfo = incentives.map((incentive: MarketIncentive) => { const incentiveAsset = findAssetByDenom(incentive.denom, assets) - if (!incentiveAsset) return + if (!incentiveAsset) + return { + symbol: MARS_SYMBOL, + color: colors.mars, + apy: 0, + } + const startTime = incentive.start_time ?? 0 + const duration = incentive.duration ?? 0 + const isValid = moment().isBefore(moment(startTime + duration)) + if (!isValid) + return { + symbol: incentiveAsset.symbol, + color: incentiveAsset.color, + apy: 0, + } const anualEmission = Number(incentive.emission_per_second) * SECONDS_IN_YEAR const anualEmissionVaule = convertToBaseCurrency({ denom: incentive.denom, @@ -93,7 +108,6 @@ const redBankSlice = (set: NamedSet, get: GetState): RedBankSlice findByDenom(get().marketInfo, asset.denom)?.incentives, { denom: asset.denom, amount: depositLiquidity.toString() }, ) - const redBankAsset: RedBankAsset = { ...asset, walletBalance: assetWallet?.amount.toString(),