@latticexyz/common 2.2.12-pending-logs-72bb2264a91a3266f5f15bbd754d32a1e2a62ccb → 2.2.12
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/dist/actions.js +1 -1
- package/dist/chains.d.ts +311 -65
- package/dist/chains.js +1 -1
- package/dist/chains.js.map +1 -1
- package/dist/{chunk-3XILP7OL.js → chunk-24YWZ2XF.js} +2 -2
- package/dist/{chunk-3XILP7OL.js.map → chunk-24YWZ2XF.js.map} +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/actions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{d as o,e as a}from"./chunk-
|
|
1
|
+
import{d as o,e as a}from"./chunk-24YWZ2XF.js";import"./chunk-TCWGPC6G.js";function m(n={}){return r=>({writeContract:t=>o(r,t,n),sendTransaction:t=>a(r,t,n)})}import{getAction as s}from"viem/utils";import{writeContract as u}from"viem/actions";function h({onWrite:n}){let r=0;return t=>({writeContract:e=>{let i=s(t,u,"writeContract")(e),c=`${t.chain.id}:${t.account.address}:${r++}`;return n({id:c,request:e,result:i}),i}})}export{m as transactionQueue,h as writeObserver};
|
|
2
2
|
//# sourceMappingURL=actions.js.map
|
package/dist/chains.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as viem_chains from 'viem/chains';
|
|
|
2
2
|
import { Chain } from 'viem/chains';
|
|
3
3
|
import * as viem from 'viem';
|
|
4
4
|
import * as viem_experimental from 'viem/experimental';
|
|
5
|
+
import * as viem_op_stack from 'viem/op-stack';
|
|
5
6
|
|
|
6
7
|
type MUDChain = Chain & {
|
|
7
8
|
iconUrls?: readonly string[];
|
|
@@ -54,10 +55,58 @@ declare const mudFoundry: {
|
|
|
54
55
|
readonly serializers?: viem.ChainSerializers<undefined, viem.TransactionSerializable<bigint, number>> | undefined;
|
|
55
56
|
};
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
readonly
|
|
60
|
-
readonly
|
|
58
|
+
declare const redstone: {
|
|
59
|
+
readonly iconUrls: readonly ["https://redstone.xyz/chain-icons/redstone.png"];
|
|
60
|
+
readonly indexerUrl: "https://indexer.mud.redstonechain.com";
|
|
61
|
+
readonly blockExplorers: {
|
|
62
|
+
readonly default: {
|
|
63
|
+
readonly name: "Blockscout";
|
|
64
|
+
readonly url: "https://explorer.redstone.xyz";
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
readonly contracts: {
|
|
68
|
+
readonly multicall3: {
|
|
69
|
+
readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
|
|
70
|
+
};
|
|
71
|
+
readonly portal: {
|
|
72
|
+
readonly 1: {
|
|
73
|
+
readonly address: "0xC7bCb0e8839a28A1cFadd1CF716de9016CdA51ae";
|
|
74
|
+
readonly blockCreated: 19578329;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
readonly l2OutputOracle: {
|
|
78
|
+
readonly 1: {
|
|
79
|
+
readonly address: "0xa426A052f657AEEefc298b3B5c35a470e4739d69";
|
|
80
|
+
readonly blockCreated: 19578337;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
readonly l1StandardBridge: {
|
|
84
|
+
readonly 1: {
|
|
85
|
+
readonly address: "0xc473ca7E02af24c129c2eEf51F2aDf0411c1Df69";
|
|
86
|
+
readonly blockCreated: 19578331;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
readonly gasPriceOracle: {
|
|
90
|
+
readonly address: "0x420000000000000000000000000000000000000F";
|
|
91
|
+
};
|
|
92
|
+
readonly l1Block: {
|
|
93
|
+
readonly address: "0x4200000000000000000000000000000000000015";
|
|
94
|
+
};
|
|
95
|
+
readonly l2CrossDomainMessenger: {
|
|
96
|
+
readonly address: "0x4200000000000000000000000000000000000007";
|
|
97
|
+
};
|
|
98
|
+
readonly l2Erc721Bridge: {
|
|
99
|
+
readonly address: "0x4200000000000000000000000000000000000014";
|
|
100
|
+
};
|
|
101
|
+
readonly l2StandardBridge: {
|
|
102
|
+
readonly address: "0x4200000000000000000000000000000000000010";
|
|
103
|
+
};
|
|
104
|
+
readonly l2ToL1MessagePasser: {
|
|
105
|
+
readonly address: "0x4200000000000000000000000000000000000016";
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
readonly id: 690;
|
|
109
|
+
readonly name: "Redstone";
|
|
61
110
|
readonly nativeCurrency: {
|
|
62
111
|
readonly decimals: 18;
|
|
63
112
|
readonly name: "Ether";
|
|
@@ -65,21 +114,248 @@ declare const latticeTestnet: {
|
|
|
65
114
|
};
|
|
66
115
|
readonly rpcUrls: {
|
|
67
116
|
readonly default: {
|
|
68
|
-
readonly http: readonly ["https://
|
|
69
|
-
readonly webSocket: readonly ["wss://
|
|
70
|
-
};
|
|
71
|
-
readonly public: {
|
|
72
|
-
readonly http: readonly ["https://follower.testnet-chain.linfra.xyz"];
|
|
73
|
-
readonly webSocket: readonly ["wss://follower.testnet-chain.linfra.xyz"];
|
|
117
|
+
readonly http: readonly ["https://rpc.redstonechain.com"];
|
|
118
|
+
readonly webSocket: readonly ["wss://rpc.redstonechain.com"];
|
|
74
119
|
};
|
|
75
120
|
};
|
|
76
|
-
readonly
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
121
|
+
readonly sourceId: 1;
|
|
122
|
+
readonly testnet?: boolean | undefined;
|
|
123
|
+
readonly custom?: Record<string, unknown> | undefined;
|
|
124
|
+
readonly fees?: viem.ChainFees<undefined> | undefined;
|
|
125
|
+
readonly formatters: {
|
|
126
|
+
readonly block: {
|
|
127
|
+
exclude: [] | undefined;
|
|
128
|
+
format: (args: viem_chains.OpStackRpcBlock<viem.BlockTag, boolean>) => {
|
|
129
|
+
baseFeePerGas: bigint | null;
|
|
130
|
+
blobGasUsed: bigint;
|
|
131
|
+
difficulty: bigint;
|
|
132
|
+
excessBlobGas: bigint;
|
|
133
|
+
extraData: `0x${string}`;
|
|
134
|
+
gasLimit: bigint;
|
|
135
|
+
gasUsed: bigint;
|
|
136
|
+
hash: `0x${string}` | null;
|
|
137
|
+
logsBloom: `0x${string}` | null;
|
|
138
|
+
miner: `0x${string}`;
|
|
139
|
+
mixHash: `0x${string}`;
|
|
140
|
+
nonce: `0x${string}` | null;
|
|
141
|
+
number: bigint | null;
|
|
142
|
+
parentBeaconBlockRoot?: `0x${string}` | undefined;
|
|
143
|
+
parentHash: `0x${string}`;
|
|
144
|
+
receiptsRoot: `0x${string}`;
|
|
145
|
+
sealFields: `0x${string}`[];
|
|
146
|
+
sha3Uncles: `0x${string}`;
|
|
147
|
+
size: bigint;
|
|
148
|
+
stateRoot: `0x${string}`;
|
|
149
|
+
timestamp: bigint;
|
|
150
|
+
totalDifficulty: bigint | null;
|
|
151
|
+
transactions: `0x${string}`[] | viem_chains.OpStackTransaction<boolean>[];
|
|
152
|
+
transactionsRoot: `0x${string}`;
|
|
153
|
+
uncles: `0x${string}`[];
|
|
154
|
+
withdrawals?: viem.Withdrawal[] | undefined;
|
|
155
|
+
withdrawalsRoot?: `0x${string}` | undefined;
|
|
156
|
+
};
|
|
157
|
+
type: "block";
|
|
158
|
+
};
|
|
159
|
+
readonly transaction: {
|
|
160
|
+
exclude: [] | undefined;
|
|
161
|
+
format: (args: viem_chains.OpStackRpcTransaction<boolean>) => {
|
|
162
|
+
blockHash: `0x${string}` | null;
|
|
163
|
+
blockNumber: bigint | null;
|
|
164
|
+
from: `0x${string}`;
|
|
165
|
+
gas: bigint;
|
|
166
|
+
hash: `0x${string}`;
|
|
167
|
+
input: `0x${string}`;
|
|
168
|
+
nonce: number;
|
|
169
|
+
r: `0x${string}`;
|
|
170
|
+
s: `0x${string}`;
|
|
171
|
+
to: `0x${string}` | null;
|
|
172
|
+
transactionIndex: number | null;
|
|
173
|
+
typeHex: `0x${string}` | null;
|
|
174
|
+
v: bigint;
|
|
175
|
+
value: bigint;
|
|
176
|
+
yParity: number;
|
|
177
|
+
gasPrice?: undefined;
|
|
178
|
+
maxFeePerBlobGas?: undefined;
|
|
179
|
+
maxFeePerGas: bigint;
|
|
180
|
+
maxPriorityFeePerGas: bigint;
|
|
181
|
+
isSystemTx?: boolean | undefined;
|
|
182
|
+
mint?: bigint | undefined;
|
|
183
|
+
sourceHash: `0x${string}`;
|
|
184
|
+
type: "deposit";
|
|
185
|
+
} | {
|
|
186
|
+
r: `0x${string}`;
|
|
187
|
+
s: `0x${string}`;
|
|
188
|
+
v: bigint;
|
|
189
|
+
to: `0x${string}` | null;
|
|
190
|
+
from: `0x${string}`;
|
|
191
|
+
gas: bigint;
|
|
192
|
+
nonce: number;
|
|
193
|
+
value: bigint;
|
|
194
|
+
blockHash: `0x${string}` | null;
|
|
195
|
+
blockNumber: bigint | null;
|
|
196
|
+
hash: `0x${string}`;
|
|
197
|
+
input: `0x${string}`;
|
|
198
|
+
transactionIndex: number | null;
|
|
199
|
+
typeHex: `0x${string}` | null;
|
|
200
|
+
accessList?: undefined;
|
|
201
|
+
authorizationList?: undefined;
|
|
202
|
+
blobVersionedHashes?: undefined;
|
|
203
|
+
chainId?: number | undefined;
|
|
204
|
+
yParity?: undefined;
|
|
205
|
+
type: "legacy";
|
|
206
|
+
gasPrice: bigint;
|
|
207
|
+
maxFeePerBlobGas?: undefined;
|
|
208
|
+
maxFeePerGas?: undefined;
|
|
209
|
+
maxPriorityFeePerGas?: undefined;
|
|
210
|
+
isSystemTx?: undefined;
|
|
211
|
+
mint?: undefined;
|
|
212
|
+
sourceHash?: undefined;
|
|
213
|
+
} | {
|
|
214
|
+
blockHash: `0x${string}` | null;
|
|
215
|
+
blockNumber: bigint | null;
|
|
216
|
+
from: `0x${string}`;
|
|
217
|
+
gas: bigint;
|
|
218
|
+
hash: `0x${string}`;
|
|
219
|
+
input: `0x${string}`;
|
|
220
|
+
nonce: number;
|
|
221
|
+
r: `0x${string}`;
|
|
222
|
+
s: `0x${string}`;
|
|
223
|
+
to: `0x${string}` | null;
|
|
224
|
+
transactionIndex: number | null;
|
|
225
|
+
typeHex: `0x${string}` | null;
|
|
226
|
+
v: bigint;
|
|
227
|
+
value: bigint;
|
|
228
|
+
yParity: number;
|
|
229
|
+
accessList: viem.AccessList;
|
|
230
|
+
authorizationList?: undefined;
|
|
231
|
+
blobVersionedHashes?: undefined;
|
|
232
|
+
chainId: number;
|
|
233
|
+
type: "eip2930";
|
|
234
|
+
gasPrice: bigint;
|
|
235
|
+
maxFeePerBlobGas?: undefined;
|
|
236
|
+
maxFeePerGas?: undefined;
|
|
237
|
+
maxPriorityFeePerGas?: undefined;
|
|
238
|
+
isSystemTx?: undefined;
|
|
239
|
+
mint?: undefined;
|
|
240
|
+
sourceHash?: undefined;
|
|
241
|
+
} | {
|
|
242
|
+
blockHash: `0x${string}` | null;
|
|
243
|
+
blockNumber: bigint | null;
|
|
244
|
+
from: `0x${string}`;
|
|
245
|
+
gas: bigint;
|
|
246
|
+
hash: `0x${string}`;
|
|
247
|
+
input: `0x${string}`;
|
|
248
|
+
nonce: number;
|
|
249
|
+
r: `0x${string}`;
|
|
250
|
+
s: `0x${string}`;
|
|
251
|
+
to: `0x${string}` | null;
|
|
252
|
+
transactionIndex: number | null;
|
|
253
|
+
typeHex: `0x${string}` | null;
|
|
254
|
+
v: bigint;
|
|
255
|
+
value: bigint;
|
|
256
|
+
yParity: number;
|
|
257
|
+
accessList: viem.AccessList;
|
|
258
|
+
authorizationList?: undefined;
|
|
259
|
+
blobVersionedHashes?: undefined;
|
|
260
|
+
chainId: number;
|
|
261
|
+
type: "eip1559";
|
|
262
|
+
gasPrice?: undefined;
|
|
263
|
+
maxFeePerBlobGas?: undefined;
|
|
264
|
+
maxFeePerGas: bigint;
|
|
265
|
+
maxPriorityFeePerGas: bigint;
|
|
266
|
+
isSystemTx?: undefined;
|
|
267
|
+
mint?: undefined;
|
|
268
|
+
sourceHash?: undefined;
|
|
269
|
+
} | {
|
|
270
|
+
blockHash: `0x${string}` | null;
|
|
271
|
+
blockNumber: bigint | null;
|
|
272
|
+
from: `0x${string}`;
|
|
273
|
+
gas: bigint;
|
|
274
|
+
hash: `0x${string}`;
|
|
275
|
+
input: `0x${string}`;
|
|
276
|
+
nonce: number;
|
|
277
|
+
r: `0x${string}`;
|
|
278
|
+
s: `0x${string}`;
|
|
279
|
+
to: `0x${string}` | null;
|
|
280
|
+
transactionIndex: number | null;
|
|
281
|
+
typeHex: `0x${string}` | null;
|
|
282
|
+
v: bigint;
|
|
283
|
+
value: bigint;
|
|
284
|
+
yParity: number;
|
|
285
|
+
accessList: viem.AccessList;
|
|
286
|
+
authorizationList?: undefined;
|
|
287
|
+
blobVersionedHashes: readonly `0x${string}`[];
|
|
288
|
+
chainId: number;
|
|
289
|
+
type: "eip4844";
|
|
290
|
+
gasPrice?: undefined;
|
|
291
|
+
maxFeePerBlobGas: bigint;
|
|
292
|
+
maxFeePerGas: bigint;
|
|
293
|
+
maxPriorityFeePerGas: bigint;
|
|
294
|
+
isSystemTx?: undefined;
|
|
295
|
+
mint?: undefined;
|
|
296
|
+
sourceHash?: undefined;
|
|
297
|
+
} | {
|
|
298
|
+
blockHash: `0x${string}` | null;
|
|
299
|
+
blockNumber: bigint | null;
|
|
300
|
+
from: `0x${string}`;
|
|
301
|
+
gas: bigint;
|
|
302
|
+
hash: `0x${string}`;
|
|
303
|
+
input: `0x${string}`;
|
|
304
|
+
nonce: number;
|
|
305
|
+
r: `0x${string}`;
|
|
306
|
+
s: `0x${string}`;
|
|
307
|
+
to: `0x${string}` | null;
|
|
308
|
+
transactionIndex: number | null;
|
|
309
|
+
typeHex: `0x${string}` | null;
|
|
310
|
+
v: bigint;
|
|
311
|
+
value: bigint;
|
|
312
|
+
yParity: number;
|
|
313
|
+
accessList: viem.AccessList;
|
|
314
|
+
authorizationList: viem_experimental.SignedAuthorizationList<number>;
|
|
315
|
+
blobVersionedHashes?: undefined;
|
|
316
|
+
chainId: number;
|
|
317
|
+
type: "eip7702";
|
|
318
|
+
gasPrice?: undefined;
|
|
319
|
+
maxFeePerBlobGas?: undefined;
|
|
320
|
+
maxFeePerGas: bigint;
|
|
321
|
+
maxPriorityFeePerGas: bigint;
|
|
322
|
+
isSystemTx?: undefined;
|
|
323
|
+
mint?: undefined;
|
|
324
|
+
sourceHash?: undefined;
|
|
325
|
+
};
|
|
326
|
+
type: "transaction";
|
|
327
|
+
};
|
|
328
|
+
readonly transactionReceipt: {
|
|
329
|
+
exclude: [] | undefined;
|
|
330
|
+
format: (args: viem_chains.OpStackRpcTransactionReceipt) => {
|
|
331
|
+
blobGasPrice?: bigint | undefined;
|
|
332
|
+
blobGasUsed?: bigint | undefined;
|
|
333
|
+
blockHash: `0x${string}`;
|
|
334
|
+
blockNumber: bigint;
|
|
335
|
+
contractAddress: `0x${string}` | null | undefined;
|
|
336
|
+
cumulativeGasUsed: bigint;
|
|
337
|
+
effectiveGasPrice: bigint;
|
|
338
|
+
from: `0x${string}`;
|
|
339
|
+
gasUsed: bigint;
|
|
340
|
+
logs: viem.Log<bigint, number, false, undefined, undefined, undefined, undefined>[];
|
|
341
|
+
logsBloom: `0x${string}`;
|
|
342
|
+
root?: `0x${string}` | undefined;
|
|
343
|
+
status: "success" | "reverted";
|
|
344
|
+
to: `0x${string}` | null;
|
|
345
|
+
transactionHash: `0x${string}`;
|
|
346
|
+
transactionIndex: number;
|
|
347
|
+
type: viem.TransactionType;
|
|
348
|
+
l1GasPrice: bigint | null;
|
|
349
|
+
l1GasUsed: bigint | null;
|
|
350
|
+
l1Fee: bigint | null;
|
|
351
|
+
l1FeeScalar: number | null;
|
|
352
|
+
};
|
|
353
|
+
type: "transactionReceipt";
|
|
80
354
|
};
|
|
81
355
|
};
|
|
82
|
-
readonly
|
|
356
|
+
readonly serializers: {
|
|
357
|
+
readonly transaction: typeof viem_chains.serializeTransactionOpStack;
|
|
358
|
+
};
|
|
83
359
|
};
|
|
84
360
|
|
|
85
361
|
declare const garnet: {
|
|
@@ -385,37 +661,24 @@ declare const garnet: {
|
|
|
385
661
|
};
|
|
386
662
|
};
|
|
387
663
|
|
|
388
|
-
declare const
|
|
389
|
-
readonly
|
|
390
|
-
readonly
|
|
391
|
-
readonly
|
|
664
|
+
declare const rhodolite: {
|
|
665
|
+
readonly name: "Rhodolite Devnet";
|
|
666
|
+
readonly testnet: true;
|
|
667
|
+
readonly id: 17420;
|
|
668
|
+
readonly sourceId: 17001;
|
|
669
|
+
readonly nativeCurrency: {
|
|
670
|
+
readonly name: "Ether";
|
|
671
|
+
readonly symbol: "ETH";
|
|
672
|
+
readonly decimals: 18;
|
|
673
|
+
};
|
|
674
|
+
readonly rpcUrls: {
|
|
392
675
|
readonly default: {
|
|
393
|
-
readonly
|
|
394
|
-
readonly url: "https://explorer.redstone.xyz";
|
|
676
|
+
readonly http: readonly ["https://rpc.rhodolitechain.com"];
|
|
395
677
|
};
|
|
396
678
|
};
|
|
679
|
+
readonly iconUrls: readonly ["https://redstone.xyz/chain-icons/rhodolite.png"];
|
|
680
|
+
readonly indexerUrl: "https://indexer.mud.rhodolitechain.com";
|
|
397
681
|
readonly contracts: {
|
|
398
|
-
readonly multicall3: {
|
|
399
|
-
readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
|
|
400
|
-
};
|
|
401
|
-
readonly portal: {
|
|
402
|
-
readonly 1: {
|
|
403
|
-
readonly address: "0xC7bCb0e8839a28A1cFadd1CF716de9016CdA51ae";
|
|
404
|
-
readonly blockCreated: 19578329;
|
|
405
|
-
};
|
|
406
|
-
};
|
|
407
|
-
readonly l2OutputOracle: {
|
|
408
|
-
readonly 1: {
|
|
409
|
-
readonly address: "0xa426A052f657AEEefc298b3B5c35a470e4739d69";
|
|
410
|
-
readonly blockCreated: 19578337;
|
|
411
|
-
};
|
|
412
|
-
};
|
|
413
|
-
readonly l1StandardBridge: {
|
|
414
|
-
readonly 1: {
|
|
415
|
-
readonly address: "0xc473ca7E02af24c129c2eEf51F2aDf0411c1Df69";
|
|
416
|
-
readonly blockCreated: 19578331;
|
|
417
|
-
};
|
|
418
|
-
};
|
|
419
682
|
readonly gasPriceOracle: {
|
|
420
683
|
readonly address: "0x420000000000000000000000000000000000000F";
|
|
421
684
|
};
|
|
@@ -435,27 +698,10 @@ declare const redstone: {
|
|
|
435
698
|
readonly address: "0x4200000000000000000000000000000000000016";
|
|
436
699
|
};
|
|
437
700
|
};
|
|
438
|
-
readonly id: 690;
|
|
439
|
-
readonly name: "Redstone";
|
|
440
|
-
readonly nativeCurrency: {
|
|
441
|
-
readonly decimals: 18;
|
|
442
|
-
readonly name: "Ether";
|
|
443
|
-
readonly symbol: "ETH";
|
|
444
|
-
};
|
|
445
|
-
readonly rpcUrls: {
|
|
446
|
-
readonly default: {
|
|
447
|
-
readonly http: readonly ["https://rpc.redstonechain.com"];
|
|
448
|
-
readonly webSocket: readonly ["wss://rpc.redstonechain.com"];
|
|
449
|
-
};
|
|
450
|
-
};
|
|
451
|
-
readonly sourceId: 1;
|
|
452
|
-
readonly testnet?: boolean | undefined;
|
|
453
|
-
readonly custom?: Record<string, unknown> | undefined;
|
|
454
|
-
readonly fees?: viem.ChainFees<undefined> | undefined;
|
|
455
701
|
readonly formatters: {
|
|
456
702
|
readonly block: {
|
|
457
703
|
exclude: [] | undefined;
|
|
458
|
-
format: (args:
|
|
704
|
+
format: (args: viem_op_stack.OpStackRpcBlock<viem.BlockTag, boolean>) => {
|
|
459
705
|
baseFeePerGas: bigint | null;
|
|
460
706
|
blobGasUsed: bigint;
|
|
461
707
|
difficulty: bigint;
|
|
@@ -478,7 +724,7 @@ declare const redstone: {
|
|
|
478
724
|
stateRoot: `0x${string}`;
|
|
479
725
|
timestamp: bigint;
|
|
480
726
|
totalDifficulty: bigint | null;
|
|
481
|
-
transactions: `0x${string}`[] |
|
|
727
|
+
transactions: `0x${string}`[] | viem_op_stack.OpStackTransaction<boolean>[];
|
|
482
728
|
transactionsRoot: `0x${string}`;
|
|
483
729
|
uncles: `0x${string}`[];
|
|
484
730
|
withdrawals?: viem.Withdrawal[] | undefined;
|
|
@@ -488,7 +734,7 @@ declare const redstone: {
|
|
|
488
734
|
};
|
|
489
735
|
readonly transaction: {
|
|
490
736
|
exclude: [] | undefined;
|
|
491
|
-
format: (args:
|
|
737
|
+
format: (args: viem_op_stack.OpStackRpcTransaction<boolean>) => {
|
|
492
738
|
blockHash: `0x${string}` | null;
|
|
493
739
|
blockNumber: bigint | null;
|
|
494
740
|
from: `0x${string}`;
|
|
@@ -657,7 +903,7 @@ declare const redstone: {
|
|
|
657
903
|
};
|
|
658
904
|
readonly transactionReceipt: {
|
|
659
905
|
exclude: [] | undefined;
|
|
660
|
-
format: (args:
|
|
906
|
+
format: (args: viem_op_stack.OpStackRpcTransactionReceipt) => {
|
|
661
907
|
blobGasPrice?: bigint | undefined;
|
|
662
908
|
blobGasUsed?: bigint | undefined;
|
|
663
909
|
blockHash: `0x${string}`;
|
|
@@ -684,8 +930,8 @@ declare const redstone: {
|
|
|
684
930
|
};
|
|
685
931
|
};
|
|
686
932
|
readonly serializers: {
|
|
687
|
-
readonly transaction: typeof
|
|
933
|
+
readonly transaction: typeof viem_op_stack.serializeTransaction;
|
|
688
934
|
};
|
|
689
935
|
};
|
|
690
936
|
|
|
691
|
-
export { MUDChain, garnet,
|
|
937
|
+
export { MUDChain, garnet, mudFoundry, redstone, rhodolite };
|
package/dist/chains.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{foundry as t}from"viem/chains";var e={...t,fees:{defaultPriorityFee:0n}};var r={
|
|
1
|
+
import{foundry as t}from"viem/chains";var e={...t,fees:{defaultPriorityFee:0n}};import{redstone as o}from"viem/chains";var r={...o,iconUrls:["https://redstone.xyz/chain-icons/redstone.png"],indexerUrl:"https://indexer.mud.redstonechain.com"};import{garnet as n}from"viem/chains";var i={...n,iconUrls:["https://redstone.xyz/chain-icons/garnet.png"],indexerUrl:"https://indexer.mud.garnetchain.com"};import{chainConfig as s}from"viem/op-stack";var a=17001,p={...s,name:"Rhodolite Devnet",testnet:!0,id:17420,sourceId:a,nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.rhodolitechain.com"]}},iconUrls:["https://redstone.xyz/chain-icons/rhodolite.png"],indexerUrl:"https://indexer.mud.rhodolitechain.com"};export{i as garnet,e as mudFoundry,r as redstone,p as rhodolite};
|
|
2
2
|
//# sourceMappingURL=chains.js.map
|
package/dist/chains.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/chains/mudFoundry.ts","../src/chains/
|
|
1
|
+
{"version":3,"sources":["../src/chains/mudFoundry.ts","../src/chains/redstone.ts","../src/chains/garnet.ts","../src/chains/rhodolite.ts"],"sourcesContent":["import { foundry } from \"viem/chains\";\nimport { MUDChain } from \"./types\";\n\nexport const mudFoundry = {\n ...foundry,\n fees: {\n defaultPriorityFee: 0n,\n },\n} as const satisfies MUDChain;\n","import { redstone as redstoneConfig } from \"viem/chains\";\nimport type { MUDChain } from \"./types\";\n\nexport const redstone = {\n ...redstoneConfig,\n iconUrls: [\"https://redstone.xyz/chain-icons/redstone.png\"],\n indexerUrl: \"https://indexer.mud.redstonechain.com\",\n} as const satisfies MUDChain;\n","import { garnet as garnetConfig } from \"viem/chains\";\nimport type { MUDChain } from \"./types\";\n\nexport const garnet = {\n ...garnetConfig,\n iconUrls: [\"https://redstone.xyz/chain-icons/garnet.png\"],\n indexerUrl: \"https://indexer.mud.garnetchain.com\",\n} as const satisfies MUDChain;\n","import { chainConfig } from \"viem/op-stack\";\nimport { MUDChain } from \"./types\";\n\nconst sourceId = 17001;\n\nexport const rhodolite = {\n ...chainConfig,\n name: \"Rhodolite Devnet\",\n testnet: true,\n id: 17420,\n sourceId,\n nativeCurrency: { name: \"Ether\", symbol: \"ETH\", decimals: 18 },\n rpcUrls: {\n default: {\n http: [\"https://rpc.rhodolitechain.com\"],\n },\n },\n iconUrls: [\"https://redstone.xyz/chain-icons/rhodolite.png\"],\n indexerUrl: \"https://indexer.mud.rhodolitechain.com\",\n} as const satisfies MUDChain;\n"],"mappings":"AAAA,OAAS,WAAAA,MAAe,cAGjB,IAAMC,EAAa,CACxB,GAAGD,EACH,KAAM,CACJ,mBAAoB,EACtB,CACF,ECRA,OAAS,YAAYE,MAAsB,cAGpC,IAAMC,EAAW,CACtB,GAAGD,EACH,SAAU,CAAC,+CAA+C,EAC1D,WAAY,uCACd,ECPA,OAAS,UAAUE,MAAoB,cAGhC,IAAMC,EAAS,CACpB,GAAGD,EACH,SAAU,CAAC,6CAA6C,EACxD,WAAY,qCACd,ECPA,OAAS,eAAAE,MAAmB,gBAG5B,IAAMC,EAAW,MAEJC,EAAY,CACvB,GAAGF,EACH,KAAM,mBACN,QAAS,GACT,GAAI,MACJ,SAAAC,EACA,eAAgB,CAAE,KAAM,QAAS,OAAQ,MAAO,SAAU,EAAG,EAC7D,QAAS,CACP,QAAS,CACP,KAAM,CAAC,gCAAgC,CACzC,CACF,EACA,SAAU,CAAC,gDAAgD,EAC3D,WAAY,wCACd","names":["foundry","mudFoundry","redstoneConfig","redstone","garnetConfig","garnet","chainConfig","sourceId","rhodolite"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as m}from"./chunk-TCWGPC6G.js";import{getAddress as v}from"viem";import{getChainId as O}from"viem/actions";import{getAction as A}from"viem/utils";async function p({client:e,address:r,blockTag:t}){return`mud:createNonceManager:${e.chain?.id??await A(e,O,"getChainId")({})}:${v(r)}:${t}`}import{BaseError as E,NonceTooHighError as I,NonceTooLowError as S}from"viem";import{getTransactionCount as k}from"viem/actions";import q from"p-queue";import{getAction as B}from"viem/utils";var w=m.extend("createNonceManager");function y({client:e,address:r,blockTag:t="latest",broadcastChannelName:o,queueConcurrency:i=1}){let n={nonce:-1,noncePromise:null},c=null;typeof BroadcastChannel<"u"&&(o?Promise.resolve(o):p({client:e,address:r,blockTag:t})).then(f=>{c=new BroadcastChannel(f),c.addEventListener("message",M=>{let b=JSON.parse(M.data);w("got nonce from broadcast channel",b),n.nonce=b})});function s(){return n.nonce>=0}function a(){if(!s())throw new Error("call resetNonce before using getNonce");return n.nonce}function u(){if(!s())throw new Error("call resetNonce before using nextNonce");let d=n.nonce++;return c?.postMessage(JSON.stringify(n.nonce)),d}async function R(){n.noncePromise??=(async()=>{n.nonce=await B(e,k,"getTransactionCount")({address:r,blockTag:t}),n.noncePromise=null,c?.postMessage(JSON.stringify(n.nonce)),w("reset nonce to",n.nonce)})(),await n.noncePromise}function P(d){return d instanceof E&&d.walk(f=>f instanceof S||f instanceof I)!=null}let F=new q({concurrency:i});return{hasNonce:s,getNonce:a,nextNonce:u,resetNonce:R,shouldResetNonce:P,mempoolQueue:F}}var N=new Map;async function g({client:e,address:r,blockTag:t="latest",...o}){let i=await p({client:e,address:r,blockTag:t}),n=N.get(i)??y({client:e,address:r,blockTag:t,...o});return N.has(i)||N.set(i,n),n.hasNonce()||await n.resetNonce(),n}import{writeContract as D}from"viem/actions";import J from"p-retry";import{parseAccount as U}from"viem/accounts";import{getChainId as Q}from"viem/actions";import{estimateFeesPerGas as W}from"viem/actions";import{getAction as G}from"viem/utils";async function x({client:e,args:r,refreshInterval:t}){let o={fees:{},lastUpdatedTimestamp:0};async function i(){let n=await G(e,W,"estimateFeesPerGas")(r);o.fees=n,o.lastUpdatedTimestamp=Date.now()}return setInterval(i,t),await i(),o}import{getAction as H}from"viem/utils";var T=new Map;async function l(e){let r=e.args?.chain?.id??e.client.chain?.id??await H(e.client,Q,"getChainId")({}),t=T.get(r);if(t)return t;let o=await x(e);return T.set(r,o),o}import{getAction as $}from"viem/utils";var h=m.extend("writeContract");async function Se(e,r,t={}){let o=r.account??e.account;if(!o)throw new Error("No account provided");let i=U(o),n=e.chain,c=await g({client:t.publicClient??e,address:i.address,queueConcurrency:t.queueConcurrency}),s=await l({client:t.publicClient??e,refreshInterval:1e4,args:{chain:n}});return c.mempoolQueue.add(()=>J(async()=>{let a=c.nextNonce(),u={blockTag:"pending",...r,nonce:a
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as m}from"./chunk-TCWGPC6G.js";import{getAddress as v}from"viem";import{getChainId as O}from"viem/actions";import{getAction as A}from"viem/utils";async function p({client:e,address:r,blockTag:t}){return`mud:createNonceManager:${e.chain?.id??await A(e,O,"getChainId")({})}:${v(r)}:${t}`}import{BaseError as E,NonceTooHighError as I,NonceTooLowError as S}from"viem";import{getTransactionCount as k}from"viem/actions";import q from"p-queue";import{getAction as B}from"viem/utils";var w=m.extend("createNonceManager");function y({client:e,address:r,blockTag:t="latest",broadcastChannelName:o,queueConcurrency:i=1}){let n={nonce:-1,noncePromise:null},c=null;typeof BroadcastChannel<"u"&&(o?Promise.resolve(o):p({client:e,address:r,blockTag:t})).then(f=>{c=new BroadcastChannel(f),c.addEventListener("message",M=>{let b=JSON.parse(M.data);w("got nonce from broadcast channel",b),n.nonce=b})});function s(){return n.nonce>=0}function a(){if(!s())throw new Error("call resetNonce before using getNonce");return n.nonce}function u(){if(!s())throw new Error("call resetNonce before using nextNonce");let d=n.nonce++;return c?.postMessage(JSON.stringify(n.nonce)),d}async function R(){n.noncePromise??=(async()=>{n.nonce=await B(e,k,"getTransactionCount")({address:r,blockTag:t}),n.noncePromise=null,c?.postMessage(JSON.stringify(n.nonce)),w("reset nonce to",n.nonce)})(),await n.noncePromise}function P(d){return d instanceof E&&d.walk(f=>f instanceof S||f instanceof I)!=null}let F=new q({concurrency:i});return{hasNonce:s,getNonce:a,nextNonce:u,resetNonce:R,shouldResetNonce:P,mempoolQueue:F}}var N=new Map;async function g({client:e,address:r,blockTag:t="latest",...o}){let i=await p({client:e,address:r,blockTag:t}),n=N.get(i)??y({client:e,address:r,blockTag:t,...o});return N.has(i)||N.set(i,n),n.hasNonce()||await n.resetNonce(),n}import{writeContract as D}from"viem/actions";import J from"p-retry";import{parseAccount as U}from"viem/accounts";import{getChainId as Q}from"viem/actions";import{estimateFeesPerGas as W}from"viem/actions";import{getAction as G}from"viem/utils";async function x({client:e,args:r,refreshInterval:t}){let o={fees:{},lastUpdatedTimestamp:0};async function i(){let n=await G(e,W,"estimateFeesPerGas")(r);o.fees=n,o.lastUpdatedTimestamp=Date.now()}return setInterval(i,t),await i(),o}import{getAction as H}from"viem/utils";var T=new Map;async function l(e){let r=e.args?.chain?.id??e.client.chain?.id??await H(e.client,Q,"getChainId")({}),t=T.get(r);if(t)return t;let o=await x(e);return T.set(r,o),o}import{getAction as $}from"viem/utils";var h=m.extend("writeContract");async function Se(e,r,t={}){let o=r.account??e.account;if(!o)throw new Error("No account provided");let i=U(o),n=e.chain,c=await g({client:t.publicClient??e,address:i.address,queueConcurrency:t.queueConcurrency}),s=await l({client:t.publicClient??e,refreshInterval:1e4,args:{chain:n}});return c.mempoolQueue.add(()=>J(async()=>{let a=c.nextNonce(),u={blockTag:"pending",...s.fees,...r,nonce:a};return h("calling",u.functionName,"at",u.address,"with nonce",a),await $(e,D,"writeContract")(u)},{retries:3,onFailedAttempt:async a=>{if(h("failed, resetting nonce"),await c.resetNonce(),c.shouldResetNonce(a)){h("got nonce error, retrying",a.message);return}if(String(a).includes("transaction underpriced")){h("got transaction underpriced error, retrying",a.message);return}throw a}}),{throwOnTimeout:!0})}import{sendTransaction as L}from"viem/actions";import _ from"p-retry";import{parseAccount as j}from"viem/accounts";import{getAction as z}from"viem/utils";var C=m.extend("sendTransaction");async function Je(e,r,t={}){let o=r.account??e.account;if(!o)throw new Error("No account provided");let i=j(o),n=e.chain,c=await g({client:t.publicClient??e,address:i.address,queueConcurrency:t.queueConcurrency}),s=await l({client:t.publicClient??e,refreshInterval:1e4,args:{chain:n}});return await c.mempoolQueue.add(()=>_(async()=>{let a=c.nextNonce(),u={blockTag:"pending",...s.fees,...r,nonce:a};return C("sending tx to",r.to,"with nonce",a),await z(e,L,"sendTransaction")(u)},{retries:3,onFailedAttempt:async a=>{if(C("failed, resetting nonce"),await c.resetNonce(),c.shouldResetNonce(a)){C("got nonce error, retrying",a.message);return}if(String(a).includes("transaction underpriced")){C("got transaction underpriced error, retrying",a.message);return}throw a}}),{throwOnTimeout:!0})}export{p as a,y as b,g as c,Se as d,Je as e};
|
|
2
|
+
//# sourceMappingURL=chunk-24YWZ2XF.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/getNonceManagerId.ts","../src/createNonceManager.ts","../src/getNonceManager.ts","../src/writeContract.ts","../src/getFeeRef.ts","../src/createFeeRef.ts","../src/sendTransaction.ts"],"sourcesContent":["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 { BaseError, BlockTag, Client, Hex, NonceTooHighError, NonceTooLowError } 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\";\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: unknown) => 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: unknown): boolean {\n return (\n error instanceof BaseError &&\n error.walk((e) => e instanceof NonceTooLowError || e instanceof NonceTooHighError) != null\n );\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","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 {\n Abi,\n Account,\n Chain,\n Client,\n Transport,\n WriteContractParameters,\n WriteContractReturnType,\n ContractFunctionName,\n ContractFunctionArgs,\n PublicClient,\n} from \"viem\";\nimport { writeContract as viem_writeContract } 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(\"writeContract\");\n\nexport type WriteContractExtraOptions<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`, `simulateContract`). 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?: PublicClient<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 writeContract<\n chain extends Chain | undefined,\n account extends Account | undefined,\n const abi extends Abi | readonly unknown[],\n functionName extends ContractFunctionName<abi, \"nonpayable\" | \"payable\">,\n args extends ContractFunctionArgs<abi, \"nonpayable\" | \"payable\", functionName>,\n chainOverride extends Chain | undefined,\n>(\n client: Client<Transport, chain, account>,\n request: WriteContractParameters<abi, functionName, args, chain, account, chainOverride>,\n opts: WriteContractExtraOptions<chain> = {},\n): Promise<WriteContractReturnType> {\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 nonceManager.mempoolQueue.add(\n () =>\n pRetry(\n async () => {\n const nonce = nonceManager.nextNonce();\n const params = {\n // viem_writeContract internally estimates gas, which we want to happen on the pending block\n blockTag: \"pending\",\n ...request,\n nonce,\n ...feeRef.fees,\n } as const satisfies WriteContractParameters<abi, functionName, args, chain, account, chainOverride>;\n debug(\"calling\", params.functionName, \"at\", params.address, \"with nonce\", nonce);\n return await getAction(client, viem_writeContract, \"writeContract\")(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 { 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","import {\n Account,\n Chain,\n Client,\n SendTransactionParameters,\n Transport,\n SendTransactionReturnType,\n PublicClient,\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?: PublicClient<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 ...request,\n nonce,\n ...feeRef.fees,\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"],"mappings":"wCAAA,OAAgC,cAAAA,MAAkB,OACl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/BM,EAAS,CAEb,SAAU,UACV,GAAGZ,EACH,MAAAW,EACA,GAAGH,EAAO,IACZ,EACA,OAAAX,EAAM,gBAAiBG,EAAQ,GAAI,aAAcW,CAAK,EAC/C,MAAMf,EAAUG,EAAQc,EAAsB,iBAAiB,EAAED,CAAe,CACzF,EACA,CACE,QAAS,EACT,gBAAiB,MAAOE,GAAU,CAMhC,GAJAjB,EAAM,yBAAyB,EAC/B,MAAMS,EAAa,WAAW,EAG1BA,EAAa,iBAAiBQ,CAAK,EAAG,CACxCjB,EAAM,4BAA6BiB,EAAM,OAAO,EAChD,OAGF,GAAI,OAAOA,CAAK,EAAE,SAAS,yBAAyB,EAAG,CACrDjB,EAAM,8CAA+CiB,EAAM,OAAO,EAClE,OAGF,MAAMA,CACR,CACF,CACF,EACF,CAAE,eAAgB,EAAK,CACzB,CACF","names":["getAddress","getChainId","getAction","getNonceManagerId","client","address","blockTag","BaseError","NonceTooHighError","NonceTooLowError","getTransactionCount","PQueue","getAction","debug","createNonceManager","client","address","blockTag","broadcastChannelName","queueConcurrency","ref","channel","getNonceManagerId","name","event","nonce","hasNonce","getNonce","nextNonce","resetNonce","shouldResetNonce","error","BaseError","e","NonceTooLowError","NonceTooHighError","mempoolQueue","nonceManagers","getNonceManager","client","address","blockTag","opts","id","getNonceManagerId","nonceManager","createNonceManager","viem_writeContract","pRetry","parseAccount","getChainId","estimateFeesPerGas","getAction","createFeeRef","client","args","refreshInterval","feeRef","updateFees","fees","getAction","feeRefs","getFeeRef","opts","chainId","getChainId","existingFeeRef","feeRef","createFeeRef","getAction","debug","writeContract","client","request","opts","rawAccount","account","parseAccount","chain","nonceManager","getNonceManager","feeRef","getFeeRef","pRetry","nonce","params","viem_writeContract","error","viem_sendTransaction","pRetry","parseAccount","getAction","debug","sendTransaction","client","request","opts","rawAccount","account","parseAccount","chain","nonceManager","getNonceManager","feeRef","getFeeRef","pRetry","nonce","params","viem_sendTransaction","error"]}
|
|
1
|
+
{"version":3,"sources":["../src/getNonceManagerId.ts","../src/createNonceManager.ts","../src/getNonceManager.ts","../src/writeContract.ts","../src/getFeeRef.ts","../src/createFeeRef.ts","../src/sendTransaction.ts"],"sourcesContent":["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 { BaseError, BlockTag, Client, Hex, NonceTooHighError, NonceTooLowError } 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\";\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: unknown) => 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: unknown): boolean {\n return (\n error instanceof BaseError &&\n error.walk((e) => e instanceof NonceTooLowError || e instanceof NonceTooHighError) != null\n );\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","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 {\n Abi,\n Account,\n Chain,\n Client,\n Transport,\n WriteContractParameters,\n WriteContractReturnType,\n ContractFunctionName,\n ContractFunctionArgs,\n PublicClient,\n} from \"viem\";\nimport { writeContract as viem_writeContract } 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(\"writeContract\");\n\nexport type WriteContractExtraOptions<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`, `simulateContract`). 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?: PublicClient<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 writeContract<\n chain extends Chain | undefined,\n account extends Account | undefined,\n const abi extends Abi | readonly unknown[],\n functionName extends ContractFunctionName<abi, \"nonpayable\" | \"payable\">,\n args extends ContractFunctionArgs<abi, \"nonpayable\" | \"payable\", functionName>,\n chainOverride extends Chain | undefined,\n>(\n client: Client<Transport, chain, account>,\n request: WriteContractParameters<abi, functionName, args, chain, account, chainOverride>,\n opts: WriteContractExtraOptions<chain> = {},\n): Promise<WriteContractReturnType> {\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 nonceManager.mempoolQueue.add(\n () =>\n pRetry(\n async () => {\n const nonce = nonceManager.nextNonce();\n const params = {\n // viem_writeContract 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 WriteContractParameters<abi, functionName, args, chain, account, chainOverride>;\n debug(\"calling\", params.functionName, \"at\", params.address, \"with nonce\", nonce);\n return await getAction(client, viem_writeContract, \"writeContract\")(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 { 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","import {\n Account,\n Chain,\n Client,\n SendTransactionParameters,\n Transport,\n SendTransactionReturnType,\n PublicClient,\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?: PublicClient<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"],"mappings":"wCAAA,OAAgC,cAAAA,MAAkB,OAClD,OAAS,cAAAC,MAAkB,eAC3B,OAAS,aAAAC,MAAiB,aAE1B,eAAsBC,EAAkB,CACtC,OAAAC,EACA,QAAAC,EACA,SAA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AI,aAAcW,CAAK,EAC/C,MAAMf,EAAUG,EAAQc,EAAsB,iBAAiB,EAAED,CAAe,CACzF,EACA,CACE,QAAS,EACT,gBAAiB,MAAOE,GAAU,CAMhC,GAJAjB,EAAM,yBAAyB,EAC/B,MAAMS,EAAa,WAAW,EAG1BA,EAAa,iBAAiBQ,CAAK,EAAG,CACxCjB,EAAM,4BAA6BiB,EAAM,OAAO,EAChD,OAGF,GAAI,OAAOA,CAAK,EAAE,SAAS,yBAAyB,EAAG,CACrDjB,EAAM,8CAA+CiB,EAAM,OAAO,EAClE,OAGF,MAAMA,CACR,CACF,CACF,EACF,CAAE,eAAgB,EAAK,CACzB,CACF","names":["getAddress","getChainId","getAction","getNonceManagerId","client","address","blockTag","BaseError","NonceTooHighError","NonceTooLowError","getTransactionCount","PQueue","getAction","debug","createNonceManager","client","address","blockTag","broadcastChannelName","queueConcurrency","ref","channel","getNonceManagerId","name","event","nonce","hasNonce","getNonce","nextNonce","resetNonce","shouldResetNonce","error","BaseError","e","NonceTooLowError","NonceTooHighError","mempoolQueue","nonceManagers","getNonceManager","client","address","blockTag","opts","id","getNonceManagerId","nonceManager","createNonceManager","viem_writeContract","pRetry","parseAccount","getChainId","estimateFeesPerGas","getAction","createFeeRef","client","args","refreshInterval","feeRef","updateFees","fees","getAction","feeRefs","getFeeRef","opts","chainId","getChainId","existingFeeRef","feeRef","createFeeRef","getAction","debug","writeContract","client","request","opts","rawAccount","account","parseAccount","chain","nonceManager","getNonceManager","feeRef","getFeeRef","pRetry","nonce","params","viem_writeContract","error","viem_sendTransaction","pRetry","parseAccount","getAction","debug","sendTransaction","client","request","opts","rawAccount","account","parseAccount","chain","nonceManager","getNonceManager","feeRef","getFeeRef","pRetry","nonce","params","viem_sendTransaction","error"]}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as K,b as $,c as q,d as p,e as _}from"./chunk-
|
|
1
|
+
import{a as K,b as $,c as q,d as p,e as _}from"./chunk-24YWZ2XF.js";import{a as B,b as D,c as x,d as L,e as m}from"./chunk-DDEUATTE.js";import{a as l}from"./chunk-TCWGPC6G.js";import h from"debug";var T=h("mud:benchmark");T.log=console.info.bind(console);function U(e){let r=T.extend(e),t=performance.now();return o=>{let n=(performance.now()-t)/1e3;r("%s: +%ds",o,n),t=performance.now()}}import{privateKeyToAccount as P}from"viem/accounts";function Q(e){return{...P(e)}}import{getContract as w}from"viem";function H(e){let r=e.length&&Array.isArray(e[0]),t=r?e[0]:[],o=(r?e[1]:e[0])??{};return{args:t,options:o}}function d({abi:e,address:r,client:{public:t,wallet:o},onWrite:n}){let i=w({abi:e,address:r,client:{public:t,wallet:o}});if(i.write){let s=0;i.write=new Proxy({},{get(F,C){return(...g)=>{let{args:A,options:k}=H(g),c={abi:e,address:r,functionName:C,args:A,...k,onWrite:n},u=p(o,c,{publicClient:t}),y=`${o.chain.id}:${o.account.address}:${s++}`;return n?.({id:y,request:c,result:u}),u}}})}return i}import{generatePrivateKey as v,privateKeyToAccount as f}from"viem/accounts";import{isHex as W}from"viem";function O(e,r){if(!W(e))throw console.error("Private key found in cache is not valid hex",{privateKey:e,cacheKey:r}),new Error(`Private key found in cache (${r}) is not valid hex`);f(e)}function Te(e="mud:burnerWallet"){let r=localStorage.getItem(e);if(r!=null)return O(r,e),r;let t=v();return console.log("New burner wallet created:",f(t)),localStorage.setItem(e,t),t}function fe(e,r){return e.blockNumber===r.blockNumber?e.logIndex===r.logIndex?0:e.logIndex==null?1:r.logIndex==null?-1:e.logIndex-r.logIndex:e.blockNumber==null?1:r.blockNumber==null?-1:e.blockNumber>r.blockNumber?1:e.blockNumber<r.blockNumber?-1:0}var b=class extends Map{maxSize;constructor(r){super(),this.maxSize=r}set(r,t){return super.set(r,t),this.maxSize&&this.size>this.maxSize&&this.delete(this.keys().next().value),this}};function a(e,r,t){return`0x${e.replace(/^0x/,"").slice(r*2,t!=null?t*2:void 0).padEnd(((t??r)-r)*2,"0")}`}function Ae(e){return"ok"in e}function I(e){return"error"in e}function ke(e){if(I(e))throw e.error;return e.ok}import{concatHex as N}from"viem";function He(e,r,t=0,o="0x"){return N([a(e,0,r),o,a(e,r+t)])}import{keccak256 as E}from"viem";var R=l.extend("transportObserver");function Ee(e){return r=>{let t=e(r);return{...t,request:async n=>{if(n.method==="eth_sendRawTransaction"&&n.params instanceof Array){let i=n.params.map(s=>E(s));R("saw txs",i)}return t.request(n)}}}}var S=d;var G=x;var z=m;export{b as LruMap,U as createBenchmark,Q as createBurnerAccount,S as createContract,$ as createNonceManager,Te as getBurnerPrivateKey,d as getContract,q as getNonceManager,K as getNonceManagerId,m as hexToResource,z as hexToResourceId,I as isError,Ae as isOk,fe as logSort,a as readHex,G as resourceIdToHex,x as resourceToHex,L as resourceToLabel,D as resourceTypeIds,B as resourceTypes,_ as sendTransaction,He as spliceHex,Ee as transportObserver,ke as unwrap,p as writeContract};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latticexyz/common",
|
|
3
|
-
"version": "2.2.12
|
|
3
|
+
"version": "2.2.12",
|
|
4
4
|
"description": "Common low level logic shared between packages",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"prettier": "3.2.5",
|
|
67
67
|
"prettier-plugin-solidity": "1.3.1",
|
|
68
68
|
"viem": "2.21.19",
|
|
69
|
-
"@latticexyz/schema-type": "2.2.12
|
|
69
|
+
"@latticexyz/schema-type": "2.2.12"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/debug": "^4.1.7",
|