@algorandfoundation/algokit-utils 1.0.0-beta.2 → 1.0.0-beta.21

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 (183) hide show
  1. package/{dist/account.d.ts → account.d.ts} +29 -31
  2. package/account.d.ts.map +1 -0
  3. package/{dist/account.js → account.js} +43 -43
  4. package/account.js.map +1 -0
  5. package/amount.d.ts +8 -0
  6. package/amount.d.ts.map +1 -0
  7. package/amount.js +24 -0
  8. package/amount.js.map +1 -0
  9. package/app.d.ts +51 -0
  10. package/app.d.ts.map +1 -0
  11. package/app.js +288 -0
  12. package/app.js.map +1 -0
  13. package/application-client.d.ts +10 -0
  14. package/application-client.d.ts.map +1 -0
  15. package/application-client.js +15 -0
  16. package/application-client.js.map +1 -0
  17. package/deploy-app.d.ts +93 -0
  18. package/deploy-app.d.ts.map +1 -0
  19. package/{dist/deploy-app.js → deploy-app.js} +129 -137
  20. package/deploy-app.js.map +1 -0
  21. package/index.d.ts +14 -0
  22. package/index.d.ts.map +1 -0
  23. package/{dist/index.js → index.js} +6 -4
  24. package/index.js.map +1 -0
  25. package/{dist/indexer-lookup.d.ts → indexer-lookup.d.ts} +1 -1
  26. package/{dist/indexer-lookup.d.ts.map → indexer-lookup.d.ts.map} +1 -1
  27. package/{dist/localnet.d.ts → localnet.d.ts} +4 -4
  28. package/localnet.d.ts.map +1 -0
  29. package/{dist/localnet.js → localnet.js} +10 -10
  30. package/localnet.js.map +1 -0
  31. package/{dist/network-client.d.ts → network-client.d.ts} +11 -20
  32. package/network-client.d.ts.map +1 -0
  33. package/{dist/network-client.js → network-client.js} +11 -11
  34. package/{dist/network-client.js.map → network-client.js.map} +1 -1
  35. package/package.json +4 -92
  36. package/testing/account.d.ts +14 -0
  37. package/testing/account.d.ts.map +1 -0
  38. package/testing/account.js +31 -0
  39. package/testing/account.js.map +1 -0
  40. package/testing/fixtures/algokit-log-capture-fixture.d.ts +19 -0
  41. package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +1 -0
  42. package/testing/fixtures/algokit-log-capture-fixture.js +43 -0
  43. package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -0
  44. package/testing/fixtures/algorand-fixture.d.ts +20 -0
  45. package/testing/fixtures/algorand-fixture.d.ts.map +1 -0
  46. package/testing/fixtures/algorand-fixture.js +49 -0
  47. package/testing/fixtures/algorand-fixture.js.map +1 -0
  48. package/testing/fixtures/index.d.ts +3 -0
  49. package/testing/fixtures/index.d.ts.map +1 -0
  50. package/testing/fixtures/index.js +19 -0
  51. package/testing/fixtures/index.js.map +1 -0
  52. package/testing/index.d.ts +6 -0
  53. package/testing/index.d.ts.map +1 -0
  54. package/testing/index.js +22 -0
  55. package/testing/index.js.map +1 -0
  56. package/testing/indexer.d.ts +12 -0
  57. package/testing/indexer.d.ts.map +1 -0
  58. package/testing/indexer.js +39 -0
  59. package/testing/indexer.js.map +1 -0
  60. package/testing/test-logger.d.ts +39 -0
  61. package/testing/test-logger.d.ts.map +1 -0
  62. package/testing/test-logger.js +69 -0
  63. package/testing/test-logger.js.map +1 -0
  64. package/testing/transaction-logger.d.ts +29 -0
  65. package/testing/transaction-logger.d.ts.map +1 -0
  66. package/testing/transaction-logger.js +71 -0
  67. package/testing/transaction-logger.js.map +1 -0
  68. package/transaction.d.ts +80 -0
  69. package/transaction.d.ts.map +1 -0
  70. package/{dist/transaction.js → transaction.js} +88 -106
  71. package/transaction.js.map +1 -0
  72. package/transfer.d.ts +21 -0
  73. package/transfer.d.ts.map +1 -0
  74. package/transfer.js +65 -0
  75. package/transfer.js.map +1 -0
  76. package/types/account.d.ts +52 -0
  77. package/types/account.d.ts.map +1 -0
  78. package/types/account.js +86 -0
  79. package/types/account.js.map +1 -0
  80. package/types/algo-http-client-with-retry.d.ts.map +1 -0
  81. package/{dist → types}/algo-http-client-with-retry.js +2 -2
  82. package/types/algo-http-client-with-retry.js.map +1 -0
  83. package/{dist/algod-type.d.ts → types/algod.d.ts} +6 -7
  84. package/types/algod.d.ts.map +1 -0
  85. package/{dist/algod-type.js → types/algod.js} +1 -1
  86. package/types/algod.js.map +1 -0
  87. package/{dist/algo-amount.d.ts → types/amount.d.ts} +3 -1
  88. package/types/amount.d.ts.map +1 -0
  89. package/{dist/algo-amount.js → types/amount.js} +7 -1
  90. package/types/amount.js.map +1 -0
  91. package/types/app.d.ts +234 -0
  92. package/types/app.d.ts.map +1 -0
  93. package/types/app.js +32 -0
  94. package/types/app.js.map +1 -0
  95. package/types/application-client.d.ts +155 -0
  96. package/types/application-client.d.ts.map +1 -0
  97. package/types/application-client.js +348 -0
  98. package/types/application-client.js.map +1 -0
  99. package/types/appspec.d.ts +77 -0
  100. package/types/appspec.d.ts.map +1 -0
  101. package/types/appspec.js +15 -0
  102. package/types/appspec.js.map +1 -0
  103. package/types/config.d.ts +15 -0
  104. package/types/config.d.ts.map +1 -0
  105. package/types/config.js +27 -0
  106. package/types/config.js.map +1 -0
  107. package/{dist/indexer-type.d.ts → types/indexer.d.ts} +9 -10
  108. package/types/indexer.d.ts.map +1 -0
  109. package/{dist/indexer-type.js → types/indexer.js} +1 -1
  110. package/types/indexer.js.map +1 -0
  111. package/{dist/config.d.ts → types/logging.d.ts} +3 -15
  112. package/types/logging.d.ts.map +1 -0
  113. package/types/logging.js +27 -0
  114. package/types/logging.js.map +1 -0
  115. package/types/logic-error.d.ts +33 -0
  116. package/types/logic-error.d.ts.map +1 -0
  117. package/types/logic-error.js +46 -0
  118. package/types/logic-error.js.map +1 -0
  119. package/types/network-client.d.ts +11 -0
  120. package/types/network-client.d.ts.map +1 -0
  121. package/types/network-client.js +3 -0
  122. package/types/network-client.js.map +1 -0
  123. package/types/testing.d.ts +89 -0
  124. package/types/testing.d.ts.map +1 -0
  125. package/types/testing.js +3 -0
  126. package/types/testing.js.map +1 -0
  127. package/types/transaction.d.ts +67 -0
  128. package/types/transaction.d.ts.map +1 -0
  129. package/types/transaction.js +3 -0
  130. package/types/transaction.js.map +1 -0
  131. package/types/transfer.d.ts +32 -0
  132. package/types/transfer.d.ts.map +1 -0
  133. package/types/transfer.js +3 -0
  134. package/types/transfer.js.map +1 -0
  135. package/types/urlTokenBaseHTTPClient.d.ts.map +1 -0
  136. package/types/urlTokenBaseHTTPClient.js.map +1 -0
  137. package/LICENSE +0 -21
  138. package/README.md +0 -31
  139. package/dist/account.d.ts.map +0 -1
  140. package/dist/account.js.map +0 -1
  141. package/dist/algo-amount.d.ts.map +0 -1
  142. package/dist/algo-amount.js.map +0 -1
  143. package/dist/algo-http-client-with-retry.d.ts.map +0 -1
  144. package/dist/algo-http-client-with-retry.js.map +0 -1
  145. package/dist/algod-type.d.ts.map +0 -1
  146. package/dist/algod-type.js.map +0 -1
  147. package/dist/app.d.ts +0 -150
  148. package/dist/app.d.ts.map +0 -1
  149. package/dist/app.js +0 -160
  150. package/dist/app.js.map +0 -1
  151. package/dist/application-client.d.ts +0 -1
  152. package/dist/application-client.d.ts.map +0 -1
  153. package/dist/application-client.js +0 -69
  154. package/dist/application-client.js.map +0 -1
  155. package/dist/config.d.ts.map +0 -1
  156. package/dist/config.js +0 -28
  157. package/dist/config.js.map +0 -1
  158. package/dist/deploy-app.d.ts +0 -149
  159. package/dist/deploy-app.d.ts.map +0 -1
  160. package/dist/deploy-app.js.map +0 -1
  161. package/dist/index.d.ts +0 -13
  162. package/dist/index.d.ts.map +0 -1
  163. package/dist/index.js.map +0 -1
  164. package/dist/indexer-type.d.ts.map +0 -1
  165. package/dist/indexer-type.js.map +0 -1
  166. package/dist/localnet.d.ts.map +0 -1
  167. package/dist/localnet.js.map +0 -1
  168. package/dist/network-client.d.ts.map +0 -1
  169. package/dist/package.json +0 -20
  170. package/dist/transaction.d.ts +0 -147
  171. package/dist/transaction.d.ts.map +0 -1
  172. package/dist/transaction.js.map +0 -1
  173. package/dist/transfer.d.ts +0 -24
  174. package/dist/transfer.d.ts.map +0 -1
  175. package/dist/transfer.js +0 -33
  176. package/dist/transfer.js.map +0 -1
  177. package/dist/urlTokenBaseHTTPClient.d.ts.map +0 -1
  178. package/dist/urlTokenBaseHTTPClient.js.map +0 -1
  179. /package/{dist/indexer-lookup.js → indexer-lookup.js} +0 -0
  180. /package/{dist/indexer-lookup.js.map → indexer-lookup.js.map} +0 -0
  181. /package/{dist → types}/algo-http-client-with-retry.d.ts +0 -0
  182. /package/{dist → types}/urlTokenBaseHTTPClient.d.ts +0 -0
  183. /package/{dist → types}/urlTokenBaseHTTPClient.js +0 -0
