@magmaprotocol/magma-clmm-sdk 0.5.62 → 0.5.64
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 +7 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10897,6 +10897,65 @@ var DlmmModule = class {
|
|
|
10897
10897
|
});
|
|
10898
10898
|
return res;
|
|
10899
10899
|
}
|
|
10900
|
+
/**
|
|
10901
|
+
* Gets a list of positions for the given account address.
|
|
10902
|
+
* @param accountAddress The account address to get positions for.
|
|
10903
|
+
* @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
10904
|
+
* @returns array of Position objects.
|
|
10905
|
+
*/
|
|
10906
|
+
async getUserPositionById(positionId, showDisplay = true) {
|
|
10907
|
+
let position;
|
|
10908
|
+
const ownerRes = await this._sdk.fullClient.getObject({
|
|
10909
|
+
id: positionId,
|
|
10910
|
+
options: { showContent: true, showType: true, showDisplay, showOwner: true }
|
|
10911
|
+
});
|
|
10912
|
+
const type = extractStructTagFromType(ownerRes.data.type);
|
|
10913
|
+
if (type.full_address === this.buildPositionType()) {
|
|
10914
|
+
position = this.buildPosition(ownerRes);
|
|
10915
|
+
} else {
|
|
10916
|
+
throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${ownerRes.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
|
|
10917
|
+
}
|
|
10918
|
+
const poolMap = /* @__PURE__ */ new Set();
|
|
10919
|
+
poolMap.add(position.pool);
|
|
10920
|
+
const pool = (await this.getPoolInfo(Array.from(poolMap)))[0];
|
|
10921
|
+
const _params = [];
|
|
10922
|
+
_params.push({
|
|
10923
|
+
pool_id: pool.pool_id,
|
|
10924
|
+
coin_a: pool.coin_a,
|
|
10925
|
+
coin_b: pool.coin_b
|
|
10926
|
+
});
|
|
10927
|
+
const pool_reward_coins = await this.getPairRewarders(_params);
|
|
10928
|
+
const positionLiquidity = await this.getPositionLiquidity({
|
|
10929
|
+
pair: position.pool,
|
|
10930
|
+
positionId: position.pos_object_id,
|
|
10931
|
+
coinTypeA: pool?.coin_a,
|
|
10932
|
+
coinTypeB: pool?.coin_b
|
|
10933
|
+
});
|
|
10934
|
+
const rewards_token = pool_reward_coins.get(position.pool) || [];
|
|
10935
|
+
let positionRewards = { position_id: position.pos_object_id, reward: [], amount: [] };
|
|
10936
|
+
if (rewards_token.length > 0) {
|
|
10937
|
+
positionRewards = await this.getEarnedRewards({
|
|
10938
|
+
pool_id: position.pool,
|
|
10939
|
+
position_id: position.pos_object_id,
|
|
10940
|
+
coin_a: pool?.coin_a,
|
|
10941
|
+
coin_b: pool?.coin_b,
|
|
10942
|
+
rewards_token: pool_reward_coins.get(position.pool) || []
|
|
10943
|
+
});
|
|
10944
|
+
}
|
|
10945
|
+
const positionFees = await this.getEarnedFees({
|
|
10946
|
+
pool_id: position.pool,
|
|
10947
|
+
position_id: position.pos_object_id,
|
|
10948
|
+
coin_a: pool?.coin_a,
|
|
10949
|
+
coin_b: pool?.coin_b
|
|
10950
|
+
});
|
|
10951
|
+
return {
|
|
10952
|
+
position,
|
|
10953
|
+
liquidity: positionLiquidity,
|
|
10954
|
+
rewards: positionRewards,
|
|
10955
|
+
fees: positionFees,
|
|
10956
|
+
contractPool: pool
|
|
10957
|
+
};
|
|
10958
|
+
}
|
|
10900
10959
|
/**
|
|
10901
10960
|
* Gets a list of positions for the given account address.
|
|
10902
10961
|
* @param accountAddress The account address to get positions for.
|