@@ -19,20 +19,23 @@ import Web3Modal, { IProviderOptions } from 'web3modal'
1919import { API_ENDPOINT , API_ENDPOINT_DEV } from './config/endpoint'
2020import { NETWORKS , ZERO_ADDRESS } from './config/networks'
2121import { PROVIDER_OPTIONS } from './config/providers'
22- import DropKitCollectionABI from './contracts/DropKitCollection.json'
2322import DropKitCollectionV2ABI from './contracts/DropKitCollectionV2.json'
2423import DropKitCollectionV3ABI from './contracts/DropKitCollectionV3.json'
24+ import DropKitCollectionV4ABI from './contracts/DropKitCollectionV4.json'
25+ import DropKitCollectionV5ABI from './contracts/DropKitCollectionV5.json'
2526import { handleError } from './errors/utils'
2627import {
2728 DropApiResponse ,
2829 ErrorApiResponse ,
2930 ProofApiResponse ,
31+ ProofApiResponseV2 ,
3032} from './types/api-responses'
3133
3234const abis : Record < number , any > = {
33- 2 : DropKitCollectionABI . abi ,
34- 3 : DropKitCollectionV2ABI . abi ,
35- 4 : DropKitCollectionV3ABI . abi ,
35+ 2 : DropKitCollectionV2ABI ,
36+ 3 : DropKitCollectionV3ABI ,
37+ 4 : DropKitCollectionV4ABI ,
38+ 5 : DropKitCollectionV5ABI ,
3639}
3740
3841export default class DropKit {
@@ -82,7 +85,7 @@ export default class DropKit {
8285 this . networkName = data . networkName
8386 this . chainId = data . chainId
8487 this . maxSupply = data . version <= 3 ? data . maxAmount : 0
85- const abi = abis [ data . version || 1 ]
88+ const abi = abis [ data . version || 2 ]
8689
8790 let signerOrProvider : Signer | Provider
8891 if ( provider ) {
@@ -227,7 +230,7 @@ export default class DropKit {
227230 return false
228231 }
229232
230- // Unfortunately, the presaleActive() method is not available in the v2 contracts
233+ // Unfortunately, the presaleActive() method is not available in the v3 contracts
231234 // So we need to assume that the presale is active and check with generateProof()
232235 if ( this . version === 3 ) {
233236 return ! ( await this . saleActive ( ) )
@@ -250,6 +253,20 @@ export default class DropKit {
250253 return data
251254 }
252255
256+ async generateProofV2 ( ) : Promise < ProofApiResponseV2 & ErrorApiResponse > {
257+ const { data } = await axios . post < ProofApiResponseV2 & ErrorApiResponse > (
258+ `${ this . apiBaseUrl } /v2/drops/list/${ this . collectionId } ` ,
259+ {
260+ wallet : this . walletAddress ,
261+ } ,
262+ {
263+ validateStatus : ( status ) => status < 500 ,
264+ }
265+ )
266+
267+ return data
268+ }
269+
253270 async mint ( quantity : number ) : Promise < ContractReceipt | null > {
254271 try {
255272 // safety check
@@ -276,9 +293,11 @@ export default class DropKit {
276293
277294 // Presale minting
278295 if ( presaleActive ) {
279- // Backwards compatibility with v2 contracts:
296+ // Backwards compatibility with v3 contracts:
280297 // If the public sale is not active, we can still try mint with the presale
281- return await this . _presaleMint ( quantity , amount )
298+ return this . version <= 4
299+ ? await this . _presaleMint ( quantity , amount )
300+ : await this . _presaleMintV2 ( quantity , amount )
282301 }
283302
284303 // Regular minting
@@ -336,17 +355,38 @@ export default class DropKit {
336355 ) : Promise < ContractReceipt > {
337356 const data = await this . generateProof ( )
338357 if ( data . message ) {
339- // Backwards compatibility for v2 contracts
358+ // Backwards compatibility for v3 contracts
340359 if ( this . version === 3 ) {
341360 throw new Error (
342361 'Collection is not active or your wallet is not part of presale.'
343362 )
344363 }
345- throw new Error ( 'Your wallet is not part of presale.' )
364+ throw new Error ( data . message )
365+ }
366+
367+ const trx : ContractTransaction = await this . contract . presaleMint (
368+ quantity ,
369+ data . proof ,
370+ {
371+ value : amount ,
372+ }
373+ )
374+
375+ return trx . wait ( )
376+ }
377+
378+ private async _presaleMintV2 (
379+ quantity : number ,
380+ amount : BigNumber
381+ ) : Promise < ContractReceipt > {
382+ const data = await this . generateProofV2 ( )
383+ if ( data . message ) {
384+ throw new Error ( data . message )
346385 }
347386
348387 const trx : ContractTransaction = await this . contract . presaleMint (
349388 quantity ,
389+ data . allowed ,
350390 data . proof ,
351391 {
352392 value : amount ,
0 commit comments