starknet 4.13.2 → 4.14.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/CODE_OF_CONDUCT.md +128 -0
  3. package/README.md +2 -2
  4. package/__tests__/account.test.ts +38 -14
  5. package/__tests__/contract.test.ts +70 -57
  6. package/__tests__/defaultProvider.test.ts +14 -13
  7. package/__tests__/fixtures.ts +26 -27
  8. package/__tests__/rpcProvider.test.ts +19 -16
  9. package/__tests__/sequencerProvider.test.ts +47 -55
  10. package/__tests__/utils/utils.test.ts +10 -0
  11. package/dist/index.d.ts +112 -28
  12. package/dist/index.global.js +511 -453
  13. package/dist/index.global.js.map +1 -1
  14. package/dist/index.js +107 -49
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +107 -49
  17. package/dist/index.mjs.map +1 -1
  18. package/index.d.ts +112 -28
  19. package/index.global.js +511 -453
  20. package/index.global.js.map +1 -1
  21. package/index.js +107 -49
  22. package/index.js.map +1 -1
  23. package/index.mjs +107 -49
  24. package/index.mjs.map +1 -1
  25. package/package.json +2 -2
  26. package/src/account/default.ts +29 -7
  27. package/src/account/interface.ts +71 -5
  28. package/src/contract/contractFactory.ts +20 -13
  29. package/src/contract/default.ts +10 -1
  30. package/src/provider/default.ts +26 -11
  31. package/src/provider/interface.ts +9 -3
  32. package/src/provider/rpc.ts +15 -11
  33. package/src/provider/sequencer.ts +11 -6
  34. package/src/provider/utils.ts +19 -11
  35. package/src/types/account.ts +21 -1
  36. package/src/types/lib.ts +5 -2
  37. package/src/types/provider.ts +0 -5
  38. package/src/utils/events.ts +32 -0
  39. package/src/utils/number.ts +6 -0
  40. package/www/docs/API/account.md +156 -2
  41. package/www/docs/API/contractFactory.md +7 -11
  42. package/www/docs/API/provider.md +5 -9
  43. package/www/docs/API/utils.md +8 -0
  44. package/www/guides/account.md +89 -38
  45. package/www/guides/erc20.md +115 -59
  46. package/www/guides/intro.md +11 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "4.13.2",
3
+ "version": "4.14.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -21,7 +21,7 @@
21
21
  "build:iife": "tsup --clean false --format iife --platform browser",
22
22
  "build:dts": "tsup --clean false --dts-only",
23
23
  "pretest": "npm run lint",
24
- "test": "jest",
24
+ "test": "jest -i",
25
25
  "posttest": "npm run format",
26
26
  "test:watch": "jest --watch",
27
27
  "docs": "cd www && npm run start",
