Skip to content

Commit 4fa80a1

Browse files
committed
v1.6.3
1 parent ec3273d commit 4fa80a1

File tree

6 files changed

+44
-7
lines changed

6 files changed

+44
-7
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "mars",
33
"homepage": "./",
4-
"version": "1.6.1",
5-
"license": "SEE LICENSE IN LICENSE FILE",
4+
"version": "1.6.3",
65
"private": false,
6+
"license": "SEE LICENSE IN LICENSE FILE",
77
"scripts": {
88
"dev": "next dev -p 3001",
99
"build": "yarn test && next build",

src/functions/fields/getClosePositionActions.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import BigNumber from 'bignumber.js'
2+
import { findByDenom } from 'functions/findByDenom'
23
import { Action, ActionAmount } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
34

45
export const getClosePositionActions = (
56
vault: ActiveVault,
67
primaryToSecondaryRate: number,
78
slippage: number,
9+
whitelistedAssets: Asset[],
810
): Action[] => {
911
const swapMessage: Action[] = []
1012

@@ -18,16 +20,25 @@ export const getClosePositionActions = (
1820
? 'primary'
1921
: 'secondary'
2022

21-
const availableAmountForRepay = vault.position.amounts.lp[borrowType]
23+
const supplyType = borrowType === 'primary' ? 'secondary' : 'primary'
24+
const borrowAsset = findByDenom(whitelistedAssets, vault.denoms[borrowType])
25+
const supplyAsset = findByDenom(whitelistedAssets, vault.denoms[supplyType])
26+
const additionalDecimals = Number(borrowAsset?.decimals ?? 6) - Number(supplyAsset?.decimals ?? 6)
2227

28+
const availableAmountForRepay = vault.position.amounts.lp[borrowType]
2329
if (availableAmountForRepay < borrowAmount) {
2430
const swapTargetAmount = borrowAmount - availableAmountForRepay
2531
const exchangeRate =
2632
borrowType === 'secondary'
2733
? new BigNumber(1).div(primaryToSecondaryRate)
2834
: new BigNumber(primaryToSecondaryRate)
35+
2936
const swapAmount = Math.max(
30-
exchangeRate.times(swapTargetAmount).integerValue(BigNumber.ROUND_CEIL).toNumber(),
37+
exchangeRate
38+
.times(swapTargetAmount)
39+
.shiftedBy(-additionalDecimals)
40+
.integerValue(BigNumber.ROUND_CEIL)
41+
.toNumber(),
3142
10,
3243
)
3344

src/hooks/queries/useClosePosition.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ interface Props {
1212
export const useClosePosition = (props: Props) => {
1313
const getExchangeRate = useStore((s) => s.getExchangeRate)
1414
const slippage = useStore((s) => s.slippage)
15+
const whitelistedAssets = useStore((s) => s.whitelistedAssets)
1516

1617
const actions = useMemo(() => {
1718
if (!props.activeVault) return []
1819
const primaryToSecondaryRate = getExchangeRate(
1920
props.activeVault.denoms.primary,
2021
props.activeVault.denoms.secondary,
2122
)
22-
return getClosePositionActions(props.activeVault, primaryToSecondaryRate, slippage)
23+
return getClosePositionActions(
24+
props.activeVault,
25+
primaryToSecondaryRate,
26+
slippage,
27+
whitelistedAssets,
28+
)
2329
}, [props.activeVault, getExchangeRate, slippage])
2430

2531
const { data: fee } = useEstimateFarmFee({

src/libs/pyth.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export const getPythVaaMessage = (
77
pythContractAddress?: string,
88
sender?: string,
99
): MsgExecuteContract | undefined => {
10+
// Disabled until further notice
11+
return
12+
13+
/*
1014
if (!sender || pythVaa.data.length === 0 || !pythContractAddress || isLedger) return
1115
1216
return new MsgExecuteContract({
@@ -15,4 +19,5 @@ export const getPythVaaMessage = (
1519
msg: { update_price_feeds: { data: pythVaa.data } },
1620
funds: [{ denom: baseCurrencyDenom, amount: String(pythVaa.data.length) }],
1721
})
22+
*/
1823
}

src/pages/farm/vault/[address]/account/[id]/close/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const CloseVaultPosition = () => {
1717
activeVault,
1818
isLoading: isLoading || !!data || !!error,
1919
})
20+
2021
const isValidVault = vaultConfigs.find((vault) => vault.address === vaultAddress)
2122

2223
const ref = useRef(activeVault)

src/store/slices/redBank.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import isEqual from 'lodash.isequal'
77
import moment from 'moment'
88
import { RedBankSlice } from 'store/interfaces/redBank.interface'
99
import { Store } from 'store/interfaces/store.interface'
10+
import colors from 'styles/_assets.module.scss'
1011
import { State } from 'types/enums'
1112
import { GetState } from 'zustand'
1213
import { NamedSet } from 'zustand/middleware'
@@ -31,7 +32,21 @@ const redBankSlice = (set: NamedSet<Store>, get: GetState<Store>): RedBankSlice
3132

3233
const incentiveAssetsInfo = incentives.map((incentive: MarketIncentive) => {
3334
const incentiveAsset = findAssetByDenom(incentive.denom, assets)
34-
if (!incentiveAsset) return
35+
if (!incentiveAsset)
36+
return {
37+
symbol: MARS_SYMBOL,
38+
color: colors.mars,
39+
apy: 0,
40+
}
41+
const startTime = incentive.start_time ?? 0
42+
const duration = incentive.duration ?? 0
43+
const isValid = moment().isBefore(moment(startTime + duration))
44+
if (!isValid)
45+
return {
46+
symbol: incentiveAsset.symbol,
47+
color: incentiveAsset.color,
48+
apy: 0,
49+
}
3550
const anualEmission = Number(incentive.emission_per_second) * SECONDS_IN_YEAR
3651
const anualEmissionVaule = convertToBaseCurrency({
3752
denom: incentive.denom,
@@ -93,7 +108,6 @@ const redBankSlice = (set: NamedSet<Store>, get: GetState<Store>): RedBankSlice
93108
findByDenom(get().marketInfo, asset.denom)?.incentives,
94109
{ denom: asset.denom, amount: depositLiquidity.toString() },
95110
)
96-
97111
const redBankAsset: RedBankAsset = {
98112
...asset,
99113
walletBalance: assetWallet?.amount.toString(),

0 commit comments

Comments
 (0)