@zoralabs/protocol-sdk 0.5.10 → 0.5.12

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 (39) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/CHANGELOG.md +15 -0
  3. package/README.md +10 -0
  4. package/dist/create/1155-create-helper.d.ts +2 -2
  5. package/dist/create/1155-create-helper.d.ts.map +1 -1
  6. package/dist/index.cjs +136 -212
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +135 -209
  11. package/dist/index.js.map +1 -1
  12. package/dist/mint/mint-client.d.ts +3 -4
  13. package/dist/mint/mint-client.d.ts.map +1 -1
  14. package/dist/mints/mints-contracts.d.ts +2868 -2027
  15. package/dist/mints/mints-contracts.d.ts.map +1 -1
  16. package/dist/mints/mints-eth-unwrapper-and-caller.d.ts +78 -0
  17. package/dist/mints/mints-eth-unwrapper-and-caller.d.ts.map +1 -0
  18. package/dist/mints/mints-relay-example.d.ts +60 -0
  19. package/dist/mints/mints-relay-example.d.ts.map +1 -0
  20. package/dist/premint/premint-client.d.ts +1 -1
  21. package/dist/premint/premint-client.d.ts.map +1 -1
  22. package/dist/preminter.d.ts +23 -11
  23. package/dist/preminter.d.ts.map +1 -1
  24. package/dist/test-utils.d.ts +11 -0
  25. package/dist/test-utils.d.ts.map +1 -0
  26. package/dist/utils.d.ts +3 -0
  27. package/dist/utils.d.ts.map +1 -0
  28. package/package.json +6 -4
  29. package/src/create/1155-create-helper.ts +14 -11
  30. package/src/index.ts +2 -0
  31. package/src/mint/mint-client.ts +16 -19
  32. package/src/mints/mints-contracts.test.ts +32 -225
  33. package/src/mints/mints-contracts.ts +200 -281
  34. package/src/mints/mints-eth-unwrapper-and-caller.test.ts +467 -0
  35. package/src/mints/mints-eth-unwrapper-and-caller.ts +83 -0
  36. package/src/mints/mints-relay-example.ts +313 -0
  37. package/src/premint/premint-client.ts +15 -11
  38. package/src/test-utils.ts +39 -0
  39. package/src/utils.ts +30 -0
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  zoraMints1155Config,
3
3
  zoraMintsManagerImplABI,
4
+ zoraMintsManagerImplAddress,
4
5
  zoraMintsManagerImplConfig,
5
- mintsEthUnwrapperAndCallerConfig,
6
- iUnwrapAndForwardActionABI,
7
6
  } from "@zoralabs/protocol-deployments";
