@magmaprotocol/magma-clmm-sdk 0.5.89 → 0.5.90
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 +11 -10
- package/dist/index.js +162 -119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +162 -119
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10765,6 +10765,7 @@ var DlmmModule = class {
|
|
|
10765
10765
|
const args = [
|
|
10766
10766
|
tx.object(params.pair),
|
|
10767
10767
|
tx.object(dlmmConfig.factory),
|
|
10768
|
+
tx.object(dlmm_pool.config.rewarder_global_vault),
|
|
10768
10769
|
tx.object(params.positionId),
|
|
10769
10770
|
primaryCoinAInputs.targetCoin,
|
|
10770
10771
|
primaryCoinBInputs.targetCoin,
|
|
@@ -10983,65 +10984,68 @@ var DlmmModule = class {
|
|
|
10983
10984
|
});
|
|
10984
10985
|
return res.sort((a, b) => a.real_bin_id - b.real_bin_id);
|
|
10985
10986
|
}
|
|
10986
|
-
/**
|
|
10987
|
-
|
|
10988
|
-
|
|
10989
|
-
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
async getUserPositionById(positionId, showDisplay = true) {
|
|
10993
|
-
|
|
10994
|
-
|
|
10995
|
-
|
|
10996
|
-
|
|
10997
|
-
|
|
10998
|
-
|
|
10999
|
-
|
|
11000
|
-
|
|
11001
|
-
|
|
11002
|
-
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
|
|
11007
|
-
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11011
|
-
|
|
11012
|
-
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
10987
|
+
// /**
|
|
10988
|
+
// * Gets a list of positions for the given account address.
|
|
10989
|
+
// * @param accountAddress The account address to get positions for.
|
|
10990
|
+
// * @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
10991
|
+
// * @returns array of Position objects.
|
|
10992
|
+
// */
|
|
10993
|
+
// async getUserPositionById(positionId: string, showDisplay = true): Promise<DlmmPositionInfo> {
|
|
10994
|
+
// let position
|
|
10995
|
+
// const ownerRes: any = await this._sdk.fullClient.getObject({
|
|
10996
|
+
// id: positionId,
|
|
10997
|
+
// options: { showContent: true, showType: true, showDisplay, showOwner: true },
|
|
10998
|
+
// })
|
|
10999
|
+
// const type = extractStructTagFromType(ownerRes.data.type)
|
|
11000
|
+
// if (type.full_address === this.buildPositionType()) {
|
|
11001
|
+
// position = this.buildPosition(ownerRes)
|
|
11002
|
+
// } else {
|
|
11003
|
+
// throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${ownerRes.error}`, PositionErrorCode.InvalidPositionObject)
|
|
11004
|
+
// }
|
|
11005
|
+
// const poolMap = new Set<string>()
|
|
11006
|
+
// poolMap.add(position.pool)
|
|
11007
|
+
// const pool = (await this.getPoolInfo(Array.from(poolMap)))[0]
|
|
11008
|
+
// const _params: GetPairRewarderParams[] = []
|
|
11009
|
+
// _params.push({
|
|
11010
|
+
// pool_id: pool.pool_id,
|
|
11011
|
+
// coin_a: pool.coin_a,
|
|
11012
|
+
// coin_b: pool.coin_b,
|
|
11013
|
+
// })
|
|
11014
|
+
// const pool_reward_coins = await this.getPairRewarders(_params)
|
|
11015
|
+
// // 1. Get Liquidity
|
|
11016
|
+
// // 2. Get rewards
|
|
11017
|
+
// // 3. Get fees
|
|
11018
|
+
// const positionLiquidity = await this.getPositionLiquidity({
|
|
11019
|
+
// pair: position.pool,
|
|
11020
|
+
// positionId: position.pos_object_id,
|
|
11021
|
+
// coinTypeA: pool!.coin_a,
|
|
11022
|
+
// coinTypeB: pool!.coin_b,
|
|
11023
|
+
// })
|
|
11024
|
+
// const rewards_token = pool_reward_coins.get(position.pool) || []
|
|
11025
|
+
// let positionRewards: DlmmEventEarnedRewards = { position_id: position.pos_object_id, reward: [], amount: [] }
|
|
11026
|
+
// if (rewards_token.length > 0) {
|
|
11027
|
+
// positionRewards = await this.getEarnedRewards({
|
|
11028
|
+
// pool_id: position.pool,
|
|
11029
|
+
// position_id: position.pos_object_id,
|
|
11030
|
+
// coin_a: pool!.coin_a,
|
|
11031
|
+
// coin_b: pool!.coin_b,
|
|
11032
|
+
// rewards_token: pool_reward_coins.get(position.pool) || [],
|
|
11033
|
+
// })
|
|
11034
|
+
// }
|
|
11035
|
+
// const positionFees = await this.getEarnedFees({
|
|
11036
|
+
// pool_id: position.pool,
|
|
11037
|
+
// position_id: position.pos_object_id,
|
|
11038
|
+
// coin_a: pool!.coin_a,
|
|
11039
|
+
// coin_b: pool!.coin_b,
|
|
11040
|
+
// })
|
|
11041
|
+
// return {
|
|
11042
|
+
// position,
|
|
11043
|
+
// liquidity: positionLiquidity,
|
|
11044
|
+
// rewards: positionRewards,
|
|
11045
|
+
// fees: positionFees,
|
|
11046
|
+
// contractPool: pool,
|
|
11047
|
+
// }
|
|
11048
|
+
// }
|
|
11045
11049
|
/**
|
|
11046
11050
|
* Gets a list of positions for the given account address.
|
|
11047
11051
|
* @param accountAddress The account address to get positions for.
|
|
@@ -11085,19 +11089,20 @@ var DlmmModule = class {
|
|
|
11085
11089
|
});
|
|
11086
11090
|
}
|
|
11087
11091
|
const pool_reward_coins = await this.getPairRewarders(_params);
|
|
11088
|
-
const
|
|
11092
|
+
const positionLiquidityParams = [];
|
|
11093
|
+
const dlmmRewardsParams = [];
|
|
11094
|
+
const dlmmCollectFeeParams = [];
|
|
11089
11095
|
for (const item of allPosition) {
|
|
11090
11096
|
const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
|
|
11091
|
-
|
|
11097
|
+
positionLiquidityParams.push({
|
|
11092
11098
|
pair: item.pool,
|
|
11093
11099
|
positionId: item.pos_object_id,
|
|
11094
11100
|
coinTypeA: pool.coin_a,
|
|
11095
11101
|
coinTypeB: pool.coin_b
|
|
11096
11102
|
});
|
|
11097
11103
|
const rewards_token = pool_reward_coins.get(item.pool) || [];
|
|
11098
|
-
let positionRewards = { position_id: item.pos_object_id, reward: [], amount: [] };
|
|
11099
11104
|
if (rewards_token.length > 0) {
|
|
11100
|
-
|
|
11105
|
+
dlmmRewardsParams.push({
|
|
11101
11106
|
pool_id: item.pool,
|
|
11102
11107
|
position_id: item.pos_object_id,
|
|
11103
11108
|
coin_a: pool.coin_a,
|
|
@@ -11105,16 +11110,27 @@ var DlmmModule = class {
|
|
|
11105
11110
|
rewards_token: pool_reward_coins.get(item.pool) || []
|
|
11106
11111
|
});
|
|
11107
11112
|
}
|
|
11108
|
-
|
|
11113
|
+
dlmmCollectFeeParams.push({
|
|
11109
11114
|
pool_id: item.pool,
|
|
11110
11115
|
position_id: item.pos_object_id,
|
|
11111
11116
|
coin_a: pool.coin_a,
|
|
11112
11117
|
coin_b: pool.coin_b
|
|
11113
11118
|
});
|
|
11119
|
+
}
|
|
11120
|
+
const positionsLiquidity = await this.getPositionLiquidity(positionLiquidityParams);
|
|
11121
|
+
const positionsRewards = await this.getEarnedRewards(dlmmRewardsParams);
|
|
11122
|
+
const positionsFees = await this.getEarnedFees(dlmmCollectFeeParams);
|
|
11123
|
+
const out = [];
|
|
11124
|
+
for (let i = 0; i < allPosition.length; i++) {
|
|
11125
|
+
const item = allPosition[i];
|
|
11126
|
+
const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
|
|
11127
|
+
const positionLiquidity = positionsLiquidity.find((liquidity) => liquidity.position_id === item.pos_object_id);
|
|
11128
|
+
const positionRewards = positionsRewards.find((rewards) => rewards.position_id === item.pos_object_id);
|
|
11129
|
+
const positionFees = positionsFees.find((fees) => fees.position_id === item.pos_object_id);
|
|
11114
11130
|
out.push({
|
|
11115
|
-
position:
|
|
11131
|
+
position: allPosition[i],
|
|
11116
11132
|
liquidity: positionLiquidity,
|
|
11117
|
-
rewards: positionRewards,
|
|
11133
|
+
rewards: positionRewards || { position_id: item.pos_object_id, reward: [], amount: [] },
|
|
11118
11134
|
fees: positionFees,
|
|
11119
11135
|
contractPool: pool
|
|
11120
11136
|
});
|
|
@@ -11153,8 +11169,15 @@ var DlmmModule = class {
|
|
|
11153
11169
|
return `${this._sdk.sdkOptions.dlmm_pool.package_id}::dlmm_position::Position`;
|
|
11154
11170
|
}
|
|
11155
11171
|
async getPositionLiquidity(params) {
|
|
11156
|
-
|
|
11157
|
-
const
|
|
11172
|
+
let tx = new Transaction12();
|
|
11173
|
+
for (const param of params) {
|
|
11174
|
+
tx = await this._getPositionLiquidity(param, tx);
|
|
11175
|
+
}
|
|
11176
|
+
return this._parsePositionLiquidity(tx);
|
|
11177
|
+
}
|
|
11178
|
+
async _getPositionLiquidity(params, tx) {
|
|
11179
|
+
tx = tx || new Transaction12();
|
|
11180
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11158
11181
|
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
11159
11182
|
const args = [tx.object(params.pair), tx.object(params.positionId)];
|
|
11160
11183
|
tx.moveCall({
|
|
@@ -11162,6 +11185,10 @@ var DlmmModule = class {
|
|
|
11162
11185
|
arguments: args,
|
|
11163
11186
|
typeArguments
|
|
11164
11187
|
});
|
|
11188
|
+
return tx;
|
|
11189
|
+
}
|
|
11190
|
+
async _parsePositionLiquidity(tx) {
|
|
11191
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11165
11192
|
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11166
11193
|
transactionBlock: tx,
|
|
11167
11194
|
sender: simulationAccount.address
|
|
@@ -11169,26 +11196,20 @@ var DlmmModule = class {
|
|
|
11169
11196
|
if (simulateRes.error != null) {
|
|
11170
11197
|
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11171
11198
|
}
|
|
11172
|
-
const out =
|
|
11173
|
-
shares: 0,
|
|
11174
|
-
liquidity: 0,
|
|
11175
|
-
x_equivalent: 0,
|
|
11176
|
-
y_equivalent: 0,
|
|
11177
|
-
bin_real_ids: [],
|
|
11178
|
-
bin_x_eq: [],
|
|
11179
|
-
bin_y_eq: [],
|
|
11180
|
-
bin_liquidity: []
|
|
11181
|
-
};
|
|
11199
|
+
const out = [];
|
|
11182
11200
|
simulateRes.events?.forEach((item) => {
|
|
11183
11201
|
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
11184
|
-
out.
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11202
|
+
out.push({
|
|
11203
|
+
position_id: item.parsedJson.position_id,
|
|
11204
|
+
shares: item.parsedJson.shares,
|
|
11205
|
+
liquidity: item.parsedJson.liquidity,
|
|
11206
|
+
x_equivalent: item.parsedJson.x_equivalent,
|
|
11207
|
+
y_equivalent: item.parsedJson.y_equivalent,
|
|
11208
|
+
bin_real_ids: item.parsedJson.bin_ids.map((id) => get_real_id(id)),
|
|
11209
|
+
bin_x_eq: item.parsedJson.bin_x_eq,
|
|
11210
|
+
bin_y_eq: item.parsedJson.bin_y_eq,
|
|
11211
|
+
bin_liquidity: item.parsedJson.bin_liquidity
|
|
11212
|
+
});
|
|
11192
11213
|
}
|
|
11193
11214
|
});
|
|
11194
11215
|
return out;
|
|
@@ -11233,8 +11254,15 @@ var DlmmModule = class {
|
|
|
11233
11254
|
return out;
|
|
11234
11255
|
}
|
|
11235
11256
|
async getEarnedFees(params) {
|
|
11236
|
-
|
|
11237
|
-
const
|
|
11257
|
+
let tx = new Transaction12();
|
|
11258
|
+
for (const param of params) {
|
|
11259
|
+
tx = await this._getEarnedFees(param, tx);
|
|
11260
|
+
}
|
|
11261
|
+
return this._parseEarnedFees(tx);
|
|
11262
|
+
}
|
|
11263
|
+
async _getEarnedFees(params, tx) {
|
|
11264
|
+
tx = tx || new Transaction12();
|
|
11265
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11238
11266
|
const typeArguments = [params.coin_a, params.coin_b];
|
|
11239
11267
|
const args = [tx.object(params.pool_id), tx.object(params.position_id)];
|
|
11240
11268
|
tx.moveCall({
|
|
@@ -11242,34 +11270,41 @@ var DlmmModule = class {
|
|
|
11242
11270
|
arguments: args,
|
|
11243
11271
|
typeArguments
|
|
11244
11272
|
});
|
|
11273
|
+
return tx;
|
|
11274
|
+
}
|
|
11275
|
+
async _parseEarnedFees(tx) {
|
|
11276
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11245
11277
|
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11246
11278
|
transactionBlock: tx,
|
|
11247
11279
|
sender: simulationAccount.address
|
|
11248
11280
|
});
|
|
11249
|
-
const out =
|
|
11250
|
-
position_id: "",
|
|
11251
|
-
x: "",
|
|
11252
|
-
y: "",
|
|
11253
|
-
fee_x: 0,
|
|
11254
|
-
fee_y: 0
|
|
11255
|
-
};
|
|
11281
|
+
const out = [];
|
|
11256
11282
|
if (simulateRes.error != null) {
|
|
11257
11283
|
throw new Error(`fetchPairRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11258
11284
|
}
|
|
11259
11285
|
simulateRes.events?.forEach((item) => {
|
|
11260
11286
|
if (extractStructTagFromType(item.type).name === `EventEarnedFees`) {
|
|
11261
|
-
out.
|
|
11262
|
-
|
|
11263
|
-
|
|
11264
|
-
|
|
11265
|
-
|
|
11287
|
+
out.push({
|
|
11288
|
+
position_id: item.parsedJson.position_id,
|
|
11289
|
+
x: item.parsedJson.x.name,
|
|
11290
|
+
y: item.parsedJson.y.name,
|
|
11291
|
+
fee_x: item.parsedJson.fee_x,
|
|
11292
|
+
fee_y: item.parsedJson.fee_y
|
|
11293
|
+
});
|
|
11266
11294
|
}
|
|
11267
11295
|
});
|
|
11268
11296
|
return out;
|
|
11269
11297
|
}
|
|
11270
11298
|
async getEarnedRewards(params) {
|
|
11271
|
-
|
|
11272
|
-
const
|
|
11299
|
+
let tx = new Transaction12();
|
|
11300
|
+
for (const param of params) {
|
|
11301
|
+
tx = await this._getEarnedRewards(param, tx);
|
|
11302
|
+
}
|
|
11303
|
+
return this._parseEarnedRewards(tx);
|
|
11304
|
+
}
|
|
11305
|
+
async _getEarnedRewards(params, tx) {
|
|
11306
|
+
tx = tx || new Transaction12();
|
|
11307
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11273
11308
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
11274
11309
|
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
11275
11310
|
let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
|
|
@@ -11281,34 +11316,40 @@ var DlmmModule = class {
|
|
|
11281
11316
|
arguments: args,
|
|
11282
11317
|
typeArguments
|
|
11283
11318
|
});
|
|
11319
|
+
return tx;
|
|
11320
|
+
}
|
|
11321
|
+
async _parseEarnedRewards(tx) {
|
|
11322
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11284
11323
|
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11285
11324
|
transactionBlock: tx,
|
|
11286
11325
|
sender: simulationAccount.address
|
|
11287
11326
|
});
|
|
11288
|
-
const
|
|
11289
|
-
position_id: "",
|
|
11290
|
-
reward: [],
|
|
11291
|
-
amount: []
|
|
11292
|
-
};
|
|
11327
|
+
const res = [];
|
|
11293
11328
|
if (simulateRes.error != null) {
|
|
11294
11329
|
throw new Error(`getEarnedRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11295
11330
|
}
|
|
11296
11331
|
simulateRes.events?.forEach((item) => {
|
|
11297
11332
|
if (extractStructTagFromType(item.type).name === `EventEarnedRewards`) {
|
|
11298
|
-
|
|
11299
|
-
|
|
11300
|
-
|
|
11333
|
+
res.push({
|
|
11334
|
+
position_id: item.parsedJson.position_id,
|
|
11335
|
+
reward: [item.parsedJson.reward.name],
|
|
11336
|
+
amount: [item.parsedJson.amount]
|
|
11337
|
+
});
|
|
11301
11338
|
} else if (extractStructTagFromType(item.type).name === `EventEarnedRewards2`) {
|
|
11302
|
-
|
|
11303
|
-
|
|
11304
|
-
|
|
11339
|
+
res.push({
|
|
11340
|
+
position_id: item.parsedJson.position_id,
|
|
11341
|
+
reward: [item.parsedJson.reward1.name, item.parsedJson.reward2.name],
|
|
11342
|
+
amount: [item.parsedJson.amount1, item.parsedJson.amount2]
|
|
11343
|
+
});
|
|
11305
11344
|
} else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
|
|
11306
|
-
|
|
11307
|
-
|
|
11308
|
-
|
|
11345
|
+
res.push({
|
|
11346
|
+
position_id: item.parsedJson.position_id,
|
|
11347
|
+
reward: [item.parsedJson.reward1.name, item.parsedJson.reward2.name, item.parsedJson.reward3.name],
|
|
11348
|
+
amount: [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3]
|
|
11349
|
+
});
|
|
11309
11350
|
}
|
|
11310
11351
|
});
|
|
11311
|
-
return
|
|
11352
|
+
return res;
|
|
11312
11353
|
}
|
|
11313
11354
|
// return pool_id => reward_tokens
|
|
11314
11355
|
async getPairRewarders(params) {
|
|
@@ -11691,7 +11732,8 @@ var SDKConfig = {
|
|
|
11691
11732
|
minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
|
|
11692
11733
|
},
|
|
11693
11734
|
dlmmConfig: {
|
|
11694
|
-
factory: ""
|
|
11735
|
+
factory: "",
|
|
11736
|
+
rewarder_global_vault: ""
|
|
11695
11737
|
},
|
|
11696
11738
|
gaugeConfig: {}
|
|
11697
11739
|
};
|
|
@@ -11777,7 +11819,8 @@ var SDKConfig2 = {
|
|
|
11777
11819
|
minter_id: "0x89435d6b2a510ba50ca23303f10e91ec058f138a88f69a43fe03cd22edb214c5"
|
|
11778
11820
|
},
|
|
11779
11821
|
dlmmConfig: {
|
|
11780
|
-
factory: ""
|
|
11822
|
+
factory: "",
|
|
11823
|
+
rewarder_global_vault: ""
|
|
11781
11824
|
}
|
|
11782
11825
|
};
|
|
11783
11826
|
var clmmTestnet = {
|