starknet 4.9.0 → 4.11.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 (81) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +1 -3
  3. package/__tests__/account.test.ts +5 -1
  4. package/__tests__/defaultProvider.test.ts +97 -210
  5. package/__tests__/fixtures.ts +2 -2
  6. package/__tests__/rpcProvider.test.ts +7 -4
  7. package/__tests__/udc.test.ts +41 -0
  8. package/account/default.d.ts +3 -1
  9. package/account/default.js +53 -3
  10. package/account/interface.d.ts +24 -7
  11. package/constants.d.ts +7 -1
  12. package/constants.js +7 -1
  13. package/contract/default.d.ts +11 -27
  14. package/contract/default.js +104 -120
  15. package/contract/interface.d.ts +5 -2
  16. package/dist/account/default.d.ts +3 -1
  17. package/dist/account/default.js +53 -3
  18. package/dist/account/interface.d.ts +24 -7
  19. package/dist/constants.d.ts +7 -1
  20. package/dist/constants.js +7 -1
  21. package/dist/contract/default.d.ts +11 -27
  22. package/dist/contract/default.js +104 -120
  23. package/dist/contract/interface.d.ts +5 -2
  24. package/dist/provider/default.d.ts +4 -2
  25. package/dist/provider/default.js +13 -2
  26. package/dist/provider/interface.d.ts +18 -3
  27. package/dist/provider/rpc.d.ts +15 -10
  28. package/dist/provider/rpc.js +71 -31
  29. package/dist/provider/sequencer.d.ts +6 -2
  30. package/dist/provider/sequencer.js +33 -5
  31. package/dist/signer/default.d.ts +2 -2
  32. package/dist/signer/default.js +15 -15
  33. package/dist/signer/interface.d.ts +2 -0
  34. package/dist/types/api/index.d.ts +0 -6
  35. package/dist/types/api/openrpc.d.ts +147 -98
  36. package/dist/types/api/openrpc.js +22 -4
  37. package/dist/types/index.d.ts +1 -1
  38. package/dist/types/lib.d.ts +22 -2
  39. package/dist/types/lib.js +6 -0
  40. package/dist/utils/number.d.ts +1 -0
  41. package/dist/utils/number.js +3 -1
  42. package/package.json +1 -1
  43. package/provider/default.d.ts +4 -2
  44. package/provider/default.js +13 -2
  45. package/provider/interface.d.ts +18 -3
  46. package/provider/rpc.d.ts +15 -10
  47. package/provider/rpc.js +71 -31
  48. package/provider/sequencer.d.ts +6 -2
  49. package/provider/sequencer.js +33 -5
  50. package/signer/default.d.ts +2 -2
  51. package/signer/default.js +15 -15
  52. package/signer/interface.d.ts +2 -0
  53. package/src/account/default.ts +51 -7
  54. package/src/account/interface.ts +34 -7
  55. package/src/constants.ts +7 -0
  56. package/src/contract/default.ts +123 -140
  57. package/src/contract/interface.ts +5 -2
  58. package/src/provider/default.ts +21 -3
  59. package/src/provider/interface.ts +26 -2
  60. package/src/provider/rpc.ts +73 -45
  61. package/src/provider/sequencer.ts +24 -4
  62. package/src/signer/default.ts +18 -18
  63. package/src/signer/interface.ts +2 -0
  64. package/src/types/api/index.ts +0 -4
  65. package/src/types/api/openrpc.ts +193 -105
  66. package/src/types/api/rpc.ts +0 -1
  67. package/src/types/index.ts +1 -1
  68. package/src/types/lib.ts +23 -2
  69. package/src/utils/number.ts +2 -0
  70. package/types/api/index.d.ts +0 -6
  71. package/types/api/openrpc.d.ts +147 -98
  72. package/types/api/openrpc.js +22 -4
  73. package/types/index.d.ts +1 -1
  74. package/types/lib.d.ts +22 -2
  75. package/types/lib.js +6 -0
  76. package/utils/number.d.ts +1 -0
  77. package/utils/number.js +3 -1
  78. package/www/docs/API/account.md +122 -22
  79. package/www/docs/API/contract.md +39 -3
  80. package/www/docs/API/provider.md +4 -0
  81. package/www/docs/API/signer.md +56 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,46 @@
