Skip to content

Commit 6d7c3ea

Browse files
committed
Remove Li.fi bridge and optimize quote process
1 parent 497c448 commit 6d7c3ea

File tree

22 files changed

+53
-859
lines changed

22 files changed

+53
-859
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Omni Balance is an intelligent liquidity management tool designed to achieve sea
2525
| [Darwinia Bridge](https://bridge.darwinia.network/) | ||
2626
| [OKX web3](https://www.okx.com/zh-hans/web3/build/docs/waas/dex-crosschain-swap) |||
2727
| [Router Nitro](https://app.routernitro.com/swap) |||
28-
| [Li.FI](https://li.fi/) |||
2928

3029

3130
### Installation

cmd/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"omni-balance/utils/provider"
1818
_ "omni-balance/utils/provider/bridge/darwinia"
1919
_ "omni-balance/utils/provider/bridge/helix_liquidity_claim"
20-
_ "omni-balance/utils/provider/bridge/li"
2120
_ "omni-balance/utils/provider/bridge/okx"
2221
_ "omni-balance/utils/provider/bridge/routernitro"
2322
_ "omni-balance/utils/provider/cex/gate"

internal/daemons/bot/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func createOrder(ctx context.Context, tasks []bot.Task, processType bot.ProcessT
6868
TaskId: taskId,
6969
ProcessType: string(processType),
7070
Remark: v.Remark,
71+
CurrentBalance: v.CurrentBalance,
7172
}
7273

7374
if err = txn.Create(o).Error; err != nil {

internal/daemons/market/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ func init() {
1111
Description: "Look for tasks in the database that are not being processed and process them.",
1212
TaskFunc: Run,
1313
DefaultInterval: time.Minute * 3,
14-
RunOnStart: true,
14+
RunOnStart: false,
1515
})
1616
}

internal/daemons/market/util.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func getBestProvider(ctx context.Context, order models.Order, conf configs.Confi
9696
if !ok || len(tokenInCosts) == 0 {
9797
continue
9898
}
99-
log.Debugf("provider %s can use %s on %s. The tokenInCosts is %+v",
99+
log.Infof("provider %s can use %s on %s. The tokenInCosts is %+v",
100100
p.Name(), order.TokenOutName, order.TargetChainName, tokenInCosts)
101101
canUseProviders = append(canUseProviders, canUseProvider{
102102
provider: p,
@@ -131,16 +131,27 @@ func getBestProvider(ctx context.Context, order models.Order, conf configs.Confi
131131
}
132132
tokenName2Price, err := models.FindTokenPrice(db.DB(), tokenNames)
133133
if err != nil {
134-
log.Warnf("find token price error: %s", err.Error())
134+
log.Warnf("find %+v token price error: %s", tokenNames, err.Error())
135135
continue
136136
}
137137
// if token out is RING and provider is darwinia, then use darwinia as the provider
138138
if order.TokenOutName == "RING" && canUseProvider.provider.Name() == new(darwinia.Bridge).Name() {
139139
return canUseProvider.provider, nil
140140
}
141+
if len(tokenName2Price) == 0 {
142+
log.Warnf("not found %+v price, set to 0", tokenNames)
143+
minPrice = decimal.Zero
144+
providerObj = canUseProvider.provider
145+
continue
146+
}
141147

142148
for name, v := range tokenName2Price {
143149
log.Debugf("token %s price %s on %s", name, v.String(), canUseProvider.provider.Name())
150+
if v.LessThanOrEqual(decimal.Zero) {
151+
log.Warnf("token %s price %s is less than or equal to zero, set to 1",
152+
name, v.String())
153+
v = decimal.RequireFromString("1")
154+
}
144155
price := v.Mul(tokenInCostsMap[name])
145156
if price.IsZero() {
146157
continue
@@ -173,12 +184,12 @@ func providerSupportsOrder(ctx context.Context, p provider.Provider, order model
173184
TargetChain: order.TargetChainName,
174185
Amount: order.Amount,
175186
SourceChainNames: order.TokenInChainNames,
187+
CurrentBalance: order.CurrentBalance,
176188
})
177189
if err != nil {
178190
log.Debugf("token %s on %s cannot use %s provider, source chain is '%s', source token is '%s'", order.TokenOutName, order.TargetChainName, p.Name(), order.SourceChainName, order.TokenInName)
179191
return nil, false
180192
}
181-
log.Debugf("check token %s on %s use %s success, the tokenInCosts is %+v", order.TokenOutName, order.TargetChainName, p.Name(), tokenInCosts)
182193
return tokenInCosts, true
183194
}
184195

internal/daemons/token_price/token_price.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func init() {
2121
Description: "Responsible for obtaining the token price, denominated in USDT.",
2222
TaskFunc: Run,
2323
DefaultInterval: time.Minute * 3,
24-
// RunOnStart: true,
24+
RunOnStart: true,
2525
})
2626
}
2727

@@ -39,7 +39,6 @@ func Run(ctx context.Context, conf configs.Config) error {
3939
defer w.Done()
4040
result, err := provider.GetTokenPriceInUSDT(ctx, conf.SourceTokens...)
4141
if err != nil {
42-
4342
log.Warnf("%s get token price error: %s", provider.Name(), err)
4443
return
4544
}

internal/daemons/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func CreateSwapParams(order models.Order, orderProcess models.OrderProcess, wall
3939
RecordFn: createRecordFunction(order),
4040
Order: order.Order,
4141
Remark: order.Remark,
42+
CurrentBalance: order.CurrentBalance,
4243
}
4344
}
4445

internal/models/token_price.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package models
22

33
import (
44
"context"
5+
56
"github.com/shopspring/decimal"
67
"gorm.io/gorm"
78
)
@@ -56,7 +57,7 @@ func FindTokenPrice(db *gorm.DB, tokenName []string) (result map[string]decimal.
5657
tokenPrices []TokenPrice
5758
tokenName2Price = make(map[string]TokenPrices)
5859
)
59-
err = db.Where("token_name in (?)", tokenName).First(&tokenPrices).Error
60+
err = db.Where("token_name in (?)", tokenName).Find(&tokenPrices).Error
6061
if err != nil {
6162
return
6263
}

utils/bot/balance_on_chain/monitor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (b BalanceOnChain) Check(ctx context.Context, args bot.Params) ([]bot.Task,
5656
Wallet: info.Wallet.GetAddress().Hex(),
5757
TokenOutName: info.TokenName,
5858
Amount: amount,
59+
CurrentBalance: balance,
5960
})
6061
return tasks, bot.Queue, nil
6162
}

utils/bot/bot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Config struct {
4141

4242
type Task struct {
4343
Wallet string `json:"wallet" gorm:"type:varchar(64)"`
44+
CurrentBalance decimal.Decimal `json:"current_balance"`
4445
TokenInName string `json:"token_in_name"`
4546
TokenOutName string `json:"token_out_name" gorm:"type:varchar(64)"`
4647
TokenInChainName string `json:"source_chain_name"`

utils/bot/gate_liquidity/gate_liquidity.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (b GateLiquidity) Check(ctx context.Context, args bot.Params) ([]bot.Task,
5050
ProviderType: configs.CEX,
5151
ProviderName: "gate.io",
5252
Remark: b.Name(),
53+
CurrentBalance: task.CurrentBalance,
5354
})
5455
}
5556
return result, processType, nil

utils/bot/helix_liquidity/helix_liquidity.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func (h HelixLiquidity) Check(ctx context.Context, args bot.Params) ([]bot.Task,
7171

7272
if total.Add(purchaseAmount).LessThanOrEqual(threshold) {
7373
newAmount := threshold.Add(threshold.Mul(decimal.RequireFromString("0.3")))
74-
log.Infof("The %s current balance is %s, amount in config is %s, balance(%s) + amount(%s) <= threshold(%s), so set amount to %s",
75-
args.Info.Wallet.GetAddress(), total, purchaseAmount, total, purchaseAmount, threshold, newAmount)
74+
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",
75+
args.Info.Wallet.GetAddress(), args.Info.TokenName, args.Info.Chain, total, purchaseAmount, total, purchaseAmount, threshold, newAmount)
7676
purchaseAmount = newAmount
7777
}
7878
return []bot.Task{
@@ -82,6 +82,7 @@ func (h HelixLiquidity) Check(ctx context.Context, args bot.Params) ([]bot.Task,
8282
TokenOutChainName: args.Info.Chain,
8383
Amount: purchaseAmount,
8484
Status: provider.TxStatusPending,
85+
CurrentBalance: total,
8586
},
8687
}, bot.Queue, nil
8788
}

utils/configs/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func (c *Config) Check() error {
332332
}
333333
}
334334
if !ok {
335-
return errors.Errorf("source_token[%d] token name not in chainsMap", index)
335+
return errors.Errorf("token %s, source_token[%d] token name not in chainsMap", v.Name, index)
336336
}
337337
}
338338
}

0 commit comments

Comments
 (0)