"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildPoolRebalanceLeafTree = void 0;
var tslib_1 = require("tslib");
var contracts_1 = require("@across-protocol/contracts");
var ContractUtils_1 = require("../../../utils/ContractUtils");
var ethers_1 = require("ethers");
function buildPoolRebalanceLeafTree(poolRebalanceLeaves) {
    for (var i = 0; i < poolRebalanceLeaves.length; i++) {
        if (poolRebalanceLeaves[i].l1Tokens.length !== poolRebalanceLeaves[i].bundleLpFees.length ||
            poolRebalanceLeaves[i].netSendAmounts.length !== poolRebalanceLeaves[i].bundleLpFees.length) {
            throw new Error("Provided lef arrays are not of equal length");
        }
        if (poolRebalanceLeaves[i].runningBalances.length !== poolRebalanceLeaves[i].bundleLpFees.length * 2 &&
            poolRebalanceLeaves[i].runningBalances.length !== poolRebalanceLeaves[i].bundleLpFees.length) {
            throw new Error("Running balances length unexpected");
        }
    }
    var paramType = (0, ContractUtils_1.getParamType)("MerkleLibTest", "verifyPoolRebalance", "rebalance");
    var hashFn = function (input) {
        var ethersLeaf = tslib_1.__assign(tslib_1.__assign({}, input), { l1Tokens: input.l1Tokens.map(function (l1Token) { return l1Token.toEvmAddress(); }) });
        return ethers_1.utils.keccak256(ethers_1.utils.defaultAbiCoder.encode([paramType], [ethersLeaf]));
    };
    return new contracts_1.MerkleTree(poolRebalanceLeaves, hashFn);
}
exports.buildPoolRebalanceLeafTree = buildPoolRebalanceLeafTree;
//# sourceMappingURL=MerkleTreeUtils.js.map