MerkleVault
Inherits: IMerkleVault, Administrable, Initializable, Implementation
Author: mortimr @ Kiln
Funds distribution vault using merkle proofs to authorize withdrawals
State Variables
$root
The current merkle root used to verify claim requests
Slot: keccak256(bytes("merkleVault.1.root")) - 1
types.Bytes32 internal constant $root = types.Bytes32.wrap(0x1d72bdd8ebb24cdc615789f17c463dfb1fe22d0a9c3e2e83db3203cf4b1f2be0);
$ipfsHash
The current ipfs hash associated with the merkle root
Slot: keccak256(bytes("merkleVault.1.ipfsHash")) - 1
types.String internal constant $ipfsHash = types.String.wrap(0xe9bb128fd68516c65b38522aa2f7739e85d47a3214671ac9273550d2cef5e1a4);
$totalClaimedPerAccount
The mapping of already claimed amounts : mapping(address => uint256)
Slot: keccak256(bytes("merkleVault.1.totalClaimedPerAccount")) - 1
types.Mapping internal constant $totalClaimedPerAccount =
types.Mapping.wrap(0x434b080ec0dc7613d87ca93b5b660083adb8c732eaa35678d5918a3b53d5ff81);
$totalClaimed
The sum of all claimed amounts
Slot: keccak256(bytes("merkleVault.1.totalClaimed")) - 1
types.Uint256 internal constant $totalClaimed = types.Uint256.wrap(0xd861ffae2fee684c1e2f63e370c8ea498da9e58b75f637eeee60d1a01ca75c59);
$frameSize
Amount of epochs per frame
Slot: keccak256(bytes("merkleVault.1.frameSize")) - 1
types.Uint256 internal constant $frameSize = types.Uint256.wrap(0xe906a0ea72c128fe3b63278ff794cbb58f458fcecc52717e792bf287499a0fa7);
Functions
initialize
function initialize(address admin, bytes32 initialRoot, string calldata initialIpfsHash, uint256 initialFrameSize) external init(0);
Parameters
| Name | Type | Description |
|---|---|---|
admin | address | The address able to update the merkle root |
initialRoot | bytes32 | The initial merkle root |
initialIpfsHash | string | The initial report ipfs hash |
initialFrameSize | uint256 | The initial frame size |
totalClaimedForAccount
Retrieve the total claimed amount for an account
function totalClaimedForAccount(address account) external view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
account | address | The account to inspect |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The total claimed amount for the account |
totalClaimed
Retrieve the total claimed on the contract
function totalClaimed() external view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The total claimed amount |
root
Retrieve the current merkle root
function root() external view returns (bytes32);
Returns
| Name | Type | Description |
|---|---|---|
<none> | bytes32 | Current merkle root |
ipfsHash
Retrieve the ipfs hash holding the merkle tree + extra data
function ipfsHash() external view returns (string memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | string | The ipfs hash |
setRootAndIpfsHash
Set the current merkle root
function setRootAndIpfsHash(bytes32 newRoot, string calldata newIpfsHash) external onlyAdmin;
Parameters
| Name | Type | Description |
|---|---|---|
newRoot | bytes32 | The new merkle root value |
newIpfsHash | string |
claim
Claims funds based on total claimed and current amount
function claim(address account, uint256 amount, bytes32[] calldata proofs) external;
Parameters
| Name | Type | Description |
|---|---|---|
account | address | |
amount | uint256 | The total amount of rewards claimable for the caller |
proofs | bytes32[] | The array of proofs to verify before claim |
frameSize
Retreive the number of epochs between two reports
function frameSize() external view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The number of epochs |
setFrameSize
Update the number of epochs between two reports
function setFrameSize(uint256 newFrameSize) external onlyAdmin;
Parameters
| Name | Type | Description |
|---|---|---|
newFrameSize | uint256 | The new frame size |
fallback
fallback() external payable;
receive
receive() external payable;
_leaf
Converts the account and amount combo to a bytes32 leaf
function _leaf(address account, uint256 amount) internal pure returns (bytes32);
Parameters
| Name | Type | Description |
|---|---|---|
account | address | The claimer account |
amount | uint256 | The claimable amount |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bytes32 | The leaf |
_verify
Internal utility to verify if a leaf is part of a merkle tree
function _verify(bytes32 leaf, bytes32[] calldata proofs) internal view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
leaf | bytes32 | The leaf to verify |
proofs | bytes32[] | The list of proofs to use for the verification |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | True if leaf is in the tree |
_setRootAndIpfsHash
Internal utility to change the stored merkle root
function _setRootAndIpfsHash(bytes32 newRoot, string calldata newIpfsHash) internal;
Parameters
| Name | Type | Description |
|---|---|---|
newRoot | bytes32 | New merkle root value |
newIpfsHash | string |
_setFrameSize
Internal utility to change the frame size
function _setFrameSize(uint256 newFrameSize) internal;
Parameters
| Name | Type | Description |
|---|---|---|
newFrameSize | uint256 | New frame size value |