@@ -1,10 +1,27 @@
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
4
  /**
5
- * The account name identifier used for fund dispensing in test environments
5
+ * Returns an account wrapper that supports partial or full multisig signing.
6
+ * @param multisigParams The parameters that define the multisig account
7
+ * @param signingAccounts The signers that are currently present
8
+ * @returns A multisig account wrapper
6
9
  */
7
- export declare const DISPENSER_ACCOUNT = "DISPENSER";
10
+ export declare function multisigAccount(multisigParams: MultisigMetadata, signingAccounts: (Account | SigningAccount)[]): MultisigAccount;
11
+ /**
12
+ * Returns an account wrapper that supports a rekeyed account.
13
+ * @param account The account, with private key loaded, that is signing
14
+ * @param sender The address of the rekeyed account that will act as a sender
15
+ * @returns The @see SigningAccount wrapper
16
+ */
17
+ export declare function rekeyedAccount(account: Account, sender: string): SigningAccount;
18
+ /**
19
+ * Returns an account wrapper that supports a transaction signer with associated sender address.
20
+ * @param signer The transaction signer
21
+ * @param sender The address of sender account
22
+ * @returns The @see SigningAccount wrapper
23
+ */
24
+ export declare function transactionSignerAccount(signer: TransactionSigner, sender: string): TransactionSignerAccount;
8
25
  /** Returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
9
26
  *
10
27
  * This is a wrapper around algosdk.mnemonicToSecretKey to provide a more friendly/obvious name.
@@ -12,24 +29,24 @@ export declare const DISPENSER_ACCOUNT = "DISPENSER";
12
29
  * @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
13
30
  * 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
31
  */
