@magmaprotocol/magma-clmm-sdk 0.5.89 → 0.5.91

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
@@ -10471,7 +10471,7 @@ var DlmmModule = class {
10471
10471
  sender: simulationAccount.address
10472
10472
  });
10473
10473
  if (simulateRes.error != null) {
10474
- throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
10474
+ throw new Error(`fetchPairParams error code: ${simulateRes.error ?? "unknown error"}`);
10475
10475
  }
10476
10476
  let res = {
10477
10477
  base_factor: 0,
@@ -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,
@@ -10969,7 +10970,7 @@ var DlmmModule = class {
10969
10970
  sender: simulationAccount.address
10970
10971
  });
10971
10972
  if (simulateRes.error != null) {
10972
- throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
10973
+ throw new Error(`swap code: ${simulateRes.error ?? "unknown error"}`);
10973
10974
  }
10974
10975
  let res = [];
10975
10976
  simulateRes.events?.forEach((item) => {
@@ -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.getPositionsLiquidityLimit(positionLiquidityParams);
11121
+ const positionsRewards = await this.getEarnedRewards(dlmmRewardsParams);
11122
+ const positionsFees = await this.getEarnedFeesLimit(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
  });
@@ -11152,9 +11168,30 @@ var DlmmModule = class {
11152
11168
  buildPositionType() {
11153
11169
  return `${this._sdk.sdkOptions.dlmm_pool.package_id}::dlmm_position::Position`;
11154
11170
  }
11155
- async getPositionLiquidity(params) {
11156
- const tx = new Transaction12();
11157
- const { integrate, simulationAccount } = this.sdk.sdkOptions;
11171
+ async getPositionsLiquidityLimit(params) {
11172
+ const out = [];
11173
+ const limit = 2;
11174
+ for (let i = 0; i < params.length; i += limit) {
11175
+ if (i + limit >= params.length) {
11176
+ const res2 = await this.getPositionsLiquidity(params.slice(i, params.length));
11177
+ out.push(...res2);
11178
+ return out;
11179
+ }
11180
+ const res = await this.getPositionsLiquidity(params.slice(i, i + limit));
11181
+ out.push(...res);
11182
+ }
11183
+ return out;
11184
+ }
11185
+ async getPositionsLiquidity(params) {
11186
+ let tx = new Transaction12();
11187
+ for (const param of params) {
11188
+ tx = await this._getPositionLiquidity(param, tx);
11189
+ }
11190
+ return this._parsePositionLiquidity(tx);
11191
+ }
11192
+ async _getPositionLiquidity(params, tx) {
11193
+ tx = tx || new Transaction12();
11194
+ const { integrate } = this.sdk.sdkOptions;
11158
11195
  const typeArguments = [params.coinTypeA, params.coinTypeB];
11159
11196
  const args = [tx.object(params.pair), tx.object(params.positionId)];
11160
11197
  tx.moveCall({
@@ -11162,33 +11199,31 @@ var DlmmModule = class {
11162
11199
  arguments: args,
11163
11200
  typeArguments
11164
11201
  });
11202
+ return tx;
11203
+ }
11204
+ async _parsePositionLiquidity(tx) {
11205
+ const { simulationAccount } = this.sdk.sdkOptions;
11165
11206
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11166
11207
  transactionBlock: tx,
11167
11208
  sender: simulationAccount.address
11168
11209
  });
11169
11210
  if (simulateRes.error != null) {
11170
- throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11211
+ throw new Error(`fetchPositionLiquidity error code: ${simulateRes.error ?? "unknown error"}`);
11171
11212
  }
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
- };
11213
+ const out = [];
11182
11214
  simulateRes.events?.forEach((item) => {
11183
11215
  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;
11216
+ out.push({
11217
+ position_id: item.parsedJson.position_id,
11218
+ shares: item.parsedJson.shares,
11219
+ liquidity: item.parsedJson.liquidity,
11220
+ x_equivalent: item.parsedJson.x_equivalent,
11221
+ y_equivalent: item.parsedJson.y_equivalent,
11222
+ bin_real_ids: item.parsedJson.bin_ids.map((id) => get_real_id(id)),
11223
+ bin_x_eq: item.parsedJson.bin_x_eq,
11224
+ bin_y_eq: item.parsedJson.bin_y_eq,
11225
+ bin_liquidity: item.parsedJson.bin_liquidity
11226
+ });
11192
11227
  }
11193
11228
  });
11194
11229
  return out;
@@ -11208,7 +11243,7 @@ var DlmmModule = class {
11208
11243
  sender: simulationAccount.address
11209
11244
  });
