From c4e1ee54de5c2d5d8f83597c9066a7d77008375b Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Thu, 22 Jun 2023 18:56:56 +0100 Subject: [PATCH] back to viem 1.1.1 --- e2e/packages/client-vanilla/package.json | 2 +- e2e/pnpm-lock.yaml | 14 +-- .../packages/client-phaser/package.json | 2 +- .../packages/client-react/package.json | 2 +- .../packages/client-vanilla/package.json | 2 +- examples/minimal/pnpm-lock.yaml | 32 +++---- packages/block-events-stream/dist/index.js | 2 + .../block-events-stream/dist/index.js.map | 1 + .../block-events-stream/dist/src/common.d.ts | 13 +++ .../block-events-stream/dist/src/common.js | 2 + .../dist/src/common.js.map | 1 + .../dist/src/createBlockEventsStream.d.ts | 13 +++ .../dist/src/createBlockEventsStream.js | 88 +++++++++++++++++++ .../dist/src/createBlockEventsStream.js.map | 1 + .../dist/src/createBlockNumberStream.d.ts | 12 +++ .../dist/src/createBlockNumberStream.js | 24 +++++ .../dist/src/createBlockNumberStream.js.map | 1 + .../dist/src/createBlockStream.d.ts | 7 ++ .../dist/src/createBlockStream.js | 26 ++++++ .../dist/src/createBlockStream.js.map | 1 + .../block-events-stream/dist/src/debug.d.ts | 2 + .../block-events-stream/dist/src/debug.js | 3 + .../block-events-stream/dist/src/debug.js.map | 1 + .../block-events-stream/dist/src/getLogs.d.ts | 11 +++ .../block-events-stream/dist/src/getLogs.js | 34 +++++++ .../dist/src/getLogs.js.map | 1 + .../block-events-stream/dist/src/index.d.ts | 4 + .../block-events-stream/dist/src/index.js | 5 ++ .../block-events-stream/dist/src/index.js.map | 1 + .../dist/src/isNonPendingBlock.d.ts | 8 ++ .../dist/src/isNonPendingBlock.js | 4 + .../dist/src/isNonPendingBlock.js.map | 1 + .../dist/src/isNonPendingLog.d.ts | 9 ++ .../dist/src/isNonPendingLog.js | 8 ++ .../dist/src/isNonPendingLog.js.map | 1 + .../block-events-stream/dist/src/utils.d.ts | 2 + .../block-events-stream/dist/src/utils.js | 7 ++ .../block-events-stream/dist/src/utils.js.map | 1 + .../block-events-stream/dist/tsup.config.d.ts | 2 + .../block-events-stream/dist/tsup.config.js | 11 +++ .../dist/tsup.config.js.map | 1 + packages/block-events-stream/package.json | 44 ++++++++++ packages/common/package.json | 2 +- packages/dev-tools/package.json | 2 +- packages/network/package.json | 2 +- packages/protocol-parser/package.json | 2 +- packages/schema-type/package.json | 2 +- packages/std-client/package.json | 2 +- pnpm-lock.yaml | 81 ++++++++++++----- 49 files changed, 445 insertions(+), 55 deletions(-) create mode 100644 packages/block-events-stream/dist/index.js create mode 100644 packages/block-events-stream/dist/index.js.map create mode 100644 packages/block-events-stream/dist/src/common.d.ts create mode 100644 packages/block-events-stream/dist/src/common.js create mode 100644 packages/block-events-stream/dist/src/common.js.map create mode 100644 packages/block-events-stream/dist/src/createBlockEventsStream.d.ts create mode 100644 packages/block-events-stream/dist/src/createBlockEventsStream.js create mode 100644 packages/block-events-stream/dist/src/createBlockEventsStream.js.map create mode 100644 packages/block-events-stream/dist/src/createBlockNumberStream.d.ts create mode 100644 packages/block-events-stream/dist/src/createBlockNumberStream.js create mode 100644 packages/block-events-stream/dist/src/createBlockNumberStream.js.map create mode 100644 packages/block-events-stream/dist/src/createBlockStream.d.ts create mode 100644 packages/block-events-stream/dist/src/createBlockStream.js create mode 100644 packages/block-events-stream/dist/src/createBlockStream.js.map create mode 100644 packages/block-events-stream/dist/src/debug.d.ts create mode 100644 packages/block-events-stream/dist/src/debug.js create mode 100644 packages/block-events-stream/dist/src/debug.js.map create mode 100644 packages/block-events-stream/dist/src/getLogs.d.ts create mode 100644 packages/block-events-stream/dist/src/getLogs.js create mode 100644 packages/block-events-stream/dist/src/getLogs.js.map create mode 100644 packages/block-events-stream/dist/src/index.d.ts create mode 100644 packages/block-events-stream/dist/src/index.js create mode 100644 packages/block-events-stream/dist/src/index.js.map create mode 100644 packages/block-events-stream/dist/src/isNonPendingBlock.d.ts create mode 100644 packages/block-events-stream/dist/src/isNonPendingBlock.js create mode 100644 packages/block-events-stream/dist/src/isNonPendingBlock.js.map create mode 100644 packages/block-events-stream/dist/src/isNonPendingLog.d.ts create mode 100644 packages/block-events-stream/dist/src/isNonPendingLog.js create mode 100644 packages/block-events-stream/dist/src/isNonPendingLog.js.map create mode 100644 packages/block-events-stream/dist/src/utils.d.ts create mode 100644 packages/block-events-stream/dist/src/utils.js create mode 100644 packages/block-events-stream/dist/src/utils.js.map create mode 100644 packages/block-events-stream/dist/tsup.config.d.ts create mode 100644 packages/block-events-stream/dist/tsup.config.js create mode 100644 packages/block-events-stream/dist/tsup.config.js.map create mode 100644 packages/block-events-stream/package.json diff --git a/e2e/packages/client-vanilla/package.json b/e2e/packages/client-vanilla/package.json index 52ca878487..0643aa281e 100644 --- a/e2e/packages/client-vanilla/package.json +++ b/e2e/packages/client-vanilla/package.json @@ -33,7 +33,7 @@ "react": "^18.2.0", "rxjs": "7.5.5", "threads": "^1.7.0", - "viem": "1.1.4" + "viem": "1.1.1" }, "devDependencies": { "rimraf": "^3.0.2", diff --git a/e2e/pnpm-lock.yaml b/e2e/pnpm-lock.yaml index 60efbf9489..0f55b26c19 100644 --- a/e2e/pnpm-lock.yaml +++ b/e2e/pnpm-lock.yaml @@ -80,8 +80,8 @@ importers: specifier: ^1.7.0 version: 1.7.0 viem: - specifier: 1.1.4 - version: 1.1.4(typescript@5.1.3) + specifier: 1.1.1 + version: 1.1.1(typescript@5.1.3) devDependencies: rimraf: specifier: ^3.0.2 @@ -889,8 +889,8 @@ packages: typescript: 5.1.3 dev: false - /@wagmi/chains@1.2.0(typescript@5.1.3): - resolution: {integrity: sha512-dmDRipsE54JfyudOBkuhEexqQWcrZqxn/qiujG8SBzMh/az/AH5xlJSA+j1CPWTx9+QofSMF3B7A4gb6XRmSaQ==} + /@wagmi/chains@1.1.0(typescript@5.1.3): + resolution: {integrity: sha512-pWZlxBk0Ql8E7DV8DwqlbBpOyUdaG9UDlQPBxJNALuEK1I0tbQ3AVvSDnlsEIt06UPmPo5o27gzs3hwPQ/A+UA==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: @@ -2203,8 +2203,8 @@ packages: hasBin: true dev: true - /viem@1.1.4(typescript@5.1.3): - resolution: {integrity: sha512-3bJkS60Sw6Rf6a2ydKDnDxAI0PTZK0yGoyux2nqPSBoXBL+w9hXPNcnm8Uf6FlKce5sQadVRfi2n6MrgzablxA==} + /viem@1.1.1(typescript@5.1.3): + resolution: {integrity: sha512-RVwDpDQYngaXRWnP3ZfmKHSis7ojN4q46mOApGRlfGrS/p56UD7/hA35zYxeq+X0dwVhCNhWuIqtV9XSsMtVfg==} peerDependencies: typescript: '>=5.0.4' dependencies: @@ -2213,7 +2213,7 @@ packages: '@noble/hashes': 1.3.0 '@scure/bip32': 1.3.0 '@scure/bip39': 1.2.0 - '@wagmi/chains': 1.2.0(typescript@5.1.3) + '@wagmi/chains': 1.1.0(typescript@5.1.3) abitype: 0.8.7(typescript@5.1.3) isomorphic-ws: 5.0.0(ws@8.12.0) typescript: 5.1.3 diff --git a/examples/minimal/packages/client-phaser/package.json b/examples/minimal/packages/client-phaser/package.json index b9cdbacddd..0a7282d5f0 100644 --- a/examples/minimal/packages/client-phaser/package.json +++ b/examples/minimal/packages/client-phaser/package.json @@ -39,7 +39,7 @@ "styled-components": "^5.3.10", "threads": "^1.7.0", "use-resize-observer": "^9.1.0", - "viem": "1.1.4", + "viem": "1.1.1", "vite": "^4.2.1", "zustand": "^4.3.8" }, diff --git a/examples/minimal/packages/client-react/package.json b/examples/minimal/packages/client-react/package.json index 3be8acd517..f0dabe702d 100644 --- a/examples/minimal/packages/client-react/package.json +++ b/examples/minimal/packages/client-react/package.json @@ -35,7 +35,7 @@ "react-dom": "^18.2.0", "rxjs": "7.5.5", "threads": "^1.7.0", - "viem": "1.1.4" + "viem": "1.1.1" }, "devDependencies": { "@types/react": "^18.2.6", diff --git a/examples/minimal/packages/client-vanilla/package.json b/examples/minimal/packages/client-vanilla/package.json index 0409d3dda1..d430585a8a 100644 --- a/examples/minimal/packages/client-vanilla/package.json +++ b/examples/minimal/packages/client-vanilla/package.json @@ -33,7 +33,7 @@ "react": "^18.2.0", "rxjs": "7.5.5", "threads": "^1.7.0", - "viem": "1.1.4" + "viem": "1.1.1" }, "devDependencies": { "vite": "^4.2.1", diff --git a/examples/minimal/pnpm-lock.yaml b/examples/minimal/pnpm-lock.yaml index e1b7d13dbe..76ee7d21a4 100644 --- a/examples/minimal/pnpm-lock.yaml +++ b/examples/minimal/pnpm-lock.yaml @@ -114,8 +114,8 @@ importers: specifier: ^9.1.0 version: 9.1.0(react-dom@18.2.0)(react@18.2.0) viem: - specifier: 1.1.4 - version: 1.1.4(typescript@4.9.5) + specifier: 1.1.1 + version: 1.1.1(typescript@4.9.5) vite: specifier: ^4.2.1 version: 4.2.1 @@ -226,8 +226,8 @@ importers: specifier: ^1.7.0 version: 1.7.0 viem: - specifier: 1.1.4 - version: 1.1.4(typescript@5.0.4) + specifier: 1.1.1 + version: 1.1.1(typescript@5.0.4) devDependencies: '@types/react': specifier: ^18.2.6 @@ -323,8 +323,8 @@ importers: specifier: ^1.7.0 version: 1.7.0 viem: - specifier: 1.1.4 - version: 1.1.4(typescript@5.0.4) + specifier: 1.1.1 + version: 1.1.1(typescript@5.0.4) devDependencies: vite: specifier: ^4.2.1 @@ -1660,8 +1660,8 @@ packages: typescript: 5.0.4 dev: false - /@wagmi/chains@1.2.0(typescript@4.9.5): - resolution: {integrity: sha512-dmDRipsE54JfyudOBkuhEexqQWcrZqxn/qiujG8SBzMh/az/AH5xlJSA+j1CPWTx9+QofSMF3B7A4gb6XRmSaQ==} + /@wagmi/chains@1.1.0(typescript@4.9.5): + resolution: {integrity: sha512-pWZlxBk0Ql8E7DV8DwqlbBpOyUdaG9UDlQPBxJNALuEK1I0tbQ3AVvSDnlsEIt06UPmPo5o27gzs3hwPQ/A+UA==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: @@ -1671,8 +1671,8 @@ packages: typescript: 4.9.5 dev: false - /@wagmi/chains@1.2.0(typescript@5.0.4): - resolution: {integrity: sha512-dmDRipsE54JfyudOBkuhEexqQWcrZqxn/qiujG8SBzMh/az/AH5xlJSA+j1CPWTx9+QofSMF3B7A4gb6XRmSaQ==} + /@wagmi/chains@1.1.0(typescript@5.0.4): + resolution: {integrity: sha512-pWZlxBk0Ql8E7DV8DwqlbBpOyUdaG9UDlQPBxJNALuEK1I0tbQ3AVvSDnlsEIt06UPmPo5o27gzs3hwPQ/A+UA==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: @@ -4311,8 +4311,8 @@ packages: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} dev: true - /viem@1.1.4(typescript@4.9.5): - resolution: {integrity: sha512-3bJkS60Sw6Rf6a2ydKDnDxAI0PTZK0yGoyux2nqPSBoXBL+w9hXPNcnm8Uf6FlKce5sQadVRfi2n6MrgzablxA==} + /viem@1.1.1(typescript@4.9.5): + resolution: {integrity: sha512-RVwDpDQYngaXRWnP3ZfmKHSis7ojN4q46mOApGRlfGrS/p56UD7/hA35zYxeq+X0dwVhCNhWuIqtV9XSsMtVfg==} peerDependencies: typescript: '>=5.0.4' dependencies: @@ -4321,7 +4321,7 @@ packages: '@noble/hashes': 1.3.0 '@scure/bip32': 1.3.0 '@scure/bip39': 1.2.0 - '@wagmi/chains': 1.2.0(typescript@4.9.5) + '@wagmi/chains': 1.1.0(typescript@4.9.5) abitype: 0.8.7(typescript@4.9.5) isomorphic-ws: 5.0.0(ws@8.12.0) typescript: 4.9.5 @@ -4332,8 +4332,8 @@ packages: - zod dev: false - /viem@1.1.4(typescript@5.0.4): - resolution: {integrity: sha512-3bJkS60Sw6Rf6a2ydKDnDxAI0PTZK0yGoyux2nqPSBoXBL+w9hXPNcnm8Uf6FlKce5sQadVRfi2n6MrgzablxA==} + /viem@1.1.1(typescript@5.0.4): + resolution: {integrity: sha512-RVwDpDQYngaXRWnP3ZfmKHSis7ojN4q46mOApGRlfGrS/p56UD7/hA35zYxeq+X0dwVhCNhWuIqtV9XSsMtVfg==} peerDependencies: typescript: '>=5.0.4' dependencies: @@ -4342,7 +4342,7 @@ packages: '@noble/hashes': 1.3.0 '@scure/bip32': 1.3.0 '@scure/bip39': 1.2.0 - '@wagmi/chains': 1.2.0(typescript@5.0.4) + '@wagmi/chains': 1.1.0(typescript@5.0.4) abitype: 0.8.7(typescript@5.0.4) isomorphic-ws: 5.0.0(ws@8.12.0) typescript: 5.0.4 diff --git a/packages/block-events-stream/dist/index.js b/packages/block-events-stream/dist/index.js new file mode 100644 index 0000000000..bd90f97732 --- /dev/null +++ b/packages/block-events-stream/dist/index.js @@ -0,0 +1,2 @@ +import{BehaviorSubject as L,Subject as j}from"rxjs";function x(...t){return t.reduce((o,e)=>e{let n,l=t.watchBlocks({blockTag:o,emitOnBegin:!0,onBlock:i=>{n?n.next(i):(n=new S(i),e(n))},onError:i=>{s(i),n?.error(i)}})})}async function N({publicClient:t,blockTag:o,block$:e}){let s=e??await y({publicClient:t,blockTag:o}),n=s.value;if(!n.number)throw new Error(`${o} block missing or pending`);let l=new w(n.number),i=s.subscribe({next:r=>{r.number&&l.next(r.number)},error:l.error,complete:l.complete});return l}import{decodeEventLog as P,encodeEventTopics as C,numberToHex as T,formatLog as I}from"viem";import{isDefined as H}from"@latticexyz/common/utils";async function h({publicClient:t,address:o,events:e,fromBlock:s,toBlock:n}){let l=[e.flatMap(r=>C({abi:[r],eventName:r.name}))];return(await t.request({method:"eth_getLogs",params:[{address:o,topics:l,fromBlock:typeof s=="bigint"?T(s):s,toBlock:typeof n=="bigint"?T(n):n}]})).map(r=>{try{let{eventName:b,args:g}=P({abi:e,data:r.data,topics:r.topics,strict:!0});return I(r,{args:g,eventName:b})}catch{return}}).filter(H)}import{storeEventsAbi as O}from"@latticexyz/store";async function se({publicClient:t,fromBlock:o,toBlock:e,address:s,events:n,maxBlockRange:l=1e3}){if(u("createBlockEventsStream",{initialFromBlock:o,initialToBlock:e,address:s,events:n,maxBlockRange:l}),o==null){u("getting earliest block");let b=await t.getBlock({blockTag:"earliest"});if(u("earliest block",b),b.number==null)throw new Error("pending or missing earliest block");o=b.number}e==null&&(u("creating latest block number stream"),e=await N({publicClient:t,blockTag:"latest"}));let i=new j;r(o,l,e instanceof L?e.value:e);async function r(b,g,k){try{let a=x(b+BigInt(g),k);u("fetching block range",{fromBlock:b,toBlock:a});let f=await h({publicClient:t,address:s,fromBlock:b,toBlock:a,events:O}),v=f.filter(E);f.length!==v.length&&console.warn("pending logs discarded");let d=Array.from(new Set(v.map(m=>m.blockNumber)));d.sort((m,c)=>mc?1:0);for(let m of d){let c=v.filter(p=>p.blockNumber===m);c.sort((p,B)=>p.logIndexB.logIndex?1:0),c.length&&(u("emitting events for block",{blockNumber:m,blockHash:c[0].blockHash,events:c}),i.next({blockNumber:m,blockHash:c[0].blockHash,events:c}))}if(aa){r(a+1n,g,e.value);return}u("waiting for next block");let m=e.subscribe(c=>{c>a&&(m.unsubscribe(),r(a+1n,g,c))});return}i.complete()}catch(a){i.error(a)}}return i.asObservable()}export{se as createBlockEventsStream,N as createBlockNumberStream,y as createBlockStream}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/index.js.map b/packages/block-events-stream/dist/index.js.map new file mode 100644 index 0000000000..2c42661d3b --- /dev/null +++ b/packages/block-events-stream/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/createBlockEventsStream.ts","../src/utils.ts","../src/isNonPendingLog.ts","../src/debug.ts","../src/createBlockNumberStream.ts","../src/createBlockStream.ts","../src/getLogs.ts"],"sourcesContent":["import { BehaviorSubject, Subject, Subscribable } from \"rxjs\";\nimport type { BlockNumber, Hex, PublicClient } from \"viem\";\nimport type { AbiEvent } from \"abitype\";\nimport { BlockEvents, BlockEventsStream } from \"./common\";\nimport { bigIntMin } from \"./utils\";\nimport { isNonPendingLog } from \"./isNonPendingLog\";\nimport { debug } from \"./debug\";\nimport { createBlockNumberStream } from \"./createBlockNumberStream\";\nimport { getLogs } from \"./getLogs\";\nimport { storeEventsAbi } from \"@latticexyz/store\";\n\n// TODO: add nice logging with debub lib or similar\n// TODO: make `toBlock` accept a `BehaviorSubject` or add `latestBlockStream` so we only need one listener/watcher/poller\n// TODO: consider excluding `pending` block tags so we can just assume all block numbers are present\n\nexport type CreateBlockEventsStreamOptions = {\n publicClient: PublicClient;\n fromBlock?: BlockNumber;\n toBlock?: BlockNumber | Subscribable;\n address?: Hex;\n events: readonly TAbiEvent[];\n maxBlockRange?: number; // defaults to 1000\n};\n\nexport async function createBlockEventsStream({\n publicClient,\n fromBlock: initialFromBlock,\n toBlock: initialToBlock,\n address,\n events,\n maxBlockRange = 1000,\n}: CreateBlockEventsStreamOptions): Promise> {\n debug(\"createBlockEventsStream\", { initialFromBlock, initialToBlock, address, events, maxBlockRange });\n\n if (initialFromBlock == null) {\n debug(\"getting earliest block\");\n const earliestBlock = await publicClient.getBlock({ blockTag: \"earliest\" });\n debug(\"earliest block\", earliestBlock);\n if (earliestBlock.number == null) {\n // TODO: better error\n throw new Error(`pending or missing earliest block`);\n }\n initialFromBlock = earliestBlock.number;\n }\n\n if (initialToBlock == null) {\n debug(\"creating latest block number stream\");\n initialToBlock = await createBlockNumberStream({ publicClient, blockTag: \"latest\" });\n }\n\n const stream = new Subject>();\n fetchBlockRange(\n initialFromBlock,\n maxBlockRange,\n initialToBlock instanceof BehaviorSubject ? initialToBlock.value : initialToBlock\n );\n\n async function fetchBlockRange(fromBlock: bigint, maxBlockRange: number, lastBlockNumber: bigint): Promise {\n try {\n const toBlock = bigIntMin(fromBlock + BigInt(maxBlockRange), lastBlockNumber);\n debug(\"fetching block range\", { fromBlock, toBlock });\n\n // TODO: swap this with viem `getLogs` call when viem supports multiple events: https://github.com/wagmi-dev/viem/pull/633\n const logs = await getLogs({\n publicClient,\n address,\n fromBlock,\n toBlock,\n events: storeEventsAbi,\n });\n\n // TODO: do something other than just throwing out pending logs\n const nonPendingLogs = logs.filter(isNonPendingLog);\n\n if (logs.length !== nonPendingLogs.length) {\n // TODO: better error\n console.warn(\"pending logs discarded\");\n }\n\n // TODO: handle RPC block range errors\n // TODO: handle RPC rate limit errors (hopefully via client retry policy)\n\n const blockNumbers = Array.from(new Set(nonPendingLogs.map((log) => log.blockNumber)));\n blockNumbers.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));\n\n for (const blockNumber of blockNumbers) {\n const blockLogs = nonPendingLogs.filter((log) => log.blockNumber === blockNumber);\n blockLogs.sort((a, b) => (a.logIndex < b.logIndex ? -1 : a.logIndex > b.logIndex ? 1 : 0));\n\n if (blockLogs.length) {\n debug(\"emitting events for block\", { blockNumber, blockHash: blockLogs[0].blockHash, events: blockLogs });\n stream.next({\n blockNumber,\n blockHash: blockLogs[0].blockHash,\n events: blockLogs,\n // TODO: figure out why we need to cast this\n } as any as BlockEvents);\n }\n }\n\n if (toBlock < lastBlockNumber) {\n fetchBlockRange(toBlock + 1n, maxBlockRange, lastBlockNumber);\n return;\n }\n\n if (initialToBlock instanceof BehaviorSubject) {\n if (initialToBlock.value > toBlock) {\n fetchBlockRange(toBlock + 1n, maxBlockRange, initialToBlock.value);\n return;\n }\n\n debug(\"waiting for next block\");\n const sub = initialToBlock.subscribe((blockNumber) => {\n if (blockNumber > toBlock) {\n sub.unsubscribe();\n fetchBlockRange(toBlock + 1n, maxBlockRange, blockNumber);\n }\n });\n return;\n }\n\n stream.complete();\n } catch (error: unknown) {\n // TODO: do more specific error handling?\n stream.error(error);\n }\n }\n\n return stream.asObservable();\n}\n","export function bigIntMin(...args: bigint[]): bigint {\n return args.reduce((m, e) => (e < m ? e : m));\n}\n\nexport function bigIntMax(...args: bigint[]): bigint {\n return args.reduce((m, e) => (e > m ? e : m));\n}\n","import type { Log } from \"viem\";\n\nexport type NonPendingLog = TLog & {\n blockHash: NonNullable;\n blockNumber: NonNullable;\n logIndex: NonNullable;\n transactionHash: NonNullable;\n transactionIndex: NonNullable;\n};\n\nexport function isNonPendingLog(log: TLog): log is NonPendingLog {\n return (\n log.blockHash != null &&\n log.blockNumber != null &&\n log.logIndex != null &&\n log.transactionHash != null &&\n log.transactionIndex != null\n );\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:block-events-stream\");\n","import { BehaviorSubject } from \"rxjs\";\nimport type { Block, BlockNumber, BlockTag, PublicClient } from \"viem\";\nimport { createBlockStream } from \"./createBlockStream\";\nimport { ReadonlyBehaviorSubject } from \"./common\";\n\n// TODO: pass through viem's types, e.g. WatchBlocksParameters -> GetBlockReturnType\n// TODO: make stream closeable?\n\nexport type CreateBlockNumberStreamOptions =\n | {\n publicClient: PublicClient;\n blockTag: Omit;\n block$?: never;\n }\n | {\n publicClient?: never;\n blockTag?: never;\n block$: ReadonlyBehaviorSubject;\n };\n\nexport async function createBlockNumberStream({\n publicClient,\n blockTag,\n block$: initialBlock$,\n}: CreateBlockNumberStreamOptions): Promise> {\n const block$ = initialBlock$ ?? (await createBlockStream({ publicClient, blockTag: blockTag as BlockTag }));\n const block = block$.value;\n if (!block.number) {\n // TODO: better error\n throw new Error(`${blockTag} block missing or pending`);\n }\n\n const blockNumber$ = new BehaviorSubject(block.number);\n // TODO: do something with unwatch?\n const unwatch = block$.subscribe({\n next: (block) => {\n if (block.number) {\n blockNumber$.next(block.number);\n }\n // TODO: warn/error on blocks with missing block number?\n },\n error: blockNumber$.error,\n complete: blockNumber$.complete,\n });\n\n return blockNumber$;\n}\n","import { BehaviorSubject } from \"rxjs\";\nimport type { Block, BlockTag, PublicClient } from \"viem\";\nimport { ReadonlyBehaviorSubject } from \"./common\";\n\n// TODO: pass through viem's types, e.g. WatchBlocksParameters -> GetBlockReturnType\n// TODO: make stream closeable?\n\nexport type CreateBlockStreamOptions = {\n publicClient: PublicClient;\n blockTag: BlockTag;\n};\n\nexport function createBlockStream({\n publicClient,\n blockTag,\n}: CreateBlockStreamOptions): Promise> {\n return new Promise((resolve, reject) => {\n let stream: BehaviorSubject | undefined;\n // TODO: do something with unwatch?\n const unwatch = publicClient.watchBlocks({\n blockTag,\n emitOnBegin: true,\n onBlock: (block) => {\n if (!stream) {\n stream = new BehaviorSubject(block);\n // TODO: return actual readonly behavior subject rather than just a type?\n resolve(stream as ReadonlyBehaviorSubject);\n } else {\n stream.next(block);\n }\n },\n onError: (error) => {\n reject(error);\n stream?.error(error);\n },\n });\n });\n}\n","import { AbiEvent } from \"abitype\";\nimport {\n Address,\n BlockNumber,\n BlockTag,\n Log,\n PublicClient,\n decodeEventLog,\n encodeEventTopics,\n numberToHex,\n formatLog,\n} from \"viem\";\nimport { isDefined } from \"@latticexyz/common/utils\";\n\n// Based on https://github.com/wagmi-dev/viem/blob/main/src/actions/public/getLogs.ts\n// TODO: swap this out once viem has support for multiple events: https://github.com/wagmi-dev/viem/pull/633\n\nexport type GetLogsOptions = {\n publicClient: PublicClient;\n address?: Address | Address[];\n events: TAbiEvents;\n fromBlock: BlockNumber | BlockTag;\n toBlock: BlockNumber | BlockTag;\n};\n\nexport type GetLogsReturnType = Log<\n bigint,\n number,\n TAbiEvents[number],\n true,\n TAbiEvents\n>;\n\nexport async function getLogs({\n publicClient,\n address,\n events,\n fromBlock,\n toBlock,\n}: GetLogsOptions): Promise[]> {\n const topics = [events.flatMap((event) => encodeEventTopics({ abi: [event], eventName: event.name }))];\n\n const logs = await publicClient.request({\n method: \"eth_getLogs\",\n params: [\n {\n address,\n topics,\n fromBlock: typeof fromBlock === \"bigint\" ? numberToHex(fromBlock) : fromBlock,\n toBlock: typeof toBlock === \"bigint\" ? numberToHex(toBlock) : toBlock,\n },\n ],\n });\n\n return logs\n .map((log) => {\n try {\n const { eventName, args } = decodeEventLog({\n abi: events,\n data: log.data,\n topics: log.topics,\n strict: true,\n });\n return formatLog(log, { args, eventName });\n } catch (err) {\n // We're using strict mode, so just skip if there is an error decoding.\n return;\n }\n })\n .filter(isDefined) as GetLog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AAIX,EAAUD,EAAiB,CAC7BH,EAAgBI,EAAU,GAAIV,EAAeS,CAAe,EAC5D,OAGF,GAAIZ,aAA0BU,EAAiB,CAC7C,GAAIV,EAAe,MAAQa,EAAS,CAClCJ,EAAgBI,EAAU,GAAIV,EAAeH,EAAe,KAAK,EACjE,OAGFI,EAAM,wBAAwB,EAC9B,IAAMqB,EAAMzB,EAAe,UAAWuB,GAAgB,CAChDA,EAAcV,IAChBY,EAAI,YAAY,EAChBhB,EAAgBI,EAAU,GAAIV,EAAeoB,CAAW,EAE5D,CAAC,EACD,OAGFhB,EAAO,SAAS,CAClB,OAASmB,EAAP,CAEAnB,EAAO,MAAMmB,CAAK,CACpB,CACF,CAEA,OAAOnB,EAAO,aAAa,CAC7B","names":["BehaviorSubject","Subject","bigIntMin","args","m","isNonPendingLog","log","createDebug","debug","BehaviorSubject","BehaviorSubject","createBlockStream","publicClient","blockTag","resolve","reject","stream","unwatch","block","error","createBlockNumberStream","publicClient","blockTag","initialBlock$","block$","createBlockStream","block","blockNumber$","BehaviorSubject","unwatch","decodeEventLog","encodeEventTopics","numberToHex","formatLog","isDefined","getLogs","publicClient","address","events","fromBlock","toBlock","topics","event","log","eventName","args","storeEventsAbi","createBlockEventsStream","publicClient","initialFromBlock","initialToBlock","address","events","maxBlockRange","debug","earliestBlock","createBlockNumberStream","stream","Subject","fetchBlockRange","BehaviorSubject","fromBlock","lastBlockNumber","toBlock","bigIntMin","logs","getLogs","nonPendingLogs","isNonPendingLog","blockNumbers","log","a","b","blockNumber","blockLogs","sub","error"]} \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/common.d.ts b/packages/block-events-stream/dist/src/common.d.ts new file mode 100644 index 0000000000..1abb3298d6 --- /dev/null +++ b/packages/block-events-stream/dist/src/common.d.ts @@ -0,0 +1,13 @@ +import { BehaviorSubject, Observable } from "rxjs"; +import type { BlockNumber, Hex } from "viem"; +import type { AbiEvent } from "abitype"; +import { NonPendingLog } from "./isNonPendingLog"; +import { GetLogsReturnType } from "./getLogs"; +export type ReadonlyBehaviorSubject = Pick, "subscribe" | "pipe" | "value" | "getValue">; +export type BlockEvents = { + blockNumber: BlockNumber; + blockHash: Hex; + events: NonPendingLog>[]; +}; +export type BlockEventsStream = Observable>; +export type BlockEventsFromStream> = TStream extends BlockEventsStream ? BlockEvents : never; diff --git a/packages/block-events-stream/dist/src/common.js b/packages/block-events-stream/dist/src/common.js new file mode 100644 index 0000000000..6b84ded1c9 --- /dev/null +++ b/packages/block-events-stream/dist/src/common.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=common.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/common.js.map b/packages/block-events-stream/dist/src/common.js.map new file mode 100644 index 0000000000..d0c4324525 --- /dev/null +++ b/packages/block-events-stream/dist/src/common.js.map @@ -0,0 +1 @@ +{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/createBlockEventsStream.d.ts b/packages/block-events-stream/dist/src/createBlockEventsStream.d.ts new file mode 100644 index 0000000000..ca10b5c872 --- /dev/null +++ b/packages/block-events-stream/dist/src/createBlockEventsStream.d.ts @@ -0,0 +1,13 @@ +import { Subscribable } from "rxjs"; +import type { BlockNumber, Hex, PublicClient } from "viem"; +import type { AbiEvent } from "abitype"; +import { BlockEventsStream } from "./common"; +export type CreateBlockEventsStreamOptions = { + publicClient: PublicClient; + fromBlock?: BlockNumber; + toBlock?: BlockNumber | Subscribable; + address?: Hex; + events: readonly TAbiEvent[]; + maxBlockRange?: number; +}; +export declare function createBlockEventsStream({ publicClient, fromBlock: initialFromBlock, toBlock: initialToBlock, address, events, maxBlockRange, }: CreateBlockEventsStreamOptions): Promise>; diff --git a/packages/block-events-stream/dist/src/createBlockEventsStream.js b/packages/block-events-stream/dist/src/createBlockEventsStream.js new file mode 100644 index 0000000000..6eec7c803d --- /dev/null +++ b/packages/block-events-stream/dist/src/createBlockEventsStream.js @@ -0,0 +1,88 @@ +import { BehaviorSubject, Subject } from "rxjs"; +import { bigIntMin } from "./utils"; +import { isNonPendingLog } from "./isNonPendingLog"; +import { debug } from "./debug"; +import { createBlockNumberStream } from "./createBlockNumberStream"; +import { getLogs } from "./getLogs"; +import { storeEventsAbi } from "@latticexyz/store"; +export async function createBlockEventsStream({ publicClient, fromBlock: initialFromBlock, toBlock: initialToBlock, address, events, maxBlockRange = 1000, }) { + debug("createBlockEventsStream", { initialFromBlock, initialToBlock, address, events, maxBlockRange }); + if (initialFromBlock == null) { + debug("getting earliest block"); + const earliestBlock = await publicClient.getBlock({ blockTag: "earliest" }); + debug("earliest block", earliestBlock); + if (earliestBlock.number == null) { + // TODO: better error + throw new Error(`pending or missing earliest block`); + } + initialFromBlock = earliestBlock.number; + } + if (initialToBlock == null) { + debug("creating latest block number stream"); + initialToBlock = await createBlockNumberStream({ publicClient, blockTag: "latest" }); + } + const stream = new Subject(); + fetchBlockRange(initialFromBlock, maxBlockRange, initialToBlock instanceof BehaviorSubject ? initialToBlock.value : initialToBlock); + async function fetchBlockRange(fromBlock, maxBlockRange, lastBlockNumber) { + try { + const toBlock = bigIntMin(fromBlock + BigInt(maxBlockRange), lastBlockNumber); + debug("fetching block range", { fromBlock, toBlock }); + // TODO: swap this with viem `getLogs` call when viem supports multiple events: https://github.com/wagmi-dev/viem/pull/633 + const logs = await getLogs({ + publicClient, + address, + fromBlock, + toBlock, + events: storeEventsAbi, + }); + // TODO: do something other than just throwing out pending logs + const nonPendingLogs = logs.filter(isNonPendingLog); + if (logs.length !== nonPendingLogs.length) { + // TODO: better error + console.warn("pending logs discarded"); + } + // TODO: handle RPC block range errors + // TODO: handle RPC rate limit errors (hopefully via client retry policy) + const blockNumbers = Array.from(new Set(nonPendingLogs.map((log) => log.blockNumber))); + blockNumbers.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)); + for (const blockNumber of blockNumbers) { + const blockLogs = nonPendingLogs.filter((log) => log.blockNumber === blockNumber); + blockLogs.sort((a, b) => (a.logIndex < b.logIndex ? -1 : a.logIndex > b.logIndex ? 1 : 0)); + if (blockLogs.length) { + debug("emitting events for block", { blockNumber, blockHash: blockLogs[0].blockHash, events: blockLogs }); + stream.next({ + blockNumber, + blockHash: blockLogs[0].blockHash, + events: blockLogs, + // TODO: figure out why we need to cast this + }); + } + } + if (toBlock < lastBlockNumber) { + fetchBlockRange(toBlock + 1n, maxBlockRange, lastBlockNumber); + return; + } + if (initialToBlock instanceof BehaviorSubject) { + if (initialToBlock.value > toBlock) { + fetchBlockRange(toBlock + 1n, maxBlockRange, initialToBlock.value); + return; + } + debug("waiting for next block"); + const sub = initialToBlock.subscribe((blockNumber) => { + if (blockNumber > toBlock) { + sub.unsubscribe(); + fetchBlockRange(toBlock + 1n, maxBlockRange, blockNumber); + } + }); + return; + } + stream.complete(); + } + catch (error) { + // TODO: do more specific error handling? + stream.error(error); + } + } + return stream.asObservable(); +} +//# sourceMappingURL=createBlockEventsStream.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/createBlockEventsStream.js.map b/packages/block-events-stream/dist/src/createBlockEventsStream.js.map new file mode 100644 index 0000000000..31ed4790c9 --- /dev/null +++ b/packages/block-events-stream/dist/src/createBlockEventsStream.js.map @@ -0,0 +1 @@ +{"version":3,"file":"createBlockEventsStream.js","sourceRoot":"","sources":["../../src/createBlockEventsStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;AAI9D,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,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AC"} \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/createBlockNumberStream.d.ts b/packages/block-events-stream/dist/src/createBlockNumberStream.d.ts new file mode 100644 index 0000000000..71a87bd320 --- /dev/null +++ b/packages/block-events-stream/dist/src/createBlockNumberStream.d.ts @@ -0,0 +1,12 @@ +import type { Block, BlockNumber, BlockTag, PublicClient } from "viem"; +import { ReadonlyBehaviorSubject } from "./common"; +export type CreateBlockNumberStreamOptions = { + publicClient: PublicClient; + blockTag: Omit; + block$?: never; +} | { + publicClient?: never; + blockTag?: never; + block$: ReadonlyBehaviorSubject; +}; +export declare function createBlockNumberStream({ publicClient, blockTag, block$: initialBlock$, }: CreateBlockNumberStreamOptions): Promise>; diff --git a/packages/block-events-stream/dist/src/createBlockNumberStream.js b/packages/block-events-stream/dist/src/createBlockNumberStream.js new file mode 100644 index 0000000000..e251a27312 --- /dev/null +++ b/packages/block-events-stream/dist/src/createBlockNumberStream.js @@ -0,0 +1,24 @@ +import { BehaviorSubject } from "rxjs"; +import { createBlockStream } from "./createBlockStream"; +export async function createBlockNumberStream({ publicClient, blockTag, block$: initialBlock$, }) { + const block$ = initialBlock$ ?? (await createBlockStream({ publicClient, blockTag: blockTag })); + const block = block$.value; + if (!block.number) { + // TODO: better error + throw new Error(`${blockTag} block missing or pending`); + } + const blockNumber$ = new BehaviorSubject(block.number); + // TODO: do something with unwatch? + const unwatch = block$.subscribe({ + next: (block) => { + if (block.number) { + blockNumber$.next(block.number); + } + // TODO: warn/error on blocks with missing block number? + }, + error: blockNumber$.error, + complete: blockNumber$.complete, + }); + return blockNumber$; +} +//# sourceMappingURL=createBlockNumberStream.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/createBlockNumberStream.js.map b/packages/block-events-stream/dist/src/createBlockNumberStream.js.map new file mode 100644 index 0000000000..7a59e8420e --- /dev/null +++ b/packages/block-events-stream/dist/src/createBlockNumberStream.js.map @@ -0,0 +1 @@ +{"version":3,"file":"createBlockNumberStream.js","sourceRoot":"","sources":["../../src/createBlockNumberStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAkBxD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,EAC5C,YAAY,EACZ,QAAQ,EACR,MAAM,EAAE,aAAa,GACU;IAC/B,MAAM,MAAM,GAAG,aAAa,IAAI,CAAC,MAAM,iBAAiB,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAoB,EAAE,CAAC,CAAC,CAAC;IAC5G,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC3B,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjB,qBAAqB;QACrB,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,2BAA2B,CAAC,CAAC;KACzD;IAED,MAAM,YAAY,GAAG,IAAI,eAAe,CAAc,KAAK,CAAC,MAAM,CAAC,CAAC;IACpE,mCAAmC;IACnC,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC;QAC/B,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;YACd,IAAI,KAAK,CAAC,MAAM,EAAE;gBAChB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;aACjC;YACD,wDAAwD;QAC1D,CAAC;QACD,KAAK,EAAE,YAAY,CAAC,KAAK;QACzB,QAAQ,EAAE,YAAY,CAAC,QAAQ;KAChC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC"} \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/createBlockStream.d.ts b/packages/block-events-stream/dist/src/createBlockStream.d.ts new file mode 100644 index 0000000000..4291e17266 --- /dev/null +++ b/packages/block-events-stream/dist/src/createBlockStream.d.ts @@ -0,0 +1,7 @@ +import type { Block, BlockTag, PublicClient } from "viem"; +import { ReadonlyBehaviorSubject } from "./common"; +export type CreateBlockStreamOptions = { + publicClient: PublicClient; + blockTag: BlockTag; +}; +export declare function createBlockStream({ publicClient, blockTag, }: CreateBlockStreamOptions): Promise>; diff --git a/packages/block-events-stream/dist/src/createBlockStream.js b/packages/block-events-stream/dist/src/createBlockStream.js new file mode 100644 index 0000000000..5b3ef0a462 --- /dev/null +++ b/packages/block-events-stream/dist/src/createBlockStream.js @@ -0,0 +1,26 @@ +import { BehaviorSubject } from "rxjs"; +export function createBlockStream({ publicClient, blockTag, }) { + return new Promise((resolve, reject) => { + let stream; + // TODO: do something with unwatch? + const unwatch = publicClient.watchBlocks({ + blockTag, + emitOnBegin: true, + onBlock: (block) => { + if (!stream) { + stream = new BehaviorSubject(block); + // TODO: return actual readonly behavior subject rather than just a type? + resolve(stream); + } + else { + stream.next(block); + } + }, + onError: (error) => { + reject(error); + stream?.error(error); + }, + }); + }); +} +//# sourceMappingURL=createBlockStream.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/createBlockStream.js.map b/packages/block-events-stream/dist/src/createBlockStream.js.map new file mode 100644 index 0000000000..8f7691a637 --- /dev/null +++ b/packages/block-events-stream/dist/src/createBlockStream.js.map @@ -0,0 +1 @@ +{"version":3,"file":"createBlockStream.js","sourceRoot":"","sources":["../../src/createBlockStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAYvC,MAAM,UAAU,iBAAiB,CAAC,EAChC,YAAY,EACZ,QAAQ,GACiB;IACzB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,MAA0C,CAAC;QAC/C,mCAAmC;QACnC,MAAM,OAAO,GAAG,YAAY,CAAC,WAAW,CAAC;YACvC,QAAQ;YACR,WAAW,EAAE,IAAI;YACjB,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBACjB,IAAI,CAAC,MAAM,EAAE;oBACX,MAAM,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;oBACpC,yEAAyE;oBACzE,OAAO,CAAC,MAAwC,CAAC,CAAC;iBACnD;qBAAM;oBACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACpB;YACH,CAAC;YACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBACjB,MAAM,CAAC,KAAK,CAAC,CAAC;gBACd,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"} \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/debug.d.ts b/packages/block-events-stream/dist/src/debug.d.ts new file mode 100644 index 0000000000..3174ef7b01 --- /dev/null +++ b/packages/block-events-stream/dist/src/debug.d.ts @@ -0,0 +1,2 @@ +import createDebug from "debug"; +export declare const debug: createDebug.Debugger; diff --git a/packages/block-events-stream/dist/src/debug.js b/packages/block-events-stream/dist/src/debug.js new file mode 100644 index 0000000000..7f918f0ed7 --- /dev/null +++ b/packages/block-events-stream/dist/src/debug.js @@ -0,0 +1,3 @@ +import createDebug from "debug"; +export const debug = createDebug("mud:block-events-stream"); +//# sourceMappingURL=debug.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/debug.js.map b/packages/block-events-stream/dist/src/debug.js.map new file mode 100644 index 0000000000..fd003c7a64 --- /dev/null +++ b/packages/block-events-stream/dist/src/debug.js.map @@ -0,0 +1 @@ +{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,OAAO,CAAC;AAEhC,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC,yBAAyB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/getLogs.d.ts b/packages/block-events-stream/dist/src/getLogs.d.ts new file mode 100644 index 0000000000..dcaa70d1e8 --- /dev/null +++ b/packages/block-events-stream/dist/src/getLogs.d.ts @@ -0,0 +1,11 @@ +import { AbiEvent } from "abitype"; +import { Address, BlockNumber, BlockTag, Log, PublicClient } from "viem"; +export type GetLogsOptions = { + publicClient: PublicClient; + address?: Address | Address[]; + events: TAbiEvents; + fromBlock: BlockNumber | BlockTag; + toBlock: BlockNumber | BlockTag; +}; +export type GetLogsReturnType = Log; +export declare function getLogs({ publicClient, address, events, fromBlock, toBlock, }: GetLogsOptions): Promise[]>; diff --git a/packages/block-events-stream/dist/src/getLogs.js b/packages/block-events-stream/dist/src/getLogs.js new file mode 100644 index 0000000000..9f8ed241d9 --- /dev/null +++ b/packages/block-events-stream/dist/src/getLogs.js @@ -0,0 +1,34 @@ +import { decodeEventLog, encodeEventTopics, numberToHex, formatLog, } from "viem"; +import { isDefined } from "@latticexyz/common/utils"; +export async function getLogs({ publicClient, address, events, fromBlock, toBlock, }) { + const topics = [events.flatMap((event) => encodeEventTopics({ abi: [event], eventName: event.name }))]; + const logs = await publicClient.request({ + method: "eth_getLogs", + params: [ + { + address, + topics, + fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock, + toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock, + }, + ], + }); + return logs + .map((log) => { + try { + const { eventName, args } = decodeEventLog({ + abi: events, + data: log.data, + topics: log.topics, + strict: true, + }); + return formatLog(log, { args, eventName }); + } + catch (err) { + // We're using strict mode, so just skip if there is an error decoding. + return; + } + }) + .filter(isDefined); +} +//# sourceMappingURL=getLogs.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/getLogs.js.map b/packages/block-events-stream/dist/src/getLogs.js.map new file mode 100644 index 0000000000..1bffc1d765 --- /dev/null +++ b/packages/block-events-stream/dist/src/getLogs.js.map @@ -0,0 +1 @@ +{"version":3,"file":"getLogs.js","sourceRoot":"","sources":["../../src/getLogs.ts"],"names":[],"mappings":"AACA,OAAO,EAML,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,SAAS,GACV,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA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src/index.d.ts new file mode 100644 index 0000000000..c767c01088 --- /dev/null +++ b/packages/block-events-stream/dist/src/index.d.ts @@ -0,0 +1,4 @@ +export * from "./common"; +export * from "./createBlockEventsStream"; +export * from "./createBlockNumberStream"; +export * from "./createBlockStream"; diff --git a/packages/block-events-stream/dist/src/index.js b/packages/block-events-stream/dist/src/index.js new file mode 100644 index 0000000000..ad84f8da0b --- /dev/null +++ b/packages/block-events-stream/dist/src/index.js @@ -0,0 +1,5 @@ +export * from "./common"; +export * from "./createBlockEventsStream"; +export * from "./createBlockNumberStream"; +export * from "./createBlockStream"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/index.js.map b/packages/block-events-stream/dist/src/index.js.map new file mode 100644 index 0000000000..afae6820f5 --- /dev/null +++ b/packages/block-events-stream/dist/src/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC"} \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/isNonPendingBlock.d.ts b/packages/block-events-stream/dist/src/isNonPendingBlock.d.ts new file mode 100644 index 0000000000..40d3655906 --- /dev/null +++ b/packages/block-events-stream/dist/src/isNonPendingBlock.d.ts @@ -0,0 +1,8 @@ +import type { Block } from "viem"; +export type NonPendingBlock = TBlock & { + hash: NonNullable; + logsBloom: NonNullable; + nonce: NonNullable; + number: NonNullable; +}; +export declare function isNonPendingBlock(block: TBlock): block is NonPendingBlock; diff --git a/packages/block-events-stream/dist/src/isNonPendingBlock.js b/packages/block-events-stream/dist/src/isNonPendingBlock.js new file mode 100644 index 0000000000..9c8a2d9434 --- /dev/null +++ b/packages/block-events-stream/dist/src/isNonPendingBlock.js @@ -0,0 +1,4 @@ +export function isNonPendingBlock(block) { + return block.hash != null && block.logsBloom != null && block.nonce != null && block.number != null; +} +//# sourceMappingURL=isNonPendingBlock.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/isNonPendingBlock.js.map b/packages/block-events-stream/dist/src/isNonPendingBlock.js.map new file mode 100644 index 0000000000..bcacc851a4 --- /dev/null +++ b/packages/block-events-stream/dist/src/isNonPendingBlock.js.map @@ -0,0 +1 @@ +{"version":3,"file":"isNonPendingBlock.js","sourceRoot":"","sources":["../../src/isNonPendingBlock.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,iBAAiB,CAAuB,KAAa;IACnE,OAAO,KAAK,CAAC,IAAI,IAAI,IAAI,IAAI,KAAK,CAAC,SAAS,IAAI,IAAI,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC;AACtG,CAAC"} \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/isNonPendingLog.d.ts b/packages/block-events-stream/dist/src/isNonPendingLog.d.ts new file mode 100644 index 0000000000..9a347d9156 --- /dev/null +++ b/packages/block-events-stream/dist/src/isNonPendingLog.d.ts @@ -0,0 +1,9 @@ +import type { Log } from "viem"; +export type NonPendingLog = TLog & { + blockHash: NonNullable; + blockNumber: NonNullable; + logIndex: NonNullable; + transactionHash: NonNullable; + transactionIndex: NonNullable; +}; +export declare function isNonPendingLog(log: TLog): log is NonPendingLog; diff --git a/packages/block-events-stream/dist/src/isNonPendingLog.js b/packages/block-events-stream/dist/src/isNonPendingLog.js new file mode 100644 index 0000000000..8b9e67001a --- /dev/null +++ b/packages/block-events-stream/dist/src/isNonPendingLog.js @@ -0,0 +1,8 @@ +export function isNonPendingLog(log) { + return (log.blockHash != null && + log.blockNumber != null && + log.logIndex != null && + log.transactionHash != null && + log.transactionIndex != null); +} +//# sourceMappingURL=isNonPendingLog.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/isNonPendingLog.js.map b/packages/block-events-stream/dist/src/isNonPendingLog.js.map new file mode 100644 index 0000000000..a93e67246c --- /dev/null +++ b/packages/block-events-stream/dist/src/isNonPendingLog.js.map @@ -0,0 +1 @@ +{"version":3,"file":"isNonPendingLog.js","sourceRoot":"","sources":["../../src/isNonPendingLog.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,eAAe,CAAmB,GAAS;IACzD,OAAO,CACL,GAAG,CAAC,SAAS,IAAI,IAAI;QACrB,GAAG,CAAC,WAAW,IAAI,IAAI;QACvB,GAAG,CAAC,QAAQ,IAAI,IAAI;QACpB,GAAG,CAAC,eAAe,IAAI,IAAI;QAC3B,GAAG,CAAC,gBAAgB,IAAI,IAAI,CAC7B,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/utils.d.ts b/packages/block-events-stream/dist/src/utils.d.ts new file mode 100644 index 0000000000..0d76d1038d --- /dev/null +++ b/packages/block-events-stream/dist/src/utils.d.ts @@ -0,0 +1,2 @@ +export declare function bigIntMin(...args: bigint[]): bigint; +export declare function bigIntMax(...args: bigint[]): bigint; diff --git a/packages/block-events-stream/dist/src/utils.js b/packages/block-events-stream/dist/src/utils.js new file mode 100644 index 0000000000..8eb64a96b3 --- /dev/null +++ b/packages/block-events-stream/dist/src/utils.js @@ -0,0 +1,7 @@ +export function bigIntMin(...args) { + return args.reduce((m, e) => (e < m ? e : m)); +} +export function bigIntMax(...args) { + return args.reduce((m, e) => (e > m ? e : m)); +} +//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/src/utils.js.map b/packages/block-events-stream/dist/src/utils.js.map new file mode 100644 index 0000000000..06c899a2aa --- /dev/null +++ b/packages/block-events-stream/dist/src/utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAC,GAAG,IAAc;IACzC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAG,IAAc;IACzC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC"} \ No newline at end of file diff --git a/packages/block-events-stream/dist/tsup.config.d.ts b/packages/block-events-stream/dist/tsup.config.d.ts new file mode 100644 index 0000000000..b729921aa4 --- /dev/null +++ b/packages/block-events-stream/dist/tsup.config.d.ts @@ -0,0 +1,2 @@ +declare const _default: import("tsup").Options | import("tsup").Options[] | ((overrideOptions: import("tsup").Options) => import("tsup").Options | import("tsup").Options[] | Promise); +export default _default; diff --git a/packages/block-events-stream/dist/tsup.config.js b/packages/block-events-stream/dist/tsup.config.js new file mode 100644 index 0000000000..9b1798398c --- /dev/null +++ b/packages/block-events-stream/dist/tsup.config.js @@ -0,0 +1,11 @@ +import { defineConfig } from "tsup"; +export default defineConfig({ + entry: ["src/index.ts"], + target: "esnext", + format: ["esm"], + dts: false, + sourcemap: true, + clean: true, + minify: true, +}); +//# sourceMappingURL=tsup.config.js.map \ No newline at end of file diff --git a/packages/block-events-stream/dist/tsup.config.js.map b/packages/block-events-stream/dist/tsup.config.js.map new file mode 100644 index 0000000000..ac06ba87af --- /dev/null +++ b/packages/block-events-stream/dist/tsup.config.js.map @@ -0,0 +1 @@ +{"version":3,"file":"tsup.config.js","sourceRoot":"","sources":["../tsup.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEpC,eAAe,YAAY,CAAC;IAC1B,KAAK,EAAE,CAAC,cAAc,CAAC;IACvB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,CAAC,KAAK,CAAC;IACf,GAAG,EAAE,KAAK;IACV,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;CACb,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/block-events-stream/package.json b/packages/block-events-stream/package.json new file mode 100644 index 0000000000..571f7340f1 --- /dev/null +++ b/packages/block-events-stream/package.json @@ -0,0 +1,44 @@ +{ + "name": "@latticexyz/block-events-stream", + "version": "1.42.0", + "description": "Create a stream of EVM block events", + "repository": { + "type": "git", + "url": "https://github.com/latticexyz/mud.git", + "directory": "packages/block-events-stream" + }, + "license": "MIT", + "type": "module", + "exports": { + ".": "./dist/index.js" + }, + "types": "src/index.ts", + "scripts": { + "build": "pnpm run build:js", + "build:js": "tsup", + "clean": "pnpm run clean:js", + "clean:js": "rimraf dist", + "dev": "tsup --watch", + "lint": "eslint .", + "test": "vitest typecheck --run --passWithNoTests && vitest --run --passWithNoTests" + }, + "dependencies": { + "@latticexyz/common": "workspace:*", + "@latticexyz/config": "workspace:*", + "@latticexyz/schema-type": "workspace:*", + "@latticexyz/store": "workspace:*", + "abitype": "0.8.7", + "debug": "^4.3.4", + "rxjs": "7.5.5", + "viem": "1.1.1" + }, + "devDependencies": { + "@types/debug": "^4.1.7", + "tsup": "^6.7.0", + "vitest": "0.31.4" + }, + "publishConfig": { + "access": "public" + }, + "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f" +} diff --git a/packages/common/package.json b/packages/common/package.json index c1977beeca..8d95b0b97e 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -58,7 +58,7 @@ "execa": "^7.0.0", "prettier": "^2.8.4", "prettier-plugin-solidity": "^1.1.2", - "viem": "1.1.4" + "viem": "1.1.1" }, "devDependencies": { "@types/node": "^18.15.11", diff --git a/packages/dev-tools/package.json b/packages/dev-tools/package.json index 31fa708664..61c1a1c0d3 100644 --- a/packages/dev-tools/package.json +++ b/packages/dev-tools/package.json @@ -35,7 +35,7 @@ "rxjs": "7.5.5", "tailwind-merge": "^1.12.0", "use-local-storage-state": "^18.3.2", - "viem": "1.1.4", + "viem": "1.1.1", "zustand": "^4.3.7" }, "devDependencies": { diff --git a/packages/network/package.json b/packages/network/package.json index 5d26b7b334..6c4700ef12 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -53,7 +53,7 @@ "nice-grpc-web": "^2.0.1", "rxjs": "7.5.5", "threads": "^1.7.0", - "viem": "1.1.4" + "viem": "1.1.1" }, "devDependencies": { "@types/debug": "^4.1.7", diff --git a/packages/protocol-parser/package.json b/packages/protocol-parser/package.json index b262a42f38..38a743e816 100644 --- a/packages/protocol-parser/package.json +++ b/packages/protocol-parser/package.json @@ -28,7 +28,7 @@ "@latticexyz/schema-type": "workspace:*", "@latticexyz/store": "workspace:*", "abitype": "0.8.7", - "viem": "1.1.4" + "viem": "1.1.1" }, "devDependencies": { "tsup": "^6.7.0", diff --git a/packages/schema-type/package.json b/packages/schema-type/package.json index 4ef14c3593..9bc0c17db4 100644 --- a/packages/schema-type/package.json +++ b/packages/schema-type/package.json @@ -33,7 +33,7 @@ }, "dependencies": { "abitype": "0.8.7", - "viem": "1.1.4" + "viem": "1.1.1" }, "devDependencies": { "ds-test": "https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084", diff --git a/packages/std-client/package.json b/packages/std-client/package.json index e01e59fc9d..3651008246 100644 --- a/packages/std-client/package.json +++ b/packages/std-client/package.json @@ -51,7 +51,7 @@ "mobx": "^6.7.0", "react": "^18.2.0", "rxjs": "7.5.5", - "viem": "1.1.4" + "viem": "1.1.1" }, "devDependencies": { "@types/jest": "^27.4.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 94d488f650..ff9e229c3f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -57,6 +57,43 @@ importers: specifier: ^4.9.5 version: 4.9.5 + packages/block-events-stream: + dependencies: + '@latticexyz/common': + specifier: workspace:* + version: link:../common + '@latticexyz/config': + specifier: workspace:* + version: link:../config + '@latticexyz/schema-type': + specifier: workspace:* + version: link:../schema-type + '@latticexyz/store': + specifier: workspace:* + version: link:../store + abitype: + specifier: 0.8.7 + version: 0.8.7(typescript@5.0.4) + debug: + specifier: ^4.3.4 + version: 4.3.4(supports-color@8.1.1) + rxjs: + specifier: 7.5.5 + version: 7.5.5 + viem: + specifier: 1.1.1 + version: 1.1.1(typescript@5.0.4) + devDependencies: + '@types/debug': + specifier: ^4.1.7 + version: 4.1.7 + tsup: + specifier: ^6.7.0 + version: 6.7.0(postcss@8.4.23)(typescript@5.0.4) + vitest: + specifier: 0.31.4 + version: 0.31.4 + packages/cli: dependencies: '@ethersproject/abi': @@ -211,8 +248,8 @@ importers: specifier: ^1.1.2 version: 1.1.2(prettier@2.8.4) viem: - specifier: 1.1.4 - version: 1.1.4(typescript@5.0.4) + specifier: 1.1.1 + version: 1.1.1(typescript@5.0.4) devDependencies: '@types/node': specifier: ^18.15.11 @@ -316,8 +353,8 @@ importers: specifier: ^18.3.2 version: 18.3.2(react-dom@18.2.0)(react@18.2.0) viem: - specifier: 1.1.4 - version: 1.1.4(typescript@5.0.4) + specifier: 1.1.1 + version: 1.1.1(typescript@5.0.4) zustand: specifier: ^4.3.7 version: 4.3.7(react@18.2.0) @@ -450,8 +487,8 @@ importers: specifier: ^1.7.0 version: 1.7.0 viem: - specifier: 1.1.4 - version: 1.1.4(typescript@4.9.5) + specifier: 1.1.1 + version: 1.1.1(typescript@4.9.5) devDependencies: '@types/debug': specifier: ^4.1.7 @@ -579,8 +616,8 @@ importers: specifier: 0.8.7 version: 0.8.7(typescript@5.0.4) viem: - specifier: 1.1.4 - version: 1.1.4(typescript@5.0.4) + specifier: 1.1.1 + version: 1.1.1(typescript@5.0.4) devDependencies: tsup: specifier: ^6.7.0 @@ -693,8 +730,8 @@ importers: specifier: 0.8.7 version: 0.8.7(typescript@5.0.4) viem: - specifier: 1.1.4 - version: 1.1.4(typescript@5.0.4) + specifier: 1.1.1 + version: 1.1.1(typescript@5.0.4) devDependencies: ds-test: specifier: https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084 @@ -850,8 +887,8 @@ importers: specifier: 7.5.5 version: 7.5.5 viem: - specifier: 1.1.4 - version: 1.1.4(typescript@4.9.5) + specifier: 1.1.1 + version: 1.1.1(typescript@4.9.5) devDependencies: '@types/jest': specifier: ^27.4.1 @@ -4082,8 +4119,8 @@ packages: typescript: 5.0.4 dev: true - /@wagmi/chains@1.2.0(typescript@4.9.5): - resolution: {integrity: sha512-dmDRipsE54JfyudOBkuhEexqQWcrZqxn/qiujG8SBzMh/az/AH5xlJSA+j1CPWTx9+QofSMF3B7A4gb6XRmSaQ==} + /@wagmi/chains@1.1.0(typescript@4.9.5): + resolution: {integrity: sha512-pWZlxBk0Ql8E7DV8DwqlbBpOyUdaG9UDlQPBxJNALuEK1I0tbQ3AVvSDnlsEIt06UPmPo5o27gzs3hwPQ/A+UA==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: @@ -4093,8 +4130,8 @@ packages: typescript: 4.9.5 dev: false - /@wagmi/chains@1.2.0(typescript@5.0.4): - resolution: {integrity: sha512-dmDRipsE54JfyudOBkuhEexqQWcrZqxn/qiujG8SBzMh/az/AH5xlJSA+j1CPWTx9+QofSMF3B7A4gb6XRmSaQ==} + /@wagmi/chains@1.1.0(typescript@5.0.4): + resolution: {integrity: sha512-pWZlxBk0Ql8E7DV8DwqlbBpOyUdaG9UDlQPBxJNALuEK1I0tbQ3AVvSDnlsEIt06UPmPo5o27gzs3hwPQ/A+UA==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: @@ -14585,8 +14622,8 @@ packages: builtins: 5.0.1 dev: true - /viem@1.1.4(typescript@4.9.5): - resolution: {integrity: sha512-3bJkS60Sw6Rf6a2ydKDnDxAI0PTZK0yGoyux2nqPSBoXBL+w9hXPNcnm8Uf6FlKce5sQadVRfi2n6MrgzablxA==} + /viem@1.1.1(typescript@4.9.5): + resolution: {integrity: sha512-RVwDpDQYngaXRWnP3ZfmKHSis7ojN4q46mOApGRlfGrS/p56UD7/hA35zYxeq+X0dwVhCNhWuIqtV9XSsMtVfg==} peerDependencies: typescript: '>=5.0.4' dependencies: @@ -14595,7 +14632,7 @@ packages: '@noble/hashes': 1.3.0 '@scure/bip32': 1.3.0 '@scure/bip39': 1.2.0 - '@wagmi/chains': 1.2.0(typescript@4.9.5) + '@wagmi/chains': 1.1.0(typescript@4.9.5) abitype: 0.8.7(typescript@4.9.5)(zod@3.21.4) isomorphic-ws: 5.0.0(ws@8.12.0) typescript: 4.9.5 @@ -14606,8 +14643,8 @@ packages: - zod dev: false - /viem@1.1.4(typescript@5.0.4): - resolution: {integrity: sha512-3bJkS60Sw6Rf6a2ydKDnDxAI0PTZK0yGoyux2nqPSBoXBL+w9hXPNcnm8Uf6FlKce5sQadVRfi2n6MrgzablxA==} + /viem@1.1.1(typescript@5.0.4): + resolution: {integrity: sha512-RVwDpDQYngaXRWnP3ZfmKHSis7ojN4q46mOApGRlfGrS/p56UD7/hA35zYxeq+X0dwVhCNhWuIqtV9XSsMtVfg==} peerDependencies: typescript: '>=5.0.4' dependencies: @@ -14616,7 +14653,7 @@ packages: '@noble/hashes': 1.3.0 '@scure/bip32': 1.3.0 '@scure/bip39': 1.2.0 - '@wagmi/chains': 1.2.0(typescript@5.0.4) + '@wagmi/chains': 1.1.0(typescript@5.0.4) abitype: 0.8.7(typescript@5.0.4) isomorphic-ws: 5.0.0(ws@8.12.0) typescript: 5.0.4