15
- export declare function getAccountFromMnemonic(mnemonicSecret: string): Account;
32
+ export declare function mnemonicAccount(mnemonicSecret: string): Account;
16
33
  /**
17
34
  * Returns an Algorand account with private key loaded by convention based on the given name identifier.
18
35
  *
19
36
  * Note: This function expects to run in a Node.js environment.
20
37
  *
21
38
  * ## Convention:
22
- * * **Non-LocalNet:** will load process.env['{NAME}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
39
+ * * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
23
40
  * 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
41
+ * If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
42
+ * * **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
43
  *
27
44
  * 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
45
  *
29
46
  * @example Default
30
47
  *
31
48
  * 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
- * ```
49
+ * ```typescript
33
50
  * const account = await getAccount('ACCOUNT', algod)
34
51
  * ```
35
52
  *
@@ -46,25 +63,6 @@ export declare function getAccount(account: {
46
63
  name: string;
47
64
  fundWith?: AlgoAmount;
48
65
  } | 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
66
  /** Returns an account's address as a byte array
69
67
  *
70
68
  * @param account Either an account (with private key loaded) or the string address of an account
@@ -81,7 +79,7 @@ export declare function getAccountAddressAsString(addressEncodedInB64: string):
81
79
  * otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC @see {getAccount}
82
80
  *
83
81
  * @param algod An algod client
82
+ * @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
84
83
  */
85
- export declare function getDispenserAccount(algod: Algodv2): Promise<algosdk.Account | SigningAccount>;
86
- export {};
84
+ export declare function getDispenserAccount(algod: Algodv2, kmd?: Kmd): Promise<algosdk.Account | SigningAccount>;
87
85
  //# sourceMappingURL=account.d.ts.map
@@ -0,0 +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,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAI7F,OAAO,EAAqB,eAAe,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC9G,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC,OAAO,GAAG,cAAc,CAAC,EAAE,mBAE9G;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAE9D;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,OAAO,GAAG,MAAM,cAEtE;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"}
@@ -3,17 +3,42 @@ 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.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
- const transaction_1 = require("./transaction");
12
- const transfer_1 = require("./transfer");
11
+ const account_1 = require("./types/account");
13
12
  /**
14
- * The account name identifier used for fund dispensing in test environments
13
+ * Returns an account wrapper that supports partial or full multisig signing.
14
+ * @param multisigParams The parameters that define the multisig account
15
+ * @param signingAccounts The signers that are currently present
16
+ * @returns A multisig account wrapper
15
17
  */
