starknet 8.7.0 → 8.9.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 +17 -0
- package/dist/index.d.ts +18 -5
- package/dist/index.global.js +58 -16
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +58 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -319,7 +319,7 @@ var DEFAULT_GLOBAL_CONFIG = {
|
|
|
319
319
|
blake: void 0
|
|
320
320
|
};
|
|
321
321
|
var RPC_DEFAULT_NODES = {
|
|
322
|
-
SN_MAIN: [`https://starknet-mainnet.g.alchemy.com/starknet/version/rpc
|
|
322
|
+
SN_MAIN: [`https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/`],
|
|
323
323
|
SN_SEPOLIA: [`https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/`]
|
|
324
324
|
};
|
|
325
325
|
var PAYMASTER_RPC_NODES = {
|
|
@@ -5233,8 +5233,8 @@ function computeContractClassHash(contract) {
|
|
|
5233
5233
|
}
|
|
5234
5234
|
return computeLegacyContractClassHash(compiledContract);
|
|
5235
5235
|
}
|
|
5236
|
-
function computeCompiledClassHash(casm,
|
|
5237
|
-
if (
|
|
5236
|
+
function computeCompiledClassHash(casm, starknetVersion) {
|
|
5237
|
+
if (starknetVersion && compareVersions(starknetVersion, "0.14.1") >= 0) {
|
|
5238
5238
|
return computeCompiledClassHashBlake(casm);
|
|
5239
5239
|
}
|
|
5240
5240
|
return computeCompiledClassHashPoseidon(casm);
|
|
@@ -5444,11 +5444,11 @@ function isSierra(contract) {
|
|
|
5444
5444
|
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
5445
5445
|
return "sierra_program" in compiledContract;
|
|
5446
5446
|
}
|
|
5447
|
-
function extractContractHashes(payload,
|
|
5447
|
+
function extractContractHashes(payload, starknetVersion) {
|
|
5448
5448
|
const response = { ...payload };
|
|
5449
5449
|
if (isSierra(payload.contract)) {
|
|
5450
5450
|
if (!payload.compiledClassHash && payload.casm) {
|
|
5451
|
-
response.compiledClassHash = computeCompiledClassHash(payload.casm,
|
|
5451
|
+
response.compiledClassHash = computeCompiledClassHash(payload.casm, starknetVersion);
|
|
5452
5452
|
}
|
|
5453
5453
|
if (!response.compiledClassHash)
|
|
5454
5454
|
throw new Error(
|
|
@@ -5920,6 +5920,14 @@ var RpcChannel = class {
|
|
|
5920
5920
|
block_id
|
|
5921
5921
|
});
|
|
5922
5922
|
}
|
|
5923
|
+
/**
|
|
5924
|
+
* Helper method to get the starknet version from the block, default latest block
|
|
5925
|
+
* @returns Starknet version
|
|
5926
|
+
*/
|
|
5927
|
+
async getStarknetVersion(blockIdentifier = this.blockIdentifier) {
|
|
5928
|
+
const block = await this.getBlockWithTxHashes(blockIdentifier);
|
|
5929
|
+
return block.starknet_version;
|
|
5930
|
+
}
|
|
5923
5931
|
/**
|
|
5924
5932
|
* Get the most recent accepted block hash and number
|
|
5925
5933
|
*/
|
|
@@ -6509,6 +6517,14 @@ var RpcChannel2 = class {
|
|
|
6509
6517
|
block_id
|
|
6510
6518
|
});
|
|
6511
6519
|
}
|
|
6520
|
+
/**
|
|
6521
|
+
* Helper method to get the starknet version from the block, default latest block
|
|
6522
|
+
* @returns Starknet version
|
|
6523
|
+
*/
|
|
6524
|
+
async getStarknetVersion(blockIdentifier = this.blockIdentifier) {
|
|
6525
|
+
const block = await this.getBlockWithTxHashes(blockIdentifier);
|
|
6526
|
+
return block.starknet_version;
|
|
6527
|
+
}
|
|
6512
6528
|
/**
|
|
6513
6529
|
* Get the most recent accepted block hash and number
|
|
6514
6530
|
*/
|
|
@@ -8448,6 +8464,9 @@ var RpcProvider = class {
|
|
|
8448
8464
|
setUpSpecVersion() {
|
|
8449
8465
|
return this.channel.setUpSpecVersion();
|
|
8450
8466
|
}
|
|
8467
|
+
async getStarknetVersion(blockIdentifier) {
|
|
8468
|
+
return this.channel.getStarknetVersion(blockIdentifier);
|
|
8469
|
+
}
|
|
8451
8470
|
async getNonceForAddress(contractAddress, blockIdentifier) {
|
|
8452
8471
|
return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
|
|
8453
8472
|
}
|
|
@@ -8687,7 +8706,7 @@ var RpcProvider = class {
|
|
|
8687
8706
|
if (!contractClassIdentifier.classHash && "contract" in contractClassIdentifier) {
|
|
8688
8707
|
const hashes = extractContractHashes(
|
|
8689
8708
|
contractClassIdentifier,
|
|
8690
|
-
await this.channel.
|
|
8709
|
+
await this.channel.getStarknetVersion()
|
|
8691
8710
|
);
|
|
8692
8711
|
classHash = hashes.classHash;
|
|
8693
8712
|
} else if (contractClassIdentifier.classHash) {
|
|
@@ -11061,7 +11080,7 @@ var Account = class extends RpcProvider2 {
|
|
|
11061
11080
|
const invocations = [
|
|
11062
11081
|
{
|
|
11063
11082
|
type: api_exports.ETransactionType.DECLARE,
|
|
11064
|
-
payload: extractContractHashes(payload, await this.channel.
|
|
11083
|
+
payload: extractContractHashes(payload, await this.channel.getStarknetVersion())
|
|
11065
11084
|
}
|
|
11066
11085
|
];
|
|
11067
11086
|
const estimateBulk = await this.estimateFeeBulk(invocations, details);
|
|
@@ -11227,7 +11246,7 @@ var Account = class extends RpcProvider2 {
|
|
|
11227
11246
|
async declareIfNot(payload, transactionsDetail = {}) {
|
|
11228
11247
|
const declareContractPayload = extractContractHashes(
|
|
11229
11248
|
payload,
|
|
11230
|
-
await this.channel.
|
|
11249
|
+
await this.channel.getStarknetVersion()
|
|
11231
11250
|
);
|
|
11232
11251
|
try {
|
|
11233
11252
|
await this.getClassByHash(declareContractPayload.classHash);
|
|
@@ -11243,7 +11262,7 @@ var Account = class extends RpcProvider2 {
|
|
|
11243
11262
|
assert(isSierra(payload.contract), SYSTEM_MESSAGES.declareNonSierra);
|
|
11244
11263
|
const declareContractPayload = extractContractHashes(
|
|
11245
11264
|
payload,
|
|
11246
|
-
await this.channel.
|
|
11265
|
+
await this.channel.getStarknetVersion()
|
|
11247
11266
|
);
|
|
11248
11267
|
const detailsWithTip = await this.resolveDetailsWithTip(details);
|
|
11249
11268
|
const { resourceBounds: providedResourceBounds } = details;
|
|
@@ -11553,7 +11572,7 @@ var Account = class extends RpcProvider2 {
|
|
|
11553
11572
|
async buildDeclarePayload(payload, details) {
|
|
11554
11573
|
const { classHash, contract, compiledClassHash } = extractContractHashes(
|
|
11555
11574
|
payload,
|
|
11556
|
-
await this.channel.
|
|
11575
|
+
await this.channel.getStarknetVersion()
|
|
11557
11576
|
);
|
|
11558
11577
|
const compressedCompiledContract = parseContract(contract);
|
|
11559
11578
|
assert(
|
|
@@ -11903,7 +11922,7 @@ var WalletAccount = class _WalletAccount extends Account {
|
|
|
11903
11922
|
async declare(payload) {
|
|
11904
11923
|
const declareContractPayload = extractContractHashes(
|
|
11905
11924
|
payload,
|
|
11906
|
-
await this.channel.
|
|
11925
|
+
await this.channel.getStarknetVersion()
|
|
11907
11926
|
);
|
|
11908
11927
|
const pContract = payload.contract;
|
|
11909
11928
|
const cairo1Contract = {
|
|
@@ -12245,7 +12264,7 @@ var Contract = class _Contract {
|
|
|
12245
12264
|
});
|
|
12246
12265
|
}
|
|
12247
12266
|
async invoke(method, args = [], options = {}) {
|
|
12248
|
-
const { parseRequest = true, signature, waitForTransaction, ...
|
|
12267
|
+
const { parseRequest = true, signature, waitForTransaction, ...restInvokeOptions } = options;
|
|
12249
12268
|
assert(this.address !== null, "contract is not connected to an address");
|
|
12250
12269
|
const calldata = getCompiledCalldata(args, () => {
|
|
12251
12270
|
if (parseRequest) {
|
|
@@ -12261,8 +12280,20 @@ var Contract = class _Contract {
|
|
|
12261
12280
|
entrypoint: method
|
|
12262
12281
|
};
|
|
12263
12282
|
if (isAccount(this.providerOrAccount)) {
|
|
12283
|
+
if (restInvokeOptions.paymasterDetails) {
|
|
12284
|
+
const myCall = {
|
|
12285
|
+
contractAddress: this.address,
|
|
12286
|
+
entrypoint: method,
|
|
12287
|
+
calldata: args
|
|
12288
|
+
};
|
|
12289
|
+
return this.providerOrAccount.executePaymasterTransaction(
|
|
12290
|
+
[myCall],
|
|
12291
|
+
restInvokeOptions.paymasterDetails,
|
|
12292
|
+
restInvokeOptions.maxFeeInGasToken
|
|
12293
|
+
);
|
|
12294
|
+
}
|
|
12264
12295
|
const result = await this.providerOrAccount.execute(invocation, {
|
|
12265
|
-
...
|
|
12296
|
+
...restInvokeOptions
|
|
12266
12297
|
});
|
|
12267
12298
|
if (waitForTransaction) {
|
|
12268
12299
|
const result2 = await this.providerOrAccount.waitForTransaction(result.transaction_hash);
|
|
@@ -12273,7 +12304,7 @@ var Contract = class _Contract {
|
|
|
12273
12304
|
}
|
|
12274
12305
|
return result;
|
|
12275
12306
|
}
|
|
12276
|
-
if (!
|
|
12307
|
+
if (!restInvokeOptions.nonce)
|
|
12277
12308
|
throw new Error(`Manual nonce is required when invoking a function without an account`);
|
|
12278
12309
|
logger.warn(`Invoking ${method} without an account.`);
|
|
12279
12310
|
return this.providerOrAccount.invokeFunction(
|
|
@@ -12282,8 +12313,8 @@ var Contract = class _Contract {
|
|
|
12282
12313
|
signature
|
|
12283
12314
|
},
|
|
12284
12315
|
{
|
|
12285
|
-
...
|
|
12286
|
-
nonce:
|
|
12316
|
+
...restInvokeOptions,
|
|
12317
|
+
nonce: restInvokeOptions.nonce
|
|
12287
12318
|
}
|
|
12288
12319
|
);
|
|
12289
12320
|
}
|
|
@@ -12294,6 +12325,17 @@ var Contract = class _Contract {
|
|
|
12294
12325
|
}
|
|
12295
12326
|
const invocation = this.populate(method, args);
|
|
12296
12327
|
if (isAccount(this.providerOrAccount)) {
|
|
12328
|
+
if (estimateDetails.paymasterDetails) {
|
|
12329
|
+
const myCall = {
|
|
12330
|
+
contractAddress: this.address,
|
|
12331
|
+
entrypoint: method,
|
|
12332
|
+
calldata: args
|
|
12333
|
+
};
|
|
12334
|
+
return this.providerOrAccount.estimatePaymasterTransactionFee(
|
|
12335
|
+
[myCall],
|
|
12336
|
+
estimateDetails.paymasterDetails
|
|
12337
|
+
);
|
|
12338
|
+
}
|
|
12297
12339
|
return this.providerOrAccount.estimateInvokeFee(invocation, estimateDetails);
|
|
12298
12340
|
}
|
|
12299
12341
|
throw Error("Contract must be connected to the account contract to estimate");
|