Skip to content

Commit

Permalink
Merge pull request #55 from KyberNetwork/Fixbug/Handle_ETH_address_to…
Browse files Browse the repository at this point in the history
…_get_USD_value

Fixbug/Handle_ETH_address_to_get_USD_value
  • Loading branch information
Haiss2 authored Jul 10, 2024
2 parents a055ce1 + 0266e96 commit a45d5e5
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions pkg/pricefiller/price_fillter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
NetworkETH = "ETH"
updateAllCoinInfoInterval = time.Hour
backfillTradeLogsPriceInterval = time.Hour
addressETH = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
coinUSDT = "USDT"
)

var (
Expand Down Expand Up @@ -47,6 +49,14 @@ func NewPriceFiller(l *zap.SugaredLogger, binanceClient *binance.Client,
s: s,
ksClient: NewKsClient(),
binanceClient: binanceClient,
mappedCoinInfo: map[string]CoinInfo{
addressETH: {
Coin: "ETH",
Network: NetworkETH,
ContractAddress: addressETH,
Decimals: 18,
},
},
}

if err := p.updateAllCoinInfo(); err != nil {
Expand Down Expand Up @@ -86,23 +96,25 @@ func (p *PriceFiller) updateAllCoinInfo() error {
return err
}

newMappedCoinInfo := make(map[string]CoinInfo)
p.mu.Lock()
defer p.mu.Unlock()
for _, coinInfo := range resp {
for _, network := range coinInfo.NetworkList {
if network.Network == NetworkETH {
if network.Network == NetworkETH && network.ContractAddress != "" {
address := strings.ToLower(network.ContractAddress)
newMappedCoinInfo[address] = CoinInfo{
Coin: network.Coin,
Network: network.Network,
ContractAddress: address,
if _, ok := p.mappedCoinInfo[address]; !ok {
p.mappedCoinInfo[address] = CoinInfo{
Coin: network.Coin,
Network: network.Network,
ContractAddress: address,
}
}
break
}
}
}

p.l.Infow("New mapped coin info", "data", newMappedCoinInfo)
p.mappedCoinInfo = newMappedCoinInfo
p.l.Infow("New mapped coin info", "data", p.mappedCoinInfo)
return nil
}

Expand Down Expand Up @@ -183,6 +195,9 @@ func (p *PriceFiller) getPriceAndAmountUsd(address, rawAmt string, at int64) (fl
p.mu.Unlock()
}

if coin.Coin == coinUSDT {
return 1, calculateAmountUsd(rawAmt, coin.Decimals, 1), nil
}
price, err := p.getPrice(coin.Coin, int64(at))
if err != nil {
if !errors.Is(err, ErrNoPrice) {
Expand Down

0 comments on commit a45d5e5

Please sign in to comment.