16
- exports.DISPENSER_ACCOUNT = 'DISPENSER';
18
+ function multisigAccount(multisigParams, signingAccounts) {
19
+ return new account_1.MultisigAccount(multisigParams, signingAccounts);
20
+ }
21
+ exports.multisigAccount = multisigAccount;
22
+ /**
23
+ * Returns an account wrapper that supports a rekeyed account.
24
+ * @param account The account, with private key loaded, that is signing
25
+ * @param sender The address of the rekeyed account that will act as a sender
26
+ * @returns The @see SigningAccount wrapper
27
+ */
28
+ function rekeyedAccount(account, sender) {
29
+ return new account_1.SigningAccount(account, sender);
30
+ }
31
+ exports.rekeyedAccount = rekeyedAccount;
32
+ /**
33
+ * Returns an account wrapper that supports a transaction signer with associated sender address.
34
+ * @param signer The transaction signer
35
+ * @param sender The address of sender account
36
+ * @returns The @see SigningAccount wrapper
37
+ */
38
+ function transactionSignerAccount(signer, sender) {
39
+ return { addr: sender, signer };
40
+ }
41
+ exports.transactionSignerAccount = transactionSignerAccount;
17
42
  /** Returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
18
43
  *
19
44
  * This is a wrapper around algosdk.mnemonicToSecretKey to provide a more friendly/obvious name.
@@ -21,28 +46,28 @@ exports.DISPENSER_ACCOUNT = 'DISPENSER';
21
46
  * @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
22
47
  * 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
48
  */
24
- function getAccountFromMnemonic(mnemonicSecret) {
49
+ function mnemonicAccount(mnemonicSecret) {
25
50
  // This method is confusingly named, so this function provides a more dev friendly "wrapper" name
26
51
  return algosdk_1.default.mnemonicToSecretKey(mnemonicSecret);
27
52
  }
28
- exports.getAccountFromMnemonic = getAccountFromMnemonic;
53
+ exports.mnemonicAccount = mnemonicAccount;
29
54
  /**
30
55
  * Returns an Algorand account with private key loaded by convention based on the given name identifier.
31
56
  *
32
57
  * Note: This function expects to run in a Node.js environment.
33
58
  *
34
59
  * ## Convention:
35
- * * **Non-LocalNet:** will load process.env['{NAME}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
60
+ * * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
36
61
  * 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
62
+ * If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
63
+ * * **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
64
  *
40
65
  * 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
66
  *
42
67
  * @example Default
43
68
  *
44
69
  * 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
- * ```
70
+ * ```typescript
46
71
  * const account = await getAccount('ACCOUNT', algod)
47
72
  * ```
48
73
  *
@@ -71,12 +96,12 @@ async function getAccount(account, algod, kmdClient) {
71
96
  const envKey = `${name.toUpperCase()}_MNEMONIC`;
72
97
  if (process.env[envKey]) {
73
98
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
74
- const signer = getAccountFromMnemonic(process.env[envKey]);
99
+ const signer = mnemonicAccount(process.env[envKey]);
75
100
  const senderKey = `${name.toUpperCase()}_SENDER`;
76
101
  if (process.env[senderKey]) {
77
- config_1.AlgoKitConfig.logger.debug(`Using rekeyed account ${signer.addr} for sender ${process.env[senderKey]} for ${name} account`);
102
+ _1.Config.logger.debug(`Using rekeyed account ${signer.addr} for sender ${process.env[senderKey]} for ${name} account`);
78
103
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
79
- return new transaction_1.SigningAccount(signer, process.env[senderKey]);
104
+ return new account_1.SigningAccount(signer, process.env[senderKey]);
80
105
  }
81
106
  else {
82
107
  return signer;
@@ -90,32 +115,6 @@ async function getAccount(account, algod, kmdClient) {
90
115
  throw `Missing environment variable ${envKey} when looking for account ${name}`;
91
116
  }
92
117
  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
- if (!suppressLog) {
105
- config_1.AlgoKitConfig.logger.info(`New test account created with address '${account.addr}' and mnemonic '${algosdk_1.default.secretKeyToMnemonic(account.sk)}'.`);
106
- }
107
- // If we are running against LocalNet we can use the default account within it
108
- // otherwise use an automation account specified via environment variables and ensure it's populated with ALGOs
109
- const canFundFromDefaultAccount = await (0, network_client_1.isLocalNet)(algod);
110
- const dispenser = canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod) : await getAccount(exports.DISPENSER_ACCOUNT, algod);
111
- await (0, transfer_1.transferAlgos)({ from: dispenser, to: account.addr, amount: initialFunds, note: 'Funding test account', suppressLog }, algod);
112
- const accountInfo = await algod.accountInformation(account.addr).do();
113
- if (!suppressLog) {
114
- config_1.AlgoKitConfig.logger.info('Test account funded; account balance: %d µAlgos', accountInfo.amount);
115
- }
116
- return account;
117
- }
118
- exports.getTestAccount = getTestAccount;
119
118
  /** Returns an account's address as a byte array
120
119
  *
121
120
  * @param account Either an account (with private key loaded) or the string address of an account
@@ -138,11 +137,12 @@ exports.getAccountAddressAsString = getAccountAddressAsString;
138
137
  * otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC @see {getAccount}
139
138
  *
140
139
  * @param algod An algod client
140
+ * @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
141
141
  */
142
- async function getDispenserAccount(algod) {
142
+ async function getDispenserAccount(algod, kmd) {
143
143
  // 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
144
144
  const canFundFromDefaultAccount = await (0, network_client_1.isLocalNet)(algod);
145
- return canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod) : await getAccount(exports.DISPENSER_ACCOUNT, algod);
145
+ return canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod, kmd) : await getAccount(account_1.DISPENSER_ACCOUNT, algod);
146
146
  }
