@magmaprotocol/magma-clmm-sdk 0.5.8 → 0.5.10
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 +41 -1
- package/dist/index.js +206 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +204 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -301,6 +301,8 @@ var ClmmIntegrateUtilsModule = "utils";
|
|
|
301
301
|
var VotingEscrow = "voting_escrow";
|
|
302
302
|
var Voter = "voter";
|
|
303
303
|
var RewardDistributor = "reward_distributor";
|
|
304
|
+
var Gauge = "gauge";
|
|
305
|
+
var Minter = "minter";
|
|
304
306
|
var CoinInfoAddress = "0x1::coin::CoinInfo";
|
|
305
307
|
var CoinStoreAddress = "0x1::coin::CoinStore";
|
|
306
308
|
var DeepbookCustodianV2Moudle = "custodian_v2";
|
|
@@ -3014,7 +3016,6 @@ var _TransactionUtil = class {
|
|
|
3014
3016
|
static buildVoteTransaction(sdk, params) {
|
|
3015
3017
|
const tx = new Transaction();
|
|
3016
3018
|
tx.setSender(sdk.senderAddress);
|
|
3017
|
-
tx.setGasBudget(1e8);
|
|
3018
3019
|
const { integrate } = sdk.sdkOptions;
|
|
3019
3020
|
const { distribution_cfg, voting_escrow_id, magma_token, voter_id } = getPackagerConfigs(sdk.sdkOptions.magma_config);
|
|
3020
3021
|
const typeArguments = [magma_token];
|
|
@@ -7245,6 +7246,25 @@ var LockModule = class {
|
|
|
7245
7246
|
}
|
|
7246
7247
|
return TransactionUtil.buildPoke(this.sdk, params);
|
|
7247
7248
|
}
|
|
7249
|
+
async addBribeReward(params) {
|
|
7250
|
+
if (this._sdk.senderAddress.length === 0) {
|
|
7251
|
+
throw Error("this config sdk senderAddress is empty");
|
|
7252
|
+
}
|
|
7253
|
+
const tx = new Transaction9();
|
|
7254
|
+
tx.setSender(this.sdk.senderAddress);
|
|
7255
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
7256
|
+
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7257
|
+
const typeArguments = [magma_token, params.coinType];
|
|
7258
|
+
const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
7259
|
+
const coinInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.amount), params.coinType, false, true);
|
|
7260
|
+
const args = [tx.object(voter_id), coinInput.targetCoin, tx.object(CLOCK_ADDRESS)];
|
|
7261
|
+
tx.moveCall({
|
|
7262
|
+
target: `${integrate.published_at}::${Voter}::add_bribe_reward`,
|
|
7263
|
+
typeArguments,
|
|
7264
|
+
arguments: args
|
|
7265
|
+
});
|
|
7266
|
+
return tx;
|
|
7267
|
+
}
|
|
7248
7268
|
async claimVotingBribe(locks, incentive_tokens) {
|
|
7249
7269
|
if (this._sdk.senderAddress.length === 0) {
|
|
7250
7270
|
throw Error("this config sdk senderAddress is empty");
|
|
@@ -7489,14 +7509,14 @@ var LockModule = class {
|
|
|
7489
7509
|
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7490
7510
|
const typeArguments = [magma_token];
|
|
7491
7511
|
const args = [tx.object(voter_id), tx.object(lock_id)];
|
|
7512
|
+
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
7513
|
+
throw Error("this config simulationAccount is not set right");
|
|
7514
|
+
}
|
|
7492
7515
|
tx.moveCall({
|
|
7493
7516
|
target: `${integrate.published_at}::${Voter}::get_voting_fee_reward_tokens`,
|
|
7494
7517
|
arguments: args,
|
|
7495
7518
|
typeArguments
|
|
7496
7519
|
});
|
|
7497
|
-
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
7498
|
-
throw Error("this config simulationAccount is not set right");
|
|
7499
|
-
}
|
|
7500
7520
|
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
7501
7521
|
transactionBlock: tx,
|
|
7502
7522
|
sender: simulationAccount.address
|
|
@@ -8983,6 +9003,178 @@ var RpcModule = class extends SuiClient {
|
|
|
8983
9003
|
}
|
|
8984
9004
|
};
|
|
8985
9005
|
|
|
9006
|
+
// src/modules/gauge.ts
|
|
9007
|
+
import { Transaction as Transaction11 } from "@mysten/sui/transactions";
|
|
9008
|
+
var GaugeModule = class {
|
|
9009
|
+
_sdk;
|
|
9010
|
+
constructor(sdk) {
|
|
9011
|
+
this._sdk = sdk;
|
|
9012
|
+
}
|
|
9013
|
+
get sdk() {
|
|
9014
|
+
return this._sdk;
|
|
9015
|
+
}
|
|
9016
|
+
async depositPosition(params) {
|
|
9017
|
+
const tx = new Transaction11();
|
|
9018
|
+
tx.setSender(this.sdk.senderAddress);
|
|
9019
|
+
const poolGauge = await this.getPoolGaguers();
|
|
9020
|
+
const gauge = poolGauge.get(params.poolId);
|
|
9021
|
+
if (gauge === void 0) {
|
|
9022
|
+
throw Error(`Fetch gauge of pool ${params.poolId} failed`);
|
|
9023
|
+
}
|
|
9024
|
+
const { distribution_cfg, magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
9025
|
+
const { clmm_pool, integrate } = this.sdk.sdkOptions;
|
|
9026
|
+
const clmmConfig = getPackagerConfigs(clmm_pool);
|
|
9027
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB, magma_token];
|
|
9028
|
+
const args = [
|
|
9029
|
+
tx.object(clmmConfig.global_config_id),
|
|
9030
|
+
tx.object(distribution_cfg),
|
|
9031
|
+
tx.object(gauge),
|
|
9032
|
+
tx.object(params.poolId),
|
|
9033
|
+
tx.object(params.positionId),
|
|
9034
|
+
tx.object(CLOCK_ADDRESS)
|
|
9035
|
+
];
|
|
9036
|
+
tx.moveCall({
|
|
9037
|
+
target: `${integrate.published_at}::${Gauge}::deposit_position`,
|
|
9038
|
+
typeArguments,
|
|
9039
|
+
arguments: args
|
|
9040
|
+
});
|
|
9041
|
+
return tx;
|
|
9042
|
+
}
|
|
9043
|
+
async withdrawPosition(params) {
|
|
9044
|
+
const tx = new Transaction11();
|
|
9045
|
+
tx.setSender(this.sdk.senderAddress);
|
|
9046
|
+
const poolGauge = await this.sdk.Gauge.getPoolGaguers();
|
|
9047
|
+
const gauge = poolGauge.get(params.poolId);
|
|
9048
|
+
if (gauge === void 0) {
|
|
9049
|
+
throw Error(`Fetch gauge of pool ${params.poolId} failed`);
|
|
9050
|
+
}
|
|
9051
|
+
const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
9052
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
9053
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB, magma_token];
|
|
9054
|
+
const args = [tx.object(gauge), tx.object(params.poolId), tx.object(params.positionId), tx.object(CLOCK_ADDRESS)];
|
|
9055
|
+
tx.moveCall({
|
|
9056
|
+
target: `${integrate.published_at}::${Gauge}::withdraw_position`,
|
|
9057
|
+
typeArguments,
|
|
9058
|
+
arguments: args
|
|
9059
|
+
});
|
|
9060
|
+
return tx;
|
|
9061
|
+
}
|
|
9062
|
+
async getUserStakedPositionInfo(userAddr) {
|
|
9063
|
+
const poolGauger = await this.getPoolGaguers();
|
|
9064
|
+
const poolCoins = await this.getPoolCoins([...poolGauger.keys()]);
|
|
9065
|
+
const res = [];
|
|
9066
|
+
for (const [pool, gauger] of poolGauger) {
|
|
9067
|
+
const coins = poolCoins.get(pool);
|
|
9068
|
+
if (coins === void 0) {
|
|
9069
|
+
console.log(`Failed to get coins of pool: ${pool}`);
|
|
9070
|
+
continue;
|
|
9071
|
+
}
|
|
9072
|
+
const stakedPositionOfPool = await this.getUserStakedPositionInfoOfPool(userAddr, pool, gauger, coins[0], coins[1]);
|
|
9073
|
+
res.push(...stakedPositionOfPool);
|
|
9074
|
+
}
|
|
9075
|
+
return res;
|
|
9076
|
+
}
|
|
9077
|
+
async getUserStakedPositionInfoOfPool(userAddr, pool, gauger, poolCoinA, poolCoinB) {
|
|
9078
|
+
const tx = new Transaction11();
|
|
9079
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
9080
|
+
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
9081
|
+
const typeArguments = [magma_token, poolCoinA, poolCoinB];
|
|
9082
|
+
const args = [tx.object(voter_id), tx.object(gauger), tx.object(pool), tx.pure.address(userAddr), tx.object(CLOCK_ADDRESS)];
|
|
9083
|
+
tx.moveCall({
|
|
9084
|
+
target: `${integrate.published_at}::${Gauge}::user_staked_position_infos`,
|
|
9085
|
+
arguments: args,
|
|
9086
|
+
typeArguments
|
|
9087
|
+
});
|
|
9088
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
9089
|
+
transactionBlock: tx,
|
|
9090
|
+
sender: simulationAccount.address
|
|
9091
|
+
});
|
|
9092
|
+
if (simulateRes.error != null) {
|
|
9093
|
+
throw new Error(`all_lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
|
|
9094
|
+
}
|
|
9095
|
+
const res = [];
|
|
9096
|
+
simulateRes.events?.forEach((item) => {
|
|
9097
|
+
res.push(item.parsedJson);
|
|
9098
|
+
});
|
|
9099
|
+
return res;
|
|
9100
|
+
}
|
|
9101
|
+
async getPoolGaguers() {
|
|
9102
|
+
const tx = new Transaction11();
|
|
9103
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
9104
|
+
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
9105
|
+
const typeArguments = [magma_token];
|
|
9106
|
+
const args = [tx.object(voter_id)];
|
|
9107
|
+
tx.moveCall({
|
|
9108
|
+
target: `${integrate.published_at}::${Voter}::pools_gauges`,
|
|
9109
|
+
arguments: args,
|
|
9110
|
+
typeArguments
|
|
9111
|
+
});
|
|
9112
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
9113
|
+
transactionBlock: tx,
|
|
9114
|
+
sender: simulationAccount.address
|
|
9115
|
+
});
|
|
9116
|
+
if (simulateRes.error != null) {
|
|
9117
|
+
throw new Error(`all_lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
|
|
9118
|
+
}
|
|
9119
|
+
const poolGauger = /* @__PURE__ */ new Map();
|
|
9120
|
+
simulateRes.events?.forEach((item) => {
|
|
9121
|
+
const { gauges } = item.parsedJson;
|
|
9122
|
+
console.log("parsedJson", item.parsedJson);
|
|
9123
|
+
item.parsedJson.pools.map((pool, index) => {
|
|
9124
|
+
poolGauger.set(pool, gauges[index]);
|
|
9125
|
+
});
|
|
9126
|
+
});
|
|
9127
|
+
return poolGauger;
|
|
9128
|
+
}
|
|
9129
|
+
async getPoolCoins(pools) {
|
|
9130
|
+
const res = await this._sdk.fullClient.multiGetObjects({ ids: pools, options: { showContent: true } });
|
|
9131
|
+
const poolCoins = /* @__PURE__ */ new Map();
|
|
9132
|
+
res.forEach((item) => {
|
|
9133
|
+
if (item.error != null || item.data?.content?.dataType !== "moveObject") {
|
|
9134
|
+
throw new Error(`Failed to get poolCoins with err: ${item.error}`);
|
|
9135
|
+
}
|
|
9136
|
+
const type = getObjectType(item);
|
|
9137
|
+
const poolTypeFields = extractStructTagFromType(type);
|
|
9138
|
+
poolCoins.set(poolTypeFields.address, poolTypeFields.type_arguments);
|
|
9139
|
+
});
|
|
9140
|
+
return poolCoins;
|
|
9141
|
+
}
|
|
9142
|
+
async getEmissions() {
|
|
9143
|
+
const tx = new Transaction11();
|
|
9144
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
9145
|
+
const { magma_token, minter_id, voting_escrow_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
9146
|
+
const typeArguments = [magma_token];
|
|
9147
|
+
const args = [tx.object(minter_id), tx.object(voting_escrow_id)];
|
|
9148
|
+
tx.moveCall({
|
|
9149
|
+
target: `${integrate.published_at}::${Minter}::emissions`,
|
|
9150
|
+
arguments: args,
|
|
9151
|
+
typeArguments
|
|
9152
|
+
});
|
|
9153
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
9154
|
+
transactionBlock: tx,
|
|
9155
|
+
sender: simulationAccount.address
|
|
9156
|
+
});
|
|
9157
|
+
if (simulateRes.error != null) {
|
|
9158
|
+
throw new Error(`all_lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
|
|
9159
|
+
}
|
|
9160
|
+
let res = {
|
|
9161
|
+
emission: 0,
|
|
9162
|
+
rebase: 0,
|
|
9163
|
+
total_supply: 0,
|
|
9164
|
+
total_locked: 0
|
|
9165
|
+
};
|
|
9166
|
+
simulateRes.events?.forEach((item) => {
|
|
9167
|
+
res = {
|
|
9168
|
+
emission: item.parsedJson.emission,
|
|
9169
|
+
rebase: item.parsedJson.rebase,
|
|
9170
|
+
total_supply: item.parsedJson.total_supply,
|
|
9171
|
+
total_locked: item.parsedJson.total_locked
|
|
9172
|
+
};
|
|
9173
|
+
});
|
|
9174
|
+
return res;
|
|
9175
|
+
}
|
|
9176
|
+
};
|
|
9177
|
+
|
|
8986
9178
|
// src/sdk.ts
|
|
8987
9179
|
var MagmaClmmSDK = class {
|
|
8988
9180
|
_cache = {};
|
|
@@ -9006,6 +9198,7 @@ var MagmaClmmSDK = class {
|
|
|
9006
9198
|
* Provide interact with a lock interface.
|
|
9007
9199
|
*/
|
|
9008
9200
|
_lock;
|
|
9201
|
+
_gauge;
|
|
9009
9202
|
/**
|
|
9010
9203
|
* Provide interact with a position rewarder interface.
|
|
9011
9204
|
*/
|
|
@@ -9042,6 +9235,7 @@ var MagmaClmmSDK = class {
|
|
|
9042
9235
|
});
|
|
9043
9236
|
this._swap = new SwapModule(this);
|
|
9044
9237
|
this._lock = new LockModule(this);
|
|
9238
|
+
this._gauge = new GaugeModule(this);
|
|
9045
9239
|
this._pool = new PoolModule(this);
|
|
9046
9240
|
this._position = new PositionModule(this);
|
|
9047
9241
|
this._rewarder = new RewarderModule(this);
|
|
@@ -9076,6 +9270,9 @@ var MagmaClmmSDK = class {
|
|
|
9076
9270
|
get Lock() {
|
|
9077
9271
|
return this._lock;
|
|
9078
9272
|
}
|
|
9273
|
+
get Gauge() {
|
|
9274
|
+
return this._gauge;
|
|
9275
|
+
}
|
|
9079
9276
|
/**
|
|
9080
9277
|
* Getter for the fullClient property.
|
|
9081
9278
|
* @returns {RpcModule} The fullClient property value.
|
|
@@ -9291,7 +9488,7 @@ var clmmMainnet = {
|
|
|
9291
9488
|
},
|
|
9292
9489
|
integrate: {
|
|
9293
9490
|
package_id: "0x6e3ae31a16362c563c0fef5293348d262646882a10c307f20f6be8577960f1ef",
|
|
9294
|
-
published_at: "
|
|
9491
|
+
published_at: "0xba2255e57f407e1e171f0bacd54d9e743bb12e3e9bb9d51a41a362749b9e51c2"
|
|
9295
9492
|
},
|
|
9296
9493
|
deepbook: {
|
|
9297
9494
|
package_id: "0x000000000000000000000000000000000000000000000000000000000000dee9",
|
|
@@ -9430,6 +9627,7 @@ export {
|
|
|
9430
9627
|
GAS_SYMBOL,
|
|
9431
9628
|
GAS_TYPE_ARG,
|
|
9432
9629
|
GAS_TYPE_ARG_LONG,
|
|
9630
|
+
Gauge,
|
|
9433
9631
|
LockModule,
|
|
9434
9632
|
MAX_SQRT_PRICE,
|
|
9435
9633
|
MAX_TICK_INDEX,
|
|
@@ -9437,6 +9635,7 @@ export {
|
|
|
9437
9635
|
MIN_TICK_INDEX,
|
|
9438
9636
|
MagmaClmmSDK,
|
|
9439
9637
|
MathUtil,
|
|
9638
|
+
Minter,
|
|
9440
9639
|
ONE,
|
|
9441
9640
|
POOL_STRUCT,
|
|
9442
9641
|
Percentage,
|