@algorandfoundation/algokit-utils 1.0.0-beta.8 → 1.0.0-beta.9

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.
Files changed (68) hide show
  1. package/account.d.ts +87 -0
  2. package/account.d.ts.map +1 -0
  3. package/account.js +144 -0
  4. package/account.js.map +1 -0
  5. package/algo-amount.d.ts +18 -0
  6. package/algo-amount.d.ts.map +1 -0
  7. package/algo-amount.js +31 -0
  8. package/algo-amount.js.map +1 -0
  9. package/algo-http-client-with-retry.d.ts +14 -0
  10. package/algo-http-client-with-retry.d.ts.map +1 -0
  11. package/algo-http-client-with-retry.js +62 -0
  12. package/algo-http-client-with-retry.js.map +1 -0
  13. package/app.d.ts +189 -0
  14. package/app.d.ts.map +1 -0
  15. package/app.js +265 -0
  16. package/app.js.map +1 -0
  17. package/application-client.d.ts +113 -0
  18. package/application-client.d.ts.map +1 -0
  19. package/application-client.js +258 -0
  20. package/application-client.js.map +1 -0
  21. package/config.d.ts +27 -0
  22. package/config.d.ts.map +1 -0
  23. package/config.js +46 -0
  24. package/config.js.map +1 -0
  25. package/deploy-app.d.ts +164 -0
  26. package/deploy-app.d.ts.map +1 -0
  27. package/deploy-app.js +419 -0
  28. package/deploy-app.js.map +1 -0
  29. package/index.d.ts +12 -0
  30. package/index.d.ts.map +1 -0
  31. package/index.js.map +1 -0
  32. package/indexer-lookup.d.ts +31 -0
  33. package/indexer-lookup.d.ts.map +1 -0
  34. package/indexer-lookup.js +96 -0
  35. package/indexer-lookup.js.map +1 -0
  36. package/localnet.d.ts +54 -0
  37. package/localnet.d.ts.map +1 -0
  38. package/localnet.js +121 -0
  39. package/localnet.js.map +1 -0
  40. package/network-client.d.ts +102 -0
  41. package/network-client.d.ts.map +1 -0
  42. package/network-client.js +182 -0
  43. package/network-client.js.map +1 -0
  44. package/package.json +2 -2
  45. package/transaction.d.ts +157 -0
  46. package/transaction.d.ts.map +1 -0
  47. package/transaction.js +306 -0
  48. package/transaction.js.map +1 -0
  49. package/transfer.d.ts +24 -0
  50. package/transfer.d.ts.map +1 -0
  51. package/transfer.js +33 -0
  52. package/transfer.js.map +1 -0
  53. package/types/algod.d.ts +124 -0
  54. package/types/algod.d.ts.map +1 -0
  55. package/types/algod.js +3 -0
  56. package/types/algod.js.map +1 -0
  57. package/types/appspec.d.ts +78 -0
  58. package/types/appspec.d.ts.map +1 -0
  59. package/types/appspec.js +15 -0
  60. package/types/appspec.js.map +1 -0
  61. package/types/indexer.d.ts +314 -0
  62. package/types/indexer.d.ts.map +1 -0
  63. package/types/indexer.js +25 -0
  64. package/types/indexer.js.map +1 -0
  65. package/urlTokenBaseHTTPClient.d.ts +41 -0
  66. package/urlTokenBaseHTTPClient.d.ts.map +1 -0
  67. package/urlTokenBaseHTTPClient.js +151 -0
  68. package/urlTokenBaseHTTPClient.js.map +1 -0
