-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype-extensions.ts
272 lines (236 loc) · 9.13 KB
/
type-extensions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
import "hardhat/types/config";
import "hardhat/types/runtime";
import {
AccountImplementationType,
BlockIdentifier,
DeployAccountOptions,
StarknetContract,
StarknetContractFactory,
StringMap
} from "./types";
import { StarknetWrapper } from "./starknet-wrappers";
import {
FlushResponse,
IncreaseTimeResponse,
LoadL1MessagingContractResponse,
SetTimeResponse,
PredeployedAccount
} from "./devnet-utils";
import { Account, ArgentAccount, OpenZeppelinAccount } from "./account";
import { Transaction, TransactionReceipt, Block } from "./starknet-types";
import { HardhatNetworkConfig, NetworkConfig } from "hardhat/types/config";
import { StarknetChainId } from "starknet/constants";
type StarknetConfig = {
dockerizedVersion?: string;
venv?: string;
wallets?: WalletUserConfig;
network?: string;
networkUrl?: string;
networkConfig?: NetworkConfig;
};
type WalletUserConfig = {
[walletName: string]: WalletConfig | undefined;
};
type WalletConfig = {
modulePath: string;
accountName?: string;
accountPath?: string;
};
declare module "hardhat/types/config" {
export interface ProjectPathsUserConfig {
starknetArtifacts?: string;
starknetSources?: string;
cairoPaths?: string[];
}
export interface ProjectPathsConfig {
starknetArtifacts: string;
starknetSources?: string;
cairoPaths?: string[];
}
export interface HardhatConfig {
starknet: StarknetConfig;
}
export interface HardhatUserConfig {
starknet?: StarknetConfig;
}
export interface NetworksConfig {
alpha: HttpNetworkConfig;
alphaMainnet: HttpNetworkConfig;
integratedDevnet: HardhatNetworkConfig;
}
export interface NetworksUserConfig {
integratedDevnet?: HardhatNetworkUserConfig;
}
export interface HttpNetworkConfig {
verificationUrl?: string;
verifiedUrl?: string;
starknetChainId?: StarknetChainId;
}
export interface HardhatNetworkConfig {
url?: string;
venv?: string;
dockerizedVersion?: string;
starknetChainId?: StarknetChainId;
args?: string[];
}
export interface HardhatNetworkUserConfig {
url?: string;
venv?: string;
dockerizedVersion?: string;
args?: string[];
}
}
type StarknetContractType = StarknetContract;
type StarknetContractFactoryType = StarknetContractFactory;
type StringMapType = StringMap;
type AccountType = Account;
type OpenZeppelinAccountType = OpenZeppelinAccount;
type ArgentAccountType = ArgentAccount;
type TransactionReceiptType = TransactionReceipt;
type TransactionType = Transaction;
type BlockType = Block;
declare module "hardhat/types/runtime" {
interface Devnet {
/**
* Restarts the devnet.
* @returns void
* @throws {@link HardhatPluginError}
*/
restart(): Promise<void>;
/**
* Handles all pending L1 to L2 messages and sends them to the other layer
* @returns {Promise} - Metadata for the flushed messages
*/
flush: () => Promise<FlushResponse>;
/**
* Deploys or loads the L1 messaging contract.
* @param {string} networkUrl - L1 network url.
* @param {string} [address] - Address of the contract to be loaded.
* @param {string} [networkId] - Determines if the ganache or tesnet should be used/
* @returns
*/
loadL1MessagingContract: (
networkUrl: string,
address?: string,
networkId?: string
) => Promise<LoadL1MessagingContractResponse>;
/**
* Increases block time offset
* @param seconds the offset increase in seconds
* @returns an object containing the increased block time offset
*/
increaseTime: (seconds: number) => Promise<IncreaseTimeResponse>;
/**
* Sets the timestamp of next block
* @param seconds timestamp in seconds
* @returns an object containg next block timestamp
*/
setTime: (seconds: number) => Promise<SetTimeResponse>;
/**
* Fetch the predeployed accounts
* @returns an object containg array of account's metadata
*/
getPredeployedAccounts: () => Promise<PredeployedAccount[]>;
/**
* Preserves devnet instance to a file
* @param path path for the dumping
* @return void
*/
dump: (path: string) => Promise<void>;
/**
* Loads stored Starknet chain state
* @param path path for the dump file
* @returns void
*/
load: (path: string) => Promise<void>;
}
interface HardhatRuntimeEnvironment {
starknetWrapper: StarknetWrapper;
starknet: {
/**
* Fetches a compiled contract by name. E.g. if the contract is defined in MyContract.cairo,
* the provided string should be `MyContract`.
* @param name the case-sensitive contract name
* @returns a factory for generating instances of the desired contract
*/
getContractFactory: (name: string) => Promise<StarknetContractFactory>;
/**
* Cairo and Starknet source files may contain short string literals,
* which are interpreted as numbers (felts) during Starknet runtime.
* Use this utility function to provide short string arguments to your contract functions.
*
* This function converts such a short string (max 31 characters) to its felt representation (wrapped in a `BigInt`).
* Only accepts standard ASCII characters, i.e. characters with charcode between 0 and 127, inclusive.
* @param input the input short string
* @returns the numeric equivalent of the input short string, wrapped in a `BigInt`
*/
shortStringToBigInt: (convertableString: string) => BigInt;
/**
* Converts a BigInt to a string. The opposite of {@link shortStringToBigInt}.
* @param input the input BigInt
* @returns a string which is the result of converting a BigInt's hex value to its ASCII equivalent
*/
bigIntToShortString: (convertableBigInt: BigInt) => string;
/**
* The selected starknet-network name.
* Present if the called task relies on `--starknet-network` or `starknet["network"]` in the config object.
*/
network?: string;
/**
* The selected starknet-network url.
* Present if the called task relies on `--starknet-network` or `starknet["network"]` in the config object.
*/
networkUrl?: string;
/**
* The configuration object of the selected starknet-network.
*/
networkConfig?: HardhatNetworkConfig;
/**
* @param name the name of the wallet to get
* @returns a wallet
*/
getWallet: (name: string) => WalletConfig;
devnet: Devnet;
/**
* Deploys an Account contract based on the ABI and the type of Account selected
* @param accountType the enumerator value of the type of Account to use
* @param options optional deployment options
* @returns an Account object
*/
deployAccount: (
accountType: AccountImplementationType,
options?: DeployAccountOptions
) => Promise<Account>;
/**
* Returns an Account already deployed based on the address and validated by the private key
* @param address the address where the account is deployed
* @param privateKey the private key of the account
* @param accountType the enumerator value of the type of Account to use
* @returns an Account object
*/
getAccountFromAddress: (
address: string,
privateKey: string,
accountType: AccountImplementationType
) => Promise<Account>;
getTransaction: (txHash: string) => Promise<Transaction>;
getTransactionReceipt: (txHash: string) => Promise<TransactionReceipt>;
/**
* Returns an entire block and the transactions contained within it.
* @param identifier optional block identifier (by block number or hash). To query the latest block, remove the identifier.
* @returns a block object
*/
getBlock: (identifier?: BlockIdentifier) => Promise<Block>;
};
}
type StarknetContract = StarknetContractType;
type StarknetContractFactory = StarknetContractFactoryType;
type StringMap = StringMapType;
type Wallet = WalletConfig;
type Account = AccountType;
type OpenZeppelinAccount = OpenZeppelinAccountType;
type ArgentAccount = ArgentAccountType;
type Transaction = TransactionType;
type TransactionReceipt = TransactionReceiptType;
type Block = BlockType;
}