@zoralabs/protocol-sdk 0.6.0 → 0.7.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.
Files changed (59) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +6 -0
  3. package/dist/constants.d.ts +0 -1
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/index.cjs +845 -407
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +829 -391
  8. package/dist/index.js.map +1 -1
  9. package/dist/mint/mint-client.d.ts +28 -4071
  10. package/dist/mint/mint-client.d.ts.map +1 -1
  11. package/dist/mint/mint-queries.d.ts +38 -0
  12. package/dist/mint/mint-queries.d.ts.map +1 -0
  13. package/dist/mint/mint-transactions.d.ts +20 -0
  14. package/dist/mint/mint-transactions.d.ts.map +1 -0
  15. package/dist/mint/subgraph-mint-getter.d.ts +14 -7
  16. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  17. package/dist/mint/subgraph-queries.d.ts +55 -0
  18. package/dist/mint/subgraph-queries.d.ts.map +1 -0
  19. package/dist/mint/types.d.ts +117 -19
  20. package/dist/mint/types.d.ts.map +1 -1
  21. package/dist/mint/utils.d.ts +2 -0
  22. package/dist/mint/utils.d.ts.map +1 -0
  23. package/dist/mints/mints-contracts.d.ts +3 -4494
  24. package/dist/mints/mints-contracts.d.ts.map +1 -1
  25. package/dist/premint/conversions.d.ts +12 -15
  26. package/dist/premint/conversions.d.ts.map +1 -1
  27. package/dist/premint/premint-api-client.d.ts +14 -11
  28. package/dist/premint/premint-api-client.d.ts.map +1 -1
  29. package/dist/premint/premint-client.d.ts +15 -5
  30. package/dist/premint/premint-client.d.ts.map +1 -1
  31. package/dist/premint/preminter.d.ts +1 -1
  32. package/dist/premint/preminter.d.ts.map +1 -1
  33. package/dist/sdk.d.ts +4 -2
  34. package/dist/sdk.d.ts.map +1 -1
  35. package/dist/types.d.ts +3 -0
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/utils.d.ts +10 -2
  38. package/dist/utils.d.ts.map +1 -1
  39. package/package.json +1 -1
  40. package/src/constants.ts +0 -36
  41. package/src/create/1155-create-helper.test.ts +9 -7
  42. package/src/mint/mint-client.test.ts +96 -47
  43. package/src/mint/mint-client.ts +75 -343
  44. package/src/mint/mint-queries.ts +320 -0
  45. package/src/mint/mint-transactions.ts +253 -0
  46. package/src/mint/subgraph-mint-getter.ts +216 -123
  47. package/src/mint/subgraph-queries.ts +170 -0
  48. package/src/mint/types.ts +140 -23
  49. package/src/mint/utils.ts +14 -0
  50. package/src/premint/conversions.ts +26 -2
  51. package/src/premint/premint-api-client.ts +48 -16
  52. package/src/premint/premint-client.test.ts +29 -23
  53. package/src/premint/premint-client.ts +64 -36
  54. package/src/premint/preminter.ts +2 -3
  55. package/src/sdk.ts +7 -4
  56. package/src/types.ts +18 -0
  57. package/src/utils.ts +29 -28
  58. package/test-integration/setup-test-contracts.ts +96 -0
  59. package/test-integration/premint-client.test.ts +0 -148
package/src/mint/types.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { Account, Address } from "viem";
2
- import { GenericTokenIdTypes } from "src/types";
2
+ import {
3
+ GenericTokenIdTypes,
4
+ SimulateContractParametersWithAccount,
5
+ } from "src/types";
3
6
 
