-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
util.go
144 lines (120 loc) · 4.82 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package ocr2keeper
import (
"fmt"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
ocr2keepers20 "github.com/smartcontractkit/ocr2keepers/pkg/v2"
ocr2keepers20coordinator "github.com/smartcontractkit/ocr2keepers/pkg/v2/coordinator"
ocr2keepers20polling "github.com/smartcontractkit/ocr2keepers/pkg/v2/observer/polling"
ocr2keepers20runner "github.com/smartcontractkit/ocr2keepers/pkg/v2/runner"
"github.com/smartcontractkit/sqlx"
"github.com/smartcontractkit/chainlink-relay/pkg/types"
ocr2keepers21 "github.com/smartcontractkit/ocr2keepers/pkg/v3/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models"
kevm20 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evm20"
kevm21 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evm21"
kevm21transmit "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evm21/transmit"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
)
type Encoder20 interface {
ocr2keepers20.Encoder
ocr2keepers20coordinator.Encoder
ocr2keepers20polling.Encoder
ocr2keepers20runner.Encoder
ocr2keepers20coordinator.Encoder
}
type Encoder21 interface {
ocr2keepers21.Encoder
}
var (
ErrNoChainFromSpec = fmt.Errorf("could not create chain from spec")
)
func EVMProvider(db *sqlx.DB, chain evm.Chain, lggr logger.Logger, spec job.Job, pr pipeline.Runner) (evmrelay.OCR2KeeperProvider, error) {
oSpec := spec.OCR2OracleSpec
ocr2keeperRelayer := evmrelay.NewOCR2KeeperRelayer(db, chain, pr, spec, lggr.Named("OCR2KeeperRelayer"))
keeperProvider, err := ocr2keeperRelayer.NewOCR2KeeperProvider(
types.RelayArgs{
ExternalJobID: spec.ExternalJobID,
JobID: oSpec.ID,
ContractID: oSpec.ContractID,
RelayConfig: oSpec.RelayConfig.Bytes(),
},
types.PluginArgs{
TransmitterID: oSpec.TransmitterID.String,
PluginConfig: oSpec.PluginConfig.Bytes(),
},
)
if err != nil {
return nil, fmt.Errorf("%w: failed to create new ocr2keeper provider", err)
}
return keeperProvider, nil
}
func EVMDependencies20(
spec job.Job,
db *sqlx.DB,
lggr logger.Logger,
chain evm.Chain,
pr pipeline.Runner,
) (evmrelay.OCR2KeeperProvider, *kevm20.EvmRegistry, Encoder20, *kevm20.LogProvider, error) {
var err error
var keeperProvider evmrelay.OCR2KeeperProvider
var registry *kevm20.EvmRegistry
// the provider will be returned as a dependency
if keeperProvider, err = EVMProvider(db, chain, lggr, spec, pr); err != nil {
return nil, nil, nil, nil, err
}
rAddr := ethkey.MustEIP55Address(spec.OCR2OracleSpec.ContractID).Address()
if registry, err = kevm20.NewEVMRegistryService(rAddr, chain, lggr); err != nil {
return nil, nil, nil, nil, err
}
encoder := kevm20.EVMAutomationEncoder20{}
// lookback blocks is hard coded and should provide ample time for logs
// to be detected in most cases
var lookbackBlocks int64 = 250
// TODO: accept a version of the registry contract and use the correct interfaces
logProvider, err := kevm20.NewLogProvider(lggr, chain.LogPoller(), rAddr, chain.Client(), lookbackBlocks)
return keeperProvider, registry, encoder, logProvider, err
}
func FilterNamesFromSpec20(spec *job.OCR2OracleSpec) (names []string, err error) {
addr, err := ethkey.NewEIP55Address(spec.ContractID)
if err != nil {
return nil, err
}
return []string{kevm20.LogProviderFilterName(addr.Address()), kevm20.UpkeepFilterName(addr.Address())}, err
}
func EVMDependencies21(
spec job.Job,
db *sqlx.DB,
lggr logger.Logger,
chain evm.Chain,
pr pipeline.Runner,
mc *models.MercuryCredentials,
keyring ocrtypes.OnchainKeyring,
dbCfg pg.QConfig,
) (evmrelay.OCR2KeeperProvider, kevm21.AutomationServices, error) {
var err error
var keeperProvider evmrelay.OCR2KeeperProvider
oSpec := spec.OCR2OracleSpec
// the provider will be returned as a dependency
if keeperProvider, err = EVMProvider(db, chain, lggr, spec, pr); err != nil {
return nil, nil, err
}
rAddr := ethkey.MustEIP55Address(oSpec.ContractID).Address()
services, err := kevm21.New(rAddr, chain, mc, keyring, lggr, db, dbCfg)
if err != nil {
return nil, nil, err
}
return keeperProvider, services, err
}
func FilterNamesFromSpec21(spec *job.OCR2OracleSpec) (names []string, err error) {
addr, err := ethkey.NewEIP55Address(spec.ContractID)
if err != nil {
return nil, err
}
return []string{kevm21transmit.EventProviderFilterName(addr.Address()), kevm21.RegistryUpkeepFilterName(addr.Address())}, err
}