Skip to content
Closed
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
2 changes: 2 additions & 0 deletions packages/thirdweb/src/exports/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export type { NFTMetadata, NFTInput } from "../utils/nft/parseNft.js";

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

export { getSetClaimConditionPhases } from "../utils/extensions/drops/get-set-claim-condition-phases.js";

// ------------------------------------------------
// bigint
// ------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { maxUint256 } from "viem";
import { NATIVE_TOKEN_ADDRESS } from "../../../constants/addresses.js";
import type { ThirdwebContract } from "../../../contract/contract.js";
import type { SetClaimConditionsParams as GeneratedParams } from "../../../extensions/erc1155/__generated__/IDrop1155/write/setClaimConditions.js";
import { upload } from "../../../storage/upload.js";
import { dateToSeconds } from "../../date.js";
import { type Hex, toHex } from "../../encoding/hex.js";
import { convertErc20Amount } from "../convert-erc20-amount.js";
import { processOverrideList } from "./process-override-list.js";
import type { Hex } from "../../encoding/hex.js";
import { getSetClaimConditionPhases } from "./get-set-claim-condition-phases.js";
import type { ClaimConditionsInput } from "./types.js";

export async function getMulticallSetClaimConditionTransactions(options: {
Expand All @@ -16,48 +11,7 @@ export async function getMulticallSetClaimConditionTransactions(options: {
tokenId?: bigint;
resetClaimEligibility?: boolean;
}): Promise<Hex[]> {
const merkleInfos: Record<string, string> = {};
const phases = await Promise.all(
options.phases.map(async (phase) => {
// allowlist
let merkleRoot: string = phase.merkleRootHash || toHex("", { size: 32 });
if (phase.overrideList) {
const { shardedMerkleInfo, uri } = await processOverrideList({
overrides: phase.overrideList,
client: options.contract.client,
chain: options.contract.chain,
tokenDecimals: options.tokenDecimals,
});
merkleInfos[shardedMerkleInfo.merkleRoot] = uri;
merkleRoot = shardedMerkleInfo.merkleRoot;
}
// metadata
let metadata = "";
if (phase.metadata && typeof phase.metadata === "string") {
metadata = phase.metadata;
} else if (phase.metadata && typeof phase.metadata === "object") {
metadata = await upload({
client: options.contract.client,
files: [phase.metadata],
});
}
return {
startTimestamp: dateToSeconds(phase.startTime ?? new Date(0)),
currency: phase.currencyAddress || NATIVE_TOKEN_ADDRESS,
pricePerToken: await convertErc20Amount({
chain: options.contract.chain,
client: options.contract.client,
erc20Address: phase.currencyAddress || NATIVE_TOKEN_ADDRESS,
amount: phase.price?.toString() ?? "0",
}),
maxClaimableSupply: phase.maxClaimableSupply ?? maxUint256,
quantityLimitPerWallet: phase.maxClaimablePerWallet ?? maxUint256,
merkleRoot,
metadata,
supplyClaimed: 0n,
} as GeneratedParams["phases"][number];
}),
);
const { merkleInfos, phases } = await getSetClaimConditionPhases(options);
const encodedTransactions: Hex[] = [];
// if we have new merkle roots, we need to upload them to the contract metadata
if (Object.keys(merkleInfos).length > 0) {
Expand Down Expand Up @@ -88,9 +42,6 @@ export async function getMulticallSetClaimConditionTransactions(options: {
});
encodedTransactions.push(encodedSetContractURI);
}
const sortedPhases = phases.sort((a, b) =>
Number(a.startTimestamp - b.startTimestamp),
);
let encodedSetClaimConditions: Hex;
if (options.tokenId !== undefined) {
// 1155
Expand All @@ -99,7 +50,7 @@ export async function getMulticallSetClaimConditionTransactions(options: {
);
encodedSetClaimConditions = encodeSetClaimConditions({
tokenId: options.tokenId,
phases: sortedPhases,
phases,
resetClaimEligibility: options.resetClaimEligibility || false,
});
} else {
Expand All @@ -108,7 +59,7 @@ export async function getMulticallSetClaimConditionTransactions(options: {
"../../../extensions/erc721/__generated__/IDrop/write/setClaimConditions.js"
);
encodedSetClaimConditions = encodeSetClaimConditions({
phases: sortedPhases,
phases,
resetClaimEligibility: options.resetClaimEligibility || false,
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { maxUint256 } from "viem";
import { NATIVE_TOKEN_ADDRESS } from "../../../constants/addresses.js";
import type { ThirdwebContract } from "../../../contract/contract.js";
import type { SetClaimConditionsParams as GeneratedParams } from "../../../extensions/erc1155/__generated__/IDrop1155/write/setClaimConditions.js";
import { upload } from "../../../storage/upload.js";
import { dateToSeconds } from "../../date.js";
import { toHex } from "../../encoding/hex.js";
import { convertErc20Amount } from "../convert-erc20-amount.js";
import { processOverrideList } from "./process-override-list.js";
import type { ClaimConditionsInput } from "./types.js";

/**
* @param options
* @utils
*/
export async function getSetClaimConditionPhases(options: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this name is... very confusing.

I should be able to get a good idea of what this is for just by looking at the name.

Also i really dont think we should be exposing this this way. The inputs are kinda internal to us, you need to understand what tokenDecimals is for, what resetClaimEligibility does etc.

And once we expose it publicly, we can't change the API anymore.

Remind me again what's the use case you're trying to solve here? will help us figure out a good public API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do better here. Let me update the code and ping you again. This is a non-urgent issue

phases: ClaimConditionsInput[];
contract: ThirdwebContract;
tokenDecimals: number;
tokenId?: bigint;
resetClaimEligibility?: boolean;
}) {
// We need to expose this function so that some users can use it to print out the value,
// which they can use with the Explorer
const merkleInfos: Record<string, string> = {};
const phases = await Promise.all(
options.phases.map(async (phase) => {
// allowlist
let merkleRoot: string = phase.merkleRootHash || toHex("", { size: 32 });
if (phase.overrideList) {
const { shardedMerkleInfo, uri } = await processOverrideList({
overrides: phase.overrideList,
client: options.contract.client,
chain: options.contract.chain,
tokenDecimals: options.tokenDecimals,
});
merkleInfos[shardedMerkleInfo.merkleRoot] = uri;
merkleRoot = shardedMerkleInfo.merkleRoot;
}
// metadata
let metadata = "";
if (phase.metadata && typeof phase.metadata === "string") {
metadata = phase.metadata;
} else if (phase.metadata && typeof phase.metadata === "object") {
metadata = await upload({
client: options.contract.client,
files: [phase.metadata],
});
}
return {
startTimestamp: dateToSeconds(phase.startTime ?? new Date(0)),
currency: phase.currencyAddress || NATIVE_TOKEN_ADDRESS,
pricePerToken: await convertErc20Amount({
chain: options.contract.chain,
client: options.contract.client,
erc20Address: phase.currencyAddress || NATIVE_TOKEN_ADDRESS,
amount: phase.price?.toString() ?? "0",
}),
maxClaimableSupply: phase.maxClaimableSupply ?? maxUint256,
quantityLimitPerWallet: phase.maxClaimablePerWallet ?? maxUint256,
merkleRoot,
metadata,
supplyClaimed: 0n,
} as GeneratedParams["phases"][number];
}),
);
const sortedPhases = phases.sort((a, b) =>
Number(a.startTimestamp - b.startTimestamp),
);
return {
phases: sortedPhases,
merkleInfos,
};
}
Loading