@magmaprotocol/magma-clmm-sdk 0.5.40 → 0.5.42
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 +79 -1
- package/dist/index.js +272 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +272 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10648,6 +10648,153 @@ var DlmmModule = class {
|
|
|
10648
10648
|
});
|
|
10649
10649
|
return tx;
|
|
10650
10650
|
}
|
|
10651
|
+
async addLiquidity(params) {
|
|
10652
|
+
if (params.rewards_token.length === 0) {
|
|
10653
|
+
return this._raisePositionByAmounts(params);
|
|
10654
|
+
}
|
|
10655
|
+
return this._raisePositionByAmountsReward(params);
|
|
10656
|
+
}
|
|
10657
|
+
async _raisePositionByAmounts(params) {
|
|
10658
|
+
const tx = new Transaction12();
|
|
10659
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10660
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10661
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10662
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
10663
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10664
|
+
const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10665
|
+
const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10666
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
|
|
10667
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
|
|
10668
|
+
const args = [
|
|
10669
|
+
tx.object(params.pool_id),
|
|
10670
|
+
tx.object(dlmmConfig.factory),
|
|
10671
|
+
tx.object(params.position_id),
|
|
10672
|
+
primaryCoinAInputs.targetCoin,
|
|
10673
|
+
primaryCoinBInputs.targetCoin,
|
|
10674
|
+
tx.pure.vector("u64", params.amounts_a),
|
|
10675
|
+
tx.pure.vector("u64", params.amounts_b),
|
|
10676
|
+
tx.pure.address(params.receiver),
|
|
10677
|
+
tx.object(CLOCK_ADDRESS)
|
|
10678
|
+
];
|
|
10679
|
+
tx.moveCall({
|
|
10680
|
+
target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts`,
|
|
10681
|
+
typeArguments,
|
|
10682
|
+
arguments: args
|
|
10683
|
+
});
|
|
10684
|
+
return tx;
|
|
10685
|
+
}
|
|
10686
|
+
async _raisePositionByAmountsReward(params) {
|
|
10687
|
+
const tx = new Transaction12();
|
|
10688
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10689
|
+
const { dlmm_pool, integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10690
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10691
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10692
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10693
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10694
|
+
const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10695
|
+
const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10696
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
|
|
10697
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
|
|
10698
|
+
const args = [
|
|
10699
|
+
tx.object(params.pool_id),
|
|
10700
|
+
tx.object(dlmmConfig.factory),
|
|
10701
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10702
|
+
tx.object(params.position_id),
|
|
10703
|
+
primaryCoinAInputs.targetCoin,
|
|
10704
|
+
primaryCoinBInputs.targetCoin,
|
|
10705
|
+
tx.pure.vector("u64", params.amounts_a),
|
|
10706
|
+
tx.pure.vector("u64", params.amounts_b),
|
|
10707
|
+
tx.pure.address(params.receiver),
|
|
10708
|
+
tx.object(CLOCK_ADDRESS)
|
|
10709
|
+
];
|
|
10710
|
+
tx.moveCall({
|
|
10711
|
+
target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts_reward${params.rewards_token.length}`,
|
|
10712
|
+
typeArguments,
|
|
10713
|
+
arguments: args
|
|
10714
|
+
});
|
|
10715
|
+
return tx;
|
|
10716
|
+
}
|
|
10717
|
+
async burnPosition(params) {
|
|
10718
|
+
const tx = new Transaction12();
|
|
10719
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10720
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10721
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10722
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10723
|
+
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10724
|
+
let target = `${integrate.published_at}::${DlmmScript}::burn_position`;
|
|
10725
|
+
if (params.rewards_token.length > 0) {
|
|
10726
|
+
args = [tx.object(params.pool_id), tx.object(clmmConfigs.global_vault_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10727
|
+
target = `${integrate.published_at}::${DlmmScript}::burn_position_reward${params.rewards_token.length}`;
|
|
10728
|
+
}
|
|
10729
|
+
tx.moveCall({
|
|
10730
|
+
target,
|
|
10731
|
+
typeArguments,
|
|
10732
|
+
arguments: args
|
|
10733
|
+
});
|
|
10734
|
+
return tx;
|
|
10735
|
+
}
|
|
10736
|
+
async shrinkPosition(params) {
|
|
10737
|
+
const tx = new Transaction12();
|
|
10738
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10739
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10740
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10741
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10742
|
+
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.pure.u64(params.delta_percentage), tx.object(CLOCK_ADDRESS)];
|
|
10743
|
+
let target = `${integrate.published_at}::${DlmmScript}::shrink_position`;
|
|
10744
|
+
if (params.rewards_token.length > 0) {
|
|
10745
|
+
args = [
|
|
10746
|
+
tx.object(params.pool_id),
|
|
10747
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10748
|
+
tx.object(params.position_id),
|
|
10749
|
+
tx.pure.u64(params.delta_percentage),
|
|
10750
|
+
tx.object(CLOCK_ADDRESS)
|
|
10751
|
+
];
|
|
10752
|
+
target = `${integrate.published_at}::${DlmmScript}::shrink_position_reward${params.rewards_token.length}`;
|
|
10753
|
+
}
|
|
10754
|
+
tx.moveCall({
|
|
10755
|
+
target,
|
|
10756
|
+
typeArguments,
|
|
10757
|
+
arguments: args
|
|
10758
|
+
});
|
|
10759
|
+
return tx;
|
|
10760
|
+
}
|
|
10761
|
+
async collectReward(params) {
|
|
10762
|
+
const tx = new Transaction12();
|
|
10763
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10764
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10765
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10766
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10767
|
+
const args = [
|
|
10768
|
+
tx.object(params.pool_id),
|
|
10769
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10770
|
+
tx.object(params.position_id),
|
|
10771
|
+
tx.object(CLOCK_ADDRESS)
|
|
10772
|
+
];
|
|
10773
|
+
let target = `${integrate.published_at}::${DlmmScript}::collect_reward`;
|
|
10774
|
+
if (params.rewards_token.length > 1) {
|
|
10775
|
+
target = `${integrate.published_at}::${DlmmScript}::collect_reward${params.rewards_token.length}`;
|
|
10776
|
+
}
|
|
10777
|
+
tx.moveCall({
|
|
10778
|
+
target,
|
|
10779
|
+
typeArguments,
|
|
10780
|
+
arguments: args
|
|
10781
|
+
});
|
|
10782
|
+
return tx;
|
|
10783
|
+
}
|
|
10784
|
+
async collectFees(params) {
|
|
10785
|
+
const tx = new Transaction12();
|
|
10786
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10787
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
10788
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
10789
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10790
|
+
const target = `${integrate.published_at}::${DlmmScript}::collect_fees`;
|
|
10791
|
+
tx.moveCall({
|
|
10792
|
+
target,
|
|
10793
|
+
typeArguments,
|
|
10794
|
+
arguments: args
|
|
10795
|
+
});
|
|
10796
|
+
return tx;
|
|
10797
|
+
}
|
|
10651
10798
|
async swap(params) {
|
|
10652
10799
|
const tx = new Transaction12();
|
|
10653
10800
|
tx.setSender(this.sdk.senderAddress);
|
|
@@ -10689,9 +10836,11 @@ var DlmmModule = class {
|
|
|
10689
10836
|
if (simulateRes.error != null) {
|
|
10690
10837
|
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
10691
10838
|
}
|
|
10692
|
-
|
|
10839
|
+
let res = [];
|
|
10693
10840
|
simulateRes.events?.forEach((item) => {
|
|
10694
10841
|
if (extractStructTagFromType(item.type).name === `EventFetchBins`) {
|
|
10842
|
+
const { bins } = item.parsedJson;
|
|
10843
|
+
res = bins;
|
|
10695
10844
|
}
|
|
10696
10845
|
});
|
|
10697
10846
|
return res;
|
|
@@ -10729,7 +10878,7 @@ var DlmmModule = class {
|
|
|
10729
10878
|
out.liquidity = item.parsedJson.liquidity;
|
|
10730
10879
|
out.x_equivalent = item.parsedJson.x_equivalent;
|
|
10731
10880
|
out.y_equivalent = item.parsedJson.y_equivalent;
|
|
10732
|
-
out.bin_ids = item.parsedJson.
|
|
10881
|
+
out.bin_ids = item.parsedJson.bin_ids;
|
|
10733
10882
|
out.bin_x_eq = item.parsedJson.bin_x_eq;
|
|
10734
10883
|
out.bin_y_eq = item.parsedJson.bin_y_eq;
|
|
10735
10884
|
out.bin_liquidity = item.parsedJson.bin_liquidity;
|
|
@@ -10776,6 +10925,127 @@ var DlmmModule = class {
|
|
|
10776
10925
|
});
|
|
10777
10926
|
return out;
|
|
10778
10927
|
}
|
|
10928
|
+
async getEarnedFees(params) {
|
|
10929
|
+
const tx = new Transaction12();
|
|
10930
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
10931
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
10932
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id)];
|
|
10933
|
+
tx.moveCall({
|
|
10934
|
+
target: `${integrate.published_at}::${DlmmScript}::earned_fees`,
|
|
10935
|
+
arguments: args,
|
|
10936
|
+
typeArguments
|
|
10937
|
+
});
|
|
10938
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
10939
|
+
transactionBlock: tx,
|
|
10940
|
+
sender: simulationAccount.address
|
|
10941
|
+
});
|
|
10942
|
+
const out = {
|
|
10943
|
+
position_id: "",
|
|
10944
|
+
x: "",
|
|
10945
|
+
y: "",
|
|
10946
|
+
fee_x: 0,
|
|
10947
|
+
fee_y: 0
|
|
10948
|
+
};
|
|
10949
|
+
if (simulateRes.error != null) {
|
|
10950
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
10951
|
+
}
|
|
10952
|
+
simulateRes.events?.forEach((item) => {
|
|
10953
|
+
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
10954
|
+
out.position_id = item.parsedJson.position_id;
|
|
10955
|
+
out.x = item.parsedJson.x;
|
|
10956
|
+
out.y = item.parsedJson.y;
|
|
10957
|
+
out.fee_x = item.parsedJson.fee_x;
|
|
10958
|
+
out.fee_y = item.parsedJson.fee_y;
|
|
10959
|
+
}
|
|
10960
|
+
});
|
|
10961
|
+
return out;
|
|
10962
|
+
}
|
|
10963
|
+
async getEarnedRewards(params) {
|
|
10964
|
+
const tx = new Transaction12();
|
|
10965
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
10966
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10967
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id)];
|
|
10968
|
+
let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
|
|
10969
|
+
if (params.rewards_token.length > 1) {
|
|
10970
|
+
target = `${integrate.published_at}::${DlmmScript}::earned_rewards${params.rewards_token.length}`;
|
|
10971
|
+
}
|
|
10972
|
+
tx.moveCall({
|
|
10973
|
+
target,
|
|
10974
|
+
arguments: args,
|
|
10975
|
+
typeArguments
|
|
10976
|
+
});
|
|
10977
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
10978
|
+
transactionBlock: tx,
|
|
10979
|
+
sender: simulationAccount.address
|
|
10980
|
+
});
|
|
10981
|
+
const out = {
|
|
10982
|
+
position_id: "",
|
|
10983
|
+
reward: [],
|
|
10984
|
+
amount: []
|
|
10985
|
+
};
|
|
10986
|
+
if (simulateRes.error != null) {
|
|
10987
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
10988
|
+
}
|
|
10989
|
+
simulateRes.events?.forEach((item) => {
|
|
10990
|
+
if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards`) {
|
|
10991
|
+
out.position_id = item.parsedJson.position_id;
|
|
10992
|
+
out.reward = [item.parsedJson.reward];
|
|
10993
|
+
out.amount = [item.parsedJson.amount];
|
|
10994
|
+
} else if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards2`) {
|
|
10995
|
+
out.position_id = item.parsedJson.position_id;
|
|
10996
|
+
out.reward = [item.parsedJson.reward1, item.parsedJson.reward2];
|
|
10997
|
+
out.amount = [item.parsedJson.amount1, item.parsedJson.amount2];
|
|
10998
|
+
} else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
|
|
10999
|
+
out.position_id = item.parsedJson.position_id;
|
|
11000
|
+
out.reward = [item.parsedJson.reward1, item.parsedJson.reward2, item.parsedJson.reward3];
|
|
11001
|
+
out.amount = [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3];
|
|
11002
|
+
}
|
|
11003
|
+
});
|
|
11004
|
+
return out;
|
|
11005
|
+
}
|
|
11006
|
+
async getPairRewarders(params) {
|
|
11007
|
+
let tx = new Transaction12();
|
|
11008
|
+
for (const param of params) {
|
|
11009
|
+
tx = await this._getPairRewarders(param, tx);
|
|
11010
|
+
}
|
|
11011
|
+
return this._parsePairRewarders(tx);
|
|
11012
|
+
}
|
|
11013
|
+
async _getPairRewarders(params, tx) {
|
|
11014
|
+
tx = tx || new Transaction12();
|
|
11015
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11016
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
11017
|
+
const args = [tx.object(params.pool_id)];
|
|
11018
|
+
tx.moveCall({
|
|
11019
|
+
target: `${integrate.published_at}::${DlmmScript}::get_pair_rewarders`,
|
|
11020
|
+
arguments: args,
|
|
11021
|
+
typeArguments
|
|
11022
|
+
});
|
|
11023
|
+
return tx;
|
|
11024
|
+
}
|
|
11025
|
+
async _parsePairRewarders(tx) {
|
|
11026
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11027
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11028
|
+
transactionBlock: tx,
|
|
11029
|
+
sender: simulationAccount.address
|
|
11030
|
+
});
|
|
11031
|
+
const out = /* @__PURE__ */ new Map();
|
|
11032
|
+
if (simulateRes.error != null) {
|
|
11033
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11034
|
+
}
|
|
11035
|
+
simulateRes.events?.forEach((item) => {
|
|
11036
|
+
if (extractStructTagFromType(item.type).name === `EventPairRewardTypes`) {
|
|
11037
|
+
const pairRewards = {
|
|
11038
|
+
pair_id: "",
|
|
11039
|
+
tokens: []
|
|
11040
|
+
};
|
|
11041
|
+
pairRewards.pair_id = item.parsedJson.pair_id;
|
|
11042
|
+
item.parsedJson.tokens.contents.forEach((token) => {
|
|
11043
|
+
pairRewards.tokens.push(token.name);
|
|
11044
|
+
});
|
|
11045
|
+
}
|
|
11046
|
+
});
|
|
11047
|
+
return out;
|
|
11048
|
+
}
|
|
10779
11049
|
};
|
|
10780
11050
|
|
|
10781
11051
|
// src/sdk.ts
|