Skip to content

Commit 9bcd0cc

Browse files
committed
Update
1 parent 47f5387 commit 9bcd0cc

File tree

3 files changed

+81
-54
lines changed

3 files changed

+81
-54
lines changed

packages/thirdweb/src/exports/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ export type { NFTMetadata, NFTInput } from "../utils/nft/parseNft.js";
178178

179179
export { parseAbiParams } from "../utils/contract/parse-abi-params.js";
180180

181+
export { getSetClaimConditionPhases } from "../utils/extensions/drops/get-set-claim-condition-phases.js";
182+
181183
// ------------------------------------------------
182184
// bigint
183185
// ------------------------------------------------

packages/thirdweb/src/utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.ts

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import { maxUint256 } from "viem";
2-
import { NATIVE_TOKEN_ADDRESS } from "../../../constants/addresses.js";
31
import type { ThirdwebContract } from "../../../contract/contract.js";
4-
import type { SetClaimConditionsParams as GeneratedParams } from "../../../extensions/erc1155/__generated__/IDrop1155/write/setClaimConditions.js";
52
import { upload } from "../../../storage/upload.js";
6-
import { dateToSeconds } from "../../date.js";
7-
import { type Hex, toHex } from "../../encoding/hex.js";
8-
import { convertErc20Amount } from "../convert-erc20-amount.js";
9-
import { processOverrideList } from "./process-override-list.js";
3+
import type { Hex } from "../../encoding/hex.js";
4+
import { getSetClaimConditionPhases } from "./get-set-claim-condition-phases.js";
105
import type { ClaimConditionsInput } from "./types.js";
116

