@magmaprotocol/magma-clmm-sdk 0.5.32 → 0.5.34
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 +22 -1
- package/dist/index.js +356 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +356 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -2973,7 +2973,6 @@ var _TransactionUtil = class {
|
|
|
2973
2973
|
// public fun increase_unlock_time<T>(self: &mut VotingEscrow<T>, lock: &mut Lock, lock_duration: u64, clock: &Clock, ctx: &mut TxContext) {
|
|
2974
2974
|
static buildIncreaseUnlockTimeTransaction(sdk, params) {
|
|
2975
2975
|
const tx = new Transaction();
|
|
2976
|
-
tx.setGasBudget(1e8);
|
|
2977
2976
|
tx.setSender(sdk.senderAddress);
|
|
2978
2977
|
const oneDay = 24 * 60 * 60;
|
|
2979
2978
|
const newLockDuration = Math.ceil((params.newLockEndAt - Date.now() / 1e3) / oneDay);
|
|
@@ -3134,7 +3133,6 @@ var _TransactionUtil = class {
|
|
|
3134
3133
|
static buildClaimAndLockRebases(sdk, params) {
|
|
3135
3134
|
const tx = new Transaction();
|
|
3136
3135
|
tx.setSender(sdk.senderAddress);
|
|
3137
|
-
tx.setGasBudget(5e8);
|
|
3138
3136
|
const { integrate } = sdk.sdkOptions;
|
|
3139
3137
|
const { voting_escrow_id, magma_token, reward_distributor_id } = getPackagerConfigs(sdk.sdkOptions.magma_config);
|
|
3140
3138
|
const typeArguments = [magma_token];
|
|
@@ -3170,7 +3168,6 @@ var _TransactionUtil = class {
|
|
|
3170
3168
|
}
|
|
3171
3169
|
static buildClaimVotingBribe(sdk, locks, incentive_tokens) {
|
|
3172
3170
|
const tx = new Transaction();
|
|
3173
|
-
tx.setGasBudget(5e8);
|
|
3174
3171
|
tx.setSender(sdk.senderAddress);
|
|
3175
3172
|
const { integrate, distribution } = sdk.sdkOptions;
|
|
3176
3173
|
const { voting_escrow_id, magma_token, voter_id } = getPackagerConfigs(sdk.sdkOptions.magma_config);
|
|
@@ -7392,6 +7389,57 @@ var LockModule = class {
|
|
|
7392
7389
|
}
|
|
7393
7390
|
return locksInfo;
|
|
7394
7391
|
}
|
|
7392
|
+
async locksOfUserV2(user) {
|
|
7393
|
+
const locksInfo = { owner: user, lockInfo: [] };
|
|
7394
|
+
const { distribution } = this._sdk.sdkOptions;
|
|
7395
|
+
const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7396
|
+
const ownerRes = await this._sdk.fullClient.getOwnedObjectsByPage(user, {
|
|
7397
|
+
options: { showType: true, showContent: true, showDisplay: true, showOwner: true },
|
|
7398
|
+
filter: {
|
|
7399
|
+
MatchAll: [{ Package: distribution.package_id }, { StructType: `${distribution.package_id}::voting_escrow::Lock` }]
|
|
7400
|
+
}
|
|
7401
|
+
});
|
|
7402
|
+
const ids = ownerRes.data.map((item) => item.data.content.id.id);
|
|
7403
|
+
const lockSummary = await this.getAllLockSummary(ids);
|
|
7404
|
+
const lockIncentiveTokens = await this.getAllBribeRewardTokensOfLock(ids);
|
|
7405
|
+
const lockFeeTokens = await this.getAllVotingFeeRewardTokens(ids);
|
|
7406
|
+
const poolIncentiveRewards = await this.getAllIncentiveRewards(lockIncentiveTokens);
|
|
7407
|
+
const poolFeeRewards = await this.getAllFeeRewards(lockFeeTokens);
|
|
7408
|
+
for (const item of ownerRes.data) {
|
|
7409
|
+
const { fields } = item.data.content;
|
|
7410
|
+
const lock_id = fields.id.id;
|
|
7411
|
+
const votingRewards = /* @__PURE__ */ new Map();
|
|
7412
|
+
poolIncentiveRewards.get(lock_id)?.forEach((value, pool) => {
|
|
7413
|
+
if (!votingRewards.has(pool)) {
|
|
7414
|
+
votingRewards.set(pool, []);
|
|
7415
|
+
}
|
|
7416
|
+
votingRewards.get(pool)?.push(...value);
|
|
7417
|
+
});
|
|
7418
|
+
poolFeeRewards.get(lock_id)?.forEach((value, pool) => {
|
|
7419
|
+
if (!votingRewards.has(pool)) {
|
|
7420
|
+
votingRewards.set(pool, []);
|
|
7421
|
+
}
|
|
7422
|
+
votingRewards.get(pool)?.push(...value);
|
|
7423
|
+
});
|
|
7424
|
+
const lockInfo = {
|
|
7425
|
+
lock_id,
|
|
7426
|
+
amount: fields.amount,
|
|
7427
|
+
start: fields.start,
|
|
7428
|
+
end: fields.end,
|
|
7429
|
+
permanent: fields.permanent,
|
|
7430
|
+
rebase_amount: {
|
|
7431
|
+
kind: "rebaseCoin" /* RebaseCoin */,
|
|
7432
|
+
token_addr: magma_token,
|
|
7433
|
+
amount: lockSummary.get(lock_id)?.reward_distributor_claimable || "0"
|
|
7434
|
+
},
|
|
7435
|
+
voting_power: lockSummary.get(lock_id)?.voting_power || "0",
|
|
7436
|
+
// pool => incentive/fee => amount
|
|
7437
|
+
voting_rewards: votingRewards
|
|
7438
|
+
};
|
|
7439
|
+
locksInfo.lockInfo.push(lockInfo);
|
|
7440
|
+
}
|
|
7441
|
+
return locksInfo;
|
|
7442
|
+
}
|
|
7395
7443
|
async locksOfUser(user) {
|
|
7396
7444
|
const locksInfo = { owner: user, lockInfo: [] };
|
|
7397
7445
|
const { distribution } = this._sdk.sdkOptions;
|
|
@@ -7584,6 +7632,57 @@ var LockModule = class {
|
|
|
7584
7632
|
});
|
|
7585
7633
|
return res;
|
|
7586
7634
|
}
|
|
7635
|
+
// Return: lock_id => ALockSummary
|
|
7636
|
+
async getAllLockSummary(lock_ids) {
|
|
7637
|
+
let tx = new Transaction9();
|
|
7638
|
+
for (const lock_id of lock_ids) {
|
|
7639
|
+
tx = await this._aLockSummary(lock_id, tx);
|
|
7640
|
+
}
|
|
7641
|
+
return this._parseLockSummary(tx);
|
|
7642
|
+
}
|
|
7643
|
+
async _aLockSummary(lock_id, tx) {
|
|
7644
|
+
tx = tx || new Transaction9();
|
|
7645
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
7646
|
+
const { voting_escrow_id, magma_token, voter_id, reward_distributor_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7647
|
+
const typeArguments = [magma_token];
|
|
7648
|
+
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
7649
|
+
throw Error("this config simulationAccount is not set right");
|
|
7650
|
+
}
|
|
7651
|
+
const args = [
|
|
7652
|
+
tx.object(voter_id),
|
|
7653
|
+
tx.object(voting_escrow_id),
|
|
7654
|
+
tx.object(reward_distributor_id),
|
|
7655
|
+
tx.object(lock_id),
|
|
7656
|
+
tx.object(CLOCK_ADDRESS)
|
|
7657
|
+
];
|
|
7658
|
+
tx.moveCall({
|
|
7659
|
+
target: `${integrate.published_at}::${VotingEscrow}::lock_summary`,
|
|
7660
|
+
arguments: args,
|
|
7661
|
+
typeArguments
|
|
7662
|
+
});
|
|
7663
|
+
return tx;
|
|
7664
|
+
}
|
|
7665
|
+
async _parseLockSummary(tx) {
|
|
7666
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
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(`lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
|
|
7673
|
+
}
|
|
7674
|
+
const res = /* @__PURE__ */ new Map();
|
|
7675
|
+
simulateRes.events?.forEach((item) => {
|
|
7676
|
+
if (extractStructTagFromType(item.type).name === `LockSummary`) {
|
|
7677
|
+
res.set(item.parsedJson.lock_id, {
|
|
7678
|
+
fee_incentive_total: item.parsedJson.fee_incentive_total,
|
|
7679
|
+
reward_distributor_claimable: item.parsedJson.reward_distributor_claimable,
|
|
7680
|
+
voting_power: item.parsedJson.voting_power
|
|
7681
|
+
});
|
|
7682
|
+
}
|
|
7683
|
+
});
|
|
7684
|
+
return res;
|
|
7685
|
+
}
|
|
7587
7686
|
async allLockSummary() {
|
|
7588
7687
|
const tx = new Transaction9();
|
|
7589
7688
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -7664,6 +7763,54 @@ var LockModule = class {
|
|
|
7664
7763
|
});
|
|
7665
7764
|
return poolWeights;
|
|
7666
7765
|
}
|
|
7766
|
+
async getAllVotingFeeRewardTokens(lock_ids) {
|
|
7767
|
+
let tx = new Transaction9();
|
|
7768
|
+
for (const lock_id of lock_ids) {
|
|
7769
|
+
tx = await this._getVotingFeeRewardTokens(lock_id, tx);
|
|
7770
|
+
}
|
|
7771
|
+
return this._parseVotingFeeRewardTokens(tx);
|
|
7772
|
+
}
|
|
7773
|
+
async _getVotingFeeRewardTokens(lock_id, tx) {
|
|
7774
|
+
tx = tx || new Transaction9();
|
|
7775
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
7776
|
+
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7777
|
+
const typeArguments = [magma_token];
|
|
7778
|
+
const args = [tx.object(voter_id), tx.object(lock_id)];
|
|
7779
|
+
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
7780
|
+
throw Error("this config simulationAccount is not set right");
|
|
7781
|
+
}
|
|
7782
|
+
tx.moveCall({
|
|
7783
|
+
target: `${integrate.published_at}::${Voter}::get_voting_fee_reward_tokens`,
|
|
7784
|
+
arguments: args,
|
|
7785
|
+
typeArguments
|
|
7786
|
+
});
|
|
7787
|
+
return tx;
|
|
7788
|
+
}
|
|
7789
|
+
async _parseVotingFeeRewardTokens(tx) {
|
|
7790
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
7791
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
7792
|
+
transactionBlock: tx,
|
|
7793
|
+
sender: simulationAccount.address
|
|
7794
|
+
});
|
|
7795
|
+
if (simulateRes.error != null) {
|
|
7796
|
+
throw new Error(`all_lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
|
|
7797
|
+
}
|
|
7798
|
+
const poolFeeRewardTokens = /* @__PURE__ */ new Map();
|
|
7799
|
+
simulateRes.events?.forEach((event) => {
|
|
7800
|
+
if (extractStructTagFromType(event.type).name === `EventFeeRewardTokens`) {
|
|
7801
|
+
const { lock_id } = event.parsedJson;
|
|
7802
|
+
if (!poolFeeRewardTokens.has(lock_id)) {
|
|
7803
|
+
poolFeeRewardTokens.set(lock_id, []);
|
|
7804
|
+
}
|
|
7805
|
+
event.parsedJson.list.contents.forEach((poolTokens) => {
|
|
7806
|
+
poolTokens.value.forEach((token) => {
|
|
7807
|
+
poolFeeRewardTokens.get(lock_id)?.push(token.name);
|
|
7808
|
+
});
|
|
7809
|
+
});
|
|
7810
|
+
}
|
|
7811
|
+
});
|
|
7812
|
+
return poolFeeRewardTokens;
|
|
7813
|
+
}
|
|
7667
7814
|
async getVotingFeeRewardTokens(lock_id) {
|
|
7668
7815
|
const tx = new Transaction9();
|
|
7669
7816
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -7687,7 +7834,7 @@ var LockModule = class {
|
|
|
7687
7834
|
}
|
|
7688
7835
|
const poolRewardTokens = /* @__PURE__ */ new Map();
|
|
7689
7836
|
simulateRes.events?.forEach((item) => {
|
|
7690
|
-
if (extractStructTagFromType(item.type).name === `
|
|
7837
|
+
if (extractStructTagFromType(item.type).name === `EventFeeRewardTokens`) {
|
|
7691
7838
|
item.parsedJson.list.contents.forEach((poolTokens) => {
|
|
7692
7839
|
if (!poolRewardTokens.has(poolTokens.key)) {
|
|
7693
7840
|
poolRewardTokens.set(poolTokens.key, []);
|
|
@@ -7700,20 +7847,70 @@ var LockModule = class {
|
|
|
7700
7847
|
});
|
|
7701
7848
|
return poolRewardTokens;
|
|
7702
7849
|
}
|
|
7703
|
-
|
|
7704
|
-
|
|
7850
|
+
// tokens
|
|
7851
|
+
async getAllBribeRewardTokensOfLock(lock_ids) {
|
|
7852
|
+
let tx = new Transaction9();
|
|
7853
|
+
for (const lock_id of lock_ids) {
|
|
7854
|
+
tx = await this._getVotingBribeRewardTokens(lock_id, tx);
|
|
7855
|
+
}
|
|
7856
|
+
return this._parseVotingBribeRewardTokens(tx);
|
|
7857
|
+
}
|
|
7858
|
+
async _getVotingBribeRewardTokens(lock_id, tx) {
|
|
7859
|
+
tx = tx || new Transaction9();
|
|
7705
7860
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
7706
7861
|
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7707
7862
|
const typeArguments = [magma_token];
|
|
7863
|
+
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
7864
|
+
throw Error("this config simulationAccount is not set right");
|
|
7865
|
+
}
|
|
7708
7866
|
const args = [tx.object(voter_id), tx.object(lock_id)];
|
|
7709
7867
|
tx.moveCall({
|
|
7710
7868
|
target: `${integrate.published_at}::${Voter}::get_voting_bribe_reward_tokens`,
|
|
7711
7869
|
arguments: args,
|
|
7712
7870
|
typeArguments
|
|
7713
7871
|
});
|
|
7872
|
+
return tx;
|
|
7873
|
+
}
|
|
7874
|
+
async _parseVotingBribeRewardTokens(tx) {
|
|
7875
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
7876
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
7877
|
+
transactionBlock: tx,
|
|
7878
|
+
sender: simulationAccount.address
|
|
7879
|
+
});
|
|
7880
|
+
if (simulateRes.error != null) {
|
|
7881
|
+
throw new Error(`all_lock_summary error code: ${simulateRes.error ?? "unknown error"}`);
|
|
7882
|
+
}
|
|
7883
|
+
const poolBirbeRewardTokens = /* @__PURE__ */ new Map();
|
|
7884
|
+
simulateRes.events?.forEach((event) => {
|
|
7885
|
+
if (extractStructTagFromType(event.type).name === `EventBribeRewardTokens`) {
|
|
7886
|
+
const { lock_id } = event.parsedJson;
|
|
7887
|
+
if (!poolBirbeRewardTokens.has(lock_id)) {
|
|
7888
|
+
poolBirbeRewardTokens.set(lock_id, []);
|
|
7889
|
+
}
|
|
7890
|
+
event.parsedJson.list.contents.forEach((poolTokens) => {
|
|
7891
|
+
poolTokens.value.forEach((token) => {
|
|
7892
|
+
poolBirbeRewardTokens.get(lock_id)?.push(token.name);
|
|
7893
|
+
});
|
|
7894
|
+
});
|
|
7895
|
+
}
|
|
7896
|
+
});
|
|
7897
|
+
return poolBirbeRewardTokens;
|
|
7898
|
+
}
|
|
7899
|
+
// Return PoolId => tokens
|
|
7900
|
+
async getVotingBribeRewardTokens(lock_id) {
|
|
7901
|
+
const tx = new Transaction9();
|
|
7902
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
7903
|
+
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7904
|
+
const typeArguments = [magma_token];
|
|
7714
7905
|
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
7715
7906
|
throw Error("this config simulationAccount is not set right");
|
|
7716
7907
|
}
|
|
7908
|
+
const args = [tx.object(voter_id), tx.object(lock_id)];
|
|
7909
|
+
tx.moveCall({
|
|
7910
|
+
target: `${integrate.published_at}::${Voter}::get_voting_bribe_reward_tokens`,
|
|
7911
|
+
arguments: args,
|
|
7912
|
+
typeArguments
|
|
7913
|
+
});
|
|
7717
7914
|
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
7718
7915
|
transactionBlock: tx,
|
|
7719
7916
|
sender: simulationAccount.address
|
|
@@ -7723,7 +7920,7 @@ var LockModule = class {
|
|
|
7723
7920
|
}
|
|
7724
7921
|
const poolBirbeRewardTokens = /* @__PURE__ */ new Map();
|
|
7725
7922
|
simulateRes.events?.forEach((item) => {
|
|
7726
|
-
if (extractStructTagFromType(item.type).name === `
|
|
7923
|
+
if (extractStructTagFromType(item.type).name === `EventBribeRewardTokens`) {
|
|
7727
7924
|
item.parsedJson.list.contents.forEach((poolTokens) => {
|
|
7728
7925
|
if (!poolBirbeRewardTokens.has(poolTokens.key)) {
|
|
7729
7926
|
poolBirbeRewardTokens.set(poolTokens.key, []);
|
|
@@ -7736,6 +7933,68 @@ var LockModule = class {
|
|
|
7736
7933
|
});
|
|
7737
7934
|
return poolBirbeRewardTokens;
|
|
7738
7935
|
}
|
|
7936
|
+
async getAllFeeRewards(fee_tokens) {
|
|
7937
|
+
let tx = new Transaction9();
|
|
7938
|
+
fee_tokens.forEach((tokens, lock_id) => {
|
|
7939
|
+
tx = this._getFeeRewards(lock_id, tokens, tx);
|
|
7940
|
+
});
|
|
7941
|
+
return await this._parseFeeRewards(tx);
|
|
7942
|
+
}
|
|
7943
|
+
_getFeeRewards(lock_id, fee_tokens, tx) {
|
|
7944
|
+
if (fee_tokens.length % 2 !== 0) {
|
|
7945
|
+
fee_tokens.push(fee_tokens[0]);
|
|
7946
|
+
}
|
|
7947
|
+
for (let i = 0; i + 1 < fee_tokens.length; i += 2) {
|
|
7948
|
+
tx = this._getFeeRewardsInner(lock_id, fee_tokens[i], fee_tokens[i + 1], tx);
|
|
7949
|
+
}
|
|
7950
|
+
return tx;
|
|
7951
|
+
}
|
|
7952
|
+
_getFeeRewardsInner(lock_id, token_a, token_b, tx) {
|
|
7953
|
+
tx = tx || new Transaction9();
|
|
7954
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
7955
|
+
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
7956
|
+
const typeArguments = [magma_token, token_a, token_b];
|
|
7957
|
+
const args = [tx.object(voter_id), tx.object(lock_id), tx.object(CLOCK_ADDRESS)];
|
|
7958
|
+
const targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_fee_rewards`;
|
|
7959
|
+
tx.moveCall({
|
|
7960
|
+
target: targetFunc,
|
|
7961
|
+
arguments: args,
|
|
7962
|
+
typeArguments
|
|
7963
|
+
});
|
|
7964
|
+
return tx;
|
|
7965
|
+
}
|
|
7966
|
+
async _parseFeeRewards(tx) {
|
|
7967
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
7968
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
7969
|
+
transactionBlock: tx,
|
|
7970
|
+
sender: simulationAccount.address
|
|
7971
|
+
});
|
|
7972
|
+
if (simulateRes.error != null) {
|
|
7973
|
+
throw new Error(`getPoolIncentiveRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
7974
|
+
}
|
|
7975
|
+
const poolFeeRewardTokens = /* @__PURE__ */ new Map();
|
|
7976
|
+
simulateRes.events?.forEach((event) => {
|
|
7977
|
+
if (extractStructTagFromType(event.type).name === `ClaimableVotingFee`) {
|
|
7978
|
+
const { lock_id } = event.parsedJson;
|
|
7979
|
+
if (!poolFeeRewardTokens.has(lock_id)) {
|
|
7980
|
+
poolFeeRewardTokens.set(lock_id, /* @__PURE__ */ new Map());
|
|
7981
|
+
}
|
|
7982
|
+
event.parsedJson.list.contents.forEach((rewardTokens) => {
|
|
7983
|
+
rewardTokens.value.contents.forEach((token) => {
|
|
7984
|
+
if (!poolFeeRewardTokens.get(lock_id)?.has(rewardTokens.key.name)) {
|
|
7985
|
+
poolFeeRewardTokens.get(lock_id)?.set(rewardTokens.key.name, []);
|
|
7986
|
+
}
|
|
7987
|
+
poolFeeRewardTokens.get(lock_id)?.get(rewardTokens.key.name)?.push({
|
|
7988
|
+
kind: "incentiveCoin" /* Incentive */,
|
|
7989
|
+
token_addr: token.key,
|
|
7990
|
+
amount: token.value
|
|
7991
|
+
});
|
|
7992
|
+
});
|
|
7993
|
+
});
|
|
7994
|
+
}
|
|
7995
|
+
});
|
|
7996
|
+
return poolFeeRewardTokens;
|
|
7997
|
+
}
|
|
7739
7998
|
async getPoolFeeRewards(lock_id, tokens) {
|
|
7740
7999
|
const poolFeeRewardTokens = /* @__PURE__ */ new Map();
|
|
7741
8000
|
if (tokens.length === 0) {
|
|
@@ -7786,6 +8045,78 @@ var LockModule = class {
|
|
|
7786
8045
|
});
|
|
7787
8046
|
return poolFeeRewardTokens;
|
|
7788
8047
|
}
|
|
8048
|
+
// params: lock_id => incentive_tokens
|
|
8049
|
+
// lock_id => Pool => rewardTokens
|
|
8050
|
+
async getAllIncentiveRewards(lock_incentive_tokens) {
|
|
8051
|
+
let tx = new Transaction9();
|
|
8052
|
+
lock_incentive_tokens.forEach((tokens, lock_id) => {
|
|
8053
|
+
tx = this._getIncentiveRewards(lock_id, tokens, tx);
|
|
8054
|
+
});
|
|
8055
|
+
return await this._parseIncentiveRewards(tx);
|
|
8056
|
+
}
|
|
8057
|
+
_getIncentiveRewards(lock_id, incentive_tokens, tx) {
|
|
8058
|
+
let i = 0;
|
|
8059
|
+
for (; i + 3 < incentive_tokens.length; i += 3) {
|
|
8060
|
+
this._getIncentiveRewardsInner(lock_id, incentive_tokens.slice(i, i + 3), tx);
|
|
8061
|
+
}
|
|
8062
|
+
return this._getIncentiveRewardsInner(lock_id, incentive_tokens.slice(i), tx);
|
|
8063
|
+
}
|
|
8064
|
+
_getIncentiveRewardsInner(locksId, incentive_tokens, tx) {
|
|
8065
|
+
tx = tx || new Transaction9();
|
|
8066
|
+
if (incentive_tokens.length > 3) {
|
|
8067
|
+
throw Error("Too many tokens");
|
|
8068
|
+
}
|
|
8069
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
8070
|
+
const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
8071
|
+
const typeArguments = [magma_token, ...incentive_tokens];
|
|
8072
|
+
const args = [tx.object(voter_id), tx.object(locksId), tx.object(CLOCK_ADDRESS)];
|
|
8073
|
+
let targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_bribes_${incentive_tokens.length}`;
|
|
8074
|
+
if (incentive_tokens.length === 1) {
|
|
8075
|
+
targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_bribes`;
|
|
8076
|
+
}
|
|
8077
|
+
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
8078
|
+
throw Error("this config simulationAccount is not set right");
|
|
8079
|
+
}
|
|
8080
|
+
tx.moveCall({
|
|
8081
|
+
target: targetFunc,
|
|
8082
|
+
arguments: args,
|
|
8083
|
+
typeArguments
|
|
8084
|
+
});
|
|
8085
|
+
return tx;
|
|
8086
|
+
}
|
|
8087
|
+
async _parseIncentiveRewards(tx) {
|
|
8088
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
8089
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
8090
|
+
transactionBlock: tx,
|
|
8091
|
+
sender: simulationAccount.address
|
|
8092
|
+
});
|
|
8093
|
+
if (simulateRes.error != null) {
|
|
8094
|
+
throw new Error(`getPoolIncentiveRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
8095
|
+
}
|
|
8096
|
+
const poolBribeRewardTokens = /* @__PURE__ */ new Map();
|
|
8097
|
+
simulateRes.events?.forEach((event) => {
|
|
8098
|
+
if (extractStructTagFromType(event.type).name === `ClaimableVotingBribes`) {
|
|
8099
|
+
const { lock_id } = event.parsedJson;
|
|
8100
|
+
if (!poolBribeRewardTokens.has(lock_id)) {
|
|
8101
|
+
poolBribeRewardTokens.set(lock_id, /* @__PURE__ */ new Map());
|
|
8102
|
+
}
|
|
8103
|
+
event.parsedJson.list.contents.forEach((rewardTokens) => {
|
|
8104
|
+
rewardTokens.value.contents.forEach((token) => {
|
|
8105
|
+
if (!poolBribeRewardTokens.get(lock_id)?.has(rewardTokens.key.name)) {
|
|
8106
|
+
poolBribeRewardTokens.get(lock_id)?.set(rewardTokens.key.name, []);
|
|
8107
|
+
}
|
|
8108
|
+
poolBribeRewardTokens.get(lock_id)?.get(rewardTokens.key.name)?.push({
|
|
8109
|
+
kind: "incentiveCoin" /* Incentive */,
|
|
8110
|
+
token_addr: token.key,
|
|
8111
|
+
amount: token.value
|
|
8112
|
+
});
|
|
8113
|
+
});
|
|
8114
|
+
});
|
|
8115
|
+
}
|
|
8116
|
+
});
|
|
8117
|
+
return poolBribeRewardTokens;
|
|
8118
|
+
}
|
|
8119
|
+
// coin => pool => amount
|
|
7789
8120
|
async getPoolIncentiveRewards(lock_id, incentive_tokens) {
|
|
7790
8121
|
const poolBribeRewardTokens = /* @__PURE__ */ new Map();
|
|
7791
8122
|
if (incentive_tokens.length === 0) {
|
|
@@ -7812,14 +8143,14 @@ var LockModule = class {
|
|
|
7812
8143
|
if (incentive_tokens.length === 1) {
|
|
7813
8144
|
targetFunc = `${integrate.published_at}::${Voter}::claimable_voting_bribes`;
|
|
7814
8145
|
}
|
|
8146
|
+
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
8147
|
+
throw Error("this config simulationAccount is not set right");
|
|
8148
|
+
}
|
|
7815
8149
|
tx.moveCall({
|
|
7816
8150
|
target: targetFunc,
|
|
7817
8151
|
arguments: args,
|
|
7818
8152
|
typeArguments
|
|
7819
8153
|
});
|
|
7820
|
-
if (!checkInvalidSuiAddress(simulationAccount.address)) {
|
|
7821
|
-
throw Error("this config simulationAccount is not set right");
|
|
7822
|
-
}
|
|
7823
8154
|
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
7824
8155
|
transactionBlock: tx,
|
|
7825
8156
|
sender: simulationAccount.address
|
|
@@ -9402,7 +9733,6 @@ var GaugeModule = class {
|
|
|
9402
9733
|
const poolGauger = /* @__PURE__ */ new Map();
|
|
9403
9734
|
simulateRes.events?.forEach((item) => {
|
|
9404
9735
|
const { gauges } = item.parsedJson;
|
|
9405
|
-
console.log("parsedJson", item.parsedJson);
|
|
9406
9736
|
item.parsedJson.pools.map((pool, index) => {
|
|
9407
9737
|
poolGauger.set(pool, gauges[index]);
|
|
9408
9738
|
});
|
|
@@ -9469,6 +9799,21 @@ var GaugeModule = class {
|
|
|
9469
9799
|
});
|
|
9470
9800
|
return tx;
|
|
9471
9801
|
}
|
|
9802
|
+
async getAllRewardByPositions(paramsList) {
|
|
9803
|
+
const tx = new Transaction11();
|
|
9804
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
9805
|
+
const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
9806
|
+
paramsList.forEach((params) => {
|
|
9807
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB, magma_token];
|
|
9808
|
+
const args = [tx.object(params.gaugeId), tx.object(params.poolId), tx.object(params.positionId), tx.object(CLOCK_ADDRESS)];
|
|
9809
|
+
tx.moveCall({
|
|
9810
|
+
target: `${integrate.published_at}::${Gauge}::get_reward_by_position`,
|
|
9811
|
+
arguments: args,
|
|
9812
|
+
typeArguments
|
|
9813
|
+
});
|
|
9814
|
+
});
|
|
9815
|
+
return tx;
|
|
9816
|
+
}
|
|
9472
9817
|
async getEpochRewardByPool(pool, incentive_tokens) {
|
|
9473
9818
|
const tx = new Transaction11();
|
|
9474
9819
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|