starknet 4.19.1 → 4.19.3
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.
- package/CHANGELOG.md +13 -0
- package/dist/index.d.ts +175 -137
- package/dist/index.global.js +558 -372
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +85 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2595,6 +2595,23 @@ var RPCResponseParser = class {
|
|
|
2595
2595
|
}
|
|
2596
2596
|
};
|
|
2597
2597
|
|
|
2598
|
+
// src/provider/errors.ts
|
|
2599
|
+
import { CustomError } from "ts-custom-error";
|
|
2600
|
+
var LibraryError = class extends CustomError {
|
|
2601
|
+
};
|
|
2602
|
+
var GatewayError = class extends LibraryError {
|
|
2603
|
+
constructor(message, errorCode) {
|
|
2604
|
+
super(message);
|
|
2605
|
+
this.errorCode = errorCode;
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
var HttpError = class extends LibraryError {
|
|
2609
|
+
constructor(message, errorCode) {
|
|
2610
|
+
super(message);
|
|
2611
|
+
this.errorCode = errorCode;
|
|
2612
|
+
}
|
|
2613
|
+
};
|
|
2614
|
+
|
|
2598
2615
|
// src/provider/utils.ts
|
|
2599
2616
|
import { BN as BN2 } from "bn.js";
|
|
2600
2617
|
var validBlockTags = ["latest", "pending"];
|
|
@@ -2671,7 +2688,7 @@ var RpcProvider = class {
|
|
|
2671
2688
|
errorHandler(error) {
|
|
2672
2689
|
if (error) {
|
|
2673
2690
|
const { code, message } = error;
|
|
2674
|
-
throw new
|
|
2691
|
+
throw new LibraryError(`${code}: ${message}`);
|
|
2675
2692
|
}
|
|
2676
2693
|
}
|
|
2677
2694
|
async fetchEndpoint(method, params) {
|
|
@@ -2933,6 +2950,9 @@ var RpcProvider = class {
|
|
|
2933
2950
|
async getEvents(eventFilter) {
|
|
2934
2951
|
return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
|
|
2935
2952
|
}
|
|
2953
|
+
async getSimulateTransaction(_invocation, _invocationDetails, _blockIdentifier) {
|
|
2954
|
+
throw new Error("RPC does not implement simulateTransaction function");
|
|
2955
|
+
}
|
|
2936
2956
|
};
|
|
2937
2957
|
|
|
2938
2958
|
// src/provider/sequencer.ts
|
|
@@ -3026,6 +3046,31 @@ var SequencerAPIResponseParser = class extends ResponseParser {
|
|
|
3026
3046
|
};
|
|
3027
3047
|
});
|
|
3028
3048
|
}
|
|
3049
|
+
parseFeeSimulateTransactionResponse(res) {
|
|
3050
|
+
if ("overall_fee" in res.fee_estimation) {
|
|
3051
|
+
let gasInfo = {};
|
|
3052
|
+
try {
|
|
3053
|
+
gasInfo = {
|
|
3054
|
+
gas_consumed: toBN(res.fee_estimation.gas_usage),
|
|
3055
|
+
gas_price: toBN(res.fee_estimation.gas_price)
|
|
3056
|
+
};
|
|
3057
|
+
} catch {
|
|
3058
|
+
}
|
|
3059
|
+
return {
|
|
3060
|
+
trace: res.trace,
|
|
3061
|
+
fee_estimation: {
|
|
3062
|
+
...gasInfo,
|
|
3063
|
+
overall_fee: toBN(res.fee_estimation.overall_fee)
|
|
3064
|
+
}
|
|
3065
|
+
};
|
|
3066
|
+
}
|
|
3067
|
+
return {
|
|
3068
|
+
trace: res.trace,
|
|
3069
|
+
fee_estimation: {
|
|
3070
|
+
overall_fee: toBN(res.fee_estimation.amount)
|
|
3071
|
+
}
|
|
3072
|
+
};
|
|
3073
|
+
}
|
|
3029
3074
|
parseCallContractResponse(res) {
|
|
3030
3075
|
return {
|
|
3031
3076
|
result: res.result
|
|
@@ -3079,21 +3124,6 @@ function buildUrl(baseUrl, defaultPath, urlOrPath) {
|
|
|
3079
3124
|
return isUrl(urlOrPath) ? urlOrPath : urljoin(baseUrl, urlOrPath ?? defaultPath);
|
|
3080
3125
|
}
|
|
3081
3126
|
|
|
3082
|
-
// src/provider/errors.ts
|
|
3083
|
-
import { CustomError } from "ts-custom-error";
|
|
3084
|
-
var GatewayError = class extends CustomError {
|
|
3085
|
-
constructor(message, errorCode) {
|
|
3086
|
-
super(message);
|
|
3087
|
-
this.errorCode = errorCode;
|
|
3088
|
-
}
|
|
3089
|
-
};
|
|
3090
|
-
var HttpError = class extends CustomError {
|
|
3091
|
-
constructor(message, errorCode) {
|
|
3092
|
-
super(message);
|
|
3093
|
-
this.errorCode = errorCode;
|
|
3094
|
-
}
|
|
3095
|
-
};
|
|
3096
|
-
|
|
3097
3127
|
// src/provider/sequencer.ts
|
|
3098
3128
|
function isEmptyQueryObject(obj) {
|
|
3099
3129
|
return obj === void 0 || Object.keys(obj).length === 0 || Object.keys(obj).length === 1 && Object.entries(obj).every(([k, v]) => k === "blockIdentifier" && v === null);
|
|
@@ -3260,9 +3290,11 @@ var SequencerProvider = class {
|
|
|
3260
3290
|
}
|
|
3261
3291
|
async getTransaction(txHash) {
|
|
3262
3292
|
const txHashHex = toHex(toBN(txHash));
|
|
3263
|
-
return this.fetchEndpoint("get_transaction", { transactionHash: txHashHex }).then(
|
|
3264
|
-
(
|
|
3265
|
-
|
|
3293
|
+
return this.fetchEndpoint("get_transaction", { transactionHash: txHashHex }).then((result) => {
|
|
3294
|
+
if (Object.values(result).length === 1)
|
|
3295
|
+
throw new LibraryError(result.status);
|
|
3296
|
+
return this.responseParser.parseGetTransactionResponse(result);
|
|
3297
|
+
});
|
|
3266
3298
|
}
|
|
3267
3299
|
async getTransactionReceipt(txHash) {
|
|
3268
3300
|
const txHashHex = toHex(toBN(txHash));
|
|
@@ -3440,7 +3472,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
3440
3472
|
};
|
|
3441
3473
|
return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
|
|
3442
3474
|
}
|
|
3443
|
-
async
|
|
3475
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
3444
3476
|
return this.fetchEndpoint(
|
|
3445
3477
|
"simulate_transaction",
|
|
3446
3478
|
{ blockIdentifier },
|
|
@@ -3452,7 +3484,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
3452
3484
|
version: toHex(toBN((invocationDetails == null ? void 0 : invocationDetails.version) || 1)),
|
|
3453
3485
|
nonce: toHex(toBN(invocationDetails.nonce))
|
|
3454
3486
|
}
|
|
3455
|
-
);
|
|
3487
|
+
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
3456
3488
|
}
|
|
3457
3489
|
};
|
|
3458
3490
|
|
|
@@ -3538,6 +3570,9 @@ var Provider = class {
|
|
|
3538
3570
|
async waitForTransaction(txHash, retryInterval, successStates) {
|
|
3539
3571
|
return this.provider.waitForTransaction(txHash, retryInterval, successStates);
|
|
3540
3572
|
}
|
|
3573
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier) {
|
|
3574
|
+
return this.provider.getSimulateTransaction(invocation, invocationDetails, blockIdentifier);
|
|
3575
|
+
}
|
|
3541
3576
|
};
|
|
3542
3577
|
|
|
3543
3578
|
// src/provider/interface.ts
|
|
@@ -4942,6 +4977,33 @@ var Account = class extends Provider {
|
|
|
4942
4977
|
});
|
|
4943
4978
|
return calls;
|
|
4944
4979
|
}
|
|
4980
|
+
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
4981
|
+
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
4982
|
+
const nonce = toBN(providedNonce ?? await this.getNonce());
|
|
4983
|
+
const version = toBN(feeTransactionVersion);
|
|
4984
|
+
const chainId = await this.getChainId();
|
|
4985
|
+
const signerDetails = {
|
|
4986
|
+
walletAddress: this.address,
|
|
4987
|
+
nonce,
|
|
4988
|
+
maxFee: ZERO,
|
|
4989
|
+
version,
|
|
4990
|
+
chainId
|
|
4991
|
+
};
|
|
4992
|
+
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
4993
|
+
const response = await super.getSimulateTransaction(
|
|
4994
|
+
invocation,
|
|
4995
|
+
{ version, nonce },
|
|
4996
|
+
blockIdentifier
|
|
4997
|
+
);
|
|
4998
|
+
const suggestedMaxFee = estimatedFeeToMaxFee(response.fee_estimation.overall_fee);
|
|
4999
|
+
return {
|
|
5000
|
+
...response,
|
|
5001
|
+
fee_estimation: {
|
|
5002
|
+
...response.fee_estimation,
|
|
5003
|
+
suggestedMaxFee
|
|
5004
|
+
}
|
|
5005
|
+
};
|
|
5006
|
+
}
|
|
4945
5007
|
};
|
|
4946
5008
|
|
|
4947
5009
|
// src/account/interface.ts
|
|
@@ -5012,6 +5074,7 @@ export {
|
|
|
5012
5074
|
ContractInterface,
|
|
5013
5075
|
GatewayError,
|
|
5014
5076
|
HttpError,
|
|
5077
|
+
LibraryError,
|
|
5015
5078
|
Provider,
|
|
5016
5079
|
ProviderInterface,
|
|
5017
5080
|
RpcProvider,
|