@latticexyz/common 2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2 → 2.2.18-c2ad22c7feb566e1731ff16e8be291746bdffb3e

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.js +1 -39
  2. package/dist/actions.js.map +1 -1
  3. package/dist/chains.js +1 -75
  4. package/dist/chains.js.map +1 -1
  5. package/dist/chunk-6FIKI2CG.js +2 -0
  6. package/dist/{chunk-MYWRXQQH.js.map → chunk-6FIKI2CG.js.map} +1 -1
  7. package/dist/chunk-DPUUE7NM.js +2 -0
  8. package/dist/{chunk-Z6SVAIZN.js.map → chunk-DPUUE7NM.js.map} +1 -1
  9. package/dist/chunk-QQCZY3XJ.js +2 -0
  10. package/dist/{chunk-MF5NFUW7.js.map → chunk-QQCZY3XJ.js.map} +1 -1
  11. package/dist/chunk-TCWGPC6G.js +2 -0
  12. package/dist/{chunk-MK6UECU7.js.map → chunk-TCWGPC6G.js.map} +1 -1
  13. package/dist/chunk-ZIUX7JCQ.js +2 -0
  14. package/dist/{chunk-D4GDXAMP.js.map → chunk-ZIUX7JCQ.js.map} +1 -1
  15. package/dist/chunk-ZV2KGJCD.js +2 -0
  16. package/dist/{chunk-IYZZFDNO.js.map → chunk-ZV2KGJCD.js.map} +1 -1
  17. package/dist/codegen.js +49 -706
  18. package/dist/codegen.js.map +1 -1
  19. package/dist/errors.js +1 -6
  20. package/dist/foundry.js +2 -71
  21. package/dist/foundry.js.map +1 -1
  22. package/dist/index.js +1 -233
  23. package/dist/index.js.map +1 -1
  24. package/dist/internal.js +9 -205
  25. package/dist/internal.js.map +1 -1
  26. package/dist/kms.js +1 -168
  27. package/dist/kms.js.map +1 -1
  28. package/dist/utils.js +1 -122
  29. package/dist/utils.js.map +1 -1
  30. package/package.json +16 -104
  31. package/dist/actions.cjs +0 -334
  32. package/dist/actions.cjs.map +0 -1
  33. package/dist/actions.d.cts +0 -27
  34. package/dist/chains.cjs +0 -106
  35. package/dist/chains.cjs.map +0 -1
  36. package/dist/chains.d.cts +0 -968
  37. package/dist/chunk-D4GDXAMP.js +0 -64
  38. package/dist/chunk-IYZZFDNO.js +0 -16
  39. package/dist/chunk-MF5NFUW7.js +0 -12
  40. package/dist/chunk-MK6UECU7.js +0 -11
  41. package/dist/chunk-MYWRXQQH.js +0 -208
  42. package/dist/chunk-Z6SVAIZN.js +0 -70
  43. package/dist/codegen.cjs +0 -889
  44. package/dist/codegen.cjs.map +0 -1
  45. package/dist/codegen.d.cts +0 -228
  46. package/dist/errors.cjs +0 -38
  47. package/dist/errors.cjs.map +0 -1
  48. package/dist/errors.d.cts +0 -5
  49. package/dist/foundry.cjs +0 -105
  50. package/dist/foundry.cjs.map +0 -1
  51. package/dist/foundry.d.cts +0 -69
  52. package/dist/getContract-CA0EdVg6.d.cts +0 -20
  53. package/dist/index.cjs +0 -597
  54. package/dist/index.cjs.map +0 -1
  55. package/dist/index.d.cts +0 -160
  56. package/dist/internal.cjs +0 -459
  57. package/dist/internal.cjs.map +0 -1
  58. package/dist/internal.d.cts +0 -36
  59. package/dist/kms.cjs +0 -204
  60. package/dist/kms.cjs.map +0 -1
  61. package/dist/kms.d.cts +0 -18
  62. package/dist/type-utils.cjs +0 -19
  63. package/dist/type-utils.cjs.map +0 -1
  64. package/dist/type-utils.d.cts +0 -19
  65. package/dist/utils.cjs +0 -174
  66. package/dist/utils.cjs.map +0 -1
  67. package/dist/utils.d.cts +0 -40
package/dist/actions.js CHANGED
@@ -1,40 +1,2 @@
1
- import {
2
- writeContract
3
- } from "./chunk-Z6SVAIZN.js";
4
- import {
5
- sendTransaction
6
- } from "./chunk-MYWRXQQH.js";
7
- import "./chunk-MK6UECU7.js";
8
-
9
- // src/actions/transactionQueue.ts
10
- function transactionQueue(opts = {}) {
11
- return (client) => ({
12
- // Applies to: `client.writeContract`, `getContract(client, ...).write`
13
- writeContract: (args) => writeContract(client, args, opts),
14
- // Applies to: `client.sendTransaction`
15
- sendTransaction: (args) => sendTransaction(client, args, opts)
16
- });
17
- }
18
-
19
- // src/actions/writeObserver.ts
20
- import { getAction } from "viem/utils";
21
- import { writeContract as writeContract2 } from "viem/actions";
22
- function writeObserver({
23
- onWrite
24
- }) {
25
- let nextWriteId = 0;
26
- return (client) => ({
27
- // Applies to: `client.writeContract`, `getContract(client, ...).write`
28
- writeContract: (args) => {
29
- const result = getAction(client, writeContract2, "writeContract")(args);
30
- const id = `${client.chain.id}:${client.account.address}:${nextWriteId++}`;
31
- onWrite({ id, request: args, result });
32
- return result;
33
- }
34
- });
35
- }
36
- export {
37
- transactionQueue,
38
- writeObserver
39
- };
1
+ import{a as o}from"./chunk-DPUUE7NM.js";import{f as a}from"./chunk-6FIKI2CG.js";import"./chunk-TCWGPC6G.js";function d(n={}){return e=>({writeContract:t=>o(e,t,n),sendTransaction:t=>a(e,t,n)})}import{getAction as s}from"viem/utils";import{writeContract as u}from"viem/actions";function f({onWrite:n}){let e=0;return t=>({writeContract:r=>{let i=s(t,u,"writeContract")(r),c=`${t.chain.id}:${t.account.address}:${e++}`;return n({id:c,request:r,result:i}),i}})}export{d as transactionQueue,f as writeObserver};
40
2
  //# sourceMappingURL=actions.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/actions/transactionQueue.ts","../src/actions/writeObserver.ts"],"sourcesContent":["import type { Transport, Chain, Account, WalletActions, Client } from \"viem\";\nimport { writeContract as mud_writeContract } from \"../writeContract\";\nimport { sendTransaction as mud_sendTransaction } from \"../sendTransaction\";\n\nexport type TransactionQueueOptions<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`, `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\nexport function transactionQueue<chain extends Chain | undefined>(\n opts: TransactionQueueOptions<chain> = {},\n): <transport extends Transport, account extends Account | undefined = Account | undefined>(\n client: Client<transport, chain, account>,\n) => Pick<WalletActions<chain, account>, \"writeContract\" | \"sendTransaction\"> {\n return (client) => ({\n // Applies to: `client.writeContract`, `getContract(client, ...).write`\n writeContract: (args) => mud_writeContract(client, args, opts),\n // Applies to: `client.sendTransaction`\n sendTransaction: (args) => mud_sendTransaction(client, args, opts),\n });\n}\n","import type {\n WriteContractParameters,\n Transport,\n Chain,\n Account,\n WalletActions,\n WriteContractReturnType,\n Client,\n} from \"viem\";\nimport { getAction } from \"viem/utils\";\nimport { writeContract } from \"viem/actions\";\nimport { type ContractWrite } from \"../getContract\";\n\ntype WriteObserverParameters = { onWrite: (write: ContractWrite) => void };\n\nexport function writeObserver<TChain extends Chain, TAccount extends Account>({\n onWrite,\n}: WriteObserverParameters): (\n client: Client<Transport, TChain, TAccount>,\n) => Pick<WalletActions<TChain, TAccount>, \"writeContract\"> {\n let nextWriteId = 0;\n\n return (client) => ({\n // Applies to: `client.writeContract`, `getContract(client, ...).write`\n writeContract: (args): Promise<WriteContractReturnType> => {\n const result = getAction(client, writeContract, \"writeContract\")(args);\n\n const id = `${client.chain.id}:${client.account.address}:${nextWriteId++}`;\n onWrite({ id, request: args as WriteContractParameters, result });\n\n return result;\n },\n });\n}\n"],"mappings":";;;;;;;;;AAqBO,SAAS,iBACd,OAAuC,CAAC,GAGoC;AAC5E,SAAO,CAAC,YAAY;AAAA;AAAA,IAElB,eAAe,CAAC,SAAS,cAAkB,QAAQ,MAAM,IAAI;AAAA;AAAA,IAE7D,iBAAiB,CAAC,SAAS,gBAAoB,QAAQ,MAAM,IAAI;AAAA,EACnE;AACF;;;ACvBA,SAAS,iBAAiB;AAC1B,SAAS,iBAAAA,sBAAqB;AAKvB,SAAS,cAA8D;AAAA,EAC5E;AACF,GAE4D;AAC1D,MAAI,cAAc;AAElB,SAAO,CAAC,YAAY;AAAA;AAAA,IAElB,eAAe,CAAC,SAA2C;AACzD,YAAM,SAAS,UAAU,QAAQA,gBAAe,eAAe,EAAE,IAAI;AAErE,YAAM,KAAK,GAAG,OAAO,MAAM,EAAE,IAAI,OAAO,QAAQ,OAAO,IAAI,aAAa;AACxE,cAAQ,EAAE,IAAI,SAAS,MAAiC,OAAO,CAAC;AAEhE,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["writeContract"]}
