/** * MetricAMM SDK - Liquidity * Unified liquidity calculations and position operations. */ import type { Address, PublicClient, Hex } from "viem"; import type { LiquidityDelta, LiquidityBinValueInput } from "../types.js"; import { getPositionBinSharesRange, getPositionBinSharesForBins } from "../stateView/read.js"; import { convertToken0ToToken1, convertToken1ToToken0 } from "../utils/liquidityMath.js"; export { convertToken0ToToken1, convertToken1ToToken0 }; export declare const getPositionShares: typeof getPositionBinSharesRange; export declare const getPositionSharesForBins: typeof getPositionBinSharesForBins; export interface RemoveLiquidityParams { percentageToRemove: number; bins?: number[]; lowerBin?: number; upperBin?: number; } export interface BinRemovalSpec { bin: number; percentageToRemove?: number; sharesToRemove?: bigint; } export declare const NO_SLIPPAGE_LIMIT: bigint; type ModifyLiquidityParams = { salt: bigint; deltas: LiquidityDelta[]; specAmount0: bigint; specAmount1: bigint; }; export type ModifyLiquidityArgs = readonly [bigint, LiquidityDelta[], bigint, bigint]; export interface BuildModifyLiquidityArgsBase { publicClient: PublicClient; stateViewAddress: Address; poolAddress: Address; specAmountBufferPercent?: number; } export interface BuildModifyLiquidityArgsForAdditionParams extends BuildModifyLiquidityArgsBase { bins: LiquidityBinValueInput[]; currentPrice?: number; currentPriceX64?: bigint; salt?: bigint; } export interface BuildModifyLiquidityArgsForUniformAdditionParams extends BuildModifyLiquidityArgsBase { amountInTokensPerBin: bigint; amountIsInToken0: boolean; currentPrice: number; lowerBin: number; upperBin: number; salt?: bigint; } export interface BuildModifyLiquidityArgsForUniformAdditionWithTotalTokenAmountParams extends BuildModifyLiquidityArgsBase { bins: number[]; weights?: number[]; totalValueToAddInToken: bigint; totalValueInToken0: boolean; currentPriceX64: bigint; salt?: bigint; } export interface BuildModifyLiquidityArgsForPercentageRemovalParams extends BuildModifyLiquidityArgsBase { owner: Address; salt: bigint; percentageToRemove: number; bins?: number[]; lowerBin?: number; upperBin?: number; } export interface BuildModifyLiquidityArgsForRemovalParams extends BuildModifyLiquidityArgsBase { owner: Address; salt: bigint; specs: BinRemovalSpec[]; } /** * Prepare uniform liquidity distribution across a bin range. */ export declare function buildModifyLiquidityArgsForUniformAddition({ publicClient, stateViewAddress, poolAddress, amountInTokensPerBin, amountIsInToken0, currentPrice, lowerBin, upperBin, salt, specAmountBufferPercent, }: BuildModifyLiquidityArgsForUniformAdditionParams): Promise; /** * Prepare uniform liquidity across arbitrary bins from a TOTAL value budget. * * Algorithm: * 1. Calibrate by assigning weighted 1e18 targets per bin with zero buffer. * 2. Compute linear scale so selected specAmount token matches totalValueToAddInToken. * 3. Rebuild with scaled per-bin value and caller-provided specAmountBufferPercent. */ export declare function buildModifyLiquidityArgsForUniformAdditionWithTotalTokenAmount({ publicClient, stateViewAddress, poolAddress, bins, weights, totalValueToAddInToken, totalValueInToken0, currentPriceX64, salt, specAmountBufferPercent, }: BuildModifyLiquidityArgsForUniformAdditionWithTotalTokenAmountParams): Promise; /** * Prepare per-bin liquidity distribution from arbitrary per-bin amounts. * * Each input entry defines a single bin and a value expressed in token0 or token1. * The function computes `deltaShares` for every bin and totals `specAmount0/specAmount1` * needed to execute `modifyLiquidity` safely. * * ## Algorithm Overview * * This is the core distribution engine used by both: * - direct per-bin plans (computeModifyLiquidityForAddition) * - uniform plans via adapter (computeModifyLiquidityForUniformAddition) * * ## Steps * * 1. Validate inputs, price, bin range, and reject duplicate bins. * 2. Convert each bin target into both token0/token1 amounts using current price. * 3. Fetch slot0 and bin states, then classify each bin as below/current/above. * 4. Compute shares to add using ceiling division to avoid under-provisioning: * - Existing bins: proportional to current scaled balances and total shares. * - Empty bins: derived from initial scaled per-share constants. * 5. Convert scaled amounts back to external token amounts and accumulate * `specAmount0/specAmount1` with overflow checks. */ export declare function buildModifyLiquidityArgsForAddition({ publicClient, stateViewAddress, poolAddress, bins, currentPrice, currentPriceX64, salt, specAmountBufferPercent, }: BuildModifyLiquidityArgsForAdditionParams): Promise; export declare function buildModifyLiquidityArgsForRemoval({ publicClient, stateViewAddress, poolAddress, owner, salt, specs, specAmountBufferPercent, }: BuildModifyLiquidityArgsForRemovalParams): Promise; export declare function buildModifyLiquidityArgsForPercentageRemoval({ publicClient, stateViewAddress, poolAddress, owner, salt, percentageToRemove, bins, lowerBin, upperBin, specAmountBufferPercent, }: BuildModifyLiquidityArgsForPercentageRemovalParams): Promise; export declare function encodeModifyLiquidityCalldata(preparedModifyLiquidity: ModifyLiquidityParams | ModifyLiquidityArgs): Hex; //# sourceMappingURL=liquidity.d.ts.map