From a5a9512ef18e07e1f8b050231f646476d49b7b94 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 24 Jul 2023 18:23:09 +0800 Subject: [PATCH] autoborrow: check available --- pkg/strategy/autoborrow/strategy.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/strategy/autoborrow/strategy.go b/pkg/strategy/autoborrow/strategy.go index c82e0ec50..dec228fa0 100644 --- a/pkg/strategy/autoborrow/strategy.go +++ b/pkg/strategy/autoborrow/strategy.go @@ -213,8 +213,16 @@ func (s *Strategy) reBalanceDebt(ctx context.Context) { log.Infof("checking repayable balance: %+v", b) - toRepay := fixedpoint.Min(b.Borrowed, b.Available) - toRepay = toRepay.Sub(marginAsset.Low) + toRepay := b.Borrowed + if !b.Available.IsZero() { + toRepay = fixedpoint.Min(b.Borrowed, b.Available) + } else { + log.Errorf("available balance is 0: %#v", b) + } + + if !marginAsset.Low.IsZero() { + toRepay = toRepay.Sub(marginAsset.Low) + } if toRepay.Sign() <= 0 { log.Warnf("%s repay = %f, available = %f, borrowed = %f, can not repay",