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.mjs
CHANGED
|
@@ -48,6 +48,7 @@ __export(constants_exports, {
|
|
|
48
48
|
RANGE_I32: () => RANGE_I32,
|
|
49
49
|
RANGE_I64: () => RANGE_I64,
|
|
50
50
|
RANGE_I8: () => RANGE_I8,
|
|
51
|
+
RANGE_STORAGE_ADDRESS: () => RANGE_STORAGE_ADDRESS,
|
|
51
52
|
RANGE_U128: () => RANGE_U128,
|
|
52
53
|
RANGE_U16: () => RANGE_U16,
|
|
53
54
|
RANGE_U32: () => RANGE_U32,
|
|
@@ -280,6 +281,7 @@ var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
|
280
281
|
var RANGE_ETH_ADDRESS = range(ZERO, 2n ** 160n - 1n);
|
|
281
282
|
var RANGE_CONTRACT_ADDRESS = range(ZERO, ADDR_BOUND - 1n);
|
|
282
283
|
var RANGE_CLASS_HASH = range(ZERO, 2n ** 251n - 1n);
|
|
284
|
+
var RANGE_STORAGE_ADDRESS = range(ZERO, 2n ** 251n - 1n);
|
|
283
285
|
var LegacyUDC = {
|
|
284
286
|
ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
|
|
285
287
|
ENTRYPOINT: "deployContract"
|
|
@@ -961,6 +963,7 @@ var Literal = {
|
|
|
961
963
|
ClassHash: "core::starknet::class_hash::ClassHash",
|
|
962
964
|
ContractAddress: "core::starknet::contract_address::ContractAddress",
|
|
963
965
|
Secp256k1Point: "core::starknet::secp256k1::Secp256k1Point",
|
|
966
|
+
StorageAddress: "core::starknet::storage_access::StorageAddress",
|
|
964
967
|
U96: "core::internal::bounded_int::BoundedInt::<0, 79228162514264337593543950335>"
|
|
965
968
|
};
|
|
966
969
|
var ETH_ADDRESS = "core::starknet::eth_address::EthAddress";
|
|
@@ -1454,6 +1457,9 @@ function hashAbi(sierra) {
|
|
|
1454
1457
|
return BigInt(addHexPrefix(starkCurve.keccak(utf8ToUint8Array(indentString)).toString(16)));
|
|
1455
1458
|
}
|
|
1456
1459
|
function computeSierraContractClassHash(sierra) {
|
|
1460
|
+
if (sierra.abi === void 0 || sierra.abi === null) {
|
|
1461
|
+
throw Error('Invalid Sierra contract: the "abi" field is missing');
|
|
1462
|
+
}
|
|
1457
1463
|
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
1458
1464
|
const compiledClassVersion = utf8ToBigInt(CONTRACT_CLASS_VERSION);
|
|
1459
1465
|
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
@@ -8074,6 +8080,169 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
8074
8080
|
}
|
|
8075
8081
|
};
|
|
8076
8082
|
|
|
8083
|
+
// src/utils/cairoDataTypes/storageAddress.ts
|
|
8084
|
+
var CairoStorageAddress = class _CairoStorageAddress {
|
|
8085
|
+
/**
|
|
8086
|
+
* The address, always as a bigint.
|
|
8087
|
+
* @example
|
|
8088
|
+
* ```typescript
|
|
8089
|
+
* const result = new CairoStorageAddress('0x1234').data;
|
|
8090
|
+
* // result = 4660n
|
|
8091
|
+
* ```
|
|
8092
|
+
*/
|
|
8093
|
+
data;
|
|
8094
|
+
/**
|
|
8095
|
+
* The abi type this class serializes.
|
|
8096
|
+
* @example
|
|
8097
|
+
* ```typescript
|
|
8098
|
+
* const result = CairoStorageAddress.abiSelector;
|
|
8099
|
+
* // result = "core::starknet::storage_access::StorageAddress"
|
|
8100
|
+
* ```
|
|
8101
|
+
*/
|
|
8102
|
+
static abiSelector = Literal.StorageAddress;
|
|
8103
|
+
/**
|
|
8104
|
+
* Build from a number or a numeric string, refusing text and anything outside the
|
|
8105
|
+
* StorageAddress range.
|
|
8106
|
+
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^251 - 1]
|
|
8107
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the StorageAddress range
|
|
8108
|
+
* @example
|
|
8109
|
+
* ```typescript
|
|
8110
|
+
* const result = new CairoStorageAddress('0x1234').toApiRequest();
|
|
8111
|
+
* // result = ["4660"]
|
|
8112
|
+
* ```
|
|
8113
|
+
*/
|
|
8114
|
+
constructor(data) {
|
|
8115
|
+
_CairoStorageAddress.validate(data);
|
|
8116
|
+
this.data = new CairoFelt252(data).toBigInt();
|
|
8117
|
+
}
|
|
8118
|
+
/**
|
|
8119
|
+
* Serialize to the single felt a contract call carries.
|
|
8120
|
+
* @returns {string[]} one decimal-string felt, flagged as compiled
|
|
8121
|
+
* @example
|
|
8122
|
+
* ```typescript
|
|
8123
|
+
* const result = new CairoStorageAddress('0x1234').toApiRequest();
|
|
8124
|
+
* // result = ["4660"]
|
|
8125
|
+
* ```
|
|
8126
|
+
*/
|
|
8127
|
+
toApiRequest() {
|
|
8128
|
+
return addCompiledFlag([this.toBigInt().toString()]);
|
|
8129
|
+
}
|
|
8130
|
+
/**
|
|
8131
|
+
* The address as a number.
|
|
8132
|
+
* @returns {bigint} the number this address holds
|
|
8133
|
+
* @example
|
|
8134
|
+
* ```typescript
|
|
8135
|
+
* const result = new CairoStorageAddress('0x1234').toBigInt();
|
|
8136
|
+
* // result = 4660n
|
|
8137
|
+
* ```
|
|
8138
|
+
*/
|
|
8139
|
+
toBigInt() {
|
|
8140
|
+
return this.data;
|
|
8141
|
+
}
|
|
8142
|
+
/**
|
|
8143
|
+
* The address in hexadecimal, without padding.
|
|
8144
|
+
*
|
|
8145
|
+
* Leading zeros are dropped, as they are everywhere else in the library.
|
|
8146
|
+
* @returns {string} the address as a 0x-prefixed hex string
|
|
8147
|
+
* @example
|
|
8148
|
+
* ```typescript
|
|
8149
|
+
* const result = new CairoStorageAddress(4660).toHexString();
|
|
8150
|
+
* // result = "0x1234"
|
|
8151
|
+
* const result2 = new CairoStorageAddress('0x0034').toHexString();
|
|
8152
|
+
* // result2 = "0x34" (four digits in, two out)
|
|
8153
|
+
* ```
|
|
8154
|
+
*/
|
|
8155
|
+
toHexString() {
|
|
8156
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
8157
|
+
}
|
|
8158
|
+
/**
|
|
8159
|
+
* Throw unless the value can be carried by a StorageAddress.
|
|
8160
|
+
*
|
|
8161
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
8162
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
8163
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
8164
|
+
* the range of the Cairo `StorageAddress` type, [0, 2^251), which is narrower than the field.
|
|
8165
|
+
* @param {BigNumberish | boolean} data the value to check
|
|
8166
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the StorageAddress range
|
|
8167
|
+
* @example
|
|
8168
|
+
* ```typescript
|
|
8169
|
+
* CairoStorageAddress.validate('0x1234'); // passes
|
|
8170
|
+
* CairoStorageAddress.validate('abc');
|
|
8171
|
+
* // throws Error("Invalid input: a StorageAddress cannot be built from text")
|
|
8172
|
+
* CairoStorageAddress.validate(2n ** 251n);
|
|
8173
|
+
* // throws Error("Value is out of StorageAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
8174
|
+
* CairoStorageAddress.validate(-1);
|
|
8175
|
+
* // throws Error("Value is out of StorageAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
8176
|
+
* ```
|
|
8177
|
+
*/
|
|
8178
|
+
static validate(data) {
|
|
8179
|
+
assert(!isText(data), "Invalid input: a StorageAddress cannot be built from text");
|
|
8180
|
+
assert(
|
|
8181
|
+
!isNumber(data) || Number.isInteger(data),
|
|
8182
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
8183
|
+
);
|
|
8184
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
8185
|
+
assert(
|
|
8186
|
+
value >= RANGE_STORAGE_ADDRESS.min && value <= RANGE_STORAGE_ADDRESS.max,
|
|
8187
|
+
`Value is out of StorageAddress range [${RANGE_STORAGE_ADDRESS.min}, ${RANGE_STORAGE_ADDRESS.max}]`
|
|
8188
|
+
);
|
|
8189
|
+
}
|
|
8190
|
+
/**
|
|
8191
|
+
* Can this value be carried by a StorageAddress?
|
|
8192
|
+
*
|
|
8193
|
+
* The non-throwing form of {@link CairoStorageAddress.validate}, so it answers false for every
|
|
8194
|
+
* input that one refuses, whatever the reason.
|
|
8195
|
+
* @param {BigNumberish | boolean} data the value to test
|
|
8196
|
+
* @returns {boolean} true when the value fits in a StorageAddress
|
|
8197
|
+
* @example
|
|
8198
|
+
* ```typescript
|
|
8199
|
+
* const result = CairoStorageAddress.is('0x1234');
|
|
8200
|
+
* // result = true
|
|
8201
|
+
* const result2 = CairoStorageAddress.is('abc');
|
|
8202
|
+
* // result2 = false (text, not a number)
|
|
8203
|
+
* ```
|
|
8204
|
+
*/
|
|
8205
|
+
static is(data) {
|
|
8206
|
+
try {
|
|
8207
|
+
_CairoStorageAddress.validate(data);
|
|
8208
|
+
return true;
|
|
8209
|
+
} catch {
|
|
8210
|
+
return false;
|
|
8211
|
+
}
|
|
8212
|
+
}
|
|
8213
|
+
/**
|
|
8214
|
+
* Is this abi type the one this class serializes?
|
|
8215
|
+
* @param {string} abiType the abi type to test
|
|
8216
|
+
* @returns {boolean} true for `core::starknet::storage_access::StorageAddress`
|
|
8217
|
+
* @example
|
|
8218
|
+
* ```typescript
|
|
8219
|
+
* const result = CairoStorageAddress.isAbiType(
|
|
8220
|
+
* 'core::starknet::storage_access::StorageAddress'
|
|
8221
|
+
* );
|
|
8222
|
+
* // result = true
|
|
8223
|
+
* const result2 = CairoStorageAddress.isAbiType('core::felt252');
|
|
8224
|
+
* // result2 = false
|
|
8225
|
+
* ```
|
|
8226
|
+
*/
|
|
8227
|
+
static isAbiType(abiType) {
|
|
8228
|
+
return abiType === _CairoStorageAddress.abiSelector;
|
|
8229
|
+
}
|
|
8230
|
+
/**
|
|
8231
|
+
* Read one StorageAddress off a contract response, advancing the iterator past it.
|
|
8232
|
+
* @param {Iterator<string>} responseIterator the response felts, positioned on this address
|
|
8233
|
+
* @returns {CairoStorageAddress} the address that was read
|
|
8234
|
+
* @example
|
|
8235
|
+
* ```typescript
|
|
8236
|
+
* const response = ['0x1234'];
|
|
8237
|
+
* const result = CairoStorageAddress.factoryFromApiResponse(response.values()).toBigInt();
|
|
8238
|
+
* // result = 4660n
|
|
8239
|
+
* ```
|
|
8240
|
+
*/
|
|
8241
|
+
static factoryFromApiResponse(responseIterator) {
|
|
8242
|
+
return new _CairoStorageAddress(getNext(responseIterator));
|
|
8243
|
+
}
|
|
8244
|
+
};
|
|
8245
|
+
|
|
8077
8246
|
// src/utils/cairoDataTypes/ethAddress.ts
|
|
8078
8247
|
var CairoEthAddress = class _CairoEthAddress {
|
|
8079
8248
|
/**
|
|
@@ -10480,6 +10649,7 @@ var LEAF_TYPES = [
|
|
|
10480
10649
|
CairoEthAddress,
|
|
10481
10650
|
CairoClassHash,
|
|
10482
10651
|
CairoContractAddress,
|
|
10652
|
+
CairoStorageAddress,
|
|
10483
10653
|
CairoBytes31,
|
|
10484
10654
|
CairoByteArray,
|
|
10485
10655
|
CairoSecp256k1Point,
|
|
@@ -10553,6 +10723,7 @@ var cairoTypeStrategy = {
|
|
|
10553
10723
|
[CairoEthAddress.abiSelector]: (instance) => instance.toBigInt(),
|
|
10554
10724
|
[CairoClassHash.abiSelector]: (instance) => instance.toBigInt(),
|
|
10555
10725
|
[CairoContractAddress.abiSelector]: (instance) => instance.toBigInt(),
|
|
10726
|
+
[CairoStorageAddress.abiSelector]: (instance) => instance.toBigInt(),
|
|
10556
10727
|
[CairoBytes31.abiSelector]: (instance) => instance.decodeUtf8(),
|
|
10557
10728
|
[CairoByteArray.abiSelector]: (instance) => instance.decodeUtf8(),
|
|
10558
10729
|
[CairoSecp256k1Point.abiSelector]: (instance) => instance.toBigInt(),
|
|
@@ -11370,7 +11541,7 @@ function getAbiVersion(abi) {
|
|
|
11370
11541
|
return 0;
|
|
11371
11542
|
}
|
|
11372
11543
|
function isNoConstructorValid(method, argsCalldata, abiMethod) {
|
|
11373
|
-
return method === "constructor" && !abiMethod &&
|
|
11544
|
+
return method === "constructor" && !abiMethod && Object.keys(argsCalldata).length === 0;
|
|
11374
11545
|
}
|
|
11375
11546
|
|
|
11376
11547
|
// src/utils/calldata/propertyOrder.ts
|
|
@@ -11452,7 +11623,7 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
11452
11623
|
enumerable: true,
|
|
11453
11624
|
value: value ?? unorderedObject2[abiParam.name]
|
|
11454
11625
|
});
|
|
11455
|
-
if (unorderedObject2[abiParam.name] ===
|
|
11626
|
+
if (unorderedObject2[abiParam.name] === void 0) {
|
|
11456
11627
|
if (isCairo1Type(abiParam.type) || !isLen(abiParam.name)) {
|
|
11457
11628
|
throw Error(`Your object needs a property with key : ${abiParam.name} .`);
|
|
11458
11629
|
}
|
|
@@ -11553,6 +11724,9 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
11553
11724
|
if (isLen(abiParam.name) && !isCairo1Type(abiParam.type)) {
|
|
11554
11725
|
return orderedObject;
|
|
11555
11726
|
}
|
|
11727
|
+
if (unorderedObject[abiParam.name] === void 0) {
|
|
11728
|
+
throw Error(`Your object needs a property with key : ${abiParam.name} .`);
|
|
11729
|
+
}
|
|
11556
11730
|
setProperty(orderInput(unorderedObject[abiParam.name], abiParam.type));
|
|
11557
11731
|
return orderedObject;
|
|
11558
11732
|
}, {});
|
|
@@ -11560,6 +11734,11 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
11560
11734
|
}
|
|
11561
11735
|
|
|
11562
11736
|
// src/utils/calldata/index.ts
|
|
11737
|
+
function methodNotInAbiError(method) {
|
|
11738
|
+
return Error(
|
|
11739
|
+
method === "constructor" ? "Cannot pass calldata to a contract with no constructor" : `Method "${method}" not found in abi`
|
|
11740
|
+
);
|
|
11741
|
+
}
|
|
11563
11742
|
var CallData = class _CallData {
|
|
11564
11743
|
abi;
|
|
11565
11744
|
parser;
|
|
@@ -11590,11 +11769,14 @@ var CallData = class _CallData {
|
|
|
11590
11769
|
);
|
|
11591
11770
|
}
|
|
11592
11771
|
const abiMethod = this.abi.find(
|
|
11593
|
-
(abi) => type === ValidateType.DEPLOY ? abi.name === method
|
|
11772
|
+
(abi) => type === ValidateType.DEPLOY ? abi.name === method : abi.name === method && abi.type === "function"
|
|
11594
11773
|
);
|
|
11595
11774
|
if (isNoConstructorValid(method, args, abiMethod)) {
|
|
11596
11775
|
return;
|
|
11597
11776
|
}
|
|
11777
|
+
if (!abiMethod) {
|
|
11778
|
+
throw methodNotInAbiError(method);
|
|
11779
|
+
}
|
|
11598
11780
|
const inputsLength = this.parser.methodInputsLength(abiMethod);
|
|
11599
11781
|
if (args.length !== inputsLength) {
|
|
11600
11782
|
throw Error(
|
|
@@ -11622,6 +11804,9 @@ var CallData = class _CallData {
|
|
|
11622
11804
|
if (isNoConstructorValid(method, argsCalldata, abiMethod)) {
|
|
11623
11805
|
return [];
|
|
11624
11806
|
}
|
|
11807
|
+
if (!abiMethod) {
|
|
11808
|
+
throw methodNotInAbiError(method);
|
|
11809
|
+
}
|
|
11625
11810
|
let args;
|
|
11626
11811
|
if (Array.isArray(argsCalldata)) {
|
|
11627
11812
|
args = argsCalldata;
|
|
@@ -12286,6 +12471,9 @@ function wait(delay) {
|
|
|
12286
12471
|
});
|
|
12287
12472
|
}
|
|
12288
12473
|
async function createSierraContractClass(contract) {
|
|
12474
|
+
if (contract.abi === void 0 || contract.abi === null) {
|
|
12475
|
+
throw Error('Invalid Sierra contract: the "abi" field is missing');
|
|
12476
|
+
}
|
|
12289
12477
|
const result = { ...contract };
|
|
12290
12478
|
delete result.sierra_program_debug_info;
|
|
12291
12479
|
result.abi = formatSpaces(stringify2(contract.abi));
|
|
@@ -14954,7 +15142,7 @@ var SubscriptionChannel4 = class extends SubscriptionChannel {
|
|
|
14954
15142
|
var WebSocketChannel = class {
|
|
14955
15143
|
/**
|
|
14956
15144
|
* The URL of the WebSocket RPC Node.
|
|
14957
|
-
* @example 'wss://starknet-
|
|
15145
|
+
* @example 'wss://your-starknet-node/rpc/v0_10'
|
|
14958
15146
|
*/
|
|
14959
15147
|
nodeUrl;
|
|
14960
15148
|
/** Carries the frames and owns the socket lifecycle. */
|
|
@@ -17332,6 +17520,9 @@ if (typeof Symbol.dispose !== "undefined") {
|
|
|
17332
17520
|
WebSocketProvider.prototype[Symbol.dispose] = WebSocketProvider.prototype.dispose;
|
|
17333
17521
|
}
|
|
17334
17522
|
|
|
17523
|
+
// src/provider/index.ts
|
|
17524
|
+
var Provider = RpcProvider;
|
|
17525
|
+
|
|
17335
17526
|
// src/signer/interface.ts
|
|
17336
17527
|
var SignerInterface = class {
|
|
17337
17528
|
};
|
|
@@ -17799,13 +17990,13 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
17799
17990
|
*
|
|
17800
17991
|
* If you are using APP v2.2.1 with an account created with the v1.1.1, you need to use :
|
|
17801
17992
|
* ```typescript
|
|
17802
|
-
* const myLedgerSigner = new
|
|
17993
|
+
* const myLedgerSigner = new LedgerSigner221(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
|
|
17803
17994
|
* ```
|
|
17804
17995
|
* @example
|
|
17805
17996
|
* ```typescript
|
|
17806
17997
|
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
17807
17998
|
* const myNodeTransport = await TransportNodeHid.create();
|
|
17808
|
-
* const myLedgerSigner = new
|
|
17999
|
+
* const myLedgerSigner = new LedgerSigner221(myNodeTransport, 0);
|
|
17809
18000
|
* ```
|
|
17810
18001
|
*/
|
|
17811
18002
|
constructor(transport, accountID, eip2645application = "LedgerW", pathFunction = getLedgerPathBuffer221) {
|
|
@@ -18860,6 +19051,76 @@ var PaymasterRpc = class _PaymasterRpc {
|
|
|
18860
19051
|
var PaymasterInterface = class {
|
|
18861
19052
|
};
|
|
18862
19053
|
|
|
19054
|
+
// src/deployer/compileConstructorCalldata.ts
|
|
19055
|
+
function checkCompiledConstructorCalldata(calldata, abi) {
|
|
19056
|
+
const calldataClass = new CallData(abi);
|
|
19057
|
+
const constructorAbi = calldataClass.abi.find((entry) => entry.name === "constructor");
|
|
19058
|
+
if (!constructorAbi) {
|
|
19059
|
+
if (calldata.length > 0) {
|
|
19060
|
+
throw Error("Cannot pass calldata to a contract with no constructor");
|
|
19061
|
+
}
|
|
19062
|
+
return;
|
|
19063
|
+
}
|
|
19064
|
+
let index = 0;
|
|
19065
|
+
const felts = {
|
|
19066
|
+
next: () => {
|
|
19067
|
+
if (index >= calldata.length) {
|
|
19068
|
+
throw Error("it has fewer felts than the constructor takes");
|
|
19069
|
+
}
|
|
19070
|
+
index += 1;
|
|
19071
|
+
return { value: String(calldata[index - 1]), done: false };
|
|
19072
|
+
}
|
|
19073
|
+
};
|
|
19074
|
+
const parsed = {};
|
|
19075
|
+
try {
|
|
19076
|
+
constructorAbi.inputs.forEach((input) => {
|
|
19077
|
+
parsed[input.name] = calldataClass.parser.parseResponse(felts, input, parsed);
|
|
19078
|
+
});
|
|
19079
|
+
} catch (error) {
|
|
19080
|
+
throw Error(
|
|
19081
|
+
`The compiled constructor calldata does not match the abi: ${error.message}`
|
|
19082
|
+
);
|
|
19083
|
+
}
|
|
19084
|
+
const leftover = calldata.length - index;
|
|
19085
|
+
if (leftover > 0) {
|
|
19086
|
+
throw Error(
|
|
19087
|
+
`The compiled constructor calldata does not match the abi: it has ${leftover} felt${leftover > 1 ? "s" : ""} too many`
|
|
19088
|
+
);
|
|
19089
|
+
}
|
|
19090
|
+
let written;
|
|
19091
|
+
try {
|
|
19092
|
+
written = calldataClass.compile("constructor", parsed);
|
|
19093
|
+
} catch (error) {
|
|
19094
|
+
throw Error(
|
|
19095
|
+
`The compiled constructor calldata does not match the abi: ${error.message}`
|
|
19096
|
+
);
|
|
19097
|
+
}
|
|
19098
|
+
const sameFelts = written.length === calldata.length && written.every((felt2, i) => BigInt(felt2) === BigInt(calldata[i]));
|
|
19099
|
+
if (!sameFelts) {
|
|
19100
|
+
throw Error(
|
|
19101
|
+
"The compiled constructor calldata does not match the abi: the abi writes the values it holds with other felts"
|
|
19102
|
+
);
|
|
19103
|
+
}
|
|
19104
|
+
}
|
|
19105
|
+
function compileConstructorCalldata(constructorCalldata = [], abi) {
|
|
19106
|
+
let compiledHere = false;
|
|
19107
|
+
const calldata = getCompiledCalldata(constructorCalldata, () => {
|
|
19108
|
+
compiledHere = true;
|
|
19109
|
+
if (abi) {
|
|
19110
|
+
const calldataClass = new CallData(abi);
|
|
19111
|
+
if (Array.isArray(constructorCalldata)) {
|
|
19112
|
+
calldataClass.validate(ValidateType.DEPLOY, "constructor", constructorCalldata);
|
|
19113
|
+
}
|
|
19114
|
+
return calldataClass.compile("constructor", constructorCalldata);
|
|
19115
|
+
}
|
|
19116
|
+
return CallData.compile(constructorCalldata);
|
|
19117
|
+
});
|
|
19118
|
+
if (abi && !compiledHere) {
|
|
19119
|
+
checkCompiledConstructorCalldata(calldata, abi);
|
|
19120
|
+
}
|
|
19121
|
+
return calldata;
|
|
19122
|
+
}
|
|
19123
|
+
|
|
18863
19124
|
// src/deployer/default.ts
|
|
18864
19125
|
var Deployer = class {
|
|
18865
19126
|
address;
|
|
@@ -18878,16 +19139,7 @@ var Deployer = class {
|
|
|
18878
19139
|
constructorCalldata = [],
|
|
18879
19140
|
abi
|
|
18880
19141
|
} = it;
|
|
18881
|
-
const compiledConstructorCallData =
|
|
18882
|
-
if (abi) {
|
|
18883
|
-
const calldataClass = new CallData(abi);
|
|
18884
|
-
if (Array.isArray(constructorCalldata)) {
|
|
18885
|
-
calldataClass.validate(ValidateType.DEPLOY, "constructor", constructorCalldata);
|
|
18886
|
-
}
|
|
18887
|
-
return calldataClass.compile("constructor", constructorCalldata);
|
|
18888
|
-
}
|
|
18889
|
-
return CallData.compile(constructorCalldata);
|
|
18890
|
-
});
|
|
19142
|
+
const compiledConstructorCallData = compileConstructorCalldata(constructorCalldata, abi);
|
|
18891
19143
|
const deploySalt = salt ?? randomFelt();
|
|
18892
19144
|
return {
|
|
18893
19145
|
call: {
|
|
@@ -19037,9 +19289,10 @@ var Account = class {
|
|
|
19037
19289
|
classHash,
|
|
19038
19290
|
addressSalt = 0,
|
|
19039
19291
|
constructorCalldata = [],
|
|
19040
|
-
contractAddress
|
|
19292
|
+
contractAddress,
|
|
19293
|
+
abi
|
|
19041
19294
|
}, details = {}) {
|
|
19042
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
19295
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
19043
19296
|
const contractAddressFinal = contractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
19044
19297
|
const invocations = [
|
|
19045
19298
|
{
|
|
@@ -19216,6 +19469,9 @@ var Account = class {
|
|
|
19216
19469
|
* First check if contract is already declared, if not declare it
|
|
19217
19470
|
* If contract already declared returned transaction_hash is ''.
|
|
19218
19471
|
* Method will pass even if contract is already declared
|
|
19472
|
+
*
|
|
19473
|
+
* A given `classHash` is used as is to look for the class on the node, without being checked
|
|
19474
|
+
* against `contract`, to save time.
|
|
19219
19475
|
* @param transactionsDetail (optional)
|
|
19220
19476
|
*/
|
|
19221
19477
|
async declareIfNot(payload, transactionsDetail = {}) {
|
|
@@ -19288,14 +19544,29 @@ var Account = class {
|
|
|
19288
19544
|
);
|
|
19289
19545
|
}
|
|
19290
19546
|
async declareAndDeploy(payload, details = {}) {
|
|
19291
|
-
|
|
19292
|
-
|
|
19547
|
+
if (payload.abi) {
|
|
19548
|
+
logger.warn(
|
|
19549
|
+
'The "abi" field is ignored: the ABI is taken from "contract". This field will be removed in v12.'
|
|
19550
|
+
);
|
|
19551
|
+
}
|
|
19552
|
+
const abi = extractAbi(await parseContract(payload.contract));
|
|
19553
|
+
const constructorCalldata = compileConstructorCalldata(payload.constructorCalldata, abi);
|
|
19554
|
+
const classHash = computeContractClassHash(payload.contract);
|
|
19555
|
+
if (payload.classHash !== void 0 && payload.classHash !== null && toBigInt(payload.classHash) !== toBigInt(classHash)) {
|
|
19556
|
+
throw Error(
|
|
19557
|
+
`The given classHash ${payload.classHash} is not the class hash of "contract": ${classHash}`
|
|
19558
|
+
);
|
|
19559
|
+
}
|
|
19560
|
+
let declare = await this.declareIfNot({ ...payload, classHash }, details);
|
|
19561
|
+
const declarationSent = declare.transaction_hash !== "";
|
|
19562
|
+
if (declarationSent) {
|
|
19293
19563
|
const tx = await this.provider.waitForTransaction(declare.transaction_hash, details);
|
|
19294
19564
|
declare = { ...declare, ...tx };
|
|
19295
19565
|
}
|
|
19566
|
+
const deployDetails = declarationSent && details.nonce !== void 0 && details.nonce !== null ? { ...details, nonce: toBigInt(details.nonce) + 1n } : details;
|
|
19296
19567
|
const deploy = await this.deployContract(
|
|
19297
|
-
{ ...payload, classHash: declare.class_hash },
|
|
19298
|
-
|
|
19568
|
+
{ ...payload, classHash: declare.class_hash, constructorCalldata, abi: void 0 },
|
|
19569
|
+
deployDetails
|
|
19299
19570
|
);
|
|
19300
19571
|
return { declare: { ...declare }, deploy };
|
|
19301
19572
|
}
|
|
@@ -19304,9 +19575,10 @@ var Account = class {
|
|
|
19304
19575
|
classHash,
|
|
19305
19576
|
constructorCalldata = [],
|
|
19306
19577
|
addressSalt = 0,
|
|
19307
|
-
contractAddress: providedContractAddress
|
|
19578
|
+
contractAddress: providedContractAddress,
|
|
19579
|
+
abi
|
|
19308
19580
|
}, details = {}) {
|
|
19309
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
19581
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
19310
19582
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
19311
19583
|
const detailsWithTip = await this.resolveDetailsWithTip(details);
|
|
19312
19584
|
const { resourceBounds: providedResourceBounds } = details;
|
|
@@ -19317,7 +19589,8 @@ var Account = class {
|
|
|
19317
19589
|
classHash,
|
|
19318
19590
|
constructorCalldata,
|
|
19319
19591
|
addressSalt,
|
|
19320
|
-
contractAddress
|
|
19592
|
+
contractAddress,
|
|
19593
|
+
abi
|
|
19321
19594
|
},
|
|
19322
19595
|
detailsWithTip
|
|
19323
19596
|
);
|
|
@@ -19579,9 +19852,10 @@ var Account = class {
|
|
|
19579
19852
|
classHash,
|
|
19580
19853
|
addressSalt = 0,
|
|
19581
19854
|
constructorCalldata = [],
|
|
19582
|
-
contractAddress: providedContractAddress
|
|
19855
|
+
contractAddress: providedContractAddress,
|
|
19856
|
+
abi
|
|
19583
19857
|
}, details) {
|
|
19584
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
19858
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
19585
19859
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
19586
19860
|
const signature = !details.skipValidate ? await this.signer.signDeployAccountTransaction({
|
|
19587
19861
|
...details,
|
|
@@ -21206,10 +21480,10 @@ var Contract = class _Contract {
|
|
|
21206
21480
|
const deployResult = await account.deployContract(
|
|
21207
21481
|
{
|
|
21208
21482
|
classHash,
|
|
21209
|
-
constructorCalldata: deployParams.constructorCalldata,
|
|
21483
|
+
constructorCalldata: parseRequest ? deployParams.constructorCalldata : compileConstructorCalldata(deployParams.constructorCalldata),
|
|
21210
21484
|
salt: deployParams.salt,
|
|
21211
21485
|
unique: deployParams.unique,
|
|
21212
|
-
abi
|
|
21486
|
+
abi
|
|
21213
21487
|
},
|
|
21214
21488
|
details
|
|
21215
21489
|
);
|
|
@@ -21217,17 +21491,12 @@ var Contract = class _Contract {
|
|
|
21217
21491
|
} else {
|
|
21218
21492
|
const declareParams = params;
|
|
21219
21493
|
const contract = await parseContract(declareParams.contract);
|
|
21220
|
-
abi =
|
|
21494
|
+
abi = extractAbi(contract);
|
|
21495
|
+
const constructorCalldata = parseRequest ? declareParams.constructorCalldata : compileConstructorCalldata(declareParams.constructorCalldata);
|
|
21221
21496
|
const {
|
|
21222
21497
|
declare: { class_hash },
|
|
21223
21498
|
deploy: { contract_address: deployed_address }
|
|
21224
|
-
} = await account.declareAndDeploy(
|
|
21225
|
-
{
|
|
21226
|
-
...declareParams,
|
|
21227
|
-
abi: parseRequest ? abi : void 0
|
|
21228
|
-
},
|
|
21229
|
-
details
|
|
21230
|
-
);
|
|
21499
|
+
} = await account.declareAndDeploy({ ...declareParams, constructorCalldata }, details);
|
|
21231
21500
|
classHash = class_hash.toString();
|
|
21232
21501
|
contract_address = deployed_address;
|
|
21233
21502
|
}
|
|
@@ -21322,6 +21591,7 @@ export {
|
|
|
21322
21591
|
CairoResult,
|
|
21323
21592
|
CairoResultVariant,
|
|
21324
21593
|
CairoSecp256k1Point,
|
|
21594
|
+
CairoStorageAddress,
|
|
21325
21595
|
CairoStruct,
|
|
21326
21596
|
CairoTuple,
|
|
21327
21597
|
CairoTypeCustomEnum,
|
|
@@ -21368,7 +21638,7 @@ export {
|
|
|
21368
21638
|
PaymasterInterface,
|
|
21369
21639
|
PaymasterRpc,
|
|
21370
21640
|
PluginManager,
|
|
21371
|
-
|
|
21641
|
+
Provider,
|
|
21372
21642
|
ProviderInterface,
|
|
21373
21643
|
api_exports as RPC,
|
|
21374
21644
|
v0_10_2_exports as RPC0102,
|