diff --git a/configs/example.config.yaml b/configs/example.config.yaml index 02ce87f..69ca7c5 100644 --- a/configs/example.config.yaml +++ b/configs/example.config.yaml @@ -3,8 +3,8 @@ app: client_urls: binance: + dex: https://dex.binance.org explorer: https://explorer.binance.org - dex: https://dex-atlantic.binance.org/api urls: tw_assets_app: https://assets.trustwalletapp.com diff --git a/go.mod b/go.mod index ce867fe..e52477c 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.17 require ( github.com/sirupsen/logrus v1.8.1 - github.com/trustwallet/go-libs v0.2.19 - github.com/trustwallet/go-primitives v0.0.16 + github.com/trustwallet/go-libs v0.2.20 + github.com/trustwallet/go-primitives v0.0.17 ) require ( diff --git a/go.sum b/go.sum index a881022..1e085fe 100644 --- a/go.sum +++ b/go.sum @@ -272,12 +272,10 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/trustwallet/go-libs v0.2.19 h1:GTdMWYGJpTiWy7XOitveeviQIUYazU4PVxnjUBruT3g= -github.com/trustwallet/go-libs v0.2.19/go.mod h1:7QdAp1lcteKKI0DYqGoaO8KO4eTNYjGmg8vHy0YXkKc= -github.com/trustwallet/go-primitives v0.0.16-0.20211207135220-04b1926f0aa0 h1:Dd2L3iCptLdCQFt4bBH5wqrW50J7JqmEcP8aDHSZY0g= -github.com/trustwallet/go-primitives v0.0.16-0.20211207135220-04b1926f0aa0/go.mod h1:jLqd7rm+4EYG5JdpxhngM9HwbqfEXzKy/wK4vUB7STs= -github.com/trustwallet/go-primitives v0.0.16 h1:RoivfOFmMx8C4felrwWHuIWtWLm7Gd9Fj0mLIBZ8qEY= -github.com/trustwallet/go-primitives v0.0.16/go.mod h1:jLqd7rm+4EYG5JdpxhngM9HwbqfEXzKy/wK4vUB7STs= +github.com/trustwallet/go-libs v0.2.20 h1:pYstFNgsc7CVyVeYt5GHsMa0JNQHJVRvPQqMvXMpCtY= +github.com/trustwallet/go-libs v0.2.20/go.mod h1:7QdAp1lcteKKI0DYqGoaO8KO4eTNYjGmg8vHy0YXkKc= +github.com/trustwallet/go-primitives v0.0.17 h1:1fBxZMKGCHdHtgdUzsqdFlD21+1GneIk/sxN6jxYBds= +github.com/trustwallet/go-primitives v0.0.17/go.mod h1:jLqd7rm+4EYG5JdpxhngM9HwbqfEXzKy/wK4vUB7STs= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/src/client/binance/dex/client.go b/src/client/binance/dex/client.go deleted file mode 100644 index 2d71360..0000000 --- a/src/client/binance/dex/client.go +++ /dev/null @@ -1,34 +0,0 @@ -package dex - -import ( - "net/url" - "strconv" - - "github.com/trustwallet/go-libs/client" -) - -type Client struct { - req client.Request -} - -func NewClient(url string, errorHandler client.HttpErrorHandler) *Client { - return &Client{req: client.InitClient(url, errorHandler)} -} - -func (c *Client) GetMarketPairs(limit int) (pairs []MarketPair, err error) { - params := url.Values{ - "limit": {strconv.Itoa(limit)}, - } - err = c.req.Get(&pairs, "/v1/markets", params) - - return pairs, err -} - -func (c *Client) GetTokensList(limit int) (tokens []Token, err error) { - params := url.Values{ - "limit": {strconv.Itoa(limit)}, - } - err = c.req.Get(&tokens, "/v1/tokens", params) - - return tokens, err -} diff --git a/src/client/binance/dex/model.go b/src/client/binance/dex/model.go deleted file mode 100644 index 55a5ce0..0000000 --- a/src/client/binance/dex/model.go +++ /dev/null @@ -1,16 +0,0 @@ -package dex - -type ( - MarketPair struct { - BaseAssetSymbol string `json:"base_asset_symbol"` - LotSize string `json:"lot_size"` - QuoteAssetSymbol string `json:"quote_asset_symbol"` - TickSize string `json:"tick_size"` - } - - Token struct { - Symbol string `json:"symbol"` - Name string `json:"name"` - OriginalSymbol string `json:"original_symbol"` - } -) diff --git a/src/client/binance/explorer/client.go b/src/client/binance/explorer/client.go deleted file mode 100644 index 7b5a7f8..0000000 --- a/src/client/binance/explorer/client.go +++ /dev/null @@ -1,26 +0,0 @@ -package explorer - -import ( - "net/url" - "strconv" - - "github.com/trustwallet/go-libs/client" -) - -type Client struct { - req client.Request -} - -func NewClient(url string, errorHandler client.HttpErrorHandler) *Client { - return &Client{req: client.InitClient(url, errorHandler)} -} - -func (c *Client) GetBep2Assets(page, rows int) (assets Bep2Assets, err error) { - params := url.Values{ - "page": {strconv.Itoa(page)}, - "rows": {strconv.Itoa(rows)}, - } - err = c.req.Get(&assets, "/api/v1/assets", params) - - return assets, err -} \ No newline at end of file diff --git a/src/client/binance/explorer/model.go b/src/client/binance/explorer/model.go deleted file mode 100644 index c23b067..0000000 --- a/src/client/binance/explorer/model.go +++ /dev/null @@ -1,15 +0,0 @@ -package explorer - -type ( - Bep2Asset struct { - Asset string `json:"asset"` - Name string `json:"name"` - AssetImg string `json:"assetImg"` - MappedAsset string `json:"mappedAsset"` - Decimals int `json:"decimals"` - } - - Bep2Assets struct { - AssetInfoList []Bep2Asset `json:"assetInfoList"` - } -) diff --git a/src/config/config.go b/src/config/config.go index 7d25e7a..9a25a82 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -20,8 +20,8 @@ type ( ClientsURLs struct { Binance struct { - Explorer string `mapstructure:"explorer"` Dex string `mapstructure:"dex"` + Explorer string `mapstructure:"explorer"` } `mapstructure:"binance"` } diff --git a/src/core/updaters.go b/src/core/updaters.go index 6aac561..ebd06a5 100644 --- a/src/core/updaters.go +++ b/src/core/updaters.go @@ -10,9 +10,9 @@ import ( "github.com/trustwallet/assets-go-libs/pkg" "github.com/trustwallet/assets-go-libs/pkg/asset" "github.com/trustwallet/assets-go-libs/pkg/validation/info" - "github.com/trustwallet/assets-go-libs/src/client/binance/dex" - "github.com/trustwallet/assets-go-libs/src/client/binance/explorer" "github.com/trustwallet/assets-go-libs/src/config" + "github.com/trustwallet/go-libs/blockchain/binance" + "github.com/trustwallet/go-libs/blockchain/binance/explorer" assetlib "github.com/trustwallet/go-primitives/asset" "github.com/trustwallet/go-primitives/coin" "github.com/trustwallet/go-primitives/numbers" @@ -30,21 +30,21 @@ const ( ) func (s *Service) UpdateBinanceTokens() error { - explorerClient := explorer.NewClient(config.Default.ClientURLs.Binance.Explorer, nil) + explorerClient := explorer.InitClient(config.Default.ClientURLs.Binance.Explorer, nil) - bep2AssetList, err := explorerClient.GetBep2Assets(assetsPage, assetsRows) + bep2AssetList, err := explorerClient.FetchBep2Assets(assetsPage, assetsRows) if err != nil { return err } - dexClient := dex.NewClient(config.Default.ClientURLs.Binance.Dex, nil) + dexClient := binance.InitClient(config.Default.ClientURLs.Binance.Dex, "", nil) - marketPairs, err := dexClient.GetMarketPairs(marketPairsLimit) + marketPairs, err := dexClient.FetchMarketPairs(marketPairsLimit) if err != nil { return err } - tokensList, err := dexClient.GetTokensList(tokensListLimit) + tokensList, err := dexClient.FetchTokens(tokensListLimit) if err != nil { return err } @@ -119,7 +119,7 @@ func createInfoJSON(chain coin.Coin, a explorer.Bep2Asset) error { return pkg.CreateJSONFile(assetInfoPath, &assetInfo) } -func createTokenListJSON(chain coin.Coin, marketPairs []dex.MarketPair, tokenList []dex.Token) error { +func createTokenListJSON(chain coin.Coin, marketPairs []binance.MarketPair, tokenList binance.Tokens) error { tokens, err := generateTokenList(marketPairs, tokenList) if err != nil { return nil @@ -168,7 +168,7 @@ func sortTokens(tokens []TokenItem) { } } -func generateTokenList(marketPairs []dex.MarketPair, tokenList []dex.Token) ([]TokenItem, error) { +func generateTokenList(marketPairs []binance.MarketPair, tokenList binance.Tokens) ([]TokenItem, error) { if len(marketPairs) < 5 { return nil, fmt.Errorf("no markets info is returned from Binance DEX: %d", len(marketPairs)) } @@ -179,7 +179,7 @@ func generateTokenList(marketPairs []dex.MarketPair, tokenList []dex.Token) ([]T pairsMap := make(map[string][]Pair) pairsList := make(map[string]struct{}) - tokensMap := make(map[string]dex.Token) + tokensMap := make(map[string]binance.Token) for _, token := range tokenList { tokensMap[token.Symbol] = token @@ -225,7 +225,7 @@ func generateTokenList(marketPairs []dex.MarketPair, tokenList []dex.Token) ([]T return tokenItems, nil } -func getPair(marketPair dex.MarketPair) Pair { +func getPair(marketPair binance.MarketPair) Pair { return Pair{ Base: getAssetIDSymbol(marketPair.BaseAssetSymbol, coin.Coins[coin.BINANCE].Symbol, coin.BINANCE), LotSize: strconv.FormatInt(numbers.ToSatoshi(marketPair.LotSize), 10),