@@ -9,8 +9,10 @@ import {
9
9
  Call,
10
10
  DeclareContractPayload,
11
11
  DeclareContractResponse,
12
+ DeclareDeployContractPayload,
12
13
  DeployAccountContractPayload,
13
14
  DeployContractResponse,
15
+ DeployContractUDCResponse,
14
16
  EstimateFee,
15
17
  EstimateFeeAction,
16
18
  EstimateFeeDetails,
@@ -21,6 +23,7 @@ import {
21
23
  Signature,
22
24
  UniversalDeployerContractPayload,
23
25
  } from '../types';
26
+ import { parseUDCEvent } from '../utils/events';
24
27
  import {
25
28
  calculateContractAddressFromHash,
26
29
  feeTransactionVersion,
@@ -28,7 +31,7 @@ import {
28
31
  } from '../utils/hash';
29
32
  import { BigNumberish, toBN, toCairoBool } from '../utils/number';
30
33
  import { parseContract } from '../utils/provider';
31
- import { compileCalldata, estimatedFeeToMaxFee } from '../utils/stark';
34
+ import { compileCalldata, estimatedFeeToMaxFee, randomAddress } from '../utils/stark';
32
35
  import { fromCallsToExecuteCalldata } from '../utils/transaction';
33
36
  import { TypedData, getMessageHash } from '../utils/typedData';
34
37
  import { AccountInterface } from './interface';
@@ -50,7 +53,7 @@ export class Account extends Provider implements AccountInterface {
50
53
  }
51
54
 
52
55
  public async getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish> {
53
- return super.getNonce(this.address, blockIdentifier);
56
+ return super.getNonceForAddress(this.address, blockIdentifier);
54
57
  }
55
58
 
56
59
  public async estimateFee(
@@ -168,7 +171,7 @@ export class Account extends Provider implements AccountInterface {
168
171
  public async estimateDeployFee(
169
172
  {
170
173
  classHash,
171
- salt,
174
+ salt = '0',
172
175
  unique = true,
173
176
  constructorCalldata = [],
174
177
  additionalCalls = [],
@@ -276,11 +279,11 @@ export class Account extends Provider implements AccountInterface {
276
279
  constructorCalldata = [],
277
280
  additionalCalls = [],
278
281
  }: UniversalDeployerContractPayload,
279
- transactionsDetail: InvocationsDetails = {}
282
+ invocationsDetails: InvocationsDetails = {}
280
283
  ): Promise<InvokeFunctionResponse> {
281
284
  const compiledConstructorCallData = compileCalldata(constructorCalldata);
282
-
283
285
  const callsArray = Array.isArray(additionalCalls) ? additionalCalls : [additionalCalls];
286
+ const deploySalt = salt ?? randomAddress();
284
287
 
285
288
  return this.execute(
286
289
  [
@@ -289,7 +292,7 @@ export class Account extends Provider implements AccountInterface {
289
292
  entrypoint: UDC.ENTRYPOINT,
290
293
  calldata: [
291
294
  classHash,
292
- salt,
295
+ deploySalt,
293
296
  toCairoBool(unique),
294
297
  compiledConstructorCallData.length,
295
298
  ...compiledConstructorCallData,
@@ -298,10 +301,29 @@ export class Account extends Provider implements AccountInterface {
298
301
  ...callsArray,
299
302
  ],
300
303
  undefined,
301
- transactionsDetail
304
+ invocationsDetails
302
305
  );
303
306
  }
304
307
 
308
+ public async deployContract(
309
+ payload: UniversalDeployerContractPayload,
310
+ details: InvocationsDetails = {}
311
+ ): Promise<DeployContractUDCResponse> {
312
+ const deployTx = await this.deploy(payload, details);
313
+ const txReceipt = await this.waitForTransaction(deployTx.transaction_hash, ['ACCEPTED_ON_L2']);
314
+ return parseUDCEvent(txReceipt);
315
+ }
316
+
317
+ public async declareDeploy(
318
+ { classHash, contract, constructorCalldata }: DeclareDeployContractPayload,
319
+ details?: InvocationsDetails
320
+ ) {
321
+ const { transaction_hash } = await this.declare({ contract, classHash }, details);
322
+ const declare = await this.waitForTransaction(transaction_hash, ['ACCEPTED_ON_L2']);
323
+ const deploy = await this.deployContract({ classHash, constructorCalldata }, details);
324
+ return { declare: { ...declare, class_hash: classHash }, deploy };
325
+ }
326
+
305
327
  public async deployAccount(
306
328
  {
307
329
  classHash,
@@ -7,8 +7,11 @@ import {
7
7
  Call,
8
8
  DeclareContractPayload,
9
9
  DeclareContractResponse,
10
+ DeclareDeployContractPayload,
11
+ DeclareDeployContractResponse,
10
12
  DeployAccountContractPayload,
11
13
  DeployContractResponse,
14
+ DeployContractUDCResponse,
12
15
  EstimateFeeAction,
13
16
  EstimateFeeDetails,
14
17
  EstimateFeeResponse,
@@ -129,7 +132,6 @@ export abstract class AccountInterface extends ProviderInterface {
129
132
  * @param contractPayload transaction payload to be deployed containing:
130
133
  - contract: compiled contract code
131
134
  - classHash: computed class hash of compiled contract
132
- - signature
133
135
  * @param transactionsDetail Invocation Details containing:
134
136
  - optional nonce
135
137
  - optional version
@@ -147,20 +149,84 @@ export abstract class AccountInterface extends ProviderInterface {
147
149
  *
148
150
  * @param deployContractPayload containing
149
151
  * - classHash: computed class hash of compiled contract
150
- * - salt: address salt
151
- * - unique: bool if true ensure unique salt
152
- * - calldata: constructor calldata
153
- * - additionalCalls - optional additional calls array to support multicall
152
+ * - constructorCalldata: constructor calldata
153
+ * - optional salt: address salt - default random
154
+ * - optional unique: bool if true ensure unique salt - default true
155
+ * - optional additionalCalls - optional additional calls array to support multi-call
154
156
  * @param transactionsDetail Invocation Details containing:
155
157
  * - optional nonce
156
158
  * - optional version
157
159
  * - optional maxFee
160
+ * @returns Promise<InvokeFunctionResponse>
161
+ * - transaction_hash
158
162
  */
159
163
  public abstract deploy(
160
164
  deployContractPayload: UniversalDeployerContractPayload,
161
165
  transactionsDetail?: InvocationsDetails
162
166
  ): Promise<InvokeFunctionResponse>;
163
167
 
168
+ /**
169
+ * Simplify deploy simulating old DeployContract with same response + UDC specific response
170
+ *
171
+ * @param payload UniversalDeployerContractPayload
172
+ * - classHash: computed class hash of compiled contract
173
+ * - constructorCalldata: constructor calldata
174
+ * - optional salt: address salt - default random
175
+ * - optional unique: bool if true ensure unique salt - default true
176
+ * - optional additionalCalls - optional additional calls array to support multi-call
177
+ * @param details InvocationsDetails
178
+ * - optional nonce
179
+ * - optional version
180
+ * - optional maxFee
181
+ * @returns Promise<DeployContractUDCResponse>
182
+ * - contract_address
183
+ * - transaction_hash
184
+ * - address
185
+ * - deployer
186
+ * - unique
187
+ * - classHash
188
+ * - calldata_len
189
+ * - calldata
190
+ * - salt
191
+ */
192
+ public abstract deployContract(
193
+ payload: UniversalDeployerContractPayload,
194
+ details: InvocationsDetails
195
+ ): Promise<DeployContractUDCResponse>;
196
+
197
+ /**
198
+ * Declares and Deploy a given compiled contract (json) to starknet using UDC
199
+ *
200
+ * @param declareDeployerContractPayload containing
201
+ * - contract: compiled contract code
202
+ * - classHash: computed class hash of compiled contract
203
+ * - optional constructorCalldata: constructor calldata
204
+ * - optional salt: address salt - default random
205
+ * - optional unique: bool if true ensure unique salt - default true
206
+ * - optional additionalCalls: - optional additional calls array to support multicall
207
+ * @param details
208
+ * - optional nonce
209
+ * - optional version
210
+ * - optional maxFee
211
+ * @returns Promise<DeclareDeployContractResponse>
212
+ * - declare
213
+ * - transaction_hash
214
+ * - deploy
215
+ * - contract_address
216
+ * - transaction_hash
217
+ * - address
218
+ * - deployer
219
+ * - unique
220
+ * - classHash
221
+ * - calldata_len
222
+ * - calldata
223
+ * - salt
224
+ */
225
+ public abstract declareDeploy(
226
+ declareDeployerContractPayload: DeclareDeployContractPayload,
227
+ details?: InvocationsDetails
228
+ ): Promise<DeclareDeployContractResponse>;
229
+
164
230
  /**
165
231
  * Deploy the account on Starknet
166
232
  *
@@ -1,8 +1,7 @@
1
1
  import assert from 'minimalistic-assert';
2
2
 
3
3
  import { AccountInterface } from '../account';
4
- import { ProviderInterface, defaultProvider } from '../provider';
5
- import { Abi, CompiledContract, RawCalldata } from '../types';
4
+ import { Abi, CompiledContract, RawArgs } from '../types';
6
5
  import { Contract } from './default';
7
6
 
8
7
  export class ContractFactory {
@@ -10,16 +9,20 @@ export class ContractFactory {
10
9
 
11
10
  compiledContract: CompiledContract;
12
11
 
13
- providerOrAccount: ProviderInterface | AccountInterface;
12
+ classHash: string;
13
+
14
+ account: AccountInterface;
14
15
 
15
16
  constructor(
16
17
  compiledContract: CompiledContract,
17
- providerOrAccount: ProviderInterface | AccountInterface = defaultProvider,
18
+ classHash: string,
19
+ account: AccountInterface,
18
20
  abi: Abi = compiledContract.abi // abi can be different from the deployed contract ie for proxy contracts
19
21
  ) {
20
22
  this.abi = abi;
21
23
  this.compiledContract = compiledContract;
22
- this.providerOrAccount = providerOrAccount;
24
+ this.account = account;
25
+ this.classHash = classHash;
23
26
  }
24
27
 
25
28
  /**
@@ -30,20 +33,23 @@ export class ContractFactory {
30
33
  * @returns deployed Contract
31
34
  */
32
35
  public async deploy(
33
- constructorCalldata?: RawCalldata,
36
+ constructorCalldata?: RawArgs,
34
37
  addressSalt?: string | undefined
35
38
  ): Promise<Contract> {
36
- const { contract_address, transaction_hash } = await this.providerOrAccount.deployContract({
39
+ const {
40
+ deploy: { contract_address, transaction_hash },
41
+ } = await this.account.declareDeploy({
37
42
  contract: this.compiledContract,
43
+ classHash: this.classHash,
38
44
  constructorCalldata,
39
- addressSalt,
45
+ salt: addressSalt,
40
46
  });
41
47
  assert(Boolean(contract_address), 'Deployment of the contract failed');
42
48
 
43
49
  const contractInstance = new Contract(
44
50
  this.compiledContract.abi,
45
51
  contract_address!,
46
- this.providerOrAccount
52
+ this.account
47
53
  );
48
54
  contractInstance.deployTransactionHash = transaction_hash;
49
55
 
@@ -53,10 +59,11 @@ export class ContractFactory {
53
59
  /**
54
60
  * Attaches to new Provider or Account
55
61
  *
56
- * @param providerOrAccount - new Provider or Account to attach to
62
+ * @param account - new Provider or Account to attach to
63
+ * @returns ContractFactory
57
64
  */
58
- connect(providerOrAccount: ProviderInterface | AccountInterface): ContractFactory {
59
- this.providerOrAccount = providerOrAccount;
65
+ connect(account: AccountInterface): ContractFactory {
66
+ this.account = account;
60
67
  return this;
61
68
  }
62
69
 
@@ -67,7 +74,7 @@ export class ContractFactory {
67
74
  * @returns Contract
68
75
  */
69
76
  attach(address: string): Contract {
70
- return new Contract(this.abi, address, this.providerOrAccount);
77
+ return new Contract(this.abi, address, this.account);
71
78
  }
72
79
 
73
80
  // ethers.js' getDeployTransaction cant be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
@@ -9,6 +9,7 @@ import {
9
9
  AbiEntry,
10
10
  Args,
11
11
  AsyncContractFunction,
12
+ BlockTag,
12
13
  Call,
13
14
  Calldata,
14
15
  ContractFunction,
@@ -36,7 +37,15 @@ function parseFelt(candidate: string): BN {
36
37
  */
37
38
  function buildCall(contract: Contract, functionAbi: FunctionAbi): AsyncContractFunction {
38
39
  return async function (...args: Array<any>): Promise<any> {
39
- return contract.call(functionAbi.name, args);
40
+ let blockIdentifier: BlockTag | null = null;
41
+
42
+ args.forEach((arg) => {
43
+ if (arg.blockIdentifier) {
44
+ blockIdentifier = arg.blockIdentifier;
45
+ }
46
+ });
47
+
48
+ return contract.call(functionAbi.name, args, { blockIdentifier });
40
49
  };
41
50
  }
42
51
 
@@ -17,6 +17,7 @@ import {
17
17
  InvocationsDetails,
18
18
  InvocationsDetailsWithNonce,
19
19
  InvokeFunctionResponse,
20
+ Status,
20
21
  } from '../types';
21
22
  import { BigNumberish } from '../utils/number';
22
23
  import { ProviderInterface } from './interface';
@@ -33,13 +34,23 @@ export class Provider implements ProviderInterface {
33
34
  private provider!: ProviderInterface;
34
35
 
35
36
  constructor(providerOrOptions?: ProviderOptions | ProviderInterface) {
36
- if (providerOrOptions && 'chainId' in providerOrOptions) {
37
- this.provider = providerOrOptions;
38
- } else if (providerOrOptions?.rpc) {
39
- this.provider = new RpcProvider(providerOrOptions.rpc);
40
- } else if (providerOrOptions?.sequencer) {
41
- this.provider = new SequencerProvider(providerOrOptions.sequencer);
37
+ if (providerOrOptions instanceof Provider) {
38
+ // providerOrOptions is Provider
39
+ this.provider = providerOrOptions.provider;
40
+ } else if (
41
+ providerOrOptions instanceof RpcProvider ||
42
+ providerOrOptions instanceof SequencerProvider
43
+ ) {
44
+ // providerOrOptions is SequencerProvider or RpcProvider
45
+ this.provider = <ProviderInterface>providerOrOptions;
46
+ } else if (providerOrOptions && 'rpc' in providerOrOptions) {
47
+ // providerOrOptions is rpc option
48
+ this.provider = new RpcProvider(<RpcProviderOptions>providerOrOptions.rpc);
49
+ } else if (providerOrOptions && 'sequencer' in providerOrOptions) {
50
+ // providerOrOptions is sequencer option
51
+ this.provider = new SequencerProvider(<SequencerProviderOptions>providerOrOptions.sequencer);
42
52
  } else {
53
+ // providerOrOptions is none, create SequencerProvider as default
43
54
  this.provider = new SequencerProvider();
44
55
  }
45
56
  }
@@ -94,11 +105,11 @@ export class Provider implements ProviderInterface {
94
105
  );
95
106
  }
96
107
 
97
- public async getNonce(
108
+ public async getNonceForAddress(
98
109
  contractAddress: string,
99
110
  blockIdentifier?: BlockIdentifier
100
111
  ): Promise<BigNumberish> {
101
- return this.provider.getNonce(contractAddress, blockIdentifier);
112
+ return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
102
113
  }
103
114
 
104
115
  public async getStorageAt(
@@ -135,7 +146,7 @@ export class Provider implements ProviderInterface {
135
146
  * @deprecated This method won't be supported, use Account.deploy instead
136
147
  */
137
148
  public async deployContract(
138
- payload: DeployContractPayload,
149
+ payload: DeployContractPayload | any,
139
150
  details: InvocationsDetails
140
151
  ): Promise<DeployContractResponse> {
141
152
  return this.provider.deployContract(payload, details);
@@ -178,7 +189,11 @@ export class Provider implements ProviderInterface {
178
189
  return this.provider.getCode(contractAddress, blockIdentifier);
179
190
  }
180
191
 
181
- public async waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void> {
182
- return this.provider.waitForTransaction(txHash, retryInterval);
192
+ public async waitForTransaction(
193
+ txHash: BigNumberish,
194
+ successStates?: Array<Status>,
195
+ retryInterval?: number
196
+ ): Promise<any> {
197
+ return this.provider.waitForTransaction(txHash, successStates, retryInterval);
183
198
  }
184
199
  }
@@ -18,6 +18,7 @@ import type {
18
18
  InvocationsDetails,
19
19
  InvocationsDetailsWithNonce,
20
20
  InvokeFunctionResponse,
21
+ Status,
21
22
  } from '../types';
22
23
  import type { BigNumberish } from '../utils/number';
23
24
  import { BlockIdentifier } from './utils';
@@ -98,7 +99,7 @@ export abstract class ProviderInterface {
98
99
  * @param contractAddress - contract address
99
100
  * @returns the hex nonce
100
101
  */
101
- public abstract getNonce(
102
+ public abstract getNonceForAddress(
102
103
  contractAddress: string,
103
104
  blockIdentifier?: BlockIdentifier
104
105
  ): Promise<BigNumberish>;
@@ -147,7 +148,7 @@ export abstract class ProviderInterface {
147
148
  * @returns a confirmation of sending a transaction on the starknet contract
148
149
  */
149
150
  public abstract deployContract(
150
- payload: DeployContractPayload,
151
+ payload: DeployContractPayload | any,
151
152
  details?: InvocationsDetails
152
153
  ): Promise<DeployContractResponse>;
153
154
 
@@ -288,6 +289,11 @@ export abstract class ProviderInterface {
288
289
  * Wait for the transaction to be accepted
289
290
  * @param txHash - transaction hash
290
291
  * @param retryInterval - retry interval
292
+ * @return GetTransactionReceiptResponse
291
293
  */
292
- public abstract waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
294
+ public abstract waitForTransaction(
295
+ txHash: BigNumberish,
296
+ successStates?: Array<Status>,
297
+ retryInterval?: number
298
+ ): Promise<GetTransactionReceiptResponse>;
293
299
  }
@@ -132,7 +132,7 @@ export class RpcProvider implements ProviderInterface {
132
132
  });
133
133
  }
134
134
 
135
- public async getNonce(
135
+ public async getNonceForAddress(
136
136
  contractAddress: string,
137
137
  blockIdentifier: BlockIdentifier = 'pending'
138
138
  ): Promise<RPC.Nonce> {
@@ -402,31 +402,34 @@ export class RpcProvider implements ProviderInterface {
402
402
  return this.fetchEndpoint('starknet_traceBlockTransactions', { block_hash: blockHash });
403
403
  }
404
404
 
405
- public async waitForTransaction(txHash: string, retryInterval: number = 8000) {
405
+ public async waitForTransaction(
406
+ txHash: string,
407
+ successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'],
408
+ retryInterval: number = 8000
409
+ ) {
410
+ const errorStates = ['REJECTED', 'NOT_RECEIVED'];
406
411
  let { retries } = this;
407
412
  let onchain = false;
413
+ let txReceipt: any = {};
408
414
 
409
415
  while (!onchain) {
410
- const successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
411
- const errorStates = ['REJECTED', 'NOT_RECEIVED'];
412
-
413
416
  // eslint-disable-next-line no-await-in-loop
414
417
  await wait(retryInterval);
415
418
  try {
416
419
  // eslint-disable-next-line no-await-in-loop
417
- const res = await this.getTransactionReceipt(txHash);
420
+ txReceipt = await this.getTransactionReceipt(txHash);
418
421
 
419
- if (!('status' in res)) {
422
+ if (!('status' in txReceipt)) {
420
423
  const error = new Error('pending transaction');
421
424
  throw error;
422
425
  }
423
426
 
424
- if (res.status && successStates.includes(res.status)) {
427
+ if (txReceipt.status && successStates.includes(txReceipt.status)) {
425
428
  onchain = true;
426
- } else if (res.status && errorStates.includes(res.status)) {
427
- const message = res.status;
429
+ } else if (txReceipt.status && errorStates.includes(txReceipt.status)) {
430
+ const message = txReceipt.status;
428
431
  const error = new Error(message) as Error & { response: any };
429
- error.response = res;
432
+ error.response = txReceipt;
430
433
  throw error;
431
434
  }
432
435
  } catch (error: unknown) {
@@ -443,6 +446,7 @@ export class RpcProvider implements ProviderInterface {
443
446
  }
444
447
 
445
448
  await wait(retryInterval);
449
+ return txReceipt;
446
450
  }
447
451
 
448
452
  /**
@@ -256,7 +256,7 @@ export class SequencerProvider implements ProviderInterface {
256
256
  );
257
257
  }
258
258
 
259
- public async getNonce(
259
+ public async getNonceForAddress(
260
260
  contractAddress: string,
261
261
  blockIdentifier: BlockIdentifier = 'pending'
262
262
  ): Promise<BigNumberish> {
@@ -447,17 +447,20 @@ export class SequencerProvider implements ProviderInterface {
447
447
  return this.fetchEndpoint('get_code', { contractAddress, blockIdentifier });
448
448
  }
449
449
 
450
- public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
450
+ public async waitForTransaction(
451
+ txHash: BigNumberish,
452
+ successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'],
453
+ retryInterval: number = 8000
454
+ ) {
455
+ const errorStates = ['REJECTED', 'NOT_RECEIVED'];
451
456
  let onchain = false;
457
+ let res;
452
458
 
453
459
  while (!onchain) {
454
460
  // eslint-disable-next-line no-await-in-loop
455
461
  await wait(retryInterval);
456
462
  // eslint-disable-next-line no-await-in-loop
457
- const res = await this.getTransactionStatus(txHash);
458
-
459
- const successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
460
- const errorStates = ['REJECTED', 'NOT_RECEIVED'];
463
+ res = await this.getTransactionStatus(txHash);
461
464
 
462
465
  if (successStates.includes(res.tx_status)) {
463
466
  onchain = true;
@@ -470,6 +473,8 @@ export class SequencerProvider implements ProviderInterface {
470
473
  throw error;
471
474
  }
472
475
  }
476
+ const txReceipt = await this.getTransactionReceipt(txHash);
477
+ return txReceipt;
473
478
  }
474
479
 
475
480
  /**
@@ -1,4 +1,6 @@
1
1
  /* eslint-disable max-classes-per-file */
2
+ import { BN } from 'bn.js';
3
+
2
4
  import type { BlockNumber } from '../types';
3
5
  import { BigNumberish, isHex, toBN, toHex } from '../utils/number';
4
6
 
@@ -34,6 +36,7 @@ export function txIdentifier(txHash?: BigNumberish, txId?: BigNumberish): string
34
36
  // null appends nothing to the request url
35
37
 
36
38
  export type BlockIdentifier = BlockNumber | BigNumberish;
39
+ export const validBlockTags = ['latest', 'pending'];
37
40
 
38
41
  export class Block {
39
42
  hash: BlockIdentifier = null;
@@ -42,22 +45,26 @@ export class Block {
42
45
 
43
46
  tag: BlockIdentifier = null;
44
47
 
45
- private setIdentifier: (_identifier: BlockIdentifier) => void;
48
+ private setIdentifier(__identifier: BlockIdentifier) {
49
+ if (typeof __identifier === 'string' && isHex(__identifier)) {
50
+ this.hash = __identifier;
51
+ } else if (BN.isBN(__identifier)) {
52
+ this.hash = toHex(__identifier);
53
+ } else if (typeof __identifier === 'number') {
54
+ this.number = __identifier;
55
+ } else if (typeof __identifier === 'string' && validBlockTags.includes(__identifier)) {
56
+ this.tag = __identifier;
57
+ } else {
58
+ // default
59
+ this.tag = 'pending';
60
+ }
61
+ }
46
62
 
47
63
  constructor(_identifier: BlockIdentifier) {
48
- this.setIdentifier = function (__identifier: BlockIdentifier) {
49
- if (typeof __identifier === 'string' && isHex(__identifier)) {
50
- this.hash = __identifier;
51
- } else if (typeof __identifier === 'number') {
52
- this.number = __identifier;
53
- } else {
54
- this.tag = __identifier;
55
- }
56
- };
57
-
58
64
  this.setIdentifier(_identifier);
59
65
  }
60
66
 
67
+ // TODO: fix any
61
68
  get queryIdentifier(): any {
62
69
  if (this.number !== null) {
63
70
  return `blockNumber=${this.number}`;
@@ -70,6 +77,7 @@ export class Block {
70
77
  return `blockNumber=${this.tag}`;
71
78
  }
72
79
 
80
+ // TODO: fix any
73
81
  get identifier(): any {
74
82
  if (this.number !== null) {
75
83
  return { block_number: this.number };
@@ -2,7 +2,7 @@ import BN from 'bn.js';
2
2
 
3
3
  import { BlockIdentifier } from '../provider/utils';
4
4
  import { BigNumberish } from '../utils/number';
5
- import { EstimateFeeResponse } from './provider';
5
+ import { DeclareTransactionReceiptResponse, EstimateFeeResponse } from './provider';
6
6
 
7
7
  export interface EstimateFee extends EstimateFeeResponse {
8
8
  suggestedMaxFee: BN;
@@ -12,3 +12,23 @@ export interface EstimateFeeDetails {
12
12
  nonce?: BigNumberish;
13
13
  blockIdentifier?: BlockIdentifier;
14
14
  }
15
+
16
+ export interface DeployContractResponse {
17
+ contract_address: string;
18
+ transaction_hash: string;
19
+ }
20
+
21
+ export interface DeployContractUDCResponse extends DeployContractResponse {
22
+ address: string;
23
+ deployer: string;
24
+ unique: string;
25
+ classHash: string;
26
+ calldata_len: string;
27
+ calldata: Array<string>;
28
+ salt: string;
29
+ }
30
+
31
+ export type DeclareDeployContractResponse = {
32
+ declare: DeclareTransactionReceiptResponse;
33
+ deploy: DeployContractUDCResponse;
34
+ };
package/src/types/lib.ts CHANGED
@@ -21,8 +21,8 @@ export interface ContractClass {
21
21
 
22
22
  export type UniversalDeployerContractPayload = {
23
23
  classHash: BigNumberish;
24
- salt: string;
25
- unique: boolean;
24
+ salt?: string;
25
+ unique?: boolean;
26
26
  constructorCalldata?: RawArgs;
27
27
  additionalCalls?: AllowArray<Call>; // support multicall
28
28
  };
@@ -52,6 +52,9 @@ export type DeclareContractPayload = {
52
52
  classHash: BigNumberish; // Once the classHash is included in CompiledContract, this can be removed
53
53
  };
54
54
 
55
+ export type DeclareDeployContractPayload = DeclareContractPayload &
56
+ UniversalDeployerContractPayload;
57
+
55
58
  export type DeclareContractTransaction = {
56
59
  contractDefinition: ContractClass;
57
60
  senderAddress: string;
@@ -106,11 +106,6 @@ export interface InvokeFunctionResponse {
106
106
  transaction_hash: string;
107
107
  }
108
108
 
109
- export interface DeployContractResponse {
110
- contract_address: string;
111
- transaction_hash: string;
112
- }
113
-
114
109
  export interface DeclareContractResponse {
115
110
  transaction_hash: string;
116
111
  class_hash: string;