@latticexyz/common 2.2.18-90aac1d4acce19ac592d47a090732dd11c1c3e7a → 2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2

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.
Files changed (67) hide show
  1. package/dist/actions.cjs +334 -0
  2. package/dist/actions.cjs.map +1 -0
  3. package/dist/actions.d.cts +27 -0
  4. package/dist/actions.js +39 -1
  5. package/dist/actions.js.map +1 -1
  6. package/dist/chains.cjs +106 -0
  7. package/dist/chains.cjs.map +1 -0
  8. package/dist/chains.d.cts +968 -0
  9. package/dist/chains.js +75 -1
  10. package/dist/chains.js.map +1 -1
  11. package/dist/chunk-D4GDXAMP.js +64 -0
  12. package/dist/{chunk-ZIUX7JCQ.js.map → chunk-D4GDXAMP.js.map} +1 -1
  13. package/dist/chunk-IYZZFDNO.js +16 -0
  14. package/dist/{chunk-ZV2KGJCD.js.map → chunk-IYZZFDNO.js.map} +1 -1
  15. package/dist/chunk-MF5NFUW7.js +12 -0
  16. package/dist/{chunk-QQCZY3XJ.js.map → chunk-MF5NFUW7.js.map} +1 -1
  17. package/dist/chunk-MK6UECU7.js +11 -0
  18. package/dist/{chunk-TCWGPC6G.js.map → chunk-MK6UECU7.js.map} +1 -1
  19. package/dist/chunk-MYWRXQQH.js +208 -0
  20. package/dist/{chunk-6FIKI2CG.js.map → chunk-MYWRXQQH.js.map} +1 -1
  21. package/dist/chunk-Z6SVAIZN.js +70 -0
  22. package/dist/{chunk-DPUUE7NM.js.map → chunk-Z6SVAIZN.js.map} +1 -1
  23. package/dist/codegen.cjs +889 -0
  24. package/dist/codegen.cjs.map +1 -0
  25. package/dist/codegen.d.cts +228 -0
  26. package/dist/codegen.js +706 -49
  27. package/dist/codegen.js.map +1 -1
  28. package/dist/errors.cjs +38 -0
  29. package/dist/errors.cjs.map +1 -0
  30. package/dist/errors.d.cts +5 -0
  31. package/dist/errors.js +6 -1
  32. package/dist/foundry.cjs +105 -0
  33. package/dist/foundry.cjs.map +1 -0
  34. package/dist/foundry.d.cts +69 -0
  35. package/dist/foundry.js +71 -2
  36. package/dist/foundry.js.map +1 -1
  37. package/dist/getContract-CA0EdVg6.d.cts +20 -0
  38. package/dist/index.cjs +597 -0
  39. package/dist/index.cjs.map +1 -0
  40. package/dist/index.d.cts +160 -0
  41. package/dist/index.js +233 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/internal.cjs +459 -0
  44. package/dist/internal.cjs.map +1 -0
  45. package/dist/internal.d.cts +36 -0
  46. package/dist/internal.js +205 -9
  47. package/dist/internal.js.map +1 -1
  48. package/dist/kms.cjs +204 -0
  49. package/dist/kms.cjs.map +1 -0
  50. package/dist/kms.d.cts +18 -0
  51. package/dist/kms.js +168 -1
  52. package/dist/kms.js.map +1 -1
  53. package/dist/type-utils.cjs +19 -0
  54. package/dist/type-utils.cjs.map +1 -0
  55. package/dist/type-utils.d.cts +19 -0
  56. package/dist/utils.cjs +174 -0
  57. package/dist/utils.cjs.map +1 -0
  58. package/dist/utils.d.cts +40 -0
  59. package/dist/utils.js +122 -1
  60. package/dist/utils.js.map +1 -1
  61. package/package.json +104 -16
  62. package/dist/chunk-6FIKI2CG.js +0 -2
  63. package/dist/chunk-DPUUE7NM.js +0 -2
  64. package/dist/chunk-QQCZY3XJ.js +0 -2
  65. package/dist/chunk-TCWGPC6G.js +0 -2
  66. package/dist/chunk-ZIUX7JCQ.js +0 -2
  67. package/dist/chunk-ZV2KGJCD.js +0 -2
