@d20dao/vrf-sdk 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,6 +73,11 @@
73
73
  "name": "FailedCall",
74
74
  "type": "error"
75
75
  },
76
+ {
77
+ "inputs": [],
78
+ "name": "FallbackNotOpen",
79
+ "type": "error"
80
+ },
76
81
  {
77
82
  "inputs": [],
78
83
  "name": "InvalidConfig",
@@ -88,6 +93,11 @@
88
93
  "name": "InvalidEpoch",
89
94
  "type": "error"
90
95
  },
96
+ {
97
+ "inputs": [],
98
+ "name": "InvalidFallback",
99
+ "type": "error"
100
+ },
91
101
  {
92
102
  "inputs": [],
93
103
  "name": "InvalidInitialization",
@@ -145,6 +155,11 @@
145
155
  "name": "PreparationClosed",
146
156
  "type": "error"
147
157
  },
158
+ {
159
+ "inputs": [],
160
+ "name": "RenounceDisabled",
161
+ "type": "error"
162
+ },
148
163
  {
149
164
  "inputs": [],
150
165
  "name": "UUPSUnauthorizedCallContext",
@@ -161,6 +176,31 @@
161
176
  "name": "UUPSUnsupportedProxiableUUID",
162
177
  "type": "error"
163
178
  },
