@meteora-ag/dynamic-bonding-curve-sdk 1.2.9-rc.2 → 1.2.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.cjs CHANGED
@@ -26,11 +26,11 @@ var MigrationOption = /* @__PURE__ */ ((MigrationOption2) => {
26
26
  MigrationOption2[MigrationOption2["MET_DAMM_V2"] = 1] = "MET_DAMM_V2";
27
27
  return MigrationOption2;
28
28
  })(MigrationOption || {});
29
- var BaseFeeMode = /* @__PURE__ */ ((BaseFeeMode3) => {
30
- BaseFeeMode3[BaseFeeMode3["FeeSchedulerLinear"] = 0] = "FeeSchedulerLinear";
31
- BaseFeeMode3[BaseFeeMode3["FeeSchedulerExponential"] = 1] = "FeeSchedulerExponential";
32
- BaseFeeMode3[BaseFeeMode3["RateLimiter"] = 2] = "RateLimiter";
33
- return BaseFeeMode3;
29
+ var BaseFeeMode = /* @__PURE__ */ ((BaseFeeMode2) => {
30
+ BaseFeeMode2[BaseFeeMode2["FeeSchedulerLinear"] = 0] = "FeeSchedulerLinear";
31
+ BaseFeeMode2[BaseFeeMode2["FeeSchedulerExponential"] = 1] = "FeeSchedulerExponential";
32
+ BaseFeeMode2[BaseFeeMode2["RateLimiter"] = 2] = "RateLimiter";
33
+ return BaseFeeMode2;
34
34
  })(BaseFeeMode || {});
35
35
  var MigrationFeeOption = /* @__PURE__ */ ((MigrationFeeOption2) => {
36
36
  MigrationFeeOption2[MigrationFeeOption2["FixedBps25"] = 0] = "FixedBps25";
@@ -21951,7 +21951,6 @@ var PoolService = class extends DynamicBondingCurveProgram {
21951
21951
  * @returns A transaction that creates the config
21952
21952
  */
21953
21953
  async createConfigTx(configParam, config, feeClaimer, leftoverReceiver, quoteMint, payer) {
21954
- validateConfigParameters({ ...configParam, leftoverReceiver });
21955
21954
  return this.program.methods.createConfig(configParam).accountsPartial({
21956
21955
  config,
21957
21956
  feeClaimer,
@@ -22001,11 +22000,21 @@ var PoolService = class extends DynamicBondingCurveProgram {
22001
22000
  * @param payerAddress - The payer address
22002
22001
  * @returns Instructions for the first buy
22003
22002
  */
22004
- async swapBuyTx(firstBuyParam, baseMint, config, baseFeeMode, tokenType, quoteMint) {
22005
- const { buyer, buyAmount, minimumAmountOut, referralTokenAccount } = firstBuyParam;
22003
+ async swapBuyTx(createConfigAndPoolWithFirstBuyParam, config, quoteMint) {
22004
+ const { baseMint, poolCreator } = createConfigAndPoolWithFirstBuyParam.createPoolParam;
22005
+ const { buyAmount, minimumAmountOut, referralTokenAccount } = createConfigAndPoolWithFirstBuyParam.swapBuyParam;
22006
22006
  validateSwapAmount(buyAmount);
22007
+ let currentPoint;
22008
+ if (createConfigAndPoolWithFirstBuyParam.activationType === 0 /* Slot */) {
22009
+ const currentSlot = await this.connection.getSlot();
22010
+ currentPoint = currentSlot;
22011
+ } else {
22012
+ const currentSlot = await this.connection.getSlot();
22013
+ const currentTime = await this.connection.getBlockTime(currentSlot);
22014
+ currentPoint = currentTime;
22015
+ }
22007
22016
  const isRateLimiterApplied = checkRateLimiterApplied(
22008
- baseFeeMode,
22017
+ createConfigAndPoolWithFirstBuyParam.poolFees.baseFee.baseFeeMode,
22009
22018
  false,
22010
22019
  new (0, _bnjs2.default)(0),
22011
22020
  new (0, _bnjs2.default)(0),
@@ -22016,7 +22025,7 @@ var PoolService = class extends DynamicBondingCurveProgram {
22016
22025
  false,
22017
22026
  {
22018
22027
  baseMint,
22019
- poolType: tokenType
22028
+ poolType: createConfigAndPoolWithFirstBuyParam.tokenType
22020
22029
  },
22021
22030
  {
22022
22031
  quoteMint,
@@ -22031,8 +22040,8 @@ var PoolService = class extends DynamicBondingCurveProgram {
22031
22040
  ataTokenB: outputTokenAccount,
22032
22041
  instructions: preInstructions
22033
22042
  } = await this.prepareTokenAccounts(
22034
- buyer,
22035
- buyer,
22043
+ poolCreator,
22044
+ poolCreator,
22036
22045
  inputMint,
22037
22046
  outputMint,
22038
22047
  inputTokenProgram,
@@ -22041,7 +22050,7 @@ var PoolService = class extends DynamicBondingCurveProgram {
22041
22050
  if (inputMint.equals(_spltoken.NATIVE_MINT)) {
22042
22051
  preInstructions.push(
22043
22052
  ...wrapSOLInstruction(
22044
- buyer,
22053
+ poolCreator,
22045
22054
  inputTokenAccount,
22046
22055
  BigInt(buyAmount.toString())
22047
22056
  )
@@ -22051,7 +22060,7 @@ var PoolService = class extends DynamicBondingCurveProgram {
22051
22060
  if ([inputMint.toBase58(), outputMint.toBase58()].includes(
22052
22061
  _spltoken.NATIVE_MINT.toBase58()
22053
22062
  )) {
22054
- const unwrapIx = unwrapSOLInstruction(buyer, buyer);
22063
+ const unwrapIx = unwrapSOLInstruction(poolCreator, poolCreator);
22055
22064
  unwrapIx && postInstructions.push(unwrapIx);
22056
22065
  }
22057
22066
  const remainingAccounts = isRateLimiterApplied ? [
@@ -22075,7 +22084,7 @@ var PoolService = class extends DynamicBondingCurveProgram {
22075
22084
  referralTokenAccount,
22076
22085
  inputTokenAccount,
22077
22086
  outputTokenAccount,
22078
- payer: buyer,
22087
+ payer: poolCreator,
22079
22088
  tokenBaseProgram: outputTokenProgram,
22080
22089
  tokenQuoteProgram: inputTokenProgram
22081
22090
  }).remainingAccounts(remainingAccounts).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
@@ -22126,31 +22135,47 @@ var PoolService = class extends DynamicBondingCurveProgram {
22126
22135
  payer,
22127
22136
  ...configParam
22128
22137
  } = createConfigAndPoolParam;
22138
+ const { baseMint, name, symbol, uri, poolCreator } = createConfigAndPoolParam.createPoolParam;
22139
+ validateConfigParameters({ ...configParam, leftoverReceiver });
22129
22140
  const configKey = new (0, _web3js.PublicKey)(config);
22130
22141
  const quoteMintToken = new (0, _web3js.PublicKey)(quoteMint);
22131
22142
  const payerAddress = new (0, _web3js.PublicKey)(payer);
22132
- const feeClaimerAddress = new (0, _web3js.PublicKey)(feeClaimer);
22133
- const leftoverReceiverAddress = new (0, _web3js.PublicKey)(leftoverReceiver);
22134
22143
  const tx = new (0, _web3js.Transaction)();
22135
- const createConfigTx = await this.createConfigTx(
22136
- configParam,
22137
- configKey,
22138
- feeClaimerAddress,
22139
- leftoverReceiverAddress,
22140
- quoteMintToken,
22141
- payerAddress
22142
- );
22143
- tx.add(createConfigTx);
22144
- const createPoolTx = await this.createPoolTx(
22145
- {
22146
- ...createConfigAndPoolParam.preCreatePoolParam,
22147
- config: configKey,
22148
- payer: payerAddress
22149
- },
22150
- createConfigAndPoolParam.tokenType,
22151
- quoteMintToken
22152
- );
22153
- tx.add(createPoolTx);
22144
+ const configTx = await this.program.methods.createConfig(configParam).accountsPartial({
22145
+ config,
22146
+ feeClaimer,
22147
+ leftoverReceiver,
22148
+ quoteMint,
22149
+ payer
22150
+ }).transaction();
22151
+ tx.add(configTx);
22152
+ const pool = deriveDbcPoolAddress(quoteMintToken, baseMint, configKey);
22153
+ const baseVault = deriveDbcTokenVaultAddress(pool, baseMint);
22154
+ const quoteVault = deriveDbcTokenVaultAddress(pool, quoteMintToken);
22155
+ const baseParams = {
22156
+ name,
22157
+ symbol,
22158
+ uri,
22159
+ pool,
22160
+ config: configKey,
22161
+ payer: payerAddress,
22162
+ poolCreator,
22163
+ baseMint,
22164
+ baseVault,
22165
+ quoteVault,
22166
+ quoteMint: quoteMintToken
22167
+ };
22168
+ if (createConfigAndPoolParam.tokenType === 0 /* SPL */) {
22169
+ const mintMetadata = deriveMintMetadata(baseMint);
22170
+ const poolTx = await this.initializeSplPool({
22171
+ ...baseParams,
22172
+ mintMetadata
22173
+ });
22174
+ tx.add(poolTx);
22175
+ } else {
22176
+ const poolTx = await this.initializeToken2022Pool(baseParams);
22177
+ tx.add(poolTx);
22178
+ }
22154
22179
  return tx;
22155
22180
  }
22156
22181
  /**
@@ -22167,6 +22192,7 @@ var PoolService = class extends DynamicBondingCurveProgram {
22167
22192
  payer,
22168
22193
  ...configParam
22169
22194
  } = createConfigAndPoolWithFirstBuyParam;
22195
+ validateConfigParameters({ ...configParam, leftoverReceiver });
22170
22196
  const configKey = new (0, _web3js.PublicKey)(config);
22171
22197
  const quoteMintToken = new (0, _web3js.PublicKey)(quoteMint);
22172
22198
  const payerAddress = new (0, _web3js.PublicKey)(payer);
@@ -22182,7 +22208,7 @@ var PoolService = class extends DynamicBondingCurveProgram {
22182
22208
  );
22183
22209
  const createPoolTx = await this.createPoolTx(
22184
22210
  {
22185
- ...createConfigAndPoolWithFirstBuyParam.preCreatePoolParam,
22211
+ ...createConfigAndPoolWithFirstBuyParam.createPoolParam,
22186
22212
  config: configKey,
22187
22213
  payer: payerAddress
22188
22214
  },
@@ -22190,11 +22216,8 @@ var PoolService = class extends DynamicBondingCurveProgram {
22190
22216
  quoteMintToken
22191
22217
  );
22192
22218
  const swapBuyTx = await this.swapBuyTx(
22193
- createConfigAndPoolWithFirstBuyParam.firstBuyParam,
22194
- createConfigAndPoolWithFirstBuyParam.preCreatePoolParam.baseMint,
22219
+ createConfigAndPoolWithFirstBuyParam,
22195
22220
  configKey,
22196
- createConfigAndPoolWithFirstBuyParam.poolFees.baseFee.baseFeeMode,
22197
- createConfigAndPoolWithFirstBuyParam.tokenType,
22198
22221
  quoteMintToken
22199
22222
  );
22200
22223
  return {
@@ -22206,30 +22229,113 @@ var PoolService = class extends DynamicBondingCurveProgram {
22206
22229
  /**
22207
22230
  * Create a new pool and buy tokens
22208
22231
  * @param createPoolWithFirstBuyParam - The parameters for the pool and buy
22209
- * @returns An object containing the new pool transaction and swap buy transaction
22232
+ * @returns A transaction that creates the pool and buys tokens
22210
22233
  */
22211
22234
  async createPoolWithFirstBuy(createPoolWithFirstBuyParam) {
22212
22235
  const { baseMint, config, name, symbol, uri, payer, poolCreator } = createPoolWithFirstBuyParam.createPoolParam;
22213
- const { buyer, buyAmount, minimumAmountOut, referralTokenAccount } = createPoolWithFirstBuyParam.firstBuyParam;
22236
+ const { buyAmount, minimumAmountOut, referralTokenAccount } = createPoolWithFirstBuyParam;
22214
22237
  const poolConfigState = await this.state.getPoolConfig(config);
22215
22238
  const { quoteMint, tokenType } = poolConfigState;
22216
- const createPoolTx = await this.createPoolTx(
22217
- createPoolWithFirstBuyParam.createPoolParam,
22218
- tokenType,
22219
- quoteMint
22220
- );
22221
- const swapBuyTx = await this.swapBuyTx(
22222
- createPoolWithFirstBuyParam.firstBuyParam,
22223
- createPoolWithFirstBuyParam.createPoolParam.baseMint,
22239
+ const pool = deriveDbcPoolAddress(quoteMint, baseMint, config);
22240
+ const baseVault = deriveDbcTokenVaultAddress(pool, baseMint);
22241
+ const quoteVault = deriveDbcTokenVaultAddress(pool, quoteMint);
22242
+ const baseParams = {
22243
+ name,
22244
+ symbol,
22245
+ uri,
22246
+ pool,
22224
22247
  config,
22225
- poolConfigState.poolFees.baseFee.baseFeeMode,
22226
- tokenType,
22248
+ payer,
22249
+ poolCreator,
22250
+ baseMint,
22251
+ baseVault,
22252
+ quoteVault,
22227
22253
  quoteMint
22228
- );
22229
- return {
22230
- createPoolTx,
22231
- swapBuyTx
22232
22254
  };
22255
+ let tx;
22256
+ if (tokenType === 0 /* SPL */) {
22257
+ const mintMetadata = deriveMintMetadata(baseMint);
22258
+ tx = await this.initializeSplPool({ ...baseParams, mintMetadata });
22259
+ } else {
22260
+ tx = await this.initializeToken2022Pool(baseParams);
22261
+ }
22262
+ validateSwapAmount(buyAmount);
22263
+ let currentPoint;
22264
+ if (poolConfigState.activationType === 0 /* Slot */) {
22265
+ const currentSlot = await this.connection.getSlot();
22266
+ currentPoint = new (0, _bnjs2.default)(currentSlot);
22267
+ } else {
22268
+ const currentSlot = await this.connection.getSlot();
22269
+ const currentTime = await this.connection.getBlockTime(currentSlot);
22270
+ currentPoint = new (0, _bnjs2.default)(currentTime);
22271
+ }
22272
+ const isRateLimiterApplied = checkRateLimiterApplied(
22273
+ poolConfigState.poolFees.baseFee.baseFeeMode,
22274
+ false,
22275
+ new (0, _bnjs2.default)(0),
22276
+ new (0, _bnjs2.default)(0),
22277
+ new (0, _bnjs2.default)(0)
22278
+ );
22279
+ const { inputMint, outputMint, inputTokenProgram, outputTokenProgram } = this.prepareSwapParams(
22280
+ false,
22281
+ { baseMint, poolType: tokenType },
22282
+ poolConfigState
22283
+ );
22284
+ const {
22285
+ ataTokenA: inputTokenAccount,
22286
+ ataTokenB: outputTokenAccount,
22287
+ instructions: preInstructions
22288
+ } = await this.prepareTokenAccounts(
22289
+ poolCreator,
22290
+ poolCreator,
22291
+ inputMint,
22292
+ outputMint,
22293
+ inputTokenProgram,
22294
+ outputTokenProgram
22295
+ );
22296
+ if (inputMint.equals(_spltoken.NATIVE_MINT)) {
22297
+ preInstructions.push(
22298
+ ...wrapSOLInstruction(
22299
+ poolCreator,
22300
+ inputTokenAccount,
22301
+ BigInt(buyAmount.toString())
22302
+ )
22303
+ );
22304
+ }
22305
+ const postInstructions = [];
22306
+ if ([inputMint.toBase58(), outputMint.toBase58()].includes(
22307
+ _spltoken.NATIVE_MINT.toBase58()
22308
+ )) {
22309
+ const unwrapIx = unwrapSOLInstruction(poolCreator, poolCreator);
22310
+ unwrapIx && postInstructions.push(unwrapIx);
22311
+ }
22312
+ const remainingAccounts = isRateLimiterApplied ? [
22313
+ {
22314
+ isSigner: false,
22315
+ isWritable: false,
22316
+ pubkey: _web3js.SYSVAR_INSTRUCTIONS_PUBKEY
22317
+ }
22318
+ ] : [];
22319
+ const firstBuyTx = await this.program.methods.swap({
22320
+ amountIn: buyAmount,
22321
+ minimumAmountOut
22322
+ }).accountsPartial({
22323
+ baseMint,
22324
+ quoteMint,
22325
+ pool,
22326
+ baseVault,
22327
+ quoteVault,
22328
+ config,
22329
+ poolAuthority: this.poolAuthority,
22330
+ referralTokenAccount,
22331
+ inputTokenAccount,
22332
+ outputTokenAccount,
22333
+ payer: poolCreator,
22334
+ tokenBaseProgram: outputTokenProgram,
22335
+ tokenQuoteProgram: inputTokenProgram
22336
+ }).remainingAccounts(remainingAccounts).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
22337
+ tx.add(...firstBuyTx.instructions);
22338
+ return tx;
22233
22339
  }
22234
22340
  /**
22235
22341
  * Swap between base and quote
@@ -22243,7 +22349,7 @@ var PoolService = class extends DynamicBondingCurveProgram {
22243
22349
  throw new Error(`Pool not found: ${swapParam.pool.toString()}`);
22244
22350
  }
22245
22351
  const poolConfigState = await this.state.getPoolConfig(poolState.config);
22246
- const { amountIn, minimumAmountOut, swapBaseForQuote, owner, payer } = swapParam;
22352
+ const { amountIn, minimumAmountOut, swapBaseForQuote, owner } = swapParam;
22247
22353
  validateSwapAmount(amountIn);
22248
22354
  let currentPoint;
22249
22355
  if (poolConfigState.activationType === 0 /* Slot */) {
@@ -22268,7 +22374,7 @@ var PoolService = class extends DynamicBondingCurveProgram {
22268
22374
  instructions: preInstructions
22269
22375
  } = await this.prepareTokenAccounts(
22270
22376
  owner,
22271
- payer ? payer : owner,
22377
+ owner,
22272
22378
  inputMint,
22273
22379
  outputMint,
22274
22380
  inputTokenProgram,
@@ -22347,11 +22453,6 @@ var PoolService = class extends DynamicBondingCurveProgram {
22347
22453
  currentPoint
22348
22454
  );
22349
22455
  }
22350
- /**
22351
- * Calculate the exact amount in for a swap (quote)
22352
- * @param swapQuoteExactInParam - The parameters for the swap
22353
- * @returns The exact amount in for the swap
22354
- */
22355
22456
  swapQuoteExactIn(swapQuoteExactInParam) {
22356
22457
  const { virtualPool, config, currentPoint } = swapQuoteExactInParam;
22357
22458
  const requiredQuoteAmount = calculateQuoteExactInAmount(