"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildPoolRebalanceLeafTree = buildPoolRebalanceLeafTree;
const contracts_1 = require("@across-protocol/contracts");
const ContractUtils_1 = require("../../../utils/ContractUtils");
const ethers_1 = require("ethers");
function buildPoolRebalanceLeafTree(poolRebalanceLeaves) {
    for (let 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");
        }
    }
    const paramType = (0, ContractUtils_1.getParamType)("MerkleLibTest", "verifyPoolRebalance", "rebalance");
    const hashFn = (input) => {
        const ethersLeaf = {
            ...input,
            l1Tokens: input.l1Tokens.map((l1Token) => l1Token.toEvmAddress()),
        };
        return ethers_1.utils.keccak256(ethers_1.utils.defaultAbiCoder.encode([paramType], [ethersLeaf]));
    };
    return new contracts_1.MerkleTree(poolRebalanceLeaves, hashFn);
}
//# sourceMappingURL=MerkleTreeUtils.js.map