Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor helix liquidity bot to enhance balance checking logic #4

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
55 changes: 39 additions & 16 deletions utils/bot/helix_liquidity/helix_liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down
Loading