"use strict";
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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NativeMetaTxMixin = void 0;
const _1 = require(".");
const base_core_sdk_1 = require("./../mixins/base-core-sdk");
class NativeMetaTxMixin extends base_core_sdk_1.BaseCoreSDK {
    // Implementation
    signNativeMetaTxApproveExchangeToken(exchangeToken_1, value_1) {
        return __awaiter(this, arguments, void 0, function* (exchangeToken, value, overrides = {}) {
            const user = yield this._web3Lib.getSignerAddress();
            const baseArgs = {
                web3Lib: this._web3Lib,
                chainId: this._chainId,
                user,
                exchangeToken,
                spender: overrides.spender || this._protocolDiamond,
                value
            };
            if (overrides.returnTypedDataToSign) {
                return _1.handler.signNativeMetaTxApproveExchangeToken(Object.assign(Object.assign({}, baseArgs), { returnTypedDataToSign: true }));
            }
            return _1.handler.signNativeMetaTxApproveExchangeToken(Object.assign(Object.assign({}, baseArgs), { returnTypedDataToSign: false }));
        });
    }
    /**
     * Relay a native meta transaction,
     * @param metaTxParams - Required params for meta transaction.
     * @param overrides - Optional overrides.
     * @returns Transaction response.
     */
    relayNativeMetaTransaction(contractAddress_1, metaTxParams_1) {
        return __awaiter(this, arguments, void 0, function* (contractAddress, metaTxParams, overrides = {}) {
            const { metaTxApiId, metaTxApiKey, metaTxRelayerUrl } = this.assertAndGetMetaTxConfig(Object.assign(Object.assign({}, overrides), { contractAddress }));
            return _1.handler.relayNativeMetaTransaction({
                web3LibAdapter: this._web3Lib,
                contractAddress,
                chainId: this._chainId,
                metaTx: {
                    config: {
                        relayerUrl: metaTxRelayerUrl,
                        apiId: metaTxApiId,
                        apiKey: metaTxApiKey
                    },
                    params: {
                        userAddress: overrides.userAddress || (yield this._web3Lib.getSignerAddress()),
                        functionSignature: metaTxParams.functionSignature,
                        sigR: metaTxParams.sigR,
                        sigS: metaTxParams.sigS,
                        sigV: metaTxParams.sigV
                    }
                }
            });
        });
    }
    /**
     * Execute a signed native meta transaction directly on-chain (no Biconomy relayer).
     * The wallet backing the SDK pays the gas; pass `overrides.userAddress` when the
     * meta-tx signer differs from that wallet.
     * @param contractAddress - The token contract address.
     * @param metaTxParams - Required params for the native meta transaction.
     * @param overrides - Optional overrides.
     * @returns Transaction response.
     */
    executeNativeMetaTransaction(contractAddress_1, metaTxParams_1) {
        return __awaiter(this, arguments, void 0, function* (contractAddress, metaTxParams, overrides = {}) {
            const userAddress = overrides.userAddress || (yield this._web3Lib.getSignerAddress());
            return _1.handler.executeNativeMetaTransaction({
                web3Lib: this._web3Lib,
                contractAddress,
                userAddress,
                functionSignature: metaTxParams.functionSignature,
                sigR: metaTxParams.sigR,
                sigS: metaTxParams.sigS,
                sigV: metaTxParams.sigV
            });
        });
    }
}
exports.NativeMetaTxMixin = NativeMetaTxMixin;
//# sourceMappingURL=mixin.js.map