Skip to content

Commit

Permalink
implement getBoostedClaimCap
Browse files Browse the repository at this point in the history
  • Loading branch information
avernikoz committed Mar 21, 2024
1 parent be46e43 commit 3635295
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/managers/refund/RefundManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { obj } from "../../transactions/utils";
import { hexStringToByteArray } from "./utils";
import BigNumber from "bignumber.js";
import { SUI_DENOMINATOR } from "../..";
import { getAllOwnedObjects } from "../../providers/utils/getAllOwnedObjects";

/**
* @class RefundManagerSingleton
Expand All @@ -20,6 +21,7 @@ export class RefundManagerSingleton {
public static REFUND_PACKAGE_ADDRESS_READ = "";
public static REFUND_POOL_OBJECT_ID = "0xf8f7e8e3c4a4c08e5a334c45ed0b3c669b3b86098e7fc1ff9cfe062105c1f74e";
public static REFUND_POOL_PUBLISHER_OBJECT_ID = "0x492ef3058c292d1d343545001c65ff42baef932a4fb06be79968137ec381a4fc";
public static REFUND_BOOSTED_CLAIM_CAP_STRUCT_TYPE_NAME = "BoostedClaimCap";

public static REFUND_GAS_BUGET = 50_000_000;

Expand Down Expand Up @@ -263,9 +265,23 @@ export class RefundManagerSingleton {
}

public async getBoostedClaimCap({ ownerAddress }: { ownerAddress: string }) {
const objectId = "";
// Assuming we have only 1 allowed per user by design
const allBoostedClaimCapObjects = await getAllOwnedObjects({
provider: this.provider,
options: {
owner: ownerAddress,
// TODO: Check for correctness
filter: { StructType: RefundManagerSingleton.REFUND_BOOSTED_CLAIM_CAP_STRUCT_TYPE_NAME },
},
});

const boostedClaimCapObject = allBoostedClaimCapObjects[0];

if (!boostedClaimCapObject.data) {
throw new Error("No boosted claim cap object found");
}

return objectId;
return boostedClaimCapObject.data.objectId;
}

public static getAllowBoostedClaim({
Expand Down
38 changes: 38 additions & 0 deletions src/providers/utils/getAllOwnedObjects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { GetOwnedObjectsParams, PaginatedObjectsResponse, SuiClient, SuiObjectResponse } from "@mysten/sui.js/client";

/**
* Retrieves all objects owned from the SuiClient based on provided owner address, respecting limitations.
* @throws {Error} If any error occurs during the retrieval process.
* @description
* The function fetches objects from SuiClient based on the provided owner address.
* It respects the limitation of `getOwnedObjects` (50 objectIds per request) by
* splitting the requests into chunks.
*/
export async function getAllOwnedObjects({
provider,
options,
}: {
provider: SuiClient;
options: GetOwnedObjectsParams;
}) {
const allOwnedObjects: SuiObjectResponse[] = [];
let nextCursor: string | undefined | null = null;
let objects: PaginatedObjectsResponse = await provider.getOwnedObjects(options);

// Fetching and combining part
while (objects.hasNextPage) {
const userObjects: SuiObjectResponse[] = objects.data;
allOwnedObjects.push(...userObjects);

nextCursor = objects.nextCursor;
objects = await provider.getOwnedObjects({
...options,
cursor: nextCursor,
});
}

const userObjects: SuiObjectResponse[] = objects.data;
allOwnedObjects.push(...userObjects);

return allOwnedObjects;
}

0 comments on commit 3635295

Please sign in to comment.