starknet 8.3.1 → 8.5.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/dist/index.js CHANGED
@@ -40,7 +40,10 @@ __export(index_exports, {
40
40
  BlockStatus: () => BlockStatus,
41
41
  BlockTag: () => BlockTag,
42
42
  CairoByteArray: () => CairoByteArray,
43
+ CairoBytes31: () => CairoBytes31,
43
44
  CairoCustomEnum: () => CairoCustomEnum,
45
+ CairoFelt: () => CairoFelt,
46
+ CairoFelt252: () => CairoFelt252,
44
47
  CairoFixedArray: () => CairoFixedArray,
45
48
  CairoInt128: () => CairoInt128,
46
49
  CairoInt16: () => CairoInt16,
@@ -54,6 +57,7 @@ __export(index_exports, {
54
57
  CairoUint128: () => CairoUint128,
55
58
  CairoUint16: () => CairoUint16,
56
59
  CairoUint256: () => CairoUint256,
60
+ CairoUint32: () => CairoUint32,
57
61
  CairoUint512: () => CairoUint512,
58
62
  CairoUint64: () => CairoUint64,
59
63
  CairoUint8: () => CairoUint8,
@@ -6716,6 +6720,48 @@ var RpcChannel2 = class {
6716
6720
  }
6717
6721
  return txReceipt;
6718
6722
  }
6723
+ async fastWaitForTransaction(txHash, address, initNonceBN, options) {
6724
+ const initNonce = BigInt(initNonceBN);
6725
+ let retries = options?.retries ?? 50;
6726
+ const retryInterval = options?.retryInterval ?? 500;
6727
+ const errorStates = [RPCSPEC09.ETransactionExecutionStatus.REVERTED];
6728
+ const successStates = [
6729
+ RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L2,
6730
+ RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L1,
6731
+ RPCSPEC09.ETransactionFinalityStatus.PRE_CONFIRMED
6732
+ ];
6733
+ let txStatus;
6734
+ const start = (/* @__PURE__ */ new Date()).getTime();
6735
+ while (retries > 0) {
6736
+ await wait(retryInterval);
6737
+ txStatus = await this.getTransactionStatus(txHash);
6738
+ logger.info(
6739
+ `${retries} ${JSON.stringify(txStatus)} ${((/* @__PURE__ */ new Date()).getTime() - start) / 1e3}s.`
6740
+ );
6741
+ const executionStatus = txStatus.execution_status ?? "";
6742
+ const finalityStatus = txStatus.finality_status;
6743
+ if (errorStates.includes(executionStatus)) {
6744
+ const message = `${executionStatus}: ${finalityStatus}`;
6745
+ const error = new Error(message);
6746
+ error.response = txStatus;
6747
+ throw error;
6748
+ } else if (successStates.includes(finalityStatus)) {
6749
+ let currentNonce = initNonce;
6750
+ while (currentNonce === initNonce && retries > 0) {
6751
+ currentNonce = BigInt(await this.getNonceForAddress(address, BlockTag.PRE_CONFIRMED));
6752
+ logger.info(
6753
+ `${retries} Checking new nonce ${currentNonce} ${((/* @__PURE__ */ new Date()).getTime() - start) / 1e3}s.`
6754
+ );
6755
+ if (currentNonce !== initNonce) return true;
6756
+ await wait(retryInterval);
6757
+ retries -= 1;
6758
+ }
6759
+ return false;
6760
+ }
6761
+ retries -= 1;
6762
+ }
6763
+ return false;
6764
+ }
6719
6765
  getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
6720
6766
  const contract_address = toHex(contractAddress);
6721
6767
  const parsedKey = toStorageKey(key);
@@ -8563,6 +8609,31 @@ var RpcProvider = class {
8563
8609
  );
8564
8610
  return createTransactionReceipt(receiptWoHelper);
8565
8611
  }
8612
+ /**
8613
+ * Wait up until a new transaction is possible with same the account.
8614
+ * This method is fast, but Events and transaction report are not yet
8615
+ * available. Useful for gaming activity.
8616
+ * - only rpc 0.9 and onwards.
8617
+ * @param {BigNumberish} txHash - transaction hash
8618
+ * @param {string} address - address of the account
8619
+ * @param {BigNumberish} initNonce - initial nonce of the account (before the transaction).
8620
+ * @param {fastWaitForTransactionOptions} [options={retries: 50, retryInterval: 500}] - options to scan the network for the next possible transaction. `retries` is the number of times to retry.
8621
+ * @returns {Promise<boolean>} Returns true if the next transaction is possible,
8622
+ * false if the timeout has been reached,
8623
+ * throw an error in case of provider communication.
8624
+ */
8625
+ async fastWaitForTransaction(txHash, address, initNonce, options) {
8626
+ if (this.channel instanceof rpc_0_9_0_exports.RpcChannel) {
8627
+ const isSuccess = await this.channel.fastWaitForTransaction(
8628
+ txHash,
8629
+ address,
8630
+ initNonce,
8631
+ options
8632
+ );
8633
+ return isSuccess;
8634
+ }
8635
+ throw new Error("Unsupported channel type");
8636
+ }
8566
8637
  async getStorageAt(contractAddress, key, blockIdentifier) {
8567
8638
  return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
8568
8639
  }
@@ -9143,8 +9214,181 @@ var StarknetId = class _StarknetId {
9143
9214
  }
9144
9215
  };
9145
9216
 
9217
+ // src/provider/extensions/brotherId.ts
9218
+ function isBrotherDomain(domain) {
9219
+ return domain.endsWith(".brother");
9220
+ }
9221
+ function encodeBrotherDomain(domain) {
9222
+ const brotherName = domain.endsWith(".brother") ? domain.replace(".brother", "") : domain;
9223
+ return useEncoded(brotherName);
9224
+ }
9225
+ function decodeBrotherDomain(encoded) {
9226
+ const decoded = useDecoded([encoded]);
9227
+ if (decoded.endsWith(".stark")) {
9228
+ return decoded.replace(".stark", ".brother");
9229
+ }
9230
+ return decoded ? `${decoded}.brother` : decoded;
9231
+ }
9232
+ function getBrotherIdContract(chainId) {
9233
+ switch (chainId) {
9234
+ case _StarknetChainId.SN_MAIN:
9235
+ return "0x0212f1c57700f5a3913dd11efba540196aad4cf67772f7090c62709dd804fa74";
9236
+ default:
9237
+ return "0x0212f1c57700f5a3913dd11efba540196aad4cf67772f7090c62709dd804fa74";
9238
+ }
9239
+ }
9240
+ var BrotherId = class _BrotherId {
9241
+ /**
9242
+ * Gets the primary Brother domain name for an address
9243
+ * @param address - The address to get the domain for
9244
+ * @param BrotherIdContract - Optional contract address
9245
+ * @returns The domain name with .brother suffix
9246
+ */
9247
+ async getBrotherName(address, BrotherIdContract) {
9248
+ return _BrotherId.getBrotherName(
9249
+ // After Mixin, this is ProviderInterface
9250
+ this,
9251
+ address,
9252
+ BrotherIdContract
9253
+ );
9254
+ }
9255
+ /**
9256
+ * Gets the address associated with a Brother domain name
9257
+ * @param name - The domain name (with or without .brother suffix)
9258
+ * @param BrotherIdContract - Optional contract address
9259
+ * @returns The resolver address for the domain
9260
+ */
9261
+ async getAddressFromBrotherName(name, BrotherIdContract) {
9262
+ return _BrotherId.getAddressFromBrotherName(
9263
+ // After Mixin, this is ProviderInterface
9264
+ this,
9265
+ name,
9266
+ BrotherIdContract
9267
+ );
9268
+ }
9269
+ /**
9270
+ * Gets the complete profile information for a Brother domain
9271
+ * @param address - The address to get the profile for
9272
+ * @param BrotherIdContract - Optional contract address
9273
+ * @returns The complete Brother profile information
9274
+ */
9275
+ async getBrotherProfile(address, BrotherIdContract) {
9276
+ return _BrotherId.getBrotherProfile(
9277
+ // After Mixin, this is ProviderInterface
9278
+ this,
9279
+ address,
9280
+ BrotherIdContract
9281
+ );
9282
+ }
9283
+ /**
9284
+ * Static implementation of getBrotherName
9285
+ * @param provider - The provider interface
9286
+ * @param address - The address to get the domain for
9287
+ * @param BrotherIdContract - Optional contract address
9288
+ * @returns The domain name with .brother suffix
9289
+ */
9290
+ static async getBrotherName(provider, address, BrotherIdContract) {
9291
+ const chainId = await provider.getChainId();
9292
+ const contract = BrotherIdContract ?? getBrotherIdContract(chainId);
9293
+ try {
9294
+ const primaryDomain = await provider.callContract({
9295
+ contractAddress: contract,
9296
+ entrypoint: "getPrimary",
9297
+ calldata: CallData.compile({
9298
+ user: address
9299
+ })
9300
+ });
9301
+ if (!primaryDomain[0] || primaryDomain[0] === "0x0") {
9302
+ throw Error("Brother name not found");
9303
+ }
9304
+ const encodedDomain = BigInt(primaryDomain[0]);
9305
+ return decodeBrotherDomain(encodedDomain);
9306
+ } catch (e) {
9307
+ if (e instanceof Error && e.message === "Brother name not found") {
9308
+ throw e;
9309
+ }
9310
+ throw Error("Could not get brother name");
9311
+ }
9312
+ }
9313
+ /**
9314
+ * Static implementation of getAddressFromBrotherName
9315
+ * @param provider - The provider interface
9316
+ * @param name - The domain name
9317
+ * @param BrotherIdContract - Optional contract address
9318
+ * @returns The resolver address
9319
+ */
9320
+ static async getAddressFromBrotherName(provider, name, BrotherIdContract) {
9321
+ const brotherName = name.endsWith(".brother") ? name : `${name}.brother`;
9322
+ if (!isBrotherDomain(brotherName)) {
9323
+ throw new Error("Invalid domain, must be a valid .brother domain");
9324
+ }
9325
+ const chainId = await provider.getChainId();
9326
+ const contract = BrotherIdContract ?? getBrotherIdContract(chainId);
9327
+ try {
9328
+ const domainDetails = await provider.callContract({
9329
+ contractAddress: contract,
9330
+ entrypoint: "get_details_by_domain",
9331
+ calldata: CallData.compile({
9332
+ domain: encodeBrotherDomain(brotherName)
9333
+ })
9334
+ });
9335
+ if (!domainDetails[0] || domainDetails[1] === "0x0") {
9336
+ throw Error("Could not get address from brother name");
9337
+ }
9338
+ return domainDetails[1];
9339
+ } catch {
9340
+ throw Error("Could not get address from brother name");
9341
+ }
9342
+ }
9343
+ /**
9344
+ * Static implementation of getBrotherProfile
9345
+ * @param provider - The provider interface
9346
+ * @param address - The address to get the profile for
9347
+ * @param BrotherIdContract - Optional contract address
9348
+ * @returns The complete Brother profile
9349
+ */
9350
+ static async getBrotherProfile(provider, address, BrotherIdContract) {
9351
+ const chainId = await provider.getChainId();
9352
+ const contract = BrotherIdContract ?? getBrotherIdContract(chainId);
9353
+ try {
9354
+ const primaryDomain = await provider.callContract({
9355
+ contractAddress: contract,
9356
+ entrypoint: "getPrimary",
9357
+ calldata: CallData.compile({
9358
+ user: address
9359
+ })
9360
+ });
9361
+ if (!primaryDomain[0] || primaryDomain[0] === "0x0") {
9362
+ throw Error("Brother profile not found");
9363
+ }
9364
+ const encodedDomain = BigInt(primaryDomain[0]);
9365
+ const decodedDomain = decodeBrotherDomain(encodedDomain);
9366
+ const domain = decodedDomain.replace(".brother", "");
9367
+ const domainDetails = await provider.callContract({
9368
+ contractAddress: contract,
9369
+ entrypoint: "get_details_by_domain",
9370
+ calldata: CallData.compile({
9371
+ domain: encodeBrotherDomain(domain)
9372
+ })
9373
+ });
9374
+ return {
9375
+ name: domain,
9376
+ resolver: domainDetails[1],
9377
+ tokenId: domainDetails[2],
9378
+ expiryDate: parseInt(domainDetails[3], 16),
9379
+ lastTransferTime: parseInt(domainDetails[4], 16)
9380
+ };
9381
+ } catch (e) {
9382
+ if (e instanceof Error && e.message === "Brother profile not found") {
9383
+ throw e;
9384
+ }
9385
+ throw Error("Could not get brother profile");
9386
+ }
9387
+ }
9388
+ };
9389
+
9146
9390
  // src/provider/extensions/default.ts
9147
- var RpcProvider2 = class extends (0, import_ts_mixer.Mixin)(RpcProvider, StarknetId) {
9391
+ var RpcProvider2 = class extends (0, import_ts_mixer.Mixin)(RpcProvider, StarknetId, BrotherId) {
9148
9392
  };
9149
9393
 
9150
9394
  // src/provider/interface.ts
@@ -10970,6 +11214,50 @@ var Account = class extends RpcProvider2 {
10970
11214
  }
10971
11215
  );
10972
11216
  }
