@magmaprotocol/magma-clmm-sdk 0.5.50 → 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 +19 -2
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10896,6 +10896,95 @@ var DlmmModule = class {
|
|
|
10896
10896
|
});
|
|
10897
10897
|
return res;
|
|
10898
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
|
+
}
|
|
10899
10988
|
async getPositionLiquidity(params) {
|
|
10900
10989
|
const tx = new Transaction12();
|
|
10901
10990
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -11054,6 +11143,7 @@ var DlmmModule = class {
|
|
|
11054
11143
|
});
|
|
11055
11144
|
return out;
|
|
11056
11145
|
}
|
|
11146
|
+
// return pool_id => reward_tokens
|
|
11057
11147
|
async getPairRewarders(params) {
|
|
11058
11148
|
let tx = new Transaction12();
|
|
11059
11149
|
for (const param of params) {
|
|
@@ -11093,6 +11183,7 @@ var DlmmModule = class {
|
|
|
11093
11183
|
item.parsedJson.tokens.contents.forEach((token) => {
|
|
11094
11184
|
pairRewards.tokens.push(token.name);
|
|
11095
11185
|
});
|
|
11186
|
+
out.set(pairRewards.pair_id, pairRewards.tokens);
|
|
11096
11187
|
}
|
|
11097
11188
|
});
|
|
11098
11189
|
return out;
|