starknet 5.10.2 → 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 +6 -0
- package/dist/index.d.ts +324 -370
- package/dist/index.global.js +684 -56
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +343 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +339 -30
- 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) {
|
|
@@ -2708,8 +2850,8 @@ function parseResponseValue(responseIterator, element, structs) {
|
|
|
2708
2850
|
if (isTypeTuple(element.type)) {
|
|
2709
2851
|
const memberTypes = extractTupleMemberTypes(element.type);
|
|
2710
2852
|
return memberTypes.reduce((acc, it, idx) => {
|
|
2711
|
-
const name =
|
|
2712
|
-
const type =
|
|
2853
|
+
const name = it?.name ? it.name : idx;
|
|
2854
|
+
const type = it?.type ? it.type : it;
|
|
2713
2855
|
const el = { name, type };
|
|
2714
2856
|
acc[name] = parseResponseValue(responseIterator, el, structs);
|
|
2715
2857
|
return acc;
|
|
@@ -2917,6 +3059,12 @@ var CallData = class {
|
|
|
2917
3059
|
this.abi = abi;
|
|
2918
3060
|
this.structs = CallData.getAbiStruct(abi);
|
|
2919
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
|
+
*/
|
|
2920
3068
|
validate(type, method, args = []) {
|
|
2921
3069
|
if (type !== "DEPLOY") {
|
|
2922
3070
|
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
@@ -2941,14 +3089,41 @@ var CallData = class {
|
|
|
2941
3089
|
}
|
|
2942
3090
|
validateFields(abiMethod, args, this.structs);
|
|
2943
3091
|
}
|
|
2944
|
-
|
|
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
|
+
}
|
|
2945
3116
|
const argsIterator = args[Symbol.iterator]();
|
|
2946
|
-
|
|
2947
|
-
return inputs.reduce(
|
|
3117
|
+
return abiMethod.inputs.reduce(
|
|
2948
3118
|
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
2949
3119
|
[]
|
|
2950
3120
|
);
|
|
2951
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
|
+
*/
|
|
2952
3127
|
static compile(rawArgs) {
|
|
2953
3128
|
const createTree = (obj) => {
|
|
2954
3129
|
const getEntries = (o, prefix = "") => {
|
|
@@ -2983,6 +3158,12 @@ var CallData = class {
|
|
|
2983
3158
|
});
|
|
2984
3159
|
return callTreeArray;
|
|
2985
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
|
+
*/
|
|
2986
3167
|
parse(method, response) {
|
|
2987
3168
|
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
2988
3169
|
const responseIterator = response.flat()[Symbol.iterator]();
|
|
@@ -2996,13 +3177,30 @@ var CallData = class {
|
|
|
2996
3177
|
}, {});
|
|
2997
3178
|
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
2998
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
|
+
*/
|
|
2999
3187
|
format(method, response, format) {
|
|
3000
3188
|
const parsed = this.parse(method, response);
|
|
3001
3189
|
return formatter(parsed, format);
|
|
3002
3190
|
}
|
|
3191
|
+
/**
|
|
3192
|
+
* Helper to calculate inputs from abi
|
|
3193
|
+
* @param inputs AbiEntry
|
|
3194
|
+
* @returns number
|
|
3195
|
+
*/
|
|
3003
3196
|
static abiInputsLength(inputs) {
|
|
3004
3197
|
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3005
3198
|
}
|
|
3199
|
+
/**
|
|
3200
|
+
* Helper to extract structs from abi
|
|
3201
|
+
* @param abi Abi
|
|
3202
|
+
* @returns AbiStructs - structs from abi
|
|
3203
|
+
*/
|
|
3006
3204
|
static getAbiStruct(abi) {
|
|
3007
3205
|
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
3008
3206
|
(acc, abiEntry) => ({
|
|
@@ -3012,9 +3210,19 @@ var CallData = class {
|
|
|
3012
3210
|
{}
|
|
3013
3211
|
);
|
|
3014
3212
|
}
|
|
3213
|
+
/**
|
|
3214
|
+
* Helper: Compile HexCalldata | RawCalldata | RawArgs
|
|
3215
|
+
* @param rawCalldata HexCalldata | RawCalldata | RawArgs
|
|
3216
|
+
* @returns Calldata
|
|
3217
|
+
*/
|
|
3015
3218
|
static toCalldata(rawCalldata = []) {
|
|
3016
3219
|
return CallData.compile(rawCalldata);
|
|
3017
3220
|
}
|
|
3221
|
+
/**
|
|
3222
|
+
* Helper: Convert raw to HexCalldata
|
|
3223
|
+
* @param raw HexCalldata | RawCalldata | RawArgs
|
|
3224
|
+
* @returns HexCalldata
|
|
3225
|
+
*/
|
|
3018
3226
|
static toHex(raw = []) {
|
|
3019
3227
|
const calldata = CallData.compile(raw);
|
|
3020
3228
|
return calldata.map((it) => toHex(it));
|
|
@@ -3023,7 +3231,9 @@ var CallData = class {
|
|
|
3023
3231
|
|
|
3024
3232
|
// src/utils/fetchPonyfill.ts
|
|
3025
3233
|
import isomorphicFetch from "isomorphic-fetch";
|
|
3026
|
-
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;
|
|
3027
3237
|
|
|
3028
3238
|
// src/utils/hash.ts
|
|
3029
3239
|
var hash_exports = {};
|
|
@@ -3377,6 +3587,7 @@ function parseContract(contract) {
|
|
|
3377
3587
|
if (!isSierra(contract)) {
|
|
3378
3588
|
return {
|
|
3379
3589
|
...parsedContract,
|
|
3590
|
+
// TODO: Why do we gzip program object?
|
|
3380
3591
|
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
3381
3592
|
};
|
|
3382
3593
|
}
|
|
@@ -3629,6 +3840,7 @@ var Block = class {
|
|
|
3629
3840
|
this.tag = "pending";
|
|
3630
3841
|
}
|
|
3631
3842
|
}
|
|
3843
|
+
// TODO: fix any
|
|
3632
3844
|
get queryIdentifier() {
|
|
3633
3845
|
if (this.number !== null) {
|
|
3634
3846
|
return `blockNumber=${this.number}`;
|
|
@@ -3638,6 +3850,7 @@ var Block = class {
|
|
|
3638
3850
|
}
|
|
3639
3851
|
return `blockNumber=${this.tag}`;
|
|
3640
3852
|
}
|
|
3853
|
+
// TODO: fix any
|
|
3641
3854
|
get identifier() {
|
|
3642
3855
|
if (this.number !== null) {
|
|
3643
3856
|
return { block_number: this.number };
|
|
@@ -3685,17 +3898,17 @@ var RpcProvider = class {
|
|
|
3685
3898
|
}
|
|
3686
3899
|
}
|
|
3687
3900
|
async fetchEndpoint(method, params) {
|
|
3688
|
-
var _a;
|
|
3689
3901
|
try {
|
|
3690
3902
|
const rawResult = await this.fetch(method, params);
|
|
3691
3903
|
const { error, result } = await rawResult.json();
|
|
3692
3904
|
this.errorHandler(error);
|
|
3693
3905
|
return result;
|
|
3694
3906
|
} catch (error) {
|
|
3695
|
-
this.errorHandler(
|
|
3907
|
+
this.errorHandler(error?.response?.data);
|
|
3696
3908
|
throw error;
|
|
3697
3909
|
}
|
|
3698
3910
|
}
|
|
3911
|
+
// Methods from Interface
|
|
3699
3912
|
async getChainId() {
|
|
3700
3913
|
this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
|
|
3701
3914
|
return this.chainId;
|
|
@@ -3749,6 +3962,7 @@ var RpcProvider = class {
|
|
|
3749
3962
|
block_id
|
|
3750
3963
|
});
|
|
3751
3964
|
}
|
|
3965
|
+
// Methods from Interface
|
|
3752
3966
|
async getTransaction(txHash) {
|
|
3753
3967
|
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
3754
3968
|
}
|
|
@@ -3790,9 +4004,9 @@ var RpcProvider = class {
|
|
|
3790
4004
|
sender_address: invocation.contractAddress,
|
|
3791
4005
|
calldata: CallData.toHex(invocation.calldata),
|
|
3792
4006
|
signature: signatureToHexArray(invocation.signature),
|
|
3793
|
-
version: toHex(
|
|
4007
|
+
version: toHex(invocationDetails?.version || 0),
|
|
3794
4008
|
nonce: toHex(invocationDetails.nonce),
|
|
3795
|
-
max_fee: toHex(
|
|
4009
|
+
max_fee: toHex(invocationDetails?.maxFee || 0)
|
|
3796
4010
|
},
|
|
3797
4011
|
block_id
|
|
3798
4012
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -3807,12 +4021,13 @@ var RpcProvider = class {
|
|
|
3807
4021
|
program: contractDefinition.program,
|
|
3808
4022
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
3809
4023
|
abi: contractDefinition.abi
|
|
4024
|
+
// rpc 2.0
|
|
3810
4025
|
},
|
|
3811
4026
|
sender_address: senderAddress,
|
|
3812
4027
|
signature: signatureToHexArray(signature),
|
|
3813
|
-
version: toHex(
|
|
4028
|
+
version: toHex(details?.version || 0),
|
|
3814
4029
|
nonce: toHex(details.nonce),
|
|
3815
|
-
max_fee: toHex(
|
|
4030
|
+
max_fee: toHex(details?.maxFee || 0)
|
|
3816
4031
|
},
|
|
3817
4032
|
block_id
|
|
3818
4033
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -3828,9 +4043,9 @@ var RpcProvider = class {
|
|
|
3828
4043
|
class_hash: toHex(classHash),
|
|
3829
4044
|
contract_address_salt: toHex(addressSalt || 0),
|
|
3830
4045
|
signature: signatureToHexArray(signature),
|
|
3831
|
-
version: toHex(
|
|
4046
|
+
version: toHex(details?.version || 0),
|
|
3832
4047
|
nonce: toHex(details.nonce),
|
|
3833
|
-
max_fee: toHex(
|
|
4048
|
+
max_fee: toHex(details?.maxFee || 0)
|
|
3834
4049
|
},
|
|
3835
4050
|
block_id
|
|
3836
4051
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -3838,6 +4053,7 @@ var RpcProvider = class {
|
|
|
3838
4053
|
async getEstimateFeeBulk(_invocations, _blockIdentifier = this.blockIdentifier) {
|
|
3839
4054
|
throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
|
|
3840
4055
|
}
|
|
4056
|
+
// TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
|
|
3841
4057
|
async declareContract({ contractDefinition, signature, senderAddress }, details) {
|
|
3842
4058
|
if ("program" in contractDefinition) {
|
|
3843
4059
|
return this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
@@ -3846,6 +4062,7 @@ var RpcProvider = class {
|
|
|
3846
4062
|
program: contractDefinition.program,
|
|
3847
4063
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
3848
4064
|
abi: contractDefinition.abi
|
|
4065
|
+
// rpc 2.0
|
|
3849
4066
|
},
|
|
3850
4067
|
type: RPC.TransactionType.DECLARE,
|
|
3851
4068
|
version: "0x1",
|
|
@@ -3885,6 +4102,7 @@ var RpcProvider = class {
|
|
|
3885
4102
|
}
|
|
3886
4103
|
});
|
|
3887
4104
|
}
|
|
4105
|
+
// Methods from Interface
|
|
3888
4106
|
async callContract(call, blockIdentifier = this.blockIdentifier) {
|
|
3889
4107
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3890
4108
|
const result = await this.fetchEndpoint("starknet_call", {
|
|
@@ -3908,8 +4126,8 @@ var RpcProvider = class {
|
|
|
3908
4126
|
let { retries } = this;
|
|
3909
4127
|
let onchain = false;
|
|
3910
4128
|
let txReceipt = {};
|
|
3911
|
-
const retryInterval =
|
|
3912
|
-
const successStates =
|
|
4129
|
+
const retryInterval = options?.retryInterval ?? 8e3;
|
|
4130
|
+
const successStates = options?.successStates ?? [
|
|
3913
4131
|
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
3914
4132
|
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
3915
4133
|
"PENDING" /* PENDING */
|
|
@@ -3943,16 +4161,41 @@ var RpcProvider = class {
|
|
|
3943
4161
|
await wait(retryInterval);
|
|
3944
4162
|
return txReceipt;
|
|
3945
4163
|
}
|
|
4164
|
+
/**
|
|
4165
|
+
* Gets the transaction count from a block.
|
|
4166
|
+
*
|
|
4167
|
+
*
|
|
4168
|
+
* @param blockIdentifier
|
|
4169
|
+
* @returns Number of transactions
|
|
4170
|
+
*/
|
|
3946
4171
|
async getTransactionCount(blockIdentifier = this.blockIdentifier) {
|
|
3947
4172
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3948
4173
|
return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
|
|
3949
4174
|
}
|
|
4175
|
+
/**
|
|
4176
|
+
* Gets the latest block number
|
|
4177
|
+
*
|
|
4178
|
+
*
|
|
4179
|
+
* @returns Number of the latest block
|
|
4180
|
+
*/
|
|
3950
4181
|
async getBlockNumber() {
|
|
3951
4182
|
return this.fetchEndpoint("starknet_blockNumber");
|
|
3952
4183
|
}
|
|
4184
|
+
/**
|
|
4185
|
+
* Gets syncing status of the node
|
|
4186
|
+
*
|
|
4187
|
+
*
|
|
4188
|
+
* @returns Object with the stats data
|
|
4189
|
+
*/
|
|
3953
4190
|
async getSyncingStats() {
|
|
3954
4191
|
return this.fetchEndpoint("starknet_syncing");
|
|
3955
4192
|
}
|
|
4193
|
+
/**
|
|
4194
|
+
* Gets all the events filtered
|
|
4195
|
+
*
|
|
4196
|
+
*
|
|
4197
|
+
* @returns events and the pagination of the events
|
|
4198
|
+
*/
|
|
3956
4199
|
async getEvents(eventFilter) {
|
|
3957
4200
|
return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
|
|
3958
4201
|
}
|
|
@@ -4003,6 +4246,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
|
|
|
4003
4246
|
transaction_hash: res.transaction_hash,
|
|
4004
4247
|
status: res.status,
|
|
4005
4248
|
messages_sent: res.l2_to_l1_messages,
|
|
4249
|
+
// TODO: parse
|
|
4006
4250
|
events: res.events,
|
|
4007
4251
|
..."block_hash" in res && { block_hash: res.block_hash },
|
|
4008
4252
|
..."block_number" in res && { block_number: res.block_number },
|
|
@@ -4010,6 +4254,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
|
|
|
4010
4254
|
..."transaction_index" in res && { transaction_index: res.transaction_index },
|
|
4011
4255
|
..."execution_resources" in res && { execution_resources: res.execution_resources },
|
|
4012
4256
|
..."l1_to_l2_consumed_message" in res && {
|
|
4257
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
4013
4258
|
l1_to_l2_consumed_message: res["l1_to_l2_consumed_message"]
|
|
4014
4259
|
},
|
|
4015
4260
|
..."transaction_failure_reason" in res && {
|
|
@@ -4121,6 +4366,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
|
|
|
4121
4366
|
}
|
|
4122
4367
|
};
|
|
4123
4368
|
}
|
|
4369
|
+
// TODO: Define response as new type as it diff from ContractClass
|
|
4124
4370
|
parseSierraContractClassResponse(res) {
|
|
4125
4371
|
return {
|
|
4126
4372
|
...res,
|
|
@@ -4182,9 +4428,9 @@ var SequencerProvider = class {
|
|
|
4182
4428
|
);
|
|
4183
4429
|
this.gatewayUrl = buildUrl(this.baseUrl, "gateway", optionsOrProvider.gatewayUrl);
|
|
4184
4430
|
}
|
|
4185
|
-
this.chainId =
|
|
4431
|
+
this.chainId = optionsOrProvider?.chainId ?? SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
|
|
4186
4432
|
this.headers = optionsOrProvider.headers;
|
|
4187
|
-
this.blockIdentifier =
|
|
4433
|
+
this.blockIdentifier = optionsOrProvider?.blockIdentifier || defaultOptions2.blockIdentifier;
|
|
4188
4434
|
}
|
|
4189
4435
|
static getNetworkFromName(name) {
|
|
4190
4436
|
switch (name) {
|
|
@@ -4250,6 +4496,7 @@ var SequencerProvider = class {
|
|
|
4250
4496
|
}
|
|
4251
4497
|
return this.headers;
|
|
4252
4498
|
}
|
|
4499
|
+
// typesafe fetch
|
|
4253
4500
|
async fetchEndpoint(endpoint, ...[query, request]) {
|
|
4254
4501
|
const baseUrl = this.getFetchUrl(endpoint);
|
|
4255
4502
|
const method = this.getFetchMethod(endpoint);
|
|
@@ -4262,9 +4509,9 @@ var SequencerProvider = class {
|
|
|
4262
4509
|
}
|
|
4263
4510
|
async fetch(endpoint, options) {
|
|
4264
4511
|
const url = buildUrl(this.baseUrl, "", endpoint);
|
|
4265
|
-
const method =
|
|
4512
|
+
const method = options?.method ?? "GET";
|
|
4266
4513
|
const headers = this.getHeaders(method);
|
|
4267
|
-
const body = stringify2(options
|
|
4514
|
+
const body = stringify2(options?.body);
|
|
4268
4515
|
try {
|
|
4269
4516
|
const response = await fetchPonyfill_default(url, {
|
|
4270
4517
|
method,
|
|
@@ -4281,7 +4528,7 @@ var SequencerProvider = class {
|
|
|
4281
4528
|
}
|
|
4282
4529
|
throw new GatewayError(responseBody.message, responseBody.code);
|
|
4283
4530
|
}
|
|
4284
|
-
const parseChoice =
|
|
4531
|
+
const parseChoice = options?.parseAlwaysAsBigInt ? parseAlwaysAsBig : parse2;
|
|
4285
4532
|
return parseChoice(textResponse);
|
|
4286
4533
|
} catch (error) {
|
|
4287
4534
|
if (error instanceof Error && !(error instanceof LibraryError))
|
|
@@ -4297,6 +4544,9 @@ var SequencerProvider = class {
|
|
|
4297
4544
|
"call_contract",
|
|
4298
4545
|
{ blockIdentifier },
|
|
4299
4546
|
{
|
|
4547
|
+
// TODO - determine best choice once both are fully supported in devnet
|
|
4548
|
+
// signature: [],
|
|
4549
|
+
// sender_address: contractAddress,
|
|
4300
4550
|
contract_address: contractAddress,
|
|
4301
4551
|
entry_point_selector: getSelectorFromName(entryPointSelector),
|
|
4302
4552
|
calldata: CallData.compile(calldata)
|
|
@@ -4415,7 +4665,7 @@ var SequencerProvider = class {
|
|
|
4415
4665
|
sender_address: invocation.contractAddress,
|
|
4416
4666
|
calldata: CallData.compile(invocation.calldata ?? []),
|
|
4417
4667
|
signature: signatureToDecimalArray(invocation.signature),
|
|
4418
|
-
version: toHex(
|
|
4668
|
+
version: toHex(invocationDetails?.version || 1),
|
|
4419
4669
|
nonce: toHex(invocationDetails.nonce)
|
|
4420
4670
|
}
|
|
4421
4671
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -4430,7 +4680,7 @@ var SequencerProvider = class {
|
|
|
4430
4680
|
sender_address: senderAddress,
|
|
4431
4681
|
contract_class: contractDefinition,
|
|
4432
4682
|
signature: signatureToDecimalArray(signature),
|
|
4433
|
-
version: toHex(
|
|
4683
|
+
version: toHex(details?.version || toBigInt(feeTransactionVersion)),
|
|
4434
4684
|
nonce: toHex(details.nonce)
|
|
4435
4685
|
}
|
|
4436
4686
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -4459,7 +4709,7 @@ var SequencerProvider = class {
|
|
|
4459
4709
|
constructor_calldata: CallData.compile(constructorCalldata || []),
|
|
4460
4710
|
contract_address_salt: toHex(addressSalt || 0),
|
|
4461
4711
|
signature: signatureToDecimalArray(signature),
|
|
4462
|
-
version: toHex(
|
|
4712
|
+
version: toHex(details?.version || 0),
|
|
4463
4713
|
nonce: toHex(details.nonce)
|
|
4464
4714
|
}
|
|
4465
4715
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -4490,7 +4740,7 @@ var SequencerProvider = class {
|
|
|
4490
4740
|
return {
|
|
4491
4741
|
...res,
|
|
4492
4742
|
signature: bigNumberishArrayToDecimalStringArray(formatSignature(invocation.signature)),
|
|
4493
|
-
version: toHex(toBigInt(
|
|
4743
|
+
version: toHex(toBigInt(invocation?.version || 1)),
|
|
4494
4744
|
nonce: toHex(toBigInt(invocation.nonce))
|
|
4495
4745
|
};
|
|
4496
4746
|
});
|
|
@@ -4505,8 +4755,8 @@ var SequencerProvider = class {
|
|
|
4505
4755
|
const errorStates = ["REJECTED" /* REJECTED */, "NOT_RECEIVED" /* NOT_RECEIVED */];
|
|
4506
4756
|
let onchain = false;
|
|
4507
4757
|
let res;
|
|
4508
|
-
const retryInterval =
|
|
4509
|
-
const successStates =
|
|
4758
|
+
const retryInterval = options?.retryInterval ?? 8e3;
|
|
4759
|
+
const successStates = options?.successStates ?? [
|
|
4510
4760
|
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
4511
4761
|
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
4512
4762
|
"PENDING" /* PENDING */
|
|
@@ -4527,13 +4777,33 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
4527
4777
|
const txReceipt = await this.getTransactionReceipt(txHash);
|
|
4528
4778
|
return txReceipt;
|
|
4529
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
|
+
*/
|
|
4530
4788
|
async getTransactionStatus(txHash) {
|
|
4531
4789
|
const txHashHex = toHex(txHash);
|
|
4532
4790
|
return this.fetchEndpoint("get_transaction_status", { transactionHash: txHashHex });
|
|
4533
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
|
+
*/
|
|
4534
4798
|
async getContractAddresses() {
|
|
4535
4799
|
return this.fetchEndpoint("get_contract_addresses");
|
|
4536
4800
|
}
|
|
4801
|
+
/**
|
|
4802
|
+
* Gets the transaction trace from a tx id.
|
|
4803
|
+
*
|
|
4804
|
+
* @param txHash
|
|
4805
|
+
* @returns the transaction trace
|
|
4806
|
+
*/
|
|
4537
4807
|
async getTransactionTrace(txHash) {
|
|
4538
4808
|
const txHashHex = toHex(txHash);
|
|
4539
4809
|
return this.fetchEndpoint("get_transaction_trace", { transactionHash: txHashHex });
|
|
@@ -4556,9 +4826,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
4556
4826
|
sender_address: invocation.contractAddress,
|
|
4557
4827
|
calldata: CallData.compile(invocation.calldata ?? []),
|
|
4558
4828
|
signature: signatureToDecimalArray(invocation.signature),
|
|
4559
|
-
version: toHex(
|
|
4829
|
+
version: toHex(invocationDetails?.version || 1),
|
|
4560
4830
|
nonce: toHex(invocationDetails.nonce),
|
|
4561
|
-
max_fee: toHex(
|
|
4831
|
+
max_fee: toHex(invocationDetails?.maxFee || 0)
|
|
4562
4832
|
}
|
|
4563
4833
|
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
4564
4834
|
}
|
|
@@ -4568,6 +4838,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
4568
4838
|
this.responseParser.parseGetStateUpdateResponse
|
|
4569
4839
|
);
|
|
4570
4840
|
}
|
|
4841
|
+
// consider adding an optional trace retrieval parameter to the getBlock method
|
|
4571
4842
|
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
4572
4843
|
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4573
4844
|
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
@@ -4752,6 +5023,13 @@ function getCalldata(args, callback) {
|
|
|
4752
5023
|
return callback();
|
|
4753
5024
|
}
|
|
4754
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
|
+
*/
|
|
4755
5033
|
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
4756
5034
|
this.address = address && address.toLowerCase();
|
|
4757
5035
|
this.providerOrAccount = providerOrAccount;
|
|
@@ -4914,6 +5192,13 @@ var ContractFactory = class {
|
|
|
4914
5192
|
this.classHash = classHash;
|
|
4915
5193
|
this.CallData = new CallData(abi);
|
|
4916
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
|
+
*/
|
|
4917
5202
|
async deploy(...args) {
|
|
4918
5203
|
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
4919
5204
|
const constructorCalldata = getCalldata(param, () => {
|
|
@@ -4940,13 +5225,26 @@ var ContractFactory = class {
|
|
|
4940
5225
|
contractInstance.deployTransactionHash = transaction_hash;
|
|
4941
5226
|
return contractInstance;
|
|
4942
5227
|
}
|
|
5228
|
+
/**
|
|
5229
|
+
* Attaches to new Account
|
|
5230
|
+
*
|
|
5231
|
+
* @param account - new Provider or Account to attach to
|
|
5232
|
+
* @returns ContractFactory
|
|
5233
|
+
*/
|
|
4943
5234
|
connect(account) {
|
|
4944
5235
|
this.account = account;
|
|
4945
5236
|
return this;
|
|
4946
5237
|
}
|
|
5238
|
+
/**
|
|
5239
|
+
* Attaches current abi and account to the new address
|
|
5240
|
+
*
|
|
5241
|
+
* @param address - Contract address
|
|
5242
|
+
* @returns Contract
|
|
5243
|
+
*/
|
|
4947
5244
|
attach(address) {
|
|
4948
5245
|
return new Contract(this.abi, address, this.account);
|
|
4949
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
|
|
4950
5248
|
};
|
|
4951
5249
|
|
|
4952
5250
|
// src/signer/interface.ts
|
|
@@ -5525,6 +5823,14 @@ var Account = class extends Provider {
|
|
|
5525
5823
|
}
|
|
5526
5824
|
);
|
|
5527
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
|
+
*/
|
|
5528
5834
|
async declareIfNot(payload, transactionsDetail = {}) {
|
|
5529
5835
|
const declareContractPayload = extractContractHashes(payload);
|
|
5530
5836
|
try {
|
|
@@ -5705,6 +6011,9 @@ var Account = class extends Provider {
|
|
|
5705
6011
|
}
|
|
5706
6012
|
return feeEstimate.suggestedMaxFee;
|
|
5707
6013
|
}
|
|
6014
|
+
/**
|
|
6015
|
+
* will be renamed to buildDeclareContractTransaction
|
|
6016
|
+
*/
|
|
5708
6017
|
async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
|
|
5709
6018
|
const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
|
|
5710
6019
|
const contractDefinition = parseContract(contract);
|