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.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(src_exports, {
|
|
|
33
33
|
ContractInterface: () => ContractInterface,
|
|
34
34
|
GatewayError: () => GatewayError,
|
|
35
35
|
HttpError: () => HttpError,
|
|
36
|
+
LibraryError: () => LibraryError,
|
|
36
37
|
Provider: () => Provider,
|
|
37
38
|
ProviderInterface: () => ProviderInterface,
|
|
38
39
|
RpcProvider: () => RpcProvider,
|
|
@@ -2652,6 +2653,23 @@ var RPCResponseParser = class {
|
|
|
2652
2653
|
}
|
|
2653
2654
|
};
|
|
2654
2655
|
|
|
2656
|
+
// src/provider/errors.ts
|
|
2657
|
+
var import_ts_custom_error = require("ts-custom-error");
|
|
2658
|
+
var LibraryError = class extends import_ts_custom_error.CustomError {
|
|
2659
|
+
};
|
|
2660
|
+
var GatewayError = class extends LibraryError {
|
|
2661
|
+
constructor(message, errorCode) {
|
|
2662
|
+
super(message);
|
|
2663
|
+
this.errorCode = errorCode;
|
|
2664
|
+
}
|
|
2665
|
+
};
|
|
2666
|
+
var HttpError = class extends LibraryError {
|
|
2667
|
+
constructor(message, errorCode) {
|
|
2668
|
+
super(message);
|
|
2669
|
+
this.errorCode = errorCode;
|
|
2670
|
+
}
|
|
2671
|
+
};
|
|
2672
|
+
|
|
2655
2673
|
// src/provider/utils.ts
|
|
2656
2674
|
var import_bn2 = require("bn.js");
|
|
2657
2675
|
var validBlockTags = ["latest", "pending"];
|
|
@@ -2728,7 +2746,7 @@ var RpcProvider = class {
|
|
|
2728
2746
|
errorHandler(error) {
|
|
2729
2747
|
if (error) {
|
|
2730
2748
|
const { code, message } = error;
|
|
2731
|
-
throw new
|
|
2749
|
+
throw new LibraryError(`${code}: ${message}`);
|
|
2732
2750
|
}
|
|
2733
2751
|
}
|
|
2734
2752
|
async fetchEndpoint(method, params) {
|
|
@@ -2990,6 +3008,9 @@ var RpcProvider = class {
|
|
|
2990
3008
|
async getEvents(eventFilter) {
|
|
2991
3009
|
return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
|
|
2992
3010
|
}
|
|
3011
|
+
async getSimulateTransaction(_invocation, _invocationDetails, _blockIdentifier) {
|
|
3012
|
+
throw new Error("RPC does not implement simulateTransaction function");
|
|
3013
|
+
}
|
|
2993
3014
|
};
|
|
2994
3015
|
|
|
2995
3016
|
// src/provider/sequencer.ts
|
|
@@ -3083,6 +3104,31 @@ var SequencerAPIResponseParser = class extends ResponseParser {
|
|
|
3083
3104
|
};
|
|
3084
3105
|
});
|
|
3085
3106
|
}
|
|
3107
|
+
parseFeeSimulateTransactionResponse(res) {
|
|
3108
|
+
if ("overall_fee" in res.fee_estimation) {
|
|
3109
|
+
let gasInfo = {};
|
|
3110
|
+
try {
|
|
3111
|
+
gasInfo = {
|
|
3112
|
+
gas_consumed: toBN(res.fee_estimation.gas_usage),
|
|
3113
|
+
gas_price: toBN(res.fee_estimation.gas_price)
|
|
3114
|
+
};
|
|
3115
|
+
} catch {
|
|
3116
|
+
}
|
|
3117
|
+
return {
|
|
3118
|
+
trace: res.trace,
|
|
3119
|
+
fee_estimation: {
|
|
3120
|
+
...gasInfo,
|
|
3121
|
+
overall_fee: toBN(res.fee_estimation.overall_fee)
|
|
3122
|
+
}
|
|
3123
|
+
};
|
|
3124
|
+
}
|
|
3125
|
+
return {
|
|
3126
|
+
trace: res.trace,
|
|
3127
|
+
fee_estimation: {
|
|
3128
|
+
overall_fee: toBN(res.fee_estimation.amount)
|
|
3129
|
+
}
|
|
3130
|
+
};
|
|
3131
|
+
}
|
|
3086
3132
|
parseCallContractResponse(res) {
|
|
3087
3133
|
return {
|
|
3088
3134
|
result: res.result
|
|
@@ -3136,21 +3182,6 @@ function buildUrl(baseUrl, defaultPath, urlOrPath) {
|
|
|
3136
3182
|
return isUrl(urlOrPath) ? urlOrPath : (0, import_url_join.default)(baseUrl, urlOrPath ?? defaultPath);
|
|
3137
3183
|
}
|
|
3138
3184
|
|
|
3139
|
-
// src/provider/errors.ts
|
|
3140
|
-
var import_ts_custom_error = require("ts-custom-error");
|
|
3141
|
-
var GatewayError = class extends import_ts_custom_error.CustomError {
|
|
3142
|
-
constructor(message, errorCode) {
|
|
3143
|
-
super(message);
|
|
3144
|
-
this.errorCode = errorCode;
|
|
3145
|
-
}
|
|
3146
|
-
};
|
|
3147
|
-
var HttpError = class extends import_ts_custom_error.CustomError {
|
|
3148
|
-
constructor(message, errorCode) {
|
|
3149
|
-
super(message);
|
|
3150
|
-
this.errorCode = errorCode;
|
|
3151
|
-
}
|
|
3152
|
-
};
|
|
3153
|
-
|
|
3154
3185
|
// src/provider/sequencer.ts
|
|
3155
3186
|
function isEmptyQueryObject(obj) {
|
|
3156
3187
|
return obj === void 0 || Object.keys(obj).length === 0 || Object.keys(obj).length === 1 && Object.entries(obj).every(([k, v]) => k === "blockIdentifier" && v === null);
|
|
@@ -3317,9 +3348,11 @@ var SequencerProvider = class {
|
|
|
3317
3348
|
}
|
|
3318
3349
|
async getTransaction(txHash) {
|
|
3319
3350
|
const txHashHex = toHex(toBN(txHash));
|
|
3320
|
-
return this.fetchEndpoint("get_transaction", { transactionHash: txHashHex }).then(
|
|
3321
|
-
(
|
|
3322
|
-
|
|
3351
|
+
return this.fetchEndpoint("get_transaction", { transactionHash: txHashHex }).then((result) => {
|
|
3352
|
+
if (Object.values(result).length === 1)
|
|
3353
|
+
throw new LibraryError(result.status);
|
|
3354
|
+
return this.responseParser.parseGetTransactionResponse(result);
|
|
3355
|
+
});
|
|
3323
3356
|
}
|
|
3324
3357
|
async getTransactionReceipt(txHash) {
|
|
3325
3358
|
const txHashHex = toHex(toBN(txHash));
|
|
@@ -3497,7 +3530,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
3497
3530
|
};
|
|
3498
3531
|
return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
|
|
3499
3532
|
}
|
|
3500
|
-
async
|
|
3533
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
3501
3534
|
return this.fetchEndpoint(
|
|
3502
3535
|
"simulate_transaction",
|
|
3503
3536
|
{ blockIdentifier },
|
|
@@ -3509,7 +3542,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
3509
3542
|
version: toHex(toBN((invocationDetails == null ? void 0 : invocationDetails.version) || 1)),
|
|
3510
3543
|
nonce: toHex(toBN(invocationDetails.nonce))
|
|
3511
3544
|
}
|
|
3512
|
-
);
|
|
3545
|
+
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
3513
3546
|
}
|
|
3514
3547
|
};
|
|
3515
3548
|
|
|
@@ -3595,6 +3628,9 @@ var Provider = class {
|
|
|
3595
3628
|
async waitForTransaction(txHash, retryInterval, successStates) {
|
|
3596
3629
|
return this.provider.waitForTransaction(txHash, retryInterval, successStates);
|
|
3597
3630
|
}
|
|
3631
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier) {
|
|
3632
|
+
return this.provider.getSimulateTransaction(invocation, invocationDetails, blockIdentifier);
|
|
3633
|
+
}
|
|
3598
3634
|
};
|
|
3599
3635
|
|
|
3600
3636
|
// src/provider/interface.ts
|
|
@@ -4999,6 +5035,33 @@ var Account = class extends Provider {
|
|
|
4999
5035
|
});
|
|
5000
5036
|
return calls;
|
|
5001
5037
|
}
|
|
5038
|
+
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
5039
|
+
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
5040
|
+
const nonce = toBN(providedNonce ?? await this.getNonce());
|
|
5041
|
+
const version = toBN(feeTransactionVersion);
|
|
5042
|
+
const chainId = await this.getChainId();
|
|
5043
|
+
const signerDetails = {
|
|
5044
|
+
walletAddress: this.address,
|
|
5045
|
+
nonce,
|
|
5046
|
+
maxFee: ZERO,
|
|
5047
|
+
version,
|
|
5048
|
+
chainId
|
|
5049
|
+
};
|
|
5050
|
+
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
5051
|
+
const response = await super.getSimulateTransaction(
|
|
5052
|
+
invocation,
|
|
5053
|
+
{ version, nonce },
|
|
5054
|
+
blockIdentifier
|
|
5055
|
+
);
|
|
5056
|
+
const suggestedMaxFee = estimatedFeeToMaxFee(response.fee_estimation.overall_fee);
|
|
5057
|
+
return {
|
|
5058
|
+
...response,
|
|
5059
|
+
fee_estimation: {
|
|
5060
|
+
...response.fee_estimation,
|
|
5061
|
+
suggestedMaxFee
|
|
5062
|
+
}
|
|
5063
|
+
};
|
|
5064
|
+
}
|
|
5002
5065
|
};
|
|
5003
5066
|
|
|
5004
5067
|
// src/account/interface.ts
|
|
@@ -5070,6 +5133,7 @@ function validateChecksumAddress(address) {
|
|
|
5070
5133
|
ContractInterface,
|
|
5071
5134
|
GatewayError,
|
|
5072
5135
|
HttpError,
|
|
5136
|
+
LibraryError,
|
|
5073
5137
|
Provider,
|
|
5074
5138
|
ProviderInterface,
|
|
5075
5139
|
RpcProvider,
|