11217
+ /**
11218
+ * Execute one or multiple calls through the account contract,
11219
+ * responding as soon as a new transaction is possible with the same account.
11220
+ * Useful for gaming usage.
11221
+ * - This method requires the provider to be initialized with `pre_confirmed` blockIdentifier option.
11222
+ * - Rpc 0.9 minimum.
11223
+ * - In a normal myAccount.execute() call, followed by myProvider.waitForTransaction(), you have an immediate access to the events and to the transaction report. Here, we are processing consecutive transactions faster, but events & transaction reports are not available immediately.
11224
+ * - As a consequence of the previous point, do not use contract/account deployment with this method.
11225
+ * @param {AllowArray<Call>} transactions - Single call or array of calls to execute
11226
+ * @param {UniversalDetails} [transactionsDetail] - Transaction execution options
11227
+ * @param {fastWaitForTransactionOptions} [waitDetail={retries: 50, retryInterval: 500}] - options to scan the network for the next possible transaction. `retries` is the number of times to retry, `retryInterval` is the time in ms between retries.
11228
+ * @returns {Promise<fastExecuteResponse>} Response containing the transaction result and status for the next transaction. If `isReady` is true, you can execute the next transaction. If false, timeout has been reached before the next transaction was possible.
11229
+ * @example
11230
+ * ```typescript
11231
+ * const myProvider = new RpcProvider({ nodeUrl: url, blockIdentifier: BlockTag.PRE_CONFIRMED });
11232
+ * const myAccount = new Account({ provider: myProvider, address: accountAddress0, signer: privateKey0 });
11233
+ * const resp = await myAccount.fastExecute(
11234
+ * call, { tip: recommendedTip},
11235
+ * { retries: 30, retryInterval: 500 });
11236
+ * // if resp.isReady is true, you can launch immediately a new tx.
11237
+ * ```
11238
+ */
11239
+ async fastExecute(transactions, transactionsDetail = {}, waitDetail = {}) {
11240
+ assert(
11241
+ this.channel instanceof rpc_0_9_0_exports.RpcChannel,
11242
+ "Wrong Rpc version in Provider. At least Rpc v0.9 required."
11243
+ );
11244
+ assert(
11245
+ this.channel.blockIdentifier === BlockTag.PRE_CONFIRMED,
11246
+ "Provider needs to be initialized with `pre_confirmed` blockIdentifier option."
11247
+ );
11248
+ const initNonce = BigInt(
11249
+ transactionsDetail.nonce ?? await this.getNonceForAddress(this.address, BlockTag.PRE_CONFIRMED)
11250
+ );
11251
+ const details = { ...transactionsDetail, nonce: initNonce };
11252
+ const resultTx = await this.execute(transactions, details);
11253
+ const resultWait = await this.fastWaitForTransaction(
11254
+ resultTx.transaction_hash,
11255
+ this.address,
11256
+ initNonce,
11257
+ waitDetail
11258
+ );
11259
+ return { txResult: resultTx, isReady: resultWait };
11260
+ }
10973
11261
  /**
10974
11262
  * First check if contract is already declared, if not declare it
10975
11263
  * If contract already declared returned transaction_hash is ''.
@@ -12268,7 +12556,10 @@ function units(amount, simbol = "fri") {
12268
12556
  BlockStatus,
12269
12557
  BlockTag,
12270
12558
  CairoByteArray,
12559
+ CairoBytes31,
12271
12560
  CairoCustomEnum,
12561
+ CairoFelt,
12562
+ CairoFelt252,
12272
12563
  CairoFixedArray,
12273
12564
  CairoInt128,
12274
12565
  CairoInt16,
@@ -12282,6 +12573,7 @@ function units(amount, simbol = "fri") {
12282
12573
  CairoUint128,
12283
12574
  CairoUint16,
12284
12575
  CairoUint256,
12576
+ CairoUint32,
12285
12577
  CairoUint512,
12286
12578
  CairoUint64,
12287
12579
  CairoUint8,