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
11 changes: 11 additions & 0 deletions docs/sdk.delayedreveal.featurename.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@thirdweb-dev/sdk](./sdk.md) &gt; [DelayedReveal](./sdk.delayedreveal.md) &gt; [featureName](./sdk.delayedreveal.featurename.md)

## DelayedReveal.featureName property

<b>Signature:</b>

```typescript
featureName: "ERC721Revealable";
```
8 changes: 7 additions & 1 deletion docs/sdk.delayedreveal.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Handles delayed reveal logic
<b>Signature:</b>

```typescript
export declare class DelayedReveal<T extends SignatureDrop | DropERC721>
export declare class DelayedReveal<T extends DropERC721 | BaseDelayedRevealERC721>
```

## Constructors
Expand All @@ -18,6 +18,12 @@ export declare class DelayedReveal<T extends SignatureDrop | DropERC721>
| --- | --- | --- |
| [(constructor)(contractWrapper, storage)](./sdk.delayedreveal._constructor_.md) | | Constructs a new instance of the <code>DelayedReveal</code> class |

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [featureName](./sdk.delayedreveal.featurename.md) | | "ERC721Revealable" | |

## Methods

| Method | Modifiers | Description |
Expand Down
1 change: 1 addition & 0 deletions docs/sdk.erc721.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ await contract.nft.transfer(walletAddress, tokenId);
| [mint](./sdk.erc721.mint.md) | | [Erc721Mintable](./sdk.erc721mintable.md) \| undefined | |
| [options](./sdk.erc721.options.md) | | [SDKOptions](./sdk.sdkoptions.md) | |
| [query](./sdk.erc721.query.md) | | [Erc721Supply](./sdk.erc721supply.md) \| undefined | |
| [revealer](./sdk.erc721.revealer.md) | | [DelayedReveal](./sdk.delayedreveal.md)<!-- -->&lt;BaseDelayedRevealERC721 \| DropERC721&gt; \| undefined | |
| [storage](./sdk.erc721.storage.md) | | [IStorage](./sdk.istorage.md) | |

## Methods
Expand Down
11 changes: 11 additions & 0 deletions docs/sdk.erc721.revealer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@thirdweb-dev/sdk](./sdk.md) &gt; [Erc721](./sdk.erc721.md) &gt; [revealer](./sdk.erc721.revealer.md)

## Erc721.revealer property

<b>Signature:</b>

```typescript
revealer: DelayedReveal<BaseDelayedRevealERC721 | DropERC721> | undefined;
```
12 changes: 7 additions & 5 deletions etc/sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -855,15 +855,17 @@ export const DEFAULT_IPFS_GATEWAY = "https://gateway.ipfscdn.io/ipfs/";
// @internal (undocumented)
export const DEFAULT_QUERY_ALL_COUNT = 100;

