@magmaprotocol/magma-clmm-sdk 0.5.49 → 0.5.51
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 +31 -2
- package/dist/index.js +124 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +124 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10506,8 +10506,8 @@ var GaugeModule = class {
|
|
|
10506
10506
|
|
|
10507
10507
|
// src/modules/dlmm.ts
|
|
10508
10508
|
import { Transaction as Transaction12 } from "@mysten/sui/transactions";
|
|
10509
|
-
import Decimal10 from "decimal.js";
|
|
10510
10509
|
import { get_real_id_from_price_x128 as get_real_id_from_price_x1282, get_storage_id_from_real_id } from "@magmaprotocol/calc_dlmm";
|
|
10510
|
+
import Decimal10 from "decimal.js";
|
|
10511
10511
|
var DlmmModule = class {
|
|
10512
10512
|
_sdk;
|
|
10513
10513
|
constructor(sdk) {
|
|
@@ -10814,6 +10814,38 @@ var DlmmModule = class {
|
|
|
10814
10814
|
});
|
|
10815
10815
|
return tx;
|
|
10816
10816
|
}
|
|
10817
|
+
async createPairAddLiquidity(params) {
|
|
10818
|
+
const tx = new Transaction12();
|
|
10819
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10820
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10821
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10822
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10823
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10824
|
+
const amountATotal = params.amountsX.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10825
|
+
const amountBTotal = params.amountsY.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10826
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coinTypeA, false, true);
|
|
10827
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coinTypeB, false, true);
|
|
10828
|
+
const args = [
|
|
10829
|
+
tx.object(dlmmConfig.factory),
|
|
10830
|
+
tx.pure.u64(params.baseFee),
|
|
10831
|
+
tx.pure.u16(params.binStep),
|
|
10832
|
+
tx.pure.u32(params.activeId),
|
|
10833
|
+
primaryCoinAInputs.targetCoin,
|
|
10834
|
+
primaryCoinBInputs.targetCoin,
|
|
10835
|
+
tx.pure.vector("u32", params.storageIds),
|
|
10836
|
+
tx.pure.vector("u64", params.amountsX),
|
|
10837
|
+
tx.pure.vector("u64", params.amountsY),
|
|
10838
|
+
tx.pure.address(params.to),
|
|
10839
|
+
tx.object(CLOCK_ADDRESS)
|
|
10840
|
+
];
|
|
10841
|
+
const target = `${integrate.published_at}::${DlmmScript}::create_pair_add_liquidity`;
|
|
10842
|
+
tx.moveCall({
|
|
10843
|
+
target,
|
|
10844
|
+
typeArguments,
|
|
10845
|
+
arguments: args
|
|
10846
|
+
});
|
|
10847
|
+
return tx;
|
|
10848
|
+
}
|
|
10817
10849
|
async swap(params) {
|
|
10818
10850
|
const tx = new Transaction12();
|
|
10819
10851
|
tx.setSender(this.sdk.senderAddress);
|
|
@@ -10864,6 +10896,95 @@ var DlmmModule = class {
|
|
|
10864
10896
|
});
|
|
10865
10897
|
return res;
|
|
10866
10898
|
}
|
|
10899
|
+
async getUserPositions(who, showDisplay = true) {
|
|
10900
|
+
const ownerRes = await this._sdk.fullClient.getOwnedObjectsByPage(who, {
|
|
10901
|
+
options: { showType: true, showContent: true, showDisplay, showOwner: true },
|
|
10902
|
+
filter: { Package: this._sdk.sdkOptions.dlmm_pool.package_id }
|
|
10903
|
+
});
|
|
10904
|
+
const positions = [];
|
|
10905
|
+
const pools = [];
|
|
10906
|
+
for (const item of ownerRes.data) {
|
|
10907
|
+
const type = extractStructTagFromType(item.data.type);
|
|
10908
|
+
if (type.full_address === this.buildPositionType()) {
|
|
10909
|
+
const position = this.buildPosition(item);
|
|
10910
|
+
positions.push(position);
|
|
10911
|
+
if (!pools.includes(position.pool)) {
|
|
10912
|
+
pools.push(position.pool);
|
|
10913
|
+
}
|
|
10914
|
+
}
|
|
10915
|
+
}
|
|
10916
|
+
const pool_coins = await this.getPoolCoins(pools);
|
|
10917
|
+
const _params = [];
|
|
10918
|
+
for (const [key, value] of pool_coins.entries()) {
|
|
10919
|
+
_params.push({
|
|
10920
|
+
pool_id: key,
|
|
10921
|
+
coin_a: value[0],
|
|
10922
|
+
coin_b: value[1]
|
|
10923
|
+
});
|
|
10924
|
+
}
|
|
10925
|
+
const pool_reward_coins = await this.getPairRewarders(_params);
|
|
10926
|
+
const out = [];
|
|
10927
|
+
for (const item of positions) {
|
|
10928
|
+
const coins = pool_coins.get(item.pool) || ["", ""];
|
|
10929
|
+
const positionLiquidity = await this.getPositionLiquidity({
|
|
10930
|
+
pair: item.pool,
|
|
10931
|
+
positionId: item.pos_object_id,
|
|
10932
|
+
coinTypeA: coins[0],
|
|
10933
|
+
coinTypeB: coins[1]
|
|
10934
|
+
});
|
|
10935
|
+
const positionRewards = await this.getEarnedRewards({
|
|
10936
|
+
pool_id: item.pool,
|
|
10937
|
+
position_id: item.pos_object_id,
|
|
10938
|
+
coin_a: coins[0],
|
|
10939
|
+
coin_b: coins[1],
|
|
10940
|
+
rewards_token: pool_reward_coins.get(item.pool) || []
|
|
10941
|
+
});
|
|
10942
|
+
const positionFees = await this.getEarnedFees({
|
|
10943
|
+
pool_id: item.pool,
|
|
10944
|
+
position_id: item.pos_object_id,
|
|
10945
|
+
coin_a: coins[0],
|
|
10946
|
+
coin_b: coins[1]
|
|
10947
|
+
});
|
|
10948
|
+
out.push({
|
|
10949
|
+
position: item,
|
|
10950
|
+
liquidity: positionLiquidity,
|
|
10951
|
+
rewards: positionRewards,
|
|
10952
|
+
fees: positionFees
|
|
10953
|
+
});
|
|
10954
|
+
}
|
|
10955
|
+
return out;
|
|
10956
|
+
}
|
|
10957
|
+
buildPosition(object) {
|
|
10958
|
+
if (object.error != null || object.data?.content?.dataType !== "moveObject") {
|
|
10959
|
+
throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${object.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
|
|
10960
|
+
}
|
|
10961
|
+
const fields = getObjectFields(object);
|
|
10962
|
+
const ownerWarp = getObjectOwner(object);
|
|
10963
|
+
return {
|
|
10964
|
+
pos_object_id: fields.id.id,
|
|
10965
|
+
owner: ownerWarp.AddressOwner,
|
|
10966
|
+
pool: fields.pair_id,
|
|
10967
|
+
bin_ids: fields.bin_ids,
|
|
10968
|
+
type: ""
|
|
10969
|
+
};
|
|
10970
|
+
}
|
|
10971
|
+
// return [coin_a, coin_b]
|
|
10972
|
+
async getPoolCoins(pools) {
|
|
10973
|
+
const res = await this._sdk.fullClient.multiGetObjects({ ids: pools, options: { showContent: true } });
|
|
10974
|
+
const poolCoins = /* @__PURE__ */ new Map();
|
|
10975
|
+
res.forEach((item) => {
|
|
10976
|
+
if (item.error != null || item.data?.content?.dataType !== "moveObject") {
|
|
10977
|
+
throw new Error(`Failed to get poolCoins with err: ${item.error}`);
|
|
10978
|
+
}
|
|
10979
|
+
const type = getObjectType(item);
|
|
10980
|
+
const poolTypeFields = extractStructTagFromType(type);
|
|
10981
|
+
poolCoins.set(item.data.objectId, poolTypeFields.type_arguments);
|
|
10982
|
+
});
|
|
10983
|
+
return poolCoins;
|
|
10984
|
+
}
|
|
10985
|
+
buildPositionType() {
|
|
10986
|
+
return `${this._sdk.sdkOptions.dlmm_pool.package_id}::dlmm_position::Position`;
|
|
10987
|
+
}
|
|
10867
10988
|
async getPositionLiquidity(params) {
|
|
10868
10989
|
const tx = new Transaction12();
|
|
10869
10990
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -11022,6 +11143,7 @@ var DlmmModule = class {
|
|
|
11022
11143
|
});
|
|
11023
11144
|
return out;
|
|
11024
11145
|
}
|
|
11146
|
+
// return pool_id => reward_tokens
|
|
11025
11147
|
async getPairRewarders(params) {
|
|
11026
11148
|
let tx = new Transaction12();
|
|
11027
11149
|
for (const param of params) {
|
|
@@ -11061,6 +11183,7 @@ var DlmmModule = class {
|
|
|
11061
11183
|
item.parsedJson.tokens.contents.forEach((token) => {
|
|
11062
11184
|
pairRewards.tokens.push(token.name);
|
|
11063
11185
|
});
|
|
11186
|
+
out.set(pairRewards.pair_id, pairRewards.tokens);
|
|
11064
11187
|
}
|
|
11065
11188
|
});
|
|
11066
11189
|
return out;
|