import { decodeAbiParameters, encodeAbiParameters } from "viem";
const ABI = [
    { name: "routers", type: "address[]" },
    { name: "tokensIn", type: "address[]" },
    { name: "tokensOut", type: "address[]" },
    { name: "maxAmountPerTx", type: "uint256" },
    { name: "maxSlippageBps", type: "uint256" },
    { name: "priceOracle", type: "address" },
    { name: "maxPriceAgeSec", type: "uint256" },
];
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
export const boundedSwapTemplate = {
    name: "SharedBoundedSwapPermission",
    address: "0x0000000000000000000000000000000000000000",
    encoder: {
        encode(params) {
            return encodeAbiParameters(ABI, [
                params.routers,
                params.tokensIn,
                params.tokensOut,
                params.maxAmountPerTx,
                BigInt(params.maxSlippageBps),
                params.priceOracle,
                BigInt(params.maxPriceAgeSec),
            ]);
        },
        decode(data) {
            const decoded = decodeAbiParameters(ABI, data);
            return {
                routers: [...decoded[0]],
                tokensIn: [...decoded[1]],
                tokensOut: [...decoded[2]],
                maxAmountPerTx: decoded[3],
                maxSlippageBps: Number(decoded[4]),
                priceOracle: decoded[5],
                maxPriceAgeSec: Number(decoded[6]),
            };
        },
    },
    explainer: {
        explain(params) {
            const warnings = [];
            if (params.maxSlippageBps > 100) {
                warnings.push(`High slippage tolerance: ${params.maxSlippageBps / 100}%`);
            }
            if (params.priceOracle === ZERO_ADDRESS) {
                warnings.push("No price oracle configured — swaps are not checked against a reference price");
            }
            return {
                templateName: "SharedBoundedSwapPermission",
                humanReadable: [
                    `Maximum input per swap: ${params.maxAmountPerTx.toString()} (input-token base units)`,
                    `Maximum slippage: ${params.maxSlippageBps / 100}%`,
                    `Allowed routers: ${params.routers.join(", ")}`,
                    `Allowed input tokens: ${params.tokensIn.join(", ")}`,
                    `Allowed output tokens: ${params.tokensOut.join(", ")}`,
                    params.priceOracle === ZERO_ADDRESS
                        ? "Price oracle: none"
                        : `Price oracle: ${params.priceOracle} (max age ${params.maxPriceAgeSec}s)`,
                ],
                warnings,
            };
        },
    },
};
//# sourceMappingURL=boundedSwap.js.map