@@ -63,8 +63,10 @@ export class Erc20SignatureMintable implements DetectableFeature {
6363 async ( signedPayload : SignedPayload20 ) => {
6464 const mintRequest = signedPayload . payload ;
6565 const signature = signedPayload . signature ;
66- const message = await this . mapPayloadToContractStruct ( mintRequest ) ;
67- const overrides = await this . contractWrapper . getCallOverrides ( ) ;
66+ const [ message , overrides ] = await Promise . all ( [
67+ this . mapPayloadToContractStruct ( mintRequest ) ,
68+ this . contractWrapper . getCallOverrides ( ) ,
69+ ] ) ;
6870 // TODO: Transaction Sequence Pattern
6971 await setErc20Allowance (
7072 this . contractWrapper ,
@@ -89,22 +91,23 @@ export class Erc20SignatureMintable implements DetectableFeature {
8991 */
9092 mintBatch = /* @__PURE__ */ buildTransactionFunction (
9193 async ( signedPayloads : SignedPayload20 [ ] ) => {
92- const contractPayloads = await Promise . all (
93- signedPayloads . map ( async ( s ) => {
94- const message = await this . mapPayloadToContractStruct ( s . payload ) ;
95- const signature = s . signature ;
96- const price = s . payload . price ;
97- if ( BigNumber . from ( price ) . gt ( 0 ) ) {
98- throw new Error (
99- "Can only batch free mints. For mints with a price, use regular mint()" ,
100- ) ;
101- }
102- return {
103- message,
104- signature,
105- } ;
106- } ) ,
94+ const messages = await Promise . all (
95+ signedPayloads . map ( ( s ) => this . mapPayloadToContractStruct ( s . payload ) ) ,
10796 ) ;
97+ const contractPayloads = signedPayloads . map ( ( s , index ) => {
98+ const message = messages [ index ] ;
99+ const signature = s . signature ;
100+ const price = s . payload . price ;
101+ if ( BigNumber . from ( price ) . gt ( 0 ) ) {
102+ throw new Error (
103+ "Can only batch free mints. For mints with a price, use regular mint()" ,
104+ ) ;
105+ }
106+ return {
107+ message,
108+ signature,
109+ } ;
110+ } ) ;
108111
109112 const contractEncoder = new ContractEncoder ( this . contractWrapper ) ;
110113 const encoded = contractPayloads . map ( ( p ) => {
@@ -204,21 +207,30 @@ export class Erc20SignatureMintable implements DetectableFeature {
204207 await this . contractWrapper . getSignerAddress ( ) ,
205208 ) ;
206209
207- const parsedRequests : FilledSignaturePayload20 [ ] = await Promise . all (
208- payloadsToSign . map ( ( m ) => Signature20PayloadInput . parseAsync ( m ) ) ,
209- ) ;
210+ const [ chainId , name , parsedRequests ] : [
211+ number ,
212+ string ,
213+ FilledSignaturePayload20 [ ] ,
214+ ] = await Promise . all ( [
215+ this . contractWrapper . getChainID ( ) ,
216+ this . contractWrapper . read ( "name" , [ ] ) , // ERC20Permit (EIP-712) spec differs from signature mint 721, 1155.
217+ Promise . all (
218+ payloadsToSign . map ( ( m ) => Signature20PayloadInput . parseAsync ( m ) ) ,
219+ ) ,
220+ ] ) ;
210221
211- const chainId = await this . contractWrapper . getChainID ( ) ;
212222 const signer = this . contractWrapper . getSigner ( ) ;
213223 invariant ( signer , "No signer available" ) ;
214224
215- // ERC20Permit (EIP-712) spec differs from signature mint 721, 1155.
216- const name = await this . contractWrapper . read ( "name" , [ ] ) ;
217-
218- return await Promise . all (
219- parsedRequests . map ( async ( m ) => {
220- const finalPayload = await Signature20PayloadOutput . parseAsync ( m ) ;
221- const signature = await this . contractWrapper . signTypedData (
225+ const finalPayloads = await Promise . all (
226+ parsedRequests . map ( ( m ) => Signature20PayloadOutput . parseAsync ( m ) ) ,
227+ ) ;
228+ const contractStructs = await Promise . all (
229+ finalPayloads . map ( ( payload ) => this . mapPayloadToContractStruct ( payload ) ) ,
230+ ) ;
231+ const signatures = await Promise . all (
232+ contractStructs . map ( ( struct ) =>
233+ this . contractWrapper . signTypedData (
222234 signer ,
223235 {
224236 name,
@@ -227,14 +239,18 @@ export class Erc20SignatureMintable implements DetectableFeature {
227239 verifyingContract : this . contractWrapper . address ,
228240 } ,
229241 { MintRequest : MintRequest20 } ,
230- await this . mapPayloadToContractStruct ( finalPayload ) ,
231- ) ;
232- return {
233- payload : finalPayload ,
234- signature : signature . toString ( ) ,
235- } ;
236- } ) ,
242+ struct ,
243+ ) ,
244+ ) ,
237245 ) ;
246+ return parsedRequests . map ( ( m , index ) => {
247+ const finalPayload = finalPayloads [ index ] ;
248+ const signature = signatures [ index ] ;
249+ return {
250+ payload : finalPayload ,
251+ signature : signature . toString ( ) ,
252+ } ;
253+ } ) ;
238254 }
239255
240256 /** ******************************
@@ -251,15 +267,15 @@ export class Erc20SignatureMintable implements DetectableFeature {
251267 private async mapPayloadToContractStruct (
252268 mintRequest : PayloadWithUri20 ,
253269 ) : Promise < ITokenERC20 . MintRequestStructOutput > {
254- const normalizedPrice = await normalizePriceValue (
255- this . contractWrapper . getProvider ( ) ,
256- mintRequest . price ,
257- mintRequest . currencyAddress ,
258- ) ;
259- const amountWithDecimals = utils . parseUnits (
260- mintRequest . quantity ,
261- await this . contractWrapper . read ( "decimals" , [ ] ) ,
262- ) ;
270+ const [ normalizedPrice , decimals ] = await Promise . all ( [
271+ normalizePriceValue (
272+ this . contractWrapper . getProvider ( ) ,
273+ mintRequest . price ,
274+ mintRequest . currencyAddress ,
275+ ) ,
276+ this . contractWrapper . read ( "decimals" , [ ] ) ,
277+ ] ) ;
278+ const amountWithDecimals = utils . parseUnits ( mintRequest . quantity , decimals ) ;
263279 return {
264280 to : mintRequest . to ,
265281 primarySaleRecipient : mintRequest . primarySaleRecipient ,
0 commit comments