@magmaprotocol/magma-clmm-sdk 0.5.18 → 0.5.19

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
@@ -7285,11 +7285,16 @@ var LockModule = class {
7285
7285
  const { fields } = item.data.content;
7286
7286
  const aLockSummary = await this.aLockSummary(fields.id.id);
7287
7287
  const poolIncentiveTokens = await this.getVotingBribeRewardTokens(fields.id.id);
7288
+ const poolFeeTokens = await this.getVotingFeeRewardTokens(fields.id.id);
7288
7289
  const incentiveTokens = [];
7289
7290
  poolIncentiveTokens.forEach((value, key) => {
7290
7291
  incentiveTokens.push(...value);
7291
7292
  });
7292
- const poolIncentiveRewards = await this.getPoolIncentiveRewrads(incentiveTokens, fields.id.id);
7293
+ const feeTokens = [];
7294
+ poolFeeTokens.forEach((value, key) => {
7295
+ feeTokens.push(...value);
7296
+ });
7297
+ const poolIncentiveRewards = await this.getPoolIncentiveRewards(fields.id.id, incentiveTokens);
7293
7298
  const votingRewards = /* @__PURE__ */ new Map();
7294
7299
  poolIncentiveRewards.forEach((value, coin) => {
7295
7300
  value.forEach((amount, pool) => {
@@ -7303,6 +7308,19 @@ var LockModule = class {
7303
7308
  });
7304
7309
  });
7305
7310
  });
7311
+ const poolFeeRewards = await this.getPoolFeeRewards(fields.id.id, feeTokens);
7312
+ poolFeeRewards.forEach((value, coin) => {
7313
+ value.forEach((amount, pool) => {
7314
+ if (!votingRewards.has(pool)) {
7315
+ votingRewards.set(pool, []);
7316
+ }
7317
+ votingRewards.get(pool)?.push({
7318
+ kind: "fee" /* Fee */,
7319
+ token_addr: coin,
7320
+ amount: amount.toString()
7321
+ });
7322
+ });
7323
+ });
7306
7324
  const lockInfo = {
7307
7325
  lock_id: fields.id.id,
7308
7326
  amount: fields.amount,
@@ -7315,7 +7333,7 @@ var LockModule = class {
7315
7333
  amount: aLockSummary.reward_distributor_claimable
7316
7334
  },
7317
7335
  voting_power: aLockSummary.voting_power,
7318
- // pool => incentive => amount
7336
+ // pool => incentive/fee => amount
7319
7337
  voting_rewards: votingRewards
7320
7338
  };
7321
7339
  locksInfo.lockInfo.push(lockInfo);
@@ -7323,7 +7341,6 @@ var LockModule = class {
7323
7341
  return locksInfo;
7324
7342
  }
7325
7343
  async aLockInfo(lockId) {
7326
- const aLockSummary = await this.aLockSummary(lockId);
7327
7344
  const lockObj = await this._sdk.fullClient.getObject({
7328
7345
  id: lockId,
7329
7346
  options: {
@@ -7335,13 +7352,25 @@ var LockModule = class {
7335
7352
  showType: true
7336
7353
  }
7337
7354
  });
7355
+ if (lockObj.error != null || lockObj.data?.content?.dataType !== "moveObject") {
7356
+ throw new ClmmpoolsError(
7357
+ `getPool error code: ${lockObj.error?.code ?? "unknown error"}, please check config and object id`,
7358
+ "InvalidLockObject" /* InvalidLockObject */
7359
+ );
7360
+ }
7338
7361
  const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7362
+ const aLockSummary = await this.aLockSummary(lockId);
7339
7363
  const poolIncentiveTokens = await this.getVotingBribeRewardTokens(lockId);
7364
+ const poolFeeTokens = await this.getVotingFeeRewardTokens(lockId);
7340
7365
  const incentiveTokens = [];
7341
7366
  poolIncentiveTokens.forEach((value, key) => {
7342
7367
  incentiveTokens.push(...value);
7343
7368
  });
7344
- const poolIncentiveRewards = await this.getPoolIncentiveRewrads(incentiveTokens, lockId);
7369
+ const feeTokens = [];
7370
+ poolFeeTokens.forEach((value, key) => {
7371
+ feeTokens.push(...value);
7372
+ });
7373
+ const poolIncentiveRewards = await this.getPoolIncentiveRewards(lockId, incentiveTokens);
7345
7374
  const votingRewards = /* @__PURE__ */ new Map();
7346
7375
  poolIncentiveRewards.forEach((value, coin) => {
7347
7376
  value.forEach((amount, pool) => {
@@ -7355,12 +7384,19 @@ var LockModule = class {
7355
7384
  });
7356
7385
  });
7357
7386
  });
7358
- if (lockObj.error != null || lockObj.data?.content?.dataType !== "moveObject") {
7359
- throw new ClmmpoolsError(
7360
- `getPool error code: ${lockObj.error?.code ?? "unknown error"}, please check config and object id`,
7361
- "InvalidLockObject" /* InvalidLockObject */
7362
- );
7363
- }
7387
+ const poolFeeRewards = await this.getPoolFeeRewards(lockId, feeTokens);
7388
+ poolFeeRewards.forEach((value, coin) => {
7389
+ value.forEach((amount, pool) => {
7390
+ if (!votingRewards.has(pool)) {
7391
+ votingRewards.set(pool, []);
7392
+ }
7393
+ votingRewards.get(pool)?.push({
7394
+ kind: "fee" /* Fee */,
7395
+ token_addr: coin,
7396
+ amount: amount.toString()
7397
+ });
7398
+ });
7399
+ });
7364
7400
  const fields = getObjectFields(lockObj);
7365
7401
  const lockInfo = {
7366
7402
  lock_id: lockId,
@@ -7575,11 +7611,72 @@ var LockModule = class {
7575
7611
  });
7576
7612
  return poolBirbeRewardTokens;
7577
7613
  }
