🐛 reclaim lent assets for trade (#429)

This commit is contained in:
Bob van der Helm 2023-09-06 10:28:12 +02:00 committed by GitHub
parent b0b957a5b3
commit 5bb87b6d27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 9 deletions

View File

@ -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>
</>
)
}
}

View File

@ -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,
}
}
}

View File

@ -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(
}
},
}
}
}

View File

@ -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>
}
}