Claiming Rewards
Understanding Markets Rewards
When integrating Morpho Markets, it's important to include the rewards claiming functionality to provide a complete experience for your users. Many rewards are distributed to Morpho Markets users that can claim them.
Working with the Universal Rewards Distributor
Morpho rewards are distributed through potentially different Universal Rewards Distributor (URD) contracts, which manage reward distributions using Merkle proofs. To implement rewards claiming in your integration, please refer to this tutorial. [//]: # "TODO Insert Tutorial claim here"
Implementing the Claim Function
The core of claiming rewards is interacting with the URD contract's claim
function:
// solidity
function claim(address account, address reward, uint256 claimable, bytes32[] calldata proof) external returns (uint256 amount);
Claims rewards for a specific account.
- Reverts if the root is not set, if the proof is invalid, or if the claimable amount is less than the amount already claimed.
- Emits a
Claimed
event upon successful execution.
Understanding the Claim Parameters
When calling the claim
function on the URD, you need to provide:
- account: The address that will receive the rewards (typically the caller's address)
- reward: The address of the reward token contract
- claimable: The total amount claimable for this user (as provided by the API). Note: it is normal if the amount is higher than what the user can earn. it is suppsoed to be the total amount of rewards that the user earned related to this urd.
- proof: The Merkle proof array that verifies the claim's validity
The function returns the actual amount claimed, which may be less than the claimable amount if the user has already claimed part of their rewards.
Security Considerations
When implementing rewards claiming:
- Validate Proofs: Never modify the proof data returned by the API
- Handle Gas Efficiently: Batch claims when possible to save gas
- Verify Contracts: Always verify that you're interacting with the correct URD contract addresses
- Error Handling: Implement proper error handling for failed claims