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.js
CHANGED
|
@@ -55,6 +55,7 @@ __export(src_exports, {
|
|
|
55
55
|
encode: () => encode_exports,
|
|
56
56
|
fixProto: () => fixProto,
|
|
57
57
|
fixStack: () => fixStack,
|
|
58
|
+
getCalldata: () => getCalldata,
|
|
58
59
|
getChecksumAddress: () => getChecksumAddress,
|
|
59
60
|
hash: () => hash_exports,
|
|
60
61
|
isUrl: () => isUrl,
|
|
@@ -63,7 +64,9 @@ __export(src_exports, {
|
|
|
63
64
|
num: () => num_exports,
|
|
64
65
|
number: () => number,
|
|
65
66
|
shortString: () => shortString_exports,
|
|
67
|
+
splitArgsAndOptions: () => splitArgsAndOptions,
|
|
66
68
|
stark: () => stark_exports,
|
|
69
|
+
starknetId: () => starknetId_exports,
|
|
67
70
|
transaction: () => transaction_exports,
|
|
68
71
|
typedData: () => typedData_exports,
|
|
69
72
|
uint256: () => uint256_exports,
|
|
@@ -2547,6 +2550,9 @@ function felt(it) {
|
|
|
2547
2550
|
if (typeof it === "string" && isStringWholeNumber(it)) {
|
|
2548
2551
|
return it;
|
|
2549
2552
|
}
|
|
2553
|
+
if (typeof it === "boolean") {
|
|
2554
|
+
return `${+it}`;
|
|
2555
|
+
}
|
|
2550
2556
|
throw new Error(`${it} can't be computed by felt()`);
|
|
2551
2557
|
}
|
|
2552
2558
|
|
|
@@ -2833,7 +2839,6 @@ function extractContractHashes(payload) {
|
|
|
2833
2839
|
// src/utils/stark.ts
|
|
2834
2840
|
var stark_exports = {};
|
|
2835
2841
|
__export(stark_exports, {
|
|
2836
|
-
compileCalldata: () => compileCalldata,
|
|
2837
2842
|
compressProgram: () => compressProgram,
|
|
2838
2843
|
estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
|
|
2839
2844
|
formatSignature: () => formatSignature,
|
|
@@ -2875,21 +2880,6 @@ function signatureToDecimalArray(sig) {
|
|
|
2875
2880
|
function signatureToHexArray(sig) {
|
|
2876
2881
|
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
2877
2882
|
}
|
|
2878
|
-
function compileCalldata(args) {
|
|
2879
|
-
const compiledData = Object.values(args).flatMap((value) => {
|
|
2880
|
-
if (Array.isArray(value))
|
|
2881
|
-
return [toBigInt(value.length).toString(), ...value.map((x) => toBigInt(x).toString())];
|
|
2882
|
-
if (typeof value === "object" && "type" in value)
|
|
2883
|
-
return Object.entries(value).filter(([k]) => k !== "type").map(([, v]) => toBigInt(v).toString());
|
|
2884
|
-
return toBigInt(value).toString();
|
|
2885
|
-
});
|
|
2886
|
-
Object.defineProperty(compiledData, "compiled", {
|
|
2887
|
-
enumerable: false,
|
|
2888
|
-
writable: false,
|
|
2889
|
-
value: true
|
|
2890
|
-
});
|
|
2891
|
-
return compiledData;
|
|
2892
|
-
}
|
|
2893
2883
|
function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
|
|
2894
2884
|
const overHeadPercent = Math.round((1 + overhead) * 100);
|
|
2895
2885
|
return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
|
|
@@ -3003,308 +2993,826 @@ var HttpError = class extends LibraryError {
|
|
|
3003
2993
|
}
|
|
3004
2994
|
};
|
|
3005
2995
|
|
|
3006
|
-
// src/utils/
|
|
3007
|
-
var
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
str = str.substring(0, str.length - 1);
|
|
3017
|
-
k += 1;
|
|
2996
|
+
// src/utils/calldata/formatter.ts
|
|
2997
|
+
var guard = {
|
|
2998
|
+
isBN: (data, type, key) => {
|
|
2999
|
+
if (!isBigInt(data[key]))
|
|
3000
|
+
throw new Error(
|
|
3001
|
+
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
3002
|
+
);
|
|
3003
|
+
},
|
|
3004
|
+
unknown: (data, type, key) => {
|
|
3005
|
+
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
3018
3006
|
}
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
subdomain /= basicSizePlusOne;
|
|
3027
|
-
if (code === BigInt(basicAlphabet.length)) {
|
|
3028
|
-
const nextSubdomain = subdomain / bigAlphabetSizePlusOne;
|
|
3029
|
-
if (nextSubdomain === ZERO) {
|
|
3030
|
-
const code2 = subdomain % bigAlphabetSizePlusOne;
|
|
3031
|
-
subdomain = nextSubdomain;
|
|
3032
|
-
if (code2 === ZERO)
|
|
3033
|
-
decoded += basicAlphabet[0];
|
|
3034
|
-
else
|
|
3035
|
-
decoded += bigAlphabet[Number(code2) - 1];
|
|
3036
|
-
} else {
|
|
3037
|
-
const code2 = subdomain % bigAlphabetSize;
|
|
3038
|
-
decoded += bigAlphabet[Number(code2)];
|
|
3039
|
-
subdomain /= bigAlphabetSize;
|
|
3040
|
-
}
|
|
3041
|
-
} else
|
|
3042
|
-
decoded += basicAlphabet[Number(code)];
|
|
3007
|
+
};
|
|
3008
|
+
function formatter(data, type, sameType) {
|
|
3009
|
+
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
3010
|
+
const elType = sameType ?? type[key];
|
|
3011
|
+
if (!(key in type) && !sameType) {
|
|
3012
|
+
acc[key] = value;
|
|
3013
|
+
return acc;
|
|
3043
3014
|
}
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3015
|
+
if (elType === "string") {
|
|
3016
|
+
if (Array.isArray(data[key])) {
|
|
3017
|
+
const arrayStr = formatter(
|
|
3018
|
+
data[key],
|
|
3019
|
+
data[key].map((_) => elType)
|
|
3020
|
+
);
|
|
3021
|
+
acc[key] = Object.values(arrayStr).join("");
|
|
3022
|
+
return acc;
|
|
3023
|
+
}
|
|
3024
|
+
guard.isBN(data, type, key);
|
|
3025
|
+
acc[key] = decodeShortString(value);
|
|
3026
|
+
return acc;
|
|
3027
|
+
}
|
|
3028
|
+
if (elType === "number") {
|
|
3029
|
+
guard.isBN(data, type, key);
|
|
3030
|
+
acc[key] = Number(value);
|
|
3031
|
+
return acc;
|
|
3032
|
+
}
|
|
3033
|
+
if (typeof elType === "function") {
|
|
3034
|
+
acc[key] = elType(value);
|
|
3035
|
+
return acc;
|
|
3036
|
+
}
|
|
3037
|
+
if (Array.isArray(elType)) {
|
|
3038
|
+
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
3039
|
+
acc[key] = Object.values(arrayObj);
|
|
3040
|
+
return acc;
|
|
3041
|
+
}
|
|
3042
|
+
if (typeof elType === "object") {
|
|
3043
|
+
acc[key] = formatter(data[key], elType);
|
|
3044
|
+
return acc;
|
|
3045
|
+
}
|
|
3046
|
+
guard.unknown(data, type, key);
|
|
3047
|
+
return acc;
|
|
3048
|
+
}, {});
|
|
3053
3049
|
}
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3050
|
+
|
|
3051
|
+
// src/utils/calldata/tuple.ts
|
|
3052
|
+
function parseNamedTuple(namedTuple) {
|
|
3053
|
+
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
3054
|
+
const type = namedTuple.substring(name.length + ":".length);
|
|
3055
|
+
return { name, type };
|
|
3056
|
+
}
|
|
3057
|
+
function parseSubTuple(s) {
|
|
3058
|
+
if (!s.includes("("))
|
|
3059
|
+
return { subTuple: [], result: s };
|
|
3060
|
+
const subTuple = [];
|
|
3061
|
+
let result = "";
|
|
3062
|
+
let i = 0;
|
|
3063
|
+
while (i < s.length) {
|
|
3064
|
+
if (s[i] === "(") {
|
|
3065
|
+
let counter = 1;
|
|
3066
|
+
const lBracket = i;
|
|
3067
|
+
i++;
|
|
3068
|
+
while (counter) {
|
|
3069
|
+
if (s[i] === ")")
|
|
3070
|
+
counter--;
|
|
3071
|
+
if (s[i] === "(")
|
|
3072
|
+
counter++;
|
|
3073
|
+
i++;
|
|
3077
3074
|
}
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
multiplier *= bigAlphabetSize;
|
|
3075
|
+
subTuple.push(s.substring(lBracket, i));
|
|
3076
|
+
result += " ";
|
|
3077
|
+
i--;
|
|
3078
|
+
} else {
|
|
3079
|
+
result += s[i];
|
|
3084
3080
|
}
|
|
3081
|
+
i++;
|
|
3085
3082
|
}
|
|
3086
|
-
return
|
|
3083
|
+
return {
|
|
3084
|
+
subTuple,
|
|
3085
|
+
result
|
|
3086
|
+
};
|
|
3087
3087
|
}
|
|
3088
|
-
function
|
|
3089
|
-
const
|
|
3090
|
-
const
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3088
|
+
function extractCairo0Tuple(type) {
|
|
3089
|
+
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
3090
|
+
const { subTuple, result } = parseSubTuple(cleanType);
|
|
3091
|
+
let recomposed = result.split(",").map((it) => {
|
|
3092
|
+
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
3093
|
+
});
|
|
3094
|
+
if (isTypeNamedTuple(type)) {
|
|
3095
|
+
recomposed = recomposed.reduce((acc, it) => {
|
|
3096
|
+
return acc.concat(parseNamedTuple(it));
|
|
3097
|
+
}, []);
|
|
3098
3098
|
}
|
|
3099
|
+
return recomposed;
|
|
3099
3100
|
}
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
const chainId = await provider.getChainId();
|
|
3104
|
-
const contract = StarknetIdContract ?? getStarknetIdContract(chainId);
|
|
3105
|
-
try {
|
|
3106
|
-
const hexDomain = await provider.callContract({
|
|
3107
|
-
contractAddress: contract,
|
|
3108
|
-
entrypoint: "address_to_domain",
|
|
3109
|
-
calldata: compileCalldata({
|
|
3110
|
-
address
|
|
3111
|
-
})
|
|
3112
|
-
});
|
|
3113
|
-
const decimalDomain = hexDomain.result.map((element) => BigInt(element)).slice(1);
|
|
3114
|
-
const stringDomain = useDecoded(decimalDomain);
|
|
3115
|
-
if (!stringDomain) {
|
|
3116
|
-
throw Error("Starkname not found");
|
|
3117
|
-
}
|
|
3118
|
-
return stringDomain;
|
|
3119
|
-
} catch (e) {
|
|
3120
|
-
if (e instanceof Error && e.message === "Starkname not found") {
|
|
3121
|
-
throw e;
|
|
3122
|
-
}
|
|
3123
|
-
throw Error("Could not get stark name");
|
|
3124
|
-
}
|
|
3101
|
+
function extractCairo1Tuple(type) {
|
|
3102
|
+
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
3103
|
+
return cleanType.split(",");
|
|
3125
3104
|
}
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
try {
|
|
3130
|
-
const addressData = await provider.callContract({
|
|
3131
|
-
contractAddress: contract,
|
|
3132
|
-
entrypoint: "domain_to_address",
|
|
3133
|
-
calldata: compileCalldata({
|
|
3134
|
-
domain: [useEncoded(name.replace(".stark", "")).toString(10)]
|
|
3135
|
-
})
|
|
3136
|
-
});
|
|
3137
|
-
return addressData.result[0];
|
|
3138
|
-
} catch {
|
|
3139
|
-
throw Error("Could not get address from stark name");
|
|
3105
|
+
function extractTupleMemberTypes(type) {
|
|
3106
|
+
if (isCairo1Type(type)) {
|
|
3107
|
+
return extractCairo1Tuple(type);
|
|
3140
3108
|
}
|
|
3109
|
+
return extractCairo0Tuple(type);
|
|
3141
3110
|
}
|
|
3142
3111
|
|
|
3143
|
-
// src/
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
}
|
|
3154
|
-
setIdentifier(__identifier) {
|
|
3155
|
-
if (typeof __identifier === "string" && isHex(__identifier)) {
|
|
3156
|
-
this.hash = __identifier;
|
|
3157
|
-
} else if (typeof __identifier === "bigint") {
|
|
3158
|
-
this.hash = toHex(__identifier);
|
|
3159
|
-
} else if (typeof __identifier === "number") {
|
|
3160
|
-
this.number = __identifier;
|
|
3161
|
-
} else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
|
|
3162
|
-
this.tag = __identifier;
|
|
3163
|
-
} else {
|
|
3164
|
-
this.tag = "pending";
|
|
3165
|
-
}
|
|
3112
|
+
// src/utils/calldata/requestParser.ts
|
|
3113
|
+
function parseTuple(element, typeStr) {
|
|
3114
|
+
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
3115
|
+
const elements = Object.values(element);
|
|
3116
|
+
if (elements.length !== memberTypes.length) {
|
|
3117
|
+
throw Error(
|
|
3118
|
+
`ParseTuple: provided and expected abi tuple size do not match.
|
|
3119
|
+
provided: ${elements}
|
|
3120
|
+
expected: ${memberTypes}`
|
|
3121
|
+
);
|
|
3166
3122
|
}
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
if (this.number !== null) {
|
|
3178
|
-
return { block_number: this.number };
|
|
3179
|
-
}
|
|
3180
|
-
if (this.hash !== null) {
|
|
3181
|
-
return { block_hash: this.hash };
|
|
3182
|
-
}
|
|
3183
|
-
return this.tag;
|
|
3123
|
+
return memberTypes.map((it, dx) => {
|
|
3124
|
+
return {
|
|
3125
|
+
element: elements[dx],
|
|
3126
|
+
type: it.type ?? it
|
|
3127
|
+
};
|
|
3128
|
+
});
|
|
3129
|
+
}
|
|
3130
|
+
function parseCalldataValue(element, type, structs) {
|
|
3131
|
+
if (element === void 0) {
|
|
3132
|
+
throw Error(`Missing parameter for type ${type}`);
|
|
3184
3133
|
}
|
|
3185
|
-
|
|
3186
|
-
|
|
3134
|
+
if (Array.isArray(element)) {
|
|
3135
|
+
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
3187
3136
|
}
|
|
3188
|
-
|
|
3189
|
-
|
|
3137
|
+
if (isTypeUint256(type)) {
|
|
3138
|
+
const el_uint256 = uint256(element);
|
|
3139
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
3190
3140
|
}
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
retries: 200
|
|
3198
|
-
};
|
|
3199
|
-
var RpcProvider = class {
|
|
3200
|
-
constructor(optionsOrProvider) {
|
|
3201
|
-
this.responseParser = new RPCResponseParser();
|
|
3202
|
-
const { nodeUrl, retries, headers, blockIdentifier } = optionsOrProvider;
|
|
3203
|
-
this.nodeUrl = nodeUrl;
|
|
3204
|
-
this.retries = retries || defaultOptions.retries;
|
|
3205
|
-
this.headers = { ...defaultOptions.headers, ...headers };
|
|
3206
|
-
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
|
|
3207
|
-
this.getChainId();
|
|
3141
|
+
if (structs[type] && structs[type].members.length) {
|
|
3142
|
+
const { members } = structs[type];
|
|
3143
|
+
const subElement = element;
|
|
3144
|
+
return members.reduce((acc, it) => {
|
|
3145
|
+
return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs));
|
|
3146
|
+
}, []);
|
|
3208
3147
|
}
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
});
|
|
3148
|
+
if (isTypeTuple(type)) {
|
|
3149
|
+
const tupled = parseTuple(element, type);
|
|
3150
|
+
return tupled.reduce((acc, it) => {
|
|
3151
|
+
const parsedData = parseCalldataValue(it.element, it.type, structs);
|
|
3152
|
+
return acc.concat(parsedData);
|
|
3153
|
+
}, []);
|
|
3215
3154
|
}
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
const { code, message } = error;
|
|
3219
|
-
throw new LibraryError(`${code}: ${message}`);
|
|
3220
|
-
}
|
|
3155
|
+
if (typeof element === "object") {
|
|
3156
|
+
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
3221
3157
|
}
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3158
|
+
return felt(element);
|
|
3159
|
+
}
|
|
3160
|
+
function parseCalldataField(argsIterator, input, structs) {
|
|
3161
|
+
const { name, type } = input;
|
|
3162
|
+
let { value } = argsIterator.next();
|
|
3163
|
+
switch (true) {
|
|
3164
|
+
case isTypeArray(type):
|
|
3165
|
+
if (!Array.isArray(value) && !isText(value)) {
|
|
3166
|
+
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
3167
|
+
}
|
|
3168
|
+
if (typeof value === "string") {
|
|
3169
|
+
value = splitLongString(value);
|
|
3170
|
+
}
|
|
3171
|
+
const result = [];
|
|
3172
|
+
result.push(felt(value.length));
|
|
3173
|
+
const arrayType = getArrayType(input.type);
|
|
3174
|
+
return value.reduce((acc, el) => {
|
|
3175
|
+
if (isTypeFelt(arrayType) || isTypeUint(arrayType) || isTypeContractAddress(arrayType)) {
|
|
3176
|
+
acc.push(felt(el));
|
|
3177
|
+
} else if (isTypeBool(arrayType) && typeof el === "boolean") {
|
|
3178
|
+
acc.push(el.toString());
|
|
3179
|
+
} else {
|
|
3180
|
+
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
3181
|
+
}
|
|
3182
|
+
return acc;
|
|
3183
|
+
}, result);
|
|
3184
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
|
|
3185
|
+
return parseCalldataValue(value, type, structs);
|
|
3186
|
+
case isTypeBool(type):
|
|
3187
|
+
return `${+value}`;
|
|
3188
|
+
default:
|
|
3189
|
+
return felt(value);
|
|
3233
3190
|
}
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3191
|
+
}
|
|
3192
|
+
|
|
3193
|
+
// src/utils/calldata/responseParser.ts
|
|
3194
|
+
function parseResponseStruct(responseIterator, type, structs) {
|
|
3195
|
+
if (type in structs && structs[type]) {
|
|
3196
|
+
return structs[type].members.reduce((acc, el) => {
|
|
3197
|
+
acc[el.name] = parseResponseStruct(responseIterator, el.type, structs);
|
|
3198
|
+
return acc;
|
|
3199
|
+
}, {});
|
|
3237
3200
|
}
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3201
|
+
if (isTypeTuple(type)) {
|
|
3202
|
+
const memberTypes = extractTupleMemberTypes(type);
|
|
3203
|
+
return memberTypes.reduce((acc, it, idx) => {
|
|
3204
|
+
const tName = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
3205
|
+
const tType = (it == null ? void 0 : it.type) ? it.type : it;
|
|
3206
|
+
acc[tName] = parseResponseStruct(responseIterator, tType, structs);
|
|
3207
|
+
return acc;
|
|
3208
|
+
}, {});
|
|
3242
3209
|
}
|
|
3243
|
-
|
|
3244
|
-
|
|
3210
|
+
const temp = responseIterator.next().value;
|
|
3211
|
+
return BigInt(temp);
|
|
3212
|
+
}
|
|
3213
|
+
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
3214
|
+
const { name, type } = output;
|
|
3215
|
+
let temp;
|
|
3216
|
+
switch (true) {
|
|
3217
|
+
case isLen(name):
|
|
3218
|
+
temp = responseIterator.next().value;
|
|
3219
|
+
return BigInt(temp);
|
|
3220
|
+
case isTypeBool(type):
|
|
3221
|
+
temp = responseIterator.next().value;
|
|
3222
|
+
return Boolean(BigInt(temp));
|
|
3223
|
+
case isTypeUint256(type):
|
|
3224
|
+
const low = responseIterator.next().value;
|
|
3225
|
+
const high = responseIterator.next().value;
|
|
3226
|
+
return uint256ToBN({ low, high });
|
|
3227
|
+
case isTypeArray(type):
|
|
3228
|
+
const parsedDataArr = [];
|
|
3229
|
+
if (isCairo1Type(type)) {
|
|
3230
|
+
responseIterator.next();
|
|
3231
|
+
let it = responseIterator.next();
|
|
3232
|
+
while (!it.done) {
|
|
3233
|
+
parsedDataArr.push(BigInt(it.value));
|
|
3234
|
+
it = responseIterator.next();
|
|
3235
|
+
}
|
|
3236
|
+
return parsedDataArr;
|
|
3237
|
+
}
|
|
3238
|
+
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
3239
|
+
const arrLen = parsedResult[`${name}_len`];
|
|
3240
|
+
while (parsedDataArr.length < arrLen) {
|
|
3241
|
+
parsedDataArr.push(
|
|
3242
|
+
parseResponseStruct(responseIterator, output.type.replace("*", ""), structs)
|
|
3243
|
+
);
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
return parsedDataArr;
|
|
3247
|
+
case (type in structs || isTypeTuple(type)):
|
|
3248
|
+
return parseResponseStruct(responseIterator, type, structs);
|
|
3249
|
+
default:
|
|
3250
|
+
temp = responseIterator.next().value;
|
|
3251
|
+
return BigInt(temp);
|
|
3245
3252
|
}
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3253
|
+
}
|
|
3254
|
+
|
|
3255
|
+
// src/utils/calldata/validate.ts
|
|
3256
|
+
var validateFelt = (parameter, input) => {
|
|
3257
|
+
assert(
|
|
3258
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
3259
|
+
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
3260
|
+
);
|
|
3261
|
+
};
|
|
3262
|
+
var validateUint = (parameter, input) => {
|
|
3263
|
+
if (typeof parameter === "number") {
|
|
3264
|
+
assert(
|
|
3265
|
+
parameter <= Number.MAX_SAFE_INTEGER,
|
|
3266
|
+
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
3267
|
+
);
|
|
3249
3268
|
}
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3269
|
+
assert(
|
|
3270
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
3271
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
|
|
3272
|
+
);
|
|
3273
|
+
const param = toBigInt(parameter);
|
|
3274
|
+
switch (input.type) {
|
|
3275
|
+
case "core::integer::u8" /* u8 */:
|
|
3276
|
+
assert(
|
|
3277
|
+
param >= 0n && param <= 255n,
|
|
3278
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
3279
|
+
);
|
|
3280
|
+
break;
|
|
3281
|
+
case "core::integer::u16" /* u16 */:
|
|
3282
|
+
assert(
|
|
3283
|
+
param >= 0n && param <= 65535n,
|
|
3284
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
3285
|
+
);
|
|
3286
|
+
break;
|
|
3287
|
+
case "core::integer::u32" /* u32 */:
|
|
3288
|
+
assert(
|
|
3289
|
+
param >= 0n && param <= 4294967295n,
|
|
3290
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
3291
|
+
);
|
|
3292
|
+
break;
|
|
3293
|
+
case "core::integer::u64" /* u64 */:
|
|
3294
|
+
assert(
|
|
3295
|
+
param >= 0n && param <= 2n ** 64n - 1n,
|
|
3296
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
3297
|
+
);
|
|
3298
|
+
break;
|
|
3299
|
+
case "core::integer::u128" /* u128 */:
|
|
3300
|
+
assert(
|
|
3301
|
+
param >= 0n && param <= 2n ** 128n - 1n,
|
|
3302
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
3303
|
+
);
|
|
3304
|
+
break;
|
|
3305
|
+
case "core::integer::u256" /* u256 */:
|
|
3306
|
+
assert(
|
|
3307
|
+
param >= 0n && param <= 2n ** 256n - 1n,
|
|
3308
|
+
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
3309
|
+
);
|
|
3310
|
+
break;
|
|
3311
|
+
default:
|
|
3312
|
+
break;
|
|
3253
3313
|
}
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3314
|
+
};
|
|
3315
|
+
var validateBool = (parameter, input) => {
|
|
3316
|
+
assert(
|
|
3317
|
+
typeof parameter === "boolean",
|
|
3318
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
3319
|
+
);
|
|
3320
|
+
};
|
|
3321
|
+
var validateStruct = (parameter, input, structs) => {
|
|
3322
|
+
assert(
|
|
3323
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
3324
|
+
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
3325
|
+
);
|
|
3326
|
+
structs[input.type].members.forEach(({ name }) => {
|
|
3327
|
+
assert(
|
|
3328
|
+
Object.keys(parameter).includes(name),
|
|
3329
|
+
`Validate: arg ${input.name} should have a property ${name}`
|
|
3330
|
+
);
|
|
3331
|
+
});
|
|
3332
|
+
};
|
|
3333
|
+
var validateTuple = (parameter, input) => {
|
|
3334
|
+
assert(
|
|
3335
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
3336
|
+
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
3337
|
+
);
|
|
3338
|
+
};
|
|
3339
|
+
var validateArray = (parameter, input, structs) => {
|
|
3340
|
+
const baseType = getArrayType(input.type);
|
|
3341
|
+
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
3342
|
+
return;
|
|
3343
|
+
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
3344
|
+
switch (true) {
|
|
3345
|
+
case isTypeFelt(baseType):
|
|
3346
|
+
parameter.forEach((param) => validateFelt(param, input));
|
|
3347
|
+
break;
|
|
3348
|
+
case isTypeTuple(baseType):
|
|
3349
|
+
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
3350
|
+
break;
|
|
3351
|
+
case isTypeStruct(baseType, structs):
|
|
3352
|
+
parameter.forEach(
|
|
3353
|
+
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
3354
|
+
);
|
|
3355
|
+
break;
|
|
3356
|
+
case isTypeUint(baseType):
|
|
3357
|
+
parameter.forEach((param) => validateUint(param, input));
|
|
3358
|
+
break;
|
|
3359
|
+
case isTypeBool(baseType):
|
|
3360
|
+
parameter.forEach((param) => validateBool(param, input));
|
|
3361
|
+
break;
|
|
3362
|
+
default:
|
|
3363
|
+
throw new Error(
|
|
3364
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
3365
|
+
);
|
|
3267
3366
|
}
|
|
3268
|
-
|
|
3269
|
-
|
|
3367
|
+
};
|
|
3368
|
+
function validateFields(abiMethod, args, structs) {
|
|
3369
|
+
abiMethod.inputs.reduce((acc, input) => {
|
|
3370
|
+
const parameter = args[acc];
|
|
3371
|
+
switch (true) {
|
|
3372
|
+
case isLen(input.name):
|
|
3373
|
+
return acc;
|
|
3374
|
+
case isTypeFelt(input.type):
|
|
3375
|
+
validateFelt(parameter, input);
|
|
3376
|
+
break;
|
|
3377
|
+
case isTypeUint(input.type):
|
|
3378
|
+
validateUint(parameter, input);
|
|
3379
|
+
break;
|
|
3380
|
+
case isTypeBool(input.type):
|
|
3381
|
+
validateBool(parameter, input);
|
|
3382
|
+
break;
|
|
3383
|
+
case isTypeContractAddress(input.type):
|
|
3384
|
+
break;
|
|
3385
|
+
case isTypeStruct(input.type, structs):
|
|
3386
|
+
validateStruct(parameter, input, structs);
|
|
3387
|
+
break;
|
|
3388
|
+
case isTypeTuple(input.type):
|
|
3389
|
+
validateTuple(parameter, input);
|
|
3390
|
+
break;
|
|
3391
|
+
case isTypeArray(input.type):
|
|
3392
|
+
validateArray(parameter, input, structs);
|
|
3393
|
+
break;
|
|
3394
|
+
default:
|
|
3395
|
+
throw new Error(
|
|
3396
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
3397
|
+
);
|
|
3398
|
+
}
|
|
3399
|
+
return acc + 1;
|
|
3400
|
+
}, 0);
|
|
3401
|
+
}
|
|
3402
|
+
|
|
3403
|
+
// src/utils/calldata/index.ts
|
|
3404
|
+
var CallData = class {
|
|
3405
|
+
constructor(abi) {
|
|
3406
|
+
this.abi = abi;
|
|
3407
|
+
this.structs = CallData.getAbiStruct(abi);
|
|
3270
3408
|
}
|
|
3271
|
-
|
|
3272
|
-
|
|
3409
|
+
validate(type, method, args = []) {
|
|
3410
|
+
if (type !== "DEPLOY") {
|
|
3411
|
+
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
3412
|
+
if (abi.type !== "function")
|
|
3413
|
+
return false;
|
|
3414
|
+
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
3415
|
+
return type === "INVOKE" ? !isView : isView;
|
|
3416
|
+
}).map((abi) => abi.name);
|
|
3417
|
+
assert(
|
|
3418
|
+
invocableFunctionNames.includes(method),
|
|
3419
|
+
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
3420
|
+
);
|
|
3421
|
+
}
|
|
3422
|
+
const abiMethod = this.abi.find(
|
|
3423
|
+
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
3424
|
+
);
|
|
3425
|
+
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
3426
|
+
if (args.length !== inputsLength) {
|
|
3427
|
+
throw Error(
|
|
3428
|
+
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
3429
|
+
);
|
|
3430
|
+
}
|
|
3431
|
+
validateFields(abiMethod, args, this.structs);
|
|
3273
3432
|
}
|
|
3274
|
-
|
|
3275
|
-
const
|
|
3276
|
-
|
|
3433
|
+
compile(method, args) {
|
|
3434
|
+
const argsIterator = args[Symbol.iterator]();
|
|
3435
|
+
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
3436
|
+
return inputs.reduce(
|
|
3437
|
+
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
3438
|
+
[]
|
|
3439
|
+
);
|
|
3277
3440
|
}
|
|
3278
|
-
|
|
3279
|
-
const
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3441
|
+
static compile(rawArgs) {
|
|
3442
|
+
const createTree = (obj) => {
|
|
3443
|
+
const getEntries = (o, prefix = "") => {
|
|
3444
|
+
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
3445
|
+
return Object.entries(oe).flatMap(([k, v]) => {
|
|
3446
|
+
let value = v;
|
|
3447
|
+
if (isLongText(value))
|
|
3448
|
+
value = splitLongString(value);
|
|
3449
|
+
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
3450
|
+
if (isBigInt(value))
|
|
3451
|
+
return [[`${prefix}${kk}`, felt(value)]];
|
|
3452
|
+
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
3453
|
+
});
|
|
3454
|
+
};
|
|
3455
|
+
return Object.fromEntries(getEntries(obj));
|
|
3456
|
+
};
|
|
3457
|
+
let callTreeArray;
|
|
3458
|
+
if (!Array.isArray(rawArgs)) {
|
|
3459
|
+
const callTree = createTree(rawArgs);
|
|
3460
|
+
callTreeArray = Object.values(callTree);
|
|
3461
|
+
} else {
|
|
3462
|
+
const callObj = { ...rawArgs };
|
|
3463
|
+
const callTree = createTree(callObj);
|
|
3464
|
+
callTreeArray = Object.values(callTree);
|
|
3465
|
+
}
|
|
3466
|
+
Object.defineProperty(callTreeArray, "__compiled__", {
|
|
3467
|
+
enumerable: false,
|
|
3468
|
+
writable: false,
|
|
3469
|
+
value: true
|
|
3285
3470
|
});
|
|
3471
|
+
return callTreeArray;
|
|
3286
3472
|
}
|
|
3287
|
-
|
|
3288
|
-
|
|
3473
|
+
parse(method, response) {
|
|
3474
|
+
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
3475
|
+
const responseIterator = response.flat()[Symbol.iterator]();
|
|
3476
|
+
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
3477
|
+
const propName = output.name ?? idx;
|
|
3478
|
+
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
3479
|
+
if (acc[propName] && acc[`${propName}_len`]) {
|
|
3480
|
+
delete acc[`${propName}_len`];
|
|
3481
|
+
}
|
|
3482
|
+
return acc;
|
|
3483
|
+
}, {});
|
|
3484
|
+
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
3289
3485
|
}
|
|
3290
|
-
|
|
3291
|
-
|
|
3486
|
+
format(method, response, format) {
|
|
3487
|
+
const parsed = this.parse(method, response);
|
|
3488
|
+
return formatter(parsed, format);
|
|
3292
3489
|
}
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
|
|
3490
|
+
static abiInputsLength(inputs) {
|
|
3491
|
+
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3296
3492
|
}
|
|
3297
|
-
|
|
3298
|
-
return
|
|
3493
|
+
static getAbiStruct(abi) {
|
|
3494
|
+
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
3495
|
+
(acc, abiEntry) => ({
|
|
3496
|
+
...acc,
|
|
3497
|
+
[abiEntry.name]: abiEntry
|
|
3498
|
+
}),
|
|
3499
|
+
{}
|
|
3500
|
+
);
|
|
3299
3501
|
}
|
|
3300
|
-
|
|
3301
|
-
|
|
3502
|
+
};
|
|
3503
|
+
|
|
3504
|
+
// src/utils/starknetId.ts
|
|
3505
|
+
var starknetId_exports = {};
|
|
3506
|
+
__export(starknetId_exports, {
|
|
3507
|
+
StarknetIdContract: () => StarknetIdContract,
|
|
3508
|
+
getStarknetIdContract: () => getStarknetIdContract,
|
|
3509
|
+
useDecoded: () => useDecoded,
|
|
3510
|
+
useEncoded: () => useEncoded
|
|
3511
|
+
});
|
|
3512
|
+
var basicAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
|
3513
|
+
var basicSizePlusOne = BigInt(basicAlphabet.length + 1);
|
|
3514
|
+
var bigAlphabet = "\u8FD9\u6765";
|
|
3515
|
+
var basicAlphabetSize = BigInt(basicAlphabet.length);
|
|
3516
|
+
var bigAlphabetSize = BigInt(bigAlphabet.length);
|
|
3517
|
+
var bigAlphabetSizePlusOne = BigInt(bigAlphabet.length + 1);
|
|
3518
|
+
function extractStars(str) {
|
|
3519
|
+
let k = 0;
|
|
3520
|
+
while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
|
|
3521
|
+
str = str.substring(0, str.length - 1);
|
|
3522
|
+
k += 1;
|
|
3302
3523
|
}
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3524
|
+
return [str, k];
|
|
3525
|
+
}
|
|
3526
|
+
function useDecoded(encoded) {
|
|
3527
|
+
let decoded = "";
|
|
3528
|
+
encoded.forEach((subdomain) => {
|
|
3529
|
+
while (subdomain !== ZERO) {
|
|
3530
|
+
const code = subdomain % basicSizePlusOne;
|
|
3531
|
+
subdomain /= basicSizePlusOne;
|
|
3532
|
+
if (code === BigInt(basicAlphabet.length)) {
|
|
3533
|
+
const nextSubdomain = subdomain / bigAlphabetSizePlusOne;
|
|
3534
|
+
if (nextSubdomain === ZERO) {
|
|
3535
|
+
const code2 = subdomain % bigAlphabetSizePlusOne;
|
|
3536
|
+
subdomain = nextSubdomain;
|
|
3537
|
+
if (code2 === ZERO)
|
|
3538
|
+
decoded += basicAlphabet[0];
|
|
3539
|
+
else
|
|
3540
|
+
decoded += bigAlphabet[Number(code2) - 1];
|
|
3541
|
+
} else {
|
|
3542
|
+
const code2 = subdomain % bigAlphabetSize;
|
|
3543
|
+
decoded += bigAlphabet[Number(code2)];
|
|
3544
|
+
subdomain /= bigAlphabetSize;
|
|
3545
|
+
}
|
|
3546
|
+
} else
|
|
3547
|
+
decoded += basicAlphabet[Number(code)];
|
|
3548
|
+
}
|
|
3549
|
+
const [str, k] = extractStars(decoded);
|
|
3550
|
+
if (k)
|
|
3551
|
+
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));
|
|
3552
|
+
decoded += ".";
|
|
3553
|
+
});
|
|
3554
|
+
if (!decoded) {
|
|
3555
|
+
return decoded;
|
|
3306
3556
|
}
|
|
3307
|
-
|
|
3557
|
+
return decoded.concat("stark");
|
|
3558
|
+
}
|
|
3559
|
+
function useEncoded(decoded) {
|
|
3560
|
+
let encoded = BigInt(0);
|
|
3561
|
+
let multiplier = BigInt(1);
|
|
3562
|
+
if (decoded.endsWith(bigAlphabet[0] + basicAlphabet[1])) {
|
|
3563
|
+
const [str, k] = extractStars(decoded.substring(0, decoded.length - 2));
|
|
3564
|
+
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
|
|
3565
|
+
} else {
|
|
3566
|
+
const [str, k] = extractStars(decoded);
|
|
3567
|
+
if (k)
|
|
3568
|
+
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
|
|
3569
|
+
}
|
|
3570
|
+
for (let i = 0; i < decoded.length; i += 1) {
|
|
3571
|
+
const char = decoded[i];
|
|
3572
|
+
const index = basicAlphabet.indexOf(char);
|
|
3573
|
+
const bnIndex = BigInt(basicAlphabet.indexOf(char));
|
|
3574
|
+
if (index !== -1) {
|
|
3575
|
+
if (i === decoded.length - 1 && decoded[i] === basicAlphabet[0]) {
|
|
3576
|
+
encoded += multiplier * basicAlphabetSize;
|
|
3577
|
+
multiplier *= basicSizePlusOne;
|
|
3578
|
+
multiplier *= basicSizePlusOne;
|
|
3579
|
+
} else {
|
|
3580
|
+
encoded += multiplier * bnIndex;
|
|
3581
|
+
multiplier *= basicSizePlusOne;
|
|
3582
|
+
}
|
|
3583
|
+
} else if (bigAlphabet.indexOf(char) !== -1) {
|
|
3584
|
+
encoded += multiplier * basicAlphabetSize;
|
|
3585
|
+
multiplier *= basicSizePlusOne;
|
|
3586
|
+
const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
|
|
3587
|
+
encoded += multiplier * BigInt(newid);
|
|
3588
|
+
multiplier *= bigAlphabetSize;
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
return encoded;
|
|
3592
|
+
}
|
|
3593
|
+
var StarknetIdContract = /* @__PURE__ */ ((StarknetIdContract2) => {
|
|
3594
|
+
StarknetIdContract2["MAINNET"] = "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678";
|
|
3595
|
+
StarknetIdContract2["TESTNET"] = "0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce";
|
|
3596
|
+
return StarknetIdContract2;
|
|
3597
|
+
})(StarknetIdContract || {});
|
|
3598
|
+
function getStarknetIdContract(chainId) {
|
|
3599
|
+
switch (chainId) {
|
|
3600
|
+
case "0x534e5f4d41494e" /* SN_MAIN */:
|
|
3601
|
+
return "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678" /* MAINNET */;
|
|
3602
|
+
case "0x534e5f474f45524c49" /* SN_GOERLI */:
|
|
3603
|
+
return "0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce" /* TESTNET */;
|
|
3604
|
+
default:
|
|
3605
|
+
throw new Error("Starknet.id is not yet deployed on this network");
|
|
3606
|
+
}
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
// src/provider/starknetId.ts
|
|
3610
|
+
async function getStarkName(provider, address, StarknetIdContract2) {
|
|
3611
|
+
const chainId = await provider.getChainId();
|
|
3612
|
+
const contract = StarknetIdContract2 ?? getStarknetIdContract(chainId);
|
|
3613
|
+
try {
|
|
3614
|
+
const hexDomain = await provider.callContract({
|
|
3615
|
+
contractAddress: contract,
|
|
3616
|
+
entrypoint: "address_to_domain",
|
|
3617
|
+
calldata: CallData.compile({
|
|
3618
|
+
address
|
|
3619
|
+
})
|
|
3620
|
+
});
|
|
3621
|
+
const decimalDomain = hexDomain.result.map((element) => BigInt(element)).slice(1);
|
|
3622
|
+
const stringDomain = useDecoded(decimalDomain);
|
|
3623
|
+
if (!stringDomain) {
|
|
3624
|
+
throw Error("Starkname not found");
|
|
3625
|
+
}
|
|
3626
|
+
return stringDomain;
|
|
3627
|
+
} catch (e) {
|
|
3628
|
+
if (e instanceof Error && e.message === "Starkname not found") {
|
|
3629
|
+
throw e;
|
|
3630
|
+
}
|
|
3631
|
+
throw Error("Could not get stark name");
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
async function getAddressFromStarkName(provider, name, StarknetIdContract2) {
|
|
3635
|
+
const chainId = await provider.getChainId();
|
|
3636
|
+
const contract = StarknetIdContract2 ?? getStarknetIdContract(chainId);
|
|
3637
|
+
try {
|
|
3638
|
+
const addressData = await provider.callContract({
|
|
3639
|
+
contractAddress: contract,
|
|
3640
|
+
entrypoint: "domain_to_address",
|
|
3641
|
+
calldata: CallData.compile({
|
|
3642
|
+
domain: [useEncoded(name.replace(".stark", "")).toString(10)]
|
|
3643
|
+
})
|
|
3644
|
+
});
|
|
3645
|
+
return addressData.result[0];
|
|
3646
|
+
} catch {
|
|
3647
|
+
throw Error("Could not get address from stark name");
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
|
|
3651
|
+
// src/provider/utils.ts
|
|
3652
|
+
var validBlockTags = ["latest", "pending"];
|
|
3653
|
+
var Block = class {
|
|
3654
|
+
constructor(_identifier) {
|
|
3655
|
+
this.hash = null;
|
|
3656
|
+
this.number = null;
|
|
3657
|
+
this.tag = null;
|
|
3658
|
+
this.valueOf = () => this.number;
|
|
3659
|
+
this.toString = () => this.hash;
|
|
3660
|
+
this.setIdentifier(_identifier);
|
|
3661
|
+
}
|
|
3662
|
+
setIdentifier(__identifier) {
|
|
3663
|
+
if (typeof __identifier === "string" && isHex(__identifier)) {
|
|
3664
|
+
this.hash = __identifier;
|
|
3665
|
+
} else if (typeof __identifier === "bigint") {
|
|
3666
|
+
this.hash = toHex(__identifier);
|
|
3667
|
+
} else if (typeof __identifier === "number") {
|
|
3668
|
+
this.number = __identifier;
|
|
3669
|
+
} else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
|
|
3670
|
+
this.tag = __identifier;
|
|
3671
|
+
} else {
|
|
3672
|
+
this.tag = "pending";
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
get queryIdentifier() {
|
|
3676
|
+
if (this.number !== null) {
|
|
3677
|
+
return `blockNumber=${this.number}`;
|
|
3678
|
+
}
|
|
3679
|
+
if (this.hash !== null) {
|
|
3680
|
+
return `blockHash=${this.hash}`;
|
|
3681
|
+
}
|
|
3682
|
+
return `blockNumber=${this.tag}`;
|
|
3683
|
+
}
|
|
3684
|
+
get identifier() {
|
|
3685
|
+
if (this.number !== null) {
|
|
3686
|
+
return { block_number: this.number };
|
|
3687
|
+
}
|
|
3688
|
+
if (this.hash !== null) {
|
|
3689
|
+
return { block_hash: this.hash };
|
|
3690
|
+
}
|
|
3691
|
+
return this.tag;
|
|
3692
|
+
}
|
|
3693
|
+
set identifier(_identifier) {
|
|
3694
|
+
this.setIdentifier(_identifier);
|
|
3695
|
+
}
|
|
3696
|
+
get sequencerIdentifier() {
|
|
3697
|
+
return this.hash !== null ? { blockHash: this.hash } : { blockNumber: this.number ?? this.tag };
|
|
3698
|
+
}
|
|
3699
|
+
};
|
|
3700
|
+
|
|
3701
|
+
// src/provider/rpc.ts
|
|
3702
|
+
var defaultOptions = {
|
|
3703
|
+
headers: { "Content-Type": "application/json" },
|
|
3704
|
+
blockIdentifier: "latest",
|
|
3705
|
+
retries: 200
|
|
3706
|
+
};
|
|
3707
|
+
var RpcProvider = class {
|
|
3708
|
+
constructor(optionsOrProvider) {
|
|
3709
|
+
this.responseParser = new RPCResponseParser();
|
|
3710
|
+
const { nodeUrl, retries, headers, blockIdentifier } = optionsOrProvider;
|
|
3711
|
+
this.nodeUrl = nodeUrl;
|
|
3712
|
+
this.retries = retries || defaultOptions.retries;
|
|
3713
|
+
this.headers = { ...defaultOptions.headers, ...headers };
|
|
3714
|
+
this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
|
|
3715
|
+
this.getChainId();
|
|
3716
|
+
}
|
|
3717
|
+
fetch(method, params) {
|
|
3718
|
+
return fetchPonyfill_default(this.nodeUrl, {
|
|
3719
|
+
method: "POST",
|
|
3720
|
+
body: stringify2({ method, jsonrpc: "2.0", params, id: 0 }),
|
|
3721
|
+
headers: this.headers
|
|
3722
|
+
});
|
|
3723
|
+
}
|
|
3724
|
+
errorHandler(error) {
|
|
3725
|
+
if (error) {
|
|
3726
|
+
const { code, message } = error;
|
|
3727
|
+
throw new LibraryError(`${code}: ${message}`);
|
|
3728
|
+
}
|
|
3729
|
+
}
|
|
3730
|
+
async fetchEndpoint(method, params) {
|
|
3731
|
+
var _a;
|
|
3732
|
+
try {
|
|
3733
|
+
const rawResult = await this.fetch(method, params);
|
|
3734
|
+
const { error, result } = await rawResult.json();
|
|
3735
|
+
this.errorHandler(error);
|
|
3736
|
+
return result;
|
|
3737
|
+
} catch (error) {
|
|
3738
|
+
this.errorHandler((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data);
|
|
3739
|
+
throw error;
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
async getChainId() {
|
|
3743
|
+
this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
|
|
3744
|
+
return this.chainId;
|
|
3745
|
+
}
|
|
3746
|
+
async getBlock(blockIdentifier = this.blockIdentifier) {
|
|
3747
|
+
return this.getBlockWithTxHashes(blockIdentifier).then(
|
|
3748
|
+
this.responseParser.parseGetBlockResponse
|
|
3749
|
+
);
|
|
3750
|
+
}
|
|
3751
|
+
async getBlockHashAndNumber() {
|
|
3752
|
+
return this.fetchEndpoint("starknet_blockHashAndNumber");
|
|
3753
|
+
}
|
|
3754
|
+
async getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
|
|
3755
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3756
|
+
return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
|
|
3757
|
+
}
|
|
3758
|
+
async getBlockWithTxs(blockIdentifier = this.blockIdentifier) {
|
|
3759
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3760
|
+
return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
|
|
3761
|
+
}
|
|
3762
|
+
async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3763
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3764
|
+
return this.fetchEndpoint("starknet_getClassHashAt", {
|
|
3765
|
+
block_id,
|
|
3766
|
+
contract_address: contractAddress
|
|
3767
|
+
});
|
|
3768
|
+
}
|
|
3769
|
+
async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3770
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3771
|
+
return this.fetchEndpoint("starknet_getNonce", {
|
|
3772
|
+
contract_address: contractAddress,
|
|
3773
|
+
block_id
|
|
3774
|
+
});
|
|
3775
|
+
}
|
|
3776
|
+
async getPendingTransactions() {
|
|
3777
|
+
return this.fetchEndpoint("starknet_pendingTransactions");
|
|
3778
|
+
}
|
|
3779
|
+
async getProtocolVersion() {
|
|
3780
|
+
throw new Error("Pathfinder does not implement this rpc 0.1.0 method");
|
|
3781
|
+
}
|
|
3782
|
+
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
3783
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3784
|
+
return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
|
|
3785
|
+
}
|
|
3786
|
+
async getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
|
|
3787
|
+
const parsedKey = toHex(key);
|
|
3788
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3789
|
+
return this.fetchEndpoint("starknet_getStorageAt", {
|
|
3790
|
+
contract_address: contractAddress,
|
|
3791
|
+
key: parsedKey,
|
|
3792
|
+
block_id
|
|
3793
|
+
});
|
|
3794
|
+
}
|
|
3795
|
+
async getTransaction(txHash) {
|
|
3796
|
+
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
3797
|
+
}
|
|
3798
|
+
async getTransactionByHash(txHash) {
|
|
3799
|
+
return this.fetchEndpoint("starknet_getTransactionByHash", { transaction_hash: txHash });
|
|
3800
|
+
}
|
|
3801
|
+
async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
|
|
3802
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3803
|
+
return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
|
|
3804
|
+
}
|
|
3805
|
+
async getTransactionReceipt(txHash) {
|
|
3806
|
+
return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash: txHash });
|
|
3807
|
+
}
|
|
3808
|
+
async getClassByHash(classHash) {
|
|
3809
|
+
return this.getClass(classHash);
|
|
3810
|
+
}
|
|
3811
|
+
async getClass(classHash, blockIdentifier = this.blockIdentifier) {
|
|
3812
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
3813
|
+
return this.fetchEndpoint("starknet_getClass", { class_hash: classHash, block_id });
|
|
3814
|
+
}
|
|
3815
|
+
async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
3308
3816
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3309
3817
|
return this.fetchEndpoint("starknet_getClassAt", {
|
|
3310
3818
|
block_id,
|
|
@@ -3494,11 +4002,11 @@ var RpcProvider = class {
|
|
|
3494
4002
|
async getSimulateTransaction(_invocation, _invocationDetails, _blockIdentifier) {
|
|
3495
4003
|
throw new Error("RPC does not implement simulateTransaction function");
|
|
3496
4004
|
}
|
|
3497
|
-
async getStarkName(address,
|
|
3498
|
-
return getStarkName(this, address,
|
|
4005
|
+
async getStarkName(address, StarknetIdContract2) {
|
|
4006
|
+
return getStarkName(this, address, StarknetIdContract2);
|
|
3499
4007
|
}
|
|
3500
|
-
async getAddressFromStarkName(name,
|
|
3501
|
-
return getAddressFromStarkName(this, name,
|
|
4008
|
+
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4009
|
+
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
3502
4010
|
}
|
|
3503
4011
|
};
|
|
3504
4012
|
|
|
@@ -4028,711 +4536,206 @@ var SequencerProvider = class {
|
|
|
4028
4536
|
...res,
|
|
4029
4537
|
signature: bigNumberishArrayToDecimalStringArray(formatSignature(invocation.signature)),
|
|
4030
4538
|
version: toHex(toBigInt((invocation == null ? void 0 : invocation.version) || 1)),
|
|
4031
|
-
nonce: toHex(toBigInt(invocation.nonce))
|
|
4032
|
-
};
|
|
4033
|
-
});
|
|
4034
|
-
return this.fetchEndpoint("estimate_fee_bulk", { blockIdentifier }, params).then(
|
|
4035
|
-
this.responseParser.parseFeeEstimateBulkResponse
|
|
4036
|
-
);
|
|
4037
|
-
}
|
|
4038
|
-
async getCode(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
4039
|
-
return this.fetchEndpoint("get_code", { contractAddress, blockIdentifier });
|
|
4040
|
-
}
|
|
4041
|
-
async waitForTransaction(txHash, options) {
|
|
4042
|
-
const errorStates = ["REJECTED" /* REJECTED */, "NOT_RECEIVED" /* NOT_RECEIVED */];
|
|
4043
|
-
let onchain = false;
|
|
4044
|
-
let res;
|
|
4045
|
-
const retryInterval = (options == null ? void 0 : options.retryInterval) ?? 8e3;
|
|
4046
|
-
const successStates = (options == null ? void 0 : options.successStates) ?? [
|
|
4047
|
-
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
4048
|
-
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
4049
|
-
"PENDING" /* PENDING */
|
|
4050
|
-
];
|
|
4051
|
-
while (!onchain) {
|
|
4052
|
-
await wait(retryInterval);
|
|
4053
|
-
res = await this.getTransactionStatus(txHash);
|
|
4054
|
-
if (successStates.includes(res.tx_status)) {
|
|
4055
|
-
onchain = true;
|
|
4056
|
-
} else if (errorStates.includes(res.tx_status)) {
|
|
4057
|
-
const message = res.tx_failure_reason ? `${res.tx_status}: ${res.tx_failure_reason.code}
|
|
4058
|
-
${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
4059
|
-
const error = new Error(message);
|
|
4060
|
-
error.response = res;
|
|
4061
|
-
throw error;
|
|
4062
|
-
}
|
|
4063
|
-
}
|
|
4064
|
-
const txReceipt = await this.getTransactionReceipt(txHash);
|
|
4065
|
-
return txReceipt;
|
|
4066
|
-
}
|
|
4067
|
-
async getTransactionStatus(txHash) {
|
|
4068
|
-
const txHashHex = toHex(txHash);
|
|
4069
|
-
return this.fetchEndpoint("get_transaction_status", { transactionHash: txHashHex });
|
|
4070
|
-
}
|
|
4071
|
-
async getContractAddresses() {
|
|
4072
|
-
return this.fetchEndpoint("get_contract_addresses");
|
|
4073
|
-
}
|
|
4074
|
-
async getTransactionTrace(txHash) {
|
|
4075
|
-
const txHashHex = toHex(txHash);
|
|
4076
|
-
return this.fetchEndpoint("get_transaction_trace", { transactionHash: txHashHex });
|
|
4077
|
-
}
|
|
4078
|
-
async estimateMessageFee({ from_address, to_address, entry_point_selector, payload }, blockIdentifier = this.blockIdentifier) {
|
|
4079
|
-
const validCallL1Handler = {
|
|
4080
|
-
from_address: getDecimalString(from_address),
|
|
4081
|
-
to_address: getHexString(to_address),
|
|
4082
|
-
entry_point_selector: getSelector(entry_point_selector),
|
|
4083
|
-
payload: getHexStringArray(payload)
|
|
4084
|
-
};
|
|
4085
|
-
return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
|
|
4086
|
-
}
|
|
4087
|
-
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
4088
|
-
return this.fetchEndpoint(
|
|
4089
|
-
"simulate_transaction",
|
|
4090
|
-
{ blockIdentifier, skipValidate },
|
|
4091
|
-
{
|
|
4092
|
-
type: "INVOKE_FUNCTION",
|
|
4093
|
-
sender_address: invocation.contractAddress,
|
|
4094
|
-
calldata: invocation.calldata ?? [],
|
|
4095
|
-
signature: signatureToDecimalArray(invocation.signature),
|
|
4096
|
-
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
4097
|
-
nonce: toHex(invocationDetails.nonce),
|
|
4098
|
-
max_fee: toHex((invocationDetails == null ? void 0 : invocationDetails.maxFee) || 0)
|
|
4099
|
-
}
|
|
4100
|
-
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
4101
|
-
}
|
|
4102
|
-
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
4103
|
-
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4104
|
-
return this.fetchEndpoint("get_state_update", { ...args }).then(
|
|
4105
|
-
this.responseParser.parseGetStateUpdateResponse
|
|
4106
|
-
);
|
|
4107
|
-
}
|
|
4108
|
-
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
4109
|
-
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4110
|
-
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
4111
|
-
}
|
|
4112
|
-
async getStarkName(address, StarknetIdContract) {
|
|
4113
|
-
return getStarkName(this, address, StarknetIdContract);
|
|
4114
|
-
}
|
|
4115
|
-
async getAddressFromStarkName(name, StarknetIdContract) {
|
|
4116
|
-
return getAddressFromStarkName(this, name, StarknetIdContract);
|
|
4117
|
-
}
|
|
4118
|
-
};
|
|
4119
|
-
|
|
4120
|
-
// src/provider/default.ts
|
|
4121
|
-
var Provider = class {
|
|
4122
|
-
constructor(providerOrOptions) {
|
|
4123
|
-
if (providerOrOptions instanceof Provider) {
|
|
4124
|
-
this.provider = providerOrOptions.provider;
|
|
4125
|
-
} else if (providerOrOptions instanceof RpcProvider || providerOrOptions instanceof SequencerProvider) {
|
|
4126
|
-
this.provider = providerOrOptions;
|
|
4127
|
-
} else if (providerOrOptions && "rpc" in providerOrOptions) {
|
|
4128
|
-
this.provider = new RpcProvider(providerOrOptions.rpc);
|
|
4129
|
-
} else if (providerOrOptions && "sequencer" in providerOrOptions) {
|
|
4130
|
-
this.provider = new SequencerProvider(providerOrOptions.sequencer);
|
|
4131
|
-
} else {
|
|
4132
|
-
this.provider = new SequencerProvider();
|
|
4133
|
-
}
|
|
4134
|
-
}
|
|
4135
|
-
async getChainId() {
|
|
4136
|
-
return this.provider.getChainId();
|
|
4137
|
-
}
|
|
4138
|
-
async getBlock(blockIdentifier) {
|
|
4139
|
-
return this.provider.getBlock(blockIdentifier);
|
|
4140
|
-
}
|
|
4141
|
-
async getClassAt(contractAddress, blockIdentifier) {
|
|
4142
|
-
return this.provider.getClassAt(contractAddress, blockIdentifier);
|
|
4143
|
-
}
|
|
4144
|
-
async getClassHashAt(contractAddress, blockIdentifier) {
|
|
4145
|
-
return this.provider.getClassHashAt(contractAddress, blockIdentifier);
|
|
4146
|
-
}
|
|
4147
|
-
getClassByHash(classHash) {
|
|
4148
|
-
return this.provider.getClassByHash(classHash);
|
|
4149
|
-
}
|
|
4150
|
-
async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
4151
|
-
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
4152
|
-
}
|
|
4153
|
-
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
|
|
4154
|
-
return this.provider.getInvokeEstimateFee(
|
|
4155
|
-
invocationWithTxType,
|
|
4156
|
-
invocationDetails,
|
|
4157
|
-
blockIdentifier,
|
|
4158
|
-
skipValidate
|
|
4159
|
-
);
|
|
4160
|
-
}
|
|
4161
|
-
async getEstimateFeeBulk(invocations, blockIdentifier) {
|
|
4162
|
-
return this.provider.getEstimateFeeBulk(invocations, blockIdentifier);
|
|
4163
|
-
}
|
|
4164
|
-
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
4165
|
-
return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
|
|
4166
|
-
}
|
|
4167
|
-
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4168
|
-
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
|
|
4169
|
-
}
|
|
4170
|
-
async getTransaction(txHash) {
|
|
4171
|
-
return this.provider.getTransaction(txHash);
|
|
4172
|
-
}
|
|
4173
|
-
async getTransactionReceipt(txHash) {
|
|
4174
|
-
return this.provider.getTransactionReceipt(txHash);
|
|
4175
|
-
}
|
|
4176
|
-
async callContract(request, blockIdentifier) {
|
|
4177
|
-
return this.provider.callContract(request, blockIdentifier);
|
|
4178
|
-
}
|
|
4179
|
-
async invokeFunction(functionInvocation, details) {
|
|
4180
|
-
return this.provider.invokeFunction(functionInvocation, details);
|
|
4181
|
-
}
|
|
4182
|
-
async deployAccountContract(payload, details) {
|
|
4183
|
-
return this.provider.deployAccountContract(payload, details);
|
|
4184
|
-
}
|
|
4185
|
-
async declareContract(transaction, details) {
|
|
4186
|
-
return this.provider.declareContract(transaction, details);
|
|
4187
|
-
}
|
|
4188
|
-
async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4189
|
-
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
|
|
4190
|
-
}
|
|
4191
|
-
getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4192
|
-
return this.provider.getDeployAccountEstimateFee(
|
|
4193
|
-
transaction,
|
|
4194
|
-
details,
|
|
4195
|
-
blockIdentifier,
|
|
4196
|
-
skipValidate
|
|
4197
|
-
);
|
|
4198
|
-
}
|
|
4199
|
-
async getCode(contractAddress, blockIdentifier) {
|
|
4200
|
-
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
4201
|
-
}
|
|
4202
|
-
async waitForTransaction(txHash, options) {
|
|
4203
|
-
return this.provider.waitForTransaction(txHash, options);
|
|
4204
|
-
}
|
|
4205
|
-
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
|
|
4206
|
-
return this.provider.getSimulateTransaction(
|
|
4207
|
-
invocation,
|
|
4208
|
-
invocationDetails,
|
|
4209
|
-
blockIdentifier,
|
|
4210
|
-
skipValidate
|
|
4211
|
-
);
|
|
4212
|
-
}
|
|
4213
|
-
async getStateUpdate(blockIdentifier) {
|
|
4214
|
-
return this.provider.getStateUpdate(blockIdentifier);
|
|
4215
|
-
}
|
|
4216
|
-
async getStarkName(address, StarknetIdContract) {
|
|
4217
|
-
return getStarkName(this, address, StarknetIdContract);
|
|
4218
|
-
}
|
|
4219
|
-
async getAddressFromStarkName(name, StarknetIdContract) {
|
|
4220
|
-
return getAddressFromStarkName(this, name, StarknetIdContract);
|
|
4221
|
-
}
|
|
4222
|
-
};
|
|
4223
|
-
|
|
4224
|
-
// src/provider/interface.ts
|
|
4225
|
-
var ProviderInterface = class {
|
|
4226
|
-
};
|
|
4227
|
-
|
|
4228
|
-
// src/provider/index.ts
|
|
4229
|
-
var defaultProvider = new Provider();
|
|
4230
|
-
|
|
4231
|
-
// src/utils/calldata/formatter.ts
|
|
4232
|
-
var guard = {
|
|
4233
|
-
isBN: (data, type, key) => {
|
|
4234
|
-
if (!isBigInt(data[key]))
|
|
4235
|
-
throw new Error(
|
|
4236
|
-
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
4237
|
-
);
|
|
4238
|
-
},
|
|
4239
|
-
unknown: (data, type, key) => {
|
|
4240
|
-
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
4241
|
-
}
|
|
4242
|
-
};
|
|
4243
|
-
function formatter(data, type, sameType) {
|
|
4244
|
-
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
4245
|
-
const elType = sameType ?? type[key];
|
|
4246
|
-
if (!(key in type) && !sameType) {
|
|
4247
|
-
acc[key] = value;
|
|
4248
|
-
return acc;
|
|
4249
|
-
}
|
|
4250
|
-
if (elType === "string") {
|
|
4251
|
-
if (Array.isArray(data[key])) {
|
|
4252
|
-
const arrayStr = formatter(
|
|
4253
|
-
data[key],
|
|
4254
|
-
data[key].map((_) => elType)
|
|
4255
|
-
);
|
|
4256
|
-
acc[key] = Object.values(arrayStr).join("");
|
|
4257
|
-
return acc;
|
|
4258
|
-
}
|
|
4259
|
-
guard.isBN(data, type, key);
|
|
4260
|
-
acc[key] = decodeShortString(value);
|
|
4261
|
-
return acc;
|
|
4262
|
-
}
|
|
4263
|
-
if (elType === "number") {
|
|
4264
|
-
guard.isBN(data, type, key);
|
|
4265
|
-
acc[key] = Number(value);
|
|
4266
|
-
return acc;
|
|
4267
|
-
}
|
|
4268
|
-
if (typeof elType === "function") {
|
|
4269
|
-
acc[key] = elType(value);
|
|
4270
|
-
return acc;
|
|
4271
|
-
}
|
|
4272
|
-
if (Array.isArray(elType)) {
|
|
4273
|
-
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
4274
|
-
acc[key] = Object.values(arrayObj);
|
|
4275
|
-
return acc;
|
|
4276
|
-
}
|
|
4277
|
-
if (typeof elType === "object") {
|
|
4278
|
-
acc[key] = formatter(data[key], elType);
|
|
4279
|
-
return acc;
|
|
4280
|
-
}
|
|
4281
|
-
guard.unknown(data, type, key);
|
|
4282
|
-
return acc;
|
|
4283
|
-
}, {});
|
|
4284
|
-
}
|
|
4285
|
-
|
|
4286
|
-
// src/utils/calldata/tuple.ts
|
|
4287
|
-
function parseNamedTuple(namedTuple) {
|
|
4288
|
-
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
4289
|
-
const type = namedTuple.substring(name.length + ":".length);
|
|
4290
|
-
return { name, type };
|
|
4291
|
-
}
|
|
4292
|
-
function parseSubTuple(s) {
|
|
4293
|
-
if (!s.includes("("))
|
|
4294
|
-
return { subTuple: [], result: s };
|
|
4295
|
-
const subTuple = [];
|
|
4296
|
-
let result = "";
|
|
4297
|
-
let i = 0;
|
|
4298
|
-
while (i < s.length) {
|
|
4299
|
-
if (s[i] === "(") {
|
|
4300
|
-
let counter = 1;
|
|
4301
|
-
const lBracket = i;
|
|
4302
|
-
i++;
|
|
4303
|
-
while (counter) {
|
|
4304
|
-
if (s[i] === ")")
|
|
4305
|
-
counter--;
|
|
4306
|
-
if (s[i] === "(")
|
|
4307
|
-
counter++;
|
|
4308
|
-
i++;
|
|
4309
|
-
}
|
|
4310
|
-
subTuple.push(s.substring(lBracket, i));
|
|
4311
|
-
result += " ";
|
|
4312
|
-
i--;
|
|
4313
|
-
} else {
|
|
4314
|
-
result += s[i];
|
|
4315
|
-
}
|
|
4316
|
-
i++;
|
|
4317
|
-
}
|
|
4318
|
-
return {
|
|
4319
|
-
subTuple,
|
|
4320
|
-
result
|
|
4321
|
-
};
|
|
4322
|
-
}
|
|
4323
|
-
function extractCairo0Tuple(type) {
|
|
4324
|
-
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
4325
|
-
const { subTuple, result } = parseSubTuple(cleanType);
|
|
4326
|
-
let recomposed = result.split(",").map((it) => {
|
|
4327
|
-
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
4328
|
-
});
|
|
4329
|
-
if (isTypeNamedTuple(type)) {
|
|
4330
|
-
recomposed = recomposed.reduce((acc, it) => {
|
|
4331
|
-
return acc.concat(parseNamedTuple(it));
|
|
4332
|
-
}, []);
|
|
4333
|
-
}
|
|
4334
|
-
return recomposed;
|
|
4335
|
-
}
|
|
4336
|
-
function extractCairo1Tuple(type) {
|
|
4337
|
-
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
4338
|
-
return cleanType.split(",");
|
|
4339
|
-
}
|
|
4340
|
-
function extractTupleMemberTypes(type) {
|
|
4341
|
-
if (isCairo1Type(type)) {
|
|
4342
|
-
return extractCairo1Tuple(type);
|
|
4343
|
-
}
|
|
4344
|
-
return extractCairo0Tuple(type);
|
|
4345
|
-
}
|
|
4346
|
-
|
|
4347
|
-
// src/utils/calldata/requestParser.ts
|
|
4348
|
-
function parseTuple(element, typeStr) {
|
|
4349
|
-
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
4350
|
-
const elements = Object.values(element);
|
|
4351
|
-
if (elements.length !== memberTypes.length) {
|
|
4352
|
-
throw Error(
|
|
4353
|
-
`ParseTuple: provided and expected abi tuple size do not match.
|
|
4354
|
-
provided: ${elements}
|
|
4355
|
-
expected: ${memberTypes}`
|
|
4356
|
-
);
|
|
4357
|
-
}
|
|
4358
|
-
return memberTypes.map((it, dx) => {
|
|
4359
|
-
return {
|
|
4360
|
-
element: elements[dx],
|
|
4361
|
-
type: it.type ?? it
|
|
4362
|
-
};
|
|
4363
|
-
});
|
|
4364
|
-
}
|
|
4365
|
-
function parseCalldataValue(element, type, structs) {
|
|
4366
|
-
if (element === void 0) {
|
|
4367
|
-
throw Error(`Missing parameter for type ${type}`);
|
|
4368
|
-
}
|
|
4369
|
-
if (Array.isArray(element)) {
|
|
4370
|
-
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
4371
|
-
}
|
|
4372
|
-
if (isTypeUint256(type)) {
|
|
4373
|
-
const el_uint256 = uint256(element);
|
|
4374
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
4375
|
-
}
|
|
4376
|
-
if (structs[type] && structs[type].members.length) {
|
|
4377
|
-
const { members } = structs[type];
|
|
4378
|
-
const subElement = element;
|
|
4379
|
-
return members.reduce((acc, it) => {
|
|
4380
|
-
return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs));
|
|
4381
|
-
}, []);
|
|
4382
|
-
}
|
|
4383
|
-
if (isTypeTuple(type)) {
|
|
4384
|
-
const tupled = parseTuple(element, type);
|
|
4385
|
-
return tupled.reduce((acc, it) => {
|
|
4386
|
-
const parsedData = parseCalldataValue(it.element, it.type, structs);
|
|
4387
|
-
return acc.concat(parsedData);
|
|
4388
|
-
}, []);
|
|
4389
|
-
}
|
|
4390
|
-
if (typeof element === "object") {
|
|
4391
|
-
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
4392
|
-
}
|
|
4393
|
-
return felt(element);
|
|
4394
|
-
}
|
|
4395
|
-
function parseCalldataField(argsIterator, input, structs) {
|
|
4396
|
-
const { name, type } = input;
|
|
4397
|
-
let { value } = argsIterator.next();
|
|
4398
|
-
switch (true) {
|
|
4399
|
-
case isTypeArray(type):
|
|
4400
|
-
if (!Array.isArray(value) && !isText(value)) {
|
|
4401
|
-
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
4402
|
-
}
|
|
4403
|
-
if (typeof value === "string") {
|
|
4404
|
-
value = splitLongString(value);
|
|
4405
|
-
}
|
|
4406
|
-
const result = [];
|
|
4407
|
-
result.push(felt(value.length));
|
|
4408
|
-
const arrayType = getArrayType(input.type);
|
|
4409
|
-
return value.reduce((acc, el) => {
|
|
4410
|
-
if (isTypeFelt(arrayType) || isTypeUint(arrayType) || isTypeContractAddress(arrayType)) {
|
|
4411
|
-
acc.push(felt(el));
|
|
4412
|
-
} else if (isTypeBool(arrayType) && typeof el === "boolean") {
|
|
4413
|
-
acc.push(el.toString());
|
|
4414
|
-
} else {
|
|
4415
|
-
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
4416
|
-
}
|
|
4417
|
-
return acc;
|
|
4418
|
-
}, result);
|
|
4419
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
|
|
4420
|
-
return parseCalldataValue(value, type, structs);
|
|
4421
|
-
case isTypeBool(type):
|
|
4422
|
-
return `${+value}`;
|
|
4423
|
-
default:
|
|
4424
|
-
return felt(value);
|
|
4425
|
-
}
|
|
4426
|
-
}
|
|
4427
|
-
|
|
4428
|
-
// src/utils/calldata/responseParser.ts
|
|
4429
|
-
function parseResponseStruct(responseIterator, type, structs) {
|
|
4430
|
-
if (type in structs && structs[type]) {
|
|
4431
|
-
return structs[type].members.reduce((acc, el) => {
|
|
4432
|
-
acc[el.name] = parseResponseStruct(responseIterator, el.type, structs);
|
|
4433
|
-
return acc;
|
|
4434
|
-
}, {});
|
|
4435
|
-
}
|
|
4436
|
-
if (isTypeTuple(type)) {
|
|
4437
|
-
const memberTypes = extractTupleMemberTypes(type);
|
|
4438
|
-
return memberTypes.reduce((acc, it, idx) => {
|
|
4439
|
-
const tName = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
4440
|
-
const tType = (it == null ? void 0 : it.type) ? it.type : it;
|
|
4441
|
-
acc[tName] = parseResponseStruct(responseIterator, tType, structs);
|
|
4442
|
-
return acc;
|
|
4443
|
-
}, {});
|
|
4444
|
-
}
|
|
4445
|
-
const temp = responseIterator.next().value;
|
|
4446
|
-
return BigInt(temp);
|
|
4447
|
-
}
|
|
4448
|
-
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
4449
|
-
const { name, type } = output;
|
|
4450
|
-
let temp;
|
|
4451
|
-
switch (true) {
|
|
4452
|
-
case isLen(name):
|
|
4453
|
-
temp = responseIterator.next().value;
|
|
4454
|
-
return BigInt(temp);
|
|
4455
|
-
case isTypeBool(type):
|
|
4456
|
-
temp = responseIterator.next().value;
|
|
4457
|
-
return Boolean(BigInt(temp));
|
|
4458
|
-
case isTypeUint256(type):
|
|
4459
|
-
const low = responseIterator.next().value;
|
|
4460
|
-
const high = responseIterator.next().value;
|
|
4461
|
-
return uint256ToBN({ low, high });
|
|
4462
|
-
case isTypeArray(type):
|
|
4463
|
-
const parsedDataArr = [];
|
|
4464
|
-
if (isCairo1Type(type)) {
|
|
4465
|
-
responseIterator.next();
|
|
4466
|
-
let it = responseIterator.next();
|
|
4467
|
-
while (!it.done) {
|
|
4468
|
-
parsedDataArr.push(BigInt(it.value));
|
|
4469
|
-
it = responseIterator.next();
|
|
4470
|
-
}
|
|
4471
|
-
return parsedDataArr;
|
|
4472
|
-
}
|
|
4473
|
-
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
4474
|
-
const arrLen = parsedResult[`${name}_len`];
|
|
4475
|
-
while (parsedDataArr.length < arrLen) {
|
|
4476
|
-
parsedDataArr.push(
|
|
4477
|
-
parseResponseStruct(responseIterator, output.type.replace("*", ""), structs)
|
|
4478
|
-
);
|
|
4479
|
-
}
|
|
4480
|
-
}
|
|
4481
|
-
return parsedDataArr;
|
|
4482
|
-
case (type in structs || isTypeTuple(type)):
|
|
4483
|
-
return parseResponseStruct(responseIterator, type, structs);
|
|
4484
|
-
default:
|
|
4485
|
-
temp = responseIterator.next().value;
|
|
4486
|
-
return BigInt(temp);
|
|
4487
|
-
}
|
|
4488
|
-
}
|
|
4489
|
-
|
|
4490
|
-
// src/utils/calldata/validate.ts
|
|
4491
|
-
var validateFelt = (parameter, input) => {
|
|
4492
|
-
assert(
|
|
4493
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
4494
|
-
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
4495
|
-
);
|
|
4496
|
-
};
|
|
4497
|
-
var validateUint = (parameter, input) => {
|
|
4498
|
-
if (typeof parameter === "number") {
|
|
4499
|
-
assert(
|
|
4500
|
-
parameter <= Number.MAX_SAFE_INTEGER,
|
|
4501
|
-
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
4502
|
-
);
|
|
4503
|
-
}
|
|
4504
|
-
assert(
|
|
4505
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
4506
|
-
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
|
|
4507
|
-
);
|
|
4508
|
-
const param = toBigInt(parameter);
|
|
4509
|
-
switch (input.type) {
|
|
4510
|
-
case "core::integer::u8" /* u8 */:
|
|
4511
|
-
assert(
|
|
4512
|
-
param >= 0n && param <= 255n,
|
|
4513
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
4514
|
-
);
|
|
4515
|
-
break;
|
|
4516
|
-
case "core::integer::u16" /* u16 */:
|
|
4517
|
-
assert(
|
|
4518
|
-
param >= 0n && param <= 65535n,
|
|
4519
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
4520
|
-
);
|
|
4521
|
-
break;
|
|
4522
|
-
case "core::integer::u32" /* u32 */:
|
|
4523
|
-
assert(
|
|
4524
|
-
param >= 0n && param <= 4294967295n,
|
|
4525
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
4526
|
-
);
|
|
4527
|
-
break;
|
|
4528
|
-
case "core::integer::u64" /* u64 */:
|
|
4529
|
-
assert(
|
|
4530
|
-
param >= 0n && param <= 2n ** 64n - 1n,
|
|
4531
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
4532
|
-
);
|
|
4533
|
-
break;
|
|
4534
|
-
case "core::integer::u128" /* u128 */:
|
|
4535
|
-
assert(
|
|
4536
|
-
param >= 0n && param <= 2n ** 128n - 1n,
|
|
4537
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
4538
|
-
);
|
|
4539
|
-
break;
|
|
4540
|
-
case "core::integer::u256" /* u256 */:
|
|
4541
|
-
assert(
|
|
4542
|
-
param >= 0n && param <= 2n ** 256n - 1n,
|
|
4543
|
-
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
4544
|
-
);
|
|
4545
|
-
break;
|
|
4546
|
-
default:
|
|
4547
|
-
break;
|
|
4548
|
-
}
|
|
4549
|
-
};
|
|
4550
|
-
var validateBool = (parameter, input) => {
|
|
4551
|
-
assert(
|
|
4552
|
-
typeof parameter === "boolean",
|
|
4553
|
-
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
4554
|
-
);
|
|
4555
|
-
};
|
|
4556
|
-
var validateStruct = (parameter, input, structs) => {
|
|
4557
|
-
assert(
|
|
4558
|
-
typeof parameter === "object" && !Array.isArray(parameter),
|
|
4559
|
-
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
4560
|
-
);
|
|
4561
|
-
structs[input.type].members.forEach(({ name }) => {
|
|
4562
|
-
assert(
|
|
4563
|
-
Object.keys(parameter).includes(name),
|
|
4564
|
-
`Validate: arg ${input.name} should have a property ${name}`
|
|
4565
|
-
);
|
|
4566
|
-
});
|
|
4567
|
-
};
|
|
4568
|
-
var validateTuple = (parameter, input) => {
|
|
4569
|
-
assert(
|
|
4570
|
-
typeof parameter === "object" && !Array.isArray(parameter),
|
|
4571
|
-
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
4572
|
-
);
|
|
4573
|
-
};
|
|
4574
|
-
var validateArray = (parameter, input, structs) => {
|
|
4575
|
-
const baseType = getArrayType(input.type);
|
|
4576
|
-
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
4577
|
-
return;
|
|
4578
|
-
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
4579
|
-
switch (true) {
|
|
4580
|
-
case isTypeFelt(baseType):
|
|
4581
|
-
parameter.forEach((param) => validateFelt(param, input));
|
|
4582
|
-
break;
|
|
4583
|
-
case isTypeTuple(baseType):
|
|
4584
|
-
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
4585
|
-
break;
|
|
4586
|
-
case isTypeStruct(baseType, structs):
|
|
4587
|
-
parameter.forEach(
|
|
4588
|
-
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
4589
|
-
);
|
|
4590
|
-
break;
|
|
4591
|
-
case isTypeUint(baseType):
|
|
4592
|
-
parameter.forEach((param) => validateUint(param, input));
|
|
4593
|
-
break;
|
|
4594
|
-
case isTypeBool(baseType):
|
|
4595
|
-
parameter.forEach((param) => validateBool(param, input));
|
|
4596
|
-
break;
|
|
4597
|
-
default:
|
|
4598
|
-
throw new Error(
|
|
4599
|
-
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
4600
|
-
);
|
|
4601
|
-
}
|
|
4602
|
-
};
|
|
4603
|
-
function validateFields(abiMethod, args, structs) {
|
|
4604
|
-
abiMethod.inputs.reduce((acc, input) => {
|
|
4605
|
-
const parameter = args[acc];
|
|
4606
|
-
switch (true) {
|
|
4607
|
-
case isLen(input.name):
|
|
4608
|
-
return acc;
|
|
4609
|
-
case isTypeFelt(input.type):
|
|
4610
|
-
validateFelt(parameter, input);
|
|
4611
|
-
break;
|
|
4612
|
-
case isTypeUint(input.type):
|
|
4613
|
-
validateUint(parameter, input);
|
|
4614
|
-
break;
|
|
4615
|
-
case isTypeBool(input.type):
|
|
4616
|
-
validateBool(parameter, input);
|
|
4617
|
-
break;
|
|
4618
|
-
case isTypeContractAddress(input.type):
|
|
4619
|
-
break;
|
|
4620
|
-
case isTypeStruct(input.type, structs):
|
|
4621
|
-
validateStruct(parameter, input, structs);
|
|
4622
|
-
break;
|
|
4623
|
-
case isTypeTuple(input.type):
|
|
4624
|
-
validateTuple(parameter, input);
|
|
4625
|
-
break;
|
|
4626
|
-
case isTypeArray(input.type):
|
|
4627
|
-
validateArray(parameter, input, structs);
|
|
4628
|
-
break;
|
|
4629
|
-
default:
|
|
4630
|
-
throw new Error(
|
|
4631
|
-
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
4632
|
-
);
|
|
4633
|
-
}
|
|
4634
|
-
return acc + 1;
|
|
4635
|
-
}, 0);
|
|
4636
|
-
}
|
|
4637
|
-
|
|
4638
|
-
// src/utils/calldata/index.ts
|
|
4639
|
-
var CallData = class {
|
|
4640
|
-
constructor(abi) {
|
|
4641
|
-
this.abi = abi;
|
|
4642
|
-
this.structs = CallData.getAbiStruct(abi);
|
|
4643
|
-
}
|
|
4644
|
-
validate(type, method, args = []) {
|
|
4645
|
-
if (type !== "DEPLOY") {
|
|
4646
|
-
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
4647
|
-
if (abi.type !== "function")
|
|
4648
|
-
return false;
|
|
4649
|
-
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
4650
|
-
return type === "INVOKE" ? !isView : isView;
|
|
4651
|
-
}).map((abi) => abi.name);
|
|
4652
|
-
assert(
|
|
4653
|
-
invocableFunctionNames.includes(method),
|
|
4654
|
-
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
4655
|
-
);
|
|
4656
|
-
}
|
|
4657
|
-
const abiMethod = this.abi.find(
|
|
4658
|
-
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
4539
|
+
nonce: toHex(toBigInt(invocation.nonce))
|
|
4540
|
+
};
|
|
4541
|
+
});
|
|
4542
|
+
return this.fetchEndpoint("estimate_fee_bulk", { blockIdentifier }, params).then(
|
|
4543
|
+
this.responseParser.parseFeeEstimateBulkResponse
|
|
4659
4544
|
);
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4545
|
+
}
|
|
4546
|
+
async getCode(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
4547
|
+
return this.fetchEndpoint("get_code", { contractAddress, blockIdentifier });
|
|
4548
|
+
}
|
|
4549
|
+
async waitForTransaction(txHash, options) {
|
|
4550
|
+
const errorStates = ["REJECTED" /* REJECTED */, "NOT_RECEIVED" /* NOT_RECEIVED */];
|
|
4551
|
+
let onchain = false;
|
|
4552
|
+
let res;
|
|
4553
|
+
const retryInterval = (options == null ? void 0 : options.retryInterval) ?? 8e3;
|
|
4554
|
+
const successStates = (options == null ? void 0 : options.successStates) ?? [
|
|
4555
|
+
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
4556
|
+
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
4557
|
+
"PENDING" /* PENDING */
|
|
4558
|
+
];
|
|
4559
|
+
while (!onchain) {
|
|
4560
|
+
await wait(retryInterval);
|
|
4561
|
+
res = await this.getTransactionStatus(txHash);
|
|
4562
|
+
if (successStates.includes(res.tx_status)) {
|
|
4563
|
+
onchain = true;
|
|
4564
|
+
} else if (errorStates.includes(res.tx_status)) {
|
|
4565
|
+
const message = res.tx_failure_reason ? `${res.tx_status}: ${res.tx_failure_reason.code}
|
|
4566
|
+
${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
4567
|
+
const error = new Error(message);
|
|
4568
|
+
error.response = res;
|
|
4569
|
+
throw error;
|
|
4570
|
+
}
|
|
4665
4571
|
}
|
|
4666
|
-
|
|
4572
|
+
const txReceipt = await this.getTransactionReceipt(txHash);
|
|
4573
|
+
return txReceipt;
|
|
4667
4574
|
}
|
|
4668
|
-
|
|
4669
|
-
const
|
|
4670
|
-
return
|
|
4671
|
-
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
4672
|
-
[]
|
|
4673
|
-
);
|
|
4575
|
+
async getTransactionStatus(txHash) {
|
|
4576
|
+
const txHashHex = toHex(txHash);
|
|
4577
|
+
return this.fetchEndpoint("get_transaction_status", { transactionHash: txHashHex });
|
|
4674
4578
|
}
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
};
|
|
4689
|
-
return Object.fromEntries(getEntries(obj));
|
|
4579
|
+
async getContractAddresses() {
|
|
4580
|
+
return this.fetchEndpoint("get_contract_addresses");
|
|
4581
|
+
}
|
|
4582
|
+
async getTransactionTrace(txHash) {
|
|
4583
|
+
const txHashHex = toHex(txHash);
|
|
4584
|
+
return this.fetchEndpoint("get_transaction_trace", { transactionHash: txHashHex });
|
|
4585
|
+
}
|
|
4586
|
+
async estimateMessageFee({ from_address, to_address, entry_point_selector, payload }, blockIdentifier = this.blockIdentifier) {
|
|
4587
|
+
const validCallL1Handler = {
|
|
4588
|
+
from_address: getDecimalString(from_address),
|
|
4589
|
+
to_address: getHexString(to_address),
|
|
4590
|
+
entry_point_selector: getSelector(entry_point_selector),
|
|
4591
|
+
payload: getHexStringArray(payload)
|
|
4690
4592
|
};
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4593
|
+
return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
|
|
4594
|
+
}
|
|
4595
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
4596
|
+
return this.fetchEndpoint(
|
|
4597
|
+
"simulate_transaction",
|
|
4598
|
+
{ blockIdentifier, skipValidate },
|
|
4599
|
+
{
|
|
4600
|
+
type: "INVOKE_FUNCTION",
|
|
4601
|
+
sender_address: invocation.contractAddress,
|
|
4602
|
+
calldata: invocation.calldata ?? [],
|
|
4603
|
+
signature: signatureToDecimalArray(invocation.signature),
|
|
4604
|
+
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
4605
|
+
nonce: toHex(invocationDetails.nonce),
|
|
4606
|
+
max_fee: toHex((invocationDetails == null ? void 0 : invocationDetails.maxFee) || 0)
|
|
4607
|
+
}
|
|
4608
|
+
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
4609
|
+
}
|
|
4610
|
+
async getStateUpdate(blockIdentifier = this.blockIdentifier) {
|
|
4611
|
+
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4612
|
+
return this.fetchEndpoint("get_state_update", { ...args }).then(
|
|
4613
|
+
this.responseParser.parseGetStateUpdateResponse
|
|
4614
|
+
);
|
|
4615
|
+
}
|
|
4616
|
+
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
4617
|
+
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
4618
|
+
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
4619
|
+
}
|
|
4620
|
+
async getStarkName(address, StarknetIdContract2) {
|
|
4621
|
+
return getStarkName(this, address, StarknetIdContract2);
|
|
4622
|
+
}
|
|
4623
|
+
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4624
|
+
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4625
|
+
}
|
|
4626
|
+
};
|
|
4627
|
+
|
|
4628
|
+
// src/provider/default.ts
|
|
4629
|
+
var Provider = class {
|
|
4630
|
+
constructor(providerOrOptions) {
|
|
4631
|
+
if (providerOrOptions instanceof Provider) {
|
|
4632
|
+
this.provider = providerOrOptions.provider;
|
|
4633
|
+
} else if (providerOrOptions instanceof RpcProvider || providerOrOptions instanceof SequencerProvider) {
|
|
4634
|
+
this.provider = providerOrOptions;
|
|
4635
|
+
} else if (providerOrOptions && "rpc" in providerOrOptions) {
|
|
4636
|
+
this.provider = new RpcProvider(providerOrOptions.rpc);
|
|
4637
|
+
} else if (providerOrOptions && "sequencer" in providerOrOptions) {
|
|
4638
|
+
this.provider = new SequencerProvider(providerOrOptions.sequencer);
|
|
4695
4639
|
} else {
|
|
4696
|
-
|
|
4640
|
+
this.provider = new SequencerProvider();
|
|
4697
4641
|
}
|
|
4698
|
-
Object.defineProperty(callTreeArray, "compiled", {
|
|
4699
|
-
enumerable: false,
|
|
4700
|
-
writable: false,
|
|
4701
|
-
value: true
|
|
4702
|
-
});
|
|
4703
|
-
return callTreeArray;
|
|
4704
4642
|
}
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
const responseIterator = response.flat()[Symbol.iterator]();
|
|
4708
|
-
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
4709
|
-
const propName = output.name ?? idx;
|
|
4710
|
-
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
4711
|
-
if (acc[propName] && acc[`${propName}_len`]) {
|
|
4712
|
-
delete acc[`${propName}_len`];
|
|
4713
|
-
}
|
|
4714
|
-
return acc;
|
|
4715
|
-
}, {});
|
|
4716
|
-
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
4643
|
+
async getChainId() {
|
|
4644
|
+
return this.provider.getChainId();
|
|
4717
4645
|
}
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
return formatter(parsed, format);
|
|
4646
|
+
async getBlock(blockIdentifier) {
|
|
4647
|
+
return this.provider.getBlock(blockIdentifier);
|
|
4721
4648
|
}
|
|
4722
|
-
|
|
4723
|
-
return
|
|
4649
|
+
async getClassAt(contractAddress, blockIdentifier) {
|
|
4650
|
+
return this.provider.getClassAt(contractAddress, blockIdentifier);
|
|
4724
4651
|
}
|
|
4725
|
-
|
|
4726
|
-
return
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4652
|
+
async getClassHashAt(contractAddress, blockIdentifier) {
|
|
4653
|
+
return this.provider.getClassHashAt(contractAddress, blockIdentifier);
|
|
4654
|
+
}
|
|
4655
|
+
getClassByHash(classHash) {
|
|
4656
|
+
return this.provider.getClassByHash(classHash);
|
|
4657
|
+
}
|
|
4658
|
+
async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
4659
|
+
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
4660
|
+
}
|
|
4661
|
+
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
|
|
4662
|
+
return this.provider.getInvokeEstimateFee(
|
|
4663
|
+
invocationWithTxType,
|
|
4664
|
+
invocationDetails,
|
|
4665
|
+
blockIdentifier,
|
|
4666
|
+
skipValidate
|
|
4667
|
+
);
|
|
4668
|
+
}
|
|
4669
|
+
async getEstimateFeeBulk(invocations, blockIdentifier) {
|
|
4670
|
+
return this.provider.getEstimateFeeBulk(invocations, blockIdentifier);
|
|
4671
|
+
}
|
|
4672
|
+
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
4673
|
+
return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
|
|
4674
|
+
}
|
|
4675
|
+
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4676
|
+
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
|
|
4677
|
+
}
|
|
4678
|
+
async getTransaction(txHash) {
|
|
4679
|
+
return this.provider.getTransaction(txHash);
|
|
4680
|
+
}
|
|
4681
|
+
async getTransactionReceipt(txHash) {
|
|
4682
|
+
return this.provider.getTransactionReceipt(txHash);
|
|
4683
|
+
}
|
|
4684
|
+
async callContract(request, blockIdentifier) {
|
|
4685
|
+
return this.provider.callContract(request, blockIdentifier);
|
|
4686
|
+
}
|
|
4687
|
+
async invokeFunction(functionInvocation, details) {
|
|
4688
|
+
return this.provider.invokeFunction(functionInvocation, details);
|
|
4689
|
+
}
|
|
4690
|
+
async deployAccountContract(payload, details) {
|
|
4691
|
+
return this.provider.deployAccountContract(payload, details);
|
|
4692
|
+
}
|
|
4693
|
+
async declareContract(transaction, details) {
|
|
4694
|
+
return this.provider.declareContract(transaction, details);
|
|
4695
|
+
}
|
|
4696
|
+
async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4697
|
+
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
|
|
4698
|
+
}
|
|
4699
|
+
getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
4700
|
+
return this.provider.getDeployAccountEstimateFee(
|
|
4701
|
+
transaction,
|
|
4702
|
+
details,
|
|
4703
|
+
blockIdentifier,
|
|
4704
|
+
skipValidate
|
|
4705
|
+
);
|
|
4706
|
+
}
|
|
4707
|
+
async getCode(contractAddress, blockIdentifier) {
|
|
4708
|
+
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
4709
|
+
}
|
|
4710
|
+
async waitForTransaction(txHash, options) {
|
|
4711
|
+
return this.provider.waitForTransaction(txHash, options);
|
|
4712
|
+
}
|
|
4713
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
|
|
4714
|
+
return this.provider.getSimulateTransaction(
|
|
4715
|
+
invocation,
|
|
4716
|
+
invocationDetails,
|
|
4717
|
+
blockIdentifier,
|
|
4718
|
+
skipValidate
|
|
4732
4719
|
);
|
|
4733
4720
|
}
|
|
4721
|
+
async getStateUpdate(blockIdentifier) {
|
|
4722
|
+
return this.provider.getStateUpdate(blockIdentifier);
|
|
4723
|
+
}
|
|
4724
|
+
async getStarkName(address, StarknetIdContract2) {
|
|
4725
|
+
return getStarkName(this, address, StarknetIdContract2);
|
|
4726
|
+
}
|
|
4727
|
+
async getAddressFromStarkName(name, StarknetIdContract2) {
|
|
4728
|
+
return getAddressFromStarkName(this, name, StarknetIdContract2);
|
|
4729
|
+
}
|
|
4730
|
+
};
|
|
4731
|
+
|
|
4732
|
+
// src/provider/interface.ts
|
|
4733
|
+
var ProviderInterface = class {
|
|
4734
4734
|
};
|
|
4735
4735
|
|
|
4736
|
+
// src/provider/index.ts
|
|
4737
|
+
var defaultProvider = new Provider();
|
|
4738
|
+
|
|
4736
4739
|
// src/contract/default.ts
|
|
4737
4740
|
var splitArgsAndOptions = (args) => {
|
|
4738
4741
|
const options = [
|
|
@@ -4742,13 +4745,14 @@ var splitArgsAndOptions = (args) => {
|
|
|
4742
4745
|
"formatResponse",
|
|
4743
4746
|
"maxFee",
|
|
4744
4747
|
"nonce",
|
|
4745
|
-
"signature"
|
|
4748
|
+
"signature",
|
|
4749
|
+
"addressSalt"
|
|
4746
4750
|
];
|
|
4747
4751
|
const lastArg = args[args.length - 1];
|
|
4748
4752
|
if (typeof lastArg === "object" && options.some((x) => x in lastArg)) {
|
|
4749
4753
|
return { args, options: args.pop() };
|
|
4750
4754
|
}
|
|
4751
|
-
return { args
|
|
4755
|
+
return { args };
|
|
4752
4756
|
};
|
|
4753
4757
|
function buildCall(contract, functionAbi) {
|
|
4754
4758
|
return async function(...args) {
|
|
@@ -4785,20 +4789,20 @@ function buildEstimate(contract, functionAbi) {
|
|
|
4785
4789
|
return contract.estimate(functionAbi.name, args);
|
|
4786
4790
|
};
|
|
4787
4791
|
}
|
|
4788
|
-
|
|
4789
|
-
if (
|
|
4790
|
-
return
|
|
4791
|
-
|
|
4792
|
-
|
|
4792
|
+
function getCalldata(args, callback) {
|
|
4793
|
+
if ("__compiled__" in args)
|
|
4794
|
+
return args;
|
|
4795
|
+
if (Array.isArray(args[0]) && "__compiled__" in args[0])
|
|
4796
|
+
return args[0];
|
|
4797
|
+
return callback();
|
|
4798
|
+
}
|
|
4793
4799
|
var Contract = class {
|
|
4794
|
-
constructor(abi, address, providerOrAccount = defaultProvider
|
|
4795
|
-
this.version = "0";
|
|
4800
|
+
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
4796
4801
|
this.address = address && address.toLowerCase();
|
|
4797
4802
|
this.providerOrAccount = providerOrAccount;
|
|
4798
4803
|
this.callData = new CallData(abi);
|
|
4799
4804
|
this.structs = CallData.getAbiStruct(abi);
|
|
4800
4805
|
this.abi = abi;
|
|
4801
|
-
this.version = cairoVersion;
|
|
4802
4806
|
const options = { enumerable: true, value: {}, writable: false };
|
|
4803
4807
|
Object.defineProperties(this, {
|
|
4804
4808
|
functions: { enumerable: true, value: {}, writable: false },
|
|
@@ -4855,15 +4859,21 @@ var Contract = class {
|
|
|
4855
4859
|
}
|
|
4856
4860
|
return this;
|
|
4857
4861
|
}
|
|
4858
|
-
async call(method, args = [],
|
|
4862
|
+
async call(method, args = [], {
|
|
4863
|
+
parseRequest = true,
|
|
4864
|
+
parseResponse = true,
|
|
4865
|
+
formatResponse = void 0,
|
|
4866
|
+
blockIdentifier = void 0
|
|
4867
|
+
} = {}) {
|
|
4859
4868
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4860
|
-
const
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4869
|
+
const calldata = getCalldata(args, () => {
|
|
4870
|
+
if (parseRequest) {
|
|
4871
|
+
this.callData.validate("CALL", method, args);
|
|
4872
|
+
return this.callData.compile(method, args);
|
|
4873
|
+
}
|
|
4874
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
4875
|
+
return args;
|
|
4876
|
+
});
|
|
4867
4877
|
return this.providerOrAccount.callContract(
|
|
4868
4878
|
{
|
|
4869
4879
|
contractAddress: this.address,
|
|
@@ -4872,25 +4882,25 @@ var Contract = class {
|
|
|
4872
4882
|
},
|
|
4873
4883
|
blockIdentifier
|
|
4874
4884
|
).then((x) => {
|
|
4875
|
-
if (!
|
|
4885
|
+
if (!parseResponse) {
|
|
4876
4886
|
return x.result;
|
|
4877
4887
|
}
|
|
4878
|
-
if (
|
|
4879
|
-
return this.callData.format(method, x.result,
|
|
4888
|
+
if (formatResponse) {
|
|
4889
|
+
return this.callData.format(method, x.result, formatResponse);
|
|
4880
4890
|
}
|
|
4881
4891
|
return this.callData.parse(method, x.result);
|
|
4882
4892
|
});
|
|
4883
4893
|
}
|
|
4884
|
-
invoke(method, args = [],
|
|
4885
|
-
parseRequest: true
|
|
4886
|
-
}) {
|
|
4894
|
+
invoke(method, args = [], { parseRequest = true, maxFee, nonce, signature } = {}) {
|
|
4887
4895
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4896
|
+
const calldata = getCalldata(args, () => {
|
|
4897
|
+
if (parseRequest) {
|
|
4898
|
+
this.callData.validate("INVOKE", method, args);
|
|
4899
|
+
return this.callData.compile(method, args);
|
|
4900
|
+
}
|
|
4901
|
+
console.warn("Invoke skipped parsing but provided rawArgs, possible malfunction request");
|
|
4902
|
+
return args;
|
|
4903
|
+
});
|
|
4894
4904
|
const invocation = {
|
|
4895
4905
|
contractAddress: this.address,
|
|
4896
4906
|
calldata,
|
|
@@ -4898,40 +4908,36 @@ var Contract = class {
|
|
|
4898
4908
|
};
|
|
4899
4909
|
if ("execute" in this.providerOrAccount) {
|
|
4900
4910
|
return this.providerOrAccount.execute(invocation, void 0, {
|
|
4901
|
-
maxFee
|
|
4902
|
-
nonce
|
|
4911
|
+
maxFee,
|
|
4912
|
+
nonce
|
|
4903
4913
|
});
|
|
4904
4914
|
}
|
|
4905
|
-
if (!
|
|
4915
|
+
if (!nonce)
|
|
4906
4916
|
throw new Error(`Nonce is required when invoking a function without an account`);
|
|
4907
|
-
}
|
|
4908
4917
|
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
4909
4918
|
return this.providerOrAccount.invokeFunction(
|
|
4910
4919
|
{
|
|
4911
4920
|
...invocation,
|
|
4912
|
-
signature
|
|
4921
|
+
signature
|
|
4913
4922
|
},
|
|
4914
4923
|
{
|
|
4915
|
-
nonce
|
|
4924
|
+
nonce
|
|
4916
4925
|
}
|
|
4917
4926
|
);
|
|
4918
4927
|
}
|
|
4919
4928
|
async estimate(method, args = []) {
|
|
4920
|
-
var _a;
|
|
4921
4929
|
assert(this.address !== null, "contract is not connected to an address");
|
|
4922
|
-
if (!((
|
|
4930
|
+
if (!getCalldata(args, () => false)) {
|
|
4923
4931
|
this.callData.validate("INVOKE", method, args);
|
|
4924
4932
|
}
|
|
4925
|
-
const invocation = this.
|
|
4933
|
+
const invocation = this.populate(method, args);
|
|
4926
4934
|
if ("estimateInvokeFee" in this.providerOrAccount) {
|
|
4927
4935
|
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
4928
4936
|
}
|
|
4929
4937
|
throw Error("Contract must be connected to the account contract to estimate");
|
|
4930
4938
|
}
|
|
4931
4939
|
populate(method, args = []) {
|
|
4932
|
-
|
|
4933
|
-
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
4934
|
-
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);
|
|
4940
|
+
const calldata = getCalldata(args, () => this.callData.compile(method, args));
|
|
4935
4941
|
return {
|
|
4936
4942
|
contractAddress: this.address,
|
|
4937
4943
|
entrypoint: method,
|
|
@@ -4951,36 +4957,24 @@ var ContractFactory = class {
|
|
|
4951
4957
|
this.compiledContract = compiledContract;
|
|
4952
4958
|
this.account = account;
|
|
4953
4959
|
this.classHash = classHash;
|
|
4954
|
-
this.
|
|
4960
|
+
this.CallData = new CallData(abi);
|
|
4955
4961
|
}
|
|
4956
4962
|
async deploy(...args) {
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
if (typeof arg !== "object")
|
|
4963
|
-
return;
|
|
4964
|
-
if ("addressSalt" in arg) {
|
|
4965
|
-
addressSalt = arg.addressSalt;
|
|
4966
|
-
}
|
|
4967
|
-
if ("parseRequest" in arg) {
|
|
4968
|
-
parseRequest = arg.parseRequest;
|
|
4963
|
+
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
4964
|
+
const constructorCalldata = getCalldata(param, () => {
|
|
4965
|
+
if (options.parseRequest) {
|
|
4966
|
+
this.CallData.validate("DEPLOY", "constructor", param);
|
|
4967
|
+
return this.CallData.compile("constructor", param);
|
|
4969
4968
|
}
|
|
4969
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
4970
|
+
return param;
|
|
4970
4971
|
});
|
|
4971
|
-
if (!parseRequest || ((_a = args[0]) == null ? void 0 : _a.compiled)) {
|
|
4972
|
-
constructorCalldata = args[0];
|
|
4973
|
-
} else {
|
|
4974
|
-
this.callData.validate("DEPLOY", "constructor", args);
|
|
4975
|
-
const { inputs } = this.abi.find((abi) => abi.type === "constructor");
|
|
4976
|
-
constructorCalldata = this.callData.compile(args, inputs);
|
|
4977
|
-
}
|
|
4978
4972
|
const {
|
|
4979
4973
|
deploy: { contract_address, transaction_hash }
|
|
4980
4974
|
} = await this.account.declareAndDeploy({
|
|
4981
4975
|
contract: this.compiledContract,
|
|
4982
4976
|
constructorCalldata,
|
|
4983
|
-
salt: addressSalt
|
|
4977
|
+
salt: options.addressSalt
|
|
4984
4978
|
});
|
|
4985
4979
|
assert(Boolean(contract_address), "Deployment of the contract failed");
|
|
4986
4980
|
const contractInstance = new Contract(
|
|
@@ -5608,7 +5602,7 @@ var Account = class extends Provider {
|
|
|
5608
5602
|
unique = true,
|
|
5609
5603
|
constructorCalldata = []
|
|
5610
5604
|
} = it;
|
|
5611
|
-
const compiledConstructorCallData =
|
|
5605
|
+
const compiledConstructorCallData = CallData.compile(constructorCalldata);
|
|
5612
5606
|
const deploySalt = salt ?? randomAddress();
|
|
5613
5607
|
return {
|
|
5614
5608
|
call: {
|
|
@@ -5632,7 +5626,10 @@ var Account = class extends Provider {
|
|
|
5632
5626
|
});
|
|
5633
5627
|
const calls = params.map((it) => it.call);
|
|
5634
5628
|
const addresses = params.map((it) => it.address);
|
|
5635
|
-
const invokeResponse = await this.execute(calls, void 0,
|
|
5629
|
+
const invokeResponse = await this.execute(calls, void 0, {
|
|
5630
|
+
...details,
|
|
5631
|
+
cairoVersion: "0"
|
|
5632
|
+
});
|
|
5636
5633
|
return {
|
|
5637
5634
|
...invokeResponse,
|
|
5638
5635
|
contract_address: addresses
|
|
@@ -5704,7 +5701,7 @@ var Account = class extends Provider {
|
|
|
5704
5701
|
await this.callContract({
|
|
5705
5702
|
contractAddress: this.address,
|
|
5706
5703
|
entrypoint: "isValidSignature",
|
|
5707
|
-
calldata:
|
|
5704
|
+
calldata: CallData.compile({
|
|
5708
5705
|
hash: toBigInt(hash).toString(),
|
|
5709
5706
|
signature: formatSignature(signature)
|
|
5710
5707
|
})
|
|
@@ -5790,7 +5787,7 @@ var Account = class extends Provider {
|
|
|
5790
5787
|
unique = true,
|
|
5791
5788
|
constructorCalldata = []
|
|
5792
5789
|
} = it;
|
|
5793
|
-
const compiledConstructorCallData =
|
|
5790
|
+
const compiledConstructorCallData = CallData.compile(constructorCalldata);
|
|
5794
5791
|
return {
|
|
5795
5792
|
contractAddress: UDC.ADDRESS,
|
|
5796
5793
|
entrypoint: UDC.ENTRYPOINT,
|
|
@@ -5834,8 +5831,8 @@ var Account = class extends Provider {
|
|
|
5834
5831
|
}
|
|
5835
5832
|
};
|
|
5836
5833
|
}
|
|
5837
|
-
async getStarkName(address = this.address,
|
|
5838
|
-
return super.getStarkName(address,
|
|
5834
|
+
async getStarkName(address = this.address, StarknetIdContract2) {
|
|
5835
|
+
return super.getStarkName(address, StarknetIdContract2);
|
|
5839
5836
|
}
|
|
5840
5837
|
};
|
|
5841
5838
|
|
|
@@ -5907,6 +5904,7 @@ var number = num_exports;
|
|
|
5907
5904
|
encode,
|
|
5908
5905
|
fixProto,
|
|
5909
5906
|
fixStack,
|
|
5907
|
+
getCalldata,
|
|
5910
5908
|
getChecksumAddress,
|
|
5911
5909
|
hash,
|
|
5912
5910
|
isUrl,
|
|
@@ -5915,7 +5913,9 @@ var number = num_exports;
|
|
|
5915
5913
|
num,
|
|
5916
5914
|
number,
|
|
5917
5915
|
shortString,
|
|
5916
|
+
splitArgsAndOptions,
|
|
5918
5917
|
stark,
|
|
5918
|
+
starknetId,
|
|
5919
5919
|
transaction,
|
|
5920
5920
|
typedData,
|
|
5921
5921
|
uint256,
|