Merge pull request #13 from Instadapp/fluid-merkle-connector

Add fluid merkle rewards claim connector
This commit is contained in:
Shriya Tyagi 2024-05-30 00:12:24 +05:30 committed by GitHub
commit 7d3c69dd0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 142 additions and 0 deletions

View File

@ -0,0 +1,23 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
contract Events {
event LogClaim(
uint256 cumulativeAmount,
address fToken,
uint256 cycle,
bytes32[] merkleProof,
uint256 rewardsClaimed,
uint256 setId
);
event LogClaimOnBehalf(
address recipient_,
uint256 cumulativeAmount,
address fToken,
uint256 cycle,
bytes32[] merkleProof,
uint256 rewardsClaimed,
uint256 setId
);
}

View File

@ -0,0 +1,12 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
interface IFluidMerkleDistributor {
function claim(
address recipient_,
uint256 cumulativeAmount_,
address fToken_,
uint256 cycle_,
bytes32[] calldata merkleProof_
) external;
}

View File

@ -0,0 +1,107 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import {Basic} from "../../common/basic.sol";
import {Events} from "./events.sol";
import {IFluidMerkleDistributor} from "./interface.sol";
import {TokenInterface} from "../../common/interfaces.sol";
abstract contract FluidMerkle is Basic, Events {
IFluidMerkleDistributor internal constant MERKLE_DISTRIBUTOR =
IFluidMerkleDistributor(0x1d3D6d38Da24E9Ff3B17693f6971CAe62c3AA1DE);
TokenInterface internal constant TOKEN =
TokenInterface(0x6f40d4A6237C257fff2dB00FA0510DeEECd303eb);
/**
* @dev Claims rewards from Fluid merkle distributor contract
* @param cumulativeAmount_ Total reward cumulated since reward inception.
* @param fToken_ Address of fToken on which rewards are being distributed.
* @param cycle_ Current epoch cycle.
* @param merkleProof_ Merkle proof that validates this claim.
* @param setId_ Id to set the rewards received.
*/
function claim(
uint256 cumulativeAmount_,
address fToken_,
uint256 cycle_,
bytes32[] calldata merkleProof_,
uint256 setId_
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 rewardsBeforeBal_ = TOKEN.balanceOf(address(this));
MERKLE_DISTRIBUTOR.claim(
address(this),
cumulativeAmount_,
fToken_,
cycle_,
merkleProof_
);
uint256 rewardsClaimed_ = TOKEN.balanceOf(address(this)) -
rewardsBeforeBal_;
_eventName = "LogClaim(uint256,address,uint256,bytes32[],uint256,uint256)";
_eventParam = abi.encode(
cumulativeAmount_,
fToken_,
cycle_,
merkleProof_,
rewardsClaimed_,
setId_
);
}
/**
* @dev Claims rewards from Fluid merkle distributor contract
* @param cumulativeAmount_ Total reward cumulated since reward inception.
* @param fToken_ Address of fToken on which rewards are being distributed.
* @param cycle_ Current epoch cycle.
* @param merkleProof_ Merkle proof that validates this claim.
* @param setId_ Id to set the rewards received.
*/
function claimOnBehalf(
address recipient_,
uint256 cumulativeAmount_,
address fToken_,
uint256 cycle_,
bytes32[] calldata merkleProof_,
uint256 setId_
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 rewardsBeforeBal_ = TOKEN.balanceOf(recipient_);
MERKLE_DISTRIBUTOR.claim(
recipient_,
cumulativeAmount_,
fToken_,
cycle_,
merkleProof_
);
uint256 rewardsClaimed_ = TOKEN.balanceOf(recipient_) -
rewardsBeforeBal_;
_eventName = "LogClaimOnBehalf(address,uint256,address,uint256,bytes32[],uint256,uint256)";
_eventParam = abi.encode(
recipient_,
cumulativeAmount_,
fToken_,
cycle_,
merkleProof_,
rewardsClaimed_,
setId_
);
}
}
contract ConnectV2FluidMerkleClaim is FluidMerkle {
string public constant name = "Fluid-Merkle-v1.0";
}