4
7
  export type MintParameters<MintType> = {
5
8
  /** Type of the collection to be minted. */
@@ -29,15 +32,25 @@ export type MintTypes =
29
32
  | Erc721MintParameters
30
33
  | PremintMintParameters;
31
34
 
35
+ export type GetMintParameters = MintTypes & {
36
+ /** Address of the contract that the item belongs to */
37
+ tokenContract: Address;
38
+ preferredSaleType?: SaleType;
39
+ };
40
+
41
+ export type GetMintsOfContractParameters = {
42
+ /** Address of the contract to get the tokens of */
43
+ tokenContract: Address;
44
+ preferredSaleType?: SaleType;
45
+ };
46
+
32
47
  export const isOnChainMint = (mint: MintTypes): mint is OnChainMintParameters =>
33
48
  mint.mintType !== "premint";
34
49
 
35
50
  export const is1155Mint = (mint: MintTypes): mint is Erc1155MintParameters =>
36
51
  mint.mintType === "1155";
37
52
 
38
- export type MakeMintParametersArgumentsBase = {
39
- /** Premint contract address */
40
- tokenContract: Address;
53
+ export type MintParametersBase = {
41
54
  /** Account to execute the mint */
42
55
  minterAccount: Account | Address;
43
56
  /** Quantity of tokens to mint. Defaults to 1 */
@@ -48,16 +61,23 @@ export type MakeMintParametersArgumentsBase = {
48
61
  mintReferral?: Address;
49
62
  /** Address to receive the minted tokens. Defaults to the minting account */
50
63
  mintRecipient?: Address;
64
+ /** If this is a premint, the address to get the first minter reward */
65
+ firstMinter?: Address;
66
+ };
67
+
68
+ export type MakeMintParametersArgumentsBase = MintParametersBase & {
69
+ /** Premint contract address */
70
+ tokenContract: Address;
51
71
  };
52
72
 
53
73
  export type Make1155MintArguments = MakeMintParametersArgumentsBase &
54
74
  Erc1155MintParameters & {
55
- saleType?: SaleType;
75
+ preferredSaleType?: SaleType;
56
76
  };
57
77
 
58
78
  export type Make721MintArguments = MakeMintParametersArgumentsBase &
59
79
  Erc721MintParameters & {
60
- saleType?: SaleType;
80
+ preferredSaleType?: SaleType;
61
81
  };
62
82
 
63
83
  export type MakePremintMintParametersArguments =
@@ -79,44 +99,141 @@ export type GetMintCostsParameters = {
79
99
  quantityMinted: number | bigint;
80
100
  } & MintTypes;
81
101
 
82
- export type SaleType = "fixedPrice" | "erc20";
102
+ export type SaleType = "fixedPrice" | "erc20" | "premint";
83
103
 
84
104
  type SaleStrategy<T extends SaleType> = {
85
105
  saleType: T;
86
- address: Address;
87
106
  pricePerToken: bigint;
88
- saleEnd: string;
89
- saleStart: string;
90
107
  maxTokensPerAddress: bigint;
91
108
  };
92
109
 
93
- type FixedPriceSaleStrategy = SaleStrategy<"fixedPrice">;
110
+ type FixedPriceSaleStrategy = SaleStrategy<"fixedPrice"> & {
111
+ address: Address;
112
+ saleStart: string;
113
+ saleEnd: string;
114
+ };
94
115
 
95
116
  type ERC20SaleStrategy = SaleStrategy<"erc20"> & {
117
+ address: Address;
118
+ saleStart: string;
119
+ saleEnd: string;
96
120
  currency: Address;
97
121
  };
98
122
 
99
- type SaleStrategies = FixedPriceSaleStrategy | ERC20SaleStrategy;
123
+ type PremintSaleStrategy = SaleStrategy<"premint"> & {
124
+ duration: bigint;
125
+ };
126
+
127
+ export type SaleStrategies =
128
+ | FixedPriceSaleStrategy
129
+ | ERC20SaleStrategy
130
+ | PremintSaleStrategy;
131
+
132
+ export type OnchainSalesStrategies = FixedPriceSaleStrategy | ERC20SaleStrategy;
100
133
 
101
134
  export function isErc20SaleStrategy(
102
- salesConfig: SaleStrategies,
135
+ salesConfig: FixedPriceSaleStrategy | ERC20SaleStrategy | PremintSaleStrategy,
103
136
  ): salesConfig is ERC20SaleStrategy {
104
137
  return salesConfig.saleType === "erc20";
105
138
  }
106
139
 
107
- export type SalesConfigAndTokenInfo = {
108
- salesConfig: SaleStrategies;
140
+ export type ContractInfo = {
141
+ /** Address of the contract */
142
+ address: Address;
143
+ /** Contract metadata uri */
144
+ URI: string;
145
+ /** Contract name */
146
+ name: string;
147
+ };
148
+
149
+ export type MintableBase = {
150
+ /** The contract the mintable belongs to */
151
+ contract: ContractInfo;
152
+ /** Token metadata URI */
153
+ tokenURI: string;
154
+ /** Price in eth to mint 1 item */
109
155
  mintFeePerQuantity: bigint;
156
+ /** Creator of the mintable item */
157
+ creator: Address;
158
+ /** Maximum total number of items that can be minted */
159
+ maxSupply: bigint;
160
+ /** Total number of items minted so far */
161
+ totalMinted: bigint;
162
+ };
163
+
164
+ export type OnchainMintable = MintableBase & {
165
+ mintType: "721" | "1155";
166
+ tokenId?: bigint;
167
+ contractVersion: string;
168
+ };
169
+
170
+ export type PremintMintable = MintableBase & {
171
+ mintType: "premint";
172
+ uid: number;
110
173
  };
111
174
 
112
- export interface IMintGetter {
113
- getSalesConfigAndTokenInfo({
114
- tokenAddress,
115
- tokenId,
116
- saleType,
117
- }: {
175
+ export type OnchainSalesConfigAndTokenInfo = {
176
+ salesConfig: FixedPriceSaleStrategy | ERC20SaleStrategy;
177
+ } & OnchainMintable;
178
+
179
+ export type PremintSalesConfigAndTokenInfo = {
180
+ salesConfig: PremintSaleStrategy;
181
+ } & PremintMintable;
182
+
183
+ export type SalesConfigAndTokenInfo =
184
+ | OnchainSalesConfigAndTokenInfo
185
+ | PremintMintable;
186
+
187
+ export interface IOnchainMintGetter {
188
+ getMintable(params: {
118
189
  tokenAddress: Address;
119
190
  tokenId?: GenericTokenIdTypes;
120
- saleType?: SaleType;
121
- }): Promise<SalesConfigAndTokenInfo>;
191
+ preferredSaleType?: SaleType;
192
+ }): Promise<OnchainSalesConfigAndTokenInfo>;
193
+
194
+ getContractMintable(params: {
195
+ tokenAddress: Address;
196
+ }): Promise<OnchainSalesConfigAndTokenInfo[]>;
197
+
198
+ getContractPremintTokenIds(params: {
199
+ tokenAddress: Address;
200
+ }): Promise<{ tokenId: BigInt; uid: number }[]>;
122
201
  }
202
+
203
+ export type MintCosts = {
204
+ /** The total of the mint fee, in eth */
205
+ mintFee: bigint;
206
+ /** If it is a paid or erc20 mint, the total price of the paid or erc20 mint in eth or erc20 value correspondingly. */
207
+ totalPurchaseCost: bigint;
208
+ /** If it is an erc20 mint, the erc20 address */
209
+ totalPurchaseCostCurrency?: Address;
210
+ /** The total cost in eth (mint fee + purchase cost) to mint */
211
+ totalCostEth: bigint;
212
+ };
213
+
214
+ export type Erc20Approval = {
215
+ /** ERC20 token address that must be approved */
216
+ erc20: Address;
217
+ /** Quantity of ERC20 that must be approved */
218
+ quantity: bigint;
219
+ /** Address that must be approved to transfer to */
220
+ approveTo: Address;
221
+ };
222
+
223
+ export type PrepareMintReturn = {
224
+ /** Prepared parameters to execute the mint transaction */
225
+ parameters: SimulateContractParametersWithAccount;
226
+ /** If an erc20 approval is necessary, information for the erc20 approval */
227
+ erc20Approval?: Erc20Approval;
228
+ /** Cost breakdown to mint the quantity of tokens */
229
+ costs: MintCosts;
230
+ };
231
+
232
+ export type PrepareMint = (params: MintParametersBase) => PrepareMintReturn;
233
+
234
+ export type MintableReturn = {
235
+ /** Token information */
236
+ token: SalesConfigAndTokenInfo;
237
+ /** Function that takes a quantity of items to mint and returns a prepared transaction and the costs to mint that quantity */
238
+ prepareMint: PrepareMint;
239
+ };
@@ -0,0 +1,14 @@
1
+ import * as semver from "semver";
2
+ export const contractSupportsNewMintFunction = (
3
+ contractVersion?: string | null,
4
+ ) => {
5
+ if (!contractVersion) {
6
+ return false;
7
+ }
8
+
9
+ // Try force-convert version format to semver format
10
+ const semVerContractVersion = semver.coerce(contractVersion)?.raw;
11
+ if (!semVerContractVersion) return false;
12
+
13
+ return semver.gte(semVerContractVersion, "2.9.0");
14
+ };
@@ -9,7 +9,10 @@ import {
9
9
  PremintConfigVersion,
10
10
  PremintConfigWithVersion,
11
11
  } from "@zoralabs/protocol-deployments";
12
- import { PremintSignatureGetResponse } from "./premint-api-client";
12
+ import {
13
+ PremintSignatureGetOfCollectionResponse,
14
+ PremintSignatureGetResponse,
15
+ } from "./premint-api-client";
13
16
  import { ContractCreationConfigOrAddress } from "./contract-types";
14
17
 
15
18
  export const convertCollectionFromApi = (
@@ -84,13 +87,34 @@ export const convertPremintFromApi = (
84
87
  }
85
88
  };
86
89
 
90
+ export type PremintFromApi = ReturnType<typeof convertGetPremintApiResponse>;
91
+
87
92
  export const convertGetPremintApiResponse = (
88
93
  response: PremintSignatureGetResponse,
89
94
  ) => ({
90
- ...convertPremintFromApi(response.premint),
91
95
  collection: convertCollectionFromApi(response.collection),
92
96
  collectionAddress: response.collection_address as Address,
93
97
  signature: response.signature as Hex,
98
+ signer: response.signer as Address,
99
+ premint: convertPremintFromApi(response.premint),
100
+ });
101
+
102
+ export type PremintCollectionFromApi = ReturnType<
103
+ typeof convertGetPremintOfCollectionApiResponse
104
+ >;
105
+
106
+ export const convertGetPremintOfCollectionApiResponse = (
107
+ response: PremintSignatureGetOfCollectionResponse,
108
+ ) => ({
109
+ collection: convertCollectionFromApi({
110
+ contractAdmin: response.contract_admin,
111
+ contractName: response.contract_name,
112
+ contractURI: response.contract_uri,
113
+ }),
114
+ premints: response.premints.map((premint) => ({
115
+ premint: convertPremintFromApi(premint),
116
+ signature: premint.signature as Hex,
117
+ })),
94
118
  });
95
119
 
96
120
  const encodePremintV1ForAPI = ({
@@ -6,16 +6,17 @@ import { components, paths } from "../apis/generated/premint-api-types";
6
6
  import { ZORA_API_BASE } from "../constants";
7
7
  import { getApiNetworkConfigForChain } from "src/mint/subgraph-mint-getter";
8
8
  import {
9
- ContractCreationConfig,
10
- PremintConfigAndVersion,
11
9
  PremintConfigVersion,
12
10
  PremintConfigWithVersion,
13
11
  } from "@zoralabs/protocol-deployments";
14
12
  import { Address, Hex } from "viem";
15
13
  import {
14
+ PremintCollectionFromApi,
15
+ PremintFromApi,
16
16
  PremintSignatureRequestBody,
17
17
  PremintSignatureResponse,
18
18
  convertGetPremintApiResponse,
19
+ convertGetPremintOfCollectionApiResponse,
19
20
  encodePostSignatureInput,
20
21
  } from "./conversions";
21
22
  import { ContractCreationConfigOrAddress } from "./contract-types";
@@ -32,6 +33,11 @@ type SignaturePremintGetType =
32
33
  export type PremintSignatureGetResponse =
33
34
  SignaturePremintGetType["responses"][200]["content"]["application/json"];
34
35
 
36
+ type SignaturePremintGetOfCollectionType =
37
+ paths["/signature/{chain_name}/{collection_address}"]["get"];
38
+ export type PremintSignatureGetOfCollectionResponse =
39
+ SignaturePremintGetOfCollectionType["responses"][200]["content"]["application/json"];
40
+
35
41
  export type PremintCollection = PremintSignatureGetResponse["collection"];
36
42
 
37
43
  export type BackendChainNames = components["schemas"]["ChainName"];
@@ -72,13 +78,7 @@ export const getSignature = async ({
72
78
  uid: number;
73
79
  chainId: number;
74
80
  httpClient?: Pick<IHttpClient, "retries" | "get">;
75
- }): Promise<
76
- {
77
- signature: Hex;
78
- collection: ContractCreationConfig | undefined;
79
- collectionAddress: Address;
80
- } & PremintConfigAndVersion
81
- > => {
81
+ }): Promise<PremintFromApi> => {
82
82
  const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
83
83
  const result = await retries(() =>
84
84
  get<PremintSignatureGetResponse>(
@@ -89,15 +89,40 @@ export const getSignature = async ({
89
89
  return convertGetPremintApiResponse(result);
90
90
  };
91
91
 
92
+ const getOfCollection = async ({
93
+ collectionAddress,
94
+ chainId,
95
+ httpClient: { retries, get } = defaultHttpClient,
96
+ }: {
97
+ collectionAddress: Address;
98
+ chainId: number;
99
+ httpClient?: Pick<IHttpClient, "retries" | "get">;
100
+ }) => {
101
+ const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
102
+ const result = await retries(() =>
103
+ get<PremintSignatureGetOfCollectionResponse>(
104
+ `${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}`,
105
+ ),
106
+ );
107
+
108
+ return convertGetPremintOfCollectionApiResponse(result);
109
+ };
110
+
92
111
  export interface IPremintGetter {
93
- getSignature(params: {
112
+ get(params: {
94
113
  collectionAddress: Address;
95
114
  uid: number;
96
- }): ReturnType<typeof getSignature>;
115
+ }): Promise<PremintFromApi>;
116
+
117
+ getOfCollection(params: {
118
+ collectionAddress: Address;
119
+ }): Promise<PremintCollectionFromApi>;
97
120
  }
98
121
 
99
122
  export interface IPremintAPI {
100
- getSignature: IPremintGetter["getSignature"];
123
+ get: IPremintGetter["get"];
124
+
125
+ getOfCollection: IPremintGetter["getOfCollection"];
101
126
 
102
127
  getNextUID(collectionAddress: Address): Promise<number>;
103
128
 
@@ -141,10 +166,7 @@ class PremintAPIClient implements IPremintAPI {
141
166
  })
142
167
  ).next_uid;
143
168
 
144
- getSignature: IPremintAPI["getSignature"] = async ({
145
- collectionAddress,
146
- uid,
147
- }) => {
169
+ get: IPremintAPI["get"] = async ({ collectionAddress, uid }) => {
148
170
  return getSignature({
149
171
  collectionAddress,
150
172
  uid,
@@ -152,6 +174,16 @@ class PremintAPIClient implements IPremintAPI {
152
174
  httpClient: this.httpClient,
153
175
  });
154
176
  };
177
+
178
+ getOfCollection: IPremintAPI["getOfCollection"] = async ({
179
+ collectionAddress,
180
+ }) => {
181
+ return getOfCollection({
182
+ collectionAddress,
183
+ chainId: this.chainId,
184
+ httpClient: this.httpClient,
185
+ });
186
+ };
155
187
  }
156
188
 
157
189
  export { ZORA_API_BASE, PremintAPIClient };
@@ -28,8 +28,8 @@ describe("ZoraCreator1155Premint", () => {
28
28
 
29
29
  const premintApiClient = new PremintAPIClient(chain.id);
30
30
 
31
- premintApiClient.getSignature = vi
32
- .fn<any, ReturnType<typeof premintApiClient.getSignature>>()
31
+ premintApiClient.get = vi
32
+ .fn<any, ReturnType<typeof premintApiClient.get>>()
33
33
  .mockResolvedValue({
34
34
  collection: {
35
35
  contractAdmin: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
@@ -39,25 +39,28 @@ describe("ZoraCreator1155Premint", () => {
39
39
  additionalAdmins: [],
40
40
  },
41
41
  collectionAddress: "0xf8dA7f53c283d898818af7FB9d98103F559bDac2",
42
- premintConfig: {
43
- deleted: false,
44
- tokenConfig: {
45
- fixedPriceMinter: getDefaultFixedPriceMinterAddress(chain.id),
46
- maxSupply: 18446744073709551615n,
47
- maxTokensPerAddress: 0n,
48
- mintDuration: 604800n,
49
- mintStart: 0n,
50
- pricePerToken: 0n,
51
- royaltyBPS: 1000,
52
- royaltyMintSchedule: 0,
53
- royaltyRecipient: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
54
- tokenURI:
55
- "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
42
+ premint: {
43
+ premintConfig: {
44
+ deleted: false,
45
+ tokenConfig: {
46
+ fixedPriceMinter: getDefaultFixedPriceMinterAddress(chain.id),
47
+ maxSupply: 18446744073709551615n,
48
+ maxTokensPerAddress: 0n,
49
+ mintDuration: 604800n,
50
+ mintStart: 0n,
51
+ pricePerToken: 0n,
52
+ royaltyBPS: 1000,
53
+ royaltyMintSchedule: 0,
54
+ royaltyRecipient: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
55
+ tokenURI:
56
+ "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
57
+ },
58
+ uid: 3,
59
+ version: 0,
56
60
  },
57
- uid: 3,
58
- version: 0,
61
+ premintConfigVersion: PremintConfigVersion.V1,
59
62
  },
60
- premintConfigVersion: PremintConfigVersion.V1,
63
+ signer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
61
64
  signature:
62
65
  "0x4d191dd60d428adfe507932a1758bee8ac5bbb77dcd3c05840c237416a3a25035bb8cc7c62177a4e9acb5f40c4032cdb3dbfefdd1575f2c3b4c57945b2076e2e1c",
63
66
  });
@@ -238,13 +241,16 @@ describe("ZoraCreator1155Premint - v2 signatures", () => {
238
241
  account: additionalAdmin!,
239
242
  });
240
243
 
241
- premintApiClient.getSignature = vi
242
- .fn<any, ReturnType<typeof premintApiClient.getSignature>>()
244
+ premintApiClient.get = vi
245
+ .fn<any, ReturnType<typeof premintApiClient.get>>()
243
246
  .mockResolvedValue({
244
247
  collection,
245
248
  collectionAddress,
246
- premintConfig: premintConfig as PremintConfigV2,
247
- premintConfigVersion: PremintConfigVersion.V2,
249
+ premint: {
250
+ premintConfig: premintConfig as PremintConfigV2,
251
+ premintConfigVersion: PremintConfigVersion.V2,
252
+ },
253
+ signer: collection.contractAdmin,
248
254
  signature,
249
255
  });
250
256
 
@@ -27,6 +27,7 @@ import {
27
27
  emptyContractCreationConfig,
28
28
  defaultAdditionalAdmins,
29
29
  toContractCreationConfigOrAddress,
30
+ getPremintMintFee,
30
31
  } from "./preminter";
31
32
  import {
32
33
  PremintConfigVersion,
@@ -42,7 +43,6 @@ import { IPremintAPI, IPremintGetter } from "./premint-api-client";
42
43
  import type { DecodeEventLogReturnType } from "viem";
43
44
  import { OPEN_EDITION_MINT_SIZE } from "../constants";
44
45
  import { getApiNetworkConfigForChain } from "src/mint/subgraph-mint-getter";
45
- import { MintCosts } from "src/mint/mint-client";
46
46
  import {
47
47
  makeContractParameters,
48
48
  mintRecipientOrAccount,
@@ -52,7 +52,13 @@ import {
52
52
  ContractCreationConfigAndAddress,
53
53
  ContractCreationConfigOrAddress,
54
54
  } from "./contract-types";
55
- import { MakePremintMintParametersArguments } from "src/mint/types";
55
+ import {
56
+ MakeMintParametersArgumentsBase,
57
+ MakePremintMintParametersArguments,
58
+ MintCosts,
59
+ } from "src/mint/types";
60
+ import { PremintFromApi } from "./conversions";
61
+ import { SimulateContractParametersWithAccount } from "src/types";
56
62
 
57
63
  type PremintedV2LogType = DecodeEventLogReturnType<
58
64
  typeof zoraCreator1155PremintExecutorImplABI,
@@ -297,7 +303,7 @@ export class PremintClient {
297
303
  * @returns PremintSignatureGetResponse of premint data from the API
298
304
  */
299
305
  async getPremint({ address, uid }: { address: Address; uid: number }) {
300
- return await this.apiClient.getSignature({
306
+ return await this.apiClient.get({
301
307
  collectionAddress: address,
302
308
  uid,
303
309
  });
@@ -426,7 +432,7 @@ type PremintReturn<T extends PremintConfigVersion> = {
426
432
  /** Signs the Premint, and submits it and the signature to the Zora Premint API */
427
433
  signAndSubmit: (params: SignAndSubmitParams) => Promise<SignAndSubmitReturn>;
428
434
  /** For the case where the premint is signed externally, takes the signature for the Premint, and submits it and the Premint to the Zora Premint API */
429
- submit: (params: SubmitParams) => void;
435
+ submit: (params: SubmitParams) => Promise<void>;
430
436
  } & PremintConfigWithVersion<T>;
431
437
 
432
438
  function makePremintReturn<T extends PremintConfigVersion>({
@@ -656,10 +662,9 @@ async function updatePremint({
656
662
  chainId: number;
657
663
  }) {
658
664
  const {
659
- premintConfig,
665
+ premint: { premintConfig, premintConfigVersion },
660
666
  collection: collectionCreationConfig,
661
- premintConfigVersion,
662
- } = await apiClient.getSignature({
667
+ } = await apiClient.get({
663
668
  collectionAddress: collection,
664
669
  uid: uid,
665
670
  });
@@ -703,11 +708,10 @@ async function deletePremint({
703
708
  chainId: number;
704
709
  }) {
705
710
  const {
706
- premintConfig,
707
- premintConfigVersion,
711
+ premint: { premintConfig, premintConfigVersion },
708
712
  collection: collectionCreationConfig,
709
713
  collectionAddress,
710
- } = await apiClient.getSignature({
714
+ } = await apiClient.get({
711
715
  collectionAddress: collection,
712
716
  uid: uid,
713
717
  });
@@ -781,32 +785,51 @@ export async function collectPremint({
781
785
  throw new Error("Quantity to mint cannot be below 1");
782
786
  }
783
787
 
784
- const {
785
- premintConfig,
786
- premintConfigVersion,
787
- collection,
788
- collectionAddress,
789
- signature,
790
- } = await premintGetter.getSignature({
788
+ const premint = await premintGetter.get({
791
789
  collectionAddress: tokenContract,
792
790
  uid,
793
791
  });
794
792
 
795
- const numberToMint = BigInt(quantityToMint || 1);
796
-
797
- if (premintConfigVersion === PremintConfigVersion.V3) {
798
- throw new Error("PremintV3 not supported in premint SDK");
799
- }
793
+ const mintFee = await getPremintMintFee({
794
+ tokenContract,
795
+ publicClient,
796
+ });
800
797
 
801
- const value = (
802
- await getPremintMintCosts({
803
- tokenContract,
804
- quantityToMint: numberToMint,
805
- publicClient,
806
- tokenPrice: premintConfig.tokenConfig.pricePerToken,
807
- })
808
- ).totalCostEth;
798
+ return buildPremintMintCall({
799
+ mintArguments: {
800
+ minterAccount,
801
+ quantityToMint,
802
+ firstMinter,
803
+ mintComment,
804
+ mintRecipient,
805
+ mintReferral,
806
+ },
807
+ mintFee,
808
+ premint,
809
+ });
810
+ }
809
811
 
812
+ export const buildPremintMintCall = ({
813
+ mintArguments: {
814
+ minterAccount,
815
+ mintComment = "",
816
+ mintRecipient,
817
+ mintReferral,
818
+ firstMinter,
819
+ quantityToMint,
820
+ },
821
+ premint: { collection, collectionAddress, premint, signature },
822
+ mintFee,
823
+ }: {
824
+ mintArguments: Omit<MakeMintParametersArgumentsBase, "tokenContract"> & {
825
+ firstMinter?: Address;
826
+ };
827
+ premint: Pick<
828
+ PremintFromApi,
829
+ "collection" | "collectionAddress" | "premint" | "signature"
830
+ >;
831
+ mintFee: bigint;
832
+ }): SimulateContractParametersWithAccount => {
810
833
  const mintArgumentsContract: PremintMintArguments = {
811
834
  mintComment: mintComment,
812
835
  mintRecipient: mintRecipientOrAccount({
@@ -829,6 +852,14 @@ export async function collectPremint({
829
852
  firstMinter ||
830
853
  (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
831
854
 
855
+ if (premint.premintConfigVersion === PremintConfigVersion.V3) {
856
+ throw new Error("PremintV3 not supported in premint SDK");
857
+ }
858
+
859
+ const value =
860
+ (mintFee + premint.premintConfig.tokenConfig.pricePerToken) *
861
+ BigInt(quantityToMint);
862
+
832
863
  return makeContractParameters({
833
864
  account: minterAccount,
834
865
  abi: zoraCreator1155PremintExecutorImplABI,
@@ -838,18 +869,15 @@ export async function collectPremint({
838
869
  args: [
839
870
  collectionOrEmpty,
840
871
  collectionAddressToSubmit,
841
- encodePremintConfig({
842
- premintConfig,
843
- premintConfigVersion,
844
- }),
872
+ encodePremintConfig(premint),
845
873
  signature,
846
- numberToMint,
874
+ BigInt(quantityToMint),
847
875
  mintArgumentsContract,
848
876
  firstMinterToSubmit,
849
877
  zeroAddress,
850
878
  ],
851
879
  });
852
- }
880
+ };
853
881
 
854
882
  export function makeUrls({
855
883
  uid,