@zoralabs/protocol-sdk 0.3.4 → 0.4.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 (44) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +34 -0
  3. package/README.md +30 -58
  4. package/dist/anvil.d.ts +4 -2
  5. package/dist/anvil.d.ts.map +1 -1
  6. package/dist/constants.d.ts +32 -0
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/index.cjs +819 -518
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +788 -493
  13. package/dist/index.js.map +1 -1
  14. package/dist/mint/mint-api-client.d.ts +16 -216
  15. package/dist/mint/mint-api-client.d.ts.map +1 -1
  16. package/dist/mint/mint-client.d.ts +7 -227
  17. package/dist/mint/mint-client.d.ts.map +1 -1
  18. package/dist/premint/contract-types.d.ts +125 -0
  19. package/dist/premint/contract-types.d.ts.map +1 -0
  20. package/dist/premint/premint-api-client.d.ts +14 -7
  21. package/dist/premint/premint-api-client.d.ts.map +1 -1
  22. package/dist/premint/premint-client.d.ts +45 -115
  23. package/dist/premint/premint-client.d.ts.map +1 -1
  24. package/dist/premint/preminter.d.ts +102 -21
  25. package/dist/premint/preminter.d.ts.map +1 -1
  26. package/dist/types.d.ts +2 -0
  27. package/dist/types.d.ts.map +1 -0
  28. package/package.json +1 -1
  29. package/src/anvil.ts +7 -4
  30. package/src/constants.ts +7 -0
  31. package/src/index.ts +2 -0
  32. package/src/mint/mint-api-client.ts +72 -68
  33. package/src/mint/mint-client.test.ts +9 -11
  34. package/src/mint/mint-client.ts +51 -221
  35. package/src/premint/contract-types.ts +109 -0
  36. package/src/premint/premint-api-client.ts +162 -22
  37. package/src/premint/premint-client.test.ts +186 -84
  38. package/src/premint/premint-client.ts +357 -289
  39. package/src/premint/preminter.test.ts +209 -130
  40. package/src/premint/preminter.ts +377 -54
  41. package/src/types.ts +1 -0
  42. package/dist/apis/generated/discover-api-types.d.ts +0 -2131
  43. package/dist/apis/generated/discover-api-types.d.ts.map +0 -1
  44. package/src/apis/generated/discover-api-types.ts +0 -2180
@@ -7,9 +7,9 @@ $ tsup
7
7
  CLI Cleaning output folder
8
8
  CJS Build start
9
9
  ESM Build start
10
- ESM dist/index.js 37.02 KB
11
- ESM dist/index.js.map 74.33 KB
12
- ESM ⚡️ Build success in 34ms
13
- CJS dist/index.cjs 39.62 KB
14
- CJS dist/index.cjs.map 74.34 KB
15
- CJS ⚡️ Build success in 35ms
10
+ CJS dist/index.cjs 48.03 KB
11
+ CJS dist/index.cjs.map 93.11 KB
12
+ CJS ⚡️ Build success in 46ms
13
+ ESM dist/index.js 44.64 KB
14
+ ESM dist/index.js.map 93.23 KB
15
+ ESM ⚡️ Build success in 45ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @zoralabs/protocol-sdk
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 28884c9: \* `PremintClient` now takes a premint config v1 or v2, and a premint config version, for every call to create/update/delete a premint. PremintClient methods have been simplified and are easier to use - for example `createPremint` no longer allows to specify `deleted` = true. For `makeMintParameters` - it now just takes the uid and contract address (instead of full premint config)
8
+ - `PremintAPIClient` now converts entities to contract entities before returning them, and correspondingly expects them as contract entities when passed in. It internally converts them to backend entities before sending them to the backend.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [4b77307]
13
+ - @zoralabs/protocol-deployments@0.0.8
14
+
15
+ ## 0.3.5
16
+
17
+ ### Patch Changes
18
+
19
+ - 7eb5e3f: ### Changes to `preminter`
20
+
21
+ lower level `preminter.ts` now supports premint v2 by defining v2 typed data defintions.
22
+
23
+ - `isValidSignature` now takes either v1 or v2 of a premint config, along with the premint config version. and both recovers the signer address and validates if the signer can create a premint on the given contract.
24
+ - new function `premintTypedDataDefinition` which takes a premint config version and returns the signable typed data definition for that version
25
+ - new function `recoverCreatorFromCreatorAttribution` which recovers the creator address from a `CreatorAttribution` event
26
+ - new function `supportsPremintVersion` which checks if a given token contract supports a given premint config version
27
+ - new function `tryRecoverPremintSigner` which takes a premint config version and a premint signature, and tries to recover the signer address from the signature. If the signature is invalid, it returns undefined.
28
+
29
+ ### Changes to PremintClient
30
+
31
+ `PremintClient` creation, updating, and deletion now take both premint config v1 and v2, but currently rejects them until the backend api supports creating v2 premints.
32
+
33
+ - `isValidSignature` now just takes the data directly as a param, instead of `{data}`
34
+
35
+ - 27a2e23: Fix reading the FIXED_PRICE_MINTER from the subgraph
36
+
3
37
  ## 0.3.4
