[entropy] add entropy ABIs to solidity sdk (#1219)

This commit is contained in:
Jayant Krishnamurthy 2024-01-10 10:57:03 -08:00 committed by GitHub
parent 0eee513bf9
commit 7cf7420203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 830 additions and 4 deletions

View File

@ -38,5 +38,5 @@ jobs:
run: npx lerna run lint
- name: Generate ABIs
run: npx lerna run generate-abi
- name: Check Solidity ABI
run: git diff --exit-code target_chains/ethereum/sdk/solidity/abis/
- name: Check ABIs
run: npx lerna run check-abi

View File

@ -0,0 +1,52 @@
[
{
"inputs": [],
"name": "AssertionFailure",
"type": "error"
},
{
"inputs": [],
"name": "BlockhashUnavailable",
"type": "error"
},
{
"inputs": [],
"name": "IncorrectRevelation",
"type": "error"
},
{
"inputs": [],
"name": "InsufficientFee",
"type": "error"
},
{
"inputs": [],
"name": "InvalidUpgradeMagic",
"type": "error"
},
{
"inputs": [],
"name": "NoSuchProvider",
"type": "error"
},
{
"inputs": [],
"name": "NoSuchRequest",
"type": "error"
},
{
"inputs": [],
"name": "OutOfRandomness",
"type": "error"
},
{
"inputs": [],
"name": "ProviderAlreadyRegistered",
"type": "error"
},
{
"inputs": [],
"name": "Unauthorized",
"type": "error"
}
]

View File

@ -0,0 +1,191 @@
[
{
"anonymous": false,
"inputs": [
{
"components": [
{
"internalType": "uint128",
"name": "feeInWei",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "accruedFeesInWei",
"type": "uint128"
},
{
"internalType": "bytes32",
"name": "originalCommitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "originalCommitmentSequenceNumber",
"type": "uint64"
},
{
"internalType": "bytes",
"name": "commitmentMetadata",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "uri",
"type": "bytes"
},
{
"internalType": "uint64",
"name": "endSequenceNumber",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
},
{
"internalType": "bytes32",
"name": "currentCommitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "currentCommitmentSequenceNumber",
"type": "uint64"
}
],
"indexed": false,
"internalType": "struct EntropyStructs.ProviderInfo",
"name": "provider",
"type": "tuple"
}
],
"name": "Registered",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "provider",
"type": "address"
},
{
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
},
{
"internalType": "uint32",
"name": "numHashes",
"type": "uint32"
},
{
"internalType": "bytes32",
"name": "commitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "blockNumber",
"type": "uint64"
},
{
"internalType": "address",
"name": "requester",
"type": "address"
},
{
"internalType": "bool",
"name": "useBlockhash",
"type": "bool"
}
],
"indexed": false,
"internalType": "struct EntropyStructs.Request",
"name": "request",
"type": "tuple"
}
],
"name": "Requested",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "provider",
"type": "address"
},
{
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
},
{
"internalType": "uint32",
"name": "numHashes",
"type": "uint32"
},
{
"internalType": "bytes32",
"name": "commitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "blockNumber",
"type": "uint64"
},
{
"internalType": "address",
"name": "requester",
"type": "address"
},
{
"internalType": "bool",
"name": "useBlockhash",
"type": "bool"
}
],
"indexed": false,
"internalType": "struct EntropyStructs.Request",
"name": "request",
"type": "tuple"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "userRevelation",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "providerRevelation",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "blockHash",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "randomNumber",
"type": "bytes32"
}
],
"name": "Revealed",
"type": "event"
}
]

View File

