1- import { maxUint256 } from "viem" ;
2- import { NATIVE_TOKEN_ADDRESS } from "../../../constants/addresses.js" ;
31import type { ThirdwebContract } from "../../../contract/contract.js" ;
4- import type { SetClaimConditionsParams as GeneratedParams } from "../../../extensions/erc1155/__generated__/IDrop1155/write/setClaimConditions.js" ;
52import { 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" ;
105import type { ClaimConditionsInput } from "./types.js" ;
116
127export 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 }
0 commit comments