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", "name": "mars",
"homepage": "./", "homepage": "./",
"version": "1.6.1", "version": "1.6.3",
"license": "SEE LICENSE IN LICENSE FILE",
"private": false, "private": false,
"license": "SEE LICENSE IN LICENSE FILE",
"scripts": { "scripts": {
"dev": "next dev -p 3001", "dev": "next dev -p 3001",
"build": "yarn test && next build", "build": "yarn test && next build",

View File

@ -1,10 +1,12 @@
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
import { findByDenom } from 'functions/findByDenom'
import { Action, ActionAmount } from 'types/generated/mars-credit-manager/MarsCreditManager.types' import { Action, ActionAmount } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
export const getClosePositionActions = ( export const getClosePositionActions = (
vault: ActiveVault, vault: ActiveVault,
primaryToSecondaryRate: number, primaryToSecondaryRate: number,
slippage: number, slippage: number,
whitelistedAssets: Asset[],
): Action[] => { ): Action[] => {
const swapMessage: Action[] = [] const swapMessage: Action[] = []
@ -18,16 +20,25 @@ export const getClosePositionActions = (
? 'primary' ? 'primary'
: 'secondary' : '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) { if (availableAmountForRepay < borrowAmount) {
const swapTargetAmount = borrowAmount - availableAmountForRepay const swapTargetAmount = borrowAmount - availableAmountForRepay
const exchangeRate = const exchangeRate =
borrowType === 'secondary' borrowType === 'secondary'
? new BigNumber(1).div(primaryToSecondaryRate) ? new BigNumber(1).div(primaryToSecondaryRate)
: new BigNumber(primaryToSecondaryRate) : new BigNumber(primaryToSecondaryRate)
const swapAmount = Math.max( const swapAmount = Math.max(
exchangeRate.times(swapTargetAmount).integerValue(BigNumber.ROUND_CEIL).toNumber(), exchangeRate
.times(swapTargetAmount)
.shiftedBy(-additionalDecimals)
.integerValue(BigNumber.ROUND_CEIL)
.toNumber(),
10, 10,
) )

View File

@ -12,6 +12,7 @@ interface Props {
export const useClosePosition = (props: Props) => { export const useClosePosition = (props: Props) => {
const getExchangeRate = useStore((s) => s.getExchangeRate) const getExchangeRate = useStore((s) => s.getExchangeRate)
const slippage = useStore((s) => s.slippage) const slippage = useStore((s) => s.slippage)
const whitelistedAssets = useStore((s) => s.whitelistedAssets)
const actions = useMemo(() => { const actions = useMemo(() => {
if (!props.activeVault) return [] if (!props.activeVault) return []
@ -19,7 +20,12 @@ export const useClosePosition = (props: Props) => {
props.activeVault.denoms.primary, props.activeVault.denoms.primary,
props.activeVault.denoms.secondary, props.activeVault.denoms.secondary,
) )
return getClosePositionActions(props.activeVault, primaryToSecondaryRate, slippage) return getClosePositionActions(
props.activeVault,
primaryToSecondaryRate,
slippage,
whitelistedAssets,
)
}, [props.activeVault, getExchangeRate, slippage]) }, [props.activeVault, getExchangeRate, slippage])
const { data: fee } = useEstimateFarmFee({ const { data: fee } = useEstimateFarmFee({

View File

@ -7,6 +7,10 @@ export const getPythVaaMessage = (
pythContractAddress?: string, pythContractAddress?: string,
sender?: string, sender?: string,
): MsgExecuteContract | undefined => { ): MsgExecuteContract | undefined => {
// Disabled until further notice
return
/*
if (!sender || pythVaa.data.length === 0 || !pythContractAddress || isLedger) return if (!sender || pythVaa.data.length === 0 || !pythContractAddress || isLedger) return
return new MsgExecuteContract({ return new MsgExecuteContract({
@ -15,4 +19,5 @@ export const getPythVaaMessage = (
msg: { update_price_feeds: { data: pythVaa.data } }, msg: { update_price_feeds: { data: pythVaa.data } },
funds: [{ denom: baseCurrencyDenom, amount: String(pythVaa.data.length) }], funds: [{ denom: baseCurrencyDenom, amount: String(pythVaa.data.length) }],
}) })
*/
} }

View File

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

View File

@ -7,6 +7,7 @@ import isEqual from 'lodash.isequal'
import moment from 'moment' import moment from 'moment'
import { RedBankSlice } from 'store/interfaces/redBank.interface' import { RedBankSlice } from 'store/interfaces/redBank.interface'
import { Store } from 'store/interfaces/store.interface' import { Store } from 'store/interfaces/store.interface'
import colors from 'styles/_assets.module.scss'
import { State } from 'types/enums' import { State } from 'types/enums'
import { GetState } from 'zustand' import { GetState } from 'zustand'
import { NamedSet } from 'zustand/middleware' 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 incentiveAssetsInfo = incentives.map((incentive: MarketIncentive) => {
const incentiveAsset = findAssetByDenom(incentive.denom, assets) 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 anualEmission = Number(incentive.emission_per_second) * SECONDS_IN_YEAR
const anualEmissionVaule = convertToBaseCurrency({ const anualEmissionVaule = convertToBaseCurrency({
denom: incentive.denom, denom: incentive.denom,
@ -93,7 +108,6 @@ const redBankSlice = (set: NamedSet<Store>, get: GetState<Store>): RedBankSlice
findByDenom(get().marketInfo, asset.denom)?.incentives, findByDenom(get().marketInfo, asset.denom)?.incentives,
{ denom: asset.denom, amount: depositLiquidity.toString() }, { denom: asset.denom, amount: depositLiquidity.toString() },
) )
const redBankAsset: RedBankAsset = { const redBankAsset: RedBankAsset = {
...asset, ...asset,
walletBalance: assetWallet?.amount.toString(), walletBalance: assetWallet?.amount.toString(),