@zoralabs/protocol-sdk 0.9.4-PRE.0 → 0.9.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoralabs/protocol-sdk",
3
- "version": "0.9.4-PRE.0",
3
+ "version": "0.9.4",
4
4
  "repository": "https://github.com/ourzora/zora-protocol",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,18 +15,9 @@
15
15
  "default": "./dist/index.cjs"
16
16
  }
17
17
  },
18
- "scripts": {
19
- "build": "pnpm tsup",
20
- "prepack": "pnpm build",
21
- "test:js": "vitest src",
22
- "test:integration": "vitest test-integration",
23
- "generate-types": "echo 'npx is used here because this is a rare operation' && npx openapi-typescript https://api.zora.co/premint/openapi.json -o src/apis/generated/premint-api-types.ts",
24
- "prettier:write": "prettier --write 'src/**/*.ts' 'test-integration/**/*.ts'",
25
- "lint": "prettier --check 'src/**/*.ts' 'test-integration/**/*.ts'"
26
- },
27
18
  "dependencies": {
28
- "@zoralabs/protocol-deployments": "workspace:^",
29
- "abitype": "^1.0.2"
19
+ "abitype": "^1.0.2",
20
+ "@zoralabs/protocol-deployments": "^0.3.1"
30
21
  },
31
22
  "peerDependencies": {
32
23
  "viem": "^2.13.2"
@@ -37,7 +28,6 @@
37
28
  "@reservoir0x/reservoir-sdk": "^2.0.11",
38
29
  "@types/node": "^20.13.0",
39
30
  "@types/semver": "^7.5.8",
40
- "@zoralabs/tsconfig": "workspace:^",
41
31
  "graphql-prettier": "^1.0.6",
42
32
  "multiformats": "^13.2.0",
43
33
  "prettier": "^3.0.3",
@@ -46,6 +36,15 @@
46
36
  "tsup": "^7.2.0",
47
37
  "typescript": "^5.2.2",
48
38
  "vite": "^4.5.0",
49
- "vitest": "^2.0.5"
39
+ "vitest": "^2.0.5",
40
+ "@zoralabs/tsconfig": "^0.0.0"
41
+ },
42
+ "scripts": {
43
+ "build": "pnpm tsup",
44
+ "test:js": "vitest src",
45
+ "test:integration": "vitest test-integration",
46
+ "generate-types": "echo 'npx is used here because this is a rare operation' && npx openapi-typescript https://api.zora.co/premint/openapi.json -o src/apis/generated/premint-api-types.ts",
47
+ "prettier:write": "prettier --write 'src/**/*.ts' 'test-integration/**/*.ts'",
48
+ "lint": "prettier --check 'src/**/*.ts' 'test-integration/**/*.ts'"
50
49
  }
51
- }
50
+ }
@@ -79,15 +79,16 @@ export const post = async <T>(url: string, data: any) => {
79
79
  return (await response.json()) as T;
80
80
  };
81
81
 
