From 9dd7c915cb1d38635cea04a3a3c3c7bf20e3cfb4 Mon Sep 17 00:00:00 2001 From: avernikoz Date: Thu, 21 Mar 2024 13:26:41 +0300 Subject: [PATCH 1/3] v2.4.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b6f77f3..345b92e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@avernikoz/rinbot-sui-sdk", - "version": "2.4.8", + "version": "2.4.9", "description": "Sui Trading Bot SDK (typescript)", "files": [ "dist" From 23f32aee5588c26923a7f838b4c0ee5e16ed3e3a Mon Sep 17 00:00:00 2001 From: avernikoz Date: Thu, 21 Mar 2024 13:55:17 +0300 Subject: [PATCH 2/3] add getUnclaimedAddressesList --- src/managers/refund/RefundManager.ts | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/managers/refund/RefundManager.ts b/src/managers/refund/RefundManager.ts index c1865fe..29468a5 100644 --- a/src/managers/refund/RefundManager.ts +++ b/src/managers/refund/RefundManager.ts @@ -140,6 +140,43 @@ export class RefundManagerSingleton { return phase; } + public async getUnclaimedAddressesList({ + poolObjectId, + transaction, + }: { + poolObjectId: string; + transaction?: TransactionBlock; + }) { + const tx = transaction ?? new TransactionBlock(); + + const txRes = tx.moveCall({ + target: `${RefundManagerSingleton.REFUND_PACKAGE_ADDRESS}::refund::unclaimed`, + typeArguments: [], + arguments: [obj(tx, poolObjectId)], + }); + + tx.setGasBudget(RefundManagerSingleton.REFUND_GAS_BUGET); + + const res = await this.provider.devInspectTransactionBlock({ + sender: RefundManagerSingleton.SIMLATION_ACCOUNT_ADDRESS, + transactionBlock: tx, + }); + + if (!res.results) { + throw new Error("No results found for the request phase request"); + } + + const returnValues = res.results[0].returnValues; + + if (!returnValues) { + throw new Error("Return values are undefined"); + } + + const table = returnValues[0][0]; + + return table; + } + public static getAllowBoostedClaim({ publisherObjectId, poolObjectId, From 6faba8504f1eb75f1fed7d017e59e6e2c9d2db34 Mon Sep 17 00:00:00 2001 From: avernikoz Date: Thu, 21 Mar 2024 14:17:49 +0300 Subject: [PATCH 3/3] add getClaimAmount method to refund --- examples/refund/get-claim-amount.ts | 14 +++ .../refund/get-unclaimed-addresses-list.ts | 13 +++ src/managers/refund/RefundManager.ts | 85 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 examples/refund/get-claim-amount.ts create mode 100644 examples/refund/get-unclaimed-addresses-list.ts diff --git a/examples/refund/get-claim-amount.ts b/examples/refund/get-claim-amount.ts new file mode 100644 index 0000000..54b6220 --- /dev/null +++ b/examples/refund/get-claim-amount.ts @@ -0,0 +1,14 @@ +import { RefundManagerSingleton } from "../../src"; +import { suiProviderUrl, user } from "../common"; + +// yarn ts-node examples/refund/get-claim-amount.ts +(async () => { + const refundManager = RefundManagerSingleton.getInstance(suiProviderUrl); + + const result = await refundManager.getClaimAmount({ + poolObjectId: RefundManagerSingleton.REFUND_POOL_OBJECT_ID, + affectedAddress: user, + }); + + console.debug("result: ", result); +})(); diff --git a/examples/refund/get-unclaimed-addresses-list.ts b/examples/refund/get-unclaimed-addresses-list.ts new file mode 100644 index 0000000..93e0539 --- /dev/null +++ b/examples/refund/get-unclaimed-addresses-list.ts @@ -0,0 +1,13 @@ +import { RefundManagerSingleton } from "../../src"; +import { suiProviderUrl } from "../common"; + +// yarn ts-node examples/refund/get-unclaimed-addresses-list.ts +(async () => { + const refundManager = RefundManagerSingleton.getInstance(suiProviderUrl); + + const result = await refundManager.getUnclaimedAddressesList({ + poolObjectId: RefundManagerSingleton.REFUND_POOL_OBJECT_ID, + }); + + console.debug("result: ", result); +})(); diff --git a/src/managers/refund/RefundManager.ts b/src/managers/refund/RefundManager.ts index 29468a5..9d477f8 100644 --- a/src/managers/refund/RefundManager.ts +++ b/src/managers/refund/RefundManager.ts @@ -6,6 +6,8 @@ import { verifyPersonalMessage } from "@mysten/sui.js/verify"; import { ObjectArg } from "../../transactions/types"; import { obj } from "../../transactions/utils"; import { hexStringToByteArray } from "./utils"; +import BigNumber from "bignumber.js"; +import { SUI_DENOMINATOR } from "../.."; /** * @class RefundManagerSingleton @@ -177,6 +179,89 @@ export class RefundManagerSingleton { return table; } + public async getClaimAmountNormal({ + poolObjectId, + affectedAddress, + }: { + poolObjectId: string; + affectedAddress: string; + }) { + const tx = new TransactionBlock(); + + const txRes = tx.moveCall({ + target: `${RefundManagerSingleton.REFUND_PACKAGE_ADDRESS}::refund::amount_to_claim`, + typeArguments: [], + arguments: [obj(tx, poolObjectId), tx.pure(affectedAddress)], + }); + + tx.setGasBudget(RefundManagerSingleton.REFUND_GAS_BUGET); + + const res = await this.provider.devInspectTransactionBlock({ + sender: RefundManagerSingleton.SIMLATION_ACCOUNT_ADDRESS, + transactionBlock: tx, + }); + + if (!res.results) { + throw new Error("No results found for the request phase request"); + } + + const returnValues = res.results[0].returnValues; + + if (!returnValues) { + throw new Error("Return values are undefined"); + } + + const amount = returnValues[0][0][0]; + + return { mist: amount, sui: new BigNumber(amount).div(SUI_DENOMINATOR).toString() }; + } + + public async getClaimAmountBoosted({ + poolObjectId, + affectedAddress, + }: { + poolObjectId: string; + affectedAddress: string; + }) { + const tx = new TransactionBlock(); + + const txRes = tx.moveCall({ + target: `${RefundManagerSingleton.REFUND_PACKAGE_ADDRESS}::refund::amount_to_claim_boosted`, + typeArguments: [], + arguments: [obj(tx, poolObjectId), tx.pure(affectedAddress)], + }); + + tx.setGasBudget(RefundManagerSingleton.REFUND_GAS_BUGET); + + const res = await this.provider.devInspectTransactionBlock({ + sender: RefundManagerSingleton.SIMLATION_ACCOUNT_ADDRESS, + transactionBlock: tx, + }); + + if (!res.results) { + throw new Error("No results found for the request phase request"); + } + + const returnValues = res.results[0].returnValues; + + if (!returnValues) { + throw new Error("Return values are undefined"); + } + + const amount = returnValues[0][0][0]; + + return { mist: amount, sui: new BigNumber(amount).div(SUI_DENOMINATOR).toString() }; + } + + public async getClaimAmount({ poolObjectId, affectedAddress }: { poolObjectId: string; affectedAddress: string }) { + const [normalRefund, boosedRefund] = await Promise.all([ + this.getClaimAmountNormal({ poolObjectId, affectedAddress }), + this.getClaimAmountBoosted({ poolObjectId, affectedAddress }), + ]); + + return { normalRefund, boosedRefund }; + } + public static getAllowBoostedClaim({ publisherObjectId, poolObjectId,