import { FunctionSelector, FunctionType } from '@aztec/foundation/abi';
import { Fr } from '@aztec/foundation/fields';
/**
 * Holds information about how the fee for a transaction is to be paid.
 */
export class PrivateFeePaymentMethod {
    constructor(
    /**
     * The asset used to pay the fee.
     */
    asset, 
    /**
     * Address which will hold the fee payment.
     */
    paymentContract, 
    /**
     * An auth witness provider to authorize fee payments
     */
    wallet, 
    /**
     * Address that the FPC sends notes it receives to.
     */
    feeRecipient, 
    /**
     * If true, the max fee will be set to 1.
     * TODO(#7694): Remove this param once the lacking feature in TXE is implemented.
     */
    setMaxFeeToOne = false) {
        this.asset = asset;
        this.paymentContract = paymentContract;
        this.wallet = wallet;
        this.feeRecipient = feeRecipient;
        this.setMaxFeeToOne = setMaxFeeToOne;
    }
    /**
     * The asset used to pay the fee.
     * @returns The asset used to pay the fee.
     */
    getAsset() {
        return this.asset;
    }
    getFeePayer() {
        return Promise.resolve(this.paymentContract);
    }
    /**
     * Creates a function call to pay the fee in the given asset.
     * @param gasSettings - The gas settings.
     * @returns The function call to pay the fee.
     */
    async getFunctionCalls(gasSettings) {
        // We assume 1:1 exchange rate between fee juice and token. But in reality you would need to convert feeLimit
        // (maxFee) to be in token denomination.
        const maxFee = this.setMaxFeeToOne ? Fr.ONE : gasSettings.getFeeLimit();
        const nonce = Fr.random();
        await this.wallet.createAuthWit({
            caller: this.paymentContract,
            action: {
                name: 'setup_refund',
                args: [this.feeRecipient.toField(), this.wallet.getAddress().toField(), maxFee, nonce],
                selector: FunctionSelector.fromSignature('setup_refund((Field),(Field),Field,Field)'),
                type: FunctionType.PRIVATE,
                isStatic: false,
                to: this.asset,
                returnTypes: [],
            },
        });
        return [
            {
                name: 'fee_entrypoint_private',
                to: this.paymentContract,
                selector: FunctionSelector.fromSignature('fee_entrypoint_private(Field,(Field),Field)'),
                type: FunctionType.PRIVATE,
                isStatic: false,
                args: [maxFee, this.asset.toField(), nonce],
                returnTypes: [],
            },
        ];
    }
}
//# sourceMappingURL=data:application/json;base64,eyJ2Z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