"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.ERC20Mixin = void 0;
const base_core_sdk_1 = require("./../mixins/base-core-sdk");
const handler_1 = require("./handler");
class ERC20Mixin extends base_core_sdk_1.BaseCoreSDK {
    // Implementation
    erc20Approve(args_1) {
        return __awaiter(this, arguments, void 0, function* (args, overrides = {}) {
            const { returnTxInfo } = overrides;
            const approveArgs = Object.assign(Object.assign({}, args), { web3Lib: this._web3Lib, contractAddress: overrides.contractAddress, txRequest: overrides.txRequest });
            if (returnTxInfo === true) {
                return (0, handler_1.approve)(Object.assign(Object.assign({}, approveArgs), { returnTxInfo: true }));
            }
            else {
                return (0, handler_1.approve)(Object.assign(Object.assign({}, approveArgs), { returnTxInfo: false }));
            }
        });
    }
    erc20EnsureAllowance(args) {
        return __awaiter(this, void 0, void 0, function* () {
            return (0, handler_1.ensureAllowance)(Object.assign({ web3Lib: this._web3Lib }, args));
        });
    }
    erc20GetAllowance(args) {
        return __awaiter(this, void 0, void 0, function* () {
            return (0, handler_1.getAllowance)(Object.assign({ web3Lib: this._web3Lib }, args));
        });
    }
    erc20GetDecimals(args) {
        return __awaiter(this, void 0, void 0, function* () {
            return (0, handler_1.getDecimals)(Object.assign({ web3Lib: this._web3Lib }, args));
        });
    }
    erc20GetSymbol(args) {
        return __awaiter(this, void 0, void 0, function* () {
            return (0, handler_1.getSymbol)(Object.assign({ web3Lib: this._web3Lib }, args));
        });
    }
    erc20GetName(args) {
        return __awaiter(this, void 0, void 0, function* () {
            return (0, handler_1.getName)(Object.assign({ web3Lib: this._web3Lib }, args));
        });
    }
    erc20BalanceOf(args) {
        return __awaiter(this, void 0, void 0, function* () {
            return (0, handler_1.balanceOf)(Object.assign({ web3Lib: this._web3Lib }, args));
        });
    }
    // Implementation
    signReceiveWithErc3009Authorization(exchangeToken_1, tokenDomain_1, value_1, validAfter_1, validBefore_1) {
        return __awaiter(this, arguments, void 0, function* (exchangeToken, tokenDomain, value, validAfter, validBefore, overrides = {}) {
            const user = yield this._web3Lib.getSignerAddress();
            const baseArgs = {
                web3Lib: this._web3Lib,
                chainId: this._chainId,
                user,
                exchangeToken,
                spender: overrides.spender || this._protocolDiamond,
                value,
                tokenDomain,
                validAfter,
                validBefore
            };
            if (overrides.returnTypedDataToSign) {
                return (0, handler_1.signReceiveWithErc3009Authorization)(Object.assign(Object.assign({}, baseArgs), { returnTypedDataToSign: true }));
            }
            return (0, handler_1.signReceiveWithErc3009Authorization)(Object.assign(Object.assign({}, baseArgs), { returnTypedDataToSign: false }));
        });
    }
    // Implementation
    signReceiveWithErc2612Permit(exchangeToken_1, tokenDomain_1, value_1, deadline_1) {
        return __awaiter(this, arguments, void 0, function* (exchangeToken, tokenDomain, value, deadline, overrides = {}) {
            const user = yield this._web3Lib.getSignerAddress();
            const baseArgs = {
                web3Lib: this._web3Lib,
                chainId: this._chainId,
                user,
                exchangeToken,
                spender: overrides.spender || this._protocolDiamond,
                value,
                tokenDomain,
                deadline
            };
            if (overrides.returnTypedDataToSign) {
                return (0, handler_1.signReceiveWithErc2612Permit)(Object.assign(Object.assign({}, baseArgs), { returnTypedDataToSign: true }));
            }
            return (0, handler_1.signReceiveWithErc2612Permit)(Object.assign(Object.assign({}, baseArgs), { returnTypedDataToSign: false }));
        });
    }
    // Implementation
    signReceiveWithPermit2(exchangeToken_1, value_1, deadline_1) {
        return __awaiter(this, arguments, void 0, function* (exchangeToken, value, deadline, overrides = {}) {
            var _a;
            const user = yield this._web3Lib.getSignerAddress();
            const permit2Address = overrides.permit2Address || ((_a = this._contracts) === null || _a === void 0 ? void 0 : _a.permit2);
            if (!permit2Address) {
                throw new Error("Permit2 contract address not configured. Provide overrides.permit2Address or initialize CoreSDK with contracts.permit2.");
            }
            const baseArgs = {
                web3Lib: this._web3Lib,
                chainId: this._chainId,
                user,
                exchangeToken,
                spender: overrides.spender || this._protocolDiamond,
                value,
                permit2Address,
                deadline,
                permit2Nonce: overrides.permit2Nonce
            };
            if (overrides.returnTypedDataToSign) {
                return (0, handler_1.signReceiveWithPermit2)(Object.assign(Object.assign({}, baseArgs), { returnTypedDataToSign: true }));
            }
            return (0, handler_1.signReceiveWithPermit2)(Object.assign(Object.assign({}, baseArgs), { returnTypedDataToSign: false }));
        });
    }
    // Implementation
    signReceiveWithDaiPermit(exchangeToken_1, tokenDomain_1, value_1, expiry_1) {
        return __awaiter(this, arguments, void 0, function* (exchangeToken, tokenDomain, value, expiry, overrides = {}) {
            const user = yield this._web3Lib.getSignerAddress();
            const baseArgs = {
                web3Lib: this._web3Lib,
                chainId: this._chainId,
                user,
                exchangeToken,
                spender: overrides.spender || this._protocolDiamond,
                value,
                tokenDomain,
                expiry
            };
            if (overrides.returnTypedDataToSign) {
                return (0, handler_1.signReceiveWithDaiPermit)(Object.assign(Object.assign({}, baseArgs), { returnTypedDataToSign: true }));
            }
            return (0, handler_1.signReceiveWithDaiPermit)(Object.assign(Object.assign({}, baseArgs), { returnTypedDataToSign: false }));
        });
    }
}
exports.ERC20Mixin = ERC20Mixin;
//# sourceMappingURL=mixin.js.map