1
+ {"version":3,"sources":["../src/actions/transactionQueue.ts","../src/actions/writeObserver.ts"],"sourcesContent":["import type { Transport, Chain, Account, WalletActions, Client } from \"viem\";\nimport { writeContract as mud_writeContract } from \"../writeContract\";\nimport { sendTransaction as mud_sendTransaction } from \"../sendTransaction\";\n\nexport type TransactionQueueOptions<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`, `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\nexport function transactionQueue<chain extends Chain | undefined>(\n opts: TransactionQueueOptions<chain> = {},\n): <transport extends Transport, account extends Account | undefined = Account | undefined>(\n client: Client<transport, chain, account>,\n) => Pick<WalletActions<chain, account>, \"writeContract\" | \"sendTransaction\"> {\n return (client) => ({\n // Applies to: `client.writeContract`, `getContract(client, ...).write`\n writeContract: (args) => mud_writeContract(client, args, opts),\n // Applies to: `client.sendTransaction`\n sendTransaction: (args) => mud_sendTransaction(client, args, opts),\n });\n}\n","import type {\n WriteContractParameters,\n Transport,\n Chain,\n Account,\n WalletActions,\n WriteContractReturnType,\n Client,\n} from \"viem\";\nimport { getAction } from \"viem/utils\";\nimport { writeContract } from \"viem/actions\";\nimport { type ContractWrite } from \"../getContract\";\n\ntype WriteObserverParameters = { onWrite: (write: ContractWrite) => void };\n\nexport function writeObserver<TChain extends Chain, TAccount extends Account>({\n onWrite,\n}: WriteObserverParameters): (\n client: Client<Transport, TChain, TAccount>,\n) => Pick<WalletActions<TChain, TAccount>, \"writeContract\"> {\n let nextWriteId = 0;\n\n return (client) => ({\n // Applies to: `client.writeContract`, `getContract(client, ...).write`\n writeContract: (args): Promise<WriteContractReturnType> => {\n const result = getAction(client, writeContract, \"writeContract\")(args);\n\n const id = `${client.chain.id}:${client.account.address}:${nextWriteId++}`;\n onWrite({ id, request: args as WriteContractParameters, result });\n\n return result;\n },\n });\n}\n"],"mappings":"4GAqBO,SAASA,EACdC,EAAuC,CAAC,EAGoC,CAC5E,OAAQC,IAAY,CAElB,cAAgBC,GAASC,EAAkBF,EAAQC,EAAMF,CAAI,EAE7D,gBAAkBE,GAASE,EAAoBH,EAAQC,EAAMF,CAAI,CACnE,EACF,CCvBA,OAAS,aAAAK,MAAiB,aAC1B,OAAS,iBAAAC,MAAqB,eAKvB,SAASC,EAA8D,CAC5E,QAAAC,CACF,EAE4D,CAC1D,IAAIC,EAAc,EAElB,OAAQC,IAAY,CAElB,cAAgBC,GAA2C,CACzD,IAAMC,EAASP,EAAUK,EAAQJ,EAAe,eAAe,EAAEK,CAAI,EAE/DE,EAAK,GAAGH,EAAO,MAAM,EAAE,IAAIA,EAAO,QAAQ,OAAO,IAAID,GAAa,GACxE,OAAAD,EAAQ,CAAE,GAAAK,EAAI,QAASF,EAAiC,OAAAC,CAAO,CAAC,EAEzDA,CACT,CACF,EACF","names":["transactionQueue","opts","client","args","writeContract","sendTransaction","getAction","writeContract","writeObserver","onWrite","nextWriteId","client","args","result","id"]}
package/dist/chains.js CHANGED
@@ -1,76 +1,2 @@
1
- // src/chains/mudFoundry.ts
2
- import { foundry } from "viem/chains";
3
- var mudFoundry = {
4
- ...foundry,
5
- fees: {
6
- defaultPriorityFee: 0n
7
- }
8
- };
9
-
10
- // src/chains/redstone.ts
11
- import { redstone as redstoneConfig } from "viem/chains";
12
- var redstone = {
13
- ...redstoneConfig,
14
- iconUrls: ["https://redstone.xyz/chain-icons/redstone.png"],
15
- indexerUrl: "https://indexer.mud.redstonechain.com"
16
- };
17
-
18
- // src/chains/garnet.ts
19
- import { garnet as garnetConfig } from "viem/chains";
20
- var garnet = {
21
- ...garnetConfig,
22
- iconUrls: ["https://redstone.xyz/chain-icons/garnet.png"],
23
- indexerUrl: "https://indexer.mud.garnetchain.com"
24
- };
25
-
26
- // src/chains/rhodolite.ts
27
- import { chainConfig } from "viem/op-stack";
28
- var sourceId = 17e3;
29
- var defaultRpcUrls = {
30
- http: ["https://rpc.rhodolitechain.com"],
31
- webSocket: ["wss://rpc.rhodolitechain.com"]
32
- };
33
- var rhodolite = {
34
- ...chainConfig,
35
- name: "Rhodolite Devnet",
36
- testnet: true,
37
- id: 17420,
38
- sourceId,
39
- nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
40
- rpcUrls: {
41
- default: defaultRpcUrls,
42
- bundler: defaultRpcUrls,
43
- quarryPassIssuer: defaultRpcUrls,
44
- wiresaw: defaultRpcUrls
45
- },
46
- contracts: {
47
- ...chainConfig.contracts,
48
- l1StandardBridge: {
49
- [sourceId]: {
50
- address: "0x6487446e0B9FAEa90F6a9772A6448cFa780E30F9"
51
- }
52
- },
53
- quarryPaymaster: {
54
- address: "0x7ca1b85aca23fccf2fbac14c02b5e8a6432639b9"
55
- }
56
- },
57
- blockExplorers: {
58
- default: {
59
- name: "Blockscout",
60
- url: "https://explorer.rhodolitechain.com"
61
- },
62
- worldsExplorer: {
63
- name: "MUD Worlds Explorer",
64
- url: "https://explorer.mud.dev/rhodolite/worlds"
65
- }
66
- },
67
- iconUrls: ["https://redstone.xyz/chain-icons/rhodolite.png"],
68
- indexerUrl: "https://indexer.mud.rhodolitechain.com"
69
- };
70
- export {
71
- garnet,
72
- mudFoundry,
73
- redstone,
74
- rhodolite
75
- };
1
+ import{foundry as t}from"viem/chains";var s={...t,fees:{defaultPriorityFee:0n}};import{redstone as n}from"viem/chains";var i={...n,iconUrls:["https://redstone.xyz/chain-icons/redstone.png"],indexerUrl:"https://indexer.mud.redstonechain.com"};import{garnet as a}from"viem/chains";var c={...a,iconUrls:["https://redstone.xyz/chain-icons/garnet.png"],indexerUrl:"https://indexer.mud.garnetchain.com"};import{chainConfig as e}from"viem/op-stack";var o=17e3,r={http:["https://rpc.rhodolitechain.com"],webSocket:["wss://rpc.rhodolitechain.com"]},d={...e,name:"Rhodolite Devnet",testnet:!0,id:17420,sourceId:o,nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:r,bundler:r,quarryPassIssuer:r,wiresaw:r},contracts:{...e.contracts,l1StandardBridge:{[o]:{address:"0x6487446e0B9FAEa90F6a9772A6448cFa780E30F9"}},quarryPaymaster:{address:"0x7ca1b85aca23fccf2fbac14c02b5e8a6432639b9"}},blockExplorers:{default:{name:"Blockscout",url:"https://explorer.rhodolitechain.com"},worldsExplorer:{name:"MUD Worlds Explorer",url:"https://explorer.mud.dev/rhodolite/worlds"}},iconUrls:["https://redstone.xyz/chain-icons/rhodolite.png"],indexerUrl:"https://indexer.mud.rhodolitechain.com"};export{c as garnet,s as mudFoundry,i as redstone,d as rhodolite};
76
2
  //# sourceMappingURL=chains.js.map
