fix(swap leftover amounts): use account_balance as sell amount on swaps (#405)
This commit is contained in:
parent
44d5d5e42c
commit
8ec4d61d31
@ -147,6 +147,7 @@ export default function SwapForm(props: Props) {
|
||||
borrow: borrowCoin,
|
||||
denomOut: buyAsset.denom,
|
||||
slippage,
|
||||
isMax: sellAssetAmount.isEqualTo(maxSellAmount),
|
||||
})
|
||||
}, [
|
||||
account?.id,
|
||||
@ -156,6 +157,7 @@ export default function SwapForm(props: Props) {
|
||||
sellAssetAmount,
|
||||
slippage,
|
||||
swap,
|
||||
maxSellAmount,
|
||||
])
|
||||
|
||||
const debouncedUpdateAccount = useMemo(
|
||||
|
@ -15,7 +15,6 @@ import {
|
||||
HealthComputer,
|
||||
} from 'types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types'
|
||||
import { convertAccountToPositions } from 'utils/accounts'
|
||||
import { HEALTH_BUFFER } from 'utils/constants'
|
||||
import {
|
||||
BorrowTarget,
|
||||
compute_health_js,
|
||||
@ -146,8 +145,6 @@ export default function useHealthComputer(account?: Account) {
|
||||
if (!healthComputer) return BN_ZERO
|
||||
try {
|
||||
return BN(max_borrow_estimate_js(healthComputer, denom, target))
|
||||
.times(1 - HEALTH_BUFFER)
|
||||
.integerValue()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return BN_ZERO
|
||||
@ -161,8 +158,6 @@ export default function useHealthComputer(account?: Account) {
|
||||
if (!healthComputer) return BN_ZERO
|
||||
try {
|
||||
return BN(max_withdraw_estimate_js(healthComputer, denom))
|
||||
.times(1 - HEALTH_BUFFER)
|
||||
.integerValue()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return BN_ZERO
|
||||
@ -176,8 +171,6 @@ export default function useHealthComputer(account?: Account) {
|
||||
if (!healthComputer) return BN_ZERO
|
||||
try {
|
||||
return BN(max_swap_estimate_js(healthComputer, from, to, kind))
|
||||
.times(1 - HEALTH_BUFFER)
|
||||
.integerValue()
|
||||
} catch {
|
||||
return BN_ZERO
|
||||
}
|
||||
|
@ -430,6 +430,7 @@ export default function createBroadcastSlice(
|
||||
borrow?: BNCoin
|
||||
denomOut: string
|
||||
slippage: number
|
||||
isMax?: boolean
|
||||
}) => {
|
||||
const msg: CreditManagerExecuteMsg = {
|
||||
update_credit_account: {
|
||||
@ -438,7 +439,7 @@ export default function createBroadcastSlice(
|
||||
...(options.borrow ? [{ borrow: options.borrow.toCoin() }] : []),
|
||||
{
|
||||
swap_exact_in: {
|
||||
coin_in: options.coinIn.toActionCoin(),
|
||||
coin_in: options.coinIn.toActionCoin(options.isMax),
|
||||
denom_out: options.denomOut,
|
||||
slippage: options.slippage.toString(),
|
||||
},
|
||||
|
1
src/types/interfaces/store/broadcast.d.ts
vendored
1
src/types/interfaces/store/broadcast.d.ts
vendored
@ -32,6 +32,7 @@ interface BroadcastSlice {
|
||||
borrow: BNCoin
|
||||
denomOut: string
|
||||
slippage: number
|
||||
isMax?: boolean
|
||||
}) => ExecutableTx
|
||||
toast: { message: string; isError?: boolean; title?: string } | null
|
||||
unlock: (options: {
|
||||
|
@ -9,5 +9,3 @@ export const defaultFee: StdFee = {
|
||||
}
|
||||
|
||||
export const SECONDS_IN_A_YEAR = 31540000
|
||||
|
||||
export const HEALTH_BUFFER = 0.01
|
||||
|
Loading…
Reference in New Issue
Block a user