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.mjs CHANGED
@@ -6546,6 +6546,48 @@ var RpcChannel2 = class {
6546
6546
  }
6547
6547
  return txReceipt;
6548
6548
  }
6549
+ async fastWaitForTransaction(txHash, address, initNonceBN, options) {
6550
+ const initNonce = BigInt(initNonceBN);
6551
+ let retries = options?.retries ?? 50;
6552
+ const retryInterval = options?.retryInterval ?? 500;
6553
+ const errorStates = [RPCSPEC09.ETransactionExecutionStatus.REVERTED];
6554
+ const successStates = [
6555
+ RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L2,
6556
+ RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L1,
6557
+ RPCSPEC09.ETransactionFinalityStatus.PRE_CONFIRMED
6558
+ ];
6559
+ let txStatus;
6560
+ const start = (/* @__PURE__ */ new Date()).getTime();
6561
+ while (retries > 0) {
6562
+ await wait(retryInterval);
6563
+ txStatus = await this.getTransactionStatus(txHash);
6564
+ logger.info(
6565
+ `${retries} ${JSON.stringify(txStatus)} ${((/* @__PURE__ */ new Date()).getTime() - start) / 1e3}s.`
6566
+ );
6567
+ const executionStatus = txStatus.execution_status ?? "";
6568
+ const finalityStatus = txStatus.finality_status;
6569
+ if (errorStates.includes(executionStatus)) {
6570
+ const message = `${executionStatus}: ${finalityStatus}`;
6571
+ const error = new Error(message);
6572
+ error.response = txStatus;
6573
+ throw error;
6574
+ } else if (successStates.includes(finalityStatus)) {
6575
+ let currentNonce = initNonce;
6576
+ while (currentNonce === initNonce && retries > 0) {
6577
+ currentNonce = BigInt(await this.getNonceForAddress(address, BlockTag.PRE_CONFIRMED));
6578
+ logger.info(
6579
+ `${retries} Checking new nonce ${currentNonce} ${((/* @__PURE__ */ new Date()).getTime() - start) / 1e3}s.`
6580
+ );
6581
+ if (currentNonce !== initNonce) return true;
6582
+ await wait(retryInterval);
6583
+ retries -= 1;
6584
+ }
6585
+ return false;
6586
+ }
6587
+ retries -= 1;
6588
+ }
6589
+ return false;
6590
+ }
6549
6591
  getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
6550
6592
  const contract_address = toHex(contractAddress);
6551
6593
  const parsedKey = toStorageKey(key);
@@ -8393,6 +8435,31 @@ var RpcProvider = class {
8393
8435
  );
8394
8436
  return createTransactionReceipt(receiptWoHelper);
8395
8437
  }
8438
+ /**
8439
+ * Wait up until a new transaction is possible with same the account.
8440
+ * This method is fast, but Events and transaction report are not yet
8441
+ * available. Useful for gaming activity.
8442
+ * - only rpc 0.9 and onwards.
8443
+ * @param {BigNumberish} txHash - transaction hash
8444
+ * @param {string} address - address of the account
8445
+ * @param {BigNumberish} initNonce - initial nonce of the account (before the transaction).
8446
+ * @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.
8447
+ * @returns {Promise<boolean>} Returns true if the next transaction is possible,
8448
+ * false if the timeout has been reached,
8449
+ * throw an error in case of provider communication.
8450
+ */
8451
+ async fastWaitForTransaction(txHash, address, initNonce, options) {
8452
+ if (this.channel instanceof rpc_0_9_0_exports.RpcChannel) {
8453
+ const isSuccess = await this.channel.fastWaitForTransaction(
8454
+ txHash,
8455
+ address,
8456
+ initNonce,
8457
+ options
8458
+ );
8459
+ return isSuccess;
8460
+ }
8461
+ throw new Error("Unsupported channel type");
8462
+ }
8396
8463
  async getStorageAt(contractAddress, key, blockIdentifier) {
8397
8464
  return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
8398
8465
  }
