Skip to content

Commit

Permalink
Feature/commit init no evm followups (#1472)
Browse files Browse the repository at this point in the history
## Motivation
Quick follow ups to #1361
  • Loading branch information
patrickhuie19 authored Oct 2, 2024
1 parent bd22732 commit 5aee339
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 112 deletions.
13 changes: 10 additions & 3 deletions core/services/ocr2/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,15 @@ func (d *Delegate) newServicesCCIPCommit(ctx context.Context, lggr logger.Sugare
MetricsRegisterer: prometheus.WrapRegistererWith(map[string]string{"job_name": jb.Name.ValueOrZero()}, prometheus.DefaultRegisterer),
}

var priceGetter ccip.AllTokensPriceGetter
priceGetter, err := d.ccipCommitPriceGetter(ctx, lggr, pluginJobSpecConfig, jb)
if err != nil {
return nil, fmt.Errorf("failed to create price getter: %w", err)
}
return ccipcommit.NewCommitServices(ctx, d.ds, srcProvider, dstProvider, priceGetter, jb, lggr, d.pipelineRunner, oracleArgsNoPlugin, d.isNewlyCreatedJob, int64(srcChainID), dstChainID, logError)
}

func (d *Delegate) ccipCommitPriceGetter(ctx context.Context, lggr logger.SugaredLogger, pluginJobSpecConfig ccipconfig.CommitPluginJobSpecConfig, jb job.Job) (priceGetter ccip.AllTokensPriceGetter, err error) {
spec := jb.OCR2OracleSpec
withPipeline := strings.Trim(pluginJobSpecConfig.TokenPricesUSDPipeline, "\n\t ") != ""
if withPipeline {
priceGetter, err = ccip.NewPipelineGetter(pluginJobSpecConfig.TokenPricesUSDPipeline, d.pipelineRunner, jb.ID, jb.ExternalJobID, jb.Name.ValueOrZero(), lggr)
Expand Down Expand Up @@ -1685,8 +1693,7 @@ func (d *Delegate) newServicesCCIPCommit(ctx context.Context, lggr logger.Sugare
return nil, fmt.Errorf("creating dynamic price getter: %w", err)
}
}

return ccipcommit.NewCommitServices(ctx, d.ds, srcProvider, dstProvider, priceGetter, jb, lggr, d.pipelineRunner, oracleArgsNoPlugin, d.isNewlyCreatedJob, int64(srcChainID), dstChainID, logError)
return priceGetter, nil
}

func newCCIPCommitPluginBytes(isSourceProvider bool, sourceStartBlock uint64, destStartBlock uint64) config.CommitPluginConfig {
Expand Down
26 changes: 13 additions & 13 deletions core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/rpclib"
)

const OFFCHAIN_AGGREGATOR = "OffchainAggregator"
const DECIMALS_METHOD_NAME = "decimals"
const LATEST_ROUND_DATA_METHOD_NAME = "latestRoundData"
const OffchainAggregator = "OffchainAggregator"
const DecimalsMethodName = "decimals"
const LatestRoundDataMethodName = "latestRoundData"

func init() {
// Ensure existence of latestRoundData method on the Aggregator contract.
aggregatorABI, err := abi.JSON(strings.NewReader(offchainaggregator.OffchainAggregatorABI))
if err != nil {
panic(err)
}
ensureMethodOnContract(aggregatorABI, DECIMALS_METHOD_NAME)
ensureMethodOnContract(aggregatorABI, LATEST_ROUND_DATA_METHOD_NAME)
ensureMethodOnContract(aggregatorABI, DecimalsMethodName)
ensureMethodOnContract(aggregatorABI, LatestRoundDataMethodName)
}

