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 ``` diff --git a/utils/bot/helix_liquidity/helix_liquidity.go b/utils/bot/helix_liquidity/helix_liquidity.go index e9b635c..5c37b73 100644 --- a/utils/bot/helix_liquidity/helix_liquidity.go +++ b/utils/bot/helix_liquidity/helix_liquidity.go @@ -3,9 +3,12 @@ package helix_liquidity import ( "context" "omni-balance/utils/bot" + "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 +36,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 }