@fuel-ts/account 0.0.0-rc-1832-20240415161726 → 0.0.0-rc-2034-20240415163000
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/index.global.js +139 -121
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +96 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -41
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +0 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +13 -2
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/test-utils.global.js +141 -122
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +93 -71
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +64 -42
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
@@ -31977,6 +31977,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
31977
31977
|
ErrorCode2["INVALID_COMPONENT"] = "invalid-component";
|
31978
31978
|
ErrorCode2["CONFIGURABLE_NOT_FOUND"] = "configurable-not-found";
|
31979
31979
|
ErrorCode2["TYPE_NOT_FOUND"] = "type-not-found";
|
31980
|
+
ErrorCode2["LOG_TYPE_NOT_FOUND"] = "log-type-not-found";
|
31980
31981
|
ErrorCode2["TYPE_NOT_SUPPORTED"] = "type-not-supported";
|
31981
31982
|
ErrorCode2["INVALID_DECODE_VALUE"] = "invalid-decode-value";
|
31982
31983
|
ErrorCode2["JSON_ABI_ERROR"] = "json-abi-error";
|
@@ -34762,7 +34763,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34762
34763
|
var import_bn = __toESM(require_bn(), 1);
|
34763
34764
|
var DEFAULT_PRECISION = 9;
|
34764
34765
|
var DEFAULT_MIN_PRECISION = 3;
|
34765
|
-
var
|
34766
|
+
var DEFAULT_DECIMAL_UNITS = 9;
|
34766
34767
|
function toFixed(value, options) {
|
34767
34768
|
const { precision = DEFAULT_PRECISION, minPrecision = DEFAULT_MIN_PRECISION } = options || {};
|
34768
34769
|
const [valueUnits = "0", valueDecimals = "0"] = String(value || "0.0").split(".");
|
@@ -34828,7 +34829,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34828
34829
|
}
|
34829
34830
|
format(options) {
|
34830
34831
|
const {
|
34831
|
-
units =
|
34832
|
+
units = DEFAULT_DECIMAL_UNITS,
|
34832
34833
|
precision = DEFAULT_PRECISION,
|
34833
34834
|
minPrecision = DEFAULT_MIN_PRECISION
|
34834
34835
|
} = options || {};
|
@@ -34844,7 +34845,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34844
34845
|
}
|
34845
34846
|
return formattedFixed;
|
34846
34847
|
}
|
34847
|
-
formatUnits(units =
|
34848
|
+
formatUnits(units = DEFAULT_DECIMAL_UNITS) {
|
34848
34849
|
const valueUnits = this.toString().slice(0, units * -1);
|
34849
34850
|
const valueDecimals = this.toString().slice(units * -1);
|
34850
34851
|
const length = valueDecimals.length;
|
@@ -34953,7 +34954,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
34953
34954
|
// END ANCHOR: OVERRIDES to avoid losing references
|
34954
34955
|
};
|
34955
34956
|
var bn = (value, base, endian) => new BN(value, base, endian);
|
34956
|
-
bn.parseUnits = (value, units =
|
34957
|
+
bn.parseUnits = (value, units = DEFAULT_DECIMAL_UNITS) => {
|
34957
34958
|
const valueToParse = value === "." ? "0." : value;
|
34958
34959
|
const [valueUnits = "0", valueDecimals = "0"] = valueToParse.split(".");
|
34959
34960
|
const length = valueDecimals.length;
|
@@ -35069,6 +35070,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35069
35070
|
var ENCODING_V1 = "1";
|
35070
35071
|
var WORD_SIZE = 8;
|
35071
35072
|
var BYTES_32 = 32;
|
35073
|
+
var UTXO_ID_LEN = BYTES_32 + 1;
|
35072
35074
|
var ASSET_ID_LEN = BYTES_32;
|
35073
35075
|
var ADDRESS_LEN = BYTES_32;
|
35074
35076
|
var NONCE_LEN = BYTES_32;
|
@@ -35219,15 +35221,6 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35219
35221
|
}
|
35220
35222
|
};
|
35221
35223
|
var isHeapType = (type3) => type3 === VEC_CODER_TYPE || type3 === BYTES_CODER_TYPE || type3 === STD_STRING_CODER_TYPE;
|
35222
|
-
function findOrThrow(arr, predicate, throwFn = () => {
|
35223
|
-
throw new FuelError(ErrorCode.ELEMENT_NOT_FOUND, "Element not found in the array.");
|
35224
|
-
}) {
|
35225
|
-
const found = arr.find(predicate);
|
35226
|
-
if (found === void 0) {
|
35227
|
-
throwFn();
|
35228
|
-
}
|
35229
|
-
return found;
|
35230
|
-
}
|
35231
35224
|
var isMultipleOfWordSize = (length) => length % WORD_SIZE === 0;
|
35232
35225
|
var getWordSizePadding = (length) => WORD_SIZE - length % WORD_SIZE;
|
35233
35226
|
var rightPadToWordSize = (encoded) => {
|
@@ -35237,6 +35230,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35237
35230
|
const padding = new Uint8Array(WORD_SIZE - encoded.length % WORD_SIZE);
|
35238
35231
|
return concatBytes2([encoded, padding]);
|
35239
35232
|
};
|
35233
|
+
var isUint8Array = (value) => value instanceof Uint8Array;
|
35240
35234
|
var ArrayCoder = class extends Coder {
|
35241
35235
|
coder;
|
35242
35236
|
length;
|
@@ -35778,8 +35772,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35778
35772
|
this.coder = coder;
|
35779
35773
|
}
|
35780
35774
|
encode(value) {
|
35781
|
-
if (!Array.isArray(value)) {
|
35782
|
-
throw new FuelError(
|
35775
|
+
if (!Array.isArray(value) && !isUint8Array(value)) {
|
35776
|
+
throw new FuelError(
|
35777
|
+
ErrorCode.ENCODE_ERROR,
|
35778
|
+
`Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
|
35779
|
+
);
|
35783
35780
|
}
|
35784
35781
|
const parts = [];
|
35785
35782
|
const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
|
@@ -35810,6 +35807,38 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35810
35807
|
];
|
35811
35808
|
}
|
35812
35809
|
};
|
35810
|
+
var findFunctionByName = (abi, name) => {
|
35811
|
+
const fn = abi.functions.find((f2) => f2.name === name);
|
35812
|
+
if (!fn) {
|
35813
|
+
throw new FuelError(
|
35814
|
+
ErrorCode.FUNCTION_NOT_FOUND,
|
35815
|
+
`Function with name '${name}' doesn't exist in the ABI`
|
35816
|
+
);
|
35817
|
+
}
|
35818
|
+
return fn;
|
35819
|
+
};
|
35820
|
+
var findTypeById = (abi, typeId) => {
|
35821
|
+
const type3 = abi.types.find((t) => t.typeId === typeId);
|
35822
|
+
if (!type3) {
|
35823
|
+
throw new FuelError(
|
35824
|
+
ErrorCode.TYPE_NOT_FOUND,
|
35825
|
+
`Type with typeId '${typeId}' doesn't exist in the ABI.`
|
35826
|
+
);
|
35827
|
+
}
|
35828
|
+
return type3;
|
35829
|
+
};
|
35830
|
+
var findNonEmptyInputs = (abi, inputs) => inputs.filter((input) => findTypeById(abi, input.type).type !== "()");
|
35831
|
+
var findVectorBufferArgument = (components) => {
|
35832
|
+
const bufferComponent = components.find((c) => c.name === "buf");
|
35833
|
+
const bufferTypeArgument = bufferComponent?.originalTypeArguments?.[0];
|
35834
|
+
if (!bufferComponent || !bufferTypeArgument) {
|
35835
|
+
throw new FuelError(
|
35836
|
+
ErrorCode.INVALID_COMPONENT,
|
35837
|
+
`The Vec type provided is missing or has a malformed 'buf' component.`
|
35838
|
+
);
|
35839
|
+
}
|
35840
|
+
return bufferTypeArgument;
|
35841
|
+
};
|
35813
35842
|
var ResolvedAbiType = class {
|
35814
35843
|
abi;
|
35815
35844
|
name;
|
@@ -35818,20 +35847,8 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35818
35847
|
components;
|
35819
35848
|
constructor(abi, argument) {
|
35820
35849
|
this.abi = abi;
|
35821
|
-
const type3 = findOrThrow(
|
35822
|
-
abi.types,
|
35823
|
-
(t) => t.typeId === argument.type,
|
35824
|
-
() => {
|
35825
|
-
throw new FuelError(
|
35826
|
-
ErrorCode.TYPE_NOT_FOUND,
|
35827
|
-
`Type does not exist in the provided abi: ${JSON.stringify({
|
35828
|
-
argument,
|
35829
|
-
abi: this.abi
|
35830
|
-
})}`
|
35831
|
-
);
|
35832
|
-
}
|
35833
|
-
);
|
35834
35850
|
this.name = argument.name;
|
35851
|
+
const type3 = findTypeById(abi, argument.type);
|
35835
35852
|
this.type = type3.type;
|
35836
35853
|
this.originalTypeArguments = argument.typeArguments;
|
35837
35854
|
this.components = ResolvedAbiType.getResolvedGenericComponents(
|
@@ -35883,7 +35900,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35883
35900
|
)
|
35884
35901
|
};
|
35885
35902
|
}
|
35886
|
-
const argType =
|
35903
|
+
const argType = findTypeById(abi, arg.type);
|
35887
35904
|
const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
|
35888
35905
|
if (implicitTypeParameters && implicitTypeParameters.length > 0) {
|
35889
35906
|
return {
|
@@ -35900,7 +35917,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
35900
35917
|
}
|
35901
35918
|
const implicitGenericParameters = implicitGenericParametersParam ?? [];
|
35902
35919
|
args.forEach((a) => {
|
35903
|
-
const argType =
|
35920
|
+
const argType = findTypeById(abi, a.type);
|
35904
35921
|
if (genericRegEx.test(argType.type)) {
|
35905
35922
|
implicitGenericParameters.push(argType.typeId);
|
35906
35923
|
return;
|
@@ -36009,13 +36026,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36009
36026
|
return new ArrayCoder(arrayElementCoder, length);
|
36010
36027
|
}
|
36011
36028
|
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
36012
|
-
const arg =
|
36013
|
-
if (!arg) {
|
36014
|
-
throw new FuelError(
|
36015
|
-
ErrorCode.INVALID_COMPONENT,
|
36016
|
-
`The provided Vec type is missing the 'type argument'.`
|
36017
|
-
);
|
36018
|
-
}
|
36029
|
+
const arg = findVectorBufferArgument(components);
|
36019
36030
|
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
36020
36031
|
const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
|
36021
36032
|
return new VecCoder(itemCoder);
|
@@ -36484,13 +36495,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36484
36495
|
return new ArrayCoder(arrayElementCoder, length);
|
36485
36496
|
}
|
36486
36497
|
if (resolvedAbiType.type === VEC_CODER_TYPE) {
|
36487
|
-
const arg =
|
36488
|
-
if (!arg) {
|
36489
|
-
throw new FuelError(
|
36490
|
-
ErrorCode.INVALID_COMPONENT,
|
36491
|
-
`The provided Vec type is missing the 'type argument'.`
|
36492
|
-
);
|
36493
|
-
}
|
36498
|
+
const arg = findVectorBufferArgument(components);
|
36494
36499
|
const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
|
36495
36500
|
const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
|
36496
36501
|
return new VecCoder2(itemCoder);
|
@@ -36561,7 +36566,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36561
36566
|
jsonAbi;
|
36562
36567
|
constructor(jsonAbi, name) {
|
36563
36568
|
this.jsonAbi = jsonAbi;
|
36564
|
-
this.jsonFn =
|
36569
|
+
this.jsonFn = findFunctionByName(this.jsonAbi, name);
|
36565
36570
|
this.name = name;
|
36566
36571
|
this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
|
36567
36572
|
this.selector = FunctionFragment.getFunctionSelector(this.signature);
|
@@ -36585,13 +36590,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36585
36590
|
return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);
|
36586
36591
|
}
|
36587
36592
|
#isInputDataPointer() {
|
36588
|
-
const inputTypes = this.jsonFn.inputs.map(
|
36589
|
-
(i) => this.jsonAbi.types.find((t) => t.typeId === i.type)
|
36590
|
-
);
|
36593
|
+
const inputTypes = this.jsonFn.inputs.map((i) => findTypeById(this.jsonAbi, i.type));
|
36591
36594
|
return this.jsonFn.inputs.length > 1 || isPointerType(inputTypes[0]?.type || "");
|
36592
36595
|
}
|
36593
36596
|
#isOutputDataHeap() {
|
36594
|
-
const outputType =
|
36597
|
+
const outputType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
|
36595
36598
|
return isHeapType(outputType?.type || "");
|
36596
36599
|
}
|
36597
36600
|
#getOutputEncodedLength() {
|
@@ -36611,9 +36614,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36611
36614
|
encodeArguments(values, offset = 0) {
|
36612
36615
|
FunctionFragment.verifyArgsAndInputsAlign(values, this.jsonFn.inputs, this.jsonAbi);
|
36613
36616
|
const shallowCopyValues = values.slice();
|
36614
|
-
const nonEmptyInputs = this.jsonFn.inputs
|
36615
|
-
(x) => findOrThrow(this.jsonAbi.types, (t) => t.typeId === x.type).type !== "()"
|
36616
|
-
);
|
36617
|
+
const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
|
36617
36618
|
if (Array.isArray(values) && nonEmptyInputs.length !== values.length) {
|
36618
36619
|
shallowCopyValues.length = this.jsonFn.inputs.length;
|
36619
36620
|
shallowCopyValues.fill(void 0, values.length);
|
@@ -36634,7 +36635,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36634
36635
|
if (args.length === inputs.length) {
|
36635
36636
|
return;
|
36636
36637
|
}
|
36637
|
-
const inputTypes = inputs.map((
|
36638
|
+
const inputTypes = inputs.map((input) => findTypeById(abi, input.type));
|
36638
36639
|
const optionalInputs = inputTypes.filter(
|
36639
36640
|
(x) => x.type === OPTION_CODER_TYPE || x.type === "()"
|
36640
36641
|
);
|
@@ -36649,9 +36650,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36649
36650
|
}
|
36650
36651
|
decodeArguments(data) {
|
36651
36652
|
const bytes3 = arrayify(data);
|
36652
|
-
const nonEmptyInputs = this.jsonFn.inputs
|
36653
|
-
(x) => findOrThrow(this.jsonAbi.types, (t) => t.typeId === x.type).type !== "()"
|
36654
|
-
);
|
36653
|
+
const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
|
36655
36654
|
if (nonEmptyInputs.length === 0) {
|
36656
36655
|
if (bytes3.length === 0) {
|
36657
36656
|
return void 0;
|
@@ -36686,10 +36685,7 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36686
36685
|
return result.decoded;
|
36687
36686
|
}
|
36688
36687
|
decodeOutput(data) {
|
36689
|
-
const outputAbiType =
|
36690
|
-
this.jsonAbi.types,
|
36691
|
-
(t) => t.typeId === this.jsonFn.output.type
|
36692
|
-
);
|
36688
|
+
const outputAbiType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
|
36693
36689
|
if (outputAbiType.type === "()") {
|
36694
36690
|
return [void 0, 0];
|
36695
36691
|
}
|
@@ -36699,6 +36695,15 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36699
36695
|
});
|
36700
36696
|
return coder.decode(bytes3, 0);
|
36701
36697
|
}
|
36698
|
+
/**
|
36699
|
+
* Checks if the function is read-only i.e. it only reads from storage, does not write to it.
|
36700
|
+
*
|
36701
|
+
* @returns True if the function is read-only or pure, false otherwise.
|
36702
|
+
*/
|
36703
|
+
isReadOnly() {
|
36704
|
+
const storageAttribute = this.attributes.find((attr) => attr.name === "storage");
|
36705
|
+
return !storageAttribute?.arguments.includes("write");
|
36706
|
+
}
|
36702
36707
|
};
|
36703
36708
|
var Interface = class {
|
36704
36709
|
functions;
|
@@ -36741,38 +36746,33 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
36741
36746
|
return fragment.decodeOutput(data);
|
36742
36747
|
}
|
36743
36748
|
decodeLog(data, logId) {
|
36744
|
-
const
|
36745
|
-
|
36749
|
+
const loggedType = this.jsonAbi.loggedTypes.find((type3) => type3.logId === logId);
|
36750
|
+
if (!loggedType) {
|
36751
|
+
throw new FuelError(
|
36752
|
+
ErrorCode.LOG_TYPE_NOT_FOUND,
|
36753
|
+
`Log type with logId '${logId}' doesn't exist in the ABI.`
|
36754
|
+
);
|
36755
|
+
}
|
36756
|
+
return AbiCoder.decode(this.jsonAbi, loggedType.loggedType, arrayify(data), 0, {
|
36746
36757
|
encoding: this.jsonAbi.encoding
|
36747
36758
|
});
|
36748
36759
|
}
|
36749
36760
|
encodeConfigurable(name, value) {
|
36750
|
-
const configurable =
|
36751
|
-
|
36752
|
-
|
36753
|
-
|
36754
|
-
|
36755
|
-
|
36756
|
-
|
36757
|
-
);
|
36758
|
-
}
|
36759
|
-
);
|
36761
|
+
const configurable = this.jsonAbi.configurables.find((c) => c.name === name);
|
36762
|
+
if (!configurable) {
|
36763
|
+
throw new FuelError(
|
36764
|
+
ErrorCode.CONFIGURABLE_NOT_FOUND,
|
36765
|
+
`A configurable with the '${name}' was not found in the ABI.`
|
36766
|
+
);
|
36767
|
+
}
|
36760
36768
|
return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
|
36761
36769
|
isRightPadded: true,
|
36762
|
-
|
36770
|
+
// TODO: Review support for configurables in v1 encoding when it becomes available
|
36771
|
+
encoding: ENCODING_V0
|
36763
36772
|
});
|
36764
36773
|
}
|
36765
36774
|
getTypeById(typeId) {
|
36766
|
-
return
|
36767
|
-
this.jsonAbi.types,
|
36768
|
-
(t) => t.typeId === typeId,
|
36769
|
-
() => {
|
36770
|
-
throw new FuelError(
|
36771
|
-
ErrorCode.TYPE_NOT_FOUND,
|
36772
|
-
`Type with typeId '${typeId}' doesn't exist in the ABI.`
|
36773
|
-
);
|
36774
|
-
}
|
36775
|
-
);
|
36775
|
+
return findTypeById(this.jsonAbi, typeId);
|
36776
36776
|
}
|
36777
36777
|
};
|
36778
36778
|
|
@@ -42339,8 +42339,8 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
42339
42339
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
42340
42340
|
return {
|
42341
42341
|
type: InputType.Coin,
|
42342
|
-
txID: hexlify(arrayify(value.id).slice(0,
|
42343
|
-
outputIndex: arrayify(value.id)
|
42342
|
+
txID: hexlify(arrayify(value.id).slice(0, BYTES_32)),
|
42343
|
+
outputIndex: toNumber2(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
|
42344
42344
|
owner: hexlify(value.owner),
|
42345
42345
|
amount: bn(value.amount),
|
42346
42346
|
assetId: hexlify(value.assetId),
|
@@ -43163,8 +43163,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
43163
43163
|
assetId,
|
43164
43164
|
txPointer: "0x00000000000000000000000000000000",
|
43165
43165
|
witnessIndex,
|
43166
|
-
predicate: predicate?.bytes
|
43167
|
-
predicateData: predicate?.predicateDataBytes
|
43166
|
+
predicate: predicate?.bytes
|
43168
43167
|
};
|
43169
43168
|
this.pushInput(input);
|
43170
43169
|
this.addChangeOutput(owner, assetId);
|
@@ -43196,8 +43195,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
43196
43195
|
recipient: recipient.toB256(),
|
43197
43196
|
amount,
|
43198
43197
|
witnessIndex,
|
43199
|
-
predicate: predicate?.bytes
|
43200
|
-
predicateData: predicate?.predicateDataBytes
|
43198
|
+
predicate: predicate?.bytes
|
43201
43199
|
};
|
43202
43200
|
this.pushInput(input);
|
43203
43201
|
this.addChangeOutput(recipient, assetId);
|
@@ -43352,12 +43350,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
43352
43350
|
* @param quantities - CoinQuantity Array.
|
43353
43351
|
*/
|
43354
43352
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
43355
|
-
let idCounter = 0;
|
43356
|
-
const generateId = () => {
|
43357
|
-
const counterString = String(idCounter++);
|
43358
|
-
const id = ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
43359
|
-
return id;
|
43360
|
-
};
|
43361
43353
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
43362
43354
|
if ("assetId" in input) {
|
43363
43355
|
return input.assetId === assetId;
|
@@ -43367,12 +43359,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
43367
43359
|
const updateAssetInput = (assetId, quantity) => {
|
43368
43360
|
const assetInput = findAssetInput(assetId);
|
43369
43361
|
if (assetInput && "assetId" in assetInput) {
|
43370
|
-
assetInput.id =
|
43362
|
+
assetInput.id = hexlify(randomBytes22(UTXO_ID_LEN));
|
43371
43363
|
assetInput.amount = quantity;
|
43372
43364
|
} else {
|
43373
43365
|
this.addResources([
|
43374
43366
|
{
|
43375
|
-
id:
|
43367
|
+
id: hexlify(randomBytes22(UTXO_ID_LEN)),
|
43376
43368
|
amount: quantity,
|
43377
43369
|
assetId,
|
43378
43370
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -45151,6 +45143,36 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
45151
45143
|
missingContractIds
|
45152
45144
|
};
|
45153
45145
|
}
|
45146
|
+
/**
|
45147
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
45148
|
+
* @param transactionRequest - The transaction request object.
|
45149
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
45150
|
+
*/
|
45151
|
+
estimateTxGasAndFee(params) {
|
45152
|
+
const { transactionRequest } = params;
|
45153
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
45154
|
+
const chainInfo = this.getChain();
|
45155
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
45156
|
+
transactionRequest.gasPrice = gasPrice;
|
45157
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
45158
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
45159
|
+
if (transactionRequest.type === TransactionType.Script) {
|
45160
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
45161
|
+
transactionRequest.gasLimit = minGas;
|
45162
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
45163
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
45164
|
+
);
|
45165
|
+
}
|
45166
|
+
}
|
45167
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
45168
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
45169
|
+
return {
|
45170
|
+
minGas,
|
45171
|
+
minFee,
|
45172
|
+
maxGas,
|
45173
|
+
maxFee
|
45174
|
+
};
|
45175
|
+
}
|
45154
45176
|
/**
|
45155
45177
|
* Executes a signed transaction without applying the states changes
|
45156
45178
|
* on the chain.
|
@@ -45198,17 +45220,16 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
45198
45220
|
signatureCallback
|
45199
45221
|
} = {}) {
|
45200
45222
|
const txRequestClone = clone_default(transactionRequestify(transactionRequestLike));
|
45201
|
-
const
|
45202
|
-
const
|
45203
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
45223
|
+
const { minGasPrice } = this.getGasConfig();
|
45224
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
45204
45225
|
const isScriptTransaction = txRequestClone.type === TransactionType.Script;
|
45205
45226
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
45206
45227
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
45207
45228
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
45229
|
+
if (isScriptTransaction) {
|
45230
|
+
txRequestClone.gasLimit = bn(0);
|
45231
|
+
}
|
45208
45232
|
if (estimatePredicates) {
|
45209
|
-
if (isScriptTransaction) {
|
45210
|
-
txRequestClone.gasLimit = bn(0);
|
45211
|
-
}
|
45212
45233
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
45213
45234
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
45214
45235
|
}
|
@@ -45217,36 +45238,34 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
45217
45238
|
if (signatureCallback && isScriptTransaction) {
|
45218
45239
|
await signatureCallback(txRequestClone);
|
45219
45240
|
}
|
45220
|
-
|
45221
|
-
|
45241
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
45242
|
+
transactionRequest: txRequestClone
|
45243
|
+
});
|
45222
45244
|
let receipts = [];
|
45223
45245
|
let missingContractIds = [];
|
45224
45246
|
let outputVariables = 0;
|
45247
|
+
let gasUsed = bn(0);
|
45225
45248
|
if (isScriptTransaction && estimateTxDependencies) {
|
45226
45249
|
txRequestClone.gasPrice = bn(0);
|
45227
|
-
txRequestClone.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
45228
45250
|
const result = await this.estimateTxDependencies(txRequestClone);
|
45229
45251
|
receipts = result.receipts;
|
45230
45252
|
outputVariables = result.outputVariables;
|
45231
45253
|
missingContractIds = result.missingContractIds;
|
45254
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
45255
|
+
txRequestClone.gasLimit = gasUsed;
|
45256
|
+
txRequestClone.gasPrice = setGasPrice;
|
45257
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
45258
|
+
transactionRequest: txRequestClone
|
45259
|
+
}));
|
45232
45260
|
}
|
45233
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
45234
|
-
const usedFee = calculatePriceWithFactor(
|
45235
|
-
gasUsed,
|
45236
|
-
gasPrice,
|
45237
|
-
gasPriceFactor
|
45238
|
-
).normalizeZeroToOne();
|
45239
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
45240
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
45241
45261
|
return {
|
45242
45262
|
requiredQuantities: allQuantities,
|
45243
45263
|
receipts,
|
45244
45264
|
gasUsed,
|
45245
45265
|
minGasPrice,
|
45246
|
-
gasPrice,
|
45266
|
+
gasPrice: setGasPrice,
|
45247
45267
|
minGas,
|
45248
45268
|
maxGas,
|
45249
|
-
usedFee,
|
45250
45269
|
minFee,
|
45251
45270
|
maxFee,
|
45252
45271
|
estimatedInputs: txRequestClone.inputs,
|
@@ -47532,12 +47551,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
47532
47551
|
};
|
47533
47552
|
|
47534
47553
|
// ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/rng.js
|
47535
|
-
var
|
47554
|
+
var import_crypto16 = __toESM(__require("crypto"));
|
47536
47555
|
var rnds8Pool = new Uint8Array(256);
|
47537
47556
|
var poolPtr = rnds8Pool.length;
|
47538
47557
|
function rng() {
|
47539
47558
|
if (poolPtr > rnds8Pool.length - 16) {
|
47540
|
-
|
47559
|
+
import_crypto16.default.randomFillSync(rnds8Pool);
|
47541
47560
|
poolPtr = 0;
|
47542
47561
|
}
|
47543
47562
|
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
@@ -47553,9 +47572,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
47553
47572
|
}
|
47554
47573
|
|
47555
47574
|
// ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/native.js
|
47556
|
-
var
|
47575
|
+
var import_crypto17 = __toESM(__require("crypto"));
|
47557
47576
|
var native_default = {
|
47558
|
-
randomUUID:
|
47577
|
+
randomUUID: import_crypto17.default.randomUUID
|
47559
47578
|
};
|
47560
47579
|
|
47561
47580
|
// ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/v4.js
|
@@ -50535,7 +50554,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
50535
50554
|
|
50536
50555
|
// src/test-utils/launchNode.ts
|
50537
50556
|
var import_child_process = __require("child_process");
|
50538
|
-
var
|
50557
|
+
var import_crypto21 = __require("crypto");
|
50539
50558
|
var import_fs2 = __require("fs");
|
50540
50559
|
var import_os = __toESM(__require("os"));
|
50541
50560
|
var import_path8 = __toESM(__require("path"));
|
@@ -50607,7 +50626,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
50607
50626
|
})).toString();
|
50608
50627
|
let chainConfigPathToUse;
|
50609
50628
|
const prefix = basePath || import_os.default.tmpdir();
|
50610
|
-
const suffix = basePath ? "" : (0,
|
50629
|
+
const suffix = basePath ? "" : (0, import_crypto21.randomUUID)();
|
50611
50630
|
const tempDirPath = import_path8.default.join(prefix, ".fuels", suffix);
|
50612
50631
|
if (chainConfigPath) {
|
50613
50632
|
chainConfigPathToUse = chainConfigPath;
|