@@ -8973,8 +9040,181 @@ var StarknetId = class _StarknetId {
8973
9040
  }
8974
9041
  };
8975
9042
 
9043
+ // src/provider/extensions/brotherId.ts
9044
+ function isBrotherDomain(domain) {
9045
+ return domain.endsWith(".brother");
9046
+ }
9047
+ function encodeBrotherDomain(domain) {
9048
+ const brotherName = domain.endsWith(".brother") ? domain.replace(".brother", "") : domain;
9049
+ return useEncoded(brotherName);
9050
+ }
9051
+ function decodeBrotherDomain(encoded) {
9052
+ const decoded = useDecoded([encoded]);
9053
+ if (decoded.endsWith(".stark")) {
9054
+ return decoded.replace(".stark", ".brother");
9055
+ }
9056
+ return decoded ? `${decoded}.brother` : decoded;
9057
+ }
9058
+ function getBrotherIdContract(chainId) {
9059
+ switch (chainId) {
9060
+ case _StarknetChainId.SN_MAIN:
9061
+ return "0x0212f1c57700f5a3913dd11efba540196aad4cf67772f7090c62709dd804fa74";
9062
+ default:
9063
+ return "0x0212f1c57700f5a3913dd11efba540196aad4cf67772f7090c62709dd804fa74";
9064
+ }
9065
+ }
9066
+ var BrotherId = class _BrotherId {
9067
+ /**
9068
+ * Gets the primary Brother domain name for an address
9069
+ * @param address - The address to get the domain for
9070
+ * @param BrotherIdContract - Optional contract address
9071
+ * @returns The domain name with .brother suffix
9072
+ */
9073
+ async getBrotherName(address, BrotherIdContract) {
9074
+ return _BrotherId.getBrotherName(
9075
+ // After Mixin, this is ProviderInterface
9076
+ this,
9077
+ address,
9078
+ BrotherIdContract
9079
+ );
9080
+ }
9081
+ /**
9082
+ * Gets the address associated with a Brother domain name
9083
+ * @param name - The domain name (with or without .brother suffix)
9084
+ * @param BrotherIdContract - Optional contract address
9085
+ * @returns The resolver address for the domain
9086
+ */
9087
+ async getAddressFromBrotherName(name, BrotherIdContract) {
9088
+ return _BrotherId.getAddressFromBrotherName(
9089
+ // After Mixin, this is ProviderInterface
9090
+ this,
9091
+ name,
9092
+ BrotherIdContract
9093
+ );
9094
+ }
9095
+ /**
9096
+ * Gets the complete profile information for a Brother domain
9097
+ * @param address - The address to get the profile for
9098
+ * @param BrotherIdContract - Optional contract address
9099
+ * @returns The complete Brother profile information
9100
+ */
9101
+ async getBrotherProfile(address, BrotherIdContract) {
9102
+ return _BrotherId.getBrotherProfile(
9103
+ // After Mixin, this is ProviderInterface
9104
+ this,
9105
+ address,
9106
+ BrotherIdContract
9107
+ );
9108
+ }
9109
+ /**
9110
+ * Static implementation of getBrotherName
9111
+ * @param provider - The provider interface
9112
+ * @param address - The address to get the domain for
9113
+ * @param BrotherIdContract - Optional contract address
9114
+ * @returns The domain name with .brother suffix
9115
+ */
9116
+ static async getBrotherName(provider, address, BrotherIdContract) {
9117
+ const chainId = await provider.getChainId();
9118
+ const contract = BrotherIdContract ?? getBrotherIdContract(chainId);
9119
+ try {
9120
+ const primaryDomain = await provider.callContract({
9121
+ contractAddress: contract,
9122
+ entrypoint: "getPrimary",
9123
+ calldata: CallData.compile({
9124
+ user: address
9125
+ })
9126
+ });
9127
+ if (!primaryDomain[0] || primaryDomain[0] === "0x0") {
9128
+ throw Error("Brother name not found");
9129
+ }
9130
+ const encodedDomain = BigInt(primaryDomain[0]);
9131
+ return decodeBrotherDomain(encodedDomain);
9132
+ } catch (e) {
9133
+ if (e instanceof Error && e.message === "Brother name not found") {
9134
+ throw e;
9135
+ }
9136
+ throw Error("Could not get brother name");
9137
+ }
9138
+ }
9139
+ /**
9140
+ * Static implementation of getAddressFromBrotherName
9141
+ * @param provider - The provider interface
9142
+ * @param name - The domain name
9143
+ * @param BrotherIdContract - Optional contract address
9144
+ * @returns The resolver address
9145
+ */
9146
+ static async getAddressFromBrotherName(provider, name, BrotherIdContract) {
9147
+ const brotherName = name.endsWith(".brother") ? name : `${name}.brother`;
9148
+ if (!isBrotherDomain(brotherName)) {
9149
+ throw new Error("Invalid domain, must be a valid .brother domain");
9150
+ }
9151
+ const chainId = await provider.getChainId();
9152
+ const contract = BrotherIdContract ?? getBrotherIdContract(chainId);
9153
+ try {
9154
+ const domainDetails = await provider.callContract({
9155
+ contractAddress: contract,
9156
+ entrypoint: "get_details_by_domain",
9157
+ calldata: CallData.compile({
9158
+ domain: encodeBrotherDomain(brotherName)
9159
+ })
9160
+ });
9161
+ if (!domainDetails[0] || domainDetails[1] === "0x0") {
9162
+ throw Error("Could not get address from brother name");
9163
+ }
9164
+ return domainDetails[1];
9165
+ } catch {
9166
+ throw Error("Could not get address from brother name");
9167
+ }
9168
+ }
9169
+ /**
9170
+ * Static implementation of getBrotherProfile
9171
+ * @param provider - The provider interface
9172
+ * @param address - The address to get the profile for
9173
+ * @param BrotherIdContract - Optional contract address
9174
+ * @returns The complete Brother profile
9175
+ */
9176
+ static async getBrotherProfile(provider, address, BrotherIdContract) {
9177
+ const chainId = await provider.getChainId();
9178
+ const contract = BrotherIdContract ?? getBrotherIdContract(chainId);
9179
+ try {
9180
+ const primaryDomain = await provider.callContract({
9181
+ contractAddress: contract,
9182
+ entrypoint: "getPrimary",
9183
+ calldata: CallData.compile({
9184
+ user: address
9185
+ })
9186
+ });
9187
+ if (!primaryDomain[0] || primaryDomain[0] === "0x0") {
9188
+ throw Error("Brother profile not found");
9189
+ }
9190
+ const encodedDomain = BigInt(primaryDomain[0]);
9191
+ const decodedDomain = decodeBrotherDomain(encodedDomain);
9192
+ const domain = decodedDomain.replace(".brother", "");
9193
+ const domainDetails = await provider.callContract({
9194
+ contractAddress: contract,
9195
+ entrypoint: "get_details_by_domain",
9196
+ calldata: CallData.compile({
9197
+ domain: encodeBrotherDomain(domain)
9198
+ })
9199
+ });
9200
+ return {
9201
+ name: domain,
9202
+ resolver: domainDetails[1],
9203
+ tokenId: domainDetails[2],
9204
+ expiryDate: parseInt(domainDetails[3], 16),
9205
+ lastTransferTime: parseInt(domainDetails[4], 16)
9206
+ };
9207
+ } catch (e) {
9208
+ if (e instanceof Error && e.message === "Brother profile not found") {
9209
+ throw e;
9210
+ }
9211
+ throw Error("Could not get brother profile");
9212
+ }
9213
+ }
9214
+ };
9215
+
8976
9216
  // src/provider/extensions/default.ts
