@magmaprotocol/magma-clmm-sdk 0.5.40 → 0.5.41

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
@@ -10455,6 +10455,20 @@ var GaugeModule = class {
10455
10455
  });
10456
10456
  return tx;
10457
10457
  }
10458
+ async testTeacherCap() {
10459
+ const tx = new Transaction11();
10460
+ tx.moveCall({
10461
+ target: `0xd1bf0385f6d298d3b6f140869c28700e85709d570984200cd82c8164401c5e49::hello_world::call_func1`,
10462
+ arguments: [tx.object("0xe1af009a9212aa4bf936ff51794d39e8a75dfbd8e65e3265d3a8e93b4c9256bf")],
10463
+ typeArguments: []
10464
+ });
10465
+ tx.moveCall({
10466
+ target: `0xd1bf0385f6d298d3b6f140869c28700e85709d570984200cd82c8164401c5e49::hello_world::call_func2`,
10467
+ arguments: [tx.object("0xe1af009a9212aa4bf936ff51794d39e8a75dfbd8e65e3265d3a8e93b4c9256bf")],
10468
+ typeArguments: []
10469
+ });
10470
+ return tx;
10471
+ }
10458
10472
  async getEpochRewardByPool(pool, incentive_tokens) {
10459
10473
  const tx = new Transaction11();
10460
10474
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
@@ -10648,6 +10662,153 @@ var DlmmModule = class {
10648
10662
  });
10649
10663
  return tx;
10650
10664
  }
