@zoralabs/protocol-sdk 0.6.0 → 0.7.1

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 (86) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +12 -0
  3. package/dist/constants.d.ts +0 -1
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/index.cjs +2023 -431
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2001 -412
  10. package/dist/index.js.map +1 -1
  11. package/dist/ipfs/arweave.d.ts +3 -0
  12. package/dist/ipfs/arweave.d.ts.map +1 -0
  13. package/dist/ipfs/gateway.d.ts +4 -0
  14. package/dist/ipfs/gateway.d.ts.map +1 -0
  15. package/dist/ipfs/index.d.ts +4 -0
  16. package/dist/ipfs/index.d.ts.map +1 -0
  17. package/dist/ipfs/ipfs.d.ts +5 -0
  18. package/dist/ipfs/ipfs.d.ts.map +1 -0
  19. package/dist/ipfs/mimeTypes.d.ts +25 -0
  20. package/dist/ipfs/mimeTypes.d.ts.map +1 -0
  21. package/dist/ipfs/text-metadata.d.ts +5 -0
  22. package/dist/ipfs/text-metadata.d.ts.map +1 -0
  23. package/dist/ipfs/token-metadata.d.ts +14 -0
  24. package/dist/ipfs/token-metadata.d.ts.map +1 -0
  25. package/dist/ipfs/types.d.ts +49 -0
  26. package/dist/ipfs/types.d.ts.map +1 -0
  27. package/dist/mint/mint-client.d.ts +28 -4071
  28. package/dist/mint/mint-client.d.ts.map +1 -1
  29. package/dist/mint/mint-queries.d.ts +38 -0
  30. package/dist/mint/mint-queries.d.ts.map +1 -0
  31. package/dist/mint/mint-transactions.d.ts +20 -0
  32. package/dist/mint/mint-transactions.d.ts.map +1 -0
  33. package/dist/mint/subgraph-mint-getter.d.ts +14 -7
  34. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  35. package/dist/mint/subgraph-queries.d.ts +55 -0
  36. package/dist/mint/subgraph-queries.d.ts.map +1 -0
  37. package/dist/mint/types.d.ts +117 -19
  38. package/dist/mint/types.d.ts.map +1 -1
  39. package/dist/mint/utils.d.ts +2 -0
  40. package/dist/mint/utils.d.ts.map +1 -0
  41. package/dist/mints/mints-contracts.d.ts +3 -4494
  42. package/dist/mints/mints-contracts.d.ts.map +1 -1
  43. package/dist/premint/conversions.d.ts +12 -15
  44. package/dist/premint/conversions.d.ts.map +1 -1
  45. package/dist/premint/premint-api-client.d.ts +14 -11
  46. package/dist/premint/premint-api-client.d.ts.map +1 -1
  47. package/dist/premint/premint-client.d.ts +17 -6
  48. package/dist/premint/premint-client.d.ts.map +1 -1
  49. package/dist/premint/preminter.d.ts +1 -1
  50. package/dist/premint/preminter.d.ts.map +1 -1
  51. package/dist/sdk.d.ts +4 -2
  52. package/dist/sdk.d.ts.map +1 -1
  53. package/dist/types.d.ts +3 -0
  54. package/dist/types.d.ts.map +1 -1
  55. package/dist/utils.d.ts +10 -2
  56. package/dist/utils.d.ts.map +1 -1
  57. package/package.json +2 -1
  58. package/src/constants.ts +0 -36
  59. package/src/create/1155-create-helper.test.ts +9 -7
  60. package/src/index.ts +2 -0
  61. package/src/ipfs/arweave.ts +5 -0
  62. package/src/ipfs/gateway.ts +48 -0
  63. package/src/ipfs/index.ts +7 -0
  64. package/src/ipfs/ipfs.ts +82 -0
  65. package/src/ipfs/mimeTypes.ts +141 -0
  66. package/src/ipfs/text-metadata.ts +128 -0
  67. package/src/ipfs/token-metadata.ts +99 -0
  68. package/src/ipfs/types.ts +54 -0
  69. package/src/mint/mint-client.test.ts +96 -47
  70. package/src/mint/mint-client.ts +75 -343
  71. package/src/mint/mint-queries.ts +320 -0
  72. package/src/mint/mint-transactions.ts +253 -0
  73. package/src/mint/subgraph-mint-getter.ts +216 -123
  74. package/src/mint/subgraph-queries.ts +170 -0
  75. package/src/mint/types.ts +140 -23
  76. package/src/mint/utils.ts +14 -0
  77. package/src/premint/conversions.ts +26 -2
  78. package/src/premint/premint-api-client.ts +48 -16
  79. package/src/premint/premint-client.test.ts +29 -23
  80. package/src/premint/premint-client.ts +73 -37
  81. package/src/premint/preminter.ts +2 -3
  82. package/src/sdk.ts +7 -4
  83. package/src/types.ts +18 -0
  84. package/src/utils.ts +29 -28
  85. package/test-integration/setup-test-contracts.ts +96 -0
  86. 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,14 +52,20 @@ 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,
59
65
  "PremintedV2"
60
66
  >["args"];
61
67
 
