@fuel-ts/account 0.74.0 → 0.76.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.
- package/dist/account.d.ts +4 -5
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +2 -1
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/connectors/fuel.d.ts +1 -2
- package/dist/connectors/fuel.d.ts.map +1 -1
- package/dist/connectors/types/data-type.d.ts +0 -8
- package/dist/connectors/types/data-type.d.ts.map +1 -1
- package/dist/connectors/types/events.d.ts +2 -36
- package/dist/connectors/types/events.d.ts.map +1 -1
- package/dist/connectors/types/index.d.ts +0 -2
- package/dist/connectors/types/index.d.ts.map +1 -1
- package/dist/hdwallet/hdwallet.d.ts +1 -1
- package/dist/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.global.js +1554 -2272
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +576 -451
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +495 -385
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts +1 -1
- package/dist/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/mnemonic/utils.d.ts +1 -1
- package/dist/mnemonic/utils.d.ts.map +1 -1
- package/dist/predicate/utils/getPredicateRoot.d.ts +1 -1
- package/dist/predicate/utils/getPredicateRoot.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +38 -38
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/assets/index.d.ts +4 -0
- package/dist/providers/assets/index.d.ts.map +1 -0
- package/dist/providers/assets/types.d.ts +36 -0
- package/dist/providers/assets/types.d.ts.map +1 -0
- package/dist/providers/assets/utils/index.d.ts +4 -0
- package/dist/providers/assets/utils/index.d.ts.map +1 -0
- package/dist/providers/assets/utils/network.d.ts +33 -0
- package/dist/providers/assets/utils/network.d.ts.map +1 -0
- package/dist/providers/assets/utils/resolveIconPaths.d.ts +14 -0
- package/dist/providers/assets/utils/resolveIconPaths.d.ts.map +1 -0
- package/dist/providers/assets/utils/url.d.ts +2 -0
- package/dist/providers/assets/utils/url.d.ts.map +1 -0
- package/dist/providers/chains.d.ts +11 -0
- package/dist/providers/chains.d.ts.map +1 -0
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts +13 -3
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/memory-cache.d.ts +1 -1
- package/dist/providers/memory-cache.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -2
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +18 -8
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/resource.d.ts +1 -1
- package/dist/providers/resource.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/hash-transaction.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +1 -1
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/output.d.ts +1 -1
- package/dist/providers/transaction-request/output.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -2
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/storage-slot.d.ts +1 -1
- package/dist/providers/transaction-request/storage-slot.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +2 -10
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/witness.d.ts +1 -1
- package/dist/providers/transaction-request/witness.d.ts.map +1 -1
- package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/index.d.ts +0 -1
- package/dist/providers/transaction-summary/index.d.ts.map +1 -1
- package/dist/providers/transaction-summary/operations.d.ts +0 -2
- package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
- package/dist/providers/transaction-summary/output.d.ts +2 -2
- package/dist/providers/transaction-summary/output.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +0 -1
- package/dist/providers/transaction-summary/types.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/signer/signer.d.ts +1 -1
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +4098 -4882
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +466 -416
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +390 -352
- package/dist/test-utils.mjs.map +1 -1
- package/dist/utils/formatTransferToContractScriptData.d.ts +1 -2
- package/dist/utils/formatTransferToContractScriptData.d.ts.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +4 -4
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/dist/wallet/wallet.d.ts +1 -2
- package/dist/wallet/wallet.d.ts.map +1 -1
- package/dist/wallet/wallets.d.ts +1 -1
- package/dist/wallet/wallets.d.ts.map +1 -1
- package/package.json +16 -16
- package/dist/connectors/types/asset.d.ts +0 -2
- package/dist/connectors/types/asset.d.ts.map +0 -1
- package/dist/connectors/types/constants.d.ts +0 -7
- package/dist/connectors/types/constants.d.ts.map +0 -1
- package/dist/connectors/types/message.d.ts +0 -15
- package/dist/connectors/types/message.d.ts.map +0 -1
- package/dist/providers/transaction-summary/date.d.ts +0 -3
- package/dist/providers/transaction-summary/date.d.ts.map +0 -1
- package/dist/providers/utils/time.d.ts +0 -40
- package/dist/providers/utils/time.d.ts.map +0 -1
package/dist/test-utils.js
CHANGED
@@ -58,19 +58,20 @@ module.exports = __toCommonJS(test_utils_exports);
|
|
58
58
|
|
59
59
|
// src/wallet/base-wallet-unlocked.ts
|
60
60
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
+
var import_utils30 = require("@fuel-ts/utils");
|
61
62
|
|
62
63
|
// src/account.ts
|
63
64
|
var import_address4 = require("@fuel-ts/address");
|
64
|
-
var
|
65
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
65
66
|
var import_errors15 = require("@fuel-ts/errors");
|
66
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
67
68
|
var import_math17 = require("@fuel-ts/math");
|
68
|
-
var
|
69
|
+
var import_utils27 = require("@fuel-ts/utils");
|
69
70
|
|
70
71
|
// src/providers/coin-quantity.ts
|
71
72
|
var import_configs = require("@fuel-ts/address/configs");
|
72
73
|
var import_math = require("@fuel-ts/math");
|
73
|
-
var
|
74
|
+
var import_utils = require("@fuel-ts/utils");
|
74
75
|
var coinQuantityfy = (coinQuantityLike) => {
|
75
76
|
let assetId;
|
76
77
|
let amount;
|
@@ -86,7 +87,7 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
86
87
|
}
|
87
88
|
const bnAmount = (0, import_math.bn)(amount);
|
88
89
|
return {
|
89
|
-
assetId: (0,
|
90
|
+
assetId: (0, import_utils.hexlify)(assetId),
|
90
91
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
91
92
|
max: max2 ? (0, import_math.bn)(max2) : void 0
|
92
93
|
};
|
@@ -108,8 +109,10 @@ var import_address3 = require("@fuel-ts/address");
|
|
108
109
|
var import_errors13 = require("@fuel-ts/errors");
|
109
110
|
var import_math14 = require("@fuel-ts/math");
|
110
111
|
var import_transactions17 = require("@fuel-ts/transactions");
|
112
|
+
var import_utils22 = require("@fuel-ts/utils");
|
111
113
|
var import_versions = require("@fuel-ts/versions");
|
112
|
-
var
|
114
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
115
|
+
var import_ethers2 = require("ethers");
|
113
116
|
var import_graphql_request = require("graphql-request");
|
114
117
|
var import_ramda3 = require("ramda");
|
115
118
|
|
@@ -918,71 +921,67 @@ function getSdk(requester) {
|
|
918
921
|
// src/providers/fuel-graphql-subscriber.ts
|
919
922
|
var import_errors = require("@fuel-ts/errors");
|
920
923
|
var import_graphql = require("graphql");
|
921
|
-
var
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
this.readableStreamController.enqueue(
|
938
|
-
new import_errors.FuelError(
|
939
|
-
import_errors.FuelError.CODES.INVALID_REQUEST,
|
940
|
-
errors.map((err) => err.message).join("\n\n")
|
941
|
-
)
|
942
|
-
);
|
943
|
-
} else {
|
944
|
-
this.readableStreamController.enqueue(data);
|
945
|
-
}
|
946
|
-
}
|
924
|
+
var _FuelGraphqlSubscriber = class {
|
925
|
+
constructor(options) {
|
926
|
+
this.options = options;
|
927
|
+
}
|
928
|
+
stream;
|
929
|
+
async setStream() {
|
930
|
+
const { url, query, variables, fetchFn } = this.options;
|
931
|
+
const response = await fetchFn(`${url}-sub`, {
|
932
|
+
method: "POST",
|
933
|
+
body: JSON.stringify({
|
934
|
+
query: (0, import_graphql.print)(query),
|
935
|
+
variables
|
936
|
+
}),
|
937
|
+
headers: {
|
938
|
+
"Content-Type": "application/json",
|
939
|
+
Accept: "text/event-stream"
|
947
940
|
}
|
948
941
|
});
|
942
|
+
this.stream = response.body.getReader();
|
949
943
|
}
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
async function* fuelGraphQLSubscriber({
|
954
|
-
url,
|
955
|
-
variables,
|
956
|
-
query,
|
957
|
-
fetchFn
|
958
|
-
}) {
|
959
|
-
const response = await fetchFn(`${url}-sub`, {
|
960
|
-
method: "POST",
|
961
|
-
body: JSON.stringify({
|
962
|
-
query: (0, import_graphql.print)(query),
|
963
|
-
variables
|
964
|
-
}),
|
965
|
-
headers: {
|
966
|
-
"Content-Type": "application/json",
|
967
|
-
Accept: "text/event-stream"
|
944
|
+
async next() {
|
945
|
+
if (!this.stream) {
|
946
|
+
await this.setStream();
|
968
947
|
}
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
948
|
+
while (true) {
|
949
|
+
const { value, done } = await this.stream.read();
|
950
|
+
if (done) {
|
951
|
+
return { value, done };
|
952
|
+
}
|
953
|
+
const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
|
954
|
+
if (!text.startsWith("data:")) {
|
955
|
+
continue;
|
956
|
+
}
|
957
|
+
const { data, errors } = JSON.parse(text.split("data:")[1]);
|
958
|
+
if (Array.isArray(errors)) {
|
959
|
+
throw new import_errors.FuelError(
|
960
|
+
import_errors.FuelError.CODES.INVALID_REQUEST,
|
961
|
+
errors.map((err) => err.message).join("\n\n")
|
962
|
+
);
|
963
|
+
}
|
964
|
+
return { value: data, done: false };
|
979
965
|
}
|
980
966
|
}
|
981
|
-
|
967
|
+
/**
|
968
|
+
* Gets called when `break` is called in a `for-await-of` loop.
|
969
|
+
*/
|
970
|
+
async return() {
|
971
|
+
await this.stream.cancel();
|
972
|
+
this.stream.releaseLock();
|
973
|
+
return { done: true, value: void 0 };
|
974
|
+
}
|
975
|
+
[Symbol.asyncIterator]() {
|
976
|
+
return this;
|
977
|
+
}
|
978
|
+
};
|
979
|
+
var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
980
|
+
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
982
981
|
|
983
982
|
// src/providers/memory-cache.ts
|
984
983
|
var import_errors2 = require("@fuel-ts/errors");
|
985
|
-
var
|
984
|
+
var import_utils2 = require("@fuel-ts/utils");
|
986
985
|
var cache = {};
|
987
986
|
var DEFAULT_TTL_IN_MS = 30 * 1e3;
|
988
987
|
var MemoryCache = class {
|
@@ -997,7 +996,7 @@ var MemoryCache = class {
|
|
997
996
|
}
|
998
997
|
}
|
999
998
|
get(value, isAutoExpiring = true) {
|
1000
|
-
const key = (0,
|
999
|
+
const key = (0, import_utils2.hexlify)(value);
|
1001
1000
|
if (cache[key]) {
|
1002
1001
|
if (!isAutoExpiring || cache[key].expires > Date.now()) {
|
1003
1002
|
return cache[key].value;
|
@@ -1008,7 +1007,7 @@ var MemoryCache = class {
|
|
1008
1007
|
}
|
1009
1008
|
set(value) {
|
1010
1009
|
const expiresAt = Date.now() + this.ttl;
|
1011
|
-
const key = (0,
|
1010
|
+
const key = (0, import_utils2.hexlify)(value);
|
1012
1011
|
cache[key] = {
|
1013
1012
|
expires: expiresAt,
|
1014
1013
|
value
|
@@ -1034,7 +1033,7 @@ var MemoryCache = class {
|
|
1034
1033
|
}, []);
|
1035
1034
|
}
|
1036
1035
|
del(value) {
|
1037
|
-
const key = (0,
|
1036
|
+
const key = (0, import_utils2.hexlify)(value);
|
1038
1037
|
delete cache[key];
|
1039
1038
|
}
|
1040
1039
|
};
|
@@ -1044,31 +1043,31 @@ var import_configs2 = require("@fuel-ts/address/configs");
|
|
1044
1043
|
var import_errors3 = require("@fuel-ts/errors");
|
1045
1044
|
var import_math2 = require("@fuel-ts/math");
|
1046
1045
|
var import_transactions = require("@fuel-ts/transactions");
|
1047
|
-
var
|
1046
|
+
var import_utils3 = require("@fuel-ts/utils");
|
1048
1047
|
var inputify = (value) => {
|
1049
1048
|
const { type } = value;
|
1050
1049
|
switch (value.type) {
|
1051
1050
|
case import_transactions.InputType.Coin: {
|
1052
|
-
const predicate = (0,
|
1053
|
-
const predicateData = (0,
|
1051
|
+
const predicate = (0, import_utils3.arrayify)(value.predicate ?? "0x");
|
1052
|
+
const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
|
1054
1053
|
return {
|
1055
1054
|
type: import_transactions.InputType.Coin,
|
1056
|
-
txID: (0,
|
1057
|
-
outputIndex: (0,
|
1058
|
-
owner: (0,
|
1055
|
+
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1056
|
+
outputIndex: (0, import_utils3.arrayify)(value.id)[32],
|
1057
|
+
owner: (0, import_utils3.hexlify)(value.owner),
|
1059
1058
|
amount: (0, import_math2.bn)(value.amount),
|
1060
|
-
assetId: (0,
|
1059
|
+
assetId: (0, import_utils3.hexlify)(value.assetId),
|
1061
1060
|
txPointer: {
|
1062
|
-
blockHeight: (0, import_math2.toNumber)((0,
|
1063
|
-
txIndex: (0, import_math2.toNumber)((0,
|
1061
|
+
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1062
|
+
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1064
1063
|
},
|
1065
1064
|
witnessIndex: value.witnessIndex,
|
1066
1065
|
maturity: value.maturity ?? 0,
|
1067
1066
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1068
1067
|
predicateLength: predicate.length,
|
1069
1068
|
predicateDataLength: predicateData.length,
|
1070
|
-
predicate: (0,
|
1071
|
-
predicateData: (0,
|
1069
|
+
predicate: (0, import_utils3.hexlify)(predicate),
|
1070
|
+
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1072
1071
|
};
|
1073
1072
|
}
|
1074
1073
|
case import_transactions.InputType.Contract: {
|
@@ -1079,29 +1078,29 @@ var inputify = (value) => {
|
|
1079
1078
|
balanceRoot: import_configs2.ZeroBytes32,
|
1080
1079
|
stateRoot: import_configs2.ZeroBytes32,
|
1081
1080
|
txPointer: {
|
1082
|
-
blockHeight: (0, import_math2.toNumber)((0,
|
1083
|
-
txIndex: (0, import_math2.toNumber)((0,
|
1081
|
+
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1082
|
+
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1084
1083
|
},
|
1085
|
-
contractID: (0,
|
1084
|
+
contractID: (0, import_utils3.hexlify)(value.contractId)
|
1086
1085
|
};
|
1087
1086
|
}
|
1088
1087
|
case import_transactions.InputType.Message: {
|
1089
|
-
const predicate = (0,
|
1090
|
-
const predicateData = (0,
|
1091
|
-
const data = (0,
|
1088
|
+
const predicate = (0, import_utils3.arrayify)(value.predicate ?? "0x");
|
1089
|
+
const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
|
1090
|
+
const data = (0, import_utils3.arrayify)(value.data ?? "0x");
|
1092
1091
|
return {
|
1093
1092
|
type: import_transactions.InputType.Message,
|
1094
|
-
sender: (0,
|
1095
|
-
recipient: (0,
|
1093
|
+
sender: (0, import_utils3.hexlify)(value.sender),
|
1094
|
+
recipient: (0, import_utils3.hexlify)(value.recipient),
|
1096
1095
|
amount: (0, import_math2.bn)(value.amount),
|
1097
|
-
nonce: (0,
|
1096
|
+
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1098
1097
|
witnessIndex: value.witnessIndex,
|
1099
1098
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1100
1099
|
predicateLength: predicate.length,
|
1101
1100
|
predicateDataLength: predicateData.length,
|
1102
|
-
predicate: (0,
|
1103
|
-
predicateData: (0,
|
1104
|
-
data: (0,
|
1101
|
+
predicate: (0, import_utils3.hexlify)(predicate),
|
1102
|
+
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1103
|
+
data: (0, import_utils3.hexlify)(data),
|
1105
1104
|
dataLength: data.length
|
1106
1105
|
};
|
1107
1106
|
}
|
@@ -1119,16 +1118,16 @@ var import_configs3 = require("@fuel-ts/address/configs");
|
|
1119
1118
|
var import_errors4 = require("@fuel-ts/errors");
|
1120
1119
|
var import_math3 = require("@fuel-ts/math");
|
1121
1120
|
var import_transactions2 = require("@fuel-ts/transactions");
|
1122
|
-
var
|
1121
|
+
var import_utils4 = require("@fuel-ts/utils");
|
1123
1122
|
var outputify = (value) => {
|
1124
1123
|
const { type } = value;
|
1125
1124
|
switch (type) {
|
1126
1125
|
case import_transactions2.OutputType.Coin: {
|
1127
1126
|
return {
|
1128
1127
|
type: import_transactions2.OutputType.Coin,
|
1129
|
-
to: (0,
|
1128
|
+
to: (0, import_utils4.hexlify)(value.to),
|
1130
1129
|
amount: (0, import_math3.bn)(value.amount),
|
1131
|
-
assetId: (0,
|
1130
|
+
assetId: (0, import_utils4.hexlify)(value.assetId)
|
1132
1131
|
};
|
1133
1132
|
}
|
1134
1133
|
case import_transactions2.OutputType.Contract: {
|
@@ -1142,9 +1141,9 @@ var outputify = (value) => {
|
|
1142
1141
|
case import_transactions2.OutputType.Change: {
|
1143
1142
|
return {
|
1144
1143
|
type: import_transactions2.OutputType.Change,
|
1145
|
-
to: (0,
|
1144
|
+
to: (0, import_utils4.hexlify)(value.to),
|
1146
1145
|
amount: (0, import_math3.bn)(0),
|
1147
|
-
assetId: (0,
|
1146
|
+
assetId: (0, import_utils4.hexlify)(value.assetId)
|
1148
1147
|
};
|
1149
1148
|
}
|
1150
1149
|
case import_transactions2.OutputType.Variable: {
|
@@ -1158,8 +1157,8 @@ var outputify = (value) => {
|
|
1158
1157
|
case import_transactions2.OutputType.ContractCreated: {
|
1159
1158
|
return {
|
1160
1159
|
type: import_transactions2.OutputType.ContractCreated,
|
1161
|
-
contractId: (0,
|
1162
|
-
stateRoot: (0,
|
1160
|
+
contractId: (0, import_utils4.hexlify)(value.contractId),
|
1161
|
+
stateRoot: (0, import_utils4.hexlify)(value.stateRoot)
|
1163
1162
|
};
|
1164
1163
|
}
|
1165
1164
|
default: {
|
@@ -1176,7 +1175,7 @@ var import_address = require("@fuel-ts/address");
|
|
1176
1175
|
var import_configs6 = require("@fuel-ts/address/configs");
|
1177
1176
|
var import_math6 = require("@fuel-ts/math");
|
1178
1177
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1179
|
-
var
|
1178
|
+
var import_utils9 = require("@fuel-ts/utils");
|
1180
1179
|
|
1181
1180
|
// src/providers/resource.ts
|
1182
1181
|
var isCoin = (resource) => "id" in resource;
|
@@ -1187,7 +1186,7 @@ var import_errors5 = require("@fuel-ts/errors");
|
|
1187
1186
|
var import_math4 = require("@fuel-ts/math");
|
1188
1187
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1189
1188
|
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1190
|
-
var
|
1189
|
+
var import_utils5 = require("@fuel-ts/utils");
|
1191
1190
|
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1192
1191
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1193
1192
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
@@ -1331,7 +1330,7 @@ function assembleReceiptByType(receipt) {
|
|
1331
1330
|
const recipient = hexOrZero(receipt.recipient);
|
1332
1331
|
const nonce = hexOrZero(receipt.nonce);
|
1333
1332
|
const amount = (0, import_math4.bn)(receipt.amount);
|
1334
|
-
const data = receipt.data ? (0,
|
1333
|
+
const data = receipt.data ? (0, import_utils5.arrayify)(receipt.data) : Uint8Array.from([]);
|
1335
1334
|
const digest = hexOrZero(receipt.digest);
|
1336
1335
|
const messageId = import_transactions3.ReceiptMessageOutCoder.getMessageId({
|
1337
1336
|
sender,
|
@@ -1393,7 +1392,7 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1393
1392
|
// src/providers/utils/gas.ts
|
1394
1393
|
var import_math5 = require("@fuel-ts/math");
|
1395
1394
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1396
|
-
var
|
1395
|
+
var import_utils6 = require("@fuel-ts/utils");
|
1397
1396
|
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1398
1397
|
var getGasUsedFromReceipts = (receipts) => {
|
1399
1398
|
const scriptResult = receipts.filter(
|
@@ -1418,9 +1417,7 @@ function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
|
1418
1417
|
const totalGas = inputs.reduce((total, input) => {
|
1419
1418
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1420
1419
|
return total.add(
|
1421
|
-
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(
|
1422
|
-
resolveGasDependentCosts((0, import_ethers6.getBytesCopy)(input.predicate).length, gasCosts.contractRoot)
|
1423
|
-
).add((0, import_math5.bn)(input.predicateGasUsed))
|
1420
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1424
1421
|
);
|
1425
1422
|
}
|
1426
1423
|
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
@@ -1469,13 +1466,13 @@ function calculateMetadataGasForTxScript({
|
|
1469
1466
|
}
|
1470
1467
|
|
1471
1468
|
// src/providers/utils/json.ts
|
1472
|
-
var
|
1469
|
+
var import_utils7 = require("@fuel-ts/utils");
|
1473
1470
|
var import_ramda = require("ramda");
|
1474
1471
|
function normalize(object) {
|
1475
1472
|
Object.keys(object).forEach((key) => {
|
1476
1473
|
switch (object[key]?.constructor.name) {
|
1477
1474
|
case "Uint8Array":
|
1478
|
-
object[key] = (0,
|
1475
|
+
object[key] = (0, import_utils7.hexlify)(object[key]);
|
1479
1476
|
break;
|
1480
1477
|
case "Array":
|
1481
1478
|
object[key] = normalize(object[key]);
|
@@ -1508,9 +1505,6 @@ function sleep(time) {
|
|
1508
1505
|
});
|
1509
1506
|
}
|
1510
1507
|
|
1511
|
-
// src/providers/utils/time.ts
|
1512
|
-
var fromUnixToTai64 = (unixTimestampMs) => (BigInt(unixTimestampMs) + BigInt(2 ** 62) + BigInt(10)).toString();
|
1513
|
-
|
1514
1508
|
// src/providers/transaction-request/errors.ts
|
1515
1509
|
var NoWitnessAtIndexError = class extends Error {
|
1516
1510
|
constructor(index) {
|
@@ -1522,11 +1516,11 @@ var NoWitnessAtIndexError = class extends Error {
|
|
1522
1516
|
};
|
1523
1517
|
|
1524
1518
|
// src/providers/transaction-request/witness.ts
|
1525
|
-
var
|
1519
|
+
var import_utils8 = require("@fuel-ts/utils");
|
1526
1520
|
var witnessify = (value) => {
|
1527
|
-
const data = (0,
|
1521
|
+
const data = (0, import_utils8.arrayify)(value);
|
1528
1522
|
return {
|
1529
|
-
data: (0,
|
1523
|
+
data: (0, import_utils8.hexlify)(data),
|
1530
1524
|
dataLength: data.length
|
1531
1525
|
};
|
1532
1526
|
};
|
@@ -1646,7 +1640,7 @@ var BaseTransactionRequest = class {
|
|
1646
1640
|
* Creates an empty witness without any side effects and returns the index
|
1647
1641
|
*/
|
1648
1642
|
createWitness() {
|
1649
|
-
this.witnesses.push((0,
|
1643
|
+
this.witnesses.push((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
1650
1644
|
return this.witnesses.length - 1;
|
1651
1645
|
}
|
1652
1646
|
/**
|
@@ -1715,9 +1709,9 @@ var BaseTransactionRequest = class {
|
|
1715
1709
|
const found = this.inputs.find((input) => {
|
1716
1710
|
switch (input.type) {
|
1717
1711
|
case import_transactions5.InputType.Coin:
|
1718
|
-
return (0,
|
1712
|
+
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
1719
1713
|
case import_transactions5.InputType.Message:
|
1720
|
-
return (0,
|
1714
|
+
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
1721
1715
|
default:
|
1722
1716
|
return false;
|
1723
1717
|
}
|
@@ -1883,7 +1877,7 @@ var BaseTransactionRequest = class {
|
|
1883
1877
|
*/
|
1884
1878
|
addChangeOutput(to, assetId = import_configs6.BaseAssetId) {
|
1885
1879
|
const changeOutput = this.getChangeOutputs().find(
|
1886
|
-
(output) => (0,
|
1880
|
+
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
1887
1881
|
);
|
1888
1882
|
if (!changeOutput) {
|
1889
1883
|
this.pushOutput({
|
@@ -1996,19 +1990,27 @@ var BaseTransactionRequest = class {
|
|
1996
1990
|
toJSON() {
|
1997
1991
|
return normalizeJSON(this);
|
1998
1992
|
}
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
1993
|
+
updatePredicateInputs(inputs) {
|
1994
|
+
this.inputs.forEach((i) => {
|
1995
|
+
let correspondingInput;
|
1996
|
+
switch (i.type) {
|
1997
|
+
case import_transactions5.InputType.Coin:
|
1998
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions5.InputType.Coin && x.owner === i.owner);
|
1999
|
+
break;
|
2000
|
+
case import_transactions5.InputType.Message:
|
2001
|
+
correspondingInput = inputs.find(
|
2002
|
+
(x) => x.type === import_transactions5.InputType.Message && x.sender === i.sender
|
2003
|
+
);
|
2004
|
+
break;
|
2005
|
+
default:
|
2006
|
+
return;
|
2007
|
+
}
|
2008
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math6.bn)(correspondingInput.predicateGasUsed).gt(0)) {
|
2009
|
+
i.predicate = correspondingInput.predicate;
|
2010
|
+
i.predicateData = correspondingInput.predicateData;
|
2011
|
+
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
2012
|
+
}
|
2013
|
+
});
|
2012
2014
|
}
|
2013
2015
|
};
|
2014
2016
|
|
@@ -2016,14 +2018,15 @@ var BaseTransactionRequest = class {
|
|
2016
2018
|
var import_configs8 = require("@fuel-ts/address/configs");
|
2017
2019
|
var import_math8 = require("@fuel-ts/math");
|
2018
2020
|
var import_transactions7 = require("@fuel-ts/transactions");
|
2019
|
-
var
|
2021
|
+
var import_utils13 = require("@fuel-ts/utils");
|
2020
2022
|
|
2021
2023
|
// src/providers/transaction-request/hash-transaction.ts
|
2022
2024
|
var import_configs7 = require("@fuel-ts/address/configs");
|
2023
2025
|
var import_hasher = require("@fuel-ts/hasher");
|
2024
2026
|
var import_math7 = require("@fuel-ts/math");
|
2025
2027
|
var import_transactions6 = require("@fuel-ts/transactions");
|
2026
|
-
var
|
2028
|
+
var import_utils11 = require("@fuel-ts/utils");
|
2029
|
+
var import_ethers = require("ethers");
|
2027
2030
|
var import_ramda2 = require("ramda");
|
2028
2031
|
function hashTransaction(transactionRequest, chainId) {
|
2029
2032
|
const transaction = transactionRequest.toTransaction();
|
@@ -2085,15 +2088,15 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2085
2088
|
transaction.witnessesCount = 0;
|
2086
2089
|
transaction.witnesses = [];
|
2087
2090
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2088
|
-
const concatenatedData = (0,
|
2089
|
-
return (0,
|
2091
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions6.TransactionCoder().encode(transaction)]);
|
2092
|
+
return (0, import_ethers.sha256)(concatenatedData);
|
2090
2093
|
}
|
2091
2094
|
|
2092
2095
|
// src/providers/transaction-request/storage-slot.ts
|
2093
|
-
var
|
2096
|
+
var import_utils12 = require("@fuel-ts/utils");
|
2094
2097
|
var getStorageValue = (value) => {
|
2095
2098
|
const v = new Uint8Array(32);
|
2096
|
-
v.set((0,
|
2099
|
+
v.set((0, import_utils12.arrayify)(value));
|
2097
2100
|
return v;
|
2098
2101
|
};
|
2099
2102
|
var storageSlotify = (storageSlot) => {
|
@@ -2107,8 +2110,8 @@ var storageSlotify = (storageSlot) => {
|
|
2107
2110
|
value = storageSlot.value;
|
2108
2111
|
}
|
2109
2112
|
return {
|
2110
|
-
key: (0,
|
2111
|
-
value: (0,
|
2113
|
+
key: (0, import_utils12.hexlify)(key),
|
2114
|
+
value: (0, import_utils12.hexlify)(getStorageValue(value))
|
2112
2115
|
};
|
2113
2116
|
};
|
2114
2117
|
|
@@ -2141,7 +2144,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2141
2144
|
} = {}) {
|
2142
2145
|
super(rest);
|
2143
2146
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2144
|
-
this.salt = (0,
|
2147
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2145
2148
|
this.storageSlots = [...storageSlots ?? []];
|
2146
2149
|
}
|
2147
2150
|
/**
|
@@ -2159,7 +2162,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2159
2162
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2160
2163
|
bytecodeWitnessIndex,
|
2161
2164
|
storageSlotsCount: storageSlots.length,
|
2162
|
-
salt: this.salt ? (0,
|
2165
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2163
2166
|
storageSlots
|
2164
2167
|
};
|
2165
2168
|
}
|
@@ -2198,7 +2201,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2198
2201
|
}
|
2199
2202
|
metadataGas(gasCosts) {
|
2200
2203
|
return calculateMetadataGasForTxCreate({
|
2201
|
-
contractBytesSize: (0, import_math8.bn)((0,
|
2204
|
+
contractBytesSize: (0, import_math8.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2202
2205
|
gasCosts,
|
2203
2206
|
stateRootSize: this.storageSlots.length,
|
2204
2207
|
txBytesSize: this.byteSize()
|
@@ -2212,17 +2215,17 @@ var import_address2 = require("@fuel-ts/address");
|
|
2212
2215
|
var import_configs9 = require("@fuel-ts/address/configs");
|
2213
2216
|
var import_math9 = require("@fuel-ts/math");
|
2214
2217
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2215
|
-
var
|
2218
|
+
var import_utils15 = require("@fuel-ts/utils");
|
2216
2219
|
|
2217
2220
|
// src/providers/transaction-request/scripts.ts
|
2218
|
-
var
|
2221
|
+
var import_utils14 = require("@fuel-ts/utils");
|
2219
2222
|
var returnZeroScript = {
|
2220
2223
|
/*
|
2221
2224
|
Opcode::RET(REG_ZERO)
|
2222
2225
|
Opcode::NOOP
|
2223
2226
|
*/
|
2224
2227
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
2225
|
-
bytes: (0,
|
2228
|
+
bytes: (0, import_utils14.arrayify)("0x24000000"),
|
2226
2229
|
encodeScriptData: () => new Uint8Array(0)
|
2227
2230
|
};
|
2228
2231
|
var withdrawScript = {
|
@@ -2236,7 +2239,7 @@ var withdrawScript = {
|
|
2236
2239
|
00000000 00000000 [amount value]
|
2237
2240
|
*/
|
2238
2241
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
2239
|
-
bytes: (0,
|
2242
|
+
bytes: (0, import_utils14.arrayify)("0x5040C0105D44C0064C40001124000000"),
|
2240
2243
|
encodeScriptData: () => new Uint8Array(0)
|
2241
2244
|
};
|
2242
2245
|
|
@@ -2264,8 +2267,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2264
2267
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2265
2268
|
super(rest);
|
2266
2269
|
this.gasLimit = (0, import_math9.bn)(gasLimit);
|
2267
|
-
this.script = (0,
|
2268
|
-
this.scriptData = (0,
|
2270
|
+
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
2271
|
+
this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
2269
2272
|
}
|
2270
2273
|
/**
|
2271
2274
|
* Converts the transaction request to a `TransactionScript`.
|
@@ -2273,8 +2276,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2273
2276
|
* @returns The transaction script object.
|
2274
2277
|
*/
|
2275
2278
|
toTransaction() {
|
2276
|
-
const script = (0,
|
2277
|
-
const scriptData = (0,
|
2279
|
+
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2280
|
+
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2278
2281
|
return {
|
2279
2282
|
type: import_transactions8.TransactionType.Script,
|
2280
2283
|
scriptGasLimit: this.gasLimit,
|
@@ -2282,8 +2285,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2282
2285
|
scriptLength: script.length,
|
2283
2286
|
scriptDataLength: scriptData.length,
|
2284
2287
|
receiptsRoot: import_configs9.ZeroBytes32,
|
2285
|
-
script: (0,
|
2286
|
-
scriptData: (0,
|
2288
|
+
script: (0, import_utils15.hexlify)(script),
|
2289
|
+
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2287
2290
|
};
|
2288
2291
|
}
|
2289
2292
|
/**
|
@@ -2434,15 +2437,15 @@ var transactionRequestify = (obj) => {
|
|
2434
2437
|
var import_errors12 = require("@fuel-ts/errors");
|
2435
2438
|
var import_math13 = require("@fuel-ts/math");
|
2436
2439
|
var import_transactions15 = require("@fuel-ts/transactions");
|
2437
|
-
var
|
2440
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2438
2441
|
|
2439
2442
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2440
|
-
var
|
2443
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2441
2444
|
|
2442
2445
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2443
2446
|
var import_math10 = require("@fuel-ts/math");
|
2444
2447
|
var import_transactions10 = require("@fuel-ts/transactions");
|
2445
|
-
var
|
2448
|
+
var import_utils16 = require("@fuel-ts/utils");
|
2446
2449
|
var calculateTransactionFee = (params) => {
|
2447
2450
|
const {
|
2448
2451
|
gasUsed,
|
@@ -2451,7 +2454,7 @@ var calculateTransactionFee = (params) => {
|
|
2451
2454
|
} = params;
|
2452
2455
|
const gasPerByte = (0, import_math10.bn)(feeParams.gasPerByte);
|
2453
2456
|
const gasPriceFactor = (0, import_math10.bn)(feeParams.gasPriceFactor);
|
2454
|
-
const transactionBytes = (0,
|
2457
|
+
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2455
2458
|
const [transaction] = new import_transactions10.TransactionCoder().decode(transactionBytes, 0);
|
2456
2459
|
if (transaction.type === import_transactions10.TransactionType.Mint) {
|
2457
2460
|
return {
|
@@ -2466,7 +2469,7 @@ var calculateTransactionFee = (params) => {
|
|
2466
2469
|
let gasLimit = (0, import_math10.bn)(0);
|
2467
2470
|
if (type === import_transactions10.TransactionType.Create) {
|
2468
2471
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2469
|
-
const contractBytesSize = (0, import_math10.bn)((0,
|
2472
|
+
const contractBytesSize = (0, import_math10.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2470
2473
|
metadataGas = calculateMetadataGasForTxCreate({
|
2471
2474
|
contractBytesSize,
|
2472
2475
|
gasCosts,
|
@@ -2512,14 +2515,8 @@ var calculateTransactionFee = (params) => {
|
|
2512
2515
|
};
|
2513
2516
|
};
|
2514
2517
|
|
2515
|
-
// src/providers/transaction-summary/date.ts
|
2516
|
-
var import_tai64 = require("tai64");
|
2517
|
-
var fromTai64ToDate = (tai64Timestamp) => {
|
2518
|
-
const timestamp = import_tai64.TAI64.fromString(tai64Timestamp, 10).toUnix();
|
2519
|
-
return new Date(timestamp * 1e3);
|
2520
|
-
};
|
2521
|
-
|
2522
2518
|
// src/providers/transaction-summary/operations.ts
|
2519
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2523
2520
|
var import_errors10 = require("@fuel-ts/errors");
|
2524
2521
|
var import_math12 = require("@fuel-ts/math");
|
2525
2522
|
var import_transactions13 = require("@fuel-ts/transactions");
|
@@ -2716,36 +2713,6 @@ function addOperation(operations, toAdd) {
|
|
2716
2713
|
}
|
2717
2714
|
return allOperations;
|
2718
2715
|
}
|
2719
|
-
function getReceiptsTransferOut(receipts) {
|
2720
|
-
return getReceiptsByType(receipts, import_transactions13.ReceiptType.TransferOut);
|
2721
|
-
}
|
2722
|
-
function getContractTransferOperations({ receipts }) {
|
2723
|
-
const transferOutReceipts = getReceiptsTransferOut(receipts);
|
2724
|
-
const contractTransferOperations = transferOutReceipts.reduce(
|
2725
|
-
(prevContractTransferOps, receipt) => {
|
2726
|
-
const newContractTransferOps = addOperation(prevContractTransferOps, {
|
2727
|
-
name: "Contract transfer" /* contractTransfer */,
|
2728
|
-
from: {
|
2729
|
-
type: 0 /* contract */,
|
2730
|
-
address: receipt.from
|
2731
|
-
},
|
2732
|
-
to: {
|
2733
|
-
type: 1 /* account */,
|
2734
|
-
address: receipt.to
|
2735
|
-
},
|
2736
|
-
assetsSent: [
|
2737
|
-
{
|
2738
|
-
amount: receipt.amount,
|
2739
|
-
assetId: receipt.assetId
|
2740
|
-
}
|
2741
|
-
]
|
2742
|
-
});
|
2743
|
-
return newContractTransferOps;
|
2744
|
-
},
|
2745
|
-
[]
|
2746
|
-
);
|
2747
|
-
return contractTransferOperations;
|
2748
|
-
}
|
2749
2716
|
function getWithdrawFromFuelOperations({
|
2750
2717
|
inputs,
|
2751
2718
|
receipts
|
@@ -2843,70 +2810,77 @@ function getContractCallOperations({
|
|
2843
2810
|
}, []);
|
2844
2811
|
return contractCallOperations;
|
2845
2812
|
}
|
2813
|
+
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
2814
|
+
const { to: toAddress, assetId, amount } = receipt;
|
2815
|
+
let { from: fromAddress } = receipt;
|
2816
|
+
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2817
|
+
if (import_configs10.ZeroBytes32 === fromAddress) {
|
2818
|
+
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2819
|
+
fromAddress = change?.to || fromAddress;
|
2820
|
+
}
|
2821
|
+
const fromType = contractInputs.some((input) => input.contractID === fromAddress) ? 0 /* contract */ : 1 /* account */;
|
2822
|
+
return {
|
2823
|
+
name: "Transfer asset" /* transfer */,
|
2824
|
+
from: {
|
2825
|
+
type: fromType,
|
2826
|
+
address: fromAddress
|
2827
|
+
},
|
2828
|
+
to: {
|
2829
|
+
type: toType,
|
2830
|
+
address: toAddress
|
2831
|
+
},
|
2832
|
+
assetsSent: [
|
2833
|
+
{
|
2834
|
+
assetId: assetId.toString(),
|
2835
|
+
amount
|
2836
|
+
}
|
2837
|
+
]
|
2838
|
+
};
|
2839
|
+
}
|
2846
2840
|
function getTransferOperations({
|
2847
2841
|
inputs,
|
2848
2842
|
outputs,
|
2849
2843
|
receipts
|
2850
2844
|
}) {
|
2845
|
+
let operations = [];
|
2851
2846
|
const coinOutputs = getOutputsCoin(outputs);
|
2852
|
-
const
|
2847
|
+
const contractInputs = getInputsContract(inputs);
|
2848
|
+
const changeOutputs = getOutputsChange(outputs);
|
2849
|
+
coinOutputs.forEach((output) => {
|
2850
|
+
const { amount, assetId, to } = output;
|
2851
|
+
const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
|
2852
|
+
if (changeOutput) {
|
2853
|
+
operations = addOperation(operations, {
|
2854
|
+
name: "Transfer asset" /* transfer */,
|
2855
|
+
from: {
|
2856
|
+
type: 1 /* account */,
|
2857
|
+
address: changeOutput.to
|
2858
|
+
},
|
2859
|
+
to: {
|
2860
|
+
type: 1 /* account */,
|
2861
|
+
address: to
|
2862
|
+
},
|
2863
|
+
assetsSent: [
|
2864
|
+
{
|
2865
|
+
assetId,
|
2866
|
+
amount
|
2867
|
+
}
|
2868
|
+
]
|
2869
|
+
});
|
2870
|
+
}
|
2871
|
+
});
|
2872
|
+
const transferReceipts = getReceiptsByType(
|
2853
2873
|
receipts,
|
2854
2874
|
import_transactions13.ReceiptType.Transfer
|
2855
2875
|
);
|
2856
|
-
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
2860
|
-
|
2861
|
-
|
2862
|
-
|
2863
|
-
|
2864
|
-
const inputAddress = getInputAccountAddress(utxo);
|
2865
|
-
operations = addOperation(operations, {
|
2866
|
-
name: "Transfer asset" /* transfer */,
|
2867
|
-
from: {
|
2868
|
-
type: 1 /* account */,
|
2869
|
-
address: inputAddress
|
2870
|
-
},
|
2871
|
-
to: {
|
2872
|
-
type: 0 /* contract */,
|
2873
|
-
address: contractInput.contractID
|
2874
|
-
},
|
2875
|
-
assetsSent: [
|
2876
|
-
{
|
2877
|
-
assetId: assetId.toString(),
|
2878
|
-
amount: transferReceipt.amount
|
2879
|
-
}
|
2880
|
-
]
|
2881
|
-
});
|
2882
|
-
}
|
2883
|
-
});
|
2884
|
-
} else {
|
2885
|
-
coinOutputs.forEach((output) => {
|
2886
|
-
const input = getInputFromAssetId(inputs, output.assetId);
|
2887
|
-
if (input) {
|
2888
|
-
const inputAddress = getInputAccountAddress(input);
|
2889
|
-
const operationToAdd = {
|
2890
|
-
name: "Transfer asset" /* transfer */,
|
2891
|
-
from: {
|
2892
|
-
type: 1 /* account */,
|
2893
|
-
address: inputAddress
|
2894
|
-
},
|
2895
|
-
to: {
|
2896
|
-
type: 1 /* account */,
|
2897
|
-
address: output.to.toString()
|
2898
|
-
},
|
2899
|
-
assetsSent: [
|
2900
|
-
{
|
2901
|
-
assetId: output.assetId.toString(),
|
2902
|
-
amount: output.amount
|
2903
|
-
}
|
2904
|
-
]
|
2905
|
-
};
|
2906
|
-
operations = addOperation(operations, operationToAdd);
|
2907
|
-
}
|
2908
|
-
});
|
2909
|
-
}
|
2876
|
+
const transferOutReceipts = getReceiptsByType(
|
2877
|
+
receipts,
|
2878
|
+
import_transactions13.ReceiptType.TransferOut
|
2879
|
+
);
|
2880
|
+
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2881
|
+
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
2882
|
+
operations = addOperation(operations, operation);
|
2883
|
+
});
|
2910
2884
|
return operations;
|
2911
2885
|
}
|
2912
2886
|
function getPayProducerOperations(outputs) {
|
@@ -2979,7 +2953,6 @@ function getOperations({
|
|
2979
2953
|
rawPayload,
|
2980
2954
|
maxInputs
|
2981
2955
|
}),
|
2982
|
-
...getContractTransferOperations({ receipts }),
|
2983
2956
|
...getWithdrawFromFuelOperations({ inputs, receipts })
|
2984
2957
|
];
|
2985
2958
|
}
|
@@ -3108,7 +3081,7 @@ function assembleTransactionSummary(params) {
|
|
3108
3081
|
gasCosts
|
3109
3082
|
} = params;
|
3110
3083
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3111
|
-
const rawPayload = (0,
|
3084
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3112
3085
|
const operations = getOperations({
|
3113
3086
|
transactionType: transaction.type,
|
3114
3087
|
inputs: transaction.inputs || [],
|
@@ -3135,7 +3108,7 @@ function assembleTransactionSummary(params) {
|
|
3135
3108
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3136
3109
|
let date;
|
3137
3110
|
if (time) {
|
3138
|
-
date =
|
3111
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3139
3112
|
}
|
3140
3113
|
const transactionSummary = {
|
3141
3114
|
id,
|
@@ -3225,7 +3198,7 @@ var TransactionResponse = class {
|
|
3225
3198
|
*/
|
3226
3199
|
decodeTransaction(transactionWithReceipts) {
|
3227
3200
|
return new import_transactions15.TransactionCoder().decode(
|
3228
|
-
(0,
|
3201
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3229
3202
|
0
|
3230
3203
|
)?.[0];
|
3231
3204
|
}
|
@@ -3251,7 +3224,7 @@ var TransactionResponse = class {
|
|
3251
3224
|
id: this.id,
|
3252
3225
|
receipts,
|
3253
3226
|
transaction: decodedTransaction,
|
3254
|
-
transactionBytes: (0,
|
3227
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3255
3228
|
gqlTransactionStatus: transaction.status,
|
3256
3229
|
gasPerByte,
|
3257
3230
|
gasPriceFactor,
|
@@ -3541,7 +3514,7 @@ var _Provider = class {
|
|
3541
3514
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
3542
3515
|
const isSubscription = opDefinition?.operation === "subscription";
|
3543
3516
|
if (isSubscription) {
|
3544
|
-
return
|
3517
|
+
return new FuelGraphqlSubscriber({
|
3545
3518
|
url: this.url,
|
3546
3519
|
query,
|
3547
3520
|
fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
@@ -3575,7 +3548,7 @@ var _Provider = class {
|
|
3575
3548
|
name,
|
3576
3549
|
consensusParameters: { chainId }
|
3577
3550
|
} = await this.getChain();
|
3578
|
-
const network = new
|
3551
|
+
const network = new import_ethers2.Network(name, chainId.toNumber());
|
3579
3552
|
return Promise.resolve(network);
|
3580
3553
|
}
|
3581
3554
|
/**
|
@@ -3643,7 +3616,7 @@ var _Provider = class {
|
|
3643
3616
|
if (estimateTxDependencies) {
|
3644
3617
|
await this.estimateTxDependencies(transactionRequest);
|
3645
3618
|
}
|
3646
|
-
const encodedTransaction = (0,
|
3619
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3647
3620
|
if (awaitExecution) {
|
3648
3621
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3649
3622
|
for await (const { submitAndAwait } of subscription) {
|
@@ -3674,9 +3647,9 @@ var _Provider = class {
|
|
3674
3647
|
async call(transactionRequestLike, { utxoValidation, estimateTxDependencies = true } = {}) {
|
3675
3648
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
3676
3649
|
if (estimateTxDependencies) {
|
3677
|
-
|
3650
|
+
return this.estimateTxDependencies(transactionRequest);
|
3678
3651
|
}
|
3679
|
-
const encodedTransaction = (0,
|
3652
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3680
3653
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3681
3654
|
encodedTransaction,
|
3682
3655
|
utxoValidation: utxoValidation || false
|
@@ -3693,7 +3666,15 @@ var _Provider = class {
|
|
3693
3666
|
* @returns A promise that resolves to the estimated transaction request object.
|
3694
3667
|
*/
|
3695
3668
|
async estimatePredicates(transactionRequest) {
|
3696
|
-
const
|
3669
|
+
const shouldEstimatePredicates = Boolean(
|
3670
|
+
transactionRequest.inputs.find(
|
3671
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math14.BN(input.predicateGasUsed).isZero()
|
3672
|
+
)
|
3673
|
+
);
|
3674
|
+
if (!shouldEstimatePredicates) {
|
3675
|
+
return transactionRequest;
|
3676
|
+
}
|
3677
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3697
3678
|
const response = await this.operations.estimatePredicates({
|
3698
3679
|
encodedTransaction
|
3699
3680
|
});
|
@@ -3723,34 +3704,41 @@ var _Provider = class {
|
|
3723
3704
|
* @returns A promise.
|
3724
3705
|
*/
|
3725
3706
|
async estimateTxDependencies(transactionRequest) {
|
3726
|
-
let missingOutputVariableCount = 0;
|
3727
|
-
let missingOutputContractIdsCount = 0;
|
3728
|
-
let tries = 0;
|
3729
3707
|
if (transactionRequest.type === import_transactions17.TransactionType.Create) {
|
3730
|
-
return
|
3731
|
-
|
3732
|
-
|
3733
|
-
|
3734
|
-
|
3708
|
+
return {
|
3709
|
+
receipts: [],
|
3710
|
+
outputVariables: 0,
|
3711
|
+
missingContractIds: []
|
3712
|
+
};
|
3735
3713
|
}
|
3736
|
-
|
3714
|
+
await this.estimatePredicates(transactionRequest);
|
3715
|
+
let receipts = [];
|
3716
|
+
const missingContractIds = [];
|
3717
|
+
let outputVariables = 0;
|
3718
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3737
3719
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3738
|
-
encodedTransaction: (0,
|
3720
|
+
encodedTransaction: (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes()),
|
3739
3721
|
utxoValidation: false
|
3740
3722
|
});
|
3741
|
-
|
3723
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3742
3724
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3743
|
-
|
3744
|
-
|
3745
|
-
|
3746
|
-
|
3725
|
+
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3726
|
+
if (hasMissingOutputs) {
|
3727
|
+
outputVariables += missingOutputVariables.length;
|
3728
|
+
transactionRequest.addVariableOutputs(missingOutputVariables.length);
|
3729
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
3730
|
+
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3731
|
+
missingContractIds.push(contractId);
|
3732
|
+
});
|
3733
|
+
} else {
|
3734
|
+
break;
|
3747
3735
|
}
|
3748
|
-
txRequest.addVariableOutputs(missingOutputVariableCount);
|
3749
|
-
missingOutputContractIds.forEach(
|
3750
|
-
({ contractId }) => txRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId))
|
3751
|
-
);
|
3752
|
-
tries += 1;
|
3753
3736
|
}
|
3737
|
+
return {
|
3738
|
+
receipts,
|
3739
|
+
outputVariables,
|
3740
|
+
missingContractIds
|
3741
|
+
};
|
3754
3742
|
}
|
3755
3743
|
/**
|
3756
3744
|
* Executes a signed transaction without applying the states changes
|
@@ -3765,9 +3753,9 @@ var _Provider = class {
|
|
3765
3753
|
async simulate(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
3766
3754
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
3767
3755
|
if (estimateTxDependencies) {
|
3768
|
-
|
3756
|
+
return this.estimateTxDependencies(transactionRequest);
|
3769
3757
|
}
|
3770
|
-
const encodedTransaction = (0,
|
3758
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3771
3759
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3772
3760
|
encodedTransaction,
|
3773
3761
|
utxoValidation: true
|
@@ -3797,35 +3785,37 @@ var _Provider = class {
|
|
3797
3785
|
estimatePredicates = true,
|
3798
3786
|
resourcesOwner
|
3799
3787
|
} = {}) {
|
3800
|
-
const
|
3788
|
+
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3801
3789
|
const chainInfo = this.getChain();
|
3802
3790
|
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3803
|
-
const gasPrice = (0, import_math14.max)(
|
3804
|
-
const isScriptTransaction =
|
3805
|
-
|
3791
|
+
const gasPrice = (0, import_math14.max)(txRequestClone.gasPrice, minGasPrice);
|
3792
|
+
const isScriptTransaction = txRequestClone.type === import_transactions17.TransactionType.Script;
|
3793
|
+
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3794
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3795
|
+
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3796
|
+
if (estimatePredicates) {
|
3806
3797
|
if (isScriptTransaction) {
|
3807
|
-
|
3798
|
+
txRequestClone.gasLimit = (0, import_math14.bn)(0);
|
3799
|
+
}
|
3800
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3801
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3808
3802
|
}
|
3809
|
-
await this.estimatePredicates(
|
3803
|
+
await this.estimatePredicates(txRequestClone);
|
3810
3804
|
}
|
3811
|
-
const minGas =
|
3812
|
-
const maxGas =
|
3813
|
-
const coinOutputsQuantities = transactionRequest.getCoinOutputsQuantities();
|
3814
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3815
|
-
transactionRequest.fundWithFakeUtxos(allQuantities, resourcesOwner);
|
3816
|
-
let gasUsed = minGas;
|
3805
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3806
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
3817
3807
|
let receipts = [];
|
3818
|
-
|
3819
|
-
|
3820
|
-
|
3821
|
-
|
3822
|
-
|
3823
|
-
|
3808
|
+
let missingContractIds = [];
|
3809
|
+
let outputVariables = 0;
|
3810
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3811
|
+
txRequestClone.gasPrice = (0, import_math14.bn)(0);
|
3812
|
+
txRequestClone.gasLimit = (0, import_math14.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3813
|
+
const result = await this.estimateTxDependencies(txRequestClone);
|
3824
3814
|
receipts = result.receipts;
|
3825
|
-
|
3826
|
-
|
3827
|
-
gasUsed = minGas;
|
3815
|
+
outputVariables = result.outputVariables;
|
3816
|
+
missingContractIds = result.missingContractIds;
|
3828
3817
|
}
|
3818
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3829
3819
|
const usedFee = calculatePriceWithFactor(
|
3830
3820
|
gasUsed,
|
3831
3821
|
gasPrice,
|
@@ -3843,7 +3833,10 @@ var _Provider = class {
|
|
3843
3833
|
maxGas,
|
3844
3834
|
usedFee,
|
3845
3835
|
minFee,
|
3846
|
-
maxFee
|
3836
|
+
maxFee,
|
3837
|
+
estimatedInputs: txRequestClone.inputs,
|
3838
|
+
outputVariables,
|
3839
|
+
missingContractIds
|
3847
3840
|
};
|
3848
3841
|
}
|
3849
3842
|
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
@@ -3872,7 +3865,7 @@ var _Provider = class {
|
|
3872
3865
|
const result = await this.operations.getCoins({
|
3873
3866
|
first: 10,
|
3874
3867
|
...paginationArgs,
|
3875
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
3868
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
3876
3869
|
});
|
3877
3870
|
const coins = result.coins.edges.map((edge) => edge.node);
|
3878
3871
|
return coins.map((coin) => ({
|
@@ -3896,19 +3889,19 @@ var _Provider = class {
|
|
3896
3889
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
3897
3890
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
3898
3891
|
const excludeInput = {
|
3899
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
3900
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
3892
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
3893
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
3901
3894
|
};
|
3902
3895
|
if (this.cache) {
|
3903
3896
|
const uniqueUtxos = new Set(
|
3904
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
3897
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
3905
3898
|
);
|
3906
3899
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
3907
3900
|
}
|
3908
3901
|
const coinsQuery = {
|
3909
3902
|
owner: ownerAddress.toB256(),
|
3910
3903
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
3911
|
-
assetId: (0,
|
3904
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
3912
3905
|
amount: amount.toString(10),
|
3913
3906
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
3914
3907
|
})),
|
@@ -4011,7 +4004,7 @@ var _Provider = class {
|
|
4011
4004
|
time: block.header.time,
|
4012
4005
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4013
4006
|
transactions: block.transactions.map(
|
4014
|
-
(tx) => new import_transactions17.TransactionCoder().decode((0,
|
4007
|
+
(tx) => new import_transactions17.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4015
4008
|
)
|
4016
4009
|
};
|
4017
4010
|
}
|
@@ -4027,7 +4020,7 @@ var _Provider = class {
|
|
4027
4020
|
return null;
|
4028
4021
|
}
|
4029
4022
|
return new import_transactions17.TransactionCoder().decode(
|
4030
|
-
(0,
|
4023
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4031
4024
|
0
|
4032
4025
|
)?.[0];
|
4033
4026
|
}
|
@@ -4054,7 +4047,7 @@ var _Provider = class {
|
|
4054
4047
|
async getContractBalance(contractId, assetId) {
|
4055
4048
|
const { contractBalance } = await this.operations.getContractBalance({
|
4056
4049
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4057
|
-
asset: (0,
|
4050
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4058
4051
|
});
|
4059
4052
|
return (0, import_math14.bn)(contractBalance.amount, 10);
|
4060
4053
|
}
|
@@ -4068,7 +4061,7 @@ var _Provider = class {
|
|
4068
4061
|
async getBalance(owner, assetId) {
|
4069
4062
|
const { balance } = await this.operations.getBalance({
|
4070
4063
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4071
|
-
assetId: (0,
|
4064
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4072
4065
|
});
|
4073
4066
|
return (0, import_math14.bn)(balance.amount, 10);
|
4074
4067
|
}
|
@@ -4223,13 +4216,13 @@ var _Provider = class {
|
|
4223
4216
|
* Lets you produce blocks with custom timestamps and the block number of the last block produced.
|
4224
4217
|
*
|
4225
4218
|
* @param amount - The amount of blocks to produce
|
4226
|
-
* @param startTime - The UNIX timestamp to set for the first produced block
|
4219
|
+
* @param startTime - The UNIX timestamp (milliseconds) to set for the first produced block
|
4227
4220
|
* @returns A promise that resolves to the block number of the last produced block.
|
4228
4221
|
*/
|
4229
4222
|
async produceBlocks(amount, startTime) {
|
4230
4223
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4231
4224
|
blocksToProduce: (0, import_math14.bn)(amount).toString(10),
|
4232
|
-
startTimestamp: startTime ?
|
4225
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4233
4226
|
});
|
4234
4227
|
return (0, import_math14.bn)(latestBlockHeight);
|
4235
4228
|
}
|
@@ -4257,21 +4250,66 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4257
4250
|
var import_errors14 = require("@fuel-ts/errors");
|
4258
4251
|
var import_math15 = require("@fuel-ts/math");
|
4259
4252
|
var import_transactions18 = require("@fuel-ts/transactions");
|
4260
|
-
var
|
4253
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4254
|
+
|
4255
|
+
// src/providers/chains.ts
|
4256
|
+
var CHAIN_IDS = {
|
4257
|
+
eth: {
|
4258
|
+
sepolia: 11155111,
|
4259
|
+
foundry: 31337
|
4260
|
+
},
|
4261
|
+
fuel: {
|
4262
|
+
beta5: 0,
|
4263
|
+
devnet: 10
|
4264
|
+
}
|
4265
|
+
};
|
4266
|
+
|
4267
|
+
// src/providers/assets/index.ts
|
4268
|
+
var assets = [
|
4269
|
+
{
|
4270
|
+
name: "Ethereum",
|
4271
|
+
symbol: "ETH",
|
4272
|
+
icon: "eth.svg",
|
4273
|
+
networks: [
|
4274
|
+
{
|
4275
|
+
type: "ethereum",
|
4276
|
+
chainId: CHAIN_IDS.eth.sepolia,
|
4277
|
+
decimals: 18
|
4278
|
+
},
|
4279
|
+
{
|
4280
|
+
type: "ethereum",
|
4281
|
+
chainId: CHAIN_IDS.eth.foundry,
|
4282
|
+
decimals: 18
|
4283
|
+
},
|
4284
|
+
{
|
4285
|
+
type: "fuel",
|
4286
|
+
chainId: CHAIN_IDS.fuel.beta5,
|
4287
|
+
decimals: 9,
|
4288
|
+
assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
4289
|
+
},
|
4290
|
+
{
|
4291
|
+
type: "fuel",
|
4292
|
+
chainId: CHAIN_IDS.fuel.devnet,
|
4293
|
+
decimals: 9,
|
4294
|
+
assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
4295
|
+
}
|
4296
|
+
]
|
4297
|
+
}
|
4298
|
+
];
|
4261
4299
|
|
4262
4300
|
// src/utils/formatTransferToContractScriptData.ts
|
4263
4301
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4264
4302
|
var import_math16 = require("@fuel-ts/math");
|
4303
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4265
4304
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4266
|
-
var import_ethers20 = require("ethers");
|
4267
4305
|
var formatTransferToContractScriptData = (params) => {
|
4268
4306
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4269
|
-
const numberCoder = new import_abi_coder4.
|
4307
|
+
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4270
4308
|
const encoded = numberCoder.encode(new import_math16.BN(amountToTransfer).toNumber());
|
4271
4309
|
const scriptData = Uint8Array.from([
|
4272
|
-
...(0,
|
4310
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4273
4311
|
...encoded,
|
4274
|
-
...(0,
|
4312
|
+
...(0, import_utils26.arrayify)(assetId)
|
4275
4313
|
]);
|
4276
4314
|
return scriptData;
|
4277
4315
|
};
|
@@ -4418,7 +4456,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4418
4456
|
* @param assetId - The asset ID to check the balance for.
|
4419
4457
|
* @returns A promise that resolves to the balance amount.
|
4420
4458
|
*/
|
4421
|
-
async getBalance(assetId =
|
4459
|
+
async getBalance(assetId = import_configs11.BaseAssetId) {
|
4422
4460
|
const amount = await this.provider.getBalance(this.address, assetId);
|
4423
4461
|
return amount;
|
4424
4462
|
}
|
@@ -4459,7 +4497,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4459
4497
|
async fund(request, coinQuantities, fee) {
|
4460
4498
|
const updatedQuantities = addAmountToAsset({
|
4461
4499
|
amount: (0, import_math17.bn)(fee),
|
4462
|
-
assetId:
|
4500
|
+
assetId: import_configs11.BaseAssetId,
|
4463
4501
|
coinQuantities
|
4464
4502
|
});
|
4465
4503
|
const quantitiesDict = {};
|
@@ -4483,8 +4521,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4483
4521
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4484
4522
|
cachedUtxos.push(input.id);
|
4485
4523
|
}
|
4486
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4487
|
-
quantitiesDict[
|
4524
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs11.BaseAssetId]) {
|
4525
|
+
quantitiesDict[import_configs11.BaseAssetId].owned = quantitiesDict[import_configs11.BaseAssetId].owned.add(input.amount);
|
4488
4526
|
cachedMessages.push(input.nonce);
|
4489
4527
|
}
|
4490
4528
|
}
|
@@ -4516,12 +4554,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4516
4554
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4517
4555
|
* @returns A promise that resolves to the prepared transaction request.
|
4518
4556
|
*/
|
4519
|
-
async createTransfer(destination, amount, assetId =
|
4557
|
+
async createTransfer(destination, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
|
4520
4558
|
const { minGasPrice } = this.provider.getGasConfig();
|
4521
4559
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4522
4560
|
const request = new ScriptTransactionRequest(params);
|
4523
4561
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4524
|
-
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(request
|
4562
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4563
|
+
estimateTxDependencies: true,
|
4564
|
+
resourcesOwner: this
|
4565
|
+
});
|
4525
4566
|
request.gasPrice = (0, import_math17.bn)(txParams.gasPrice ?? minGasPrice);
|
4526
4567
|
request.gasLimit = (0, import_math17.bn)(txParams.gasLimit ?? gasUsed);
|
4527
4568
|
this.validateGas({
|
@@ -4531,6 +4572,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4531
4572
|
minGasPrice
|
4532
4573
|
});
|
4533
4574
|
await this.fund(request, requiredQuantities, maxFee);
|
4575
|
+
request.updatePredicateInputs(estimatedInputs);
|
4534
4576
|
return request;
|
4535
4577
|
}
|
4536
4578
|
/**
|
@@ -4542,9 +4584,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4542
4584
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4543
4585
|
* @returns A promise that resolves to the transaction response.
|
4544
4586
|
*/
|
4545
|
-
async transfer(destination, amount, assetId =
|
4587
|
+
async transfer(destination, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
|
4546
4588
|
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4547
|
-
return this.sendTransaction(request);
|
4589
|
+
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4548
4590
|
}
|
4549
4591
|
/**
|
4550
4592
|
* Transfers coins to a contract address.
|
@@ -4555,7 +4597,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4555
4597
|
* @param txParams - The optional transaction parameters.
|
4556
4598
|
* @returns A promise that resolves to the transaction response.
|
4557
4599
|
*/
|
4558
|
-
async transferToContract(contractId, amount, assetId =
|
4600
|
+
async transferToContract(contractId, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
|
4559
4601
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4560
4602
|
const { minGasPrice } = this.provider.getGasConfig();
|
4561
4603
|
const params = { gasPrice: minGasPrice, ...txParams };
|
@@ -4595,20 +4637,20 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4595
4637
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4596
4638
|
const { minGasPrice } = this.provider.getGasConfig();
|
4597
4639
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4598
|
-
const recipientDataArray = (0,
|
4640
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
4599
4641
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4600
4642
|
);
|
4601
|
-
const amountDataArray = (0,
|
4643
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
4602
4644
|
"0x".concat((0, import_math17.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4603
4645
|
);
|
4604
4646
|
const script = new Uint8Array([
|
4605
|
-
...(0,
|
4647
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
4606
4648
|
...recipientDataArray,
|
4607
4649
|
...amountDataArray
|
4608
4650
|
]);
|
4609
4651
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4610
4652
|
const request = new ScriptTransactionRequest(params);
|
4611
|
-
const forwardingQuantities = [{ amount: (0, import_math17.bn)(amount), assetId:
|
4653
|
+
const forwardingQuantities = [{ amount: (0, import_math17.bn)(amount), assetId: import_configs11.BaseAssetId }];
|
4612
4654
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4613
4655
|
request,
|
4614
4656
|
forwardingQuantities
|
@@ -4635,16 +4677,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4635
4677
|
* @param transactionRequestLike - The transaction request to be sent.
|
4636
4678
|
* @returns A promise that resolves to the transaction response.
|
4637
4679
|
*/
|
4638
|
-
async sendTransaction(transactionRequestLike,
|
4680
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
4639
4681
|
if (this._connector) {
|
4640
4682
|
return this.provider.getTransactionResponse(
|
4641
4683
|
await this._connector.sendTransaction(this.address.toString(), transactionRequestLike)
|
4642
4684
|
);
|
4643
4685
|
}
|
4644
4686
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4645
|
-
|
4687
|
+
if (estimateTxDependencies) {
|
4688
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
4689
|
+
}
|
4646
4690
|
return this.provider.sendTransaction(transactionRequest, {
|
4647
|
-
|
4691
|
+
awaitExecution,
|
4648
4692
|
estimateTxDependencies: false
|
4649
4693
|
});
|
4650
4694
|
}
|
@@ -4654,9 +4698,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4654
4698
|
* @param transactionRequestLike - The transaction request to be simulated.
|
4655
4699
|
* @returns A promise that resolves to the call result.
|
4656
4700
|
*/
|
4657
|
-
async simulateTransaction(transactionRequestLike) {
|
4701
|
+
async simulateTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
4658
4702
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4659
|
-
|
4703
|
+
if (estimateTxDependencies) {
|
4704
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
4705
|
+
}
|
4660
4706
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4661
4707
|
}
|
4662
4708
|
validateGas({
|
@@ -4685,8 +4731,8 @@ var import_address5 = require("@fuel-ts/address");
|
|
4685
4731
|
var import_crypto = require("@fuel-ts/crypto");
|
4686
4732
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4687
4733
|
var import_math18 = require("@fuel-ts/math");
|
4734
|
+
var import_utils28 = require("@fuel-ts/utils");
|
4688
4735
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4689
|
-
var import_ethers22 = require("ethers");
|
4690
4736
|
var Signer = class {
|
4691
4737
|
address;
|
4692
4738
|
publicKey;
|
@@ -4705,9 +4751,9 @@ var Signer = class {
|
|
4705
4751
|
}
|
4706
4752
|
}
|
4707
4753
|
const privateKeyBytes = (0, import_math18.toBytes)(privateKey, 32);
|
4708
|
-
this.privateKey = (0,
|
4709
|
-
this.publicKey = (0,
|
4710
|
-
this.compressedPublicKey = (0,
|
4754
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
4755
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4756
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4711
4757
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4712
4758
|
}
|
4713
4759
|
/**
|
@@ -4721,11 +4767,11 @@ var Signer = class {
|
|
4721
4767
|
* @returns hashed signature
|
4722
4768
|
*/
|
4723
4769
|
sign(data) {
|
4724
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4770
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
4725
4771
|
const r = (0, import_math18.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4726
4772
|
const s = (0, import_math18.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4727
4773
|
s[0] |= (signature.recovery || 0) << 7;
|
4728
|
-
return (0,
|
4774
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
4729
4775
|
}
|
4730
4776
|
/**
|
4731
4777
|
* Add point on the current elliptic curve
|
@@ -4734,8 +4780,8 @@ var Signer = class {
|
|
4734
4780
|
* @returns compressed point on the curve
|
4735
4781
|
*/
|
4736
4782
|
addPoint(point) {
|
4737
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4738
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4783
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
4784
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
4739
4785
|
const result = p0.add(p1);
|
4740
4786
|
return `0x${result.toHex(true)}`;
|
4741
4787
|
}
|
@@ -4747,16 +4793,16 @@ var Signer = class {
|
|
4747
4793
|
* @returns public key from signature from the
|
4748
4794
|
*/
|
4749
4795
|
static recoverPublicKey(data, signature) {
|
4750
|
-
const signedMessageBytes = (0,
|
4796
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
4751
4797
|
const r = signedMessageBytes.slice(0, 32);
|
4752
4798
|
const s = signedMessageBytes.slice(32, 64);
|
4753
4799
|
const recoveryParam = (s[0] & 128) >> 7;
|
4754
4800
|
s[0] &= 127;
|
4755
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
4801
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
4756
4802
|
recoveryParam
|
4757
4803
|
);
|
4758
|
-
const publicKey = sig.recoverPublicKey((0,
|
4759
|
-
return (0,
|
4804
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
4805
|
+
return (0, import_utils28.hexlify)(publicKey);
|
4760
4806
|
}
|
4761
4807
|
/**
|
4762
4808
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -4775,7 +4821,7 @@ var Signer = class {
|
|
4775
4821
|
* @returns random 32-byte hashed
|
4776
4822
|
*/
|
4777
4823
|
static generatePrivateKey(entropy) {
|
4778
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
4824
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
4779
4825
|
}
|
4780
4826
|
/**
|
4781
4827
|
* Extended publicKey from a compact publicKey
|
@@ -4784,8 +4830,8 @@ var Signer = class {
|
|
4784
4830
|
* @returns extended publicKey
|
4785
4831
|
*/
|
4786
4832
|
static extendPublicKey(publicKey) {
|
4787
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4788
|
-
return (0,
|
4833
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
4834
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
4789
4835
|
}
|
4790
4836
|
};
|
4791
4837
|
|
@@ -4793,7 +4839,7 @@ var Signer = class {
|
|
4793
4839
|
var import_address6 = require("@fuel-ts/address");
|
4794
4840
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4795
4841
|
var import_errors16 = require("@fuel-ts/errors");
|
4796
|
-
var
|
4842
|
+
var import_utils29 = require("@fuel-ts/utils");
|
4797
4843
|
var import_uuid = require("uuid");
|
4798
4844
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
4799
4845
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -4876,7 +4922,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
4876
4922
|
);
|
4877
4923
|
}
|
4878
4924
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
4879
|
-
const privateKey = (0,
|
4925
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
4880
4926
|
return privateKey;
|
4881
4927
|
}
|
4882
4928
|
|
@@ -4921,7 +4967,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
4921
4967
|
*/
|
4922
4968
|
async signMessage(message) {
|
4923
4969
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
4924
|
-
return signedMessage;
|
4970
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
4925
4971
|
}
|
4926
4972
|
/**
|
4927
4973
|
* Signs a transaction with the wallet's private key.
|
@@ -4934,7 +4980,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
4934
4980
|
const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
|
4935
4981
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
4936
4982
|
const signature = await this.signer().sign(hashedTransaction);
|
4937
|
-
return signature;
|
4983
|
+
return (0, import_utils30.hexlify)(signature);
|
4938
4984
|
}
|
4939
4985
|
/**
|
4940
4986
|
* Populates a transaction with the witnesses signature.
|
@@ -4954,12 +5000,14 @@ var BaseWalletUnlocked = class extends Account {
|
|
4954
5000
|
* @param transactionRequestLike - The transaction request to send.
|
4955
5001
|
* @returns A promise that resolves to the TransactionResponse object.
|
4956
5002
|
*/
|
4957
|
-
async sendTransaction(transactionRequestLike,
|
5003
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
4958
5004
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4959
|
-
|
5005
|
+
if (estimateTxDependencies) {
|
5006
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
5007
|
+
}
|
4960
5008
|
return this.provider.sendTransaction(
|
4961
5009
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
4962
|
-
{
|
5010
|
+
{ awaitExecution, estimateTxDependencies: false }
|
4963
5011
|
);
|
4964
5012
|
}
|
4965
5013
|
/**
|
@@ -4968,9 +5016,11 @@ var BaseWalletUnlocked = class extends Account {
|
|
4968
5016
|
* @param transactionRequestLike - The transaction request to simulate.
|
4969
5017
|
* @returns A promise that resolves to the CallResult object.
|
4970
5018
|
*/
|
4971
|
-
async simulateTransaction(transactionRequestLike) {
|
5019
|
+
async simulateTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
4972
5020
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4973
|
-
|
5021
|
+
if (estimateTxDependencies) {
|
5022
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
5023
|
+
}
|
4974
5024
|
return this.provider.call(
|
4975
5025
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
4976
5026
|
{
|
@@ -4991,12 +5041,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
4991
5041
|
// src/hdwallet/hdwallet.ts
|
4992
5042
|
var import_errors19 = require("@fuel-ts/errors");
|
4993
5043
|
var import_math19 = require("@fuel-ts/math");
|
4994
|
-
var
|
5044
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5045
|
+
var import_ethers5 = require("ethers");
|
4995
5046
|
|
4996
5047
|
// src/mnemonic/mnemonic.ts
|
4997
5048
|
var import_crypto3 = require("@fuel-ts/crypto");
|
4998
5049
|
var import_errors18 = require("@fuel-ts/errors");
|
4999
|
-
var
|
5050
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5051
|
+
var import_ethers4 = require("ethers");
|
5000
5052
|
|
5001
5053
|
// src/wordlists/words/english.ts
|
5002
5054
|
var english = [
|
@@ -7052,7 +7104,8 @@ var english = [
|
|
7052
7104
|
|
7053
7105
|
// src/mnemonic/utils.ts
|
7054
7106
|
var import_errors17 = require("@fuel-ts/errors");
|
7055
|
-
var
|
7107
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7108
|
+
var import_ethers3 = require("ethers");
|
7056
7109
|
function toUtf8Bytes(stri) {
|
7057
7110
|
const str = stri.normalize("NFKD");
|
7058
7111
|
const result = [];
|
@@ -7119,14 +7172,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7119
7172
|
}
|
7120
7173
|
}
|
7121
7174
|
const checksumBits = entropy.length / 4;
|
7122
|
-
const checksum = (0,
|
7175
|
+
const checksum = (0, import_utils31.arrayify)((0, import_ethers3.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7123
7176
|
indices[indices.length - 1] <<= checksumBits;
|
7124
7177
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7125
7178
|
return indices;
|
7126
7179
|
}
|
7127
7180
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7128
7181
|
const size = Math.ceil(11 * words.length / 8);
|
7129
|
-
const entropy = (0,
|
7182
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7130
7183
|
let offset = 0;
|
7131
7184
|
for (let i = 0; i < words.length; i += 1) {
|
7132
7185
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7146,7 +7199,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7146
7199
|
const entropyBits = 32 * words.length / 3;
|
7147
7200
|
const checksumBits = words.length / 3;
|
7148
7201
|
const checksumMask = getUpperMask(checksumBits);
|
7149
|
-
const checksum = (0,
|
7202
|
+
const checksum = (0, import_utils31.arrayify)((0, import_ethers3.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7150
7203
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7151
7204
|
throw new import_errors17.FuelError(
|
7152
7205
|
import_errors17.ErrorCode.INVALID_CHECKSUM,
|
@@ -7221,7 +7274,7 @@ var Mnemonic = class {
|
|
7221
7274
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7222
7275
|
const words = getWords(phrase);
|
7223
7276
|
assertMnemonic(words);
|
7224
|
-
return (0,
|
7277
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7225
7278
|
}
|
7226
7279
|
/**
|
7227
7280
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7229,7 +7282,7 @@ var Mnemonic = class {
|
|
7229
7282
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7230
7283
|
*/
|
7231
7284
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7232
|
-
const entropyBytes = (0,
|
7285
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7233
7286
|
assertWordList(wordlist);
|
7234
7287
|
assertEntropy(entropyBytes);
|
7235
7288
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7243,7 +7296,7 @@ var Mnemonic = class {
|
|
7243
7296
|
assertMnemonic(getWords(phrase));
|
7244
7297
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
7245
7298
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
7246
|
-
return (0,
|
7299
|
+
return (0, import_ethers4.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
7247
7300
|
}
|
7248
7301
|
/**
|
7249
7302
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -7298,14 +7351,14 @@ var Mnemonic = class {
|
|
7298
7351
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7299
7352
|
*/
|
7300
7353
|
static masterKeysFromSeed(seed) {
|
7301
|
-
const seedArray = (0,
|
7354
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7302
7355
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7303
7356
|
throw new import_errors18.FuelError(
|
7304
7357
|
import_errors18.ErrorCode.INVALID_SEED,
|
7305
7358
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7306
7359
|
);
|
7307
7360
|
}
|
7308
|
-
return (0,
|
7361
|
+
return (0, import_utils32.arrayify)((0, import_ethers4.computeHmac)("sha512", MasterSecret, seedArray));
|
7309
7362
|
}
|
7310
7363
|
/**
|
7311
7364
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7316,22 +7369,22 @@ var Mnemonic = class {
|
|
7316
7369
|
*/
|
7317
7370
|
static seedToExtendedKey(seed, testnet = false) {
|
7318
7371
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7319
|
-
const prefix = (0,
|
7372
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7320
7373
|
const depth = "0x00";
|
7321
7374
|
const fingerprint = "0x00000000";
|
7322
7375
|
const index = "0x00000000";
|
7323
7376
|
const chainCode = masterKey.slice(32);
|
7324
7377
|
const privateKey = masterKey.slice(0, 32);
|
7325
|
-
const extendedKey = (0,
|
7378
|
+
const extendedKey = (0, import_utils32.concat)([
|
7326
7379
|
prefix,
|
7327
7380
|
depth,
|
7328
7381
|
fingerprint,
|
7329
7382
|
index,
|
7330
7383
|
chainCode,
|
7331
|
-
(0,
|
7384
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
7332
7385
|
]);
|
7333
|
-
const checksum = (0,
|
7334
|
-
return (0,
|
7386
|
+
const checksum = (0, import_ethers4.dataSlice)((0, import_ethers4.sha256)((0, import_ethers4.sha256)(extendedKey)), 0, 4);
|
7387
|
+
return (0, import_ethers4.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
7335
7388
|
}
|
7336
7389
|
/**
|
7337
7390
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7346,7 +7399,7 @@ var Mnemonic = class {
|
|
7346
7399
|
* @returns A randomly generated mnemonic
|
7347
7400
|
*/
|
7348
7401
|
static generate(size = 32, extraEntropy = "") {
|
7349
|
-
const entropy = extraEntropy ? (0,
|
7402
|
+
const entropy = extraEntropy ? (0, import_ethers4.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
7350
7403
|
return Mnemonic.entropyToMnemonic(entropy);
|
7351
7404
|
}
|
7352
7405
|
};
|
@@ -7354,12 +7407,12 @@ var mnemonic_default = Mnemonic;
|
|
7354
7407
|
|
7355
7408
|
// src/hdwallet/hdwallet.ts
|
7356
7409
|
var HARDENED_INDEX = 2147483648;
|
7357
|
-
var MainnetPRV2 = (0,
|
7358
|
-
var MainnetPUB = (0,
|
7359
|
-
var TestnetPRV2 = (0,
|
7360
|
-
var TestnetPUB = (0,
|
7410
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
7411
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
7412
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7413
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
7361
7414
|
function base58check(data) {
|
7362
|
-
return (0,
|
7415
|
+
return (0, import_ethers5.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers5.dataSlice)((0, import_ethers5.sha256)((0, import_ethers5.sha256)(data)), 0, 4)]));
|
7363
7416
|
}
|
7364
7417
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7365
7418
|
if (isPublic) {
|
@@ -7368,11 +7421,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7368
7421
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7369
7422
|
}
|
7370
7423
|
function isPublicExtendedKey(extendedKey) {
|
7371
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7424
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
7372
7425
|
}
|
7373
7426
|
function isValidExtendedKey(extendedKey) {
|
7374
7427
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7375
|
-
(0,
|
7428
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
7376
7429
|
);
|
7377
7430
|
}
|
7378
7431
|
function parsePath(path2, depth = 0) {
|
@@ -7390,8 +7443,8 @@ function parsePath(path2, depth = 0) {
|
|
7390
7443
|
var HDWallet = class {
|
7391
7444
|
depth = 0;
|
7392
7445
|
index = 0;
|
7393
|
-
fingerprint = (0,
|
7394
|
-
parentFingerprint = (0,
|
7446
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7447
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7395
7448
|
privateKey;
|
7396
7449
|
publicKey;
|
7397
7450
|
chainCode;
|
@@ -7403,8 +7456,8 @@ var HDWallet = class {
|
|
7403
7456
|
constructor(config) {
|
7404
7457
|
if (config.privateKey) {
|
7405
7458
|
const signer = new Signer(config.privateKey);
|
7406
|
-
this.publicKey = (0,
|
7407
|
-
this.privateKey = (0,
|
7459
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
7460
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
7408
7461
|
} else {
|
7409
7462
|
if (!config.publicKey) {
|
7410
7463
|
throw new import_errors19.FuelError(
|
@@ -7412,10 +7465,10 @@ var HDWallet = class {
|
|
7412
7465
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7413
7466
|
);
|
7414
7467
|
}
|
7415
|
-
this.publicKey = (0,
|
7468
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
7416
7469
|
}
|
7417
7470
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7418
|
-
this.fingerprint = (0,
|
7471
|
+
this.fingerprint = (0, import_ethers5.dataSlice)((0, import_ethers5.ripemd160)((0, import_ethers5.sha256)(this.publicKey)), 0, 4);
|
7419
7472
|
this.depth = config.depth || this.depth;
|
7420
7473
|
this.index = config.index || this.index;
|
7421
7474
|
this.chainCode = config.chainCode;
|
@@ -7431,9 +7484,9 @@ var HDWallet = class {
|
|
7431
7484
|
* @returns A new instance of HDWallet on the derived index
|
7432
7485
|
*/
|
7433
7486
|
deriveIndex(index) {
|
7434
|
-
const privateKey = this.privateKey && (0,
|
7435
|
-
const publicKey = (0,
|
7436
|
-
const chainCode = (0,
|
7487
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
7488
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
7489
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
7437
7490
|
const data = new Uint8Array(37);
|
7438
7491
|
if (index & HARDENED_INDEX) {
|
7439
7492
|
if (!privateKey) {
|
@@ -7444,10 +7497,10 @@ var HDWallet = class {
|
|
7444
7497
|
}
|
7445
7498
|
data.set(privateKey, 1);
|
7446
7499
|
} else {
|
7447
|
-
data.set((0,
|
7500
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
7448
7501
|
}
|
7449
7502
|
data.set((0, import_math19.toBytes)(index, 4), 33);
|
7450
|
-
const bytes = (0,
|
7503
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers5.computeHmac)("sha512", chainCode, data));
|
7451
7504
|
const IL = bytes.slice(0, 32);
|
7452
7505
|
const IR = bytes.slice(32);
|
7453
7506
|
if (privateKey) {
|
@@ -7461,7 +7514,7 @@ var HDWallet = class {
|
|
7461
7514
|
parentFingerprint: this.fingerprint
|
7462
7515
|
});
|
7463
7516
|
}
|
7464
|
-
const signer = new Signer((0,
|
7517
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
7465
7518
|
const Ki = signer.addPoint(publicKey);
|
7466
7519
|
return new HDWallet({
|
7467
7520
|
publicKey: Ki,
|
@@ -7496,14 +7549,12 @@ var HDWallet = class {
|
|
7496
7549
|
);
|
7497
7550
|
}
|
7498
7551
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7499
|
-
const depth = (0,
|
7552
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
7500
7553
|
const parentFingerprint = this.parentFingerprint;
|
7501
7554
|
const index = (0, import_math19.toHex)(this.index, 4);
|
7502
7555
|
const chainCode = this.chainCode;
|
7503
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7504
|
-
const extendedKey = (0,
|
7505
|
-
(0, import_ethers26.concat)([prefix, depth, parentFingerprint, index, chainCode, key])
|
7506
|
-
);
|
7556
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7557
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7507
7558
|
return base58check(extendedKey);
|
7508
7559
|
}
|
7509
7560
|
/**
|
@@ -7515,13 +7566,13 @@ var HDWallet = class {
|
|
7515
7566
|
static fromSeed(seed) {
|
7516
7567
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7517
7568
|
return new HDWallet({
|
7518
|
-
chainCode: (0,
|
7519
|
-
privateKey: (0,
|
7569
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
7570
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
7520
7571
|
});
|
7521
7572
|
}
|
7522
7573
|
static fromExtendedKey(extendedKey) {
|
7523
|
-
const decoded = (0,
|
7524
|
-
const bytes = (0,
|
7574
|
+
const decoded = (0, import_ethers5.toBeHex)((0, import_ethers5.decodeBase58)(extendedKey));
|
7575
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
7525
7576
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7526
7577
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7527
7578
|
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7530,9 +7581,9 @@ var HDWallet = class {
|
|
7530
7581
|
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7531
7582
|
}
|
7532
7583
|
const depth = bytes[4];
|
7533
|
-
const parentFingerprint = (0,
|
7534
|
-
const index = parseInt((0,
|
7535
|
-
const chainCode = (0,
|
7584
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
7585
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7586
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
7536
7587
|
const key = bytes.slice(45, 78);
|
7537
7588
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7538
7589
|
throw new import_errors19.FuelError(
|
@@ -7746,13 +7797,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7746
7797
|
};
|
7747
7798
|
|
7748
7799
|
// src/test-utils/launchNode.ts
|
7749
|
-
var
|
7800
|
+
var import_configs12 = require("@fuel-ts/address/configs");
|
7750
7801
|
var import_math20 = require("@fuel-ts/math");
|
7751
|
-
var
|
7802
|
+
var import_utils35 = require("@fuel-ts/utils");
|
7752
7803
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
7753
7804
|
var import_child_process = require("child_process");
|
7754
7805
|
var import_crypto5 = require("crypto");
|
7755
|
-
var import_ethers27 = require("ethers");
|
7756
7806
|
var import_fs = require("fs");
|
7757
7807
|
var import_os = __toESM(require("os"));
|
7758
7808
|
var import_path = __toESM(require("path"));
|
@@ -7807,7 +7857,7 @@ var launchNode = async ({
|
|
7807
7857
|
"--poa-instant"
|
7808
7858
|
]);
|
7809
7859
|
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
7810
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
7860
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
|
7811
7861
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
7812
7862
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
7813
7863
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -7833,21 +7883,21 @@ var launchNode = async ({
|
|
7833
7883
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
7834
7884
|
}
|
7835
7885
|
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
7836
|
-
let chainConfig =
|
7886
|
+
let chainConfig = import_utils35.defaultChainConfig;
|
7837
7887
|
if (!process.env.GENESIS_SECRET) {
|
7838
7888
|
const pk = Signer.generatePrivateKey();
|
7839
7889
|
const signer = new Signer(pk);
|
7840
|
-
process.env.GENESIS_SECRET = (0,
|
7890
|
+
process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
|
7841
7891
|
chainConfig = {
|
7842
|
-
...
|
7892
|
+
...import_utils35.defaultChainConfig,
|
7843
7893
|
initial_state: {
|
7844
|
-
...
|
7894
|
+
...import_utils35.defaultChainConfig.initial_state,
|
7845
7895
|
coins: [
|
7846
|
-
...
|
7896
|
+
...import_utils35.defaultChainConfig.initial_state.coins,
|
7847
7897
|
{
|
7848
7898
|
owner: signer.address.toHexString(),
|
7849
7899
|
amount: (0, import_math20.toHex)(1e9),
|
7850
|
-
asset_id:
|
7900
|
+
asset_id: import_configs12.BaseAssetId
|
7851
7901
|
}
|
7852
7902
|
]
|
7853
7903
|
}
|
@@ -7915,7 +7965,7 @@ var launchNode = async ({
|
|
7915
7965
|
var generateWallets = async (count, provider) => {
|
7916
7966
|
const wallets = [];
|
7917
7967
|
for (let i = 0; i < count; i += 1) {
|
7918
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
7968
|
+
const wallet = await generateTestWallet(provider, [[1e3, import_configs12.BaseAssetId]]);
|
7919
7969
|
wallets.push(wallet);
|
7920
7970
|
}
|
7921
7971
|
return wallets;
|