starknet 4.9.0 → 4.10.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 +22 -0
- package/README.md +1 -3
- package/__tests__/account.test.ts +1 -1
- package/__tests__/defaultProvider.test.ts +85 -210
- package/__tests__/fixtures.ts +1 -1
- package/__tests__/rpcProvider.test.ts +4 -3
- package/__tests__/udc.test.ts +41 -0
- package/account/default.d.ts +3 -1
- package/account/default.js +50 -0
- package/account/interface.d.ts +24 -7
- package/constants.d.ts +7 -1
- package/constants.js +7 -1
- package/contract/default.d.ts +11 -27
- package/contract/default.js +104 -120
- package/contract/interface.d.ts +5 -2
- package/dist/account/default.d.ts +3 -1
- package/dist/account/default.js +50 -0
- package/dist/account/interface.d.ts +24 -7
- package/dist/constants.d.ts +7 -1
- package/dist/constants.js +7 -1
- package/dist/contract/default.d.ts +11 -27
- package/dist/contract/default.js +104 -120
- package/dist/contract/interface.d.ts +5 -2
- package/dist/provider/rpc.d.ts +3 -1
- package/dist/provider/rpc.js +15 -2
- package/dist/provider/sequencer.d.ts +4 -2
- package/dist/provider/sequencer.js +18 -5
- package/dist/signer/default.d.ts +2 -2
- package/dist/signer/default.js +15 -15
- package/dist/signer/interface.d.ts +2 -0
- package/dist/types/api/index.d.ts +0 -6
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lib.d.ts +13 -0
- package/dist/utils/number.d.ts +1 -0
- package/dist/utils/number.js +3 -1
- package/package.json +1 -1
- package/provider/rpc.d.ts +3 -1
- package/provider/rpc.js +15 -2
- package/provider/sequencer.d.ts +4 -2
- package/provider/sequencer.js +18 -5
- package/signer/default.d.ts +2 -2
- package/signer/default.js +15 -15
- package/signer/interface.d.ts +2 -0
- package/src/account/default.ts +43 -3
- package/src/account/interface.ts +34 -7
- package/src/constants.ts +7 -0
- package/src/contract/default.ts +123 -140
- package/src/contract/interface.ts +5 -2
- package/src/provider/rpc.ts +7 -3
- package/src/provider/sequencer.ts +13 -4
- package/src/signer/default.ts +18 -18
- package/src/signer/interface.ts +2 -0
- package/src/types/api/index.ts +0 -4
- package/src/types/index.ts +1 -1
- package/src/types/lib.ts +13 -0
- package/src/utils/number.ts +2 -0
- package/types/api/index.d.ts +0 -6
- package/types/index.d.ts +1 -1
- package/types/lib.d.ts +13 -0
- package/utils/number.d.ts +1 -0
- package/utils/number.js +3 -1
- package/www/docs/API/account.md +122 -22
- package/www/docs/API/contract.md +39 -3
- package/www/docs/API/provider.md +4 -0
- package/www/docs/API/signer.md +56 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
# [4.10.0](https://github.com/0xs34n/starknet.js/compare/v4.9.0...v4.10.0) (2022-11-10)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- ci ([9b38cd8](https://github.com/0xs34n/starknet.js/commit/9b38cd8a2e23b71a1490c168ae83b64f479d3da9))
|
|
6
|
+
- deploy return type in interface ([6a663d4](https://github.com/0xs34n/starknet.js/commit/6a663d492751b0cd8493af6d4ee9a5cf5524ed19))
|
|
7
|
+
- path rpc test to release ([a1dafad](https://github.com/0xs34n/starknet.js/commit/a1dafad7056fb2e52849a8d5d533872254c62293))
|
|
8
|
+
- remove multiple RawArgs declaration ([b65dc65](https://github.com/0xs34n/starknet.js/commit/b65dc651bbd86708d4f88b7445813dab7dfea639))
|
|
9
|
+
- return type and rename calldata ([67fe081](https://github.com/0xs34n/starknet.js/commit/67fe081a24ca9eb64669ed9b0c2726898c68a34c))
|
|
10
|
+
- update readme ([7859cb1](https://github.com/0xs34n/starknet.js/commit/7859cb1d2b6e4e924f8bb21a1bbb9ada1a46a308))
|
|
11
|
+
- wait for declare and deploy, use random salt ([8dbd3c1](https://github.com/0xs34n/starknet.js/commit/8dbd3c183413f298307f2b22941c6981191a62b2))
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- add multicall support ([4b99f4a](https://github.com/0xs34n/starknet.js/commit/4b99f4a7b09a03990e2ba9ea00de2d0206f93ce0))
|
|
16
|
+
- enable custom providers headers option ([f2e9b1a](https://github.com/0xs34n/starknet.js/commit/f2e9b1a439908179bad1f4bb0e0632180b7b658f))
|
|
17
|
+
- fix and add proper UDC tests ([d96cc53](https://github.com/0xs34n/starknet.js/commit/d96cc531786738de7d8ec285ccdaa39e76a94de3))
|
|
18
|
+
- provider docs update ([e5d0376](https://github.com/0xs34n/starknet.js/commit/e5d0376dd281b04c486c58786709c42ea1e3a5a7))
|
|
19
|
+
- testnet2 ([8a054d0](https://github.com/0xs34n/starknet.js/commit/8a054d0ceb312efc0b6d303cad73b9bb39ba4304))
|
|
20
|
+
- udc demo ([27b402b](https://github.com/0xs34n/starknet.js/commit/27b402b6eed4c2bec67bfbf7ee27c9636ca4ae2b))
|
|
21
|
+
- udc working example ([5c4452a](https://github.com/0xs34n/starknet.js/commit/5c4452aa2e6b50768438f1117794dce430984ff8))
|
|
22
|
+
|
|
1
23
|
# [4.9.0](https://github.com/0xs34n/starknet.js/compare/v4.8.0...v4.9.0) (2022-10-19)
|
|
2
24
|
|
|
3
25
|
### 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))
|
|
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.
|
|
@@ -145,7 +145,7 @@ describe('deploy and test Wallet', () => {
|
|
|
145
145
|
expect(res).toHaveProperty('overall_fee');
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
test('Declare
|
|
148
|
+
test('Declare ERC20 contract', async () => {
|
|
149
149
|
const declareTx = await account.declare({
|
|
150
150
|
contract: compiledErc20,
|
|
151
151
|
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { BlockNumber,
|
|
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(
|
|
40
|
-
|
|
34
|
+
test('deployContract()', () => {
|
|
35
|
+
expect(exampleContractAddress).toBeTruthy();
|
|
36
|
+
expect(exampleTransactionHash).toBeTruthy();
|
|
41
37
|
});
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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,13 @@ 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
|
+
|
|
67
89
|
describe('getStorageAt', () => {
|
|
68
90
|
test('with "key" type of number', () => {
|
|
69
91
|
return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
|
|
@@ -82,7 +104,7 @@ describe('defaultProvider', () => {
|
|
|
82
104
|
});
|
|
83
105
|
});
|
|
84
106
|
|
|
85
|
-
test('getTransaction() - successful transaction', async () => {
|
|
107
|
+
test('getTransaction() - successful deploy transaction', async () => {
|
|
86
108
|
const transaction = await testProvider.getTransaction(exampleTransactionHash);
|
|
87
109
|
|
|
88
110
|
expect(transaction).toHaveProperty('transaction_hash');
|
|
@@ -91,198 +113,51 @@ describe('defaultProvider', () => {
|
|
|
91
113
|
test('getTransactionReceipt() - successful transaction', async () => {
|
|
92
114
|
const transactionReceipt = await testProvider.getTransactionReceipt(exampleTransactionHash);
|
|
93
115
|
|
|
94
|
-
|
|
116
|
+
expect(transactionReceipt).toHaveProperty('actual_fee');
|
|
117
|
+
expect(transactionReceipt).toHaveProperty('transaction_hash');
|
|
118
|
+
expect(transactionReceipt).toHaveProperty('status');
|
|
119
|
+
expect(transactionReceipt).toHaveProperty('actual_fee');
|
|
95
120
|
});
|
|
96
121
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe('addTransaction()', () => {
|
|
123
|
-
test('deployContract()', async () => {
|
|
124
|
-
const response = await testProvider.deployContract({
|
|
125
|
-
contract: compiledOpenZeppelinAccount,
|
|
126
|
-
});
|
|
127
|
-
|
|
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
|
-
});
|
|
122
|
+
describe('callContract()', () => {
|
|
123
|
+
test('callContract()', () => {
|
|
124
|
+
return expect(
|
|
125
|
+
testProvider.callContract({
|
|
126
|
+
contractAddress: exampleContractAddress,
|
|
127
|
+
entrypoint: 'balanceOf',
|
|
128
|
+
calldata: compileCalldata({
|
|
129
|
+
user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b',
|
|
130
|
+
}),
|
|
131
|
+
})
|
|
132
|
+
).resolves.not.toThrow();
|
|
227
133
|
});
|
|
228
134
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
135
|
+
test('callContract() - user wallet', () => {
|
|
136
|
+
return expect(
|
|
137
|
+
testProvider
|
|
138
|
+
.callContract({
|
|
139
|
+
contractAddress: exampleContractAddress,
|
|
140
|
+
entrypoint: 'balanceOf',
|
|
141
|
+
calldata: compileCalldata({
|
|
142
|
+
user: wallet,
|
|
143
|
+
}),
|
|
144
|
+
})
|
|
145
|
+
.then((res) => {
|
|
146
|
+
expect(Array.isArray(res.result)).toBe(true);
|
|
147
|
+
})
|
|
148
|
+
).resolves.not.toThrow();
|
|
238
149
|
});
|
|
239
150
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
});
|
|
151
|
+
test('callContract() - gateway error', async () => {
|
|
152
|
+
return expect(
|
|
153
|
+
testProvider.callContract({
|
|
154
|
+
contractAddress: exampleContractAddress,
|
|
155
|
+
entrypoint: 'non_existent_entrypoint',
|
|
156
|
+
calldata: compileCalldata({
|
|
157
|
+
user: '0xdeadbeef',
|
|
158
|
+
}),
|
|
159
|
+
})
|
|
160
|
+
).rejects.toThrowError();
|
|
286
161
|
});
|
|
287
162
|
});
|
|
288
163
|
});
|
package/__tests__/fixtures.ts
CHANGED
|
@@ -28,7 +28,7 @@ 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
34
|
export const getTestProvider = () => {
|
|
@@ -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,7 @@ describeIfRpc('RPCProvider', () => {
|
|
|
22
23
|
|
|
23
24
|
test('getChainId', async () => {
|
|
24
25
|
const chainId = await rpcProvider.getChainId();
|
|
25
|
-
expect(chainId).toBe(
|
|
26
|
+
expect(chainId).toBe(StarknetChainId.TESTNET2);
|
|
26
27
|
});
|
|
27
28
|
|
|
28
29
|
test('getPendingTransactions', async () => {
|
|
@@ -115,9 +116,9 @@ describeIfRpc('RPCProvider', () => {
|
|
|
115
116
|
});
|
|
116
117
|
});
|
|
117
118
|
|
|
118
|
-
test('getClass classHash
|
|
119
|
+
test('getClass classHash 0x00808396477a4296946bf6574afb2e14723f8d9a37bba25a1e104315ca89b1f7', async () => {
|
|
119
120
|
const contractClass = await rpcProvider.getClass(
|
|
120
|
-
'
|
|
121
|
+
'0x00808396477a4296946bf6574afb2e14723f8d9a37bba25a1e104315ca89b1f7'
|
|
121
122
|
);
|
|
122
123
|
expect(contractClass).toHaveProperty('program');
|
|
123
124
|
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
|
+
});
|
package/account/default.d.ts
CHANGED
|
@@ -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>;
|
package/account/default.js
CHANGED
|
@@ -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");
|
|
@@ -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;
|
package/account/interface.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ProviderInterface } from '../provider';
|
|
|
2
2
|
import { BlockIdentifier } from '../provider/utils';
|
|
3
3
|
import { SignerInterface } from '../signer';
|
|
4
4
|
import { Abi, Call, DeclareContractResponse, DeployContractResponse, EstimateFeeAction, EstimateFeeDetails, EstimateFeeResponse, InvocationsDetails, InvokeFunctionResponse, Signature } from '../types';
|
|
5
|
-
import { AllowArray, DeclareContractPayload, DeployAccountContractPayload } from '../types/lib';
|
|
5
|
+
import { AllowArray, DeclareContractPayload, DeployAccountContractPayload, UniversalDeployerContractPayload } from '../types/lib';
|
|
6
6
|
import { BigNumberish } from '../utils/number';
|
|
7
7
|
import { TypedData } from '../utils/typedData/types';
|
|
8
8
|
export declare abstract class AccountInterface extends ProviderInterface {
|
|
@@ -45,7 +45,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
45
45
|
* Estimate Fee for executing a DEPLOY_ACCOUNT transaction on starknet
|
|
46
46
|
*
|
|
47
47
|
* @param contractPayload the payload object containing:
|
|
48
|
-
* - contract - the compiled contract to be
|
|
48
|
+
* - contract - the compiled contract to be deployed
|
|
49
49
|
* - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
|
|
50
50
|
*
|
|
51
51
|
* @returns response from estimate_fee
|
|
@@ -66,6 +66,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
66
66
|
abstract execute(transactions: AllowArray<Call>, abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
67
67
|
/**
|
|
68
68
|
* Declares a given compiled contract (json) to starknet
|
|
69
|
+
*
|
|
69
70
|
* @param contractPayload transaction payload to be deployed containing:
|
|
70
71
|
- contract: compiled contract code
|
|
71
72
|
- classHash: computed class hash of compiled contract
|
|
@@ -77,13 +78,27 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
77
78
|
* @returns a confirmation of sending a transaction on the starknet contract
|
|
78
79
|
*/
|
|
79
80
|
abstract declare(contractPayload: DeclareContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeclareContractResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* @param deployContractPayload containing
|
|
83
|
+
* - classHash: computed class hash of compiled contract
|
|
84
|
+
* - salt: address salt
|
|
85
|
+
* - unique: bool if true ensure unique salt
|
|
86
|
+
* - calldata: constructor calldata
|
|
87
|
+
* @param additionalCalls - optional additional calls array to support multicall
|
|
88
|
+
* @param transactionsDetail Invocation Details containing:
|
|
89
|
+
* - optional nonce
|
|
90
|
+
* - optional version
|
|
91
|
+
* - optional maxFee
|
|
92
|
+
*/
|
|
93
|
+
abstract deploy(deployContractPayload: UniversalDeployerContractPayload, additionalCalls?: AllowArray<Call>, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
80
94
|
/**
|
|
81
95
|
* Deploy the account on Starknet
|
|
96
|
+
*
|
|
82
97
|
* @param contractPayload transaction payload to be deployed containing:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
-
|
|
98
|
+
- classHash: computed class hash of compiled contract
|
|
99
|
+
- optional constructor calldata
|
|
100
|
+
- optional address salt
|
|
101
|
+
- optional contractAddress
|
|
87
102
|
* @param transactionsDetail Invocation Details containing:
|
|
88
103
|
- optional nonce
|
|
89
104
|
- optional version
|
|
@@ -112,7 +127,7 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
112
127
|
/**
|
|
113
128
|
* Verify a signature of a JSON object
|
|
114
129
|
*
|
|
115
|
-
* @param
|
|
130
|
+
* @param typedData - JSON object to be verified
|
|
116
131
|
* @param signature - signature of the JSON object
|
|
117
132
|
* @returns true if the signature is valid, false otherwise
|
|
118
133
|
* @throws {Error} if the JSON object is not a valid JSON or the signature is not a valid signature
|
|
@@ -130,12 +145,14 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
130
145
|
abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
|
|
131
146
|
/**
|
|
132
147
|
* Gets the nonce of the account with respect to a specific block
|
|
148
|
+
*
|
|
133
149
|
* @param {BlockIdentifier} blockIdentifier - optional blockIdentifier. Defaults to 'pending'
|
|
134
150
|
* @returns nonce of the account
|
|
135
151
|
*/
|
|
136
152
|
abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
137
153
|
/**
|
|
138
154
|
* Gets Suggested Max Fee based on the transaction type
|
|
155
|
+
*
|
|
139
156
|
* @param {EstimateFeeAction} estimateFeeAction
|
|
140
157
|
* @param {EstimateFeeDetails} details
|
|
141
158
|
* @returns suggestedMaxFee
|
package/constants.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ export declare const MASK_250: import("bn.js");
|
|
|
7
7
|
export declare const MASK_251: import("bn.js");
|
|
8
8
|
export declare enum StarknetChainId {
|
|
9
9
|
MAINNET = "0x534e5f4d41494e",
|
|
10
|
-
TESTNET = "0x534e5f474f45524c49"
|
|
10
|
+
TESTNET = "0x534e5f474f45524c49",
|
|
11
|
+
TESTNET2 = "0x534e5f474f45524c4932"
|
|
11
12
|
}
|
|
12
13
|
export declare enum TransactionHashPrefix {
|
|
13
14
|
DECLARE = "0x6465636c617265",
|
|
@@ -16,6 +17,11 @@ export declare enum TransactionHashPrefix {
|
|
|
16
17
|
INVOKE = "0x696e766f6b65",
|
|
17
18
|
L1_HANDLER = "0x6c315f68616e646c6572"
|
|
18
19
|
}
|
|
20
|
+
export declare const UDC: {
|
|
21
|
+
ADDRESS: string;
|
|
22
|
+
ENTRYPOINT: string;
|
|
23
|
+
ADDRESS_DEVNET: string;
|
|
24
|
+
};
|
|
19
25
|
/**
|
|
20
26
|
* The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default
|
|
21
27
|
* Please do not edit until the JSON changes.
|