From faccbc28bb893882c3679ca61cb681cb58cea7d3 Mon Sep 17 00:00:00 2001 From: jppade Date: Wed, 2 Aug 2023 15:29:13 +0200 Subject: [PATCH] add zenlink trades scraper for polkadot runtime. --- cmd/exchange-scrapers/collector/go.mod | 2 +- cmd/services/tradesBlockService/go.mod | 2 +- config/assetlists/non_eth_assets.json | 56 +++++++++++++++++++ .../tradesBlockService/tradesBlockService.go | 9 +++ pkg/dia/Messages.go | 1 + .../exchange-scrapers/ZenlinkScraper.go | 18 ++++-- scripts/bifrost/main.js | 2 +- scripts/bifrost/zenlink-bifrost-polkadot.js | 2 +- 8 files changed, 82 insertions(+), 10 deletions(-) diff --git a/cmd/exchange-scrapers/collector/go.mod b/cmd/exchange-scrapers/collector/go.mod index 749c203bc..3d04af305 100644 --- a/cmd/exchange-scrapers/collector/go.mod +++ b/cmd/exchange-scrapers/collector/go.mod @@ -3,7 +3,7 @@ module github.com/diadata-org/diadata/exchange-scrapers/collector go 1.17 require ( - github.com/diadata-org/diadata v1.4.309 + github.com/diadata-org/diadata v1.4.317 github.com/segmentio/kafka-go v0.4.35 github.com/sirupsen/logrus v1.9.0 ) diff --git a/cmd/services/tradesBlockService/go.mod b/cmd/services/tradesBlockService/go.mod index ae77ade82..b258590f6 100644 --- a/cmd/services/tradesBlockService/go.mod +++ b/cmd/services/tradesBlockService/go.mod @@ -3,7 +3,7 @@ module github.com/diadata-org/diadata/services/tradesBlockService go 1.17 require ( - github.com/diadata-org/diadata v1.4.297 + github.com/diadata-org/diadata v1.4.317 github.com/segmentio/kafka-go v0.4.35 github.com/sirupsen/logrus v1.8.1 ) diff --git a/config/assetlists/non_eth_assets.json b/config/assetlists/non_eth_assets.json index 1ad44e434..55bc99ef2 100644 --- a/config/assetlists/non_eth_assets.json +++ b/config/assetlists/non_eth_assets.json @@ -643,6 +643,62 @@ "Decimals": 10, "Blockchain": "Bifrost", "Address": "521" + }, + { + "Symbol": "BNC", + "Name": "Bifrost", + "Decimals": 12, + "Blockchain": "Bifrost-polkadot", + "Address": "0" + }, + { + "Symbol": "DOT", + "Name": "Polkadot", + "Decimals": 10, + "Blockchain": "Bifrost-polkadot", + "Address": "2048" + }, + { + "Symbol": "vDOT", + "Name": "Voucher DOT", + "Decimals": 10, + "Blockchain": "Bifrost-polkadot", + "Address": "2304" + }, + { + "Symbol": "vsDOT", + "Name": "vsDOT", + "Decimals": 10, + "Blockchain": "Bifrost-polkadot", + "Address": "2560" + }, + { + "Symbol": "GLMR", + "Name": "Moonriver", + "Decimals": 18, + "Blockchain": "Bifrost-polkadot", + "Address": "2049" + }, + { + "Symbol": "FIL", + "Name": "Filecoin Network Token", + "Decimals": 18, + "Blockchain": "Bifrost-polkadot", + "Address": "2052" + }, + { + "Symbol": "vGLMR", + "Name": "vGLMR", + "Decimals": 18, + "Blockchain": "Bifrost-polkadot", + "Address": "2305" + }, + { + "Symbol": "vFIL", + "Name": "vFIL", + "Decimals": 18, + "Blockchain": "Bifrost-polkadot", + "Address": "2308" } ] } \ No newline at end of file diff --git a/internal/pkg/tradesBlockService/tradesBlockService.go b/internal/pkg/tradesBlockService/tradesBlockService.go index d4c204608..34befddef 100644 --- a/internal/pkg/tradesBlockService/tradesBlockService.go +++ b/internal/pkg/tradesBlockService/tradesBlockService.go @@ -459,5 +459,14 @@ func buildBridge(t dia.Trade) dia.Asset { } } } + if basetoken.Blockchain == dia.BIFROST_POLKADOT && t.Source == dia.ZenlinkswapExchangeBifrostPolkadot { + if basetoken.Address == "2048" { + basetoken = dia.Asset{ + Symbol: "KSM", + Address: "0x0000000000000000000000000000000000000000", + Blockchain: dia.KUSAMA, + } + } + } return basetoken } diff --git a/pkg/dia/Messages.go b/pkg/dia/Messages.go index 69a1c0439..8c18d69a1 100644 --- a/pkg/dia/Messages.go +++ b/pkg/dia/Messages.go @@ -44,6 +44,7 @@ const ( OSMOSIS = "Osmosis" FIAT = "Fiat" BIFROST = "Bifrost" + BIFROST_POLKADOT = "Bifrost-polkadot" ) type VerificationMechanism string diff --git a/pkg/dia/scraper/exchange-scrapers/ZenlinkScraper.go b/pkg/dia/scraper/exchange-scrapers/ZenlinkScraper.go index fbd3a1fa8..b2fefe7eb 100644 --- a/pkg/dia/scraper/exchange-scrapers/ZenlinkScraper.go +++ b/pkg/dia/scraper/exchange-scrapers/ZenlinkScraper.go @@ -42,7 +42,7 @@ type ZenlinkPair struct { } type ZenlinkScraper struct { - exchangeName string + exchange dia.Exchange // channels to signal events initDone chan nothing @@ -81,7 +81,7 @@ func NewZenlinkScraper(exchange dia.Exchange, scrape bool) *ZenlinkScraper { } scraper := &ZenlinkScraper{ - exchangeName: exchange.Name, + exchange: exchange, wsClient: wsClient, initDone: make(chan nothing), shutdown: make(chan nothing), @@ -103,6 +103,8 @@ func (s *ZenlinkScraper) receive(nodeScriptPath string) { go func() { cmd := exec.Command("node", nodeScriptPath) stdout, _ := cmd.StdoutPipe() + stderr, _ := cmd.StderrPipe() + err := cmd.Start() if err != nil { log.Error("start main.js: ", err) @@ -118,6 +120,10 @@ func (s *ZenlinkScraper) receive(nodeScriptPath string) { fmt.Println(scanner.Text()) } } + scannerErr := bufio.NewScanner(stderr) + for scannerErr.Scan() { + log.Error("Run script: ", scannerErr.Text()) + } // Wait for the script to finish cmd.Wait() }() @@ -141,12 +147,12 @@ func (s *ZenlinkScraper) receive(nodeScriptPath string) { price := FromAmount / toAmount basetoken := dia.Asset{ Symbol: fields[2], - Blockchain: dia.BIFROST, + Blockchain: s.exchange.BlockChain.Name, Address: fields[6], } quotetoken := dia.Asset{ Symbol: fields[1], - Blockchain: dia.BIFROST, + Blockchain: s.exchange.BlockChain.Name, Address: fields[5], } trade := &dia.Trade{ @@ -156,7 +162,7 @@ func (s *ZenlinkScraper) receive(nodeScriptPath string) { Volume: toAmount, Time: time.Now(), ForeignTradeID: fields[7], - Source: s.exchangeName, + Source: s.exchange.Name, BaseToken: basetoken, QuoteToken: quotetoken, VerifiedPair: true, @@ -222,7 +228,7 @@ func (s *ZenlinkScraper) FetchAvailablePairs() (pairs []dia.ExchangePair, err er pairToNormalize := dia.ExchangePair{ Symbol: strings.Split(p.Symbol, "/")[0], ForeignName: p.Symbol, - Exchange: s.exchangeName, + Exchange: s.exchange.Name, } pairs = append(pairs, pairToNormalize) } diff --git a/scripts/bifrost/main.js b/scripts/bifrost/main.js index 2cd0e70b9..fc4c2866b 100644 --- a/scripts/bifrost/main.js +++ b/scripts/bifrost/main.js @@ -33,7 +33,7 @@ async function main() { let toDecimals = getDecimals(to); let out = `${to}-${from} ${to} ${from}` out += ` ${BigNumber(asset_balance[0]).dividedBy(10 ** toDecimals)} ${BigNumber(asset_balance[asset_balance.length - 1]).dividedBy(10 ** fromDecimals)}`; - out += ` ${to_asset_id} ${from_asset_id}`; + out += ` ${to_native.assetIndex} ${from_native.assetIndex}`; out += ` ${header.number}-${phase.asApplyExtrinsic}`; console.log(`Trade:${out}`) }); diff --git a/scripts/bifrost/zenlink-bifrost-polkadot.js b/scripts/bifrost/zenlink-bifrost-polkadot.js index b06ffa1ef..cdb4c4b93 100644 --- a/scripts/bifrost/zenlink-bifrost-polkadot.js +++ b/scripts/bifrost/zenlink-bifrost-polkadot.js @@ -33,7 +33,7 @@ async function main() { let toDecimals = getDecimals(to); let out = `${to}-${from} ${to} ${from}` out += ` ${BigNumber(asset_balance[0]).dividedBy(10 ** toDecimals)} ${BigNumber(asset_balance[asset_balance.length - 1]).dividedBy(10 ** fromDecimals)}`; - out += ` ${to_asset_id} ${from_asset_id}`; + out += ` ${to_native.assetIndex} ${from_native.assetIndex}`; out += ` ${header.number}-${phase.asApplyExtrinsic}`; console.log(`Trade:${out}`) });