Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
About Onyx: A High-Performance Layer 3 Blockchain
Learn about Onyxcoin
The Onyx Governance API Library



Governance Security and Stability Mechanisms
function propose(
address[] memory targets,
uint[] memory values,
string[] memory signatures,
bytes[] memory calldatas,
string memory description
) public returns (uint)CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
uint proposalId = gov.propose(targets, values, signatures, calldatas, description);const tx = await gov.methods.propose(targets, values, signatures, calldatas, description).send({ from: proposerAddress });function proposalThreshold() public view returns (uint)CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
uint threshold = gov.proposalThreshold();const threshold = await gov.methods.proposalThreshold().call();function cancel(uint proposalId) publicCHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
gov.cancel(proposalId);const tx = await gov.methods.cancel(proposalId).send({ from: sender });function getReceipt(uint proposalId, address voter) public view returns (Receipt memory)CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
Receipt memory ballot = gov.getReceipt(proposalId, voterAddress);const proposalId = 11;
const voterAddress = '0x123...';
const result = await gov.methods.getReceipt(proposalId, voterAddress).call();
const { hasVoted, support, votes } = result;function votingPeriod() public view returns (uint)CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
uint blocks = gov.votingPeriod();const blocks = await gov.methods.votingPeriod().call();function castVoteBySig(
uint proposalId,
bool support,
uint8 v,
bytes32 r,
bytes32 s
) publicCHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
gov.castVoteBySig(proposalId, true, v, r, s); // Voting in favor using an offline signatureconst tx = await gov.methods.castVoteBySig(proposalId, false, v, r, s).send({}); // Voting against using an offline signaturefunction execute(uint proposalId) public payable returns (uint)CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
gov.execute(proposalId).value(999).gas(999)();const tx = await gov.methods.execute(proposalId).send({ from: sender, value: 1 });function queue(uint proposalId) publicCHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
gov.queue(proposalId);const tx = await gov.methods.queue(proposalId).send({ from: sender });
function state(uint proposalId) public view returns (ProposalState)
CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
CHNGovernance.ProposalState proposalState = gov.state(123);const proposalStates = ['Pending', 'Active', 'Canceled', 'Defeated', 'Succeeded', 'Queued', 'Expired', 'Executed'];
const proposalId = 123;
const result = await gov.methods.state(proposalId).call();
const proposalState = proposalStates[result];function votingDelay() public view returns (uint)CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
uint blocks = gov.votingDelay();const blocks = await gov.methods.votingDelay().call();function quorumVotes() public pure returns (uint)CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
uint quorum = gov.quorumVotes();const quorum = await gov.methods.quorumVotes().call();GET /proposals
Response:
[
{
"proposalId": 1,
"title": "Update Risk Parameters",
"state": "Active",
"createdAt": "2024-02-05T12:00:00Z",
"votesFor": 150000000,
"votesAgainst": 50000000
}
]
GET /proposals/{proposalId}
Response:
{
"proposalId": 1,
"title": "Update Risk Parameters",
"description": "Adjust risk parameters for oETH market.",
"state": "Active",
"votesFor": 150000000,
"votesAgainst": 50000000,
"quorum": 200000000,
"timelockExpiration": "2024-02-07T12:00:00Z"
}POST /vote
Request Body:
{
"proposalId": 1,
"voter": "0x123456789abcdef",
"support": true,
"signature": "0xabcdef..."
}
Response:
{
"status": "success",
"message": "Vote successfully recorded."
}GET /receipts/{proposalId}/{voter}
Response:
{
"proposalId": 1,
"voter": "0x123456789abcdef",
"hasVoted": true,
"support": true,
"votes": 5000000
}GET /proposals/{proposalId}/state
Response:
{
"proposalId": 1,
"state": "Active"
}class TokenDispenser {
constructor() {
this.users = {};
}
requestToken(user) {
if (!this.users[user] || this._canReceive(user)) {
this.users[user] = Date.now();
return 'Token Granted';
}
return 'Token Request Denied';
}
_canReceive(user) {
return Date.now() - this.users[user] > 86400000;
}
}
Web3 Implementation (Solidity):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract TokenDispenser {
mapping(address => uint256) public lastRequest;
uint256 public cooldown = 1 days;
function requestToken() public returns (bool) {
require(block.timestamp - lastRequest[msg.sender] > cooldown, "Cooldown period active");
lastRequest[msg.sender] = block.timestamp;
return true;
}
}
function getActions(uint proposalId)
public
view
returns (
address[] memory targets,
uint[] memory values,
string[] memory signatures,
bytes[] memory calldatas
)CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
uint proposalId = 123;
(address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas) = gov.getActions(proposalId);const proposalId = 123;
const {0: targets, 1: values, 2: signatures, 3: calldatas} = await gov.methods.getActions(proposalId).call();const { NodeInterface__factory } = require("@onyx/sdk/dist/lib/abi/factories/NodeInterface__factory");
const { NODE_INTERFACE_ADDRESS } = require("@onyx/sdk/dist/lib/dataEntities/constants");
const nodeInterface = NodeInterface__factory.connect(NODE_INTERFACE_ADDRESS, baseL2Provider);
const gasEstimateComponents = await nodeInterface.callStatic.gasEstimateComponents(
destinationAddress,
false,
txData,
{ blockTag: 'latest' }
);
const l1GasEstimated = gasEstimateComponents.gasEstimateForL1;
const l2GasUsed = gasEstimateComponents.gasEstimate.sub(gasEstimateComponents.gasEstimateForL1);
const l2EstimatedPrice = gasEstimateComponents.baseFee;
const l1EstimatedPrice = gasEstimateComponents.l1BaseFeeEstimate.mul(16);
const l1Cost = l1GasEstimated.mul(l2EstimatedPrice);
const l1Size = l1Cost.div(l1EstimatedPrice);
const P = l2EstimatedPrice;
const L2G = l2GasUsed;
const L1P = l1EstimatedPrice;
const L1S = l1Size;
const L1C = L1P.mul(L1S);
const B = L1C.div(P);
const G = L2G.add(B);
const TXFEES = P.mul(G);Get step by step instructions on how to run a full-node on Onyx
Season One of Onyx Points Program Whitelisted Assets
proposalMaxOperations()--parent-chain.connection.url=<BASE_RPC_URL>--chain.info-json=<PATH_OR_INLINE_JSON>--chain.name=conduit-orbit-deployer--execution.forwarding-target=<SEQUENCER_RPC_URL>--node.data-availability.enable
--node.data-availability.rest-aggregator.enable--node.data-availability.rest-aggregator.urls=<DAS_URL_1>,<DAS_URL_2>--node.data-availability.rest-aggregator.online-url-list=<DAS_URL_LIST_ENDPOINT>--http.addr=0.0.0.0
--http.vhosts=*
--http.api=net,web3,eth
--http.corsdomain=*
--ws.addr=0.0.0.0
--ws.port=8548
--ws.origins=*mkdir -p /data/arbitrum
chmod -R 777 /data/arbitrum/home/user/.arbitrumdocker run --rm -it \
-v /data/arbitrum:/home/user/.arbitrum \
-p 0.0.0.0:8547:8547 \
-p 0.0.0.0:8548:8548 \
offchainlabs/nitro-node:v3.4.0-d896e9c \
--parent-chain.connection.url=<BASE_RPC_URL> \
--chain.id=80888 \
--chain.name=conduit-orbit-deployer \
--chain.info-json=<CHAIN_INFO_JSON> \
--execution.forwarding-target=<SEQUENCER_RPC_URL> \
--node.data-availability.enable \
--node.data-availability.rest-aggregator.enable \
--node.data-availability.rest-aggregator.urls=<DAS_URLS> \
--http.api=net,web3,eth \
--http.addr=0.0.0.0 \
--http.vhosts=* \
--http.corsdomain=* \
--ws.addr=0.0.0.0 \
--ws.port=8548 \
--ws.origins=*--node.feed.input.url=<SEQUENCER_FEED_URL>--node.feed.output.enable=true \
--node.feed.output.addr=<SEQUENCER_FEED_ADDR> \
--node.feed.output.port=<SEQUENCER_FEED_PORT>docker stop --time=300 $(docker ps -aq)--helpfunction proposalMaxOperations() public pure returns (uint)CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
uint operations = gov.proposalMaxOperations();const operations = await gov.methods.proposalMaxOperations().call();

castVoteWithReason function (if available) is used.function castVote(uint proposalId, bool support) publicCHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
gov.castVote(proposalId, true); // Voting in favor of the proposalconst tx = await gov.methods.castVote(proposalId, false).send({ from: sender }); // Voting against the proposal