starknet 4.17.0 → 4.18.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 +20 -0
- package/README.md +2 -10
- package/dist/index.d.ts +27 -9
- package/dist/index.global.js +30 -13
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +30 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -1
- package/.babelrc +0 -6
- package/.commitlintrc +0 -22
- package/.eslintignore +0 -2
- package/.eslintrc +0 -28
- package/.prettierrc +0 -6
- package/.releaserc +0 -28
- package/CODE_OF_CONDUCT.md +0 -128
- package/CONTRIBUTING.md +0 -52
- package/__mocks__/Account.json +0 -25486
- package/__mocks__/ERC20.json +0 -40027
- package/__mocks__/TestDapp.json +0 -12962
- package/__mocks__/contract.json +0 -33191
- package/__mocks__/l1l2_compiled.json +0 -10107
- package/__mocks__/multicall.json +0 -8139
- package/__mocks__/naming_compiled.json +0 -53283
- package/__mocks__/starknetId_compiled.json +0 -44703
- package/__mocks__/typedDataExample.json +0 -35
- package/__mocks__/typedDataSessionExample.json +0 -42
- package/__mocks__/typedDataStructArrayExample.json +0 -44
- package/__tests__/account.test.ts +0 -345
- package/__tests__/contract.test.ts +0 -249
- package/__tests__/defaultProvider.test.ts +0 -177
- package/__tests__/fixtures.ts +0 -84
- package/__tests__/jest.setup.ts +0 -30
- package/__tests__/rpcProvider.test.ts +0 -132
- package/__tests__/sequencerProvider.test.ts +0 -123
- package/__tests__/utils/__snapshots__/ellipticalCurve.test.ts.snap +0 -5
- package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +0 -5
- package/__tests__/utils/__snapshots__/utils.test.ts.snap +0 -5
- package/__tests__/utils/address.test.ts +0 -45
- package/__tests__/utils/ellipticalCurve.test.ts +0 -91
- package/__tests__/utils/merkle.test.ts +0 -256
- package/__tests__/utils/shortString.test.ts +0 -22
- package/__tests__/utils/starknetId.test.ts +0 -53
- package/__tests__/utils/transactionHash.test.ts +0 -17
- package/__tests__/utils/typedData.test.ts +0 -223
- package/__tests__/utils/uint256.test.ts +0 -32
- package/__tests__/utils/utils.browser.test.ts +0 -29
- package/__tests__/utils/utils.test.ts +0 -141
- package/img/logo.svg +0 -17
- package/index.d.ts +0 -2683
- package/index.global.js +0 -23192
- package/index.global.js.map +0 -1
- package/index.js +0 -4910
- package/index.js.map +0 -1
- package/index.mjs +0 -4852
- package/index.mjs.map +0 -1
- package/src/account/default.ts +0 -501
- package/src/account/index.ts +0 -2
- package/src/account/interface.ts +0 -309
- package/src/constants.ts +0 -2065
- package/src/contract/contractFactory.ts +0 -88
- package/src/contract/default.ts +0 -425
- package/src/contract/index.ts +0 -3
- package/src/contract/interface.ts +0 -106
- package/src/index.ts +0 -26
- package/src/provider/default.ts +0 -187
- package/src/provider/errors.ts +0 -14
- package/src/provider/index.ts +0 -9
- package/src/provider/interface.ts +0 -281
- package/src/provider/rpc.ts +0 -482
- package/src/provider/sequencer.ts +0 -523
- package/src/provider/utils.ts +0 -100
- package/src/signer/default.ts +0 -99
- package/src/signer/index.ts +0 -2
- package/src/signer/interface.ts +0 -77
- package/src/types/account.ts +0 -43
- package/src/types/api/index.ts +0 -10
- package/src/types/api/openrpc.ts +0 -607
- package/src/types/api/rpc.ts +0 -45
- package/src/types/api/sequencer.ts +0 -369
- package/src/types/contract.ts +0 -5
- package/src/types/index.ts +0 -8
- package/src/types/lib.ts +0 -143
- package/src/types/provider.ts +0 -134
- package/src/types/signer.ts +0 -24
- package/src/utils/address.ts +0 -44
- package/src/utils/calldata.ts +0 -250
- package/src/utils/ellipticCurve.ts +0 -120
- package/src/utils/encode.ts +0 -66
- package/src/utils/events.ts +0 -32
- package/src/utils/fetchPonyfill.ts +0 -5
- package/src/utils/hash.ts +0 -235
- package/src/utils/json.ts +0 -15
- package/src/utils/merkle.ts +0 -69
- package/src/utils/number.ts +0 -98
- package/src/utils/provider.ts +0 -28
- package/src/utils/responseParser/index.ts +0 -28
- package/src/utils/responseParser/rpc.ts +0 -70
- package/src/utils/responseParser/sequencer.ts +0 -135
- package/src/utils/shortString.ts +0 -21
- package/src/utils/stark.ts +0 -57
- package/src/utils/starknetId.ts +0 -116
- package/src/utils/transaction.ts +0 -56
- package/src/utils/typedData/index.ts +0 -247
- package/src/utils/typedData/types.ts +0 -37
- package/src/utils/typedData/utils.ts +0 -16
- package/src/utils/uint256.ts +0 -32
- package/src/utils/url.ts +0 -53
- package/tsconfig.eslint.json +0 -4
- package/tsup.config.ts +0 -9
- package/www/README.md +0 -41
- package/www/babel.config.js +0 -3
- package/www/code-examples/account.js +0 -65
- package/www/code-examples/amm.js +0 -44
- package/www/code-examples/erc20.js +0 -13
- package/www/code-examples/package-lock.json +0 -336
- package/www/code-examples/package.json +0 -15
- package/www/docs/API/_category_.json +0 -5
- package/www/docs/API/account.md +0 -463
- package/www/docs/API/changelog.md +0 -15
- package/www/docs/API/contract.md +0 -135
- package/www/docs/API/contractFactory.md +0 -45
- package/www/docs/API/index.md +0 -3
- package/www/docs/API/provider.md +0 -725
- package/www/docs/API/signer.md +0 -105
- package/www/docs/API/utils.md +0 -374
- package/www/docusaurus.config.js +0 -130
- package/www/guides/account.md +0 -140
- package/www/guides/cra.md +0 -3
- package/www/guides/erc20.md +0 -163
- package/www/guides/intro.md +0 -63
- package/www/package-lock.json +0 -20405
- package/www/package.json +0 -43
- package/www/sidebars.js +0 -31
- package/www/src/components/HomepageFeatures/index.tsx +0 -67
- package/www/src/components/HomepageFeatures/styles.module.css +0 -10
- package/www/src/css/custom.css +0 -39
- package/www/src/pages/index.module.css +0 -23
- package/www/src/pages/index.tsx +0 -40
- package/www/src/pages/markdown-page.md +0 -7
- 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 +0 -17
- 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/src/account/default.ts
DELETED
|
@@ -1,501 +0,0 @@
|
|
|
1
|
-
import { BN } from 'bn.js';
|
|
2
|
-
|
|
3
|
-
import { UDC, ZERO } from '../constants';
|
|
4
|
-
import { ProviderInterface, ProviderOptions } from '../provider';
|
|
5
|
-
import { Provider } from '../provider/default';
|
|
6
|
-
import { BlockIdentifier } from '../provider/utils';
|
|
7
|
-
import { Signer, SignerInterface } from '../signer';
|
|
8
|
-
import {
|
|
9
|
-
Abi,
|
|
10
|
-
AllowArray,
|
|
11
|
-
Call,
|
|
12
|
-
DeclareContractPayload,
|
|
13
|
-
DeclareContractResponse,
|
|
14
|
-
DeclareDeployContractPayload,
|
|
15
|
-
DeclareDeployUDCResponse,
|
|
16
|
-
DeployAccountContractPayload,
|
|
17
|
-
DeployContractResponse,
|
|
18
|
-
DeployContractUDCResponse,
|
|
19
|
-
EstimateFee,
|
|
20
|
-
EstimateFeeAction,
|
|
21
|
-
EstimateFeeDetails,
|
|
22
|
-
InvocationsDetails,
|
|
23
|
-
InvocationsSignerDetails,
|
|
24
|
-
InvokeFunctionResponse,
|
|
25
|
-
KeyPair,
|
|
26
|
-
MultiDeployContractResponse,
|
|
27
|
-
Signature,
|
|
28
|
-
UniversalDeployerContractPayload,
|
|
29
|
-
} from '../types';
|
|
30
|
-
import { parseUDCEvent } from '../utils/events';
|
|
31
|
-
import {
|
|
32
|
-
calculateContractAddressFromHash,
|
|
33
|
-
feeTransactionVersion,
|
|
34
|
-
pedersen,
|
|
35
|
-
transactionVersion,
|
|
36
|
-
} from '../utils/hash';
|
|
37
|
-
import { BigNumberish, hexToDecimalString, toBN, toCairoBool } from '../utils/number';
|
|
38
|
-
import { parseContract } from '../utils/provider';
|
|
39
|
-
import { compileCalldata, estimatedFeeToMaxFee, randomAddress } from '../utils/stark';
|
|
40
|
-
import { getStarknetIdContract, useDecoded, useEncoded } from '../utils/starknetId';
|
|
41
|
-
import { fromCallsToExecuteCalldata } from '../utils/transaction';
|
|
42
|
-
import { TypedData, getMessageHash } from '../utils/typedData';
|
|
43
|
-
import { AccountInterface } from './interface';
|
|
44
|
-
|
|
45
|
-
export class Account extends Provider implements AccountInterface {
|
|
46
|
-
public signer: SignerInterface;
|
|
47
|
-
|
|
48
|
-
public address: string;
|
|
49
|
-
|
|
50
|
-
constructor(
|
|
51
|
-
providerOrOptions: ProviderOptions | ProviderInterface,
|
|
52
|
-
address: string,
|
|
53
|
-
keyPairOrSigner: KeyPair | SignerInterface
|
|
54
|
-
) {
|
|
55
|
-
super(providerOrOptions);
|
|
56
|
-
this.address = address.toLowerCase();
|
|
57
|
-
this.signer =
|
|
58
|
-
'getPubKey' in keyPairOrSigner ? keyPairOrSigner : new Signer(keyPairOrSigner as KeyPair);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public async getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish> {
|
|
62
|
-
return super.getNonceForAddress(this.address, blockIdentifier);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public async getStarkName(StarknetIdContract?: string): Promise<string | Error> {
|
|
66
|
-
const chainId = await this.getChainId();
|
|
67
|
-
const contract = StarknetIdContract ?? getStarknetIdContract(chainId);
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
const hexDomain = await this.callContract({
|
|
71
|
-
contractAddress: contract,
|
|
72
|
-
entrypoint: 'address_to_domain',
|
|
73
|
-
calldata: compileCalldata({
|
|
74
|
-
address: this.address,
|
|
75
|
-
}),
|
|
76
|
-
});
|
|
77
|
-
const decimalDomain = hexDomain.result
|
|
78
|
-
.map((element) => new BN(hexToDecimalString(element)))
|
|
79
|
-
.slice(1);
|
|
80
|
-
|
|
81
|
-
const stringDomain = useDecoded(decimalDomain);
|
|
82
|
-
|
|
83
|
-
return stringDomain;
|
|
84
|
-
} catch {
|
|
85
|
-
return Error('Could not get stark name');
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public async getAddressFromStarkName(
|
|
90
|
-
name: string,
|
|
91
|
-
StarknetIdContract?: string
|
|
92
|
-
): Promise<string | Error> {
|
|
93
|
-
const chainId = await this.getChainId();
|
|
94
|
-
const contract = StarknetIdContract ?? getStarknetIdContract(chainId);
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
const addressData = await this.callContract({
|
|
98
|
-
contractAddress: contract,
|
|
99
|
-
entrypoint: 'domain_to_address',
|
|
100
|
-
calldata: compileCalldata({
|
|
101
|
-
domain: [useEncoded(name.replace('.stark', '')).toString(10)],
|
|
102
|
-
}),
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
return addressData.result[0];
|
|
106
|
-
} catch {
|
|
107
|
-
return Error('Could not get address from stark name');
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public async estimateFee(
|
|
112
|
-
calls: AllowArray<Call>,
|
|
113
|
-
estimateFeeDetails?: EstimateFeeDetails | undefined
|
|
114
|
-
): Promise<EstimateFee> {
|
|
115
|
-
return this.estimateInvokeFee(calls, estimateFeeDetails);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
public async estimateInvokeFee(
|
|
119
|
-
calls: AllowArray<Call>,
|
|
120
|
-
{ nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {}
|
|
121
|
-
): Promise<EstimateFee> {
|
|
122
|
-
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
123
|
-
const nonce = toBN(providedNonce ?? (await this.getNonce()));
|
|
124
|
-
const version = toBN(feeTransactionVersion);
|
|
125
|
-
const chainId = await this.getChainId();
|
|
126
|
-
|
|
127
|
-
const signerDetails: InvocationsSignerDetails = {
|
|
128
|
-
walletAddress: this.address,
|
|
129
|
-
nonce,
|
|
130
|
-
maxFee: ZERO,
|
|
131
|
-
version,
|
|
132
|
-
chainId,
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const signature = await this.signer.signTransaction(transactions, signerDetails);
|
|
136
|
-
|
|
137
|
-
const calldata = fromCallsToExecuteCalldata(transactions);
|
|
138
|
-
const response = await super.getInvokeEstimateFee(
|
|
139
|
-
{ contractAddress: this.address, calldata, signature },
|
|
140
|
-
{ version, nonce },
|
|
141
|
-
blockIdentifier
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
...response,
|
|
148
|
-
suggestedMaxFee,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
public async estimateDeclareFee(
|
|
153
|
-
{ classHash, contract }: DeclareContractPayload,
|
|
154
|
-
{ blockIdentifier, nonce: providedNonce }: EstimateFeeDetails = {}
|
|
155
|
-
): Promise<EstimateFee> {
|
|
156
|
-
const nonce = toBN(providedNonce ?? (await this.getNonce()));
|
|
157
|
-
const version = toBN(feeTransactionVersion);
|
|
158
|
-
const chainId = await this.getChainId();
|
|
159
|
-
const contractDefinition = parseContract(contract);
|
|
160
|
-
|
|
161
|
-
const signature = await this.signer.signDeclareTransaction({
|
|
162
|
-
classHash,
|
|
163
|
-
senderAddress: this.address,
|
|
164
|
-
chainId,
|
|
165
|
-
maxFee: ZERO,
|
|
166
|
-
version,
|
|
167
|
-
nonce,
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const response = await super.getDeclareEstimateFee(
|
|
171
|
-
{ senderAddress: this.address, signature, contractDefinition },
|
|
172
|
-
{ version, nonce },
|
|
173
|
-
blockIdentifier
|
|
174
|
-
);
|
|
175
|
-
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
176
|
-
|
|
177
|
-
return {
|
|
178
|
-
...response,
|
|
179
|
-
suggestedMaxFee,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
public async estimateAccountDeployFee(
|
|
184
|
-
{
|
|
185
|
-
classHash,
|
|
186
|
-
addressSalt = 0,
|
|
187
|
-
constructorCalldata = [],
|
|
188
|
-
contractAddress: providedContractAddress,
|
|
189
|
-
}: DeployAccountContractPayload,
|
|
190
|
-
{ blockIdentifier, nonce: providedNonce }: EstimateFeeDetails = {}
|
|
191
|
-
): Promise<EstimateFee> {
|
|
192
|
-
const nonce = toBN(providedNonce ?? (await this.getNonce()));
|
|
193
|
-
const version = toBN(feeTransactionVersion);
|
|
194
|
-
const chainId = await this.getChainId();
|
|
195
|
-
const contractAddress =
|
|
196
|
-
providedContractAddress ??
|
|
197
|
-
calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
|
|
198
|
-
|
|
199
|
-
const signature = await this.signer.signDeployAccountTransaction({
|
|
200
|
-
classHash,
|
|
201
|
-
contractAddress,
|
|
202
|
-
chainId,
|
|
203
|
-
maxFee: ZERO,
|
|
204
|
-
version,
|
|
205
|
-
nonce,
|
|
206
|
-
addressSalt,
|
|
207
|
-
constructorCalldata,
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
const response = await super.getDeployAccountEstimateFee(
|
|
211
|
-
{ classHash, addressSalt, constructorCalldata, signature },
|
|
212
|
-
{ version, nonce },
|
|
213
|
-
blockIdentifier
|
|
214
|
-
);
|
|
215
|
-
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
216
|
-
|
|
217
|
-
return {
|
|
218
|
-
...response,
|
|
219
|
-
suggestedMaxFee,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
public async estimateDeployFee(
|
|
224
|
-
payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[],
|
|
225
|
-
transactionsDetail?: InvocationsDetails | undefined
|
|
226
|
-
): Promise<EstimateFee> {
|
|
227
|
-
const calls = [].concat(payload as []).map((it) => {
|
|
228
|
-
const {
|
|
229
|
-
classHash,
|
|
230
|
-
salt = '0',
|
|
231
|
-
unique = true,
|
|
232
|
-
constructorCalldata = [],
|
|
233
|
-
} = it as UniversalDeployerContractPayload;
|
|
234
|
-
const compiledConstructorCallData = compileCalldata(constructorCalldata);
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
contractAddress: UDC.ADDRESS,
|
|
238
|
-
entrypoint: UDC.ENTRYPOINT,
|
|
239
|
-
calldata: [
|
|
240
|
-
classHash,
|
|
241
|
-
salt,
|
|
242
|
-
toCairoBool(unique),
|
|
243
|
-
compiledConstructorCallData.length,
|
|
244
|
-
...compiledConstructorCallData,
|
|
245
|
-
],
|
|
246
|
-
};
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
return this.estimateInvokeFee(calls, transactionsDetail);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
public async execute(
|
|
253
|
-
calls: AllowArray<Call>,
|
|
254
|
-
abis: Abi[] | undefined = undefined,
|
|
255
|
-
transactionsDetail: InvocationsDetails = {}
|
|
256
|
-
): Promise<InvokeFunctionResponse> {
|
|
257
|
-
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
258
|
-
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
|
|
259
|
-
const maxFee =
|
|
260
|
-
transactionsDetail.maxFee ??
|
|
261
|
-
(await this.getSuggestedMaxFee({ type: 'INVOKE', payload: calls }, transactionsDetail));
|
|
262
|
-
const version = toBN(transactionVersion);
|
|
263
|
-
const chainId = await this.getChainId();
|
|
264
|
-
|
|
265
|
-
const signerDetails: InvocationsSignerDetails = {
|
|
266
|
-
walletAddress: this.address,
|
|
267
|
-
nonce,
|
|
268
|
-
maxFee,
|
|
269
|
-
version,
|
|
270
|
-
chainId,
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
|
|
274
|
-
|
|
275
|
-
const calldata = fromCallsToExecuteCalldata(transactions);
|
|
276
|
-
|
|
277
|
-
return this.invokeFunction(
|
|
278
|
-
{ contractAddress: this.address, calldata, signature },
|
|
279
|
-
{
|
|
280
|
-
nonce,
|
|
281
|
-
maxFee,
|
|
282
|
-
version,
|
|
283
|
-
}
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
public async declare(
|
|
288
|
-
{ classHash, contract }: DeclareContractPayload,
|
|
289
|
-
transactionsDetail: InvocationsDetails = {}
|
|
290
|
-
): Promise<DeclareContractResponse> {
|
|
291
|
-
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
|
|
292
|
-
const maxFee =
|
|
293
|
-
transactionsDetail.maxFee ??
|
|
294
|
-
(await this.getSuggestedMaxFee(
|
|
295
|
-
{ type: 'DECLARE', payload: { classHash, contract } },
|
|
296
|
-
transactionsDetail
|
|
297
|
-
));
|
|
298
|
-
|
|
299
|
-
const version = toBN(transactionVersion);
|
|
300
|
-
const chainId = await this.getChainId();
|
|
301
|
-
|
|
302
|
-
const signature = await this.signer.signDeclareTransaction({
|
|
303
|
-
classHash,
|
|
304
|
-
senderAddress: this.address,
|
|
305
|
-
chainId,
|
|
306
|
-
maxFee,
|
|
307
|
-
version,
|
|
308
|
-
nonce,
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
const contractDefinition = parseContract(contract);
|
|
312
|
-
|
|
313
|
-
return this.declareContract(
|
|
314
|
-
{ contractDefinition, senderAddress: this.address, signature },
|
|
315
|
-
{
|
|
316
|
-
nonce,
|
|
317
|
-
maxFee,
|
|
318
|
-
version,
|
|
319
|
-
}
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
public async deploy(
|
|
324
|
-
payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[],
|
|
325
|
-
details?: InvocationsDetails | undefined
|
|
326
|
-
): Promise<MultiDeployContractResponse> {
|
|
327
|
-
const params = [].concat(payload as []).map((it) => {
|
|
328
|
-
const {
|
|
329
|
-
classHash,
|
|
330
|
-
salt,
|
|
331
|
-
unique = true,
|
|
332
|
-
constructorCalldata = [],
|
|
333
|
-
} = it as UniversalDeployerContractPayload;
|
|
334
|
-
|
|
335
|
-
const compiledConstructorCallData = compileCalldata(constructorCalldata);
|
|
336
|
-
const deploySalt = salt ?? randomAddress();
|
|
337
|
-
|
|
338
|
-
return {
|
|
339
|
-
call: {
|
|
340
|
-
contractAddress: UDC.ADDRESS,
|
|
341
|
-
entrypoint: UDC.ENTRYPOINT,
|
|
342
|
-
calldata: [
|
|
343
|
-
classHash,
|
|
344
|
-
deploySalt,
|
|
345
|
-
toCairoBool(unique),
|
|
346
|
-
compiledConstructorCallData.length,
|
|
347
|
-
...compiledConstructorCallData,
|
|
348
|
-
],
|
|
349
|
-
},
|
|
350
|
-
address: calculateContractAddressFromHash(
|
|
351
|
-
unique ? pedersen([this.address, deploySalt]) : deploySalt,
|
|
352
|
-
classHash,
|
|
353
|
-
compiledConstructorCallData,
|
|
354
|
-
unique ? UDC.ADDRESS : 0
|
|
355
|
-
),
|
|
356
|
-
};
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
const calls = params.map((it) => it.call);
|
|
360
|
-
const addresses = params.map((it) => it.address);
|
|
361
|
-
const invokeResponse = await this.execute(calls, undefined, details);
|
|
362
|
-
|
|
363
|
-
return {
|
|
364
|
-
...invokeResponse,
|
|
365
|
-
contract_address: addresses,
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
public async deployContract(
|
|
370
|
-
payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[],
|
|
371
|
-
details?: InvocationsDetails | undefined
|
|
372
|
-
): Promise<DeployContractUDCResponse> {
|
|
373
|
-
const deployTx = await this.deploy(payload, details);
|
|
374
|
-
const txReceipt = await this.waitForTransaction(deployTx.transaction_hash, undefined, [
|
|
375
|
-
'ACCEPTED_ON_L2',
|
|
376
|
-
]);
|
|
377
|
-
return parseUDCEvent(txReceipt);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
public async declareDeploy(
|
|
381
|
-
payload: DeclareDeployContractPayload,
|
|
382
|
-
details?: InvocationsDetails | undefined
|
|
383
|
-
): Promise<DeclareDeployUDCResponse> {
|
|
384
|
-
const { classHash, contract, constructorCalldata, salt, unique } = payload;
|
|
385
|
-
const { transaction_hash } = await this.declare({ contract, classHash }, details);
|
|
386
|
-
const declare = await this.waitForTransaction(transaction_hash, undefined, ['ACCEPTED_ON_L2']);
|
|
387
|
-
const deploy = await this.deployContract(
|
|
388
|
-
{ classHash, salt, unique, constructorCalldata },
|
|
389
|
-
details
|
|
390
|
-
);
|
|
391
|
-
return { declare: { ...declare, class_hash: classHash }, deploy };
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
public async deployAccount(
|
|
395
|
-
{
|
|
396
|
-
classHash,
|
|
397
|
-
constructorCalldata = [],
|
|
398
|
-
addressSalt = 0,
|
|
399
|
-
contractAddress: providedContractAddress,
|
|
400
|
-
}: DeployAccountContractPayload,
|
|
401
|
-
transactionsDetail: InvocationsDetails = {}
|
|
402
|
-
): Promise<DeployContractResponse> {
|
|
403
|
-
const nonce = toBN(transactionsDetail.nonce ?? (await this.getNonce()));
|
|
404
|
-
const version = toBN(transactionVersion);
|
|
405
|
-
const chainId = await this.getChainId();
|
|
406
|
-
|
|
407
|
-
const contractAddress =
|
|
408
|
-
providedContractAddress ??
|
|
409
|
-
calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
|
|
410
|
-
|
|
411
|
-
const maxFee =
|
|
412
|
-
transactionsDetail.maxFee ??
|
|
413
|
-
(await this.getSuggestedMaxFee(
|
|
414
|
-
{
|
|
415
|
-
type: 'DEPLOY_ACCOUNT',
|
|
416
|
-
payload: { classHash, constructorCalldata, addressSalt, contractAddress },
|
|
417
|
-
},
|
|
418
|
-
transactionsDetail
|
|
419
|
-
));
|
|
420
|
-
|
|
421
|
-
const signature = await this.signer.signDeployAccountTransaction({
|
|
422
|
-
classHash,
|
|
423
|
-
constructorCalldata,
|
|
424
|
-
contractAddress,
|
|
425
|
-
addressSalt,
|
|
426
|
-
chainId,
|
|
427
|
-
maxFee,
|
|
428
|
-
version,
|
|
429
|
-
nonce,
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
return this.deployAccountContract(
|
|
433
|
-
{ classHash, addressSalt, constructorCalldata, signature },
|
|
434
|
-
{
|
|
435
|
-
nonce,
|
|
436
|
-
maxFee,
|
|
437
|
-
version,
|
|
438
|
-
}
|
|
439
|
-
);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
public async signMessage(typedData: TypedData): Promise<Signature> {
|
|
443
|
-
return this.signer.signMessage(typedData, this.address);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
public async hashMessage(typedData: TypedData): Promise<string> {
|
|
447
|
-
return getMessageHash(typedData, this.address);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
public async verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean> {
|
|
451
|
-
try {
|
|
452
|
-
await this.callContract({
|
|
453
|
-
contractAddress: this.address,
|
|
454
|
-
entrypoint: 'isValidSignature',
|
|
455
|
-
calldata: compileCalldata({
|
|
456
|
-
hash: toBN(hash).toString(),
|
|
457
|
-
signature: signature.map((x) => toBN(x).toString()),
|
|
458
|
-
}),
|
|
459
|
-
});
|
|
460
|
-
return true;
|
|
461
|
-
} catch {
|
|
462
|
-
return false;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
public async verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean> {
|
|
467
|
-
const hash = await this.hashMessage(typedData);
|
|
468
|
-
return this.verifyMessageHash(hash, signature);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
public async getSuggestedMaxFee(
|
|
472
|
-
{ type, payload }: EstimateFeeAction,
|
|
473
|
-
details: EstimateFeeDetails
|
|
474
|
-
) {
|
|
475
|
-
let feeEstimate: EstimateFee;
|
|
476
|
-
|
|
477
|
-
switch (type) {
|
|
478
|
-
case 'INVOKE':
|
|
479
|
-
feeEstimate = await this.estimateInvokeFee(payload, details);
|
|
480
|
-
break;
|
|
481
|
-
|
|
482
|
-
case 'DECLARE':
|
|
483
|
-
feeEstimate = await this.estimateDeclareFee(payload, details);
|
|
484
|
-
break;
|
|
485
|
-
|
|
486
|
-
case 'DEPLOY_ACCOUNT':
|
|
487
|
-
feeEstimate = await this.estimateAccountDeployFee(payload, details);
|
|
488
|
-
break;
|
|
489
|
-
|
|
490
|
-
case 'DEPLOY':
|
|
491
|
-
feeEstimate = await this.estimateDeployFee(payload, details);
|
|
492
|
-
break;
|
|
493
|
-
|
|
494
|
-
default:
|
|
495
|
-
feeEstimate = { suggestedMaxFee: ZERO, overall_fee: ZERO };
|
|
496
|
-
break;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
return feeEstimate.suggestedMaxFee.toString();
|
|
500
|
-
}
|
|
501
|
-
}
|
package/src/account/index.ts
DELETED