@fuel-ts/account 0.0.0-pr-1788-20240222094224 → 0.75.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.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

Files changed (38) hide show
  1. package/dist/connectors/fuel-connector.d.ts +2 -1
  2. package/dist/connectors/fuel-connector.d.ts.map +1 -1
  3. package/dist/connectors/types/data-type.d.ts +0 -8
  4. package/dist/connectors/types/data-type.d.ts.map +1 -1
  5. package/dist/connectors/types/events.d.ts +2 -36
  6. package/dist/connectors/types/events.d.ts.map +1 -1
  7. package/dist/connectors/types/index.d.ts +0 -2
  8. package/dist/connectors/types/index.d.ts.map +1 -1
  9. package/dist/index.global.js +543 -409
  10. package/dist/index.global.js.map +1 -1
  11. package/dist/index.js +143 -172
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +132 -159
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/providers/fuel-graphql-subscriber.d.ts +13 -3
  16. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  17. package/dist/providers/provider.d.ts +9 -3
  18. package/dist/providers/provider.d.ts.map +1 -1
  19. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  20. package/dist/providers/transaction-summary/operations.d.ts +0 -2
  21. package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
  22. package/dist/providers/transaction-summary/output.d.ts +2 -2
  23. package/dist/providers/transaction-summary/output.d.ts.map +1 -1
  24. package/dist/providers/transaction-summary/types.d.ts +0 -1
  25. package/dist/providers/transaction-summary/types.d.ts.map +1 -1
  26. package/dist/test-utils.global.js +543 -400
  27. package/dist/test-utils.global.js.map +1 -1
  28. package/dist/test-utils.js +144 -160
  29. package/dist/test-utils.js.map +1 -1
  30. package/dist/test-utils.mjs +132 -148
  31. package/dist/test-utils.mjs.map +1 -1
  32. package/package.json +16 -16
  33. package/dist/connectors/types/asset.d.ts +0 -2
  34. package/dist/connectors/types/asset.d.ts.map +0 -1
  35. package/dist/connectors/types/constants.d.ts +0 -7
  36. package/dist/connectors/types/constants.d.ts.map +0 -1
  37. package/dist/connectors/types/message.d.ts +0 -15
  38. package/dist/connectors/types/message.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -893,67 +893,63 @@ function getSdk(requester) {
893
893
  // src/providers/fuel-graphql-subscriber.ts
894
894
  import { FuelError } from "@fuel-ts/errors";
895
895
  import { print } from "graphql";
896
- var _FuelSubscriptionStream = class {
897
- readable;
898
- writable;
899
- readableStreamController;
900
- constructor() {
901
- this.readable = new ReadableStream({
902
- start: (controller) => {
903
- this.readableStreamController = controller;
904
- }
905
- });
906
- this.writable = new WritableStream({
907
- write: (bytes) => {
908
- const text = _FuelSubscriptionStream.textDecoder.decode(bytes);
909
- if (text.startsWith("data:")) {
910
- const { data, errors } = JSON.parse(text.split("data:")[1]);
911
- if (Array.isArray(errors)) {
912
- this.readableStreamController.enqueue(
913
- new FuelError(
914
- FuelError.CODES.INVALID_REQUEST,
915
- errors.map((err) => err.message).join("\n\n")
916
- )
917
- );
918
- } else {
919
- this.readableStreamController.enqueue(data);
920
- }
921
- }
896
+ var _FuelGraphqlSubscriber = class {
897
+ constructor(options) {
898
+ this.options = options;
899
+ }
900
+ stream;
901
+ async setStream() {
902
+ const { url, query, variables, fetchFn } = this.options;
903
+ const response = await fetchFn(`${url}-sub`, {
904
+ method: "POST",
905
+ body: JSON.stringify({
906
+ query: print(query),
907
+ variables
908
+ }),
909
+ headers: {
910
+ "Content-Type": "application/json",
911
+ Accept: "text/event-stream"
922
912
  }
923
913
  });
914
+ this.stream = response.body.getReader();
924
915
  }
925
- };
926
- var FuelSubscriptionStream = _FuelSubscriptionStream;
927
- __publicField(FuelSubscriptionStream, "textDecoder", new TextDecoder());
928
- async function* fuelGraphQLSubscriber({
929
- url,
930
- variables,
931
- query,
932
- fetchFn
933
- }) {
934
- const response = await fetchFn(`${url}-sub`, {
935
- method: "POST",
936
- body: JSON.stringify({
937
- query: print(query),
938
- variables
939
- }),
940
- headers: {
941
- "Content-Type": "application/json",
942
- Accept: "text/event-stream"
943
- }
944
- });
945
- const subscriptionStreamReader = response.body.pipeThrough(new FuelSubscriptionStream()).getReader();
946
- while (true) {
947
- const { value, done } = await subscriptionStreamReader.read();
948
- if (value instanceof FuelError) {
949
- throw value;
916
+ async next() {
917
+ if (!this.stream) {
918
+ await this.setStream();
950
919
  }
951
- yield value;
952
- if (done) {
953
- break;
920
+ while (true) {
921
+ const { value, done } = await this.stream.read();
922
+ if (done) {
923
+ return { value, done };
924
+ }
925
+ const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
926
+ if (!text.startsWith("data:")) {
927
+ continue;
928
+ }
929
+ const { data, errors } = JSON.parse(text.split("data:")[1]);
930
+ if (Array.isArray(errors)) {
931
+ throw new FuelError(
932
+ FuelError.CODES.INVALID_REQUEST,
933
+ errors.map((err) => err.message).join("\n\n")
934
+ );
935
+ }
936
+ return { value: data, done: false };
954
937
  }
955
938
  }
956
- }
939
+ /**
940
+ * Gets called when `break` is called in a `for-await-of` loop.
941
+ */
942
+ async return() {
943
+ await this.stream.cancel();
944
+ this.stream.releaseLock();
945
+ return { done: true, value: void 0 };
946
+ }
947
+ [Symbol.asyncIterator]() {
948
+ return this;
949
+ }
950
+ };
951
+ var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
952
+ __publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
957
953
 
958
954
  // src/providers/memory-cache.ts
959
955
  import { ErrorCode, FuelError as FuelError2 } from "@fuel-ts/errors";
@@ -2059,8 +2055,6 @@ var BaseTransactionRequest = class {
2059
2055
  this.inputs.forEach((i) => {
2060
2056
  let correspondingInput;
2061
2057
  switch (i.type) {
2062
- case InputType2.Contract:
2063
- return;
2064
2058
  case InputType2.Coin:
2065
2059
  correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
2066
2060
  break;
@@ -2070,7 +2064,7 @@ var BaseTransactionRequest = class {
2070
2064
  );
2071
2065
  break;
2072
2066
  default:
2073
- break;
2067
+ return;
2074
2068
  }
2075
2069
  if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
2076
2070
  i.predicate = correspondingInput.predicate;
@@ -2591,6 +2585,7 @@ var fromTai64ToDate = (tai64Timestamp) => {
2591
2585
  var fromDateToTai64 = (date) => TAI64.fromUnix(Math.floor(date.getTime() / 1e3)).toString(10);
2592
2586
 
2593
2587
  // src/providers/transaction-summary/operations.ts
2588
+ import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
2594
2589
  import { ErrorCode as ErrorCode8, FuelError as FuelError9 } from "@fuel-ts/errors";
2595
2590
  import { bn as bn12 } from "@fuel-ts/math";
2596
2591
  import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
@@ -2735,7 +2730,6 @@ var OperationName = /* @__PURE__ */ ((OperationName2) => {
2735
2730
  OperationName2["contractCreated"] = "Contract created";
2736
2731
  OperationName2["transfer"] = "Transfer asset";
2737
2732
  OperationName2["contractCall"] = "Contract call";
2738
- OperationName2["contractTransfer"] = "Contract transfer";
2739
2733
  OperationName2["receive"] = "Receive asset";
2740
2734
  OperationName2["mint"] = "Mint asset";
2741
2735
  OperationName2["predicatecall"] = "Predicate call";
@@ -2835,33 +2829,6 @@ function addOperation(operations, toAdd) {
2835
2829
  function getReceiptsTransferOut(receipts) {
2836
2830
  return getReceiptsByType(receipts, ReceiptType3.TransferOut);
2837
2831
  }
2838
- function getContractTransferOperations({ receipts }) {
2839
- const transferOutReceipts = getReceiptsTransferOut(receipts);
2840
- const contractTransferOperations = transferOutReceipts.reduce(
2841
- (prevContractTransferOps, receipt) => {
2842
- const newContractTransferOps = addOperation(prevContractTransferOps, {
2843
- name: "Contract transfer" /* contractTransfer */,
2844
- from: {
2845
- type: 0 /* contract */,
2846
- address: receipt.from
2847
- },
2848
- to: {
2849
- type: 1 /* account */,
2850
- address: receipt.to
2851
- },
2852
- assetsSent: [
2853
- {
2854
- amount: receipt.amount,
2855
- assetId: receipt.assetId
2856
- }
2857
- ]
2858
- });
2859
- return newContractTransferOps;
2860
- },
2861
- []
2862
- );
2863
- return contractTransferOperations;
2864
- }
2865
2832
  function getWithdrawFromFuelOperations({
2866
2833
  inputs,
2867
2834
  receipts
@@ -2959,70 +2926,77 @@ function getContractCallOperations({
2959
2926
  }, []);
2960
2927
  return contractCallOperations;
2961
2928
  }
2929
+ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
2930
+ const { to: toAddress, assetId, amount } = receipt;
2931
+ let { from: fromAddress } = receipt;
2932
+ const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
2933
+ if (ZeroBytes328 === fromAddress) {
2934
+ const change = changeOutputs.find((output) => output.assetId === assetId);
2935
+ fromAddress = change?.to || fromAddress;
2936
+ }
2937
+ const fromType = contractInputs.some((input) => input.contractID === fromAddress) ? 0 /* contract */ : 1 /* account */;
2938
+ return {
2939
+ name: "Transfer asset" /* transfer */,
2940
+ from: {
2941
+ type: fromType,
2942
+ address: fromAddress
2943
+ },
2944
+ to: {
2945
+ type: toType,
2946
+ address: toAddress
2947
+ },
2948
+ assetsSent: [
2949
+ {
2950
+ assetId: assetId.toString(),
2951
+ amount
2952
+ }
2953
+ ]
2954
+ };
2955
+ }
2962
2956
  function getTransferOperations({
2963
2957
  inputs,
2964
2958
  outputs,
2965
2959
  receipts
2966
2960
  }) {
2961
+ let operations = [];
2967
2962
  const coinOutputs = getOutputsCoin(outputs);
2968
- const [transferReceipt] = getReceiptsByType(
2963
+ const contractInputs = getInputsContract(inputs);
2964
+ const changeOutputs = getOutputsChange(outputs);
2965
+ coinOutputs.forEach((output) => {
2966
+ const { amount, assetId, to } = output;
2967
+ const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
2968
+ if (changeOutput) {
2969
+ operations = addOperation(operations, {
2970
+ name: "Transfer asset" /* transfer */,
2971
+ from: {
2972
+ type: 1 /* account */,
2973
+ address: changeOutput.to
2974
+ },
2975
+ to: {
2976
+ type: 1 /* account */,
2977
+ address: to
2978
+ },
2979
+ assetsSent: [
2980
+ {
2981
+ assetId,
2982
+ amount
2983
+ }
2984
+ ]
2985
+ });
2986
+ }
2987
+ });
2988
+ const transferReceipts = getReceiptsByType(
2969
2989
  receipts,
2970
2990
  ReceiptType3.Transfer
2971
2991
  );
2972
- let operations = [];
2973
- if (transferReceipt) {
2974
- const changeOutputs = getOutputsChange(outputs);
2975
- changeOutputs.forEach((output) => {
2976
- const { assetId } = output;
2977
- const [contractInput] = getInputsContract(inputs);
2978
- const utxo = getInputFromAssetId(inputs, assetId);
2979
- if (utxo && contractInput) {
2980
- const inputAddress = getInputAccountAddress(utxo);
2981
- operations = addOperation(operations, {
2982
- name: "Transfer asset" /* transfer */,
2983
- from: {
2984
- type: 1 /* account */,
2985
- address: inputAddress
2986
- },
2987
- to: {
2988
- type: 0 /* contract */,
2989
- address: contractInput.contractID
2990
- },
2991
- assetsSent: [
2992
- {
2993
- assetId: assetId.toString(),
2994
- amount: transferReceipt.amount
2995
- }
2996
- ]
2997
- });
2998
- }
2999
- });
3000
- } else {
3001
- coinOutputs.forEach((output) => {
3002
- const input = getInputFromAssetId(inputs, output.assetId);
3003
- if (input) {
3004
- const inputAddress = getInputAccountAddress(input);
3005
- const operationToAdd = {
3006
- name: "Transfer asset" /* transfer */,
3007
- from: {
3008
- type: 1 /* account */,
3009
- address: inputAddress
3010
- },
3011
- to: {
3012
- type: 1 /* account */,
3013
- address: output.to.toString()
3014
- },
3015
- assetsSent: [
3016
- {
3017
- assetId: output.assetId.toString(),
3018
- amount: output.amount
3019
- }
3020
- ]
3021
- };
3022
- operations = addOperation(operations, operationToAdd);
3023
- }
3024
- });
3025
- }
2992
+ const transferOutReceipts = getReceiptsByType(
2993
+ receipts,
2994
+ ReceiptType3.TransferOut
2995
+ );
2996
+ [...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
2997
+ const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
2998
+ operations = addOperation(operations, operation);
2999
+ });
3026
3000
  return operations;
3027
3001
  }
3028
3002
  function getPayProducerOperations(outputs) {
@@ -3095,7 +3069,6 @@ function getOperations({
3095
3069
  rawPayload,
3096
3070
  maxInputs
3097
3071
  }),
3098
- ...getContractTransferOperations({ receipts }),
3099
3072
  ...getWithdrawFromFuelOperations({ inputs, receipts })
3100
3073
  ];
3101
3074
  }
@@ -3668,7 +3641,7 @@ var _Provider = class {
3668
3641
  const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
3669
3642
  const isSubscription = opDefinition?.operation === "subscription";
3670
3643
  if (isSubscription) {
3671
- return fuelGraphQLSubscriber({
3644
+ return new FuelGraphqlSubscriber({
3672
3645
  url: this.url,
3673
3646
  query,
3674
3647
  fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
@@ -3860,11 +3833,15 @@ var _Provider = class {
3860
3833
  async estimateTxDependencies(transactionRequest) {
3861
3834
  if (transactionRequest.type === TransactionType8.Create) {
3862
3835
  return {
3863
- receipts: []
3836
+ receipts: [],
3837
+ outputVariables: 0,
3838
+ missingContractIds: []
3864
3839
  };
3865
3840
  }
3866
3841
  await this.estimatePredicates(transactionRequest);
3867
3842
  let receipts = [];
3843
+ const missingContractIds = [];
3844
+ let outputVariables = 0;
3868
3845
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3869
3846
  const { dryRun: gqlReceipts } = await this.operations.dryRun({
3870
3847
  encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
@@ -3874,16 +3851,20 @@ var _Provider = class {
3874
3851
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3875
3852
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3876
3853
  if (hasMissingOutputs) {
3854
+ outputVariables += missingOutputVariables.length;
3877
3855
  transactionRequest.addVariableOutputs(missingOutputVariables.length);
3878
3856
  missingOutputContractIds.forEach(({ contractId }) => {
3879
3857
  transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
3858
+ missingContractIds.push(contractId);
3880
3859
  });
3881
3860
  } else {
3882
3861
  break;
3883
3862
  }
3884
3863
  }
3885
3864
  return {
3886
- receipts
3865
+ receipts,
3866
+ outputVariables,
3867
+ missingContractIds
3887
3868
  };
3888
3869
  }
3889
3870
  /**
@@ -3951,11 +3932,15 @@ var _Provider = class {
3951
3932
  const minGas = txRequestClone.calculateMinGas(chainInfo);
3952
3933
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3953
3934
  let receipts = [];
3935
+ let missingContractIds = [];
3936
+ let outputVariables = 0;
3954
3937
  if (isScriptTransaction && estimateTxDependencies) {
3955
3938
  txRequestClone.gasPrice = bn14(0);
3956
3939
  txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
3957
3940
  const result = await this.estimateTxDependencies(txRequestClone);
3958
3941
  receipts = result.receipts;
3942
+ outputVariables = result.outputVariables;
3943
+ missingContractIds = result.missingContractIds;
3959
3944
  }
3960
3945
  const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3961
3946
  const usedFee = calculatePriceWithFactor(
@@ -3977,7 +3962,8 @@ var _Provider = class {
3977
3962
  minFee,
3978
3963
  maxFee,
3979
3964
  estimatedInputs: txRequestClone.inputs,
3980
- estimatedOutputs: txRequestClone.outputs
3965
+ outputVariables,
3966
+ missingContractIds
3981
3967
  };
3982
3968
  }
3983
3969
  async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
@@ -8752,17 +8738,6 @@ var FuelConnectorEventTypes = /* @__PURE__ */ ((FuelConnectorEventTypes2) => {
8752
8738
  })(FuelConnectorEventTypes || {});
8753
8739
  var FuelConnectorEventType = "FuelConnector";
8754
8740
 
8755
- // src/connectors/types/data-type.ts
8756
- var MessageTypes = /* @__PURE__ */ ((MessageTypes2) => {
8757
- MessageTypes2["ping"] = "ping";
8758
- MessageTypes2["uiEvent"] = "uiEvent";
8759
- MessageTypes2["event"] = "event";
8760
- MessageTypes2["request"] = "request";
8761
- MessageTypes2["response"] = "response";
8762
- MessageTypes2["removeConnection"] = "removeConnection";
8763
- return MessageTypes2;
8764
- })(MessageTypes || {});
8765
-
8766
8741
  // src/connectors/types/local-storage.ts
8767
8742
  var LocalStorage = class {
8768
8743
  storage;
@@ -9399,7 +9374,6 @@ export {
9399
9374
  LocalStorage,
9400
9375
  MNEMONIC_SIZES,
9401
9376
  MemoryStorage,
9402
- MessageTypes,
9403
9377
  mnemonic_default as Mnemonic,
9404
9378
  MnemonicVault,
9405
9379
  NoWitnessAtIndexError,
@@ -9448,7 +9422,6 @@ export {
9448
9422
  getAssetWithNetwork,
9449
9423
  getContractCallOperations,
9450
9424
  getContractCreatedOperations,
9451
- getContractTransferOperations,
9452
9425
  getDecodedLogs,
9453
9426
  getDefaultChainId,
9454
9427
  getGasUsedFromReceipts,