ISLAYRewardsV2
Interface for the SLAYRewardsV2 contract, which handles the distribution and claiming of rewards. In this context, a provider is an actor that distribute rewards (think rewards provider). This can be a service an operator, or any other entity that wants to distribute rewards.
Functions
getDistributionRoots
Returns the current and previous Merkle roots for a (provider,token) pair.
function getDistributionRoots(address provider, address token) external view returns (DistributionRoots memory);
Parameters
Name | Type | Description |
---|---|---|
provider | address | The address of the provider (e.g. service or operator). |
token | address | The address of the token. |
Returns
Name | Type | Description |
---|---|---|
<none> | DistributionRoots | DistributionRoots containing the previous and current Merkle roots. |
getBalance
Returns the balance of a provider for a specific token.
function getBalance(address provider, address token) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
provider | address | The address of the provider (e.g. service or operator). |
token | address | The address of the token. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The balance of the provider for the specified token. |
getClaimedRewards
Returns the total claimed rewards for a specific provider, token, and earner.
function getClaimedRewards(address provider, address token, address earner) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
provider | address | The address of the provider (e.g. service or operator). |
token | address | The address of the token. |
earner | address | The address of the earner. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The total amount of claimed rewards for the specified provider, token, and earner. |
distributeRewards
Distributes rewards from a provider (service or operator) to earners using a Merkle tree. Although rewards are usually distributed by service or operator, anybody can distribute rewards. This is not limited to the service/operator itself to allow for flexibility in reward distribution.
Service needs to ensure proper allowance is made for the contract to transfer tokens. When the {amount} is 0, the function will essentially only update the Merkle root without any token transfer. This allows for patching of existing distributions.
function distributeRewards(address token, uint256 amount, bytes32 merkleRoot) external;
Parameters
Name | Type | Description |
---|---|---|
token | address | The address of the token to distribute. |
amount | uint256 | The amount of tokens to distribute. |
merkleRoot | bytes32 | The Merkle root of the distribution. |
claimRewards
Claims rewards for an earner for a specific provider and token using merkle proof.
The function checks the Merkle proof, updates the claimed rewards and send the tokens to the recipient.
function claimRewards(ClaimableRewardProof calldata params) external;
Parameters
Name | Type | Description |
---|---|---|
params | ClaimableRewardProof | The parameters containing provider, token, amount, recipient, merkleRoot, proof, leafIndex, and totalLeaves. |
Events
RewardsDistributed
Emitted when rewards are distributed by provider.
event RewardsDistributed(address indexed provider, address indexed token, uint256 amount, bytes32 indexed merkleRoot);
Parameters
Name | Type | Description |
---|---|---|
provider | address | The address of the provider (service or operator) distributing rewards. |
token | address | The address of the token being distributed. |
amount | uint256 | The total amount of tokens distributed. |
merkleRoot | bytes32 | The Merkle root of the distribution. |
RewardsClaimed
Emitted when rewards are claimed by an earner.
event RewardsClaimed(
address indexed provider,
address indexed token,
address indexed earner,
address recipient,
uint256 amount,
bytes32 merkleRoot
);
Parameters
Name | Type | Description |
---|---|---|
provider | address | The address of the provider from which rewards are claimed. |
token | address | The address of the token being claimed. |
earner | address | The address of the earner claiming rewards. |
recipient | address | The address receiving the claimed rewards. |
amount | uint256 | The amount of tokens claimed. |
merkleRoot | bytes32 | The Merkle root of the distribution from which the claim is made. |
Errors
InvalidMerkleRoot
Error thrown when an invalid Merkle root is provided for a provider and token pair.
error InvalidMerkleRoot(address provider, address token, bytes32 merkleRoot);
AmountAlreadyClaimed
Error thrown when an earner attempts to claim an amount that has already been claimed.
error AmountAlreadyClaimed(address provider, address token, address earner, uint256 amount);
InvalidMerkleProof
Error thrown when an invalid Merkle proof is provided during reward claiming.
error InvalidMerkleProof();
InsufficientBalance
Error thrown when a provider has insufficient balance for a token to distribute rewards.
error InsufficientBalance(address provider, address token);
Structs
ClaimableRewardProof
Contains all the necessary information to verify and process a reward claim. This struct is used as an input parameter for the claimRewards function.
struct ClaimableRewardProof {
address provider;
address token;
uint256 amount;
address recipient;
bytes32 merkleRoot;
bytes32[] proof;
uint32 leafIndex;
uint32 totalLeaves;
}
DistributionRoots
Stores the previous and current Merkle roots for a provider-token pair. This allows for a transition period where claims can be made against either root.
struct DistributionRoots {
bytes32 prevRoot;
bytes32 currentRoot;
}