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

Merkle distributor [wip] #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions contracts/SharedNFTLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {Base64} from "base64-sol/base64.sol";

pragma solidity 0.8.6;


contract SharedNFTLogic {
function base64Encode(bytes memory args)
public
Expand Down
40 changes: 40 additions & 0 deletions contracts/distributor/EditionMerkleSale.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-3.0

import {IEditionSingleMintable} from "../IEditionSingleMintable.sol";
import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

pragma solidity 0.8.6;

contract SingleEditionMintableDistributor {
IEditionSingleMintable private immutable mintable;
bytes32 merkleRoot;

mapping(uint256 => uint256) private claimedBitMap;

// From astrodrop (https://etherscan.io/address/0x4f96cccfd25b4b7a89062d52c3099e1a97793a99#code)
function isClaimed(uint256 index) public view returns (bool) {
uint256 claimedWordIndex = index / 256;
uint256 claimedBitIndex = index % 256;
uint256 claimedWord = claimedBitMap[claimedWordIndex];
uint256 mask = (1 << claimedBitIndex);
return claimedWord & mask == mask;
}
function _setClaimed(uint256 index) private {
uint256 claimedWordIndex = index / 256;
uint256 claimedBitIndex = index % 256;
claimedBitMap[claimedWordIndex] = claimedBitMap[claimedWordIndex] | (1 << claimedBitIndex);
}

constructor(IEditionSingleMintable _mintable, bytes32 _merkleRoot) {
mintable = _mintable;
merkleRoot = _merkleRoot;
}

function claim(uint256 index, bytes32[] memory merkleProof) public {
require(!isClaimed(index));
bytes32 node = keccak256(abi.encodePacked(index, msg.sender));
require(MerkleProof.verify(merkleProof, merkleRoot, node), 'Invalid proof');
mintable.mintEdition(msg.sender);
_setClaimed(index);
}
}
60 changes: 60 additions & 0 deletions test/SingleEditionMintableDistributor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { expect } from "chai";
import "@nomiclabs/hardhat-ethers";
import { ethers, deployments } from "hardhat";
import parseDataURI from "data-urls";

import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import {
SingleEditionMintableCreator,
SingleEditionMintable,
} from "../typechain";

describe("SingleEditionMintable", () => {
let signer: SignerWithAddress;
let signerAddress: string;
let dynamicSketch: SingleEditionMintableCreator;

beforeEach(async () => {
const { SingleEditionMintableCreator } = await deployments.fixture([
"SingleEditionMintableCreator",
"SingleEditionMintable",
]);
const dynamicMintableAddress = (
await deployments.get("SingleEditionMintable")
).address;
dynamicSketch = (await ethers.getContractAt(
"SingleEditionMintableCreator",
SingleEditionMintableCreator.address
)) as SingleEditionMintableCreator;

signer = (await ethers.getSigners())[0];
signerAddress = await signer.getAddress();
});

it("purchases a edition", async () => {
await dynamicSketch.createEdition(
"Testing Token",
"TEST",
"This is a testing token for all",
"https://ipfs.io/ipfsbafybeify52a63pgcshhbtkff4nxxxp2zp5yjn2xw43jcy4knwful7ymmgy",
"0x0000000000000000000000000000000000000000000000000000000000000000",
"",
"0x0000000000000000000000000000000000000000000000000000000000000000",
10,
10
);

const editionResult = await dynamicSketch.getEditionAtId(0);
const minterContract = (await ethers.getContractAt(
"SingleEditionMintable",
editionResult
)) as SingleEditionMintable;



expect(await minterContract.name()).to.be.equal("Testing Token");
expect(await minterContract.symbol()).to.be.equal("TEST");

// expect(await minterContract.setApprovedMinter())
});
});