Skip to content

Commit

Permalink
add zenlink trades scraper for polkadot runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
jppade committed Aug 2, 2023
1 parent fc7f71a commit faccbc2
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/exchange-scrapers/collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/services/tradesBlockService/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
56 changes: 56 additions & 0 deletions config/assetlists/non_eth_assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
9 changes: 9 additions & 0 deletions internal/pkg/tradesBlockService/tradesBlockService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions pkg/dia/Messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
OSMOSIS = "Osmosis"
FIAT = "Fiat"
BIFROST = "Bifrost"
BIFROST_POLKADOT = "Bifrost-polkadot"
)

type VerificationMechanism string
Expand Down
18 changes: 12 additions & 6 deletions pkg/dia/scraper/exchange-scrapers/ZenlinkScraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ZenlinkPair struct {
}

type ZenlinkScraper struct {
exchangeName string
exchange dia.Exchange

// channels to signal events
initDone chan nothing
Expand Down Expand Up @@ -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),
Expand All @@ -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)
Expand All @@ -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()
}()
Expand All @@ -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{
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/bifrost/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
});
Expand Down
2 changes: 1 addition & 1 deletion scripts/bifrost/zenlink-bifrost-polkadot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
});
Expand Down

0 comments on commit faccbc2

Please sign in to comment.