-
Notifications
You must be signed in to change notification settings - Fork 126
/
tradesBlockService.go
621 lines (575 loc) · 19.8 KB
/
tradesBlockService.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
package tradesBlockService
import (
"errors"
"math"
"sort"
"strconv"
"sync"
"time"
"github.com/cnf/structhash"
"github.com/diadata-org/diadata/pkg/dia"
scrapers "github.com/diadata-org/diadata/pkg/dia/scraper/exchange-scrapers"
models "github.com/diadata-org/diadata/pkg/model"
"github.com/diadata-org/diadata/pkg/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/sirupsen/logrus"
)
type nothing struct{}
func init() {
log = logrus.New()
var err error
batchTimeSeconds, err = strconv.Atoi(utils.Getenv("BATCH_TIME_SECONDS", "30"))
if err != nil {
log.Error("parse BATCH_TIME_SECONDS: ", err)
}
volumeThreshold, err = strconv.ParseFloat(utils.Getenv("VOLUME_THRESHOLD", "100000"), 64)
if err != nil {
log.Error("parse env var VOLUME_THRESHOLD: ", err)
}
blueChipThreshold, err = strconv.ParseFloat(utils.Getenv("BLUECHIP_THRESHOLD", "50000000"), 64)
if err != nil {
log.Error("parse env var BLUECHIP_THRESHOLD: ", err)
}
smallX, err = strconv.ParseFloat(utils.Getenv("SMALL_X", "10"), 64)
if err != nil {
log.Error("parse env var SMALL_X: ", err)
}
normalX, err = strconv.ParseFloat(utils.Getenv("NORMAL_X", "10"), 64)
if err != nil {
log.Error("parse env var NORMAL_X: ", err)
}
tradeVolumeThresholdExponent, err := strconv.ParseFloat(utils.Getenv("TRADE_VOLUME_THRESHOLD_EXPONENT", ""), 64)
if err != nil {
log.Error("Parse TRADE_VOLUME_THRESHOLD_EXPONENT: ", err)
}
tradeVolumeThreshold = math.Pow(10, -tradeVolumeThresholdExponent)
tradeVolumeThresholdUSDExponent, err := strconv.ParseFloat(utils.Getenv("TRADE_VOLUME_THRESHOLD_USD_EXPONENT", ""), 64)
if err != nil {
log.Error("Parse TRADE_VOLUME_THRESHOLD_USD_EXPONENT: ", err)
}
tradeVolumeThresholdUSD = math.Pow(10, -tradeVolumeThresholdUSDExponent)
}
var (
stablecoins = map[string]interface{}{
"USDT": "",
"TUSD": "",
// "DAI": "",
// "USDC": "",
"PAX": "",
"BUSD": "",
}
// These should be loaded from postgres once we have a list.
USDT = dia.Asset{Address: "0xdAC17F958D2ee523a2206206994597C13D831ec7", Blockchain: dia.ETHEREUM}
USDC = dia.Asset{Address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", Blockchain: dia.ETHEREUM}
BUSD = dia.Asset{Address: "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56", Blockchain: dia.BINANCESMARTCHAIN}
DAI = dia.Asset{Address: "0x6B175474E89094C44Da98b954EedeAC495271d0F", Blockchain: dia.ETHEREUM}
TUSD = dia.Asset{Address: "0x0000000000085d4780B73119b644AE5ecd22b376", Blockchain: dia.ETHEREUM}
stablecoinAssets = map[string]interface{}{
USDT.Identifier(): "",
USDC.Identifier(): "",
BUSD.Identifier(): "",
DAI.Identifier(): "",
TUSD.Identifier(): "",
}
tol = float64(0.04)
log *logrus.Logger
batchTimeSeconds int
tradeVolumeThreshold float64
tradeVolumeThresholdUSD float64
volumeUpdateSeconds = 60 * 10
volumeThreshold float64
blueChipThreshold float64
smallX float64
normalX float64
checkTradesDuplicate = make(map[string]struct{})
)
type TradesBlockService struct {
shutdown chan nothing
shutdownDone chan nothing
chanTrades chan *dia.Trade
chanTradesBlock chan *dia.TradesBlock
errorLock sync.RWMutex
error error
closed bool
started bool
BlockDuration int64
currentBlock *dia.TradesBlock
priceCache map[string]float64
volumeCache map[string]float64
datastore models.Datastore
relDB models.RelDatastore
historical bool
writeMeasurement string
batchTicker *time.Ticker
volumeTicker *time.Ticker
}
func NewTradesBlockService(datastore models.Datastore, relDB models.RelDatastore, blockDuration int64, historical bool) *TradesBlockService {
s := &TradesBlockService{
shutdown: make(chan nothing),
shutdownDone: make(chan nothing),
chanTrades: make(chan *dia.Trade),
chanTradesBlock: make(chan *dia.TradesBlock),
error: nil,
started: false,
currentBlock: nil,
BlockDuration: blockDuration,
priceCache: make(map[string]float64),
volumeCache: make(map[string]float64),
datastore: datastore,
relDB: relDB,
historical: historical,
batchTicker: time.NewTicker(time.Duration(batchTimeSeconds) * time.Second),
volumeTicker: time.NewTicker(time.Duration(volumeUpdateSeconds) * time.Second),
}
if historical {
s.writeMeasurement = utils.Getenv("INFLUX_MEASUREMENT_WRITE", "tradesTmp")
}
log.Info("write measurement: ", s.writeMeasurement)
log.Info("historical: ", s.historical)
log.Info("batch ticker time: ", batchTimeSeconds)
log.Info("volume threshold: ", volumeThreshold)
log.Info("bluechip threshold: ", blueChipThreshold)
log.Info("smallX: ", smallX)
log.Info("normalX: ", normalX)
log.Info("tradeVolumeThreshold: ", tradeVolumeThreshold)
log.Info("tradeVolumeThresholdUSD: ", tradeVolumeThresholdUSD)
s.volumeCache = s.loadVolumes()
log.Info("...done loading volumes.")
go s.mainLoop()
go s.loadVolumesLoop()
return s
}
// runs in a goroutine until s is closed
func (s *TradesBlockService) mainLoop() {
var (
acceptCountDEX int
// acceptCountSwapDEX int
totalCount int
logTicker = *time.NewTicker(120 * time.Second)
)
for {
select {
case <-s.shutdown:
log.Println("TradesBlockService shutting down")
s.cleanup(nil)
return
case t := <-s.chanTrades:
// Only take into account original order for CEX trade.
if scrapers.Exchanges[(*t).Source].Centralized {
s.process(*t)
} else {
// tSwapped, err := dia.SwapTrade(*t)
// if err != nil {
// log.Error("swap trade: ", err)
// }
// Collect booleans for stats.
tradeOk := s.checkTrade(*t)
// swapppedTradeOk := s.checkTrade(tSwapped)
if tradeOk {
acceptCountDEX++
}
// if swapppedTradeOk {
// acceptCountSwapDEX++
// }
// if tradeOk || swapppedTradeOk {
// acceptCount++
// }
totalCount++
// Process (possibly) both trades.
if tradeOk {
s.process(*t)
}
// s.process(tSwapped)
}
case <-s.batchTicker.C:
err := s.datastore.Flush()
if err != nil {
log.Error("flush influx batch: ", err)
}
case <-logTicker.C:
log.Info("accepted trades DEX: ", acceptCountDEX)
// log.Info("accepted swapped trades DEX: ", acceptCountSwapDEX)
log.Info("discarded trades: ", totalCount-acceptCountDEX)
acceptCountDEX = 0
// acceptCountSwapDEX = 0
totalCount = 0
}
}
}
// checkTrade determines whether a (DEX-)trade should be taken into account for price determination.
func (s *TradesBlockService) checkTrade(t dia.Trade) bool {
// Discard (very) low volume trade.
if math.Abs(t.Volume) < tradeVolumeThreshold {
log.Info("low volume trade: ", t)
return false
}
// Replace basetoken with bridged asset for pricing if necessary.
// The basetoken in the stored trade will remain unchanged.
basetoken := buildBridge(t)
// Allow trade where basetoken is stablecoin.
if _, ok := stablecoinAssets[basetoken.Identifier()]; ok {
return true
}
// Only take into account stablecoin trade if basetoken is stable coin as well.
if _, ok := stablecoinAssets[t.QuoteToken.Identifier()]; ok {
if _, ok := stablecoinAssets[basetoken.Identifier()]; !ok {
return false
}
}
if baseVolume, ok := s.volumeCache[basetoken.Identifier()]; ok {
if baseVolume > blueChipThreshold {
return true
}
if quoteVolume, ok := s.volumeCache[t.QuoteToken.Identifier()]; ok {
if baseVolume < volumeThreshold {
// For small volume basetoken, quotetoken must be a small volume asset too.
return quoteVolume < smallX*baseVolume
}
// Discard trade if base volume is too small compared to quote volume.
return quoteVolume < normalX*baseVolume
}
// Base asset has enough volume or quotetoken has no volume yet.
return true
}
return false
}
func (s *TradesBlockService) process(t dia.Trade) {
var (
verifiedTrade bool
tradeOk bool
)
if scrapers.Exchanges[t.Source].Centralized {
tradeOk = true
} else {
tradeOk = s.checkTrade(t)
}
// Price estimation can only be done for verified pairs.
// Trades with unverified pairs are still saved, but not sent to the filtersBlockService.
if t.VerifiedPair && tradeOk {
if t.BaseToken.Address == "840" && t.BaseToken.Blockchain == dia.FIAT {
// All prices are measured in US-Dollar, so just price for base token == USD
t.EstimatedUSDPrice = t.Price
verifiedTrade = true
} else {
var (
quotation *models.AssetQuotation
price float64
ok bool
err error
)
// Bridge basetoken if necessary.
basetoken := buildBridge(t)
// Get latest price from cache.
if _, ok = s.priceCache[basetoken.Identifier()]; ok {
price = s.priceCache[basetoken.Identifier()]
} else {
quotation, err = s.datastore.GetAssetQuotationCache(basetoken)
price = quotation.Price
s.priceCache[basetoken.Identifier()] = price
// log.Infof("quotation for %s from redis cache: %v", basetoken.Symbol, price)
}
if err != nil {
log.Errorf("Can't find quotation for base token in trade %s: %v.\n Basetoken address -- blockchain: %s --- %s",
t.Pair,
err,
t.BaseToken.Address,
t.BaseToken.Blockchain,
)
} else {
if price > 0.0 {
t.EstimatedUSDPrice = t.Price * price
if t.VolumeUSD() > tradeVolumeThresholdUSD {
verifiedTrade = true
} else {
log.Warn("low $ volume on trade: ", t)
}
}
}
}
}
// // If estimated price for stablecoin diverges too much ignore trade
if _, ok := stablecoins[t.Symbol]; ok {
if math.Abs(t.EstimatedUSDPrice-1) > tol && t.EstimatedUSDPrice > 0 {
log.Errorf("%s on %s. price for %s diverges by %v", t.Pair, t.Source, t.Symbol, math.Abs(t.EstimatedUSDPrice-1))
verifiedTrade = false
}
}
// Comment Philipp: We could make another check here. Store CG and/or CMC quotation in redis cache
// and compare with estimatedUSDPrice. If deviation is too large ignore trade.
var err error
if !s.historical {
err = s.datastore.SaveTradeInflux(&t)
if err != nil {
log.Error(err)
}
} else {
err = s.datastore.SaveTradeInfluxToTable(&t, s.writeMeasurement)
if err != nil {
log.Error(err)
}
}
if s.currentBlock != nil && s.currentBlock.TradesBlockData.BeginTime.After(t.Time) {
log.Debugf("ignore trade should be in previous block %v", t)
verifiedTrade = false
}
// Only verified trades of verified pairs with nonzero price are added to the tradesBlock
if verifiedTrade && t.EstimatedUSDPrice > 0 {
if s.currentBlock == nil || s.currentBlock.TradesBlockData.EndTime.Before(t.Time) {
if s.currentBlock != nil {
s.finaliseCurrentBlock()
s.priceCache = make(map[string]float64)
}
b := &dia.TradesBlock{
TradesBlockData: dia.TradesBlockData{
Trades: []dia.Trade{},
EndTime: time.Unix((t.Time.Unix()/s.BlockDuration)*s.BlockDuration+s.BlockDuration, 0),
BeginTime: time.Unix((t.Time.Unix()/s.BlockDuration)*s.BlockDuration, 0),
},
}
if s.currentBlock != nil {
log.Info("created new block beginTime:", b.TradesBlockData.BeginTime, "previous block nb trades:", len(s.currentBlock.TradesBlockData.Trades))
}
s.currentBlock = b
err = s.datastore.Flush()
if err != nil {
log.Error(err)
}
}
// For centralized exchanges check if trade is not in the block yet
// (we have observed ws APIs sending identical trades).
if scrapers.Exchanges[t.Source].Centralized {
if _, ok := checkTradesDuplicate[t.TradeIdentifierFull()]; !ok {
s.currentBlock.TradesBlockData.Trades = append(s.currentBlock.TradesBlockData.Trades, t)
checkTradesDuplicate[t.TradeIdentifierFull()] = struct{}{}
} else {
if scrapers.Exchanges[t.Source].Name != dia.BitforexExchange {
log.Warn("duplicate trade within one tradesblock: ", t)
}
}
} else {
s.currentBlock.TradesBlockData.Trades = append(s.currentBlock.TradesBlockData.Trades, t)
}
} else {
log.Debugf("ignore trade %v", t)
}
}
func (s *TradesBlockService) loadVolumes() map[string]float64 {
// Clean asset volumes
volumeCache := make(map[string]float64)
endtime := time.Now()
assets, err := s.relDB.GetAssetsWithVolByBlockchain(endtime.AddDate(0, 0, -7), endtime, "")
if err != nil {
log.Error("could not load asset with volume: ", err)
}
for _, asset := range assets {
volumeCache[asset.Asset.Identifier()] = asset.Volume
}
return volumeCache
}
func (s *TradesBlockService) loadVolumesLoop() {
for range s.volumeTicker.C {
s.volumeCache = s.loadVolumes()
}
}
func (s *TradesBlockService) finaliseCurrentBlock() {
sort.Slice(s.currentBlock.TradesBlockData.Trades, func(i, j int) bool {
return s.currentBlock.TradesBlockData.Trades[i].Time.Before(s.currentBlock.TradesBlockData.Trades[j].Time)
})
hash, err := structhash.Hash(s.currentBlock.TradesBlockData, 1)
if err != nil {
log.Printf("error on hash")
hash = "hashError"
}
s.currentBlock.BlockHash = hash
s.currentBlock.TradesBlockData.TradesNumber = len(s.currentBlock.TradesBlockData.Trades)
// Reset duplicate trades identifier.
checkTradesDuplicate = make(map[string]struct{})
s.chanTradesBlock <- s.currentBlock
}
func (s *TradesBlockService) ProcessTrade(trade *dia.Trade) {
s.chanTrades <- trade
}
func (s *TradesBlockService) Close() error {
if s.closed {
return errors.New("TradesBlockService: Already closed")
}
close(s.shutdown)
<-s.shutdownDone
return s.error
}
// must only be called from mainLoop
func (s *TradesBlockService) cleanup(err error) {
s.errorLock.Lock()
defer s.errorLock.Unlock()
if err != nil {
s.error = err
}
s.closed = true
close(s.shutdownDone) // signal that shutdown is complete
}
func (s *TradesBlockService) Channel() chan *dia.TradesBlock {
return s.chanTradesBlock
}
func buildBridge(t dia.Trade) dia.Asset {
basetoken := t.BaseToken
// if basetoken.Blockchain == dia.ETHEREUM && basetoken.Address == "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" {
// basetoken = dia.Asset{
// Symbol: "ETH",
// Address: "0x0000000000000000000000000000000000000000",
// Blockchain: dia.ETHEREUM,
// }
// }
if basetoken.Blockchain == dia.SOLANA && t.Source == dia.OrcaExchange {
if basetoken.Address == "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" {
basetoken = dia.Asset{
Symbol: "USDC",
Address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
Blockchain: dia.ETHEREUM,
}
}
if basetoken.Address == "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB" {
basetoken = dia.Asset{
Symbol: "USDT",
Address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
Blockchain: dia.ETHEREUM,
}
}
}
if basetoken.Blockchain == dia.METIS && (t.Source == dia.NetswapExchange || t.Source == dia.TethysExchange || t.Source == dia.HermesExchange) && basetoken.Address == "0xEA32A96608495e54156Ae48931A7c20f0dcc1a21" {
basetoken = dia.Asset{
Symbol: "USDC",
Address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
Blockchain: dia.ETHEREUM,
}
}
if basetoken.Blockchain == dia.FANTOM && (t.Source == dia.SpookyswapExchange || t.Source == dia.SpiritswapExchange || t.Source == dia.BeetsExchange || t.Source == dia.SushiSwapExchangeFantom) {
if basetoken.Address == "0x04068DA6C83AFCFA0e13ba15A6696662335D5B75" {
basetoken = dia.Asset{
Symbol: "USDC",
Address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
Blockchain: dia.ETHEREUM,
}
}
}
if basetoken.Blockchain == dia.TELOS && (t.Source == dia.OmniDexExchange) && basetoken.Address == common.HexToAddress("0xd102ce6a4db07d247fcc28f366a623df0938ca9e").Hex() {
basetoken = dia.Asset{
Symbol: "TLOS",
Address: "0x0000000000000000000000000000000000000000",
Blockchain: dia.TELOS,
}
}
if basetoken.Blockchain == dia.EVMOS && t.Source == dia.DiffusionExchange {
if basetoken.Address == common.HexToAddress("0xD4949664cD82660AaE99bEdc034a0deA8A0bd517").Hex() {
basetoken = dia.Asset{
Symbol: "EVMOS",
Address: "0x0000000000000000000000000000000000000000",
Blockchain: dia.EVMOS,
}
}
}
if t.Source == dia.StellaswapExchange && basetoken.Blockchain == dia.MOONBEAM {
if basetoken.Address == common.HexToAddress("0xAcc15dC74880C9944775448304B263D191c6077F").Hex() {
basetoken = dia.Asset{
Symbol: "GLMR",
Address: "0x0000000000000000000000000000000000000000",
Blockchain: dia.MOONBEAM,
}
}
}
if t.Source == dia.CurveFIExchangeMoonbeam && basetoken.Blockchain == dia.MOONBEAM {
if basetoken.Address == common.HexToAddress("0xFFFFFFfFea09FB06d082fd1275CD48b191cbCD1d").Hex() {
basetoken = dia.Asset{
Symbol: "USDT",
Address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
Blockchain: dia.ETHEREUM,
}
}
}
if (t.Source == dia.UniswapExchangeV3Polygon || t.Source == dia.QuickswapExchange || t.Source == dia.SushiSwapExchangePolygon || t.Source == dia.DfynNetwork) && basetoken.Blockchain == dia.POLYGON {
if basetoken.Address == common.HexToAddress("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174").Hex() {
basetoken = dia.Asset{
Symbol: "USDC",
Address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
Blockchain: dia.ETHEREUM,
}
}
if basetoken.Address == common.HexToAddress("0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270").Hex() {
basetoken = dia.Asset{
Symbol: "MATIC",
Address: "0x0000000000000000000000000000000000001010",
Blockchain: dia.POLYGON,
}
}
}
if t.Source == dia.ArthswapExchange && basetoken.Blockchain == dia.ASTAR {
if basetoken.Address == common.HexToAddress("0x6a2d262D56735DbA19Dd70682B39F6bE9a931D98").Hex() {
basetoken = dia.Asset{
Symbol: "USDC",
Address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
Blockchain: dia.ETHEREUM,
}
}
if basetoken.Address == common.HexToAddress("0xAeaaf0e2c81Af264101B9129C00F4440cCF0F720").Hex() {
basetoken = dia.Asset{
Symbol: "ASTR",
Address: "0x0000000000000000000000000000000000000000",
Blockchain: dia.ASTAR,
}
}
}
if basetoken.Blockchain == dia.AVALANCHE && (t.Source == dia.TraderJoeExchange || t.Source == dia.PangolinExchange) {
if basetoken.Address == common.HexToAddress("0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7").Hex() {
basetoken = dia.Asset{
Symbol: "AVAX",
Address: "0x0000000000000000000000000000000000000000",
Blockchain: dia.AVALANCHE,
}
}
}
if basetoken.Blockchain == dia.WANCHAIN && t.Source == dia.WanswapExchange {
if basetoken.Address == common.HexToAddress("0xdabD997aE5E4799BE47d6E69D9431615CBa28f48").Hex() {
basetoken = dia.Asset{
Symbol: "WAN",
Address: "0x0000000000000000000000000000000000000000",
Blockchain: dia.WANCHAIN,
}
}
}
if basetoken.Blockchain == dia.ARBITRUM && (t.Source == dia.UniswapExchangeV3Arbitrum || t.Source == dia.SushiSwapExchangeArbitrum || t.Source == dia.CamelotExchange || t.Source == dia.TraderJoeExchangeV2_1Arbitrum) {
if basetoken.Address == common.HexToAddress("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1").Hex() {
basetoken = dia.Asset{
Symbol: "ETH",
Address: "0x0000000000000000000000000000000000000000",
Blockchain: dia.ETHEREUM,
}
}
}
if basetoken.Blockchain == dia.OSMOSIS && t.Source == dia.OsmosisExchange {
if basetoken.Address == "ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858" {
basetoken = dia.Asset{
Symbol: "USDC",
Address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
Blockchain: dia.ETHEREUM,
}
}
}
if basetoken.Blockchain == dia.BIFROST && t.Source == dia.ZenlinkswapExchange {
if basetoken.Address == "516" {
basetoken = dia.Asset{
Symbol: "KSM",
Address: "0x0000000000000000000000000000000000000000",
Blockchain: dia.KUSAMA,
}
}
}
if basetoken.Blockchain == dia.BIFROST_POLKADOT && t.Source == dia.ZenlinkswapExchangeBifrostPolkadot {
if basetoken.Address == "2048" {
basetoken = dia.Asset{
Symbol: "DOT",
Address: "0x0000000000000000000000000000000000000000",
Blockchain: dia.POLKADOT,
}
}
}
return basetoken
}