-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathethereum_keeper_contracts.go
272 lines (244 loc) · 11.8 KB
/
ethereum_keeper_contracts.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package contracts
import (
"context"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
goabi "github.com/umbracle/ethgo/abi"
"github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
cltypes "github.com/smartcontractkit/chainlink-integrations/evm/types"
ac "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_compatible_utils"
registrar21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_registrar_wrapper2_1"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_automation_registry_master_wrapper_2_2"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_automation_registry_master_wrapper_2_3"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1"
)
var compatibleUtils = cltypes.MustGetABI(ac.AutomationCompatibleUtilsABI)
var registrarABI = cltypes.MustGetABI(registrar21.AutomationRegistrarABI)
type KeeperRegistrar interface {
Address() string
EncodeRegisterRequest(name string, email []byte, upkeepAddr string, gasLimit uint32, adminAddr string, checkData []byte, amount *big.Int, source uint8, senderAddr string, isLogTrigger bool, isMercury bool, linkTokenAddr string) ([]byte, error)
Fund(ethAmount *big.Float) error
RegisterUpkeepFromKey(keyNum int, name string, email []byte, upkeepAddr string, gasLimit uint32, adminAddr string, checkData []byte, amount *big.Int, wethTokenAddr string, isLogTrigger bool, isMercury bool) (*types.Transaction, error)
}
type UpkeepTranscoder interface {
Address() string
}
type KeeperRegistry interface {
Address() string
Fund(ethAmount *big.Float) error
SetConfig(config KeeperRegistrySettings, ocrConfig OCRv2Config) error
SetConfigTypeSafe(ocrConfig OCRv2Config) error
SetRegistrar(registrarAddr string) error
AddUpkeepFunds(id *big.Int, amount *big.Int) error
AddUpkeepFundsFromKey(id *big.Int, amount *big.Int, keyNum int) error
GetUpkeepInfo(ctx context.Context, id *big.Int) (*UpkeepInfo, error)
GetKeeperInfo(ctx context.Context, keeperAddr string) (*KeeperInfo, error)
SetKeepers(keepers []string, payees []string, ocrConfig OCRv2Config) error
GetKeeperList(ctx context.Context) ([]string, error)
RegisterUpkeep(target string, gasLimit uint32, admin string, checkData []byte) error
CancelUpkeep(id *big.Int) error
SetUpkeepGasLimit(id *big.Int, gas uint32) error
ParseUpkeepPerformedLog(log *types.Log) (*UpkeepPerformedLog, error)
ParseStaleUpkeepReportLog(log *types.Log) (*StaleUpkeepReportLog, error)
ParseUpkeepIdFromRegisteredLog(log *types.Log) (*big.Int, error)
Pause() error
Migrate(upkeepIDs []*big.Int, destinationAddress common.Address) error
SetMigrationPermissions(peerAddress common.Address, permission uint8) error
PauseUpkeep(id *big.Int) error
UnpauseUpkeep(id *big.Int) error
UpdateCheckData(id *big.Int, newCheckData []byte) error
SetUpkeepTriggerConfig(id *big.Int, triggerConfig []byte) error
SetUpkeepPrivilegeConfig(id *big.Int, privilegeConfig []byte) error
SetUpkeepOffchainConfig(id *big.Int, offchainConfig []byte) error
RegistryOwnerAddress() common.Address
ChainModuleAddress() common.Address
ReorgProtectionEnabled() bool
}
type KeeperConsumer interface {
Address() string
Counter(ctx context.Context) (*big.Int, error)
Start() error
}
type UpkeepCounter interface {
Address() string
Fund(ethAmount *big.Float) error
Counter(ctx context.Context) (*big.Int, error)
SetSpread(testRange *big.Int, interval *big.Int) error
Start() error
}
type UpkeepPerformCounterRestrictive interface {
Address() string
Fund(ethAmount *big.Float) error
Counter(ctx context.Context) (*big.Int, error)
SetSpread(testRange *big.Int, interval *big.Int) error
}
// KeeperConsumerPerformance is a keeper consumer contract that is more complicated than the typical consumer,
// it's intended to only be used for performance tests.
type KeeperConsumerPerformance interface {
Address() string
Fund(ethAmount *big.Float) error
CheckEligible(ctx context.Context) (bool, error)
GetUpkeepCount(ctx context.Context) (*big.Int, error)
SetCheckGasToBurn(ctx context.Context, gas *big.Int) error
SetPerformGasToBurn(ctx context.Context, gas *big.Int) error
}
// AutomationConsumerBenchmark is a keeper consumer contract that is more complicated than the typical consumer,
// it's intended to only be used for benchmark tests.
type AutomationConsumerBenchmark interface {
Address() string
Fund(ethAmount *big.Float) error
CheckEligible(ctx context.Context, id *big.Int, _range *big.Int, firstEligibleBuffer *big.Int) (bool, error)
GetUpkeepCount(ctx context.Context, id *big.Int) (*big.Int, error)
}
type KeeperPerformDataChecker interface {
Address() string
Counter(ctx context.Context) (*big.Int, error)
SetExpectedData(ctx context.Context, expectedData []byte) error
}
type UpkeepPerformedLog struct {
Id *big.Int
Success bool
From common.Address
}
type StaleUpkeepReportLog struct {
Id *big.Int
}
// KeeperRegistryOpts opts to deploy keeper registry version
type KeeperRegistryOpts struct {
RegistryVersion ethereum.KeeperRegistryVersion
LinkAddr string
ETHFeedAddr string
GasFeedAddr string
TranscoderAddr string
RegistrarAddr string
Settings KeeperRegistrySettings
LinkUSDFeedAddr string
NativeUSDFeedAddr string
WrappedNativeAddr string
}
// KeeperRegistrySettings represents the settings to fine tune keeper registry
type KeeperRegistrySettings struct {
PaymentPremiumPPB uint32 // payment premium rate oracles receive on top of being reimbursed for gas, measured in parts per billion
FlatFeeMicroLINK uint32 // flat fee charged for each upkeep
BlockCountPerTurn *big.Int // number of blocks each oracle has during their turn to perform upkeep before it will be the next keeper's turn to submit
CheckGasLimit uint32 // gas limit when checking for upkeep
StalenessSeconds *big.Int // number of seconds that is allowed for feed data to be stale before switching to the fallback pricing
GasCeilingMultiplier uint16 // multiplier to apply to the fast gas feed price when calculating the payment ceiling for keepers
MinUpkeepSpend *big.Int // minimum spend required by an upkeep before they can withdraw funds
MaxPerformGas uint32 // max gas allowed for an upkeep within perform
FallbackGasPrice *big.Int // gas price used if the gas price feed is stale
FallbackLinkPrice *big.Int // LINK price used if the LINK price feed is stale
FallbackNativePrice *big.Int // Native price used if the Native price feed is stale
MaxCheckDataSize uint32
MaxPerformDataSize uint32
MaxRevertDataSize uint32
RegistryVersion ethereum.KeeperRegistryVersion
}
func (rcs *KeeperRegistrySettings) Create23OnchainConfig(registrar string, registryOwnerAddress, chainModuleAddress common.Address, reorgProtectionEnabled bool) i_automation_registry_master_wrapper_2_3.AutomationRegistryBase23OnchainConfig {
return i_automation_registry_master_wrapper_2_3.AutomationRegistryBase23OnchainConfig{
CheckGasLimit: rcs.CheckGasLimit,
StalenessSeconds: rcs.StalenessSeconds,
GasCeilingMultiplier: rcs.GasCeilingMultiplier,
MaxPerformGas: rcs.MaxPerformGas,
MaxCheckDataSize: rcs.MaxCheckDataSize,
MaxPerformDataSize: rcs.MaxPerformDataSize,
MaxRevertDataSize: rcs.MaxRevertDataSize,
FallbackGasPrice: rcs.FallbackGasPrice,
FallbackLinkPrice: rcs.FallbackLinkPrice,
Transcoder: common.Address{},
Registrars: []common.Address{common.HexToAddress(registrar)},
UpkeepPrivilegeManager: registryOwnerAddress,
ChainModule: chainModuleAddress,
ReorgProtectionEnabled: reorgProtectionEnabled,
FinanceAdmin: registryOwnerAddress,
FallbackNativePrice: rcs.FallbackNativePrice,
}
}
func (rcs *KeeperRegistrySettings) Encode20OnchainConfig(registrar string) []byte {
configType := goabi.MustNewType("tuple(uint32 paymentPremiumPPB,uint32 flatFeeMicroLink,uint32 checkGasLimit,uint24 stalenessSeconds,uint16 gasCeilingMultiplier,uint96 minUpkeepSpend,uint32 maxPerformGas,uint32 maxCheckDataSize,uint32 maxPerformDataSize,uint256 fallbackGasPrice,uint256 fallbackLinkPrice,address transcoder,address registrar)")
onchainConfig, _ := goabi.Encode(map[string]interface{}{
"paymentPremiumPPB": rcs.PaymentPremiumPPB,
"flatFeeMicroLink": rcs.FlatFeeMicroLINK,
"checkGasLimit": rcs.CheckGasLimit,
"stalenessSeconds": rcs.StalenessSeconds,
"gasCeilingMultiplier": rcs.GasCeilingMultiplier,
"minUpkeepSpend": rcs.MinUpkeepSpend,
"maxPerformGas": rcs.MaxPerformGas,
"maxCheckDataSize": rcs.MaxCheckDataSize,
"maxPerformDataSize": rcs.MaxPerformDataSize,
"fallbackGasPrice": rcs.FallbackGasPrice,
"fallbackLinkPrice": rcs.FallbackLinkPrice,
"transcoder": common.Address{},
"registrar": registrar,
}, configType)
return onchainConfig
}
func (rcs *KeeperRegistrySettings) Create22OnchainConfig(registrar string, registryOwnerAddress, chainModuleAddress common.Address, reorgProtectionEnabled bool) i_automation_registry_master_wrapper_2_2.AutomationRegistryBase22OnchainConfig {
return i_automation_registry_master_wrapper_2_2.AutomationRegistryBase22OnchainConfig{
PaymentPremiumPPB: rcs.PaymentPremiumPPB,
FlatFeeMicroLink: rcs.FlatFeeMicroLINK,
CheckGasLimit: rcs.CheckGasLimit,
StalenessSeconds: rcs.StalenessSeconds,
GasCeilingMultiplier: rcs.GasCeilingMultiplier,
MinUpkeepSpend: rcs.MinUpkeepSpend,
MaxPerformGas: rcs.MaxPerformGas,
MaxCheckDataSize: rcs.MaxCheckDataSize,
MaxPerformDataSize: rcs.MaxPerformDataSize,
MaxRevertDataSize: rcs.MaxRevertDataSize,
FallbackGasPrice: rcs.FallbackGasPrice,
FallbackLinkPrice: rcs.FallbackLinkPrice,
Transcoder: common.Address{},
Registrars: []common.Address{common.HexToAddress(registrar)},
UpkeepPrivilegeManager: registryOwnerAddress,
ChainModule: chainModuleAddress,
ReorgProtectionEnabled: reorgProtectionEnabled,
}
}
func (rcs *KeeperRegistrySettings) Create21OnchainConfig(registrar string, registryOwnerAddress common.Address) i_keeper_registry_master_wrapper_2_1.IAutomationV21PlusCommonOnchainConfigLegacy {
return i_keeper_registry_master_wrapper_2_1.IAutomationV21PlusCommonOnchainConfigLegacy{
PaymentPremiumPPB: rcs.PaymentPremiumPPB,
FlatFeeMicroLink: rcs.FlatFeeMicroLINK,
CheckGasLimit: rcs.CheckGasLimit,
StalenessSeconds: rcs.StalenessSeconds,
GasCeilingMultiplier: rcs.GasCeilingMultiplier,
MinUpkeepSpend: rcs.MinUpkeepSpend,
MaxPerformGas: rcs.MaxPerformGas,
MaxCheckDataSize: rcs.MaxCheckDataSize,
MaxPerformDataSize: rcs.MaxPerformDataSize,
MaxRevertDataSize: rcs.MaxRevertDataSize,
FallbackGasPrice: rcs.FallbackGasPrice,
FallbackLinkPrice: rcs.FallbackLinkPrice,
Transcoder: common.Address{},
Registrars: []common.Address{common.HexToAddress(registrar)},
UpkeepPrivilegeManager: registryOwnerAddress,
}
}
// KeeperRegistrarSettings represents settings for registrar contract
type KeeperRegistrarSettings struct {
AutoApproveConfigType uint8
AutoApproveMaxAllowed uint16
RegistryAddr string
MinLinkJuels *big.Int
WETHTokenAddr string
}
// KeeperInfo keeper status and balance info
type KeeperInfo struct {
Payee string
Active bool
Balance *big.Int
}
// UpkeepInfo keeper target info
type UpkeepInfo struct {
Target string
ExecuteGas uint32
CheckData []byte
Balance *big.Int
LastKeeper string
Admin string
MaxValidBlocknumber uint64
LastPerformBlockNumber uint32
AmountSpent *big.Int
Paused bool
OffchainConfig []byte
}