@fuel-ts/account 0.0.0-rc-2143-20240424152333 → 0.0.0-rc-1976-20240424153519
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/README.md +2 -2
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +57 -41
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +93 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -41
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +2 -2
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +7 -0
- package/dist/providers/provider.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/transaction-request.d.ts +5 -5
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/utils/merge-quantities.d.ts +1 -1
- package/dist/providers/utils/merge-quantities.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +2 -4
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +60 -44
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +95 -81
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +57 -43
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -15
package/dist/index.js
CHANGED
@@ -184,14 +184,12 @@ module.exports = __toCommonJS(src_exports);
|
|
184
184
|
|
185
185
|
// src/account.ts
|
186
186
|
var import_address4 = require("@fuel-ts/address");
|
187
|
-
var import_configs12 = require("@fuel-ts/address/configs");
|
188
187
|
var import_errors16 = require("@fuel-ts/errors");
|
189
188
|
var import_interfaces = require("@fuel-ts/interfaces");
|
190
189
|
var import_math18 = require("@fuel-ts/math");
|
191
190
|
var import_utils28 = require("@fuel-ts/utils");
|
192
191
|
|
193
192
|
// src/providers/coin-quantity.ts
|
194
|
-
var import_configs = require("@fuel-ts/address/configs");
|
195
193
|
var import_math = require("@fuel-ts/math");
|
196
194
|
var import_utils = require("@fuel-ts/utils");
|
197
195
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -200,11 +198,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
200
198
|
let max2;
|
201
199
|
if (Array.isArray(coinQuantityLike)) {
|
202
200
|
amount = coinQuantityLike[0];
|
203
|
-
assetId = coinQuantityLike[1]
|
204
|
-
max2 = coinQuantityLike[2]
|
201
|
+
assetId = coinQuantityLike[1];
|
202
|
+
max2 = coinQuantityLike[2];
|
205
203
|
} else {
|
206
204
|
amount = coinQuantityLike.amount;
|
207
|
-
assetId = coinQuantityLike.assetId
|
205
|
+
assetId = coinQuantityLike.assetId;
|
208
206
|
max2 = coinQuantityLike.max ?? void 0;
|
209
207
|
}
|
210
208
|
const bnAmount = (0, import_math.bn)(amount);
|
@@ -1183,7 +1181,7 @@ var MemoryCache = class {
|
|
1183
1181
|
|
1184
1182
|
// src/providers/transaction-request/input.ts
|
1185
1183
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
1186
|
-
var
|
1184
|
+
var import_configs = require("@fuel-ts/address/configs");
|
1187
1185
|
var import_errors3 = require("@fuel-ts/errors");
|
1188
1186
|
var import_math2 = require("@fuel-ts/math");
|
1189
1187
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1217,10 +1215,10 @@ var inputify = (value) => {
|
|
1217
1215
|
case import_transactions.InputType.Contract: {
|
1218
1216
|
return {
|
1219
1217
|
type: import_transactions.InputType.Contract,
|
1220
|
-
txID:
|
1218
|
+
txID: import_configs.ZeroBytes32,
|
1221
1219
|
outputIndex: 0,
|
1222
|
-
balanceRoot:
|
1223
|
-
stateRoot:
|
1220
|
+
balanceRoot: import_configs.ZeroBytes32,
|
1221
|
+
stateRoot: import_configs.ZeroBytes32,
|
1224
1222
|
txPointer: {
|
1225
1223
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1226
1224
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1258,7 +1256,7 @@ var inputify = (value) => {
|
|
1258
1256
|
};
|
1259
1257
|
|
1260
1258
|
// src/providers/transaction-request/output.ts
|
1261
|
-
var
|
1259
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1262
1260
|
var import_errors4 = require("@fuel-ts/errors");
|
1263
1261
|
var import_math3 = require("@fuel-ts/math");
|
1264
1262
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1278,8 +1276,8 @@ var outputify = (value) => {
|
|
1278
1276
|
return {
|
1279
1277
|
type: import_transactions2.OutputType.Contract,
|
1280
1278
|
inputIndex: value.inputIndex,
|
1281
|
-
balanceRoot:
|
1282
|
-
stateRoot:
|
1279
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1280
|
+
stateRoot: import_configs2.ZeroBytes32
|
1283
1281
|
};
|
1284
1282
|
}
|
1285
1283
|
case import_transactions2.OutputType.Change: {
|
@@ -1293,9 +1291,9 @@ var outputify = (value) => {
|
|
1293
1291
|
case import_transactions2.OutputType.Variable: {
|
1294
1292
|
return {
|
1295
1293
|
type: import_transactions2.OutputType.Variable,
|
1296
|
-
to:
|
1294
|
+
to: import_configs2.ZeroBytes32,
|
1297
1295
|
amount: (0, import_math3.bn)(0),
|
1298
|
-
assetId:
|
1296
|
+
assetId: import_configs2.ZeroBytes32
|
1299
1297
|
};
|
1300
1298
|
}
|
1301
1299
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1317,7 +1315,7 @@ var outputify = (value) => {
|
|
1317
1315
|
// src/providers/transaction-request/transaction-request.ts
|
1318
1316
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1319
1317
|
var import_address = require("@fuel-ts/address");
|
1320
|
-
var
|
1318
|
+
var import_configs6 = require("@fuel-ts/address/configs");
|
1321
1319
|
var import_crypto = require("@fuel-ts/crypto");
|
1322
1320
|
var import_math7 = require("@fuel-ts/math");
|
1323
1321
|
var import_transactions6 = require("@fuel-ts/transactions");
|
@@ -1330,13 +1328,13 @@ var isCoin = (resource) => "id" in resource;
|
|
1330
1328
|
var isMessage = (resource) => "recipient" in resource;
|
1331
1329
|
|
1332
1330
|
// src/providers/utils/receipts.ts
|
1333
|
-
var
|
1331
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1334
1332
|
var import_errors5 = require("@fuel-ts/errors");
|
1335
1333
|
var import_math4 = require("@fuel-ts/math");
|
1336
1334
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1337
|
-
var
|
1335
|
+
var import_configs4 = require("@fuel-ts/transactions/configs");
|
1338
1336
|
var import_utils5 = require("@fuel-ts/utils");
|
1339
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1337
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1340
1338
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1341
1339
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1342
1340
|
(memo, receipt) => {
|
@@ -1353,7 +1351,7 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1353
1351
|
missingOutputContractIds: []
|
1354
1352
|
}
|
1355
1353
|
);
|
1356
|
-
var hexOrZero = (hex) => hex ||
|
1354
|
+
var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
|
1357
1355
|
function assembleReceiptByType(receipt) {
|
1358
1356
|
const { receiptType } = receipt;
|
1359
1357
|
switch (receiptType) {
|
@@ -1717,16 +1715,16 @@ function sleep(time) {
|
|
1717
1715
|
var import_errors7 = require("@fuel-ts/errors");
|
1718
1716
|
var import_math6 = require("@fuel-ts/math");
|
1719
1717
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1720
|
-
var
|
1718
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1721
1719
|
var assemblePanicError = (status) => {
|
1722
1720
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1723
1721
|
const reason = status.reason;
|
1724
|
-
if (
|
1722
|
+
if (import_configs5.PANIC_REASONS.includes(status.reason)) {
|
1725
1723
|
errorMessage = `${errorMessage}
|
1726
1724
|
|
1727
1725
|
You can read more about this error at:
|
1728
1726
|
|
1729
|
-
${
|
1727
|
+
${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
|
1730
1728
|
}
|
1731
1729
|
return { errorMessage, reason };
|
1732
1730
|
};
|
@@ -1738,28 +1736,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1738
1736
|
if (revertReceipt) {
|
1739
1737
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1740
1738
|
switch (reasonHex) {
|
1741
|
-
case
|
1739
|
+
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
1742
1740
|
reason = "require";
|
1743
1741
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1744
1742
|
break;
|
1745
1743
|
}
|
1746
|
-
case
|
1744
|
+
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
1747
1745
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1748
1746
|
reason = "assert_eq";
|
1749
1747
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1750
1748
|
break;
|
1751
1749
|
}
|
1752
|
-
case
|
1750
|
+
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
1753
1751
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1754
1752
|
reason = "assert_ne";
|
1755
1753
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1756
1754
|
break;
|
1757
1755
|
}
|
1758
|
-
case
|
1756
|
+
case import_configs5.FAILED_ASSERT_SIGNAL:
|
1759
1757
|
reason = "assert";
|
1760
1758
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1761
1759
|
break;
|
1762
|
-
case
|
1760
|
+
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1763
1761
|
reason = "MissingOutputChange";
|
1764
1762
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1765
1763
|
break;
|
@@ -1946,7 +1944,7 @@ var BaseTransactionRequest = class {
|
|
1946
1944
|
* @returns The index of the created witness.
|
1947
1945
|
*/
|
1948
1946
|
addEmptyWitness() {
|
1949
|
-
this.addWitness((0, import_utils9.concat)([
|
1947
|
+
this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
1950
1948
|
return this.witnesses.length - 1;
|
1951
1949
|
}
|
1952
1950
|
/**
|
@@ -2073,15 +2071,13 @@ var BaseTransactionRequest = class {
|
|
2073
2071
|
}
|
2074
2072
|
/**
|
2075
2073
|
* Adds a single message input to the transaction and a change output for the
|
2076
|
-
*
|
2074
|
+
* asset against the message
|
2077
2075
|
*
|
2078
2076
|
* @param message - Message resource.
|
2079
2077
|
* @param predicate - Predicate bytes.
|
2080
|
-
* @param predicateData - Predicate data bytes.
|
2081
2078
|
*/
|
2082
2079
|
addMessageInput(message, predicate) {
|
2083
|
-
const { recipient, sender, amount } = message;
|
2084
|
-
const assetId = import_configs7.BaseAssetId;
|
2080
|
+
const { recipient, sender, amount, assetId } = message;
|
2085
2081
|
let witnessIndex;
|
2086
2082
|
if (predicate) {
|
2087
2083
|
witnessIndex = 0;
|
@@ -2162,7 +2158,7 @@ var BaseTransactionRequest = class {
|
|
2162
2158
|
* @param amount - Amount of coin.
|
2163
2159
|
* @param assetId - Asset ID of coin.
|
2164
2160
|
*/
|
2165
|
-
addCoinOutput(to, amount, assetId
|
2161
|
+
addCoinOutput(to, amount, assetId) {
|
2166
2162
|
this.pushOutput({
|
2167
2163
|
type: import_transactions6.OutputType.Coin,
|
2168
2164
|
to: (0, import_address.addressify)(to).toB256(),
|
@@ -2194,7 +2190,7 @@ var BaseTransactionRequest = class {
|
|
2194
2190
|
* @param to - Address of the owner.
|
2195
2191
|
* @param assetId - Asset ID of coin.
|
2196
2192
|
*/
|
2197
|
-
addChangeOutput(to, assetId
|
2193
|
+
addChangeOutput(to, assetId) {
|
2198
2194
|
const changeOutput = this.getChangeOutputs().find(
|
2199
2195
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2200
2196
|
);
|
@@ -2251,8 +2247,9 @@ var BaseTransactionRequest = class {
|
|
2251
2247
|
* quantities array.
|
2252
2248
|
*
|
2253
2249
|
* @param quantities - CoinQuantity Array.
|
2250
|
+
* @param baseAssetId - The base asset to fund the transaction.
|
2254
2251
|
*/
|
2255
|
-
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2252
|
+
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2256
2253
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2257
2254
|
if ("assetId" in input) {
|
2258
2255
|
return input.assetId === assetId;
|
@@ -2278,7 +2275,7 @@ var BaseTransactionRequest = class {
|
|
2278
2275
|
]);
|
2279
2276
|
}
|
2280
2277
|
};
|
2281
|
-
updateAssetInput(
|
2278
|
+
updateAssetInput(baseAssetId, (0, import_math7.bn)(1e11));
|
2282
2279
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2283
2280
|
}
|
2284
2281
|
/**
|
@@ -2328,13 +2325,13 @@ var BaseTransactionRequest = class {
|
|
2328
2325
|
};
|
2329
2326
|
|
2330
2327
|
// src/providers/transaction-request/create-transaction-request.ts
|
2331
|
-
var
|
2328
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2332
2329
|
var import_math9 = require("@fuel-ts/math");
|
2333
2330
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2334
2331
|
var import_utils13 = require("@fuel-ts/utils");
|
2335
2332
|
|
2336
2333
|
// src/providers/transaction-request/hash-transaction.ts
|
2337
|
-
var
|
2334
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
2338
2335
|
var import_hasher = require("@fuel-ts/hasher");
|
2339
2336
|
var import_math8 = require("@fuel-ts/math");
|
2340
2337
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2343,7 +2340,7 @@ var import_ramda2 = require("ramda");
|
|
2343
2340
|
function hashTransaction(transactionRequest, chainId) {
|
2344
2341
|
const transaction = transactionRequest.toTransaction();
|
2345
2342
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2346
|
-
transaction.receiptsRoot =
|
2343
|
+
transaction.receiptsRoot = import_configs7.ZeroBytes32;
|
2347
2344
|
}
|
2348
2345
|
transaction.inputs = transaction.inputs.map((input) => {
|
2349
2346
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2365,10 +2362,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2365
2362
|
blockHeight: 0,
|
2366
2363
|
txIndex: 0
|
2367
2364
|
};
|
2368
|
-
inputClone.txID =
|
2365
|
+
inputClone.txID = import_configs7.ZeroBytes32;
|
2369
2366
|
inputClone.outputIndex = 0;
|
2370
|
-
inputClone.balanceRoot =
|
2371
|
-
inputClone.stateRoot =
|
2367
|
+
inputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2368
|
+
inputClone.stateRoot = import_configs7.ZeroBytes32;
|
2372
2369
|
return inputClone;
|
2373
2370
|
}
|
2374
2371
|
default:
|
@@ -2379,8 +2376,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2379
2376
|
const outputClone = (0, import_ramda2.clone)(output);
|
2380
2377
|
switch (outputClone.type) {
|
2381
2378
|
case import_transactions7.OutputType.Contract: {
|
2382
|
-
outputClone.balanceRoot =
|
2383
|
-
outputClone.stateRoot =
|
2379
|
+
outputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2380
|
+
outputClone.stateRoot = import_configs7.ZeroBytes32;
|
2384
2381
|
return outputClone;
|
2385
2382
|
}
|
2386
2383
|
case import_transactions7.OutputType.Change: {
|
@@ -2388,9 +2385,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2388
2385
|
return outputClone;
|
2389
2386
|
}
|
2390
2387
|
case import_transactions7.OutputType.Variable: {
|
2391
|
-
outputClone.to =
|
2388
|
+
outputClone.to = import_configs7.ZeroBytes32;
|
2392
2389
|
outputClone.amount = (0, import_math8.bn)(0);
|
2393
|
-
outputClone.assetId =
|
2390
|
+
outputClone.assetId = import_configs7.ZeroBytes32;
|
2394
2391
|
return outputClone;
|
2395
2392
|
}
|
2396
2393
|
default:
|
@@ -2448,15 +2445,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2448
2445
|
*
|
2449
2446
|
* @param createTransactionRequestLike - The initial values for the instance
|
2450
2447
|
*/
|
2451
|
-
constructor({
|
2452
|
-
bytecodeWitnessIndex,
|
2453
|
-
salt,
|
2454
|
-
storageSlots,
|
2455
|
-
...rest
|
2456
|
-
} = {}) {
|
2448
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2457
2449
|
super(rest);
|
2458
2450
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2459
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2451
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2460
2452
|
this.storageSlots = [...storageSlots ?? []];
|
2461
2453
|
}
|
2462
2454
|
/**
|
@@ -2474,7 +2466,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2474
2466
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2475
2467
|
bytecodeWitnessIndex,
|
2476
2468
|
storageSlotsCount: storageSlots.length,
|
2477
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2469
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2478
2470
|
storageSlots
|
2479
2471
|
};
|
2480
2472
|
}
|
@@ -2524,7 +2516,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2524
2516
|
// src/providers/transaction-request/script-transaction-request.ts
|
2525
2517
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
2526
2518
|
var import_address2 = require("@fuel-ts/address");
|
2527
|
-
var
|
2519
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2528
2520
|
var import_math10 = require("@fuel-ts/math");
|
2529
2521
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2530
2522
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2598,7 +2590,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2598
2590
|
...super.getBaseTransaction(),
|
2599
2591
|
scriptLength: script.length,
|
2600
2592
|
scriptDataLength: scriptData.length,
|
2601
|
-
receiptsRoot:
|
2593
|
+
receiptsRoot: import_configs9.ZeroBytes32,
|
2602
2594
|
script: (0, import_utils15.hexlify)(script),
|
2603
2595
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2604
2596
|
};
|
@@ -2830,7 +2822,7 @@ var calculateTransactionFee = (params) => {
|
|
2830
2822
|
};
|
2831
2823
|
|
2832
2824
|
// src/providers/transaction-summary/operations.ts
|
2833
|
-
var
|
2825
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2834
2826
|
var import_errors11 = require("@fuel-ts/errors");
|
2835
2827
|
var import_math13 = require("@fuel-ts/math");
|
2836
2828
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -3175,7 +3167,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3175
3167
|
const { to: toAddress, assetId, amount } = receipt;
|
3176
3168
|
let { from: fromAddress } = receipt;
|
3177
3169
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3178
|
-
if (
|
3170
|
+
if (import_configs10.ZeroBytes32 === fromAddress) {
|
3179
3171
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3180
3172
|
fromAddress = change?.to || fromAddress;
|
3181
3173
|
}
|
@@ -3714,7 +3706,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3714
3706
|
}
|
3715
3707
|
|
3716
3708
|
// src/providers/utils/merge-quantities.ts
|
3717
|
-
var mergeQuantities = (
|
3709
|
+
var mergeQuantities = (...coinQuantities) => {
|
3718
3710
|
const resultMap = {};
|
3719
3711
|
function addToMap({ amount, assetId }) {
|
3720
3712
|
if (resultMap[assetId]) {
|
@@ -3723,8 +3715,7 @@ var mergeQuantities = (arr1, arr2) => {
|
|
3723
3715
|
resultMap[assetId] = amount;
|
3724
3716
|
}
|
3725
3717
|
}
|
3726
|
-
|
3727
|
-
arr2.forEach(addToMap);
|
3718
|
+
coinQuantities.forEach((arr) => arr.forEach(addToMap));
|
3728
3719
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
3729
3720
|
};
|
3730
3721
|
|
@@ -3752,6 +3743,7 @@ var processGqlChain = (chain) => {
|
|
3752
3743
|
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3753
3744
|
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3754
3745
|
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3746
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3755
3747
|
gasCosts
|
3756
3748
|
},
|
3757
3749
|
gasCosts,
|
@@ -3994,6 +3986,17 @@ var _Provider = class {
|
|
3994
3986
|
} = this.getChain();
|
3995
3987
|
return chainId.toNumber();
|
3996
3988
|
}
|
3989
|
+
/**
|
3990
|
+
* Returns the base asset ID
|
3991
|
+
*
|
3992
|
+
* @returns A promise that resolves to the base asset ID
|
3993
|
+
*/
|
3994
|
+
getBaseAssetId() {
|
3995
|
+
const {
|
3996
|
+
consensusParameters: { baseAssetId }
|
3997
|
+
} = this.getChain();
|
3998
|
+
return baseAssetId;
|
3999
|
+
}
|
3997
4000
|
/**
|
3998
4001
|
* Submits a transaction to the chain to be executed.
|
3999
4002
|
*
|
@@ -4224,9 +4227,10 @@ var _Provider = class {
|
|
4224
4227
|
const { minGasPrice } = this.getGasConfig();
|
4225
4228
|
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4226
4229
|
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4230
|
+
const baseAssetId = this.getBaseAssetId();
|
4227
4231
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4228
4232
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4229
|
-
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4233
|
+
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4230
4234
|
if (isScriptTransaction) {
|
4231
4235
|
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4232
4236
|
}
|
@@ -5057,8 +5061,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5057
5061
|
* @param assetId - The asset ID to check the balance for.
|
5058
5062
|
* @returns A promise that resolves to the balance amount.
|
5059
5063
|
*/
|
5060
|
-
async getBalance(assetId
|
5061
|
-
const
|
5064
|
+
async getBalance(assetId) {
|
5065
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
5066
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5062
5067
|
return amount;
|
5063
5068
|
}
|
5064
5069
|
/**
|
@@ -5096,9 +5101,10 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5096
5101
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5097
5102
|
*/
|
5098
5103
|
async fund(request, coinQuantities, fee) {
|
5104
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5099
5105
|
const updatedQuantities = addAmountToAsset({
|
5100
5106
|
amount: (0, import_math18.bn)(fee),
|
5101
|
-
assetId:
|
5107
|
+
assetId: baseAssetId,
|
5102
5108
|
coinQuantities
|
5103
5109
|
});
|
5104
5110
|
const quantitiesDict = {};
|
@@ -5122,8 +5128,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5122
5128
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5123
5129
|
cachedUtxos.push(input.id);
|
5124
5130
|
}
|
5125
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
5126
|
-
quantitiesDict[
|
5131
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
5132
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
5127
5133
|
cachedMessages.push(input.nonce);
|
5128
5134
|
}
|
5129
5135
|
}
|
@@ -5155,11 +5161,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5155
5161
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5156
5162
|
* @returns A promise that resolves to the prepared transaction request.
|
5157
5163
|
*/
|
5158
|
-
async createTransfer(destination, amount, assetId
|
5164
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5159
5165
|
const { minGasPrice } = this.provider.getGasConfig();
|
5166
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5160
5167
|
const params = { gasPrice: minGasPrice, ...txParams };
|
5161
5168
|
const request = new ScriptTransactionRequest(params);
|
5162
|
-
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount,
|
5169
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5163
5170
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5164
5171
|
estimateTxDependencies: true,
|
5165
5172
|
resourcesOwner: this
|
@@ -5185,14 +5192,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5185
5192
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5186
5193
|
* @returns A promise that resolves to the transaction response.
|
5187
5194
|
*/
|
5188
|
-
async transfer(destination, amount, assetId
|
5195
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
5189
5196
|
if ((0, import_math18.bn)(amount).lte(0)) {
|
5190
5197
|
throw new import_errors16.FuelError(
|
5191
5198
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5192
5199
|
"Transfer amount must be a positive number."
|
5193
5200
|
);
|
5194
5201
|
}
|
5195
|
-
const
|
5202
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5203
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5196
5204
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5197
5205
|
}
|
5198
5206
|
/**
|
@@ -5204,7 +5212,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5204
5212
|
* @param txParams - The optional transaction parameters.
|
5205
5213
|
* @returns A promise that resolves to the transaction response.
|
5206
5214
|
*/
|
5207
|
-
async transferToContract(contractId, amount, assetId
|
5215
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5208
5216
|
if ((0, import_math18.bn)(amount).lte(0)) {
|
5209
5217
|
throw new import_errors16.FuelError(
|
5210
5218
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
@@ -5213,11 +5221,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5213
5221
|
}
|
5214
5222
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5215
5223
|
const { minGasPrice } = this.provider.getGasConfig();
|
5224
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5216
5225
|
const params = { gasPrice: minGasPrice, ...txParams };
|
5217
5226
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5218
5227
|
hexlifiedContractId: contractAddress.toB256(),
|
5219
5228
|
amountToTransfer: (0, import_math18.bn)(amount),
|
5220
|
-
assetId
|
5229
|
+
assetId: assetIdToTransfer
|
5221
5230
|
});
|
5222
5231
|
const request = new ScriptTransactionRequest({
|
5223
5232
|
...params,
|
@@ -5227,7 +5236,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5227
5236
|
request.addContractInputAndOutput(contractAddress);
|
5228
5237
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5229
5238
|
request,
|
5230
|
-
[{ amount: (0, import_math18.bn)(amount), assetId: String(
|
5239
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
|
5231
5240
|
);
|
5232
5241
|
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5233
5242
|
this.validateGas({
|
@@ -5249,6 +5258,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5249
5258
|
*/
|
5250
5259
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5251
5260
|
const { minGasPrice } = this.provider.getGasConfig();
|
5261
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5252
5262
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5253
5263
|
const recipientDataArray = (0, import_utils28.arrayify)(
|
5254
5264
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -5261,9 +5271,13 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5261
5271
|
...recipientDataArray,
|
5262
5272
|
...amountDataArray
|
5263
5273
|
]);
|
5264
|
-
const params = {
|
5274
|
+
const params = {
|
5275
|
+
script,
|
5276
|
+
gasPrice: minGasPrice,
|
5277
|
+
...txParams
|
5278
|
+
};
|
5265
5279
|
const request = new ScriptTransactionRequest(params);
|
5266
|
-
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId:
|
5280
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
|
5267
5281
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5268
5282
|
request,
|
5269
5283
|
forwardingQuantities
|
@@ -8826,7 +8840,6 @@ var StorageAbstract = class {
|
|
8826
8840
|
// src/predicate/predicate.ts
|
8827
8841
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8828
8842
|
var import_address10 = require("@fuel-ts/address");
|
8829
|
-
var import_configs13 = require("@fuel-ts/address/configs");
|
8830
8843
|
var import_errors25 = require("@fuel-ts/errors");
|
8831
8844
|
var import_transactions20 = require("@fuel-ts/transactions");
|
8832
8845
|
var import_utils37 = require("@fuel-ts/utils");
|
@@ -8904,8 +8917,9 @@ var Predicate = class extends Account {
|
|
8904
8917
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8905
8918
|
* @returns A promise that resolves to the prepared transaction request.
|
8906
8919
|
*/
|
8907
|
-
async createTransfer(destination, amount, assetId
|
8908
|
-
const
|
8920
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8921
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
8922
|
+
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8909
8923
|
return this.populateTransactionPredicateData(request);
|
8910
8924
|
}
|
8911
8925
|
/**
|