import { Biconomy } from "../meta-tx/biconomy";
export class BaseCoreSDK {
    _web3Lib;
    _metadataStorage;
    _theGraphStorage;
    _subgraphUrl;
    _protocolDiamond;
    _chainId;
    _tokenInfoManager;
    _errorsMap = new Map();
    _metaTxConfig;
    _lens;
    _contracts;
    _uuid;
    _getTxExplorerUrl;
    /**
     * Creates an instance of `BaseCoreSDK`
     * @param args - Constructor args
     */
    constructor(opts) {
        this._web3Lib = opts.web3Lib;
        this._subgraphUrl = opts.subgraphUrl;
        this._protocolDiamond = opts.protocolDiamond;
        this._metadataStorage = opts.metadataStorage;
        this._theGraphStorage = opts.theGraphStorage;
        this._chainId = opts.chainId;
        this._metaTxConfig = opts.metaTx;
        this._lens = opts.lens;
        this._contracts = opts.contracts;
        this._uuid = crypto.randomUUID();
        this._getTxExplorerUrl = opts.getTxExplorerUrl;
    }
    assertAndGetMetaTxConfig(overrides = {}) {
        const contractAddress = overrides.contractAddress || this._protocolDiamond;
        const metaTransactionMethod = overrides.metaTransactionMethod || "executeMetaTransaction";
        const metaTxRelayerUrl = overrides.metaTxConfig?.relayerUrl || this._metaTxConfig?.relayerUrl;
        const metaTxApiKey = overrides.metaTxConfig?.apiKey || this._metaTxConfig?.apiKey;
        // metaTxApiId is depending on the contract/method(=executeMetaTransaction) to be called with Biconomy
        const apiIds = this._metaTxConfig?.apiIds[contractAddress.toLowerCase()];
        const metaTxApiId = overrides.metaTxConfig?.apiId ||
            (apiIds && apiIds[metaTransactionMethod]);
        if (!(metaTxRelayerUrl && metaTxApiKey && metaTxApiId)) {
            throw new Error("CoreSDK not configured to relay meta transactions. Either pass in 'relayerUrl', 'apiKey' and 'apiId' during initialization OR as overrides arguments.");
        }
        return {
            metaTxRelayerUrl,
            metaTxApiId,
            metaTxApiKey,
            contractAddress
        };
    }
    async assertAndGetMetaTxConfig2(overrides = {}) {
        const ret = this.assertAndGetMetaTxConfig(overrides);
        // Check the meta-tx gateway is ready and accepts relaying transaction to the targeted contract
        const biconomy = new Biconomy(ret.metaTxRelayerUrl, ret.metaTxApiKey, ret.metaTxApiId);
        const ready = await biconomy.check({
            contract: ret.contractAddress
        });
        return ready ? ret : undefined;
    }
}
// Doc: https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern
export function applyMixins(derivedCtor, constructors) {
    constructors.forEach((baseCtor) => {
        Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
            Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
                Object.create(null));
        });
    });
}
//# sourceMappingURL=base-core-sdk.js.map