Skip to content

Commit 53e79f6

Browse files
committed
DF-21462 Move secure mint plugin interface to cl-common and looppify it
1 parent f23b9b5 commit 53e79f6

18 files changed

Lines changed: 2151 additions & 47 deletions

pkg/capabilities/consensus/ocr3/datafeeds/securemint_aggregator.go

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212

1313
chainselectors "github.com/smartcontractkit/chain-selectors"
1414
ocrcommon "github.com/smartcontractkit/libocr/commontypes"
15-
ocr2types "github.com/smartcontractkit/libocr/offchainreporting2/types"
1615
ocr3types "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
1716

1817
"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
1918
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/types"
2019
"github.com/smartcontractkit/chainlink-common/pkg/logger"
2120
"github.com/smartcontractkit/chainlink-common/pkg/types/chains/solana"
21+
"github.com/smartcontractkit/chainlink-common/pkg/types/core/securemint"
2222
"github.com/smartcontractkit/chainlink-protos/cre/go/values"
2323
)
2424

@@ -60,28 +60,17 @@ const (
6060
SolDataIDOutputFieldName = SolanaEncoderKey("dataId")
6161
)
6262

63-
// secureMintReport represents the inner report structure, mimics the Report type in the SM plugin repo
64-
type secureMintReport struct {
65-
ConfigDigest ocr2types.ConfigDigest `json:"configDigest"`
66-
SeqNr uint64 `json:"seqNr"`
67-
Block uint64 `json:"block"`
68-
Mintable *big.Int `json:"mintable"`
69-
}
70-
7163
type wrappedMintReport struct {
72-
Report secureMintReport `json:"report"`
64+
Report securemint.Report `json:"report"`
7365
SolanaAccountContext solana.AccountMetaSlice `json:"solanaAccountContext,omitempty"`
7466
}
7567

76-
// chainSelector represents the chain selector type, mimics the ChainSelector type in the SM plugin repo
77-
type chainSelector uint64
78-
7968
// SecureMintAggregatorConfig is the config for the SecureMint aggregator.
8069
// This aggregator is designed to pick out reports for a specific chain selector.
8170
type SecureMintAggregatorConfig struct {
8271
// TargetChainSelector is the chain selector to look for
83-
TargetChainSelector chainSelector `mapstructure:"targetChainSelector"`
84-
DataID [16]byte `mapstructure:"dataID"`
72+
TargetChainSelector securemint.ChainSelector `mapstructure:"targetChainSelector"`
73+
DataID [16]byte `mapstructure:"dataID"`
8574
}
8675

8776
// ToMap converts the SecureMintAggregatorConfig to a values.Map, which is suitable for the
@@ -107,13 +96,13 @@ type chainReportFormatter interface {
10796
}
10897

10998
type evmReportFormatter struct {
110-
targetChainSelector chainSelector
99+
targetChainSelector securemint.ChainSelector
111100
dataID [16]byte
112101
}
113102

