This commit is contained in:
Linkie Link 2023-08-22 15:50:12 +02:00
parent ec3273d44f
commit 4fa80a1fd1
No known key found for this signature in database
GPG Key ID: 5318B0F2564D38EA
6 changed files with 44 additions and 7 deletions

View File

@ -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",

View File

@ -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,
)

View File

@ -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({

View File

@ -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) }],
})
*/
}

View File

@ -17,6 +17,7 @@ const CloseVaultPosition = () => {
activeVault,
isLoading: isLoading || !!data || !!error,
})
const isValidVault = vaultConfigs.find((vault) => vault.address === vaultAddress)
const ref = useRef(activeVault)

View File

@ -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<Store>, get: GetState<Store>): 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<Store>, get: GetState<Store>): RedBankSlice
findByDenom(get().marketInfo, asset.denom)?.incentives,
{ denom: asset.denom, amount: depositLiquidity.toString() },
)
const redBankAsset: RedBankAsset = {
...asset,
walletBalance: assetWallet?.amount.toString(),