@@ -0,0 +1,459 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/exports/internal.ts
31
+ var internal_exports = {};
32
+ __export(internal_exports, {
33
+ ensureContract: () => ensureContract,
34
+ ensureContractsDeployed: () => ensureContractsDeployed,
35
+ ensureDeployer: () => ensureDeployer,
36
+ getContractAddress: () => getContractAddress,
37
+ getDeployer: () => getDeployer,
38
+ waitForTransactions: () => waitForTransactions
39
+ });
40
+ module.exports = __toCommonJS(internal_exports);
41
+
42
+ // src/debug.ts
43
+ var import_debug = __toESM(require("debug"), 1);
44
+ var debug = (0, import_debug.default)("mud:common");
45
+ var error = (0, import_debug.default)("mud:common");
46
+ debug.log = console.debug.bind(console);
47
+ error.log = console.error.bind(console);
48
+
49
+ // src/waitForTransactions.ts
50
+ var import_actions = require("viem/actions");
51
+ async function waitForTransactions({
52
+ client,
53
+ hashes,
54
+ debugLabel = "transactions"
55
+ }) {
56
+ if (!hashes.length) return;
57
+ debug(`waiting for ${debugLabel} to confirm`);
58
+ for (const hash of hashes) {
59
+ const receipt = await (0, import_actions.waitForTransactionReceipt)(client, { hash });
60
+ if (receipt.status === "reverted") {
61
+ throw new Error(`Transaction reverted: ${hash}`);
62
+ }
63
+ }
64
+ }
65
+
66
+ // src/deploy/ensureContract.ts
67
+ var import_viem3 = require("viem");
68
+ var import_actions7 = require("viem/actions");
69
+
70
+ // src/deploy/common.ts
71
+ var import_viem = require("viem");
72
+ var singletonSalt = (0, import_viem.stringToHex)("", { size: 32 });
73
+ var contractSizeLimit = parseInt("6000", 16);
74
+
75
+ // src/deploy/debug.ts
76
+ var debug2 = debug.extend("deploy");
77
+ var error2 = debug.extend("deploy");
78
+ debug2.log = console.debug.bind(console);
79
+ error2.log = console.error.bind(console);
80
+
81
+ // src/sendTransaction.ts
82
+ var import_actions6 = require("viem/actions");
83
+ var import_p_retry = __toESM(require("p-retry"), 1);
84
+
85
+ // src/getNonceManagerId.ts
86
+ var import_viem2 = require("viem");
87
+ var import_actions2 = require("viem/actions");
88
+ var import_utils = require("viem/utils");
89
+ async function getNonceManagerId({
90
+ client,
91
+ address,
92
+ blockTag
93
+ }) {
94
+ const chainId = client.chain?.id ?? await (0, import_utils.getAction)(client, import_actions2.getChainId, "getChainId")({});
95
+ return `mud:createNonceManager:${chainId}:${(0, import_viem2.getAddress)(address)}:${blockTag}`;
96
+ }
97
+
98
+ // src/createNonceManager.ts
99
+ var import_actions3 = require("viem/actions");
100
+ var import_p_queue = __toESM(require("p-queue"), 1);
101
+ var import_utils2 = require("viem/utils");
102
+
103
+ // src/findCause.ts
104
+ function findCause(error3, fn) {
105
+ if (fn?.(error3)) return error3;
106
+ if (error3.cause instanceof Error) return findCause(error3.cause, fn);
107
+ return fn ? null : error3;
108
+ }
109
+
110
+ // src/createNonceManager.ts
111
+ var debug3 = debug.extend("createNonceManager");
112
+ function createNonceManager({
113
+ client,
114
+ address,
115
+ // TODO: rename to account?
116
+ blockTag = "latest",
117
+ broadcastChannelName,
118
+ queueConcurrency = 1
119
+ }) {
120
+ const ref = { nonce: -1, noncePromise: null };
121
+ let channel = null;
122
+ if (typeof BroadcastChannel !== "undefined") {
123
+ const channelName = broadcastChannelName ? Promise.resolve(broadcastChannelName) : getNonceManagerId({ client, address, blockTag });
124
+ channelName.then((name) => {
125
+ channel = new BroadcastChannel(name);
126
+ channel.addEventListener("message", (event) => {
127
+ const nonce = JSON.parse(event.data);
128
+ debug3("got nonce from broadcast channel", nonce);
129
+ ref.nonce = nonce;
130
+ });
131
+ });
132
+ }
133
+ function hasNonce() {
134
+ return ref.nonce >= 0;
135
+ }
136
+ function getNonce() {
137
+ if (!hasNonce()) throw new Error("call resetNonce before using getNonce");
138
+ return ref.nonce;
139
+ }
140
+ function nextNonce() {
141
+ if (!hasNonce()) throw new Error("call resetNonce before using nextNonce");
142
+ const nonce = ref.nonce++;
143
+ channel?.postMessage(JSON.stringify(ref.nonce));
144
+ return nonce;
145
+ }
146
+ async function resetNonce() {
147
+ ref.noncePromise ??= (async () => {
148
+ ref.nonce = await (0, import_utils2.getAction)(client, import_actions3.getTransactionCount, "getTransactionCount")({ address, blockTag });
149
+ ref.noncePromise = null;
150
+ channel?.postMessage(JSON.stringify(ref.nonce));
151
+ debug3("reset nonce to", ref.nonce);
152
+ })();
153
+ await ref.noncePromise;
154
+ }
155
+ function shouldResetNonce(error3) {
156
+ const nonceError = findCause(error3, ({ name }) => name === "NonceTooLowError" || name === "NonceTooHighError");
157
+ return nonceError != null;
158
+ }
159
+ const mempoolQueue = new import_p_queue.default({ concurrency: queueConcurrency });
160
+ return {
161
+ hasNonce,
162
+ getNonce,
163
+ nextNonce,
164
+ resetNonce,
165
+ shouldResetNonce,
166
+ mempoolQueue
167
+ };
168
+ }
169
+
170
+ // src/getNonceManager.ts
171
+ var nonceManagers = /* @__PURE__ */ new Map();
172
+ async function getNonceManager({
173
+ client,
174
+ address,
175
+ // TODO: rename to account?
176
+ blockTag = "latest",
177
+ ...opts
178
+ }) {
179
+ const id = await getNonceManagerId({ client, address, blockTag });
180
+ const nonceManager = nonceManagers.get(id) ?? createNonceManager({ client, address, blockTag, ...opts });
181
+ if (!nonceManagers.has(id)) {
182
+ nonceManagers.set(id, nonceManager);
183
+ }
184
+ if (!nonceManager.hasNonce()) {
185
+ await nonceManager.resetNonce();
186
+ }
187
+ return nonceManager;
188
+ }
189
+
190
+ // src/sendTransaction.ts
191
+ var import_accounts = require("viem/accounts");
192
+
193
+ // src/getFeeRef.ts
194
+ var import_actions5 = require("viem/actions");
195
+
196
+ // src/createFeeRef.ts
197
+ var import_actions4 = require("viem/actions");
198
+ var import_utils3 = require("viem/utils");
199
+ async function createFeeRef({ client, args, refreshInterval }) {
200
+ const feeRef = { fees: {}, lastUpdatedTimestamp: 0 };
201
+ async function updateFees() {
202
+ const fees = await (0, import_utils3.getAction)(client, import_actions4.estimateFeesPerGas, "estimateFeesPerGas")(args);
203
+ feeRef.fees = fees;
204
+ feeRef.lastUpdatedTimestamp = Date.now();
205
+ }
206
+ setInterval(updateFees, refreshInterval);
207
+ await updateFees();
208
+ return feeRef;
209
+ }
210
+
211
+ // src/getFeeRef.ts
212
+ var import_utils4 = require("viem/utils");
213
+ var feeRefs = /* @__PURE__ */ new Map();
214
+ async function getFeeRef(opts) {
215
+ const chainId = opts.args?.chain?.id ?? opts.client.chain?.id ?? await (0, import_utils4.getAction)(opts.client, import_actions5.getChainId, "getChainId")({});
216
+ const existingFeeRef = feeRefs.get(chainId);
217
+ if (existingFeeRef) {
218
+ return existingFeeRef;
219
+ }
220
+ const feeRef = await createFeeRef(opts);
221
+ feeRefs.set(chainId, feeRef);
222
+ return feeRef;
223
+ }
224
+
225
+ // src/sendTransaction.ts
226
+ var import_utils5 = require("viem/utils");
227
+ var debug4 = debug.extend("sendTransaction");
228
+ async function sendTransaction(client, request, opts = {}) {
229
+ const rawAccount = request.account ?? client.account;
230
+ if (!rawAccount) {
231
+ throw new Error("No account provided");
232
+ }
233
+ const account = (0, import_accounts.parseAccount)(rawAccount);
234
+ const chain = client.chain;
235
+ const nonceManager = await getNonceManager({
236
+ client: opts.publicClient ?? client,
237
+ address: account.address,
238
+ queueConcurrency: opts.queueConcurrency
239
+ });
240
+ const feeRef = await getFeeRef({
241
+ client: opts.publicClient ?? client,
242
+ refreshInterval: 1e4,
243
+ args: { chain }
244
+ });
245
+ return await nonceManager.mempoolQueue.add(
246
+ () => (0, import_p_retry.default)(
247
+ async () => {
248
+ const nonce = nonceManager.nextNonce();
249
+ const params = {
250
+ // viem_sendTransaction internally estimates gas, which we want to happen on the pending block
251
+ blockTag: "pending",
252
+ ...feeRef.fees,
253
+ ...request,
254
+ nonce
255
+ };
256
+ debug4("sending tx to", request.to, "with nonce", nonce);
257
+ return await (0, import_utils5.getAction)(client, import_actions6.sendTransaction, "sendTransaction")(params);
258
+ },
259
+ {
260
+ retries: 3,
261
+ onFailedAttempt: async (error3) => {
262
+ debug4("failed, resetting nonce");
263
+ await nonceManager.resetNonce();
264
+ if (nonceManager.shouldResetNonce(error3)) {
265
+ debug4("got nonce error, retrying", error3.message);
266
+ return;
267
+ }
268
+ if (String(error3).includes("transaction underpriced")) {
269
+ debug4("got transaction underpriced error, retrying", error3.message);
270
+ return;
271
+ }
272
+ throw error3;
273
+ }
274
+ }
275
+ ),
276
+ { throwOnTimeout: true }
277
+ );
278
+ }
279
+
280
+ // src/deploy/ensureContract.ts
281
+ async function ensureContract({
282
+ client,
283
+ deployerAddress,
284
+ bytecode,
285
+ deployedBytecodeSize,
286
+ debugLabel = "contract",
287
+ salt = singletonSalt
288
+ }) {
289
+ if (bytecode.includes("__$")) {
290
+ throw new Error(`Found unlinked public library in ${debugLabel} bytecode`);
291
+ }
292
+ const address = (0, import_viem3.getCreate2Address)({ from: deployerAddress, salt, bytecode });
293
+ const contractCode = await (0, import_actions7.getCode)(client, { address, blockTag: "pending" });
294
+ if (contractCode) {
295
+ debug2("found", debugLabel, "at", address);
296
+ return [];
297
+ }
298
+ if (deployedBytecodeSize != null) {
299
+ if (deployedBytecodeSize > contractSizeLimit) {
300
+ console.warn(
301
+ `
302
+ Bytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.
303
+ `
304
+ );
305
+ } else if (deployedBytecodeSize > contractSizeLimit * 0.95) {
306
+ console.warn(
307
+ // eslint-disable-next-line max-len
308
+ `
309
+ Bytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is almost over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.
310
+ `
311
+ );
312
+ }
313
+ }
314
+ debug2("deploying", debugLabel, "at", address);
315
+ return [
316
+ await sendTransaction(client, {
317
+ chain: client.chain ?? null,
318
+ to: deployerAddress,
319
+ data: (0, import_viem3.concatHex)([salt, bytecode])
320
+ })
321
+ ];
322
+ }
323
+
324
+ // src/utils/uniqueBy.ts
325
+ function uniqueBy(values, getKey) {
326
+ const map = /* @__PURE__ */ new Map();
327
+ for (const value of values) {
328
+ const key = getKey(value);
329
+ if (!map.has(key)) {
330
+ map.set(key, value);
331
+ }
332
+ }
333
+ return Array.from(map.values());
334
+ }
335
+
336
+ // src/deploy/ensureContractsDeployed.ts
337
+ async function ensureContractsDeployed({
338
+ client,
339
+ deployerAddress,
340
+ contracts
341
+ }) {
342
+ const uniqueContracts = uniqueBy(contracts, (contract) => contract.bytecode);
343
+ const txs = (await Promise.all(uniqueContracts.map((contract) => ensureContract({ client, deployerAddress, ...contract })))).flat();
344
+ await waitForTransactions({
345
+ client,
346
+ hashes: txs,
347
+ debugLabel: "contract deploys"
348
+ });
349
+ return txs;
350
+ }
351
+
352
+ // src/deploy/ensureDeployer.ts
353
+ var import_actions9 = require("viem/actions");
354
+
355
+ // src/deploy/create2/deployment.json
356
+ var deployment_default = {
357
+ gasPrice: 1e11,
358
+ gasLimit: 1e5,
359
+ signerAddress: "3fab184622dc19b6109349b94811493bf2a45362",
360
+ transaction: "f8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222",
361
+ address: "4e59b44847b379578588920ca78fbf26c0b4956c",
362
+ creationCode: "604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3"
363
+ };
364
+
365
+ // src/deploy/getDeployer.ts
366
+ var import_viem4 = require("viem");
367
+ var import_actions8 = require("viem/actions");
368
+ var deployer = `0x${deployment_default.address}`;
369
+ async function getDeployer(client) {
370
+ const bytecode = await (0, import_actions8.getCode)(client, { address: deployer });
371
+ if (bytecode) {
372
+ debug2("found deployer bytecode at", deployer);
373
+ if (bytecode !== (0, import_viem4.sliceHex)(`0x${deployment_default.creationCode}`, 14)) {
374
+ console.warn(
375
+ `
376
+ \u26A0\uFE0F Bytecode for deployer at ${deployer} did not match the expected CREATE2 bytecode. You may have unexpected results.
377
+ `
378
+ );
379
+ }
380
+ return deployer;
381
+ }
382
+ }
383
+
384
+ // src/deploy/ensureDeployer.ts
385
+ var deployer2 = `0x${deployment_default.address}`;
386
+ async function ensureDeployer(client) {
387
+ const existingDeployer = await getDeployer(client);
388
+ if (existingDeployer !== void 0) {
389
+ return existingDeployer;
390
+ }
391
+ const gasRequired = BigInt(deployment_default.gasLimit) * BigInt(deployment_default.gasPrice);
392
+ const currentBalance = await (0, import_actions9.getBalance)(client, { address: `0x${deployment_default.signerAddress}` });
393
+ const gasNeeded = gasRequired - currentBalance;
394
+ if (gasNeeded > 0) {
395
+ debug2("sending gas for CREATE2 deployer to signer at", deployment_default.signerAddress);
396
+ const gasTx = await (0, import_actions9.sendTransaction)(client, {
397
+ chain: client.chain ?? null,
398
+ to: `0x${deployment_default.signerAddress}`,
399
+ value: gasNeeded
400
+ });
401
+ const gasReceipt = await (0, import_actions9.waitForTransactionReceipt)(client, { hash: gasTx });
402
+ if (gasReceipt.status !== "success") {
403
+ console.error("failed to send gas to deployer signer", gasReceipt);
404
+ throw new Error("failed to send gas to deployer signer");
405
+ }
406
+ }
407
+ debug2("deploying CREATE2 deployer at", deployer2);
408
+ const deployTx = await (0, import_actions9.sendRawTransaction)(client, { serializedTransaction: `0x${deployment_default.transaction}` }).catch(
409
+ (error3) => {
410
+ if (String(error3).includes("only replay-protected (EIP-155) transactions allowed over RPC")) {
411
+ console.warn(
412
+ // eslint-disable-next-line max-len
413
+ `
414
+ \u26A0\uFE0F Your chain or RPC does not allow for non EIP-155 signed transactions, so your deploys will not be determinstic and contract addresses may change between deploys.
415
+
416
+ We recommend running your chain's node with \`--rpc.allow-unprotected-txs\` to enable determinstic deployments.
417
+ `
418
+ );
419
+ debug2("deploying CREATE2 deployer");
420
+ return (0, import_actions9.sendTransaction)(client, {
421
+ chain: client.chain ?? null,
422
+ data: `0x${deployment_default.creationCode}`
423
+ });
424
+ }
425
+ throw error3;
426
+ }
427
+ );
428
+ const deployReceipt = await (0, import_actions9.waitForTransactionReceipt)(client, { hash: deployTx });
429
+ if (!deployReceipt.contractAddress) {
430
+ throw new Error("Deploy receipt did not have contract address, was the deployer not deployed?");
431
+ }
432
+ if (deployReceipt.contractAddress !== deployer2) {
433
+ console.warn(
434
+ `
435
+ \u26A0\uFE0F CREATE2 deployer created at ${deployReceipt.contractAddress} does not match the CREATE2 determinstic deployer we expected (${deployer2})`
436
+ );
437
+ }
438
+ return deployReceipt.contractAddress;
439
+ }
440
+
441
+ // src/deploy/getContractAddress.ts
442
+ var import_viem5 = require("viem");
443
+ function getContractAddress({
444
+ deployerAddress,
445
+ bytecode,
446
+ salt = singletonSalt
447
+ }) {
448
+ return (0, import_viem5.getCreate2Address)({ from: deployerAddress, bytecode, salt });
449
+ }
450
+ // Annotate the CommonJS export names for ESM import in node:
451
+ 0 && (module.exports = {
452
+ ensureContract,
453
+ ensureContractsDeployed,
454
+ ensureDeployer,
455
+ getContractAddress,
456
+ getDeployer,
457
+ waitForTransactions
458
+ });
459
+ //# sourceMappingURL=internal.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/exports/internal.ts","../src/debug.ts","../src/waitForTransactions.ts","../src/deploy/ensureContract.ts","../src/deploy/common.ts","../src/deploy/debug.ts","../src/sendTransaction.ts","../src/getNonceManagerId.ts","../src/createNonceManager.ts","../src/findCause.ts","../src/getNonceManager.ts","../src/getFeeRef.ts","../src/createFeeRef.ts","../src/utils/uniqueBy.ts","../src/deploy/ensureContractsDeployed.ts","../src/deploy/ensureDeployer.ts","../src/deploy/create2/deployment.json","../src/deploy/getDeployer.ts","../src/deploy/getContractAddress.ts"],"sourcesContent":["export * from \"../waitForTransactions\";\nexport * from \"../deploy/ensureContract\";\nexport * from \"../deploy/ensureContractsDeployed\";\nexport * from \"../deploy/ensureDeployer\";\nexport * from \"../deploy/getContractAddress\";\nexport * from \"../deploy/getDeployer\";\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:common\");\nexport const error = createDebug(\"mud:common\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","import { Client, Transport, Chain, Account, Hex } from \"viem\";\nimport { debug } from \"./debug\";\nimport { waitForTransactionReceipt } from \"viem/actions\";\n\nexport async function waitForTransactions({\n client,\n hashes,\n debugLabel = \"transactions\",\n}: {\n readonly client: Client<Transport, Chain | undefined, Account>;\n readonly hashes: readonly Hex[];\n readonly debugLabel?: string;\n}): Promise<void> {\n if (!hashes.length) return;\n\n debug(`waiting for ${debugLabel} to confirm`);\n // wait for each tx separately/serially, because parallelizing results in RPC errors\n for (const hash of hashes) {\n const receipt = await waitForTransactionReceipt(client, { hash });\n // TODO: handle user op failures?\n if (receipt.status === \"reverted\") {\n throw new Error(`Transaction reverted: ${hash}`);\n }\n }\n}\n","import { Client, Transport, Chain, Account, concatHex, getCreate2Address, Hex } from \"viem\";\nimport { getCode } from \"viem/actions\";\nimport { contractSizeLimit, singletonSalt } from \"./common\";\nimport { debug } from \"./debug\";\nimport { sendTransaction } from \"../sendTransaction\";\n\nexport type Contract = {\n bytecode: Hex;\n deployedBytecodeSize?: number;\n debugLabel?: string;\n salt?: Hex;\n};\n\nexport async function ensureContract({\n client,\n deployerAddress,\n bytecode,\n deployedBytecodeSize,\n debugLabel = \"contract\",\n salt = singletonSalt,\n}: {\n readonly client: Client<Transport, Chain | undefined, Account>;\n readonly deployerAddress: Hex;\n} & Contract): Promise<readonly Hex[]> {\n if (bytecode.includes(\"__$\")) {\n throw new Error(`Found unlinked public library in ${debugLabel} bytecode`);\n }\n\n const address = getCreate2Address({ from: deployerAddress, salt, bytecode });\n\n const contractCode = await getCode(client, { address, blockTag: \"pending\" });\n if (contractCode) {\n debug(\"found\", debugLabel, \"at\", address);\n return [];\n }\n\n if (deployedBytecodeSize != null) {\n if (deployedBytecodeSize > contractSizeLimit) {\n console.warn(\n `\\nBytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is over the contract size limit (${contractSizeLimit} bytes). Run \\`forge build --sizes\\` for more info.\\n`,\n );\n } else if (deployedBytecodeSize > contractSizeLimit * 0.95) {\n console.warn(\n // eslint-disable-next-line max-len\n `\\nBytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is almost over the contract size limit (${contractSizeLimit} bytes). Run \\`forge build --sizes\\` for more info.\\n`,\n );\n }\n }\n\n debug(\"deploying\", debugLabel, \"at\", address);\n return [\n await sendTransaction(client, {\n chain: client.chain ?? null,\n to: deployerAddress,\n data: concatHex([salt, bytecode]),\n }),\n ];\n}\n","import { stringToHex } from \"viem\";\n\n// salt for deterministic deploys of singleton contracts\nexport const singletonSalt = stringToHex(\"\", { size: 32 });\n\n// https://eips.ethereum.org/EIPS/eip-170\nexport const contractSizeLimit = parseInt(\"6000\", 16);\n","import { debug as parentDebug } from \"../debug\";\n\nexport const debug = parentDebug.extend(\"deploy\");\nexport const error = parentDebug.extend(\"deploy\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","import {\n Account,\n Chain,\n Client,\n SendTransactionParameters,\n Transport,\n SendTransactionReturnType,\n SendTransactionRequest,\n} from \"viem\";\nimport { sendTransaction as viem_sendTransaction } from \"viem/actions\";\nimport pRetry from \"p-retry\";\nimport { debug as parentDebug } from \"./debug\";\nimport { getNonceManager } from \"./getNonceManager\";\nimport { parseAccount } from \"viem/accounts\";\nimport { getFeeRef } from \"./getFeeRef\";\nimport { getAction } from \"viem/utils\";\n\nconst debug = parentDebug.extend(\"sendTransaction\");\n\nexport type SendTransactionExtraOptions<chain extends Chain | undefined> = {\n /**\n * `publicClient` can be provided to be used in place of the extended viem client for making public action calls\n * (`getChainId`, `getTransactionCount`, `call`). This helps in cases where the extended\n * viem client is a smart account client, like in [permissionless.js](https://github.com/pimlicolabs/permissionless.js),\n * where the transport is the bundler, not an RPC.\n */\n publicClient?: Client<Transport, chain>;\n /**\n * Adjust the number of concurrent calls to the mempool. This defaults to `1` to ensure transactions are ordered\n * and nonces are handled properly. Any number greater than that is likely to see nonce errors and/or transactions\n * arriving out of order, but this may be an acceptable trade-off for some applications that can safely retry.\n * @default 1\n */\n queueConcurrency?: number;\n};\n\n/** @deprecated Use `walletClient.extend(transactionQueue())` instead. */\nexport async function sendTransaction<\n chain extends Chain | undefined,\n account extends Account | undefined,\n const request extends SendTransactionRequest<chain, chainOverride>,\n chainOverride extends Chain | undefined = undefined,\n>(\n client: Client<Transport, chain, account>,\n request: SendTransactionParameters<chain, account, chainOverride, request>,\n opts: SendTransactionExtraOptions<chain> = {},\n): Promise<SendTransactionReturnType> {\n const rawAccount = request.account ?? client.account;\n if (!rawAccount) {\n // TODO: replace with viem AccountNotFoundError once its exported\n throw new Error(\"No account provided\");\n }\n const account = parseAccount(rawAccount);\n const chain = client.chain;\n\n const nonceManager = await getNonceManager({\n client: opts.publicClient ?? client,\n address: account.address,\n queueConcurrency: opts.queueConcurrency,\n });\n\n const feeRef = await getFeeRef({\n client: opts.publicClient ?? client,\n refreshInterval: 10000,\n args: { chain },\n });\n\n return await nonceManager.mempoolQueue.add(\n () =>\n pRetry(\n async () => {\n const nonce = nonceManager.nextNonce();\n const params = {\n // viem_sendTransaction internally estimates gas, which we want to happen on the pending block\n blockTag: \"pending\",\n ...feeRef.fees,\n ...request,\n nonce,\n } as const satisfies SendTransactionParameters<chain, account, chainOverride, request>;\n debug(\"sending tx to\", request.to, \"with nonce\", nonce);\n return await getAction(client, viem_sendTransaction, \"sendTransaction\")(params as never);\n },\n {\n retries: 3,\n onFailedAttempt: async (error) => {\n // in case this tx failed before hitting the mempool (i.e. gas estimation error), reset nonce so we don't skip past the unused nonce\n debug(\"failed, resetting nonce\");\n await nonceManager.resetNonce();\n // retry nonce errors\n // TODO: upgrade p-retry and move this to shouldRetry\n if (nonceManager.shouldResetNonce(error)) {\n debug(\"got nonce error, retrying\", error.message);\n return;\n }\n\n if (String(error).includes(\"transaction underpriced\")) {\n debug(\"got transaction underpriced error, retrying\", error.message);\n return;\n }\n\n throw error;\n },\n },\n ),\n { throwOnTimeout: true },\n );\n}\n","import { BlockTag, Client, Hex, getAddress } from \"viem\";\nimport { getChainId } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\n\nexport async function getNonceManagerId({\n client,\n address,\n blockTag,\n}: {\n client: Client;\n address: Hex;\n blockTag: BlockTag;\n}): Promise<string> {\n // TODO: improve this so we don't have to call getChainId every time\n const chainId = client.chain?.id ?? (await getAction(client, getChainId, \"getChainId\")({}));\n return `mud:createNonceManager:${chainId}:${getAddress(address)}:${blockTag}`;\n}\n","import { BlockTag, Client, Hex } from \"viem\";\nimport { debug as parentDebug } from \"./debug\";\nimport { getNonceManagerId } from \"./getNonceManagerId\";\nimport { getTransactionCount } from \"viem/actions\";\nimport PQueue from \"p-queue\";\nimport { getAction } from \"viem/utils\";\nimport { findCause } from \"./findCause\";\n\nconst debug = parentDebug.extend(\"createNonceManager\");\n\nexport type CreateNonceManagerOptions = {\n client: Client;\n address: Hex;\n blockTag?: BlockTag;\n broadcastChannelName?: string;\n queueConcurrency?: number;\n};\n\nexport type CreateNonceManagerResult = {\n hasNonce: () => boolean;\n getNonce: () => number;\n nextNonce: () => number;\n resetNonce: () => Promise<void>;\n shouldResetNonce: (error: Error) => boolean;\n mempoolQueue: PQueue;\n};\n\nexport function createNonceManager({\n client,\n address, // TODO: rename to account?\n blockTag = \"latest\",\n broadcastChannelName,\n queueConcurrency = 1,\n}: CreateNonceManagerOptions): CreateNonceManagerResult {\n const ref = { nonce: -1, noncePromise: null as Promise<void> | null };\n let channel: BroadcastChannel | null = null;\n\n if (typeof BroadcastChannel !== \"undefined\") {\n const channelName = broadcastChannelName\n ? Promise.resolve(broadcastChannelName)\n : getNonceManagerId({ client, address, blockTag });\n channelName.then((name) => {\n channel = new BroadcastChannel(name);\n // TODO: emit some sort of \"connected\" event so other channels can broadcast current nonce\n channel.addEventListener(\"message\", (event) => {\n const nonce = JSON.parse(event.data);\n debug(\"got nonce from broadcast channel\", nonce);\n ref.nonce = nonce;\n });\n });\n }\n\n function hasNonce(): boolean {\n return ref.nonce >= 0;\n }\n\n function getNonce(): number {\n if (!hasNonce()) throw new Error(\"call resetNonce before using getNonce\");\n return ref.nonce;\n }\n\n function nextNonce(): number {\n if (!hasNonce()) throw new Error(\"call resetNonce before using nextNonce\");\n const nonce = ref.nonce++;\n channel?.postMessage(JSON.stringify(ref.nonce));\n return nonce;\n }\n\n async function resetNonce(): Promise<void> {\n ref.noncePromise ??= (async (): Promise<void> => {\n ref.nonce = await getAction(client, getTransactionCount, \"getTransactionCount\")({ address, blockTag });\n ref.noncePromise = null;\n channel?.postMessage(JSON.stringify(ref.nonce));\n debug(\"reset nonce to\", ref.nonce);\n })();\n await ref.noncePromise;\n }\n\n function shouldResetNonce(error: Error): boolean {\n const nonceError = findCause(error, ({ name }) => name === \"NonceTooLowError\" || name === \"NonceTooHighError\");\n return nonceError != null;\n }\n\n const mempoolQueue = new PQueue({ concurrency: queueConcurrency });\n\n return {\n hasNonce,\n getNonce,\n nextNonce,\n resetNonce,\n shouldResetNonce,\n mempoolQueue,\n };\n}\n","export function findCause(error: Error, fn?: (error: Error) => boolean): Error | null {\n if (fn?.(error)) return error;\n if (error.cause instanceof Error) return findCause(error.cause, fn);\n return fn ? null : error;\n}\n","import { CreateNonceManagerOptions, CreateNonceManagerResult, createNonceManager } from \"./createNonceManager\";\nimport { getNonceManagerId } from \"./getNonceManagerId\";\n\nconst nonceManagers = new Map<string, CreateNonceManagerResult>();\n\nexport async function getNonceManager({\n client,\n address, // TODO: rename to account?\n blockTag = \"latest\",\n ...opts\n}: CreateNonceManagerOptions): Promise<CreateNonceManagerResult> {\n const id = await getNonceManagerId({ client, address, blockTag });\n\n const nonceManager = nonceManagers.get(id) ?? createNonceManager({ client, address, blockTag, ...opts });\n if (!nonceManagers.has(id)) {\n nonceManagers.set(id, nonceManager);\n }\n\n if (!nonceManager.hasNonce()) {\n await nonceManager.resetNonce();\n }\n\n return nonceManager;\n}\n","import { getChainId } from \"viem/actions\";\nimport { CreateFeeRefOptions, FeeRef, createFeeRef } from \"./createFeeRef\";\nimport { getAction } from \"viem/utils\";\n\nconst feeRefs = new Map<number, FeeRef>();\n\nexport async function getFeeRef(opts: CreateFeeRefOptions): Promise<FeeRef> {\n const chainId =\n opts.args?.chain?.id ?? opts.client.chain?.id ?? (await getAction(opts.client, getChainId, \"getChainId\")({}));\n\n const existingFeeRef = feeRefs.get(chainId);\n if (existingFeeRef) {\n return existingFeeRef;\n }\n\n const feeRef = await createFeeRef(opts);\n feeRefs.set(chainId, feeRef);\n return feeRef;\n}\n","import { EstimateFeesPerGasParameters, Client, EstimateFeesPerGasReturnType } from \"viem\";\nimport { estimateFeesPerGas } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\n\nexport type CreateFeeRefOptions = {\n client: Client;\n refreshInterval: number;\n args?: EstimateFeesPerGasParameters;\n};\n\nexport type FeeRef = {\n fees: EstimateFeesPerGasReturnType | {};\n lastUpdatedTimestamp: number;\n};\n\n/** Update fee values once every `refreshInterval` instead of right before every request */\nexport async function createFeeRef({ client, args, refreshInterval }: CreateFeeRefOptions): Promise<FeeRef> {\n const feeRef: FeeRef = { fees: {}, lastUpdatedTimestamp: 0 };\n\n async function updateFees(): Promise<void> {\n const fees = await getAction(client, estimateFeesPerGas, \"estimateFeesPerGas\")(args);\n feeRef.fees = fees;\n feeRef.lastUpdatedTimestamp = Date.now();\n }\n\n setInterval(updateFees, refreshInterval);\n await updateFees();\n\n return feeRef;\n}\n","export function uniqueBy<value, key>(values: readonly value[], getKey: (value: value) => key): readonly value[] {\n const map = new Map<key, value>();\n for (const value of values) {\n const key = getKey(value);\n if (!map.has(key)) {\n map.set(key, value);\n }\n }\n return Array.from(map.values());\n}\n","import { Client, Transport, Chain, Account, Hex } from \"viem\";\nimport { Contract, ensureContract } from \"./ensureContract\";\nimport { waitForTransactions } from \"../waitForTransactions\";\nimport { uniqueBy } from \"../utils/uniqueBy\";\n\nexport async function ensureContractsDeployed({\n client,\n deployerAddress,\n contracts,\n}: {\n readonly client: Client<Transport, Chain | undefined, Account>;\n readonly deployerAddress: Hex;\n readonly contracts: readonly Contract[];\n}): Promise<readonly Hex[]> {\n // Deployments assume a deterministic deployer, so we only need to deploy the unique bytecode\n const uniqueContracts = uniqueBy(contracts, (contract) => contract.bytecode);\n\n const txs = (\n await Promise.all(uniqueContracts.map((contract) => ensureContract({ client, deployerAddress, ...contract })))\n ).flat();\n\n await waitForTransactions({\n client,\n hashes: txs,\n debugLabel: \"contract deploys\",\n });\n\n return txs;\n}\n","import { Account, Address, Chain, Client, Transport } from \"viem\";\nimport { getBalance, sendRawTransaction, sendTransaction, waitForTransactionReceipt } from \"viem/actions\";\nimport deployment from \"./create2/deployment.json\";\nimport { debug } from \"./debug\";\nimport { getDeployer } from \"./getDeployer\";\n\nconst deployer = `0x${deployment.address}` as const;\n\nexport async function ensureDeployer(client: Client<Transport, Chain | undefined, Account>): Promise<Address> {\n const existingDeployer = await getDeployer(client);\n if (existingDeployer !== undefined) {\n return existingDeployer;\n }\n\n // There's not really a way to simulate a pre-EIP-155 (no chain ID) transaction,\n // so we have to attempt to create the deployer first and, if it fails, fall back\n // to a regular deploy.\n\n // Send gas to deployment signer\n const gasRequired = BigInt(deployment.gasLimit) * BigInt(deployment.gasPrice);\n const currentBalance = await getBalance(client, { address: `0x${deployment.signerAddress}` });\n const gasNeeded = gasRequired - currentBalance;\n if (gasNeeded > 0) {\n debug(\"sending gas for CREATE2 deployer to signer at\", deployment.signerAddress);\n const gasTx = await sendTransaction(client, {\n chain: client.chain ?? null,\n to: `0x${deployment.signerAddress}`,\n value: gasNeeded,\n });\n const gasReceipt = await waitForTransactionReceipt(client, { hash: gasTx });\n if (gasReceipt.status !== \"success\") {\n console.error(\"failed to send gas to deployer signer\", gasReceipt);\n throw new Error(\"failed to send gas to deployer signer\");\n }\n }\n\n // Deploy the deployer\n debug(\"deploying CREATE2 deployer at\", deployer);\n const deployTx = await sendRawTransaction(client, { serializedTransaction: `0x${deployment.transaction}` }).catch(\n (error) => {\n // Do a regular contract create if the presigned transaction doesn't work due to replay protection\n if (String(error).includes(\"only replay-protected (EIP-155) transactions allowed over RPC\")) {\n console.warn(\n // eslint-disable-next-line max-len\n `\\n ⚠️ Your chain or RPC does not allow for non EIP-155 signed transactions, so your deploys will not be determinstic and contract addresses may change between deploys.\\n\\n We recommend running your chain's node with \\`--rpc.allow-unprotected-txs\\` to enable determinstic deployments.\\n`,\n );\n debug(\"deploying CREATE2 deployer\");\n return sendTransaction(client, {\n chain: client.chain ?? null,\n data: `0x${deployment.creationCode}`,\n });\n }\n throw error;\n },\n );\n\n const deployReceipt = await waitForTransactionReceipt(client, { hash: deployTx });\n if (!deployReceipt.contractAddress) {\n throw new Error(\"Deploy receipt did not have contract address, was the deployer not deployed?\");\n }\n\n if (deployReceipt.contractAddress !== deployer) {\n console.warn(\n `\\n ⚠️ CREATE2 deployer created at ${deployReceipt.contractAddress} does not match the CREATE2 determinstic deployer we expected (${deployer})`,\n );\n }\n\n return deployReceipt.contractAddress;\n}\n","{\n \"gasPrice\": 100000000000,\n \"gasLimit\": 100000,\n \"signerAddress\": \"3fab184622dc19b6109349b94811493bf2a45362\",\n \"transaction\": \"f8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222\",\n \"address\": \"4e59b44847b379578588920ca78fbf26c0b4956c\",\n \"creationCode\": \"604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3\"\n}\n","import { Address, Chain, Client, Transport, sliceHex } from \"viem\";\nimport { getCode } from \"viem/actions\";\nimport deployment from \"./create2/deployment.json\";\nimport { debug } from \"./debug\";\n\nconst deployer = `0x${deployment.address}` as const;\n\nexport async function getDeployer(client: Client<Transport, Chain | undefined>): Promise<Address | undefined> {\n const bytecode = await getCode(client, { address: deployer });\n if (bytecode) {\n debug(\"found deployer bytecode at\", deployer);\n // check if deployed bytecode is the same as the expected bytecode (minus 14-bytes creation code prefix)\n if (bytecode !== sliceHex(`0x${deployment.creationCode}`, 14)) {\n console.warn(\n `\\n ⚠️ Bytecode for deployer at ${deployer} did not match the expected CREATE2 bytecode. You may have unexpected results.\\n`,\n );\n }\n return deployer;\n }\n}\n","import { Hex, getCreate2Address } from \"viem\";\nimport { singletonSalt } from \"./common\";\n\nexport function getContractAddress({\n deployerAddress,\n bytecode,\n salt = singletonSalt,\n}: {\n readonly deployerAddress: Hex;\n readonly bytecode: Hex;\n readonly salt?: Hex;\n}): Hex {\n return getCreate2Address({ from: deployerAddress, bytecode, salt });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAwB;AAEjB,IAAM,YAAQ,aAAAA,SAAY,YAA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AA,QACF;AACA,QAAAD,OAAM,4BAA4B;AAClC,mBAAO,iCAAgB,QAAQ;AAAA,UAC7B,OAAO,OAAO,SAAS;AAAA,UACvB,MAAM,KAAK,mBAAW,YAAY;AAAA,QACpC,CAAC;AAAA,MACH;AACA,YAAMC;AAAA,IACR;AAAA,EACF;AAEA,QAAM,gBAAgB,UAAM,2CAA0B,QAAQ,EAAE,MAAM,SAAS,CAAC;AAChF,MAAI,CAAC,cAAc,iBAAiB;AAClC,UAAM,IAAI,MAAM,8EAA8E;AAAA,EAChG;AAEA,MAAI,cAAc,oBAAoBF,WAAU;AAC9C,YAAQ;AAAA,MACN;AAAA,6CAAsC,cAAc,eAAe,kEAAkEA,SAAQ;AAAA,IAC/I;AAAA,EACF;AAEA,SAAO,cAAc;AACvB;;;AGpEA,IAAAG,eAAuC;AAGhC,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA,OAAO;AACT,GAIQ;AACN,aAAO,gCAAkB,EAAE,MAAM,iBAAiB,UAAU,KAAK,CAAC;AACpE;","names":["createDebug","import_viem","import_actions","debug","error","import_actions","import_viem","import_actions","import_actions","import_utils","error","debug","error","PQueue","import_actions","import_actions","import_utils","import_utils","import_utils","debug","pRetry","viem_sendTransaction","error","debug","import_actions","import_viem","import_actions","debug","deployer","debug","error","import_viem"]}
@@ -0,0 +1,36 @@
1
+ import { Client, Transport, Chain, Account, Hex, Address } from 'viem';
2
+
3
+ declare function waitForTransactions({ client, hashes, debugLabel, }: {
4
+ readonly client: Client<Transport, Chain | undefined, Account>;
5
+ readonly hashes: readonly Hex[];
6
+ readonly debugLabel?: string;
7
+ }): Promise<void>;
8
+
9
+ type Contract = {
10
+ bytecode: Hex;
11
+ deployedBytecodeSize?: number;
12
+ debugLabel?: string;
13
+ salt?: Hex;
14
+ };
15
+ declare function ensureContract({ client, deployerAddress, bytecode, deployedBytecodeSize, debugLabel, salt, }: {
16
+ readonly client: Client<Transport, Chain | undefined, Account>;
17
+ readonly deployerAddress: Hex;
18
+ } & Contract): Promise<readonly Hex[]>;
19
+
20
+ declare function ensureContractsDeployed({ client, deployerAddress, contracts, }: {
21
+ readonly client: Client<Transport, Chain | undefined, Account>;
22
+ readonly deployerAddress: Hex;
23
+ readonly contracts: readonly Contract[];
24
+ }): Promise<readonly Hex[]>;
25
+
26
+ declare function ensureDeployer(client: Client<Transport, Chain | undefined, Account>): Promise<Address>;
27
+
28
+ declare function getContractAddress({ deployerAddress, bytecode, salt, }: {
29
+ readonly deployerAddress: Hex;
30
+ readonly bytecode: Hex;
31
+ readonly salt?: Hex;
32
+ }): Hex;
33
+
34
+ declare function getDeployer(client: Client<Transport, Chain | undefined>): Promise<Address | undefined>;
35
+
36
+ export { type Contract, ensureContract, ensureContractsDeployed, ensureDeployer, getContractAddress, getDeployer, waitForTransactions };