-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
util.go
123 lines (101 loc) · 4.42 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
package ocr2keeper
import (
"fmt"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/jmoiron/sqlx"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
ocr2keepers20 "github.com/smartcontractkit/chainlink-automation/pkg/v2"
ocr2keepers20coordinator "github.com/smartcontractkit/chainlink-automation/pkg/v2/coordinator"
ocr2keepers20polling "github.com/smartcontractkit/chainlink-automation/pkg/v2/observer/polling"
ocr2keepers20runner "github.com/smartcontractkit/chainlink-automation/pkg/v2/runner"
ocr2keepers21 "github.com/smartcontractkit/chainlink-common/pkg/types/automation"
"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm"
"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"
evmregistry20 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v20"
evmregistry21 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21"
evmregistry21transmit "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/transmit"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
)
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 legacyevm.Chain, lggr logger.Logger, spec job.Job, ethKeystore keystore.Eth, dbCfg pg.QConfig) (evmrelay.OCR2KeeperProvider, error) {
oSpec := spec.OCR2OracleSpec
ocr2keeperRelayer := evmrelay.NewOCR2KeeperRelayer(db, chain, lggr.Named("OCR2KeeperRelayer"), ethKeystore, dbCfg)
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 legacyevm.Chain,
ethKeystore keystore.Eth,
dbCfg pg.QConfig,
) (evmrelay.OCR2KeeperProvider, *evmregistry20.EvmRegistry, Encoder20, *evmregistry20.LogProvider, error) {
var err error
var keeperProvider evmrelay.OCR2KeeperProvider
var registry *evmregistry20.EvmRegistry
// the provider will be returned as a dependency
if keeperProvider, err = EVMProvider(db, chain, lggr, spec, ethKeystore, dbCfg); err != nil {
return nil, nil, nil, nil, err
}
rAddr := ethkey.MustEIP55Address(spec.OCR2OracleSpec.ContractID).Address()
if registry, err = evmregistry20.NewEVMRegistryService(rAddr, chain, lggr); err != nil {
return nil, nil, nil, nil, err
}
encoder := evmregistry20.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 := evmregistry20.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{evmregistry20.LogProviderFilterName(addr.Address()), evmregistry20.UpkeepFilterName(addr.Address())}, err
}
func EVMDependencies21(
keyring ocrtypes.OnchainKeyring,
) (evmregistry21.AutomationServices, error) {
return evmregistry21.New(keyring)
}
func FilterNamesFromSpec21(spec *job.OCR2OracleSpec) (names []string, err error) {
addr, err := ethkey.NewEIP55Address(spec.ContractID)
if err != nil {
return nil, err
}
return []string{evmregistry21transmit.EventProviderFilterName(addr.Address()), evmregistry21.RegistryUpkeepFilterName(addr.Address())}, err
}