179
+ {
180
+ "anonymous": false,
181
+ "inputs": [
182
+ {
183
+ "indexed": true,
184
+ "internalType": "uint64",
185
+ "name": "fromEpoch",
186
+ "type": "uint64"
187
+ },
188
+ {
189
+ "indexed": true,
190
+ "internalType": "bytes32",
191
+ "name": "catalogHash",
192
+ "type": "bytes32"
193
+ },
194
+ {
195
+ "indexed": false,
196
+ "internalType": "address[4]",
197
+ "name": "signers",
198
+ "type": "address[4]"
199
+ }
200
+ ],
201
+ "name": "CatalogScheduled",
202
+ "type": "event"
203
+ },
164
204
  {
165
205
  "anonymous": false,
166
206
  "inputs": [
@@ -295,6 +335,45 @@
295
335
  "stateMutability": "view",
296
336
  "type": "function"
297
337
  },
338
+ {
339
+ "inputs": [],
340
+ "name": "FALLBACK_DELAY_BLOCKS",
341
+ "outputs": [
342
+ {
343
+ "internalType": "uint64",
344
+ "name": "",
345
+ "type": "uint64"
346
+ }
347
+ ],
348
+ "stateMutability": "view",
349
+ "type": "function"
350
+ },
351
+ {
352
+ "inputs": [],
353
+ "name": "MAX_ATTESTATION_AGE",
354
+ "outputs": [
355
+ {
356
+ "internalType": "uint256",
357
+ "name": "",
358
+ "type": "uint256"
359
+ }
360
+ ],
361
+ "stateMutability": "view",
362
+ "type": "function"
363
+ },
364
+ {
365
+ "inputs": [],
366
+ "name": "MAX_FALLBACK_ATTEMPT",
367
+ "outputs": [
368
+ {
369
+ "internalType": "uint8",
370
+ "name": "",
371
+ "type": "uint8"
372
+ }
373
+ ],
374
+ "stateMutability": "view",
375
+ "type": "function"
376
+ },
298
377
  {
299
378
  "inputs": [],
300
379
  "name": "MAX_PACKET_BYTES",
@@ -393,6 +472,25 @@
393
472
  "stateMutability": "view",
394
473
  "type": "function"
395
474
  },
475
+ {
476
+ "inputs": [
477
+ {
478
+ "internalType": "uint64",
479
+ "name": "epochId",
480
+ "type": "uint64"
481
+ }
482
+ ],
483
+ "name": "catalogHashAt",
484
+ "outputs": [
485
+ {
486
+ "internalType": "bytes32",
487
+ "name": "hash",
488
+ "type": "bytes32"
489
+ }
490
+ ],
491
+ "stateMutability": "view",
492
+ "type": "function"
493
+ },
396
494
  {
397
495
  "inputs": [
398
496
  {
@@ -447,6 +545,46 @@
447
545
  "stateMutability": "nonpayable",
448
546
  "type": "function"
449
547
  },
548
+ {
549
+ "inputs": [
550
+ {
551
+ "internalType": "uint64",
552
+ "name": "epochId",
553
+ "type": "uint64"
554
+ },
555
+ {
556
+ "internalType": "uint8",
557
+ "name": "attempt",
558
+ "type": "uint8"
559
+ },
560
+ {
561
+ "components": [
562
+ {
563
+ "internalType": "uint256",
564
+ "name": "timestamp",
565
+ "type": "uint256"
566
+ },
567
+ {
568
+ "internalType": "bytes",
569
+ "name": "data",
570
+ "type": "bytes"
571
+ },
572
+ {
573
+ "internalType": "bytes",
574
+ "name": "signature",
575
+ "type": "bytes"
576
+ }
577
+ ],
578
+ "internalType": "struct EpochEntropy.Attestation",
579
+ "name": "a",
580
+ "type": "tuple"
581
+ }
582
+ ],
583
+ "name": "commitEpochFallback",
584
+ "outputs": [],
585
+ "stateMutability": "nonpayable",
586
+ "type": "function"
587
+ },
450
588
  {
451
589
  "inputs": [],
452
590
  "name": "committer",
@@ -530,6 +668,30 @@
530
668
  "stateMutability": "view",
531
669
  "type": "function"
532
670
  },
671
+ {
672
+ "inputs": [
673
+ {
674
+ "internalType": "uint64",
675
+ "name": "epochId",
676
+ "type": "uint64"
677
+ },
678
+ {
679
+ "internalType": "uint8",
680
+ "name": "attempt",
681
+ "type": "uint8"
682
+ }
683
+ ],
684
+ "name": "fallbackOpensAt",
685
+ "outputs": [
686
+ {
687
+ "internalType": "uint64",
688
+ "name": "",
689
+ "type": "uint64"
690
+ }
691
+ ],
692
+ "stateMutability": "view",
693
+ "type": "function"
694
+ },
533
695
  {
534
696
  "inputs": [],
535
697
  "name": "firstEpochStart",
@@ -609,6 +771,57 @@
609
771
  "stateMutability": "view",
610
772
  "type": "function"
611
773
  },
774
+ {
775
+ "inputs": [
776
+ {
777
+ "internalType": "uint64",
778
+ "name": "epochId",
779
+ "type": "uint64"
780
+ },
781
+ {
782
+ "internalType": "uint8",
783
+ "name": "attempt",
784
+ "type": "uint8"
785
+ }
786
+ ],
787
+ "name": "getEpochFallbackSelection",
788
+ "outputs": [
789
+ {
790
+ "components": [
791
+ {
792
+ "internalType": "uint8",
793
+ "name": "source",
794
+ "type": "uint8"
795
+ },
796
+ {
797
+ "internalType": "address",
798
+ "name": "airnode",
799
+ "type": "address"
800
+ },
801
+ {
802
+ "internalType": "bytes32",
803
+ "name": "selector",
804
+ "type": "bytes32"
805
+ },
806
+ {
807
+ "internalType": "bytes32",
808
+ "name": "queryHash",
809
+ "type": "bytes32"
810
+ },
811
+ {
812
+ "internalType": "string",
813
+ "name": "canonicalRequest",
814
+ "type": "string"
815
+ }
816
+ ],
817
+ "internalType": "struct EpochEntropy.Selection",
818
+ "name": "s",
819
+ "type": "tuple"
820
+ }
821
+ ],
822
+ "stateMutability": "view",
823
+ "type": "function"
824
+ },
612
825
  {
613
826
  "inputs": [
614
827
  {
@@ -753,6 +966,24 @@
753
966
  "inputs": [],
754
967
  "name": "renounceOwnership",
755
968
  "outputs": [],
969
+ "stateMutability": "view",
970
+ "type": "function"
971
+ },
972
+ {
973
+ "inputs": [
974
+ {
975
+ "internalType": "address[4]",
976
+ "name": "signers",
977
+ "type": "address[4]"
978
+ },
979
+ {
980
+ "internalType": "uint64",
981
+ "name": "fromEpoch",
982
+ "type": "uint64"
983
+ }
984
+ ],
985
+ "name": "scheduleCatalog",
986
+ "outputs": [],
756
987
  "stateMutability": "nonpayable",
757
988
  "type": "function"
758
989
  },
@@ -769,6 +1000,25 @@
769
1000
  "stateMutability": "nonpayable",
770
1001
  "type": "function"
771
1002
  },
1003
+ {
1004
+ "inputs": [
1005
+ {
1006
+ "internalType": "uint64",
1007
+ "name": "epochId",
1008
+ "type": "uint64"
1009
+ }
1010
+ ],
1011
+ "name": "signersAt",
1012
+ "outputs": [
1013
+ {
1014
+ "internalType": "address[4]",
1015
+ "name": "signers",
1016
+ "type": "address[4]"
1017
+ }
1018
+ ],
1019
+ "stateMutability": "view",
1020
+ "type": "function"
1021
+ },
772
1022
  {
773
1023
  "inputs": [
774
1024
  {
@@ -27,7 +27,8 @@ abstract contract MiningRandomnessConsumer is D20VRFConsumer {
27
27
  if (claimRandomness[claimId].requested) revert ClaimAlreadyRequested();
28
28
  claimRandomness[claimId].requested = true;
29
29
  ID20VRF rng = ID20VRF(vrfCoordinator);
30
- requestId = rng.requestRandomness{value: rng.requestFee()}(
30
+ // The same-transaction quote is exact; only off-chain senders need a buffer.
31
+ requestId = rng.requestRandomness{value: rng.quoteFee(callbackGasLimit)}(
31
32
  keccak256(abi.encode(claimId, lockedWork)), callbackGasLimit, refundAddress
32
33
  );
33
34
  claimRandomness[claimId].requestId = requestId;
@@ -4,7 +4,11 @@ pragma solidity 0.8.28;
4
4
  import {RandomnessMapping} from "../libraries/RandomnessMapping.sol";
5
5
 
6
6
  interface ID20VRF {
7
- function requestFee() external view returns (uint256);
7
+ /// @notice Exact fee for a request sent in this same transaction. Through eth_call the base fee is often reported as 0,
8
+ /// so off-chain senders must quote with quoteFeeAt and the latest header baseFeePerGas plus a buffer.
9
+ function quoteFee(uint32 callbackGasLimit) external view returns (uint256);
10
+ /// @notice max(minFee, feeMultiplier * baseFee * (fulfillGasOverhead + callbackGasLimit)) over the current parameters.
11
+ function quoteFeeAt(uint32 callbackGasLimit, uint256 baseFee) external view returns (uint256);
8
12
  function requestRandomness(bytes32 clientSeed, uint32 callbackGasLimit, address _refundAddress)
9
13
  external payable returns (uint256 requestId);
10
14
  function requestMappedRandomness(
@@ -6,6 +6,7 @@ import {RandomnessMapping as M} from "./RandomnessMapping.sol";
6
6
 
7
7
  /// @notice Built-in request helpers for game contracts. All requests still callback with (id, rawWord).
8
8
  /// @dev Usage: using D20VRFRequests for ID20VRF; rng.d20(options). Inspect getMappedResult(id) after fulfillment.
9
+ /// Each helper pays the exact same-transaction quote from the calling contract balance.
9
10
  library D20VRFRequests {
10
11
  struct Options { bytes32 clientSeed; uint32 callbackGasLimit; address refundAddress; }
11
12
  function diceRoll(ID20VRF rng, uint256 sides, uint32 count, Options memory o) internal returns (uint256) {
@@ -36,6 +37,6 @@ library D20VRFRequests {
36
37
  return _send(rng, M.Spec(M.Operation.Shuffle, 0, 0, population, population), o);
37
38
  }
38
39
  function _send(ID20VRF rng, M.Spec memory spec, Options memory o) private returns (uint256) {
39
- return rng.requestMappedRandomness{value: rng.requestFee()}(o.clientSeed, o.callbackGasLimit, o.refundAddress, spec);
40
+ return rng.requestMappedRandomness{value: rng.quoteFee(o.callbackGasLimit)}(o.clientSeed, o.callbackGasLimit, o.refundAddress, spec);
40
41
  }
41
42
  }