@magmaprotocol/magma-clmm-sdk 0.5.89 → 0.5.91
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 +13 -10
- package/dist/index.js +198 -125
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +198 -125
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -454,6 +454,7 @@ type ClmmConfig = {
|
|
|
454
454
|
};
|
|
455
455
|
type DlmmConfig = {
|
|
456
456
|
factory: SuiObjectIdType;
|
|
457
|
+
rewarder_global_vault: SuiObjectIdType;
|
|
457
458
|
};
|
|
458
459
|
/**
|
|
459
460
|
* Represents an event to create a liquidity mining partner.
|
|
@@ -1725,6 +1726,7 @@ type EventBin = {
|
|
|
1725
1726
|
real_bin_id: number;
|
|
1726
1727
|
};
|
|
1727
1728
|
type EventPositionLiquidity = {
|
|
1729
|
+
position_id: string;
|
|
1728
1730
|
shares: number | string;
|
|
1729
1731
|
liquidity: number | string;
|
|
1730
1732
|
x_equivalent: number | string;
|
|
@@ -3783,13 +3785,6 @@ declare class DlmmModule implements IModule {
|
|
|
3783
3785
|
createPairAddLiquidity(params: DlmmCreatePairAddLiquidityParams): Promise<Transaction>;
|
|
3784
3786
|
swap(params: DLMMSwapParams): Promise<Transaction>;
|
|
3785
3787
|
fetchBins(params: FetchBinsParams): Promise<EventBin[]>;
|
|
3786
|
-
/**
|
|
3787
|
-
* Gets a list of positions for the given account address.
|
|
3788
|
-
* @param accountAddress The account address to get positions for.
|
|
3789
|
-
* @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
3790
|
-
* @returns array of Position objects.
|
|
3791
|
-
*/
|
|
3792
|
-
getUserPositionById(positionId: string, showDisplay?: boolean): Promise<DlmmPositionInfo>;
|
|
3793
3788
|
/**
|
|
3794
3789
|
* Gets a list of positions for the given account address.
|
|
3795
3790
|
* @param accountAddress The account address to get positions for.
|
|
@@ -3800,10 +3795,18 @@ declare class DlmmModule implements IModule {
|
|
|
3800
3795
|
private buildPosition;
|
|
3801
3796
|
private getPoolCoins;
|
|
3802
3797
|
private buildPositionType;
|
|
3803
|
-
|
|
3798
|
+
getPositionsLiquidityLimit(params: GetPositionLiquidityParams[]): Promise<EventPositionLiquidity[]>;
|
|
3799
|
+
private getPositionsLiquidity;
|
|
3800
|
+
private _getPositionLiquidity;
|
|
3801
|
+
private _parsePositionLiquidity;
|
|
3804
3802
|
getPairLiquidity(params: GetPairLiquidityParams): Promise<EventPairLiquidity>;
|
|
3805
|
-
|
|
3806
|
-
|
|
3803
|
+
getEarnedFeesLimit(params: DlmmCollectFeeParams[]): Promise<DlmmEventEarnedFees[]>;
|
|
3804
|
+
private getEarnedFees;
|
|
3805
|
+
private _getEarnedFees;
|
|
3806
|
+
private _parseEarnedFees;
|
|
3807
|
+
getEarnedRewards(params: DlmmRewardsParams[]): Promise<DlmmEventEarnedRewards[]>;
|
|
3808
|
+
private _getEarnedRewards;
|
|
3809
|
+
private _parseEarnedRewards;
|
|
3807
3810
|
getPairRewarders(params: GetPairRewarderParams[]): Promise<Map<string, string[]>>;
|
|
3808
3811
|
private _getPairRewarders;
|
|
3809
3812
|
private _parsePairRewarders;
|
package/dist/index.js
CHANGED
|
@@ -10684,7 +10684,7 @@ var DlmmModule = class {
|
|
|
10684
10684
|
sender: simulationAccount.address
|
|
10685
10685
|
});
|
|
10686
10686
|
if (simulateRes.error != null) {
|
|
10687
|
-
throw new Error(`
|
|
10687
|
+
throw new Error(`fetchPairParams error code: ${simulateRes.error ?? "unknown error"}`);
|
|
10688
10688
|
}
|
|
10689
10689
|
let res = {
|
|
10690
10690
|
base_factor: 0,
|
|
@@ -10978,6 +10978,7 @@ var DlmmModule = class {
|
|
|
10978
10978
|
const args = [
|
|
10979
10979
|
tx.object(params.pair),
|
|
10980
10980
|
tx.object(dlmmConfig.factory),
|
|
10981
|
+
tx.object(dlmm_pool.config.rewarder_global_vault),
|
|
10981
10982
|
tx.object(params.positionId),
|
|
10982
10983
|
primaryCoinAInputs.targetCoin,
|
|
10983
10984
|
primaryCoinBInputs.targetCoin,
|
|
@@ -11182,7 +11183,7 @@ var DlmmModule = class {
|
|
|
11182
11183
|
sender: simulationAccount.address
|
|
11183
11184
|
});
|
|
11184
11185
|
if (simulateRes.error != null) {
|
|
11185
|
-
throw new Error(`
|
|
11186
|
+
throw new Error(`swap code: ${simulateRes.error ?? "unknown error"}`);
|
|
11186
11187
|
}
|
|
11187
11188
|
let res = [];
|
|
11188
11189
|
simulateRes.events?.forEach((item) => {
|
|
@@ -11196,65 +11197,68 @@ var DlmmModule = class {
|
|
|
11196
11197
|
});
|
|
11197
11198
|
return res.sort((a, b) => a.real_bin_id - b.real_bin_id);
|
|
11198
11199
|
}
|
|
11199
|
-
/**
|
|
11200
|
-
|
|
11201
|
-
|
|
11202
|
-
|
|
11203
|
-
|
|
11204
|
-
|
|
11205
|
-
async getUserPositionById(positionId, showDisplay = true) {
|
|
11206
|
-
|
|
11207
|
-
|
|
11208
|
-
|
|
11209
|
-
|
|
11210
|
-
|
|
11211
|
-
|
|
11212
|
-
|
|
11213
|
-
|
|
11214
|
-
|
|
11215
|
-
|
|
11216
|
-
|
|
11217
|
-
|
|
11218
|
-
|
|
11219
|
-
|
|
11220
|
-
|
|
11221
|
-
|
|
11222
|
-
|
|
11223
|
-
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
|
|
11236
|
-
|
|
11237
|
-
|
|
11238
|
-
|
|
11239
|
-
|
|
11240
|
-
|
|
11241
|
-
|
|
11242
|
-
|
|
11243
|
-
|
|
11244
|
-
|
|
11245
|
-
|
|
11246
|
-
|
|
11247
|
-
|
|
11248
|
-
|
|
11249
|
-
|
|
11250
|
-
|
|
11251
|
-
|
|
11252
|
-
|
|
11253
|
-
|
|
11254
|
-
|
|
11255
|
-
|
|
11256
|
-
|
|
11257
|
-
|
|
11200
|
+
// /**
|
|
11201
|
+
// * Gets a list of positions for the given account address.
|
|
11202
|
+
// * @param accountAddress The account address to get positions for.
|
|
11203
|
+
// * @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
11204
|
+
// * @returns array of Position objects.
|
|
11205
|
+
// */
|
|
11206
|
+
// async getUserPositionById(positionId: string, showDisplay = true): Promise<DlmmPositionInfo> {
|
|
11207
|
+
// let position
|
|
11208
|
+
// const ownerRes: any = await this._sdk.fullClient.getObject({
|
|
11209
|
+
// id: positionId,
|
|
11210
|
+
// options: { showContent: true, showType: true, showDisplay, showOwner: true },
|
|
11211
|
+
// })
|
|
11212
|
+
// const type = extractStructTagFromType(ownerRes.data.type)
|
|
11213
|
+
// if (type.full_address === this.buildPositionType()) {
|
|
11214
|
+
// position = this.buildPosition(ownerRes)
|
|
11215
|
+
// } else {
|
|
11216
|
+
// throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${ownerRes.error}`, PositionErrorCode.InvalidPositionObject)
|
|
11217
|
+
// }
|
|
11218
|
+
// const poolMap = new Set<string>()
|
|
11219
|
+
// poolMap.add(position.pool)
|
|
11220
|
+
// const pool = (await this.getPoolInfo(Array.from(poolMap)))[0]
|
|
11221
|
+
// const _params: GetPairRewarderParams[] = []
|
|
11222
|
+
// _params.push({
|
|
11223
|
+
// pool_id: pool.pool_id,
|
|
11224
|
+
// coin_a: pool.coin_a,
|
|
11225
|
+
// coin_b: pool.coin_b,
|
|
11226
|
+
// })
|
|
11227
|
+
// const pool_reward_coins = await this.getPairRewarders(_params)
|
|
11228
|
+
// // 1. Get Liquidity
|
|
11229
|
+
// // 2. Get rewards
|
|
11230
|
+
// // 3. Get fees
|
|
11231
|
+
// const positionLiquidity = await this.getPositionLiquidity({
|
|
11232
|
+
// pair: position.pool,
|
|
11233
|
+
// positionId: position.pos_object_id,
|
|
11234
|
+
// coinTypeA: pool!.coin_a,
|
|
11235
|
+
// coinTypeB: pool!.coin_b,
|
|
11236
|
+
// })
|
|
11237
|
+
// const rewards_token = pool_reward_coins.get(position.pool) || []
|
|
11238
|
+
// let positionRewards: DlmmEventEarnedRewards = { position_id: position.pos_object_id, reward: [], amount: [] }
|
|
11239
|
+
// if (rewards_token.length > 0) {
|
|
11240
|
+
// positionRewards = await this.getEarnedRewards({
|
|
11241
|
+
// pool_id: position.pool,
|
|
11242
|
+
// position_id: position.pos_object_id,
|
|
11243
|
+
// coin_a: pool!.coin_a,
|
|
11244
|
+
// coin_b: pool!.coin_b,
|
|
11245
|
+
// rewards_token: pool_reward_coins.get(position.pool) || [],
|
|
11246
|
+
// })
|
|
11247
|
+
// }
|
|
11248
|
+
// const positionFees = await this.getEarnedFees({
|
|
11249
|
+
// pool_id: position.pool,
|
|
11250
|
+
// position_id: position.pos_object_id,
|
|
11251
|
+
// coin_a: pool!.coin_a,
|
|
11252
|
+
// coin_b: pool!.coin_b,
|
|
11253
|
+
// })
|
|
11254
|
+
// return {
|
|
11255
|
+
// position,
|
|
11256
|
+
// liquidity: positionLiquidity,
|
|
11257
|
+
// rewards: positionRewards,
|
|
11258
|
+
// fees: positionFees,
|
|
11259
|
+
// contractPool: pool,
|
|
11260
|
+
// }
|
|
11261
|
+
// }
|
|
11258
11262
|
/**
|
|
11259
11263
|
* Gets a list of positions for the given account address.
|
|
11260
11264
|
* @param accountAddress The account address to get positions for.
|
|
@@ -11298,19 +11302,20 @@ var DlmmModule = class {
|
|
|
11298
11302
|
});
|
|
11299
11303
|
}
|
|
11300
11304
|
const pool_reward_coins = await this.getPairRewarders(_params);
|
|
11301
|
-
const
|
|
11305
|
+
const positionLiquidityParams = [];
|
|
11306
|
+
const dlmmRewardsParams = [];
|
|
11307
|
+
const dlmmCollectFeeParams = [];
|
|
11302
11308
|
for (const item of allPosition) {
|
|
11303
11309
|
const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
|
|
11304
|
-
|
|
11310
|
+
positionLiquidityParams.push({
|
|
11305
11311
|
pair: item.pool,
|
|
11306
11312
|
positionId: item.pos_object_id,
|
|
11307
11313
|
coinTypeA: pool.coin_a,
|
|
11308
11314
|
coinTypeB: pool.coin_b
|
|
11309
11315
|
});
|
|
11310
11316
|
const rewards_token = pool_reward_coins.get(item.pool) || [];
|
|
11311
|
-
let positionRewards = { position_id: item.pos_object_id, reward: [], amount: [] };
|
|
11312
11317
|
if (rewards_token.length > 0) {
|
|
11313
|
-
|
|
11318
|
+
dlmmRewardsParams.push({
|
|
11314
11319
|
pool_id: item.pool,
|
|
11315
11320
|
position_id: item.pos_object_id,
|
|
11316
11321
|
coin_a: pool.coin_a,
|
|
@@ -11318,16 +11323,27 @@ var DlmmModule = class {
|
|
|
11318
11323
|
rewards_token: pool_reward_coins.get(item.pool) || []
|
|
11319
11324
|
});
|
|
11320
11325
|
}
|
|
11321
|
-
|
|
11326
|
+
dlmmCollectFeeParams.push({
|
|
11322
11327
|
pool_id: item.pool,
|
|
11323
11328
|
position_id: item.pos_object_id,
|
|
11324
11329
|
coin_a: pool.coin_a,
|
|
11325
11330
|
coin_b: pool.coin_b
|
|
11326
11331
|
});
|
|
11332
|
+
}
|
|
11333
|
+
const positionsLiquidity = await this.getPositionsLiquidityLimit(positionLiquidityParams);
|
|
11334
|
+
const positionsRewards = await this.getEarnedRewards(dlmmRewardsParams);
|
|
11335
|
+
const positionsFees = await this.getEarnedFeesLimit(dlmmCollectFeeParams);
|
|
11336
|
+
const out = [];
|
|
11337
|
+
for (let i = 0; i < allPosition.length; i++) {
|
|
11338
|
+
const item = allPosition[i];
|
|
11339
|
+
const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
|
|
11340
|
+
const positionLiquidity = positionsLiquidity.find((liquidity) => liquidity.position_id === item.pos_object_id);
|
|
11341
|
+
const positionRewards = positionsRewards.find((rewards) => rewards.position_id === item.pos_object_id);
|
|
11342
|
+
const positionFees = positionsFees.find((fees) => fees.position_id === item.pos_object_id);
|
|
11327
11343
|
out.push({
|
|
11328
|
-
position:
|
|
11344
|
+
position: allPosition[i],
|
|
11329
11345
|
liquidity: positionLiquidity,
|
|
11330
|
-
rewards: positionRewards,
|
|
11346
|
+
rewards: positionRewards || { position_id: item.pos_object_id, reward: [], amount: [] },
|
|
11331
11347
|
fees: positionFees,
|
|
11332
11348
|
contractPool: pool
|
|
11333
11349
|
});
|
|
@@ -11365,9 +11381,30 @@ var DlmmModule = class {
|
|
|
11365
11381
|
buildPositionType() {
|
|
11366
11382
|
return `${this._sdk.sdkOptions.dlmm_pool.package_id}::dlmm_position::Position`;
|
|
11367
11383
|
}
|
|
11368
|
-
async
|
|
11369
|
-
const
|
|
11370
|
-
const
|
|
11384
|
+
async getPositionsLiquidityLimit(params) {
|
|
11385
|
+
const out = [];
|
|
11386
|
+
const limit = 2;
|
|
11387
|
+
for (let i = 0; i < params.length; i += limit) {
|
|
11388
|
+
if (i + limit >= params.length) {
|
|
11389
|
+
const res2 = await this.getPositionsLiquidity(params.slice(i, params.length));
|
|
11390
|
+
out.push(...res2);
|
|
11391
|
+
return out;
|
|
11392
|
+
}
|
|
11393
|
+
const res = await this.getPositionsLiquidity(params.slice(i, i + limit));
|
|
11394
|
+
out.push(...res);
|
|
11395
|
+
}
|
|
11396
|
+
return out;
|
|
11397
|
+
}
|
|
11398
|
+
async getPositionsLiquidity(params) {
|
|
11399
|
+
let tx = new import_transactions12.Transaction();
|
|
11400
|
+
for (const param of params) {
|
|
11401
|
+
tx = await this._getPositionLiquidity(param, tx);
|
|
11402
|
+
}
|
|
11403
|
+
return this._parsePositionLiquidity(tx);
|
|
11404
|
+
}
|
|
11405
|
+
async _getPositionLiquidity(params, tx) {
|
|
11406
|
+
tx = tx || new import_transactions12.Transaction();
|
|
11407
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11371
11408
|
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
11372
11409
|
const args = [tx.object(params.pair), tx.object(params.positionId)];
|
|
11373
11410
|
tx.moveCall({
|
|
@@ -11375,33 +11412,31 @@ var DlmmModule = class {
|
|
|
11375
11412
|
arguments: args,
|
|
11376
11413
|
typeArguments
|
|
11377
11414
|
});
|
|
11415
|
+
return tx;
|
|
11416
|
+
}
|
|
11417
|
+
async _parsePositionLiquidity(tx) {
|
|
11418
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11378
11419
|
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11379
11420
|
transactionBlock: tx,
|
|
11380
11421
|
sender: simulationAccount.address
|
|
11381
11422
|
});
|
|
11382
11423
|
if (simulateRes.error != null) {
|
|
11383
|
-
throw new Error(`
|
|
11424
|
+
throw new Error(`fetchPositionLiquidity error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11384
11425
|
}
|
|
11385
|
-
const out =
|
|
11386
|
-
shares: 0,
|
|
11387
|
-
liquidity: 0,
|
|
11388
|
-
x_equivalent: 0,
|
|
11389
|
-
y_equivalent: 0,
|
|
11390
|
-
bin_real_ids: [],
|
|
11391
|
-
bin_x_eq: [],
|
|
11392
|
-
bin_y_eq: [],
|
|
11393
|
-
bin_liquidity: []
|
|
11394
|
-
};
|
|
11426
|
+
const out = [];
|
|
11395
11427
|
simulateRes.events?.forEach((item) => {
|
|
11396
11428
|
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
11397
|
-
out.
|
|
11398
|
-
|
|
11399
|
-
|
|
11400
|
-
|
|
11401
|
-
|
|
11402
|
-
|
|
11403
|
-
|
|
11404
|
-
|
|
11429
|
+
out.push({
|
|
11430
|
+
position_id: item.parsedJson.position_id,
|
|
11431
|
+
shares: item.parsedJson.shares,
|
|
11432
|
+
liquidity: item.parsedJson.liquidity,
|
|
11433
|
+
x_equivalent: item.parsedJson.x_equivalent,
|
|
11434
|
+
y_equivalent: item.parsedJson.y_equivalent,
|
|
11435
|
+
bin_real_ids: item.parsedJson.bin_ids.map((id) => (0, import_calc_dlmm3.get_real_id)(id)),
|
|
11436
|
+
bin_x_eq: item.parsedJson.bin_x_eq,
|
|
11437
|
+
bin_y_eq: item.parsedJson.bin_y_eq,
|
|
11438
|
+
bin_liquidity: item.parsedJson.bin_liquidity
|
|
11439
|
+
});
|
|
11405
11440
|
}
|
|
11406
11441
|
});
|
|
11407
11442
|
return out;
|
|
@@ -11421,7 +11456,7 @@ var DlmmModule = class {
|
|
|
11421
11456
|
sender: simulationAccount.address
|
|
11422
11457
|
});
|
|
11423
11458
|
if (simulateRes.error != null) {
|
|
11424
|
-
throw new Error(`
|
|
11459
|
+
throw new Error(`getPairLiquidity error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11425
11460
|
}
|
|
11426
11461
|
const out = {
|
|
11427
11462
|
shares: 0,
|
|
@@ -11445,9 +11480,31 @@ var DlmmModule = class {
|
|
|
11445
11480
|
});
|
|
11446
11481
|
return out;
|
|
11447
11482
|
}
|
|
11483
|
+
async getEarnedFeesLimit(params) {
|
|
11484
|
+
const out = [];
|
|
11485
|
+
const limit = 2;
|
|
11486
|
+
for (let i = 0; i < params.length; i += limit) {
|
|
11487
|
+
if (i + limit >= params.length) {
|
|
11488
|
+
const res2 = await this.getEarnedFees(params.slice(i, params.length));
|
|
11489
|
+
out.push(...res2);
|
|
11490
|
+
return out;
|
|
11491
|
+
}
|
|
11492
|
+
const res = await this.getEarnedFees(params.slice(i, i + limit));
|
|
11493
|
+
out.push(...res);
|
|
11494
|
+
}
|
|
11495
|
+
return out;
|
|
11496
|
+
}
|
|
11448
11497
|
async getEarnedFees(params) {
|
|
11449
|
-
|
|
11450
|
-
|
|
11498
|
+
console.log("############ params: ", params);
|
|
11499
|
+
let tx = new import_transactions12.Transaction();
|
|
11500
|
+
for (const param of params) {
|
|
11501
|
+
tx = await this._getEarnedFees(param, tx);
|
|
11502
|
+
}
|
|
11503
|
+
return this._parseEarnedFees(tx);
|
|
11504
|
+
}
|
|
11505
|
+
async _getEarnedFees(params, tx) {
|
|
11506
|
+
tx = tx || new import_transactions12.Transaction();
|
|
11507
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11451
11508
|
const typeArguments = [params.coin_a, params.coin_b];
|
|
11452
11509
|
const args = [tx.object(params.pool_id), tx.object(params.position_id)];
|
|
11453
11510
|
tx.moveCall({
|
|
@@ -11455,34 +11512,41 @@ var DlmmModule = class {
|
|
|
11455
11512
|
arguments: args,
|
|
11456
11513
|
typeArguments
|
|
11457
11514
|
});
|
|
11515
|
+
return tx;
|
|
11516
|
+
}
|
|
11517
|
+
async _parseEarnedFees(tx) {
|
|
11518
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11458
11519
|
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11459
11520
|
transactionBlock: tx,
|
|
11460
11521
|
sender: simulationAccount.address
|
|
11461
11522
|
});
|
|
11462
|
-
const out =
|
|
11463
|
-
position_id: "",
|
|
11464
|
-
x: "",
|
|
11465
|
-
y: "",
|
|
11466
|
-
fee_x: 0,
|
|
11467
|
-
fee_y: 0
|
|
11468
|
-
};
|
|
11523
|
+
const out = [];
|
|
11469
11524
|
if (simulateRes.error != null) {
|
|
11470
11525
|
throw new Error(`fetchPairRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11471
11526
|
}
|
|
11472
11527
|
simulateRes.events?.forEach((item) => {
|
|
11473
11528
|
if (extractStructTagFromType(item.type).name === `EventEarnedFees`) {
|
|
11474
|
-
out.
|
|
11475
|
-
|
|
11476
|
-
|
|
11477
|
-
|
|
11478
|
-
|
|
11529
|
+
out.push({
|
|
11530
|
+
position_id: item.parsedJson.position_id,
|
|
11531
|
+
x: item.parsedJson.x.name,
|
|
11532
|
+
y: item.parsedJson.y.name,
|
|
11533
|
+
fee_x: item.parsedJson.fee_x,
|
|
11534
|
+
fee_y: item.parsedJson.fee_y
|
|
11535
|
+
});
|
|
11479
11536
|
}
|
|
11480
11537
|
});
|
|
11481
11538
|
return out;
|
|
11482
11539
|
}
|
|
11483
11540
|
async getEarnedRewards(params) {
|
|
11484
|
-
|
|
11485
|
-
const
|
|
11541
|
+
let tx = new import_transactions12.Transaction();
|
|
11542
|
+
for (const param of params) {
|
|
11543
|
+
tx = await this._getEarnedRewards(param, tx);
|
|
11544
|
+
}
|
|
11545
|
+
return this._parseEarnedRewards(tx);
|
|
11546
|
+
}
|
|
11547
|
+
async _getEarnedRewards(params, tx) {
|
|
11548
|
+
tx = tx || new import_transactions12.Transaction();
|
|
11549
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11486
11550
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
11487
11551
|
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
11488
11552
|
let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
|
|
@@ -11494,37 +11558,44 @@ var DlmmModule = class {
|
|
|
11494
11558
|
arguments: args,
|
|
11495
11559
|
typeArguments
|
|
11496
11560
|
});
|
|
11561
|
+
return tx;
|
|
11562
|
+
}
|
|
11563
|
+
async _parseEarnedRewards(tx) {
|
|
11564
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11497
11565
|
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11498
11566
|
transactionBlock: tx,
|
|
11499
11567
|
sender: simulationAccount.address
|
|
11500
11568
|
});
|
|
11501
|
-
const
|
|
11502
|
-
position_id: "",
|
|
11503
|
-
reward: [],
|
|
11504
|
-
amount: []
|
|
11505
|
-
};
|
|
11569
|
+
const res = [];
|
|
11506
11570
|
if (simulateRes.error != null) {
|
|
11507
11571
|
throw new Error(`getEarnedRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11508
11572
|
}
|
|
11509
11573
|
simulateRes.events?.forEach((item) => {
|
|
11510
11574
|
if (extractStructTagFromType(item.type).name === `EventEarnedRewards`) {
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
11575
|
+
res.push({
|
|
11576
|
+
position_id: item.parsedJson.position_id,
|
|
11577
|
+
reward: [item.parsedJson.reward.name],
|
|
11578
|
+
amount: [item.parsedJson.amount]
|
|
11579
|
+
});
|
|
11514
11580
|
} else if (extractStructTagFromType(item.type).name === `EventEarnedRewards2`) {
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
|
|
11581
|
+
res.push({
|
|
11582
|
+
position_id: item.parsedJson.position_id,
|
|
11583
|
+
reward: [item.parsedJson.reward1.name, item.parsedJson.reward2.name],
|
|
11584
|
+
amount: [item.parsedJson.amount1, item.parsedJson.amount2]
|
|
11585
|
+
});
|
|
11518
11586
|
} else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
|
|
11587
|
+
res.push({
|
|
11588
|
+
position_id: item.parsedJson.position_id,
|
|
11589
|
+
reward: [item.parsedJson.reward1.name, item.parsedJson.reward2.name, item.parsedJson.reward3.name],
|
|
11590
|
+
amount: [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3]
|
|
11591
|
+
});
|
|
11522
11592
|
}
|
|
11523
11593
|
});
|
|
11524
|
-
return
|
|
11594
|
+
return res;
|
|
11525
11595
|
}
|
|
11526
11596
|
// return pool_id => reward_tokens
|
|
11527
11597
|
async getPairRewarders(params) {
|
|
11598
|
+
params = [params[0]];
|
|
11528
11599
|
let tx = new import_transactions12.Transaction();
|
|
11529
11600
|
for (const param of params) {
|
|
11530
11601
|
tx = await this._getPairRewarders(param, tx);
|
|
@@ -11551,7 +11622,7 @@ var DlmmModule = class {
|
|
|
11551
11622
|
});
|
|
11552
11623
|
const out = /* @__PURE__ */ new Map();
|
|
11553
11624
|
if (simulateRes.error != null) {
|
|
11554
|
-
throw new Error(`
|
|
11625
|
+
throw new Error(`getPairReward error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11555
11626
|
}
|
|
11556
11627
|
simulateRes.events?.forEach((item) => {
|
|
11557
11628
|
if (extractStructTagFromType(item.type).name === `EventPairRewardTypes`) {
|
|
@@ -11904,7 +11975,8 @@ var SDKConfig = {
|
|
|
11904
11975
|
minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
|
|
11905
11976
|
},
|
|
11906
11977
|
dlmmConfig: {
|
|
11907
|
-
factory: ""
|
|
11978
|
+
factory: "",
|
|
11979
|
+
rewarder_global_vault: ""
|
|
11908
11980
|
},
|
|
11909
11981
|
gaugeConfig: {}
|
|
11910
11982
|
};
|
|
@@ -11990,7 +12062,8 @@ var SDKConfig2 = {
|
|
|
11990
12062
|
minter_id: "0x89435d6b2a510ba50ca23303f10e91ec058f138a88f69a43fe03cd22edb214c5"
|
|
11991
12063
|
},
|
|
11992
12064
|
dlmmConfig: {
|
|
11993
|
-
factory: ""
|
|
12065
|
+
factory: "",
|
|
12066
|
+
rewarder_global_vault: ""
|
|
11994
12067
|
}
|
|
11995
12068
|
};
|
|
11996
12069
|
var clmmTestnet = {
|