Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CuttingBoardNFT

Git Source

Inherits: ERC721, Owned

Title: CuttingBoardNFT

NFT representing temporary control rights over a validator's cutting board

Each NFT grants the holder the ability to update the reward allocation (cutting board) for a specific validator until the expiry timestamp. NFTs are tradeable and can be used in DeFi protocols as collateral or for yield optimization strategies.

State Variables

auction

Address of the auction contract authorized to mint NFTs

address public immutable auction

manager

Address of the control manager authorized to invalidate NFTs

address public manager

_tokenRights

Mapping from token ID to control rights

mapping(uint256 => ControlRights) private _tokenRights

_nextTokenId

Current token ID counter

uint256 private _nextTokenId

_baseTokenURI

Metadata uri

string private _baseTokenURI

Functions

onlyAuction

modifier onlyAuction() ;

onlyManager

modifier onlyManager() ;

constructor

Initialize the CuttingBoardNFT contract

constructor(
    address _auction,
    address _owner,
    address _manager,
    string memory _baseURI
) ERC721("Cutting Board NFT", "CBNFT") Owned(_owner);

Parameters

NameTypeDescription
_auctionaddressAddress of the auction contract
_owneraddressAddress of the contract owner
_manageraddressAddress of contract manager for invalidating NFT's
_baseURIstringMetadata uri

setManager

Set the manager contract address

function setManager(address _manager) external virtual onlyOwner;

Parameters

NameTypeDescription
_manageraddressAddress of the ValidatorControlManager contract

mint

Mint a new control NFT

function mint(
    address to,
    bytes calldata validatorPubkey,
    uint256 expiryTimestamp,
    uint256 auctionId
) external virtual onlyAuction returns (uint256 tokenId);

Parameters

NameTypeDescription
toaddressAddress to receive the NFT
validatorPubkeybytesValidator pubkey being controlled
expiryTimestampuint256When control rights expire
auctionIduint256The auction ID that granted these rights

Returns

NameTypeDescription
tokenIduint256The ID of the newly minted token

isValid

Check if an NFT is still valid (active and not expired)

function isValid(uint256 tokenId) external view virtual returns (bool);

Parameters

NameTypeDescription
tokenIduint256The token ID to check

Returns

NameTypeDescription
<none>boolTrue if the NFT is valid and grants control rights

getValidator

Get the validator pubkey associated with a token

function getValidator(uint256 tokenId)
    external
    view
    virtual
    returns (bytes memory);

Parameters

NameTypeDescription
tokenIduint256The token ID

Returns

NameTypeDescription
<none>bytesThe validator pubkey

getControlRights

Get complete control rights information for a token

function getControlRights(uint256 tokenId)
    external
    view
    virtual
    returns (
        bytes memory validatorPubkey,
        uint256 expiryTimestamp,
        uint256 auctionId,
        bool active
    );

Parameters

NameTypeDescription
tokenIduint256The token ID

Returns

NameTypeDescription
validatorPubkeybytesThe validator pubkey
expiryTimestampuint256When control expires
auctionIduint256The auction that granted these rights
activeboolWhether the NFT is still active

invalidate

Invalidate an NFT (emergency or on expiry)

function invalidate(uint256 tokenId) external virtual onlyManager;

Parameters

NameTypeDescription
tokenIduint256The token ID to invalidate

tokenURI

Get the token URI for metadata

function tokenURI(uint256 tokenId)
    public
    view
    virtual
    override
    returns (string memory);

Parameters

NameTypeDescription
tokenIduint256The token ID

Returns

NameTypeDescription
<none>stringThe token URI (empty string for now, can be extended)

setBaseURI

Set metadata uri

Only owner can call

function setBaseURI(string memory newBaseURI) external onlyOwner;

Parameters

NameTypeDescription
newBaseURIstringnew uri

totalSupply

Get the total number of NFTs minted

function totalSupply() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The total supply of NFTs

Events

ControlNFTMinted

Emitted when a new control NFT is minted

event ControlNFTMinted(
    uint256 indexed tokenId,
    address indexed owner,
    bytes validatorPubkey,
    uint256 expiryTimestamp,
    uint256 indexed auctionId
);

Parameters

NameTypeDescription
tokenIduint256The ID of the newly minted token
owneraddressThe address receiving the NFT
validatorPubkeybytesThe validator pubkey being controlled
expiryTimestampuint256When control rights expire
auctionIduint256The auction ID that granted these rights

ControlNFTInvalidated

Emitted when an NFT is invalidated

event ControlNFTInvalidated(uint256 indexed tokenId);

Parameters

NameTypeDescription
tokenIduint256The ID of the invalidated token

ManagerUpdated

Emitted when the manager address is updated

event ManagerUpdated(
    address indexed oldManager, address indexed newManager
);

Parameters

NameTypeDescription
oldManageraddressThe previous manager address
newManageraddressThe new manager address

Errors

NotAuction

Thrown when caller is not the auction contract

error NotAuction();

NotManager

Thrown when caller is not the manager contract

error NotManager();

InvalidTokenId

Thrown when attempting to interact with an invalid token ID

error InvalidTokenId();

TokenInactive

Thrown when attempting to interact with an inactive NFT

error TokenInactive();

TokenExpired

Thrown when attempting to interact with an expired NFT

error TokenExpired();

InvalidManager

Thrown when providing an invalid manager address

error InvalidManager();

Structs

ControlRights

Represents the control rights associated with an NFT

struct ControlRights {
    bytes validatorPubkey;
    uint256 expiryTimestamp;
    uint256 auctionId;
    bool active;
}