Skip to content

Commit

Permalink
Add decimals to offchain config
Browse files Browse the repository at this point in the history
Signed-off-by: asoliman <[email protected]>
  • Loading branch information
asoliman92 committed Aug 16, 2024
1 parent 2b55c95 commit 9c4952d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion commit/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions commit/plugin_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion commit/plugin_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/reader/onchain_prices_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion pluginconfig/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9c4952d

Please sign in to comment.