@zoralabs/protocol-sdk 0.3.3 → 0.3.5
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 +28 -0
- package/README.md +7 -26
- package/dist/anvil.d.ts +4 -2
- package/dist/anvil.d.ts.map +1 -1
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs +476 -323
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +447 -298
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +16 -213
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +7 -226
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +63 -17
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +106 -19
- package/dist/premint/preminter.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/anvil.ts +7 -4
- package/src/constants.ts +7 -0
- package/src/create/1155-create-helper.ts +1 -1
- package/src/mint/mint-api-client.ts +79 -53
- package/src/mint/mint-client.test.ts +9 -11
- package/src/mint/mint-client.ts +50 -215
- package/src/premint/premint-client.test.ts +9 -8
- package/src/premint/premint-client.ts +113 -61
- package/src/premint/preminter.test.ts +207 -130
- package/src/premint/preminter.ts +388 -51
- package/src/types.ts +1 -0
- package/tsconfig.json +2 -17
- package/dist/apis/generated/discover-api-types.d.ts +0 -2131
- package/dist/apis/generated/discover-api-types.d.ts.map +0 -1
- package/src/apis/generated/discover-api-types.ts +0 -2180
package/src/mint/mint-client.ts
CHANGED
|
@@ -4,18 +4,19 @@ import {
|
|
|
4
4
|
PublicClient,
|
|
5
5
|
createPublicClient,
|
|
6
6
|
encodeAbiParameters,
|
|
7
|
-
parseAbi,
|
|
8
7
|
parseAbiParameters,
|
|
9
8
|
zeroAddress,
|
|
10
9
|
http,
|
|
11
10
|
} from "viem";
|
|
12
11
|
import { IHttpClient } from "../apis/http-api-base";
|
|
13
|
-
import { MintAPIClient,
|
|
12
|
+
import { MintAPIClient, SalesConfigAndTokenInfo } from "./mint-api-client";
|
|
14
13
|
import { SimulateContractParameters } from "viem";
|
|
15
14
|
import {
|
|
16
15
|
zoraCreator1155ImplABI,
|
|
17
16
|
zoraCreatorFixedPriceSaleStrategyAddress,
|
|
18
17
|
} from "@zoralabs/protocol-deployments";
|
|
18
|
+
import { GenericTokenIdTypes } from "src/types";
|
|
19
|
+
import { zora721Abi } from "src/constants";
|
|
19
20
|
|
|
20
21
|
class MintError extends Error {}
|
|
21
22
|
class MintInactiveError extends Error {}
|
|
@@ -32,11 +33,6 @@ type MintArguments = {
|
|
|
32
33
|
mintToAddress: Address;
|
|
33
34
|
};
|
|
34
35
|
|
|
35
|
-
const zora721Abi = parseAbi([
|
|
36
|
-
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
37
|
-
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)",
|
|
38
|
-
] as const);
|
|
39
|
-
|
|
40
36
|
class MintClient {
|
|
41
37
|
readonly apiClient: MintAPIClient;
|
|
42
38
|
readonly publicClient: PublicClient;
|
|
@@ -51,25 +47,6 @@ class MintClient {
|
|
|
51
47
|
publicClient || createPublicClient({ chain, transport: http() });
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
/**
|
|
55
|
-
* Gets mintable information for a given token
|
|
56
|
-
* @param param0.tokenContract The contract address of the token to mint.
|
|
57
|
-
* @param param0.tokenId The token id to mint.
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
async getMintable({
|
|
61
|
-
tokenContract,
|
|
62
|
-
tokenId,
|
|
63
|
-
}: {
|
|
64
|
-
tokenContract: Address;
|
|
65
|
-
tokenId?: bigint | number | string;
|
|
66
|
-
}) {
|
|
67
|
-
return await this.apiClient.getMintableForToken({
|
|
68
|
-
tokenContract,
|
|
69
|
-
tokenId: tokenId?.toString(),
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
50
|
/**
|
|
74
51
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
75
52
|
* @param param0.minterAccount The account that will mint the token.
|
|
@@ -81,7 +58,8 @@ class MintClient {
|
|
|
81
58
|
...rest
|
|
82
59
|
}: {
|
|
83
60
|
minterAccount: Address;
|
|
84
|
-
|
|
61
|
+
tokenAddress: Address;
|
|
62
|
+
tokenId?: GenericTokenIdTypes;
|
|
85
63
|
mintArguments: MintArguments;
|
|
86
64
|
}): Promise<SimulateContractParameters> {
|
|
87
65
|
return makePrepareMintTokenParams({
|
|
@@ -90,41 +68,6 @@ class MintClient {
|
|
|
90
68
|
publicClient: this.publicClient,
|
|
91
69
|
});
|
|
92
70
|
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Returns the mintFee, sale fee, and total cost of minting x quantities of a token.
|
|
96
|
-
* @param param0.mintable The mintable token to mint.
|
|
97
|
-
* @param param0.quantityToMint The quantity of tokens to mint.
|
|
98
|
-
* @returns
|
|
99
|
-
*/
|
|
100
|
-
async getMintCosts({
|
|
101
|
-
mintable,
|
|
102
|
-
quantityToMint,
|
|
103
|
-
}: {
|
|
104
|
-
mintable: Mintable;
|
|
105
|
-
quantityToMint: number | bigint;
|
|
106
|
-
}): Promise<MintCosts> {
|
|
107
|
-
const mintContextType = validateMintableAndGetContextType(mintable);
|
|
108
|
-
|
|
109
|
-
if (mintContextType === "zora_create_1155") {
|
|
110
|
-
return await get1155MintCosts({
|
|
111
|
-
mintable,
|
|
112
|
-
publicClient: this.publicClient,
|
|
113
|
-
quantityToMint: BigInt(quantityToMint),
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
if (mintContextType === "zora_create") {
|
|
117
|
-
return await get721MintCosts({
|
|
118
|
-
mintable,
|
|
119
|
-
publicClient: this.publicClient,
|
|
120
|
-
quantityToMint: BigInt(quantityToMint),
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
throw new MintError(
|
|
125
|
-
`Mintable type ${mintContextType} is currently unsupported.`,
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
71
|
}
|
|
129
72
|
|
|
130
73
|
/**
|
|
@@ -148,128 +91,60 @@ export function createMintClient({
|
|
|
148
91
|
|
|
149
92
|
export type TMintClient = ReturnType<typeof createMintClient>;
|
|
150
93
|
|
|
151
|
-
function validateMintableAndGetContextType(
|
|
152
|
-
mintable: MintableGetTokenResponse | undefined,
|
|
153
|
-
) {
|
|
154
|
-
if (!mintable) {
|
|
155
|
-
throw new MintError("No mintable found");
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (!mintable.is_active) {
|
|
159
|
-
throw new MintInactiveError("Minting token is inactive");
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (!mintable.mint_context) {
|
|
163
|
-
throw new MintError("No minting context data from zora API");
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
!["zora_create", "zora_create_1155"].includes(
|
|
168
|
-
mintable.mint_context?.mint_context_type!,
|
|
169
|
-
)
|
|
170
|
-
) {
|
|
171
|
-
throw new MintError(
|
|
172
|
-
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`,
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return mintable.mint_context.mint_context_type;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
94
|
async function makePrepareMintTokenParams({
|
|
180
95
|
publicClient,
|
|
181
|
-
mintable,
|
|
182
96
|
apiClient,
|
|
97
|
+
tokenId,
|
|
98
|
+
tokenAddress,
|
|
183
99
|
...rest
|
|
184
100
|
}: {
|
|
185
101
|
publicClient: PublicClient;
|
|
186
102
|
minterAccount: Address;
|
|
187
|
-
|
|
103
|
+
tokenId?: GenericTokenIdTypes;
|
|
104
|
+
tokenAddress: Address;
|
|
188
105
|
mintArguments: MintArguments;
|
|
189
106
|
apiClient: MintAPIClient;
|
|
190
107
|
}): Promise<SimulateContractParameters> {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
108
|
+
const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
|
|
109
|
+
tokenId,
|
|
110
|
+
tokenAddress,
|
|
111
|
+
});
|
|
194
112
|
|
|
195
|
-
if (
|
|
196
|
-
return makePrepareMint1155TokenParams({
|
|
197
|
-
apiClient,
|
|
198
|
-
publicClient: thisPublicClient,
|
|
199
|
-
mintable,
|
|
200
|
-
mintContextType,
|
|
201
|
-
...rest,
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
if (mintContextType === "zora_create") {
|
|
113
|
+
if (tokenId === undefined) {
|
|
205
114
|
return makePrepareMint721TokenParams({
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
mintContextType,
|
|
115
|
+
salesConfigAndTokenInfo,
|
|
116
|
+
tokenAddress,
|
|
209
117
|
...rest,
|
|
210
118
|
});
|
|
211
119
|
}
|
|
212
120
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
async function get721MintCosts({
|
|
219
|
-
mintable,
|
|
220
|
-
publicClient,
|
|
221
|
-
quantityToMint,
|
|
222
|
-
}: {
|
|
223
|
-
mintable: MintableGetTokenResponse;
|
|
224
|
-
publicClient: PublicClient;
|
|
225
|
-
quantityToMint: bigint;
|
|
226
|
-
}): Promise<MintCosts> {
|
|
227
|
-
const address = mintable.collection.address as Address;
|
|
228
|
-
|
|
229
|
-
const [_, mintFee] = await publicClient.readContract({
|
|
230
|
-
abi: zora721Abi,
|
|
231
|
-
address,
|
|
232
|
-
functionName: "zoraFeeForAmount",
|
|
233
|
-
args: [BigInt(quantityToMint)],
|
|
121
|
+
return makePrepareMint1155TokenParams({
|
|
122
|
+
salesConfigAndTokenInfo,
|
|
123
|
+
tokenAddress,
|
|
124
|
+
tokenId,
|
|
125
|
+
...rest,
|
|
234
126
|
});
|
|
235
|
-
|
|
236
|
-
const tokenPurchaseCost =
|
|
237
|
-
BigInt(mintable.cost.native_price.raw) * quantityToMint;
|
|
238
|
-
return {
|
|
239
|
-
mintFee,
|
|
240
|
-
tokenPurchaseCost,
|
|
241
|
-
totalCost: mintFee + tokenPurchaseCost,
|
|
242
|
-
};
|
|
243
127
|
}
|
|
244
128
|
|
|
245
129
|
async function makePrepareMint721TokenParams({
|
|
246
|
-
|
|
130
|
+
tokenAddress,
|
|
131
|
+
salesConfigAndTokenInfo,
|
|
247
132
|
minterAccount,
|
|
248
|
-
mintable,
|
|
249
|
-
mintContextType,
|
|
250
133
|
mintArguments,
|
|
251
134
|
}: {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
mintContextType: ReturnType<typeof validateMintableAndGetContextType>;
|
|
135
|
+
tokenAddress: Address;
|
|
136
|
+
salesConfigAndTokenInfo: SalesConfigAndTokenInfo;
|
|
255
137
|
minterAccount: Address;
|
|
256
138
|
mintArguments: MintArguments;
|
|
257
139
|
}): Promise<SimulateContractParameters<typeof zora721Abi, "mintWithRewards">> {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const mintValue = (
|
|
263
|
-
await get721MintCosts({
|
|
264
|
-
mintable,
|
|
265
|
-
publicClient,
|
|
266
|
-
quantityToMint: BigInt(mintArguments.quantityToMint),
|
|
267
|
-
})
|
|
268
|
-
).totalCost;
|
|
140
|
+
const mintValue = getMintCosts({
|
|
141
|
+
salesConfigAndTokenInfo,
|
|
142
|
+
quantityToMint: BigInt(mintArguments.quantityToMint),
|
|
143
|
+
}).totalCost;
|
|
269
144
|
|
|
270
145
|
const result = {
|
|
271
146
|
abi: zora721Abi,
|
|
272
|
-
address:
|
|
147
|
+
address: tokenAddress,
|
|
273
148
|
account: minterAccount,
|
|
274
149
|
functionName: "mintWithRewards",
|
|
275
150
|
value: mintValue,
|
|
@@ -284,45 +159,23 @@ async function makePrepareMint721TokenParams({
|
|
|
284
159
|
return result;
|
|
285
160
|
}
|
|
286
161
|
|
|
287
|
-
async function get1155MintFee({
|
|
288
|
-
collectionAddress,
|
|
289
|
-
publicClient,
|
|
290
|
-
}: {
|
|
291
|
-
collectionAddress: Address;
|
|
292
|
-
publicClient: PublicClient;
|
|
293
|
-
}) {
|
|
294
|
-
return await publicClient.readContract({
|
|
295
|
-
abi: zoraCreator1155ImplABI,
|
|
296
|
-
functionName: "mintFee",
|
|
297
|
-
address: collectionAddress,
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
|
|
301
162
|
export type MintCosts = {
|
|
302
163
|
mintFee: bigint;
|
|
303
164
|
tokenPurchaseCost: bigint;
|
|
304
165
|
totalCost: bigint;
|
|
305
166
|
};
|
|
306
167
|
|
|
307
|
-
export
|
|
308
|
-
|
|
309
|
-
publicClient,
|
|
168
|
+
export function getMintCosts({
|
|
169
|
+
salesConfigAndTokenInfo,
|
|
310
170
|
quantityToMint,
|
|
311
171
|
}: {
|
|
312
|
-
|
|
313
|
-
publicClient: PublicClient;
|
|
172
|
+
salesConfigAndTokenInfo: SalesConfigAndTokenInfo;
|
|
314
173
|
quantityToMint: bigint;
|
|
315
|
-
}):
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
const mintFee = await get1155MintFee({
|
|
319
|
-
collectionAddress: address,
|
|
320
|
-
publicClient,
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
const mintFeeForTokens = mintFee * quantityToMint;
|
|
174
|
+
}): MintCosts {
|
|
175
|
+
const mintFeeForTokens =
|
|
176
|
+
salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
|
|
324
177
|
const tokenPurchaseCost =
|
|
325
|
-
BigInt(
|
|
178
|
+
BigInt(salesConfigAndTokenInfo.fixedPrice.pricePerToken) * quantityToMint;
|
|
326
179
|
|
|
327
180
|
return {
|
|
328
181
|
mintFee: mintFeeForTokens,
|
|
@@ -332,52 +185,36 @@ export async function get1155MintCosts({
|
|
|
332
185
|
}
|
|
333
186
|
|
|
334
187
|
async function makePrepareMint1155TokenParams({
|
|
335
|
-
|
|
336
|
-
|
|
188
|
+
tokenId,
|
|
189
|
+
salesConfigAndTokenInfo,
|
|
337
190
|
minterAccount,
|
|
338
|
-
|
|
339
|
-
mintContextType,
|
|
191
|
+
tokenAddress,
|
|
340
192
|
mintArguments,
|
|
341
193
|
}: {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
mintable: Mintable;
|
|
345
|
-
mintContextType: ReturnType<typeof validateMintableAndGetContextType>;
|
|
194
|
+
salesConfigAndTokenInfo: SalesConfigAndTokenInfo;
|
|
195
|
+
tokenId: GenericTokenIdTypes;
|
|
346
196
|
minterAccount: Address;
|
|
197
|
+
tokenAddress: Address;
|
|
347
198
|
mintArguments: MintArguments;
|
|
348
199
|
}) {
|
|
349
|
-
if (mintContextType !== "zora_create_1155") {
|
|
350
|
-
throw new Error("Minted token type must be for 1155");
|
|
351
|
-
}
|
|
352
|
-
|
|
353
200
|
const mintQuantity = BigInt(mintArguments.quantityToMint);
|
|
354
201
|
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
mintable,
|
|
360
|
-
publicClient,
|
|
361
|
-
quantityToMint: mintQuantity,
|
|
362
|
-
})
|
|
363
|
-
).totalCost;
|
|
364
|
-
|
|
365
|
-
const tokenFixedPriceMinter = await apiClient.getSalesConfigFixedPrice({
|
|
366
|
-
contractAddress: address,
|
|
367
|
-
tokenId: BigInt(mintable.token_id!),
|
|
368
|
-
});
|
|
202
|
+
const mintValue = getMintCosts({
|
|
203
|
+
salesConfigAndTokenInfo,
|
|
204
|
+
quantityToMint: mintQuantity,
|
|
205
|
+
}).totalCost;
|
|
369
206
|
|
|
370
207
|
const result = {
|
|
371
208
|
abi: zoraCreator1155ImplABI,
|
|
372
209
|
functionName: "mintWithRewards",
|
|
373
210
|
account: minterAccount,
|
|
374
211
|
value: mintValue,
|
|
375
|
-
address,
|
|
212
|
+
address: tokenAddress,
|
|
376
213
|
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
377
214
|
args: [
|
|
378
|
-
(
|
|
215
|
+
(salesConfigAndTokenInfo?.fixedPrice.address ||
|
|
379
216
|
zoraCreatorFixedPriceSaleStrategyAddress[999]) as Address,
|
|
380
|
-
BigInt(
|
|
217
|
+
BigInt(tokenId),
|
|
381
218
|
mintQuantity,
|
|
382
219
|
encodeAbiParameters(parseAbiParameters("address, string"), [
|
|
383
220
|
mintArguments.mintToAddress,
|
|
@@ -392,5 +229,3 @@ async function makePrepareMint1155TokenParams({
|
|
|
392
229
|
|
|
393
230
|
return result;
|
|
394
231
|
}
|
|
395
|
-
|
|
396
|
-
export type Mintable = MintableGetTokenResponse;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { foundry } from "viem/chains";
|
|
2
2
|
import { describe, expect, vi } from "vitest";
|
|
3
3
|
import { createPremintClient } from "./premint-client";
|
|
4
|
-
import { anvilTest } from "src/anvil";
|
|
4
|
+
import { anvilTest, forkUrls, makeAnvilTest } from "src/anvil";
|
|
5
|
+
import { PremintSignatureResponse } from "./premint-api-client";
|
|
5
6
|
|
|
6
7
|
describe("ZoraCreator1155Premint", () => {
|
|
7
|
-
|
|
8
|
+
makeAnvilTest({
|
|
9
|
+
forkUrl: forkUrls.zoraGoerli,
|
|
10
|
+
forkBlockNumber: 1763437,
|
|
11
|
+
})(
|
|
8
12
|
"can sign on the forked premint contract",
|
|
9
13
|
async ({ viemClients: { walletClient, publicClient } }) => {
|
|
10
14
|
const [deployerAccount] = await walletClient.getAddresses();
|
|
@@ -76,7 +80,7 @@ describe("ZoraCreator1155Premint", () => {
|
|
|
76
80
|
publicClient,
|
|
77
81
|
});
|
|
78
82
|
|
|
79
|
-
const premintData = {
|
|
83
|
+
const premintData: PremintSignatureResponse = {
|
|
80
84
|
collection: {
|
|
81
85
|
contractAdmin: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
82
86
|
contractName: "Testing Contract",
|
|
@@ -101,15 +105,12 @@ describe("ZoraCreator1155Premint", () => {
|
|
|
101
105
|
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
|
|
102
106
|
},
|
|
103
107
|
},
|
|
104
|
-
chain_name: "ZORA-
|
|
108
|
+
chain_name: "ZORA-GOERLI",
|
|
105
109
|
signature:
|
|
106
110
|
"0x588d19641de9ba1dade4d2bb5387c8dc96f4a990fef69787534b60caead759e6334975a6be10a796da948cd7d1d4f5580b3f84d49d9fa4e0b41c97759507975a1c",
|
|
107
111
|
} as const;
|
|
108
112
|
|
|
109
|
-
const signatureValid = await premintClient.isValidSignature(
|
|
110
|
-
// @ts-ignore: Fix enum type
|
|
111
|
-
data: premintData,
|
|
112
|
-
});
|
|
113
|
+
const signatureValid = await premintClient.isValidSignature(premintData);
|
|
113
114
|
expect(signatureValid.isValid).toBe(true);
|
|
114
115
|
},
|
|
115
116
|
);
|