8
7
  import { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
9
8
  import {
@@ -11,23 +10,36 @@ import {
11
10
  PremintConfigV2,
12
11
  } from "src/premint/contract-types";
13
12
  import { ContractCreationConfig } from "src/preminter";
13
+ import { makeSimulateContractParamaters } from "src/utils";
14
14
  import {
15
15
  Account,
16
16
  Address,
17
17
  ContractFunctionRevertedError,
18
18
  Hex,
19
+ PublicClient,
19
20
  ReadContractParameters,
20
21
  SignTypedDataParameters,
21
- SimulateContractParameters,
22
22
  TypedData,
23
23
  decodeErrorResult,
24
- encodeAbiParameters,
25
24
  encodeFunctionData,
26
- parseAbiParameters,
27
25
  zeroAddress,
28
26
  } from "viem";
29
27
 
30
- export function mintWithEthParams({
28
+ const addressOrAccountAddress = (address: Address | Account) =>
29
+ typeof address === "string" ? address : address.address;
30
+
31
+ /**
32
+ * Constructs the parameters to mint a MINT with ETH on the ZoraMintsManager based on the price of the currently mintable ETH token.
33
+ *
34
+ * @param quantity - The number of mints to be created.
35
+ * @param recipient - The address that will receive the mints.
36
+ * @param chainId - The ID of the blockchain network where the contract is deployed.
37
+ * @param pricePerMint - The price for each mint in ETH. Must match the price of the defualt mintable ETH token.
38
+ * @param account - The address or account that is creating the mints.
39
+ *
40
+ * @returns The parameters for the `mintWithEth` function call, including the ABI, contract address, function name, arguments, value, and account.
41
+ */
42
+ export const mintWithEthParams = ({
31
43
  quantity,
32
44
  recipient,
33
45
  chainId,
@@ -35,23 +47,19 @@ export function mintWithEthParams({
35
47
  account,
36
48
  }: {
37
49
  quantity: bigint;
38
- recipient: Address;
50
+ recipient?: Address;
39
51
  chainId: keyof typeof zoraMints1155Config.address;
40
52
  pricePerMint: bigint;
41
53
  account: Address | Account;
42
- }): SimulateContractParameters<
43
- typeof zoraMintsManagerImplConfig.abi,
44
- "mintWithEth"
45
- > {
46
- return {
54
+ }) =>
55
+ makeSimulateContractParamaters({
47
56
  abi: zoraMintsManagerImplConfig.abi,
48
57
  address: zoraMintsManagerImplConfig.address[chainId],
49
58
  functionName: "mintWithEth",
50
- args: [quantity, recipient],
59
+ args: [quantity, recipient || addressOrAccountAddress(account)],
51
60
  value: pricePerMint * quantity,
52
61
  account,
53
- };
54
- }
62
+ });
55
63
 
56
64
  const getPaidMintValue = (quantities: bigint[], pricePerMint?: bigint) => {
57
65
  if (!pricePerMint || pricePerMint === 0n) return;
@@ -59,12 +67,11 @@ const getPaidMintValue = (quantities: bigint[], pricePerMint?: bigint) => {
59
67
  return quantities.reduce((a, b) => a + b, 0n) * pricePerMint;
60
68
  };
61
69
 
62
- export const fixedPriceMinterMinterArguments = ({
63
- mintRecipient,
64
- }: {
65
- mintRecipient: Address;
66
- }) => encodeAbiParameters(parseAbiParameters("address"), [mintRecipient]);
67
-
70
+ /**
71
+ * Constructs the parameters to get the total mints balance of an account on the ZoraMints1155 contract.
72
+ * @param account - The address of the account to check the balance of.
73
+ * @returns The parameters for the `balanceOfAccount` function call, including the ABI, contract address, function name, and arguments.
74
+ */
68
75
  export const mintsBalanceOfAccountParams = ({
69
76
  account,
70
77
  chainId,
@@ -107,125 +114,114 @@ export const encodeCollectOnManager = ({
107
114
  ],
108
115
  });
109
116
 
117
+ /**
118
+ * Constructs parameters to collect a Zora Creator 1155 token using MINTs an account owns.
119
+ * @param tokenIds - The MINT token ids to use to collect the Zora Creator 1155 token with.
120
+ * @param quantities - The quantities of each MINT token to use to collect the Zora Creator 1155 token with. The sum of these quantities will be the total quantity of the Zora Creator 1155 token collected.
121
+ * @param chainId - The ID of the chain where the MINTs are to be used
122
+ * @param paidMintPricePerToken - If this is for a paid mint, this is the price in eth per each token to be collected
123
+ * @param account - The account that will be executing the transaction, and whos MINTs will be used
124
+ * @param mintArguments - The minterArguments, mintRewardsRecipients, and mintComment
125
+ * @param minter - The IMinter1155 used by the Zora Creator 1155 contract to mint the tokens
126
+ * @param zoraCreator1155Contract - The Zora Creator 1155 contract address to mint tokens on
127
+ * @param zoraCreator1155TokenId - The token id on the Zora Creator contract to mint
128
+ */
110
129
  export function collectWithMintsParams({
111
130
  tokenIds,
112
131
  quantities,
113
132
  chainId,
114
- pricePerToken,
133
+ paidMintPricePerToken,
115
134
  account,
116
- ...rest
135
+ mintArguments,
136
+ minter,
137
+ zoraCreator1155Contract,
138
+ zoraCreator1155TokenId,
117
139
  }: {
118
140
  paidMintValue?: bigint;
119
141
  chainId: keyof typeof zoraMints1155Config.address;
120
- pricePerToken?: bigint;
142
+ paidMintPricePerToken?: bigint;
121
143
  account: Address | Account;
122
- } & CollectOnManagerParams): SimulateContractParameters<
123
- typeof zoraMints1155Config.abi,
124
- "transferBatchToManagerAndCall"
125
- > {
144
+ } & CollectOnManagerParams) {
126
145
  const call = encodeCollectOnManager({
127
146
  tokenIds,
128
147
  quantities,
129
- ...rest,
148
+ zoraCreator1155Contract,
149
+ zoraCreator1155TokenId,
150
+ minter,
151
+ mintArguments,
130
152
  });
131
153
 
132
- return {
154
+ return makeSimulateContractParamaters({
133
155
  abi: zoraMints1155Config.abi,
134
156
  address: zoraMints1155Config.address[chainId],
135
157
  functionName: "transferBatchToManagerAndCall",
136
158
  args: [tokenIds, quantities, call],
137
- value: getPaidMintValue(quantities, pricePerToken),
159
+ // if it is a paid mint, the aadditional value will be sent to the manager contract and forwarded to the creator 1155 contract
160
+ // for the paid mint cost.
161
+ value: getPaidMintValue(quantities, paidMintPricePerToken),
138
162
  account,
139
- };
163
+ });
140
164
  }
141
165
 
142
- export const collectWithMintsTypedDataDefinition = ({
143
- tokenIds,
144
- quantities,
145
- chainId,
146
- account,
147
- nonce,
148
- deadline,
149
- ...rest
150
- }: {
166
+ type PermitTransferBatchParameters = {
167
+ tokenIds: bigint[];
168
+ quantities: bigint[];
151
169
  chainId: keyof typeof zoraMints1155Config.address;
152
170
  nonce: bigint;
153
171
  deadline: bigint;
154
- account: Account | Address;
155
- } & CollectOnManagerParams) => {
156
- const safeTransferData = encodeCollectOnManager({
157
- tokenIds,
158
- quantities,
159
- ...rest,
160
- });
161
-
162
- return makePermitTransferBatchAndTypeData({
163
- tokenIds,
164
- quantities,
165
- chainId,
166
- account,
167
- nonce,
168
- deadline,
169
- safeTransferData,
170
- // will safe transfer to manager contract before doing the
171
- // collect operation
172
- to: zoraMintsManagerImplConfig.address[chainId],
173
- });
172
+ mintsOwner: Account | Address;
173
+ to: Address;
174
+ safeTransferData: Hex;
174
175
  };
175
176
 
176
- export const collectPremintWithMintsTypedDataDefinition = ({
177
- tokenIds,
178
- quantities,
179
- chainId,
180
- account,
181
- nonce,
182
- deadline,
183
- ...rest
177
+ /**
178
+ * Get the current price to mint a MINT with ETH
179
+ * @param publicClient - The public client to use to read the contract
180
+ */
181
+ export function getMintsEthPrice({
182
+ publicClient,
184
183
  }: {
185
- chainId: keyof typeof zoraMints1155Config.address;
186
- nonce: bigint;
187
- deadline: bigint;
188
- account: Account | Address;
189
- } & PremintOnManagerParams) => {
190
- const safeTransferData = encodePremintOnManager({
191
- ...rest,
192
- });
193
-
194
- return makePermitTransferBatchAndTypeData({
195
- tokenIds,
196
- quantities,
197
- chainId,
198
- account,
199
- nonce,
200
- deadline,
201
- safeTransferData,
202
- // will safe transfer to manager contract before doing the
203
- // collect operation
204
- to: zoraMintsManagerImplConfig.address[chainId],
184
+ publicClient: PublicClient;
185
+ }) {
186
+ const chainId = publicClient.chain?.id as
187
+ | keyof typeof zoraMintsManagerImplAddress
188
+ | undefined;
189
+ // if chain id is not in the zoraMintsManagerImplAddress, throw an error:
190
+ if (!chainId || !zoraMintsManagerImplAddress[chainId]) {
191
+ throw new Error(`Chain id ${chainId} not supported`);
192
+ }
193
+
194
+ return publicClient.readContract({
195
+ abi: zoraMintsManagerImplABI,
196
+ address: zoraMintsManagerImplAddress[chainId],
197
+ functionName: "getEthPrice",
205
198
  });
206
- };
199
+ }
207
200
 
208
- function makePermitTransferBatchAndTypeData({
201
+ /**
202
+ * Builds the permit data and typed data to sign for permitting a batch transfer of MINTs.
203
+ * @param tokenIds - The token ids to transfer.
204
+ * @param quantities - The quantities of each token to transfer.
205
+ * @param chainId - The ID of the chain where the MINTs are to be used
206
+ * @param mintsOwner - The account that owns the MINTs to be transferred (and the account that is to sign the permit)
207
+ * @param to - The address to transfer the MINTs to.
208
+ * @param nonce - Random nonce of the permit.
209
+ * @param deadline - The deadline of the permit.
210
+ * @param safeTransferData - The data to be sent with the transfer.
211
+ * @returns permit and corresponding typed data to sign.
212
+ */
213
+ export function makePermitTransferBatchAndTypeData({
209
214
  tokenIds,
210
215
  quantities,
211
216
  chainId,
212
- account,
217
+ mintsOwner,
213
218
  to,
214
219
  nonce,
215
220
  deadline,
216
221
  safeTransferData,
217
- }: {
218
- tokenIds: bigint[];
219
- quantities: bigint[];
220
- chainId: keyof typeof zoraMints1155Config.address;
221
- nonce: bigint;
222
- deadline: bigint;
223
- account: Account | Address;
224
- to: Address;
225
- safeTransferData: Hex;
226
- }) {
222
+ }: PermitTransferBatchParameters) {
227
223
  const permit: PermitSafeTransferBatch = {
228
- owner: typeof account === "string" ? account : account.address,
224
+ owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
229
225
  to,
230
226
  tokenIds,
231
227
  quantities,
@@ -237,7 +233,7 @@ function makePermitTransferBatchAndTypeData({
237
233
  const typedData = permitBatchTypedDataDefinition({
238
234
  chainId,
239
235
  permit,
240
- account,
236
+ account: mintsOwner,
241
237
  });
242
238
 
243
239
  return {
@@ -246,11 +242,23 @@ function makePermitTransferBatchAndTypeData({
246
242
  };
247
243
  }
248
244
 
249
- function makePermitTransferTypeData({
245
+ /**
246
+ * Builds the permit data and typed data to sign for permitting a transfer of a MINTs for a single MINTs token id
247
+ * @param tokenId - The token id to transfer.
248
+ * @param quantity - The quantity of the token to transfer.
249
+ * @param chainId - The ID of the chain where the MINTs are to be used
250
+ * @param mintsOwner - The account that owns the MINTs to be transferred (and the account that is to sign the permit)
251
+ * @param to - The address to transfer the MINTs to.
252
+ * @param nonce - Random nonce of the permit.
253
+ * @param deadline - The deadline of the permit.
254
+ * @param safeTransferData - The data to be sent with the transfer.
255
+ * @returns
256
+ */
257
+ export function makePermitTransferTypeData({
250
258
  tokenId,
251
259
  quantity,
252
260
  chainId,
253
- account,
261
+ mintsOwner,
254
262
  to,
255
263
  nonce,
256
264
  deadline,
@@ -261,12 +269,12 @@ function makePermitTransferTypeData({
261
269
  chainId: keyof typeof zoraMints1155Config.address;
262
270
  nonce: bigint;
263
271
  deadline: bigint;
264
- account: Account | Address;
272
+ mintsOwner: Account | Address;
265
273
  to: Address;
266
274
  safeTransferData: Hex;
267
275
  }) {
268
276
  const permit: PermitSafeTransfer = {
269
- owner: typeof account === "string" ? account : account.address,
277
+ owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
270
278
  to,
271
279
  tokenId,
272
280
  quantity,
@@ -278,7 +286,7 @@ function makePermitTransferTypeData({
278
286
  const typedData = permitTransferTypedDataDefinition({
279
287
  chainId,
280
288
  permit,
281
- account,
289
+ account: mintsOwner,
282
290
  });
283
291
 
284
292
  return {
@@ -297,7 +305,7 @@ type PremintOnManagerParams = {
297
305
  signerContract?: Address;
298
306
  };
299
307
 
300
- export const encodePremintOnManager = ({
308
+ const encodePremintOnManager = ({
301
309
  contractCreationConfig,
302
310
  premintConfig,
303
311
  premintSignature,
@@ -316,33 +324,101 @@ export const encodePremintOnManager = ({
316
324
  ],
317
325
  });
318
326
 
327
+ /**
328
+ * Builds a permit, and corresponding typed data to sign
329
+ * to collect a premint or non-premint Using the mints an account owns.
330
+ * @param mintsOwner - The account that owns the MINTs to be transferred (and the account that is to sign the permit)
331
+ * @param chainId - The ID of the chain where the MINTs are to be used
332
+ * @param deadline - The deadline of the permit.
333
+ * @param nonce - Random nonce of the permit.
334
+ * @param tokenIds - The mint token ids to to use
335
+ * @param quantities - The quantities of each token to use to collect the Zora Creator 1155 token with. The sum of these quantities will be the total quantity of the Zora Creator 1155 token collected.
336
+ * @param premint - If this is for a premint, the configuration of the premint to collect
337
+ * @param collect - If this is for a non-premint, the configuration of the non-premint to collect
338
+ * @returns
339
+ */
340
+ export const makePermitToCollectPremintOrNonPremint = ({
341
+ mintsOwner,
342
+ chainId,
343
+ deadline,
344
+ tokenIds,
345
+ // this quantity of MINTs will be used to collect premint
346
+ // and will be burned. This same quantity is the quantity of
347
+ // premint to collect.
348
+ quantities,
349
+ nonce,
350
+ premint,
351
+ collect,
352
+ }: Omit<PermitTransferBatchParameters, "to" | "safeTransferData"> &
353
+ (
354
+ | {
355
+ premint: Parameters<typeof encodePremintOnManager>[0];
356
+ collect?: undefined;
357
+ }
358
+ | {
359
+ premint?: undefined;
360
+ collect: Parameters<typeof encodeCollectOnManager>[0];
361
+ }
362
+ )) => {
363
+ let safeTransferData: Hex;
364
+
365
+ if (premint) {
366
+ safeTransferData = encodePremintOnManager(premint);
367
+ } else if (collect) {
368
+ safeTransferData = encodeCollectOnManager(collect);
369
+ } else {
370
+ throw new Error("Invalid operation");
371
+ }
372
+
373
+ return makePermitTransferBatchAndTypeData({
374
+ tokenIds,
375
+ quantities,
376
+ chainId,
377
+ mintsOwner,
378
+ nonce,
379
+ deadline,
380
+ safeTransferData,
381
+ to: zoraMintsManagerImplConfig.address[chainId],
382
+ });
383
+ };
384
+
385
+ /**
386
+ * Constructs the parameters to collect a premint using MINTs an account owns.
387
+ * @param tokenIds - The MINT token ids to use to collect the premint with.
388
+ * @param quantities - The quantities of each MINT token to use to collect the premint with. The sum of these quantities will be the total quantity of the premint collected.
389
+ * @param chainId - The ID of the chain where the MINTs are to be used
390
+ * @param account - The account which's MINTs will be used to collect the premint.
391
+ * @param contractCreationConfig - The premint contract creation config
392
+ * @param premintConfig - The premint config
393
+ * @param premintSignature - The signature for the premint
394
+ * @param mintArguments - The minterArguments, mintRewardsRecipients, and mintComment
395
+ * @param signerContract - The contract that signed the premint, if this is a smart wallet based premint
396
+ * @param paidMintPricePerToken - If this is for a paid mint, this is the price in eth per each token to be collected
397
+ */
319
398
  export function collectPremintV2WithMintsParams({
320
399
  tokenIds,
321
400
  quantities,
322
- pricePerToken,
401
+ paidMintPricePerToken,
323
402
  account,
324
403
  chainId,
325
404
  ...rest
326
405
  }: {
327
- pricePerToken?: bigint;
406
+ paidMintPricePerToken?: bigint;
328
407
  chainId: keyof typeof zoraMints1155Config.address;
329
408
  account: Address | Account;
330
- } & PremintOnManagerParams): SimulateContractParameters<
331
- typeof zoraMints1155Config.abi,
332
- "transferBatchToManagerAndCall"
333
- > {
409
+ } & PremintOnManagerParams) {
334
410
  const call = encodePremintOnManager({
335
411
  ...rest,
336
412
  });
337
413
 
338
- return {
414
+ return makeSimulateContractParamaters({
339
415
  abi: zoraMints1155Config.abi,
340
416
  address: zoraMints1155Config.address[chainId],
341
417
  functionName: "transferBatchToManagerAndCall",
342
418
  args: [tokenIds, quantities, call],
343
- value: getPaidMintValue(quantities, pricePerToken),
419
+ value: getPaidMintValue(quantities, paidMintPricePerToken),
344
420
  account,
345
- };
421
+ });
346
422
  }
347
423
 
348
424
  export type PermitSafeTransferBatch = AbiParametersToPrimitiveTypes<
@@ -362,7 +438,6 @@ export type PermitSafeTransfer = AbiParametersToPrimitiveTypes<
362
438
  export type CollectMintArguments = AbiParametersToPrimitiveTypes<
363
439
  ExtractAbiFunction<typeof zoraMintsManagerImplConfig.abi, "collect">["inputs"]
364
440
  >[3];
365
- // export type PermitTransferBatchToManager = ExtractAbiFunction<
366
441
 
367
442
  function makeTypeData<
368
443
  const TTypedData extends TypedData | { [key: string]: unknown },
@@ -481,167 +556,11 @@ export function permitTransferTypedDataDefinition({
481
556
  });
482
557
  }
483
558
 
484
- export const permitTransferBatchToManagerAndCallParams = ({
485
- permit,
486
- chainId,
487
- signature,
488
- }: {
489
- permit: PermitSafeTransferBatch;
490
- chainId: keyof typeof zoraMints1155Config.address;
491
- signature: Hex;
492
- }) => {
493
- const result: SimulateContractParameters<
494
- typeof zoraMints1155Config.abi,
495
- "permitSafeTransferBatch"
496
- > = {
497
- abi: zoraMints1155Config.abi,
498
- address: zoraMints1155Config.address[chainId],
499
- functionName: "permitSafeTransferBatch",
500
- args: [permit, signature],
501
- };
502
-
503
- return result;
504
- };
505
-
506
- export const safeTransferAndUnwrapTypedDataDefinition = ({
507
- chainId,
508
- tokenId,
509
- quantity,
510
- from,
511
- addressToCall,
512
- functionToCall,
513
- valueToSend,
514
- deadline,
515
- nonce,
516
- }: {
517
- tokenId: bigint;
518
- quantity: bigint;
519
- chainId: keyof typeof zoraMints1155Config.address;
520
- // mints will be transferred from this address,
521
- // must match the callers address
522
- from: Address | Account;
523
- addressToCall: Address;
524
- functionToCall: Hex;
525
- valueToSend: bigint;
526
- deadline: bigint;
527
- nonce: bigint;
528
- }) => {
529
- // this is the call that the wrapper will call
530
- const callArgument = encodeFunctionData({
531
- abi: iUnwrapAndForwardActionABI,
532
- functionName: "callWithEth",
533
- args: [addressToCall, functionToCall, valueToSend],
534
- });
535
-
536
- return makePermitTransferTypeData({
537
- account: from,
538
- chainId,
539
- deadline,
540
- tokenId,
541
- quantity,
542
- safeTransferData: callArgument,
543
- to: mintsEthUnwrapperAndCallerConfig.address[chainId],
544
- nonce,
545
- });
546
- };
547
-
548
- export const safeTransferBatchAndUnwrapTypedDataDefinition = ({
549
- chainId,
550
- tokenIds,
551
- quantities,
552
- from,
553
- addressToCall,
554
- functionToCall,
555
- valueToSend,
556
- deadline,
557
- nonce,
558
- }: {
559
- tokenIds: bigint[];
560
- quantities: bigint[];
561
- chainId: keyof typeof zoraMints1155Config.address;
562
- // mints will be transferred from this address,
563
- // must match the callers address
564
- from: Address | Account;
565
- addressToCall: Address;
566
- functionToCall: Hex;
567
- valueToSend: bigint;
568
- deadline: bigint;
569
- nonce: bigint;
570
- }) => {
571
- // this is the call that the wrapper will call
572
- const callArgument = encodeFunctionData({
573
- abi: iUnwrapAndForwardActionABI,
574
- functionName: "callWithEth",
575
- args: [addressToCall, functionToCall, valueToSend],
576
- });
577
-
578
- return makePermitTransferBatchAndTypeData({
579
- account: from,
580
- chainId,
581
- deadline,
582
- tokenIds,
583
- quantities,
584
- safeTransferData: callArgument,
585
- to: mintsEthUnwrapperAndCallerConfig.address[chainId],
586
- nonce,
587
- });
588
- };
589
-
590
- export const safeTransferAndUnwrapEthParams = ({
591
- chainId,
592
- tokenIds,
593
- quantities,
594
- from,
595
- addressToCall,
596
- functionToCall,
597
- valueToSend,
598
- }: {
599
- tokenIds: bigint[];
600
- quantities: bigint[];
601
- chainId: keyof typeof zoraMints1155Config.address;
602
- // mints will be transferred from this address,
603
- // must match the callers address
604
- from: Address | Account;
605
- addressToCall: Address;
606
- functionToCall: Hex;
607
- valueToSend: bigint;
608
- }) => {
609
- // this is the encoded calldata for the eth unwrapper to
610
- // read and execute.
611
- // for valueToSend, whatever is remaining will be refunded
612
- // to the recipient.
613
- const callArgument = encodeFunctionData({
614
- abi: iUnwrapAndForwardActionABI,
615
- functionName: "callWithEth",
616
- args: [addressToCall, functionToCall, valueToSend],
617
- });
618
-
619
- const result: SimulateContractParameters<
620
- typeof zoraMints1155Config.abi,
621
- "safeBatchTransferFrom"
622
- > = {
623
- abi: zoraMints1155Config.abi,
624
- functionName: "safeBatchTransferFrom",
625
- address: zoraMints1155Config.address[chainId],
626
- args: [
627
- typeof from === "string" ? from : from.address,
628
- // the mints will be transferred to this address, which
629
- // will burn/redeem their eth value
630
- mintsEthUnwrapperAndCallerConfig.address[chainId],
631
- // token ids to transfer/burn/unwrap - must be eth based tokens
632
- tokenIds,
633
- // quantities to transfer/burn/unwrap
634
- quantities,
635
- // this is the safeTransferData - which gets forwarded to the eth transferrer
636
- callArgument,
637
- ],
638
- // the account whos mints will be transferred from
639
- account: from,
640
- };
641
-
642
- return result;
643
- };
644
-
559
+ /**
560
+ * Can be used to decode an a CallFailed error from the ZoraMints1155 contract when it has called a function on the ZoraMintsManager.
561
+ * @param error
562
+ * @returns
563
+ */
645
564
  export function decodeCallFailedError(error: ContractFunctionRevertedError) {
646
565
  if (error.data?.errorName !== "CallFailed")
647
566
  throw new Error("Not a CallFailed error");