func ensureMethodOnContract(abi abi.ABI, methodName string) {
Expand Down Expand Up @@ -159,7 +159,7 @@ func (d *DynamicPriceGetter) performBatchCall(ctx context.Context, chainID uint6
for i, call := range batchCalls.decimalCalls {
bindings = append(bindings, types.BoundContract{
Address: string(ccipcalc.EvmAddrToGeneric(call.ContractAddress())),
Name: fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i),
Name: fmt.Sprintf("%v_%v", OffchainAggregator, i),
})
}

Expand All @@ -172,15 +172,15 @@ func (d *DynamicPriceGetter) performBatchCall(ctx context.Context, chainID uint6
var decimalsReq uint8
batchGetLatestValuesRequest := make(map[string]types.ContractBatch)
for i, call := range batchCalls.decimalCalls {
contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i)
contractName := fmt.Sprintf("%v_%v", OffchainAggregator, i)
batchGetLatestValuesRequest[contractName] = append(batchGetLatestValuesRequest[contractName], types.BatchRead{
ReadName: call.MethodName(),
ReturnVal: &decimalsReq,
})
}

for i, call := range batchCalls.latestRoundDataCalls {
contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i)
contractName := fmt.Sprintf("%v_%v", OffchainAggregator, i)
batchGetLatestValuesRequest[contractName] = append(batchGetLatestValuesRequest[contractName], types.BatchRead{
ReadName: call.MethodName(),
ReturnVal: &aggregator_v3_interface.LatestRoundData{},
Expand All @@ -200,7 +200,7 @@ func (d *DynamicPriceGetter) performBatchCall(ctx context.Context, chainID uint6
latestRoundCR := make([]aggregator_v3_interface.LatestRoundData, 0, nbDecimalCalls)
var respErr error
for j := range nbCalls {
contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, j)
contractName := fmt.Sprintf("%v_%v", OffchainAggregator, j)
offchainAggregatorRespSlice := result[contractName]

for _, read := range offchainAggregatorRespSlice {
Expand All @@ -209,14 +209,14 @@ func (d *DynamicPriceGetter) performBatchCall(ctx context.Context, chainID uint6
respErr = multierr.Append(respErr, fmt.Errorf("error with contract reader readName %v: %w", read.ReadName, readErr))
continue
}
if read.ReadName == DECIMALS_METHOD_NAME {
if read.ReadName == DecimalsMethodName {
decimal, ok := val.(*uint8)
if !ok {
return fmt.Errorf("expected type uint8 for method call %v on contract %v: %w", batchCalls.decimalCalls[j].MethodName(), batchCalls.decimalCalls[j].ContractAddress(), readErr)
}

decimalsCR = append(decimalsCR, *decimal)
} else if read.ReadName == LATEST_ROUND_DATA_METHOD_NAME {
} else if read.ReadName == LatestRoundDataMethodName {
latestRoundDataRes, ok := val.(*aggregator_v3_interface.LatestRoundData)
if !ok {
return fmt.Errorf("expected type latestRoundDataConfig for method call %v on contract %v: %w", batchCalls.latestRoundDataCalls[j].MethodName(), batchCalls.latestRoundDataCalls[j].ContractAddress(), readErr)
Expand Down Expand Up @@ -271,12 +271,12 @@ func (d *DynamicPriceGetter) preparePricesAndBatchCallsPerChain(tokens []cciptyp
chainCalls := batchCallsPerChain[aggCfg.ChainID]
chainCalls.decimalCalls = append(chainCalls.decimalCalls, rpclib.NewEvmCall(
d.aggregatorAbi,
DECIMALS_METHOD_NAME,
DecimalsMethodName,
aggCfg.AggregatorContractAddress,
))
chainCalls.latestRoundDataCalls = append(chainCalls.latestRoundDataCalls, rpclib.NewEvmCall(
d.aggregatorAbi,
LATEST_ROUND_DATA_METHOD_NAME,
LatestRoundDataMethodName,
aggCfg.AggregatorContractAddress,
))
chainCalls.tokenOrder = append(chainCalls.tokenOrder, tk)
Expand Down
Loading

0 comments on commit 5aee339

Please sign in to comment.