1
+ # [4.11.0](https://github.com/0xs34n/starknet.js/compare/v4.10.0...v4.11.0) (2022-11-14)
2
+
3
+ ### Bug Fixes
4
+
5
+ - change txn version for estimate fee apis to be feeTransactionVersion ([4d255c5](https://github.com/0xs34n/starknet.js/commit/4d255c5cf4adceb16a7f9ac61904a6e5d8020cbd))
6
+ - lib FunctionAbiType and EventAbi shallow ([7088dc6](https://github.com/0xs34n/starknet.js/commit/7088dc6828f9f4fd29922323e63183a2e11f7340))
7
+ - remove deprecated function ([0a9f84f](https://github.com/0xs34n/starknet.js/commit/0a9f84f86aabaa49ab78faa3331cac0ca98ace61))
8
+ - removed fixed params swap ([57c01f6](https://github.com/0xs34n/starknet.js/commit/57c01f6418771d8ceaa3f393d54cad8bfff94b56))
9
+ - rpcProvider tests ([4b0fd20](https://github.com/0xs34n/starknet.js/commit/4b0fd20a8ce235e0e069521f7dca50a4696120a4))
10
+
11
+ ### Features
12
+
13
+ - fill in sequencer class methods ([83c0a29](https://github.com/0xs34n/starknet.js/commit/83c0a296bced3128a0ca9dd5246b376816a0be63))
14
+ - implement rpc-0.2.1rc1 types ([2b1b71e](https://github.com/0xs34n/starknet.js/commit/2b1b71ebedfa709aab4fa652bd98a8efc2d3e39a))
15
+ - rpc 0.2.0 plane implementation ([35a880c](https://github.com/0xs34n/starknet.js/commit/35a880ce4f8438e78143f7c0997ccfe6de680d80))
16
+ - rpc 0.2.0 type implementation ([866dda7](https://github.com/0xs34n/starknet.js/commit/866dda76fc35ef656a9e21b8b8674f73729c9a50))
17
+ - rpc 0.2.0 types spec ([25b2d29](https://github.com/0xs34n/starknet.js/commit/25b2d293a1a570b6fc68ea3877bfe6c3e898e3a6))
18
+ - rpc 0.2.1 ([ed17f63](https://github.com/0xs34n/starknet.js/commit/ed17f6380d2b1ab1432d5426c7395ab18c6dc793))
19
+ - rpc v0.2 endpoint, default identifiers, getClassHashAt flip parameters ([f0a0d6c](https://github.com/0xs34n/starknet.js/commit/f0a0d6c49e33442b603dcc9c9c119867c1ed32cc))
20
+ - rpc0.2.1 definition migration comlete ([35c5a06](https://github.com/0xs34n/starknet.js/commit/35c5a0645dafe061080c2c2ced6a9a4a9882207c))
21
+
22
+ # [4.10.0](https://github.com/0xs34n/starknet.js/compare/v4.9.0...v4.10.0) (2022-11-10)
23
+
24
+ ### Bug Fixes
25
+
26
+ - ci ([9b38cd8](https://github.com/0xs34n/starknet.js/commit/9b38cd8a2e23b71a1490c168ae83b64f479d3da9))
27
+ - deploy return type in interface ([6a663d4](https://github.com/0xs34n/starknet.js/commit/6a663d492751b0cd8493af6d4ee9a5cf5524ed19))
28
+ - path rpc test to release ([a1dafad](https://github.com/0xs34n/starknet.js/commit/a1dafad7056fb2e52849a8d5d533872254c62293))
29
+ - remove multiple RawArgs declaration ([b65dc65](https://github.com/0xs34n/starknet.js/commit/b65dc651bbd86708d4f88b7445813dab7dfea639))
30
+ - return type and rename calldata ([67fe081](https://github.com/0xs34n/starknet.js/commit/67fe081a24ca9eb64669ed9b0c2726898c68a34c))
31
+ - update readme ([7859cb1](https://github.com/0xs34n/starknet.js/commit/7859cb1d2b6e4e924f8bb21a1bbb9ada1a46a308))
32
+ - wait for declare and deploy, use random salt ([8dbd3c1](https://github.com/0xs34n/starknet.js/commit/8dbd3c183413f298307f2b22941c6981191a62b2))
33
+
34
+ ### Features
35
+
36
+ - add multicall support ([4b99f4a](https://github.com/0xs34n/starknet.js/commit/4b99f4a7b09a03990e2ba9ea00de2d0206f93ce0))
37
+ - enable custom providers headers option ([f2e9b1a](https://github.com/0xs34n/starknet.js/commit/f2e9b1a439908179bad1f4bb0e0632180b7b658f))
38
+ - fix and add proper UDC tests ([d96cc53](https://github.com/0xs34n/starknet.js/commit/d96cc531786738de7d8ec285ccdaa39e76a94de3))
39
+ - provider docs update ([e5d0376](https://github.com/0xs34n/starknet.js/commit/e5d0376dd281b04c486c58786709c42ea1e3a5a7))
40
+ - testnet2 ([8a054d0](https://github.com/0xs34n/starknet.js/commit/8a054d0ceb312efc0b6d303cad73b9bb39ba4304))
41
+ - udc demo ([27b402b](https://github.com/0xs34n/starknet.js/commit/27b402b6eed4c2bec67bfbf7ee27c9636ca4ae2b))
42
+ - udc working example ([5c4452a](https://github.com/0xs34n/starknet.js/commit/5c4452aa2e6b50768438f1117794dce430984ff8))
43
+
1
44
  # [4.9.0](https://github.com/0xs34n/starknet.js/compare/v4.8.0...v4.9.0) (2022-10-19)
2
45
 
3
46
  ### Bug Fixes
package/README.md CHANGED
@@ -72,12 +72,10 @@ If you consider to contribute to this project please read [CONTRIBUTING.md](http
72
72
 
73
73
  Special thanks to all the [contributors](https://github.com/0xs34n/starknet.js/graphs/contributors), especially to:
74
74
 
75
- Janek ([@janek26](https://github.com/janek26)) and Axel ([@delaaxe](https://github.com/delaaxe)) from [Argent](https://github.com/argentlabs)
75
+ Janek ([@janek26](https://github.com/janek26)), Axel ([@delaaxe](https://github.com/delaaxe)) and Dhruv ([@dhruvkelawala](https://github.com/dhruvkelawala)) from [Argent](https://github.com/argentlabs)
76
76
 
77
77
  Miljan ([@MilGard91](https://github.com/MilGard91)) from [Shard Labs](https://shardlabs.io/)
78
78
 
79
- Dhruv ([@dhruvkelawala](https://github.com/dhruvkelawala)) from [Jedi Swap](https://twitter.com/jediswap)
80
-
81
79
  and of course the [StarkWare](https://starkware.co/) team for their dedicated support!
82
80
 
83
81
  This library would not be possible without these rockstars.
@@ -2,6 +2,7 @@ import { isBN } from 'bn.js';
2
2
 
3
3
  import typedDataExample from '../__mocks__/typedDataExample.json';
4
4
  import { Account, Contract, Provider, number, stark } from '../src';
5
+ import { feeTransactionVersion } from '../src/utils/hash';
5
6
  import { toBN } from '../src/utils/number';
6
7
  import {
7
8
  compiledErc20,
@@ -43,12 +44,15 @@ describe('deploy and test Wallet', () => {
43
44
  });
44
45
 
45
46
  test('estimate fee', async () => {
47
+ const innerInvokeEstFeeSpy = jest.spyOn(account.signer, 'signTransaction');
46
48
  const { overall_fee } = await account.estimateInvokeFee({
47
49
  contractAddress: erc20Address,
48
50
  entrypoint: 'transfer',
49
51
  calldata: [erc20.address, '10', '0'],
50
52
  });
51
53
  expect(isBN(overall_fee)).toBe(true);
54
+ expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(feeTransactionVersion);
55
+ innerInvokeEstFeeSpy.mockClear();
52
56
  });
53
57
 
54
58
  test('read balance of wallet', async () => {
@@ -145,7 +149,7 @@ describe('deploy and test Wallet', () => {
145
149
  expect(res).toHaveProperty('overall_fee');
146
150
  });
147
151
 
148
- test('Declare Account contract', async () => {
152
+ test('Declare ERC20 contract', async () => {
149
153
  const declareTx = await account.declare({
150
154
  contract: compiledErc20,
151
155
  classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
@@ -1,11 +1,6 @@
1
- import { BlockNumber, DeployContractResponse, GetBlockResponse, stark } from '../src';
1
+ import { BlockNumber, GetBlockResponse, stark } from '../src';
2
2
  import { toBN } from '../src/utils/number';
3
- import {
4
- compiledOpenZeppelinAccount,
5
- describeIfNotDevnet,
6
- getERC20DeployPayload,
7
- getTestProvider,
8
- } from './fixtures';
3
+ import { getERC20DeployPayload, getTestProvider } from './fixtures';
9
4
 
10
5
  const { compileCalldata } = stark;
11
6
 
@@ -36,27 +31,47 @@ describe('defaultProvider', () => {
36
31
  });
37
32
 
38
33
  describe('endpoints', () => {
39
- test(`getBlock(blockHash=undefined, blockNumber=${exampleBlockNumber})`, () => {
40
- return expect(testProvider.getBlock(exampleBlockNumber)).resolves.not.toThrow();
34
+ test('deployContract()', () => {
35
+ expect(exampleContractAddress).toBeTruthy();
36
+ expect(exampleTransactionHash).toBeTruthy();
41
37
  });
42
38
 
43
- test(`getBlock(blockHash=${exampleBlockHash}, blockNumber=undefined)`, () => {
44
- return expect(testProvider.getBlock(exampleBlockHash)).resolves.not.toThrow();
45
- });
46
-
47
- test('getBlock(blockIdentifier=latest)', async () => {
48
- expect(exampleBlock).not.toBeNull();
49
-
50
- const { block_number, timestamp } = exampleBlock;
39
+ describe('getBlock', () => {
40
+ test('getBlock(blockIdentifier=latest)', async () => {
41
+ expect(exampleBlock).not.toBeNull();
42
+ const { block_number, timestamp } = exampleBlock;
43
+ expect(typeof block_number).toEqual('number');
44
+ return expect(typeof timestamp).toEqual('number');
45
+ });
51
46
 
52
- expect(typeof block_number).toEqual('number');
47
+ test(`getBlock(blockHash=undefined, blockNumber=${exampleBlockNumber})`, async () => {
48
+ const block = await testProvider.getBlock(exampleBlockNumber);
49
+ expect(block).toHaveProperty('block_hash');
50
+ expect(block).toHaveProperty('parent_hash');
51
+ expect(block).toHaveProperty('block_number');
52
+ expect(block).toHaveProperty('status');
53
+ expect(block).toHaveProperty('new_root');
54
+ expect(block).toHaveProperty('timestamp');
55
+ expect(block).toHaveProperty('transactions');
56
+ expect(Array.isArray(block.transactions)).toBe(true);
57
+ });
53
58
 
54
- return expect(typeof timestamp).toEqual('number');
55
- });
59
+ test(`getBlock(blockHash=${exampleBlockHash}, blockNumber=undefined)`, async () => {
60
+ const block = await testProvider.getBlock(exampleBlockHash);
61
+ expect(block).toHaveProperty('block_hash');
62
+ expect(block).toHaveProperty('parent_hash');
63
+ expect(block).toHaveProperty('block_number');
64
+ expect(block).toHaveProperty('status');
65
+ expect(block).toHaveProperty('new_root');
66
+ expect(block).toHaveProperty('timestamp');
67
+ expect(block).toHaveProperty('transactions');
68
+ expect(Array.isArray(block.transactions)).toBe(true);
69
+ });
56
70
 
57
- test('getBlock() -> { blockNumber }', async () => {
58
- const block = await testProvider.getBlock('latest');
59
- return expect(block).toHaveProperty('block_number');
71
+ test('getBlock() -> { blockNumber }', async () => {
72
+ const block = await testProvider.getBlock('latest');
73
+ return expect(block).toHaveProperty('block_number');
74
+ });
60
75
  });
61
76
 
62
77
  test('getNonce()', async () => {
@@ -64,6 +79,25 @@ describe('defaultProvider', () => {
64
79
  return expect(nonce).toEqual('0x0');
65
80
  });
66
81
 
82
+ test('getClassAt(contractAddress, blockNumber="latest")', async () => {
83
+ const classResponse = await testProvider.getClassAt(exampleContractAddress);
84
+
85
+ expect(classResponse).toHaveProperty('program');
86
+ expect(classResponse).toHaveProperty('entry_points_by_type');
87
+ });
88
+
89
+ // TODO see if feasible to split
90
+ describe('getClassHashAt & GetClass', () => {
91
+ test('responses', async () => {
92
+ const classHash = await testProvider.getClassHashAt(exampleContractAddress);
93
+ expect(typeof classHash).toBe('string');
94
+
95
+ const classResponse = await testProvider.getClass(classHash);
96
+ expect(classResponse).toHaveProperty('program');
97
+ expect(classResponse).toHaveProperty('entry_points_by_type');
98
+ });
99
+ });
100
+
67
101
  describe('getStorageAt', () => {
68
102
  test('with "key" type of number', () => {
69
103
  return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
@@ -82,7 +116,7 @@ describe('defaultProvider', () => {
82
116
  });
83
117
  });
84
118
 
85
- test('getTransaction() - successful transaction', async () => {
119
+ test('getTransaction() - successful deploy transaction', async () => {
86
120
  const transaction = await testProvider.getTransaction(exampleTransactionHash);
87
121
 
88
122
  expect(transaction).toHaveProperty('transaction_hash');
@@ -91,198 +125,51 @@ describe('defaultProvider', () => {
91
125
  test('getTransactionReceipt() - successful transaction', async () => {
92
126
  const transactionReceipt = await testProvider.getTransactionReceipt(exampleTransactionHash);
93
127
 
94
- return expect(transactionReceipt).toHaveProperty('actual_fee');
95
- });
96
-
97
- test('callContract()', () => {
98
- return expect(
99
- testProvider.callContract({
100
- contractAddress: exampleContractAddress,
101
- entrypoint: 'balanceOf',
102
- calldata: compileCalldata({
103
- user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
104
- }),
105
- })
106
- ).resolves.not.toThrow();
107
- });
108
-
109
- test('callContract() - gateway error', async () => {
110
- return expect(
111
- testProvider.callContract({
112
- contractAddress: exampleContractAddress,
113
- entrypoint: 'non_existent_entrypoint',
114
- calldata: compileCalldata({
115
- user: '0xdeadbeef',
116
- }),
117
- })
118
- ).rejects.toThrowError();
128
+ expect(transactionReceipt).toHaveProperty('actual_fee');
129
+ expect(transactionReceipt).toHaveProperty('transaction_hash');
130
+ expect(transactionReceipt).toHaveProperty('status');
131
+ expect(transactionReceipt).toHaveProperty('actual_fee');
119
132
  });
120
- });
121
-
122
- describe('addTransaction()', () => {
123
- test('deployContract()', async () => {
124
- const response = await testProvider.deployContract({
125
- contract: compiledOpenZeppelinAccount,
126
- });
127
133
 
128
- expect(response.transaction_hash).toBeDefined();
129
- expect(response.contract_address).toBeDefined();
130
- });
131
- });
132
-
133
- describeIfNotDevnet('Provider', () => {
134
- const provider = getTestProvider();
135
- let latestBlock;
136
- describe(`Provider methods if not devnet`, () => {
137
- describe('getBlock', () => {
138
- test('getBlock by tag latest', async () => {
139
- latestBlock = await provider.getBlock('latest');
140
- expect(latestBlock).toHaveProperty('block_hash');
141
- expect(latestBlock).toHaveProperty('parent_hash');
142
- expect(latestBlock).toHaveProperty('block_number');
143
- expect(latestBlock).toHaveProperty('status');
144
- expect(latestBlock).toHaveProperty('new_root');
145
- expect(latestBlock).toHaveProperty('timestamp');
146
- expect(latestBlock).toHaveProperty('transactions');
147
- expect(Array.isArray(latestBlock.transactions)).toBe(true);
148
- });
149
-
150
- test('getBlock by Hash', async () => {
151
- const block = await provider.getBlock(latestBlock.block_hash);
152
- expect(block).toHaveProperty('block_hash');
153
- expect(block).toHaveProperty('parent_hash');
154
- expect(block).toHaveProperty('block_number');
155
- expect(block).toHaveProperty('status');
156
- expect(block).toHaveProperty('new_root');
157
- expect(block).toHaveProperty('timestamp');
158
- expect(block).toHaveProperty('transactions');
159
- expect(Array.isArray(block.transactions)).toBe(true);
160
- });
161
-
162
- test('getBlock by Number', async () => {
163
- const block = await provider.getBlock(latestBlock.block_number);
164
- expect(block).toHaveProperty('block_hash');
165
- expect(block).toHaveProperty('parent_hash');
166
- expect(block).toHaveProperty('block_number');
167
- expect(block).toHaveProperty('status');
168
- expect(block).toHaveProperty('new_root');
169
- expect(block).toHaveProperty('timestamp');
170
- expect(block).toHaveProperty('transactions');
171
- expect(Array.isArray(block.transactions)).toBe(true);
172
- });
173
- });
174
-
175
- describe('getStorageAt', () => {
176
- test('pending', async () => {
177
- const storage = await provider.getStorageAt(
178
- '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
179
- '0'
180
- );
181
- expect(typeof storage).toBe('string');
182
- });
183
-
184
- test('Block Hash 0x7104702055c2a5773a870ceada9552ec659d69c18053b14078983f07527dea8', async () => {
185
- const storage = await provider.getStorageAt(
186
- '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
187
- '0',
188
- '0x7225762c7ff5e7e5f0867f0a8e73594df4f44f05a65375339a76398e8ae3e64'
189
- );
190
- expect(typeof storage).toBe('string');
191
- });
192
- });
193
-
194
- describe('getTransaction', () => {
195
- test('Deploy Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348', async () => {
196
- const transaction = await provider.getTransaction(
197
- '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
198
- );
199
-
200
- expect(transaction.transaction_hash).toBeTruthy();
201
- expect(transaction.contract_address).toBeTruthy();
202
- });
203
-
204
- test('Invoke Transaction Hash 0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b', async () => {
205
- const transaction = await provider.getTransaction(
206
- '0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b'
207
- );
208
-
209
- expect(transaction.transaction_hash).toBeTruthy();
210
- expect(transaction.contract_address).toBeTruthy();
211
- expect(Array.isArray(transaction.calldata)).toBe(true);
212
- // expect(transaction.entry_point_selector).toBeTruthy();
213
- expect(Array.isArray(transaction.signature)).toBe(true);
214
- expect(transaction.max_fee).toBeTruthy();
215
- });
216
-
217
- test('Declare Transaction Hash 0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea', async () => {
218
- const transaction = await provider.getTransaction(
219
- '0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea'
220
- );
221
-
222
- expect(transaction.max_fee).toBeTruthy();
223
- expect(transaction.transaction_hash).toBeTruthy();
224
- expect(transaction).toHaveProperty('nonce');
225
- expect(transaction).toHaveProperty('version');
226
- });
134
+ describe('callContract()', () => {
135
+ test('callContract()', () => {
136
+ return expect(
137
+ testProvider.callContract({
138
+ contractAddress: exampleContractAddress,
139
+ entrypoint: 'balanceOf',
140
+ calldata: compileCalldata({
141
+ user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
142
+ }),
143
+ })
144
+ ).resolves.not.toThrow();
227
145
  });
228
146
 
229
- describe('getTransactionReceipt', () => {
230
- test('Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348', async () => {
231
- const receipt = await provider.getTransactionReceipt(
232
- '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
233
- );
234
- expect(receipt).toHaveProperty('transaction_hash');
235
- expect(receipt).toHaveProperty('status');
236
- expect(receipt).toHaveProperty('actual_fee');
237
- });
147
+ test('callContract() - user wallet', () => {
148
+ return expect(
149
+ testProvider
150
+ .callContract({
151
+ contractAddress: exampleContractAddress,
152
+ entrypoint: 'balanceOf',
153
+ calldata: compileCalldata({
154
+ user: wallet,
155
+ }),
156
+ })
157
+ .then((res) => {
158
+ expect(Array.isArray(res.result)).toBe(true);
159
+ })
160
+ ).resolves.not.toThrow();
238
161
  });
239
162
 
240
- describe('Contract methods', () => {
241
- let contractAddress: string;
242
- let deployResponse: DeployContractResponse;
243
- let blockNumber: BlockNumber;
244
-
245
- beforeAll(async () => {
246
- const erc20DeployPayload = getERC20DeployPayload(wallet);
247
- deployResponse = await provider.deployContract(erc20DeployPayload);
248
- contractAddress = deployResponse.contract_address;
249
- await provider.waitForTransaction(deployResponse.transaction_hash);
250
- ({ block_number: blockNumber } = await provider.getBlock('latest'));
251
- });
252
-
253
- describe('deployContract', () => {
254
- test('response', () => {
255
- expect(deployResponse.contract_address).toBeTruthy();
256
- expect(deployResponse.transaction_hash).toBeTruthy();
257
- });
258
- });
259
-
260
- describe('getClassAt', () => {
261
- test('response', async () => {
262
- const classResponse = await provider.getClassAt(contractAddress, blockNumber);
263
-
264
- expect(classResponse).toHaveProperty('program');
265
- expect(classResponse).toHaveProperty('entry_points_by_type');
266
- });
267
- });
268
-
269
- describe('callContract', () => {
270
- test('result', () => {
271
- return expect(
272
- provider
273
- .callContract({
274
- contractAddress: deployResponse.contract_address,
275
- entrypoint: 'balanceOf',
276
- calldata: compileCalldata({
277
- user: wallet,
278
- }),
279
- })
280
- .then((res) => {
281
- expect(Array.isArray(res.result)).toBe(true);
282
- })
283
- ).resolves.not.toThrow();
284
- });
285
- });
163
+ test('callContract() - gateway error', async () => {
164
+ return expect(
165
+ testProvider.callContract({
166
+ contractAddress: exampleContractAddress,
167
+ entrypoint: 'non_existent_entrypoint',
168
+ calldata: compileCalldata({
169
+ user: '0xdeadbeef',
170
+ }),
171
+ })
172
+ ).rejects.toThrowError();
286
173
  });
287
174
  });
288
175
  });
@@ -28,10 +28,10 @@ const IS_RPC_DEVNET = Boolean(
28
28
  );
29
29
  const IS_SEQUENCER = !IS_RPC;
30
30
  const IS_SEQUENCER_DEVNET = !BASE_URL.includes('starknet.io');
31
- export const IS_SEQUENCER_GOERLI = BASE_URL === 'https://alpha4.starknet.io';
31
+ export const IS_SEQUENCER_GOERLI = BASE_URL === 'https://alpha4-2.starknet.io';
32
32
  export const IS_DEVNET = IS_SEQUENCER ? IS_SEQUENCER_DEVNET : IS_RPC_DEVNET;
33
33
 
34
- export const getTestProvider = () => {
34
+ export const getTestProvider = (): ProviderInterface => {
35
35
  const provider = RPC_URL
36
36
  ? new RpcProvider({ nodeUrl: RPC_URL })
37
37
  : new SequencerProvider({ baseUrl: BASE_URL });
@@ -1,4 +1,5 @@
1
1
  import { Account, GetBlockResponse, RpcProvider, ec } from '../src';
2
+ import { StarknetChainId } from '../src/constants';
2
3
  import {
3
4
  compiledOpenZeppelinAccount,
4
5
  describeIfRpc,
@@ -22,7 +23,9 @@ describeIfRpc('RPCProvider', () => {
22
23
 
23
24
  test('getChainId', async () => {
24
25
  const chainId = await rpcProvider.getChainId();
25
- expect(chainId).toBe('0x534e5f474f45524c49');
26
+ expect([StarknetChainId.TESTNET2, StarknetChainId.MAINNET, StarknetChainId.TESTNET]).toContain(
27
+ chainId
28
+ );
26
29
  });
27
30
 
28
31
  test('getPendingTransactions', async () => {
@@ -106,7 +109,7 @@ describeIfRpc('RPCProvider', () => {
106
109
  });
107
110
 
108
111
  test('getClassHashAt', async () => {
109
- const classHash = await rpcProvider.getClassHashAt('latest', contract_address);
112
+ const classHash = await rpcProvider.getClassHashAt(contract_address);
110
113
  expect(typeof classHash).toBe('string');
111
114
  });
112
115
 
@@ -115,9 +118,9 @@ describeIfRpc('RPCProvider', () => {
115
118
  });
116
119
  });
117
120
 
118
- test('getClass classHash 0x0733734fa0dab1158bccdfe0df7b0becf3827f908971fac8d39cc73d99ad8645', async () => {
121
+ test('getClass classHash 0x03fcbf77b28c96f4f2fb5bd2d176ab083a12a5e123adeb0de955d7ee228c9854', async () => {
119
122
  const contractClass = await rpcProvider.getClass(
120
- '0x0733734fa0dab1158bccdfe0df7b0becf3827f908971fac8d39cc73d99ad8645'
123
+ '0x03fcbf77b28c96f4f2fb5bd2d176ab083a12a5e123adeb0de955d7ee228c9854'
121
124
  );
122
125
  expect(contractClass).toHaveProperty('program');
123
126
  expect(contractClass).toHaveProperty('entry_points_by_type');
@@ -0,0 +1,41 @@
1
+ import { encodeShortString } from '../src/utils/shortString';
2
+ import { randomAddress } from '../src/utils/stark';
3
+ import { IS_DEVNET, compiledErc20, getTestAccount, getTestProvider } from './fixtures';
4
+
5
+ describe('Declare and UDC Deploy Flow', () => {
6
+ const provider = getTestProvider();
7
+ const account = getTestAccount(provider);
8
+ const erc20ClassHash = '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a';
9
+
10
+ test('ERC20 Declare', async () => {
11
+ const declareTx = await account.declare({
12
+ classHash: erc20ClassHash,
13
+ contract: compiledErc20,
14
+ });
15
+
16
+ await provider.waitForTransaction(declareTx.transaction_hash);
17
+
18
+ expect(declareTx).toHaveProperty('class_hash');
19
+ expect(declareTx.class_hash).toEqual(erc20ClassHash);
20
+ });
21
+
22
+ test('UDC Deploy', async () => {
23
+ const salt = randomAddress(); // use random salt
24
+
25
+ const deployment = await account.deploy({
26
+ classHash: erc20ClassHash,
27
+ constructorCalldata: [
28
+ encodeShortString('Token'),
29
+ encodeShortString('ERC20'),
30
+ account.address,
31
+ ],
32
+ salt,
33
+ unique: true, // Using true here so as not to clash with normal erc20 deploy in account and provider test
34
+ isDevnet: IS_DEVNET,
35
+ });
36
+
37
+ await provider.waitForTransaction(deployment.transaction_hash);
38
+
39
+ expect(deployment).toHaveProperty('transaction_hash');
40
+ });
41
+ });
@@ -4,7 +4,7 @@ import { BlockIdentifier } from '../provider/utils';
4
4
  import { SignerInterface } from '../signer';
5
5
  import { Abi, Call, DeclareContractResponse, DeployContractResponse, EstimateFeeAction, InvocationsDetails, InvokeFunctionResponse, KeyPair, Signature } from '../types';
6
6
  import { EstimateFee, EstimateFeeDetails } from '../types/account';
7
- import { AllowArray, DeclareContractPayload, DeployAccountContractPayload } from '../types/lib';
7
+ import { AllowArray, DeclareContractPayload, DeployAccountContractPayload, UniversalDeployerContractPayload } from '../types/lib';
8
8
  import { BigNumberish } from '../utils/number';
9
9
  import { TypedData } from '../utils/typedData';
10
10
  import { AccountInterface } from './interface';
@@ -19,6 +19,8 @@ export declare class Account extends Provider implements AccountInterface {
19
19
  estimateAccountDeployFee({ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress, }: DeployAccountContractPayload, { blockIdentifier, nonce: providedNonce }?: EstimateFeeDetails): Promise<EstimateFee>;
20
20
  execute(calls: AllowArray<Call>, abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
21
21
  declare({ classHash, contract }: DeclareContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeclareContractResponse>;
22
+ deploy({ classHash, salt, unique, constructorCalldata, isDevnet, }: UniversalDeployerContractPayload, additionalCalls?: AllowArray<Call>, // support multicall
23
+ transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
22
24
  deployAccount({ classHash, constructorCalldata, addressSalt, contractAddress: providedContractAddress, }: DeployAccountContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeployContractResponse>;
23
25
  signMessage(typedData: TypedData): Promise<Signature>;
24
26
  hashMessage(typedData: TypedData): Promise<string>;
@@ -61,6 +61,31 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
61
61
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
62
  }
63
63
  };
64
+ var __read = (this && this.__read) || function (o, n) {
65
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
66
+ if (!m) return o;
67
+ var i = m.call(o), r, ar = [], e;
68
+ try {
69
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
70
+ }
71
+ catch (error) { e = { error: error }; }
72
+ finally {
73
+ try {
74
+ if (r && !r.done && (m = i["return"])) m.call(i);
75
+ }
76
+ finally { if (e) throw e.error; }
77
+ }
78
+ return ar;
79
+ };
80
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
81
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
82
+ if (ar || !(i in from)) {
83
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
84
+ ar[i] = from[i];
85
+ }
86
+ }
87
+ return to.concat(ar || Array.prototype.slice.call(from));
88
+ };
64
89
  Object.defineProperty(exports, "__esModule", { value: true });
65
90
  exports.Account = void 0;
66
91
  var constants_1 = require("../constants");
@@ -113,7 +138,7 @@ var Account = /** @class */ (function (_super) {
113
138
  _e.label = 3;
114
139
  case 3:
115
140
  nonce = _c.apply(void 0, [_d]);
116
- version = (0, number_1.toBN)(hash_1.transactionVersion);
141
+ version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
117
142
  return [4 /*yield*/, this.getChainId()];
118
143
  case 4:
119
144
  chainId = _e.sent();
@@ -155,7 +180,7 @@ var Account = /** @class */ (function (_super) {
155
180
  _f.label = 3;
156
181
  case 3:
157
182
  nonce = _d.apply(void 0, [_e]);
158
- version = (0, number_1.toBN)(hash_1.transactionVersion);
183
+ version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
159
184
  return [4 /*yield*/, this.getChainId()];
160
185
  case 4:
161
186
  chainId = _f.sent();
@@ -197,7 +222,7 @@ var Account = /** @class */ (function (_super) {
197
222
  _h.label = 3;
198
223
  case 3:
199
224
  nonce = _f.apply(void 0, [_g]);
200
- version = (0, number_1.toBN)(hash_1.transactionVersion);
225
+ version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
201
226
  return [4 /*yield*/, this.getChainId()];
202
227
  case 4:
203
228
  chainId = _h.sent();
@@ -328,6 +353,31 @@ var Account = /** @class */ (function (_super) {
328
353
  });
329
354
  });
330
355
  };
356
+ Account.prototype.deploy = function (_a, additionalCalls, // support multicall
357
+ transactionsDetail) {
358
+ var classHash = _a.classHash, salt = _a.salt, _b = _a.unique, unique = _b === void 0 ? true : _b, _c = _a.constructorCalldata, constructorCalldata = _c === void 0 ? [] : _c, _d = _a.isDevnet, isDevnet = _d === void 0 ? false : _d;
359
+ if (additionalCalls === void 0) { additionalCalls = []; }
360
+ if (transactionsDetail === void 0) { transactionsDetail = {}; }
361
+ return __awaiter(this, void 0, void 0, function () {
362
+ var compiledConstructorCallData, callsArray;
363
+ return __generator(this, function (_e) {
364
+ compiledConstructorCallData = (0, stark_1.compileCalldata)(constructorCalldata);
365
+ callsArray = Array.isArray(additionalCalls) ? additionalCalls : [additionalCalls];
366
+ return [2 /*return*/, this.execute(__spreadArray([
367
+ {
368
+ contractAddress: isDevnet ? constants_1.UDC.ADDRESS_DEVNET : constants_1.UDC.ADDRESS,
369
+ entrypoint: constants_1.UDC.ENTRYPOINT,
370
+ calldata: __spreadArray([
371
+ classHash,
372
+ salt,
373
+ (0, number_1.toCairoBool)(unique),
374
+ compiledConstructorCallData.length
375
+ ], __read(compiledConstructorCallData), false),
376
+ }
377
+ ], __read(callsArray), false), undefined, transactionsDetail)];
378
+ });
379
+ });
380
+ };
331
381
  Account.prototype.deployAccount = function (_a, transactionsDetail) {
332
382
  var _b, _c;
333
383
  var classHash = _a.classHash, _d = _a.constructorCalldata, constructorCalldata = _d === void 0 ? [] : _d, _e = _a.addressSalt, addressSalt = _e === void 0 ? 0 : _e, providedContractAddress = _a.contractAddress;