62
- type URLSReturnType = {
68
+ export type URLSReturnType = {
63
69
  explorer: null | string;
64
70
  zoraCollect: null | string;
65
71
  zoraManage: null | string;
@@ -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,8 @@ 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>;
436
+ urls: URLSReturnType;
430
437
  } & PremintConfigWithVersion<T>;
431
438
 
432
439
  function makePremintReturn<T extends PremintConfigVersion>({
@@ -497,6 +504,12 @@ function makePremintReturn<T extends PremintConfigVersion>({
497
504
  });
498
505
  };
499
506
 
507
+ const urls = makeUrls({
508
+ chainId,
509
+ address: collectionAddress,
510
+ uid: premintConfig.uid,
511
+ });
512
+
500
513
  return {
501
514
  premintConfig,
502
515
  premintConfigVersion,
@@ -504,6 +517,7 @@ function makePremintReturn<T extends PremintConfigVersion>({
504
517
  collectionAddress,
505
518
  signAndSubmit,
506
519
  submit,
520
+ urls,
507
521
  };
508
522
  }
509
523
 
@@ -656,10 +670,9 @@ async function updatePremint({
656
670
  chainId: number;
657
671
  }) {
658
672
  const {
659
- premintConfig,
673
+ premint: { premintConfig, premintConfigVersion },
660
674
  collection: collectionCreationConfig,
661
- premintConfigVersion,
662
- } = await apiClient.getSignature({
675
+ } = await apiClient.get({
663
676
  collectionAddress: collection,
664
677
  uid: uid,
665
678
  });
@@ -703,11 +716,10 @@ async function deletePremint({
703
716
  chainId: number;
704
717
  }) {
705
718
  const {
706
- premintConfig,
707
- premintConfigVersion,
719
+ premint: { premintConfig, premintConfigVersion },
708
720
  collection: collectionCreationConfig,
709
721
  collectionAddress,
710
- } = await apiClient.getSignature({
722
+ } = await apiClient.get({
711
723
  collectionAddress: collection,
712
724
  uid: uid,
713
725
  });
@@ -781,32 +793,51 @@ export async function collectPremint({
781
793
  throw new Error("Quantity to mint cannot be below 1");
782
794
  }
783
795
 
784
- const {
785
- premintConfig,
786
- premintConfigVersion,
787
- collection,
788
- collectionAddress,
789
- signature,
790
- } = await premintGetter.getSignature({
796
+ const premint = await premintGetter.get({
791
797
  collectionAddress: tokenContract,
792
798
  uid,
793
799
  });
794
800
 
795
- const numberToMint = BigInt(quantityToMint || 1);
796
-
797
- if (premintConfigVersion === PremintConfigVersion.V3) {
798
- throw new Error("PremintV3 not supported in premint SDK");
799
- }
801
+ const mintFee = await getPremintMintFee({
802
+ tokenContract,
803
+ publicClient,
804
+ });
800
805
 
801
- const value = (
802
- await getPremintMintCosts({
803
- tokenContract,
804
- quantityToMint: numberToMint,
805
- publicClient,
806
- tokenPrice: premintConfig.tokenConfig.pricePerToken,
807
- })
808
- ).totalCostEth;
806
+ return buildPremintMintCall({
807
+ mintArguments: {
808
+ minterAccount,
809
+ quantityToMint,
810
+ firstMinter,
811
+ mintComment,
812
+ mintRecipient,
813
+ mintReferral,
814
+ },
815
+ mintFee,
816
+ premint,
817
+ });
818
+ }
809
819
 
820
+ export const buildPremintMintCall = ({
821
+ mintArguments: {
822
+ minterAccount,
823
+ mintComment = "",
824
+ mintRecipient,
825
+ mintReferral,
826
+ firstMinter,
827
+ quantityToMint,
828
+ },
829
+ premint: { collection, collectionAddress, premint, signature },
830
+ mintFee,
831
+ }: {
832
+ mintArguments: Omit<MakeMintParametersArgumentsBase, "tokenContract"> & {
833
+ firstMinter?: Address;
834
+ };
835
+ premint: Pick<
836
+ PremintFromApi,
837
+ "collection" | "collectionAddress" | "premint" | "signature"
838
+ >;
839
+ mintFee: bigint;
840
+ }): SimulateContractParametersWithAccount => {
810
841
  const mintArgumentsContract: PremintMintArguments = {
811
842
  mintComment: mintComment,
812
843
  mintRecipient: mintRecipientOrAccount({
@@ -829,6 +860,14 @@ export async function collectPremint({
829
860
  firstMinter ||
830
861
  (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
831
862
 
863
+ if (premint.premintConfigVersion === PremintConfigVersion.V3) {
864
+ throw new Error("PremintV3 not supported in premint SDK");
865
+ }
866
+
867
+ const value =
868
+ (mintFee + premint.premintConfig.tokenConfig.pricePerToken) *
869
+ BigInt(quantityToMint);
870
+
832
871
  return makeContractParameters({
833
872
  account: minterAccount,
834
873
  abi: zoraCreator1155PremintExecutorImplABI,
@@ -838,18 +877,15 @@ export async function collectPremint({
838
877
  args: [
839
878
  collectionOrEmpty,
840
879
  collectionAddressToSubmit,
841
- encodePremintConfig({
842
- premintConfig,
843
- premintConfigVersion,
844
- }),
880
+ encodePremintConfig(premint),
845
881
  signature,
846
- numberToMint,
882
+ BigInt(quantityToMint),
847
883
  mintArgumentsContract,
848
884
  firstMinterToSubmit,
849
885
  zeroAddress,
850
886
  ],
851
887
  });
852
- }
888
+ };
853
889
 
854
890
  export function makeUrls({
855
891
  uid,