@zoralabs/protocol-sdk 0.11.7-COMMENTS.0 → 0.11.8

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 (50) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +8 -8
  3. package/dist/anvil.d.ts +1 -0
  4. package/dist/anvil.d.ts.map +1 -1
  5. package/dist/create/mint-from-create.d.ts +1 -2
  6. package/dist/create/mint-from-create.d.ts.map +1 -1
  7. package/dist/fixtures/rewards-query-results.d.ts +4 -1
  8. package/dist/fixtures/rewards-query-results.d.ts.map +1 -1
  9. package/dist/index.cjs +66 -207
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +68 -213
  12. package/dist/index.js.map +1 -1
  13. package/dist/mint/mint-client.d.ts +1 -3
  14. package/dist/mint/mint-client.d.ts.map +1 -1
  15. package/dist/mint/mint-queries.d.ts +3 -5
  16. package/dist/mint/mint-queries.d.ts.map +1 -1
  17. package/dist/mint/mint-transactions.d.ts +2 -4
  18. package/dist/mint/mint-transactions.d.ts.map +1 -1
  19. package/dist/rewards/rewards-queries.d.ts.map +1 -1
  20. package/dist/rewards/subgraph-queries.d.ts +2 -1
  21. package/dist/rewards/subgraph-queries.d.ts.map +1 -1
  22. package/dist/rewards/subgraph-rewards-getter.d.ts +9 -3
  23. package/dist/rewards/subgraph-rewards-getter.d.ts.map +1 -1
  24. package/dist/sdk.d.ts.map +1 -1
  25. package/dist/secondary/secondary-client.d.ts +1 -2
  26. package/dist/secondary/secondary-client.d.ts.map +1 -1
  27. package/dist/secondary/types.d.ts +0 -1
  28. package/dist/secondary/types.d.ts.map +1 -1
  29. package/dist/test-utils.d.ts +1 -5
  30. package/dist/test-utils.d.ts.map +1 -1
  31. package/package.json +4 -4
  32. package/src/create/1155-create-helper.test.ts +12 -2
  33. package/src/create/1155-create-helper.ts +0 -2
  34. package/src/create/mint-from-create.ts +0 -3
  35. package/src/fixtures/rewards-query-results.ts +9 -2
  36. package/src/mint/mint-client.test.ts +30 -67
  37. package/src/mint/mint-client.ts +1 -10
  38. package/src/mint/mint-queries.ts +5 -16
  39. package/src/mint/mint-transactions.ts +16 -80
  40. package/src/rewards/rewards-client.test.ts +41 -9
  41. package/src/rewards/rewards-queries.ts +15 -5
  42. package/src/rewards/subgraph-queries.ts +4 -2
  43. package/src/rewards/subgraph-rewards-getter.ts +24 -10
  44. package/src/sdk.ts +0 -1
  45. package/src/secondary/secondary-client.test.ts +2 -248
  46. package/src/secondary/secondary-client.ts +6 -136
  47. package/src/secondary/types.ts +0 -2
  48. package/src/sparks/sparks-sponsored-sparks-spender.test.ts +1 -2
  49. package/src/test-utils.ts +0 -19
  50. package/src/comments/comments.test.ts +0 -338