7578
- // tokenId => pool => incentive_tokens
7579
- async getPoolIncentiveRewrads(incentive_tokens, locksId) {
7580
- const poolBirbeRewardTokens = /* @__PURE__ */ new Map();
7614
+ async getPoolFeeRewards(lock_id, tokens) {
7615
+ const poolFeeRewardTokens = /* @__PURE__ */ new Map();
7616
+ if (tokens.length === 0) {
7617
+ return poolFeeRewardTokens;
7618
+ }
7619
+ if (tokens.length % 2 !== 0) {
7620
+ tokens.push(tokens[0]);
7621
+ }
7622
+ for (let i = 0; i + 1 < tokens.length; i += 2) {
7623
+ await this._getPoolFeeRewards(lock_id, tokens[i], tokens[i + 1], poolFeeRewardTokens);
7624
+ }
7625
+ return poolFeeRewardTokens;
7626
+ }
7627
+ // if you have many tokens, call this function multi times
7628
+ async _getPoolFeeRewards(lock_id, token_a, token_b, poolFeeRewardTokens) {
7629
+ const tx = new Transaction9();
7630
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
7631
+ const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7632
+ const typeArguments = [magma_token, token_a, token_b];
7633
+ const args = [tx.object(voter_id), tx.object(lock_id), tx.object(CLOCK_ADDRESS)];
7634
+ const targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_fee_rewards`;
7635
+ tx.moveCall({
7636
+ target: targetFunc,
7637
+ arguments: args,
7638
+ typeArguments
7639
+ });
7640
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
7641
+ throw Error("this config simulationAccount is not set right");
7642
+ }
7643
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
7644
+ transactionBlock: tx,
7645
+ sender: simulationAccount.address
7646
+ });
7647
+ if (simulateRes.error != null) {
7648
+ throw new Error(`getPoolFeeRewards error code: ${simulateRes.error ?? "unknown error"}`);
7649
+ }
7650
+ simulateRes.events?.forEach((item) => {
7651
+ if (extractStructTagFromType(item.type).name === `ClaimableVotingFee`) {
7652
+ item.parsedJson.data.contents.forEach((rewardTokens) => {
7653
+ if (!poolFeeRewardTokens.has(rewardTokens.key.name)) {
7654
+ poolFeeRewardTokens.set(rewardTokens.key.name, /* @__PURE__ */ new Map());
7655
+ }
7656
+ rewardTokens.value.contents.forEach((token) => {
7657
+ poolFeeRewardTokens.get(rewardTokens.key.name)?.set(token.key, token.value);
7658
+ });
7659
+ });
7660
+ }
7661
+ });
7662
+ return poolFeeRewardTokens;
7663
+ }
7664
+ async getPoolIncentiveRewards(lock_id, incentive_tokens) {
7665
+ const poolBribeRewardTokens = /* @__PURE__ */ new Map();
7581
7666
  if (incentive_tokens.length === 0) {
7582
- return poolBirbeRewardTokens;
7667
+ return poolBribeRewardTokens;
7668
+ }
7669
+ let i = 0;
7670
+ for (; i + 3 < incentive_tokens.length; i += 3) {
7671
+ await this._getPoolIncentiveRewards(lock_id, incentive_tokens.slice(i, i + 3), poolBribeRewardTokens);
7672
+ }
7673
+ await this._getPoolIncentiveRewards(lock_id, incentive_tokens.slice(i), poolBribeRewardTokens);
7674
+ return poolBribeRewardTokens;
7675
+ }
7676
+ // tokenId => pool => incentive_tokens
7677
+ async _getPoolIncentiveRewards(locksId, incentive_tokens, poolBribeRewardTokens) {
7678
+ if (incentive_tokens.length > 3) {
7679
+ throw Error("Too many tokens");
7583
7680
  }
7584
7681
  const tx = new Transaction9();
7585
7682
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
@@ -7603,21 +7700,21 @@ var LockModule = class {
7603
7700
  sender: simulationAccount.address
7604
7701
  });
7605
7702
  if (simulateRes.error != null) {
7606
- throw new Error(`all_lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
7703
+ throw new Error(`getPoolIncentiveRewards error code: ${simulateRes.error ?? "unknown error"}`);
7607
7704
  }
7608
7705
  simulateRes.events?.forEach((item) => {
7609
7706
  if (extractStructTagFromType(item.type).name === `ClaimableVotingBribes`) {
7610
7707
  item.parsedJson.data.contents.forEach((rewardTokens) => {
7611
- if (!poolBirbeRewardTokens.has(rewardTokens.key.name)) {
7612
- poolBirbeRewardTokens.set(rewardTokens.key.name, /* @__PURE__ */ new Map());
7708
+ if (!poolBribeRewardTokens.has(rewardTokens.key.name)) {
7709
+ poolBribeRewardTokens.set(rewardTokens.key.name, /* @__PURE__ */ new Map());
7613
7710
  }
7614
7711
  rewardTokens.value.contents.forEach((token) => {
7615
- poolBirbeRewardTokens.get(rewardTokens.key.name)?.set(token.key, token.value);
7712
+ poolBribeRewardTokens.get(rewardTokens.key.name)?.set(token.key, token.value);
7616
7713
  });
7617
7714
  });
7618
7715
  }
7619
7716
  });
7620
- return poolBirbeRewardTokens;
7717
+ return poolBribeRewardTokens;
7621
7718
  }
7622
7719
  async getPoolBribeRewardTokens(pool_id) {
7623
7720
  const tx = new Transaction9();