11210
11245
  if (simulateRes.error != null) {
11211
- throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11246
+ throw new Error(`getPairLiquidity error code: ${simulateRes.error ?? "unknown error"}`);
11212
11247
  }
11213
11248
  const out = {
11214
11249
  shares: 0,
@@ -11232,9 +11267,31 @@ var DlmmModule = class {
11232
11267
  });
11233
11268
  return out;
11234
11269
  }
11270
+ async getEarnedFeesLimit(params) {
11271
+ const out = [];
11272
+ const limit = 2;
11273
+ for (let i = 0; i < params.length; i += limit) {
11274
+ if (i + limit >= params.length) {
11275
+ const res2 = await this.getEarnedFees(params.slice(i, params.length));
11276
+ out.push(...res2);
11277
+ return out;
11278
+ }
11279
+ const res = await this.getEarnedFees(params.slice(i, i + limit));
11280
+ out.push(...res);
11281
+ }
11282
+ return out;
11283
+ }
11235
11284
  async getEarnedFees(params) {
11236
- const tx = new Transaction12();
11237
- const { integrate, simulationAccount } = this.sdk.sdkOptions;
11285
+ console.log("############ params: ", params);
11286
+ let tx = new Transaction12();
11287
+ for (const param of params) {
11288
+ tx = await this._getEarnedFees(param, tx);
11289
+ }
11290
+ return this._parseEarnedFees(tx);
11291
+ }
11292
+ async _getEarnedFees(params, tx) {
11293
+ tx = tx || new Transaction12();
11294
+ const { integrate } = this.sdk.sdkOptions;
11238
11295
  const typeArguments = [params.coin_a, params.coin_b];
11239
11296
  const args = [tx.object(params.pool_id), tx.object(params.position_id)];
11240
11297
  tx.moveCall({
@@ -11242,34 +11299,41 @@ var DlmmModule = class {
11242
11299
  arguments: args,
11243
11300
  typeArguments
11244
11301
  });
11302
+ return tx;
11303
+ }
11304
+ async _parseEarnedFees(tx) {
11305
+ const { simulationAccount } = this.sdk.sdkOptions;
11245
11306
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11246
11307
  transactionBlock: tx,
11247
11308
  sender: simulationAccount.address
11248
11309
  });
11249
- const out = {
11250
- position_id: "",
11251
- x: "",
11252
- y: "",
11253
- fee_x: 0,
11254
- fee_y: 0
11255
- };
11310
+ const out = [];
11256
11311
  if (simulateRes.error != null) {
11257
11312
  throw new Error(`fetchPairRewards error code: ${simulateRes.error ?? "unknown error"}`);
11258
11313
  }
11259
11314
  simulateRes.events?.forEach((item) => {
11260
11315
  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;
11316
+ out.push({
11317
+ position_id: item.parsedJson.position_id,
11318
+ x: item.parsedJson.x.name,
11319
+ y: item.parsedJson.y.name,
11320
+ fee_x: item.parsedJson.fee_x,
11321
+ fee_y: item.parsedJson.fee_y
11322
+ });
11266
11323
  }
11267
11324
  });
11268
11325
  return out;
11269
11326
  }
