@zoralabs/protocol-sdk 0.5.17 → 0.7.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 (84) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +19 -0
  3. package/README.md +1 -416
  4. package/dist/constants.d.ts +0 -1
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/create/1155-create-helper.d.ts +16 -55
  7. package/dist/create/1155-create-helper.d.ts.map +1 -1
  8. package/dist/create/contract-setup.d.ts +14 -0
  9. package/dist/create/contract-setup.d.ts.map +1 -0
  10. package/dist/create/token-setup.d.ts +27 -0
  11. package/dist/create/token-setup.d.ts.map +1 -0
  12. package/dist/create/types.d.ts +45 -0
  13. package/dist/create/types.d.ts.map +1 -0
  14. package/dist/index.cjs +1745 -891
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +3 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1698 -858
  19. package/dist/index.js.map +1 -1
  20. package/dist/mint/mint-client.d.ts +48 -51
  21. package/dist/mint/mint-client.d.ts.map +1 -1
  22. package/dist/mint/mint-queries.d.ts +38 -0
  23. package/dist/mint/mint-queries.d.ts.map +1 -0
  24. package/dist/mint/mint-transactions.d.ts +20 -0
  25. package/dist/mint/mint-transactions.d.ts.map +1 -0
  26. package/dist/mint/subgraph-mint-getter.d.ts +24 -0
  27. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -0
  28. package/dist/mint/subgraph-queries.d.ts +55 -0
  29. package/dist/mint/subgraph-queries.d.ts.map +1 -0
  30. package/dist/mint/types.d.ts +177 -0
  31. package/dist/mint/types.d.ts.map +1 -0
  32. package/dist/mint/utils.d.ts +2 -0
  33. package/dist/mint/utils.d.ts.map +1 -0
  34. package/dist/mints/mints-contracts.d.ts +27 -4518
  35. package/dist/mints/mints-contracts.d.ts.map +1 -1
  36. package/dist/premint/contract-types.d.ts +4 -4
  37. package/dist/premint/contract-types.d.ts.map +1 -1
  38. package/dist/premint/conversions.d.ts +15 -16
  39. package/dist/premint/conversions.d.ts.map +1 -1
  40. package/dist/premint/premint-api-client.d.ts +32 -16
  41. package/dist/premint/premint-api-client.d.ts.map +1 -1
  42. package/dist/premint/premint-client.d.ts +76 -50
  43. package/dist/premint/premint-client.d.ts.map +1 -1
  44. package/dist/premint/preminter.d.ts +20 -8
  45. package/dist/premint/preminter.d.ts.map +1 -1
  46. package/dist/sdk.d.ts +45 -0
  47. package/dist/sdk.d.ts.map +1 -0
  48. package/dist/types.d.ts +3 -0
  49. package/dist/types.d.ts.map +1 -1
  50. package/dist/utils.d.ts +24 -6869
  51. package/dist/utils.d.ts.map +1 -1
  52. package/package.json +3 -2
  53. package/src/constants.ts +0 -36
  54. package/src/create/1155-create-helper.test.ts +236 -55
  55. package/src/create/1155-create-helper.ts +141 -309
  56. package/src/create/contract-setup.ts +88 -0
  57. package/src/create/token-setup.ts +379 -0
  58. package/src/create/types.ts +57 -0
  59. package/src/index.ts +5 -1
  60. package/src/mint/mint-client.test.ts +116 -78
  61. package/src/mint/mint-client.ts +130 -234
  62. package/src/mint/mint-queries.ts +320 -0
  63. package/src/mint/mint-transactions.ts +253 -0
  64. package/src/mint/subgraph-mint-getter.ts +247 -0
  65. package/src/mint/subgraph-queries.ts +170 -0
  66. package/src/mint/types.ts +239 -0
  67. package/src/mint/utils.ts +14 -0
  68. package/src/mints/mints-contracts.test.ts +1 -1
  69. package/src/mints/mints-contracts.ts +4 -4
  70. package/src/premint/contract-types.ts +4 -4
  71. package/src/premint/conversions.ts +38 -4
  72. package/src/premint/premint-api-client.ts +92 -48
  73. package/src/premint/premint-client.test.ts +100 -84
  74. package/src/premint/premint-client.ts +186 -185
  75. package/src/premint/preminter.test.ts +4 -5
  76. package/src/premint/preminter.ts +63 -14
  77. package/src/sdk.ts +101 -0
  78. package/src/types.ts +18 -0
  79. package/src/utils.ts +54 -46
  80. package/test-integration/setup-test-contracts.ts +96 -0
  81. package/dist/mint/mint-api-client.d.ts +0 -35
  82. package/dist/mint/mint-api-client.d.ts.map +0 -1
  83. package/src/mint/mint-api-client.ts +0 -177
  84. package/test-integration/premint-client.test.ts +0 -148
