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/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" diff --git a/src/managers/refund/RefundManager.ts b/src/managers/refund/RefundManager.ts index c1865fe..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 @@ -140,6 +142,126 @@ 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 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,