Caricamento del resto di questo confronto.

MinipoolManager

Creato Il diff non scade mai
121 rimozioni
531 linee
127 aggiunte
538 linee
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.17;
pragma solidity 0.8.17;


import {Base} from "./Base.sol";
import {Base} from "./Base.sol";
import {IWithdrawer} from "../interface/IWithdrawer.sol";
import {IWithdrawer} from "../interface/IWithdrawer.sol";
import {MinipoolStatus} from "../types/MinipoolStatus.sol";
import {MinipoolStatus} from "../types/MinipoolStatus.sol";
import {MultisigManager} from "./MultisigManager.sol";
import {MultisigManager} from "./MultisigManager.sol";
import {Oracle} from "./Oracle.sol";
import {Oracle} from "./Oracle.sol";
import {ProtocolDAO} from "./ProtocolDAO.sol";
import {ProtocolDAO} from "./ProtocolDAO.sol";
import {Staking} from "./Staking.sol";
import {Staking} from "./Staking.sol";
import {Storage} from "./Storage.sol";
import {Storage} from "./Storage.sol";
import {TokenggAVAX} from "./tokens/TokenggAVAX.sol";
import {TokenggAVAX} from "./tokens/TokenggAVAX.sol";
import {Vault} from "./Vault.sol";
import {Vault} from "./Vault.sol";
import {FixedPointMathLib} from "@rari-capital/solmate/src/utils/FixedPointMathLib.sol";
import {FixedPointMathLib} from "@rari-capital/solmate/src/utils/FixedPointMathLib.sol";
import {ReentrancyGuard} from "@rari-capital/solmate/src/utils/ReentrancyGuard.sol";
import {ReentrancyGuard} from "@rari-capital/solmate/src/utils/ReentrancyGuard.sol";
import {SafeTransferLib} from "@rari-capital/solmate/src/utils/SafeTransferLib.sol";
import {SafeTransferLib} from "@rari-capital/solmate/src/utils/SafeTransferLib.sol";


/*
/*
Data Storage Schema
Data Storage Schema
NodeIDs are 20 bytes so can use Solidity 'address' as storage type for them
NodeIDs are 20 bytes so can use Solidity 'address' as storage type for them
NodeIDs can be added, but never removed. If a nodeID submits another validation request,
NodeIDs can be added, but never removed. If a nodeID submits another validation request,
it will overwrite the old one (only allowed for specific statuses).
it will overwrite the old one (only allowed for specific statuses).


MinipoolManager.TotalAVAXLiquidStakerAmt = total for all active minipools (Prelaunch/Launched/Staking)
MinipoolManager.TotalAVAXLiquidStakerAmt = total for all active minipools (Prelaunch/Launched/Staking)


minipool.count = Starts at 0 and counts up by 1 after a node is added.
minipool.count = Starts at 0 and counts up by 1 after a node is added.


minipool.index<nodeID> = <index> of nodeID
minipool.index<nodeID> = <index> of nodeID
minipool.item<index>.nodeID = nodeID used as primary key (NOT the ascii "Node-123..." but the actual 20 bytes)
minipool.item<index>.nodeID = nodeID used as primary key (NOT the ascii "Node-123..." but the actual 20 bytes)
minipool.item<index>.status = enum
minipool.item<index>.status = enum
minipool.item<index>.duration = requested validation duration in seconds (performed as 14 day cycles)
minipool.item<index>.duration = requested validation duration in seconds (performed as 14 day cycles)
minipool.item<index>.delegationFee = node operator specified fee (must be between 0 and 1 ether) 2% is 0.2 ether
minipool.item<index>.delegationFee = node operator specified fee (must be between 0 and 1 ether) 2% is 0.2 ether
minipool.item<index>.owner = owner address
minipool.item<index>.owner = owner address
minipool.item<index>.multisigAddr = which Rialto multisig is assigned to manage this validation
minipool.item<index>.multisigAddr = which Rialto multisig is assigned to manage this validation
minipool.item<index>.avaxNodeOpAmt = avax deposited by node operator (for this cycle)
minipool.item<index>.avaxNodeOpAmt = avax deposited by node operator (for this cycle)
minipool.item<index>.avaxNodeOpInitialAmt = avax deposited by node operator for the **first** validation cycle
minipool.item<index>.avaxNodeOpInitialAmt = avax deposited by node operator for the **first** validation cycle
minipool.item<index>.avaxLiquidStakerAmt = avax deposited by users and assigned to this nodeID
minipool.item<index>.avaxLiquidStakerAmt = avax deposited by users and assigned to this nodeID
minipool.item<index>.creationTime = actual time the minipool was created
minipool.item<index>.creationTime = actual time the minipool was created
minipool.item<index>.blsPubkeyAndSig = pub key [48 bytes] + sig [96 bytes]
minipool.item<index>.hardwareProvider = enum representing the hardware provider


// Submitted by the Rialto oracle
// Submitted by the Rialto oracle
minipool.item<index>.txID = transaction id of the AddValidatorTx
minipool.item<index>.txID = transaction id of the AddValidatorTx
minipool.item<index>.initialStartTime = actual time the **first** validation cycle was started
minipool.item<index>.initialStartTime = actual time the **first** validation cycle was started
minipool.item<index>.startTime = actual time validation was started
minipool.item<index>.startTime = actual time validation was started
minipool.item<index>.endTime = actual time validation was finished
minipool.item<index>.endTime = actual time validation was finished
minipool.item<index>.avaxTotalRewardAmt = Actual total avax rewards paid by avalanchego to the TSS P-chain addr
minipool.item<index>.avaxTotalRewardAmt = Actual total avax rewards paid by avalanchego to the TSS P-chain addr
minipool.item<index>.errorCode = bytes32 that encodes an error msg if something went wrong during launch of minipool
minipool.item<index>.errorCode = bytes32 that encodes an error msg if something went wrong during launch of minipool


// Calculated in recordStakingEnd()
// Calculated in recordStakingEnd()
minipool.item<index>.avaxNodeOpRewardAmt
minipool.item<index>.avaxNodeOpRewardAmt
minipool.item<index>.avaxLiquidStakerRewardAmt
minipool.item<index>.avaxLiquidStakerRewardAmt
minipool.item<index>.ggpSlashAmt = amt of ggp bond that was slashed if necessary (expected reward amt = avaxLiquidStakerAmt * x%/yr / ggpPriceInAvax)
minipool.item<index>.ggpSlashAmt = amt of ggp bond that was slashed if necessary (expected reward amt = avaxLiquidStakerAmt * x%/yr / ggpPriceInAvax)
*/
*/


