@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.
- package/AGENTS.md +53 -43
- package/BUILD-MANIFEST.json +17 -14
- package/PROTOCOL-PROVENANCE.json +7 -7
- package/README.md +151 -99
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/abi/D20VRFCoordinator.json +441 -3
- package/abi/EpochEntropy.json +250 -0
- package/contracts/examples/MiningRandomnessConsumer.sol +2 -1
- package/contracts/interfaces/ID20VRF.sol +5 -1
- package/contracts/libraries/D20VRFRequests.sol +2 -1
- package/dist/abi.d.ts +534 -3
- package/dist/abi.js +2 -2
- package/dist/epoch.d.ts +7 -2
- package/dist/epoch.js +24 -9
- package/dist/fees.d.ts +56 -0
- package/dist/fees.js +48 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/examples/DiceConsumer.sol +14 -7
- package/package.json +76 -76
|
@@ -3,24 +3,31 @@ pragma solidity 0.8.28;
|
|
|
3
3
|
|
|
4
4
|
import {D20VRFConsumer} from "@d20dao/vrf-sdk/contracts/D20VRFConsumer.sol";
|
|
5
5
|
import {ID20VRF} from "@d20dao/vrf-sdk/contracts/interfaces/ID20VRF.sol";
|
|
6
|
-
import {
|
|
6
|
+
import {RandomnessMapping} from "@d20dao/vrf-sdk/contracts/libraries/RandomnessMapping.sol";
|
|
7
7
|
|
|
8
8
|
/// @notice Minimal request/storage starter; no game payment, proof, mint or deployment policy.
|
|
9
|
+
/// @dev The player pays the request. A wallet cannot know the exact same-transaction quote in advance, so it quotes
|
|
10
|
+
/// off-chain with quoteFeeAt(callbackGasLimit, latestBlock.baseFeePerGas) plus a buffer (the SDK's quoteRequestFee
|
|
11
|
+
/// helper does this) and sends that value. The whole payment is forwarded: the coordinator escrows exactly
|
|
12
|
+
/// quoteFee(callbackGasLimit) and credits any excess to the player (the refund address) as refund credit that only
|
|
13
|
+
/// the player can pull with withdrawRefundCredit. Underpayment reverts inside the coordinator with
|
|
14
|
+
/// IncorrectFee(expected, actual). A contract that funds requests from its own balance would instead pay
|
|
15
|
+
/// rng.quoteFee(callbackGasLimit) in the same transaction, as the D20VRFRequests helpers do.
|
|
9
16
|
contract DiceConsumer is D20VRFConsumer {
|
|
10
|
-
using D20VRFRequests for ID20VRF;
|
|
11
17
|
struct Roll { address player; bytes32 rawWord; bool ready; }
|
|
12
18
|
mapping(uint256 => Roll) public rolls;
|
|
13
19
|
mapping(uint256 => bool) public refunded;
|
|
14
|
-
error WrongFee();
|
|
15
20
|
error UnexpectedCallback();
|
|
16
21
|
error NotReady();
|
|
17
22
|
|
|
18
23
|
constructor(address coordinator) D20VRFConsumer(coordinator) {}
|
|
19
24
|
|
|
20
25
|
function roll(bytes32 clientSeed, uint32 callbackGasLimit) external payable returns (uint256 requestId) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
requestId =
|
|
26
|
+
// One d20. The callback still receives the raw word; result() reads the canonical mapped value.
|
|
27
|
+
RandomnessMapping.Spec memory spec = RandomnessMapping.Spec(RandomnessMapping.Operation.DiceRoll, 0, 20, 1, 0);
|
|
28
|
+
requestId = ID20VRF(vrfCoordinator).requestMappedRandomness{value: msg.value}(
|
|
29
|
+
clientSeed, callbackGasLimit, msg.sender, spec
|
|
30
|
+
);
|
|
24
31
|
rolls[requestId] = Roll(msg.sender, bytes32(0), false);
|
|
25
32
|
}
|
|
26
33
|
|
|
@@ -31,7 +38,7 @@ contract DiceConsumer is D20VRFConsumer {
|
|
|
31
38
|
result.ready = true;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
//
|
|
41
|
+
// Called after an expired request's refund share was paid to the player or recorded as the player's refund credit.
|
|
35
42
|
function _onRefund(uint256 requestId) internal override {
|
|
36
43
|
Roll storage result = rolls[requestId];
|
|
37
44
|
if (result.player == address(0) || result.ready) revert UnexpectedCallback();
|
package/package.json
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@d20dao/vrf-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "D20DAO verifiable randomness: Solidity consumer helpers, contract ABIs and public proof replay",
|
|
5
|
-
"publishConfig": {
|
|
6
|
-
"access": "public",
|
|
7
|
-
"registry": "https://registry.npmjs.org/"
|
|
8
|
-
},
|
|
9
|
-
"type": "module",
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"engines": {
|
|
12
|
-
"node": ">=22.13.0"
|
|
13
|
-
},
|
|
14
|
-
"main": "./dist/index.js",
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"exports": {
|
|
17
|
-
".": {
|
|
18
|
-
"types": "./dist/index.d.ts",
|
|
19
|
-
"import": "./dist/index.js"
|
|
20
|
-
},
|
|
21
|
-
"./abi": {
|
|
22
|
-
"types": "./dist/abi.d.ts",
|
|
23
|
-
"import": "./dist/abi.js"
|
|
24
|
-
},
|
|
25
|
-
"./epoch": {
|
|
26
|
-
"types": "./dist/epoch.d.ts",
|
|
27
|
-
"import": "./dist/epoch.js"
|
|
28
|
-
},
|
|
29
|
-
"./abi/D20VRFCoordinator.json": "./abi/D20VRFCoordinator.json",
|
|
30
|
-
"./abi/EpochEntropy.json": "./abi/EpochEntropy.json",
|
|
31
|
-
"./contracts/*": "./contracts/*",
|
|
32
|
-
"./examples/*": "./examples/*",
|
|
33
|
-
"./AGENTS.md": "./AGENTS.md"
|
|
34
|
-
},
|
|
35
|
-
"files": [
|
|
36
|
-
"dist/*.js",
|
|
37
|
-
"dist/*.d.ts",
|
|
38
|
-
"contracts/**/*.sol",
|
|
39
|
-
"examples/*.sol",
|
|
40
|
-
"AGENTS.md",
|
|
41
|
-
"LICENSE",
|
|
42
|
-
"THIRD_PARTY_NOTICES.md",
|
|
43
|
-
"notices/*",
|
|
44
|
-
"BUILD-MANIFEST.json",
|
|
45
|
-
"PROTOCOL-PROVENANCE.json",
|
|
46
|
-
"abi/D20VRFCoordinator.json",
|
|
47
|
-
"abi/EpochEntropy.json"
|
|
48
|
-
],
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "node scripts/build.mjs",
|
|
51
|
-
"prepack": "npm run build",
|
|
52
|
-
"prepublishOnly": "npm test",
|
|
53
|
-
"test": "node scripts/smoke.mjs"
|
|
54
|
-
},
|
|
55
|
-
"dependencies": {
|
|
56
|
-
"@noble/curves": "1.9.7",
|
|
57
|
-
"ethers": "6.17.0"
|
|
58
|
-
},
|
|
59
|
-
"devDependencies": {
|
|
60
|
-
"@openzeppelin/contracts": "5.6.1",
|
|
61
|
-
"@types/node": "24.10.0",
|
|
62
|
-
"esbuild": "0.28.2",
|
|
63
|
-
"solc": "0.8.28",
|
|
64
|
-
"typescript": "5.9.3",
|
|
65
|
-
"@openzeppelin/contracts-upgradeable": "5.6.1"
|
|
66
|
-
},
|
|
67
|
-
"overrides": {
|
|
68
|
-
"solc": {
|
|
69
|
-
"tmp": "0.2.7"
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
"repository": {
|
|
73
|
-
"type": "git",
|
|
74
|
-
"url": "https://github.com/d20dao/d20-sdk.git"
|
|
75
|
-
}
|
|
76
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@d20dao/vrf-sdk",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "D20DAO verifiable randomness: Solidity consumer helpers, contract ABIs and public proof replay",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org/"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=22.13.0"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./abi": {
|
|
22
|
+
"types": "./dist/abi.d.ts",
|
|
23
|
+
"import": "./dist/abi.js"
|
|
24
|
+
},
|
|
25
|
+
"./epoch": {
|
|
26
|
+
"types": "./dist/epoch.d.ts",
|
|
27
|
+
"import": "./dist/epoch.js"
|
|
28
|
+
},
|
|
29
|
+
"./abi/D20VRFCoordinator.json": "./abi/D20VRFCoordinator.json",
|
|
30
|
+
"./abi/EpochEntropy.json": "./abi/EpochEntropy.json",
|
|
31
|
+
"./contracts/*": "./contracts/*",
|
|
32
|
+
"./examples/*": "./examples/*",
|
|
33
|
+
"./AGENTS.md": "./AGENTS.md"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist/*.js",
|
|
37
|
+
"dist/*.d.ts",
|
|
38
|
+
"contracts/**/*.sol",
|
|
39
|
+
"examples/*.sol",
|
|
40
|
+
"AGENTS.md",
|
|
41
|
+
"LICENSE",
|
|
42
|
+
"THIRD_PARTY_NOTICES.md",
|
|
43
|
+
"notices/*",
|
|
44
|
+
"BUILD-MANIFEST.json",
|
|
45
|
+
"PROTOCOL-PROVENANCE.json",
|
|
46
|
+
"abi/D20VRFCoordinator.json",
|
|
47
|
+
"abi/EpochEntropy.json"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "node scripts/build.mjs",
|
|
51
|
+
"prepack": "npm run build",
|
|
52
|
+
"prepublishOnly": "npm test",
|
|
53
|
+
"test": "node scripts/smoke.mjs"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@noble/curves": "1.9.7",
|
|
57
|
+
"ethers": "6.17.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@openzeppelin/contracts": "5.6.1",
|
|
61
|
+
"@types/node": "24.10.0",
|
|
62
|
+
"esbuild": "0.28.2",
|
|
63
|
+
"solc": "0.8.28",
|
|
64
|
+
"typescript": "5.9.3",
|
|
65
|
+
"@openzeppelin/contracts-upgradeable": "5.6.1"
|
|
66
|
+
},
|
|
67
|
+
"overrides": {
|
|
68
|
+
"solc": {
|
|
69
|
+
"tmp": "0.2.7"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"repository": {
|
|
73
|
+
"type": "git",
|
|
74
|
+
"url": "https://github.com/d20dao/d20-sdk.git"
|
|
75
|
+
}
|
|
76
|
+
}
|