@magmaprotocol/magma-clmm-sdk 0.5.33 → 0.5.34

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
@@ -7389,6 +7389,57 @@ var LockModule = class {
7389
7389
  }
7390
7390
  return locksInfo;
7391
7391
  }
7392
+ async locksOfUserV2(user) {
7393
+ const locksInfo = { owner: user, lockInfo: [] };
7394
+ const { distribution } = this._sdk.sdkOptions;
7395
+ const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7396
+ const ownerRes = await this._sdk.fullClient.getOwnedObjectsByPage(user, {
7397
+ options: { showType: true, showContent: true, showDisplay: true, showOwner: true },
7398
+ filter: {
7399
+ MatchAll: [{ Package: distribution.package_id }, { StructType: `${distribution.package_id}::voting_escrow::Lock` }]
7400
+ }
7401
+ });
7402
+ const ids = ownerRes.data.map((item) => item.data.content.id.id);
7403
+ const lockSummary = await this.getAllLockSummary(ids);
7404
+ const lockIncentiveTokens = await this.getAllBribeRewardTokensOfLock(ids);
7405
+ const lockFeeTokens = await this.getAllVotingFeeRewardTokens(ids);
7406
+ const poolIncentiveRewards = await this.getAllIncentiveRewards(lockIncentiveTokens);
7407
+ const poolFeeRewards = await this.getAllFeeRewards(lockFeeTokens);
7408
+ for (const item of ownerRes.data) {
7409
+ const { fields } = item.data.content;
7410
+ const lock_id = fields.id.id;
7411
+ const votingRewards = /* @__PURE__ */ new Map();
7412
+ poolIncentiveRewards.get(lock_id)?.forEach((value, pool) => {
7413
+ if (!votingRewards.has(pool)) {
7414
+ votingRewards.set(pool, []);
7415
+ }
7416
+ votingRewards.get(pool)?.push(...value);
7417
+ });
7418
+ poolFeeRewards.get(lock_id)?.forEach((value, pool) => {
7419
+ if (!votingRewards.has(pool)) {
7420
+ votingRewards.set(pool, []);
7421
+ }
7422
+ votingRewards.get(pool)?.push(...value);
7423
+ });
7424
+ const lockInfo = {
7425
+ lock_id,
7426
+ amount: fields.amount,
7427
+ start: fields.start,
7428
+ end: fields.end,
7429
+ permanent: fields.permanent,
7430
+ rebase_amount: {
7431
+ kind: "rebaseCoin" /* RebaseCoin */,
7432
+ token_addr: magma_token,
7433
+ amount: lockSummary.get(lock_id)?.reward_distributor_claimable || "0"
7434
+ },
7435
+ voting_power: lockSummary.get(lock_id)?.voting_power || "0",
7436
+ // pool => incentive/fee => amount
7437
+ voting_rewards: votingRewards
7438
+ };
7439
+ locksInfo.lockInfo.push(lockInfo);
7440
+ }
7441
+ return locksInfo;
7442
+ }
7392
7443
  async locksOfUser(user) {
7393
7444
  const locksInfo = { owner: user, lockInfo: [] };
7394
7445
  const { distribution } = this._sdk.sdkOptions;
@@ -7581,6 +7632,57 @@ var LockModule = class {
7581
7632
  });
7582
7633
  return res;
7583
7634
  }
