Проверенный контрактТочноеApache-2.0-or-later
RigoblockGovernanceStrategy
Адрес0xd2793d8a9cafd7f5650bae6fd5bd64a00a6cf2c3
- Баланс
0 ETH
- Транзакций
0
- Компилятор
solc 0.8.37
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.37+commit.f401782d
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- cancun
- Лицензия
- Apache-2.0-or-later
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 096 507
- Транзакция создания
- 0x69d0eb23db…5f90f68e07
16 файлов
- project/contracts/governance/strategies/RigoblockGovernanceStrategy.solглавный11,47 КБ
- project/contracts/governance/interfaces/IGovernanceStrategy.sol4,07 КБ
- project/contracts/governance/interfaces/IRigoblockGovernanceFactory.sol2,57 КБ
- project/contracts/governance/interfaces/governance/IGovernanceEvents.sol1,8 КБ
- project/contracts/governance/interfaces/governance/IGovernanceState.sol3,06 КБ
- project/contracts/governance/interfaces/governance/IGovernanceVoting.sol1,53 КБ
- project/contracts/governance/types/GovernanceTypes.sol1,75 КБ
- project/contracts/governance/types/TimeType.sol410 Б
- project/contracts/protocol/interfaces/IPoolRegistry.sol4,2 КБ
- project/contracts/rigoToken/interfaces/IRigoToken.sol2,06 КБ
- project/contracts/staking/interfaces/IGrgVault.sol4,08 КБ
- project/contracts/staking/interfaces/IStaking.sol10,38 КБ
- project/contracts/staking/interfaces/IStorage.sol4,91 КБ
- project/contracts/staking/interfaces/IStructs.sol3,72 КБ
- project/contracts/tokens/ERC20/IERC20.sol2,36 КБ
- project/lib/wormhole-solidity-sdk/src/interfaces/ICoreBridge.sol2,76 КБ
project/contracts/governance/strategies/RigoblockGovernanceStrategy.sol
// SPDX-License-Identifier: Apache-2.0-or-later
pragma solidity 0.8.37;
import {ICoreBridge} from "wormhole-solidity-sdk/src/interfaces/ICoreBridge.sol";
import {CrossChainPayload, ProposalStatus} from "../types/GovernanceTypes.sol";
import {IGovernanceState} from "../interfaces/governance/IGovernanceState.sol";
import {IGovernanceStrategy} from "../interfaces/IGovernanceStrategy.sol";
import {IGovernanceVoting} from "../interfaces/governance/IGovernanceVoting.sol";
import {IRigoblockGovernanceFactory} from "../interfaces/IRigoblockGovernanceFactory.sol";
import {IStaking} from "../../staking/interfaces/IStaking.sol";
import {IStorage} from "../../staking/interfaces/IStorage.sol";
import {IStructs} from "../../staking/interfaces/IStructs.sol";
import {TimeType} from "../types/TimeType.sol";
/// @dev Reverts on any time type other than TimeType.Timestamp: see docs/governance/STRATEGY.md.
contract RigoblockGovernanceStrategy is IGovernanceStrategy {
/// @notice Wormhole core contract on the same chain as this strategy.
address private immutable _wormhole;
/// @notice Wormhole chain id of the chain this strategy is deployed on.
uint16 private immutable _wormholeChainId;
address private immutable _stakingProxy;
uint256 private immutable _votingPeriod;
/// @notice Thrown when a Wormhole cross-chain action has malformed calldata.
error GovCrosschainInvalidData();
/// @notice Thrown when a Wormhole cross-chain action targets the current chain.
error GovCrosschainTargetSelf(uint16 targetChainId);
/// @notice Thrown when a Wormhole cross-chain proposal is created outside Ethereum mainnet.
error GovCrosschainNotMainnet();
/// @notice Thrown when a Wormhole cross-chain action carries a non-zero wrapper value.
/// @dev The inner action value is paid on the destination chain from the receiver's balance,
/// so the wrapper must be zero and the Wormhole fee is attached at execution time only.
error GovCrosschainInvalidValue(uint256 value);
/// @notice Thrown when a Wormhole message is published with a consistency level other than finalized.
/// @param consistencyLevel The supplied consistency level.
error GovCrosschainInvalidConsistencyLevel(uint8 consistencyLevel);
/// @notice Thrown when the proposal threshold is outside the allowed range.
error GovStrategyInvalidProposalThreshold(uint256 proposalThreshold, uint256 floor, uint256 cap);
/// @notice Thrown when the quorum threshold is outside the allowed range.
error GovStrategyInvalidQuorumThreshold(uint256 quorumThreshold, uint256 floor, uint256 cap);
/// @notice Thrown when the governance time type is not TimeType.Timestamp.
error GovStrategyInvalidTimeType(TimeType timeType);
constructor(address stakingProxy, address wormhole, uint16 wormholeChainId) {
_stakingProxy = stakingProxy;
_wormhole = wormhole;
_wormholeChainId = wormholeChainId;
_votingPeriod = 7 days;
}
/// @inheritdoc IGovernanceStrategy
function assertValidInitParams(IRigoblockGovernanceFactory.Parameters memory params) external view override {
_assertTimestamp(params.timeType);
assert(keccak256(abi.encodePacked(params.name)) == keccak256(abi.encodePacked(string("Rigoblock Governance"))));
_assertValidProposalThreshold(params.proposalThreshold);
_assertValidQuorumThreshold(params.quorumThreshold);
}
/// @inheritdoc IGovernanceStrategy
function assertValidProposalThreshold(uint256 proposalThreshold) public view override {
_assertValidProposalThreshold(proposalThreshold);
}
/// @inheritdoc IGovernanceStrategy
function assertValidQuorumThreshold(uint256 quorumThreshold) public view override {
_assertValidQuorumThreshold(quorumThreshold);
}
/// @inheritdoc IGovernanceStrategy
function getProposalState(
IGovernanceState.Proposal memory proposal,
uint256 minimumQuorum,
TimeType timeType
) external view override returns (ProposalStatus) {
_assertTimestamp(timeType);
// notice: because in rigoblock staking we use epochs, the exact start time will never perfectly match the new epoch
// using timestamps instead of epoch is a safeguard for upgrades, should the staking system get stuck by being unable to finalize.
uint256 time = block.timestamp;
if (time <= proposal.startBlockOrTime) {
return ProposalStatus.Pending;
} else if (time <= proposal.endBlockOrTime && _qualifiedConsensus(proposal, minimumQuorum)) {
return ProposalStatus.Qualified;
} else if (time <= proposal.endBlockOrTime) {
return ProposalStatus.Active;
} else if (proposal.votesFor <= 2 * proposal.votesAgainst || proposal.votesFor < minimumQuorum) {
return ProposalStatus.Defeated;
} else if (proposal.executed) {
return ProposalStatus.Executed;
} else {
return ProposalStatus.Succeeded;
}
}
function _qualifiedConsensus(
IGovernanceState.Proposal memory proposal,
uint256 minimumQuorum
) private view returns (bool) {
return (3 * proposal.votesFor >
2 *
IStaking(_getStakingProxy())
.getGlobalStakeByStatus(IStructs.StakeStatus.DELEGATED)
.currentEpochBalance &&
proposal.votesFor >= minimumQuorum);
}
/// @inheritdoc IGovernanceStrategy
function getVotingPower(address account) public view override returns (uint256) {
return
IStaking(_getStakingProxy())
.getOwnerStakeByStatus(account, IStructs.StakeStatus.DELEGATED)
.currentEpochBalance;
}
/// @inheritdoc IGovernanceStrategy
function votingPeriod() public view override returns (uint256) {
uint256 stakingEpochDuration = IStorage(_getStakingProxy()).epochDurationInSeconds();
return stakingEpochDuration < _votingPeriod ? stakingEpochDuration : _votingPeriod;
}
/// @inheritdoc IGovernanceStrategy
function votingTimestamps(
TimeType timeType
) public view override returns (uint256 startBlockOrTime, uint256 endBlockOrTime) {
_assertTimestamp(timeType);
startBlockOrTime = IStaking(_getStakingProxy()).getCurrentEpochEarliestEndTimeInSeconds();
// we require voting starts next block to prevent instant upgrade
startBlockOrTime = block.timestamp >= startBlockOrTime ? block.timestamp + 1 : startBlockOrTime;
endBlockOrTime = startBlockOrTime + votingPeriod();
}
/// @dev Reverts unless the governance uses TimeType.Timestamp.
function _assertTimestamp(TimeType timeType) private pure {
require(timeType == TimeType.Timestamp, GovStrategyInvalidTimeType(timeType));
}
function _assertValidProposalThreshold(uint256 proposalThreshold) private view {
uint256 grgTotalSupply = IStaking(_getStakingProxy()).getGrgContract().totalSupply();
uint256 chainId = block.chainid;
// between 1 and 2% of total supply
uint256 floor = grgTotalSupply / 100;
uint256 cap = grgTotalSupply / 50;
// hard limits on altchains
if (chainId != 1) {
floor = floor < 20_000e18 ? 20_000e18 : floor;
cap = cap < 100_000e18 ? 100_000e18 : cap;
}
require(
proposalThreshold >= floor && proposalThreshold <= cap,
GovStrategyInvalidProposalThreshold(proposalThreshold, floor, cap)
);
}
function _assertValidQuorumThreshold(uint256 quorumThreshold) private view {
uint256 grgTotalSupply = IStaking(_getStakingProxy()).getGrgContract().totalSupply();
uint256 chainId = block.chainid;
// between 4 and 10% of total supply
uint256 floor = grgTotalSupply / 25;
uint256 cap = grgTotalSupply / 10;
// hard limits on altchains
if (chainId != 1) {
floor = floor < 100_000e18 ? 100_000e18 : floor;
cap = cap < 400_000e18 ? 400_000e18 : cap;
}
require(
quorumThreshold >= floor && quorumThreshold <= cap,
GovStrategyInvalidQuorumThreshold(quorumThreshold, floor, cap)
);
}
/// @inheritdoc IGovernanceStrategy
function beforePropose(
IGovernanceVoting.ProposedAction calldata action
) external view override returns (IGovernanceVoting.ProposedAction memory) {
if (action.target != _wormhole) {
return action;
}
// Cross-chain proposals are only allowed from Ethereum mainnet
require(block.chainid == 1, GovCrosschainNotMainnet());
// The wrapped action value is paid on the destination chain from the receiver's own
// balance; Wormhole's fee is added at execution time in beforeExecute instead.
require(action.value == 0, GovCrosschainInvalidValue(action.value));
_assertValidWormholeData(action.data);
return action;
}
/// @notice Decodes a Wormhole publishMessage call and validates its inner payload.
/// @dev Enforced at proposal time on the sender chain: every inner action must carry no
/// value, as the governance is expected to hold no native balance on receiver chains.
function _assertValidWormholeData(bytes calldata data) private view {
require(data.length >= 4 && bytes4(data) == ICoreBridge.publishMessage.selector, GovCrosschainInvalidData());
(, bytes memory payload, uint8 consistencyLevel) = abi.decode(data[4:], (uint32, bytes, uint8));
// 200 is Wormhole's finalized consistency level: mainnet votes must reach finality before attestation
require(consistencyLevel == 200, GovCrosschainInvalidConsistencyLevel(consistencyLevel));
CrossChainPayload memory crossChainPayload = abi.decode(payload, (CrossChainPayload));
require(
crossChainPayload.targetWormholeChainId != _wormholeChainId,
GovCrosschainTargetSelf(crossChainPayload.targetWormholeChainId)
);
for (uint256 i = 0; i < crossChainPayload.actions.length; i++) {
require(
crossChainPayload.actions[i].value == 0,
GovCrosschainInvalidValue(crossChainPayload.actions[i].value)
);
}
}
/// @inheritdoc IGovernanceStrategy
function beforeExecute(
IGovernanceVoting.ProposedAction memory action
) external view override returns (IGovernanceVoting.ProposedAction memory) {
if (action.target != _wormhole) {
return action;
}
// Wormhole requires msg.value == messageFee() on publishMessage, so the wrapper value
// must be exactly the fee, overriding any (zero) value set at proposal time.
action.value = ICoreBridge(_wormhole).messageFee();
return action;
}
/// @inheritdoc IGovernanceStrategy
function wormhole() external view override returns (address) {
return _wormhole;
}
/// @inheritdoc IGovernanceStrategy
function wormholeChainId() external view override returns (uint16) {
return _wormholeChainId;
}
/// @notice It is more gas efficient at deploy to reading immutable from internal method.
function _getStakingProxy() private view returns (address) {
return _stakingProxy;
}
}
project/contracts/governance/interfaces/IGovernanceStrategy.sol
// SPDX-License-Identifier: Apache-2.0-or-later
pragma solidity ^0.8.0;
import {IGovernanceState} from "./governance/IGovernanceState.sol";
import {IGovernanceVoting} from "./governance/IGovernanceVoting.sol";
import {IRigoblockGovernanceFactory} from "./IRigoblockGovernanceFactory.sol";
import {ProposalStatus} from "../types/GovernanceTypes.sol";
import {TimeType} from "../types/TimeType.sol";
interface IGovernanceStrategy {
/// @notice Reverts if initialization paramters are incorrect.
/// @dev Only used at initialization, as params deleted from factory storage after setup.
/// @param params Tuple of factory parameters.
function assertValidInitParams(IRigoblockGovernanceFactory.Parameters calldata params) external view;
/// @notice Reverts if the proposal threshold is incorrect.
/// @param proposalThreshold Number of votes required to make a proposal.
function assertValidProposalThreshold(uint256 proposalThreshold) external view;
/// @notice Reverts if the quorum threshold is incorrect.
/// @param quorumThreshold Number of votes required for a proposal to succeed.
function assertValidQuorumThreshold(uint256 quorumThreshold) external view;
/// @notice Returns the state of a proposal for a required quorum.
/// @dev Must use the same time reference as `timeType` and revert for unsupported time types.
/// See docs/governance/STRATEGY.md.
/// @param proposal Tuple of the proposal.
/// @param minimumQuorum Number of votes required for a proposal to pass.
/// @param timeType Time reference used by the proposal's voting period.
/// @return Tuple of the proposal state.
function getProposalState(
IGovernanceState.Proposal calldata proposal,
uint256 minimumQuorum,
TimeType timeType
) external view returns (ProposalStatus);
/// @notice Return the voting period.
/// @dev Informational only: the enforceable window is the one returned by votingTimestamps.
/// @return Number of blocks or seconds of period duration, matching the governance's time type.
function votingPeriod() external view returns (uint256);
/// @notice Returns the voting timestamps.
/// @dev Must produce start/end values expressed in the same unit as `timeType` (block numbers
/// for TimeType.Blocknumber, timestamps for TimeType.Timestamp). See getProposalState.
/// @param timeType Time reference used by the proposal's voting period.
/// @return startBlockOrTime Timestamp when proposal starts.
/// @return endBlockOrTime Timestamp when voting ends.
function votingTimestamps(
TimeType timeType
) external view returns (uint256 startBlockOrTime, uint256 endBlockOrTime);
/// @notice Return a user's voting power.
/// @param account Address to check votes for.
function getVotingPower(address account) external view returns (uint256);
/// @notice Validates and optionally modifies an action before it is stored as part of a proposal.
/// @param action The action to validate.
/// @return The validated (possibly modified) action.
function beforePropose(
IGovernanceVoting.ProposedAction calldata action
) external view returns (IGovernanceVoting.ProposedAction memory);
/// @notice Returns the action as it should be executed, optionally modifying the value.
/// @param action The action to execute.
/// @return The action to execute.
function beforeExecute(
IGovernanceVoting.ProposedAction calldata action
) external view returns (IGovernanceVoting.ProposedAction memory);
/// @notice Returns the Wormhole core contract used for cross-chain governance.
/// @return Address of the Wormhole core contract, or the zero address if this chain is not
/// configured as a cross-chain governance receiver.
function wormhole() external view returns (address);
/// @notice Returns the Wormhole chain id of the chain this strategy is deployed on.
function wormholeChainId() external view returns (uint16);
}
project/contracts/governance/interfaces/IRigoblockGovernanceFactory.sol
// SPDX-License-Identifier: Apache-2.0-or-later
/*
Copyright 2017-2022 RigoBlock, Rigo Investment Sagl, Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.0;
import {TimeType} from "../types/TimeType.sol";
// solhint-disable-next-line
interface IRigoblockGovernanceFactory {
/// @notice Emitted when a governance is created.
/// @param governance Address of the governance proxy.
event GovernanceCreated(address governance);
/// @notice Creates a new governance proxy.
/// @param implementation Address of the governance implementation contract.
/// @param governanceStrategy Address of the voting strategy.
/// @param proposalThreshold Number of votes required for creating a new proposal.
/// @param quorumThreshold Number of votes required for execution.
/// @param timeType Enum of time type (block number or timestamp).
/// @param name Human readable string of the name.
/// @return governance Address of the new governance.
function createGovernance(
address implementation,
address governanceStrategy,
uint256 proposalThreshold,
uint256 quorumThreshold,
TimeType timeType,
string calldata name
) external returns (address governance);
struct Parameters {
/// @notice Address of the governance implementation contract.
address implementation;
/// @notice Address of the voting strategy.
address governanceStrategy;
/// @notice Number of votes required for creating a new proposal.
uint256 proposalThreshold;
/// @notice Number of votes required for execution.
uint256 quorumThreshold;
/// @notice Type of time chosed, block number of timestamp.
TimeType timeType;
/// @notice String of the name of the application.
string name;
}
/// @notice Returns the governance initialization parameters at proxy deploy.
/// @return Tuple of the governance parameters.
function parameters() external view returns (Parameters memory);
}
project/contracts/governance/interfaces/governance/IGovernanceEvents.sol
// SPDX-License-Identifier: Apache-2.0-or-later
pragma solidity ^0.8.0;
import "./IGovernanceVoting.sol";
interface IGovernanceEvents {
/// @notice Emitted when a new proposal is created.
/// @param proposer Address of the proposer.
/// @param proposalId Number of the proposal.
/// @param actions Struct array of actions (targets, datas, values).
/// @param startBlockOrTime Timestamp in seconds after which proposal can be voted on.
/// @param endBlockOrTime Timestamp in seconds after which proposal can be executed.
/// @param description String description of proposal.
event ProposalCreated(
address proposer,
uint256 proposalId,
IGovernanceVoting.ProposedAction[] actions,
uint256 startBlockOrTime,
uint256 endBlockOrTime,
string description
);
/// @notice Emmited when the governance strategy is upgraded.
/// @param newStrategy Address of the new strategy contract.
event StrategyUpgraded(address newStrategy);
/// @notice Emitted when implementation written to proxy storage.
/// @dev Emitted also at first variable initialization.
/// @param newImplementation Address of the new implementation.
event Upgraded(address indexed newImplementation);
/// @notice Emitted when a voter votes.
/// @param voter Address of the voter.
/// @param proposalId Number of the proposal.
/// @param voteType Number of vote type.
/// @param votingPower Number of votes.
event VoteCast(address voter, uint256 proposalId, IGovernanceVoting.VoteType voteType, uint256 votingPower);
/// @notice Emitted when the proposal threshold is updated.
/// @param proposalThreshold The new proposal threshold.
event ProposalThresholdSet(uint256 proposalThreshold);
}
project/contracts/governance/interfaces/governance/IGovernanceState.sol
// SPDX-License-Identifier: Apache-2.0-or-later
pragma solidity ^0.8.0;
import "./IGovernanceVoting.sol";
import {ProposalStatus} from "../../types/GovernanceTypes.sol";
import {TimeType} from "../../types/TimeType.sol";
interface IGovernanceState {
struct Proposal {
uint256 actionsLength;
uint256 startBlockOrTime;
uint256 endBlockOrTime;
uint256 votesFor;
uint256 votesAgainst;
uint256 votesAbstain;
bool executed;
}
struct ProposalWrapper {
Proposal proposal;
IGovernanceVoting.ProposedAction[] proposedAction;
}
/// @notice Returns the actions proposed for a given proposal.
/// @param proposalId Number of the proposal.
/// @return proposedActions Array of tuple of proposed actions.
function getActions(
uint256 proposalId
) external view returns (IGovernanceVoting.ProposedAction[] memory proposedActions);
/// @notice Returns a proposal for a given id.
/// @param proposalId The number of the proposal.
/// @return proposalWrapper Tuple wrapper of the proposal and proposed actions tuples.
function getProposalById(uint256 proposalId) external view returns (ProposalWrapper memory proposalWrapper);
/// @notice Returns the state of a proposal.
/// @param proposalId Number of the proposal.
/// @return Number of proposal state.
function getProposalState(uint256 proposalId) external view returns (ProposalStatus);
struct Receipt {
bool hasVoted;
uint96 votes;
IGovernanceVoting.VoteType voteType;
}
/// @notice Returns the receipt of a voter for a given proposal.
/// @param proposalId Number of the proposal.
/// @param voter Address of the voter.
/// @return Tuple of voter receipt.
function getReceipt(uint256 proposalId, address voter) external view returns (Receipt memory);
/// @notice Computes the current voting power of the given account.
/// @param account The address of the account.
/// @return votingPower The current voting power of the given account.
function getVotingPower(address account) external view returns (uint256 votingPower);
struct GovernanceParameters {
address strategy;
uint256 proposalThreshold;
uint256 quorumThreshold;
TimeType timeType;
}
struct EnhancedParams {
GovernanceParameters params;
string name;
string version;
}
/// @notice Returns the governance parameters.
/// @return Tuple of the governance parameters.
function governanceParameters() external view returns (EnhancedParams memory);
/// @notice Returns the total number of proposals.
/// @return count The number of proposals.
function proposalCount() external view returns (uint256 count);
/// @notice Returns all proposals ever made to the governance.
/// @return proposalWrapper Tuple array of all governance proposals.
function proposals() external view returns (ProposalWrapper[] memory proposalWrapper);
}
project/contracts/governance/interfaces/governance/IGovernanceVoting.sol
// SPDX-License-Identifier: Apache-2.0-or-later
pragma solidity ^0.8.0;
import "./IGovernanceEvents.sol";
interface IGovernanceVoting {
// Values match the OpenZeppelin support values. See docs/governance/TALLY_COMPAT.md.
enum VoteType {
Against,
For,
Abstain
}
/// @notice Executes a proposal that has passed and is currently executable.
/// @param proposalId The ID of the proposal to execute.
function execute(uint256 proposalId) external payable;
/// @notice Cancels a proposal that has not started voting yet.
/// @dev Only the proposer can cancel, and only while the proposal is Pending. A canceled
/// proposal cannot be voted on or executed. Cancelling does not consume the proposal id.
/// @param proposalId The ID of the proposal to cancel.
function cancel(uint256 proposalId) external;
struct ProposedAction {
address target;
bytes data;
uint256 value;
}
/// @notice Creates a proposal on the the given actions. Must have at least `proposalThreshold`.
/// @dev Must have at least `proposalThreshold` of voting power to call this function.
/// @param actions The proposed actions. An action specifies a contract call.
/// @param description A text description for the proposal.
/// @return proposalId The ID of the newly created proposal.
function propose(
ProposedAction[] calldata actions,
string calldata description
) external returns (uint256 proposalId);
}
project/contracts/governance/types/GovernanceTypes.sol
// SPDX-License-Identifier: Apache-2.0-or-later
pragma solidity ^0.8.0;
import {IGovernanceVoting} from "../interfaces/governance/IGovernanceVoting.sol";
/// @title GovernanceTypes - Shared types for governance.
/// @notice This file holds types that are not already declared inside the public
/// governance interfaces, which must keep their types as interface members
/// for backwards compatibility with deployed contracts.
/// The native proposal-state enum lives here under the name `ProposalStatus`:
/// two inherited enums cannot share the `ProposalState` name (solc 9097
/// "Identifier already declared" — see `IRigoblockGovernance`, which inherits
/// both `IGovernanceState` and OZ's `IGovernor`), and a name distinct from
/// the OZ enum keeps every use site unambiguous.
/// @notice Native Rigoblock proposal states, a superset of the OZ Governor numbering
/// (adds Qualified). Encoded as uint8; value numbering is part of the
/// externally observable surface and must never change.
enum ProposalStatus {
Pending,
Active,
Canceled,
Qualified,
Defeated,
Succeeded,
Queued,
Expired,
Executed
}
/// @notice Payload delivered through Wormhole to a target-chain receiver.
/// @param targetWormholeChainId Wormhole chain id of the target chain.
/// @param proposalId Mainnet proposal id that produced the message.
/// @param actions Actions to execute on the target chain, in order. Actions may target
/// external contracts or the governance itself (e.g. implementation upgrades).
struct CrossChainPayload {
uint16 targetWormholeChainId;
uint256 proposalId;
IGovernanceVoting.ProposedAction[] actions;
}
project/contracts/governance/types/TimeType.sol
// SPDX-License-Identifier: Apache-2.0-or-later
pragma solidity ^0.8.0;
/// @notice Time reference type for governance voting periods.
/// @dev Declared at file level so that factories and proxies can import it without
/// depending on the governance interfaces, keeping their init code (and CREATE2
/// addresses) stable when the interfaces evolve.
enum TimeType {
Blocknumber,
Timestamp
}
project/contracts/protocol/interfaces/IPoolRegistry.sol
// SPDX-License-Identifier: Apache 2.0
/*
Copyright 2017-2022 RigoBlock, Rigo Investment Sagl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity >=0.7.0 <0.9.0;
/// @title Pool Registry Interface - Allows external interaction with pool registry.
/// @author Gabriele Rigo - <[email protected]>
// solhint-disable-next-line
interface IPoolRegistry {
/// @notice Mapping of pool meta by pool key.
/// @param meta Mapping of bytes32 key to bytes32 meta.
struct PoolMeta {
mapping(bytes32 => bytes32) meta;
}
/// @notice Emitted when Rigoblock Dao updates authority address.
/// @param authority Address of the new authority contract.
event AuthorityChanged(address indexed authority);
/// @notice Emitted when pool owner updates meta data for its pool.
/// @param pool Address of the pool.
/// @param key Bytes32 key for indexing.
/// @param value Bytes32 of the value associated with the key.
event MetaChanged(address indexed pool, bytes32 indexed key, bytes32 value);
/// @notice Emitted when a new pool is registered in registry.
/// @param group Address of the pool factory.
/// @param pool Address of the registered pool.
/// @param name String name of the pool.
/// @param symbol String name of the pool.
/// @param id Bytes32 id of the pool.
event Registered(
address indexed group,
address pool,
bytes32 indexed name, // client can prune sybil pools
bytes32 indexed symbol,
bytes32 id
);
/// @notice Emitted when rigoblock Dao address is updated.
/// @param rigoblockDao New Dao address.
event RigoblockDaoChanged(address indexed rigoblockDao);
/// @notice Returns the address of the Rigoblock authority contract.
/// @return Address of the authority contract.
function authority() external view returns (address);
/// @notice Returns the address of the Rigoblock Dao.
/// @return Address of the Rigoblock Dao.
function rigoblockDao() external view returns (address);
/// @notice Allows a factory which is an authority to register a pool.
/// @param pool Address of the pool.
/// @param name String name of the pool (31 characters/bytes or less).
/// @param symbol String symbol of the pool (3 to 5 characters/bytes).
/// @param poolId Bytes32 of the pool id.
function register(
address pool,
string calldata name,
string calldata symbol,
bytes32 poolId
) external;
/// @notice Allows Rigoblock governance to update authority.
/// @param authority Address of the authority contract.
function setAuthority(address authority) external;
/// @notice Allows pool owner to set metadata for a pool.
/// @param pool Address of the pool.
/// @param key Bytes32 of the key.
/// @param value Bytes32 of the value.
function setMeta(
address pool,
bytes32 key,
bytes32 value
) external;
/// @notice Allows Rigoblock Dao to update its address.
/// @dev Creates internal record.
/// @param newRigoblockDao Address of the Rigoblock Dao.
function setRigoblockDao(address newRigoblockDao) external;
/// @notice Returns metadata for a given pool.
/// @param pool Address of the pool.
/// @param key Bytes32 key.
/// @return poolMeta Meta by key.
function getMeta(address pool, bytes32 key) external view returns (bytes32 poolMeta);
/// @notice Returns the id of a pool from its address.
/// @param pool Address of the pool.
/// @return poolId bytes32 id of the pool.
function getPoolIdFromAddress(address pool) external view returns (bytes32 poolId);
}
project/contracts/rigoToken/interfaces/IRigoToken.sol
// SPDX-License-Identifier: Apache 2.0
/*
Copyright 2017-2018 RigoBlock, Rigo Investment Sagl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity >=0.8.0 <0.9.0;
import "../../tokens/ERC20/IERC20.sol";
/// @title Rigo Token Interface - Allows interaction with the Rigo token.
/// @author Gabriele Rigo - <[email protected]>
// solhint-disable-next-line
interface IRigoToken is IERC20 {
/// @notice Emitted when new tokens have been minted.
/// @param recipient Address receiving the new tokens.
/// @param amount Number of minted units.
event TokenMinted(address indexed recipient, uint256 amount);
/// @notice Returns the address of the minter.
/// @return Address of the minter.
function minter() external view returns (address);
/// @notice Returns the address of the Rigoblock Dao.
/// @return Address of the Dao.
function rigoblock() external view returns (address);
/// @notice Allows minter to create new tokens.
/// @dev Mint method is reserved for minter module.
/// @param recipient Address receiving the new tokens.
/// @param amount Number of minted tokens.
function mintToken(address recipient, uint256 amount) external;
/// @notice Allows Rigoblock Dao to update minter.
/// @param newAddress Address of the new minter.
function changeMintingAddress(address newAddress) external;
/// @notice Allows Rigoblock Dao to update its address.
/// @param newAddress Address of the new Dao.
function changeRigoblockAddress(address newAddress) external;
}
project/contracts/staking/interfaces/IGrgVault.sol
// SPDX-License-Identifier: Apache 2.0
/*
Original work Copyright 2019 ZeroEx Intl.
Modified work Copyright 2020-2022 Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity >=0.8.0 <0.9.0;
interface IGrgVault {
/// @notice Emmitted whenever a StakingProxy is set in a vault.
/// @param stakingProxyAddress Address of the staking proxy contract.
event StakingProxySet(address stakingProxyAddress);
/// @notice Emitted when the Staking contract is put into Catastrophic Failure Mode
/// @param sender Address of sender (`msg.sender`)
event InCatastrophicFailureMode(address sender);
/// @notice Emitted when Grg Tokens are deposited into the vault.
/// @param staker Address of the Grg staker.
/// @param amount of Grg Tokens deposited.
event Deposit(address indexed staker, uint256 amount);
/// @notice Emitted when Grg Tokens are withdrawn from the vault.
/// @param staker Address of the Grg staker.
/// @param amount of Grg Tokens withdrawn.
event Withdraw(address indexed staker, uint256 amount);
/// @notice Emitted whenever the Grg AssetProxy is set.
/// @param grgProxyAddress Address of the Grg transfer proxy.
event GrgProxySet(address grgProxyAddress);
/// @notice Sets the address of the StakingProxy contract.
/// @dev Note that only the contract staker can call this function.
/// @param stakingProxyAddress Address of Staking proxy contract.
function setStakingProxy(address stakingProxyAddress) external;
/// @notice Vault enters into Catastrophic Failure Mode.
/// @dev *** WARNING - ONCE IN CATOSTROPHIC FAILURE MODE, YOU CAN NEVER GO BACK! ***
/// @dev Note that only the contract staker can call this function.
function enterCatastrophicFailure() external;
/// @notice Sets the Grg proxy.
/// @dev Note that only the contract staker can call this.
/// @dev Note that this can only be called when *not* in Catastrophic Failure mode.
/// @param grgProxyAddress Address of the RigoBlock Grg Proxy.
function setGrgProxy(address grgProxyAddress) external;
/// @notice Deposit an `amount` of Grg Tokens from `staker` into the vault.
/// @dev Note that only the Staking contract can call this.
/// @dev Note that this can only be called when *not* in Catastrophic Failure mode.
/// @param staker Address of the Grg staker.
/// @param amount of Grg Tokens to deposit.
function depositFrom(address staker, uint256 amount) external;
/// @notice Withdraw an `amount` of Grg Tokens to `staker` from the vault.
/// @dev Note that only the Staking contract can call this.
/// @dev Note that this can only be called when *not* in Catastrophic Failure mode.
/// @param staker Address of the Grg staker.
/// @param amount of Grg Tokens to withdraw.
function withdrawFrom(address staker, uint256 amount) external;
/// @notice Withdraw ALL Grg Tokens to `staker` from the vault.
/// @dev Note that this can only be called when *in* Catastrophic Failure mode.
/// @param staker Address of the Grg staker.
function withdrawAllFrom(address staker) external returns (uint256);
/// @notice Returns the balance in Grg Tokens of the `staker`
/// @param staker Address of the Grg staker.
/// @return Balance in Grg.
function balanceOf(address staker) external view returns (uint256);
/// @notice Returns the entire balance of Grg tokens in the vault.
/// @return Balance in Grg.
function balanceOfGrgVault() external view returns (uint256);
}
project/contracts/staking/interfaces/IStaking.sol
// SPDX-License-Identifier: Apache 2.0
/*
Original work Copyright 2019 ZeroEx Intl.
Modified work Copyright 2020-2022 Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity >=0.8.0 <0.9.0;
import {IPoolRegistry as PoolRegistry} from "../../protocol/interfaces/IPoolRegistry.sol";
import {IRigoToken as RigoToken} from "../../rigoToken/interfaces/IRigoToken.sol";
import "./IStructs.sol";
import {IGrgVault as GrgVault} from "./IGrgVault.sol";
interface IStaking {
/// @notice Adds a new proof_of_performance address.
/// @param addr Address of proof_of_performance contract to add.
function addPopAddress(address addr) external;
/// @notice Create a new staking pool. The sender will be the staking pal of this pool.
/// @dev Note that a staking pal must be payable.
/// @dev When governance updates registry address, pools must be migrated to new registry, or this contract must query from both.
/// @param rigoblockPoolAddress Adds rigoblock pool to the created staking pool for convenience if non-null.
/// @return poolId The unique pool id generated for this pool.
function createStakingPool(address rigoblockPoolAddress) external returns (bytes32 poolId);
/// @notice Allows the operator to update the staking pal address.
/// @param poolId Unique id of pool.
/// @param newStakingPalAddress Address of the new staking pal.
function setStakingPalAddress(bytes32 poolId, address newStakingPalAddress) external;
/// @notice Decreases the operator share for the given pool (i.e. increases pool rewards for members).
/// @param poolId Unique Id of pool.
/// @param newOperatorShare The newly decreased percentage of any rewards owned by the operator.
function decreaseStakingPoolOperatorShare(bytes32 poolId, uint32 newOperatorShare) external;
/// @notice Begins a new epoch, preparing the prior one for finalization.
/// @dev Throws if not enough time has passed between epochs or if the
/// @dev previous epoch was not fully finalized.
/// @return numPoolsToFinalize The number of unfinalized pools.
function endEpoch() external returns (uint256 numPoolsToFinalize);
/// @notice Instantly finalizes a single pool that earned rewards in the previous epoch,
/// @dev crediting it rewards for members and withdrawing operator's rewards as GRG.
/// @dev This can be called by internal functions that need to finalize a pool immediately.
/// @dev Does nothing if the pool is already finalized or did not earn rewards in the previous epoch.
/// @param poolId The pool ID to finalize.
function finalizePool(bytes32 poolId) external;
/// @notice Initialize storage owned by this contract.
/// @dev This function should not be called directly.
/// @dev The StakingProxy contract will call it in `attachStakingContract()`.
function init() external;
/// @notice Moves stake between statuses: 'undelegated' or 'delegated'.
/// @dev Delegated stake can also be moved between pools.
/// @dev This change comes into effect next epoch.
/// @param from Status to move stake out of.
/// @param to Status to move stake into.
/// @param amount Amount of stake to move.
function moveStake(
IStructs.StakeInfo calldata from,
IStructs.StakeInfo calldata to,
uint256 amount
) external;
/// @notice Credits the value of a pool's pop reward.
/// @dev Only a known RigoBlock pop can call this method. See (MixinPopManager).
/// @param poolAccount The address of the rigoblock pool account.
/// @param popReward The pop reward.
function creditPopReward(address poolAccount, uint256 popReward) external payable;
/// @notice Removes an existing proof_of_performance address.
/// @param addr Address of proof_of_performance contract to remove.
function removePopAddress(address addr) external;
/// @notice Set all configurable parameters at once.
/// @param _epochDurationInSeconds Minimum seconds between epochs.
/// @param _rewardDelegatedStakeWeight How much delegated stake is weighted vs operator stake, in ppm.
/// @param _minimumPoolStake Minimum amount of stake required in a pool to collect rewards.
/// @param _cobbDouglasAlphaNumerator Numerator for cobb douglas alpha factor.
/// @param _cobbDouglasAlphaDenominator Denominator for cobb douglas alpha factor.
function setParams(
uint256 _epochDurationInSeconds,
uint32 _rewardDelegatedStakeWeight,
uint256 _minimumPoolStake,
uint32 _cobbDouglasAlphaNumerator,
uint32 _cobbDouglasAlphaDenominator
) external;
/// @notice Stake GRG tokens. Tokens are deposited into the GRG Vault.
/// @dev Unstake to retrieve the GRG. Stake is in the 'Active' status.
/// @param amount of GRG to stake.
function stake(uint256 amount) external;
/// @notice Unstake. Tokens are withdrawn from the GRG Vault and returned to the staker.
/// @dev Stake must be in the 'undelegated' status in both the current and next epoch in order to be unstaked.
/// @param amount of GRG to unstake.
function unstake(uint256 amount) external;
/// @notice Withdraws the caller's GRG rewards that have accumulated until the last epoch.
/// @param poolId Unique id of pool.
function withdrawDelegatorRewards(bytes32 poolId) external;
/// @notice Computes the reward balance in GRG of a specific member of a pool.
/// @param poolId Unique id of pool.
/// @param member The member of the pool.
/// @return reward Balance in GRG.
function computeRewardBalanceOfDelegator(bytes32 poolId, address member) external view returns (uint256 reward);
/// @notice Computes the reward balance in GRG of the operator of a pool.
/// @param poolId Unique id of pool.
/// @return reward Balance in GRG.
function computeRewardBalanceOfOperator(bytes32 poolId) external view returns (uint256 reward);
/// @notice Returns the earliest end time in seconds of this epoch.
/// @dev The next epoch can begin once this time is reached.
/// @dev Epoch period = [startTimeInSeconds..endTimeInSeconds)
/// @return Time in seconds.
function getCurrentEpochEarliestEndTimeInSeconds() external view returns (uint256);
/// @notice Gets global stake for a given status.
/// @param stakeStatus UNDELEGATED or DELEGATED
/// @return balance Global stake for given status.
function getGlobalStakeByStatus(IStructs.StakeStatus stakeStatus)
external
view
returns (IStructs.StoredBalance memory balance);
/// @notice Gets an owner's stake balances by status.
/// @param staker Owner of stake.
/// @param stakeStatus UNDELEGATED or DELEGATED
/// @return balance Owner's stake balances for given status.
function getOwnerStakeByStatus(address staker, IStructs.StakeStatus stakeStatus)
external
view
returns (IStructs.StoredBalance memory balance);
/// @notice Returns the total stake for a given staker.
/// @param staker of stake.
/// @return Total GRG staked by `staker`.
function getTotalStake(address staker) external view returns (uint256);
/// @dev Retrieves all configurable parameter values.
/// @return _epochDurationInSeconds Minimum seconds between epochs.
/// @return _rewardDelegatedStakeWeight How much delegated stake is weighted vs operator stake, in ppm.
/// @return _minimumPoolStake Minimum amount of stake required in a pool to collect rewards.
/// @return _cobbDouglasAlphaNumerator Numerator for cobb douglas alpha factor.
/// @return _cobbDouglasAlphaDenominator Denominator for cobb douglas alpha factor.
function getParams()
external
view
returns (
uint256 _epochDurationInSeconds,
uint32 _rewardDelegatedStakeWeight,
uint256 _minimumPoolStake,
uint32 _cobbDouglasAlphaNumerator,
uint32 _cobbDouglasAlphaDenominator
);
/// @notice Returns stake delegated to pool by staker.
/// @param staker of stake.
/// @param poolId Unique Id of pool.
/// @return balance Stake delegated to pool by staker.
function getStakeDelegatedToPoolByOwner(address staker, bytes32 poolId)
external
view
returns (IStructs.StoredBalance memory balance);
/// @notice Returns a staking pool
/// @param poolId Unique id of pool.
function getStakingPool(bytes32 poolId) external view returns (IStructs.Pool memory);
/// @notice Get stats on a staking pool in this epoch.
/// @param poolId Pool Id to query.
/// @return PoolStats struct for pool id.
function getStakingPoolStatsThisEpoch(bytes32 poolId) external view returns (IStructs.PoolStats memory);
/// @notice Returns the total stake delegated to a specific staking pool, across all members.
/// @param poolId Unique Id of pool.
/// @return balance Total stake delegated to pool.
function getTotalStakeDelegatedToPool(bytes32 poolId) external view returns (IStructs.StoredBalance memory balance);
/// @notice An overridable way to access the deployed GRG contract.
/// @dev Must be view to allow overrides to access state.
/// @return The GRG contract instance.
function getGrgContract() external view returns (RigoToken);
/// @notice An overridable way to access the deployed grgVault.
/// @dev Must be view to allow overrides to access state.
/// @return The GRG vault contract.
function getGrgVault() external view returns (GrgVault);
/// @notice An overridable way to access the deployed rigoblock pool registry.
/// @dev Must be view to allow overrides to access state.
/// @return The pool registry contract.
function getPoolRegistry() external view returns (PoolRegistry);
}
project/contracts/staking/interfaces/IStorage.sol
// SPDX-License-Identifier: Apache 2.0
/*
Original work Copyright 2019 ZeroEx Intl.
Modified work Copyright 2020-2022 Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity >=0.8.0 <0.9.0;
interface IStorage {
/// @notice Address of staking contract.
/// @return stakingContract Address of the staking contract.
function stakingContract() external view returns (address);
/// @notice Mapping from RigoBlock pool subaccount to pool Id of rigoblock pool
/// @dev 0 RigoBlock pool subaccount address.
/// @return 0 The pool ID.
function poolIdByRbPoolAccount(address) external view returns (bytes32);
/// @notice mapping from pool ID to reward balance of members
/// @dev 0 Pool ID.
/// @return 0 The total reward balance of members in this pool.
function rewardsByPoolId(bytes32) external view returns (uint256);
/// @notice The current epoch.
/// @return currentEpoch The number of the current epoch.
function currentEpoch() external view returns (uint256);
/// @notice The current epoch start time.
/// @return currentEpochStartTimeInSeconds Timestamp of start time.
function currentEpochStartTimeInSeconds() external view returns (uint256);
/// @notice Registered RigoBlock Proof_of_Performance contracts, capable of paying protocol fees.
/// @dev 0 The address to check.
/// @return 0 Whether the address is a registered proof_of_performance.
function validPops(address popAddress) external view returns (bool);
/// @notice Minimum seconds between epochs.
/// @return epochDurationInSeconds Number of seconds.
function epochDurationInSeconds() external view returns (uint256);
// @notice How much delegated stake is weighted vs operator stake, in ppm.
/// @return rewardDelegatedStakeWeight Number in units of a million.
function rewardDelegatedStakeWeight() external view returns (uint32);
/// @notice Minimum amount of stake required in a pool to collect rewards.
/// @return minimumPoolStake Minimum amount required.
function minimumPoolStake() external view returns (uint256);
/// @notice Numerator for cobb douglas alpha factor.
/// @return cobbDouglasAlphaNumerator Number of the numerator.
function cobbDouglasAlphaNumerator() external view returns (uint32);
/// @notice Denominator for cobb douglas alpha factor.
/// @return cobbDouglasAlphaDenominator Number of the denominator.
function cobbDouglasAlphaDenominator() external view returns (uint32);
/// @notice Stats for each pool that generated fees with sufficient stake to earn rewards.
/// @dev See `_minimumPoolStake` in `MixinParams`.
/// @param key Pool ID.
/// @param epoch Epoch number.
/// @return feesCollected Amount of fees collected in epoch.
/// @return weightedStake Weighted stake per million.
/// @return membersStake Members stake per million.
function poolStatsByEpoch(bytes32 key, uint256 epoch)
external
view
returns (
uint256 feesCollected,
uint256 weightedStake,
uint256 membersStake
);
/// @notice Aggregated stats across all pools that generated fees with sufficient stake to earn rewards.
/// @dev See `_minimumPoolStake` in MixinParams.
/// @param epoch Epoch number.
/// @return rewardsAvailable Rewards (GRG) available to the epoch being finalized (the previous epoch).
/// @return numPoolsToFinalize The number of pools that have yet to be finalized through `finalizePools()`.
/// @return totalFeesCollected The total fees collected for the epoch being finalized.
/// @return totalWeightedStake The total fees collected for the epoch being finalized.
/// @return totalRewardsFinalized Amount of rewards that have been paid during finalization.
function aggregatedStatsByEpoch(uint256 epoch)
external
view
returns (
uint256 rewardsAvailable,
uint256 numPoolsToFinalize,
uint256 totalFeesCollected,
uint256 totalWeightedStake,
uint256 totalRewardsFinalized
);
/// @notice The GRG balance of this contract that is reserved for pool reward payouts.
/// @return grgReservedForPoolRewards Number of tokens reserved for rewards.
function grgReservedForPoolRewards() external view returns (uint256);
}
project/contracts/staking/interfaces/IStructs.sol
// SPDX-License-Identifier: Apache 2.0
/*
Original work Copyright 2019 ZeroEx Intl.
Modified work Copyright 2020-2022 Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity >=0.8.0 <0.9.0;
interface IStructs {
/// @notice Stats for a pool that earned rewards.
/// @param feesCollected Fees collected in ETH by this pool.
/// @param weightedStake Amount of weighted stake in the pool.
/// @param membersStake Amount of non-operator stake in the pool.
struct PoolStats {
uint256 feesCollected;
uint256 weightedStake;
uint256 membersStake;
}
/// @notice Holds stats aggregated across a set of pools.
/// @dev rewardsAvailable is simply the balanc of the contract at the end of the epoch.
/// @param rewardsAvailable Rewards (GRG) available to the epoch being finalized (the previous epoch).
/// @param numPoolsToFinalize The number of pools that have yet to be finalized through `finalizePools()`.
/// @param totalFeesCollected The total fees collected for the epoch being finalized.
/// @param totalWeightedStake The total fees collected for the epoch being finalized.
/// @param totalRewardsFinalized Amount of rewards that have been paid during finalization.
struct AggregatedStats {
uint256 rewardsAvailable;
uint256 numPoolsToFinalize;
uint256 totalFeesCollected;
uint256 totalWeightedStake;
uint256 totalRewardsFinalized;
}
/// @notice Encapsulates a balance for the current and next epochs.
/// @dev Note that these balances may be stale if the current epoch is greater than `currentEpoch`.
/// @param currentEpoch The current epoch
/// @param currentEpochBalance Balance in the current epoch.
/// @param nextEpochBalance Balance in `currentEpoch+1`.
struct StoredBalance {
uint64 currentEpoch;
uint96 currentEpochBalance;
uint96 nextEpochBalance;
}
/// @notice Statuses that stake can exist in.
/// @dev Any stake can be (re)delegated effective at the next epoch.
/// @dev Undelegated stake can be withdrawn if it is available in both the current and next epoch.
enum StakeStatus {
UNDELEGATED,
DELEGATED
}
/// @notice Info used to describe a status.
/// @param status Status of the stake.
/// @param poolId Unique Id of pool. This is set when status=DELEGATED.
struct StakeInfo {
StakeStatus status;
bytes32 poolId;
}
/// @notice Struct to represent a fraction.
/// @param numerator Numerator of fraction.
/// @param denominator Denominator of fraction.
struct Fraction {
uint256 numerator;
uint256 denominator;
}
/// @notice Holds the metadata for a staking pool.
/// @param operator Operator of the pool.
/// @param stakingPal Staking pal of the pool.
/// @param operatorShare Fraction of the total balance owned by the operator, in ppm.
/// @param stakingPalShare Fraction of the operator reward owned by the staking pal, in ppm.
struct Pool {
address operator;
address stakingPal;
uint32 operatorShare;
uint32 stakingPalShare;
}
}
project/contracts/tokens/ERC20/IERC20.sol
// SPDX-License-Identifier: Apache 2.0
pragma solidity >=0.5.0;
interface IERC20 {
/// @notice Emitted when a token is transferred.
/// @param from Address transferring the tokens.
/// @param to Address receiving the tokens.
/// @param value Number of token units.
event Transfer(address indexed from, address indexed to, uint256 value);
/// @notice Emitted when a token holder sets and approval.
/// @param owner Address of the account setting the approval.
/// @param spender Address of the allowed account.
/// @param value Number of approved units.
event Approval(address indexed owner, address indexed spender, uint256 value);
/// @notice Transfers token from holder to another address.
/// @param to Address to send tokens to.
/// @param value Number of token units to send.
/// @return success Bool the transaction was successful.
function transfer(address to, uint256 value) external returns (bool success);
/// @notice Allows spender to transfer tokens from the holder.
/// @param from Address of the token holder.
/// @param to Address to send tokens to.
/// @param value Number of units to transfer.
/// @return success Bool the transaction was successful.
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool success);
/// @notice Allows a holder to approve a spender.
/// @param spender Address of the token spender.
/// @param value Number of units to be approved.
/// @return success Bool the transaction was successful.
function approve(address spender, uint256 value) external returns (bool success);
/// @notice Returns token balance for an address.
/// @param who Address to query balance for.
/// @return Number of units held.
function balanceOf(address who) external view returns (uint256);
/// @notice Returns token allowance of an address to another address.
/// @param owner Address of token hodler.
/// @param spender Address of the token spender.
/// @return Number of allowed units.
function allowance(address owner, address spender) external view returns (uint256);
/// @notice Returns the total supply of the token.
/// @return Number of issued units.
function totalSupply() external view returns (uint256);
}
project/lib/wormhole-solidity-sdk/src/interfaces/ICoreBridge.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
// ╭─────────────────────────────────────────────────────────────╮
// │ For verification, consider using `CoreBridgeLib` │
// │ For encoding and decoding, consider using `VaaLib` │
// │ For replay protection, consider using `ReplayProtectionLib` │
// ╰─────────────────────────────────────────────────────────────╯
//slimmed down interface of the CoreBridge (aka the Wormhole contract)
struct GuardianSet {
address[] keys;
uint32 expirationTime;
}
struct GuardianSignature {
bytes32 r;
bytes32 s;
uint8 v;
uint8 guardianIndex;
}
//VM = Verified Message - legacy struct of the CoreBridge
//contains fields that are not relevant to the integrator:
// * version - always 1 regardless
// * signatures/guardianSetIndex - only the CoreBridge itself cares (for verification)
// * hash - NOT the VAA hash, but the hash of the hash! see warning at the top of VaaLib.sol!
// _finalized_ VAAs should use the unique (emitterChainId, emitterAddress, sequence) triple
// for cheaper replay protection, see SequenceReplayProtectionLib
struct CoreBridgeVM {
uint8 version;
uint32 timestamp;
uint32 nonce;
uint16 emitterChainId;
bytes32 emitterAddress;
uint64 sequence;
uint8 consistencyLevel;
bytes payload;
uint32 guardianSetIndex;
GuardianSignature[] signatures;
bytes32 hash; //see comment above
}
interface ICoreBridge {
event LogMessagePublished(
address indexed sender,
uint64 sequence,
uint32 nonce,
bytes payload,
uint8 consistencyLevel
);
// -- publishing --
function messageFee() external view returns (uint256);
//Note: This function requires a msg.value equal to the message fee!
function publishMessage(
uint32 nonce,
bytes memory payload,
uint8 consistencyLevel
) external payable returns (uint64 sequence);
// -- verification --
//consider using `VaaLib` and `CoreBridgeLib` instead to save on gas
// (though at the expense of some code size)
function parseAndVerifyVM(
bytes calldata encodedVM
) external view returns (CoreBridgeVM memory vm, bool valid, string memory reason);
// -- getters --
function chainId() external view returns (uint16);
function nextSequence(address emitter) external view returns (uint64);
function getGuardianSet(uint32 index) external view returns (GuardianSet memory);
function getCurrentGuardianSetIndex() external view returns (uint32);
}
Настройки компилятораПоказать
{
"metadata": {
"useLiteralContent": true
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"project/:wormhole-solidity-sdk/=project/lib/wormhole-solidity-sdk/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.