@ -0,0 +1,525 @@
[
{
"anonymous": false,
"inputs": [
{
"components": [
{
"internalType": "uint128",
"name": "feeInWei",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "accruedFeesInWei",
"type": "uint128"
},
{
"internalType": "bytes32",
"name": "originalCommitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "originalCommitmentSequenceNumber",
"type": "uint64"
},
{
"internalType": "bytes",
"name": "commitmentMetadata",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "uri",
"type": "bytes"
},
{
"internalType": "uint64",
"name": "endSequenceNumber",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
},
{
"internalType": "bytes32",
"name": "currentCommitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "currentCommitmentSequenceNumber",
"type": "uint64"
}
],
"indexed": false,
"internalType": "struct EntropyStructs.ProviderInfo",
"name": "provider",
"type": "tuple"
}
],
"name": "Registered",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "provider",
"type": "address"
},
{
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
},
{
"internalType": "uint32",
"name": "numHashes",
"type": "uint32"
},
{
"internalType": "bytes32",
"name": "commitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "blockNumber",
"type": "uint64"
},
{
"internalType": "address",
"name": "requester",
"type": "address"
},
{
"internalType": "bool",
"name": "useBlockhash",
"type": "bool"
}
],
"indexed": false,
"internalType": "struct EntropyStructs.Request",
"name": "request",
"type": "tuple"
}
],
"name": "Requested",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "provider",
"type": "address"
},
{
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
},
{
"internalType": "uint32",
"name": "numHashes",
"type": "uint32"
},
{
"internalType": "bytes32",
"name": "commitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "blockNumber",
"type": "uint64"
},
{
"internalType": "address",
"name": "requester",
"type": "address"
},
{
"internalType": "bool",
"name": "useBlockhash",
"type": "bool"
}
],
"indexed": false,
"internalType": "struct EntropyStructs.Request",
"name": "request",
"type": "tuple"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "userRevelation",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "providerRevelation",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "blockHash",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "randomNumber",
"type": "bytes32"
}
],
"name": "Revealed",
"type": "event"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "userRandomness",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "providerRandomness",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "blockHash",
"type": "bytes32"
}
],
"name": "combineRandomValues",
"outputs": [
{
"internalType": "bytes32",
"name": "combinedRandomness",
"type": "bytes32"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "userRandomness",
"type": "bytes32"
}
],
"name": "constructUserCommitment",
"outputs": [
{
"internalType": "bytes32",
"name": "userCommitment",
"type": "bytes32"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "getAccruedPythFees",
"outputs": [
{
"internalType": "uint128",
"name": "accruedPythFeesInWei",
"type": "uint128"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getDefaultProvider",
"outputs": [
{
"internalType": "address",
"name": "provider",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "provider",
"type": "address"
}
],
"name": "getFee",
"outputs": [
{
"internalType": "uint128",
"name": "feeAmount",
"type": "uint128"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "provider",
"type": "address"
}
],
"name": "getProviderInfo",
"outputs": [
{
"components": [
{
"internalType": "uint128",
"name": "feeInWei",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "accruedFeesInWei",
"type": "uint128"
},
{
"internalType": "bytes32",
"name": "originalCommitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "originalCommitmentSequenceNumber",
"type": "uint64"
},
{
"internalType": "bytes",
"name": "commitmentMetadata",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "uri",
"type": "bytes"
},
{
"internalType": "uint64",
"name": "endSequenceNumber",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
},
{
"internalType": "bytes32",
"name": "currentCommitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "currentCommitmentSequenceNumber",
"type": "uint64"
}
],
"internalType": "struct EntropyStructs.ProviderInfo",
"name": "info",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "provider",
"type": "address"
},
{
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
}
],
"name": "getRequest",
"outputs": [
{
"components": [
{
"internalType": "address",
"name": "provider",
"type": "address"
},
{
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
},
{
"internalType": "uint32",
"name": "numHashes",
"type": "uint32"
},
{
"internalType": "bytes32",
"name": "commitment",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "blockNumber",
"type": "uint64"
},
{
"internalType": "address",
"name": "requester",
"type": "address"
},
{
"internalType": "bool",
"name": "useBlockhash",
"type": "bool"
}
],
"internalType": "struct EntropyStructs.Request",
"name": "req",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint128",
"name": "feeInWei",
"type": "uint128"
},
{
"internalType": "bytes32",
"name": "commitment",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "commitmentMetadata",
"type": "bytes"
},
{
"internalType": "uint64",
"name": "chainLength",
"type": "uint64"
},
{
"internalType": "bytes",
"name": "uri",
"type": "bytes"
}
],
"name": "register",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "provider",
"type": "address"
},
{
"internalType": "bytes32",
"name": "userCommitment",
"type": "bytes32"
},
{
"internalType": "bool",
"name": "useBlockHash",
"type": "bool"
}
],
"name": "request",
"outputs": [
{
"internalType": "uint64",
"name": "assignedSequenceNumber",
"type": "uint64"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "provider",
"type": "address"
},
{
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
},
{
"internalType": "bytes32",
"name": "userRandomness",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "providerRevelation",
"type": "bytes32"
}
],
"name": "reveal",
"outputs": [
{
"internalType": "bytes32",
"name": "randomNumber",
"type": "bytes32"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint128",
"name": "amount",
"type": "uint128"
}
],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]

View File

@ -1,6 +1,6 @@
{
"name": "@pythnetwork/entropy-sdk-solidity",
"version": "1.0.0",
"version": "1.1.0",
"description": "Generate secure random numbers with Pyth Entropy",
"repository": {
"type": "git",
@ -11,7 +11,9 @@
"access": "public"
},
"scripts": {
"format": "npx prettier --write ."
"format": "npx prettier --write .",
"generate-abi": "node scripts/generateAbi.js",
"check-abi": "git diff --exit-code abis"
},
"keywords": [
"pyth",

View File

@ -0,0 +1,54 @@
const fs = require("fs");
const solc = require("solc");
// Assuming each contract is in the file with the same name.
var contracts = [
"IEntropy",
"EntropyErrors",
"EntropyEvents",
"EntropyStructs",
];
var sources = {};
var outputSelection = {};
for (let contract of contracts) {
const contractFile = `${contract}.sol`;
sources[contractFile] = {
content: fs.readFileSync(contractFile).toString(),
};
outputSelection[contractFile] = {};
outputSelection[contractFile][contract] = ["abi"];
}
var input = {
language: "Solidity",
sources,
settings: {
outputSelection,
},
};
function findImports(path) {
return {
contents: fs.readFileSync(path).toString(),
};
}
const output = JSON.parse(
solc.compile(JSON.stringify(input), { import: findImports })
);
if (!fs.existsSync("abis")) {
fs.mkdirSync("abis");
}
for (let contract of contracts) {
const contractFile = `${contract}.sol`;
const abi = output.contracts[contractFile][contract].abi;
fs.writeFileSync(
`abis/${contract}.json`,
JSON.stringify(abi, null, 2) + "\n"
);
}

View File

@ -10,6 +10,7 @@
"scripts": {
"format": "npx prettier --write .",
"generate-abi": "node scripts/generateAbi.js",
"check-abi": "git diff --exit-code abis",
"build": "solcjs --bin MockPyth.sol --base-path . -o build/"
},
"keywords": [