"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDepositAmountsWithRatio = void 0;
var bn_1 = require("./bn");
function getDepositAmountsWithRatio(price, depositRatio, amt0BN, amt1BN, token0, token1) {
    var _a, _b;
    if (token0.decimals == null || token1.decimals == null)
        return [amt0BN, amt1BN];
    if (token0.isBase === true)
        price = 1 / price; // handle tokens reverse logic
    if (amt0BN !== null && amt1BN === null) {
        // Given amt0, calculate amt1;
        if (depositRatio === 0)
            return [(0, bn_1.toBN)(0), (0, bn_1.toBN)(0)];
        if (depositRatio === 1)
            return [null, (0, bn_1.toBN)(0)];
        // TODO: deposit ratio must consider token decimal differences
        var amt0 = (0, bn_1.bnToNumber)(amt0BN, token1.decimals); // using target token result decimals
        var amt1Result = (_a = ((amt0 * (1 / depositRatio - 1)) / price)) === null || _a === void 0 ? void 0 : _a.toFixed(token1.decimals);
        var amt1ResultBN = (0, bn_1.safeParseUnits)(amt1Result, token1.decimals);
        return [null, amt1ResultBN];
    }
    else if (amt0BN === null && amt1BN !== null) {
        // Given amt1, calcualte amt0;
        if (depositRatio === 0)
            return [(0, bn_1.toBN)(0), null];
        if (depositRatio === 1)
            return [(0, bn_1.toBN)(0), (0, bn_1.toBN)(0)];
        var amt1 = (0, bn_1.bnToNumber)(amt1BN, token0.decimals); // using target token result decimals
        var amt0Result = (_b = (amt1 * (1 / depositRatio - 1) * price)) === null || _b === void 0 ? void 0 : _b.toFixed(token0.decimals);
        var amt0ResultBN = (0, bn_1.safeParseUnits)(amt0Result, token0.decimals);
        return [amt0ResultBN, null];
    }
    else
        throw new Error('Invalid amounts given to getDepositAmounts');
}
exports.getDepositAmountsWithRatio = getDepositAmountsWithRatio;
//# sourceMappingURL=depositRatio.js.map