4
38
 
5
39
  ### Patch Changes
package/README.md CHANGED
@@ -43,16 +43,11 @@ async function mintNFT({
43
43
  }) {
44
44
  const mintClient = createMintClient({chain: walletClient.chain!});
45
45
 
46
- // get mintable information about the token.
47
- const mintable = await mintClient.getMintable({
48
- tokenContract,
49
- tokenId,
50
- });
51
-
52
46
  // prepare the mint transaction, which can be simulated via an rpc with the public client.
53
47
  const prepared = await mintClient.makePrepareMintTokenParams({
54
48
  // token to mint
55
- mintable,
49
+ tokenContract,
50
+ tokenId,
56
51
  mintArguments: {
57
52
  // address that will receive the token
58
53
  mintToAddress,
@@ -81,7 +76,7 @@ async function mintNFT({
81
76
  #### Using wagmi
82
77
 
83
78
  ```tsx
84
- import {createMintClient, Mintable} from "@zoralabs/protocol-sdk";
79
+ import {createMintClient} from "@zoralabs/protocol-sdk";
85
80
  import {useEffect, useMemo, useState} from "react";
86
81
  import {BaseError, SimulateContractParameters, stringify} from "viem";
87
82
  import {Address, useAccount, useContractWrite, useNetwork, usePrepareContractWrite, usePublicClient, useWaitForTransaction} from "wagmi";
@@ -104,33 +99,19 @@ export const Mint = ({tokenId, tokenContract}: {tokenId: string; tokenContract:
104
99
  // value will be set by the form
105
100
  const [quantityToMint, setQuantityToMint] = useState<number>(1);
106
101
 
107
- // fetched mintable info from the sdk
108
- const [mintable, setMintable] = useState<Mintable>();
109
-
110
- useEffect(() => {
111
- // fetch the mintable token info
112
- const fetchMintable = async () => {
113
- if (mintClient) {
114
- const mintable = await mintClient.getMintable({tokenId, tokenContract});
115
- setMintable(mintable);
116
- }
117
- };
118
-
119
- fetchMintable();
120
- }, [mintClient, tokenId, tokenContract]);
121
-
122
102
  // params for the prepare contract write hook
123
103
  const [params, setParams] = useState<SimulateContractParameters>();
124
104
 
125
105
  const {address} = useAccount();
126
106
 
127
107
  useEffect(() => {
128
- if (!mintable || !mintClient || !address) return;
108
+ if (!mintClient || !address) return;
129
109
 
130
110
  const makeParams = async () => {
131
111
  // make the params for the prepare contract write hook
132
112
  const params = await mintClient.makePrepareMintTokenParams({
133
- mintable,
113
+ tokenId,
114
+ tokenContract,
134
115
  minterAccount: address,
135
116
  mintArguments: {
136
117
  mintToAddress: address,
@@ -141,7 +122,7 @@ export const Mint = ({tokenId, tokenContract}: {tokenId: string; tokenContract:
141
122
  };
142
123
 
143
124
  makeParams();
144
- }, [mintable, mintClient, address, quantityToMint]);
125
+ }, [mintClient, address, quantityToMint]);
145
126
 
146
127
  const {config} = usePrepareContractWrite(params);
147
128
 
@@ -222,32 +203,33 @@ import type {Address, PublicClient, WalletClient} from "viem";
222
203
 
223
204
  async function createForFree({
224
205
  walletClient,
206
+ publicClient,
225
207
  creatorAccount,
226
208
  }: {
227
209
  // wallet client that will submit the transaction
228
210
  walletClient: WalletClient;
211
+ // public client that will simulate the transaction
212
+ publicClient: PublicClient;
229
213
  // address of the token contract
230
214
  creatorAccount: Address;
231
215
  }) {
232
- const premintClient = createPremintClient({ chain: walletClient.chain! });
216
+ const premintClient = createPremintClient({chain: walletClient.chain!, publicClient});
233
217
 
234
218
  // create and sign a free token creation.
235
219
  const createdPremint = await premintClient.createPremint({
236
220
  walletClient,
237
- account: creatorAccount,
221
+ creatorAccount,
238
222
  // if true, will validate that the creator is authorized to create premints on the contract.
239
223
  checkSignature: true,
240
224
  // collection info of collection to create
241
225
  collection: {
242
226
  contractAdmin: creatorAccount,
243
227
  contractName: "Testing Contract",
244
- contractURI:
245
- "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
228
+ contractURI: "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
246
229
  },
247
230
  // token info of token to create
248
- token: {
249
- tokenURI:
250
- "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
231
+ tokenCreationConfig: {
232
+ tokenURI: "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
251
233
  },
252
234
  });
253
235
 
@@ -255,12 +237,13 @@ async function createForFree({
255
237
  const premintCollectionAddress = createdPremint.verifyingContract;
256
238
 
257
239
  return {
258
- // unique id of created premint, which can be used later to
240
+ // unique id of created premint, which can be used later to
259
241
  // update or delete the premint
260
242
  uid: premintUid,
261
- tokenContract: premintCollectionAddress,
262
- }
263
- }
243
+ tokenContractAddress: premintCollectionAddress,
244
+ };
245
+ }
246
+
264
247
  ```
265
248
 
266
249
  ### Updating a token that was created for free (before it was brought onchain):
@@ -272,8 +255,7 @@ import {createPremintClient} from "@zoralabs/protocol-sdk";
272
255
  import type {Address, PublicClient, WalletClient} from "viem";
273
256
 
274
257
  async function updateCreatedForFreeToken(walletClient: WalletClient, premintUid: number) {
275
- // Create premint API object passing in the current wallet chain (only zora and zora testnet are supported currently).
276
- const premintClient = createPremintClient({ chain: walletClient.chain! });
258
+ const premintClient = createPremintClient({chain: walletClient.chain!});
277
259
 
278
260
  // sign a message to update the created for free token, and store the update
279
261
  await premintClient.updatePremint({
@@ -282,9 +264,8 @@ async function updateCreatedForFreeToken(walletClient: WalletClient, premintUid:
282
264
  // WalletClient doing the signature
283
265
  walletClient,
284
266
  // Token information, falls back to defaults set in DefaultMintArguments.
285
- token: {
286
- tokenURI:
287
- "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
267
+ tokenConfigUpdates: {
268
+ tokenURI: "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
288
269
  },
289
270
  });
290
271
  }
@@ -295,11 +276,8 @@ async function updateCreatedForFreeToken(walletClient: WalletClient, premintUid:
295
276
  Before a token that was created for free is brought onchain, it can be deleted by the original creator of that token, by having that creator sign a message indicating the deletion:
296
277
 
297
278
  ```ts
298
- import {createPremintClient} from "@zoralabs/protocol-sdk";
299
- import type {Address, PublicClient, WalletClient} from "viem";
300
-
301
279
  async function deleteCreatedForFreeToken(walletClient: WalletClient) {
302
- const premintClient = createPremintClient({ chain: walletClient.chain! });
280
+ const premintClient = createPremintClient({chain: walletClient.chain!});
303
281
 
304
282
  // sign a message to delete the premint, and store the deletion
305
283
  await premintClient.deletePremint({
@@ -318,19 +296,13 @@ async function deleteCreatedForFreeToken(walletClient: WalletClient) {
318
296
  import {createPremintClient} from "@zoralabs/protocol-sdk";
319
297
  import type {Address, PublicClient, WalletClient} from "viem";
320
298
 
321
- async function mintCreatedForFreeToken(
322
- walletClient: WalletClient,
323
- publicClient: PublicClient,
324
- minterAccount: Address,
325
- ) {
326
- const premintClient = createPremintClient({ chain: walletClient.chain! });
299
+ async function mintCreatedForFreeToken(walletClient: WalletClient, publicClient: PublicClient, minterAccount: Address) {
300
+ const premintClient = createPremintClient({chain: walletClient.chain!});
327
301
 
328
302
  const simulateContractParameters = await premintClient.makeMintParameters({
329
303
  account: minterAccount,
330
- data: await premintClient.getPremintData({
331
- address: "0xf8dA7f53c283d898818af7FB9d98103F559bDac2",
332
- uid: 3,
333
- }),
304
+ tokenContract: "0xf8dA7f53c283d898818af7FB9d98103F559bDac2",
305
+ uid: 3,
334
306
  mintArguments: {
335
307
  quantityToMint: 1,
336
308
  mintComment: "",
@@ -338,7 +310,7 @@ async function mintCreatedForFreeToken(
338
310
  });
339
311
 
340
312
  // simulate the transaction and get any validation errors
341
- const { request } = await publicClient.simulateContract(simulateContractParameters);
313
+ const {request} = await publicClient.simulateContract(simulateContractParameters);
342
314
 
343
315
  // submit the transaction to the network
344
316
  const txHash = await walletClient.writeContract(request);
@@ -346,7 +318,7 @@ async function mintCreatedForFreeToken(
346
318
  // wait for the transaction to be complete
347
319
  const receipt = await publicClient.waitForTransactionReceipt({hash: txHash});
348
320
 
349
- const { urls } = await premintClient.getDataFromPremintReceipt(receipt);
321
+ const {urls} = await premintClient.getDataFromPremintReceipt(receipt);
350
322
 
351
323
  // block explorer url:
352
324
  console.log(urls.explorer);
package/dist/anvil.d.ts CHANGED
@@ -6,10 +6,11 @@ export interface AnvilViemClientsTest {
6
6
  testClient: TestClient;
7
7
  };
8
8
  }
9
- export declare const makeAnvilTest: ({ forkUrl, forkBlockNumber, }: {
9
+ export type AnvilTestForkSettings = {
10
10
  forkUrl: string;
11
11
  forkBlockNumber: number;
12
- }) => import("@vitest/runner/dist/tasks-e594cd24").e<{
12
+ };
13
+ export declare const makeAnvilTest: ({ forkUrl, forkBlockNumber, }: AnvilTestForkSettings) => import("@vitest/runner/dist/tasks-e594cd24").e<{
13
14
  viemClients: {
14
15
  walletClient: WalletClient;
15
16
  publicClient: PublicClient;
@@ -19,6 +20,7 @@ export declare const makeAnvilTest: ({ forkUrl, forkBlockNumber, }: {
19
20
  export declare const forkUrls: {
20
21
  zoraMainnet: string;
21
22
  zoraGoerli: string;
23
+ zoraSepolia: string;
22
24
  };
23
25
  export declare const anvilTest: import("@vitest/runner/dist/tasks-e594cd24").e<{
24
26
  viemClients: {
@@ -1 +1 @@
1
- {"version":3,"file":"anvil.d.ts","sourceRoot":"","sources":["../src/anvil.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EAKb,MAAM,MAAM,CAAC;AAGd,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE;QACX,YAAY,EAAE,YAAY,CAAC;QAC3B,YAAY,EAAE,YAAY,CAAC;QAC3B,UAAU,EAAE,UAAU,CAAC;KACxB,CAAC;CACH;AAUD,eAAO,MAAM,aAAa;aAIf,MAAM;qBACE,MAAM;;;sBAnBP,YAAY;sBACZ,YAAY;oBACd,UAAU;;EAwEtB,CAAC;AAEL,eAAO,MAAM,QAAQ;;;CAGpB,CAAC;AAEF,eAAO,MAAM,SAAS;;sBAjFJ,YAAY;sBACZ,YAAY;oBACd,UAAU;;EAkFxB,CAAC"}
1
+ {"version":3,"file":"anvil.d.ts","sourceRoot":"","sources":["../src/anvil.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EAKb,MAAM,MAAM,CAAC;AAGd,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE;QACX,YAAY,EAAE,YAAY,CAAC;QAC3B,YAAY,EAAE,YAAY,CAAC;QAC3B,UAAU,EAAE,UAAU,CAAC;KACxB,CAAC;CACH;AAUD,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,aAAa,kCAGvB,qBAAqB;;sBAtBN,YAAY;sBACZ,YAAY;oBACd,UAAU;;EA0EtB,CAAC;AAEL,eAAO,MAAM,QAAQ;;;;CAIpB,CAAC;AAEF,eAAO,MAAM,SAAS;;sBApFJ,YAAY;sBACZ,YAAY;oBACd,UAAU;;EAqFxB,CAAC"}
@@ -1,4 +1,36 @@
1
1
  export declare const ZORA_API_BASE = "https://api.zora.co/";
2
2
  export declare const OPEN_EDITION_MINT_SIZE: bigint;
3
3
  export declare function getSubgraph(name: string, version: string): string;
4
+ export declare const zora721Abi: readonly [{
5
+ readonly name: "mintWithRewards";
6
+ readonly type: "function";
7
+ readonly stateMutability: "payable";
8
+ readonly inputs: readonly [{
9
+ readonly type: "address";
10
+ readonly name: "recipient";
11
+ }, {
12
+ readonly type: "uint256";
13
+ readonly name: "quantity";
14
+ }, {
15
+ readonly type: "string";
16
+ readonly name: "comment";
17
+ }, {
18
+ readonly type: "address";
19
+ readonly name: "mintReferral";
20
+ }];
21
+ readonly outputs: readonly [];
22
+ }, {
23
+ readonly name: "zoraFeeForAmount";
24
+ readonly type: "function";
25
+ readonly stateMutability: "view";
26
+ readonly inputs: readonly [{
27
+ readonly type: "uint256";
28
+ readonly name: "amount";
29
+ }];
30
+ readonly outputs: readonly [{
31
+ readonly type: "address";
32
+ }, {
33
+ readonly type: "uint256";
34
+ }];
35
+ }];
4
36
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,yBAAyB,CAAC;AACpD,eAAO,MAAM,sBAAsB,QAAiC,CAAC;AAMrE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjE"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,yBAAyB,CAAC;AACpD,eAAO,MAAM,sBAAsB,QAAiC,CAAC;AAMrE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGZ,CAAC"}