@magmaprotocol/magma-clmm-sdk 0.5.56 → 0.5.58
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 +25 -1
- package/dist/index.js +65 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1847,6 +1847,7 @@ type DlmmPositionInfo = {
|
|
|
1847
1847
|
liquidity: EventPositionLiquidity;
|
|
1848
1848
|
rewards: DlmmEventEarnedRewards;
|
|
1849
1849
|
fees: DlmmEventEarnedFees;
|
|
1850
|
+
contractPool: DlmmPoolInfo | undefined;
|
|
1850
1851
|
};
|
|
1851
1852
|
|
|
1852
1853
|
type BigNumber = Decimal.Value | number | string;
|
|
@@ -3716,6 +3717,7 @@ declare class GaugeModule implements IModule {
|
|
|
3716
3717
|
|
|
3717
3718
|
declare class DlmmModule implements IModule {
|
|
3718
3719
|
protected _sdk: MagmaClmmSDK;
|
|
3720
|
+
private readonly _cache;
|
|
3719
3721
|
constructor(sdk: MagmaClmmSDK);
|
|
3720
3722
|
get sdk(): MagmaClmmSDK;
|
|
3721
3723
|
getPoolInfo(pools: string[]): Promise<DlmmPoolInfo[]>;
|
|
@@ -3734,7 +3736,13 @@ declare class DlmmModule implements IModule {
|
|
|
3734
3736
|
createPairAddLiquidity(params: DlmmCreatePairAddLiquidityParams): Promise<Transaction>;
|
|
3735
3737
|
swap(params: DLMMSwapParams): Promise<Transaction>;
|
|
3736
3738
|
fetchBins(params: FetchBinsParams): Promise<EventBin[]>;
|
|
3737
|
-
|
|
3739
|
+
/**
|
|
3740
|
+
* Gets a list of positions for the given account address.
|
|
3741
|
+
* @param accountAddress The account address to get positions for.
|
|
3742
|
+
* @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
3743
|
+
* @returns array of Position objects.
|
|
3744
|
+
*/
|
|
3745
|
+
getUserPositions(accountAddress: string, assignPoolIds?: string[], showDisplay?: boolean): Promise<DlmmPositionInfo[]>;
|
|
3738
3746
|
private buildPosition;
|
|
3739
3747
|
private getPoolCoins;
|
|
3740
3748
|
private buildPositionType;
|
|
@@ -3745,6 +3753,22 @@ declare class DlmmModule implements IModule {
|
|
|
3745
3753
|
getPairRewarders(params: GetPairRewarderParams[]): Promise<Map<string, string[]>>;
|
|
3746
3754
|
private _getPairRewarders;
|
|
3747
3755
|
private _parsePairRewarders;
|
|
3756
|
+
/**
|
|
3757
|
+
* Updates the cache for the given key.
|
|
3758
|
+
*
|
|
3759
|
+
* @param key The key of the cache entry to update.
|
|
3760
|
+
* @param data The data to store in the cache.
|
|
3761
|
+
* @param time The time in minutes after which the cache entry should expire.
|
|
3762
|
+
*/
|
|
3763
|
+
updateCache(key: string, data: SuiResource, time?: number): void;
|
|
3764
|
+
/**
|
|
3765
|
+
* Gets the cache entry for the given key.
|
|
3766
|
+
*
|
|
3767
|
+
* @param key The key of the cache entry to get.
|
|
3768
|
+
* @param forceRefresh Whether to force a refresh of the cache entry.
|
|
3769
|
+
* @returns The cache entry for the given key, or undefined if the cache entry does not exist or is expired.
|
|
3770
|
+
*/
|
|
3771
|
+
getCache<T>(key: string, forceRefresh?: boolean): T | undefined;
|
|
3748
3772
|
}
|
|
3749
3773
|
|
|
3750
3774
|
/**
|
package/dist/index.js
CHANGED
|
@@ -10728,6 +10728,7 @@ var import_calc_dlmm3 = require("@magmaprotocol/calc_dlmm");
|
|
|
10728
10728
|
var import_decimal13 = __toESM(require("decimal.js"));
|
|
10729
10729
|
var DlmmModule = class {
|
|
10730
10730
|
_sdk;
|
|
10731
|
+
_cache = {};
|
|
10731
10732
|
constructor(sdk) {
|
|
10732
10733
|
this._sdk = sdk;
|
|
10733
10734
|
}
|
|
@@ -11114,20 +11115,32 @@ var DlmmModule = class {
|
|
|
11114
11115
|
});
|
|
11115
11116
|
return res;
|
|
11116
11117
|
}
|
|
11117
|
-
|
|
11118
|
-
|
|
11118
|
+
/**
|
|
11119
|
+
* Gets a list of positions for the given account address.
|
|
11120
|
+
* @param accountAddress The account address to get positions for.
|
|
11121
|
+
* @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
11122
|
+
* @returns array of Position objects.
|
|
11123
|
+
*/
|
|
11124
|
+
async getUserPositions(accountAddress, assignPoolIds = [], showDisplay = true) {
|
|
11125
|
+
const allPosition = [];
|
|
11126
|
+
const ownerRes = await this._sdk.fullClient.getOwnedObjectsByPage(accountAddress, {
|
|
11119
11127
|
options: { showType: true, showContent: true, showDisplay, showOwner: true },
|
|
11120
11128
|
filter: { Package: this._sdk.sdkOptions.dlmm_pool.package_id }
|
|
11121
11129
|
});
|
|
11122
|
-
const
|
|
11130
|
+
const hasAssignPoolIds = assignPoolIds.length > 0;
|
|
11123
11131
|
const pools = [];
|
|
11124
11132
|
for (const item of ownerRes.data) {
|
|
11125
11133
|
const type = extractStructTagFromType(item.data.type);
|
|
11126
11134
|
if (type.full_address === this.buildPositionType()) {
|
|
11127
11135
|
const position = this.buildPosition(item);
|
|
11128
|
-
|
|
11129
|
-
|
|
11130
|
-
|
|
11136
|
+
const cacheKey = `${position.pos_object_id}_getPositionList`;
|
|
11137
|
+
this.updateCache(cacheKey, position, cacheTime24h);
|
|
11138
|
+
if (hasAssignPoolIds) {
|
|
11139
|
+
if (assignPoolIds.includes(position.pool)) {
|
|
11140
|
+
allPosition.push(position);
|
|
11141
|
+
}
|
|
11142
|
+
} else {
|
|
11143
|
+
allPosition.push(position);
|
|
11131
11144
|
}
|
|
11132
11145
|
}
|
|
11133
11146
|
}
|
|
@@ -11140,9 +11153,16 @@ var DlmmModule = class {
|
|
|
11140
11153
|
coin_b: value[1]
|
|
11141
11154
|
});
|
|
11142
11155
|
}
|
|
11156
|
+
const poolMap = /* @__PURE__ */ new Set();
|
|
11157
|
+
for (const item of allPosition) {
|
|
11158
|
+
poolMap.add(item.pool);
|
|
11159
|
+
}
|
|
11160
|
+
const poolList = await this.getPoolInfo(Array.from(poolMap));
|
|
11161
|
+
this.updateCache(`${DlmmScript}_positionList_poolList`, poolList, cacheTime24h);
|
|
11143
11162
|
const pool_reward_coins = await this.getPairRewarders(_params);
|
|
11144
11163
|
const out = [];
|
|
11145
|
-
for (const item of
|
|
11164
|
+
for (const item of allPosition) {
|
|
11165
|
+
const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
|
|
11146
11166
|
const coins = pool_coins.get(item.pool) || ["", ""];
|
|
11147
11167
|
const positionLiquidity = await this.getPositionLiquidity({
|
|
11148
11168
|
pair: item.pool,
|
|
@@ -11151,7 +11171,7 @@ var DlmmModule = class {
|
|
|
11151
11171
|
coinTypeB: coins[1]
|
|
11152
11172
|
});
|
|
11153
11173
|
const rewards_token = pool_reward_coins.get(item.pool) || [];
|
|
11154
|
-
let positionRewards = { position_id: item.
|
|
11174
|
+
let positionRewards = { position_id: item.pos_object_id, reward: [], amount: [] };
|
|
11155
11175
|
if (rewards_token.length > 0) {
|
|
11156
11176
|
positionRewards = await this.getEarnedRewards({
|
|
11157
11177
|
pool_id: item.pool,
|
|
@@ -11171,7 +11191,8 @@ var DlmmModule = class {
|
|
|
11171
11191
|
position: item,
|
|
11172
11192
|
liquidity: positionLiquidity,
|
|
11173
11193
|
rewards: positionRewards,
|
|
11174
|
-
fees: positionFees
|
|
11194
|
+
fees: positionFees,
|
|
11195
|
+
contractPool: pool
|
|
11175
11196
|
});
|
|
11176
11197
|
}
|
|
11177
11198
|
return out;
|
|
@@ -11410,6 +11431,41 @@ var DlmmModule = class {
|
|
|
11410
11431
|
});
|
|
11411
11432
|
return out;
|
|
11412
11433
|
}
|
|
11434
|
+
/**
|
|
11435
|
+
* Updates the cache for the given key.
|
|
11436
|
+
*
|
|
11437
|
+
* @param key The key of the cache entry to update.
|
|
11438
|
+
* @param data The data to store in the cache.
|
|
11439
|
+
* @param time The time in minutes after which the cache entry should expire.
|
|
11440
|
+
*/
|
|
11441
|
+
updateCache(key, data, time = cacheTime5min) {
|
|
11442
|
+
let cacheData = this._cache[key];
|
|
11443
|
+
if (cacheData) {
|
|
11444
|
+
cacheData.overdueTime = getFutureTime(time);
|
|
11445
|
+
cacheData.value = data;
|
|
11446
|
+
} else {
|
|
11447
|
+
cacheData = new CachedContent(data, getFutureTime(time));
|
|
11448
|
+
}
|
|
11449
|
+
this._cache[key] = cacheData;
|
|
11450
|
+
}
|
|
11451
|
+
/**
|
|
11452
|
+
* Gets the cache entry for the given key.
|
|
11453
|
+
*
|
|
11454
|
+
* @param key The key of the cache entry to get.
|
|
11455
|
+
* @param forceRefresh Whether to force a refresh of the cache entry.
|
|
11456
|
+
* @returns The cache entry for the given key, or undefined if the cache entry does not exist or is expired.
|
|
11457
|
+
*/
|
|
11458
|
+
getCache(key, forceRefresh = false) {
|
|
11459
|
+
const cacheData = this._cache[key];
|
|
11460
|
+
const isValid = cacheData?.isValid();
|
|
11461
|
+
if (!forceRefresh && isValid) {
|
|
11462
|
+
return cacheData.value;
|
|
11463
|
+
}
|
|
11464
|
+
if (!isValid) {
|
|
11465
|
+
delete this._cache[key];
|
|
11466
|
+
}
|
|
11467
|
+
return void 0;
|
|
11468
|
+
}
|
|
11413
11469
|
};
|
|
11414
11470
|
|
|
11415
11471
|
// src/sdk.ts
|