diff --git a/.changeset/swift-carpets-accept.md b/.changeset/swift-carpets-accept.md new file mode 100644 index 0000000000..56c7470cd3 --- /dev/null +++ b/.changeset/swift-carpets-accept.md @@ -0,0 +1,5 @@ +--- +"viem": minor +--- + +Added formatter for Optimism transaction receipts (format `l1GasPrice`, `l1GasUsed`, etc). diff --git a/.changeset/twenty-apples-pull.md b/.changeset/twenty-apples-pull.md new file mode 100644 index 0000000000..7c6dc3adcf --- /dev/null +++ b/.changeset/twenty-apples-pull.md @@ -0,0 +1,5 @@ +--- +"viem": minor +--- + +Added entrypoints for Celo (`viem/chains/celo`) & Optimism (`viem/chains/optimism`) chains. diff --git a/package.json b/package.json index 2440fc7df5..091c517e53 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,16 @@ "import": "./dist/esm/chains/index.js", "default": "./dist/cjs/chains/index.js" }, + "./chains/celo": { + "types": "./dist/types/chains/celo/index.d.ts", + "import": "./dist/esm/chains/celo/index.js", + "default": "./dist/cjs/chains/celo/index.js" + }, + "./chains/optimism": { + "types": "./dist/types/chains/optimism/index.d.ts", + "import": "./dist/esm/chains/optimism/index.js", + "default": "./dist/cjs/chains/optimism/index.js" + }, "./contract": { "types": "./dist/types/contract.d.ts", "import": "./dist/esm/contract.js", @@ -111,39 +121,17 @@ }, "typesVersions": { "*": { - "abi": [ - "./dist/types/abi.d.ts" - ], - "accounts": [ - "./dist/types/accounts/index.d.ts" - ], - "actions": [ - "./dist/types/actions/index.d.ts" - ], - "chains": [ - "./dist/types/chains.d.ts" - ], - "contract": [ - "./dist/types/contract.d.ts" - ], - "ens": [ - "./dist/types/ens.d.ts" - ], - "public": [ - "./dist/types/public.d.ts" - ], - "test": [ - "./dist/types/test.d.ts" - ], - "utils": [ - "./dist/types/utils/index.d.ts" - ], - "wallet": [ - "./dist/types/wallet.d.ts" - ], - "window": [ - "./dist/types/window.d.ts" - ] + "abi": ["./dist/types/abi.d.ts"], + "accounts": ["./dist/types/accounts/index.d.ts"], + "actions": ["./dist/types/actions/index.d.ts"], + "chains": ["./dist/types/chains.d.ts"], + "contract": ["./dist/types/contract.d.ts"], + "ens": ["./dist/types/ens.d.ts"], + "public": ["./dist/types/public.d.ts"], + "test": ["./dist/types/test.d.ts"], + "utils": ["./dist/types/utils/index.d.ts"], + "wallet": ["./dist/types/wallet.d.ts"], + "window": ["./dist/types/window.d.ts"] } }, "peerDependencies": { @@ -191,23 +179,14 @@ }, "license": "MIT", "repository": "wagmi-dev/viem", - "authors": [ - "awkweb.eth", - "jxom.eth" - ], + "authors": ["awkweb.eth", "jxom.eth"], "funding": [ { "type": "github", "url": "https://github.com/sponsors/wagmi-dev" } ], - "keywords": [ - "eth", - "ethereum", - "dapps", - "wallet", - "web3" - ], + "keywords": ["eth", "ethereum", "dapps", "wallet", "web3"], "size-limit": [ { "name": "viem (cjs)", @@ -260,9 +239,7 @@ "viem": "workspace:*" }, "peerDependencyRules": { - "ignoreMissing": [ - "@algolia/client-search" - ] + "ignoreMissing": ["@algolia/client-search"] }, "patchedDependencies": { "vitepress@1.0.0-beta.4": "patches/vitepress@1.0.0-beta.4.patch" diff --git a/src/chains/formatters/celo.test-d.ts b/src/chains/celo/formatters.test-d.ts similarity index 93% rename from src/chains/formatters/celo.test-d.ts rename to src/chains/celo/formatters.test-d.ts index 3dff304deb..8be16d89b8 100644 --- a/src/chains/formatters/celo.test-d.ts +++ b/src/chains/celo/formatters.test-d.ts @@ -15,7 +15,7 @@ import type { import type { TransactionRequest } from '../../types/transaction.js' import { sendTransaction } from '../../wallet.js' import { celo } from '../index.js' -import { formattersCelo } from './celo.js' +import { formattersCelo } from './formatters.js' describe('block', () => { expectTypeOf(formattersCelo.block.format).parameter(0).toEqualTypeOf< @@ -152,6 +152,21 @@ describe('smoke', () => { expectTypeOf( block_includeTransactions.transactions[0].gatewayFeeRecipient, ).toEqualTypeOf<`0x${string}` | null>() + + const block_pending = await getBlock(client, { + blockTag: 'pending', + includeTransactions: true, + }) + expectTypeOf(block_pending.hash).toEqualTypeOf() + expectTypeOf(block_pending.logsBloom).toEqualTypeOf() + expectTypeOf(block_pending.number).toEqualTypeOf() + expectTypeOf(block_pending.transactions[0].blockHash).toEqualTypeOf() + expectTypeOf( + block_pending.transactions[0].blockNumber, + ).toEqualTypeOf() + expectTypeOf( + block_pending.transactions[0].transactionIndex, + ).toEqualTypeOf() }) test('transaction', async () => { diff --git a/src/chains/celo/formatters.test.ts b/src/chains/celo/formatters.test.ts new file mode 100644 index 0000000000..9b00272f9b --- /dev/null +++ b/src/chains/celo/formatters.test.ts @@ -0,0 +1,810 @@ +import { describe, expect, test } from 'vitest' + +import { getBlock } from '../../actions/public/getBlock.js' +import { getTransaction } from '../../actions/public/getTransaction.js' +import { getTransactionReceipt } from '../../actions/public/getTransactionReceipt.js' +import { createPublicClient } from '../../clients/createPublicClient.js' +import { http } from '../../clients/transports/http.js' +import { celo } from '../index.js' + +describe('block', () => { + test('formatter', () => { + const { block } = celo.formatters! + + expect( + block.format({ + baseFeePerGas: '0x0', + extraData: + '0xd983010700846765746889676f312e31372e3133856c696e7578000000000000f8ccc0c080b84169807e4d7934803decfde330167e444ec323431e1ff4cd70f40f2e79f24ce91f60340b99f97e3562ee57389e2c72343a74379e0b8b7ca5237ec141e84278bb3e00f8418e3e8af95497b7f6ffe7d3c4cbfbbdb06b26f6f3e913ca2cb7dff23532eaf3eb9f3b06ae75498c88353d279cf58fb0570736e2aa20cf53381722b6485f0f3c8180f8418e3fffffffffffffffffffffffffffb0005d23be939b9f8135e6b1ff283baff985c1b6ccacf2b6aa7fbd8939c4b6178b1d242b574a614b6347182a3b3195258080', + gasUsed: '0x1', + hash: '0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d', + logsBloom: + '0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000', + miner: '0xe267d978037b89db06c6a5fcf82fad8297e290ff', + number: '0x2', + parentHash: + '0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed', + randomness: { + committed: + '0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711', + revealed: + '0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88', + }, + receiptsRoot: + '0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a', + size: '0x3', + stateRoot: + '0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48', + timestamp: '0x4', + totalDifficulty: '0x5', + transactions: [ + '0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85', + ], + transactionsRoot: + '0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866', + }), + ).toMatchInlineSnapshot(` + { + "baseFeePerGas": 0n, + "extraData": "0xd983010700846765746889676f312e31372e3133856c696e7578000000000000f8ccc0c080b84169807e4d7934803decfde330167e444ec323431e1ff4cd70f40f2e79f24ce91f60340b99f97e3562ee57389e2c72343a74379e0b8b7ca5237ec141e84278bb3e00f8418e3e8af95497b7f6ffe7d3c4cbfbbdb06b26f6f3e913ca2cb7dff23532eaf3eb9f3b06ae75498c88353d279cf58fb0570736e2aa20cf53381722b6485f0f3c8180f8418e3fffffffffffffffffffffffffffb0005d23be939b9f8135e6b1ff283baff985c1b6ccacf2b6aa7fbd8939c4b6178b1d242b574a614b6347182a3b3195258080", + "gasUsed": 1n, + "hash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", + "logsBloom": "0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000", + "miner": "0xe267d978037b89db06c6a5fcf82fad8297e290ff", + "number": 2n, + "parentHash": "0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed", + "randomness": { + "committed": "0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711", + "revealed": "0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88", + }, + "receiptsRoot": "0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a", + "size": 3n, + "stateRoot": "0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48", + "timestamp": 4n, + "totalDifficulty": 5n, + "transactions": [ + "0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85", + ], + "transactionsRoot": "0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866", + } + `) + + expect( + block.format({ + baseFeePerGas: '0x0', + extraData: + '0xd983010700846765746889676f312e31372e3133856c696e7578000000000000f8ccc0c080b84169807e4d7934803decfde330167e444ec323431e1ff4cd70f40f2e79f24ce91f60340b99f97e3562ee57389e2c72343a74379e0b8b7ca5237ec141e84278bb3e00f8418e3e8af95497b7f6ffe7d3c4cbfbbdb06b26f6f3e913ca2cb7dff23532eaf3eb9f3b06ae75498c88353d279cf58fb0570736e2aa20cf53381722b6485f0f3c8180f8418e3fffffffffffffffffffffffffffb0005d23be939b9f8135e6b1ff283baff985c1b6ccacf2b6aa7fbd8939c4b6178b1d242b574a614b6347182a3b3195258080', + gasUsed: '0x1', + hash: '0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d', + logsBloom: + '0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000', + miner: '0xe267d978037b89db06c6a5fcf82fad8297e290ff', + number: '0x2', + parentHash: + '0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed', + randomness: { + committed: + '0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711', + revealed: + '0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88', + }, + receiptsRoot: + '0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a', + size: '0x3', + stateRoot: + '0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48', + timestamp: '0x4', + totalDifficulty: '0x5', + transactions: [ + { + accessList: [], + blockHash: + '0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d', + blockNumber: '0x1', + chainId: '0x1', + feeCurrency: null, + from: '0x045d685d23e8aa34dc408a66fb408f20dc84d785', + gas: '0x69420', + maxFeePerGas: '0x0', + maxPriorityFeePerGas: '0x0', + gatewayFee: '0x0', + gatewayFeeRecipient: null, + hash: '0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85', + input: '0x389ec778', + nonce: '0x1', + r: '0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0', + s: '0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774', + to: '0xb86d682b1b6bf20d8d54f55c48f848b9487dec37', + transactionIndex: '0x0', + type: '0x2', + v: '0x0', + value: '0x0', + }, + { + accessList: [], + blockHash: + '0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d', + blockNumber: '0x1', + chainId: '0x1', + feeCurrency: null, + from: '0x045d685d23e8aa34dc408a66fb408f20dc84d785', + gas: '0x69420', + maxFeePerGas: '0x0', + maxPriorityFeePerGas: '0x0', + gatewayFee: null, + gatewayFeeRecipient: null, + hash: '0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85', + input: '0x389ec778', + nonce: '0x1', + r: '0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0', + s: '0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774', + to: '0xb86d682b1b6bf20d8d54f55c48f848b9487dec37', + transactionIndex: '0x0', + type: '0x2', + v: '0x0', + value: '0x0', + }, + ], + transactionsRoot: + '0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866', + }), + ).toMatchInlineSnapshot(` + { + "baseFeePerGas": 0n, + "extraData": "0xd983010700846765746889676f312e31372e3133856c696e7578000000000000f8ccc0c080b84169807e4d7934803decfde330167e444ec323431e1ff4cd70f40f2e79f24ce91f60340b99f97e3562ee57389e2c72343a74379e0b8b7ca5237ec141e84278bb3e00f8418e3e8af95497b7f6ffe7d3c4cbfbbdb06b26f6f3e913ca2cb7dff23532eaf3eb9f3b06ae75498c88353d279cf58fb0570736e2aa20cf53381722b6485f0f3c8180f8418e3fffffffffffffffffffffffffffb0005d23be939b9f8135e6b1ff283baff985c1b6ccacf2b6aa7fbd8939c4b6178b1d242b574a614b6347182a3b3195258080", + "gasUsed": 1n, + "hash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", + "logsBloom": "0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000", + "miner": "0xe267d978037b89db06c6a5fcf82fad8297e290ff", + "number": 2n, + "parentHash": "0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed", + "randomness": { + "committed": "0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711", + "revealed": "0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88", + }, + "receiptsRoot": "0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a", + "size": 3n, + "stateRoot": "0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48", + "timestamp": 4n, + "totalDifficulty": 5n, + "transactions": [ + { + "accessList": [], + "blockHash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", + "blockNumber": 1n, + "chainId": 1, + "feeCurrency": null, + "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", + "gas": 431136n, + "gasPrice": undefined, + "gatewayFee": 0n, + "gatewayFeeRecipient": null, + "hash": "0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85", + "input": "0x389ec778", + "maxFeePerGas": 0n, + "maxPriorityFeePerGas": 0n, + "nonce": 1, + "r": "0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0", + "s": "0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774", + "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", + "transactionIndex": 0, + "type": "eip1559", + "typeHex": "0x2", + "v": 0n, + "value": 0n, + }, + { + "accessList": [], + "blockHash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", + "blockNumber": 1n, + "chainId": 1, + "feeCurrency": null, + "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", + "gas": 431136n, + "gasPrice": undefined, + "gatewayFee": null, + "gatewayFeeRecipient": null, + "hash": "0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85", + "input": "0x389ec778", + "maxFeePerGas": 0n, + "maxPriorityFeePerGas": 0n, + "nonce": 1, + "r": "0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0", + "s": "0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774", + "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", + "transactionIndex": 0, + "type": "eip1559", + "typeHex": "0x2", + "v": 0n, + "value": 0n, + }, + ], + "transactionsRoot": "0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866", + } + `) + }) + + test('action', async () => { + const client = createPublicClient({ + chain: celo, + transport: http(), + }) + + const block = await getBlock(client, { + blockNumber: 16645775n, + includeTransactions: true, + }) + + const { extraData: _extraData, transactions, ...rest } = block + expect(transactions[0]).toMatchInlineSnapshot(` + { + "blockHash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", + "blockNumber": 16645775n, + "chainId": undefined, + "ethCompatible": false, + "feeCurrency": null, + "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", + "gas": 1527520n, + "gasPrice": 562129081n, + "gatewayFee": 0n, + "gatewayFeeRecipient": null, + "hash": "0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85", + "input": "0x389ec778", + "nonce": 714820, + "r": "0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0", + "s": "0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774", + "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", + "transactionIndex": 0, + "type": "legacy", + "typeHex": "0x0", + "v": 84476n, + "value": 0n, + } + `) + expect(rest).toMatchInlineSnapshot(` + { + "baseFeePerGas": null, + "epochSnarkData": null, + "gasUsed": 5045322n, + "hash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", + "logsBloom": "0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000", + "miner": "0xe267d978037b89db06c6a5fcf82fad8297e290ff", + "number": 16645775n, + "parentHash": "0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed", + "randomness": { + "committed": "0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711", + "revealed": "0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88", + }, + "receiptsRoot": "0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a", + "size": 24562n, + "stateRoot": "0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48", + "timestamp": 1670896907n, + "totalDifficulty": 16645776n, + "transactionsRoot": "0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866", + } + `) + }) +}) + +describe('transaction', () => { + test('formatter', () => { + const { transaction } = celo.formatters! + + expect( + transaction.format({ + accessList: [], + blockHash: + '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', + blockNumber: '0x1', + chainId: '0x1', + feeCurrency: null, + from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', + gas: '0x2', + gasPrice: undefined, + gatewayFee: '0x3', + gatewayFeeRecipient: null, + hash: '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', + input: + '0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0', + maxFeePerGas: '0x4', + maxPriorityFeePerGas: '0x5', + nonce: '0x6', + r: '0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca', + s: '0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0', + to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', + transactionIndex: '0x7', + type: '0x2', + v: '0x1', + value: '0x0', + }), + ).toMatchInlineSnapshot(` + { + "accessList": [], + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 1n, + "chainId": 1, + "feeCurrency": null, + "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + "gas": 2n, + "gasPrice": undefined, + "gatewayFee": 3n, + "gatewayFeeRecipient": null, + "hash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "input": "0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0", + "maxFeePerGas": 4n, + "maxPriorityFeePerGas": 5n, + "nonce": 6, + "r": "0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca", + "s": "0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0", + "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "transactionIndex": 7, + "type": "eip1559", + "typeHex": "0x2", + "v": 1n, + "value": 0n, + } + `) + + expect( + transaction.format({ + accessList: [], + blockHash: + '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', + blockNumber: '0x1', + chainId: '0x1', + feeCurrency: null, + from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', + gas: '0x2', + gasPrice: undefined, + gatewayFee: null, + gatewayFeeRecipient: null, + hash: '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', + input: + '0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0', + maxFeePerGas: '0x4', + maxPriorityFeePerGas: '0x5', + nonce: '0x6', + r: '0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca', + s: '0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0', + to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', + transactionIndex: '0x7', + type: '0x2', + v: '0x1', + value: '0x0', + }), + ).toMatchInlineSnapshot(` + { + "accessList": [], + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 1n, + "chainId": 1, + "feeCurrency": null, + "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + "gas": 2n, + "gasPrice": undefined, + "gatewayFee": null, + "gatewayFeeRecipient": null, + "hash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", + "input": "0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0", + "maxFeePerGas": 4n, + "maxPriorityFeePerGas": 5n, + "nonce": 6, + "r": "0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca", + "s": "0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0", + "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "transactionIndex": 7, + "type": "eip1559", + "typeHex": "0x2", + "v": 1n, + "value": 0n, + } + `) + }) + + test('action', async () => { + const client = createPublicClient({ + chain: celo, + transport: http(), + }) + + const transaction = await getTransaction(client, { + blockNumber: 16628100n, + index: 0, + }) + + expect(transaction).toMatchInlineSnapshot(` + { + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "chainId": undefined, + "ethCompatible": false, + "feeCurrency": null, + "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", + "gas": 1527520n, + "gasPrice": 2999683966n, + "gatewayFee": 0n, + "gatewayFeeRecipient": null, + "hash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "input": "0x389ec778", + "nonce": 697201, + "r": "0xf507fb8fa33ffd05a7f26c980bbb8271aa113affc8f192feba87abe26549bda1", + "s": "0x7971c7b15ab4475ce6256da0bdf62ca1d1e491be8a03fe7637289f98c166f521", + "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", + "transactionIndex": 0, + "type": "legacy", + "typeHex": "0x0", + "v": 84475n, + "value": 0n, + } + `) + }) +}) + +describe('transactionReceipt', () => { + test('formatter', () => { + const { transactionReceipt } = celo.formatters! + expect( + transactionReceipt.format({ + blockHash: + '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', + blockNumber: '0x1', + contractAddress: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', + cumulativeGasUsed: '0x2', + effectiveGasPrice: '0x3', + feeCurrency: null, + from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', + gasUsed: '0x4', + gatewayFee: null, + gatewayFeeRecipient: null, + logs: [], + to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', + status: '0x0', + type: '0x0', + }), + ).toMatchInlineSnapshot(` + { + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 1n, + "contractAddress": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + "cumulativeGasUsed": 2n, + "effectiveGasPrice": 3n, + "feeCurrency": null, + "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + "gasUsed": 4n, + "gatewayFee": null, + "gatewayFeeRecipient": null, + "logs": [], + "status": "reverted", + "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "transactionIndex": null, + "type": "legacy", + } + `) + + expect( + transactionReceipt.format({ + blockHash: + '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', + blockNumber: '0x1', + contractAddress: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', + cumulativeGasUsed: '0x2', + effectiveGasPrice: '0x3', + feeCurrency: null, + from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', + gasUsed: '0x4', + gatewayFee: '0x123', + gatewayFeeRecipient: null, + logs: [], + to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', + status: '0x0', + type: '0x0', + }), + ).toMatchInlineSnapshot(` + { + "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", + "blockNumber": 1n, + "contractAddress": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + "cumulativeGasUsed": 2n, + "effectiveGasPrice": 3n, + "feeCurrency": null, + "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", + "gasUsed": 4n, + "gatewayFee": 291n, + "gatewayFeeRecipient": null, + "logs": [], + "status": "reverted", + "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", + "transactionIndex": null, + "type": "legacy", + } + `) + }) + + test('action', async () => { + const client = createPublicClient({ + chain: celo, + transport: http(), + }) + + const transaction = await getTransactionReceipt(client, { + hash: '0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17', + }) + + expect(transaction).toMatchInlineSnapshot(` + { + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "contractAddress": null, + "cumulativeGasUsed": 490857n, + "effectiveGasPrice": 2999683966n, + "feeCurrency": undefined, + "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", + "gasUsed": 490857n, + "gatewayFee": null, + "gatewayFeeRecipient": undefined, + "logs": [ + { + "address": "0x918146359264c492bd6934071c6bd31c854edbc3", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x0000000000000000000000000000000000000000000000000004be9c24a9467d0000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", + "logIndex": 0, + "removed": false, + "topics": [ + "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", + "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0x918146359264c492bd6934071c6bd31c854edbc3", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x0000000000000000000000000000000000000000000000000004be9c24a9467d", + "logIndex": 1, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0xe273ad7ee11dcfaa87383ad5977ee1504ac07568", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x000000000000000000000000000000000000000000000000000051069a5460020000000000000000000000000000000000000000033267b28d9c01bb6124f934", + "logIndex": 2, + "removed": false, + "topics": [ + "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", + "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0xe273ad7ee11dcfaa87383ad5977ee1504ac07568", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x000000000000000000000000000000000000000000000000000051069a546002", + "logIndex": 3, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0x471ece3750da237f93b8e339c536989b8978a438", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x0000000000000000000000000000000000000000000000000000000000000000", + "logIndex": 4, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000b460f9ae1fea4f77107146c1960bb1c978118816", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0x918146359264c492bd6934071c6bd31c854edbc3", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x0000000000000000000000000000000000000000000000000002950b4b3a43b40000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", + "logIndex": 5, + "removed": false, + "topics": [ + "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", + "0x000000000000000000000000b460f9ae1fea4f77107146c1960bb1c978118816", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0x918146359264c492bd6934071c6bd31c854edbc3", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x0000000000000000000000000000000000000000000000000002950b4b3a43b4", + "logIndex": 6, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000b460f9ae1fea4f77107146c1960bb1c978118816", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0x122013fd7df1c6f636a5bb8f03108e876548b455", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x0000000000000000000000000000000000000000000000000000000000000000", + "logIndex": 7, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000313e1b5edeebab73b6e869a74a896dc999e204cc", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0x918146359264c492bd6934071c6bd31c854edbc3", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x00000000000000000000000000000000000000000000000000024144eaf931230000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", + "logIndex": 8, + "removed": false, + "topics": [ + "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", + "0x000000000000000000000000313e1b5edeebab73b6e869a74a896dc999e204cc", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0x918146359264c492bd6934071c6bd31c854edbc3", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x00000000000000000000000000000000000000000000000000024144eaf93123", + "logIndex": 9, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000313e1b5edeebab73b6e869a74a896dc999e204cc", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0x02de4766c272abc10bc88c220d214a26960a7e92", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x0000000000000000000000000000000000000000000000000000000000000000", + "logIndex": 10, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000ec5c9c99ad30adf396ac4b48fba09dc34819c65a", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0x918146359264c492bd6934071c6bd31c854edbc3", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x000000000000000000000000000000000000000000000000000121f3877515ea0000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", + "logIndex": 11, + "removed": false, + "topics": [ + "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", + "0x000000000000000000000000ec5c9c99ad30adf396ac4b48fba09dc34819c65a", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + { + "address": "0x918146359264c492bd6934071c6bd31c854edbc3", + "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", + "blockNumber": 16628100n, + "data": "0x000000000000000000000000000000000000000000000000000121f3877515ea", + "logIndex": 12, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000ec5c9c99ad30adf396ac4b48fba09dc34819c65a", + "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", + ], + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + }, + ], + "logsBloom": "0x00004000004000000000000000800000000000000000400002000000002000000000800000000000000180000001000000000000000000000000000000000000000000000000000020000008000800000000000000000000000000000000000000000000000000000000000040000800000004000000000000000010000800000000000000000000000010000000000000000000000000000000000000000000020000000000000000000000000000002000081000000000000000000000040020800402000000100000000000000000000000000010000010000000000000200010002000000000000000000080000000000000000000000000000004000000", + "status": "success", + "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", + "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", + "transactionIndex": 0, + "type": "legacy", + } + `) + }) +}) + +describe('transactionRequest', () => { + test('formatter', () => { + const { transactionRequest } = celo.formatters! + + expect( + transactionRequest.format({ + feeCurrency: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', + from: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', + gas: 1n, + gatewayFee: 4n, + gatewayFeeRecipient: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', + maxFeePerGas: 2n, + maxPriorityFeePerGas: 1n, + nonce: 1, + value: 1n, + }), + ).toMatchInlineSnapshot(` + { + "feeCurrency": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", + "from": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", + "gas": "0x1", + "gasPrice": undefined, + "gatewayFee": "0x4", + "gatewayFeeRecipient": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", + "maxFeePerGas": "0x2", + "maxPriorityFeePerGas": "0x1", + "nonce": "0x1", + "value": "0x1", + } + `) + + expect( + transactionRequest.format({ + feeCurrency: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', + from: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', + gas: 1n, + gatewayFeeRecipient: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', + maxFeePerGas: 2n, + maxPriorityFeePerGas: 1n, + nonce: 1, + value: 1n, + }), + ).toMatchInlineSnapshot(` + { + "feeCurrency": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", + "from": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", + "gas": "0x1", + "gasPrice": undefined, + "gatewayFee": undefined, + "gatewayFeeRecipient": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", + "maxFeePerGas": "0x2", + "maxPriorityFeePerGas": "0x1", + "nonce": "0x1", + "value": "0x1", + } + `) + }) +}) diff --git a/src/chains/formatters/celo.ts b/src/chains/celo/formatters.ts similarity index 60% rename from src/chains/formatters/celo.ts rename to src/chains/celo/formatters.ts index ccd30abe64..13b12fd69f 100644 --- a/src/chains/formatters/celo.ts +++ b/src/chains/celo/formatters.ts @@ -1,9 +1,5 @@ -import type { Address } from 'abitype' - import { type Formatters } from '../../types/formatter.js' -import type { Hash, Hex } from '../../types/misc.js' -import type { RpcTransaction } from '../../types/rpc.js' -import type { Transaction } from '../../types/transaction.js' +import type { Hash } from '../../types/misc.js' import { hexToBigInt } from '../../utils/encoding/fromHex.js' import { numberToHex } from '../../utils/encoding/toHex.js' import { defineBlock } from '../../utils/formatters/block.js' @@ -13,47 +9,28 @@ import { } from '../../utils/formatters/transaction.js' import { defineTransactionReceipt } from '../../utils/formatters/transactionReceipt.js' import { defineTransactionRequest } from '../../utils/formatters/transactionRequest.js' - -export type CeloFormatOverrides = { - RpcBlock: { - randomness: { - committed: Hex - revealed: Hex - } - transactions: - | Hash[] - | (RpcTransaction & { - feeCurrency: Address | null - gatewayFee: Hex | null - gatewayFeeRecipient: Address | null - })[] - } - RpcTransaction: { - feeCurrency: Address | null - gatewayFee: Hex | null - gatewayFeeRecipient: Address | null - } - RpcTransactionReceipt: { - feeCurrency: Address | null - gatewayFee: Hex | null - gatewayFeeRecipient: Address | null - } - TransactionRequest: { - feeCurrency?: Address - gatewayFee?: bigint - gatewayFeeRecipient?: Address - } - Transaction: { - feeCurrency: Address | null - gatewayFee: bigint | null - gatewayFeeRecipient: Address | null - } -} +import type { + CeloBlockOverrides, + CeloRpcTransaction, + CeloRpcTransactionOverrides, + CeloRpcTransactionReceiptOverrides, + CeloRpcTransactionRequestOverrides, + CeloTransaction, + CeloTransactionOverrides, + CeloTransactionReceiptOverrides, + CeloTransactionRequestOverrides, +} from './types.js' export const formattersCelo = { block: /*#__PURE__*/ defineBlock({ exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'], - format(args: CeloFormatOverrides['RpcBlock']) { + format( + args: CeloBlockOverrides & { + transactions: Hash[] | CeloRpcTransaction[] + }, + ): CeloBlockOverrides & { + transactions: Hash[] | CeloTransaction[] + } { const transactions = args.transactions?.map((transaction) => { if (typeof transaction === 'string') return transaction return { @@ -64,7 +41,7 @@ export const formattersCelo = { : null, gatewayFeeRecipient: transaction.gatewayFeeRecipient, } - }) as Hash[] | (Transaction & CeloFormatOverrides['Transaction'])[] + }) as Hash[] | CeloTransaction[] return { randomness: args.randomness, transactions, @@ -72,7 +49,7 @@ export const formattersCelo = { }, }), transaction: /*#__PURE__*/ defineTransaction({ - format(args: CeloFormatOverrides['RpcTransaction']) { + format(args: CeloRpcTransactionOverrides): CeloTransactionOverrides { return { feeCurrency: args.feeCurrency, gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null, @@ -81,7 +58,9 @@ export const formattersCelo = { }, }), transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({ - format(args: CeloFormatOverrides['RpcTransactionReceipt']) { + format( + args: CeloRpcTransactionReceiptOverrides, + ): CeloTransactionReceiptOverrides { return { feeCurrency: args.feeCurrency, gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null, @@ -90,7 +69,9 @@ export const formattersCelo = { }, }), transactionRequest: /*#__PURE__*/ defineTransactionRequest({ - format(args: CeloFormatOverrides['TransactionRequest']) { + format( + args: CeloTransactionRequestOverrides, + ): CeloRpcTransactionRequestOverrides { return { feeCurrency: args.feeCurrency, gatewayFee: diff --git a/src/chains/celo/index.test.ts b/src/chains/celo/index.test.ts new file mode 100644 index 0000000000..302b1eb41c --- /dev/null +++ b/src/chains/celo/index.test.ts @@ -0,0 +1,16 @@ +import { expect, test } from 'vitest' + +import * as actions from './index.js' + +test('exports', () => { + expect(Object.keys(actions)).toMatchInlineSnapshot(` + [ + "celo", + "celoAlfajores", + "celoCannoli", + "formattersCelo", + "serializeTransactionCelo", + "serializersCelo", + ] + `) +}) diff --git a/src/chains/celo/index.ts b/src/chains/celo/index.ts new file mode 100644 index 0000000000..a0fd99bd2a --- /dev/null +++ b/src/chains/celo/index.ts @@ -0,0 +1,29 @@ +export { celo, celoAlfajores, celoCannoli } from '../index.js' + +export { formattersCelo } from './formatters.js' + +export { + type CeloTransactionSerializable, + type TransactionSerializableCIP42, + serializeTransactionCelo, + serializersCelo, +} from './serializers.js' + +export type { + CeloBlock, + CeloBlockOverrides, + CeloRpcBlock, + CeloRpcBlockOverrides, + CeloRpcTransaction, + CeloRpcTransactionOverrides, + CeloRpcTransactionReceipt, + CeloRpcTransactionReceiptOverrides, + CeloRpcTransactionRequest, + CeloRpcTransactionRequestOverrides, + CeloTransaction, + CeloTransactionOverrides, + CeloTransactionReceipt, + CeloTransactionReceiptOverrides, + CeloTransactionRequest, + CeloTransactionRequestOverrides, +} from './types.js' diff --git a/src/chains/serializers/celo.test.ts b/src/chains/celo/serializers.test.ts similarity index 99% rename from src/chains/serializers/celo.test.ts rename to src/chains/celo/serializers.test.ts index 077b723822..e1d0db3061 100644 --- a/src/chains/serializers/celo.test.ts +++ b/src/chains/celo/serializers.test.ts @@ -12,7 +12,7 @@ import { import { type TransactionSerializableCIP42, serializeTransactionCelo, -} from './celo.js' +} from './serializers.js' import { describe, expect, test } from 'vitest' const baseCip42: TransactionSerializableCIP42 = { diff --git a/src/chains/serializers/celo.ts b/src/chains/celo/serializers.ts similarity index 97% rename from src/chains/serializers/celo.ts rename to src/chains/celo/serializers.ts index b67436b508..0c30b6e83f 100644 --- a/src/chains/serializers/celo.ts +++ b/src/chains/celo/serializers.ts @@ -24,7 +24,7 @@ import { } from '../../utils/transaction/serializeTransaction.js' export const serializeTransactionCelo: SerializeTransactionFn< - TransactionSerializableCelo + CeloTransactionSerializable > = (tx, signature) => { // Handle CIP-42 transactions if (isCIP42(tx)) @@ -58,7 +58,7 @@ export type TransactionSerializableCIP42< type?: 'cip42' } -export type TransactionSerializableCelo = +export type CeloTransactionSerializable = | TransactionSerializableCIP42 | TransactionSerializable @@ -123,7 +123,7 @@ function serializeTransactionCIP42( // Utilities // process as CIP42 if any of these fields are present. realistically gatewayfee is not used but is part of spec -function isCIP42(transaction: TransactionSerializableCelo) { +function isCIP42(transaction: CeloTransactionSerializable) { if ( 'maxFeePerGas' in transaction && 'maxPriorityFeePerGas' in transaction && diff --git a/src/chains/celo/types.ts b/src/chains/celo/types.ts new file mode 100644 index 0000000000..385ff76834 --- /dev/null +++ b/src/chains/celo/types.ts @@ -0,0 +1,111 @@ +import type { Address } from 'abitype' + +import type { Block, BlockTag } from '../../types/block.js' +import type { Hex } from '../../types/misc.js' +import type { + RpcBlock, + RpcTransaction, + RpcTransactionReceipt, + RpcTransactionRequest, +} from '../../types/rpc.js' +import type { + Transaction, + TransactionReceipt, + TransactionRequest, +} from '../../types/transaction.js' +import type { NeverBy } from '../../types/utils.js' +import type { OptimismRpcTransaction } from '../optimism/types.js' + +type CeloBlockExclude = + | 'difficulty' + | 'gasLimit' + | 'mixHash' + | 'nonce' + | 'uncles' + +export type CeloBlockOverrides = { + randomness: { + committed: Hex + revealed: Hex + } +} +export type CeloBlock< + TIncludeTransactions extends boolean = boolean, + TBlockTag extends BlockTag = BlockTag, +> = NeverBy< + Block< + bigint, + TIncludeTransactions, + TBlockTag, + CeloTransaction + >, + CeloBlockExclude +> & + CeloBlockOverrides + +export type CeloRpcBlockOverrides = { + randomness: { + committed: Hex + revealed: Hex + } +} +export type CeloRpcBlock< + TBlockTag extends BlockTag = BlockTag, + TIncludeTransactions extends boolean = boolean, +> = NeverBy< + RpcBlock< + TBlockTag, + TIncludeTransactions, + OptimismRpcTransaction + >, + CeloBlockExclude +> & + CeloRpcBlockOverrides + +export type CeloRpcTransactionOverrides = { + feeCurrency: Address | null + gatewayFee: Hex | null + gatewayFeeRecipient: Address | null +} +export type CeloRpcTransaction = + RpcTransaction & CeloRpcTransactionOverrides + +export type CeloRpcTransactionReceiptOverrides = { + feeCurrency: Address | null + gatewayFee: Hex | null + gatewayFeeRecipient: Address | null +} +export type CeloRpcTransactionReceipt = RpcTransactionReceipt & + CeloRpcTransactionReceiptOverrides + +export type CeloRpcTransactionRequestOverrides = { + feeCurrency?: Address + gatewayFee?: Hex + gatewayFeeRecipient?: Address +} +export type CeloRpcTransactionRequest = RpcTransactionRequest & + CeloRpcTransactionRequestOverrides + +export type CeloTransactionOverrides = { + feeCurrency: Address | null + gatewayFee: bigint | null + gatewayFeeRecipient: Address | null +} +export type CeloTransaction = + Transaction & CeloTransactionOverrides + +export type CeloTransactionReceiptOverrides = { + feeCurrency: Address | null + gatewayFee: bigint | null + gatewayFeeRecipient: Address | null +} +export type CeloTransactionReceipt = TransactionReceipt & + CeloTransactionReceiptOverrides + +export type CeloTransactionRequestOverrides = { + feeCurrency?: Address + gatewayFee?: bigint + gatewayFeeRecipient?: Address +} +export type CeloTransactionRequest = TransactionRequest & + CeloTransactionRequestOverrides diff --git a/src/chains/formatters/celo.test.ts b/src/chains/formatters/celo.test.ts deleted file mode 100644 index dd9aab753c..0000000000 --- a/src/chains/formatters/celo.test.ts +++ /dev/null @@ -1,336 +0,0 @@ -import { expect, test } from 'vitest' - -import { getBlock } from '../../actions/public/getBlock.js' -import { getTransaction } from '../../actions/public/getTransaction.js' -import { getTransactionReceipt } from '../../actions/public/getTransactionReceipt.js' -import { createPublicClient } from '../../clients/createPublicClient.js' -import { http } from '../../clients/transports/http.js' -import { celo } from '../index.js' - -test('block', async () => { - const client = createPublicClient({ - chain: celo, - transport: http(), - }) - - const block = await getBlock(client, { - blockNumber: 16645775n, - includeTransactions: true, - }) - - const { extraData: _extraData, transactions, ...rest } = block - expect(transactions[0]).toMatchInlineSnapshot(` - { - "blockHash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", - "blockNumber": 16645775n, - "chainId": undefined, - "ethCompatible": false, - "feeCurrency": null, - "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", - "gas": 1527520n, - "gasPrice": 562129081n, - "gatewayFee": 0n, - "gatewayFeeRecipient": null, - "hash": "0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85", - "input": "0x389ec778", - "nonce": 714820, - "r": "0x1c0c8776e2e9d97b9a95435d2c2439d5f634e1afc35a5a0f0bd02093dd4724e0", - "s": "0xde418ff749f2430a85e60a4b3f81af9f8e2117cffbe32c719b9b784c01be774", - "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", - "transactionIndex": 0, - "type": "legacy", - "typeHex": "0x0", - "v": 84476n, - "value": 0n, - } - `) - expect(rest).toMatchInlineSnapshot(` - { - "baseFeePerGas": null, - "epochSnarkData": null, - "gasUsed": 5045322n, - "hash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", - "logsBloom": "0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000", - "miner": "0xe267d978037b89db06c6a5fcf82fad8297e290ff", - "number": 16645775n, - "parentHash": "0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed", - "randomness": { - "committed": "0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711", - "revealed": "0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88", - }, - "receiptsRoot": "0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a", - "size": 24562n, - "stateRoot": "0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48", - "timestamp": 1670896907n, - "totalDifficulty": 16645776n, - "transactionsRoot": "0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866", - } - `) -}) - -test('transaction', async () => { - const client = createPublicClient({ - chain: celo, - transport: http(), - }) - - const transaction = await getTransaction(client, { - blockNumber: 16628100n, - index: 0, - }) - - expect(transaction).toMatchInlineSnapshot(` - { - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "chainId": undefined, - "ethCompatible": false, - "feeCurrency": null, - "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", - "gas": 1527520n, - "gasPrice": 2999683966n, - "gatewayFee": 0n, - "gatewayFeeRecipient": null, - "hash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "input": "0x389ec778", - "nonce": 697201, - "r": "0xf507fb8fa33ffd05a7f26c980bbb8271aa113affc8f192feba87abe26549bda1", - "s": "0x7971c7b15ab4475ce6256da0bdf62ca1d1e491be8a03fe7637289f98c166f521", - "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", - "transactionIndex": 0, - "type": "legacy", - "typeHex": "0x0", - "v": 84475n, - "value": 0n, - } - `) -}) - -test('transactionReceipt', async () => { - const client = createPublicClient({ - chain: celo, - transport: http(), - }) - - const transaction = await getTransactionReceipt(client, { - hash: '0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17', - }) - - expect(transaction).toMatchInlineSnapshot(` - { - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "contractAddress": null, - "cumulativeGasUsed": 490857n, - "effectiveGasPrice": 2999683966n, - "feeCurrency": undefined, - "from": "0x045d685d23e8aa34dc408a66fb408f20dc84d785", - "gasUsed": 490857n, - "gatewayFee": null, - "gatewayFeeRecipient": undefined, - "logs": [ - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000004be9c24a9467d0000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", - "logIndex": 0, - "removed": false, - "topics": [ - "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", - "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000004be9c24a9467d", - "logIndex": 1, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0xe273ad7ee11dcfaa87383ad5977ee1504ac07568", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x000000000000000000000000000000000000000000000000000051069a5460020000000000000000000000000000000000000000033267b28d9c01bb6124f934", - "logIndex": 2, - "removed": false, - "topics": [ - "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", - "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0xe273ad7ee11dcfaa87383ad5977ee1504ac07568", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x000000000000000000000000000000000000000000000000000051069a546002", - "logIndex": 3, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000f94fea0c87d2b357dc72b743b45a8cb682b0716e", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x471ece3750da237f93b8e339c536989b8978a438", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000000000000000000", - "logIndex": 4, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000b460f9ae1fea4f77107146c1960bb1c978118816", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000002950b4b3a43b40000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", - "logIndex": 5, - "removed": false, - "topics": [ - "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", - "0x000000000000000000000000b460f9ae1fea4f77107146c1960bb1c978118816", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000002950b4b3a43b4", - "logIndex": 6, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000b460f9ae1fea4f77107146c1960bb1c978118816", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x122013fd7df1c6f636a5bb8f03108e876548b455", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000000000000000000", - "logIndex": 7, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000313e1b5edeebab73b6e869a74a896dc999e204cc", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x00000000000000000000000000000000000000000000000000024144eaf931230000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", - "logIndex": 8, - "removed": false, - "topics": [ - "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", - "0x000000000000000000000000313e1b5edeebab73b6e869a74a896dc999e204cc", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x00000000000000000000000000000000000000000000000000024144eaf93123", - "logIndex": 9, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000313e1b5edeebab73b6e869a74a896dc999e204cc", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x02de4766c272abc10bc88c220d214a26960a7e92", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x0000000000000000000000000000000000000000000000000000000000000000", - "logIndex": 10, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000ec5c9c99ad30adf396ac4b48fba09dc34819c65a", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x000000000000000000000000000000000000000000000000000121f3877515ea0000000000000000000000000000000000000000035b7e007bd2ad61e3574e25", - "logIndex": 11, - "removed": false, - "topics": [ - "0x4beccb90f994c31aced7a23b5611020728a23d8ec5cddd1a3e9d97b96fda8666", - "0x000000000000000000000000ec5c9c99ad30adf396ac4b48fba09dc34819c65a", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - { - "address": "0x918146359264c492bd6934071c6bd31c854edbc3", - "blockHash": "0x740371d30b3cee9d687f72e3409ba6447eceda7de86bc38b0fa84493114b510b", - "blockNumber": 16628100n, - "data": "0x000000000000000000000000000000000000000000000000000121f3877515ea", - "logIndex": 12, - "removed": false, - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000ec5c9c99ad30adf396ac4b48fba09dc34819c65a", - "0x000000000000000000000000045d685d23e8aa34dc408a66fb408f20dc84d785", - ], - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - }, - ], - "logsBloom": "0x00004000004000000000000000800000000000000000400002000000002000000000800000000000000180000001000000000000000000000000000000000000000000000000000020000008000800000000000000000000000000000000000000000000000000000000000040000800000004000000000000000010000800000000000000000000000010000000000000000000000000000000000000000000020000000000000000000000000000002000081000000000000000000000040020800402000000100000000000000000000000000010000010000000000000200010002000000000000000000080000000000000000000000000000004000000", - "status": "success", - "to": "0xb86d682b1b6bf20d8d54f55c48f848b9487dec37", - "transactionHash": "0x55678b68cc086d5b9739bb28748b492db030d001d9eb59001cc2d1f7a3305d17", - "transactionIndex": 0, - "type": "legacy", - } - `) -}) diff --git a/src/chains/formatters/optimism.test.ts b/src/chains/formatters/optimism.test.ts deleted file mode 100644 index caf2577e31..0000000000 --- a/src/chains/formatters/optimism.test.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { expect, test } from 'vitest' - -import { getBlock } from '../../actions/public/getBlock.js' -import { getTransaction } from '../../actions/public/getTransaction.js' -import { createPublicClient } from '../../clients/createPublicClient.js' -import { http } from '../../clients/transports/http.js' -import { optimism } from '../index.js' - -test('block', async () => { - const client = createPublicClient({ - chain: optimism, - transport: http(), - }) - const block = await getBlock(client, { - blockNumber: 105849734n, - includeTransactions: true, - }) - - const { extraData: _extraData, transactions, ...rest } = block - expect(transactions[0]).toMatchInlineSnapshot(` - { - "blockHash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", - "blockNumber": 105849734n, - "chainId": undefined, - "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", - "gas": 1000000n, - "gasPrice": 0n, - "hash": "0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a", - "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0", - "isSystemTx": undefined, - "maxFeePerGas": undefined, - "maxPriorityFeePerGas": undefined, - "mint": 0n, - "nonce": 614670, - "r": "0x0", - "s": "0x0", - "sourceHash": "0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df", - "to": "0x4200000000000000000000000000000000000015", - "transactionIndex": 0, - "type": "deposit", - "typeHex": "0x7e", - "v": 0n, - "value": 0n, - } - `) - expect(rest).toMatchInlineSnapshot(` - { - "baseFeePerGas": 83n, - "difficulty": 0n, - "gasLimit": 30000000n, - "gasUsed": 1414689n, - "hash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", - "logsBloom": "0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010", - "miner": "0x4200000000000000000000000000000000000011", - "mixHash": "0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887", - "nonce": "0x0000000000000000", - "number": 105849734n, - "parentHash": "0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6", - "receiptsRoot": "0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde", - "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - "size": 4072n, - "stateRoot": "0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746", - "timestamp": 1687298245n, - "totalDifficulty": 0n, - "transactionsRoot": "0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5", - "uncles": [], - } - `) -}) - -test('transaction', async () => { - const client = createPublicClient({ - chain: optimism, - transport: http(), - }) - - const transaction = await getTransaction(client, { - hash: '0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822', - }) - - expect(transaction).toMatchInlineSnapshot(` - { - "accessList": [], - "blockHash": "0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574", - "blockNumber": 105848892n, - "chainId": 10, - "from": "0xacd03d601e5bb1b275bb94076ff46ed9d753435a", - "gas": 21000n, - "gasPrice": 267n, - "hash": "0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822", - "input": "0x", - "maxFeePerGas": 191000n, - "maxPriorityFeePerGas": 191n, - "nonce": 775017, - "r": "0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e", - "s": "0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a", - "to": "0xeb610a69341aace81ed810ed42428249512378cd", - "transactionIndex": 7, - "type": "eip1559", - "typeHex": "0x2", - "v": 1n, - "value": 650000000000000n, - } - `) -}) - -test('transaction (deposit)', async () => { - const client = createPublicClient({ - chain: optimism, - transport: http(), - }) - - const transaction = await getTransaction(client, { - hash: '0x97f8e79b683df44ae2cc2e9f6eeebd2febdd6f0aeda71f184e6b297cbe7f620b', - }) - - expect(transaction).toMatchInlineSnapshot(` - { - "blockHash": "0x7c04fe001ea0efd91d5eea232e6936a2b94af8d238e56f0e025d264a55e65a58", - "blockNumber": 105847831n, - "chainId": undefined, - "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", - "gas": 1000000n, - "gasPrice": 0n, - "hash": "0x97f8e79b683df44ae2cc2e9f6eeebd2febdd6f0aeda71f184e6b297cbe7f620b", - "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000010b62c6000000000000000000000000000000000000000000000000000000006492119f000000000000000000000000000000000000000000000000000000078e016aff6b099ac98f4d1e69a45ad7bccba81386deddee0569412aafb388d8c1510f9e0800000000000000000000000000000000000000000000000000000000000000020000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0", - "isSystemTx": undefined, - "maxFeePerGas": undefined, - "maxPriorityFeePerGas": undefined, - "mint": 0n, - "nonce": 612767, - "r": "0x0", - "s": "0x0", - "sourceHash": "0x3fd7eb0bfa68ab126d745d17de615819430e1a6e922f65e5c06418569eb8dee1", - "to": "0x4200000000000000000000000000000000000015", - "transactionIndex": 0, - "type": "deposit", - "typeHex": "0x7e", - "v": 0n, - "value": 0n, - } - `) -}) diff --git a/src/chains/formatters/optimism.ts b/src/chains/formatters/optimism.ts deleted file mode 100644 index 37fef24766..0000000000 --- a/src/chains/formatters/optimism.ts +++ /dev/null @@ -1,91 +0,0 @@ -import type { FeeValuesEIP1559 } from '../../types/fee.js' -import { type Formatters } from '../../types/formatter.js' -import type { Hash, Hex } from '../../types/misc.js' -import type { - Index, - Quantity, - RpcTransaction as RpcTransaction_, -} from '../../types/rpc.js' -import type { - Transaction as Transaction_, - TransactionBase, -} from '../../types/transaction.js' -import { hexToBigInt } from '../../utils/encoding/fromHex.js' -import { defineBlock } from '../../utils/formatters/block.js' -import { - defineTransaction, - formatTransaction, -} from '../../utils/formatters/transaction.js' - -type RpcTransaction = RpcTransaction_ & { - isSystemTx?: undefined - mint?: undefined - sourceHash?: undefined -} - -type Transaction = Transaction_ & { - isSystemTx?: undefined - mint?: undefined - sourceHash?: undefined -} - -export type RpcDepositTransaction = TransactionBase & - FeeValuesEIP1559 & { - isSystemTx?: boolean - mint?: Hex - sourceHash: Hex - type: '0x7e' - } - -export type DepositTransaction = TransactionBase & - FeeValuesEIP1559 & { - isSystemTx?: boolean - mint?: bigint - sourceHash: Hex - type: 'deposit' - } - -export type OptimismFormatOverrides = { - RpcBlock: { - transactions: Hash[] | OptimismFormatOverrides['RpcTransaction'][] - } - RpcTransaction: RpcTransaction | RpcDepositTransaction - Transaction: Transaction | DepositTransaction -} - -export const formattersOptimism = { - block: /*#__PURE__*/ defineBlock({ - format(args: OptimismFormatOverrides['RpcBlock']) { - const transactions = args.transactions?.map((transaction) => { - if (typeof transaction === 'string') return transaction - const formatted = formatTransaction( - transaction as RpcTransaction, - ) as OptimismFormatOverrides['Transaction'] - if (formatted.typeHex === '0x7e') { - formatted.isSystemTx = transaction.isSystemTx - formatted.mint = transaction.mint - ? hexToBigInt(transaction.mint) - : undefined - formatted.sourceHash = transaction.sourceHash - formatted.type = 'deposit' - } - return formatted - }) as Hash[] | OptimismFormatOverrides['Transaction'][] - return { - transactions, - } - }, - }), - transaction: /*#__PURE__*/ defineTransaction({ - format(args: OptimismFormatOverrides['RpcTransaction']) { - const transaction = {} as OptimismFormatOverrides['Transaction'] - if (args.type === '0x7e') { - transaction.isSystemTx = args.isSystemTx - transaction.mint = args.mint ? hexToBigInt(args.mint) : undefined - transaction.sourceHash = args.sourceHash - transaction.type = 'deposit' - } - return transaction - }, - }), -} as const satisfies Formatters diff --git a/src/chains/index.test.ts b/src/chains/index.test.ts index bae3d5eed4..5af953b135 100644 --- a/src/chains/index.test.ts +++ b/src/chains/index.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, test } from 'vitest' +import { expect, test } from 'vitest' import * as chains from './index.js' @@ -104,351 +104,3 @@ test('exports chains', () => { ] `) }) - -describe('formatters', () => { - test('celo', () => { - const { block, transaction, transactionReceipt, transactionRequest } = - chains.celo.formatters! - - expect( - block.format({ - baseFeePerGas: '0x0', - extraData: - '0xd983010700846765746889676f312e31372e3133856c696e7578000000000000f8ccc0c080b84169807e4d7934803decfde330167e444ec323431e1ff4cd70f40f2e79f24ce91f60340b99f97e3562ee57389e2c72343a74379e0b8b7ca5237ec141e84278bb3e00f8418e3e8af95497b7f6ffe7d3c4cbfbbdb06b26f6f3e913ca2cb7dff23532eaf3eb9f3b06ae75498c88353d279cf58fb0570736e2aa20cf53381722b6485f0f3c8180f8418e3fffffffffffffffffffffffffffb0005d23be939b9f8135e6b1ff283baff985c1b6ccacf2b6aa7fbd8939c4b6178b1d242b574a614b6347182a3b3195258080', - gasUsed: '0x1', - hash: '0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d', - logsBloom: - '0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000', - miner: '0xe267d978037b89db06c6a5fcf82fad8297e290ff', - number: '0x2', - parentHash: - '0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed', - randomness: { - committed: - '0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711', - revealed: - '0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88', - }, - receiptsRoot: - '0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a', - size: '0x3', - stateRoot: - '0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48', - timestamp: '0x4', - totalDifficulty: '0x5', - transactions: [ - '0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85', - '0x3aa054b868fb0ce99388d74165b6128a5aca0992a785eb73a84fb7532f02a6a3', - '0x7273f2bf436b14621094de5694d5aced028666389c7a89f4a863ac33d653cf52', - '0xe5240102364623faf753498c52102de4a5f9641ceb6f99d9c92b032716e2f8f9', - '0x92c31e9e4397e08a5abcccd8cc466e73d554be16da1ca7cac6a01b643f806524', - '0x0acc190dfc0bbc6c9823dc17ff815c94e1494b60f9be9b6e045cbad572fdbdb1', - '0x27c8cff64388e80b279407758d6801fe0dfe3410bacc7051deddf6c49c16710c', - '0x6d4e4a0a01b1ebbb8be5cddede5de036779bd230ffc22e465eaa6128bd552ecb', - '0xa80107ba2f636428883a71b7ce8a23171faf5076bae51e3a68e046c143434ed9', - '0xcdadac0ee4a8901992ee365b7d251ff567134b007d2ad2d6a2285f7091998d60', - '0xdff49ec96503acbd0110a8200f0f18b9924978bc5db32ae5c47a0986bcb58b58', - '0xb0591b97ed1f7779e5cd548a9acfdad535d9073a3879d5bd4e3ff053bce31c5f', - '0xa58e9da5702648d3f3f81e44952d5072b07b10eb13477a877cf3d957443b5605', - '0x00d3bf8dc0ed9b62a786ce2fe1bec7de9d0ba286421acd3c4942b055b0741c0c', - '0xf02343c58c6ef8007e86840e8ac9f8c2a6c52c7877b7554e87711efaab49d50a', - '0x063f62e3c507eb0102f9dbe887520db4a1d3d34c4279f646bc3fc2c76e074369', - '0xbeb28f46cc143db996e14fa35591cb5de4dcc92a569422f68f87f3f6a72a0e64', - '0x9a38f385833a2c1ea159031f12c3e1af4033860c389afb69d77d1b897f37c452', - '0xae6dbf3554a531e0ad6c51ec1e2201b41859f466dbb0ca3364fa7237fb0c60f3', - '0x789aca8285c9e0ce2deb306f2c2f0f53df9b3601e295bdc0838a8622bd697be6', - '0x230ebdcd6c3282992c8793f23eb847f955220f2a6c14bb82b38bc48ccf0cf1c4', - '0xad7f4b13ac995055b681cb64f90bfe2863582e49d1179b837ebde353117ab2b4', - '0xe40fc6bbacf5cfc1f6c41f06737d7df6274aef89a9c46bbe4fb8cb8484ffa54b', - '0xa78f1aa9b1a0a2130477c0ed9df303c033c5c852240689a9ec34347333defa42', - '0x3b10b4297066dbac52031920159034ef43544b77fc82c5fcc561df7208064b2f', - '0x5d73e6bb86089544825ca8c8ca2091744b7fd25bdd36a8b4d9941968be76a845', - '0x2f5d0deb26329807564b18ecbf24d9cb9d802d92369ea48c78fb973e1ea78994', - '0x086a6ff358bce56bcbc022978b1b84448143ae66de7f9e0c3f7a68bce7664135', - '0x8f36d90a6da392b377162caa1f81a5f0e3882c48794bea979bf79f119bb9284d', - '0xe0a475e8a6f9495b00a55d8472b108171bf11a51cb8db131c98c25a17d0ac78c', - '0x8ba00695bd7b524ff55fbbda3f17c6e93056e6895089de2ee29d58541e11b88f', - '0xf971ed0462249050dbeaa4a812c2b881957d4225587dcd10c88581ca6b096a36', - '0x229ab6e46f4be57cb81f8c7b2070f19827e55d4162c72b4abf26e618521eaaee', - '0x99601bf74f39ef88dabd853b40e86bc9653899a93af85518fe73ecf372578588', - '0x5deaa0abfd7689d3c33543a3d3b1bebc3dba46acd72246775fabb0bb5561e410', - '0x413bada477356cdf02680950e2d0368ce3614eccc4a6c245fabd54ee07253f60', - ], - transactionsRoot: - '0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866', - }), - ).toMatchInlineSnapshot(` - { - "baseFeePerGas": 0n, - "extraData": "0xd983010700846765746889676f312e31372e3133856c696e7578000000000000f8ccc0c080b84169807e4d7934803decfde330167e444ec323431e1ff4cd70f40f2e79f24ce91f60340b99f97e3562ee57389e2c72343a74379e0b8b7ca5237ec141e84278bb3e00f8418e3e8af95497b7f6ffe7d3c4cbfbbdb06b26f6f3e913ca2cb7dff23532eaf3eb9f3b06ae75498c88353d279cf58fb0570736e2aa20cf53381722b6485f0f3c8180f8418e3fffffffffffffffffffffffffffb0005d23be939b9f8135e6b1ff283baff985c1b6ccacf2b6aa7fbd8939c4b6178b1d242b574a614b6347182a3b3195258080", - "gasUsed": 1n, - "hash": "0xac8c9bc3b84e103dc321bbe83b670e425ff68bfc9a333a4f1b1b204ad11c583d", - "logsBloom": "0x02004000004200000000000000800020000000000000400002040000002020000000802000000000000180000001000020800000000000000000000000000000000000000022000260000008000800000000000000000000000000000000000000000008000410002100000140000800000044c00200000000400010000800008800000080000000000010000040000000000000000000000000000000800020028000000100000000000000000000002002881000000000000800020000040020900402020000180000000000000040000800000011020090002000400000200010002000001000000000000080000000000000000000000000000004000000", - "miner": "0xe267d978037b89db06c6a5fcf82fad8297e290ff", - "number": 2n, - "parentHash": "0xf6e57c99be5a81167bcb7bdf8d55572235384182c71635857ace2c04d25294ed", - "randomness": { - "committed": "0x339714505ecf55eacc2d2568ea53a7424bd0aa40fd710fd6892464d0716da711", - "revealed": "0xe10b5f01b0376fdc9151f66992f8c1b990083acabc14ec1b04f6a53ad804db88", - }, - "receiptsRoot": "0xca8aabc507534e45c982aa43e38118fc6f9cf222800e3d703a6e299a2e661f2a", - "size": 3n, - "stateRoot": "0x051c8e40ed3d8afabbad5321a4bb6b9d686a8a62d9b696b3e5a5c769c3623d48", - "timestamp": 4n, - "totalDifficulty": 5n, - "transactions": [ - "0x487efb864b308ee85afd7ed5954e968457cfe84e71726114b0a44f31fb876e85", - "0x3aa054b868fb0ce99388d74165b6128a5aca0992a785eb73a84fb7532f02a6a3", - "0x7273f2bf436b14621094de5694d5aced028666389c7a89f4a863ac33d653cf52", - "0xe5240102364623faf753498c52102de4a5f9641ceb6f99d9c92b032716e2f8f9", - "0x92c31e9e4397e08a5abcccd8cc466e73d554be16da1ca7cac6a01b643f806524", - "0x0acc190dfc0bbc6c9823dc17ff815c94e1494b60f9be9b6e045cbad572fdbdb1", - "0x27c8cff64388e80b279407758d6801fe0dfe3410bacc7051deddf6c49c16710c", - "0x6d4e4a0a01b1ebbb8be5cddede5de036779bd230ffc22e465eaa6128bd552ecb", - "0xa80107ba2f636428883a71b7ce8a23171faf5076bae51e3a68e046c143434ed9", - "0xcdadac0ee4a8901992ee365b7d251ff567134b007d2ad2d6a2285f7091998d60", - "0xdff49ec96503acbd0110a8200f0f18b9924978bc5db32ae5c47a0986bcb58b58", - "0xb0591b97ed1f7779e5cd548a9acfdad535d9073a3879d5bd4e3ff053bce31c5f", - "0xa58e9da5702648d3f3f81e44952d5072b07b10eb13477a877cf3d957443b5605", - "0x00d3bf8dc0ed9b62a786ce2fe1bec7de9d0ba286421acd3c4942b055b0741c0c", - "0xf02343c58c6ef8007e86840e8ac9f8c2a6c52c7877b7554e87711efaab49d50a", - "0x063f62e3c507eb0102f9dbe887520db4a1d3d34c4279f646bc3fc2c76e074369", - "0xbeb28f46cc143db996e14fa35591cb5de4dcc92a569422f68f87f3f6a72a0e64", - "0x9a38f385833a2c1ea159031f12c3e1af4033860c389afb69d77d1b897f37c452", - "0xae6dbf3554a531e0ad6c51ec1e2201b41859f466dbb0ca3364fa7237fb0c60f3", - "0x789aca8285c9e0ce2deb306f2c2f0f53df9b3601e295bdc0838a8622bd697be6", - "0x230ebdcd6c3282992c8793f23eb847f955220f2a6c14bb82b38bc48ccf0cf1c4", - "0xad7f4b13ac995055b681cb64f90bfe2863582e49d1179b837ebde353117ab2b4", - "0xe40fc6bbacf5cfc1f6c41f06737d7df6274aef89a9c46bbe4fb8cb8484ffa54b", - "0xa78f1aa9b1a0a2130477c0ed9df303c033c5c852240689a9ec34347333defa42", - "0x3b10b4297066dbac52031920159034ef43544b77fc82c5fcc561df7208064b2f", - "0x5d73e6bb86089544825ca8c8ca2091744b7fd25bdd36a8b4d9941968be76a845", - "0x2f5d0deb26329807564b18ecbf24d9cb9d802d92369ea48c78fb973e1ea78994", - "0x086a6ff358bce56bcbc022978b1b84448143ae66de7f9e0c3f7a68bce7664135", - "0x8f36d90a6da392b377162caa1f81a5f0e3882c48794bea979bf79f119bb9284d", - "0xe0a475e8a6f9495b00a55d8472b108171bf11a51cb8db131c98c25a17d0ac78c", - "0x8ba00695bd7b524ff55fbbda3f17c6e93056e6895089de2ee29d58541e11b88f", - "0xf971ed0462249050dbeaa4a812c2b881957d4225587dcd10c88581ca6b096a36", - "0x229ab6e46f4be57cb81f8c7b2070f19827e55d4162c72b4abf26e618521eaaee", - "0x99601bf74f39ef88dabd853b40e86bc9653899a93af85518fe73ecf372578588", - "0x5deaa0abfd7689d3c33543a3d3b1bebc3dba46acd72246775fabb0bb5561e410", - "0x413bada477356cdf02680950e2d0368ce3614eccc4a6c245fabd54ee07253f60", - ], - "transactionsRoot": "0xb293e2c4ce20a9eac253241e750a5592c9d3c1b27bf090d0fc2fa4756a038866", - } - `) - - expect( - transaction.format({ - accessList: [], - blockHash: - '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', - blockNumber: '0x1', - chainId: '0x1', - feeCurrency: null, - from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - gas: '0x2', - gasPrice: undefined, - gatewayFee: '0x3', - gatewayFeeRecipient: null, - hash: '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', - input: - '0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0', - maxFeePerGas: '0x4', - maxPriorityFeePerGas: '0x5', - nonce: '0x6', - r: '0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca', - s: '0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0', - to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', - transactionIndex: '0x7', - type: '0x2', - v: '0x1', - value: '0x0', - }), - ).toMatchInlineSnapshot(` - { - "accessList": [], - "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", - "blockNumber": 1n, - "chainId": 1, - "feeCurrency": null, - "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "gas": 2n, - "gasPrice": undefined, - "gatewayFee": 3n, - "gatewayFeeRecipient": null, - "hash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", - "input": "0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0", - "maxFeePerGas": 4n, - "maxPriorityFeePerGas": 5n, - "nonce": 6, - "r": "0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca", - "s": "0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0", - "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", - "transactionIndex": 7, - "type": "eip1559", - "typeHex": "0x2", - "v": 1n, - "value": 0n, - } - `) - - expect( - transaction.format({ - accessList: [], - blockHash: - '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', - blockNumber: '0x1', - chainId: '0x1', - feeCurrency: null, - from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - gas: '0x2', - gasPrice: undefined, - gatewayFee: null, - gatewayFeeRecipient: null, - hash: '0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b', - input: - '0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0', - maxFeePerGas: '0x4', - maxPriorityFeePerGas: '0x5', - nonce: '0x6', - r: '0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca', - s: '0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0', - to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', - transactionIndex: '0x7', - type: '0x2', - v: '0x1', - value: '0x0', - }), - ).toMatchInlineSnapshot(` - { - "accessList": [], - "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", - "blockNumber": 1n, - "chainId": 1, - "feeCurrency": null, - "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "gas": 2n, - "gasPrice": undefined, - "gatewayFee": null, - "gatewayFeeRecipient": null, - "hash": "0xa4b1f606b66105fa45cb5db23d2f6597075701e7f0e2367f4e6a39d17a8cf98b", - "input": "0x23b872dd000000000000000000000000a00f99bc38b1ecda1fd70eaa1cd31d576a9f46b0000000000000000000000000f16e9b0d03470827a95cdfd0cb8a8a3b46969b910000000000000000000000000000000000000000000000000000002b3b6fb3d0", - "maxFeePerGas": 4n, - "maxPriorityFeePerGas": 5n, - "nonce": 6, - "r": "0x5e49a7bd0534c6b6d3bbe581659424d3747f920d40ce56e48d26e5d94aac32ca", - "s": "0x1746abe27b7c4f00bda1ec714ac1f7083e9025b6ca3b2248e439a173e4ab55e0", - "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", - "transactionIndex": 7, - "type": "eip1559", - "typeHex": "0x2", - "v": 1n, - "value": 0n, - } - `) - - expect( - transactionReceipt.format({ - blockHash: - '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', - blockNumber: '0x1', - contractAddress: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - cumulativeGasUsed: '0x2', - effectiveGasPrice: '0x3', - feeCurrency: null, - from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - gasUsed: '0x4', - gatewayFee: null, - gatewayFeeRecipient: null, - logs: [], - to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', - status: '0x0', - type: '0x0', - }), - ).toMatchInlineSnapshot(` - { - "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", - "blockNumber": 1n, - "contractAddress": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "cumulativeGasUsed": 2n, - "effectiveGasPrice": 3n, - "feeCurrency": null, - "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "gasUsed": 4n, - "gatewayFee": null, - "gatewayFeeRecipient": null, - "logs": [], - "status": "reverted", - "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", - "transactionIndex": null, - "type": "legacy", - } - `) - - expect( - transactionReceipt.format({ - blockHash: - '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', - blockNumber: '0x1', - contractAddress: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - cumulativeGasUsed: '0x2', - effectiveGasPrice: '0x3', - feeCurrency: null, - from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', - gasUsed: '0x4', - gatewayFee: '0x123', - gatewayFeeRecipient: null, - logs: [], - to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da', - status: '0x0', - type: '0x0', - }), - ).toMatchInlineSnapshot(` - { - "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d", - "blockNumber": 1n, - "contractAddress": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "cumulativeGasUsed": 2n, - "effectiveGasPrice": 3n, - "feeCurrency": null, - "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e", - "gasUsed": 4n, - "gatewayFee": 291n, - "gatewayFeeRecipient": null, - "logs": [], - "status": "reverted", - "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da", - "transactionIndex": null, - "type": "legacy", - } - `) - - expect( - transactionRequest.format({ - feeCurrency: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', - from: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', - gas: 1n, - gatewayFee: 4n, - gatewayFeeRecipient: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9', - maxFeePerGas: 2n, - maxPriorityFeePerGas: 1n, - nonce: 1, - value: 1n, - }), - ).toMatchInlineSnapshot(` - { - "feeCurrency": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", - "from": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", - "gas": "0x1", - "gasPrice": undefined, - "gatewayFee": "0x4", - "gatewayFeeRecipient": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9", - "maxFeePerGas": "0x2", - "maxPriorityFeePerGas": "0x1", - "nonce": "0x1", - "value": "0x1", - } - `) - }) -}) diff --git a/src/chains/index.ts b/src/chains/index.ts index 122c5c92c3..e858a93466 100644 --- a/src/chains/index.ts +++ b/src/chains/index.ts @@ -1,9 +1,9 @@ import * as chains from '@wagmi/chains' import { defineChain } from '../utils/chain.js' -import { formattersCelo } from './formatters/celo.js' -import { formattersOptimism } from './formatters/optimism.js' -import { serializersCelo } from './serializers/celo.js' +import { formattersCelo } from './celo/formatters.js' +import { serializersCelo } from './celo/serializers.js' +import { formattersOptimism } from './optimism/formatters.js' export const arbitrum = /*#__PURE__*/ defineChain(chains.arbitrum) export const arbitrumGoerli = /*#__PURE__*/ defineChain(chains.arbitrumGoerli) diff --git a/src/chains/formatters/optimism.test-d.ts b/src/chains/optimism/formatters.test-d.ts similarity index 74% rename from src/chains/formatters/optimism.test-d.ts rename to src/chains/optimism/formatters.test-d.ts index 8d3c2a4851..dc1841357f 100644 --- a/src/chains/formatters/optimism.test-d.ts +++ b/src/chains/optimism/formatters.test-d.ts @@ -2,18 +2,27 @@ import { describe, expectTypeOf, test } from 'vitest' import { getBlock } from '../../actions/public/getBlock.js' import { getTransaction } from '../../actions/public/getTransaction.js' +import { getTransactionReceipt } from '../../actions/public/getTransactionReceipt.js' import { createPublicClient } from '../../clients/createPublicClient.js' import { http } from '../../clients/transports/http.js' import type { Hash } from '../../types/misc.js' -import type { RpcBlock, RpcTransaction } from '../../types/rpc.js' +import type { RpcBlock } from '../../types/rpc.js' +import type { Assign } from '../../types/utils.js' import { optimism } from '../index.js' -import { type RpcDepositTransaction, formattersOptimism } from './optimism.js' +import { formattersOptimism } from './formatters.js' +import type { + OptimismRpcBlockOverrides, + OptimismRpcTransaction, +} from './types.js' describe('block', () => { expectTypeOf(formattersOptimism.block.format).parameter(0).toEqualTypeOf< - Partial & { - transactions: `0x${string}`[] | (RpcTransaction | RpcDepositTransaction)[] - } + Assign< + Partial, + OptimismRpcBlockOverrides & { + transactions: `0x${string}`[] | OptimismRpcTransaction[] + } + > >() }) @@ -91,4 +100,20 @@ describe('smoke', () => { transaction.type === 'eip1559' && transaction.mint, ).toEqualTypeOf() }) + + test('transaction receipt', async () => { + const client = createPublicClient({ + chain: optimism, + transport: http(), + }) + + const transactionReceipt = await getTransactionReceipt(client, { + hash: '0x', + }) + + expectTypeOf(transactionReceipt.l1Fee).toEqualTypeOf() + expectTypeOf(transactionReceipt.l1FeeScalar).toEqualTypeOf() + expectTypeOf(transactionReceipt.l1GasPrice).toEqualTypeOf() + expectTypeOf(transactionReceipt.l1GasUsed).toEqualTypeOf() + }) }) diff --git a/src/chains/optimism/formatters.test.ts b/src/chains/optimism/formatters.test.ts new file mode 100644 index 0000000000..33a17ff9c3 --- /dev/null +++ b/src/chains/optimism/formatters.test.ts @@ -0,0 +1,685 @@ +import { describe, expect, test } from 'vitest' + +import { getBlock } from '../../actions/public/getBlock.js' +import { getTransaction } from '../../actions/public/getTransaction.js' +import { getTransactionReceipt } from '../../actions/public/getTransactionReceipt.js' +import { createPublicClient } from '../../clients/createPublicClient.js' +import { http } from '../../clients/transports/http.js' +import { optimism } from '../index.js' + +describe('block', () => { + test('formatter', async () => { + const { block } = optimism.formatters! + + expect( + block.format({ + baseFeePerGas: '0x1', + difficulty: '0x0', + gasLimit: '0x420', + gasUsed: '0x69', + hash: '0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846', + logsBloom: + '0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010', + miner: '0x4200000000000000000000000000000000000011', + mixHash: + '0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887', + nonce: '0x0000000000000000', + number: '0x69420', + parentHash: + '0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6', + receiptsRoot: + '0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde', + sha3Uncles: + '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', + size: '0x69420', + stateRoot: + '0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746', + timestamp: '0xa42069', + totalDifficulty: '0x0', + transactionsRoot: + '0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5', + transactions: [ + { + blockHash: + '0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846', + blockNumber: '0x1', + from: '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001', + gas: '0x420', + hash: '0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a', + maxFeePerGas: '0x0', + maxPriorityFeePerGas: '0x0', + input: + '0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0', + mint: '0x0', + nonce: '0x420', + r: '0x0', + s: '0x0', + sourceHash: + '0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df', + to: '0x4200000000000000000000000000000000000015', + transactionIndex: '0x0', + type: '0x7e', + v: '0x0', + value: '0x0', + }, + { + blockHash: + '0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846', + blockNumber: '0x1', + from: '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001', + gas: '0x420', + hash: '0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a', + maxFeePerGas: '0x0', + maxPriorityFeePerGas: '0x0', + input: + '0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0', + mint: undefined, + nonce: '0x420', + r: '0x0', + s: '0x0', + sourceHash: + '0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df', + to: '0x4200000000000000000000000000000000000015', + transactionIndex: '0x0', + type: '0x7e', + v: '0x0', + value: '0x0', + }, + ], + uncles: [], + }), + ).toMatchInlineSnapshot(` + { + "baseFeePerGas": 1n, + "difficulty": 0n, + "gasLimit": 1056n, + "gasUsed": 105n, + "hash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", + "logsBloom": "0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010", + "miner": "0x4200000000000000000000000000000000000011", + "mixHash": "0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887", + "nonce": "0x0000000000000000", + "number": 431136n, + "parentHash": "0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6", + "receiptsRoot": "0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde", + "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "size": 431136n, + "stateRoot": "0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746", + "timestamp": 10756201n, + "totalDifficulty": 0n, + "transactions": [ + { + "blockHash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", + "blockNumber": 1n, + "chainId": undefined, + "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", + "gas": 1056n, + "gasPrice": undefined, + "hash": "0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a", + "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0", + "isSystemTx": undefined, + "maxFeePerGas": 0n, + "maxPriorityFeePerGas": 0n, + "mint": 0n, + "nonce": 1056, + "r": "0x0", + "s": "0x0", + "sourceHash": "0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df", + "to": "0x4200000000000000000000000000000000000015", + "transactionIndex": 0, + "type": "deposit", + "typeHex": "0x7e", + "v": 0n, + "value": 0n, + }, + { + "blockHash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", + "blockNumber": 1n, + "chainId": undefined, + "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", + "gas": 1056n, + "gasPrice": undefined, + "hash": "0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a", + "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0", + "isSystemTx": undefined, + "maxFeePerGas": 0n, + "maxPriorityFeePerGas": 0n, + "mint": undefined, + "nonce": 1056, + "r": "0x0", + "s": "0x0", + "sourceHash": "0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df", + "to": "0x4200000000000000000000000000000000000015", + "transactionIndex": 0, + "type": "deposit", + "typeHex": "0x7e", + "v": 0n, + "value": 0n, + }, + ], + "transactionsRoot": "0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5", + "uncles": [], + } + `) + + expect( + block.format({ + baseFeePerGas: '0x1', + difficulty: '0x0', + gasLimit: '0x420', + gasUsed: '0x69', + hash: '0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846', + logsBloom: + '0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010', + miner: '0x4200000000000000000000000000000000000011', + mixHash: + '0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887', + nonce: '0x0000000000000000', + number: '0x69420', + parentHash: + '0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6', + receiptsRoot: + '0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde', + sha3Uncles: + '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', + size: '0x69420', + stateRoot: + '0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746', + timestamp: '0xa42069', + totalDifficulty: '0x0', + transactionsRoot: + '0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5', + transactions: ['0x'], + uncles: [], + }), + ).toMatchInlineSnapshot(` + { + "baseFeePerGas": 1n, + "difficulty": 0n, + "gasLimit": 1056n, + "gasUsed": 105n, + "hash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", + "logsBloom": "0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010", + "miner": "0x4200000000000000000000000000000000000011", + "mixHash": "0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887", + "nonce": "0x0000000000000000", + "number": 431136n, + "parentHash": "0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6", + "receiptsRoot": "0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde", + "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "size": 431136n, + "stateRoot": "0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746", + "timestamp": 10756201n, + "totalDifficulty": 0n, + "transactions": [ + "0x", + ], + "transactionsRoot": "0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5", + "uncles": [], + } + `) + }) + + test('action', async () => { + const client = createPublicClient({ + chain: optimism, + transport: http(), + }) + const block = await getBlock(client, { + blockNumber: 105849734n, + includeTransactions: true, + }) + + const { extraData: _extraData, transactions, ...rest } = block + expect(transactions[0]).toMatchInlineSnapshot(` + { + "blockHash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", + "blockNumber": 105849734n, + "chainId": undefined, + "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", + "gas": 1000000n, + "gasPrice": 0n, + "hash": "0xf169b1021e555a1088b69e693938efd32a98231417eda1fb024de83aad98663a", + "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000010b6402000000000000000000000000000000000000000000000000000000006492207b000000000000000000000000000000000000000000000000000000033601dfdd1eca1cc72d59c84864665457586b5e8910fb78a19fbffd1a23190862dc7f9dd900000000000000000000000000000000000000000000000000000000000000000000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0", + "isSystemTx": undefined, + "maxFeePerGas": undefined, + "maxPriorityFeePerGas": undefined, + "mint": 0n, + "nonce": 614670, + "r": "0x0", + "s": "0x0", + "sourceHash": "0x0456be3615ad9f8bb63410c832db98c02d4fdeda0139f4f98186970aef5111df", + "to": "0x4200000000000000000000000000000000000015", + "transactionIndex": 0, + "type": "deposit", + "typeHex": "0x7e", + "v": 0n, + "value": 0n, + } + `) + expect(rest).toMatchInlineSnapshot(` + { + "baseFeePerGas": 83n, + "difficulty": 0n, + "gasLimit": 30000000n, + "gasUsed": 1414689n, + "hash": "0x40b65fabd4bdda5bb716b1a39e761d76a968d5cc54d887d05b47ac6c2c298846", + "logsBloom": "0x0000008002000011000c200080000012000010000400000010040000001000a010001010400002810016001000100001080000090000008020804000002022408010c800290400202090000c000020000081000080440000200000000460800100000000024000400040480002132800000010800000040802000198020000000012000000804001401000000000000001840000002000000000004000000000268080000008c1a024000804000800020000200000080000004000a0000000008404000208000000000800015030000001800250000800001001000a100030001010811020000008000000000040100804001000409000000000480008010010", + "miner": "0x4200000000000000000000000000000000000011", + "mixHash": "0x324be0a5ff604a0e2c11541ebfd5850046d6d9044fb2e3c93716080cb02f4887", + "nonce": "0x0000000000000000", + "number": 105849734n, + "parentHash": "0x15274362f5bf7aa966ec2eb95c972fd85f2917da803ab178bced6a53479752b6", + "receiptsRoot": "0x4cfa86d92cf2d52d2bca8b901592a5a0444be409793f0a4c2af006c0c7aafbde", + "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "size": 4072n, + "stateRoot": "0x95676f3a28d2c8a0bf64db60e910dc47275d37f5a3c3d7353b6f571c25fcd746", + "timestamp": 1687298245n, + "totalDifficulty": 0n, + "transactionsRoot": "0xe41f41da49507646478023c060078f8afa962973ac38da1f7efd0355363b31d5", + "uncles": [], + } + `) + }) +}) + +describe('transaction', () => { + test('formatter', () => { + const { transaction } = optimism.formatters! + + expect( + transaction.format({ + accessList: [], + blockHash: + '0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574', + blockNumber: '0x1', + chainId: '0x1', + from: '0xacd03d601e5bb1b275bb94076ff46ed9d753435a', + gas: '0x69', + hash: '0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822', + input: '0x', + maxFeePerGas: '0x1', + maxPriorityFeePerGas: '0x2', + nonce: '0x3', + r: '0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e', + s: '0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a', + to: '0xeb610a69341aace81ed810ed42428249512378cd', + transactionIndex: '0x4', + type: '0x2', + v: '0x1', + value: '0x69', + }), + ).toMatchInlineSnapshot(` + { + "accessList": [], + "blockHash": "0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574", + "blockNumber": 1n, + "chainId": 1, + "from": "0xacd03d601e5bb1b275bb94076ff46ed9d753435a", + "gas": 105n, + "gasPrice": undefined, + "hash": "0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822", + "input": "0x", + "maxFeePerGas": 1n, + "maxPriorityFeePerGas": 2n, + "nonce": 3, + "r": "0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e", + "s": "0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a", + "to": "0xeb610a69341aace81ed810ed42428249512378cd", + "transactionIndex": 4, + "type": "eip1559", + "typeHex": "0x2", + "v": 1n, + "value": 105n, + } + `) + }) + + test('action', async () => { + const client = createPublicClient({ + chain: optimism, + transport: http(), + }) + + const transaction = await getTransaction(client, { + hash: '0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822', + }) + + expect(transaction).toMatchInlineSnapshot(` + { + "accessList": [], + "blockHash": "0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574", + "blockNumber": 105848892n, + "chainId": 10, + "from": "0xacd03d601e5bb1b275bb94076ff46ed9d753435a", + "gas": 21000n, + "gasPrice": 267n, + "hash": "0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822", + "input": "0x", + "maxFeePerGas": 191000n, + "maxPriorityFeePerGas": 191n, + "nonce": 775017, + "r": "0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e", + "s": "0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a", + "to": "0xeb610a69341aace81ed810ed42428249512378cd", + "transactionIndex": 7, + "type": "eip1559", + "typeHex": "0x2", + "v": 1n, + "value": 650000000000000n, + } + `) + }) +}) + +describe('transaction (deposit)', () => { + test('formatter', () => { + const { transaction } = optimism.formatters! + + expect( + transaction.format({ + accessList: [], + blockHash: + '0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574', + blockNumber: '0x1', + chainId: '0x1', + from: '0xacd03d601e5bb1b275bb94076ff46ed9d753435a', + gas: '0x69', + hash: '0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822', + input: '0x', + maxFeePerGas: '0x1', + maxPriorityFeePerGas: '0x2', + nonce: '0x3', + r: '0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e', + s: '0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a', + sourceHash: '0x', + to: '0xeb610a69341aace81ed810ed42428249512378cd', + transactionIndex: '0x4', + type: '0x7e', + v: '0x1', + value: '0x69', + }), + ).toMatchInlineSnapshot(` + { + "accessList": [], + "blockHash": "0xd981071322be9757dc3b5479a84d61b4f1f5dd2d44ecb66463be6cfc8246f574", + "blockNumber": 1n, + "chainId": 1, + "from": "0xacd03d601e5bb1b275bb94076ff46ed9d753435a", + "gas": 105n, + "gasPrice": undefined, + "hash": "0x64241d12d64bb6106a9e818d83d4c9f5d49ebef3c6180e58979bf5894461f822", + "input": "0x", + "isSystemTx": undefined, + "maxFeePerGas": 1n, + "maxPriorityFeePerGas": 2n, + "mint": undefined, + "nonce": 3, + "r": "0xf5272819865bb23110822bedd12b4f14a9b89ca113e280d40ec06c83d126090e", + "s": "0xaaa4249c6b174d714cd6d1eaf1a15a9549769addfcc6d846524f1f8ce38178a", + "sourceHash": "0x", + "to": "0xeb610a69341aace81ed810ed42428249512378cd", + "transactionIndex": 4, + "type": "deposit", + "typeHex": "0x7e", + "v": 1n, + "value": 105n, + } + `) + }) + + test('action', async () => { + const client = createPublicClient({ + chain: optimism, + transport: http(), + }) + + const transaction = await getTransaction(client, { + hash: '0x97f8e79b683df44ae2cc2e9f6eeebd2febdd6f0aeda71f184e6b297cbe7f620b', + }) + + expect(transaction).toMatchInlineSnapshot(` + { + "blockHash": "0x7c04fe001ea0efd91d5eea232e6936a2b94af8d238e56f0e025d264a55e65a58", + "blockNumber": 105847831n, + "chainId": undefined, + "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001", + "gas": 1000000n, + "gasPrice": 0n, + "hash": "0x97f8e79b683df44ae2cc2e9f6eeebd2febdd6f0aeda71f184e6b297cbe7f620b", + "input": "0x015d8eb900000000000000000000000000000000000000000000000000000000010b62c6000000000000000000000000000000000000000000000000000000006492119f000000000000000000000000000000000000000000000000000000078e016aff6b099ac98f4d1e69a45ad7bccba81386deddee0569412aafb388d8c1510f9e0800000000000000000000000000000000000000000000000000000000000000020000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f3298500000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0", + "isSystemTx": undefined, + "maxFeePerGas": undefined, + "maxPriorityFeePerGas": undefined, + "mint": 0n, + "nonce": 612767, + "r": "0x0", + "s": "0x0", + "sourceHash": "0x3fd7eb0bfa68ab126d745d17de615819430e1a6e922f65e5c06418569eb8dee1", + "to": "0x4200000000000000000000000000000000000015", + "transactionIndex": 0, + "type": "deposit", + "typeHex": "0x7e", + "v": 0n, + "value": 0n, + } + `) + }) +}) + +describe('transaction receipt', async () => { + test('formatter', () => { + const { transactionReceipt } = optimism.formatters! + + expect( + transactionReceipt.format({ + blockHash: + '0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0', + blockNumber: '0x1', + contractAddress: null, + cumulativeGasUsed: '0x1', + effectiveGasPrice: '0x1', + from: '0x24476ac81915c512b0e13207aa917923fba4a16a', + gasUsed: '0x42069', + l1Fee: '0x420', + l1FeeScalar: '1.5', + l1GasPrice: '0x69', + l1GasUsed: '0x1', + logs: [], + logsBloom: + '0x00000000000000004000000000000000000040000000021000000000000010102000000000000000000080000010000000000000000000000000000000000000004000000000000000000008000008000000000000000000000000000000000000040000060000000080100000000800000000000000000000000010000100000000000400000000000000000000000000000000280000000000000000000000000000004000020000000004000000008000000000000000000000000010000000001002000008000000000000000000000000000000000000000000000020001000800000000000000000002000100000010000000000000000000000000000', + status: '0x1', + to: '0xdd69db25f6d620a7bad3023c5d32761d353d3de9', + transactionHash: + '0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3', + transactionIndex: '0x1', + type: '0x2', + }), + ).toMatchInlineSnapshot(` + { + "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", + "blockNumber": 1n, + "contractAddress": null, + "cumulativeGasUsed": 1n, + "effectiveGasPrice": 1n, + "from": "0x24476ac81915c512b0e13207aa917923fba4a16a", + "gasUsed": 270441n, + "l1Fee": 1056n, + "l1FeeScalar": 1.5, + "l1GasPrice": 105n, + "l1GasUsed": 1n, + "logs": [], + "logsBloom": "0x00000000000000004000000000000000000040000000021000000000000010102000000000000000000080000010000000000000000000000000000000000000004000000000000000000008000008000000000000000000000000000000000000040000060000000080100000000800000000000000000000000010000100000000000400000000000000000000000000000000280000000000000000000000000000004000020000000004000000008000000000000000000000000010000000001002000008000000000000000000000000000000000000000000000020001000800000000000000000002000100000010000000000000000000000000000", + "status": "success", + "to": "0xdd69db25f6d620a7bad3023c5d32761d353d3de9", + "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", + "transactionIndex": 1, + "type": "eip1559", + } + `) + + expect( + transactionReceipt.format({ + blockHash: + '0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0', + blockNumber: '0x1', + contractAddress: null, + cumulativeGasUsed: '0x1', + effectiveGasPrice: '0x1', + from: '0x24476ac81915c512b0e13207aa917923fba4a16a', + gasUsed: '0x42069', + l1Fee: null, + l1FeeScalar: null, + l1GasPrice: null, + l1GasUsed: null, + logs: [], + logsBloom: + '0x00000000000000004000000000000000000040000000021000000000000010102000000000000000000080000010000000000000000000000000000000000000004000000000000000000008000008000000000000000000000000000000000000040000060000000080100000000800000000000000000000000010000100000000000400000000000000000000000000000000280000000000000000000000000000004000020000000004000000008000000000000000000000000010000000001002000008000000000000000000000000000000000000000000000020001000800000000000000000002000100000010000000000000000000000000000', + status: '0x1', + to: '0xdd69db25f6d620a7bad3023c5d32761d353d3de9', + transactionHash: + '0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3', + transactionIndex: '0x1', + type: '0x2', + }), + ).toMatchInlineSnapshot(` + { + "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", + "blockNumber": 1n, + "contractAddress": null, + "cumulativeGasUsed": 1n, + "effectiveGasPrice": 1n, + "from": "0x24476ac81915c512b0e13207aa917923fba4a16a", + "gasUsed": 270441n, + "l1Fee": null, + "l1FeeScalar": null, + "l1GasPrice": null, + "l1GasUsed": null, + "logs": [], + "logsBloom": "0x00000000000000004000000000000000000040000000021000000000000010102000000000000000000080000010000000000000000000000000000000000000004000000000000000000008000008000000000000000000000000000000000000040000060000000080100000000800000000000000000000000010000100000000000400000000000000000000000000000000280000000000000000000000000000004000020000000004000000008000000000000000000000000010000000001002000008000000000000000000000000000000000000000000000020001000800000000000000000002000100000010000000000000000000000000000", + "status": "success", + "to": "0xdd69db25f6d620a7bad3023c5d32761d353d3de9", + "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", + "transactionIndex": 1, + "type": "eip1559", + } + `) + }) + + test('action', async () => { + const client = createPublicClient({ + chain: optimism, + transport: http(), + }) + + const transaction = await getTransactionReceipt(client, { + hash: '0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3', + }) + + expect(transaction).toMatchInlineSnapshot(` + { + "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", + "blockNumber": 106812538n, + "contractAddress": null, + "cumulativeGasUsed": 1431996n, + "effectiveGasPrice": 58n, + "from": "0x24476ac81915c512b0e13207aa917923fba4a16a", + "gasUsed": 228719n, + "l1Fee": 44700351261503n, + "l1FeeScalar": 0.684, + "l1GasPrice": 15694378178n, + "l1GasUsed": 4164n, + "logs": [ + { + "address": "0xdd69db25f6d620a7bad3023c5d32761d353d3de9", + "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", + "blockNumber": 106812538n, + "data": "0x000000000000000000000000000000000000000000000000008e1bc9bf040000", + "logIndex": 19, + "removed": false, + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x00000000000000000000000024476ac81915c512b0e13207aa917923fba4a16a", + "0x0000000000000000000000000000000000000000000000000000000000000000", + ], + "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", + "transactionIndex": 10, + }, + { + "address": "0x81e792e5a9003cc1c8bf5569a00f34b65d75b017", + "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", + "blockNumber": 106812538n, + "data": "0x000000000000000000000000000000000000000000000000000031a1add99f8b", + "logIndex": 20, + "removed": false, + "topics": [ + "0xdf21c415b78ed2552cc9971249e32a053abce6087a0ae0fbf3f78db5174a3493", + ], + "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", + "transactionIndex": 10, + }, + { + "address": "0x4d73adb72bc3dd368966edd0f0b2148401a178e2", + "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", + "blockNumber": 106812538n, + "data": "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002200010000000000000000000000000000000000000000000000000000000000030d40000000000000000000000000000000000000000000000000000000000000", + "logIndex": 21, + "removed": false, + "topics": [ + "0xb0c632f55f1e1b3b2c3d82f41ee4716bb4c00f0f5d84cdafc141581bb8757a4f", + ], + "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", + "transactionIndex": 10, + }, + { + "address": "0xa0cc33dd6f4819d473226257792afe230ec3c67f", + "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", + "blockNumber": 106812538n, + "data": "0x000000000000000000000000000000000000000000000000000000000000009a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000014000000000000000000000000dd69db25f6d620a7bad3023c5d32761d353d3de90000000000000000000000000000000000000000000000000000000124c9d6c5", + "logIndex": 22, + "removed": false, + "topics": [ + "0x4e41ee13e03cd5e0446487b524fdc48af6acf26c074dacdbdfb6b574b42c8146", + ], + "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", + "transactionIndex": 10, + }, + { + "address": "0x4d73adb72bc3dd368966edd0f0b2148401a178e2", + "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", + "blockNumber": 106812538n, + "data": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000d40000000000049d1a006fdd69db25f6d620a7bad3023c5d32761d353d3de9009a4f7a67464b5976d7547c860109e4432d50afb38e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000008e1bc9bf040000000000000000000000000000000000000000000000000000000000000000001424476ac81915c512b0e13207aa917923fba4a16a000000000000000000000000000000000000000000000000", + "logIndex": 23, + "removed": false, + "topics": [ + "0xe9bded5f24a4168e4f3bf44e00298c993b22376aad8c58c7dda9718a54cbea82", + ], + "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", + "transactionIndex": 10, + }, + { + "address": "0xdd69db25f6d620a7bad3023c5d32761d353d3de9", + "blockHash": "0x7f9f15ca4806d8f8deb2c73e82a2a153a2de668118e14e27a96cd672936449f0", + "blockNumber": 106812538n, + "data": "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000008e1bc9bf040000000000000000000000000000000000000000000000000000000000000000001424476ac81915c512b0e13207aa917923fba4a16a000000000000000000000000", + "logIndex": 24, + "removed": false, + "topics": [ + "0x39a4c66499bcf4b56d79f0dde8ed7a9d4925a0df55825206b2b8531e202be0d0", + "0x000000000000000000000000000000000000000000000000000000000000009a", + "0x00000000000000000000000024476ac81915c512b0e13207aa917923fba4a16a", + ], + "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", + "transactionIndex": 10, + }, + ], + "logsBloom": "0x00000000000000004000000000000000000040000000021000000000000010102000000000000000000080000010000000000000000000000000000000000000004000000000000000000008000008000000000000000000000000000000000000040000060000000080100000000800000000000000000000000010000100000000000400000000000000000000000000000000280000000000000000000000000000004000020000000004000000008000000000000000000000000010000000001002000008000000000000000000000000000000000000000000000020001000800000000000000000002000100000010000000000000000000000000000", + "status": "success", + "to": "0xdd69db25f6d620a7bad3023c5d32761d353d3de9", + "transactionHash": "0x4d8f0ebd260ea5ac2e11886cdd0af8cba982b21d9f9c1efad808212c6d6a65d3", + "transactionIndex": 10, + "type": "eip1559", + } + `) + }) +}) diff --git a/src/chains/optimism/formatters.ts b/src/chains/optimism/formatters.ts new file mode 100644 index 0000000000..c732aff514 --- /dev/null +++ b/src/chains/optimism/formatters.ts @@ -0,0 +1,74 @@ +import { type Formatters } from '../../types/formatter.js' +import type { Hash } from '../../types/misc.js' +import { type RpcTransaction } from '../../types/rpc.js' +import { hexToBigInt } from '../../utils/encoding/fromHex.js' +import { defineBlock } from '../../utils/formatters/block.js' +import { + defineTransaction, + formatTransaction, +} from '../../utils/formatters/transaction.js' +import { defineTransactionReceipt } from '../../utils/formatters/transactionReceipt.js' +import type { + OptimismBlockOverrides, + OptimismRpcBlockOverrides, + OptimismRpcTransaction, + OptimismRpcTransactionReceiptOverrides, + OptimismTransaction, + OptimismTransactionReceiptOverrides, +} from './types.js' + +export const formattersOptimism = { + block: /*#__PURE__*/ defineBlock({ + format( + args: OptimismRpcBlockOverrides & { + transactions: Hash[] | OptimismRpcTransaction[] + }, + ): OptimismBlockOverrides & { + transactions: Hash[] | OptimismTransaction[] + } { + const transactions = args.transactions?.map((transaction) => { + if (typeof transaction === 'string') return transaction + const formatted = formatTransaction( + transaction as RpcTransaction, + ) as OptimismTransaction + if (formatted.typeHex === '0x7e') { + formatted.isSystemTx = transaction.isSystemTx + formatted.mint = transaction.mint + ? hexToBigInt(transaction.mint) + : undefined + formatted.sourceHash = transaction.sourceHash + formatted.type = 'deposit' + } + return formatted + }) as Hash[] | OptimismTransaction[] + return { + transactions, + stateRoot: args.stateRoot, + } + }, + }), + transaction: /*#__PURE__*/ defineTransaction({ + format(args: OptimismRpcTransaction): OptimismTransaction { + const transaction = {} as OptimismTransaction + if (args.type === '0x7e') { + transaction.isSystemTx = args.isSystemTx + transaction.mint = args.mint ? hexToBigInt(args.mint) : undefined + transaction.sourceHash = args.sourceHash + transaction.type = 'deposit' + } + return transaction + }, + }), + transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({ + format( + args: OptimismRpcTransactionReceiptOverrides, + ): OptimismTransactionReceiptOverrides { + return { + l1GasPrice: args.l1GasPrice ? hexToBigInt(args.l1GasPrice) : null, + l1GasUsed: args.l1GasUsed ? hexToBigInt(args.l1GasUsed) : null, + l1Fee: args.l1Fee ? hexToBigInt(args.l1Fee) : null, + l1FeeScalar: args.l1FeeScalar ? Number(args.l1FeeScalar) : null, + } + }, + }), +} as const satisfies Formatters diff --git a/src/chains/optimism/index.test.ts b/src/chains/optimism/index.test.ts new file mode 100644 index 0000000000..43c885ee4f --- /dev/null +++ b/src/chains/optimism/index.test.ts @@ -0,0 +1,13 @@ +import { expect, test } from 'vitest' + +import * as actions from './index.js' + +test('exports', () => { + expect(Object.keys(actions)).toMatchInlineSnapshot(` + [ + "optimism", + "optimismGoerli", + "formattersOptimism", + ] + `) +}) diff --git a/src/chains/optimism/index.ts b/src/chains/optimism/index.ts new file mode 100644 index 0000000000..37615f94c4 --- /dev/null +++ b/src/chains/optimism/index.ts @@ -0,0 +1,18 @@ +export { optimism, optimismGoerli } from '../index.js' + +export { formattersOptimism } from './formatters.js' + +export type { + OptimismBlock, + OptimismBlockOverrides, + OptimismDepositTransaction, + OptimismRpcBlock, + OptimismRpcBlockOverrides, + OptimismRpcDepositTransaction, + OptimismRpcTransaction, + OptimismRpcTransactionReceipt, + OptimismRpcTransactionReceiptOverrides, + OptimismTransaction, + OptimismTransactionReceipt, + OptimismTransactionReceiptOverrides, +} from './types.js' diff --git a/src/chains/optimism/types.ts b/src/chains/optimism/types.ts new file mode 100644 index 0000000000..4c89f3e249 --- /dev/null +++ b/src/chains/optimism/types.ts @@ -0,0 +1,102 @@ +import type { Block, BlockTag } from '../../types/block.js' +import type { FeeValuesEIP1559 } from '../../types/fee.js' +import type { Hash, Hex } from '../../types/misc.js' +import type { + Index, + Quantity, + RpcBlock, + RpcTransaction as RpcTransaction_, + RpcTransactionReceipt, +} from '../../types/rpc.js' +import type { + Transaction as Transaction_, + TransactionBase, + TransactionReceipt, +} from '../../types/transaction.js' + +export type OptimismBlockOverrides = { + stateRoot: Hash +} +export type OptimismBlock< + TIncludeTransactions extends boolean = boolean, + TBlockTag extends BlockTag = BlockTag, +> = Block< + bigint, + TIncludeTransactions, + TBlockTag, + OptimismTransaction +> & + OptimismBlockOverrides + +export type OptimismRpcBlockOverrides = { + stateRoot: Hash +} +export type OptimismRpcBlock< + TBlockTag extends BlockTag = BlockTag, + TIncludeTransactions extends boolean = boolean, +> = RpcBlock< + TBlockTag, + TIncludeTransactions, + OptimismRpcTransaction +> & + OptimismRpcBlockOverrides + +type RpcTransaction = + RpcTransaction_ & { + isSystemTx?: undefined + mint?: undefined + sourceHash?: undefined + } + +export type OptimismRpcDepositTransaction = + Omit, 'typeHex'> & + FeeValuesEIP1559 & { + isSystemTx?: boolean + mint?: Hex + sourceHash: Hex + type: '0x7e' + } +export type OptimismRpcTransaction = + | RpcTransaction + | OptimismRpcDepositTransaction + +export type OptimismRpcTransactionReceiptOverrides = { + l1GasPrice: Hex | null + l1GasUsed: Hex | null + l1Fee: Hex | null + l1FeeScalar: `${number}` | null +} +export type OptimismRpcTransactionReceipt = RpcTransactionReceipt & + OptimismRpcTransactionReceiptOverrides + +type Transaction = Transaction_< + bigint, + number, + TPending +> & { + isSystemTx?: undefined + mint?: undefined + sourceHash?: undefined +} + +export type OptimismDepositTransaction = + TransactionBase & + FeeValuesEIP1559 & { + isSystemTx?: boolean + mint?: bigint + sourceHash: Hex + type: 'deposit' + } + +export type OptimismTransaction = + | Transaction + | OptimismDepositTransaction + +export type OptimismTransactionReceiptOverrides = { + l1GasPrice: bigint | null + l1GasUsed: bigint | null + l1Fee: bigint | null + l1FeeScalar: number | null +} +export type OptimismTransactionReceipt = TransactionReceipt & + OptimismTransactionReceiptOverrides diff --git a/src/types/rpc.ts b/src/types/rpc.ts index bef30f1706..c6bd1aabc5 100644 --- a/src/types/rpc.ts +++ b/src/types/rpc.ts @@ -26,12 +26,8 @@ export type TransactionType = '0x0' | '0x1' | '0x2' | (string & {}) export type RpcBlock< TBlockTag extends BlockTag = BlockTag, TIncludeTransactions extends boolean = boolean, -> = Block< - Quantity, - TIncludeTransactions, - TBlockTag, - RpcTransaction -> + TTransaction = RpcTransaction, +> = Block export type RpcBlockNumber = BlockNumber export type RpcBlockIdentifier = BlockIdentifier export type RpcUncle = Uncle diff --git a/src/types/utils.ts b/src/types/utils.ts index 1d139fe8db..b07f9a5a94 100644 --- a/src/types/utils.ts +++ b/src/types/utils.ts @@ -155,6 +155,17 @@ export type OptionalNullable = { [K in keyof T as T[K] extends NonNullable ? never : K]?: T[K] } +/** + * @description Make properties K of type T never. + * + * @example + * NeverBy<{ a: string, b: boolean, c: number }, 'a' | 'c'> + * => { a: never, b: boolean, c: never } + */ +export type NeverBy = { + [U in keyof T]: U extends K ? never : T[U] +} + /** * @description Constructs a type by excluding `undefined` from `T`. * diff --git a/src/utils/formatters/formatter.ts b/src/utils/formatters/formatter.ts index b8cfc943b5..4c789cb689 100644 --- a/src/utils/formatters/formatter.ts +++ b/src/utils/formatters/formatter.ts @@ -17,8 +17,8 @@ export function defineFormatter( }) => { return { exclude, - format: (args: TParameters & TOverrideParameters) => { - const formatted = format(args) + format: (args: Assign) => { + const formatted = format(args as any) if (exclude) { for (const key of exclude) { delete (formatted as any)[key]