starknet 5.11.1 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +779 -513
- package/dist/index.global.js +3860 -3850
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +802 -795
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +802 -796
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,73 +4,28 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
TransactionType2["DEPLOY"] = "DEPLOY";
|
|
29
|
-
TransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
|
|
30
|
-
return TransactionType2;
|
|
31
|
-
})(TransactionType || {});
|
|
32
|
-
|
|
33
|
-
// src/types/api/rpc.ts
|
|
34
|
-
var RPC;
|
|
35
|
-
((RPC2) => {
|
|
36
|
-
let TransactionType2;
|
|
37
|
-
((TransactionType3) => {
|
|
38
|
-
TransactionType3["DECLARE"] = "DECLARE";
|
|
39
|
-
TransactionType3["DEPLOY"] = "DEPLOY";
|
|
40
|
-
TransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
|
|
41
|
-
TransactionType3["INVOKE"] = "INVOKE";
|
|
42
|
-
TransactionType3["L1_HANDLER"] = "L1_HANDLER";
|
|
43
|
-
})(TransactionType2 = RPC2.TransactionType || (RPC2.TransactionType = {}));
|
|
44
|
-
})(RPC || (RPC = {}));
|
|
45
|
-
|
|
46
|
-
// src/utils/assert.ts
|
|
47
|
-
function assert(condition, message) {
|
|
48
|
-
if (!condition) {
|
|
49
|
-
throw new Error(message || "Assertion failure");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// src/utils/num.ts
|
|
54
|
-
var num_exports = {};
|
|
55
|
-
__export(num_exports, {
|
|
56
|
-
assertInRange: () => assertInRange,
|
|
57
|
-
bigNumberishArrayToDecimalStringArray: () => bigNumberishArrayToDecimalStringArray,
|
|
58
|
-
bigNumberishArrayToHexadecimalStringArray: () => bigNumberishArrayToHexadecimalStringArray,
|
|
59
|
-
cleanHex: () => cleanHex,
|
|
60
|
-
getDecimalString: () => getDecimalString,
|
|
61
|
-
getHexString: () => getHexString,
|
|
62
|
-
getHexStringArray: () => getHexStringArray,
|
|
63
|
-
hexToBytes: () => hexToBytes,
|
|
64
|
-
hexToDecimalString: () => hexToDecimalString,
|
|
65
|
-
isBigInt: () => isBigInt,
|
|
66
|
-
isHex: () => isHex,
|
|
67
|
-
isStringWholeNumber: () => isStringWholeNumber,
|
|
68
|
-
toBigInt: () => toBigInt,
|
|
69
|
-
toCairoBool: () => toCairoBool,
|
|
70
|
-
toHex: () => toHex,
|
|
71
|
-
toHexString: () => toHexString
|
|
7
|
+
// src/constants.ts
|
|
8
|
+
var constants_exports = {};
|
|
9
|
+
__export(constants_exports, {
|
|
10
|
+
ALPHA: () => ALPHA,
|
|
11
|
+
API_VERSION: () => API_VERSION,
|
|
12
|
+
BETA: () => BETA,
|
|
13
|
+
BaseUrl: () => BaseUrl,
|
|
14
|
+
CONSTANT_POINTS: () => CONSTANT_POINTS,
|
|
15
|
+
EC_ORDER: () => EC_ORDER,
|
|
16
|
+
FIELD_GEN: () => FIELD_GEN,
|
|
17
|
+
FIELD_PRIME: () => FIELD_PRIME,
|
|
18
|
+
FIELD_SIZE: () => FIELD_SIZE,
|
|
19
|
+
IS_BROWSER: () => IS_BROWSER,
|
|
20
|
+
MASK_250: () => MASK_250,
|
|
21
|
+
MASK_251: () => MASK_251,
|
|
22
|
+
MAX_ECDSA_VAL: () => MAX_ECDSA_VAL,
|
|
23
|
+
NetworkName: () => NetworkName,
|
|
24
|
+
StarknetChainId: () => StarknetChainId,
|
|
25
|
+
TransactionHashPrefix: () => TransactionHashPrefix,
|
|
26
|
+
UDC: () => UDC,
|
|
27
|
+
ZERO: () => ZERO
|
|
72
28
|
});
|
|
73
|
-
import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
|
|
74
29
|
|
|
75
30
|
// src/utils/encode.ts
|
|
76
31
|
var encode_exports = {};
|
|
@@ -135,98 +90,7 @@ function utf8ToArray(str) {
|
|
|
135
90
|
return new TextEncoder().encode(str);
|
|
136
91
|
}
|
|
137
92
|
|
|
138
|
-
// src/utils/num.ts
|
|
139
|
-
function isHex(hex) {
|
|
140
|
-
return /^0x[0-9a-f]*$/i.test(hex);
|
|
141
|
-
}
|
|
142
|
-
function toBigInt(value) {
|
|
143
|
-
return BigInt(value);
|
|
144
|
-
}
|
|
145
|
-
function isBigInt(value) {
|
|
146
|
-
return typeof value === "bigint";
|
|
147
|
-
}
|
|
148
|
-
function toHex(number2) {
|
|
149
|
-
return addHexPrefix(toBigInt(number2).toString(16));
|
|
150
|
-
}
|
|
151
|
-
function hexToDecimalString(hex) {
|
|
152
|
-
return BigInt(addHexPrefix(hex)).toString(10);
|
|
153
|
-
}
|
|
154
|
-
var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
|
|
155
|
-
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
156
|
-
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
157
|
-
const inputBigInt = BigInt(input);
|
|
158
|
-
const lowerBoundBigInt = BigInt(lowerBound);
|
|
159
|
-
const upperBoundBigInt = BigInt(upperBound);
|
|
160
|
-
assert(
|
|
161
|
-
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
162
|
-
`Message not signable, ${messageSuffix}.`
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
166
|
-
return rawCalldata.map((x) => toBigInt(x).toString(10));
|
|
167
|
-
}
|
|
168
|
-
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
169
|
-
return rawCalldata.map((x) => toHex(x));
|
|
170
|
-
}
|
|
171
|
-
var isStringWholeNumber = (value) => /^\d+$/.test(value);
|
|
172
|
-
var toHexString = (value) => toHex(value);
|
|
173
|
-
function getDecimalString(value) {
|
|
174
|
-
if (isHex(value)) {
|
|
175
|
-
return hexToDecimalString(value);
|
|
176
|
-
}
|
|
177
|
-
if (isStringWholeNumber(value)) {
|
|
178
|
-
return value;
|
|
179
|
-
}
|
|
180
|
-
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
181
|
-
}
|
|
182
|
-
function getHexString(value) {
|
|
183
|
-
if (isHex(value)) {
|
|
184
|
-
return value;
|
|
185
|
-
}
|
|
186
|
-
if (isStringWholeNumber(value)) {
|
|
187
|
-
return toHexString(value);
|
|
188
|
-
}
|
|
189
|
-
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
190
|
-
}
|
|
191
|
-
function getHexStringArray(value) {
|
|
192
|
-
return value.map((el) => getHexString(el));
|
|
193
|
-
}
|
|
194
|
-
var toCairoBool = (value) => (+value).toString();
|
|
195
|
-
function hexToBytes(value) {
|
|
196
|
-
if (!isHex(value))
|
|
197
|
-
throw new Error(`${value} need to be a hex-string`);
|
|
198
|
-
let adaptedValue = removeHexPrefix(value);
|
|
199
|
-
if (adaptedValue.length % 2 !== 0) {
|
|
200
|
-
adaptedValue = `0${adaptedValue}`;
|
|
201
|
-
}
|
|
202
|
-
return hexToBytesNoble(adaptedValue);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// src/utils/selector.ts
|
|
206
|
-
import { keccak } from "micro-starknet";
|
|
207
|
-
|
|
208
93
|
// src/constants.ts
|
|
209
|
-
var constants_exports = {};
|
|
210
|
-
__export(constants_exports, {
|
|
211
|
-
ALPHA: () => ALPHA,
|
|
212
|
-
API_VERSION: () => API_VERSION,
|
|
213
|
-
BETA: () => BETA,
|
|
214
|
-
BaseUrl: () => BaseUrl,
|
|
215
|
-
CONSTANT_POINTS: () => CONSTANT_POINTS,
|
|
216
|
-
EC_ORDER: () => EC_ORDER,
|
|
217
|
-
FIELD_GEN: () => FIELD_GEN,
|
|
218
|
-
FIELD_PRIME: () => FIELD_PRIME,
|
|
219
|
-
FIELD_SIZE: () => FIELD_SIZE,
|
|
220
|
-
IS_BROWSER: () => IS_BROWSER,
|
|
221
|
-
MASK_250: () => MASK_250,
|
|
222
|
-
MASK_251: () => MASK_251,
|
|
223
|
-
MAX_ECDSA_VAL: () => MAX_ECDSA_VAL,
|
|
224
|
-
NetworkName: () => NetworkName,
|
|
225
|
-
StarknetChainId: () => StarknetChainId,
|
|
226
|
-
TransactionHashPrefix: () => TransactionHashPrefix,
|
|
227
|
-
UDC: () => UDC,
|
|
228
|
-
ZERO: () => ZERO
|
|
229
|
-
});
|
|
230
94
|
var ZERO = 0n;
|
|
231
95
|
var MASK_250 = 2n ** 250n - 1n;
|
|
232
96
|
var MASK_251 = 2n ** 251n;
|
|
@@ -2295,42 +2159,185 @@ var CONSTANT_POINTS = [
|
|
|
2295
2159
|
]
|
|
2296
2160
|
];
|
|
2297
2161
|
|
|
2298
|
-
// src/
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
return
|
|
2313
|
-
}
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2162
|
+
// src/types/index.ts
|
|
2163
|
+
var types_exports = {};
|
|
2164
|
+
__export(types_exports, {
|
|
2165
|
+
EntryPointType: () => EntryPointType,
|
|
2166
|
+
RPC: () => RPC,
|
|
2167
|
+
TransactionStatus: () => TransactionStatus,
|
|
2168
|
+
TransactionType: () => TransactionType
|
|
2169
|
+
});
|
|
2170
|
+
|
|
2171
|
+
// src/types/lib/contract/index.ts
|
|
2172
|
+
var EntryPointType = /* @__PURE__ */ ((EntryPointType2) => {
|
|
2173
|
+
EntryPointType2["EXTERNAL"] = "EXTERNAL";
|
|
2174
|
+
EntryPointType2["L1_HANDLER"] = "L1_HANDLER";
|
|
2175
|
+
EntryPointType2["CONSTRUCTOR"] = "CONSTRUCTOR";
|
|
2176
|
+
return EntryPointType2;
|
|
2177
|
+
})(EntryPointType || {});
|
|
2178
|
+
|
|
2179
|
+
// src/types/lib/index.ts
|
|
2180
|
+
var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
|
2181
|
+
TransactionStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
|
|
2182
|
+
TransactionStatus2["RECEIVED"] = "RECEIVED";
|
|
2183
|
+
TransactionStatus2["PENDING"] = "PENDING";
|
|
2184
|
+
TransactionStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
|
|
2185
|
+
TransactionStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
|
|
2186
|
+
TransactionStatus2["REJECTED"] = "REJECTED";
|
|
2187
|
+
return TransactionStatus2;
|
|
2188
|
+
})(TransactionStatus || {});
|
|
2189
|
+
var TransactionType = /* @__PURE__ */ ((TransactionType2) => {
|
|
2190
|
+
TransactionType2["INVOKE"] = "INVOKE_FUNCTION";
|
|
2191
|
+
TransactionType2["DECLARE"] = "DECLARE";
|
|
2192
|
+
TransactionType2["DEPLOY"] = "DEPLOY";
|
|
2193
|
+
TransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
|
|
2194
|
+
return TransactionType2;
|
|
2195
|
+
})(TransactionType || {});
|
|
2196
|
+
|
|
2197
|
+
// src/types/api/rpc.ts
|
|
2198
|
+
var RPC;
|
|
2199
|
+
((RPC2) => {
|
|
2200
|
+
let TransactionType2;
|
|
2201
|
+
((TransactionType3) => {
|
|
2202
|
+
TransactionType3["DECLARE"] = "DECLARE";
|
|
2203
|
+
TransactionType3["DEPLOY"] = "DEPLOY";
|
|
2204
|
+
TransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
|
|
2205
|
+
TransactionType3["INVOKE"] = "INVOKE";
|
|
2206
|
+
TransactionType3["L1_HANDLER"] = "L1_HANDLER";
|
|
2207
|
+
})(TransactionType2 = RPC2.TransactionType || (RPC2.TransactionType = {}));
|
|
2208
|
+
})(RPC || (RPC = {}));
|
|
2209
|
+
|
|
2210
|
+
// src/utils/assert.ts
|
|
2211
|
+
function assert(condition, message) {
|
|
2212
|
+
if (!condition) {
|
|
2213
|
+
throw new Error(message || "Assertion failure");
|
|
2320
2214
|
}
|
|
2321
|
-
return getSelectorFromName(value);
|
|
2322
2215
|
}
|
|
2323
2216
|
|
|
2324
|
-
// src/utils/
|
|
2325
|
-
var
|
|
2326
|
-
__export(
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2217
|
+
// src/utils/num.ts
|
|
2218
|
+
var num_exports = {};
|
|
2219
|
+
__export(num_exports, {
|
|
2220
|
+
assertInRange: () => assertInRange,
|
|
2221
|
+
bigNumberishArrayToDecimalStringArray: () => bigNumberishArrayToDecimalStringArray,
|
|
2222
|
+
bigNumberishArrayToHexadecimalStringArray: () => bigNumberishArrayToHexadecimalStringArray,
|
|
2223
|
+
cleanHex: () => cleanHex,
|
|
2224
|
+
getDecimalString: () => getDecimalString,
|
|
2225
|
+
getHexString: () => getHexString,
|
|
2226
|
+
getHexStringArray: () => getHexStringArray,
|
|
2227
|
+
hexToBytes: () => hexToBytes,
|
|
2228
|
+
hexToDecimalString: () => hexToDecimalString,
|
|
2229
|
+
isBigInt: () => isBigInt,
|
|
2230
|
+
isHex: () => isHex,
|
|
2231
|
+
isStringWholeNumber: () => isStringWholeNumber,
|
|
2232
|
+
toBigInt: () => toBigInt,
|
|
2233
|
+
toCairoBool: () => toCairoBool,
|
|
2234
|
+
toHex: () => toHex,
|
|
2235
|
+
toHexString: () => toHexString
|
|
2236
|
+
});
|
|
2237
|
+
import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
|
|
2238
|
+
function isHex(hex) {
|
|
2239
|
+
return /^0x[0-9a-f]*$/i.test(hex);
|
|
2240
|
+
}
|
|
2241
|
+
function toBigInt(value) {
|
|
2242
|
+
return BigInt(value);
|
|
2243
|
+
}
|
|
2244
|
+
function isBigInt(value) {
|
|
2245
|
+
return typeof value === "bigint";
|
|
2246
|
+
}
|
|
2247
|
+
function toHex(number2) {
|
|
2248
|
+
return addHexPrefix(toBigInt(number2).toString(16));
|
|
2249
|
+
}
|
|
2250
|
+
function hexToDecimalString(hex) {
|
|
2251
|
+
return BigInt(addHexPrefix(hex)).toString(10);
|
|
2252
|
+
}
|
|
2253
|
+
var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
|
|
2254
|
+
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
2255
|
+
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
2256
|
+
const inputBigInt = BigInt(input);
|
|
2257
|
+
const lowerBoundBigInt = BigInt(lowerBound);
|
|
2258
|
+
const upperBoundBigInt = BigInt(upperBound);
|
|
2259
|
+
assert(
|
|
2260
|
+
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
2261
|
+
`Message not signable, ${messageSuffix}.`
|
|
2262
|
+
);
|
|
2263
|
+
}
|
|
2264
|
+
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
2265
|
+
return rawCalldata.map((x) => toBigInt(x).toString(10));
|
|
2266
|
+
}
|
|
2267
|
+
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
2268
|
+
return rawCalldata.map((x) => toHex(x));
|
|
2269
|
+
}
|
|
2270
|
+
var isStringWholeNumber = (value) => /^\d+$/.test(value);
|
|
2271
|
+
var toHexString = (value) => toHex(value);
|
|
2272
|
+
function getDecimalString(value) {
|
|
2273
|
+
if (isHex(value)) {
|
|
2274
|
+
return hexToDecimalString(value);
|
|
2275
|
+
}
|
|
2276
|
+
if (isStringWholeNumber(value)) {
|
|
2277
|
+
return value;
|
|
2278
|
+
}
|
|
2279
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
2280
|
+
}
|
|
2281
|
+
function getHexString(value) {
|
|
2282
|
+
if (isHex(value)) {
|
|
2283
|
+
return value;
|
|
2284
|
+
}
|
|
2285
|
+
if (isStringWholeNumber(value)) {
|
|
2286
|
+
return toHexString(value);
|
|
2287
|
+
}
|
|
2288
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
2289
|
+
}
|
|
2290
|
+
function getHexStringArray(value) {
|
|
2291
|
+
return value.map((el) => getHexString(el));
|
|
2292
|
+
}
|
|
2293
|
+
var toCairoBool = (value) => (+value).toString();
|
|
2294
|
+
function hexToBytes(value) {
|
|
2295
|
+
if (!isHex(value))
|
|
2296
|
+
throw new Error(`${value} need to be a hex-string`);
|
|
2297
|
+
let adaptedValue = removeHexPrefix(value);
|
|
2298
|
+
if (adaptedValue.length % 2 !== 0) {
|
|
2299
|
+
adaptedValue = `0${adaptedValue}`;
|
|
2300
|
+
}
|
|
2301
|
+
return hexToBytesNoble(adaptedValue);
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
// src/utils/selector.ts
|
|
2305
|
+
import { keccak } from "micro-starknet";
|
|
2306
|
+
function keccakBn(value) {
|
|
2307
|
+
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
2308
|
+
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2309
|
+
return addHexPrefix(keccak(hexToBytes(addHexPrefix(evenHex))).toString(16));
|
|
2310
|
+
}
|
|
2311
|
+
function keccakHex(value) {
|
|
2312
|
+
return addHexPrefix(keccak(utf8ToArray(value)).toString(16));
|
|
2313
|
+
}
|
|
2314
|
+
function starknetKeccak(value) {
|
|
2315
|
+
const hash = BigInt(keccakHex(value));
|
|
2316
|
+
return hash & MASK_250;
|
|
2317
|
+
}
|
|
2318
|
+
function getSelectorFromName(funcName) {
|
|
2319
|
+
return toHex(starknetKeccak(funcName));
|
|
2320
|
+
}
|
|
2321
|
+
function getSelector(value) {
|
|
2322
|
+
if (isHex(value)) {
|
|
2323
|
+
return value;
|
|
2324
|
+
}
|
|
2325
|
+
if (isStringWholeNumber(value)) {
|
|
2326
|
+
return toHexString(value);
|
|
2327
|
+
}
|
|
2328
|
+
return getSelectorFromName(value);
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
// src/utils/shortString.ts
|
|
2332
|
+
var shortString_exports = {};
|
|
2333
|
+
__export(shortString_exports, {
|
|
2334
|
+
decodeShortString: () => decodeShortString,
|
|
2335
|
+
encodeShortString: () => encodeShortString,
|
|
2336
|
+
isASCII: () => isASCII,
|
|
2337
|
+
isDecimalString: () => isDecimalString,
|
|
2338
|
+
isLongText: () => isLongText,
|
|
2339
|
+
isShortString: () => isShortString,
|
|
2340
|
+
isShortText: () => isShortText,
|
|
2334
2341
|
isText: () => isText,
|
|
2335
2342
|
splitLongString: () => splitLongString
|
|
2336
2343
|
});
|
|
@@ -4956,463 +4963,169 @@ var Provider = class {
|
|
|
4956
4963
|
}
|
|
4957
4964
|
};
|
|
4958
4965
|
|
|
4959
|
-
// src/
|
|
4960
|
-
var
|
|
4966
|
+
// src/signer/interface.ts
|
|
4967
|
+
var SignerInterface = class {
|
|
4961
4968
|
};
|
|
4962
4969
|
|
|
4963
|
-
// src/
|
|
4964
|
-
var
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
};
|
|
4984
|
-
function buildCall(contract, functionAbi) {
|
|
4985
|
-
return async function(...args) {
|
|
4986
|
-
const params = splitArgsAndOptions(args);
|
|
4987
|
-
return contract.call(functionAbi.name, params.args, {
|
|
4988
|
-
parseRequest: true,
|
|
4989
|
-
parseResponse: true,
|
|
4990
|
-
...params.options
|
|
4991
|
-
});
|
|
4992
|
-
};
|
|
4993
|
-
}
|
|
4994
|
-
function buildInvoke(contract, functionAbi) {
|
|
4995
|
-
return async function(...args) {
|
|
4996
|
-
const params = splitArgsAndOptions(args);
|
|
4997
|
-
return contract.invoke(functionAbi.name, params.args, {
|
|
4998
|
-
parseRequest: true,
|
|
4999
|
-
...params.options
|
|
4970
|
+
// src/utils/transaction.ts
|
|
4971
|
+
var transaction_exports = {};
|
|
4972
|
+
__export(transaction_exports, {
|
|
4973
|
+
fromCallsToExecuteCalldata: () => fromCallsToExecuteCalldata,
|
|
4974
|
+
fromCallsToExecuteCalldataWithNonce: () => fromCallsToExecuteCalldataWithNonce,
|
|
4975
|
+
fromCallsToExecuteCalldata_cairo1: () => fromCallsToExecuteCalldata_cairo1,
|
|
4976
|
+
getExecuteCalldata: () => getExecuteCalldata,
|
|
4977
|
+
transformCallsToMulticallArrays: () => transformCallsToMulticallArrays,
|
|
4978
|
+
transformCallsToMulticallArrays_cairo1: () => transformCallsToMulticallArrays_cairo1
|
|
4979
|
+
});
|
|
4980
|
+
var transformCallsToMulticallArrays = (calls) => {
|
|
4981
|
+
const callArray = [];
|
|
4982
|
+
const calldata = [];
|
|
4983
|
+
calls.forEach((call) => {
|
|
4984
|
+
const data = CallData.compile(call.calldata || []);
|
|
4985
|
+
callArray.push({
|
|
4986
|
+
to: toBigInt(call.contractAddress).toString(10),
|
|
4987
|
+
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
4988
|
+
data_offset: calldata.length.toString(),
|
|
4989
|
+
data_len: data.length.toString()
|
|
5000
4990
|
});
|
|
4991
|
+
calldata.push(...data);
|
|
4992
|
+
});
|
|
4993
|
+
return {
|
|
4994
|
+
callArray,
|
|
4995
|
+
calldata: CallData.compile({ calldata })
|
|
5001
4996
|
};
|
|
5002
|
-
}
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
4997
|
+
};
|
|
4998
|
+
var fromCallsToExecuteCalldata = (calls) => {
|
|
4999
|
+
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
5000
|
+
const compiledCalls = CallData.compile({ callArray });
|
|
5001
|
+
return [...compiledCalls, ...calldata];
|
|
5002
|
+
};
|
|
5003
|
+
var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
|
|
5004
|
+
return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
|
|
5005
|
+
};
|
|
5006
|
+
var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
5007
|
+
const callArray = calls.map((call) => ({
|
|
5008
|
+
to: toBigInt(call.contractAddress).toString(10),
|
|
5009
|
+
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
5010
|
+
calldata: CallData.compile(call.calldata || [])
|
|
5011
|
+
}));
|
|
5012
|
+
return callArray;
|
|
5013
|
+
};
|
|
5014
|
+
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
5015
|
+
const orderCalls = calls.map((call) => ({
|
|
5016
|
+
contractAddress: call.contractAddress,
|
|
5017
|
+
entrypoint: call.entrypoint,
|
|
5018
|
+
calldata: call.calldata
|
|
5019
|
+
}));
|
|
5020
|
+
return CallData.compile({ orderCalls });
|
|
5021
|
+
};
|
|
5022
|
+
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
5023
|
+
if (cairoVersion === "1") {
|
|
5024
|
+
return fromCallsToExecuteCalldata_cairo1(calls);
|
|
5006
5025
|
}
|
|
5007
|
-
return
|
|
5008
|
-
}
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
}
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
this.address = address && address.toLowerCase();
|
|
5036
|
-
this.providerOrAccount = providerOrAccount;
|
|
5037
|
-
this.callData = new CallData(abi);
|
|
5038
|
-
this.structs = CallData.getAbiStruct(abi);
|
|
5039
|
-
this.abi = abi;
|
|
5040
|
-
const options = { enumerable: true, value: {}, writable: false };
|
|
5041
|
-
Object.defineProperties(this, {
|
|
5042
|
-
functions: { enumerable: true, value: {}, writable: false },
|
|
5043
|
-
callStatic: { enumerable: true, value: {}, writable: false },
|
|
5044
|
-
populateTransaction: { enumerable: true, value: {}, writable: false },
|
|
5045
|
-
estimateFee: { enumerable: true, value: {}, writable: false }
|
|
5046
|
-
});
|
|
5047
|
-
this.abi.forEach((abiElement) => {
|
|
5048
|
-
if (abiElement.type !== "function")
|
|
5049
|
-
return;
|
|
5050
|
-
const signature = abiElement.name;
|
|
5051
|
-
if (!this[signature]) {
|
|
5052
|
-
Object.defineProperty(this, signature, {
|
|
5053
|
-
...options,
|
|
5054
|
-
value: buildDefault(this, abiElement)
|
|
5055
|
-
});
|
|
5056
|
-
}
|
|
5057
|
-
if (!this.functions[signature]) {
|
|
5058
|
-
Object.defineProperty(this.functions, signature, {
|
|
5059
|
-
...options,
|
|
5060
|
-
value: buildDefault(this, abiElement)
|
|
5061
|
-
});
|
|
5062
|
-
}
|
|
5063
|
-
if (!this.callStatic[signature]) {
|
|
5064
|
-
Object.defineProperty(this.callStatic, signature, {
|
|
5065
|
-
...options,
|
|
5066
|
-
value: buildCall(this, abiElement)
|
|
5067
|
-
});
|
|
5068
|
-
}
|
|
5069
|
-
if (!this.populateTransaction[signature]) {
|
|
5070
|
-
Object.defineProperty(this.populateTransaction, signature, {
|
|
5071
|
-
...options,
|
|
5072
|
-
value: buildPopulate(this, abiElement)
|
|
5073
|
-
});
|
|
5074
|
-
}
|
|
5075
|
-
if (!this.estimateFee[signature]) {
|
|
5076
|
-
Object.defineProperty(this.estimateFee, signature, {
|
|
5077
|
-
...options,
|
|
5078
|
-
value: buildEstimate(this, abiElement)
|
|
5079
|
-
});
|
|
5080
|
-
}
|
|
5081
|
-
});
|
|
5082
|
-
}
|
|
5083
|
-
attach(address) {
|
|
5084
|
-
this.address = address;
|
|
5085
|
-
}
|
|
5086
|
-
connect(providerOrAccount) {
|
|
5087
|
-
this.providerOrAccount = providerOrAccount;
|
|
5026
|
+
return fromCallsToExecuteCalldata(calls);
|
|
5027
|
+
};
|
|
5028
|
+
|
|
5029
|
+
// src/utils/typedData.ts
|
|
5030
|
+
var typedData_exports = {};
|
|
5031
|
+
__export(typedData_exports, {
|
|
5032
|
+
encodeData: () => encodeData,
|
|
5033
|
+
encodeType: () => encodeType,
|
|
5034
|
+
encodeValue: () => encodeValue,
|
|
5035
|
+
getDependencies: () => getDependencies,
|
|
5036
|
+
getMessageHash: () => getMessageHash,
|
|
5037
|
+
getStructHash: () => getStructHash,
|
|
5038
|
+
getTypeHash: () => getTypeHash,
|
|
5039
|
+
isMerkleTreeType: () => isMerkleTreeType,
|
|
5040
|
+
prepareSelector: () => prepareSelector
|
|
5041
|
+
});
|
|
5042
|
+
|
|
5043
|
+
// src/utils/merkle.ts
|
|
5044
|
+
var merkle_exports = {};
|
|
5045
|
+
__export(merkle_exports, {
|
|
5046
|
+
MerkleTree: () => MerkleTree,
|
|
5047
|
+
proofMerklePath: () => proofMerklePath
|
|
5048
|
+
});
|
|
5049
|
+
var MerkleTree = class {
|
|
5050
|
+
constructor(leafHashes) {
|
|
5051
|
+
this.branches = [];
|
|
5052
|
+
this.leaves = leafHashes;
|
|
5053
|
+
this.root = this.build(leafHashes);
|
|
5088
5054
|
}
|
|
5089
|
-
|
|
5090
|
-
if (
|
|
5091
|
-
|
|
5092
|
-
this.deployTransactionHash = void 0;
|
|
5055
|
+
build(leaves) {
|
|
5056
|
+
if (leaves.length === 1) {
|
|
5057
|
+
return leaves[0];
|
|
5093
5058
|
}
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
async call(method, args = [], {
|
|
5097
|
-
parseRequest = true,
|
|
5098
|
-
parseResponse = true,
|
|
5099
|
-
formatResponse = void 0,
|
|
5100
|
-
blockIdentifier = void 0
|
|
5101
|
-
} = {}) {
|
|
5102
|
-
assert(this.address !== null, "contract is not connected to an address");
|
|
5103
|
-
const calldata = getCalldata(args, () => {
|
|
5104
|
-
if (parseRequest) {
|
|
5105
|
-
this.callData.validate("CALL", method, args);
|
|
5106
|
-
return this.callData.compile(method, args);
|
|
5107
|
-
}
|
|
5108
|
-
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
5109
|
-
return args;
|
|
5110
|
-
});
|
|
5111
|
-
return this.providerOrAccount.callContract(
|
|
5112
|
-
{
|
|
5113
|
-
contractAddress: this.address,
|
|
5114
|
-
calldata,
|
|
5115
|
-
entrypoint: method
|
|
5116
|
-
},
|
|
5117
|
-
blockIdentifier
|
|
5118
|
-
).then((x) => {
|
|
5119
|
-
if (!parseResponse) {
|
|
5120
|
-
return x.result;
|
|
5121
|
-
}
|
|
5122
|
-
if (formatResponse) {
|
|
5123
|
-
return this.callData.format(method, x.result, formatResponse);
|
|
5124
|
-
}
|
|
5125
|
-
return this.callData.parse(method, x.result);
|
|
5126
|
-
});
|
|
5127
|
-
}
|
|
5128
|
-
invoke(method, args = [], { parseRequest = true, maxFee, nonce, signature } = {}) {
|
|
5129
|
-
assert(this.address !== null, "contract is not connected to an address");
|
|
5130
|
-
const calldata = getCalldata(args, () => {
|
|
5131
|
-
if (parseRequest) {
|
|
5132
|
-
this.callData.validate("INVOKE", method, args);
|
|
5133
|
-
return this.callData.compile(method, args);
|
|
5134
|
-
}
|
|
5135
|
-
console.warn("Invoke skipped parsing but provided rawArgs, possible malfunction request");
|
|
5136
|
-
return args;
|
|
5137
|
-
});
|
|
5138
|
-
const invocation = {
|
|
5139
|
-
contractAddress: this.address,
|
|
5140
|
-
calldata,
|
|
5141
|
-
entrypoint: method
|
|
5142
|
-
};
|
|
5143
|
-
if ("execute" in this.providerOrAccount) {
|
|
5144
|
-
return this.providerOrAccount.execute(invocation, void 0, {
|
|
5145
|
-
maxFee,
|
|
5146
|
-
nonce
|
|
5147
|
-
});
|
|
5059
|
+
if (leaves.length !== this.leaves.length) {
|
|
5060
|
+
this.branches.push(leaves);
|
|
5148
5061
|
}
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
{
|
|
5154
|
-
|
|
5155
|
-
signature
|
|
5156
|
-
},
|
|
5157
|
-
{
|
|
5158
|
-
nonce
|
|
5062
|
+
const newLeaves = [];
|
|
5063
|
+
for (let i = 0; i < leaves.length; i += 2) {
|
|
5064
|
+
if (i + 1 === leaves.length) {
|
|
5065
|
+
newLeaves.push(MerkleTree.hash(leaves[i], "0x0"));
|
|
5066
|
+
} else {
|
|
5067
|
+
newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
|
|
5159
5068
|
}
|
|
5160
|
-
|
|
5069
|
+
}
|
|
5070
|
+
return this.build(newLeaves);
|
|
5161
5071
|
}
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5072
|
+
static hash(a, b) {
|
|
5073
|
+
const [aSorted, bSorted] = [toBigInt(a), toBigInt(b)].sort((x, y) => x >= y ? 1 : -1);
|
|
5074
|
+
return starkCurve.pedersen(aSorted, bSorted);
|
|
5075
|
+
}
|
|
5076
|
+
getProof(leaf, branch = this.leaves, hashPath = []) {
|
|
5077
|
+
const index = branch.indexOf(leaf);
|
|
5078
|
+
if (index === -1) {
|
|
5079
|
+
throw new Error("leaf not found");
|
|
5166
5080
|
}
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
5081
|
+
if (branch.length === 1) {
|
|
5082
|
+
return hashPath;
|
|
5170
5083
|
}
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
const
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5084
|
+
const isLeft = index % 2 === 0;
|
|
5085
|
+
const neededBranch = (isLeft ? branch[index + 1] : branch[index - 1]) ?? "0x0";
|
|
5086
|
+
const newHashPath = [...hashPath, neededBranch];
|
|
5087
|
+
const currentBranchLevelIndex = this.leaves.length === branch.length ? -1 : this.branches.findIndex((b) => b.length === branch.length);
|
|
5088
|
+
const nextBranch = this.branches[currentBranchLevelIndex + 1] ?? [this.root];
|
|
5089
|
+
return this.getProof(
|
|
5090
|
+
MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
|
|
5091
|
+
nextBranch,
|
|
5092
|
+
newHashPath
|
|
5093
|
+
);
|
|
5180
5094
|
}
|
|
5181
5095
|
};
|
|
5096
|
+
function proofMerklePath(root, leaf, path) {
|
|
5097
|
+
if (path.length === 0) {
|
|
5098
|
+
return root === leaf;
|
|
5099
|
+
}
|
|
5100
|
+
const [next, ...rest] = path;
|
|
5101
|
+
return proofMerklePath(root, MerkleTree.hash(leaf, next), rest);
|
|
5102
|
+
}
|
|
5182
5103
|
|
|
5183
|
-
// src/
|
|
5184
|
-
|
|
5104
|
+
// src/utils/typedData.ts
|
|
5105
|
+
function getHex(value) {
|
|
5106
|
+
try {
|
|
5107
|
+
return toHex(value);
|
|
5108
|
+
} catch (e) {
|
|
5109
|
+
if (typeof value === "string") {
|
|
5110
|
+
return toHex(encodeShortString(value));
|
|
5111
|
+
}
|
|
5112
|
+
throw new Error(`Invalid BigNumberish: ${value}`);
|
|
5113
|
+
}
|
|
5114
|
+
}
|
|
5115
|
+
var validateTypedData = (data) => {
|
|
5116
|
+
const typedData = data;
|
|
5117
|
+
const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
|
|
5118
|
+
return valid;
|
|
5185
5119
|
};
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
}
|
|
5196
|
-
/**
|
|
5197
|
-
* Deploys contract and returns new instance of the Contract
|
|
5198
|
-
*
|
|
5199
|
-
* @param args - Array of the constructor arguments for deployment
|
|
5200
|
-
* @param options (optional) Object - parseRequest, parseResponse, addressSalt
|
|
5201
|
-
* @returns deployed Contract
|
|
5202
|
-
*/
|
|
5203
|
-
async deploy(...args) {
|
|
5204
|
-
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
5205
|
-
const constructorCalldata = getCalldata(param, () => {
|
|
5206
|
-
if (options.parseRequest) {
|
|
5207
|
-
this.CallData.validate("DEPLOY", "constructor", param);
|
|
5208
|
-
return this.CallData.compile("constructor", param);
|
|
5209
|
-
}
|
|
5210
|
-
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
5211
|
-
return param;
|
|
5212
|
-
});
|
|
5213
|
-
const {
|
|
5214
|
-
deploy: { contract_address, transaction_hash }
|
|
5215
|
-
} = await this.account.declareAndDeploy({
|
|
5216
|
-
contract: this.compiledContract,
|
|
5217
|
-
constructorCalldata,
|
|
5218
|
-
salt: options.addressSalt
|
|
5219
|
-
});
|
|
5220
|
-
assert(Boolean(contract_address), "Deployment of the contract failed");
|
|
5221
|
-
const contractInstance = new Contract(
|
|
5222
|
-
this.compiledContract.abi,
|
|
5223
|
-
contract_address,
|
|
5224
|
-
this.account
|
|
5225
|
-
);
|
|
5226
|
-
contractInstance.deployTransactionHash = transaction_hash;
|
|
5227
|
-
return contractInstance;
|
|
5228
|
-
}
|
|
5229
|
-
/**
|
|
5230
|
-
* Attaches to new Account
|
|
5231
|
-
*
|
|
5232
|
-
* @param account - new Provider or Account to attach to
|
|
5233
|
-
* @returns ContractFactory
|
|
5234
|
-
*/
|
|
5235
|
-
connect(account) {
|
|
5236
|
-
this.account = account;
|
|
5237
|
-
return this;
|
|
5238
|
-
}
|
|
5239
|
-
/**
|
|
5240
|
-
* Attaches current abi and account to the new address
|
|
5241
|
-
*
|
|
5242
|
-
* @param address - Contract address
|
|
5243
|
-
* @returns Contract
|
|
5244
|
-
*/
|
|
5245
|
-
attach(address) {
|
|
5246
|
-
return new Contract(this.abi, address, this.account);
|
|
5247
|
-
}
|
|
5248
|
-
// ethers.js' getDeployTransaction cant be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
|
|
5249
|
-
};
|
|
5250
|
-
|
|
5251
|
-
// src/signer/interface.ts
|
|
5252
|
-
var SignerInterface = class {
|
|
5253
|
-
};
|
|
5254
|
-
|
|
5255
|
-
// src/utils/transaction.ts
|
|
5256
|
-
var transaction_exports = {};
|
|
5257
|
-
__export(transaction_exports, {
|
|
5258
|
-
fromCallsToExecuteCalldata: () => fromCallsToExecuteCalldata,
|
|
5259
|
-
fromCallsToExecuteCalldataWithNonce: () => fromCallsToExecuteCalldataWithNonce,
|
|
5260
|
-
fromCallsToExecuteCalldata_cairo1: () => fromCallsToExecuteCalldata_cairo1,
|
|
5261
|
-
getExecuteCalldata: () => getExecuteCalldata,
|
|
5262
|
-
transformCallsToMulticallArrays: () => transformCallsToMulticallArrays,
|
|
5263
|
-
transformCallsToMulticallArrays_cairo1: () => transformCallsToMulticallArrays_cairo1
|
|
5264
|
-
});
|
|
5265
|
-
var transformCallsToMulticallArrays = (calls) => {
|
|
5266
|
-
const callArray = [];
|
|
5267
|
-
const calldata = [];
|
|
5268
|
-
calls.forEach((call) => {
|
|
5269
|
-
const data = CallData.compile(call.calldata || []);
|
|
5270
|
-
callArray.push({
|
|
5271
|
-
to: toBigInt(call.contractAddress).toString(10),
|
|
5272
|
-
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
5273
|
-
data_offset: calldata.length.toString(),
|
|
5274
|
-
data_len: data.length.toString()
|
|
5275
|
-
});
|
|
5276
|
-
calldata.push(...data);
|
|
5277
|
-
});
|
|
5278
|
-
return {
|
|
5279
|
-
callArray,
|
|
5280
|
-
calldata: CallData.compile({ calldata })
|
|
5281
|
-
};
|
|
5282
|
-
};
|
|
5283
|
-
var fromCallsToExecuteCalldata = (calls) => {
|
|
5284
|
-
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
5285
|
-
const compiledCalls = CallData.compile({ callArray });
|
|
5286
|
-
return [...compiledCalls, ...calldata];
|
|
5287
|
-
};
|
|
5288
|
-
var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
|
|
5289
|
-
return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
|
|
5290
|
-
};
|
|
5291
|
-
var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
5292
|
-
const callArray = calls.map((call) => ({
|
|
5293
|
-
to: toBigInt(call.contractAddress).toString(10),
|
|
5294
|
-
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
5295
|
-
calldata: CallData.compile(call.calldata || [])
|
|
5296
|
-
}));
|
|
5297
|
-
return callArray;
|
|
5298
|
-
};
|
|
5299
|
-
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
5300
|
-
const orderCalls = calls.map((call) => ({
|
|
5301
|
-
contractAddress: call.contractAddress,
|
|
5302
|
-
entrypoint: call.entrypoint,
|
|
5303
|
-
calldata: call.calldata
|
|
5304
|
-
}));
|
|
5305
|
-
return CallData.compile({ orderCalls });
|
|
5306
|
-
};
|
|
5307
|
-
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
5308
|
-
if (cairoVersion === "1") {
|
|
5309
|
-
return fromCallsToExecuteCalldata_cairo1(calls);
|
|
5310
|
-
}
|
|
5311
|
-
return fromCallsToExecuteCalldata(calls);
|
|
5312
|
-
};
|
|
5313
|
-
|
|
5314
|
-
// src/utils/typedData/index.ts
|
|
5315
|
-
var typedData_exports = {};
|
|
5316
|
-
__export(typedData_exports, {
|
|
5317
|
-
encodeData: () => encodeData,
|
|
5318
|
-
encodeType: () => encodeType,
|
|
5319
|
-
encodeValue: () => encodeValue,
|
|
5320
|
-
getDependencies: () => getDependencies,
|
|
5321
|
-
getMessageHash: () => getMessageHash,
|
|
5322
|
-
getStructHash: () => getStructHash,
|
|
5323
|
-
getTypeHash: () => getTypeHash,
|
|
5324
|
-
isMerkleTreeType: () => isMerkleTreeType,
|
|
5325
|
-
prepareSelector: () => prepareSelector
|
|
5326
|
-
});
|
|
5327
|
-
|
|
5328
|
-
// src/utils/merkle.ts
|
|
5329
|
-
var merkle_exports = {};
|
|
5330
|
-
__export(merkle_exports, {
|
|
5331
|
-
MerkleTree: () => MerkleTree,
|
|
5332
|
-
proofMerklePath: () => proofMerklePath
|
|
5333
|
-
});
|
|
5334
|
-
var MerkleTree = class {
|
|
5335
|
-
constructor(leafHashes) {
|
|
5336
|
-
this.branches = [];
|
|
5337
|
-
this.leaves = leafHashes;
|
|
5338
|
-
this.root = this.build(leafHashes);
|
|
5339
|
-
}
|
|
5340
|
-
build(leaves) {
|
|
5341
|
-
if (leaves.length === 1) {
|
|
5342
|
-
return leaves[0];
|
|
5343
|
-
}
|
|
5344
|
-
if (leaves.length !== this.leaves.length) {
|
|
5345
|
-
this.branches.push(leaves);
|
|
5346
|
-
}
|
|
5347
|
-
const newLeaves = [];
|
|
5348
|
-
for (let i = 0; i < leaves.length; i += 2) {
|
|
5349
|
-
if (i + 1 === leaves.length) {
|
|
5350
|
-
newLeaves.push(MerkleTree.hash(leaves[i], "0x0"));
|
|
5351
|
-
} else {
|
|
5352
|
-
newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
|
|
5353
|
-
}
|
|
5354
|
-
}
|
|
5355
|
-
return this.build(newLeaves);
|
|
5356
|
-
}
|
|
5357
|
-
static hash(a, b) {
|
|
5358
|
-
const [aSorted, bSorted] = [toBigInt(a), toBigInt(b)].sort((x, y) => x >= y ? 1 : -1);
|
|
5359
|
-
return starkCurve.pedersen(aSorted, bSorted);
|
|
5360
|
-
}
|
|
5361
|
-
getProof(leaf, branch = this.leaves, hashPath = []) {
|
|
5362
|
-
const index = branch.indexOf(leaf);
|
|
5363
|
-
if (index === -1) {
|
|
5364
|
-
throw new Error("leaf not found");
|
|
5365
|
-
}
|
|
5366
|
-
if (branch.length === 1) {
|
|
5367
|
-
return hashPath;
|
|
5368
|
-
}
|
|
5369
|
-
const isLeft = index % 2 === 0;
|
|
5370
|
-
const neededBranch = (isLeft ? branch[index + 1] : branch[index - 1]) ?? "0x0";
|
|
5371
|
-
const newHashPath = [...hashPath, neededBranch];
|
|
5372
|
-
const currentBranchLevelIndex = this.leaves.length === branch.length ? -1 : this.branches.findIndex((b) => b.length === branch.length);
|
|
5373
|
-
const nextBranch = this.branches[currentBranchLevelIndex + 1] ?? [this.root];
|
|
5374
|
-
return this.getProof(
|
|
5375
|
-
MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
|
|
5376
|
-
nextBranch,
|
|
5377
|
-
newHashPath
|
|
5378
|
-
);
|
|
5379
|
-
}
|
|
5380
|
-
};
|
|
5381
|
-
function proofMerklePath(root, leaf, path) {
|
|
5382
|
-
if (path.length === 0) {
|
|
5383
|
-
return root === leaf;
|
|
5384
|
-
}
|
|
5385
|
-
const [next, ...rest] = path;
|
|
5386
|
-
return proofMerklePath(root, MerkleTree.hash(leaf, next), rest);
|
|
5387
|
-
}
|
|
5388
|
-
|
|
5389
|
-
// src/utils/typedData/utils.ts
|
|
5390
|
-
var validateTypedData = (data) => {
|
|
5391
|
-
const typedData = data;
|
|
5392
|
-
const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
|
|
5393
|
-
return valid;
|
|
5394
|
-
};
|
|
5395
|
-
|
|
5396
|
-
// src/utils/typedData/index.ts
|
|
5397
|
-
function getHex(value) {
|
|
5398
|
-
try {
|
|
5399
|
-
return toHex(value);
|
|
5400
|
-
} catch (e) {
|
|
5401
|
-
if (typeof value === "string") {
|
|
5402
|
-
return toHex(encodeShortString(value));
|
|
5403
|
-
}
|
|
5404
|
-
throw new Error(`Invalid BigNumberish: ${value}`);
|
|
5405
|
-
}
|
|
5406
|
-
}
|
|
5407
|
-
function prepareSelector(selector) {
|
|
5408
|
-
return isHex(selector) ? selector : getSelectorFromName(selector);
|
|
5409
|
-
}
|
|
5410
|
-
function isMerkleTreeType(type) {
|
|
5411
|
-
return type.type === "merkletree";
|
|
5412
|
-
}
|
|
5413
|
-
var getDependencies = (types, type, dependencies = []) => {
|
|
5414
|
-
if (type[type.length - 1] === "*") {
|
|
5415
|
-
type = type.slice(0, -1);
|
|
5120
|
+
function prepareSelector(selector) {
|
|
5121
|
+
return isHex(selector) ? selector : getSelectorFromName(selector);
|
|
5122
|
+
}
|
|
5123
|
+
function isMerkleTreeType(type) {
|
|
5124
|
+
return type.type === "merkletree";
|
|
5125
|
+
}
|
|
5126
|
+
var getDependencies = (types, type, dependencies = []) => {
|
|
5127
|
+
if (type[type.length - 1] === "*") {
|
|
5128
|
+
type = type.slice(0, -1);
|
|
5416
5129
|
}
|
|
5417
5130
|
if (dependencies.includes(type)) {
|
|
5418
5131
|
return dependencies;
|
|
@@ -5937,187 +5650,479 @@ var Account = class extends Provider {
|
|
|
5937
5650
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5938
5651
|
const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
5939
5652
|
{
|
|
5940
|
-
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
5941
|
-
payload: {
|
|
5942
|
-
classHash,
|
|
5943
|
-
constructorCalldata: compiledCalldata,
|
|
5944
|
-
addressSalt,
|
|
5945
|
-
contractAddress
|
|
5946
|
-
}
|
|
5653
|
+
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
5654
|
+
payload: {
|
|
5655
|
+
classHash,
|
|
5656
|
+
constructorCalldata: compiledCalldata,
|
|
5657
|
+
addressSalt,
|
|
5658
|
+
contractAddress
|
|
5659
|
+
}
|
|
5660
|
+
},
|
|
5661
|
+
transactionsDetail
|
|
5662
|
+
);
|
|
5663
|
+
const signature = await this.signer.signDeployAccountTransaction({
|
|
5664
|
+
classHash,
|
|
5665
|
+
constructorCalldata: compiledCalldata,
|
|
5666
|
+
contractAddress,
|
|
5667
|
+
addressSalt,
|
|
5668
|
+
chainId,
|
|
5669
|
+
maxFee,
|
|
5670
|
+
version,
|
|
5671
|
+
nonce
|
|
5672
|
+
});
|
|
5673
|
+
return this.deployAccountContract(
|
|
5674
|
+
{ classHash, addressSalt, constructorCalldata, signature },
|
|
5675
|
+
{
|
|
5676
|
+
nonce,
|
|
5677
|
+
maxFee,
|
|
5678
|
+
version
|
|
5679
|
+
}
|
|
5680
|
+
);
|
|
5681
|
+
}
|
|
5682
|
+
async signMessage(typedData) {
|
|
5683
|
+
return this.signer.signMessage(typedData, this.address);
|
|
5684
|
+
}
|
|
5685
|
+
async hashMessage(typedData) {
|
|
5686
|
+
return getMessageHash(typedData, this.address);
|
|
5687
|
+
}
|
|
5688
|
+
async verifyMessageHash(hash, signature) {
|
|
5689
|
+
try {
|
|
5690
|
+
await this.callContract({
|
|
5691
|
+
contractAddress: this.address,
|
|
5692
|
+
entrypoint: "isValidSignature",
|
|
5693
|
+
calldata: CallData.compile({
|
|
5694
|
+
hash: toBigInt(hash).toString(),
|
|
5695
|
+
signature: formatSignature(signature)
|
|
5696
|
+
})
|
|
5697
|
+
});
|
|
5698
|
+
return true;
|
|
5699
|
+
} catch {
|
|
5700
|
+
return false;
|
|
5701
|
+
}
|
|
5702
|
+
}
|
|
5703
|
+
async verifyMessage(typedData, signature) {
|
|
5704
|
+
const hash = await this.hashMessage(typedData);
|
|
5705
|
+
return this.verifyMessageHash(hash, signature);
|
|
5706
|
+
}
|
|
5707
|
+
async getSuggestedMaxFee({ type, payload }, details) {
|
|
5708
|
+
let feeEstimate;
|
|
5709
|
+
switch (type) {
|
|
5710
|
+
case "INVOKE_FUNCTION" /* INVOKE */:
|
|
5711
|
+
feeEstimate = await this.estimateInvokeFee(payload, details);
|
|
5712
|
+
break;
|
|
5713
|
+
case "DECLARE" /* DECLARE */:
|
|
5714
|
+
feeEstimate = await this.estimateDeclareFee(payload, details);
|
|
5715
|
+
break;
|
|
5716
|
+
case "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */:
|
|
5717
|
+
feeEstimate = await this.estimateAccountDeployFee(payload, details);
|
|
5718
|
+
break;
|
|
5719
|
+
case "DEPLOY" /* DEPLOY */:
|
|
5720
|
+
feeEstimate = await this.estimateDeployFee(payload, details);
|
|
5721
|
+
break;
|
|
5722
|
+
default:
|
|
5723
|
+
feeEstimate = { suggestedMaxFee: ZERO, overall_fee: ZERO };
|
|
5724
|
+
break;
|
|
5725
|
+
}
|
|
5726
|
+
return feeEstimate.suggestedMaxFee;
|
|
5727
|
+
}
|
|
5728
|
+
/**
|
|
5729
|
+
* will be renamed to buildDeclareContractTransaction
|
|
5730
|
+
*/
|
|
5731
|
+
async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
|
|
5732
|
+
const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
|
|
5733
|
+
const contractDefinition = parseContract(contract);
|
|
5734
|
+
const signature = await this.signer.signDeclareTransaction({
|
|
5735
|
+
classHash,
|
|
5736
|
+
compiledClassHash,
|
|
5737
|
+
senderAddress: walletAddress,
|
|
5738
|
+
chainId,
|
|
5739
|
+
maxFee,
|
|
5740
|
+
version,
|
|
5741
|
+
nonce
|
|
5742
|
+
});
|
|
5743
|
+
return {
|
|
5744
|
+
senderAddress: walletAddress,
|
|
5745
|
+
signature,
|
|
5746
|
+
contractDefinition,
|
|
5747
|
+
compiledClassHash
|
|
5748
|
+
};
|
|
5749
|
+
}
|
|
5750
|
+
async buildAccountDeployPayload({
|
|
5751
|
+
classHash,
|
|
5752
|
+
addressSalt = 0,
|
|
5753
|
+
constructorCalldata = [],
|
|
5754
|
+
contractAddress: providedContractAddress
|
|
5755
|
+
}, { nonce, chainId, version, maxFee }) {
|
|
5756
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5757
|
+
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5758
|
+
const signature = await this.signer.signDeployAccountTransaction({
|
|
5759
|
+
classHash,
|
|
5760
|
+
contractAddress,
|
|
5761
|
+
chainId,
|
|
5762
|
+
maxFee,
|
|
5763
|
+
version,
|
|
5764
|
+
nonce,
|
|
5765
|
+
addressSalt,
|
|
5766
|
+
constructorCalldata: compiledCalldata
|
|
5767
|
+
});
|
|
5768
|
+
return {
|
|
5769
|
+
classHash,
|
|
5770
|
+
addressSalt,
|
|
5771
|
+
constructorCalldata: compiledCalldata,
|
|
5772
|
+
signature
|
|
5773
|
+
};
|
|
5774
|
+
}
|
|
5775
|
+
buildUDCContractPayload(payload) {
|
|
5776
|
+
const calls = [].concat(payload).map((it) => {
|
|
5777
|
+
const {
|
|
5778
|
+
classHash,
|
|
5779
|
+
salt = "0",
|
|
5780
|
+
unique = true,
|
|
5781
|
+
constructorCalldata = []
|
|
5782
|
+
} = it;
|
|
5783
|
+
const compiledConstructorCallData = CallData.compile(constructorCalldata);
|
|
5784
|
+
return {
|
|
5785
|
+
contractAddress: UDC.ADDRESS,
|
|
5786
|
+
entrypoint: UDC.ENTRYPOINT,
|
|
5787
|
+
calldata: [
|
|
5788
|
+
classHash,
|
|
5789
|
+
salt,
|
|
5790
|
+
toCairoBool(unique),
|
|
5791
|
+
compiledConstructorCallData.length,
|
|
5792
|
+
...compiledConstructorCallData
|
|
5793
|
+
]
|
|
5794
|
+
};
|
|
5795
|
+
});
|
|
5796
|
+
return calls;
|
|
5797
|
+
}
|
|
5798
|
+
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
|
|
5799
|
+
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
5800
|
+
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5801
|
+
const version = toBigInt(feeTransactionVersion);
|
|
5802
|
+
const chainId = await this.getChainId();
|
|
5803
|
+
const signerDetails = {
|
|
5804
|
+
walletAddress: this.address,
|
|
5805
|
+
nonce,
|
|
5806
|
+
maxFee: ZERO,
|
|
5807
|
+
version,
|
|
5808
|
+
chainId,
|
|
5809
|
+
cairoVersion: this.cairoVersion
|
|
5810
|
+
};
|
|
5811
|
+
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
5812
|
+
const response = await super.getSimulateTransaction(
|
|
5813
|
+
invocation,
|
|
5814
|
+
{ version, nonce },
|
|
5815
|
+
blockIdentifier,
|
|
5816
|
+
skipValidate
|
|
5817
|
+
);
|
|
5818
|
+
const suggestedMaxFee = estimatedFeeToMaxFee(response.fee_estimation.overall_fee);
|
|
5819
|
+
return {
|
|
5820
|
+
...response,
|
|
5821
|
+
fee_estimation: {
|
|
5822
|
+
...response.fee_estimation,
|
|
5823
|
+
suggestedMaxFee
|
|
5824
|
+
}
|
|
5825
|
+
};
|
|
5826
|
+
}
|
|
5827
|
+
async getStarkName(address = this.address, StarknetIdContract2) {
|
|
5828
|
+
return super.getStarkName(address, StarknetIdContract2);
|
|
5829
|
+
}
|
|
5830
|
+
};
|
|
5831
|
+
|
|
5832
|
+
// src/provider/interface.ts
|
|
5833
|
+
var ProviderInterface = class {
|
|
5834
|
+
};
|
|
5835
|
+
|
|
5836
|
+
// src/provider/index.ts
|
|
5837
|
+
var defaultProvider = new Provider();
|
|
5838
|
+
|
|
5839
|
+
// src/account/interface.ts
|
|
5840
|
+
var AccountInterface = class extends ProviderInterface {
|
|
5841
|
+
};
|
|
5842
|
+
|
|
5843
|
+
// src/contract/default.ts
|
|
5844
|
+
var splitArgsAndOptions = (args) => {
|
|
5845
|
+
const options = [
|
|
5846
|
+
"blockIdentifier",
|
|
5847
|
+
"parseRequest",
|
|
5848
|
+
"parseResponse",
|
|
5849
|
+
"formatResponse",
|
|
5850
|
+
"maxFee",
|
|
5851
|
+
"nonce",
|
|
5852
|
+
"signature",
|
|
5853
|
+
"addressSalt"
|
|
5854
|
+
];
|
|
5855
|
+
const lastArg = args[args.length - 1];
|
|
5856
|
+
if (typeof lastArg === "object" && options.some((x) => x in lastArg)) {
|
|
5857
|
+
return { args, options: args.pop() };
|
|
5858
|
+
}
|
|
5859
|
+
return { args };
|
|
5860
|
+
};
|
|
5861
|
+
function buildCall(contract, functionAbi) {
|
|
5862
|
+
return async function(...args) {
|
|
5863
|
+
const params = splitArgsAndOptions(args);
|
|
5864
|
+
return contract.call(functionAbi.name, params.args, {
|
|
5865
|
+
parseRequest: true,
|
|
5866
|
+
parseResponse: true,
|
|
5867
|
+
...params.options
|
|
5868
|
+
});
|
|
5869
|
+
};
|
|
5870
|
+
}
|
|
5871
|
+
function buildInvoke(contract, functionAbi) {
|
|
5872
|
+
return async function(...args) {
|
|
5873
|
+
const params = splitArgsAndOptions(args);
|
|
5874
|
+
return contract.invoke(functionAbi.name, params.args, {
|
|
5875
|
+
parseRequest: true,
|
|
5876
|
+
...params.options
|
|
5877
|
+
});
|
|
5878
|
+
};
|
|
5879
|
+
}
|
|
5880
|
+
function buildDefault(contract, functionAbi) {
|
|
5881
|
+
if (functionAbi.stateMutability === "view" || functionAbi.state_mutability === "view") {
|
|
5882
|
+
return buildCall(contract, functionAbi);
|
|
5883
|
+
}
|
|
5884
|
+
return buildInvoke(contract, functionAbi);
|
|
5885
|
+
}
|
|
5886
|
+
function buildPopulate(contract, functionAbi) {
|
|
5887
|
+
return function(...args) {
|
|
5888
|
+
return contract.populate(functionAbi.name, args);
|
|
5889
|
+
};
|
|
5890
|
+
}
|
|
5891
|
+
function buildEstimate(contract, functionAbi) {
|
|
5892
|
+
return function(...args) {
|
|
5893
|
+
return contract.estimate(functionAbi.name, args);
|
|
5894
|
+
};
|
|
5895
|
+
}
|
|
5896
|
+
function getCalldata(args, callback) {
|
|
5897
|
+
if (Array.isArray(args) && "__compiled__" in args)
|
|
5898
|
+
return args;
|
|
5899
|
+
if (Array.isArray(args) && Array.isArray(args[0]) && "__compiled__" in args[0])
|
|
5900
|
+
return args[0];
|
|
5901
|
+
return callback();
|
|
5902
|
+
}
|
|
5903
|
+
var Contract = class {
|
|
5904
|
+
/**
|
|
5905
|
+
* Contract class to handle contract methods
|
|
5906
|
+
*
|
|
5907
|
+
* @param abi - Abi of the contract object
|
|
5908
|
+
* @param address (optional) - address to connect to
|
|
5909
|
+
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
5910
|
+
*/
|
|
5911
|
+
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
5912
|
+
this.address = address && address.toLowerCase();
|
|
5913
|
+
this.providerOrAccount = providerOrAccount;
|
|
5914
|
+
this.callData = new CallData(abi);
|
|
5915
|
+
this.structs = CallData.getAbiStruct(abi);
|
|
5916
|
+
this.abi = abi;
|
|
5917
|
+
const options = { enumerable: true, value: {}, writable: false };
|
|
5918
|
+
Object.defineProperties(this, {
|
|
5919
|
+
functions: { enumerable: true, value: {}, writable: false },
|
|
5920
|
+
callStatic: { enumerable: true, value: {}, writable: false },
|
|
5921
|
+
populateTransaction: { enumerable: true, value: {}, writable: false },
|
|
5922
|
+
estimateFee: { enumerable: true, value: {}, writable: false }
|
|
5923
|
+
});
|
|
5924
|
+
this.abi.forEach((abiElement) => {
|
|
5925
|
+
if (abiElement.type !== "function")
|
|
5926
|
+
return;
|
|
5927
|
+
const signature = abiElement.name;
|
|
5928
|
+
if (!this[signature]) {
|
|
5929
|
+
Object.defineProperty(this, signature, {
|
|
5930
|
+
...options,
|
|
5931
|
+
value: buildDefault(this, abiElement)
|
|
5932
|
+
});
|
|
5933
|
+
}
|
|
5934
|
+
if (!this.functions[signature]) {
|
|
5935
|
+
Object.defineProperty(this.functions, signature, {
|
|
5936
|
+
...options,
|
|
5937
|
+
value: buildDefault(this, abiElement)
|
|
5938
|
+
});
|
|
5939
|
+
}
|
|
5940
|
+
if (!this.callStatic[signature]) {
|
|
5941
|
+
Object.defineProperty(this.callStatic, signature, {
|
|
5942
|
+
...options,
|
|
5943
|
+
value: buildCall(this, abiElement)
|
|
5944
|
+
});
|
|
5945
|
+
}
|
|
5946
|
+
if (!this.populateTransaction[signature]) {
|
|
5947
|
+
Object.defineProperty(this.populateTransaction, signature, {
|
|
5948
|
+
...options,
|
|
5949
|
+
value: buildPopulate(this, abiElement)
|
|
5950
|
+
});
|
|
5951
|
+
}
|
|
5952
|
+
if (!this.estimateFee[signature]) {
|
|
5953
|
+
Object.defineProperty(this.estimateFee, signature, {
|
|
5954
|
+
...options,
|
|
5955
|
+
value: buildEstimate(this, abiElement)
|
|
5956
|
+
});
|
|
5957
|
+
}
|
|
5958
|
+
});
|
|
5959
|
+
}
|
|
5960
|
+
attach(address) {
|
|
5961
|
+
this.address = address;
|
|
5962
|
+
}
|
|
5963
|
+
connect(providerOrAccount) {
|
|
5964
|
+
this.providerOrAccount = providerOrAccount;
|
|
5965
|
+
}
|
|
5966
|
+
async deployed() {
|
|
5967
|
+
if (this.deployTransactionHash) {
|
|
5968
|
+
await this.providerOrAccount.waitForTransaction(this.deployTransactionHash);
|
|
5969
|
+
this.deployTransactionHash = void 0;
|
|
5970
|
+
}
|
|
5971
|
+
return this;
|
|
5972
|
+
}
|
|
5973
|
+
async call(method, args = [], {
|
|
5974
|
+
parseRequest = true,
|
|
5975
|
+
parseResponse = true,
|
|
5976
|
+
formatResponse = void 0,
|
|
5977
|
+
blockIdentifier = void 0
|
|
5978
|
+
} = {}) {
|
|
5979
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
5980
|
+
const calldata = getCalldata(args, () => {
|
|
5981
|
+
if (parseRequest) {
|
|
5982
|
+
this.callData.validate("CALL", method, args);
|
|
5983
|
+
return this.callData.compile(method, args);
|
|
5984
|
+
}
|
|
5985
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
5986
|
+
return args;
|
|
5987
|
+
});
|
|
5988
|
+
return this.providerOrAccount.callContract(
|
|
5989
|
+
{
|
|
5990
|
+
contractAddress: this.address,
|
|
5991
|
+
calldata,
|
|
5992
|
+
entrypoint: method
|
|
5993
|
+
},
|
|
5994
|
+
blockIdentifier
|
|
5995
|
+
).then((x) => {
|
|
5996
|
+
if (!parseResponse) {
|
|
5997
|
+
return x.result;
|
|
5998
|
+
}
|
|
5999
|
+
if (formatResponse) {
|
|
6000
|
+
return this.callData.format(method, x.result, formatResponse);
|
|
6001
|
+
}
|
|
6002
|
+
return this.callData.parse(method, x.result);
|
|
6003
|
+
});
|
|
6004
|
+
}
|
|
6005
|
+
invoke(method, args = [], { parseRequest = true, maxFee, nonce, signature } = {}) {
|
|
6006
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
6007
|
+
const calldata = getCalldata(args, () => {
|
|
6008
|
+
if (parseRequest) {
|
|
6009
|
+
this.callData.validate("INVOKE", method, args);
|
|
6010
|
+
return this.callData.compile(method, args);
|
|
6011
|
+
}
|
|
6012
|
+
console.warn("Invoke skipped parsing but provided rawArgs, possible malfunction request");
|
|
6013
|
+
return args;
|
|
6014
|
+
});
|
|
6015
|
+
const invocation = {
|
|
6016
|
+
contractAddress: this.address,
|
|
6017
|
+
calldata,
|
|
6018
|
+
entrypoint: method
|
|
6019
|
+
};
|
|
6020
|
+
if ("execute" in this.providerOrAccount) {
|
|
6021
|
+
return this.providerOrAccount.execute(invocation, void 0, {
|
|
6022
|
+
maxFee,
|
|
6023
|
+
nonce
|
|
6024
|
+
});
|
|
6025
|
+
}
|
|
6026
|
+
if (!nonce)
|
|
6027
|
+
throw new Error(`Nonce is required when invoking a function without an account`);
|
|
6028
|
+
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
6029
|
+
return this.providerOrAccount.invokeFunction(
|
|
6030
|
+
{
|
|
6031
|
+
...invocation,
|
|
6032
|
+
signature
|
|
5947
6033
|
},
|
|
5948
|
-
transactionsDetail
|
|
5949
|
-
);
|
|
5950
|
-
const signature = await this.signer.signDeployAccountTransaction({
|
|
5951
|
-
classHash,
|
|
5952
|
-
constructorCalldata: compiledCalldata,
|
|
5953
|
-
contractAddress,
|
|
5954
|
-
addressSalt,
|
|
5955
|
-
chainId,
|
|
5956
|
-
maxFee,
|
|
5957
|
-
version,
|
|
5958
|
-
nonce
|
|
5959
|
-
});
|
|
5960
|
-
return this.deployAccountContract(
|
|
5961
|
-
{ classHash, addressSalt, constructorCalldata, signature },
|
|
5962
6034
|
{
|
|
5963
|
-
nonce
|
|
5964
|
-
maxFee,
|
|
5965
|
-
version
|
|
6035
|
+
nonce
|
|
5966
6036
|
}
|
|
5967
6037
|
);
|
|
5968
6038
|
}
|
|
5969
|
-
async
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
return getMessageHash(typedData, this.address);
|
|
5974
|
-
}
|
|
5975
|
-
async verifyMessageHash(hash, signature) {
|
|
5976
|
-
try {
|
|
5977
|
-
await this.callContract({
|
|
5978
|
-
contractAddress: this.address,
|
|
5979
|
-
entrypoint: "isValidSignature",
|
|
5980
|
-
calldata: CallData.compile({
|
|
5981
|
-
hash: toBigInt(hash).toString(),
|
|
5982
|
-
signature: formatSignature(signature)
|
|
5983
|
-
})
|
|
5984
|
-
});
|
|
5985
|
-
return true;
|
|
5986
|
-
} catch {
|
|
5987
|
-
return false;
|
|
6039
|
+
async estimate(method, args = []) {
|
|
6040
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
6041
|
+
if (!getCalldata(args, () => false)) {
|
|
6042
|
+
this.callData.validate("INVOKE", method, args);
|
|
5988
6043
|
}
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
return this.verifyMessageHash(hash, signature);
|
|
5993
|
-
}
|
|
5994
|
-
async getSuggestedMaxFee({ type, payload }, details) {
|
|
5995
|
-
let feeEstimate;
|
|
5996
|
-
switch (type) {
|
|
5997
|
-
case "INVOKE_FUNCTION" /* INVOKE */:
|
|
5998
|
-
feeEstimate = await this.estimateInvokeFee(payload, details);
|
|
5999
|
-
break;
|
|
6000
|
-
case "DECLARE" /* DECLARE */:
|
|
6001
|
-
feeEstimate = await this.estimateDeclareFee(payload, details);
|
|
6002
|
-
break;
|
|
6003
|
-
case "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */:
|
|
6004
|
-
feeEstimate = await this.estimateAccountDeployFee(payload, details);
|
|
6005
|
-
break;
|
|
6006
|
-
case "DEPLOY" /* DEPLOY */:
|
|
6007
|
-
feeEstimate = await this.estimateDeployFee(payload, details);
|
|
6008
|
-
break;
|
|
6009
|
-
default:
|
|
6010
|
-
feeEstimate = { suggestedMaxFee: ZERO, overall_fee: ZERO };
|
|
6011
|
-
break;
|
|
6044
|
+
const invocation = this.populate(method, args);
|
|
6045
|
+
if ("estimateInvokeFee" in this.providerOrAccount) {
|
|
6046
|
+
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
6012
6047
|
}
|
|
6013
|
-
|
|
6048
|
+
throw Error("Contract must be connected to the account contract to estimate");
|
|
6014
6049
|
}
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
*/
|
|
6018
|
-
async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
|
|
6019
|
-
const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
|
|
6020
|
-
const contractDefinition = parseContract(contract);
|
|
6021
|
-
const signature = await this.signer.signDeclareTransaction({
|
|
6022
|
-
classHash,
|
|
6023
|
-
compiledClassHash,
|
|
6024
|
-
senderAddress: walletAddress,
|
|
6025
|
-
chainId,
|
|
6026
|
-
maxFee,
|
|
6027
|
-
version,
|
|
6028
|
-
nonce
|
|
6029
|
-
});
|
|
6050
|
+
populate(method, args = []) {
|
|
6051
|
+
const calldata = getCalldata(args, () => this.callData.compile(method, args));
|
|
6030
6052
|
return {
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
compiledClassHash
|
|
6053
|
+
contractAddress: this.address,
|
|
6054
|
+
entrypoint: method,
|
|
6055
|
+
calldata
|
|
6035
6056
|
};
|
|
6036
6057
|
}
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
nonce,
|
|
6052
|
-
addressSalt,
|
|
6053
|
-
constructorCalldata: compiledCalldata
|
|
6054
|
-
});
|
|
6055
|
-
return {
|
|
6056
|
-
classHash,
|
|
6057
|
-
addressSalt,
|
|
6058
|
-
constructorCalldata: compiledCalldata,
|
|
6059
|
-
signature
|
|
6060
|
-
};
|
|
6058
|
+
};
|
|
6059
|
+
|
|
6060
|
+
// src/contract/interface.ts
|
|
6061
|
+
var ContractInterface = class {
|
|
6062
|
+
};
|
|
6063
|
+
|
|
6064
|
+
// src/contract/contractFactory.ts
|
|
6065
|
+
var ContractFactory = class {
|
|
6066
|
+
constructor(compiledContract, classHash, account, abi = compiledContract.abi) {
|
|
6067
|
+
this.abi = abi;
|
|
6068
|
+
this.compiledContract = compiledContract;
|
|
6069
|
+
this.account = account;
|
|
6070
|
+
this.classHash = classHash;
|
|
6071
|
+
this.CallData = new CallData(abi);
|
|
6061
6072
|
}
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
compiledConstructorCallData.length,
|
|
6079
|
-
...compiledConstructorCallData
|
|
6080
|
-
]
|
|
6081
|
-
};
|
|
6073
|
+
/**
|
|
6074
|
+
* Deploys contract and returns new instance of the Contract
|
|
6075
|
+
*
|
|
6076
|
+
* @param args - Array of the constructor arguments for deployment
|
|
6077
|
+
* @param options (optional) Object - parseRequest, parseResponse, addressSalt
|
|
6078
|
+
* @returns deployed Contract
|
|
6079
|
+
*/
|
|
6080
|
+
async deploy(...args) {
|
|
6081
|
+
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
6082
|
+
const constructorCalldata = getCalldata(param, () => {
|
|
6083
|
+
if (options.parseRequest) {
|
|
6084
|
+
this.CallData.validate("DEPLOY", "constructor", param);
|
|
6085
|
+
return this.CallData.compile("constructor", param);
|
|
6086
|
+
}
|
|
6087
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
6088
|
+
return param;
|
|
6082
6089
|
});
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
chainId,
|
|
6096
|
-
cairoVersion: this.cairoVersion
|
|
6097
|
-
};
|
|
6098
|
-
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
6099
|
-
const response = await super.getSimulateTransaction(
|
|
6100
|
-
invocation,
|
|
6101
|
-
{ version, nonce },
|
|
6102
|
-
blockIdentifier,
|
|
6103
|
-
skipValidate
|
|
6090
|
+
const {
|
|
6091
|
+
deploy: { contract_address, transaction_hash }
|
|
6092
|
+
} = await this.account.declareAndDeploy({
|
|
6093
|
+
contract: this.compiledContract,
|
|
6094
|
+
constructorCalldata,
|
|
6095
|
+
salt: options.addressSalt
|
|
6096
|
+
});
|
|
6097
|
+
assert(Boolean(contract_address), "Deployment of the contract failed");
|
|
6098
|
+
const contractInstance = new Contract(
|
|
6099
|
+
this.compiledContract.abi,
|
|
6100
|
+
contract_address,
|
|
6101
|
+
this.account
|
|
6104
6102
|
);
|
|
6105
|
-
|
|
6106
|
-
return
|
|
6107
|
-
...response,
|
|
6108
|
-
fee_estimation: {
|
|
6109
|
-
...response.fee_estimation,
|
|
6110
|
-
suggestedMaxFee
|
|
6111
|
-
}
|
|
6112
|
-
};
|
|
6103
|
+
contractInstance.deployTransactionHash = transaction_hash;
|
|
6104
|
+
return contractInstance;
|
|
6113
6105
|
}
|
|
6114
|
-
|
|
6115
|
-
|
|
6106
|
+
/**
|
|
6107
|
+
* Attaches to new Account
|
|
6108
|
+
*
|
|
6109
|
+
* @param account - new Provider or Account to attach to
|
|
6110
|
+
* @returns ContractFactory
|
|
6111
|
+
*/
|
|
6112
|
+
connect(account) {
|
|
6113
|
+
this.account = account;
|
|
6114
|
+
return this;
|
|
6116
6115
|
}
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6116
|
+
/**
|
|
6117
|
+
* Attaches current abi and account to the new address
|
|
6118
|
+
*
|
|
6119
|
+
* @param address - Contract address
|
|
6120
|
+
* @returns Contract
|
|
6121
|
+
*/
|
|
6122
|
+
attach(address) {
|
|
6123
|
+
return new Contract(this.abi, address, this.account);
|
|
6124
|
+
}
|
|
6125
|
+
// ethers.js' getDeployTransaction cant be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
|
|
6121
6126
|
};
|
|
6122
6127
|
|
|
6123
6128
|
// src/utils/address.ts
|
|
@@ -6197,6 +6202,7 @@ export {
|
|
|
6197
6202
|
starknetId_exports as starknetId,
|
|
6198
6203
|
transaction_exports as transaction,
|
|
6199
6204
|
typedData_exports as typedData,
|
|
6205
|
+
types_exports as types,
|
|
6200
6206
|
uint256_exports as uint256,
|
|
6201
6207
|
validateAndParseAddress,
|
|
6202
6208
|
validateChecksumAddress
|