import { BaseCoreSDK } from "./../mixins/base-core-sdk";
import { approve, getAllowance, getDecimals, getSymbol, getName, ensureAllowance, balanceOf, signReceiveWithErc3009Authorization, signReceiveWithErc2612Permit, signReceiveWithPermit2, signReceiveWithDaiPermit } from "./handler";
export class ERC20Mixin extends BaseCoreSDK {
    // Implementation
    async erc20Approve(args, overrides = {}) {
        const { returnTxInfo } = overrides;
        const approveArgs = {
            ...args,
            web3Lib: this._web3Lib,
            contractAddress: overrides.contractAddress,
            txRequest: overrides.txRequest
        };
        if (returnTxInfo === true) {
            return approve({
                ...approveArgs,
                returnTxInfo: true
            });
        }
        else {
            return approve({
                ...approveArgs,
                returnTxInfo: false
            });
        }
    }
    async erc20EnsureAllowance(args) {
        return ensureAllowance({ web3Lib: this._web3Lib, ...args });
    }
    async erc20GetAllowance(args) {
        return getAllowance({ web3Lib: this._web3Lib, ...args });
    }
    async erc20GetDecimals(args) {
        return getDecimals({ web3Lib: this._web3Lib, ...args });
    }
    async erc20GetSymbol(args) {
        return getSymbol({ web3Lib: this._web3Lib, ...args });
    }
    async erc20GetName(args) {
        return getName({ web3Lib: this._web3Lib, ...args });
    }
    async erc20BalanceOf(args) {
        return balanceOf({ web3Lib: this._web3Lib, ...args });
    }
    // Implementation
    async signReceiveWithErc3009Authorization(exchangeToken, tokenDomain, value, validAfter, validBefore, overrides = {}) {
        const user = await 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 signReceiveWithErc3009Authorization({
                ...baseArgs,
                returnTypedDataToSign: true
            });
        }
        return signReceiveWithErc3009Authorization({
            ...baseArgs,
            returnTypedDataToSign: false
        });
    }
    // Implementation
    async signReceiveWithErc2612Permit(exchangeToken, tokenDomain, value, deadline, overrides = {}) {
        const user = await 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 signReceiveWithErc2612Permit({
                ...baseArgs,
                returnTypedDataToSign: true
            });
        }
        return signReceiveWithErc2612Permit({
            ...baseArgs,
            returnTypedDataToSign: false
        });
    }
    // Implementation
    async signReceiveWithPermit2(exchangeToken, value, deadline, overrides = {}) {
        const user = await this._web3Lib.getSignerAddress();
        const permit2Address = overrides.permit2Address || this._contracts?.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 signReceiveWithPermit2({
                ...baseArgs,
                returnTypedDataToSign: true
            });
        }
        return signReceiveWithPermit2({
            ...baseArgs,
            returnTypedDataToSign: false
        });
    }
    // Implementation
    async signReceiveWithDaiPermit(exchangeToken, tokenDomain, value, expiry, overrides = {}) {
        const user = await 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 signReceiveWithDaiPermit({
                ...baseArgs,
                returnTypedDataToSign: true
            });
        }
        return signReceiveWithDaiPermit({
            ...baseArgs,
            returnTypedDataToSign: false
        });
    }
}
//# sourceMappingURL=mixin.js.map