Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.
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
8 changes: 4 additions & 4 deletions docs/sdk.editiondrop.getclaimtransaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ getClaimTransaction(destinationAddress: string, tokenId: BigNumberish, quantity:

| Parameter | Type | Description |
| --- | --- | --- |
| destinationAddress | string | |
| tokenId | BigNumberish | |
| quantity | BigNumberish | |
| checkERC20Allowance | boolean | <i>(Optional)</i> |
| destinationAddress | string | Address you want to send the token to |
| tokenId | BigNumberish | Id of the token you want to claim |
| quantity | BigNumberish | Quantity of the tokens you want to claim |
| checkERC20Allowance | boolean | <i>(Optional)</i> Optional, check if the wallet has enough ERC20 allowance to claim the tokens, and if not, approve the transfer |

<b>Returns:</b>

Expand Down
29 changes: 22 additions & 7 deletions src/contracts/edition-drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,23 +264,37 @@ export class EditionDrop extends Erc1155<DropERC1155> {
/**
* Construct a claim transaction without executing it.
* This is useful for estimating the gas cost of a claim transaction, overriding transaction options and having fine grained control over the transaction execution.
* @param destinationAddress
* @param tokenId
* @param quantity
* @param checkERC20Allowance
* @param destinationAddress - Address you want to send the token to
* @param tokenId - Id of the token you want to claim
* @param quantity - Quantity of the tokens you want to claim
* @param checkERC20Allowance - Optional, check if the wallet has enough ERC20 allowance to claim the tokens, and if not, approve the transfer
* @param claimData - Optional claim verification data (e.g. price, allowlist proof, etc...)
*/
public async getClaimTransaction(
destinationAddress: string,
tokenId: BigNumberish,
quantity: BigNumberish,
checkERC20Allowance = true, // TODO split up allowance checks
): Promise<TransactionTask> {
return this._claim.getClaimTransaction(
destinationAddress,
const claimVerification = await this._claim.conditions.prepareClaim(
tokenId,
quantity,
checkERC20Allowance,
);
return TransactionTask.make({
contractWrapper: this.contractWrapper,
functionName: "claim",
args: [
destinationAddress,
tokenId,
quantity,
claimVerification.currencyAddress,
claimVerification.price,
claimVerification.proofs,
claimVerification.maxQuantityPerTransaction,
],
overrides: claimVerification.overrides,
});
}

/**
Expand Down Expand Up @@ -312,12 +326,13 @@ export class EditionDrop extends Erc1155<DropERC1155> {
quantity: BigNumberish,
checkERC20Allowance = true,
): Promise<TransactionResult> {
return this._claim.to(
const tx = await this.getClaimTransaction(
destinationAddress,
tokenId,
quantity,
checkERC20Allowance,
);
return await tx.execute();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/classes/drop-erc1155-claim-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export class DropErc1155ClaimConditions<
const encoded = [];

// keep the old merkle roots from other tokenIds
for (const key of Object.keys(metadata.merkle)) {
for (const key of Object.keys(metadata.merkle || {})) {
merkleInfo[key] = metadata.merkle[key];
}

Expand Down
24 changes: 6 additions & 18 deletions src/core/classes/erc-1155-claimable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ContractWrapper } from "./contract-wrapper";
import { ContractMetadata } from "./contract-metadata";
import { CustomContractSchema } from "../../schema/contracts/custom";
import { ClaimVerification } from "../../types/claim-conditions/claim-conditions";
import { BigNumberish } from "ethers";
import { BigNumberish, ethers } from "ethers";
import { TransactionResult } from "../types";
import { TransactionTask } from "./TransactionTask";

Expand Down Expand Up @@ -75,8 +75,11 @@ export class Erc1155Claimable implements DetectableFeature {
quantity,
claimVerification.currencyAddress,
claimVerification.price,
claimVerification.proofs,
claimVerification.maxQuantityPerTransaction,
{
proof: claimVerification.proofs,
maxQuantityInAllowlist: claimVerification.maxQuantityPerTransaction,
},
ethers.utils.toUtf8Bytes(""),
],
overrides: claimVerification.overrides,
});
Expand Down Expand Up @@ -112,21 +115,6 @@ export class Erc1155Claimable implements DetectableFeature {
checkERC20Allowance = true,
claimData?: ClaimVerification,
): Promise<TransactionResult> {
let claimVerification = claimData;
if (this.conditions && !claimData) {
claimVerification = await this.conditions.prepareClaim(
tokenId,
quantity,
checkERC20Allowance,
);
}

if (!claimVerification) {
throw new Error(
"Claim verification Data is required - either pass it in as 'claimData' or set claim conditions via 'conditions.set()'",
);
}

const tx = await this.getClaimTransaction(
destinationAddress,
tokenId,
Expand Down
42 changes: 37 additions & 5 deletions src/core/classes/erc-1155-droppable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { TokensLazyMintedEvent } from "contracts/LazyMint";
import { detectContractFeature } from "../../common/feature-detection";
import {
detectContractFeature,
hasFunction,
} from "../../common/feature-detection";
import { uploadOrExtractURIs } from "../../common/nft";
import {
FEATURE_EDITION_DROPPABLE,
Expand All @@ -19,6 +22,8 @@ import { ContractWrapper } from "./contract-wrapper";
import { Erc1155 } from "./erc-1155";
import { Erc1155Claimable } from "./erc-1155-claimable";
import { DelayedReveal } from "./delayed-reveal";
import { TokenERC721 } from "contracts";
import { ethers } from "ethers";

export class Erc1155Droppable implements DetectableFeature {
featureName = FEATURE_EDITION_DROPPABLE.name;
Expand Down Expand Up @@ -136,10 +141,22 @@ export class Erc1155Droppable implements DetectableFeature {
);
}
}
const receipt = await this.contractWrapper.sendTransaction("lazyMint", [
batch.length,
`${baseUri.endsWith("/") ? baseUri : `${baseUri}/`}`,
]);
const isLegacyEditionDropContract =
await this.isLegacyEditionDropContract();
let receipt;
if (isLegacyEditionDropContract) {
receipt = await this.contractWrapper.sendTransaction("lazyMint", [
batch.length,
`${baseUri.endsWith("/") ? baseUri : `${baseUri}/`}`,
]);
} else {
// new contracts/extensions have support for delayed reveal that adds an extra parameter to lazyMint
receipt = await this.contractWrapper.sendTransaction("lazyMint", [
batch.length,
`${baseUri.endsWith("/") ? baseUri : `${baseUri}/`}`,
ethers.utils.toUtf8Bytes(""),
]);
}
const event = this.contractWrapper.parseLogs<TokensLazyMintedEvent>(
"TokensLazyMinted",
receipt?.logs,
Expand Down Expand Up @@ -191,4 +208,19 @@ export class Erc1155Droppable implements DetectableFeature {
}
return undefined;
}

private async isLegacyEditionDropContract() {
if (hasFunction<TokenERC721>("contractType", this.contractWrapper)) {
try {
const contractType = ethers.utils.toUtf8String(
await this.contractWrapper.readContract.contractType(),
);
return contractType.includes("DropERC1155");
} catch (e) {
return false;
}
} else {
return false;
}
}
}
43 changes: 43 additions & 0 deletions test/publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,49 @@ describe("Publishing", async () => {
expect(nftsAfter[1].owner).to.equal(AddressZero);
});

it("ERC1155Drop base feature detection", async () => {
const ipfsUri = "ipfs://QmZsZcLS3fAtPw2EyZGbHxkdeofTxNtqMoXNWLc79sRXWa";
const addr = await sdk.deployer.deployContractFromUri(ipfsUri, [
"test",
"test",
]);
const c = await sdk.getContract(addr);

invariant(c.edition, "edition must be defined");
invariant(c.edition.query, "query must be defined");
invariant(c.edition.drop, "drop must be defined");
invariant(c.edition.drop.claim, "claim conditions must be defined");

const nftsBefore = await c.edition.query.all();
expect(nftsBefore.length).to.equal(0);

const tx = await c.edition.drop.lazyMint([
{
name: "cool nft 1",
},
{
name: "cool nft 2",
},
]);
expect(tx.length).to.eq(2);

await c.edition.drop.claim.conditions.set(0, [
{
price: "0",
maxQuantity: 2,
startTime: new Date(0),
},
]);
await c.edition.drop.claim.to(adminWallet.address, 0, 1);

const nftsAfter = await c.edition.query.all();
expect(nftsAfter.length).to.equal(2);
expect(nftsAfter[0].metadata.name).to.equal("cool nft 1");
expect(nftsAfter[0].supply.toNumber()).to.equal(1);
expect(nftsAfter[1].metadata.name).to.equal("cool nft 2");
expect(nftsAfter[1].supply.toNumber()).to.equal(0);
});

it("Constructor params with tuples", async () => {
const ipfsUri = "ipfs://QmZQa56Cj1gFnZgKSkvGE5uzhaQrQV3nU6upDWDusCaCwY/0";
const addr = await sdk.deployer.deployContractFromUri(ipfsUri, [
Expand Down