import { Buffer } from 'buffer';
import { tokenPaymentBeet } from '@metaplex-foundation/mpl-candy-guard';
import { mapSerializer, createSerializerFromBeet } from '../../../types/Serializer.mjs';
import { token } from '../../../types/Amount.mjs';

/**
 * 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: mapSerializer(createSerializerFromBeet(tokenPaymentBeet), settings => ({
    ...settings,
    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.from([]),
      remainingAccounts: [{
        isSigner: false,
        address: tokenAddress,
        isWritable: true
      }, {
        isSigner: false,
        address: settings.destinationAta,
        isWritable: true
      }]
    };
  }
};

export { tokenPaymentGuardManifest };
//# sourceMappingURL=tokenPayment.mjs.map
