PChainStakeMirror
#
Source | Inherits from IPChainStakeMirror, PChainStake, GovernedAndFlareDaemonized, IFlareDaemonize, IICleanable, AddressUpdatable
Contract used to mirror all stake amounts from P-chain.
Functions#
activate
#
function activate(
) external;
Activates PChainStakeMirror
contract - enable mirroring.
Only governance
can call this.
balanceHistoryCleanup
#
function balanceHistoryCleanup(
address _owner,
uint256 _count
) external returns (
uint256);
Delete balance checkpoints that expired (i.e. are before cleanupBlockNumber
).
Method can only be called from the cleanerContract
(which may be a proxy to external cleaners).
Parameters | Type | Description |
---|---|---|
_owner |
address |
balance owner account address |
_count |
uint256 |
maximum number of checkpoints to delete |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
the number of checkpoints deleted |
balanceOf
#
function balanceOf(
address _owner
) public view returns (
uint256);
Queries the token balance of _owner
at current block.
Parameters | Type | Description |
---|---|---|
_owner |
address |
The address from which the balance will be retrieved. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The current balance. |
balanceOfAt
#
function balanceOfAt(
address _owner,
uint256 _blockNumber
) public view returns (
uint256);
Queries the token balance of _owner
at a specific _blockNumber
.
Parameters | Type | Description |
---|---|---|
_owner |
address |
The address from which the balance will be retrieved. |
_blockNumber |
uint256 |
The block number when the balance is queried. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The balance at _blockNumber . |
batchVotePowerOfAt
#
function batchVotePowerOfAt(
bytes20[] _owners,
uint256 _blockNumber
) external view returns (
uint256[] _votePowers);
Return vote powers for several node ids in a batch.
Parameters | Type | Description |
---|---|---|
_owners |
bytes20[] |
|
_blockNumber |
uint256 |
The block number at which to fetch. |
Returns | Type | Description |
---|---|---|
_votePowers |
uint256[] |
A list of vote powers. |
cancelGovernanceCall
#
function cancelGovernanceCall(
bytes4 _selector
) external;
Cancel a timelocked governance
call before it has been executed.
Only governance
can call this method.
Parameters | Type | Description |
---|---|---|
_selector |
bytes4 |
The method selector. |
cleanupBlockNumber
#
function cleanupBlockNumber(
) external view returns (
uint256);
Get the current cleanup block number set with setCleanupBlockNumber
.
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The currently set cleanup block number. |
constructor
#
constructor(
address _governance,
contract FlareDaemon _flareDaemon,
address _addressUpdater,
uint256 _maxUpdatesPerBlock
) public;
Initializes the contract with default parameters
Parameters | Type | Description |
---|---|---|
_governance |
address |
Address identifying the governance address |
_flareDaemon |
contract FlareDaemon |
Address identifying the flare daemon contract |
_addressUpdater |
address |
Address identifying the address updater contract |
_maxUpdatesPerBlock |
uint256 |
Max number of updates (stake ends) per block |
daemonize
#
function daemonize(
) external returns (
bool);
Implement this function to receive a trigger from the FlareDaemon
.
The trigger method is called by the validator right at the end of block state transition.
Only flare daemon can call this. Reduce balances and vote powers for stakes that just ended.
Returns | Type | Description |
---|---|---|
[0] | bool |
bool Whether the contract is still active after the call. Currently unused. |
deactivate
#
function deactivate(
) external;
Deactivates PChainStakeMirror
contract - disable mirroring.
Only governance
can call this.
executeGovernanceCall
#
function executeGovernanceCall(
bytes4 _selector
) external;
Execute the timelocked governance
calls once the timelock period expires.
Only executor can call this method.
Parameters | Type | Description |
---|---|---|
_selector |
bytes4 |
The method selector (only one timelocked call per method is stored). |
getAddressUpdater
#
function getAddressUpdater(
) public view returns (
address _addressUpdater);
Returns the configured address updater.
Returns | Type | Description |
---|---|---|
_addressUpdater |
address |
The AddresUpdater contract that can update our contract address list, as a response to a governance call. |
getContractName
#
function getContractName(
) external pure returns (
string);
Implement this function to allow updating daemonized contracts through the AddressUpdater
.
Returns | Type | Description |
---|---|---|
[0] | string |
string Contract name. |
getTransactionHashList
#
function getTransactionHashList(
uint256 _endTime
) external view returns (
bytes32[]);
Returns the list of transaction hashes of stakes that end at given _endTime
.
Parameters | Type | Description |
---|---|---|
_endTime |
uint256 |
Time when stakes end, in seconds from UNIX epoch. |
Returns | Type | Description |
---|---|---|
[0] | bytes32[] |
List of transaction hashes - keccak256(abi.encode(txId, inputAddress)) . |
governance
#
function governance(
) public view returns (
address);
Returns the current effective governance
address.
isActiveStakeMirrored
#
function isActiveStakeMirrored(
bytes32 _txId,
bytes20 _inputAddress
) external view returns (
bool);
Method for checking if active
stake (stake start time <= block.timestamp < stake end time) was already mirrored.
Parameters | Type | Description |
---|---|---|
_txId |
bytes32 |
P-chain stake transaction id. |
_inputAddress |
bytes20 |
P-chain address that opened stake. |
Returns | Type | Description |
---|---|---|
[0] | bool |
True if stake is active and mirrored. |
mirrorStake
#
function mirrorStake(
struct IPChainStakeMirrorVerifier.PChainStake _stakeData,
bytes32[] _merkleProof
) external;
Method for P-chain stake mirroring using PChainStake
data and Merkle proof.
Parameters | Type | Description |
---|---|---|
_stakeData |
struct IPChainStakeMirrorVerifier.PChainStake |
Information about P-chain stake. |
_merkleProof |
bytes32[] |
Merkle proof that should be used to prove the P-chain stake. |
revokeStake
#
function revokeStake(
bytes32 _txId,
bytes20 _inputAddress,
uint256 _endTime,
uint256 _endTimeTxHashIndex
) external;
Revokes stake in case of invalid stakes - voting should be reset first, so that Merkle root is not valid and it cannot be used for mirroring again.
Only governance
can call this.
Parameters | Type | Description |
---|---|---|
_txId |
bytes32 |
P-chain stake transaction id. |
_inputAddress |
bytes20 |
P-chain address that opened stake. |
_endTime |
uint256 |
Time when stake ends, in seconds from UNIX epoch. |
_endTimeTxHashIndex |
uint256 |
Index of txHash = keccak256(abi.encode(_txId, _inputAddress)) in the endTimeToTransactionHashList[_endTime] list. |
setCleanerContract
#
function setCleanerContract(
address _cleanerContract
) external;
Set the contract that is allowed to call history cleaning methods.
Only governance
can call this.
Parameters | Type | Description |
---|---|---|
_cleanerContract |
address |
Address of the cleanup contract. Usually this will be an instance of CleanupBlockNumberManager . |
setCleanupBlockNumber
#
function setCleanupBlockNumber(
uint256 _blockNumber
) external;
Set the cleanup block number.
Historic data for the blocks before cleanupBlockNumber
can be erased.
History before that block should never be used since it can be inconsistent.
In particular, cleanup block number must be lower than the current vote power block.
The method can be called only by cleanupBlockNumberManager
.
Parameters | Type | Description |
---|---|---|
_blockNumber |
uint256 |
The new cleanup block number. |
setMaxUpdatesPerBlock
#
function setMaxUpdatesPerBlock(
uint256 _maxUpdatesPerBlock
) external;
Sets max number of updates (stake ends) per block (a daemonize
call).
Only governance
can call this.
Parameters | Type | Description |
---|---|---|
_maxUpdatesPerBlock |
uint256 |
Max number of updates (stake ends) per block |
stakesHistoryCleanup
#
function stakesHistoryCleanup(
address _owner,
uint256 _count
) external returns (
uint256);
Delete stakes checkpoints that expired (i.e. are before cleanupBlockNumber
).
Method can only be called from the cleanerContract
(which may be a proxy to external cleaners).
Parameters | Type | Description |
---|---|---|
_owner |
address |
Balance owner account address. |
_count |
uint256 |
Maximum number of checkpoints to delete. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
Number of deleted checkpoints. |
stakesOf
#
function stakesOf(
address _owner
) external view returns (
bytes20[] _nodeIds,
uint256[] _amounts);
Get the amounts and node ids being staked to by a vote power owner.
Parameters | Type | Description |
---|---|---|
_owner |
address |
The address being queried. |
Returns | Type | Description |
---|---|---|
_nodeIds |
bytes20[] |
Array of node ids. |
_amounts |
uint256[] |
Array of staked amounts, for each node id. |
stakesOfAt
#
function stakesOfAt(
address _owner,
uint256 _blockNumber
) external view returns (
bytes20[] _nodeIds,
uint256[] _amounts);
Get the amounts and node ids being staked to by a vote power owner, at a given block.
Parameters | Type | Description |
---|---|---|
_owner |
address |
The address being queried. |
_blockNumber |
uint256 |
The block number being queried. |
Returns | Type | Description |
---|---|---|
_nodeIds |
bytes20[] |
Array of node ids. |
_amounts |
uint256[] |
Array of staked amounts, for each node id. |
switchToFallbackMode
#
function switchToFallbackMode(
) external returns (
bool);
This function will be called after an error is caught in daemonize
.
It will switch the contract to a simpler fallback mode, which hopefully works when full mode doesn't.
Not every contract needs to support fallback mode (FtsoManager
does), so this method may be empty.
Switching back to normal mode is left to the contract (typically a governed method call).
This function may be called due to low-gas error, so it shouldn't use more than ~30.000 gas.
Only flare daemon can call this.
Returns | Type | Description |
---|---|---|
[0] | bool |
True if switched to fallback mode, false if already in fallback mode or if fallback mode is not supported. |
switchToProductionMode
#
function switchToProductionMode(
) external;
Enter the production mode after all the initial governance
settings have been set.
This enables timelocks and the governance
can be obtained afterward by calling
governanceSettings
.getGovernanceAddress().
Emits GovernedProductionModeEntered
.
totalSupply
#
function totalSupply(
) public view returns (
uint256);
Total amount of tokens at current block.
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The current total amount of tokens. |
totalSupplyAt
#
function totalSupplyAt(
uint256 _blockNumber
) public view returns (
uint256);
Total amount of tokens at a specific _blockNumber
.
Parameters | Type | Description |
---|---|---|
_blockNumber |
uint256 |
The block number when the totalSupply is queried. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The total amount of tokens at _blockNumber . |
totalSupplyCacheCleanup
#
function totalSupplyCacheCleanup(
uint256 _blockNumber
) external returns (
uint256);
Delete total supply cache entry that expired (i.e. is before cleanupBlockNumber
).
Method can only be called from the cleanerContract
(which may be a proxy to external cleaners).
Parameters | Type | Description |
---|---|---|
_blockNumber |
uint256 |
the block number for which total supply value was cached |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
the number of cache entries deleted (always 0 or 1) |
totalSupplyHistoryCleanup
#
function totalSupplyHistoryCleanup(
uint256 _count
) external returns (
uint256);
Delete total supply checkpoints that expired (i.e. are before cleanupBlockNumber
).
Method can only be called from the cleanerContract
(which may be a proxy to external cleaners).
Parameters | Type | Description |
---|---|---|
_count |
uint256 |
maximum number of checkpoints to delete |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
the number of checkpoints deleted |
totalVotePower
#
function totalVotePower(
) external view returns (
uint256);
Get the current total vote power.
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The current total vote power (sum of all accounts' vote powers). |
totalVotePowerAt
#
function totalVotePowerAt(
uint256 _blockNumber
) external view returns (
uint256);
Get the total vote power at block _blockNumber
Parameters | Type | Description |
---|---|---|
_blockNumber |
uint256 |
The block number at which to fetch. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The total vote power at the block (sum of all accounts' vote powers). |
totalVotePowerAtCached
#
function totalVotePowerAtCached(
uint256 _blockNumber
) external returns (
uint256);
Get the total vote power at block _blockNumber
using cache.
It tries to read the cached value and if not found, reads the actual value and stores it in cache.
Can only be used if _blockNumber
is in the past, otherwise reverts.
Parameters | Type | Description |
---|---|---|
_blockNumber |
uint256 |
The block number at which to fetch. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The total vote power at the block (sum of all accounts' vote powers). |
updateContractAddresses
#
function updateContractAddresses(
bytes32[] _contractNameHashes,
address[] _contractAddresses
) external;
External method called from AddressUpdater
only.
votePowerCacheCleanup
#
function votePowerCacheCleanup(
bytes20 _nodeId,
uint256 _blockNumber
) external returns (
uint256);
Delete vote power cache entry that expired (i.e. is before cleanupBlockNumber
).
Method can only be called from the cleanerContract
(which may be a proxy to external cleaners).
Parameters | Type | Description |
---|---|---|
_nodeId |
bytes20 |
vote power node id |
_blockNumber |
uint256 |
the block number for which total supply value was cached |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
the number of cache entries deleted (always 0 or 1) |
votePowerFromTo
#
function votePowerFromTo(
address _owner,
bytes20 _nodeId
) external view returns (
uint256 _votePower);
Get current staked vote power from _owner
staked to _nodeId
.
Parameters | Type | Description |
---|---|---|
_owner |
address |
Address of vote power owner. |
_nodeId |
bytes20 |
Node id. |
Returns | Type | Description |
---|---|---|
_votePower |
uint256 |
The staked vote power. |
votePowerFromToAt
#
function votePowerFromToAt(
address _owner,
bytes20 _nodeId,
uint256 _blockNumber
) external view returns (
uint256 _votePower);
Get current staked vote power from _owner
staked to _nodeId
at _blockNumber
.
Parameters | Type | Description |
---|---|---|
_owner |
address |
Address of vote power owner. |
_nodeId |
bytes20 |
Node id. |
_blockNumber |
uint256 |
The block number at which to fetch. |
Returns | Type | Description |
---|---|---|
_votePower |
uint256 |
The staked vote power. |
votePowerHistoryCleanup
#
function votePowerHistoryCleanup(
bytes20 _nodeId,
uint256 _count
) external returns (
uint256);
Delete vote power checkpoints that expired (i.e. are before cleanupBlockNumber
).
Method can only be called from the cleanerContract
(which may be a proxy to external cleaners).
Parameters | Type | Description |
---|---|---|
_nodeId |
bytes20 |
vote power node id |
_count |
uint256 |
maximum number of checkpoints to delete |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
the number of checkpoints deleted |
votePowerOf
#
function votePowerOf(
bytes20 _nodeId
) external view returns (
uint256);
Get the current vote power of _nodeId
.
Parameters | Type | Description |
---|---|---|
_nodeId |
bytes20 |
The node id to get voting power. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
Current vote power of _nodeId . |
votePowerOfAt
#
function votePowerOfAt(
bytes20 _nodeId,
uint256 _blockNumber
) external view returns (
uint256);
Get the vote power of _nodeId
at block _blockNumber
Parameters | Type | Description |
---|---|---|
_nodeId |
bytes20 |
The node id to get voting power. |
_blockNumber |
uint256 |
The block number at which to fetch. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
Vote power of _nodeId at _blockNumber . |
votePowerOfAtCached
#
function votePowerOfAtCached(
bytes20 _nodeId,
uint256 _blockNumber
) external returns (
uint256);
Get the vote power of _owner
at block _blockNumber
using cache.
It tries to read the cached value and if not found, reads the actual value and stores it in cache.
Can only be used if _blockNumber is in the past, otherwise reverts.
Parameters | Type | Description |
---|---|---|
_nodeId |
bytes20 |
|
_blockNumber |
uint256 |
The block number at which to fetch. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
Vote power of _owner at _blockNumber . |
Modifiers#
notBeforeCleanupBlock
#
modifier notBeforeCleanupBlock( uint256 _blockNumber)
This method cannot be called for _blockNumber
lower than the current cleanup block number.
onlyAddressUpdater
#
modifier onlyAddressUpdater()
Only the AdressUpdater
contract can call this method.
Its address is set at construction time but it can also update itself.
onlyCleaner
#
modifier onlyCleaner()
Only the cleanerContract
can call this method.
onlyFlareDaemon
#
modifier onlyFlareDaemon()
Only the flareDaemon
can call this method.
whenActive
#
modifier whenActive()
This method can only be called when the PChainStakeMirror
is active
.
Structures#
PChainStakingData
#
struct PChainStakingData {
address owner;
bytes20 nodeId;
uint64 weightGwei;
}
Variables#
active
#
bool active
Indicates if stakes can be mirrored.
addressBinder
#
contract IAddressBinder addressBinder
The contract used for converting P-chain address to C-chain address - both derived from the same public key.
cleanerContract
#
address cleanerContract
Address of the contract that is allowed to call methods for history cleaning.
cleanupBlockNumberManager
#
address cleanupBlockNumberManager
The contract that is allowed to set cleanupBlockNumber
.
Usually this will be an instance of CleanupBlockNumberManager
.
endTimeToTransactionHashList
#
mapping(uint256 => bytes32[]) endTimeToTransactionHashList
Mapping from stake end time to the list of tx hashes - keccak256(abi.encode(txId, inputAddress))
flareDaemon
#
contract FlareDaemon flareDaemon
The FlareDaemon
contract, set at construction time.
governanceSettings
#
contract IGovernanceSettings governanceSettings
Governance Settings.
governanceVotePower
#
contract IIGovernanceVotePower governanceVotePower
The contract to use for governance
vote power and delegation.
Here only to properly update governance
VP at stake start/end,
all actual operations go directly to governance
VP contract.
maxUpdatesPerBlock
#
uint256 maxUpdatesPerBlock
Max number of stake ends that Flare daemon updates per block.
nextTimestampToTrigger
#
uint256 nextTimestampToTrigger
Indicates timestamp of stake ends that Flare daemon will trigger next.
productionMode
#
bool productionMode
When true, governance
is enabled and cannot be disabled. See switchToProductionMode
.
timelockedCalls
#
mapping(bytes4 => struct GovernedBase.TimelockedCall) timelockedCalls
List of pending timelocked governance
calls.
transactionHashToPChainStakingData
#
mapping(bytes32 => struct PChainStakeMirror.PChainStakingData) transactionHashToPChainStakingData
Return staking data for given tx hash - keccak256(abi.encode(txId, inputAddress))