@exponent-labs/market-three-math 0.1.8
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/CHANGELOG.md +8 -0
- package/README.md +197 -0
- package/build/addLiquidity.d.ts +67 -0
- package/build/addLiquidity.js +269 -0
- package/build/addLiquidity.js.map +1 -0
- package/build/bisect.d.ts +1 -0
- package/build/bisect.js +62 -0
- package/build/bisect.js.map +1 -0
- package/build/index.d.ts +24 -0
- package/build/index.js +76 -0
- package/build/index.js.map +1 -0
- package/build/liquidityHistogram.d.ts +50 -0
- package/build/liquidityHistogram.js +162 -0
- package/build/liquidityHistogram.js.map +1 -0
- package/build/quote.d.ts +18 -0
- package/build/quote.js +106 -0
- package/build/quote.js.map +1 -0
- package/build/swap-v2.d.ts +20 -0
- package/build/swap-v2.js +261 -0
- package/build/swap-v2.js.map +1 -0
- package/build/swap.d.ts +15 -0
- package/build/swap.js +249 -0
- package/build/swap.js.map +1 -0
- package/build/swapLegacy.d.ts +16 -0
- package/build/swapLegacy.js +229 -0
- package/build/swapLegacy.js.map +1 -0
- package/build/swapV2.d.ts +11 -0
- package/build/swapV2.js +406 -0
- package/build/swapV2.js.map +1 -0
- package/build/types.d.ts +73 -0
- package/build/types.js +9 -0
- package/build/types.js.map +1 -0
- package/build/utils.d.ts +119 -0
- package/build/utils.js +219 -0
- package/build/utils.js.map +1 -0
- package/build/utilsV2.d.ts +88 -0
- package/build/utilsV2.js +180 -0
- package/build/utilsV2.js.map +1 -0
- package/build/withdrawLiquidity.d.ts +8 -0
- package/build/withdrawLiquidity.js +174 -0
- package/build/withdrawLiquidity.js.map +1 -0
- package/build/ytTrades.d.ts +106 -0
- package/build/ytTrades.js +292 -0
- package/build/ytTrades.js.map +1 -0
- package/build/ytTradesLegacy.d.ts +106 -0
- package/build/ytTradesLegacy.js +292 -0
- package/build/ytTradesLegacy.js.map +1 -0
- package/examples/.env.example +1 -0
- package/examples/test-histogram-simple.ts +172 -0
- package/examples/test-histogram.ts +112 -0
- package/package.json +26 -0
- package/src/addLiquidity.ts +384 -0
- package/src/bisect.ts +72 -0
- package/src/index.ts +74 -0
- package/src/liquidityHistogram.ts +192 -0
- package/src/quote.ts +128 -0
- package/src/swap.ts +299 -0
- package/src/swapLegacy.ts +272 -0
- package/src/types.ts +80 -0
- package/src/utils.ts +235 -0
- package/src/withdrawLiquidity.ts +240 -0
- package/src/ytTrades.ts +419 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swapV2.js","sourceRoot":"","sources":["../src/swapV2.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,mCAAkF;AAClF,uCAMkB;AAElB,MAAM,WAAW,GAAG,KAAK,CAAA;AAEzB;;;GAGG;AACH,SAAgB,YAAY,CAAC,WAA6B,EAAE,IAAc;IACxE,MAAM,KAAK,GAAG,KAAK,CAAA,CAAC,4BAA4B;IAEhD,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,GAAG,WAAW,CAAA;IAC/D,MAAM,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IAEzF,4CAA4C;IAC5C,MAAM,QAAQ,GAAG,IAAI,iBAAO,CAAC,IAAA,iCAAuB,EAAC,gBAAgB,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;IAE5F,yCAAyC;IACzC,MAAM,YAAY,GAAG,IAAI,sBAAY,CAAC,KAAK,CAAC,CAAA;IAE5C,oDAAoD;IACpD,IAAI,gBAAgB,GAAG,YAAY,CAAC,gBAAgB,CAAA;IACpD,IAAI,sBAAsB,GAAG,YAAY,CAAC,cAAc,CAAA;IAExD,qEAAqE;IACrE,IAAI,kBAAkB,GAAG,YAAY,CAAC,gBAAgB,CAAA;IACtD,IAAI,kBAAkB,GA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AE,kBAAkB;QAC1C,gBAAgB,EAAE,YAAY;QAC9B,kBAAkB,EAAE,OAAO;QAC3B,kBAAkB,EAAE,MAAM,CAAC,OAAO,CAAC;KACpC,CAAA;AACH,CAAC"}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { MarketConfigurationOptions, MarketThreeFinancials, Ticks } from "@exponent-labs/exponent-fetcher";
|
|
2
|
+
export declare enum SwapDirection {
|
|
3
|
+
PtToSy = "PtToSy",
|
|
4
|
+
SyToPt = "SyToPt"
|
|
5
|
+
}
|
|
6
|
+
export interface MarketThreeState {
|
|
7
|
+
/** Market financials */
|
|
8
|
+
financials: MarketThreeFinancials;
|
|
9
|
+
/** Configuration options */
|
|
10
|
+
configurationOptions: MarketConfigurationOptions;
|
|
11
|
+
/** Ticks data */
|
|
12
|
+
ticks: Ticks;
|
|
13
|
+
/** Current SY exchange rate */
|
|
14
|
+
currentSyExchangeRate: number;
|
|
15
|
+
}
|
|
16
|
+
export interface SwapArgs {
|
|
17
|
+
/** Direction of the swap */
|
|
18
|
+
direction: SwapDirection;
|
|
19
|
+
/** Exact amount in */
|
|
20
|
+
amountIn: number;
|
|
21
|
+
/** Optional spot price limit (anti-sandwich) */
|
|
22
|
+
priceSpotLimit?: number;
|
|
23
|
+
/** SY exchange rate */
|
|
24
|
+
syExchangeRate: number;
|
|
25
|
+
/** Is this a flash swap? */
|
|
26
|
+
isCurrentFlashSwap: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface SwapOutcome {
|
|
29
|
+
/** Amount of input consumed */
|
|
30
|
+
amountInConsumed: number;
|
|
31
|
+
/** Amount out (after fees) */
|
|
32
|
+
amountOut: number;
|
|
33
|
+
/** LP fee charged in out token */
|
|
34
|
+
lpFeeChargedOutToken: number;
|
|
35
|
+
/** Protocol fee charged in out token */
|
|
36
|
+
protocolFeeChargedOutToken: number;
|
|
37
|
+
/** Final spot price after swap */
|
|
38
|
+
finalSpotPrice: number;
|
|
39
|
+
/** Final tick index after swap */
|
|
40
|
+
finalTickIndex: number;
|
|
41
|
+
}
|
|
42
|
+
export interface AddLiquidityArgs {
|
|
43
|
+
/** Lower tick key (ln implied rate in bps) */
|
|
44
|
+
lowerTick: number;
|
|
45
|
+
/** Upper tick key (ln implied rate in bps) */
|
|
46
|
+
upperTick: number;
|
|
47
|
+
/** Maximum SY to spend */
|
|
48
|
+
maxSy: number;
|
|
49
|
+
/** Maximum PT to spend */
|
|
50
|
+
maxPt: number;
|
|
51
|
+
/** SY exchange rate */
|
|
52
|
+
syExchangeRate: number;
|
|
53
|
+
}
|
|
54
|
+
export interface AddLiquidityOutcome {
|
|
55
|
+
/** Liquidity added */
|
|
56
|
+
deltaL: number;
|
|
57
|
+
/** SY spent */
|
|
58
|
+
sySpent: number;
|
|
59
|
+
/** PT spent */
|
|
60
|
+
ptSpent: number;
|
|
61
|
+
}
|
|
62
|
+
export interface LiquidityNeeds {
|
|
63
|
+
/** Target liquidity to add */
|
|
64
|
+
liquidityTarget: number;
|
|
65
|
+
/** SY needed */
|
|
66
|
+
syNeeded: number;
|
|
67
|
+
/** PT needed */
|
|
68
|
+
ptNeeded: number;
|
|
69
|
+
/** Price split point for the need calculation */
|
|
70
|
+
priceSplitForNeed: number;
|
|
71
|
+
/** Tick index of the split point */
|
|
72
|
+
priceSplitTickIdx: number;
|
|
73
|
+
}
|
package/build/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapDirection = void 0;
|
|
4
|
+
var SwapDirection;
|
|
5
|
+
(function (SwapDirection) {
|
|
6
|
+
SwapDirection["PtToSy"] = "PtToSy";
|
|
7
|
+
SwapDirection["SyToPt"] = "SyToPt";
|
|
8
|
+
})(SwapDirection || (exports.SwapDirection = SwapDirection = {}));
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,kCAAiB,CAAA;AACnB,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB"}
|
package/build/utils.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for CLMM calculations
|
|
3
|
+
* Ported from exponent_clmm/src/utils/math.rs
|
|
4
|
+
*/
|
|
5
|
+
import { Tick, Ticks } from "@exponent-labs/exponent-fetcher";
|
|
6
|
+
/**
|
|
7
|
+
* Effective price snapshot
|
|
8
|
+
* This captures the time factor and SY exchange rate at a given moment
|
|
9
|
+
* Matches the Rust implementation from exponent_clmm/src/state/market_three/helpers/add_liquidity.rs
|
|
10
|
+
*/
|
|
11
|
+
export declare class EffSnap {
|
|
12
|
+
/** Time factor (tau = normalized time remaining) */
|
|
13
|
+
timeFactor: number;
|
|
14
|
+
/** SY exchange rate (r) */
|
|
15
|
+
syExchangeRate: number;
|
|
16
|
+
constructor(timeFactor: number, syExchangeRate: number);
|
|
17
|
+
/**
|
|
18
|
+
* Calculate effective price from spot price
|
|
19
|
+
* Rust formula: C(u) = u^(-(τ-1)) / (r * (τ - 1))
|
|
20
|
+
* where τ = time_factor, u = spot_price (ln implied rate), r = sy_exchange_rate
|
|
21
|
+
*/
|
|
22
|
+
getEffectivePrice(u: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Convert effective price back to spot price
|
|
25
|
+
* Rust formula: u = (r * C * (τ - 1))^(1/(1-τ))
|
|
26
|
+
* In Rust: spot_price_from_effective_price
|
|
27
|
+
*/
|
|
28
|
+
spotPriceFromEffectivePrice(cEff: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* Legacy alias for backwards compatibility
|
|
31
|
+
*/
|
|
32
|
+
impliedRateFromEffectivePrice(cEff: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Calculate delta SY from change in effective price
|
|
35
|
+
* Rust formula: ΔSY = L * (C_old - C_new)
|
|
36
|
+
* Note: No division by time_factor in the Rust implementation
|
|
37
|
+
*/
|
|
38
|
+
deltaEffPriceToSy(liquidity: number, oldEffPrice: number, newEffPrice: number): number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Calculate normalized time remaining
|
|
42
|
+
* Returns seconds_remaining / SECONDS_PER_YEAR
|
|
43
|
+
*/
|
|
44
|
+
export declare function normalizedTimeRemaining(secondsRemaining: number): number;
|
|
45
|
+
/**
|
|
46
|
+
* Calculate current fee rate from fee rate root and time remaining
|
|
47
|
+
* fee_rate = e^(ln_fee_rate_root * time_factor)
|
|
48
|
+
*/
|
|
49
|
+
export declare function calculateFeeRate(lnFeeRateRoot: number, secondsRemaining: number): number;
|
|
50
|
+
/**
|
|
51
|
+
* Calculate fee from amount
|
|
52
|
+
* Returns the fee to charge given an amount and fee rate
|
|
53
|
+
* fee = amount * (fee_rate - 1.0)
|
|
54
|
+
*/
|
|
55
|
+
export declare function getFeeFromAmount(amount: number, feeRate: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* Find the active liquidity at a given tick index
|
|
58
|
+
* This is computed by summing liquidity_net up to the current tick
|
|
59
|
+
*/
|
|
60
|
+
export declare function getActiveLiquidity(ticks: Ticks, tickIndex: number): bigint;
|
|
61
|
+
/**
|
|
62
|
+
* Find the successor tick (next tick to the right)
|
|
63
|
+
* In Rust: ticks.successor_idx(current_left_boundary_index)
|
|
64
|
+
* @param ticks - The ticks data structure
|
|
65
|
+
* @param currentTickKey - The current tick key (apyBasePoints)
|
|
66
|
+
* @returns The next tick key (apyBasePoints) or null if none exists
|
|
67
|
+
*/
|
|
68
|
+
export declare function getSuccessorTickKey(ticks: Ticks, currentTickKey: number): number | null;
|
|
69
|
+
/**
|
|
70
|
+
* Find the successor tick by index in the tick tree
|
|
71
|
+
* This is almost equivalent to the Rust successor_idx method
|
|
72
|
+
*/
|
|
73
|
+
export declare function getSuccessorTickByIdx(ticks: Ticks, tickIdx: number): number | null;
|
|
74
|
+
/**
|
|
75
|
+
* Find the predecessor tick (next tick to the left)
|
|
76
|
+
* In Rust: ticks.predecessor_idx(current_left_boundary_index)
|
|
77
|
+
* @param ticks - The ticks data structure
|
|
78
|
+
* @param currentTickKey - The current tick key (apyBasePoints)
|
|
79
|
+
* @returns The previous tick key (apyBasePoints) or null if none exists
|
|
80
|
+
*/
|
|
81
|
+
export declare function getPredecessorTickKey(ticks: Ticks, currentTickKey: number): number | null;
|
|
82
|
+
/**
|
|
83
|
+
* Get the spot price (implied rate) for a tick key
|
|
84
|
+
* Tick key represents APY in parts per million (1e6)
|
|
85
|
+
* spot_price = 1 + tick_key / 1e6
|
|
86
|
+
*
|
|
87
|
+
* This is equivalent to the Rust code:
|
|
88
|
+
* let spot_price = (1.0 + (key as f64) / TICK_KEY_BASE_POINTS);
|
|
89
|
+
* But Rust stores it pre-computed, we compute it here
|
|
90
|
+
*/
|
|
91
|
+
export declare function getImpliedRate(tickKey: number): number;
|
|
92
|
+
/**
|
|
93
|
+
* Find a tick by its key
|
|
94
|
+
*/
|
|
95
|
+
export declare function findTickByKey(ticks: Ticks, tickKey: number): {
|
|
96
|
+
tick: Tick;
|
|
97
|
+
index: number;
|
|
98
|
+
} | null;
|
|
99
|
+
/**
|
|
100
|
+
* Find a tick by its index
|
|
101
|
+
*/
|
|
102
|
+
export declare function findTickByIndex(ticks: Ticks, index: number): Tick;
|
|
103
|
+
/**
|
|
104
|
+
* Convert APY percentage to basis points
|
|
105
|
+
*/
|
|
106
|
+
export declare function convertApyToApyBp(apyPercent: number): number;
|
|
107
|
+
/**
|
|
108
|
+
* Convert basis points to APY percentage
|
|
109
|
+
*/
|
|
110
|
+
export declare function convertApyBpToApy(apyBp: number): number;
|
|
111
|
+
export declare function bigIntMax(...args: bigint[]): bigint;
|
|
112
|
+
export declare function bigIntMin(...args: bigint[]): bigint;
|
|
113
|
+
/**
|
|
114
|
+
* Calculate PT price in asset from current spot price and expiration timestamp
|
|
115
|
+
* @param currentSpotPrice - Current spot price in format of 1 + percentage / 100
|
|
116
|
+
* @param expirationTs - Expiration timestamp in seconds
|
|
117
|
+
* @returns PT price in asset
|
|
118
|
+
*/
|
|
119
|
+
export declare function calcPtPriceInAsset(currentSpotPrice: number, expirationTs: number): number;
|
package/build/utils.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calcPtPriceInAsset = exports.bigIntMin = exports.bigIntMax = exports.convertApyBpToApy = exports.convertApyToApyBp = exports.findTickByIndex = exports.findTickByKey = exports.getImpliedRate = exports.getPredecessorTickKey = exports.getSuccessorTickByIdx = exports.getSuccessorTickKey = exports.getActiveLiquidity = exports.getFeeFromAmount = exports.calculateFeeRate = exports.normalizedTimeRemaining = exports.EffSnap = void 0;
|
|
4
|
+
const SECONDS_PER_YEAR = 365 * 24 * 60 * 60;
|
|
5
|
+
// const BASE_POINTS = 10000
|
|
6
|
+
/**
|
|
7
|
+
* Effective price snapshot
|
|
8
|
+
* This captures the time factor and SY exchange rate at a given moment
|
|
9
|
+
* Matches the Rust implementation from exponent_clmm/src/state/market_three/helpers/add_liquidity.rs
|
|
10
|
+
*/
|
|
11
|
+
class EffSnap {
|
|
12
|
+
/** Time factor (tau = normalized time remaining) */
|
|
13
|
+
timeFactor;
|
|
14
|
+
/** SY exchange rate (r) */
|
|
15
|
+
syExchangeRate;
|
|
16
|
+
constructor(timeFactor, syExchangeRate) {
|
|
17
|
+
this.timeFactor = timeFactor;
|
|
18
|
+
this.syExchangeRate = syExchangeRate;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Calculate effective price from spot price
|
|
22
|
+
* Rust formula: C(u) = u^(-(τ-1)) / (r * (τ - 1))
|
|
23
|
+
* where τ = time_factor, u = spot_price (ln implied rate), r = sy_exchange_rate
|
|
24
|
+
*/
|
|
25
|
+
getEffectivePrice(u) {
|
|
26
|
+
if (this.timeFactor === 1.0) {
|
|
27
|
+
throw new Error("time_factor cannot be 1.0");
|
|
28
|
+
}
|
|
29
|
+
return Math.pow(u, -this.timeFactor + 1.0) / (this.syExchangeRate * (this.timeFactor - 1.0));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert effective price back to spot price
|
|
33
|
+
* Rust formula: u = (r * C * (τ - 1))^(1/(1-τ))
|
|
34
|
+
* In Rust: spot_price_from_effective_price
|
|
35
|
+
*/
|
|
36
|
+
spotPriceFromEffectivePrice(cEff) {
|
|
37
|
+
const base = this.syExchangeRate * cEff * (this.timeFactor - 1.0);
|
|
38
|
+
return Math.pow(base, 1.0 / (1.0 - this.timeFactor));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Legacy alias for backwards compatibility
|
|
42
|
+
*/
|
|
43
|
+
impliedRateFromEffectivePrice(cEff) {
|
|
44
|
+
return this.spotPriceFromEffectivePrice(cEff);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Calculate delta SY from change in effective price
|
|
48
|
+
* Rust formula: ΔSY = L * (C_old - C_new)
|
|
49
|
+
* Note: No division by time_factor in the Rust implementation
|
|
50
|
+
*/
|
|
51
|
+
deltaEffPriceToSy(liquidity, oldEffPrice, newEffPrice) {
|
|
52
|
+
return liquidity * (oldEffPrice - newEffPrice);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.EffSnap = EffSnap;
|
|
56
|
+
/**
|
|
57
|
+
* Calculate normalized time remaining
|
|
58
|
+
* Returns seconds_remaining / SECONDS_PER_YEAR
|
|
59
|
+
*/
|
|
60
|
+
function normalizedTimeRemaining(secondsRemaining) {
|
|
61
|
+
return secondsRemaining / SECONDS_PER_YEAR;
|
|
62
|
+
}
|
|
63
|
+
exports.normalizedTimeRemaining = normalizedTimeRemaining;
|
|
64
|
+
/**
|
|
65
|
+
* Calculate current fee rate from fee rate root and time remaining
|
|
66
|
+
* fee_rate = e^(ln_fee_rate_root * time_factor)
|
|
67
|
+
*/
|
|
68
|
+
function calculateFeeRate(lnFeeRateRoot, secondsRemaining) {
|
|
69
|
+
const timeFactor = normalizedTimeRemaining(secondsRemaining);
|
|
70
|
+
return Math.exp(lnFeeRateRoot * timeFactor);
|
|
71
|
+
}
|
|
72
|
+
exports.calculateFeeRate = calculateFeeRate;
|
|
73
|
+
/**
|
|
74
|
+
* Calculate fee from amount
|
|
75
|
+
* Returns the fee to charge given an amount and fee rate
|
|
76
|
+
* fee = amount * (fee_rate - 1.0)
|
|
77
|
+
*/
|
|
78
|
+
function getFeeFromAmount(amount, feeRate) {
|
|
79
|
+
return Math.ceil(amount * (feeRate - 1.0));
|
|
80
|
+
}
|
|
81
|
+
exports.getFeeFromAmount = getFeeFromAmount;
|
|
82
|
+
/**
|
|
83
|
+
* Find the active liquidity at a given tick index
|
|
84
|
+
* This is computed by summing liquidity_net up to the current tick
|
|
85
|
+
*/
|
|
86
|
+
function getActiveLiquidity(ticks, tickIndex) {
|
|
87
|
+
let activeLiquidity = 0n;
|
|
88
|
+
// Sum all liquidity_net from ticks up to and including tickIndex
|
|
89
|
+
for (const tick of ticks.ticksTree) {
|
|
90
|
+
if (tick.apyBasePoints <= tickIndex) {
|
|
91
|
+
activeLiquidity += tick.liquidityNet;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return activeLiquidity;
|
|
95
|
+
}
|
|
96
|
+
exports.getActiveLiquidity = getActiveLiquidity;
|
|
97
|
+
/**
|
|
98
|
+
* Find the successor tick (next tick to the right)
|
|
99
|
+
* In Rust: ticks.successor_idx(current_left_boundary_index)
|
|
100
|
+
* @param ticks - The ticks data structure
|
|
101
|
+
* @param currentTickKey - The current tick key (apyBasePoints)
|
|
102
|
+
* @returns The next tick key (apyBasePoints) or null if none exists
|
|
103
|
+
*/
|
|
104
|
+
function getSuccessorTickKey(ticks, currentTickKey) {
|
|
105
|
+
let minKey = null;
|
|
106
|
+
for (const tick of ticks.ticksTree) {
|
|
107
|
+
if (tick.apyBasePoints > currentTickKey) {
|
|
108
|
+
if (minKey === null || tick.apyBasePoints < minKey) {
|
|
109
|
+
minKey = tick.apyBasePoints;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return minKey;
|
|
114
|
+
}
|
|
115
|
+
exports.getSuccessorTickKey = getSuccessorTickKey;
|
|
116
|
+
/**
|
|
117
|
+
* Find the successor tick by index in the tick tree
|
|
118
|
+
* This is almost equivalent to the Rust successor_idx method
|
|
119
|
+
*/
|
|
120
|
+
function getSuccessorTickByIdx(ticks, tickIdx) {
|
|
121
|
+
//TODO Refactor to make it more CPU efficient
|
|
122
|
+
const tick = ticks.ticksTree.at(tickIdx - 1) ?? null;
|
|
123
|
+
if (!tick)
|
|
124
|
+
return null;
|
|
125
|
+
// Find ticks with apyBasePoints greater than tickIdx
|
|
126
|
+
const successorTicks = ticks.ticksTree
|
|
127
|
+
.filter((t) => t.apyBasePoints > tick.apyBasePoints)
|
|
128
|
+
.sort((a, b) => a.apyBasePoints - b.apyBasePoints);
|
|
129
|
+
const successorTick = successorTicks.at(0) ?? null;
|
|
130
|
+
return !!successorTick ? ticks.ticksTree.indexOf(successorTick) + 1 : null;
|
|
131
|
+
}
|
|
132
|
+
exports.getSuccessorTickByIdx = getSuccessorTickByIdx;
|
|
133
|
+
/**
|
|
134
|
+
* Find the predecessor tick (next tick to the left)
|
|
135
|
+
* In Rust: ticks.predecessor_idx(current_left_boundary_index)
|
|
136
|
+
* @param ticks - The ticks data structure
|
|
137
|
+
* @param currentTickKey - The current tick key (apyBasePoints)
|
|
138
|
+
* @returns The previous tick key (apyBasePoints) or null if none exists
|
|
139
|
+
*/
|
|
140
|
+
function getPredecessorTickKey(ticks, currentTickKey) {
|
|
141
|
+
let maxKey = null;
|
|
142
|
+
for (const tick of ticks.ticksTree) {
|
|
143
|
+
if (tick.apyBasePoints < currentTickKey) {
|
|
144
|
+
if (maxKey === null || tick.apyBasePoints > maxKey) {
|
|
145
|
+
maxKey = tick.apyBasePoints;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return maxKey;
|
|
150
|
+
}
|
|
151
|
+
exports.getPredecessorTickKey = getPredecessorTickKey;
|
|
152
|
+
/**
|
|
153
|
+
* Get the spot price (implied rate) for a tick key
|
|
154
|
+
* Tick key represents APY in parts per million (1e6)
|
|
155
|
+
* spot_price = 1 + tick_key / 1e6
|
|
156
|
+
*
|
|
157
|
+
* This is equivalent to the Rust code:
|
|
158
|
+
* let spot_price = (1.0 + (key as f64) / TICK_KEY_BASE_POINTS);
|
|
159
|
+
* But Rust stores it pre-computed, we compute it here
|
|
160
|
+
*/
|
|
161
|
+
function getImpliedRate(tickKey) {
|
|
162
|
+
const TICK_KEY_BASE_POINTS = 1_000_000;
|
|
163
|
+
return 1.0 + tickKey / TICK_KEY_BASE_POINTS;
|
|
164
|
+
}
|
|
165
|
+
exports.getImpliedRate = getImpliedRate;
|
|
166
|
+
/**
|
|
167
|
+
* Find a tick by its key
|
|
168
|
+
*/
|
|
169
|
+
function findTickByKey(ticks, tickKey) {
|
|
170
|
+
const index = ticks.ticksTree.findIndex((t) => t.apyBasePoints === tickKey);
|
|
171
|
+
if (index === -1)
|
|
172
|
+
return null;
|
|
173
|
+
return { tick: ticks.ticksTree[index - 1], index };
|
|
174
|
+
}
|
|
175
|
+
exports.findTickByKey = findTickByKey;
|
|
176
|
+
/**
|
|
177
|
+
* Find a tick by its index
|
|
178
|
+
*/
|
|
179
|
+
function findTickByIndex(ticks, index) {
|
|
180
|
+
return ticks.ticksTree.at(index - 1) ?? null;
|
|
181
|
+
}
|
|
182
|
+
exports.findTickByIndex = findTickByIndex;
|
|
183
|
+
/**
|
|
184
|
+
* Convert APY percentage to basis points
|
|
185
|
+
*/
|
|
186
|
+
function convertApyToApyBp(apyPercent) {
|
|
187
|
+
return Math.round(apyPercent * 100);
|
|
188
|
+
}
|
|
189
|
+
exports.convertApyToApyBp = convertApyToApyBp;
|
|
190
|
+
/**
|
|
191
|
+
* Convert basis points to APY percentage
|
|
192
|
+
*/
|
|
193
|
+
function convertApyBpToApy(apyBp) {
|
|
194
|
+
return apyBp / 100;
|
|
195
|
+
}
|
|
196
|
+
exports.convertApyBpToApy = convertApyBpToApy;
|
|
197
|
+
function bigIntMax(...args) {
|
|
198
|
+
return args.reduce((m, e) => (e > m ? e : m));
|
|
199
|
+
}
|
|
200
|
+
exports.bigIntMax = bigIntMax;
|
|
201
|
+
function bigIntMin(...args) {
|
|
202
|
+
return args.reduce((m, e) => (e < m ? e : m));
|
|
203
|
+
}
|
|
204
|
+
exports.bigIntMin = bigIntMin;
|
|
205
|
+
/**
|
|
206
|
+
* Calculate PT price in asset from current spot price and expiration timestamp
|
|
207
|
+
* @param currentSpotPrice - Current spot price in format of 1 + percentage / 100
|
|
208
|
+
* @param expirationTs - Expiration timestamp in seconds
|
|
209
|
+
* @returns PT price in asset
|
|
210
|
+
*/
|
|
211
|
+
function calcPtPriceInAsset(currentSpotPrice, expirationTs) {
|
|
212
|
+
const impliedApy = currentSpotPrice - 1;
|
|
213
|
+
const secondsRemaining = Math.max(0, expirationTs);
|
|
214
|
+
const SECONDS_PER_YEAR = 365 * 86400;
|
|
215
|
+
const ptPriceInAsset = Math.exp(Math.log(1 + impliedApy) * (-secondsRemaining / SECONDS_PER_YEAR));
|
|
216
|
+
return ptPriceInAsset;
|
|
217
|
+
}
|
|
218
|
+
exports.calcPtPriceInAsset = calcPtPriceInAsset;
|
|
219
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAMA,MAAM,gBAAgB,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;AAC3C,4BAA4B;AAE5B;;;;GAIG;AACH,MAAa,OAAO;IAClB,oDAAoD;IACpD,UAAU,CAAQ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gB,kBAAkB,CAAC,gBAAwB,EAAE,YAAoB;IAC/E,MAAM,UAAU,GAAG,gBAAgB,GAAG,CAAC,CAAA;IACvC,MAAM,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,CAAA;IAClD,MAAM,gBAAgB,GAAG,GAAG,GAAG,KAAK,CAAA;IACpC,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAA;IAClG,OAAO,cAAc,CAAA;AACvB,CAAC;AAND,gDAMC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities V2 for CLMM calculations
|
|
3
|
+
* More closely mirrors the Rust on-chain implementation
|
|
4
|
+
* Uses tick key (apyBasePoints) as the primary identifier instead of array index
|
|
5
|
+
*/
|
|
6
|
+
import { Tick, Ticks } from "@exponent-labs/exponent-fetcher";
|
|
7
|
+
/**
|
|
8
|
+
* Effective price snapshot
|
|
9
|
+
* Matches the Rust EffSnap struct
|
|
10
|
+
*/
|
|
11
|
+
export declare class EffSnap {
|
|
12
|
+
timeFactor: number;
|
|
13
|
+
syExchangeRate: number;
|
|
14
|
+
constructor(timeFactor: number, syExchangeRate: number);
|
|
15
|
+
/**
|
|
16
|
+
* Calculate effective price from spot price
|
|
17
|
+
* Rust: C(u) = u^(-(τ-1)) / (r * (τ - 1))
|
|
18
|
+
*/
|
|
19
|
+
getEffectivePrice(u: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Convert effective price back to spot price
|
|
22
|
+
* Rust: u = (r * C * (τ - 1))^(1/(1-τ))
|
|
23
|
+
*/
|
|
24
|
+
spotPriceFromEffectivePrice(cEff: number): number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* TicksWrapper - wraps the ticks array and provides RB-tree-like operations
|
|
28
|
+
* This simulates the Rust RB-tree behavior using a sorted map
|
|
29
|
+
*/
|
|
30
|
+
export declare class TicksWrapper {
|
|
31
|
+
private ticksByKey;
|
|
32
|
+
private sortedKeys;
|
|
33
|
+
currentSpotPrice: number;
|
|
34
|
+
currentTickKey: number;
|
|
35
|
+
currentPrefixSum: bigint;
|
|
36
|
+
feeGrowthIndexGlobalPt: bigint;
|
|
37
|
+
feeGrowthIndexGlobalSy: bigint;
|
|
38
|
+
constructor(ticks: Ticks);
|
|
39
|
+
/**
|
|
40
|
+
* Find tick key by spot price (for initialization)
|
|
41
|
+
*/
|
|
42
|
+
private findTickKeyBySpotPrice;
|
|
43
|
+
/**
|
|
44
|
+
* Get tick by key (apyBasePoints)
|
|
45
|
+
* Equivalent to Rust's ticks_tree.get_node(idx).value
|
|
46
|
+
*/
|
|
47
|
+
getTickByKey(key: number): Tick | null;
|
|
48
|
+
/**
|
|
49
|
+
* Get spot price for a tick key
|
|
50
|
+
* Equivalent to Rust's ticks.get_spot_price(idx)
|
|
51
|
+
* In Rust: spot_price = 1.0 + key / TICK_KEY_BASE_POINTS
|
|
52
|
+
*/
|
|
53
|
+
getSpotPrice(key: number): number;
|
|
54
|
+
/**
|
|
55
|
+
* Find successor key (next tick with greater apyBasePoints)
|
|
56
|
+
* Equivalent to Rust's ticks.successor_idx(idx)
|
|
57
|
+
*/
|
|
58
|
+
successorKey(currentKey: number): number | null;
|
|
59
|
+
/**
|
|
60
|
+
* Find predecessor key (previous tick with smaller apyBasePoints)
|
|
61
|
+
* Equivalent to Rust's ticks.predecessor_idx(idx)
|
|
62
|
+
*/
|
|
63
|
+
predecessorKey(currentKey: number): number | null;
|
|
64
|
+
/**
|
|
65
|
+
* Get principal values for a tick
|
|
66
|
+
*/
|
|
67
|
+
getPrincipals(key: number): {
|
|
68
|
+
principalPt: bigint;
|
|
69
|
+
principalSy: bigint;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Get liquidity net for a tick
|
|
73
|
+
*/
|
|
74
|
+
getLiquidityNet(key: number): bigint;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Calculate normalized time remaining
|
|
78
|
+
*/
|
|
79
|
+
export declare function normalizedTimeRemaining(secondsRemaining: number): number;
|
|
80
|
+
/**
|
|
81
|
+
* Calculate current fee rate
|
|
82
|
+
*/
|
|
83
|
+
export declare function calculateFeeRate(lnFeeRateRoot: number, secondsRemaining: number): number;
|
|
84
|
+
/**
|
|
85
|
+
* Calculate fee from amount
|
|
86
|
+
* Mirrors Rust: ((amount as f64) * (fee_rate - 1.0)).ceil() as u64
|
|
87
|
+
*/
|
|
88
|
+
export declare function getFeeFromAmount(amount: number, feeRate: number): number;
|