@meteora-ag/dynamic-bonding-curve-sdk 1.4.8 → 1.4.9

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.d.cts CHANGED
@@ -5560,6 +5560,12 @@ type BuildCurveWithTwoSegmentsParams = BuildCurveBaseParams & {
5560
5560
  migrationMarketCap: number;
5561
5561
  percentageSupplyOnMigration: number;
5562
5562
  };
5563
+ type BuildCurveWithMidPriceParams = BuildCurveBaseParams & {
5564
+ initialMarketCap: number;
5565
+ migrationMarketCap: number;
5566
+ midPrice: number;
5567
+ percentageSupplyOnMigration: number;
5568
+ };
5563
5569
  type BuildCurveWithLiquidityWeightsParams = BuildCurveBaseParams & {
5564
5570
  initialMarketCap: number;
5565
5571
  migrationMarketCap: number;
@@ -6662,6 +6668,19 @@ declare const getTotalSupplyFromCurve: (migrationQuoteThreshold: BN$1, sqrtStart
6662
6668
  * @returns The migration threshold price
6663
6669
  */
6664
6670
  declare const getMigrationThresholdPrice: (migrationThreshold: BN$1, sqrtStartPrice: BN$1, curve: Array<LiquidityDistributionParameters>) => BN$1;
6671
+ /**
6672
+ * Calculate the quote amount allocated to each curve segment
6673
+ * Formula: Δb = L * (√P_upper - √P_lower) for each segment
6674
+ * @param migrationQuoteThreshold - The total migration quote threshold
6675
+ * @param sqrtStartPrice - The start sqrt price
6676
+ * @param curve - The curve segments with sqrtPrice and liquidity
6677
+ * @returns Array of quote amounts for each segment and the final sqrt price reached
6678
+ */
6679
+ declare const getCurveBreakdown: (migrationQuoteThreshold: BN$1, sqrtStartPrice: BN$1, curve: Array<LiquidityDistributionParameters>) => {
6680
+ segmentAmounts: BN$1[];
6681
+ finalSqrtPrice: BN$1;
6682
+ totalAmount: BN$1;
6683
+ };
6665
6684
  /**
6666
6685
  * Get the swap amount with buffer
6667
6686
  * @param swapBaseAmount - The swap base amount
@@ -7244,6 +7263,12 @@ declare function buildCurveWithMarketCap(buildCurveWithMarketCapParam: BuildCurv
7244
7263
  * @returns The build custom constant product curve by market cap
7245
7264
  */
7246
7265
  declare function buildCurveWithTwoSegments(buildCurveWithTwoSegmentsParam: BuildCurveWithTwoSegmentsParams): ConfigParameters;
7266
+ /**
7267
+ * Build a custom constant product curve with a mid price. This will create a two segment curve with a start price -> mid price, and a mid price -> migration price.
7268
+ * @param buildCurveWithMidPriceParam - The parameters for the custom constant product curve with a mid price
7269
+ * @returns The build custom constant product curve by mid price
7270
+ */
7271
+ declare function buildCurveWithMidPrice(buildCurveWithMidPriceParam: BuildCurveWithMidPriceParams): ConfigParameters;
7247
7272
  /**
7248
7273
  * Build a custom curve graph with liquidity weights, changing the curve shape based on the liquidity weights
7249
7274
  * @param buildCurveWithLiquidityWeightsParam - The parameters for the custom constant product curve with liquidity weights
@@ -21662,4 +21687,4 @@ var idl = {
21662
21687
  types: types
21663
21688
  };
21664
21689
 
21665
- export { ActivationType, BASE_ADDRESS, BASIS_POINT_MAX, BIN_STEP_BPS_DEFAULT, BIN_STEP_BPS_U128_DEFAULT, type BaseFee, type BaseFeeConfig, type BaseFeeHandler, BaseFeeMode, type BaseFeeParams, type BuildCurveBaseParams, type BuildCurveParams, type BuildCurveWithLiquidityWeightsParams, type BuildCurveWithMarketCapParams, type BuildCurveWithTwoSegmentsParams, type ClaimCreatorTradingFee2Params, type ClaimCreatorTradingFeeParams, type ClaimCreatorTradingFeeWithQuoteMintNotSolParams, type ClaimCreatorTradingFeeWithQuoteMintSolParams, type ClaimPartnerTradingFeeWithQuoteMintNotSolParams, type ClaimPartnerTradingFeeWithQuoteMintSolParams, type ClaimTradingFee2Params, type ClaimTradingFeeParams, CollectFeeMode, type ConfigParameters, type CreateConfigAccounts, type CreateConfigAndPoolParams, type CreateConfigAndPoolWithFirstBuyParams, type CreateConfigParams, type CreateDammV1MigrationMetadataParams, type CreateLockerParams, type CreatePartnerMetadataParameters, type CreatePartnerMetadataParams, type CreatePoolParams, type CreatePoolWithFirstBuyParams, type CreatePoolWithPartnerAndCreatorFirstBuyParams, type CreateVirtualPoolMetadataParams, type CreatorFirstBuyParams, CreatorService, type CreatorWithdrawSurplusParams, DAMM_V1_MIGRATION_FEE_ADDRESS, DAMM_V1_PROGRAM_ID, DAMM_V2_MIGRATION_FEE_ADDRESS, DAMM_V2_PROGRAM_ID, DYNAMIC_BONDING_CURVE_PROGRAM_ID, DYNAMIC_FEE_DECAY_PERIOD_DEFAULT, DYNAMIC_FEE_FILTER_PERIOD_DEFAULT, DYNAMIC_FEE_REDUCTION_FACTOR_DEFAULT, DYNAMIC_FEE_ROUNDING_OFFSET, DYNAMIC_FEE_SCALING_FACTOR, type DammLpTokenParams, DammV2DynamicFeeMode, DynamicBondingCurveClient, idl as DynamicBondingCurveIdl, DynamicBondingCurveProgram, type DynamicBondingCurve as DynamicBondingCurveTypes, type DynamicCurveProgram, type DynamicFeeConfig, type DynamicFeeParameters, FEE_DENOMINATOR, type FeeMode, type FeeOnAmountResult, FeeRateLimiter, type FeeResult, FeeScheduler, type FeeSchedulerParams, type FirstBuyParams, type InitializePoolBaseParams, type InitializePoolParameters, LOCKER_PROGRAM_ID, type LiquidityDistributionParameters, type LockEscrow, type LockedVestingParameters, type LockedVestingParams, MAX_CREATOR_MIGRATION_FEE_PERCENTAGE, MAX_CURVE_POINT, MAX_DYNAMIC_FEE_PERCENTAGE, MAX_FEE_BPS, MAX_FEE_NUMERATOR, MAX_MIGRATED_POOL_FEE_BPS, MAX_MIGRATION_FEE_PERCENTAGE, MAX_PRICE_CHANGE_BPS_DEFAULT, MAX_RATE_LIMITER_DURATION_IN_SECONDS, MAX_RATE_LIMITER_DURATION_IN_SLOTS, MAX_SQRT_PRICE, METAPLEX_PROGRAM_ID, MIN_FEE_BPS, MIN_FEE_NUMERATOR, MIN_MIGRATED_POOL_FEE_BPS, MIN_SQRT_PRICE, type MeteoraDammMigrationMetadata, type MigrateToDammV1Params, type MigrateToDammV2Params, type MigrateToDammV2Response, type MigratedPoolFee, MigrationFeeOption, MigrationOption, MigrationService, OFFSET, ONE_Q64, PARTNER_SURPLUS_SHARE, type PartnerFirstBuyParams, type PartnerMetadata, PartnerService, type PartnerWithdrawSurplusParams, type PoolConfig, type PoolFeeParameters, type PoolFees, type PoolFeesConfig, PoolService, type PreCreatePoolParams, type PrepareSwapParams, RESOLUTION, type RateLimiterParams, Rounding, SLOT_DURATION, SWAP_BUFFER_PERCENTAGE, SafeMath, StateService, type Swap2Params, type SwapAmount, SwapMode, type SwapParams, type SwapQuote2Params, type SwapQuote2Result, type SwapQuoteParams, type SwapQuoteResult, type SwapResult, type SwapResult2, TIMESTAMP_DURATION, TokenDecimal, TokenType, TokenUpdateAuthorityOption, TradeDirection, type TransferPoolCreatorParams, U128_MAX, U16_MAX, U64_MAX, VAULT_PROGRAM_ID, type VirtualPool, type VirtualPoolMetadata, type VolatilityTracker, type WithdrawLeftoverParams, type WithdrawMigrationFeeParams, bpsToFeeNumerator, buildCurve, buildCurveWithLiquidityWeights, buildCurveWithMarketCap, buildCurveWithTwoSegments, calculateBaseToQuoteFromAmountIn, calculateBaseToQuoteFromAmountOut, calculateFeeSchedulerEndingBaseFeeBps, calculateQuoteToBaseFromAmountIn, calculateQuoteToBaseFromAmountOut, checkRateLimiterApplied, cleanUpTokenAccountTx, convertDecimalToBN, convertToLamports, createDammV1Program, createDammV2Program, createDbcProgram, createInitializePermissionlessDynamicVaultIx, createLockEscrowIx, createProgramAccountFilter, createVaultProgram, deriveBaseKeyForLocker, deriveDammV1EventAuthority, deriveDammV1LockEscrowAddress, deriveDammV1LpMintAddress, deriveDammV1MigrationMetadataAddress, deriveDammV1PoolAddress, deriveDammV1PoolAuthority, deriveDammV1ProtocolFeeAddress, deriveDammV1VaultLPAddress, deriveDammV2EventAuthority, deriveDammV2LockEscrowAddress, deriveDammV2MigrationMetadataAddress, deriveDammV2PoolAddress, deriveDammV2PoolAuthority, deriveDammV2TokenVaultAddress, deriveDbcEventAuthority, deriveDbcPoolAddress, deriveDbcPoolAuthority, deriveDbcPoolMetadata, deriveDbcTokenVaultAddress, deriveEscrow, deriveLockerEventAuthority, deriveMintMetadata, derivePartnerMetadata, derivePositionAddress, derivePositionNftAccount, deriveTokenVaultKey, deriveVaultAddress, deriveVaultLpMintAddress, deriveVaultPdas, feeNumeratorToBps, findAssociatedTokenAddress, fromDecimalToBN, getAccountCreationTimestamp, getAccountCreationTimestamps, getAccountData, getBaseFeeHandler, getBaseFeeNumerator, getBaseFeeNumeratorByPeriod, getBaseFeeParams, getBaseTokenForSwap, getCheckedAmounts, getCurrentPoint, getDeltaAmountBaseUnsigned, getDeltaAmountBaseUnsigned256, getDeltaAmountBaseUnsignedUnchecked, getDeltaAmountQuoteUnsigned, getDeltaAmountQuoteUnsigned256, getDeltaAmountQuoteUnsignedUnchecked, getDynamicFeeParams, getExcludedFeeAmount, getFeeMode, getFeeNumeratorFromExcludedAmount, getFeeNumeratorFromIncludedAmount, getFeeNumeratorOnExponentialFeeScheduler, getFeeNumeratorOnLinearFeeScheduler, getFeeOnAmount, getFeeSchedulerParams, getFirstCurve, getFirstKey, getIncludedFeeAmount, getInitialLiquidityFromDeltaBase, getInitialLiquidityFromDeltaQuote, getLiquidity, getLockedVestingParams, getMaxBaseFeeNumerator, getMaxIndex, getMaxOutAmountWithMinBaseFee, getMigratedPoolFeeParams, getMigrationBaseToken, getMigrationQuoteAmount, getMigrationQuoteAmountFromMigrationQuoteThreshold, getMigrationQuoteThresholdFromMigrationQuoteAmount, getMigrationThresholdPrice, getMinBaseFeeNumerator, getNextSqrtPriceFromBaseAmountInRoundingUp, getNextSqrtPriceFromBaseAmountOutRoundingUp, getNextSqrtPriceFromInput, getNextSqrtPriceFromOutput, getNextSqrtPriceFromQuoteAmountInRoundingDown, getNextSqrtPriceFromQuoteAmountOutRoundingDown, getOrCreateATAInstruction, getPercentageSupplyOnMigration, getPriceFromSqrtPrice, getQuoteReserveFromNextSqrtPrice, getRateLimiterExcludedFeeAmount, getRateLimiterParams, getSecondKey, getSqrtPriceFromMarketCap, getSqrtPriceFromPrice, getSwapAmountWithBuffer, getSwapResult, getSwapResultFromExactInput, getSwapResultFromExactOutput, getSwapResultFromPartialInput, getTokenDecimals, getTokenProgram, getTokenType, getTokenomics, getTotalFeeNumerator, getTotalFeeNumeratorFromExcludedFeeAmount, getTotalFeeNumeratorFromIncludedFeeAmount, getTotalSupplyFromCurve, getTotalTokenSupply, getTotalVestingAmount, getTwoCurve, getVariableFeeNumerator, isDefaultLockedVesting, isDynamicFeeEnabled, isNativeSol, isNonZeroRateLimiter, isRateLimiterApplied, isZeroRateLimiter, mulDiv, mulShr, pow, prepareSwapAmountParam, prepareTokenAccountTx, splitFees, sqrt, swapQuote, swapQuoteExactIn, swapQuoteExactOut, swapQuotePartialFill, toNumerator, unwrapSOLInstruction, validateActivationType, validateBalance, validateBaseTokenType, validateCollectFeeMode, validateConfigParameters, validateCurve, validateFeeRateLimiter, validateFeeScheduler, validateLPPercentages, validateMigratedPoolFee, validateMigrationAndTokenType, validateMigrationFee, validateMigrationFeeOption, validatePoolFees, validateSwapAmount, validateTokenDecimals, validateTokenSupply, validateTokenUpdateAuthorityOptions, wrapSOLInstruction };
21690
+ export { ActivationType, BASE_ADDRESS, BASIS_POINT_MAX, BIN_STEP_BPS_DEFAULT, BIN_STEP_BPS_U128_DEFAULT, type BaseFee, type BaseFeeConfig, type BaseFeeHandler, BaseFeeMode, type BaseFeeParams, type BuildCurveBaseParams, type BuildCurveParams, type BuildCurveWithLiquidityWeightsParams, type BuildCurveWithMarketCapParams, type BuildCurveWithMidPriceParams, type BuildCurveWithTwoSegmentsParams, type ClaimCreatorTradingFee2Params, type ClaimCreatorTradingFeeParams, type ClaimCreatorTradingFeeWithQuoteMintNotSolParams, type ClaimCreatorTradingFeeWithQuoteMintSolParams, type ClaimPartnerTradingFeeWithQuoteMintNotSolParams, type ClaimPartnerTradingFeeWithQuoteMintSolParams, type ClaimTradingFee2Params, type ClaimTradingFeeParams, CollectFeeMode, type ConfigParameters, type CreateConfigAccounts, type CreateConfigAndPoolParams, type CreateConfigAndPoolWithFirstBuyParams, type CreateConfigParams, type CreateDammV1MigrationMetadataParams, type CreateLockerParams, type CreatePartnerMetadataParameters, type CreatePartnerMetadataParams, type CreatePoolParams, type CreatePoolWithFirstBuyParams, type CreatePoolWithPartnerAndCreatorFirstBuyParams, type CreateVirtualPoolMetadataParams, type CreatorFirstBuyParams, CreatorService, type CreatorWithdrawSurplusParams, DAMM_V1_MIGRATION_FEE_ADDRESS, DAMM_V1_PROGRAM_ID, DAMM_V2_MIGRATION_FEE_ADDRESS, DAMM_V2_PROGRAM_ID, DYNAMIC_BONDING_CURVE_PROGRAM_ID, DYNAMIC_FEE_DECAY_PERIOD_DEFAULT, DYNAMIC_FEE_FILTER_PERIOD_DEFAULT, DYNAMIC_FEE_REDUCTION_FACTOR_DEFAULT, DYNAMIC_FEE_ROUNDING_OFFSET, DYNAMIC_FEE_SCALING_FACTOR, type DammLpTokenParams, DammV2DynamicFeeMode, DynamicBondingCurveClient, idl as DynamicBondingCurveIdl, DynamicBondingCurveProgram, type DynamicBondingCurve as DynamicBondingCurveTypes, type DynamicCurveProgram, type DynamicFeeConfig, type DynamicFeeParameters, FEE_DENOMINATOR, type FeeMode, type FeeOnAmountResult, FeeRateLimiter, type FeeResult, FeeScheduler, type FeeSchedulerParams, type FirstBuyParams, type InitializePoolBaseParams, type InitializePoolParameters, LOCKER_PROGRAM_ID, type LiquidityDistributionParameters, type LockEscrow, type LockedVestingParameters, type LockedVestingParams, MAX_CREATOR_MIGRATION_FEE_PERCENTAGE, MAX_CURVE_POINT, MAX_DYNAMIC_FEE_PERCENTAGE, MAX_FEE_BPS, MAX_FEE_NUMERATOR, MAX_MIGRATED_POOL_FEE_BPS, MAX_MIGRATION_FEE_PERCENTAGE, MAX_PRICE_CHANGE_BPS_DEFAULT, MAX_RATE_LIMITER_DURATION_IN_SECONDS, MAX_RATE_LIMITER_DURATION_IN_SLOTS, MAX_SQRT_PRICE, METAPLEX_PROGRAM_ID, MIN_FEE_BPS, MIN_FEE_NUMERATOR, MIN_MIGRATED_POOL_FEE_BPS, MIN_SQRT_PRICE, type MeteoraDammMigrationMetadata, type MigrateToDammV1Params, type MigrateToDammV2Params, type MigrateToDammV2Response, type MigratedPoolFee, MigrationFeeOption, MigrationOption, MigrationService, OFFSET, ONE_Q64, PARTNER_SURPLUS_SHARE, type PartnerFirstBuyParams, type PartnerMetadata, PartnerService, type PartnerWithdrawSurplusParams, type PoolConfig, type PoolFeeParameters, type PoolFees, type PoolFeesConfig, PoolService, type PreCreatePoolParams, type PrepareSwapParams, RESOLUTION, type RateLimiterParams, Rounding, SLOT_DURATION, SWAP_BUFFER_PERCENTAGE, SafeMath, StateService, type Swap2Params, type SwapAmount, SwapMode, type SwapParams, type SwapQuote2Params, type SwapQuote2Result, type SwapQuoteParams, type SwapQuoteResult, type SwapResult, type SwapResult2, TIMESTAMP_DURATION, TokenDecimal, TokenType, TokenUpdateAuthorityOption, TradeDirection, type TransferPoolCreatorParams, U128_MAX, U16_MAX, U64_MAX, VAULT_PROGRAM_ID, type VirtualPool, type VirtualPoolMetadata, type VolatilityTracker, type WithdrawLeftoverParams, type WithdrawMigrationFeeParams, bpsToFeeNumerator, buildCurve, buildCurveWithLiquidityWeights, buildCurveWithMarketCap, buildCurveWithMidPrice, buildCurveWithTwoSegments, calculateBaseToQuoteFromAmountIn, calculateBaseToQuoteFromAmountOut, calculateFeeSchedulerEndingBaseFeeBps, calculateQuoteToBaseFromAmountIn, calculateQuoteToBaseFromAmountOut, checkRateLimiterApplied, cleanUpTokenAccountTx, convertDecimalToBN, convertToLamports, createDammV1Program, createDammV2Program, createDbcProgram, createInitializePermissionlessDynamicVaultIx, createLockEscrowIx, createProgramAccountFilter, createVaultProgram, deriveBaseKeyForLocker, deriveDammV1EventAuthority, deriveDammV1LockEscrowAddress, deriveDammV1LpMintAddress, deriveDammV1MigrationMetadataAddress, deriveDammV1PoolAddress, deriveDammV1PoolAuthority, deriveDammV1ProtocolFeeAddress, deriveDammV1VaultLPAddress, deriveDammV2EventAuthority, deriveDammV2LockEscrowAddress, deriveDammV2MigrationMetadataAddress, deriveDammV2PoolAddress, deriveDammV2PoolAuthority, deriveDammV2TokenVaultAddress, deriveDbcEventAuthority, deriveDbcPoolAddress, deriveDbcPoolAuthority, deriveDbcPoolMetadata, deriveDbcTokenVaultAddress, deriveEscrow, deriveLockerEventAuthority, deriveMintMetadata, derivePartnerMetadata, derivePositionAddress, derivePositionNftAccount, deriveTokenVaultKey, deriveVaultAddress, deriveVaultLpMintAddress, deriveVaultPdas, feeNumeratorToBps, findAssociatedTokenAddress, fromDecimalToBN, getAccountCreationTimestamp, getAccountCreationTimestamps, getAccountData, getBaseFeeHandler, getBaseFeeNumerator, getBaseFeeNumeratorByPeriod, getBaseFeeParams, getBaseTokenForSwap, getCheckedAmounts, getCurrentPoint, getCurveBreakdown, getDeltaAmountBaseUnsigned, getDeltaAmountBaseUnsigned256, getDeltaAmountBaseUnsignedUnchecked, getDeltaAmountQuoteUnsigned, getDeltaAmountQuoteUnsigned256, getDeltaAmountQuoteUnsignedUnchecked, getDynamicFeeParams, getExcludedFeeAmount, getFeeMode, getFeeNumeratorFromExcludedAmount, getFeeNumeratorFromIncludedAmount, getFeeNumeratorOnExponentialFeeScheduler, getFeeNumeratorOnLinearFeeScheduler, getFeeOnAmount, getFeeSchedulerParams, getFirstCurve, getFirstKey, getIncludedFeeAmount, getInitialLiquidityFromDeltaBase, getInitialLiquidityFromDeltaQuote, getLiquidity, getLockedVestingParams, getMaxBaseFeeNumerator, getMaxIndex, getMaxOutAmountWithMinBaseFee, getMigratedPoolFeeParams, getMigrationBaseToken, getMigrationQuoteAmount, getMigrationQuoteAmountFromMigrationQuoteThreshold, getMigrationQuoteThresholdFromMigrationQuoteAmount, getMigrationThresholdPrice, getMinBaseFeeNumerator, getNextSqrtPriceFromBaseAmountInRoundingUp, getNextSqrtPriceFromBaseAmountOutRoundingUp, getNextSqrtPriceFromInput, getNextSqrtPriceFromOutput, getNextSqrtPriceFromQuoteAmountInRoundingDown, getNextSqrtPriceFromQuoteAmountOutRoundingDown, getOrCreateATAInstruction, getPercentageSupplyOnMigration, getPriceFromSqrtPrice, getQuoteReserveFromNextSqrtPrice, getRateLimiterExcludedFeeAmount, getRateLimiterParams, getSecondKey, getSqrtPriceFromMarketCap, getSqrtPriceFromPrice, getSwapAmountWithBuffer, getSwapResult, getSwapResultFromExactInput, getSwapResultFromExactOutput, getSwapResultFromPartialInput, getTokenDecimals, getTokenProgram, getTokenType, getTokenomics, getTotalFeeNumerator, getTotalFeeNumeratorFromExcludedFeeAmount, getTotalFeeNumeratorFromIncludedFeeAmount, getTotalSupplyFromCurve, getTotalTokenSupply, getTotalVestingAmount, getTwoCurve, getVariableFeeNumerator, isDefaultLockedVesting, isDynamicFeeEnabled, isNativeSol, isNonZeroRateLimiter, isRateLimiterApplied, isZeroRateLimiter, mulDiv, mulShr, pow, prepareSwapAmountParam, prepareTokenAccountTx, splitFees, sqrt, swapQuote, swapQuoteExactIn, swapQuoteExactOut, swapQuotePartialFill, toNumerator, unwrapSOLInstruction, validateActivationType, validateBalance, validateBaseTokenType, validateCollectFeeMode, validateConfigParameters, validateCurve, validateFeeRateLimiter, validateFeeScheduler, validateLPPercentages, validateMigratedPoolFee, validateMigrationAndTokenType, validateMigrationFee, validateMigrationFeeOption, validatePoolFees, validateSwapAmount, validateTokenDecimals, validateTokenSupply, validateTokenUpdateAuthorityOptions, wrapSOLInstruction };
package/dist/index.d.ts CHANGED
@@ -5560,6 +5560,12 @@ type BuildCurveWithTwoSegmentsParams = BuildCurveBaseParams & {
5560
5560
  migrationMarketCap: number;
5561
5561
  percentageSupplyOnMigration: number;
5562
5562
  };
5563
+ type BuildCurveWithMidPriceParams = BuildCurveBaseParams & {
5564
+ initialMarketCap: number;
5565
+ migrationMarketCap: number;
5566
+ midPrice: number;
5567
+ percentageSupplyOnMigration: number;
5568
+ };
5563
5569
  type BuildCurveWithLiquidityWeightsParams = BuildCurveBaseParams & {
5564
5570
  initialMarketCap: number;
5565
5571
  migrationMarketCap: number;
@@ -6662,6 +6668,19 @@ declare const getTotalSupplyFromCurve: (migrationQuoteThreshold: BN$1, sqrtStart
6662
6668
  * @returns The migration threshold price
6663
6669
  */
6664
6670
  declare const getMigrationThresholdPrice: (migrationThreshold: BN$1, sqrtStartPrice: BN$1, curve: Array<LiquidityDistributionParameters>) => BN$1;
6671
+ /**
6672
+ * Calculate the quote amount allocated to each curve segment
6673
+ * Formula: Δb = L * (√P_upper - √P_lower) for each segment
6674
+ * @param migrationQuoteThreshold - The total migration quote threshold
6675
+ * @param sqrtStartPrice - The start sqrt price
6676
+ * @param curve - The curve segments with sqrtPrice and liquidity
6677
+ * @returns Array of quote amounts for each segment and the final sqrt price reached
6678
+ */
6679
+ declare const getCurveBreakdown: (migrationQuoteThreshold: BN$1, sqrtStartPrice: BN$1, curve: Array<LiquidityDistributionParameters>) => {
6680
+ segmentAmounts: BN$1[];
6681
+ finalSqrtPrice: BN$1;
6682
+ totalAmount: BN$1;
6683
+ };
6665
6684
  /**
6666
6685
  * Get the swap amount with buffer
6667
6686
  * @param swapBaseAmount - The swap base amount
@@ -7244,6 +7263,12 @@ declare function buildCurveWithMarketCap(buildCurveWithMarketCapParam: BuildCurv
7244
7263
  * @returns The build custom constant product curve by market cap
7245
7264
  */
7246
7265
  declare function buildCurveWithTwoSegments(buildCurveWithTwoSegmentsParam: BuildCurveWithTwoSegmentsParams): ConfigParameters;
7266
+ /**
7267
+ * Build a custom constant product curve with a mid price. This will create a two segment curve with a start price -> mid price, and a mid price -> migration price.
7268
+ * @param buildCurveWithMidPriceParam - The parameters for the custom constant product curve with a mid price
7269
+ * @returns The build custom constant product curve by mid price
7270
+ */
7271
+ declare function buildCurveWithMidPrice(buildCurveWithMidPriceParam: BuildCurveWithMidPriceParams): ConfigParameters;
7247
7272
  /**
7248
7273
  * Build a custom curve graph with liquidity weights, changing the curve shape based on the liquidity weights
7249
7274
  * @param buildCurveWithLiquidityWeightsParam - The parameters for the custom constant product curve with liquidity weights
@@ -21662,4 +21687,4 @@ var idl = {
21662
21687
  types: types
21663
21688
  };
21664
21689
 
21665
- export { ActivationType, BASE_ADDRESS, BASIS_POINT_MAX, BIN_STEP_BPS_DEFAULT, BIN_STEP_BPS_U128_DEFAULT, type BaseFee, type BaseFeeConfig, type BaseFeeHandler, BaseFeeMode, type BaseFeeParams, type BuildCurveBaseParams, type BuildCurveParams, type BuildCurveWithLiquidityWeightsParams, type BuildCurveWithMarketCapParams, type BuildCurveWithTwoSegmentsParams, type ClaimCreatorTradingFee2Params, type ClaimCreatorTradingFeeParams, type ClaimCreatorTradingFeeWithQuoteMintNotSolParams, type ClaimCreatorTradingFeeWithQuoteMintSolParams, type ClaimPartnerTradingFeeWithQuoteMintNotSolParams, type ClaimPartnerTradingFeeWithQuoteMintSolParams, type ClaimTradingFee2Params, type ClaimTradingFeeParams, CollectFeeMode, type ConfigParameters, type CreateConfigAccounts, type CreateConfigAndPoolParams, type CreateConfigAndPoolWithFirstBuyParams, type CreateConfigParams, type CreateDammV1MigrationMetadataParams, type CreateLockerParams, type CreatePartnerMetadataParameters, type CreatePartnerMetadataParams, type CreatePoolParams, type CreatePoolWithFirstBuyParams, type CreatePoolWithPartnerAndCreatorFirstBuyParams, type CreateVirtualPoolMetadataParams, type CreatorFirstBuyParams, CreatorService, type CreatorWithdrawSurplusParams, DAMM_V1_MIGRATION_FEE_ADDRESS, DAMM_V1_PROGRAM_ID, DAMM_V2_MIGRATION_FEE_ADDRESS, DAMM_V2_PROGRAM_ID, DYNAMIC_BONDING_CURVE_PROGRAM_ID, DYNAMIC_FEE_DECAY_PERIOD_DEFAULT, DYNAMIC_FEE_FILTER_PERIOD_DEFAULT, DYNAMIC_FEE_REDUCTION_FACTOR_DEFAULT, DYNAMIC_FEE_ROUNDING_OFFSET, DYNAMIC_FEE_SCALING_FACTOR, type DammLpTokenParams, DammV2DynamicFeeMode, DynamicBondingCurveClient, idl as DynamicBondingCurveIdl, DynamicBondingCurveProgram, type DynamicBondingCurve as DynamicBondingCurveTypes, type DynamicCurveProgram, type DynamicFeeConfig, type DynamicFeeParameters, FEE_DENOMINATOR, type FeeMode, type FeeOnAmountResult, FeeRateLimiter, type FeeResult, FeeScheduler, type FeeSchedulerParams, type FirstBuyParams, type InitializePoolBaseParams, type InitializePoolParameters, LOCKER_PROGRAM_ID, type LiquidityDistributionParameters, type LockEscrow, type LockedVestingParameters, type LockedVestingParams, MAX_CREATOR_MIGRATION_FEE_PERCENTAGE, MAX_CURVE_POINT, MAX_DYNAMIC_FEE_PERCENTAGE, MAX_FEE_BPS, MAX_FEE_NUMERATOR, MAX_MIGRATED_POOL_FEE_BPS, MAX_MIGRATION_FEE_PERCENTAGE, MAX_PRICE_CHANGE_BPS_DEFAULT, MAX_RATE_LIMITER_DURATION_IN_SECONDS, MAX_RATE_LIMITER_DURATION_IN_SLOTS, MAX_SQRT_PRICE, METAPLEX_PROGRAM_ID, MIN_FEE_BPS, MIN_FEE_NUMERATOR, MIN_MIGRATED_POOL_FEE_BPS, MIN_SQRT_PRICE, type MeteoraDammMigrationMetadata, type MigrateToDammV1Params, type MigrateToDammV2Params, type MigrateToDammV2Response, type MigratedPoolFee, MigrationFeeOption, MigrationOption, MigrationService, OFFSET, ONE_Q64, PARTNER_SURPLUS_SHARE, type PartnerFirstBuyParams, type PartnerMetadata, PartnerService, type PartnerWithdrawSurplusParams, type PoolConfig, type PoolFeeParameters, type PoolFees, type PoolFeesConfig, PoolService, type PreCreatePoolParams, type PrepareSwapParams, RESOLUTION, type RateLimiterParams, Rounding, SLOT_DURATION, SWAP_BUFFER_PERCENTAGE, SafeMath, StateService, type Swap2Params, type SwapAmount, SwapMode, type SwapParams, type SwapQuote2Params, type SwapQuote2Result, type SwapQuoteParams, type SwapQuoteResult, type SwapResult, type SwapResult2, TIMESTAMP_DURATION, TokenDecimal, TokenType, TokenUpdateAuthorityOption, TradeDirection, type TransferPoolCreatorParams, U128_MAX, U16_MAX, U64_MAX, VAULT_PROGRAM_ID, type VirtualPool, type VirtualPoolMetadata, type VolatilityTracker, type WithdrawLeftoverParams, type WithdrawMigrationFeeParams, bpsToFeeNumerator, buildCurve, buildCurveWithLiquidityWeights, buildCurveWithMarketCap, buildCurveWithTwoSegments, calculateBaseToQuoteFromAmountIn, calculateBaseToQuoteFromAmountOut, calculateFeeSchedulerEndingBaseFeeBps, calculateQuoteToBaseFromAmountIn, calculateQuoteToBaseFromAmountOut, checkRateLimiterApplied, cleanUpTokenAccountTx, convertDecimalToBN, convertToLamports, createDammV1Program, createDammV2Program, createDbcProgram, createInitializePermissionlessDynamicVaultIx, createLockEscrowIx, createProgramAccountFilter, createVaultProgram, deriveBaseKeyForLocker, deriveDammV1EventAuthority, deriveDammV1LockEscrowAddress, deriveDammV1LpMintAddress, deriveDammV1MigrationMetadataAddress, deriveDammV1PoolAddress, deriveDammV1PoolAuthority, deriveDammV1ProtocolFeeAddress, deriveDammV1VaultLPAddress, deriveDammV2EventAuthority, deriveDammV2LockEscrowAddress, deriveDammV2MigrationMetadataAddress, deriveDammV2PoolAddress, deriveDammV2PoolAuthority, deriveDammV2TokenVaultAddress, deriveDbcEventAuthority, deriveDbcPoolAddress, deriveDbcPoolAuthority, deriveDbcPoolMetadata, deriveDbcTokenVaultAddress, deriveEscrow, deriveLockerEventAuthority, deriveMintMetadata, derivePartnerMetadata, derivePositionAddress, derivePositionNftAccount, deriveTokenVaultKey, deriveVaultAddress, deriveVaultLpMintAddress, deriveVaultPdas, feeNumeratorToBps, findAssociatedTokenAddress, fromDecimalToBN, getAccountCreationTimestamp, getAccountCreationTimestamps, getAccountData, getBaseFeeHandler, getBaseFeeNumerator, getBaseFeeNumeratorByPeriod, getBaseFeeParams, getBaseTokenForSwap, getCheckedAmounts, getCurrentPoint, getDeltaAmountBaseUnsigned, getDeltaAmountBaseUnsigned256, getDeltaAmountBaseUnsignedUnchecked, getDeltaAmountQuoteUnsigned, getDeltaAmountQuoteUnsigned256, getDeltaAmountQuoteUnsignedUnchecked, getDynamicFeeParams, getExcludedFeeAmount, getFeeMode, getFeeNumeratorFromExcludedAmount, getFeeNumeratorFromIncludedAmount, getFeeNumeratorOnExponentialFeeScheduler, getFeeNumeratorOnLinearFeeScheduler, getFeeOnAmount, getFeeSchedulerParams, getFirstCurve, getFirstKey, getIncludedFeeAmount, getInitialLiquidityFromDeltaBase, getInitialLiquidityFromDeltaQuote, getLiquidity, getLockedVestingParams, getMaxBaseFeeNumerator, getMaxIndex, getMaxOutAmountWithMinBaseFee, getMigratedPoolFeeParams, getMigrationBaseToken, getMigrationQuoteAmount, getMigrationQuoteAmountFromMigrationQuoteThreshold, getMigrationQuoteThresholdFromMigrationQuoteAmount, getMigrationThresholdPrice, getMinBaseFeeNumerator, getNextSqrtPriceFromBaseAmountInRoundingUp, getNextSqrtPriceFromBaseAmountOutRoundingUp, getNextSqrtPriceFromInput, getNextSqrtPriceFromOutput, getNextSqrtPriceFromQuoteAmountInRoundingDown, getNextSqrtPriceFromQuoteAmountOutRoundingDown, getOrCreateATAInstruction, getPercentageSupplyOnMigration, getPriceFromSqrtPrice, getQuoteReserveFromNextSqrtPrice, getRateLimiterExcludedFeeAmount, getRateLimiterParams, getSecondKey, getSqrtPriceFromMarketCap, getSqrtPriceFromPrice, getSwapAmountWithBuffer, getSwapResult, getSwapResultFromExactInput, getSwapResultFromExactOutput, getSwapResultFromPartialInput, getTokenDecimals, getTokenProgram, getTokenType, getTokenomics, getTotalFeeNumerator, getTotalFeeNumeratorFromExcludedFeeAmount, getTotalFeeNumeratorFromIncludedFeeAmount, getTotalSupplyFromCurve, getTotalTokenSupply, getTotalVestingAmount, getTwoCurve, getVariableFeeNumerator, isDefaultLockedVesting, isDynamicFeeEnabled, isNativeSol, isNonZeroRateLimiter, isRateLimiterApplied, isZeroRateLimiter, mulDiv, mulShr, pow, prepareSwapAmountParam, prepareTokenAccountTx, splitFees, sqrt, swapQuote, swapQuoteExactIn, swapQuoteExactOut, swapQuotePartialFill, toNumerator, unwrapSOLInstruction, validateActivationType, validateBalance, validateBaseTokenType, validateCollectFeeMode, validateConfigParameters, validateCurve, validateFeeRateLimiter, validateFeeScheduler, validateLPPercentages, validateMigratedPoolFee, validateMigrationAndTokenType, validateMigrationFee, validateMigrationFeeOption, validatePoolFees, validateSwapAmount, validateTokenDecimals, validateTokenSupply, validateTokenUpdateAuthorityOptions, wrapSOLInstruction };
21690
+ export { ActivationType, BASE_ADDRESS, BASIS_POINT_MAX, BIN_STEP_BPS_DEFAULT, BIN_STEP_BPS_U128_DEFAULT, type BaseFee, type BaseFeeConfig, type BaseFeeHandler, BaseFeeMode, type BaseFeeParams, type BuildCurveBaseParams, type BuildCurveParams, type BuildCurveWithLiquidityWeightsParams, type BuildCurveWithMarketCapParams, type BuildCurveWithMidPriceParams, type BuildCurveWithTwoSegmentsParams, type ClaimCreatorTradingFee2Params, type ClaimCreatorTradingFeeParams, type ClaimCreatorTradingFeeWithQuoteMintNotSolParams, type ClaimCreatorTradingFeeWithQuoteMintSolParams, type ClaimPartnerTradingFeeWithQuoteMintNotSolParams, type ClaimPartnerTradingFeeWithQuoteMintSolParams, type ClaimTradingFee2Params, type ClaimTradingFeeParams, CollectFeeMode, type ConfigParameters, type CreateConfigAccounts, type CreateConfigAndPoolParams, type CreateConfigAndPoolWithFirstBuyParams, type CreateConfigParams, type CreateDammV1MigrationMetadataParams, type CreateLockerParams, type CreatePartnerMetadataParameters, type CreatePartnerMetadataParams, type CreatePoolParams, type CreatePoolWithFirstBuyParams, type CreatePoolWithPartnerAndCreatorFirstBuyParams, type CreateVirtualPoolMetadataParams, type CreatorFirstBuyParams, CreatorService, type CreatorWithdrawSurplusParams, DAMM_V1_MIGRATION_FEE_ADDRESS, DAMM_V1_PROGRAM_ID, DAMM_V2_MIGRATION_FEE_ADDRESS, DAMM_V2_PROGRAM_ID, DYNAMIC_BONDING_CURVE_PROGRAM_ID, DYNAMIC_FEE_DECAY_PERIOD_DEFAULT, DYNAMIC_FEE_FILTER_PERIOD_DEFAULT, DYNAMIC_FEE_REDUCTION_FACTOR_DEFAULT, DYNAMIC_FEE_ROUNDING_OFFSET, DYNAMIC_FEE_SCALING_FACTOR, type DammLpTokenParams, DammV2DynamicFeeMode, DynamicBondingCurveClient, idl as DynamicBondingCurveIdl, DynamicBondingCurveProgram, type DynamicBondingCurve as DynamicBondingCurveTypes, type DynamicCurveProgram, type DynamicFeeConfig, type DynamicFeeParameters, FEE_DENOMINATOR, type FeeMode, type FeeOnAmountResult, FeeRateLimiter, type FeeResult, FeeScheduler, type FeeSchedulerParams, type FirstBuyParams, type InitializePoolBaseParams, type InitializePoolParameters, LOCKER_PROGRAM_ID, type LiquidityDistributionParameters, type LockEscrow, type LockedVestingParameters, type LockedVestingParams, MAX_CREATOR_MIGRATION_FEE_PERCENTAGE, MAX_CURVE_POINT, MAX_DYNAMIC_FEE_PERCENTAGE, MAX_FEE_BPS, MAX_FEE_NUMERATOR, MAX_MIGRATED_POOL_FEE_BPS, MAX_MIGRATION_FEE_PERCENTAGE, MAX_PRICE_CHANGE_BPS_DEFAULT, MAX_RATE_LIMITER_DURATION_IN_SECONDS, MAX_RATE_LIMITER_DURATION_IN_SLOTS, MAX_SQRT_PRICE, METAPLEX_PROGRAM_ID, MIN_FEE_BPS, MIN_FEE_NUMERATOR, MIN_MIGRATED_POOL_FEE_BPS, MIN_SQRT_PRICE, type MeteoraDammMigrationMetadata, type MigrateToDammV1Params, type MigrateToDammV2Params, type MigrateToDammV2Response, type MigratedPoolFee, MigrationFeeOption, MigrationOption, MigrationService, OFFSET, ONE_Q64, PARTNER_SURPLUS_SHARE, type PartnerFirstBuyParams, type PartnerMetadata, PartnerService, type PartnerWithdrawSurplusParams, type PoolConfig, type PoolFeeParameters, type PoolFees, type PoolFeesConfig, PoolService, type PreCreatePoolParams, type PrepareSwapParams, RESOLUTION, type RateLimiterParams, Rounding, SLOT_DURATION, SWAP_BUFFER_PERCENTAGE, SafeMath, StateService, type Swap2Params, type SwapAmount, SwapMode, type SwapParams, type SwapQuote2Params, type SwapQuote2Result, type SwapQuoteParams, type SwapQuoteResult, type SwapResult, type SwapResult2, TIMESTAMP_DURATION, TokenDecimal, TokenType, TokenUpdateAuthorityOption, TradeDirection, type TransferPoolCreatorParams, U128_MAX, U16_MAX, U64_MAX, VAULT_PROGRAM_ID, type VirtualPool, type VirtualPoolMetadata, type VolatilityTracker, type WithdrawLeftoverParams, type WithdrawMigrationFeeParams, bpsToFeeNumerator, buildCurve, buildCurveWithLiquidityWeights, buildCurveWithMarketCap, buildCurveWithMidPrice, buildCurveWithTwoSegments, calculateBaseToQuoteFromAmountIn, calculateBaseToQuoteFromAmountOut, calculateFeeSchedulerEndingBaseFeeBps, calculateQuoteToBaseFromAmountIn, calculateQuoteToBaseFromAmountOut, checkRateLimiterApplied, cleanUpTokenAccountTx, convertDecimalToBN, convertToLamports, createDammV1Program, createDammV2Program, createDbcProgram, createInitializePermissionlessDynamicVaultIx, createLockEscrowIx, createProgramAccountFilter, createVaultProgram, deriveBaseKeyForLocker, deriveDammV1EventAuthority, deriveDammV1LockEscrowAddress, deriveDammV1LpMintAddress, deriveDammV1MigrationMetadataAddress, deriveDammV1PoolAddress, deriveDammV1PoolAuthority, deriveDammV1ProtocolFeeAddress, deriveDammV1VaultLPAddress, deriveDammV2EventAuthority, deriveDammV2LockEscrowAddress, deriveDammV2MigrationMetadataAddress, deriveDammV2PoolAddress, deriveDammV2PoolAuthority, deriveDammV2TokenVaultAddress, deriveDbcEventAuthority, deriveDbcPoolAddress, deriveDbcPoolAuthority, deriveDbcPoolMetadata, deriveDbcTokenVaultAddress, deriveEscrow, deriveLockerEventAuthority, deriveMintMetadata, derivePartnerMetadata, derivePositionAddress, derivePositionNftAccount, deriveTokenVaultKey, deriveVaultAddress, deriveVaultLpMintAddress, deriveVaultPdas, feeNumeratorToBps, findAssociatedTokenAddress, fromDecimalToBN, getAccountCreationTimestamp, getAccountCreationTimestamps, getAccountData, getBaseFeeHandler, getBaseFeeNumerator, getBaseFeeNumeratorByPeriod, getBaseFeeParams, getBaseTokenForSwap, getCheckedAmounts, getCurrentPoint, getCurveBreakdown, getDeltaAmountBaseUnsigned, getDeltaAmountBaseUnsigned256, getDeltaAmountBaseUnsignedUnchecked, getDeltaAmountQuoteUnsigned, getDeltaAmountQuoteUnsigned256, getDeltaAmountQuoteUnsignedUnchecked, getDynamicFeeParams, getExcludedFeeAmount, getFeeMode, getFeeNumeratorFromExcludedAmount, getFeeNumeratorFromIncludedAmount, getFeeNumeratorOnExponentialFeeScheduler, getFeeNumeratorOnLinearFeeScheduler, getFeeOnAmount, getFeeSchedulerParams, getFirstCurve, getFirstKey, getIncludedFeeAmount, getInitialLiquidityFromDeltaBase, getInitialLiquidityFromDeltaQuote, getLiquidity, getLockedVestingParams, getMaxBaseFeeNumerator, getMaxIndex, getMaxOutAmountWithMinBaseFee, getMigratedPoolFeeParams, getMigrationBaseToken, getMigrationQuoteAmount, getMigrationQuoteAmountFromMigrationQuoteThreshold, getMigrationQuoteThresholdFromMigrationQuoteAmount, getMigrationThresholdPrice, getMinBaseFeeNumerator, getNextSqrtPriceFromBaseAmountInRoundingUp, getNextSqrtPriceFromBaseAmountOutRoundingUp, getNextSqrtPriceFromInput, getNextSqrtPriceFromOutput, getNextSqrtPriceFromQuoteAmountInRoundingDown, getNextSqrtPriceFromQuoteAmountOutRoundingDown, getOrCreateATAInstruction, getPercentageSupplyOnMigration, getPriceFromSqrtPrice, getQuoteReserveFromNextSqrtPrice, getRateLimiterExcludedFeeAmount, getRateLimiterParams, getSecondKey, getSqrtPriceFromMarketCap, getSqrtPriceFromPrice, getSwapAmountWithBuffer, getSwapResult, getSwapResultFromExactInput, getSwapResultFromExactOutput, getSwapResultFromPartialInput, getTokenDecimals, getTokenProgram, getTokenType, getTokenomics, getTotalFeeNumerator, getTotalFeeNumeratorFromExcludedFeeAmount, getTotalFeeNumeratorFromIncludedFeeAmount, getTotalSupplyFromCurve, getTotalTokenSupply, getTotalVestingAmount, getTwoCurve, getVariableFeeNumerator, isDefaultLockedVesting, isDynamicFeeEnabled, isNativeSol, isNonZeroRateLimiter, isRateLimiterApplied, isZeroRateLimiter, mulDiv, mulShr, pow, prepareSwapAmountParam, prepareTokenAccountTx, splitFees, sqrt, swapQuote, swapQuoteExactIn, swapQuoteExactOut, swapQuotePartialFill, toNumerator, unwrapSOLInstruction, validateActivationType, validateBalance, validateBaseTokenType, validateCollectFeeMode, validateConfigParameters, validateCurve, validateFeeRateLimiter, validateFeeScheduler, validateLPPercentages, validateMigratedPoolFee, validateMigrationAndTokenType, validateMigrationFee, validateMigrationFeeOption, validatePoolFees, validateSwapAmount, validateTokenDecimals, validateTokenSupply, validateTokenUpdateAuthorityOptions, wrapSOLInstruction };
package/dist/index.js CHANGED
@@ -933,6 +933,56 @@ var getMigrationThresholdPrice = (migrationThreshold, sqrtStartPrice, curve) =>
933
933
  }
934
934
  return nextSqrtPrice;
935
935
  };
936
+ var getCurveBreakdown = (migrationQuoteThreshold, sqrtStartPrice, curve) => {
937
+ if (curve.length === 0) {
938
+ throw Error("Curve is empty");
939
+ }
940
+ const segmentAmounts = [];
941
+ let totalAllocated = new BN6(0);
942
+ let currentSqrtPrice = sqrtStartPrice;
943
+ let finalSqrtPrice = sqrtStartPrice;
944
+ for (let i = 0; i < curve.length; i++) {
945
+ const lowerSqrtPrice = currentSqrtPrice;
946
+ const upperSqrtPrice = curve[i].sqrtPrice;
947
+ const liquidity = curve[i].liquidity;
948
+ const maxSegmentAmount = getDeltaAmountQuoteUnsigned(
949
+ lowerSqrtPrice,
950
+ upperSqrtPrice,
951
+ liquidity,
952
+ 0 /* Up */
953
+ );
954
+ if (maxSegmentAmount.gte(migrationQuoteThreshold)) {
955
+ segmentAmounts.push(migrationQuoteThreshold);
956
+ totalAllocated = totalAllocated.add(migrationQuoteThreshold);
957
+ finalSqrtPrice = getNextSqrtPriceFromInput(
958
+ lowerSqrtPrice,
959
+ liquidity,
960
+ migrationQuoteThreshold,
961
+ false
962
+ );
963
+ for (let j = i + 1; j < curve.length; j++) {
964
+ segmentAmounts.push(new BN6(0));
965
+ }
966
+ break;
967
+ } else {
968
+ segmentAmounts.push(maxSegmentAmount);
969
+ totalAllocated = totalAllocated.add(maxSegmentAmount);
970
+ currentSqrtPrice = upperSqrtPrice;
971
+ finalSqrtPrice = upperSqrtPrice;
972
+ if (i === curve.length - 1 && totalAllocated.lt(migrationQuoteThreshold)) {
973
+ const shortfall = migrationQuoteThreshold.sub(totalAllocated);
974
+ throw Error(
975
+ `Not enough liquidity in curve. Total allocated: ${totalAllocated.toString()}, Required: ${migrationQuoteThreshold.toString()}, Shortfall: ${shortfall.toString()}`
976
+ );
977
+ }
978
+ }
979
+ }
980
+ return {
981
+ segmentAmounts,
982
+ finalSqrtPrice,
983
+ totalAmount: totalAllocated
984
+ };
985
+ };
936
986
  var getSwapAmountWithBuffer = (swapBaseAmount, sqrtStartPrice, curve) => {
937
987
  const swapAmountBuffer = swapBaseAmount.add(
938
988
  swapBaseAmount.mul(new BN6(SWAP_BUFFER_PERCENTAGE)).div(new BN6(100))
@@ -3532,7 +3582,7 @@ function buildCurveWithTwoSegments(buildCurveWithTwoSegmentsParam) {
3532
3582
  let product2 = numerator3.mul(numerator4);
3533
3583
  let midSqrtPriceDecimal3 = Decimal4.pow(product2, 0.25);
3534
3584
  let midSqrtPrice3 = new BN14(midSqrtPriceDecimal3.floor().toFixed());
3535
- let midPrices = [midSqrtPrice1, midSqrtPrice2, midSqrtPrice3];
3585
+ let midPrices = [midSqrtPrice3, midSqrtPrice2, midSqrtPrice1];
3536
3586
  let sqrtStartPrice = new BN14(0);
3537
3587
  let curve = [];
3538
3588
  for (let i = 0; i < midPrices.length; i++) {
@@ -3603,6 +3653,165 @@ function buildCurveWithTwoSegments(buildCurveWithTwoSegmentsParam) {
3603
3653
  };
3604
3654
  return instructionParams;
3605
3655
  }
3656
+ function buildCurveWithMidPrice(buildCurveWithMidPriceParam) {
3657
+ const {
3658
+ totalTokenSupply,
3659
+ initialMarketCap,
3660
+ migrationMarketCap,
3661
+ midPrice,
3662
+ percentageSupplyOnMigration,
3663
+ migrationOption,
3664
+ tokenBaseDecimal,
3665
+ tokenQuoteDecimal,
3666
+ creatorTradingFeePercentage,
3667
+ collectFeeMode,
3668
+ leftover,
3669
+ tokenType,
3670
+ partnerLpPercentage,
3671
+ creatorLpPercentage,
3672
+ partnerLockedLpPercentage,
3673
+ creatorLockedLpPercentage,
3674
+ activationType,
3675
+ dynamicFeeEnabled,
3676
+ migrationFeeOption,
3677
+ migrationFee,
3678
+ tokenUpdateAuthority,
3679
+ baseFeeParams,
3680
+ migratedPoolFee
3681
+ } = buildCurveWithMidPriceParam;
3682
+ const baseFee = getBaseFeeParams(
3683
+ baseFeeParams,
3684
+ tokenQuoteDecimal,
3685
+ activationType
3686
+ );
3687
+ const {
3688
+ totalLockedVestingAmount,
3689
+ numberOfVestingPeriod,
3690
+ cliffUnlockAmount,
3691
+ totalVestingDuration,
3692
+ cliffDurationFromMigrationTime
3693
+ } = buildCurveWithMidPriceParam.lockedVestingParam;
3694
+ const lockedVesting = getLockedVestingParams(
3695
+ totalLockedVestingAmount,
3696
+ numberOfVestingPeriod,
3697
+ cliffUnlockAmount,
3698
+ totalVestingDuration,
3699
+ cliffDurationFromMigrationTime,
3700
+ tokenBaseDecimal
3701
+ );
3702
+ const migratedPoolFeeParams = getMigratedPoolFeeParams(
3703
+ migrationOption,
3704
+ migrationFeeOption,
3705
+ migratedPoolFee
3706
+ );
3707
+ let migrationBaseSupply = new BN14(totalTokenSupply).mul(new BN14(percentageSupplyOnMigration)).div(new BN14(100));
3708
+ let totalSupply = convertToLamports(totalTokenSupply, tokenBaseDecimal);
3709
+ let migrationQuoteAmount = getMigrationQuoteAmount(
3710
+ new Decimal4(migrationMarketCap),
3711
+ new Decimal4(percentageSupplyOnMigration)
3712
+ );
3713
+ let migrationQuoteThreshold = getMigrationQuoteThresholdFromMigrationQuoteAmount(
3714
+ migrationQuoteAmount,
3715
+ new Decimal4(migrationFee.feePercentage)
3716
+ );
3717
+ let migrationPrice = migrationQuoteAmount.div(
3718
+ new Decimal4(migrationBaseSupply.toString())
3719
+ );
3720
+ let migrationQuoteThresholdInLamport = fromDecimalToBN(
3721
+ migrationQuoteThreshold.mul(new Decimal4(10 ** tokenQuoteDecimal))
3722
+ );
3723
+ let migrationQuoteAmountInLamport = fromDecimalToBN(
3724
+ migrationQuoteAmount.mul(new Decimal4(10 ** tokenQuoteDecimal))
3725
+ );
3726
+ let migrateSqrtPrice = getSqrtPriceFromPrice(
3727
+ migrationPrice.toString(),
3728
+ tokenBaseDecimal,
3729
+ tokenQuoteDecimal
3730
+ );
3731
+ let migrationBaseAmount = getMigrationBaseToken(
3732
+ migrationQuoteAmountInLamport,
3733
+ migrateSqrtPrice,
3734
+ migrationOption
3735
+ );
3736
+ let totalVestingAmount = getTotalVestingAmount(lockedVesting);
3737
+ let totalLeftover = convertToLamports(leftover, tokenBaseDecimal);
3738
+ let swapAmount = totalSupply.sub(migrationBaseAmount).sub(totalVestingAmount).sub(totalLeftover);
3739
+ let initialSqrtPrice = getSqrtPriceFromMarketCap(
3740
+ initialMarketCap,
3741
+ totalTokenSupply,
3742
+ tokenBaseDecimal,
3743
+ tokenQuoteDecimal
3744
+ );
3745
+ const midSqrtPrice = getSqrtPriceFromPrice(
3746
+ midPrice.toString(),
3747
+ tokenBaseDecimal,
3748
+ tokenQuoteDecimal
3749
+ );
3750
+ let sqrtStartPrice = new BN14(0);
3751
+ let curve = [];
3752
+ const result = getTwoCurve(
3753
+ migrateSqrtPrice,
3754
+ midSqrtPrice,
3755
+ initialSqrtPrice,
3756
+ swapAmount,
3757
+ migrationQuoteThresholdInLamport
3758
+ );
3759
+ curve = result.curve;
3760
+ sqrtStartPrice = result.sqrtStartPrice;
3761
+ let totalDynamicSupply = getTotalSupplyFromCurve(
3762
+ migrationQuoteThresholdInLamport,
3763
+ sqrtStartPrice,
3764
+ curve,
3765
+ lockedVesting,
3766
+ migrationOption,
3767
+ totalLeftover,
3768
+ migrationFee.feePercentage
3769
+ );
3770
+ if (totalDynamicSupply.gt(totalSupply)) {
3771
+ let leftOverDelta = totalDynamicSupply.sub(totalSupply);
3772
+ if (!leftOverDelta.lt(totalLeftover)) {
3773
+ throw new Error("leftOverDelta must be less than totalLeftover");
3774
+ }
3775
+ }
3776
+ const instructionParams = {
3777
+ poolFees: {
3778
+ baseFee: {
3779
+ ...baseFee
3780
+ },
3781
+ dynamicFee: dynamicFeeEnabled ? getDynamicFeeParams(
3782
+ baseFeeParams.baseFeeMode === 2 /* RateLimiter */ ? baseFeeParams.rateLimiterParam.baseFeeBps : baseFeeParams.feeSchedulerParam.endingFeeBps
3783
+ ) : null
3784
+ },
3785
+ activationType,
3786
+ collectFeeMode,
3787
+ migrationOption,
3788
+ tokenType,
3789
+ tokenDecimal: tokenBaseDecimal,
3790
+ migrationQuoteThreshold: migrationQuoteThresholdInLamport,
3791
+ partnerLpPercentage,
3792
+ creatorLpPercentage,
3793
+ partnerLockedLpPercentage,
3794
+ creatorLockedLpPercentage,
3795
+ sqrtStartPrice,
3796
+ lockedVesting,
3797
+ migrationFeeOption,
3798
+ tokenSupply: {
3799
+ preMigrationTokenSupply: totalSupply,
3800
+ postMigrationTokenSupply: totalSupply
3801
+ },
3802
+ creatorTradingFeePercentage,
3803
+ migratedPoolFee: {
3804
+ collectFeeMode: migratedPoolFeeParams.collectFeeMode,
3805
+ dynamicFee: migratedPoolFeeParams.dynamicFee,
3806
+ poolFeeBps: migratedPoolFeeParams.poolFeeBps
3807
+ },
3808
+ padding: [],
3809
+ curve,
3810
+ tokenUpdateAuthority,
3811
+ migrationFee
3812
+ };
3813
+ return instructionParams;
3814
+ }
3606
3815
  function buildCurveWithLiquidityWeights(buildCurveWithLiquidityWeightsParam) {
3607
3816
  let {
3608
3817
  totalTokenSupply,
@@ -26350,6 +26559,7 @@ export {
26350
26559
  buildCurve,
26351
26560
  buildCurveWithLiquidityWeights,
26352
26561
  buildCurveWithMarketCap,
26562
+ buildCurveWithMidPrice,
26353
26563
  buildCurveWithTwoSegments,
26354
26564
  calculateBaseToQuoteFromAmountIn,
26355
26565
  calculateBaseToQuoteFromAmountOut,
@@ -26410,6 +26620,7 @@ export {
26410
26620
  getBaseTokenForSwap,
26411
26621
  getCheckedAmounts,
26412
26622
  getCurrentPoint,
26623
+ getCurveBreakdown,
26413
26624
  getDeltaAmountBaseUnsigned,
26414
26625
  getDeltaAmountBaseUnsigned256,
26415
26626
  getDeltaAmountBaseUnsignedUnchecked,