// Warning: (ae-forgotten-export) The symbol "SignatureDrop" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DropERC721" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "BaseDelayedRevealERC721" needs to be exported by the entry point index.d.ts
//
// @public
export class DelayedReveal<T extends SignatureDrop_2 | DropERC721> {
export class DelayedReveal<T extends DropERC721 | BaseDelayedRevealERC721> {
constructor(contractWrapper: ContractWrapper<T>, storage: IStorage);
createDelayedRevealBatch(placeholder: NFTMetadataInput, metadatas: NFTMetadataInput[], password: string, options?: {
onProgress: (event: UploadProgressEvent) => void;
}): Promise<TransactionResultWithId[]>;
// (undocumented)
featureName: "ERC721Revealable";
getBatchesToReveal(): Promise<BatchToReveal[]>;
reveal(batchId: BigNumberish, password: string): Promise<TransactionResult>;
}
Expand Down Expand Up @@ -1682,6 +1684,7 @@ export type ERC20Wrappable = {
};

// Warning: (ae-forgotten-export) The symbol "Multiwrap" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "SignatureDrop" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "TokenERC721" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "BaseERC721" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -1713,6 +1716,8 @@ export class Erc721<T extends Multiwrap_2 | SignatureDrop_2 | DropERC721 | Token
ownerOf(tokenId: BigNumberish): Promise<string>;
// (undocumented)
query: Erc721Supply | undefined;
// (undocumented)
revealer: DelayedReveal<BaseDelayedRevealERC721 | DropERC721> | undefined;
// @internal
setApprovalForAll(operator: string, approved: boolean): Promise<TransactionResult>;
// @internal
Expand Down Expand Up @@ -4216,7 +4221,6 @@ export class SignatureDrop extends Erc721<SignatureDrop_2> {
metadata: ContractMetadata<SignatureDrop_2, typeof SignatureDrop.schema>;
// (undocumented)
platformFees: ContractPlatformFee<SignatureDrop_2>;
revealer: DelayedReveal<SignatureDrop_2>;
// (undocumented)
roles: ContractRoles<SignatureDrop_2, typeof SignatureDrop.contractRoles[number]>;
royalties: ContractRoyalty<SignatureDrop_2, typeof SignatureDrop.schema>;
Expand Down Expand Up @@ -4338,8 +4342,6 @@ export class SignatureDrop extends Erc721<SignatureDrop_2> {
}>;
};
// Warning: (ae-forgotten-export) The symbol "Erc721WithQuantitySignatureMinting" needs to be exported by the entry point index.d.ts
//
// (undocumented)
signature: Erc721WithQuantitySignatureMinting;
totalClaimedSupply(): Promise<BigNumber>;
totalSupply(): Promise<BigNumber>;
Expand Down
4 changes: 3 additions & 1 deletion src/constants/contract-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
FEATURE_NFT_LAZY_MINTABLE,
FEATURE_NFT_MINTABLE,
FEATURE_NFT_SUPPLY,
FEATURE_NFT_REVEALABLE,
} from "./erc721-features";
import {
FEATURE_TOKEN,
Expand Down Expand Up @@ -46,7 +47,8 @@ export type Feature =
| typeof FEATURE_PLATFORM_FEE
| typeof FEATURE_PRIMARY_SALE
| typeof FEATURE_PERMISSIONS
| typeof FEATURE_METADATA;
| typeof FEATURE_METADATA
| typeof FEATURE_NFT_REVEALABLE;

/**
* @internal
Expand Down
13 changes: 13 additions & 0 deletions src/constants/erc721-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Erc721SupplyAbi from "../../abis/IERC721Supply.json";
import IMintableERC721Abi from "../../abis/IMintableERC721.json";
import MulticallAbi from "../../abis/IMulticall.json";
import LazyMintERC721Abi from "../../abis/LazyMintERC721.json";
import DelayedRevealAbi from "../../abis/DelayedReveal.json";

export const FEATURE_NFT_LAZY_MINTABLE = {
name: "ERC721LazyMintable",
Expand Down Expand Up @@ -64,6 +65,17 @@ export const FEATURE_NFT_SUPPLY = {
},
} as const;

export const FEATURE_NFT_REVEALABLE = {
name: "ERC721Revealable",
namespace: "nft.revealer",
docLinks: {
sdk: "sdk.delayedreveal",
contracts: "IDelayedReveal",
},
abis: [Erc721Abi, DelayedRevealAbi, LazyMintERC721Abi],
features: {},
} as const;

export const FEATURE_NFT = {
name: "ERC721",
namespace: "nft",
Expand All @@ -76,5 +88,6 @@ export const FEATURE_NFT = {
[FEATURE_NFT_SUPPLY.name]: FEATURE_NFT_SUPPLY,
[FEATURE_NFT_MINTABLE.name]: FEATURE_NFT_MINTABLE,
[FEATURE_NFT_LAZY_MINTABLE.name]: FEATURE_NFT_LAZY_MINTABLE,
[FEATURE_NFT_REVEALABLE.name]: FEATURE_NFT_REVEALABLE,
},
} as const;
4 changes: 2 additions & 2 deletions src/contracts/nft-drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
BigNumber,
BigNumberish,
BytesLike,
constants,
ethers,
utils,
constants,
} from "ethers";
import { ContractMetadata } from "../core/classes/contract-metadata";
import { ContractRoyalty } from "../core/classes/contract-royalty";
Expand Down Expand Up @@ -159,7 +159,7 @@ export class NFTDrop extends Erc721<DropERC721> {
* await contract.revealer.reveal(batchId, "my secret password");
* ```
*/
public revealer: DelayedReveal<DropERC721>;
public override revealer: DelayedReveal<DropERC721>;

private _query = this.query as Erc721Supply;
private _owned = this._query.owned as Erc721Enumerable;
Expand Down
7 changes: 0 additions & 7 deletions src/contracts/signature-drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { Erc721 } from "../core/classes/erc-721";
import { ContractPrimarySale } from "../core/classes/contract-sales";
import { prepareClaim } from "../common/claim-conditions";
import { ContractEncoder } from "../core/classes/contract-encoder";
import { DelayedReveal } from "../core/classes/delayed-reveal";
import {
Erc721Enumerable,
Erc721Supply,
Expand Down Expand Up @@ -160,8 +159,6 @@ export class SignatureDrop extends Erc721<SignatureDropContract> {
* await contract.revealer.reveal(batchId, "my secret password");
* ```
*/
public revealer: DelayedReveal<SignatureDropContract>;

public signature: Erc721WithQuantitySignatureMinting;

private _query = this.query as Erc721Supply;
Expand Down Expand Up @@ -196,10 +193,6 @@ export class SignatureDrop extends Erc721<SignatureDropContract> {
this.estimator = new GasCostEstimator(this.contractWrapper);
this.events = new ContractEvents(this.contractWrapper);
this.platformFees = new ContractPlatformFee(this.contractWrapper);
this.revealer = new DelayedReveal<SignatureDropContract>(
this.contractWrapper,
this.storage,
);
this.interceptor = new ContractInterceptor(this.contractWrapper);
this.signature = new Erc721WithQuantitySignatureMinting(
this.contractWrapper,
Expand Down
43 changes: 25 additions & 18 deletions src/core/classes/delayed-reveal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumber, BigNumberish, ethers } from "ethers";
import { ContractWrapper } from "./contract-wrapper";
import { DropERC721, SignatureDrop } from "contracts";
import { DropERC721 } from "contracts";
import {
CommonNFTInput,
NFTMetadata,
Expand All @@ -11,12 +11,17 @@ import { fetchTokenMetadata } from "../../common/nft";
import { BatchToReveal } from "../../types/delayed-reveal";
import { TokensLazyMintedEvent } from "contracts/DropERC721";
import { UploadProgressEvent } from "../../types/events";
import { BaseDelayedRevealERC721 } from "../../types/eips";
import { hasFunction } from "../../common";
import { FEATURE_NFT_REVEALABLE } from "../../constants/erc721-features";

/**
* Handles delayed reveal logic
* @public
*/
export class DelayedReveal<T extends SignatureDrop | DropERC721> {
export class DelayedReveal<T extends DropERC721 | BaseDelayedRevealERC721> {
featureName = FEATURE_NFT_REVEALABLE.name;

private contractWrapper: ContractWrapper<T>;
private storage: IStorage;

Expand Down Expand Up @@ -167,17 +172,26 @@ export class DelayedReveal<T extends SignatureDrop | DropERC721> {

const countRangeArray = Array.from(Array(count.toNumber()).keys());

const contractType = ethers.utils.toUtf8String(
await this.contractWrapper.readContract.contractType(),
);

// map over to get the base uri indices, which should be the end token id of every batch
const uriIndices = await Promise.all(
countRangeArray.map((i) =>
this.isSignatureDrop(this.contractWrapper.readContract, contractType)
? this.contractWrapper.readContract.getBatchIdAtIndex(i)
: this.contractWrapper.readContract.baseURIIndices(i),
),
countRangeArray.map((i) => {
if (
hasFunction<BaseDelayedRevealERC721>(
"getBatchIdAtIndex",
this.contractWrapper,
)
) {
return this.contractWrapper.readContract.getBatchIdAtIndex(i);
}

if (hasFunction<DropERC721>("baseURIIndices", this.contractWrapper)) {
return this.contractWrapper.readContract.baseURIIndices(i);
}

throw new Error(
"Contract does not have getBatchIdAtIndex or baseURIIndices.",
);
}),
);

// first batch always start from 0. don't need to fetch the last batch so pop it from the range array
Expand Down Expand Up @@ -235,11 +249,4 @@ export class DelayedReveal<T extends SignatureDrop | DropERC721> {
const tokenUri = await this.contractWrapper.readContract.tokenURI(tokenId);
return fetchTokenMetadata(tokenId, tokenUri, this.storage);
}

private isSignatureDrop(
_contract: SignatureDrop | DropERC721,
contractType: string,
): _contract is SignatureDrop {
return contractType.includes("SignatureDrop");
}
}
28 changes: 23 additions & 5 deletions src/core/classes/erc-721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import {
} from "contracts";
import { Erc721Supply } from "./erc-721-supply";
import { Erc721Mintable } from "./erc-721-mintable";
import { BaseERC721 } from "../../types/eips";
import { BaseDelayedRevealERC721, BaseERC721 } from "../../types/eips";
import { FEATURE_NFT } from "../../constants/erc721-features";
import { DetectableFeature } from "../interfaces/DetectableFeature";
import { Erc721LazyMintable } from "./erc-721-lazy-mintable";
import { DelayedReveal } from "./delayed-reveal";

/**
* Standard ERC721 NFT functions
Expand All @@ -47,13 +48,15 @@ export class Erc721<
> implements UpdateableNetwork, DetectableFeature
{
featureName = FEATURE_NFT.name;
protected contractWrapper: ContractWrapper<T>;
protected storage: IStorage;
protected options: SDKOptions;

public query: Erc721Supply | undefined;
public mint: Erc721Mintable | undefined;
public lazy: Erc721LazyMintable | undefined;
public revealer:
| DelayedReveal<BaseDelayedRevealERC721 | DropERC721>
| undefined;
protected contractWrapper: ContractWrapper<T>;
protected storage: IStorage;
protected options: SDKOptions;

constructor(
contractWrapper: ContractWrapper<T>,
Expand All @@ -74,6 +77,7 @@ export class Erc721<
this.query = this.detectErc721Enumerable();
this.mint = this.detectErc721Mintable();
this.lazy = this.detectErc721LazyMintable();
this.revealer = this.detectErc721Revealable();
}

/**
Expand Down Expand Up @@ -273,4 +277,18 @@ export class Erc721<
}
return undefined;
}

private detectErc721Revealable():
| DelayedReveal<BaseDelayedRevealERC721>
| undefined {
if (
detectContractFeature<BaseDelayedRevealERC721>(
this.contractWrapper,
"ERC721Revealable",
)
) {
return new DelayedReveal(this.contractWrapper, this.storage);
}
return undefined;
}
}
1 change: 1 addition & 0 deletions src/core/classes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from "./contract-metadata";
export * from "./contract-roles";
export * from "./contract-royalty";
export * from "./contract-sales";
export * from "./delayed-reveal";
export * from "./drop-claim-conditions";
export * from "./drop-erc1155-claim-conditions";
export * from "./drop-erc1155-history";
Expand Down
7 changes: 7 additions & 0 deletions src/types/eips.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import {
DelayedReveal,
DropERC721,
IERC1155,
IERC1155Metadata,
IERC1155Supply,
IERC20,
IERC20Metadata,
IERC721,
IERC721Metadata,
LazyMintERC721,
} from "contracts";

export type BaseERC20 = IERC20 & IERC20Metadata;
export type BaseERC721 = IERC721 & IERC721Metadata;
export type BaseERC1155 = IERC1155 & IERC1155Metadata & IERC1155Supply;
export type BaseDelayedRevealERC721 = BaseERC721 &
DelayedReveal &
LazyMintERC721 &
DropERC721;
Loading