10665
+ async addLiquidity(params) {
10666
+ if (params.rewards_token.length === 0) {
10667
+ return this._raisePositionByAmounts(params);
10668
+ }
10669
+ return this._raisePositionByAmountsReward(params);
10670
+ }
10671
+ async _raisePositionByAmounts(params) {
10672
+ const tx = new Transaction12();
10673
+ tx.setSender(this.sdk.senderAddress);
10674
+ const { dlmm_pool, integrate } = this.sdk.sdkOptions;
10675
+ const dlmmConfig = getPackagerConfigs(dlmm_pool);
10676
+ const typeArguments = [params.coin_a, params.coin_b];
10677
+ const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10678
+ const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
10679
+ const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
10680
+ const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
10681
+ const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
10682
+ const args = [
10683
+ tx.object(params.pool_id),
10684
+ tx.object(dlmmConfig.factory),
10685
+ tx.object(params.position_id),
10686
+ primaryCoinAInputs.targetCoin,
10687
+ primaryCoinBInputs.targetCoin,
10688
+ tx.pure.vector("u64", params.amounts_a),
10689
+ tx.pure.vector("u64", params.amounts_b),
10690
+ tx.pure.address(params.receiver),
10691
+ tx.object(CLOCK_ADDRESS)
10692
+ ];
10693
+ tx.moveCall({
10694
+ target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts`,
10695
+ typeArguments,
10696
+ arguments: args
10697
+ });
10698
+ return tx;
10699
+ }
10700
+ async _raisePositionByAmountsReward(params) {
10701
+ const tx = new Transaction12();
10702
+ tx.setSender(this.sdk.senderAddress);
10703
+ const { dlmm_pool, integrate, clmm_pool } = this.sdk.sdkOptions;
10704
+ const dlmmConfig = getPackagerConfigs(dlmm_pool);
10705
+ const clmmConfigs = getPackagerConfigs(clmm_pool);
10706
+ const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
10707
+ const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10708
+ const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
10709
+ const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
10710
+ const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
10711
+ const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
10712
+ const args = [
10713
+ tx.object(params.pool_id),
10714
+ tx.object(dlmmConfig.factory),
10715
+ tx.object(clmmConfigs.global_vault_id),
10716
+ tx.object(params.position_id),
10717
+ primaryCoinAInputs.targetCoin,
10718
+ primaryCoinBInputs.targetCoin,
10719
+ tx.pure.vector("u64", params.amounts_a),
10720
+ tx.pure.vector("u64", params.amounts_b),
10721
+ tx.pure.address(params.receiver),
10722
+ tx.object(CLOCK_ADDRESS)
10723
+ ];
10724
+ tx.moveCall({
10725
+ target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts_reward${params.rewards_token.length}`,
10726
+ typeArguments,
10727
+ arguments: args
10728
+ });
10729
+ return tx;
10730
+ }
10731
+ async burnPosition(params) {
10732
+ const tx = new Transaction12();
10733
+ tx.setSender(this.sdk.senderAddress);
10734
+ const { integrate, clmm_pool } = this.sdk.sdkOptions;
10735
+ const clmmConfigs = getPackagerConfigs(clmm_pool);
10736
+ const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
10737
+ let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
10738
+ let target = `${integrate.published_at}::${DlmmScript}::burn_position`;
10739
+ if (params.rewards_token.length > 0) {
10740
+ args = [tx.object(params.pool_id), tx.object(clmmConfigs.global_vault_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
10741
+ target = `${integrate.published_at}::${DlmmScript}::burn_position_reward${params.rewards_token.length}`;
10742
+ }
10743
+ tx.moveCall({
10744
+ target,
10745
+ typeArguments,
10746
+ arguments: args
10747
+ });
10748
+ return tx;
10749
+ }
10750
+ async shrinkPosition(params) {
10751
+ const tx = new Transaction12();
10752
+ tx.setSender(this.sdk.senderAddress);
10753
+ const { integrate, clmm_pool } = this.sdk.sdkOptions;
10754
+ const clmmConfigs = getPackagerConfigs(clmm_pool);
10755
+ const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
10756
+ let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.pure.u64(params.delta_percentage), tx.object(CLOCK_ADDRESS)];
10757
+ let target = `${integrate.published_at}::${DlmmScript}::shrink_position`;
10758
+ if (params.rewards_token.length > 0) {
10759
+ args = [
10760
+ tx.object(params.pool_id),
10761
+ tx.object(clmmConfigs.global_vault_id),
10762
+ tx.object(params.position_id),
10763
+ tx.pure.u64(params.delta_percentage),
10764
+ tx.object(CLOCK_ADDRESS)
10765
+ ];
10766
+ target = `${integrate.published_at}::${DlmmScript}::shrink_position_reward${params.rewards_token.length}`;
10767
+ }
10768
+ tx.moveCall({
10769
+ target,
10770
+ typeArguments,
10771
+ arguments: args
10772
+ });
10773
+ return tx;
10774
+ }
10775
+ async collectReward(params) {
10776
+ const tx = new Transaction12();
10777
+ tx.setSender(this.sdk.senderAddress);
10778
+ const { integrate, clmm_pool } = this.sdk.sdkOptions;
10779
+ const clmmConfigs = getPackagerConfigs(clmm_pool);
10780
+ const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
10781
+ const args = [
10782
+ tx.object(params.pool_id),
10783
+ tx.object(clmmConfigs.global_vault_id),
10784
+ tx.object(params.position_id),
10785
+ tx.object(CLOCK_ADDRESS)
10786
+ ];
10787
+ let target = `${integrate.published_at}::${DlmmScript}::collect_reward`;
10788
+ if (params.rewards_token.length > 1) {
10789
+ target = `${integrate.published_at}::${DlmmScript}::collect_reward${params.rewards_token.length}`;
10790
+ }
10791
+ tx.moveCall({
10792
+ target,
10793
+ typeArguments,
10794
+ arguments: args
10795
+ });
10796
+ return tx;
10797
+ }
10798
+ async collectFees(params) {
10799
+ const tx = new Transaction12();
10800
+ tx.setSender(this.sdk.senderAddress);
10801
+ const { integrate } = this.sdk.sdkOptions;
10802
+ const typeArguments = [params.coin_a, params.coin_b];
10803
+ const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
10804
+ const target = `${integrate.published_at}::${DlmmScript}::collect_fees`;
10805
+ tx.moveCall({
10806
+ target,
10807
+ typeArguments,
10808
+ arguments: args
10809
+ });
10810
+ return tx;
10811
+ }
10651
10812
  async swap(params) {
10652
10813
  const tx = new Transaction12();
10653
10814
  tx.setSender(this.sdk.senderAddress);
@@ -10689,9 +10850,11 @@ var DlmmModule = class {
10689
10850
  if (simulateRes.error != null) {
10690
10851
  throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
10691
10852
  }
10692
- const res = [];
10853
+ let res = [];
10693
10854
  simulateRes.events?.forEach((item) => {
10694
10855
  if (extractStructTagFromType(item.type).name === `EventFetchBins`) {
10856
+ const { bins } = item.parsedJson;
10857
+ res = bins;
10695
10858
  }
10696
10859
  });
10697
10860
  return res;
@@ -10729,7 +10892,7 @@ var DlmmModule = class {
10729
10892
  out.liquidity = item.parsedJson.liquidity;
10730
10893
  out.x_equivalent = item.parsedJson.x_equivalent;
10731
10894
  out.y_equivalent = item.parsedJson.y_equivalent;
10732
- out.bin_ids = item.parsedJson.bin_id;
10895
+ out.bin_ids = item.parsedJson.bin_ids;
10733
10896
  out.bin_x_eq = item.parsedJson.bin_x_eq;
10734
10897
  out.bin_y_eq = item.parsedJson.bin_y_eq;
10735
10898
  out.bin_liquidity = item.parsedJson.bin_liquidity;
@@ -10776,6 +10939,127 @@ var DlmmModule = class {
10776
10939
  });
10777
10940
  return out;
10778
10941
  }
10942
+ async getEarnedFees(params) {
10943
+ const tx = new Transaction12();
10944
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
10945
+ const typeArguments = [params.coin_a, params.coin_b];
10946
+ const args = [tx.object(params.pool_id), tx.object(params.position_id)];
10947
+ tx.moveCall({
10948
+ target: `${integrate.published_at}::${DlmmScript}::earned_fees`,
10949
+ arguments: args,
10950
+ typeArguments
10951
+ });
10952
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
10953
+ transactionBlock: tx,
10954
+ sender: simulationAccount.address
10955
+ });
10956
+ const out = {
10957
+ position_id: "",
10958
+ x: "",
10959
+ y: "",
10960
+ fee_x: 0,
10961
+ fee_y: 0
10962
+ };
10963
+ if (simulateRes.error != null) {
10964
+ throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
10965
+ }
10966
+ simulateRes.events?.forEach((item) => {
10967
+ if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
10968
+ out.position_id = item.parsedJson.position_id;
10969
+ out.x = item.parsedJson.x;
10970
+ out.y = item.parsedJson.y;
10971
+ out.fee_x = item.parsedJson.fee_x;
10972
+ out.fee_y = item.parsedJson.fee_y;
10973
+ }
10974
+ });
10975
+ return out;
10976
+ }
10977
+ async getEarnedRewards(params) {
10978
+ const tx = new Transaction12();
10979
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
10980
+ const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
10981
+ const args = [tx.object(params.pool_id), tx.object(params.position_id)];
10982
+ let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
10983
+ if (params.rewards_token.length > 1) {
10984
+ target = `${integrate.published_at}::${DlmmScript}::earned_rewards${params.rewards_token.length}`;
10985
+ }
10986
+ tx.moveCall({
10987
+ target,
10988
+ arguments: args,
10989
+ typeArguments
10990
+ });
10991
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
10992
+ transactionBlock: tx,
10993
+ sender: simulationAccount.address
10994
+ });
10995
+ const out = {
10996
+ position_id: "",
10997
+ reward: [],
10998
+ amount: []
10999
+ };
11000
+ if (simulateRes.error != null) {
11001
+ throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11002
+ }
11003
+ simulateRes.events?.forEach((item) => {
11004
+ if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards`) {
11005
+ out.position_id = item.parsedJson.position_id;
11006
+ out.reward = [item.parsedJson.reward];
11007
+ out.amount = [item.parsedJson.amount];
11008
+ } else if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards2`) {
11009
+ out.position_id = item.parsedJson.position_id;
11010
+ out.reward = [item.parsedJson.reward1, item.parsedJson.reward2];
11011
+ out.amount = [item.parsedJson.amount1, item.parsedJson.amount2];
11012
+ } else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
11013
+ out.position_id = item.parsedJson.position_id;
11014
+ out.reward = [item.parsedJson.reward1, item.parsedJson.reward2, item.parsedJson.reward3];
11015
+ out.amount = [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3];
11016
+ }
11017
+ });
11018
+ return out;
11019
+ }
11020
+ async getPairRewarders(params) {
11021
+ let tx = new Transaction12();
11022
+ for (const param of params) {
11023
+ tx = await this._getPairRewarders(param, tx);
11024
+ }
11025
+ return this._parsePairRewarders(tx);
11026
+ }
11027
+ async _getPairRewarders(params, tx) {
11028
+ tx = tx || new Transaction12();
11029
+ const { integrate } = this.sdk.sdkOptions;
11030
+ const typeArguments = [params.coin_a, params.coin_b];
11031
+ const args = [tx.object(params.pool_id)];
11032
+ tx.moveCall({
11033
+ target: `${integrate.published_at}::${DlmmScript}::get_pair_rewarders`,
11034
+ arguments: args,
11035
+ typeArguments
11036
+ });
11037
+ return tx;
11038
+ }
11039
+ async _parsePairRewarders(tx) {
11040
+ const { simulationAccount } = this.sdk.sdkOptions;
11041
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11042
+ transactionBlock: tx,
11043
+ sender: simulationAccount.address
11044
+ });
11045
+ const out = /* @__PURE__ */ new Map();
11046
+ if (simulateRes.error != null) {
11047
+ throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11048
+ }
11049
+ simulateRes.events?.forEach((item) => {
11050
+ if (extractStructTagFromType(item.type).name === `EventPairRewardTypes`) {
11051
+ const pairRewards = {
11052
+ pair_id: "",
11053
+ tokens: []
11054
+ };
11055
+ pairRewards.pair_id = item.parsedJson.pair_id;
11056
+ item.parsedJson.tokens.contents.forEach((token) => {
11057
+ pairRewards.tokens.push(token.name);
11058
+ });
11059
+ }
11060
+ });
11061
+ return out;
11062
+ }
10779
11063
  };
