Skip to content

Commit

Permalink
Merge pull request #9 from lista-dao/main-bbtc
Browse files Browse the repository at this point in the history
Add bbtc
  • Loading branch information
bill-lista authored Jul 4, 2024
2 parents e54b633 + 12aad8e commit 4d33d00
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/bot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func Run(cfg *config.Config) {
context.Background(),
resource.Log,
resource.Wallet,
resource.AnalyticsClient,
resource.AnalyticsClientV3,
resource.HttpNodeClient,
interaction,
collateral,
Expand Down
4 changes: 3 additions & 1 deletion config/example.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ contract:
- "0x04C0599Ae5A44757c0af6F9eC3b93da8976c150A"
- "0x80137510979822322193fc997d400d5a6c747bf7"
- "0x4aae823a6a0b376de6a78e74ecc5b079d38cbcf7"
- "0xF5e11df1ebCf78b6b6D26E04FF19cD786a1e81dC"
hay: "0x0782b6d8c4551B9760e74c0545a9bCD90bdc41E5"
flushBuy: ""
settings:
maxPricePercentage: 80
analytics:
url: "https://api.prod.helio.money/"
url: "https://api.prod.helio.money/"
lista-api-url: "https://api.lista.org/"
49 changes: 49 additions & 0 deletions internal/analytics/v3/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package v1

import (
"context"
"encoding/json"
"fmt"
httpcon "github.com/lista-dao/AuctionBots-go/pkg/httpconn"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"net/http"
"net/url"
)

type Client struct {
cn *httpcon.Connector
log *logrus.Logger
}

func NewClient(
base *url.URL,
log *logrus.Logger,
) *Client {
cli := &Client{
cn: httpcon.NewConnector(base, nil),
log: log,
}
cli.log.Debug("V3 New Client ", base.Host)
return cli
}

func (cli *Client) GetRedUsers(ctx context.Context) ([]User, error) {
cli.log.Debug("V3 GetRedUsers Starting...")
code, body, err := cli.cn.Get(ctx, "/api/v2/liquidations/red", nil)
if err != nil {
return nil, err
}

if *code == http.StatusOK {
var resp CommonDataResp

if err := json.Unmarshal(body, &resp); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal body %s", string(body))
}

return resp.Data.Users, nil
}

return nil, errors.New(fmt.Sprintf("failed with %s", http.StatusText(*code)))
}
28 changes: 28 additions & 0 deletions internal/analytics/v3/misc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v1

import (
"github.com/ethereum/go-ethereum/common"
"github.com/shopspring/decimal"
)

type LiquidationUsersResp struct {
Users []User `json:"users"`
}

type CommonDataResp struct {
Code string `json:"code"`
Msg string `json:"msg"`
Data struct {
Users []User `json:"users"`
} `json:"data"`
Timestamp int64 `json:"timestamp"`
}

type User struct {
UserAddress common.Address `json:"userAddress"`
TokenName string `json:"tokenName"`
Collateral decimal.Decimal `json:"collateral"`
//LiquidationCost decimal.Decimal `json:"liquidationCost"`
//RangeFromLiquidation decimal.Decimal `json:"rangeFromLiquidation"`
//LiquidationPrice decimal.Decimal `json:"liquidationPrice"`
}
8 changes: 4 additions & 4 deletions internal/jobs/start_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
analyticsv1 "github.com/lista-dao/AuctionBots-go/internal/analytics/v1"
analyticsv3 "github.com/lista-dao/AuctionBots-go/internal/analytics/v3"
daov2 "github.com/lista-dao/AuctionBots-go/internal/dao/v2/interaction"
"github.com/lista-dao/AuctionBots-go/internal/wallet"
"github.com/pkg/errors"
Expand All @@ -22,7 +22,7 @@ func NewStartAuctionJob(
ctx context.Context,
log *logrus.Logger,
wall wallet.Walleter,
analyticsCli *analyticsv1.Client,
analyticsCli *analyticsv3.Client,
ethCli *ethclient.Client,
interactAddr common.Address,
collateralAddr common.Address,
Expand Down Expand Up @@ -52,7 +52,7 @@ type startAuctionJob struct {
ctx context.Context

wallet wallet.Walleter
analyticsCli *analyticsv1.Client
analyticsCli *analyticsv3.Client
ethCli *ethclient.Client
log *logrus.Entry
interactAddr common.Address
Expand Down Expand Up @@ -120,7 +120,7 @@ func (j *startAuctionJob) Run(ctx context.Context) {
}()
}

func (j *startAuctionJob) startAuction(user analyticsv1.User) error {
func (j *startAuctionJob) startAuction(user analyticsv3.User) error {
logrus.Infof("start auction for user: %s collateral: %s", user.UserAddress.String(), j.collateralAddr.String())

opts, err := j.wallet.Opts(j.ctx)
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type Config struct {
MaxPricePercentage int64 `mapstructure:"maxPricePercentage"`
} `mapstructure:"settings"`
Analytics struct {
Url string `mapstructure:"url"`
Url string `mapstructure:"url"`
ListaApiUrl string `mapstructure:"lista-api-url"`
} `mapstructure:"analytics"`
}

Expand Down
12 changes: 8 additions & 4 deletions pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/rpc"
"github.com/gorilla/websocket"
analyticsv3 "github.com/lista-dao/AuctionBots-go/internal/analytics/v3"
"net/http"
"net/url"
"sync"
Expand All @@ -17,10 +18,11 @@ import (
)

type Resource struct {
Log *logrus.Logger
HttpNodeClient *ethclient.Client
Wallet wallet.Walleter
AnalyticsClient *analyticsv1.Client
Log *logrus.Logger
HttpNodeClient *ethclient.Client
Wallet wallet.Walleter
AnalyticsClient *analyticsv1.Client
AnalyticsClientV3 *analyticsv3.Client
}

func LoadEnvironmentResource(config *Config) (*Resource, error) {
Expand All @@ -36,10 +38,12 @@ func LoadEnvironmentResource(config *Config) (*Resource, error) {
resource.Log.SetReportCaller(config.Log.Caller)

analyticsUrl, err := url.Parse(config.Analytics.Url)
analyticsUrlV3, err := url.Parse(config.Analytics.ListaApiUrl)
if err != nil {
return nil, fmt.Errorf("url.Parse err: %w", err)
}
resource.AnalyticsClient = analyticsv1.NewClient(analyticsUrl)
resource.AnalyticsClientV3 = analyticsv3.NewClient(analyticsUrlV3, resource.Log)

resource.HttpNodeClient, err = initHttpNodeClient(config.RpcNode.Http)
if err != nil {
Expand Down

0 comments on commit 4d33d00

Please sign in to comment.