'use strict';

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

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

/**
 * The tokenGate guard restricts minting to token holders
 * of a specified mint account. The `amount` determines
 * how many tokens are required.
 *
 * This object defines the settings that should be
 * provided when creating and/or updating a Candy
 * Machine if you wish to enable this guard.
 *
 * @see {@link TokenGateGuardMintSettings} for more
 * information on the mint settings of this guard.
 */

/** @internal */
const tokenGateGuardManifest = {
  name: 'tokenGate',
  settingsBytes: 40,
  settingsSerializer: Serializer.mapSerializer(Serializer.createSerializerFromBeet(mplCandyGuard.tokenGateBeet), settings => ({
    ...settings,
    amount: Amount.token(settings.amount)
  }), settings => ({
    ...settings,
    amount: settings.amount.basisPoints
  })),
  mintSettingsParser: ({
    metaplex,
    settings,
    mintSettings,
    payer,
    programs
  }) => {
    const tokenAccount = mintSettings?.tokenAccount ?? metaplex.tokens().pdas().associatedTokenAccount({
      mint: settings.mint,
      owner: payer.publicKey,
      programs
    });
    return {
      arguments: Buffer.from([]),
      remainingAccounts: [{
        isSigner: false,
        address: tokenAccount,
        isWritable: false
      }]
    };
  }
};

exports.tokenGateGuardManifest = tokenGateGuardManifest;
//# sourceMappingURL=tokenGate.cjs.map
