Skip to content

Commit

Permalink
fix: pricing system
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 19, 2023
1 parent ac9eb34 commit b9ad218
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions processes/prices/fetcher.curveAMM.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func fetchPricesFromCurveAMM(chainID uint64, blockNumber *uint64, tokens []commo
calls := []ethereum.Call{}
for _, token := range tokens {
calls = append(calls, multicalls.GetLPPrice(token.Hex(), token))
calls = append(calls, multicalls.GetDecimals(token.Hex(), token))
}

/**********************************************************************************************
Expand All @@ -55,14 +56,19 @@ func fetchPricesFromCurveAMM(chainID uint64, blockNumber *uint64, tokens []commo

for _, token := range tokens {
rawTokenPrice := response[token.Hex()+`lp_price`]
rawDecimals := response[token.Hex()+`decimals`]
if len(rawTokenPrice) == 0 {
continue
}
tokenPrice := bigNumber.SetInt(rawTokenPrice[0].(*big.Int))
if tokenPrice.IsZero() {
decimals := helpers.DecodeUint64(rawDecimals)
bigTokenPrice := bigNumber.SetInt(rawTokenPrice[0].(*big.Int))
if bigTokenPrice.IsZero() {
continue
}
newPriceMap[token] = helpers.DecodeBigInt(rawTokenPrice)
tokenPriceUSD := helpers.ToNormalizedAmount(bigTokenPrice, decimals)
tokenPrice := bigNumber.NewFloat(0).Mul(tokenPriceUSD, bigNumber.NewFloat(1e6)).Int()

newPriceMap[token] = tokenPrice
}
return newPriceMap
}
8 changes: 8 additions & 0 deletions processes/prices/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

"github.com/ethereum/go-ethereum/common"
"github.com/yearn/ydaemon/common/addresses"
"github.com/yearn/ydaemon/common/bigNumber"
"github.com/yearn/ydaemon/common/env"
"github.com/yearn/ydaemon/common/ethereum"
Expand Down Expand Up @@ -52,10 +53,16 @@ func fetchPrices(
for _, token := range tokenList {
if pricesLlama[token] != nil && !pricesLlama[token].IsZero() {
newPriceMap[token] = pricesLlama[token]
if addresses.Equals(`0x7F86Bf177Dd4F3494b841a37e810A34dD56c829B`, token) {
logs.Error(pricesLlama[token])
}
continue
}
if pricesGecko[token] != nil && !pricesGecko[token].IsZero() {
newPriceMap[token] = pricesGecko[token]
if addresses.Equals(`0x7F86Bf177Dd4F3494b841a37e810A34dD56c829B`, token) {
logs.Error(pricesGecko[token])
}
}
}

Expand Down Expand Up @@ -133,6 +140,7 @@ func fetchPrices(
for token, price := range priceMapLensOracle {
if !price.IsZero() && newPriceMap[token] == nil {
newPriceMap[token] = price

}
}

Expand Down

0 comments on commit b9ad218

Please sign in to comment.