@exponent-labs/market-three-math 0.1.8 → 0.9.1
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 +762 -36
- package/build/addLiquidity.js.map +1 -1
- package/build/bisect.d.ts +11 -0
- package/build/bisect.js +22 -12
- 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 +57 -12
- package/build/liquidityHistogram.js.map +1 -1
- package/build/quote.d.ts +1 -1
- package/build/quote.js +70 -84
- package/build/quote.js.map +1 -1
- package/build/swap.js +36 -18
- package/build/swap.js.map +1 -1
- package/build/swapV2.d.ts +6 -1
- package/build/swapV2.js +394 -52
- 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 +37 -19
- package/build/utils.js.map +1 -1
- package/build/utilsV2.d.ts +9 -0
- package/build/utilsV2.js +131 -9
- package/build/utilsV2.js.map +1 -1
- package/build/withdrawLiquidity.js +12 -7
- package/build/withdrawLiquidity.js.map +1 -1
- package/build/ytTrades.d.ts +7 -0
- package/build/ytTrades.js +166 -146
- package/build/ytTrades.js.map +1 -1
- package/build/ytTradesLegacy.js +3 -4
- package/build/ytTradesLegacy.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/build/swapLegacy.d.ts +0 -16
- package/build/swapLegacy.js +0 -229
- package/build/swapLegacy.js.map +0 -1
- package/src/swapLegacy.ts +0 -272
package/build/ytTrades.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.simulateBuyYt = simulateBuyYt;
|
|
4
|
+
exports.simulateBuyYtWithSyIn = simulateBuyYtWithSyIn;
|
|
5
|
+
exports.simulateSellYt = simulateSellYt;
|
|
4
6
|
/**
|
|
5
7
|
* YT (Yield Token) trade simulations
|
|
6
8
|
*
|
|
@@ -9,19 +11,30 @@ exports.simulateSellYt = exports.simulateBuyYtWithSyIn = exports.simulateBuyYt =
|
|
|
9
11
|
* - Sell YT: Merge PT+YT → SY, then buy PT from pool to repay
|
|
10
12
|
*/
|
|
11
13
|
const bisect_1 = require("./bisect");
|
|
12
|
-
const
|
|
14
|
+
const swapV2_1 = require("./swapV2");
|
|
13
15
|
const types_1 = require("./types");
|
|
14
16
|
/**
|
|
15
|
-
* Helper function to convert PY to SY
|
|
16
|
-
* @param syExchangeRate - The SY exchange rate
|
|
17
|
+
* Helper function to convert PY to SY (floor)
|
|
18
|
+
* @param syExchangeRate - The SY exchange rate (SY value in terms of underlying)
|
|
17
19
|
* @param pyAmount - The PY (PT or YT) amount
|
|
18
|
-
* @returns The equivalent SY amount
|
|
20
|
+
* @returns The equivalent SY amount (floored)
|
|
19
21
|
*/
|
|
20
22
|
function pyToSy(syExchangeRate, pyAmount) {
|
|
21
23
|
if (syExchangeRate <= 0)
|
|
22
24
|
return 0;
|
|
23
25
|
return Math.floor(pyAmount / syExchangeRate);
|
|
24
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Helper function to convert PY to SY (ceil) - for when you need AT LEAST this much SY
|
|
29
|
+
* @param syExchangeRate - The SY exchange rate
|
|
30
|
+
* @param pyAmount - The PY (PT or YT) amount
|
|
31
|
+
* @returns The equivalent SY amount (ceiled)
|
|
32
|
+
*/
|
|
33
|
+
function pyToSyCeil(syExchangeRate, pyAmount) {
|
|
34
|
+
if (syExchangeRate <= 0)
|
|
35
|
+
return 0;
|
|
36
|
+
return Math.ceil(pyAmount / syExchangeRate);
|
|
37
|
+
}
|
|
25
38
|
/**
|
|
26
39
|
* Helper function to convert SY to PY
|
|
27
40
|
* @param syExchangeRate - The SY exchange rate
|
|
@@ -47,13 +60,12 @@ function syToPy(syExchangeRate, syAmount) {
|
|
|
47
60
|
function simulateBuyYt(marketState, args) {
|
|
48
61
|
const { ytOut, syExchangeRate, priceSpotLimit } = args;
|
|
49
62
|
// Calculate how much SY needs to be stripped to get the desired YT
|
|
50
|
-
//
|
|
51
|
-
const syToStrip =
|
|
52
|
-
// Stripping gives
|
|
63
|
+
// Use ceiling to ensure we strip enough SY
|
|
64
|
+
const syToStrip = pyToSyCeil(syExchangeRate, ytOut);
|
|
65
|
+
// Stripping gives equal amounts of PT and YT (1:1 ratio based on underlying value)
|
|
53
66
|
const ptFromStrip = ytOut;
|
|
54
67
|
// Simulate selling the PT to get SY back
|
|
55
|
-
|
|
56
|
-
const swapResult = (0, swap_1.simulateSwap)(marketState, {
|
|
68
|
+
const swapResult = (0, swapV2_1.simulateSwap)(marketState, {
|
|
57
69
|
direction: types_1.SwapDirection.PtToSy,
|
|
58
70
|
amountIn: ytOut,
|
|
59
71
|
priceSpotLimit,
|
|
@@ -74,7 +86,22 @@ function simulateBuyYt(marketState, args) {
|
|
|
74
86
|
finalSpotPrice: swapResult.finalSpotPrice,
|
|
75
87
|
};
|
|
76
88
|
}
|
|
77
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Helper to calculate net SY cost for a given YT amount
|
|
91
|
+
*/
|
|
92
|
+
function calculateNetSyCost(marketState, ytAmount, syExchangeRate, priceSpotLimit) {
|
|
93
|
+
const syToStrip = pyToSyCeil(syExchangeRate, ytAmount);
|
|
94
|
+
const swapResult = (0, swapV2_1.simulateSwap)(marketState, {
|
|
95
|
+
direction: types_1.SwapDirection.PtToSy,
|
|
96
|
+
amountIn: ytAmount,
|
|
97
|
+
priceSpotLimit,
|
|
98
|
+
syExchangeRate,
|
|
99
|
+
isCurrentFlashSwap: true,
|
|
100
|
+
});
|
|
101
|
+
const syFromPtSale = swapResult.amountOut;
|
|
102
|
+
const netSyCost = syToStrip - syFromPtSale;
|
|
103
|
+
return { netSyCost, syToStrip, syFromPtSale };
|
|
104
|
+
}
|
|
78
105
|
/**
|
|
79
106
|
* Simulates buying YT tokens given a SY input amount
|
|
80
107
|
*
|
|
@@ -93,121 +120,140 @@ exports.simulateBuyYt = simulateBuyYt;
|
|
|
93
120
|
*/
|
|
94
121
|
function simulateBuyYtWithSyIn(marketState, args) {
|
|
95
122
|
const { syIn, syExchangeRate, priceSpotLimit } = args;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//
|
|
123
|
+
if (syIn <= 0) {
|
|
124
|
+
throw new Error("syIn must be positive");
|
|
125
|
+
}
|
|
126
|
+
if (syExchangeRate <= 0) {
|
|
127
|
+
throw new Error("syExchangeRate must be positive");
|
|
128
|
+
}
|
|
129
|
+
// Lower bound: minimum meaningful YT amount
|
|
103
130
|
const minPossibleYt = 1;
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
const marketPtLiquidity = Number(marketState.financials.ptBalance);
|
|
131
|
+
// Buy-YT uses a flash-swap PT->SY path, so the tradeable size is determined by active
|
|
132
|
+
// tick liquidity, not by the idle PT balance stored on the market account.
|
|
107
133
|
const marketSyLiquidity = Number(marketState.financials.syBalance);
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
134
|
+
// Calculate cost at minimum YT to verify function behavior
|
|
135
|
+
let minCost;
|
|
136
|
+
try {
|
|
137
|
+
const minResult = calculateNetSyCost(marketState, minPossibleYt, syExchangeRate, priceSpotLimit);
|
|
138
|
+
minCost = minResult.netSyCost;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
throw new Error("Market cannot support even minimum YT trade");
|
|
142
|
+
}
|
|
143
|
+
// If minimum cost already exceeds syIn, we can't do this trade
|
|
144
|
+
if (minCost > syIn) {
|
|
145
|
+
throw new Error(`Trade too small: minimum YT (${minPossibleYt}) costs ${minCost} SY, but only ${syIn} SY available`);
|
|
146
|
+
}
|
|
147
|
+
// Find upper bound using exponential search
|
|
148
|
+
// We need to find ytMax where netSyCost(ytMax) > syIn
|
|
149
|
+
let maxPossibleYt = Math.max(minPossibleYt + 1, syToPy(syExchangeRate, syIn)); // Start with naive estimate
|
|
116
150
|
let foundUpperBound = false;
|
|
117
|
-
let
|
|
118
|
-
|
|
119
|
-
|
|
151
|
+
let lastValidYt = minPossibleYt;
|
|
152
|
+
let lastValidCost = minCost;
|
|
153
|
+
// Exponential search to find upper bound
|
|
154
|
+
const maxAttempts = 40;
|
|
155
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
156
|
+
const testYt = Math.max(minPossibleYt + 1, Math.floor(maxPossibleYt));
|
|
120
157
|
try {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
priceSpotLimit,
|
|
126
|
-
syExchangeRate,
|
|
127
|
-
isCurrentFlashSwap: true,
|
|
128
|
-
});
|
|
129
|
-
const syFromPtSale = swapResult.amountOut;
|
|
130
|
-
const netSyCost = syToStrip - syFromPtSale;
|
|
131
|
-
// If this costs more than syIn, we found our upper bound
|
|
132
|
-
if (netSyCost > syIn) {
|
|
133
|
-
foundUpperBound = true;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
lastValidCost = netSyCost;
|
|
137
|
-
// Use adaptive growth rate based on how far we are from target
|
|
138
|
-
const costRatio = syIn / Math.max(netSyCost, 1);
|
|
139
|
-
const growthFactor = attempt < 3 ? 2.0 : Math.min(1.5, 1 + costRatio * 0.3);
|
|
140
|
-
maxPossibleYt *= growthFactor;
|
|
141
|
-
// Don't exceed liquidity constraints
|
|
142
|
-
if (maxPossibleYt > liquidityBasedMax) {
|
|
143
|
-
maxPossibleYt = liquidityBasedMax;
|
|
158
|
+
const result = calculateNetSyCost(marketState, testYt, syExchangeRate, priceSpotLimit);
|
|
159
|
+
if (result.netSyCost > syIn) {
|
|
160
|
+
// Found upper bound
|
|
161
|
+
maxPossibleYt = testYt;
|
|
144
162
|
foundUpperBound = true;
|
|
145
163
|
break;
|
|
146
164
|
}
|
|
165
|
+
// This YT amount is still affordable, save it
|
|
166
|
+
lastValidYt = testYt;
|
|
167
|
+
lastValidCost = result.netSyCost;
|
|
168
|
+
// Increase estimate using adaptive growth
|
|
169
|
+
// The closer lastValidCost is to syIn, the smaller the growth factor
|
|
170
|
+
const remainingBudget = syIn - lastValidCost;
|
|
171
|
+
const growthFactor = Math.max(1.5, Math.min(3, 1 + remainingBudget / Math.max(lastValidCost, 1)));
|
|
172
|
+
maxPossibleYt = Math.ceil(testYt * growthFactor);
|
|
147
173
|
}
|
|
148
174
|
catch (error) {
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
175
|
+
// Swap failed - we've exceeded what the market can handle
|
|
176
|
+
if (lastValidYt > minPossibleYt) {
|
|
177
|
+
// Use binary search between lastValidYt and testYt to find exact upper bound
|
|
178
|
+
let searchLo = lastValidYt;
|
|
179
|
+
let searchHi = testYt;
|
|
180
|
+
for (let i = 0; i < 10; i++) {
|
|
181
|
+
const mid = Math.floor((searchLo + searchHi) / 2);
|
|
182
|
+
try {
|
|
183
|
+
const midResult = calculateNetSyCost(marketState, mid, syExchangeRate, priceSpotLimit);
|
|
184
|
+
if (midResult.netSyCost > syIn) {
|
|
185
|
+
searchHi = mid;
|
|
186
|
+
foundUpperBound = true;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
searchLo = mid;
|
|
190
|
+
lastValidYt = mid;
|
|
191
|
+
lastValidCost = midResult.netSyCost;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
searchHi = mid;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (foundUpperBound) {
|
|
199
|
+
maxPossibleYt = searchHi;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
// Couldn't find upper bound - trade exceeds market capacity
|
|
203
|
+
throw new Error(`Trade exceeds market capacity: max affordable YT is ~${lastValidYt} (cost: ${lastValidCost}), ` +
|
|
204
|
+
`syIn = ${syIn}`);
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
155
207
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
208
|
+
// Re-throw if we haven't found any valid YT amount
|
|
209
|
+
if (error instanceof Error) {
|
|
210
|
+
throw error;
|
|
159
211
|
}
|
|
160
|
-
|
|
161
|
-
break;
|
|
212
|
+
throw new Error("Failed to find valid YT range");
|
|
162
213
|
}
|
|
163
214
|
}
|
|
164
215
|
if (!foundUpperBound) {
|
|
165
|
-
throw new Error(`Could not find upper bound for YT amount
|
|
216
|
+
throw new Error(`Could not find upper bound for YT amount after ${maxAttempts} attempts. ` +
|
|
217
|
+
`Last valid: ${lastValidYt} (cost: ${lastValidCost}), syIn: ${syIn}`);
|
|
166
218
|
}
|
|
167
|
-
//
|
|
219
|
+
// Sanity check bounds
|
|
168
220
|
if (maxPossibleYt <= minPossibleYt) {
|
|
169
|
-
|
|
221
|
+
throw new Error(`Invalid bounds: min=${minPossibleYt}, max=${maxPossibleYt}`);
|
|
170
222
|
}
|
|
171
223
|
// Use bisection search to find the ytOut that results in netSyCost = syIn
|
|
172
|
-
//
|
|
173
|
-
const adaptiveEpsilon = Math.max(
|
|
174
|
-
|
|
175
|
-
const maxIterations = 10000;
|
|
176
|
-
// Debug info for bounds validation
|
|
177
|
-
if (maxPossibleYt <= minPossibleYt) {
|
|
178
|
-
throw new Error(`Invalid bisection bounds for buy YT. ` +
|
|
179
|
-
`Min: ${minPossibleYt}, Max: ${maxPossibleYt}, ` +
|
|
180
|
-
`SyIn: ${syIn}, SyExchangeRate: ${syExchangeRate}, ` +
|
|
181
|
-
`MarketPtBalance: ${marketPtLiquidity}, MarketSyBalance: ${marketSyLiquidity}`);
|
|
182
|
-
}
|
|
224
|
+
// Epsilon should be small relative to the expected result magnitude
|
|
225
|
+
const adaptiveEpsilon = Math.max(1, syIn * 0.0001);
|
|
226
|
+
const maxIterations = 100; // Bisection converges fast with good bounds
|
|
183
227
|
const ytOut = (0, bisect_1.bisectSearch2)((ytGuess) => {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const swapResult = (0, swap_1.simulateSwap)(marketState, {
|
|
187
|
-
direction: types_1.SwapDirection.PtToSy,
|
|
188
|
-
amountIn: ytGuess,
|
|
189
|
-
priceSpotLimit,
|
|
190
|
-
syExchangeRate,
|
|
191
|
-
isCurrentFlashSwap: true,
|
|
192
|
-
});
|
|
193
|
-
const syFromPtSale = swapResult.amountOut;
|
|
194
|
-
const netSyCost = syToStrip - syFromPtSale;
|
|
195
|
-
// Return the difference between actual cost and target syIn
|
|
196
|
-
return netSyCost - syIn;
|
|
228
|
+
const result = calculateNetSyCost(marketState, ytGuess, syExchangeRate, priceSpotLimit);
|
|
229
|
+
return result.netSyCost - syIn;
|
|
197
230
|
}, minPossibleYt, maxPossibleYt, adaptiveEpsilon, maxIterations);
|
|
198
231
|
if (ytOut === null) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
232
|
+
// This shouldn't happen if bounds are correct
|
|
233
|
+
// Provide detailed debug info
|
|
234
|
+
const minResult = calculateNetSyCost(marketState, minPossibleYt, syExchangeRate, priceSpotLimit);
|
|
235
|
+
let maxResult = null;
|
|
236
|
+
try {
|
|
237
|
+
maxResult = calculateNetSyCost(marketState, maxPossibleYt, syExchangeRate, priceSpotLimit);
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
// Max might fail
|
|
241
|
+
}
|
|
242
|
+
throw new Error(`Failed to converge: bounds [${minPossibleYt}, ${maxPossibleYt}], ` +
|
|
243
|
+
`f(min)=${minResult.netSyCost - syIn}, f(max)=${maxResult ? maxResult.netSyCost - syIn : "error"}, ` +
|
|
244
|
+
`syIn=${syIn}, epsilon=${adaptiveEpsilon}`);
|
|
202
245
|
}
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
ytOut,
|
|
246
|
+
// Return full result using the found ytOut
|
|
247
|
+
const result = simulateBuyYt(marketState, {
|
|
248
|
+
ytOut: Math.floor(ytOut), // Floor to ensure we don't over-promise
|
|
206
249
|
syExchangeRate,
|
|
207
250
|
priceSpotLimit,
|
|
208
251
|
});
|
|
252
|
+
if (marketSyLiquidity * syExchangeRate < result.ytOut * 2) {
|
|
253
|
+
throw new Error(`Insufficient SY liquidity in the market. Required: ${result.ytOut * 2}, Available: ${marketSyLiquidity}`);
|
|
254
|
+
}
|
|
255
|
+
return result;
|
|
209
256
|
}
|
|
210
|
-
exports.simulateBuyYtWithSyIn = simulateBuyYtWithSyIn;
|
|
211
257
|
/**
|
|
212
258
|
* Simulates selling YT tokens
|
|
213
259
|
*
|
|
@@ -224,60 +270,35 @@ exports.simulateBuyYtWithSyIn = simulateBuyYtWithSyIn;
|
|
|
224
270
|
* @returns Simulation result with net SY received
|
|
225
271
|
*/
|
|
226
272
|
function simulateSellYt(marketState, args) {
|
|
227
|
-
const { ytIn, syExchangeRate, priceSpotLimit } = args;
|
|
273
|
+
const { ytIn, syExchangeRate, priceSpotLimit, safetyMarginBps = 0 } = args;
|
|
274
|
+
if (ytIn <= 0) {
|
|
275
|
+
throw new Error("ytIn must be positive");
|
|
276
|
+
}
|
|
228
277
|
// Check if there's sufficient PT liquidity
|
|
229
|
-
|
|
230
|
-
if (
|
|
231
|
-
throw new Error(`Insufficient PT liquidity in the market. Required: ${ytIn * 2}, Available: ${
|
|
278
|
+
const marketPtBalance = Number(marketState.financials.ptBalance);
|
|
279
|
+
if (marketPtBalance < ytIn * 2) {
|
|
280
|
+
throw new Error(`Insufficient PT liquidity in the market. Required: ${ytIn * 2}, Available: ${marketPtBalance}`);
|
|
232
281
|
}
|
|
233
|
-
// Merging PT + YT gives back the original SY
|
|
234
|
-
// The amount of PT needed equals ytIn (1:1 ratio)
|
|
282
|
+
// Merging PT + YT gives back the original SY (floor since you can't get fractional SY)
|
|
235
283
|
const syFromMerge = pyToSy(syExchangeRate, ytIn);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
direction: types_1.SwapDirection.SyToPt,
|
|
239
|
-
amountIn: syFromMerge,
|
|
240
|
-
priceSpotLimit,
|
|
241
|
-
syExchangeRate,
|
|
242
|
-
isCurrentFlashSwap: true,
|
|
243
|
-
});
|
|
244
|
-
// Check that we can buy enough PT from CLMM
|
|
245
|
-
if (upperBoundSwap.amountOut < ptNeeded) {
|
|
246
|
-
throw new Error(`Cannot buy enough PT with available SY. Need ${ytIn} PT but can only afford ${upperBoundSwap.amountOut} PT`);
|
|
284
|
+
if (syFromMerge <= 0) {
|
|
285
|
+
throw new Error(`Trade too small: merging ${ytIn} YT yields 0 SY`);
|
|
247
286
|
}
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
//
|
|
251
|
-
const
|
|
252
|
-
// Adaptive epsilon based on PT needed
|
|
253
|
-
const adaptiveEpsilon = Math.max(0.01, ptNeeded * 0.0001);
|
|
254
|
-
// Safety check: ensure lower bound is less than upper bound
|
|
255
|
-
const safeLowerBound = Math.min(estimatedLowerBound, syFromMerge * 0.95);
|
|
256
|
-
const safeUpperBound = syFromMerge;
|
|
257
|
-
if (safeLowerBound >= safeUpperBound) {
|
|
258
|
-
throw new Error(`Invalid bisection bounds for sell YT. Lower: ${safeLowerBound}, Upper: ${safeUpperBound}`);
|
|
259
|
-
}
|
|
260
|
-
const syToSpend = (0, bisect_1.bisectSearch2)((syGuess) => {
|
|
261
|
-
const swapResult = (0, swap_1.simulateSwap)(marketState, {
|
|
262
|
-
direction: types_1.SwapDirection.SyToPt,
|
|
263
|
-
amountIn: syGuess,
|
|
264
|
-
priceSpotLimit,
|
|
265
|
-
syExchangeRate,
|
|
266
|
-
isCurrentFlashSwap: true,
|
|
267
|
-
});
|
|
268
|
-
return swapResult.amountOut - ptNeeded;
|
|
269
|
-
}, safeLowerBound, safeUpperBound, adaptiveEpsilon, 100);
|
|
270
|
-
if (syToSpend === null) {
|
|
271
|
-
throw new Error("Failed to converge on correct SY amount using bisection search");
|
|
272
|
-
}
|
|
273
|
-
const swapResult = (0, swap_1.simulateSwap)(marketState, {
|
|
287
|
+
// On-chain uses pt_constraint + 2 to account for rounding, so we match that behavior
|
|
288
|
+
const ptNeeded = ytIn + 2;
|
|
289
|
+
// Match on-chain SellYt exactly: TradePtExactOut with pt_target = yt_in + 2 and SY budget = syFromMerge
|
|
290
|
+
const swapResult = (0, swapV2_1.simulateSwapExactOut)(marketState, {
|
|
274
291
|
direction: types_1.SwapDirection.SyToPt,
|
|
275
|
-
|
|
292
|
+
amountOut: ptNeeded,
|
|
276
293
|
priceSpotLimit,
|
|
277
294
|
syExchangeRate,
|
|
278
295
|
isCurrentFlashSwap: true,
|
|
296
|
+
amountInConstraint: syFromMerge,
|
|
279
297
|
});
|
|
280
|
-
|
|
298
|
+
// Optional conservative output buffer.
|
|
299
|
+
const rawNetSyReceived = syFromMerge - swapResult.amountInConsumed;
|
|
300
|
+
const safetyDeduction = safetyMarginBps > 0 ? Math.ceil((rawNetSyReceived * safetyMarginBps) / 10000) : 0;
|
|
301
|
+
const netSyReceived = rawNetSyReceived - safetyDeduction;
|
|
281
302
|
return {
|
|
282
303
|
ytIn,
|
|
283
304
|
netSyReceived,
|
|
@@ -288,5 +309,4 @@ function simulateSellYt(marketState, args) {
|
|
|
288
309
|
finalSpotPrice: swapResult.finalSpotPrice,
|
|
289
310
|
};
|
|
290
311
|
}
|
|
291
|
-
exports.simulateSellYt = simulateSellYt;
|
|
292
312
|
//# sourceMappingURL=ytTrades.js.map
|
package/build/ytTrades.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ytTrades.js","sourceRoot":"","sources":["../src/ytTrades.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ytTrades.js","sourceRoot":"","sources":["../src/ytTrades.ts"],"names":[],"mappings":";;AAoFA,sCAkCC;AAoDD,sDA0KC;AAkDD,wCA+CC;AArbD;;;;;;GAMG;AACH,qCAAwC;AACxC,qCAA6D;AAC7D,mCAAwE;AAExE;;;;;GAKG;AACH,SAAS,MAAM,CAAC,cAAsB,EAAE,QAAgB;IACtD,IAAI,cAAc,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,cAAc,CAAC,CAAA;AAC9C,CAAC;AAED;;;;;GAKG;AACH,SAAS,UAAU,CAAC,cAAsB,EAAE,QAAgB;IAC1D,IAAI,cAAc,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IACjC,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC,CAAA;AAC7C,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,cAAsB,EAAE,QAAgB;IACtD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,cAAc,CAAC,CAAA;AAC9C,CAAC;AA8BD;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAAC,WAA6B,EAAE,IAAyB;IACpF,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,IAAI,CAAA;IAEtD,mEAAmE;IACnE,2CAA2C;IAC3C,MAAM,SAAS,GAAG,UAAU,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;IAEnD,mFAAmF;IACnF,MAAM,WAAW,GAAG,KAAK,CAAA;IAEzB,yCAAyC;IACzC,MAAM,UAA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AAC,CAAC,gBAAgB,GAAG,eAAe,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACzG,MAAM,aAAa,GAAG,gBAAgB,GAAG,eAAe,CAAA;IAExD,OAAO;QACL,IAAI;QACJ,aAAa;QACb,WAAW;QACX,WAAW,EAAE,UAAU,CAAC,gBAAgB;QACxC,KAAK,EAAE,UAAU,CAAC,oBAAoB;QACtC,WAAW,EAAE,UAAU,CAAC,0BAA0B;QAClD,cAAc,EAAE,UAAU,CAAC,cAAc;KAC1C,CAAA;AACH,CAAC"}
|
package/build/ytTradesLegacy.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.simulateBuyYt = simulateBuyYt;
|
|
4
|
+
exports.simulateBuyYtWithSyIn = simulateBuyYtWithSyIn;
|
|
5
|
+
exports.simulateSellYt = simulateSellYt;
|
|
4
6
|
/**
|
|
5
7
|
* YT (Yield Token) trade simulations
|
|
6
8
|
*
|
|
@@ -74,7 +76,6 @@ function simulateBuyYt(marketState, args) {
|
|
|
74
76
|
finalSpotPrice: swapResult.finalSpotPrice,
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
|
-
exports.simulateBuyYt = simulateBuyYt;
|
|
78
79
|
/**
|
|
79
80
|
* Simulates buying YT tokens given a SY input amount
|
|
80
81
|
*
|
|
@@ -207,7 +208,6 @@ function simulateBuyYtWithSyIn(marketState, args) {
|
|
|
207
208
|
priceSpotLimit,
|
|
208
209
|
});
|
|
209
210
|
}
|
|
210
|
-
exports.simulateBuyYtWithSyIn = simulateBuyYtWithSyIn;
|
|
211
211
|
/**
|
|
212
212
|
* Simulates selling YT tokens
|
|
213
213
|
*
|
|
@@ -288,5 +288,4 @@ function simulateSellYt(marketState, args) {
|
|
|
288
288
|
finalSpotPrice: swapResult.finalSpotPrice,
|
|
289
289
|
};
|
|
290
290
|
}
|
|
291
|
-
exports.simulateSellYt = simulateSellYt;
|
|
292
291
|
//# sourceMappingURL=ytTradesLegacy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ytTradesLegacy.js","sourceRoot":"","sources":["../src/ytTradesLegacy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ytTradesLegacy.js","sourceRoot":"","sources":["../src/ytTradesLegacy.ts"],"names":[],"mappings":";;AAyEA,sCAmCC;AA2BD,sDAuJC;AA2CD,wCAyFC;AAlaD;;;;;;GAMG;AACH,qCAAwC;AACxC,qCAAuC;AACvC,mCAAyD;AAEzD;;;;;GAKG;AACH,SAAS,MAAM,CAAC,cAAsB,EAAE,QAAgB;IACtD,IAAI,cAAc,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,cAAc,CAAC,CAAA;AAC9C,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,cAAsB,EAAE,QAAgB;IACtD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,cAAc,CAAC,CAAA;AAC9C,CAAC;AA8BD;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAAC,WAA6B,EAAE,IAAyB;IACpF,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,IAAI,CAAA;IAEtD,mEAAmE;IACnE,2EAA2E;IAC3E,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IAEnD,2DAA2D;IAC3D,MAAM,WAAW,GAAG,KAAK,CAAA;IAEzB,yCAAyC;IACzC,0EAA0E;IAC1E,MAAM,UAAU,GAAG,IAAA,qBAAY,EAAC,WAAW,EAAE;QAC3C,SAAS,EAAE,qBAAa,CAAC,MAAM;QAC/B,QAAQ,EAAE,KAAK;QACf,cAAc;QACd,cAAc;QACd,kBAAkB,EAAE,IAAI;KAC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IACnF,CAAC;IAED,MAAM,UAAU,GAAG,IAAA,qBAAY,EAAC,WAAW,EAAE;QAC3C,SAAS,EAAE,qBAAa,CAAC,MAAM;QAC/B,QAAQ,EAAE,SAAS;QACnB,cAAc;QACd,cAAc;QACd,kBAAkB,EAAE,IAAI;KACzB,CAAC,CAAA;IAEF,MAAM,aAAa,GAAG,WAAW,GAAG,UAAU,CAAC,gBAAgB,CAAA;IAE/D,OAAO;QACL,IAAI;QACJ,aAAa;QACb,WAAW;QACX,WAAW,EAAE,UAAU,CAAC,gBAAgB;QACxC,KAAK,EAAE,UAAU,CAAC,oBAAoB;QACtC,WAAW,EAAE,UAAU,CAAC,0BAA0B;QAClD,cAAc,EAAE,UAAU,CAAC,cAAc;KAC1C,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exponent-labs/market-three-math",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"types": "build/index.d.ts",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"test:live": "ts-node examples/test-live-market.ts"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@exponent-labs/exponent-fetcher": "0.1
|
|
13
|
+
"@exponent-labs/exponent-fetcher": "0.9.1",
|
|
14
14
|
"@solana/web3.js": "^1.95.8"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|