starknet 4.17.0 → 4.18.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 +20 -0
- package/README.md +2 -10
- package/dist/index.d.ts +27 -9
- package/dist/index.global.js +30 -13
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +30 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -1
- package/.babelrc +0 -6
- package/.commitlintrc +0 -22
- package/.eslintignore +0 -2
- package/.eslintrc +0 -28
- package/.prettierrc +0 -6
- package/.releaserc +0 -28
- package/CODE_OF_CONDUCT.md +0 -128
- package/CONTRIBUTING.md +0 -52
- package/__mocks__/Account.json +0 -25486
- package/__mocks__/ERC20.json +0 -40027
- package/__mocks__/TestDapp.json +0 -12962
- package/__mocks__/contract.json +0 -33191
- package/__mocks__/l1l2_compiled.json +0 -10107
- package/__mocks__/multicall.json +0 -8139
- package/__mocks__/naming_compiled.json +0 -53283
- package/__mocks__/starknetId_compiled.json +0 -44703
- package/__mocks__/typedDataExample.json +0 -35
- package/__mocks__/typedDataSessionExample.json +0 -42
- package/__mocks__/typedDataStructArrayExample.json +0 -44
- package/__tests__/account.test.ts +0 -345
- package/__tests__/contract.test.ts +0 -249
- package/__tests__/defaultProvider.test.ts +0 -177
- package/__tests__/fixtures.ts +0 -84
- package/__tests__/jest.setup.ts +0 -30
- package/__tests__/rpcProvider.test.ts +0 -132
- package/__tests__/sequencerProvider.test.ts +0 -123
- package/__tests__/utils/__snapshots__/ellipticalCurve.test.ts.snap +0 -5
- package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +0 -5
- package/__tests__/utils/__snapshots__/utils.test.ts.snap +0 -5
- package/__tests__/utils/address.test.ts +0 -45
- package/__tests__/utils/ellipticalCurve.test.ts +0 -91
- package/__tests__/utils/merkle.test.ts +0 -256
- package/__tests__/utils/shortString.test.ts +0 -22
- package/__tests__/utils/starknetId.test.ts +0 -53
- package/__tests__/utils/transactionHash.test.ts +0 -17
- package/__tests__/utils/typedData.test.ts +0 -223
- package/__tests__/utils/uint256.test.ts +0 -32
- package/__tests__/utils/utils.browser.test.ts +0 -29
- package/__tests__/utils/utils.test.ts +0 -141
- package/img/logo.svg +0 -17
- package/index.d.ts +0 -2683
- package/index.global.js +0 -23192
- package/index.global.js.map +0 -1
- package/index.js +0 -4910
- package/index.js.map +0 -1
- package/index.mjs +0 -4852
- package/index.mjs.map +0 -1
- package/src/account/default.ts +0 -501
- package/src/account/index.ts +0 -2
- package/src/account/interface.ts +0 -309
- package/src/constants.ts +0 -2065
- package/src/contract/contractFactory.ts +0 -88
- package/src/contract/default.ts +0 -425
- package/src/contract/index.ts +0 -3
- package/src/contract/interface.ts +0 -106
- package/src/index.ts +0 -26
- package/src/provider/default.ts +0 -187
- package/src/provider/errors.ts +0 -14
- package/src/provider/index.ts +0 -9
- package/src/provider/interface.ts +0 -281
- package/src/provider/rpc.ts +0 -482
- package/src/provider/sequencer.ts +0 -523
- package/src/provider/utils.ts +0 -100
- package/src/signer/default.ts +0 -99
- package/src/signer/index.ts +0 -2
- package/src/signer/interface.ts +0 -77
- package/src/types/account.ts +0 -43
- package/src/types/api/index.ts +0 -10
- package/src/types/api/openrpc.ts +0 -607
- package/src/types/api/rpc.ts +0 -45
- package/src/types/api/sequencer.ts +0 -369
- package/src/types/contract.ts +0 -5
- package/src/types/index.ts +0 -8
- package/src/types/lib.ts +0 -143
- package/src/types/provider.ts +0 -134
- package/src/types/signer.ts +0 -24
- package/src/utils/address.ts +0 -44
- package/src/utils/calldata.ts +0 -250
- package/src/utils/ellipticCurve.ts +0 -120
- package/src/utils/encode.ts +0 -66
- package/src/utils/events.ts +0 -32
- package/src/utils/fetchPonyfill.ts +0 -5
- package/src/utils/hash.ts +0 -235
- package/src/utils/json.ts +0 -15
- package/src/utils/merkle.ts +0 -69
- package/src/utils/number.ts +0 -98
- package/src/utils/provider.ts +0 -28
- package/src/utils/responseParser/index.ts +0 -28
- package/src/utils/responseParser/rpc.ts +0 -70
- package/src/utils/responseParser/sequencer.ts +0 -135
- package/src/utils/shortString.ts +0 -21
- package/src/utils/stark.ts +0 -57
- package/src/utils/starknetId.ts +0 -116
- package/src/utils/transaction.ts +0 -56
- package/src/utils/typedData/index.ts +0 -247
- package/src/utils/typedData/types.ts +0 -37
- package/src/utils/typedData/utils.ts +0 -16
- package/src/utils/uint256.ts +0 -32
- package/src/utils/url.ts +0 -53
- package/tsconfig.eslint.json +0 -4
- package/tsup.config.ts +0 -9
- package/www/README.md +0 -41
- package/www/babel.config.js +0 -3
- package/www/code-examples/account.js +0 -65
- package/www/code-examples/amm.js +0 -44
- package/www/code-examples/erc20.js +0 -13
- package/www/code-examples/package-lock.json +0 -336
- package/www/code-examples/package.json +0 -15
- package/www/docs/API/_category_.json +0 -5
- package/www/docs/API/account.md +0 -463
- package/www/docs/API/changelog.md +0 -15
- package/www/docs/API/contract.md +0 -135
- package/www/docs/API/contractFactory.md +0 -45
- package/www/docs/API/index.md +0 -3
- package/www/docs/API/provider.md +0 -725
- package/www/docs/API/signer.md +0 -105
- package/www/docs/API/utils.md +0 -374
- package/www/docusaurus.config.js +0 -130
- package/www/guides/account.md +0 -140
- package/www/guides/cra.md +0 -3
- package/www/guides/erc20.md +0 -163
- package/www/guides/intro.md +0 -63
- package/www/package-lock.json +0 -20405
- package/www/package.json +0 -43
- package/www/sidebars.js +0 -31
- package/www/src/components/HomepageFeatures/index.tsx +0 -67
- package/www/src/components/HomepageFeatures/styles.module.css +0 -10
- package/www/src/css/custom.css +0 -39
- package/www/src/pages/index.module.css +0 -23
- package/www/src/pages/index.tsx +0 -40
- package/www/src/pages/markdown-page.md +0 -7
- package/www/static/.nojekyll +0 -0
- package/www/static/img/docusaurus.png +0 -0
- package/www/static/img/favicon.ico +0 -0
- package/www/static/img/logo.svg +0 -17
- package/www/static/img/starknet-1.png +0 -0
- package/www/static/img/starknet-2.png +0 -0
- package/www/static/img/starknet-3.png +0 -0
- package/www/static/img/tutorial/docsVersionDropdown.png +0 -0
- package/www/static/img/tutorial/localeDropdown.png +0 -0
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"types": {
|
|
3
|
-
"StarkNetDomain": [
|
|
4
|
-
{ "name": "name", "type": "felt" },
|
|
5
|
-
{ "name": "version", "type": "felt" },
|
|
6
|
-
{ "name": "chainId", "type": "felt" }
|
|
7
|
-
],
|
|
8
|
-
"Person": [
|
|
9
|
-
{ "name": "name", "type": "felt" },
|
|
10
|
-
{ "name": "wallet", "type": "felt" }
|
|
11
|
-
],
|
|
12
|
-
"Mail": [
|
|
13
|
-
{ "name": "from", "type": "Person" },
|
|
14
|
-
{ "name": "to", "type": "Person" },
|
|
15
|
-
{ "name": "contents", "type": "felt" }
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
"primaryType": "Mail",
|
|
19
|
-
"domain": {
|
|
20
|
-
"name": "StarkNet Mail",
|
|
21
|
-
"version": "1",
|
|
22
|
-
"chainId": 1
|
|
23
|
-
},
|
|
24
|
-
"message": {
|
|
25
|
-
"from": {
|
|
26
|
-
"name": "Cow",
|
|
27
|
-
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
|
|
28
|
-
},
|
|
29
|
-
"to": {
|
|
30
|
-
"name": "Bob",
|
|
31
|
-
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
|
|
32
|
-
},
|
|
33
|
-
"contents": "Hello, Bob!"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"primaryType": "Session",
|
|
3
|
-
"types": {
|
|
4
|
-
"Policy": [
|
|
5
|
-
{ "name": "contractAddress", "type": "felt" },
|
|
6
|
-
{ "name": "selector", "type": "selector" }
|
|
7
|
-
],
|
|
8
|
-
"Session": [
|
|
9
|
-
{ "name": "key", "type": "felt" },
|
|
10
|
-
{ "name": "expires", "type": "felt" },
|
|
11
|
-
{ "name": "root", "type": "merkletree", "contains": "Policy" }
|
|
12
|
-
],
|
|
13
|
-
"StarkNetDomain": [
|
|
14
|
-
{ "name": "name", "type": "felt" },
|
|
15
|
-
{ "name": "version", "type": "felt" },
|
|
16
|
-
{ "name": "chain_id", "type": "felt" }
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
"domain": {
|
|
20
|
-
"name": "StarkNet Mail",
|
|
21
|
-
"version": "1",
|
|
22
|
-
"chain_id": 1
|
|
23
|
-
},
|
|
24
|
-
"message": {
|
|
25
|
-
"key": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
26
|
-
"expires": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
27
|
-
"root": [
|
|
28
|
-
{
|
|
29
|
-
"contractAddress": "0x1",
|
|
30
|
-
"selector": "transfer"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"contractAddress": "0x2",
|
|
34
|
-
"selector": "transfer"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"contractAddress": "0x3",
|
|
38
|
-
"selector": "transfer"
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"types": {
|
|
3
|
-
"StarkNetDomain": [
|
|
4
|
-
{ "name": "name", "type": "felt" },
|
|
5
|
-
{ "name": "version", "type": "felt" },
|
|
6
|
-
{ "name": "chainId", "type": "felt" }
|
|
7
|
-
],
|
|
8
|
-
"Person": [
|
|
9
|
-
{ "name": "name", "type": "felt" },
|
|
10
|
-
{ "name": "wallet", "type": "felt" }
|
|
11
|
-
],
|
|
12
|
-
"Post": [
|
|
13
|
-
{ "name": "title", "type": "felt" },
|
|
14
|
-
{ "name": "content", "type": "felt" }
|
|
15
|
-
],
|
|
16
|
-
"Mail": [
|
|
17
|
-
{ "name": "from", "type": "Person" },
|
|
18
|
-
{ "name": "to", "type": "Person" },
|
|
19
|
-
{ "name": "posts_len", "type": "felt" },
|
|
20
|
-
{ "name": "posts", "type": "Post*" }
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
"primaryType": "Mail",
|
|
24
|
-
"domain": {
|
|
25
|
-
"name": "StarkNet Mail",
|
|
26
|
-
"version": "1",
|
|
27
|
-
"chainId": 1
|
|
28
|
-
},
|
|
29
|
-
"message": {
|
|
30
|
-
"from": {
|
|
31
|
-
"name": "Cow",
|
|
32
|
-
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
|
|
33
|
-
},
|
|
34
|
-
"to": {
|
|
35
|
-
"name": "Bob",
|
|
36
|
-
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
|
|
37
|
-
},
|
|
38
|
-
"posts_len": 2,
|
|
39
|
-
"posts": [
|
|
40
|
-
{ "title": "Greeting", "content": "Hello, Bob!" },
|
|
41
|
-
{ "title": "Farewell", "content": "Goodbye, Bob!" }
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
import { isBN } from 'bn.js';
|
|
2
|
-
|
|
3
|
-
import typedDataExample from '../__mocks__/typedDataExample.json';
|
|
4
|
-
import { Account, Contract, Provider, number, stark } from '../src';
|
|
5
|
-
import { getKeyPair, sign } from '../src/utils/ellipticCurve';
|
|
6
|
-
import { parseUDCEvent } from '../src/utils/events';
|
|
7
|
-
import { feeTransactionVersion, pedersen } from '../src/utils/hash';
|
|
8
|
-
import { cleanHex, hexToDecimalString, toBN } from '../src/utils/number';
|
|
9
|
-
import { encodeShortString } from '../src/utils/shortString';
|
|
10
|
-
import { randomAddress } from '../src/utils/stark';
|
|
11
|
-
import {
|
|
12
|
-
compiledErc20,
|
|
13
|
-
compiledNamingContract,
|
|
14
|
-
compiledStarknetId,
|
|
15
|
-
compiledTestDapp,
|
|
16
|
-
erc20ClassHash,
|
|
17
|
-
getTestAccount,
|
|
18
|
-
getTestProvider,
|
|
19
|
-
} from './fixtures';
|
|
20
|
-
|
|
21
|
-
describe('deploy and test Wallet', () => {
|
|
22
|
-
const provider = getTestProvider();
|
|
23
|
-
const account = getTestAccount(provider);
|
|
24
|
-
let erc20: Contract;
|
|
25
|
-
let erc20Address: string;
|
|
26
|
-
let dapp: Contract;
|
|
27
|
-
|
|
28
|
-
beforeAll(async () => {
|
|
29
|
-
expect(account).toBeInstanceOf(Account);
|
|
30
|
-
|
|
31
|
-
const declareDeploy = await account.declareDeploy({
|
|
32
|
-
contract: compiledErc20,
|
|
33
|
-
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
34
|
-
constructorCalldata: [
|
|
35
|
-
encodeShortString('Token'),
|
|
36
|
-
encodeShortString('ERC20'),
|
|
37
|
-
account.address,
|
|
38
|
-
],
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
erc20Address = declareDeploy.deploy.contract_address;
|
|
42
|
-
erc20 = new Contract(compiledErc20.abi, erc20Address, provider);
|
|
43
|
-
|
|
44
|
-
const x = await erc20.balanceOf(account.address);
|
|
45
|
-
|
|
46
|
-
expect(number.toBN(x[0].low).toString()).toStrictEqual(number.toBN(1000).toString());
|
|
47
|
-
|
|
48
|
-
const dappResponse = await account.declareDeploy({
|
|
49
|
-
contract: compiledTestDapp,
|
|
50
|
-
classHash: '0x04367b26fbb92235e8d1137d19c080e6e650a6889ded726d00658411cc1046f5',
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
dapp = new Contract(compiledTestDapp.abi, dappResponse.deploy.contract_address!, provider);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('estimate fee', async () => {
|
|
57
|
-
const innerInvokeEstFeeSpy = jest.spyOn(account.signer, 'signTransaction');
|
|
58
|
-
const { overall_fee } = await account.estimateInvokeFee({
|
|
59
|
-
contractAddress: erc20Address,
|
|
60
|
-
entrypoint: 'transfer',
|
|
61
|
-
calldata: [erc20.address, '10', '0'],
|
|
62
|
-
});
|
|
63
|
-
expect(isBN(overall_fee)).toBe(true);
|
|
64
|
-
expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(feeTransactionVersion);
|
|
65
|
-
innerInvokeEstFeeSpy.mockClear();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('read balance of wallet', async () => {
|
|
69
|
-
const x = await erc20.balanceOf(account.address);
|
|
70
|
-
|
|
71
|
-
expect(number.toBN(x[0].low).toString()).toStrictEqual(number.toBN(1000).toString());
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('execute by wallet owner', async () => {
|
|
75
|
-
const { transaction_hash } = await account.execute({
|
|
76
|
-
contractAddress: erc20Address,
|
|
77
|
-
entrypoint: 'transfer',
|
|
78
|
-
calldata: [erc20.address, '10', '0'],
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
await provider.waitForTransaction(transaction_hash, undefined, ['ACCEPTED_ON_L2']);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('read balance of wallet after transfer', async () => {
|
|
85
|
-
const { balance } = await erc20.balanceOf(account.address);
|
|
86
|
-
|
|
87
|
-
expect(balance.low).toStrictEqual(toBN(990));
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test('execute with custom nonce', async () => {
|
|
91
|
-
const result = await account.getNonce();
|
|
92
|
-
const nonce = toBN(result).toNumber();
|
|
93
|
-
const { transaction_hash } = await account.execute(
|
|
94
|
-
{
|
|
95
|
-
contractAddress: erc20Address,
|
|
96
|
-
entrypoint: 'transfer',
|
|
97
|
-
calldata: [account.address, '10', '0'],
|
|
98
|
-
},
|
|
99
|
-
undefined,
|
|
100
|
-
{ nonce }
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
await provider.waitForTransaction(transaction_hash);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('execute multiple transactions', async () => {
|
|
107
|
-
const { transaction_hash } = await account.execute([
|
|
108
|
-
{
|
|
109
|
-
contractAddress: dapp.address,
|
|
110
|
-
entrypoint: 'set_number',
|
|
111
|
-
calldata: ['47'],
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
contractAddress: dapp.address,
|
|
115
|
-
entrypoint: 'increase_number',
|
|
116
|
-
calldata: ['10'],
|
|
117
|
-
},
|
|
118
|
-
]);
|
|
119
|
-
|
|
120
|
-
await provider.waitForTransaction(transaction_hash, undefined, ['ACCEPTED_ON_L2']);
|
|
121
|
-
|
|
122
|
-
const response = await dapp.get_number(account.address);
|
|
123
|
-
expect(toBN(response.number as string).toString()).toStrictEqual('57');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test('sign and verify offchain message fail', async () => {
|
|
127
|
-
const signature = await account.signMessage(typedDataExample);
|
|
128
|
-
// change the signature to make it invalid
|
|
129
|
-
signature[0] += '123';
|
|
130
|
-
expect(await account.verifyMessage(typedDataExample, signature)).toBe(false);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('sign and verify offchain message', async () => {
|
|
134
|
-
const signature = await account.signMessage(typedDataExample);
|
|
135
|
-
expect(await account.verifyMessage(typedDataExample, signature)).toBe(true);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('Contract interaction with Account', () => {
|
|
139
|
-
const wallet = stark.randomAddress();
|
|
140
|
-
|
|
141
|
-
beforeAll(async () => {
|
|
142
|
-
const mintResponse = await account.execute({
|
|
143
|
-
contractAddress: erc20Address,
|
|
144
|
-
entrypoint: 'mint',
|
|
145
|
-
calldata: [wallet, '1000', '0'],
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
await provider.waitForTransaction(mintResponse.transaction_hash);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test('change from provider to account', async () => {
|
|
152
|
-
expect(erc20.providerOrAccount instanceof Provider);
|
|
153
|
-
erc20.connect(account);
|
|
154
|
-
expect(erc20.providerOrAccount instanceof Account);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test('estimate gas fee for `mint`', async () => {
|
|
158
|
-
const res = await erc20.estimateFee.mint(wallet, ['10', '0']);
|
|
159
|
-
expect(res).toHaveProperty('overall_fee');
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test('Declare ERC20 contract', async () => {
|
|
163
|
-
const declareTx = await account.declare({
|
|
164
|
-
contract: compiledErc20,
|
|
165
|
-
classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
|
|
166
|
-
});
|
|
167
|
-
await provider.waitForTransaction(declareTx.transaction_hash);
|
|
168
|
-
|
|
169
|
-
expect(declareTx.class_hash).toBeDefined();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test('Get the stark name of the account and account from stark name (using starknet.id)', async () => {
|
|
173
|
-
// Deploy naming contract
|
|
174
|
-
const namingResponse = await account.declareDeploy({
|
|
175
|
-
contract: compiledNamingContract,
|
|
176
|
-
classHash: '0x3f2f8c80ab2d404bcfb4182e8528708e4efa2c646dd711bdd7b721ecc6111f7',
|
|
177
|
-
});
|
|
178
|
-
const namingAddress = namingResponse.deploy.contract_address;
|
|
179
|
-
|
|
180
|
-
// Deploy Starknet id contract
|
|
181
|
-
const idResponse = await account.declareDeploy({
|
|
182
|
-
contract: compiledStarknetId,
|
|
183
|
-
classHash: '0x1eb5a8308760d82321cb3ee8967581bb1d38348c7d2f082a07580040c52217c',
|
|
184
|
-
});
|
|
185
|
-
const idAddress = idResponse.deploy.contract_address;
|
|
186
|
-
|
|
187
|
-
// Create signature from private key
|
|
188
|
-
const whitelistingPublicKey =
|
|
189
|
-
'1893860513534673656759973582609638731665558071107553163765293299136715951024';
|
|
190
|
-
const whitelistingPrivateKey =
|
|
191
|
-
'301579081698031303837612923223391524790804435085778862878979120159194507372';
|
|
192
|
-
const hashed = pedersen([
|
|
193
|
-
pedersen([toBN('18925'), toBN('1922775124')]),
|
|
194
|
-
toBN(hexToDecimalString(account.address)),
|
|
195
|
-
]);
|
|
196
|
-
const keyPair = getKeyPair(toBN(whitelistingPrivateKey));
|
|
197
|
-
const signed = sign(keyPair, hashed);
|
|
198
|
-
|
|
199
|
-
const { transaction_hash } = await account.execute([
|
|
200
|
-
{
|
|
201
|
-
contractAddress: namingAddress,
|
|
202
|
-
entrypoint: 'initializer',
|
|
203
|
-
calldata: [
|
|
204
|
-
idAddress, // starknetid_contract_addr
|
|
205
|
-
'0', // pricing_contract_addr
|
|
206
|
-
account.address, // admin
|
|
207
|
-
whitelistingPublicKey, // whitelisting_key
|
|
208
|
-
'0', // l1_contract
|
|
209
|
-
],
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
contractAddress: idAddress,
|
|
213
|
-
entrypoint: 'mint',
|
|
214
|
-
calldata: ['1'], // TokenId
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
contractAddress: namingAddress,
|
|
218
|
-
entrypoint: 'whitelisted_mint',
|
|
219
|
-
calldata: [
|
|
220
|
-
'18925', // Domain encoded "ben"
|
|
221
|
-
'1922775124', // Expiry
|
|
222
|
-
'1', // Starknet id linked
|
|
223
|
-
account.address, // receiver_address
|
|
224
|
-
signed[0], // sig 0 for whitelist
|
|
225
|
-
signed[1], // sig 1 for whitelist
|
|
226
|
-
],
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
contractAddress: namingAddress,
|
|
230
|
-
entrypoint: 'set_address_to_domain',
|
|
231
|
-
calldata: [
|
|
232
|
-
'1', // length
|
|
233
|
-
'18925', // Domain encoded "ben"
|
|
234
|
-
],
|
|
235
|
-
},
|
|
236
|
-
]);
|
|
237
|
-
|
|
238
|
-
await provider.waitForTransaction(transaction_hash);
|
|
239
|
-
|
|
240
|
-
const address = await account.getAddressFromStarkName('ben.stark', namingAddress);
|
|
241
|
-
expect(hexToDecimalString(address as string)).toEqual(hexToDecimalString(account.address));
|
|
242
|
-
|
|
243
|
-
const name = await account.getStarkName(namingAddress);
|
|
244
|
-
expect(name).toEqual('ben.stark');
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
describe('Declare and UDC Deploy Flow', () => {
|
|
249
|
-
test('ERC20 Declare', async () => {
|
|
250
|
-
const declareTx = await account.declare({
|
|
251
|
-
classHash: erc20ClassHash,
|
|
252
|
-
contract: compiledErc20,
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
await provider.waitForTransaction(declareTx.transaction_hash);
|
|
256
|
-
|
|
257
|
-
expect(declareTx).toHaveProperty('class_hash');
|
|
258
|
-
expect(hexToDecimalString(declareTx.class_hash)).toEqual(hexToDecimalString(erc20ClassHash));
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test('UDC DeployContract', async () => {
|
|
262
|
-
const deployResponse = await account.deployContract({
|
|
263
|
-
classHash: erc20ClassHash,
|
|
264
|
-
constructorCalldata: [
|
|
265
|
-
encodeShortString('Token'),
|
|
266
|
-
encodeShortString('ERC20'),
|
|
267
|
-
account.address,
|
|
268
|
-
],
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
expect(deployResponse.contract_address).toBeDefined();
|
|
272
|
-
expect(deployResponse.transaction_hash).toBeDefined();
|
|
273
|
-
expect(deployResponse.address).toBeDefined();
|
|
274
|
-
expect(deployResponse.deployer).toBeDefined();
|
|
275
|
-
expect(deployResponse.unique).toBeDefined();
|
|
276
|
-
expect(deployResponse.classHash).toBeDefined();
|
|
277
|
-
expect(deployResponse.calldata_len).toBeDefined();
|
|
278
|
-
expect(deployResponse.calldata).toBeDefined();
|
|
279
|
-
expect(deployResponse.salt).toBeDefined();
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
test('UDC Deploy unique', async () => {
|
|
283
|
-
const salt = randomAddress(); // use random salt
|
|
284
|
-
|
|
285
|
-
const deployment = await account.deploy({
|
|
286
|
-
classHash: erc20ClassHash,
|
|
287
|
-
constructorCalldata: [
|
|
288
|
-
encodeShortString('Token'),
|
|
289
|
-
encodeShortString('ERC20'),
|
|
290
|
-
account.address,
|
|
291
|
-
],
|
|
292
|
-
salt,
|
|
293
|
-
unique: true,
|
|
294
|
-
});
|
|
295
|
-
expect(deployment).toHaveProperty('transaction_hash');
|
|
296
|
-
|
|
297
|
-
// check pre-calculated address
|
|
298
|
-
const txReceipt = await provider.waitForTransaction(deployment.transaction_hash);
|
|
299
|
-
const udcEvent = parseUDCEvent(txReceipt);
|
|
300
|
-
expect(cleanHex(deployment.contract_address[0])).toBe(cleanHex(udcEvent.contract_address));
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
test('UDC Deploy non-unique', async () => {
|
|
304
|
-
const salt = randomAddress(); // use random salt
|
|
305
|
-
|
|
306
|
-
const deployment = await account.deploy({
|
|
307
|
-
classHash: erc20ClassHash,
|
|
308
|
-
constructorCalldata: [
|
|
309
|
-
encodeShortString('Token'),
|
|
310
|
-
encodeShortString('ERC20'),
|
|
311
|
-
account.address,
|
|
312
|
-
],
|
|
313
|
-
salt,
|
|
314
|
-
unique: false,
|
|
315
|
-
});
|
|
316
|
-
expect(deployment).toHaveProperty('transaction_hash');
|
|
317
|
-
|
|
318
|
-
// check pre-calculated address
|
|
319
|
-
const txReceipt = await provider.waitForTransaction(deployment.transaction_hash);
|
|
320
|
-
const udcEvent = parseUDCEvent(txReceipt);
|
|
321
|
-
expect(cleanHex(deployment.contract_address[0])).toBe(cleanHex(udcEvent.contract_address));
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
test('UDC multi Deploy', async () => {
|
|
325
|
-
const deployments = await account.deploy([
|
|
326
|
-
{
|
|
327
|
-
classHash: '0x04367b26fbb92235e8d1137d19c080e6e650a6889ded726d00658411cc1046f5',
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
classHash: erc20ClassHash,
|
|
331
|
-
constructorCalldata: [
|
|
332
|
-
encodeShortString('Token'),
|
|
333
|
-
encodeShortString('ERC20'),
|
|
334
|
-
account.address,
|
|
335
|
-
],
|
|
336
|
-
},
|
|
337
|
-
]);
|
|
338
|
-
expect(deployments).toHaveProperty('transaction_hash');
|
|
339
|
-
expect(deployments.contract_address[0]).toBeDefined();
|
|
340
|
-
expect(deployments.contract_address[1]).toBeDefined();
|
|
341
|
-
|
|
342
|
-
await provider.waitForTransaction(deployments.transaction_hash);
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
});
|