Skip to content

Commit

Permalink
Feature/hydration (#1157)
Browse files Browse the repository at this point in the history
* updated logic to pull and filter events

* custom events to websocket

* wip

* wip

* added new block logic event scraper

* put gsrpc library inside repo and set default block to latest

* add decimals and extrinsic id

* add asset name and don't stop on reaching last block

* get omnipool events

* filter pools in code

* fix rebase errors

* hydration liquidity and asset scrapers

* hydration - fix 4 pool error in parsing assets

---------

Co-authored-by: Erion Barasuol <[email protected]>
  • Loading branch information
didaunesp and Erion Barasuol authored Nov 5, 2024
1 parent baed5ea commit 6623f41
Show file tree
Hide file tree
Showing 12 changed files with 933 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cmd/assetCollectionService/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ func NewAssetScraper(exchange string, secret string, relDB *models.RelDB) source
return source.NewVelodromeAssetSource(exchanges[dia.AerodromeSlipstreamExchange], relDB)
case dia.AerodromeV1Exchange:
return source.NewVelodromeAssetSource(exchanges[dia.AerodromeV1Exchange], relDB)
case dia.HydrationExchange:
return source.NewHydrationAssetSource(exchanges[dia.HydrationExchange], relDB)
case dia.BifrostExchange:
return source.NewBifrostAssetSource(exchanges[dia.BifrostExchange], relDB)
default:
Expand Down
1 change: 1 addition & 0 deletions cmd/exchange-scrapers/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
dia.BitflowExchange,
dia.VelarExchange,
dia.BifrostExchange,
dia.HydrationExchange,
}

exchange = flag.String("exchange", "", "which exchange")
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ require (
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-resty/resty/v2 v2.7.0
github.com/gocolly/colly v1.2.0
github.com/google/gofuzz v1.2.0
github.com/gorilla/websocket v1.5.0
github.com/graph-gophers/graphql-go v1.3.0
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c
Expand Down Expand Up @@ -126,6 +125,7 @@ require (
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/rpc v1.2.0 // indirect
Expand Down Expand Up @@ -156,7 +156,6 @@ require (
github.com/leodido/go-urn v1.3.0 // indirect
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/machinebox/graphql v0.2.2 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/matryer/is v1.4.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down Expand Up @@ -197,7 +196,6 @@ require (
github.com/spf13/viper v1.10.1 // indirect
github.com/streamingfast/binary v0.0.0-20210928223119-44fc44e4a0b5 // indirect
github.com/streamingfast/logging v0.0.0-20230608130331-f22c91403091 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
Expand Down Expand Up @@ -241,7 +239,6 @@ require (
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/kennygrant/sanitize v1.2.4 // indirect
github.com/machinebox/graphql v0.2.2
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/rs/zerolog v1.29.0 // indirect
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
Expand Down
1 change: 1 addition & 0 deletions pkg/dia/Config.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const (
AerodromeSlipstreamExchange = "AerodromeSlipstream"
AerodromeV1Exchange = "AerodromeV1"
BifrostExchange = "Bifrost"
HydrationExchange = "Hydration"
// FinageForex = "FinageForex"
)

Expand Down
26 changes: 26 additions & 0 deletions pkg/dia/helpers/hydration-helper/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package hydrationhelper

import (
"github.com/sirupsen/logrus"
"time"
)

const (
AssetAddressURI = "AssetRegistry:Assets"
Blockchain = "polkadot"
GetAssetsPath = "assets"
)

type HydrationClient struct {
logger *logrus.Entry
sleepBetweenCalls time.Duration
debug bool
}

func NewHydrationClient(logger *logrus.Entry, sleepBetweenCalls time.Duration, isDebug bool) *HydrationClient {
return &HydrationClient{
logger: logger,
sleepBetweenCalls: sleepBetweenCalls,
debug: isDebug,
}
}
59 changes: 59 additions & 0 deletions pkg/dia/helpers/hydration-helper/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package hydrationhelper

const (
DefaultRefreshDelay = 400 // millisec
DefaultSleepBetweenContractCalls = 300 // millisec
DefaultEventsLimit = 100
DefaultSwapContractsLimit = 100
)

type HydrationAssetMetadata struct {
Id string `json:"id"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Decimals uint `json:"decimals"`
Icon string `json:"icon"`
Type string `json:"type"`
IsSufficient bool `json:"isSufficient"`
ExistentialDeposit string `json:"existentialDeposit"`
Origin int `json:"origin"`
}

type HydrationPoolTokenMetada struct {
ID string `json:"id"`
Balance string `json:"balance"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Decimals int `json:"decimals"`
Icon string `json:"icon"`
Type string `json:"type"`
IsSufficient bool `json:"isSufficient"`
ExistentialDeposit string `json:"existentialDeposit"`
Origin int `json:"origin,omitempty"`
UsdBalance string `json:"usdBalance"`
Index int `json:"index"`
}

type HydrationPoolUsdBalanceMetadata struct {
Amount string `json:"amount"`
Decimals int `json:"decimals"`
}

type HydrationPoolMetada struct {
Address string `json:"address"`
Type string `json:"type"`
Tokens []HydrationPoolTokenMetada `json:"tokens"`
MaxInRatio int `json:"maxInRatio"`
MaxOutRatio int `json:"maxOutRatio"`
MinTradingLimit int `json:"minTradingLimit"`
}

type HydrationSwapEvent struct {
TxID string `json:"txId"`
Timestamp int64 `json:"timestamp"`
BlockHash string `json:"blockHash"`
AssetIn string `json:"assetIn"`
AssetOut string `json:"assetOut"`
AmountIn string `json:"amountIn"`
AmountOut string `json:"amountOut"`
}
2 changes: 2 additions & 0 deletions pkg/dia/scraper/exchange-scrapers/APIScraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ func NewAPIScraper(exchange string, scrape bool, key string, secret string, relD
return NewVelarScraper(Exchanges[dia.VelarExchange], scrape, relDB)
case dia.BifrostExchange:
return NewBifrostScraper(Exchanges[dia.BifrostExchange], scrape, relDB)
case dia.HydrationExchange:
return NewHydrationScraper(Exchanges[dia.HydrationExchange], scrape, relDB)
default:
return nil
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/dia/scraper/exchange-scrapers/BifrostScraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import (
"github.com/sirupsen/logrus"
)

const (
Blockchain = "Bifrost"
)

type BifrostScraper struct {
logger *logrus.Entry
pairScrapers map[string]*BifrostPairScraper // pc.ExchangePair -> pairScraperSet
Expand Down Expand Up @@ -67,7 +63,7 @@ func NewBifrostScraper(exchange dia.Exchange, scrape bool, relDB *models.RelDB)
db: relDB,
wsApi: wsApi,
exchangeName: exchange.Name,
blockchain: Blockchain,
blockchain: "Bifrost",
currentBlock: startBlockUint64,
}

Expand Down
Loading

0 comments on commit 6623f41

Please sign in to comment.