Skip to content

Commit

Permalink
v1.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
linkielink committed Aug 22, 2023
1 parent ec3273d commit 4fa80a1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 13 additions & 2 deletions src/functions/fields/getClosePositionActions.ts
Original file line number Diff line number Diff line change
@@ -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[] = []

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

Expand Down
8 changes: 7 additions & 1 deletion src/hooks/queries/useClosePosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ 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 []
const primaryToSecondaryRate = getExchangeRate(
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({
Expand Down
5 changes: 5 additions & 0 deletions src/libs/pyth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -15,4 +19,5 @@ export const getPythVaaMessage = (
msg: { update_price_feeds: { data: pythVaa.data } },
funds: [{ denom: baseCurrencyDenom, amount: String(pythVaa.data.length) }],
})
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const CloseVaultPosition = () => {
activeVault,
isLoading: isLoading || !!data || !!error,
})

const isValidVault = vaultConfigs.find((vault) => vault.address === vaultAddress)

const ref = useRef(activeVault)
Expand Down
18 changes: 16 additions & 2 deletions src/store/slices/redBank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 4fa80a1

Please sign in to comment.