"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
const typechain_1 = require("../typechain");
const superstruct_1 = require("superstruct");
const utils_1 = require("../utils");
const 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)(),
});
const L1TokenConfigSs = (0, superstruct_1.object)({
    rateModel: RateModelSs,
    routeRateModel: (0, superstruct_1.optional)((0, superstruct_1.record)((0, superstruct_1.string)(), RateModelSs)),
});
class Client {
    contract;
    constructor(address, provider) {
        this.contract = typechain_1.AcrossConfigStore__factory.connect(address, provider);
    }
    static parseL1TokenConfig(data) {
        const l1TokenConfig = JSON.parse(data);
        const l1TokenConfigMask = (0, utils_1.filterFalsyKeys)((0, superstruct_1.mask)(l1TokenConfig, L1TokenConfigSs));
        (0, superstruct_1.assert)(l1TokenConfigMask, L1TokenConfigSs);
        return l1TokenConfigMask;
    }
    async getL1TokenConfig(l1TokenAddress, overrides = {}) {
        const data = await this.contract.l1TokenConfig(l1TokenAddress, overrides);
        return Client.parseL1TokenConfig(data);
    }
    async getRateModel(l1TokenAddress, overrides = {}, originChainId, destinationChainId) {
        const l1TokenConfig = await this.getL1TokenConfig(l1TokenAddress, overrides);
        if (originChainId === undefined || destinationChainId === undefined)
            return l1TokenConfig.rateModel;
        const routeRateModelKey = `${originChainId}-${destinationChainId}`;
        if (l1TokenConfig.routeRateModel && l1TokenConfig.routeRateModel[routeRateModelKey]) {
            return l1TokenConfig.routeRateModel[routeRateModelKey];
        }
        return l1TokenConfig.rateModel;
    }
}
exports.Client = Client;
//# sourceMappingURL=acrossConfigStore.js.map