@exponent-labs/market-three-math 0.1.8 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/addLiquidity.d.ts +65 -4
- package/build/addLiquidity.js +757 -30
- package/build/addLiquidity.js.map +1 -1
- package/build/bisect.d.ts +11 -0
- package/build/bisect.js +21 -10
- package/build/bisect.js.map +1 -1
- package/build/index.d.ts +5 -4
- package/build/index.js +14 -7
- package/build/index.js.map +1 -1
- package/build/liquidityHistogram.d.ts +6 -1
- package/build/liquidityHistogram.js +55 -9
- package/build/liquidityHistogram.js.map +1 -1
- package/build/quote.d.ts +1 -1
- package/build/quote.js +68 -82
- package/build/quote.js.map +1 -1
- package/build/swap.js +35 -16
- package/build/swap.js.map +1 -1
- package/build/swapV2.d.ts +6 -1
- package/build/swapV2.js +394 -51
- package/build/swapV2.js.map +1 -1
- package/build/types.d.ts +51 -0
- package/build/utils.d.ts +8 -2
- package/build/utils.js +23 -5
- package/build/utils.js.map +1 -1
- package/build/utilsV2.d.ts +9 -0
- package/build/utilsV2.js +127 -5
- package/build/utilsV2.js.map +1 -1
- package/build/withdrawLiquidity.js +11 -5
- package/build/withdrawLiquidity.js.map +1 -1
- package/build/ytTrades.d.ts +7 -0
- package/build/ytTrades.js +163 -142
- package/build/ytTrades.js.map +1 -1
- package/package.json +2 -2
- package/src/addLiquidity.ts +1012 -38
- package/src/bisect.ts +22 -11
- package/src/index.ts +11 -5
- package/src/liquidityHistogram.ts +54 -9
- package/src/quote.ts +73 -95
- package/src/swap.ts +35 -19
- package/src/swapV2.ts +999 -0
- package/src/types.ts +55 -0
- package/src/utils.ts +24 -3
- package/src/utilsV2.ts +337 -0
- package/src/withdrawLiquidity.ts +12 -6
- package/src/ytTrades.ts +191 -172
- package/src/ytTradesLegacy.ts +419 -0
- package/build/swap-v2.d.ts +0 -20
- package/build/swap-v2.js +0 -261
- package/build/swap-v2.js.map +0 -1
- package/src/swapLegacy.ts +0 -272
package/build/addLiquidity.d.ts
CHANGED
|
@@ -1,14 +1,43 @@
|
|
|
1
|
+
import { AddLiquidityArgs, AddLiquidityOutcome, CrossingScaleParams, CrossingTickState, LiquidityNeeds, MarketThreeState } from "./types";
|
|
2
|
+
import { EffSnap } from "./utilsV2";
|
|
3
|
+
import { Ticks } from "@exponent-labs/exponent-fetcher";
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
5
|
+
* Get crossing tick state and price boundaries from Ticks.
|
|
6
|
+
* Matches wrapper_provide_liquidity.rs: current node's spot_price, principal_pt/sy/supply, successor's spot_price.
|
|
4
7
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
export declare function getCrossingTickStateFromTicks(ticks: Ticks): {
|
|
9
|
+
crossingTickState: CrossingTickState;
|
|
10
|
+
crossingTickPriceLeft: number;
|
|
11
|
+
crossingTickPriceRight: number;
|
|
12
|
+
};
|
|
7
13
|
/**
|
|
8
14
|
* Compute liquidity target and token needs based on position range and budgets
|
|
9
15
|
* Ported from compute_liquidity_target_and_token_needs in math.rs
|
|
10
16
|
*/
|
|
11
17
|
export declare function computeLiquidityTargetAndTokenNeeds(snap: EffSnap, spotPriceCurrent: number, priceEffLower: number, priceEffUpper: number, lowerPrice: number, upperPrice: number, lowerTickIdx: number, upperTickIdx: number, currentIndex: number, maxSy: number, maxPt: number, epsilonClamp: number): LiquidityNeeds;
|
|
18
|
+
/**
|
|
19
|
+
* Scale crossing tick token inputs from original max values to prevent double trimming.
|
|
20
|
+
*
|
|
21
|
+
* When adding liquidity that spans the current price (crossing tick), tokens get trimmed twice:
|
|
22
|
+
* 1. First by CLMM formula in computeLiquidityTargetAndTokenNeeds
|
|
23
|
+
* 2. Then by AMM formula in simulateAddLiquidityProportional
|
|
24
|
+
*
|
|
25
|
+
* This function calculates the segment's proportion of the total distribution and scales
|
|
26
|
+
* the original max values accordingly, ensuring maximum token utilization.
|
|
27
|
+
*
|
|
28
|
+
* @param scaleParams - Original max values and CLMM distribution extents
|
|
29
|
+
* @param duPtPart - PT segment length (spot price delta for this segment)
|
|
30
|
+
* @param syPerL1 - SY per unit liquidity for this segment
|
|
31
|
+
* @param clmmPtDelta - PT amount calculated from CLMM formula
|
|
32
|
+
* @param clmmSyDelta - SY amount calculated from CLMM formula
|
|
33
|
+
* @returns Tuple of [scaledPtIn, scaledSyIn] - maximum of CLMM-calculated and scaled original values
|
|
34
|
+
*/
|
|
35
|
+
export declare function scaleCrossingTickInputs(scaleParams: CrossingScaleParams, duPtPart: number, syPerL1: number, clmmPtDelta: number, clmmSyDelta: number): [number, number];
|
|
36
|
+
/**
|
|
37
|
+
* Compute token needs with crossing tick adjustment
|
|
38
|
+
* This matches the Rust compute_token_needs_with_crossing function
|
|
39
|
+
*/
|
|
40
|
+
export declare function computeTokenNeedsWithCrossing(snap: EffSnap, spotPriceCurrent: number, priceEffLower: number, priceEffUpper: number, lowerPrice: number, upperPrice: number, maxSy: number, maxPt: number, epsilonClamp: number, crossingTickState: CrossingTickState, crossingTickPriceLeft: number, crossingTickPriceRight: number): [number, number];
|
|
12
41
|
/**
|
|
13
42
|
* Simulate adding liquidity to the CLMM market
|
|
14
43
|
* This is a pure function that does not mutate the market state
|
|
@@ -36,6 +65,13 @@ export declare function calcDepositSyAndPtFromBaseAmount(params: {
|
|
|
36
65
|
expirationTs: number;
|
|
37
66
|
currentSpotPrice: number;
|
|
38
67
|
syExchangeRate: number;
|
|
68
|
+
/** Optional crossing tick state for accurate ratio prediction.
|
|
69
|
+
* When provided, the prediction accounts for the existing PT/SY proportions
|
|
70
|
+
* in the active tick, matching the on-chain behaviour more closely. */
|
|
71
|
+
crossingTickState?: CrossingTickState;
|
|
72
|
+
crossingTickPriceLeft?: number;
|
|
73
|
+
crossingTickPriceRight?: number;
|
|
74
|
+
epsilonClamp?: number;
|
|
39
75
|
}): {
|
|
40
76
|
syNeeded: number;
|
|
41
77
|
ptNeeded: number;
|
|
@@ -65,3 +101,28 @@ export declare function simulateWrapperProvideLiquidity(marketState: MarketThree
|
|
|
65
101
|
ptDeposited: number;
|
|
66
102
|
syDeposited: number;
|
|
67
103
|
} | null;
|
|
104
|
+
/**
|
|
105
|
+
* Simulate swap & supply operation (ixProvideLiquidityBase)
|
|
106
|
+
* 1. Mints SY from base asset
|
|
107
|
+
* 2. Swaps some SY for PT on the market (instead of stripping)
|
|
108
|
+
* 3. Deposits remaining SY + bought PT into liquidity position
|
|
109
|
+
*
|
|
110
|
+
* This approach has lower slippage than minting because it uses market liquidity.
|
|
111
|
+
*
|
|
112
|
+
* @param marketState - Current market state
|
|
113
|
+
* @param amountBase - Amount of base tokens (in lamports)
|
|
114
|
+
* @param lowerTick - Lower tick key (APY in basis points)
|
|
115
|
+
* @param upperTick - Upper tick key (APY in basis points)
|
|
116
|
+
* @param syExchangeRate - SY exchange rate
|
|
117
|
+
* @returns Simulation result with LP out, PT to buy, SY constraint, etc.
|
|
118
|
+
*/
|
|
119
|
+
export declare function simulateSwapAndSupply(marketState: MarketThreeState, amountBase: number, lowerTick: number, upperTick: number, syExchangeRate: number): {
|
|
120
|
+
lpOut: number;
|
|
121
|
+
ptToBuy: number;
|
|
122
|
+
syConstraint: number;
|
|
123
|
+
syForSwap: number;
|
|
124
|
+
syRemainder: number;
|
|
125
|
+
ptFromSwap: number;
|
|
126
|
+
syDeposited: number;
|
|
127
|
+
ptDeposited: number;
|
|
128
|
+
} | null;
|