"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTimeDayAgo = exports.getRange = exports.getSupplied = void 0;
const ks_sdk_core_1 = require("@kyberswap/ks-sdk-core");
const ks_sdk_elastic_1 = require("@kyberswap/ks-sdk-elastic");
const dayjs_1 = __importDefault(require("dayjs"));
const _types_1 = require("../../../types");
const getSupplied = ({ position, state, token0, token1, network, }) => {
    const tickLower = Number(position.tickLower);
    const tickUpper = Number(position.tickUpper);
    const feeBips = Number(position.fee);
    const networkId = _types_1.NETWORK_IDS[network];
    const t0 = new ks_sdk_core_1.Token(networkId, token0.address, token0.decimals, token0.symbol);
    const t1 = new ks_sdk_core_1.Token(networkId, token1.address, token1.decimals, token1.symbol);
    const pool = new ks_sdk_elastic_1.Pool(t0, t1, feeBips, state.sqrtPriceX96.toString(), state.liquidity.toString(), state.reinvestL.toString(), state.currentTick);
    const pos = new ks_sdk_elastic_1.Position({ pool, liquidity: position.liquidity.toString(), tickLower, tickUpper });
    const token0BalanceRaw = pos.amount0.multiply(Math.pow(10, token0.decimals)).toFixed(0);
    const token1BalanceRaw = pos.amount1.multiply(Math.pow(10, token1.decimals)).toFixed(0);
    return [token0BalanceRaw, token1BalanceRaw];
};
exports.getSupplied = getSupplied;
const getRange = ({ position, state, token0, token1, network, }) => {
    const sqrtPriceX96 = state.sqrtPriceX96;
    const tickCurrent = state.currentTick;
    const tickLower = Number(position.tickLower);
    const tickUpper = Number(position.tickUpper);
    const feeBips = Number(position.fee);
    const networkId = _types_1.NETWORK_IDS[network];
    const t0Wrapper = new ks_sdk_core_1.Token(networkId, token0.address, token0.decimals, token0.symbol);
    const t1Wrapper = new ks_sdk_core_1.Token(networkId, token1.address, token1.decimals, token1.symbol);
    const pool = new ks_sdk_elastic_1.Pool(t0Wrapper, t1Wrapper, feeBips, sqrtPriceX96.toString(), state.liquidity.toString(), state.reinvestL.toString(), tickCurrent);
    const positionZ = new ks_sdk_elastic_1.Position({ pool, liquidity: position.liquidity.toString(), tickLower, tickUpper });
    const positionLowerBound = Number(positionZ.token0PriceLower.toFixed(4));
    const positionUpperBound = Number(positionZ.token0PriceUpper.toFixed(4));
    return [positionLowerBound, positionUpperBound];
};
exports.getRange = getRange;
function getTimeDayAgo() {
    const utcCurrentTime = (0, dayjs_1.default)();
    return utcCurrentTime.subtract(1, 'day').startOf('minute').unix();
}
exports.getTimeDayAgo = getTimeDayAgo;
//# sourceMappingURL=kyberswap-elastic.liquidity.utils.js.map