From 3aab59e01f8851e6b783bfb0447027eeff0c3d50 Mon Sep 17 00:00:00 2001 From: Mikhail Melnik Date: Fri, 6 Sep 2024 12:15:23 +0300 Subject: [PATCH 1/2] support native token drop --- contracts/SignatureMerkleDrop128.sol | 5 +++-- contracts/interfaces/ISignatureMerkleDrop128.sol | 2 +- test/SignatureMerkleDrop128.test.js | 8 +++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/contracts/SignatureMerkleDrop128.sol b/contracts/SignatureMerkleDrop128.sol index eff04d4d..29cf7ac0 100644 --- a/contracts/SignatureMerkleDrop128.sol +++ b/contracts/SignatureMerkleDrop128.sol @@ -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. @@ -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); _cashback(); } @@ -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]; diff --git a/contracts/interfaces/ISignatureMerkleDrop128.sol b/contracts/interfaces/ISignatureMerkleDrop128.sol index c0c54dd8..6e22c761 100644 --- a/contracts/interfaces/ISignatureMerkleDrop128.sol +++ b/contracts/interfaces/ISignatureMerkleDrop128.sol @@ -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. diff --git a/test/SignatureMerkleDrop128.test.js b/test/SignatureMerkleDrop128.test.js index ca2072e4..7b9e8b40 100644 --- a/test/SignatureMerkleDrop128.test.js +++ b/test/SignatureMerkleDrop128.test.js @@ -1,6 +1,6 @@ const { ethers } = require('hardhat'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { deployContract, expect } = require('@1inch/solidity-utils'); +const { deployContract, expect, ether } = require('@1inch/solidity-utils'); const { MerkleTree } = require('merkletreejs'); const keccak256 = require('keccak256'); const { personalSign } = require('@metamask/eth-sig-util'); @@ -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( From fd794f3b3ee9d442e8f017b20e65f48f82eadf0f Mon Sep 17 00:00:00 2001 From: Mikhail Melnik Date: Fri, 6 Sep 2024 12:19:17 +0300 Subject: [PATCH 2/2] linter --- test/SignatureMerkleDrop128.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/SignatureMerkleDrop128.test.js b/test/SignatureMerkleDrop128.test.js index 7b9e8b40..7eb111db 100644 --- a/test/SignatureMerkleDrop128.test.js +++ b/test/SignatureMerkleDrop128.test.js @@ -1,6 +1,6 @@ const { ethers } = require('hardhat'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { deployContract, expect, ether } = require('@1inch/solidity-utils'); +const { deployContract, expect } = require('@1inch/solidity-utils'); const { MerkleTree } = require('merkletreejs'); const keccak256 = require('keccak256'); const { personalSign } = require('@metamask/eth-sig-util'); @@ -81,7 +81,7 @@ describe('SignatureMerkleDrop128', function () { 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}); + const txn = await drop.claim(alice, 1, proofs[leaves.indexOf(hashedElements[0])], signature, { value: 10 }); expect(txn).to.changeEtherBalance(alice, 10); });