127
export async function getMulticallSetClaimConditionTransactions(options: {
@@ -16,48 +11,7 @@ export async function getMulticallSetClaimConditionTransactions(options: {
1611
tokenId?: bigint;
1712
resetClaimEligibility?: boolean;
1813
}): Promise<Hex[]> {
19-
const merkleInfos: Record<string, string> = {};
20-
const phases = await Promise.all(
21-
options.phases.map(async (phase) => {
22-
// allowlist
23-
let merkleRoot: string = phase.merkleRootHash || toHex("", { size: 32 });
24-
if (phase.overrideList) {
25-
const { shardedMerkleInfo, uri } = await processOverrideList({
26-
overrides: phase.overrideList,
27-
client: options.contract.client,
28-
chain: options.contract.chain,
29-
tokenDecimals: options.tokenDecimals,
30-
});
31-
merkleInfos[shardedMerkleInfo.merkleRoot] = uri;
32-
merkleRoot = shardedMerkleInfo.merkleRoot;
33-
}
34-
// metadata
35-
let metadata = "";
36-
if (phase.metadata && typeof phase.metadata === "string") {
37-
metadata = phase.metadata;
38-
} else if (phase.metadata && typeof phase.metadata === "object") {
39-
metadata = await upload({
40-
client: options.contract.client,
41-
files: [phase.metadata],
42-
});
43-
}
44-
return {
45-
startTimestamp: dateToSeconds(phase.startTime ?? new Date(0)),
46-
currency: phase.currencyAddress || NATIVE_TOKEN_ADDRESS,
47-
pricePerToken: await convertErc20Amount({
48-
chain: options.contract.chain,
49-
client: options.contract.client,
50-
erc20Address: phase.currencyAddress || NATIVE_TOKEN_ADDRESS,
51-
amount: phase.price?.toString() ?? "0",
52-
}),
53-
maxClaimableSupply: phase.maxClaimableSupply ?? maxUint256,
54-
quantityLimitPerWallet: phase.maxClaimablePerWallet ?? maxUint256,
55-
merkleRoot,
56-
metadata,
57-
supplyClaimed: 0n,
58-
} as GeneratedParams["phases"][number];
59-
}),
60-
);
14+
const { merkleInfos, phases } = await getSetClaimConditionPhases(options);
6115
const encodedTransactions: Hex[] = [];
6216
// if we have new merkle roots, we need to upload them to the contract metadata
6317
if (Object.keys(merkleInfos).length > 0) {
@@ -88,9 +42,6 @@ export async function getMulticallSetClaimConditionTransactions(options: {
8842
});
8943
encodedTransactions.push(encodedSetContractURI);
9044
}
91-
const sortedPhases = phases.sort((a, b) =>
92-
Number(a.startTimestamp - b.startTimestamp),
93-
);
9445
let encodedSetClaimConditions: Hex;
9546
if (options.tokenId !== undefined) {
9647
// 1155
@@ -99,7 +50,7 @@ export async function getMulticallSetClaimConditionTransactions(options: {
9950
);
10051
encodedSetClaimConditions = encodeSetClaimConditions({
10152
tokenId: options.tokenId,
102-
phases: sortedPhases,
53+
phases,
10354
resetClaimEligibility: options.resetClaimEligibility || false,
10455
});
10556
} else {
@@ -108,7 +59,7 @@ export async function getMulticallSetClaimConditionTransactions(options: {
10859
"../../../extensions/erc721/__generated__/IDrop/write/setClaimConditions.js"
10960
);
11061
encodedSetClaimConditions = encodeSetClaimConditions({
111-
phases: sortedPhases,
62+
phases,
11263
resetClaimEligibility: options.resetClaimEligibility || false,
11364
});
11465
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { maxUint256 } from "viem";
2+
import { NATIVE_TOKEN_ADDRESS } from "../../../constants/addresses.js";
3+
import type { ThirdwebContract } from "../../../contract/contract.js";
4+
import type { SetClaimConditionsParams as GeneratedParams } from "../../../extensions/erc1155/__generated__/IDrop1155/write/setClaimConditions.js";
5+
import { upload } from "../../../storage/upload.js";
6+
import { dateToSeconds } from "../../date.js";
7+
import { toHex } from "../../encoding/hex.js";
8+
import { convertErc20Amount } from "../convert-erc20-amount.js";
9+
import { processOverrideList } from "./process-override-list.js";
10+
import type { ClaimConditionsInput } from "./types.js";
11+
12+
/**
13+
* @param options
14+
* @utils
15+
*/
16+
export async function getSetClaimConditionPhases(options: {
17+
phases: ClaimConditionsInput[];
18+
contract: ThirdwebContract;
19+
tokenDecimals: number;
20+
tokenId?: bigint;
21+
resetClaimEligibility?: boolean;
22+
}) {
23+
// We need to expose this function so that some users can use it to print out the value,
24+
// which they can use with the Explorer
25+
const merkleInfos: Record<string, string> = {};
26+
const phases = await Promise.all(
27+
options.phases.map(async (phase) => {
28+
// allowlist
29+
let merkleRoot: string = phase.merkleRootHash || toHex("", { size: 32 });
30+
if (phase.overrideList) {
31+
const { shardedMerkleInfo, uri } = await processOverrideList({
32+
overrides: phase.overrideList,
33+
client: options.contract.client,
34+
chain: options.contract.chain,
35+
tokenDecimals: options.tokenDecimals,
36+
});
37+
merkleInfos[shardedMerkleInfo.merkleRoot] = uri;
38+
merkleRoot = shardedMerkleInfo.merkleRoot;
39+
}
40+
// metadata
41+
let metadata = "";
42+
if (phase.metadata && typeof phase.metadata === "string") {
43+
metadata = phase.metadata;
44+
} else if (phase.metadata && typeof phase.metadata === "object") {
45+
metadata = await upload({
46+
client: options.contract.client,
47+
files: [phase.metadata],
48+
});
49+
}
50+
return {
51+
startTimestamp: dateToSeconds(phase.startTime ?? new Date(0)),
52+
currency: phase.currencyAddress || NATIVE_TOKEN_ADDRESS,
53+
pricePerToken: await convertErc20Amount({
54+
chain: options.contract.chain,
55+
client: options.contract.client,
56+
erc20Address: phase.currencyAddress || NATIVE_TOKEN_ADDRESS,
57+
amount: phase.price?.toString() ?? "0",
58+
}),
59+
maxClaimableSupply: phase.maxClaimableSupply ?? maxUint256,
60+
quantityLimitPerWallet: phase.maxClaimablePerWallet ?? maxUint256,
61+
merkleRoot,
62+
metadata,
63+
supplyClaimed: 0n,
64+
} as GeneratedParams["phases"][number];
65+
}),
66+
);
67+
const sortedPhases = phases.sort((a, b) =>
68+
Number(a.startTimestamp - b.startTimestamp),
69+
);
70+
return {
71+
phases: sortedPhases,
72+
merkleInfos,
73+
};
74+
}

0 commit comments

Comments
 (0)