11270
11327
  async getEarnedRewards(params) {
11271
- const tx = new Transaction12();
11272
- const { integrate, simulationAccount } = this.sdk.sdkOptions;
11328
+ let tx = new Transaction12();
11329
+ for (const param of params) {
11330
+ tx = await this._getEarnedRewards(param, tx);
11331
+ }
11332
+ return this._parseEarnedRewards(tx);
11333
+ }
11334
+ async _getEarnedRewards(params, tx) {
11335
+ tx = tx || new Transaction12();
11336
+ const { integrate } = this.sdk.sdkOptions;
11273
11337
  const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
11274
11338
  const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
11275
11339
  let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
@@ -11281,37 +11345,44 @@ var DlmmModule = class {
11281
11345
  arguments: args,
11282
11346
  typeArguments
11283
11347
  });
11348
+ return tx;
11349
+ }
11350
+ async _parseEarnedRewards(tx) {
11351
+ const { simulationAccount } = this.sdk.sdkOptions;
11284
11352
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11285
11353
  transactionBlock: tx,
11286
11354
  sender: simulationAccount.address
11287
11355
  });
11288
- const out = {
11289
- position_id: "",
11290
- reward: [],
11291
- amount: []
11292
- };
11356
+ const res = [];
11293
11357
  if (simulateRes.error != null) {
11294
11358
  throw new Error(`getEarnedRewards error code: ${simulateRes.error ?? "unknown error"}`);
11295
11359
  }
11296
11360
  simulateRes.events?.forEach((item) => {
11297
11361
  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];
11362
+ res.push({
11363
+ position_id: item.parsedJson.position_id,
11364
+ reward: [item.parsedJson.reward.name],
11365
+ amount: [item.parsedJson.amount]
11366
+ });
11301
11367
  } 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];
11368
+ res.push({
11369
+ position_id: item.parsedJson.position_id,
11370
+ reward: [item.parsedJson.reward1.name, item.parsedJson.reward2.name],
11371
+ amount: [item.parsedJson.amount1, item.parsedJson.amount2]
11372
+ });
11305
11373
  } 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];
11374
+ res.push({
11375
+ position_id: item.parsedJson.position_id,
11376
+ reward: [item.parsedJson.reward1.name, item.parsedJson.reward2.name, item.parsedJson.reward3.name],
11377
+ amount: [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3]
11378
+ });
11309
11379
  }
11310
11380
  });
11311
- return out;
11381
+ return res;
11312
11382
  }
11313
11383
  // return pool_id => reward_tokens
11314
11384
  async getPairRewarders(params) {
11385
+ params = [params[0]];
11315
11386
  let tx = new Transaction12();
11316
11387
  for (const param of params) {
11317
11388
  tx = await this._getPairRewarders(param, tx);
@@ -11338,7 +11409,7 @@ var DlmmModule = class {
11338
11409
  });
11339
11410
  const out = /* @__PURE__ */ new Map();
11340
11411
  if (simulateRes.error != null) {
11341
- throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11412
+ throw new Error(`getPairReward error code: ${simulateRes.error ?? "unknown error"}`);
11342
11413
  }
11343
11414
  simulateRes.events?.forEach((item) => {
11344
11415
  if (extractStructTagFromType(item.type).name === `EventPairRewardTypes`) {
@@ -11691,7 +11762,8 @@ var SDKConfig = {
11691
11762
  minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
11692
11763
  },
11693
11764
  dlmmConfig: {
11694
- factory: ""
11765
+ factory: "",
11766
+ rewarder_global_vault: ""
11695
11767
  },
11696
11768
  gaugeConfig: {}
11697
11769
  };
@@ -11777,7 +11849,8 @@ var SDKConfig2 = {
11777
11849
  minter_id: "0x89435d6b2a510ba50ca23303f10e91ec058f138a88f69a43fe03cd22edb214c5"
11778
11850
  },
11779
11851
  dlmmConfig: {
11780
- factory: ""
11852
+ factory: "",
11853
+ rewarder_global_vault: ""
11781
11854
  }
11782
11855
  };
11783
11856
  var clmmTestnet = {