147
147
  exports.getDispenserAccount = getDispenserAccount;
148
148
  //# sourceMappingURL=account.js.map
package/account.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"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"}
package/amount.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { AlgoAmount } from './types/amount';
2
+ /** Returns an amount of Algos using @see AlgoAmount */
3
+ export declare const algos: (algos: number) => AlgoAmount;
4
+ /** Returns an amount of µAlgos using @see AlgoAmount */
5
+ export declare const microAlgos: (microAlgos: number) => AlgoAmount;
6
+ /** Returns an amount of µAlgos to cover standard fees for the given number of transactions using @see AlgoAmount */
7
+ export declare const transactionFees: (numberOfTransactions: number) => AlgoAmount;
8
+ //# 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,uDAAuD;AACvD,eAAO,MAAM,KAAK,UAAW,MAAM,eAElC,CAAA;AAED,wDAAwD;AACxD,eAAO,MAAM,UAAU,eAAgB,MAAM,eAE5C,CAAA;AAED,oHAAoH;AACpH,eAAO,MAAM,eAAe,yBAA0B,MAAM,eAE3D,CAAA"}
package/amount.js ADDED
@@ -0,0 +1,24 @@
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
+ /** Returns an amount of Algos using @see AlgoAmount */
10
+ const algos = (algos) => {
11
+ return amount_1.AlgoAmount.Algos(algos);
12
+ };
13
+ exports.algos = algos;
14
+ /** Returns an amount of µAlgos using @see AlgoAmount */
15
+ const microAlgos = (microAlgos) => {
16
+ return amount_1.AlgoAmount.MicroAlgos(microAlgos);
17
+ };
18
+ exports.microAlgos = microAlgos;
19
+ /** Returns an amount of µAlgos to cover standard fees for the given number of transactions using @see AlgoAmount */
20
+ const transactionFees = (numberOfTransactions) => {
21
+ return amount_1.AlgoAmount.MicroAlgos(numberOfTransactions * algosdk_1.default.ALGORAND_MIN_TX_FEE);
22
+ };
23
+ exports.transactionFees = transactionFees;
24
+ //# 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;AAE3C,uDAAuD;AAChD,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE;IACrC,OAAO,mBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA;AAFY,QAAA,KAAK,SAEjB;AAED,wDAAwD;AACjD,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,oHAAoH;AAC7G,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"}
package/app.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import algosdk, { Algodv2 } from 'algosdk';
2
+ import { ApplicationResponse, PendingTransactionResponse } from './types/algod';
3
+ import { ABIReturn, AppCallArgs, AppCallParams, AppCallTransactionResult, AppCompilationResult, AppReference, CompiledTeal, CreateAppParams, UpdateAppParams } from './types/app';
4
+ /**
5
+ * Creates a smart contract app, returns the details of the created app.
6
+ * @param create The parameters to create the app with
7
+ * @param algod An algod client
8
+ * @returns The details of the created app, or the transaction to create it if `skipSending`
9
+ */
10
+ export declare function createApp(create: CreateAppParams, algod: Algodv2): Promise<Partial<AppCompilationResult> & AppCallTransactionResult & AppReference>;
11
+ /**
12
+ * Updates a smart contract app.
13
+ * @param update The parameters to update the app with
14
+ * @param algod An algod client
15
+ * @returns The transaction
16
+ */
17
+ export declare function updateApp(update: UpdateAppParams, algod: Algodv2): Promise<Partial<AppCompilationResult> & AppCallTransactionResult>;
18
+ /**
19
+ * Issues a call to a given app.
20
+ * @param call The call details.
21
+ * @param algod An algod client
22
+ * @returns The result of the call
23
+ */
24
+ export declare function callApp(call: AppCallParams, algod: Algodv2): Promise<AppCallTransactionResult>;
25
+ export declare function getABIReturn(args?: AppCallArgs, confirmation?: PendingTransactionResponse): ABIReturn | undefined;
26
+ /** Returns the app args ready to load onto an app @see {Transaction} object */
27
+ export declare function getAppArgsForTransaction(args?: AppCallArgs): {
28
+ accounts: string[] | undefined;
29
+ appArgs: Uint8Array[] | undefined;
30
+ boxes: algosdk.BoxReference[] | undefined;
31
+ foreignApps: number[] | undefined;
32
+ foreignAssets: number[] | undefined;
33
+ lease: Uint8Array | undefined;
34
+ } | undefined;
35
+ /**
36
+ * Gets the current data for the given app from algod.
37
+ *
38
+ * @param appId The id of the app
39
+ * @param algod An algod client
40
+ * @returns The data about the app
41
+ */
42
+ export declare function getAppByIndex(appId: number, algod: Algodv2): Promise<ApplicationResponse>;
43
+ /**
44
+ * Compiles the given TEAL using algod and returns the result.
45
+ *
46
+ * @param algod An algod client
47
+ * @param tealCode The TEAL code
48
+ * @returns The information about the compiled file
49
+ */
50
+ export declare function compileTeal(tealCode: string, algod: Algodv2): Promise<CompiledTeal>;
51
+ //# sourceMappingURL=app.d.ts.map
package/app.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAEd,OAAO,EAMR,MAAM,SAAS,CAAA;AAIhB,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAA;AAC/E,OAAO,EACL,SAAS,EAET,WAAW,EACX,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,YAAY,EAEZ,YAAY,EACZ,eAAe,EACf,eAAe,EAChB,MAAM,aAAa,CAAA;AAEpB;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,wBAAwB,GAAG,YAAY,CAAC,CA2ClF;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,wBAAwB,CAAC,CA6BnE;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAqCpG;AAED,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,YAAY,CAAC,EAAE,0BAA0B,GAAG,SAAS,GAAG,SAAS,CA6BjH;AAED,+EAA+E;AAC/E,wBAAgB,wBAAwB,CAAC,IAAI,CAAC,EAAE,WAAW;;;;;;;cA4E1D;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,gCAEhE;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CASzF"}
package/app.js ADDED
@@ -0,0 +1,288 @@
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 = void 0;
27
+ const algosdk_1 = __importStar(require("algosdk"));
28
+ const buffer_1 = require("buffer");
29
+ const _1 = require("./");
30
+ const transaction_1 = require("./transaction");
31
+ const app_1 = require("./types/app");
32
+ /**
33
+ * Creates a smart contract app, returns the details of the created app.
34
+ * @param create The parameters to create the app with
35
+ * @param algod An algod client
36
+ * @returns The details of the created app, or the transaction to create it if `skipSending`
37
+ */
38
+ async function createApp(create, algod) {
39
+ const { from, approvalProgram: approval, clearStateProgram: clear, schema, note, transactionParams, args, ...sendParams } = create;
40
+ const compiledApproval = typeof approval === 'string' ? await compileTeal(approval, algod) : undefined;
41
+ const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : approval;
42
+ const compiledClear = typeof clear === 'string' ? await compileTeal(clear, algod) : undefined;
43
+ const clearProgram = compiledClear ? compiledClear.compiledBase64ToBytes : clear;
44
+ const transaction = algosdk_1.default.makeApplicationCreateTxnFromObject({
45
+ approvalProgram: approvalProgram,
46
+ clearProgram: clearProgram,
47
+ numLocalInts: schema.localInts,
48
+ numLocalByteSlices: schema.localByteSlices,
49
+ numGlobalInts: schema.globalInts,
50
+ numGlobalByteSlices: schema.globalByteSlices,
51
+ extraPages: schema.extraPages ?? Math.floor((approvalProgram.length + clearProgram.length) / app_1.APP_PAGE_MAX_SIZE),
52
+ onComplete: algosdk_1.default.OnApplicationComplete.NoOpOC,
53
+ suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
54
+ from: (0, transaction_1.getSenderAddress)(from),
55
+ note: (0, transaction_1.encodeTransactionNote)(note),
56
+ ...getAppArgsForTransaction(args),
57
+ rekeyTo: undefined,
58
+ });
59
+ const { confirmation } = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
60
+ if (confirmation) {
61
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
62
+ const appId = confirmation['application-index'];
63
+ _1.Config.getLogger(sendParams.suppressLog).debug(`Created app ${appId} from creator ${(0, transaction_1.getSenderAddress)(from)}`);
64
+ return {
65
+ transaction,
66
+ confirmation,
67
+ appId,
68
+ appAddress: algosdk_1.default.getApplicationAddress(appId),
69
+ return: getABIReturn(args, confirmation),
70
+ compiledApproval,
71
+ compiledClear,
72
+ };
73
+ }
74
+ else {
75
+ return { transaction, appId: 0, appAddress: '', compiledApproval, compiledClear };
76
+ }
77
+ }
78
+ exports.createApp = createApp;
79
+ /**
80
+ * Updates a smart contract app.
81
+ * @param update The parameters to update the app with
82
+ * @param algod An algod client
83
+ * @returns The transaction
84
+ */
85
+ async function updateApp(update, algod) {
86
+ const { appId, from, approvalProgram: approval, clearStateProgram: clear, note, transactionParams, args, ...sendParams } = update;
87
+ const compiledApproval = typeof approval === 'string' ? await compileTeal(approval, algod) : undefined;
88
+ const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : approval;
89
+ const compiledClear = typeof clear === 'string' ? await compileTeal(clear, algod) : undefined;
90
+ const clearProgram = compiledClear ? compiledClear.compiledBase64ToBytes : clear;
91
+ const transaction = algosdk_1.default.makeApplicationUpdateTxnFromObject({
92
+ appIndex: appId,
93
+ approvalProgram: approvalProgram,
94
+ clearProgram: clearProgram,
95
+ suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
96
+ from: (0, transaction_1.getSenderAddress)(from),
97
+ note: (0, transaction_1.encodeTransactionNote)(note),
98
+ ...getAppArgsForTransaction(args),
99
+ rekeyTo: undefined,
100
+ });
101
+ _1.Config.getLogger(sendParams.suppressLog).debug(`Updating app ${appId}`);
102
+ const result = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
103
+ return {
104
+ ...result,
105
+ return: getABIReturn(args, result.confirmation),
106
+ compiledApproval,
107
+ compiledClear,
108
+ };
109
+ }
110
+ exports.updateApp = updateApp;
111
+ /**
112
+ * Issues a call to a given app.
113
+ * @param call The call details.
114
+ * @param algod An algod client
115
+ * @returns The result of the call
116
+ */
117
+ async function callApp(call, algod) {
118
+ const { appId, callType, from, args, note, transactionParams, ...sendParams } = call;
119
+ const appCallParameters = {
120
+ appIndex: appId,
121
+ from: (0, transaction_1.getSenderAddress)(from),
122
+ suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
123
+ ...getAppArgsForTransaction(args),
124
+ note: (0, transaction_1.encodeTransactionNote)(note),
125
+ rekeyTo: undefined,
126
+ };
127
+ let transaction;
128
+ switch (callType) {
129
+ case 'optin':
130
+ transaction = algosdk_1.default.makeApplicationOptInTxnFromObject(appCallParameters);
131
+ break;
132
+ case 'clearstate':
133
+ transaction = algosdk_1.default.makeApplicationClearStateTxnFromObject(appCallParameters);
134
+ break;
135
+ case 'closeout':
136
+ transaction = algosdk_1.default.makeApplicationCloseOutTxnFromObject(appCallParameters);
137
+ break;
138
+ case 'delete':
139
+ transaction = algosdk_1.default.makeApplicationDeleteTxnFromObject(appCallParameters);
140
+ break;
141
+ case 'normal':
142
+ transaction = algosdk_1.default.makeApplicationNoOpTxnFromObject(appCallParameters);
143
+ break;
144
+ }
145
+ const result = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
146
+ return {
147
+ ...result,
148
+ return: getABIReturn(args, result.confirmation),
149
+ };
150
+ }
151
+ exports.callApp = callApp;
152
+ function getABIReturn(args, confirmation) {
153
+ try {
154
+ if (!args || !('method' in args)) {
155
+ return undefined;
156
+ }
157
+ const method = 'txnCount' in args.method ? args.method : new algosdk_1.ABIMethod(args.method);
158
+ if (method.returns.type !== 'void' && confirmation) {
159
+ const logs = confirmation.logs || [];
160
+ if (logs.length === 0) {
161
+ throw new Error('App call transaction did not log a return value');
162
+ }
163
+ const lastLog = logs[logs.length - 1];
164
+ if (lastLog.byteLength < 4 || lastLog.slice(0, 4).toString() !== app_1.ABI_RETURN_PREFIX.toString()) {
165
+ throw new Error('App call transaction did not log a return value (ABI_RETURN_PREFIX not found)');
166
+ }
167
+ return {
168
+ rawReturnValue: new Uint8Array(lastLog.slice(4)),
169
+ returnValue: method.returns.type.decode(new Uint8Array(lastLog.slice(4))),
170
+ decodeError: undefined,
171
+ };
172
+ }
173
+ }
174
+ catch (e) {
175
+ return {
176
+ rawReturnValue: undefined,
177
+ returnValue: undefined,
178
+ decodeError: e,
179
+ };
180
+ }
181
+ return undefined;
182
+ }
183
+ exports.getABIReturn = getABIReturn;
184
+ /** Returns the app args ready to load onto an app @see {Transaction} object */
185
+ function getAppArgsForTransaction(args) {
186
+ if (!args)
187
+ return undefined;
188
+ let actualArgs;
189
+ if ('method' in args) {
190
+ // todo: Land a change to algosdk that extract the logic from ATC, because (fair warning) this is a HACK
191
+ // I don't want to have to rewrite all of the ABI resolution logic so using an ATC temporarily here
192
+ // and passing stuff in to keep it happy like a randomly generated account :O
193
+ // Most of these values aren't being used since the transaction is discarded
194
+ const dummyAtc = new algosdk_1.AtomicTransactionComposer();
195
+ const dummyAccount = algosdk_1.default.generateAccount();
196
+ const dummySigner = (0, algosdk_1.makeBasicAccountTransactionSigner)(dummyAccount);
197
+ const dummyAppId = 1;
198
+ const dummyParams = {
199
+ fee: 1,
200
+ firstRound: 1,
201
+ genesisHash: buffer_1.Buffer.from('abcd', 'utf-8').toString('base64'),
202
+ genesisID: 'a',
203
+ lastRound: 1,
204
+ };
205
+ const methodArgs = args.args?.map((a) => {
206
+ if (typeof a !== 'object') {
207
+ return a;
208
+ }
209
+ // Handle the various forms of transactions to wrangle them for ATC
210
+ return 'txn' in a
211
+ ? a
212
+ : 'transaction' in a
213
+ ? { txn: a.transaction, signer: dummySigner }
214
+ : 'txID' in a
215
+ ? { txn: a, signer: dummySigner }
216
+ : a;
217
+ });
218
+ const dummyOnComplete = algosdk_1.OnApplicationComplete.NoOpOC;
219
+ dummyAtc.addMethodCall({
220
+ method: 'txnCount' in args.method ? args.method : new algosdk_1.ABIMethod(args.method),
221
+ methodArgs,
222
+ // Rest are dummy values
223
+ appID: dummyAppId,
224
+ sender: dummyAccount.addr,
225
+ signer: dummySigner,
226
+ suggestedParams: dummyParams,
227
+ onComplete: dummyOnComplete,
228
+ });
229
+ const txn = dummyAtc.buildGroup()[0];
230
+ actualArgs = {
231
+ accounts: txn.txn.appAccounts,
232
+ appArgs: txn.txn.appArgs,
233
+ apps: txn.txn.appForeignApps,
234
+ assets: txn.txn.appForeignAssets,
235
+ boxes: txn.txn.boxes?.map((b) => ({
236
+ appId: b.appIndex,
237
+ name: b.name,
238
+ })),
239
+ lease: args.lease,
240
+ };
241
+ }
242
+ else {
243
+ actualArgs = args;
244
+ }
245
+ const encoder = new TextEncoder();
246
+ return {
247
+ accounts: actualArgs?.accounts?.map((a) => (typeof a === 'string' ? a : algosdk_1.default.encodeAddress(a.publicKey))),
248
+ appArgs: actualArgs?.appArgs?.map((a) => (typeof a === 'string' ? encoder.encode(a) : a)),
249
+ boxes: actualArgs?.boxes?.map((ref) => ({
250
+ appIndex: ref.appId,
251
+ name: typeof ref.name === 'string' ? encoder.encode(ref.name) : ref.name,
252
+ })),
253
+ foreignApps: actualArgs?.apps,
254
+ foreignAssets: actualArgs?.assets,
255
+ lease: typeof actualArgs?.lease === 'string' ? encoder.encode(actualArgs?.lease) : actualArgs?.lease,
256
+ };
257
+ }
258
+ exports.getAppArgsForTransaction = getAppArgsForTransaction;
259
+ /**
260
+ * Gets the current data for the given app from algod.
261
+ *
262
+ * @param appId The id of the app
263
+ * @param algod An algod client
264
+ * @returns The data about the app
265
+ */
266
+ async function getAppByIndex(appId, algod) {
267
+ return (await algod.getApplicationByID(appId).do());
268
+ }
269
+ exports.getAppByIndex = getAppByIndex;
270
+ /**
271
+ * Compiles the given TEAL using algod and returns the result.
272
+ *
273
+ * @param algod An algod client
274
+ * @param tealCode The TEAL code
275
+ * @returns The information about the compiled file
276
+ */
277
+ async function compileTeal(tealCode, algod) {
278
+ const compiled = await algod.compile(tealCode).sourcemap(true).do();
279
+ return {
280
+ teal: tealCode,
281
+ compiled: compiled.result,
282
+ compiledHash: compiled.hash,
283
+ compiledBase64ToBytes: new Uint8Array(buffer_1.Buffer.from(compiled.result, 'base64')),
284
+ sourceMap: new algosdk_1.SourceMap(compiled['sourcemap']),
285
+ };
286
+ }
287
+ exports.compileTeal = compileTeal;
288
+ //# sourceMappingURL=app.js.map