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 PublicFeePaymentMethod {
    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) {
        this.asset = asset;
        this.paymentContract = paymentContract;
        this.wallet = wallet;
    }
    /**
     * 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.
     */
    getFunctionCalls(gasSettings) {
        const nonce = Fr.random();
        const maxFee = gasSettings.getFeeLimit();
        return Promise.resolve([
            this.wallet
                .setPublicAuthWit({
                caller: this.paymentContract,
                action: {
                    name: 'transfer_in_public',
                    args: [this.wallet.getAddress().toField(), this.paymentContract.toField(), maxFee, nonce],
                    selector: FunctionSelector.fromSignature('transfer_in_public((Field),(Field),Field,Field)'),
                    type: FunctionType.PUBLIC,
                    isStatic: false,
                    to: this.asset,
                    returnTypes: [],
                },
            }, true)
                .request(),
            {
                name: 'fee_entrypoint_public',
                to: this.paymentContract,
                selector: FunctionSelector.fromSignature('fee_entrypoint_public(Field,(Field),Field)'),
                type: FunctionType.PRIVATE,
                isStatic: false,
                args: [maxFee, this.asset.toField(), nonce],
                returnTypes: [],
            },
        ]);
    }
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljX2ZlZV9wYXltZW50X21ldGhvZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9mZWUvcHVibGljX2ZlZV9wYXltZW50X21ldGhvZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsZ0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