@@ -1,19 +1,20 @@
1
1
  import { describe, expect } from "vitest";
2
- import { Address, parseAbi, parseEther } from "viem";
3
- import { zora } from "viem/chains";
4
- import {
5
- zoraCreator1155ImplABI,
6
- erc20MinterAddress,
7
- } from "@zoralabs/protocol-deployments";
8
- import { createMintClient } from "./mint-client";
9
- import { anvilTest, forkUrls, makeAnvilTest } from "src/anvil";
2
+ import { Address, erc20Abi, parseAbi, parseEther } from "viem";
3
+ import { zora, zoraSepolia } from "viem/chains";
4
+ import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
5
+ import { forkUrls, makeAnvilTest } from "src/anvil";
6
+ import { createCollectorClient } from "src/sdk";
10
7
 
11
8
  const erc721ABI = parseAbi([
12
9
  "function balanceOf(address owner) public view returns (uint256)",
13
10
  ] as const);
14
11
 
15
12
  describe("mint-helper", () => {
16
- anvilTest(
13
+ makeAnvilTest({
14
+ forkBlockNumber: 16028671,
15
+ forkUrl: forkUrls.zoraMainnet,
16
+ anvilChainId: zora.id,
17
+ })(
17
18
  "mints a new 1155 token",
18
19
  async ({ viemClients }) => {
19
20
  const { testClient, walletClient, publicClient } = viemClients;
@@ -25,18 +26,29 @@ describe("mint-helper", () => {
25
26
  const targetContract: Address =
26
27
  "0xa2fea3537915dc6c7c7a97a82d1236041e6feb2e";
27
28
  const targetTokenId = 1n;
28
- const minter = createMintClient({ chain: zora });
29
+ const collectorClient = createCollectorClient({
30
+ chainId: zora.id,
31
+ publicClient,
32
+ });
29
33
 
30
- const params = await minter.makePrepareMintTokenParams({
31
- minterAccount: creatorAccount,
34
+ const { token: mintable, prepareMint } = await collectorClient.getToken({
35
+ tokenContract: targetContract,
36
+ mintType: "1155",
32
37
  tokenId: targetTokenId,
33
- tokenAddress: targetContract,
34
- mintArguments: {
35
- mintToAddress: creatorAccount,
36
- quantityToMint: 1,
37
- },
38
38
  });
39
39
 
40
+ mintable.maxSupply;
41
+ mintable.totalMinted;
42
+ mintable.tokenURI;
43
+ mintable;
44
+
45
+ const { parameters, costs } = prepareMint({
46
+ minterAccount: creatorAccount,
47
+ quantityToMint: 1,
48
+ });
49
+
50
+ expect(costs.totalCostEth).toBe(1n * parseEther("0.000777"));
51
+
40
52
  const oldBalance = await publicClient.readContract({
41
53
  abi: zoraCreator1155ImplABI,
42
54
  address: targetContract,
@@ -44,7 +56,7 @@ describe("mint-helper", () => {
44
56
  args: [creatorAccount, targetTokenId],
45
57
  });
46
58
 
47
- const simulationResult = await publicClient.simulateContract(params);
59
+ const simulationResult = await publicClient.simulateContract(parameters);
48
60
 
49
61
  const hash = await walletClient.writeContract(simulationResult.request);
50
62
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
@@ -64,6 +76,7 @@ describe("mint-helper", () => {
64
76
  makeAnvilTest({
65
77
  forkUrl: forkUrls.zoraMainnet,
66
78
  forkBlockNumber: 6133407,
79
+ anvilChainId: zora.id,
67
80
  })(
68
81
  "mints a new 721 token",
69
82
  async ({ viemClients }) => {
@@ -76,18 +89,29 @@ describe("mint-helper", () => {
76
89
 
77
90
  const targetContract: Address =
78
91
  "0x7aae7e67515A2CbB8585C707Ca6db37BDd3EA839";
79
- const targetTokenId = undefined;
80
- const minter = createMintClient({ chain: zora });
92
+ const collectorClient = createCollectorClient({
93
+ chainId: zora.id,
94
+ publicClient,
95
+ });
81
96
 
82
- const params = await minter.makePrepareMintTokenParams({
83
- tokenId: targetTokenId,
84
- tokenAddress: targetContract,
97
+ const { prepareMint } = await collectorClient.getToken({
98
+ tokenContract: targetContract,
99
+ mintType: "721",
100
+ });
101
+
102
+ const quantityToMint = 3n;
103
+
104
+ const { parameters, costs } = prepareMint({
85
105
  minterAccount: creatorAccount,
86
- mintArguments: {
87
- mintToAddress: creatorAccount,
88
- quantityToMint: 1,
89
- },
106
+ mintRecipient: creatorAccount,
107
+ quantityToMint,
90
108
  });
109
+
110
+ expect(costs.totalPurchaseCost).toBe(quantityToMint * parseEther(".08"));
111
+ expect(costs.totalCostEth).toBe(
112
+ quantityToMint * (parseEther("0.08") + parseEther("0.000777")),
113
+ );
114
+
91
115
  const oldBalance = await publicClient.readContract({
92
116
  abi: erc721ABI,
93
117
  address: targetContract,
@@ -95,7 +119,7 @@ describe("mint-helper", () => {
95
119
  args: [creatorAccount],
96
120
  });
97
121
 
98
- const simulated = await publicClient.simulateContract(params);
122
+ const simulated = await publicClient.simulateContract(parameters);
99
123
 
100
124
  const hash = await walletClient.writeContract(simulated.request);
101
125
 
@@ -110,7 +134,7 @@ describe("mint-helper", () => {
110
134
  });
111
135
 
112
136
  expect(oldBalance).to.be.equal(0n);
113
- expect(newBalance).to.be.equal(1n);
137
+ expect(newBalance).to.be.equal(quantityToMint);
114
138
  },
115
139
  12 * 1000,
116
140
  );
@@ -118,67 +142,64 @@ describe("mint-helper", () => {
118
142
  makeAnvilTest({
119
143
  forkUrl: forkUrls.zoraMainnet,
120
144
  forkBlockNumber: 14484183,
145
+ anvilChainId: zora.id,
121
146
  })(
122
147
  "mints an 1155 token with an ERC20 token",
123
148
  async ({ viemClients }) => {
124
- const { testClient, walletClient, publicClient } = viemClients;
149
+ const { testClient, walletClient, publicClient, chain } = viemClients;
125
150
 
126
151
  const targetContract: Address =
127
152
  "0x689bc305456c38656856d12469aed282fbd89fe0";
128
153
  const targetTokenId = 16n;
129
154
 
130
- const minter = createMintClient({ chain: zora });
155
+ const minter = createCollectorClient({ chainId: chain.id, publicClient });
131
156
 
132
157
  const mockCollector = "0xb6b701878a1f80197dF2c209D0BDd292EA73164D";
133
158
  await testClient.impersonateAccount({
134
159
  address: mockCollector,
135
160
  });
136
161
 
137
- const erc20Currency = "0xa6b280b42cb0b7c4a4f789ec6ccc3a7609a1bc39";
138
- const erc20PricePerToken = 1000000000000000000n;
162
+ const { prepareMint } = await minter.getToken({
163
+ mintType: "1155",
164
+ tokenContract: targetContract,
165
+ tokenId: targetTokenId,
166
+ });
167
+
168
+ const quantityToMint = 1n;
139
169
 
140
- const erc20Abi = parseAbi([
141
- "function balanceOf(address) public view returns (uint256)",
142
- "function approve(address spender, uint256 amount) public returns (bool)",
143
- "function allowance(address owner, address spender) public view returns (uint256)",
144
- ]);
170
+ const { parameters, erc20Approval, costs } = prepareMint({
171
+ minterAccount: mockCollector,
172
+ quantityToMint,
173
+ });
174
+
175
+ expect(erc20Approval).toBeDefined();
176
+ expect(costs.totalCostEth).toBe(0n);
177
+ expect(costs.totalPurchaseCost).toBe(
178
+ quantityToMint * 1000000000000000000n,
179
+ );
180
+ expect(costs.totalPurchaseCostCurrency).toBe(
181
+ "0xa6b280b42cb0b7c4a4f789ec6ccc3a7609a1bc39",
182
+ );
145
183
 
146
184
  const beforeERC20Balance = await publicClient.readContract({
147
185
  abi: erc20Abi,
148
- address: erc20Currency,
186
+ address: erc20Approval!.erc20,
149
187
  functionName: "balanceOf",
150
188
  args: [mockCollector],
151
189
  });
152
190
 
153
- const { request } = await publicClient.simulateContract({
154
- account: mockCollector,
155
- address: erc20Currency,
191
+ // execute the erc20 approval
192
+ const { request: erc20Request } = await publicClient.simulateContract({
156
193
  abi: erc20Abi,
194
+ address: erc20Approval!.erc20,
157
195
  functionName: "approve",
158
- args: [erc20MinterAddress[7777777], erc20PricePerToken],
159
- });
160
- const approveHash = await walletClient.writeContract(request);
161
- const approveTxReciept = await publicClient.waitForTransactionReceipt({
162
- hash: approveHash,
163
- });
164
- expect(approveTxReciept).to.not.be.null;
165
-
166
- const beforeAllowance = await publicClient.readContract({
167
- abi: erc20Abi,
168
- address: erc20Currency,
169
- functionName: "allowance",
170
- args: [mockCollector, erc20MinterAddress[7777777]],
196
+ args: [erc20Approval!.approveTo, erc20Approval!.quantity],
197
+ account: mockCollector,
171
198
  });
172
- expect(beforeAllowance).to.be.equal(erc20PricePerToken);
173
199
 
174
- const params = await minter.makePrepareMintTokenParams({
175
- minterAccount: mockCollector,
176
- tokenId: targetTokenId,
177
- tokenAddress: targetContract,
178
- mintArguments: {
179
- mintToAddress: mockCollector,
180
- quantityToMint: 1,
181
- },
200
+ const approveHash = await walletClient.writeContract(erc20Request);
201
+ await publicClient.waitForTransactionReceipt({
202
+ hash: approveHash,
182
203
  });
183
204
 
184
205
  const beforeCollector1155Balance = await publicClient.readContract({
@@ -189,27 +210,20 @@ describe("mint-helper", () => {
189
210
  });
190
211
  expect(beforeCollector1155Balance).to.be.equal(0n);
191
212
 
192
- const simulationResult = await publicClient.simulateContract(params);
213
+ // execute the mint
214
+ const simulationResult = await publicClient.simulateContract(parameters);
193
215
  const hash = await walletClient.writeContract(simulationResult.request);
194
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
195
- expect(receipt).to.not.be.null;
196
-
197
- const afterAllowance = await publicClient.readContract({
198
- abi: erc20Abi,
199
- address: erc20Currency,
200
- functionName: "allowance",
201
- args: [mockCollector, erc20MinterAddress[7777777]],
202
- });
203
- expect(afterAllowance).to.be.equal(0n);
216
+ await publicClient.waitForTransactionReceipt({ hash });
204
217
 
205
218
  const afterERC20Balance = await publicClient.readContract({
206
219
  abi: erc20Abi,
207
- address: erc20Currency,
220
+ address: erc20Approval!.erc20,
208
221
  functionName: "balanceOf",
209
222
  args: [mockCollector],
210
223
  });
224
+
211
225
  expect(beforeERC20Balance - afterERC20Balance).to.be.equal(
212
- erc20PricePerToken,
226
+ erc20Approval!.quantity,
213
227
  );
214
228
 
215
229
  const afterCollector1155Balance = await publicClient.readContract({
@@ -218,7 +232,31 @@ describe("mint-helper", () => {
218
232
  functionName: "balanceOf",
219
233
  args: [mockCollector, targetTokenId],
220
234
  });
221
- expect(afterCollector1155Balance).to.be.equal(1n);
235
+ expect(afterCollector1155Balance).to.be.equal(quantityToMint);
236
+ },
237
+ 12 * 1000,
238
+ );
239
+
240
+ makeAnvilTest({
241
+ forkUrl: forkUrls.zoraSepolia,
242
+ forkBlockNumber: 10294670,
243
+ anvilChainId: zoraSepolia.id,
244
+ })(
245
+ "gets onchain and premint mintables",
246
+ async ({ viemClients }) => {
247
+ const { publicClient, chain } = viemClients;
248
+
249
+ const targetContract: Address =
250
+ "0xa33e4228843092bb0f2fcbb2eb237bcefc1046b3";
251
+
252
+ const minter = createCollectorClient({ chainId: chain.id, publicClient });
253
+
254
+ const { tokens: mintables, contract } = await minter.getTokensOfContract({
255
+ tokenContract: targetContract,
256
+ });
257
+
258
+ expect(mintables.length).toBe(4);
259
+ expect(contract).toBeDefined();
222
260
  },
223
261
  12 * 1000,
224
262
  );