8977
- var RpcProvider2 = class extends Mixin(RpcProvider, StarknetId) {
9217
+ var RpcProvider2 = class extends Mixin(RpcProvider, StarknetId, BrotherId) {
8978
9218
  };
8979
9219
 
8980
9220
  // src/provider/interface.ts
@@ -10800,6 +11040,50 @@ var Account = class extends RpcProvider2 {
10800
11040
  }
10801
11041
  );
10802
11042
  }
11043
+ /**
11044
+ * Execute one or multiple calls through the account contract,
11045
+ * responding as soon as a new transaction is possible with the same account.
11046
+ * Useful for gaming usage.
11047
+ * - This method requires the provider to be initialized with `pre_confirmed` blockIdentifier option.
11048
+ * - Rpc 0.9 minimum.
11049
+ * - 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.
11050
+ * - As a consequence of the previous point, do not use contract/account deployment with this method.
11051
+ * @param {AllowArray<Call>} transactions - Single call or array of calls to execute
11052
+ * @param {UniversalDetails} [transactionsDetail] - Transaction execution options
11053
+ * @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.
11054
+ * @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.
11055
+ * @example
11056
+ * ```typescript
11057
+ * const myProvider = new RpcProvider({ nodeUrl: url, blockIdentifier: BlockTag.PRE_CONFIRMED });
11058
+ * const myAccount = new Account({ provider: myProvider, address: accountAddress0, signer: privateKey0 });
11059
+ * const resp = await myAccount.fastExecute(
11060
+ * call, { tip: recommendedTip},
11061
+ * { retries: 30, retryInterval: 500 });
11062
+ * // if resp.isReady is true, you can launch immediately a new tx.
11063
+ * ```
11064
+ */
11065
+ async fastExecute(transactions, transactionsDetail = {}, waitDetail = {}) {
11066
+ assert(
11067
+ this.channel instanceof rpc_0_9_0_exports.RpcChannel,
11068
+ "Wrong Rpc version in Provider. At least Rpc v0.9 required."
11069
+ );
11070
+ assert(
11071
+ this.channel.blockIdentifier === BlockTag.PRE_CONFIRMED,
11072
+ "Provider needs to be initialized with `pre_confirmed` blockIdentifier option."
11073
+ );
11074
+ const initNonce = BigInt(
11075
+ transactionsDetail.nonce ?? await this.getNonceForAddress(this.address, BlockTag.PRE_CONFIRMED)
11076
+ );
11077
+ const details = { ...transactionsDetail, nonce: initNonce };
11078
+ const resultTx = await this.execute(transactions, details);
11079
+ const resultWait = await this.fastWaitForTransaction(
11080
+ resultTx.transaction_hash,
11081
+ this.address,
11082
+ initNonce,
11083
+ waitDetail
11084
+ );
11085
+ return { txResult: resultTx, isReady: resultWait };
11086
+ }
10803
11087
  /**
10804
11088
  * First check if contract is already declared, if not declare it
10805
11089
  * If contract already declared returned transaction_hash is ''.
@@ -12098,7 +12382,10 @@ export {
12098
12382
  BlockStatus,
12099
12383
  BlockTag,
12100
12384
  CairoByteArray,
12385
+ CairoBytes31,
12101
12386
  CairoCustomEnum,
12387
+ CairoFelt,
12388
+ CairoFelt252,
12102
12389
  CairoFixedArray,
12103
12390
  CairoInt128,
12104
12391
  CairoInt16,
@@ -12112,6 +12399,7 @@ export {
12112
12399
  CairoUint128,
12113
12400
  CairoUint16,
12114
12401
  CairoUint256,
12402
+ CairoUint32,
12115
12403
  CairoUint512,
12116
12404
  CairoUint64,
12117
12405
  CairoUint8,