Skip to content

Commit

Permalink
fix(balance-monitoring): reduce top-up amount to 1% of threshold
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
perrornet committed Aug 26, 2024
1 parent 557f661 commit c1cee3c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion utils/bot/balance_on_chain/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions utils/bot/helix_liquidity/aave_debt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion utils/bot/helix_liquidity/helix_liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c1cee3c

Please sign in to comment.