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,511 @@
1
+ import { getArc56ReturnValue, getABIStructFromABITuple } from '@algorandfoundation/algokit-utils/types/app-arc56';
2
+ import { AppClient as _AppClient, } from '@algorandfoundation/algokit-utils/types/app-client';
3
+ import { AppFactory as _AppFactory } from '@algorandfoundation/algokit-utils/types/app-factory';
4
+ export const APP_SPEC = { "name": "AbelReader", "structs": { "AssetTinyLabels": [{ "name": "name", "type": "string" }, { "name": "unitName", "type": "string" }, { "name": "decimals", "type": "uint8" }, { "name": "labels", "type": "string[]" }] }, "methods": [{ "name": "getAssetsTiny", "args": [{ "type": "uint64[]", "name": "assetIds" }, { "type": "uint64", "name": "abelAppId" }], "returns": { "type": "(string,string,uint8,string[])", "struct": "AssetTinyLabels" }, "actions": { "create": ["NoOp"], "call": ["NoOp"] }, "readonly": true, "events": [], "recommendations": {} }], "arcs": [22, 28], "networks": {}, "state": { "schema": { "global": { "ints": 0, "bytes": 0 }, "local": { "ints": 0, "bytes": 0 } }, "keys": { "global": {}, "local": {}, "box": {} }, "maps": { "global": {}, "local": {}, "box": {} } }, "bareActions": { "create": [], "call": [] }, "sourceInfo": { "approval": { "sourceInfo": [{ "pc": [170], "errorMessage": "Bytes has valid prefix" }, { "pc": [23], "errorMessage": "OnCompletion must be NoOp" }, { "pc": [185, 192, 195], "errorMessage": "asset exists" }, { "pc": [79], "errorMessage": "index access is out of bounds" }, { "pc": [38], "errorMessage": "invalid array length header" }, { "pc": [50], "errorMessage": "invalid number of bytes for arc4.dynamic_array<asset>" }, { "pc": [58, 175], "errorMessage": "invalid number of bytes for arc4.uint64" }, { "pc": [201], "errorMessage": "overflow" }], "pcOffsetMethod": "none" }, "clear": { "sourceInfo": [], "pcOffsetMethod": "none" } }, "source": { "approval": "I3ByYWdtYSB2ZXJzaW9uIDExCiNwcmFnbWEgdHlwZXRy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mRmb3VuZGF0aW9uL2FsZ29yYW5kLXR5cGVzY3JpcHQvYmFzZS1jb250cmFjdC5kLnRzOjpCYXNlQ29udHJhY3QuY2xlYXJTdGF0ZVByb2dyYW0oKSAtPiB1aW50NjQ6Cm1haW46CiAgICBwdXNoaW50IDEgLy8gMQogICAgcmV0dXJuCg==" }, "byteCode": { "approval": "CyADCAABgATVqzNmNhoAjgEAAQAxGRREQgAAI0cDgAA2GgFHAiNZSU4CIguBAghMFRJENhoCSRUiEkQXI0lLAwxBAN9LA1cCAEsBIgtKIlhFC1tJRQZxC0UBQAAYgA0ABwAJAAALAAAAAAAAsEkkCEUBQv/IsYAEl/QKirIaSwiyGoAEAAJwdrIaI7IZSwGyGIEGshAjsgGztD5JVwQATFcABIAEFR98dRJESRUiEkQXSwVJcQRMRQpESXEDTEUJRHEBRBZJkyIORFcHAUUJQABEgAIAAEsHSRUWVwYCTFBJFYEHCEsISRUWVwYCTFBLARZXBgKAAgAHTFBLARVPAwhMSwxQTBZXBgJQTwJQTFBMULBC/1eACAABAAIAAnB2Qv+zgBEVH3x1AAcACQAACwAAAAAAALAkQw==", "clear": "C4EBQw==" }, "events": [], "templateVariables": {} };
5
+ class BinaryStateValue {
6
+ value;
7
+ constructor(value) {
8
+ this.value = value;
9
+ }
10
+ asByteArray() {
11
+ return this.value;
12
+ }
13
+ asString() {
14
+ return this.value !== undefined ? Buffer.from(this.value).toString('utf-8') : undefined;
15
+ }
16
+ }
17
+ /**
18
+ * Converts the ABI tuple representation of a AssetTinyLabels to the struct representation
19
+ */
20
+ export function AssetTinyLabelsFromTuple(abiTuple) {
21
+ return getABIStructFromABITuple(abiTuple, APP_SPEC.structs.AssetTinyLabels, APP_SPEC.structs);
22
+ }
23
+ /**
24
+ * Exposes methods for constructing `AppClient` params objects for ABI calls to the AbelReader smart contract
25
+ */
26
+ export class AbelReaderParamsFactory {
27
+ /**
28
+ * Gets available create ABI call param factories
29
+ */
30
+ static get create() {
31
+ return {
32
+ _resolveByMethod(params) {
33
+ switch (params.method) {
34
+ case 'getAssetsTiny':
35
+ case 'getAssetsTiny(uint64[],uint64)(string,string,uint8,string[])':
36
+ return AbelReaderParamsFactory.create.getAssetsTiny(params);
37
+ }
38
+ throw new Error(`Unknown ' + verb + ' method`);
39
+ },
40
+ /**
41
+ * Constructs create ABI call params for the AbelReader smart contract using the getAssetsTiny(uint64[],uint64)(string,string,uint8,string[]) ABI method
42
+ *
43
+ * @param params Parameters for the call
44
+ * @returns An `AppClientMethodCallParams` object for the call
45
+ */
46
+ getAssetsTiny(params) {
47
+ return {
48
+ ...params,
49
+ method: 'getAssetsTiny(uint64[],uint64)(string,string,uint8,string[])',
50
+ args: Array.isArray(params.args) ? params.args : [params.args.assetIds, params.args.abelAppId],
51
+ };
52
+ },
53
+ };
54
+ }
55
+ /**
56
+ * Constructs a no op call for the getAssetsTiny(uint64[],uint64)(string,string,uint8,string[]) ABI method
57
+ *
58
+ * @param params Parameters for the call
59
+ * @returns An `AppClientMethodCallParams` object for the call
60
+ */
61
+ static getAssetsTiny(params) {
62
+ return {
63
+ ...params,
64
+ method: 'getAssetsTiny(uint64[],uint64)(string,string,uint8,string[])',
65
+ args: Array.isArray(params.args) ? params.args : [params.args.assetIds, params.args.abelAppId],
66
+ };
67
+ }
68
+ }
69
+ /**
70
+ * A factory to create and deploy one or more instance of the AbelReader smart contract and to create one or more app clients to interact with those (or other) app instances
71
+ */
72
+ class AbelReaderFactory {
73
+ /**
74
+ * The underlying `AppFactory` for when you want to have more flexibility
75
+ */
76
+ appFactory;
77
+ /**
78
+ * Creates a new instance of `AbelReaderFactory`
79
+ *
80
+ * @param params The parameters to initialise the app factory with
81
+ */
82
+ constructor(params) {
83
+ this.appFactory = new _AppFactory({
84
+ ...params,
85
+ appSpec: APP_SPEC,
86
+ });
87
+ }
88
+ /** The name of the app (from the ARC-32 / ARC-56 app spec or override). */
89
+ get appName() {
90
+ return this.appFactory.appName;
91
+ }
92
+ /** The ARC-56 app spec being used */
93
+ get appSpec() {
94
+ return APP_SPEC;
95
+ }
96
+ /** A reference to the underlying `AlgorandClient` this app factory is using. */
97
+ get algorand() {
98
+ return this.appFactory.algorand;
99
+ }
100
+ /**
101
+ * Returns a new `AppClient` client for an app instance of the given ID.
102
+ *
103
+ * Automatically populates appName, defaultSender and source maps from the factory
104
+ * if not specified in the params.
105
+ * @param params The parameters to create the app client
106
+ * @returns The `AppClient`
107
+ */
108
+ getAppClientById(params) {
109
+ return new AbelReaderClient(this.appFactory.getAppClientById(params));
110
+ }
111
+ /**
112
+ * Returns a new `AppClient` client, resolving the app by creator address and name
113
+ * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
114
+ *
115
+ * Automatically populates appName, defaultSender and source maps from the factory
116
+ * if not specified in the params.
117
+ * @param params The parameters to create the app client
118
+ * @returns The `AppClient`
119
+ */
120
+ async getAppClientByCreatorAndName(params) {
121
+ return new AbelReaderClient(await this.appFactory.getAppClientByCreatorAndName(params));
122
+ }
123
+ /**
124
+ * Idempotently deploys the AbelReader smart contract.
125
+ *
126
+ * @param params The arguments for the contract calls and any additional parameters for the call
127
+ * @returns The deployment result
128
+ */
129
+ async deploy(params = {}) {
130
+ const result = await this.appFactory.deploy({
131
+ ...params,
132
+ createParams: params.createParams?.method ? AbelReaderParamsFactory.create._resolveByMethod(params.createParams) : params.createParams ? params.createParams : undefined,
133
+ });
134
+ return { result: result.result, appClient: new AbelReaderClient(result.appClient) };
135
+ }
136
+ /**
137
+ * Get parameters to create transactions (create and deploy related calls) for the current app. A good mental model for this is that these parameters represent a deferred transaction creation.
138
+ */
139
+ params = {
140
+ /**
141
+ * Gets available create methods
142
+ */
143
+ create: {
144
+ /**
145
+ * Creates a new instance of the AbelReader smart contract using the getAssetsTiny(uint64[],uint64)(string,string,uint8,string[]) ABI method.
146
+ *
147
+ * @param params The params for the smart contract call
148
+ * @returns The create params
149
+ */
150
+ getAssetsTiny: (params) => {
151
+ return this.appFactory.params.create(AbelReaderParamsFactory.create.getAssetsTiny(params));
152
+ },
153
+ },
154
+ };
155
+ /**
156
+ * Create transactions for the current app
157
+ */
158
+ createTransaction = {
159
+ /**
160
+ * Gets available create methods
161
+ */
162
+ create: {
163
+ /**
164
+ * Creates a new instance of the AbelReader smart contract using the getAssetsTiny(uint64[],uint64)(string,string,uint8,string[]) ABI method.
165
+ *
166
+ * @param params The params for the smart contract call
167
+ * @returns The create transaction
168
+ */
169
+ getAssetsTiny: (params) => {
170
+ return this.appFactory.createTransaction.create(AbelReaderParamsFactory.create.getAssetsTiny(params));
171
+ },
172
+ },
173
+ };
174
+ /**
175
+ * Send calls to the current app
176
+ */
177
+ send = {
178
+ /**
179
+ * Gets available create methods
180
+ */
181
+ create: {
182
+ /**
183
+ * Creates a new instance of the AbelReader smart contract using an ABI method call using the getAssetsTiny(uint64[],uint64)(string,string,uint8,string[]) ABI method.
184
+ *
185
+ * @param params The params for the smart contract call
186
+ * @returns The create result
187
+ */
188
+ getAssetsTiny: async (params) => {
189
+ const result = await this.appFactory.send.create(AbelReaderParamsFactory.create.getAssetsTiny(params));
190
+ return { result: { ...result.result, return: result.result.return }, appClient: new AbelReaderClient(result.appClient) };
191
+ },
192
+ },
193
+ };
194
+ }
195
+ /**
196
+ * A client to make calls to the AbelReader smart contract
197
+ */
198
+ class AbelReaderClient {
199
+ /**
200
+ * The underlying `AppClient` for when you want to have more flexibility
201
+ */
202
+ appClient;
203
+ constructor(appClientOrParams) {
204
+ this.appClient = appClientOrParams instanceof _AppClient ? appClientOrParams : new _AppClient({
205
+ ...appClientOrParams,
206
+ appSpec: APP_SPEC,
207
+ });
208
+ }
209
+ /**
210
+ * Checks for decode errors on the given return value and maps the return value to the return type for the given method
211
+ * @returns The typed return value or undefined if there was no value
212
+ */
213
+ decodeReturnValue(method, returnValue) {
214
+ return returnValue !== undefined ? getArc56ReturnValue(returnValue, this.appClient.getABIMethod(method), APP_SPEC.structs) : undefined;
215
+ }
216
+ /**
217
+ * Returns a new `AbelReaderClient` client, resolving the app by creator address and name
218
+ * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
219
+ * @param params The parameters to create the app client
220
+ */
221
+ static async fromCreatorAndName(params) {
222
+ return new AbelReaderClient(await _AppClient.fromCreatorAndName({ ...params, appSpec: APP_SPEC }));
223
+ }
224
+ /**
225
+ * Returns an `AbelReaderClient` instance for the current network based on
226
+ * pre-determined network-specific app IDs specified in the ARC-56 app spec.
227
+ *
228
+ * If no IDs are in the app spec or the network isn't recognised, an error is thrown.
229
+ * @param params The parameters to create the app client
230
+ */
231
+ static async fromNetwork(params) {
232
+ return new AbelReaderClient(await _AppClient.fromNetwork({ ...params, appSpec: APP_SPEC }));
233
+ }
234
+ /** The ID of the app instance this client is linked to. */
235
+ get appId() {
236
+ return this.appClient.appId;
237
+ }
238
+ /** The app address of the app instance this client is linked to. */
239
+ get appAddress() {
240
+ return this.appClient.appAddress;
241
+ }
242
+ /** The name of the app. */
243
+ get appName() {
244
+ return this.appClient.appName;
245
+ }
246
+ /** The ARC-56 app spec being used */
247
+ get appSpec() {
248
+ return this.appClient.appSpec;
249
+ }
250
+ /** A reference to the underlying `AlgorandClient` this app client is using. */
251
+ get algorand() {
252
+ return this.appClient.algorand;
253
+ }
254
+ /**
255
+ * Get parameters to create transactions for the current app. A good mental model for this is that these parameters represent a deferred transaction creation.
256
+ */
257
+ params = {
258
+ /**
259
+ * Makes a clear_state call to an existing instance of the AbelReader smart contract.
260
+ *
261
+ * @param params The params for the bare (raw) call
262
+ * @returns The clearState result
263
+ */
264
+ clearState: (params) => {
265
+ return this.appClient.params.bare.clearState(params);
266
+ },
267
+ /**
268
+ * Makes a call to the AbelReader smart contract using the `getAssetsTiny(uint64[],uint64)(string,string,uint8,string[])` ABI method.
269
+ *
270
+ * This method is a readonly method; calling it with onComplete of NoOp will result in a simulated transaction rather than a real transaction.
271
+ *
272
+ * @param params The params for the smart contract call
273
+ * @returns The call params
274
+ */
275
+ getAssetsTiny: (params) => {
276
+ return this.appClient.params.call(AbelReaderParamsFactory.getAssetsTiny(params));
277
+ },
278
+ };
279
+ /**
280
+ * Create transactions for the current app
281
+ */
282
+ createTransaction = {
283
+ /**
284
+ * Makes a clear_state call to an existing instance of the AbelReader smart contract.
285
+ *
286
+ * @param params The params for the bare (raw) call
287
+ * @returns The clearState result
288
+ */
289
+ clearState: (params) => {
290
+ return this.appClient.createTransaction.bare.clearState(params);
291
+ },
292
+ /**
293
+ * Makes a call to the AbelReader smart contract using the `getAssetsTiny(uint64[],uint64)(string,string,uint8,string[])` ABI method.
294
+ *
295
+ * This method is a readonly method; calling it with onComplete of NoOp will result in a simulated transaction rather than a real transaction.
296
+ *
297
+ * @param params The params for the smart contract call
298
+ * @returns The call transaction
299
+ */
300
+ getAssetsTiny: (params) => {
301
+ return this.appClient.createTransaction.call(AbelReaderParamsFactory.getAssetsTiny(params));
302
+ },
303
+ };
304
+ /**
305
+ * Send calls to the current app
306
+ */
307
+ send = {
308
+ /**
309
+ * Makes a clear_state call to an existing instance of the AbelReader smart contract.
310
+ *
311
+ * @param params The params for the bare (raw) call
312
+ * @returns The clearState result
313
+ */
314
+ clearState: (params) => {
315
+ return this.appClient.send.bare.clearState(params);
316
+ },
317
+ /**
318
+ * Makes a call to the AbelReader smart contract using the `getAssetsTiny(uint64[],uint64)(string,string,uint8,string[])` ABI method.
319
+ *
320
+ * This method is a readonly method; calling it with onComplete of NoOp will result in a simulated transaction rather than a real transaction.
321
+ *
322
+ * @param params The params for the smart contract call
323
+ * @returns The call result
324
+ */
325
+ getAssetsTiny: async (params) => {
326
+ const result = await this.appClient.send.call(AbelReaderParamsFactory.getAssetsTiny(params));
327
+ return { ...result, return: result.return };
328
+ },
329
+ };
330
+ /**
331
+ * Clone this app client with different params
332
+ *
333
+ * @param params The params to use for the the cloned app client. Omit a param to keep the original value. Set a param to override the original value. Setting to undefined will clear the original value.
334
+ * @returns A new app client with the altered params
335
+ */
336
+ clone(params) {
337
+ return new AbelReaderClient(this.appClient.clone(params));
338
+ }
339
+ /**
340
+ * Makes a readonly (simulated) call to the AbelReader smart contract using the `getAssetsTiny(uint64[],uint64)(string,string,uint8,string[])` ABI method.
341
+ *
342
+ * This method is a readonly method; calling it with onComplete of NoOp will result in a simulated transaction rather than a real transaction.
343
+ *
344
+ * @param params The params for the smart contract call
345
+ * @returns The call result
346
+ */
347
+ async getAssetsTiny(params) {
348
+ const result = await this.appClient.send.call(AbelReaderParamsFactory.getAssetsTiny(params));
349
+ return result.return;
350
+ }
351
+ /**
352
+ * Methods to access state for the current AbelReader app
353
+ */
354
+ state = {};
355
+ newGroup() {
356
+ const client = this;
357
+ const composer = this.algorand.newGroup();
358
+ let promiseChain = Promise.resolve();
359
+ const resultMappers = [];
360
+ return {
361
+ /**
362
+ * Add a getAssetsTiny(uint64[],uint64)(string,string,uint8,string[]) method call against the AbelReader contract
363
+ */
364
+ getAssetsTiny(params) {
365
+ promiseChain = promiseChain.then(async () => composer.addAppCallMethodCall(await client.params.getAssetsTiny(params)));
366
+ resultMappers.push((v) => client.decodeReturnValue('getAssetsTiny(uint64[],uint64)(string,string,uint8,string[])', v));
367
+ return this;
368
+ },
369
+ /**
370
+ * Add a clear state call to the AbelReader contract
371
+ */
372
+ clearState(params) {
373
+ promiseChain = promiseChain.then(() => composer.addAppCall(client.params.clearState(params)));
374
+ return this;
375
+ },
376
+ addTransaction(txn, signer) {
377
+ promiseChain = promiseChain.then(() => composer.addTransaction(txn, signer));
378
+ return this;
379
+ },
380
+ async composer() {
381
+ await promiseChain;
382
+ return composer;
383
+ },
384
+ async simulate(options) {
385
+ await promiseChain;
386
+ const result = await (!options ? composer.simulate() : composer.simulate(options));
387
+ return {
388
+ ...result,
389
+ returns: result.returns?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i](val) : val.returnValue)
390
+ };
391
+ },
392
+ async send(params) {
393
+ await promiseChain;
394
+ const result = await composer.send(params);
395
+ return {
396
+ ...result,
397
+ returns: result.returns?.map((val, i) => resultMappers[i] !== undefined ? resultMappers[i](val) : val.returnValue)
398
+ };
399
+ }
400
+ };
401
+ }
402
+ }
403
+ /* BEGIN GHOST SDK CODE */
404
+ import { getABIDecodedValue } from '@algorandfoundation/algokit-utils/types/app-arc56';
405
+ import { makeEmptyTransactionSigner } from 'algosdk';
406
+ const emptySigner = makeEmptyTransactionSigner();
407
+ class GhostBase {
408
+ static factory = AbelReaderFactory;
409
+ static client = AbelReaderClient;
410
+ algorand;
411
+ readerAccount = 'A7NMWS3NT3IUDMLVO26ULGXGIIOUQ3ND2TXSER6EBGRZNOBOUIQXHIBGDE'; // non-mainnet fee sink
412
+ ghostAppId;
413
+ factory;
414
+ client;
415
+ cacheParamsTimeout = 75; // ms
416
+ constructor({ algorand, readerAccount, ghostAppId, }) {
417
+ this.algorand = algorand;
418
+ if (readerAccount)
419
+ this.readerAccount = readerAccount;
420
+ this.factory = this.algorand.client.getTypedAppFactory(AbelReaderFactory, {
421
+ defaultSender: this.readerAccount,
422
+ });
423
+ this.ghostAppId = ghostAppId;
424
+ this.client = this.factory.getAppClientById({ appId: ghostAppId ?? 13n });
425
+ }
426
+ async getAndCacheSuggestedParams() {
427
+ const suggestedParams = await this.algorand.getSuggestedParams();
428
+ if (this.cacheParamsTimeout) {
429
+ this.algorand.setSuggestedParamsCache(suggestedParams, new Date(Date.now() + this.cacheParamsTimeout));
430
+ }
431
+ return suggestedParams;
432
+ }
433
+ async execute({ signature, txnBuilder, methodArgsOrArgsArray, extraMethodCallArgs, extraSimulateArgs, }) {
434
+ await this.getAndCacheSuggestedParams();
435
+ const methodName = signature.slice(0, signature.indexOf('('));
436
+ let builder = this.client.newGroup();
437
+ if (this.ghostAppId) {
438
+ // deployed variant, we can call directly
439
+ const argsArray = Array.isArray(methodArgsOrArgsArray) ? methodArgsOrArgsArray : [methodArgsOrArgsArray];
440
+ for (let i = 0; i < argsArray.length; i++) {
441
+ const args = argsArray[i];
442
+ const extra = Array.isArray(extraMethodCallArgs) ? extraMethodCallArgs[i] : extraMethodCallArgs;
443
+ builder = txnBuilder(builder, { args, signer: emptySigner, ...extra });
444
+ }
445
+ }
446
+ else {
447
+ // ghost variant
448
+ // Avoiding .createTransaction because it compiles on the fly (why?). build app args and convert to app create
449
+ let throwawayBuilder = this.client.newGroup();
450
+ const argsArray = Array.isArray(methodArgsOrArgsArray) ? methodArgsOrArgsArray : [methodArgsOrArgsArray];
451
+ for (let i = 0; i < argsArray.length; i++) {
452
+ const args = argsArray[i];
453
+ const extra = Array.isArray(extraMethodCallArgs) ? extraMethodCallArgs[i] : extraMethodCallArgs;
454
+ throwawayBuilder = txnBuilder(throwawayBuilder, { args, signer: emptySigner, ...extra });
455
+ }
456
+ const { transactions } = await (await throwawayBuilder.composer()).buildTransactions();
457
+ // convert to app creates, copy to new real builder
458
+ for (const txn of transactions) {
459
+ // @ts-ignore
460
+ txn.applicationCall = {
461
+ ...txn.applicationCall,
462
+ appIndex: 0,
463
+ approvalProgram: Buffer.from(APP_SPEC.byteCode.approval, 'base64'),
464
+ clearProgram: Buffer.from(APP_SPEC.byteCode.clear, 'base64'),
465
+ numGlobalByteSlices: APP_SPEC.state.schema.global.bytes,
466
+ numGlobalInts: APP_SPEC.state.schema.global.ints,
467
+ numLocalByteSlices: APP_SPEC.state.schema.local.bytes,
468
+ numLocalInts: APP_SPEC.state.schema.local.ints,
469
+ extraPages: 3,
470
+ };
471
+ builder = builder.addTransaction(txn, emptySigner);
472
+ }
473
+ }
474
+ const { confirmations } = await builder.simulate({
475
+ extraOpcodeBudget: 170000,
476
+ allowMoreLogging: true,
477
+ allowEmptySignatures: true,
478
+ allowUnnamedResources: true,
479
+ ...extraSimulateArgs,
480
+ });
481
+ const logs = confirmations.flatMap(({ logs }, i) => {
482
+ if (!logs)
483
+ throw new Error(`logs were not returned from simulate txn ${i}. this should never happen`);
484
+ return logs.slice(0, -1);
485
+ });
486
+ const specRetObj = this.client.appSpec.methods.find(({ name }) => name === methodName)?.returns;
487
+ if (!specRetObj)
488
+ throw new Error('Method not found in app spec');
489
+ const retTypeStr = specRetObj.struct ?? specRetObj.type;
490
+ const retData = [];
491
+ for (let i = 0; i < logs.length; i++) {
492
+ retData.push(getABIDecodedValue(new Uint8Array(logs[i]), retTypeStr, this.factory.appSpec.structs));
493
+ }
494
+ return retData;
495
+ }
496
+ }
497
+ export class AbelReaderSDK extends GhostBase {
498
+ constructor(args) {
499
+ super(args);
500
+ }
501
+ async getAssetsTiny({ methodArgsOrArgsArray, extraMethodCallArgs, extraSimulateArgs, }) {
502
+ return this.execute({
503
+ signature: 'getAssetsTiny(uint64[],uint64)(string,string,uint8,string[])',
504
+ txnBuilder: (builder, args) => builder.getAssetsTiny(args),
505
+ methodArgsOrArgsArray,
506
+ extraMethodCallArgs,
507
+ extraSimulateArgs,
508
+ });
509
+ }
510
+ }
511
+ /* END GHOST SDK CODE */