10780
11064
 
10781
11065
  // src/sdk.ts
@@ -11055,7 +11339,7 @@ var SDKConfig = {
11055
11339
  clmmConfig: {
11056
11340
  pools_id: "0xfa145b9de10fe858be81edd1c6cdffcf27be9d016de02a1345eb1009a68ba8b2",
11057
11341
  // clmm and dlmm both use this global_config
11058
- global_config_id: "0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a",
11342
+ global_config_id: "0x4e39044c21fe04e27c67b110dec37807ad439516a1701cf2e0dc842e9e20f1f3",
11059
11343
  global_vault_id: "0xa7e1102f222b6eb81ccc8a126e7feb2353342be9df6f6646a77c4519da29c071",
11060
11344
  admin_cap_id: "0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"
11061
11345
  },
@@ -11076,7 +11360,7 @@ var SDKConfig = {
11076
11360
  minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
11077
11361
  },
11078
11362
  dlmmConfig: {
11079
- factory: ""
11363
+ factory: "0xb7d4f7281bc604981e2caaa5d2af875b66f9422fcdbf6e310d8ed16b854a5d3e"
11080
11364
  },
11081
11365
  gaugeConfig: {}
11082
11366
  };
@@ -11096,8 +11380,8 @@ var clmmMainnet = {
11096
11380
  config: SDKConfig.clmmConfig
11097
11381
  },
