🐛 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 throttledEstimateExactIn = useMemo(() => asyncThrottle(estimateExactIn, 250), [])
|
||||
const { simulateTrade } = useUpdatedAccount(account)
|
||||
const { simulateTrade, removedLends } = useUpdatedAccount(account)
|
||||
|
||||
const borrowAsset = useMemo(
|
||||
() => borrowAssets.find(byDenom(sellAsset.denom)),
|
||||
@ -165,6 +165,7 @@ export default function SwapForm(props: Props) {
|
||||
return swap({
|
||||
accountId: account?.id || '',
|
||||
coinIn: BNCoin.fromDenomAndBigNumber(sellAsset.denom, sellAssetAmount.integerValue()),
|
||||
reclaim: removedLends[0],
|
||||
borrow: borrowCoin,
|
||||
denomOut: buyAsset.denom,
|
||||
slippage,
|
||||
@ -305,4 +306,4 @@ export default function SwapForm(props: Props) {
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
@ -136,8 +136,9 @@ export function useUpdatedAccount(account?: Account) {
|
||||
|
||||
const { deposit, lend } = getDepositAndLendCoinsToSpend(removeCoin, account)
|
||||
|
||||
removeDeposits([deposit])
|
||||
removeLends([lend])
|
||||
if (!deposit.amount.isZero()) removeDeposits([deposit])
|
||||
if (!lend.amount.isZero()) removeLends([lend])
|
||||
|
||||
if (target === 'deposit') addDeposits([addCoin])
|
||||
if (target === 'lend') addLends([addCoin])
|
||||
|
||||
@ -222,4 +223,4 @@ export function useUpdatedAccount(account?: Account) {
|
||||
simulateVaultDeposit,
|
||||
simulateWithdraw,
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import { formatAmountWithSymbol } from 'utils/formatters'
|
||||
import getTokenOutFromSwapResponse from 'utils/getTokenOutFromSwapResponse'
|
||||
import { BN } from 'utils/helpers'
|
||||
|
||||
|
||||
function generateExecutionMessage(
|
||||
sender: string | undefined = '',
|
||||
contract: string,
|
||||
@ -414,7 +415,7 @@ export default function createBroadcastSlice(
|
||||
|
||||
handleResponseMessages(
|
||||
response,
|
||||
`Successfully deposited ${formatAmountWithSymbol(options.coin.toCoin())}`,
|
||||
`Successfully lent ${formatAmountWithSymbol(options.coin.toCoin())}`,
|
||||
)
|
||||
return !!response.result
|
||||
},
|
||||
@ -443,6 +444,7 @@ export default function createBroadcastSlice(
|
||||
swap: (options: {
|
||||
accountId: string
|
||||
coinIn: BNCoin
|
||||
reclaim?: BNCoin
|
||||
borrow?: BNCoin
|
||||
denomOut: string
|
||||
slippage: number
|
||||
@ -452,6 +454,7 @@ export default function createBroadcastSlice(
|
||||
update_credit_account: {
|
||||
account_id: options.accountId,
|
||||
actions: [
|
||||
...(options.reclaim ? [{ reclaim: options.reclaim.toActionCoin() }] : []),
|
||||
...(options.borrow ? [{ borrow: options.borrow.toCoin() }] : []),
|
||||
{
|
||||
swap_exact_in: {
|
||||
@ -526,4 +529,4 @@ export default function createBroadcastSlice(
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
5
src/types/interfaces/store/broadcast.d.ts
vendored
5
src/types/interfaces/store/broadcast.d.ts
vendored
@ -34,7 +34,8 @@ interface BroadcastSlice {
|
||||
swap: (options: {
|
||||
accountId: string
|
||||
coinIn: BNCoin
|
||||
borrow: BNCoin
|
||||
reclaim?: BNCoin
|
||||
borrow?: BNCoin
|
||||
denomOut: string
|
||||
slippage: number
|
||||
isMax?: boolean
|
||||
@ -52,4 +53,4 @@ interface BroadcastSlice {
|
||||
borrow: BNCoin[]
|
||||
reclaims: ActionCoin[]
|
||||
}) => Promise<boolean>
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user