From 9c4952d7588555a6d4c4b5c9c0965a7fadbc4adf Mon Sep 17 00:00:00 2001 From: asoliman Date: Fri, 16 Aug 2024 18:29:46 +0400 Subject: [PATCH] Add decimals to offchain config Signed-off-by: asoliman --- commit/plugin.go | 2 +- commit/plugin_functions.go | 4 ++-- commit/plugin_functions_test.go | 2 +- internal/reader/onchain_prices_reader.go | 4 ++-- pluginconfig/commit.go | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/commit/plugin.go b/commit/plugin.go index cc4a1b84c..7cbd16d46 100644 --- a/commit/plugin.go +++ b/commit/plugin.go @@ -277,7 +277,7 @@ func (p *Plugin) Outcome( } p.lggr.Infow("new messages consensus", "merkleRoots", merkleRoots) - tokenPrices := tokenPricesConsensus(decodedObservations, fChainDest) + tokenPrices := tokenPricesMedianized(decodedObservations, fChainDest) gasPrices := gasPricesConsensus(p.lggr, decodedObservations, fChainDest) p.lggr.Infow("gas prices consensus", "gasPrices", gasPrices) diff --git a/commit/plugin_functions.go b/commit/plugin_functions.go index cca9751c0..ef04f0ba6 100644 --- a/commit/plugin_functions.go +++ b/commit/plugin_functions.go @@ -388,8 +388,8 @@ func maxSeqNumsConsensus( return seqNums } -// tokenPricesConsensus returns the median price for tokens that have at least 2f_chain+1 observations. -func tokenPricesConsensus(observations []plugintypes.CommitPluginObservation, fChain int) []cciptypes.TokenPrice { +// tokenPricesMedianized returns the median price for tokens that have at least 2f_chain+1 observations. +func tokenPricesMedianized(observations []plugintypes.CommitPluginObservation, fChain int) []cciptypes.TokenPrice { pricesPerToken := make(map[types.Account][]cciptypes.BigInt) for _, obs := range observations { for _, price := range obs.TokenPrices { diff --git a/commit/plugin_functions_test.go b/commit/plugin_functions_test.go index 5fc2c84f7..0db719758 100644 --- a/commit/plugin_functions_test.go +++ b/commit/plugin_functions_test.go @@ -1404,7 +1404,7 @@ func Test_tokenPricesConsensus(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - prices := tokenPricesConsensus(tc.observations, tc.fChain) + prices := tokenPricesMedianized(tc.observations, tc.fChain) assert.Equal(t, tc.expPrices, prices) }) } diff --git a/internal/reader/onchain_prices_reader.go b/internal/reader/onchain_prices_reader.go index f1802a204..a92188cf4 100644 --- a/internal/reader/onchain_prices_reader.go +++ b/internal/reader/onchain_prices_reader.go @@ -66,7 +66,7 @@ func (pr *OnchainTokenPricesReader) GetTokenPricesUSD( if err != nil { return fmt.Errorf("failed to get token price for %s: %w", token, err) } - decimals, err := pr.getTokenDecimals(ctx, token) + decimals, err := pr.getFeedDecimals(ctx, token) if err != nil { return fmt.Errorf("failed to get decimals for %s: %w", token, err) } @@ -111,7 +111,7 @@ func (pr *OnchainTokenPricesReader) getRawTokenPrice(ctx context.Context, token return latestRoundData.Answer, nil } -func (pr *OnchainTokenPricesReader) getTokenDecimals(ctx context.Context, token types.Account) (*uint8, error) { +func (pr *OnchainTokenPricesReader) getFeedDecimals(ctx context.Context, token types.Account) (*uint8, error) { var decimals *uint8 if err := pr.ContractReader.GetLatestValue( diff --git a/pluginconfig/commit.go b/pluginconfig/commit.go index c535a9aba..4e2aa51e3 100644 --- a/pluginconfig/commit.go +++ b/pluginconfig/commit.go @@ -94,7 +94,8 @@ type CommitOffchainConfig struct { // PriceSources is a map of Arbitrum price sources for each token. // Note that the token address is that on the remote chain. - PriceSources map[types.Account]ArbitrumPriceSource `json:"priceSources"` + PriceSources map[types.Account]ArbitrumPriceSource `json:"priceSources"` + TokenDecimals map[types.Account]uint8 `json:"decimals"` // TokenPriceChainSelector is the chain selector for the chain on which // the token prices are read from.