starknet 11.1.0 → 11.3.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 +16 -0
- package/dist/index.d.ts +277 -49
- package/dist/index.global.js +308 -38
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +309 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +308 -38
- package/dist/index.mjs.map +1 -1
- package/dist/ledger/index.d.ts +116 -0
- package/dist/ledger/index.js +75 -0
- package/dist/ledger/index.js.map +1 -0
- package/dist/ledger/index.mjs +32 -0
- package/dist/ledger/index.mjs.map +1 -0
- package/package.json +23 -2
package/dist/index.js
CHANGED
|
@@ -62,6 +62,7 @@ __export(index_exports, {
|
|
|
62
62
|
CairoResult: () => CairoResult,
|
|
63
63
|
CairoResultVariant: () => CairoResultVariant,
|
|
64
64
|
CairoSecp256k1Point: () => CairoSecp256k1Point,
|
|
65
|
+
CairoStorageAddress: () => CairoStorageAddress,
|
|
65
66
|
CairoStruct: () => CairoStruct,
|
|
66
67
|
CairoTuple: () => CairoTuple,
|
|
67
68
|
CairoTypeCustomEnum: () => CairoTypeCustomEnum,
|
|
@@ -108,7 +109,7 @@ __export(index_exports, {
|
|
|
108
109
|
PaymasterInterface: () => PaymasterInterface,
|
|
109
110
|
PaymasterRpc: () => PaymasterRpc,
|
|
110
111
|
PluginManager: () => PluginManager,
|
|
111
|
-
Provider: () =>
|
|
112
|
+
Provider: () => Provider,
|
|
112
113
|
ProviderInterface: () => ProviderInterface,
|
|
113
114
|
RPC: () => api_exports,
|
|
114
115
|
RPC0102: () => v0_10_2_exports,
|
|
@@ -255,6 +256,7 @@ __export(constants_exports, {
|
|
|
255
256
|
RANGE_I32: () => RANGE_I32,
|
|
256
257
|
RANGE_I64: () => RANGE_I64,
|
|
257
258
|
RANGE_I8: () => RANGE_I8,
|
|
259
|
+
RANGE_STORAGE_ADDRESS: () => RANGE_STORAGE_ADDRESS,
|
|
258
260
|
RANGE_U128: () => RANGE_U128,
|
|
259
261
|
RANGE_U16: () => RANGE_U16,
|
|
260
262
|
RANGE_U32: () => RANGE_U32,
|
|
@@ -486,6 +488,7 @@ var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
|
486
488
|
var RANGE_ETH_ADDRESS = range(ZERO, 2n ** 160n - 1n);
|
|
487
489
|
var RANGE_CONTRACT_ADDRESS = range(ZERO, ADDR_BOUND - 1n);
|
|
488
490
|
var RANGE_CLASS_HASH = range(ZERO, 2n ** 251n - 1n);
|
|
491
|
+
var RANGE_STORAGE_ADDRESS = range(ZERO, 2n ** 251n - 1n);
|
|
489
492
|
var LegacyUDC = {
|
|
490
493
|
ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
|
|
491
494
|
ENTRYPOINT: "deployContract"
|
|
@@ -1167,6 +1170,7 @@ var Literal = {
|
|
|
1167
1170
|
ClassHash: "core::starknet::class_hash::ClassHash",
|
|
1168
1171
|
ContractAddress: "core::starknet::contract_address::ContractAddress",
|
|
1169
1172
|
Secp256k1Point: "core::starknet::secp256k1::Secp256k1Point",
|
|
1173
|
+
StorageAddress: "core::starknet::storage_access::StorageAddress",
|
|
1170
1174
|
U96: "core::internal::bounded_int::BoundedInt::<0, 79228162514264337593543950335>"
|
|
1171
1175
|
};
|
|
1172
1176
|
var ETH_ADDRESS = "core::starknet::eth_address::EthAddress";
|
|
@@ -1660,6 +1664,9 @@ function hashAbi(sierra) {
|
|
|
1660
1664
|
return BigInt(addHexPrefix(starkCurve.keccak(utf8ToUint8Array(indentString)).toString(16)));
|
|
1661
1665
|
}
|
|
1662
1666
|
function computeSierraContractClassHash(sierra) {
|
|
1667
|
+
if (sierra.abi === void 0 || sierra.abi === null) {
|
|
1668
|
+
throw Error('Invalid Sierra contract: the "abi" field is missing');
|
|
1669
|
+
}
|
|
1663
1670
|
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
1664
1671
|
const compiledClassVersion = utf8ToBigInt(CONTRACT_CLASS_VERSION);
|
|
1665
1672
|
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
@@ -8280,6 +8287,169 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
8280
8287
|
}
|
|
8281
8288
|
};
|
|
8282
8289
|
|
|
8290
|
+
// src/utils/cairoDataTypes/storageAddress.ts
|
|
8291
|
+
var CairoStorageAddress = class _CairoStorageAddress {
|
|
8292
|
+
/**
|
|
8293
|
+
* The address, always as a bigint.
|
|
8294
|
+
* @example
|
|
8295
|
+
* ```typescript
|
|
8296
|
+
* const result = new CairoStorageAddress('0x1234').data;
|
|
8297
|
+
* // result = 4660n
|
|
8298
|
+
* ```
|
|
8299
|
+
*/
|
|
8300
|
+
data;
|
|
8301
|
+
/**
|
|
8302
|
+
* The abi type this class serializes.
|
|
8303
|
+
* @example
|
|
8304
|
+
* ```typescript
|
|
8305
|
+
* const result = CairoStorageAddress.abiSelector;
|
|
8306
|
+
* // result = "core::starknet::storage_access::StorageAddress"
|
|
8307
|
+
* ```
|
|
8308
|
+
*/
|
|
8309
|
+
static abiSelector = Literal.StorageAddress;
|
|
8310
|
+
/**
|
|
8311
|
+
* Build from a number or a numeric string, refusing text and anything outside the
|
|
8312
|
+
* StorageAddress range.
|
|
8313
|
+
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^251 - 1]
|
|
8314
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the StorageAddress range
|
|
8315
|
+
* @example
|
|
8316
|
+
* ```typescript
|
|
8317
|
+
* const result = new CairoStorageAddress('0x1234').toApiRequest();
|
|
8318
|
+
* // result = ["4660"]
|
|
8319
|
+
* ```
|
|
8320
|
+
*/
|
|
8321
|
+
constructor(data) {
|
|
8322
|
+
_CairoStorageAddress.validate(data);
|
|
8323
|
+
this.data = new CairoFelt252(data).toBigInt();
|
|
8324
|
+
}
|
|
8325
|
+
/**
|
|
8326
|
+
* Serialize to the single felt a contract call carries.
|
|
8327
|
+
* @returns {string[]} one decimal-string felt, flagged as compiled
|
|
8328
|
+
* @example
|
|
8329
|
+
* ```typescript
|
|
8330
|
+
* const result = new CairoStorageAddress('0x1234').toApiRequest();
|
|
8331
|
+
* // result = ["4660"]
|
|
8332
|
+
* ```
|
|
8333
|
+
*/
|
|
8334
|
+
toApiRequest() {
|
|
8335
|
+
return addCompiledFlag([this.toBigInt().toString()]);
|
|
8336
|
+
}
|
|
8337
|
+
/**
|
|
8338
|
+
* The address as a number.
|
|
8339
|
+
* @returns {bigint} the number this address holds
|
|
8340
|
+
* @example
|
|
8341
|
+
* ```typescript
|
|
8342
|
+
* const result = new CairoStorageAddress('0x1234').toBigInt();
|
|
8343
|
+
* // result = 4660n
|
|
8344
|
+
* ```
|
|
8345
|
+
*/
|
|
8346
|
+
toBigInt() {
|
|
8347
|
+
return this.data;
|
|
8348
|
+
}
|
|
8349
|
+
/**
|
|
8350
|
+
* The address in hexadecimal, without padding.
|
|
8351
|
+
*
|
|
8352
|
+
* Leading zeros are dropped, as they are everywhere else in the library.
|
|
8353
|
+
* @returns {string} the address as a 0x-prefixed hex string
|
|
8354
|
+
* @example
|
|
8355
|
+
* ```typescript
|
|
8356
|
+
* const result = new CairoStorageAddress(4660).toHexString();
|
|
8357
|
+
* // result = "0x1234"
|
|
8358
|
+
* const result2 = new CairoStorageAddress('0x0034').toHexString();
|
|
8359
|
+
* // result2 = "0x34" (four digits in, two out)
|
|
8360
|
+
* ```
|
|
8361
|
+
*/
|
|
8362
|
+
toHexString() {
|
|
8363
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
8364
|
+
}
|
|
8365
|
+
/**
|
|
8366
|
+
* Throw unless the value can be carried by a StorageAddress.
|
|
8367
|
+
*
|
|
8368
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
8369
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
8370
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
8371
|
+
* the range of the Cairo `StorageAddress` type, [0, 2^251), which is narrower than the field.
|
|
8372
|
+
* @param {BigNumberish | boolean} data the value to check
|
|
8373
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the StorageAddress range
|
|
8374
|
+
* @example
|
|
8375
|
+
* ```typescript
|
|
8376
|
+
* CairoStorageAddress.validate('0x1234'); // passes
|
|
8377
|
+
* CairoStorageAddress.validate('abc');
|
|
8378
|
+
* // throws Error("Invalid input: a StorageAddress cannot be built from text")
|
|
8379
|
+
* CairoStorageAddress.validate(2n ** 251n);
|
|
8380
|
+
* // throws Error("Value is out of StorageAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
8381
|
+
* CairoStorageAddress.validate(-1);
|
|
8382
|
+
* // throws Error("Value is out of StorageAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
8383
|
+
* ```
|
|
8384
|
+
*/
|
|
8385
|
+
static validate(data) {
|
|
8386
|
+
assert(!isText(data), "Invalid input: a StorageAddress cannot be built from text");
|
|
8387
|
+
assert(
|
|
8388
|
+
!isNumber(data) || Number.isInteger(data),
|
|
8389
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
8390
|
+
);
|
|
8391
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
8392
|
+
assert(
|
|
8393
|
+
value >= RANGE_STORAGE_ADDRESS.min && value <= RANGE_STORAGE_ADDRESS.max,
|
|
8394
|
+
`Value is out of StorageAddress range [${RANGE_STORAGE_ADDRESS.min}, ${RANGE_STORAGE_ADDRESS.max}]`
|
|
8395
|
+
);
|
|
8396
|
+
}
|
|
8397
|
+
/**
|
|
8398
|
+
* Can this value be carried by a StorageAddress?
|
|
8399
|
+
*
|
|
8400
|
+
* The non-throwing form of {@link CairoStorageAddress.validate}, so it answers false for every
|
|
8401
|
+
* input that one refuses, whatever the reason.
|
|
8402
|
+
* @param {BigNumberish | boolean} data the value to test
|
|
8403
|
+
* @returns {boolean} true when the value fits in a StorageAddress
|
|
8404
|
+
* @example
|
|
8405
|
+
* ```typescript
|
|
8406
|
+
* const result = CairoStorageAddress.is('0x1234');
|
|
8407
|
+
* // result = true
|
|
8408
|
+
* const result2 = CairoStorageAddress.is('abc');
|
|
8409
|
+
* // result2 = false (text, not a number)
|
|
8410
|
+
* ```
|
|
8411
|
+
*/
|
|
8412
|
+
static is(data) {
|
|
8413
|
+
try {
|
|
8414
|
+
_CairoStorageAddress.validate(data);
|
|
8415
|
+
return true;
|
|
8416
|
+
} catch {
|
|
8417
|
+
return false;
|
|
8418
|
+
}
|
|
8419
|
+
}
|
|
8420
|
+
/**
|
|
8421
|
+
* Is this abi type the one this class serializes?
|
|
8422
|
+
* @param {string} abiType the abi type to test
|
|
8423
|
+
* @returns {boolean} true for `core::starknet::storage_access::StorageAddress`
|
|
8424
|
+
* @example
|
|
8425
|
+
* ```typescript
|
|
8426
|
+
* const result = CairoStorageAddress.isAbiType(
|
|
8427
|
+
* 'core::starknet::storage_access::StorageAddress'
|
|
8428
|
+
* );
|
|
8429
|
+
* // result = true
|
|
8430
|
+
* const result2 = CairoStorageAddress.isAbiType('core::felt252');
|
|
8431
|
+
* // result2 = false
|
|
8432
|
+
* ```
|
|
8433
|
+
*/
|
|
8434
|
+
static isAbiType(abiType) {
|
|
8435
|
+
return abiType === _CairoStorageAddress.abiSelector;
|
|
8436
|
+
}
|
|
8437
|
+
/**
|
|
8438
|
+
* Read one StorageAddress off a contract response, advancing the iterator past it.
|
|
8439
|
+
* @param {Iterator<string>} responseIterator the response felts, positioned on this address
|
|
8440
|
+
* @returns {CairoStorageAddress} the address that was read
|
|
8441
|
+
* @example
|
|
8442
|
+
* ```typescript
|
|
8443
|
+
* const response = ['0x1234'];
|
|
8444
|
+
* const result = CairoStorageAddress.factoryFromApiResponse(response.values()).toBigInt();
|
|
8445
|
+
* // result = 4660n
|
|
8446
|
+
* ```
|
|
8447
|
+
*/
|
|
8448
|
+
static factoryFromApiResponse(responseIterator) {
|
|
8449
|
+
return new _CairoStorageAddress(getNext(responseIterator));
|
|
8450
|
+
}
|
|
8451
|
+
};
|
|
8452
|
+
|
|
8283
8453
|
// src/utils/cairoDataTypes/ethAddress.ts
|
|
8284
8454
|
var CairoEthAddress = class _CairoEthAddress {
|
|
8285
8455
|
/**
|
|
@@ -10686,6 +10856,7 @@ var LEAF_TYPES = [
|
|
|
10686
10856
|
CairoEthAddress,
|
|
10687
10857
|
CairoClassHash,
|
|
10688
10858
|
CairoContractAddress,
|
|
10859
|
+
CairoStorageAddress,
|
|
10689
10860
|
CairoBytes31,
|
|
10690
10861
|
CairoByteArray,
|
|
10691
10862
|
CairoSecp256k1Point,
|
|
@@ -10759,6 +10930,7 @@ var cairoTypeStrategy = {
|
|
|
10759
10930
|
[CairoEthAddress.abiSelector]: (instance) => instance.toBigInt(),
|
|
10760
10931
|
[CairoClassHash.abiSelector]: (instance) => instance.toBigInt(),
|
|
10761
10932
|
[CairoContractAddress.abiSelector]: (instance) => instance.toBigInt(),
|
|
10933
|
+
[CairoStorageAddress.abiSelector]: (instance) => instance.toBigInt(),
|
|
10762
10934
|
[CairoBytes31.abiSelector]: (instance) => instance.decodeUtf8(),
|
|
10763
10935
|
[CairoByteArray.abiSelector]: (instance) => instance.decodeUtf8(),
|
|
10764
10936
|
[CairoSecp256k1Point.abiSelector]: (instance) => instance.toBigInt(),
|
|
@@ -11576,7 +11748,7 @@ function getAbiVersion(abi) {
|
|
|
11576
11748
|
return 0;
|
|
11577
11749
|
}
|
|
11578
11750
|
function isNoConstructorValid(method, argsCalldata, abiMethod) {
|
|
11579
|
-
return method === "constructor" && !abiMethod &&
|
|
11751
|
+
return method === "constructor" && !abiMethod && Object.keys(argsCalldata).length === 0;
|
|
11580
11752
|
}
|
|
11581
11753
|
|
|
11582
11754
|
// src/utils/calldata/propertyOrder.ts
|
|
@@ -11658,7 +11830,7 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
11658
11830
|
enumerable: true,
|
|
11659
11831
|
value: value ?? unorderedObject2[abiParam.name]
|
|
11660
11832
|
});
|
|
11661
|
-
if (unorderedObject2[abiParam.name] ===
|
|
11833
|
+
if (unorderedObject2[abiParam.name] === void 0) {
|
|
11662
11834
|
if (isCairo1Type(abiParam.type) || !isLen(abiParam.name)) {
|
|
11663
11835
|
throw Error(`Your object needs a property with key : ${abiParam.name} .`);
|
|
11664
11836
|
}
|
|
@@ -11759,6 +11931,9 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
11759
11931
|
if (isLen(abiParam.name) && !isCairo1Type(abiParam.type)) {
|
|
11760
11932
|
return orderedObject;
|
|
11761
11933
|
}
|
|
11934
|
+
if (unorderedObject[abiParam.name] === void 0) {
|
|
11935
|
+
throw Error(`Your object needs a property with key : ${abiParam.name} .`);
|
|
11936
|
+
}
|
|
11762
11937
|
setProperty(orderInput(unorderedObject[abiParam.name], abiParam.type));
|
|
11763
11938
|
return orderedObject;
|
|
11764
11939
|
}, {});
|
|
@@ -11766,6 +11941,11 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
11766
11941
|
}
|
|
11767
11942
|
|
|
11768
11943
|
// src/utils/calldata/index.ts
|
|
11944
|
+
function methodNotInAbiError(method) {
|
|
11945
|
+
return Error(
|
|
11946
|
+
method === "constructor" ? "Cannot pass calldata to a contract with no constructor" : `Method "${method}" not found in abi`
|
|
11947
|
+
);
|
|
11948
|
+
}
|
|
11769
11949
|
var CallData = class _CallData {
|
|
11770
11950
|
abi;
|
|
11771
11951
|
parser;
|
|
@@ -11796,11 +11976,14 @@ var CallData = class _CallData {
|
|
|
11796
11976
|
);
|
|
11797
11977
|
}
|
|
11798
11978
|
const abiMethod = this.abi.find(
|
|
11799
|
-
(abi) => type === ValidateType.DEPLOY ? abi.name === method
|
|
11979
|
+
(abi) => type === ValidateType.DEPLOY ? abi.name === method : abi.name === method && abi.type === "function"
|
|
11800
11980
|
);
|
|
11801
11981
|
if (isNoConstructorValid(method, args, abiMethod)) {
|
|
11802
11982
|
return;
|
|
11803
11983
|
}
|
|
11984
|
+
if (!abiMethod) {
|
|
11985
|
+
throw methodNotInAbiError(method);
|
|
11986
|
+
}
|
|
11804
11987
|
const inputsLength = this.parser.methodInputsLength(abiMethod);
|
|
11805
11988
|
if (args.length !== inputsLength) {
|
|
11806
11989
|
throw Error(
|
|
@@ -11828,6 +12011,9 @@ var CallData = class _CallData {
|
|
|
11828
12011
|
if (isNoConstructorValid(method, argsCalldata, abiMethod)) {
|
|
11829
12012
|
return [];
|
|
11830
12013
|
}
|
|
12014
|
+
if (!abiMethod) {
|
|
12015
|
+
throw methodNotInAbiError(method);
|
|
12016
|
+
}
|
|
11831
12017
|
let args;
|
|
11832
12018
|
if (Array.isArray(argsCalldata)) {
|
|
11833
12019
|
args = argsCalldata;
|
|
@@ -12492,6 +12678,9 @@ function wait(delay) {
|
|
|
12492
12678
|
});
|
|
12493
12679
|
}
|
|
12494
12680
|
async function createSierraContractClass(contract) {
|
|
12681
|
+
if (contract.abi === void 0 || contract.abi === null) {
|
|
12682
|
+
throw Error('Invalid Sierra contract: the "abi" field is missing');
|
|
12683
|
+
}
|
|
12495
12684
|
const result = { ...contract };
|
|
12496
12685
|
delete result.sierra_program_debug_info;
|
|
12497
12686
|
result.abi = formatSpaces(stringify2(contract.abi));
|
|
@@ -15160,7 +15349,7 @@ var SubscriptionChannel4 = class extends SubscriptionChannel {
|
|
|
15160
15349
|
var WebSocketChannel = class {
|
|
15161
15350
|
/**
|
|
15162
15351
|
* The URL of the WebSocket RPC Node.
|
|
15163
|
-
* @example 'wss://starknet-
|
|
15352
|
+
* @example 'wss://your-starknet-node/rpc/v0_10'
|
|
15164
15353
|
*/
|
|
15165
15354
|
nodeUrl;
|
|
15166
15355
|
/** Carries the frames and owns the socket lifecycle. */
|
|
@@ -17538,6 +17727,9 @@ if (typeof Symbol.dispose !== "undefined") {
|
|
|
17538
17727
|
WebSocketProvider.prototype[Symbol.dispose] = WebSocketProvider.prototype.dispose;
|
|
17539
17728
|
}
|
|
17540
17729
|
|
|
17730
|
+
// src/provider/index.ts
|
|
17731
|
+
var Provider = RpcProvider;
|
|
17732
|
+
|
|
17541
17733
|
// src/signer/interface.ts
|
|
17542
17734
|
var SignerInterface = class {
|
|
17543
17735
|
};
|
|
@@ -18005,13 +18197,13 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
18005
18197
|
*
|
|
18006
18198
|
* If you are using APP v2.2.1 with an account created with the v1.1.1, you need to use :
|
|
18007
18199
|
* ```typescript
|
|
18008
|
-
* const myLedgerSigner = new
|
|
18200
|
+
* const myLedgerSigner = new LedgerSigner221(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
|
|
18009
18201
|
* ```
|
|
18010
18202
|
* @example
|
|
18011
18203
|
* ```typescript
|
|
18012
18204
|
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
18013
18205
|
* const myNodeTransport = await TransportNodeHid.create();
|
|
18014
|
-
* const myLedgerSigner = new
|
|
18206
|
+
* const myLedgerSigner = new LedgerSigner221(myNodeTransport, 0);
|
|
18015
18207
|
* ```
|
|
18016
18208
|
*/
|
|
18017
18209
|
constructor(transport, accountID, eip2645application = "LedgerW", pathFunction = getLedgerPathBuffer221) {
|
|
@@ -19066,6 +19258,76 @@ var PaymasterRpc = class _PaymasterRpc {
|
|
|
19066
19258
|
var PaymasterInterface = class {
|
|
19067
19259
|
};
|
|
19068
19260
|
|
|
19261
|
+
// src/deployer/compileConstructorCalldata.ts
|
|
19262
|
+
function checkCompiledConstructorCalldata(calldata, abi) {
|
|
19263
|
+
const calldataClass = new CallData(abi);
|
|
19264
|
+
const constructorAbi = calldataClass.abi.find((entry) => entry.name === "constructor");
|
|
19265
|
+
if (!constructorAbi) {
|
|
19266
|
+
if (calldata.length > 0) {
|
|
19267
|
+
throw Error("Cannot pass calldata to a contract with no constructor");
|
|
19268
|
+
}
|
|
19269
|
+
return;
|
|
19270
|
+
}
|
|
19271
|
+
let index = 0;
|
|
19272
|
+
const felts = {
|
|
19273
|
+
next: () => {
|
|
19274
|
+
if (index >= calldata.length) {
|
|
19275
|
+
throw Error("it has fewer felts than the constructor takes");
|
|
19276
|
+
}
|
|
19277
|
+
index += 1;
|
|
19278
|
+
return { value: String(calldata[index - 1]), done: false };
|
|
19279
|
+
}
|
|
19280
|
+
};
|
|
19281
|
+
const parsed = {};
|
|
19282
|
+
try {
|
|
19283
|
+
constructorAbi.inputs.forEach((input) => {
|
|
19284
|
+
parsed[input.name] = calldataClass.parser.parseResponse(felts, input, parsed);
|
|
19285
|
+
});
|
|
19286
|
+
} catch (error) {
|
|
19287
|
+
throw Error(
|
|
19288
|
+
`The compiled constructor calldata does not match the abi: ${error.message}`
|
|
19289
|
+
);
|
|
19290
|
+
}
|
|
19291
|
+
const leftover = calldata.length - index;
|
|
19292
|
+
if (leftover > 0) {
|
|
19293
|
+
throw Error(
|
|
19294
|
+
`The compiled constructor calldata does not match the abi: it has ${leftover} felt${leftover > 1 ? "s" : ""} too many`
|
|
19295
|
+
);
|
|
19296
|
+
}
|
|
19297
|
+
let written;
|
|
19298
|
+
try {
|
|
19299
|
+
written = calldataClass.compile("constructor", parsed);
|
|
19300
|
+
} catch (error) {
|
|
19301
|
+
throw Error(
|
|
19302
|
+
`The compiled constructor calldata does not match the abi: ${error.message}`
|
|
19303
|
+
);
|
|
19304
|
+
}
|
|
19305
|
+
const sameFelts = written.length === calldata.length && written.every((felt2, i) => BigInt(felt2) === BigInt(calldata[i]));
|
|
19306
|
+
if (!sameFelts) {
|
|
19307
|
+
throw Error(
|
|
19308
|
+
"The compiled constructor calldata does not match the abi: the abi writes the values it holds with other felts"
|
|
19309
|
+
);
|
|
19310
|
+
}
|
|
19311
|
+
}
|
|
19312
|
+
function compileConstructorCalldata(constructorCalldata = [], abi) {
|
|
19313
|
+
let compiledHere = false;
|
|
19314
|
+
const calldata = getCompiledCalldata(constructorCalldata, () => {
|
|
19315
|
+
compiledHere = true;
|
|
19316
|
+
if (abi) {
|
|
19317
|
+
const calldataClass = new CallData(abi);
|
|
19318
|
+
if (Array.isArray(constructorCalldata)) {
|
|
19319
|
+
calldataClass.validate(ValidateType.DEPLOY, "constructor", constructorCalldata);
|
|
19320
|
+
}
|
|
19321
|
+
return calldataClass.compile("constructor", constructorCalldata);
|
|
19322
|
+
}
|
|
19323
|
+
return CallData.compile(constructorCalldata);
|
|
19324
|
+
});
|
|
19325
|
+
if (abi && !compiledHere) {
|
|
19326
|
+
checkCompiledConstructorCalldata(calldata, abi);
|
|
19327
|
+
}
|
|
19328
|
+
return calldata;
|
|
19329
|
+
}
|
|
19330
|
+
|
|
19069
19331
|
// src/deployer/default.ts
|
|
19070
19332
|
var Deployer = class {
|
|
19071
19333
|
address;
|
|
@@ -19084,16 +19346,7 @@ var Deployer = class {
|
|
|
19084
19346
|
constructorCalldata = [],
|
|
19085
19347
|
abi
|
|
19086
19348
|
} = it;
|
|
19087
|
-
const compiledConstructorCallData =
|
|
19088
|
-
if (abi) {
|
|
19089
|
-
const calldataClass = new CallData(abi);
|
|
19090
|
-
if (Array.isArray(constructorCalldata)) {
|
|
19091
|
-
calldataClass.validate(ValidateType.DEPLOY, "constructor", constructorCalldata);
|
|
19092
|
-
}
|
|
19093
|
-
return calldataClass.compile("constructor", constructorCalldata);
|
|
19094
|
-
}
|
|
19095
|
-
return CallData.compile(constructorCalldata);
|
|
19096
|
-
});
|
|
19349
|
+
const compiledConstructorCallData = compileConstructorCalldata(constructorCalldata, abi);
|
|
19097
19350
|
const deploySalt = salt ?? randomFelt();
|
|
19098
19351
|
return {
|
|
19099
19352
|
call: {
|
|
@@ -19243,9 +19496,10 @@ var Account = class {
|
|
|
19243
19496
|
classHash,
|
|
19244
19497
|
addressSalt = 0,
|
|
19245
19498
|
constructorCalldata = [],
|
|
19246
|
-
contractAddress
|
|
19499
|
+
contractAddress,
|
|
19500
|
+
abi
|
|
19247
19501
|
}, details = {}) {
|
|
19248
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
19502
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
19249
19503
|
const contractAddressFinal = contractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
19250
19504
|
const invocations = [
|
|
19251
19505
|
{
|
|
@@ -19422,6 +19676,9 @@ var Account = class {
|
|
|
19422
19676
|
* First check if contract is already declared, if not declare it
|
|
19423
19677
|
* If contract already declared returned transaction_hash is ''.
|
|
19424
19678
|
* Method will pass even if contract is already declared
|
|
19679
|
+
*
|
|
19680
|
+
* A given `classHash` is used as is to look for the class on the node, without being checked
|
|
19681
|
+
* against `contract`, to save time.
|
|
19425
19682
|
* @param transactionsDetail (optional)
|
|
19426
19683
|
*/
|
|
19427
19684
|
async declareIfNot(payload, transactionsDetail = {}) {
|
|
@@ -19494,14 +19751,29 @@ var Account = class {
|
|
|
19494
19751
|
);
|
|
19495
19752
|
}
|
|
19496
19753
|
async declareAndDeploy(payload, details = {}) {
|
|
19497
|
-
|
|
19498
|
-
|
|
19754
|
+
if (payload.abi) {
|
|
19755
|
+
logger.warn(
|
|
19756
|
+
'The "abi" field is ignored: the ABI is taken from "contract". This field will be removed in v12.'
|
|
19757
|
+
);
|
|
19758
|
+
}
|
|
19759
|
+
const abi = extractAbi(await parseContract(payload.contract));
|
|
19760
|
+
const constructorCalldata = compileConstructorCalldata(payload.constructorCalldata, abi);
|
|
19761
|
+
const classHash = computeContractClassHash(payload.contract);
|
|
19762
|
+
if (payload.classHash !== void 0 && payload.classHash !== null && toBigInt(payload.classHash) !== toBigInt(classHash)) {
|
|
19763
|
+
throw Error(
|
|
19764
|
+
`The given classHash ${payload.classHash} is not the class hash of "contract": ${classHash}`
|
|
19765
|
+
);
|
|
19766
|
+
}
|
|
19767
|
+
let declare = await this.declareIfNot({ ...payload, classHash }, details);
|
|
19768
|
+
const declarationSent = declare.transaction_hash !== "";
|
|
19769
|
+
if (declarationSent) {
|
|
19499
19770
|
const tx = await this.provider.waitForTransaction(declare.transaction_hash, details);
|
|
19500
19771
|
declare = { ...declare, ...tx };
|
|
19501
19772
|
}
|
|
19773
|
+
const deployDetails = declarationSent && details.nonce !== void 0 && details.nonce !== null ? { ...details, nonce: toBigInt(details.nonce) + 1n } : details;
|
|
19502
19774
|
const deploy = await this.deployContract(
|
|
19503
|
-
{ ...payload, classHash: declare.class_hash },
|
|
19504
|
-
|
|
19775
|
+
{ ...payload, classHash: declare.class_hash, constructorCalldata, abi: void 0 },
|
|
19776
|
+
deployDetails
|
|
19505
19777
|
);
|
|
19506
19778
|
return { declare: { ...declare }, deploy };
|
|
19507
19779
|
}
|
|
@@ -19510,9 +19782,10 @@ var Account = class {
|
|
|
19510
19782
|
classHash,
|
|
19511
19783
|
constructorCalldata = [],
|
|
19512
19784
|
addressSalt = 0,
|
|
19513
|
-
contractAddress: providedContractAddress
|
|
19785
|
+
contractAddress: providedContractAddress,
|
|
19786
|
+
abi
|
|
19514
19787
|
}, details = {}) {
|
|
19515
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
19788
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
19516
19789
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
19517
19790
|
const detailsWithTip = await this.resolveDetailsWithTip(details);
|
|
19518
19791
|
const { resourceBounds: providedResourceBounds } = details;
|
|
@@ -19523,7 +19796,8 @@ var Account = class {
|
|
|
19523
19796
|
classHash,
|
|
19524
19797
|
constructorCalldata,
|
|
19525
19798
|
addressSalt,
|
|
19526
|
-
contractAddress
|
|
19799
|
+
contractAddress,
|
|
19800
|
+
abi
|
|
19527
19801
|
},
|
|
19528
19802
|
detailsWithTip
|
|
19529
19803
|
);
|
|
@@ -19785,9 +20059,10 @@ var Account = class {
|
|
|
19785
20059
|
classHash,
|
|
19786
20060
|
addressSalt = 0,
|
|
19787
20061
|
constructorCalldata = [],
|
|
19788
|
-
contractAddress: providedContractAddress
|
|
20062
|
+
contractAddress: providedContractAddress,
|
|
20063
|
+
abi
|
|
19789
20064
|
}, details) {
|
|
19790
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
20065
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
19791
20066
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
19792
20067
|
const signature = !details.skipValidate ? await this.signer.signDeployAccountTransaction({
|
|
19793
20068
|
...details,
|
|
@@ -21412,10 +21687,10 @@ var Contract = class _Contract {
|
|
|
21412
21687
|
const deployResult = await account.deployContract(
|
|
21413
21688
|
{
|
|
21414
21689
|
classHash,
|
|
21415
|
-
constructorCalldata: deployParams.constructorCalldata,
|
|
21690
|
+
constructorCalldata: parseRequest ? deployParams.constructorCalldata : compileConstructorCalldata(deployParams.constructorCalldata),
|
|
21416
21691
|
salt: deployParams.salt,
|
|
21417
21692
|
unique: deployParams.unique,
|
|
21418
|
-
abi
|
|
21693
|
+
abi
|
|
21419
21694
|
},
|
|
21420
21695
|
details
|
|
21421
21696
|
);
|
|
@@ -21423,17 +21698,12 @@ var Contract = class _Contract {
|
|
|
21423
21698
|
} else {
|
|
21424
21699
|
const declareParams = params;
|
|
21425
21700
|
const contract = await parseContract(declareParams.contract);
|
|
21426
|
-
abi =
|
|
21701
|
+
abi = extractAbi(contract);
|
|
21702
|
+
const constructorCalldata = parseRequest ? declareParams.constructorCalldata : compileConstructorCalldata(declareParams.constructorCalldata);
|
|
21427
21703
|
const {
|
|
21428
21704
|
declare: { class_hash },
|
|
21429
21705
|
deploy: { contract_address: deployed_address }
|
|
21430
|
-
} = await account.declareAndDeploy(
|
|
21431
|
-
{
|
|
21432
|
-
...declareParams,
|
|
21433
|
-
abi: parseRequest ? abi : void 0
|
|
21434
|
-
},
|
|
21435
|
-
details
|
|
21436
|
-
);
|
|
21706
|
+
} = await account.declareAndDeploy({ ...declareParams, constructorCalldata }, details);
|
|
21437
21707
|
classHash = class_hash.toString();
|
|
21438
21708
|
contract_address = deployed_address;
|
|
21439
21709
|
}
|
|
@@ -21528,6 +21798,7 @@ function units(amount, simbol = "fri") {
|
|
|
21528
21798
|
CairoResult,
|
|
21529
21799
|
CairoResultVariant,
|
|
21530
21800
|
CairoSecp256k1Point,
|
|
21801
|
+
CairoStorageAddress,
|
|
21531
21802
|
CairoStruct,
|
|
21532
21803
|
CairoTuple,
|
|
21533
21804
|
CairoTypeCustomEnum,
|