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.global.js
CHANGED
|
@@ -77,6 +77,7 @@ var starknet = (() => {
|
|
|
77
77
|
CairoResult: () => CairoResult,
|
|
78
78
|
CairoResultVariant: () => CairoResultVariant,
|
|
79
79
|
CairoSecp256k1Point: () => CairoSecp256k1Point,
|
|
80
|
+
CairoStorageAddress: () => CairoStorageAddress,
|
|
80
81
|
CairoStruct: () => CairoStruct,
|
|
81
82
|
CairoTuple: () => CairoTuple,
|
|
82
83
|
CairoTypeCustomEnum: () => CairoTypeCustomEnum,
|
|
@@ -123,7 +124,7 @@ var starknet = (() => {
|
|
|
123
124
|
PaymasterInterface: () => PaymasterInterface,
|
|
124
125
|
PaymasterRpc: () => PaymasterRpc,
|
|
125
126
|
PluginManager: () => PluginManager,
|
|
126
|
-
Provider: () =>
|
|
127
|
+
Provider: () => Provider,
|
|
127
128
|
ProviderInterface: () => ProviderInterface,
|
|
128
129
|
RPC: () => api_exports3,
|
|
129
130
|
RPC0102: () => v0_10_2_exports,
|
|
@@ -269,6 +270,7 @@ var starknet = (() => {
|
|
|
269
270
|
RANGE_I32: () => RANGE_I32,
|
|
270
271
|
RANGE_I64: () => RANGE_I64,
|
|
271
272
|
RANGE_I8: () => RANGE_I8,
|
|
273
|
+
RANGE_STORAGE_ADDRESS: () => RANGE_STORAGE_ADDRESS,
|
|
272
274
|
RANGE_U128: () => RANGE_U128,
|
|
273
275
|
RANGE_U16: () => RANGE_U16,
|
|
274
276
|
RANGE_U32: () => RANGE_U32,
|
|
@@ -1236,6 +1238,7 @@ var starknet = (() => {
|
|
|
1236
1238
|
var RANGE_ETH_ADDRESS = range(ZERO, 2n ** 160n - 1n);
|
|
1237
1239
|
var RANGE_CONTRACT_ADDRESS = range(ZERO, ADDR_BOUND - 1n);
|
|
1238
1240
|
var RANGE_CLASS_HASH = range(ZERO, 2n ** 251n - 1n);
|
|
1241
|
+
var RANGE_STORAGE_ADDRESS = range(ZERO, 2n ** 251n - 1n);
|
|
1239
1242
|
var LegacyUDC = {
|
|
1240
1243
|
ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
|
|
1241
1244
|
ENTRYPOINT: "deployContract"
|
|
@@ -3203,6 +3206,7 @@ ${indent}}` : "}";
|
|
|
3203
3206
|
ClassHash: "core::starknet::class_hash::ClassHash",
|
|
3204
3207
|
ContractAddress: "core::starknet::contract_address::ContractAddress",
|
|
3205
3208
|
Secp256k1Point: "core::starknet::secp256k1::Secp256k1Point",
|
|
3209
|
+
StorageAddress: "core::starknet::storage_access::StorageAddress",
|
|
3206
3210
|
U96: "core::internal::bounded_int::BoundedInt::<0, 79228162514264337593543950335>"
|
|
3207
3211
|
};
|
|
3208
3212
|
var ETH_ADDRESS = "core::starknet::eth_address::EthAddress";
|
|
@@ -6600,6 +6604,9 @@ ${indent}}` : "}";
|
|
|
6600
6604
|
return BigInt(addHexPrefix(starknet_exports.keccak(utf8ToUint8Array(indentString)).toString(16)));
|
|
6601
6605
|
}
|
|
6602
6606
|
function computeSierraContractClassHash(sierra) {
|
|
6607
|
+
if (sierra.abi === void 0 || sierra.abi === null) {
|
|
6608
|
+
throw Error('Invalid Sierra contract: the "abi" field is missing');
|
|
6609
|
+
}
|
|
6603
6610
|
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
6604
6611
|
const compiledClassVersion = utf8ToBigInt(CONTRACT_CLASS_VERSION);
|
|
6605
6612
|
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
@@ -13705,6 +13712,169 @@ ${indent}}` : "}";
|
|
|
13705
13712
|
}
|
|
13706
13713
|
};
|
|
13707
13714
|
|
|
13715
|
+
// src/utils/cairoDataTypes/storageAddress.ts
|
|
13716
|
+
var CairoStorageAddress = class _CairoStorageAddress {
|
|
13717
|
+
/**
|
|
13718
|
+
* The address, always as a bigint.
|
|
13719
|
+
* @example
|
|
13720
|
+
* ```typescript
|
|
13721
|
+
* const result = new CairoStorageAddress('0x1234').data;
|
|
13722
|
+
* // result = 4660n
|
|
13723
|
+
* ```
|
|
13724
|
+
*/
|
|
13725
|
+
data;
|
|
13726
|
+
/**
|
|
13727
|
+
* The abi type this class serializes.
|
|
13728
|
+
* @example
|
|
13729
|
+
* ```typescript
|
|
13730
|
+
* const result = CairoStorageAddress.abiSelector;
|
|
13731
|
+
* // result = "core::starknet::storage_access::StorageAddress"
|
|
13732
|
+
* ```
|
|
13733
|
+
*/
|
|
13734
|
+
static abiSelector = Literal.StorageAddress;
|
|
13735
|
+
/**
|
|
13736
|
+
* Build from a number or a numeric string, refusing text and anything outside the
|
|
13737
|
+
* StorageAddress range.
|
|
13738
|
+
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^251 - 1]
|
|
13739
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the StorageAddress range
|
|
13740
|
+
* @example
|
|
13741
|
+
* ```typescript
|
|
13742
|
+
* const result = new CairoStorageAddress('0x1234').toApiRequest();
|
|
13743
|
+
* // result = ["4660"]
|
|
13744
|
+
* ```
|
|
13745
|
+
*/
|
|
13746
|
+
constructor(data) {
|
|
13747
|
+
_CairoStorageAddress.validate(data);
|
|
13748
|
+
this.data = new CairoFelt252(data).toBigInt();
|
|
13749
|
+
}
|
|
13750
|
+
/**
|
|
13751
|
+
* Serialize to the single felt a contract call carries.
|
|
13752
|
+
* @returns {string[]} one decimal-string felt, flagged as compiled
|
|
13753
|
+
* @example
|
|
13754
|
+
* ```typescript
|
|
13755
|
+
* const result = new CairoStorageAddress('0x1234').toApiRequest();
|
|
13756
|
+
* // result = ["4660"]
|
|
13757
|
+
* ```
|
|
13758
|
+
*/
|
|
13759
|
+
toApiRequest() {
|
|
13760
|
+
return addCompiledFlag([this.toBigInt().toString()]);
|
|
13761
|
+
}
|
|
13762
|
+
/**
|
|
13763
|
+
* The address as a number.
|
|
13764
|
+
* @returns {bigint} the number this address holds
|
|
13765
|
+
* @example
|
|
13766
|
+
* ```typescript
|
|
13767
|
+
* const result = new CairoStorageAddress('0x1234').toBigInt();
|
|
13768
|
+
* // result = 4660n
|
|
13769
|
+
* ```
|
|
13770
|
+
*/
|
|
13771
|
+
toBigInt() {
|
|
13772
|
+
return this.data;
|
|
13773
|
+
}
|
|
13774
|
+
/**
|
|
13775
|
+
* The address in hexadecimal, without padding.
|
|
13776
|
+
*
|
|
13777
|
+
* Leading zeros are dropped, as they are everywhere else in the library.
|
|
13778
|
+
* @returns {string} the address as a 0x-prefixed hex string
|
|
13779
|
+
* @example
|
|
13780
|
+
* ```typescript
|
|
13781
|
+
* const result = new CairoStorageAddress(4660).toHexString();
|
|
13782
|
+
* // result = "0x1234"
|
|
13783
|
+
* const result2 = new CairoStorageAddress('0x0034').toHexString();
|
|
13784
|
+
* // result2 = "0x34" (four digits in, two out)
|
|
13785
|
+
* ```
|
|
13786
|
+
*/
|
|
13787
|
+
toHexString() {
|
|
13788
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
13789
|
+
}
|
|
13790
|
+
/**
|
|
13791
|
+
* Throw unless the value can be carried by a StorageAddress.
|
|
13792
|
+
*
|
|
13793
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
13794
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
13795
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
13796
|
+
* the range of the Cairo `StorageAddress` type, [0, 2^251), which is narrower than the field.
|
|
13797
|
+
* @param {BigNumberish | boolean} data the value to check
|
|
13798
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the StorageAddress range
|
|
13799
|
+
* @example
|
|
13800
|
+
* ```typescript
|
|
13801
|
+
* CairoStorageAddress.validate('0x1234'); // passes
|
|
13802
|
+
* CairoStorageAddress.validate('abc');
|
|
13803
|
+
* // throws Error("Invalid input: a StorageAddress cannot be built from text")
|
|
13804
|
+
* CairoStorageAddress.validate(2n ** 251n);
|
|
13805
|
+
* // throws Error("Value is out of StorageAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
13806
|
+
* CairoStorageAddress.validate(-1);
|
|
13807
|
+
* // throws Error("Value is out of StorageAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
13808
|
+
* ```
|
|
13809
|
+
*/
|
|
13810
|
+
static validate(data) {
|
|
13811
|
+
assert(!isText(data), "Invalid input: a StorageAddress cannot be built from text");
|
|
13812
|
+
assert(
|
|
13813
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
13814
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
13815
|
+
);
|
|
13816
|
+
const value = isNumber2(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
13817
|
+
assert(
|
|
13818
|
+
value >= RANGE_STORAGE_ADDRESS.min && value <= RANGE_STORAGE_ADDRESS.max,
|
|
13819
|
+
`Value is out of StorageAddress range [${RANGE_STORAGE_ADDRESS.min}, ${RANGE_STORAGE_ADDRESS.max}]`
|
|
13820
|
+
);
|
|
13821
|
+
}
|
|
13822
|
+
/**
|
|
13823
|
+
* Can this value be carried by a StorageAddress?
|
|
13824
|
+
*
|
|
13825
|
+
* The non-throwing form of {@link CairoStorageAddress.validate}, so it answers false for every
|
|
13826
|
+
* input that one refuses, whatever the reason.
|
|
13827
|
+
* @param {BigNumberish | boolean} data the value to test
|
|
13828
|
+
* @returns {boolean} true when the value fits in a StorageAddress
|
|
13829
|
+
* @example
|
|
13830
|
+
* ```typescript
|
|
13831
|
+
* const result = CairoStorageAddress.is('0x1234');
|
|
13832
|
+
* // result = true
|
|
13833
|
+
* const result2 = CairoStorageAddress.is('abc');
|
|
13834
|
+
* // result2 = false (text, not a number)
|
|
13835
|
+
* ```
|
|
13836
|
+
*/
|
|
13837
|
+
static is(data) {
|
|
13838
|
+
try {
|
|
13839
|
+
_CairoStorageAddress.validate(data);
|
|
13840
|
+
return true;
|
|
13841
|
+
} catch {
|
|
13842
|
+
return false;
|
|
13843
|
+
}
|
|
13844
|
+
}
|
|
13845
|
+
/**
|
|
13846
|
+
* Is this abi type the one this class serializes?
|
|
13847
|
+
* @param {string} abiType the abi type to test
|
|
13848
|
+
* @returns {boolean} true for `core::starknet::storage_access::StorageAddress`
|
|
13849
|
+
* @example
|
|
13850
|
+
* ```typescript
|
|
13851
|
+
* const result = CairoStorageAddress.isAbiType(
|
|
13852
|
+
* 'core::starknet::storage_access::StorageAddress'
|
|
13853
|
+
* );
|
|
13854
|
+
* // result = true
|
|
13855
|
+
* const result2 = CairoStorageAddress.isAbiType('core::felt252');
|
|
13856
|
+
* // result2 = false
|
|
13857
|
+
* ```
|
|
13858
|
+
*/
|
|
13859
|
+
static isAbiType(abiType) {
|
|
13860
|
+
return abiType === _CairoStorageAddress.abiSelector;
|
|
13861
|
+
}
|
|
13862
|
+
/**
|
|
13863
|
+
* Read one StorageAddress off a contract response, advancing the iterator past it.
|
|
13864
|
+
* @param {Iterator<string>} responseIterator the response felts, positioned on this address
|
|
13865
|
+
* @returns {CairoStorageAddress} the address that was read
|
|
13866
|
+
* @example
|
|
13867
|
+
* ```typescript
|
|
13868
|
+
* const response = ['0x1234'];
|
|
13869
|
+
* const result = CairoStorageAddress.factoryFromApiResponse(response.values()).toBigInt();
|
|
13870
|
+
* // result = 4660n
|
|
13871
|
+
* ```
|
|
13872
|
+
*/
|
|
13873
|
+
static factoryFromApiResponse(responseIterator) {
|
|
13874
|
+
return new _CairoStorageAddress(getNext(responseIterator));
|
|
13875
|
+
}
|
|
13876
|
+
};
|
|
13877
|
+
|
|
13708
13878
|
// src/utils/cairoDataTypes/ethAddress.ts
|
|
13709
13879
|
var CairoEthAddress = class _CairoEthAddress {
|
|
13710
13880
|
/**
|
|
@@ -16111,6 +16281,7 @@ ${indent}}` : "}";
|
|
|
16111
16281
|
CairoEthAddress,
|
|
16112
16282
|
CairoClassHash,
|
|
16113
16283
|
CairoContractAddress,
|
|
16284
|
+
CairoStorageAddress,
|
|
16114
16285
|
CairoBytes31,
|
|
16115
16286
|
CairoByteArray,
|
|
16116
16287
|
CairoSecp256k1Point,
|
|
@@ -16184,6 +16355,7 @@ ${indent}}` : "}";
|
|
|
16184
16355
|
[CairoEthAddress.abiSelector]: (instance) => instance.toBigInt(),
|
|
16185
16356
|
[CairoClassHash.abiSelector]: (instance) => instance.toBigInt(),
|
|
16186
16357
|
[CairoContractAddress.abiSelector]: (instance) => instance.toBigInt(),
|
|
16358
|
+
[CairoStorageAddress.abiSelector]: (instance) => instance.toBigInt(),
|
|
16187
16359
|
[CairoBytes31.abiSelector]: (instance) => instance.decodeUtf8(),
|
|
16188
16360
|
[CairoByteArray.abiSelector]: (instance) => instance.decodeUtf8(),
|
|
16189
16361
|
[CairoSecp256k1Point.abiSelector]: (instance) => instance.toBigInt(),
|
|
@@ -17001,7 +17173,7 @@ ${indent}}` : "}";
|
|
|
17001
17173
|
return 0;
|
|
17002
17174
|
}
|
|
17003
17175
|
function isNoConstructorValid(method, argsCalldata, abiMethod) {
|
|
17004
|
-
return method === "constructor" && !abiMethod &&
|
|
17176
|
+
return method === "constructor" && !abiMethod && Object.keys(argsCalldata).length === 0;
|
|
17005
17177
|
}
|
|
17006
17178
|
|
|
17007
17179
|
// src/utils/calldata/propertyOrder.ts
|
|
@@ -17083,7 +17255,7 @@ ${indent}}` : "}";
|
|
|
17083
17255
|
enumerable: true,
|
|
17084
17256
|
value: value ?? unorderedObject2[abiParam.name]
|
|
17085
17257
|
});
|
|
17086
|
-
if (unorderedObject2[abiParam.name] ===
|
|
17258
|
+
if (unorderedObject2[abiParam.name] === void 0) {
|
|
17087
17259
|
if (isCairo1Type(abiParam.type) || !isLen(abiParam.name)) {
|
|
17088
17260
|
throw Error(`Your object needs a property with key : ${abiParam.name} .`);
|
|
17089
17261
|
}
|
|
@@ -17184,6 +17356,9 @@ ${indent}}` : "}";
|
|
|
17184
17356
|
if (isLen(abiParam.name) && !isCairo1Type(abiParam.type)) {
|
|
17185
17357
|
return orderedObject;
|
|
17186
17358
|
}
|
|
17359
|
+
if (unorderedObject[abiParam.name] === void 0) {
|
|
17360
|
+
throw Error(`Your object needs a property with key : ${abiParam.name} .`);
|
|
17361
|
+
}
|
|
17187
17362
|
setProperty(orderInput(unorderedObject[abiParam.name], abiParam.type));
|
|
17188
17363
|
return orderedObject;
|
|
17189
17364
|
}, {});
|
|
@@ -17191,6 +17366,11 @@ ${indent}}` : "}";
|
|
|
17191
17366
|
}
|
|
17192
17367
|
|
|
17193
17368
|
// src/utils/calldata/index.ts
|
|
17369
|
+
function methodNotInAbiError(method) {
|
|
17370
|
+
return Error(
|
|
17371
|
+
method === "constructor" ? "Cannot pass calldata to a contract with no constructor" : `Method "${method}" not found in abi`
|
|
17372
|
+
);
|
|
17373
|
+
}
|
|
17194
17374
|
var CallData = class _CallData {
|
|
17195
17375
|
abi;
|
|
17196
17376
|
parser;
|
|
@@ -17221,11 +17401,14 @@ ${indent}}` : "}";
|
|
|
17221
17401
|
);
|
|
17222
17402
|
}
|
|
17223
17403
|
const abiMethod = this.abi.find(
|
|
17224
|
-
(abi) => type === ValidateType.DEPLOY ? abi.name === method
|
|
17404
|
+
(abi) => type === ValidateType.DEPLOY ? abi.name === method : abi.name === method && abi.type === "function"
|
|
17225
17405
|
);
|
|
17226
17406
|
if (isNoConstructorValid(method, args, abiMethod)) {
|
|
17227
17407
|
return;
|
|
17228
17408
|
}
|
|
17409
|
+
if (!abiMethod) {
|
|
17410
|
+
throw methodNotInAbiError(method);
|
|
17411
|
+
}
|
|
17229
17412
|
const inputsLength = this.parser.methodInputsLength(abiMethod);
|
|
17230
17413
|
if (args.length !== inputsLength) {
|
|
17231
17414
|
throw Error(
|
|
@@ -17253,6 +17436,9 @@ ${indent}}` : "}";
|
|
|
17253
17436
|
if (isNoConstructorValid(method, argsCalldata, abiMethod)) {
|
|
17254
17437
|
return [];
|
|
17255
17438
|
}
|
|
17439
|
+
if (!abiMethod) {
|
|
17440
|
+
throw methodNotInAbiError(method);
|
|
17441
|
+
}
|
|
17256
17442
|
let args;
|
|
17257
17443
|
if (Array.isArray(argsCalldata)) {
|
|
17258
17444
|
args = argsCalldata;
|
|
@@ -17915,6 +18101,9 @@ ${indent}}` : "}";
|
|
|
17915
18101
|
});
|
|
17916
18102
|
}
|
|
17917
18103
|
async function createSierraContractClass(contract) {
|
|
18104
|
+
if (contract.abi === void 0 || contract.abi === null) {
|
|
18105
|
+
throw Error('Invalid Sierra contract: the "abi" field is missing');
|
|
18106
|
+
}
|
|
17918
18107
|
const result = { ...contract };
|
|
17919
18108
|
delete result.sierra_program_debug_info;
|
|
17920
18109
|
result.abi = formatSpaces(stringify2(contract.abi));
|
|
@@ -20713,7 +20902,7 @@ ${indent}}` : "}";
|
|
|
20713
20902
|
var WebSocketChannel = class {
|
|
20714
20903
|
/**
|
|
20715
20904
|
* The URL of the WebSocket RPC Node.
|
|
20716
|
-
* @example 'wss://starknet-
|
|
20905
|
+
* @example 'wss://your-starknet-node/rpc/v0_10'
|
|
20717
20906
|
*/
|
|
20718
20907
|
nodeUrl;
|
|
20719
20908
|
/** Carries the frames and owns the socket lifecycle. */
|
|
@@ -23091,6 +23280,9 @@ ${indent}}` : "}";
|
|
|
23091
23280
|
WebSocketProvider.prototype[Symbol.dispose] = WebSocketProvider.prototype.dispose;
|
|
23092
23281
|
}
|
|
23093
23282
|
|
|
23283
|
+
// src/provider/index.ts
|
|
23284
|
+
var Provider = RpcProvider;
|
|
23285
|
+
|
|
23094
23286
|
// src/signer/interface.ts
|
|
23095
23287
|
var SignerInterface = class {
|
|
23096
23288
|
};
|
|
@@ -23554,13 +23746,13 @@ ${indent}}` : "}";
|
|
|
23554
23746
|
*
|
|
23555
23747
|
* If you are using APP v2.2.1 with an account created with the v1.1.1, you need to use :
|
|
23556
23748
|
* ```typescript
|
|
23557
|
-
* const myLedgerSigner = new
|
|
23749
|
+
* const myLedgerSigner = new LedgerSigner221(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
|
|
23558
23750
|
* ```
|
|
23559
23751
|
* @example
|
|
23560
23752
|
* ```typescript
|
|
23561
23753
|
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
23562
23754
|
* const myNodeTransport = await TransportNodeHid.create();
|
|
23563
|
-
* const myLedgerSigner = new
|
|
23755
|
+
* const myLedgerSigner = new LedgerSigner221(myNodeTransport, 0);
|
|
23564
23756
|
* ```
|
|
23565
23757
|
*/
|
|
23566
23758
|
constructor(transport, accountID, eip2645application = "LedgerW", pathFunction = getLedgerPathBuffer221) {
|
|
@@ -24615,6 +24807,76 @@ ${indent}}` : "}";
|
|
|
24615
24807
|
var PaymasterInterface = class {
|
|
24616
24808
|
};
|
|
24617
24809
|
|
|
24810
|
+
// src/deployer/compileConstructorCalldata.ts
|
|
24811
|
+
function checkCompiledConstructorCalldata(calldata, abi) {
|
|
24812
|
+
const calldataClass = new CallData(abi);
|
|
24813
|
+
const constructorAbi = calldataClass.abi.find((entry) => entry.name === "constructor");
|
|
24814
|
+
if (!constructorAbi) {
|
|
24815
|
+
if (calldata.length > 0) {
|
|
24816
|
+
throw Error("Cannot pass calldata to a contract with no constructor");
|
|
24817
|
+
}
|
|
24818
|
+
return;
|
|
24819
|
+
}
|
|
24820
|
+
let index = 0;
|
|
24821
|
+
const felts = {
|
|
24822
|
+
next: () => {
|
|
24823
|
+
if (index >= calldata.length) {
|
|
24824
|
+
throw Error("it has fewer felts than the constructor takes");
|
|
24825
|
+
}
|
|
24826
|
+
index += 1;
|
|
24827
|
+
return { value: String(calldata[index - 1]), done: false };
|
|
24828
|
+
}
|
|
24829
|
+
};
|
|
24830
|
+
const parsed = {};
|
|
24831
|
+
try {
|
|
24832
|
+
constructorAbi.inputs.forEach((input) => {
|
|
24833
|
+
parsed[input.name] = calldataClass.parser.parseResponse(felts, input, parsed);
|
|
24834
|
+
});
|
|
24835
|
+
} catch (error) {
|
|
24836
|
+
throw Error(
|
|
24837
|
+
`The compiled constructor calldata does not match the abi: ${error.message}`
|
|
24838
|
+
);
|
|
24839
|
+
}
|
|
24840
|
+
const leftover = calldata.length - index;
|
|
24841
|
+
if (leftover > 0) {
|
|
24842
|
+
throw Error(
|
|
24843
|
+
`The compiled constructor calldata does not match the abi: it has ${leftover} felt${leftover > 1 ? "s" : ""} too many`
|
|
24844
|
+
);
|
|
24845
|
+
}
|
|
24846
|
+
let written;
|
|
24847
|
+
try {
|
|
24848
|
+
written = calldataClass.compile("constructor", parsed);
|
|
24849
|
+
} catch (error) {
|
|
24850
|
+
throw Error(
|
|
24851
|
+
`The compiled constructor calldata does not match the abi: ${error.message}`
|
|
24852
|
+
);
|
|
24853
|
+
}
|
|
24854
|
+
const sameFelts = written.length === calldata.length && written.every((felt2, i) => BigInt(felt2) === BigInt(calldata[i]));
|
|
24855
|
+
if (!sameFelts) {
|
|
24856
|
+
throw Error(
|
|
24857
|
+
"The compiled constructor calldata does not match the abi: the abi writes the values it holds with other felts"
|
|
24858
|
+
);
|
|
24859
|
+
}
|
|
24860
|
+
}
|
|
24861
|
+
function compileConstructorCalldata(constructorCalldata = [], abi) {
|
|
24862
|
+
let compiledHere = false;
|
|
24863
|
+
const calldata = getCompiledCalldata(constructorCalldata, () => {
|
|
24864
|
+
compiledHere = true;
|
|
24865
|
+
if (abi) {
|
|
24866
|
+
const calldataClass = new CallData(abi);
|
|
24867
|
+
if (Array.isArray(constructorCalldata)) {
|
|
24868
|
+
calldataClass.validate(ValidateType.DEPLOY, "constructor", constructorCalldata);
|
|
24869
|
+
}
|
|
24870
|
+
return calldataClass.compile("constructor", constructorCalldata);
|
|
24871
|
+
}
|
|
24872
|
+
return CallData.compile(constructorCalldata);
|
|
24873
|
+
});
|
|
24874
|
+
if (abi && !compiledHere) {
|
|
24875
|
+
checkCompiledConstructorCalldata(calldata, abi);
|
|
24876
|
+
}
|
|
24877
|
+
return calldata;
|
|
24878
|
+
}
|
|
24879
|
+
|
|
24618
24880
|
// src/deployer/default.ts
|
|
24619
24881
|
var Deployer = class {
|
|
24620
24882
|
address;
|
|
@@ -24633,16 +24895,7 @@ ${indent}}` : "}";
|
|
|
24633
24895
|
constructorCalldata = [],
|
|
24634
24896
|
abi
|
|
24635
24897
|
} = it;
|
|
24636
|
-
const compiledConstructorCallData =
|
|
24637
|
-
if (abi) {
|
|
24638
|
-
const calldataClass = new CallData(abi);
|
|
24639
|
-
if (Array.isArray(constructorCalldata)) {
|
|
24640
|
-
calldataClass.validate(ValidateType.DEPLOY, "constructor", constructorCalldata);
|
|
24641
|
-
}
|
|
24642
|
-
return calldataClass.compile("constructor", constructorCalldata);
|
|
24643
|
-
}
|
|
24644
|
-
return CallData.compile(constructorCalldata);
|
|
24645
|
-
});
|
|
24898
|
+
const compiledConstructorCallData = compileConstructorCalldata(constructorCalldata, abi);
|
|
24646
24899
|
const deploySalt = salt ?? randomFelt();
|
|
24647
24900
|
return {
|
|
24648
24901
|
call: {
|
|
@@ -24792,9 +25045,10 @@ ${indent}}` : "}";
|
|
|
24792
25045
|
classHash,
|
|
24793
25046
|
addressSalt = 0,
|
|
24794
25047
|
constructorCalldata = [],
|
|
24795
|
-
contractAddress
|
|
25048
|
+
contractAddress,
|
|
25049
|
+
abi
|
|
24796
25050
|
}, details = {}) {
|
|
24797
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
25051
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
24798
25052
|
const contractAddressFinal = contractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
24799
25053
|
const invocations = [
|
|
24800
25054
|
{
|
|
@@ -24971,6 +25225,9 @@ ${indent}}` : "}";
|
|
|
24971
25225
|
* First check if contract is already declared, if not declare it
|
|
24972
25226
|
* If contract already declared returned transaction_hash is ''.
|
|
24973
25227
|
* Method will pass even if contract is already declared
|
|
25228
|
+
*
|
|
25229
|
+
* A given `classHash` is used as is to look for the class on the node, without being checked
|
|
25230
|
+
* against `contract`, to save time.
|
|
24974
25231
|
* @param transactionsDetail (optional)
|
|
24975
25232
|
*/
|
|
24976
25233
|
async declareIfNot(payload, transactionsDetail = {}) {
|
|
@@ -25043,14 +25300,29 @@ ${indent}}` : "}";
|
|
|
25043
25300
|
);
|
|
25044
25301
|
}
|
|
25045
25302
|
async declareAndDeploy(payload, details = {}) {
|
|
25046
|
-
|
|
25047
|
-
|
|
25303
|
+
if (payload.abi) {
|
|
25304
|
+
logger.warn(
|
|
25305
|
+
'The "abi" field is ignored: the ABI is taken from "contract". This field will be removed in v12.'
|
|
25306
|
+
);
|
|
25307
|
+
}
|
|
25308
|
+
const abi = extractAbi(await parseContract(payload.contract));
|
|
25309
|
+
const constructorCalldata = compileConstructorCalldata(payload.constructorCalldata, abi);
|
|
25310
|
+
const classHash = computeContractClassHash(payload.contract);
|
|
25311
|
+
if (payload.classHash !== void 0 && payload.classHash !== null && toBigInt(payload.classHash) !== toBigInt(classHash)) {
|
|
25312
|
+
throw Error(
|
|
25313
|
+
`The given classHash ${payload.classHash} is not the class hash of "contract": ${classHash}`
|
|
25314
|
+
);
|
|
25315
|
+
}
|
|
25316
|
+
let declare = await this.declareIfNot({ ...payload, classHash }, details);
|
|
25317
|
+
const declarationSent = declare.transaction_hash !== "";
|
|
25318
|
+
if (declarationSent) {
|
|
25048
25319
|
const tx = await this.provider.waitForTransaction(declare.transaction_hash, details);
|
|
25049
25320
|
declare = { ...declare, ...tx };
|
|
25050
25321
|
}
|
|
25322
|
+
const deployDetails = declarationSent && details.nonce !== void 0 && details.nonce !== null ? { ...details, nonce: toBigInt(details.nonce) + 1n } : details;
|
|
25051
25323
|
const deploy = await this.deployContract(
|
|
25052
|
-
{ ...payload, classHash: declare.class_hash },
|
|
25053
|
-
|
|
25324
|
+
{ ...payload, classHash: declare.class_hash, constructorCalldata, abi: void 0 },
|
|
25325
|
+
deployDetails
|
|
25054
25326
|
);
|
|
25055
25327
|
return { declare: { ...declare }, deploy };
|
|
25056
25328
|
}
|
|
@@ -25059,9 +25331,10 @@ ${indent}}` : "}";
|
|
|
25059
25331
|
classHash,
|
|
25060
25332
|
constructorCalldata = [],
|
|
25061
25333
|
addressSalt = 0,
|
|
25062
|
-
contractAddress: providedContractAddress
|
|
25334
|
+
contractAddress: providedContractAddress,
|
|
25335
|
+
abi
|
|
25063
25336
|
}, details = {}) {
|
|
25064
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
25337
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
25065
25338
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
25066
25339
|
const detailsWithTip = await this.resolveDetailsWithTip(details);
|
|
25067
25340
|
const { resourceBounds: providedResourceBounds } = details;
|
|
@@ -25072,7 +25345,8 @@ ${indent}}` : "}";
|
|
|
25072
25345
|
classHash,
|
|
25073
25346
|
constructorCalldata,
|
|
25074
25347
|
addressSalt,
|
|
25075
|
-
contractAddress
|
|
25348
|
+
contractAddress,
|
|
25349
|
+
abi
|
|
25076
25350
|
},
|
|
25077
25351
|
detailsWithTip
|
|
25078
25352
|
);
|
|
@@ -25334,9 +25608,10 @@ ${indent}}` : "}";
|
|
|
25334
25608
|
classHash,
|
|
25335
25609
|
addressSalt = 0,
|
|
25336
25610
|
constructorCalldata = [],
|
|
25337
|
-
contractAddress: providedContractAddress
|
|
25611
|
+
contractAddress: providedContractAddress,
|
|
25612
|
+
abi
|
|
25338
25613
|
}, details) {
|
|
25339
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
25614
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
25340
25615
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
25341
25616
|
const signature = !details.skipValidate ? await this.signer.signDeployAccountTransaction({
|
|
25342
25617
|
...details,
|
|
@@ -26961,10 +27236,10 @@ ${indent}}` : "}";
|
|
|
26961
27236
|
const deployResult = await account.deployContract(
|
|
26962
27237
|
{
|
|
26963
27238
|
classHash,
|
|
26964
|
-
constructorCalldata: deployParams.constructorCalldata,
|
|
27239
|
+
constructorCalldata: parseRequest ? deployParams.constructorCalldata : compileConstructorCalldata(deployParams.constructorCalldata),
|
|
26965
27240
|
salt: deployParams.salt,
|
|
26966
27241
|
unique: deployParams.unique,
|
|
26967
|
-
abi
|
|
27242
|
+
abi
|
|
26968
27243
|
},
|
|
26969
27244
|
details
|
|
26970
27245
|
);
|
|
@@ -26972,17 +27247,12 @@ ${indent}}` : "}";
|
|
|
26972
27247
|
} else {
|
|
26973
27248
|
const declareParams = params;
|
|
26974
27249
|
const contract = await parseContract(declareParams.contract);
|
|
26975
|
-
abi =
|
|
27250
|
+
abi = extractAbi(contract);
|
|
27251
|
+
const constructorCalldata = parseRequest ? declareParams.constructorCalldata : compileConstructorCalldata(declareParams.constructorCalldata);
|
|
26976
27252
|
const {
|
|
26977
27253
|
declare: { class_hash },
|
|
26978
27254
|
deploy: { contract_address: deployed_address }
|
|
26979
|
-
} = await account.declareAndDeploy(
|
|
26980
|
-
{
|
|
26981
|
-
...declareParams,
|
|
26982
|
-
abi: parseRequest ? abi : void 0
|
|
26983
|
-
},
|
|
26984
|
-
details
|
|
26985
|
-
);
|
|
27255
|
+
} = await account.declareAndDeploy({ ...declareParams, constructorCalldata }, details);
|
|
26986
27256
|
classHash = class_hash.toString();
|
|
26987
27257
|
contract_address = deployed_address;
|
|
26988
27258
|
}
|