@nexusmutual/sdk 0.3.12 → 0.3.14

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/dist/index.mjs CHANGED
@@ -50,235 +50,14 @@ __export(constants_exports, {
50
50
  MAXIMUM_COVER_PERIOD: () => MAXIMUM_COVER_PERIOD,
51
51
  MINIMUM_COVER_PERIOD: () => MINIMUM_COVER_PERIOD,
52
52
  NEXUS_MUTUAL_DAO_TREASURY_ADDRESS: () => NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
53
- SLIPPAGE_DENOMINATOR: () => SLIPPAGE_DENOMINATOR,
54
- TARGET_PRICE_DENOMINATOR: () => TARGET_PRICE_DENOMINATOR
55
- });
56
-
57
- // src/quote/index.ts
58
- var quote_exports = {};
59
- __export(quote_exports, {
60
- getQuoteAndBuyCoverInputs: () => getQuoteAndBuyCoverInputs
61
- });
62
-
63
- // src/quote/getQuoteAndBuyCoverInputs.ts
64
- import axios from "axios";
65
- async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, coverAsset, coverBuyerAddress, slippage = DEFAULT_SLIPPAGE / SLIPPAGE_DENOMINATOR, ipfsCid = "", coverRouterUrl = "https://api.nexusmutual.io/v2") {
66
- if (!Number.isInteger(productId) || productId <= 0) {
67
- return { result: void 0, error: { message: "Invalid productId: must be a positive integer" } };
68
- }
69
- if (typeof coverAmount !== "string" || !/^\d+$/.test(coverAmount) || parseInt(coverAmount, 10) <= 0) {
70
- return { result: void 0, error: { message: "Invalid coverAmount: must be a positive integer string" } };
71
- }
72
- if (!Number.isInteger(coverPeriod) || coverPeriod < MINIMUM_COVER_PERIOD || coverPeriod > MAXIMUM_COVER_PERIOD) {
73
- return {
74
- result: void 0,
75
- error: {
76
- message: `Invalid coverPeriod: must be between ${MINIMUM_COVER_PERIOD} and ${MAXIMUM_COVER_PERIOD} days`
77
- }
78
- };
79
- }
80
- const coverAssetsString = Object.keys(CoverAsset).filter((k) => isNaN(+k)).map((k) => `CoverAsset.${k}`).join(", ");
81
- if (!Object.values(CoverAsset).includes(coverAsset)) {
82
- return {
83
- result: void 0,
84
- error: {
85
- message: `Invalid coverAsset: must be one of ${coverAssetsString}`
86
- }
87
- };
88
- }
89
- if (!/^0x[a-fA-F0-9]{40}$/.test(coverBuyerAddress)) {
90
- return { result: void 0, error: { message: "Invalid coverBuyerAddress: must be a valid Ethereum address" } };
91
- }
92
- if (typeof slippage !== "number" || slippage < 0 || slippage > 1) {
93
- return {
94
- result: void 0,
95
- error: { message: "Invalid slippage: must be a number between 0 and 1" }
96
- };
97
- }
98
- if (typeof ipfsCid !== "string") {
99
- return { result: void 0, error: { message: "Invalid ipfsCid: must be a valid IPFS CID" } };
100
- }
101
- slippage = slippage * SLIPPAGE_DENOMINATOR;
102
- try {
103
- const { quote } = await getQuote(productId, coverAmount, coverPeriod, coverAsset, coverRouterUrl);
104
- const maxPremiumInAsset = calculatePremiumWithCommissionAndSlippage(
105
- BigInt(quote.premiumInAsset),
106
- DEFAULT_COMMISSION_RATIO,
107
- slippage
108
- );
109
- const yearlyCostPerc = calculatePremiumWithCommissionAndSlippage(
110
- BigInt(quote.annualPrice),
111
- DEFAULT_COMMISSION_RATIO,
112
- slippage
113
- );
114
- const result = {
115
- displayInfo: {
116
- premiumInAsset: maxPremiumInAsset.toString(),
117
- coverAmount,
118
- yearlyCostPerc: Number(yearlyCostPerc) / TARGET_PRICE_DENOMINATOR,
119
- maxCapacity: await getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl) ?? ""
120
- },
121
- buyCoverInput: {
122
- buyCoverParams: {
123
- coverId: 0 /* BUY */,
124
- owner: coverBuyerAddress,
125
- productId,
126
- coverAsset,
127
- amount: coverAmount,
128
- period: coverPeriod * 60 * 60 * 24,
129
- // seconds
130
- maxPremiumInAsset: maxPremiumInAsset.toString(),
131
- paymentAsset: coverAsset,
132
- commissionRatio: DEFAULT_COMMISSION_RATIO,
133
- commissionDestination: NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
134
- ipfsData: ipfsCid
135
- },
136
- poolAllocationRequests: quote.poolAllocationRequests
137
- }
138
- };
139
- return { result, error: void 0 };
140
- } catch (error) {
141
- const errorResponse = await handleError(error, productId, coverPeriod, coverAsset, coverRouterUrl);
142
- return errorResponse;
143
- }
144
- }
145
- async function getQuote(productId, coverAmount, coverPeriod, coverAsset, coverRouterUrl) {
146
- const params = { productId, amount: coverAmount, period: coverPeriod, coverAsset };
147
- const response = await axios.get(coverRouterUrl + "/quote", { params });
148
- if (!response.data) {
149
- throw new Error("Failed to fetch cover quote");
150
- }
151
- return response.data;
152
- }
153
- async function getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl) {
154
- const params = { period: coverPeriod };
155
- const capacityUrl = coverRouterUrl + `/capacity/${productId}`;
156
- const response = await axios.get(capacityUrl, { params });
157
- if (!response.data) {
158
- throw new Error("Failed to fetch cover capacities");
159
- }
160
- return response.data.availableCapacity.find((av) => av.assetId === coverAsset)?.amount;
161
- }
162
- async function handleError(error, productId, coverPeriod, coverAsset, coverRouterUrl) {
163
- const axiosError = error;
164
- if (axiosError.isAxiosError) {
165
- if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
166
- const maxCapacity = await getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl);
167
- return {
168
- result: void 0,
169
- error: {
170
- message: axiosError.response?.data.error,
171
- data: maxCapacity ? { maxCapacity } : void 0
172
- }
173
- };
174
- }
175
- }
176
- return {
177
- result: void 0,
178
- error: { message: error.message || "Something went wrong" }
179
- };
180
- }
181
-
182
- // src/swap/index.ts
183
- var swap_exports = {};
184
- __export(swap_exports, {
185
- calculateEthForExactNxm: () => calculateEthForExactNxm,
186
- calculateExactEthForNxm: () => calculateExactEthForNxm,
187
- calculateExactNxmForEth: () => calculateExactNxmForEth,
188
- calculateNxmForExactEth: () => calculateNxmForExactEth,
189
- calculatePriceImpactA: () => calculatePriceImpactA,
190
- calculatePriceImpactB: () => calculatePriceImpactB,
191
- calculateSpotPrice: () => calculateSpotPrice
192
- });
193
-
194
- // src/swap/calculateExactNxmForEth.ts
195
- var calculateExactNxmForEth = (ethIn, reserves) => {
196
- if (ethIn <= 0n) {
197
- throw new Error("ETH in value must be greater than 0");
198
- }
199
- const k = reserves.nxmA * reserves.ethReserve;
200
- const ethReservesAfter = reserves.ethReserve + ethIn;
201
- const nxmReservesAfter = k / ethReservesAfter;
202
- const nxmOut = reserves.nxmA - nxmReservesAfter;
203
- if (nxmOut < 0n) {
204
- throw new Error("Cannot swap this amount");
205
- }
206
- return nxmOut;
207
- };
208
-
209
- // src/swap/calculateExactEthForNxm.ts
210
- var calculateExactEthForNxm = (nxmIn, reserves) => {
211
- if (nxmIn <= 0n) {
212
- throw new Error("NXM in value must be greater than 0");
213
- }
214
- const k = reserves.nxmB * reserves.ethReserve;
215
- const nxmReservesAfter = reserves.nxmB + nxmIn;
216
- const ethReservesAfter = k / nxmReservesAfter;
217
- const ethOut = reserves.ethReserve - ethReservesAfter;
218
- if (ethOut < 0n) {
219
- throw new Error("Cannot swap this amount");
220
- }
221
- return ethOut;
222
- };
223
-
224
- // src/swap/calculateNxmForExactEth.ts
225
- var calculateNxmForExactEth = (ethOut, reserves) => {
226
- if (ethOut <= 0n || ethOut >= reserves.ethReserve) {
227
- throw new Error("ETH out value must be greater than 0 and less than the reserves");
228
- }
229
- const k = reserves.nxmB * reserves.ethReserve;
230
- const ethReservesAfter = reserves.ethReserve - ethOut;
231
- const nxmReservesAfter = k / ethReservesAfter;
232
- const nxmIn = nxmReservesAfter - reserves.nxmB;
233
- return nxmIn;
234
- };
235
-
236
- // src/swap/calculateEthForExactNxm.ts
237
- var calculateEthForExactNxm = (nxmOut, reserves) => {
238
- if (nxmOut <= 0n || nxmOut >= reserves.nxmA) {
239
- throw new Error("NXM out value must be greater than 0 and less than the reserves");
240
- }
241
- const k = reserves.nxmA * reserves.ethReserve;
242
- const nxmReservesAfter = reserves.nxmA - nxmOut;
243
- const ethReservesAfter = k / nxmReservesAfter;
244
- const ethIn = ethReservesAfter - reserves.ethReserve;
245
- return ethIn;
246
- };
247
-
248
- // src/swap/calculateSpotPrice.ts
249
- var calculateSpotPrice = (reserves) => {
250
- const oneEth = BigInt(1e18);
251
- return {
252
- spotPriceA: oneEth * reserves.ethReserve / reserves.nxmA,
253
- spotPriceB: oneEth * reserves.ethReserve / reserves.nxmB
254
- };
255
- };
256
-
257
- // src/swap/calculatePriceImpactA.ts
258
- var calculatePriceImpactA = (ethIn, reserves) => {
259
- const { spotPriceA } = calculateSpotPrice(reserves);
260
- const nxmOut = calculateExactNxmForEth(ethIn, reserves);
261
- const nxmOutAtSpotPrice = BigInt(1e18) * ethIn / spotPriceA;
262
- return BigInt(1e6) - BigInt(1e6) * nxmOut / nxmOutAtSpotPrice;
263
- };
264
-
265
- // src/swap/calculatePriceImpactB.ts
266
- var calculatePriceImpactB = (nxmIn, reserves) => {
267
- const { spotPriceB } = calculateSpotPrice(reserves);
268
- const ethOut = calculateExactEthForNxm(nxmIn, reserves);
269
- const ethOutAtSpotPrice = spotPriceB * nxmIn / BigInt(1e18);
270
- return BigInt(1e6) - BigInt(1e6) * ethOut / ethOutAtSpotPrice;
271
- };
272
-
273
- // src/types/index.ts
274
- var types_exports = {};
275
- __export(types_exports, {
276
53
  ProductCategoryEnum: () => ProductCategoryEnum,
54
+ SLIPPAGE_DENOMINATOR: () => SLIPPAGE_DENOMINATOR,
55
+ TARGET_PRICE_DENOMINATOR: () => TARGET_PRICE_DENOMINATOR,
277
56
  categoryLabelByEnum: () => categoryLabelByEnum,
278
57
  productCategoryMap: () => productCategoryMap
279
58
  });