@@ -36,13 +36,11 @@ export async function getMint({
36
36
  mintGetter,
37
37
  premintGetter,
38
38
  publicClient,
39
- chainId,
40
39
  }: {
41
40
  params: GetMintParameters;
42
41
  mintGetter: IOnchainMintGetter;
43
42
  premintGetter: IPremintGetter;
44
43
  publicClient: IPublicClient;
45
- chainId: number;
46
44
  }): Promise<MintableReturn> {
47
45
  const { tokenContract } = params;
48
46
  if (isOnChainMint(params)) {
@@ -55,7 +53,7 @@ export async function getMint({
55
53
  blockTime: blockTime,
56
54
  });
57
55
 
58
- return toMintableReturn(result, chainId);
56
+ return toMintableReturn(result);
59
57
  }
60
58
 
61
59
  const premint = await premintGetter.get({
@@ -105,19 +103,17 @@ export async function getMintsOfContract({
105
103
  mintGetter,
106
104
  premintGetter,
107
105
  publicClient,
108
- chainId,
109
106
  }: {
110
107
  params: GetMintsOfContractParameters;
111
108
  mintGetter: IOnchainMintGetter;
112
109
  premintGetter: IPremintGetter;
113
110
  publicClient: IPublicClient;
114
- chainId: number;
115
111
  }): Promise<{ contract?: ContractInfo; tokens: MintableReturn[] }> {
116
112
  const onchainMints = (
117
113
  await mintGetter.getContractMintable({
118
114
  tokenAddress: params.tokenContract,
119
115
  })
120
- ).map((result) => toMintableReturn(result, chainId));
116
+ ).map(toMintableReturn);
121
117
 
122
118
  const offchainMints = await getPremintsOfContractMintable({
123
119
  mintGetter,
@@ -274,7 +270,7 @@ function parsePremint({
274
270
  }
275
271
 
276
272
  export const makeOnchainPrepareMint =
277
- (result: OnchainSalesConfigAndTokenInfo, chainId: number): PrepareMint =>
273
+ (result: OnchainSalesConfigAndTokenInfo): PrepareMint =>
278
274
  (params: MintParametersBase) => {
279
275
  if (!result.salesConfig) {
280
276
  throw new Error("No valid sales config found for token");
@@ -284,7 +280,6 @@ export const makeOnchainPrepareMint =
284
280
  parameters: makeOnchainMintCall({
285
281
  token: result as Concrete<OnchainSalesConfigAndTokenInfo>,
286
282
  mintParams: params,
287
- chainId,
288
283
  }),
289
284
  erc20Approval: getRequiredErc20Approvals(params, result.salesConfig),
290
285
  costs: parseMintCosts({
@@ -295,10 +290,7 @@ export const makeOnchainPrepareMint =
295
290
  };
296
291
  };
297
292
 
298
- function toMintableReturn(
299
- result: GetMintableReturn,
300
- chainId: number,
301
- ): MintableReturn {
293
+ function toMintableReturn(result: GetMintableReturn): MintableReturn {
302
294
  const primaryMintActive = result.primaryMintActive;
303
295
  if (!primaryMintActive) {
304
296
  return {
@@ -314,10 +306,7 @@ function toMintableReturn(
314
306
  primaryMintActive,
315
307
  primaryMintEnd: result.primaryMintEnd,
316
308
  secondaryMarketActive: result.secondaryMarketActive,
317
- prepareMint: makeOnchainPrepareMint(
318
- result.salesConfigAndTokenInfo,
319
- chainId,
320
- ),
309
+ prepareMint: makeOnchainPrepareMint(result.salesConfigAndTokenInfo),
321
310
  };
322
311
  }
323
312
 
@@ -11,8 +11,6 @@ import {
11
11
  erc20MinterABI,
12
12
  zoraCreator1155ImplABI,
13
13
  zoraTimedSaleStrategyABI,
14
- callerAndCommenterABI,
15
- callerAndCommenterAddress,
16
14
  } from "@zoralabs/protocol-deployments";
17
15
  import { zora721Abi, zora1155LegacyAbi } from "src/constants";
18
16
  import {
@@ -34,11 +32,9 @@ import { AllowListEntry } from "src/allow-list/types";
34
32
  export function makeOnchainMintCall({
35
33
  token,
36
34
  mintParams,
37
- chainId,
38
35
  }: {
39
36
  token: Concrete<OnchainSalesConfigAndTokenInfo>;
40
37
  mintParams: Omit<MakeMintParametersArgumentsBase, "tokenContract">;
41
- chainId: number;
42
38
  }): SimulateContractParametersWithAccount {
43
39
  if (token.mintType === "721") {
44
40
  return makePrepareMint721TokenParams({
@@ -52,7 +48,6 @@ export function makeOnchainMintCall({
52
48
  salesConfigAndTokenInfo: token,
53
49
  tokenContract: token.contract.address,
54
50
  tokenId: token.tokenId!,
55
- chainId,
56
51
  ...mintParams,
57
52
  });
58
53
  }
@@ -62,69 +57,6 @@ export type MintableParameters = Pick<
62
57
  "contractVersion" | "salesConfig"
63
58
  >;
64
59
 
65
- function makeZoraTimedSaleStrategyMintCall({
66
- minterAccount,
67
- salesConfigAndTokenInfo,
68
- mintQuantity,
69
- mintTo,
70
- tokenContract,
71
- tokenId,
72
- mintReferral,
73
- mintComment,
74
- chainId,
75
- }: {
76
- minterAccount: Address | Account;
77
- salesConfigAndTokenInfo: Concrete<MintableParameters>;
78
- mintQuantity: bigint;
79
- mintTo: Address;
80
- tokenContract: Address;
81
- tokenId: GenericTokenIdTypes;
82
- mintReferral?: Address;
83
- mintComment?: string;
84
- chainId: number;
85
- }) {
86
- // if there is a mint comment, use the caller and commenter
87
- if (mintComment && mintComment !== "") {
88
- return makeContractParameters({
89
- abi: callerAndCommenterABI,
90
- address:
91
- callerAndCommenterAddress[
92
- chainId as keyof typeof callerAndCommenterAddress
93
- ],
94
- functionName: "timedSaleMintAndComment",
95
- account: minterAccount,
96
- value:
97
- salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
98
- args: [
99
- mintTo,
100
- mintQuantity,
101
- tokenContract,
102
- tokenId,
103
- mintReferral || zeroAddress,
104
- mintComment,
105
- ],
106
- });
107
- }
108
-
109
- return makeContractParameters({
110
- abi: zoraTimedSaleStrategyABI,
111
- functionName: "mint",
112
- account: minterAccount,
113
- address: salesConfigAndTokenInfo.salesConfig.address,
114
- value:
115
- salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
116
- /* args: mintTo, quantity, collection, tokenId, mintReferral, comment */
117
- args: [
118
- mintTo,
119
- mintQuantity,
120
- tokenContract,
121
- BigInt(tokenId),
122
- mintReferral || zeroAddress,
123
- "",
124
- ],
125
- });
126
- }
127
-
128
60
  export function makePrepareMint1155TokenParams({
129
61
  tokenContract: tokenContract,
130
62
  tokenId,
@@ -135,11 +67,9 @@ export function makePrepareMint1155TokenParams({
135
67
  mintRecipient,
136
68
  quantityToMint,
137
69
  allowListEntry,
138
- chainId,
139
70
  }: {
140
71
  salesConfigAndTokenInfo: Concrete<MintableParameters>;
141
72
  tokenId: GenericTokenIdTypes;
142
- chainId: number;
143
73
  } & Pick<
144
74
  MakeMintParametersArgumentsBase,
145
75
  | "minterAccount"
@@ -171,16 +101,22 @@ export function makePrepareMint1155TokenParams({
171
101
  }
172
102
 
173
103
  if (saleType === "timed") {
174
- return makeZoraTimedSaleStrategyMintCall({
175
- minterAccount,
176
- salesConfigAndTokenInfo,
177
- mintQuantity,
178
- mintTo,
179
- tokenContract,
180
- tokenId,
181
- mintReferral,
182
- mintComment,
183
- chainId,
104
+ return makeContractParameters({
105
+ abi: zoraTimedSaleStrategyABI,
106
+ functionName: "mint",
107
+ account: minterAccount,
108
+ address: salesConfigAndTokenInfo.salesConfig.address,
109
+ value:
110
+ salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
111
+ /* args: mintTo, quantity, collection, tokenId, mintReferral, comment */
112
+ args: [
113
+ mintTo,
114
+ mintQuantity,
115
+ tokenContract,
116
+ BigInt(tokenId),
117
+ mintReferral || zeroAddress,
118
+ mintComment || "",
119
+ ],
184
120
  });
185
121
  }
186
122
 
@@ -1,12 +1,12 @@
1
1
  import { describe, expect, vi } from "vitest";
2
2
  import { encodeAbiParameters, erc20Abi, parseEther } from "viem";
3
- import { zoraSepolia } from "viem/chains";
3
+ import { zoraSepolia, base } from "viem/chains";
4
4
  import {
5
5
  forkUrls,
6
6
  makeAnvilTest,
7
7
  simulateAndWriteContractWithRetries,
8
8
  } from "src/anvil";
9
- import { createCollectorClient } from "src/sdk";
9
+ import { createCollectorClient, createCreatorClient } from "src/sdk";
10
10
  import { new1155ContractVersion } from "src/create/contract-setup";
11
11
  import { ISubgraphQuerier } from "src/apis/subgraph-querier";
12
12
  import { mockTimedSaleStrategyTokenQueryResult } from "src/fixtures/mint-query-results";
@@ -16,11 +16,32 @@ import {
16
16
  zoraCreator1155ImplABI,
17
17
  } from "@zoralabs/protocol-deployments";
18
18
  import { makeContractParameters } from "src/utils";
19
- import { mockRewardsQueryResults } from "src/fixtures/rewards-query-results";
20
19
  import { setupContractAndToken } from "src/fixtures/contract-setup";
21
20
  import { advanceToSaleAndAndLaunchMarket } from "src/fixtures/secondary";
21
+ import { CreatorERC20zQueryResult } from "./subgraph-queries";
22
22
 
23
23
  describe("rewardsClient", () => {
24
+ makeAnvilTest({
25
+ forkBlockNumber: 22375202,
26
+ forkUrl: forkUrls.baseMainnet,
27
+ anvilChainId: base.id,
28
+ })(
29
+ "it can query rewards balances where there are multiple minters",
30
+ async ({ viemClients: { publicClient, chain } }) => {
31
+ const creatorClient = createCreatorClient({
32
+ chainId: chain.id,
33
+ publicClient,
34
+ });
35
+ const rewardsBalance = await creatorClient.getRewardsBalances({
36
+ account: "0x129F04B140Acc1AA350be2F9f048C178103c62f3",
37
+ });
38
+
39
+ const erc20zKeys = Object.keys(rewardsBalance.secondaryRoyalties.erc20);
40
+
41
+ expect(erc20zKeys.length).toBeGreaterThan(0);
42
+ },
43
+ 20_000,
44
+ );
24
45
  makeAnvilTest({
25
46
  forkBlockNumber: 14653556,
26
47
  forkUrl: forkUrls.zoraSepolia,
@@ -251,20 +272,31 @@ describe("rewardsClient", () => {
251
272
 
252
273
  // now we should be able to get rewards balances for these royalties
253
274
 
275
+ const mockResult: CreatorERC20zQueryResult = {
276
+ zoraCreateTokens: [
277
+ {
278
+ salesStrategies: [
279
+ {
280
+ zoraTimedMinter: {
281
+ secondaryActivated: true,
282
+ erc20Z: { id: erc20z },
283
+ },
284
+ },
285
+ ],
286
+ },
287
+ ],
288
+ };
289
+
254
290
  // we need to stub the subgraph return
255
291
  rewardsGetter.subgraphQuerier.query = vi
256
292
  .fn<ISubgraphQuerier["query"]>()
257
- .mockResolvedValue(
258
- mockRewardsQueryResults({
259
- erc20z: [erc20z],
260
- }),
261
- );
293
+ .mockResolvedValue(mockResult);
262
294
 
263
295
  const rewardsBalance = await creatorClient.getRewardsBalances({
264
296
  account: creatorAccount,
265
297
  });
266
298
 
267
- expect(rewardsBalance.secondaryRoyalties.eth).toBeGreaterThan(0);
299
+ expect(rewardsBalance.protocolRewards).toBeGreaterThan(0n);
268
300
  expect(rewardsBalance.secondaryRoyalties.erc20[erc20z]).toBeGreaterThan(
269
301
  0,
270
302
  );
@@ -77,7 +77,13 @@ export const getRewardsBalance = async ({
77
77
  rewardsGetter: IRewardsGetter;
78
78
  }): Promise<RewardsBalance> => {
79
79
  const address = typeof account === "string" ? account : account.address;
80
- const erc20Zs = await rewardsGetter.getErc20ZzForCreator({ address });
80
+ const erc20ZsAndSecondaryActivated = await rewardsGetter.getErc20ZzForCreator(
81
+ { address },
82
+ );
83
+
84
+ const validErc20Zs = erc20ZsAndSecondaryActivated
85
+ .filter(({ secondaryActivated }) => secondaryActivated)
86
+ .map(({ erc20z }) => erc20z);
81
87
 
82
88
  // Perform multicall to get protocol rewards balance and unclaimed fees
83
89
  const result = await (publicClient as PublicClientWithMulticall).multicall({
@@ -98,7 +104,7 @@ export const getRewardsBalance = async ({
98
104
  ],
99
105
  abi: erc20ZRoyaltiesABI,
100
106
  functionName: "getUnclaimedFeesBatch",
101
- args: [erc20Zs],
107
+ args: [validErc20Zs],
102
108
  },
103
109
  ],
104
110
  multicallAddress: multicall3Address,
@@ -147,9 +153,13 @@ const makeClaimSecondaryRoyaltiesCalls = async ({
147
153
  chainId: number;
148
154
  rewardsGetter: IRewardsGetter;
149
155
  }) => {
150
- const erc20z = await rewardsGetter.getErc20ZzForCreator({
151
- address: claimFor,
152
- });
156
+ const erc20ZsAndSecondaryActivated = await rewardsGetter.getErc20ZzForCreator(
157
+ { address: claimFor },
158
+ );
159
+
160
+ const erc20z = erc20ZsAndSecondaryActivated
161
+ .filter(({ secondaryActivated }) => secondaryActivated)
162
+ .map(({ erc20z }) => erc20z);
153
163
 
154
164
  const royaltiesAddress =
155
165
  erc20ZRoyaltiesAddress[chainId as keyof typeof erc20ZRoyaltiesAddress];
@@ -4,7 +4,8 @@ import { Address } from "viem";
4
4
  export type RewardsToken = {
5
5
  salesStrategies: [
6
6
  {
7
- zoraTimedMinter: {
7
+ zoraTimedMinter?: {
8
+ secondaryActivated: boolean;
8
9
  erc20Z: {
9
10
  id: Address;
10
11
  };
@@ -26,13 +27,14 @@ export function buildCreatorERC20zs({
26
27
  query: `
27
28
  query ($address: Bytes!) {
28
29
  zoraCreateTokens(
29
- where: { royalties_: { user: $address }, salesStrategies_: { type: "ZORA_TIMED" } }
30
+ where: { royalties_: { royaltyRecipient: $address }, salesStrategies_: { type: "ZORA_TIMED" } }
30
31
  ) {
31
32
  royalties {
32
33
  user
33
34
  }
34
35
  salesStrategies {
35
36
  zoraTimedMinter {
37
+ secondaryActivated
36
38
  erc20Z {
37
39
  id
38
40
  }
@@ -4,7 +4,9 @@ import { Address } from "viem";
4
4
  import { buildCreatorERC20zs } from "./subgraph-queries";
5
5
 
6
6
  export interface IRewardsGetter {
7
- getErc20ZzForCreator: (params: { address: Address }) => Promise<Address[]>;
7
+ getErc20ZzForCreator: (params: {
8
+ address: Address;
9
+ }) => Promise<{ secondaryActivated: boolean; erc20z: Address }[]>;
8
10
  }
9
11
 
10
12
  export class SubgraphRewardsGetter
@@ -15,19 +17,31 @@ export class SubgraphRewardsGetter
15
17
  super(chainId, subgraphQuerier);
16
18
  }
17
19
 
18
- async getErc20ZzForCreator({
19
- address,
20
- }: {
21
- address: Address;
22
- }): Promise<Address[]> {
20
+ async getErc20ZzForCreator({ address }: { address: Address }) {
23
21
  const queryResults = await this.querySubgraphWithRetries(
24
22
  buildCreatorERC20zs({ address }),
25
23
  );
26
24
 
27
- return (
28
- queryResults?.map(
29
- (result) => result.salesStrategies[0].zoraTimedMinter.erc20Z.id,
30
- ) || []
25
+ const results = (
26
+ queryResults?.map((result) => {
27
+ const timedMinter = result.salesStrategies[0].zoraTimedMinter;
28
+
29
+ if (!timedMinter) {
30
+ return null;
31
+ }
32
+
33
+ return {
34
+ secondaryActivated: timedMinter.secondaryActivated,
35
+ erc20z: timedMinter.erc20Z.id,
36
+ };
37
+ }) || []
38
+ ).filter(
39
+ (
40
+ idAndActivated,
41
+ ): idAndActivated is { secondaryActivated: boolean; erc20z: Address } =>
42
+ !!idAndActivated,
31
43
  );
44
+
45
+ return results;
32
46
  }
33
47
  }
package/src/sdk.ts CHANGED
@@ -116,7 +116,6 @@ export function createCollectorClient(
116
116
  publicClient: params.publicClient,
117
117
  premintGetter: premintGetterToUse,
118
118
  mintGetter: mintGetterToUse,
119
- chainId: params.chainId,
120
119
  });
121
120
  const secondaryClient = new SecondaryClient({
122
121
  publicClient: params.publicClient,