@magmaprotocol/magma-clmm-sdk 0.5.18 → 0.5.19
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 +4 -1
- package/dist/index.js +116 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3098,7 +3098,10 @@ declare class LockModule implements IModule {
|
|
|
3098
3098
|
poolWeights(pools: string[]): Promise<PoolWeight[]>;
|
|
3099
3099
|
getVotingFeeRewardTokens(lock_id: string): Promise<Map<string, string[]>>;
|
|
3100
3100
|
getVotingBribeRewardTokens(lock_id: string): Promise<Map<string, string[]>>;
|
|
3101
|
-
|
|
3101
|
+
getPoolFeeRewards(lock_id: string, tokens: string[]): Promise<Map<string, Map<string, string>>>;
|
|
3102
|
+
_getPoolFeeRewards(lock_id: string, token_a: string, token_b: string, poolFeeRewardTokens: Map<string, Map<string, string>>): Promise<Map<string, Map<string, string>>>;
|
|
3103
|
+
getPoolIncentiveRewards(lock_id: string, incentive_tokens: string[]): Promise<Map<string, Map<string, string>>>;
|
|
3104
|
+
_getPoolIncentiveRewards(locksId: string, incentive_tokens: string[], poolBribeRewardTokens: Map<string, Map<string, string>>): Promise<Map<string, Map<string, string>>>;
|
|
3102
3105
|
getPoolBribeRewardTokens(pool_id: string): Promise<Map<string, string[]>>;
|
|
3103
3106
|
}
|
|
3104
3107
|
|
package/dist/index.js
CHANGED
|
@@ -7490,11 +7490,16 @@ var LockModule = class {
|
|
|
7490
7490
|
const { fields } = item.data.content;
|
|
7491
7491
|
const aLockSummary = await this.aLockSummary(fields.id.id);
|
|
7492
7492
|
const poolIncentiveTokens = await this.getVotingBribeRewardTokens(fields.id.id);
|
|
7493
|
+
const poolFeeTokens = await this.getVotingFeeRewardTokens(fields.id.id);
|
|
7493
7494
|
const incentiveTokens = [];
|
|
7494
7495
|
poolIncentiveTokens.forEach((value, key) => {
|
|
7495
7496
|
incentiveTokens.push(...value);
|
|
7496
7497
|
});
|
|
7497
|
-
const
|
|
7498
|
+
const feeTokens = [];
|
|
7499
|
+
poolFeeTokens.forEach((value, key) => {
|
|
7500
|
+
feeTokens.push(...value);
|
|
7501
|
+
});
|
|
7502
|
+
const poolIncentiveRewards = await this.getPoolIncentiveRewards(fields.id.id, incentiveTokens);
|
|
7498
7503
|
const votingRewards = /* @__PURE__ */ new Map();
|
|
7499
7504
|
poolIncentiveRewards.forEach((value, coin) => {
|
|
7500
7505
|
value.forEach((amount, pool) => {
|
|
@@ -7508,6 +7513,19 @@ var LockModule = class {
|
|
|
7508
7513
|
});
|
|
7509
7514
|
});
|
|
7510
7515
|
});
|
|
7516
|
+
const poolFeeRewards = await this.getPoolFeeRewards(fields.id.id, feeTokens);
|
|
7517
|
+
poolFeeRewards.forEach((value, coin) => {
|
|
7518
|
+
value.forEach((amount, pool) => {
|
|
7519
|
+
if (!votingRewards.has(pool)) {
|
|
7520
|
+
votingRewards.set(pool, []);
|
|
7521
|
+
}
|
|
7522
|
+
votingRewards.get(pool)?.push({
|
|
7523
|
+
kind: "fee" /* Fee */,
|
|
7524
|
+
token_addr: coin,
|
|
7525
|
+
amount: amount.toString()
|
|
7526
|
+
});
|
|
7527
|
+
});
|
|
7528
|
+
});
|
|
7511
7529
|
const lockInfo = {
|
|
7512
7530
|
lock_id: fields.id.id,
|
|
7513
7531
|
amount: fields.amount,
|
|
@@ -7520,7 +7538,7 @@ var LockModule = class {
|
|
|
7520
7538
|
amount: aLockSummary.reward_distributor_claimable
|
|
7521
7539
|
},
|
|
7522
7540
|
voting_power: aLockSummary.voting_power,
|
|
7523
|
-
// pool => incentive => amount
|
|
7541
|
+
// pool => incentive/fee => amount
|
|
7524
7542
|
voting_rewards: votingRewards
|
|
7525
7543
|
};
|
|
7526
7544
|
locksInfo.lockInfo.push(lockInfo);
|
|
@@ -7528,7 +7546,6 @@ var LockModule = class {
|
|
|
7528
7546
|
return locksInfo;
|
|
7529
7547
|
}
|
|
7530
7548
|
async aLockInfo(lockId) {
|
|
7531
|
-
const aLockSummary = await this.aLockSummary(lockId);
|
|
7532
7549
|
const lockObj = await this._sdk.fullClient.getObject({
|
|
7533
7550
|
id: lockId,
|
|
7534
7551
|
options: {
|
|
@@ -7540,13 +7557,25 @@ var LockModule = class {
|
|
|
7540
7557
|
showType: true
|
|
7541
7558
|
}
|
|
7542
7559
|
});
|
|
7560
|
+
if (lockObj.error != null || lockObj.data?.content?.dataType !== "moveObject") {
|
|
7561
|
+
throw new ClmmpoolsError(
|
|
7562
|
+
`getPool error code: ${lockObj.error?.code ?? "unknown error"}, please check config and object id`,
|
|
7563
|
+
"InvalidLockObject" /* InvalidLockObject */
|
|
7564
|
+
);
|
|
7565
|
+
}
|
|
7543
7566
|
const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7567
|
+
const aLockSummary = await this.aLockSummary(lockId);
|
|
7544
7568
|
const poolIncentiveTokens = await this.getVotingBribeRewardTokens(lockId);
|
|
7569
|
+
const poolFeeTokens = await this.getVotingFeeRewardTokens(lockId);
|
|
7545
7570
|
const incentiveTokens = [];
|
|
7546
7571
|
poolIncentiveTokens.forEach((value, key) => {
|
|
7547
7572
|
incentiveTokens.push(...value);
|
|
7548
7573
|
});
|
|
7549
|
-
const
|
|
7574
|
+
const feeTokens = [];
|
|
7575
|
+
poolFeeTokens.forEach((value, key) => {
|
|
7576
|
+
feeTokens.push(...value);
|
|
7577
|
+
});
|
|
7578
|
+
const poolIncentiveRewards = await this.getPoolIncentiveRewards(lockId, incentiveTokens);
|
|
7550
7579
|
const votingRewards = /* @__PURE__ */ new Map();
|
|
7551
7580
|
poolIncentiveRewards.forEach((value, coin) => {
|
|
7552
7581
|
value.forEach((amount, pool) => {
|
|
@@ -7560,12 +7589,19 @@ var LockModule = class {
|
|
|
7560
7589
|
});
|
|
7561
7590
|
});
|
|
7562
7591
|
});
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
|
-
|
|
7592
|
+
const poolFeeRewards = await this.getPoolFeeRewards(lockId, feeTokens);
|
|
7593
|
+
poolFeeRewards.forEach((value, coin) => {
|
|
7594
|
+
value.forEach((amount, pool) => {
|
|
7595
|
+
if (!votingRewards.has(pool)) {
|
|
7596
|
+
votingRewards.set(pool, []);
|
|
7597
|
+
}
|
|
7598
|
+
votingRewards.get(pool)?.push({
|
|
7599
|
+
kind: "fee" /* Fee */,
|
|
7600
|
+
token_addr: coin,
|
|
7601
|
+
amount: amount.toString()
|
|
7602
|
+
});
|
|
7603
|
+
});
|
|
7604
|
+
});
|
|
7569
7605
|
const fields = getObjectFields(lockObj);
|
|
7570
7606
|
const lockInfo = {
|
|
7571
7607
|
lock_id: lockId,
|
|
@@ -7780,11 +7816,72 @@ var LockModule = class {
|
|
|
7780
7816
|
});
|
|
7781
7817
|
return poolBirbeRewardTokens;
|
|
7782
7818
|
}
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7819
|
+
async getPoolFeeRewards(lock_id, tokens) {
|
|
7820
|
+
const poolFeeRewardTokens = /* @__PURE__ */ new Map();
|
|
7821
|
+
if (tokens.length === 0) {
|
|
7822
|
+
return poolFeeRewardTokens;
|
|
7823
|
+
}
|
|
7824
|
+
if (tokens.length % 2 !== 0) {
|
|
7825
|
+
tokens.push(tokens[0]);
|
|
7826
|
+
}
|
|
7827
|
+
for (let i = 0; i + 1 < tokens.length; i += 2) {
|
|
7828
|
+
await this._getPoolFeeRewards(lock_id, tokens[i], tokens[i + 1], poolFeeRewardTokens);
|
|
7829
|
+
}
|
|
7830
|
+
return poolFeeRewardTokens;
|
|
7831
|
+
}
|
|
7832
|
+
// if you have many tokens, call this function multi times
|
|
7833
|
+
async _getPoolFeeRewards(lock_id, token_a, token_b, poolFeeRewardTokens) {
|
|
7834
|
+
const tx = new import_transactions9.Transaction();
|
|
7835
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
7836
|
+
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7837
|
+
const typeArguments = [magma_token, token_a, token_b];
|
|
7838
|
+
const args = [tx.object(voter_id), tx.object(lock_id), tx.object(CLOCK_ADDRESS)];
|
|
7839
|
+
const targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_fee_rewards`;
|
|
7840
|
+
tx.moveCall({
|
|
7841
|
+
target: targetFunc,
|
|
7842
|
+
arguments: args,
|
|
7843
|
+
typeArguments
|
|
7844
|
+
});
|
|
7845
|
+
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
7846
|
+
throw Error("this config simulationAccount is not set right");
|
|
7847
|
+
}
|
|
7848
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
7849
|
+
transactionBlock: tx,
|
|
7850
|
+
sender: simulationAccount.address
|
|
7851
|
+
});
|
|
7852
|
+
if (simulateRes.error != null) {
|
|
7853
|
+
throw new Error(`getPoolFeeRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
7854
|
+
}
|
|
7855
|
+
simulateRes.events?.forEach((item) => {
|
|
7856
|
+
if (extractStructTagFromType(item.type).name === `ClaimableVotingFee`) {
|
|
7857
|
+
item.parsedJson.data.contents.forEach((rewardTokens) => {
|
|
7858
|
+
if (!poolFeeRewardTokens.has(rewardTokens.key.name)) {
|
|
7859
|
+
poolFeeRewardTokens.set(rewardTokens.key.name, /* @__PURE__ */ new Map());
|
|
7860
|
+
}
|
|
7861
|
+
rewardTokens.value.contents.forEach((token) => {
|
|
7862
|
+
poolFeeRewardTokens.get(rewardTokens.key.name)?.set(token.key, token.value);
|
|
7863
|
+
});
|
|
7864
|
+
});
|
|
7865
|
+
}
|
|
7866
|
+
});
|
|
7867
|
+
return poolFeeRewardTokens;
|
|
7868
|
+
}
|
|
7869
|
+
async getPoolIncentiveRewards(lock_id, incentive_tokens) {
|
|
7870
|
+
const poolBribeRewardTokens = /* @__PURE__ */ new Map();
|
|
7786
7871
|
if (incentive_tokens.length === 0) {
|
|
7787
|
-
return
|
|
7872
|
+
return poolBribeRewardTokens;
|
|
7873
|
+
}
|
|
7874
|
+
let i = 0;
|
|
7875
|
+
for (; i + 3 < incentive_tokens.length; i += 3) {
|
|
7876
|
+
await this._getPoolIncentiveRewards(lock_id, incentive_tokens.slice(i, i + 3), poolBribeRewardTokens);
|
|
7877
|
+
}
|
|
7878
|
+
await this._getPoolIncentiveRewards(lock_id, incentive_tokens.slice(i), poolBribeRewardTokens);
|
|
7879
|
+
return poolBribeRewardTokens;
|
|
7880
|
+
}
|
|
7881
|
+
// tokenId => pool => incentive_tokens
|
|
7882
|
+
async _getPoolIncentiveRewards(locksId, incentive_tokens, poolBribeRewardTokens) {
|
|
7883
|
+
if (incentive_tokens.length > 3) {
|
|
7884
|
+
throw Error("Too many tokens");
|
|
7788
7885
|
}
|
|
7789
7886
|
const tx = new import_transactions9.Transaction();
|
|
7790
7887
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -7808,21 +7905,21 @@ var LockModule = class {
|
|
|
7808
7905
|
sender: simulationAccount.address
|
|
7809
7906
|
});
|
|
7810
7907
|
if (simulateRes.error != null) {
|
|
7811
|
-
throw new Error(`
|
|
7908
|
+
throw new Error(`getPoolIncentiveRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
7812
7909
|
}
|
|
7813
7910
|
simulateRes.events?.forEach((item) => {
|
|
7814
7911
|
if (extractStructTagFromType(item.type).name === `ClaimableVotingBribes`) {
|
|
7815
7912
|
item.parsedJson.data.contents.forEach((rewardTokens) => {
|
|
7816
|
-
if (!
|
|
7817
|
-
|
|
7913
|
+
if (!poolBribeRewardTokens.has(rewardTokens.key.name)) {
|
|
7914
|
+
poolBribeRewardTokens.set(rewardTokens.key.name, /* @__PURE__ */ new Map());
|
|
7818
7915
|
}
|
|
7819
7916
|
rewardTokens.value.contents.forEach((token) => {
|
|
7820
|
-
|
|
7917
|
+
poolBribeRewardTokens.get(rewardTokens.key.name)?.set(token.key, token.value);
|
|
7821
7918
|
});
|
|
7822
7919
|
});
|
|
7823
7920
|
}
|
|
7824
7921
|
});
|
|
7825
|
-
return
|
|
7922
|
+
return poolBribeRewardTokens;
|
|
7826
7923
|
}
|
|
7827
7924
|
async getPoolBribeRewardTokens(pool_id) {
|
|
7828
7925
|
const tx = new import_transactions9.Transaction();
|