starknet 3.5.1 → 3.8.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 +39 -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 +14 -1
- package/account/default.js +78 -14
- package/account/interface.d.ts +14 -0
- package/contract/default.d.ts +13 -3
- package/contract/default.js +36 -25
- package/contract/interface.d.ts +21 -3
- package/dist/account/default.d.ts +8 -2
- package/dist/account/default.js +57 -11
- package/dist/account/interface.d.ts +13 -1
- package/dist/contract/default.d.ts +7 -4
- package/dist/contract/default.js +27 -24
- package/dist/contract/interface.d.ts +9 -4
- package/dist/provider/default.d.ts +11 -4
- package/dist/provider/default.js +34 -30
- package/dist/provider/utils.d.ts +1 -2
- package/dist/provider/utils.js +7 -8
- 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 +60 -3
- package/package.json +5 -2
- package/provider/default.d.ts +13 -3
- package/provider/default.js +49 -42
- package/provider/utils.d.ts +1 -2
- package/provider/utils.js +7 -8
- 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 +40 -6
- package/src/account/interface.ts +15 -0
- package/src/contract/default.ts +37 -34
- package/src/contract/interface.ts +21 -3
- package/src/provider/default.ts +31 -23
- package/src/provider/utils.ts +7 -8
- package/src/signer/index.ts +1 -0
- package/src/signer/ledger.ts +81 -0
- package/src/types/api.ts +65 -4
- package/tsconfig.json +1 -10
- package/types/api.d.ts +60 -3
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
+
# [3.8.0](https://github.com/seanjameshan/starknet.js/compare/v3.7.0...v3.8.0) (2022-04-04)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- getBlock should not default to pending block ([7a641b5](https://github.com/seanjameshan/starknet.js/commit/7a641b55c3c762dada70814bf509b147f0cd315e))
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- complete interface ([39d2f05](https://github.com/seanjameshan/starknet.js/commit/39d2f0574691e4b37a6050831b4e548b07a8e3e3))
|
|
10
|
+
- default estimateFee to pending block ([719dda5](https://github.com/seanjameshan/starknet.js/commit/719dda5f33a2bed353bd1bf311a2baf3110d1654))
|
|
11
|
+
- default to pending block ([d3c1bdc](https://github.com/seanjameshan/starknet.js/commit/d3c1bdcdca996bce273673cf9c8220156e965863))
|
|
12
|
+
- pending as success ([9e79288](https://github.com/seanjameshan/starknet.js/commit/9e7928845cc1e7088ba9a8dc9ba8fb9311970440))
|
|
13
|
+
|
|
14
|
+
# [3.7.0](https://github.com/seanjameshan/starknet.js/compare/v3.6.0...v3.7.0) (2022-03-24)
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
- **Account:** account constructor should take a KeyPair or a Signer as parameter ([ea6ae40](https://github.com/seanjameshan/starknet.js/commit/ea6ae40225d33e293b9d2de7c8509e87fb7a651e))
|
|
19
|
+
- add BigInt support within BigNumberish ([e42427a](https://github.com/seanjameshan/starknet.js/commit/e42427afa9a57673576da68cfbbee1356ffb5c0d))
|
|
20
|
+
- using typeguard to narrow variable's type in Account's constructor ([ed048f3](https://github.com/seanjameshan/starknet.js/commit/ed048f355bee815cc9b2ccc984db900059fa2303))
|
|
21
|
+
|
|
22
|
+
# [3.6.0](https://github.com/seanjameshan/starknet.js/compare/v3.5.1...v3.6.0) (2022-03-24)
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
- **account:** estimate fee transfered from provider to account class ([93e7dd9](https://github.com/seanjameshan/starknet.js/commit/93e7dd941b35bccb67cc426b9ae546801092964c))
|
|
27
|
+
- formatting ([248246f](https://github.com/seanjameshan/starknet.js/commit/248246f2fe75b9897700b955fa98e1779aec1744))
|
|
28
|
+
- link ([494e000](https://github.com/seanjameshan/starknet.js/commit/494e0005c3b1cb86f5de0f25a10cbbe786a87b34))
|
|
29
|
+
- **provider:** estimateFee entrypoint conversion fix ([e40204a](https://github.com/seanjameshan/starknet.js/commit/e40204a2eca5f475fe50a88349fd4890bbc36790))
|
|
30
|
+
- **provider:** estimation fee response type ([ce674ca](https://github.com/seanjameshan/starknet.js/commit/ce674ca632ff70a07d95d685c9bf2f48bebaca20))
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
- add LedgerSigner class + blind signing ([9b700f3](https://github.com/seanjameshan/starknet.js/commit/9b700f300a91a0967f8827d0ecdd69e531738ec4))
|
|
35
|
+
- **contract:** contract expanded with estimateFee method ([fbaf4ba](https://github.com/seanjameshan/starknet.js/commit/fbaf4bab56ace0917ce7c66ecf90f8e2d0dc7f60))
|
|
36
|
+
- improvements after PR reviewing ([9f30e20](https://github.com/seanjameshan/starknet.js/commit/9f30e20c2e5d2afafe4eae58c597b82dffc3bbe2))
|
|
37
|
+
- new improvements after new PR review ([2e16808](https://github.com/seanjameshan/starknet.js/commit/2e168082b0042f27336946639f3948e91bc5f641))
|
|
38
|
+
- **provider:** provider expanded with getTransactionTrace ([b67361a](https://github.com/seanjameshan/starknet.js/commit/b67361ad7c50218e00273c097426e14814441404))
|
|
39
|
+
|
|
1
40
|
## [3.5.1](https://github.com/seanjameshan/starknet.js/compare/v3.5.0...v3.5.1) (2022-03-11)
|
|
2
41
|
|
|
3
42
|
### Bug Fixes
|
|
@@ -44,6 +44,16 @@ describe('deploy and test Wallet', () => {
|
|
|
44
44
|
await defaultProvider.waitForTransaction(dappResponse.transaction_hash);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
+
test('estimate fee', async () => {
|
|
48
|
+
const { amount, unit } = await account.estimateFee({
|
|
49
|
+
contractAddress: erc20Address,
|
|
50
|
+
entrypoint: 'transfer',
|
|
51
|
+
calldata: [erc20.address, '10'],
|
|
52
|
+
});
|
|
53
|
+
expect(typeof amount).toBe('number');
|
|
54
|
+
expect(typeof unit).toBe('string');
|
|
55
|
+
});
|
|
56
|
+
|
|
47
57
|
test('same wallet address', () => {
|
|
48
58
|
expect(account.address).toBe(account.address);
|
|
49
59
|
});
|
|
@@ -65,11 +75,15 @@ describe('deploy and test Wallet', () => {
|
|
|
65
75
|
});
|
|
66
76
|
|
|
67
77
|
test('execute by wallet owner', async () => {
|
|
68
|
-
const { code, transaction_hash } = await account.execute(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
const { code, transaction_hash } = await account.execute(
|
|
79
|
+
{
|
|
80
|
+
contractAddress: erc20Address,
|
|
81
|
+
entrypoint: 'transfer',
|
|
82
|
+
calldata: [erc20.address, '10'],
|
|
83
|
+
},
|
|
84
|
+
undefined,
|
|
85
|
+
{ maxFee: '0' }
|
|
86
|
+
);
|
|
73
87
|
|
|
74
88
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
75
89
|
await defaultProvider.waitForTransaction(transaction_hash);
|
|
@@ -78,7 +92,7 @@ describe('deploy and test Wallet', () => {
|
|
|
78
92
|
test('read balance of wallet after transfer', async () => {
|
|
79
93
|
const { res } = await erc20.balance_of(account.address);
|
|
80
94
|
|
|
81
|
-
expect(
|
|
95
|
+
expect(res).toStrictEqual(toBN(990));
|
|
82
96
|
});
|
|
83
97
|
|
|
84
98
|
test('execute with custom nonce', async () => {
|
|
@@ -91,10 +105,10 @@ describe('deploy and test Wallet', () => {
|
|
|
91
105
|
{
|
|
92
106
|
contractAddress: erc20Address,
|
|
93
107
|
entrypoint: 'transfer',
|
|
94
|
-
calldata: [
|
|
108
|
+
calldata: [account.address, '10'],
|
|
95
109
|
},
|
|
96
110
|
undefined,
|
|
97
|
-
{ nonce }
|
|
111
|
+
{ nonce, maxFee: '0' }
|
|
98
112
|
);
|
|
99
113
|
|
|
100
114
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
@@ -102,18 +116,22 @@ describe('deploy and test Wallet', () => {
|
|
|
102
116
|
});
|
|
103
117
|
|
|
104
118
|
test('execute multiple transactions', async () => {
|
|
105
|
-
const { code, transaction_hash } = await account.execute(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
const { code, transaction_hash } = await account.execute(
|
|
120
|
+
[
|
|
121
|
+
{
|
|
122
|
+
contractAddress: dapp.address,
|
|
123
|
+
entrypoint: 'set_number',
|
|
124
|
+
calldata: ['47'],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
contractAddress: dapp.address,
|
|
128
|
+
entrypoint: 'increase_number',
|
|
129
|
+
calldata: ['10'],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
undefined,
|
|
133
|
+
{ maxFee: '0' }
|
|
134
|
+
);
|
|
117
135
|
|
|
118
136
|
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
119
137
|
await defaultProvider.waitForTransaction(transaction_hash);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Contract, defaultProvider, ec, hash, number, stark } from '../src';
|
|
2
|
-
import { transformCallsToMulticallArrays } from '../src/utils/transaction';
|
|
3
2
|
import { compiledArgentAccount, compiledErc20 } from './fixtures';
|
|
4
3
|
|
|
5
4
|
describe('getStarkAccountFromPrivateKey()', () => {
|
|
@@ -64,36 +63,6 @@ describe('deploy and test Wallet', () => {
|
|
|
64
63
|
|
|
65
64
|
expect(res).toStrictEqual(number.toBN(1000));
|
|
66
65
|
});
|
|
67
|
-
|
|
68
|
-
test('execute by wallet owner', async () => {
|
|
69
|
-
const nonce = (await accountContract.get_nonce()).nonce.toString();
|
|
70
|
-
|
|
71
|
-
const calls = [
|
|
72
|
-
{ contractAddress: erc20Address, entrypoint: 'transfer', calldata: [erc20Address, '10'] },
|
|
73
|
-
];
|
|
74
|
-
const msgHash = hash.hashMulticall(accountContract.address, calls, nonce, '0');
|
|
75
|
-
|
|
76
|
-
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
77
|
-
|
|
78
|
-
const signature = ec.sign(starkKeyPair, msgHash);
|
|
79
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
80
|
-
const { code, transaction_hash } = await accountContract.__execute__(
|
|
81
|
-
callArray,
|
|
82
|
-
calldata,
|
|
83
|
-
nonce,
|
|
84
|
-
signature
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
expect(code).toBe('TRANSACTION_RECEIVED');
|
|
88
|
-
|
|
89
|
-
await defaultProvider.waitForTransaction(transaction_hash);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('read balance of wallet after transfer', async () => {
|
|
93
|
-
const { res } = await erc20.balance_of(accountContract.address);
|
|
94
|
-
|
|
95
|
-
expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
|
|
96
|
-
});
|
|
97
66
|
});
|
|
98
67
|
|
|
99
68
|
test('build tx', async () => {
|
|
@@ -4,12 +4,8 @@ import { Account, Contract, ContractFactory, Provider, defaultProvider, ec, star
|
|
|
4
4
|
import { getSelectorFromName } from '../src/utils/hash';
|
|
5
5
|
import { BigNumberish, toBN } from '../src/utils/number';
|
|
6
6
|
import { compileCalldata } from '../src/utils/stark';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
compiledErc20,
|
|
10
|
-
compiledMulticall,
|
|
11
|
-
compiledTypeTransformation,
|
|
12
|
-
} from './fixtures';
|
|
7
|
+
import { ACCOUNT_ADDRESS, PRIVATE_KEY } from './constancts';
|
|
8
|
+
import { compiledErc20, compiledMulticall, compiledTypeTransformation } from './fixtures';
|
|
13
9
|
|
|
14
10
|
describe('class Contract {}', () => {
|
|
15
11
|
const wallet = stark.randomAddress();
|
|
@@ -50,6 +46,10 @@ describe('class Contract {}', () => {
|
|
|
50
46
|
expect(res).toHaveProperty('signature');
|
|
51
47
|
});
|
|
52
48
|
|
|
49
|
+
test('estimate gas fee for `mint` should fail when connected to the provider', async () => {
|
|
50
|
+
expect(erc20.estimateFee.mint(wallet, '10')).rejects.toThrow();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
53
|
test('read initial balance of that account', async () => {
|
|
54
54
|
const result = await erc20.balance_of(wallet);
|
|
55
55
|
const [res] = result;
|
|
@@ -204,26 +204,13 @@ describe('class Contract {}', () => {
|
|
|
204
204
|
});
|
|
205
205
|
|
|
206
206
|
describe('Contract interaction with Account', () => {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
const starkKeyPair = ec.getKeyPair(privateKey);
|
|
210
|
-
const starkKeyPub = ec.getStarkKey(starkKeyPair);
|
|
207
|
+
const starkKeyPair = ec.getKeyPair(PRIVATE_KEY);
|
|
211
208
|
let account: Account;
|
|
212
209
|
let erc20: Contract;
|
|
213
210
|
let erc20Address: string;
|
|
214
211
|
|
|
215
212
|
beforeAll(async () => {
|
|
216
|
-
|
|
217
|
-
contract: compiledArgentAccount,
|
|
218
|
-
addressSalt: starkKeyPub,
|
|
219
|
-
});
|
|
220
|
-
const contract = new Contract(compiledArgentAccount.abi, accountResponse.address);
|
|
221
|
-
expect(accountResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
222
|
-
|
|
223
|
-
const initializeResponse = await contract.initialize(starkKeyPub, '0');
|
|
224
|
-
expect(initializeResponse.code).toBe('TRANSACTION_RECEIVED');
|
|
225
|
-
|
|
226
|
-
account = new Account(defaultProvider, accountResponse.address, starkKeyPair);
|
|
213
|
+
account = new Account(defaultProvider, ACCOUNT_ADDRESS, starkKeyPair);
|
|
227
214
|
|
|
228
215
|
const erc20Response = await defaultProvider.deployContract({
|
|
229
216
|
contract: compiledErc20,
|
|
@@ -251,6 +238,12 @@ describe('class Contract {}', () => {
|
|
|
251
238
|
expect(erc20.providerOrAccount instanceof Account);
|
|
252
239
|
});
|
|
253
240
|
|
|
241
|
+
test('estimate gas fee for `mint`', async () => {
|
|
242
|
+
const res = await erc20.estimateFee.mint(wallet, '10');
|
|
243
|
+
expect(res).toHaveProperty('amount');
|
|
244
|
+
expect(res).toHaveProperty('unit');
|
|
245
|
+
});
|
|
246
|
+
|
|
254
247
|
test('read balance of wallet', async () => {
|
|
255
248
|
const { res } = await erc20.balance_of(account.address);
|
|
256
249
|
|
|
@@ -93,6 +93,14 @@ describe('defaultProvider', () => {
|
|
|
93
93
|
})
|
|
94
94
|
).resolves.not.toThrow();
|
|
95
95
|
});
|
|
96
|
+
|
|
97
|
+
test('transaction trace', async () => {
|
|
98
|
+
const transactionTrace = await defaultProvider.getTransactionTrace(
|
|
99
|
+
'0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
|
|
100
|
+
);
|
|
101
|
+
expect(transactionTrace).toHaveProperty('function_invocation');
|
|
102
|
+
expect(transactionTrace).toHaveProperty('signature');
|
|
103
|
+
});
|
|
96
104
|
});
|
|
97
105
|
|
|
98
106
|
describe('addTransaction()', () => {
|
package/account/default.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
|
+
import { SignerInterface } from '../signer';
|
|
2
4
|
import {
|
|
3
5
|
Abi,
|
|
4
6
|
AddTransactionResponse,
|
|
5
7
|
Call,
|
|
8
|
+
EstimateFeeResponse,
|
|
6
9
|
InvocationsDetails,
|
|
7
10
|
KeyPair,
|
|
8
11
|
Signature,
|
|
@@ -14,8 +17,18 @@ import { AccountInterface } from './interface';
|
|
|
14
17
|
export declare class Account extends Provider implements AccountInterface {
|
|
15
18
|
address: string;
|
|
16
19
|
private signer;
|
|
17
|
-
constructor(provider: Provider, address: string,
|
|
20
|
+
constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
18
21
|
getNonce(): Promise<string>;
|
|
22
|
+
estimateFee(
|
|
23
|
+
calls: Call | Call[],
|
|
24
|
+
{
|
|
25
|
+
nonce: providedNonce,
|
|
26
|
+
blockIdentifier,
|
|
27
|
+
}?: {
|
|
28
|
+
nonce?: BigNumberish;
|
|
29
|
+
blockIdentifier?: BlockIdentifier;
|
|
30
|
+
}
|
|
31
|
+
): Promise<EstimateFeeResponse>;
|
|
19
32
|
/**
|
|
20
33
|
* Invoke execute function in account contract
|
|
21
34
|
*
|
package/account/default.js
CHANGED
|
@@ -207,9 +207,10 @@ var transaction_1 = require('../utils/transaction');
|
|
|
207
207
|
var typedData_1 = require('../utils/typedData');
|
|
208
208
|
var Account = /** @class */ (function (_super) {
|
|
209
209
|
__extends(Account, _super);
|
|
210
|
-
function Account(provider, address,
|
|
210
|
+
function Account(provider, address, keyPairOrSigner) {
|
|
211
211
|
var _this = _super.call(this, provider) || this;
|
|
212
|
-
_this.signer =
|
|
212
|
+
_this.signer =
|
|
213
|
+
'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new signer_1.Signer(keyPairOrSigner);
|
|
213
214
|
_this.address = address;
|
|
214
215
|
return _this;
|
|
215
216
|
}
|
|
@@ -233,6 +234,61 @@ var Account = /** @class */ (function (_super) {
|
|
|
233
234
|
});
|
|
234
235
|
});
|
|
235
236
|
};
|
|
237
|
+
Account.prototype.estimateFee = function (calls, _a) {
|
|
238
|
+
var _b = _a === void 0 ? {} : _a,
|
|
239
|
+
providedNonce = _b.nonce,
|
|
240
|
+
_c = _b.blockIdentifier,
|
|
241
|
+
blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
242
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
+
var transactions, nonce, _d, signerDetails, signature, calldata;
|
|
244
|
+
return __generator(this, function (_e) {
|
|
245
|
+
switch (_e.label) {
|
|
246
|
+
case 0:
|
|
247
|
+
transactions = Array.isArray(calls) ? calls : [calls];
|
|
248
|
+
if (!(providedNonce !== null && providedNonce !== void 0)) return [3 /*break*/, 1];
|
|
249
|
+
_d = providedNonce;
|
|
250
|
+
return [3 /*break*/, 3];
|
|
251
|
+
case 1:
|
|
252
|
+
return [4 /*yield*/, this.getNonce()];
|
|
253
|
+
case 2:
|
|
254
|
+
_d = _e.sent();
|
|
255
|
+
_e.label = 3;
|
|
256
|
+
case 3:
|
|
257
|
+
nonce = _d;
|
|
258
|
+
signerDetails = {
|
|
259
|
+
walletAddress: this.address,
|
|
260
|
+
nonce: (0, number_1.toBN)(nonce),
|
|
261
|
+
maxFee: (0, number_1.toBN)('0'),
|
|
262
|
+
};
|
|
263
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
264
|
+
case 4:
|
|
265
|
+
signature = _e.sent();
|
|
266
|
+
calldata = __spreadArray(
|
|
267
|
+
__spreadArray(
|
|
268
|
+
[],
|
|
269
|
+
__read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)),
|
|
270
|
+
false
|
|
271
|
+
),
|
|
272
|
+
[signerDetails.nonce.toString()],
|
|
273
|
+
false
|
|
274
|
+
);
|
|
275
|
+
return [
|
|
276
|
+
2 /*return*/,
|
|
277
|
+
this.fetchEndpoint(
|
|
278
|
+
'estimate_fee',
|
|
279
|
+
{ blockIdentifier: blockIdentifier },
|
|
280
|
+
{
|
|
281
|
+
contract_address: this.address,
|
|
282
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
283
|
+
calldata: calldata,
|
|
284
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
285
|
+
}
|
|
286
|
+
),
|
|
287
|
+
];
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
};
|
|
236
292
|
/**
|
|
237
293
|
* Invoke execute function in account contract
|
|
238
294
|
*
|
|
@@ -250,15 +306,11 @@ var Account = /** @class */ (function (_super) {
|
|
|
250
306
|
transactionsDetail = {};
|
|
251
307
|
}
|
|
252
308
|
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
var transactions,
|
|
254
|
-
var _e;
|
|
309
|
+
var transactions, nonce, _c, _d, maxFee, _e, signerDetails, signature, calldata;
|
|
255
310
|
return __generator(this, function (_f) {
|
|
256
311
|
switch (_f.label) {
|
|
257
312
|
case 0:
|
|
258
313
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
259
|
-
_e = {
|
|
260
|
-
walletAddress: this.address,
|
|
261
|
-
};
|
|
262
314
|
_c = number_1.toBN;
|
|
263
315
|
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0))
|
|
264
316
|
return [3 /*break*/, 1];
|
|
@@ -270,14 +322,25 @@ var Account = /** @class */ (function (_super) {
|
|
|
270
322
|
_d = _f.sent();
|
|
271
323
|
_f.label = 3;
|
|
272
324
|
case 3:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
_e);
|
|
279
|
-
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
325
|
+
nonce = _c.apply(void 0, [_d]);
|
|
326
|
+
if (!((_b = transactionsDetail.maxFee) !== null && _b !== void 0))
|
|
327
|
+
return [3 /*break*/, 4];
|
|
328
|
+
_e = _b;
|
|
329
|
+
return [3 /*break*/, 6];
|
|
280
330
|
case 4:
|
|
331
|
+
return [4 /*yield*/, this.estimateFee(transactions, { nonce: nonce })];
|
|
332
|
+
case 5:
|
|
333
|
+
_e = _f.sent().amount;
|
|
334
|
+
_f.label = 6;
|
|
335
|
+
case 6:
|
|
336
|
+
maxFee = _e;
|
|
337
|
+
signerDetails = {
|
|
338
|
+
walletAddress: this.address,
|
|
339
|
+
nonce: nonce,
|
|
340
|
+
maxFee: maxFee,
|
|
341
|
+
};
|
|
342
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
343
|
+
case 7:
|
|
281
344
|
signature = _f.sent();
|
|
282
345
|
calldata = __spreadArray(
|
|
283
346
|
__spreadArray(
|
|
@@ -296,6 +359,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
296
359
|
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
297
360
|
calldata: calldata,
|
|
298
361
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
362
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(maxFee)),
|
|
299
363
|
}),
|
|
300
364
|
];
|
|
301
365
|
}
|
package/account/interface.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
AddTransactionResponse,
|
|
5
5
|
Call,
|
|
6
6
|
DeployContractPayload,
|
|
7
|
+
EstimateFeeResponse,
|
|
8
|
+
Invocation,
|
|
7
9
|
InvocationsDetails,
|
|
8
10
|
Signature,
|
|
9
11
|
} from '../types';
|
|
@@ -25,6 +27,18 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
25
27
|
payload: DeployContractPayload,
|
|
26
28
|
abi?: Abi
|
|
27
29
|
): Promise<AddTransactionResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Estimate Fee for a method on starknet
|
|
32
|
+
*
|
|
33
|
+
* @param invocation the invocation object containing:
|
|
34
|
+
* - contractAddress - the address of the contract
|
|
35
|
+
* - entrypoint - the entrypoint of the contract
|
|
36
|
+
* - calldata - (defaults to []) the calldata
|
|
37
|
+
* - signature - (defaults to []) the signature
|
|
38
|
+
*
|
|
39
|
+
* @returns response from addTransaction
|
|
40
|
+
*/
|
|
41
|
+
abstract estimateFee(invocation: Invocation): Promise<EstimateFeeResponse>;
|
|
28
42
|
/**
|
|
29
43
|
* Invoke execute function in account contract
|
|
30
44
|
*
|
package/contract/default.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AccountInterface } from '../account';
|
|
2
2
|
import { ProviderInterface } from '../provider';
|
|
3
|
+
import { BlockIdentifier } from '../provider/utils';
|
|
3
4
|
import {
|
|
4
5
|
Abi,
|
|
5
6
|
AbiEntry,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
Calldata,
|
|
10
11
|
ContractFunction,
|
|
11
12
|
Invocation,
|
|
13
|
+
Overrides,
|
|
12
14
|
ParsedStruct,
|
|
13
15
|
Result,
|
|
14
16
|
StructAbi,
|
|
@@ -136,8 +138,16 @@ export declare class Contract implements ContractInterface {
|
|
|
136
138
|
* @return - parsed response corresponding to the abi
|
|
137
139
|
*/
|
|
138
140
|
protected parseResponse(method: string, response: string[]): Result;
|
|
139
|
-
invoke(method: string, args?: Array<any
|
|
140
|
-
call(
|
|
141
|
-
|
|
141
|
+
invoke(method: string, args?: Array<any>, options?: Overrides): Promise<AddTransactionResponse>;
|
|
142
|
+
call(
|
|
143
|
+
method: string,
|
|
144
|
+
args?: Array<any>,
|
|
145
|
+
{
|
|
146
|
+
blockIdentifier,
|
|
147
|
+
}?: {
|
|
148
|
+
blockIdentifier?: BlockIdentifier;
|
|
149
|
+
}
|
|
150
|
+
): Promise<Result>;
|
|
151
|
+
estimate(method: string, args?: Array<any>): Promise<import('../types').EstimateFeeResponse>;
|
|
142
152
|
populate(method: string, args?: Array<any>): Invocation;
|
|
143
153
|
}
|
package/contract/default.js
CHANGED
|
@@ -188,7 +188,6 @@ exports.Contract = void 0;
|
|
|
188
188
|
var bn_js_1 = __importDefault(require('bn.js'));
|
|
189
189
|
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
|
|
190
190
|
var provider_1 = require('../provider');
|
|
191
|
-
var hash_1 = require('../utils/hash');
|
|
192
191
|
var number_1 = require('../utils/number');
|
|
193
192
|
function parseFelt(candidate) {
|
|
194
193
|
try {
|
|
@@ -706,10 +705,13 @@ var Contract = /** @class */ (function () {
|
|
|
706
705
|
return acc;
|
|
707
706
|
}, []);
|
|
708
707
|
};
|
|
709
|
-
Contract.prototype.invoke = function (method, args) {
|
|
708
|
+
Contract.prototype.invoke = function (method, args, options) {
|
|
710
709
|
if (args === void 0) {
|
|
711
710
|
args = [];
|
|
712
711
|
}
|
|
712
|
+
if (options === void 0) {
|
|
713
|
+
options = {};
|
|
714
|
+
}
|
|
713
715
|
// ensure contract is connected
|
|
714
716
|
(0, minimalistic_assert_1.default)(
|
|
715
717
|
this.address !== null,
|
|
@@ -726,10 +728,6 @@ var Contract = /** @class */ (function () {
|
|
|
726
728
|
}
|
|
727
729
|
return acc;
|
|
728
730
|
}, 0);
|
|
729
|
-
var signature = [];
|
|
730
|
-
if (args.length === inputsLength + 1 && Array.isArray(args[args.length - 1])) {
|
|
731
|
-
signature.push.apply(signature, __spreadArray([], __read(args.pop()), false));
|
|
732
|
-
}
|
|
733
731
|
if (args.length !== inputsLength) {
|
|
734
732
|
throw Error(
|
|
735
733
|
'Invalid number of arguments, expected ' +
|
|
@@ -746,20 +744,26 @@ var Contract = /** @class */ (function () {
|
|
|
746
744
|
entrypoint: method,
|
|
747
745
|
};
|
|
748
746
|
if ('execute' in this.providerOrAccount) {
|
|
749
|
-
return this.providerOrAccount.execute(invocation
|
|
747
|
+
return this.providerOrAccount.execute(invocation, undefined, {
|
|
748
|
+
maxFee: options.maxFee,
|
|
749
|
+
nonce: options.nonce,
|
|
750
|
+
});
|
|
750
751
|
}
|
|
751
752
|
return this.providerOrAccount.invokeFunction(
|
|
752
|
-
__assign(__assign({}, invocation), { signature: signature })
|
|
753
|
+
__assign(__assign({}, invocation), { signature: options.signature || [] })
|
|
753
754
|
);
|
|
754
755
|
};
|
|
755
|
-
Contract.prototype.call = function (method, args) {
|
|
756
|
+
Contract.prototype.call = function (method, args, _a) {
|
|
756
757
|
if (args === void 0) {
|
|
757
758
|
args = [];
|
|
758
759
|
}
|
|
760
|
+
var _b = _a === void 0 ? {} : _a,
|
|
761
|
+
_c = _b.blockIdentifier,
|
|
762
|
+
blockIdentifier = _c === void 0 ? 'pending' : _c;
|
|
759
763
|
return __awaiter(this, void 0, void 0, function () {
|
|
760
|
-
var inputs,
|
|
764
|
+
var inputs, calldata;
|
|
761
765
|
var _this = this;
|
|
762
|
-
return __generator(this, function (
|
|
766
|
+
return __generator(this, function (_d) {
|
|
763
767
|
// ensure contract is connected
|
|
764
768
|
(0,
|
|
765
769
|
minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
@@ -768,13 +772,6 @@ var Contract = /** @class */ (function () {
|
|
|
768
772
|
inputs = this.abi.find(function (abi) {
|
|
769
773
|
return abi.name === method;
|
|
770
774
|
}).inputs;
|
|
771
|
-
inputsLength = inputs.length;
|
|
772
|
-
options = {
|
|
773
|
-
blockIdentifier: null,
|
|
774
|
-
};
|
|
775
|
-
if (args.length === inputsLength + 1 && typeof args[args.length - 1] === 'object') {
|
|
776
|
-
Object.assign(options, args.pop());
|
|
777
|
-
}
|
|
778
775
|
calldata = this.compileCalldata(args, inputs);
|
|
779
776
|
return [
|
|
780
777
|
2 /*return*/,
|
|
@@ -785,7 +782,7 @@ var Contract = /** @class */ (function () {
|
|
|
785
782
|
calldata: calldata,
|
|
786
783
|
entrypoint: method,
|
|
787
784
|
},
|
|
788
|
-
|
|
785
|
+
{ blockIdentifier: blockIdentifier }
|
|
789
786
|
)
|
|
790
787
|
.then(function (x) {
|
|
791
788
|
return _this.parseResponse(method, x.result);
|
|
@@ -794,14 +791,28 @@ var Contract = /** @class */ (function () {
|
|
|
794
791
|
});
|
|
795
792
|
});
|
|
796
793
|
};
|
|
797
|
-
Contract.prototype.estimate = function (
|
|
798
|
-
if (
|
|
799
|
-
|
|
794
|
+
Contract.prototype.estimate = function (method, args) {
|
|
795
|
+
if (args === void 0) {
|
|
796
|
+
args = [];
|
|
800
797
|
}
|
|
801
798
|
return __awaiter(this, void 0, void 0, function () {
|
|
802
|
-
|
|
799
|
+
var invocation;
|
|
800
|
+
var _a;
|
|
801
|
+
return __generator(this, function (_b) {
|
|
803
802
|
// TODO; remove error as soon as estimate fees are supported
|
|
804
|
-
|
|
803
|
+
// ensure contract is connected
|
|
804
|
+
(0,
|
|
805
|
+
minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
806
|
+
// validate method and args
|
|
807
|
+
this.validateMethodAndArgs('INVOKE', method, args);
|
|
808
|
+
invocation = (_a = this.populateTransaction)[method].apply(
|
|
809
|
+
_a,
|
|
810
|
+
__spreadArray([], __read(args), false)
|
|
811
|
+
);
|
|
812
|
+
if ('estimateFee' in this.providerOrAccount) {
|
|
813
|
+
return [2 /*return*/, this.providerOrAccount.estimateFee(invocation)];
|
|
814
|
+
}
|
|
815
|
+
throw Error('Contract must be connected to the account contract to estimate');
|
|
805
816
|
});
|
|
806
817
|
});
|
|
807
818
|
};
|
|
@@ -814,7 +825,7 @@ var Contract = /** @class */ (function () {
|
|
|
814
825
|
}).inputs;
|
|
815
826
|
return {
|
|
816
827
|
contractAddress: this.address,
|
|
817
|
-
entrypoint:
|
|
828
|
+
entrypoint: method,
|
|
818
829
|
calldata: this.compileCalldata(args, inputs),
|
|
819
830
|
signature: [],
|
|
820
831
|
};
|