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 { createRevokeInstruction } from '@solarti/spl-token';
import { isSigner, useOperation, } from '../../../types';
import { TransactionBuilder } from '../../../utils';
// -----------------
// Operation
// -----------------
const Key = 'RevokeTokenDelegateAuthorityOperation';
/**
 * Revokes the current delegate authority for a token account.
 *
 * ```ts
 * await metaplex
 *   .tokens()
 *   .revokeDelegateAuthority({ mintAddress };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const revokeTokenDelegateAuthorityOperation = useOperation(Key);
/**
 * @group Operations
 * @category Handlers
 */
export const revokeTokenDelegateAuthorityOperationHandler = {
    handle: (operation, metaplex, scope) => __awaiter(void 0, void 0, void 0, function* () {
        return revokeTokenDelegateAuthorityBuilder(metaplex, operation.input, scope).sendAndConfirm(metaplex, scope.confirmOptions);
    }),
};
/**
 * Revokes the current delegate authority for a token account.
 *
 * ```ts
 * await metaplex
 *   .tokens()
 *   .builders()
 *   .revokeDelegateAuthority({ mintAddress });
 * ```
 *
 * @group Transaction Builders
 * @category Constructors
 */
export const revokeTokenDelegateAuthorityBuilder = (metaplex, params, options = {}) => {
    var _a;
    const { programs, payer = metaplex.rpc().getDefaultFeePayer() } = options;
    const { mintAddress, owner = metaplex.identity(), tokenAddress, multiSigners = [], } = params;
    const [ownerPublicKey, signers] = isSigner(owner)
        ? [owner.publicKey, [owner]]
        : [owner, multiSigners];
    const tokenProgram = metaplex.programs().getToken(programs);
    const tokenAccount = tokenAddress !== null && tokenAddress !== void 0 ? tokenAddress : metaplex.tokens().pdas().associatedTokenAccount({
        mint: mintAddress,
        owner: ownerPublicKey,
        programs,
    });
    return TransactionBuilder.make()
        .setFeePayer(payer)
        .add({
        instruction: createRevokeInstruction(tokenAccount, ownerPublicKey, multiSigners, tokenProgram.address),
        signers,
        key: (_a = params.instructionKey) !== null && _a !== void 0 ? _a : 'revokeDelegateAuthority',
    });
};
//# sourceMappingURL=revokeTokenDelegateAuthority.js.map