@algorandfoundation/algokit-utils 9.1.1-beta.4 → 9.1.1-beta.6

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.
@@ -18,6 +18,8 @@ var getApplicationAddress = algosdk.getApplicationAddress;
18
18
  var Indexer = algosdk.Indexer;
19
19
  var OnApplicationComplete = algosdk.OnApplicationComplete;
20
20
  var SourceMap = algosdk.ProgramSourceMap;
21
+ /** The maximum opcode budget for a simulate call as per https://github.com/algorand/go-algorand/blob/807b29a91c371d225e12b9287c5d56e9b33c4e4c/ledger/simulation/trace.go#L104 */
22
+ const MAX_SIMULATE_OPCODE_BUDGET = 20000 * 16;
21
23
  /**
22
24
  * Determines deploy time control (UPDATABLE, DELETABLE) value by inspecting application specification
23
25
  * @param approval TEAL Approval program, not the base64 version found on the appSpec
@@ -913,13 +915,11 @@ class AppClient {
913
915
  ...params,
914
916
  };
915
917
  // Read-only calls do not require fees to be paid, as they are only simulated on the network.
916
- // Therefore there is no value in calculating the minimum fee needed for a successful app call with inner transactions.
917
- // As a a result we only need to send a single simulate call,
918
- // however to do this successfully we need to ensure fees for the transaction are fully covered using maxFee.
919
- if (params.coverAppCallInnerTransactionFees) {
920
- if (params.maxFee === undefined) {
921
- throw Error(`Please provide a maxFee for the transaction when coverAppCallInnerTransactionFees is enabled.`);
922
- }
918
+ // With maximum opcode budget provided, ensure_budget (and similar op-up utilities) won't need to create inner transactions,
919
+ // so fee coverage for op-up inner transactions does not need to be accounted for in readonly calls.
920
+ // If max_fee is provided, use it as static_fee, as there may still be inner transactions sent which need to be covered by the outermost transaction,
921
+ // even though ARC-22 specifies that readonly methods should not send inner transactions.
922
+ if (params.coverAppCallInnerTransactionFees && params.maxFee) {
923
923
  readonlyParams.staticFee = params.maxFee;
924
924
  readonlyParams.extraFee = undefined;
925
925
  }
@@ -931,6 +931,8 @@ class AppClient {
931
931
  allowUnnamedResources: params.populateAppCallResources ?? true,
932
932
  // Simulate calls for a readonly method shouldn't invoke signing
933
933
  skipSignatures: true,
934
+ // Simulate calls for a readonly method can use the max opcode budget
935
+ extraOpcodeBudget: MAX_SIMULATE_OPCODE_BUDGET,
934
936
  });
935
937
  return this.processMethodCallReturn({
936
938
  ...result,
@@ -942,6 +944,8 @@ class AppClient {
942
944
  }
943
945
  catch (e) {
944
946
  const error = e;
947
+ // For read-only calls with max opcode budget, fee issues should be rare
948
+ // but we can still provide helpful error message if they occur
945
949
  if (params.coverAppCallInnerTransactionFees && error && error.message && error.message.match(/fee too small/)) {
946
950
  throw Error(`Fees were too small. You may need to increase the transaction maxFee.`);
947
951
  }