@magmaprotocol/magma-clmm-sdk 0.5.89 → 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.mjs CHANGED
@@ -10765,6 +10765,7 @@ var DlmmModule = class {
10765
10765
  const args = [
10766
10766
  tx.object(params.pair),
10767
10767
  tx.object(dlmmConfig.factory),
10768
+ tx.object(dlmm_pool.config.rewarder_global_vault),
10768
10769
  tx.object(params.positionId),
10769
10770
  primaryCoinAInputs.targetCoin,
10770
10771
  primaryCoinBInputs.targetCoin,
@@ -10983,65 +10984,68 @@ var DlmmModule = class {
10983
10984
  });
10984
10985
  return res.sort((a, b) => a.real_bin_id - b.real_bin_id);
10985
10986
  }
10986
- /**
10987
- * Gets a list of positions for the given account address.
10988
- * @param accountAddress The account address to get positions for.
10989
- * @param assignPoolIds An array of pool IDs to filter the positions by.
10990
- * @returns array of Position objects.
10991
- */
10992
- async getUserPositionById(positionId, showDisplay = true) {
10993
- let position;
10994
- const ownerRes = await this._sdk.fullClient.getObject({
10995
- id: positionId,
10996
- options: { showContent: true, showType: true, showDisplay, showOwner: true }
10997
- });
10998
- const type = extractStructTagFromType(ownerRes.data.type);
10999
- if (type.full_address === this.buildPositionType()) {
11000
- position = this.buildPosition(ownerRes);
11001
- } else {
11002
- throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${ownerRes.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
11003
- }
11004
- const poolMap = /* @__PURE__ */ new Set();
11005
- poolMap.add(position.pool);
11006
- const pool = (await this.getPoolInfo(Array.from(poolMap)))[0];
11007
- const _params = [];
11008
- _params.push({
11009
- pool_id: pool.pool_id,
11010
- coin_a: pool.coin_a,
11011
- coin_b: pool.coin_b
11012
- });
11013
- const pool_reward_coins = await this.getPairRewarders(_params);
11014
- const positionLiquidity = await this.getPositionLiquidity({
11015
- pair: position.pool,
11016
- positionId: position.pos_object_id,
11017
- coinTypeA: pool.coin_a,
11018
- coinTypeB: pool.coin_b
11019
- });
11020
- const rewards_token = pool_reward_coins.get(position.pool) || [];
11021
- let positionRewards = { position_id: position.pos_object_id, reward: [], amount: [] };
11022
- if (rewards_token.length > 0) {
11023
- positionRewards = await this.getEarnedRewards({
11024
- pool_id: position.pool,
11025
- position_id: position.pos_object_id,
11026
- coin_a: pool.coin_a,
11027
- coin_b: pool.coin_b,
11028
- rewards_token: pool_reward_coins.get(position.pool) || []
11029
- });
11030
- }
11031
- const positionFees = await this.getEarnedFees({
11032
- pool_id: position.pool,
11033
- position_id: position.pos_object_id,
11034
- coin_a: pool.coin_a,
11035
- coin_b: pool.coin_b
11036
- });
11037
- return {
11038
- position,
11039
- liquidity: positionLiquidity,
11040
- rewards: positionRewards,
11041
- fees: positionFees,
11042
- contractPool: pool
11043
- };
11044
- }
10987
+ // /**
10988
+ // * Gets a list of positions for the given account address.
10989
+ // * @param accountAddress The account address to get positions for.
10990
+ // * @param assignPoolIds An array of pool IDs to filter the positions by.
10991
+ // * @returns array of Position objects.
10992
+ // */
10993
+ // async getUserPositionById(positionId: string, showDisplay = true): Promise<DlmmPositionInfo> {
10994
+ // let position
10995
+ // const ownerRes: any = await this._sdk.fullClient.getObject({
10996
+ // id: positionId,
10997
+ // options: { showContent: true, showType: true, showDisplay, showOwner: true },
10998
+ // })
10999
+ // const type = extractStructTagFromType(ownerRes.data.type)
11000
+ // if (type.full_address === this.buildPositionType()) {
11001
+ // position = this.buildPosition(ownerRes)
11002
+ // } else {
11003
+ // throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${ownerRes.error}`, PositionErrorCode.InvalidPositionObject)
11004
+ // }
11005
+ // const poolMap = new Set<string>()
11006
+ // poolMap.add(position.pool)
11007
+ // const pool = (await this.getPoolInfo(Array.from(poolMap)))[0]
11008
+ // const _params: GetPairRewarderParams[] = []
11009
+ // _params.push({
11010
+ // pool_id: pool.pool_id,
11011
+ // coin_a: pool.coin_a,
11012
+ // coin_b: pool.coin_b,
11013
+ // })
11014
+ // const pool_reward_coins = await this.getPairRewarders(_params)
11015
+ // // 1. Get Liquidity
11016
+ // // 2. Get rewards
11017
+ // // 3. Get fees
11018
+ // const positionLiquidity = await this.getPositionLiquidity({
11019
+ // pair: position.pool,
11020
+ // positionId: position.pos_object_id,
11021
+ // coinTypeA: pool!.coin_a,
11022
+ // coinTypeB: pool!.coin_b,
11023
+ // })
11024
+ // const rewards_token = pool_reward_coins.get(position.pool) || []
11025
+ // let positionRewards: DlmmEventEarnedRewards = { position_id: position.pos_object_id, reward: [], amount: [] }
11026
+ // if (rewards_token.length > 0) {
11027
+ // positionRewards = await this.getEarnedRewards({
11028
+ // pool_id: position.pool,
11029
+ // position_id: position.pos_object_id,
11030
+ // coin_a: pool!.coin_a,
11031
+ // coin_b: pool!.coin_b,
11032
+ // rewards_token: pool_reward_coins.get(position.pool) || [],
11033
+ // })
11034
+ // }
11035
+ // const positionFees = await this.getEarnedFees({
11036
+ // pool_id: position.pool,
11037
+ // position_id: position.pos_object_id,
11038
+ // coin_a: pool!.coin_a,
11039
+ // coin_b: pool!.coin_b,
11040
+ // })
11041
+ // return {
11042
+ // position,
11043
+ // liquidity: positionLiquidity,
11044
+ // rewards: positionRewards,
11045
+ // fees: positionFees,
11046
+ // contractPool: pool,
11047
+ // }
11048
+ // }
11045
11049
  /**
11046
11050
  * Gets a list of positions for the given account address.
11047
11051
  * @param accountAddress The account address to get positions for.
@@ -11085,19 +11089,20 @@ var DlmmModule = class {
11085
11089
  });
11086
11090
  }
11087
11091
  const pool_reward_coins = await this.getPairRewarders(_params);
11088
- const out = [];
11092
+ const positionLiquidityParams = [];
11093
+ const dlmmRewardsParams = [];
11094
+ const dlmmCollectFeeParams = [];
11089
11095
  for (const item of allPosition) {
11090
11096
  const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
11091
- const positionLiquidity = await this.getPositionLiquidity({
11097
+ positionLiquidityParams.push({
11092
11098
  pair: item.pool,
11093
11099
  positionId: item.pos_object_id,
11094
11100
  coinTypeA: pool.coin_a,
11095
11101
  coinTypeB: pool.coin_b
11096
11102
  });
11097
11103
  const rewards_token = pool_reward_coins.get(item.pool) || [];
11098
- let positionRewards = { position_id: item.pos_object_id, reward: [], amount: [] };
11099
11104
  if (rewards_token.length > 0) {
11100
- positionRewards = await this.getEarnedRewards({
11105
+ dlmmRewardsParams.push({
11101
11106
  pool_id: item.pool,
11102
11107
  position_id: item.pos_object_id,
11103
11108
  coin_a: pool.coin_a,
@@ -11105,16 +11110,27 @@ var DlmmModule = class {
11105
11110
  rewards_token: pool_reward_coins.get(item.pool) || []
11106
11111
  });
11107
11112
  }
11108
- const positionFees = await this.getEarnedFees({
11113
+ dlmmCollectFeeParams.push({
11109
11114
  pool_id: item.pool,
11110
11115
  position_id: item.pos_object_id,
11111
11116
  coin_a: pool.coin_a,
11112
11117
  coin_b: pool.coin_b
11113
11118
  });
11119
+ }
11120
+ const positionsLiquidity = await this.getPositionLiquidity(positionLiquidityParams);
11121
+ const positionsRewards = await this.getEarnedRewards(dlmmRewardsParams);
11122
+ const positionsFees = await this.getEarnedFees(dlmmCollectFeeParams);
11123
+ const out = [];
11124
+ for (let i = 0; i < allPosition.length; i++) {
11125
+ const item = allPosition[i];
11126
+ const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
11127
+ const positionLiquidity = positionsLiquidity.find((liquidity) => liquidity.position_id === item.pos_object_id);
11128
+ const positionRewards = positionsRewards.find((rewards) => rewards.position_id === item.pos_object_id);
11129
+ const positionFees = positionsFees.find((fees) => fees.position_id === item.pos_object_id);
11114
11130
  out.push({
11115
- position: item,
11131
+ position: allPosition[i],
11116
11132
  liquidity: positionLiquidity,
11117
- rewards: positionRewards,
11133
+ rewards: positionRewards || { position_id: item.pos_object_id, reward: [], amount: [] },
11118
11134
  fees: positionFees,
11119
11135
  contractPool: pool
11120
11136
  });
@@ -11153,8 +11169,15 @@ var DlmmModule = class {
11153
11169
  return `${this._sdk.sdkOptions.dlmm_pool.package_id}::dlmm_position::Position`;
11154
11170
  }
11155
11171
  async getPositionLiquidity(params) {
11156
- const tx = new Transaction12();
11157
- const { integrate, simulationAccount } = this.sdk.sdkOptions;
11172
+ let tx = new Transaction12();
11173
+ for (const param of params) {
11174
+ tx = await this._getPositionLiquidity(param, tx);
11175
+ }
11176
+ return this._parsePositionLiquidity(tx);
11177
+ }
11178
+ async _getPositionLiquidity(params, tx) {
11179
+ tx = tx || new Transaction12();
11180
+ const { integrate } = this.sdk.sdkOptions;
11158
11181
  const typeArguments = [params.coinTypeA, params.coinTypeB];
11159
11182
  const args = [tx.object(params.pair), tx.object(params.positionId)];
11160
11183
  tx.moveCall({
@@ -11162,6 +11185,10 @@ var DlmmModule = class {
11162
11185
  arguments: args,
11163
11186
  typeArguments
11164
11187
  });
11188
+ return tx;
11189
+ }
11190
+ async _parsePositionLiquidity(tx) {
11191
+ const { simulationAccount } = this.sdk.sdkOptions;
11165
11192
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11166
11193
  transactionBlock: tx,
11167
11194
  sender: simulationAccount.address
@@ -11169,26 +11196,20 @@ var DlmmModule = class {
11169
11196
  if (simulateRes.error != null) {
11170
11197
  throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11171
11198
  }
11172
- const out = {
11173
- shares: 0,
11174
- liquidity: 0,
11175
- x_equivalent: 0,
11176
- y_equivalent: 0,
11177
- bin_real_ids: [],
11178
- bin_x_eq: [],
11179
- bin_y_eq: [],
11180
- bin_liquidity: []
11181
- };
11199
+ const out = [];
11182
11200
  simulateRes.events?.forEach((item) => {
11183
11201
  if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
11184
- out.shares = item.parsedJson.shares;
11185
- out.liquidity = item.parsedJson.liquidity;
11186
- out.x_equivalent = item.parsedJson.x_equivalent;
11187
- out.y_equivalent = item.parsedJson.y_equivalent;
11188
- out.bin_real_ids = item.parsedJson.bin_ids.map((id) => get_real_id(id));
11189
- out.bin_x_eq = item.parsedJson.bin_x_eq;
11190
- out.bin_y_eq = item.parsedJson.bin_y_eq;
11191
- out.bin_liquidity = item.parsedJson.bin_liquidity;
11202
+ out.push({
11203
+ position_id: item.parsedJson.position_id,
11204
+ shares: item.parsedJson.shares,
11205
+ liquidity: item.parsedJson.liquidity,
11206
+ x_equivalent: item.parsedJson.x_equivalent,
11207
+ y_equivalent: item.parsedJson.y_equivalent,
11208
+ bin_real_ids: item.parsedJson.bin_ids.map((id) => get_real_id(id)),
11209
+ bin_x_eq: item.parsedJson.bin_x_eq,
11210
+ bin_y_eq: item.parsedJson.bin_y_eq,
11211
+ bin_liquidity: item.parsedJson.bin_liquidity
11212
+ });
11192
11213
  }
11193
11214
  });
11194
11215
  return out;
@@ -11233,8 +11254,15 @@ var DlmmModule = class {
11233
11254
  return out;
11234
11255
  }
11235
11256
  async getEarnedFees(params) {
11236
- const tx = new Transaction12();
11237
- const { integrate, simulationAccount } = this.sdk.sdkOptions;
11257
+ let tx = new Transaction12();
11258
+ for (const param of params) {
11259
+ tx = await this._getEarnedFees(param, tx);
11260
+ }
11261
+ return this._parseEarnedFees(tx);
11262
+ }
11263
+ async _getEarnedFees(params, tx) {
11264
+ tx = tx || new Transaction12();
11265
+ const { integrate } = this.sdk.sdkOptions;
11238
11266
  const typeArguments = [params.coin_a, params.coin_b];
11239
11267
  const args = [tx.object(params.pool_id), tx.object(params.position_id)];
11240
11268
  tx.moveCall({
@@ -11242,34 +11270,41 @@ var DlmmModule = class {
11242
11270
  arguments: args,
11243
11271
  typeArguments
11244
11272
  });
11273
+ return tx;
11274
+ }
11275
+ async _parseEarnedFees(tx) {
11276
+ const { simulationAccount } = this.sdk.sdkOptions;
11245
11277
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11246
11278
  transactionBlock: tx,
11247
11279
  sender: simulationAccount.address
11248
11280
  });
11249
- const out = {
11250
- position_id: "",
11251
- x: "",
11252
- y: "",
11253
- fee_x: 0,
11254
- fee_y: 0
11255
- };
11281
+ const out = [];
11256
11282
  if (simulateRes.error != null) {
11257
11283
  throw new Error(`fetchPairRewards error code: ${simulateRes.error ?? "unknown error"}`);
11258
11284
  }
11259
11285
  simulateRes.events?.forEach((item) => {
11260
11286
  if (extractStructTagFromType(item.type).name === `EventEarnedFees`) {
11261
- out.position_id = item.parsedJson.position_id;
11262
- out.x = item.parsedJson.x.name;
11263
- out.y = item.parsedJson.y.name;
11264
- out.fee_x = item.parsedJson.fee_x;
11265
- out.fee_y = item.parsedJson.fee_y;
11287
+ out.push({
11288
+ position_id: item.parsedJson.position_id,
11289
+ x: item.parsedJson.x.name,
11290
+ y: item.parsedJson.y.name,
11291
+ fee_x: item.parsedJson.fee_x,
11292
+ fee_y: item.parsedJson.fee_y
11293
+ });
11266
11294
  }
11267
11295
  });
11268
11296
  return out;
11269
11297
  }
11270
11298
  async getEarnedRewards(params) {
11271
- const tx = new Transaction12();
11272
- const { integrate, simulationAccount } = this.sdk.sdkOptions;
11299
+ let tx = new Transaction12();
11300
+ for (const param of params) {
11301
+ tx = await this._getEarnedRewards(param, tx);
11302
+ }
11303
+ return this._parseEarnedRewards(tx);
11304
+ }
11305
+ async _getEarnedRewards(params, tx) {
11306
+ tx = tx || new Transaction12();
11307
+ const { integrate } = this.sdk.sdkOptions;
11273
11308
  const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
11274
11309
  const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
11275
11310
  let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
@@ -11281,34 +11316,40 @@ var DlmmModule = class {
11281
11316
  arguments: args,
11282
11317
  typeArguments
11283
11318
  });
11319
+ return tx;
11320
+ }
11321
+ async _parseEarnedRewards(tx) {
11322
+ const { simulationAccount } = this.sdk.sdkOptions;
11284
11323
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11285
11324
  transactionBlock: tx,
11286
11325
  sender: simulationAccount.address
11287
11326
  });
11288
- const out = {
11289
- position_id: "",
11290
- reward: [],
11291
- amount: []
11292
- };
11327
+ const res = [];
11293
11328
  if (simulateRes.error != null) {
11294
11329
  throw new Error(`getEarnedRewards error code: ${simulateRes.error ?? "unknown error"}`);
11295
11330
  }
11296
11331
  simulateRes.events?.forEach((item) => {
11297
11332
  if (extractStructTagFromType(item.type).name === `EventEarnedRewards`) {
11298
- out.position_id = item.parsedJson.position_id;
11299
- out.reward = [item.parsedJson.reward.name];
11300
- out.amount = [item.parsedJson.amount];
11333
+ res.push({
11334
+ position_id: item.parsedJson.position_id,
11335
+ reward: [item.parsedJson.reward.name],
11336
+ amount: [item.parsedJson.amount]
11337
+ });
11301
11338
  } else if (extractStructTagFromType(item.type).name === `EventEarnedRewards2`) {
11302
- out.position_id = item.parsedJson.position_id;
11303
- out.reward = [item.parsedJson.reward1.name, item.parsedJson.reward2.name];
11304
- out.amount = [item.parsedJson.amount1, item.parsedJson.amount2];
11339
+ res.push({
11340
+ position_id: item.parsedJson.position_id,
11341
+ reward: [item.parsedJson.reward1.name, item.parsedJson.reward2.name],
11342
+ amount: [item.parsedJson.amount1, item.parsedJson.amount2]
11343
+ });
11305
11344
  } else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
11306
- out.position_id = item.parsedJson.position_id;
11307
- out.reward = [item.parsedJson.reward1.name, item.parsedJson.reward2.name, item.parsedJson.reward3.name];
11308
- out.amount = [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3];
11345
+ res.push({
11346
+ position_id: item.parsedJson.position_id,
11347
+ reward: [item.parsedJson.reward1.name, item.parsedJson.reward2.name, item.parsedJson.reward3.name],
11348
+ amount: [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3]
11349
+ });
11309
11350
  }
11310
11351
  });
11311
- return out;
11352
+ return res;
11312
11353
  }
11313
11354
  // return pool_id => reward_tokens
11314
11355
  async getPairRewarders(params) {
@@ -11691,7 +11732,8 @@ var SDKConfig = {
11691
11732
  minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
11692
11733
  },
11693
11734
  dlmmConfig: {
11694
- factory: ""
11735
+ factory: "",
11736
+ rewarder_global_vault: ""
11695
11737
  },
11696
11738
  gaugeConfig: {}
11697
11739
  };
@@ -11777,7 +11819,8 @@ var SDKConfig2 = {
11777
11819
  minter_id: "0x89435d6b2a510ba50ca23303f10e91ec058f138a88f69a43fe03cd22edb214c5"
11778
11820
  },
11779
11821
  dlmmConfig: {
11780
- factory: ""
11822
+ factory: "",
11823
+ rewarder_global_vault: ""
11781
11824
  }
11782
11825
  };
11783
11826
  var clmmTestnet = {