@@ -1 +1 @@
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\";\nimport { Chain } from \"viem\";\n\nconst sourceId = 17000;\n\nconst defaultRpcUrls = {\n http: [\"https://rpc.rhodolitechain.com\"],\n webSocket: [\"wss://rpc.rhodolitechain.com\"],\n} as const satisfies Chain[\"rpcUrls\"][\"default\"];\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: defaultRpcUrls,\n bundler: defaultRpcUrls,\n quarryPassIssuer: defaultRpcUrls,\n wiresaw: defaultRpcUrls,\n },\n contracts: {\n ...chainConfig.contracts,\n l1StandardBridge: {\n [sourceId]: {\n address: \"0x6487446e0B9FAEa90F6a9772A6448cFa780E30F9\",\n },\n },\n quarryPaymaster: {\n address: \"0x7ca1b85aca23fccf2fbac14c02b5e8a6432639b9\",\n },\n },\n blockExplorers: {\n default: {\n name: \"Blockscout\",\n url: \"https://explorer.rhodolitechain.com\",\n },\n worldsExplorer: {\n name: \"MUD Worlds Explorer\",\n url: \"https://explorer.mud.dev/rhodolite/worlds\",\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,SAAS,eAAe;AAGjB,IAAM,aAAa;AAAA,EACxB,GAAG;AAAA,EACH,MAAM;AAAA,IACJ,oBAAoB;AAAA,EACtB;AACF;;;ACRA,SAAS,YAAY,sBAAsB;AAGpC,IAAM,WAAW;AAAA,EACtB,GAAG;AAAA,EACH,UAAU,CAAC,+CAA+C;AAAA,EAC1D,YAAY;AACd;;;ACPA,SAAS,UAAU,oBAAoB;AAGhC,IAAM,SAAS;AAAA,EACpB,GAAG;AAAA,EACH,UAAU,CAAC,6CAA6C;AAAA,EACxD,YAAY;AACd;;;ACPA,SAAS,mBAAmB;AAI5B,IAAM,WAAW;AAEjB,IAAM,iBAAiB;AAAA,EACrB,MAAM,CAAC,gCAAgC;AAAA,EACvC,WAAW,CAAC,8BAA8B;AAC5C;AAEO,IAAM,YAAY;AAAA,EACvB,GAAG;AAAA,EACH,MAAM;AAAA,EACN,SAAS;AAAA,EACT,IAAI;AAAA,EACJ;AAAA,EACA,gBAAgB,EAAE,MAAM,SAAS,QAAQ,OAAO,UAAU,GAAG;AAAA,EAC7D,SAAS;AAAA,IACP,SAAS;AAAA,IACT,SAAS;AAAA,IACT,kBAAkB;AAAA,IAClB,SAAS;AAAA,EACX;AAAA,EACA,WAAW;AAAA,IACT,GAAG,YAAY;AAAA,IACf,kBAAkB;AAAA,MAChB,CAAC,QAAQ,GAAG;AAAA,QACV,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,SAAS;AAAA,IACX;AAAA,EACF;AAAA,EACA,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,MAAM;AAAA,MACN,KAAK;AAAA,IACP;AAAA,IACA,gBAAgB;AAAA,MACd,MAAM;AAAA,MACN,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EACA,UAAU,CAAC,gDAAgD;AAAA,EAC3D,YAAY;AACd;","names":[]}
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\";\nimport { Chain } from \"viem\";\n\nconst sourceId = 17000;\n\nconst defaultRpcUrls = {\n http: [\"https://rpc.rhodolitechain.com\"],\n webSocket: [\"wss://rpc.rhodolitechain.com\"],\n} as const satisfies Chain[\"rpcUrls\"][\"default\"];\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: defaultRpcUrls,\n bundler: defaultRpcUrls,\n quarryPassIssuer: defaultRpcUrls,\n wiresaw: defaultRpcUrls,\n },\n contracts: {\n ...chainConfig.contracts,\n l1StandardBridge: {\n [sourceId]: {\n address: \"0x6487446e0B9FAEa90F6a9772A6448cFa780E30F9\",\n },\n },\n quarryPaymaster: {\n address: \"0x7ca1b85aca23fccf2fbac14c02b5e8a6432639b9\",\n },\n },\n blockExplorers: {\n default: {\n name: \"Blockscout\",\n url: \"https://explorer.rhodolitechain.com\",\n },\n worldsExplorer: {\n name: \"MUD Worlds Explorer\",\n url: \"https://explorer.mud.dev/rhodolite/worlds\",\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,gBAI5B,IAAMC,EAAW,KAEXC,EAAiB,CACrB,KAAM,CAAC,gCAAgC,EACvC,UAAW,CAAC,8BAA8B,CAC5C,EAEaC,EAAY,CACvB,GAAGH,EACH,KAAM,mBACN,QAAS,GACT,GAAI,MACJ,SAAAC,EACA,eAAgB,CAAE,KAAM,QAAS,OAAQ,MAAO,SAAU,EAAG,EAC7D,QAAS,CACP,QAASC,EACT,QAASA,EACT,iBAAkBA,EAClB,QAASA,CACX,EACA,UAAW,CACT,GAAGF,EAAY,UACf,iBAAkB,CAChB,CAACC,CAAQ,EAAG,CACV,QAAS,4CACX,CACF,EACA,gBAAiB,CACf,QAAS,4CACX,CACF,EACA,eAAgB,CACd,QAAS,CACP,KAAM,aACN,IAAK,qCACP,EACA,eAAgB,CACd,KAAM,sBACN,IAAK,2CACP,CACF,EACA,SAAU,CAAC,gDAAgD,EAC3D,WAAY,wCACd","names":["foundry","mudFoundry","redstoneConfig","redstone","garnetConfig","garnet","chainConfig","sourceId","defaultRpcUrls","rhodolite"]}
@@ -0,0 +1,2 @@
1
+ import{a as d}from"./chunk-TCWGPC6G.js";import{getAddress as E}from"viem";import{getChainId as O}from"viem/actions";import{getAction as v}from"viem/utils";async function f({client:e,address:n,blockTag:r}){return`mud:createNonceManager:${e.chain?.id??await v(e,O,"getChainId")({})}:${E(n)}:${r}`}function l(e,n){return n?.(e)?e:e.cause instanceof Error?l(e.cause,n):n?null:e}import{getTransactionCount as I}from"viem/actions";import S from"p-queue";import{getAction as A}from"viem/utils";var R=d.extend("createNonceManager");function T({client:e,address:n,blockTag:r="latest",broadcastChannelName:o,queueConcurrency:a=1}){let t={nonce:-1,noncePromise:null},i=null;typeof BroadcastChannel<"u"&&(o?Promise.resolve(o):f({client:e,address:n,blockTag:r})).then(N=>{i=new BroadcastChannel(N),i.addEventListener("message",m=>{let C=JSON.parse(m.data);R("got nonce from broadcast channel",C),t.nonce=C})});function s(){return t.nonce>=0}function c(){if(!s())throw new Error("call resetNonce before using getNonce");return t.nonce}function g(){if(!s())throw new Error("call resetNonce before using nextNonce");let u=t.nonce++;return i?.postMessage(JSON.stringify(t.nonce)),u}async function b(){t.noncePromise??=(async()=>{t.nonce=await A(e,I,"getTransactionCount")({address:n,blockTag:r}),t.noncePromise=null,i?.postMessage(JSON.stringify(t.nonce)),R("reset nonce to",t.nonce)})(),await t.noncePromise}function M(u){return l(u,({name:m})=>m==="NonceTooLowError"||m==="NonceTooHighError")!=null}let F=new S({concurrency:a});return{hasNonce:s,getNonce:c,nextNonce:g,resetNonce:b,shouldResetNonce:M,mempoolQueue:F}}var h=new Map;async function x({client:e,address:n,blockTag:r="latest",...o}){let a=await f({client:e,address:n,blockTag:r}),t=h.get(a)??T({client:e,address:n,blockTag:r,...o});return h.has(a)||h.set(a,t),t.hasNonce()||await t.resetNonce(),t}import{sendTransaction as H}from"viem/actions";import Q from"p-retry";import{parseAccount as D}from"viem/accounts";import{getChainId as G}from"viem/actions";import{estimateFeesPerGas as q}from"viem/actions";import{getAction as B}from"viem/utils";async function w({client:e,args:n,refreshInterval:r}){let o={fees:{},lastUpdatedTimestamp:0};async function a(){let t=await B(e,q,"estimateFeesPerGas")(n);o.fees=t,o.lastUpdatedTimestamp=Date.now()}return setInterval(a,r),await a(),o}import{getAction as k}from"viem/utils";var y=new Map;async function P(e){let n=e.args?.chain?.id??e.client.chain?.id??await k(e.client,G,"getChainId")({}),r=y.get(n);if(r)return r;let o=await w(e);return y.set(n,o),o}import{getAction as J}from"viem/utils";var p=d.extend("sendTransaction");async function Pe(e,n,r={}){let o=n.account??e.account;if(!o)throw new Error("No account provided");let a=D(o),t=e.chain,i=await x({client:r.publicClient??e,address:a.address,queueConcurrency:r.queueConcurrency}),s=await P({client:r.publicClient??e,refreshInterval:1e4,args:{chain:t}});return await i.mempoolQueue.add(()=>Q(async()=>{let c=i.nextNonce(),g={blockTag:"pending",...s.fees,...n,nonce:c};return p("sending tx to",n.to,"with nonce",c),await J(e,H,"sendTransaction")(g)},{retries:3,onFailedAttempt:async c=>{if(p("failed, resetting nonce"),await i.resetNonce(),i.shouldResetNonce(c)){p("got nonce error, retrying",c.message);return}if(String(c).includes("transaction underpriced")){p("got transaction underpriced error, retrying",c.message);return}throw c}}),{throwOnTimeout:!0})}export{f as a,l as b,T as c,x as d,P as e,Pe as f};
2
+ //# sourceMappingURL=chunk-6FIKI2CG.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/getNonceManagerId.ts","../src/findCause.ts","../src/createNonceManager.ts","../src/getNonceManager.ts","../src/sendTransaction.ts","../src/getFeeRef.ts","../src/createFeeRef.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","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 { 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","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 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 { 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"],"mappings":";;;;;AAAA,SAAgC,kBAAkB;AAClD,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AA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IACjB,kBAAkB,KAAK;AAAA,EACzB,CAAC;AAED,QAAM,SAAS,MAAM,UAAU;AAAA,IAC7B,QAAQ,KAAK,gBAAgB;AAAA,IAC7B,iBAAiB;AAAA,IACjB,MAAM,EAAE,MAAM;AAAA,EAChB,CAAC;AAED,SAAO,MAAM,aAAa,aAAa;AAAA,IACrC,MACE;AAAA,MACE,YAAY;AACV,cAAM,QAAQ,aAAa,UAAU;AACrC,cAAM,SAAS;AAAA;AAAA,UAEb,UAAU;AAAA,UACV,GAAG,OAAO;AAAA,UACV,GAAG;AAAA,UACH;AAAA,QACF;AACA,QAAAA,OAAM,iBAAiB,QAAQ,IAAI,cAAc,KAAK;AACtD,eAAO,MAAMD,WAAU,QAAQ,sBAAsB,iBAAiB,EAAE,MAAe;AAAA,MACzF;AAAA,MACA;AAAA,QACE,SAAS;AAAA,QACT,iBAAiB,OAAO,UAAU;AAEhC,UAAAC,OAAM,yBAAyB;AAC/B,gBAAM,aAAa,WAAW;AAG9B,cAAI,aAAa,iBAAiB,KAAK,GAAG;AACxC,YAAAA,OAAM,6BAA6B,MAAM,OAAO;AAChD;AAAA,UACF;AAEA,cAAI,OAAO,KAAK,EAAE,SAAS,yBAAyB,GAAG;AACrD,YAAAA,OAAM,+CAA+C,MAAM,OAAO;AAClE;AAAA,UACF;AAEA,gBAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,IACF,EAAE,gBAAgB,KAAK;AAAA,EACzB;AACF;","names":["getAction","debug","getAction","getChainId","getAction","getAction","getChainId","getAction","debug"]}
1
+ {"version":3,"sources":["../src/getNonceManagerId.ts","../src/findCause.ts","../src/createNonceManager.ts","../src/getNonceManager.ts","../src/sendTransaction.ts","../src/getFeeRef.ts","../src/createFeeRef.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","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 { 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","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 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 { 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"],"mappings":"wCAAA,OAAgC,cAAAA,MAAkB,OAClD,OAAS,cAAAC,MAAkB,eAC3B,OAAS,aAAAC,MAAiB,aAE1B,eAAsBC,EAAkB,CACtC,OAAAC,EACA,QAAAC,EACA,SAAAC,CACF,EAIoB,CAGlB,MAAO,0BADSF,EAAO,OAAO,IAAO,MAAMF,EAAUE,EAAQH,EAAY,YAAY,EAAE,CAAC,CAAC,CACjD,IAAID,EAAWK,CAAO,CAAC,IAAIC,CAAQ,EAC7E,CChBO,SAASC,EAAUC,EAAcC,EAA8C,CACpF,OAAIA,IAAKD,CAAK,EAAUA,EACpBA,EAAM,iBAAiB,MAAcD,EAAUC,EAAM,MAAOC,CAAE,EAC3DA,EAAK,KAAOD,CACrB,CCDA,OAAS,uBAAAE,MAA2B,eACpC,OAAOC,MAAY,UACnB,OAAS,aAAAC,MAAiB,aAG1B,IAAMC,EAAQA,EAAY,OAAO,oBAAoB,EAmB9C,SAASC,EAAmB,CACjC,OAAAC,EACA,QAAAC,EACA,SAAAC,EAAW,SACX,qBAAAC,EACA,iBAAAC,EAAmB,CACrB,EAAwD,CACtD,IAAMC,EAAM,CAAE,MAAO,GAAI,aAAc,IAA6B,EAChEC,EAAmC,KAEnC,OAAO,iBAAqB,MACVH,EAChB,QAAQ,QAAQA,CAAoB,EACpCI,EAAkB,CAAE,OAAAP,EAAQ,QAAAC,EAAS,SAAAC,CAAS,CAAC,GACvC,KAAMM,GAAS,CACzBF,EAAU,IAAI,iBAAiBE,CAAI,EAEnCF,EAAQ,iBAAiB,UAAYG,GAAU,CAC7C,IAAMC,EAAQ,KAAK,MAAMD,EAAM,IAAI,EACnCX,EAAM,mCAAoCY,CAAK,EAC/CL,EAAI,MAAQK,CACd,CAAC,CACH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AAUC,EAAaF,CAAU,EACjCG,EAAQN,EAAO,MAEfO,EAAe,MAAMC,EAAgB,CACzC,OAAQN,EAAK,cAAgBF,EAC7B,QAASI,EAAQ,QACjB,iBAAkBF,EAAK,gBACzB,CAAC,EAEKO,EAAS,MAAMC,EAAU,CAC7B,OAAQR,EAAK,cAAgBF,EAC7B,gBAAiB,IACjB,KAAM,CAAE,MAAAM,CAAM,CAChB,CAAC,EAED,OAAO,MAAMC,EAAa,aAAa,IACrC,IACEI,EACE,SAAY,CACV,IAAMC,EAAQL,EAAa,UAAU,EAC/BM,EAAS,CAEb,SAAU,UACV,GAAGJ,EAAO,KACV,GAAGR,EACH,MAAAW,CACF,EACA,OAAAd,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,MACF,CAEA,GAAI,OAAOA,CAAK,EAAE,SAAS,yBAAyB,EAAG,CACrDjB,EAAM,8CAA+CiB,EAAM,OAAO,EAClE,MACF,CAEA,MAAMA,CACR,CACF,CACF,EACF,CAAE,eAAgB,EAAK,CACzB,CACF","names":["getAddress","getChainId","getAction","getNonceManagerId","client","address","blockTag","findCause","error","fn","getTransactionCount","PQueue","getAction","debug","createNonceManager","client","address","blockTag","broadcastChannelName","queueConcurrency","ref","channel","getNonceManagerId","name","event","nonce","hasNonce","getNonce","nextNonce","resetNonce","getAction","getTransactionCount","shouldResetNonce","error","findCause","mempoolQueue","PQueue","nonceManagers","getNonceManager","client","address","blockTag","opts","id","getNonceManagerId","nonceManager","createNonceManager","viem_sendTransaction","pRetry","parseAccount","getChainId","estimateFeesPerGas","getAction","createFeeRef","client","args","refreshInterval","feeRef","updateFees","fees","getAction","feeRefs","getFeeRef","opts","chainId","getChainId","existingFeeRef","feeRef","createFeeRef","getAction","debug","sendTransaction","client","request","opts","rawAccount","account","parseAccount","chain","nonceManager","getNonceManager","feeRef","getFeeRef","pRetry","nonce","params","viem_sendTransaction","error"]}
@@ -0,0 +1,2 @@
1
+ import{d as u,e as d}from"./chunk-6FIKI2CG.js";import{a as s}from"./chunk-TCWGPC6G.js";import{writeContract as f}from"viem/actions";import g from"p-retry";import{parseAccount as h}from"viem/accounts";import{getAction as l}from"viem/utils";var r=s.extend("writeContract");async function T(e,c,a={}){let i=c.account??e.account;if(!i)throw new Error("No account provided");let m=h(i),p=e.chain,t=await u({client:a.publicClient??e,address:m.address,queueConcurrency:a.queueConcurrency}),C=await d({client:a.publicClient??e,refreshInterval:1e4,args:{chain:p}});return t.mempoolQueue.add(()=>g(async()=>{let n=t.nextNonce(),o={blockTag:"pending",...C.fees,...c,nonce:n};return r("calling",o.functionName,"at",o.address,"with nonce",n),await l(e,f,"writeContract")(o)},{retries:3,onFailedAttempt:async n=>{if(r("failed, resetting nonce"),await t.resetNonce(),t.shouldResetNonce(n)){r("got nonce error, retrying",n.message);return}if(String(n).includes("transaction underpriced")){r("got transaction underpriced error, retrying",n.message);return}throw n}}),{throwOnTimeout:!0})}export{T as a};
2
+ //# sourceMappingURL=chunk-DPUUE7NM.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/writeContract.ts"],"sourcesContent":["import {\n Abi,\n Account,\n Chain,\n Client,\n Transport,\n WriteContractParameters,\n WriteContractReturnType,\n ContractFunctionName,\n ContractFunctionArgs,\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?: 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 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"],"mappings":";;;;;;;;;AAWA,SAAS,iBAAiB,0BAA0B;AACpD,OAAO,YAAY;AAGnB,SAAS,oBAAoB;AAE7B,SAAS,iBAAiB;AAE1B,IAAMA,SAAQ,MAAY,OAAO,eAAe;AAoBhD,eAAsB,cAQpB,QACA,SACA,OAAyC,CAAC,GACR;AAClC,QAAM,aAAa,QAAQ,WAAW,OAAO;AAC7C,MAAI,CAAC,YAAY;AAEf,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AACA,QAAM,UAAU,aAAa,UAAU;AACvC,QAAM,QAAQ,OAAO;AAErB,QAAM,eAAe,MAAM,gBAAgB;AAAA,IACzC,QAAQ,KAAK,gBAAgB;AAAA,IAC7B,SAAS,QAAQ;AAAA,IACjB,kBAAkB,KAAK;AAAA,EACzB,CAAC;AAED,QAAM,SAAS,MAAM,UAAU;AAAA,IAC7B,QAAQ,KAAK,gBAAgB;AAAA,IAC7B,iBAAiB;AAAA,IACjB,MAAM,EAAE,MAAM;AAAA,EAChB,CAAC;AAED,SAAO,aAAa,aAAa;AAAA,IAC/B,MACE;AAAA,MACE,YAAY;AACV,cAAM,QAAQ,aAAa,UAAU;AACrC,cAAM,SAAS;AAAA;AAAA,UAEb,UAAU;AAAA,UACV,GAAG,OAAO;AAAA,UACV,GAAG;AAAA,UACH;AAAA,QACF;AACA,QAAAA,OAAM,WAAW,OAAO,cAAc,MAAM,OAAO,SAAS,cAAc,KAAK;AAC/E,eAAO,MAAM,UAAU,QAAQ,oBAAoB,eAAe,EAAE,MAAe;AAAA,MACrF;AAAA,MACA;AAAA,QACE,SAAS;AAAA,QACT,iBAAiB,OAAO,UAAU;AAEhC,UAAAA,OAAM,yBAAyB;AAC/B,gBAAM,aAAa,WAAW;AAG9B,cAAI,aAAa,iBAAiB,KAAK,GAAG;AACxC,YAAAA,OAAM,6BAA6B,MAAM,OAAO;AAChD;AAAA,UACF;AAEA,cAAI,OAAO,KAAK,EAAE,SAAS,yBAAyB,GAAG;AACrD,YAAAA,OAAM,+CAA+C,MAAM,OAAO;AAClE;AAAA,UACF;AAEA,gBAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,IACF,EAAE,gBAAgB,KAAK;AAAA,EACzB;AACF;","names":["debug"]}
1
+ {"version":3,"sources":["../src/writeContract.ts"],"sourcesContent":["import {\n Abi,\n Account,\n Chain,\n Client,\n Transport,\n WriteContractParameters,\n WriteContractReturnType,\n ContractFunctionName,\n ContractFunctionArgs,\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?: 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 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"],"mappings":"uFAWA,OAAS,iBAAiBA,MAA0B,eACpD,OAAOC,MAAY,UAGnB,OAAS,gBAAAC,MAAoB,gBAE7B,OAAS,aAAAC,MAAiB,aAE1B,IAAMC,EAAQA,EAAY,OAAO,eAAe,EAoBhD,eAAsBC,EAQpBC,EACAC,EACAC,EAAyC,CAAC,EACR,CAClC,IAAMC,EAAaF,EAAQ,SAAWD,EAAO,QAC7C,GAAI,CAACG,EAEH,MAAM,IAAI,MAAM,qBAAqB,EAEvC,IAAMC,EAAUC,EAAaF,CAAU,EACjCG,EAAQN,EAAO,MAEfO,EAAe,MAAMC,EAAgB,CACzC,OAAQN,EAAK,cAAgBF,EAC7B,QAASI,EAAQ,QACjB,iBAAkBF,EAAK,gBACzB,CAAC,EAEKO,EAAS,MAAMC,EAAU,CAC7B,OAAQR,EAAK,cAAgBF,EAC7B,gBAAiB,IACjB,KAAM,CAAE,MAAAM,CAAM,CAChB,CAAC,EAED,OAAOC,EAAa,aAAa,IAC/B,IACEI,EACE,SAAY,CACV,IAAMC,EAAQL,EAAa,UAAU,EAC/BM,EAAS,CAEb,SAAU,UACV,GAAGJ,EAAO,KACV,GAAGR,EACH,MAAAW,CACF,EACA,OAAAd,EAAM,UAAWe,EAAO,aAAc,KAAMA,EAAO,QAAS,aAAcD,CAAK,EACxE,MAAMf,EAAUG,EAAQc,EAAoB,eAAe,EAAED,CAAe,CACrF,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,MACF,CAEA,GAAI,OAAOA,CAAK,EAAE,SAAS,yBAAyB,EAAG,CACrDjB,EAAM,8CAA+CiB,EAAM,OAAO,EAClE,MACF,CAEA,MAAMA,CACR,CACF,CACF,EACF,CAAE,eAAgB,EAAK,CACzB,CACF","names":["viem_writeContract","pRetry","parseAccount","getAction","debug","writeContract","client","request","opts","rawAccount","account","parseAccount","chain","nonceManager","getNonceManager","feeRef","getFeeRef","pRetry","nonce","params","viem_writeContract","error"]}
@@ -0,0 +1,2 @@
1
+ var r=class extends Error{constructor(){super(...arguments);this.name="MUDError"}};export{r as a};
2
+ //# sourceMappingURL=chunk-QQCZY3XJ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors/MUDError.ts"],"sourcesContent":["export class MUDError extends Error {\n name = \"MUDError\";\n}\n"],"mappings":";AAAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAA7B;AAAA;AACL,gBAAO;AAAA;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/errors/MUDError.ts"],"sourcesContent":["export class MUDError extends Error {\n name = \"MUDError\";\n}\n"],"mappings":"AAAO,IAAMA,EAAN,cAAuB,KAAM,CAA7B,kCACL,UAAO,WACT","names":["MUDError"]}
@@ -0,0 +1,2 @@
1
+ import o from"debug";var e=o("mud:common"),r=o("mud:common");e.log=console.debug.bind(console);r.log=console.error.bind(console);export{e as a};
2
+ //# sourceMappingURL=chunk-TCWGPC6G.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/debug.ts"],"sourcesContent":["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"],"mappings":";AAAA,OAAO,iBAAiB;AAEjB,IAAM,QAAQ,YAAY,YAAY;AACtC,IAAM,QAAQ,YAAY,YAAY;AAG7C,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO;AAGtC,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO;","names":[]}
1
+ {"version":3,"sources":["../src/debug.ts"],"sourcesContent":["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"],"mappings":"AAAA,OAAOA,MAAiB,QAEjB,IAAMC,EAAQD,EAAY,YAAY,EAChCE,EAAQF,EAAY,YAAY,EAG7CC,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO,EAGtCC,EAAM,IAAM,QAAQ,MAAM,KAAK,OAAO","names":["createDebug","debug","error"]}
@@ -0,0 +1,2 @@
1
+ var m=["table","offchainTable","namespace","system"];import{stringToHex as s,concatHex as u}from"viem";var o={table:"tb",offchainTable:"ot",namespace:"ns",system:"sy"};function x(e){let r=o[e.type];if(e.namespace.length>14)throw new Error(`Namespaces must fit into \`bytes14\`, but "${e.namespace}" is too long.`);return u([s(r,{size:2}),s(e.namespace,{size:14}),s(e.name.slice(0,16),{size:16})])}var y="";function i({namespace:e,name:r}){return e===y?r:`${e}__${r}`}import{hexToString as t,sliceHex as n}from"viem";var f=Object.fromEntries(Object.entries(o).map(([e,r])=>[r,e]));function T(e){let r=f[e];if(m.includes(r))return r}function _(e){let r=t(n(e,0,2)).replace(/\0+$/,""),c=T(r),a=t(n(e,2,16)).replace(/\0+$/,""),p=t(n(e,16,32)).replace(/\0+$/,"");if(!c)throw new Error(`Unknown type (${r}) for resource (${i({namespace:a,name:p})})`);return{resourceId:e,type:c,namespace:a,name:p}}export{m as a,o as b,x as c,i as d,_ as e};
2
+ //# sourceMappingURL=chunk-ZIUX7JCQ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/resourceTypes.ts","../src/resourceToHex.ts","../src/resourceToLabel.ts","../src/hexToResource.ts"],"sourcesContent":["export const resourceTypes = [\"table\", \"offchainTable\", \"namespace\", \"system\"] as const;\n\nexport type ResourceType = (typeof resourceTypes)[number];\n","import { Hex, stringToHex, concatHex } from \"viem\";\nimport { Resource } from \"./common\";\nimport { ResourceType } from \"./resourceTypes\";\n\n/** @internal */\nexport const resourceTypeIds = {\n // keep these in sync with storeResourceTypes.sol\n table: \"tb\",\n offchainTable: \"ot\",\n // keep these in sync with worldResourceTypes.sol\n namespace: \"ns\",\n system: \"sy\",\n} as const satisfies Record<ResourceType, string>;\n\nexport function resourceToHex(resource: Omit<Resource, \"resourceId\">): Hex {\n const typeId = resourceTypeIds[resource.type];\n // Because namespaces are tied to access control, it's not safe to automatically truncate. Instead, we'll throw an error.\n if (resource.namespace.length > 14) {\n throw new Error(`Namespaces must fit into \\`bytes14\\`, but \"${resource.namespace}\" is too long.`);\n }\n return concatHex([\n stringToHex(typeId, { size: 2 }),\n stringToHex(resource.namespace, { size: 14 }),\n stringToHex(resource.name.slice(0, 16), { size: 16 }),\n ]);\n}\n","const rootNamespace = \"\";\n\nexport type ResourceLabel<\n namespace extends string = string,\n name extends string = string,\n> = namespace extends typeof rootNamespace ? name : `${namespace}__${name}`;\n\nexport function resourceToLabel<namespace extends string, name extends string>({\n namespace,\n name,\n}: {\n readonly namespace: namespace;\n readonly name: name;\n}): ResourceLabel<namespace, name> {\n return (namespace === rootNamespace ? name : `${namespace}__${name}`) as ResourceLabel<namespace, name>;\n}\n","import { Hex, hexToString, sliceHex } from \"viem\";\nimport { Resource } from \"./common\";\nimport { ResourceType, resourceTypes } from \"./resourceTypes\";\nimport { resourceTypeIds } from \"./resourceToHex\";\nimport { ReverseMap } from \"./type-utils/common\";\nimport { resourceToLabel } from \"./resourceToLabel\";\n\nconst resourceTypeIdToType = Object.fromEntries(\n Object.entries(resourceTypeIds).map(([key, value]) => [value, key]),\n) as ReverseMap<typeof resourceTypeIds>;\n\nfunction getResourceType(resourceTypeId: string): ResourceType | undefined {\n // TODO: replace Partial with `noUncheckedIndexedAccess`\n const type = (resourceTypeIdToType as Partial<Record<string, ResourceType>>)[resourceTypeId];\n if (resourceTypes.includes(type as ResourceType)) {\n return type;\n }\n}\n\nexport function hexToResource(hex: Hex): Resource {\n const resourceTypeId = hexToString(sliceHex(hex, 0, 2)).replace(/\\0+$/, \"\");\n const type = getResourceType(resourceTypeId);\n const namespace = hexToString(sliceHex(hex, 2, 16)).replace(/\\0+$/, \"\");\n const name = hexToString(sliceHex(hex, 16, 32)).replace(/\\0+$/, \"\");\n\n if (!type) {\n throw new Error(`Unknown type (${resourceTypeId}) for resource (${resourceToLabel({ namespace, name })})`);\n }\n\n return { resourceId: hex, type, namespace, name };\n}\n"],"mappings":";AAAO,IAAM,gBAAgB,CAAC,SAAS,iBAAiB,aAAa,QAAQ;;;ACA7E,SAAc,aAAa,iBAAiB;AAKrC,IAAM,kBAAkB;AAAA;AAAA,EAE7B,OAAO;AAAA,EACP,eAAe;AAAA;AAAA,EAEf,WAAW;AAAA,EACX,QAAQ;AACV;AAEO,SAAS,cAAc,UAA6C;AACzE,QAAM,SAAS,gBAAgB,SAAS,IAAI;AAE5C,MAAI,SAAS,UAAU,SAAS,IAAI;AAClC,UAAM,IAAI,MAAM,8CAA8C,SAAS,SAAS,gBAAgB;AAAA,EAClG;AACA,SAAO,UAAU;AAAA,IACf,YAAY,QAAQ,EAAE,MAAM,EAAE,CAAC;AAAA,IAC/B,YAAY,SAAS,WAAW,EAAE,MAAM,GAAG,CAAC;AAAA,IAC5C,YAAY,SAAS,KAAK,MAAM,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC;AAAA,EACtD,CAAC;AACH;;;ACzBA,IAAM,gBAAgB;AAOf,SAAS,gBAA+D;AAAA,EAC7E;AAAA,EACA;AACF,GAGmC;AACjC,SAAQ,cAAc,gBAAgB,OAAO,GAAG,SAAS,KAAK,IAAI;AACpE;;;ACfA,SAAc,aAAa,gBAAgB;AAO3C,IAAM,uBAAuB,OAAO;AAAA,EAClC,OAAO,QAAQ,eAAe,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,OAAO,GAAG,CAAC;AACpE;AAEA,SAAS,gBAAgB,gBAAkD;AAEzE,QAAM,OAAQ,qBAA+D,cAAc;AAC3F,MAAI,cAAc,SAAS,IAAoB,GAAG;AAChD,WAAO;AAAA,EACT;AACF;AAEO,SAAS,cAAc,KAAoB;AAChD,QAAM,iBAAiB,YAAY,SAAS,KAAK,GAAG,CAAC,CAAC,EAAE,QAAQ,QAAQ,EAAE;AAC1E,QAAM,OAAO,gBAAgB,cAAc;AAC3C,QAAM,YAAY,YAAY,SAAS,KAAK,GAAG,EAAE,CAAC,EAAE,QAAQ,QAAQ,EAAE;AACtE,QAAM,OAAO,YAAY,SAAS,KAAK,IAAI,EAAE,CAAC,EAAE,QAAQ,QAAQ,EAAE;AAElE,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,iBAAiB,cAAc,mBAAmB,gBAAgB,EAAE,WAAW,KAAK,CAAC,CAAC,GAAG;AAAA,EAC3G;AAEA,SAAO,EAAE,YAAY,KAAK,MAAM,WAAW,KAAK;AAClD;","names":[]}
1
+ {"version":3,"sources":["../src/resourceTypes.ts","../src/resourceToHex.ts","../src/resourceToLabel.ts","../src/hexToResource.ts"],"sourcesContent":["export const resourceTypes = [\"table\", \"offchainTable\", \"namespace\", \"system\"] as const;\n\nexport type ResourceType = (typeof resourceTypes)[number];\n","import { Hex, stringToHex, concatHex } from \"viem\";\nimport { Resource } from \"./common\";\nimport { ResourceType } from \"./resourceTypes\";\n\n/** @internal */\nexport const resourceTypeIds = {\n // keep these in sync with storeResourceTypes.sol\n table: \"tb\",\n offchainTable: \"ot\",\n // keep these in sync with worldResourceTypes.sol\n namespace: \"ns\",\n system: \"sy\",\n} as const satisfies Record<ResourceType, string>;\n\nexport function resourceToHex(resource: Omit<Resource, \"resourceId\">): Hex {\n const typeId = resourceTypeIds[resource.type];\n // Because namespaces are tied to access control, it's not safe to automatically truncate. Instead, we'll throw an error.\n if (resource.namespace.length > 14) {\n throw new Error(`Namespaces must fit into \\`bytes14\\`, but \"${resource.namespace}\" is too long.`);\n }\n return concatHex([\n stringToHex(typeId, { size: 2 }),\n stringToHex(resource.namespace, { size: 14 }),\n stringToHex(resource.name.slice(0, 16), { size: 16 }),\n ]);\n}\n","const rootNamespace = \"\";\n\nexport type ResourceLabel<\n namespace extends string = string,\n name extends string = string,\n> = namespace extends typeof rootNamespace ? name : `${namespace}__${name}`;\n\nexport function resourceToLabel<namespace extends string, name extends string>({\n namespace,\n name,\n}: {\n readonly namespace: namespace;\n readonly name: name;\n}): ResourceLabel<namespace, name> {\n return (namespace === rootNamespace ? name : `${namespace}__${name}`) as ResourceLabel<namespace, name>;\n}\n","import { Hex, hexToString, sliceHex } from \"viem\";\nimport { Resource } from \"./common\";\nimport { ResourceType, resourceTypes } from \"./resourceTypes\";\nimport { resourceTypeIds } from \"./resourceToHex\";\nimport { ReverseMap } from \"./type-utils/common\";\nimport { resourceToLabel } from \"./resourceToLabel\";\n\nconst resourceTypeIdToType = Object.fromEntries(\n Object.entries(resourceTypeIds).map(([key, value]) => [value, key]),\n) as ReverseMap<typeof resourceTypeIds>;\n\nfunction getResourceType(resourceTypeId: string): ResourceType | undefined {\n // TODO: replace Partial with `noUncheckedIndexedAccess`\n const type = (resourceTypeIdToType as Partial<Record<string, ResourceType>>)[resourceTypeId];\n if (resourceTypes.includes(type as ResourceType)) {\n return type;\n }\n}\n\nexport function hexToResource(hex: Hex): Resource {\n const resourceTypeId = hexToString(sliceHex(hex, 0, 2)).replace(/\\0+$/, \"\");\n const type = getResourceType(resourceTypeId);\n const namespace = hexToString(sliceHex(hex, 2, 16)).replace(/\\0+$/, \"\");\n const name = hexToString(sliceHex(hex, 16, 32)).replace(/\\0+$/, \"\");\n\n if (!type) {\n throw new Error(`Unknown type (${resourceTypeId}) for resource (${resourceToLabel({ namespace, name })})`);\n }\n\n return { resourceId: hex, type, namespace, name };\n}\n"],"mappings":"AAAO,IAAMA,EAAgB,CAAC,QAAS,gBAAiB,YAAa,QAAQ,ECA7E,OAAc,eAAAC,EAA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D,CAAc,mBAAmBS,EAAgB,CAAE,UAAAF,EAAW,KAAAC,CAAK,CAAC,CAAC,GAAG,EAG3G,MAAO,CAAE,WAAYJ,EAAK,KAAAH,EAAM,UAAAM,EAAW,KAAAC,CAAK,CAClD","names":["resourceTypes","stringToHex","concatHex","resourceTypeIds","resourceToHex","resource","typeId","rootNamespace","resourceToLabel","namespace","name","hexToString","sliceHex","resourceTypeIdToType","resourceTypeIds","key","value","getResourceType","resourceTypeId","type","resourceTypes","hexToResource","hex","hexToString","sliceHex","namespace","name","resourceToLabel"]}
@@ -0,0 +1,2 @@
1
+ function o(l,n){let e=new Map;for(let a of l){let u=n(a);e.has(u)||e.set(u,a)}return Array.from(e.values())}export{o as a};
2
+ //# sourceMappingURL=chunk-ZV2KGJCD.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/uniqueBy.ts"],"sourcesContent":["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"],"mappings":";AAAO,SAAS,SAAqB,QAA0B,QAAiD;AAC9G,QAAM,MAAM,oBAAI,IAAgB;AAChC,aAAW,SAAS,QAAQ;AAC1B,UAAM,MAAM,OAAO,KAAK;AACxB,QAAI,CAAC,IAAI,IAAI,GAAG,GAAG;AACjB,UAAI,IAAI,KAAK,KAAK;AAAA,IACpB;AAAA,EACF;AACA,SAAO,MAAM,KAAK,IAAI,OAAO,CAAC;AAChC;","names":[]}
1
+ {"version":3,"sources":["../src/utils/uniqueBy.ts"],"sourcesContent":["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"],"mappings":"AAAO,SAASA,EAAqBC,EAA0BC,EAAiD,CAC9G,IAAMC,EAAM,IAAI,IAChB,QAAWC,KAASH,EAAQ,CAC1B,IAAMI,EAAMH,EAAOE,CAAK,EACnBD,EAAI,IAAIE,CAAG,GACdF,EAAI,IAAIE,EAAKD,CAAK,CAEtB,CACA,OAAO,MAAM,KAAKD,EAAI,OAAO,CAAC,CAChC","names":["uniqueBy","values","getKey","map","value","key"]}