From c1cee3c7e450f2c84fd0da48a448e9e8760006fb Mon Sep 17 00:00:00 2001 From: perror <23651751+perrornet@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:24:56 +0800 Subject: [PATCH] fix(balance-monitoring): reduce top-up amount to 1% of threshold Change the top-up logic for both BalanceOnChain and HelixLiquidity modules to increase the balance by only 1% of the threshold value, ensuring more precise management of funds and preventing overtopping accounts with unnecessary large amounts. The adjustment was previously set to 30% of the threshold. Additionally, an erroneous debt calculation test case in Aave has been corrected to reflect the correct balance, ensuring accurate test results. --- utils/bot/balance_on_chain/monitor.go | 2 +- utils/bot/helix_liquidity/aave_debt_test.go | 17 +++++++++++++++++ utils/bot/helix_liquidity/helix_liquidity.go | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/utils/bot/balance_on_chain/monitor.go b/utils/bot/balance_on_chain/monitor.go index c62d880..123b1b2 100644 --- a/utils/bot/balance_on_chain/monitor.go +++ b/utils/bot/balance_on_chain/monitor.go @@ -45,7 +45,7 @@ func (b BalanceOnChain) Check(ctx context.Context, args bot.Params) ([]bot.Task, } amount := config.GetTokenPurchaseAmount(info.Wallet.GetAddress().Hex(), info.TokenName, info.Chain) if balance.Add(amount).LessThanOrEqual(threshold) { - newAmount := threshold.Add(threshold.Mul(decimal.RequireFromString("0.3"))) + newAmount := threshold.Add(threshold.Mul(decimal.RequireFromString("0.01"))) log.Infof("The %s current balance is %s, amount in config is %s, balance(%s) + amount(%s) <= threshold(%s), so set amount to %s", info.Wallet.GetAddress(), balance, amount, balance, amount, threshold, newAmount) amount = newAmount diff --git a/utils/bot/helix_liquidity/aave_debt_test.go b/utils/bot/helix_liquidity/aave_debt_test.go index f06c456..7fcb431 100644 --- a/utils/bot/helix_liquidity/aave_debt_test.go +++ b/utils/bot/helix_liquidity/aave_debt_test.go @@ -41,4 +41,21 @@ func TestAave_BalanceOf(t *testing.T) { }) assert.NoError(t, err) assert.Equal(t, balance.String(), strconv.Itoa(1000-900)) + + mockClient = chain_mocks.NewMockClient(t) + mockClient.On("CallContract", context.TODO(), ethereum.CallMsg{To: &token, Data: input}, mock.Anything).Return( + chains.EthToWei(decimal.RequireFromString("0"), 6).Bytes(), nil, + ) + + mockClient.On("CallContract", context.TODO(), ethereum.CallMsg{To: &vtoken, Data: input}, mock.Anything).Return( + chains.EthToWei(decimal.RequireFromString("100"), 6).Bytes(), nil, + ) + balance, err = new(Aave).BalanceOf(context.TODO(), DebtParams{ + Address: constant.ZeroAddress, + Token: "USDC", + Client: mockClient, + Chain: constant.ArbitrumSepolia, + }) + assert.NoError(t, err) + assert.Equal(t, balance.String(), strconv.Itoa(-100)) } diff --git a/utils/bot/helix_liquidity/helix_liquidity.go b/utils/bot/helix_liquidity/helix_liquidity.go index 7726e25..071da44 100644 --- a/utils/bot/helix_liquidity/helix_liquidity.go +++ b/utils/bot/helix_liquidity/helix_liquidity.go @@ -70,7 +70,7 @@ func (h HelixLiquidity) Check(ctx context.Context, args bot.Params) ([]bot.Task, } if total.Add(purchaseAmount).LessThanOrEqual(threshold) { - newAmount := threshold.Add(threshold.Mul(decimal.RequireFromString("0.3"))) + newAmount := threshold.Add(threshold.Mul(decimal.RequireFromString("0.01"))) log.Infof("The %s %s on %s current balance is %s, amount in config is %s, balance(%s) + amount(%s) <= threshold(%s), so set amount to %s", args.Info.Wallet.GetAddress(), args.Info.TokenName, args.Info.Chain, total, purchaseAmount, total, purchaseAmount, threshold, newAmount) purchaseAmount = newAmount