abel-ghost-sdk 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ import { AlgorandClient } from "@algorandfoundation/algokit-utils";
2
+ import { AbelReaderSDK } from "./generated/AbelReaderSDK.js";
3
+ export declare class AbelGhostSDK {
4
+ static baseSDK: typeof AbelReaderSDK;
5
+ algorand: AlgorandClient;
6
+ registryAppId?: bigint;
7
+ baseSDK: AbelReaderSDK;
8
+ concurrency: number;
9
+ constructor({ algorand, registryAppId, concurrency, ghostAppId, }: {
10
+ algorand: AlgorandClient;
11
+ concurrency?: number;
12
+ registryAppId?: number | bigint;
13
+ ghostAppId?: bigint;
14
+ });
15
+ getAssetsTinyLabels(assetIds: number[] | bigint[]): Promise<import("./generated/AbelReaderSDK.js").AssetTinyLabels[]>;
16
+ getAssetsTiny(assetIds: number[] | bigint[]): Promise<import("./generated/AbelReaderSDK.js").AssetTinyLabels[]>;
17
+ }
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { AbelReaderSDK } from "./generated/AbelReaderSDK.js";
8
+ import { chunked } from "./utils/chunked.js";
9
+ export class AbelGhostSDK {
10
+ static baseSDK = AbelReaderSDK;
11
+ algorand;
12
+ registryAppId;
13
+ baseSDK;
14
+ concurrency;
15
+ constructor({ algorand, registryAppId, concurrency = 4, ghostAppId, }) {
16
+ this.algorand = algorand;
17
+ this.registryAppId = registryAppId !== undefined ? BigInt(registryAppId) : undefined;
18
+ this.concurrency = concurrency;
19
+ this.baseSDK = new AbelReaderSDK({
20
+ algorand: this.algorand,
21
+ readerAccount: "Y76M3MSY6DKBRHBL7C3NNDXGS5IIMQVQVUAB6MP4XEMMGVF2QWNPL226CA",
22
+ ghostAppId,
23
+ });
24
+ }
25
+ getAssetsTinyLabels(assetIds) {
26
+ if (!this.registryAppId)
27
+ throw new Error("Can not get labels without registry app id");
28
+ console.log({ assetIds, abelAppId: this.registryAppId });
29
+ return this.baseSDK.getAssetsTiny({
30
+ methodArgsOrArgsArray: { assetIds, abelAppId: this.registryAppId },
31
+ extraMethodCallArgs: { extraFee: (1000).microAlgo() },
32
+ });
33
+ }
34
+ getAssetsTiny(assetIds) {
35
+ return this.baseSDK.getAssetsTiny({
36
+ methodArgsOrArgsArray: { assetIds, abelAppId: 0n },
37
+ });
38
+ }
39
+ }
40
+ __decorate([
41
+ chunked(63)
42
+ ], AbelGhostSDK.prototype, "getAssetsTinyLabels", null);
43
+ __decorate([
44
+ chunked(128)
45
+ ], AbelGhostSDK.prototype, "getAssetsTiny", null);
@@ -0,0 +1 @@
1
+ export declare function chunk<T>(array: T[], size: number): T[][];
@@ -0,0 +1,9 @@
1
+ export function chunk(array, size) {
2
+ const chunkedArr = [];
3
+ let index = 0;
4
+ while (index < array.length) {
5
+ chunkedArr.push(array.slice(index, size + index));
6
+ index += size;
7
+ }
8
+ return chunkedArr;
9
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Decorator that automatically chunks array arguments and aggregates results
3
+ * @param chunkSize - The maximum size of each chunk
4
+ * @param chunkArgIndex - The index of the argument to chunk
5
+ * @returns Method decorator
6
+ */
7
+ export declare function chunked(chunkSize: number, chunkArgIndex?: number): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
@@ -0,0 +1,35 @@
1
+ import pMap from "p-map";
2
+ import { chunk } from "./chunk.js";
3
+ /**
4
+ * Decorator that automatically chunks array arguments and aggregates results
5
+ * @param chunkSize - The maximum size of each chunk
6
+ * @param chunkArgIndex - The index of the argument to chunk
7
+ * @returns Method decorator
8
+ */
9
+ export function chunked(chunkSize, chunkArgIndex = 0) {
10
+ return function (target, propertyKey, descriptor) {
11
+ const originalMethod = descriptor.value;
12
+ descriptor.value = async function (...args) {
13
+ // If appIds array is smaller than or equal to chunk size, call original method directly
14
+ if (args[chunkArgIndex].length <= chunkSize) {
15
+ // No chunking needed, calling original method directly
16
+ return originalMethod.apply(this, args);
17
+ }
18
+ // read concurrency from 'this' if available
19
+ const concurrency = this && typeof this.concurrency === "number" ? this.concurrency : 2;
20
+ // Chunk the appIds array
21
+ const chunks = chunk(args[chunkArgIndex], chunkSize);
22
+ // pMap over chunks with concurrency control. Will be returned in order by pMap.
23
+ const results = await pMap(chunks, async (chunkedIds) => {
24
+ // reconstruct the arguments with the chunked appIds
25
+ const applyArgs = chunkArgIndex === 0
26
+ ? [chunkedIds, ...args.slice(1)]
27
+ : [...args.slice(0, chunkArgIndex), chunkedIds, ...args.slice(chunkArgIndex + 1)];
28
+ return originalMethod.apply(this, applyArgs);
29
+ }, { concurrency });
30
+ // Flatten the results into a single array
31
+ return results.flat();
32
+ };
33
+ return descriptor;
34
+ };
35
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "abel-ghost-sdk",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/d13co/abel-ghost-sdk.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/d13co/abel-ghost-sdk/issues"
11
+ },
12
+ "homepage": "https://github.com/d13co/abel-ghost-sdk/tree/main/projects/sdk#readme",
13
+ "main": "dist/index.js",
14
+ "types": "dist/index.d.ts",
15
+ "files": [
16
+ "dist/"
17
+ ],
18
+ "scripts": {
19
+ "prebuild": "cp ../contracts/smart_contracts/artifacts/abel_reader/AbelReaderSDK.ts src/generated",
20
+ "build": "tsc"
21
+ },
22
+ "keywords": [],
23
+ "author": "",
24
+ "license": "MIT",
25
+ "packageManager": "pnpm@10.11.0",
26
+ "dependencies": {
27
+ "p-map": "^7.0.4"
28
+ },
29
+ "peerDependencies": {
30
+ "@algorandfoundation/algokit-utils": "^9.2.0",
31
+ "algosdk": "^3.5.2"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^25.0.3",
35
+ "tsx": "^4.21.0"
36
+ }
37
+ }