11098
11382
  dlmm_pool: {
11099
- package_id: "",
11100
- published_at: "",
11383
+ package_id: "0xb3a44310c59536782d1b5c29d01a066798750ff0c15242a7f3eb7e55d188cfc3",
11384
+ published_at: "0xb3a44310c59536782d1b5c29d01a066798750ff0c15242a7f3eb7e55d188cfc3",
11101
11385
  config: SDKConfig.dlmmConfig
11102
11386
  },
11103
11387
  distribution: {
@@ -11105,8 +11389,8 @@ var clmmMainnet = {
11105
11389
  published_at: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b"
11106
11390
  },
11107
11391
  integrate: {
11108
- package_id: "0x2e704d8afc1d6d7f154dee337cc14c153f6f9ce1708213e5dc04a32afe0e45f1",
11109
- published_at: "0x2e704d8afc1d6d7f154dee337cc14c153f6f9ce1708213e5dc04a32afe0e45f1"
11392
+ package_id: "0x228638b6ea17788e34971afee4b4580dbc4dcaa847ef62604d858ef5d3beb5a6",
11393
+ published_at: "0x228638b6ea17788e34971afee4b4580dbc4dcaa847ef62604d858ef5d3beb5a6"
11110
11394
  },
11111
11395
  deepbook: {
11112
11396
  package_id: "0x000000000000000000000000000000000000000000000000000000000000dee9",