Skip to content

Commit

Permalink
Merge pull request #32 from 1inch/feature/native-token-drop
Browse files Browse the repository at this point in the history
support native token drop
  • Loading branch information
galekseev authored Sep 12, 2024
2 parents 9027e5d + fd794f3 commit 8cea66d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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);
_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

0 comments on commit 8cea66d

Please sign in to comment.