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.js
CHANGED
|
@@ -55,6 +55,7 @@ __export(src_exports, {
|
|
|
55
55
|
encode: () => encode_exports,
|
|
56
56
|
fixProto: () => fixProto,
|
|
57
57
|
fixStack: () => fixStack,
|
|
58
|
+
getCalldata: () => getCalldata,
|
|
58
59
|
getChecksumAddress: () => getChecksumAddress,
|
|
59
60
|
hash: () => hash_exports,
|
|
60
61
|
isUrl: () => isUrl,
|
|
@@ -63,6 +64,7 @@ __export(src_exports, {
|
|
|
63
64
|
num: () => num_exports,
|
|
64
65
|
number: () => number,
|
|
65
66
|
shortString: () => shortString_exports,
|
|
67
|
+
splitArgsAndOptions: () => splitArgsAndOptions,
|
|
66
68
|
stark: () => stark_exports,
|
|
67
69
|
starknetId: () => starknetId_exports,
|
|
68
70
|
transaction: () => transaction_exports,
|
|
@@ -112,9 +114,12 @@ var RPC;
|
|
|
112
114
|
})(TransactionType2 = RPC2.TransactionType || (RPC2.TransactionType = {}));
|
|
113
115
|
})(RPC || (RPC = {}));
|
|
114
116
|
|
|
115
|
-
// src/utils/
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
// src/utils/assert.ts
|
|
118
|
+
function assert(condition, message) {
|
|
119
|
+
if (!condition) {
|
|
120
|
+
throw new Error(message || "Assertion failure");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
118
123
|
|
|
119
124
|
// src/utils/hash.ts
|
|
120
125
|
var hash_exports = {};
|
|
@@ -2340,15 +2345,6 @@ __export(num_exports, {
|
|
|
2340
2345
|
toHexString: () => toHexString
|
|
2341
2346
|
});
|
|
2342
2347
|
var import_utils = require("@noble/curves/abstract/utils");
|
|
2343
|
-
|
|
2344
|
-
// src/utils/assert.ts
|
|
2345
|
-
function assert(condition, message) {
|
|
2346
|
-
if (!condition) {
|
|
2347
|
-
throw new Error(message || "Assertion failure");
|
|
2348
|
-
}
|
|
2349
|
-
}
|
|
2350
|
-
|
|
2351
|
-
// src/utils/num.ts
|
|
2352
2348
|
function isHex(hex) {
|
|
2353
2349
|
return /^0x[0-9a-f]*$/i.test(hex);
|
|
2354
2350
|
}
|
|
@@ -2548,6 +2544,9 @@ function felt(it) {
|
|
|
2548
2544
|
if (typeof it === "string" && isStringWholeNumber(it)) {
|
|
2549
2545
|
return it;
|
|
2550
2546
|
}
|
|
2547
|
+
if (typeof it === "boolean") {
|
|
2548
|
+
return `${+it}`;
|
|
2549
|
+
}
|
|
2551
2550
|
throw new Error(`${it} can't be computed by felt()`);
|
|
2552
2551
|
}
|
|
2553
2552
|
|
|
@@ -2809,584 +2808,1087 @@ function computeContractClassHash(contract) {
|
|
|
2809
2808
|
return computeLegacyContractClassHash(compiledContract);
|
|
2810
2809
|
}
|
|
2811
2810
|
|
|
2812
|
-
// src/utils/
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
}
|
|
2817
|
-
function extractContractHashes(payload) {
|
|
2818
|
-
const response = { ...payload };
|
|
2819
|
-
if (isSierra(payload.contract)) {
|
|
2820
|
-
if (!payload.compiledClassHash && payload.casm) {
|
|
2821
|
-
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
2822
|
-
}
|
|
2823
|
-
if (!response.compiledClassHash)
|
|
2811
|
+
// src/utils/calldata/formatter.ts
|
|
2812
|
+
var guard = {
|
|
2813
|
+
isBN: (data, type, key) => {
|
|
2814
|
+
if (!isBigInt(data[key]))
|
|
2824
2815
|
throw new Error(
|
|
2825
|
-
|
|
2816
|
+
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
2826
2817
|
);
|
|
2818
|
+
},
|
|
2819
|
+
unknown: (data, type, key) => {
|
|
2820
|
+
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
2827
2821
|
}
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2822
|
+
};
|
|
2823
|
+
function formatter(data, type, sameType) {
|
|
2824
|
+
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
2825
|
+
const elType = sameType ?? type[key];
|
|
2826
|
+
if (!(key in type) && !sameType) {
|
|
2827
|
+
acc[key] = value;
|
|
2828
|
+
return acc;
|
|
2829
|
+
}
|
|
2830
|
+
if (elType === "string") {
|
|
2831
|
+
if (Array.isArray(data[key])) {
|
|
2832
|
+
const arrayStr = formatter(
|
|
2833
|
+
data[key],
|
|
2834
|
+
data[key].map((_) => elType)
|
|
2835
|
+
);
|
|
2836
|
+
acc[key] = Object.values(arrayStr).join("");
|
|
2837
|
+
return acc;
|
|
2838
|
+
}
|
|
2839
|
+
guard.isBN(data, type, key);
|
|
2840
|
+
acc[key] = decodeShortString(value);
|
|
2841
|
+
return acc;
|
|
2842
|
+
}
|
|
2843
|
+
if (elType === "number") {
|
|
2844
|
+
guard.isBN(data, type, key);
|
|
2845
|
+
acc[key] = Number(value);
|
|
2846
|
+
return acc;
|
|
2847
|
+
}
|
|
2848
|
+
if (typeof elType === "function") {
|
|
2849
|
+
acc[key] = elType(value);
|
|
2850
|
+
return acc;
|
|
2851
|
+
}
|
|
2852
|
+
if (Array.isArray(elType)) {
|
|
2853
|
+
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
2854
|
+
acc[key] = Object.values(arrayObj);
|
|
2855
|
+
return acc;
|
|
2856
|
+
}
|
|
2857
|
+
if (typeof elType === "object") {
|
|
2858
|
+
acc[key] = formatter(data[key], elType);
|
|
2859
|
+
return acc;
|
|
2860
|
+
}
|
|
2861
|
+
guard.unknown(data, type, key);
|
|
2862
|
+
return acc;
|
|
2863
|
+
}, {});
|
|
2832
2864
|
}
|
|
2833
2865
|
|
|
2834
|
-
// src/utils/
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
|
|
2840
|
-
formatSignature: () => formatSignature,
|
|
2841
|
-
makeAddress: () => makeAddress,
|
|
2842
|
-
randomAddress: () => randomAddress,
|
|
2843
|
-
signatureToDecimalArray: () => signatureToDecimalArray,
|
|
2844
|
-
signatureToHexArray: () => signatureToHexArray
|
|
2845
|
-
});
|
|
2846
|
-
var import_micro_starknet2 = require("micro-starknet");
|
|
2847
|
-
var import_pako = require("pako");
|
|
2848
|
-
function compressProgram(jsonProgram) {
|
|
2849
|
-
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
2850
|
-
const compressedProgram = (0, import_pako.gzip)(stringified);
|
|
2851
|
-
return btoaUniversal(compressedProgram);
|
|
2852
|
-
}
|
|
2853
|
-
function randomAddress() {
|
|
2854
|
-
const randomKeyPair = import_micro_starknet2.utils.randomPrivateKey();
|
|
2855
|
-
return (0, import_micro_starknet2.getStarkKey)(randomKeyPair);
|
|
2856
|
-
}
|
|
2857
|
-
function makeAddress(input) {
|
|
2858
|
-
return addHexPrefix(input).toLowerCase();
|
|
2866
|
+
// src/utils/calldata/tuple.ts
|
|
2867
|
+
function parseNamedTuple(namedTuple) {
|
|
2868
|
+
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
2869
|
+
const type = namedTuple.substring(name.length + ":".length);
|
|
2870
|
+
return { name, type };
|
|
2859
2871
|
}
|
|
2860
|
-
function
|
|
2861
|
-
if (!
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2872
|
+
function parseSubTuple(s) {
|
|
2873
|
+
if (!s.includes("("))
|
|
2874
|
+
return { subTuple: [], result: s };
|
|
2875
|
+
const subTuple = [];
|
|
2876
|
+
let result = "";
|
|
2877
|
+
let i = 0;
|
|
2878
|
+
while (i < s.length) {
|
|
2879
|
+
if (s[i] === "(") {
|
|
2880
|
+
let counter = 1;
|
|
2881
|
+
const lBracket = i;
|
|
2882
|
+
i++;
|
|
2883
|
+
while (counter) {
|
|
2884
|
+
if (s[i] === ")")
|
|
2885
|
+
counter--;
|
|
2886
|
+
if (s[i] === "(")
|
|
2887
|
+
counter++;
|
|
2888
|
+
i++;
|
|
2889
|
+
}
|
|
2890
|
+
subTuple.push(s.substring(lBracket, i));
|
|
2891
|
+
result += " ";
|
|
2892
|
+
i--;
|
|
2893
|
+
} else {
|
|
2894
|
+
result += s[i];
|
|
2895
|
+
}
|
|
2896
|
+
i++;
|
|
2871
2897
|
}
|
|
2898
|
+
return {
|
|
2899
|
+
subTuple,
|
|
2900
|
+
result
|
|
2901
|
+
};
|
|
2872
2902
|
}
|
|
2873
|
-
function
|
|
2874
|
-
|
|
2875
|
-
}
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
}
|
|
2879
|
-
function compileCalldata(args) {
|
|
2880
|
-
const compiledData = Object.values(args).flatMap((value) => {
|
|
2881
|
-
if (Array.isArray(value))
|
|
2882
|
-
return [toBigInt(value.length).toString(), ...value.map((x) => toBigInt(x).toString())];
|
|
2883
|
-
if (typeof value === "object" && "type" in value)
|
|
2884
|
-
return Object.entries(value).filter(([k]) => k !== "type").map(([, v]) => toBigInt(v).toString());
|
|
2885
|
-
return toBigInt(value).toString();
|
|
2886
|
-
});
|
|
2887
|
-
Object.defineProperty(compiledData, "compiled", {
|
|
2888
|
-
enumerable: false,
|
|
2889
|
-
writable: false,
|
|
2890
|
-
value: true
|
|
2891
|
-
});
|
|
2892
|
-
return compiledData;
|
|
2893
|
-
}
|
|
2894
|
-
function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
|
|
2895
|
-
const overHeadPercent = Math.round((1 + overhead) * 100);
|
|
2896
|
-
return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
|
|
2897
|
-
}
|
|
2898
|
-
|
|
2899
|
-
// src/utils/provider.ts
|
|
2900
|
-
function wait(delay) {
|
|
2901
|
-
return new Promise((res) => {
|
|
2902
|
-
setTimeout(res, delay);
|
|
2903
|
-
});
|
|
2904
|
-
}
|
|
2905
|
-
function parseCalldata(calldata = []) {
|
|
2906
|
-
return calldata.map((data) => {
|
|
2907
|
-
if (typeof data === "string" && isHex(data)) {
|
|
2908
|
-
return data;
|
|
2909
|
-
}
|
|
2910
|
-
return toHex(data);
|
|
2903
|
+
function extractCairo0Tuple(type) {
|
|
2904
|
+
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
2905
|
+
const { subTuple, result } = parseSubTuple(cleanType);
|
|
2906
|
+
let recomposed = result.split(",").map((it) => {
|
|
2907
|
+
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
2911
2908
|
});
|
|
2909
|
+
if (isTypeNamedTuple(type)) {
|
|
2910
|
+
recomposed = recomposed.reduce((acc, it) => {
|
|
2911
|
+
return acc.concat(parseNamedTuple(it));
|
|
2912
|
+
}, []);
|
|
2913
|
+
}
|
|
2914
|
+
return recomposed;
|
|
2912
2915
|
}
|
|
2913
|
-
function
|
|
2914
|
-
const
|
|
2915
|
-
|
|
2916
|
-
result.abi = formatSpaces(stringify2(contract.abi));
|
|
2917
|
-
result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
|
|
2918
|
-
result.sierra_program = compressProgram(result.sierra_program);
|
|
2919
|
-
return result;
|
|
2916
|
+
function extractCairo1Tuple(type) {
|
|
2917
|
+
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
2918
|
+
return cleanType.split(",");
|
|
2920
2919
|
}
|
|
2921
|
-
function
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
return {
|
|
2925
|
-
...parsedContract,
|
|
2926
|
-
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
2927
|
-
};
|
|
2920
|
+
function extractTupleMemberTypes(type) {
|
|
2921
|
+
if (isCairo1Type(type)) {
|
|
2922
|
+
return extractCairo1Tuple(type);
|
|
2928
2923
|
}
|
|
2929
|
-
return
|
|
2924
|
+
return extractCairo0Tuple(type);
|
|
2930
2925
|
}
|
|
2931
2926
|
|
|
2932
|
-
// src/utils/
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
parent_hash: res.parent_hash,
|
|
2941
|
-
status: res.status,
|
|
2942
|
-
transactions: res.transactions
|
|
2943
|
-
};
|
|
2927
|
+
// src/utils/calldata/requestParser.ts
|
|
2928
|
+
function parseBaseTypes(type, val) {
|
|
2929
|
+
switch (true) {
|
|
2930
|
+
case isTypeUint256(type):
|
|
2931
|
+
const el_uint256 = uint256(val);
|
|
2932
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
2933
|
+
default:
|
|
2934
|
+
return felt(val);
|
|
2944
2935
|
}
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
};
|
|
2936
|
+
}
|
|
2937
|
+
function parseTuple(element, typeStr) {
|
|
2938
|
+
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
2939
|
+
const elements = Object.values(element);
|
|
2940
|
+
if (elements.length !== memberTypes.length) {
|
|
2941
|
+
throw Error(
|
|
2942
|
+
`ParseTuple: provided and expected abi tuple size do not match.
|
|
2943
|
+
provided: ${elements}
|
|
2944
|
+
expected: ${memberTypes}`
|
|
2945
|
+
);
|
|
2956
2946
|
}
|
|
2957
|
-
|
|
2947
|
+
return memberTypes.map((it, dx) => {
|
|
2958
2948
|
return {
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
gas_price: toBigInt(res.gas_price)
|
|
2949
|
+
element: elements[dx],
|
|
2950
|
+
type: it.type ?? it
|
|
2962
2951
|
};
|
|
2963
|
-
}
|
|
2964
|
-
parseCallContractResponse(res) {
|
|
2965
|
-
return {
|
|
2966
|
-
result: res
|
|
2967
|
-
};
|
|
2968
|
-
}
|
|
2969
|
-
};
|
|
2970
|
-
|
|
2971
|
-
// src/provider/errors.ts
|
|
2972
|
-
function fixStack(target, fn = target.constructor) {
|
|
2973
|
-
const { captureStackTrace } = Error;
|
|
2974
|
-
captureStackTrace && captureStackTrace(target, fn);
|
|
2975
|
-
}
|
|
2976
|
-
function fixProto(target, prototype) {
|
|
2977
|
-
const { setPrototypeOf } = Object;
|
|
2978
|
-
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
2952
|
+
});
|
|
2979
2953
|
}
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
Object.defineProperty(this, "name", {
|
|
2984
|
-
value: new.target.name,
|
|
2985
|
-
enumerable: false,
|
|
2986
|
-
configurable: true
|
|
2987
|
-
});
|
|
2988
|
-
fixProto(this, new.target.prototype);
|
|
2989
|
-
fixStack(this);
|
|
2954
|
+
function parseCalldataValue(element, type, structs) {
|
|
2955
|
+
if (element === void 0) {
|
|
2956
|
+
throw Error(`Missing parameter for type ${type}`);
|
|
2990
2957
|
}
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
};
|
|
2994
|
-
var GatewayError = class extends LibraryError {
|
|
2995
|
-
constructor(message, errorCode) {
|
|
2996
|
-
super(message);
|
|
2997
|
-
this.errorCode = errorCode;
|
|
2958
|
+
if (Array.isArray(element)) {
|
|
2959
|
+
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
2998
2960
|
}
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
2961
|
+
if (structs[type] && structs[type].members.length) {
|
|
2962
|
+
const { members } = structs[type];
|
|
2963
|
+
const subElement = element;
|
|
2964
|
+
return members.reduce((acc, it) => {
|
|
2965
|
+
return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs));
|
|
2966
|
+
}, []);
|
|
3004
2967
|
}
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
getStarknetIdContract: () => getStarknetIdContract,
|
|
3012
|
-
useDecoded: () => useDecoded,
|
|
3013
|
-
useEncoded: () => useEncoded
|
|
3014
|
-
});
|
|
3015
|
-
var basicAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
|
3016
|
-
var basicSizePlusOne = BigInt(basicAlphabet.length + 1);
|
|
3017
|
-
var bigAlphabet = "\u8FD9\u6765";
|
|
3018
|
-
var basicAlphabetSize = BigInt(basicAlphabet.length);
|
|
3019
|
-
var bigAlphabetSize = BigInt(bigAlphabet.length);
|
|
3020
|
-
var bigAlphabetSizePlusOne = BigInt(bigAlphabet.length + 1);
|
|
3021
|
-
function extractStars(str) {
|
|
3022
|
-
let k = 0;
|
|
3023
|
-
while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
|
|
3024
|
-
str = str.substring(0, str.length - 1);
|
|
3025
|
-
k += 1;
|
|
2968
|
+
if (isTypeTuple(type)) {
|
|
2969
|
+
const tupled = parseTuple(element, type);
|
|
2970
|
+
return tupled.reduce((acc, it) => {
|
|
2971
|
+
const parsedData = parseCalldataValue(it.element, it.type, structs);
|
|
2972
|
+
return acc.concat(parsedData);
|
|
2973
|
+
}, []);
|
|
3026
2974
|
}
|
|
3027
|
-
|
|
2975
|
+
if (typeof element === "object") {
|
|
2976
|
+
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
2977
|
+
}
|
|
2978
|
+
return parseBaseTypes(type, element);
|
|
3028
2979
|
}
|
|
3029
|
-
function
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
2980
|
+
function parseCalldataField(argsIterator, input, structs) {
|
|
2981
|
+
const { name, type } = input;
|
|
2982
|
+
let { value } = argsIterator.next();
|
|
2983
|
+
switch (true) {
|
|
2984
|
+
case isTypeArray(type):
|
|
2985
|
+
if (!Array.isArray(value) && !isText(value)) {
|
|
2986
|
+
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
2987
|
+
}
|
|
2988
|
+
if (typeof value === "string") {
|
|
2989
|
+
value = splitLongString(value);
|
|
2990
|
+
}
|
|
2991
|
+
const result = [];
|
|
2992
|
+
result.push(felt(value.length));
|
|
2993
|
+
const arrayType = getArrayType(input.type);
|
|
2994
|
+
return value.reduce((acc, el) => {
|
|
2995
|
+
if (isTypeStruct(arrayType, structs) || isTypeTuple(arrayType) || isTypeArray(arrayType)) {
|
|
2996
|
+
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
3044
2997
|
} else {
|
|
3045
|
-
|
|
3046
|
-
decoded += bigAlphabet[Number(code2)];
|
|
3047
|
-
subdomain /= bigAlphabetSize;
|
|
2998
|
+
return acc.concat(parseBaseTypes(arrayType, el));
|
|
3048
2999
|
}
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
decoded += ".";
|
|
3056
|
-
});
|
|
3057
|
-
if (!decoded) {
|
|
3058
|
-
return decoded;
|
|
3000
|
+
return acc;
|
|
3001
|
+
}, result);
|
|
3002
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type)):
|
|
3003
|
+
return parseCalldataValue(value, type, structs);
|
|
3004
|
+
default:
|
|
3005
|
+
return parseBaseTypes(type, value);
|
|
3059
3006
|
}
|
|
3060
|
-
return decoded.concat("stark");
|
|
3061
3007
|
}
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3008
|
+
|
|
3009
|
+
// src/utils/calldata/responseParser.ts
|
|
3010
|
+
function parseBaseTypes2(type, it) {
|
|
3011
|
+
let temp;
|
|
3012
|
+
switch (true) {
|
|
3013
|
+
case isTypeBool(type):
|
|
3014
|
+
temp = it.next().value;
|
|
3015
|
+
return Boolean(BigInt(temp));
|
|
3016
|
+
case isTypeUint256(type):
|
|
3017
|
+
const low = it.next().value;
|
|
3018
|
+
const high = it.next().value;
|
|
3019
|
+
return uint256ToBN({ low, high });
|
|
3020
|
+
default:
|
|
3021
|
+
temp = it.next().value;
|
|
3022
|
+
return BigInt(temp);
|
|
3072
3023
|
}
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
multiplier *= basicSizePlusOne;
|
|
3081
|
-
multiplier *= basicSizePlusOne;
|
|
3082
|
-
} else {
|
|
3083
|
-
encoded += multiplier * bnIndex;
|
|
3084
|
-
multiplier *= basicSizePlusOne;
|
|
3085
|
-
}
|
|
3086
|
-
} else if (bigAlphabet.indexOf(char) !== -1) {
|
|
3087
|
-
encoded += multiplier * basicAlphabetSize;
|
|
3088
|
-
multiplier *= basicSizePlusOne;
|
|
3089
|
-
const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
|
|
3090
|
-
encoded += multiplier * BigInt(newid);
|
|
3091
|
-
multiplier *= bigAlphabetSize;
|
|
3092
|
-
}
|
|
3024
|
+
}
|
|
3025
|
+
function parseResponseStruct(responseIterator, type, structs) {
|
|
3026
|
+
if (type in structs && structs[type]) {
|
|
3027
|
+
return structs[type].members.reduce((acc, el) => {
|
|
3028
|
+
acc[el.name] = parseResponseStruct(responseIterator, el.type, structs);
|
|
3029
|
+
return acc;
|
|
3030
|
+
}, {});
|
|
3093
3031
|
}
|
|
3094
|
-
|
|
3032
|
+
if (isTypeTuple(type)) {
|
|
3033
|
+
const memberTypes = extractTupleMemberTypes(type);
|
|
3034
|
+
return memberTypes.reduce((acc, it, idx) => {
|
|
3035
|
+
const tName = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
3036
|
+
const tType = (it == null ? void 0 : it.type) ? it.type : it;
|
|
3037
|
+
acc[tName] = parseResponseStruct(responseIterator, tType, structs);
|
|
3038
|
+
return acc;
|
|
3039
|
+
}, {});
|
|
3040
|
+
}
|
|
3041
|
+
return parseBaseTypes2(type, responseIterator);
|
|
3095
3042
|
}
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
case
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3043
|
+
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
3044
|
+
const { name, type } = output;
|
|
3045
|
+
let temp;
|
|
3046
|
+
switch (true) {
|
|
3047
|
+
case isLen(name):
|
|
3048
|
+
temp = responseIterator.next().value;
|
|
3049
|
+
return BigInt(temp);
|
|
3050
|
+
case isTypeArray(type):
|
|
3051
|
+
const parsedDataArr = [];
|
|
3052
|
+
if (isCairo1Type(type)) {
|
|
3053
|
+
const arrayType = getArrayType(type);
|
|
3054
|
+
const len = BigInt(responseIterator.next().value);
|
|
3055
|
+
while (parsedDataArr.length < len) {
|
|
3056
|
+
parsedDataArr.push(parseResponseStruct(responseIterator, arrayType, structs));
|
|
3057
|
+
}
|
|
3058
|
+
return parsedDataArr;
|
|
3059
|
+
}
|
|
3060
|
+
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
3061
|
+
const arrLen = parsedResult[`${name}_len`];
|
|
3062
|
+
while (parsedDataArr.length < arrLen) {
|
|
3063
|
+
parsedDataArr.push(
|
|
3064
|
+
parseResponseStruct(responseIterator, output.type.replace("*", ""), structs)
|
|
3065
|
+
);
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
return parsedDataArr;
|
|
3069
|
+
case (type in structs || isTypeTuple(type)):
|
|
3070
|
+
return parseResponseStruct(responseIterator, type, structs);
|
|
3107
3071
|
default:
|
|
3108
|
-
|
|
3072
|
+
return parseBaseTypes2(type, responseIterator);
|
|
3109
3073
|
}
|
|
3110
3074
|
}
|
|
3111
3075
|
|
|
3112
|
-
// src/
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
const stringDomain = useDecoded(decimalDomain);
|
|
3126
|
-
if (!stringDomain) {
|
|
3127
|
-
throw Error("Starkname not found");
|
|
3128
|
-
}
|
|
3129
|
-
return stringDomain;
|
|
3130
|
-
} catch (e) {
|
|
3131
|
-
if (e instanceof Error && e.message === "Starkname not found") {
|
|
3132
|
-
throw e;
|
|
3133
|
-
}
|
|
3134
|
-
throw Error("Could not get stark name");
|
|
3076
|
+
// src/utils/calldata/validate.ts
|
|
3077
|
+
var validateFelt = (parameter, input) => {
|
|
3078
|
+
assert(
|
|
3079
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
3080
|
+
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
3081
|
+
);
|
|
3082
|
+
};
|
|
3083
|
+
var validateUint = (parameter, input) => {
|
|
3084
|
+
if (typeof parameter === "number") {
|
|
3085
|
+
assert(
|
|
3086
|
+
parameter <= Number.MAX_SAFE_INTEGER,
|
|
3087
|
+
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
3088
|
+
);
|
|
3135
3089
|
}
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3090
|
+
assert(
|
|
3091
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
3092
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
|
|
3093
|
+
);
|
|
3094
|
+
const param = toBigInt(parameter);
|
|
3095
|
+
switch (input.type) {
|
|
3096
|
+
case "core::integer::u8" /* u8 */:
|
|
3097
|
+
assert(
|
|
3098
|
+
param >= 0n && param <= 255n,
|
|
3099
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
3100
|
+
);
|
|
3101
|
+
break;
|
|
3102
|
+
case "core::integer::u16" /* u16 */:
|
|
3103
|
+
assert(
|
|
3104
|
+
param >= 0n && param <= 65535n,
|
|
3105
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
3106
|
+
);
|
|
3107
|
+
break;
|
|
3108
|
+
case "core::integer::u32" /* u32 */:
|
|
3109
|
+
assert(
|
|
3110
|
+
param >= 0n && param <= 4294967295n,
|
|
3111
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
3112
|
+
);
|
|
3113
|
+
break;
|
|
3114
|
+
case "core::integer::u64" /* u64 */:
|
|
3115
|
+
assert(
|
|
3116
|
+
param >= 0n && param <= 2n ** 64n - 1n,
|
|
3117
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
3118
|
+
);
|
|
3119
|
+
break;
|
|
3120
|
+
case "core::integer::u128" /* u128 */:
|
|
3121
|
+
assert(
|
|
3122
|
+
param >= 0n && param <= 2n ** 128n - 1n,
|
|
3123
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
3124
|
+
);
|
|
3125
|
+
break;
|
|
3126
|
+
case "core::integer::u256" /* u256 */:
|
|
3127
|
+
assert(
|
|
3128
|
+
param >= 0n && param <= 2n ** 256n - 1n,
|
|
3129
|
+
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
3130
|
+
);
|
|
3131
|
+
break;
|
|
3132
|
+
default:
|
|
3133
|
+
break;
|
|
3151
3134
|
}
|
|
3152
|
-
}
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3135
|
+
};
|
|
3136
|
+
var validateBool = (parameter, input) => {
|
|
3137
|
+
assert(
|
|
3138
|
+
typeof parameter === "boolean",
|
|
3139
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
3140
|
+
);
|
|
3141
|
+
};
|
|
3142
|
+
var validateStruct = (parameter, input, structs) => {
|
|
3143
|
+
assert(
|
|
3144
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
3145
|
+
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
3146
|
+
);
|
|
3147
|
+
structs[input.type].members.forEach(({ name }) => {
|
|
3148
|
+
assert(
|
|
3149
|
+
Object.keys(parameter).includes(name),
|
|
3150
|
+
`Validate: arg ${input.name} should have a property ${name}`
|
|
3151
|
+
);
|
|
3152
|
+
});
|
|
3153
|
+
};
|
|
3154
|
+
var validateTuple = (parameter, input) => {
|
|
3155
|
+
assert(
|
|
3156
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
3157
|
+
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
3158
|
+
);
|
|
3159
|
+
};
|
|
3160
|
+
var validateArray = (parameter, input, structs) => {
|
|
3161
|
+
const baseType = getArrayType(input.type);
|
|
3162
|
+
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
3163
|
+
return;
|
|
3164
|
+
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
3165
|
+
switch (true) {
|
|
3166
|
+
case isTypeFelt(baseType):
|
|
3167
|
+
parameter.forEach((param) => validateFelt(param, input));
|
|
3168
|
+
break;
|
|
3169
|
+
case isTypeTuple(baseType):
|
|
3170
|
+
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
3171
|
+
break;
|
|
3172
|
+
case isTypeStruct(baseType, structs):
|
|
3173
|
+
parameter.forEach(
|
|
3174
|
+
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
3175
|
+
);
|
|
3176
|
+
break;
|
|
3177
|
+
case isTypeUint(baseType):
|
|
3178
|
+
parameter.forEach((param) => validateUint(param, input));
|
|
3179
|
+
break;
|
|
3180
|
+
case isTypeBool(baseType):
|
|
3181
|
+
parameter.forEach((param) => validateBool(param, input));
|
|
3182
|
+
break;
|
|
3183
|
+
default:
|
|
3184
|
+
throw new Error(
|
|
3185
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
3186
|
+
);
|
|
3164
3187
|
}
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3188
|
+
};
|
|
3189
|
+
function validateFields(abiMethod, args, structs) {
|
|
3190
|
+
abiMethod.inputs.reduce((acc, input) => {
|
|
3191
|
+
const parameter = args[acc];
|
|
3192
|
+
switch (true) {
|
|
3193
|
+
case isLen(input.name):
|
|
3194
|
+
return acc;
|
|
3195
|
+
case isTypeFelt(input.type):
|
|
3196
|
+
validateFelt(parameter, input);
|
|
3197
|
+
break;
|
|
3198
|
+
case isTypeUint(input.type):
|
|
3199
|
+
validateUint(parameter, input);
|
|
3200
|
+
break;
|
|
3201
|
+
case isTypeBool(input.type):
|
|
3202
|
+
validateBool(parameter, input);
|
|
3203
|
+
break;
|
|
3204
|
+
case isTypeContractAddress(input.type):
|
|
3205
|
+
break;
|
|
3206
|
+
case isTypeStruct(input.type, structs):
|
|
3207
|
+
validateStruct(parameter, input, structs);
|
|
3208
|
+
break;
|
|
3209
|
+
case isTypeTuple(input.type):
|
|
3210
|
+
validateTuple(parameter, input);
|
|
3211
|
+
break;
|
|
3212
|
+
case isTypeArray(input.type):
|
|
3213
|
+
validateArray(parameter, input, structs);
|
|
3214
|
+
break;
|
|
3215
|
+
default:
|
|
3216
|
+
throw new Error(
|
|
3217
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
3218
|
+
);
|
|
3176
3219
|
}
|
|
3220
|
+
return acc + 1;
|
|
3221
|
+
}, 0);
|
|
3222
|
+
}
|
|
3223
|
+
|
|
3224
|
+
// src/utils/calldata/index.ts
|
|
3225
|
+
var CallData = class {
|
|
3226
|
+
constructor(abi) {
|
|
3227
|
+
this.abi = abi;
|
|
3228
|
+
this.structs = CallData.getAbiStruct(abi);
|
|
3177
3229
|
}
|
|
3178
|
-
|
|
3179
|
-
if (
|
|
3180
|
-
|
|
3230
|
+
validate(type, method, args = []) {
|
|
3231
|
+
if (type !== "DEPLOY") {
|
|
3232
|
+
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
3233
|
+
if (abi.type !== "function")
|
|
3234
|
+
return false;
|
|
3235
|
+
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
3236
|
+
return type === "INVOKE" ? !isView : isView;
|
|
3237
|
+
}).map((abi) => abi.name);
|
|
3238
|
+
assert(
|
|
3239
|
+
invocableFunctionNames.includes(method),
|
|
3240
|
+
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
3241
|
+
);
|
|
3181
3242
|
}
|
|
3182
|
-
|
|
3183
|
-
|
|
3243
|
+
const abiMethod = this.abi.find(
|
|
3244
|
+
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
3245
|
+
);
|
|
3246
|
+
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
3247
|
+
if (args.length !== inputsLength) {
|
|
3248
|
+
throw Error(
|
|
3249
|
+
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
3250
|
+
);
|
|
3184
3251
|
}
|
|
3185
|
-
|
|
3252
|
+
validateFields(abiMethod, args, this.structs);
|
|
3186
3253
|
}
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3254
|
+
compile(method, args) {
|
|
3255
|
+
const argsIterator = args[Symbol.iterator]();
|
|
3256
|
+
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
3257
|
+
return inputs.reduce(
|
|
3258
|
+
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
3259
|
+
[]
|
|
3260
|
+
);
|
|
3261
|
+
}
|
|
3262
|
+
static compile(rawArgs) {
|
|
3263
|
+
const createTree = (obj) => {
|
|
3264
|
+
const getEntries = (o, prefix = "") => {
|
|
3265
|
+
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
3266
|
+
return Object.entries(oe).flatMap(([k, v]) => {
|
|
3267
|
+
let value = v;
|
|
3268
|
+
if (isLongText(value))
|
|
3269
|
+
value = splitLongString(value);
|
|
3270
|
+
if (k === "entrypoint")
|
|
3271
|
+
value = getSelectorFromName(value);
|
|
3272
|
+
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
3273
|
+
if (isBigInt(value))
|
|
3274
|
+
return [[`${prefix}${kk}`, felt(value)]];
|
|
3275
|
+
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
3276
|
+
});
|
|
3277
|
+
};
|
|
3278
|
+
return Object.fromEntries(getEntries(obj));
|
|
3279
|
+
};
|
|
3280
|
+
let callTreeArray;
|
|
3281
|
+
if (!Array.isArray(rawArgs)) {
|
|
3282
|
+
const callTree = createTree(rawArgs);
|
|
3283
|
+
callTreeArray = Object.values(callTree);
|
|
3284
|
+
} else {
|
|
3285
|
+
const callObj = { ...rawArgs };
|
|
3286
|
+
const callTree = createTree(callObj);
|
|
3287
|
+
callTreeArray = Object.values(callTree);
|
|
3193
3288
|
}
|
|
3194
|
-
|
|
3289
|
+
Object.defineProperty(callTreeArray, "__compiled__", {
|
|
3290
|
+
enumerable: false,
|
|
3291
|
+
writable: false,
|
|
3292
|
+
value: true
|
|
3293
|
+
});
|
|
3294
|
+
return callTreeArray;
|
|
3195
3295
|
}
|
|
3196
|
-
|
|
3197
|
-
this.
|
|
3296
|
+
parse(method, response) {
|
|
3297
|
+
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
3298
|
+
const responseIterator = response.flat()[Symbol.iterator]();
|
|
3299
|
+
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
3300
|
+
const propName = output.name ?? idx;
|
|
3301
|
+
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
3302
|
+
if (acc[propName] && acc[`${propName}_len`]) {
|
|
3303
|
+
delete acc[`${propName}_len`];
|
|
3304
|
+
}
|
|
3305
|
+
return acc;
|
|
3306
|
+
}, {});
|
|
3307
|
+
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
3198
3308
|
}
|
|
3199
|
-
|
|
3200
|
-
|
|
3309
|
+
format(method, response, format) {
|
|
3310
|
+
const parsed = this.parse(method, response);
|
|
3311
|
+
return formatter(parsed, format);
|
|
3201
3312
|
}
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
// src/provider/rpc.ts
|
|
3205
|
-
var defaultOptions = {
|
|
3206
|
-
headers: { "Content-Type": "application/json" },
|
|
3207
|
-
blockIdentifier: "latest",
|
|
3208
|
-
retries: 200
|
|
3209
|
-
};
|
|
3210
|
-
var RpcProvider = class {
|
|
3211
|
-
constructor(optionsOrProvider) {
|
|
3212
|
-
this.responseParser = new RPCResponseParser();
|
|
3213
|
-
const { nodeUrl, retries, headers, blockIdentifier } = optionsOrProvider;
|
|
3214
|
-
this.nodeUrl = nodeUrl;
|
|
3215
|
-
this.retries = retries || defaultOptions.retries;
|
|
3216
|
-
this.headers = { ...defaultOptions.headers, ...headers };
|
|
3217
|
-
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
|
|
3218
|
-
this.getChainId();
|
|
3219
|
-
}
|
|
3220
|
-
fetch(method, params) {
|
|
3221
|
-
return fetchPonyfill_default(this.nodeUrl, {
|
|
3222
|
-
method: "POST",
|
|
3223
|
-
body: stringify2({ method, jsonrpc: "2.0", params, id: 0 }),
|
|
3224
|
-
headers: this.headers
|
|
3225
|
-
});
|
|
3226
|
-
}
|
|
3227
|
-
errorHandler(error) {
|
|
3228
|
-
if (error) {
|
|
3229
|
-
const { code, message } = error;
|
|
3230
|
-
throw new LibraryError(`${code}: ${message}`);
|
|
3231
|
-
}
|
|
3313
|
+
static abiInputsLength(inputs) {
|
|
3314
|
+
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3232
3315
|
}
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
this.errorHandler((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data);
|
|
3242
|
-
throw error;
|
|
3243
|
-
}
|
|
3316
|
+
static getAbiStruct(abi) {
|
|
3317
|
+
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
3318
|
+
(acc, abiEntry) => ({
|
|
3319
|
+
...acc,
|
|
3320
|
+
[abiEntry.name]: abiEntry
|
|
3321
|
+
}),
|
|
3322
|
+
{}
|
|
3323
|
+
);
|
|
3244
3324
|
}
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
return this.chainId;
|
|
3325
|
+
static toCalldata(rawCalldata = []) {
|
|
3326
|
+
return CallData.compile(rawCalldata);
|
|
3248
3327
|
}
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
);
|
|
3328
|
+
static toHex(rawCalldata = []) {
|
|
3329
|
+
const calldata = CallData.compile(rawCalldata);
|
|
3330
|
+
return calldata.map((it) => toHex(it));
|
|
3253
3331
|
}
|
|
3254
|
-
|
|
3255
|
-
|
|
3332
|
+
};
|
|
3333
|
+
|
|
3334
|
+
// src/utils/fetchPonyfill.ts
|
|
3335
|
+
var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
|
|
3336
|
+
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || import_isomorphic_fetch.default;
|
|
3337
|
+
|
|
3338
|
+
// src/utils/contract.ts
|
|
3339
|
+
function isSierra(contract) {
|
|
3340
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3341
|
+
return "sierra_program" in compiledContract;
|
|
3342
|
+
}
|
|
3343
|
+
function extractContractHashes(payload) {
|
|
3344
|
+
const response = { ...payload };
|
|
3345
|
+
if (isSierra(payload.contract)) {
|
|
3346
|
+
if (!payload.compiledClassHash && payload.casm) {
|
|
3347
|
+
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
3348
|
+
}
|
|
3349
|
+
if (!response.compiledClassHash)
|
|
3350
|
+
throw new Error(
|
|
3351
|
+
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
3352
|
+
);
|
|
3256
3353
|
}
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3354
|
+
response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
|
|
3355
|
+
if (!response.classHash)
|
|
3356
|
+
throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
3357
|
+
return response;
|
|
3358
|
+
}
|
|
3359
|
+
|
|
3360
|
+
// src/utils/stark.ts
|
|
3361
|
+
var stark_exports = {};
|
|
3362
|
+
__export(stark_exports, {
|
|
3363
|
+
compressProgram: () => compressProgram,
|
|
3364
|
+
estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
|
|
3365
|
+
formatSignature: () => formatSignature,
|
|
3366
|
+
makeAddress: () => makeAddress,
|
|
3367
|
+
randomAddress: () => randomAddress,
|
|
3368
|
+
signatureToDecimalArray: () => signatureToDecimalArray,
|
|
3369
|
+
signatureToHexArray: () => signatureToHexArray
|
|
3370
|
+
});
|
|
3371
|
+
var import_micro_starknet2 = require("micro-starknet");
|
|
3372
|
+
var import_pako = require("pako");
|
|
3373
|
+
function compressProgram(jsonProgram) {
|
|
3374
|
+
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
3375
|
+
const compressedProgram = (0, import_pako.gzip)(stringified);
|
|
3376
|
+
return btoaUniversal(compressedProgram);
|
|
3377
|
+
}
|
|
3378
|
+
function randomAddress() {
|
|
3379
|
+
const randomKeyPair = import_micro_starknet2.utils.randomPrivateKey();
|
|
3380
|
+
return (0, import_micro_starknet2.getStarkKey)(randomKeyPair);
|
|
3381
|
+
}
|
|
3382
|
+
function makeAddress(input) {
|
|
3383
|
+
return addHexPrefix(input).toLowerCase();
|
|
3384
|
+
}
|
|
3385
|
+
function formatSignature(sig) {
|
|
3386
|
+
if (!sig)
|
|
3387
|
+
throw Error("formatSignature: provided signature is undefined");
|
|
3388
|
+
if (Array.isArray(sig)) {
|
|
3389
|
+
return sig.map((it) => toHex(it));
|
|
3260
3390
|
}
|
|
3261
|
-
|
|
3262
|
-
const
|
|
3263
|
-
return
|
|
3391
|
+
try {
|
|
3392
|
+
const { r, s } = sig;
|
|
3393
|
+
return [toHex(r), toHex(s)];
|
|
3394
|
+
} catch (e) {
|
|
3395
|
+
throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
|
|
3264
3396
|
}
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3397
|
+
}
|
|
3398
|
+
function signatureToDecimalArray(sig) {
|
|
3399
|
+
return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
|
|
3400
|
+
}
|
|
3401
|
+
function signatureToHexArray(sig) {
|
|
3402
|
+
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
3403
|
+
}
|
|
3404
|
+
function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
|
|
3405
|
+
const overHeadPercent = Math.round((1 + overhead) * 100);
|
|
3406
|
+
return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3409
|
+
// src/utils/provider.ts
|
|
3410
|
+
function wait(delay) {
|
|
3411
|
+
return new Promise((res) => {
|
|
3412
|
+
setTimeout(res, delay);
|
|
3413
|
+
});
|
|
3414
|
+
}
|
|
3415
|
+
function createSierraContractClass(contract) {
|
|
3416
|
+
const result = { ...contract };
|
|
3417
|
+
delete result.sierra_program_debug_info;
|
|
3418
|
+
result.abi = formatSpaces(stringify2(contract.abi));
|
|
3419
|
+
result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
|
|
3420
|
+
result.sierra_program = compressProgram(result.sierra_program);
|
|
3421
|
+
return result;
|
|
3422
|
+
}
|
|
3423
|
+
function parseContract(contract) {
|
|
3424
|
+
const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3425
|
+
if (!isSierra(contract)) {
|
|
3426
|
+
return {
|
|
3427
|
+
...parsedContract,
|
|
3428
|
+
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
3429
|
+
};
|
|
3271
3430
|
}
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3431
|
+
return createSierraContractClass(parsedContract);
|
|
3432
|
+
}
|
|
3433
|
+
|
|
3434
|
+
// src/utils/responseParser/rpc.ts
|
|
3435
|
+
var RPCResponseParser = class {
|
|
3436
|
+
parseGetBlockResponse(res) {
|
|
3437
|
+
return {
|
|
3438
|
+
timestamp: res.timestamp,
|
|
3439
|
+
block_hash: res.block_hash,
|
|
3440
|
+
block_number: res.block_number,
|
|
3441
|
+
new_root: res.new_root,
|
|
3442
|
+
parent_hash: res.parent_hash,
|
|
3443
|
+
status: res.status,
|
|
3444
|
+
transactions: res.transactions
|
|
3445
|
+
};
|
|
3278
3446
|
}
|
|
3279
|
-
|
|
3280
|
-
return
|
|
3447
|
+
parseGetTransactionResponse(res) {
|
|
3448
|
+
return {
|
|
3449
|
+
calldata: res.calldata || [],
|
|
3450
|
+
contract_address: res.contract_address,
|
|
3451
|
+
sender_address: res.contract_address,
|
|
3452
|
+
max_fee: res.max_fee,
|
|
3453
|
+
nonce: res.nonce,
|
|
3454
|
+
signature: res.signature || [],
|
|
3455
|
+
transaction_hash: res.transaction_hash,
|
|
3456
|
+
version: res.version
|
|
3457
|
+
};
|
|
3281
3458
|
}
|
|
3282
|
-
|
|
3283
|
-
|
|
3459
|
+
parseFeeEstimateResponse(res) {
|
|
3460
|
+
return {
|
|
3461
|
+
overall_fee: toBigInt(res.overall_fee),
|
|
3462
|
+
gas_consumed: toBigInt(res.gas_consumed),
|
|
3463
|
+
gas_price: toBigInt(res.gas_price)
|
|
3464
|
+
};
|
|
3284
3465
|
}
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3466
|
+
parseCallContractResponse(res) {
|
|
3467
|
+
return {
|
|
3468
|
+
result: res
|
|
3469
|
+
};
|
|
3288
3470
|
}
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3471
|
+
};
|
|
3472
|
+
|
|
3473
|
+
// src/provider/errors.ts
|
|
3474
|
+
function fixStack(target, fn = target.constructor) {
|
|
3475
|
+
const { captureStackTrace } = Error;
|
|
3476
|
+
captureStackTrace && captureStackTrace(target, fn);
|
|
3477
|
+
}
|
|
3478
|
+
function fixProto(target, prototype) {
|
|
3479
|
+
const { setPrototypeOf } = Object;
|
|
3480
|
+
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
3481
|
+
}
|
|
3482
|
+
var CustomError = class extends Error {
|
|
3483
|
+
constructor(message) {
|
|
3484
|
+
super(message);
|
|
3485
|
+
Object.defineProperty(this, "name", {
|
|
3486
|
+
value: new.target.name,
|
|
3487
|
+
enumerable: false,
|
|
3488
|
+
configurable: true
|
|
3296
3489
|
});
|
|
3490
|
+
fixProto(this, new.target.prototype);
|
|
3491
|
+
fixStack(this);
|
|
3297
3492
|
}
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3493
|
+
};
|
|
3494
|
+
var LibraryError = class extends CustomError {
|
|
3495
|
+
};
|
|
3496
|
+
var GatewayError = class extends LibraryError {
|
|
3497
|
+
constructor(message, errorCode) {
|
|
3498
|
+
super(message);
|
|
3499
|
+
this.errorCode = errorCode;
|
|
3303
3500
|
}
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3501
|
+
};
|
|
3502
|
+
var HttpError = class extends LibraryError {
|
|
3503
|
+
constructor(message, errorCode) {
|
|
3504
|
+
super(message);
|
|
3505
|
+
this.errorCode = errorCode;
|
|
3307
3506
|
}
|
|
3308
|
-
|
|
3309
|
-
|
|
3507
|
+
};
|
|
3508
|
+
|
|
3509
|
+
// src/utils/starknetId.ts
|
|
3510
|
+
var starknetId_exports = {};
|
|
3511
|
+
__export(starknetId_exports, {
|
|
3512
|
+
StarknetIdContract: () => StarknetIdContract,
|
|
3513
|
+
getStarknetIdContract: () => getStarknetIdContract,
|
|
3514
|
+
useDecoded: () => useDecoded,
|
|
3515
|
+
useEncoded: () => useEncoded
|
|
3516
|
+
});
|
|
3517
|
+
var basicAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
|
3518
|
+
var basicSizePlusOne = BigInt(basicAlphabet.length + 1);
|
|
3519
|
+
var bigAlphabet = "\u8FD9\u6765";
|
|
3520
|
+
var basicAlphabetSize = BigInt(basicAlphabet.length);
|
|
3521
|
+
var bigAlphabetSize = BigInt(bigAlphabet.length);
|
|
3522
|
+
var bigAlphabetSizePlusOne = BigInt(bigAlphabet.length + 1);
|
|
3523
|
+
function extractStars(str) {
|
|
3524
|
+
let k = 0;
|
|
3525
|
+
while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
|
|
3526
|
+
str = str.substring(0, str.length - 1);
|
|
3527
|
+
k += 1;
|
|
3310
3528
|
}
|
|
3311
|
-
|
|
3312
|
-
|
|
3529
|
+
return [str, k];
|
|
3530
|
+
}
|
|
3531
|
+
function useDecoded(encoded) {
|
|
3532
|
+
let decoded = "";
|
|
3533
|
+
encoded.forEach((subdomain) => {
|
|
3534
|
+
while (subdomain !== ZERO) {
|
|
3535
|
+
const code = subdomain % basicSizePlusOne;
|
|
3536
|
+
subdomain /= basicSizePlusOne;
|
|
3537
|
+
if (code === BigInt(basicAlphabet.length)) {
|
|
3538
|
+
const nextSubdomain = subdomain / bigAlphabetSizePlusOne;
|
|
3539
|
+
if (nextSubdomain === ZERO) {
|
|
3540
|
+
const code2 = subdomain % bigAlphabetSizePlusOne;
|
|
3541
|
+
subdomain = nextSubdomain;
|
|
3542
|
+
if (code2 === ZERO)
|
|
3543
|
+
decoded += basicAlphabet[0];
|
|
3544
|
+
else
|
|
3545
|
+
decoded += bigAlphabet[Number(code2) - 1];
|
|
3546
|
+
} else {
|
|
3547
|
+
const code2 = subdomain % bigAlphabetSize;
|
|
3548
|
+
decoded += bigAlphabet[Number(code2)];
|
|
3549
|
+
subdomain /= bigAlphabetSize;
|
|
3550
|
+
}
|
|
3551
|
+
} else
|
|
3552
|
+
decoded += basicAlphabet[Number(code)];
|
|
3553
|
+
}
|
|
3554
|
+
const [str, k] = extractStars(decoded);
|
|
3555
|
+
if (k)
|
|
3556
|
+
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));
|
|
3557
|
+
decoded += ".";
|
|
3558
|
+
});
|
|
3559
|
+
if (!decoded) {
|
|
3560
|
+
return decoded;
|
|
3313
3561
|
}
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3562
|
+
return decoded.concat("stark");
|
|
3563
|
+
}
|
|
3564
|
+
function useEncoded(decoded) {
|
|
3565
|
+
let encoded = BigInt(0);
|
|
3566
|
+
let multiplier = BigInt(1);
|
|
3567
|
+
if (decoded.endsWith(bigAlphabet[0] + basicAlphabet[1])) {
|
|
3568
|
+
const [str, k] = extractStars(decoded.substring(0, decoded.length - 2));
|
|
3569
|
+
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
|
|
3570
|
+
} else {
|
|
3571
|
+
const [str, k] = extractStars(decoded);
|
|
3572
|
+
if (k)
|
|
3573
|
+
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
|
|
3317
3574
|
}
|
|
3318
|
-
|
|
3319
|
-
const
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3575
|
+
for (let i = 0; i < decoded.length; i += 1) {
|
|
3576
|
+
const char = decoded[i];
|
|
3577
|
+
const index = basicAlphabet.indexOf(char);
|
|
3578
|
+
const bnIndex = BigInt(basicAlphabet.indexOf(char));
|
|
3579
|
+
if (index !== -1) {
|
|
3580
|
+
if (i === decoded.length - 1 && decoded[i] === basicAlphabet[0]) {
|
|
3581
|
+
encoded += multiplier * basicAlphabetSize;
|
|
3582
|
+
multiplier *= basicSizePlusOne;
|
|
3583
|
+
multiplier *= basicSizePlusOne;
|
|
3584
|
+
} else {
|
|
3585
|
+
encoded += multiplier * bnIndex;
|
|
3586
|
+
multiplier *= basicSizePlusOne;
|
|
3587
|
+
}
|
|
3588
|
+
} else if (bigAlphabet.indexOf(char) !== -1) {
|
|
3589
|
+
encoded += multiplier * basicAlphabetSize;
|
|
3590
|
+
multiplier *= basicSizePlusOne;
|
|
3591
|
+
const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
|
|
3592
|
+
encoded += multiplier * BigInt(newid);
|
|
3593
|
+
multiplier *= bigAlphabetSize;
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
return encoded;
|
|
3597
|
+
}
|
|
3598
|
+
var StarknetIdContract = /* @__PURE__ */ ((StarknetIdContract2) => {
|
|
3599
|
+
StarknetIdContract2["MAINNET"] = "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678";
|
|
3600
|
+
StarknetIdContract2["TESTNET"] = "0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce";
|
|
3601
|
+
return StarknetIdContract2;
|
|
3602
|
+
})(StarknetIdContract || {});
|
|
3603
|
+
function getStarknetIdContract(chainId) {
|
|
3604
|
+
switch (chainId) {
|
|
3605
|
+
case "0x534e5f4d41494e" /* SN_MAIN */:
|
|
3606
|
+
return "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678" /* MAINNET */;
|
|
3607
|
+
case "0x534e5f474f45524c49" /* SN_GOERLI */:
|
|
3608
|
+
return "0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce" /* TESTNET */;
|
|
3609
|
+
default:
|
|
3610
|
+
throw new Error("Starknet.id is not yet deployed on this network");
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
// src/provider/starknetId.ts
|
|
3615
|
+
async function getStarkName(provider, address, StarknetIdContract2) {
|
|
3616
|
+
const chainId = await provider.getChainId();
|
|
3617
|
+
const contract = StarknetIdContract2 ?? getStarknetIdContract(chainId);
|
|
3618
|
+
try {
|
|
3619
|
+
const hexDomain = await provider.callContract({
|
|
3620
|
+
contractAddress: contract,
|
|
3621
|
+
entrypoint: "address_to_domain",
|
|
3622
|
+
calldata: CallData.compile({
|
|
3623
|
+
address
|
|
3624
|
+
})
|
|
3323
3625
|
});
|
|
3626
|
+
const decimalDomain = hexDomain.result.map((element) => BigInt(element)).slice(1);
|
|
3627
|
+
const stringDomain = useDecoded(decimalDomain);
|
|
3628
|
+
if (!stringDomain) {
|
|
3629
|
+
throw Error("Starkname not found");
|
|
3630
|
+
}
|
|
3631
|
+
return stringDomain;
|
|
3632
|
+
} catch (e) {
|
|
3633
|
+
if (e instanceof Error && e.message === "Starkname not found") {
|
|
3634
|
+
throw e;
|
|
3635
|
+
}
|
|
3636
|
+
throw Error("Could not get stark name");
|
|
3324
3637
|
}
|
|
3325
|
-
|
|
3326
|
-
|
|
3638
|
+
}
|
|
3639
|
+
async function getAddressFromStarkName(provider, name, StarknetIdContract2) {
|
|
3640
|
+
const chainId = await provider.getChainId();
|
|
3641
|
+
const contract = StarknetIdContract2 ?? getStarknetIdContract(chainId);
|
|
3642
|
+
try {
|
|
3643
|
+
const addressData = await provider.callContract({
|
|
3644
|
+
contractAddress: contract,
|
|
3645
|
+
entrypoint: "domain_to_address",
|
|
3646
|
+
calldata: CallData.compile({
|
|
3647
|
+
domain: [useEncoded(name.replace(".stark", "")).toString(10)]
|
|
3648
|
+
})
|
|
3649
|
+
});
|
|
3650
|
+
return addressData.result[0];
|
|
3651
|
+
} catch {
|
|
3652
|
+
throw Error("Could not get address from stark name");
|
|
3327
3653
|
}
|
|
3328
|
-
|
|
3329
|
-
|
|
3654
|
+
}
|
|
3655
|
+
|
|
3656
|
+
// src/provider/utils.ts
|
|
3657
|
+
var validBlockTags = ["latest", "pending"];
|
|
3658
|
+
var Block = class {
|
|
3659
|
+
constructor(_identifier) {
|
|
3660
|
+
this.hash = null;
|
|
3661
|
+
this.number = null;
|
|
3662
|
+
this.tag = null;
|
|
3663
|
+
this.valueOf = () => this.number;
|
|
3664
|
+
this.toString = () => this.hash;
|
|
3665
|
+
this.setIdentifier(_identifier);
|
|
3330
3666
|
}
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
block_id
|
|
3344
|
-
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3667
|
+
setIdentifier(__identifier) {
|
|
3668
|
+
if (typeof __identifier === "string" && isHex(__identifier)) {
|
|
3669
|
+
this.hash = __identifier;
|
|
3670
|
+
} else if (typeof __identifier === "bigint") {
|
|
3671
|
+
this.hash = toHex(__identifier);
|
|
3672
|
+
} else if (typeof __identifier === "number") {
|
|
3673
|
+
this.number = __identifier;
|
|
3674
|
+
} else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
|
|
3675
|
+
this.tag = __identifier;
|
|
3676
|
+
} else {
|
|
3677
|
+
this.tag = "pending";
|
|
3678
|
+
}
|
|
3345
3679
|
}
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3350
|
-
request: {
|
|
3351
|
-
type: RPC.TransactionType.DECLARE,
|
|
3352
|
-
contract_class: {
|
|
3353
|
-
program: contractDefinition.program,
|
|
3354
|
-
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
3355
|
-
abi: contractDefinition.abi
|
|
3356
|
-
},
|
|
3357
|
-
sender_address: senderAddress,
|
|
3358
|
-
signature: signatureToHexArray(signature),
|
|
3359
|
-
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
3360
|
-
nonce: toHex(details.nonce),
|
|
3361
|
-
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
3362
|
-
},
|
|
3363
|
-
block_id
|
|
3364
|
-
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3680
|
+
get queryIdentifier() {
|
|
3681
|
+
if (this.number !== null) {
|
|
3682
|
+
return `blockNumber=${this.number}`;
|
|
3365
3683
|
}
|
|
3366
|
-
|
|
3684
|
+
if (this.hash !== null) {
|
|
3685
|
+
return `blockHash=${this.hash}`;
|
|
3686
|
+
}
|
|
3687
|
+
return `blockNumber=${this.tag}`;
|
|
3367
3688
|
}
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
signature: signatureToHexArray(signature),
|
|
3377
|
-
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
3378
|
-
nonce: toHex(details.nonce),
|
|
3379
|
-
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
3380
|
-
},
|
|
3381
|
-
block_id
|
|
3382
|
-
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3689
|
+
get identifier() {
|
|
3690
|
+
if (this.number !== null) {
|
|
3691
|
+
return { block_number: this.number };
|
|
3692
|
+
}
|
|
3693
|
+
if (this.hash !== null) {
|
|
3694
|
+
return { block_hash: this.hash };
|
|
3695
|
+
}
|
|
3696
|
+
return this.tag;
|
|
3383
3697
|
}
|
|
3384
|
-
|
|
3385
|
-
|
|
3698
|
+
set identifier(_identifier) {
|
|
3699
|
+
this.setIdentifier(_identifier);
|
|
3386
3700
|
}
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3701
|
+
get sequencerIdentifier() {
|
|
3702
|
+
return this.hash !== null ? { blockHash: this.hash } : { blockNumber: this.number ?? this.tag };
|
|
3703
|
+
}
|
|
3704
|
+
};
|
|
3705
|
+
|
|
3706
|
+
// src/provider/rpc.ts
|
|
3707
|
+
var defaultOptions = {
|
|
3708
|
+
headers: { "Content-Type": "application/json" },
|
|
3709
|
+
blockIdentifier: "latest",
|
|
3710
|
+
retries: 200
|
|
3711
|
+
};
|
|
3712
|
+
var RpcProvider = class {
|
|
3713
|
+
constructor(optionsOrProvider) {
|
|
3714
|
+
this.responseParser = new RPCResponseParser();
|
|
3715
|
+
const { nodeUrl, retries, headers, blockIdentifier } = optionsOrProvider;
|
|
3716
|
+
this.nodeUrl = nodeUrl;
|
|
3717
|
+
this.retries = retries || defaultOptions.retries;
|
|
3718
|
+
this.headers = { ...defaultOptions.headers, ...headers };
|
|
3719
|
+
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
|
|
3720
|
+
this.getChainId();
|
|
3721
|
+
}
|
|
3722
|
+
fetch(method, params) {
|
|
3723
|
+
return fetchPonyfill_default(this.nodeUrl, {
|
|
3724
|
+
method: "POST",
|
|
3725
|
+
body: stringify2({ method, jsonrpc: "2.0", params, id: 0 }),
|
|
3726
|
+
headers: this.headers
|
|
3727
|
+
});
|
|
3728
|
+
}
|
|
3729
|
+
errorHandler(error) {
|
|
3730
|
+
if (error) {
|
|
3731
|
+
const { code, message } = error;
|
|
3732
|
+
throw new LibraryError(`${code}: ${message}`);
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
async fetchEndpoint(method, params) {
|
|
3736
|
+
var _a;
|
|
3737
|
+
try {
|
|
3738
|
+
const rawResult = await this.fetch(method, params);
|
|
3739
|
+
const { error, result } = await rawResult.json();
|
|
3740
|
+
this.errorHandler(error);
|
|
3741
|
+
return result;
|
|
3742
|
+
} catch (error) {
|
|
3743
|
+
this.errorHandler((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data);
|
|
3744
|
+
throw error;
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
async getChainId() {
|
|
3748
|
+
this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
|
|
3749
|
+
return this.chainId;
|
|
3750
|
+
}
|
|
3751
|
+
async getBlock(blockIdentifier = this.blockIdentifier) {
|
|
3752
|
+
return this.getBlockWithTxHashes(blockIdentifier).then(
|
|
3753
|
+
this.responseParser.parseGetBlockResponse
|
|
3754
|
+
);
|
|
3755
|
+
}
|
|
3756
|
+
async getBlockHashAndNumber() {
|
|
3757
|
+
return this.fetchEndpoint("starknet_blockHashAndNumber");
|
|
3758
|
+
}
|
|
3759
|
+
async getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
|
|
3760
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3761
|
+
return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
|
|
3762
|
+
}
|
|
3763
|
+
async getBlockWithTxs(blockIdentifier = this.blockIdentifier) {
|
|
3764
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3765
|
+
return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
|
|
3766
|
+
}
|
|
3767
|
+
async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3768
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3769
|
+
return this.fetchEndpoint("starknet_getClassHashAt", {
|
|
3770
|
+
block_id,
|
|
3771
|
+
contract_address: contractAddress
|
|
3772
|
+
});
|
|
3773
|
+
}
|
|
3774
|
+
async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3775
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3776
|
+
return this.fetchEndpoint("starknet_getNonce", {
|
|
3777
|
+
contract_address: contractAddress,
|
|
3778
|
+
block_id
|
|
3779
|
+
});
|
|
3780
|
+
}
|
|
3781
|
+
async getPendingTransactions() {
|
|
3782
|
+
return this.fetchEndpoint("starknet_pendingTransactions");
|
|
3783
|
+
}
|
|
3784
|
+
async getProtocolVersion() {
|
|
3785
|
+
throw new Error("Pathfinder does not implement this rpc 0.1.0 method");
|
|
3786
|
+
}
|
|
3787
|
+
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
3788
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3789
|
+
return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
|
|
3790
|
+
}
|
|
3791
|
+
async getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
|
|
3792
|
+
const parsedKey = toHex(key);
|
|
3793
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3794
|
+
return this.fetchEndpoint("starknet_getStorageAt", {
|
|
3795
|
+
contract_address: contractAddress,
|
|
3796
|
+
key: parsedKey,
|
|
3797
|
+
block_id
|
|
3798
|
+
});
|
|
3799
|
+
}
|
|
3800
|
+
async getTransaction(txHash) {
|
|
3801
|
+
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
3802
|
+
}
|
|
3803
|
+
async getTransactionByHash(txHash) {
|
|
3804
|
+
return this.fetchEndpoint("starknet_getTransactionByHash", { transaction_hash: txHash });
|
|
3805
|
+
}
|
|
3806
|
+
async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
|
|
3807
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3808
|
+
return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
|
|
3809
|
+
}
|
|
3810
|
+
async getTransactionReceipt(txHash) {
|
|
3811
|
+
return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash: txHash });
|
|
3812
|
+
}
|
|
3813
|
+
async getClassByHash(classHash) {
|
|
3814
|
+
return this.getClass(classHash);
|
|
3815
|
+
}
|
|
3816
|
+
async getClass(classHash, blockIdentifier = this.blockIdentifier) {
|
|
3817
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3818
|
+
return this.fetchEndpoint("starknet_getClass", { class_hash: classHash, block_id });
|
|
3819
|
+
}
|
|
3820
|
+
async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3821
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3822
|
+
return this.fetchEndpoint("starknet_getClassAt", {
|
|
3823
|
+
block_id,
|
|
3824
|
+
contract_address: contractAddress
|
|
3825
|
+
});
|
|
3826
|
+
}
|
|
3827
|
+
async getCode(_contractAddress, _blockIdentifier) {
|
|
3828
|
+
throw new Error("RPC does not implement getCode function");
|
|
3829
|
+
}
|
|
3830
|
+
async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
3831
|
+
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
|
|
3832
|
+
}
|
|
3833
|
+
async getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
3834
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3835
|
+
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3836
|
+
request: {
|
|
3837
|
+
type: RPC.TransactionType.INVOKE,
|
|
3838
|
+
sender_address: invocation.contractAddress,
|
|
3839
|
+
calldata: CallData.toHex(invocation.calldata),
|
|
3840
|
+
signature: signatureToHexArray(invocation.signature),
|
|
3841
|
+
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 0),
|
|
3842
|
+
nonce: toHex(invocationDetails.nonce),
|
|
3843
|
+
max_fee: toHex((invocationDetails == null ? void 0 : invocationDetails.maxFee) || 0)
|
|
3844
|
+
},
|
|
3845
|
+
block_id
|
|
3846
|
+
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3847
|
+
}
|
|
3848
|
+
async getDeclareEstimateFee({ senderAddress, contractDefinition, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
3849
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3850
|
+
if ("program" in contractDefinition) {
|
|
3851
|
+
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3852
|
+
request: {
|
|
3853
|
+
type: RPC.TransactionType.DECLARE,
|
|
3854
|
+
contract_class: {
|
|
3855
|
+
program: contractDefinition.program,
|
|
3856
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
3857
|
+
abi: contractDefinition.abi
|
|
3858
|
+
},
|
|
3859
|
+
sender_address: senderAddress,
|
|
3860
|
+
signature: signatureToHexArray(signature),
|
|
3861
|
+
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
3862
|
+
nonce: toHex(details.nonce),
|
|
3863
|
+
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
3864
|
+
},
|
|
3865
|
+
block_id
|
|
3866
|
+
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3867
|
+
}
|
|
3868
|
+
throw new Error("RPC do not support Sierra Contracts yet");
|
|
3869
|
+
}
|
|
3870
|
+
async getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
3871
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3872
|
+
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3873
|
+
request: {
|
|
3874
|
+
type: RPC.TransactionType.DEPLOY_ACCOUNT,
|
|
3875
|
+
constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata || []),
|
|
3876
|
+
class_hash: toHex(classHash),
|
|
3877
|
+
contract_address_salt: toHex(addressSalt || 0),
|
|
3878
|
+
signature: signatureToHexArray(signature),
|
|
3879
|
+
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
3880
|
+
nonce: toHex(details.nonce),
|
|
3881
|
+
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
3882
|
+
},
|
|
3883
|
+
block_id
|
|
3884
|
+
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
3885
|
+
}
|
|
3886
|
+
async getEstimateFeeBulk(_invocations, _blockIdentifier = this.blockIdentifier) {
|
|
3887
|
+
throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
|
|
3888
|
+
}
|
|
3889
|
+
async declareContract({ contractDefinition, signature, senderAddress }, details) {
|
|
3890
|
+
if ("program" in contractDefinition) {
|
|
3891
|
+
return this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
3390
3892
|
declare_transaction: {
|
|
3391
3893
|
contract_class: {
|
|
3392
3894
|
program: contractDefinition.program,
|
|
@@ -3422,7 +3924,7 @@ var RpcProvider = class {
|
|
|
3422
3924
|
return this.fetchEndpoint("starknet_addInvokeTransaction", {
|
|
3423
3925
|
invoke_transaction: {
|
|
3424
3926
|
sender_address: functionInvocation.contractAddress,
|
|
3425
|
-
calldata:
|
|
3927
|
+
calldata: CallData.toHex(functionInvocation.calldata),
|
|
3426
3928
|
type: RPC.TransactionType.INVOKE,
|
|
3427
3929
|
max_fee: toHex(details.maxFee || 0),
|
|
3428
3930
|
version: "0x1",
|
|
@@ -3437,7 +3939,7 @@ var RpcProvider = class {
|
|
|
3437
3939
|
request: {
|
|
3438
3940
|
contract_address: call.contractAddress,
|
|
3439
3941
|
entry_point_selector: getSelectorFromName(call.entrypoint),
|
|
3440
|
-
calldata:
|
|
3942
|
+
calldata: CallData.toHex(call.calldata)
|
|
3441
3943
|
},
|
|
3442
3944
|
block_id
|
|
3443
3945
|
});
|
|
@@ -3907,7 +4409,7 @@ var SequencerProvider = class {
|
|
|
3907
4409
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
3908
4410
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
3909
4411
|
sender_address: functionInvocation.contractAddress,
|
|
3910
|
-
calldata:
|
|
4412
|
+
calldata: CallData.compile(functionInvocation.calldata ?? []),
|
|
3911
4413
|
signature: signatureToDecimalArray(functionInvocation.signature),
|
|
3912
4414
|
nonce: toHex(details.nonce),
|
|
3913
4415
|
max_fee: toHex(details.maxFee || 0),
|
|
@@ -3918,7 +4420,7 @@ var SequencerProvider = class {
|
|
|
3918
4420
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
3919
4421
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
3920
4422
|
contract_address_salt: addressSalt ?? randomAddress(),
|
|
3921
|
-
constructor_calldata:
|
|
4423
|
+
constructor_calldata: CallData.compile(constructorCalldata ?? []),
|
|
3922
4424
|
class_hash: toHex(classHash),
|
|
3923
4425
|
max_fee: toHex(details.maxFee || 0),
|
|
3924
4426
|
version: toHex(details.version || 0),
|
|
@@ -4002,7 +4504,7 @@ var SequencerProvider = class {
|
|
|
4002
4504
|
{
|
|
4003
4505
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
4004
4506
|
class_hash: toHex(classHash),
|
|
4005
|
-
constructor_calldata:
|
|
4507
|
+
constructor_calldata: CallData.compile(constructorCalldata || []),
|
|
4006
4508
|
contract_address_salt: toHex(addressSalt || 0),
|
|
4007
4509
|
signature: signatureToDecimalArray(signature),
|
|
4008
4510
|
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
@@ -4029,9 +4531,7 @@ var SequencerProvider = class {
|
|
|
4029
4531
|
res = {
|
|
4030
4532
|
type: invocation.type,
|
|
4031
4533
|
class_hash: toHex(toBigInt(invocation.classHash)),
|
|
4032
|
-
constructor_calldata:
|
|
4033
|
-
invocation.constructorCalldata || []
|
|
4034
|
-
),
|
|
4534
|
+
constructor_calldata: CallData.compile(invocation.constructorCalldata || []),
|
|
4035
4535
|
contract_address_salt: toHex(toBigInt(invocation.addressSalt || 0))
|
|
4036
4536
|
};
|
|
4037
4537
|
}
|
|
@@ -4110,640 +4610,135 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
4110
4610
|
}
|
|
4111
4611
|
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
4112
4612
|
}
|
|
4113
|
-
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
4114
|
-
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4115
|
-
return this.fetchEndpoint("get_state_update", { ...args }).then(
|
|
4116
|
-
this.responseParser.parseGetStateUpdateResponse
|
|
4117
|
-
);
|
|
4118
|
-
}
|
|
4119
|
-
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
4120
|
-
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4121
|
-
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
4122
|
-
}
|
|
4123
|
-
async getStarkName(address, StarknetIdContract2) {
|
|
4124
|
-
return getStarkName(this, address, StarknetIdContract2);
|
|
4125
|
-
}
|
|
4126
|
-
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4127
|
-
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4128
|
-
}
|
|
4129
|
-
};
|
|
4130
|
-
|
|
4131
|
-
// src/provider/default.ts
|
|
4132
|
-
var Provider = class {
|
|
4133
|
-
constructor(providerOrOptions) {
|
|
4134
|
-
if (providerOrOptions instanceof Provider) {
|
|
4135
|
-
this.provider = providerOrOptions.provider;
|
|
4136
|
-
} else if (providerOrOptions instanceof RpcProvider || providerOrOptions instanceof SequencerProvider) {
|
|
4137
|
-
this.provider = providerOrOptions;
|
|
4138
|
-
} else if (providerOrOptions && "rpc" in providerOrOptions) {
|
|
4139
|
-
this.provider = new RpcProvider(providerOrOptions.rpc);
|
|
4140
|
-
} else if (providerOrOptions && "sequencer" in providerOrOptions) {
|
|
4141
|
-
this.provider = new SequencerProvider(providerOrOptions.sequencer);
|
|
4142
|
-
} else {
|
|
4143
|
-
this.provider = new SequencerProvider();
|
|
4144
|
-
}
|
|
4145
|
-
}
|
|
4146
|
-
async getChainId() {
|
|
4147
|
-
return this.provider.getChainId();
|
|
4148
|
-
}
|
|
4149
|
-
async getBlock(blockIdentifier) {
|
|
4150
|
-
return this.provider.getBlock(blockIdentifier);
|
|
4151
|
-
}
|
|
4152
|
-
async getClassAt(contractAddress, blockIdentifier) {
|
|
4153
|
-
return this.provider.getClassAt(contractAddress, blockIdentifier);
|
|
4154
|
-
}
|
|
4155
|
-
async getClassHashAt(contractAddress, blockIdentifier) {
|
|
4156
|
-
return this.provider.getClassHashAt(contractAddress, blockIdentifier);
|
|
4157
|
-
}
|
|
4158
|
-
getClassByHash(classHash) {
|
|
4159
|
-
return this.provider.getClassByHash(classHash);
|
|
4160
|
-
}
|
|
4161
|
-
async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
4162
|
-
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
4163
|
-
}
|
|
4164
|
-
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
|
|
4165
|
-
return this.provider.getInvokeEstimateFee(
|
|
4166
|
-
invocationWithTxType,
|
|
4167
|
-
invocationDetails,
|
|
4168
|
-
blockIdentifier,
|
|
4169
|
-
skipValidate
|
|
4170
|
-
);
|
|
4171
|
-
}
|
|
4172
|
-
async getEstimateFeeBulk(invocations, blockIdentifier) {
|
|
4173
|
-
return this.provider.getEstimateFeeBulk(invocations, blockIdentifier);
|
|
4174
|
-
}
|
|
4175
|
-
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
4176
|
-
return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
|
|
4177
|
-
}
|
|
4178
|
-
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4179
|
-
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
|
|
4180
|
-
}
|
|
4181
|
-
async getTransaction(txHash) {
|
|
4182
|
-
return this.provider.getTransaction(txHash);
|
|
4183
|
-
}
|
|
4184
|
-
async getTransactionReceipt(txHash) {
|
|
4185
|
-
return this.provider.getTransactionReceipt(txHash);
|
|
4186
|
-
}
|
|
4187
|
-
async callContract(request, blockIdentifier) {
|
|
4188
|
-
return this.provider.callContract(request, blockIdentifier);
|
|
4189
|
-
}
|
|
4190
|
-
async invokeFunction(functionInvocation, details) {
|
|
4191
|
-
return this.provider.invokeFunction(functionInvocation, details);
|
|
4192
|
-
}
|
|
4193
|
-
async deployAccountContract(payload, details) {
|
|
4194
|
-
return this.provider.deployAccountContract(payload, details);
|
|
4195
|
-
}
|
|
4196
|
-
async declareContract(transaction, details) {
|
|
4197
|
-
return this.provider.declareContract(transaction, details);
|
|
4198
|
-
}
|
|
4199
|
-
async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4200
|
-
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
|
|
4201
|
-
}
|
|
4202
|
-
getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4203
|
-
return this.provider.getDeployAccountEstimateFee(
|
|
4204
|
-
transaction,
|
|
4205
|
-
details,
|
|
4206
|
-
blockIdentifier,
|
|
4207
|
-
skipValidate
|
|
4208
|
-
);
|
|
4209
|
-
}
|
|
4210
|
-
async getCode(contractAddress, blockIdentifier) {
|
|
4211
|
-
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
4212
|
-
}
|
|
4213
|
-
async waitForTransaction(txHash, options) {
|
|
4214
|
-
return this.provider.waitForTransaction(txHash, options);
|
|
4215
|
-
}
|
|
4216
|
-
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
|
|
4217
|
-
return this.provider.getSimulateTransaction(
|
|
4218
|
-
invocation,
|
|
4219
|
-
invocationDetails,
|
|
4220
|
-
blockIdentifier,
|
|
4221
|
-
skipValidate
|
|
4222
|
-
);
|
|
4223
|
-
}
|
|
4224
|
-
async getStateUpdate(blockIdentifier) {
|
|
4225
|
-
return this.provider.getStateUpdate(blockIdentifier);
|
|
4226
|
-
}
|
|
4227
|
-
async getStarkName(address, StarknetIdContract2) {
|
|
4228
|
-
return getStarkName(this, address, StarknetIdContract2);
|
|
4229
|
-
}
|
|
4230
|
-
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4231
|
-
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4232
|
-
}
|
|
4233
|
-
};
|
|
4234
|
-
|
|
4235
|
-
// src/provider/interface.ts
|
|
4236
|
-
var ProviderInterface = class {
|
|
4237
|
-
};
|
|
4238
|
-
|
|
4239
|
-
// src/provider/index.ts
|
|
4240
|
-
var defaultProvider = new Provider();
|
|
4241
|
-
|
|
4242
|
-
// src/utils/calldata/formatter.ts
|
|
4243
|
-
var guard = {
|
|
4244
|
-
isBN: (data, type, key) => {
|
|
4245
|
-
if (!isBigInt(data[key]))
|
|
4246
|
-
throw new Error(
|
|
4247
|
-
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
4248
|
-
);
|
|
4249
|
-
},
|
|
4250
|
-
unknown: (data, type, key) => {
|
|
4251
|
-
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
4252
|
-
}
|
|
4253
|
-
};
|
|
4254
|
-
function formatter(data, type, sameType) {
|
|
4255
|
-
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
4256
|
-
const elType = sameType ?? type[key];
|
|
4257
|
-
if (!(key in type) && !sameType) {
|
|
4258
|
-
acc[key] = value;
|
|
4259
|
-
return acc;
|
|
4260
|
-
}
|
|
4261
|
-
if (elType === "string") {
|
|
4262
|
-
if (Array.isArray(data[key])) {
|
|
4263
|
-
const arrayStr = formatter(
|
|
4264
|
-
data[key],
|
|
4265
|
-
data[key].map((_) => elType)
|
|
4266
|
-
);
|
|
4267
|
-
acc[key] = Object.values(arrayStr).join("");
|
|
4268
|
-
return acc;
|
|
4269
|
-
}
|
|
4270
|
-
guard.isBN(data, type, key);
|
|
4271
|
-
acc[key] = decodeShortString(value);
|
|
4272
|
-
return acc;
|
|
4273
|
-
}
|
|
4274
|
-
if (elType === "number") {
|
|
4275
|
-
guard.isBN(data, type, key);
|
|
4276
|
-
acc[key] = Number(value);
|
|
4277
|
-
return acc;
|
|
4278
|
-
}
|
|
4279
|
-
if (typeof elType === "function") {
|
|
4280
|
-
acc[key] = elType(value);
|
|
4281
|
-
return acc;
|
|
4282
|
-
}
|
|
4283
|
-
if (Array.isArray(elType)) {
|
|
4284
|
-
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
4285
|
-
acc[key] = Object.values(arrayObj);
|
|
4286
|
-
return acc;
|
|
4287
|
-
}
|
|
4288
|
-
if (typeof elType === "object") {
|
|
4289
|
-
acc[key] = formatter(data[key], elType);
|
|
4290
|
-
return acc;
|
|
4291
|
-
}
|
|
4292
|
-
guard.unknown(data, type, key);
|
|
4293
|
-
return acc;
|
|
4294
|
-
}, {});
|
|
4295
|
-
}
|
|
4296
|
-
|
|
4297
|
-
// src/utils/calldata/tuple.ts
|
|
4298
|
-
function parseNamedTuple(namedTuple) {
|
|
4299
|
-
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
4300
|
-
const type = namedTuple.substring(name.length + ":".length);
|
|
4301
|
-
return { name, type };
|
|
4302
|
-
}
|
|
4303
|
-
function parseSubTuple(s) {
|
|
4304
|
-
if (!s.includes("("))
|
|
4305
|
-
return { subTuple: [], result: s };
|
|
4306
|
-
const subTuple = [];
|
|
4307
|
-
let result = "";
|
|
4308
|
-
let i = 0;
|
|
4309
|
-
while (i < s.length) {
|
|
4310
|
-
if (s[i] === "(") {
|
|
4311
|
-
let counter = 1;
|
|
4312
|
-
const lBracket = i;
|
|
4313
|
-
i++;
|
|
4314
|
-
while (counter) {
|
|
4315
|
-
if (s[i] === ")")
|
|
4316
|
-
counter--;
|
|
4317
|
-
if (s[i] === "(")
|
|
4318
|
-
counter++;
|
|
4319
|
-
i++;
|
|
4320
|
-
}
|
|
4321
|
-
subTuple.push(s.substring(lBracket, i));
|
|
4322
|
-
result += " ";
|
|
4323
|
-
i--;
|
|
4324
|
-
} else {
|
|
4325
|
-
result += s[i];
|
|
4326
|
-
}
|
|
4327
|
-
i++;
|
|
4328
|
-
}
|
|
4329
|
-
return {
|
|
4330
|
-
subTuple,
|
|
4331
|
-
result
|
|
4332
|
-
};
|
|
4333
|
-
}
|
|
4334
|
-
function extractCairo0Tuple(type) {
|
|
4335
|
-
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
4336
|
-
const { subTuple, result } = parseSubTuple(cleanType);
|
|
4337
|
-
let recomposed = result.split(",").map((it) => {
|
|
4338
|
-
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
4339
|
-
});
|
|
4340
|
-
if (isTypeNamedTuple(type)) {
|
|
4341
|
-
recomposed = recomposed.reduce((acc, it) => {
|
|
4342
|
-
return acc.concat(parseNamedTuple(it));
|
|
4343
|
-
}, []);
|
|
4344
|
-
}
|
|
4345
|
-
return recomposed;
|
|
4346
|
-
}
|
|
4347
|
-
function extractCairo1Tuple(type) {
|
|
4348
|
-
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
4349
|
-
return cleanType.split(",");
|
|
4350
|
-
}
|
|
4351
|
-
function extractTupleMemberTypes(type) {
|
|
4352
|
-
if (isCairo1Type(type)) {
|
|
4353
|
-
return extractCairo1Tuple(type);
|
|
4354
|
-
}
|
|
4355
|
-
return extractCairo0Tuple(type);
|
|
4356
|
-
}
|
|
4357
|
-
|
|
4358
|
-
// src/utils/calldata/requestParser.ts
|
|
4359
|
-
function parseTuple(element, typeStr) {
|
|
4360
|
-
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
4361
|
-
const elements = Object.values(element);
|
|
4362
|
-
if (elements.length !== memberTypes.length) {
|
|
4363
|
-
throw Error(
|
|
4364
|
-
`ParseTuple: provided and expected abi tuple size do not match.
|
|
4365
|
-
provided: ${elements}
|
|
4366
|
-
expected: ${memberTypes}`
|
|
4367
|
-
);
|
|
4368
|
-
}
|
|
4369
|
-
return memberTypes.map((it, dx) => {
|
|
4370
|
-
return {
|
|
4371
|
-
element: elements[dx],
|
|
4372
|
-
type: it.type ?? it
|
|
4373
|
-
};
|
|
4374
|
-
});
|
|
4375
|
-
}
|
|
4376
|
-
function parseCalldataValue(element, type, structs) {
|
|
4377
|
-
if (element === void 0) {
|
|
4378
|
-
throw Error(`Missing parameter for type ${type}`);
|
|
4379
|
-
}
|
|
4380
|
-
if (Array.isArray(element)) {
|
|
4381
|
-
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
4382
|
-
}
|
|
4383
|
-
if (isTypeUint256(type)) {
|
|
4384
|
-
const el_uint256 = uint256(element);
|
|
4385
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
4386
|
-
}
|
|
4387
|
-
if (structs[type] && structs[type].members.length) {
|
|
4388
|
-
const { members } = structs[type];
|
|
4389
|
-
const subElement = element;
|
|
4390
|
-
return members.reduce((acc, it) => {
|
|
4391
|
-
return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs));
|
|
4392
|
-
}, []);
|
|
4393
|
-
}
|
|
4394
|
-
if (isTypeTuple(type)) {
|
|
4395
|
-
const tupled = parseTuple(element, type);
|
|
4396
|
-
return tupled.reduce((acc, it) => {
|
|
4397
|
-
const parsedData = parseCalldataValue(it.element, it.type, structs);
|
|
4398
|
-
return acc.concat(parsedData);
|
|
4399
|
-
}, []);
|
|
4400
|
-
}
|
|
4401
|
-
if (typeof element === "object") {
|
|
4402
|
-
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
4403
|
-
}
|
|
4404
|
-
return felt(element);
|
|
4405
|
-
}
|
|
4406
|
-
function parseCalldataField(argsIterator, input, structs) {
|
|
4407
|
-
const { name, type } = input;
|
|
4408
|
-
let { value } = argsIterator.next();
|
|
4409
|
-
switch (true) {
|
|
4410
|
-
case isTypeArray(type):
|
|
4411
|
-
if (!Array.isArray(value) && !isText(value)) {
|
|
4412
|
-
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
4413
|
-
}
|
|
4414
|
-
if (typeof value === "string") {
|
|
4415
|
-
value = splitLongString(value);
|
|
4416
|
-
}
|
|
4417
|
-
const result = [];
|
|
4418
|
-
result.push(felt(value.length));
|
|
4419
|
-
const arrayType = getArrayType(input.type);
|
|
4420
|
-
return value.reduce((acc, el) => {
|
|
4421
|
-
if (isTypeFelt(arrayType) || isTypeUint(arrayType) || isTypeContractAddress(arrayType)) {
|
|
4422
|
-
acc.push(felt(el));
|
|
4423
|
-
} else if (isTypeBool(arrayType) && typeof el === "boolean") {
|
|
4424
|
-
acc.push(el.toString());
|
|
4425
|
-
} else {
|
|
4426
|
-
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
4427
|
-
}
|
|
4428
|
-
return acc;
|
|
4429
|
-
}, result);
|
|
4430
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
|
|
4431
|
-
return parseCalldataValue(value, type, structs);
|
|
4432
|
-
case isTypeBool(type):
|
|
4433
|
-
return `${+value}`;
|
|
4434
|
-
default:
|
|
4435
|
-
return felt(value);
|
|
4436
|
-
}
|
|
4437
|
-
}
|
|
4438
|
-
|
|
4439
|
-
// src/utils/calldata/responseParser.ts
|
|
4440
|
-
function parseResponseStruct(responseIterator, type, structs) {
|
|
4441
|
-
if (type in structs && structs[type]) {
|
|
4442
|
-
return structs[type].members.reduce((acc, el) => {
|
|
4443
|
-
acc[el.name] = parseResponseStruct(responseIterator, el.type, structs);
|
|
4444
|
-
return acc;
|
|
4445
|
-
}, {});
|
|
4446
|
-
}
|
|
4447
|
-
if (isTypeTuple(type)) {
|
|
4448
|
-
const memberTypes = extractTupleMemberTypes(type);
|
|
4449
|
-
return memberTypes.reduce((acc, it, idx) => {
|
|
4450
|
-
const tName = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
4451
|
-
const tType = (it == null ? void 0 : it.type) ? it.type : it;
|
|
4452
|
-
acc[tName] = parseResponseStruct(responseIterator, tType, structs);
|
|
4453
|
-
return acc;
|
|
4454
|
-
}, {});
|
|
4455
|
-
}
|
|
4456
|
-
const temp = responseIterator.next().value;
|
|
4457
|
-
return BigInt(temp);
|
|
4458
|
-
}
|
|
4459
|
-
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
4460
|
-
const { name, type } = output;
|
|
4461
|
-
let temp;
|
|
4462
|
-
switch (true) {
|
|
4463
|
-
case isLen(name):
|
|
4464
|
-
temp = responseIterator.next().value;
|
|
4465
|
-
return BigInt(temp);
|
|
4466
|
-
case isTypeBool(type):
|
|
4467
|
-
temp = responseIterator.next().value;
|
|
4468
|
-
return Boolean(BigInt(temp));
|
|
4469
|
-
case isTypeUint256(type):
|
|
4470
|
-
const low = responseIterator.next().value;
|
|
4471
|
-
const high = responseIterator.next().value;
|
|
4472
|
-
return uint256ToBN({ low, high });
|
|
4473
|
-
case isTypeArray(type):
|
|
4474
|
-
const parsedDataArr = [];
|
|
4475
|
-
if (isCairo1Type(type)) {
|
|
4476
|
-
responseIterator.next();
|
|
4477
|
-
let it = responseIterator.next();
|
|
4478
|
-
while (!it.done) {
|
|
4479
|
-
parsedDataArr.push(BigInt(it.value));
|
|
4480
|
-
it = responseIterator.next();
|
|
4481
|
-
}
|
|
4482
|
-
return parsedDataArr;
|
|
4483
|
-
}
|
|
4484
|
-
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
4485
|
-
const arrLen = parsedResult[`${name}_len`];
|
|
4486
|
-
while (parsedDataArr.length < arrLen) {
|
|
4487
|
-
parsedDataArr.push(
|
|
4488
|
-
parseResponseStruct(responseIterator, output.type.replace("*", ""), structs)
|
|
4489
|
-
);
|
|
4490
|
-
}
|
|
4491
|
-
}
|
|
4492
|
-
return parsedDataArr;
|
|
4493
|
-
case (type in structs || isTypeTuple(type)):
|
|
4494
|
-
return parseResponseStruct(responseIterator, type, structs);
|
|
4495
|
-
default:
|
|
4496
|
-
temp = responseIterator.next().value;
|
|
4497
|
-
return BigInt(temp);
|
|
4498
|
-
}
|
|
4499
|
-
}
|
|
4500
|
-
|
|
4501
|
-
// src/utils/calldata/validate.ts
|
|
4502
|
-
var validateFelt = (parameter, input) => {
|
|
4503
|
-
assert(
|
|
4504
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
4505
|
-
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
4506
|
-
);
|
|
4507
|
-
};
|
|
4508
|
-
var validateUint = (parameter, input) => {
|
|
4509
|
-
if (typeof parameter === "number") {
|
|
4510
|
-
assert(
|
|
4511
|
-
parameter <= Number.MAX_SAFE_INTEGER,
|
|
4512
|
-
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
4513
|
-
);
|
|
4514
|
-
}
|
|
4515
|
-
assert(
|
|
4516
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
4517
|
-
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
|
|
4518
|
-
);
|
|
4519
|
-
const param = toBigInt(parameter);
|
|
4520
|
-
switch (input.type) {
|
|
4521
|
-
case "core::integer::u8" /* u8 */:
|
|
4522
|
-
assert(
|
|
4523
|
-
param >= 0n && param <= 255n,
|
|
4524
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
4525
|
-
);
|
|
4526
|
-
break;
|
|
4527
|
-
case "core::integer::u16" /* u16 */:
|
|
4528
|
-
assert(
|
|
4529
|
-
param >= 0n && param <= 65535n,
|
|
4530
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
4531
|
-
);
|
|
4532
|
-
break;
|
|
4533
|
-
case "core::integer::u32" /* u32 */:
|
|
4534
|
-
assert(
|
|
4535
|
-
param >= 0n && param <= 4294967295n,
|
|
4536
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
4537
|
-
);
|
|
4538
|
-
break;
|
|
4539
|
-
case "core::integer::u64" /* u64 */:
|
|
4540
|
-
assert(
|
|
4541
|
-
param >= 0n && param <= 2n ** 64n - 1n,
|
|
4542
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
4543
|
-
);
|
|
4544
|
-
break;
|
|
4545
|
-
case "core::integer::u128" /* u128 */:
|
|
4546
|
-
assert(
|
|
4547
|
-
param >= 0n && param <= 2n ** 128n - 1n,
|
|
4548
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
4549
|
-
);
|
|
4550
|
-
break;
|
|
4551
|
-
case "core::integer::u256" /* u256 */:
|
|
4552
|
-
assert(
|
|
4553
|
-
param >= 0n && param <= 2n ** 256n - 1n,
|
|
4554
|
-
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
4555
|
-
);
|
|
4556
|
-
break;
|
|
4557
|
-
default:
|
|
4558
|
-
break;
|
|
4559
|
-
}
|
|
4560
|
-
};
|
|
4561
|
-
var validateBool = (parameter, input) => {
|
|
4562
|
-
assert(
|
|
4563
|
-
typeof parameter === "boolean",
|
|
4564
|
-
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
4565
|
-
);
|
|
4566
|
-
};
|
|
4567
|
-
var validateStruct = (parameter, input, structs) => {
|
|
4568
|
-
assert(
|
|
4569
|
-
typeof parameter === "object" && !Array.isArray(parameter),
|
|
4570
|
-
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
4571
|
-
);
|
|
4572
|
-
structs[input.type].members.forEach(({ name }) => {
|
|
4573
|
-
assert(
|
|
4574
|
-
Object.keys(parameter).includes(name),
|
|
4575
|
-
`Validate: arg ${input.name} should have a property ${name}`
|
|
4576
|
-
);
|
|
4577
|
-
});
|
|
4578
|
-
};
|
|
4579
|
-
var validateTuple = (parameter, input) => {
|
|
4580
|
-
assert(
|
|
4581
|
-
typeof parameter === "object" && !Array.isArray(parameter),
|
|
4582
|
-
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
4583
|
-
);
|
|
4584
|
-
};
|
|
4585
|
-
var validateArray = (parameter, input, structs) => {
|
|
4586
|
-
const baseType = getArrayType(input.type);
|
|
4587
|
-
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
4588
|
-
return;
|
|
4589
|
-
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
4590
|
-
switch (true) {
|
|
4591
|
-
case isTypeFelt(baseType):
|
|
4592
|
-
parameter.forEach((param) => validateFelt(param, input));
|
|
4593
|
-
break;
|
|
4594
|
-
case isTypeTuple(baseType):
|
|
4595
|
-
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
4596
|
-
break;
|
|
4597
|
-
case isTypeStruct(baseType, structs):
|
|
4598
|
-
parameter.forEach(
|
|
4599
|
-
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
4600
|
-
);
|
|
4601
|
-
break;
|
|
4602
|
-
case isTypeUint(baseType):
|
|
4603
|
-
parameter.forEach((param) => validateUint(param, input));
|
|
4604
|
-
break;
|
|
4605
|
-
case isTypeBool(baseType):
|
|
4606
|
-
parameter.forEach((param) => validateBool(param, input));
|
|
4607
|
-
break;
|
|
4608
|
-
default:
|
|
4609
|
-
throw new Error(
|
|
4610
|
-
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
4611
|
-
);
|
|
4612
|
-
}
|
|
4613
|
+
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
4614
|
+
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4615
|
+
return this.fetchEndpoint("get_state_update", { ...args }).then(
|
|
4616
|
+
this.responseParser.parseGetStateUpdateResponse
|
|
4617
|
+
);
|
|
4618
|
+
}
|
|
4619
|
+
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
4620
|
+
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4621
|
+
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
4622
|
+
}
|
|
4623
|
+
async getStarkName(address, StarknetIdContract2) {
|
|
4624
|
+
return getStarkName(this, address, StarknetIdContract2);
|
|
4625
|
+
}
|
|
4626
|
+
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4627
|
+
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4628
|
+
}
|
|
4613
4629
|
};
|
|
4614
|
-
function validateFields(abiMethod, args, structs) {
|
|
4615
|
-
abiMethod.inputs.reduce((acc, input) => {
|
|
4616
|
-
const parameter = args[acc];
|
|
4617
|
-
switch (true) {
|
|
4618
|
-
case isLen(input.name):
|
|
4619
|
-
return acc;
|
|
4620
|
-
case isTypeFelt(input.type):
|
|
4621
|
-
validateFelt(parameter, input);
|
|
4622
|
-
break;
|
|
4623
|
-
case isTypeUint(input.type):
|
|
4624
|
-
validateUint(parameter, input);
|
|
4625
|
-
break;
|
|
4626
|
-
case isTypeBool(input.type):
|
|
4627
|
-
validateBool(parameter, input);
|
|
4628
|
-
break;
|
|
4629
|
-
case isTypeContractAddress(input.type):
|
|
4630
|
-
break;
|
|
4631
|
-
case isTypeStruct(input.type, structs):
|
|
4632
|
-
validateStruct(parameter, input, structs);
|
|
4633
|
-
break;
|
|
4634
|
-
case isTypeTuple(input.type):
|
|
4635
|
-
validateTuple(parameter, input);
|
|
4636
|
-
break;
|
|
4637
|
-
case isTypeArray(input.type):
|
|
4638
|
-
validateArray(parameter, input, structs);
|
|
4639
|
-
break;
|
|
4640
|
-
default:
|
|
4641
|
-
throw new Error(
|
|
4642
|
-
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
4643
|
-
);
|
|
4644
|
-
}
|
|
4645
|
-
return acc + 1;
|
|
4646
|
-
}, 0);
|
|
4647
|
-
}
|
|
4648
4630
|
|
|
4649
|
-
// src/
|
|
4650
|
-
var
|
|
4651
|
-
constructor(
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
if (
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
}).map((abi) => abi.name);
|
|
4663
|
-
assert(
|
|
4664
|
-
invocableFunctionNames.includes(method),
|
|
4665
|
-
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
4666
|
-
);
|
|
4667
|
-
}
|
|
4668
|
-
const abiMethod = this.abi.find(
|
|
4669
|
-
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
4670
|
-
);
|
|
4671
|
-
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
4672
|
-
if (args.length !== inputsLength) {
|
|
4673
|
-
throw Error(
|
|
4674
|
-
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
4675
|
-
);
|
|
4631
|
+
// src/provider/default.ts
|
|
4632
|
+
var Provider = class {
|
|
4633
|
+
constructor(providerOrOptions) {
|
|
4634
|
+
if (providerOrOptions instanceof Provider) {
|
|
4635
|
+
this.provider = providerOrOptions.provider;
|
|
4636
|
+
} else if (providerOrOptions instanceof RpcProvider || providerOrOptions instanceof SequencerProvider) {
|
|
4637
|
+
this.provider = providerOrOptions;
|
|
4638
|
+
} else if (providerOrOptions && "rpc" in providerOrOptions) {
|
|
4639
|
+
this.provider = new RpcProvider(providerOrOptions.rpc);
|
|
4640
|
+
} else if (providerOrOptions && "sequencer" in providerOrOptions) {
|
|
4641
|
+
this.provider = new SequencerProvider(providerOrOptions.sequencer);
|
|
4642
|
+
} else {
|
|
4643
|
+
this.provider = new SequencerProvider();
|
|
4676
4644
|
}
|
|
4677
|
-
validateFields(abiMethod, args, this.structs);
|
|
4678
4645
|
}
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4646
|
+
async getChainId() {
|
|
4647
|
+
return this.provider.getChainId();
|
|
4648
|
+
}
|
|
4649
|
+
async getBlock(blockIdentifier) {
|
|
4650
|
+
return this.provider.getBlock(blockIdentifier);
|
|
4651
|
+
}
|
|
4652
|
+
async getClassAt(contractAddress, blockIdentifier) {
|
|
4653
|
+
return this.provider.getClassAt(contractAddress, blockIdentifier);
|
|
4654
|
+
}
|
|
4655
|
+
async getClassHashAt(contractAddress, blockIdentifier) {
|
|
4656
|
+
return this.provider.getClassHashAt(contractAddress, blockIdentifier);
|
|
4657
|
+
}
|
|
4658
|
+
getClassByHash(classHash) {
|
|
4659
|
+
return this.provider.getClassByHash(classHash);
|
|
4660
|
+
}
|
|
4661
|
+
async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
4662
|
+
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
4663
|
+
}
|
|
4664
|
+
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
|
|
4665
|
+
return this.provider.getInvokeEstimateFee(
|
|
4666
|
+
invocationWithTxType,
|
|
4667
|
+
invocationDetails,
|
|
4668
|
+
blockIdentifier,
|
|
4669
|
+
skipValidate
|
|
4684
4670
|
);
|
|
4685
4671
|
}
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
const getEntries = (o, prefix = "") => {
|
|
4689
|
-
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
4690
|
-
return Object.entries(oe).flatMap(([k, v]) => {
|
|
4691
|
-
let value = v;
|
|
4692
|
-
if (isLongText(value))
|
|
4693
|
-
value = splitLongString(value);
|
|
4694
|
-
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
4695
|
-
if (isBigInt(value))
|
|
4696
|
-
return [[`${prefix}${kk}`, felt(value)]];
|
|
4697
|
-
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
4698
|
-
});
|
|
4699
|
-
};
|
|
4700
|
-
return Object.fromEntries(getEntries(obj));
|
|
4701
|
-
};
|
|
4702
|
-
let callTreeArray;
|
|
4703
|
-
if (!Array.isArray(data)) {
|
|
4704
|
-
const callTree = createTree(data);
|
|
4705
|
-
callTreeArray = Object.values(callTree);
|
|
4706
|
-
} else {
|
|
4707
|
-
callTreeArray = data;
|
|
4708
|
-
}
|
|
4709
|
-
Object.defineProperty(callTreeArray, "compiled", {
|
|
4710
|
-
enumerable: false,
|
|
4711
|
-
writable: false,
|
|
4712
|
-
value: true
|
|
4713
|
-
});
|
|
4714
|
-
return callTreeArray;
|
|
4672
|
+
async getEstimateFeeBulk(invocations, blockIdentifier) {
|
|
4673
|
+
return this.provider.getEstimateFeeBulk(invocations, blockIdentifier);
|
|
4715
4674
|
}
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
const responseIterator = response.flat()[Symbol.iterator]();
|
|
4719
|
-
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
4720
|
-
const propName = output.name ?? idx;
|
|
4721
|
-
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
4722
|
-
if (acc[propName] && acc[`${propName}_len`]) {
|
|
4723
|
-
delete acc[`${propName}_len`];
|
|
4724
|
-
}
|
|
4725
|
-
return acc;
|
|
4726
|
-
}, {});
|
|
4727
|
-
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
4675
|
+
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
4676
|
+
return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
|
|
4728
4677
|
}
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
return formatter(parsed, format);
|
|
4678
|
+
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4679
|
+
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
|
|
4732
4680
|
}
|
|
4733
|
-
|
|
4734
|
-
return
|
|
4681
|
+
async getTransaction(txHash) {
|
|
4682
|
+
return this.provider.getTransaction(txHash);
|
|
4735
4683
|
}
|
|
4736
|
-
|
|
4737
|
-
return
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4684
|
+
async getTransactionReceipt(txHash) {
|
|
4685
|
+
return this.provider.getTransactionReceipt(txHash);
|
|
4686
|
+
}
|
|
4687
|
+
async callContract(request, blockIdentifier) {
|
|
4688
|
+
return this.provider.callContract(request, blockIdentifier);
|
|
4689
|
+
}
|
|
4690
|
+
async invokeFunction(functionInvocation, details) {
|
|
4691
|
+
return this.provider.invokeFunction(functionInvocation, details);
|
|
4692
|
+
}
|
|
4693
|
+
async deployAccountContract(payload, details) {
|
|
4694
|
+
return this.provider.deployAccountContract(payload, details);
|
|
4695
|
+
}
|
|
4696
|
+
async declareContract(transaction, details) {
|
|
4697
|
+
return this.provider.declareContract(transaction, details);
|
|
4698
|
+
}
|
|
4699
|
+
async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4700
|
+
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
|
|
4701
|
+
}
|
|
4702
|
+
getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4703
|
+
return this.provider.getDeployAccountEstimateFee(
|
|
4704
|
+
transaction,
|
|
4705
|
+
details,
|
|
4706
|
+
blockIdentifier,
|
|
4707
|
+
skipValidate
|
|
4708
|
+
);
|
|
4709
|
+
}
|
|
4710
|
+
async getCode(contractAddress, blockIdentifier) {
|
|
4711
|
+
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
4712
|
+
}
|
|
4713
|
+
async waitForTransaction(txHash, options) {
|
|
4714
|
+
return this.provider.waitForTransaction(txHash, options);
|
|
4715
|
+
}
|
|
4716
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
|
|
4717
|
+
return this.provider.getSimulateTransaction(
|
|
4718
|
+
invocation,
|
|
4719
|
+
invocationDetails,
|
|
4720
|
+
blockIdentifier,
|
|
4721
|
+
skipValidate
|
|
4743
4722
|
);
|
|
4744
4723
|
}
|
|
4724
|
+
async getStateUpdate(blockIdentifier) {
|
|
4725
|
+
return this.provider.getStateUpdate(blockIdentifier);
|
|
4726
|
+
}
|
|
4727
|
+
async getStarkName(address, StarknetIdContract2) {
|
|
4728
|
+
return getStarkName(this, address, StarknetIdContract2);
|
|
4729
|
+
}
|
|
4730
|
+
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4731
|
+
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4732
|
+
}
|
|
4733
|
+
};
|
|
4734
|
+
|
|
4735
|
+
// src/provider/interface.ts
|
|
4736
|
+
var ProviderInterface = class {
|
|
4745
4737
|
};
|
|
4746
4738
|
|
|
4739
|
+
// src/provider/index.ts
|
|
4740
|
+
var defaultProvider = new Provider();
|
|
4741
|
+
|
|
4747
4742
|
// src/contract/default.ts
|
|
4748
4743
|
var splitArgsAndOptions = (args) => {
|
|
4749
4744
|
const options = [
|
|
@@ -4753,13 +4748,14 @@ var splitArgsAndOptions = (args) => {
|
|
|
4753
4748
|
"formatResponse",
|
|
4754
4749
|
"maxFee",
|
|
4755
4750
|
"nonce",
|
|
4756
|
-
"signature"
|
|
4751
|
+
"signature",
|
|
4752
|
+
"addressSalt"
|
|
4757
4753
|
];
|
|
4758
4754
|
const lastArg = args[args.length - 1];
|
|
4759
4755
|
if (typeof lastArg === "object" && options.some((x) => x in lastArg)) {
|
|
4760
4756
|
return { args, options: args.pop() };
|
|
4761
4757
|
}
|
|
4762
|
-
return { args
|
|
4758
|
+
return { args };
|
|
4763
4759
|
};
|
|
4764
4760
|
function buildCall(contract, functionAbi) {
|
|
4765
4761
|
return async function(...args) {
|
|
@@ -4796,20 +4792,20 @@ function buildEstimate(contract, functionAbi) {
|
|
|
4796
4792
|
return contract.estimate(functionAbi.name, args);
|
|
4797
4793
|
};
|
|
4798
4794
|
}
|
|
4799
|
-
|
|
4800
|
-
if (
|
|
4801
|
-
return
|
|
4802
|
-
|
|
4803
|
-
|
|
4795
|
+
function getCalldata(args, callback) {
|
|
4796
|
+
if ("__compiled__" in args)
|
|
4797
|
+
return args;
|
|
4798
|
+
if (Array.isArray(args[0]) && "__compiled__" in args[0])
|
|
4799
|
+
return args[0];
|
|
4800
|
+
return callback();
|
|
4801
|
+
}
|
|
4804
4802
|
var Contract = class {
|
|
4805
|
-
constructor(abi, address, providerOrAccount = defaultProvider
|
|
4806
|
-
this.version = "0";
|
|
4803
|
+
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
4807
4804
|
this.address = address && address.toLowerCase();
|
|
4808
4805
|
this.providerOrAccount = providerOrAccount;
|
|
4809
4806
|
this.callData = new CallData(abi);
|
|
4810
4807
|
this.structs = CallData.getAbiStruct(abi);
|
|
4811
4808
|
this.abi = abi;
|
|
4812
|
-
this.version = cairoVersion;
|
|
4813
4809
|
const options = { enumerable: true, value: {}, writable: false };
|
|
4814
4810
|
Object.defineProperties(this, {
|
|
4815
4811
|
functions: { enumerable: true, value: {}, writable: false },
|
|
@@ -4866,15 +4862,21 @@ var Contract = class {
|
|
|
4866
4862
|
}
|
|
4867
4863
|
return this;
|
|
4868
4864
|
}
|
|
4869
|
-
async call(method, args = [],
|
|
4865
|
+
async call(method, args = [], {
|
|
4866
|
+
parseRequest = true,
|
|
4867
|
+
parseResponse = true,
|
|
4868
|
+
formatResponse = void 0,
|
|
4869
|
+
blockIdentifier = void 0
|
|
4870
|
+
} = {}) {
|
|
4870
4871
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4871
|
-
const
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4872
|
+
const calldata = getCalldata(args, () => {
|
|
4873
|
+
if (parseRequest) {
|
|
4874
|
+
this.callData.validate("CALL", method, args);
|
|
4875
|
+
return this.callData.compile(method, args);
|
|
4876
|
+
}
|
|
4877
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
4878
|
+
return args;
|
|
4879
|
+
});
|
|
4878
4880
|
return this.providerOrAccount.callContract(
|
|
4879
4881
|
{
|
|
4880
4882
|
contractAddress: this.address,
|
|
@@ -4883,25 +4885,25 @@ var Contract = class {
|
|
|
4883
4885
|
},
|
|
4884
4886
|
blockIdentifier
|
|
4885
4887
|
).then((x) => {
|
|
4886
|
-
if (!
|
|
4888
|
+
if (!parseResponse) {
|
|
4887
4889
|
return x.result;
|
|
4888
4890
|
}
|
|
4889
|
-
if (
|
|
4890
|
-
return this.callData.format(method, x.result,
|
|
4891
|
+
if (formatResponse) {
|
|
4892
|
+
return this.callData.format(method, x.result, formatResponse);
|
|
4891
4893
|
}
|
|
4892
4894
|
return this.callData.parse(method, x.result);
|
|
4893
4895
|
});
|
|
4894
4896
|
}
|
|
4895
|
-
invoke(method, args = [],
|
|
4896
|
-
parseRequest: true
|
|
4897
|
-
}) {
|
|
4897
|
+
invoke(method, args = [], { parseRequest = true, maxFee, nonce, signature } = {}) {
|
|
4898
4898
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4899
|
+
const calldata = getCalldata(args, () => {
|
|
4900
|
+
if (parseRequest) {
|
|
4901
|
+
this.callData.validate("INVOKE", method, args);
|
|
4902
|
+
return this.callData.compile(method, args);
|
|
4903
|
+
}
|
|
4904
|
+
console.warn("Invoke skipped parsing but provided rawArgs, possible malfunction request");
|
|
4905
|
+
return args;
|
|
4906
|
+
});
|
|
4905
4907
|
const invocation = {
|
|
4906
4908
|
contractAddress: this.address,
|
|
4907
4909
|
calldata,
|
|
@@ -4909,40 +4911,36 @@ var Contract = class {
|
|
|
4909
4911
|
};
|
|
4910
4912
|
if ("execute" in this.providerOrAccount) {
|
|
4911
4913
|
return this.providerOrAccount.execute(invocation, void 0, {
|
|
4912
|
-
maxFee
|
|
4913
|
-
nonce
|
|
4914
|
+
maxFee,
|
|
4915
|
+
nonce
|
|
4914
4916
|
});
|
|
4915
4917
|
}
|
|
4916
|
-
if (!
|
|
4918
|
+
if (!nonce)
|
|
4917
4919
|
throw new Error(`Nonce is required when invoking a function without an account`);
|
|
4918
|
-
}
|
|
4919
4920
|
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
4920
4921
|
return this.providerOrAccount.invokeFunction(
|
|
4921
4922
|
{
|
|
4922
4923
|
...invocation,
|
|
4923
|
-
signature
|
|
4924
|
+
signature
|
|
4924
4925
|
},
|
|
4925
4926
|
{
|
|
4926
|
-
nonce
|
|
4927
|
+
nonce
|
|
4927
4928
|
}
|
|
4928
4929
|
);
|
|
4929
4930
|
}
|
|
4930
4931
|
async estimate(method, args = []) {
|
|
4931
|
-
var _a;
|
|
4932
4932
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4933
|
-
if (!((
|
|
4933
|
+
if (!getCalldata(args, () => false)) {
|
|
4934
4934
|
this.callData.validate("INVOKE", method, args);
|
|
4935
4935
|
}
|
|
4936
|
-
const invocation = this.
|
|
4936
|
+
const invocation = this.populate(method, args);
|
|
4937
4937
|
if ("estimateInvokeFee" in this.providerOrAccount) {
|
|
4938
4938
|
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
4939
4939
|
}
|
|
4940
4940
|
throw Error("Contract must be connected to the account contract to estimate");
|
|
4941
4941
|
}
|
|
4942
4942
|
populate(method, args = []) {
|
|
4943
|
-
|
|
4944
|
-
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
4945
|
-
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);
|
|
4943
|
+
const calldata = getCalldata(args, () => this.callData.compile(method, args));
|
|
4946
4944
|
return {
|
|
4947
4945
|
contractAddress: this.address,
|
|
4948
4946
|
entrypoint: method,
|
|
@@ -4962,36 +4960,24 @@ var ContractFactory = class {
|
|
|
4962
4960
|
this.compiledContract = compiledContract;
|
|
4963
4961
|
this.account = account;
|
|
4964
4962
|
this.classHash = classHash;
|
|
4965
|
-
this.
|
|
4963
|
+
this.CallData = new CallData(abi);
|
|
4966
4964
|
}
|
|
4967
4965
|
async deploy(...args) {
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
if (typeof arg !== "object")
|
|
4974
|
-
return;
|
|
4975
|
-
if ("addressSalt" in arg) {
|
|
4976
|
-
addressSalt = arg.addressSalt;
|
|
4977
|
-
}
|
|
4978
|
-
if ("parseRequest" in arg) {
|
|
4979
|
-
parseRequest = arg.parseRequest;
|
|
4966
|
+
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
4967
|
+
const constructorCalldata = getCalldata(param, () => {
|
|
4968
|
+
if (options.parseRequest) {
|
|
4969
|
+
this.CallData.validate("DEPLOY", "constructor", param);
|
|
4970
|
+
return this.CallData.compile("constructor", param);
|
|
4980
4971
|
}
|
|
4972
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
4973
|
+
return param;
|
|
4981
4974
|
});
|
|
4982
|
-
if (!parseRequest || ((_a = args[0]) == null ? void 0 : _a.compiled)) {
|
|
4983
|
-
constructorCalldata = args[0];
|
|
4984
|
-
} else {
|
|
4985
|
-
this.callData.validate("DEPLOY", "constructor", args);
|
|
4986
|
-
const { inputs } = this.abi.find((abi) => abi.type === "constructor");
|
|
4987
|
-
constructorCalldata = this.callData.compile(args, inputs);
|
|
4988
|
-
}
|
|
4989
4975
|
const {
|
|
4990
4976
|
deploy: { contract_address, transaction_hash }
|
|
4991
4977
|
} = await this.account.declareAndDeploy({
|
|
4992
4978
|
contract: this.compiledContract,
|
|
4993
4979
|
constructorCalldata,
|
|
4994
|
-
salt: addressSalt
|
|
4980
|
+
salt: options.addressSalt
|
|
4995
4981
|
});
|
|
4996
4982
|
assert(Boolean(contract_address), "Deployment of the contract failed");
|
|
4997
4983
|
const contractInstance = new Contract(
|
|
@@ -5040,19 +5026,13 @@ var transformCallsToMulticallArrays = (calls) => {
|
|
|
5040
5026
|
});
|
|
5041
5027
|
return {
|
|
5042
5028
|
callArray,
|
|
5043
|
-
calldata:
|
|
5029
|
+
calldata: CallData.compile({ calldata })
|
|
5044
5030
|
};
|
|
5045
5031
|
};
|
|
5046
5032
|
var fromCallsToExecuteCalldata = (calls) => {
|
|
5047
5033
|
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
...callArray.map(
|
|
5051
|
-
({ to, selector, data_offset, data_len }) => [to, selector, data_offset, data_len]
|
|
5052
|
-
).flat(),
|
|
5053
|
-
calldata.length.toString(),
|
|
5054
|
-
...calldata
|
|
5055
|
-
];
|
|
5034
|
+
const compiledCalls = CallData.compile({ callArray });
|
|
5035
|
+
return [...compiledCalls, ...calldata];
|
|
5056
5036
|
};
|
|
5057
5037
|
var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
|
|
5058
5038
|
return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
|
|
@@ -5061,20 +5041,16 @@ var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
|
5061
5041
|
const callArray = calls.map((call) => ({
|
|
5062
5042
|
to: toBigInt(call.contractAddress).toString(10),
|
|
5063
5043
|
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
5064
|
-
calldata:
|
|
5044
|
+
calldata: CallData.compile(call.calldata || [])
|
|
5065
5045
|
}));
|
|
5066
5046
|
return callArray;
|
|
5067
5047
|
};
|
|
5068
5048
|
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
5069
|
-
|
|
5070
|
-
return [
|
|
5071
|
-
callArray.length.toString(),
|
|
5072
|
-
...callArray.map(({ to, selector, calldata }) => [to, selector, calldata.length.toString(), ...calldata]).flat()
|
|
5073
|
-
];
|
|
5049
|
+
return CallData.compile({ calls });
|
|
5074
5050
|
};
|
|
5075
5051
|
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
5076
5052
|
if (cairoVersion === "1") {
|
|
5077
|
-
return
|
|
5053
|
+
return CallData.compile({ calls });
|
|
5078
5054
|
}
|
|
5079
5055
|
return fromCallsToExecuteCalldata(calls);
|
|
5080
5056
|
};
|
|
@@ -5619,7 +5595,7 @@ var Account = class extends Provider {
|
|
|
5619
5595
|
unique = true,
|
|
5620
5596
|
constructorCalldata = []
|
|
5621
5597
|
} = it;
|
|
5622
|
-
const compiledConstructorCallData =
|
|
5598
|
+
const compiledConstructorCallData = CallData.compile(constructorCalldata);
|
|
5623
5599
|
const deploySalt = salt ?? randomAddress();
|
|
5624
5600
|
return {
|
|
5625
5601
|
call: {
|
|
@@ -5643,7 +5619,10 @@ var Account = class extends Provider {
|
|
|
5643
5619
|
});
|
|
5644
5620
|
const calls = params.map((it) => it.call);
|
|
5645
5621
|
const addresses = params.map((it) => it.address);
|
|
5646
|
-
const invokeResponse = await this.execute(calls, void 0,
|
|
5622
|
+
const invokeResponse = await this.execute(calls, void 0, {
|
|
5623
|
+
...details,
|
|
5624
|
+
cairoVersion: "0"
|
|
5625
|
+
});
|
|
5647
5626
|
return {
|
|
5648
5627
|
...invokeResponse,
|
|
5649
5628
|
contract_address: addresses
|
|
@@ -5677,7 +5656,8 @@ var Account = class extends Provider {
|
|
|
5677
5656
|
const version = toBigInt(transactionVersion);
|
|
5678
5657
|
const nonce = ZERO;
|
|
5679
5658
|
const chainId = await this.getChainId();
|
|
5680
|
-
const
|
|
5659
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5660
|
+
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5681
5661
|
const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
5682
5662
|
{
|
|
5683
5663
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
@@ -5715,7 +5695,7 @@ var Account = class extends Provider {
|
|
|
5715
5695
|
await this.callContract({
|
|
5716
5696
|
contractAddress: this.address,
|
|
5717
5697
|
entrypoint: "isValidSignature",
|
|
5718
|
-
calldata:
|
|
5698
|
+
calldata: CallData.compile({
|
|
5719
5699
|
hash: toBigInt(hash).toString(),
|
|
5720
5700
|
signature: formatSignature(signature)
|
|
5721
5701
|
})
|
|
@@ -5775,7 +5755,8 @@ var Account = class extends Provider {
|
|
|
5775
5755
|
constructorCalldata = [],
|
|
5776
5756
|
contractAddress: providedContractAddress
|
|
5777
5757
|
}, { nonce, chainId, version, maxFee }) {
|
|
5778
|
-
const
|
|
5758
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5759
|
+
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5779
5760
|
const signature = await this.signer.signDeployAccountTransaction({
|
|
5780
5761
|
classHash,
|
|
5781
5762
|
contractAddress,
|
|
@@ -5801,7 +5782,7 @@ var Account = class extends Provider {
|
|
|
5801
5782
|
unique = true,
|
|
5802
5783
|
constructorCalldata = []
|
|
5803
5784
|
} = it;
|
|
5804
|
-
const compiledConstructorCallData =
|
|
5785
|
+
const compiledConstructorCallData = CallData.compile(constructorCalldata);
|
|
5805
5786
|
return {
|
|
5806
5787
|
contractAddress: UDC.ADDRESS,
|
|
5807
5788
|
entrypoint: UDC.ENTRYPOINT,
|
|
@@ -5918,6 +5899,7 @@ var number = num_exports;
|
|
|
5918
5899
|
encode,
|
|
5919
5900
|
fixProto,
|
|
5920
5901
|
fixStack,
|
|
5902
|
+
getCalldata,
|
|
5921
5903
|
getChecksumAddress,
|
|
5922
5904
|
hash,
|
|
5923
5905
|
isUrl,
|
|
@@ -5926,6 +5908,7 @@ var number = num_exports;
|
|
|
5926
5908
|
num,
|
|
5927
5909
|
number,
|
|
5928
5910
|
shortString,
|
|
5911
|
+
splitArgsAndOptions,
|
|
5929
5912
|
stark,
|
|
5930
5913
|
starknetId,
|
|
5931
5914
|
transaction,
|