@@ -83,8 +83,10 @@ export class Erc1155SignatureMintable implements DetectableFeature {
83
83
) : Promise < Transaction < TransactionResultWithId > > => {
84
84
const mintRequest = signedPayload . payload ;
85
85
const signature = signedPayload . signature ;
86
- const message = await this . mapPayloadToContractStruct ( mintRequest ) ;
87
- const overrides = await this . contractWrapper . getCallOverrides ( ) ;
86
+ const [ message , overrides ] = await Promise . all ( [
87
+ this . mapPayloadToContractStruct ( mintRequest ) ,
88
+ this . contractWrapper . getCallOverrides ( ) ,
89
+ ] ) ;
88
90
// TODO: Transaction Sequence Pattern
89
91
await setErc20Allowance (
90
92
this . contractWrapper ,
@@ -136,22 +138,23 @@ export class Erc1155SignatureMintable implements DetectableFeature {
136
138
async (
137
139
signedPayloads : SignedPayload1155 [ ] ,
138
140
) : Promise < Transaction < TransactionResultWithId [ ] > > => {
139
- const contractPayloads = await Promise . all (
140
- signedPayloads . map ( async ( s ) => {
141
- const message = await this . mapPayloadToContractStruct ( s . payload ) ;
142
- const signature = s . signature ;
143
- const price = s . payload . price ;
144
- if ( BigNumber . from ( price ) . gt ( 0 ) ) {
145
- throw new Error (
146
- "Can only batch free mints. For mints with a price, use regular mint()" ,
147
- ) ;
148
- }
149
- return {
150
- message,
151
- signature,
152
- } ;
153
- } ) ,
141
+ const contractStructs = await Promise . all (
142
+ signedPayloads . map ( ( s ) => this . mapPayloadToContractStruct ( s . payload ) ) ,
154
143
) ;
144
+ const contractPayloads = signedPayloads . map ( ( s , index ) => {
145
+ const message = contractStructs [ index ] ;
146
+ const signature = s . signature ;
147
+ const price = s . payload . price ;
148
+ if ( BigNumber . from ( price ) . gt ( 0 ) ) {
149
+ throw new Error (
150
+ "Can only batch free mints. For mints with a price, use regular mint()" ,
151
+ ) ;
152
+ }
153
+ return {
154
+ message,
155
+ signature,
156
+ } ;
157
+ } ) ;
155
158
const contractEncoder = new ContractEncoder ( this . contractWrapper ) ;
156
159
const encoded = contractPayloads . map ( ( p ) => {
157
160
return contractEncoder . encode ( "mintWithSignature" , [
@@ -276,7 +279,7 @@ export class Erc1155SignatureMintable implements DetectableFeature {
276
279
}
277
280
278
281
/**
279
- * Generate a signature that can be used to mint additionaly supply to an existing NFT.
282
+ * Generate a signature that can be used to mint additionally supply to an existing NFT.
280
283
*
281
284
* @remarks Takes in a payload with the token ID of an existing NFT, and signs it with your private key. The generated signature can then be used to mint additional supply to the NFT using the exact payload and signature generated.
282
285
*
@@ -291,7 +294,7 @@ export class Erc1155SignatureMintable implements DetectableFeature {
291
294
* const startTime = new Date();
292
295
* const endTime = new Date(Date.now() + 60 * 60 * 24 * 1000);
293
296
* const payload = {
294
- * tokenId: 0, // Instead of metadata, we specificy the token ID of the NFT to mint supply to
297
+ * tokenId: 0, // Instead of metadata, we specify the token ID of the NFT to mint supply to
295
298
* to: {{wallet_address}}, // Who will receive the NFT (or AddressZero for anyone)
296
299
* quantity: 2, // the quantity of NFTs to mint
297
300
* price: 0.5, // the price per NFT
@@ -337,7 +340,7 @@ export class Erc1155SignatureMintable implements DetectableFeature {
337
340
}
338
341
339
342
/**
340
- * Genrate a batch of signatures that can be used to mint new NFTs or additionaly supply to existing NFTs dynamically.
343
+ * Generate a batch of signatures that can be used to mint new NFTs or additionally supply to existing NFTs dynamically.
341
344
*
342
345
* @remarks See {@link Erc1155SignatureMintable.generateFromTokenId}
343
346
*
@@ -348,10 +351,10 @@ export class Erc1155SignatureMintable implements DetectableFeature {
348
351
public async generateBatchFromTokenIds (
349
352
payloadsToSign : PayloadToSign1155WithTokenId [ ] ,
350
353
) : Promise < SignedPayload1155 [ ] > {
351
- await this . roles ?. verify (
352
- [ "minter" ] ,
353
- await this . contractWrapper . getSignerAddress ( ) ,
354
- ) ;
354
+ const signer = this . contractWrapper . getSigner ( ) ;
355
+ invariant ( signer , "No signer available" ) ;
356
+
357
+ await this . roles ?. verify ( [ "minter" ] , await signer . getAddress ( ) ) ;
355
358
356
359
const parsedRequests : FilledSignaturePayload1155WithTokenId [ ] =
357
360
await Promise . all (
@@ -361,26 +364,34 @@ export class Erc1155SignatureMintable implements DetectableFeature {
361
364
) ;
362
365
363
366
const metadatas = parsedRequests . map ( ( r ) => r . metadata ) ;
364
- const uris = await uploadOrExtractURIs ( metadatas , this . storage ) ;
365
367
366
- const chainId = await this . contractWrapper . getChainID ( ) ;
367
- const signer = this . contractWrapper . getSigner ( ) ;
368
- invariant ( signer , "No signer available" ) ;
368
+ const [ uris , chainId , contractInfo ] = await Promise . all ( [
369
+ uploadOrExtractURIs ( metadatas , this . storage ) ,
370
+ this . contractWrapper . getChainID ( ) ,
371
+ getPrebuiltInfo (
372
+ this . contractWrapper . address ,
373
+ this . contractWrapper . getProvider ( ) ,
374
+ ) ,
375
+ ] ) ;
369
376
370
- const contractInfo = await getPrebuiltInfo (
371
- this . contractWrapper . address ,
372
- this . contractWrapper . getProvider ( ) ,
377
+ const finalPayloads = await Promise . all (
378
+ parsedRequests . map ( ( m , i ) =>
379
+ Signature1155PayloadOutput . parseAsync ( {
380
+ ...m ,
381
+ uri : uris [ i ] ,
382
+ } ) ,
383
+ ) ,
384
+ ) ;
385
+ const contractStructs = await Promise . all (
386
+ finalPayloads . map ( ( finalPayload ) =>
387
+ this . mapPayloadToContractStruct ( finalPayload ) ,
388
+ ) ,
373
389
) ;
374
- const isLegacyContract = contractInfo ?. type === "TokenERC1155" ;
375
390
376
- return await Promise . all (
377
- parsedRequests . map ( async ( m , i ) => {
378
- const uri = uris [ i ] ;
379
- const finalPayload = await Signature1155PayloadOutput . parseAsync ( {
380
- ...m ,
381
- uri,
382
- } ) ;
383
- const signature = await this . contractWrapper . signTypedData (
391
+ const isLegacyContract = contractInfo ?. type === "TokenERC1155" ;
392
+ const signatures = await Promise . all (
393
+ contractStructs . map ( ( contractStruct ) =>
394
+ this . contractWrapper . signTypedData (
384
395
signer ,
385
396
{
386
397
name : isLegacyContract ? "TokenERC1155" : "SignatureMintERC1155" ,
@@ -389,14 +400,14 @@ export class Erc1155SignatureMintable implements DetectableFeature {
389
400
verifyingContract : this . contractWrapper . address ,
390
401
} ,
391
402
{ MintRequest : MintRequest1155 } , // TYPEHASH
392
- await this . mapPayloadToContractStruct ( finalPayload ) ,
393
- ) ;
394
- return {
395
- payload : finalPayload ,
396
- signature : signature . toString ( ) ,
397
- } ;
398
- } ) ,
403
+ contractStruct ,
404
+ ) ,
405
+ ) ,
399
406
) ;
407
+ return signatures . map ( ( signature , index ) => ( {
408
+ payload : finalPayloads [ index ] ,
409
+ signature : signature . toString ( ) ,
410
+ } ) ) ;
400
411
}
401
412
402
413
/** ******************************
0 commit comments