var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { createWithdrawFromFeeInstruction, } from '@metaplex-foundation/mpl-auction-house';
import { useOperation, } from '../../../types';
import { TransactionBuilder } from '../../../utils';
// -----------------
// Operation
// -----------------
const Key = 'WithdrawFromFeeAccountOperation';
/**
 * Transfers funds from Auction House Fee Wallet to the Fee Withdrawal Destination Wallet.
 * By default Fee Withdrawal Destination Wallet is set to `metaplex.identity()`.
 *
 * ```ts
 * await metaplex
 *   .auctionHouse()
 *   .withdrawFromFeeAccount({ auctionHouse, amount };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const withdrawFromFeeAccountOperation = useOperation(Key);
/**
 * @group Operations
 * @category Handlers
 */
export const withdrawFromFeeAccountOperationHandler = {
    handle: (operation, metaplex, scope) => __awaiter(void 0, void 0, void 0, function* () {
        return withdrawFromFeeAccountBuilder(metaplex, operation.input, scope).sendAndConfirm(metaplex, scope.confirmOptions);
    }),
};
/**
 * Transfers funds from Auction House Fee Wallet to the Fee Withdrawal Destination Wallet.
 * By default Fee Withdrawal Destination Wallet is set to `metaplex.identity()`.
 *
 * ```ts
 * const transactionBuilder = metaplex
 *   .auctionHouse()
 *   .builders()
 *   .withdrawFromFeeAccount({ auctionHouse, amount });
 * ```
 *
 * @group Transaction Builders
 * @category Constructors
 */
export const withdrawFromFeeAccountBuilder = (metaplex, params, options = {}) => {
    // Data.
    const { payer = metaplex.rpc().getDefaultFeePayer() } = options;
    const { auctionHouse, amount, instructionKey, authority = metaplex.identity(), } = params;
    // Accounts.
    const accounts = {
        authority: auctionHouse.authorityAddress,
        feeWithdrawalDestination: auctionHouse.feeWithdrawalDestinationAddress,
        auctionHouse: auctionHouse.address,
        auctionHouseFeeAccount: auctionHouse.feeAccountAddress,
    };
    // Withdraw From Fee Instruction.
    const withdrawFromFeeInstruction = createWithdrawFromFeeInstruction(accounts, { amount: amount.basisPoints });
    // Signers.
    return (TransactionBuilder.make()
        .setFeePayer(payer)
        // Withdraw From Fee.
        .add({
        instruction: withdrawFromFeeInstruction,
        signers: [authority],
        key: instructionKey !== null && instructionKey !== void 0 ? instructionKey : 'withdrawFromFeeAccount',
    }));
};
//# sourceMappingURL=withdrawFromFeeAccount.js.map