Skip to content

PChainStakeMirror#

Contract used to mirror all stake amounts from P-chain.

Functions#

activate#

Defined in PChainStakeMirror (Docs, Source).

function activate(
) external;

Activates PChainStakeMirror contract - enable mirroring.

Only governance can call this.

balanceHistoryCleanup#

Defined in CheckPointable (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in GovernedBase (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

function deactivate(
) external;

Deactivates PChainStakeMirror contract - disable mirroring.

Only governance can call this.

executeGovernanceCall#

Defined in GovernedBase (Docs, Source).

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#

Defined in AddressUpdatable (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in GovernedBase (Docs, Source).

function governance(
) public view returns (
    address);

Returns the current effective governance address.

isActiveStakeMirrored#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in GovernedBase (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in PChainStakeMirror (Docs, Source).

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#

Defined in CheckPointable (Docs, Source).

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#

Defined in CheckPointable (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in AddressUpdatable (Docs, Source).

function updateContractAddresses(
    bytes32[] _contractNameHashes,
    address[] _contractAddresses
) external;

External method called from AddressUpdater only.

votePowerCacheCleanup#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in PChainStake (Docs, Source).

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#

Defined in CheckPointable (Docs, Source).

modifier notBeforeCleanupBlock(    uint256 _blockNumber)

This method cannot be called for _blockNumber lower than the current cleanup block number.

onlyAddressUpdater#

Defined in AddressUpdatable (Docs, Source).

modifier onlyAddressUpdater()

Only the AdressUpdater contract can call this method. Its address is set at construction time but it can also update itself.

onlyCleaner#

Defined in CheckPointable (Docs, Source).

modifier onlyCleaner()

Only the cleanerContract can call this method.

onlyFlareDaemon#

Defined in GovernedAndFlareDaemonized (Docs, Source).

modifier onlyFlareDaemon()

Only the flareDaemon can call this method.

onlyGovernance#

Defined in GovernedBase (Docs, Source).

modifier onlyGovernance()

onlyImmediateGovernance#

Defined in GovernedBase (Docs, Source).

modifier onlyImmediateGovernance()

whenActive#

Defined in PChainStakeMirror (Docs, Source).

modifier whenActive()

This method can only be called when the PChainStakeMirror is active.

Structures#

PChainStakingData#

Defined in PChainStakeMirror (Docs, Source).

struct PChainStakingData {
  address owner;
  bytes20 nodeId;
  uint64 weightGwei;
}

TimelockedCall#

Defined in GovernedBase (Docs, Source).

struct TimelockedCall {
  uint256 allowedAfterTimestamp;
  bytes encodedCall;
}

Variables#

active#

Defined in PChainStakeMirror (Docs, Source).

    bool active

Indicates if stakes can be mirrored.

addressBinder#

Defined in PChainStakeMirror (Docs, Source).

    contract IAddressBinder addressBinder

The contract used for converting P-chain address to C-chain address - both derived from the same public key.

cleanerContract#

Defined in CheckPointable (Docs, Source).

    address cleanerContract

Address of the contract that is allowed to call methods for history cleaning.

cleanupBlockNumberManager#

Defined in PChainStakeMirror (Docs, Source).

    address cleanupBlockNumberManager

The contract that is allowed to set cleanupBlockNumber. Usually this will be an instance of CleanupBlockNumberManager.

endTimeToTransactionHashList#

Defined in PChainStakeMirror (Docs, Source).

    mapping(uint256 => bytes32[]) endTimeToTransactionHashList

Mapping from stake end time to the list of tx hashes - keccak256(abi.encode(txId, inputAddress))

flareDaemon#

Defined in GovernedAndFlareDaemonized (Docs, Source).

    contract FlareDaemon flareDaemon

The FlareDaemon contract, set at construction time.

governanceSettings#

Defined in GovernedBase (Docs, Source).

    contract IGovernanceSettings governanceSettings

Governance Settings.

governanceVotePower#

Defined in PChainStakeMirror (Docs, Source).

    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#

Defined in PChainStakeMirror (Docs, Source).

    uint256 maxUpdatesPerBlock

Max number of stake ends that Flare daemon updates per block.

nextTimestampToTrigger#

Defined in PChainStakeMirror (Docs, Source).

    uint256 nextTimestampToTrigger

Indicates timestamp of stake ends that Flare daemon will trigger next.

productionMode#

Defined in GovernedBase (Docs, Source).

    bool productionMode

When true, governance is enabled and cannot be disabled. See switchToProductionMode.

timelockedCalls#

Defined in GovernedBase (Docs, Source).

    mapping(bytes4 => struct GovernedBase.TimelockedCall) timelockedCalls

List of pending timelocked governance calls.

transactionHashToPChainStakingData#

Defined in PChainStakeMirror (Docs, Source).

    mapping(bytes32 => struct PChainStakeMirror.PChainStakingData) transactionHashToPChainStakingData

Return staking data for given tx hash - keccak256(abi.encode(txId, inputAddress))

verifier#

Defined in PChainStakeMirror (Docs, Source).

    contract IIPChainStakeMirrorVerifier verifier

The contract used for P-chain stake verifications.