mirror of
https://github.com/cerc-io/mars-interface.git
synced 2024-12-22 04:07:44 +00:00
v1.7.0 hotfix
This commit is contained in:
parent
55aaa85e84
commit
433b6dfeac
@ -7,6 +7,7 @@ export const getClosePositionActions = (
|
||||
primaryToSecondaryRate: number,
|
||||
slippage: number,
|
||||
whitelistedAssets: Asset[],
|
||||
isV2: boolean,
|
||||
): Action[] => {
|
||||
const swapMessage: Action[] = []
|
||||
|
||||
@ -56,6 +57,40 @@ export const getClosePositionActions = (
|
||||
})
|
||||
}
|
||||
|
||||
const withdrawLiquidity = isV2
|
||||
? {
|
||||
withdraw_liquidity: {
|
||||
slippage: slippage.toString(),
|
||||
lp_token: {
|
||||
amount: 'account_balance' as ActionAmount,
|
||||
denom: vault.denoms.lpToken,
|
||||
},
|
||||
},
|
||||
}
|
||||
: {
|
||||
withdraw_liquidity: {
|
||||
lp_token: {
|
||||
amount: 'account_balance' as ActionAmount,
|
||||
denom: vault.denoms.lpToken,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const repay = isV2
|
||||
? {
|
||||
repay: {
|
||||
coin: {
|
||||
denom: vault.position.borrowDenom || vault.denoms.secondary,
|
||||
amount: 'account_balance' as ActionAmount,
|
||||
},
|
||||
},
|
||||
}
|
||||
: {
|
||||
repay: {
|
||||
denom: vault.position.borrowDenom || vault.denoms.secondary,
|
||||
amount: 'account_balance' as ActionAmount,
|
||||
},
|
||||
}
|
||||
return [
|
||||
{
|
||||
exit_vault_unlocked: {
|
||||
@ -65,27 +100,10 @@ export const getClosePositionActions = (
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
withdraw_liquidity: {
|
||||
slippage: slippage.toString(),
|
||||
lp_token: {
|
||||
amount: 'account_balance',
|
||||
denom: vault.denoms.lpToken,
|
||||
},
|
||||
},
|
||||
},
|
||||
withdrawLiquidity,
|
||||
...swapMessage,
|
||||
...(Math.max(vault.position.amounts.borrowedPrimary, vault.position.amounts.borrowedSecondary)
|
||||
? [
|
||||
{
|
||||
repay: {
|
||||
coin: {
|
||||
denom: vault.position.borrowDenom || vault.denoms.secondary,
|
||||
amount: 'account_balance' as ActionAmount,
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
? [repay]
|
||||
: []),
|
||||
{ refund_all_coin_balances: {} },
|
||||
]
|
||||
|
@ -2,20 +2,29 @@ import { Action, Coin } from 'types/generated/mars-credit-manager/MarsCreditMana
|
||||
|
||||
import { orderCoinsByDenom } from './orderCoinsByDenom'
|
||||
|
||||
export const getRepayActionsAndFunds = (coin: Coin): [Action[], Coin[]] => {
|
||||
return [
|
||||
[
|
||||
{
|
||||
deposit: coin,
|
||||
},
|
||||
{
|
||||
export const getRepayActionsAndFunds = (coin: Coin, isV2: boolean): [Action[], Coin[]] => {
|
||||
const repay = isV2
|
||||
? {
|
||||
repay: {
|
||||
coin: {
|
||||
denom: coin.denom,
|
||||
amount: { exact: coin.amount },
|
||||
},
|
||||
},
|
||||
}
|
||||
: {
|
||||
repay: {
|
||||
denom: coin.denom,
|
||||
amount: { exact: coin.amount },
|
||||
},
|
||||
}
|
||||
|
||||
return [
|
||||
[
|
||||
{
|
||||
deposit: coin,
|
||||
},
|
||||
repay,
|
||||
],
|
||||
orderCoinsByDenom([coin]),
|
||||
]
|
||||
|
@ -13,6 +13,8 @@ export const useClosePosition = (props: Props) => {
|
||||
const getExchangeRate = useStore((s) => s.getExchangeRate)
|
||||
const slippage = useStore((s) => s.slippage)
|
||||
const whitelistedAssets = useStore((s) => s.whitelistedAssets)
|
||||
const networkConfig = useStore((s) => s.networkConfig)
|
||||
const isV2 = !!networkConfig.contracts?.params
|
||||
|
||||
const actions = useMemo(() => {
|
||||
if (!props.activeVault) return []
|
||||
@ -25,8 +27,9 @@ export const useClosePosition = (props: Props) => {
|
||||
primaryToSecondaryRate,
|
||||
slippage,
|
||||
whitelistedAssets,
|
||||
isV2,
|
||||
)
|
||||
}, [props.activeVault, getExchangeRate, slippage, whitelistedAssets])
|
||||
}, [isV2, props.activeVault, getExchangeRate, slippage, whitelistedAssets])
|
||||
|
||||
const { data: fee } = useEstimateFarmFee({
|
||||
accountId: props.activeVault?.position.accountId,
|
||||
|
@ -6,6 +6,7 @@ import useStore from 'store'
|
||||
import { Action, Coin } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||
|
||||
import { useEstimateFarmFee } from './useEstimateFarmFee'
|
||||
import { useProvideLiquidity } from './useProvideLiquidity'
|
||||
|
||||
interface Props {
|
||||
accountId?: null | string
|
||||
@ -17,6 +18,8 @@ interface Props {
|
||||
}
|
||||
|
||||
export const useEditPosition = (props: Props) => {
|
||||
const networkConfig = useStore((s) => s.networkConfig)
|
||||
const isV2 = !!networkConfig.contracts?.params
|
||||
const convertToBaseCurrency = useStore((s) => s.convertToBaseCurrency)
|
||||
const convertValueToAmount = useStore((s) => s.convertValueToAmount)
|
||||
const slippage = useStore((s) => s.slippage)
|
||||
@ -115,8 +118,13 @@ export const useEditPosition = (props: Props) => {
|
||||
props.position.amounts.borrowedSecondary,
|
||||
])
|
||||
|
||||
const { data: minLpToReceive } = useProvideLiquidity({
|
||||
coins: coinsAfterSwap,
|
||||
vault: props.vault,
|
||||
})
|
||||
|
||||
const { actions, funds } = useMemo<{ actions: Action[]; funds: Coin[] }>(() => {
|
||||
if (props.isReducingPosition) return { actions: [], funds: [] }
|
||||
if ((!isV2 && !minLpToReceive) || props.isReducingPosition) return { actions: [], funds: [] }
|
||||
|
||||
const coins: { supply: Coin[]; borrow?: Coin } = { supply: [], borrow: undefined }
|
||||
|
||||
@ -188,6 +196,26 @@ export const useEditPosition = (props: Props) => {
|
||||
}
|
||||
|
||||
BigNumber.config({ EXPONENTIAL_AT: [-7, 30] })
|
||||
const minimumReceive = new BigNumber(isV2 || !minLpToReceive ? 0 : minLpToReceive)
|
||||
.times(1 - slippage)
|
||||
.integerValue(BigNumber.ROUND_CEIL)
|
||||
.toString()
|
||||
|
||||
const provideLiquidity = isV2
|
||||
? {
|
||||
provide_liquidity: {
|
||||
coins_in: coinsToActionCoins(coinsAfterSwap),
|
||||
lp_token_out: props.vault?.denoms.lpToken || '',
|
||||
slippage: slippage.toString(),
|
||||
},
|
||||
}
|
||||
: {
|
||||
provide_liquidity: {
|
||||
coins_in: coinsToActionCoins(coinsAfterSwap),
|
||||
lp_token_out: props.vault?.denoms.lpToken || '',
|
||||
minimum_receive: minimumReceive,
|
||||
},
|
||||
}
|
||||
|
||||
const actions: Action[] = [
|
||||
...(coins.supply[0]
|
||||
@ -200,13 +228,7 @@ export const useEditPosition = (props: Props) => {
|
||||
...(coins.supply[1] ? [{ deposit: coins.supply[1] }] : []),
|
||||
...(coins.borrow ? [{ borrow: coins.borrow }] : []),
|
||||
...swapMessage,
|
||||
{
|
||||
provide_liquidity: {
|
||||
coins_in: coinsToActionCoins(coinsAfterSwap),
|
||||
lp_token_out: props.vault?.denoms.lpToken || '',
|
||||
slippage: slippage.toString(),
|
||||
},
|
||||
},
|
||||
provideLiquidity,
|
||||
{
|
||||
enter_vault: {
|
||||
coin: {
|
||||
@ -230,6 +252,8 @@ export const useEditPosition = (props: Props) => {
|
||||
coinsAfterSwap,
|
||||
convertToBaseCurrency,
|
||||
convertValueToAmount,
|
||||
minLpToReceive,
|
||||
isV2,
|
||||
slippage,
|
||||
props.isReducingPosition,
|
||||
])
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { getRepayActionsAndFunds, orderCoinsByDenom } from 'functions/fields'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import useStore from 'store'
|
||||
|
||||
import { useEstimateFarmFee } from './useEstimateFarmFee'
|
||||
|
||||
@ -12,6 +13,8 @@ interface Props {
|
||||
|
||||
export const useRepayPosition = (props: Props) => {
|
||||
const [amount, setAmount] = useState(0)
|
||||
const networkConfig = useStore((s) => s.networkConfig)
|
||||
const isV2 = !!networkConfig.contracts?.params
|
||||
|
||||
useEffect(() => {
|
||||
const borrowKey =
|
||||
@ -32,11 +35,14 @@ export const useRepayPosition = (props: Props) => {
|
||||
|
||||
const [actions, funds] = useMemo(() => {
|
||||
if (!amount) return [[], []]
|
||||
return getRepayActionsAndFunds({
|
||||
denom: props.activeVault.position.borrowDenom || props.activeVault.denoms.secondary,
|
||||
amount: amount.toString(),
|
||||
})
|
||||
}, [amount, props.activeVault.denoms.secondary, props.activeVault.position.borrowDenom])
|
||||
return getRepayActionsAndFunds(
|
||||
{
|
||||
denom: props.activeVault.position.borrowDenom || props.activeVault.denoms.secondary,
|
||||
amount: amount.toString(),
|
||||
},
|
||||
isV2,
|
||||
)
|
||||
}, [isV2, amount, props.activeVault.denoms.secondary, props.activeVault.position.borrowDenom])
|
||||
|
||||
const { data: fee } = useEstimateFarmFee({
|
||||
accountId: props.prevPosition.accountId,
|
||||
|
@ -81,7 +81,9 @@ export type Action =
|
||||
}
|
||||
| {
|
||||
repay: {
|
||||
coin: ActionCoin
|
||||
coin?: ActionCoin
|
||||
amount?: ActionAmount
|
||||
denom?: string
|
||||
recipient_account_id?: string | null
|
||||
}
|
||||
}
|
||||
@ -127,13 +129,14 @@ export type Action =
|
||||
provide_liquidity: {
|
||||
coins_in: ActionCoin[]
|
||||
lp_token_out: string
|
||||
slippage: Decimal
|
||||
slippage?: Decimal
|
||||
minimum_receive?: Uint128
|
||||
}
|
||||
}
|
||||
| {
|
||||
withdraw_liquidity: {
|
||||
lp_token: ActionCoin
|
||||
slippage: Decimal
|
||||
slippage?: Decimal
|
||||
}
|
||||
}
|
||||
| {
|
||||
@ -191,7 +194,9 @@ export type CallbackMsg =
|
||||
| {
|
||||
repay: {
|
||||
account_id: string
|
||||
coin: ActionCoin
|
||||
coin?: ActionCoin
|
||||
denom?: string
|
||||
amount?: ActionAmount
|
||||
}
|
||||
}
|
||||
| {
|
||||
@ -299,7 +304,8 @@ export type CallbackMsg =
|
||||
account_id: string
|
||||
coins_in: ActionCoin[]
|
||||
lp_token_out: string
|
||||
slippage: Decimal
|
||||
slippage?: Decimal
|
||||
minimum_receive?: Uint128
|
||||
}
|
||||
}
|
||||
| {
|
||||
@ -309,6 +315,12 @@ export type CallbackMsg =
|
||||
slippage: Decimal
|
||||
}
|
||||
}
|
||||
| {
|
||||
withdraw_liquidity: {
|
||||
account_id: string
|
||||
lp_token: ActionCoin
|
||||
}
|
||||
}
|
||||
| {
|
||||
refund_all_coin_balances: {
|
||||
account_id: string
|
||||
|
Loading…
Reference in New Issue
Block a user