MerkleVault

Git Source

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

NameTypeDescription
adminaddressThe address able to update the merkle root
initialRootbytes32The initial merkle root
initialIpfsHashstringThe initial report ipfs hash
initialFrameSizeuint256The initial frame size

totalClaimedForAccount

Retrieve the total claimed amount for an account

function totalClaimedForAccount(address account) external view returns (uint256);

Parameters

NameTypeDescription
accountaddressThe account to inspect

Returns

NameTypeDescription
<none>uint256The total claimed amount for the account

totalClaimed

Retrieve the total claimed on the contract

function totalClaimed() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256The total claimed amount

root

Retrieve the current merkle root

function root() external view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32Current merkle root

ipfsHash

Retrieve the ipfs hash holding the merkle tree + extra data

function ipfsHash() external view returns (string memory);

Returns

NameTypeDescription
<none>stringThe ipfs hash

setRootAndIpfsHash

Set the current merkle root

function setRootAndIpfsHash(bytes32 newRoot, string calldata newIpfsHash) external onlyAdmin;

Parameters

NameTypeDescription
newRootbytes32The new merkle root value
newIpfsHashstring

claim

Claims funds based on total claimed and current amount

function claim(address account, uint256 amount, bytes32[] calldata proofs) external;

Parameters

NameTypeDescription
accountaddress
amountuint256The total amount of rewards claimable for the caller
proofsbytes32[]The array of proofs to verify before claim

frameSize

Retreive the number of epochs between two reports

function frameSize() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256The number of epochs

setFrameSize

Update the number of epochs between two reports

function setFrameSize(uint256 newFrameSize) external onlyAdmin;

Parameters

NameTypeDescription
newFrameSizeuint256The 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

NameTypeDescription
accountaddressThe claimer account
amountuint256The claimable amount

Returns

NameTypeDescription
<none>bytes32The 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

NameTypeDescription
leafbytes32The leaf to verify
proofsbytes32[]The list of proofs to use for the verification

Returns

NameTypeDescription
<none>boolTrue if leaf is in the tree

_setRootAndIpfsHash

Internal utility to change the stored merkle root

function _setRootAndIpfsHash(bytes32 newRoot, string calldata newIpfsHash) internal;

Parameters

NameTypeDescription
newRootbytes32New merkle root value
newIpfsHashstring

_setFrameSize

Internal utility to change the frame size

function _setFrameSize(uint256 newFrameSize) internal;

Parameters

NameTypeDescription
newFrameSizeuint256New frame size value