7635
+ // Return: lock_id => ALockSummary
7636
+ async getAllLockSummary(lock_ids) {
7637
+ let tx = new Transaction9();
7638
+ for (const lock_id of lock_ids) {
7639
+ tx = await this._aLockSummary(lock_id, tx);
7640
+ }
7641
+ return this._parseLockSummary(tx);
7642
+ }
7643
+ async _aLockSummary(lock_id, tx) {
7644
+ tx = tx || new Transaction9();
7645
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
7646
+ const { voting_escrow_id, magma_token, voter_id, reward_distributor_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7647
+ const typeArguments = [magma_token];
7648
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
7649
+ throw Error("this config simulationAccount is not set right");
7650
+ }
7651
+ const args = [
7652
+ tx.object(voter_id),
7653
+ tx.object(voting_escrow_id),
7654
+ tx.object(reward_distributor_id),
7655
+ tx.object(lock_id),
7656
+ tx.object(CLOCK_ADDRESS)
7657
+ ];
7658
+ tx.moveCall({
7659
+ target: `${integrate.published_at}::${VotingEscrow}::lock_summary`,
7660
+ arguments: args,
7661
+ typeArguments
7662
+ });
7663
+ return tx;
7664
+ }
7665
+ async _parseLockSummary(tx) {
7666
+ const { simulationAccount } = this.sdk.sdkOptions;
7667
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
7668
+ transactionBlock: tx,
7669
+ sender: simulationAccount.address
7670
+ });
7671
+ if (simulateRes.error != null) {
7672
+ throw new Error(`lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
7673
+ }
7674
+ const res = /* @__PURE__ */ new Map();
7675
+ simulateRes.events?.forEach((item) => {
7676
+ if (extractStructTagFromType(item.type).name === `LockSummary`) {
7677
+ res.set(item.parsedJson.lock_id, {
7678
+ fee_incentive_total: item.parsedJson.fee_incentive_total,
7679
+ reward_distributor_claimable: item.parsedJson.reward_distributor_claimable,
7680
+ voting_power: item.parsedJson.voting_power
7681
+ });
7682
+ }
7683
+ });
7684
+ return res;
7685
+ }
7584
7686
  async allLockSummary() {
7585
7687
  const tx = new Transaction9();
7586
7688
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
@@ -7661,6 +7763,54 @@ var LockModule = class {
7661
7763
  });
7662
7764
  return poolWeights;
7663
7765
  }
7766
+ async getAllVotingFeeRewardTokens(lock_ids) {
7767
+ let tx = new Transaction9();
7768
+ for (const lock_id of lock_ids) {
7769
+ tx = await this._getVotingFeeRewardTokens(lock_id, tx);
7770
+ }
7771
+ return this._parseVotingFeeRewardTokens(tx);
7772
+ }
7773
+ async _getVotingFeeRewardTokens(lock_id, tx) {
7774
+ tx = tx || new Transaction9();
7775
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
7776
+ const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7777
+ const typeArguments = [magma_token];
7778
+ const args = [tx.object(voter_id), tx.object(lock_id)];
7779
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
7780
+ throw Error("this config simulationAccount is not set right");
7781
+ }
7782
+ tx.moveCall({
7783
+ target: `${integrate.published_at}::${Voter}::get_voting_fee_reward_tokens`,
7784
+ arguments: args,
7785
+ typeArguments
7786
+ });
7787
+ return tx;
7788
+ }
7789
+ async _parseVotingFeeRewardTokens(tx) {
7790
+ const { simulationAccount } = this.sdk.sdkOptions;
7791
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
7792
+ transactionBlock: tx,
7793
+ sender: simulationAccount.address
7794
+ });
7795
+ if (simulateRes.error != null) {
7796
+ throw new Error(`all_lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
7797
+ }
7798
+ const poolFeeRewardTokens = /* @__PURE__ */ new Map();
7799
+ simulateRes.events?.forEach((event) => {
7800
+ if (extractStructTagFromType(event.type).name === `EventFeeRewardTokens`) {
7801
+ const { lock_id } = event.parsedJson;
7802
+ if (!poolFeeRewardTokens.has(lock_id)) {
7803
+ poolFeeRewardTokens.set(lock_id, []);
7804
+ }
7805
+ event.parsedJson.list.contents.forEach((poolTokens) => {
7806
+ poolTokens.value.forEach((token) => {
7807
+ poolFeeRewardTokens.get(lock_id)?.push(token.name);
7808
+ });
7809
+ });
7810
+ }
7811
+ });
7812
+ return poolFeeRewardTokens;
7813
+ }
7664
7814
  async getVotingFeeRewardTokens(lock_id) {
7665
7815
  const tx = new Transaction9();
7666
7816
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
@@ -7684,7 +7834,7 @@ var LockModule = class {
7684
7834
  }
7685
7835
  const poolRewardTokens = /* @__PURE__ */ new Map();
7686
7836
  simulateRes.events?.forEach((item) => {
7687
- if (extractStructTagFromType(item.type).name === `EventRewardTokens`) {
7837
+ if (extractStructTagFromType(item.type).name === `EventFeeRewardTokens`) {
7688
7838
  item.parsedJson.list.contents.forEach((poolTokens) => {
7689
7839
  if (!poolRewardTokens.has(poolTokens.key)) {
7690
7840
  poolRewardTokens.set(poolTokens.key, []);
@@ -7697,20 +7847,70 @@ var LockModule = class {
7697
7847
  });
7698
7848
  return poolRewardTokens;
7699
7849
  }
7700
- async getVotingBribeRewardTokens(lock_id) {
7701
- const tx = new Transaction9();
7850
+ // tokens
7851
+ async getAllBribeRewardTokensOfLock(lock_ids) {
7852
+ let tx = new Transaction9();
7853
+ for (const lock_id of lock_ids) {
7854
+ tx = await this._getVotingBribeRewardTokens(lock_id, tx);
7855
+ }
7856
+ return this._parseVotingBribeRewardTokens(tx);
7857
+ }
7858
+ async _getVotingBribeRewardTokens(lock_id, tx) {
7859
+ tx = tx || new Transaction9();
7702
7860
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
7703
7861
  const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7704
7862
  const typeArguments = [magma_token];
7863
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
7864
+ throw Error("this config simulationAccount is not set right");
7865
+ }
7705
7866
  const args = [tx.object(voter_id), tx.object(lock_id)];
7706
7867
  tx.moveCall({
7707
7868
  target: `${integrate.published_at}::${Voter}::get_voting_bribe_reward_tokens`,
7708
7869
  arguments: args,
7709
7870
  typeArguments
7710
7871
  });
7872
+ return tx;
7873
+ }
7874
+ async _parseVotingBribeRewardTokens(tx) {
7875
+ const { simulationAccount } = this.sdk.sdkOptions;
7876
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
7877
+ transactionBlock: tx,
7878
+ sender: simulationAccount.address
7879
+ });
7880
+ if (simulateRes.error != null) {
7881
+ throw new Error(`all_lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
7882
+ }
7883
+ const poolBirbeRewardTokens = /* @__PURE__ */ new Map();
7884
+ simulateRes.events?.forEach((event) => {
7885
+ if (extractStructTagFromType(event.type).name === `EventBribeRewardTokens`) {
7886
+ const { lock_id } = event.parsedJson;
7887
+ if (!poolBirbeRewardTokens.has(lock_id)) {
7888
+ poolBirbeRewardTokens.set(lock_id, []);
7889
+ }
7890
+ event.parsedJson.list.contents.forEach((poolTokens) => {
7891
+ poolTokens.value.forEach((token) => {
7892
+ poolBirbeRewardTokens.get(lock_id)?.push(token.name);
7893
+ });
7894
+ });
7895
+ }
7896
+ });
7897
+ return poolBirbeRewardTokens;
7898
+ }
7899
+ // Return PoolId => tokens
7900
+ async getVotingBribeRewardTokens(lock_id) {
7901
+ const tx = new Transaction9();
7902
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
7903
+ const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7904
+ const typeArguments = [magma_token];
7711
7905
  if (!checkInvalidSuiAddress(simulationAccount.address)) {
7712
7906
  throw Error("this config simulationAccount is not set right");
7713
7907
  }
7908
+ const args = [tx.object(voter_id), tx.object(lock_id)];
7909
+ tx.moveCall({
7910
+ target: `${integrate.published_at}::${Voter}::get_voting_bribe_reward_tokens`,
7911
+ arguments: args,
7912
+ typeArguments
7913
+ });
7714
7914
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
7715
7915
  transactionBlock: tx,
7716
7916
  sender: simulationAccount.address
@@ -7720,7 +7920,7 @@ var LockModule = class {
7720
7920
  }
7721
7921
  const poolBirbeRewardTokens = /* @__PURE__ */ new Map();
7722
7922
  simulateRes.events?.forEach((item) => {
7723
- if (extractStructTagFromType(item.type).name === `EventRewardTokens`) {
7923
+ if (extractStructTagFromType(item.type).name === `EventBribeRewardTokens`) {
7724
7924
  item.parsedJson.list.contents.forEach((poolTokens) => {
7725
7925
  if (!poolBirbeRewardTokens.has(poolTokens.key)) {
7726
7926
  poolBirbeRewardTokens.set(poolTokens.key, []);
@@ -7733,6 +7933,68 @@ var LockModule = class {
7733
7933
  });
7734
7934
  return poolBirbeRewardTokens;
7735
7935
  }
7936
+ async getAllFeeRewards(fee_tokens) {
7937
+ let tx = new Transaction9();
7938
+ fee_tokens.forEach((tokens, lock_id) => {
7939
+ tx = this._getFeeRewards(lock_id, tokens, tx);
7940
+ });
7941
+ return await this._parseFeeRewards(tx);
7942
+ }
7943
+ _getFeeRewards(lock_id, fee_tokens, tx) {
7944
+ if (fee_tokens.length % 2 !== 0) {
7945
+ fee_tokens.push(fee_tokens[0]);
7946
+ }
7947
+ for (let i = 0; i + 1 < fee_tokens.length; i += 2) {
7948
+ tx = this._getFeeRewardsInner(lock_id, fee_tokens[i], fee_tokens[i + 1], tx);
7949
+ }
7950
+ return tx;
7951
+ }
7952
+ _getFeeRewardsInner(lock_id, token_a, token_b, tx) {
7953
+ tx = tx || new Transaction9();
7954
+ const { integrate } = this.sdk.sdkOptions;
7955
+ const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7956
+ const typeArguments = [magma_token, token_a, token_b];
7957
+ const args = [tx.object(voter_id), tx.object(lock_id), tx.object(CLOCK_ADDRESS)];
7958
+ const targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_fee_rewards`;
7959
+ tx.moveCall({
7960
+ target: targetFunc,
7961
+ arguments: args,
7962
+ typeArguments
7963
+ });
7964
+ return tx;
7965
+ }
7966
+ async _parseFeeRewards(tx) {
7967
+ const { simulationAccount } = this.sdk.sdkOptions;
7968
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
7969
+ transactionBlock: tx,
7970
+ sender: simulationAccount.address
7971
+ });
7972
+ if (simulateRes.error != null) {
7973
+ throw new Error(`getPoolIncentiveRewards error code: ${simulateRes.error ?? "unknown error"}`);
7974
+ }
7975
+ const poolFeeRewardTokens = /* @__PURE__ */ new Map();
7976
+ simulateRes.events?.forEach((event) => {
7977
+ if (extractStructTagFromType(event.type).name === `ClaimableVotingFee`) {
7978
+ const { lock_id } = event.parsedJson;
7979
+ if (!poolFeeRewardTokens.has(lock_id)) {
7980
+ poolFeeRewardTokens.set(lock_id, /* @__PURE__ */ new Map());
7981
+ }
7982
+ event.parsedJson.list.contents.forEach((rewardTokens) => {
7983
+ rewardTokens.value.contents.forEach((token) => {
7984
+ if (!poolFeeRewardTokens.get(lock_id)?.has(rewardTokens.key.name)) {
7985
+ poolFeeRewardTokens.get(lock_id)?.set(rewardTokens.key.name, []);
7986
+ }
7987
+ poolFeeRewardTokens.get(lock_id)?.get(rewardTokens.key.name)?.push({
7988
+ kind: "incentiveCoin" /* Incentive */,
7989
+ token_addr: token.key,
7990
+ amount: token.value
7991
+ });
7992
+ });
7993
+ });
7994
+ }
7995
+ });
7996
+ return poolFeeRewardTokens;
7997
+ }
7736
7998
  async getPoolFeeRewards(lock_id, tokens) {
7737
7999
  const poolFeeRewardTokens = /* @__PURE__ */ new Map();
7738
8000
  if (tokens.length === 0) {
@@ -7783,6 +8045,78 @@ var LockModule = class {
7783
8045
  });
7784
8046
  return poolFeeRewardTokens;
7785
8047
  }
8048
+ // params: lock_id => incentive_tokens
8049
+ // lock_id => Pool => rewardTokens
8050
+ async getAllIncentiveRewards(lock_incentive_tokens) {
8051
+ let tx = new Transaction9();
8052
+ lock_incentive_tokens.forEach((tokens, lock_id) => {
8053
+ tx = this._getIncentiveRewards(lock_id, tokens, tx);
8054
+ });
8055
+ return await this._parseIncentiveRewards(tx);
8056
+ }
8057
+ _getIncentiveRewards(lock_id, incentive_tokens, tx) {
8058
+ let i = 0;
8059
+ for (; i + 3 < incentive_tokens.length; i += 3) {
8060
+ this._getIncentiveRewardsInner(lock_id, incentive_tokens.slice(i, i + 3), tx);
8061
+ }
8062
+ return this._getIncentiveRewardsInner(lock_id, incentive_tokens.slice(i), tx);
8063
+ }
8064
+ _getIncentiveRewardsInner(locksId, incentive_tokens, tx) {
8065
+ tx = tx || new Transaction9();
8066
+ if (incentive_tokens.length > 3) {
8067
+ throw Error("Too many tokens");
8068
+ }
8069
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
8070
+ const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
8071
+ const typeArguments = [magma_token, ...incentive_tokens];
8072
+ const args = [tx.object(voter_id), tx.object(locksId), tx.object(CLOCK_ADDRESS)];
8073
+ let targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_bribes_${incentive_tokens.length}`;
8074
+ if (incentive_tokens.length === 1) {
8075
+ targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_bribes`;
8076
+ }
8077
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
8078
+ throw Error("this config simulationAccount is not set right");
8079
+ }
8080
+ tx.moveCall({
8081
+ target: targetFunc,
8082
+ arguments: args,
8083
+ typeArguments
8084
+ });
8085
+ return tx;
8086
+ }
8087
+ async _parseIncentiveRewards(tx) {
8088
+ const { simulationAccount } = this.sdk.sdkOptions;
8089
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
8090
+ transactionBlock: tx,
8091
+ sender: simulationAccount.address
8092
+ });
8093
+ if (simulateRes.error != null) {
8094
+ throw new Error(`getPoolIncentiveRewards error code: ${simulateRes.error ?? "unknown error"}`);
8095
+ }
8096
+ const poolBribeRewardTokens = /* @__PURE__ */ new Map();
8097
+ simulateRes.events?.forEach((event) => {
8098
+ if (extractStructTagFromType(event.type).name === `ClaimableVotingBribes`) {
8099
+ const { lock_id } = event.parsedJson;
8100
+ if (!poolBribeRewardTokens.has(lock_id)) {
8101
+ poolBribeRewardTokens.set(lock_id, /* @__PURE__ */ new Map());
8102
+ }
8103
+ event.parsedJson.list.contents.forEach((rewardTokens) => {
8104
+ rewardTokens.value.contents.forEach((token) => {
8105
+ if (!poolBribeRewardTokens.get(lock_id)?.has(rewardTokens.key.name)) {
8106
+ poolBribeRewardTokens.get(lock_id)?.set(rewardTokens.key.name, []);
8107
+ }
8108
+ poolBribeRewardTokens.get(lock_id)?.get(rewardTokens.key.name)?.push({
8109
+ kind: "incentiveCoin" /* Incentive */,
8110
+ token_addr: token.key,
8111
+ amount: token.value
8112
+ });
8113
+ });
8114
+ });
8115
+ }
8116
+ });
8117
+ return poolBribeRewardTokens;
8118
+ }
8119
+ // coin => pool => amount
7786
8120
  async getPoolIncentiveRewards(lock_id, incentive_tokens) {
7787
8121
  const poolBribeRewardTokens = /* @__PURE__ */ new Map();
7788
8122
  if (incentive_tokens.length === 0) {
@@ -7809,14 +8143,14 @@ var LockModule = class {
7809
8143
  if (incentive_tokens.length === 1) {
7810
8144
  targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_bribes`;
7811
8145
  }
8146
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
8147
+ throw Error("this config simulationAccount is not set right");
8148
+ }
7812
8149
  tx.moveCall({
7813
8150
  target: targetFunc,
7814
8151
  arguments: args,
7815
8152
  typeArguments
7816
8153
  });
7817
- if (!checkInvalidSuiAddress(simulationAccount.address)) {
7818
- throw Error("this config simulationAccount is not set right");
7819
- }
7820
8154
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
7821
8155
  transactionBlock: tx,
7822
8156
  sender: simulationAccount.address
@@ -9465,6 +9799,21 @@ var GaugeModule = class {
9465
9799
  });
9466
9800
  return tx;
9467
9801
  }
9802
+ async getAllRewardByPositions(paramsList) {
9803
+ const tx = new Transaction11();
9804
+ const { integrate } = this.sdk.sdkOptions;
9805
+ const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
9806
+ paramsList.forEach((params) => {
9807
+ const typeArguments = [params.coinTypeA, params.coinTypeB, magma_token];
9808
+ const args = [tx.object(params.gaugeId), tx.object(params.poolId), tx.object(params.positionId), tx.object(CLOCK_ADDRESS)];
9809
+ tx.moveCall({
9810
+ target: `${integrate.published_at}::${Gauge}::get_reward_by_position`,
9811
+ arguments: args,
9812
+ typeArguments
9813
+ });
9814
+ });
9815
+ return tx;
9816
+ }
9468
9817
  async getEpochRewardByPool(pool, incentive_tokens) {
9469
9818
  const tx = new Transaction11();
9470
9819
  const { integrate, simulationAccount } = this.sdk.sdkOptions;