@magmaprotocol/magma-clmm-sdk 0.5.88 → 0.5.90

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.ts CHANGED
@@ -454,6 +454,7 @@ type ClmmConfig = {
454
454
  };
455
455
  type DlmmConfig = {
456
456
  factory: SuiObjectIdType;
457
+ rewarder_global_vault: SuiObjectIdType;
457
458
  };
458
459
  /**
459
460
  * Represents an event to create a liquidity mining partner.
@@ -1725,6 +1726,7 @@ type EventBin = {
1725
1726
  real_bin_id: number;
1726
1727
  };
1727
1728
  type EventPositionLiquidity = {
1729
+ position_id: string;
1728
1730
  shares: number | string;
1729
1731
  liquidity: number | string;
1730
1732
  x_equivalent: number | string;
@@ -3783,13 +3785,6 @@ declare class DlmmModule implements IModule {
3783
3785
  createPairAddLiquidity(params: DlmmCreatePairAddLiquidityParams): Promise<Transaction>;
3784
3786
  swap(params: DLMMSwapParams): Promise<Transaction>;
3785
3787
  fetchBins(params: FetchBinsParams): Promise<EventBin[]>;
3786
- /**
3787
- * Gets a list of positions for the given account address.
3788
- * @param accountAddress The account address to get positions for.
3789
- * @param assignPoolIds An array of pool IDs to filter the positions by.
3790
- * @returns array of Position objects.
3791
- */
3792
- getUserPositionById(positionId: string, showDisplay?: boolean): Promise<DlmmPositionInfo>;
3793
3788
  /**
3794
3789
  * Gets a list of positions for the given account address.
3795
3790
  * @param accountAddress The account address to get positions for.
@@ -3800,10 +3795,16 @@ declare class DlmmModule implements IModule {
3800
3795
  private buildPosition;
3801
3796
  private getPoolCoins;
3802
3797
  private buildPositionType;
3803
- getPositionLiquidity(params: GetPositionLiquidityParams): Promise<EventPositionLiquidity>;
3798
+ getPositionLiquidity(params: GetPositionLiquidityParams[]): Promise<EventPositionLiquidity[]>;
3799
+ private _getPositionLiquidity;
3800
+ private _parsePositionLiquidity;
3804
3801
  getPairLiquidity(params: GetPairLiquidityParams): Promise<EventPairLiquidity>;
3805
- getEarnedFees(params: DlmmCollectFeeParams): Promise<DlmmEventEarnedFees>;
3806
- getEarnedRewards(params: DlmmRewardsParams): Promise<DlmmEventEarnedRewards>;
3802
+ getEarnedFees(params: DlmmCollectFeeParams[]): Promise<DlmmEventEarnedFees[]>;
3803
+ private _getEarnedFees;
3804
+ private _parseEarnedFees;
3805
+ getEarnedRewards(params: DlmmRewardsParams[]): Promise<DlmmEventEarnedRewards[]>;
3806
+ private _getEarnedRewards;
3807
+ private _parseEarnedRewards;
3807
3808
  getPairRewarders(params: GetPairRewarderParams[]): Promise<Map<string, string[]>>;
3808
3809
  private _getPairRewarders;
3809
3810
  private _parsePairRewarders;
package/dist/index.js CHANGED
@@ -10978,6 +10978,7 @@ var DlmmModule = class {
10978
10978
  const args = [
10979
10979
  tx.object(params.pair),
10980
10980
  tx.object(dlmmConfig.factory),
10981
+ tx.object(dlmm_pool.config.rewarder_global_vault),
10981
10982
  tx.object(params.positionId),
10982
10983
  primaryCoinAInputs.targetCoin,
10983
10984
  primaryCoinBInputs.targetCoin,
@@ -11047,7 +11048,7 @@ var DlmmModule = class {
11047
11048
  let tx = new import_transactions12.Transaction();
11048
11049
  tx = await this.collectFees(params);
11049
11050
  if (params.rewards_token.length > 0) {
11050
- tx = await this.collectReward(params);
11051
+ tx = await this.collectReward(params, tx);
11051
11052
  }
11052
11053
  return tx;
11053
11054
  }
@@ -11196,65 +11197,68 @@ var DlmmModule = class {
11196
11197
  });
11197
11198
  return res.sort((a, b) => a.real_bin_id - b.real_bin_id);
11198
11199
  }
11199
- /**
11200
- * Gets a list of positions for the given account address.
11201
- * @param accountAddress The account address to get positions for.
11202
- * @param assignPoolIds An array of pool IDs to filter the positions by.
11203
- * @returns array of Position objects.
11204
- */
11205
- async getUserPositionById(positionId, showDisplay = true) {
11206
- let position;
11207
- const ownerRes = await this._sdk.fullClient.getObject({
11208
- id: positionId,
11209
- options: { showContent: true, showType: true, showDisplay, showOwner: true }
11210
- });
11211
- const type = extractStructTagFromType(ownerRes.data.type);
11212
- if (type.full_address === this.buildPositionType()) {
11213
- position = this.buildPosition(ownerRes);
11214
- } else {
11215
- throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${ownerRes.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
11216
- }
11217
- const poolMap = /* @__PURE__ */ new Set();
11218
- poolMap.add(position.pool);
11219
- const pool = (await this.getPoolInfo(Array.from(poolMap)))[0];
11220
- const _params = [];
11221
- _params.push({
11222
- pool_id: pool.pool_id,
11223
- coin_a: pool.coin_a,
11224
- coin_b: pool.coin_b
11225
- });
11226
- const pool_reward_coins = await this.getPairRewarders(_params);
11227
- const positionLiquidity = await this.getPositionLiquidity({
11228
- pair: position.pool,
11229
- positionId: position.pos_object_id,
11230
- coinTypeA: pool.coin_a,
11231
- coinTypeB: pool.coin_b
11232
- });
11233
- const rewards_token = pool_reward_coins.get(position.pool) || [];
11234
- let positionRewards = { position_id: position.pos_object_id, reward: [], amount: [] };
11235
- if (rewards_token.length > 0) {
11236
- positionRewards = await this.getEarnedRewards({
11237
- pool_id: position.pool,
11238
- position_id: position.pos_object_id,
11239
- coin_a: pool.coin_a,
11240
- coin_b: pool.coin_b,
11241
- rewards_token: pool_reward_coins.get(position.pool) || []
11242
- });
11243
- }
11244
- const positionFees = await this.getEarnedFees({
11245
- pool_id: position.pool,
11246
- position_id: position.pos_object_id,
11247
- coin_a: pool.coin_a,
11248
- coin_b: pool.coin_b
11249
- });
11250
- return {
11251
- position,
11252
- liquidity: positionLiquidity,
11253
- rewards: positionRewards,
11254
- fees: positionFees,
11255
- contractPool: pool
11256
- };
11257
- }
11200
+ // /**
11201
+ // * Gets a list of positions for the given account address.
11202
+ // * @param accountAddress The account address to get positions for.
11203
+ // * @param assignPoolIds An array of pool IDs to filter the positions by.
11204
+ // * @returns array of Position objects.
11205
+ // */
11206
+ // async getUserPositionById(positionId: string, showDisplay = true): Promise<DlmmPositionInfo> {
11207
+ // let position
11208
+ // const ownerRes: any = await this._sdk.fullClient.getObject({
11209
+ // id: positionId,
11210
+ // options: { showContent: true, showType: true, showDisplay, showOwner: true },
11211
+ // })
11212
+ // const type = extractStructTagFromType(ownerRes.data.type)
11213
+ // if (type.full_address === this.buildPositionType()) {
11214
+ // position = this.buildPosition(ownerRes)
11215
+ // } else {
11216
+ // throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${ownerRes.error}`, PositionErrorCode.InvalidPositionObject)
11217
+ // }
11218
+ // const poolMap = new Set<string>()
11219
+ // poolMap.add(position.pool)
11220
+ // const pool = (await this.getPoolInfo(Array.from(poolMap)))[0]
11221
+ // const _params: GetPairRewarderParams[] = []
11222
+ // _params.push({
11223
+ // pool_id: pool.pool_id,
11224
+ // coin_a: pool.coin_a,
11225
+ // coin_b: pool.coin_b,
11226
+ // })
11227
+ // const pool_reward_coins = await this.getPairRewarders(_params)
11228
+ // // 1. Get Liquidity
11229
+ // // 2. Get rewards
11230
+ // // 3. Get fees
11231
+ // const positionLiquidity = await this.getPositionLiquidity({
11232
+ // pair: position.pool,
11233
+ // positionId: position.pos_object_id,
11234
+ // coinTypeA: pool!.coin_a,
11235
+ // coinTypeB: pool!.coin_b,
11236
+ // })
11237
+ // const rewards_token = pool_reward_coins.get(position.pool) || []
11238
+ // let positionRewards: DlmmEventEarnedRewards = { position_id: position.pos_object_id, reward: [], amount: [] }
11239
+ // if (rewards_token.length > 0) {
11240
+ // positionRewards = await this.getEarnedRewards({
11241
+ // pool_id: position.pool,
11242
+ // position_id: position.pos_object_id,
11243
+ // coin_a: pool!.coin_a,
11244
+ // coin_b: pool!.coin_b,
11245
+ // rewards_token: pool_reward_coins.get(position.pool) || [],
11246
+ // })
11247
+ // }
11248
+ // const positionFees = await this.getEarnedFees({
11249
+ // pool_id: position.pool,
11250
+ // position_id: position.pos_object_id,
11251
+ // coin_a: pool!.coin_a,
11252
+ // coin_b: pool!.coin_b,
11253
+ // })
11254
+ // return {
11255
+ // position,
11256
+ // liquidity: positionLiquidity,
11257
+ // rewards: positionRewards,
11258
+ // fees: positionFees,
11259
+ // contractPool: pool,
11260
+ // }
11261
+ // }
11258
11262
  /**
11259
11263
  * Gets a list of positions for the given account address.
11260
11264
  * @param accountAddress The account address to get positions for.
@@ -11298,19 +11302,20 @@ var DlmmModule = class {
11298
11302
  });
11299
11303
  }
11300
11304
  const pool_reward_coins = await this.getPairRewarders(_params);
11301
- const out = [];
11305
+ const positionLiquidityParams = [];
11306
+ const dlmmRewardsParams = [];
11307
+ const dlmmCollectFeeParams = [];
11302
11308
  for (const item of allPosition) {
11303
11309
  const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
11304
- const positionLiquidity = await this.getPositionLiquidity({
11310
+ positionLiquidityParams.push({
11305
11311
  pair: item.pool,
11306
11312
  positionId: item.pos_object_id,
11307
11313
  coinTypeA: pool.coin_a,
11308
11314
  coinTypeB: pool.coin_b
11309
11315
  });
11310
11316
  const rewards_token = pool_reward_coins.get(item.pool) || [];
11311
- let positionRewards = { position_id: item.pos_object_id, reward: [], amount: [] };
11312
11317
  if (rewards_token.length > 0) {
11313
- positionRewards = await this.getEarnedRewards({
11318
+ dlmmRewardsParams.push({
11314
11319
  pool_id: item.pool,
11315
11320
  position_id: item.pos_object_id,
11316
11321
  coin_a: pool.coin_a,
@@ -11318,16 +11323,27 @@ var DlmmModule = class {
11318
11323
  rewards_token: pool_reward_coins.get(item.pool) || []
11319
11324
  });
11320
11325
  }
11321
- const positionFees = await this.getEarnedFees({
11326
+ dlmmCollectFeeParams.push({
11322
11327
  pool_id: item.pool,
11323
11328
  position_id: item.pos_object_id,
11324
11329
  coin_a: pool.coin_a,
11325
11330
  coin_b: pool.coin_b
11326
11331
  });
11332
+ }
11333
+ const positionsLiquidity = await this.getPositionLiquidity(positionLiquidityParams);
11334
+ const positionsRewards = await this.getEarnedRewards(dlmmRewardsParams);
11335
+ const positionsFees = await this.getEarnedFees(dlmmCollectFeeParams);
11336
+ const out = [];
11337
+ for (let i = 0; i < allPosition.length; i++) {
11338
+ const item = allPosition[i];
11339
+ const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
11340
+ const positionLiquidity = positionsLiquidity.find((liquidity) => liquidity.position_id === item.pos_object_id);
11341
+ const positionRewards = positionsRewards.find((rewards) => rewards.position_id === item.pos_object_id);
11342
+ const positionFees = positionsFees.find((fees) => fees.position_id === item.pos_object_id);
11327
11343
  out.push({
11328
- position: item,
11344
+ position: allPosition[i],
11329
11345
  liquidity: positionLiquidity,
11330
- rewards: positionRewards,
11346
+ rewards: positionRewards || { position_id: item.pos_object_id, reward: [], amount: [] },
11331
11347
  fees: positionFees,
11332
11348
  contractPool: pool
11333
11349
  });
@@ -11366,8 +11382,15 @@ var DlmmModule = class {
11366
11382
  return `${this._sdk.sdkOptions.dlmm_pool.package_id}::dlmm_position::Position`;
11367
11383
  }
11368
11384
  async getPositionLiquidity(params) {
11369
- const tx = new import_transactions12.Transaction();
11370
- const { integrate, simulationAccount } = this.sdk.sdkOptions;
11385
+ let tx = new import_transactions12.Transaction();
11386
+ for (const param of params) {
11387
+ tx = await this._getPositionLiquidity(param, tx);
11388
+ }
11389
+ return this._parsePositionLiquidity(tx);
11390
+ }
11391
+ async _getPositionLiquidity(params, tx) {
11392
+ tx = tx || new import_transactions12.Transaction();
11393
+ const { integrate } = this.sdk.sdkOptions;
11371
11394
  const typeArguments = [params.coinTypeA, params.coinTypeB];
11372
11395
  const args = [tx.object(params.pair), tx.object(params.positionId)];
11373
11396
  tx.moveCall({
@@ -11375,6 +11398,10 @@ var DlmmModule = class {
11375
11398
  arguments: args,
11376
11399
  typeArguments
11377
11400
  });
11401
+ return tx;
11402
+ }
11403
+ async _parsePositionLiquidity(tx) {
11404
+ const { simulationAccount } = this.sdk.sdkOptions;
11378
11405
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11379
11406
  transactionBlock: tx,
11380
11407
  sender: simulationAccount.address
@@ -11382,26 +11409,20 @@ var DlmmModule = class {
11382
11409
  if (simulateRes.error != null) {
11383
11410
  throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11384
11411
  }
11385
- const out = {
11386
- shares: 0,
11387
- liquidity: 0,
11388
- x_equivalent: 0,
11389
- y_equivalent: 0,
11390
- bin_real_ids: [],
11391
- bin_x_eq: [],
11392
- bin_y_eq: [],
11393
- bin_liquidity: []
11394
- };
11412
+ const out = [];
11395
11413
  simulateRes.events?.forEach((item) => {
11396
11414
  if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
11397
- out.shares = item.parsedJson.shares;
11398
- out.liquidity = item.parsedJson.liquidity;
11399
- out.x_equivalent = item.parsedJson.x_equivalent;
11400
- out.y_equivalent = item.parsedJson.y_equivalent;
11401
- out.bin_real_ids = item.parsedJson.bin_ids.map((id) => (0, import_calc_dlmm3.get_real_id)(id));
11402
- out.bin_x_eq = item.parsedJson.bin_x_eq;
11403
- out.bin_y_eq = item.parsedJson.bin_y_eq;
11404
- out.bin_liquidity = item.parsedJson.bin_liquidity;
11415
+ out.push({
11416
+ position_id: item.parsedJson.position_id,
11417
+ shares: item.parsedJson.shares,
11418
+ liquidity: item.parsedJson.liquidity,
11419
+ x_equivalent: item.parsedJson.x_equivalent,
11420
+ y_equivalent: item.parsedJson.y_equivalent,
11421
+ bin_real_ids: item.parsedJson.bin_ids.map((id) => (0, import_calc_dlmm3.get_real_id)(id)),
11422
+ bin_x_eq: item.parsedJson.bin_x_eq,
11423
+ bin_y_eq: item.parsedJson.bin_y_eq,
11424
+ bin_liquidity: item.parsedJson.bin_liquidity
11425
+ });
11405
11426
  }
11406
11427
  });
11407
11428
  return out;
@@ -11446,8 +11467,15 @@ var DlmmModule = class {
11446
11467
  return out;
11447
11468
  }
11448
11469
  async getEarnedFees(params) {
11449
- const tx = new import_transactions12.Transaction();
11450
- const { integrate, simulationAccount } = this.sdk.sdkOptions;
11470
+ let tx = new import_transactions12.Transaction();
11471
+ for (const param of params) {
11472
+ tx = await this._getEarnedFees(param, tx);
11473
+ }
11474
+ return this._parseEarnedFees(tx);
11475
+ }
11476
+ async _getEarnedFees(params, tx) {
11477
+ tx = tx || new import_transactions12.Transaction();
11478
+ const { integrate } = this.sdk.sdkOptions;
11451
11479
  const typeArguments = [params.coin_a, params.coin_b];
11452
11480
  const args = [tx.object(params.pool_id), tx.object(params.position_id)];
11453
11481
  tx.moveCall({
@@ -11455,34 +11483,41 @@ var DlmmModule = class {
11455
11483
  arguments: args,
11456
11484
  typeArguments
11457
11485
  });
11486
+ return tx;
11487
+ }
11488
+ async _parseEarnedFees(tx) {
11489
+ const { simulationAccount } = this.sdk.sdkOptions;
11458
11490
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11459
11491
  transactionBlock: tx,
11460
11492
  sender: simulationAccount.address
11461
11493
  });
11462
- const out = {
11463
- position_id: "",
11464
- x: "",
11465
- y: "",
11466
- fee_x: 0,
11467
- fee_y: 0
11468
- };
11494
+ const out = [];
11469
11495
  if (simulateRes.error != null) {
11470
11496
  throw new Error(`fetchPairRewards error code: ${simulateRes.error ?? "unknown error"}`);
11471
11497
  }
11472
11498
  simulateRes.events?.forEach((item) => {
11473
11499
  if (extractStructTagFromType(item.type).name === `EventEarnedFees`) {
11474
- out.position_id = item.parsedJson.position_id;
11475
- out.x = item.parsedJson.x.name;
11476
- out.y = item.parsedJson.y.name;
11477
- out.fee_x = item.parsedJson.fee_x;
11478
- out.fee_y = item.parsedJson.fee_y;
11500
+ out.push({
11501
+ position_id: item.parsedJson.position_id,
11502
+ x: item.parsedJson.x.name,
11503
+ y: item.parsedJson.y.name,
11504
+ fee_x: item.parsedJson.fee_x,
11505
+ fee_y: item.parsedJson.fee_y
11506
+ });
11479
11507
  }
11480
11508
  });
11481
11509
  return out;
11482
11510
  }
11483
11511
  async getEarnedRewards(params) {
11484
- const tx = new import_transactions12.Transaction();
11485
- const { integrate, simulationAccount } = this.sdk.sdkOptions;
11512
+ let tx = new import_transactions12.Transaction();
11513
+ for (const param of params) {
11514
+ tx = await this._getEarnedRewards(param, tx);
11515
+ }
11516
+ return this._parseEarnedRewards(tx);
11517
+ }
11518
+ async _getEarnedRewards(params, tx) {
11519
+ tx = tx || new import_transactions12.Transaction();
11520
+ const { integrate } = this.sdk.sdkOptions;
11486
11521
  const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
11487
11522
  const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
11488
11523
  let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
@@ -11494,34 +11529,40 @@ var DlmmModule = class {
11494
11529
  arguments: args,
11495
11530
  typeArguments
11496
11531
  });
11532
+ return tx;
11533
+ }
11534
+ async _parseEarnedRewards(tx) {
11535
+ const { simulationAccount } = this.sdk.sdkOptions;
11497
11536
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11498
11537
  transactionBlock: tx,
11499
11538
  sender: simulationAccount.address
11500
11539
  });
11501
- const out = {
11502
- position_id: "",
11503
- reward: [],
11504
- amount: []
11505
- };
11540
+ const res = [];
11506
11541
  if (simulateRes.error != null) {
11507
11542
  throw new Error(`getEarnedRewards error code: ${simulateRes.error ?? "unknown error"}`);
11508
11543
  }
11509
11544
  simulateRes.events?.forEach((item) => {
11510
11545
  if (extractStructTagFromType(item.type).name === `EventEarnedRewards`) {
11511
- out.position_id = item.parsedJson.position_id;
11512
- out.reward = [item.parsedJson.reward.name];
11513
- out.amount = [item.parsedJson.amount];
11546
+ res.push({
11547
+ position_id: item.parsedJson.position_id,
11548
+ reward: [item.parsedJson.reward.name],
11549
+ amount: [item.parsedJson.amount]
11550
+ });
11514
11551
  } else if (extractStructTagFromType(item.type).name === `EventEarnedRewards2`) {
11515
- out.position_id = item.parsedJson.position_id;
11516
- out.reward = [item.parsedJson.reward1.name, item.parsedJson.reward2.name];
11517
- out.amount = [item.parsedJson.amount1, item.parsedJson.amount2];
11552
+ res.push({
11553
+ position_id: item.parsedJson.position_id,
11554
+ reward: [item.parsedJson.reward1.name, item.parsedJson.reward2.name],
11555
+ amount: [item.parsedJson.amount1, item.parsedJson.amount2]
11556
+ });
11518
11557
  } else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
11519
- out.position_id = item.parsedJson.position_id;
11520
- out.reward = [item.parsedJson.reward1.name, item.parsedJson.reward2.name, item.parsedJson.reward3.name];
11521
- out.amount = [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3];
11558
+ res.push({
11559
+ position_id: item.parsedJson.position_id,
11560
+ reward: [item.parsedJson.reward1.name, item.parsedJson.reward2.name, item.parsedJson.reward3.name],
11561
+ amount: [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3]
11562
+ });
11522
11563
  }
11523
11564
  });
11524
- return out;
11565
+ return res;
11525
11566
  }
11526
11567
  // return pool_id => reward_tokens
11527
11568
  async getPairRewarders(params) {
@@ -11904,7 +11945,8 @@ var SDKConfig = {
11904
11945
  minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
11905
11946
  },
11906
11947
  dlmmConfig: {
11907
- factory: ""
11948
+ factory: "",
11949
+ rewarder_global_vault: ""
11908
11950
  },
11909
11951
  gaugeConfig: {}
11910
11952
  };
@@ -11990,7 +12032,8 @@ var SDKConfig2 = {
11990
12032
  minter_id: "0x89435d6b2a510ba50ca23303f10e91ec058f138a88f69a43fe03cd22edb214c5"
11991
12033
  },
11992
12034
  dlmmConfig: {
11993
- factory: ""
12035
+ factory: "",
12036
+ rewarder_global_vault: ""
11994
12037
  }
11995
12038
  };
11996
12039
  var clmmTestnet = {