import { decodeAbiParameters, encodeAbiParameters } from "viem";
const ABI = [
    { name: "protocols", type: "address[]" },
    { name: "assets", type: "address[]" },
    { name: "maxAmountPerTx", type: "uint256" },
    { name: "maxLtvBps", type: "uint256" },
    { name: "collateralOracle", type: "address" },
    { name: "borrowOracle", type: "address" },
    { name: "maxPriceAgeSec", type: "uint256" },
];
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
export const boundedBorrowTemplate = {
    name: "SharedBoundedBorrowPermission",
    address: "0x0000000000000000000000000000000000000000",
    encoder: {
        encode(params) {
            return encodeAbiParameters(ABI, [
                params.protocols,
                params.assets,
                params.maxAmountPerTx,
                BigInt(params.maxLtvBps),
                params.collateralOracle,
                params.borrowOracle,
                BigInt(params.maxPriceAgeSec),
            ]);
        },
        decode(data) {
            const decoded = decodeAbiParameters(ABI, data);
            return {
                protocols: [...decoded[0]],
                assets: [...decoded[1]],
                maxAmountPerTx: decoded[2],
                maxLtvBps: Number(decoded[3]),
                collateralOracle: decoded[4],
                borrowOracle: decoded[5],
                maxPriceAgeSec: Number(decoded[6]),
            };
        },
    },
    explainer: {
        explain(params) {
            const warnings = [];
            if (params.maxLtvBps > 8000) {
                warnings.push(`High LTV cap: ${params.maxLtvBps / 100}% — liquidation risk is elevated`);
            }
            if (params.collateralOracle === ZERO_ADDRESS || params.borrowOracle === ZERO_ADDRESS) {
                warnings.push("LTV not enforced — both collateral and borrow oracles must be set");
            }
            return {
                templateName: "SharedBoundedBorrowPermission",
                humanReadable: [
                    `Maximum borrow per tx: ${params.maxAmountPerTx.toString()} (asset base units)`,
                    `Maximum LTV: ${params.maxLtvBps / 100}%`,
                    `Allowed protocols: ${params.protocols.join(", ")}`,
                    `Allowed assets: ${params.assets.join(", ")}`,
                    `Collateral oracle: ${params.collateralOracle}`,
                    `Borrow oracle: ${params.borrowOracle}`,
                    `Max oracle price age: ${params.maxPriceAgeSec}s`,
                ],
                warnings,
            };
        },
    },
};
//# sourceMappingURL=boundedBorrow.js.map