114103
func (f *evmReportFormatter) packReport(lggr logger.Logger, wreport *wrappedMintReport) (*values.Map, error) {
115104
report := wreport.Report
116-
smReportAsAnswer, err := packSecureMintReportIntoUint224ForEVM(report.Mintable, report.Block)
105+
smReportAsAnswer, err := packSecureMintReportIntoUint224ForEVM(report.Mintable, uint64(report.Block))
117106
if err != nil {
118107
return nil, fmt.Errorf("failed to pack secure mint report for evm into uint224: %w", err)
119108
}
@@ -140,19 +129,19 @@ func (f *evmReportFormatter) packReport(lggr logger.Logger, wreport *wrappedMint
140129
return wrappedReport, nil
141130
}
142131

143-
func newEVMReportFormatter(chainSelector chainSelector, config SecureMintAggregatorConfig) chainReportFormatter {
132+
func newEVMReportFormatter(chainSelector securemint.ChainSelector, config SecureMintAggregatorConfig) chainReportFormatter {
144133
return &evmReportFormatter{targetChainSelector: chainSelector, dataID: config.DataID}
145134
}
146135

147136
type solanaReportFormatter struct {
148-
targetChainSelector chainSelector
137+
targetChainSelector securemint.ChainSelector
149138
dataID [16]byte
150139
}
151140

152141
func (f *solanaReportFormatter) packReport(lggr logger.Logger, wreport *wrappedMintReport) (*values.Map, error) {
153142
report := wreport.Report
154143
// pack answer
155-
smReportAsAnswer, err := packSecureMintReportIntoU128ForSolana(report.Mintable, report.Block)
144+
smReportAsAnswer, err := packSecureMintReportIntoU128ForSolana(report.Mintable, uint64(report.Block))
156145
if err != nil {
157146
return nil, fmt.Errorf("failed to pack secure mint report for solana into u128: %w", err)
158147
}
@@ -191,24 +180,24 @@ func (f *solanaReportFormatter) packReport(lggr logger.Logger, wreport *wrappedM
191180
return wrappedReport, nil
192181
}
193182

194-
func newSolanaReportFormatter(chainSelector chainSelector, config SecureMintAggregatorConfig) chainReportFormatter {
183+
func newSolanaReportFormatter(chainSelector securemint.ChainSelector, config SecureMintAggregatorConfig) chainReportFormatter {
195184
return &solanaReportFormatter{targetChainSelector: chainSelector, dataID: config.DataID}
196185
}
197186

198187
// chainReportFormatterBuilder is a function that returns a chainReportFormatter for a given chain selector and config
199-
type chainReportFormatterBuilder func(chainSelector chainSelector, config SecureMintAggregatorConfig) chainReportFormatter
188+
type chainReportFormatterBuilder func(chainSelector securemint.ChainSelector, config SecureMintAggregatorConfig) chainReportFormatter
200189

201190
type formatterFactory struct {
202-
builders map[chainSelector]chainReportFormatterBuilder
191+
builders map[securemint.ChainSelector]chainReportFormatterBuilder
203192
}
204193

205194
// register registers a new chain report formatter builder for a given chain selector
206-
func (r *formatterFactory) register(chSel chainSelector, builder chainReportFormatterBuilder) {
195+
func (r *formatterFactory) register(chSel securemint.ChainSelector, builder chainReportFormatterBuilder) {
207196
r.builders[chSel] = builder
208197
}
209198

210199
// get uses a chain report formatter builder to create a chain report formatter
211-
func (r *formatterFactory) get(chSel chainSelector, config SecureMintAggregatorConfig) (chainReportFormatter, error) {
200+
func (r *formatterFactory) get(chSel securemint.ChainSelector, config SecureMintAggregatorConfig) (chainReportFormatter, error) {
212201
b, ok := r.builders[chSel]
213202
if !ok {
214203
return nil, fmt.Errorf("no formatter registered for chain selector: %d", chSel)
@@ -220,17 +209,17 @@ func (r *formatterFactory) get(chSel chainSelector, config SecureMintAggregatorC
220209
// newFormatterFactory collects all chain report formatters per chain family so that they can be used to pack reports for different chains
221210
func newFormatterFactory() *formatterFactory {
222211
r := formatterFactory{
223-
builders: map[chainSelector]chainReportFormatterBuilder{},
212+
builders: map[securemint.ChainSelector]chainReportFormatterBuilder{},
224213
}
225214

226215
// EVM
227216
for _, selector := range chainselectors.EvmChainIdToChainSelector() {
228-
r.register(chainSelector(selector), newEVMReportFormatter)
217+
r.register(securemint.ChainSelector(selector), newEVMReportFormatter)
229218
}
230219

231220
// Solana
232221
for _, selector := range chainselectors.SolanaChainIdToChainSelector() {
233-
r.register(chainSelector(selector), newSolanaReportFormatter)
222+
r.register(securemint.ChainSelector(selector), newSolanaReportFormatter)
234223
}
235224

236225
return &r
@@ -320,7 +309,7 @@ func (a *SecureMintAggregator) extractAndValidateReports(lggr logger.Logger, obs
320309
lggr.Debugw("Obs with context", "obs with ctx", obsWithContext)
321310

322311
// Deserialize the ReportWithInfo
323-
var reportWithInfo ocr3types.ReportWithInfo[chainSelector]
312+
var reportWithInfo ocr3types.ReportWithInfo[securemint.ChainSelector]
324313
if err := json.Unmarshal(obsWithContext.Event.Report, &reportWithInfo); err != nil {
325314
lggr.Errorw("failed to unmarshal ReportWithInfo", "err", err)
326315
continue
@@ -336,9 +325,9 @@ func (a *SecureMintAggregator) extractAndValidateReports(lggr logger.Logger, obs
336325
foundMatchingChainSelector = true
337326

338327
// Deserialize the inner secureMintReport
339-
var innerReport secureMintReport
328+
var innerReport securemint.Report
340329
if err := json.Unmarshal(reportWithInfo.Report, &innerReport); err != nil {
341-
lggr.Errorw("failed to unmarshal secureMintReport", "err", err)
330+
lggr.Errorw("failed to unmarshal securemint.Report", "err", err)
342331
continue
343332
}
344333
report := &wrappedMintReport{
@@ -432,7 +421,7 @@ func parseSecureMintConfig(config values.Map) (SecureMintAggregatorConfig, error
432421
}
433422

434423
parsedConfig := SecureMintAggregatorConfig{
435-
TargetChainSelector: chainSelector(sel),
424+
TargetChainSelector: securemint.ChainSelector(sel),
436425
DataID: [16]byte(decodedDataID),
437426
}
438427

pkg/capabilities/consensus/ocr3/datafeeds/securemint_aggregator_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/types"
1515
"github.com/smartcontractkit/chainlink-common/pkg/logger"
1616
"github.com/smartcontractkit/chainlink-common/pkg/types/chains/solana"
17+
"github.com/smartcontractkit/chainlink-common/pkg/types/core/securemint"
1718
ocrcommon "github.com/smartcontractkit/libocr/commontypes"
1819
ocr2types "github.com/smartcontractkit/libocr/offchainreporting2/types"
1920
ocr3types "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
@@ -23,9 +24,9 @@ import (
2324

2425
var (
2526
// Test chain selectors
26-
ethSepoliaChainSelector = chainSelector(16015286601757825753) // Ethereum Sepolia testnet
27-
bnbTestnetChainSelector = chainSelector(13264668187771770619) // Binance Smart Chain testnet
28-
solDevnetChainSelector = chainSelector(16423721717087811551) // Solana devnet
27+
ethSepoliaChainSelector = securemint.ChainSelector(16015286601757825753) // Ethereum Sepolia testnet
28+
bnbTestnetChainSelector = securemint.ChainSelector(13264668187771770619) // Binance Smart Chain testnet
29+
solDevnetChainSelector = securemint.ChainSelector(16423721717087811551) // Solana devnet
2930
)
3031

3132
func TestSecureMintAggregator_Aggregate(t *testing.T) {
@@ -114,7 +115,7 @@ func TestSecureMintAggregator_Aggregate(t *testing.T) {
114115
{
115116
chainSelector: ethSepoliaChainSelector,
116117
seqNr: 10,
117-
report: &secureMintReport{
118+
report: &securemint.Report{
118119
ConfigDigest: ocr2types.ConfigDigest{0: 1, 31: 2},
119120
SeqNr: 10,
120121
Block: 1000,
@@ -124,7 +125,7 @@ func TestSecureMintAggregator_Aggregate(t *testing.T) {
124125
{
125126
chainSelector: bnbTestnetChainSelector,
126127
seqNr: 10,
127-
report: &secureMintReport{
128+
report: &securemint.Report{
128129
ConfigDigest: ocr2types.ConfigDigest{0: 2, 31: 3},
129130
SeqNr: 10,
130131
Block: 1100,
@@ -146,7 +147,7 @@ func TestSecureMintAggregator_Aggregate(t *testing.T) {
146147
{
147148
chainSelector: bnbTestnetChainSelector,
148149
seqNr: 10,
149-
report: &secureMintReport{
150+
report: &securemint.Report{
150151
ConfigDigest: ocr2types.ConfigDigest{0: 1, 31: 2},
151152
SeqNr: 10,
152153
Block: 1000,
@@ -179,7 +180,7 @@ func TestSecureMintAggregator_Aggregate(t *testing.T) {
179180
{
180181
chainSelector: solDevnetChainSelector,
181182
seqNr: 10,
182-
report: &secureMintReport{
183+
report: &securemint.Report{
183184
ConfigDigest: ocr2types.ConfigDigest{0: 1, 31: 2},
184185
SeqNr: 10,
185186
Block: 1000,
@@ -190,7 +191,7 @@ func TestSecureMintAggregator_Aggregate(t *testing.T) {
190191
{
191192
chainSelector: bnbTestnetChainSelector,
192193
seqNr: 10,
193-
report: &secureMintReport{
194+
report: &securemint.Report{
194195
ConfigDigest: ocr2types.ConfigDigest{0: 2, 31: 3},
195196
SeqNr: 10,
196197
Block: 1100,
@@ -268,7 +269,7 @@ func TestSecureMintAggregatorConfig_Validation(t *testing.T) {
268269
chainSelector string
269270
dataID string
270271
solanaAccounts solana.AccountMetaSlice
271-
expectedChainSelector chainSelector
272+
expectedChainSelector securemint.ChainSelector
272273
expectedDataID [16]byte
273274
expectError bool
274275
errorMsg string
@@ -374,9 +375,9 @@ func TestSecureMintAggregatorConfig_Validation(t *testing.T) {
374375
// Helper types and functions
375376

376377
type ocrTriggerEventData struct {
377-
chainSelector chainSelector
378+
chainSelector securemint.ChainSelector
378379
seqNr uint64
379-
report *secureMintReport
380+
report *securemint.Report
380381
accCtx solana.AccountMetaSlice
381382
}
382383

@@ -389,7 +390,7 @@ func createSecureMintObservations(t *testing.T, events []ocrTriggerEventData) ma
389390
var oracleObservations []values.Value
390391
for _, event := range events {
391392
// Create the ReportWithInfo
392-
ocr3Report := &ocr3types.ReportWithInfo[chainSelector]{
393+
ocr3Report := &ocr3types.ReportWithInfo[securemint.ChainSelector]{
393394
Report: createReportBytes(t, event.report),
394395
Info: event.chainSelector,
395396
}
@@ -430,7 +431,7 @@ func createSecureMintObservations(t *testing.T, events []ocrTriggerEventData) ma
430431
return observations
431432
}
432433

433-
func createReportBytes(t *testing.T, report *secureMintReport) []byte {
434+
func createReportBytes(t *testing.T, report *securemint.Report) []byte {
434435
reportBytes, err := json.Marshal(report)
435436
require.NoError(t, err)
436437
return reportBytes

pkg/loop/internal/pb/reporting_plugin_service.pb.go

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/loop/internal/pb/reporting_plugin_service.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ message NewReportingPluginFactoryRequest {
3535
uint32 capRegistryID = 6;
3636
uint32 keyValueStoreID = 7;
3737
uint32 relayerSetID = 8;
38+
uint32 secureMintExternalAdapterID = 9;
3839
}
3940

4041
// NewReportingPluginFactoryReply has return arguments for [github.com/smartcontractkit/chainlink-common/pkg/loop/reporting_plugins/LOOPPService.NewReportingPluginFactory].

0 commit comments

Comments
 (0)