Compare commits

..
Author SHA1 Message Date
github-actions[bot]andgithub-actions[bot] 2e8d3fd6e7 Version Packages (#358)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2022-10-28 18:14:35 -07:00
Nacho Iacovino cc4613b5fd [React] Add Pack and Multiwrap as NFTContract types (#356) 2022-10-29 01:28:40 +02:00
github-actions[bot]andgithub-actions[bot] 78566babaa Version Packages (#354)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2022-10-28 10:29:57 -07:00
Joaquim Verges 65fc7ba6ff [SDK] Expose claimCondtions.getClaimerProofs(address) (#357) 2022-10-28 10:25:36 -07:00
Nacho Iacovino 1c24c3c3c4 [Multi] Add useUpdateCreator hook, fix CreatorInput schema (#353) 2022-10-26 18:19:32 +00:00
21 changed files with 172 additions and 19 deletions
+4
View File
@@ -1,5 +1,9 @@
# @thirdweb-dev/auth # @thirdweb-dev/auth
## 2.0.25
## 2.0.24
## 2.0.23 ## 2.0.23
## 2.0.22 ## 2.0.22
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@thirdweb-dev/auth", "name": "@thirdweb-dev/auth",
"version": "2.0.23", "version": "2.0.25",
"exports": { "exports": {
"./next": { "./next": {
"module": "./next/dist/thirdweb-dev-auth-next.esm.js", "module": "./next/dist/thirdweb-dev-auth-next.esm.js",
+14
View File
@@ -1,5 +1,19 @@
# thirdweb # thirdweb
## 0.8.11
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/sdk@3.4.4
## 0.8.10
### Patch Changes
- Updated dependencies [[`1c24c3c`](https://github.com/thirdweb-dev/js/commit/1c24c3c3c48476a824f817e09e7bf0fbe67c1db5), [`65fc7ba`](https://github.com/thirdweb-dev/js/commit/65fc7ba6fff093a971b53cb0979c39768e090ba1)]:
- @thirdweb-dev/sdk@3.4.3
## 0.8.9 ## 0.8.9
### Patch Changes ### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "thirdweb", "name": "thirdweb",
"main": "dist/cli/index.js", "main": "dist/cli/index.js",
"version": "0.8.9", "version": "0.8.11",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli", "repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
"author": "thirdweb eng <[email protected]>", "author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0", "license": "Apache-2.0",
+12
View File
@@ -1,5 +1,17 @@
# @thirdweb-dev/react # @thirdweb-dev/react
## 3.4.4
### Patch Changes
- [#356](https://github.com/thirdweb-dev/js/pull/356) [`cc4613b`](https://github.com/thirdweb-dev/js/commit/cc4613b5fd69840f4f9cfd0ac1c4e6743e62fe52) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add Pack and Multiwrap as NFTContract types
## 3.4.3
### Patch Changes
- [#353](https://github.com/thirdweb-dev/js/pull/353) [`1c24c3c`](https://github.com/thirdweb-dev/js/commit/1c24c3c3c48476a824f817e09e7bf0fbe67c1db5) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add useUpdateCreators hook, fix CreatorInput schema
## 3.4.2 ## 3.4.2
### Patch Changes ### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@thirdweb-dev/react", "name": "@thirdweb-dev/react",
"version": "3.4.2", "version": "3.4.4",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react", "repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
"author": "thirdweb eng <[email protected]>", "author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0", "license": "Apache-2.0",
+4
View File
@@ -14,6 +14,8 @@ import type {
ClaimOptions, ClaimOptions,
NFTMetadataOrUri, NFTMetadataOrUri,
Token, Token,
Multiwrap,
Pack,
} from "@thirdweb-dev/sdk"; } from "@thirdweb-dev/sdk";
import type { Edition } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition"; import type { Edition } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition";
import type { EditionDrop } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition-drop"; import type { EditionDrop } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition-drop";
@@ -68,6 +70,8 @@ export type TokenBurnParams = {
export type NFTContract = export type NFTContract =
| NFTCollection | NFTCollection
| Edition | Edition
| Pack
| Multiwrap
| Exclude<DropContract, "TokenDrop">; | Exclude<DropContract, "TokenDrop">;
/** /**
@@ -0,0 +1,47 @@
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
import {
requiredParamInvariant,
RequiredParam,
} from "../../../core/query-utils/required-param";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import type { CreatorInput, NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
/**
* Update the creators for an NFT program
* @param program - The NFT program instance to update the creators for
*
* @example
* ```jsx
* import { useProgram, useUpdateCreators } from "@thirdweb-dev/react/solana";
*
* export default function Component() {
* const { program } = useProgram("{{program_address}}");
* const { mutateAsync: updateCreators, isLoading, error } = useUpdateCreators(program);
*
* return (
* <button
* onClick={() => updateCreators([{ address: "0x...", share: 10 }])}
* >
* Update Creators
* </button>
* )
* }
* ```
*
* @public
*/
export function useUpdateCreators(
program: RequiredParam<NFTCollection | NFTDrop>,
) {
const queryClient = useQueryClient();
return useMutation(
async (creators: CreatorInput[]) => {
requiredParamInvariant(program, "program is required");
return await program.updateCreators(creators);
},
{
onSettled: () =>
queryClient.invalidateQueries(createSOLProgramQueryKey(program)),
},
);
}
+2
View File
@@ -16,6 +16,8 @@ export * from "./hooks/nft/useTransferNFT";
export * from "./hooks/nft/useBurnNFT"; export * from "./hooks/nft/useBurnNFT";
export * from "./hooks/nft/useRoyaltySettings"; export * from "./hooks/nft/useRoyaltySettings";
export * from "./hooks/nft/useUpdateRoyaltySettings"; export * from "./hooks/nft/useUpdateRoyaltySettings";
export * from "./hooks/nft/useCreators";
export * from "./hooks/nft/useUpdateCreators";
// NFT Collection // NFT Collection
export * from "./hooks/nft/collection/useMintNFT"; export * from "./hooks/nft/collection/useMintNFT";
+10
View File
@@ -1,5 +1,15 @@
# @thirdweb-dev/sdk # @thirdweb-dev/sdk
## 3.4.4
## 3.4.3
### Patch Changes
- [#353](https://github.com/thirdweb-dev/js/pull/353) [`1c24c3c`](https://github.com/thirdweb-dev/js/commit/1c24c3c3c48476a824f817e09e7bf0fbe67c1db5) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add useUpdateCreators hook, fix CreatorInput schema
- [#357](https://github.com/thirdweb-dev/js/pull/357) [`65fc7ba`](https://github.com/thirdweb-dev/js/commit/65fc7ba6fff093a971b53cb0979c39768e090ba1) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose claimConditions.getClaimerProofs(address) to get allowlist information for a given address
## 3.4.2 ## 3.4.2
### Patch Changes ### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@thirdweb-dev/sdk", "name": "@thirdweb-dev/sdk",
"version": "3.4.2", "version": "3.4.4",
"description": "The main thirdweb SDK.", "description": "The main thirdweb SDK.",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk", "repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
"license": "Apache-2.0", "license": "Apache-2.0",
+2 -2
View File
@@ -72,12 +72,12 @@ export const BigNumberTransformSchema = z
export const BasisPointsSchema = z export const BasisPointsSchema = z
.number() .number()
.max(MAX_BPS, "Cannot exeed 100%") .max(MAX_BPS, "Cannot exceed 100%")
.min(0, "Cannot be below 0%"); .min(0, "Cannot be below 0%");
export const PercentSchema = z export const PercentSchema = z
.number() .number()
.max(100, "Cannot exeed 100%") .max(100, "Cannot exceed 100%")
.min(0, "Cannot be below 0%"); .min(0, "Cannot be below 0%");
export const HexColor = z.union([ export const HexColor = z.union([
@@ -1,5 +1,6 @@
import { includesErrorMessage } from "../../common"; import { includesErrorMessage } from "../../common";
import { import {
fetchSnapshotEntryForAddress,
getClaimerProofs, getClaimerProofs,
prepareClaim, prepareClaim,
processClaimConditionInputs, processClaimConditionInputs,
@@ -14,7 +15,7 @@ import {
import { isNode } from "../../common/utils"; import { isNode } from "../../common/utils";
import { NATIVE_TOKEN_ADDRESS } from "../../constants/index"; import { NATIVE_TOKEN_ADDRESS } from "../../constants/index";
import { ClaimEligibility } from "../../enums"; import { ClaimEligibility } from "../../enums";
import { AmountSchema } from "../../schema"; import { AmountSchema, SnapshotEntryWithProof } from "../../schema";
import { import {
Amount, Amount,
ClaimCondition, ClaimCondition,
@@ -339,6 +340,31 @@ export class DropClaimConditions<
return reasons; return reasons;
} }
/**
* Returns allow list information and merkle proofs for the given address.
* @param claimerAddress
*/
public async getClaimerProofs(
claimerAddress: string,
): Promise<SnapshotEntryWithProof | null> {
const claimCondition = await this.getActive();
const merkeRoot = claimCondition.merkleRootHash;
const merkleRootArray = ethers.utils.stripZeros(
claimCondition.merkleRootHash,
);
if (merkleRootArray.length > 0) {
const metadata = await this.metadata.get();
return await fetchSnapshotEntryForAddress(
claimerAddress,
merkeRoot.toString(),
metadata.merkle,
this.storage,
);
} else {
return null;
}
}
/** *************************************** /** ***************************************
* WRITE FUNCTIONS * WRITE FUNCTIONS
*****************************************/ *****************************************/
@@ -1,5 +1,6 @@
import { includesErrorMessage } from "../../common"; import { includesErrorMessage } from "../../common";
import { import {
fetchSnapshotEntryForAddress,
getClaimerProofs, getClaimerProofs,
prepareClaim, prepareClaim,
processClaimConditionInputs, processClaimConditionInputs,
@@ -11,6 +12,7 @@ import { hasFunction } from "../../common/feature-detection";
import { isNode } from "../../common/utils"; import { isNode } from "../../common/utils";
import { NATIVE_TOKEN_ADDRESS } from "../../constants/index"; import { NATIVE_TOKEN_ADDRESS } from "../../constants/index";
import { ClaimEligibility } from "../../enums"; import { ClaimEligibility } from "../../enums";
import { SnapshotEntryWithProof } from "../../schema";
import { import {
ClaimCondition, ClaimCondition,
ClaimConditionFetchOptions, ClaimConditionFetchOptions,
@@ -342,6 +344,33 @@ export class DropErc1155ClaimConditions<
return reasons; return reasons;
} }
/**
* Returns allow list information and merkle proofs for the given address.
* @param tokenId
* @param claimerAddress
*/
public async getClaimerProofs(
tokenId: BigNumberish,
claimerAddress: string,
): Promise<SnapshotEntryWithProof | null> {
const claimCondition = await this.getActive(tokenId);
const merkeRoot = claimCondition.merkleRootHash;
const merkleRootArray = ethers.utils.stripZeros(
claimCondition.merkleRootHash,
);
if (merkleRootArray.length > 0) {
const metadata = await this.metadata.get();
return await fetchSnapshotEntryForAddress(
claimerAddress,
merkeRoot.toString(),
metadata.merkle,
this.storage,
);
} else {
return null;
}
}
/** *************************************** /** ***************************************
* WRITE FUNCTIONS * WRITE FUNCTIONS
*****************************************/ *****************************************/
+2 -2
View File
@@ -57,12 +57,12 @@ export const BigNumberTransformSchema = z
export const BasisPointsSchema = z export const BasisPointsSchema = z
.number() .number()
.max(MAX_BPS, "Cannot exeed 100%") .max(MAX_BPS, "Cannot exceed 100%")
.min(0, "Cannot be below 0%"); .min(0, "Cannot be below 0%");
export const PercentSchema = z export const PercentSchema = z
.number() .number()
.max(100, "Cannot exeed 100%") .max(100, "Cannot exceed 100%")
.min(0, "Cannot be below 0%"); .min(0, "Cannot be below 0%");
export const AddressSchema = z.string().refine( export const AddressSchema = z.string().refine(
@@ -13,14 +13,14 @@ export function enforceCreator(
// If no creators are specified, we assume the owner is the creator // If no creators are specified, we assume the owner is the creator
creators = creators.concat({ creators = creators.concat({
address: owner.toBase58(), address: owner.toBase58(),
sharePercentage: 100, share: 100,
verified: true, verified: true,
}); });
} }
return creators.map((creator) => ({ return creators.map((creator) => ({
verified: creator.verified || false, verified: creator.verified || false,
address: new PublicKey(creator.address), address: new PublicKey(creator.address),
share: creator.sharePercentage, share: creator.share,
})); }));
} }
+2 -2
View File
@@ -12,7 +12,7 @@ export const MAX_BPS = 10000;
*/ */
export const BasisPointsSchema = z export const BasisPointsSchema = z
.number() .number()
.max(MAX_BPS, "Cannot exeed 100%") .max(MAX_BPS, "Cannot exceed 100%")
.min(0, "Cannot be below 0%"); .min(0, "Cannot be below 0%");
/** /**
@@ -20,7 +20,7 @@ export const BasisPointsSchema = z
*/ */
export const PercentSchema = z export const PercentSchema = z
.number() .number()
.max(100, "Cannot exeed 100%") .max(100, "Cannot exceed 100%")
.min(0, "Cannot be below 0%"); .min(0, "Cannot be below 0%");
/** /**
@@ -1,4 +1,4 @@
import { AmountSchema, FileOrBufferOrStringSchema } from "../common"; import { AmountSchema, FileOrBufferOrStringSchema, PercentSchema } from "../common";
import { Creator } from "@metaplex-foundation/js"; import { Creator } from "@metaplex-foundation/js";
import { z } from "zod"; import { z } from "zod";
@@ -27,7 +27,7 @@ export const CommonContractOutputSchema = CommonContractSchema.extend({
*/ */
export const CreatorInputSchema = z.object({ export const CreatorInputSchema = z.object({
address: z.string(), address: z.string(),
sharePercentage: z.number(), share: PercentSchema,
verified: z.boolean().default(false), verified: z.boolean().default(false),
}); });
+5
View File
@@ -97,6 +97,11 @@ describe("NFT Drop Contract", async () => {
(c) => c.merkleRootHash, (c) => c.merkleRootHash,
); );
expect(roots).length(2); expect(roots).length(2);
const proof = await dropContract.claimConditions.getClaimerProofs(
bobWallet.address,
);
expect(proof.address).to.eq(bobWallet.address);
}); });
it("should return snapshot data on claim conditions", async () => { it("should return snapshot data on claim conditions", async () => {
@@ -143,8 +143,8 @@ describe("NFTCollection", async () => {
const newCreator = Keypair.generate().publicKey.toBase58(); const newCreator = Keypair.generate().publicKey.toBase58();
await collection.updateCreators([ await collection.updateCreators([
{ address: sdk.wallet.getAddress() as string, sharePercentage: 75 }, { address: sdk.wallet.getAddress() as string, share: 75 },
{ address: newCreator, sharePercentage: 25 }, { address: newCreator, share: 25 },
]); ]);
creators = await collection.getCreators(); creators = await collection.getCreators();
+2 -2
View File
@@ -133,8 +133,8 @@ describe("NFTDrop", async () => {
const newCreator = Keypair.generate().publicKey.toBase58(); const newCreator = Keypair.generate().publicKey.toBase58();
await drop.updateCreators([ await drop.updateCreators([
{ address: sdk.wallet.getAddress() as string, sharePercentage: 75 }, { address: sdk.wallet.getAddress() as string, share: 75 },
{ address: newCreator, sharePercentage: 25 }, { address: newCreator, share: 25 },
]); ]);
creators = await drop.getCreators(); creators = await drop.getCreators();