starknet 5.6.1 → 5.8.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 +21 -0
- package/dist/index.d.ts +140 -100
- package/dist/index.global.js +1040 -1043
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1043 -1043
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1040 -1043
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2479,6 +2479,9 @@ function felt(it) {
|
|
|
2479
2479
|
if (typeof it === "string" && isStringWholeNumber(it)) {
|
|
2480
2480
|
return it;
|
|
2481
2481
|
}
|
|
2482
|
+
if (typeof it === "boolean") {
|
|
2483
|
+
return `${+it}`;
|
|
2484
|
+
}
|
|
2482
2485
|
throw new Error(`${it} can't be computed by felt()`);
|
|
2483
2486
|
}
|
|
2484
2487
|
|
|
@@ -2765,7 +2768,6 @@ function extractContractHashes(payload) {
|
|
|
2765
2768
|
// src/utils/stark.ts
|
|
2766
2769
|
var stark_exports = {};
|
|
2767
2770
|
__export(stark_exports, {
|
|
2768
|
-
compileCalldata: () => compileCalldata,
|
|
2769
2771
|
compressProgram: () => compressProgram,
|
|
2770
2772
|
estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
|
|
2771
2773
|
formatSignature: () => formatSignature,
|
|
@@ -2807,21 +2809,6 @@ function signatureToDecimalArray(sig) {
|
|
|
2807
2809
|
function signatureToHexArray(sig) {
|
|
2808
2810
|
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
2809
2811
|
}
|
|
2810
|
-
function compileCalldata(args) {
|
|
2811
|
-
const compiledData = Object.values(args).flatMap((value) => {
|
|
2812
|
-
if (Array.isArray(value))
|
|
2813
|
-
return [toBigInt(value.length).toString(), ...value.map((x) => toBigInt(x).toString())];
|
|
2814
|
-
if (typeof value === "object" && "type" in value)
|
|
2815
|
-
return Object.entries(value).filter(([k]) => k !== "type").map(([, v]) => toBigInt(v).toString());
|
|
2816
|
-
return toBigInt(value).toString();
|
|
2817
|
-
});
|
|
2818
|
-
Object.defineProperty(compiledData, "compiled", {
|
|
2819
|
-
enumerable: false,
|
|
2820
|
-
writable: false,
|
|
2821
|
-
value: true
|
|
2822
|
-
});
|
|
2823
|
-
return compiledData;
|
|
2824
|
-
}
|
|
2825
2812
|
function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
|
|
2826
2813
|
const overHeadPercent = Math.round((1 + overhead) * 100);
|
|
2827
2814
|
return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
|
|
@@ -2935,308 +2922,826 @@ var HttpError = class extends LibraryError {
|
|
|
2935
2922
|
}
|
|
2936
2923
|
};
|
|
2937
2924
|
|
|
2938
|
-
// src/utils/
|
|
2939
|
-
var
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
str = str.substring(0, str.length - 1);
|
|
2949
|
-
k += 1;
|
|
2925
|
+
// src/utils/calldata/formatter.ts
|
|
2926
|
+
var guard = {
|
|
2927
|
+
isBN: (data, type, key) => {
|
|
2928
|
+
if (!isBigInt(data[key]))
|
|
2929
|
+
throw new Error(
|
|
2930
|
+
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
2931
|
+
);
|
|
2932
|
+
},
|
|
2933
|
+
unknown: (data, type, key) => {
|
|
2934
|
+
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
2950
2935
|
}
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
subdomain /= basicSizePlusOne;
|
|
2959
|
-
if (code === BigInt(basicAlphabet.length)) {
|
|
2960
|
-
const nextSubdomain = subdomain / bigAlphabetSizePlusOne;
|
|
2961
|
-
if (nextSubdomain === ZERO) {
|
|
2962
|
-
const code2 = subdomain % bigAlphabetSizePlusOne;
|
|
2963
|
-
subdomain = nextSubdomain;
|
|
2964
|
-
if (code2 === ZERO)
|
|
2965
|
-
decoded += basicAlphabet[0];
|
|
2966
|
-
else
|
|
2967
|
-
decoded += bigAlphabet[Number(code2) - 1];
|
|
2968
|
-
} else {
|
|
2969
|
-
const code2 = subdomain % bigAlphabetSize;
|
|
2970
|
-
decoded += bigAlphabet[Number(code2)];
|
|
2971
|
-
subdomain /= bigAlphabetSize;
|
|
2972
|
-
}
|
|
2973
|
-
} else
|
|
2974
|
-
decoded += basicAlphabet[Number(code)];
|
|
2936
|
+
};
|
|
2937
|
+
function formatter(data, type, sameType) {
|
|
2938
|
+
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
2939
|
+
const elType = sameType ?? type[key];
|
|
2940
|
+
if (!(key in type) && !sameType) {
|
|
2941
|
+
acc[key] = value;
|
|
2942
|
+
return acc;
|
|
2975
2943
|
}
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2944
|
+
if (elType === "string") {
|
|
2945
|
+
if (Array.isArray(data[key])) {
|
|
2946
|
+
const arrayStr = formatter(
|
|
2947
|
+
data[key],
|
|
2948
|
+
data[key].map((_) => elType)
|
|
2949
|
+
);
|
|
2950
|
+
acc[key] = Object.values(arrayStr).join("");
|
|
2951
|
+
return acc;
|
|
2952
|
+
}
|
|
2953
|
+
guard.isBN(data, type, key);
|
|
2954
|
+
acc[key] = decodeShortString(value);
|
|
2955
|
+
return acc;
|
|
2956
|
+
}
|
|
2957
|
+
if (elType === "number") {
|
|
2958
|
+
guard.isBN(data, type, key);
|
|
2959
|
+
acc[key] = Number(value);
|
|
2960
|
+
return acc;
|
|
2961
|
+
}
|
|
2962
|
+
if (typeof elType === "function") {
|
|
2963
|
+
acc[key] = elType(value);
|
|
2964
|
+
return acc;
|
|
2965
|
+
}
|
|
2966
|
+
if (Array.isArray(elType)) {
|
|
2967
|
+
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
2968
|
+
acc[key] = Object.values(arrayObj);
|
|
2969
|
+
return acc;
|
|
2970
|
+
}
|
|
2971
|
+
if (typeof elType === "object") {
|
|
2972
|
+
acc[key] = formatter(data[key], elType);
|
|
2973
|
+
return acc;
|
|
2974
|
+
}
|
|
2975
|
+
guard.unknown(data, type, key);
|
|
2976
|
+
return acc;
|
|
2977
|
+
}, {});
|
|
2985
2978
|
}
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
2979
|
+
|
|
2980
|
+
// src/utils/calldata/tuple.ts
|
|
2981
|
+
function parseNamedTuple(namedTuple) {
|
|
2982
|
+
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
2983
|
+
const type = namedTuple.substring(name.length + ":".length);
|
|
2984
|
+
return { name, type };
|
|
2985
|
+
}
|
|
2986
|
+
function parseSubTuple(s) {
|
|
2987
|
+
if (!s.includes("("))
|
|
2988
|
+
return { subTuple: [], result: s };
|
|
2989
|
+
const subTuple = [];
|
|
2990
|
+
let result = "";
|
|
2991
|
+
let i = 0;
|
|
2992
|
+
while (i < s.length) {
|
|
2993
|
+
if (s[i] === "(") {
|
|
2994
|
+
let counter = 1;
|
|
2995
|
+
const lBracket = i;
|
|
2996
|
+
i++;
|
|
2997
|
+
while (counter) {
|
|
2998
|
+
if (s[i] === ")")
|
|
2999
|
+
counter--;
|
|
3000
|
+
if (s[i] === "(")
|
|
3001
|
+
counter++;
|
|
3002
|
+
i++;
|
|
3009
3003
|
}
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
multiplier *= bigAlphabetSize;
|
|
3004
|
+
subTuple.push(s.substring(lBracket, i));
|
|
3005
|
+
result += " ";
|
|
3006
|
+
i--;
|
|
3007
|
+
} else {
|
|
3008
|
+
result += s[i];
|
|
3016
3009
|
}
|
|
3010
|
+
i++;
|
|
3017
3011
|
}
|
|
3018
|
-
return
|
|
3012
|
+
return {
|
|
3013
|
+
subTuple,
|
|
3014
|
+
result
|
|
3015
|
+
};
|
|
3019
3016
|
}
|
|
3020
|
-
function
|
|
3021
|
-
const
|
|
3022
|
-
const
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3017
|
+
function extractCairo0Tuple(type) {
|
|
3018
|
+
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
3019
|
+
const { subTuple, result } = parseSubTuple(cleanType);
|
|
3020
|
+
let recomposed = result.split(",").map((it) => {
|
|
3021
|
+
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
3022
|
+
});
|
|
3023
|
+
if (isTypeNamedTuple(type)) {
|
|
3024
|
+
recomposed = recomposed.reduce((acc, it) => {
|
|
3025
|
+
return acc.concat(parseNamedTuple(it));
|
|
3026
|
+
}, []);
|
|
3030
3027
|
}
|
|
3028
|
+
return recomposed;
|
|
3031
3029
|
}
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
const chainId = await provider.getChainId();
|
|
3036
|
-
const contract = StarknetIdContract ?? getStarknetIdContract(chainId);
|
|
3037
|
-
try {
|
|
3038
|
-
const hexDomain = await provider.callContract({
|
|
3039
|
-
contractAddress: contract,
|
|
3040
|
-
entrypoint: "address_to_domain",
|
|
3041
|
-
calldata: compileCalldata({
|
|
3042
|
-
address
|
|
3043
|
-
})
|
|
3044
|
-
});
|
|
3045
|
-
const decimalDomain = hexDomain.result.map((element) => BigInt(element)).slice(1);
|
|
3046
|
-
const stringDomain = useDecoded(decimalDomain);
|
|
3047
|
-
if (!stringDomain) {
|
|
3048
|
-
throw Error("Starkname not found");
|
|
3049
|
-
}
|
|
3050
|
-
return stringDomain;
|
|
3051
|
-
} catch (e) {
|
|
3052
|
-
if (e instanceof Error && e.message === "Starkname not found") {
|
|
3053
|
-
throw e;
|
|
3054
|
-
}
|
|
3055
|
-
throw Error("Could not get stark name");
|
|
3056
|
-
}
|
|
3030
|
+
function extractCairo1Tuple(type) {
|
|
3031
|
+
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
3032
|
+
return cleanType.split(",");
|
|
3057
3033
|
}
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
try {
|
|
3062
|
-
const addressData = await provider.callContract({
|
|
3063
|
-
contractAddress: contract,
|
|
3064
|
-
entrypoint: "domain_to_address",
|
|
3065
|
-
calldata: compileCalldata({
|
|
3066
|
-
domain: [useEncoded(name.replace(".stark", "")).toString(10)]
|
|
3067
|
-
})
|
|
3068
|
-
});
|
|
3069
|
-
return addressData.result[0];
|
|
3070
|
-
} catch {
|
|
3071
|
-
throw Error("Could not get address from stark name");
|
|
3034
|
+
function extractTupleMemberTypes(type) {
|
|
3035
|
+
if (isCairo1Type(type)) {
|
|
3036
|
+
return extractCairo1Tuple(type);
|
|
3072
3037
|
}
|
|
3038
|
+
return extractCairo0Tuple(type);
|
|
3073
3039
|
}
|
|
3074
3040
|
|
|
3075
|
-
// src/
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
}
|
|
3086
|
-
setIdentifier(__identifier) {
|
|
3087
|
-
if (typeof __identifier === "string" && isHex(__identifier)) {
|
|
3088
|
-
this.hash = __identifier;
|
|
3089
|
-
} else if (typeof __identifier === "bigint") {
|
|
3090
|
-
this.hash = toHex(__identifier);
|
|
3091
|
-
} else if (typeof __identifier === "number") {
|
|
3092
|
-
this.number = __identifier;
|
|
3093
|
-
} else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
|
|
3094
|
-
this.tag = __identifier;
|
|
3095
|
-
} else {
|
|
3096
|
-
this.tag = "pending";
|
|
3097
|
-
}
|
|
3041
|
+
// src/utils/calldata/requestParser.ts
|
|
3042
|
+
function parseTuple(element, typeStr) {
|
|
3043
|
+
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
3044
|
+
const elements = Object.values(element);
|
|
3045
|
+
if (elements.length !== memberTypes.length) {
|
|
3046
|
+
throw Error(
|
|
3047
|
+
`ParseTuple: provided and expected abi tuple size do not match.
|
|
3048
|
+
provided: ${elements}
|
|
3049
|
+
expected: ${memberTypes}`
|
|
3050
|
+
);
|
|
3098
3051
|
}
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
if (this.number !== null) {
|
|
3110
|
-
return { block_number: this.number };
|
|
3111
|
-
}
|
|
3112
|
-
if (this.hash !== null) {
|
|
3113
|
-
return { block_hash: this.hash };
|
|
3114
|
-
}
|
|
3115
|
-
return this.tag;
|
|
3052
|
+
return memberTypes.map((it, dx) => {
|
|
3053
|
+
return {
|
|
3054
|
+
element: elements[dx],
|
|
3055
|
+
type: it.type ?? it
|
|
3056
|
+
};
|
|
3057
|
+
});
|
|
3058
|
+
}
|
|
3059
|
+
function parseCalldataValue(element, type, structs) {
|
|
3060
|
+
if (element === void 0) {
|
|
3061
|
+
throw Error(`Missing parameter for type ${type}`);
|
|
3116
3062
|
}
|
|
3117
|
-
|
|
3118
|
-
|
|
3063
|
+
if (Array.isArray(element)) {
|
|
3064
|
+
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
3119
3065
|
}
|
|
3120
|
-
|
|
3121
|
-
|
|
3066
|
+
if (isTypeUint256(type)) {
|
|
3067
|
+
const el_uint256 = uint256(element);
|
|
3068
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
3122
3069
|
}
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
retries: 200
|
|
3130
|
-
};
|
|
3131
|
-
var RpcProvider = class {
|
|
3132
|
-
constructor(optionsOrProvider) {
|
|
3133
|
-
this.responseParser = new RPCResponseParser();
|
|
3134
|
-
const { nodeUrl, retries, headers, blockIdentifier } = optionsOrProvider;
|
|
3135
|
-
this.nodeUrl = nodeUrl;
|
|
3136
|
-
this.retries = retries || defaultOptions.retries;
|
|
3137
|
-
this.headers = { ...defaultOptions.headers, ...headers };
|
|
3138
|
-
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
|
|
3139
|
-
this.getChainId();
|
|
3070
|
+
if (structs[type] && structs[type].members.length) {
|
|
3071
|
+
const { members } = structs[type];
|
|
3072
|
+
const subElement = element;
|
|
3073
|
+
return members.reduce((acc, it) => {
|
|
3074
|
+
return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs));
|
|
3075
|
+
}, []);
|
|
3140
3076
|
}
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
});
|
|
3077
|
+
if (isTypeTuple(type)) {
|
|
3078
|
+
const tupled = parseTuple(element, type);
|
|
3079
|
+
return tupled.reduce((acc, it) => {
|
|
3080
|
+
const parsedData = parseCalldataValue(it.element, it.type, structs);
|
|
3081
|
+
return acc.concat(parsedData);
|
|
3082
|
+
}, []);
|
|
3147
3083
|
}
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
const { code, message } = error;
|
|
3151
|
-
throw new LibraryError(`${code}: ${message}`);
|
|
3152
|
-
}
|
|
3084
|
+
if (typeof element === "object") {
|
|
3085
|
+
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
3153
3086
|
}
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3087
|
+
return felt(element);
|
|
3088
|
+
}
|
|
3089
|
+
function parseCalldataField(argsIterator, input, structs) {
|
|
3090
|
+
const { name, type } = input;
|
|
3091
|
+
let { value } = argsIterator.next();
|
|
3092
|
+
switch (true) {
|
|
3093
|
+
case isTypeArray(type):
|
|
3094
|
+
if (!Array.isArray(value) && !isText(value)) {
|
|
3095
|
+
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
3096
|
+
}
|
|
3097
|
+
if (typeof value === "string") {
|
|
3098
|
+
value = splitLongString(value);
|
|
3099
|
+
}
|
|
3100
|
+
const result = [];
|
|
3101
|
+
result.push(felt(value.length));
|
|
3102
|
+
const arrayType = getArrayType(input.type);
|
|
3103
|
+
return value.reduce((acc, el) => {
|
|
3104
|
+
if (isTypeFelt(arrayType) || isTypeUint(arrayType) || isTypeContractAddress(arrayType)) {
|
|
3105
|
+
acc.push(felt(el));
|
|
3106
|
+
} else if (isTypeBool(arrayType) && typeof el === "boolean") {
|
|
3107
|
+
acc.push(el.toString());
|
|
3108
|
+
} else {
|
|
3109
|
+
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
3110
|
+
}
|
|
3111
|
+
return acc;
|
|
3112
|
+
}, result);
|
|
3113
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
|
|
3114
|
+
return parseCalldataValue(value, type, structs);
|
|
3115
|
+
case isTypeBool(type):
|
|
3116
|
+
return `${+value}`;
|
|
3117
|
+
default:
|
|
3118
|
+
return felt(value);
|
|
3165
3119
|
}
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
// src/utils/calldata/responseParser.ts
|
|
3123
|
+
function parseResponseStruct(responseIterator, type, structs) {
|
|
3124
|
+
if (type in structs && structs[type]) {
|
|
3125
|
+
return structs[type].members.reduce((acc, el) => {
|
|
3126
|
+
acc[el.name] = parseResponseStruct(responseIterator, el.type, structs);
|
|
3127
|
+
return acc;
|
|
3128
|
+
}, {});
|
|
3169
3129
|
}
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3130
|
+
if (isTypeTuple(type)) {
|
|
3131
|
+
const memberTypes = extractTupleMemberTypes(type);
|
|
3132
|
+
return memberTypes.reduce((acc, it, idx) => {
|
|
3133
|
+
const tName = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
3134
|
+
const tType = (it == null ? void 0 : it.type) ? it.type : it;
|
|
3135
|
+
acc[tName] = parseResponseStruct(responseIterator, tType, structs);
|
|
3136
|
+
return acc;
|
|
3137
|
+
}, {});
|
|
3174
3138
|
}
|
|
3175
|
-
|
|
3176
|
-
|
|
3139
|
+
const temp = responseIterator.next().value;
|
|
3140
|
+
return BigInt(temp);
|
|
3141
|
+
}
|
|
3142
|
+
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
3143
|
+
const { name, type } = output;
|
|
3144
|
+
let temp;
|
|
3145
|
+
switch (true) {
|
|
3146
|
+
case isLen(name):
|
|
3147
|
+
temp = responseIterator.next().value;
|
|
3148
|
+
return BigInt(temp);
|
|
3149
|
+
case isTypeBool(type):
|
|
3150
|
+
temp = responseIterator.next().value;
|
|
3151
|
+
return Boolean(BigInt(temp));
|
|
3152
|
+
case isTypeUint256(type):
|
|
3153
|
+
const low = responseIterator.next().value;
|
|
3154
|
+
const high = responseIterator.next().value;
|
|
3155
|
+
return uint256ToBN({ low, high });
|
|
3156
|
+
case isTypeArray(type):
|
|
3157
|
+
const parsedDataArr = [];
|
|
3158
|
+
if (isCairo1Type(type)) {
|
|
3159
|
+
responseIterator.next();
|
|
3160
|
+
let it = responseIterator.next();
|
|
3161
|
+
while (!it.done) {
|
|
3162
|
+
parsedDataArr.push(BigInt(it.value));
|
|
3163
|
+
it = responseIterator.next();
|
|
3164
|
+
}
|
|
3165
|
+
return parsedDataArr;
|
|
3166
|
+
}
|
|
3167
|
+
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
3168
|
+
const arrLen = parsedResult[`${name}_len`];
|
|
3169
|
+
while (parsedDataArr.length < arrLen) {
|
|
3170
|
+
parsedDataArr.push(
|
|
3171
|
+
parseResponseStruct(responseIterator, output.type.replace("*", ""), structs)
|
|
3172
|
+
);
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
return parsedDataArr;
|
|
3176
|
+
case (type in structs || isTypeTuple(type)):
|
|
3177
|
+
return parseResponseStruct(responseIterator, type, structs);
|
|
3178
|
+
default:
|
|
3179
|
+
temp = responseIterator.next().value;
|
|
3180
|
+
return BigInt(temp);
|
|
3177
3181
|
}
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3182
|
+
}
|
|
3183
|
+
|
|
3184
|
+
// src/utils/calldata/validate.ts
|
|
3185
|
+
var validateFelt = (parameter, input) => {
|
|
3186
|
+
assert(
|
|
3187
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
3188
|
+
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
3189
|
+
);
|
|
3190
|
+
};
|
|
3191
|
+
var validateUint = (parameter, input) => {
|
|
3192
|
+
if (typeof parameter === "number") {
|
|
3193
|
+
assert(
|
|
3194
|
+
parameter <= Number.MAX_SAFE_INTEGER,
|
|
3195
|
+
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
3196
|
+
);
|
|
3181
3197
|
}
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3198
|
+
assert(
|
|
3199
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
3200
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
|
|
3201
|
+
);
|
|
3202
|
+
const param = toBigInt(parameter);
|
|
3203
|
+
switch (input.type) {
|
|
3204
|
+
case "core::integer::u8" /* u8 */:
|
|
3205
|
+
assert(
|
|
3206
|
+
param >= 0n && param <= 255n,
|
|
3207
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
3208
|
+
);
|
|
3209
|
+
break;
|
|
3210
|
+
case "core::integer::u16" /* u16 */:
|
|
3211
|
+
assert(
|
|
3212
|
+
param >= 0n && param <= 65535n,
|
|
3213
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
3214
|
+
);
|
|
3215
|
+
break;
|
|
3216
|
+
case "core::integer::u32" /* u32 */:
|
|
3217
|
+
assert(
|
|
3218
|
+
param >= 0n && param <= 4294967295n,
|
|
3219
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
3220
|
+
);
|
|
3221
|
+
break;
|
|
3222
|
+
case "core::integer::u64" /* u64 */:
|
|
3223
|
+
assert(
|
|
3224
|
+
param >= 0n && param <= 2n ** 64n - 1n,
|
|
3225
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
3226
|
+
);
|
|
3227
|
+
break;
|
|
3228
|
+
case "core::integer::u128" /* u128 */:
|
|
3229
|
+
assert(
|
|
3230
|
+
param >= 0n && param <= 2n ** 128n - 1n,
|
|
3231
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
3232
|
+
);
|
|
3233
|
+
break;
|
|
3234
|
+
case "core::integer::u256" /* u256 */:
|
|
3235
|
+
assert(
|
|
3236
|
+
param >= 0n && param <= 2n ** 256n - 1n,
|
|
3237
|
+
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
3238
|
+
);
|
|
3239
|
+
break;
|
|
3240
|
+
default:
|
|
3241
|
+
break;
|
|
3185
3242
|
}
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3243
|
+
};
|
|
3244
|
+
var validateBool = (parameter, input) => {
|
|
3245
|
+
assert(
|
|
3246
|
+
typeof parameter === "boolean",
|
|
3247
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
3248
|
+
);
|
|
3249
|
+
};
|
|
3250
|
+
var validateStruct = (parameter, input, structs) => {
|
|
3251
|
+
assert(
|
|
3252
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
3253
|
+
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
3254
|
+
);
|
|
3255
|
+
structs[input.type].members.forEach(({ name }) => {
|
|
3256
|
+
assert(
|
|
3257
|
+
Object.keys(parameter).includes(name),
|
|
3258
|
+
`Validate: arg ${input.name} should have a property ${name}`
|
|
3259
|
+
);
|
|
3260
|
+
});
|
|
3261
|
+
};
|
|
3262
|
+
var validateTuple = (parameter, input) => {
|
|
3263
|
+
assert(
|
|
3264
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
3265
|
+
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
3266
|
+
);
|
|
3267
|
+
};
|
|
3268
|
+
var validateArray = (parameter, input, structs) => {
|
|
3269
|
+
const baseType = getArrayType(input.type);
|
|
3270
|
+
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
3271
|
+
return;
|
|
3272
|
+
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
3273
|
+
switch (true) {
|
|
3274
|
+
case isTypeFelt(baseType):
|
|
3275
|
+
parameter.forEach((param) => validateFelt(param, input));
|
|
3276
|
+
break;
|
|
3277
|
+
case isTypeTuple(baseType):
|
|
3278
|
+
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
3279
|
+
break;
|
|
3280
|
+
case isTypeStruct(baseType, structs):
|
|
3281
|
+
parameter.forEach(
|
|
3282
|
+
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
3283
|
+
);
|
|
3284
|
+
break;
|
|
3285
|
+
case isTypeUint(baseType):
|
|
3286
|
+
parameter.forEach((param) => validateUint(param, input));
|
|
3287
|
+
break;
|
|
3288
|
+
case isTypeBool(baseType):
|
|
3289
|
+
parameter.forEach((param) => validateBool(param, input));
|
|
3290
|
+
break;
|
|
3291
|
+
default:
|
|
3292
|
+
throw new Error(
|
|
3293
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
3294
|
+
);
|
|
3199
3295
|
}
|
|
3200
|
-
|
|
3201
|
-
|
|
3296
|
+
};
|
|
3297
|
+
function validateFields(abiMethod, args, structs) {
|
|
3298
|
+
abiMethod.inputs.reduce((acc, input) => {
|
|
3299
|
+
const parameter = args[acc];
|
|
3300
|
+
switch (true) {
|
|
3301
|
+
case isLen(input.name):
|
|
3302
|
+
return acc;
|
|
3303
|
+
case isTypeFelt(input.type):
|
|
3304
|
+
validateFelt(parameter, input);
|
|
3305
|
+
break;
|
|
3306
|
+
case isTypeUint(input.type):
|
|
3307
|
+
validateUint(parameter, input);
|
|
3308
|
+
break;
|
|
3309
|
+
case isTypeBool(input.type):
|
|
3310
|
+
validateBool(parameter, input);
|
|
3311
|
+
break;
|
|
3312
|
+
case isTypeContractAddress(input.type):
|
|
3313
|
+
break;
|
|
3314
|
+
case isTypeStruct(input.type, structs):
|
|
3315
|
+
validateStruct(parameter, input, structs);
|
|
3316
|
+
break;
|
|
3317
|
+
case isTypeTuple(input.type):
|
|
3318
|
+
validateTuple(parameter, input);
|
|
3319
|
+
break;
|
|
3320
|
+
case isTypeArray(input.type):
|
|
3321
|
+
validateArray(parameter, input, structs);
|
|
3322
|
+
break;
|
|
3323
|
+
default:
|
|
3324
|
+
throw new Error(
|
|
3325
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
3326
|
+
);
|
|
3327
|
+
}
|
|
3328
|
+
return acc + 1;
|
|
3329
|
+
}, 0);
|
|
3330
|
+
}
|
|
3331
|
+
|
|
3332
|
+
// src/utils/calldata/index.ts
|
|
3333
|
+
var CallData = class {
|
|
3334
|
+
constructor(abi) {
|
|
3335
|
+
this.abi = abi;
|
|
3336
|
+
this.structs = CallData.getAbiStruct(abi);
|
|
3202
3337
|
}
|
|
3203
|
-
|
|
3204
|
-
|
|
3338
|
+
validate(type, method, args = []) {
|
|
3339
|
+
if (type !== "DEPLOY") {
|
|
3340
|
+
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
3341
|
+
if (abi.type !== "function")
|
|
3342
|
+
return false;
|
|
3343
|
+
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
3344
|
+
return type === "INVOKE" ? !isView : isView;
|
|
3345
|
+
}).map((abi) => abi.name);
|
|
3346
|
+
assert(
|
|
3347
|
+
invocableFunctionNames.includes(method),
|
|
3348
|
+
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
3349
|
+
);
|
|
3350
|
+
}
|
|
3351
|
+
const abiMethod = this.abi.find(
|
|
3352
|
+
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
3353
|
+
);
|
|
3354
|
+
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
3355
|
+
if (args.length !== inputsLength) {
|
|
3356
|
+
throw Error(
|
|
3357
|
+
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
3358
|
+
);
|
|
3359
|
+
}
|
|
3360
|
+
validateFields(abiMethod, args, this.structs);
|
|
3205
3361
|
}
|
|
3206
|
-
|
|
3207
|
-
const
|
|
3208
|
-
|
|
3362
|
+
compile(method, args) {
|
|
3363
|
+
const argsIterator = args[Symbol.iterator]();
|
|
3364
|
+
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
3365
|
+
return inputs.reduce(
|
|
3366
|
+
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
3367
|
+
[]
|
|
3368
|
+
);
|
|
3209
3369
|
}
|
|
3210
|
-
|
|
3211
|
-
const
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3370
|
+
static compile(rawArgs) {
|
|
3371
|
+
const createTree = (obj) => {
|
|
3372
|
+
const getEntries = (o, prefix = "") => {
|
|
3373
|
+
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
3374
|
+
return Object.entries(oe).flatMap(([k, v]) => {
|
|
3375
|
+
let value = v;
|
|
3376
|
+
if (isLongText(value))
|
|
3377
|
+
value = splitLongString(value);
|
|
3378
|
+
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
3379
|
+
if (isBigInt(value))
|
|
3380
|
+
return [[`${prefix}${kk}`, felt(value)]];
|
|
3381
|
+
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
3382
|
+
});
|
|
3383
|
+
};
|
|
3384
|
+
return Object.fromEntries(getEntries(obj));
|
|
3385
|
+
};
|
|
3386
|
+
let callTreeArray;
|
|
3387
|
+
if (!Array.isArray(rawArgs)) {
|
|
3388
|
+
const callTree = createTree(rawArgs);
|
|
3389
|
+
callTreeArray = Object.values(callTree);
|
|
3390
|
+
} else {
|
|
3391
|
+
const callObj = { ...rawArgs };
|
|
3392
|
+
const callTree = createTree(callObj);
|
|
3393
|
+
callTreeArray = Object.values(callTree);
|
|
3394
|
+
}
|
|
3395
|
+
Object.defineProperty(callTreeArray, "__compiled__", {
|
|
3396
|
+
enumerable: false,
|
|
3397
|
+
writable: false,
|
|
3398
|
+
value: true
|
|
3217
3399
|
});
|
|
3400
|
+
return callTreeArray;
|
|
3218
3401
|
}
|
|
3219
|
-
|
|
3220
|
-
|
|
3402
|
+
parse(method, response) {
|
|
3403
|
+
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
3404
|
+
const responseIterator = response.flat()[Symbol.iterator]();
|
|
3405
|
+
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
3406
|
+
const propName = output.name ?? idx;
|
|
3407
|
+
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
3408
|
+
if (acc[propName] && acc[`${propName}_len`]) {
|
|
3409
|
+
delete acc[`${propName}_len`];
|
|
3410
|
+
}
|
|
3411
|
+
return acc;
|
|
3412
|
+
}, {});
|
|
3413
|
+
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
3221
3414
|
}
|
|
3222
|
-
|
|
3223
|
-
|
|
3415
|
+
format(method, response, format) {
|
|
3416
|
+
const parsed = this.parse(method, response);
|
|
3417
|
+
return formatter(parsed, format);
|
|
3224
3418
|
}
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
|
|
3419
|
+
static abiInputsLength(inputs) {
|
|
3420
|
+
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3228
3421
|
}
|
|
3229
|
-
|
|
3230
|
-
return
|
|
3422
|
+
static getAbiStruct(abi) {
|
|
3423
|
+
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
3424
|
+
(acc, abiEntry) => ({
|
|
3425
|
+
...acc,
|
|
3426
|
+
[abiEntry.name]: abiEntry
|
|
3427
|
+
}),
|
|
3428
|
+
{}
|
|
3429
|
+
);
|
|
3231
3430
|
}
|
|
3232
|
-
|
|
3233
|
-
|
|
3431
|
+
};
|
|
3432
|
+
|
|
3433
|
+
// src/utils/starknetId.ts
|
|
3434
|
+
var starknetId_exports = {};
|
|
3435
|
+
__export(starknetId_exports, {
|
|
3436
|
+
StarknetIdContract: () => StarknetIdContract,
|
|
3437
|
+
getStarknetIdContract: () => getStarknetIdContract,
|
|
3438
|
+
useDecoded: () => useDecoded,
|
|
3439
|
+
useEncoded: () => useEncoded
|
|
3440
|
+
});
|
|
3441
|
+
var basicAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
|
3442
|
+
var basicSizePlusOne = BigInt(basicAlphabet.length + 1);
|
|
3443
|
+
var bigAlphabet = "\u8FD9\u6765";
|
|
3444
|
+
var basicAlphabetSize = BigInt(basicAlphabet.length);
|
|
3445
|
+
var bigAlphabetSize = BigInt(bigAlphabet.length);
|
|
3446
|
+
var bigAlphabetSizePlusOne = BigInt(bigAlphabet.length + 1);
|
|
3447
|
+
function extractStars(str) {
|
|
3448
|
+
let k = 0;
|
|
3449
|
+
while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
|
|
3450
|
+
str = str.substring(0, str.length - 1);
|
|
3451
|
+
k += 1;
|
|
3234
3452
|
}
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3453
|
+
return [str, k];
|
|
3454
|
+
}
|
|
3455
|
+
function useDecoded(encoded) {
|
|
3456
|
+
let decoded = "";
|
|
3457
|
+
encoded.forEach((subdomain) => {
|
|
3458
|
+
while (subdomain !== ZERO) {
|
|
3459
|
+
const code = subdomain % basicSizePlusOne;
|
|
3460
|
+
subdomain /= basicSizePlusOne;
|
|
3461
|
+
if (code === BigInt(basicAlphabet.length)) {
|
|
3462
|
+
const nextSubdomain = subdomain / bigAlphabetSizePlusOne;
|
|
3463
|
+
if (nextSubdomain === ZERO) {
|
|
3464
|
+
const code2 = subdomain % bigAlphabetSizePlusOne;
|
|
3465
|
+
subdomain = nextSubdomain;
|
|
3466
|
+
if (code2 === ZERO)
|
|
3467
|
+
decoded += basicAlphabet[0];
|
|
3468
|
+
else
|
|
3469
|
+
decoded += bigAlphabet[Number(code2) - 1];
|
|
3470
|
+
} else {
|
|
3471
|
+
const code2 = subdomain % bigAlphabetSize;
|
|
3472
|
+
decoded += bigAlphabet[Number(code2)];
|
|
3473
|
+
subdomain /= bigAlphabetSize;
|
|
3474
|
+
}
|
|
3475
|
+
} else
|
|
3476
|
+
decoded += basicAlphabet[Number(code)];
|
|
3477
|
+
}
|
|
3478
|
+
const [str, k] = extractStars(decoded);
|
|
3479
|
+
if (k)
|
|
3480
|
+
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));
|
|
3481
|
+
decoded += ".";
|
|
3482
|
+
});
|
|
3483
|
+
if (!decoded) {
|
|
3484
|
+
return decoded;
|
|
3238
3485
|
}
|
|
3239
|
-
|
|
3486
|
+
return decoded.concat("stark");
|
|
3487
|
+
}
|
|
3488
|
+
function useEncoded(decoded) {
|
|
3489
|
+
let encoded = BigInt(0);
|
|
3490
|
+
let multiplier = BigInt(1);
|
|
3491
|
+
if (decoded.endsWith(bigAlphabet[0] + basicAlphabet[1])) {
|
|
3492
|
+
const [str, k] = extractStars(decoded.substring(0, decoded.length - 2));
|
|
3493
|
+
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
|
|
3494
|
+
} else {
|
|
3495
|
+
const [str, k] = extractStars(decoded);
|
|
3496
|
+
if (k)
|
|
3497
|
+
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
|
|
3498
|
+
}
|
|
3499
|
+
for (let i = 0; i < decoded.length; i += 1) {
|
|
3500
|
+
const char = decoded[i];
|
|
3501
|
+
const index = basicAlphabet.indexOf(char);
|
|
3502
|
+
const bnIndex = BigInt(basicAlphabet.indexOf(char));
|
|
3503
|
+
if (index !== -1) {
|
|
3504
|
+
if (i === decoded.length - 1 && decoded[i] === basicAlphabet[0]) {
|
|
3505
|
+
encoded += multiplier * basicAlphabetSize;
|
|
3506
|
+
multiplier *= basicSizePlusOne;
|
|
3507
|
+
multiplier *= basicSizePlusOne;
|
|
3508
|
+
} else {
|
|
3509
|
+
encoded += multiplier * bnIndex;
|
|
3510
|
+
multiplier *= basicSizePlusOne;
|
|
3511
|
+
}
|
|
3512
|
+
} else if (bigAlphabet.indexOf(char) !== -1) {
|
|
3513
|
+
encoded += multiplier * basicAlphabetSize;
|
|
3514
|
+
multiplier *= basicSizePlusOne;
|
|
3515
|
+
const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
|
|
3516
|
+
encoded += multiplier * BigInt(newid);
|
|
3517
|
+
multiplier *= bigAlphabetSize;
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
return encoded;
|
|
3521
|
+
}
|
|
3522
|
+
var StarknetIdContract = /* @__PURE__ */ ((StarknetIdContract2) => {
|
|
3523
|
+
StarknetIdContract2["MAINNET"] = "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678";
|
|
3524
|
+
StarknetIdContract2["TESTNET"] = "0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce";
|
|
3525
|
+
return StarknetIdContract2;
|
|
3526
|
+
})(StarknetIdContract || {});
|
|
3527
|
+
function getStarknetIdContract(chainId) {
|
|
3528
|
+
switch (chainId) {
|
|
3529
|
+
case "0x534e5f4d41494e" /* SN_MAIN */:
|
|
3530
|
+
return "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678" /* MAINNET */;
|
|
3531
|
+
case "0x534e5f474f45524c49" /* SN_GOERLI */:
|
|
3532
|
+
return "0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce" /* TESTNET */;
|
|
3533
|
+
default:
|
|
3534
|
+
throw new Error("Starknet.id is not yet deployed on this network");
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
// src/provider/starknetId.ts
|
|
3539
|
+
async function getStarkName(provider, address, StarknetIdContract2) {
|
|
3540
|
+
const chainId = await provider.getChainId();
|
|
3541
|
+
const contract = StarknetIdContract2 ?? getStarknetIdContract(chainId);
|
|
3542
|
+
try {
|
|
3543
|
+
const hexDomain = await provider.callContract({
|
|
3544
|
+
contractAddress: contract,
|
|
3545
|
+
entrypoint: "address_to_domain",
|
|
3546
|
+
calldata: CallData.compile({
|
|
3547
|
+
address
|
|
3548
|
+
})
|
|
3549
|
+
});
|
|
3550
|
+
const decimalDomain = hexDomain.result.map((element) => BigInt(element)).slice(1);
|
|
3551
|
+
const stringDomain = useDecoded(decimalDomain);
|
|
3552
|
+
if (!stringDomain) {
|
|
3553
|
+
throw Error("Starkname not found");
|
|
3554
|
+
}
|
|
3555
|
+
return stringDomain;
|
|
3556
|
+
} catch (e) {
|
|
3557
|
+
if (e instanceof Error && e.message === "Starkname not found") {
|
|
3558
|
+
throw e;
|
|
3559
|
+
}
|
|
3560
|
+
throw Error("Could not get stark name");
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
async function getAddressFromStarkName(provider, name, StarknetIdContract2) {
|
|
3564
|
+
const chainId = await provider.getChainId();
|
|
3565
|
+
const contract = StarknetIdContract2 ?? getStarknetIdContract(chainId);
|
|
3566
|
+
try {
|
|
3567
|
+
const addressData = await provider.callContract({
|
|
3568
|
+
contractAddress: contract,
|
|
3569
|
+
entrypoint: "domain_to_address",
|
|
3570
|
+
calldata: CallData.compile({
|
|
3571
|
+
domain: [useEncoded(name.replace(".stark", "")).toString(10)]
|
|
3572
|
+
})
|
|
3573
|
+
});
|
|
3574
|
+
return addressData.result[0];
|
|
3575
|
+
} catch {
|
|
3576
|
+
throw Error("Could not get address from stark name");
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3580
|
+
// src/provider/utils.ts
|
|
3581
|
+
var validBlockTags = ["latest", "pending"];
|
|
3582
|
+
var Block = class {
|
|
3583
|
+
constructor(_identifier) {
|
|
3584
|
+
this.hash = null;
|
|
3585
|
+
this.number = null;
|
|
3586
|
+
this.tag = null;
|
|
3587
|
+
this.valueOf = () => this.number;
|
|
3588
|
+
this.toString = () => this.hash;
|
|
3589
|
+
this.setIdentifier(_identifier);
|
|
3590
|
+
}
|
|
3591
|
+
setIdentifier(__identifier) {
|
|
3592
|
+
if (typeof __identifier === "string" && isHex(__identifier)) {
|
|
3593
|
+
this.hash = __identifier;
|
|
3594
|
+
} else if (typeof __identifier === "bigint") {
|
|
3595
|
+
this.hash = toHex(__identifier);
|
|
3596
|
+
} else if (typeof __identifier === "number") {
|
|
3597
|
+
this.number = __identifier;
|
|
3598
|
+
} else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
|
|
3599
|
+
this.tag = __identifier;
|
|
3600
|
+
} else {
|
|
3601
|
+
this.tag = "pending";
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
get queryIdentifier() {
|
|
3605
|
+
if (this.number !== null) {
|
|
3606
|
+
return `blockNumber=${this.number}`;
|
|
3607
|
+
}
|
|
3608
|
+
if (this.hash !== null) {
|
|
3609
|
+
return `blockHash=${this.hash}`;
|
|
3610
|
+
}
|
|
3611
|
+
return `blockNumber=${this.tag}`;
|
|
3612
|
+
}
|
|
3613
|
+
get identifier() {
|
|
3614
|
+
if (this.number !== null) {
|
|
3615
|
+
return { block_number: this.number };
|
|
3616
|
+
}
|
|
3617
|
+
if (this.hash !== null) {
|
|
3618
|
+
return { block_hash: this.hash };
|
|
3619
|
+
}
|
|
3620
|
+
return this.tag;
|
|
3621
|
+
}
|
|
3622
|
+
set identifier(_identifier) {
|
|
3623
|
+
this.setIdentifier(_identifier);
|
|
3624
|
+
}
|
|
3625
|
+
get sequencerIdentifier() {
|
|
3626
|
+
return this.hash !== null ? { blockHash: this.hash } : { blockNumber: this.number ?? this.tag };
|
|
3627
|
+
}
|
|
3628
|
+
};
|
|
3629
|
+
|
|
3630
|
+
// src/provider/rpc.ts
|
|
3631
|
+
var defaultOptions = {
|
|
3632
|
+
headers: { "Content-Type": "application/json" },
|
|
3633
|
+
blockIdentifier: "latest",
|
|
3634
|
+
retries: 200
|
|
3635
|
+
};
|
|
3636
|
+
var RpcProvider = class {
|
|
3637
|
+
constructor(optionsOrProvider) {
|
|
3638
|
+
this.responseParser = new RPCResponseParser();
|
|
3639
|
+
const { nodeUrl, retries, headers, blockIdentifier } = optionsOrProvider;
|
|
3640
|
+
this.nodeUrl = nodeUrl;
|
|
3641
|
+
this.retries = retries || defaultOptions.retries;
|
|
3642
|
+
this.headers = { ...defaultOptions.headers, ...headers };
|
|
3643
|
+
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
|
|
3644
|
+
this.getChainId();
|
|
3645
|
+
}
|
|
3646
|
+
fetch(method, params) {
|
|
3647
|
+
return fetchPonyfill_default(this.nodeUrl, {
|
|
3648
|
+
method: "POST",
|
|
3649
|
+
body: stringify2({ method, jsonrpc: "2.0", params, id: 0 }),
|
|
3650
|
+
headers: this.headers
|
|
3651
|
+
});
|
|
3652
|
+
}
|
|
3653
|
+
errorHandler(error) {
|
|
3654
|
+
if (error) {
|
|
3655
|
+
const { code, message } = error;
|
|
3656
|
+
throw new LibraryError(`${code}: ${message}`);
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
async fetchEndpoint(method, params) {
|
|
3660
|
+
var _a;
|
|
3661
|
+
try {
|
|
3662
|
+
const rawResult = await this.fetch(method, params);
|
|
3663
|
+
const { error, result } = await rawResult.json();
|
|
3664
|
+
this.errorHandler(error);
|
|
3665
|
+
return result;
|
|
3666
|
+
} catch (error) {
|
|
3667
|
+
this.errorHandler((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data);
|
|
3668
|
+
throw error;
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
async getChainId() {
|
|
3672
|
+
this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
|
|
3673
|
+
return this.chainId;
|
|
3674
|
+
}
|
|
3675
|
+
async getBlock(blockIdentifier = this.blockIdentifier) {
|
|
3676
|
+
return this.getBlockWithTxHashes(blockIdentifier).then(
|
|
3677
|
+
this.responseParser.parseGetBlockResponse
|
|
3678
|
+
);
|
|
3679
|
+
}
|
|
3680
|
+
async getBlockHashAndNumber() {
|
|
3681
|
+
return this.fetchEndpoint("starknet_blockHashAndNumber");
|
|
3682
|
+
}
|
|
3683
|
+
async getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
|
|
3684
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3685
|
+
return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
|
|
3686
|
+
}
|
|
3687
|
+
async getBlockWithTxs(blockIdentifier = this.blockIdentifier) {
|
|
3688
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3689
|
+
return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
|
|
3690
|
+
}
|
|
3691
|
+
async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3692
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3693
|
+
return this.fetchEndpoint("starknet_getClassHashAt", {
|
|
3694
|
+
block_id,
|
|
3695
|
+
contract_address: contractAddress
|
|
3696
|
+
});
|
|
3697
|
+
}
|
|
3698
|
+
async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3699
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3700
|
+
return this.fetchEndpoint("starknet_getNonce", {
|
|
3701
|
+
contract_address: contractAddress,
|
|
3702
|
+
block_id
|
|
3703
|
+
});
|
|
3704
|
+
}
|
|
3705
|
+
async getPendingTransactions() {
|
|
3706
|
+
return this.fetchEndpoint("starknet_pendingTransactions");
|
|
3707
|
+
}
|
|
3708
|
+
async getProtocolVersion() {
|
|
3709
|
+
throw new Error("Pathfinder does not implement this rpc 0.1.0 method");
|
|
3710
|
+
}
|
|
3711
|
+
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
3712
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3713
|
+
return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
|
|
3714
|
+
}
|
|
3715
|
+
async getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
|
|
3716
|
+
const parsedKey = toHex(key);
|
|
3717
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3718
|
+
return this.fetchEndpoint("starknet_getStorageAt", {
|
|
3719
|
+
contract_address: contractAddress,
|
|
3720
|
+
key: parsedKey,
|
|
3721
|
+
block_id
|
|
3722
|
+
});
|
|
3723
|
+
}
|
|
3724
|
+
async getTransaction(txHash) {
|
|
3725
|
+
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
3726
|
+
}
|
|
3727
|
+
async getTransactionByHash(txHash) {
|
|
3728
|
+
return this.fetchEndpoint("starknet_getTransactionByHash", { transaction_hash: txHash });
|
|
3729
|
+
}
|
|
3730
|
+
async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
|
|
3731
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3732
|
+
return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
|
|
3733
|
+
}
|
|
3734
|
+
async getTransactionReceipt(txHash) {
|
|
3735
|
+
return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash: txHash });
|
|
3736
|
+
}
|
|
3737
|
+
async getClassByHash(classHash) {
|
|
3738
|
+
return this.getClass(classHash);
|
|
3739
|
+
}
|
|
3740
|
+
async getClass(classHash, blockIdentifier = this.blockIdentifier) {
|
|
3741
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3742
|
+
return this.fetchEndpoint("starknet_getClass", { class_hash: classHash, block_id });
|
|
3743
|
+
}
|
|
3744
|
+
async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3240
3745
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3241
3746
|
return this.fetchEndpoint("starknet_getClassAt", {
|
|
3242
3747
|
block_id,
|
|
@@ -3426,11 +3931,11 @@ var RpcProvider = class {
|
|
|
3426
3931
|
async getSimulateTransaction(_invocation, _invocationDetails, _blockIdentifier) {
|
|
3427
3932
|
throw new Error("RPC does not implement simulateTransaction function");
|
|
3428
3933
|
}
|
|
3429
|
-
async getStarkName(address,
|
|
3430
|
-
return getStarkName(this, address,
|
|
3934
|
+
async getStarkName(address, StarknetIdContract2) {
|
|
3935
|
+
return getStarkName(this, address, StarknetIdContract2);
|
|
3431
3936
|
}
|
|
3432
|
-
async getAddressFromStarkName(name,
|
|
3433
|
-
return getAddressFromStarkName(this, name,
|
|
3937
|
+
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
3938
|
+
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
3434
3939
|
}
|
|
3435
3940
|
};
|
|
3436
3941
|
|
|
@@ -3960,711 +4465,206 @@ var SequencerProvider = class {
|
|
|
3960
4465
|
...res,
|
|
3961
4466
|
signature: bigNumberishArrayToDecimalStringArray(formatSignature(invocation.signature)),
|
|
3962
4467
|
version: toHex(toBigInt((invocation == null ? void 0 : invocation.version) || 1)),
|
|
3963
|
-
nonce: toHex(toBigInt(invocation.nonce))
|
|
3964
|
-
};
|
|
3965
|
-
});
|
|
3966
|
-
return this.fetchEndpoint("estimate_fee_bulk", { blockIdentifier }, params).then(
|
|
3967
|
-
this.responseParser.parseFeeEstimateBulkResponse
|
|
3968
|
-
);
|
|
3969
|
-
}
|
|
3970
|
-
async getCode(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3971
|
-
return this.fetchEndpoint("get_code", { contractAddress, blockIdentifier });
|
|
3972
|
-
}
|
|
3973
|
-
async waitForTransaction(txHash, options) {
|
|
3974
|
-
const errorStates = ["REJECTED" /* REJECTED */, "NOT_RECEIVED" /* NOT_RECEIVED */];
|
|
3975
|
-
let onchain = false;
|
|
3976
|
-
let res;
|
|
3977
|
-
const retryInterval = (options == null ? void 0 : options.retryInterval) ?? 8e3;
|
|
3978
|
-
const successStates = (options == null ? void 0 : options.successStates) ?? [
|
|
3979
|
-
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
3980
|
-
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
3981
|
-
"PENDING" /* PENDING */
|
|
3982
|
-
];
|
|
3983
|
-
while (!onchain) {
|
|
3984
|
-
await wait(retryInterval);
|
|
3985
|
-
res = await this.getTransactionStatus(txHash);
|
|
3986
|
-
if (successStates.includes(res.tx_status)) {
|
|
3987
|
-
onchain = true;
|
|
3988
|
-
} else if (errorStates.includes(res.tx_status)) {
|
|
3989
|
-
const message = res.tx_failure_reason ? `${res.tx_status}: ${res.tx_failure_reason.code}
|
|
3990
|
-
${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
3991
|
-
const error = new Error(message);
|
|
3992
|
-
error.response = res;
|
|
3993
|
-
throw error;
|
|
3994
|
-
}
|
|
3995
|
-
}
|
|
3996
|
-
const txReceipt = await this.getTransactionReceipt(txHash);
|
|
3997
|
-
return txReceipt;
|
|
3998
|
-
}
|
|
3999
|
-
async getTransactionStatus(txHash) {
|
|
4000
|
-
const txHashHex = toHex(txHash);
|
|
4001
|
-
return this.fetchEndpoint("get_transaction_status", { transactionHash: txHashHex });
|
|
4002
|
-
}
|
|
4003
|
-
async getContractAddresses() {
|
|
4004
|
-
return this.fetchEndpoint("get_contract_addresses");
|
|
4005
|
-
}
|
|
4006
|
-
async getTransactionTrace(txHash) {
|
|
4007
|
-
const txHashHex = toHex(txHash);
|
|
4008
|
-
return this.fetchEndpoint("get_transaction_trace", { transactionHash: txHashHex });
|
|
4009
|
-
}
|
|
4010
|
-
async estimateMessageFee({ from_address, to_address, entry_point_selector, payload }, blockIdentifier = this.blockIdentifier) {
|
|
4011
|
-
const validCallL1Handler = {
|
|
4012
|
-
from_address: getDecimalString(from_address),
|
|
4013
|
-
to_address: getHexString(to_address),
|
|
4014
|
-
entry_point_selector: getSelector(entry_point_selector),
|
|
4015
|
-
payload: getHexStringArray(payload)
|
|
4016
|
-
};
|
|
4017
|
-
return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
|
|
4018
|
-
}
|
|
4019
|
-
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
4020
|
-
return this.fetchEndpoint(
|
|
4021
|
-
"simulate_transaction",
|
|
4022
|
-
{ blockIdentifier, skipValidate },
|
|
4023
|
-
{
|
|
4024
|
-
type: "INVOKE_FUNCTION",
|
|
4025
|
-
sender_address: invocation.contractAddress,
|
|
4026
|
-
calldata: invocation.calldata ?? [],
|
|
4027
|
-
signature: signatureToDecimalArray(invocation.signature),
|
|
4028
|
-
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
4029
|
-
nonce: toHex(invocationDetails.nonce),
|
|
4030
|
-
max_fee: toHex((invocationDetails == null ? void 0 : invocationDetails.maxFee) || 0)
|
|
4031
|
-
}
|
|
4032
|
-
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
4033
|
-
}
|
|
4034
|
-
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
4035
|
-
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4036
|
-
return this.fetchEndpoint("get_state_update", { ...args }).then(
|
|
4037
|
-
this.responseParser.parseGetStateUpdateResponse
|
|
4038
|
-
);
|
|
4039
|
-
}
|
|
4040
|
-
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
4041
|
-
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4042
|
-
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
4043
|
-
}
|
|
4044
|
-
async getStarkName(address, StarknetIdContract) {
|
|
4045
|
-
return getStarkName(this, address, StarknetIdContract);
|
|
4046
|
-
}
|
|
4047
|
-
async getAddressFromStarkName(name, StarknetIdContract) {
|
|
4048
|
-
return getAddressFromStarkName(this, name, StarknetIdContract);
|
|
4049
|
-
}
|
|
4050
|
-
};
|
|
4051
|
-
|
|
4052
|
-
// src/provider/default.ts
|
|
4053
|
-
var Provider = class {
|
|
4054
|
-
constructor(providerOrOptions) {
|
|
4055
|
-
if (providerOrOptions instanceof Provider) {
|
|
4056
|
-
this.provider = providerOrOptions.provider;
|
|
4057
|
-
} else if (providerOrOptions instanceof RpcProvider || providerOrOptions instanceof SequencerProvider) {
|
|
4058
|
-
this.provider = providerOrOptions;
|
|
4059
|
-
} else if (providerOrOptions && "rpc" in providerOrOptions) {
|
|
4060
|
-
this.provider = new RpcProvider(providerOrOptions.rpc);
|
|
4061
|
-
} else if (providerOrOptions && "sequencer" in providerOrOptions) {
|
|
4062
|
-
this.provider = new SequencerProvider(providerOrOptions.sequencer);
|
|
4063
|
-
} else {
|
|
4064
|
-
this.provider = new SequencerProvider();
|
|
4065
|
-
}
|
|
4066
|
-
}
|
|
4067
|
-
async getChainId() {
|
|
4068
|
-
return this.provider.getChainId();
|
|
4069
|
-
}
|
|
4070
|
-
async getBlock(blockIdentifier) {
|
|
4071
|
-
return this.provider.getBlock(blockIdentifier);
|
|
4072
|
-
}
|
|
4073
|
-
async getClassAt(contractAddress, blockIdentifier) {
|
|
4074
|
-
return this.provider.getClassAt(contractAddress, blockIdentifier);
|
|
4075
|
-
}
|
|
4076
|
-
async getClassHashAt(contractAddress, blockIdentifier) {
|
|
4077
|
-
return this.provider.getClassHashAt(contractAddress, blockIdentifier);
|
|
4078
|
-
}
|
|
4079
|
-
getClassByHash(classHash) {
|
|
4080
|
-
return this.provider.getClassByHash(classHash);
|
|
4081
|
-
}
|
|
4082
|
-
async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
4083
|
-
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
4084
|
-
}
|
|
4085
|
-
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
|
|
4086
|
-
return this.provider.getInvokeEstimateFee(
|
|
4087
|
-
invocationWithTxType,
|
|
4088
|
-
invocationDetails,
|
|
4089
|
-
blockIdentifier,
|
|
4090
|
-
skipValidate
|
|
4091
|
-
);
|
|
4092
|
-
}
|
|
4093
|
-
async getEstimateFeeBulk(invocations, blockIdentifier) {
|
|
4094
|
-
return this.provider.getEstimateFeeBulk(invocations, blockIdentifier);
|
|
4095
|
-
}
|
|
4096
|
-
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
4097
|
-
return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
|
|
4098
|
-
}
|
|
4099
|
-
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4100
|
-
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
|
|
4101
|
-
}
|
|
4102
|
-
async getTransaction(txHash) {
|
|
4103
|
-
return this.provider.getTransaction(txHash);
|
|
4104
|
-
}
|
|
4105
|
-
async getTransactionReceipt(txHash) {
|
|
4106
|
-
return this.provider.getTransactionReceipt(txHash);
|
|
4107
|
-
}
|
|
4108
|
-
async callContract(request, blockIdentifier) {
|
|
4109
|
-
return this.provider.callContract(request, blockIdentifier);
|
|
4110
|
-
}
|
|
4111
|
-
async invokeFunction(functionInvocation, details) {
|
|
4112
|
-
return this.provider.invokeFunction(functionInvocation, details);
|
|
4113
|
-
}
|
|
4114
|
-
async deployAccountContract(payload, details) {
|
|
4115
|
-
return this.provider.deployAccountContract(payload, details);
|
|
4116
|
-
}
|
|
4117
|
-
async declareContract(transaction, details) {
|
|
4118
|
-
return this.provider.declareContract(transaction, details);
|
|
4119
|
-
}
|
|
4120
|
-
async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4121
|
-
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
|
|
4122
|
-
}
|
|
4123
|
-
getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4124
|
-
return this.provider.getDeployAccountEstimateFee(
|
|
4125
|
-
transaction,
|
|
4126
|
-
details,
|
|
4127
|
-
blockIdentifier,
|
|
4128
|
-
skipValidate
|
|
4129
|
-
);
|
|
4130
|
-
}
|
|
4131
|
-
async getCode(contractAddress, blockIdentifier) {
|
|
4132
|
-
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
4133
|
-
}
|
|
4134
|
-
async waitForTransaction(txHash, options) {
|
|
4135
|
-
return this.provider.waitForTransaction(txHash, options);
|
|
4136
|
-
}
|
|
4137
|
-
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
|
|
4138
|
-
return this.provider.getSimulateTransaction(
|
|
4139
|
-
invocation,
|
|
4140
|
-
invocationDetails,
|
|
4141
|
-
blockIdentifier,
|
|
4142
|
-
skipValidate
|
|
4143
|
-
);
|
|
4144
|
-
}
|
|
4145
|
-
async getStateUpdate(blockIdentifier) {
|
|
4146
|
-
return this.provider.getStateUpdate(blockIdentifier);
|
|
4147
|
-
}
|
|
4148
|
-
async getStarkName(address, StarknetIdContract) {
|
|
4149
|
-
return getStarkName(this, address, StarknetIdContract);
|
|
4150
|
-
}
|
|
4151
|
-
async getAddressFromStarkName(name, StarknetIdContract) {
|
|
4152
|
-
return getAddressFromStarkName(this, name, StarknetIdContract);
|
|
4153
|
-
}
|
|
4154
|
-
};
|
|
4155
|
-
|
|
4156
|
-
// src/provider/interface.ts
|
|
4157
|
-
var ProviderInterface = class {
|
|
4158
|
-
};
|
|
4159
|
-
|
|
4160
|
-
// src/provider/index.ts
|
|
4161
|
-
var defaultProvider = new Provider();
|
|
4162
|
-
|
|
4163
|
-
// src/utils/calldata/formatter.ts
|
|
4164
|
-
var guard = {
|
|
4165
|
-
isBN: (data, type, key) => {
|
|
4166
|
-
if (!isBigInt(data[key]))
|
|
4167
|
-
throw new Error(
|
|
4168
|
-
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
4169
|
-
);
|
|
4170
|
-
},
|
|
4171
|
-
unknown: (data, type, key) => {
|
|
4172
|
-
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
4173
|
-
}
|
|
4174
|
-
};
|
|
4175
|
-
function formatter(data, type, sameType) {
|
|
4176
|
-
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
4177
|
-
const elType = sameType ?? type[key];
|
|
4178
|
-
if (!(key in type) && !sameType) {
|
|
4179
|
-
acc[key] = value;
|
|
4180
|
-
return acc;
|
|
4181
|
-
}
|
|
4182
|
-
if (elType === "string") {
|
|
4183
|
-
if (Array.isArray(data[key])) {
|
|
4184
|
-
const arrayStr = formatter(
|
|
4185
|
-
data[key],
|
|
4186
|
-
data[key].map((_) => elType)
|
|
4187
|
-
);
|
|
4188
|
-
acc[key] = Object.values(arrayStr).join("");
|
|
4189
|
-
return acc;
|
|
4190
|
-
}
|
|
4191
|
-
guard.isBN(data, type, key);
|
|
4192
|
-
acc[key] = decodeShortString(value);
|
|
4193
|
-
return acc;
|
|
4194
|
-
}
|
|
4195
|
-
if (elType === "number") {
|
|
4196
|
-
guard.isBN(data, type, key);
|
|
4197
|
-
acc[key] = Number(value);
|
|
4198
|
-
return acc;
|
|
4199
|
-
}
|
|
4200
|
-
if (typeof elType === "function") {
|
|
4201
|
-
acc[key] = elType(value);
|
|
4202
|
-
return acc;
|
|
4203
|
-
}
|
|
4204
|
-
if (Array.isArray(elType)) {
|
|
4205
|
-
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
4206
|
-
acc[key] = Object.values(arrayObj);
|
|
4207
|
-
return acc;
|
|
4208
|
-
}
|
|
4209
|
-
if (typeof elType === "object") {
|
|
4210
|
-
acc[key] = formatter(data[key], elType);
|
|
4211
|
-
return acc;
|
|
4212
|
-
}
|
|
4213
|
-
guard.unknown(data, type, key);
|
|
4214
|
-
return acc;
|
|
4215
|
-
}, {});
|
|
4216
|
-
}
|
|
4217
|
-
|
|
4218
|
-
// src/utils/calldata/tuple.ts
|
|
4219
|
-
function parseNamedTuple(namedTuple) {
|
|
4220
|
-
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
4221
|
-
const type = namedTuple.substring(name.length + ":".length);
|
|
4222
|
-
return { name, type };
|
|
4223
|
-
}
|
|
4224
|
-
function parseSubTuple(s) {
|
|
4225
|
-
if (!s.includes("("))
|
|
4226
|
-
return { subTuple: [], result: s };
|
|
4227
|
-
const subTuple = [];
|
|
4228
|
-
let result = "";
|
|
4229
|
-
let i = 0;
|
|
4230
|
-
while (i < s.length) {
|
|
4231
|
-
if (s[i] === "(") {
|
|
4232
|
-
let counter = 1;
|
|
4233
|
-
const lBracket = i;
|
|
4234
|
-
i++;
|
|
4235
|
-
while (counter) {
|
|
4236
|
-
if (s[i] === ")")
|
|
4237
|
-
counter--;
|
|
4238
|
-
if (s[i] === "(")
|
|
4239
|
-
counter++;
|
|
4240
|
-
i++;
|
|
4241
|
-
}
|
|
4242
|
-
subTuple.push(s.substring(lBracket, i));
|
|
4243
|
-
result += " ";
|
|
4244
|
-
i--;
|
|
4245
|
-
} else {
|
|
4246
|
-
result += s[i];
|
|
4247
|
-
}
|
|
4248
|
-
i++;
|
|
4249
|
-
}
|
|
4250
|
-
return {
|
|
4251
|
-
subTuple,
|
|
4252
|
-
result
|
|
4253
|
-
};
|
|
4254
|
-
}
|
|
4255
|
-
function extractCairo0Tuple(type) {
|
|
4256
|
-
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
4257
|
-
const { subTuple, result } = parseSubTuple(cleanType);
|
|
4258
|
-
let recomposed = result.split(",").map((it) => {
|
|
4259
|
-
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
4260
|
-
});
|
|
4261
|
-
if (isTypeNamedTuple(type)) {
|
|
4262
|
-
recomposed = recomposed.reduce((acc, it) => {
|
|
4263
|
-
return acc.concat(parseNamedTuple(it));
|
|
4264
|
-
}, []);
|
|
4265
|
-
}
|
|
4266
|
-
return recomposed;
|
|
4267
|
-
}
|
|
4268
|
-
function extractCairo1Tuple(type) {
|
|
4269
|
-
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
4270
|
-
return cleanType.split(",");
|
|
4271
|
-
}
|
|
4272
|
-
function extractTupleMemberTypes(type) {
|
|
4273
|
-
if (isCairo1Type(type)) {
|
|
4274
|
-
return extractCairo1Tuple(type);
|
|
4275
|
-
}
|
|
4276
|
-
return extractCairo0Tuple(type);
|
|
4277
|
-
}
|
|
4278
|
-
|
|
4279
|
-
// src/utils/calldata/requestParser.ts
|
|
4280
|
-
function parseTuple(element, typeStr) {
|
|
4281
|
-
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
4282
|
-
const elements = Object.values(element);
|
|
4283
|
-
if (elements.length !== memberTypes.length) {
|
|
4284
|
-
throw Error(
|
|
4285
|
-
`ParseTuple: provided and expected abi tuple size do not match.
|
|
4286
|
-
provided: ${elements}
|
|
4287
|
-
expected: ${memberTypes}`
|
|
4288
|
-
);
|
|
4289
|
-
}
|
|
4290
|
-
return memberTypes.map((it, dx) => {
|
|
4291
|
-
return {
|
|
4292
|
-
element: elements[dx],
|
|
4293
|
-
type: it.type ?? it
|
|
4294
|
-
};
|
|
4295
|
-
});
|
|
4296
|
-
}
|
|
4297
|
-
function parseCalldataValue(element, type, structs) {
|
|
4298
|
-
if (element === void 0) {
|
|
4299
|
-
throw Error(`Missing parameter for type ${type}`);
|
|
4300
|
-
}
|
|
4301
|
-
if (Array.isArray(element)) {
|
|
4302
|
-
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
4303
|
-
}
|
|
4304
|
-
if (isTypeUint256(type)) {
|
|
4305
|
-
const el_uint256 = uint256(element);
|
|
4306
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
4307
|
-
}
|
|
4308
|
-
if (structs[type] && structs[type].members.length) {
|
|
4309
|
-
const { members } = structs[type];
|
|
4310
|
-
const subElement = element;
|
|
4311
|
-
return members.reduce((acc, it) => {
|
|
4312
|
-
return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs));
|
|
4313
|
-
}, []);
|
|
4314
|
-
}
|
|
4315
|
-
if (isTypeTuple(type)) {
|
|
4316
|
-
const tupled = parseTuple(element, type);
|
|
4317
|
-
return tupled.reduce((acc, it) => {
|
|
4318
|
-
const parsedData = parseCalldataValue(it.element, it.type, structs);
|
|
4319
|
-
return acc.concat(parsedData);
|
|
4320
|
-
}, []);
|
|
4321
|
-
}
|
|
4322
|
-
if (typeof element === "object") {
|
|
4323
|
-
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
4324
|
-
}
|
|
4325
|
-
return felt(element);
|
|
4326
|
-
}
|
|
4327
|
-
function parseCalldataField(argsIterator, input, structs) {
|
|
4328
|
-
const { name, type } = input;
|
|
4329
|
-
let { value } = argsIterator.next();
|
|
4330
|
-
switch (true) {
|
|
4331
|
-
case isTypeArray(type):
|
|
4332
|
-
if (!Array.isArray(value) && !isText(value)) {
|
|
4333
|
-
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
4334
|
-
}
|
|
4335
|
-
if (typeof value === "string") {
|
|
4336
|
-
value = splitLongString(value);
|
|
4337
|
-
}
|
|
4338
|
-
const result = [];
|
|
4339
|
-
result.push(felt(value.length));
|
|
4340
|
-
const arrayType = getArrayType(input.type);
|
|
4341
|
-
return value.reduce((acc, el) => {
|
|
4342
|
-
if (isTypeFelt(arrayType) || isTypeUint(arrayType) || isTypeContractAddress(arrayType)) {
|
|
4343
|
-
acc.push(felt(el));
|
|
4344
|
-
} else if (isTypeBool(arrayType) && typeof el === "boolean") {
|
|
4345
|
-
acc.push(el.toString());
|
|
4346
|
-
} else {
|
|
4347
|
-
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
4348
|
-
}
|
|
4349
|
-
return acc;
|
|
4350
|
-
}, result);
|
|
4351
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
|
|
4352
|
-
return parseCalldataValue(value, type, structs);
|
|
4353
|
-
case isTypeBool(type):
|
|
4354
|
-
return `${+value}`;
|
|
4355
|
-
default:
|
|
4356
|
-
return felt(value);
|
|
4357
|
-
}
|
|
4358
|
-
}
|
|
4359
|
-
|
|
4360
|
-
// src/utils/calldata/responseParser.ts
|
|
4361
|
-
function parseResponseStruct(responseIterator, type, structs) {
|
|
4362
|
-
if (type in structs && structs[type]) {
|
|
4363
|
-
return structs[type].members.reduce((acc, el) => {
|
|
4364
|
-
acc[el.name] = parseResponseStruct(responseIterator, el.type, structs);
|
|
4365
|
-
return acc;
|
|
4366
|
-
}, {});
|
|
4367
|
-
}
|
|
4368
|
-
if (isTypeTuple(type)) {
|
|
4369
|
-
const memberTypes = extractTupleMemberTypes(type);
|
|
4370
|
-
return memberTypes.reduce((acc, it, idx) => {
|
|
4371
|
-
const tName = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
4372
|
-
const tType = (it == null ? void 0 : it.type) ? it.type : it;
|
|
4373
|
-
acc[tName] = parseResponseStruct(responseIterator, tType, structs);
|
|
4374
|
-
return acc;
|
|
4375
|
-
}, {});
|
|
4376
|
-
}
|
|
4377
|
-
const temp = responseIterator.next().value;
|
|
4378
|
-
return BigInt(temp);
|
|
4379
|
-
}
|
|
4380
|
-
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
4381
|
-
const { name, type } = output;
|
|
4382
|
-
let temp;
|
|
4383
|
-
switch (true) {
|
|
4384
|
-
case isLen(name):
|
|
4385
|
-
temp = responseIterator.next().value;
|
|
4386
|
-
return BigInt(temp);
|
|
4387
|
-
case isTypeBool(type):
|
|
4388
|
-
temp = responseIterator.next().value;
|
|
4389
|
-
return Boolean(BigInt(temp));
|
|
4390
|
-
case isTypeUint256(type):
|
|
4391
|
-
const low = responseIterator.next().value;
|
|
4392
|
-
const high = responseIterator.next().value;
|
|
4393
|
-
return uint256ToBN({ low, high });
|
|
4394
|
-
case isTypeArray(type):
|
|
4395
|
-
const parsedDataArr = [];
|
|
4396
|
-
if (isCairo1Type(type)) {
|
|
4397
|
-
responseIterator.next();
|
|
4398
|
-
let it = responseIterator.next();
|
|
4399
|
-
while (!it.done) {
|
|
4400
|
-
parsedDataArr.push(BigInt(it.value));
|
|
4401
|
-
it = responseIterator.next();
|
|
4402
|
-
}
|
|
4403
|
-
return parsedDataArr;
|
|
4404
|
-
}
|
|
4405
|
-
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
4406
|
-
const arrLen = parsedResult[`${name}_len`];
|
|
4407
|
-
while (parsedDataArr.length < arrLen) {
|
|
4408
|
-
parsedDataArr.push(
|
|
4409
|
-
parseResponseStruct(responseIterator, output.type.replace("*", ""), structs)
|
|
4410
|
-
);
|
|
4411
|
-
}
|
|
4412
|
-
}
|
|
4413
|
-
return parsedDataArr;
|
|
4414
|
-
case (type in structs || isTypeTuple(type)):
|
|
4415
|
-
return parseResponseStruct(responseIterator, type, structs);
|
|
4416
|
-
default:
|
|
4417
|
-
temp = responseIterator.next().value;
|
|
4418
|
-
return BigInt(temp);
|
|
4419
|
-
}
|
|
4420
|
-
}
|
|
4421
|
-
|
|
4422
|
-
// src/utils/calldata/validate.ts
|
|
4423
|
-
var validateFelt = (parameter, input) => {
|
|
4424
|
-
assert(
|
|
4425
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
4426
|
-
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
4427
|
-
);
|
|
4428
|
-
};
|
|
4429
|
-
var validateUint = (parameter, input) => {
|
|
4430
|
-
if (typeof parameter === "number") {
|
|
4431
|
-
assert(
|
|
4432
|
-
parameter <= Number.MAX_SAFE_INTEGER,
|
|
4433
|
-
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
4434
|
-
);
|
|
4435
|
-
}
|
|
4436
|
-
assert(
|
|
4437
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
4438
|
-
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
|
|
4439
|
-
);
|
|
4440
|
-
const param = toBigInt(parameter);
|
|
4441
|
-
switch (input.type) {
|
|
4442
|
-
case "core::integer::u8" /* u8 */:
|
|
4443
|
-
assert(
|
|
4444
|
-
param >= 0n && param <= 255n,
|
|
4445
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
4446
|
-
);
|
|
4447
|
-
break;
|
|
4448
|
-
case "core::integer::u16" /* u16 */:
|
|
4449
|
-
assert(
|
|
4450
|
-
param >= 0n && param <= 65535n,
|
|
4451
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
4452
|
-
);
|
|
4453
|
-
break;
|
|
4454
|
-
case "core::integer::u32" /* u32 */:
|
|
4455
|
-
assert(
|
|
4456
|
-
param >= 0n && param <= 4294967295n,
|
|
4457
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
4458
|
-
);
|
|
4459
|
-
break;
|
|
4460
|
-
case "core::integer::u64" /* u64 */:
|
|
4461
|
-
assert(
|
|
4462
|
-
param >= 0n && param <= 2n ** 64n - 1n,
|
|
4463
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
4464
|
-
);
|
|
4465
|
-
break;
|
|
4466
|
-
case "core::integer::u128" /* u128 */:
|
|
4467
|
-
assert(
|
|
4468
|
-
param >= 0n && param <= 2n ** 128n - 1n,
|
|
4469
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
4470
|
-
);
|
|
4471
|
-
break;
|
|
4472
|
-
case "core::integer::u256" /* u256 */:
|
|
4473
|
-
assert(
|
|
4474
|
-
param >= 0n && param <= 2n ** 256n - 1n,
|
|
4475
|
-
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
4476
|
-
);
|
|
4477
|
-
break;
|
|
4478
|
-
default:
|
|
4479
|
-
break;
|
|
4480
|
-
}
|
|
4481
|
-
};
|
|
4482
|
-
var validateBool = (parameter, input) => {
|
|
4483
|
-
assert(
|
|
4484
|
-
typeof parameter === "boolean",
|
|
4485
|
-
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
4486
|
-
);
|
|
4487
|
-
};
|
|
4488
|
-
var validateStruct = (parameter, input, structs) => {
|
|
4489
|
-
assert(
|
|
4490
|
-
typeof parameter === "object" && !Array.isArray(parameter),
|
|
4491
|
-
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
4492
|
-
);
|
|
4493
|
-
structs[input.type].members.forEach(({ name }) => {
|
|
4494
|
-
assert(
|
|
4495
|
-
Object.keys(parameter).includes(name),
|
|
4496
|
-
`Validate: arg ${input.name} should have a property ${name}`
|
|
4497
|
-
);
|
|
4498
|
-
});
|
|
4499
|
-
};
|
|
4500
|
-
var validateTuple = (parameter, input) => {
|
|
4501
|
-
assert(
|
|
4502
|
-
typeof parameter === "object" && !Array.isArray(parameter),
|
|
4503
|
-
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
4504
|
-
);
|
|
4505
|
-
};
|
|
4506
|
-
var validateArray = (parameter, input, structs) => {
|
|
4507
|
-
const baseType = getArrayType(input.type);
|
|
4508
|
-
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
4509
|
-
return;
|
|
4510
|
-
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
4511
|
-
switch (true) {
|
|
4512
|
-
case isTypeFelt(baseType):
|
|
4513
|
-
parameter.forEach((param) => validateFelt(param, input));
|
|
4514
|
-
break;
|
|
4515
|
-
case isTypeTuple(baseType):
|
|
4516
|
-
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
4517
|
-
break;
|
|
4518
|
-
case isTypeStruct(baseType, structs):
|
|
4519
|
-
parameter.forEach(
|
|
4520
|
-
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
4521
|
-
);
|
|
4522
|
-
break;
|
|
4523
|
-
case isTypeUint(baseType):
|
|
4524
|
-
parameter.forEach((param) => validateUint(param, input));
|
|
4525
|
-
break;
|
|
4526
|
-
case isTypeBool(baseType):
|
|
4527
|
-
parameter.forEach((param) => validateBool(param, input));
|
|
4528
|
-
break;
|
|
4529
|
-
default:
|
|
4530
|
-
throw new Error(
|
|
4531
|
-
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
4532
|
-
);
|
|
4533
|
-
}
|
|
4534
|
-
};
|
|
4535
|
-
function validateFields(abiMethod, args, structs) {
|
|
4536
|
-
abiMethod.inputs.reduce((acc, input) => {
|
|
4537
|
-
const parameter = args[acc];
|
|
4538
|
-
switch (true) {
|
|
4539
|
-
case isLen(input.name):
|
|
4540
|
-
return acc;
|
|
4541
|
-
case isTypeFelt(input.type):
|
|
4542
|
-
validateFelt(parameter, input);
|
|
4543
|
-
break;
|
|
4544
|
-
case isTypeUint(input.type):
|
|
4545
|
-
validateUint(parameter, input);
|
|
4546
|
-
break;
|
|
4547
|
-
case isTypeBool(input.type):
|
|
4548
|
-
validateBool(parameter, input);
|
|
4549
|
-
break;
|
|
4550
|
-
case isTypeContractAddress(input.type):
|
|
4551
|
-
break;
|
|
4552
|
-
case isTypeStruct(input.type, structs):
|
|
4553
|
-
validateStruct(parameter, input, structs);
|
|
4554
|
-
break;
|
|
4555
|
-
case isTypeTuple(input.type):
|
|
4556
|
-
validateTuple(parameter, input);
|
|
4557
|
-
break;
|
|
4558
|
-
case isTypeArray(input.type):
|
|
4559
|
-
validateArray(parameter, input, structs);
|
|
4560
|
-
break;
|
|
4561
|
-
default:
|
|
4562
|
-
throw new Error(
|
|
4563
|
-
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
4564
|
-
);
|
|
4565
|
-
}
|
|
4566
|
-
return acc + 1;
|
|
4567
|
-
}, 0);
|
|
4568
|
-
}
|
|
4569
|
-
|
|
4570
|
-
// src/utils/calldata/index.ts
|
|
4571
|
-
var CallData = class {
|
|
4572
|
-
constructor(abi) {
|
|
4573
|
-
this.abi = abi;
|
|
4574
|
-
this.structs = CallData.getAbiStruct(abi);
|
|
4575
|
-
}
|
|
4576
|
-
validate(type, method, args = []) {
|
|
4577
|
-
if (type !== "DEPLOY") {
|
|
4578
|
-
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
4579
|
-
if (abi.type !== "function")
|
|
4580
|
-
return false;
|
|
4581
|
-
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
4582
|
-
return type === "INVOKE" ? !isView : isView;
|
|
4583
|
-
}).map((abi) => abi.name);
|
|
4584
|
-
assert(
|
|
4585
|
-
invocableFunctionNames.includes(method),
|
|
4586
|
-
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
4587
|
-
);
|
|
4588
|
-
}
|
|
4589
|
-
const abiMethod = this.abi.find(
|
|
4590
|
-
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
4468
|
+
nonce: toHex(toBigInt(invocation.nonce))
|
|
4469
|
+
};
|
|
4470
|
+
});
|
|
4471
|
+
return this.fetchEndpoint("estimate_fee_bulk", { blockIdentifier }, params).then(
|
|
4472
|
+
this.responseParser.parseFeeEstimateBulkResponse
|
|
4591
4473
|
);
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4474
|
+
}
|
|
4475
|
+
async getCode(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
4476
|
+
return this.fetchEndpoint("get_code", { contractAddress, blockIdentifier });
|
|
4477
|
+
}
|
|
4478
|
+
async waitForTransaction(txHash, options) {
|
|
4479
|
+
const errorStates = ["REJECTED" /* REJECTED */, "NOT_RECEIVED" /* NOT_RECEIVED */];
|
|
4480
|
+
let onchain = false;
|
|
4481
|
+
let res;
|
|
4482
|
+
const retryInterval = (options == null ? void 0 : options.retryInterval) ?? 8e3;
|
|
4483
|
+
const successStates = (options == null ? void 0 : options.successStates) ?? [
|
|
4484
|
+
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
4485
|
+
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
4486
|
+
"PENDING" /* PENDING */
|
|
4487
|
+
];
|
|
4488
|
+
while (!onchain) {
|
|
4489
|
+
await wait(retryInterval);
|
|
4490
|
+
res = await this.getTransactionStatus(txHash);
|
|
4491
|
+
if (successStates.includes(res.tx_status)) {
|
|
4492
|
+
onchain = true;
|
|
4493
|
+
} else if (errorStates.includes(res.tx_status)) {
|
|
4494
|
+
const message = res.tx_failure_reason ? `${res.tx_status}: ${res.tx_failure_reason.code}
|
|
4495
|
+
${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
4496
|
+
const error = new Error(message);
|
|
4497
|
+
error.response = res;
|
|
4498
|
+
throw error;
|
|
4499
|
+
}
|
|
4597
4500
|
}
|
|
4598
|
-
|
|
4501
|
+
const txReceipt = await this.getTransactionReceipt(txHash);
|
|
4502
|
+
return txReceipt;
|
|
4599
4503
|
}
|
|
4600
|
-
|
|
4601
|
-
const
|
|
4602
|
-
return
|
|
4603
|
-
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
4604
|
-
[]
|
|
4605
|
-
);
|
|
4504
|
+
async getTransactionStatus(txHash) {
|
|
4505
|
+
const txHashHex = toHex(txHash);
|
|
4506
|
+
return this.fetchEndpoint("get_transaction_status", { transactionHash: txHashHex });
|
|
4606
4507
|
}
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
};
|
|
4621
|
-
return Object.fromEntries(getEntries(obj));
|
|
4508
|
+
async getContractAddresses() {
|
|
4509
|
+
return this.fetchEndpoint("get_contract_addresses");
|
|
4510
|
+
}
|
|
4511
|
+
async getTransactionTrace(txHash) {
|
|
4512
|
+
const txHashHex = toHex(txHash);
|
|
4513
|
+
return this.fetchEndpoint("get_transaction_trace", { transactionHash: txHashHex });
|
|
4514
|
+
}
|
|
4515
|
+
async estimateMessageFee({ from_address, to_address, entry_point_selector, payload }, blockIdentifier = this.blockIdentifier) {
|
|
4516
|
+
const validCallL1Handler = {
|
|
4517
|
+
from_address: getDecimalString(from_address),
|
|
4518
|
+
to_address: getHexString(to_address),
|
|
4519
|
+
entry_point_selector: getSelector(entry_point_selector),
|
|
4520
|
+
payload: getHexStringArray(payload)
|
|
4622
4521
|
};
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4522
|
+
return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
|
|
4523
|
+
}
|
|
4524
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
4525
|
+
return this.fetchEndpoint(
|
|
4526
|
+
"simulate_transaction",
|
|
4527
|
+
{ blockIdentifier, skipValidate },
|
|
4528
|
+
{
|
|
4529
|
+
type: "INVOKE_FUNCTION",
|
|
4530
|
+
sender_address: invocation.contractAddress,
|
|
4531
|
+
calldata: invocation.calldata ?? [],
|
|
4532
|
+
signature: signatureToDecimalArray(invocation.signature),
|
|
4533
|
+
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
4534
|
+
nonce: toHex(invocationDetails.nonce),
|
|
4535
|
+
max_fee: toHex((invocationDetails == null ? void 0 : invocationDetails.maxFee) || 0)
|
|
4536
|
+
}
|
|
4537
|
+
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
4538
|
+
}
|
|
4539
|
+
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
4540
|
+
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4541
|
+
return this.fetchEndpoint("get_state_update", { ...args }).then(
|
|
4542
|
+
this.responseParser.parseGetStateUpdateResponse
|
|
4543
|
+
);
|
|
4544
|
+
}
|
|
4545
|
+
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
4546
|
+
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4547
|
+
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
4548
|
+
}
|
|
4549
|
+
async getStarkName(address, StarknetIdContract2) {
|
|
4550
|
+
return getStarkName(this, address, StarknetIdContract2);
|
|
4551
|
+
}
|
|
4552
|
+
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4553
|
+
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4554
|
+
}
|
|
4555
|
+
};
|
|
4556
|
+
|
|
4557
|
+
// src/provider/default.ts
|
|
4558
|
+
var Provider = class {
|
|
4559
|
+
constructor(providerOrOptions) {
|
|
4560
|
+
if (providerOrOptions instanceof Provider) {
|
|
4561
|
+
this.provider = providerOrOptions.provider;
|
|
4562
|
+
} else if (providerOrOptions instanceof RpcProvider || providerOrOptions instanceof SequencerProvider) {
|
|
4563
|
+
this.provider = providerOrOptions;
|
|
4564
|
+
} else if (providerOrOptions && "rpc" in providerOrOptions) {
|
|
4565
|
+
this.provider = new RpcProvider(providerOrOptions.rpc);
|
|
4566
|
+
} else if (providerOrOptions && "sequencer" in providerOrOptions) {
|
|
4567
|
+
this.provider = new SequencerProvider(providerOrOptions.sequencer);
|
|
4627
4568
|
} else {
|
|
4628
|
-
|
|
4569
|
+
this.provider = new SequencerProvider();
|
|
4629
4570
|
}
|
|
4630
|
-
Object.defineProperty(callTreeArray, "compiled", {
|
|
4631
|
-
enumerable: false,
|
|
4632
|
-
writable: false,
|
|
4633
|
-
value: true
|
|
4634
|
-
});
|
|
4635
|
-
return callTreeArray;
|
|
4636
4571
|
}
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
const responseIterator = response.flat()[Symbol.iterator]();
|
|
4640
|
-
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
4641
|
-
const propName = output.name ?? idx;
|
|
4642
|
-
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
4643
|
-
if (acc[propName] && acc[`${propName}_len`]) {
|
|
4644
|
-
delete acc[`${propName}_len`];
|
|
4645
|
-
}
|
|
4646
|
-
return acc;
|
|
4647
|
-
}, {});
|
|
4648
|
-
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
4572
|
+
async getChainId() {
|
|
4573
|
+
return this.provider.getChainId();
|
|
4649
4574
|
}
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
return formatter(parsed, format);
|
|
4575
|
+
async getBlock(blockIdentifier) {
|
|
4576
|
+
return this.provider.getBlock(blockIdentifier);
|
|
4653
4577
|
}
|
|
4654
|
-
|
|
4655
|
-
return
|
|
4578
|
+
async getClassAt(contractAddress, blockIdentifier) {
|
|
4579
|
+
return this.provider.getClassAt(contractAddress, blockIdentifier);
|
|
4656
4580
|
}
|
|
4657
|
-
|
|
4658
|
-
return
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4581
|
+
async getClassHashAt(contractAddress, blockIdentifier) {
|
|
4582
|
+
return this.provider.getClassHashAt(contractAddress, blockIdentifier);
|
|
4583
|
+
}
|
|
4584
|
+
getClassByHash(classHash) {
|
|
4585
|
+
return this.provider.getClassByHash(classHash);
|
|
4586
|
+
}
|
|
4587
|
+
async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
4588
|
+
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
4589
|
+
}
|
|
4590
|
+
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
|
|
4591
|
+
return this.provider.getInvokeEstimateFee(
|
|
4592
|
+
invocationWithTxType,
|
|
4593
|
+
invocationDetails,
|
|
4594
|
+
blockIdentifier,
|
|
4595
|
+
skipValidate
|
|
4596
|
+
);
|
|
4597
|
+
}
|
|
4598
|
+
async getEstimateFeeBulk(invocations, blockIdentifier) {
|
|
4599
|
+
return this.provider.getEstimateFeeBulk(invocations, blockIdentifier);
|
|
4600
|
+
}
|
|
4601
|
+
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
4602
|
+
return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
|
|
4603
|
+
}
|
|
4604
|
+
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4605
|
+
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
|
|
4606
|
+
}
|
|
4607
|
+
async getTransaction(txHash) {
|
|
4608
|
+
return this.provider.getTransaction(txHash);
|
|
4609
|
+
}
|
|
4610
|
+
async getTransactionReceipt(txHash) {
|
|
4611
|
+
return this.provider.getTransactionReceipt(txHash);
|
|
4612
|
+
}
|
|
4613
|
+
async callContract(request, blockIdentifier) {
|
|
4614
|
+
return this.provider.callContract(request, blockIdentifier);
|
|
4615
|
+
}
|
|
4616
|
+
async invokeFunction(functionInvocation, details) {
|
|
4617
|
+
return this.provider.invokeFunction(functionInvocation, details);
|
|
4618
|
+
}
|
|
4619
|
+
async deployAccountContract(payload, details) {
|
|
4620
|
+
return this.provider.deployAccountContract(payload, details);
|
|
4621
|
+
}
|
|
4622
|
+
async declareContract(transaction, details) {
|
|
4623
|
+
return this.provider.declareContract(transaction, details);
|
|
4624
|
+
}
|
|
4625
|
+
async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4626
|
+
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
|
|
4627
|
+
}
|
|
4628
|
+
getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4629
|
+
return this.provider.getDeployAccountEstimateFee(
|
|
4630
|
+
transaction,
|
|
4631
|
+
details,
|
|
4632
|
+
blockIdentifier,
|
|
4633
|
+
skipValidate
|
|
4634
|
+
);
|
|
4635
|
+
}
|
|
4636
|
+
async getCode(contractAddress, blockIdentifier) {
|
|
4637
|
+
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
4638
|
+
}
|
|
4639
|
+
async waitForTransaction(txHash, options) {
|
|
4640
|
+
return this.provider.waitForTransaction(txHash, options);
|
|
4641
|
+
}
|
|
4642
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
|
|
4643
|
+
return this.provider.getSimulateTransaction(
|
|
4644
|
+
invocation,
|
|
4645
|
+
invocationDetails,
|
|
4646
|
+
blockIdentifier,
|
|
4647
|
+
skipValidate
|
|
4664
4648
|
);
|
|
4665
4649
|
}
|
|
4650
|
+
async getStateUpdate(blockIdentifier) {
|
|
4651
|
+
return this.provider.getStateUpdate(blockIdentifier);
|
|
4652
|
+
}
|
|
4653
|
+
async getStarkName(address, StarknetIdContract2) {
|
|
4654
|
+
return getStarkName(this, address, StarknetIdContract2);
|
|
4655
|
+
}
|
|
4656
|
+
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4657
|
+
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4658
|
+
}
|
|
4659
|
+
};
|
|
4660
|
+
|
|
4661
|
+
// src/provider/interface.ts
|
|
4662
|
+
var ProviderInterface = class {
|
|
4666
4663
|
};
|
|
4667
4664
|
|
|
4665
|
+
// src/provider/index.ts
|
|
4666
|
+
var defaultProvider = new Provider();
|
|
4667
|
+
|
|
4668
4668
|
// src/contract/default.ts
|
|
4669
4669
|
var splitArgsAndOptions = (args) => {
|
|
4670
4670
|
const options = [
|
|
@@ -4674,13 +4674,14 @@ var splitArgsAndOptions = (args) => {
|
|
|
4674
4674
|
"formatResponse",
|
|
4675
4675
|
"maxFee",
|
|
4676
4676
|
"nonce",
|
|
4677
|
-
"signature"
|
|
4677
|
+
"signature",
|
|
4678
|
+
"addressSalt"
|
|
4678
4679
|
];
|
|
4679
4680
|
const lastArg = args[args.length - 1];
|
|
4680
4681
|
if (typeof lastArg === "object" && options.some((x) => x in lastArg)) {
|
|
4681
4682
|
return { args, options: args.pop() };
|
|
4682
4683
|
}
|
|
4683
|
-
return { args
|
|
4684
|
+
return { args };
|
|
4684
4685
|
};
|
|
4685
4686
|
function buildCall(contract, functionAbi) {
|
|
4686
4687
|
return async function(...args) {
|
|
@@ -4717,20 +4718,20 @@ function buildEstimate(contract, functionAbi) {
|
|
|
4717
4718
|
return contract.estimate(functionAbi.name, args);
|
|
4718
4719
|
};
|
|
4719
4720
|
}
|
|
4720
|
-
|
|
4721
|
-
if (
|
|
4722
|
-
return
|
|
4723
|
-
|
|
4724
|
-
|
|
4721
|
+
function getCalldata(args, callback) {
|
|
4722
|
+
if ("__compiled__" in args)
|
|
4723
|
+
return args;
|
|
4724
|
+
if (Array.isArray(args[0]) && "__compiled__" in args[0])
|
|
4725
|
+
return args[0];
|
|
4726
|
+
return callback();
|
|
4727
|
+
}
|
|
4725
4728
|
var Contract = class {
|
|
4726
|
-
constructor(abi, address, providerOrAccount = defaultProvider
|
|
4727
|
-
this.version = "0";
|
|
4729
|
+
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
4728
4730
|
this.address = address && address.toLowerCase();
|
|
4729
4731
|
this.providerOrAccount = providerOrAccount;
|
|
4730
4732
|
this.callData = new CallData(abi);
|
|
4731
4733
|
this.structs = CallData.getAbiStruct(abi);
|
|
4732
4734
|
this.abi = abi;
|
|
4733
|
-
this.version = cairoVersion;
|
|
4734
4735
|
const options = { enumerable: true, value: {}, writable: false };
|
|
4735
4736
|
Object.defineProperties(this, {
|
|
4736
4737
|
functions: { enumerable: true, value: {}, writable: false },
|
|
@@ -4787,15 +4788,21 @@ var Contract = class {
|
|
|
4787
4788
|
}
|
|
4788
4789
|
return this;
|
|
4789
4790
|
}
|
|
4790
|
-
async call(method, args = [],
|
|
4791
|
+
async call(method, args = [], {
|
|
4792
|
+
parseRequest = true,
|
|
4793
|
+
parseResponse = true,
|
|
4794
|
+
formatResponse = void 0,
|
|
4795
|
+
blockIdentifier = void 0
|
|
4796
|
+
} = {}) {
|
|
4791
4797
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4792
|
-
const
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4798
|
+
const calldata = getCalldata(args, () => {
|
|
4799
|
+
if (parseRequest) {
|
|
4800
|
+
this.callData.validate("CALL", method, args);
|
|
4801
|
+
return this.callData.compile(method, args);
|
|
4802
|
+
}
|
|
4803
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
4804
|
+
return args;
|
|
4805
|
+
});
|
|
4799
4806
|
return this.providerOrAccount.callContract(
|
|
4800
4807
|
{
|
|
4801
4808
|
contractAddress: this.address,
|
|
@@ -4804,25 +4811,25 @@ var Contract = class {
|
|
|
4804
4811
|
},
|
|
4805
4812
|
blockIdentifier
|
|
4806
4813
|
).then((x) => {
|
|
4807
|
-
if (!
|
|
4814
|
+
if (!parseResponse) {
|
|
4808
4815
|
return x.result;
|
|
4809
4816
|
}
|
|
4810
|
-
if (
|
|
4811
|
-
return this.callData.format(method, x.result,
|
|
4817
|
+
if (formatResponse) {
|
|
4818
|
+
return this.callData.format(method, x.result, formatResponse);
|
|
4812
4819
|
}
|
|
4813
4820
|
return this.callData.parse(method, x.result);
|
|
4814
4821
|
});
|
|
4815
4822
|
}
|
|
4816
|
-
invoke(method, args = [],
|
|
4817
|
-
parseRequest: true
|
|
4818
|
-
}) {
|
|
4823
|
+
invoke(method, args = [], { parseRequest = true, maxFee, nonce, signature } = {}) {
|
|
4819
4824
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4825
|
+
const calldata = getCalldata(args, () => {
|
|
4826
|
+
if (parseRequest) {
|
|
4827
|
+
this.callData.validate("INVOKE", method, args);
|
|
4828
|
+
return this.callData.compile(method, args);
|
|
4829
|
+
}
|
|
4830
|
+
console.warn("Invoke skipped parsing but provided rawArgs, possible malfunction request");
|
|
4831
|
+
return args;
|
|
4832
|
+
});
|
|
4826
4833
|
const invocation = {
|
|
4827
4834
|
contractAddress: this.address,
|
|
4828
4835
|
calldata,
|
|
@@ -4830,40 +4837,36 @@ var Contract = class {
|
|
|
4830
4837
|
};
|
|
4831
4838
|
if ("execute" in this.providerOrAccount) {
|
|
4832
4839
|
return this.providerOrAccount.execute(invocation, void 0, {
|
|
4833
|
-
maxFee
|
|
4834
|
-
nonce
|
|
4840
|
+
maxFee,
|
|
4841
|
+
nonce
|
|
4835
4842
|
});
|
|
4836
4843
|
}
|
|
4837
|
-
if (!
|
|
4844
|
+
if (!nonce)
|
|
4838
4845
|
throw new Error(`Nonce is required when invoking a function without an account`);
|
|
4839
|
-
}
|
|
4840
4846
|
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
4841
4847
|
return this.providerOrAccount.invokeFunction(
|
|
4842
4848
|
{
|
|
4843
4849
|
...invocation,
|
|
4844
|
-
signature
|
|
4850
|
+
signature
|
|
4845
4851
|
},
|
|
4846
4852
|
{
|
|
4847
|
-
nonce
|
|
4853
|
+
nonce
|
|
4848
4854
|
}
|
|
4849
4855
|
);
|
|
4850
4856
|
}
|
|
4851
4857
|
async estimate(method, args = []) {
|
|
4852
|
-
var _a;
|
|
4853
4858
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4854
|
-
if (!((
|
|
4859
|
+
if (!getCalldata(args, () => false)) {
|
|
4855
4860
|
this.callData.validate("INVOKE", method, args);
|
|
4856
4861
|
}
|
|
4857
|
-
const invocation = this.
|
|
4862
|
+
const invocation = this.populate(method, args);
|
|
4858
4863
|
if ("estimateInvokeFee" in this.providerOrAccount) {
|
|
4859
4864
|
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
4860
4865
|
}
|
|
4861
4866
|
throw Error("Contract must be connected to the account contract to estimate");
|
|
4862
4867
|
}
|
|
4863
4868
|
populate(method, args = []) {
|
|
4864
|
-
|
|
4865
|
-
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
4866
|
-
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);
|
|
4869
|
+
const calldata = getCalldata(args, () => this.callData.compile(method, args));
|
|
4867
4870
|
return {
|
|
4868
4871
|
contractAddress: this.address,
|
|
4869
4872
|
entrypoint: method,
|
|
@@ -4883,36 +4886,24 @@ var ContractFactory = class {
|
|
|
4883
4886
|
this.compiledContract = compiledContract;
|
|
4884
4887
|
this.account = account;
|
|
4885
4888
|
this.classHash = classHash;
|
|
4886
|
-
this.
|
|
4889
|
+
this.CallData = new CallData(abi);
|
|
4887
4890
|
}
|
|
4888
4891
|
async deploy(...args) {
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
if (typeof arg !== "object")
|
|
4895
|
-
return;
|
|
4896
|
-
if ("addressSalt" in arg) {
|
|
4897
|
-
addressSalt = arg.addressSalt;
|
|
4898
|
-
}
|
|
4899
|
-
if ("parseRequest" in arg) {
|
|
4900
|
-
parseRequest = arg.parseRequest;
|
|
4892
|
+
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
4893
|
+
const constructorCalldata = getCalldata(param, () => {
|
|
4894
|
+
if (options.parseRequest) {
|
|
4895
|
+
this.CallData.validate("DEPLOY", "constructor", param);
|
|
4896
|
+
return this.CallData.compile("constructor", param);
|
|
4901
4897
|
}
|
|
4898
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
4899
|
+
return param;
|
|
4902
4900
|
});
|
|
4903
|
-
if (!parseRequest || ((_a = args[0]) == null ? void 0 : _a.compiled)) {
|
|
4904
|
-
constructorCalldata = args[0];
|
|
4905
|
-
} else {
|
|
4906
|
-
this.callData.validate("DEPLOY", "constructor", args);
|
|
4907
|
-
const { inputs } = this.abi.find((abi) => abi.type === "constructor");
|
|
4908
|
-
constructorCalldata = this.callData.compile(args, inputs);
|
|
4909
|
-
}
|
|
4910
4901
|
const {
|
|
4911
4902
|
deploy: { contract_address, transaction_hash }
|
|
4912
4903
|
} = await this.account.declareAndDeploy({
|
|
4913
4904
|
contract: this.compiledContract,
|
|
4914
4905
|
constructorCalldata,
|
|
4915
|
-
salt: addressSalt
|
|
4906
|
+
salt: options.addressSalt
|
|
4916
4907
|
});
|
|
4917
4908
|
assert(Boolean(contract_address), "Deployment of the contract failed");
|
|
4918
4909
|
const contractInstance = new Contract(
|
|
@@ -5540,7 +5531,7 @@ var Account = class extends Provider {
|
|
|
5540
5531
|
unique = true,
|
|
5541
5532
|
constructorCalldata = []
|
|
5542
5533
|
} = it;
|
|
5543
|
-
const compiledConstructorCallData =
|
|
5534
|
+
const compiledConstructorCallData = CallData.compile(constructorCalldata);
|
|
5544
5535
|
const deploySalt = salt ?? randomAddress();
|
|
5545
5536
|
return {
|
|
5546
5537
|
call: {
|
|
@@ -5564,7 +5555,10 @@ var Account = class extends Provider {
|
|
|
5564
5555
|
});
|
|
5565
5556
|
const calls = params.map((it) => it.call);
|
|
5566
5557
|
const addresses = params.map((it) => it.address);
|
|
5567
|
-
const invokeResponse = await this.execute(calls, void 0,
|
|
5558
|
+
const invokeResponse = await this.execute(calls, void 0, {
|
|
5559
|
+
...details,
|
|
5560
|
+
cairoVersion: "0"
|
|
5561
|
+
});
|
|
5568
5562
|
return {
|
|
5569
5563
|
...invokeResponse,
|
|
5570
5564
|
contract_address: addresses
|
|
@@ -5636,7 +5630,7 @@ var Account = class extends Provider {
|
|
|
5636
5630
|
await this.callContract({
|
|
5637
5631
|
contractAddress: this.address,
|
|
5638
5632
|
entrypoint: "isValidSignature",
|
|
5639
|
-
calldata:
|
|
5633
|
+
calldata: CallData.compile({
|
|
5640
5634
|
hash: toBigInt(hash).toString(),
|
|
5641
5635
|
signature: formatSignature(signature)
|
|
5642
5636
|
})
|
|
@@ -5722,7 +5716,7 @@ var Account = class extends Provider {
|
|
|
5722
5716
|
unique = true,
|
|
5723
5717
|
constructorCalldata = []
|
|
5724
5718
|
} = it;
|
|
5725
|
-
const compiledConstructorCallData =
|
|
5719
|
+
const compiledConstructorCallData = CallData.compile(constructorCalldata);
|
|
5726
5720
|
return {
|
|
5727
5721
|
contractAddress: UDC.ADDRESS,
|
|
5728
5722
|
entrypoint: UDC.ENTRYPOINT,
|
|
@@ -5766,8 +5760,8 @@ var Account = class extends Provider {
|
|
|
5766
5760
|
}
|
|
5767
5761
|
};
|
|
5768
5762
|
}
|
|
5769
|
-
async getStarkName(address = this.address,
|
|
5770
|
-
return super.getStarkName(address,
|
|
5763
|
+
async getStarkName(address = this.address, StarknetIdContract2) {
|
|
5764
|
+
return super.getStarkName(address, StarknetIdContract2);
|
|
5771
5765
|
}
|
|
5772
5766
|
};
|
|
5773
5767
|
|
|
@@ -5838,6 +5832,7 @@ export {
|
|
|
5838
5832
|
encode_exports as encode,
|
|
5839
5833
|
fixProto,
|
|
5840
5834
|
fixStack,
|
|
5835
|
+
getCalldata,
|
|
5841
5836
|
getChecksumAddress,
|
|
5842
5837
|
hash_exports as hash,
|
|
5843
5838
|
isUrl,
|
|
@@ -5846,7 +5841,9 @@ export {
|
|
|
5846
5841
|
num_exports as num,
|
|
5847
5842
|
number,
|
|
5848
5843
|
shortString_exports as shortString,
|
|
5844
|
+
splitArgsAndOptions,
|
|
5849
5845
|
stark_exports as stark,
|
|
5846
|
+
starknetId_exports as starknetId,
|
|
5850
5847
|
transaction_exports as transaction,
|
|
5851
5848
|
typedData_exports as typedData,
|
|
5852
5849
|
uint256_exports as uint256,
|