@magmaprotocol/magma-clmm-sdk 0.5.32 → 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.d.ts CHANGED
@@ -3026,6 +3026,8 @@ declare class SwapModule implements IModule {
3026
3026
  }>;
3027
3027
  }
3028
3028
 
3029
+ type LockID = string;
3030
+ type PoolID = string;
3029
3031
  type LocksInfo = {
3030
3032
  owner: string;
3031
3033
  lockInfo: LockInfo[];
@@ -3100,15 +3102,33 @@ declare class LockModule implements IModule {
3100
3102
  claimVotingBribe(locks: string[], incentive_tokens: string[]): Promise<Transaction>;
3101
3103
  claimVotingFeeAndBribeForPool(lockId: string, poolId: string, feeTokens: string[], incentiveTokens: string[]): Promise<Transaction>;
3102
3104
  fastLocksOfUser(user: string): Promise<LocksInfo>;
3105
+ locksOfUserV2(user: string): Promise<LocksInfo>;
3103
3106
  locksOfUser(user: string): Promise<LocksInfo>;
3104
3107
  aLockInfo(lockId: string): Promise<LockInfo>;
3105
3108
  aLockSummary(lock_id: string): Promise<ALockSummary>;
3109
+ getAllLockSummary(lock_ids: string[]): Promise<Map<LockID, ALockSummary>>;
3110
+ _aLockSummary(lock_id: string, tx?: Transaction): Promise<Transaction>;
3111
+ _parseLockSummary(tx: Transaction): Promise<Map<LockID, ALockSummary>>;
3106
3112
  allLockSummary(): Promise<AllLockSummary>;
3107
3113
  poolWeights(pools: string[]): Promise<PoolWeight[]>;
3114
+ getAllVotingFeeRewardTokens(lock_ids: string[]): Promise<Map<LockID, string[]>>;
3115
+ _getVotingFeeRewardTokens(lock_id: string, tx?: Transaction): Promise<Transaction>;
3116
+ _parseVotingFeeRewardTokens(tx: Transaction): Promise<Map<LockID, string[]>>;
3108
3117
  getVotingFeeRewardTokens(lock_id: string): Promise<Map<string, string[]>>;
3118
+ getAllBribeRewardTokensOfLock(lock_ids: string[]): Promise<Map<LockID, string[]>>;
3119
+ _getVotingBribeRewardTokens(lock_id: string, tx?: Transaction): Promise<Transaction>;
3120
+ _parseVotingBribeRewardTokens(tx: Transaction): Promise<Map<LockID, string[]>>;
3109
3121
  getVotingBribeRewardTokens(lock_id: string): Promise<Map<string, string[]>>;
3110
- getPoolFeeRewards(lock_id: string, tokens: string[]): Promise<Map<string, Map<string, string>>>;
3122
+ getAllFeeRewards(fee_tokens: Map<LockID, string[]>): Promise<Map<LockID, Map<PoolID, Coin[]>>>;
3123
+ _getFeeRewards(lock_id: string, fee_tokens: string[], tx: Transaction): Transaction;
3124
+ _getFeeRewardsInner(lock_id: LockID, token_a: string, token_b: string, tx?: Transaction): Transaction;
3125
+ _parseFeeRewards(tx: Transaction): Promise<Map<LockID, Map<PoolID, Coin[]>>>;
3126
+ getPoolFeeRewards(lock_id: LockID, tokens: string[]): Promise<Map<string, Map<string, string>>>;
3111
3127
  _getPoolFeeRewards(lock_id: string, token_a: string, token_b: string, poolFeeRewardTokens: Map<string, Map<string, string>>): Promise<Map<string, Map<string, string>>>;
3128
+ getAllIncentiveRewards(lock_incentive_tokens: Map<LockID, string[]>): Promise<Map<LockID, Map<PoolID, Coin[]>>>;
3129
+ _getIncentiveRewards(lock_id: string, incentive_tokens: string[], tx?: Transaction): Transaction;
3130
+ _getIncentiveRewardsInner(locksId: string, incentive_tokens: string[], tx?: Transaction): Transaction;
3131
+ _parseIncentiveRewards(tx: Transaction): Promise<Map<LockID, Map<PoolID, Coin[]>>>;
3112
3132
  getPoolIncentiveRewards(lock_id: string, incentive_tokens: string[]): Promise<Map<string, Map<string, string>>>;
3113
3133
  _getPoolIncentiveRewards(locksId: string, incentive_tokens: string[], poolBribeRewardTokens: Map<string, Map<string, string>>): Promise<Map<string, Map<string, string>>>;
3114
3134
  getPoolBribeRewardTokens(pool_id: string): Promise<Map<string, string[]>>;
@@ -3352,6 +3372,7 @@ declare class GaugeModule implements IModule {
3352
3372
  getPoolCoins(pools: string[]): Promise<Map<string, string[]>>;
3353
3373
  getEmissions(): Promise<EpochEmission>;
3354
3374
  getRewardByPosition(params: GetRewardByPosition): Promise<Transaction>;
3375
+ getAllRewardByPositions(paramsList: GetRewardByPosition[]): Promise<Transaction>;
3355
3376
  getEpochRewardByPool(pool: string, incentive_tokens: string[]): Promise<Map<string, string>>;
3356
3377
  }
3357
3378
 
package/dist/index.js CHANGED
@@ -3178,7 +3178,6 @@ var _TransactionUtil = class {
3178
3178
  // public fun increase_unlock_time<T>(self: &mut VotingEscrow<T>, lock: &mut Lock, lock_duration: u64, clock: &Clock, ctx: &mut TxContext) {
3179
3179
  static buildIncreaseUnlockTimeTransaction(sdk, params) {
3180
3180
  const tx = new import_transactions.Transaction();
3181
- tx.setGasBudget(1e8);
3182
3181
  tx.setSender(sdk.senderAddress);
3183
3182
  const oneDay = 24 * 60 * 60;
3184
3183
  const newLockDuration = Math.ceil((params.newLockEndAt - Date.now() / 1e3) / oneDay);
@@ -3339,7 +3338,6 @@ var _TransactionUtil = class {
3339
3338
  static buildClaimAndLockRebases(sdk, params) {
3340
3339
  const tx = new import_transactions.Transaction();
3341
3340
  tx.setSender(sdk.senderAddress);
3342
- tx.setGasBudget(5e8);
3343
3341
  const { integrate } = sdk.sdkOptions;
3344
3342
  const { voting_escrow_id, magma_token, reward_distributor_id } = getPackagerConfigs(sdk.sdkOptions.magma_config);
3345
3343
  const typeArguments = [magma_token];
@@ -3375,7 +3373,6 @@ var _TransactionUtil = class {
3375
3373
  }
3376
3374
  static buildClaimVotingBribe(sdk, locks, incentive_tokens) {
3377
3375
  const tx = new import_transactions.Transaction();
3378
- tx.setGasBudget(5e8);
3379
3376
  tx.setSender(sdk.senderAddress);
3380
3377
  const { integrate, distribution } = sdk.sdkOptions;
3381
3378
  const { voting_escrow_id, magma_token, voter_id } = getPackagerConfigs(sdk.sdkOptions.magma_config);
@@ -7597,6 +7594,57 @@ var LockModule = class {
7597
7594
  }
7598
7595
  return locksInfo;
7599
7596
  }
7597
+ async locksOfUserV2(user) {
7598
+ const locksInfo = { owner: user, lockInfo: [] };
7599
+ const { distribution } = this._sdk.sdkOptions;
7600
+ const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7601
+ const ownerRes = await this._sdk.fullClient.getOwnedObjectsByPage(user, {
7602
+ options: { showType: true, showContent: true, showDisplay: true, showOwner: true },
7603
+ filter: {
7604
+ MatchAll: [{ Package: distribution.package_id }, { StructType: `${distribution.package_id}::voting_escrow::Lock` }]
7605
+ }
7606
+ });
7607
+ const ids = ownerRes.data.map((item) => item.data.content.id.id);
7608
+ const lockSummary = await this.getAllLockSummary(ids);
7609
+ const lockIncentiveTokens = await this.getAllBribeRewardTokensOfLock(ids);
7610
+ const lockFeeTokens = await this.getAllVotingFeeRewardTokens(ids);
7611
+ const poolIncentiveRewards = await this.getAllIncentiveRewards(lockIncentiveTokens);
7612
+ const poolFeeRewards = await this.getAllFeeRewards(lockFeeTokens);
7613
+ for (const item of ownerRes.data) {
7614
+ const { fields } = item.data.content;
7615
+ const lock_id = fields.id.id;
7616
+ const votingRewards = /* @__PURE__ */ new Map();
7617
+ poolIncentiveRewards.get(lock_id)?.forEach((value, pool) => {
7618
+ if (!votingRewards.has(pool)) {
7619
+ votingRewards.set(pool, []);
7620
+ }
7621
+ votingRewards.get(pool)?.push(...value);
7622
+ });
7623
+ poolFeeRewards.get(lock_id)?.forEach((value, pool) => {
7624
+ if (!votingRewards.has(pool)) {
7625
+ votingRewards.set(pool, []);
7626
+ }
7627
+ votingRewards.get(pool)?.push(...value);
7628
+ });
7629
+ const lockInfo = {
7630
+ lock_id,
7631
+ amount: fields.amount,
7632
+ start: fields.start,
7633
+ end: fields.end,
7634
+ permanent: fields.permanent,
7635
+ rebase_amount: {
7636
+ kind: "rebaseCoin" /* RebaseCoin */,
7637
+ token_addr: magma_token,
7638
+ amount: lockSummary.get(lock_id)?.reward_distributor_claimable || "0"
7639
+ },
7640
+ voting_power: lockSummary.get(lock_id)?.voting_power || "0",
7641
+ // pool => incentive/fee => amount
7642
+ voting_rewards: votingRewards
7643
+ };
7644
+ locksInfo.lockInfo.push(lockInfo);
7645
+ }
7646
+ return locksInfo;
7647
+ }
7600
7648
  async locksOfUser(user) {
7601
7649
  const locksInfo = { owner: user, lockInfo: [] };
7602
7650
  const { distribution } = this._sdk.sdkOptions;
@@ -7789,6 +7837,57 @@ var LockModule = class {
7789
7837
  });
7790
7838
  return res;
7791
7839
  }
7840
+ // Return: lock_id => ALockSummary
7841
+ async getAllLockSummary(lock_ids) {
7842
+ let tx = new import_transactions9.Transaction();
7843
+ for (const lock_id of lock_ids) {
7844
+ tx = await this._aLockSummary(lock_id, tx);
7845
+ }
7846
+ return this._parseLockSummary(tx);
7847
+ }
7848
+ async _aLockSummary(lock_id, tx) {
7849
+ tx = tx || new import_transactions9.Transaction();
7850
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
7851
+ const { voting_escrow_id, magma_token, voter_id, reward_distributor_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7852
+ const typeArguments = [magma_token];
7853
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
7854
+ throw Error("this config simulationAccount is not set right");
7855
+ }
7856
+ const args = [
7857
+ tx.object(voter_id),
7858
+ tx.object(voting_escrow_id),
7859
+ tx.object(reward_distributor_id),
7860
+ tx.object(lock_id),
7861
+ tx.object(CLOCK_ADDRESS)
7862
+ ];
7863
+ tx.moveCall({
7864
+ target: `${integrate.published_at}::${VotingEscrow}::lock_summary`,
7865
+ arguments: args,
7866
+ typeArguments
7867
+ });
7868
+ return tx;
7869
+ }
7870
+ async _parseLockSummary(tx) {
7871
+ const { simulationAccount } = this.sdk.sdkOptions;
7872
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
7873
+ transactionBlock: tx,
7874
+ sender: simulationAccount.address
7875
+ });
7876
+ if (simulateRes.error != null) {
7877
+ throw new Error(`lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
7878
+ }
7879
+ const res = /* @__PURE__ */ new Map();
7880
+ simulateRes.events?.forEach((item) => {
7881
+ if (extractStructTagFromType(item.type).name === `LockSummary`) {
7882
+ res.set(item.parsedJson.lock_id, {
7883
+ fee_incentive_total: item.parsedJson.fee_incentive_total,
7884
+ reward_distributor_claimable: item.parsedJson.reward_distributor_claimable,
7885
+ voting_power: item.parsedJson.voting_power
7886
+ });
7887
+ }
7888
+ });
7889
+ return res;
7890
+ }
7792
7891
  async allLockSummary() {
7793
7892
  const tx = new import_transactions9.Transaction();
7794
7893
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
@@ -7869,6 +7968,54 @@ var LockModule = class {
7869
7968
  });
7870
7969
  return poolWeights;
7871
7970
  }
7971
+ async getAllVotingFeeRewardTokens(lock_ids) {
7972
+ let tx = new import_transactions9.Transaction();
7973
+ for (const lock_id of lock_ids) {
7974
+ tx = await this._getVotingFeeRewardTokens(lock_id, tx);
7975
+ }
7976
+ return this._parseVotingFeeRewardTokens(tx);
7977
+ }
7978
+ async _getVotingFeeRewardTokens(lock_id, tx) {
7979
+ tx = tx || new import_transactions9.Transaction();
7980
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
7981
+ const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7982
+ const typeArguments = [magma_token];
7983
+ const args = [tx.object(voter_id), tx.object(lock_id)];
7984
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
7985
+ throw Error("this config simulationAccount is not set right");
7986
+ }
7987
+ tx.moveCall({
7988
+ target: `${integrate.published_at}::${Voter}::get_voting_fee_reward_tokens`,
7989
+ arguments: args,
7990
+ typeArguments
7991
+ });
7992
+ return tx;
7993
+ }
7994
+ async _parseVotingFeeRewardTokens(tx) {
7995
+ const { simulationAccount } = this.sdk.sdkOptions;
7996
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
7997
+ transactionBlock: tx,
7998
+ sender: simulationAccount.address
7999
+ });
8000
+ if (simulateRes.error != null) {
8001
+ throw new Error(`all_lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
8002
+ }
8003
+ const poolFeeRewardTokens = /* @__PURE__ */ new Map();
8004
+ simulateRes.events?.forEach((event) => {
8005
+ if (extractStructTagFromType(event.type).name === `EventFeeRewardTokens`) {
8006
+ const { lock_id } = event.parsedJson;
8007
+ if (!poolFeeRewardTokens.has(lock_id)) {
8008
+ poolFeeRewardTokens.set(lock_id, []);
8009
+ }
8010
+ event.parsedJson.list.contents.forEach((poolTokens) => {
8011
+ poolTokens.value.forEach((token) => {
8012
+ poolFeeRewardTokens.get(lock_id)?.push(token.name);
8013
+ });
8014
+ });
8015
+ }
8016
+ });
8017
+ return poolFeeRewardTokens;
8018
+ }
7872
8019
  async getVotingFeeRewardTokens(lock_id) {
7873
8020
  const tx = new import_transactions9.Transaction();
7874
8021
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
@@ -7892,7 +8039,7 @@ var LockModule = class {
7892
8039
  }
7893
8040
  const poolRewardTokens = /* @__PURE__ */ new Map();
7894
8041
  simulateRes.events?.forEach((item) => {
7895
- if (extractStructTagFromType(item.type).name === `EventRewardTokens`) {
8042
+ if (extractStructTagFromType(item.type).name === `EventFeeRewardTokens`) {
7896
8043
  item.parsedJson.list.contents.forEach((poolTokens) => {
7897
8044
  if (!poolRewardTokens.has(poolTokens.key)) {
7898
8045
  poolRewardTokens.set(poolTokens.key, []);
@@ -7905,20 +8052,70 @@ var LockModule = class {
7905
8052
  });
7906
8053
  return poolRewardTokens;
7907
8054
  }
7908
- async getVotingBribeRewardTokens(lock_id) {
7909
- const tx = new import_transactions9.Transaction();
8055
+ // tokens
8056
+ async getAllBribeRewardTokensOfLock(lock_ids) {
8057
+ let tx = new import_transactions9.Transaction();
8058
+ for (const lock_id of lock_ids) {
8059
+ tx = await this._getVotingBribeRewardTokens(lock_id, tx);
8060
+ }
8061
+ return this._parseVotingBribeRewardTokens(tx);
8062
+ }
8063
+ async _getVotingBribeRewardTokens(lock_id, tx) {
8064
+ tx = tx || new import_transactions9.Transaction();
7910
8065
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
7911
8066
  const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
7912
8067
  const typeArguments = [magma_token];
8068
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
8069
+ throw Error("this config simulationAccount is not set right");
8070
+ }
7913
8071
  const args = [tx.object(voter_id), tx.object(lock_id)];
7914
8072
  tx.moveCall({
7915
8073
  target: `${integrate.published_at}::${Voter}::get_voting_bribe_reward_tokens`,
7916
8074
  arguments: args,
7917
8075
  typeArguments
7918
8076
  });
8077
+ return tx;
8078
+ }
8079
+ async _parseVotingBribeRewardTokens(tx) {
8080
+ const { simulationAccount } = this.sdk.sdkOptions;
8081
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
8082
+ transactionBlock: tx,
8083
+ sender: simulationAccount.address
8084
+ });
8085
+ if (simulateRes.error != null) {
8086
+ throw new Error(`all_lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
8087
+ }
8088
+ const poolBirbeRewardTokens = /* @__PURE__ */ new Map();
8089
+ simulateRes.events?.forEach((event) => {
8090
+ if (extractStructTagFromType(event.type).name === `EventBribeRewardTokens`) {
8091
+ const { lock_id } = event.parsedJson;
8092
+ if (!poolBirbeRewardTokens.has(lock_id)) {
8093
+ poolBirbeRewardTokens.set(lock_id, []);
8094
+ }
8095
+ event.parsedJson.list.contents.forEach((poolTokens) => {
8096
+ poolTokens.value.forEach((token) => {
8097
+ poolBirbeRewardTokens.get(lock_id)?.push(token.name);
8098
+ });
8099
+ });
8100
+ }
8101
+ });
8102
+ return poolBirbeRewardTokens;
8103
+ }
8104
+ // Return PoolId => tokens
8105
+ async getVotingBribeRewardTokens(lock_id) {
8106
+ const tx = new import_transactions9.Transaction();
8107
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
8108
+ const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
8109
+ const typeArguments = [magma_token];
7919
8110
  if (!checkInvalidSuiAddress(simulationAccount.address)) {
7920
8111
  throw Error("this config simulationAccount is not set right");
7921
8112
  }
8113
+ const args = [tx.object(voter_id), tx.object(lock_id)];
8114
+ tx.moveCall({
8115
+ target: `${integrate.published_at}::${Voter}::get_voting_bribe_reward_tokens`,
8116
+ arguments: args,
8117
+ typeArguments
8118
+ });
7922
8119
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
7923
8120
  transactionBlock: tx,
7924
8121
  sender: simulationAccount.address
@@ -7928,7 +8125,7 @@ var LockModule = class {
7928
8125
  }
7929
8126
  const poolBirbeRewardTokens = /* @__PURE__ */ new Map();
7930
8127
  simulateRes.events?.forEach((item) => {
7931
- if (extractStructTagFromType(item.type).name === `EventRewardTokens`) {
8128
+ if (extractStructTagFromType(item.type).name === `EventBribeRewardTokens`) {
7932
8129
  item.parsedJson.list.contents.forEach((poolTokens) => {
7933
8130
  if (!poolBirbeRewardTokens.has(poolTokens.key)) {
7934
8131
  poolBirbeRewardTokens.set(poolTokens.key, []);
@@ -7941,6 +8138,68 @@ var LockModule = class {
7941
8138
  });
7942
8139
  return poolBirbeRewardTokens;
7943
8140
  }
8141
+ async getAllFeeRewards(fee_tokens) {
8142
+ let tx = new import_transactions9.Transaction();
8143
+ fee_tokens.forEach((tokens, lock_id) => {
8144
+ tx = this._getFeeRewards(lock_id, tokens, tx);
8145
+ });
8146
+ return await this._parseFeeRewards(tx);
8147
+ }
8148
+ _getFeeRewards(lock_id, fee_tokens, tx) {
8149
+ if (fee_tokens.length % 2 !== 0) {
8150
+ fee_tokens.push(fee_tokens[0]);
8151
+ }
8152
+ for (let i = 0; i + 1 < fee_tokens.length; i += 2) {
8153
+ tx = this._getFeeRewardsInner(lock_id, fee_tokens[i], fee_tokens[i + 1], tx);
8154
+ }
8155
+ return tx;
8156
+ }
8157
+ _getFeeRewardsInner(lock_id, token_a, token_b, tx) {
8158
+ tx = tx || new import_transactions9.Transaction();
8159
+ const { integrate } = this.sdk.sdkOptions;
8160
+ const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
8161
+ const typeArguments = [magma_token, token_a, token_b];
8162
+ const args = [tx.object(voter_id), tx.object(lock_id), tx.object(CLOCK_ADDRESS)];
8163
+ const targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_fee_rewards`;
8164
+ tx.moveCall({
8165
+ target: targetFunc,
8166
+ arguments: args,
8167
+ typeArguments
8168
+ });
8169
+ return tx;
8170
+ }
8171
+ async _parseFeeRewards(tx) {
8172
+ const { simulationAccount } = this.sdk.sdkOptions;
8173
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
8174
+ transactionBlock: tx,
8175
+ sender: simulationAccount.address
8176
+ });
8177
+ if (simulateRes.error != null) {
8178
+ throw new Error(`getPoolIncentiveRewards error code: ${simulateRes.error ?? "unknown error"}`);
8179
+ }
8180
+ const poolFeeRewardTokens = /* @__PURE__ */ new Map();
8181
+ simulateRes.events?.forEach((event) => {
8182
+ if (extractStructTagFromType(event.type).name === `ClaimableVotingFee`) {
8183
+ const { lock_id } = event.parsedJson;
8184
+ if (!poolFeeRewardTokens.has(lock_id)) {
8185
+ poolFeeRewardTokens.set(lock_id, /* @__PURE__ */ new Map());
8186
+ }
8187
+ event.parsedJson.list.contents.forEach((rewardTokens) => {
8188
+ rewardTokens.value.contents.forEach((token) => {
8189
+ if (!poolFeeRewardTokens.get(lock_id)?.has(rewardTokens.key.name)) {
8190
+ poolFeeRewardTokens.get(lock_id)?.set(rewardTokens.key.name, []);
8191
+ }
8192
+ poolFeeRewardTokens.get(lock_id)?.get(rewardTokens.key.name)?.push({
8193
+ kind: "incentiveCoin" /* Incentive */,
8194
+ token_addr: token.key,
8195
+ amount: token.value
8196
+ });
8197
+ });
8198
+ });
8199
+ }
8200
+ });
8201
+ return poolFeeRewardTokens;
8202
+ }
7944
8203
  async getPoolFeeRewards(lock_id, tokens) {
7945
8204
  const poolFeeRewardTokens = /* @__PURE__ */ new Map();
7946
8205
  if (tokens.length === 0) {
@@ -7991,6 +8250,78 @@ var LockModule = class {
7991
8250
  });
7992
8251
  return poolFeeRewardTokens;
7993
8252
  }
8253
+ // params: lock_id => incentive_tokens
8254
+ // lock_id => Pool => rewardTokens
8255
+ async getAllIncentiveRewards(lock_incentive_tokens) {
8256
+ let tx = new import_transactions9.Transaction();
8257
+ lock_incentive_tokens.forEach((tokens, lock_id) => {
8258
+ tx = this._getIncentiveRewards(lock_id, tokens, tx);
8259
+ });
8260
+ return await this._parseIncentiveRewards(tx);
8261
+ }
8262
+ _getIncentiveRewards(lock_id, incentive_tokens, tx) {
8263
+ let i = 0;
8264
+ for (; i + 3 < incentive_tokens.length; i += 3) {
8265
+ this._getIncentiveRewardsInner(lock_id, incentive_tokens.slice(i, i + 3), tx);
8266
+ }
8267
+ return this._getIncentiveRewardsInner(lock_id, incentive_tokens.slice(i), tx);
8268
+ }
8269
+ _getIncentiveRewardsInner(locksId, incentive_tokens, tx) {
8270
+ tx = tx || new import_transactions9.Transaction();
8271
+ if (incentive_tokens.length > 3) {
8272
+ throw Error("Too many tokens");
8273
+ }
8274
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
8275
+ const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
8276
+ const typeArguments = [magma_token, ...incentive_tokens];
8277
+ const args = [tx.object(voter_id), tx.object(locksId), tx.object(CLOCK_ADDRESS)];
8278
+ let targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_bribes_${incentive_tokens.length}`;
8279
+ if (incentive_tokens.length === 1) {
8280
+ targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_bribes`;
8281
+ }
8282
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
8283
+ throw Error("this config simulationAccount is not set right");
8284
+ }
8285
+ tx.moveCall({
8286
+ target: targetFunc,
8287
+ arguments: args,
8288
+ typeArguments
8289
+ });
8290
+ return tx;
8291
+ }
8292
+ async _parseIncentiveRewards(tx) {
8293
+ const { simulationAccount } = this.sdk.sdkOptions;
8294
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
8295
+ transactionBlock: tx,
8296
+ sender: simulationAccount.address
8297
+ });
8298
+ if (simulateRes.error != null) {
8299
+ throw new Error(`getPoolIncentiveRewards error code: ${simulateRes.error ?? "unknown error"}`);
8300
+ }
8301
+ const poolBribeRewardTokens = /* @__PURE__ */ new Map();
8302
+ simulateRes.events?.forEach((event) => {
8303
+ if (extractStructTagFromType(event.type).name === `ClaimableVotingBribes`) {
8304
+ const { lock_id } = event.parsedJson;
8305
+ if (!poolBribeRewardTokens.has(lock_id)) {
8306
+ poolBribeRewardTokens.set(lock_id, /* @__PURE__ */ new Map());
8307
+ }
8308
+ event.parsedJson.list.contents.forEach((rewardTokens) => {
8309
+ rewardTokens.value.contents.forEach((token) => {
8310
+ if (!poolBribeRewardTokens.get(lock_id)?.has(rewardTokens.key.name)) {
8311
+ poolBribeRewardTokens.get(lock_id)?.set(rewardTokens.key.name, []);
8312
+ }
8313
+ poolBribeRewardTokens.get(lock_id)?.get(rewardTokens.key.name)?.push({
8314
+ kind: "incentiveCoin" /* Incentive */,
8315
+ token_addr: token.key,
8316
+ amount: token.value
8317
+ });
8318
+ });
8319
+ });
8320
+ }
8321
+ });
8322
+ return poolBribeRewardTokens;
8323
+ }
8324
+ // coin => pool => amount
7994
8325
  async getPoolIncentiveRewards(lock_id, incentive_tokens) {
7995
8326
  const poolBribeRewardTokens = /* @__PURE__ */ new Map();
7996
8327
  if (incentive_tokens.length === 0) {
@@ -8017,14 +8348,14 @@ var LockModule = class {
8017
8348
  if (incentive_tokens.length === 1) {
8018
8349
  targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_bribes`;
8019
8350
  }
8351
+ if (!checkInvalidSuiAddress(simulationAccount.address)) {
8352
+ throw Error("this config simulationAccount is not set right");
8353
+ }
8020
8354
  tx.moveCall({
8021
8355
  target: targetFunc,
8022
8356
  arguments: args,
8023
8357
  typeArguments
8024
8358
  });
8025
- if (!checkInvalidSuiAddress(simulationAccount.address)) {
8026
- throw Error("this config simulationAccount is not set right");
8027
- }
8028
8359
  const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
8029
8360
  transactionBlock: tx,
8030
8361
  sender: simulationAccount.address
@@ -9605,7 +9936,6 @@ var GaugeModule = class {
9605
9936
  const poolGauger = /* @__PURE__ */ new Map();
9606
9937
  simulateRes.events?.forEach((item) => {
9607
9938
  const { gauges } = item.parsedJson;
9608
- console.log("parsedJson", item.parsedJson);
9609
9939
  item.parsedJson.pools.map((pool, index) => {
9610
9940
  poolGauger.set(pool, gauges[index]);
9611
9941
  });
@@ -9672,6 +10002,21 @@ var GaugeModule = class {
9672
10002
  });
9673
10003
  return tx;
9674
10004
  }
10005
+ async getAllRewardByPositions(paramsList) {
10006
+ const tx = new import_transactions11.Transaction();
10007
+ const { integrate } = this.sdk.sdkOptions;
10008
+ const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
10009
+ paramsList.forEach((params) => {
10010
+ const typeArguments = [params.coinTypeA, params.coinTypeB, magma_token];
10011
+ const args = [tx.object(params.gaugeId), tx.object(params.poolId), tx.object(params.positionId), tx.object(CLOCK_ADDRESS)];
10012
+ tx.moveCall({
10013
+ target: `${integrate.published_at}::${Gauge}::get_reward_by_position`,
10014
+ arguments: args,
10015
+ typeArguments
10016
+ });
10017
+ });
10018
+ return tx;
10019
+ }
9675
10020
  async getEpochRewardByPool(pool, incentive_tokens) {
9676
10021
  const tx = new import_transactions11.Transaction();
9677
10022
  const { integrate, simulationAccount } = this.sdk.sdkOptions;