From 967c7d467ee40cdd9ec9f9dfe072d7610a2a9283 Mon Sep 17 00:00:00 2001 From: perror <23651751+perrornet@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:15:43 +0800 Subject: [PATCH 1/3] Refactor helix liquidity bot to enhance balance checking logic --- utils/bot/helix_liquidity/helix_liquidity.go | 56 ++++++++++++++------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/utils/bot/helix_liquidity/helix_liquidity.go b/utils/bot/helix_liquidity/helix_liquidity.go index e9b635c..7eacf60 100644 --- a/utils/bot/helix_liquidity/helix_liquidity.go +++ b/utils/bot/helix_liquidity/helix_liquidity.go @@ -3,9 +3,13 @@ package helix_liquidity import ( "context" "omni-balance/utils/bot" + "omni-balance/utils/bot/balance_on_chain" + "omni-balance/utils/chains" "omni-balance/utils/provider" "omni-balance/utils/provider/bridge/helix_liquidity_claim" + "github.com/ethereum/go-ethereum/common" + "github.com/shopspring/decimal" "github.com/sirupsen/logrus" ) @@ -33,23 +37,43 @@ func (h HelixLiquidity) Check(ctx context.Context, args bot.Params) ([]bot.Task, if err != nil { return nil, bot.Parallel, err } - var result []bot.Task - for index, v := range records { - result = append(result, bot.Task{ - Remark: v.Channel, - Wallet: args.Info.Wallet.GetAddress().Hex(), - CurrentChainName: v.FromChain, - TokenInName: v.TokenName, - TokenOutName: v.TokenName, - TokenInChainName: v.FromChain, - TokenOutChainName: v.ToChain, - Amount: v.TotalAmount, - Status: provider.TxStatusPending, - ProviderType: claim.Type(), - ProviderName: claim.Name(), - Order: records[index], - }) + token := args.Conf.GetTokenInfoOnChain(args.Info.TokenName, args.Info.Chain) + client, err := chains.NewTryClient(ctx, args.Conf.GetChainConfig(args.Info.Chain).RpcEndpoints) + if err != nil { + return nil, bot.Parallel, err + } + defer client.Close() + balance, err := args.Info.Wallet.GetExternalBalance(ctx, common.HexToAddress(token.ContractAddress), token.Decimals, client) + if err != nil { + return nil, bot.Parallel, err + } + threshold := args.Conf.GetTokenThreshold(args.Info.Wallet.GetAddress().Hex(), args.Info.TokenName, args.Info.Chain) + purchaseAmount := args.Conf.GetTokenPurchaseAmount(args.Info.Wallet.GetAddress().Hex(), args.Info.TokenName, args.Info.Chain) + var ( + result []bot.Task + total = balance + ) + for _, v := range records { + total = total.Add(v.TotalAmount) } + if !total.LessThanOrEqual(threshold) { + return nil, bot.Parallel, nil + } + + if total.Add(purchaseAmount).LessThanOrEqual(threshold) { + newAmount := threshold.Add(threshold.Mul(decimal.RequireFromString("0.3"))) + log.Infof("The %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(), total, purchaseAmount, balance, purchaseAmount, threshold, newAmount) + purchaseAmount = newAmount + } + + result = append(result, bot.Task{ + Wallet: args.Info.Wallet.GetAddress().Hex(), + TokenOutName: args.Info.TokenName, + TokenOutChainName: args.Info.Chain, + Amount: purchaseAmount, + Status: provider.TxStatusPending, + }) return result, bot.Queue, nil } From 6fccf9338e04cda746b74d78b98f7b9241cd8053 Mon Sep 17 00:00:00 2001 From: perror <23651751+perrornet@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:17:50 +0800 Subject: [PATCH 2/3] Fix "imported and not used" error --- utils/bot/helix_liquidity/helix_liquidity.go | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/bot/helix_liquidity/helix_liquidity.go b/utils/bot/helix_liquidity/helix_liquidity.go index 7eacf60..5c37b73 100644 --- a/utils/bot/helix_liquidity/helix_liquidity.go +++ b/utils/bot/helix_liquidity/helix_liquidity.go @@ -3,7 +3,6 @@ package helix_liquidity import ( "context" "omni-balance/utils/bot" - "omni-balance/utils/bot/balance_on_chain" "omni-balance/utils/chains" "omni-balance/utils/provider" "omni-balance/utils/provider/bridge/helix_liquidity_claim" From fe4f1a71558096c18de0f6266a1f271bdf04efdd Mon Sep 17 00:00:00 2001 From: perror <23651751+perrornet@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:20:56 +0800 Subject: [PATCH 3/3] Fix README.md file path error --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 268db78..3f17ce8 100644 --- a/README.md +++ b/README.md @@ -93,11 +93,11 @@ GLOBAL OPTIONS: ##### Example -* [global_config.yaml](./example/global_config.yaml): A generic example configuration for global settings. -* [gate_liquidity_config.yaml](./example/gate_liquidity_config.yaml): An example configuration for providing liquidity to the Gate.io exchange. -* [general_config.yaml](./example/general_config.yaml): An example configuration for standard addresses swapping liquidity between two chains. -* [helix_liquidity_config.yaml](./example/helix_liquidity_config.yaml): An example configuration that, when checking address balances, includes both on-chain balances and unclaimed HelixBridge balances for evaluation. -* [operator_safe_config.yaml](./example/operator_safe_config.yaml): An example configuration for scenarios where the operator address utilizes a multi-signature setup. +* [global_config.yaml](./example/configs/global_config.yaml): A generic example configuration for global settings. +* [gate_liquidity_config.yaml](./example/configs/gate_liquidity_config.yaml): An example configuration for providing liquidity to the Gate.io exchange. +* [general_config.yaml](./example/configs/general_config.yaml): An example configuration for standard addresses swapping liquidity between two chains. +* [helix_liquidity_config.yaml](./example/configs/helix_liquidity_config.yaml): An example configuration that, when checking address balances, includes both on-chain balances and unclaimed HelixBridge balances for evaluation. +* [operator_safe_config.yaml](./example/configs/operator_safe_config.yaml): An example configuration for scenarios where the operator address utilizes a multi-signature setup. ##### Configuration Reference ```