@meteora-ag/dynamic-bonding-curve-sdk 1.4.5 → 1.4.6-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -92,17 +92,16 @@ var MAX_SQRT_PRICE = new BN("79226673521066979257578248091");
92
92
  var RESOLUTION = 64;
93
93
  var ONE_Q64 = new BN(1).shln(RESOLUTION);
94
94
  var FEE_DENOMINATOR = 1e9;
95
- var MIN_FEE_BPS = 1;
95
+ var MIN_FEE_BPS = 25;
96
96
  var MAX_FEE_BPS = 9900;
97
- var MIN_FEE_NUMERATOR = 1e5;
97
+ var MIN_FEE_NUMERATOR = 25e5;
98
98
  var MAX_FEE_NUMERATOR = 99e7;
99
99
  var BASIS_POINT_MAX = 1e4;
100
100
  var MAX_CURVE_POINT = 16;
101
101
  var PARTNER_SURPLUS_SHARE = 80;
102
102
  var SWAP_BUFFER_PERCENTAGE = 25;
103
- var MAX_MIGRATION_FEE_PERCENTAGE = 50;
103
+ var MAX_MIGRATION_FEE_PERCENTAGE = 99;
104
104
  var MAX_CREATOR_MIGRATION_FEE_PERCENTAGE = 100;
105
- var MAX_SWALLOW_PERCENTAGE = 20;
106
105
  var MAX_RATE_LIMITER_DURATION_IN_SECONDS = 43200;
107
106
  var MAX_RATE_LIMITER_DURATION_IN_SLOTS = 108e3;
108
107
  var SLOT_DURATION = 400;
@@ -936,7 +935,7 @@ var getMigrationThresholdPrice = (migrationThreshold, sqrtStartPrice, curve) =>
936
935
  };
937
936
  var getSwapAmountWithBuffer = (swapBaseAmount, sqrtStartPrice, curve) => {
938
937
  const swapAmountBuffer = swapBaseAmount.add(
939
- swapBaseAmount.mul(new BN6(25)).div(new BN6(100))
938
+ swapBaseAmount.mul(new BN6(SWAP_BUFFER_PERCENTAGE)).div(new BN6(100))
940
939
  );
941
940
  const maxBaseAmountOnCurve = getBaseTokenForSwap(
942
941
  sqrtStartPrice,
@@ -2009,15 +2008,6 @@ function toNumerator(bps, feeDenominator) {
2009
2008
  );
2010
2009
  }
2011
2010
  }
