Compare commits

...
Author SHA1 Message Date
github-actions[bot]GitHubgithub-actions[bot] <github-actions[bot]@users.noreply.github.com>
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 VergesandGitHub 65fc7ba6ff [SDK] Expose claimCondtions.getClaimerProofs(address) (#357) 2022-10-28 10:25:36 -07:00
Nacho IacovinoandGitHub 1c24c3c3c4 [Multi] Add useUpdateCreator hook, fix CreatorInput schema (#353) 2022-10-26 18:19:32 +00:00
20 changed files with 151 additions and 19 deletions
+2
View File
@@ -1,5 +1,7 @@
# @thirdweb-dev/auth
## 2.0.24
## 2.0.23
## 2.0.22
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/auth",
"version": "2.0.23",
"version": "2.0.24",
"exports": {
"./next": {
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
+7
View File
@@ -1,5 +1,12 @@
# thirdweb
## 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
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "thirdweb",
"main": "dist/cli/index.js",
"version": "0.8.9",
"version": "0.8.10",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+6
View File
@@ -1,5 +1,11 @@
# @thirdweb-dev/react
## 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
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react",
"version": "3.4.2",
"version": "3.4.3",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
@@ -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/useRoyaltySettings";
export * from "./hooks/nft/useUpdateRoyaltySettings";
export * from "./hooks/nft/useCreators";
export * from "./hooks/nft/useUpdateCreators";
// NFT Collection
export * from "./hooks/nft/collection/useMintNFT";
+8
View File
@@ -1,5 +1,13 @@
# @thirdweb-dev/sdk
## 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
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/sdk",
"version": "3.4.2",
"version": "3.4.3",
"description": "The main thirdweb SDK.",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
"license": "Apache-2.0",
+2 -2
View File
@@ -72,12 +72,12 @@ export const BigNumberTransformSchema = z
export const BasisPointsSchema = z
.number()
.max(MAX_BPS, "Cannot exeed 100%")
.max(MAX_BPS, "Cannot exceed 100%")
.min(0, "Cannot be below 0%");
export const PercentSchema = z
.number()
.max(100, "Cannot exeed 100%")
.max(100, "Cannot exceed 100%")
.min(0, "Cannot be below 0%");
export const HexColor = z.union([
@@ -1,5 +1,6 @@
import { includesErrorMessage } from "../../common";
import {
fetchSnapshotEntryForAddress,
getClaimerProofs,
prepareClaim,
processClaimConditionInputs,
@@ -14,7 +15,7 @@ import {
import { isNode } from "../../common/utils";
import { NATIVE_TOKEN_ADDRESS } from "../../constants/index";
import { ClaimEligibility } from "../../enums";
import { AmountSchema } from "../../schema";
import { AmountSchema, SnapshotEntryWithProof } from "../../schema";
import {
Amount,
ClaimCondition,
@@ -339,6 +340,31 @@ export class DropClaimConditions<
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
*****************************************/
@@ -1,5 +1,6 @@
import { includesErrorMessage } from "../../common";
import {
fetchSnapshotEntryForAddress,
getClaimerProofs,
prepareClaim,
processClaimConditionInputs,
@@ -11,6 +12,7 @@ import { hasFunction } from "../../common/feature-detection";
import { isNode } from "../../common/utils";
import { NATIVE_TOKEN_ADDRESS } from "../../constants/index";
import { ClaimEligibility } from "../../enums";
import { SnapshotEntryWithProof } from "../../schema";
import {
ClaimCondition,
ClaimConditionFetchOptions,
@@ -342,6 +344,33 @@ export class DropErc1155ClaimConditions<
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
*****************************************/
+2 -2
View File
@@ -57,12 +57,12 @@ export const BigNumberTransformSchema = z
export const BasisPointsSchema = z
.number()
.max(MAX_BPS, "Cannot exeed 100%")
.max(MAX_BPS, "Cannot exceed 100%")
.min(0, "Cannot be below 0%");
export const PercentSchema = z
.number()
.max(100, "Cannot exeed 100%")
.max(100, "Cannot exceed 100%")
.min(0, "Cannot be below 0%");
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
creators = creators.concat({
address: owner.toBase58(),
sharePercentage: 100,
share: 100,
verified: true,
});
}
return creators.map((creator) => ({
verified: creator.verified || false,
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
.number()
.max(MAX_BPS, "Cannot exeed 100%")
.max(MAX_BPS, "Cannot exceed 100%")
.min(0, "Cannot be below 0%");
/**
@@ -20,7 +20,7 @@ export const BasisPointsSchema = z
*/
export const PercentSchema = z
.number()
.max(100, "Cannot exeed 100%")
.max(100, "Cannot exceed 100%")
.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 { z } from "zod";
@@ -27,7 +27,7 @@ export const CommonContractOutputSchema = CommonContractSchema.extend({
*/
export const CreatorInputSchema = z.object({
address: z.string(),
sharePercentage: z.number(),
share: PercentSchema,
verified: z.boolean().default(false),
});
+5
View File
@@ -97,6 +97,11 @@ describe("NFT Drop Contract", async () => {
(c) => c.merkleRootHash,
);
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 () => {
@@ -143,8 +143,8 @@ describe("NFTCollection", async () => {
const newCreator = Keypair.generate().publicKey.toBase58();
await collection.updateCreators([
{ address: sdk.wallet.getAddress() as string, sharePercentage: 75 },
{ address: newCreator, sharePercentage: 25 },
{ address: sdk.wallet.getAddress() as string, share: 75 },
{ address: newCreator, share: 25 },
]);
creators = await collection.getCreators();
+2 -2
View File
@@ -133,8 +133,8 @@ describe("NFTDrop", async () => {
const newCreator = Keypair.generate().publicKey.toBase58();
await drop.updateCreators([
{ address: sdk.wallet.getAddress() as string, sharePercentage: 75 },
{ address: newCreator, sharePercentage: 25 },
{ address: sdk.wallet.getAddress() as string, share: 75 },
{ address: newCreator, share: 25 },
]);
creators = await drop.getCreators();