starknet 5.2.0 → 5.4.0
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 +23 -0
- package/README.md +2 -5
- package/dist/index.d.ts +1187 -1010
- package/dist/index.global.js +1132 -2840
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +326 -204
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +324 -204
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -5
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,15 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
// src/types/lib.ts
|
|
7
|
+
// src/types/lib/contract/index.ts
|
|
8
|
+
var EntryPointType = /* @__PURE__ */ ((EntryPointType2) => {
|
|
9
|
+
EntryPointType2["EXTERNAL"] = "EXTERNAL";
|
|
10
|
+
EntryPointType2["L1_HANDLER"] = "L1_HANDLER";
|
|
11
|
+
EntryPointType2["CONSTRUCTOR"] = "CONSTRUCTOR";
|
|
12
|
+
return EntryPointType2;
|
|
13
|
+
})(EntryPointType || {});
|
|
14
|
+
|
|
15
|
+
// src/types/lib/index.ts
|
|
8
16
|
var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
|
9
17
|
TransactionStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
|
|
10
18
|
TransactionStatus2["RECEIVED"] = "RECEIVED";
|
|
@@ -52,20 +60,19 @@ __export(hash_exports, {
|
|
|
52
60
|
computeContractClassHash: () => computeContractClassHash,
|
|
53
61
|
computeHashOnElements: () => computeHashOnElements,
|
|
54
62
|
computeLegacyContractClassHash: () => computeLegacyContractClassHash,
|
|
55
|
-
|
|
63
|
+
computeSierraContractClassHash: () => computeSierraContractClassHash,
|
|
56
64
|
default: () => computeHintedClassHash,
|
|
57
65
|
feeTransactionVersion: () => feeTransactionVersion,
|
|
66
|
+
formatSpaces: () => formatSpaces,
|
|
58
67
|
getSelector: () => getSelector,
|
|
59
68
|
getSelectorFromName: () => getSelectorFromName,
|
|
60
69
|
keccakBn: () => keccakBn,
|
|
61
70
|
poseidon: () => poseidon,
|
|
62
71
|
starknetKeccak: () => starknetKeccak,
|
|
63
|
-
transactionVersion: () => transactionVersion
|
|
72
|
+
transactionVersion: () => transactionVersion,
|
|
73
|
+
transactionVersion_2: () => transactionVersion_2
|
|
64
74
|
});
|
|
65
|
-
import {
|
|
66
|
-
import { hexToBytes } from "ethereum-cryptography/utils.js";
|
|
67
|
-
import { sort } from "json-keys-sort";
|
|
68
|
-
import { poseidonHashMany } from "micro-starknet";
|
|
75
|
+
import { keccak, poseidonHashMany } from "micro-starknet";
|
|
69
76
|
|
|
70
77
|
// src/constants.ts
|
|
71
78
|
var constants_exports = {};
|
|
@@ -2232,6 +2239,7 @@ __export(num_exports, {
|
|
|
2232
2239
|
getDecimalString: () => getDecimalString,
|
|
2233
2240
|
getHexString: () => getHexString,
|
|
2234
2241
|
getHexStringArray: () => getHexStringArray,
|
|
2242
|
+
hexToBytes: () => hexToBytes,
|
|
2235
2243
|
hexToDecimalString: () => hexToDecimalString,
|
|
2236
2244
|
isBigInt: () => isBigInt,
|
|
2237
2245
|
isHex: () => isHex,
|
|
@@ -2241,6 +2249,7 @@ __export(num_exports, {
|
|
|
2241
2249
|
toHex: () => toHex,
|
|
2242
2250
|
toHexString: () => toHexString
|
|
2243
2251
|
});
|
|
2252
|
+
import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
|
|
2244
2253
|
|
|
2245
2254
|
// src/utils/assert.ts
|
|
2246
2255
|
function assert(condition, message) {
|
|
@@ -2306,6 +2315,15 @@ function getHexStringArray(value) {
|
|
|
2306
2315
|
return value.map((el) => getHexString(el));
|
|
2307
2316
|
}
|
|
2308
2317
|
var toCairoBool = (value) => (+value).toString();
|
|
2318
|
+
function hexToBytes(value) {
|
|
2319
|
+
if (!isHex(value))
|
|
2320
|
+
throw new Error(`${value} need to be a hex-string`);
|
|
2321
|
+
let adaptedValue = removeHexPrefix(value);
|
|
2322
|
+
if (adaptedValue.length % 2 !== 0) {
|
|
2323
|
+
adaptedValue = `0${adaptedValue}`;
|
|
2324
|
+
}
|
|
2325
|
+
return hexToBytesNoble(adaptedValue);
|
|
2326
|
+
}
|
|
2309
2327
|
|
|
2310
2328
|
// src/utils/shortString.ts
|
|
2311
2329
|
var shortString_exports = {};
|
|
@@ -2426,36 +2444,35 @@ import * as weierstrass from "@noble/curves/abstract/weierstrass";
|
|
|
2426
2444
|
// src/utils/json.ts
|
|
2427
2445
|
var json_exports = {};
|
|
2428
2446
|
__export(json_exports, {
|
|
2429
|
-
|
|
2430
|
-
parse: () => parse,
|
|
2447
|
+
parse: () => parse2,
|
|
2431
2448
|
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
2432
|
-
stringify: () =>
|
|
2449
|
+
stringify: () => stringify2,
|
|
2433
2450
|
stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
|
|
2434
2451
|
});
|
|
2435
|
-
import
|
|
2436
|
-
var
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
constructorAction: "preserve"
|
|
2442
|
-
});
|
|
2452
|
+
import * as json from "lossless-json";
|
|
2453
|
+
var parseIntAsNumberOrBigInt = (x) => {
|
|
2454
|
+
if (!json.isInteger(x))
|
|
2455
|
+
return parseFloat(x);
|
|
2456
|
+
const v = parseInt(x, 10);
|
|
2457
|
+
return Number.isSafeInteger(v) ? v : BigInt(x);
|
|
2443
2458
|
};
|
|
2444
|
-
var
|
|
2445
|
-
var
|
|
2446
|
-
var
|
|
2459
|
+
var parse2 = (x) => json.parse(String(x), null, parseIntAsNumberOrBigInt);
|
|
2460
|
+
var parseAlwaysAsBig = (x) => json.parse(String(x), null, json.parseNumberAndBigInt);
|
|
2461
|
+
var stringify2 = (...p) => json.stringify(...p);
|
|
2462
|
+
var stringifyAlwaysAsBig = stringify2;
|
|
2447
2463
|
|
|
2448
2464
|
// src/utils/hash.ts
|
|
2449
2465
|
import * as poseidon from "@noble/curves/abstract/poseidon";
|
|
2450
2466
|
var transactionVersion = 1n;
|
|
2467
|
+
var transactionVersion_2 = 2n;
|
|
2451
2468
|
var feeTransactionVersion = 2n ** 128n + transactionVersion;
|
|
2452
2469
|
function keccakBn(value) {
|
|
2453
2470
|
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
2454
2471
|
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2455
|
-
return addHexPrefix(
|
|
2472
|
+
return addHexPrefix(keccak(hexToBytes(addHexPrefix(evenHex))).toString(16));
|
|
2456
2473
|
}
|
|
2457
2474
|
function keccakHex(value) {
|
|
2458
|
-
return addHexPrefix(
|
|
2475
|
+
return addHexPrefix(keccak(utf8ToArray(value)).toString(16));
|
|
2459
2476
|
}
|
|
2460
2477
|
function starknetKeccak(value) {
|
|
2461
2478
|
const hash = BigInt(keccakHex(value));
|
|
@@ -2501,7 +2518,7 @@ function calculateDeployTransactionHash(contractAddress, constructorCalldata, ve
|
|
|
2501
2518
|
chainId
|
|
2502
2519
|
);
|
|
2503
2520
|
}
|
|
2504
|
-
function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce) {
|
|
2521
|
+
function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
|
|
2505
2522
|
return calculateTransactionHashCommon(
|
|
2506
2523
|
"0x6465636c617265" /* DECLARE */,
|
|
2507
2524
|
version,
|
|
@@ -2510,7 +2527,7 @@ function calculateDeclareTransactionHash(classHash, senderAddress, version, maxF
|
|
|
2510
2527
|
[classHash],
|
|
2511
2528
|
maxFee,
|
|
2512
2529
|
chainId,
|
|
2513
|
-
[nonce]
|
|
2530
|
+
[nonce, ...compiledClassHash ? [compiledClassHash] : []]
|
|
2514
2531
|
);
|
|
2515
2532
|
}
|
|
2516
2533
|
function calculateDeployAccountTransactionHash(contractAddress, classHash, constructorCalldata, salt, version, maxFee, chainId, nonce) {
|
|
@@ -2576,11 +2593,11 @@ function formatSpaces(json2) {
|
|
|
2576
2593
|
function computeHintedClassHash(compiledContract) {
|
|
2577
2594
|
const { abi, program } = compiledContract;
|
|
2578
2595
|
const contractClass = { abi, program };
|
|
2579
|
-
const serializedJson = formatSpaces(
|
|
2596
|
+
const serializedJson = formatSpaces(stringify2(contractClass, nullSkipReplacer));
|
|
2580
2597
|
return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
2581
2598
|
}
|
|
2582
2599
|
function computeLegacyContractClassHash(contract) {
|
|
2583
|
-
const compiledContract = typeof contract === "string" ?
|
|
2600
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2584
2601
|
const apiVersion = toHex(API_VERSION);
|
|
2585
2602
|
const externalEntryPointsHash = computeHashOnElements(
|
|
2586
2603
|
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
@@ -2619,36 +2636,12 @@ function hashEntryPoint(data) {
|
|
|
2619
2636
|
});
|
|
2620
2637
|
return poseidonHashMany(base);
|
|
2621
2638
|
}
|
|
2622
|
-
function parseHints(hints) {
|
|
2623
|
-
return hints.reduce((cum, [hint_id, hint_codes]) => {
|
|
2624
|
-
cum[hint_id] = hint_codes.map((it) => ({
|
|
2625
|
-
code: it,
|
|
2626
|
-
accessible_scopes: [],
|
|
2627
|
-
flow_tracking_data: { ap_tracking: { group: 0, offset: 0 }, reference_ids: {} }
|
|
2628
|
-
}));
|
|
2629
|
-
return cum;
|
|
2630
|
-
}, {});
|
|
2631
|
-
}
|
|
2632
|
-
function hintedProgram(casm) {
|
|
2633
|
-
const sortedHintedProgram = sort({
|
|
2634
|
-
program: {
|
|
2635
|
-
prime: casm.prime,
|
|
2636
|
-
data: casm.bytecode,
|
|
2637
|
-
builtins: [],
|
|
2638
|
-
hints: parseHints(casm.hints),
|
|
2639
|
-
compiler_version: casm.compiler_version
|
|
2640
|
-
}
|
|
2641
|
-
});
|
|
2642
|
-
const serialized = formatSpaces(stringify(sortedHintedProgram));
|
|
2643
|
-
return BigInt(addHexPrefix(starkCurve.keccak(utf8ToArray(serialized)).toString(16)));
|
|
2644
|
-
}
|
|
2645
2639
|
function computeCompiledClassHash(casm) {
|
|
2646
2640
|
const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
|
|
2647
2641
|
const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
|
|
2648
2642
|
const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
|
|
2649
2643
|
const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
|
|
2650
2644
|
const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
|
|
2651
|
-
const hintedCompiledClassHash = hintedProgram(casm);
|
|
2652
2645
|
const bytecode = poseidonHashMany(casm.bytecode.map((it) => BigInt(it)));
|
|
2653
2646
|
return toHex(
|
|
2654
2647
|
poseidonHashMany([
|
|
@@ -2656,29 +2649,28 @@ function computeCompiledClassHash(casm) {
|
|
|
2656
2649
|
externalEntryPointsHash,
|
|
2657
2650
|
l1Handlers,
|
|
2658
2651
|
constructor,
|
|
2659
|
-
hintedCompiledClassHash,
|
|
2660
2652
|
bytecode
|
|
2661
2653
|
])
|
|
2662
2654
|
);
|
|
2663
2655
|
}
|
|
2664
|
-
function
|
|
2656
|
+
function hashEntryPointSierra(data) {
|
|
2665
2657
|
const base = data.flatMap((it) => {
|
|
2666
2658
|
return [BigInt(it.selector), BigInt(it.function_idx)];
|
|
2667
2659
|
});
|
|
2668
2660
|
return poseidonHashMany(base);
|
|
2669
2661
|
}
|
|
2670
|
-
function hashAbi(
|
|
2671
|
-
const indentString =
|
|
2662
|
+
function hashAbi(sierra) {
|
|
2663
|
+
const indentString = formatSpaces(stringify2(sierra.abi, null));
|
|
2672
2664
|
return BigInt(addHexPrefix(starkCurve.keccak(utf8ToArray(indentString)).toString(16)));
|
|
2673
2665
|
}
|
|
2674
|
-
function
|
|
2666
|
+
function computeSierraContractClassHash(sierra) {
|
|
2675
2667
|
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
2676
2668
|
const compiledClassVersion = BigInt(encodeShortString(CONTRACT_CLASS_VERSION));
|
|
2677
|
-
const externalEntryPointsHash =
|
|
2678
|
-
const l1Handlers =
|
|
2679
|
-
const constructor =
|
|
2680
|
-
const abiHash = hashAbi(
|
|
2681
|
-
const
|
|
2669
|
+
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
2670
|
+
const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
|
|
2671
|
+
const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
|
|
2672
|
+
const abiHash = hashAbi(sierra);
|
|
2673
|
+
const sierraProgram = poseidonHashMany(sierra.sierra_program.map((it) => BigInt(it)));
|
|
2682
2674
|
return toHex(
|
|
2683
2675
|
poseidonHashMany([
|
|
2684
2676
|
compiledClassVersion,
|
|
@@ -2686,18 +2678,40 @@ function computeSieraContractClassHash(siera) {
|
|
|
2686
2678
|
l1Handlers,
|
|
2687
2679
|
constructor,
|
|
2688
2680
|
abiHash,
|
|
2689
|
-
|
|
2681
|
+
sierraProgram
|
|
2690
2682
|
])
|
|
2691
2683
|
);
|
|
2692
2684
|
}
|
|
2693
2685
|
function computeContractClassHash(contract) {
|
|
2694
|
-
const compiledContract = typeof contract === "string" ?
|
|
2686
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2695
2687
|
if ("sierra_program" in compiledContract) {
|
|
2696
|
-
return
|
|
2688
|
+
return computeSierraContractClassHash(compiledContract);
|
|
2697
2689
|
}
|
|
2698
2690
|
return computeLegacyContractClassHash(compiledContract);
|
|
2699
2691
|
}
|
|
2700
2692
|
|
|
2693
|
+
// src/utils/contract.ts
|
|
2694
|
+
function isSierra(contract) {
|
|
2695
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2696
|
+
return "sierra_program" in compiledContract;
|
|
2697
|
+
}
|
|
2698
|
+
function extractContractHashes(payload) {
|
|
2699
|
+
const response = { ...payload };
|
|
2700
|
+
if (isSierra(payload.contract)) {
|
|
2701
|
+
if (!payload.compiledClassHash && payload.casm) {
|
|
2702
|
+
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
2703
|
+
}
|
|
2704
|
+
if (!response.compiledClassHash)
|
|
2705
|
+
throw new Error(
|
|
2706
|
+
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
2707
|
+
);
|
|
2708
|
+
}
|
|
2709
|
+
response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
|
|
2710
|
+
if (!response.classHash)
|
|
2711
|
+
throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
2712
|
+
return response;
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2701
2715
|
// src/utils/stark.ts
|
|
2702
2716
|
var stark_exports = {};
|
|
2703
2717
|
__export(stark_exports, {
|
|
@@ -2714,7 +2728,7 @@ __export(stark_exports, {
|
|
|
2714
2728
|
import { Signature, getStarkKey, utils } from "micro-starknet";
|
|
2715
2729
|
import { gzip } from "pako";
|
|
2716
2730
|
function compressProgram(jsonProgram) {
|
|
2717
|
-
const stringified = typeof jsonProgram === "string" ? jsonProgram :
|
|
2731
|
+
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
2718
2732
|
const compressedProgram = gzip(stringified);
|
|
2719
2733
|
return btoaUniversal(compressedProgram);
|
|
2720
2734
|
}
|
|
@@ -2781,12 +2795,23 @@ function parseCalldata(calldata = []) {
|
|
|
2781
2795
|
return toHex(data);
|
|
2782
2796
|
});
|
|
2783
2797
|
}
|
|
2798
|
+
function createSierraContractClass(contract) {
|
|
2799
|
+
const result = { ...contract };
|
|
2800
|
+
delete result.sierra_program_debug_info;
|
|
2801
|
+
result.abi = formatSpaces(stringify2(contract.abi));
|
|
2802
|
+
result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
|
|
2803
|
+
result.sierra_program = compressProgram(result.sierra_program);
|
|
2804
|
+
return result;
|
|
2805
|
+
}
|
|
2784
2806
|
function parseContract(contract) {
|
|
2785
|
-
const parsedContract = typeof contract === "string" ?
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2807
|
+
const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2808
|
+
if (!isSierra(contract)) {
|
|
2809
|
+
return {
|
|
2810
|
+
...parsedContract,
|
|
2811
|
+
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
2812
|
+
};
|
|
2813
|
+
}
|
|
2814
|
+
return createSierraContractClass(parsedContract);
|
|
2790
2815
|
}
|
|
2791
2816
|
|
|
2792
2817
|
// src/utils/responseParser/rpc.ts
|
|
@@ -2806,6 +2831,7 @@ var RPCResponseParser = class {
|
|
|
2806
2831
|
return {
|
|
2807
2832
|
calldata: res.calldata || [],
|
|
2808
2833
|
contract_address: res.contract_address,
|
|
2834
|
+
sender_address: res.contract_address,
|
|
2809
2835
|
max_fee: res.max_fee,
|
|
2810
2836
|
nonce: res.nonce,
|
|
2811
2837
|
signature: res.signature || [],
|
|
@@ -2828,7 +2854,7 @@ var RPCResponseParser = class {
|
|
|
2828
2854
|
};
|
|
2829
2855
|
|
|
2830
2856
|
// src/provider/errors.ts
|
|
2831
|
-
import { CustomError } from "ts-custom-error";
|
|
2857
|
+
import { CustomError } from "ts-custom-error/dist/custom-error";
|
|
2832
2858
|
var LibraryError = class extends CustomError {
|
|
2833
2859
|
};
|
|
2834
2860
|
var GatewayError = class extends LibraryError {
|
|
@@ -3050,7 +3076,7 @@ var RpcProvider = class {
|
|
|
3050
3076
|
fetch(method, params) {
|
|
3051
3077
|
return fetchPonyfill_default(this.nodeUrl, {
|
|
3052
3078
|
method: "POST",
|
|
3053
|
-
body:
|
|
3079
|
+
body: stringify2({ method, jsonrpc: "2.0", params, id: 0 }),
|
|
3054
3080
|
headers: this.headers
|
|
3055
3081
|
});
|
|
3056
3082
|
}
|
|
@@ -3175,22 +3201,25 @@ var RpcProvider = class {
|
|
|
3175
3201
|
}
|
|
3176
3202
|
async getDeclareEstimateFee({ senderAddress, contractDefinition, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
3177
3203
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3204
|
+
if ("program" in contractDefinition) {
|
|
3205
|
+
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3206
|
+
request: {
|
|
3207
|
+
type: RPC.TransactionType.DECLARE,
|
|
3208
|
+
contract_class: {
|
|
3209
|
+
program: contractDefinition.program,
|
|
3210
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
3211
|
+
abi: contractDefinition.abi
|
|
3212
|
+
},
|
|
3213
|
+
sender_address: senderAddress,
|
|
3214
|
+
signature: signatureToHexArray(signature),
|
|
3215
|
+
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
3216
|
+
nonce: toHex(details.nonce),
|
|
3217
|
+
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
3185
3218
|
},
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
3191
|
-
},
|
|
3192
|
-
block_id
|
|
3193
|
-
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3219
|
+
block_id
|
|
3220
|
+
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3221
|
+
}
|
|
3222
|
+
throw new Error("RPC do not support Sierra Contracts yet");
|
|
3194
3223
|
}
|
|
3195
3224
|
async getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
3196
3225
|
const block_id = new Block(blockIdentifier).identifier;
|
|
@@ -3212,21 +3241,24 @@ var RpcProvider = class {
|
|
|
3212
3241
|
throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
|
|
3213
3242
|
}
|
|
3214
3243
|
async declareContract({ contractDefinition, signature, senderAddress }, details) {
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3244
|
+
if ("program" in contractDefinition) {
|
|
3245
|
+
return this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
3246
|
+
declare_transaction: {
|
|
3247
|
+
contract_class: {
|
|
3248
|
+
program: contractDefinition.program,
|
|
3249
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
3250
|
+
abi: contractDefinition.abi
|
|
3251
|
+
},
|
|
3252
|
+
type: RPC.TransactionType.DECLARE,
|
|
3253
|
+
version: "0x1",
|
|
3254
|
+
max_fee: toHex(details.maxFee || 0),
|
|
3255
|
+
signature: signatureToHexArray(signature),
|
|
3256
|
+
sender_address: senderAddress,
|
|
3257
|
+
nonce: toHex(details.nonce)
|
|
3258
|
+
}
|
|
3259
|
+
});
|
|
3260
|
+
}
|
|
3261
|
+
throw new Error("RPC do not support Sierra Contracts yet");
|
|
3230
3262
|
}
|
|
3231
3263
|
async deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }, details) {
|
|
3232
3264
|
return this.fetchEndpoint("starknet_addDeployAccountTransaction", {
|
|
@@ -3249,7 +3281,7 @@ var RpcProvider = class {
|
|
|
3249
3281
|
calldata: parseCalldata(functionInvocation.calldata),
|
|
3250
3282
|
type: RPC.TransactionType.INVOKE,
|
|
3251
3283
|
max_fee: toHex(details.maxFee || 0),
|
|
3252
|
-
version:
|
|
3284
|
+
version: "0x1",
|
|
3253
3285
|
signature: signatureToHexArray(functionInvocation.signature),
|
|
3254
3286
|
nonce: toHex(details.nonce)
|
|
3255
3287
|
}
|
|
@@ -3358,7 +3390,6 @@ var SequencerAPIResponseParser = class extends ResponseParser {
|
|
|
3358
3390
|
return {
|
|
3359
3391
|
...res,
|
|
3360
3392
|
calldata: "calldata" in res.transaction ? res.transaction.calldata : [],
|
|
3361
|
-
contract_address: "contract_address" in res.transaction ? res.transaction.contract_address : void 0,
|
|
3362
3393
|
contract_class: "contract_class" in res.transaction ? res.transaction.contract_class : void 0,
|
|
3363
3394
|
entry_point_selector: "entry_point_selector" in res.transaction ? res.transaction.entry_point_selector : void 0,
|
|
3364
3395
|
max_fee: "max_fee" in res.transaction ? res.transaction.max_fee : void 0,
|
|
@@ -3476,24 +3507,18 @@ var SequencerAPIResponseParser = class extends ResponseParser {
|
|
|
3476
3507
|
};
|
|
3477
3508
|
}
|
|
3478
3509
|
parseGetStateUpdateResponse(res) {
|
|
3479
|
-
const nonces =
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
return {
|
|
3487
|
-
address,
|
|
3488
|
-
storage_entries
|
|
3489
|
-
};
|
|
3490
|
-
});
|
|
3510
|
+
const nonces = Object.entries(res.state_diff.nonces).map(([contract_address, nonce]) => ({
|
|
3511
|
+
contract_address,
|
|
3512
|
+
nonce
|
|
3513
|
+
}));
|
|
3514
|
+
const storage_diffs = Object.entries(res.state_diff.storage_diffs).map(
|
|
3515
|
+
([address, storage_entries]) => ({ address, storage_entries })
|
|
3516
|
+
);
|
|
3491
3517
|
return {
|
|
3492
3518
|
...res,
|
|
3493
3519
|
state_diff: {
|
|
3520
|
+
...res.state_diff,
|
|
3494
3521
|
storage_diffs,
|
|
3495
|
-
declared_contract_hashes: res.state_diff.declared_contract_hashes,
|
|
3496
|
-
deployed_contracts: res.state_diff.deployed_contracts,
|
|
3497
3522
|
nonces
|
|
3498
3523
|
}
|
|
3499
3524
|
};
|
|
@@ -3638,20 +3663,20 @@ var SequencerProvider = class {
|
|
|
3638
3663
|
try {
|
|
3639
3664
|
const response = await fetchPonyfill_default(url, {
|
|
3640
3665
|
method,
|
|
3641
|
-
body:
|
|
3666
|
+
body: stringify2(options == null ? void 0 : options.body),
|
|
3642
3667
|
headers
|
|
3643
3668
|
});
|
|
3644
3669
|
const textResponse = await response.text();
|
|
3645
3670
|
if (!response.ok) {
|
|
3646
3671
|
let responseBody;
|
|
3647
3672
|
try {
|
|
3648
|
-
responseBody =
|
|
3673
|
+
responseBody = parse2(textResponse);
|
|
3649
3674
|
} catch {
|
|
3650
3675
|
throw new HttpError(response.statusText, response.status);
|
|
3651
3676
|
}
|
|
3652
3677
|
throw new GatewayError(responseBody.message, responseBody.code);
|
|
3653
3678
|
}
|
|
3654
|
-
const parseChoice = (options == null ? void 0 : options.parseAlwaysAsBigInt) ? parseAlwaysAsBig :
|
|
3679
|
+
const parseChoice = (options == null ? void 0 : options.parseAlwaysAsBigInt) ? parseAlwaysAsBig : parse2;
|
|
3655
3680
|
return parseChoice(textResponse);
|
|
3656
3681
|
} catch (error) {
|
|
3657
3682
|
if (error instanceof Error && !(error instanceof LibraryError))
|
|
@@ -3667,7 +3692,6 @@ var SequencerProvider = class {
|
|
|
3667
3692
|
"call_contract",
|
|
3668
3693
|
{ blockIdentifier },
|
|
3669
3694
|
{
|
|
3670
|
-
signature: [],
|
|
3671
3695
|
contract_address: contractAddress,
|
|
3672
3696
|
entry_point_selector: getSelectorFromName(entryPointSelector),
|
|
3673
3697
|
calldata
|
|
@@ -3712,18 +3736,23 @@ var SequencerProvider = class {
|
|
|
3712
3736
|
async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3713
3737
|
return this.fetchEndpoint("get_class_hash_at", { blockIdentifier, contractAddress });
|
|
3714
3738
|
}
|
|
3715
|
-
async getClassByHash(classHash) {
|
|
3716
|
-
return this.fetchEndpoint("get_class_by_hash", { classHash }).then(
|
|
3739
|
+
async getClassByHash(classHash, blockIdentifier = this.blockIdentifier) {
|
|
3740
|
+
return this.fetchEndpoint("get_class_by_hash", { classHash, blockIdentifier }).then(
|
|
3741
|
+
parseContract
|
|
3742
|
+
);
|
|
3743
|
+
}
|
|
3744
|
+
async getCompiledClassByClassHash(classHash, blockIdentifier = this.blockIdentifier) {
|
|
3745
|
+
return this.fetchEndpoint("get_compiled_class_by_class_hash", { classHash, blockIdentifier });
|
|
3717
3746
|
}
|
|
3718
3747
|
async invokeFunction(functionInvocation, details) {
|
|
3719
3748
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
3720
3749
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
3721
|
-
|
|
3750
|
+
sender_address: functionInvocation.contractAddress,
|
|
3722
3751
|
calldata: bigNumberishArrayToDecimalStringArray(functionInvocation.calldata ?? []),
|
|
3723
3752
|
signature: signatureToDecimalArray(functionInvocation.signature),
|
|
3724
3753
|
nonce: toHex(details.nonce),
|
|
3725
3754
|
max_fee: toHex(details.maxFee || 0),
|
|
3726
|
-
version:
|
|
3755
|
+
version: "0x1"
|
|
3727
3756
|
}).then(this.responseParser.parseInvokeFunctionResponse);
|
|
3728
3757
|
}
|
|
3729
3758
|
async deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }, details) {
|
|
@@ -3738,27 +3767,39 @@ var SequencerProvider = class {
|
|
|
3738
3767
|
signature: signatureToDecimalArray(signature)
|
|
3739
3768
|
}).then(this.responseParser.parseDeployContractResponse);
|
|
3740
3769
|
}
|
|
3741
|
-
async declareContract({ senderAddress, contractDefinition, signature }, details) {
|
|
3770
|
+
async declareContract({ senderAddress, contractDefinition, signature, compiledClassHash }, details) {
|
|
3771
|
+
if (!isSierra(contractDefinition)) {
|
|
3772
|
+
return this.fetchEndpoint("add_transaction", void 0, {
|
|
3773
|
+
type: "DECLARE" /* DECLARE */,
|
|
3774
|
+
contract_class: contractDefinition,
|
|
3775
|
+
nonce: toHex(details.nonce),
|
|
3776
|
+
signature: signatureToDecimalArray(signature),
|
|
3777
|
+
sender_address: senderAddress,
|
|
3778
|
+
max_fee: toHex(details.maxFee || 0),
|
|
3779
|
+
version: "0x1"
|
|
3780
|
+
}).then(this.responseParser.parseDeclareContractResponse);
|
|
3781
|
+
}
|
|
3742
3782
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
3743
3783
|
type: "DECLARE" /* DECLARE */,
|
|
3784
|
+
sender_address: senderAddress,
|
|
3785
|
+
compiled_class_hash: compiledClassHash,
|
|
3744
3786
|
contract_class: contractDefinition,
|
|
3745
3787
|
nonce: toHex(details.nonce),
|
|
3746
3788
|
signature: signatureToDecimalArray(signature),
|
|
3747
|
-
sender_address: senderAddress,
|
|
3748
3789
|
max_fee: toHex(details.maxFee || 0),
|
|
3749
|
-
version:
|
|
3790
|
+
version: "0x2"
|
|
3750
3791
|
}).then(this.responseParser.parseDeclareContractResponse);
|
|
3751
3792
|
}
|
|
3752
|
-
async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
3753
|
-
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
|
|
3793
|
+
async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
3794
|
+
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier, skipValidate);
|
|
3754
3795
|
}
|
|
3755
|
-
async getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
3796
|
+
async getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
3756
3797
|
return this.fetchEndpoint(
|
|
3757
3798
|
"estimate_fee",
|
|
3758
|
-
{ blockIdentifier },
|
|
3799
|
+
{ blockIdentifier, skipValidate },
|
|
3759
3800
|
{
|
|
3760
3801
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
3761
|
-
|
|
3802
|
+
sender_address: invocation.contractAddress,
|
|
3762
3803
|
calldata: invocation.calldata ?? [],
|
|
3763
3804
|
signature: signatureToDecimalArray(invocation.signature),
|
|
3764
3805
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
@@ -3766,24 +3807,39 @@ var SequencerProvider = class {
|
|
|
3766
3807
|
}
|
|
3767
3808
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
3768
3809
|
}
|
|
3769
|
-
async getDeclareEstimateFee({ senderAddress, contractDefinition, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
3810
|
+
async getDeclareEstimateFee({ senderAddress, contractDefinition, signature, compiledClassHash }, details, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
3811
|
+
if (!isSierra(contractDefinition)) {
|
|
3812
|
+
return this.fetchEndpoint(
|
|
3813
|
+
"estimate_fee",
|
|
3814
|
+
{ blockIdentifier, skipValidate },
|
|
3815
|
+
{
|
|
3816
|
+
type: "DECLARE" /* DECLARE */,
|
|
3817
|
+
sender_address: senderAddress,
|
|
3818
|
+
contract_class: contractDefinition,
|
|
3819
|
+
signature: signatureToDecimalArray(signature),
|
|
3820
|
+
version: toHex((details == null ? void 0 : details.version) || toBigInt(feeTransactionVersion)),
|
|
3821
|
+
nonce: toHex(details.nonce)
|
|
3822
|
+
}
|
|
3823
|
+
).then(this.responseParser.parseFeeEstimateResponse);
|
|
3824
|
+
}
|
|
3770
3825
|
return this.fetchEndpoint(
|
|
3771
3826
|
"estimate_fee",
|
|
3772
|
-
{ blockIdentifier },
|
|
3827
|
+
{ blockIdentifier, skipValidate },
|
|
3773
3828
|
{
|
|
3774
3829
|
type: "DECLARE" /* DECLARE */,
|
|
3775
3830
|
sender_address: senderAddress,
|
|
3831
|
+
compiled_class_hash: compiledClassHash,
|
|
3776
3832
|
contract_class: contractDefinition,
|
|
3833
|
+
nonce: toHex(details.nonce),
|
|
3777
3834
|
signature: signatureToDecimalArray(signature),
|
|
3778
|
-
version:
|
|
3779
|
-
nonce: toHex(details.nonce)
|
|
3835
|
+
version: "0x2"
|
|
3780
3836
|
}
|
|
3781
3837
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
3782
3838
|
}
|
|
3783
|
-
async getDeployAccountEstimateFee({ classHash, addressSalt, constructorCalldata, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
3839
|
+
async getDeployAccountEstimateFee({ classHash, addressSalt, constructorCalldata, signature }, details, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
3784
3840
|
return this.fetchEndpoint(
|
|
3785
3841
|
"estimate_fee",
|
|
3786
|
-
{ blockIdentifier },
|
|
3842
|
+
{ blockIdentifier, skipValidate },
|
|
3787
3843
|
{
|
|
3788
3844
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
3789
3845
|
class_hash: toHex(classHash),
|
|
@@ -3801,7 +3857,7 @@ var SequencerProvider = class {
|
|
|
3801
3857
|
if (invocation.type === "INVOKE_FUNCTION") {
|
|
3802
3858
|
res = {
|
|
3803
3859
|
type: invocation.type,
|
|
3804
|
-
|
|
3860
|
+
sender_address: invocation.contractAddress,
|
|
3805
3861
|
calldata: invocation.calldata ?? []
|
|
3806
3862
|
};
|
|
3807
3863
|
} else if (invocation.type === "DECLARE") {
|
|
@@ -3880,13 +3936,13 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
3880
3936
|
};
|
|
3881
3937
|
return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
|
|
3882
3938
|
}
|
|
3883
|
-
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
3939
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
3884
3940
|
return this.fetchEndpoint(
|
|
3885
3941
|
"simulate_transaction",
|
|
3886
|
-
{ blockIdentifier },
|
|
3942
|
+
{ blockIdentifier, skipValidate },
|
|
3887
3943
|
{
|
|
3888
3944
|
type: "INVOKE_FUNCTION",
|
|
3889
|
-
|
|
3945
|
+
sender_address: invocation.contractAddress,
|
|
3890
3946
|
calldata: invocation.calldata ?? [],
|
|
3891
3947
|
signature: signatureToDecimalArray(invocation.signature),
|
|
3892
3948
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
@@ -3946,11 +4002,12 @@ var Provider = class {
|
|
|
3946
4002
|
async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
3947
4003
|
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
3948
4004
|
}
|
|
3949
|
-
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
4005
|
+
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
|
|
3950
4006
|
return this.provider.getInvokeEstimateFee(
|
|
3951
4007
|
invocationWithTxType,
|
|
3952
4008
|
invocationDetails,
|
|
3953
|
-
blockIdentifier
|
|
4009
|
+
blockIdentifier,
|
|
4010
|
+
skipValidate
|
|
3954
4011
|
);
|
|
3955
4012
|
}
|
|
3956
4013
|
async getEstimateFeeBulk(invocations, blockIdentifier) {
|
|
@@ -3980,11 +4037,16 @@ var Provider = class {
|
|
|
3980
4037
|
async declareContract(transaction, details) {
|
|
3981
4038
|
return this.provider.declareContract(transaction, details);
|
|
3982
4039
|
}
|
|
3983
|
-
async getDeclareEstimateFee(transaction, details, blockIdentifier) {
|
|
3984
|
-
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier);
|
|
4040
|
+
async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4041
|
+
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
|
|
3985
4042
|
}
|
|
3986
|
-
getDeployAccountEstimateFee(transaction, details, blockIdentifier) {
|
|
3987
|
-
return this.provider.getDeployAccountEstimateFee(
|
|
4043
|
+
getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4044
|
+
return this.provider.getDeployAccountEstimateFee(
|
|
4045
|
+
transaction,
|
|
4046
|
+
details,
|
|
4047
|
+
blockIdentifier,
|
|
4048
|
+
skipValidate
|
|
4049
|
+
);
|
|
3988
4050
|
}
|
|
3989
4051
|
async getCode(contractAddress, blockIdentifier) {
|
|
3990
4052
|
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
@@ -3992,8 +4054,13 @@ var Provider = class {
|
|
|
3992
4054
|
async waitForTransaction(txHash, options) {
|
|
3993
4055
|
return this.provider.waitForTransaction(txHash, options);
|
|
3994
4056
|
}
|
|
3995
|
-
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier) {
|
|
3996
|
-
return this.provider.getSimulateTransaction(
|
|
4057
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
|
|
4058
|
+
return this.provider.getSimulateTransaction(
|
|
4059
|
+
invocation,
|
|
4060
|
+
invocationDetails,
|
|
4061
|
+
blockIdentifier,
|
|
4062
|
+
skipValidate
|
|
4063
|
+
);
|
|
3997
4064
|
}
|
|
3998
4065
|
async getStateUpdate(blockIdentifier) {
|
|
3999
4066
|
return this.provider.getStateUpdate(blockIdentifier);
|
|
@@ -4678,7 +4745,10 @@ var transaction_exports = {};
|
|
|
4678
4745
|
__export(transaction_exports, {
|
|
4679
4746
|
fromCallsToExecuteCalldata: () => fromCallsToExecuteCalldata,
|
|
4680
4747
|
fromCallsToExecuteCalldataWithNonce: () => fromCallsToExecuteCalldataWithNonce,
|
|
4681
|
-
|
|
4748
|
+
fromCallsToExecuteCalldata_cairo1: () => fromCallsToExecuteCalldata_cairo1,
|
|
4749
|
+
getExecuteCalldata: () => getExecuteCalldata,
|
|
4750
|
+
transformCallsToMulticallArrays: () => transformCallsToMulticallArrays,
|
|
4751
|
+
transformCallsToMulticallArrays_cairo1: () => transformCallsToMulticallArrays_cairo1
|
|
4682
4752
|
});
|
|
4683
4753
|
var transformCallsToMulticallArrays = (calls) => {
|
|
4684
4754
|
const callArray = [];
|
|
@@ -4712,6 +4782,27 @@ var fromCallsToExecuteCalldata = (calls) => {
|
|
|
4712
4782
|
var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
|
|
4713
4783
|
return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
|
|
4714
4784
|
};
|
|
4785
|
+
var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
4786
|
+
const callArray = calls.map((call) => ({
|
|
4787
|
+
to: toBigInt(call.contractAddress).toString(10),
|
|
4788
|
+
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
4789
|
+
calldata: bigNumberishArrayToDecimalStringArray(call.calldata || [])
|
|
4790
|
+
}));
|
|
4791
|
+
return callArray;
|
|
4792
|
+
};
|
|
4793
|
+
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
4794
|
+
const callArray = transformCallsToMulticallArrays_cairo1(calls);
|
|
4795
|
+
return [
|
|
4796
|
+
callArray.length.toString(),
|
|
4797
|
+
...callArray.map(({ to, selector, calldata }) => [to, selector, calldata.length.toString(), ...calldata]).flat()
|
|
4798
|
+
];
|
|
4799
|
+
};
|
|
4800
|
+
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
4801
|
+
if (cairoVersion === "1") {
|
|
4802
|
+
return fromCallsToExecuteCalldata_cairo1(calls);
|
|
4803
|
+
}
|
|
4804
|
+
return fromCallsToExecuteCalldata(calls);
|
|
4805
|
+
};
|
|
4715
4806
|
|
|
4716
4807
|
// src/utils/typedData/index.ts
|
|
4717
4808
|
var typedData_exports = {};
|
|
@@ -4938,7 +5029,7 @@ var Signer = class {
|
|
|
4938
5029
|
if (abis && abis.length !== transactions.length) {
|
|
4939
5030
|
throw new Error("ABI must be provided for each transaction or no transaction");
|
|
4940
5031
|
}
|
|
4941
|
-
const calldata =
|
|
5032
|
+
const calldata = getExecuteCalldata(transactions, transactionsDetail.cairoVersion);
|
|
4942
5033
|
const msgHash = calculateTransactionHash(
|
|
4943
5034
|
transactionsDetail.walletAddress,
|
|
4944
5035
|
transactionsDetail.version,
|
|
@@ -4971,14 +5062,23 @@ var Signer = class {
|
|
|
4971
5062
|
);
|
|
4972
5063
|
return starkCurve.sign(msgHash, this.pk);
|
|
4973
5064
|
}
|
|
4974
|
-
async signDeclareTransaction({
|
|
5065
|
+
async signDeclareTransaction({
|
|
5066
|
+
classHash,
|
|
5067
|
+
senderAddress,
|
|
5068
|
+
chainId,
|
|
5069
|
+
maxFee,
|
|
5070
|
+
version,
|
|
5071
|
+
nonce,
|
|
5072
|
+
compiledClassHash
|
|
5073
|
+
}) {
|
|
4975
5074
|
const msgHash = calculateDeclareTransactionHash(
|
|
4976
5075
|
classHash,
|
|
4977
5076
|
senderAddress,
|
|
4978
5077
|
version,
|
|
4979
5078
|
maxFee,
|
|
4980
5079
|
chainId,
|
|
4981
|
-
nonce
|
|
5080
|
+
nonce,
|
|
5081
|
+
compiledClassHash
|
|
4982
5082
|
);
|
|
4983
5083
|
return starkCurve.sign(msgHash, this.pk);
|
|
4984
5084
|
}
|
|
@@ -5020,7 +5120,7 @@ var Account = class extends Provider {
|
|
|
5020
5120
|
async estimateFee(calls, estimateFeeDetails) {
|
|
5021
5121
|
return this.estimateInvokeFee(calls, estimateFeeDetails);
|
|
5022
5122
|
}
|
|
5023
|
-
async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
5123
|
+
async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate, cairoVersion } = {}) {
|
|
5024
5124
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
5025
5125
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5026
5126
|
const version = toBigInt(feeTransactionVersion);
|
|
@@ -5030,13 +5130,15 @@ var Account = class extends Provider {
|
|
|
5030
5130
|
nonce,
|
|
5031
5131
|
maxFee: ZERO,
|
|
5032
5132
|
version,
|
|
5033
|
-
chainId
|
|
5133
|
+
chainId,
|
|
5134
|
+
cairoVersion: cairoVersion ?? "0"
|
|
5034
5135
|
};
|
|
5035
5136
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
5036
5137
|
const response = await super.getInvokeEstimateFee(
|
|
5037
5138
|
{ ...invocation },
|
|
5038
5139
|
{ version, nonce },
|
|
5039
|
-
blockIdentifier
|
|
5140
|
+
blockIdentifier,
|
|
5141
|
+
skipValidate
|
|
5040
5142
|
);
|
|
5041
5143
|
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
5042
5144
|
return {
|
|
@@ -5044,18 +5146,26 @@ var Account = class extends Provider {
|
|
|
5044
5146
|
suggestedMaxFee
|
|
5045
5147
|
};
|
|
5046
5148
|
}
|
|
5047
|
-
async estimateDeclareFee({ contract, classHash: providedClassHash }, { blockIdentifier, nonce: providedNonce } = {}) {
|
|
5149
|
+
async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate, cairoVersion } = {}) {
|
|
5048
5150
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5049
|
-
const version = toBigInt(feeTransactionVersion);
|
|
5151
|
+
const version = !isSierra(contract) ? toBigInt(feeTransactionVersion) : transactionVersion_2;
|
|
5050
5152
|
const chainId = await this.getChainId();
|
|
5051
|
-
const
|
|
5052
|
-
{ classHash: providedClassHash, contract },
|
|
5053
|
-
{
|
|
5153
|
+
const declareContractTransaction = await this.buildDeclarePayload(
|
|
5154
|
+
{ classHash: providedClassHash, contract, casm, compiledClassHash },
|
|
5155
|
+
{
|
|
5156
|
+
nonce,
|
|
5157
|
+
chainId,
|
|
5158
|
+
version,
|
|
5159
|
+
walletAddress: this.address,
|
|
5160
|
+
maxFee: ZERO,
|
|
5161
|
+
cairoVersion: cairoVersion ?? "0"
|
|
5162
|
+
}
|
|
5054
5163
|
);
|
|
5055
5164
|
const response = await super.getDeclareEstimateFee(
|
|
5056
|
-
|
|
5165
|
+
declareContractTransaction,
|
|
5057
5166
|
{ version, nonce },
|
|
5058
|
-
blockIdentifier
|
|
5167
|
+
blockIdentifier,
|
|
5168
|
+
skipValidate
|
|
5059
5169
|
);
|
|
5060
5170
|
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
5061
5171
|
return {
|
|
@@ -5068,18 +5178,26 @@ var Account = class extends Provider {
|
|
|
5068
5178
|
addressSalt = 0,
|
|
5069
5179
|
constructorCalldata = [],
|
|
5070
5180
|
contractAddress: providedContractAddress
|
|
5071
|
-
}, { blockIdentifier } = {}) {
|
|
5181
|
+
}, { blockIdentifier, skipValidate, cairoVersion } = {}) {
|
|
5072
5182
|
const version = toBigInt(feeTransactionVersion);
|
|
5073
5183
|
const nonce = ZERO;
|
|
5074
5184
|
const chainId = await this.getChainId();
|
|
5075
5185
|
const payload = await this.buildAccountDeployPayload(
|
|
5076
5186
|
{ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress },
|
|
5077
|
-
{
|
|
5187
|
+
{
|
|
5188
|
+
nonce,
|
|
5189
|
+
chainId,
|
|
5190
|
+
version,
|
|
5191
|
+
walletAddress: this.address,
|
|
5192
|
+
maxFee: ZERO,
|
|
5193
|
+
cairoVersion: cairoVersion ?? "0"
|
|
5194
|
+
}
|
|
5078
5195
|
);
|
|
5079
5196
|
const response = await super.getDeployAccountEstimateFee(
|
|
5080
5197
|
{ ...payload },
|
|
5081
5198
|
{ version, nonce },
|
|
5082
|
-
blockIdentifier
|
|
5199
|
+
blockIdentifier,
|
|
5200
|
+
skipValidate
|
|
5083
5201
|
);
|
|
5084
5202
|
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
5085
5203
|
return {
|
|
@@ -5091,7 +5209,7 @@ var Account = class extends Provider {
|
|
|
5091
5209
|
const calls = this.buildUDCContractPayload(payload);
|
|
5092
5210
|
return this.estimateInvokeFee(calls, transactionsDetail);
|
|
5093
5211
|
}
|
|
5094
|
-
async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
5212
|
+
async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier, cairoVersion } = {}) {
|
|
5095
5213
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5096
5214
|
const version = toBigInt(feeTransactionVersion);
|
|
5097
5215
|
const chainId = await this.getChainId();
|
|
@@ -5102,7 +5220,8 @@ var Account = class extends Provider {
|
|
|
5102
5220
|
nonce: toBigInt(Number(nonce) + index),
|
|
5103
5221
|
maxFee: ZERO,
|
|
5104
5222
|
version,
|
|
5105
|
-
chainId
|
|
5223
|
+
chainId,
|
|
5224
|
+
cairoVersion: cairoVersion ?? "0"
|
|
5106
5225
|
};
|
|
5107
5226
|
const txPayload = transaction.payload;
|
|
5108
5227
|
let res;
|
|
@@ -5160,7 +5279,7 @@ var Account = class extends Provider {
|
|
|
5160
5279
|
});
|
|
5161
5280
|
}
|
|
5162
5281
|
async buildInvocation(call, signerDetails) {
|
|
5163
|
-
const calldata =
|
|
5282
|
+
const calldata = getExecuteCalldata(call, signerDetails.cairoVersion);
|
|
5164
5283
|
const signature = await this.signer.signTransaction(call, signerDetails);
|
|
5165
5284
|
return {
|
|
5166
5285
|
contractAddress: this.address,
|
|
@@ -5177,15 +5296,17 @@ var Account = class extends Provider {
|
|
|
5177
5296
|
);
|
|
5178
5297
|
const version = toBigInt(transactionVersion);
|
|
5179
5298
|
const chainId = await this.getChainId();
|
|
5299
|
+
const cairoVersion = transactionsDetail.cairoVersion ?? "0";
|
|
5180
5300
|
const signerDetails = {
|
|
5181
5301
|
walletAddress: this.address,
|
|
5182
5302
|
nonce,
|
|
5183
5303
|
maxFee,
|
|
5184
5304
|
version,
|
|
5185
|
-
chainId
|
|
5305
|
+
chainId,
|
|
5306
|
+
cairoVersion
|
|
5186
5307
|
};
|
|
5187
5308
|
const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
|
|
5188
|
-
const calldata =
|
|
5309
|
+
const calldata = getExecuteCalldata(transactions, cairoVersion);
|
|
5189
5310
|
return this.invokeFunction(
|
|
5190
5311
|
{ contractAddress: this.address, calldata, signature },
|
|
5191
5312
|
{
|
|
@@ -5195,32 +5316,25 @@ var Account = class extends Provider {
|
|
|
5195
5316
|
}
|
|
5196
5317
|
);
|
|
5197
5318
|
}
|
|
5198
|
-
async declare(
|
|
5199
|
-
const
|
|
5200
|
-
const
|
|
5201
|
-
|
|
5202
|
-
|
|
5319
|
+
async declare(payload, transactionsDetail = {}) {
|
|
5320
|
+
const declareContractPayload = extractContractHashes(payload);
|
|
5321
|
+
const details = {};
|
|
5322
|
+
details.nonce = toBigInt(transactionsDetail.nonce ?? await this.getNonce());
|
|
5323
|
+
details.maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
5324
|
+
{
|
|
5325
|
+
type: "DECLARE" /* DECLARE */,
|
|
5326
|
+
payload: declareContractPayload
|
|
5327
|
+
},
|
|
5203
5328
|
transactionsDetail
|
|
5204
5329
|
);
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
const
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
maxFee,
|
|
5212
|
-
version,
|
|
5213
|
-
nonce
|
|
5330
|
+
details.version = !isSierra(payload.contract) ? transactionVersion : transactionVersion_2;
|
|
5331
|
+
details.chainId = await this.getChainId();
|
|
5332
|
+
const declareContractTransaction = await this.buildDeclarePayload(declareContractPayload, {
|
|
5333
|
+
...details,
|
|
5334
|
+
walletAddress: this.address,
|
|
5335
|
+
cairoVersion: transactionsDetail.cairoVersion ?? "0"
|
|
5214
5336
|
});
|
|
5215
|
-
|
|
5216
|
-
return this.declareContract(
|
|
5217
|
-
{ contractDefinition, senderAddress: this.address, signature },
|
|
5218
|
-
{
|
|
5219
|
-
nonce,
|
|
5220
|
-
maxFee,
|
|
5221
|
-
version
|
|
5222
|
-
}
|
|
5223
|
-
);
|
|
5337
|
+
return this.declareContract(declareContractTransaction, details);
|
|
5224
5338
|
}
|
|
5225
5339
|
async deploy(payload, details) {
|
|
5226
5340
|
const params = [].concat(payload).map((it) => {
|
|
@@ -5359,13 +5473,14 @@ var Account = class extends Provider {
|
|
|
5359
5473
|
feeEstimate = { suggestedMaxFee: ZERO, overall_fee: ZERO };
|
|
5360
5474
|
break;
|
|
5361
5475
|
}
|
|
5362
|
-
return feeEstimate.suggestedMaxFee
|
|
5476
|
+
return feeEstimate.suggestedMaxFee;
|
|
5363
5477
|
}
|
|
5364
|
-
async buildDeclarePayload(
|
|
5478
|
+
async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
|
|
5479
|
+
const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
|
|
5365
5480
|
const contractDefinition = parseContract(contract);
|
|
5366
|
-
const classHash = providedClassHash ?? computeContractClassHash(contract);
|
|
5367
5481
|
const signature = await this.signer.signDeclareTransaction({
|
|
5368
5482
|
classHash,
|
|
5483
|
+
compiledClassHash,
|
|
5369
5484
|
senderAddress: walletAddress,
|
|
5370
5485
|
chainId,
|
|
5371
5486
|
maxFee,
|
|
@@ -5375,7 +5490,8 @@ var Account = class extends Provider {
|
|
|
5375
5490
|
return {
|
|
5376
5491
|
senderAddress: walletAddress,
|
|
5377
5492
|
signature,
|
|
5378
|
-
contractDefinition
|
|
5493
|
+
contractDefinition,
|
|
5494
|
+
compiledClassHash
|
|
5379
5495
|
};
|
|
5380
5496
|
}
|
|
5381
5497
|
async buildAccountDeployPayload({
|
|
@@ -5425,7 +5541,7 @@ var Account = class extends Provider {
|
|
|
5425
5541
|
});
|
|
5426
5542
|
return calls;
|
|
5427
5543
|
}
|
|
5428
|
-
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
5544
|
+
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate, cairoVersion } = {}) {
|
|
5429
5545
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
5430
5546
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5431
5547
|
const version = toBigInt(feeTransactionVersion);
|
|
@@ -5435,13 +5551,15 @@ var Account = class extends Provider {
|
|
|
5435
5551
|
nonce,
|
|
5436
5552
|
maxFee: ZERO,
|
|
5437
5553
|
version,
|
|
5438
|
-
chainId
|
|
5554
|
+
chainId,
|
|
5555
|
+
cairoVersion: cairoVersion ?? "0"
|
|
5439
5556
|
};
|
|
5440
5557
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
5441
5558
|
const response = await super.getSimulateTransaction(
|
|
5442
5559
|
invocation,
|
|
5443
5560
|
{ version, nonce },
|
|
5444
|
-
blockIdentifier
|
|
5561
|
+
blockIdentifier,
|
|
5562
|
+
skipValidate
|
|
5445
5563
|
);
|
|
5446
5564
|
const suggestedMaxFee = estimatedFeeToMaxFee(response.fee_estimation.overall_fee);
|
|
5447
5565
|
return {
|
|
@@ -5497,9 +5615,11 @@ var number = num_exports;
|
|
|
5497
5615
|
export {
|
|
5498
5616
|
Account,
|
|
5499
5617
|
AccountInterface,
|
|
5618
|
+
CallData,
|
|
5500
5619
|
Contract,
|
|
5501
5620
|
ContractFactory,
|
|
5502
5621
|
ContractInterface,
|
|
5622
|
+
EntryPointType,
|
|
5503
5623
|
GatewayError,
|
|
5504
5624
|
HttpError,
|
|
5505
5625
|
LibraryError,
|