starknet 3.5.0 → 3.7.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 +33 -0
- package/__tests__/account.test.ts +38 -20
- package/__tests__/accountContract.test.ts +0 -31
- package/__tests__/constancts.ts +2 -0
- package/__tests__/contract.test.ts +14 -21
- package/__tests__/provider.test.ts +8 -0
- package/account/default.d.ts +4 -1
- package/account/default.js +63 -14
- package/account/interface.d.ts +14 -0
- package/contract/default.d.ts +6 -6
- package/contract/default.js +28 -13
- package/contract/interface.d.ts +4 -4
- package/dist/account/default.d.ts +4 -2
- package/dist/account/default.js +50 -11
- package/dist/account/interface.d.ts +13 -1
- package/dist/contract/default.d.ts +6 -6
- package/dist/contract/default.js +23 -12
- package/dist/contract/interface.d.ts +4 -4
- package/dist/provider/default.d.ts +9 -2
- package/dist/provider/default.js +16 -11
- package/dist/signer/index.d.ts +1 -0
- package/dist/signer/index.js +1 -0
- package/dist/signer/ledger.d.ts +12 -0
- package/dist/signer/ledger.js +138 -0
- package/dist/types/api.d.ts +57 -2
- package/package.json +5 -2
- package/provider/default.d.ts +9 -1
- package/provider/default.js +19 -15
- package/signer/index.d.ts +1 -0
- package/signer/index.js +1 -0
- package/signer/ledger.d.ts +15 -0
- package/signer/ledger.js +243 -0
- package/src/account/default.ts +28 -6
- package/src/account/interface.ts +15 -0
- package/src/contract/default.ts +33 -28
- package/src/contract/interface.ts +4 -4
- package/src/provider/default.ts +13 -11
- package/src/signer/index.ts +1 -0
- package/src/signer/ledger.ts +81 -0
- package/src/types/api.ts +62 -3
- package/tsconfig.json +1 -10
- package/types/api.d.ts +57 -2
- package/www/README.md +41 -0
- package/www/babel.config.js +3 -0
- package/www/code-examples/account.js +62 -0
- package/www/code-examples/amm.js +49 -0
- package/www/code-examples/erc20.js +10 -0
- package/www/code-examples/package-lock.json +336 -0
- package/www/code-examples/package.json +15 -0
- package/www/docs/API/_category_.json +5 -0
- package/www/docs/API/account.md +11 -0
- package/www/docs/API/contract.md +14 -0
- package/www/docs/API/index.md +4 -0
- package/www/docs/API/provider.md +10 -0
- package/www/docs/API/signer.md +8 -0
- package/www/docusaurus.config.js +131 -0
- package/www/guides/account.md +60 -0
- package/www/guides/cra.md +3 -0
- package/www/guides/erc20.md +88 -0
- package/www/guides/intro.md +20 -0
- package/www/package-lock.json +22285 -0
- package/www/package.json +43 -0
- package/www/sidebars.js +31 -0
- package/www/src/components/HomepageFeatures/index.tsx +67 -0
- package/www/src/components/HomepageFeatures/styles.module.css +10 -0
- package/www/src/css/custom.css +39 -0
- package/www/src/pages/index.module.css +23 -0
- package/www/src/pages/index.tsx +40 -0
- package/www/src/pages/markdown-page.md +7 -0
- 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 +17 -0
- 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
- package/www/tsconfig.json +8 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import Eth from '@ledgerhq/hw-app-eth';
|
|
2
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
3
|
+
import TransportWebHID from '@ledgerhq/hw-transport-webhid';
|
|
4
|
+
|
|
5
|
+
import { Invocation, InvocationsSignerDetails, Signature } from '../types';
|
|
6
|
+
import { addHexPrefix } from '../utils/encode';
|
|
7
|
+
import { hashMulticall } from '../utils/hash';
|
|
8
|
+
import { TypedData, getMessageHash } from '../utils/typedData';
|
|
9
|
+
import { SignerInterface } from './interface';
|
|
10
|
+
|
|
11
|
+
function hexZeroPad(hash: string, length: number): string {
|
|
12
|
+
let value = hash;
|
|
13
|
+
if (value.length > 2 * length + 2) {
|
|
14
|
+
throw new Error('value out of range');
|
|
15
|
+
}
|
|
16
|
+
while (value.length < 2 * length + 2) {
|
|
17
|
+
value = `0x0${value.substring(2)}`;
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class LedgerBlindSigner implements SignerInterface {
|
|
23
|
+
public derivationPath = "/2645'/579218131'/1148870696'/0'/0'/0";
|
|
24
|
+
|
|
25
|
+
private transport: Transport | undefined;
|
|
26
|
+
|
|
27
|
+
private async getEthApp(): Promise<Eth> {
|
|
28
|
+
if (!this.transport) {
|
|
29
|
+
try {
|
|
30
|
+
this.transport = await TransportWebHID.create();
|
|
31
|
+
} catch {
|
|
32
|
+
throw new Error('Device connection error');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return new Eth(this.transport);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public async getPubKey(): Promise<string> {
|
|
39
|
+
const eth = await this.getEthApp();
|
|
40
|
+
const response = await eth.starkGetPublicKey(this.derivationPath);
|
|
41
|
+
const starkPub = `0x${response.slice(1, 1 + 32).toString('hex')}`;
|
|
42
|
+
return starkPub;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public async signTransaction(
|
|
46
|
+
transactions: Invocation[],
|
|
47
|
+
transactionsDetail: InvocationsSignerDetails
|
|
48
|
+
): Promise<Signature> {
|
|
49
|
+
const msgHash = hashMulticall(
|
|
50
|
+
transactionsDetail.walletAddress,
|
|
51
|
+
transactions,
|
|
52
|
+
transactionsDetail.nonce.toString(),
|
|
53
|
+
transactionsDetail.maxFee.toString()
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return this.sign(msgHash);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public async signMessage(typedData: TypedData, accountAddress: string): Promise<Signature> {
|
|
60
|
+
const msgHash = getMessageHash(typedData, accountAddress);
|
|
61
|
+
|
|
62
|
+
return this.sign(msgHash);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected async sign(msgHash: string): Promise<Signature> {
|
|
66
|
+
const eth = await this.getEthApp();
|
|
67
|
+
|
|
68
|
+
const {
|
|
69
|
+
r,
|
|
70
|
+
s,
|
|
71
|
+
}: {
|
|
72
|
+
r: string;
|
|
73
|
+
s: string;
|
|
74
|
+
} = (await eth.starkUnsafeSign(this.derivationPath, hexZeroPad(msgHash, 32))) as {
|
|
75
|
+
r: string;
|
|
76
|
+
s: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return [addHexPrefix(r), addHexPrefix(s)];
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/types/api.ts
CHANGED
|
@@ -36,6 +36,13 @@ export type Endpoints = {
|
|
|
36
36
|
REQUEST: never;
|
|
37
37
|
RESPONSE: GetTransactionStatusResponse;
|
|
38
38
|
};
|
|
39
|
+
get_transaction_trace: {
|
|
40
|
+
QUERY: {
|
|
41
|
+
transactionHash: string;
|
|
42
|
+
};
|
|
43
|
+
REQUEST: never;
|
|
44
|
+
RESPONSE: GetTransactionTraceResponse;
|
|
45
|
+
};
|
|
39
46
|
get_storage_at: {
|
|
40
47
|
QUERY: {
|
|
41
48
|
contractAddress: string;
|
|
@@ -69,7 +76,7 @@ export type Endpoints = {
|
|
|
69
76
|
};
|
|
70
77
|
estimate_fee: {
|
|
71
78
|
QUERY: never;
|
|
72
|
-
REQUEST:
|
|
79
|
+
REQUEST: CallContractTransaction;
|
|
73
80
|
RESPONSE: EstimateFeeResponse;
|
|
74
81
|
};
|
|
75
82
|
};
|
|
@@ -95,6 +102,33 @@ export type InvokeFunctionTransaction = {
|
|
|
95
102
|
entry_point_selector: string;
|
|
96
103
|
calldata?: RawCalldata;
|
|
97
104
|
nonce?: BigNumberish;
|
|
105
|
+
max_fee?: BigNumberish;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export type InvokeFunctionTrace = {
|
|
109
|
+
caller_address: string;
|
|
110
|
+
contract_address: string;
|
|
111
|
+
code_address: string;
|
|
112
|
+
selector: string;
|
|
113
|
+
calldata: RawCalldata;
|
|
114
|
+
result: Array<any>;
|
|
115
|
+
execution_resources: ExecutionResources;
|
|
116
|
+
internal_call: Array<InvokeFunctionTrace>;
|
|
117
|
+
events: Array<any>;
|
|
118
|
+
messages: Array<any>;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export type ExecutionResources = {
|
|
122
|
+
n_steps: number;
|
|
123
|
+
builtin_instance_counter: {
|
|
124
|
+
pedersen_builtin: number;
|
|
125
|
+
range_check_builtin: number;
|
|
126
|
+
bitwise_builtin: number;
|
|
127
|
+
output_builtin: number;
|
|
128
|
+
ecdsa_builtin: number;
|
|
129
|
+
ec_op_builtin: number;
|
|
130
|
+
};
|
|
131
|
+
n_memory_holes: number;
|
|
98
132
|
};
|
|
99
133
|
|
|
100
134
|
export type CallContractTransaction = Omit<
|
|
@@ -149,6 +183,22 @@ export type GetTransactionStatusResponse = {
|
|
|
149
183
|
};
|
|
150
184
|
};
|
|
151
185
|
|
|
186
|
+
export type GetTransactionTraceResponse = {
|
|
187
|
+
function_invocation: {
|
|
188
|
+
caller_address: string;
|
|
189
|
+
contract_address: string;
|
|
190
|
+
code_address: string;
|
|
191
|
+
selector: string;
|
|
192
|
+
calldata: RawArgs;
|
|
193
|
+
result: Array<any>;
|
|
194
|
+
execution_resources: any;
|
|
195
|
+
internal_call: Array<any>;
|
|
196
|
+
events: Array<any>;
|
|
197
|
+
messages: Array<any>;
|
|
198
|
+
};
|
|
199
|
+
signature: Signature;
|
|
200
|
+
};
|
|
201
|
+
|
|
152
202
|
export type GetTransactionResponse = {
|
|
153
203
|
status: Status;
|
|
154
204
|
transaction: Transaction;
|
|
@@ -173,11 +223,20 @@ export type TransactionReceipt = {
|
|
|
173
223
|
l2_to_l1_messages: string[];
|
|
174
224
|
events: string[];
|
|
175
225
|
};
|
|
176
|
-
|
|
177
|
-
export type EstimateFeeResponse = {
|
|
226
|
+
|
|
227
|
+
export type EstimateFeeResponse = {
|
|
228
|
+
amount: number;
|
|
229
|
+
unit: string;
|
|
230
|
+
};
|
|
178
231
|
|
|
179
232
|
export type RawArgs = {
|
|
180
233
|
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
|
|
181
234
|
};
|
|
182
235
|
|
|
183
236
|
export type Calldata = string[];
|
|
237
|
+
|
|
238
|
+
export type Overrides = {
|
|
239
|
+
maxFee?: BigNumberish;
|
|
240
|
+
nonce?: BigNumberish;
|
|
241
|
+
signature?: Signature;
|
|
242
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -103,14 +103,5 @@
|
|
|
103
103
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
104
104
|
},
|
|
105
105
|
"include": ["src/**/*"],
|
|
106
|
-
"exclude": ["node_modules"]
|
|
107
|
-
"typedocOptions": {
|
|
108
|
-
"entryPoints": "src/index.ts",
|
|
109
|
-
"entryPointStrategy": "expand",
|
|
110
|
-
"out": "docs",
|
|
111
|
-
"githubPages": false,
|
|
112
|
-
"readme": "./README.md",
|
|
113
|
-
"name": "StarkNet.js Docs",
|
|
114
|
-
"sort": "required-first"
|
|
115
|
-
}
|
|
106
|
+
"exclude": ["node_modules"]
|
|
116
107
|
}
|
package/types/api.d.ts
CHANGED
|
@@ -35,6 +35,13 @@ export declare type Endpoints = {
|
|
|
35
35
|
REQUEST: never;
|
|
36
36
|
RESPONSE: GetTransactionStatusResponse;
|
|
37
37
|
};
|
|
38
|
+
get_transaction_trace: {
|
|
39
|
+
QUERY: {
|
|
40
|
+
transactionHash: string;
|
|
41
|
+
};
|
|
42
|
+
REQUEST: never;
|
|
43
|
+
RESPONSE: GetTransactionTraceResponse;
|
|
44
|
+
};
|
|
38
45
|
get_storage_at: {
|
|
39
46
|
QUERY: {
|
|
40
47
|
contractAddress: string;
|
|
@@ -68,7 +75,7 @@ export declare type Endpoints = {
|
|
|
68
75
|
};
|
|
69
76
|
estimate_fee: {
|
|
70
77
|
QUERY: never;
|
|
71
|
-
REQUEST:
|
|
78
|
+
REQUEST: CallContractTransaction;
|
|
72
79
|
RESPONSE: EstimateFeeResponse;
|
|
73
80
|
};
|
|
74
81
|
};
|
|
@@ -91,6 +98,31 @@ export declare type InvokeFunctionTransaction = {
|
|
|
91
98
|
entry_point_selector: string;
|
|
92
99
|
calldata?: RawCalldata;
|
|
93
100
|
nonce?: BigNumberish;
|
|
101
|
+
max_fee?: BigNumberish;
|
|
102
|
+
};
|
|
103
|
+
export declare type InvokeFunctionTrace = {
|
|
104
|
+
caller_address: string;
|
|
105
|
+
contract_address: string;
|
|
106
|
+
code_address: string;
|
|
107
|
+
selector: string;
|
|
108
|
+
calldata: RawCalldata;
|
|
109
|
+
result: Array<any>;
|
|
110
|
+
execution_resources: ExecutionResources;
|
|
111
|
+
internal_call: Array<InvokeFunctionTrace>;
|
|
112
|
+
events: Array<any>;
|
|
113
|
+
messages: Array<any>;
|
|
114
|
+
};
|
|
115
|
+
export declare type ExecutionResources = {
|
|
116
|
+
n_steps: number;
|
|
117
|
+
builtin_instance_counter: {
|
|
118
|
+
pedersen_builtin: number;
|
|
119
|
+
range_check_builtin: number;
|
|
120
|
+
bitwise_builtin: number;
|
|
121
|
+
output_builtin: number;
|
|
122
|
+
ecdsa_builtin: number;
|
|
123
|
+
ec_op_builtin: number;
|
|
124
|
+
};
|
|
125
|
+
n_memory_holes: number;
|
|
94
126
|
};
|
|
95
127
|
export declare type CallContractTransaction = Omit<
|
|
96
128
|
InvokeFunctionTransaction,
|
|
@@ -138,6 +170,21 @@ export declare type GetTransactionStatusResponse = {
|
|
|
138
170
|
error_message: string;
|
|
139
171
|
};
|
|
140
172
|
};
|
|
173
|
+
export declare type GetTransactionTraceResponse = {
|
|
174
|
+
function_invocation: {
|
|
175
|
+
caller_address: string;
|
|
176
|
+
contract_address: string;
|
|
177
|
+
code_address: string;
|
|
178
|
+
selector: string;
|
|
179
|
+
calldata: RawArgs;
|
|
180
|
+
result: Array<any>;
|
|
181
|
+
execution_resources: any;
|
|
182
|
+
internal_call: Array<any>;
|
|
183
|
+
events: Array<any>;
|
|
184
|
+
messages: Array<any>;
|
|
185
|
+
};
|
|
186
|
+
signature: Signature;
|
|
187
|
+
};
|
|
141
188
|
export declare type GetTransactionResponse = {
|
|
142
189
|
status: Status;
|
|
143
190
|
transaction: Transaction;
|
|
@@ -160,7 +207,10 @@ export declare type TransactionReceipt = {
|
|
|
160
207
|
l2_to_l1_messages: string[];
|
|
161
208
|
events: string[];
|
|
162
209
|
};
|
|
163
|
-
export declare type EstimateFeeResponse = {
|
|
210
|
+
export declare type EstimateFeeResponse = {
|
|
211
|
+
amount: number;
|
|
212
|
+
unit: string;
|
|
213
|
+
};
|
|
164
214
|
export declare type RawArgs = {
|
|
165
215
|
[inputName: string]:
|
|
166
216
|
| string
|
|
@@ -171,3 +221,8 @@ export declare type RawArgs = {
|
|
|
171
221
|
};
|
|
172
222
|
};
|
|
173
223
|
export declare type Calldata = string[];
|
|
224
|
+
export declare type Overrides = {
|
|
225
|
+
maxFee?: BigNumberish;
|
|
226
|
+
nonce?: BigNumberish;
|
|
227
|
+
signature?: Signature;
|
|
228
|
+
};
|
package/www/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Website
|
|
2
|
+
|
|
3
|
+
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
$ yarn
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Local Development
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
$ yarn start
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
|
|
18
|
+
|
|
19
|
+
### Build
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
$ yarn build
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This command generates static content into the `build` directory and can be served using any static contents hosting service.
|
|
26
|
+
|
|
27
|
+
### Deployment
|
|
28
|
+
|
|
29
|
+
Using SSH:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
$ USE_SSH=true yarn deploy
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Not using SSH:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
$ GIT_USER=<Your GitHub username> yarn deploy
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
// Install the latest version of starknet with npm install starknet@next and import starknet
|
|
3
|
+
import * as starknet from "starknet";
|
|
4
|
+
|
|
5
|
+
// Generate public and private key pair.
|
|
6
|
+
|
|
7
|
+
const keyPair = starknet.ec.genKeyPair();
|
|
8
|
+
const starkKey = starknet.ec.getStarkKey(keyPair);
|
|
9
|
+
const starkKeyInt = starknet.number.toBN(starknet.encode.removeHexPrefix(starkKey), 16);
|
|
10
|
+
|
|
11
|
+
const { address: walletAddressLocal } = await provider.deployContract({contract: COMPILED_WALLET_CONTRACT_JSON, constructorCallData: [starkKeyInt], addressSalt: 0});
|
|
12
|
+
|
|
13
|
+
walletAddress = walletAddressLocal;
|
|
14
|
+
|
|
15
|
+
const { code: codeErc20, address: erc20AddressLocal } = await defaultProvider.deployContract({
|
|
16
|
+
contract: compiledErc20,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const erc20Address = erc20AddressLocal;
|
|
20
|
+
const erc20 = new Contract(compiledErc20.abi, erc20Address);
|
|
21
|
+
|
|
22
|
+
const { code: codeErc20Mint, transaction_hash: txErc20Mint } = await erc20.invoke('mint', {
|
|
23
|
+
recipient: walletAddress,
|
|
24
|
+
amount: '1000',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const balanceBeforeTransfer = await erc20.call('balance_of', {
|
|
28
|
+
user: walletAddress,
|
|
29
|
+
}).res;
|
|
30
|
+
|
|
31
|
+
console.log(number.toBN(res).toString())
|
|
32
|
+
|
|
33
|
+
const { nonce } = await wallet.call('get_nonce');
|
|
34
|
+
const msgHash = encode.addHexPrefix(
|
|
35
|
+
hash.hashMessage(
|
|
36
|
+
wallet.connectedTo,
|
|
37
|
+
erc20Address,
|
|
38
|
+
stark.getSelectorFromName('transfer'),
|
|
39
|
+
[erc20Address, '10'],
|
|
40
|
+
nonce.toString()
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const signature = ec.sign(starkKeyPair, msgHash);
|
|
45
|
+
const { code, transaction_hash } = await wallet.invoke(
|
|
46
|
+
'execute',
|
|
47
|
+
{
|
|
48
|
+
to: erc20Address,
|
|
49
|
+
selector: stark.getSelectorFromName('transfer'),
|
|
50
|
+
calldata: [erc20Address, '10'],
|
|
51
|
+
nonce: nonce.toString(),
|
|
52
|
+
},
|
|
53
|
+
signature
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
await defaultProvider.waitForTx(transaction_hash);
|
|
57
|
+
|
|
58
|
+
const balanceAfterTransfer = await erc20.call('balance_of', {
|
|
59
|
+
user: walletAddress,
|
|
60
|
+
}).res;
|
|
61
|
+
|
|
62
|
+
console.log('Balance after transfer', balanceAfterTransfer)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defaultProvider, stark } from 'starknet';
|
|
2
|
+
const { getSelectorFromName } = stark;
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* !! IMPORTANT NOTE !! When fees are introduced all function invocations will go through the account account contract and this example will be deprecated.
|
|
7
|
+
**/
|
|
8
|
+
|
|
9
|
+
const CONTRACT_ADDRESS =
|
|
10
|
+
"0x03e19baa6cb2078631bcdb34844f3f7879449a544c9ce722681a54af08cff4b9";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* invokeFunction() example
|
|
14
|
+
**/
|
|
15
|
+
|
|
16
|
+
/** Reset the liquidity pool **/
|
|
17
|
+
const addLiquidityResponse = await defaultProvider.LEGACYinvokeFunction(
|
|
18
|
+
{
|
|
19
|
+
contractAddress: CONTRACT_ADDRESS,
|
|
20
|
+
entrypoint: "init_pool",
|
|
21
|
+
calldata: ["1000000", "1000000"],
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
console.log(addLiquidityResponse);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* callContract() example
|
|
28
|
+
**/
|
|
29
|
+
|
|
30
|
+
/** Get the balance of the liquidity pool of token A **/
|
|
31
|
+
const poolBalanceTokenA = await defaultProvider.callContract({
|
|
32
|
+
contractAddress: CONTRACT_ADDRESS,
|
|
33
|
+
entrypoint: "get_pool_token_balance",
|
|
34
|
+
calldata: ["1"], // Account 1 (no account implemented)
|
|
35
|
+
});
|
|
36
|
+
const balanceA = poolBalanceTokenA.result[0];
|
|
37
|
+
console.log('token a liquidity pool balance: ', parseInt(balanceA, 16));
|
|
38
|
+
|
|
39
|
+
/** Get the balance of the liquidity pool of token B **/
|
|
40
|
+
const poolBalanceTokenB = await defaultProvider.callContract({
|
|
41
|
+
contractAddress: CONTRACT_ADDRESS,
|
|
42
|
+
entrypoint: "get_pool_token_balance",
|
|
43
|
+
calldata: ["2"],
|
|
44
|
+
});
|
|
45
|
+
const balanceB = poolBalanceTokenB.result[0];
|
|
46
|
+
console.log('token b liquidity pool balance: ', parseInt(balanceB, 16));
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/** Make a swap */
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as starknet from "starknet";
|
|
2
|
+
|
|
3
|
+
const keyPair = starknet.ec.genKeyPair();
|
|
4
|
+
const starkKey = starknet.ec.getStarkKey(keyPair);
|
|
5
|
+
const starkKeyInt = starknet.number.toBN(starknet.encode.removeHexPrefix(starkKey), 16);
|
|
6
|
+
|
|
7
|
+
const deployWalletTx = await provider.deployContract({contract: COMPILED_WALLET_CONTRACT_JSON, constructorCallData: [starkKeyInt], addressSalt: 0});
|
|
8
|
+
|
|
9
|
+
await defaultProvider.waitForTx(deployWalletTx.transaction_hash);
|
|
10
|
+
|