@meteora-ag/dynamic-bonding-curve-sdk 1.5.9 → 1.5.10
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.cjs +122 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -1
- package/dist/index.d.ts +64 -1
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31409,6 +31409,128 @@ var PoolService = class extends DynamicBondingCurveProgram {
|
|
|
31409
31409
|
throw new Error(`Unsupported swap mode: ${swapMode}`);
|
|
31410
31410
|
}
|
|
31411
31411
|
}
|
|
31412
|
+
/**
|
|
31413
|
+
* Reconcile the only two fields that differ between an on-chain `PoolConfig`
|
|
31414
|
+
* and a `buildCurve` output (`ConfigParameters`) so the quote math can
|
|
31415
|
+
* consume either directly:
|
|
31416
|
+
* - `migrationSqrtPrice`: used when present, otherwise derived from the
|
|
31417
|
+
* curve and migration quote threshold (it is the swap stop price).
|
|
31418
|
+
* - `dynamicFee`: a null/undefined object becomes a disabled one, and a
|
|
31419
|
+
* present object is treated as enabled unless `initialized` says otherwise.
|
|
31420
|
+
*
|
|
31421
|
+
* Everything else is already in the right shape and passed through.
|
|
31422
|
+
*/
|
|
31423
|
+
normalizeQuoteConfig(config) {
|
|
31424
|
+
if (!config.curve || config.curve.length === 0) {
|
|
31425
|
+
throw new Error("config.curve is empty");
|
|
31426
|
+
}
|
|
31427
|
+
const migrationSqrtPrice = _nullishCoalesce(config.migrationSqrtPrice, () => ( getMigrationThresholdPrice(
|
|
31428
|
+
config.migrationQuoteThreshold,
|
|
31429
|
+
config.sqrtStartPrice,
|
|
31430
|
+
config.curve
|
|
31431
|
+
)));
|
|
31432
|
+
const dynamicFee = config.poolFees.dynamicFee;
|
|
31433
|
+
return {
|
|
31434
|
+
...config,
|
|
31435
|
+
migrationSqrtPrice,
|
|
31436
|
+
poolFees: {
|
|
31437
|
+
...config.poolFees,
|
|
31438
|
+
dynamicFee: dynamicFee ? {
|
|
31439
|
+
...dynamicFee,
|
|
31440
|
+
initialized: _nullishCoalesce(dynamicFee.initialized, () => ( 1))
|
|
31441
|
+
} : { initialized: 0, binStep: 0, variableFeeControl: 0 }
|
|
31442
|
+
}
|
|
31443
|
+
};
|
|
31444
|
+
}
|
|
31445
|
+
/**
|
|
31446
|
+
* creates a virtual pool state at launch with zeroed reserves and volatility, start price set.
|
|
31447
|
+
*/
|
|
31448
|
+
buildSimulatedVirtualPool(sqrtStartPrice) {
|
|
31449
|
+
return {
|
|
31450
|
+
poolState: {
|
|
31451
|
+
sqrtPrice: new (0, _bnjs2.default)(sqrtStartPrice),
|
|
31452
|
+
baseReserve: new (0, _bnjs2.default)(0),
|
|
31453
|
+
quoteReserve: new (0, _bnjs2.default)(0),
|
|
31454
|
+
activationPoint: new (0, _bnjs2.default)(0),
|
|
31455
|
+
volatilityTracker: {
|
|
31456
|
+
lastUpdateTimestamp: new (0, _bnjs2.default)(0),
|
|
31457
|
+
sqrtPriceReference: new (0, _bnjs2.default)(0),
|
|
31458
|
+
volatilityAccumulator: new (0, _bnjs2.default)(0),
|
|
31459
|
+
volatilityReference: new (0, _bnjs2.default)(0),
|
|
31460
|
+
padding: []
|
|
31461
|
+
}
|
|
31462
|
+
}
|
|
31463
|
+
};
|
|
31464
|
+
}
|
|
31465
|
+
/**
|
|
31466
|
+
* quotes a swap from an input amount before any pool exists.
|
|
31467
|
+
*/
|
|
31468
|
+
getQuoteFromInputAmount(params) {
|
|
31469
|
+
const {
|
|
31470
|
+
config,
|
|
31471
|
+
swapBaseForQuote,
|
|
31472
|
+
amountIn,
|
|
31473
|
+
swapMode = 0 /* ExactIn */,
|
|
31474
|
+
slippageBps = 0,
|
|
31475
|
+
hasReferral = false,
|
|
31476
|
+
eligibleForFirstSwapWithMinFee = false,
|
|
31477
|
+
currentPoint = new (0, _bnjs2.default)(0)
|
|
31478
|
+
} = params;
|
|
31479
|
+
const poolConfig = this.normalizeQuoteConfig(config);
|
|
31480
|
+
const virtualPool = this.buildSimulatedVirtualPool(
|
|
31481
|
+
poolConfig.sqrtStartPrice
|
|
31482
|
+
);
|
|
31483
|
+
if (swapMode === 1 /* PartialFill */) {
|
|
31484
|
+
return swapQuotePartialFill(
|
|
31485
|
+
virtualPool,
|
|
31486
|
+
poolConfig,
|
|
31487
|
+
swapBaseForQuote,
|
|
31488
|
+
amountIn,
|
|
31489
|
+
slippageBps,
|
|
31490
|
+
hasReferral,
|
|
31491
|
+
currentPoint,
|
|
31492
|
+
eligibleForFirstSwapWithMinFee
|
|
31493
|
+
);
|
|
31494
|
+
}
|
|
31495
|
+
return swapQuoteExactIn(
|
|
31496
|
+
virtualPool,
|
|
31497
|
+
poolConfig,
|
|
31498
|
+
swapBaseForQuote,
|
|
31499
|
+
amountIn,
|
|
31500
|
+
slippageBps,
|
|
31501
|
+
hasReferral,
|
|
31502
|
+
currentPoint,
|
|
31503
|
+
eligibleForFirstSwapWithMinFee
|
|
31504
|
+
);
|
|
31505
|
+
}
|
|
31506
|
+
/**
|
|
31507
|
+
* quotes a swap from an exact output amount (`SwapMode.ExactOut`)
|
|
31508
|
+
*/
|
|
31509
|
+
getQuoteFromOutputAmount(params) {
|
|
31510
|
+
const {
|
|
31511
|
+
config,
|
|
31512
|
+
swapBaseForQuote,
|
|
31513
|
+
amountOut,
|
|
31514
|
+
slippageBps = 0,
|
|
31515
|
+
hasReferral = false,
|
|
31516
|
+
eligibleForFirstSwapWithMinFee = false,
|
|
31517
|
+
currentPoint = new (0, _bnjs2.default)(0)
|
|
31518
|
+
} = params;
|
|
31519
|
+
const poolConfig = this.normalizeQuoteConfig(config);
|
|
31520
|
+
const virtualPool = this.buildSimulatedVirtualPool(
|
|
31521
|
+
poolConfig.sqrtStartPrice
|
|
31522
|
+
);
|
|
31523
|
+
return swapQuoteExactOut(
|
|
31524
|
+
virtualPool,
|
|
31525
|
+
poolConfig,
|
|
31526
|
+
swapBaseForQuote,
|
|
31527
|
+
amountOut,
|
|
31528
|
+
slippageBps,
|
|
31529
|
+
hasReferral,
|
|
31530
|
+
currentPoint,
|
|
31531
|
+
eligibleForFirstSwapWithMinFee
|
|
31532
|
+
);
|
|
31533
|
+
}
|
|
31412
31534
|
};
|
|
31413
31535
|
|
|
31414
31536
|
// src/services/creator.ts
|