starknet 11.2.0 → 11.4.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/falcon/index.d.ts +352 -0
- package/dist/falcon/index.js +3736 -0
- package/dist/falcon/index.js.map +1 -0
- package/dist/falcon/index.mjs +3723 -0
- package/dist/falcon/index.mjs.map +1 -0
- package/dist/index.d.ts +89 -43
- package/dist/index.global.js +133 -35
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +133 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +133 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -2
package/dist/index.global.js
CHANGED
|
@@ -6604,6 +6604,9 @@ ${indent}}` : "}";
|
|
|
6604
6604
|
return BigInt(addHexPrefix(starknet_exports.keccak(utf8ToUint8Array(indentString)).toString(16)));
|
|
6605
6605
|
}
|
|
6606
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
|
+
}
|
|
6607
6610
|
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
6608
6611
|
const compiledClassVersion = utf8ToBigInt(CONTRACT_CLASS_VERSION);
|
|
6609
6612
|
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
@@ -17170,7 +17173,7 @@ ${indent}}` : "}";
|
|
|
17170
17173
|
return 0;
|
|
17171
17174
|
}
|
|
17172
17175
|
function isNoConstructorValid(method, argsCalldata, abiMethod) {
|
|
17173
|
-
return method === "constructor" && !abiMethod &&
|
|
17176
|
+
return method === "constructor" && !abiMethod && Object.keys(argsCalldata).length === 0;
|
|
17174
17177
|
}
|
|
17175
17178
|
|
|
17176
17179
|
// src/utils/calldata/propertyOrder.ts
|
|
@@ -17252,7 +17255,7 @@ ${indent}}` : "}";
|
|
|
17252
17255
|
enumerable: true,
|
|
17253
17256
|
value: value ?? unorderedObject2[abiParam.name]
|
|
17254
17257
|
});
|
|
17255
|
-
if (unorderedObject2[abiParam.name] ===
|
|
17258
|
+
if (unorderedObject2[abiParam.name] === void 0) {
|
|
17256
17259
|
if (isCairo1Type(abiParam.type) || !isLen(abiParam.name)) {
|
|
17257
17260
|
throw Error(`Your object needs a property with key : ${abiParam.name} .`);
|
|
17258
17261
|
}
|
|
@@ -17353,6 +17356,9 @@ ${indent}}` : "}";
|
|
|
17353
17356
|
if (isLen(abiParam.name) && !isCairo1Type(abiParam.type)) {
|
|
17354
17357
|
return orderedObject;
|
|
17355
17358
|
}
|
|
17359
|
+
if (unorderedObject[abiParam.name] === void 0) {
|
|
17360
|
+
throw Error(`Your object needs a property with key : ${abiParam.name} .`);
|
|
17361
|
+
}
|
|
17356
17362
|
setProperty(orderInput(unorderedObject[abiParam.name], abiParam.type));
|
|
17357
17363
|
return orderedObject;
|
|
17358
17364
|
}, {});
|
|
@@ -17360,6 +17366,11 @@ ${indent}}` : "}";
|
|
|
17360
17366
|
}
|
|
17361
17367
|
|
|
17362
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
|
+
}
|
|
17363
17374
|
var CallData = class _CallData {
|
|
17364
17375
|
abi;
|
|
17365
17376
|
parser;
|
|
@@ -17390,11 +17401,14 @@ ${indent}}` : "}";
|
|
|
17390
17401
|
);
|
|
17391
17402
|
}
|
|
17392
17403
|
const abiMethod = this.abi.find(
|
|
17393
|
-
(abi) => type === ValidateType.DEPLOY ? abi.name === method
|
|
17404
|
+
(abi) => type === ValidateType.DEPLOY ? abi.name === method : abi.name === method && abi.type === "function"
|
|
17394
17405
|
);
|
|
17395
17406
|
if (isNoConstructorValid(method, args, abiMethod)) {
|
|
17396
17407
|
return;
|
|
17397
17408
|
}
|
|
17409
|
+
if (!abiMethod) {
|
|
17410
|
+
throw methodNotInAbiError(method);
|
|
17411
|
+
}
|
|
17398
17412
|
const inputsLength = this.parser.methodInputsLength(abiMethod);
|
|
17399
17413
|
if (args.length !== inputsLength) {
|
|
17400
17414
|
throw Error(
|
|
@@ -17422,6 +17436,9 @@ ${indent}}` : "}";
|
|
|
17422
17436
|
if (isNoConstructorValid(method, argsCalldata, abiMethod)) {
|
|
17423
17437
|
return [];
|
|
17424
17438
|
}
|
|
17439
|
+
if (!abiMethod) {
|
|
17440
|
+
throw methodNotInAbiError(method);
|
|
17441
|
+
}
|
|
17425
17442
|
let args;
|
|
17426
17443
|
if (Array.isArray(argsCalldata)) {
|
|
17427
17444
|
args = argsCalldata;
|
|
@@ -18084,6 +18101,9 @@ ${indent}}` : "}";
|
|
|
18084
18101
|
});
|
|
18085
18102
|
}
|
|
18086
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
|
+
}
|
|
18087
18107
|
const result = { ...contract };
|
|
18088
18108
|
delete result.sierra_program_debug_info;
|
|
18089
18109
|
result.abi = formatSpaces(stringify2(contract.abi));
|
|
@@ -20882,7 +20902,7 @@ ${indent}}` : "}";
|
|
|
20882
20902
|
var WebSocketChannel = class {
|
|
20883
20903
|
/**
|
|
20884
20904
|
* The URL of the WebSocket RPC Node.
|
|
20885
|
-
* @example 'wss://starknet-
|
|
20905
|
+
* @example 'wss://your-starknet-node/rpc/v0_10'
|
|
20886
20906
|
*/
|
|
20887
20907
|
nodeUrl;
|
|
20888
20908
|
/** Carries the frames and owns the socket lifecycle. */
|
|
@@ -24787,6 +24807,76 @@ ${indent}}` : "}";
|
|
|
24787
24807
|
var PaymasterInterface = class {
|
|
24788
24808
|
};
|
|
24789
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
|
+
|
|
24790
24880
|
// src/deployer/default.ts
|
|
24791
24881
|
var Deployer = class {
|
|
24792
24882
|
address;
|
|
@@ -24805,16 +24895,7 @@ ${indent}}` : "}";
|
|
|
24805
24895
|
constructorCalldata = [],
|
|
24806
24896
|
abi
|
|
24807
24897
|
} = it;
|
|
24808
|
-
const compiledConstructorCallData =
|
|
24809
|
-
if (abi) {
|
|
24810
|
-
const calldataClass = new CallData(abi);
|
|
24811
|
-
if (Array.isArray(constructorCalldata)) {
|
|
24812
|
-
calldataClass.validate(ValidateType.DEPLOY, "constructor", constructorCalldata);
|
|
24813
|
-
}
|
|
24814
|
-
return calldataClass.compile("constructor", constructorCalldata);
|
|
24815
|
-
}
|
|
24816
|
-
return CallData.compile(constructorCalldata);
|
|
24817
|
-
});
|
|
24898
|
+
const compiledConstructorCallData = compileConstructorCalldata(constructorCalldata, abi);
|
|
24818
24899
|
const deploySalt = salt ?? randomFelt();
|
|
24819
24900
|
return {
|
|
24820
24901
|
call: {
|
|
@@ -24964,9 +25045,10 @@ ${indent}}` : "}";
|
|
|
24964
25045
|
classHash,
|
|
24965
25046
|
addressSalt = 0,
|
|
24966
25047
|
constructorCalldata = [],
|
|
24967
|
-
contractAddress
|
|
25048
|
+
contractAddress,
|
|
25049
|
+
abi
|
|
24968
25050
|
}, details = {}) {
|
|
24969
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
25051
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
24970
25052
|
const contractAddressFinal = contractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
24971
25053
|
const invocations = [
|
|
24972
25054
|
{
|
|
@@ -25143,6 +25225,9 @@ ${indent}}` : "}";
|
|
|
25143
25225
|
* First check if contract is already declared, if not declare it
|
|
25144
25226
|
* If contract already declared returned transaction_hash is ''.
|
|
25145
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.
|
|
25146
25231
|
* @param transactionsDetail (optional)
|
|
25147
25232
|
*/
|
|
25148
25233
|
async declareIfNot(payload, transactionsDetail = {}) {
|
|
@@ -25215,14 +25300,29 @@ ${indent}}` : "}";
|
|
|
25215
25300
|
);
|
|
25216
25301
|
}
|
|
25217
25302
|
async declareAndDeploy(payload, details = {}) {
|
|
25218
|
-
|
|
25219
|
-
|
|
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) {
|
|
25220
25319
|
const tx = await this.provider.waitForTransaction(declare.transaction_hash, details);
|
|
25221
25320
|
declare = { ...declare, ...tx };
|
|
25222
25321
|
}
|
|
25322
|
+
const deployDetails = declarationSent && details.nonce !== void 0 && details.nonce !== null ? { ...details, nonce: toBigInt(details.nonce) + 1n } : details;
|
|
25223
25323
|
const deploy = await this.deployContract(
|
|
25224
|
-
{ ...payload, classHash: declare.class_hash },
|
|
25225
|
-
|
|
25324
|
+
{ ...payload, classHash: declare.class_hash, constructorCalldata, abi: void 0 },
|
|
25325
|
+
deployDetails
|
|
25226
25326
|
);
|
|
25227
25327
|
return { declare: { ...declare }, deploy };
|
|
25228
25328
|
}
|
|
@@ -25231,9 +25331,10 @@ ${indent}}` : "}";
|
|
|
25231
25331
|
classHash,
|
|
25232
25332
|
constructorCalldata = [],
|
|
25233
25333
|
addressSalt = 0,
|
|
25234
|
-
contractAddress: providedContractAddress
|
|
25334
|
+
contractAddress: providedContractAddress,
|
|
25335
|
+
abi
|
|
25235
25336
|
}, details = {}) {
|
|
25236
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
25337
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
25237
25338
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
25238
25339
|
const detailsWithTip = await this.resolveDetailsWithTip(details);
|
|
25239
25340
|
const { resourceBounds: providedResourceBounds } = details;
|
|
@@ -25244,7 +25345,8 @@ ${indent}}` : "}";
|
|
|
25244
25345
|
classHash,
|
|
25245
25346
|
constructorCalldata,
|
|
25246
25347
|
addressSalt,
|
|
25247
|
-
contractAddress
|
|
25348
|
+
contractAddress,
|
|
25349
|
+
abi
|
|
25248
25350
|
},
|
|
25249
25351
|
detailsWithTip
|
|
25250
25352
|
);
|
|
@@ -25506,9 +25608,10 @@ ${indent}}` : "}";
|
|
|
25506
25608
|
classHash,
|
|
25507
25609
|
addressSalt = 0,
|
|
25508
25610
|
constructorCalldata = [],
|
|
25509
|
-
contractAddress: providedContractAddress
|
|
25611
|
+
contractAddress: providedContractAddress,
|
|
25612
|
+
abi
|
|
25510
25613
|
}, details) {
|
|
25511
|
-
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
25614
|
+
const compiledCalldata = abi ? compileConstructorCalldata(constructorCalldata, abi) : CallData.compile(constructorCalldata);
|
|
25512
25615
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
25513
25616
|
const signature = !details.skipValidate ? await this.signer.signDeployAccountTransaction({
|
|
25514
25617
|
...details,
|
|
@@ -27133,10 +27236,10 @@ ${indent}}` : "}";
|
|
|
27133
27236
|
const deployResult = await account.deployContract(
|
|
27134
27237
|
{
|
|
27135
27238
|
classHash,
|
|
27136
|
-
constructorCalldata: deployParams.constructorCalldata,
|
|
27239
|
+
constructorCalldata: parseRequest ? deployParams.constructorCalldata : compileConstructorCalldata(deployParams.constructorCalldata),
|
|
27137
27240
|
salt: deployParams.salt,
|
|
27138
27241
|
unique: deployParams.unique,
|
|
27139
|
-
abi
|
|
27242
|
+
abi
|
|
27140
27243
|
},
|
|
27141
27244
|
details
|
|
27142
27245
|
);
|
|
@@ -27144,17 +27247,12 @@ ${indent}}` : "}";
|
|
|
27144
27247
|
} else {
|
|
27145
27248
|
const declareParams = params;
|
|
27146
27249
|
const contract = await parseContract(declareParams.contract);
|
|
27147
|
-
abi =
|
|
27250
|
+
abi = extractAbi(contract);
|
|
27251
|
+
const constructorCalldata = parseRequest ? declareParams.constructorCalldata : compileConstructorCalldata(declareParams.constructorCalldata);
|
|
27148
27252
|
const {
|
|
27149
27253
|
declare: { class_hash },
|
|
27150
27254
|
deploy: { contract_address: deployed_address }
|
|
27151
|
-
} = await account.declareAndDeploy(
|
|
27152
|
-
{
|
|
27153
|
-
...declareParams,
|
|
27154
|
-
abi: parseRequest ? abi : void 0
|
|
27155
|
-
},
|
|
27156
|
-
details
|
|
27157
|
-
);
|
|
27255
|
+
} = await account.declareAndDeploy({ ...declareParams, constructorCalldata }, details);
|
|
27158
27256
|
classHash = class_hash.toString();
|
|
27159
27257
|
contract_address = deployed_address;
|
|
27160
27258
|
}
|