github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/pricing/pricing.go (about) 1 package pricing 2 3 import ( 4 "fmt" 5 6 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 7 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 10 ) 11 12 // TODO: Much of this reporting could be removed as it's only used for debugging 13 14 // PriceUsd returns the price of the asset in USD 15 func PriceUsd(conn *rpc.Connection, statement *types.Statement) (price base.Float, source string, err error) { 16 if statement.IsStableCoin() { 17 r := priceDebugger{ 18 address: statement.AssetAddr, 19 symbol: statement.AssetSymbol, 20 } 21 r.report("stable-coin") 22 return 1.0, "stable-coin", nil 23 } 24 25 if statement.BlockNumber <= uniswapFactoryV2_deployed { 26 if statement.IsEth() { 27 return priceUsdMaker(conn, statement) 28 } else { 29 msg := fmt.Sprintf("Block %d is prior to deployment (%d) of Uniswap V2. No other source for tokens prior to UniSwap", statement.BlockNumber, uniswapFactoryV2_deployed) 30 logger.TestLog(true, msg) 31 return 0.0, "token-not-priced-pre-uni", nil 32 } 33 } 34 35 return priceUsdUniswap(conn, statement) 36 }