@magmaprotocol/magma-clmm-sdk 0.5.18 → 0.5.20
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 -2
- package/dist/index.js +190 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +190 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7271,6 +7271,30 @@ var LockModule = class {
|
|
|
7271
7271
|
}
|
|
7272
7272
|
return TransactionUtil.buildClaimVotingBribe(this.sdk, locks, incentive_tokens);
|
|
7273
7273
|
}
|
|
7274
|
+
async claimVotingFeeAndBribeForPool(lockId, poolId, feeTokens, incentiveTokens) {
|
|
7275
|
+
if (feeTokens.length !== 2) {
|
|
7276
|
+
throw Error("feeTokens length must be 2");
|
|
7277
|
+
}
|
|
7278
|
+
if (incentiveTokens.length < 1 || incentiveTokens.length > 3) {
|
|
7279
|
+
throw Error("incentiveTokens length must be between 1 and 3");
|
|
7280
|
+
}
|
|
7281
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
7282
|
+
const { voting_escrow_id, magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7283
|
+
const typeArguments = [magma_token, ...feeTokens, ...incentiveTokens];
|
|
7284
|
+
let targetFunc = `${integrate.published_at}::${Voter}::claim_voting_bribes_for_single_pool${incentiveTokens.length}`;
|
|
7285
|
+
if (incentiveTokens.length === 1) {
|
|
7286
|
+
targetFunc = `${integrate.published_at}::${Voter}::claim_voting_bribes_for_single_pool`;
|
|
7287
|
+
}
|
|
7288
|
+
const tx = new Transaction9();
|
|
7289
|
+
tx.setSender(this.sdk.senderAddress);
|
|
7290
|
+
const args = [tx.object(voter_id), tx.object(voting_escrow_id), tx.object(lockId), tx.object(poolId), tx.object(CLOCK_ADDRESS)];
|
|
7291
|
+
tx.moveCall({
|
|
7292
|
+
target: targetFunc,
|
|
7293
|
+
typeArguments,
|
|
7294
|
+
arguments: args
|
|
7295
|
+
});
|
|
7296
|
+
return tx;
|
|
7297
|
+
}
|
|
7274
7298
|
async locksOfUser(user) {
|
|
7275
7299
|
const locksInfo = { owner: user, lockInfo: [] };
|
|
7276
7300
|
const { distribution } = this._sdk.sdkOptions;
|
|
@@ -7285,11 +7309,16 @@ var LockModule = class {
|
|
|
7285
7309
|
const { fields } = item.data.content;
|
|
7286
7310
|
const aLockSummary = await this.aLockSummary(fields.id.id);
|
|
7287
7311
|
const poolIncentiveTokens = await this.getVotingBribeRewardTokens(fields.id.id);
|
|
7312
|
+
const poolFeeTokens = await this.getVotingFeeRewardTokens(fields.id.id);
|
|
7288
7313
|
const incentiveTokens = [];
|
|
7289
7314
|
poolIncentiveTokens.forEach((value, key) => {
|
|
7290
7315
|
incentiveTokens.push(...value);
|
|
7291
7316
|
});
|
|
7292
|
-
const
|
|
7317
|
+
const feeTokens = [];
|
|
7318
|
+
poolFeeTokens.forEach((value, key) => {
|
|
7319
|
+
feeTokens.push(...value);
|
|
7320
|
+
});
|
|
7321
|
+
const poolIncentiveRewards = await this.getPoolIncentiveRewards(fields.id.id, incentiveTokens);
|
|
7293
7322
|
const votingRewards = /* @__PURE__ */ new Map();
|
|
7294
7323
|
poolIncentiveRewards.forEach((value, coin) => {
|
|
7295
7324
|
value.forEach((amount, pool) => {
|
|
@@ -7303,6 +7332,19 @@ var LockModule = class {
|
|
|
7303
7332
|
});
|
|
7304
7333
|
});
|
|
7305
7334
|
});
|
|
7335
|
+
const poolFeeRewards = await this.getPoolFeeRewards(fields.id.id, feeTokens);
|
|
7336
|
+
poolFeeRewards.forEach((value, coin) => {
|
|
7337
|
+
value.forEach((amount, pool) => {
|
|
7338
|
+
if (!votingRewards.has(pool)) {
|
|
7339
|
+
votingRewards.set(pool, []);
|
|
7340
|
+
}
|
|
7341
|
+
votingRewards.get(pool)?.push({
|
|
7342
|
+
kind: "fee" /* Fee */,
|
|
7343
|
+
token_addr: coin,
|
|
7344
|
+
amount: amount.toString()
|
|
7345
|
+
});
|
|
7346
|
+
});
|
|
7347
|
+
});
|
|
7306
7348
|
const lockInfo = {
|
|
7307
7349
|
lock_id: fields.id.id,
|
|
7308
7350
|
amount: fields.amount,
|
|
@@ -7315,7 +7357,7 @@ var LockModule = class {
|
|
|
7315
7357
|
amount: aLockSummary.reward_distributor_claimable
|
|
7316
7358
|
},
|
|
7317
7359
|
voting_power: aLockSummary.voting_power,
|
|
7318
|
-
// pool => incentive => amount
|
|
7360
|
+
// pool => incentive/fee => amount
|
|
7319
7361
|
voting_rewards: votingRewards
|
|
7320
7362
|
};
|
|
7321
7363
|
locksInfo.lockInfo.push(lockInfo);
|
|
@@ -7323,7 +7365,6 @@ var LockModule = class {
|
|
|
7323
7365
|
return locksInfo;
|
|
7324
7366
|
}
|
|
7325
7367
|
async aLockInfo(lockId) {
|
|
7326
|
-
const aLockSummary = await this.aLockSummary(lockId);
|
|
7327
7368
|
const lockObj = await this._sdk.fullClient.getObject({
|
|
7328
7369
|
id: lockId,
|
|
7329
7370
|
options: {
|
|
@@ -7335,13 +7376,25 @@ var LockModule = class {
|
|
|
7335
7376
|
showType: true
|
|
7336
7377
|
}
|
|
7337
7378
|
});
|
|
7379
|
+
if (lockObj.error != null || lockObj.data?.content?.dataType !== "moveObject") {
|
|
7380
|
+
throw new ClmmpoolsError(
|
|
7381
|
+
`getPool error code: ${lockObj.error?.code ?? "unknown error"}, please check config and object id`,
|
|
7382
|
+
"InvalidLockObject" /* InvalidLockObject */
|
|
7383
|
+
);
|
|
7384
|
+
}
|
|
7338
7385
|
const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7386
|
+
const aLockSummary = await this.aLockSummary(lockId);
|
|
7339
7387
|
const poolIncentiveTokens = await this.getVotingBribeRewardTokens(lockId);
|
|
7388
|
+
const poolFeeTokens = await this.getVotingFeeRewardTokens(lockId);
|
|
7340
7389
|
const incentiveTokens = [];
|
|
7341
7390
|
poolIncentiveTokens.forEach((value, key) => {
|
|
7342
7391
|
incentiveTokens.push(...value);
|
|
7343
7392
|
});
|
|
7344
|
-
const
|
|
7393
|
+
const feeTokens = [];
|
|
7394
|
+
poolFeeTokens.forEach((value, key) => {
|
|
7395
|
+
feeTokens.push(...value);
|
|
7396
|
+
});
|
|
7397
|
+
const poolIncentiveRewards = await this.getPoolIncentiveRewards(lockId, incentiveTokens);
|
|
7345
7398
|
const votingRewards = /* @__PURE__ */ new Map();
|
|
7346
7399
|
poolIncentiveRewards.forEach((value, coin) => {
|
|
7347
7400
|
value.forEach((amount, pool) => {
|
|
@@ -7355,12 +7408,19 @@ var LockModule = class {
|
|
|
7355
7408
|
});
|
|
7356
7409
|
});
|
|
7357
7410
|
});
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7411
|
+
const poolFeeRewards = await this.getPoolFeeRewards(lockId, feeTokens);
|
|
7412
|
+
poolFeeRewards.forEach((value, coin) => {
|
|
7413
|
+
value.forEach((amount, pool) => {
|
|
7414
|
+
if (!votingRewards.has(pool)) {
|
|
7415
|
+
votingRewards.set(pool, []);
|
|
7416
|
+
}
|
|
7417
|
+
votingRewards.get(pool)?.push({
|
|
7418
|
+
kind: "fee" /* Fee */,
|
|
7419
|
+
token_addr: coin,
|
|
7420
|
+
amount: amount.toString()
|
|
7421
|
+
});
|
|
7422
|
+
});
|
|
7423
|
+
});
|
|
7364
7424
|
const fields = getObjectFields(lockObj);
|
|
7365
7425
|
const lockInfo = {
|
|
7366
7426
|
lock_id: lockId,
|
|
@@ -7575,11 +7635,72 @@ var LockModule = class {
|
|
|
7575
7635
|
});
|
|
7576
7636
|
return poolBirbeRewardTokens;
|
|
7577
7637
|
}
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7638
|
+
async getPoolFeeRewards(lock_id, tokens) {
|
|
7639
|
+
const poolFeeRewardTokens = /* @__PURE__ */ new Map();
|
|
7640
|
+
if (tokens.length === 0) {
|
|
7641
|
+
return poolFeeRewardTokens;
|
|
7642
|
+
}
|
|
7643
|
+
if (tokens.length % 2 !== 0) {
|
|
7644
|
+
tokens.push(tokens[0]);
|
|
7645
|
+
}
|
|
7646
|
+
for (let i = 0; i + 1 < tokens.length; i += 2) {
|
|
7647
|
+
await this._getPoolFeeRewards(lock_id, tokens[i], tokens[i + 1], poolFeeRewardTokens);
|
|
7648
|
+
}
|
|
7649
|
+
return poolFeeRewardTokens;
|
|
7650
|
+
}
|
|
7651
|
+
// if you have many tokens, call this function multi times
|
|
7652
|
+
async _getPoolFeeRewards(lock_id, token_a, token_b, poolFeeRewardTokens) {
|
|
7653
|
+
const tx = new Transaction9();
|
|
7654
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
7655
|
+
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7656
|
+
const typeArguments = [magma_token, token_a, token_b];
|
|
7657
|
+
const args = [tx.object(voter_id), tx.object(lock_id), tx.object(CLOCK_ADDRESS)];
|
|
7658
|
+
const targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_fee_rewards`;
|
|
7659
|
+
tx.moveCall({
|
|
7660
|
+
target: targetFunc,
|
|
7661
|
+
arguments: args,
|
|
7662
|
+
typeArguments
|
|
7663
|
+
});
|
|
7664
|
+
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
7665
|
+
throw Error("this config simulationAccount is not set right");
|
|
7666
|
+
}
|
|
7667
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
7668
|
+
transactionBlock: tx,
|
|
7669
|
+
sender: simulationAccount.address
|
|
7670
|
+
});
|
|
7671
|
+
if (simulateRes.error != null) {
|
|
7672
|
+
throw new Error(`getPoolFeeRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
7673
|
+
}
|
|
7674
|
+
simulateRes.events?.forEach((item) => {
|
|
7675
|
+
if (extractStructTagFromType(item.type).name === `ClaimableVotingFee`) {
|
|
7676
|
+
item.parsedJson.data.contents.forEach((rewardTokens) => {
|
|
7677
|
+
if (!poolFeeRewardTokens.has(rewardTokens.key.name)) {
|
|
7678
|
+
poolFeeRewardTokens.set(rewardTokens.key.name, /* @__PURE__ */ new Map());
|
|
7679
|
+
}
|
|
7680
|
+
rewardTokens.value.contents.forEach((token) => {
|
|
7681
|
+
poolFeeRewardTokens.get(rewardTokens.key.name)?.set(token.key, token.value);
|
|
7682
|
+
});
|
|
7683
|
+
});
|
|
7684
|
+
}
|
|
7685
|
+
});
|
|
7686
|
+
return poolFeeRewardTokens;
|
|
7687
|
+
}
|
|
7688
|
+
async getPoolIncentiveRewards(lock_id, incentive_tokens) {
|
|
7689
|
+
const poolBribeRewardTokens = /* @__PURE__ */ new Map();
|
|
7581
7690
|
if (incentive_tokens.length === 0) {
|
|
7582
|
-
return
|
|
7691
|
+
return poolBribeRewardTokens;
|
|
7692
|
+
}
|
|
7693
|
+
let i = 0;
|
|
7694
|
+
for (; i + 3 < incentive_tokens.length; i += 3) {
|
|
7695
|
+
await this._getPoolIncentiveRewards(lock_id, incentive_tokens.slice(i, i + 3), poolBribeRewardTokens);
|
|
7696
|
+
}
|
|
7697
|
+
await this._getPoolIncentiveRewards(lock_id, incentive_tokens.slice(i), poolBribeRewardTokens);
|
|
7698
|
+
return poolBribeRewardTokens;
|
|
7699
|
+
}
|
|
7700
|
+
// tokenId => pool => incentive_tokens
|
|
7701
|
+
async _getPoolIncentiveRewards(locksId, incentive_tokens, poolBribeRewardTokens) {
|
|
7702
|
+
if (incentive_tokens.length > 3) {
|
|
7703
|
+
throw Error("Too many tokens");
|
|
7583
7704
|
}
|
|
7584
7705
|
const tx = new Transaction9();
|
|
7585
7706
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -7603,21 +7724,21 @@ var LockModule = class {
|
|
|
7603
7724
|
sender: simulationAccount.address
|
|
7604
7725
|
});
|
|
7605
7726
|
if (simulateRes.error != null) {
|
|
7606
|
-
throw new Error(`
|
|
7727
|
+
throw new Error(`getPoolIncentiveRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
7607
7728
|
}
|
|
7608
7729
|
simulateRes.events?.forEach((item) => {
|
|
7609
7730
|
if (extractStructTagFromType(item.type).name === `ClaimableVotingBribes`) {
|
|
7610
7731
|
item.parsedJson.data.contents.forEach((rewardTokens) => {
|
|
7611
|
-
if (!
|
|
7612
|
-
|
|
7732
|
+
if (!poolBribeRewardTokens.has(rewardTokens.key.name)) {
|
|
7733
|
+
poolBribeRewardTokens.set(rewardTokens.key.name, /* @__PURE__ */ new Map());
|
|
7613
7734
|
}
|
|
7614
7735
|
rewardTokens.value.contents.forEach((token) => {
|
|
7615
|
-
|
|
7736
|
+
poolBribeRewardTokens.get(rewardTokens.key.name)?.set(token.key, token.value);
|
|
7616
7737
|
});
|
|
7617
7738
|
});
|
|
7618
7739
|
}
|
|
7619
7740
|
});
|
|
7620
|
-
return
|
|
7741
|
+
return poolBribeRewardTokens;
|
|
7621
7742
|
}
|
|
7622
7743
|
async getPoolBribeRewardTokens(pool_id) {
|
|
7623
7744
|
const tx = new Transaction9();
|
|
@@ -7655,6 +7776,46 @@ var LockModule = class {
|
|
|
7655
7776
|
});
|
|
7656
7777
|
return poolBirbeRewardTokens;
|
|
7657
7778
|
}
|
|
7779
|
+
async getLockVotingStats(lockId) {
|
|
7780
|
+
const tx = new Transaction9();
|
|
7781
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
7782
|
+
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7783
|
+
const args = [tx.object(voter_id), tx.object(lockId), tx.object(CLOCK_ADDRESS)];
|
|
7784
|
+
const typeArguments = [magma_token];
|
|
7785
|
+
tx.moveCall({
|
|
7786
|
+
target: `${integrate.published_at}::${Voter}::lock_voting_stats`,
|
|
7787
|
+
arguments: args,
|
|
7788
|
+
typeArguments
|
|
7789
|
+
});
|
|
7790
|
+
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
7791
|
+
throw Error("this config simulationAccount is not set right");
|
|
7792
|
+
}
|
|
7793
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
7794
|
+
transactionBlock: tx,
|
|
7795
|
+
sender: simulationAccount.address
|
|
7796
|
+
});
|
|
7797
|
+
if (simulateRes.error != null) {
|
|
7798
|
+
console.log(`error code: ${simulateRes.error ?? "unknown error"}`);
|
|
7799
|
+
return null;
|
|
7800
|
+
}
|
|
7801
|
+
let res = {
|
|
7802
|
+
lock_id: lockId,
|
|
7803
|
+
last_voted_at: "",
|
|
7804
|
+
pools: [],
|
|
7805
|
+
votes: []
|
|
7806
|
+
};
|
|
7807
|
+
simulateRes.events?.forEach((item) => {
|
|
7808
|
+
if (extractStructTagFromType(item.type).name === `EventLockVotingStats`) {
|
|
7809
|
+
res = {
|
|
7810
|
+
lock_id: item.parsedJson.lock_id,
|
|
7811
|
+
last_voted_at: item.parsedJson.last_voted_at,
|
|
7812
|
+
pools: item.parsedJson.pools,
|
|
7813
|
+
votes: item.parsedJson.votes
|
|
7814
|
+
};
|
|
7815
|
+
}
|
|
7816
|
+
});
|
|
7817
|
+
return res;
|
|
7818
|
+
}
|
|
7658
7819
|
};
|
|
7659
7820
|
|
|
7660
7821
|
// src/modules/tokenModule.ts
|
|
@@ -9519,12 +9680,12 @@ var SDKConfig = {
|
|
|
9519
9680
|
launchpad_pools_handle: "0x5e194a8efcf653830daf85a85b52e3ae8f65dc39481d54b2382acda25068375c",
|
|
9520
9681
|
clmm_pools_handle: "0x37f60eb2d9d227949b95da8fea810db3c32d1e1fa8ed87434fc51664f87d83cb",
|
|
9521
9682
|
global_config_id: "0x4f32c00706e7bdbce532acdcfc0afd91b14defd5ffc9e2723a0ce7ed84f5d380",
|
|
9522
|
-
voter_id: "
|
|
9523
|
-
voting_escrow_id: "
|
|
9524
|
-
reward_distributor_id: "
|
|
9525
|
-
distribution_cfg: "
|
|
9526
|
-
magma_token: "
|
|
9527
|
-
minter_id: "
|
|
9683
|
+
voter_id: "0xaab0f3a90da96d29d743e09c269e1ae48ec1bae52a28cd38c49c5dc8c1bf92b8",
|
|
9684
|
+
voting_escrow_id: "0x7ab45fbe01da26e07ba21757916d540c8747cf7daa88f3171e13db17373d5adc",
|
|
9685
|
+
reward_distributor_id: "0x9f4f882245e49fd9213278dfbcb63a14fdbdd2ce7e25e9353a0cecdca30de853",
|
|
9686
|
+
distribution_cfg: "0xaff8d151ac29317201151f97d28c546b3c5923d8cfc5499f40dea61c4022c949",
|
|
9687
|
+
magma_token: "0x7161c6c6bb65f852797c8f7f5c4f8d57adaf796e1b840921f9e23fabeadfd54e::magma::MAGMA",
|
|
9688
|
+
minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
|
|
9528
9689
|
}
|
|
9529
9690
|
};
|
|
9530
9691
|
var clmmMainnet = {
|
|
@@ -9543,12 +9704,12 @@ var clmmMainnet = {
|
|
|
9543
9704
|
config: SDKConfig.clmmConfig
|
|
9544
9705
|
},
|
|
9545
9706
|
distribution: {
|
|
9546
|
-
package_id: "
|
|
9547
|
-
published_at: "
|
|
9707
|
+
package_id: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b",
|
|
9708
|
+
published_at: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b"
|
|
9548
9709
|
},
|
|
9549
9710
|
integrate: {
|
|
9550
|
-
package_id: "
|
|
9551
|
-
published_at: "
|
|
9711
|
+
package_id: "0xc08328e57f004fdd16a38c62df1eaba2be4db74fb9680986cd911460692aaf67",
|
|
9712
|
+
published_at: "0xc08328e57f004fdd16a38c62df1eaba2be4db74fb9680986cd911460692aaf67"
|
|
9552
9713
|
},
|
|
9553
9714
|
deepbook: {
|
|
9554
9715
|
package_id: "0x000000000000000000000000000000000000000000000000000000000000dee9",
|