@fuel-ts/account 0.0.0-rc-2037-20240430170043 → 0.0.0-rc-2037-20240501112942
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 +1 -1
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +96 -49
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +226 -176
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +229 -180
- package/dist/index.mjs.map +1 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/resource.d.ts +0 -1
- package/dist/providers/resource.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +4 -2
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +3 -3
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +1 -1
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils.global.js +91 -44
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +216 -168
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +226 -178
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -15
package/dist/account.d.ts
CHANGED
@@ -84,7 +84,7 @@ export declare class Account extends AbstractAccount {
|
|
84
84
|
* Adds resources to the transaction enough to fund it.
|
85
85
|
*
|
86
86
|
* @param request - The transaction request.
|
87
|
-
* @param
|
87
|
+
* @param requiredQuantities - The coin quantities required to execute the transaction.
|
88
88
|
* @param fee - The estimated transaction fee.
|
89
89
|
* @returns A promise that resolves when the resources are added to the transaction.
|
90
90
|
*/
|
package/dist/account.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAKtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,sBAAsB,EACtB,UAAU,EACV,kBAAkB,EAClB,IAAI,EACJ,gBAAgB,EAChB,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,sBAAsB,EACtB,QAAQ,EACR,4BAA4B,EAC5B,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,eAAe,EAChB,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAKtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,sBAAsB,EACtB,UAAU,EACV,kBAAkB,EAClB,IAAI,EACJ,gBAAgB,EAChB,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,sBAAsB,EACtB,QAAQ,EACR,4BAA4B,EAC5B,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,eAAe,EAChB,MAAM,aAAa,CAAC;AAerB,MAAM,MAAM,YAAY,GAAG,IAAI,CAC7B,4BAA4B,EAC5B,UAAU,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,GAAG,cAAc,CAC5D,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,IAAI,C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CACvB,sBAAsB,EAAE,sBAAsB,EAC9C,EAAE,sBAA6B,EAAE,GAAE,yBAA8B,GAChE,OAAO,CAAC,UAAU,CAAC;IAQtB,OAAO,CAAC,yBAAyB;CAuBlC"}
|
package/dist/index.global.js
CHANGED
@@ -38645,7 +38645,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
38645
38645
|
}
|
38646
38646
|
var calculateGasFee = (params) => {
|
38647
38647
|
const { gas, gasPrice, priceFactor, tip } = params;
|
38648
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
38648
|
+
return gas.mul(gasPrice).div(priceFactor).add(bn(tip));
|
38649
38649
|
};
|
38650
38650
|
|
38651
38651
|
// src/providers/utils/json.ts
|
@@ -38782,12 +38782,21 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
38782
38782
|
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
38783
38783
|
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
38784
38784
|
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
38785
|
-
var
|
38786
|
-
(
|
38787
|
-
|
38788
|
-
|
38785
|
+
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
38786
|
+
if (isRequestInputCoin(input) && input.assetId === assetId) {
|
38787
|
+
return acc.add(input.amount);
|
38788
|
+
}
|
38789
|
+
if (isRequestInputMessage(input) && assetId === baseAsset) {
|
38790
|
+
return acc.add(input.amount);
|
38791
|
+
}
|
38792
|
+
return acc;
|
38793
|
+
}, bn(0));
|
38794
|
+
var cacheRequestInputsResources = (inputs) => inputs.filter(isRequestInputResource).reduce(
|
38795
|
+
(cache2, input) => {
|
38796
|
+
if (isRequestInputCoin(input)) {
|
38797
|
+
cache2.utxos.push(input.id);
|
38789
38798
|
} else {
|
38790
|
-
cache2.messages.push(
|
38799
|
+
cache2.messages.push(input.nonce);
|
38791
38800
|
}
|
38792
38801
|
return cache2;
|
38793
38802
|
},
|
@@ -38796,6 +38805,20 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
38796
38805
|
messages: []
|
38797
38806
|
}
|
38798
38807
|
);
|
38808
|
+
var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
|
38809
|
+
(acc, input) => {
|
38810
|
+
if (isRequestInputCoin(input) && input.owner === owner.toB256()) {
|
38811
|
+
acc.utxos.push(input.id);
|
38812
|
+
} else if (isRequestInputMessage(input) && input.recipient === owner.toB256()) {
|
38813
|
+
acc.messages.push(input.nonce);
|
38814
|
+
}
|
38815
|
+
return acc;
|
38816
|
+
},
|
38817
|
+
{
|
38818
|
+
utxos: [],
|
38819
|
+
messages: []
|
38820
|
+
}
|
38821
|
+
);
|
38799
38822
|
|
38800
38823
|
// src/providers/transaction-request/witness.ts
|
38801
38824
|
var witnessify = (value) => {
|
@@ -38836,10 +38859,10 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
38836
38859
|
outputs,
|
38837
38860
|
witnesses
|
38838
38861
|
} = {}) {
|
38839
|
-
this.tip = bn(tip);
|
38840
|
-
this.maturity = maturity
|
38841
|
-
this.witnessLimit = witnessLimit ? bn(witnessLimit) : void 0;
|
38842
|
-
this.maxFee =
|
38862
|
+
this.tip = tip ? bn(tip) : void 0;
|
38863
|
+
this.maturity = maturity && maturity > 0 ? maturity : void 0;
|
38864
|
+
this.witnessLimit = isDefined(witnessLimit) ? bn(witnessLimit) : void 0;
|
38865
|
+
this.maxFee = bn(maxFee);
|
38843
38866
|
this.inputs = inputs ?? [];
|
38844
38867
|
this.outputs = outputs ?? [];
|
38845
38868
|
this.witnesses = witnesses ?? [];
|
@@ -38847,22 +38870,21 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
38847
38870
|
static getPolicyMeta(req) {
|
38848
38871
|
let policyTypes = 0;
|
38849
38872
|
const policies = [];
|
38850
|
-
|
38873
|
+
const { tip, witnessLimit, maturity } = req;
|
38874
|
+
if (bn(tip).gt(0)) {
|
38851
38875
|
policyTypes += PolicyType.Tip;
|
38852
|
-
policies.push({ data:
|
38876
|
+
policies.push({ data: bn(tip), type: PolicyType.Tip });
|
38853
38877
|
}
|
38854
|
-
if (
|
38878
|
+
if (isDefined(witnessLimit) && bn(witnessLimit).gte(0)) {
|
38855
38879
|
policyTypes += PolicyType.WitnessLimit;
|
38856
|
-
policies.push({ data:
|
38880
|
+
policies.push({ data: bn(witnessLimit), type: PolicyType.WitnessLimit });
|
38857
38881
|
}
|
38858
|
-
if (
|
38882
|
+
if (maturity && maturity > 0) {
|
38859
38883
|
policyTypes += PolicyType.Maturity;
|
38860
|
-
policies.push({ data:
|
38861
|
-
}
|
38862
|
-
if (req.maxFee) {
|
38863
|
-
policyTypes += PolicyType.MaxFee;
|
38864
|
-
policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
|
38884
|
+
policies.push({ data: maturity, type: PolicyType.Maturity });
|
38865
38885
|
}
|
38886
|
+
policyTypes += PolicyType.MaxFee;
|
38887
|
+
policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
|
38866
38888
|
return {
|
38867
38889
|
policyTypes,
|
38868
38890
|
policies
|
@@ -39700,21 +39722,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
39700
39722
|
}
|
39701
39723
|
}
|
39702
39724
|
};
|
39703
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
39704
|
-
(acc, input) => {
|
39705
|
-
if (input.type === InputType.Coin && input.owner === owner) {
|
39706
|
-
acc.utxos.push(input.id);
|
39707
|
-
}
|
39708
|
-
if (input.type === InputType.Message && input.recipient === owner) {
|
39709
|
-
acc.messages.push(input.nonce);
|
39710
|
-
}
|
39711
|
-
return acc;
|
39712
|
-
},
|
39713
|
-
{
|
39714
|
-
utxos: [],
|
39715
|
-
messages: []
|
39716
|
-
}
|
39717
|
-
);
|
39718
39725
|
|
39719
39726
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
39720
39727
|
var calculateTransactionFee = (params) => {
|
@@ -40861,7 +40868,18 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
40861
40868
|
createOperations() {
|
40862
40869
|
const fetchFn = _Provider.getFetchFn(this.options);
|
40863
40870
|
const gqlClient = new import_graphql_request.GraphQLClient(this.url, {
|
40864
|
-
fetch: (url, requestInit) => fetchFn(url, requestInit, this.options)
|
40871
|
+
fetch: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
40872
|
+
responseMiddleware: (response) => {
|
40873
|
+
if ("response" in response) {
|
40874
|
+
const graphQlResponse = response.response;
|
40875
|
+
if (Array.isArray(graphQlResponse?.errors)) {
|
40876
|
+
throw new FuelError(
|
40877
|
+
FuelError.CODES.INVALID_REQUEST,
|
40878
|
+
graphQlResponse.errors.map((err) => err.message).join("\n\n")
|
40879
|
+
);
|
40880
|
+
}
|
40881
|
+
}
|
40882
|
+
}
|
40865
40883
|
});
|
40866
40884
|
const executeQuery = (query, vars) => {
|
40867
40885
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
@@ -42032,6 +42050,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
42032
42050
|
};
|
42033
42051
|
|
42034
42052
|
// src/account.ts
|
42053
|
+
var MAX_FUNDING_ATTEMPTS = 2;
|
42035
42054
|
var Account = class extends AbstractAccount {
|
42036
42055
|
/**
|
42037
42056
|
* The address associated with the account.
|
@@ -42189,13 +42208,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
42189
42208
|
* Adds resources to the transaction enough to fund it.
|
42190
42209
|
*
|
42191
42210
|
* @param request - The transaction request.
|
42192
|
-
* @param
|
42211
|
+
* @param requiredQuantities - The coin quantities required to execute the transaction.
|
42193
42212
|
* @param fee - The estimated transaction fee.
|
42194
42213
|
* @returns A promise that resolves when the resources are added to the transaction.
|
42195
42214
|
*/
|
42196
42215
|
async fund(request, params) {
|
42197
42216
|
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
42198
42217
|
const baseAssetId = this.provider.getBaseAssetId();
|
42218
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn(0);
|
42199
42219
|
const txRequest = request;
|
42200
42220
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
42201
42221
|
amount: bn(fee),
|
@@ -42209,18 +42229,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
42209
42229
|
owned: bn(0)
|
42210
42230
|
};
|
42211
42231
|
});
|
42212
|
-
|
42213
|
-
const
|
42214
|
-
if (!isResource) {
|
42215
|
-
return;
|
42216
|
-
}
|
42217
|
-
const isCoin2 = "owner" in input;
|
42232
|
+
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
42233
|
+
const isCoin2 = isRequestInputCoin(input);
|
42218
42234
|
const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
|
42219
42235
|
if (quantitiesDict[assetId]) {
|
42220
42236
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
|
42221
42237
|
}
|
42222
42238
|
});
|
42223
|
-
|
42239
|
+
let missingQuantities = [];
|
42224
42240
|
Object.entries(quantitiesDict).forEach(([assetId, { owned, required }]) => {
|
42225
42241
|
if (owned.lt(required)) {
|
42226
42242
|
missingQuantities.push({
|
@@ -42229,11 +42245,42 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
42229
42245
|
});
|
42230
42246
|
}
|
42231
42247
|
});
|
42232
|
-
|
42233
|
-
|
42234
|
-
|
42235
|
-
const resources = await this.getResourcesToSpend(
|
42236
|
-
|
42248
|
+
let needsToBeFunded = missingQuantities.length > 0;
|
42249
|
+
let fundingAttempts = 0;
|
42250
|
+
while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
|
42251
|
+
const resources = await this.getResourcesToSpend(
|
42252
|
+
missingQuantities,
|
42253
|
+
cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
|
42254
|
+
);
|
42255
|
+
request.addResources(resources);
|
42256
|
+
txRequest.shiftPredicateData();
|
42257
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
42258
|
+
const requestToReestimate2 = clone_default(txRequest);
|
42259
|
+
if (addedSignatures) {
|
42260
|
+
Array.from({ length: addedSignatures }).forEach(
|
42261
|
+
() => requestToReestimate2.addEmptyWitness()
|
42262
|
+
);
|
42263
|
+
}
|
42264
|
+
const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
|
42265
|
+
transactionRequest: requestToReestimate2
|
42266
|
+
});
|
42267
|
+
const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
|
42268
|
+
request.inputs,
|
42269
|
+
baseAssetId,
|
42270
|
+
baseAssetId
|
42271
|
+
);
|
42272
|
+
const totalBaseAssetRequiredWithFee = requiredInBaseAsset.add(newFee);
|
42273
|
+
if (totalBaseAssetOnInputs.gt(totalBaseAssetRequiredWithFee)) {
|
42274
|
+
needsToBeFunded = false;
|
42275
|
+
} else {
|
42276
|
+
missingQuantities = [
|
42277
|
+
{
|
42278
|
+
amount: totalBaseAssetRequiredWithFee.sub(totalBaseAssetOnInputs),
|
42279
|
+
assetId: baseAssetId
|
42280
|
+
}
|
42281
|
+
];
|
42282
|
+
}
|
42283
|
+
fundingAttempts += 1;
|
42237
42284
|
}
|
42238
42285
|
txRequest.shiftPredicateData();
|
42239
42286
|
txRequest.updatePredicateGasUsed(estimatedPredicates);
|