starknet 3.5.1 → 3.6.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 +18 -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 +2 -0
- package/account/default.js +60 -12
- package/account/interface.d.ts +14 -0
- package/contract/default.d.ts +1 -1
- package/contract/default.js +27 -11
- package/dist/account/default.d.ts +2 -1
- package/dist/account/default.js +47 -9
- package/dist/account/interface.d.ts +13 -1
- package/dist/contract/default.d.ts +1 -1
- package/dist/contract/default.js +22 -10
- 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 +25 -4
- package/src/account/interface.ts +15 -0
- package/src/contract/default.ts +23 -22
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
# [3.6.0](https://github.com/seanjameshan/starknet.js/compare/v3.5.1...v3.6.0) (2022-03-24)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- **account:** estimate fee transfered from provider to account class ([93e7dd9](https://github.com/seanjameshan/starknet.js/commit/93e7dd941b35bccb67cc426b9ae546801092964c))
|
|
6
|
+
- formatting ([248246f](https://github.com/seanjameshan/starknet.js/commit/248246f2fe75b9897700b955fa98e1779aec1744))
|
|
7
|
+
- link ([494e000](https://github.com/seanjameshan/starknet.js/commit/494e0005c3b1cb86f5de0f25a10cbbe786a87b34))
|
|
8
|
+
- **provider:** estimateFee entrypoint conversion fix ([e40204a](https://github.com/seanjameshan/starknet.js/commit/e40204a2eca5f475fe50a88349fd4890bbc36790))
|
|
9
|
+
- **provider:** estimation fee response type ([ce674ca](https://github.com/seanjameshan/starknet.js/commit/ce674ca632ff70a07d95d685c9bf2f48bebaca20))
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
- add LedgerSigner class + blind signing ([9b700f3](https://github.com/seanjameshan/starknet.js/commit/9b700f300a91a0967f8827d0ecdd69e531738ec4))
|
|
14
|
+
- **contract:** contract expanded with estimateFee method ([fbaf4ba](https://github.com/seanjameshan/starknet.js/commit/fbaf4bab56ace0917ce7c66ecf90f8e2d0dc7f60))
|
|
15
|
+
- improvements after PR reviewing ([9f30e20](https://github.com/seanjameshan/starknet.js/commit/9f30e20c2e5d2afafe4eae58c597b82dffc3bbe2))
|
|
16
|
+
- new improvements after new PR review ([2e16808](https://github.com/seanjameshan/starknet.js/commit/2e168082b0042f27336946639f3948e91bc5f641))
|
|
17
|
+
- **provider:** provider expanded with getTransactionTrace ([b67361a](https://github.com/seanjameshan/starknet.js/commit/b67361ad7c50218e00273c097426e14814441404))
|
|
18
|
+
|
|
1
19
|
## [3.5.1](https://github.com/seanjameshan/starknet.js/compare/v3.5.0...v3.5.1) (2022-03-11)
|
|
2
20
|
|
|
3
21
|
### 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
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
Abi,
|
|
4
4
|
AddTransactionResponse,
|
|
5
5
|
Call,
|
|
6
|
+
EstimateFeeResponse,
|
|
6
7
|
InvocationsDetails,
|
|
7
8
|
KeyPair,
|
|
8
9
|
Signature,
|
|
@@ -16,6 +17,7 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
16
17
|
private signer;
|
|
17
18
|
constructor(provider: Provider, address: string, keyPair: KeyPair);
|
|
18
19
|
getNonce(): Promise<string>;
|
|
20
|
+
estimateFee(calls: Call | Call[]): Promise<EstimateFeeResponse>;
|
|
19
21
|
/**
|
|
20
22
|
* Invoke execute function in account contract
|
|
21
23
|
*
|
package/account/default.js
CHANGED
|
@@ -233,6 +233,46 @@ var Account = /** @class */ (function (_super) {
|
|
|
233
233
|
});
|
|
234
234
|
});
|
|
235
235
|
};
|
|
236
|
+
Account.prototype.estimateFee = function (calls) {
|
|
237
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
238
|
+
var transactions, nonce, signerDetails, signature, calldata;
|
|
239
|
+
return __generator(this, function (_a) {
|
|
240
|
+
switch (_a.label) {
|
|
241
|
+
case 0:
|
|
242
|
+
transactions = Array.isArray(calls) ? calls : [calls];
|
|
243
|
+
return [4 /*yield*/, this.getNonce()];
|
|
244
|
+
case 1:
|
|
245
|
+
nonce = _a.sent();
|
|
246
|
+
signerDetails = {
|
|
247
|
+
walletAddress: this.address,
|
|
248
|
+
nonce: (0, number_1.toBN)(nonce),
|
|
249
|
+
maxFee: (0, number_1.toBN)('0'),
|
|
250
|
+
};
|
|
251
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
252
|
+
case 2:
|
|
253
|
+
signature = _a.sent();
|
|
254
|
+
calldata = __spreadArray(
|
|
255
|
+
__spreadArray(
|
|
256
|
+
[],
|
|
257
|
+
__read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)),
|
|
258
|
+
false
|
|
259
|
+
),
|
|
260
|
+
[signerDetails.nonce.toString()],
|
|
261
|
+
false
|
|
262
|
+
);
|
|
263
|
+
return [
|
|
264
|
+
2 /*return*/,
|
|
265
|
+
this.fetchEndpoint('estimate_fee', undefined, {
|
|
266
|
+
contract_address: this.address,
|
|
267
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
268
|
+
calldata: calldata,
|
|
269
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
270
|
+
}),
|
|
271
|
+
];
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
};
|
|
236
276
|
/**
|
|
237
277
|
* Invoke execute function in account contract
|
|
238
278
|
*
|
|
@@ -250,15 +290,11 @@ var Account = /** @class */ (function (_super) {
|
|
|
250
290
|
transactionsDetail = {};
|
|
251
291
|
}
|
|
252
292
|
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
var transactions,
|
|
254
|
-
var _e;
|
|
293
|
+
var transactions, nonce, _c, _d, maxFee, _e, signerDetails, signature, calldata;
|
|
255
294
|
return __generator(this, function (_f) {
|
|
256
295
|
switch (_f.label) {
|
|
257
296
|
case 0:
|
|
258
297
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
259
|
-
_e = {
|
|
260
|
-
walletAddress: this.address,
|
|
261
|
-
};
|
|
262
298
|
_c = number_1.toBN;
|
|
263
299
|
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0))
|
|
264
300
|
return [3 /*break*/, 1];
|
|
@@ -270,14 +306,25 @@ var Account = /** @class */ (function (_super) {
|
|
|
270
306
|
_d = _f.sent();
|
|
271
307
|
_f.label = 3;
|
|
272
308
|
case 3:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
_e);
|
|
279
|
-
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
309
|
+
nonce = _c.apply(void 0, [_d]);
|
|
310
|
+
if (!((_b = transactionsDetail.maxFee) !== null && _b !== void 0))
|
|
311
|
+
return [3 /*break*/, 4];
|
|
312
|
+
_e = _b;
|
|
313
|
+
return [3 /*break*/, 6];
|
|
280
314
|
case 4:
|
|
315
|
+
return [4 /*yield*/, this.estimateFee(transactions)];
|
|
316
|
+
case 5:
|
|
317
|
+
_e = _f.sent().amount;
|
|
318
|
+
_f.label = 6;
|
|
319
|
+
case 6:
|
|
320
|
+
maxFee = _e;
|
|
321
|
+
signerDetails = {
|
|
322
|
+
walletAddress: this.address,
|
|
323
|
+
nonce: nonce,
|
|
324
|
+
maxFee: maxFee,
|
|
325
|
+
};
|
|
326
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
327
|
+
case 7:
|
|
281
328
|
signature = _f.sent();
|
|
282
329
|
calldata = __spreadArray(
|
|
283
330
|
__spreadArray(
|
|
@@ -296,6 +343,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
296
343
|
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
297
344
|
calldata: calldata,
|
|
298
345
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
346
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(maxFee)),
|
|
299
347
|
}),
|
|
300
348
|
];
|
|
301
349
|
}
|
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
|
@@ -138,6 +138,6 @@ export declare class Contract implements ContractInterface {
|
|
|
138
138
|
protected parseResponse(method: string, response: string[]): Result;
|
|
139
139
|
invoke(method: string, args?: Array<any>): Promise<AddTransactionResponse>;
|
|
140
140
|
call(method: string, args?: Array<any>): Promise<Result>;
|
|
141
|
-
estimate(
|
|
141
|
+
estimate(method: string, args?: Array<any>): Promise<import('../types').EstimateFeeResponse>;
|
|
142
142
|
populate(method: string, args?: Array<any>): Invocation;
|
|
143
143
|
}
|
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 {
|
|
@@ -726,9 +725,9 @@ var Contract = /** @class */ (function () {
|
|
|
726
725
|
}
|
|
727
726
|
return acc;
|
|
728
727
|
}, 0);
|
|
729
|
-
var
|
|
728
|
+
var overrides = {};
|
|
730
729
|
if (args.length === inputsLength + 1 && Array.isArray(args[args.length - 1])) {
|
|
731
|
-
|
|
730
|
+
Object.assign(overrides, args.pop());
|
|
732
731
|
}
|
|
733
732
|
if (args.length !== inputsLength) {
|
|
734
733
|
throw Error(
|
|
@@ -746,10 +745,13 @@ var Contract = /** @class */ (function () {
|
|
|
746
745
|
entrypoint: method,
|
|
747
746
|
};
|
|
748
747
|
if ('execute' in this.providerOrAccount) {
|
|
749
|
-
return this.providerOrAccount.execute(invocation
|
|
748
|
+
return this.providerOrAccount.execute(invocation, undefined, {
|
|
749
|
+
maxFee: overrides.maxFee,
|
|
750
|
+
nonce: overrides.nonce,
|
|
751
|
+
});
|
|
750
752
|
}
|
|
751
753
|
return this.providerOrAccount.invokeFunction(
|
|
752
|
-
__assign(__assign({}, invocation), { signature: signature })
|
|
754
|
+
__assign(__assign({}, invocation), { signature: overrides.signature || [] })
|
|
753
755
|
);
|
|
754
756
|
};
|
|
755
757
|
Contract.prototype.call = function (method, args) {
|
|
@@ -794,14 +796,28 @@ var Contract = /** @class */ (function () {
|
|
|
794
796
|
});
|
|
795
797
|
});
|
|
796
798
|
};
|
|
797
|
-
Contract.prototype.estimate = function (
|
|
798
|
-
if (
|
|
799
|
-
|
|
799
|
+
Contract.prototype.estimate = function (method, args) {
|
|
800
|
+
if (args === void 0) {
|
|
801
|
+
args = [];
|
|
800
802
|
}
|
|
801
803
|
return __awaiter(this, void 0, void 0, function () {
|
|
802
|
-
|
|
804
|
+
var invocation;
|
|
805
|
+
var _a;
|
|
806
|
+
return __generator(this, function (_b) {
|
|
803
807
|
// TODO; remove error as soon as estimate fees are supported
|
|
804
|
-
|
|
808
|
+
// ensure contract is connected
|
|
809
|
+
(0,
|
|
810
|
+
minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
|
|
811
|
+
// validate method and args
|
|
812
|
+
this.validateMethodAndArgs('INVOKE', method, args);
|
|
813
|
+
invocation = (_a = this.populateTransaction)[method].apply(
|
|
814
|
+
_a,
|
|
815
|
+
__spreadArray([], __read(args), false)
|
|
816
|
+
);
|
|
817
|
+
if ('estimateFee' in this.providerOrAccount) {
|
|
818
|
+
return [2 /*return*/, this.providerOrAccount.estimateFee(invocation)];
|
|
819
|
+
}
|
|
820
|
+
throw Error('Contract must be connected to the account contract to estimate');
|
|
805
821
|
});
|
|
806
822
|
});
|
|
807
823
|
};
|
|
@@ -814,7 +830,7 @@ var Contract = /** @class */ (function () {
|
|
|
814
830
|
}).inputs;
|
|
815
831
|
return {
|
|
816
832
|
contractAddress: this.address,
|
|
817
|
-
entrypoint:
|
|
833
|
+
entrypoint: method,
|
|
818
834
|
calldata: this.compileCalldata(args, inputs),
|
|
819
835
|
signature: [],
|
|
820
836
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
-
import { Abi, AddTransactionResponse, Call, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
|
|
2
|
+
import { Abi, AddTransactionResponse, Call, EstimateFeeResponse, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
4
|
import { TypedData } from '../utils/typedData';
|
|
5
5
|
import { AccountInterface } from './interface';
|
|
@@ -8,6 +8,7 @@ export declare class Account extends Provider implements AccountInterface {
|
|
|
8
8
|
private signer;
|
|
9
9
|
constructor(provider: Provider, address: string, keyPair: KeyPair);
|
|
10
10
|
getNonce(): Promise<string>;
|
|
11
|
+
estimateFee(calls: Call | Call[]): Promise<EstimateFeeResponse>;
|
|
11
12
|
/**
|
|
12
13
|
* Invoke execute function in account contract
|
|
13
14
|
*
|
package/dist/account/default.js
CHANGED
|
@@ -113,6 +113,35 @@ var Account = /** @class */ (function (_super) {
|
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
};
|
|
116
|
+
Account.prototype.estimateFee = function (calls) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
+
var transactions, nonce, signerDetails, signature, calldata;
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
switch (_a.label) {
|
|
121
|
+
case 0:
|
|
122
|
+
transactions = Array.isArray(calls) ? calls : [calls];
|
|
123
|
+
return [4 /*yield*/, this.getNonce()];
|
|
124
|
+
case 1:
|
|
125
|
+
nonce = _a.sent();
|
|
126
|
+
signerDetails = {
|
|
127
|
+
walletAddress: this.address,
|
|
128
|
+
nonce: (0, number_1.toBN)(nonce),
|
|
129
|
+
maxFee: (0, number_1.toBN)('0'),
|
|
130
|
+
};
|
|
131
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
132
|
+
case 2:
|
|
133
|
+
signature = _a.sent();
|
|
134
|
+
calldata = __spreadArray(__spreadArray([], __read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)), false), [signerDetails.nonce.toString()], false);
|
|
135
|
+
return [2 /*return*/, this.fetchEndpoint('estimate_fee', undefined, {
|
|
136
|
+
contract_address: this.address,
|
|
137
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
138
|
+
calldata: calldata,
|
|
139
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
140
|
+
})];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
};
|
|
116
145
|
/**
|
|
117
146
|
* Invoke execute function in account contract
|
|
118
147
|
*
|
|
@@ -126,15 +155,11 @@ var Account = /** @class */ (function (_super) {
|
|
|
126
155
|
if (abis === void 0) { abis = undefined; }
|
|
127
156
|
if (transactionsDetail === void 0) { transactionsDetail = {}; }
|
|
128
157
|
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
-
var transactions,
|
|
130
|
-
var _e;
|
|
158
|
+
var transactions, nonce, _c, _d, maxFee, _e, signerDetails, signature, calldata;
|
|
131
159
|
return __generator(this, function (_f) {
|
|
132
160
|
switch (_f.label) {
|
|
133
161
|
case 0:
|
|
134
162
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
135
|
-
_e = {
|
|
136
|
-
walletAddress: this.address
|
|
137
|
-
};
|
|
138
163
|
_c = number_1.toBN;
|
|
139
164
|
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0)) return [3 /*break*/, 1];
|
|
140
165
|
_d = _a;
|
|
@@ -144,11 +169,23 @@ var Account = /** @class */ (function (_super) {
|
|
|
144
169
|
_d = (_f.sent());
|
|
145
170
|
_f.label = 3;
|
|
146
171
|
case 3:
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
172
|
+
nonce = _c.apply(void 0, [_d]);
|
|
173
|
+
if (!((_b = transactionsDetail.maxFee) !== null && _b !== void 0)) return [3 /*break*/, 4];
|
|
174
|
+
_e = _b;
|
|
175
|
+
return [3 /*break*/, 6];
|
|
176
|
+
case 4: return [4 /*yield*/, this.estimateFee(transactions)];
|
|
177
|
+
case 5:
|
|
178
|
+
_e = (_f.sent()).amount;
|
|
179
|
+
_f.label = 6;
|
|
180
|
+
case 6:
|
|
181
|
+
maxFee = _e;
|
|
182
|
+
signerDetails = {
|
|
183
|
+
walletAddress: this.address,
|
|
184
|
+
nonce: nonce,
|
|
185
|
+
maxFee: maxFee,
|
|
186
|
+
};
|
|
150
187
|
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
151
|
-
case
|
|
188
|
+
case 7:
|
|
152
189
|
signature = _f.sent();
|
|
153
190
|
calldata = __spreadArray(__spreadArray([], __read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)), false), [signerDetails.nonce.toString()], false);
|
|
154
191
|
return [2 /*return*/, this.fetchEndpoint('add_transaction', undefined, {
|
|
@@ -157,6 +194,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
157
194
|
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
158
195
|
calldata: calldata,
|
|
159
196
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
197
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(maxFee)),
|
|
160
198
|
})];
|
|
161
199
|
}
|
|
162
200
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProviderInterface } from '../provider';
|
|
2
|
-
import { Abi, AddTransactionResponse, Call, DeployContractPayload, InvocationsDetails, Signature } from '../types';
|
|
2
|
+
import { Abi, AddTransactionResponse, Call, DeployContractPayload, EstimateFeeResponse, Invocation, InvocationsDetails, Signature } from '../types';
|
|
3
3
|
import { BigNumberish } from '../utils/number';
|
|
4
4
|
import { TypedData } from '../utils/typedData/types';
|
|
5
5
|
export declare abstract class AccountInterface extends ProviderInterface {
|
|
@@ -15,6 +15,18 @@ export declare abstract class AccountInterface extends ProviderInterface {
|
|
|
15
15
|
* @returns a confirmation of sending a transaction on the starknet contract
|
|
16
16
|
*/
|
|
17
17
|
abstract deployContract(payload: DeployContractPayload, abi?: Abi): Promise<AddTransactionResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Estimate Fee for a method on starknet
|
|
20
|
+
*
|
|
21
|
+
* @param invocation the invocation object containing:
|
|
22
|
+
* - contractAddress - the address of the contract
|
|
23
|
+
* - entrypoint - the entrypoint of the contract
|
|
24
|
+
* - calldata - (defaults to []) the calldata
|
|
25
|
+
* - signature - (defaults to []) the signature
|
|
26
|
+
*
|
|
27
|
+
* @returns response from addTransaction
|
|
28
|
+
*/
|
|
29
|
+
abstract estimateFee(invocation: Invocation): Promise<EstimateFeeResponse>;
|
|
18
30
|
/**
|
|
19
31
|
* Invoke execute function in account contract
|
|
20
32
|
*
|
|
@@ -116,6 +116,6 @@ export declare class Contract implements ContractInterface {
|
|
|
116
116
|
protected parseResponse(method: string, response: string[]): Result;
|
|
117
117
|
invoke(method: string, args?: Array<any>): Promise<AddTransactionResponse>;
|
|
118
118
|
call(method: string, args?: Array<any>): Promise<Result>;
|
|
119
|
-
estimate(
|
|
119
|
+
estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
|
|
120
120
|
populate(method: string, args?: Array<any>): Invocation;
|
|
121
121
|
}
|