"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
var tslib_1 = require("tslib");
var typechain_1 = require("../typechain");
var superstruct_1 = require("superstruct");
var utils_1 = require("../utils");
var RateModelSs = (0, superstruct_1.object)({
    UBar: (0, superstruct_1.string)(),
    R0: (0, superstruct_1.string)(),
    R1: (0, superstruct_1.string)(),
    R2: (0, superstruct_1.string)(),
});
var L1TokenConfigSs = (0, superstruct_1.object)({
    rateModel: RateModelSs,
    routeRateModel: (0, superstruct_1.optional)((0, superstruct_1.record)((0, superstruct_1.string)(), RateModelSs)),
});
var Client = (function () {
    function Client(address, provider) {
        this.contract = typechain_1.AcrossConfigStore__factory.connect(address, provider);
    }
    Client.parseL1TokenConfig = function (data) {
        var l1TokenConfig = JSON.parse(data);
        var l1TokenConfigMask = (0, utils_1.filterFalsyKeys)((0, superstruct_1.mask)(l1TokenConfig, L1TokenConfigSs));
        (0, superstruct_1.assert)(l1TokenConfigMask, L1TokenConfigSs);
        return l1TokenConfigMask;
    };
    Client.prototype.getL1TokenConfig = function (l1TokenAddress_1) {
        return tslib_1.__awaiter(this, arguments, void 0, function (l1TokenAddress, overrides) {
            var data;
            if (overrides === void 0) { overrides = {}; }
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4, this.contract.l1TokenConfig(l1TokenAddress, overrides)];
                    case 1:
                        data = _a.sent();
                        return [2, Client.parseL1TokenConfig(data)];
                }
            });
        });
    };
    Client.prototype.getRateModel = function (l1TokenAddress_1) {
        return tslib_1.__awaiter(this, arguments, void 0, function (l1TokenAddress, overrides, originChainId, destinationChainId) {
            var l1TokenConfig, routeRateModelKey;
            if (overrides === void 0) { overrides = {}; }
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4, this.getL1TokenConfig(l1TokenAddress, overrides)];
                    case 1:
                        l1TokenConfig = _a.sent();
                        if (originChainId === undefined || destinationChainId === undefined)
                            return [2, l1TokenConfig.rateModel];
                        routeRateModelKey = "".concat(originChainId, "-").concat(destinationChainId);
                        if (l1TokenConfig.routeRateModel && l1TokenConfig.routeRateModel[routeRateModelKey]) {
                            return [2, l1TokenConfig.routeRateModel[routeRateModelKey]];
                        }
                        return [2, l1TokenConfig.rateModel];
                }
            });
        });
    };
    return Client;
}());
exports.Client = Client;
//# sourceMappingURL=acrossConfigStore.js.map