@magmaprotocol/magma-clmm-sdk 0.5.8 → 0.5.9
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 +39 -1
- package/dist/index.js +202 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +200 -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,174 @@ 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
|
+
};
|
|
9164
|
+
simulateRes.events?.forEach((item) => {
|
|
9165
|
+
res = {
|
|
9166
|
+
emission: item.parsedJson.emission,
|
|
9167
|
+
rebase: item.parsedJson.rebase
|
|
9168
|
+
};
|
|
9169
|
+
});
|
|
9170
|
+
return res;
|
|
9171
|
+
}
|
|
9172
|
+
};
|
|
9173
|
+
|
|
8986
9174
|
// src/sdk.ts
|
|
8987
9175
|
var MagmaClmmSDK = class {
|
|
8988
9176
|
_cache = {};
|
|
@@ -9006,6 +9194,7 @@ var MagmaClmmSDK = class {
|
|
|
9006
9194
|
* Provide interact with a lock interface.
|
|
9007
9195
|
*/
|
|
9008
9196
|
_lock;
|
|
9197
|
+
_gauge;
|
|
9009
9198
|
/**
|
|
9010
9199
|
* Provide interact with a position rewarder interface.
|
|
9011
9200
|
*/
|
|
@@ -9042,6 +9231,7 @@ var MagmaClmmSDK = class {
|
|
|
9042
9231
|
});
|
|
9043
9232
|
this._swap = new SwapModule(this);
|
|
9044
9233
|
this._lock = new LockModule(this);
|
|
9234
|
+
this._gauge = new GaugeModule(this);
|
|
9045
9235
|
this._pool = new PoolModule(this);
|
|
9046
9236
|
this._position = new PositionModule(this);
|
|
9047
9237
|
this._rewarder = new RewarderModule(this);
|
|
@@ -9076,6 +9266,9 @@ var MagmaClmmSDK = class {
|
|
|
9076
9266
|
get Lock() {
|
|
9077
9267
|
return this._lock;
|
|
9078
9268
|
}
|
|
9269
|
+
get Gauge() {
|
|
9270
|
+
return this._gauge;
|
|
9271
|
+
}
|
|
9079
9272
|
/**
|
|
9080
9273
|
* Getter for the fullClient property.
|
|
9081
9274
|
* @returns {RpcModule} The fullClient property value.
|
|
@@ -9291,7 +9484,7 @@ var clmmMainnet = {
|
|
|
9291
9484
|
},
|
|
9292
9485
|
integrate: {
|
|
9293
9486
|
package_id: "0x6e3ae31a16362c563c0fef5293348d262646882a10c307f20f6be8577960f1ef",
|
|
9294
|
-
published_at: "
|
|
9487
|
+
published_at: "0xba2255e57f407e1e171f0bacd54d9e743bb12e3e9bb9d51a41a362749b9e51c2"
|
|
9295
9488
|
},
|
|
9296
9489
|
deepbook: {
|
|
9297
9490
|
package_id: "0x000000000000000000000000000000000000000000000000000000000000dee9",
|
|
@@ -9430,6 +9623,7 @@ export {
|
|
|
9430
9623
|
GAS_SYMBOL,
|
|
9431
9624
|
GAS_TYPE_ARG,
|
|
9432
9625
|
GAS_TYPE_ARG_LONG,
|
|
9626
|
+
Gauge,
|
|
9433
9627
|
LockModule,
|
|
9434
9628
|
MAX_SQRT_PRICE,
|
|
9435
9629
|
MAX_TICK_INDEX,
|
|
@@ -9437,6 +9631,7 @@ export {
|
|
|
9437
9631
|
MIN_TICK_INDEX,
|
|
9438
9632
|
MagmaClmmSDK,
|
|
9439
9633
|
MathUtil,
|
|
9634
|
+
Minter,
|
|
9440
9635
|
ONE,
|
|
9441
9636
|
POOL_STRUCT,
|
|
9442
9637
|
Percentage,
|