@zoralabs/protocol-sdk 0.11.10 → 0.11.11

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.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/secondary/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAc,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAKzC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,wBAAsB,gBAAgB,CAAC,EACrC,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA0CrC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/secondary/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAc,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAKzC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAMxC,wBAAsB,gBAAgB,CAAC,EACrC,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAiDrC"}
@@ -1,7 +1,7 @@
1
1
  import { zoraCreator1155FactoryImplAddress } from "@zoralabs/protocol-deployments";
2
- import { Address, Hex, PublicClient } from "viem";
2
+ import { Address, PublicClient, Chain, WalletClient, SimulateContractReturnType, Account } from "viem";
3
3
  import { NewContractParams } from "./create/types";
4
- export declare const waitForSuccess: (hash: Hex, publicClient: PublicClient) => Promise<import("viem").TransactionReceipt>;
4
+ import { SimulateContractParametersWithAccount } from "./types";
5
5
  export declare const getFixedPricedMinter: ({ publicClient, chainId, }: {
6
6
  publicClient: PublicClient;
7
7
  chainId: keyof typeof zoraCreator1155FactoryImplAddress;
@@ -12,4 +12,14 @@ export declare const fixedPriceMinterMinterArguments: ({ mintRecipient, }: {
12
12
  export declare function randomNewContract(): NewContractParams;
13
13
  export declare const randomNonce: () => `0x${string}`;
14
14
  export declare const thirtySecondsFromNow: () => bigint;
15
+ export declare function simulateAndWriteContractWithRetries({ parameters, walletClient, publicClient, }: {
16
+ parameters: SimulateContractParametersWithAccount;
17
+ walletClient: WalletClient;
18
+ publicClient: PublicClient;
19
+ }): Promise<import("viem").TransactionReceipt>;
20
+ export declare function writeContractWithRetries({ request, walletClient, publicClient, }: {
21
+ request: SimulateContractReturnType<any, any, any, Chain, Account>["request"];
22
+ walletClient: WalletClient;
23
+ publicClient: PublicClient;
24
+ }): Promise<import("viem").TransactionReceipt>;
15
25
  //# sourceMappingURL=test-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iCAAiC,EAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,EACP,GAAG,EACH,YAAY,EAKb,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,eAAO,MAAM,cAAc,SAAgB,GAAG,gBAAgB,YAAY,+CAQzE,CAAC;AAEF,eAAO,MAAM,oBAAoB,+BAG9B;IACD,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,OAAO,iCAAiC,CAAC;CACzD,2BAKG,CAAC;AAEL,eAAO,MAAM,+BAA+B,uBAEzC;IACD,aAAa,EAAE,OAAO,CAAC;CACxB,kBAAwE,CAAC;AAI1E,wBAAgB,iBAAiB,IAAI,iBAAiB,CAKrD;AAED,eAAO,MAAM,WAAW,qBAC8B,CAAC;AACvD,eAAO,MAAM,oBAAoB,cACsB,CAAC"}
1
+ {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iCAAiC,EAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,EACP,YAAY,EAKZ,KAAK,EACL,YAAY,EACZ,0BAA0B,EAC1B,OAAO,EACR,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,qCAAqC,EAAE,MAAM,SAAS,CAAC;AAEhE,eAAO,MAAM,oBAAoB,+BAG9B;IACD,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,OAAO,iCAAiC,CAAC;CACzD,2BAKG,CAAC;AAEL,eAAO,MAAM,+BAA+B,uBAEzC;IACD,aAAa,EAAE,OAAO,CAAC;CACxB,kBAAwE,CAAC;AAI1E,wBAAgB,iBAAiB,IAAI,iBAAiB,CAKrD;AAED,eAAO,MAAM,WAAW,qBAC8B,CAAC;AACvD,eAAO,MAAM,oBAAoB,cACsB,CAAC;AAExD,wBAAsB,mCAAmC,CAAC,EACxD,UAAU,EACV,YAAY,EACZ,YAAY,GACb,EAAE;IACD,UAAU,EAAE,qCAAqC,CAAC;IAClD,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;CAC5B,8CAOA;AAED,wBAAsB,wBAAwB,CAAC,EAC7C,OAAO,EACP,YAAY,EACZ,YAAY,GACb,EAAE;IACD,OAAO,EAAE,0BAA0B,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC;IAC9E,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;CAC5B,8CAuBA"}
@@ -0,0 +1,4 @@
1
+ import { Hex } from "viem/_types/types/misc";
2
+ import { PublicClient } from "viem";
3
+ export declare const waitForSuccess: (hash: Hex, publicClient: PublicClient) => Promise<import("viem").TransactionReceipt>;
4
+ //# sourceMappingURL=waitForSuccess.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"waitForSuccess.d.ts","sourceRoot":"","sources":["../src/waitForSuccess.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEpC,eAAO,MAAM,cAAc,SAAgB,GAAG,gBAAgB,YAAY,+CAQzE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoralabs/protocol-sdk",
3
- "version": "0.11.10",
3
+ "version": "0.11.11",
4
4
  "repository": "https://github.com/ourzora/zora-protocol",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@zoralabs/protocol-deployments": "^0.3.10"
19
+ "@zoralabs/protocol-deployments": "^0.3.11"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "viem": "^2.21.21",
@@ -2,30 +2,67 @@ import {
2
2
  IHttpClient,
3
3
  httpClient as defaultHttpClient,
4
4
  } from "src/apis/http-api-base";
5
- import { paths } from "../apis/generated/allow-list-api-types";
6
- import { Hex } from "viem";
5
+ import { Address, decodeAbiParameters, encodeAbiParameters, Hex } from "viem";
7
6
  import { AllowList } from "./types";
8
7
 
9
- type AllowListCreateType = paths["/allowlist"]["post"];
10
- type AllowListCreateParameters =
11
- AllowListCreateType["requestBody"]["content"]["application/json"];
8
+ type AllowListCreateParameters = {
9
+ unhashedLeaves: Hex[];
10
+ leafTypeDescriptor: string[];
11
+ packedEncoding: boolean;
12
+ };
13
+
12
14
  type AllowListCreateResponse = {
13
- existing?: {
14
- entries: AllowListCreateParameters["entries"];
15
- root: string;
16
- added: string;
17
- };
18
- success: boolean;
19
- root: string;
20
- associated_id?: string;
15
+ merkleRoot: Hex;
16
+ };
17
+
18
+ type LanyardResponse = {
19
+ proof: Hex[];
20
+ unhashedLeaf: Hex;
21
21
  };
22
22
 
23
- const ALLOW_LIST_API_BASE = "http://allowlist.zora.co/";
24
- type AllowListAllowedResponse = {
23
+ const ALLOWLIST_ABI_PARAMETERS = [
24
+ { type: "address", name: "user" },
25
+ { type: "uint256", name: "maxCanMint" },
26
+ { type: "uint256", name: "price" },
27
+ ];
28
+
29
+ const ALLOW_LIST_API_BASE = "https://lanyard.org/api/v1/";
30
+ type AllowlistEntry = {
31
+ user: Address;
25
32
  maxCanMint: number;
26
- price: string;
27
- proof: string[];
28
- }[];
33
+ price: bigint;
34
+ priceDecimal: number;
35
+ proof: Hex[];
36
+ };
37
+
38
+ function getZoraEntry(
39
+ lanyardResponse: LanyardResponse | undefined,
40
+ root: string | undefined,
41
+ ): AllowlistEntry | undefined {
42
+ if (!lanyardResponse || !root) {
43
+ return;
44
+ }
45
+
46
+ try {
47
+ const [user, maxCanMint, price] = decodeAbiParameters(
48
+ ALLOWLIST_ABI_PARAMETERS,
49
+ lanyardResponse.unhashedLeaf,
50
+ );
51
+
52
+ return {
53
+ user: user as Address,
54
+ maxCanMint: Number(maxCanMint),
55
+ price: price as bigint,
56
+ // This won't realistically overflow.
57
+ priceDecimal: Number(price),
58
+ proof: lanyardResponse.proof,
59
+ };
60
+ } catch (e: any) {
61
+ console.error(e);
62
+ // Silently error here because the format is unexpected
63
+ return;
64
+ }
65
+ }
29
66
 
30
67
  export const createAllowList = async ({
31
68
  allowList,
@@ -39,26 +76,22 @@ export const createAllowList = async ({
39
76
  const { post, retries } = httpClient;
40
77
 
41
78
  const data: AllowListCreateParameters = {
42
- entries: allowList.entries.map((entry) => ({
43
- user: entry.user,
44
- maxCanMint: entry.maxCanMint,
45
- price: entry.price.toString(),
46
- })),
79
+ unhashedLeaves: allowList.entries.map((entry) =>
80
+ encodeAbiParameters(ALLOWLIST_ABI_PARAMETERS, [
81
+ entry.user,
82
+ entry.maxCanMint,
83
+ entry.price,
84
+ ]),
85
+ ),
86
+ leafTypeDescriptor: ["address", "uint256", "uint256"],
87
+ packedEncoding: false,
47
88
  };
48
89
 
49
90
  return (
50
- await retries(() =>
51
- post<AllowListCreateResponse>(`${baseUrl}allowlist`, data),
52
- )
53
- ).root;
91
+ await retries(() => post<AllowListCreateResponse>(`${baseUrl}tree`, data))
92
+ ).merkleRoot;
54
93
  };
55
94
 
56
- function padHex(value: string): Hex {
57
- if (value.startsWith("0x")) return value as Hex;
58
-
59
- return `0x${value}`;
60
- }
61
-
62
95
  export const getAllowListEntry = async ({
63
96
  merkleRoot,
64
97
  address,
@@ -73,24 +106,16 @@ export const getAllowListEntry = async ({
73
106
  const { retries, get } = httpClient;
74
107
 
75
108
  const response = await retries(() =>
76
- get<AllowListAllowedResponse>(
77
- `${baseUrl}allowed?user=${address}&root=${merkleRoot}`,
109
+ get<LanyardResponse>(
110
+ `${baseUrl}proof?address=${address}&root=${merkleRoot}`,
78
111
  ),
79
112
  );
80
113
 
81
- const entries = response?.map((x) => ({
82
- maxCanMint: x.maxCanMint,
83
- price: BigInt(x.price),
84
- proof: x.proof.map(padHex),
85
- }));
86
-
87
- const entry = entries?.sort(
88
- (a, b) => Number(a.price) - Number(b.price) || b.maxCanMint - a.maxCanMint,
89
- )[0];
114
+ const allowListEntry = getZoraEntry(response, merkleRoot);
90
115
 
91
116
  return {
92
- accessAllowed: entry && entry?.proof?.length,
93
- allowListEntry: entry,
117
+ accessAllowed: allowListEntry && allowListEntry?.proof?.length,
118
+ allowListEntry,
94
119
  };
95
120
  };
96
121
 
@@ -1,5 +1,6 @@
1
1
  import { describe, expect } from "vitest";
2
- import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
2
+ import { forkUrls, makeAnvilTest } from "src/anvil";
3
+ import { writeContractWithRetries } from "src/test-utils";
3
4
  import { base, zora } from "viem/chains";
4
5
  import {
5
6
  commentsABI,
@@ -25,7 +26,8 @@ import {
25
26
  hashTypedData,
26
27
  } from "viem";
27
28
  import { createCreatorClient } from "src/sdk";
28
- import { randomNewContract, waitForSuccess } from "src/test-utils";
29
+ import { randomNewContract } from "src/test-utils";
30
+ import { waitForSuccess } from "src/waitForSuccess";
29
31
  import { permitCommentTypedDataDefinition } from "@zoralabs/protocol-deployments";
30
32
  import { demoTokenMetadataURI } from "src/fixtures/contract-setup";
31
33
  import { randomNonce, thirtySecondsFromNow } from "src/test-utils";
@@ -9,15 +9,14 @@ import {
9
9
  zoraTimedSaleStrategyABI,
10
10
  zoraTimedSaleStrategyAddress,
11
11
  } from "@zoralabs/protocol-deployments";
12
- import { waitForSuccess } from "src/test-utils";
12
+ import { waitForSuccess } from "src/waitForSuccess";
13
13
  import { Address, erc20Abi, parseEther, PublicClient } from "viem";
14
14
  import { makePrepareMint1155TokenParams } from "src/mint/mint-transactions";
15
+ import { forkUrls, makeAnvilTest } from "src/anvil";
15
16
  import {
16
- forkUrls,
17
- makeAnvilTest,
18
17
  simulateAndWriteContractWithRetries,
19
18
  writeContractWithRetries,
20
- } from "src/anvil";
19
+ } from "src/test-utils";
21
20
  import { zora } from "viem/chains";
22
21
  import { AllowList } from "src/allow-list/types";
23
22
  import { createAllowList } from "src/allow-list/allow-list-client";
@@ -561,7 +560,7 @@ describe("create-helper", () => {
561
560
  "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
562
561
  salesConfig: {
563
562
  type: "allowlistMint",
564
- presaleMerkleRoot: `0x${root}`,
563
+ presaleMerkleRoot: root,
565
564
  },
566
565
  },
567
566
  account: creator,
@@ -10,8 +10,11 @@ import {
10
10
  TimedSaleParamsType,
11
11
  } from "./types";
12
12
  import { parseEther } from "viem";
13
- // 1111 mints worth of market reward eth - 0.0000111 eth * 1,111 = 0.0123321 eth
14
- export const DEFAULT_MINIMUM_MARKET_ETH = parseEther("0.0123321");
13
+
14
+ // The amount of eth per mint for the secondary market
15
+ export const MARKET_REWARD_V2 = parseEther("0.0000222");
16
+ // 1111 mints worth of market reward eth - 0.0000222 eth * 1,111 = 0.0246642 eth
17
+ export const DEFAULT_MINIMUM_MARKET_ETH = parseEther("0.0246642");
15
18
  // 24 hour countdown
16
19
  export const DEFAULT_MARKET_COUNTDOWN = BigInt(24 * 60 * 60);
17
20
 
@@ -86,7 +89,7 @@ const getMinimumMarketEth = (
86
89
  >,
87
90
  ) => {
88
91
  if (params.minimumMintsForCountdown) {
89
- return params.minimumMintsForCountdown * parseEther("0.0000111");
92
+ return params.minimumMintsForCountdown * MARKET_REWARD_V2;
90
93
  }
91
94
  return params.minimumMarketEth || DEFAULT_MINIMUM_MARKET_ETH;
92
95
  };
@@ -101,7 +104,7 @@ const timedSaleSettingsWithDefaults = (
101
104
  minimumMarketEth: params.minimumMarketEth,
102
105
  minimumMintsForCountdown: params.minimumMintsForCountdown,
103
106
  });
104
- const minimumMintsForCountdown = minimumMarketEth / parseEther("0.0000111");
107
+ const minimumMintsForCountdown = minimumMarketEth / MARKET_REWARD_V2;
105
108
 
106
109
  return {
107
110
  type: "timed",
@@ -1,5 +1,5 @@
1
1
  import { Address, Chain, PublicClient, WalletClient } from "viem";
2
- import { simulateAndWriteContractWithRetries } from "src/anvil";
2
+ import { simulateAndWriteContractWithRetries } from "src/test-utils";
3
3
  import { createCreatorClient } from "src/sdk";
4
4
  import { SubgraphMintGetter } from "src/mint/subgraph-mint-getter";
5
5
  import { SubgraphRewardsGetter } from "../rewards/subgraph-rewards-getter";
@@ -1,6 +1,6 @@
1
1
  import { Address, Account, PublicClient, TestClient, WalletClient } from "viem";
2
2
  import { CollectorClient } from "../sdk";
3
- import { simulateAndWriteContractWithRetries } from "../anvil";
3
+ import { simulateAndWriteContractWithRetries } from "src/test-utils";
4
4
  import { makeContractParameters } from "../utils";
5
5
  import {
6
6
  zoraTimedSaleStrategyABI,
@@ -14,7 +14,8 @@ import {
14
14
  commentsABI,
15
15
  callerAndCommenterABI,
16
16
  } from "@zoralabs/protocol-deployments";
17
- import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
17
+ import { forkUrls, makeAnvilTest } from "src/anvil";
18
+ import { writeContractWithRetries } from "src/test-utils";
18
19
  import { createCollectorClient, createCreatorClient } from "src/sdk";
19
20
  import { getAllowListEntry } from "src/allow-list/allow-list-client";
20
21
  import { SubgraphMintGetter } from "./subgraph-mint-getter";
@@ -1,11 +1,8 @@
1
1
  import { describe, expect, vi } from "vitest";
2
2
  import { encodeAbiParameters, erc20Abi, parseEther } from "viem";
3
3
  import { zoraSepolia, base } from "viem/chains";
4
- import {
5
- forkUrls,
6
- makeAnvilTest,
7
- simulateAndWriteContractWithRetries,
8
- } from "src/anvil";
4
+ import { forkUrls, makeAnvilTest } from "src/anvil";
5
+ import { simulateAndWriteContractWithRetries } from "src/test-utils";
9
6
  import { createCollectorClient, createCreatorClient } from "src/sdk";
10
7
  import { new1155ContractVersion } from "src/create/contract-setup";
11
8
  import { ISubgraphQuerier } from "src/apis/subgraph-querier";
@@ -138,7 +135,7 @@ describe("rewardsClient", () => {
138
135
  30_000,
139
136
  );
140
137
  makeAnvilTest({
141
- forkBlockNumber: 14653556,
138
+ forkBlockNumber: 17938475,
142
139
  forkUrl: forkUrls.zoraSepolia,
143
140
  anvilChainId: zoraSepolia.id,
144
141
  })(
@@ -1,11 +1,8 @@
1
1
  import { describe, expect, vi } from "vitest";
2
2
  import { parseEther, Address, parseEventLogs } from "viem";
3
3
  import { zoraSepolia } from "viem/chains";
4
- import {
5
- forkUrls,
6
- makeAnvilTest,
7
- simulateAndWriteContractWithRetries,
8
- } from "src/anvil";
4
+ import { forkUrls, makeAnvilTest } from "src/anvil";
5
+ import { simulateAndWriteContractWithRetries } from "src/test-utils";
9
6
  import { createCollectorClient } from "src/sdk";
10
7
  import {
11
8
  zoraCreator1155ImplABI,
@@ -5,6 +5,11 @@ import {
5
5
  zoraTimedSaleStrategyAddress,
6
6
  } from "@zoralabs/protocol-deployments";
7
7
  import { SecondaryInfo } from "./types";
8
+
9
+ const LEGACY_MINIMUM_MARKET_ETH = parseEther("0.0123321");
10
+ const LEGACY_MARKET_REWARD = parseEther("0.0000111");
11
+ const MARKET_REWARD = parseEther("0.0000222");
12
+
8
13
  export async function getSecondaryInfo({
9
14
  contract,
10
15
  tokenId,
@@ -38,6 +43,12 @@ export async function getSecondaryInfo({
38
43
  return undefined;
39
44
  }
40
45
 
46
+ const usesLegacyMarketReward =
47
+ result.minimumMarketEth === LEGACY_MINIMUM_MARKET_ETH;
48
+ const erc20zBalance = await publicClient.getBalance({
49
+ address: result.erc20zAddress,
50
+ });
51
+
41
52
  return {
42
53
  erc20z: result.erc20zAddress,
43
54
  pool: result.poolAddress,
@@ -51,10 +62,11 @@ export async function getSecondaryInfo({
51
62
  minimumMintsForCountdown:
52
63
  result.minimumMarketEth === 0n
53
64
  ? undefined
54
- : result.minimumMarketEth / parseEther("0.0000111"),
55
- mintCount:
56
- (await publicClient.getBalance({
57
- address: result.erc20zAddress,
58
- })) / parseEther("0.0000111"),
65
+ : usesLegacyMarketReward
66
+ ? result.minimumMarketEth / LEGACY_MARKET_REWARD
67
+ : result.minimumMarketEth / MARKET_REWARD,
68
+ mintCount: usesLegacyMarketReward
69
+ ? erc20zBalance / LEGACY_MARKET_REWARD
70
+ : erc20zBalance / MARKET_REWARD,
59
71
  };
60
72
  }
@@ -9,13 +9,11 @@ import {
9
9
  zoraCreator1155ImplABI,
10
10
  zoraMints1155ABI,
11
11
  zoraMints1155Address,
12
- zoraMintsManagerImplABI,
13
12
  zoraMintsManagerImplAddress,
14
13
  PremintMintArguments,
15
14
  premintTypedDataDefinition,
16
15
  zoraSparks1155Address,
17
16
  zoraSparks1155ABI,
18
- zoraSparksManagerImplABI,
19
17
  } from "@zoralabs/protocol-deployments";
20
18
  import {
21
19
  Address,
@@ -39,10 +37,9 @@ import { zora } from "viem/chains";
39
37
  import {
40
38
  fixedPriceMinterMinterArguments,
41
39
  getFixedPricedMinter,
42
- waitForSuccess,
43
40
  } from "src/test-utils";
44
41
  import { PublicClient } from "src/utils";
45
-
42
+ import { waitForSuccess } from "src/waitForSuccess";
46
43
  const sparksMainnetDeployedBlock = 17655716;
47
44
 
48
45
  const anvilTest = makeAnvilTest({
package/src/test-utils.ts CHANGED
@@ -4,25 +4,19 @@ import {
4
4
  } from "@zoralabs/protocol-deployments";
5
5
  import {
6
6
  Address,
7
- Hex,
8
7
  PublicClient,
9
8
  encodeAbiParameters,
10
9
  keccak256,
11
10
  toBytes,
12
11
  parseAbiParameters,
12
+ Chain,
13
+ WalletClient,
14
+ SimulateContractReturnType,
15
+ Account,
13
16
  } from "viem";
14
17
  import { NewContractParams } from "./create/types";
15
- import { expect } from "vitest";
16
-
17
- export const waitForSuccess = async (hash: Hex, publicClient: PublicClient) => {
18
- const receipt = await publicClient.waitForTransactionReceipt({
19
- hash,
20
- });
21
-
22
- expect(receipt.status).toBe("success");
23
-
24
- return receipt;
25
- };
18
+ import { retries } from "./apis/http-api-base";
19
+ import { SimulateContractParametersWithAccount } from "./types";
26
20
 
27
21
  export const getFixedPricedMinter = async ({
28
22
  publicClient,
@@ -56,3 +50,53 @@ export const randomNonce = () =>
56
50
  keccak256(toBytes(Math.round(Math.random() * 1000)));
57
51
  export const thirtySecondsFromNow = () =>
58
52
  BigInt(Math.round(new Date().getTime() / 1000)) + 30n;
53
+
54
+ export async function simulateAndWriteContractWithRetries({
55
+ parameters,
56
+ walletClient,
57
+ publicClient,
58
+ }: {
59
+ parameters: SimulateContractParametersWithAccount;
60
+ walletClient: WalletClient;
61
+ publicClient: PublicClient;
62
+ }) {
63
+ const { request } = await publicClient.simulateContract(parameters);
64
+ return await writeContractWithRetries({
65
+ request,
66
+ walletClient,
67
+ publicClient,
68
+ });
69
+ }
70
+
71
+ export async function writeContractWithRetries({
72
+ request,
73
+ walletClient,
74
+ publicClient,
75
+ }: {
76
+ request: SimulateContractReturnType<any, any, any, Chain, Account>["request"];
77
+ walletClient: WalletClient;
78
+ publicClient: PublicClient;
79
+ }) {
80
+ let tryCount = 1;
81
+ const tryFn = async () => {
82
+ if (tryCount > 1) {
83
+ console.log("retrying try #", tryCount);
84
+ }
85
+ const hash = await walletClient.writeContract(request);
86
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
87
+
88
+ if (receipt.status !== "success") {
89
+ console.log("failed try #", tryCount);
90
+ tryCount++;
91
+ throw new Error("transaction failed");
92
+ }
93
+
94
+ return receipt;
95
+ };
96
+
97
+ const shouldRetry = () => {
98
+ return true;
99
+ };
100
+
101
+ return await retries(tryFn, 3, 1000, shouldRetry);
102
+ }
@@ -0,0 +1,13 @@
1
+ import { expect } from "vitest";
2
+ import { Hex } from "viem/_types/types/misc";
3
+ import { PublicClient } from "viem";
4
+
5
+ export const waitForSuccess = async (hash: Hex, publicClient: PublicClient) => {
6
+ const receipt = await publicClient.waitForTransactionReceipt({
7
+ hash,
8
+ });
9
+
10
+ expect(receipt.status).toBe("success");
11
+
12
+ return receipt;
13
+ };