🐛 reclaim lent assets for trade (#429)
This commit is contained in:
parent
b0b957a5b3
commit
5bb87b6d27
@ -55,7 +55,7 @@ export default function SwapForm(props: Props) {
|
|||||||
const isAutoLendEnabled = account ? autoLendEnabledAccountIds.includes(account.id) : false
|
const isAutoLendEnabled = account ? autoLendEnabledAccountIds.includes(account.id) : false
|
||||||
|
|
||||||
const throttledEstimateExactIn = useMemo(() => asyncThrottle(estimateExactIn, 250), [])
|
const throttledEstimateExactIn = useMemo(() => asyncThrottle(estimateExactIn, 250), [])
|
||||||
const { simulateTrade } = useUpdatedAccount(account)
|
const { simulateTrade, removedLends } = useUpdatedAccount(account)
|
||||||
|
|
||||||
const borrowAsset = useMemo(
|
const borrowAsset = useMemo(
|
||||||
() => borrowAssets.find(byDenom(sellAsset.denom)),
|
() => borrowAssets.find(byDenom(sellAsset.denom)),
|
||||||
@ -165,6 +165,7 @@ export default function SwapForm(props: Props) {
|
|||||||
return swap({
|
return swap({
|
||||||
accountId: account?.id || '',
|
accountId: account?.id || '',
|
||||||
coinIn: BNCoin.fromDenomAndBigNumber(sellAsset.denom, sellAssetAmount.integerValue()),
|
coinIn: BNCoin.fromDenomAndBigNumber(sellAsset.denom, sellAssetAmount.integerValue()),
|
||||||
|
reclaim: removedLends[0],
|
||||||
borrow: borrowCoin,
|
borrow: borrowCoin,
|
||||||
denomOut: buyAsset.denom,
|
denomOut: buyAsset.denom,
|
||||||
slippage,
|
slippage,
|
||||||
|
@ -136,8 +136,9 @@ export function useUpdatedAccount(account?: Account) {
|
|||||||
|
|
||||||
const { deposit, lend } = getDepositAndLendCoinsToSpend(removeCoin, account)
|
const { deposit, lend } = getDepositAndLendCoinsToSpend(removeCoin, account)
|
||||||
|
|
||||||
removeDeposits([deposit])
|
if (!deposit.amount.isZero()) removeDeposits([deposit])
|
||||||
removeLends([lend])
|
if (!lend.amount.isZero()) removeLends([lend])
|
||||||
|
|
||||||
if (target === 'deposit') addDeposits([addCoin])
|
if (target === 'deposit') addDeposits([addCoin])
|
||||||
if (target === 'lend') addLends([addCoin])
|
if (target === 'lend') addLends([addCoin])
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import { formatAmountWithSymbol } from 'utils/formatters'
|
|||||||
import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse'
|
import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse'
|
||||||
import { BN } from 'utils/helpers'
|
import { BN } from 'utils/helpers'
|
||||||
|
|
||||||
|
|
||||||
function generateExecutionMessage(
|
function generateExecutionMessage(
|
||||||
sender: string | undefined = '',
|
sender: string | undefined = '',
|
||||||
contract: string,
|
contract: string,
|
||||||
@ -414,7 +415,7 @@ export default function createBroadcastSlice(
|
|||||||
|
|
||||||
handleResponseMessages(
|
handleResponseMessages(
|
||||||
response,
|
response,
|
||||||
`Successfully deposited ${formatAmountWithSymbol(options.coin.toCoin())}`,
|
`Successfully lent ${formatAmountWithSymbol(options.coin.toCoin())}`,
|
||||||
)
|
)
|
||||||
return !!response.result
|
return !!response.result
|
||||||
},
|
},
|
||||||
@ -443,6 +444,7 @@ export default function createBroadcastSlice(
|
|||||||
swap: (options: {
|
swap: (options: {
|
||||||
accountId: string
|
accountId: string
|
||||||
coinIn: BNCoin
|
coinIn: BNCoin
|
||||||
|
reclaim?: BNCoin
|
||||||
borrow?: BNCoin
|
borrow?: BNCoin
|
||||||
denomOut: string
|
denomOut: string
|
||||||
slippage: number
|
slippage: number
|
||||||
@ -452,6 +454,7 @@ export default function createBroadcastSlice(
|
|||||||
update_credit_account: {
|
update_credit_account: {
|
||||||
account_id: options.accountId,
|
account_id: options.accountId,
|
||||||
actions: [
|
actions: [
|
||||||
|
...(options.reclaim ? [{ reclaim: options.reclaim.toActionCoin() }] : []),
|
||||||
...(options.borrow ? [{ borrow: options.borrow.toCoin() }] : []),
|
...(options.borrow ? [{ borrow: options.borrow.toCoin() }] : []),
|
||||||
{
|
{
|
||||||
swap_exact_in: {
|
swap_exact_in: {
|
||||||
|
3
src/types/interfaces/store/broadcast.d.ts
vendored
3
src/types/interfaces/store/broadcast.d.ts
vendored
@ -34,7 +34,8 @@ interface BroadcastSlice {
|
|||||||
swap: (options: {
|
swap: (options: {
|
||||||
accountId: string
|
accountId: string
|
||||||
coinIn: BNCoin
|
coinIn: BNCoin
|
||||||
borrow: BNCoin
|
reclaim?: BNCoin
|
||||||
|
borrow?: BNCoin
|
||||||
denomOut: string
|
denomOut: string
|
||||||
slippage: number
|
slippage: number
|
||||||
isMax?: boolean
|
isMax?: boolean
|
||||||
|
Loading…
Reference in New Issue
Block a user