starknet 3.4.0 → 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/.eslintrc +2 -1
- package/CHANGELOG.md +45 -0
- package/__tests__/account.test.ts +43 -35
- package/__tests__/accountContract.test.ts +5 -48
- package/__tests__/constancts.ts +2 -0
- package/__tests__/contract.test.ts +144 -54
- package/__tests__/provider.test.ts +8 -0
- package/__tests__/utils/utils.browser.test.ts +1 -3
- package/account/default.d.ts +2 -0
- package/account/default.js +60 -12
- package/account/interface.d.ts +14 -0
- package/contract/contractFactory.d.ts +36 -0
- package/contract/contractFactory.js +218 -0
- package/contract/default.d.ts +143 -0
- package/{contract.js → contract/default.js} +372 -86
- package/contract/index.d.ts +3 -0
- package/contract/index.js +28 -0
- package/contract/interface.d.ts +79 -0
- package/contract/interface.js +8 -0
- 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/contractFactory.d.ts +32 -0
- package/dist/contract/contractFactory.js +102 -0
- package/dist/contract/default.d.ts +121 -0
- package/dist/contract/default.js +648 -0
- package/dist/contract/index.d.ts +3 -0
- package/dist/contract/index.js +15 -0
- package/dist/contract/interface.d.ts +72 -0
- package/dist/contract/interface.js +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/provider/default.d.ts +12 -2
- package/dist/provider/default.js +20 -6
- package/dist/provider/interface.d.ts +3 -1
- 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 +61 -0
- package/dist/types/contract.d.ts +5 -0
- package/dist/types/contract.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/lib.d.ts +11 -1
- package/dist/utils/transaction.d.ts +1 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +5 -2
- package/provider/default.d.ts +12 -1
- package/provider/default.js +29 -16
- package/provider/interface.d.ts +3 -1
- 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/contractFactory.ts +78 -0
- package/src/contract/default.ts +627 -0
- package/src/contract/index.ts +3 -0
- package/src/contract/interface.ts +87 -0
- package/src/index.ts +1 -1
- package/src/provider/default.ts +21 -14
- package/src/provider/interface.ts +3 -1
- package/src/signer/index.ts +1 -0
- package/src/signer/ledger.ts +81 -0
- package/src/types/api.ts +66 -0
- package/src/types/contract.ts +5 -0
- package/src/types/index.ts +1 -0
- package/src/types/lib.ts +12 -1
- package/src/utils/transaction.ts +1 -2
- package/tsconfig.json +1 -10
- package/types/api.d.ts +61 -0
- package/types/contract.d.ts +5 -0
- package/types/contract.js +2 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/lib.d.ts +11 -1
- package/utils/transaction.d.ts +1 -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/contract.d.ts +0 -98
- package/dist/contract.d.ts +0 -94
- package/dist/contract.js +0 -389
- package/src/contract.ts +0 -357
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
|
*
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Account } from '../account';
|
|
2
|
+
import { Provider } from '../provider';
|
|
3
|
+
import { Abi, CompiledContract, RawCalldata } from '../types';
|
|
4
|
+
import { BigNumberish } from '../utils/number';
|
|
5
|
+
import { Contract } from './default';
|
|
6
|
+
export declare class ContractFactory {
|
|
7
|
+
abi: Abi;
|
|
8
|
+
compiledContract: CompiledContract;
|
|
9
|
+
providerOrAccount: Provider | Account;
|
|
10
|
+
constructor(
|
|
11
|
+
compiledContract: CompiledContract,
|
|
12
|
+
providerOrAccount?: Provider | Account,
|
|
13
|
+
abi?: Abi
|
|
14
|
+
);
|
|
15
|
+
/**
|
|
16
|
+
* Deploys contract and returns new instance of the Contract
|
|
17
|
+
*
|
|
18
|
+
* @param constructorCalldata - Constructor Calldata
|
|
19
|
+
* @param addressSalt (optional) - Address Salt for deployment
|
|
20
|
+
* @returns deployed Contract
|
|
21
|
+
*/
|
|
22
|
+
deploy(constructorCalldata?: RawCalldata, addressSalt?: BigNumberish): Promise<Contract>;
|
|
23
|
+
/**
|
|
24
|
+
* Attaches to new Provider or Account
|
|
25
|
+
*
|
|
26
|
+
* @param providerOrAccount - new Provider or Account to attach to
|
|
27
|
+
*/
|
|
28
|
+
connect(providerOrAccount: Provider | Account): ContractFactory;
|
|
29
|
+
/**
|
|
30
|
+
* Attaches current abi and provider or account to the new address
|
|
31
|
+
*
|
|
32
|
+
* @param address - Contract address
|
|
33
|
+
* @returns Contract
|
|
34
|
+
*/
|
|
35
|
+
attach(address: string): Contract;
|
|
36
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter =
|
|
3
|
+
(this && this.__awaiter) ||
|
|
4
|
+
function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) {
|
|
6
|
+
return value instanceof P
|
|
7
|
+
? value
|
|
8
|
+
: new P(function (resolve) {
|
|
9
|
+
resolve(value);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) {
|
|
14
|
+
try {
|
|
15
|
+
step(generator.next(value));
|
|
16
|
+
} catch (e) {
|
|
17
|
+
reject(e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function rejected(value) {
|
|
21
|
+
try {
|
|
22
|
+
step(generator['throw'](value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function step(result) {
|
|
28
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
29
|
+
}
|
|
30
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
var __generator =
|
|
34
|
+
(this && this.__generator) ||
|
|
35
|
+
function (thisArg, body) {
|
|
36
|
+
var _ = {
|
|
37
|
+
label: 0,
|
|
38
|
+
sent: function () {
|
|
39
|
+
if (t[0] & 1) throw t[1];
|
|
40
|
+
return t[1];
|
|
41
|
+
},
|
|
42
|
+
trys: [],
|
|
43
|
+
ops: [],
|
|
44
|
+
},
|
|
45
|
+
f,
|
|
46
|
+
y,
|
|
47
|
+
t,
|
|
48
|
+
g;
|
|
49
|
+
return (
|
|
50
|
+
(g = { next: verb(0), throw: verb(1), return: verb(2) }),
|
|
51
|
+
typeof Symbol === 'function' &&
|
|
52
|
+
(g[Symbol.iterator] = function () {
|
|
53
|
+
return this;
|
|
54
|
+
}),
|
|
55
|
+
g
|
|
56
|
+
);
|
|
57
|
+
function verb(n) {
|
|
58
|
+
return function (v) {
|
|
59
|
+
return step([n, v]);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function step(op) {
|
|
63
|
+
if (f) throw new TypeError('Generator is already executing.');
|
|
64
|
+
while (_)
|
|
65
|
+
try {
|
|
66
|
+
if (
|
|
67
|
+
((f = 1),
|
|
68
|
+
y &&
|
|
69
|
+
(t =
|
|
70
|
+
op[0] & 2
|
|
71
|
+
? y['return']
|
|
72
|
+
: op[0]
|
|
73
|
+
? y['throw'] || ((t = y['return']) && t.call(y), 0)
|
|
74
|
+
: y.next) &&
|
|
75
|
+
!(t = t.call(y, op[1])).done)
|
|
76
|
+
)
|
|
77
|
+
return t;
|
|
78
|
+
if (((y = 0), t)) op = [op[0] & 2, t.value];
|
|
79
|
+
switch (op[0]) {
|
|
80
|
+
case 0:
|
|
81
|
+
case 1:
|
|
82
|
+
t = op;
|
|
83
|
+
break;
|
|
84
|
+
case 4:
|
|
85
|
+
_.label++;
|
|
86
|
+
return { value: op[1], done: false };
|
|
87
|
+
case 5:
|
|
88
|
+
_.label++;
|
|
89
|
+
y = op[1];
|
|
90
|
+
op = [0];
|
|
91
|
+
continue;
|
|
92
|
+
case 7:
|
|
93
|
+
op = _.ops.pop();
|
|
94
|
+
_.trys.pop();
|
|
95
|
+
continue;
|
|
96
|
+
default:
|
|
97
|
+
if (
|
|
98
|
+
!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) &&
|
|
99
|
+
(op[0] === 6 || op[0] === 2)
|
|
100
|
+
) {
|
|
101
|
+
_ = 0;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
105
|
+
_.label = op[1];
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
109
|
+
_.label = t[1];
|
|
110
|
+
t = op;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
if (t && _.label < t[2]) {
|
|
114
|
+
_.label = t[2];
|
|
115
|
+
_.ops.push(op);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
if (t[2]) _.ops.pop();
|
|
119
|
+
_.trys.pop();
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
op = body.call(thisArg, _);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
op = [6, e];
|
|
125
|
+
y = 0;
|
|
126
|
+
} finally {
|
|
127
|
+
f = t = 0;
|
|
128
|
+
}
|
|
129
|
+
if (op[0] & 5) throw op[1];
|
|
130
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var __importDefault =
|
|
134
|
+
(this && this.__importDefault) ||
|
|
135
|
+
function (mod) {
|
|
136
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
137
|
+
};
|
|
138
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
139
|
+
exports.ContractFactory = void 0;
|
|
140
|
+
var minimalistic_assert_1 = __importDefault(require('minimalistic-assert'));
|
|
141
|
+
var provider_1 = require('../provider');
|
|
142
|
+
var default_1 = require('./default');
|
|
143
|
+
var ContractFactory = /** @class */ (function () {
|
|
144
|
+
function ContractFactory(
|
|
145
|
+
compiledContract,
|
|
146
|
+
providerOrAccount,
|
|
147
|
+
abi // abi can be different from the deployed contract ie for proxy contracts
|
|
148
|
+
) {
|
|
149
|
+
if (providerOrAccount === void 0) {
|
|
150
|
+
providerOrAccount = provider_1.defaultProvider;
|
|
151
|
+
}
|
|
152
|
+
if (abi === void 0) {
|
|
153
|
+
abi = compiledContract.abi;
|
|
154
|
+
}
|
|
155
|
+
this.abi = abi;
|
|
156
|
+
this.compiledContract = compiledContract;
|
|
157
|
+
this.providerOrAccount = providerOrAccount;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Deploys contract and returns new instance of the Contract
|
|
161
|
+
*
|
|
162
|
+
* @param constructorCalldata - Constructor Calldata
|
|
163
|
+
* @param addressSalt (optional) - Address Salt for deployment
|
|
164
|
+
* @returns deployed Contract
|
|
165
|
+
*/
|
|
166
|
+
ContractFactory.prototype.deploy = function (constructorCalldata, addressSalt) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
168
|
+
var _a, address, code, transaction_hash, contractInstance;
|
|
169
|
+
return __generator(this, function (_b) {
|
|
170
|
+
switch (_b.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
return [
|
|
173
|
+
4 /*yield*/,
|
|
174
|
+
this.providerOrAccount.deployContract({
|
|
175
|
+
contract: this.compiledContract,
|
|
176
|
+
constructorCalldata: constructorCalldata,
|
|
177
|
+
addressSalt: addressSalt,
|
|
178
|
+
}),
|
|
179
|
+
];
|
|
180
|
+
case 1:
|
|
181
|
+
(_a = _b.sent()),
|
|
182
|
+
(address = _a.address),
|
|
183
|
+
(code = _a.code),
|
|
184
|
+
(transaction_hash = _a.transaction_hash);
|
|
185
|
+
(0,
|
|
186
|
+
minimalistic_assert_1.default)(code === 'TRANSACTION_RECEIVED' && Boolean(address), 'Deployment of the contract failed');
|
|
187
|
+
contractInstance = new default_1.Contract(
|
|
188
|
+
this.compiledContract.abi,
|
|
189
|
+
address,
|
|
190
|
+
this.providerOrAccount
|
|
191
|
+
);
|
|
192
|
+
contractInstance.deployTransactionHash = transaction_hash;
|
|
193
|
+
return [2 /*return*/, contractInstance];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Attaches to new Provider or Account
|
|
200
|
+
*
|
|
201
|
+
* @param providerOrAccount - new Provider or Account to attach to
|
|
202
|
+
*/
|
|
203
|
+
ContractFactory.prototype.connect = function (providerOrAccount) {
|
|
204
|
+
this.providerOrAccount = providerOrAccount;
|
|
205
|
+
return this;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Attaches current abi and provider or account to the new address
|
|
209
|
+
*
|
|
210
|
+
* @param address - Contract address
|
|
211
|
+
* @returns Contract
|
|
212
|
+
*/
|
|
213
|
+
ContractFactory.prototype.attach = function (address) {
|
|
214
|
+
return new default_1.Contract(this.abi, address, this.providerOrAccount);
|
|
215
|
+
};
|
|
216
|
+
return ContractFactory;
|
|
217
|
+
})();
|
|
218
|
+
exports.ContractFactory = ContractFactory;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { AccountInterface } from '../account';
|
|
2
|
+
import { ProviderInterface } from '../provider';
|
|
3
|
+
import {
|
|
4
|
+
Abi,
|
|
5
|
+
AbiEntry,
|
|
6
|
+
AddTransactionResponse,
|
|
7
|
+
Args,
|
|
8
|
+
AsyncContractFunction,
|
|
9
|
+
Calldata,
|
|
10
|
+
ContractFunction,
|
|
11
|
+
Invocation,
|
|
12
|
+
ParsedStruct,
|
|
13
|
+
Result,
|
|
14
|
+
StructAbi,
|
|
15
|
+
} from '../types';
|
|
16
|
+
import { BigNumberish } from '../utils/number';
|
|
17
|
+
import { ContractInterface } from './interface';
|
|
18
|
+
export declare class Contract implements ContractInterface {
|
|
19
|
+
abi: Abi;
|
|
20
|
+
address: string;
|
|
21
|
+
providerOrAccount: ProviderInterface | AccountInterface;
|
|
22
|
+
deployTransactionHash?: string;
|
|
23
|
+
protected readonly structs: {
|
|
24
|
+
[name: string]: StructAbi;
|
|
25
|
+
};
|
|
26
|
+
readonly functions: {
|
|
27
|
+
[name: string]: AsyncContractFunction;
|
|
28
|
+
};
|
|
29
|
+
readonly callStatic: {
|
|
30
|
+
[name: string]: AsyncContractFunction;
|
|
31
|
+
};
|
|
32
|
+
readonly populateTransaction: {
|
|
33
|
+
[name: string]: ContractFunction;
|
|
34
|
+
};
|
|
35
|
+
readonly estimateFee: {
|
|
36
|
+
[name: string]: ContractFunction;
|
|
37
|
+
};
|
|
38
|
+
readonly [key: string]: AsyncContractFunction | any;
|
|
39
|
+
/**
|
|
40
|
+
* Contract class to handle contract methods
|
|
41
|
+
*
|
|
42
|
+
* @param abi - Abi of the contract object
|
|
43
|
+
* @param address (optional) - address to connect to
|
|
44
|
+
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
45
|
+
*/
|
|
46
|
+
constructor(abi: Abi, address: string, providerOrAccount?: ProviderInterface | AccountInterface);
|
|
47
|
+
/**
|
|
48
|
+
* Saves the address of the contract deployed on network that will be used for interaction
|
|
49
|
+
*
|
|
50
|
+
* @param address - address of the contract
|
|
51
|
+
*/
|
|
52
|
+
attach(address: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Attaches to new Provider or Account
|
|
55
|
+
*
|
|
56
|
+
* @param providerOrAccount - new Provider or Account to attach to
|
|
57
|
+
*/
|
|
58
|
+
connect(providerOrAccount: ProviderInterface | AccountInterface): void;
|
|
59
|
+
/**
|
|
60
|
+
* Resolves when contract is deployed on the network or when no deployment transaction is found
|
|
61
|
+
*
|
|
62
|
+
* @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
|
|
63
|
+
* @throws When deployment fails
|
|
64
|
+
*/
|
|
65
|
+
deployed(): Promise<Contract>;
|
|
66
|
+
/**
|
|
67
|
+
* Validates if all arguments that are passed to the method are corresponding to the ones in the abi
|
|
68
|
+
*
|
|
69
|
+
* @param type - type of the method
|
|
70
|
+
* @param method - name of the method
|
|
71
|
+
* @param args - arguments that are passed to the method
|
|
72
|
+
*/
|
|
73
|
+
protected validateMethodAndArgs(type: 'INVOKE' | 'CALL', method: string, args?: Array<any>): void;
|
|
74
|
+
/**
|
|
75
|
+
* Deep parse of the object that has been passed to the method
|
|
76
|
+
*
|
|
77
|
+
* @param struct - struct that needs to be calculated
|
|
78
|
+
* @return {number} - number of members for the given struct
|
|
79
|
+
*/
|
|
80
|
+
private calculateStructMembers;
|
|
81
|
+
/**
|
|
82
|
+
* Deep parse of the object that has been passed to the method
|
|
83
|
+
*
|
|
84
|
+
* @param element - element that needs to be parsed
|
|
85
|
+
* @param type - name of the method
|
|
86
|
+
* @return {string | string[]} - parsed arguments in format that contract is expecting
|
|
87
|
+
*/
|
|
88
|
+
protected parseCalldataValue(
|
|
89
|
+
element: ParsedStruct | BigNumberish | BigNumberish[],
|
|
90
|
+
type: string
|
|
91
|
+
): string | string[];
|
|
92
|
+
/**
|
|
93
|
+
* Parse of the response elements that are converted to Object (Struct) by using the abi
|
|
94
|
+
*
|
|
95
|
+
* @param responseIterator - iterator of the response
|
|
96
|
+
* @param type - type of the struct
|
|
97
|
+
* @return {BigNumberish | ParsedStruct} - parsed arguments in format that contract is expecting
|
|
98
|
+
*/
|
|
99
|
+
protected parseResponseStruct(
|
|
100
|
+
responseIterator: Iterator<string>,
|
|
101
|
+
type: string
|
|
102
|
+
): BigNumberish | ParsedStruct;
|
|
103
|
+
/**
|
|
104
|
+
* Parse one field of the calldata by using input field from the abi for that method
|
|
105
|
+
*
|
|
106
|
+
* @param args - value of the field
|
|
107
|
+
* @param input - input(field) information from the abi that will be used to parse the data
|
|
108
|
+
* @return {string | string[]} - parsed arguments in format that contract is expecting
|
|
109
|
+
*/
|
|
110
|
+
protected parseCalldataField(argsIterator: Iterator<any>, input: AbiEntry): string | string[];
|
|
111
|
+
/**
|
|
112
|
+
* Parse the calldata by using input fields from the abi for that method
|
|
113
|
+
*
|
|
114
|
+
* @param args - arguments passed the the method
|
|
115
|
+
* @param inputs - list of inputs(fields) that are in the abi
|
|
116
|
+
* @return {Calldata} - parsed arguments in format that contract is expecting
|
|
117
|
+
*/
|
|
118
|
+
protected compileCalldata(args: Array<any>, inputs: AbiEntry[]): Calldata;
|
|
119
|
+
/**
|
|
120
|
+
* Parse elements of the response and structuring them into one field by using output property from the abi for that method
|
|
121
|
+
*
|
|
122
|
+
* @param responseIterator - iterator of the response
|
|
123
|
+
* @param output - output(field) information from the abi that will be used to parse the data
|
|
124
|
+
* @return - parsed response corresponding to the abi structure of the field
|
|
125
|
+
*/
|
|
126
|
+
protected parseResponseField(
|
|
127
|
+
responseIterator: Iterator<string>,
|
|
128
|
+
output: AbiEntry,
|
|
129
|
+
parsedResult?: Args
|
|
130
|
+
): any;
|
|
131
|
+
/**
|
|
132
|
+
* Parse elements of the response array and structuring them into response object
|
|
133
|
+
*
|
|
134
|
+
* @param method - method name
|
|
135
|
+
* @param response - response from the method
|
|
136
|
+
* @return - parsed response corresponding to the abi
|
|
137
|
+
*/
|
|
138
|
+
protected parseResponse(method: string, response: string[]): Result;
|
|
139
|
+
invoke(method: string, args?: Array<any>): Promise<AddTransactionResponse>;
|
|
140
|
+
call(method: string, args?: Array<any>): Promise<Result>;
|
|
141
|
+
estimate(method: string, args?: Array<any>): Promise<import('../types').EstimateFeeResponse>;
|
|
142
|
+
populate(method: string, args?: Array<any>): Invocation;
|
|
143
|
+
}
|