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