-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathcontract_vrf_models.go
411 lines (383 loc) · 16.6 KB
/
contract_vrf_models.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
package contracts
import (
"context"
"math/big"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_load_test_with_metrics"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_owner"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2_consumer_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_upgraded_version"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrfv2_wrapper_load_test_consumer"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrfv2plus_wrapper_load_test_consumer"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ocr2vrf/generated/dkg"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ocr2vrf/generated/vrf_beacon"
)
type VRF interface {
Fund(ethAmount *big.Float) error
ProofLength(context.Context) (*big.Int, error)
}
type VRFCoordinator interface {
RegisterProvingKey(
fee *big.Int,
oracleAddr string,
publicProvingKey [2]*big.Int,
jobID [32]byte,
) error
HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error)
Address() string
}
type VRFCoordinatorV2 interface {
GetRequestConfig(ctx context.Context) (GetRequestConfig, error)
GetConfig(ctx context.Context) (vrf_coordinator_v2.GetConfig, error)
GetFallbackWeiPerUnitLink(ctx context.Context) (*big.Int, error)
GetFeeConfig(ctx context.Context) (vrf_coordinator_v2.GetFeeConfig, error)
SetConfig(
minimumRequestConfirmations uint16,
maxGasLimit uint32,
stalenessSeconds uint32,
gasAfterPaymentCalculation uint32,
fallbackWeiPerUnitLink *big.Int,
feeConfig vrf_coordinator_v2.VRFCoordinatorV2FeeConfig,
) error
RegisterProvingKey(
oracleAddr string,
publicProvingKey [2]*big.Int,
) error
TransferOwnership(to common.Address) error
HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error)
CreateSubscription() (*types.Transaction, error)
AddConsumer(subId uint64, consumerAddress string) error
Address() string
GetSubscription(ctx context.Context, subID uint64) (Subscription, error)
GetOwner(ctx context.Context) (common.Address, error)
PendingRequestsExist(ctx context.Context, subID uint64) (bool, error)
OwnerCancelSubscription(subID uint64) (*types.Transaction, error)
ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error)
ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error)
ParseRandomWordsFulfilled(log types.Log) (*CoordinatorRandomWordsFulfilled, error)
ParseLog(log types.Log) (generated.AbigenLog, error)
CancelSubscription(subID uint64, to common.Address) (*types.Transaction, error)
FindSubscriptionID(subID uint64) (uint64, error)
WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, error)
WaitForRandomWordsRequestedEvent(keyHash [][32]byte, subID []uint64, sender []common.Address, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2RandomWordsRequested, error)
WaitForSubscriptionCanceledEvent(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error)
WaitForSubscriptionConsumerAdded(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerAdded, error)
WaitForSubscriptionConsumerRemoved(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerRemoved, error)
WaitForSubscriptionCreatedEvent(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCreated, error)
WaitForSubscriptionFunded(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionFunded, error)
WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error)
OracleWithdraw(recipient common.Address, amount *big.Int) error
}
type VRFCoordinatorV2_5 interface {
SetLINKAndLINKNativeFeed(
link string,
linkNativeFeed string,
) error
SetConfig(
minimumRequestConfirmations uint16,
maxGasLimit uint32,
stalenessSeconds uint32,
gasAfterPaymentCalculation uint32,
fallbackWeiPerUnitLink *big.Int,
fulfillmentFlatFeeNativePPM uint32,
fulfillmentFlatFeeLinkDiscountPPM uint32,
nativePremiumPercentage uint8,
linkPremiumPercentage uint8,
) error
RegisterProvingKey(
publicProvingKey [2]*big.Int,
gasLaneMaxGas uint64,
) error
HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error)
CreateSubscription() (*types.Transaction, error)
GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error)
Migrate(subId *big.Int, coordinatorAddress string) error
RegisterMigratableCoordinator(migratableCoordinatorAddress string) error
AddConsumer(subId *big.Int, consumerAddress string) error
FundSubscriptionWithNative(subId *big.Int, nativeTokenAmount *big.Int) error
Address() string
PendingRequestsExist(ctx context.Context, subID *big.Int) (bool, error)
GetSubscription(ctx context.Context, subID *big.Int) (Subscription, error)
OwnerCancelSubscription(subID *big.Int) (*types.Transaction, error)
CancelSubscription(subID *big.Int, to common.Address) (*types.Transaction, error)
Withdraw(recipient common.Address) error
WithdrawNative(recipient common.Address) error
GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error)
GetLinkTotalBalance(ctx context.Context) (*big.Int, error)
FindSubscriptionID(subID *big.Int) (*big.Int, error)
WaitForSubscriptionCreatedEvent(timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCreated, error)
WaitForSubscriptionCanceledEvent(subID *big.Int, timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error)
WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, error)
WaitForMigrationCompletedEvent(timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, error)
ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error)
ParseRandomWordsFulfilled(log types.Log) (*CoordinatorRandomWordsFulfilled, error)
WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error)
}
type VRFCoordinatorV2PlusUpgradedVersion interface {
SetLINKAndLINKNativeFeed(
link string,
linkNativeFeed string,
) error
SetConfig(
minimumRequestConfirmations uint16,
maxGasLimit uint32,
stalenessSeconds uint32,
gasAfterPaymentCalculation uint32,
fallbackWeiPerUnitLink *big.Int,
fulfillmentFlatFeeNativePPM uint32,
fulfillmentFlatFeeLinkDiscountPPM uint32,
nativePremiumPercentage uint8,
linkPremiumPercentage uint8,
) error
RegisterProvingKey(
publicProvingKey [2]*big.Int,
gasLaneMaxGasPrice uint64,
) error
HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error)
CreateSubscription() error
GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error)
GetLinkTotalBalance(ctx context.Context) (*big.Int, error)
Migrate(subId *big.Int, coordinatorAddress string) error
RegisterMigratableCoordinator(migratableCoordinatorAddress string) error
AddConsumer(subId *big.Int, consumerAddress string) error
FundSubscriptionWithNative(subId *big.Int, nativeTokenAmount *big.Int) error
Address() string
GetSubscription(ctx context.Context, subID *big.Int) (vrf_v2plus_upgraded_version.GetSubscription, error)
GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error)
FindSubscriptionID() (*big.Int, error)
WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, error)
WaitForMigrationCompletedEvent(timeout time.Duration) (*vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionMigrationCompleted, error)
ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error)
ParseRandomWordsFulfilled(log types.Log) (*CoordinatorRandomWordsFulfilled, error)
WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error)
}
type VRFV2Wrapper interface {
Address() string
SetConfig(wrapperGasOverhead uint32, coordinatorGasOverhead uint32, wrapperPremiumPercentage uint8, keyHash [32]byte, maxNumWords uint8) error
GetSubID(ctx context.Context) (uint64, error)
}
type VRFV2PlusWrapper interface {
Address() string
SetConfig(
wrapperGasOverhead uint32,
coordinatorGasOverheadNative uint32,
coordinatorGasOverheadLink uint32,
coordinatorGasOverheadPerWord uint16,
wrapperNativePremiumPercentage uint8,
wrapperLinkPremiumPercentage uint8,
keyHash [32]byte, maxNumWords uint8,
stalenessSeconds uint32,
fallbackWeiPerUnitLink *big.Int,
fulfillmentFlatFeeNativePPM uint32,
fulfillmentFlatFeeLinkDiscountPPM uint32,
) error
GetSubID(ctx context.Context) (*big.Int, error)
Coordinator(ctx context.Context) (common.Address, error)
}
type VRFOwner interface {
Address() string
SetAuthorizedSenders(senders []common.Address) error
AcceptVRFOwnership() error
WaitForRandomWordsForcedEvent(requestIDs []*big.Int, subIds []uint64, senders []common.Address, timeout time.Duration) (*vrf_owner.VRFOwnerRandomWordsForced, error)
OwnerCancelSubscription(subID uint64) (*types.Transaction, error)
}
type VRFConsumer interface {
Address() string
RequestRandomness(hash [32]byte, fee *big.Int) error
CurrentRoundID(ctx context.Context) (*big.Int, error)
RandomnessOutput(ctx context.Context) (*big.Int, error)
Fund(ethAmount *big.Float) error
}
type VRFConsumerV2 interface {
Address() string
CurrentSubscription() (uint64, error)
CreateFundedSubscription(funds *big.Int) error
TopUpSubscriptionFunds(funds *big.Int) error
RequestRandomness(hash [32]byte, subID uint64, confs uint16, gasLimit uint32, numWords uint32) error
RandomnessOutput(ctx context.Context, arg0 *big.Int) (*big.Int, error)
GetAllRandomWords(ctx context.Context, num int) ([]*big.Int, error)
GasAvailable() (*big.Int, error)
Fund(ethAmount *big.Float) error
}
type VRFv2Consumer interface {
Address() string
RequestRandomness(hash [32]byte, subID uint64, confs uint16, gasLimit uint32, numWords uint32) error
GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_v2_consumer_wrapper.GetRequestStatus, error)
GetLastRequestId(ctx context.Context) (*big.Int, error)
}
type VRFv2LoadTestConsumer interface {
Address() string
RequestRandomness(
coordinator Coordinator,
keyHash [32]byte,
subID uint64,
requestConfirmations uint16,
callbackGasLimit uint32,
numWords uint32,
requestCount uint16,
) (*CoordinatorRandomWordsRequested, error)
RequestRandomWordsWithForceFulfill(
coordinator Coordinator,
keyHash [32]byte,
requestConfirmations uint16,
callbackGasLimit uint32,
numWords uint32,
requestCount uint16,
subTopUpAmount *big.Int,
linkAddress common.Address,
) (*CoordinatorRandomWordsRequested, error)
GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_load_test_with_metrics.GetRequestStatus, error)
GetLastRequestId(ctx context.Context) (*big.Int, error)
GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error)
ResetMetrics() error
}
type VRFv2WrapperLoadTestConsumer interface {
Address() string
Fund(ethAmount *big.Float) error
RequestRandomness(coordinator Coordinator, requestConfirmations uint16, callbackGasLimit uint32, numWords uint32, requestCount uint16) (*CoordinatorRandomWordsRequested, error)
GetRequestStatus(ctx context.Context, requestID *big.Int) (vrfv2_wrapper_load_test_consumer.GetRequestStatus, error)
GetLastRequestId(ctx context.Context) (*big.Int, error)
GetWrapper(ctx context.Context) (common.Address, error)
GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error)
}
type VRFv2PlusLoadTestConsumer interface {
Address() string
RequestRandomness(
coordinator Coordinator,
keyHash [32]byte, subID *big.Int,
requestConfirmations uint16,
callbackGasLimit uint32,
nativePayment bool,
numWords uint32,
requestCount uint16,
) (*CoordinatorRandomWordsRequested, error)
GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_v2plus_load_test_with_metrics.GetRequestStatus, error)
GetLastRequestId(ctx context.Context) (*big.Int, error)
GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error)
GetCoordinator(ctx context.Context) (common.Address, error)
ResetMetrics() error
}
type VRFv2PlusWrapperLoadTestConsumer interface {
Address() string
Fund(ethAmount *big.Float) error
RequestRandomness(
coordinator Coordinator,
requestConfirmations uint16,
callbackGasLimit uint32,
numWords uint32,
requestCount uint16,
) (*CoordinatorRandomWordsRequested, error)
RequestRandomnessNative(
coordinator Coordinator,
requestConfirmations uint16,
callbackGasLimit uint32,
numWords uint32,
requestCount uint16,
) (*CoordinatorRandomWordsRequested, error)
GetRequestStatus(ctx context.Context, requestID *big.Int) (vrfv2plus_wrapper_load_test_consumer.GetRequestStatus, error)
GetLastRequestId(ctx context.Context) (*big.Int, error)
GetWrapper(ctx context.Context) (common.Address, error)
GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error)
}
type DKG interface {
Address() string
AddClient(keyID string, clientAddress string) error
SetConfig(
signerAddresses []common.Address,
transmitterAddresses []common.Address,
f uint8,
onchainConfig []byte,
offchainConfigVersion uint64,
offchainConfig []byte,
) error
WaitForConfigSetEvent(timeout time.Duration) (*dkg.DKGConfigSet, error)
WaitForTransmittedEvent(timeout time.Duration) (*dkg.DKGTransmitted, error)
}
type VRFCoordinatorV3 interface {
Address() string
SetProducer(producerAddress string) error
CreateSubscription() error
FindSubscriptionID() (*big.Int, error)
AddConsumer(subId *big.Int, consumerAddress string) error
SetConfig(maxCallbackGasLimit, maxCallbackArgumentsLength uint32) error
}
type VRFBeacon interface {
Address() string
SetPayees(transmitterAddresses []common.Address, payeesAddresses []common.Address) error
SetConfig(
signerAddresses []common.Address,
transmitterAddresses []common.Address,
f uint8,
onchainConfig []byte,
offchainConfigVersion uint64,
offchainConfig []byte,
) error
WaitForConfigSetEvent(timeout time.Duration) (*vrf_beacon.VRFBeaconConfigSet, error)
WaitForNewTransmissionEvent(timeout time.Duration) (*vrf_beacon.VRFBeaconNewTransmission, error)
LatestConfigDigestAndEpoch(ctx context.Context) (vrf_beacon.LatestConfigDigestAndEpoch,
error)
}
type VRFBeaconConsumer interface {
Address() string
RequestRandomness(
numWords uint16,
subID, confirmationDelayArg *big.Int,
) (*types.Receipt, error)
RedeemRandomness(subID, requestID *big.Int) error
RequestRandomnessFulfillment(
numWords uint16,
subID, confirmationDelayArg *big.Int,
requestGasLimit,
callbackGasLimit uint32,
arguments []byte,
) (*types.Receipt, error)
IBeaconPeriodBlocks(ctx context.Context) (*big.Int, error)
GetRequestIdsBy(ctx context.Context, nextBeaconOutputHeight *big.Int, confDelay *big.Int) (*big.Int, error)
GetRandomnessByRequestId(ctx context.Context, requestID *big.Int, numWordIndex *big.Int) (*big.Int, error)
}
type BatchBlockhashStore interface {
Address() string
}
type BatchVRFCoordinatorV2 interface {
Address() string
}
type BatchVRFCoordinatorV2Plus interface {
Address() string
}
type VRFMockETHLINKFeed interface {
Address() string
LatestRoundData() (*big.Int, error)
LatestRoundDataUpdatedAt() (*big.Int, error)
SetBlockTimestampDeduction(blockTimestampDeduction *big.Int) error
}
type RequestStatus struct {
Fulfilled bool
RandomWords []*big.Int
}
type LoadTestRequestStatus struct {
Fulfilled bool
RandomWords []*big.Int
// Currently Unused November 8, 2023, Mignt be used in near future, will remove if not.
// requestTimestamp *big.Int
// fulfilmentTimestamp *big.Int
// requestBlockNumber *big.Int
// fulfilmentBlockNumber *big.Int
}
type VRFLoadTestMetrics struct {
RequestCount *big.Int
FulfilmentCount *big.Int
AverageFulfillmentInMillions *big.Int
SlowestFulfillment *big.Int
FastestFulfillment *big.Int
P90FulfillmentBlockTime float64
P95FulfillmentBlockTime float64
AverageResponseTimeInSecondsMillions *big.Int
SlowestResponseTimeInSeconds *big.Int
FastestResponseTimeInSeconds *big.Int
}