@meteora-ag/dlmm 1.0.47-rc.1 → 1.0.47

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
@@ -6293,6 +6293,7 @@ function toAmountsOneSideByStrategy(activeId, binStep, minBinId, maxBinId, amoun
6293
6293
  }
6294
6294
  }
6295
6295
  function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
6296
+ const isSingleSideX = amountY.isZero();
6296
6297
  switch (strategyType) {
6297
6298
  case 0 /* SpotOneSide */:
6298
6299
  case 1 /* CurveOneSide */:
@@ -6301,7 +6302,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
6301
6302
  }
6302
6303
  case 3 /* SpotImBalanced */: {
6303
6304
  if (activeId < minBinId || activeId > maxBinId) {
6304
- let weights = toWeightSpotBalanced(minBinId, maxBinId);
6305
+ const weights = toWeightSpotBalanced(minBinId, maxBinId);
6305
6306
  return toAmountBothSide(
6306
6307
  activeId,
6307
6308
  binStep,
@@ -6312,27 +6313,61 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
6312
6313
  weights
6313
6314
  );
6314
6315
  }
6315
- let amountsInBin = [];
6316
- if (minBinId <= activeId) {
6317
- let weights = toWeightSpotBalanced(minBinId, activeId);
6318
- let amounts = toAmountBidSide(activeId, amountY, weights);
6319
- for (let bin of amounts) {
6320
- amountsInBin.push({
6321
- binId: bin.binId,
6322
- amountX: new (0, _anchor.BN)(0),
6323
- amountY: bin.amount
6324
- });
6316
+ const amountsInBin = [];
6317
+ if (!isSingleSideX) {
6318
+ if (minBinId <= activeId) {
6319
+ const weights = toWeightSpotBalanced(minBinId, activeId);
6320
+ const amounts = toAmountBidSide(activeId, amountY, weights);
6321
+ for (let bin of amounts) {
6322
+ amountsInBin.push({
6323
+ binId: bin.binId,
6324
+ amountX: new (0, _anchor.BN)(0),
6325
+ amountY: bin.amount
6326
+ });
6327
+ }
6325
6328
  }
6326
- }
6327
- if (activeId < maxBinId) {
6328
- let weights = toWeightSpotBalanced(activeId + 1, maxBinId);
6329
- let amounts = toAmountAskSide(activeId, binStep, amountX, weights);
6330
- for (let bin of amounts) {
6331
- amountsInBin.push({
6332
- binId: bin.binId,
6333
- amountX: bin.amount,
6334
- amountY: new (0, _anchor.BN)(0)
6335
- });
6329
+ if (activeId < maxBinId) {
6330
+ const weights = toWeightSpotBalanced(activeId + 1, maxBinId);
6331
+ const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
6332
+ for (let bin of amounts) {
6333
+ amountsInBin.push({
6334
+ binId: bin.binId,
6335
+ amountX: bin.amount,
6336
+ amountY: new (0, _anchor.BN)(0)
6337
+ });
6338
+ }
6339
+ }
6340
+ } else {
6341
+ if (minBinId < activeId) {
6342
+ const weights = toWeightSpotBalanced(minBinId, activeId - 1);
6343
+ const amountsIntoBidSide = toAmountBidSide(
6344
+ activeId,
6345
+ amountY,
6346
+ weights
6347
+ );
6348
+ for (let bin of amountsIntoBidSide) {
6349
+ amountsInBin.push({
6350
+ binId: bin.binId,
6351
+ amountX: new (0, _anchor.BN)(0),
6352
+ amountY: bin.amount
6353
+ });
6354
+ }
6355
+ }
6356
+ if (activeId <= maxBinId) {
6357
+ const weights = toWeightSpotBalanced(activeId, maxBinId);
6358
+ const amountsIntoAskSide = toAmountAskSide(
6359
+ activeId,
6360
+ binStep,
6361
+ amountX,
6362
+ weights
6363
+ );
6364
+ for (let bin of amountsIntoAskSide) {
6365
+ amountsInBin.push({
6366
+ binId: bin.binId,
6367
+ amountX: bin.amount,
6368
+ amountY: new (0, _anchor.BN)(0)
6369
+ });
6370
+ }
6336
6371
  }
6337
6372
  }
6338
6373
  return amountsInBin;
@@ -6351,7 +6386,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
6351
6386
  );
6352
6387
  }
6353
6388
  if (activeId > maxBinId) {
6354
- let weights = toWeightAscendingOrder(minBinId, maxBinId);
6389
+ const weights = toWeightAscendingOrder(minBinId, maxBinId);
6355
6390
  return toAmountBothSide(
6356
6391
  activeId,
6357
6392
  binStep,
@@ -6362,34 +6397,68 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
6362
6397
  weights
6363
6398
  );
6364
6399
  }
6365
- let amountsInBin = [];
6366
- if (minBinId <= activeId) {
6367
- let weights = toWeightAscendingOrder(minBinId, activeId);
6368
- let amounts = toAmountBidSide(activeId, amountY, weights);
6369
- for (let bin of amounts) {
6370
- amountsInBin.push({
6371
- binId: bin.binId,
6372
- amountX: new (0, _anchor.BN)(0),
6373
- amountY: bin.amount
6374
- });
6400
+ const amountsInBin = [];
6401
+ if (!isSingleSideX) {
6402
+ if (minBinId <= activeId) {
6403
+ const weights = toWeightAscendingOrder(minBinId, activeId);
6404
+ const amounts = toAmountBidSide(activeId, amountY, weights);
6405
+ for (let bin of amounts) {
6406
+ amountsInBin.push({
6407
+ binId: bin.binId,
6408
+ amountX: new (0, _anchor.BN)(0),
6409
+ amountY: bin.amount
6410
+ });
6411
+ }
6375
6412
  }
6376
- }
6377
- if (activeId < maxBinId) {
6378
- let weights = toWeightDecendingOrder(activeId + 1, maxBinId);
6379
- let amounts = toAmountAskSide(activeId, binStep, amountX, weights);
6380
- for (let bin of amounts) {
6381
- amountsInBin.push({
6382
- binId: bin.binId,
6383
- amountX: bin.amount,
6384
- amountY: new (0, _anchor.BN)(0)
6385
- });
6413
+ if (activeId < maxBinId) {
6414
+ const weights = toWeightDecendingOrder(activeId + 1, maxBinId);
6415
+ const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
6416
+ for (let bin of amounts) {
6417
+ amountsInBin.push({
6418
+ binId: bin.binId,
6419
+ amountX: bin.amount,
6420
+ amountY: new (0, _anchor.BN)(0)
6421
+ });
6422
+ }
6423
+ }
6424
+ } else {
6425
+ if (minBinId < activeId) {
6426
+ const weights = toWeightAscendingOrder(minBinId, activeId - 1);
6427
+ const amountsIntoBidSide = toAmountBidSide(
6428
+ activeId,
6429
+ amountY,
6430
+ weights
6431
+ );
6432
+ for (let bin of amountsIntoBidSide) {
6433
+ amountsInBin.push({
6434
+ binId: bin.binId,
6435
+ amountX: new (0, _anchor.BN)(0),
6436
+ amountY: bin.amount
6437
+ });
6438
+ }
6439
+ }
6440
+ if (activeId <= maxBinId) {
6441
+ const weights = toWeightDecendingOrder(activeId, maxBinId);
6442
+ const amountsIntoAskSide = toAmountAskSide(
6443
+ activeId,
6444
+ binStep,
6445
+ amountX,
6446
+ weights
6447
+ );
6448
+ for (let bin of amountsIntoAskSide) {
6449
+ amountsInBin.push({
6450
+ binId: bin.binId,
6451
+ amountX: bin.amount,
6452
+ amountY: new (0, _anchor.BN)(0)
6453
+ });
6454
+ }
6386
6455
  }
6387
6456
  }
6388
6457
  return amountsInBin;
6389
6458
  }
6390
6459
  case 5 /* BidAskImBalanced */: {
6391
6460
  if (activeId < minBinId) {
6392
- let weights = toWeightAscendingOrder(minBinId, maxBinId);
6461
+ const weights = toWeightAscendingOrder(minBinId, maxBinId);
6393
6462
  return toAmountBothSide(
6394
6463
  activeId,
6395
6464
  binStep,
@@ -6401,7 +6470,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
6401
6470
  );
6402
6471
  }
6403
6472
  if (activeId > maxBinId) {
6404
- let weights = toWeightDecendingOrder(minBinId, maxBinId);
6473
+ const weights = toWeightDecendingOrder(minBinId, maxBinId);
6405
6474
  return toAmountBothSide(
6406
6475
  activeId,
6407
6476
  binStep,
@@ -6412,27 +6481,61 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
6412
6481
  weights
6413
6482
  );
6414
6483
  }
6415
- let amountsInBin = [];
6416
- if (minBinId <= activeId) {
6417
- let weights = toWeightDecendingOrder(minBinId, activeId);
6418
- let amounts = toAmountBidSide(activeId, amountY, weights);
6419
- for (let bin of amounts) {
6420
- amountsInBin.push({
6421
- binId: bin.binId,
6422
- amountX: new (0, _anchor.BN)(0),
6423
- amountY: bin.amount
6424
- });
6484
+ const amountsInBin = [];
6485
+ if (!isSingleSideX) {
6486
+ if (minBinId <= activeId) {
6487
+ const weights = toWeightDecendingOrder(minBinId, activeId);
6488
+ const amounts = toAmountBidSide(activeId, amountY, weights);
6489
+ for (let bin of amounts) {
6490
+ amountsInBin.push({
6491
+ binId: bin.binId,
6492
+ amountX: new (0, _anchor.BN)(0),
6493
+ amountY: bin.amount
6494
+ });
6495
+ }
6425
6496
  }
6426
- }
6427
- if (activeId < maxBinId) {
6428
- let weights = toWeightAscendingOrder(activeId + 1, maxBinId);
6429
- let amounts = toAmountAskSide(activeId, binStep, amountX, weights);
6430
- for (let bin of amounts) {
6431
- amountsInBin.push({
6432
- binId: bin.binId,
6433
- amountX: bin.amount,
6434
- amountY: new (0, _anchor.BN)(0)
6435
- });
6497
+ if (activeId < maxBinId) {
6498
+ const weights = toWeightAscendingOrder(activeId + 1, maxBinId);
6499
+ const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
6500
+ for (let bin of amounts) {
6501
+ amountsInBin.push({
6502
+ binId: bin.binId,
6503
+ amountX: bin.amount,
6504
+ amountY: new (0, _anchor.BN)(0)
6505
+ });
6506
+ }
6507
+ }
6508
+ } else {
6509
+ if (minBinId < activeId) {
6510
+ const weights = toWeightDecendingOrder(minBinId, activeId - 1);
6511
+ const amountsIntoBidSide = toAmountBidSide(
6512
+ activeId,
6513
+ amountY,
6514
+ weights
6515
+ );
6516
+ for (let bin of amountsIntoBidSide) {
6517
+ amountsInBin.push({
6518
+ binId: bin.binId,
6519
+ amountX: new (0, _anchor.BN)(0),
6520
+ amountY: bin.amount
6521
+ });
6522
+ }
6523
+ }
6524
+ if (activeId <= maxBinId) {
6525
+ const weights = toWeightAscendingOrder(activeId, maxBinId);
6526
+ const amountsIntoAskSide = toAmountAskSide(
6527
+ activeId,
6528
+ binStep,
6529
+ amountX,
6530
+ weights
6531
+ );
6532
+ for (let bin of amountsIntoAskSide) {
6533
+ amountsInBin.push({
6534
+ binId: bin.binId,
6535
+ amountX: bin.amount,
6536
+ amountY: new (0, _anchor.BN)(0)
6537
+ });
6538
+ }
6436
6539
  }
6437
6540
  }
6438
6541
  return amountsInBin;