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
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
# [3.7.0](https://github.com/seanjameshan/starknet.js/compare/v3.6.0...v3.7.0) (2022-03-24)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- **Account:** account constructor should take a KeyPair or a Signer as parameter ([ea6ae40](https://github.com/seanjameshan/starknet.js/commit/ea6ae40225d33e293b9d2de7c8509e87fb7a651e))
|
|
6
|
+
- add BigInt support within BigNumberish ([e42427a](https://github.com/seanjameshan/starknet.js/commit/e42427afa9a57673576da68cfbbee1356ffb5c0d))
|
|
7
|
+
- using typeguard to narrow variable's type in Account's constructor ([ed048f3](https://github.com/seanjameshan/starknet.js/commit/ed048f355bee815cc9b2ccc984db900059fa2303))
|
|
8
|
+
|
|
9
|
+
# [3.6.0](https://github.com/seanjameshan/starknet.js/compare/v3.5.1...v3.6.0) (2022-03-24)
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
- **account:** estimate fee transfered from provider to account class ([93e7dd9](https://github.com/seanjameshan/starknet.js/commit/93e7dd941b35bccb67cc426b9ae546801092964c))
|
|
14
|
+
- formatting ([248246f](https://github.com/seanjameshan/starknet.js/commit/248246f2fe75b9897700b955fa98e1779aec1744))
|
|
15
|
+
- link ([494e000](https://github.com/seanjameshan/starknet.js/commit/494e0005c3b1cb86f5de0f25a10cbbe786a87b34))
|
|
16
|
+
- **provider:** estimateFee entrypoint conversion fix ([e40204a](https://github.com/seanjameshan/starknet.js/commit/e40204a2eca5f475fe50a88349fd4890bbc36790))
|
|
17
|
+
- **provider:** estimation fee response type ([ce674ca](https://github.com/seanjameshan/starknet.js/commit/ce674ca632ff70a07d95d685c9bf2f48bebaca20))
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
- add LedgerSigner class + blind signing ([9b700f3](https://github.com/seanjameshan/starknet.js/commit/9b700f300a91a0967f8827d0ecdd69e531738ec4))
|
|
22
|
+
- **contract:** contract expanded with estimateFee method ([fbaf4ba](https://github.com/seanjameshan/starknet.js/commit/fbaf4bab56ace0917ce7c66ecf90f8e2d0dc7f60))
|
|
23
|
+
- improvements after PR reviewing ([9f30e20](https://github.com/seanjameshan/starknet.js/commit/9f30e20c2e5d2afafe4eae58c597b82dffc3bbe2))
|
|
24
|
+
- new improvements after new PR review ([2e16808](https://github.com/seanjameshan/starknet.js/commit/2e168082b0042f27336946639f3948e91bc5f641))
|
|
25
|
+
- **provider:** provider expanded with getTransactionTrace ([b67361a](https://github.com/seanjameshan/starknet.js/commit/b67361ad7c50218e00273c097426e14814441404))
|
|
26
|
+
|
|
27
|
+
## [3.5.1](https://github.com/seanjameshan/starknet.js/compare/v3.5.0...v3.5.1) (2022-03-11)
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
- account detection ([b3b3ba7](https://github.com/seanjameshan/starknet.js/commit/b3b3ba74dde72027ba7f0e1234fed34a604fdcec))
|
|
32
|
+
- contract interface ([696116d](https://github.com/seanjameshan/starknet.js/commit/696116d383ba16c587e7ed708f7b47d02610b9d9))
|
|
33
|
+
|
|
1
34
|
# [3.5.0](https://github.com/seanjameshan/starknet.js/compare/v3.4.0...v3.5.0) (2022-03-11)
|
|
2
35
|
|
|
3
36
|
### 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,10 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
+
import { SignerInterface } from '../signer';
|
|
2
3
|
import {
|
|
3
4
|
Abi,
|
|
4
5
|
AddTransactionResponse,
|
|
5
6
|
Call,
|
|
7
|
+
EstimateFeeResponse,
|
|
6
8
|
InvocationsDetails,
|
|
7
9
|
KeyPair,
|
|
8
10
|
Signature,
|
|
@@ -14,8 +16,9 @@ import { AccountInterface } from './interface';
|
|
|
14
16
|
export declare class Account extends Provider implements AccountInterface {
|
|
15
17
|
address: string;
|
|
16
18
|
private signer;
|
|
17
|
-
constructor(provider: Provider, address: string,
|
|
19
|
+
constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
18
20
|
getNonce(): Promise<string>;
|
|
21
|
+
estimateFee(calls: Call | Call[]): Promise<EstimateFeeResponse>;
|
|
19
22
|
/**
|
|
20
23
|
* Invoke execute function in account contract
|
|
21
24
|
*
|
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,46 @@ var Account = /** @class */ (function (_super) {
|
|
|
233
234
|
});
|
|
234
235
|
});
|
|
235
236
|
};
|
|
237
|
+
Account.prototype.estimateFee = function (calls) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
239
|
+
var transactions, nonce, signerDetails, signature, calldata;
|
|
240
|
+
return __generator(this, function (_a) {
|
|
241
|
+
switch (_a.label) {
|
|
242
|
+
case 0:
|
|
243
|
+
transactions = Array.isArray(calls) ? calls : [calls];
|
|
244
|
+
return [4 /*yield*/, this.getNonce()];
|
|
245
|
+
case 1:
|
|
246
|
+
nonce = _a.sent();
|
|
247
|
+
signerDetails = {
|
|
248
|
+
walletAddress: this.address,
|
|
249
|
+
nonce: (0, number_1.toBN)(nonce),
|
|
250
|
+
maxFee: (0, number_1.toBN)('0'),
|
|
251
|
+
};
|
|
252
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
|
|
253
|
+
case 2:
|
|
254
|
+
signature = _a.sent();
|
|
255
|
+
calldata = __spreadArray(
|
|
256
|
+
__spreadArray(
|
|
257
|
+
[],
|
|
258
|
+
__read((0, transaction_1.fromCallsToExecuteCalldata)(transactions)),
|
|
259
|
+
false
|
|
260
|
+
),
|
|
261
|
+
[signerDetails.nonce.toString()],
|
|
262
|
+
false
|
|
263
|
+
);
|
|
264
|
+
return [
|
|
265
|
+
2 /*return*/,
|
|
266
|
+
this.fetchEndpoint('estimate_fee', undefined, {
|
|
267
|
+
contract_address: this.address,
|
|
268
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
269
|
+
calldata: calldata,
|
|
270
|
+
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
271
|
+
}),
|
|
272
|
+
];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
};
|
|
236
277
|
/**
|
|
237
278
|
* Invoke execute function in account contract
|
|
238
279
|
*
|
|
@@ -250,15 +291,11 @@ var Account = /** @class */ (function (_super) {
|
|
|
250
291
|
transactionsDetail = {};
|
|
251
292
|
}
|
|
252
293
|
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
var transactions,
|
|
254
|
-
var _e;
|
|
294
|
+
var transactions, nonce, _c, _d, maxFee, _e, signerDetails, signature, calldata;
|
|
255
295
|
return __generator(this, function (_f) {
|
|
256
296
|
switch (_f.label) {
|
|
257
297
|
case 0:
|
|
258
298
|
transactions = Array.isArray(calls) ? calls : [calls];
|
|
259
|
-
_e = {
|
|
260
|
-
walletAddress: this.address,
|
|
261
|
-
};
|
|
262
299
|
_c = number_1.toBN;
|
|
263
300
|
if (!((_a = transactionsDetail.nonce) !== null && _a !== void 0))
|
|
264
301
|
return [3 /*break*/, 1];
|
|
@@ -270,14 +307,25 @@ var Account = /** @class */ (function (_super) {
|
|
|
270
307
|
_d = _f.sent();
|
|
271
308
|
_f.label = 3;
|
|
272
309
|
case 3:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
_e);
|
|
279
|
-
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
310
|
+
nonce = _c.apply(void 0, [_d]);
|
|
311
|
+
if (!((_b = transactionsDetail.maxFee) !== null && _b !== void 0))
|
|
312
|
+
return [3 /*break*/, 4];
|
|
313
|
+
_e = _b;
|
|
314
|
+
return [3 /*break*/, 6];
|
|
280
315
|
case 4:
|
|
316
|
+
return [4 /*yield*/, this.estimateFee(transactions)];
|
|
317
|
+
case 5:
|
|
318
|
+
_e = _f.sent().amount;
|
|
319
|
+
_f.label = 6;
|
|
320
|
+
case 6:
|
|
321
|
+
maxFee = _e;
|
|
322
|
+
signerDetails = {
|
|
323
|
+
walletAddress: this.address,
|
|
324
|
+
nonce: nonce,
|
|
325
|
+
maxFee: maxFee,
|
|
326
|
+
};
|
|
327
|
+
return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
|
|
328
|
+
case 7:
|
|
281
329
|
signature = _f.sent();
|
|
282
330
|
calldata = __spreadArray(
|
|
283
331
|
__spreadArray(
|
|
@@ -296,6 +344,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
296
344
|
entry_point_selector: (0, hash_1.getSelectorFromName)('__execute__'),
|
|
297
345
|
calldata: calldata,
|
|
298
346
|
signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(signature),
|
|
347
|
+
max_fee: (0, number_1.toHex)((0, number_1.toBN)(maxFee)),
|
|
299
348
|
}),
|
|
300
349
|
];
|
|
301
350
|
}
|
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,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AccountInterface } from '../account';
|
|
2
|
+
import { ProviderInterface } from '../provider';
|
|
3
3
|
import {
|
|
4
4
|
Abi,
|
|
5
5
|
AbiEntry,
|
|
@@ -18,7 +18,7 @@ import { ContractInterface } from './interface';
|
|
|
18
18
|
export declare class Contract implements ContractInterface {
|
|
19
19
|
abi: Abi;
|
|
20
20
|
address: string;
|
|
21
|
-
providerOrAccount:
|
|
21
|
+
providerOrAccount: ProviderInterface | AccountInterface;
|
|
22
22
|
deployTransactionHash?: string;
|
|
23
23
|
protected readonly structs: {
|
|
24
24
|
[name: string]: StructAbi;
|
|
@@ -43,7 +43,7 @@ export declare class Contract implements ContractInterface {
|
|
|
43
43
|
* @param address (optional) - address to connect to
|
|
44
44
|
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
45
45
|
*/
|
|
46
|
-
constructor(abi: Abi, address: string, providerOrAccount?:
|
|
46
|
+
constructor(abi: Abi, address: string, providerOrAccount?: ProviderInterface | AccountInterface);
|
|
47
47
|
/**
|
|
48
48
|
* Saves the address of the contract deployed on network that will be used for interaction
|
|
49
49
|
*
|
|
@@ -55,7 +55,7 @@ export declare class Contract implements ContractInterface {
|
|
|
55
55
|
*
|
|
56
56
|
* @param providerOrAccount - new Provider or Account to attach to
|
|
57
57
|
*/
|
|
58
|
-
connect(providerOrAccount:
|
|
58
|
+
connect(providerOrAccount: ProviderInterface | AccountInterface): void;
|
|
59
59
|
/**
|
|
60
60
|
* Resolves when contract is deployed on the network or when no deployment transaction is found
|
|
61
61
|
*
|
|
@@ -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
|
@@ -187,9 +187,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
187
187
|
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
|
-
var account_1 = require('../account');
|
|
191
190
|
var provider_1 = require('../provider');
|
|
192
|
-
var hash_1 = require('../utils/hash');
|
|
193
191
|
var number_1 = require('../utils/number');
|
|
194
192
|
function parseFelt(candidate) {
|
|
195
193
|
try {
|
|
@@ -727,9 +725,9 @@ var Contract = /** @class */ (function () {
|
|
|
727
725
|
}
|
|
728
726
|
return acc;
|
|
729
727
|
}, 0);
|
|
730
|
-
var
|
|
728
|
+
var overrides = {};
|
|
731
729
|
if (args.length === inputsLength + 1 && Array.isArray(args[args.length - 1])) {
|
|
732
|
-
|
|
730
|
+
Object.assign(overrides, args.pop());
|
|
733
731
|
}
|
|
734
732
|
if (args.length !== inputsLength) {
|
|
735
733
|
throw Error(
|
|
@@ -746,11 +744,14 @@ var Contract = /** @class */ (function () {
|
|
|
746
744
|
calldata: calldata,
|
|
747
745
|
entrypoint: method,
|
|
748
746
|
};
|
|
749
|
-
if (this.providerOrAccount
|
|
750
|
-
return this.providerOrAccount.execute(invocation
|
|
747
|
+
if ('execute' in this.providerOrAccount) {
|
|
748
|
+
return this.providerOrAccount.execute(invocation, undefined, {
|
|
749
|
+
maxFee: overrides.maxFee,
|
|
750
|
+
nonce: overrides.nonce,
|
|
751
|
+
});
|
|
751
752
|
}
|
|
752
753
|
return this.providerOrAccount.invokeFunction(
|
|
753
|
-
__assign(__assign({}, invocation), { signature: signature })
|
|
754
|
+
__assign(__assign({}, invocation), { signature: overrides.signature || [] })
|
|
754
755
|
);
|
|
755
756
|
};
|
|
756
757
|
Contract.prototype.call = function (method, args) {
|
|
@@ -795,14 +796,28 @@ var Contract = /** @class */ (function () {
|
|
|
795
796
|
});
|
|
796
797
|
});
|
|
797
798
|
};
|
|
798
|
-
Contract.prototype.estimate = function (
|
|
799
|
-
if (
|
|
800
|
-
|
|
799
|
+
Contract.prototype.estimate = function (method, args) {
|
|
800
|
+
if (args === void 0) {
|
|
801
|
+
args = [];
|
|
801
802
|
}
|
|
802
803
|
return __awaiter(this, void 0, void 0, function () {
|
|
803
|
-
|
|
804
|
+
var invocation;
|
|
805
|
+
var _a;
|
|
806
|
+
return __generator(this, function (_b) {
|
|
804
807
|
// TODO; remove error as soon as estimate fees are supported
|
|
805
|
-
|
|
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');
|
|
806
821
|
});
|
|
807
822
|
});
|
|
808
823
|
};
|
|
@@ -815,7 +830,7 @@ var Contract = /** @class */ (function () {
|
|
|
815
830
|
}).inputs;
|
|
816
831
|
return {
|
|
817
832
|
contractAddress: this.address,
|
|
818
|
-
entrypoint:
|
|
833
|
+
entrypoint: method,
|
|
819
834
|
calldata: this.compileCalldata(args, inputs),
|
|
820
835
|
signature: [],
|
|
821
836
|
};
|
package/contract/interface.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AccountInterface } from '../account';
|
|
2
|
+
import { ProviderInterface } from '../provider';
|
|
3
3
|
import {
|
|
4
4
|
Abi,
|
|
5
5
|
AddTransactionResponse,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
export declare abstract class ContractInterface {
|
|
12
12
|
abstract abi: Abi;
|
|
13
13
|
abstract address: string;
|
|
14
|
-
abstract providerOrAccount:
|
|
14
|
+
abstract providerOrAccount: ProviderInterface | AccountInterface;
|
|
15
15
|
abstract deployTransactionHash?: string;
|
|
16
16
|
readonly functions: {
|
|
17
17
|
[name: string]: AsyncContractFunction;
|
|
@@ -37,7 +37,7 @@ export declare abstract class ContractInterface {
|
|
|
37
37
|
*
|
|
38
38
|
* @param providerOrAccount - new Provider or Account to attach to
|
|
39
39
|
*/
|
|
40
|
-
abstract connect(providerOrAccount:
|
|
40
|
+
abstract connect(providerOrAccount: ProviderInterface | AccountInterface): void;
|
|
41
41
|
/**
|
|
42
42
|
* Resolves when contract is deployed on the network or when no deployment transaction is found
|
|
43
43
|
*
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Provider } from '../provider';
|
|
2
|
-
import {
|
|
2
|
+
import { SignerInterface } from '../signer';
|
|
3
|
+
import { Abi, AddTransactionResponse, Call, EstimateFeeResponse, InvocationsDetails, KeyPair, Signature, Transaction } from '../types';
|
|
3
4
|
import { BigNumberish } from '../utils/number';
|
|
4
5
|
import { TypedData } from '../utils/typedData';
|
|
5
6
|
import { AccountInterface } from './interface';
|
|
6
7
|
export declare class Account extends Provider implements AccountInterface {
|
|
7
8
|
address: string;
|
|
8
9
|
private signer;
|
|
9
|
-
constructor(provider: Provider, address: string,
|
|
10
|
+
constructor(provider: Provider, address: string, keyPairOrSigner: KeyPair | SignerInterface);
|
|
10
11
|
getNonce(): Promise<string>;
|
|
12
|
+
estimateFee(calls: Call | Call[]): Promise<EstimateFeeResponse>;
|
|
11
13
|
/**
|
|
12
14
|
* Invoke execute function in account contract
|
|
13
15
|
*
|