Verified contractExactGPL-3.0-only
BackerMerkleDistributor
Address0xc442b55a082f7d5f8d8dcda3d0eff50f47dd0f82
- Balance
0 ETH
- Transactions
41
- Compiler
solc 0.6.12
- Same code
Only this contract
Details
- Compiler
- solc 0.6.12+commit.27d51765
- Language
- solidity
- Optimization
- Yes, 100 runs
- EVM version
- istanbul
- License
- GPL-3.0-only
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 14,129,983
- Creation transaction
- 0xa1384d2836…80b0b0b42a
9 files
- contracts/rewards/BackerMerkleDistributor.solmain342 B
- @openzeppelin/contracts-ethereum-package/contracts/introspection/IERC165.sol753 B
- @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol2.66 KB
- @openzeppelin/contracts-ethereum-package/contracts/token/ERC721/IERC721.sol1.99 KB
- @openzeppelin/contracts/cryptography/MerkleProof.sol1.29 KB
- contracts/interfaces/ICommunityRewards.sol1.34 KB
- contracts/interfaces/IERC20withDec.sol538 B
- contracts/interfaces/IMerkleDistributor.sol1.55 KB
- contracts/rewards/MerkleDistributor.sol2.78 KB
contracts/rewards/BackerMerkleDistributor.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.6.12;
import "./MerkleDistributor.sol";
contract BackerMerkleDistributor is MerkleDistributor {
constructor(address communityRewards_, bytes32 merkleRoot_)
public
MerkleDistributor(communityRewards_, merkleRoot_)
// solhint-disable-next-line no-empty-blocks
{
}
}
@openzeppelin/contracts-ethereum-package/contracts/introspection/IERC165.sol
pragma solidity ^0.6.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol
pragma solidity ^0.6.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/IERC721.sol
pragma solidity ^0.6.2;
import "../../introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of NFTs in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the NFT specified by `tokenId`.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to
* another (`to`).
*
*
*
* Requirements:
* - `from`, `to` cannot be zero.
* - `tokenId` must be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this
* NFT by either {approve} or {setApprovalForAll}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to
* another (`to`).
*
* Requirements:
* - If the caller is not `from`, it must be approved to move this NFT by
* either {approve} or {setApprovalForAll}.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}
@openzeppelin/contracts/cryptography/MerkleProof.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev These functions deal with verification of Merkle trees (hash trees),
*/
library MerkleProof {
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];
if (computedHash <= proofElement) {
// Hash(current computed hash + current element of the proof)
computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
} else {
// Hash(current element of the proof + current computed hash)
computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
}
}
// Check if the computed hash (root) is equal to the provided root
return computedHash == root;
}
}
contracts/interfaces/ICommunityRewards.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/IERC721.sol";
import "../interfaces/IERC20withDec.sol";
interface ICommunityRewards is IERC721 {
function rewardsToken() external view returns (IERC20withDec);
function claimableRewards(uint256 tokenId) external view returns (uint256 rewards);
function totalVestedAt(
uint256 start,
uint256 end,
uint256 granted,
uint256 cliffLength,
uint256 vestingInterval,
uint256 revokedAt,
uint256 time
) external pure returns (uint256 rewards);
function grant(
address recipient,
uint256 amount,
uint256 vestingLength,
uint256 cliffLength,
uint256 vestingInterval
) external returns (uint256 tokenId);
function loadRewards(uint256 rewards) external;
function revokeGrant(uint256 tokenId) external;
function getReward(uint256 tokenId) external;
event RewardAdded(uint256 reward);
event Granted(
address indexed user,
uint256 indexed tokenId,
uint256 amount,
uint256 vestingLength,
uint256 cliffLength,
uint256 vestingInterval
);
event GrantRevoked(uint256 indexed tokenId, uint256 totalUnvested);
event RewardPaid(address indexed user, uint256 indexed tokenId, uint256 reward);
}
contracts/interfaces/IERC20withDec.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
/*
Only addition is the `decimals` function, which we need, and which both our Fidu and USDC use, along with most ERC20's.
*/
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20withDec is IERC20 {
/**
* @dev Returns the number of decimals used for the token
*/
function decimals() external view returns (uint8);
}
contracts/interfaces/IMerkleDistributor.sol
// SPDX-License-Identifier: GPL-3.0-only
// solhint-disable-next-line max-line-length
// Adapted from https://github.com/Uniswap/merkle-distributor/blob/c3255bfa2b684594ecd562cacd7664b0f18330bf/contracts/interfaces/IMerkleDistributor.sol.
pragma solidity 0.6.12;
/// @notice Enables the granting of a CommunityRewards grant, if the grant details exist in this
/// contract's Merkle root.
interface IMerkleDistributor {
/// @notice Returns the address of the CommunityRewards contract whose grants are distributed by this contract.
function communityRewards() external view returns (address);
/// @notice Returns the merkle root of the merkle tree containing grant details available to accept.
function merkleRoot() external view returns (bytes32);
/// @notice Returns true if the index has been marked accepted.
function isGrantAccepted(uint256 index) external view returns (bool);
/// @notice Causes the sender to accept the grant consisting of the given details. Reverts if
/// the inputs (which includes who the sender is) are invalid.
function acceptGrant(
uint256 index,
uint256 amount,
uint256 vestingLength,
uint256 cliffLength,
uint256 vestingInterval,
bytes32[] calldata merkleProof
) external;
/// @notice This event is triggered whenever a call to #acceptGrant succeeds.
event GrantAccepted(
uint256 indexed tokenId,
uint256 indexed index,
address indexed account,
uint256 amount,
uint256 vestingLength,
uint256 cliffLength,
uint256 vestingInterval
);
}
contracts/rewards/MerkleDistributor.sol
// SPDX-License-Identifier: GPL-3.0-only
// solhint-disable-next-line max-line-length
// Adapted from https://github.com/Uniswap/merkle-distributor/blob/c3255bfa2b684594ecd562cacd7664b0f18330bf/contracts/MerkleDistributor.sol.
pragma solidity 0.6.12;
import "@openzeppelin/contracts/cryptography/MerkleProof.sol";
import "../interfaces/ICommunityRewards.sol";
import "../interfaces/IMerkleDistributor.sol";
contract MerkleDistributor is IMerkleDistributor {
address public immutable override communityRewards;
bytes32 public immutable override merkleRoot;
// @dev This is a packed array of booleans.
mapping(uint256 => uint256) private acceptedBitMap;
constructor(address communityRewards_, bytes32 merkleRoot_) public {
require(communityRewards_ != address(0), "Cannot use the null address");
require(merkleRoot_ != 0, "Invalid merkle root provided");
communityRewards = communityRewards_;
merkleRoot = merkleRoot_;
}
function isGrantAccepted(uint256 index) public view override returns (bool) {
uint256 acceptedWordIndex = index / 256;
uint256 acceptedBitIndex = index % 256;
uint256 acceptedWord = acceptedBitMap[acceptedWordIndex];
uint256 mask = (1 << acceptedBitIndex);
return acceptedWord & mask == mask;
}
function _setGrantAccepted(uint256 index) private {
uint256 acceptedWordIndex = index / 256;
uint256 acceptedBitIndex = index % 256;
acceptedBitMap[acceptedWordIndex] = acceptedBitMap[acceptedWordIndex] | (1 << acceptedBitIndex);
}
function acceptGrant(
uint256 index,
uint256 amount,
uint256 vestingLength,
uint256 cliffLength,
uint256 vestingInterval,
bytes32[] calldata merkleProof
) external override {
require(!isGrantAccepted(index), "Grant already accepted");
// Verify the merkle proof.
//
/// @dev Per the Warning in
/// https://github.com/ethereum/solidity/blob/v0.6.12/docs/abi-spec.rst#non-standard-packed-mode,
/// it is important that no more than one of the arguments to `abi.encodePacked()` here be a
/// dynamic type (see definition in
/// https://github.com/ethereum/solidity/blob/v0.6.12/docs/abi-spec.rst#formal-specification-of-the-encoding).
bytes32 node = keccak256(abi.encodePacked(index, msg.sender, amount, vestingLength, cliffLength, vestingInterval));
require(MerkleProof.verify(merkleProof, merkleRoot, node), "Invalid proof");
// Mark it accepted and perform the granting.
_setGrantAccepted(index);
uint256 tokenId = ICommunityRewards(communityRewards).grant(
msg.sender,
amount,
vestingLength,
cliffLength,
vestingInterval
);
emit GrantAccepted(tokenId, index, msg.sender, amount, vestingLength, cliffLength, vestingInterval);
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"libraries": {},
"optimizer": {
"runs": 100,
"enabled": true
},
"evmVersion": "istanbul",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.