starknet 5.10.1 → 5.11.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 +12 -0
- package/dist/index.d.ts +324 -370
- package/dist/index.global.js +693 -63
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +352 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +348 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -2452,7 +2452,9 @@ var uint256 = (it) => {
|
|
|
2452
2452
|
if (!isUint256(bn))
|
|
2453
2453
|
throw new Error("Number is too large");
|
|
2454
2454
|
return {
|
|
2455
|
+
// eslint-disable-next-line no-bitwise
|
|
2455
2456
|
low: (bn & UINT_128_MAX).toString(10),
|
|
2457
|
+
// eslint-disable-next-line no-bitwise
|
|
2456
2458
|
high: (bn >> 128n).toString(10)
|
|
2457
2459
|
};
|
|
2458
2460
|
};
|
|
@@ -2588,7 +2590,11 @@ function extractCairo0Tuple(type) {
|
|
|
2588
2590
|
}
|
|
2589
2591
|
function extractCairo1Tuple(type) {
|
|
2590
2592
|
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
2591
|
-
|
|
2593
|
+
const { subTuple, result } = parseSubTuple(cleanType);
|
|
2594
|
+
const recomposed = result.split(",").map((it) => {
|
|
2595
|
+
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
2596
|
+
});
|
|
2597
|
+
return recomposed;
|
|
2592
2598
|
}
|
|
2593
2599
|
function extractTupleMemberTypes(type) {
|
|
2594
2600
|
if (isCairo1Type(type)) {
|
|
@@ -2597,6 +2603,142 @@ function extractTupleMemberTypes(type) {
|
|
|
2597
2603
|
return extractCairo0Tuple(type);
|
|
2598
2604
|
}
|
|
2599
2605
|
|
|
2606
|
+
// src/utils/calldata/propertyOrder.ts
|
|
2607
|
+
function errorU256(key) {
|
|
2608
|
+
return Error(
|
|
2609
|
+
`Your object includes the property : ${key}, containing an Uint256 object without the 'low' and 'high' keys.`
|
|
2610
|
+
);
|
|
2611
|
+
}
|
|
2612
|
+
function orderPropsByAbi(unorderedObject, abiOfObject, structs) {
|
|
2613
|
+
const orderStruct = (unorderedObject2, abiObject) => {
|
|
2614
|
+
const orderedObject2 = abiObject.reduce((orderedObject, abiParam) => {
|
|
2615
|
+
const setProperty = (value) => Object.defineProperty(orderedObject, abiParam.name, {
|
|
2616
|
+
enumerable: true,
|
|
2617
|
+
value: value ?? unorderedObject2[abiParam.name]
|
|
2618
|
+
});
|
|
2619
|
+
if (unorderedObject2[abiParam.name] === "undefined") {
|
|
2620
|
+
if (isCairo1Type(abiParam.type) || !isLen(abiParam.name)) {
|
|
2621
|
+
throw Error(`Your object needs a property with key : ${abiParam.name} .`);
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
switch (true) {
|
|
2625
|
+
case isTypeStruct(abiParam.type, structs):
|
|
2626
|
+
setProperty(
|
|
2627
|
+
orderStruct(
|
|
2628
|
+
unorderedObject2[abiParam.name],
|
|
2629
|
+
structs[abiParam.type].members
|
|
2630
|
+
)
|
|
2631
|
+
);
|
|
2632
|
+
break;
|
|
2633
|
+
case isTypeUint256(abiParam.type): {
|
|
2634
|
+
const u256 = unorderedObject2[abiParam.name];
|
|
2635
|
+
if (typeof u256 !== "object") {
|
|
2636
|
+
setProperty();
|
|
2637
|
+
break;
|
|
2638
|
+
}
|
|
2639
|
+
if (!("low" in u256 && "high" in u256)) {
|
|
2640
|
+
throw errorU256(abiParam.name);
|
|
2641
|
+
}
|
|
2642
|
+
setProperty({ low: u256.low, high: u256.high });
|
|
2643
|
+
break;
|
|
2644
|
+
}
|
|
2645
|
+
case isTypeTuple(abiParam.type):
|
|
2646
|
+
setProperty(orderTuple(unorderedObject2[abiParam.name], abiParam));
|
|
2647
|
+
break;
|
|
2648
|
+
case isTypeArray(abiParam.type):
|
|
2649
|
+
setProperty(orderArray(unorderedObject2[abiParam.name], abiParam));
|
|
2650
|
+
break;
|
|
2651
|
+
case (!isCairo1Type(abiParam.type) && isLen(abiParam.name)):
|
|
2652
|
+
break;
|
|
2653
|
+
default:
|
|
2654
|
+
setProperty();
|
|
2655
|
+
}
|
|
2656
|
+
return orderedObject;
|
|
2657
|
+
}, {});
|
|
2658
|
+
return orderedObject2;
|
|
2659
|
+
};
|
|
2660
|
+
function orderArray(myArray, abiParam) {
|
|
2661
|
+
const typeInArray = getArrayType(abiParam.type);
|
|
2662
|
+
if (typeof myArray === "string") {
|
|
2663
|
+
return myArray;
|
|
2664
|
+
}
|
|
2665
|
+
switch (true) {
|
|
2666
|
+
case typeInArray in structs:
|
|
2667
|
+
return myArray.map((myObj) => orderStruct(myObj, structs[typeInArray].members));
|
|
2668
|
+
case typeInArray === "core::integer::u256":
|
|
2669
|
+
return myArray.map((u256) => {
|
|
2670
|
+
if (typeof u256 !== "object") {
|
|
2671
|
+
return u256;
|
|
2672
|
+
}
|
|
2673
|
+
if (!("low" in u256 && "high" in u256)) {
|
|
2674
|
+
throw errorU256(abiParam.name);
|
|
2675
|
+
}
|
|
2676
|
+
return { low: u256.low, high: u256.high };
|
|
2677
|
+
});
|
|
2678
|
+
case isTypeTuple(typeInArray):
|
|
2679
|
+
return myArray.map((myElem) => orderTuple(myElem, { name: "0", type: typeInArray }));
|
|
2680
|
+
case isTypeArray(typeInArray):
|
|
2681
|
+
return myArray.map((myElem) => orderArray(myElem, { name: "0", type: typeInArray }));
|
|
2682
|
+
default:
|
|
2683
|
+
return myArray;
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
function orderTuple(unorderedObject2, abiParam) {
|
|
2687
|
+
const typeList = extractTupleMemberTypes(abiParam.type);
|
|
2688
|
+
const orderedObject2 = typeList.reduce((orderedObject, abiTypeCairoX, index) => {
|
|
2689
|
+
const myObjKeys = Object.keys(unorderedObject2);
|
|
2690
|
+
const setProperty = (value) => Object.defineProperty(orderedObject, index.toString(), {
|
|
2691
|
+
enumerable: true,
|
|
2692
|
+
value: value ?? unorderedObject2[myObjKeys[index]]
|
|
2693
|
+
});
|
|
2694
|
+
const abiType = abiTypeCairoX?.type ? abiTypeCairoX.type : abiTypeCairoX;
|
|
2695
|
+
switch (true) {
|
|
2696
|
+
case isTypeStruct(abiType, structs):
|
|
2697
|
+
setProperty(
|
|
2698
|
+
orderStruct(
|
|
2699
|
+
unorderedObject2[myObjKeys[index]],
|
|
2700
|
+
structs[abiType].members
|
|
2701
|
+
)
|
|
2702
|
+
);
|
|
2703
|
+
break;
|
|
2704
|
+
case isTypeUint256(abiType): {
|
|
2705
|
+
const u256 = unorderedObject2[myObjKeys[index]];
|
|
2706
|
+
if (typeof u256 !== "object") {
|
|
2707
|
+
setProperty();
|
|
2708
|
+
break;
|
|
2709
|
+
}
|
|
2710
|
+
if (!("low" in u256 && "high" in u256)) {
|
|
2711
|
+
throw errorU256(abiParam.name);
|
|
2712
|
+
}
|
|
2713
|
+
setProperty({ low: u256.low, high: u256.high });
|
|
2714
|
+
break;
|
|
2715
|
+
}
|
|
2716
|
+
case isTypeTuple(abiType):
|
|
2717
|
+
setProperty(
|
|
2718
|
+
orderTuple(unorderedObject2[myObjKeys[index]], {
|
|
2719
|
+
name: "0",
|
|
2720
|
+
type: abiType
|
|
2721
|
+
})
|
|
2722
|
+
);
|
|
2723
|
+
break;
|
|
2724
|
+
case isTypeArray(abiType):
|
|
2725
|
+
setProperty(
|
|
2726
|
+
orderArray(unorderedObject2[myObjKeys[index]], {
|
|
2727
|
+
name: "0",
|
|
2728
|
+
type: abiType
|
|
2729
|
+
})
|
|
2730
|
+
);
|
|
2731
|
+
break;
|
|
2732
|
+
default:
|
|
2733
|
+
setProperty();
|
|
2734
|
+
}
|
|
2735
|
+
return orderedObject;
|
|
2736
|
+
}, {});
|
|
2737
|
+
return orderedObject2;
|
|
2738
|
+
}
|
|
2739
|
+
return orderStruct(unorderedObject, abiOfObject);
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2600
2742
|
// src/utils/calldata/requestParser.ts
|
|
2601
2743
|
function parseBaseTypes(type, val) {
|
|
2602
2744
|
switch (true) {
|
|
@@ -2650,6 +2792,14 @@ function parseCalldataValue(element, type, structs) {
|
|
|
2650
2792
|
return acc.concat(parsedData);
|
|
2651
2793
|
}, []);
|
|
2652
2794
|
}
|
|
2795
|
+
if (isTypeUint256(type)) {
|
|
2796
|
+
if (typeof element === "object") {
|
|
2797
|
+
const { low, high } = element;
|
|
2798
|
+
return [felt(low), felt(high)];
|
|
2799
|
+
}
|
|
2800
|
+
const el_uint256 = uint256(element);
|
|
2801
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
2802
|
+
}
|
|
2653
2803
|
if (typeof element === "object") {
|
|
2654
2804
|
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
2655
2805
|
}
|
|
@@ -2667,14 +2817,8 @@ function parseCalldataField(argsIterator, input, structs) {
|
|
|
2667
2817
|
value = splitLongString(value);
|
|
2668
2818
|
}
|
|
2669
2819
|
return parseCalldataValue(value, input.type, structs);
|
|
2670
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type)):
|
|
2820
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
|
|
2671
2821
|
return parseCalldataValue(value, type, structs);
|
|
2672
|
-
case isTypeUint256(type):
|
|
2673
|
-
if (typeof value === "object") {
|
|
2674
|
-
return [felt(value.low), felt(value.high)];
|
|
2675
|
-
}
|
|
2676
|
-
const el_uint256 = uint256(value);
|
|
2677
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
2678
2822
|
default:
|
|
2679
2823
|
return parseBaseTypes(type, value);
|
|
2680
2824
|
}
|
|
@@ -2706,8 +2850,8 @@ function parseResponseValue(responseIterator, element, structs) {
|
|
|
2706
2850
|
if (isTypeTuple(element.type)) {
|
|
2707
2851
|
const memberTypes = extractTupleMemberTypes(element.type);
|
|
2708
2852
|
return memberTypes.reduce((acc, it, idx) => {
|
|
2709
|
-
const name =
|
|
2710
|
-
const type =
|
|
2853
|
+
const name = it?.name ? it.name : idx;
|
|
2854
|
+
const type = it?.type ? it.type : it;
|
|
2711
2855
|
const el = { name, type };
|
|
2712
2856
|
acc[name] = parseResponseValue(responseIterator, el, structs);
|
|
2713
2857
|
return acc;
|
|
@@ -2915,6 +3059,12 @@ var CallData = class {
|
|
|
2915
3059
|
this.abi = abi;
|
|
2916
3060
|
this.structs = CallData.getAbiStruct(abi);
|
|
2917
3061
|
}
|
|
3062
|
+
/**
|
|
3063
|
+
* Validate arguments passed to the method as corresponding to the ones in the abi
|
|
3064
|
+
* @param type string - type of the method
|
|
3065
|
+
* @param method string - name of the method
|
|
3066
|
+
* @param args ArgsOrCalldata - arguments that are passed to the method
|
|
3067
|
+
*/
|
|
2918
3068
|
validate(type, method, args = []) {
|
|
2919
3069
|
if (type !== "DEPLOY") {
|
|
2920
3070
|
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
@@ -2939,14 +3089,41 @@ var CallData = class {
|
|
|
2939
3089
|
}
|
|
2940
3090
|
validateFields(abiMethod, args, this.structs);
|
|
2941
3091
|
}
|
|
2942
|
-
|
|
3092
|
+
/**
|
|
3093
|
+
* Compile contract callData with abi
|
|
3094
|
+
* Parse the calldata by using input fields from the abi for that method
|
|
3095
|
+
* @param method string - method name
|
|
3096
|
+
* @param args RawArgs - arguments passed to the method. Can be an array of arguments (in the order of abi definition), or an object constructed in conformity with abi (in this case, the parameter can be in a wrong order).
|
|
3097
|
+
* @return Calldata - parsed arguments in format that contract is expecting
|
|
3098
|
+
* @example
|
|
3099
|
+
* ```typescript
|
|
3100
|
+
* const calldata = myCallData.compile("constructor",["0x34a",[1,3n]]);
|
|
3101
|
+
* ```
|
|
3102
|
+
* ```typescript
|
|
3103
|
+
* const calldata2 = myCallData.compile("constructor",{list:[1,3n],balance:"0x34"}); // wrong order is valid
|
|
3104
|
+
* ```
|
|
3105
|
+
*/
|
|
3106
|
+
compile(method, argsCalldata) {
|
|
3107
|
+
const abiMethod = this.abi.find((abi) => abi.name === method);
|
|
3108
|
+
let args;
|
|
3109
|
+
if (Array.isArray(argsCalldata)) {
|
|
3110
|
+
args = argsCalldata;
|
|
3111
|
+
} else {
|
|
3112
|
+
const orderedObject = orderPropsByAbi(argsCalldata, abiMethod.inputs, this.structs);
|
|
3113
|
+
args = Object.values(orderedObject);
|
|
3114
|
+
validateFields(abiMethod, args, this.structs);
|
|
3115
|
+
}
|
|
2943
3116
|
const argsIterator = args[Symbol.iterator]();
|
|
2944
|
-
|
|
2945
|
-
return inputs.reduce(
|
|
3117
|
+
return abiMethod.inputs.reduce(
|
|
2946
3118
|
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
2947
3119
|
[]
|
|
2948
3120
|
);
|
|
2949
3121
|
}
|
|
3122
|
+
/**
|
|
3123
|
+
* Compile contract callData without abi
|
|
3124
|
+
* @param rawArgs RawArgs representing cairo method arguments or string array of compiled data
|
|
3125
|
+
* @returns Calldata
|
|
3126
|
+
*/
|
|
2950
3127
|
static compile(rawArgs) {
|
|
2951
3128
|
const createTree = (obj) => {
|
|
2952
3129
|
const getEntries = (o, prefix = "") => {
|
|
@@ -2981,6 +3158,12 @@ var CallData = class {
|
|
|
2981
3158
|
});
|
|
2982
3159
|
return callTreeArray;
|
|
2983
3160
|
}
|
|
3161
|
+
/**
|
|
3162
|
+
* Parse elements of the response array and structuring them into response object
|
|
3163
|
+
* @param method string - method name
|
|
3164
|
+
* @param response string[] - response from the method
|
|
3165
|
+
* @return Result - parsed response corresponding to the abi
|
|
3166
|
+
*/
|
|
2984
3167
|
parse(method, response) {
|
|
2985
3168
|
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
2986
3169
|
const responseIterator = response.flat()[Symbol.iterator]();
|
|
@@ -2994,13 +3177,30 @@ var CallData = class {
|
|
|
2994
3177
|
}, {});
|
|
2995
3178
|
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
2996
3179
|
}
|
|
3180
|
+
/**
|
|
3181
|
+
* Format cairo method response data to native js values based on provided format schema
|
|
3182
|
+
* @param method string - cairo method name
|
|
3183
|
+
* @param response string[] - cairo method response
|
|
3184
|
+
* @param format object - formatter object schema
|
|
3185
|
+
* @returns Result - parsed and formatted response object
|
|
3186
|
+
*/
|
|
2997
3187
|
format(method, response, format) {
|
|
2998
3188
|
const parsed = this.parse(method, response);
|
|
2999
3189
|
return formatter(parsed, format);
|
|
3000
3190
|
}
|
|
3191
|
+
/**
|
|
3192
|
+
* Helper to calculate inputs from abi
|
|
3193
|
+
* @param inputs AbiEntry
|
|
3194
|
+
* @returns number
|
|
3195
|
+
*/
|
|
3001
3196
|
static abiInputsLength(inputs) {
|
|
3002
3197
|
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3003
3198
|
}
|
|
3199
|
+
/**
|
|
3200
|
+
* Helper to extract structs from abi
|
|
3201
|
+
* @param abi Abi
|
|
3202
|
+
* @returns AbiStructs - structs from abi
|
|
3203
|
+
*/
|
|
3004
3204
|
static getAbiStruct(abi) {
|
|
3005
3205
|
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
3006
3206
|
(acc, abiEntry) => ({
|
|
@@ -3010,9 +3210,19 @@ var CallData = class {
|
|
|
3010
3210
|
{}
|
|
3011
3211
|
);
|
|
3012
3212
|
}
|
|
3213
|
+
/**
|
|
3214
|
+
* Helper: Compile HexCalldata | RawCalldata | RawArgs
|
|
3215
|
+
* @param rawCalldata HexCalldata | RawCalldata | RawArgs
|
|
3216
|
+
* @returns Calldata
|
|
3217
|
+
*/
|
|
3013
3218
|
static toCalldata(rawCalldata = []) {
|
|
3014
3219
|
return CallData.compile(rawCalldata);
|
|
3015
3220
|
}
|
|
3221
|
+
/**
|
|
3222
|
+
* Helper: Convert raw to HexCalldata
|
|
3223
|
+
* @param raw HexCalldata | RawCalldata | RawArgs
|
|
3224
|
+
* @returns HexCalldata
|
|
3225
|
+
*/
|
|
3016
3226
|
static toHex(raw = []) {
|
|
3017
3227
|
const calldata = CallData.compile(raw);
|
|
3018
3228
|
return calldata.map((it) => toHex(it));
|
|
@@ -3021,7 +3231,9 @@ var CallData = class {
|
|
|
3021
3231
|
|
|
3022
3232
|
// src/utils/fetchPonyfill.ts
|
|
3023
3233
|
import isomorphicFetch from "isomorphic-fetch";
|
|
3024
|
-
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch ||
|
|
3234
|
+
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || // use buildin fetch in browser if available
|
|
3235
|
+
typeof global !== "undefined" && global.fetch || // use buildin fetch in node, react-native and service worker if available
|
|
3236
|
+
isomorphicFetch;
|
|
3025
3237
|
|
|
3026
3238
|
// src/utils/hash.ts
|
|
3027
3239
|
var hash_exports = {};
|
|
@@ -3375,6 +3587,7 @@ function parseContract(contract) {
|
|
|
3375
3587
|
if (!isSierra(contract)) {
|
|
3376
3588
|
return {
|
|
3377
3589
|
...parsedContract,
|
|
3590
|
+
// TODO: Why do we gzip program object?
|
|
3378
3591
|
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
3379
3592
|
};
|
|
3380
3593
|
}
|
|
@@ -3627,6 +3840,7 @@ var Block = class {
|
|
|
3627
3840
|
this.tag = "pending";
|
|
3628
3841
|
}
|
|
3629
3842
|
}
|
|
3843
|
+
// TODO: fix any
|
|
3630
3844
|
get queryIdentifier() {
|
|
3631
3845
|
if (this.number !== null) {
|
|
3632
3846
|
return `blockNumber=${this.number}`;
|
|
@@ -3636,6 +3850,7 @@ var Block = class {
|
|
|
3636
3850
|
}
|
|
3637
3851
|
return `blockNumber=${this.tag}`;
|
|
3638
3852
|
}
|
|
3853
|
+
// TODO: fix any
|
|
3639
3854
|
get identifier() {
|
|
3640
3855
|
if (this.number !== null) {
|
|
3641
3856
|
return { block_number: this.number };
|
|
@@ -3683,17 +3898,17 @@ var RpcProvider = class {
|
|
|
3683
3898
|
}
|
|
3684
3899
|
}
|
|
3685
3900
|
async fetchEndpoint(method, params) {
|
|
3686
|
-
var _a;
|
|
3687
3901
|
try {
|
|
3688
3902
|
const rawResult = await this.fetch(method, params);
|
|
3689
3903
|
const { error, result } = await rawResult.json();
|
|
3690
3904
|
this.errorHandler(error);
|
|
3691
3905
|
return result;
|
|
3692
3906
|
} catch (error) {
|
|
3693
|
-
this.errorHandler(
|
|
3907
|
+
this.errorHandler(error?.response?.data);
|
|
3694
3908
|
throw error;
|
|
3695
3909
|
}
|
|
3696
3910
|
}
|
|
3911
|
+
// Methods from Interface
|
|
3697
3912
|
async getChainId() {
|
|
3698
3913
|
this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
|
|
3699
3914
|
return this.chainId;
|
|
@@ -3747,6 +3962,7 @@ var RpcProvider = class {
|
|
|
3747
3962
|
block_id
|
|
3748
3963
|
});
|
|
3749
3964
|
}
|
|
3965
|
+
// Methods from Interface
|
|
3750
3966
|
async getTransaction(txHash) {
|
|
3751
3967
|
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
3752
3968
|
}
|
|
@@ -3788,9 +4004,9 @@ var RpcProvider = class {
|
|
|
3788
4004
|
sender_address: invocation.contractAddress,
|
|
3789
4005
|
calldata: CallData.toHex(invocation.calldata),
|
|
3790
4006
|
signature: signatureToHexArray(invocation.signature),
|
|
3791
|
-
version: toHex(
|
|
4007
|
+
version: toHex(invocationDetails?.version || 0),
|
|
3792
4008
|
nonce: toHex(invocationDetails.nonce),
|
|
3793
|
-
max_fee: toHex(
|
|
4009
|
+
max_fee: toHex(invocationDetails?.maxFee || 0)
|
|
3794
4010
|
},
|
|
3795
4011
|
block_id
|
|
3796
4012
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -3805,12 +4021,13 @@ var RpcProvider = class {
|
|
|
3805
4021
|
program: contractDefinition.program,
|
|
3806
4022
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
3807
4023
|
abi: contractDefinition.abi
|
|
4024
|
+
// rpc 2.0
|
|
3808
4025
|
},
|
|
3809
4026
|
sender_address: senderAddress,
|
|
3810
4027
|
signature: signatureToHexArray(signature),
|
|
3811
|
-
version: toHex(
|
|
4028
|
+
version: toHex(details?.version || 0),
|
|
3812
4029
|
nonce: toHex(details.nonce),
|
|
3813
|
-
max_fee: toHex(
|
|
4030
|
+
max_fee: toHex(details?.maxFee || 0)
|
|
3814
4031
|
},
|
|
3815
4032
|
block_id
|
|
3816
4033
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -3826,9 +4043,9 @@ var RpcProvider = class {
|
|
|
3826
4043
|
class_hash: toHex(classHash),
|
|
3827
4044
|
contract_address_salt: toHex(addressSalt || 0),
|
|
3828
4045
|
signature: signatureToHexArray(signature),
|
|
3829
|
-
version: toHex(
|
|
4046
|
+
version: toHex(details?.version || 0),
|
|
3830
4047
|
nonce: toHex(details.nonce),
|
|
3831
|
-
max_fee: toHex(
|
|
4048
|
+
max_fee: toHex(details?.maxFee || 0)
|
|
3832
4049
|
},
|
|
3833
4050
|
block_id
|
|
3834
4051
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -3836,6 +4053,7 @@ var RpcProvider = class {
|
|
|
3836
4053
|
async getEstimateFeeBulk(_invocations, _blockIdentifier = this.blockIdentifier) {
|
|
3837
4054
|
throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
|
|
3838
4055
|
}
|
|
4056
|
+
// TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
|
|
3839
4057
|
async declareContract({ contractDefinition, signature, senderAddress }, details) {
|
|
3840
4058
|
if ("program" in contractDefinition) {
|
|
3841
4059
|
return this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
@@ -3844,6 +4062,7 @@ var RpcProvider = class {
|
|
|
3844
4062
|
program: contractDefinition.program,
|
|
3845
4063
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
3846
4064
|
abi: contractDefinition.abi
|
|
4065
|
+
// rpc 2.0
|
|
3847
4066
|
},
|
|
3848
4067
|
type: RPC.TransactionType.DECLARE,
|
|
3849
4068
|
version: "0x1",
|
|
@@ -3883,6 +4102,7 @@ var RpcProvider = class {
|
|
|
3883
4102
|
}
|
|
3884
4103
|
});
|
|
3885
4104
|
}
|
|
4105
|
+
// Methods from Interface
|
|
3886
4106
|
async callContract(call, blockIdentifier = this.blockIdentifier) {
|
|
3887
4107
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3888
4108
|
const result = await this.fetchEndpoint("starknet_call", {
|
|
@@ -3906,8 +4126,8 @@ var RpcProvider = class {
|
|
|
3906
4126
|
let { retries } = this;
|
|
3907
4127
|
let onchain = false;
|
|
3908
4128
|
let txReceipt = {};
|
|
3909
|
-
const retryInterval =
|
|
3910
|
-
const successStates =
|
|
4129
|
+
const retryInterval = options?.retryInterval ?? 8e3;
|
|
4130
|
+
const successStates = options?.successStates ?? [
|
|
3911
4131
|
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
3912
4132
|
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
3913
4133
|
"PENDING" /* PENDING */
|
|
@@ -3941,16 +4161,41 @@ var RpcProvider = class {
|
|
|
3941
4161
|
await wait(retryInterval);
|
|
3942
4162
|
return txReceipt;
|
|
3943
4163
|
}
|
|
4164
|
+
/**
|
|
4165
|
+
* Gets the transaction count from a block.
|
|
4166
|
+
*
|
|
4167
|
+
*
|
|
4168
|
+
* @param blockIdentifier
|
|
4169
|
+
* @returns Number of transactions
|
|
4170
|
+
*/
|
|
3944
4171
|
async getTransactionCount(blockIdentifier = this.blockIdentifier) {
|
|
3945
4172
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3946
4173
|
return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
|
|
3947
4174
|
}
|
|
4175
|
+
/**
|
|
4176
|
+
* Gets the latest block number
|
|
4177
|
+
*
|
|
4178
|
+
*
|
|
4179
|
+
* @returns Number of the latest block
|
|
4180
|
+
*/
|
|
3948
4181
|
async getBlockNumber() {
|
|
3949
4182
|
return this.fetchEndpoint("starknet_blockNumber");
|
|
3950
4183
|
}
|
|
4184
|
+
/**
|
|
4185
|
+
* Gets syncing status of the node
|
|
4186
|
+
*
|
|
4187
|
+
*
|
|
4188
|
+
* @returns Object with the stats data
|
|
4189
|
+
*/
|
|
3951
4190
|
async getSyncingStats() {
|
|
3952
4191
|
return this.fetchEndpoint("starknet_syncing");
|
|
3953
4192
|
}
|
|
4193
|
+
/**
|
|
4194
|
+
* Gets all the events filtered
|
|
4195
|
+
*
|
|
4196
|
+
*
|
|
4197
|
+
* @returns events and the pagination of the events
|
|
4198
|
+
*/
|
|
3954
4199
|
async getEvents(eventFilter) {
|
|
3955
4200
|
return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
|
|
3956
4201
|
}
|
|
@@ -4001,6 +4246,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
|
|
|
4001
4246
|
transaction_hash: res.transaction_hash,
|
|
4002
4247
|
status: res.status,
|
|
4003
4248
|
messages_sent: res.l2_to_l1_messages,
|
|
4249
|
+
// TODO: parse
|
|
4004
4250
|
events: res.events,
|
|
4005
4251
|
..."block_hash" in res && { block_hash: res.block_hash },
|
|
4006
4252
|
..."block_number" in res && { block_number: res.block_number },
|
|
@@ -4008,6 +4254,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
|
|
|
4008
4254
|
..."transaction_index" in res && { transaction_index: res.transaction_index },
|
|
4009
4255
|
..."execution_resources" in res && { execution_resources: res.execution_resources },
|
|
4010
4256
|
..."l1_to_l2_consumed_message" in res && {
|
|
4257
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
4011
4258
|
l1_to_l2_consumed_message: res["l1_to_l2_consumed_message"]
|
|
4012
4259
|
},
|
|
4013
4260
|
..."transaction_failure_reason" in res && {
|
|
@@ -4119,6 +4366,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
|
|
|
4119
4366
|
}
|
|
4120
4367
|
};
|
|
4121
4368
|
}
|
|
4369
|
+
// TODO: Define response as new type as it diff from ContractClass
|
|
4122
4370
|
parseSierraContractClassResponse(res) {
|
|
4123
4371
|
return {
|
|
4124
4372
|
...res,
|
|
@@ -4180,9 +4428,9 @@ var SequencerProvider = class {
|
|
|
4180
4428
|
);
|
|
4181
4429
|
this.gatewayUrl = buildUrl(this.baseUrl, "gateway", optionsOrProvider.gatewayUrl);
|
|
4182
4430
|
}
|
|
4183
|
-
this.chainId =
|
|
4431
|
+
this.chainId = optionsOrProvider?.chainId ?? SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
|
|
4184
4432
|
this.headers = optionsOrProvider.headers;
|
|
4185
|
-
this.blockIdentifier =
|
|
4433
|
+
this.blockIdentifier = optionsOrProvider?.blockIdentifier || defaultOptions2.blockIdentifier;
|
|
4186
4434
|
}
|
|
4187
4435
|
static getNetworkFromName(name) {
|
|
4188
4436
|
switch (name) {
|
|
@@ -4248,6 +4496,7 @@ var SequencerProvider = class {
|
|
|
4248
4496
|
}
|
|
4249
4497
|
return this.headers;
|
|
4250
4498
|
}
|
|
4499
|
+
// typesafe fetch
|
|
4251
4500
|
async fetchEndpoint(endpoint, ...[query, request]) {
|
|
4252
4501
|
const baseUrl = this.getFetchUrl(endpoint);
|
|
4253
4502
|
const method = this.getFetchMethod(endpoint);
|
|
@@ -4260,9 +4509,9 @@ var SequencerProvider = class {
|
|
|
4260
4509
|
}
|
|
4261
4510
|
async fetch(endpoint, options) {
|
|
4262
4511
|
const url = buildUrl(this.baseUrl, "", endpoint);
|
|
4263
|
-
const method =
|
|
4512
|
+
const method = options?.method ?? "GET";
|
|
4264
4513
|
const headers = this.getHeaders(method);
|
|
4265
|
-
const body = stringify2(options
|
|
4514
|
+
const body = stringify2(options?.body);
|
|
4266
4515
|
try {
|
|
4267
4516
|
const response = await fetchPonyfill_default(url, {
|
|
4268
4517
|
method,
|
|
@@ -4279,7 +4528,7 @@ var SequencerProvider = class {
|
|
|
4279
4528
|
}
|
|
4280
4529
|
throw new GatewayError(responseBody.message, responseBody.code);
|
|
4281
4530
|
}
|
|
4282
|
-
const parseChoice =
|
|
4531
|
+
const parseChoice = options?.parseAlwaysAsBigInt ? parseAlwaysAsBig : parse2;
|
|
4283
4532
|
return parseChoice(textResponse);
|
|
4284
4533
|
} catch (error) {
|
|
4285
4534
|
if (error instanceof Error && !(error instanceof LibraryError))
|
|
@@ -4295,6 +4544,9 @@ var SequencerProvider = class {
|
|
|
4295
4544
|
"call_contract",
|
|
4296
4545
|
{ blockIdentifier },
|
|
4297
4546
|
{
|
|
4547
|
+
// TODO - determine best choice once both are fully supported in devnet
|
|
4548
|
+
// signature: [],
|
|
4549
|
+
// sender_address: contractAddress,
|
|
4298
4550
|
contract_address: contractAddress,
|
|
4299
4551
|
entry_point_selector: getSelectorFromName(entryPointSelector),
|
|
4300
4552
|
calldata: CallData.compile(calldata)
|
|
@@ -4413,7 +4665,7 @@ var SequencerProvider = class {
|
|
|
4413
4665
|
sender_address: invocation.contractAddress,
|
|
4414
4666
|
calldata: CallData.compile(invocation.calldata ?? []),
|
|
4415
4667
|
signature: signatureToDecimalArray(invocation.signature),
|
|
4416
|
-
version: toHex(
|
|
4668
|
+
version: toHex(invocationDetails?.version || 1),
|
|
4417
4669
|
nonce: toHex(invocationDetails.nonce)
|
|
4418
4670
|
}
|
|
4419
4671
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -4428,7 +4680,7 @@ var SequencerProvider = class {
|
|
|
4428
4680
|
sender_address: senderAddress,
|
|
4429
4681
|
contract_class: contractDefinition,
|
|
4430
4682
|
signature: signatureToDecimalArray(signature),
|
|
4431
|
-
version: toHex(
|
|
4683
|
+
version: toHex(details?.version || toBigInt(feeTransactionVersion)),
|
|
4432
4684
|
nonce: toHex(details.nonce)
|
|
4433
4685
|
}
|
|
4434
4686
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -4457,7 +4709,7 @@ var SequencerProvider = class {
|
|
|
4457
4709
|
constructor_calldata: CallData.compile(constructorCalldata || []),
|
|
4458
4710
|
contract_address_salt: toHex(addressSalt || 0),
|
|
4459
4711
|
signature: signatureToDecimalArray(signature),
|
|
4460
|
-
version: toHex(
|
|
4712
|
+
version: toHex(details?.version || 0),
|
|
4461
4713
|
nonce: toHex(details.nonce)
|
|
4462
4714
|
}
|
|
4463
4715
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -4488,7 +4740,7 @@ var SequencerProvider = class {
|
|
|
4488
4740
|
return {
|
|
4489
4741
|
...res,
|
|
4490
4742
|
signature: bigNumberishArrayToDecimalStringArray(formatSignature(invocation.signature)),
|
|
4491
|
-
version: toHex(toBigInt(
|
|
4743
|
+
version: toHex(toBigInt(invocation?.version || 1)),
|
|
4492
4744
|
nonce: toHex(toBigInt(invocation.nonce))
|
|
4493
4745
|
};
|
|
4494
4746
|
});
|
|
@@ -4503,8 +4755,8 @@ var SequencerProvider = class {
|
|
|
4503
4755
|
const errorStates = ["REJECTED" /* REJECTED */, "NOT_RECEIVED" /* NOT_RECEIVED */];
|
|
4504
4756
|
let onchain = false;
|
|
4505
4757
|
let res;
|
|
4506
|
-
const retryInterval =
|
|
4507
|
-
const successStates =
|
|
4758
|
+
const retryInterval = options?.retryInterval ?? 8e3;
|
|
4759
|
+
const successStates = options?.successStates ?? [
|
|
4508
4760
|
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
4509
4761
|
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
4510
4762
|
"PENDING" /* PENDING */
|
|
@@ -4525,13 +4777,33 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
4525
4777
|
const txReceipt = await this.getTransactionReceipt(txHash);
|
|
4526
4778
|
return txReceipt;
|
|
4527
4779
|
}
|
|
4780
|
+
/**
|
|
4781
|
+
* Gets the status of a transaction.
|
|
4782
|
+
*
|
|
4783
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
4784
|
+
*
|
|
4785
|
+
* @param txHash
|
|
4786
|
+
* @returns the transaction status object \{ block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN \}
|
|
4787
|
+
*/
|
|
4528
4788
|
async getTransactionStatus(txHash) {
|
|
4529
4789
|
const txHashHex = toHex(txHash);
|
|
4530
4790
|
return this.fetchEndpoint("get_transaction_status", { transactionHash: txHashHex });
|
|
4531
4791
|
}
|
|
4792
|
+
/**
|
|
4793
|
+
* Gets the smart contract address on the goerli testnet.
|
|
4794
|
+
*
|
|
4795
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
|
|
4796
|
+
* @returns starknet smart contract addresses
|
|
4797
|
+
*/
|
|
4532
4798
|
async getContractAddresses() {
|
|
4533
4799
|
return this.fetchEndpoint("get_contract_addresses");
|
|
4534
4800
|
}
|
|
4801
|
+
/**
|
|
4802
|
+
* Gets the transaction trace from a tx id.
|
|
4803
|
+
*
|
|
4804
|
+
* @param txHash
|
|
4805
|
+
* @returns the transaction trace
|
|
4806
|
+
*/
|
|
4535
4807
|
async getTransactionTrace(txHash) {
|
|
4536
4808
|
const txHashHex = toHex(txHash);
|
|
4537
4809
|
return this.fetchEndpoint("get_transaction_trace", { transactionHash: txHashHex });
|
|
@@ -4554,9 +4826,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
4554
4826
|
sender_address: invocation.contractAddress,
|
|
4555
4827
|
calldata: CallData.compile(invocation.calldata ?? []),
|
|
4556
4828
|
signature: signatureToDecimalArray(invocation.signature),
|
|
4557
|
-
version: toHex(
|
|
4829
|
+
version: toHex(invocationDetails?.version || 1),
|
|
4558
4830
|
nonce: toHex(invocationDetails.nonce),
|
|
4559
|
-
max_fee: toHex(
|
|
4831
|
+
max_fee: toHex(invocationDetails?.maxFee || 0)
|
|
4560
4832
|
}
|
|
4561
4833
|
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
4562
4834
|
}
|
|
@@ -4566,6 +4838,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
4566
4838
|
this.responseParser.parseGetStateUpdateResponse
|
|
4567
4839
|
);
|
|
4568
4840
|
}
|
|
4841
|
+
// consider adding an optional trace retrieval parameter to the getBlock method
|
|
4569
4842
|
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
4570
4843
|
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4571
4844
|
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
@@ -4750,6 +5023,13 @@ function getCalldata(args, callback) {
|
|
|
4750
5023
|
return callback();
|
|
4751
5024
|
}
|
|
4752
5025
|
var Contract = class {
|
|
5026
|
+
/**
|
|
5027
|
+
* Contract class to handle contract methods
|
|
5028
|
+
*
|
|
5029
|
+
* @param abi - Abi of the contract object
|
|
5030
|
+
* @param address (optional) - address to connect to
|
|
5031
|
+
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
5032
|
+
*/
|
|
4753
5033
|
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
4754
5034
|
this.address = address && address.toLowerCase();
|
|
4755
5035
|
this.providerOrAccount = providerOrAccount;
|
|
@@ -4912,6 +5192,13 @@ var ContractFactory = class {
|
|
|
4912
5192
|
this.classHash = classHash;
|
|
4913
5193
|
this.CallData = new CallData(abi);
|
|
4914
5194
|
}
|
|
5195
|
+
/**
|
|
5196
|
+
* Deploys contract and returns new instance of the Contract
|
|
5197
|
+
*
|
|
5198
|
+
* @param args - Array of the constructor arguments for deployment
|
|
5199
|
+
* @param options (optional) Object - parseRequest, parseResponse, addressSalt
|
|
5200
|
+
* @returns deployed Contract
|
|
5201
|
+
*/
|
|
4915
5202
|
async deploy(...args) {
|
|
4916
5203
|
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
4917
5204
|
const constructorCalldata = getCalldata(param, () => {
|
|
@@ -4938,13 +5225,26 @@ var ContractFactory = class {
|
|
|
4938
5225
|
contractInstance.deployTransactionHash = transaction_hash;
|
|
4939
5226
|
return contractInstance;
|
|
4940
5227
|
}
|
|
5228
|
+
/**
|
|
5229
|
+
* Attaches to new Account
|
|
5230
|
+
*
|
|
5231
|
+
* @param account - new Provider or Account to attach to
|
|
5232
|
+
* @returns ContractFactory
|
|
5233
|
+
*/
|
|
4941
5234
|
connect(account) {
|
|
4942
5235
|
this.account = account;
|
|
4943
5236
|
return this;
|
|
4944
5237
|
}
|
|
5238
|
+
/**
|
|
5239
|
+
* Attaches current abi and account to the new address
|
|
5240
|
+
*
|
|
5241
|
+
* @param address - Contract address
|
|
5242
|
+
* @returns Contract
|
|
5243
|
+
*/
|
|
4945
5244
|
attach(address) {
|
|
4946
5245
|
return new Contract(this.abi, address, this.account);
|
|
4947
5246
|
}
|
|
5247
|
+
// ethers.js' getDeployTransaction cant be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
|
|
4948
5248
|
};
|
|
4949
5249
|
|
|
4950
5250
|
// src/signer/interface.ts
|
|
@@ -5523,6 +5823,14 @@ var Account = class extends Provider {
|
|
|
5523
5823
|
}
|
|
5524
5824
|
);
|
|
5525
5825
|
}
|
|
5826
|
+
/**
|
|
5827
|
+
* First check if contract is already declared, if not declare it
|
|
5828
|
+
* If contract already declared returned transaction_hash is ''.
|
|
5829
|
+
* Method will pass even if contract is already declared
|
|
5830
|
+
* @param payload DeclareContractPayload
|
|
5831
|
+
* @param transactionsDetail (optional) InvocationsDetails = \{\}
|
|
5832
|
+
* @returns DeclareContractResponse
|
|
5833
|
+
*/
|
|
5526
5834
|
async declareIfNot(payload, transactionsDetail = {}) {
|
|
5527
5835
|
const declareContractPayload = extractContractHashes(payload);
|
|
5528
5836
|
try {
|
|
@@ -5703,6 +6011,9 @@ var Account = class extends Provider {
|
|
|
5703
6011
|
}
|
|
5704
6012
|
return feeEstimate.suggestedMaxFee;
|
|
5705
6013
|
}
|
|
6014
|
+
/**
|
|
6015
|
+
* will be renamed to buildDeclareContractTransaction
|
|
6016
|
+
*/
|
|
5706
6017
|
async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
|
|
5707
6018
|
const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
|
|
5708
6019
|
const contractDefinition = parseContract(contract);
|