Skip to content

Commit

Permalink
feat(feeds) adds support for non EVM chain configs
Browse files Browse the repository at this point in the history
  • Loading branch information
giogam committed Oct 11, 2024
1 parent 998bc27 commit 75cc6ed
Show file tree
Hide file tree
Showing 3 changed files with 396 additions and 180 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"

"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 75cc6ed

Please sign in to comment.