82
+ const defaultShouldRetry = (err: any) => {
83
+ return err instanceof BadResponseError && err.status >= 500;
84
+ };
85
+
82
86
  export const retries = async <T>(
83
87
  tryFn: () => T,
84
88
  maxTries: number = 3,
85
89
  linearBackoffMS: number = 200,
90
+ shouldRetry: (err: any) => boolean = defaultShouldRetry,
86
91
  ): Promise<T> => {
87
- const shouldRetry = (err: any) => {
88
- return err instanceof BadResponseError && err.status >= 500;
89
- };
90
-
91
92
  return retriesGeneric({
92
93
  tryFn,
93
94
  maxTries,
@@ -10,21 +10,14 @@ import {
10
10
  zoraTimedSaleStrategyAddress,
11
11
  } from "@zoralabs/protocol-deployments";
12
12
  import { waitForSuccess } from "src/test-utils";
13
- import {
14
- Address,
15
- erc20Abi,
16
- parseEther,
17
- PublicClient,
18
- TransactionReceipt,
19
- } from "viem";
13
+ import { Address, erc20Abi, parseEther, PublicClient } from "viem";
20
14
  import { makePrepareMint1155TokenParams } from "src/mint/mint-transactions";
21
- import { forkUrls, makeAnvilTest } from "src/anvil";
15
+ import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
22
16
  import { zora } from "viem/chains";
23
17
  import { AllowList } from "src/allow-list/types";
24
18
  import { createAllowList } from "src/allow-list/allow-list-client";
25
19
  import { NewContractParams } from "./types";
26
20
  import { SubgraphContractGetter } from "./contract-getter";
27
- import { inspect } from "util";
28
21
 
29
22
  export const demoTokenMetadataURI =
30
23
  "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u";
@@ -59,14 +52,6 @@ const minterIsMinterOnToken = async ({
59
52
  });
60
53
  };
61
54
 
62
- function logFailure(receipt: TransactionReceipt) {
63
- if (receipt.status !== "success") {
64
- console.log("transaction failed");
65
- console.log(receipt.logs);
66
- console.log(inspect(receipt, { depth: 10 }));
67
- }
68
- }
69
-
70
55
  function randomNewContract(): NewContractParams {
71
56
  return {
72
57
  name: `testContract-${Math.round(Math.random() * 1_000_000)}`,
@@ -115,10 +100,11 @@ describe("create-helper", () => {
115
100
  });
116
101
 
117
102
  const { request } = await publicClient.simulateContract(parameters);
118
- const hash = await walletClient.writeContract(request);
119
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
120
- logFailure(receipt);
121
- expect(receipt.status).toBe("success");
103
+ const receipt = await writeContractWithRetries(
104
+ request,
105
+ walletClient,
106
+ publicClient,
107
+ );
122
108
  expect(receipt).not.toBeNull();
123
109
  expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
124
110
  expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n);
@@ -187,12 +173,8 @@ describe("create-helper", () => {
187
173
  });
188
174
 
189
175
  const { request } = await publicClient.simulateContract(parameters);
190
- const hash = await walletClient.writeContract(request);
191
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
192
176
 
193
- logFailure(receipt);
194
-
195
- expect(receipt.status).toBe("success");
177
+ await writeContractWithRetries(request, walletClient, publicClient);
196
178
 
197
179
  expect(
198
180
  await minterIsMinterOnToken({
@@ -234,13 +216,13 @@ describe("create-helper", () => {
234
216
  });
235
217
  const { request: simulateResponse } =
236
218
  await publicClient.simulateContract(request);
237
- const hash = await walletClient.writeContract(simulateResponse);
238
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
239
- logFailure(receipt);
240
- expect(receipt.status).toBe("success");
219
+ const receipt = await writeContractWithRetries(
220
+ simulateResponse,
221
+ walletClient,
222
+ publicClient,
223
+ );
241
224
  const firstTokenId = getTokenIdFromCreateReceipt(receipt);
242
225
  expect(firstTokenId).to.be.equal(1n);
243
- expect(receipt).not.toBeNull();
244
226
 
245
227
  // creator should have mint to creator count balance
246
228
  expect(
@@ -279,18 +261,16 @@ describe("create-helper", () => {
279
261
  const { request: simulateRequest } = await publicClient.simulateContract(
280
262
  newTokenOnExistingContract.parameters,
281
263
  );
282
- const newHash = await walletClient.writeContract(simulateRequest);
283
- const newReceipt = await publicClient.waitForTransactionReceipt({
284
- hash: newHash,
285
- });
286
-
287
- logFailure(receipt);
264
+ const newReceipt = await writeContractWithRetries(
265
+ simulateRequest,
266
+ walletClient,
267
+ publicClient,
268
+ );
288
269
 
289
- expect(newReceipt.status).toBe("success");
290
270
  const tokenId = getTokenIdFromCreateReceipt(newReceipt);
291
271
  expect(tokenId).to.be.equal(2n);
292
272
  },
293
- 20 * 1000,
273
+ 30 * 1000,
294
274
  );
295
275
  anvilTest(
296
276
  "creates a new token with a create referral address",
@@ -317,9 +297,11 @@ describe("create-helper", () => {
317
297
  });
318
298
  const { request: simulationResponse } =
319
299
  await publicClient.simulateContract(request);
320
- const hash = await walletClient.writeContract(simulationResponse);
321
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
322
- expect(receipt.status).toBe("success");
300
+ const receipt = await writeContractWithRetries(
301
+ simulationResponse,
302
+ walletClient,
303
+ publicClient,
304
+ );
323
305
  expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
324
306
  expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(newTokenId);
325
307
 
@@ -357,8 +339,10 @@ describe("create-helper", () => {
357
339
  });
358
340
  const { request: createSimulation } =
359
341
  await publicClient.simulateContract(request);
360
- await waitForSuccess(
361
- await walletClient.writeContract(createSimulation),
342
+
343
+ await writeContractWithRetries(
344
+ createSimulation,
345
+ walletClient,
362
346
  publicClient,
363
347
  );
364
348
 
@@ -420,8 +404,9 @@ describe("create-helper", () => {
420
404
  });
421
405
  const { request: createSimulation } =
422
406
  await publicClient.simulateContract(request);
423
- await waitForSuccess(
424
- await walletClient.writeContract(createSimulation),
407
+ await writeContractWithRetries(
408
+ createSimulation,
409
+ walletClient,
425
410
  publicClient,
426
411
  );
427
412
 
@@ -199,7 +199,7 @@ async function createNew1155ContractAndToken({
199
199
  minter,
200
200
  newToken,
201
201
  setupActions: tokenSetupActions,
202
- } = await prepareSetupActions({
202
+ } = prepareSetupActions({
203
203
  chainId,
204
204
  account,
205
205
  contractVersion,
@@ -271,7 +271,7 @@ async function createNew1155Token({
271
271
  minter,
272
272
  newToken,
273
273
  setupActions: tokenSetupActions,
274
- } = await prepareSetupActions({
274
+ } = prepareSetupActions({
275
275
  chainId,
276
276
  account,
277
277
  contractVersion,
@@ -307,7 +307,7 @@ async function createNew1155Token({
307
307
  };
308
308
  }
309
309
 
310
- async function prepareSetupActions({
310
+ function prepareSetupActions({
311
311
  chainId,
312
312
  account,
313
313
  contractVersion,
@@ -325,7 +325,7 @@ async function prepareSetupActions({
325
325
  minter,
326
326
  newToken,
327
327
  setupActions: tokenSetupActions,
328
- } = await constructCreate1155TokenCalls({
328
+ } = constructCreate1155TokenCalls({
329
329
  chainId: chainId,
330
330
  ownerAddress: account,
331
331
  contractVersion,
@@ -74,10 +74,10 @@ export const parseNameIntoSymbol = (name: string) => {
74
74
  return result;
75
75
  };
76
76
 
77
- const timedSaleSettingsWithDefaults = async (
77
+ const timedSaleSettingsWithDefaults = (
78
78
  params: TimedSaleParamsType,
79
79
  contractName: string,
80
- ): Promise<Concrete<TimedSaleParamsType>> => {
80
+ ): Concrete<TimedSaleParamsType> => {
81
81
  // If the name is not provided, try to fetch it from the metadata
82
82
  const erc20Name = params.erc20Name || contractName;
83
83
  const symbol = params.erc20Symbol || parseNameIntoSymbol(erc20Name);
@@ -106,10 +106,10 @@ const isFixedPrice = (
106
106
  );
107
107
  };
108
108
 
109
- export const getSalesConfigWithDefaults = async (
109
+ export const getSalesConfigWithDefaults = (
110
110
  salesConfig: SalesConfigParamsType | undefined,
111
111
  contractName: string,
112
- ): Promise<ConcreteSalesConfig> => {
112
+ ): ConcreteSalesConfig => {
113
113
  if (!salesConfig) return timedSaleSettingsWithDefaults({}, contractName);
114
114
  if (isAllowList(salesConfig)) {
115
115
  return allowListWithDefaults(salesConfig);
@@ -6,11 +6,11 @@ import { OPEN_EDITION_MINT_SIZE } from "src/constants";
6
6
  import { getSalesConfigWithDefaults } from "./minter-defaults";
7
7
  import { setupMinters } from "./minter-setup";
8
8
 
9
- async function applyNew1155Defaults(
9
+ function applyNew1155Defaults(
10
10
  props: CreateNew1155TokenProps,
11
11
  ownerAddress: Address,
12
12
  contractName: string,
13
- ): Promise<New1155Token> {
13
+ ): New1155Token {
14
14
  const { payoutRecipient: fundsRecipient } = props;
15
15
  const fundsRecipientOrOwner =
16
16
  fundsRecipient && fundsRecipient !== zeroAddress
@@ -25,10 +25,7 @@ async function applyNew1155Defaults(
25
25
  : BigInt(props.maxSupply),
26
26
  royaltyBPS: props.royaltyBPS || 1000,
27
27
  tokenMetadataURI: props.tokenMetadataURI,
28
- salesConfig: await getSalesConfigWithDefaults(
29
- props.salesConfig,
30
- contractName,
31
- ),
28
+ salesConfig: getSalesConfigWithDefaults(props.salesConfig, contractName),
32
29
  };
33
30
  }
34
31
 
@@ -113,7 +110,7 @@ function makeAdminMintCall({
113
110
  });
114
111
  }
115
112
 
116
- export async function constructCreate1155TokenCalls(
113
+ export function constructCreate1155TokenCalls(
117
114
  props: CreateNew1155TokenProps &
118
115
  ContractProps & {
119
116
  ownerAddress: Address;
@@ -121,11 +118,11 @@ export async function constructCreate1155TokenCalls(
121
118
  } & {
122
119
  contractName: string;
123
120
  },
124
- ): Promise<{
121
+ ): {
125
122
  setupActions: `0x${string}`[];
126
123
  newToken: New1155Token;
127
124
  minter: Address;
128
- }> {
125
+ } {
129
126
  const {
130
127
  chainId,
131
128
  nextTokenId,
@@ -134,7 +131,7 @@ export async function constructCreate1155TokenCalls(
134
131
  contractVersion,
135
132
  } = props;
136
133
 
137
- const new1155TokenPropsWithDefaults = await applyNew1155Defaults(
134
+ const new1155TokenPropsWithDefaults = applyNew1155Defaults(
138
135
  props,
139
136
  ownerAddress,
140
137
  props.contractName,
@@ -5,7 +5,7 @@ import {
5
5
  zoraCreator1155ImplABI,
6
6
  zoraTimedSaleStrategyAddress,
7
7
  } from "@zoralabs/protocol-deployments";
8
- import { forkUrls, makeAnvilTest } from "src/anvil";
8
+ import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
9
9
  import { createCollectorClient, createCreatorClient } from "src/sdk";
10
10
  import { getAllowListEntry } from "src/allow-list/allow-list-client";
11
11
  import {
@@ -370,11 +370,7 @@ describe("mint-helper", () => {
370
370
 
371
371
  const { request: createRequest } =
372
372
  await publicClient.simulateContract(parameters);
373
- const createHash = await walletClient.writeContract(createRequest);
374
- const createReceipt = await publicClient.waitForTransactionReceipt({
375
- hash: createHash,
376
- });
377
- expect(createReceipt.status).toBe("success");
373
+ await writeContractWithRetries(createRequest, walletClient, publicClient);
378
374
 
379
375
  const zoraCreateToken: TokenQueryResult = {
380
376
  contract: {
package/.env DELETED
@@ -1 +0,0 @@
1
- VITE_CONDUIT_KEY=066ae224-b5c3-4086-ac11-a3a44ede9458