Skip to content

Commit

Permalink
fixing import cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhuie19 committed Sep 24, 2024
1 parent db4ec4c commit f1a505c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
3 changes: 1 addition & 2 deletions core/gethwrappers/go_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

cutils "github.com/smartcontractkit/chainlink-common/pkg/utils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip"
"github.com/smartcontractkit/chainlink/v2/core/utils"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -58,7 +57,7 @@ func TestCheckContractHashesFromLastGoGenerate(t *testing.T) {
}

func isOCRContract(fullpath string) bool {
return strings.Contains(fullpath, ccip.OFFCHAIN_AGGREGATOR)
return strings.Contains(fullpath, "OffchainAggregator")
}

// VRFv2 currently uses revert error types which are not supported by abigen
Expand Down
39 changes: 18 additions & 21 deletions core/services/ocr2/plugins/ccip/internal/pricegetter/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,31 @@ import (
"math/big"
"strings"

"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/aggregator_v3_interface"

"go.uber.org/multierr"

"github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/rpclib"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"go.uber.org/multierr"

"github.com/smartcontractkit/chainlink-common/pkg/types"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/aggregator_v3_interface"
"github.com/smartcontractkit/chainlink/v2/core/internal/gethwrappers2/generated/offchainaggregator"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipcalc"
"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"

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, ccip.DECIMALS_METHOD_NAME)
ensureMethodOnContract(aggregatorABI, ccip.LATEST_ROUND_DATA_METHOD_NAME)
ensureMethodOnContract(aggregatorABI, DECIMALS_METHOD_NAME)
ensureMethodOnContract(aggregatorABI, LATEST_ROUND_DATA_METHOD_NAME)
}

func ensureMethodOnContract(abi abi.ABI, methodName string) {
Expand Down Expand Up @@ -162,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", ccip.OFFCHAIN_AGGREGATOR, i),
Name: fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i),
})
}

Expand All @@ -175,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", ccip.OFFCHAIN_AGGREGATOR, i)
contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i)
batchGetLatestValuesRequest[contractName] = append(batchGetLatestValuesRequest[contractName], types.BatchRead{
ReadName: call.MethodName(),
ReturnVal: &decimalsReq,
})
}

for i, call := range batchCalls.latestRoundDataCalls {
contractName := fmt.Sprintf("%v_%v", ccip.OFFCHAIN_AGGREGATOR, i)
contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i)
batchGetLatestValuesRequest[contractName] = append(batchGetLatestValuesRequest[contractName], types.BatchRead{
ReadName: call.MethodName(),
ReturnVal: &aggregator_v3_interface.LatestRoundData{},
Expand All @@ -203,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", ccip.OFFCHAIN_AGGREGATOR, j)
contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, j)
offchainAggregatorRespSlice := result[contractName]

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

decimalsCR = append(decimalsCR, *decimal)
} else if read.ReadName == ccip.LATEST_ROUND_DATA_METHOD_NAME {
} else if read.ReadName == LATEST_ROUND_DATA_METHOD_NAME {
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[i/2].MethodName(), batchCalls.latestRoundDataCalls[i/2].ContractAddress(), readErr)
Expand Down Expand Up @@ -274,12 +271,12 @@ func (d *DynamicPriceGetter) preparePricesAndBatchCallsPerChain(tokens []cciptyp
chainCalls := batchCallsPerChain[aggCfg.ChainID]
chainCalls.decimalCalls = append(chainCalls.decimalCalls, rpclib.NewEvmCall(
d.aggregatorAbi,
ccip.DECIMALS_METHOD_NAME,
DECIMALS_METHOD_NAME,
aggCfg.AggregatorContractAddress,
))
chainCalls.latestRoundDataCalls = append(chainCalls.latestRoundDataCalls, rpclib.NewEvmCall(
d.aggregatorAbi,
ccip.LATEST_ROUND_DATA_METHOD_NAME,
LATEST_ROUND_DATA_METHOD_NAME,
aggCfg.AggregatorContractAddress,
))
chainCalls.tokenOrder = append(chainCalls.tokenOrder, tk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ func mockCR(t *testing.T, decimals []uint8, rounds []aggregator_v3_interface.Lat
for i, d := range decimals {
contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i)
readRes := types.BatchReadResult{
ReadName: decimalsMethodName,
ReadName: DECIMALS_METHOD_NAME,
}
readRes.SetResult(&d, nil)
bGLVR[contractName] = append(bGLVR[contractName], readRes)
Expand All @@ -846,7 +846,7 @@ func mockCR(t *testing.T, decimals []uint8, rounds []aggregator_v3_interface.Lat
for i, r := range rounds {
contractName := fmt.Sprintf("%v_%v", OFFCHAIN_AGGREGATOR, i)
readRes := types.BatchReadResult{
ReadName: latestRoundDataMethodName,
ReadName: LATEST_ROUND_DATA_METHOD_NAME,
}
readRes.SetResult(&r, nil)
bGLVR[contractName] = append(bGLVR[contractName], readRes)
Expand Down

0 comments on commit f1a505c

Please sign in to comment.