package/app.js ADDED
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.compileTeal = exports.getAppByIndex = exports.getAppArgsForTransaction = exports.getABIReturn = exports.callApp = exports.updateApp = exports.createApp = exports.ABI_RETURN_PREFIX = exports.APP_PAGE_MAX_SIZE = void 0;
27
+ const algosdk_1 = __importStar(require("algosdk"));
28
+ const buffer_1 = require("buffer");
29
+ const config_1 = require("./config");
30
+ const transaction_1 = require("./transaction");
31
+ /** The maximum number of bytes in an app code page */
32
+ exports.APP_PAGE_MAX_SIZE = 2048;
33
+ /** First 4 bytes of SHA-512/256 hash of "return" */
34
+ exports.ABI_RETURN_PREFIX = new Uint8Array([21, 31, 124, 117]);
35
+ /**
36
+ * Creates a smart contract app, returns the details of the created app.
37
+ * @param create The parameters to create the app with
38
+ * @param algod An algod client
39
+ * @returns The details of the created app, or the transaction to create it if `skipSending`
40
+ */
41
+ async function createApp(create, algod) {
42
+ const { from, approvalProgram: approval, clearStateProgram: clear, schema, note, transactionParams, args, ...sendParams } = create;
43
+ const approvalProgram = typeof approval === 'string' ? (await compileTeal(approval, algod)).compiledBase64ToBytes : approval;
44
+ const clearProgram = typeof clear === 'string' ? (await compileTeal(clear, algod)).compiledBase64ToBytes : clear;
45
+ const transaction = algosdk_1.default.makeApplicationCreateTxnFromObject({
46
+ approvalProgram: approvalProgram,
47
+ clearProgram: clearProgram,
48
+ numLocalInts: schema.localInts,
49
+ numLocalByteSlices: schema.localByteSlices,
50
+ numGlobalInts: schema.globalInts,
51
+ numGlobalByteSlices: schema.globalByteSlices,
52
+ extraPages: schema.extraPages ?? Math.floor((approvalProgram.length + clearProgram.length) / exports.APP_PAGE_MAX_SIZE),
53
+ onComplete: algosdk_1.default.OnApplicationComplete.NoOpOC,
54
+ suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
55
+ from: (0, transaction_1.getSenderAddress)(from),
56
+ note: (0, transaction_1.encodeTransactionNote)(note),
57
+ ...getAppArgsForTransaction(args),
58
+ rekeyTo: undefined,
59
+ });
60
+ const { confirmation } = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
61
+ if (confirmation) {
62
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
63
+ const appIndex = confirmation['application-index'];
64
+ config_1.AlgoKitConfig.getLogger(sendParams.suppressLog).debug(`Created app ${appIndex} from creator ${(0, transaction_1.getSenderAddress)(from)}`);
65
+ return {
66
+ transaction,
67
+ confirmation,
68
+ appIndex,
69
+ appAddress: algosdk_1.default.getApplicationAddress(appIndex),
70
+ return: getABIReturn(args, confirmation),
71
+ };
72
+ }
73
+ else {
74
+ return { transaction, appIndex: 0, appAddress: '' };
75
+ }
76
+ }
77
+ exports.createApp = createApp;
78
+ /**
79
+ * Updates a smart contract app.
80
+ * @param update The parameters to update the app with
81
+ * @param algod An algod client
82
+ * @returns The transaction
83
+ */
84
+ async function updateApp(update, algod) {
85
+ const { appIndex, from, approvalProgram: approval, clearStateProgram: clear, note, transactionParams, args, ...sendParams } = update;
86
+ const approvalProgram = typeof approval === 'string' ? (await compileTeal(approval, algod)).compiledBase64ToBytes : approval;
87
+ const clearProgram = typeof clear === 'string' ? (await compileTeal(clear, algod)).compiledBase64ToBytes : clear;
88
+ const transaction = algosdk_1.default.makeApplicationUpdateTxnFromObject({
89
+ appIndex,
90
+ approvalProgram: approvalProgram,
91
+ clearProgram: clearProgram,
92
+ suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
93
+ from: (0, transaction_1.getSenderAddress)(from),
94
+ note: (0, transaction_1.encodeTransactionNote)(note),
95
+ ...getAppArgsForTransaction(args),
96
+ rekeyTo: undefined,
97
+ });
98
+ config_1.AlgoKitConfig.getLogger(sendParams.suppressLog).debug(`Updating app ${appIndex}`);
99
+ const result = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
100
+ return {
101
+ ...result,
102
+ return: getABIReturn(args, result.confirmation),
103
+ };
104
+ }
105
+ exports.updateApp = updateApp;
106
+ /**
107
+ * Issues a call to a given app.
108
+ * @param call The call details.
109
+ * @param algod An algod client
110
+ * @returns The result of the call
111
+ */
112
+ async function callApp(call, algod) {
113
+ const { appIndex, callType, from, args, note, transactionParams, ...sendParams } = call;
114
+ const appCallParameters = {
115
+ appIndex: appIndex,
116
+ from: (0, transaction_1.getSenderAddress)(from),
117
+ suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
118
+ ...getAppArgsForTransaction(args),
119
+ note: (0, transaction_1.encodeTransactionNote)(note),
120
+ rekeyTo: undefined,
121
+ };
122
+ let transaction;
123
+ switch (callType) {
124
+ case 'optin':
125
+ transaction = algosdk_1.default.makeApplicationOptInTxnFromObject(appCallParameters);
126
+ break;
127
+ case 'clearstate':
128
+ transaction = algosdk_1.default.makeApplicationClearStateTxnFromObject(appCallParameters);
129
+ break;
130
+ case 'closeout':
131
+ transaction = algosdk_1.default.makeApplicationCloseOutTxnFromObject(appCallParameters);
132
+ break;
133
+ case 'delete':
134
+ transaction = algosdk_1.default.makeApplicationDeleteTxnFromObject(appCallParameters);
135
+ break;
136
+ case 'normal':
137
+ transaction = algosdk_1.default.makeApplicationNoOpTxnFromObject(appCallParameters);
138
+ break;
139
+ }
140
+ const result = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
141
+ return {
142
+ ...result,
143
+ return: getABIReturn(args, result.confirmation),
144
+ };
145
+ }
146
+ exports.callApp = callApp;
147
+ function getABIReturn(args, confirmation) {
148
+ try {
149
+ if (!args || !('method' in args)) {
150
+ return undefined;
151
+ }
152
+ const method = 'txnCount' in args.method ? args.method : new algosdk_1.ABIMethod(args.method);
153
+ if (method.returns.type !== 'void' && confirmation) {
154
+ const logs = confirmation.logs || [];
155
+ if (logs.length === 0) {
156
+ throw new Error('App call transaction did not log a return value');
157
+ }
158
+ const lastLog = logs[logs.length - 1];
159
+ if (lastLog.byteLength < 4 || lastLog.slice(0, 4).toString() !== exports.ABI_RETURN_PREFIX.toString()) {
160
+ throw new Error('App call transaction did not log a return value (ABI_RETURN_PREFIX not found)');
161
+ }
162
+ return {
163
+ rawReturnValue: new Uint8Array(lastLog.slice(4)),
164
+ returnValue: method.returns.type.decode(new Uint8Array(lastLog.slice(4))),
165
+ decodeError: undefined,
166
+ };
167
+ }
168
+ }
169
+ catch (e) {
170
+ return {
171
+ rawReturnValue: undefined,
172
+ returnValue: undefined,
173
+ decodeError: e,
174
+ };
175
+ }
176
+ return undefined;
177
+ }
178
+ exports.getABIReturn = getABIReturn;
179
+ /** Returns the app args ready to load onto an app @see {Transaction} object */
180
+ function getAppArgsForTransaction(args) {
181
+ if (!args)
182
+ return undefined;
183
+ let actualArgs;
184
+ if ('method' in args) {
185
+ // todo: Land a change to algosdk that extract the logic from ATC, because (fair warning) this is a HACK
186
+ // I don't want to have to rewrite all of the ABI resolution logic so using an ATC temporarily here
187
+ // and passing stuff in to keep it happy like a randomly generated account :O
188
+ // Most of these values aren't being used since the transaction is discarded
189
+ const dummyAtc = new algosdk_1.AtomicTransactionComposer();
190
+ const dummyAccount = algosdk_1.default.generateAccount();
191
+ const dummyAppId = 1;
192
+ const dummyParams = {
193
+ fee: 1,
194
+ firstRound: 1,
195
+ genesisHash: buffer_1.Buffer.from('abcd', 'utf-8').toString('base64'),
196
+ genesisID: 'a',
197
+ lastRound: 1,
198
+ };
199
+ const dummyOnComplete = algosdk_1.OnApplicationComplete.NoOpOC;
200
+ dummyAtc.addMethodCall({
201
+ method: 'txnCount' in args.method ? args.method : new algosdk_1.ABIMethod(args.method),
202
+ methodArgs: args.args,
203
+ // Rest are dummy values
204
+ appID: dummyAppId,
205
+ sender: dummyAccount.addr,
206
+ signer: (0, algosdk_1.makeBasicAccountTransactionSigner)(dummyAccount),
207
+ suggestedParams: dummyParams,
208
+ onComplete: dummyOnComplete,
209
+ });
210
+ const txn = dummyAtc.buildGroup()[0];
211
+ actualArgs = {
212
+ accounts: txn.txn.appAccounts,
213
+ appArgs: txn.txn.appArgs,
214
+ apps: txn.txn.appForeignApps,
215
+ assets: txn.txn.appForeignAssets,
216
+ boxes: txn.txn.boxes,
217
+ lease: args.lease,
218
+ };
219
+ }
220
+ else {
221
+ actualArgs = args;
222
+ }
223
+ const encoder = new TextEncoder();
224
+ return {
225
+ accounts: actualArgs?.accounts?.map((a) => (typeof a === 'string' ? a : algosdk_1.default.encodeAddress(a.publicKey))),
226
+ appArgs: actualArgs?.appArgs?.map((a) => (typeof a === 'string' ? encoder.encode(a) : a)),
227
+ boxes: actualArgs?.boxes?.map((ref) => ({
228
+ appIndex: ref.appIndex,
229
+ name: typeof ref.name === 'string' ? encoder.encode(ref.name) : ref.name,
230
+ })),
231
+ foreignApps: actualArgs?.apps,
232
+ foreignAssets: actualArgs?.assets,
233
+ lease: typeof actualArgs?.lease === 'string' ? encoder.encode(actualArgs?.lease) : actualArgs?.lease,
234
+ };
235
+ }
236
+ exports.getAppArgsForTransaction = getAppArgsForTransaction;
237
+ /**
238
+ * Gets the current data for the given app from algod.
239
+ *
240
+ * @param appIndex The index of the app
241
+ * @param algod An algod client
242
+ * @returns The data about the app
243
+ */
244
+ async function getAppByIndex(appIndex, algod) {
245
+ return (await algod.getApplicationByID(appIndex).do());
246
+ }
247
+ exports.getAppByIndex = getAppByIndex;
248
+ /**
249
+ * Compiles the given TEAL using algod and returns the result.
250
+ *
251
+ * @param algod An algod client
252
+ * @param tealCode The TEAL code
253
+ * @returns The information about the compiled file
254
+ */
255
+ async function compileTeal(tealCode, algod) {
256
+ const compiled = await algod.compile(tealCode).do();
257
+ return {
258
+ teal: tealCode,
259
+ compiled: compiled.result,
260
+ compiledHash: compiled.hash,
261
+ compiledBase64ToBytes: new Uint8Array(buffer_1.Buffer.from(compiled.result, 'base64')),
262
+ };
263
+ }
264
+ exports.compileTeal = compileTeal;
265
+ //# sourceMappingURL=app.js.map
package/app.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAYgB;AAChB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EAAE,KAAc;IAClE,OAAO,CAAC,MAAM,KAAK,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAwB,CAAA;AAC/E,CAAC;AAFD,sCAEC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAAC,QAAgB,EAAE,KAAc;IAChE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAA;IACnD,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,QAAQ,CAAC,MAAM;QACzB,YAAY,EAAE,QAAQ,CAAC,IAAI;QAC3B,qBAAqB,EAAE,IAAI,UAAU,CAAC,eAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;KAC9E,CAAA;AACH,CAAC;AARD,kCAQC"}
@@ -0,0 +1,113 @@
1
+ import { ABIArgument, ABIMethodParams, Algodv2, Indexer, SuggestedParams } from 'algosdk';
2
+ import { AppCallArgs, AppReference, RawAppCallArgs } from './app';
3
+ import { AppLookup, AppMetadata, OnSchemaBreak, OnUpdate, TealTemplateParameters } from './deploy-app';
4
+ import { SendTransactionFrom, SendTransactionParams, TransactionNote } from './transaction';
5
+ import { AppSpec } from './types/appspec';
6
+ export declare class ApplicationClient {
7
+ private algod;
8
+ private indexer;
9
+ private appSpec;
10
+ private sender;
11
+ private params;
12
+ private existingDeployments;
13
+ private _appIndex;
14
+ private _appAddress;
15
+ private _creator;
16
+ constructor(appDetails: {
17
+ /** The ARC-0032 application spec as either:
18
+ * * Parsed JSON @see {AppSpec}
19
+ * * Raw JSON string
20
+ */
21
+ app: AppSpec | string;
22
+ /** Default sender to use for transactions issued by this application client */
23
+ sender?: SendTransactionFrom;
24
+ /** Default suggested params object to use */
25
+ params?: SuggestedParams;
26
+ } & ({
27
+ /** The index of an existing app to call using this client */
28
+ index: number;
29
+ } | {
30
+ /** The address of the app creator account */
31
+ creatorAddress: string;
32
+ /** Optional cached value of the existing apps for the given creator */
33
+ existingDeployments?: AppLookup;
34
+ }), algod: Algodv2, indexer: Indexer);
35
+ /**
36
+ * Idempotently deploy (create, update/delete if changed) an app against the given name via the given creator account, including deploy-time template placeholder substitutions.
37
+ *
38
+ * To understand the architecture decisions behind this functionality please @see https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md
39
+ *
40
+ * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.
41
+ *
42
+ * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.
43
+ * @param deploy Deployment details
44
+ * @returns The metadata and transaction result(s) of the deployment, or just the metadata if it didn't need to issue transactions
45
+ */
46
+ deploy(deploy: {
47
+ /** The version of the contract, e.g. "1.0" */
48
+ version: string;
49
+ /** The optional sender to send the transaction from, will use the application client's default sender by default if specified */
50
+ sender?: SendTransactionFrom;
51
+ /** Whether or not to allow updates in the contract using the deploy-time updatability control if present in your contract.
52
+ * If this is not specified then it will automatically be determined based on the AppSpec definition
53
+ **/
54
+ allowUpdate?: boolean;
55
+ /** Whether or not to allow deletes in the contract using the deploy-time deletability control if present in your contract.
56
+ * If this is not specified then it will automatically be determined based on the AppSpec definition
57
+ **/
58
+ allowDelete?: boolean;
59
+ /** Parameters to control transaction sending */
60
+ sendParams?: Omit<SendTransactionParams, 'args' | 'skipSending' | 'skipWaiting'>;
61
+ /** Any deploy-time parameters to replace in the TEAL code */
62
+ deployTimeParameters?: TealTemplateParameters;
63
+ /** What action to perform if a schema break is detected */
64
+ onSchemaBreak?: 'replace' | 'fail' | OnSchemaBreak;
65
+ /** What action to perform if a TEAL update is detected */
66
+ onUpdate?: 'update' | 'replace' | 'fail' | OnUpdate;
67
+ /** Any args to pass to any create transaction that is issued as part of deployment */
68
+ createArgs?: AppCallArgs;
69
+ /** Any args to pass to any update transaction that is issued as part of deployment */
70
+ updateArgs?: AppCallArgs;
71
+ /** Any args to pass to any delete transaction that is issued as part of deployment */
72
+ deleteArgs?: AppCallArgs;
73
+ }): Promise<(import("./transaction").SendTransactionResult & AppMetadata & {
74
+ operationPerformed: "update" | "create";
75
+ }) | (import("./transaction").SendTransactionResult & AppMetadata & {
76
+ deleteResult?: import("./transaction").SendTransactionResult | undefined;
77
+ operationPerformed: "replace";
78
+ }) | (AppMetadata & {
79
+ operationPerformed: "none";
80
+ })>;
81
+ create(create?: {
82
+ sender?: SendTransactionFrom;
83
+ args?: AppCallArgs;
84
+ note?: TransactionNote;
85
+ sendParams?: SendTransactionParams;
86
+ deployTimeParameters?: TealTemplateParameters;
87
+ }): Promise<import("./app").AppCallTransactionResult & AppReference>;
88
+ update(update?: {
89
+ sender?: SendTransactionFrom;
90
+ args?: AppCallArgs;
91
+ note?: TransactionNote;
92
+ sendParams?: SendTransactionParams;
93
+ deployTimeParameters?: TealTemplateParameters;
94
+ }): Promise<import("./app").AppCallTransactionResult>;
95
+ call(call: {
96
+ callType: 'optin' | 'closeout' | 'clearstate' | 'delete' | 'normal';
97
+ sender?: SendTransactionFrom;
98
+ note?: TransactionNote;
99
+ sendParams?: SendTransactionParams;
100
+ } & ({
101
+ /** If calling an ABI method then either the name of the method, or the ABI signature, if undefined then a bare call will be made */
102
+ method: string;
103
+ /** The ABI args to pass in */
104
+ methodArgs: ABIArgument[];
105
+ /** The optional lease for the transaction */
106
+ lease?: string | Uint8Array;
107
+ } | {
108
+ args: RawAppCallArgs;
109
+ })): Promise<import("./app").AppCallTransactionResult>;
110
+ getABIMethod(method: string): ABIMethodParams | undefined;
111
+ private loadAppReference;
112
+ }
113
+ //# sourceMappingURL=application-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-client.d.ts","sourceRoot":"","sources":["../src/application-client.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAyB,OAAO,EAAE,eAAe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,CAAC,EAAE,qBAAqB,CAAA;KACnC,GAAG,CACA;QACE,oIAAoI;QACpI,MAAM,EAAE,MAAM,CAAA;QACd,8BAA8B;QAC9B,UAAU,EAAE,WAAW,EAAE,CAAA;QACzB,6CAA6C;QAC7C,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;KAC5B,GACD;QACE,IAAI,EAAE,cAAc,CAAA;KACrB,CACJ;IAgDH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;YAe3C,gBAAgB;CAqB/B"}
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ApplicationClient = void 0;
27
+ const algosdk_1 = __importStar(require("algosdk"));
28
+ const buffer_1 = require("buffer");
29
+ const app_1 = require("./app");
30
+ const deploy_app_1 = require("./deploy-app");
31
+ const transaction_1 = require("./transaction");
32
+ const appspec_1 = require("./types/appspec");
33
+ class ApplicationClient {
34
+ constructor(appDetails, algod, indexer) {
35
+ const { app, sender, params, ...appIdentifier } = appDetails;
36
+ this.algod = algod;
37
+ this.indexer = indexer;
38
+ this.appSpec = typeof app == 'string' ? JSON.parse(app) : app;
39
+ if ('creatorAddress' in appIdentifier) {
40
+ this._creator = appIdentifier.creatorAddress;
41
+ if (appIdentifier.existingDeployments && appIdentifier.existingDeployments.creator !== this._creator) {
42
+ throw new Error(`Attempt to create application client with invalid existingDeployments against a different creator (${appIdentifier.existingDeployments.creator}) instead of expected creator ${this._creator}`);
43
+ }
44
+ this.existingDeployments = appIdentifier.existingDeployments;
45
+ this._appIndex = 0;
46
+ }
47
+ else {
48
+ if (appIdentifier.index < 0) {
49
+ throw new Error(`Attempt to create application client with invalid app index of ${appIdentifier.index}`);
50
+ }
51
+ this._appIndex = appIdentifier.index;
52
+ }
53
+ this._appAddress = algosdk_1.default.getApplicationAddress(this._appIndex);
54
+ this.sender = sender;
55
+ this.params = params;
56
+ // todo: find create, update, delete, etc. methods from app spec
57
+ }
58
+ /**
59
+ * Idempotently deploy (create, update/delete if changed) an app against the given name via the given creator account, including deploy-time template placeholder substitutions.
60
+ *
61
+ * To understand the architecture decisions behind this functionality please @see https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md
62
+ *
63
+ * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.
64
+ *
65
+ * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.
66
+ * @param deploy Deployment details
67
+ * @returns The metadata and transaction result(s) of the deployment, or just the metadata if it didn't need to issue transactions
68
+ */
69
+ async deploy(deploy) {
70
+ const { sender, version, allowUpdate, allowDelete, sendParams, ...deployArgs } = deploy;
71
+ if (this._appIndex !== 0) {
72
+ throw new Error(`Attempt to deploy app which already has an app index of ${this._appIndex}`);
73
+ }
74
+ if (!sender && !this.sender) {
75
+ throw new Error('No sender provided, unable to deploy app');
76
+ }
77
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
78
+ const from = sender ?? this.sender;
79
+ if (!this._creator) {
80
+ throw new Error('Attempt to deploy a contract without having specified a creator');
81
+ }
82
+ if (this._creator !== (0, transaction_1.getSenderAddress)(from)) {
83
+ throw new Error(`Attempt to deploy contract with a sender address (${(0, transaction_1.getSenderAddress)(from)}) that differs from the given creator address for this application client: ${this._creator}`);
84
+ }
85
+ const approval = buffer_1.Buffer.from(this.appSpec.source.approval, 'base64').toString('utf-8');
86
+ const clear = buffer_1.Buffer.from(this.appSpec.source.clear, 'base64').toString('utf-8');
87
+ await this.loadAppReference();
88
+ const result = await (0, deploy_app_1.deployApp)({
89
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
90
+ from,
91
+ approvalProgram: approval,
92
+ clearStateProgram: clear,
93
+ metadata: {
94
+ name: this.appSpec.contract.name,
95
+ version: version,
96
+ updatable: allowUpdate ??
97
+ ((!this.appSpec.bare_call_config.update_application && this.appSpec.bare_call_config.update_application !== 'NEVER') ||
98
+ !!Object.keys(this.appSpec.hints).filter((h) => !this.appSpec.hints[h].call_config.update_application && this.appSpec.hints[h].call_config.update_application !== 'NEVER')[0]),
99
+ deletable: allowDelete ??
100
+ ((!this.appSpec.bare_call_config.delete_application && this.appSpec.bare_call_config.delete_application !== 'NEVER') ||
101
+ !!Object.keys(this.appSpec.hints).filter((h) => !this.appSpec.hints[h].call_config.delete_application && this.appSpec.hints[h].call_config.delete_application !== 'NEVER')[0]),
102
+ },
103
+ schema: {
104
+ globalByteSlices: this.appSpec.state.global.num_byte_slices,
105
+ globalInts: this.appSpec.state.global.num_uints,
106
+ localByteSlices: this.appSpec.state.local.num_byte_slices,
107
+ localInts: this.appSpec.state.local.num_uints,
108
+ },
109
+ transactionParams: this.params,
110
+ ...(sendParams ?? {}),
111
+ ...deployArgs,
112
+ existingDeployments: this.existingDeployments,
113
+ }, this.algod, this.indexer);
114
+ // Nothing needed to happen
115
+ if (!('transaction' in result)) {
116
+ return result;
117
+ }
118
+ if (!this.existingDeployments) {
119
+ throw new Error('Expected existingDeployments to be present');
120
+ }
121
+ const { transaction, confirmation, operationPerformed, ...appMetadata } = result;
122
+ if ('deleteResult' in appMetadata) {
123
+ delete appMetadata.deleteResult;
124
+ }
125
+ this.existingDeployments = {
126
+ creator: this.existingDeployments.creator,
127
+ apps: { ...this.existingDeployments.apps, [this.appSpec.contract.name]: appMetadata },
128
+ };
129
+ return result;
130
+ }
131
+ async create(create) {
132
+ const { sender, args, note, sendParams, deployTimeParameters } = create ?? {};
133
+ // todo: Add deploy-time updatable/etc.
134
+ if (this._appIndex !== 0) {
135
+ throw new Error(`Attempt to create app which already has an app index of ${this._appIndex}`);
136
+ }
137
+ if (!sender && !this.sender) {
138
+ throw new Error('No sender provided, unable to create app');
139
+ }
140
+ const approval = buffer_1.Buffer.from(this.appSpec.source.approval, 'base64').toString('utf-8');
141
+ const clear = buffer_1.Buffer.from(this.appSpec.source.clear, 'base64').toString('utf-8');
142
+ const result = await (0, app_1.createApp)({
143
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
144
+ from: sender ?? this.sender,
145
+ approvalProgram: (0, deploy_app_1.performTemplateSubstitution)(approval, deployTimeParameters),
146
+ clearStateProgram: (0, deploy_app_1.performTemplateSubstitution)(clear, deployTimeParameters),
147
+ schema: {
148
+ globalByteSlices: this.appSpec.state.global.num_byte_slices,
149
+ globalInts: this.appSpec.state.global.num_uints,
150
+ localByteSlices: this.appSpec.state.local.num_byte_slices,
151
+ localInts: this.appSpec.state.local.num_uints,
152
+ },
153
+ args: args,
154
+ note: note,
155
+ transactionParams: this.params,
156
+ ...(sendParams ?? {}),
157
+ }, this.algod);
158
+ if (result.confirmation) {
159
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
160
+ this._appIndex = result.confirmation['application-index'];
161
+ this._appAddress = (0, algosdk_1.getApplicationAddress)(this._appIndex);
162
+ }
163
+ return result;
164
+ }
165
+ async update(update) {
166
+ const { sender, args, note, sendParams, deployTimeParameters } = update ?? {};
167
+ if (this._appIndex === 0) {
168
+ throw new Error(`Attempt to update app which doesn't have an app index defined`);
169
+ }
170
+ if (!sender && !this.sender) {
171
+ throw new Error('No sender provided, unable to create app');
172
+ }
173
+ const approval = buffer_1.Buffer.from(this.appSpec.source.approval, 'base64').toString('utf-8');
174
+ const clear = buffer_1.Buffer.from(this.appSpec.source.clear, 'base64').toString('utf-8');
175
+ const result = await (0, app_1.updateApp)({
176
+ appIndex: this._appIndex,
177
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
178
+ from: sender ?? this.sender,
179
+ approvalProgram: (0, deploy_app_1.performTemplateSubstitution)(approval, deployTimeParameters),
180
+ clearStateProgram: (0, deploy_app_1.performTemplateSubstitution)(clear, deployTimeParameters),
181
+ args: args,
182
+ note: note,
183
+ transactionParams: this.params,
184
+ ...(sendParams ?? {}),
185
+ }, this.algod);
186
+ return result;
187
+ }
188
+ async call(call) {
189
+ const { sender, callType, note, sendParams, ...args } = call;
190
+ if (!sender && !this.sender) {
191
+ throw new Error('No sender provided, unable to call app');
192
+ }
193
+ const appMetadata = await this.loadAppReference();
194
+ if (appMetadata.appIndex === 0) {
195
+ throw new Error(`Attempt to call an app that can't be found '${this.appSpec.contract.name}' for creator '${this._creator}'.`);
196
+ }
197
+ // todo: use this in create et. al. as well
198
+ let callArgs;
199
+ // ABI call
200
+ if ('method' in args) {
201
+ const abiMethod = this.getABIMethod(args.method);
202
+ if (!abiMethod) {
203
+ throw new Error(`Attempt to call ABI method ${args.method}, but it wasn't found`);
204
+ }
205
+ callArgs = {
206
+ method: abiMethod,
207
+ args: args.methodArgs,
208
+ lease: args.lease,
209
+ };
210
+ }
211
+ else {
212
+ callArgs = args.args;
213
+ }
214
+ // todo: process ABI args as needed to make them nicer to deal with like beaker-ts???
215
+ // todo: support unwrapping a logic error?
216
+ return (0, app_1.callApp)({
217
+ appIndex: appMetadata.appIndex,
218
+ callType: callType,
219
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
220
+ from: sender ?? this.sender,
221
+ args: callArgs,
222
+ note: note,
223
+ transactionParams: this.params,
224
+ ...(sendParams ?? {}),
225
+ }, this.algod);
226
+ }
227
+ getABIMethod(method) {
228
+ if (!method.includes('(')) {
229
+ const methods = this.appSpec.contract.methods.filter((m) => m.name === method);
230
+ if (methods.length > 1) {
231
+ throw new Error(`Received a call to method ${method} in contract ${this.appSpec.contract.name}, but this resolved to multiple methods; please pass in an ABI signature instead: ${methods.map(appspec_1.getABISignature).join(', ')}`);
232
+ }
233
+ return methods[0];
234
+ }
235
+ return this.appSpec.contract.methods.find((m) => (0, appspec_1.getABISignature)(m) === method);
236
+ }
237
+ async loadAppReference() {
238
+ if (!this.existingDeployments && this._creator) {
239
+ this.existingDeployments = await (0, deploy_app_1.getCreatorAppsByName)(this._creator, this.indexer);
240
+ }
241
+ if (this.existingDeployments && this._appIndex === 0) {
242
+ const app = this.existingDeployments.apps[this.appSpec.contract.name];
243
+ if (!app) {
244
+ return {
245
+ appIndex: 0,
246
+ appAddress: (0, algosdk_1.getApplicationAddress)(0),
247
+ };
248
+ }
249
+ return app;
250
+ }
251
+ return {
252
+ appIndex: this._appIndex,
253
+ appAddress: this._appAddress,
254
+ };
255
+ }
256
+ }
257
+ exports.ApplicationClient = ApplicationClient;
258
+ //# sourceMappingURL=application-client.js.map