2012
- function getMaxSwallowQuoteAmount(config) {
2013
- const maxSwallowAmount = mulDiv(
2014
- config.migrationQuoteThreshold,
2015
- new BN11(MAX_SWALLOW_PERCENTAGE),
2016
- new BN11(100),
2017
- 1 /* Down */
2018
- );
2019
- return maxSwallowAmount;
2020
- }
2021
2011
  function getFeeMode(collectFeeMode, tradeDirection, hasReferral) {
2022
2012
  let feesOnInput;
2023
2013
  let feesOnBaseToken;
@@ -2195,7 +2185,7 @@ function getSwapResult(poolState, configState, amountIn, feeMode, tradeDirection
2195
2185
  configState,
2196
2186
  poolState.sqrtPrice,
2197
2187
  actualAmountIn,
2198
- U128_MAX
2188
+ configState.migrationSqrtPrice
2199
2189
  );
2200
2190
  const { outputAmount, nextSqrtPrice } = swapAmountFromInput;
2201
2191
  const actualAmountOut = feeMode.feesOnInput ? outputAmount : (() => {
@@ -2285,9 +2275,12 @@ function getSwapResultFromExactInput(virtualPool, config, amountIn, feeMode, tra
2285
2275
  config,
2286
2276
  virtualPool.sqrtPrice,
2287
2277
  actualAmountIn,
2288
- U128_MAX
2278
+ config.migrationSqrtPrice
2289
2279
  );
2290
2280
  const { outputAmount, nextSqrtPrice, amountLeft } = swapAmountFromInput;
2281
+ if (!amountLeft.isZero()) {
2282
+ throw new Error("Swap amount is over a threshold");
2283
+ }
2291
2284
  const actualAmountOut = feeMode.feesOnInput ? outputAmount : (() => {
2292
2285
  const feeResult = getFeeOnAmount(
2293
2286
  tradeFeeNumerator,
@@ -2594,6 +2587,9 @@ function getSwapResultFromExactOutput(virtualPool, config, amountOut, feeMode, t
2594
2587
  }
2595
2588
  })();
2596
2589
  const { outputAmount: amountIn, nextSqrtPrice } = swapAmountFromOutput;
2590
+ if (nextSqrtPrice.gt(config.migrationSqrtPrice)) {
2591
+ throw new Error("Swap amount is over a threshold");
2592
+ }
2597
2593
  const [excludedFeeInputAmount, includedFeeInputAmount] = feeMode.feesOnInput ? (() => {
2598
2594
  const tradeFeeNumerator = getTotalFeeNumeratorFromExcludedFeeAmount(
2599
2595
  config.poolFees,
@@ -2775,10 +2771,6 @@ function swapQuoteExactIn(virtualPool, config, swapBaseForQuote, amountIn, slipp
2775
2771
  tradeDirection,
2776
2772
  currentPoint
2777
2773
  );
2778
- const maxSwallowQuoteAmount = getMaxSwallowQuoteAmount(config);
2779
- if (result.amountLeft.gt(maxSwallowQuoteAmount)) {
2780
- throw new Error("Amount left is over a threshold");
2781
- }
2782
2774
  let minimumAmountOut;
2783
2775
  if (slippageBps > 0) {
2784
2776
  const slippageFactor = new BN12(1e4 - slippageBps);
@@ -3106,15 +3098,8 @@ function validateConfigParameters(configParam) {
3106
3098
  )) {
3107
3099
  throw new Error("Invalid migration fee option");
3108
3100
  }
3109
- if (configParam.migrationFee.feePercentage < 0 || configParam.migrationFee.feePercentage > MAX_MIGRATION_FEE_PERCENTAGE) {
3110
- throw new Error(
3111
- `Migration fee percentage must be between 0 and ${MAX_MIGRATION_FEE_PERCENTAGE}`
3112
- );
3113
- }
3114
- if (configParam.migrationFee.creatorFeePercentage < 0 || configParam.migrationFee.creatorFeePercentage > MAX_CREATOR_MIGRATION_FEE_PERCENTAGE) {
3115
- throw new Error(
3116
- `Creator fee percentage must be between 0 and ${MAX_CREATOR_MIGRATION_FEE_PERCENTAGE}`
3117
- );
3101
+ if (!validateMigrationFee(configParam.migrationFee)) {
3102
+ throw new Error("Invalid migration fee");
3118
3103
  }
3119
3104
  if (!validateTokenDecimals(configParam.tokenDecimal)) {
3120
3105
  throw new Error("Token decimal must be between 6 and 9");
@@ -3233,6 +3218,24 @@ function validateSwapAmount(amountIn) {
3233
3218
  }
3234
3219
  return true;
3235
3220
  }
3221
+ function validateMigrationFee(migrationFee) {
3222
+ if (!Number.isInteger(migrationFee.feePercentage) || !Number.isInteger(migrationFee.creatorFeePercentage)) {
3223
+ throw new Error(
3224
+ "Migration fee percentage and creator fee percentage must be whole numbers (no decimals allowed)"
3225
+ );
3226
+ }
3227
+ if (migrationFee.feePercentage < 0 || migrationFee.feePercentage > MAX_MIGRATION_FEE_PERCENTAGE) {
3228
+ throw new Error(
3229
+ `Migration fee percentage must be between 0 and ${MAX_MIGRATION_FEE_PERCENTAGE}`
3230
+ );
3231
+ }
3232
+ if (migrationFee.creatorFeePercentage < 0 || migrationFee.creatorFeePercentage > MAX_CREATOR_MIGRATION_FEE_PERCENTAGE) {
3233
+ throw new Error(
3234
+ `Migration creator fee percentage must be between 0 and ${MAX_CREATOR_MIGRATION_FEE_PERCENTAGE}`
3235
+ );
3236
+ }
3237
+ return true;
3238
+ }
3236
3239
 
3237
3240
  // src/helpers/buildCurve.ts
3238
3241
  import Decimal4 from "decimal.js";
@@ -3779,7 +3782,7 @@ var idl_default = {
3779
3782
  address: "dbcij3LWUppWqq96dh6gJWwBifmcGfLSB5D4DuSMaqN",
3780
3783
  metadata: {
3781
3784
  name: "dynamic_bonding_curve",
3782
- version: "0.1.6",
3785
+ version: "0.1.7",
3783
3786
  spec: "0.1.0",
3784
3787
  description: "Created with Anchor"
3785
3788
  },
@@ -3917,6 +3920,83 @@ var idl_default = {
3917
3920
  }
3918
3921
  ]
3919
3922
  },
3923
+ {
3924
+ name: "claim_pool_creation_fee",
3925
+ discriminator: [
3926
+ 246,
3927
+ 51,
3928
+ 18,
3929
+ 222,
3930
+ 80,
3931
+ 42,
3932
+ 236,
3933
+ 205
3934
+ ],
3935
+ accounts: [
3936
+ {
3937
+ name: "pool",
3938
+ writable: true
3939
+ },
3940
+ {
3941
+ name: "claim_fee_operator",
3942
+ docs: [
3943
+ "Claim fee operator"
3944
+ ]
3945
+ },
3946
+ {
3947
+ name: "operator",
3948
+ docs: [
3949
+ "Operator"
3950
+ ],
3951
+ signer: true,
3952
+ relations: [
3953
+ "claim_fee_operator"
3954
+ ]
3955
+ },
3956
+ {
3957
+ name: "treasury",
3958
+ writable: true,
3959
+ address: "4EWqcx3aNZmMetCnxwLYwyNjan6XLGp3Ca2W316vrSjv"
3960
+ },
3961
+ {
3962
+ name: "system_program",
3963
+ address: "11111111111111111111111111111111"
3964
+ },
3965
+ {
3966
+ name: "event_authority",
3967
+ pda: {
3968
+ seeds: [
3969
+ {
3970
+ kind: "const",
3971
+ value: [
3972
+ 95,
3973
+ 95,
3974
+ 101,
3975
+ 118,
3976
+ 101,
3977
+ 110,
3978
+ 116,
3979
+ 95,
3980
+ 97,
3981
+ 117,
3982
+ 116,
3983
+ 104,
3984
+ 111,
3985
+ 114,
3986
+ 105,
3987
+ 116,
3988
+ 121
3989
+ ]
3990
+ }
3991
+ ]
3992
+ }
3993
+ },
3994
+ {
3995
+ name: "program"
3996
+ }
3997
+ ],
3998
+ args: []
3999
+ },
3920
4000
  {
3921
4001
  name: "claim_protocol_fee",
3922
4002
  discriminator: [
@@ -4729,7 +4809,7 @@ var idl_default = {
4729
4809
  {
4730
4810
  name: "create_partner_metadata",
4731
4811
  docs: [
4732
- "PARTNER FUNCTIONS ////"
4812
+ "PARTNER FUNCTIONS ///"
4733
4813
  ],
4734
4814
  discriminator: [
4735
4815
  192,
@@ -6036,16 +6116,10 @@ var idl_default = {
6036
6116
  docs: [
6037
6117
  "virtual pool"
6038
6118
  ],
6039
- writable: true,
6040
- relations: [
6041
- "migration_metadata"
6042
- ]
6119
+ writable: true
6043
6120
  },
6044
6121
  {
6045
- name: "migration_metadata",
6046
- docs: [
6047
- "migration metadata"
6048
- ]
6122
+ name: "migration_metadata"
6049
6123
  },
6050
6124
  {
6051
6125
  name: "config",
@@ -6173,43 +6247,16 @@ var idl_default = {
6173
6247
  name: "virtual_pool"
6174
6248
  },
6175
6249
  {
6176
- name: "config",
6177
- relations: [
6178
- "virtual_pool"
6179
- ]
6250
+ name: "config"
6180
6251
  },
6181
6252
  {
6182
- name: "migration_metadata",
6183
- writable: true,
6184
- pda: {
6185
- seeds: [
6186
- {
6187
- kind: "const",
6188
- value: [
6189
- 100,
6190
- 97,
6191
- 109,
6192
- 109,
6193
- 95,
6194
- 118,
6195
- 50
6196
- ]
6197
- },
6198
- {
6199
- kind: "account",
6200
- path: "virtual_pool"
6201
- }
6202
- ]
6203
- }
6253
+ name: "migration_metadata"
6204
6254
  },
6205
6255
  {
6206
- name: "payer",
6207
- writable: true,
6208
- signer: true
6256
+ name: "payer"
6209
6257
  },
6210
6258
  {
6211
- name: "system_program",
6212
- address: "11111111111111111111111111111111"
6259
+ name: "system_program"
6213
6260
  },
6214
6261
  {
6215
6262
  name: "event_authority",
@@ -6991,6 +7038,36 @@ var idl_default = {
6991
7038
  ],
6992
7039
  args: []
6993
7040
  },
7041
+ {
7042
+ name: "withdraw_lamports_from_pool_authority",
7043
+ discriminator: [
7044
+ 20,
7045
+ 185,
7046
+ 242,
7047
+ 240,
7048
+ 129,
7049
+ 24,
7050
+ 212,
7051
+ 194
7052
+ ],
7053
+ accounts: [
7054
+ {
7055
+ name: "pool_authority",
7056
+ writable: true,
7057
+ address: "FhVo3mqL8PW5pH5U2CN4XE33DokiyZnUwuGpH2hmHLuM"
7058
+ },
7059
+ {
7060
+ name: "receiver",
7061
+ writable: true,
7062
+ address: "4EWqcx3aNZmMetCnxwLYwyNjan6XLGp3Ca2W316vrSjv"
7063
+ },
7064
+ {
7065
+ name: "system_program",
7066
+ address: "11111111111111111111111111111111"
7067
+ }
7068
+ ],
7069
+ args: []
7070
+ },
6994
7071
  {
6995
7072
  name: "withdraw_leftover",
6996
7073
  discriminator: [
@@ -7304,19 +7381,6 @@ var idl_default = {
7304
7381
  156
7305
7382
  ]
7306
7383
  },
7307
- {
7308
- name: "MeteoraDammV2Metadata",
7309
- discriminator: [
7310
- 104,
7311
- 221,
7312
- 219,
7313
- 203,
7314
- 10,
7315
- 142,
7316
- 250,
7317
- 163
7318
- ]
7319
- },
7320
7384
  {
7321
7385
  name: "PartnerMetadata",
7322
7386
  discriminator: [
@@ -7384,6 +7448,19 @@ var idl_default = {
7384
7448
  138
7385
7449
  ]
7386
7450
  },
7451
+ {
7452
+ name: "EvtClaimPoolCreationFee",
7453
+ discriminator: [
7454
+ 149,
7455
+ 111,
7456
+ 149,
7457
+ 44,
7458
+ 136,
7459
+ 64,
7460
+ 175,
7461
+ 62
7462
+ ]
7463
+ },
7387
7464
  {
7388
7465
  name: "EvtClaimProtocolFee",
7389
7466
  discriminator: [
@@ -7462,19 +7539,6 @@ var idl_default = {
7462
7539
  144
7463
7540
  ]
7464
7541
  },
7465
- {
7466
- name: "EvtCreateDammV2MigrationMetadata",
7467
- discriminator: [
7468
- 103,
7469
- 111,
7470
- 132,
7471
- 168,
7472
- 140,
7473
- 253,
7474
- 150,
7475
- 114
7476
- ]
7477
- },
7478
7542
  {
7479
7543
  name: "EvtCreateMeteoraMigrationMetadata",
7480
7544
  discriminator: [
@@ -7903,6 +7967,16 @@ var idl_default = {
7903
7967
  code: 6048,
7904
7968
  name: "NextSqrtPriceIsSmallerThanStartSqrtPrice",
7905
7969
  msg: "Next sqrt price is smaller than start sqrt price"
7970
+ },
7971
+ {
7972
+ code: 6049,
7973
+ name: "InvalidMinBaseFee",
7974
+ msg: "Invalid min base fee"
7975
+ },
7976
+ {
7977
+ code: 6050,
7978
+ name: "AccountInvariantViolation",
7979
+ msg: "Account invariant violation"
7906
7980
  }
7907
7981
  ],
7908
7982
  types: [
@@ -8358,6 +8432,26 @@ var idl_default = {
8358
8432
  ]
8359
8433
  }
8360
8434
  },
8435
+ {
8436
+ name: "EvtClaimPoolCreationFee",
8437
+ type: {
8438
+ kind: "struct",
8439
+ fields: [
8440
+ {
8441
+ name: "pool",
8442
+ type: "pubkey"
8443
+ },
8444
+ {
8445
+ name: "treasury",
8446
+ type: "pubkey"
8447
+ },
8448
+ {
8449
+ name: "creation_fee",
8450
+ type: "u64"
8451
+ }
8452
+ ]
8453
+ }
8454
+ },
8361
8455
  {
8362
8456
  name: "EvtClaimProtocolFee",
8363
8457
  type: {
@@ -8585,18 +8679,6 @@ var idl_default = {
8585
8679
  ]
8586
8680
  }
8587
8681
  },
8588
- {
8589
- name: "EvtCreateDammV2MigrationMetadata",
8590
- type: {
8591
- kind: "struct",
8592
- fields: [
8593
- {
8594
- name: "virtual_pool",
8595
- type: "pubkey"
8596
- }
8597
- ]
8598
- }
8599
- },
8600
8682
  {
8601
8683
  name: "EvtCreateMeteoraMigrationMetadata",
8602
8684
  type: {
@@ -9214,56 +9296,6 @@ var idl_default = {
9214
9296
  ]
9215
9297
  }
9216
9298
  },
9217
- {
9218
- name: "MeteoraDammV2Metadata",
9219
- serialization: "bytemuck",
9220
- repr: {
9221
- kind: "c"
9222
- },
9223
- type: {
9224
- kind: "struct",
9225
- fields: [
9226
- {
9227
- name: "virtual_pool",
9228
- docs: [
9229
- "pool"
9230
- ],
9231
- type: "pubkey"
9232
- },
9233
- {
9234
- name: "padding_0",
9235
- docs: [
9236
- "!!! BE CAREFUL to use tomestone field, previous is pool creator"
9237
- ],
9238
- type: {
9239
- array: [
9240
- "u8",
9241
- 32
9242
- ]
9243
- }
9244
- },
9245
- {
9246
- name: "partner",
9247
- docs: [
9248
- "partner"
9249
- ],
9250
- type: "pubkey"
9251
- },
9252
- {
9253
- name: "_padding",
9254
- docs: [
9255
- "Reserve"
9256
- ],
9257
- type: {
9258
- array: [
9259
- "u8",
9260
- 126
9261
- ]
9262
- }
9263
- }
9264
- ]
9265
- }
9266
- },
9267
9299
  {
9268
9300
  name: "MigratedPoolFee",
9269
9301
  type: {
@@ -10129,6 +10161,19 @@ var idl_default = {
10129
10161
  ],
10130
10162
  type: "u64"
10131
10163
  },
10164
+ {
10165
+ name: "creation_fee_bits",
10166
+ type: "u8"
10167
+ },
10168
+ {
10169
+ name: "_padding_0",
10170
+ type: {
10171
+ array: [
10172
+ "u8",
10173
+ 7
10174
+ ]
10175
+ }
10176
+ },
10132
10177
  {
10133
10178
  name: "_padding_1",
10134
10179
  docs: [
@@ -10137,7 +10182,7 @@ var idl_default = {
10137
10182
  type: {
10138
10183
  array: [
10139
10184
  "u64",
10140
- 7
10185
+ 6
10141
10186
  ]
10142
10187
  }
10143
10188
  }
@@ -24360,25 +24405,6 @@ var MigrationService = class extends DynamicBondingCurveProgram {
24360
24405
  ///////////////////////
24361
24406
  // DAMM V2 FUNCTIONS //
24362
24407
  ///////////////////////
24363
- /**
24364
- * Create metadata for the migration of Meteora DAMM V2
24365
- * @param payer - The payer of the transaction
24366
- * @param virtualPool - The virtual pool address
24367
- * @param config - The config address
24368
- * @returns A migration transaction
24369
- */
24370
- async createDammV2MigrationMetadata(params) {
24371
- const { virtualPool, config, payer } = params;
24372
- const migrationMetadata = deriveDammV2MigrationMetadataAddress(virtualPool);
24373
- const accounts = {
24374
- virtualPool,
24375
- config,
24376
- migrationMetadata,
24377
- payer,
24378
- systemProgram: SystemProgram3.programId
24379
- };
24380
- return this.program.methods.migrationDammV2CreateMetadata().accountsPartial(accounts).transaction();
24381
- }
24382
24408
  /**
24383
24409
  * Migrate to DAMM V2
24384
24410
  * @param payer - The payer of the transaction
@@ -26290,7 +26316,6 @@ export {
26290
26316
  MAX_RATE_LIMITER_DURATION_IN_SECONDS,
26291
26317
  MAX_RATE_LIMITER_DURATION_IN_SLOTS,
26292
26318
  MAX_SQRT_PRICE,
26293
- MAX_SWALLOW_PERCENTAGE,
26294
26319
  METAPLEX_PROGRAM_ID,
26295
26320
  MIN_FEE_BPS,
26296
26321
  MIN_FEE_NUMERATOR,
@@ -26409,7 +26434,6 @@ export {
26409
26434
  getMaxBaseFeeNumerator,
26410
26435
  getMaxIndex,
26411
26436
  getMaxOutAmountWithMinBaseFee,
26412
- getMaxSwallowQuoteAmount,
26413
26437
  getMigratedPoolFeeParams,
26414
26438
  getMigrationBaseToken,
26415
26439
  getMigrationQuoteAmount,
@@ -26479,6 +26503,7 @@ export {
26479
26503
  validateLPPercentages,
26480
26504
  validateMigratedPoolFee,
26481
26505
  validateMigrationAndTokenType,
26506
+ validateMigrationFee,
26482
26507
  validateMigrationFeeOption,
26483
26508
  validatePoolFees,
26484
26509
  validateSwapAmount,