280
59
 
281
- // src/types/cover.ts
60
+ // src/constants/products.ts
282
61
  var ProductCategoryEnum = /* @__PURE__ */ ((ProductCategoryEnum2) => {
283
62
  ProductCategoryEnum2["All"] = "all";
284
63
  ProductCategoryEnum2["Lending"] = "lending";
@@ -288,7 +67,6 @@ var ProductCategoryEnum = /* @__PURE__ */ ((ProductCategoryEnum2) => {
288
67
  ProductCategoryEnum2["Perpetuals"] = "perpetuals";
289
68
  ProductCategoryEnum2["SmartWallet"] = "smart-wallet";
290
69
  ProductCategoryEnum2["RWA"] = "rwa";
291
- ProductCategoryEnum2["Coverage"] = "coverage";
292
70
  ProductCategoryEnum2["ETHStaking"] = "eth-staking";
293
71
  ProductCategoryEnum2["Unity"] = "unity";
294
72
  return ProductCategoryEnum2;
@@ -301,8 +79,7 @@ var categoryLabelByEnum = {
301
79
  ["yield-optimizer" /* YieldOptimizer */]: "Yield Optimizer",
302
80
  ["perpetuals" /* Perpetuals */]: "Perpetuals",
303
81
  ["smart-wallet" /* SmartWallet */]: "Smart Wallet",
304
- ["rwa" /* RWA */]: "RWA",
305
- ["coverage" /* Coverage */]: "Coverage",
82
+ ["rwa" /* RWA */]: "RWA Coverage",
306
83
  ["eth-staking" /* ETHStaking */]: "ETH Staking",
307
84
  ["unity" /* Unity */]: "Unity"
308
85
  // [ProductCategoryEnum.Uncategorized]: 'Uncategorized',
@@ -350,8 +127,7 @@ var productCategoryMap = {
350
127
  // 27: ProductCategoryEnum.Uncategorized, // Curve sETH LP (eCrv)
351
128
  28: "perpetuals" /* Perpetuals */,
352
129
  // dydx Perpetual
353
- 29: "coverage" /* Coverage */,
354
- // Ease v1
130
+ // 29: ProductCategoryEnum.Uncategorized, // Ease v1
355
131
  // 30: ProductCategoryEnum.Uncategorized, // Enzyme v3
356
132
  31: "yield-optimizer" /* YieldOptimizer */,
357
133
  // Enzyme v4
@@ -564,12 +340,241 @@ var productCategoryMap = {
564
340
  // Etherfi (Zircuit) Pendle
565
341
  161: "liquid-restaking" /* LiquidRestaking */,
566
342
  // KelpDAO (Zircuit) Pendle
567
- 162: "liquid-restaking" /* LiquidRestaking */
343
+ 162: "liquid-restaking" /* LiquidRestaking */,
568
344
  // Renzo (Zircuit) Pendle
569
345
  // 163: ProductCategoryEnum.Uncategorized, // Pocket Universe
570
346
  // 164: ProductCategoryEnum.Uncategorized, // Request Finance
347
+ 165: "yield-optimizer" /* YieldOptimizer */,
348
+ // Etherfi Liquid Market-Neutral USD Vault
349
+ 166: "yield-optimizer" /* YieldOptimizer */,
350
+ // Superform
351
+ 167: "liquid-restaking" /* LiquidRestaking */,
352
+ // EigenLayer + Etherfi
353
+ 168: "yield-optimizer" /* YieldOptimizer */,
354
+ // Beefy CLM + Uniswap v3
355
+ 169: "eth-staking" /* ETHStaking */
356
+ // RockX
571
357
  };
572
358
 
359
+ // src/quote/index.ts
360
+ var quote_exports = {};
361
+ __export(quote_exports, {
362
+ getQuoteAndBuyCoverInputs: () => getQuoteAndBuyCoverInputs
363
+ });
364
+
365
+ // src/quote/getQuoteAndBuyCoverInputs.ts
366
+ import axios from "axios";
367
+ async function getQuoteAndBuyCoverInputs(productId, coverAmount, coverPeriod, coverAsset, coverBuyerAddress, slippage = DEFAULT_SLIPPAGE / SLIPPAGE_DENOMINATOR, ipfsCid = "", coverRouterUrl = "https://api.nexusmutual.io/v2") {
368
+ if (!Number.isInteger(productId) || productId <= 0) {
369
+ return { result: void 0, error: { message: "Invalid productId: must be a positive integer" } };
370
+ }
371
+ if (typeof coverAmount !== "string" || !/^\d+$/.test(coverAmount) || parseInt(coverAmount, 10) <= 0) {
372
+ return { result: void 0, error: { message: "Invalid coverAmount: must be a positive integer string" } };
373
+ }
374
+ if (!Number.isInteger(coverPeriod) || coverPeriod < MINIMUM_COVER_PERIOD || coverPeriod > MAXIMUM_COVER_PERIOD) {
375
+ return {
376
+ result: void 0,
377
+ error: {
378
+ message: `Invalid coverPeriod: must be between ${MINIMUM_COVER_PERIOD} and ${MAXIMUM_COVER_PERIOD} days`
379
+ }
380
+ };
381
+ }
382
+ const coverAssetsString = Object.keys(CoverAsset).filter((k) => isNaN(+k)).map((k) => `CoverAsset.${k}`).join(", ");
383
+ if (!Object.values(CoverAsset).includes(coverAsset)) {
384
+ return {
385
+ result: void 0,
386
+ error: {
387
+ message: `Invalid coverAsset: must be one of ${coverAssetsString}`
388
+ }
389
+ };
390
+ }
391
+ if (!/^0x[a-fA-F0-9]{40}$/.test(coverBuyerAddress)) {
392
+ return { result: void 0, error: { message: "Invalid coverBuyerAddress: must be a valid Ethereum address" } };
393
+ }
394
+ if (typeof slippage !== "number" || slippage < 0 || slippage > 1) {
395
+ return {
396
+ result: void 0,
397
+ error: { message: "Invalid slippage: must be a number between 0 and 1" }
398
+ };
399
+ }
400
+ if (typeof ipfsCid !== "string") {
401
+ return { result: void 0, error: { message: "Invalid ipfsCid: must be a valid IPFS CID" } };
402
+ }
403
+ slippage = slippage * SLIPPAGE_DENOMINATOR;
404
+ try {
405
+ const { quote } = await getQuote(productId, coverAmount, coverPeriod, coverAsset, coverRouterUrl);
406
+ const maxPremiumInAsset = calculatePremiumWithCommissionAndSlippage(
407
+ BigInt(quote.premiumInAsset),
408
+ DEFAULT_COMMISSION_RATIO,
409
+ slippage
410
+ );
411
+ const yearlyCostPerc = calculatePremiumWithCommissionAndSlippage(
412
+ BigInt(quote.annualPrice),
413
+ DEFAULT_COMMISSION_RATIO,
414
+ slippage
415
+ );
416
+ const result = {
417
+ displayInfo: {
418
+ premiumInAsset: maxPremiumInAsset.toString(),
419
+ coverAmount,
420
+ yearlyCostPerc: Number(yearlyCostPerc) / TARGET_PRICE_DENOMINATOR,
421
+ maxCapacity: await getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl) ?? ""
422
+ },
423
+ buyCoverInput: {
424
+ buyCoverParams: {
425
+ coverId: 0 /* BUY */,
426
+ owner: coverBuyerAddress,
427
+ productId,
428
+ coverAsset,
429
+ amount: coverAmount,
430
+ period: coverPeriod * 60 * 60 * 24,
431
+ // seconds
432
+ maxPremiumInAsset: maxPremiumInAsset.toString(),
433
+ paymentAsset: coverAsset,
434
+ commissionRatio: DEFAULT_COMMISSION_RATIO,
435
+ commissionDestination: NEXUS_MUTUAL_DAO_TREASURY_ADDRESS,
436
+ ipfsData: ipfsCid
437
+ },
438
+ poolAllocationRequests: quote.poolAllocationRequests
439
+ }
440
+ };
441
+ return { result, error: void 0 };
442
+ } catch (error) {
443
+ const errorResponse = await handleError(error, productId, coverPeriod, coverAsset, coverRouterUrl);
444
+ return errorResponse;
445
+ }
446
+ }
447
+ async function getQuote(productId, coverAmount, coverPeriod, coverAsset, coverRouterUrl) {
448
+ const params = { productId, amount: coverAmount, period: coverPeriod, coverAsset };
449
+ const response = await axios.get(coverRouterUrl + "/quote", { params });
450
+ if (!response.data) {
451
+ throw new Error("Failed to fetch cover quote");
452
+ }
453
+ return response.data;
454
+ }
455
+ async function getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl) {
456
+ const params = { period: coverPeriod };
457
+ const capacityUrl = coverRouterUrl + `/capacity/${productId}`;
458
+ const response = await axios.get(capacityUrl, { params });
459
+ if (!response.data) {
460
+ throw new Error("Failed to fetch cover capacities");
461
+ }
462
+ return response.data.availableCapacity.find((av) => av.assetId === coverAsset)?.amount;
463
+ }
464
+ async function handleError(error, productId, coverPeriod, coverAsset, coverRouterUrl) {
465
+ const axiosError = error;
466
+ if (axiosError.isAxiosError) {
467
+ if (axiosError.response?.data?.error?.includes("Not enough capacity")) {
468
+ const maxCapacity = await getProductCapacity(productId, coverPeriod, coverAsset, coverRouterUrl);
469
+ return {
470
+ result: void 0,
471
+ error: {
472
+ message: axiosError.response?.data.error,
473
+ data: maxCapacity ? { maxCapacity } : void 0
474
+ }
475
+ };
476
+ }
477
+ }
478
+ return {
479
+ result: void 0,
480
+ error: { message: error.message || "Something went wrong" }
481
+ };
482
+ }
483
+
484
+ // src/swap/index.ts
485
+ var swap_exports = {};
486
+ __export(swap_exports, {
487
+ calculateEthForExactNxm: () => calculateEthForExactNxm,
488
+ calculateExactEthForNxm: () => calculateExactEthForNxm,
489
+ calculateExactNxmForEth: () => calculateExactNxmForEth,
490
+ calculateNxmForExactEth: () => calculateNxmForExactEth,
491
+ calculatePriceImpactA: () => calculatePriceImpactA,
492
+ calculatePriceImpactB: () => calculatePriceImpactB,
493
+ calculateSpotPrice: () => calculateSpotPrice
494
+ });
495
+
496
+ // src/swap/calculateExactNxmForEth.ts
497
+ var calculateExactNxmForEth = (ethIn, reserves) => {
498
+ if (ethIn <= 0n) {
499
+ throw new Error("ETH in value must be greater than 0");
500
+ }
501
+ const k = reserves.nxmA * reserves.ethReserve;
502
+ const ethReservesAfter = reserves.ethReserve + ethIn;
503
+ const nxmReservesAfter = k / ethReservesAfter;
504
+ const nxmOut = reserves.nxmA - nxmReservesAfter;
505
+ if (nxmOut < 0n) {
506
+ throw new Error("Cannot swap this amount");
507
+ }
508
+ return nxmOut;
509
+ };
510
+
511
+ // src/swap/calculateExactEthForNxm.ts
512
+ var calculateExactEthForNxm = (nxmIn, reserves) => {
513
+ if (nxmIn <= 0n) {
514
+ throw new Error("NXM in value must be greater than 0");
515
+ }
516
+ const k = reserves.nxmB * reserves.ethReserve;
517
+ const nxmReservesAfter = reserves.nxmB + nxmIn;
518
+ const ethReservesAfter = k / nxmReservesAfter;
519
+ const ethOut = reserves.ethReserve - ethReservesAfter;
520
+ if (ethOut < 0n) {
521
+ throw new Error("Cannot swap this amount");
522
+ }
523
+ return ethOut;
524
+ };
525
+
526
+ // src/swap/calculateNxmForExactEth.ts
527
+ var calculateNxmForExactEth = (ethOut, reserves) => {
528
+ if (ethOut <= 0n || ethOut >= reserves.ethReserve) {
529
+ throw new Error("ETH out value must be greater than 0 and less than the reserves");
530
+ }
531
+ const k = reserves.nxmB * reserves.ethReserve;
532
+ const ethReservesAfter = reserves.ethReserve - ethOut;
533
+ const nxmReservesAfter = k / ethReservesAfter;
534
+ const nxmIn = nxmReservesAfter - reserves.nxmB;
535
+ return nxmIn;
536
+ };
537
+
538
+ // src/swap/calculateEthForExactNxm.ts
539
+ var calculateEthForExactNxm = (nxmOut, reserves) => {
540
+ if (nxmOut <= 0n || nxmOut >= reserves.nxmA) {
541
+ throw new Error("NXM out value must be greater than 0 and less than the reserves");
542
+ }
543
+ const k = reserves.nxmA * reserves.ethReserve;
544
+ const nxmReservesAfter = reserves.nxmA - nxmOut;
545
+ const ethReservesAfter = k / nxmReservesAfter;
546
+ const ethIn = ethReservesAfter - reserves.ethReserve;
547
+ return ethIn;
548
+ };
549
+
550
+ // src/swap/calculateSpotPrice.ts
551
+ var calculateSpotPrice = (reserves) => {
552
+ const oneEth = BigInt(1e18);
553
+ return {
554
+ spotPriceA: oneEth * reserves.ethReserve / reserves.nxmA,
555
+ spotPriceB: oneEth * reserves.ethReserve / reserves.nxmB
556
+ };
557
+ };
558
+
559
+ // src/swap/calculatePriceImpactA.ts
560
+ var calculatePriceImpactA = (ethIn, reserves) => {
561
+ const { spotPriceA } = calculateSpotPrice(reserves);
562
+ const nxmOut = calculateExactNxmForEth(ethIn, reserves);
563
+ const nxmOutAtSpotPrice = BigInt(1e18) * ethIn / spotPriceA;
564
+ return BigInt(1e6) - BigInt(1e6) * nxmOut / nxmOutAtSpotPrice;
565
+ };
566
+
567
+ // src/swap/calculatePriceImpactB.ts
568
+ var calculatePriceImpactB = (nxmIn, reserves) => {
569
+ const { spotPriceB } = calculateSpotPrice(reserves);
570
+ const ethOut = calculateExactEthForNxm(nxmIn, reserves);
571
+ const ethOutAtSpotPrice = spotPriceB * nxmIn / BigInt(1e18);
572
+ return BigInt(1e6) - BigInt(1e6) * ethOut / ethOutAtSpotPrice;
573
+ };
574
+
575
+ // src/types/index.ts
576
+ var types_exports = {};
577
+
573
578
  // generated/product-types.json
574
579
  var product_types_default = [
575
580
  {
@@ -2097,7 +2102,7 @@ var products_default = [
2097
2102
  "DAI"
2098
2103
  ],
2099
2104
  isPrivate: true,
2100
- timestamp: 1704980411
2105
+ timestamp: 1684312727
2101
2106
  },
2102
2107
  {
2103
2108
  id: 88,
@@ -2114,7 +2119,7 @@ var products_default = [
2114
2119
  "DAI"
2115
2120
  ],
2116
2121
  isPrivate: true,
2117
- timestamp: 1704980411
2122
+ timestamp: 1684312727
2118
2123
  },
2119
2124
  {
2120
2125
  id: 89,
@@ -2358,7 +2363,7 @@ var products_default = [
2358
2363
  "DAI"
2359
2364
  ],
2360
2365
  isPrivate: true,
2361
- timestamp: 1689782903
2366
+ timestamp: 1704980411
2362
2367
  },
2363
2368
  {
2364
2369
  id: 105,
@@ -2375,7 +2380,7 @@ var products_default = [
2375
2380
  "DAI"
2376
2381
  ],
2377
2382
  isPrivate: true,
2378
- timestamp: 1689782903
2383
+ timestamp: 1704980411
2379
2384
  },
2380
2385
  {
2381
2386
  id: 106,
@@ -2497,7 +2502,7 @@ var products_default = [
2497
2502
  "DAI"
2498
2503
  ],
2499
2504
  isPrivate: true,
2500
- timestamp: 1691495087
2505
+ timestamp: 1691493035
2501
2506
  },
2502
2507
  {
2503
2508
  id: 114,
@@ -2840,7 +2845,7 @@ var products_default = [
2840
2845
  "ETH"
2841
2846
  ],
2842
2847
  isPrivate: false,
2843
- timestamp: 1709311739
2848
+ timestamp: 1709310707
2844
2849
  },
2845
2850
  {
2846
2851
  id: 137,
@@ -2932,7 +2937,7 @@ var products_default = [
2932
2937
  "DAI"
2933
2938
  ],
2934
2939
  isPrivate: false,
2935
- timestamp: 1715349875
2940
+ timestamp: 1710254231
2936
2941
  },
2937
2942
  {
2938
2943
  id: 143,
@@ -2965,7 +2970,7 @@ var products_default = [
2965
2970
  "DAI"
2966
2971
  ],
2967
2972
  isPrivate: false,
2968
- timestamp: 1715349875
2973
+ timestamp: 1710254231
2969
2974
  },
2970
2975
  {
2971
2976
  id: 145,
@@ -2982,7 +2987,7 @@ var products_default = [
2982
2987
  "DAI"
2983
2988
  ],
2984
2989
  isPrivate: false,
2985
- timestamp: 1715349875
2990
+ timestamp: 1710254231
2986
2991
  },
2987
2992
  {
2988
2993
  id: 146,
@@ -3046,7 +3051,7 @@ var products_default = [
3046
3051
  "DAI"
3047
3052
  ],
3048
3053
  isPrivate: false,
3049
- timestamp: 1710850979
3054
+ timestamp: 1715349875
3050
3055
  },
3051
3056
  {
3052
3057
  id: 150,
@@ -3111,7 +3116,7 @@ var products_default = [
3111
3116
  "ETH"
3112
3117
  ],
3113
3118
  isPrivate: false,
3114
- timestamp: 1715349875
3119
+ timestamp: 1711473767
3115
3120
  },
3116
3121
  {
3117
3122
  id: 154,
@@ -3191,7 +3196,7 @@ var products_default = [
3191
3196
  "ETH"
3192
3197
  ],
3193
3198
  isPrivate: false,
3194
- timestamp: 1712244083
3199
+ timestamp: 1715349875
3195
3200
  },
3196
3201
  {
3197
3202
  id: 159,
@@ -3224,7 +3229,7 @@ var products_default = [
3224
3229
  "ETH"
3225
3230
  ],
3226
3231
  isPrivate: false,
3227
- timestamp: 1715349875
3232
+ timestamp: 1713185771
3228
3233
  },
3229
3234
  {
3230
3235
  id: 161,
@@ -3240,7 +3245,7 @@ var products_default = [
3240
3245
  "ETH"
3241
3246
  ],
3242
3247
  isPrivate: false,
3243
- timestamp: 1715349875
3248
+ timestamp: 1713185771
3244
3249
  },
3245
3250
  {
3246
3251
  id: 162,
@@ -3256,7 +3261,7 @@ var products_default = [
3256
3261
  "ETH"
3257
3262
  ],
3258
3263
  isPrivate: false,
3259
- timestamp: 1715349875
3264
+ timestamp: 1713185771
3260
3265
  },
3261
3266
  {
3262
3267
  id: 163,