'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var buffer = require('buffer');
var mplCandyGuard = require('@metaplex-foundation/mpl-candy-guard');
var Serializer = require('../../../types/Serializer.cjs');
var Amount = require('../../../types/Amount.cjs');

/**
 * The tokenPayment guard allows minting by charging the
 * payer a specific amount of tokens from a certain mint acount.
 * The tokens will be transfered to a predefined destination.
 *
 * This guard alone does not limit how many times a holder
 * can mint. A holder can mint as many times as they have
 * the required amount of tokens to pay with.
 *
 * This object defines the settings that should be
 * provided when creating and/or updating a Candy
 * Machine if you wish to enable this guard.
 */

/** @internal */
const tokenPaymentGuardManifest = {
  name: 'tokenPayment',
  settingsBytes: 72,
  settingsSerializer: Serializer.mapSerializer(Serializer.createSerializerFromBeet(mplCandyGuard.tokenPaymentBeet), settings => ({
    ...settings,
    amount: Amount.token(settings.amount)
  }), settings => ({
    ...settings,
    amount: settings.amount.basisPoints
  })),
  mintSettingsParser: ({
    metaplex,
    settings,
    payer,
    programs
  }) => {
    const tokenAddress = metaplex.tokens().pdas().associatedTokenAccount({
      mint: settings.tokenMint,
      owner: payer.publicKey,
      programs
    });
    return {
      arguments: buffer.Buffer.from([]),
      remainingAccounts: [{
        isSigner: false,
        address: tokenAddress,
        isWritable: true
      }, {
        isSigner: false,
        address: settings.destinationAta,
        isWritable: true
      }]
    };
  }
};

exports.tokenPaymentGuardManifest = tokenPaymentGuardManifest;
//# sourceMappingURL=tokenPayment.cjs.map
