Skip to content

Commit

Permalink
feat(feeds) adds support for non EVM chain configs (#14731)
Browse files Browse the repository at this point in the history
* feat(feeds) adds support for non EVM chain configs

* feat(feeds) add multichain to Test_CreateFeedsManagerChainConfig tests

* feat(feeds): adds tests for aptos chain configs

* chore(feeds): update mocks

---------

Co-authored-by: James Kong <[email protected]>
  • Loading branch information
giogam and jkongie authored Oct 14, 2024
1 parent 2a47a4d commit 44daea3
Show file tree
Hide file tree
Showing 4 changed files with 548 additions and 205 deletions.
16 changes: 16 additions & 0 deletions core/services/feeds/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/pkg/errors"
"gopkg.in/guregu/null.v4"

proto "github.com/smartcontractkit/chainlink/v2/core/services/feeds/proto"
"github.com/smartcontractkit/chainlink/v2/core/utils/crypto"
)

Expand Down Expand Up @@ -77,7 +78,9 @@ type ChainType string

const (
ChainTypeUnknown ChainType = "UNKNOWN"
ChainTypeAptos ChainType = "APTOS"
ChainTypeEVM ChainType = "EVM"
ChainTypeSolana ChainType = "SOLANA"
ChainTypeStarknet ChainType = "STARKNET"
)

Expand All @@ -87,11 +90,24 @@ func NewChainType(s string) (ChainType, error) {
return ChainTypeEVM, nil
case "STARKNET":
return ChainTypeStarknet, nil
case "SOLANA":
return ChainTypeSolana, nil
case "APTOS":
return ChainTypeAptos, nil
default:
return ChainTypeUnknown, errors.New("invalid chain type")
}
}

// ChainTypeToProtoChainType converts a ChainType to a proto.ChainType.
func ChainTypeToProtoChainType(chainType ChainType) proto.ChainType {
prefixed := "CHAIN_TYPE_" + string(chainType)
if chainType, exists := proto.ChainType_value[prefixed]; exists {
return proto.ChainType(chainType)
}
return proto.ChainType_CHAIN_TYPE_UNSPECIFIED
}

// FeedsManager defines a registered Feeds Manager Service and the connection
// information.
type FeedsManager struct {
Expand Down
8 changes: 4 additions & 4 deletions core/services/feeds/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1225,9 +1225,9 @@ func (s *service) generateJob(ctx context.Context, spec string) (*job.Job, error

// newChainConfigMsg generates a chain config protobuf message.
func (s *service) newChainConfigMsg(cfg ChainConfig) (*pb.ChainConfig, error) {
// Only supports EVM Chains
if cfg.ChainType != "EVM" {
return nil, errors.New("unsupported chain type")
protoChainType := ChainTypeToProtoChainType(cfg.ChainType)
if protoChainType == pb.ChainType_CHAIN_TYPE_UNSPECIFIED {
return nil, errors.Errorf("unsupported chain type: %s", cfg.ChainType)
}

ocr1Cfg, err := s.newOCR1ConfigMsg(cfg.OCR1Config)
Expand All @@ -1243,7 +1243,7 @@ func (s *service) newChainConfigMsg(cfg ChainConfig) (*pb.ChainConfig, error) {
pbChainConfig := pb.ChainConfig{
Chain: &pb.Chain{
Id: cfg.ChainID,
Type: pb.ChainType_CHAIN_TYPE_EVM,
Type: protoChainType,
},
AccountAddress: cfg.AccountAddress,
AdminAddress: cfg.AdminAddress,
Expand Down
Loading

0 comments on commit 44daea3

Please sign in to comment.