starknet 5.7.0 → 5.9.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 +22 -0
- package/dist/index.d.ts +155 -114
- package/dist/index.global.js +5558 -5577
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1211 -1228
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1209 -1228
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -43,9 +43,12 @@ var RPC;
|
|
|
43
43
|
})(TransactionType2 = RPC2.TransactionType || (RPC2.TransactionType = {}));
|
|
44
44
|
})(RPC || (RPC = {}));
|
|
45
45
|
|
|
46
|
-
// src/utils/
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
// src/utils/assert.ts
|
|
47
|
+
function assert(condition, message) {
|
|
48
|
+
if (!condition) {
|
|
49
|
+
throw new Error(message || "Assertion failure");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
49
52
|
|
|
50
53
|
// src/utils/hash.ts
|
|
51
54
|
var hash_exports = {};
|
|
@@ -2271,15 +2274,6 @@ __export(num_exports, {
|
|
|
2271
2274
|
toHexString: () => toHexString
|
|
2272
2275
|
});
|
|
2273
2276
|
import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
|
|
2274
|
-
|
|
2275
|
-
// src/utils/assert.ts
|
|
2276
|
-
function assert(condition, message) {
|
|
2277
|
-
if (!condition) {
|
|
2278
|
-
throw new Error(message || "Assertion failure");
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
|
|
2282
|
-
// src/utils/num.ts
|
|
2283
2277
|
function isHex(hex) {
|
|
2284
2278
|
return /^0x[0-9a-f]*$/i.test(hex);
|
|
2285
2279
|
}
|
|
@@ -2479,6 +2473,9 @@ function felt(it) {
|
|
|
2479
2473
|
if (typeof it === "string" && isStringWholeNumber(it)) {
|
|
2480
2474
|
return it;
|
|
2481
2475
|
}
|
|
2476
|
+
if (typeof it === "boolean") {
|
|
2477
|
+
return `${+it}`;
|
|
2478
|
+
}
|
|
2482
2479
|
throw new Error(`${it} can't be computed by felt()`);
|
|
2483
2480
|
}
|
|
2484
2481
|
|
|
@@ -2740,584 +2737,1087 @@ function computeContractClassHash(contract) {
|
|
|
2740
2737
|
return computeLegacyContractClassHash(compiledContract);
|
|
2741
2738
|
}
|
|
2742
2739
|
|
|
2743
|
-
// src/utils/
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
}
|
|
2748
|
-
function extractContractHashes(payload) {
|
|
2749
|
-
const response = { ...payload };
|
|
2750
|
-
if (isSierra(payload.contract)) {
|
|
2751
|
-
if (!payload.compiledClassHash && payload.casm) {
|
|
2752
|
-
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
2753
|
-
}
|
|
2754
|
-
if (!response.compiledClassHash)
|
|
2740
|
+
// src/utils/calldata/formatter.ts
|
|
2741
|
+
var guard = {
|
|
2742
|
+
isBN: (data, type, key) => {
|
|
2743
|
+
if (!isBigInt(data[key]))
|
|
2755
2744
|
throw new Error(
|
|
2756
|
-
|
|
2745
|
+
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
2757
2746
|
);
|
|
2747
|
+
},
|
|
2748
|
+
unknown: (data, type, key) => {
|
|
2749
|
+
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
2758
2750
|
}
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2751
|
+
};
|
|
2752
|
+
function formatter(data, type, sameType) {
|
|
2753
|
+
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
2754
|
+
const elType = sameType ?? type[key];
|
|
2755
|
+
if (!(key in type) && !sameType) {
|
|
2756
|
+
acc[key] = value;
|
|
2757
|
+
return acc;
|
|
2758
|
+
}
|
|
2759
|
+
if (elType === "string") {
|
|
2760
|
+
if (Array.isArray(data[key])) {
|
|
2761
|
+
const arrayStr = formatter(
|
|
2762
|
+
data[key],
|
|
2763
|
+
data[key].map((_) => elType)
|
|
2764
|
+
);
|
|
2765
|
+
acc[key] = Object.values(arrayStr).join("");
|
|
2766
|
+
return acc;
|
|
2767
|
+
}
|
|
2768
|
+
guard.isBN(data, type, key);
|
|
2769
|
+
acc[key] = decodeShortString(value);
|
|
2770
|
+
return acc;
|
|
2771
|
+
}
|
|
2772
|
+
if (elType === "number") {
|
|
2773
|
+
guard.isBN(data, type, key);
|
|
2774
|
+
acc[key] = Number(value);
|
|
2775
|
+
return acc;
|
|
2776
|
+
}
|
|
2777
|
+
if (typeof elType === "function") {
|
|
2778
|
+
acc[key] = elType(value);
|
|
2779
|
+
return acc;
|
|
2780
|
+
}
|
|
2781
|
+
if (Array.isArray(elType)) {
|
|
2782
|
+
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
2783
|
+
acc[key] = Object.values(arrayObj);
|
|
2784
|
+
return acc;
|
|
2785
|
+
}
|
|
2786
|
+
if (typeof elType === "object") {
|
|
2787
|
+
acc[key] = formatter(data[key], elType);
|
|
2788
|
+
return acc;
|
|
2789
|
+
}
|
|
2790
|
+
guard.unknown(data, type, key);
|
|
2791
|
+
return acc;
|
|
2792
|
+
}, {});
|
|
2763
2793
|
}
|
|
2764
2794
|
|
|
2765
|
-
// src/utils/
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
|
|
2771
|
-
formatSignature: () => formatSignature,
|
|
2772
|
-
makeAddress: () => makeAddress,
|
|
2773
|
-
randomAddress: () => randomAddress,
|
|
2774
|
-
signatureToDecimalArray: () => signatureToDecimalArray,
|
|
2775
|
-
signatureToHexArray: () => signatureToHexArray
|
|
2776
|
-
});
|
|
2777
|
-
import { getStarkKey, utils } from "micro-starknet";
|
|
2778
|
-
import { gzip } from "pako";
|
|
2779
|
-
function compressProgram(jsonProgram) {
|
|
2780
|
-
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
2781
|
-
const compressedProgram = gzip(stringified);
|
|
2782
|
-
return btoaUniversal(compressedProgram);
|
|
2783
|
-
}
|
|
2784
|
-
function randomAddress() {
|
|
2785
|
-
const randomKeyPair = utils.randomPrivateKey();
|
|
2786
|
-
return getStarkKey(randomKeyPair);
|
|
2787
|
-
}
|
|
2788
|
-
function makeAddress(input) {
|
|
2789
|
-
return addHexPrefix(input).toLowerCase();
|
|
2795
|
+
// src/utils/calldata/tuple.ts
|
|
2796
|
+
function parseNamedTuple(namedTuple) {
|
|
2797
|
+
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
2798
|
+
const type = namedTuple.substring(name.length + ":".length);
|
|
2799
|
+
return { name, type };
|
|
2790
2800
|
}
|
|
2791
|
-
function
|
|
2792
|
-
if (!
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2801
|
+
function parseSubTuple(s) {
|
|
2802
|
+
if (!s.includes("("))
|
|
2803
|
+
return { subTuple: [], result: s };
|
|
2804
|
+
const subTuple = [];
|
|
2805
|
+
let result = "";
|
|
2806
|
+
let i = 0;
|
|
2807
|
+
while (i < s.length) {
|
|
2808
|
+
if (s[i] === "(") {
|
|
2809
|
+
let counter = 1;
|
|
2810
|
+
const lBracket = i;
|
|
2811
|
+
i++;
|
|
2812
|
+
while (counter) {
|
|
2813
|
+
if (s[i] === ")")
|
|
2814
|
+
counter--;
|
|
2815
|
+
if (s[i] === "(")
|
|
2816
|
+
counter++;
|
|
2817
|
+
i++;
|
|
2818
|
+
}
|
|
2819
|
+
subTuple.push(s.substring(lBracket, i));
|
|
2820
|
+
result += " ";
|
|
2821
|
+
i--;
|
|
2822
|
+
} else {
|
|
2823
|
+
result += s[i];
|
|
2824
|
+
}
|
|
2825
|
+
i++;
|
|
2802
2826
|
}
|
|
2827
|
+
return {
|
|
2828
|
+
subTuple,
|
|
2829
|
+
result
|
|
2830
|
+
};
|
|
2803
2831
|
}
|
|
2804
|
-
function
|
|
2805
|
-
|
|
2806
|
-
}
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
}
|
|
2810
|
-
function compileCalldata(args) {
|
|
2811
|
-
const compiledData = Object.values(args).flatMap((value) => {
|
|
2812
|
-
if (Array.isArray(value))
|
|
2813
|
-
return [toBigInt(value.length).toString(), ...value.map((x) => toBigInt(x).toString())];
|
|
2814
|
-
if (typeof value === "object" && "type" in value)
|
|
2815
|
-
return Object.entries(value).filter(([k]) => k !== "type").map(([, v]) => toBigInt(v).toString());
|
|
2816
|
-
return toBigInt(value).toString();
|
|
2817
|
-
});
|
|
2818
|
-
Object.defineProperty(compiledData, "compiled", {
|
|
2819
|
-
enumerable: false,
|
|
2820
|
-
writable: false,
|
|
2821
|
-
value: true
|
|
2822
|
-
});
|
|
2823
|
-
return compiledData;
|
|
2824
|
-
}
|
|
2825
|
-
function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
|
|
2826
|
-
const overHeadPercent = Math.round((1 + overhead) * 100);
|
|
2827
|
-
return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
|
|
2828
|
-
}
|
|
2829
|
-
|
|
2830
|
-
// src/utils/provider.ts
|
|
2831
|
-
function wait(delay) {
|
|
2832
|
-
return new Promise((res) => {
|
|
2833
|
-
setTimeout(res, delay);
|
|
2834
|
-
});
|
|
2835
|
-
}
|
|
2836
|
-
function parseCalldata(calldata = []) {
|
|
2837
|
-
return calldata.map((data) => {
|
|
2838
|
-
if (typeof data === "string" && isHex(data)) {
|
|
2839
|
-
return data;
|
|
2840
|
-
}
|
|
2841
|
-
return toHex(data);
|
|
2832
|
+
function extractCairo0Tuple(type) {
|
|
2833
|
+
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
2834
|
+
const { subTuple, result } = parseSubTuple(cleanType);
|
|
2835
|
+
let recomposed = result.split(",").map((it) => {
|
|
2836
|
+
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
2842
2837
|
});
|
|
2838
|
+
if (isTypeNamedTuple(type)) {
|
|
2839
|
+
recomposed = recomposed.reduce((acc, it) => {
|
|
2840
|
+
return acc.concat(parseNamedTuple(it));
|
|
2841
|
+
}, []);
|
|
2842
|
+
}
|
|
2843
|
+
return recomposed;
|
|
2843
2844
|
}
|
|
2844
|
-
function
|
|
2845
|
-
const
|
|
2846
|
-
|
|
2847
|
-
result.abi = formatSpaces(stringify2(contract.abi));
|
|
2848
|
-
result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
|
|
2849
|
-
result.sierra_program = compressProgram(result.sierra_program);
|
|
2850
|
-
return result;
|
|
2845
|
+
function extractCairo1Tuple(type) {
|
|
2846
|
+
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
2847
|
+
return cleanType.split(",");
|
|
2851
2848
|
}
|
|
2852
|
-
function
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
return {
|
|
2856
|
-
...parsedContract,
|
|
2857
|
-
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
2858
|
-
};
|
|
2849
|
+
function extractTupleMemberTypes(type) {
|
|
2850
|
+
if (isCairo1Type(type)) {
|
|
2851
|
+
return extractCairo1Tuple(type);
|
|
2859
2852
|
}
|
|
2860
|
-
return
|
|
2853
|
+
return extractCairo0Tuple(type);
|
|
2861
2854
|
}
|
|
2862
2855
|
|
|
2863
|
-
// src/utils/
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
parent_hash: res.parent_hash,
|
|
2872
|
-
status: res.status,
|
|
2873
|
-
transactions: res.transactions
|
|
2874
|
-
};
|
|
2856
|
+
// src/utils/calldata/requestParser.ts
|
|
2857
|
+
function parseBaseTypes(type, val) {
|
|
2858
|
+
switch (true) {
|
|
2859
|
+
case isTypeUint256(type):
|
|
2860
|
+
const el_uint256 = uint256(val);
|
|
2861
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
2862
|
+
default:
|
|
2863
|
+
return felt(val);
|
|
2875
2864
|
}
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
};
|
|
2865
|
+
}
|
|
2866
|
+
function parseTuple(element, typeStr) {
|
|
2867
|
+
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
2868
|
+
const elements = Object.values(element);
|
|
2869
|
+
if (elements.length !== memberTypes.length) {
|
|
2870
|
+
throw Error(
|
|
2871
|
+
`ParseTuple: provided and expected abi tuple size do not match.
|
|
2872
|
+
provided: ${elements}
|
|
2873
|
+
expected: ${memberTypes}`
|
|
2874
|
+
);
|
|
2887
2875
|
}
|
|
2888
|
-
|
|
2876
|
+
return memberTypes.map((it, dx) => {
|
|
2889
2877
|
return {
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
gas_price: toBigInt(res.gas_price)
|
|
2878
|
+
element: elements[dx],
|
|
2879
|
+
type: it.type ?? it
|
|
2893
2880
|
};
|
|
2894
|
-
}
|
|
2895
|
-
parseCallContractResponse(res) {
|
|
2896
|
-
return {
|
|
2897
|
-
result: res
|
|
2898
|
-
};
|
|
2899
|
-
}
|
|
2900
|
-
};
|
|
2901
|
-
|
|
2902
|
-
// src/provider/errors.ts
|
|
2903
|
-
function fixStack(target, fn = target.constructor) {
|
|
2904
|
-
const { captureStackTrace } = Error;
|
|
2905
|
-
captureStackTrace && captureStackTrace(target, fn);
|
|
2906
|
-
}
|
|
2907
|
-
function fixProto(target, prototype) {
|
|
2908
|
-
const { setPrototypeOf } = Object;
|
|
2909
|
-
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
2881
|
+
});
|
|
2910
2882
|
}
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
Object.defineProperty(this, "name", {
|
|
2915
|
-
value: new.target.name,
|
|
2916
|
-
enumerable: false,
|
|
2917
|
-
configurable: true
|
|
2918
|
-
});
|
|
2919
|
-
fixProto(this, new.target.prototype);
|
|
2920
|
-
fixStack(this);
|
|
2883
|
+
function parseCalldataValue(element, type, structs) {
|
|
2884
|
+
if (element === void 0) {
|
|
2885
|
+
throw Error(`Missing parameter for type ${type}`);
|
|
2921
2886
|
}
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
};
|
|
2925
|
-
var GatewayError = class extends LibraryError {
|
|
2926
|
-
constructor(message, errorCode) {
|
|
2927
|
-
super(message);
|
|
2928
|
-
this.errorCode = errorCode;
|
|
2887
|
+
if (Array.isArray(element)) {
|
|
2888
|
+
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
2929
2889
|
}
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2890
|
+
if (structs[type] && structs[type].members.length) {
|
|
2891
|
+
const { members } = structs[type];
|
|
2892
|
+
const subElement = element;
|
|
2893
|
+
return members.reduce((acc, it) => {
|
|
2894
|
+
return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs));
|
|
2895
|
+
}, []);
|
|
2935
2896
|
}
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
getStarknetIdContract: () => getStarknetIdContract,
|
|
2943
|
-
useDecoded: () => useDecoded,
|
|
2944
|
-
useEncoded: () => useEncoded
|
|
2945
|
-
});
|
|
2946
|
-
var basicAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
|
2947
|
-
var basicSizePlusOne = BigInt(basicAlphabet.length + 1);
|
|
2948
|
-
var bigAlphabet = "\u8FD9\u6765";
|
|
2949
|
-
var basicAlphabetSize = BigInt(basicAlphabet.length);
|
|
2950
|
-
var bigAlphabetSize = BigInt(bigAlphabet.length);
|
|
2951
|
-
var bigAlphabetSizePlusOne = BigInt(bigAlphabet.length + 1);
|
|
2952
|
-
function extractStars(str) {
|
|
2953
|
-
let k = 0;
|
|
2954
|
-
while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
|
|
2955
|
-
str = str.substring(0, str.length - 1);
|
|
2956
|
-
k += 1;
|
|
2897
|
+
if (isTypeTuple(type)) {
|
|
2898
|
+
const tupled = parseTuple(element, type);
|
|
2899
|
+
return tupled.reduce((acc, it) => {
|
|
2900
|
+
const parsedData = parseCalldataValue(it.element, it.type, structs);
|
|
2901
|
+
return acc.concat(parsedData);
|
|
2902
|
+
}, []);
|
|
2957
2903
|
}
|
|
2958
|
-
|
|
2904
|
+
if (typeof element === "object") {
|
|
2905
|
+
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
2906
|
+
}
|
|
2907
|
+
return parseBaseTypes(type, element);
|
|
2959
2908
|
}
|
|
2960
|
-
function
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2909
|
+
function parseCalldataField(argsIterator, input, structs) {
|
|
2910
|
+
const { name, type } = input;
|
|
2911
|
+
let { value } = argsIterator.next();
|
|
2912
|
+
switch (true) {
|
|
2913
|
+
case isTypeArray(type):
|
|
2914
|
+
if (!Array.isArray(value) && !isText(value)) {
|
|
2915
|
+
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
2916
|
+
}
|
|
2917
|
+
if (typeof value === "string") {
|
|
2918
|
+
value = splitLongString(value);
|
|
2919
|
+
}
|
|
2920
|
+
const result = [];
|
|
2921
|
+
result.push(felt(value.length));
|
|
2922
|
+
const arrayType = getArrayType(input.type);
|
|
2923
|
+
return value.reduce((acc, el) => {
|
|
2924
|
+
if (isTypeStruct(arrayType, structs) || isTypeTuple(arrayType) || isTypeArray(arrayType)) {
|
|
2925
|
+
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
2975
2926
|
} else {
|
|
2976
|
-
|
|
2977
|
-
decoded += bigAlphabet[Number(code2)];
|
|
2978
|
-
subdomain /= bigAlphabetSize;
|
|
2927
|
+
return acc.concat(parseBaseTypes(arrayType, el));
|
|
2979
2928
|
}
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
decoded += ".";
|
|
2987
|
-
});
|
|
2988
|
-
if (!decoded) {
|
|
2989
|
-
return decoded;
|
|
2929
|
+
return acc;
|
|
2930
|
+
}, result);
|
|
2931
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type)):
|
|
2932
|
+
return parseCalldataValue(value, type, structs);
|
|
2933
|
+
default:
|
|
2934
|
+
return parseBaseTypes(type, value);
|
|
2990
2935
|
}
|
|
2991
|
-
return decoded.concat("stark");
|
|
2992
2936
|
}
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
2937
|
+
|
|
2938
|
+
// src/utils/calldata/responseParser.ts
|
|
2939
|
+
function parseBaseTypes2(type, it) {
|
|
2940
|
+
let temp;
|
|
2941
|
+
switch (true) {
|
|
2942
|
+
case isTypeBool(type):
|
|
2943
|
+
temp = it.next().value;
|
|
2944
|
+
return Boolean(BigInt(temp));
|
|
2945
|
+
case isTypeUint256(type):
|
|
2946
|
+
const low = it.next().value;
|
|
2947
|
+
const high = it.next().value;
|
|
2948
|
+
return uint256ToBN({ low, high });
|
|
2949
|
+
default:
|
|
2950
|
+
temp = it.next().value;
|
|
2951
|
+
return BigInt(temp);
|
|
3003
2952
|
}
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
multiplier *= basicSizePlusOne;
|
|
3012
|
-
multiplier *= basicSizePlusOne;
|
|
3013
|
-
} else {
|
|
3014
|
-
encoded += multiplier * bnIndex;
|
|
3015
|
-
multiplier *= basicSizePlusOne;
|
|
3016
|
-
}
|
|
3017
|
-
} else if (bigAlphabet.indexOf(char) !== -1) {
|
|
3018
|
-
encoded += multiplier * basicAlphabetSize;
|
|
3019
|
-
multiplier *= basicSizePlusOne;
|
|
3020
|
-
const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
|
|
3021
|
-
encoded += multiplier * BigInt(newid);
|
|
3022
|
-
multiplier *= bigAlphabetSize;
|
|
3023
|
-
}
|
|
2953
|
+
}
|
|
2954
|
+
function parseResponseStruct(responseIterator, type, structs) {
|
|
2955
|
+
if (type in structs && structs[type]) {
|
|
2956
|
+
return structs[type].members.reduce((acc, el) => {
|
|
2957
|
+
acc[el.name] = parseResponseStruct(responseIterator, el.type, structs);
|
|
2958
|
+
return acc;
|
|
2959
|
+
}, {});
|
|
3024
2960
|
}
|
|
3025
|
-
|
|
2961
|
+
if (isTypeTuple(type)) {
|
|
2962
|
+
const memberTypes = extractTupleMemberTypes(type);
|
|
2963
|
+
return memberTypes.reduce((acc, it, idx) => {
|
|
2964
|
+
const tName = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
2965
|
+
const tType = (it == null ? void 0 : it.type) ? it.type : it;
|
|
2966
|
+
acc[tName] = parseResponseStruct(responseIterator, tType, structs);
|
|
2967
|
+
return acc;
|
|
2968
|
+
}, {});
|
|
2969
|
+
}
|
|
2970
|
+
return parseBaseTypes2(type, responseIterator);
|
|
3026
2971
|
}
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
case
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
2972
|
+
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
2973
|
+
const { name, type } = output;
|
|
2974
|
+
let temp;
|
|
2975
|
+
switch (true) {
|
|
2976
|
+
case isLen(name):
|
|
2977
|
+
temp = responseIterator.next().value;
|
|
2978
|
+
return BigInt(temp);
|
|
2979
|
+
case isTypeArray(type):
|
|
2980
|
+
const parsedDataArr = [];
|
|
2981
|
+
if (isCairo1Type(type)) {
|
|
2982
|
+
const arrayType = getArrayType(type);
|
|
2983
|
+
const len = BigInt(responseIterator.next().value);
|
|
2984
|
+
while (parsedDataArr.length < len) {
|
|
2985
|
+
parsedDataArr.push(parseResponseStruct(responseIterator, arrayType, structs));
|
|
2986
|
+
}
|
|
2987
|
+
return parsedDataArr;
|
|
2988
|
+
}
|
|
2989
|
+
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
2990
|
+
const arrLen = parsedResult[`${name}_len`];
|
|
2991
|
+
while (parsedDataArr.length < arrLen) {
|
|
2992
|
+
parsedDataArr.push(
|
|
2993
|
+
parseResponseStruct(responseIterator, output.type.replace("*", ""), structs)
|
|
2994
|
+
);
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
return parsedDataArr;
|
|
2998
|
+
case (type in structs || isTypeTuple(type)):
|
|
2999
|
+
return parseResponseStruct(responseIterator, type, structs);
|
|
3038
3000
|
default:
|
|
3039
|
-
|
|
3001
|
+
return parseBaseTypes2(type, responseIterator);
|
|
3040
3002
|
}
|
|
3041
3003
|
}
|
|
3042
3004
|
|
|
3043
|
-
// src/
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
const stringDomain = useDecoded(decimalDomain);
|
|
3057
|
-
if (!stringDomain) {
|
|
3058
|
-
throw Error("Starkname not found");
|
|
3059
|
-
}
|
|
3060
|
-
return stringDomain;
|
|
3061
|
-
} catch (e) {
|
|
3062
|
-
if (e instanceof Error && e.message === "Starkname not found") {
|
|
3063
|
-
throw e;
|
|
3064
|
-
}
|
|
3065
|
-
throw Error("Could not get stark name");
|
|
3005
|
+
// src/utils/calldata/validate.ts
|
|
3006
|
+
var validateFelt = (parameter, input) => {
|
|
3007
|
+
assert(
|
|
3008
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
3009
|
+
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
3010
|
+
);
|
|
3011
|
+
};
|
|
3012
|
+
var validateUint = (parameter, input) => {
|
|
3013
|
+
if (typeof parameter === "number") {
|
|
3014
|
+
assert(
|
|
3015
|
+
parameter <= Number.MAX_SAFE_INTEGER,
|
|
3016
|
+
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
3017
|
+
);
|
|
3066
3018
|
}
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3019
|
+
assert(
|
|
3020
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
3021
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
|
|
3022
|
+
);
|
|
3023
|
+
const param = toBigInt(parameter);
|
|
3024
|
+
switch (input.type) {
|
|
3025
|
+
case "core::integer::u8" /* u8 */:
|
|
3026
|
+
assert(
|
|
3027
|
+
param >= 0n && param <= 255n,
|
|
3028
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
3029
|
+
);
|
|
3030
|
+
break;
|
|
3031
|
+
case "core::integer::u16" /* u16 */:
|
|
3032
|
+
assert(
|
|
3033
|
+
param >= 0n && param <= 65535n,
|
|
3034
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
3035
|
+
);
|
|
3036
|
+
break;
|
|
3037
|
+
case "core::integer::u32" /* u32 */:
|
|
3038
|
+
assert(
|
|
3039
|
+
param >= 0n && param <= 4294967295n,
|
|
3040
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
3041
|
+
);
|
|
3042
|
+
break;
|
|
3043
|
+
case "core::integer::u64" /* u64 */:
|
|
3044
|
+
assert(
|
|
3045
|
+
param >= 0n && param <= 2n ** 64n - 1n,
|
|
3046
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
3047
|
+
);
|
|
3048
|
+
break;
|
|
3049
|
+
case "core::integer::u128" /* u128 */:
|
|
3050
|
+
assert(
|
|
3051
|
+
param >= 0n && param <= 2n ** 128n - 1n,
|
|
3052
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
3053
|
+
);
|
|
3054
|
+
break;
|
|
3055
|
+
case "core::integer::u256" /* u256 */:
|
|
3056
|
+
assert(
|
|
3057
|
+
param >= 0n && param <= 2n ** 256n - 1n,
|
|
3058
|
+
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
3059
|
+
);
|
|
3060
|
+
break;
|
|
3061
|
+
default:
|
|
3062
|
+
break;
|
|
3082
3063
|
}
|
|
3083
|
-
}
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3064
|
+
};
|
|
3065
|
+
var validateBool = (parameter, input) => {
|
|
3066
|
+
assert(
|
|
3067
|
+
typeof parameter === "boolean",
|
|
3068
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
3069
|
+
);
|
|
3070
|
+
};
|
|
3071
|
+
var validateStruct = (parameter, input, structs) => {
|
|
3072
|
+
assert(
|
|
3073
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
3074
|
+
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
3075
|
+
);
|
|
3076
|
+
structs[input.type].members.forEach(({ name }) => {
|
|
3077
|
+
assert(
|
|
3078
|
+
Object.keys(parameter).includes(name),
|
|
3079
|
+
`Validate: arg ${input.name} should have a property ${name}`
|
|
3080
|
+
);
|
|
3081
|
+
});
|
|
3082
|
+
};
|
|
3083
|
+
var validateTuple = (parameter, input) => {
|
|
3084
|
+
assert(
|
|
3085
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
3086
|
+
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
3087
|
+
);
|
|
3088
|
+
};
|
|
3089
|
+
var validateArray = (parameter, input, structs) => {
|
|
3090
|
+
const baseType = getArrayType(input.type);
|
|
3091
|
+
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
3092
|
+
return;
|
|
3093
|
+
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
3094
|
+
switch (true) {
|
|
3095
|
+
case isTypeFelt(baseType):
|
|
3096
|
+
parameter.forEach((param) => validateFelt(param, input));
|
|
3097
|
+
break;
|
|
3098
|
+
case isTypeTuple(baseType):
|
|
3099
|
+
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
3100
|
+
break;
|
|
3101
|
+
case isTypeStruct(baseType, structs):
|
|
3102
|
+
parameter.forEach(
|
|
3103
|
+
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
3104
|
+
);
|
|
3105
|
+
break;
|
|
3106
|
+
case isTypeUint(baseType):
|
|
3107
|
+
parameter.forEach((param) => validateUint(param, input));
|
|
3108
|
+
break;
|
|
3109
|
+
case isTypeBool(baseType):
|
|
3110
|
+
parameter.forEach((param) => validateBool(param, input));
|
|
3111
|
+
break;
|
|
3112
|
+
default:
|
|
3113
|
+
throw new Error(
|
|
3114
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
3115
|
+
);
|
|
3095
3116
|
}
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3117
|
+
};
|
|
3118
|
+
function validateFields(abiMethod, args, structs) {
|
|
3119
|
+
abiMethod.inputs.reduce((acc, input) => {
|
|
3120
|
+
const parameter = args[acc];
|
|
3121
|
+
switch (true) {
|
|
3122
|
+
case isLen(input.name):
|
|
3123
|
+
return acc;
|
|
3124
|
+
case isTypeFelt(input.type):
|
|
3125
|
+
validateFelt(parameter, input);
|
|
3126
|
+
break;
|
|
3127
|
+
case isTypeUint(input.type):
|
|
3128
|
+
validateUint(parameter, input);
|
|
3129
|
+
break;
|
|
3130
|
+
case isTypeBool(input.type):
|
|
3131
|
+
validateBool(parameter, input);
|
|
3132
|
+
break;
|
|
3133
|
+
case isTypeContractAddress(input.type):
|
|
3134
|
+
break;
|
|
3135
|
+
case isTypeStruct(input.type, structs):
|
|
3136
|
+
validateStruct(parameter, input, structs);
|
|
3137
|
+
break;
|
|
3138
|
+
case isTypeTuple(input.type):
|
|
3139
|
+
validateTuple(parameter, input);
|
|
3140
|
+
break;
|
|
3141
|
+
case isTypeArray(input.type):
|
|
3142
|
+
validateArray(parameter, input, structs);
|
|
3143
|
+
break;
|
|
3144
|
+
default:
|
|
3145
|
+
throw new Error(
|
|
3146
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
3147
|
+
);
|
|
3107
3148
|
}
|
|
3149
|
+
return acc + 1;
|
|
3150
|
+
}, 0);
|
|
3151
|
+
}
|
|
3152
|
+
|
|
3153
|
+
// src/utils/calldata/index.ts
|
|
3154
|
+
var CallData = class {
|
|
3155
|
+
constructor(abi) {
|
|
3156
|
+
this.abi = abi;
|
|
3157
|
+
this.structs = CallData.getAbiStruct(abi);
|
|
3108
3158
|
}
|
|
3109
|
-
|
|
3110
|
-
if (
|
|
3111
|
-
|
|
3159
|
+
validate(type, method, args = []) {
|
|
3160
|
+
if (type !== "DEPLOY") {
|
|
3161
|
+
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
3162
|
+
if (abi.type !== "function")
|
|
3163
|
+
return false;
|
|
3164
|
+
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
3165
|
+
return type === "INVOKE" ? !isView : isView;
|
|
3166
|
+
}).map((abi) => abi.name);
|
|
3167
|
+
assert(
|
|
3168
|
+
invocableFunctionNames.includes(method),
|
|
3169
|
+
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
3170
|
+
);
|
|
3112
3171
|
}
|
|
3113
|
-
|
|
3114
|
-
|
|
3172
|
+
const abiMethod = this.abi.find(
|
|
3173
|
+
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
3174
|
+
);
|
|
3175
|
+
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
3176
|
+
if (args.length !== inputsLength) {
|
|
3177
|
+
throw Error(
|
|
3178
|
+
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
3179
|
+
);
|
|
3115
3180
|
}
|
|
3116
|
-
|
|
3181
|
+
validateFields(abiMethod, args, this.structs);
|
|
3117
3182
|
}
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3183
|
+
compile(method, args) {
|
|
3184
|
+
const argsIterator = args[Symbol.iterator]();
|
|
3185
|
+
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
3186
|
+
return inputs.reduce(
|
|
3187
|
+
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
3188
|
+
[]
|
|
3189
|
+
);
|
|
3190
|
+
}
|
|
3191
|
+
static compile(rawArgs) {
|
|
3192
|
+
const createTree = (obj) => {
|
|
3193
|
+
const getEntries = (o, prefix = "") => {
|
|
3194
|
+
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
3195
|
+
return Object.entries(oe).flatMap(([k, v]) => {
|
|
3196
|
+
let value = v;
|
|
3197
|
+
if (isLongText(value))
|
|
3198
|
+
value = splitLongString(value);
|
|
3199
|
+
if (k === "entrypoint")
|
|
3200
|
+
value = getSelectorFromName(value);
|
|
3201
|
+
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
3202
|
+
if (isBigInt(value))
|
|
3203
|
+
return [[`${prefix}${kk}`, felt(value)]];
|
|
3204
|
+
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
3205
|
+
});
|
|
3206
|
+
};
|
|
3207
|
+
return Object.fromEntries(getEntries(obj));
|
|
3208
|
+
};
|
|
3209
|
+
let callTreeArray;
|
|
3210
|
+
if (!Array.isArray(rawArgs)) {
|
|
3211
|
+
const callTree = createTree(rawArgs);
|
|
3212
|
+
callTreeArray = Object.values(callTree);
|
|
3213
|
+
} else {
|
|
3214
|
+
const callObj = { ...rawArgs };
|
|
3215
|
+
const callTree = createTree(callObj);
|
|
3216
|
+
callTreeArray = Object.values(callTree);
|
|
3124
3217
|
}
|
|
3125
|
-
|
|
3218
|
+
Object.defineProperty(callTreeArray, "__compiled__", {
|
|
3219
|
+
enumerable: false,
|
|
3220
|
+
writable: false,
|
|
3221
|
+
value: true
|
|
3222
|
+
});
|
|
3223
|
+
return callTreeArray;
|
|
3126
3224
|
}
|
|
3127
|
-
|
|
3128
|
-
this.
|
|
3225
|
+
parse(method, response) {
|
|
3226
|
+
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
3227
|
+
const responseIterator = response.flat()[Symbol.iterator]();
|
|
3228
|
+
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
3229
|
+
const propName = output.name ?? idx;
|
|
3230
|
+
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
3231
|
+
if (acc[propName] && acc[`${propName}_len`]) {
|
|
3232
|
+
delete acc[`${propName}_len`];
|
|
3233
|
+
}
|
|
3234
|
+
return acc;
|
|
3235
|
+
}, {});
|
|
3236
|
+
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
3129
3237
|
}
|
|
3130
|
-
|
|
3131
|
-
|
|
3238
|
+
format(method, response, format) {
|
|
3239
|
+
const parsed = this.parse(method, response);
|
|
3240
|
+
return formatter(parsed, format);
|
|
3132
3241
|
}
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
// src/provider/rpc.ts
|
|
3136
|
-
var defaultOptions = {
|
|
3137
|
-
headers: { "Content-Type": "application/json" },
|
|
3138
|
-
blockIdentifier: "latest",
|
|
3139
|
-
retries: 200
|
|
3140
|
-
};
|
|
3141
|
-
var RpcProvider = class {
|
|
3142
|
-
constructor(optionsOrProvider) {
|
|
3143
|
-
this.responseParser = new RPCResponseParser();
|
|
3144
|
-
const { nodeUrl, retries, headers, blockIdentifier } = optionsOrProvider;
|
|
3145
|
-
this.nodeUrl = nodeUrl;
|
|
3146
|
-
this.retries = retries || defaultOptions.retries;
|
|
3147
|
-
this.headers = { ...defaultOptions.headers, ...headers };
|
|
3148
|
-
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
|
|
3149
|
-
this.getChainId();
|
|
3150
|
-
}
|
|
3151
|
-
fetch(method, params) {
|
|
3152
|
-
return fetchPonyfill_default(this.nodeUrl, {
|
|
3153
|
-
method: "POST",
|
|
3154
|
-
body: stringify2({ method, jsonrpc: "2.0", params, id: 0 }),
|
|
3155
|
-
headers: this.headers
|
|
3156
|
-
});
|
|
3157
|
-
}
|
|
3158
|
-
errorHandler(error) {
|
|
3159
|
-
if (error) {
|
|
3160
|
-
const { code, message } = error;
|
|
3161
|
-
throw new LibraryError(`${code}: ${message}`);
|
|
3162
|
-
}
|
|
3242
|
+
static abiInputsLength(inputs) {
|
|
3243
|
+
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3163
3244
|
}
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
this.errorHandler((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data);
|
|
3173
|
-
throw error;
|
|
3174
|
-
}
|
|
3245
|
+
static getAbiStruct(abi) {
|
|
3246
|
+
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
3247
|
+
(acc, abiEntry) => ({
|
|
3248
|
+
...acc,
|
|
3249
|
+
[abiEntry.name]: abiEntry
|
|
3250
|
+
}),
|
|
3251
|
+
{}
|
|
3252
|
+
);
|
|
3175
3253
|
}
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
return this.chainId;
|
|
3254
|
+
static toCalldata(rawCalldata = []) {
|
|
3255
|
+
return CallData.compile(rawCalldata);
|
|
3179
3256
|
}
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
);
|
|
3257
|
+
static toHex(rawCalldata = []) {
|
|
3258
|
+
const calldata = CallData.compile(rawCalldata);
|
|
3259
|
+
return calldata.map((it) => toHex(it));
|
|
3184
3260
|
}
|
|
3185
|
-
|
|
3186
|
-
|
|
3261
|
+
};
|
|
3262
|
+
|
|
3263
|
+
// src/utils/fetchPonyfill.ts
|
|
3264
|
+
import isomorphicFetch from "isomorphic-fetch";
|
|
3265
|
+
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || isomorphicFetch;
|
|
3266
|
+
|
|
3267
|
+
// src/utils/contract.ts
|
|
3268
|
+
function isSierra(contract) {
|
|
3269
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3270
|
+
return "sierra_program" in compiledContract;
|
|
3271
|
+
}
|
|
3272
|
+
function extractContractHashes(payload) {
|
|
3273
|
+
const response = { ...payload };
|
|
3274
|
+
if (isSierra(payload.contract)) {
|
|
3275
|
+
if (!payload.compiledClassHash && payload.casm) {
|
|
3276
|
+
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
3277
|
+
}
|
|
3278
|
+
if (!response.compiledClassHash)
|
|
3279
|
+
throw new Error(
|
|
3280
|
+
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
3281
|
+
);
|
|
3187
3282
|
}
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3283
|
+
response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
|
|
3284
|
+
if (!response.classHash)
|
|
3285
|
+
throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
3286
|
+
return response;
|
|
3287
|
+
}
|
|
3288
|
+
|
|
3289
|
+
// src/utils/stark.ts
|
|
3290
|
+
var stark_exports = {};
|
|
3291
|
+
__export(stark_exports, {
|
|
3292
|
+
compressProgram: () => compressProgram,
|
|
3293
|
+
estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
|
|
3294
|
+
formatSignature: () => formatSignature,
|
|
3295
|
+
makeAddress: () => makeAddress,
|
|
3296
|
+
randomAddress: () => randomAddress,
|
|
3297
|
+
signatureToDecimalArray: () => signatureToDecimalArray,
|
|
3298
|
+
signatureToHexArray: () => signatureToHexArray
|
|
3299
|
+
});
|
|
3300
|
+
import { getStarkKey, utils } from "micro-starknet";
|
|
3301
|
+
import { gzip } from "pako";
|
|
3302
|
+
function compressProgram(jsonProgram) {
|
|
3303
|
+
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
3304
|
+
const compressedProgram = gzip(stringified);
|
|
3305
|
+
return btoaUniversal(compressedProgram);
|
|
3306
|
+
}
|
|
3307
|
+
function randomAddress() {
|
|
3308
|
+
const randomKeyPair = utils.randomPrivateKey();
|
|
3309
|
+
return getStarkKey(randomKeyPair);
|
|
3310
|
+
}
|
|
3311
|
+
function makeAddress(input) {
|
|
3312
|
+
return addHexPrefix(input).toLowerCase();
|
|
3313
|
+
}
|
|
3314
|
+
function formatSignature(sig) {
|
|
3315
|
+
if (!sig)
|
|
3316
|
+
throw Error("formatSignature: provided signature is undefined");
|
|
3317
|
+
if (Array.isArray(sig)) {
|
|
3318
|
+
return sig.map((it) => toHex(it));
|
|
3191
3319
|
}
|
|
3192
|
-
|
|
3193
|
-
const
|
|
3194
|
-
return
|
|
3320
|
+
try {
|
|
3321
|
+
const { r, s } = sig;
|
|
3322
|
+
return [toHex(r), toHex(s)];
|
|
3323
|
+
} catch (e) {
|
|
3324
|
+
throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
|
|
3195
3325
|
}
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3326
|
+
}
|
|
3327
|
+
function signatureToDecimalArray(sig) {
|
|
3328
|
+
return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
|
|
3329
|
+
}
|
|
3330
|
+
function signatureToHexArray(sig) {
|
|
3331
|
+
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
3332
|
+
}
|
|
3333
|
+
function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
|
|
3334
|
+
const overHeadPercent = Math.round((1 + overhead) * 100);
|
|
3335
|
+
return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
|
|
3336
|
+
}
|
|
3337
|
+
|
|
3338
|
+
// src/utils/provider.ts
|
|
3339
|
+
function wait(delay) {
|
|
3340
|
+
return new Promise((res) => {
|
|
3341
|
+
setTimeout(res, delay);
|
|
3342
|
+
});
|
|
3343
|
+
}
|
|
3344
|
+
function createSierraContractClass(contract) {
|
|
3345
|
+
const result = { ...contract };
|
|
3346
|
+
delete result.sierra_program_debug_info;
|
|
3347
|
+
result.abi = formatSpaces(stringify2(contract.abi));
|
|
3348
|
+
result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
|
|
3349
|
+
result.sierra_program = compressProgram(result.sierra_program);
|
|
3350
|
+
return result;
|
|
3351
|
+
}
|
|
3352
|
+
function parseContract(contract) {
|
|
3353
|
+
const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3354
|
+
if (!isSierra(contract)) {
|
|
3355
|
+
return {
|
|
3356
|
+
...parsedContract,
|
|
3357
|
+
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
3358
|
+
};
|
|
3202
3359
|
}
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3360
|
+
return createSierraContractClass(parsedContract);
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
// src/utils/responseParser/rpc.ts
|
|
3364
|
+
var RPCResponseParser = class {
|
|
3365
|
+
parseGetBlockResponse(res) {
|
|
3366
|
+
return {
|
|
3367
|
+
timestamp: res.timestamp,
|
|
3368
|
+
block_hash: res.block_hash,
|
|
3369
|
+
block_number: res.block_number,
|
|
3370
|
+
new_root: res.new_root,
|
|
3371
|
+
parent_hash: res.parent_hash,
|
|
3372
|
+
status: res.status,
|
|
3373
|
+
transactions: res.transactions
|
|
3374
|
+
};
|
|
3209
3375
|
}
|
|
3210
|
-
|
|
3211
|
-
return
|
|
3376
|
+
parseGetTransactionResponse(res) {
|
|
3377
|
+
return {
|
|
3378
|
+
calldata: res.calldata || [],
|
|
3379
|
+
contract_address: res.contract_address,
|
|
3380
|
+
sender_address: res.contract_address,
|
|
3381
|
+
max_fee: res.max_fee,
|
|
3382
|
+
nonce: res.nonce,
|
|
3383
|
+
signature: res.signature || [],
|
|
3384
|
+
transaction_hash: res.transaction_hash,
|
|
3385
|
+
version: res.version
|
|
3386
|
+
};
|
|
3212
3387
|
}
|
|
3213
|
-
|
|
3214
|
-
|
|
3388
|
+
parseFeeEstimateResponse(res) {
|
|
3389
|
+
return {
|
|
3390
|
+
overall_fee: toBigInt(res.overall_fee),
|
|
3391
|
+
gas_consumed: toBigInt(res.gas_consumed),
|
|
3392
|
+
gas_price: toBigInt(res.gas_price)
|
|
3393
|
+
};
|
|
3215
3394
|
}
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3395
|
+
parseCallContractResponse(res) {
|
|
3396
|
+
return {
|
|
3397
|
+
result: res
|
|
3398
|
+
};
|
|
3219
3399
|
}
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3400
|
+
};
|
|
3401
|
+
|
|
3402
|
+
// src/provider/errors.ts
|
|
3403
|
+
function fixStack(target, fn = target.constructor) {
|
|
3404
|
+
const { captureStackTrace } = Error;
|
|
3405
|
+
captureStackTrace && captureStackTrace(target, fn);
|
|
3406
|
+
}
|
|
3407
|
+
function fixProto(target, prototype) {
|
|
3408
|
+
const { setPrototypeOf } = Object;
|
|
3409
|
+
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
3410
|
+
}
|
|
3411
|
+
var CustomError = class extends Error {
|
|
3412
|
+
constructor(message) {
|
|
3413
|
+
super(message);
|
|
3414
|
+
Object.defineProperty(this, "name", {
|
|
3415
|
+
value: new.target.name,
|
|
3416
|
+
enumerable: false,
|
|
3417
|
+
configurable: true
|
|
3227
3418
|
});
|
|
3419
|
+
fixProto(this, new.target.prototype);
|
|
3420
|
+
fixStack(this);
|
|
3228
3421
|
}
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3422
|
+
};
|
|
3423
|
+
var LibraryError = class extends CustomError {
|
|
3424
|
+
};
|
|
3425
|
+
var GatewayError = class extends LibraryError {
|
|
3426
|
+
constructor(message, errorCode) {
|
|
3427
|
+
super(message);
|
|
3428
|
+
this.errorCode = errorCode;
|
|
3234
3429
|
}
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3430
|
+
};
|
|
3431
|
+
var HttpError = class extends LibraryError {
|
|
3432
|
+
constructor(message, errorCode) {
|
|
3433
|
+
super(message);
|
|
3434
|
+
this.errorCode = errorCode;
|
|
3238
3435
|
}
|
|
3239
|
-
|
|
3240
|
-
|
|
3436
|
+
};
|
|
3437
|
+
|
|
3438
|
+
// src/utils/starknetId.ts
|
|
3439
|
+
var starknetId_exports = {};
|
|
3440
|
+
__export(starknetId_exports, {
|
|
3441
|
+
StarknetIdContract: () => StarknetIdContract,
|
|
3442
|
+
getStarknetIdContract: () => getStarknetIdContract,
|
|
3443
|
+
useDecoded: () => useDecoded,
|
|
3444
|
+
useEncoded: () => useEncoded
|
|
3445
|
+
});
|
|
3446
|
+
var basicAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
|
3447
|
+
var basicSizePlusOne = BigInt(basicAlphabet.length + 1);
|
|
3448
|
+
var bigAlphabet = "\u8FD9\u6765";
|
|
3449
|
+
var basicAlphabetSize = BigInt(basicAlphabet.length);
|
|
3450
|
+
var bigAlphabetSize = BigInt(bigAlphabet.length);
|
|
3451
|
+
var bigAlphabetSizePlusOne = BigInt(bigAlphabet.length + 1);
|
|
3452
|
+
function extractStars(str) {
|
|
3453
|
+
let k = 0;
|
|
3454
|
+
while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
|
|
3455
|
+
str = str.substring(0, str.length - 1);
|
|
3456
|
+
k += 1;
|
|
3241
3457
|
}
|
|
3242
|
-
|
|
3243
|
-
|
|
3458
|
+
return [str, k];
|
|
3459
|
+
}
|
|
3460
|
+
function useDecoded(encoded) {
|
|
3461
|
+
let decoded = "";
|
|
3462
|
+
encoded.forEach((subdomain) => {
|
|
3463
|
+
while (subdomain !== ZERO) {
|
|
3464
|
+
const code = subdomain % basicSizePlusOne;
|
|
3465
|
+
subdomain /= basicSizePlusOne;
|
|
3466
|
+
if (code === BigInt(basicAlphabet.length)) {
|
|
3467
|
+
const nextSubdomain = subdomain / bigAlphabetSizePlusOne;
|
|
3468
|
+
if (nextSubdomain === ZERO) {
|
|
3469
|
+
const code2 = subdomain % bigAlphabetSizePlusOne;
|
|
3470
|
+
subdomain = nextSubdomain;
|
|
3471
|
+
if (code2 === ZERO)
|
|
3472
|
+
decoded += basicAlphabet[0];
|
|
3473
|
+
else
|
|
3474
|
+
decoded += bigAlphabet[Number(code2) - 1];
|
|
3475
|
+
} else {
|
|
3476
|
+
const code2 = subdomain % bigAlphabetSize;
|
|
3477
|
+
decoded += bigAlphabet[Number(code2)];
|
|
3478
|
+
subdomain /= bigAlphabetSize;
|
|
3479
|
+
}
|
|
3480
|
+
} else
|
|
3481
|
+
decoded += basicAlphabet[Number(code)];
|
|
3482
|
+
}
|
|
3483
|
+
const [str, k] = extractStars(decoded);
|
|
3484
|
+
if (k)
|
|
3485
|
+
decoded = str + (k % 2 === 0 ? bigAlphabet[bigAlphabet.length - 1].repeat(k / 2 - 1) + bigAlphabet[0] + basicAlphabet[1] : bigAlphabet[bigAlphabet.length - 1].repeat((k - 1) / 2 + 1));
|
|
3486
|
+
decoded += ".";
|
|
3487
|
+
});
|
|
3488
|
+
if (!decoded) {
|
|
3489
|
+
return decoded;
|
|
3244
3490
|
}
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3491
|
+
return decoded.concat("stark");
|
|
3492
|
+
}
|
|
3493
|
+
function useEncoded(decoded) {
|
|
3494
|
+
let encoded = BigInt(0);
|
|
3495
|
+
let multiplier = BigInt(1);
|
|
3496
|
+
if (decoded.endsWith(bigAlphabet[0] + basicAlphabet[1])) {
|
|
3497
|
+
const [str, k] = extractStars(decoded.substring(0, decoded.length - 2));
|
|
3498
|
+
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
|
|
3499
|
+
} else {
|
|
3500
|
+
const [str, k] = extractStars(decoded);
|
|
3501
|
+
if (k)
|
|
3502
|
+
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
|
|
3248
3503
|
}
|
|
3249
|
-
|
|
3250
|
-
const
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3504
|
+
for (let i = 0; i < decoded.length; i += 1) {
|
|
3505
|
+
const char = decoded[i];
|
|
3506
|
+
const index = basicAlphabet.indexOf(char);
|
|
3507
|
+
const bnIndex = BigInt(basicAlphabet.indexOf(char));
|
|
3508
|
+
if (index !== -1) {
|
|
3509
|
+
if (i === decoded.length - 1 && decoded[i] === basicAlphabet[0]) {
|
|
3510
|
+
encoded += multiplier * basicAlphabetSize;
|
|
3511
|
+
multiplier *= basicSizePlusOne;
|
|
3512
|
+
multiplier *= basicSizePlusOne;
|
|
3513
|
+
} else {
|
|
3514
|
+
encoded += multiplier * bnIndex;
|
|
3515
|
+
multiplier *= basicSizePlusOne;
|
|
3516
|
+
}
|
|
3517
|
+
} else if (bigAlphabet.indexOf(char) !== -1) {
|
|
3518
|
+
encoded += multiplier * basicAlphabetSize;
|
|
3519
|
+
multiplier *= basicSizePlusOne;
|
|
3520
|
+
const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
|
|
3521
|
+
encoded += multiplier * BigInt(newid);
|
|
3522
|
+
multiplier *= bigAlphabetSize;
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
return encoded;
|
|
3526
|
+
}
|
|
3527
|
+
var StarknetIdContract = /* @__PURE__ */ ((StarknetIdContract2) => {
|
|
3528
|
+
StarknetIdContract2["MAINNET"] = "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678";
|
|
3529
|
+
StarknetIdContract2["TESTNET"] = "0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce";
|
|
3530
|
+
return StarknetIdContract2;
|
|
3531
|
+
})(StarknetIdContract || {});
|
|
3532
|
+
function getStarknetIdContract(chainId) {
|
|
3533
|
+
switch (chainId) {
|
|
3534
|
+
case "0x534e5f4d41494e" /* SN_MAIN */:
|
|
3535
|
+
return "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678" /* MAINNET */;
|
|
3536
|
+
case "0x534e5f474f45524c49" /* SN_GOERLI */:
|
|
3537
|
+
return "0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce" /* TESTNET */;
|
|
3538
|
+
default:
|
|
3539
|
+
throw new Error("Starknet.id is not yet deployed on this network");
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
// src/provider/starknetId.ts
|
|
3544
|
+
async function getStarkName(provider, address, StarknetIdContract2) {
|
|
3545
|
+
const chainId = await provider.getChainId();
|
|
3546
|
+
const contract = StarknetIdContract2 ?? getStarknetIdContract(chainId);
|
|
3547
|
+
try {
|
|
3548
|
+
const hexDomain = await provider.callContract({
|
|
3549
|
+
contractAddress: contract,
|
|
3550
|
+
entrypoint: "address_to_domain",
|
|
3551
|
+
calldata: CallData.compile({
|
|
3552
|
+
address
|
|
3553
|
+
})
|
|
3254
3554
|
});
|
|
3555
|
+
const decimalDomain = hexDomain.result.map((element) => BigInt(element)).slice(1);
|
|
3556
|
+
const stringDomain = useDecoded(decimalDomain);
|
|
3557
|
+
if (!stringDomain) {
|
|
3558
|
+
throw Error("Starkname not found");
|
|
3559
|
+
}
|
|
3560
|
+
return stringDomain;
|
|
3561
|
+
} catch (e) {
|
|
3562
|
+
if (e instanceof Error && e.message === "Starkname not found") {
|
|
3563
|
+
throw e;
|
|
3564
|
+
}
|
|
3565
|
+
throw Error("Could not get stark name");
|
|
3255
3566
|
}
|
|
3256
|
-
|
|
3257
|
-
|
|
3567
|
+
}
|
|
3568
|
+
async function getAddressFromStarkName(provider, name, StarknetIdContract2) {
|
|
3569
|
+
const chainId = await provider.getChainId();
|
|
3570
|
+
const contract = StarknetIdContract2 ?? getStarknetIdContract(chainId);
|
|
3571
|
+
try {
|
|
3572
|
+
const addressData = await provider.callContract({
|
|
3573
|
+
contractAddress: contract,
|
|
3574
|
+
entrypoint: "domain_to_address",
|
|
3575
|
+
calldata: CallData.compile({
|
|
3576
|
+
domain: [useEncoded(name.replace(".stark", "")).toString(10)]
|
|
3577
|
+
})
|
|
3578
|
+
});
|
|
3579
|
+
return addressData.result[0];
|
|
3580
|
+
} catch {
|
|
3581
|
+
throw Error("Could not get address from stark name");
|
|
3258
3582
|
}
|
|
3259
|
-
|
|
3260
|
-
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3585
|
+
// src/provider/utils.ts
|
|
3586
|
+
var validBlockTags = ["latest", "pending"];
|
|
3587
|
+
var Block = class {
|
|
3588
|
+
constructor(_identifier) {
|
|
3589
|
+
this.hash = null;
|
|
3590
|
+
this.number = null;
|
|
3591
|
+
this.tag = null;
|
|
3592
|
+
this.valueOf = () => this.number;
|
|
3593
|
+
this.toString = () => this.hash;
|
|
3594
|
+
this.setIdentifier(_identifier);
|
|
3261
3595
|
}
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
block_id
|
|
3275
|
-
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3596
|
+
setIdentifier(__identifier) {
|
|
3597
|
+
if (typeof __identifier === "string" && isHex(__identifier)) {
|
|
3598
|
+
this.hash = __identifier;
|
|
3599
|
+
} else if (typeof __identifier === "bigint") {
|
|
3600
|
+
this.hash = toHex(__identifier);
|
|
3601
|
+
} else if (typeof __identifier === "number") {
|
|
3602
|
+
this.number = __identifier;
|
|
3603
|
+
} else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
|
|
3604
|
+
this.tag = __identifier;
|
|
3605
|
+
} else {
|
|
3606
|
+
this.tag = "pending";
|
|
3607
|
+
}
|
|
3276
3608
|
}
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3281
|
-
request: {
|
|
3282
|
-
type: RPC.TransactionType.DECLARE,
|
|
3283
|
-
contract_class: {
|
|
3284
|
-
program: contractDefinition.program,
|
|
3285
|
-
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
3286
|
-
abi: contractDefinition.abi
|
|
3287
|
-
},
|
|
3288
|
-
sender_address: senderAddress,
|
|
3289
|
-
signature: signatureToHexArray(signature),
|
|
3290
|
-
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
3291
|
-
nonce: toHex(details.nonce),
|
|
3292
|
-
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
3293
|
-
},
|
|
3294
|
-
block_id
|
|
3295
|
-
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3609
|
+
get queryIdentifier() {
|
|
3610
|
+
if (this.number !== null) {
|
|
3611
|
+
return `blockNumber=${this.number}`;
|
|
3296
3612
|
}
|
|
3297
|
-
|
|
3613
|
+
if (this.hash !== null) {
|
|
3614
|
+
return `blockHash=${this.hash}`;
|
|
3615
|
+
}
|
|
3616
|
+
return `blockNumber=${this.tag}`;
|
|
3298
3617
|
}
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
signature: signatureToHexArray(signature),
|
|
3308
|
-
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
3309
|
-
nonce: toHex(details.nonce),
|
|
3310
|
-
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
3311
|
-
},
|
|
3312
|
-
block_id
|
|
3313
|
-
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3618
|
+
get identifier() {
|
|
3619
|
+
if (this.number !== null) {
|
|
3620
|
+
return { block_number: this.number };
|
|
3621
|
+
}
|
|
3622
|
+
if (this.hash !== null) {
|
|
3623
|
+
return { block_hash: this.hash };
|
|
3624
|
+
}
|
|
3625
|
+
return this.tag;
|
|
3314
3626
|
}
|
|
3315
|
-
|
|
3316
|
-
|
|
3627
|
+
set identifier(_identifier) {
|
|
3628
|
+
this.setIdentifier(_identifier);
|
|
3317
3629
|
}
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3630
|
+
get sequencerIdentifier() {
|
|
3631
|
+
return this.hash !== null ? { blockHash: this.hash } : { blockNumber: this.number ?? this.tag };
|
|
3632
|
+
}
|
|
3633
|
+
};
|
|
3634
|
+
|
|
3635
|
+
// src/provider/rpc.ts
|
|
3636
|
+
var defaultOptions = {
|
|
3637
|
+
headers: { "Content-Type": "application/json" },
|
|
3638
|
+
blockIdentifier: "latest",
|
|
3639
|
+
retries: 200
|
|
3640
|
+
};
|
|
3641
|
+
var RpcProvider = class {
|
|
3642
|
+
constructor(optionsOrProvider) {
|
|
3643
|
+
this.responseParser = new RPCResponseParser();
|
|
3644
|
+
const { nodeUrl, retries, headers, blockIdentifier } = optionsOrProvider;
|
|
3645
|
+
this.nodeUrl = nodeUrl;
|
|
3646
|
+
this.retries = retries || defaultOptions.retries;
|
|
3647
|
+
this.headers = { ...defaultOptions.headers, ...headers };
|
|
3648
|
+
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
|
|
3649
|
+
this.getChainId();
|
|
3650
|
+
}
|
|
3651
|
+
fetch(method, params) {
|
|
3652
|
+
return fetchPonyfill_default(this.nodeUrl, {
|
|
3653
|
+
method: "POST",
|
|
3654
|
+
body: stringify2({ method, jsonrpc: "2.0", params, id: 0 }),
|
|
3655
|
+
headers: this.headers
|
|
3656
|
+
});
|
|
3657
|
+
}
|
|
3658
|
+
errorHandler(error) {
|
|
3659
|
+
if (error) {
|
|
3660
|
+
const { code, message } = error;
|
|
3661
|
+
throw new LibraryError(`${code}: ${message}`);
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
async fetchEndpoint(method, params) {
|
|
3665
|
+
var _a;
|
|
3666
|
+
try {
|
|
3667
|
+
const rawResult = await this.fetch(method, params);
|
|
3668
|
+
const { error, result } = await rawResult.json();
|
|
3669
|
+
this.errorHandler(error);
|
|
3670
|
+
return result;
|
|
3671
|
+
} catch (error) {
|
|
3672
|
+
this.errorHandler((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data);
|
|
3673
|
+
throw error;
|
|
3674
|
+
}
|
|
3675
|
+
}
|
|
3676
|
+
async getChainId() {
|
|
3677
|
+
this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
|
|
3678
|
+
return this.chainId;
|
|
3679
|
+
}
|
|
3680
|
+
async getBlock(blockIdentifier = this.blockIdentifier) {
|
|
3681
|
+
return this.getBlockWithTxHashes(blockIdentifier).then(
|
|
3682
|
+
this.responseParser.parseGetBlockResponse
|
|
3683
|
+
);
|
|
3684
|
+
}
|
|
3685
|
+
async getBlockHashAndNumber() {
|
|
3686
|
+
return this.fetchEndpoint("starknet_blockHashAndNumber");
|
|
3687
|
+
}
|
|
3688
|
+
async getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
|
|
3689
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3690
|
+
return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
|
|
3691
|
+
}
|
|
3692
|
+
async getBlockWithTxs(blockIdentifier = this.blockIdentifier) {
|
|
3693
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3694
|
+
return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
|
|
3695
|
+
}
|
|
3696
|
+
async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3697
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3698
|
+
return this.fetchEndpoint("starknet_getClassHashAt", {
|
|
3699
|
+
block_id,
|
|
3700
|
+
contract_address: contractAddress
|
|
3701
|
+
});
|
|
3702
|
+
}
|
|
3703
|
+
async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3704
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3705
|
+
return this.fetchEndpoint("starknet_getNonce", {
|
|
3706
|
+
contract_address: contractAddress,
|
|
3707
|
+
block_id
|
|
3708
|
+
});
|
|
3709
|
+
}
|
|
3710
|
+
async getPendingTransactions() {
|
|
3711
|
+
return this.fetchEndpoint("starknet_pendingTransactions");
|
|
3712
|
+
}
|
|
3713
|
+
async getProtocolVersion() {
|
|
3714
|
+
throw new Error("Pathfinder does not implement this rpc 0.1.0 method");
|
|
3715
|
+
}
|
|
3716
|
+
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
3717
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3718
|
+
return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
|
|
3719
|
+
}
|
|
3720
|
+
async getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
|
|
3721
|
+
const parsedKey = toHex(key);
|
|
3722
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3723
|
+
return this.fetchEndpoint("starknet_getStorageAt", {
|
|
3724
|
+
contract_address: contractAddress,
|
|
3725
|
+
key: parsedKey,
|
|
3726
|
+
block_id
|
|
3727
|
+
});
|
|
3728
|
+
}
|
|
3729
|
+
async getTransaction(txHash) {
|
|
3730
|
+
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
3731
|
+
}
|
|
3732
|
+
async getTransactionByHash(txHash) {
|
|
3733
|
+
return this.fetchEndpoint("starknet_getTransactionByHash", { transaction_hash: txHash });
|
|
3734
|
+
}
|
|
3735
|
+
async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
|
|
3736
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3737
|
+
return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
|
|
3738
|
+
}
|
|
3739
|
+
async getTransactionReceipt(txHash) {
|
|
3740
|
+
return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash: txHash });
|
|
3741
|
+
}
|
|
3742
|
+
async getClassByHash(classHash) {
|
|
3743
|
+
return this.getClass(classHash);
|
|
3744
|
+
}
|
|
3745
|
+
async getClass(classHash, blockIdentifier = this.blockIdentifier) {
|
|
3746
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3747
|
+
return this.fetchEndpoint("starknet_getClass", { class_hash: classHash, block_id });
|
|
3748
|
+
}
|
|
3749
|
+
async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3750
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3751
|
+
return this.fetchEndpoint("starknet_getClassAt", {
|
|
3752
|
+
block_id,
|
|
3753
|
+
contract_address: contractAddress
|
|
3754
|
+
});
|
|
3755
|
+
}
|
|
3756
|
+
async getCode(_contractAddress, _blockIdentifier) {
|
|
3757
|
+
throw new Error("RPC does not implement getCode function");
|
|
3758
|
+
}
|
|
3759
|
+
async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
3760
|
+
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
|
|
3761
|
+
}
|
|
3762
|
+
async getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
3763
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3764
|
+
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3765
|
+
request: {
|
|
3766
|
+
type: RPC.TransactionType.INVOKE,
|
|
3767
|
+
sender_address: invocation.contractAddress,
|
|
3768
|
+
calldata: CallData.toHex(invocation.calldata),
|
|
3769
|
+
signature: signatureToHexArray(invocation.signature),
|
|
3770
|
+
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 0),
|
|
3771
|
+
nonce: toHex(invocationDetails.nonce),
|
|
3772
|
+
max_fee: toHex((invocationDetails == null ? void 0 : invocationDetails.maxFee) || 0)
|
|
3773
|
+
},
|
|
3774
|
+
block_id
|
|
3775
|
+
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3776
|
+
}
|
|
3777
|
+
async getDeclareEstimateFee({ senderAddress, contractDefinition, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
3778
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3779
|
+
if ("program" in contractDefinition) {
|
|
3780
|
+
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3781
|
+
request: {
|
|
3782
|
+
type: RPC.TransactionType.DECLARE,
|
|
3783
|
+
contract_class: {
|
|
3784
|
+
program: contractDefinition.program,
|
|
3785
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
3786
|
+
abi: contractDefinition.abi
|
|
3787
|
+
},
|
|
3788
|
+
sender_address: senderAddress,
|
|
3789
|
+
signature: signatureToHexArray(signature),
|
|
3790
|
+
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
3791
|
+
nonce: toHex(details.nonce),
|
|
3792
|
+
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
3793
|
+
},
|
|
3794
|
+
block_id
|
|
3795
|
+
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3796
|
+
}
|
|
3797
|
+
throw new Error("RPC do not support Sierra Contracts yet");
|
|
3798
|
+
}
|
|
3799
|
+
async getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
3800
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3801
|
+
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3802
|
+
request: {
|
|
3803
|
+
type: RPC.TransactionType.DEPLOY_ACCOUNT,
|
|
3804
|
+
constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata || []),
|
|
3805
|
+
class_hash: toHex(classHash),
|
|
3806
|
+
contract_address_salt: toHex(addressSalt || 0),
|
|
3807
|
+
signature: signatureToHexArray(signature),
|
|
3808
|
+
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
3809
|
+
nonce: toHex(details.nonce),
|
|
3810
|
+
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
3811
|
+
},
|
|
3812
|
+
block_id
|
|
3813
|
+
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3814
|
+
}
|
|
3815
|
+
async getEstimateFeeBulk(_invocations, _blockIdentifier = this.blockIdentifier) {
|
|
3816
|
+
throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
|
|
3817
|
+
}
|
|
3818
|
+
async declareContract({ contractDefinition, signature, senderAddress }, details) {
|
|
3819
|
+
if ("program" in contractDefinition) {
|
|
3820
|
+
return this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
3321
3821
|
declare_transaction: {
|
|
3322
3822
|
contract_class: {
|
|
3323
3823
|
program: contractDefinition.program,
|
|
@@ -3353,7 +3853,7 @@ var RpcProvider = class {
|
|
|
3353
3853
|
return this.fetchEndpoint("starknet_addInvokeTransaction", {
|
|
3354
3854
|
invoke_transaction: {
|
|
3355
3855
|
sender_address: functionInvocation.contractAddress,
|
|
3356
|
-
calldata:
|
|
3856
|
+
calldata: CallData.toHex(functionInvocation.calldata),
|
|
3357
3857
|
type: RPC.TransactionType.INVOKE,
|
|
3358
3858
|
max_fee: toHex(details.maxFee || 0),
|
|
3359
3859
|
version: "0x1",
|
|
@@ -3368,7 +3868,7 @@ var RpcProvider = class {
|
|
|
3368
3868
|
request: {
|
|
3369
3869
|
contract_address: call.contractAddress,
|
|
3370
3870
|
entry_point_selector: getSelectorFromName(call.entrypoint),
|
|
3371
|
-
calldata:
|
|
3871
|
+
calldata: CallData.toHex(call.calldata)
|
|
3372
3872
|
},
|
|
3373
3873
|
block_id
|
|
3374
3874
|
});
|
|
@@ -3838,7 +4338,7 @@ var SequencerProvider = class {
|
|
|
3838
4338
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
3839
4339
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
3840
4340
|
sender_address: functionInvocation.contractAddress,
|
|
3841
|
-
calldata:
|
|
4341
|
+
calldata: CallData.compile(functionInvocation.calldata ?? []),
|
|
3842
4342
|
signature: signatureToDecimalArray(functionInvocation.signature),
|
|
3843
4343
|
nonce: toHex(details.nonce),
|
|
3844
4344
|
max_fee: toHex(details.maxFee || 0),
|
|
@@ -3849,7 +4349,7 @@ var SequencerProvider = class {
|
|
|
3849
4349
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
3850
4350
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
3851
4351
|
contract_address_salt: addressSalt ?? randomAddress(),
|
|
3852
|
-
constructor_calldata:
|
|
4352
|
+
constructor_calldata: CallData.compile(constructorCalldata ?? []),
|
|
3853
4353
|
class_hash: toHex(classHash),
|
|
3854
4354
|
max_fee: toHex(details.maxFee || 0),
|
|
3855
4355
|
version: toHex(details.version || 0),
|
|
@@ -3933,7 +4433,7 @@ var SequencerProvider = class {
|
|
|
3933
4433
|
{
|
|
3934
4434
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
3935
4435
|
class_hash: toHex(classHash),
|
|
3936
|
-
constructor_calldata:
|
|
4436
|
+
constructor_calldata: CallData.compile(constructorCalldata || []),
|
|
3937
4437
|
contract_address_salt: toHex(addressSalt || 0),
|
|
3938
4438
|
signature: signatureToDecimalArray(signature),
|
|
3939
4439
|
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
@@ -3960,9 +4460,7 @@ var SequencerProvider = class {
|
|
|
3960
4460
|
res = {
|
|
3961
4461
|
type: invocation.type,
|
|
3962
4462
|
class_hash: toHex(toBigInt(invocation.classHash)),
|
|
3963
|
-
constructor_calldata:
|
|
3964
|
-
invocation.constructorCalldata || []
|
|
3965
|
-
),
|
|
4463
|
+
constructor_calldata: CallData.compile(invocation.constructorCalldata || []),
|
|
3966
4464
|
contract_address_salt: toHex(toBigInt(invocation.addressSalt || 0))
|
|
3967
4465
|
};
|
|
3968
4466
|
}
|
|
@@ -4041,640 +4539,135 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
4041
4539
|
}
|
|
4042
4540
|
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
4043
4541
|
}
|
|
4044
|
-
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
4045
|
-
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4046
|
-
return this.fetchEndpoint("get_state_update", { ...args }).then(
|
|
4047
|
-
this.responseParser.parseGetStateUpdateResponse
|
|
4048
|
-
);
|
|
4049
|
-
}
|
|
4050
|
-
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
4051
|
-
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4052
|
-
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
4053
|
-
}
|
|
4054
|
-
async getStarkName(address, StarknetIdContract2) {
|
|
4055
|
-
return getStarkName(this, address, StarknetIdContract2);
|
|
4056
|
-
}
|
|
4057
|
-
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4058
|
-
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4059
|
-
}
|
|
4060
|
-
};
|
|
4061
|
-
|
|
4062
|
-
// src/provider/default.ts
|
|
4063
|
-
var Provider = class {
|
|
4064
|
-
constructor(providerOrOptions) {
|
|
4065
|
-
if (providerOrOptions instanceof Provider) {
|
|
4066
|
-
this.provider = providerOrOptions.provider;
|
|
4067
|
-
} else if (providerOrOptions instanceof RpcProvider || providerOrOptions instanceof SequencerProvider) {
|
|
4068
|
-
this.provider = providerOrOptions;
|
|
4069
|
-
} else if (providerOrOptions && "rpc" in providerOrOptions) {
|
|
4070
|
-
this.provider = new RpcProvider(providerOrOptions.rpc);
|
|
4071
|
-
} else if (providerOrOptions && "sequencer" in providerOrOptions) {
|
|
4072
|
-
this.provider = new SequencerProvider(providerOrOptions.sequencer);
|
|
4073
|
-
} else {
|
|
4074
|
-
this.provider = new SequencerProvider();
|
|
4075
|
-
}
|
|
4076
|
-
}
|
|
4077
|
-
async getChainId() {
|
|
4078
|
-
return this.provider.getChainId();
|
|
4079
|
-
}
|
|
4080
|
-
async getBlock(blockIdentifier) {
|
|
4081
|
-
return this.provider.getBlock(blockIdentifier);
|
|
4082
|
-
}
|
|
4083
|
-
async getClassAt(contractAddress, blockIdentifier) {
|
|
4084
|
-
return this.provider.getClassAt(contractAddress, blockIdentifier);
|
|
4085
|
-
}
|
|
4086
|
-
async getClassHashAt(contractAddress, blockIdentifier) {
|
|
4087
|
-
return this.provider.getClassHashAt(contractAddress, blockIdentifier);
|
|
4088
|
-
}
|
|
4089
|
-
getClassByHash(classHash) {
|
|
4090
|
-
return this.provider.getClassByHash(classHash);
|
|
4091
|
-
}
|
|
4092
|
-
async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
4093
|
-
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
4094
|
-
}
|
|
4095
|
-
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
|
|
4096
|
-
return this.provider.getInvokeEstimateFee(
|
|
4097
|
-
invocationWithTxType,
|
|
4098
|
-
invocationDetails,
|
|
4099
|
-
blockIdentifier,
|
|
4100
|
-
skipValidate
|
|
4101
|
-
);
|
|
4102
|
-
}
|
|
4103
|
-
async getEstimateFeeBulk(invocations, blockIdentifier) {
|
|
4104
|
-
return this.provider.getEstimateFeeBulk(invocations, blockIdentifier);
|
|
4105
|
-
}
|
|
4106
|
-
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
4107
|
-
return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
|
|
4108
|
-
}
|
|
4109
|
-
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4110
|
-
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
|
|
4111
|
-
}
|
|
4112
|
-
async getTransaction(txHash) {
|
|
4113
|
-
return this.provider.getTransaction(txHash);
|
|
4114
|
-
}
|
|
4115
|
-
async getTransactionReceipt(txHash) {
|
|
4116
|
-
return this.provider.getTransactionReceipt(txHash);
|
|
4117
|
-
}
|
|
4118
|
-
async callContract(request, blockIdentifier) {
|
|
4119
|
-
return this.provider.callContract(request, blockIdentifier);
|
|
4120
|
-
}
|
|
4121
|
-
async invokeFunction(functionInvocation, details) {
|
|
4122
|
-
return this.provider.invokeFunction(functionInvocation, details);
|
|
4123
|
-
}
|
|
4124
|
-
async deployAccountContract(payload, details) {
|
|
4125
|
-
return this.provider.deployAccountContract(payload, details);
|
|
4126
|
-
}
|
|
4127
|
-
async declareContract(transaction, details) {
|
|
4128
|
-
return this.provider.declareContract(transaction, details);
|
|
4129
|
-
}
|
|
4130
|
-
async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4131
|
-
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
|
|
4132
|
-
}
|
|
4133
|
-
getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4134
|
-
return this.provider.getDeployAccountEstimateFee(
|
|
4135
|
-
transaction,
|
|
4136
|
-
details,
|
|
4137
|
-
blockIdentifier,
|
|
4138
|
-
skipValidate
|
|
4139
|
-
);
|
|
4140
|
-
}
|
|
4141
|
-
async getCode(contractAddress, blockIdentifier) {
|
|
4142
|
-
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
4143
|
-
}
|
|
4144
|
-
async waitForTransaction(txHash, options) {
|
|
4145
|
-
return this.provider.waitForTransaction(txHash, options);
|
|
4146
|
-
}
|
|
4147
|
-
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
|
|
4148
|
-
return this.provider.getSimulateTransaction(
|
|
4149
|
-
invocation,
|
|
4150
|
-
invocationDetails,
|
|
4151
|
-
blockIdentifier,
|
|
4152
|
-
skipValidate
|
|
4153
|
-
);
|
|
4154
|
-
}
|
|
4155
|
-
async getStateUpdate(blockIdentifier) {
|
|
4156
|
-
return this.provider.getStateUpdate(blockIdentifier);
|
|
4157
|
-
}
|
|
4158
|
-
async getStarkName(address, StarknetIdContract2) {
|
|
4159
|
-
return getStarkName(this, address, StarknetIdContract2);
|
|
4160
|
-
}
|
|
4161
|
-
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4162
|
-
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4163
|
-
}
|
|
4164
|
-
};
|
|
4165
|
-
|
|
4166
|
-
// src/provider/interface.ts
|
|
4167
|
-
var ProviderInterface = class {
|
|
4168
|
-
};
|
|
4169
|
-
|
|
4170
|
-
// src/provider/index.ts
|
|
4171
|
-
var defaultProvider = new Provider();
|
|
4172
|
-
|
|
4173
|
-
// src/utils/calldata/formatter.ts
|
|
4174
|
-
var guard = {
|
|
4175
|
-
isBN: (data, type, key) => {
|
|
4176
|
-
if (!isBigInt(data[key]))
|
|
4177
|
-
throw new Error(
|
|
4178
|
-
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
4179
|
-
);
|
|
4180
|
-
},
|
|
4181
|
-
unknown: (data, type, key) => {
|
|
4182
|
-
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
4183
|
-
}
|
|
4184
|
-
};
|
|
4185
|
-
function formatter(data, type, sameType) {
|
|
4186
|
-
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
4187
|
-
const elType = sameType ?? type[key];
|
|
4188
|
-
if (!(key in type) && !sameType) {
|
|
4189
|
-
acc[key] = value;
|
|
4190
|
-
return acc;
|
|
4191
|
-
}
|
|
4192
|
-
if (elType === "string") {
|
|
4193
|
-
if (Array.isArray(data[key])) {
|
|
4194
|
-
const arrayStr = formatter(
|
|
4195
|
-
data[key],
|
|
4196
|
-
data[key].map((_) => elType)
|
|
4197
|
-
);
|
|
4198
|
-
acc[key] = Object.values(arrayStr).join("");
|
|
4199
|
-
return acc;
|
|
4200
|
-
}
|
|
4201
|
-
guard.isBN(data, type, key);
|
|
4202
|
-
acc[key] = decodeShortString(value);
|
|
4203
|
-
return acc;
|
|
4204
|
-
}
|
|
4205
|
-
if (elType === "number") {
|
|
4206
|
-
guard.isBN(data, type, key);
|
|
4207
|
-
acc[key] = Number(value);
|
|
4208
|
-
return acc;
|
|
4209
|
-
}
|
|
4210
|
-
if (typeof elType === "function") {
|
|
4211
|
-
acc[key] = elType(value);
|
|
4212
|
-
return acc;
|
|
4213
|
-
}
|
|
4214
|
-
if (Array.isArray(elType)) {
|
|
4215
|
-
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
4216
|
-
acc[key] = Object.values(arrayObj);
|
|
4217
|
-
return acc;
|
|
4218
|
-
}
|
|
4219
|
-
if (typeof elType === "object") {
|
|
4220
|
-
acc[key] = formatter(data[key], elType);
|
|
4221
|
-
return acc;
|
|
4222
|
-
}
|
|
4223
|
-
guard.unknown(data, type, key);
|
|
4224
|
-
return acc;
|
|
4225
|
-
}, {});
|
|
4226
|
-
}
|
|
4227
|
-
|
|
4228
|
-
// src/utils/calldata/tuple.ts
|
|
4229
|
-
function parseNamedTuple(namedTuple) {
|
|
4230
|
-
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
4231
|
-
const type = namedTuple.substring(name.length + ":".length);
|
|
4232
|
-
return { name, type };
|
|
4233
|
-
}
|
|
4234
|
-
function parseSubTuple(s) {
|
|
4235
|
-
if (!s.includes("("))
|
|
4236
|
-
return { subTuple: [], result: s };
|
|
4237
|
-
const subTuple = [];
|
|
4238
|
-
let result = "";
|
|
4239
|
-
let i = 0;
|
|
4240
|
-
while (i < s.length) {
|
|
4241
|
-
if (s[i] === "(") {
|
|
4242
|
-
let counter = 1;
|
|
4243
|
-
const lBracket = i;
|
|
4244
|
-
i++;
|
|
4245
|
-
while (counter) {
|
|
4246
|
-
if (s[i] === ")")
|
|
4247
|
-
counter--;
|
|
4248
|
-
if (s[i] === "(")
|
|
4249
|
-
counter++;
|
|
4250
|
-
i++;
|
|
4251
|
-
}
|
|
4252
|
-
subTuple.push(s.substring(lBracket, i));
|
|
4253
|
-
result += " ";
|
|
4254
|
-
i--;
|
|
4255
|
-
} else {
|
|
4256
|
-
result += s[i];
|
|
4257
|
-
}
|
|
4258
|
-
i++;
|
|
4259
|
-
}
|
|
4260
|
-
return {
|
|
4261
|
-
subTuple,
|
|
4262
|
-
result
|
|
4263
|
-
};
|
|
4264
|
-
}
|
|
4265
|
-
function extractCairo0Tuple(type) {
|
|
4266
|
-
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
4267
|
-
const { subTuple, result } = parseSubTuple(cleanType);
|
|
4268
|
-
let recomposed = result.split(",").map((it) => {
|
|
4269
|
-
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
4270
|
-
});
|
|
4271
|
-
if (isTypeNamedTuple(type)) {
|
|
4272
|
-
recomposed = recomposed.reduce((acc, it) => {
|
|
4273
|
-
return acc.concat(parseNamedTuple(it));
|
|
4274
|
-
}, []);
|
|
4275
|
-
}
|
|
4276
|
-
return recomposed;
|
|
4277
|
-
}
|
|
4278
|
-
function extractCairo1Tuple(type) {
|
|
4279
|
-
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
4280
|
-
return cleanType.split(",");
|
|
4281
|
-
}
|
|
4282
|
-
function extractTupleMemberTypes(type) {
|
|
4283
|
-
if (isCairo1Type(type)) {
|
|
4284
|
-
return extractCairo1Tuple(type);
|
|
4285
|
-
}
|
|
4286
|
-
return extractCairo0Tuple(type);
|
|
4287
|
-
}
|
|
4288
|
-
|
|
4289
|
-
// src/utils/calldata/requestParser.ts
|
|
4290
|
-
function parseTuple(element, typeStr) {
|
|
4291
|
-
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
4292
|
-
const elements = Object.values(element);
|
|
4293
|
-
if (elements.length !== memberTypes.length) {
|
|
4294
|
-
throw Error(
|
|
4295
|
-
`ParseTuple: provided and expected abi tuple size do not match.
|
|
4296
|
-
provided: ${elements}
|
|
4297
|
-
expected: ${memberTypes}`
|
|
4298
|
-
);
|
|
4299
|
-
}
|
|
4300
|
-
return memberTypes.map((it, dx) => {
|
|
4301
|
-
return {
|
|
4302
|
-
element: elements[dx],
|
|
4303
|
-
type: it.type ?? it
|
|
4304
|
-
};
|
|
4305
|
-
});
|
|
4306
|
-
}
|
|
4307
|
-
function parseCalldataValue(element, type, structs) {
|
|
4308
|
-
if (element === void 0) {
|
|
4309
|
-
throw Error(`Missing parameter for type ${type}`);
|
|
4310
|
-
}
|
|
4311
|
-
if (Array.isArray(element)) {
|
|
4312
|
-
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
4313
|
-
}
|
|
4314
|
-
if (isTypeUint256(type)) {
|
|
4315
|
-
const el_uint256 = uint256(element);
|
|
4316
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
4317
|
-
}
|
|
4318
|
-
if (structs[type] && structs[type].members.length) {
|
|
4319
|
-
const { members } = structs[type];
|
|
4320
|
-
const subElement = element;
|
|
4321
|
-
return members.reduce((acc, it) => {
|
|
4322
|
-
return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs));
|
|
4323
|
-
}, []);
|
|
4324
|
-
}
|
|
4325
|
-
if (isTypeTuple(type)) {
|
|
4326
|
-
const tupled = parseTuple(element, type);
|
|
4327
|
-
return tupled.reduce((acc, it) => {
|
|
4328
|
-
const parsedData = parseCalldataValue(it.element, it.type, structs);
|
|
4329
|
-
return acc.concat(parsedData);
|
|
4330
|
-
}, []);
|
|
4331
|
-
}
|
|
4332
|
-
if (typeof element === "object") {
|
|
4333
|
-
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
4334
|
-
}
|
|
4335
|
-
return felt(element);
|
|
4336
|
-
}
|
|
4337
|
-
function parseCalldataField(argsIterator, input, structs) {
|
|
4338
|
-
const { name, type } = input;
|
|
4339
|
-
let { value } = argsIterator.next();
|
|
4340
|
-
switch (true) {
|
|
4341
|
-
case isTypeArray(type):
|
|
4342
|
-
if (!Array.isArray(value) && !isText(value)) {
|
|
4343
|
-
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
4344
|
-
}
|
|
4345
|
-
if (typeof value === "string") {
|
|
4346
|
-
value = splitLongString(value);
|
|
4347
|
-
}
|
|
4348
|
-
const result = [];
|
|
4349
|
-
result.push(felt(value.length));
|
|
4350
|
-
const arrayType = getArrayType(input.type);
|
|
4351
|
-
return value.reduce((acc, el) => {
|
|
4352
|
-
if (isTypeFelt(arrayType) || isTypeUint(arrayType) || isTypeContractAddress(arrayType)) {
|
|
4353
|
-
acc.push(felt(el));
|
|
4354
|
-
} else if (isTypeBool(arrayType) && typeof el === "boolean") {
|
|
4355
|
-
acc.push(el.toString());
|
|
4356
|
-
} else {
|
|
4357
|
-
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
4358
|
-
}
|
|
4359
|
-
return acc;
|
|
4360
|
-
}, result);
|
|
4361
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
|
|
4362
|
-
return parseCalldataValue(value, type, structs);
|
|
4363
|
-
case isTypeBool(type):
|
|
4364
|
-
return `${+value}`;
|
|
4365
|
-
default:
|
|
4366
|
-
return felt(value);
|
|
4367
|
-
}
|
|
4368
|
-
}
|
|
4369
|
-
|
|
4370
|
-
// src/utils/calldata/responseParser.ts
|
|
4371
|
-
function parseResponseStruct(responseIterator, type, structs) {
|
|
4372
|
-
if (type in structs && structs[type]) {
|
|
4373
|
-
return structs[type].members.reduce((acc, el) => {
|
|
4374
|
-
acc[el.name] = parseResponseStruct(responseIterator, el.type, structs);
|
|
4375
|
-
return acc;
|
|
4376
|
-
}, {});
|
|
4377
|
-
}
|
|
4378
|
-
if (isTypeTuple(type)) {
|
|
4379
|
-
const memberTypes = extractTupleMemberTypes(type);
|
|
4380
|
-
return memberTypes.reduce((acc, it, idx) => {
|
|
4381
|
-
const tName = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
4382
|
-
const tType = (it == null ? void 0 : it.type) ? it.type : it;
|
|
4383
|
-
acc[tName] = parseResponseStruct(responseIterator, tType, structs);
|
|
4384
|
-
return acc;
|
|
4385
|
-
}, {});
|
|
4386
|
-
}
|
|
4387
|
-
const temp = responseIterator.next().value;
|
|
4388
|
-
return BigInt(temp);
|
|
4389
|
-
}
|
|
4390
|
-
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
4391
|
-
const { name, type } = output;
|
|
4392
|
-
let temp;
|
|
4393
|
-
switch (true) {
|
|
4394
|
-
case isLen(name):
|
|
4395
|
-
temp = responseIterator.next().value;
|
|
4396
|
-
return BigInt(temp);
|
|
4397
|
-
case isTypeBool(type):
|
|
4398
|
-
temp = responseIterator.next().value;
|
|
4399
|
-
return Boolean(BigInt(temp));
|
|
4400
|
-
case isTypeUint256(type):
|
|
4401
|
-
const low = responseIterator.next().value;
|
|
4402
|
-
const high = responseIterator.next().value;
|
|
4403
|
-
return uint256ToBN({ low, high });
|
|
4404
|
-
case isTypeArray(type):
|
|
4405
|
-
const parsedDataArr = [];
|
|
4406
|
-
if (isCairo1Type(type)) {
|
|
4407
|
-
responseIterator.next();
|
|
4408
|
-
let it = responseIterator.next();
|
|
4409
|
-
while (!it.done) {
|
|
4410
|
-
parsedDataArr.push(BigInt(it.value));
|
|
4411
|
-
it = responseIterator.next();
|
|
4412
|
-
}
|
|
4413
|
-
return parsedDataArr;
|
|
4414
|
-
}
|
|
4415
|
-
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
4416
|
-
const arrLen = parsedResult[`${name}_len`];
|
|
4417
|
-
while (parsedDataArr.length < arrLen) {
|
|
4418
|
-
parsedDataArr.push(
|
|
4419
|
-
parseResponseStruct(responseIterator, output.type.replace("*", ""), structs)
|
|
4420
|
-
);
|
|
4421
|
-
}
|
|
4422
|
-
}
|
|
4423
|
-
return parsedDataArr;
|
|
4424
|
-
case (type in structs || isTypeTuple(type)):
|
|
4425
|
-
return parseResponseStruct(responseIterator, type, structs);
|
|
4426
|
-
default:
|
|
4427
|
-
temp = responseIterator.next().value;
|
|
4428
|
-
return BigInt(temp);
|
|
4429
|
-
}
|
|
4430
|
-
}
|
|
4431
|
-
|
|
4432
|
-
// src/utils/calldata/validate.ts
|
|
4433
|
-
var validateFelt = (parameter, input) => {
|
|
4434
|
-
assert(
|
|
4435
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
4436
|
-
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
4437
|
-
);
|
|
4438
|
-
};
|
|
4439
|
-
var validateUint = (parameter, input) => {
|
|
4440
|
-
if (typeof parameter === "number") {
|
|
4441
|
-
assert(
|
|
4442
|
-
parameter <= Number.MAX_SAFE_INTEGER,
|
|
4443
|
-
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
4444
|
-
);
|
|
4445
|
-
}
|
|
4446
|
-
assert(
|
|
4447
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
4448
|
-
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
|
|
4449
|
-
);
|
|
4450
|
-
const param = toBigInt(parameter);
|
|
4451
|
-
switch (input.type) {
|
|
4452
|
-
case "core::integer::u8" /* u8 */:
|
|
4453
|
-
assert(
|
|
4454
|
-
param >= 0n && param <= 255n,
|
|
4455
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
4456
|
-
);
|
|
4457
|
-
break;
|
|
4458
|
-
case "core::integer::u16" /* u16 */:
|
|
4459
|
-
assert(
|
|
4460
|
-
param >= 0n && param <= 65535n,
|
|
4461
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
4462
|
-
);
|
|
4463
|
-
break;
|
|
4464
|
-
case "core::integer::u32" /* u32 */:
|
|
4465
|
-
assert(
|
|
4466
|
-
param >= 0n && param <= 4294967295n,
|
|
4467
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
4468
|
-
);
|
|
4469
|
-
break;
|
|
4470
|
-
case "core::integer::u64" /* u64 */:
|
|
4471
|
-
assert(
|
|
4472
|
-
param >= 0n && param <= 2n ** 64n - 1n,
|
|
4473
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
4474
|
-
);
|
|
4475
|
-
break;
|
|
4476
|
-
case "core::integer::u128" /* u128 */:
|
|
4477
|
-
assert(
|
|
4478
|
-
param >= 0n && param <= 2n ** 128n - 1n,
|
|
4479
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
4480
|
-
);
|
|
4481
|
-
break;
|
|
4482
|
-
case "core::integer::u256" /* u256 */:
|
|
4483
|
-
assert(
|
|
4484
|
-
param >= 0n && param <= 2n ** 256n - 1n,
|
|
4485
|
-
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
4486
|
-
);
|
|
4487
|
-
break;
|
|
4488
|
-
default:
|
|
4489
|
-
break;
|
|
4490
|
-
}
|
|
4491
|
-
};
|
|
4492
|
-
var validateBool = (parameter, input) => {
|
|
4493
|
-
assert(
|
|
4494
|
-
typeof parameter === "boolean",
|
|
4495
|
-
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
4496
|
-
);
|
|
4497
|
-
};
|
|
4498
|
-
var validateStruct = (parameter, input, structs) => {
|
|
4499
|
-
assert(
|
|
4500
|
-
typeof parameter === "object" && !Array.isArray(parameter),
|
|
4501
|
-
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
4502
|
-
);
|
|
4503
|
-
structs[input.type].members.forEach(({ name }) => {
|
|
4504
|
-
assert(
|
|
4505
|
-
Object.keys(parameter).includes(name),
|
|
4506
|
-
`Validate: arg ${input.name} should have a property ${name}`
|
|
4507
|
-
);
|
|
4508
|
-
});
|
|
4509
|
-
};
|
|
4510
|
-
var validateTuple = (parameter, input) => {
|
|
4511
|
-
assert(
|
|
4512
|
-
typeof parameter === "object" && !Array.isArray(parameter),
|
|
4513
|
-
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
4514
|
-
);
|
|
4515
|
-
};
|
|
4516
|
-
var validateArray = (parameter, input, structs) => {
|
|
4517
|
-
const baseType = getArrayType(input.type);
|
|
4518
|
-
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
4519
|
-
return;
|
|
4520
|
-
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
4521
|
-
switch (true) {
|
|
4522
|
-
case isTypeFelt(baseType):
|
|
4523
|
-
parameter.forEach((param) => validateFelt(param, input));
|
|
4524
|
-
break;
|
|
4525
|
-
case isTypeTuple(baseType):
|
|
4526
|
-
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
4527
|
-
break;
|
|
4528
|
-
case isTypeStruct(baseType, structs):
|
|
4529
|
-
parameter.forEach(
|
|
4530
|
-
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
4531
|
-
);
|
|
4532
|
-
break;
|
|
4533
|
-
case isTypeUint(baseType):
|
|
4534
|
-
parameter.forEach((param) => validateUint(param, input));
|
|
4535
|
-
break;
|
|
4536
|
-
case isTypeBool(baseType):
|
|
4537
|
-
parameter.forEach((param) => validateBool(param, input));
|
|
4538
|
-
break;
|
|
4539
|
-
default:
|
|
4540
|
-
throw new Error(
|
|
4541
|
-
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
4542
|
-
);
|
|
4543
|
-
}
|
|
4542
|
+
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
4543
|
+
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4544
|
+
return this.fetchEndpoint("get_state_update", { ...args }).then(
|
|
4545
|
+
this.responseParser.parseGetStateUpdateResponse
|
|
4546
|
+
);
|
|
4547
|
+
}
|
|
4548
|
+
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
4549
|
+
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4550
|
+
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
4551
|
+
}
|
|
4552
|
+
async getStarkName(address, StarknetIdContract2) {
|
|
4553
|
+
return getStarkName(this, address, StarknetIdContract2);
|
|
4554
|
+
}
|
|
4555
|
+
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4556
|
+
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4557
|
+
}
|
|
4544
4558
|
};
|
|
4545
|
-
function validateFields(abiMethod, args, structs) {
|
|
4546
|
-
abiMethod.inputs.reduce((acc, input) => {
|
|
4547
|
-
const parameter = args[acc];
|
|
4548
|
-
switch (true) {
|
|
4549
|
-
case isLen(input.name):
|
|
4550
|
-
return acc;
|
|
4551
|
-
case isTypeFelt(input.type):
|
|
4552
|
-
validateFelt(parameter, input);
|
|
4553
|
-
break;
|
|
4554
|
-
case isTypeUint(input.type):
|
|
4555
|
-
validateUint(parameter, input);
|
|
4556
|
-
break;
|
|
4557
|
-
case isTypeBool(input.type):
|
|
4558
|
-
validateBool(parameter, input);
|
|
4559
|
-
break;
|
|
4560
|
-
case isTypeContractAddress(input.type):
|
|
4561
|
-
break;
|
|
4562
|
-
case isTypeStruct(input.type, structs):
|
|
4563
|
-
validateStruct(parameter, input, structs);
|
|
4564
|
-
break;
|
|
4565
|
-
case isTypeTuple(input.type):
|
|
4566
|
-
validateTuple(parameter, input);
|
|
4567
|
-
break;
|
|
4568
|
-
case isTypeArray(input.type):
|
|
4569
|
-
validateArray(parameter, input, structs);
|
|
4570
|
-
break;
|
|
4571
|
-
default:
|
|
4572
|
-
throw new Error(
|
|
4573
|
-
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
4574
|
-
);
|
|
4575
|
-
}
|
|
4576
|
-
return acc + 1;
|
|
4577
|
-
}, 0);
|
|
4578
|
-
}
|
|
4579
4559
|
|
|
4580
|
-
// src/
|
|
4581
|
-
var
|
|
4582
|
-
constructor(
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
if (
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
}).map((abi) => abi.name);
|
|
4594
|
-
assert(
|
|
4595
|
-
invocableFunctionNames.includes(method),
|
|
4596
|
-
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
4597
|
-
);
|
|
4598
|
-
}
|
|
4599
|
-
const abiMethod = this.abi.find(
|
|
4600
|
-
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
4601
|
-
);
|
|
4602
|
-
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
4603
|
-
if (args.length !== inputsLength) {
|
|
4604
|
-
throw Error(
|
|
4605
|
-
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
4606
|
-
);
|
|
4560
|
+
// src/provider/default.ts
|
|
4561
|
+
var Provider = class {
|
|
4562
|
+
constructor(providerOrOptions) {
|
|
4563
|
+
if (providerOrOptions instanceof Provider) {
|
|
4564
|
+
this.provider = providerOrOptions.provider;
|
|
4565
|
+
} else if (providerOrOptions instanceof RpcProvider || providerOrOptions instanceof SequencerProvider) {
|
|
4566
|
+
this.provider = providerOrOptions;
|
|
4567
|
+
} else if (providerOrOptions && "rpc" in providerOrOptions) {
|
|
4568
|
+
this.provider = new RpcProvider(providerOrOptions.rpc);
|
|
4569
|
+
} else if (providerOrOptions && "sequencer" in providerOrOptions) {
|
|
4570
|
+
this.provider = new SequencerProvider(providerOrOptions.sequencer);
|
|
4571
|
+
} else {
|
|
4572
|
+
this.provider = new SequencerProvider();
|
|
4607
4573
|
}
|
|
4608
|
-
validateFields(abiMethod, args, this.structs);
|
|
4609
4574
|
}
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4575
|
+
async getChainId() {
|
|
4576
|
+
return this.provider.getChainId();
|
|
4577
|
+
}
|
|
4578
|
+
async getBlock(blockIdentifier) {
|
|
4579
|
+
return this.provider.getBlock(blockIdentifier);
|
|
4580
|
+
}
|
|
4581
|
+
async getClassAt(contractAddress, blockIdentifier) {
|
|
4582
|
+
return this.provider.getClassAt(contractAddress, blockIdentifier);
|
|
4583
|
+
}
|
|
4584
|
+
async getClassHashAt(contractAddress, blockIdentifier) {
|
|
4585
|
+
return this.provider.getClassHashAt(contractAddress, blockIdentifier);
|
|
4586
|
+
}
|
|
4587
|
+
getClassByHash(classHash) {
|
|
4588
|
+
return this.provider.getClassByHash(classHash);
|
|
4589
|
+
}
|
|
4590
|
+
async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
4591
|
+
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
4592
|
+
}
|
|
4593
|
+
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
|
|
4594
|
+
return this.provider.getInvokeEstimateFee(
|
|
4595
|
+
invocationWithTxType,
|
|
4596
|
+
invocationDetails,
|
|
4597
|
+
blockIdentifier,
|
|
4598
|
+
skipValidate
|
|
4615
4599
|
);
|
|
4616
4600
|
}
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
const getEntries = (o, prefix = "") => {
|
|
4620
|
-
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
4621
|
-
return Object.entries(oe).flatMap(([k, v]) => {
|
|
4622
|
-
let value = v;
|
|
4623
|
-
if (isLongText(value))
|
|
4624
|
-
value = splitLongString(value);
|
|
4625
|
-
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
4626
|
-
if (isBigInt(value))
|
|
4627
|
-
return [[`${prefix}${kk}`, felt(value)]];
|
|
4628
|
-
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
4629
|
-
});
|
|
4630
|
-
};
|
|
4631
|
-
return Object.fromEntries(getEntries(obj));
|
|
4632
|
-
};
|
|
4633
|
-
let callTreeArray;
|
|
4634
|
-
if (!Array.isArray(data)) {
|
|
4635
|
-
const callTree = createTree(data);
|
|
4636
|
-
callTreeArray = Object.values(callTree);
|
|
4637
|
-
} else {
|
|
4638
|
-
callTreeArray = data;
|
|
4639
|
-
}
|
|
4640
|
-
Object.defineProperty(callTreeArray, "compiled", {
|
|
4641
|
-
enumerable: false,
|
|
4642
|
-
writable: false,
|
|
4643
|
-
value: true
|
|
4644
|
-
});
|
|
4645
|
-
return callTreeArray;
|
|
4601
|
+
async getEstimateFeeBulk(invocations, blockIdentifier) {
|
|
4602
|
+
return this.provider.getEstimateFeeBulk(invocations, blockIdentifier);
|
|
4646
4603
|
}
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
const responseIterator = response.flat()[Symbol.iterator]();
|
|
4650
|
-
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
4651
|
-
const propName = output.name ?? idx;
|
|
4652
|
-
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
4653
|
-
if (acc[propName] && acc[`${propName}_len`]) {
|
|
4654
|
-
delete acc[`${propName}_len`];
|
|
4655
|
-
}
|
|
4656
|
-
return acc;
|
|
4657
|
-
}, {});
|
|
4658
|
-
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
4604
|
+
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
4605
|
+
return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
|
|
4659
4606
|
}
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
return formatter(parsed, format);
|
|
4607
|
+
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4608
|
+
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
|
|
4663
4609
|
}
|
|
4664
|
-
|
|
4665
|
-
return
|
|
4610
|
+
async getTransaction(txHash) {
|
|
4611
|
+
return this.provider.getTransaction(txHash);
|
|
4666
4612
|
}
|
|
4667
|
-
|
|
4668
|
-
return
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4613
|
+
async getTransactionReceipt(txHash) {
|
|
4614
|
+
return this.provider.getTransactionReceipt(txHash);
|
|
4615
|
+
}
|
|
4616
|
+
async callContract(request, blockIdentifier) {
|
|
4617
|
+
return this.provider.callContract(request, blockIdentifier);
|
|
4618
|
+
}
|
|
4619
|
+
async invokeFunction(functionInvocation, details) {
|
|
4620
|
+
return this.provider.invokeFunction(functionInvocation, details);
|
|
4621
|
+
}
|
|
4622
|
+
async deployAccountContract(payload, details) {
|
|
4623
|
+
return this.provider.deployAccountContract(payload, details);
|
|
4624
|
+
}
|
|
4625
|
+
async declareContract(transaction, details) {
|
|
4626
|
+
return this.provider.declareContract(transaction, details);
|
|
4627
|
+
}
|
|
4628
|
+
async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4629
|
+
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
|
|
4630
|
+
}
|
|
4631
|
+
getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4632
|
+
return this.provider.getDeployAccountEstimateFee(
|
|
4633
|
+
transaction,
|
|
4634
|
+
details,
|
|
4635
|
+
blockIdentifier,
|
|
4636
|
+
skipValidate
|
|
4637
|
+
);
|
|
4638
|
+
}
|
|
4639
|
+
async getCode(contractAddress, blockIdentifier) {
|
|
4640
|
+
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
4641
|
+
}
|
|
4642
|
+
async waitForTransaction(txHash, options) {
|
|
4643
|
+
return this.provider.waitForTransaction(txHash, options);
|
|
4644
|
+
}
|
|
4645
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
|
|
4646
|
+
return this.provider.getSimulateTransaction(
|
|
4647
|
+
invocation,
|
|
4648
|
+
invocationDetails,
|
|
4649
|
+
blockIdentifier,
|
|
4650
|
+
skipValidate
|
|
4674
4651
|
);
|
|
4675
4652
|
}
|
|
4653
|
+
async getStateUpdate(blockIdentifier) {
|
|
4654
|
+
return this.provider.getStateUpdate(blockIdentifier);
|
|
4655
|
+
}
|
|
4656
|
+
async getStarkName(address, StarknetIdContract2) {
|
|
4657
|
+
return getStarkName(this, address, StarknetIdContract2);
|
|
4658
|
+
}
|
|
4659
|
+
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4660
|
+
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4661
|
+
}
|
|
4662
|
+
};
|
|
4663
|
+
|
|
4664
|
+
// src/provider/interface.ts
|
|
4665
|
+
var ProviderInterface = class {
|
|
4676
4666
|
};
|
|
4677
4667
|
|
|
4668
|
+
// src/provider/index.ts
|
|
4669
|
+
var defaultProvider = new Provider();
|
|
4670
|
+
|
|
4678
4671
|
// src/contract/default.ts
|
|
4679
4672
|
var splitArgsAndOptions = (args) => {
|
|
4680
4673
|
const options = [
|
|
@@ -4684,13 +4677,14 @@ var splitArgsAndOptions = (args) => {
|
|
|
4684
4677
|
"formatResponse",
|
|
4685
4678
|
"maxFee",
|
|
4686
4679
|
"nonce",
|
|
4687
|
-
"signature"
|
|
4680
|
+
"signature",
|
|
4681
|
+
"addressSalt"
|
|
4688
4682
|
];
|
|
4689
4683
|
const lastArg = args[args.length - 1];
|
|
4690
4684
|
if (typeof lastArg === "object" && options.some((x) => x in lastArg)) {
|
|
4691
4685
|
return { args, options: args.pop() };
|
|
4692
4686
|
}
|
|
4693
|
-
return { args
|
|
4687
|
+
return { args };
|
|
4694
4688
|
};
|
|
4695
4689
|
function buildCall(contract, functionAbi) {
|
|
4696
4690
|
return async function(...args) {
|
|
@@ -4727,20 +4721,20 @@ function buildEstimate(contract, functionAbi) {
|
|
|
4727
4721
|
return contract.estimate(functionAbi.name, args);
|
|
4728
4722
|
};
|
|
4729
4723
|
}
|
|
4730
|
-
|
|
4731
|
-
if (
|
|
4732
|
-
return
|
|
4733
|
-
|
|
4734
|
-
|
|
4724
|
+
function getCalldata(args, callback) {
|
|
4725
|
+
if ("__compiled__" in args)
|
|
4726
|
+
return args;
|
|
4727
|
+
if (Array.isArray(args[0]) && "__compiled__" in args[0])
|
|
4728
|
+
return args[0];
|
|
4729
|
+
return callback();
|
|
4730
|
+
}
|
|
4735
4731
|
var Contract = class {
|
|
4736
|
-
constructor(abi, address, providerOrAccount = defaultProvider
|
|
4737
|
-
this.version = "0";
|
|
4732
|
+
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
4738
4733
|
this.address = address && address.toLowerCase();
|
|
4739
4734
|
this.providerOrAccount = providerOrAccount;
|
|
4740
4735
|
this.callData = new CallData(abi);
|
|
4741
4736
|
this.structs = CallData.getAbiStruct(abi);
|
|
4742
4737
|
this.abi = abi;
|
|
4743
|
-
this.version = cairoVersion;
|
|
4744
4738
|
const options = { enumerable: true, value: {}, writable: false };
|
|
4745
4739
|
Object.defineProperties(this, {
|
|
4746
4740
|
functions: { enumerable: true, value: {}, writable: false },
|
|
@@ -4797,15 +4791,21 @@ var Contract = class {
|
|
|
4797
4791
|
}
|
|
4798
4792
|
return this;
|
|
4799
4793
|
}
|
|
4800
|
-
async call(method, args = [],
|
|
4794
|
+
async call(method, args = [], {
|
|
4795
|
+
parseRequest = true,
|
|
4796
|
+
parseResponse = true,
|
|
4797
|
+
formatResponse = void 0,
|
|
4798
|
+
blockIdentifier = void 0
|
|
4799
|
+
} = {}) {
|
|
4801
4800
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4802
|
-
const
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4801
|
+
const calldata = getCalldata(args, () => {
|
|
4802
|
+
if (parseRequest) {
|
|
4803
|
+
this.callData.validate("CALL", method, args);
|
|
4804
|
+
return this.callData.compile(method, args);
|
|
4805
|
+
}
|
|
4806
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
4807
|
+
return args;
|
|
4808
|
+
});
|
|
4809
4809
|
return this.providerOrAccount.callContract(
|
|
4810
4810
|
{
|
|
4811
4811
|
contractAddress: this.address,
|
|
@@ -4814,25 +4814,25 @@ var Contract = class {
|
|
|
4814
4814
|
},
|
|
4815
4815
|
blockIdentifier
|
|
4816
4816
|
).then((x) => {
|
|
4817
|
-
if (!
|
|
4817
|
+
if (!parseResponse) {
|
|
4818
4818
|
return x.result;
|
|
4819
4819
|
}
|
|
4820
|
-
if (
|
|
4821
|
-
return this.callData.format(method, x.result,
|
|
4820
|
+
if (formatResponse) {
|
|
4821
|
+
return this.callData.format(method, x.result, formatResponse);
|
|
4822
4822
|
}
|
|
4823
4823
|
return this.callData.parse(method, x.result);
|
|
4824
4824
|
});
|
|
4825
4825
|
}
|
|
4826
|
-
invoke(method, args = [],
|
|
4827
|
-
parseRequest: true
|
|
4828
|
-
}) {
|
|
4826
|
+
invoke(method, args = [], { parseRequest = true, maxFee, nonce, signature } = {}) {
|
|
4829
4827
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4828
|
+
const calldata = getCalldata(args, () => {
|
|
4829
|
+
if (parseRequest) {
|
|
4830
|
+
this.callData.validate("INVOKE", method, args);
|
|
4831
|
+
return this.callData.compile(method, args);
|
|
4832
|
+
}
|
|
4833
|
+
console.warn("Invoke skipped parsing but provided rawArgs, possible malfunction request");
|
|
4834
|
+
return args;
|
|
4835
|
+
});
|
|
4836
4836
|
const invocation = {
|
|
4837
4837
|
contractAddress: this.address,
|
|
4838
4838
|
calldata,
|
|
@@ -4840,40 +4840,36 @@ var Contract = class {
|
|
|
4840
4840
|
};
|
|
4841
4841
|
if ("execute" in this.providerOrAccount) {
|
|
4842
4842
|
return this.providerOrAccount.execute(invocation, void 0, {
|
|
4843
|
-
maxFee
|
|
4844
|
-
nonce
|
|
4843
|
+
maxFee,
|
|
4844
|
+
nonce
|
|
4845
4845
|
});
|
|
4846
4846
|
}
|
|
4847
|
-
if (!
|
|
4847
|
+
if (!nonce)
|
|
4848
4848
|
throw new Error(`Nonce is required when invoking a function without an account`);
|
|
4849
|
-
}
|
|
4850
4849
|
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
4851
4850
|
return this.providerOrAccount.invokeFunction(
|
|
4852
4851
|
{
|
|
4853
4852
|
...invocation,
|
|
4854
|
-
signature
|
|
4853
|
+
signature
|
|
4855
4854
|
},
|
|
4856
4855
|
{
|
|
4857
|
-
nonce
|
|
4856
|
+
nonce
|
|
4858
4857
|
}
|
|
4859
4858
|
);
|
|
4860
4859
|
}
|
|
4861
4860
|
async estimate(method, args = []) {
|
|
4862
|
-
var _a;
|
|
4863
4861
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4864
|
-
if (!((
|
|
4862
|
+
if (!getCalldata(args, () => false)) {
|
|
4865
4863
|
this.callData.validate("INVOKE", method, args);
|
|
4866
4864
|
}
|
|
4867
|
-
const invocation = this.
|
|
4865
|
+
const invocation = this.populate(method, args);
|
|
4868
4866
|
if ("estimateInvokeFee" in this.providerOrAccount) {
|
|
4869
4867
|
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
4870
4868
|
}
|
|
4871
4869
|
throw Error("Contract must be connected to the account contract to estimate");
|
|
4872
4870
|
}
|
|
4873
4871
|
populate(method, args = []) {
|
|
4874
|
-
|
|
4875
|
-
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
4876
|
-
const calldata = ((_a = args == null ? void 0 : args[0]) == null ? void 0 : _a.compiled) ? args == null ? void 0 : args[0] : this.callData.compile(args, inputs);
|
|
4872
|
+
const calldata = getCalldata(args, () => this.callData.compile(method, args));
|
|
4877
4873
|
return {
|
|
4878
4874
|
contractAddress: this.address,
|
|
4879
4875
|
entrypoint: method,
|
|
@@ -4893,36 +4889,24 @@ var ContractFactory = class {
|
|
|
4893
4889
|
this.compiledContract = compiledContract;
|
|
4894
4890
|
this.account = account;
|
|
4895
4891
|
this.classHash = classHash;
|
|
4896
|
-
this.
|
|
4892
|
+
this.CallData = new CallData(abi);
|
|
4897
4893
|
}
|
|
4898
4894
|
async deploy(...args) {
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
if (typeof arg !== "object")
|
|
4905
|
-
return;
|
|
4906
|
-
if ("addressSalt" in arg) {
|
|
4907
|
-
addressSalt = arg.addressSalt;
|
|
4908
|
-
}
|
|
4909
|
-
if ("parseRequest" in arg) {
|
|
4910
|
-
parseRequest = arg.parseRequest;
|
|
4895
|
+
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
4896
|
+
const constructorCalldata = getCalldata(param, () => {
|
|
4897
|
+
if (options.parseRequest) {
|
|
4898
|
+
this.CallData.validate("DEPLOY", "constructor", param);
|
|
4899
|
+
return this.CallData.compile("constructor", param);
|
|
4911
4900
|
}
|
|
4901
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
4902
|
+
return param;
|
|
4912
4903
|
});
|
|
4913
|
-
if (!parseRequest || ((_a = args[0]) == null ? void 0 : _a.compiled)) {
|
|
4914
|
-
constructorCalldata = args[0];
|
|
4915
|
-
} else {
|
|
4916
|
-
this.callData.validate("DEPLOY", "constructor", args);
|
|
4917
|
-
const { inputs } = this.abi.find((abi) => abi.type === "constructor");
|
|
4918
|
-
constructorCalldata = this.callData.compile(args, inputs);
|
|
4919
|
-
}
|
|
4920
4904
|
const {
|
|
4921
4905
|
deploy: { contract_address, transaction_hash }
|
|
4922
4906
|
} = await this.account.declareAndDeploy({
|
|
4923
4907
|
contract: this.compiledContract,
|
|
4924
4908
|
constructorCalldata,
|
|
4925
|
-
salt: addressSalt
|
|
4909
|
+
salt: options.addressSalt
|
|
4926
4910
|
});
|
|
4927
4911
|
assert(Boolean(contract_address), "Deployment of the contract failed");
|
|
4928
4912
|
const contractInstance = new Contract(
|
|
@@ -4971,19 +4955,13 @@ var transformCallsToMulticallArrays = (calls) => {
|
|
|
4971
4955
|
});
|
|
4972
4956
|
return {
|
|
4973
4957
|
callArray,
|
|
4974
|
-
calldata:
|
|
4958
|
+
calldata: CallData.compile({ calldata })
|
|
4975
4959
|
};
|
|
4976
4960
|
};
|
|
4977
4961
|
var fromCallsToExecuteCalldata = (calls) => {
|
|
4978
4962
|
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
...callArray.map(
|
|
4982
|
-
({ to, selector, data_offset, data_len }) => [to, selector, data_offset, data_len]
|
|
4983
|
-
).flat(),
|
|
4984
|
-
calldata.length.toString(),
|
|
4985
|
-
...calldata
|
|
4986
|
-
];
|
|
4963
|
+
const compiledCalls = CallData.compile({ callArray });
|
|
4964
|
+
return [...compiledCalls, ...calldata];
|
|
4987
4965
|
};
|
|
4988
4966
|
var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
|
|
4989
4967
|
return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
|
|
@@ -4992,20 +4970,16 @@ var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
|
4992
4970
|
const callArray = calls.map((call) => ({
|
|
4993
4971
|
to: toBigInt(call.contractAddress).toString(10),
|
|
4994
4972
|
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
4995
|
-
calldata:
|
|
4973
|
+
calldata: CallData.compile(call.calldata || [])
|
|
4996
4974
|
}));
|
|
4997
4975
|
return callArray;
|
|
4998
4976
|
};
|
|
4999
4977
|
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
5000
|
-
|
|
5001
|
-
return [
|
|
5002
|
-
callArray.length.toString(),
|
|
5003
|
-
...callArray.map(({ to, selector, calldata }) => [to, selector, calldata.length.toString(), ...calldata]).flat()
|
|
5004
|
-
];
|
|
4978
|
+
return CallData.compile({ calls });
|
|
5005
4979
|
};
|
|
5006
4980
|
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
5007
4981
|
if (cairoVersion === "1") {
|
|
5008
|
-
return
|
|
4982
|
+
return CallData.compile({ calls });
|
|
5009
4983
|
}
|
|
5010
4984
|
return fromCallsToExecuteCalldata(calls);
|
|
5011
4985
|
};
|
|
@@ -5550,7 +5524,7 @@ var Account = class extends Provider {
|
|
|
5550
5524
|
unique = true,
|
|
5551
5525
|
constructorCalldata = []
|
|
5552
5526
|
} = it;
|
|
5553
|
-
const compiledConstructorCallData =
|
|
5527
|
+
const compiledConstructorCallData = CallData.compile(constructorCalldata);
|
|
5554
5528
|
const deploySalt = salt ?? randomAddress();
|
|
5555
5529
|
return {
|
|
5556
5530
|
call: {
|
|
@@ -5574,7 +5548,10 @@ var Account = class extends Provider {
|
|
|
5574
5548
|
});
|
|
5575
5549
|
const calls = params.map((it) => it.call);
|
|
5576
5550
|
const addresses = params.map((it) => it.address);
|
|
5577
|
-
const invokeResponse = await this.execute(calls, void 0,
|
|
5551
|
+
const invokeResponse = await this.execute(calls, void 0, {
|
|
5552
|
+
...details,
|
|
5553
|
+
cairoVersion: "0"
|
|
5554
|
+
});
|
|
5578
5555
|
return {
|
|
5579
5556
|
...invokeResponse,
|
|
5580
5557
|
contract_address: addresses
|
|
@@ -5608,7 +5585,8 @@ var Account = class extends Provider {
|
|
|
5608
5585
|
const version = toBigInt(transactionVersion);
|
|
5609
5586
|
const nonce = ZERO;
|
|
5610
5587
|
const chainId = await this.getChainId();
|
|
5611
|
-
const
|
|
5588
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5589
|
+
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5612
5590
|
const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
5613
5591
|
{
|
|
5614
5592
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
@@ -5646,7 +5624,7 @@ var Account = class extends Provider {
|
|
|
5646
5624
|
await this.callContract({
|
|
5647
5625
|
contractAddress: this.address,
|
|
5648
5626
|
entrypoint: "isValidSignature",
|
|
5649
|
-
calldata:
|
|
5627
|
+
calldata: CallData.compile({
|
|
5650
5628
|
hash: toBigInt(hash).toString(),
|
|
5651
5629
|
signature: formatSignature(signature)
|
|
5652
5630
|
})
|
|
@@ -5706,7 +5684,8 @@ var Account = class extends Provider {
|
|
|
5706
5684
|
constructorCalldata = [],
|
|
5707
5685
|
contractAddress: providedContractAddress
|
|
5708
5686
|
}, { nonce, chainId, version, maxFee }) {
|
|
5709
|
-
const
|
|
5687
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5688
|
+
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5710
5689
|
const signature = await this.signer.signDeployAccountTransaction({
|
|
5711
5690
|
classHash,
|
|
5712
5691
|
contractAddress,
|
|
@@ -5732,7 +5711,7 @@ var Account = class extends Provider {
|
|
|
5732
5711
|
unique = true,
|
|
5733
5712
|
constructorCalldata = []
|
|
5734
5713
|
} = it;
|
|
5735
|
-
const compiledConstructorCallData =
|
|
5714
|
+
const compiledConstructorCallData = CallData.compile(constructorCalldata);
|
|
5736
5715
|
return {
|
|
5737
5716
|
contractAddress: UDC.ADDRESS,
|
|
5738
5717
|
entrypoint: UDC.ENTRYPOINT,
|
|
@@ -5848,6 +5827,7 @@ export {
|
|
|
5848
5827
|
encode_exports as encode,
|
|
5849
5828
|
fixProto,
|
|
5850
5829
|
fixStack,
|
|
5830
|
+
getCalldata,
|
|
5851
5831
|
getChecksumAddress,
|
|
5852
5832
|
hash_exports as hash,
|
|
5853
5833
|
isUrl,
|
|
@@ -5856,6 +5836,7 @@ export {
|
|
|
5856
5836
|
num_exports as num,
|
|
5857
5837
|
number,
|
|
5858
5838
|
shortString_exports as shortString,
|
|
5839
|
+
splitArgsAndOptions,
|
|
5859
5840
|
stark_exports as stark,
|
|
5860
5841
|
starknetId_exports as starknetId,
|
|
5861
5842
|
transaction_exports as transaction,
|