Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support native token drop #32

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions contracts/SignatureMerkleDrop128.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract SignatureMerkleDrop128 is ISignatureMerkleDrop128, Ownable {
depth = depth_;
}

function claim(address receiver, uint256 amount, bytes calldata merkleProof, bytes calldata signature) external override {
function claim(address receiver, uint256 amount, bytes calldata merkleProof, bytes calldata signature) external payable {
bytes32 signedHash = ECDSA.toEthSignedMessageHash(keccak256(abi.encodePacked(receiver)));
address account = ECDSA.recover(signedHash, signature);
// Verify the merkle proof.
Expand All @@ -42,6 +42,7 @@ contract SignatureMerkleDrop128 is ISignatureMerkleDrop128, Ownable {
if (!valid) revert InvalidProof();
_invalidate(index);
IERC20(token).safeTransfer(receiver, amount);
payable(receiver).sendValue(msg.value);
ZumZoom marked this conversation as resolved.
Show resolved Hide resolved
_cashback();
}

Expand All @@ -53,7 +54,7 @@ contract SignatureMerkleDrop128 is ISignatureMerkleDrop128, Ownable {
return _verifyAsm(proof, merkleRoot, leaf);
}

function isClaimed(uint256 index) external view override returns (bool) {
function isClaimed(uint256 index) external view returns (bool) {
uint256 claimedWordIndex = index / 256;
uint256 claimedBitIndex = index % 256;
uint256 claimedWord = _claimedBitMap[claimedWordIndex];
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISignatureMerkleDrop128.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ISignatureMerkleDrop128 {
// Returns the tree depth of the merkle tree containing account balances available to claim.
function depth() external view returns (uint256);
// Claim the given amount of the token to the given address. Reverts if the inputs are invalid.
function claim(address receiver, uint256 amount, bytes calldata merkleProof, bytes calldata signature) external;
function claim(address receiver, uint256 amount, bytes calldata merkleProof, bytes calldata signature) external payable;
// Verifies that given leaf and merkle proof matches given merkle root and returns leaf index.
function verify(bytes calldata proof, bytes16 root, bytes16 leaf) external view returns (bool valid, uint256 index);
// Returns true if the index has been marked claimed.
Expand Down
6 changes: 6 additions & 0 deletions test/SignatureMerkleDrop128.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ describe('SignatureMerkleDrop128', function () {
await drop.claim(alice, 1, proofs[leaves.indexOf(hashedElements[0])], signature);
});

it('Should transfer money to another wallet with extra value', async function () {
const { accounts: { alice }, contracts: { drop }, others: { hashedElements, leaves, proofs, signature } } = await loadFixture(deployContractsFixture);
const txn = await drop.claim(alice, 1, proofs[leaves.indexOf(hashedElements[0])], signature, { value: 10 });
expect(txn).to.changeEtherBalance(alice, 10);
});

it('Should disallow invalid proof', async function () {
const { accounts: { alice }, contracts: { drop }, others: { signature } } = await loadFixture(deployContractsFixture);
await expect(
Expand Down
Loading