/// @title Minipool creation and management
/// @title Minipool creation and management
contract MinipoolManager is Base, ReentrancyGuard, IWithdrawer {
contract MinipoolManager is Base, ReentrancyGuard, IWithdrawer {
using FixedPointMathLib for uint256;
using FixedPointMathLib for uint256;
using SafeTransferLib for address;
using SafeTransferLib for address;


error CancellationTooEarly();
error CancellationTooEarly();
error DurationOutOfBounds();
error DurationOutOfBounds();
error DelegationFeeOutOfBounds();
error DelegationFeeOutOfBounds();
error InsufficientGGPCollateralization();
error InsufficientGGPCollateralization();
error InsufficientAVAXForMinipoolCreation();
error InsufficientAVAXForMinipoolCreation();
error InvalidAmount();
error InvalidAmount();
error InvalidAVAXAssignmentRequest();
error InvalidAVAXAssignmentRequest();
error InvalidStartTime();
error InvalidStartTime();
error InvalidEndTime();
error InvalidEndTime();
error InvalidMultisigAddress();
error InvalidMultisigAddress();
error InvalidNodeID();
error InvalidNodeID();
error InvalidStateTransition();
error InvalidStateTransition();
error MinipoolNotFound();
error MinipoolNotFound();
error MinipoolDurationExceeded();
error MinipoolDurationExceeded();
error NegativeCycleDuration();
error NegativeCycleDuration();
error OnlyOwner();
error OnlyOwner();
error OnlyRole();
error WithdrawAmountTooLarge();
error WithdrawAmountTooLarge();
error WithdrawForDelegationDisabled();


event GGPSlashed(address indexed nodeID, uint256 ggp);
event GGPSlashed(address indexed nodeID, uint256 ggp);
event MinipoolStatusChanged(address indexed nodeID, MinipoolStatus indexed status);
event MinipoolStatusChanged(address indexed nodeID, MinipoolStatus indexed status);
event WithdrawForDelegation(address indexed nodeID, uint256 amount);
event DepositFromDelegation(address indexed nodeID, uint256 amount, uint256 rewardsAmount);
event BLSKeysAdded(address indexed nodeID, bytes blsPubkeyAndSig);
event MinipoolLaunched(address indexed nodeID, bytes32 hardwareProvider, uint256 duration);


/// @dev Not used for storage, just for returning data from view functions
/// @dev Not used for storage, just for returning data from view functions
struct Minipool {
struct Minipool {
int256 index;
int256 index;
address nodeID;
address nodeID;
uint256 status;
uint256 status;
uint256 duration;
uint256 duration;
uint256 delegationFee;
uint256 delegationFee;
address owner;
address owner;
address multisigAddr;
address multisigAddr;
uint256 avaxNodeOpAmt;
uint256 avaxNodeOpAmt;
uint256 avaxNodeOpInitialAmt;
uint256 avaxNodeOpInitialAmt;
uint256 avaxLiquidStakerAmt;
uint256 avaxLiquidStakerAmt;
bytes blsPubkeyAndSig;
// Submitted by the Rialto Oracle
// Submitted by the Rialto Oracle
bytes32 txID;
bytes32 txID;
uint256 creationTime;
uint256 creationTime;
uint256 initialStartTime;
uint256 initialStartTime;