@zoralabs/protocol-sdk 0.11.12 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +10 -0
- package/dist/apis/network-config.d.ts +3 -0
- package/dist/apis/network-config.d.ts.map +1 -0
- package/dist/create/contract-setup.d.ts +3 -4
- package/dist/create/contract-setup.d.ts.map +1 -1
- package/dist/create/create-client.d.ts +53 -0
- package/dist/create/create-client.d.ts.map +1 -0
- package/dist/create/types.d.ts +11 -3
- package/dist/create/types.d.ts.map +1 -1
- package/dist/fixtures/contract-setup.d.ts +2 -2
- package/dist/fixtures/contract-setup.d.ts.map +1 -1
- package/dist/fixtures/rewards-query-results.d.ts +0 -1
- package/dist/fixtures/rewards-query-results.d.ts.map +1 -1
- package/dist/fixtures/secondary.d.ts +3 -6
- package/dist/fixtures/secondary.d.ts.map +1 -1
- package/dist/index.cjs +1509 -1396
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1559 -1465
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-client.d.ts +21 -9
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +24 -22
- package/dist/mint/mint-queries.d.ts.map +1 -1
- package/dist/mint/strategies-parsing.d.ts +28 -0
- package/dist/mint/strategies-parsing.d.ts.map +1 -0
- package/dist/mint/subgraph-mint-getter.d.ts +2 -6
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/types.d.ts +25 -8
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/rewards/rewards-client.d.ts +7 -3
- package/dist/rewards/rewards-client.d.ts.map +1 -1
- package/dist/rewards/rewards-queries.d.ts +14 -11
- package/dist/rewards/rewards-queries.d.ts.map +1 -1
- package/dist/rewards/subgraph-queries.d.ts +0 -1
- package/dist/rewards/subgraph-queries.d.ts.map +1 -1
- package/dist/rewards/subgraph-rewards-getter.d.ts +2 -8
- package/dist/rewards/subgraph-rewards-getter.d.ts.map +1 -1
- package/dist/sdk.d.ts +9 -3
- package/dist/sdk.d.ts.map +1 -1
- package/dist/secondary/secondary-client.d.ts +7 -8
- package/dist/secondary/secondary-client.d.ts.map +1 -1
- package/dist/secondary/uniswap/uniswapQuote.d.ts +0 -1
- package/dist/secondary/uniswap/uniswapQuote.d.ts.map +1 -1
- package/dist/secondary/utils.d.ts +1 -2
- package/dist/secondary/utils.d.ts.map +1 -1
- package/dist/types.d.ts +6 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/apis/network-config.ts +8 -0
- package/src/apis/subgraph-getter.ts +1 -1
- package/src/comments/comments.test.ts +11 -22
- package/src/create/contract-setup.ts +3 -4
- package/src/create/{1155-create-helper.test.ts → create-client.test.ts} +52 -88
- package/src/create/{1155-create-helper.ts → create-client.ts} +129 -63
- package/src/create/types.ts +13 -3
- package/src/fixtures/contract-setup.ts +3 -3
- package/src/fixtures/rewards-query-results.ts +2 -9
- package/src/fixtures/secondary.ts +16 -10
- package/src/index.ts +34 -4
- package/src/mint/mint-client.test.ts +37 -64
- package/src/mint/mint-client.ts +36 -32
- package/src/mint/mint-queries.ts +73 -54
- package/src/mint/strategies-parsing.ts +311 -0
- package/src/mint/subgraph-mint-getter.ts +4 -304
- package/src/mint/types.ts +36 -7
- package/src/premint/premint-api-client.ts +1 -1
- package/src/premint/premint-client.ts +1 -1
- package/src/rewards/rewards-client.test.ts +318 -21
- package/src/rewards/rewards-client.ts +15 -16
- package/src/rewards/rewards-queries.ts +116 -36
- package/src/rewards/subgraph-queries.ts +0 -2
- package/src/rewards/subgraph-rewards-getter.ts +3 -13
- package/src/sdk.ts +9 -7
- package/src/secondary/secondary-client.test.ts +39 -40
- package/src/secondary/secondary-client.ts +14 -33
- package/src/secondary/uniswap/uniswapQuote.ts +3 -2
- package/src/secondary/utils.ts +2 -2
- package/src/types.ts +15 -4
- package/src/utils.ts +9 -3
- package/dist/create/1155-create-helper.d.ts +0 -29
- package/dist/create/1155-create-helper.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1932,10 +1932,12 @@ __export(src_exports, {
|
|
|
1932
1932
|
PremintAPIClient: () => PremintAPIClient,
|
|
1933
1933
|
PremintClient: () => PremintClient,
|
|
1934
1934
|
PremintConfigVersion: () => PremintConfigVersion3,
|
|
1935
|
+
SubgraphContractGetter: () => SubgraphContractGetter,
|
|
1935
1936
|
SubgraphMintGetter: () => SubgraphMintGetter,
|
|
1936
1937
|
ZORA_API_BASE: () => ZORA_API_BASE,
|
|
1937
1938
|
applyUpdateToPremint: () => applyUpdateToPremint,
|
|
1938
1939
|
buildPremintMintCall: () => buildPremintMintCall,
|
|
1940
|
+
buy1155OnSecondary: () => buy1155OnSecondary,
|
|
1939
1941
|
collectPremint: () => collectPremint,
|
|
1940
1942
|
collectPremintV2WithMintsParams: () => collectPremintV2WithMintsParams,
|
|
1941
1943
|
collectWithMintsParams: () => collectWithMintsParams,
|
|
@@ -1943,9 +1945,11 @@ __export(src_exports, {
|
|
|
1943
1945
|
convertGetPremintApiResponse: () => convertGetPremintApiResponse,
|
|
1944
1946
|
convertGetPremintOfCollectionApiResponse: () => convertGetPremintOfCollectionApiResponse,
|
|
1945
1947
|
convertPremintFromApi: () => convertPremintFromApi,
|
|
1948
|
+
create1155: () => create1155,
|
|
1946
1949
|
createAllowList: () => createAllowList,
|
|
1947
1950
|
createCollectorClient: () => createCollectorClient,
|
|
1948
1951
|
createCreatorClient: () => createCreatorClient,
|
|
1952
|
+
createNew1155Token: () => createNew1155Token,
|
|
1949
1953
|
decodeCallFailedError: () => decodeCallFailedError,
|
|
1950
1954
|
defaultAdditionalAdmins: () => defaultAdditionalAdmins,
|
|
1951
1955
|
defaultTokenConfigV1MintArguments: () => defaultTokenConfigV1MintArguments,
|
|
@@ -1954,8 +1958,8 @@ __export(src_exports, {
|
|
|
1954
1958
|
encodeCollectOnManager: () => encodeCollectOnManager,
|
|
1955
1959
|
encodePostSignatureInput: () => encodePostSignatureInput,
|
|
1956
1960
|
encodePremintForAPI: () => encodePremintForAPI,
|
|
1961
|
+
findTargetStrategyWithPrimaryOrSecondarySaleActive: () => findTargetStrategyWithPrimaryOrSecondarySaleActive,
|
|
1957
1962
|
generateTextNftMetadataFiles: () => generateTextNftMetadataFiles,
|
|
1958
|
-
getApiNetworkConfigForChain: () => getApiNetworkConfigForChain,
|
|
1959
1963
|
getContractAddressFromReceipt: () => getContractAddressFromReceipt,
|
|
1960
1964
|
getDataFromPremintReceipt: () => getDataFromPremintReceipt,
|
|
1961
1965
|
getDefaultFixedPriceMinterAddress: () => getDefaultFixedPriceMinterAddress,
|
|
@@ -1968,32 +1972,47 @@ __export(src_exports, {
|
|
|
1968
1972
|
getPremintMintFee: () => getPremintMintFee,
|
|
1969
1973
|
getPremintPricePerToken: () => getPremintPricePerToken,
|
|
1970
1974
|
getPremintedLogFromReceipt: () => getPremintedLogFromReceipt,
|
|
1975
|
+
getRewardsBalances: () => getRewardsBalances,
|
|
1976
|
+
getSecondaryInfo: () => getSecondaryInfo,
|
|
1971
1977
|
getSignature: () => getSignature,
|
|
1978
|
+
getToken: () => getToken,
|
|
1972
1979
|
getTokenIdFromCreateReceipt: () => getTokenIdFromCreateReceipt,
|
|
1980
|
+
getTokensOfContract: () => getTokensOfContract,
|
|
1981
|
+
is1155Mint: () => is1155Mint,
|
|
1973
1982
|
isAuthorizedToCreatePremint: () => isAuthorizedToCreatePremint,
|
|
1983
|
+
isOnChainMint: () => isOnChainMint,
|
|
1974
1984
|
isPremintConfigV1: () => isPremintConfigV1,
|
|
1975
1985
|
isPremintConfigV2: () => isPremintConfigV2,
|
|
1976
1986
|
isValidSignature: () => isValidSignature,
|
|
1977
1987
|
makeCreateContractAndTokenCall: () => makeCreateContractAndTokenCall,
|
|
1988
|
+
makeCreateTokenCall: () => makeCreateTokenCall,
|
|
1978
1989
|
makeMediaTokenMetadata: () => makeMediaTokenMetadata,
|
|
1979
1990
|
makeMintRewardsRecipient: () => makeMintRewardsRecipient,
|
|
1980
1991
|
makeNewPremint: () => makeNewPremint,
|
|
1992
|
+
makeOnchainPrepareMintFromCreate: () => makeOnchainPrepareMintFromCreate,
|
|
1981
1993
|
makePermitToCollectPremintOrNonPremint: () => makePermitToCollectPremintOrNonPremint,
|
|
1982
1994
|
makePermitTransferBatchAndTypeData: () => makePermitTransferBatchAndTypeData,
|
|
1983
1995
|
makePermitTransferTypeData: () => makePermitTransferTypeData,
|
|
1984
1996
|
makeTextTokenMetadata: () => makeTextTokenMetadata,
|
|
1985
1997
|
makeUrls: () => makeUrls,
|
|
1986
1998
|
migratePremintConfigToV2: () => migratePremintConfigToV2,
|
|
1999
|
+
mint: () => mint,
|
|
1987
2000
|
mintWithEthParams: () => mintWithEthParams,
|
|
1988
2001
|
mintsBalanceOfAccountParams: () => mintsBalanceOfAccountParams,
|
|
2002
|
+
new1155ContractVersion: () => new1155ContractVersion,
|
|
2003
|
+
parseAndFilterTokenQueryResult: () => parseAndFilterTokenQueryResult,
|
|
2004
|
+
prepareSetupActions: () => prepareSetupActions,
|
|
1989
2005
|
recoverCreatorFromCreatorAttribution: () => recoverCreatorFromCreatorAttribution,
|
|
1990
2006
|
recoverPremintSigner: () => recoverPremintSigner,
|
|
1991
2007
|
selectMintsToCollectWithFromQueryResult: () => selectMintsToCollectWithFromQueryResult,
|
|
2008
|
+
sell1155OnSecondary: () => sell1155OnSecondary,
|
|
1992
2009
|
sumBalances: () => sumBalances,
|
|
1993
2010
|
supportedPremintVersions: () => supportedPremintVersions,
|
|
1994
2011
|
supportsPremintVersion: () => supportsPremintVersion,
|
|
1995
2012
|
toContractCreationConfigOrAddress: () => toContractCreationConfigOrAddress,
|
|
1996
|
-
|
|
2013
|
+
toMintableReturn: () => toMintableReturn,
|
|
2014
|
+
tryRecoverPremintSigner: () => tryRecoverPremintSigner,
|
|
2015
|
+
withdrawRewards: () => withdrawRewards
|
|
1997
2016
|
});
|
|
1998
2017
|
module.exports = __toCommonJS(src_exports);
|
|
1999
2018
|
|
|
@@ -2551,1196 +2570,1210 @@ var toContractCreationConfigOrAddress = ({
|
|
|
2551
2570
|
// src/premint/premint-client.ts
|
|
2552
2571
|
var import_protocol_deployments4 = require("@zoralabs/protocol-deployments");
|
|
2553
2572
|
|
|
2554
|
-
// src/
|
|
2555
|
-
var
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
address
|
|
2560
|
-
pricePerToken
|
|
2561
|
-
saleEnd
|
|
2562
|
-
saleStart
|
|
2563
|
-
maxTokensPerAddress
|
|
2564
|
-
}
|
|
2565
|
-
erc20Minter {
|
|
2566
|
-
address
|
|
2567
|
-
pricePerToken
|
|
2568
|
-
currency
|
|
2569
|
-
saleEnd
|
|
2570
|
-
saleStart
|
|
2571
|
-
maxTokensPerAddress
|
|
2572
|
-
}
|
|
2573
|
-
presale {
|
|
2574
|
-
address
|
|
2575
|
-
presaleStart
|
|
2576
|
-
presaleEnd
|
|
2577
|
-
merkleRoot
|
|
2578
|
-
}
|
|
2579
|
-
zoraTimedMinter {
|
|
2580
|
-
address
|
|
2581
|
-
mintFee
|
|
2582
|
-
saleStart
|
|
2583
|
-
saleEnd
|
|
2584
|
-
erc20Z {
|
|
2585
|
-
id
|
|
2586
|
-
pool
|
|
2587
|
-
}
|
|
2588
|
-
secondaryActivated
|
|
2589
|
-
marketCountdown
|
|
2590
|
-
minimumMarketEth
|
|
2591
|
-
}
|
|
2592
|
-
}`;
|
|
2593
|
-
var TOKEN_FRAGMENT = `
|
|
2594
|
-
fragment Token on ZoraCreateToken {
|
|
2595
|
-
creator
|
|
2596
|
-
tokenId
|
|
2597
|
-
uri
|
|
2598
|
-
totalMinted
|
|
2599
|
-
maxSupply
|
|
2600
|
-
tokenStandard
|
|
2601
|
-
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
2602
|
-
...SaleStrategy
|
|
2603
|
-
}
|
|
2604
|
-
contract {
|
|
2605
|
-
address
|
|
2606
|
-
mintFeePerQuantity
|
|
2607
|
-
contractVersion
|
|
2608
|
-
contractURI
|
|
2609
|
-
name
|
|
2610
|
-
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
2611
|
-
...SaleStrategy
|
|
2612
|
-
}
|
|
2613
|
-
}
|
|
2614
|
-
}`;
|
|
2615
|
-
var FRAGMENTS = `
|
|
2616
|
-
${NFT_SALE_STRATEGY_FRAGMENT}
|
|
2617
|
-
${TOKEN_FRAGMENT}
|
|
2618
|
-
`;
|
|
2619
|
-
function buildNftTokenSalesQuery({
|
|
2620
|
-
tokenId,
|
|
2621
|
-
tokenAddress
|
|
2622
|
-
}) {
|
|
2623
|
-
return {
|
|
2624
|
-
query: `
|
|
2625
|
-
${FRAGMENTS}
|
|
2626
|
-
query ($id: ID!) {
|
|
2627
|
-
zoraCreateToken(id: $id) {
|
|
2628
|
-
...Token
|
|
2629
|
-
}
|
|
2630
|
-
}
|
|
2631
|
-
`,
|
|
2632
|
-
variables: {
|
|
2633
|
-
id: tokenId !== void 0 ? (
|
|
2634
|
-
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
2635
|
-
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
2636
|
-
) : `${tokenAddress.toLowerCase()}-0`
|
|
2637
|
-
},
|
|
2638
|
-
parseResponseData: (responseData) => responseData?.zoraCreateToken
|
|
2639
|
-
};
|
|
2640
|
-
}
|
|
2641
|
-
function buildContractTokensQuery({
|
|
2642
|
-
tokenAddress
|
|
2643
|
-
}) {
|
|
2644
|
-
return {
|
|
2645
|
-
query: `
|
|
2646
|
-
${FRAGMENTS}
|
|
2647
|
-
query ($contract: Bytes!) {
|
|
2648
|
-
zoraCreateTokens(
|
|
2649
|
-
where: {address: $contract}
|
|
2650
|
-
) {
|
|
2651
|
-
...Token
|
|
2652
|
-
}
|
|
2653
|
-
}
|
|
2654
|
-
`,
|
|
2655
|
-
variables: {
|
|
2656
|
-
contract: tokenAddress.toLowerCase()
|
|
2657
|
-
},
|
|
2658
|
-
parseResponseData: (responseData) => responseData?.zoraCreateTokens
|
|
2659
|
-
};
|
|
2660
|
-
}
|
|
2661
|
-
function buildPremintsOfContractQuery({
|
|
2662
|
-
tokenAddress
|
|
2573
|
+
// src/utils.ts
|
|
2574
|
+
var makeContractParameters = (args) => args;
|
|
2575
|
+
function mintRecipientOrAccount({
|
|
2576
|
+
mintRecipient,
|
|
2577
|
+
minterAccount
|
|
2663
2578
|
}) {
|
|
2664
|
-
return
|
|
2665
|
-
query: `
|
|
2666
|
-
query ($contractAddress: Bytes!) {
|
|
2667
|
-
premints(where:{contractAddress:$contractAddress}) {
|
|
2668
|
-
uid
|
|
2669
|
-
tokenId
|
|
2670
|
-
}
|
|
2671
|
-
}
|
|
2672
|
-
`,
|
|
2673
|
-
variables: {
|
|
2674
|
-
contractAddress: tokenAddress.toLowerCase()
|
|
2675
|
-
},
|
|
2676
|
-
parseResponseData: (responseData) => responseData?.premints
|
|
2677
|
-
};
|
|
2579
|
+
return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
|
|
2678
2580
|
}
|
|
2581
|
+
var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
|
|
2679
2582
|
|
|
2680
|
-
// src/apis/
|
|
2681
|
-
var
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
}
|
|
2685
|
-
async query({
|
|
2686
|
-
subgraphUrl,
|
|
2687
|
-
query,
|
|
2688
|
-
variables
|
|
2689
|
-
}) {
|
|
2690
|
-
const { retries: retries2, post: post2 } = this.httpClient;
|
|
2691
|
-
const result = await retries2(async () => {
|
|
2692
|
-
return await post2(subgraphUrl, {
|
|
2693
|
-
query,
|
|
2694
|
-
variables
|
|
2695
|
-
});
|
|
2696
|
-
});
|
|
2697
|
-
return result?.data;
|
|
2583
|
+
// src/apis/network-config.ts
|
|
2584
|
+
var getApiNetworkConfigForChain = (chainId) => {
|
|
2585
|
+
if (!networkConfigByChain[chainId]) {
|
|
2586
|
+
throw new Error(`chain id ${chainId} network not configured `);
|
|
2698
2587
|
}
|
|
2588
|
+
return networkConfigByChain[chainId];
|
|
2699
2589
|
};
|
|
2700
2590
|
|
|
2701
|
-
// src/
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2591
|
+
// src/premint/premint-client.ts
|
|
2592
|
+
var defaultTokenConfigV1MintArguments = () => ({
|
|
2593
|
+
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
2594
|
+
maxTokensPerAddress: 0n,
|
|
2595
|
+
pricePerToken: 0n,
|
|
2596
|
+
mintDuration: 0n,
|
|
2597
|
+
mintStart: 0n,
|
|
2598
|
+
royaltyMintSchedule: 0,
|
|
2599
|
+
royaltyBPS: 1e3
|
|
2600
|
+
// 10%,
|
|
2601
|
+
});
|
|
2602
|
+
var pickTokenConfigV1 = (tokenConfig) => ({
|
|
2603
|
+
maxSupply: tokenConfig.maxSupply,
|
|
2604
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
|
|
2605
|
+
pricePerToken: tokenConfig.pricePerToken,
|
|
2606
|
+
mintDuration: tokenConfig.mintDuration,
|
|
2607
|
+
mintStart: tokenConfig.mintStart,
|
|
2608
|
+
royaltyBPS: tokenConfig.royaltyBPS,
|
|
2609
|
+
tokenURI: tokenConfig.tokenURI,
|
|
2610
|
+
royaltyRecipient: tokenConfig.payoutRecipient
|
|
2611
|
+
});
|
|
2612
|
+
var pickTokenConfigV2 = (tokenConfig) => ({
|
|
2613
|
+
maxSupply: tokenConfig.maxSupply,
|
|
2614
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
|
|
2615
|
+
pricePerToken: tokenConfig.pricePerToken,
|
|
2616
|
+
mintDuration: tokenConfig.mintDuration,
|
|
2617
|
+
mintStart: tokenConfig.mintStart,
|
|
2618
|
+
royaltyBPS: tokenConfig.royaltyBPS,
|
|
2619
|
+
tokenURI: tokenConfig.tokenURI,
|
|
2620
|
+
payoutRecipient: tokenConfig.payoutRecipient,
|
|
2621
|
+
createReferral: tokenConfig.createReferral || import_viem4.zeroAddress
|
|
2622
|
+
});
|
|
2623
|
+
var tokenConfigV1WithDefault = (tokenConfig, fixedPriceMinter) => ({
|
|
2624
|
+
...pickTokenConfigV1(tokenConfig),
|
|
2625
|
+
...defaultTokenConfigV1MintArguments(),
|
|
2626
|
+
fixedPriceMinter
|
|
2627
|
+
});
|
|
2628
|
+
var tokenConfigV2WithDefault = (tokenConfig, fixedPriceMinter) => ({
|
|
2629
|
+
...pickTokenConfigV2(tokenConfig),
|
|
2630
|
+
...defaultTokenConfigV2MintArguments(),
|
|
2631
|
+
fixedPriceMinter
|
|
2632
|
+
});
|
|
2633
|
+
var defaultTokenConfigV2MintArguments = () => ({
|
|
2634
|
+
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
2635
|
+
maxTokensPerAddress: 0n,
|
|
2636
|
+
pricePerToken: 0n,
|
|
2637
|
+
mintDuration: 0n,
|
|
2638
|
+
mintStart: 0n,
|
|
2639
|
+
royaltyBPS: 1e3
|
|
2640
|
+
// 10%,
|
|
2641
|
+
});
|
|
2642
|
+
var makeTokenConfigWithDefaults = ({
|
|
2643
|
+
chainId,
|
|
2644
|
+
tokenCreationConfig,
|
|
2645
|
+
supportedPremintVersions: supportedPremintVersions2
|
|
2713
2646
|
}) => {
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
if (atTry <= maxTries) {
|
|
2719
|
-
await wait(atTry * linearBackoffMS);
|
|
2720
|
-
return await retryInternal({
|
|
2721
|
-
tryFn,
|
|
2722
|
-
maxTries,
|
|
2723
|
-
atTry: atTry + 1,
|
|
2724
|
-
linearBackoffMS,
|
|
2725
|
-
shouldRetryOnError
|
|
2726
|
-
});
|
|
2727
|
-
}
|
|
2647
|
+
const fixedPriceMinter = getDefaultFixedPriceMinterAddress(chainId);
|
|
2648
|
+
if (!supportedPremintVersions2.includes(import_protocol_deployments4.PremintConfigVersion.V2)) {
|
|
2649
|
+
if (tokenCreationConfig.createReferral) {
|
|
2650
|
+
throw new Error("Contract does not support create referral");
|
|
2728
2651
|
}
|
|
2729
|
-
|
|
2652
|
+
return {
|
|
2653
|
+
premintConfigVersion: import_protocol_deployments4.PremintConfigVersion.V1,
|
|
2654
|
+
tokenConfig: tokenConfigV1WithDefault(
|
|
2655
|
+
tokenCreationConfig,
|
|
2656
|
+
fixedPriceMinter
|
|
2657
|
+
)
|
|
2658
|
+
};
|
|
2730
2659
|
}
|
|
2660
|
+
return {
|
|
2661
|
+
premintConfigVersion: import_protocol_deployments4.PremintConfigVersion.V2,
|
|
2662
|
+
tokenConfig: tokenConfigV2WithDefault(
|
|
2663
|
+
tokenCreationConfig,
|
|
2664
|
+
fixedPriceMinter
|
|
2665
|
+
)
|
|
2666
|
+
};
|
|
2731
2667
|
};
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
...params,
|
|
2735
|
-
atTry: 1
|
|
2736
|
-
});
|
|
2737
|
-
};
|
|
2738
|
-
|
|
2739
|
-
// src/apis/http-api-base.ts
|
|
2740
|
-
var BadResponseError = class extends Error {
|
|
2741
|
-
constructor(message, status, json) {
|
|
2742
|
-
super(message);
|
|
2743
|
-
this.name = "BadResponseError";
|
|
2744
|
-
this.status = status;
|
|
2745
|
-
this.json = json;
|
|
2746
|
-
}
|
|
2747
|
-
};
|
|
2748
|
-
var get = async (url) => {
|
|
2749
|
-
const response = await fetch(url, { method: "GET" });
|
|
2750
|
-
if (response.status !== 200) {
|
|
2751
|
-
let json;
|
|
2668
|
+
function getPremintedLogFromReceipt(receipt) {
|
|
2669
|
+
for (const data of receipt.logs) {
|
|
2752
2670
|
try {
|
|
2753
|
-
|
|
2754
|
-
|
|
2671
|
+
const decodedLog = (0, import_viem4.decodeEventLog)({
|
|
2672
|
+
abi: import_protocol_deployments3.zoraCreator1155PremintExecutorImplABI,
|
|
2673
|
+
eventName: "PremintedV2",
|
|
2674
|
+
...data
|
|
2675
|
+
});
|
|
2676
|
+
if (decodedLog.eventName === "PremintedV2") {
|
|
2677
|
+
return decodedLog.args;
|
|
2678
|
+
}
|
|
2679
|
+
} catch (err) {
|
|
2755
2680
|
}
|
|
2756
|
-
throw new BadResponseError(
|
|
2757
|
-
`Invalid response, status ${response.status}`,
|
|
2758
|
-
response.status,
|
|
2759
|
-
json
|
|
2760
|
-
);
|
|
2761
2681
|
}
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
"content-type": "application/json",
|
|
2773
|
-
accept: "application/json"
|
|
2774
|
-
},
|
|
2775
|
-
body: JSON.stringify(data),
|
|
2776
|
-
signal
|
|
2777
|
-
});
|
|
2778
|
-
clearTimeout(timeoutId);
|
|
2779
|
-
if (response.status !== 200) {
|
|
2780
|
-
let json;
|
|
2781
|
-
try {
|
|
2782
|
-
json = await response.json();
|
|
2783
|
-
} catch (e) {
|
|
2784
|
-
}
|
|
2785
|
-
throw new BadResponseError(
|
|
2786
|
-
`Bad response: ${response.status}`,
|
|
2787
|
-
response.status,
|
|
2788
|
-
json
|
|
2789
|
-
);
|
|
2682
|
+
}
|
|
2683
|
+
var PremintClient = class {
|
|
2684
|
+
constructor({
|
|
2685
|
+
chainId,
|
|
2686
|
+
publicClient,
|
|
2687
|
+
premintApi
|
|
2688
|
+
}) {
|
|
2689
|
+
this.chainId = chainId;
|
|
2690
|
+
this.apiClient = premintApi;
|
|
2691
|
+
this.publicClient = publicClient;
|
|
2790
2692
|
}
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
var defaultShouldRetry = (err) => {
|
|
2794
|
-
return err instanceof BadResponseError && err.status >= 500;
|
|
2795
|
-
};
|
|
2796
|
-
var retries = async (tryFn, maxTries = 3, linearBackoffMS = 200, shouldRetry = defaultShouldRetry) => {
|
|
2797
|
-
return retriesGeneric({
|
|
2798
|
-
tryFn,
|
|
2799
|
-
maxTries,
|
|
2800
|
-
linearBackoffMS,
|
|
2801
|
-
shouldRetryOnError: shouldRetry
|
|
2802
|
-
});
|
|
2803
|
-
};
|
|
2804
|
-
var httpClient = {
|
|
2805
|
-
get,
|
|
2806
|
-
post,
|
|
2807
|
-
retries
|
|
2808
|
-
};
|
|
2809
|
-
|
|
2810
|
-
// src/apis/subgraph-getter.ts
|
|
2811
|
-
var SubgraphGetter = class {
|
|
2812
|
-
constructor(chainId, subgraphQuerier) {
|
|
2813
|
-
this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
|
|
2814
|
-
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
2693
|
+
getDataFromPremintReceipt(receipt, blockExplorerUrl) {
|
|
2694
|
+
return getDataFromPremintReceipt(receipt, this.chainId, blockExplorerUrl);
|
|
2815
2695
|
}
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2696
|
+
/**
|
|
2697
|
+
* Prepares data for updating a premint
|
|
2698
|
+
*
|
|
2699
|
+
* @param parameters - Parameters for updating the premint {@link UpdatePremintParams}
|
|
2700
|
+
* @returns A PremintReturn. {@link PremintReturn}
|
|
2701
|
+
*/
|
|
2702
|
+
async updatePremint(args) {
|
|
2703
|
+
return await updatePremint({
|
|
2704
|
+
...args,
|
|
2705
|
+
apiClient: this.apiClient,
|
|
2706
|
+
publicClient: this.publicClient,
|
|
2707
|
+
chainId: this.chainId
|
|
2708
|
+
});
|
|
2709
|
+
}
|
|
2710
|
+
/**
|
|
2711
|
+
* Prepares data for deleting a premint
|
|
2712
|
+
*
|
|
2713
|
+
* @param parameters - Parameters for deleting the premint {@link DeletePremintParams}
|
|
2714
|
+
* @returns A PremintReturn. {@link PremintReturn}
|
|
2715
|
+
*/
|
|
2716
|
+
async deletePremint(params) {
|
|
2717
|
+
return deletePremint({
|
|
2718
|
+
...params,
|
|
2719
|
+
apiClient: this.apiClient,
|
|
2720
|
+
publicClient: this.publicClient,
|
|
2721
|
+
chainId: this.chainId
|
|
2722
|
+
});
|
|
2723
|
+
}
|
|
2724
|
+
/**
|
|
2725
|
+
* Prepares data for creating a premint
|
|
2726
|
+
*
|
|
2727
|
+
* @param parameters - Parameters for creating the premint {@link CreatePremintParameters}
|
|
2728
|
+
* @returns A PremintReturn. {@link PremintReturn}
|
|
2729
|
+
*/
|
|
2730
|
+
async createPremint(parameters) {
|
|
2731
|
+
return createPremint({
|
|
2732
|
+
...parameters,
|
|
2733
|
+
publicClient: this.publicClient,
|
|
2734
|
+
apiClient: this.apiClient,
|
|
2735
|
+
chainId: this.chainId
|
|
2736
|
+
});
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Fetches given premint data from the ZORA API.
|
|
2740
|
+
*
|
|
2741
|
+
* @param address Address for the premint contract
|
|
2742
|
+
* @param uid UID for the desired premint
|
|
2743
|
+
* @returns PremintSignatureGetResponse of premint data from the API
|
|
2744
|
+
*/
|
|
2745
|
+
async getPremint({ address, uid }) {
|
|
2746
|
+
return await this.apiClient.get({
|
|
2747
|
+
collectionAddress: address,
|
|
2748
|
+
uid
|
|
2749
|
+
});
|
|
2750
|
+
}
|
|
2751
|
+
/**
|
|
2752
|
+
* Gets the deterministic contract address for a premint collection
|
|
2753
|
+
* @param collection Collection to get the address for
|
|
2754
|
+
* @returns deterministic contract address
|
|
2755
|
+
*/
|
|
2756
|
+
async getCollectionAddress(collection) {
|
|
2757
|
+
return await getPremintCollectionAddress({
|
|
2758
|
+
contract: collection,
|
|
2759
|
+
publicClient: this.publicClient
|
|
2760
|
+
});
|
|
2761
|
+
}
|
|
2762
|
+
async getMintCosts({
|
|
2763
|
+
tokenContract,
|
|
2764
|
+
quantityToMint,
|
|
2765
|
+
pricePerToken
|
|
2820
2766
|
}) {
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2767
|
+
return await getPremintMintCosts({
|
|
2768
|
+
publicClient: this.publicClient,
|
|
2769
|
+
quantityToMint,
|
|
2770
|
+
tokenContract,
|
|
2771
|
+
tokenPrice: pricePerToken
|
|
2825
2772
|
});
|
|
2826
|
-
return parseResponseData(responseData);
|
|
2827
2773
|
}
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2774
|
+
/**
|
|
2775
|
+
* Prepares the parameters to collect a premint; it brings the contract and token onchain, then collects
|
|
2776
|
+
* tokens on that contract for the mint recipient.
|
|
2777
|
+
*
|
|
2778
|
+
* @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
|
|
2779
|
+
* @returns receipt, log, zoraURL
|
|
2780
|
+
*/
|
|
2781
|
+
async makeMintParameters({
|
|
2782
|
+
minterAccount,
|
|
2783
|
+
tokenContract,
|
|
2784
|
+
uid,
|
|
2785
|
+
mintArguments,
|
|
2786
|
+
firstMinter
|
|
2787
|
+
}) {
|
|
2788
|
+
return await collectPremint({
|
|
2789
|
+
uid,
|
|
2790
|
+
tokenContract,
|
|
2791
|
+
minterAccount,
|
|
2792
|
+
quantityToMint: mintArguments?.quantityToMint || 1n,
|
|
2793
|
+
mintComment: mintArguments?.mintComment,
|
|
2794
|
+
mintReferral: mintArguments?.mintReferral,
|
|
2795
|
+
mintRecipient: mintArguments?.mintRecipient,
|
|
2796
|
+
firstMinter,
|
|
2797
|
+
premintGetter: this.apiClient,
|
|
2798
|
+
publicClient: this.publicClient
|
|
2799
|
+
});
|
|
2834
2800
|
}
|
|
2835
|
-
return networkConfigByChain[chainId];
|
|
2836
2801
|
};
|
|
2837
|
-
function
|
|
2838
|
-
const
|
|
2839
|
-
return {
|
|
2840
|
-
salesStrategy: {
|
|
2841
|
-
saleType: "fixedPrice",
|
|
2842
|
-
...fixedPrice,
|
|
2843
|
-
maxTokensPerAddress: BigInt(fixedPrice.maxTokensPerAddress),
|
|
2844
|
-
pricePerToken: BigInt(fixedPrice.pricePerToken),
|
|
2845
|
-
mintFeePerQuantity: contractMintFee
|
|
2846
|
-
},
|
|
2847
|
-
saleEnd,
|
|
2848
|
-
saleActive: BigInt(fixedPrice.saleStart) <= blockTime && BigInt(saleEnd) > blockTime
|
|
2849
|
-
};
|
|
2850
|
-
}
|
|
2851
|
-
function parseERC20SalesConfig(erc20Minter, blockTime) {
|
|
2852
|
-
const saleEnd = BigInt(erc20Minter.saleEnd);
|
|
2853
|
-
return {
|
|
2854
|
-
salesStrategy: {
|
|
2855
|
-
saleType: "erc20",
|
|
2856
|
-
...erc20Minter,
|
|
2857
|
-
maxTokensPerAddress: BigInt(erc20Minter.maxTokensPerAddress),
|
|
2858
|
-
pricePerToken: BigInt(erc20Minter.pricePerToken),
|
|
2859
|
-
mintFeePerQuantity: 0n
|
|
2860
|
-
},
|
|
2861
|
-
saleEnd,
|
|
2862
|
-
saleActive: BigInt(erc20Minter.saleStart) <= blockTime && saleEnd > blockTime
|
|
2863
|
-
};
|
|
2864
|
-
}
|
|
2865
|
-
function parsePresaleSalesConfig(presale, contractMintFee, blockTime) {
|
|
2866
|
-
const saleEnd = BigInt(presale.presaleEnd);
|
|
2802
|
+
function getDataFromPremintReceipt(receipt, chainId, blockExplorerUrl) {
|
|
2803
|
+
const premintedLog = getPremintedLogFromReceipt(receipt);
|
|
2867
2804
|
return {
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
saleActive: BigInt(presale.presaleStart) <= blockTime && saleEnd > blockTime
|
|
2805
|
+
tokenId: premintedLog?.tokenId,
|
|
2806
|
+
collectionAddres: premintedLog?.contractAddress,
|
|
2807
|
+
premintedLog,
|
|
2808
|
+
urls: makeUrls({
|
|
2809
|
+
address: premintedLog?.contractAddress,
|
|
2810
|
+
tokenId: premintedLog?.tokenId,
|
|
2811
|
+
chainId,
|
|
2812
|
+
blockExplorerUrl
|
|
2813
|
+
})
|
|
2878
2814
|
};
|
|
2879
2815
|
}
|
|
2880
|
-
function
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
mintFee: BigInt(zoraTimedMinter.mintFee),
|
|
2888
|
-
saleStart: zoraTimedMinter.saleStart,
|
|
2889
|
-
saleEnd: zoraTimedMinter.saleEnd,
|
|
2890
|
-
erc20Z: zoraTimedMinter.erc20Z.id,
|
|
2891
|
-
pool: zoraTimedMinter.erc20Z.pool,
|
|
2892
|
-
secondaryActivated: zoraTimedMinter.secondaryActivated,
|
|
2893
|
-
mintFeePerQuantity: BigInt(zoraTimedMinter.mintFee),
|
|
2894
|
-
marketCountdown: zoraTimedMinter.marketCountdown ? BigInt(zoraTimedMinter.marketCountdown) : void 0,
|
|
2895
|
-
minimumMarketEth: zoraTimedMinter.minimumMarketEth ? BigInt(zoraTimedMinter.minimumMarketEth) : void 0
|
|
2896
|
-
},
|
|
2897
|
-
saleEnd: hasSaleEnd ? saleEnd : void 0,
|
|
2898
|
-
secondaryMarketActive: zoraTimedMinter.secondaryActivated,
|
|
2899
|
-
saleActive: BigInt(zoraTimedMinter.saleStart) <= blockTime && (hasSaleEnd ? saleEnd > blockTime : true)
|
|
2900
|
-
};
|
|
2901
|
-
}
|
|
2902
|
-
function parseSalesConfig(targetStrategy, contractMintFee, blockTime) {
|
|
2903
|
-
switch (targetStrategy.type) {
|
|
2904
|
-
case "FIXED_PRICE":
|
|
2905
|
-
return parseFixedPriceSalesConfig(
|
|
2906
|
-
targetStrategy.fixedPrice,
|
|
2907
|
-
contractMintFee,
|
|
2908
|
-
blockTime
|
|
2909
|
-
);
|
|
2910
|
-
case "ERC_20_MINTER":
|
|
2911
|
-
return parseERC20SalesConfig(targetStrategy.erc20Minter, blockTime);
|
|
2912
|
-
case "PRESALE":
|
|
2913
|
-
return parsePresaleSalesConfig(
|
|
2914
|
-
targetStrategy.presale,
|
|
2915
|
-
contractMintFee,
|
|
2916
|
-
blockTime
|
|
2917
|
-
);
|
|
2918
|
-
case "ZORA_TIMED":
|
|
2919
|
-
return parseZoraTimedSalesConfig(
|
|
2920
|
-
targetStrategy.zoraTimedMinter,
|
|
2921
|
-
blockTime
|
|
2922
|
-
);
|
|
2923
|
-
default:
|
|
2924
|
-
throw new Error("Unknown saleType");
|
|
2925
|
-
}
|
|
2926
|
-
}
|
|
2927
|
-
function getTargetStrategy({
|
|
2928
|
-
tokenId,
|
|
2929
|
-
preferredSaleType,
|
|
2930
|
-
token,
|
|
2931
|
-
blockTime,
|
|
2932
|
-
contractMintFee
|
|
2816
|
+
function makePremintReturn({
|
|
2817
|
+
premintConfig,
|
|
2818
|
+
premintConfigVersion,
|
|
2819
|
+
publicClient,
|
|
2820
|
+
apiClient,
|
|
2821
|
+
chainId,
|
|
2822
|
+
...collectionAndAddress
|
|
2933
2823
|
}) {
|
|
2934
|
-
const
|
|
2935
|
-
const
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
);
|
|
2941
|
-
const
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
);
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2824
|
+
const { collection, collectionAddress } = collectionAndAddress;
|
|
2825
|
+
const typedDataDefinition = (0, import_protocol_deployments4.premintTypedDataDefinition)({
|
|
2826
|
+
verifyingContract: collectionAddress,
|
|
2827
|
+
premintConfig,
|
|
2828
|
+
premintConfigVersion,
|
|
2829
|
+
chainId
|
|
2830
|
+
});
|
|
2831
|
+
const signAndSubmit = async ({
|
|
2832
|
+
walletClient,
|
|
2833
|
+
account,
|
|
2834
|
+
checkSignature
|
|
2835
|
+
}) => {
|
|
2836
|
+
const { signature, signerAccount } = await signPremint({
|
|
2837
|
+
account,
|
|
2838
|
+
walletClient,
|
|
2839
|
+
typedDataDefinition
|
|
2840
|
+
});
|
|
2841
|
+
await submit({
|
|
2842
|
+
signature,
|
|
2843
|
+
checkSignature,
|
|
2844
|
+
account: signerAccount
|
|
2845
|
+
});
|
|
2846
|
+
return {
|
|
2847
|
+
signature,
|
|
2848
|
+
signerAccount
|
|
2849
|
+
};
|
|
2850
|
+
};
|
|
2851
|
+
const submit = async ({
|
|
2852
|
+
signature,
|
|
2853
|
+
checkSignature,
|
|
2854
|
+
account
|
|
2855
|
+
}) => {
|
|
2856
|
+
if (checkSignature) {
|
|
2857
|
+
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
2858
|
+
collectionAddress,
|
|
2859
|
+
additionalAdmins: collection?.additionalAdmins,
|
|
2860
|
+
contractAdmin: collection?.contractAdmin,
|
|
2861
|
+
publicClient,
|
|
2862
|
+
signer: account
|
|
2863
|
+
});
|
|
2864
|
+
if (!isAuthorized) {
|
|
2865
|
+
throw new Error("Not authorized to create premint");
|
|
2866
|
+
}
|
|
2958
2867
|
}
|
|
2959
|
-
|
|
2960
|
-
|
|
2868
|
+
await apiClient.postSignature({
|
|
2869
|
+
...toContractCreationConfigOrAddress(collectionAndAddress),
|
|
2870
|
+
signature,
|
|
2871
|
+
premintConfig,
|
|
2872
|
+
premintConfigVersion
|
|
2873
|
+
});
|
|
2874
|
+
};
|
|
2875
|
+
const urls = makeUrls({
|
|
2876
|
+
chainId,
|
|
2877
|
+
address: collectionAddress,
|
|
2878
|
+
uid: premintConfig.uid
|
|
2879
|
+
});
|
|
2880
|
+
return {
|
|
2881
|
+
premintConfig,
|
|
2882
|
+
premintConfigVersion,
|
|
2883
|
+
typedDataDefinition,
|
|
2884
|
+
collectionAddress,
|
|
2885
|
+
signAndSubmit,
|
|
2886
|
+
submit,
|
|
2887
|
+
urls
|
|
2888
|
+
};
|
|
2961
2889
|
}
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
blockTime
|
|
2970
|
-
}) => {
|
|
2971
|
-
const token = await this.querySubgraphWithRetries(
|
|
2972
|
-
buildNftTokenSalesQuery({
|
|
2973
|
-
tokenId,
|
|
2974
|
-
tokenAddress
|
|
2975
|
-
})
|
|
2976
|
-
);
|
|
2977
|
-
if (!token) {
|
|
2978
|
-
throw new Error("Cannot find token");
|
|
2979
|
-
}
|
|
2980
|
-
const defaultMintFee = await this.getContractMintFee(token.contract);
|
|
2981
|
-
return parseTokenQueryResult({
|
|
2982
|
-
token,
|
|
2983
|
-
defaultMintFee,
|
|
2984
|
-
tokenId,
|
|
2985
|
-
preferredSaleType: saleType,
|
|
2986
|
-
blockTime
|
|
2987
|
-
});
|
|
2988
|
-
};
|
|
2989
|
-
}
|
|
2990
|
-
async getContractMintFee(contract) {
|
|
2991
|
-
return BigInt(contract.mintFeePerQuantity);
|
|
2992
|
-
}
|
|
2993
|
-
async getContractMintable({
|
|
2994
|
-
tokenAddress,
|
|
2995
|
-
preferredSaleType,
|
|
2996
|
-
blockTime
|
|
2997
|
-
}) {
|
|
2998
|
-
const tokens = await this.querySubgraphWithRetries(
|
|
2999
|
-
buildContractTokensQuery({
|
|
3000
|
-
tokenAddress
|
|
3001
|
-
})
|
|
3002
|
-
);
|
|
3003
|
-
if (!tokens || tokens.length === 0)
|
|
3004
|
-
return [];
|
|
3005
|
-
const defaultMintFee = await this.getContractMintFee(tokens[0].contract);
|
|
3006
|
-
return tokens.filter((x) => x.tokenId !== "0").map(
|
|
3007
|
-
(token) => parseTokenQueryResult({
|
|
3008
|
-
token,
|
|
3009
|
-
tokenId: token.tokenId,
|
|
3010
|
-
preferredSaleType,
|
|
3011
|
-
defaultMintFee,
|
|
3012
|
-
blockTime
|
|
3013
|
-
})
|
|
3014
|
-
);
|
|
2890
|
+
async function signPremint({
|
|
2891
|
+
account,
|
|
2892
|
+
walletClient,
|
|
2893
|
+
typedDataDefinition
|
|
2894
|
+
}) {
|
|
2895
|
+
if (!account) {
|
|
2896
|
+
account = walletClient.account;
|
|
3015
2897
|
}
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
}) {
|
|
3019
|
-
const premints = await this.querySubgraphWithRetries(
|
|
3020
|
-
buildPremintsOfContractQuery({
|
|
3021
|
-
tokenAddress
|
|
3022
|
-
})
|
|
3023
|
-
);
|
|
3024
|
-
return premints?.map((premint) => ({
|
|
3025
|
-
tokenId: BigInt(premint.tokenId),
|
|
3026
|
-
uid: +premint.uid
|
|
3027
|
-
})) || [];
|
|
2898
|
+
if (!account) {
|
|
2899
|
+
throw new Error("No account provided");
|
|
3028
2900
|
}
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
tokenId,
|
|
3033
|
-
preferredSaleType,
|
|
3034
|
-
defaultMintFee,
|
|
3035
|
-
blockTime
|
|
3036
|
-
}) {
|
|
3037
|
-
const targetStrategy = getTargetStrategy({
|
|
3038
|
-
tokenId,
|
|
3039
|
-
preferredSaleType,
|
|
3040
|
-
token,
|
|
3041
|
-
blockTime,
|
|
3042
|
-
contractMintFee: defaultMintFee
|
|
2901
|
+
const signature = await walletClient.signTypedData({
|
|
2902
|
+
account,
|
|
2903
|
+
...typedDataDefinition
|
|
3043
2904
|
});
|
|
3044
|
-
return
|
|
2905
|
+
return {
|
|
2906
|
+
signature,
|
|
2907
|
+
signerAccount: account
|
|
2908
|
+
};
|
|
3045
2909
|
}
|
|
3046
|
-
function
|
|
3047
|
-
token,
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
2910
|
+
async function createPremint({
|
|
2911
|
+
token: tokenCreationConfig,
|
|
2912
|
+
uid,
|
|
2913
|
+
publicClient,
|
|
2914
|
+
apiClient,
|
|
2915
|
+
chainId,
|
|
2916
|
+
...collectionOrAddress
|
|
3052
2917
|
}) {
|
|
3053
|
-
const
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
2918
|
+
const {
|
|
2919
|
+
premintConfig,
|
|
2920
|
+
premintConfigVersion,
|
|
2921
|
+
collectionAddress: collectionAddressToUse
|
|
2922
|
+
} = await prepareCreatePremintConfig({
|
|
2923
|
+
...collectionOrAddress,
|
|
2924
|
+
tokenCreationConfig,
|
|
2925
|
+
uid,
|
|
2926
|
+
publicClient,
|
|
2927
|
+
apiClient,
|
|
2928
|
+
chainId
|
|
3059
2929
|
});
|
|
3060
|
-
|
|
3061
|
-
|
|
2930
|
+
return makePremintReturn({
|
|
2931
|
+
premintConfig,
|
|
2932
|
+
premintConfigVersion,
|
|
2933
|
+
collectionAddress: collectionAddressToUse,
|
|
2934
|
+
collection: collectionOrAddress.contract,
|
|
2935
|
+
publicClient,
|
|
2936
|
+
apiClient,
|
|
2937
|
+
chainId
|
|
3062
2938
|
});
|
|
3063
|
-
return {
|
|
3064
|
-
salesConfigAndTokenInfo: {
|
|
3065
|
-
...tokenInfo,
|
|
3066
|
-
salesConfig: salesStrategyAndMintInfo?.salesStrategy
|
|
3067
|
-
},
|
|
3068
|
-
primaryMintActive: salesStrategyAndMintInfo?.saleActive ?? false,
|
|
3069
|
-
primaryMintEnd: salesStrategyAndMintInfo?.saleEnd,
|
|
3070
|
-
secondaryMarketActive: salesStrategyAndMintInfo?.secondaryMarketActive ?? false
|
|
3071
|
-
};
|
|
3072
2939
|
}
|
|
3073
|
-
function
|
|
3074
|
-
|
|
2940
|
+
async function prepareCreatePremintConfig({
|
|
2941
|
+
tokenCreationConfig,
|
|
2942
|
+
uid,
|
|
2943
|
+
publicClient,
|
|
2944
|
+
apiClient,
|
|
2945
|
+
chainId,
|
|
2946
|
+
...collectionOrAddress
|
|
3075
2947
|
}) {
|
|
2948
|
+
const newContractAddress = await getPremintCollectionAddress({
|
|
2949
|
+
publicClient,
|
|
2950
|
+
...collectionOrAddress
|
|
2951
|
+
});
|
|
2952
|
+
let uidToUse = uid;
|
|
2953
|
+
if (typeof uidToUse !== "number") {
|
|
2954
|
+
uidToUse = await apiClient.getNextUID(newContractAddress);
|
|
2955
|
+
}
|
|
2956
|
+
const supportedVersions = await supportedPremintVersions({
|
|
2957
|
+
tokenContract: newContractAddress,
|
|
2958
|
+
publicClient
|
|
2959
|
+
});
|
|
2960
|
+
const tokenConfigAndVersion = makeTokenConfigWithDefaults({
|
|
2961
|
+
tokenCreationConfig,
|
|
2962
|
+
chainId,
|
|
2963
|
+
supportedPremintVersions: supportedVersions
|
|
2964
|
+
});
|
|
2965
|
+
const premintConfig = makeNewPremint({
|
|
2966
|
+
...tokenConfigAndVersion,
|
|
2967
|
+
uid: uidToUse
|
|
2968
|
+
});
|
|
2969
|
+
const premintConfigAndVersion = {
|
|
2970
|
+
premintConfig,
|
|
2971
|
+
premintConfigVersion: tokenConfigAndVersion.premintConfigVersion
|
|
2972
|
+
};
|
|
3076
2973
|
return {
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
name: token.contract.name,
|
|
3080
|
-
URI: token.contract.contractURI
|
|
3081
|
-
},
|
|
3082
|
-
tokenURI: token.uri,
|
|
3083
|
-
tokenId: token.tokenId ? BigInt(token.tokenId) : void 0,
|
|
3084
|
-
mintType: token.tokenStandard === "ERC721" ? "721" : "1155",
|
|
3085
|
-
creator: token.creator,
|
|
3086
|
-
totalMinted: BigInt(token.totalMinted),
|
|
3087
|
-
maxSupply: BigInt(token.maxSupply),
|
|
3088
|
-
contractVersion: token.contract.contractVersion
|
|
2974
|
+
...premintConfigAndVersion,
|
|
2975
|
+
collectionAddress: newContractAddress
|
|
3089
2976
|
};
|
|
3090
2977
|
}
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
2978
|
+
async function updatePremint({
|
|
2979
|
+
uid,
|
|
2980
|
+
collection,
|
|
2981
|
+
tokenConfigUpdates,
|
|
2982
|
+
apiClient,
|
|
2983
|
+
publicClient,
|
|
2984
|
+
chainId
|
|
2985
|
+
}) {
|
|
2986
|
+
const {
|
|
2987
|
+
premint: { premintConfig, premintConfigVersion },
|
|
2988
|
+
collection: collectionCreationConfig
|
|
2989
|
+
} = await apiClient.get({
|
|
2990
|
+
collectionAddress: collection,
|
|
2991
|
+
uid
|
|
2992
|
+
});
|
|
2993
|
+
const updatedPremint = applyUpdateToPremint({
|
|
2994
|
+
uid: premintConfig.uid,
|
|
2995
|
+
version: premintConfig.version,
|
|
2996
|
+
tokenConfig: premintConfig.tokenConfig,
|
|
2997
|
+
tokenConfigUpdates
|
|
2998
|
+
});
|
|
2999
|
+
return makePremintReturn({
|
|
3000
|
+
premintConfig: updatedPremint,
|
|
3001
|
+
premintConfigVersion,
|
|
3002
|
+
collectionAddress: collection,
|
|
3003
|
+
collection: collectionCreationConfig,
|
|
3004
|
+
publicClient,
|
|
3005
|
+
apiClient,
|
|
3006
|
+
chainId
|
|
3007
|
+
});
|
|
3008
|
+
}
|
|
3009
|
+
async function deletePremint({
|
|
3010
|
+
uid,
|
|
3011
|
+
collection,
|
|
3012
|
+
publicClient,
|
|
3013
|
+
apiClient,
|
|
3014
|
+
chainId
|
|
3015
|
+
}) {
|
|
3016
|
+
const {
|
|
3017
|
+
premint: { premintConfig, premintConfigVersion },
|
|
3018
|
+
collection: collectionCreationConfig,
|
|
3019
|
+
collectionAddress
|
|
3020
|
+
} = await apiClient.get({
|
|
3021
|
+
collectionAddress: collection,
|
|
3022
|
+
uid
|
|
3023
|
+
});
|
|
3024
|
+
const deletedPremint = {
|
|
3025
|
+
...premintConfig,
|
|
3026
|
+
version: premintConfig.version + 1,
|
|
3027
|
+
deleted: true
|
|
3028
|
+
};
|
|
3029
|
+
return makePremintReturn({
|
|
3030
|
+
premintConfig: deletedPremint,
|
|
3031
|
+
premintConfigVersion,
|
|
3032
|
+
collectionAddress,
|
|
3033
|
+
collection: collectionCreationConfig,
|
|
3034
|
+
publicClient,
|
|
3035
|
+
apiClient,
|
|
3036
|
+
chainId
|
|
3037
|
+
});
|
|
3038
|
+
}
|
|
3039
|
+
async function collectPremint({
|
|
3040
|
+
uid,
|
|
3041
|
+
tokenContract,
|
|
3042
|
+
minterAccount,
|
|
3043
|
+
quantityToMint,
|
|
3044
|
+
mintComment = "",
|
|
3045
|
+
mintReferral,
|
|
3095
3046
|
mintRecipient,
|
|
3096
|
-
|
|
3047
|
+
firstMinter,
|
|
3048
|
+
premintGetter,
|
|
3049
|
+
publicClient
|
|
3097
3050
|
}) {
|
|
3098
|
-
|
|
3051
|
+
if (typeof quantityToMint !== "undefined" && quantityToMint < 1) {
|
|
3052
|
+
throw new Error("Quantity to mint cannot be below 1");
|
|
3053
|
+
}
|
|
3054
|
+
const premint = await premintGetter.get({
|
|
3055
|
+
collectionAddress: tokenContract,
|
|
3056
|
+
uid
|
|
3057
|
+
});
|
|
3058
|
+
const mintFee = await getPremintMintFee({
|
|
3059
|
+
tokenContract,
|
|
3060
|
+
publicClient
|
|
3061
|
+
});
|
|
3062
|
+
return buildPremintMintCall({
|
|
3063
|
+
mintArguments: {
|
|
3064
|
+
minterAccount,
|
|
3065
|
+
quantityToMint,
|
|
3066
|
+
firstMinter,
|
|
3067
|
+
mintComment,
|
|
3068
|
+
mintRecipient,
|
|
3069
|
+
mintReferral
|
|
3070
|
+
},
|
|
3071
|
+
mintFee,
|
|
3072
|
+
premint
|
|
3073
|
+
});
|
|
3099
3074
|
}
|
|
3100
|
-
var
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
// 10%,
|
|
3112
|
-
});
|
|
3113
|
-
var pickTokenConfigV1 = (tokenConfig) => ({
|
|
3114
|
-
maxSupply: tokenConfig.maxSupply,
|
|
3115
|
-
maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
|
|
3116
|
-
pricePerToken: tokenConfig.pricePerToken,
|
|
3117
|
-
mintDuration: tokenConfig.mintDuration,
|
|
3118
|
-
mintStart: tokenConfig.mintStart,
|
|
3119
|
-
royaltyBPS: tokenConfig.royaltyBPS,
|
|
3120
|
-
tokenURI: tokenConfig.tokenURI,
|
|
3121
|
-
royaltyRecipient: tokenConfig.payoutRecipient
|
|
3122
|
-
});
|
|
3123
|
-
var pickTokenConfigV2 = (tokenConfig) => ({
|
|
3124
|
-
maxSupply: tokenConfig.maxSupply,
|
|
3125
|
-
maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
|
|
3126
|
-
pricePerToken: tokenConfig.pricePerToken,
|
|
3127
|
-
mintDuration: tokenConfig.mintDuration,
|
|
3128
|
-
mintStart: tokenConfig.mintStart,
|
|
3129
|
-
royaltyBPS: tokenConfig.royaltyBPS,
|
|
3130
|
-
tokenURI: tokenConfig.tokenURI,
|
|
3131
|
-
payoutRecipient: tokenConfig.payoutRecipient,
|
|
3132
|
-
createReferral: tokenConfig.createReferral || import_viem4.zeroAddress
|
|
3133
|
-
});
|
|
3134
|
-
var tokenConfigV1WithDefault = (tokenConfig, fixedPriceMinter) => ({
|
|
3135
|
-
...pickTokenConfigV1(tokenConfig),
|
|
3136
|
-
...defaultTokenConfigV1MintArguments(),
|
|
3137
|
-
fixedPriceMinter
|
|
3138
|
-
});
|
|
3139
|
-
var tokenConfigV2WithDefault = (tokenConfig, fixedPriceMinter) => ({
|
|
3140
|
-
...pickTokenConfigV2(tokenConfig),
|
|
3141
|
-
...defaultTokenConfigV2MintArguments(),
|
|
3142
|
-
fixedPriceMinter
|
|
3143
|
-
});
|
|
3144
|
-
var defaultTokenConfigV2MintArguments = () => ({
|
|
3145
|
-
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
3146
|
-
maxTokensPerAddress: 0n,
|
|
3147
|
-
pricePerToken: 0n,
|
|
3148
|
-
mintDuration: 0n,
|
|
3149
|
-
mintStart: 0n,
|
|
3150
|
-
royaltyBPS: 1e3
|
|
3151
|
-
// 10%,
|
|
3152
|
-
});
|
|
3153
|
-
var makeTokenConfigWithDefaults = ({
|
|
3154
|
-
chainId,
|
|
3155
|
-
tokenCreationConfig,
|
|
3156
|
-
supportedPremintVersions: supportedPremintVersions2
|
|
3075
|
+
var buildPremintMintCall = ({
|
|
3076
|
+
mintArguments: {
|
|
3077
|
+
minterAccount,
|
|
3078
|
+
mintComment = "",
|
|
3079
|
+
mintRecipient,
|
|
3080
|
+
mintReferral,
|
|
3081
|
+
firstMinter,
|
|
3082
|
+
quantityToMint
|
|
3083
|
+
},
|
|
3084
|
+
premint: { collection, collectionAddress, premint, signature },
|
|
3085
|
+
mintFee
|
|
3157
3086
|
}) => {
|
|
3158
|
-
const
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3087
|
+
const mintArgumentsContract = {
|
|
3088
|
+
mintComment,
|
|
3089
|
+
mintRecipient: mintRecipientOrAccount({
|
|
3090
|
+
mintRecipient,
|
|
3091
|
+
minterAccount
|
|
3092
|
+
}),
|
|
3093
|
+
mintRewardsRecipients: makeMintRewardsRecipient({
|
|
3094
|
+
mintReferral
|
|
3095
|
+
})
|
|
3096
|
+
};
|
|
3097
|
+
const collectionOrEmpty = collection ? defaultAdditionalAdmins(collection) : emptyContractCreationConfig();
|
|
3098
|
+
const collectionAddressToSubmit = collection ? import_viem4.zeroAddress : collectionAddress;
|
|
3099
|
+
const firstMinterToSubmit = firstMinter || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
|
|
3100
|
+
if (premint.premintConfigVersion === import_protocol_deployments4.PremintConfigVersion.V3) {
|
|
3101
|
+
throw new Error("PremintV3 not supported in premint SDK");
|
|
3102
|
+
}
|
|
3103
|
+
const value = (mintFee + premint.premintConfig.tokenConfig.pricePerToken) * BigInt(quantityToMint);
|
|
3104
|
+
return makeContractParameters({
|
|
3105
|
+
account: minterAccount,
|
|
3106
|
+
abi: import_protocol_deployments3.zoraCreator1155PremintExecutorImplABI,
|
|
3107
|
+
functionName: "premint",
|
|
3108
|
+
value,
|
|
3109
|
+
address: getPremintExecutorAddress(),
|
|
3110
|
+
args: [
|
|
3111
|
+
collectionOrEmpty,
|
|
3112
|
+
collectionAddressToSubmit,
|
|
3113
|
+
(0, import_protocol_deployments3.encodePremintConfig)(premint),
|
|
3114
|
+
signature,
|
|
3115
|
+
BigInt(quantityToMint),
|
|
3116
|
+
mintArgumentsContract,
|
|
3117
|
+
firstMinterToSubmit,
|
|
3118
|
+
import_viem4.zeroAddress
|
|
3119
|
+
]
|
|
3120
|
+
});
|
|
3121
|
+
};
|
|
3122
|
+
function makeUrls({
|
|
3123
|
+
uid,
|
|
3124
|
+
address,
|
|
3125
|
+
tokenId,
|
|
3126
|
+
chainId,
|
|
3127
|
+
blockExplorerUrl
|
|
3128
|
+
}) {
|
|
3129
|
+
if ((!uid || !tokenId) && !address) {
|
|
3130
|
+
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
3170
3131
|
}
|
|
3132
|
+
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
3133
|
+
const network = getApiNetworkConfigForChain(chainId);
|
|
3171
3134
|
return {
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
fixedPriceMinter
|
|
3176
|
-
)
|
|
3135
|
+
explorer: tokenId ? `https://${blockExplorerUrl}/token/${address}/instance/${tokenId}` : null,
|
|
3136
|
+
zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`,
|
|
3137
|
+
zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
|
|
3177
3138
|
};
|
|
3178
|
-
}
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3141
|
+
// src/premint/contract-types.ts
|
|
3142
|
+
var import_protocol_deployments5 = require("@zoralabs/protocol-deployments");
|
|
3143
|
+
var PremintConfigVersion3 = ((PremintConfigVersion4) => {
|
|
3144
|
+
PremintConfigVersion4[PremintConfigVersion4["V1"] = import_protocol_deployments5.PremintConfigVersion.V1] = "V1";
|
|
3145
|
+
PremintConfigVersion4[PremintConfigVersion4["V2"] = import_protocol_deployments5.PremintConfigVersion.V2] = "V2";
|
|
3146
|
+
PremintConfigVersion4[PremintConfigVersion4["V3"] = import_protocol_deployments5.PremintConfigVersion.V3] = "V3";
|
|
3147
|
+
return PremintConfigVersion4;
|
|
3148
|
+
})(PremintConfigVersion3 || {});
|
|
3149
|
+
|
|
3150
|
+
// src/retries.ts
|
|
3151
|
+
async function wait(delayMs) {
|
|
3152
|
+
return new Promise((resolve) => {
|
|
3153
|
+
setTimeout(resolve, delayMs);
|
|
3154
|
+
});
|
|
3155
|
+
}
|
|
3156
|
+
var retryInternal = async ({
|
|
3157
|
+
tryFn,
|
|
3158
|
+
maxTries = 3,
|
|
3159
|
+
atTry,
|
|
3160
|
+
linearBackoffMS = 200,
|
|
3161
|
+
shouldRetryOnError = () => true
|
|
3162
|
+
}) => {
|
|
3163
|
+
try {
|
|
3164
|
+
return await tryFn();
|
|
3165
|
+
} catch (err) {
|
|
3166
|
+
if (shouldRetryOnError(err)) {
|
|
3167
|
+
if (atTry <= maxTries) {
|
|
3168
|
+
await wait(atTry * linearBackoffMS);
|
|
3169
|
+
return await retryInternal({
|
|
3170
|
+
tryFn,
|
|
3171
|
+
maxTries,
|
|
3172
|
+
atTry: atTry + 1,
|
|
3173
|
+
linearBackoffMS,
|
|
3174
|
+
shouldRetryOnError
|
|
3175
|
+
});
|
|
3189
3176
|
}
|
|
3190
|
-
} catch (err) {
|
|
3191
3177
|
}
|
|
3178
|
+
throw err;
|
|
3192
3179
|
}
|
|
3193
|
-
}
|
|
3194
|
-
var
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
* Prepares data for updating a premint
|
|
3209
|
-
*
|
|
3210
|
-
* @param parameters - Parameters for updating the premint {@link UpdatePremintParams}
|
|
3211
|
-
* @returns A PremintReturn. {@link PremintReturn}
|
|
3212
|
-
*/
|
|
3213
|
-
async updatePremint(args) {
|
|
3214
|
-
return await updatePremint({
|
|
3215
|
-
...args,
|
|
3216
|
-
apiClient: this.apiClient,
|
|
3217
|
-
publicClient: this.publicClient,
|
|
3218
|
-
chainId: this.chainId
|
|
3219
|
-
});
|
|
3180
|
+
};
|
|
3181
|
+
var retriesGeneric = async (params) => {
|
|
3182
|
+
return retryInternal({
|
|
3183
|
+
...params,
|
|
3184
|
+
atTry: 1
|
|
3185
|
+
});
|
|
3186
|
+
};
|
|
3187
|
+
|
|
3188
|
+
// src/apis/http-api-base.ts
|
|
3189
|
+
var BadResponseError = class extends Error {
|
|
3190
|
+
constructor(message, status, json) {
|
|
3191
|
+
super(message);
|
|
3192
|
+
this.name = "BadResponseError";
|
|
3193
|
+
this.status = status;
|
|
3194
|
+
this.json = json;
|
|
3220
3195
|
}
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3196
|
+
};
|
|
3197
|
+
var get = async (url) => {
|
|
3198
|
+
const response = await fetch(url, { method: "GET" });
|
|
3199
|
+
if (response.status !== 200) {
|
|
3200
|
+
let json;
|
|
3201
|
+
try {
|
|
3202
|
+
json = await response.json();
|
|
3203
|
+
} catch (e) {
|
|
3204
|
+
}
|
|
3205
|
+
throw new BadResponseError(
|
|
3206
|
+
`Invalid response, status ${response.status}`,
|
|
3207
|
+
response.status,
|
|
3208
|
+
json
|
|
3209
|
+
);
|
|
3234
3210
|
}
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
}
|
|
3211
|
+
return await response.json();
|
|
3212
|
+
};
|
|
3213
|
+
var post = async (url, data) => {
|
|
3214
|
+
const controller = new AbortController();
|
|
3215
|
+
const { signal } = controller;
|
|
3216
|
+
const timeout = 30 * 60 * 1e3;
|
|
3217
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
3218
|
+
const response = await fetch(url, {
|
|
3219
|
+
method: "POST",
|
|
3220
|
+
headers: {
|
|
3221
|
+
"content-type": "application/json",
|
|
3222
|
+
accept: "application/json"
|
|
3223
|
+
},
|
|
3224
|
+
body: JSON.stringify(data),
|
|
3225
|
+
signal
|
|
3226
|
+
});
|
|
3227
|
+
clearTimeout(timeoutId);
|
|
3228
|
+
if (response.status !== 200) {
|
|
3229
|
+
let json;
|
|
3230
|
+
try {
|
|
3231
|
+
json = await response.json();
|
|
3232
|
+
} catch (e) {
|
|
3233
|
+
}
|
|
3234
|
+
throw new BadResponseError(
|
|
3235
|
+
`Bad response: ${response.status}`,
|
|
3236
|
+
response.status,
|
|
3237
|
+
json
|
|
3238
|
+
);
|
|
3248
3239
|
}
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3240
|
+
return await response.json();
|
|
3241
|
+
};
|
|
3242
|
+
var defaultShouldRetry = (err) => {
|
|
3243
|
+
return err instanceof BadResponseError && err.status >= 500;
|
|
3244
|
+
};
|
|
3245
|
+
var retries = async (tryFn, maxTries = 3, linearBackoffMS = 200, shouldRetry = defaultShouldRetry) => {
|
|
3246
|
+
return retriesGeneric({
|
|
3247
|
+
tryFn,
|
|
3248
|
+
maxTries,
|
|
3249
|
+
linearBackoffMS,
|
|
3250
|
+
shouldRetryOnError: shouldRetry
|
|
3251
|
+
});
|
|
3252
|
+
};
|
|
3253
|
+
var httpClient = {
|
|
3254
|
+
get,
|
|
3255
|
+
post,
|
|
3256
|
+
retries
|
|
3257
|
+
};
|
|
3258
|
+
|
|
3259
|
+
// src/premint/premint-api-client.ts
|
|
3260
|
+
var postSignature = async ({
|
|
3261
|
+
httpClient: { post: post2, retries: retries2 } = httpClient,
|
|
3262
|
+
...data
|
|
3263
|
+
}) => retries2(
|
|
3264
|
+
() => post2(`${ZORA_API_BASE}premint/signature`, data)
|
|
3265
|
+
);
|
|
3266
|
+
var getNextUID = async ({
|
|
3267
|
+
chainId,
|
|
3268
|
+
collection_address,
|
|
3269
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3270
|
+
}) => retries2(
|
|
3271
|
+
() => get2(
|
|
3272
|
+
`${ZORA_API_BASE}premint/signature/${getApiNetworkConfigForChain(chainId).zoraBackendChainName}/${collection_address}/next_uid`
|
|
3273
|
+
)
|
|
3274
|
+
);
|
|
3275
|
+
var getSignature = async ({
|
|
3276
|
+
collectionAddress,
|
|
3277
|
+
uid,
|
|
3278
|
+
chainId,
|
|
3279
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3280
|
+
}) => {
|
|
3281
|
+
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
3282
|
+
const result = await retries2(
|
|
3283
|
+
() => get2(
|
|
3284
|
+
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}/${uid}`
|
|
3285
|
+
)
|
|
3286
|
+
);
|
|
3287
|
+
return convertGetPremintApiResponse(result);
|
|
3288
|
+
};
|
|
3289
|
+
var getOfCollection = async ({
|
|
3290
|
+
collectionAddress,
|
|
3291
|
+
chainId,
|
|
3292
|
+
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3293
|
+
}) => {
|
|
3294
|
+
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
3295
|
+
const result = await retries2(
|
|
3296
|
+
() => get2(
|
|
3297
|
+
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}`
|
|
3298
|
+
)
|
|
3299
|
+
);
|
|
3300
|
+
return convertGetPremintOfCollectionApiResponse(result);
|
|
3301
|
+
};
|
|
3302
|
+
var PremintAPIClient = class {
|
|
3303
|
+
constructor(chainId, httpClient2) {
|
|
3304
|
+
this.postSignature = ({
|
|
3305
|
+
signature,
|
|
3306
|
+
...rest
|
|
3307
|
+
}) => {
|
|
3308
|
+
const data = encodePostSignatureInput({
|
|
3309
|
+
...rest,
|
|
3310
|
+
chainId: this.chainId,
|
|
3311
|
+
signature
|
|
3312
|
+
});
|
|
3313
|
+
return postSignature({
|
|
3314
|
+
...data,
|
|
3315
|
+
httpClient: this.httpClient
|
|
3316
|
+
});
|
|
3317
|
+
};
|
|
3318
|
+
this.getNextUID = async (collectionAddress) => (await getNextUID({
|
|
3319
|
+
collection_address: collectionAddress.toLowerCase(),
|
|
3320
|
+
chainId: this.chainId,
|
|
3321
|
+
httpClient: this.httpClient
|
|
3322
|
+
})).next_uid;
|
|
3323
|
+
this.get = async ({ collectionAddress, uid }) => {
|
|
3324
|
+
return getSignature({
|
|
3325
|
+
collectionAddress,
|
|
3326
|
+
uid,
|
|
3327
|
+
chainId: this.chainId,
|
|
3328
|
+
httpClient: this.httpClient
|
|
3329
|
+
});
|
|
3330
|
+
};
|
|
3331
|
+
this.getOfCollection = async ({
|
|
3332
|
+
collectionAddress
|
|
3333
|
+
}) => {
|
|
3334
|
+
return getOfCollection({
|
|
3335
|
+
collectionAddress,
|
|
3336
|
+
chainId: this.chainId,
|
|
3337
|
+
httpClient: this.httpClient
|
|
3338
|
+
});
|
|
3339
|
+
};
|
|
3340
|
+
this.chainId = chainId;
|
|
3341
|
+
this.httpClient = httpClient2 || httpClient;
|
|
3261
3342
|
}
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3343
|
+
};
|
|
3344
|
+
|
|
3345
|
+
// src/mint/subgraph-queries.ts
|
|
3346
|
+
var NFT_SALE_STRATEGY_FRAGMENT = `
|
|
3347
|
+
fragment SaleStrategy on SalesStrategyConfig {
|
|
3348
|
+
type
|
|
3349
|
+
fixedPrice {
|
|
3350
|
+
address
|
|
3351
|
+
pricePerToken
|
|
3352
|
+
saleEnd
|
|
3353
|
+
saleStart
|
|
3354
|
+
maxTokensPerAddress
|
|
3272
3355
|
}
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
quantityToMint,
|
|
3356
|
+
erc20Minter {
|
|
3357
|
+
address
|
|
3276
3358
|
pricePerToken
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
tokenContract,
|
|
3282
|
-
tokenPrice: pricePerToken
|
|
3283
|
-
});
|
|
3359
|
+
currency
|
|
3360
|
+
saleEnd
|
|
3361
|
+
saleStart
|
|
3362
|
+
maxTokensPerAddress
|
|
3284
3363
|
}
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
* @returns receipt, log, zoraURL
|
|
3291
|
-
*/
|
|
3292
|
-
async makeMintParameters({
|
|
3293
|
-
minterAccount,
|
|
3294
|
-
tokenContract,
|
|
3295
|
-
uid,
|
|
3296
|
-
mintArguments,
|
|
3297
|
-
firstMinter
|
|
3298
|
-
}) {
|
|
3299
|
-
return await collectPremint({
|
|
3300
|
-
uid,
|
|
3301
|
-
tokenContract,
|
|
3302
|
-
minterAccount,
|
|
3303
|
-
quantityToMint: mintArguments?.quantityToMint || 1n,
|
|
3304
|
-
mintComment: mintArguments?.mintComment,
|
|
3305
|
-
mintReferral: mintArguments?.mintReferral,
|
|
3306
|
-
mintRecipient: mintArguments?.mintRecipient,
|
|
3307
|
-
firstMinter,
|
|
3308
|
-
premintGetter: this.apiClient,
|
|
3309
|
-
publicClient: this.publicClient
|
|
3310
|
-
});
|
|
3364
|
+
presale {
|
|
3365
|
+
address
|
|
3366
|
+
presaleStart
|
|
3367
|
+
presaleEnd
|
|
3368
|
+
merkleRoot
|
|
3311
3369
|
}
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3370
|
+
zoraTimedMinter {
|
|
3371
|
+
address
|
|
3372
|
+
mintFee
|
|
3373
|
+
saleStart
|
|
3374
|
+
saleEnd
|
|
3375
|
+
erc20Z {
|
|
3376
|
+
id
|
|
3377
|
+
pool
|
|
3378
|
+
}
|
|
3379
|
+
secondaryActivated
|
|
3380
|
+
marketCountdown
|
|
3381
|
+
minimumMarketEth
|
|
3382
|
+
}
|
|
3383
|
+
}`;
|
|
3384
|
+
var TOKEN_FRAGMENT = `
|
|
3385
|
+
fragment Token on ZoraCreateToken {
|
|
3386
|
+
creator
|
|
3387
|
+
tokenId
|
|
3388
|
+
uri
|
|
3389
|
+
totalMinted
|
|
3390
|
+
maxSupply
|
|
3391
|
+
tokenStandard
|
|
3392
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
3393
|
+
...SaleStrategy
|
|
3394
|
+
}
|
|
3395
|
+
contract {
|
|
3396
|
+
address
|
|
3397
|
+
mintFeePerQuantity
|
|
3398
|
+
contractVersion
|
|
3399
|
+
contractURI
|
|
3400
|
+
name
|
|
3401
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
3402
|
+
...SaleStrategy
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
}`;
|
|
3406
|
+
var FRAGMENTS = `
|
|
3407
|
+
${NFT_SALE_STRATEGY_FRAGMENT}
|
|
3408
|
+
${TOKEN_FRAGMENT}
|
|
3409
|
+
`;
|
|
3410
|
+
function buildNftTokenSalesQuery({
|
|
3411
|
+
tokenId,
|
|
3412
|
+
tokenAddress
|
|
3413
|
+
}) {
|
|
3315
3414
|
return {
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3415
|
+
query: `
|
|
3416
|
+
${FRAGMENTS}
|
|
3417
|
+
query ($id: ID!) {
|
|
3418
|
+
zoraCreateToken(id: $id) {
|
|
3419
|
+
...Token
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
`,
|
|
3423
|
+
variables: {
|
|
3424
|
+
id: tokenId !== void 0 ? (
|
|
3425
|
+
// Generic Token ID types all stringify down to the base numeric equivalent.
|
|
3426
|
+
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
3427
|
+
) : `${tokenAddress.toLowerCase()}-0`
|
|
3428
|
+
},
|
|
3429
|
+
parseResponseData: (responseData) => responseData?.zoraCreateToken
|
|
3325
3430
|
};
|
|
3326
3431
|
}
|
|
3327
|
-
function
|
|
3328
|
-
|
|
3329
|
-
premintConfigVersion,
|
|
3330
|
-
publicClient,
|
|
3331
|
-
apiClient,
|
|
3332
|
-
chainId,
|
|
3333
|
-
...collectionAndAddress
|
|
3432
|
+
function buildContractTokensQuery({
|
|
3433
|
+
tokenAddress
|
|
3334
3434
|
}) {
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
typedDataDefinition
|
|
3351
|
-
});
|
|
3352
|
-
await submit({
|
|
3353
|
-
signature,
|
|
3354
|
-
checkSignature,
|
|
3355
|
-
account: signerAccount
|
|
3356
|
-
});
|
|
3357
|
-
return {
|
|
3358
|
-
signature,
|
|
3359
|
-
signerAccount
|
|
3360
|
-
};
|
|
3361
|
-
};
|
|
3362
|
-
const submit = async ({
|
|
3363
|
-
signature,
|
|
3364
|
-
checkSignature,
|
|
3365
|
-
account
|
|
3366
|
-
}) => {
|
|
3367
|
-
if (checkSignature) {
|
|
3368
|
-
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
3369
|
-
collectionAddress,
|
|
3370
|
-
additionalAdmins: collection?.additionalAdmins,
|
|
3371
|
-
contractAdmin: collection?.contractAdmin,
|
|
3372
|
-
publicClient,
|
|
3373
|
-
signer: account
|
|
3374
|
-
});
|
|
3375
|
-
if (!isAuthorized) {
|
|
3376
|
-
throw new Error("Not authorized to create premint");
|
|
3377
|
-
}
|
|
3378
|
-
}
|
|
3379
|
-
await apiClient.postSignature({
|
|
3380
|
-
...toContractCreationConfigOrAddress(collectionAndAddress),
|
|
3381
|
-
signature,
|
|
3382
|
-
premintConfig,
|
|
3383
|
-
premintConfigVersion
|
|
3384
|
-
});
|
|
3435
|
+
return {
|
|
3436
|
+
query: `
|
|
3437
|
+
${FRAGMENTS}
|
|
3438
|
+
query ($contract: Bytes!) {
|
|
3439
|
+
zoraCreateTokens(
|
|
3440
|
+
where: {address: $contract}
|
|
3441
|
+
) {
|
|
3442
|
+
...Token
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
`,
|
|
3446
|
+
variables: {
|
|
3447
|
+
contract: tokenAddress.toLowerCase()
|
|
3448
|
+
},
|
|
3449
|
+
parseResponseData: (responseData) => responseData?.zoraCreateTokens
|
|
3385
3450
|
};
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
});
|
|
3451
|
+
}
|
|
3452
|
+
function buildPremintsOfContractQuery({
|
|
3453
|
+
tokenAddress
|
|
3454
|
+
}) {
|
|
3391
3455
|
return {
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3456
|
+
query: `
|
|
3457
|
+
query ($contractAddress: Bytes!) {
|
|
3458
|
+
premints(where:{contractAddress:$contractAddress}) {
|
|
3459
|
+
uid
|
|
3460
|
+
tokenId
|
|
3461
|
+
}
|
|
3462
|
+
}
|
|
3463
|
+
`,
|
|
3464
|
+
variables: {
|
|
3465
|
+
contractAddress: tokenAddress.toLowerCase()
|
|
3466
|
+
},
|
|
3467
|
+
parseResponseData: (responseData) => responseData?.premints
|
|
3399
3468
|
};
|
|
3400
3469
|
}
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
if (!account) {
|
|
3407
|
-
account = walletClient.account;
|
|
3470
|
+
|
|
3471
|
+
// src/apis/subgraph-querier.ts
|
|
3472
|
+
var SubgraphQuerier = class {
|
|
3473
|
+
constructor(httpClient2) {
|
|
3474
|
+
this.httpClient = httpClient2;
|
|
3408
3475
|
}
|
|
3409
|
-
|
|
3410
|
-
|
|
3476
|
+
async query({
|
|
3477
|
+
subgraphUrl,
|
|
3478
|
+
query,
|
|
3479
|
+
variables
|
|
3480
|
+
}) {
|
|
3481
|
+
const { retries: retries2, post: post2 } = this.httpClient;
|
|
3482
|
+
const result = await retries2(async () => {
|
|
3483
|
+
return await post2(subgraphUrl, {
|
|
3484
|
+
query,
|
|
3485
|
+
variables
|
|
3486
|
+
});
|
|
3487
|
+
});
|
|
3488
|
+
return result?.data;
|
|
3411
3489
|
}
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3490
|
+
};
|
|
3491
|
+
|
|
3492
|
+
// src/apis/subgraph-getter.ts
|
|
3493
|
+
var SubgraphGetter = class {
|
|
3494
|
+
constructor(chainId, subgraphQuerier) {
|
|
3495
|
+
this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
|
|
3496
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
3497
|
+
}
|
|
3498
|
+
async querySubgraphWithRetries({
|
|
3499
|
+
query,
|
|
3500
|
+
variables,
|
|
3501
|
+
parseResponseData
|
|
3502
|
+
}) {
|
|
3503
|
+
const responseData = await this.subgraphQuerier.query({
|
|
3504
|
+
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
3505
|
+
query,
|
|
3506
|
+
variables
|
|
3507
|
+
});
|
|
3508
|
+
return parseResponseData(responseData);
|
|
3509
|
+
}
|
|
3510
|
+
};
|
|
3511
|
+
|
|
3512
|
+
// src/mint/strategies-parsing.ts
|
|
3513
|
+
function parseFixedPriceSalesConfig(fixedPrice, contractMintFee) {
|
|
3416
3514
|
return {
|
|
3417
|
-
|
|
3418
|
-
|
|
3515
|
+
salesStrategy: {
|
|
3516
|
+
saleType: "fixedPrice",
|
|
3517
|
+
...fixedPrice,
|
|
3518
|
+
maxTokensPerAddress: BigInt(fixedPrice.maxTokensPerAddress),
|
|
3519
|
+
pricePerToken: BigInt(fixedPrice.pricePerToken),
|
|
3520
|
+
mintFeePerQuantity: contractMintFee
|
|
3521
|
+
},
|
|
3522
|
+
saleEnd: BigInt(fixedPrice.saleEnd),
|
|
3523
|
+
saleStart: BigInt(fixedPrice.saleStart)
|
|
3524
|
+
// saleActive:
|
|
3525
|
+
// BigInt(fixedPrice.saleStart) <= blockTime && BigInt(saleEnd) > blockTime,
|
|
3419
3526
|
};
|
|
3420
3527
|
}
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
tokenCreationConfig,
|
|
3436
|
-
uid,
|
|
3437
|
-
publicClient,
|
|
3438
|
-
apiClient,
|
|
3439
|
-
chainId
|
|
3440
|
-
});
|
|
3441
|
-
return makePremintReturn({
|
|
3442
|
-
premintConfig,
|
|
3443
|
-
premintConfigVersion,
|
|
3444
|
-
collectionAddress: collectionAddressToUse,
|
|
3445
|
-
collection: collectionOrAddress.contract,
|
|
3446
|
-
publicClient,
|
|
3447
|
-
apiClient,
|
|
3448
|
-
chainId
|
|
3449
|
-
});
|
|
3528
|
+
function parseERC20SalesConfig(erc20Minter) {
|
|
3529
|
+
return {
|
|
3530
|
+
salesStrategy: {
|
|
3531
|
+
saleType: "erc20",
|
|
3532
|
+
...erc20Minter,
|
|
3533
|
+
maxTokensPerAddress: BigInt(erc20Minter.maxTokensPerAddress),
|
|
3534
|
+
pricePerToken: BigInt(erc20Minter.pricePerToken),
|
|
3535
|
+
mintFeePerQuantity: 0n
|
|
3536
|
+
},
|
|
3537
|
+
saleEnd: BigInt(erc20Minter.saleEnd),
|
|
3538
|
+
saleStart: BigInt(erc20Minter.saleStart)
|
|
3539
|
+
// saleActive:
|
|
3540
|
+
// BigInt(erc20Minter.saleStart) <= blockTime && saleEnd > blockTime,
|
|
3541
|
+
};
|
|
3450
3542
|
}
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
uidToUse = await apiClient.getNextUID(newContractAddress);
|
|
3466
|
-
}
|
|
3467
|
-
const supportedVersions = await supportedPremintVersions({
|
|
3468
|
-
tokenContract: newContractAddress,
|
|
3469
|
-
publicClient
|
|
3470
|
-
});
|
|
3471
|
-
const tokenConfigAndVersion = makeTokenConfigWithDefaults({
|
|
3472
|
-
tokenCreationConfig,
|
|
3473
|
-
chainId,
|
|
3474
|
-
supportedPremintVersions: supportedVersions
|
|
3475
|
-
});
|
|
3476
|
-
const premintConfig = makeNewPremint({
|
|
3477
|
-
...tokenConfigAndVersion,
|
|
3478
|
-
uid: uidToUse
|
|
3479
|
-
});
|
|
3480
|
-
const premintConfigAndVersion = {
|
|
3481
|
-
premintConfig,
|
|
3482
|
-
premintConfigVersion: tokenConfigAndVersion.premintConfigVersion
|
|
3543
|
+
function parsePresaleSalesConfig(presale, contractMintFee) {
|
|
3544
|
+
return {
|
|
3545
|
+
salesStrategy: {
|
|
3546
|
+
saleType: "allowlist",
|
|
3547
|
+
address: presale.address,
|
|
3548
|
+
merkleRoot: presale.merkleRoot,
|
|
3549
|
+
saleStart: presale.presaleStart,
|
|
3550
|
+
saleEnd: presale.presaleEnd,
|
|
3551
|
+
mintFeePerQuantity: contractMintFee
|
|
3552
|
+
},
|
|
3553
|
+
saleEnd: BigInt(presale.presaleEnd),
|
|
3554
|
+
saleStart: BigInt(presale.presaleStart)
|
|
3555
|
+
// saleActive:
|
|
3556
|
+
// BigInt(presale.presaleStart) <= blockTime && saleEnd > blockTime,
|
|
3483
3557
|
};
|
|
3558
|
+
}
|
|
3559
|
+
function parseZoraTimedSalesConfig(zoraTimedMinter) {
|
|
3560
|
+
const saleEnd = BigInt(zoraTimedMinter.saleEnd);
|
|
3484
3561
|
return {
|
|
3485
|
-
|
|
3486
|
-
|
|
3562
|
+
salesStrategy: {
|
|
3563
|
+
saleType: "timed",
|
|
3564
|
+
address: zoraTimedMinter.address,
|
|
3565
|
+
mintFee: BigInt(zoraTimedMinter.mintFee),
|
|
3566
|
+
saleStart: zoraTimedMinter.saleStart,
|
|
3567
|
+
saleEnd: zoraTimedMinter.saleEnd,
|
|
3568
|
+
erc20Z: zoraTimedMinter.erc20Z.id,
|
|
3569
|
+
pool: zoraTimedMinter.erc20Z.pool,
|
|
3570
|
+
secondaryActivated: zoraTimedMinter.secondaryActivated,
|
|
3571
|
+
mintFeePerQuantity: BigInt(zoraTimedMinter.mintFee),
|
|
3572
|
+
marketCountdown: zoraTimedMinter.marketCountdown ? BigInt(zoraTimedMinter.marketCountdown) : void 0,
|
|
3573
|
+
minimumMarketEth: zoraTimedMinter.minimumMarketEth ? BigInt(zoraTimedMinter.minimumMarketEth) : void 0
|
|
3574
|
+
},
|
|
3575
|
+
saleEnd: saleEnd > 0n ? saleEnd : void 0,
|
|
3576
|
+
saleStart: BigInt(zoraTimedMinter.saleStart)
|
|
3577
|
+
// saleActive:
|
|
3578
|
+
// BigInt(zoraTimedMinter.saleStart) <= blockTime &&
|
|
3579
|
+
// (hasSaleEnd ? saleEnd > blockTime : true),
|
|
3487
3580
|
};
|
|
3488
3581
|
}
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3582
|
+
function parseSalesConfig(targetStrategy, contractMintFee) {
|
|
3583
|
+
switch (targetStrategy.type) {
|
|
3584
|
+
case "FIXED_PRICE":
|
|
3585
|
+
return parseFixedPriceSalesConfig(
|
|
3586
|
+
targetStrategy.fixedPrice,
|
|
3587
|
+
contractMintFee
|
|
3588
|
+
// blockTime,
|
|
3589
|
+
);
|
|
3590
|
+
case "ERC_20_MINTER":
|
|
3591
|
+
return parseERC20SalesConfig(targetStrategy.erc20Minter);
|
|
3592
|
+
case "PRESALE":
|
|
3593
|
+
return parsePresaleSalesConfig(
|
|
3594
|
+
targetStrategy.presale,
|
|
3595
|
+
contractMintFee
|
|
3596
|
+
// blockTime,
|
|
3597
|
+
);
|
|
3598
|
+
case "ZORA_TIMED":
|
|
3599
|
+
return parseZoraTimedSalesConfig(
|
|
3600
|
+
targetStrategy.zoraTimedMinter
|
|
3601
|
+
// blockTime,
|
|
3602
|
+
);
|
|
3603
|
+
default:
|
|
3604
|
+
throw new Error("Unknown saleType");
|
|
3605
|
+
}
|
|
3606
|
+
}
|
|
3607
|
+
function isPrimaryMintActive(sale, blockTime) {
|
|
3608
|
+
if (sale.saleStart > blockTime)
|
|
3609
|
+
return false;
|
|
3610
|
+
if (!sale.saleEnd)
|
|
3611
|
+
return true;
|
|
3612
|
+
return sale.saleEnd > blockTime;
|
|
3613
|
+
}
|
|
3614
|
+
function isSecondaryMinter(result) {
|
|
3615
|
+
return result.saleType === "timed";
|
|
3616
|
+
}
|
|
3617
|
+
function isSecondaryMarketActive(sale) {
|
|
3618
|
+
const salesStrategy = sale.salesStrategy;
|
|
3619
|
+
if (isSecondaryMinter(salesStrategy)) {
|
|
3620
|
+
return salesStrategy.secondaryActivated;
|
|
3621
|
+
}
|
|
3622
|
+
return false;
|
|
3623
|
+
}
|
|
3624
|
+
function getTargetStrategy({
|
|
3625
|
+
preferredSaleType,
|
|
3626
|
+
blockTime,
|
|
3627
|
+
parsedStrategies
|
|
3496
3628
|
}) {
|
|
3497
|
-
const
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
const
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3629
|
+
const withPrimaryAndSecondaryMintActive = parsedStrategies.map(
|
|
3630
|
+
(strategy) => ({
|
|
3631
|
+
strategy,
|
|
3632
|
+
primaryMintActive: isPrimaryMintActive(strategy, blockTime),
|
|
3633
|
+
secondaryMarketActive: isSecondaryMarketActive(strategy)
|
|
3634
|
+
})
|
|
3635
|
+
);
|
|
3636
|
+
const stillValidSalesStrategies = withPrimaryAndSecondaryMintActive.filter(
|
|
3637
|
+
({ primaryMintActive, secondaryMarketActive }) => primaryMintActive || secondaryMarketActive
|
|
3638
|
+
);
|
|
3639
|
+
const saleStrategies = stillValidSalesStrategies.sort(
|
|
3640
|
+
(a, b) => (a.strategy.saleEnd ?? 0n) > (b.strategy.saleEnd ?? 0n) ? 1 : -1
|
|
3641
|
+
);
|
|
3642
|
+
let targetStrategy;
|
|
3643
|
+
if (!preferredSaleType) {
|
|
3644
|
+
return saleStrategies[0];
|
|
3645
|
+
} else {
|
|
3646
|
+
targetStrategy = saleStrategies.find(
|
|
3647
|
+
({ strategy: { salesStrategy } }) => salesStrategy.saleType === preferredSaleType
|
|
3648
|
+
);
|
|
3649
|
+
if (!targetStrategy) {
|
|
3650
|
+
targetStrategy = saleStrategies.find(
|
|
3651
|
+
({ strategy: { salesStrategy } }) => salesStrategy.saleType === "timed" || salesStrategy.saleType === "fixedPrice" || salesStrategy.saleType === "erc20"
|
|
3652
|
+
);
|
|
3653
|
+
if (!targetStrategy)
|
|
3654
|
+
throw new Error("Cannot find valid sale strategy");
|
|
3655
|
+
return targetStrategy;
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
return targetStrategy;
|
|
3519
3659
|
}
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3660
|
+
function findTargetStrategyWithPrimaryOrSecondarySaleActive({
|
|
3661
|
+
token,
|
|
3662
|
+
tokenId,
|
|
3663
|
+
preferredSaleType,
|
|
3664
|
+
defaultMintFee,
|
|
3665
|
+
blockTime
|
|
3526
3666
|
}) {
|
|
3527
|
-
const
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
const deletedPremint = {
|
|
3536
|
-
...premintConfig,
|
|
3537
|
-
version: premintConfig.version + 1,
|
|
3538
|
-
deleted: true
|
|
3539
|
-
};
|
|
3540
|
-
return makePremintReturn({
|
|
3541
|
-
premintConfig: deletedPremint,
|
|
3542
|
-
premintConfigVersion,
|
|
3543
|
-
collectionAddress,
|
|
3544
|
-
collection: collectionCreationConfig,
|
|
3545
|
-
publicClient,
|
|
3546
|
-
apiClient,
|
|
3547
|
-
chainId
|
|
3667
|
+
const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
|
|
3668
|
+
const parsedStrategies = allStrategies.map(
|
|
3669
|
+
(strategy) => parseSalesConfig(strategy, defaultMintFee)
|
|
3670
|
+
);
|
|
3671
|
+
const targetStrategy = getTargetStrategy({
|
|
3672
|
+
preferredSaleType,
|
|
3673
|
+
blockTime,
|
|
3674
|
+
parsedStrategies
|
|
3548
3675
|
});
|
|
3676
|
+
return targetStrategy;
|
|
3549
3677
|
}
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
mintComment = "",
|
|
3556
|
-
mintReferral,
|
|
3557
|
-
mintRecipient,
|
|
3558
|
-
firstMinter,
|
|
3559
|
-
premintGetter,
|
|
3560
|
-
publicClient
|
|
3678
|
+
function parseAndFilterTokenQueryResult({
|
|
3679
|
+
token,
|
|
3680
|
+
tokenId,
|
|
3681
|
+
preferredSaleType,
|
|
3682
|
+
blockTime
|
|
3561
3683
|
}) {
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3684
|
+
const defaultMintFee = BigInt(token.contract.mintFeePerQuantity);
|
|
3685
|
+
const salesStrategyAndMintInfo = findTargetStrategyWithPrimaryOrSecondarySaleActive({
|
|
3686
|
+
token,
|
|
3687
|
+
tokenId,
|
|
3688
|
+
preferredSaleType,
|
|
3689
|
+
defaultMintFee,
|
|
3690
|
+
blockTime
|
|
3568
3691
|
});
|
|
3569
|
-
const
|
|
3570
|
-
|
|
3571
|
-
publicClient
|
|
3692
|
+
const tokenInfo = parseTokenInfo({
|
|
3693
|
+
token
|
|
3572
3694
|
});
|
|
3573
|
-
return
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
firstMinter,
|
|
3578
|
-
mintComment,
|
|
3579
|
-
mintRecipient,
|
|
3580
|
-
mintReferral
|
|
3695
|
+
return {
|
|
3696
|
+
salesConfigAndTokenInfo: {
|
|
3697
|
+
...tokenInfo,
|
|
3698
|
+
salesConfig: salesStrategyAndMintInfo?.strategy.salesStrategy
|
|
3581
3699
|
},
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
}
|
|
3586
|
-
var buildPremintMintCall = ({
|
|
3587
|
-
mintArguments: {
|
|
3588
|
-
minterAccount,
|
|
3589
|
-
mintComment = "",
|
|
3590
|
-
mintRecipient,
|
|
3591
|
-
mintReferral,
|
|
3592
|
-
firstMinter,
|
|
3593
|
-
quantityToMint
|
|
3594
|
-
},
|
|
3595
|
-
premint: { collection, collectionAddress, premint, signature },
|
|
3596
|
-
mintFee
|
|
3597
|
-
}) => {
|
|
3598
|
-
const mintArgumentsContract = {
|
|
3599
|
-
mintComment,
|
|
3600
|
-
mintRecipient: mintRecipientOrAccount({
|
|
3601
|
-
mintRecipient,
|
|
3602
|
-
minterAccount
|
|
3603
|
-
}),
|
|
3604
|
-
mintRewardsRecipients: makeMintRewardsRecipient({
|
|
3605
|
-
mintReferral
|
|
3606
|
-
})
|
|
3700
|
+
primaryMintActive: salesStrategyAndMintInfo?.primaryMintActive ?? false,
|
|
3701
|
+
primaryMintEnd: salesStrategyAndMintInfo?.strategy.saleEnd,
|
|
3702
|
+
secondaryMarketActive: salesStrategyAndMintInfo?.secondaryMarketActive ?? false
|
|
3607
3703
|
};
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
if (premint.premintConfigVersion === import_protocol_deployments4.PremintConfigVersion.V3) {
|
|
3612
|
-
throw new Error("PremintV3 not supported in premint SDK");
|
|
3613
|
-
}
|
|
3614
|
-
const value = (mintFee + premint.premintConfig.tokenConfig.pricePerToken) * BigInt(quantityToMint);
|
|
3615
|
-
return makeContractParameters({
|
|
3616
|
-
account: minterAccount,
|
|
3617
|
-
abi: import_protocol_deployments3.zoraCreator1155PremintExecutorImplABI,
|
|
3618
|
-
functionName: "premint",
|
|
3619
|
-
value,
|
|
3620
|
-
address: getPremintExecutorAddress(),
|
|
3621
|
-
args: [
|
|
3622
|
-
collectionOrEmpty,
|
|
3623
|
-
collectionAddressToSubmit,
|
|
3624
|
-
(0, import_protocol_deployments3.encodePremintConfig)(premint),
|
|
3625
|
-
signature,
|
|
3626
|
-
BigInt(quantityToMint),
|
|
3627
|
-
mintArgumentsContract,
|
|
3628
|
-
firstMinterToSubmit,
|
|
3629
|
-
import_viem4.zeroAddress
|
|
3630
|
-
]
|
|
3631
|
-
});
|
|
3632
|
-
};
|
|
3633
|
-
function makeUrls({
|
|
3634
|
-
uid,
|
|
3635
|
-
address,
|
|
3636
|
-
tokenId,
|
|
3637
|
-
chainId,
|
|
3638
|
-
blockExplorerUrl
|
|
3704
|
+
}
|
|
3705
|
+
function parseTokenInfo({
|
|
3706
|
+
token
|
|
3639
3707
|
}) {
|
|
3640
|
-
if ((!uid || !tokenId) && !address) {
|
|
3641
|
-
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
3642
|
-
}
|
|
3643
|
-
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
3644
|
-
const network = getApiNetworkConfigForChain(chainId);
|
|
3645
3708
|
return {
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3709
|
+
contract: {
|
|
3710
|
+
address: token.contract.address,
|
|
3711
|
+
name: token.contract.name,
|
|
3712
|
+
URI: token.contract.contractURI
|
|
3713
|
+
},
|
|
3714
|
+
tokenURI: token.uri,
|
|
3715
|
+
tokenId: token.tokenId ? BigInt(token.tokenId) : void 0,
|
|
3716
|
+
mintType: token.tokenStandard === "ERC721" ? "721" : "1155",
|
|
3717
|
+
creator: token.creator,
|
|
3718
|
+
totalMinted: BigInt(token.totalMinted),
|
|
3719
|
+
maxSupply: BigInt(token.maxSupply),
|
|
3720
|
+
contractVersion: token.contract.contractVersion
|
|
3649
3721
|
};
|
|
3650
3722
|
}
|
|
3651
3723
|
|
|
3652
|
-
// src/
|
|
3653
|
-
var
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
})(PremintConfigVersion3 || {});
|
|
3660
|
-
|
|
3661
|
-
// src/premint/premint-api-client.ts
|
|
3662
|
-
var postSignature = async ({
|
|
3663
|
-
httpClient: { post: post2, retries: retries2 } = httpClient,
|
|
3664
|
-
...data
|
|
3665
|
-
}) => retries2(
|
|
3666
|
-
() => post2(`${ZORA_API_BASE}premint/signature`, data)
|
|
3667
|
-
);
|
|
3668
|
-
var getNextUID = async ({
|
|
3669
|
-
chainId,
|
|
3670
|
-
collection_address,
|
|
3671
|
-
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3672
|
-
}) => retries2(
|
|
3673
|
-
() => get2(
|
|
3674
|
-
`${ZORA_API_BASE}premint/signature/${getApiNetworkConfigForChain(chainId).zoraBackendChainName}/${collection_address}/next_uid`
|
|
3675
|
-
)
|
|
3676
|
-
);
|
|
3677
|
-
var getSignature = async ({
|
|
3678
|
-
collectionAddress,
|
|
3679
|
-
uid,
|
|
3680
|
-
chainId,
|
|
3681
|
-
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3682
|
-
}) => {
|
|
3683
|
-
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
3684
|
-
const result = await retries2(
|
|
3685
|
-
() => get2(
|
|
3686
|
-
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}/${uid}`
|
|
3687
|
-
)
|
|
3688
|
-
);
|
|
3689
|
-
return convertGetPremintApiResponse(result);
|
|
3690
|
-
};
|
|
3691
|
-
var getOfCollection = async ({
|
|
3692
|
-
collectionAddress,
|
|
3693
|
-
chainId,
|
|
3694
|
-
httpClient: { retries: retries2, get: get2 } = httpClient
|
|
3695
|
-
}) => {
|
|
3696
|
-
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
3697
|
-
const result = await retries2(
|
|
3698
|
-
() => get2(
|
|
3699
|
-
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}`
|
|
3700
|
-
)
|
|
3701
|
-
);
|
|
3702
|
-
return convertGetPremintOfCollectionApiResponse(result);
|
|
3703
|
-
};
|
|
3704
|
-
var PremintAPIClient = class {
|
|
3705
|
-
constructor(chainId, httpClient2) {
|
|
3706
|
-
this.postSignature = ({
|
|
3707
|
-
signature,
|
|
3708
|
-
...rest
|
|
3709
|
-
}) => {
|
|
3710
|
-
const data = encodePostSignatureInput({
|
|
3711
|
-
...rest,
|
|
3712
|
-
chainId: this.chainId,
|
|
3713
|
-
signature
|
|
3714
|
-
});
|
|
3715
|
-
return postSignature({
|
|
3716
|
-
...data,
|
|
3717
|
-
httpClient: this.httpClient
|
|
3718
|
-
});
|
|
3719
|
-
};
|
|
3720
|
-
this.getNextUID = async (collectionAddress) => (await getNextUID({
|
|
3721
|
-
collection_address: collectionAddress.toLowerCase(),
|
|
3722
|
-
chainId: this.chainId,
|
|
3723
|
-
httpClient: this.httpClient
|
|
3724
|
-
})).next_uid;
|
|
3725
|
-
this.get = async ({ collectionAddress, uid }) => {
|
|
3726
|
-
return getSignature({
|
|
3727
|
-
collectionAddress,
|
|
3728
|
-
uid,
|
|
3729
|
-
chainId: this.chainId,
|
|
3730
|
-
httpClient: this.httpClient
|
|
3731
|
-
});
|
|
3732
|
-
};
|
|
3733
|
-
this.getOfCollection = async ({
|
|
3734
|
-
collectionAddress
|
|
3724
|
+
// src/mint/subgraph-mint-getter.ts
|
|
3725
|
+
var SubgraphMintGetter = class extends SubgraphGetter {
|
|
3726
|
+
constructor(chainId, subgraphQuerier) {
|
|
3727
|
+
super(chainId, subgraphQuerier);
|
|
3728
|
+
this.getMintable = async ({
|
|
3729
|
+
tokenAddress,
|
|
3730
|
+
tokenId
|
|
3735
3731
|
}) => {
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3732
|
+
const token = await this.querySubgraphWithRetries(
|
|
3733
|
+
buildNftTokenSalesQuery({
|
|
3734
|
+
tokenId,
|
|
3735
|
+
tokenAddress
|
|
3736
|
+
})
|
|
3737
|
+
);
|
|
3738
|
+
if (!token) {
|
|
3739
|
+
throw new Error("Cannot find token");
|
|
3740
|
+
}
|
|
3741
|
+
return token;
|
|
3741
3742
|
};
|
|
3742
|
-
|
|
3743
|
-
|
|
3743
|
+
}
|
|
3744
|
+
async getContractMintable({
|
|
3745
|
+
tokenAddress,
|
|
3746
|
+
preferredSaleType,
|
|
3747
|
+
blockTime
|
|
3748
|
+
}) {
|
|
3749
|
+
const tokens = await this.querySubgraphWithRetries(
|
|
3750
|
+
buildContractTokensQuery({
|
|
3751
|
+
tokenAddress
|
|
3752
|
+
})
|
|
3753
|
+
);
|
|
3754
|
+
if (!tokens || tokens.length === 0)
|
|
3755
|
+
return [];
|
|
3756
|
+
return tokens.filter((x) => x.tokenId !== "0").map(
|
|
3757
|
+
(token) => parseAndFilterTokenQueryResult({
|
|
3758
|
+
token,
|
|
3759
|
+
tokenId: token.tokenId,
|
|
3760
|
+
preferredSaleType,
|
|
3761
|
+
blockTime
|
|
3762
|
+
})
|
|
3763
|
+
);
|
|
3764
|
+
}
|
|
3765
|
+
async getContractPremintTokenIds({
|
|
3766
|
+
tokenAddress
|
|
3767
|
+
}) {
|
|
3768
|
+
const premints = await this.querySubgraphWithRetries(
|
|
3769
|
+
buildPremintsOfContractQuery({
|
|
3770
|
+
tokenAddress
|
|
3771
|
+
})
|
|
3772
|
+
);
|
|
3773
|
+
return premints?.map((premint) => ({
|
|
3774
|
+
tokenId: BigInt(premint.tokenId),
|
|
3775
|
+
uid: +premint.uid
|
|
3776
|
+
})) || [];
|
|
3744
3777
|
}
|
|
3745
3778
|
};
|
|
3746
3779
|
|
|
@@ -4035,32 +4068,33 @@ function parseMintCosts({
|
|
|
4035
4068
|
}
|
|
4036
4069
|
|
|
4037
4070
|
// src/mint/mint-queries.ts
|
|
4038
|
-
async function
|
|
4039
|
-
params
|
|
4040
|
-
|
|
4041
|
-
premintGetter,
|
|
4042
|
-
publicClient,
|
|
4043
|
-
chainId
|
|
4044
|
-
}) {
|
|
4045
|
-
const { tokenContract } = params;
|
|
4071
|
+
async function getToken(params) {
|
|
4072
|
+
const { premintGetter, publicClient } = params;
|
|
4073
|
+
const chainId = publicClient.chain.id;
|
|
4046
4074
|
if (isOnChainMint(params)) {
|
|
4047
4075
|
const tokenId = is1155Mint(params) ? params.tokenId : void 0;
|
|
4048
4076
|
const blockTime = (await publicClient.getBlock()).timestamp;
|
|
4049
|
-
const
|
|
4077
|
+
const mintGetterOrDefault = params.mintGetter ?? new SubgraphMintGetter(chainId);
|
|
4078
|
+
const result = await mintGetterOrDefault.getMintable({
|
|
4079
|
+
tokenId,
|
|
4080
|
+
tokenAddress: params.tokenContract
|
|
4081
|
+
});
|
|
4082
|
+
const token = parseAndFilterTokenQueryResult({
|
|
4083
|
+
token: result,
|
|
4050
4084
|
tokenId,
|
|
4051
|
-
tokenAddress: tokenContract,
|
|
4052
4085
|
preferredSaleType: params.preferredSaleType,
|
|
4053
4086
|
blockTime
|
|
4054
4087
|
});
|
|
4055
|
-
return toMintableReturn(
|
|
4088
|
+
return toMintableReturn(token, chainId);
|
|
4056
4089
|
}
|
|
4057
|
-
const
|
|
4058
|
-
|
|
4090
|
+
const premintGetterOrDefault = premintGetter ?? new PremintAPIClient(chainId);
|
|
4091
|
+
const premint = await premintGetterOrDefault.get({
|
|
4092
|
+
collectionAddress: params.tokenContract,
|
|
4059
4093
|
uid: params.uid
|
|
4060
4094
|
});
|
|
4061
4095
|
const mintFee = await getPremintMintFee({
|
|
4062
4096
|
publicClient,
|
|
4063
|
-
tokenContract
|
|
4097
|
+
tokenContract: params.tokenContract
|
|
4064
4098
|
});
|
|
4065
4099
|
return toPremintMintReturn({ premint, mintFee });
|
|
4066
4100
|
}
|
|
@@ -4086,19 +4120,20 @@ async function getPremintsOfCollectionWithTokenIds({
|
|
|
4086
4120
|
premints: premintsWithTokenId
|
|
4087
4121
|
};
|
|
4088
4122
|
}
|
|
4089
|
-
async function
|
|
4090
|
-
params,
|
|
4123
|
+
async function getTokensOfContract({
|
|
4091
4124
|
mintGetter,
|
|
4092
4125
|
premintGetter,
|
|
4093
4126
|
publicClient,
|
|
4094
|
-
|
|
4127
|
+
...params
|
|
4095
4128
|
}) {
|
|
4096
|
-
const
|
|
4129
|
+
const chainId = publicClient.chain.id;
|
|
4130
|
+
const mintGetterOrDefault = mintGetter ?? new SubgraphMintGetter(chainId);
|
|
4131
|
+
const onchainMints = (await mintGetterOrDefault.getContractMintable({
|
|
4097
4132
|
tokenAddress: params.tokenContract
|
|
4098
4133
|
})).map((result) => toMintableReturn(result, chainId));
|
|
4099
4134
|
const offchainMints = await getPremintsOfContractMintable({
|
|
4100
|
-
mintGetter,
|
|
4101
|
-
premintGetter,
|
|
4135
|
+
mintGetter: mintGetterOrDefault,
|
|
4136
|
+
premintGetter: premintGetter ?? new PremintAPIClient(chainId),
|
|
4102
4137
|
publicClient,
|
|
4103
4138
|
params: {
|
|
4104
4139
|
tokenContract: params.tokenContract
|
|
@@ -4121,16 +4156,20 @@ async function getMintCosts({
|
|
|
4121
4156
|
if (isOnChainMint(params)) {
|
|
4122
4157
|
const tokenId = is1155Mint(params) ? params.tokenId : void 0;
|
|
4123
4158
|
const blockTime = (await publicClient.getBlock()).timestamp;
|
|
4124
|
-
const
|
|
4159
|
+
const result = await mintGetter.getMintable({
|
|
4160
|
+
tokenId,
|
|
4161
|
+
tokenAddress: collection
|
|
4162
|
+
});
|
|
4163
|
+
const token = parseAndFilterTokenQueryResult({
|
|
4164
|
+
token: result,
|
|
4125
4165
|
tokenId,
|
|
4126
|
-
tokenAddress: collection,
|
|
4127
4166
|
blockTime
|
|
4128
4167
|
});
|
|
4129
|
-
if (!salesConfigAndTokenInfo.salesConfig) {
|
|
4168
|
+
if (!token.salesConfigAndTokenInfo.salesConfig) {
|
|
4130
4169
|
throw new Error("No valid sales config found for token");
|
|
4131
4170
|
}
|
|
4132
4171
|
return parseMintCosts({
|
|
4133
|
-
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
4172
|
+
salesConfig: token.salesConfigAndTokenInfo.salesConfig,
|
|
4134
4173
|
quantityToMint: BigInt(quantityToMint),
|
|
4135
4174
|
allowListEntry
|
|
4136
4175
|
});
|
|
@@ -4180,7 +4219,7 @@ async function getPremintsOfContractMintable({
|
|
|
4180
4219
|
});
|
|
4181
4220
|
});
|
|
4182
4221
|
}
|
|
4183
|
-
function
|
|
4222
|
+
function isPrimaryMintActive2(premint) {
|
|
4184
4223
|
const currentTime = (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
4185
4224
|
return premint.premintConfig.tokenConfig.mintStart < currentTime;
|
|
4186
4225
|
}
|
|
@@ -4273,7 +4312,7 @@ function toPremintMintReturn({
|
|
|
4273
4312
|
mintFee
|
|
4274
4313
|
}) {
|
|
4275
4314
|
const mintable = parsePremint({ premint, mintFee });
|
|
4276
|
-
const primaryMintActive =
|
|
4315
|
+
const primaryMintActive = isPrimaryMintActive2(premint.premint);
|
|
4277
4316
|
if (!primaryMintActive) {
|
|
4278
4317
|
return {
|
|
4279
4318
|
token: mintable,
|
|
@@ -4312,13 +4351,11 @@ var MintClient = class {
|
|
|
4312
4351
|
constructor({
|
|
4313
4352
|
publicClient,
|
|
4314
4353
|
premintGetter,
|
|
4315
|
-
mintGetter
|
|
4316
|
-
chainId
|
|
4354
|
+
mintGetter
|
|
4317
4355
|
}) {
|
|
4318
4356
|
this.publicClient = publicClient;
|
|
4319
4357
|
this.mintGetter = mintGetter;
|
|
4320
4358
|
this.premintGetter = premintGetter;
|
|
4321
|
-
this.chainId = chainId;
|
|
4322
4359
|
}
|
|
4323
4360
|
/**
|
|
4324
4361
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
@@ -4329,26 +4366,24 @@ var MintClient = class {
|
|
|
4329
4366
|
*/
|
|
4330
4367
|
async mint(parameters) {
|
|
4331
4368
|
return mint({
|
|
4332
|
-
parameters,
|
|
4369
|
+
...parameters,
|
|
4333
4370
|
publicClient: this.publicClient,
|
|
4334
4371
|
mintGetter: this.mintGetter,
|
|
4335
|
-
premintGetter: this.premintGetter
|
|
4336
|
-
chainId: this.chainId
|
|
4372
|
+
premintGetter: this.premintGetter
|
|
4337
4373
|
});
|
|
4338
4374
|
}
|
|
4339
4375
|
/**
|
|
4340
4376
|
* Gets an 1155, 721, or premint, and returns both information about it, and a function
|
|
4341
4377
|
* that can be used to build a mint transaction for a quantity of items to mint.
|
|
4342
|
-
* @param parameters - Token to get {@link
|
|
4378
|
+
* @param parameters - Token to get {@link GetMintParametersArguments}
|
|
4343
4379
|
* @Returns Information about the mint and a function to build a mint transaction {@link MintableReturn}
|
|
4344
4380
|
*/
|
|
4345
4381
|
async get(parameters) {
|
|
4346
|
-
return
|
|
4347
|
-
|
|
4382
|
+
return getToken({
|
|
4383
|
+
...parameters,
|
|
4348
4384
|
mintGetter: this.mintGetter,
|
|
4349
4385
|
premintGetter: this.premintGetter,
|
|
4350
|
-
publicClient: this.publicClient
|
|
4351
|
-
chainId: this.chainId
|
|
4386
|
+
publicClient: this.publicClient
|
|
4352
4387
|
});
|
|
4353
4388
|
}
|
|
4354
4389
|
/**
|
|
@@ -4358,17 +4393,16 @@ var MintClient = class {
|
|
|
4358
4393
|
* @Returns Array of tokens, each containing information about the token and a function to build a mint transaction.
|
|
4359
4394
|
*/
|
|
4360
4395
|
async getOfContract(params) {
|
|
4361
|
-
return
|
|
4362
|
-
params,
|
|
4396
|
+
return getTokensOfContract({
|
|
4397
|
+
...params,
|
|
4363
4398
|
mintGetter: this.mintGetter,
|
|
4364
4399
|
premintGetter: this.premintGetter,
|
|
4365
|
-
publicClient: this.publicClient
|
|
4366
|
-
chainId: this.chainId
|
|
4400
|
+
publicClient: this.publicClient
|
|
4367
4401
|
});
|
|
4368
4402
|
}
|
|
4369
4403
|
/**
|
|
4370
4404
|
* Gets the costs to mint the quantity of tokens specified for a mint.
|
|
4371
|
-
* @param parameters - Parameters for the mint {@link
|
|
4405
|
+
* @param parameters - Parameters for the mint {@link GetMintCostsParameterArguments}
|
|
4372
4406
|
* @returns Costs to mint the quantity of tokens specified
|
|
4373
4407
|
*/
|
|
4374
4408
|
async getMintCosts(parameters) {
|
|
@@ -4381,18 +4415,16 @@ var MintClient = class {
|
|
|
4381
4415
|
}
|
|
4382
4416
|
};
|
|
4383
4417
|
async function mint({
|
|
4384
|
-
parameters,
|
|
4385
4418
|
publicClient,
|
|
4386
4419
|
mintGetter,
|
|
4387
4420
|
premintGetter,
|
|
4388
|
-
|
|
4421
|
+
...parameters
|
|
4389
4422
|
}) {
|
|
4390
|
-
const { prepareMint, primaryMintActive } = await
|
|
4391
|
-
|
|
4423
|
+
const { prepareMint, primaryMintActive } = await getToken({
|
|
4424
|
+
...parameters,
|
|
4392
4425
|
mintGetter,
|
|
4393
4426
|
premintGetter,
|
|
4394
|
-
publicClient
|
|
4395
|
-
chainId
|
|
4427
|
+
publicClient
|
|
4396
4428
|
});
|
|
4397
4429
|
if (!primaryMintActive) {
|
|
4398
4430
|
throw new Error("Primary mint is not active");
|
|
@@ -4407,7 +4439,7 @@ async function mint({
|
|
|
4407
4439
|
});
|
|
4408
4440
|
}
|
|
4409
4441
|
|
|
4410
|
-
// src/create/
|
|
4442
|
+
// src/create/create-client.ts
|
|
4411
4443
|
var import_protocol_deployments10 = require("@zoralabs/protocol-deployments");
|
|
4412
4444
|
var import_viem11 = require("viem");
|
|
4413
4445
|
|
|
@@ -4424,9 +4456,9 @@ async function getDeterministicContractAddress({
|
|
|
4424
4456
|
publicClient,
|
|
4425
4457
|
account,
|
|
4426
4458
|
setupActions,
|
|
4427
|
-
contract
|
|
4428
|
-
chainId
|
|
4459
|
+
contract
|
|
4429
4460
|
}) {
|
|
4461
|
+
const chainId = publicClient.chain.id;
|
|
4430
4462
|
const contractAddress = await publicClient.readContract({
|
|
4431
4463
|
abi: import_protocol_deployments7.zoraCreator1155FactoryImplABI,
|
|
4432
4464
|
address: import_protocol_deployments7.zoraCreator1155FactoryImplAddress[chainId],
|
|
@@ -4966,7 +4998,65 @@ function makeOnchainPrepareMintFromCreate({
|
|
|
4966
4998
|
};
|
|
4967
4999
|
}
|
|
4968
5000
|
|
|
4969
|
-
// src/create/
|
|
5001
|
+
// src/create/subgraph-queries.ts
|
|
5002
|
+
function buildContractInfoQuery({
|
|
5003
|
+
contractAddress
|
|
5004
|
+
}) {
|
|
5005
|
+
return {
|
|
5006
|
+
query: `
|
|
5007
|
+
query ($contractAddress: Bytes!) {
|
|
5008
|
+
zoraCreateContract(id: $contractAddress) {
|
|
5009
|
+
contractVersion
|
|
5010
|
+
name
|
|
5011
|
+
mintFeePerQuantity
|
|
5012
|
+
tokens(first: 1, orderBy: tokenId, orderDirection: desc) {
|
|
5013
|
+
tokenId
|
|
5014
|
+
}
|
|
5015
|
+
}
|
|
5016
|
+
}
|
|
5017
|
+
`,
|
|
5018
|
+
variables: {
|
|
5019
|
+
contractAddress: contractAddress.toLowerCase()
|
|
5020
|
+
},
|
|
5021
|
+
parseResponseData: (responseData) => responseData.zoraCreateContract
|
|
5022
|
+
};
|
|
5023
|
+
}
|
|
5024
|
+
|
|
5025
|
+
// src/create/contract-getter.ts
|
|
5026
|
+
var SubgraphContractGetter = class extends SubgraphGetter {
|
|
5027
|
+
constructor(chainId, subgraphQuerier) {
|
|
5028
|
+
super(chainId, subgraphQuerier);
|
|
5029
|
+
}
|
|
5030
|
+
async getContractInfo({
|
|
5031
|
+
contractAddress,
|
|
5032
|
+
retries: retries2 = 1
|
|
5033
|
+
}) {
|
|
5034
|
+
const tryFn = async () => {
|
|
5035
|
+
const responseData2 = await this.querySubgraphWithRetries(
|
|
5036
|
+
buildContractInfoQuery({ contractAddress })
|
|
5037
|
+
);
|
|
5038
|
+
if (!responseData2) {
|
|
5039
|
+
console.log("could not find contract");
|
|
5040
|
+
throw new Error("Cannot find contract");
|
|
5041
|
+
}
|
|
5042
|
+
return responseData2;
|
|
5043
|
+
};
|
|
5044
|
+
const responseData = await retriesGeneric({
|
|
5045
|
+
tryFn,
|
|
5046
|
+
maxTries: retries2,
|
|
5047
|
+
linearBackoffMS: 1e3
|
|
5048
|
+
});
|
|
5049
|
+
const nextTokenId = responseData.tokens.length === 0 ? 1n : BigInt(responseData.tokens[0].tokenId) + 1n;
|
|
5050
|
+
return {
|
|
5051
|
+
name: responseData.name,
|
|
5052
|
+
contractVersion: responseData.contractVersion,
|
|
5053
|
+
mintFee: BigInt(responseData.mintFeePerQuantity),
|
|
5054
|
+
nextTokenId
|
|
5055
|
+
};
|
|
5056
|
+
}
|
|
5057
|
+
};
|
|
5058
|
+
|
|
5059
|
+
// src/create/create-client.ts
|
|
4970
5060
|
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
4971
5061
|
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
4972
5062
|
for (const data of receipt.logs) {
|
|
@@ -5047,19 +5137,16 @@ function makeCreateTokenCall({
|
|
|
5047
5137
|
}
|
|
5048
5138
|
var Create1155Client = class {
|
|
5049
5139
|
constructor({
|
|
5050
|
-
chainId,
|
|
5051
5140
|
publicClient,
|
|
5052
5141
|
contractGetter
|
|
5053
5142
|
}) {
|
|
5054
|
-
this.chainId = chainId;
|
|
5055
5143
|
this.publicClient = publicClient;
|
|
5056
5144
|
this.contractGetter = contractGetter;
|
|
5057
5145
|
}
|
|
5058
5146
|
async createNew1155(props) {
|
|
5059
|
-
return
|
|
5147
|
+
return create1155({
|
|
5060
5148
|
...props,
|
|
5061
|
-
publicClient: this.publicClient
|
|
5062
|
-
chainId: this.chainId
|
|
5149
|
+
publicClient: this.publicClient
|
|
5063
5150
|
});
|
|
5064
5151
|
}
|
|
5065
5152
|
async createNew1155OnExistingContract({
|
|
@@ -5073,83 +5160,100 @@ var Create1155Client = class {
|
|
|
5073
5160
|
account,
|
|
5074
5161
|
token,
|
|
5075
5162
|
getAdditionalSetupActions,
|
|
5076
|
-
|
|
5077
|
-
chainId: this.
|
|
5078
|
-
contractGetter: this.contractGetter
|
|
5163
|
+
contractGetter: this.contractGetter,
|
|
5164
|
+
chainId: this.publicClient.chain.id
|
|
5079
5165
|
});
|
|
5080
5166
|
}
|
|
5081
5167
|
};
|
|
5082
|
-
async function
|
|
5168
|
+
async function create1155({
|
|
5083
5169
|
contract,
|
|
5084
5170
|
account,
|
|
5085
|
-
chainId,
|
|
5086
5171
|
token,
|
|
5087
5172
|
publicClient,
|
|
5088
5173
|
getAdditionalSetupActions
|
|
5089
5174
|
}) {
|
|
5090
5175
|
const nextTokenId = 1n;
|
|
5176
|
+
const chainId = publicClient.chain.id;
|
|
5091
5177
|
const contractVersion = new1155ContractVersion(chainId);
|
|
5092
|
-
const {
|
|
5093
|
-
minter,
|
|
5094
|
-
newToken,
|
|
5095
|
-
setupActions: tokenSetupActions
|
|
5096
|
-
} = prepareSetupActions({
|
|
5097
|
-
chainId,
|
|
5098
|
-
account,
|
|
5099
|
-
contractVersion,
|
|
5100
|
-
nextTokenId,
|
|
5101
|
-
token,
|
|
5102
|
-
getAdditionalSetupActions,
|
|
5103
|
-
contractName: contract.name
|
|
5104
|
-
});
|
|
5105
|
-
const request = makeCreateContractAndTokenCall({
|
|
5178
|
+
const result = prepareNew1155ContractAndToken({
|
|
5106
5179
|
contract,
|
|
5107
5180
|
account,
|
|
5108
5181
|
chainId,
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5182
|
+
token,
|
|
5183
|
+
getAdditionalSetupActions,
|
|
5184
|
+
nextTokenId,
|
|
5185
|
+
contractVersion
|
|
5112
5186
|
});
|
|
5113
5187
|
const contractAddress = await getDeterministicContractAddress({
|
|
5114
5188
|
account: typeof account === "string" ? account : account.address,
|
|
5115
5189
|
publicClient,
|
|
5116
|
-
setupActions:
|
|
5117
|
-
chainId,
|
|
5190
|
+
setupActions: result.setupActions,
|
|
5118
5191
|
contract
|
|
5119
5192
|
});
|
|
5120
5193
|
const prepareMint = makeOnchainPrepareMintFromCreate({
|
|
5121
5194
|
contractAddress,
|
|
5122
5195
|
contractVersion,
|
|
5123
|
-
minter,
|
|
5124
|
-
result: newToken.salesConfig,
|
|
5196
|
+
minter: result.minter,
|
|
5197
|
+
result: result.newToken.salesConfig,
|
|
5125
5198
|
tokenId: nextTokenId,
|
|
5199
|
+
chainId,
|
|
5126
5200
|
// to get the contract wide mint fee, we get what it would be for a new contract
|
|
5127
5201
|
getContractMintFee: async () => getNewContractMintFee({
|
|
5128
5202
|
publicClient,
|
|
5129
5203
|
chainId
|
|
5130
|
-
})
|
|
5131
|
-
chainId
|
|
5204
|
+
})
|
|
5132
5205
|
});
|
|
5133
5206
|
return {
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
newTokenId: nextTokenId,
|
|
5137
|
-
newToken,
|
|
5207
|
+
...result,
|
|
5208
|
+
prepareMint,
|
|
5138
5209
|
contractAddress,
|
|
5139
5210
|
contractVersion,
|
|
5140
|
-
|
|
5141
|
-
prepareMint
|
|
5211
|
+
newTokenId: nextTokenId
|
|
5142
5212
|
};
|
|
5143
5213
|
}
|
|
5144
|
-
|
|
5214
|
+
function prepareNew1155ContractAndToken({
|
|
5215
|
+
account,
|
|
5216
|
+
chainId,
|
|
5217
|
+
token,
|
|
5218
|
+
getAdditionalSetupActions,
|
|
5219
|
+
nextTokenId,
|
|
5220
|
+
contractVersion,
|
|
5221
|
+
contract
|
|
5222
|
+
}) {
|
|
5223
|
+
const { minter, newToken, setupActions } = prepareSetupActions({
|
|
5224
|
+
chainId,
|
|
5225
|
+
account,
|
|
5226
|
+
contractVersion,
|
|
5227
|
+
nextTokenId,
|
|
5228
|
+
token,
|
|
5229
|
+
getAdditionalSetupActions,
|
|
5230
|
+
contractName: contract.name
|
|
5231
|
+
});
|
|
5232
|
+
const request = makeCreateContractAndTokenCall({
|
|
5233
|
+
contract,
|
|
5234
|
+
account,
|
|
5235
|
+
chainId,
|
|
5236
|
+
tokenSetupActions: setupActions,
|
|
5237
|
+
fundsRecipient: token.payoutRecipient,
|
|
5238
|
+
royaltyBPS: token.royaltyBPS
|
|
5239
|
+
});
|
|
5240
|
+
return {
|
|
5241
|
+
parameters: request,
|
|
5242
|
+
setupActions,
|
|
5243
|
+
newToken,
|
|
5244
|
+
minter
|
|
5245
|
+
};
|
|
5246
|
+
}
|
|
5247
|
+
function prepareNew1155Token({
|
|
5145
5248
|
contractAddress,
|
|
5146
5249
|
account,
|
|
5147
5250
|
getAdditionalSetupActions,
|
|
5148
5251
|
token,
|
|
5149
5252
|
chainId,
|
|
5150
|
-
|
|
5253
|
+
nextTokenId,
|
|
5254
|
+
contractVersion,
|
|
5255
|
+
contractName
|
|
5151
5256
|
}) {
|
|
5152
|
-
const { nextTokenId, contractVersion, mintFee, name } = await contractGetter.getContractInfo({ contractAddress, retries: 5 });
|
|
5153
5257
|
const {
|
|
5154
5258
|
minter,
|
|
5155
5259
|
newToken,
|
|
@@ -5161,30 +5265,57 @@ async function createNew1155Token({
|
|
|
5161
5265
|
nextTokenId,
|
|
5162
5266
|
token,
|
|
5163
5267
|
getAdditionalSetupActions,
|
|
5164
|
-
contractName
|
|
5268
|
+
contractName
|
|
5165
5269
|
});
|
|
5166
5270
|
const request = makeCreateTokenCall({
|
|
5167
5271
|
contractAddress,
|
|
5168
5272
|
account,
|
|
5169
5273
|
tokenSetupActions
|
|
5170
5274
|
});
|
|
5275
|
+
return {
|
|
5276
|
+
parameters: request,
|
|
5277
|
+
setupActions: tokenSetupActions,
|
|
5278
|
+
newToken,
|
|
5279
|
+
minter
|
|
5280
|
+
};
|
|
5281
|
+
}
|
|
5282
|
+
async function createNew1155Token({
|
|
5283
|
+
contractAddress,
|
|
5284
|
+
account,
|
|
5285
|
+
getAdditionalSetupActions,
|
|
5286
|
+
token,
|
|
5287
|
+
chainId,
|
|
5288
|
+
contractGetter
|
|
5289
|
+
}) {
|
|
5290
|
+
const contractGetterOrDefault = contractGetter ?? new SubgraphContractGetter(chainId);
|
|
5291
|
+
const { nextTokenId, contractVersion, mintFee, name } = await contractGetterOrDefault.getContractInfo({
|
|
5292
|
+
contractAddress,
|
|
5293
|
+
retries: 5
|
|
5294
|
+
});
|
|
5295
|
+
const preparedToken = prepareNew1155Token({
|
|
5296
|
+
contractAddress,
|
|
5297
|
+
account,
|
|
5298
|
+
getAdditionalSetupActions,
|
|
5299
|
+
token,
|
|
5300
|
+
chainId,
|
|
5301
|
+
nextTokenId,
|
|
5302
|
+
contractVersion,
|
|
5303
|
+
contractName: name
|
|
5304
|
+
});
|
|
5171
5305
|
const prepareMint = makeOnchainPrepareMintFromCreate({
|
|
5172
5306
|
contractAddress,
|
|
5173
5307
|
contractVersion,
|
|
5174
|
-
minter,
|
|
5175
|
-
result: newToken.salesConfig,
|
|
5308
|
+
minter: preparedToken.minter,
|
|
5309
|
+
result: preparedToken.newToken.salesConfig,
|
|
5176
5310
|
tokenId: nextTokenId,
|
|
5177
5311
|
getContractMintFee: async () => mintFee,
|
|
5178
5312
|
chainId
|
|
5179
5313
|
});
|
|
5180
5314
|
return {
|
|
5181
|
-
|
|
5182
|
-
|
|
5315
|
+
...preparedToken,
|
|
5316
|
+
prepareMint,
|
|
5183
5317
|
newTokenId: nextTokenId,
|
|
5184
|
-
|
|
5185
|
-
contractVersion,
|
|
5186
|
-
minter,
|
|
5187
|
-
prepareMint
|
|
5318
|
+
contractVersion
|
|
5188
5319
|
};
|
|
5189
5320
|
}
|
|
5190
5321
|
function prepareSetupActions({
|
|
@@ -5504,80 +5635,72 @@ function decodeCallFailedError(error) {
|
|
|
5504
5635
|
});
|
|
5505
5636
|
}
|
|
5506
5637
|
|
|
5507
|
-
// src/
|
|
5508
|
-
|
|
5509
|
-
|
|
5638
|
+
// src/rewards/rewards-queries.ts
|
|
5639
|
+
var import_protocol_deployments12 = require("@zoralabs/protocol-deployments");
|
|
5640
|
+
var import_viem13 = require("viem");
|
|
5641
|
+
|
|
5642
|
+
// src/apis/multicall3.ts
|
|
5643
|
+
var multicall3Abi = [
|
|
5644
|
+
"struct Call { address target; bytes callData; }",
|
|
5645
|
+
"struct Call3 { address target; bool allowFailure; bytes callData; }",
|
|
5646
|
+
"struct Call3Value { address target; bool allowFailure; uint256 value; bytes callData; }",
|
|
5647
|
+
"struct Result { bool success; bytes returnData; }",
|
|
5648
|
+
"function aggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes[] memory returnData)",
|
|
5649
|
+
"function aggregate3(Call3[] calldata calls) public payable returns (Result[] memory returnData)",
|
|
5650
|
+
"function aggregate3Value(Call3Value[] calldata calls) public payable returns (Result[] memory returnData)"
|
|
5651
|
+
];
|
|
5652
|
+
var multicall3Address = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
5653
|
+
|
|
5654
|
+
// src/rewards/subgraph-queries.ts
|
|
5655
|
+
function buildCreatorERC20zs({
|
|
5656
|
+
address
|
|
5510
5657
|
}) {
|
|
5511
5658
|
return {
|
|
5512
5659
|
query: `
|
|
5513
|
-
query ($
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5660
|
+
query ($address: Bytes!) {
|
|
5661
|
+
zoraCreateTokens(
|
|
5662
|
+
where: { royalties_: { royaltyRecipient: $address }, salesStrategies_: { type: "ZORA_TIMED" } }
|
|
5663
|
+
) {
|
|
5664
|
+
royalties {
|
|
5665
|
+
user
|
|
5666
|
+
}
|
|
5667
|
+
salesStrategies {
|
|
5668
|
+
zoraTimedMinter {
|
|
5669
|
+
erc20Z {
|
|
5670
|
+
id
|
|
5671
|
+
}
|
|
5672
|
+
}
|
|
5520
5673
|
}
|
|
5521
5674
|
}
|
|
5522
5675
|
}
|
|
5523
5676
|
`,
|
|
5524
|
-
variables: {
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5677
|
+
variables: { address },
|
|
5678
|
+
parseResponseData: (responseData) => {
|
|
5679
|
+
return responseData?.zoraCreateTokens;
|
|
5680
|
+
}
|
|
5528
5681
|
};
|
|
5529
5682
|
}
|
|
5530
5683
|
|
|
5531
|
-
// src/
|
|
5532
|
-
var
|
|
5684
|
+
// src/rewards/subgraph-rewards-getter.ts
|
|
5685
|
+
var SubgraphRewardsGetter = class extends SubgraphGetter {
|
|
5533
5686
|
constructor(chainId, subgraphQuerier) {
|
|
5534
5687
|
super(chainId, subgraphQuerier);
|
|
5535
5688
|
}
|
|
5536
|
-
async
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
const
|
|
5541
|
-
const
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
if (!responseData2) {
|
|
5545
|
-
console.log("could not find contract");
|
|
5546
|
-
throw new Error("Cannot find contract");
|
|
5689
|
+
async getErc20ZzForCreator({ address }) {
|
|
5690
|
+
const queryResults = await this.querySubgraphWithRetries(
|
|
5691
|
+
buildCreatorERC20zs({ address })
|
|
5692
|
+
);
|
|
5693
|
+
const results = (queryResults?.map((result) => {
|
|
5694
|
+
const timedMinter = result.salesStrategies[0].zoraTimedMinter;
|
|
5695
|
+
if (!timedMinter) {
|
|
5696
|
+
return null;
|
|
5547
5697
|
}
|
|
5548
|
-
return
|
|
5549
|
-
};
|
|
5550
|
-
|
|
5551
|
-
tryFn,
|
|
5552
|
-
maxTries: retries2,
|
|
5553
|
-
linearBackoffMS: 1e3
|
|
5554
|
-
});
|
|
5555
|
-
const nextTokenId = responseData.tokens.length === 0 ? 1n : BigInt(responseData.tokens[0].tokenId) + 1n;
|
|
5556
|
-
return {
|
|
5557
|
-
name: responseData.name,
|
|
5558
|
-
contractVersion: responseData.contractVersion,
|
|
5559
|
-
mintFee: BigInt(responseData.mintFeePerQuantity),
|
|
5560
|
-
nextTokenId
|
|
5561
|
-
};
|
|
5698
|
+
return timedMinter.erc20Z.id;
|
|
5699
|
+
}) || []).filter((id) => !!id);
|
|
5700
|
+
return results;
|
|
5562
5701
|
}
|
|
5563
5702
|
};
|
|
5564
5703
|
|
|
5565
|
-
// src/rewards/rewards-queries.ts
|
|
5566
|
-
var import_protocol_deployments12 = require("@zoralabs/protocol-deployments");
|
|
5567
|
-
var import_viem13 = require("viem");
|
|
5568
|
-
|
|
5569
|
-
// src/apis/multicall3.ts
|
|
5570
|
-
var multicall3Abi = [
|
|
5571
|
-
"struct Call { address target; bytes callData; }",
|
|
5572
|
-
"struct Call3 { address target; bool allowFailure; bytes callData; }",
|
|
5573
|
-
"struct Call3Value { address target; bool allowFailure; uint256 value; bytes callData; }",
|
|
5574
|
-
"struct Result { bool success; bytes returnData; }",
|
|
5575
|
-
"function aggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes[] memory returnData)",
|
|
5576
|
-
"function aggregate3(Call3[] calldata calls) public payable returns (Result[] memory returnData)",
|
|
5577
|
-
"function aggregate3Value(Call3Value[] calldata calls) public payable returns (Result[] memory returnData)"
|
|
5578
|
-
];
|
|
5579
|
-
var multicall3Address = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
5580
|
-
|
|
5581
5704
|
// src/rewards/rewards-queries.ts
|
|
5582
5705
|
function aggregateUnclaimedFees(unclaimedFees, wethAddress2) {
|
|
5583
5706
|
let ethBalance = 0n;
|
|
@@ -5604,21 +5727,47 @@ function aggregateUnclaimedFees(unclaimedFees, wethAddress2) {
|
|
|
5604
5727
|
erc20: unclaimedFeesAggregate
|
|
5605
5728
|
};
|
|
5606
5729
|
}
|
|
5607
|
-
var
|
|
5730
|
+
var getErc20zsWithPositions = async ({
|
|
5731
|
+
address,
|
|
5732
|
+
publicClient,
|
|
5733
|
+
rewardsGetter
|
|
5734
|
+
}) => {
|
|
5735
|
+
const chainId = publicClient.chain.id;
|
|
5736
|
+
const rewardsGetterOrDefault = rewardsGetter ?? new SubgraphRewardsGetter(chainId);
|
|
5737
|
+
const erc20zsForCreator = await rewardsGetterOrDefault.getErc20ZzForCreator({
|
|
5738
|
+
address
|
|
5739
|
+
});
|
|
5740
|
+
const royaltiesAddress = import_protocol_deployments12.erc20ZRoyaltiesAddress[chainId];
|
|
5741
|
+
const positionsByErc20z = await publicClient.multicall({
|
|
5742
|
+
contracts: erc20zsForCreator.map((erc20z) => ({
|
|
5743
|
+
address: royaltiesAddress,
|
|
5744
|
+
abi: import_protocol_deployments12.erc20ZRoyaltiesABI,
|
|
5745
|
+
functionName: "positionsByErc20z",
|
|
5746
|
+
args: [erc20z]
|
|
5747
|
+
})),
|
|
5748
|
+
multicallAddress: multicall3Address,
|
|
5749
|
+
allowFailure: false
|
|
5750
|
+
});
|
|
5751
|
+
const erc20zsWithPositions = erc20zsForCreator.filter(
|
|
5752
|
+
(_, i) => positionsByErc20z[i] !== 0n
|
|
5753
|
+
);
|
|
5754
|
+
return erc20zsWithPositions;
|
|
5755
|
+
};
|
|
5756
|
+
var getRewardsBalances = async ({
|
|
5608
5757
|
account,
|
|
5609
5758
|
// The account to check rewards for (Address or Account object)
|
|
5610
5759
|
publicClient,
|
|
5611
5760
|
// The public client for making blockchain queries
|
|
5612
|
-
chainId,
|
|
5613
|
-
// The ID of the blockchain network
|
|
5614
5761
|
rewardsGetter
|
|
5615
5762
|
// Interface for getting ERC20Z tokens for a creator
|
|
5616
5763
|
}) => {
|
|
5764
|
+
const chainId = publicClient.chain.id;
|
|
5617
5765
|
const address = typeof account === "string" ? account : account.address;
|
|
5618
|
-
const
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5766
|
+
const erc20zsWithPositions = await getErc20zsWithPositions({
|
|
5767
|
+
address,
|
|
5768
|
+
publicClient,
|
|
5769
|
+
rewardsGetter
|
|
5770
|
+
});
|
|
5622
5771
|
const result = await publicClient.multicall({
|
|
5623
5772
|
contracts: [
|
|
5624
5773
|
{
|
|
@@ -5631,7 +5780,7 @@ var getRewardsBalance = async ({
|
|
|
5631
5780
|
address: import_protocol_deployments12.erc20ZRoyaltiesAddress[chainId],
|
|
5632
5781
|
abi: import_protocol_deployments12.erc20ZRoyaltiesABI,
|
|
5633
5782
|
functionName: "getUnclaimedFeesBatch",
|
|
5634
|
-
args: [
|
|
5783
|
+
args: [erc20zsWithPositions]
|
|
5635
5784
|
}
|
|
5636
5785
|
],
|
|
5637
5786
|
multicallAddress: multicall3Address,
|
|
@@ -5662,12 +5811,14 @@ var withdrawProtocolRewards = ({
|
|
|
5662
5811
|
var makeClaimSecondaryRoyaltiesCalls = async ({
|
|
5663
5812
|
claimFor,
|
|
5664
5813
|
chainId,
|
|
5665
|
-
rewardsGetter
|
|
5814
|
+
rewardsGetter,
|
|
5815
|
+
publicClient
|
|
5666
5816
|
}) => {
|
|
5667
|
-
const
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5817
|
+
const erc20z = await getErc20zsWithPositions({
|
|
5818
|
+
address: claimFor,
|
|
5819
|
+
publicClient,
|
|
5820
|
+
rewardsGetter
|
|
5821
|
+
});
|
|
5671
5822
|
const royaltiesAddress = import_protocol_deployments12.erc20ZRoyaltiesAddress[chainId];
|
|
5672
5823
|
if (erc20z.length === 0) {
|
|
5673
5824
|
return [];
|
|
@@ -5698,37 +5849,57 @@ var createMulticallParameters = (calls, account) => makeContractParameters({
|
|
|
5698
5849
|
args: [calls],
|
|
5699
5850
|
account
|
|
5700
5851
|
});
|
|
5701
|
-
var
|
|
5702
|
-
account,
|
|
5703
|
-
withdrawFor,
|
|
5704
|
-
claimSecondaryRoyalties = true,
|
|
5852
|
+
var handleProtocolRewardsOnly = ({
|
|
5705
5853
|
chainId,
|
|
5706
|
-
|
|
5854
|
+
withdrawFor,
|
|
5855
|
+
account
|
|
5856
|
+
}) => ({
|
|
5857
|
+
...withdrawProtocolRewards({ chainId, withdrawFor }),
|
|
5858
|
+
account
|
|
5859
|
+
});
|
|
5860
|
+
var handleAllRewards = async ({
|
|
5861
|
+
withdrawFor,
|
|
5862
|
+
account,
|
|
5863
|
+
rewardsGetter,
|
|
5864
|
+
publicClient
|
|
5707
5865
|
}) => {
|
|
5708
|
-
|
|
5709
|
-
return {
|
|
5710
|
-
...withdrawProtocolRewards({ chainId, withdrawFor }),
|
|
5711
|
-
account
|
|
5712
|
-
};
|
|
5713
|
-
}
|
|
5866
|
+
const chainId = publicClient.chain.id;
|
|
5714
5867
|
const protocolRewardsCall = createProtocolRewardsCall(chainId, withdrawFor);
|
|
5715
5868
|
const secondaryRoyaltiesCalls = await makeClaimSecondaryRoyaltiesCalls({
|
|
5716
5869
|
chainId,
|
|
5717
5870
|
claimFor: withdrawFor,
|
|
5718
|
-
rewardsGetter
|
|
5871
|
+
rewardsGetter,
|
|
5872
|
+
publicClient
|
|
5719
5873
|
});
|
|
5720
5874
|
const allCalls = [protocolRewardsCall, ...secondaryRoyaltiesCalls];
|
|
5721
5875
|
return createMulticallParameters(allCalls, account);
|
|
5722
5876
|
};
|
|
5877
|
+
var withdrawRewards = async ({
|
|
5878
|
+
account,
|
|
5879
|
+
withdrawFor,
|
|
5880
|
+
claimSecondaryRoyalties = true,
|
|
5881
|
+
rewardsGetter,
|
|
5882
|
+
publicClient
|
|
5883
|
+
}) => {
|
|
5884
|
+
const parameters = claimSecondaryRoyalties ? await handleAllRewards({
|
|
5885
|
+
withdrawFor,
|
|
5886
|
+
account,
|
|
5887
|
+
rewardsGetter,
|
|
5888
|
+
publicClient
|
|
5889
|
+
}) : await handleProtocolRewardsOnly({
|
|
5890
|
+
chainId: publicClient.chain.id,
|
|
5891
|
+
withdrawFor,
|
|
5892
|
+
account
|
|
5893
|
+
});
|
|
5894
|
+
return { parameters };
|
|
5895
|
+
};
|
|
5723
5896
|
|
|
5724
5897
|
// src/rewards/rewards-client.ts
|
|
5725
5898
|
var RewardsClient = class {
|
|
5726
5899
|
constructor({
|
|
5727
|
-
chainId,
|
|
5728
5900
|
publicClient,
|
|
5729
5901
|
rewardsGetter
|
|
5730
5902
|
}) {
|
|
5731
|
-
this.chainId = chainId;
|
|
5732
5903
|
this.publicClient = publicClient;
|
|
5733
5904
|
this.rewardsGetter = rewardsGetter;
|
|
5734
5905
|
}
|
|
@@ -5738,83 +5909,24 @@ var RewardsClient = class {
|
|
|
5738
5909
|
withdrawFor,
|
|
5739
5910
|
claimSecondaryRoyalties
|
|
5740
5911
|
}) {
|
|
5741
|
-
return {
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
})
|
|
5749
|
-
};
|
|
5912
|
+
return await withdrawRewards({
|
|
5913
|
+
rewardsGetter: this.rewardsGetter,
|
|
5914
|
+
withdrawFor,
|
|
5915
|
+
claimSecondaryRoyalties,
|
|
5916
|
+
account,
|
|
5917
|
+
publicClient: this.publicClient
|
|
5918
|
+
});
|
|
5750
5919
|
}
|
|
5751
5920
|
/** Retrieves the rewards balances for a given account */
|
|
5752
5921
|
async getRewardsBalances(params) {
|
|
5753
|
-
return
|
|
5922
|
+
return getRewardsBalances({
|
|
5754
5923
|
account: params.account,
|
|
5755
|
-
chainId: this.chainId,
|
|
5756
5924
|
publicClient: this.publicClient,
|
|
5757
5925
|
rewardsGetter: this.rewardsGetter
|
|
5758
5926
|
});
|
|
5759
5927
|
}
|
|
5760
5928
|
};
|
|
5761
5929
|
|
|
5762
|
-
// src/rewards/subgraph-queries.ts
|
|
5763
|
-
function buildCreatorERC20zs({
|
|
5764
|
-
address
|
|
5765
|
-
}) {
|
|
5766
|
-
return {
|
|
5767
|
-
query: `
|
|
5768
|
-
query ($address: Bytes!) {
|
|
5769
|
-
zoraCreateTokens(
|
|
5770
|
-
where: { royalties_: { royaltyRecipient: $address }, salesStrategies_: { type: "ZORA_TIMED" } }
|
|
5771
|
-
) {
|
|
5772
|
-
royalties {
|
|
5773
|
-
user
|
|
5774
|
-
}
|
|
5775
|
-
salesStrategies {
|
|
5776
|
-
zoraTimedMinter {
|
|
5777
|
-
secondaryActivated
|
|
5778
|
-
erc20Z {
|
|
5779
|
-
id
|
|
5780
|
-
}
|
|
5781
|
-
}
|
|
5782
|
-
}
|
|
5783
|
-
}
|
|
5784
|
-
}
|
|
5785
|
-
`,
|
|
5786
|
-
variables: { address },
|
|
5787
|
-
parseResponseData: (responseData) => {
|
|
5788
|
-
return responseData?.zoraCreateTokens;
|
|
5789
|
-
}
|
|
5790
|
-
};
|
|
5791
|
-
}
|
|
5792
|
-
|
|
5793
|
-
// src/rewards/subgraph-rewards-getter.ts
|
|
5794
|
-
var SubgraphRewardsGetter = class extends SubgraphGetter {
|
|
5795
|
-
constructor(chainId, subgraphQuerier) {
|
|
5796
|
-
super(chainId, subgraphQuerier);
|
|
5797
|
-
}
|
|
5798
|
-
async getErc20ZzForCreator({ address }) {
|
|
5799
|
-
const queryResults = await this.querySubgraphWithRetries(
|
|
5800
|
-
buildCreatorERC20zs({ address })
|
|
5801
|
-
);
|
|
5802
|
-
const results = (queryResults?.map((result) => {
|
|
5803
|
-
const timedMinter = result.salesStrategies[0].zoraTimedMinter;
|
|
5804
|
-
if (!timedMinter) {
|
|
5805
|
-
return null;
|
|
5806
|
-
}
|
|
5807
|
-
return {
|
|
5808
|
-
secondaryActivated: timedMinter.secondaryActivated,
|
|
5809
|
-
erc20z: timedMinter.erc20Z.id
|
|
5810
|
-
};
|
|
5811
|
-
}) || []).filter(
|
|
5812
|
-
(idAndActivated) => !!idAndActivated
|
|
5813
|
-
);
|
|
5814
|
-
return results;
|
|
5815
|
-
}
|
|
5816
|
-
};
|
|
5817
|
-
|
|
5818
5930
|
// src/secondary/secondary-client.ts
|
|
5819
5931
|
var import_viem19 = require("viem");
|
|
5820
5932
|
var import_protocol_deployments15 = require("@zoralabs/protocol-deployments");
|
|
@@ -5986,7 +6098,8 @@ async function getPoolInfo({
|
|
|
5986
6098
|
};
|
|
5987
6099
|
}
|
|
5988
6100
|
async function getUniswapQuote(input, client) {
|
|
5989
|
-
const { type, quantity, poolAddress,
|
|
6101
|
+
const { type, quantity, poolAddress, erc20z } = input;
|
|
6102
|
+
const chainId = client.chain.id;
|
|
5990
6103
|
const WETH = import_protocol_deployments13.wethAddress[chainId];
|
|
5991
6104
|
const pool = await getPoolInfo({ poolAddress, WETH, erc20z, client });
|
|
5992
6105
|
const { fee, wethBalance, erc20zBalance } = pool;
|
|
@@ -6054,10 +6167,10 @@ var MARKET_REWARD = (0, import_viem18.parseEther)("0.0000222");
|
|
|
6054
6167
|
async function getSecondaryInfo({
|
|
6055
6168
|
contract,
|
|
6056
6169
|
tokenId,
|
|
6057
|
-
publicClient
|
|
6058
|
-
chainId
|
|
6170
|
+
publicClient
|
|
6059
6171
|
}) {
|
|
6060
6172
|
let result;
|
|
6173
|
+
const chainId = publicClient.chain.id;
|
|
6061
6174
|
try {
|
|
6062
6175
|
result = await publicClient.readContract({
|
|
6063
6176
|
abi: import_protocol_deployments14.zoraTimedSaleStrategyABI,
|
|
@@ -6109,7 +6222,6 @@ async function makeBuy({
|
|
|
6109
6222
|
quantity,
|
|
6110
6223
|
account,
|
|
6111
6224
|
recipient,
|
|
6112
|
-
chainId,
|
|
6113
6225
|
slippage,
|
|
6114
6226
|
publicClient,
|
|
6115
6227
|
comment
|
|
@@ -6130,7 +6242,7 @@ async function makeBuy({
|
|
|
6130
6242
|
return handleBuyWithComment({
|
|
6131
6243
|
accountAddress,
|
|
6132
6244
|
recipient,
|
|
6133
|
-
chainId,
|
|
6245
|
+
chainId: publicClient.chain.id,
|
|
6134
6246
|
quantity,
|
|
6135
6247
|
contract,
|
|
6136
6248
|
tokenId,
|
|
@@ -6145,7 +6257,7 @@ async function makeBuy({
|
|
|
6145
6257
|
recipient,
|
|
6146
6258
|
accountAddress,
|
|
6147
6259
|
costWithSlippage,
|
|
6148
|
-
chainId,
|
|
6260
|
+
chainId: publicClient.chain.id,
|
|
6149
6261
|
account
|
|
6150
6262
|
});
|
|
6151
6263
|
}
|
|
@@ -6229,12 +6341,11 @@ function handleBuyWithoutComment({
|
|
|
6229
6341
|
})
|
|
6230
6342
|
};
|
|
6231
6343
|
}
|
|
6232
|
-
async function
|
|
6344
|
+
async function buy1155OnSecondary({
|
|
6233
6345
|
contract,
|
|
6234
6346
|
tokenId,
|
|
6235
6347
|
publicClient,
|
|
6236
6348
|
quantity,
|
|
6237
|
-
chainId,
|
|
6238
6349
|
account,
|
|
6239
6350
|
slippage = UNISWAP_SLIPPAGE,
|
|
6240
6351
|
recipient,
|
|
@@ -6243,8 +6354,7 @@ async function buyWithSlippage({
|
|
|
6243
6354
|
const secondaryInfo = await getSecondaryInfo({
|
|
6244
6355
|
contract,
|
|
6245
6356
|
tokenId,
|
|
6246
|
-
publicClient
|
|
6247
|
-
chainId
|
|
6357
|
+
publicClient
|
|
6248
6358
|
});
|
|
6249
6359
|
if (!secondaryInfo) {
|
|
6250
6360
|
return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
|
|
@@ -6258,8 +6368,7 @@ async function buyWithSlippage({
|
|
|
6258
6368
|
type: "buy",
|
|
6259
6369
|
quantity,
|
|
6260
6370
|
poolAddress: pool,
|
|
6261
|
-
erc20z
|
|
6262
|
-
chainId
|
|
6371
|
+
erc20z
|
|
6263
6372
|
},
|
|
6264
6373
|
publicClient
|
|
6265
6374
|
);
|
|
@@ -6272,7 +6381,6 @@ async function buyWithSlippage({
|
|
|
6272
6381
|
quantity,
|
|
6273
6382
|
account,
|
|
6274
6383
|
recipient,
|
|
6275
|
-
chainId,
|
|
6276
6384
|
slippage,
|
|
6277
6385
|
comment,
|
|
6278
6386
|
publicClient
|
|
@@ -6290,7 +6398,6 @@ async function makeSell({
|
|
|
6290
6398
|
quantity,
|
|
6291
6399
|
account,
|
|
6292
6400
|
recipient,
|
|
6293
|
-
chainId,
|
|
6294
6401
|
slippage,
|
|
6295
6402
|
publicClient
|
|
6296
6403
|
}) {
|
|
@@ -6315,6 +6422,7 @@ async function makeSell({
|
|
|
6315
6422
|
receivedWithSlippage,
|
|
6316
6423
|
0n
|
|
6317
6424
|
]);
|
|
6425
|
+
const chainId = publicClient.chain.id;
|
|
6318
6426
|
return {
|
|
6319
6427
|
parameters: makeContractParameters({
|
|
6320
6428
|
abi: import_protocol_deployments15.zoraCreator1155ImplABI,
|
|
@@ -6331,12 +6439,11 @@ async function makeSell({
|
|
|
6331
6439
|
})
|
|
6332
6440
|
};
|
|
6333
6441
|
}
|
|
6334
|
-
async function
|
|
6442
|
+
async function sell1155OnSecondary({
|
|
6335
6443
|
contract,
|
|
6336
6444
|
tokenId,
|
|
6337
6445
|
publicClient,
|
|
6338
6446
|
quantity,
|
|
6339
|
-
chainId,
|
|
6340
6447
|
account,
|
|
6341
6448
|
slippage = UNISWAP_SLIPPAGE,
|
|
6342
6449
|
recipient
|
|
@@ -6344,8 +6451,7 @@ async function sellWithSlippage({
|
|
|
6344
6451
|
const secondaryInfo = await getSecondaryInfo({
|
|
6345
6452
|
contract,
|
|
6346
6453
|
tokenId,
|
|
6347
|
-
publicClient
|
|
6348
|
-
chainId
|
|
6454
|
+
publicClient
|
|
6349
6455
|
});
|
|
6350
6456
|
if (!secondaryInfo) {
|
|
6351
6457
|
return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
|
|
@@ -6355,7 +6461,7 @@ async function sellWithSlippage({
|
|
|
6355
6461
|
return makeError(ERROR_SECONDARY_NOT_STARTED);
|
|
6356
6462
|
}
|
|
6357
6463
|
const { poolBalance, amount, price } = await getUniswapQuote(
|
|
6358
|
-
{ type: "sell", quantity, poolAddress: pool,
|
|
6464
|
+
{ type: "sell", quantity, poolAddress: pool, erc20z },
|
|
6359
6465
|
publicClient
|
|
6360
6466
|
);
|
|
6361
6467
|
const call = await makeSell({
|
|
@@ -6366,7 +6472,6 @@ async function sellWithSlippage({
|
|
|
6366
6472
|
quantity,
|
|
6367
6473
|
account,
|
|
6368
6474
|
recipient,
|
|
6369
|
-
chainId,
|
|
6370
6475
|
slippage,
|
|
6371
6476
|
publicClient
|
|
6372
6477
|
});
|
|
@@ -6381,12 +6486,8 @@ var SecondaryClient = class {
|
|
|
6381
6486
|
* @param publicClient - The public client for interacting with the blockchain.
|
|
6382
6487
|
* @param chainId - The ID of the blockchain network.
|
|
6383
6488
|
*/
|
|
6384
|
-
constructor({
|
|
6385
|
-
publicClient,
|
|
6386
|
-
chainId
|
|
6387
|
-
}) {
|
|
6489
|
+
constructor({ publicClient }) {
|
|
6388
6490
|
this.publicClient = publicClient;
|
|
6389
|
-
this.chainId = chainId;
|
|
6390
6491
|
}
|
|
6391
6492
|
/**
|
|
6392
6493
|
* Get the secondary info for a given contract and token ID.
|
|
@@ -6401,8 +6502,7 @@ var SecondaryClient = class {
|
|
|
6401
6502
|
return getSecondaryInfo({
|
|
6402
6503
|
contract,
|
|
6403
6504
|
tokenId,
|
|
6404
|
-
publicClient: this.publicClient
|
|
6405
|
-
chainId: this.chainId
|
|
6505
|
+
publicClient: this.publicClient
|
|
6406
6506
|
});
|
|
6407
6507
|
}
|
|
6408
6508
|
/**
|
|
@@ -6411,10 +6511,9 @@ var SecondaryClient = class {
|
|
|
6411
6511
|
* @returns A promise that resolves to the result of the buy operation, including price breakdown and transaction parameters.
|
|
6412
6512
|
*/
|
|
6413
6513
|
async buy1155OnSecondary(input) {
|
|
6414
|
-
return
|
|
6514
|
+
return buy1155OnSecondary({
|
|
6415
6515
|
...input,
|
|
6416
|
-
publicClient: this.publicClient
|
|
6417
|
-
chainId: this.chainId
|
|
6516
|
+
publicClient: this.publicClient
|
|
6418
6517
|
});
|
|
6419
6518
|
}
|
|
6420
6519
|
/**
|
|
@@ -6423,10 +6522,9 @@ var SecondaryClient = class {
|
|
|
6423
6522
|
* @returns A promise that resolves to the result of the sell operation, including price breakdown and transaction parameters.
|
|
6424
6523
|
*/
|
|
6425
6524
|
async sell1155OnSecondary(input) {
|
|
6426
|
-
return
|
|
6525
|
+
return sell1155OnSecondary({
|
|
6427
6526
|
...input,
|
|
6428
|
-
publicClient: this.publicClient
|
|
6429
|
-
chainId: this.chainId
|
|
6527
|
+
publicClient: this.publicClient
|
|
6430
6528
|
});
|
|
6431
6529
|
}
|
|
6432
6530
|
};
|
|
@@ -6439,12 +6537,10 @@ function createCreatorClient(clientConfig) {
|
|
|
6439
6537
|
premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
|
|
6440
6538
|
});
|
|
6441
6539
|
const create1155CreatorClient = new Create1155Client({
|
|
6442
|
-
chainId: clientConfig.chainId,
|
|
6443
6540
|
publicClient: clientConfig.publicClient,
|
|
6444
6541
|
contractGetter: clientConfig.contractGetter || new SubgraphContractGetter(clientConfig.chainId)
|
|
6445
6542
|
});
|
|
6446
6543
|
const rewardsClient = new RewardsClient({
|
|
6447
|
-
chainId: clientConfig.chainId,
|
|
6448
6544
|
publicClient: clientConfig.publicClient,
|
|
6449
6545
|
rewardsGetter: clientConfig.rewardsGetter || new SubgraphRewardsGetter(clientConfig.chainId)
|
|
6450
6546
|
});
|
|
@@ -6464,12 +6560,10 @@ function createCollectorClient(params) {
|
|
|
6464
6560
|
const mintClient = new MintClient({
|
|
6465
6561
|
publicClient: params.publicClient,
|
|
6466
6562
|
premintGetter: premintGetterToUse,
|
|
6467
|
-
mintGetter: mintGetterToUse
|
|
6468
|
-
chainId: params.chainId
|
|
6563
|
+
mintGetter: mintGetterToUse
|
|
6469
6564
|
});
|
|
6470
6565
|
const secondaryClient = new SecondaryClient({
|
|
6471
|
-
publicClient: params.publicClient
|
|
6472
|
-
chainId: params.chainId
|
|
6566
|
+
publicClient: params.publicClient
|
|
6473
6567
|
});
|
|
6474
6568
|
return {
|
|
6475
6569
|
getPremint: (p) => premintGetterToUse.get({
|
|
@@ -7714,10 +7808,12 @@ var createAllowList = async ({
|
|
|
7714
7808
|
PremintAPIClient,
|
|
7715
7809
|
PremintClient,
|
|
7716
7810
|
PremintConfigVersion,
|
|
7811
|
+
SubgraphContractGetter,
|
|
7717
7812
|
SubgraphMintGetter,
|
|
7718
7813
|
ZORA_API_BASE,
|
|
7719
7814
|
applyUpdateToPremint,
|
|
7720
7815
|
buildPremintMintCall,
|
|
7816
|
+
buy1155OnSecondary,
|
|
7721
7817
|
collectPremint,
|
|
7722
7818
|
collectPremintV2WithMintsParams,
|
|
7723
7819
|
collectWithMintsParams,
|
|
@@ -7725,9 +7821,11 @@ var createAllowList = async ({
|
|
|
7725
7821
|
convertGetPremintApiResponse,
|
|
7726
7822
|
convertGetPremintOfCollectionApiResponse,
|
|
7727
7823
|
convertPremintFromApi,
|
|
7824
|
+
create1155,
|
|
7728
7825
|
createAllowList,
|
|
7729
7826
|
createCollectorClient,
|
|
7730
7827
|
createCreatorClient,
|
|
7828
|
+
createNew1155Token,
|
|
7731
7829
|
decodeCallFailedError,
|
|
7732
7830
|
defaultAdditionalAdmins,
|
|
7733
7831
|
defaultTokenConfigV1MintArguments,
|
|
@@ -7736,8 +7834,8 @@ var createAllowList = async ({
|
|
|
7736
7834
|
encodeCollectOnManager,
|
|
7737
7835
|
encodePostSignatureInput,
|
|
7738
7836
|
encodePremintForAPI,
|
|
7837
|
+
findTargetStrategyWithPrimaryOrSecondarySaleActive,
|
|
7739
7838
|
generateTextNftMetadataFiles,
|
|
7740
|
-
getApiNetworkConfigForChain,
|
|
7741
7839
|
getContractAddressFromReceipt,
|
|
7742
7840
|
getDataFromPremintReceipt,
|
|
7743
7841
|
getDefaultFixedPriceMinterAddress,
|
|
@@ -7750,31 +7848,46 @@ var createAllowList = async ({
|
|
|
7750
7848
|
getPremintMintFee,
|
|
7751
7849
|
getPremintPricePerToken,
|
|
7752
7850
|
getPremintedLogFromReceipt,
|
|
7851
|
+
getRewardsBalances,
|
|
7852
|
+
getSecondaryInfo,
|
|
7753
7853
|
getSignature,
|
|
7854
|
+
getToken,
|
|
7754
7855
|
getTokenIdFromCreateReceipt,
|
|
7856
|
+
getTokensOfContract,
|
|
7857
|
+
is1155Mint,
|
|
7755
7858
|
isAuthorizedToCreatePremint,
|
|
7859
|
+
isOnChainMint,
|
|
7756
7860
|
isPremintConfigV1,
|
|
7757
7861
|
isPremintConfigV2,
|
|
7758
7862
|
isValidSignature,
|
|
7759
7863
|
makeCreateContractAndTokenCall,
|
|
7864
|
+
makeCreateTokenCall,
|
|
7760
7865
|
makeMediaTokenMetadata,
|
|
7761
7866
|
makeMintRewardsRecipient,
|
|
7762
7867
|
makeNewPremint,
|
|
7868
|
+
makeOnchainPrepareMintFromCreate,
|
|
7763
7869
|
makePermitToCollectPremintOrNonPremint,
|
|
7764
7870
|
makePermitTransferBatchAndTypeData,
|
|
7765
7871
|
makePermitTransferTypeData,
|
|
7766
7872
|
makeTextTokenMetadata,
|
|
7767
7873
|
makeUrls,
|
|
7768
7874
|
migratePremintConfigToV2,
|
|
7875
|
+
mint,
|
|
7769
7876
|
mintWithEthParams,
|
|
7770
7877
|
mintsBalanceOfAccountParams,
|
|
7878
|
+
new1155ContractVersion,
|
|
7879
|
+
parseAndFilterTokenQueryResult,
|
|
7880
|
+
prepareSetupActions,
|
|
7771
7881
|
recoverCreatorFromCreatorAttribution,
|
|
7772
7882
|
recoverPremintSigner,
|
|
7773
7883
|
selectMintsToCollectWithFromQueryResult,
|
|
7884
|
+
sell1155OnSecondary,
|
|
7774
7885
|
sumBalances,
|
|
7775
7886
|
supportedPremintVersions,
|
|
7776
7887
|
supportsPremintVersion,
|
|
7777
7888
|
toContractCreationConfigOrAddress,
|
|
7778
|
-
|
|
7889
|
+
toMintableReturn,
|
|
7890
|
+
tryRecoverPremintSigner,
|
|
7891
|
+
withdrawRewards
|
|
7779
7892
|
});
|
|
7780
7893
|
//# sourceMappingURL=index.cjs.map
|