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

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 (158) hide show
  1. package/README.md +38 -0
  2. package/account.d.ts +41 -36
  3. package/account.d.ts.map +1 -1
  4. package/account.js +59 -44
  5. package/account.js.map +1 -1
  6. package/amount.d.ts +20 -0
  7. package/amount.d.ts.map +1 -0
  8. package/amount.js +36 -0
  9. package/amount.js.map +1 -0
  10. package/app-client.d.ts +14 -0
  11. package/app-client.d.ts.map +1 -0
  12. package/app-client.js +19 -0
  13. package/app-client.js.map +1 -0
  14. package/app-deploy.d.ts +95 -0
  15. package/app-deploy.d.ts.map +1 -0
  16. package/{deploy-app.js → app-deploy.js} +129 -119
  17. package/app-deploy.js.map +1 -0
  18. package/app.d.ts +112 -148
  19. package/app.d.ts.map +1 -1
  20. package/app.js +460 -143
  21. package/app.js.map +1 -1
  22. package/index.d.ts +6 -4
  23. package/index.d.ts.map +1 -1
  24. package/index.js +7 -4
  25. package/index.js.map +1 -1
  26. package/indexer-lookup.d.ts +11 -4
  27. package/indexer-lookup.d.ts.map +1 -1
  28. package/indexer-lookup.js +19 -9
  29. package/indexer-lookup.js.map +1 -1
  30. package/localnet.d.ts +10 -10
  31. package/localnet.d.ts.map +1 -1
  32. package/localnet.js +16 -16
  33. package/localnet.js.map +1 -1
  34. package/network-client.d.ts +15 -24
  35. package/network-client.d.ts.map +1 -1
  36. package/network-client.js +16 -16
  37. package/network-client.js.map +1 -1
  38. package/package.json +2 -2
  39. package/testing/account.d.ts +14 -0
  40. package/testing/account.d.ts.map +1 -0
  41. package/testing/account.js +31 -0
  42. package/testing/account.js.map +1 -0
  43. package/testing/fixtures/algokit-log-capture-fixture.d.ts +19 -0
  44. package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +1 -0
  45. package/testing/fixtures/algokit-log-capture-fixture.js +43 -0
  46. package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -0
  47. package/testing/fixtures/algorand-fixture.d.ts +24 -0
  48. package/testing/fixtures/algorand-fixture.d.ts.map +1 -0
  49. package/testing/fixtures/algorand-fixture.js +60 -0
  50. package/testing/fixtures/algorand-fixture.js.map +1 -0
  51. package/testing/fixtures/index.d.ts +3 -0
  52. package/testing/fixtures/index.d.ts.map +1 -0
  53. package/testing/fixtures/index.js +19 -0
  54. package/testing/fixtures/index.js.map +1 -0
  55. package/testing/index.d.ts +6 -0
  56. package/testing/index.d.ts.map +1 -0
  57. package/testing/index.js +22 -0
  58. package/testing/index.js.map +1 -0
  59. package/testing/indexer.d.ts +12 -0
  60. package/testing/indexer.d.ts.map +1 -0
  61. package/testing/indexer.js +40 -0
  62. package/testing/indexer.js.map +1 -0
  63. package/testing/test-logger.d.ts +41 -0
  64. package/testing/test-logger.d.ts.map +1 -0
  65. package/testing/test-logger.js +71 -0
  66. package/testing/test-logger.js.map +1 -0
  67. package/testing/transaction-logger.d.ts +29 -0
  68. package/testing/transaction-logger.d.ts.map +1 -0
  69. package/testing/transaction-logger.js +71 -0
  70. package/testing/transaction-logger.js.map +1 -0
  71. package/transaction.d.ts +55 -91
  72. package/transaction.d.ts.map +1 -1
  73. package/transaction.js +213 -155
  74. package/transaction.js.map +1 -1
  75. package/transfer.d.ts +14 -16
  76. package/transfer.d.ts.map +1 -1
  77. package/transfer.js +38 -4
  78. package/transfer.js.map +1 -1
  79. package/types/account.d.ts +55 -0
  80. package/types/account.d.ts.map +1 -0
  81. package/types/account.js +91 -0
  82. package/types/account.js.map +1 -0
  83. package/types/algo-http-client-with-retry.d.ts.map +1 -0
  84. package/{algo-http-client-with-retry.js → types/algo-http-client-with-retry.js} +3 -3
  85. package/types/algo-http-client-with-retry.js.map +1 -0
  86. package/types/algod.d.ts +28 -15
  87. package/types/algod.d.ts.map +1 -1
  88. package/{algo-amount.d.ts → types/amount.d.ts} +9 -3
  89. package/types/amount.d.ts.map +1 -0
  90. package/{algo-amount.js → types/amount.js} +13 -3
  91. package/types/amount.js.map +1 -0
  92. package/types/app-client.d.ts +282 -0
  93. package/types/app-client.d.ts.map +1 -0
  94. package/types/app-client.js +529 -0
  95. package/types/app-client.js.map +1 -0
  96. package/types/app-spec.d.ts +141 -0
  97. package/types/app-spec.d.ts.map +1 -0
  98. package/types/{appspec.js → app-spec.js} +5 -7
  99. package/types/app-spec.js.map +1 -0
  100. package/types/app.d.ts +285 -0
  101. package/types/app.d.ts.map +1 -0
  102. package/types/app.js +32 -0
  103. package/types/app.js.map +1 -0
  104. package/types/config.d.ts +32 -0
  105. package/types/config.d.ts.map +1 -0
  106. package/types/config.js +53 -0
  107. package/types/config.js.map +1 -0
  108. package/types/indexer.d.ts +368 -58
  109. package/types/indexer.d.ts.map +1 -1
  110. package/types/indexer.js +9 -0
  111. package/types/indexer.js.map +1 -1
  112. package/{config.d.ts → types/logging.d.ts} +2 -16
  113. package/types/logging.d.ts.map +1 -0
  114. package/{config.js → types/logging.js} +5 -24
  115. package/types/logging.js.map +1 -0
  116. package/types/logic-error.d.ts +37 -0
  117. package/types/logic-error.d.ts.map +1 -0
  118. package/types/logic-error.js +50 -0
  119. package/types/logic-error.js.map +1 -0
  120. package/types/network-client.d.ts +11 -0
  121. package/types/network-client.d.ts.map +1 -0
  122. package/types/network-client.js +3 -0
  123. package/types/network-client.js.map +1 -0
  124. package/types/testing.d.ts +89 -0
  125. package/types/testing.d.ts.map +1 -0
  126. package/types/testing.js +3 -0
  127. package/types/testing.js.map +1 -0
  128. package/types/transaction.d.ts +112 -0
  129. package/types/transaction.d.ts.map +1 -0
  130. package/types/transaction.js +3 -0
  131. package/types/transaction.js.map +1 -0
  132. package/types/transfer.d.ts +32 -0
  133. package/types/transfer.d.ts.map +1 -0
  134. package/types/transfer.js +3 -0
  135. package/types/transfer.js.map +1 -0
  136. package/types/urlTokenBaseHTTPClient.d.ts.map +1 -0
  137. package/types/urlTokenBaseHTTPClient.js.map +1 -0
  138. package/algo-amount.d.ts.map +0 -1
  139. package/algo-amount.js.map +0 -1
  140. package/algo-http-client-with-retry.d.ts.map +0 -1
  141. package/algo-http-client-with-retry.js.map +0 -1
  142. package/application-client.d.ts +0 -113
  143. package/application-client.d.ts.map +0 -1
  144. package/application-client.js +0 -258
  145. package/application-client.js.map +0 -1
  146. package/config.d.ts.map +0 -1
  147. package/config.js.map +0 -1
  148. package/deploy-app.d.ts +0 -164
  149. package/deploy-app.d.ts.map +0 -1
  150. package/deploy-app.js.map +0 -1
  151. package/types/appspec.d.ts +0 -78
  152. package/types/appspec.d.ts.map +0 -1
  153. package/types/appspec.js.map +0 -1
  154. package/urlTokenBaseHTTPClient.d.ts.map +0 -1
  155. package/urlTokenBaseHTTPClient.js.map +0 -1
  156. /package/{algo-http-client-with-retry.d.ts → types/algo-http-client-with-retry.d.ts} +0 -0
  157. /package/{urlTokenBaseHTTPClient.d.ts → types/urlTokenBaseHTTPClient.d.ts} +0 -0
  158. /package/{urlTokenBaseHTTPClient.js → types/urlTokenBaseHTTPClient.js} +0 -0
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # AlgoKit TypeScript Utilities
2
+
3
+ A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand. This project is part of [AlgoKit](https://github.com/algorandfoundation/algokit-cli).
4
+
5
+ The goal of this library is to provide intuitive, productive utility functions that make it easier, quicker and safer to build applications on Algorand. Largely these functions wrap the underlying Algorand SDK, but provide a higher level interface with sensible defaults and capabilities for common tasks.
6
+
7
+ Note: If you prefer Python there's an equivalent [Python utility library](https://github.com/algorandfoundation/algokit-utils-py).
8
+
9
+ [Install](#install) | [Documentation](docs/README.md)
10
+
11
+ ## Install
12
+
13
+ This library can be installed from NPM using your favourite npm client, e.g.:
14
+
15
+ ```
16
+ npm install @algorandfoundation/algokit-utils
17
+ ```
18
+
19
+ ## Guiding principles
20
+
21
+ This library follows the [Guiding Principles of AlgoKit](https://github.com/algorandfoundation/algokit-cli/docs/algokit.md#guiding-principles).
22
+
23
+ ## Contributing
24
+
25
+ This is an open source project managed by the Algorand Foundation. See the [AlgoKit contributing page](https://github.com/algorandfoundation/algokit-cli/blob/main/CONTRIBUTING.MD) to learn about making improvements.
26
+
27
+ To successfully run the tests in this repository you need to be running LocalNet via [AlgoKit](https://github.com/algorandfoundation/algokit-cli) and also have package dependencies and `.env.template` copied to `.env` (both of which `algokit bootstrap all` can do for you):
28
+
29
+ ```
30
+ algokit bootstrap all
31
+ algokit localnet start
32
+ ```
33
+
34
+ To run tests you can use VS Code, or:
35
+
36
+ ```
37
+ npm run test
38
+ ```
package/account.d.ts CHANGED
@@ -1,10 +1,28 @@
1
- import algosdk, { Account, Algodv2, Kmd } from 'algosdk';
2
- import { AlgoAmount } from './algo-amount';
3
- import { SigningAccount } from './transaction';
1
+ import algosdk, { Account, Algodv2, Kmd, MultisigMetadata, TransactionSigner } from 'algosdk';
2
+ import { MultisigAccount, SigningAccount, TransactionSignerAccount } from './types/account';
3
+ import { AlgoAmount } from './types/amount';
4
+ import { SendTransactionFrom } from './types/transaction';
4
5
  /**
5
- * The account name identifier used for fund dispensing in test environments
6
+ * Returns an account wrapper that supports partial or full multisig signing.
7
+ * @param multisigParams The parameters that define the multisig account
8
+ * @param signingAccounts The signers that are currently present
9
+ * @returns A multisig account wrapper
6
10
  */
7
- export declare const DISPENSER_ACCOUNT = "DISPENSER";
11
+ export declare function multisigAccount(multisigParams: MultisigMetadata, signingAccounts: (Account | SigningAccount)[]): MultisigAccount;
12
+ /**
13
+ * Returns an account wrapper that supports a rekeyed account.
14
+ * @param signer The account, with private key loaded, that is signing
15
+ * @param sender The address of the rekeyed account that will act as a sender
16
+ * @returns The SigningAccount wrapper
17
+ */
18
+ export declare function rekeyedAccount(signer: Account, sender: string): SigningAccount;
19
+ /**
20
+ * Returns an account wrapper that supports a transaction signer with associated sender address.
21
+ * @param signer The transaction signer
22
+ * @param sender The address of sender account
23
+ * @returns The SigningAccount wrapper
24
+ */
25
+ export declare function transactionSignerAccount(signer: TransactionSigner, sender: string): TransactionSignerAccount;
8
26
  /** Returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
9
27
  *
10
28
  * This is a wrapper around algosdk.mnemonicToSecretKey to provide a more friendly/obvious name.
@@ -12,24 +30,30 @@ export declare const DISPENSER_ACCOUNT = "DISPENSER";
12
30
  * @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
13
31
  * never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
14
32
  */
15
- export declare function getAccountFromMnemonic(mnemonicSecret: string): Account;
33
+ export declare function mnemonicAccount(mnemonicSecret: string): Account;
34
+ /** Returns a new, random Algorand account with secret key loaded.
35
+ *
36
+ * This is a wrapper around algosdk.generateAccount to provide a more friendly/obvious name.
37
+ *
38
+ */
39
+ export declare function randomAccount(): Account;
16
40
  /**
17
41
  * Returns an Algorand account with private key loaded by convention based on the given name identifier.
18
42
  *
19
43
  * Note: This function expects to run in a Node.js environment.
20
44
  *
21
45
  * ## Convention:
22
- * * **Non-LocalNet:** will load process.env['{NAME}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
46
+ * * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
23
47
  * never commit it into source control and ideally load it via a secret storage service rather than the file system.
24
- * If process.env['{NAME}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
25
- * * **LocalNet:** will load the account from a KMD wallet called {NAME} and if that wallet doesn't exist it will create it and fund the account for you
48
+ * If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
49
+ * * **LocalNet:** will load the account from a KMD wallet called \{NAME\} and if that wallet doesn't exist it will create it and fund the account for you
26
50
  *
27
51
  * This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
28
52
  *
29
53
  * @example Default
30
54
  *
31
55
  * If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
32
- * ```
56
+ * ```typescript
33
57
  * const account = await getAccount('ACCOUNT', algod)
34
58
  * ```
35
59
  *
@@ -37,39 +61,20 @@ export declare function getAccountFromMnemonic(mnemonicSecret: string): Account;
37
61
  *
38
62
  * @param account The details of the account to get, wither the name identifier (string) or an object with:
39
63
  * * `name`: The name identifier of the account
40
- * * `fundWith`: The amount to fund the account with it it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account @see {getDispenserAccount}
64
+ * * `fundWith`: The amount to fund the account with it it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account
41
65
  * @param algod An algod client
42
- * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
66
+ * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables
43
67
  * @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account)
44
68
  */
45
69
  export declare function getAccount(account: {
46
70
  name: string;
47
71
  fundWith?: AlgoAmount;
48
72
  } | string, algod: Algodv2, kmdClient?: Kmd): Promise<Account | SigningAccount>;
49
- /**
50
- * Parameters for the getTestAccount function.
51
- */
52
- interface GetTestAccountParams {
53
- /** Initial funds to ensure the account has */
54
- initialFunds: AlgoAmount;
55
- /** Whether to suppress the log (which includes a mnemonic) or not (default: do not supress the log) */
56
- suppressLog?: boolean;
57
- }
58
- /**
59
- * Creates an ephemeral Algorand account for the purposes of testing.
60
- * Returns a newly created random test account that is funded from the dispenser @see {getDispenserAccount}
61
- * DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!
62
- * Note: By default this will log the mnemonic of the account.
63
- * @param param0 The config for the test account to generate
64
- * @param algod An algod client
65
- * @returns The account, with private key loaded
66
- */
67
- export declare function getTestAccount({ suppressLog, initialFunds }: GetTestAccountParams, algod: Algodv2): Promise<Account>;
68
73
  /** Returns an account's address as a byte array
69
74
  *
70
75
  * @param account Either an account (with private key loaded) or the string address of an account
71
76
  */
72
- export declare function getAccountAddressAsUint8Array(account: Account | string): Uint8Array;
77
+ export declare function getAccountAddressAsUint8Array(account: SendTransactionFrom | string): Uint8Array;
73
78
  /** Returns the string address of an Algorand account from a base64 encoded version of the underlying byte array of the address public key
74
79
  *
75
80
  * @param addressEncodedInB64 The base64 encoded version of the underlying byte array of the address public key
@@ -77,11 +82,11 @@ export declare function getAccountAddressAsUint8Array(account: Account | string)
77
82
  export declare function getAccountAddressAsString(addressEncodedInB64: string): string;
78
83
  /** Returns an account (with private key loaded) that can act as a dispenser
79
84
  *
80
- * If running on Sandbox then it will return the default dispenser account automatically,
81
- * otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC @see {getAccount}
85
+ * If running on LocalNet then it will return the default dispenser account automatically,
86
+ * otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC
82
87
  *
83
88
  * @param algod An algod client
89
+ * @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables
84
90
  */
85
- export declare function getDispenserAccount(algod: Algodv2): Promise<algosdk.Account | SigningAccount>;
86
- export {};
91
+ export declare function getDispenserAccount(algod: Algodv2, kmd?: Kmd): Promise<algosdk.Account | SigningAccount>;
87
92
  //# sourceMappingURL=account.d.ts.map
package/account.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAI1C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAG9C;;GAEG;AACH,eAAO,MAAM,iBAAiB,cAAc,CAAA;AAE5C;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,MAAM,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gB,EAAE,eAAe,EAAE,CAAC,OAAO,GAAG,cAAc,CAAC,EAAE,mBAE9G;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAE7D;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,GAAG,wBAAwB,CAE5G;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAG/D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAGvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAA;CAAE,GAAG,MAAM,EACzD,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,CAmCnC;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,cAElF;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,mBAAmB,EAAE,MAAM,GAAG,MAAM,CAE7E;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,6CAIlE"}
package/account.js CHANGED
@@ -3,17 +3,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getDispenserAccount = exports.getAccountAddressAsString = exports.getAccountAddressAsUint8Array = exports.getTestAccount = exports.getAccount = exports.getAccountFromMnemonic = exports.DISPENSER_ACCOUNT = void 0;
6
+ exports.getDispenserAccount = exports.getAccountAddressAsString = exports.getAccountAddressAsUint8Array = exports.getAccount = exports.randomAccount = exports.mnemonicAccount = exports.transactionSignerAccount = exports.rekeyedAccount = exports.multisigAccount = void 0;
7
7
  const algosdk_1 = __importDefault(require("algosdk"));
8
- const config_1 = require("./config");
8
+ const _1 = require("./");
9
9
  const localnet_1 = require("./localnet");
10
10
  const network_client_1 = require("./network-client");
11
11
  const transaction_1 = require("./transaction");
12
- const transfer_1 = require("./transfer");
12
+ const account_1 = require("./types/account");
13
13
  /**
14
- * The account name identifier used for fund dispensing in test environments
14
+ * Returns an account wrapper that supports partial or full multisig signing.
15
+ * @param multisigParams The parameters that define the multisig account
16
+ * @param signingAccounts The signers that are currently present
17
+ * @returns A multisig account wrapper
15
18
  */
16
- exports.DISPENSER_ACCOUNT = 'DISPENSER';
19
+ function multisigAccount(multisigParams, signingAccounts) {
20
+ return new account_1.MultisigAccount(multisigParams, signingAccounts);
21
+ }
22
+ exports.multisigAccount = multisigAccount;
23
+ /**
24
+ * Returns an account wrapper that supports a rekeyed account.
25
+ * @param signer The account, with private key loaded, that is signing
26
+ * @param sender The address of the rekeyed account that will act as a sender
27
+ * @returns The SigningAccount wrapper
28
+ */
29
+ function rekeyedAccount(signer, sender) {
30
+ return new account_1.SigningAccount(signer, sender);
31
+ }
32
+ exports.rekeyedAccount = rekeyedAccount;
33
+ /**
34
+ * Returns an account wrapper that supports a transaction signer with associated sender address.
35
+ * @param signer The transaction signer
36
+ * @param sender The address of sender account
37
+ * @returns The SigningAccount wrapper
38
+ */
39
+ function transactionSignerAccount(signer, sender) {
40
+ return { addr: sender, signer };
41
+ }
42
+ exports.transactionSignerAccount = transactionSignerAccount;
17
43
  /** Returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
18
44
  *
19
45
  * This is a wrapper around algosdk.mnemonicToSecretKey to provide a more friendly/obvious name.
@@ -21,28 +47,38 @@ exports.DISPENSER_ACCOUNT = 'DISPENSER';
21
47
  * @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
22
48
  * never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
23
49
  */
24
- function getAccountFromMnemonic(mnemonicSecret) {
50
+ function mnemonicAccount(mnemonicSecret) {
25
51
  // This method is confusingly named, so this function provides a more dev friendly "wrapper" name
26
52
  return algosdk_1.default.mnemonicToSecretKey(mnemonicSecret);
27
53
  }
28
- exports.getAccountFromMnemonic = getAccountFromMnemonic;
54
+ exports.mnemonicAccount = mnemonicAccount;
55
+ /** Returns a new, random Algorand account with secret key loaded.
56
+ *
57
+ * This is a wrapper around algosdk.generateAccount to provide a more friendly/obvious name.
58
+ *
59
+ */
60
+ function randomAccount() {
61
+ // This method is confusingly named, so this function provides a more dev friendly "wrapper" name
62
+ return algosdk_1.default.generateAccount();
63
+ }
64
+ exports.randomAccount = randomAccount;
29
65
  /**
30
66
  * Returns an Algorand account with private key loaded by convention based on the given name identifier.
31
67
  *
32
68
  * Note: This function expects to run in a Node.js environment.
33
69
  *
34
70
  * ## Convention:
35
- * * **Non-LocalNet:** will load process.env['{NAME}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
71
+ * * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
36
72
  * never commit it into source control and ideally load it via a secret storage service rather than the file system.
37
- * If process.env['{NAME}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
38
- * * **LocalNet:** will load the account from a KMD wallet called {NAME} and if that wallet doesn't exist it will create it and fund the account for you
73
+ * If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
74
+ * * **LocalNet:** will load the account from a KMD wallet called \{NAME\} and if that wallet doesn't exist it will create it and fund the account for you
39
75
  *
40
76
  * This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
41
77
  *
42
78
  * @example Default
43
79
  *
44
80
  * If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
45
- * ```
81
+ * ```typescript
46
82
  * const account = await getAccount('ACCOUNT', algod)
47
83
  * ```
48
84
  *
@@ -50,9 +86,9 @@ exports.getAccountFromMnemonic = getAccountFromMnemonic;
50
86
  *
51
87
  * @param account The details of the account to get, wither the name identifier (string) or an object with:
52
88
  * * `name`: The name identifier of the account
53
- * * `fundWith`: The amount to fund the account with it it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account @see {getDispenserAccount}
89
+ * * `fundWith`: The amount to fund the account with it it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account
54
90
  * @param algod An algod client
55
- * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
91
+ * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables
56
92
  * @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account)
57
93
  */
58
94
  async function getAccount(account, algod, kmdClient) {
@@ -71,12 +107,12 @@ async function getAccount(account, algod, kmdClient) {
71
107
  const envKey = `${name.toUpperCase()}_MNEMONIC`;
72
108
  if (process.env[envKey]) {
73
109
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
74
- const signer = getAccountFromMnemonic(process.env[envKey]);
110
+ const signer = mnemonicAccount(process.env[envKey]);
75
111
  const senderKey = `${name.toUpperCase()}_SENDER`;
76
112
  if (process.env[senderKey]) {
77
- config_1.AlgoKitConfig.logger.debug(`Using rekeyed account ${signer.addr} for sender ${process.env[senderKey]} for ${name} account`);
113
+ _1.Config.logger.debug(`Using rekeyed account ${signer.addr} for sender ${process.env[senderKey]} for ${name} account`);
78
114
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
79
- return new transaction_1.SigningAccount(signer, process.env[senderKey]);
115
+ return new account_1.SigningAccount(signer, process.env[senderKey]);
80
116
  }
81
117
  else {
82
118
  return signer;
@@ -90,34 +126,12 @@ async function getAccount(account, algod, kmdClient) {
90
126
  throw `Missing environment variable ${envKey} when looking for account ${name}`;
91
127
  }
92
128
  exports.getAccount = getAccount;
93
- /**
94
- * Creates an ephemeral Algorand account for the purposes of testing.
95
- * Returns a newly created random test account that is funded from the dispenser @see {getDispenserAccount}
96
- * DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!
97
- * Note: By default this will log the mnemonic of the account.
98
- * @param param0 The config for the test account to generate
99
- * @param algod An algod client
100
- * @returns The account, with private key loaded
101
- */
102
- async function getTestAccount({ suppressLog, initialFunds }, algod) {
103
- const account = algosdk_1.default.generateAccount();
104
- config_1.AlgoKitConfig.getLogger(suppressLog).info(`New test account created with address '${account.addr}' and mnemonic '${algosdk_1.default.secretKeyToMnemonic(account.sk)}'.`);
105
- // If we are running against LocalNet we can use the default account within it
106
- // otherwise use an automation account specified via environment variables and ensure it's populated with ALGOs
107
- const canFundFromDefaultAccount = await (0, network_client_1.isLocalNet)(algod);
108
- const dispenser = canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod) : await getAccount(exports.DISPENSER_ACCOUNT, algod);
109
- await (0, transfer_1.transferAlgos)({ from: dispenser, to: account.addr, amount: initialFunds, note: 'Funding test account', suppressLog }, algod);
110
- const accountInfo = await algod.accountInformation(account.addr).do();
111
- config_1.AlgoKitConfig.getLogger(suppressLog).info('Test account funded; account balance: %d µAlgos', accountInfo.amount);
112
- return account;
113
- }
114
- exports.getTestAccount = getTestAccount;
115
129
  /** Returns an account's address as a byte array
116
130
  *
117
131
  * @param account Either an account (with private key loaded) or the string address of an account
118
132
  */
119
133
  function getAccountAddressAsUint8Array(account) {
120
- return algosdk_1.default.decodeAddress(typeof account === 'string' ? account : account.addr).publicKey;
134
+ return algosdk_1.default.decodeAddress(typeof account === 'string' ? account : (0, transaction_1.getSenderAddress)(account)).publicKey;
121
135
  }
122
136
  exports.getAccountAddressAsUint8Array = getAccountAddressAsUint8Array;
123
137
  /** Returns the string address of an Algorand account from a base64 encoded version of the underlying byte array of the address public key
@@ -130,15 +144,16 @@ function getAccountAddressAsString(addressEncodedInB64) {
130
144
  exports.getAccountAddressAsString = getAccountAddressAsString;
131
145
  /** Returns an account (with private key loaded) that can act as a dispenser
132
146
  *
133
- * If running on Sandbox then it will return the default dispenser account automatically,
134
- * otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC @see {getAccount}
147
+ * If running on LocalNet then it will return the default dispenser account automatically,
148
+ * otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC
135
149
  *
136
150
  * @param algod An algod client
151
+ * @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables
137
152
  */
138
- async function getDispenserAccount(algod) {
139
- // If we are running against a sandbox we can use the default account within it, otherwise use an automation account specified via environment variables and ensure it's populated with ALGOs
153
+ async function getDispenserAccount(algod, kmd) {
154
+ // If we are running against LocalNet we can use the default account within it, otherwise use an automation account specified via environment variables and ensure it's populated with ALGOs
140
155
  const canFundFromDefaultAccount = await (0, network_client_1.isLocalNet)(algod);
141
- return canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod) : await getAccount(exports.DISPENSER_ACCOUNT, algod);
156
+ return canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod, kmd) : await getAccount(account_1.DISPENSER_ACCOUNT, algod);
142
157
  }
143
158
  exports.getDispenserAccount = getDispenserAccount;
144
159
  //# sourceMappingURL=account.js.map
package/account.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwD;AAExD,qCAAwC;AACxC,yCAAqF;AACrF,qDAA6C;AAC7C,+CAA8C;AAC9C,yCAA0C;AAE1C;;GAEG;AACU,QAAA,iBAAiB,GAAG,WAAW,CAAA;AAE5C;;;;;;GAMG;AACH,SAAgB,sBAAsB,C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ACjE,4LAA4L;IAC5L,MAAM,yBAAyB,GAAG,MAAM,IAAA,2BAAU,EAAC,KAAK,CAAC,CAAA;IACzD,OAAO,yBAAyB,CAAC,CAAC,CAAC,MAAM,IAAA,sCAA2B,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,2BAAiB,EAAE,KAAK,CAAC,CAAA;AAC/H,CAAC;AAJD,kDAIC"}
package/amount.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { AlgoAmount } from './types/amount';
2
+ declare global {
3
+ interface Number {
4
+ microAlgos(this: number): AlgoAmount;
5
+ algos(this: number): AlgoAmount;
6
+ }
7
+ }
8
+ /** Returns an amount of Algos using AlgoAmount
9
+ * @param algos The amount in Algos
10
+ */
11
+ export declare const algos: (algos: number) => AlgoAmount;
12
+ /** Returns an amount of µAlgos using AlgoAmount
13
+ * @param microAlgos The amount in µAlgos
14
+ */
15
+ export declare const microAlgos: (microAlgos: number) => AlgoAmount;
16
+ /** Returns an amount of µAlgos to cover standard fees for the given number of transactions using AlgoAmount
17
+ * @param numberOfTransactions The of standard transaction fees to return the amount of ALGOs
18
+ */
19
+ export declare const transactionFees: (numberOfTransactions: number) => AlgoAmount;
20
+ //# sourceMappingURL=amount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../src/amount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAA;QACpC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAA;KAChC;CACF;AAUD;;GAEG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM,eAElC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,eAAgB,MAAM,eAE5C,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,yBAA0B,MAAM,eAE3D,CAAA"}
package/amount.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.transactionFees = exports.microAlgos = exports.algos = void 0;
7
+ const algosdk_1 = __importDefault(require("algosdk"));
8
+ const amount_1 = require("./types/amount");
9
+ Number.prototype.microAlgos = function () {
10
+ return amount_1.AlgoAmount.MicroAlgos(this);
11
+ };
12
+ Number.prototype.algos = function () {
13
+ return amount_1.AlgoAmount.Algos(this);
14
+ };
15
+ /** Returns an amount of Algos using AlgoAmount
16
+ * @param algos The amount in Algos
17
+ */
18
+ const algos = (algos) => {
19
+ return amount_1.AlgoAmount.Algos(algos);
20
+ };
21
+ exports.algos = algos;
22
+ /** Returns an amount of µAlgos using AlgoAmount
23
+ * @param microAlgos The amount in µAlgos
24
+ */
25
+ const microAlgos = (microAlgos) => {
26
+ return amount_1.AlgoAmount.MicroAlgos(microAlgos);
27
+ };
28
+ exports.microAlgos = microAlgos;
29
+ /** Returns an amount of µAlgos to cover standard fees for the given number of transactions using AlgoAmount
30
+ * @param numberOfTransactions The of standard transaction fees to return the amount of ALGOs
31
+ */
32
+ const transactionFees = (numberOfTransactions) => {
33
+ return amount_1.AlgoAmount.MicroAlgos(numberOfTransactions * algosdk_1.default.ALGORAND_MIN_TX_FEE);
34
+ };
35
+ exports.transactionFees = transactionFees;
36
+ //# sourceMappingURL=amount.js.map
package/amount.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amount.js","sourceRoot":"","sources":["../src/amount.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAC7B,2CAA2C;AAS3C,MAAM,CAAC,SAAS,CAAC,UAAU,GAAG;IAC5B,OAAO,mBAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AACpC,CAAC,CAAA;AAED,MAAM,CAAC,SAAS,CAAC,KAAK,GAAG;IACvB,OAAO,mBAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC,CAAA;AAED;;GAEG;AACI,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE;IACrC,OAAO,mBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA;AAFY,QAAA,KAAK,SAEjB;AAED;;GAEG;AACI,MAAM,UAAU,GAAG,CAAC,UAAkB,EAAE,EAAE;IAC/C,OAAO,mBAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;AAC1C,CAAC,CAAA;AAFY,QAAA,UAAU,cAEtB;AAED;;GAEG;AACI,MAAM,eAAe,GAAG,CAAC,oBAA4B,EAAE,EAAE;IAC9D,OAAO,mBAAU,CAAC,UAAU,CAAC,oBAAoB,GAAG,iBAAO,CAAC,mBAAmB,CAAC,CAAA;AAClF,CAAC,CAAA;AAFY,QAAA,eAAe,mBAE3B"}
@@ -0,0 +1,14 @@
1
+ import { Algodv2 } from 'algosdk';
2
+ import { ApplicationClient, AppSpecAppDetails } from './types/app-client';
3
+ /**
4
+ * @deprecated Use `algokit.getAppClient`
5
+ */
6
+ export declare const getApplicationClient: typeof getAppClient;
7
+ /**
8
+ * Create a new ApplicationClient instance
9
+ * @param appDetails The details of the app
10
+ * @param algod An algod instance
11
+ * @returns The application client
12
+ */
13
+ export declare function getAppClient(appDetails: AppSpecAppDetails, algod: Algodv2): ApplicationClient;
14
+ //# sourceMappingURL=app-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-client.d.ts","sourceRoot":"","sources":["../src/app-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAEzE;;GAEG;AACH,eAAO,MAAM,oBAAoB,qBAAe,CAAA;AAEhD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,iBAAiB,EAAE,KAAK,EAAE,OAAO,qBAEzE"}
package/app-client.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAppClient = exports.getApplicationClient = void 0;
4
+ const app_client_1 = require("./types/app-client");
5
+ /**
6
+ * @deprecated Use `algokit.getAppClient`
7
+ */
8
+ exports.getApplicationClient = getAppClient;
9
+ /**
10
+ * Create a new ApplicationClient instance
11
+ * @param appDetails The details of the app
12
+ * @param algod An algod instance
13
+ * @returns The application client
14
+ */
15
+ function getAppClient(appDetails, algod) {
16
+ return new app_client_1.ApplicationClient(appDetails, algod);
17
+ }
18
+ exports.getAppClient = getAppClient;
19
+ //# sourceMappingURL=app-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-client.js","sourceRoot":"","sources":["../src/app-client.ts"],"names":[],"mappings":";;;AACA,mDAAyE;AAEzE;;GAEG;AACU,QAAA,oBAAoB,GAAG,YAAY,CAAA;AAEhD;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,UAA6B,EAAE,KAAc;IACxE,OAAO,IAAI,8BAAiB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;AACjD,CAAC;AAFD,oCAEC"}
@@ -0,0 +1,95 @@
1
+ import { Algodv2, Indexer } from 'algosdk';
2
+ import { ApplicationStateSchema } from './types/algod';
3
+ import { ABIReturn, AppCompilationResult, AppDeploymentParams, AppDeployMetadata, AppLookup, AppMetadata, CompiledTeal, TealTemplateParams } from './types/app';
4
+ import { Arc2TransactionNote, ConfirmedTransactionResult, ConfirmedTransactionResults, SendTransactionFrom } from './types/transaction';
5
+ /**
6
+ * Idempotently deploy (create, update/delete if changed) an app against the given name via the given creator account, including deploy-time template placeholder substitutions.
7
+ *
8
+ * 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
9
+ *
10
+ * **Note:** When using the return from this function be sure to check `operationPerformed` to get access to various return properties like `transaction`, `confirmation` and `deleteResult`.
11
+ *
12
+ * **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.
13
+ *
14
+ * **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.
15
+ * @param deployment The arguments to control the app deployment
16
+ * @param algod An algod client
17
+ * @param indexer An indexer client, needed if `existingDeployments` not passed in
18
+ * @returns The app reference of the new/existing app
19
+ */
20
+ export declare function deployApp(deployment: AppDeploymentParams, algod: Algodv2, indexer?: Indexer): Promise<Partial<AppCompilationResult> & ((ConfirmedTransactionResults & AppMetadata & {
21
+ return?: ABIReturn;
22
+ operationPerformed: 'create' | 'update';
23
+ }) | (ConfirmedTransactionResults & AppMetadata & {
24
+ return?: ABIReturn;
25
+ deleteReturn?: ABIReturn;
26
+ deleteResult: ConfirmedTransactionResult;
27
+ operationPerformed: 'replace';
28
+ }) | (AppMetadata & {
29
+ operationPerformed: 'nothing';
30
+ }))>;
31
+ /** Returns true is there is a breaking change in the application state schema from before to after.
32
+ * i.e. if the schema becomes larger, since applications can't ask for more schema after creation.
33
+ * Otherwise, there is no error, the app just doesn't store data in the extra schema :(
34
+ *
35
+ * @param before The existing schema
36
+ * @param after The new schema
37
+ * @returns Whether or not there is a breaking change
38
+ */
39
+ export declare function isSchemaIsBroken(before: ApplicationStateSchema, after: ApplicationStateSchema): boolean;
40
+ /**
41
+ * Returns a lookup of name => app metadata (id, address, ...metadata) for all apps created by the given account that have an `AppDeployNote` in the transaction note of the creation transaction.
42
+ *
43
+ * **Note:** It's recommended this is only called once and then stored since it's a somewhat expensive operation (multiple indexer calls).
44
+ *
45
+ * @param creatorAccount The account (with private key loaded) or string address of an account that is the creator of the apps you want to search for
46
+ * @param indexer An indexer client
47
+ * @returns A name-based lookup of the app information (id, address)
48
+ */
49
+ export declare function getCreatorAppsByName(creatorAccount: SendTransactionFrom | string, indexer: Indexer): Promise<AppLookup>;
50
+ /**
51
+ * Return the transaction note for an app deployment.
52
+ * @param metadata The metadata of the deployment
53
+ * @returns The transaction note as a utf-8 string
54
+ */
55
+ export declare function getAppDeploymentTransactionNote(metadata: AppDeployMetadata): Arc2TransactionNote;
56
+ /**
57
+ * Replaces deploy-time deployment control parameters within the given teal code.
58
+ *
59
+ * * `TMPL_UPDATABLE` for updatability / immutability control
60
+ * * `TMPL_DELETABLE` for deletability / permanence control
61
+ *
62
+ * Note: If these values are not undefined, but the corresponding `TMPL_*` value
63
+ * isn't in the teal code it will throw an exception.
64
+ *
65
+ * @param tealCode The TEAL code to substitute
66
+ * @param params The deploy-time deployment control parameter value to replace
67
+ * @returns The replaced TEAL code
68
+ */
69
+ export declare function replaceDeployTimeControlParams(tealCode: string, params: {
70
+ updatable?: boolean;
71
+ deletable?: boolean;
72
+ }): string;
73
+ /**
74
+ * Performs template substitution of a teal file.
75
+ *
76
+ * Looks for `TMPL_{parameter}` for template replacements.
77
+ *
78
+ * @param tealCode The TEAL logic to compile
79
+ * @param templateParams Any parameters to replace in the .teal file before compiling
80
+ * @returns The TEAL code with replacements
81
+ */
82
+ export declare function performTemplateSubstitution(tealCode: string, templateParams?: TealTemplateParams): string;
83
+ /**
84
+ * Performs template substitution of a teal file and compiles it, returning the compiled result.
85
+ *
86
+ * Looks for `TMPL_{parameter}` for template replacements.
87
+ *
88
+ * @param tealCode The TEAL logic to compile
89
+ * @param algod An algod client
90
+ * @param templateParams Any parameters to replace in the .teal file before compiling
91
+ * @param deploymentMetadata The deployment metadata the app will be deployed with
92
+ * @returns The information about the compiled code
93
+ */
94
+ export declare function performTemplateSubstitutionAndCompile(tealCode: string, algod: Algodv2, templateParams?: TealTemplateParams, deploymentMetadata?: AppDeployMetadata): Promise<CompiledTeal>;
95
+ //# sourceMappingURL=app-deploy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-deploy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