viem 0.0.0-main.20230620T232415 → 0.0.0-main.20230621T010720
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chains/package.json +3 -3
- package/dist/cjs/actions/public/call.js +3 -6
- package/dist/cjs/actions/public/call.js.map +1 -1
- package/dist/cjs/actions/public/estimateContractGas.js.map +1 -1
- package/dist/cjs/actions/public/estimateGas.js +3 -6
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/actions/public/getBlock.js +2 -4
- package/dist/cjs/actions/public/getBlock.js.map +1 -1
- package/dist/cjs/actions/public/getTransaction.js +2 -4
- package/dist/cjs/actions/public/getTransaction.js.map +1 -1
- package/dist/cjs/actions/public/getTransactionConfirmations.js.map +1 -1
- package/dist/cjs/actions/public/getTransactionReceipt.js +2 -4
- package/dist/cjs/actions/public/getTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/public/simulateContract.js.map +1 -1
- package/dist/cjs/actions/public/watchBlocks.js +2 -4
- package/dist/cjs/actions/public/watchBlocks.js.map +1 -1
- package/dist/cjs/actions/test/sendUnsignedTransaction.js +3 -6
- package/dist/cjs/actions/test/sendUnsignedTransaction.js.map +1 -1
- package/dist/cjs/actions/wallet/sendTransaction.js +3 -6
- package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/cjs/chains/formatters/celo.js +62 -0
- package/dist/cjs/chains/formatters/celo.js.map +1 -0
- package/dist/cjs/chains/formatters/optimism.js +43 -0
- package/dist/cjs/chains/formatters/optimism.js.map +1 -0
- package/dist/cjs/{chains.js → chains/index.js} +16 -50
- package/dist/cjs/chains/index.js.map +1 -0
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/serializer.js +3 -0
- package/dist/cjs/types/serializer.js.map +1 -0
- package/dist/cjs/utils/chain.js +6 -2
- package/dist/cjs/utils/chain.js.map +1 -1
- package/dist/cjs/utils/formatters/block.js +2 -4
- package/dist/cjs/utils/formatters/block.js.map +1 -1
- package/dist/cjs/utils/formatters/formatter.js +21 -0
- package/dist/cjs/utils/formatters/formatter.js.map +1 -0
- package/dist/cjs/utils/formatters/transaction.js +3 -4
- package/dist/cjs/utils/formatters/transaction.js.map +1 -1
- package/dist/cjs/utils/formatters/transactionReceipt.js +2 -4
- package/dist/cjs/utils/formatters/transactionReceipt.js.map +1 -1
- package/dist/cjs/utils/formatters/transactionRequest.js +2 -4
- package/dist/cjs/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/cjs/utils/index.js +4 -5
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/wallet.js.map +1 -1
- package/dist/esm/actions/public/call.js +3 -6
- package/dist/esm/actions/public/call.js.map +1 -1
- package/dist/esm/actions/public/estimateContractGas.js.map +1 -1
- package/dist/esm/actions/public/estimateGas.js +3 -6
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/actions/public/getBlock.js +2 -4
- package/dist/esm/actions/public/getBlock.js.map +1 -1
- package/dist/esm/actions/public/getTransaction.js +2 -4
- package/dist/esm/actions/public/getTransaction.js.map +1 -1
- package/dist/esm/actions/public/getTransactionConfirmations.js.map +1 -1
- package/dist/esm/actions/public/getTransactionReceipt.js +2 -4
- package/dist/esm/actions/public/getTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/public/simulateContract.js.map +1 -1
- package/dist/esm/actions/public/watchBlocks.js +2 -4
- package/dist/esm/actions/public/watchBlocks.js.map +1 -1
- package/dist/esm/actions/test/sendUnsignedTransaction.js +3 -6
- package/dist/esm/actions/test/sendUnsignedTransaction.js.map +1 -1
- package/dist/esm/actions/wallet/sendTransaction.js +3 -6
- package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/esm/chains/formatters/celo.js +59 -0
- package/dist/esm/chains/formatters/celo.js.map +1 -0
- package/dist/esm/chains/formatters/optimism.js +40 -0
- package/dist/esm/chains/formatters/optimism.js.map +1 -0
- package/dist/esm/{chains.js → chains/index.js} +13 -47
- package/dist/esm/chains/index.js.map +1 -0
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/serializer.js +2 -0
- package/dist/esm/types/serializer.js.map +1 -0
- package/dist/esm/utils/chain.js +6 -2
- package/dist/esm/utils/chain.js.map +1 -1
- package/dist/esm/utils/formatters/block.js +2 -5
- package/dist/esm/utils/formatters/block.js.map +1 -1
- package/dist/esm/utils/formatters/formatter.js +17 -0
- package/dist/esm/utils/formatters/formatter.js.map +1 -0
- package/dist/esm/utils/formatters/transaction.js +4 -4
- package/dist/esm/utils/formatters/transaction.js.map +1 -1
- package/dist/esm/utils/formatters/transactionReceipt.js +2 -4
- package/dist/esm/utils/formatters/transactionReceipt.js.map +1 -1
- package/dist/esm/utils/formatters/transactionRequest.js +2 -4
- package/dist/esm/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/wallet.js.map +1 -1
- package/dist/types/actions/public/call.d.ts +3 -7
- package/dist/types/actions/public/call.d.ts.map +1 -1
- package/dist/types/actions/public/estimateContractGas.d.ts +1 -1
- package/dist/types/actions/public/estimateContractGas.d.ts.map +1 -1
- package/dist/types/actions/public/estimateGas.d.ts +3 -7
- package/dist/types/actions/public/estimateGas.d.ts.map +1 -1
- package/dist/types/actions/public/getBlock.d.ts +2 -2
- package/dist/types/actions/public/getBlock.d.ts.map +1 -1
- package/dist/types/actions/public/getTransaction.d.ts +2 -2
- package/dist/types/actions/public/getTransaction.d.ts.map +1 -1
- package/dist/types/actions/public/getTransactionConfirmations.d.ts +2 -2
- package/dist/types/actions/public/getTransactionConfirmations.d.ts.map +1 -1
- package/dist/types/actions/public/getTransactionReceipt.d.ts +3 -3
- package/dist/types/actions/public/getTransactionReceipt.d.ts.map +1 -1
- package/dist/types/actions/public/simulateContract.d.ts +1 -1
- package/dist/types/actions/public/simulateContract.d.ts.map +1 -1
- package/dist/types/actions/public/verifyHash.d.ts +1 -1
- package/dist/types/actions/public/verifyHash.d.ts.map +1 -1
- package/dist/types/actions/public/verifyMessage.d.ts +1 -1
- package/dist/types/actions/public/verifyMessage.d.ts.map +1 -1
- package/dist/types/actions/public/verifyTypedData.d.ts +1 -1
- package/dist/types/actions/public/verifyTypedData.d.ts.map +1 -1
- package/dist/types/actions/public/watchBlocks.d.ts.map +1 -1
- package/dist/types/actions/test/sendUnsignedTransaction.d.ts +2 -8
- package/dist/types/actions/test/sendUnsignedTransaction.d.ts.map +1 -1
- package/dist/types/actions/wallet/sendTransaction.d.ts +2 -7
- package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/dist/types/chains/formatters/celo.d.ts +235 -0
- package/dist/types/chains/formatters/celo.d.ts.map +1 -0
- package/dist/types/chains/formatters/optimism.d.ts +286 -0
- package/dist/types/chains/formatters/optimism.d.ts.map +1 -0
- package/dist/types/chains/index.d.ts +5246 -0
- package/dist/types/chains/index.d.ts.map +1 -0
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +5 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/chain.d.ts +5 -8
- package/dist/types/types/chain.d.ts.map +1 -1
- package/dist/types/types/fee.d.ts +1 -0
- package/dist/types/types/fee.d.ts.map +1 -1
- package/dist/types/types/formatter.d.ts +8 -10
- package/dist/types/types/formatter.d.ts.map +1 -1
- package/dist/types/types/serializer.d.ts +7 -0
- package/dist/types/types/serializer.d.ts.map +1 -0
- package/dist/types/types/transaction.d.ts +2 -0
- package/dist/types/types/transaction.d.ts.map +1 -1
- package/dist/types/types/utils.d.ts +5 -5
- package/dist/types/types/utils.d.ts.map +1 -1
- package/dist/types/utils/chain.d.ts +4 -1
- package/dist/types/utils/chain.d.ts.map +1 -1
- package/dist/types/utils/formatters/block.d.ts +5 -11
- package/dist/types/utils/formatters/block.d.ts.map +1 -1
- package/dist/types/utils/formatters/formatter.d.ts +6 -0
- package/dist/types/utils/formatters/formatter.d.ts.map +1 -0
- package/dist/types/utils/formatters/transaction.d.ts +5 -11
- package/dist/types/utils/formatters/transaction.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionReceipt.d.ts +5 -11
- package/dist/types/utils/formatters/transactionReceipt.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionRequest.d.ts +5 -11
- package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +5 -5
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/wallet.d.ts +1 -1
- package/dist/types/wallet.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/actions/public/call.ts +20 -30
- package/src/actions/public/estimateContractGas.ts +7 -1
- package/src/actions/public/estimateGas.ts +20 -30
- package/src/actions/public/getBlock.ts +3 -6
- package/src/actions/public/getTransaction.ts +3 -6
- package/src/actions/public/getTransactionConfirmations.ts +2 -7
- package/src/actions/public/getTransactionReceipt.ts +4 -7
- package/src/actions/public/simulateContract.ts +7 -1
- package/src/actions/public/verifyHash.ts +1 -1
- package/src/actions/public/verifyMessage.ts +1 -1
- package/src/actions/public/verifyTypedData.ts +1 -1
- package/src/actions/public/watchBlocks.ts +2 -4
- package/src/actions/test/sendUnsignedTransaction.ts +18 -32
- package/src/actions/wallet/sendTransaction.ts +18 -32
- package/src/chains/formatters/celo.ts +102 -0
- package/src/chains/formatters/optimism.ts +88 -0
- package/src/{chains.ts → chains/index.ts} +13 -56
- package/src/errors/version.ts +1 -1
- package/src/index.ts +1 -8
- package/src/types/chain.ts +11 -8
- package/src/types/fee.ts +1 -0
- package/src/types/formatter.ts +26 -17
- package/src/types/serializer.ts +19 -0
- package/src/types/transaction.ts +2 -0
- package/src/types/utils.ts +5 -5
- package/src/utils/chain.ts +11 -4
- package/src/utils/formatters/block.ts +5 -17
- package/src/utils/formatters/formatter.ts +32 -0
- package/src/utils/formatters/transaction.ts +7 -21
- package/src/utils/formatters/transactionReceipt.ts +7 -21
- package/src/utils/formatters/transactionRequest.ts +7 -22
- package/src/utils/index.ts +1 -10
- package/src/wallet.ts +0 -1
- package/dist/cjs/chains.js.map +0 -1
- package/dist/cjs/utils/formatters/format.js +0 -23
- package/dist/cjs/utils/formatters/format.js.map +0 -1
- package/dist/esm/chains.js.map +0 -1
- package/dist/esm/utils/formatters/format.js +0 -21
- package/dist/esm/utils/formatters/format.js.map +0 -1
- package/dist/types/chains.d.ts +0 -2834
- package/dist/types/chains.d.ts.map +0 -1
- package/dist/types/utils/formatters/format.d.ts +0 -38
- package/dist/types/utils/formatters/format.d.ts.map +0 -1
- package/src/utils/formatters/format.ts +0 -99
@@ -0,0 +1,88 @@
|
|
1
|
+
import { defineBlock, formatTransaction } from '../../index.js'
|
2
|
+
import type { FeeValuesEIP1559 } from '../../types/fee.js'
|
3
|
+
import type { Hash, Hex } from '../../types/misc.js'
|
4
|
+
import type {
|
5
|
+
Index,
|
6
|
+
Quantity,
|
7
|
+
RpcTransaction as RpcTransaction_,
|
8
|
+
} from '../../types/rpc.js'
|
9
|
+
import type {
|
10
|
+
Transaction as Transaction_,
|
11
|
+
TransactionBase,
|
12
|
+
} from '../../types/transaction.js'
|
13
|
+
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
14
|
+
import { defineTransaction } from '../../utils/formatters/transaction.js'
|
15
|
+
|
16
|
+
type RpcTransaction = RpcTransaction_ & {
|
17
|
+
isSystemTx?: undefined
|
18
|
+
mint?: undefined
|
19
|
+
sourceHash?: undefined
|
20
|
+
}
|
21
|
+
|
22
|
+
type RpcDepositTransaction = TransactionBase<Quantity, Index> &
|
23
|
+
FeeValuesEIP1559<Quantity> & {
|
24
|
+
isSystemTx?: boolean
|
25
|
+
mint?: Hex
|
26
|
+
sourceHash: Hex
|
27
|
+
type: '0x7e'
|
28
|
+
}
|
29
|
+
|
30
|
+
type Transaction = Transaction_ & {
|
31
|
+
isSystemTx?: undefined
|
32
|
+
mint?: undefined
|
33
|
+
sourceHash?: undefined
|
34
|
+
}
|
35
|
+
|
36
|
+
type DepositTransaction = TransactionBase &
|
37
|
+
FeeValuesEIP1559 & {
|
38
|
+
isSystemTx?: boolean
|
39
|
+
mint?: bigint
|
40
|
+
sourceHash: Hex
|
41
|
+
type: 'deposit'
|
42
|
+
}
|
43
|
+
|
44
|
+
type OptimismOverrides = {
|
45
|
+
RpcBlock: {
|
46
|
+
transactions: Hash[] | OptimismOverrides['RpcTransaction'][]
|
47
|
+
}
|
48
|
+
RpcTransaction: RpcTransaction | RpcDepositTransaction
|
49
|
+
Transaction: Transaction | DepositTransaction
|
50
|
+
}
|
51
|
+
|
52
|
+
export const optimismFormatters = {
|
53
|
+
block: /*#__PURE__*/ defineBlock({
|
54
|
+
exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'],
|
55
|
+
format(args: OptimismOverrides['RpcBlock']) {
|
56
|
+
const transactions = args.transactions?.map((transaction) => {
|
57
|
+
if (typeof transaction === 'string') return transaction
|
58
|
+
const formatted = formatTransaction(
|
59
|
+
transaction as RpcTransaction,
|
60
|
+
) as OptimismOverrides['Transaction']
|
61
|
+
if (formatted.typeHex === '0x7e') {
|
62
|
+
formatted.isSystemTx = transaction.isSystemTx
|
63
|
+
formatted.mint = transaction.mint
|
64
|
+
? hexToBigInt(transaction.mint)
|
65
|
+
: undefined
|
66
|
+
formatted.sourceHash = transaction.sourceHash
|
67
|
+
formatted.type = 'deposit'
|
68
|
+
}
|
69
|
+
return formatted
|
70
|
+
}) as Hash[] | OptimismOverrides['Transaction'][]
|
71
|
+
return {
|
72
|
+
transactions,
|
73
|
+
}
|
74
|
+
},
|
75
|
+
}),
|
76
|
+
transaction: /*#__PURE__*/ defineTransaction({
|
77
|
+
format(args: OptimismOverrides['RpcTransaction']) {
|
78
|
+
const transaction = {} as OptimismOverrides['Transaction']
|
79
|
+
if (args.type === '0x7e') {
|
80
|
+
transaction.isSystemTx = args.isSystemTx
|
81
|
+
transaction.mint = args.mint ? hexToBigInt(args.mint) : undefined
|
82
|
+
transaction.sourceHash = args.sourceHash
|
83
|
+
transaction.type = 'deposit'
|
84
|
+
}
|
85
|
+
return transaction
|
86
|
+
},
|
87
|
+
}),
|
88
|
+
} as const
|
@@ -1,53 +1,9 @@
|
|
1
1
|
import * as chains from '@wagmi/chains'
|
2
2
|
|
3
|
-
import
|
3
|
+
import { defineChain } from '../utils/chain.js'
|
4
|
+
import { celoFormatters } from './formatters/celo.js'
|
5
|
+
import { optimismFormatters } from './formatters/optimism.js'
|
4
6
|
|
5
|
-
import type { Hex } from './types/misc.js'
|
6
|
-
import type { Quantity } from './types/rpc.js'
|
7
|
-
import { defineChain } from './utils/chain.js'
|
8
|
-
import { defineBlock } from './utils/formatters/block.js'
|
9
|
-
import { defineTransaction } from './utils/formatters/transaction.js'
|
10
|
-
import { defineTransactionReceipt } from './utils/formatters/transactionReceipt.js'
|
11
|
-
import { defineTransactionRequest } from './utils/formatters/transactionRequest.js'
|
12
|
-
|
13
|
-
const celoFormatters = {
|
14
|
-
block: /*#__PURE__*/ defineBlock({
|
15
|
-
exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'],
|
16
|
-
format: (block) => ({
|
17
|
-
randomness: block.randomness as {
|
18
|
-
committed: Hex
|
19
|
-
revealed: Hex
|
20
|
-
},
|
21
|
-
}),
|
22
|
-
}),
|
23
|
-
transaction: /*#__PURE__*/ defineTransaction({
|
24
|
-
format: (transaction) => ({
|
25
|
-
feeCurrency: transaction.feeCurrency as Address | null,
|
26
|
-
gatewayFee: transaction.gatewayFee
|
27
|
-
? BigInt(transaction.gatewayFee as Quantity)
|
28
|
-
: null,
|
29
|
-
gatewayFeeRecipient: transaction.gatewayFeeRecipient as Address | null,
|
30
|
-
}),
|
31
|
-
}),
|
32
|
-
transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({
|
33
|
-
format: (transaction) => ({
|
34
|
-
feeCurrency: transaction.feeCurrency as Address | null,
|
35
|
-
gatewayFee: transaction.gatewayFee
|
36
|
-
? BigInt(transaction.gatewayFee as Quantity)
|
37
|
-
: null,
|
38
|
-
gatewayFeeRecipient: transaction.gatewayFeeRecipient as Address | null,
|
39
|
-
}),
|
40
|
-
}),
|
41
|
-
transactionRequest: /*#__PURE__*/ defineTransactionRequest({
|
42
|
-
format: (transactionRequest) => ({
|
43
|
-
feeCurrency: transactionRequest.feeCurrency as Address | undefined,
|
44
|
-
gatewayFee: transactionRequest.gatewayFee as Quantity | undefined,
|
45
|
-
gatewayFeeRecipient: transactionRequest.gatewayFeeRecipient as
|
46
|
-
| Address
|
47
|
-
| undefined,
|
48
|
-
}),
|
49
|
-
}),
|
50
|
-
}
|
51
7
|
export const arbitrum = /*#__PURE__*/ defineChain(chains.arbitrum)
|
52
8
|
export const arbitrumGoerli = /*#__PURE__*/ defineChain(chains.arbitrumGoerli)
|
53
9
|
export const aurora = /*#__PURE__*/ defineChain(chains.aurora)
|
@@ -61,16 +17,13 @@ export const bronosTestnet = /*#__PURE__*/ defineChain(chains.bronosTestnet)
|
|
61
17
|
export const bsc = /*#__PURE__*/ defineChain(chains.bsc)
|
62
18
|
export const bscTestnet = /*#__PURE__*/ defineChain(chains.bscTestnet)
|
63
19
|
export const canto = /*#__PURE__*/ defineChain(chains.canto)
|
64
|
-
export const celo = /*#__PURE__*/ defineChain({
|
65
|
-
...chains.celo,
|
20
|
+
export const celo = /*#__PURE__*/ defineChain(chains.celo, {
|
66
21
|
formatters: celoFormatters,
|
67
22
|
})
|
68
|
-
export const celoAlfajores = /*#__PURE__*/ defineChain({
|
69
|
-
...chains.celoAlfajores,
|
23
|
+
export const celoAlfajores = /*#__PURE__*/ defineChain(chains.celoAlfajores, {
|
70
24
|
formatters: celoFormatters,
|
71
25
|
})
|
72
|
-
export const celoCannoli = /*#__PURE__*/ defineChain({
|
73
|
-
...chains.celoCannoli,
|
26
|
+
export const celoCannoli = /*#__PURE__*/ defineChain(chains.celoCannoli, {
|
74
27
|
formatters: celoFormatters,
|
75
28
|
})
|
76
29
|
export const cronos = /*#__PURE__*/ defineChain(chains.cronos)
|
@@ -111,8 +64,12 @@ export const moonbeam = /*#__PURE__*/ defineChain(chains.moonbeam)
|
|
111
64
|
export const moonriver = /*#__PURE__*/ defineChain(chains.moonriver)
|
112
65
|
export const nexi = /*#__PURE__*/ defineChain(chains.nexi)
|
113
66
|
export const okc = /*#__PURE__*/ defineChain(chains.okc)
|
114
|
-
export const optimism = /*#__PURE__*/ defineChain(chains.optimism
|
115
|
-
|
67
|
+
export const optimism = /*#__PURE__*/ defineChain(chains.optimism, {
|
68
|
+
formatters: optimismFormatters,
|
69
|
+
})
|
70
|
+
export const optimismGoerli = /*#__PURE__*/ defineChain(chains.optimismGoerli, {
|
71
|
+
formatters: optimismFormatters,
|
72
|
+
})
|
116
73
|
export const polygon = /*#__PURE__*/ defineChain(chains.polygon)
|
117
74
|
export const polygonMumbai = /*#__PURE__*/ defineChain(chains.polygonMumbai)
|
118
75
|
export const polygonZkEvm = /*#__PURE__*/ defineChain(chains.polygonZkEvm)
|
@@ -174,4 +131,4 @@ export const zkSync = /*#__PURE__*/ defineChain(chains.zkSync)
|
|
174
131
|
export const zkSyncTestnet = /*#__PURE__*/ defineChain(chains.zkSyncTestnet)
|
175
132
|
export const zoraTestnet = /*#__PURE__*/ defineChain(chains.zoraTestnet)
|
176
133
|
|
177
|
-
export type { Chain } from '
|
134
|
+
export type { Chain } from '../types/chain.js'
|
package/src/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '0.0.0-main.
|
1
|
+
export const version = '0.0.0-main.20230621T010720'
|
package/src/index.ts
CHANGED
@@ -476,6 +476,7 @@ export type {
|
|
476
476
|
Formatter,
|
477
477
|
Formatters,
|
478
478
|
} from './types/formatter.js'
|
479
|
+
export type { Serializers } from './types/serializer.js'
|
479
480
|
export type {
|
480
481
|
GetTypedDataDomain,
|
481
482
|
GetTypedDataMessage,
|
@@ -507,7 +508,6 @@ export type {
|
|
507
508
|
export { labelhash } from './utils/ens/labelhash.js'
|
508
509
|
export { namehash } from './utils/ens/namehash.js'
|
509
510
|
export {
|
510
|
-
type BlockFormatter,
|
511
511
|
type FormattedBlock,
|
512
512
|
defineBlock,
|
513
513
|
formatBlock,
|
@@ -559,25 +559,18 @@ export {
|
|
559
559
|
type EncodeFunctionResultParameters,
|
560
560
|
encodeFunctionResult,
|
561
561
|
} from './utils/abi/encodeFunctionResult.js'
|
562
|
-
export type {
|
563
|
-
ExtractFormatter,
|
564
|
-
Formatted,
|
565
|
-
} from './utils/formatters/format.js'
|
566
562
|
export {
|
567
563
|
type FormattedTransaction,
|
568
|
-
type TransactionFormatter,
|
569
564
|
defineTransaction,
|
570
565
|
formatTransaction,
|
571
566
|
transactionType,
|
572
567
|
} from './utils/formatters/transaction.js'
|
573
568
|
export {
|
574
569
|
type FormattedTransactionReceipt,
|
575
|
-
type TransactionReceiptFormatter,
|
576
570
|
defineTransactionReceipt,
|
577
571
|
} from './utils/formatters/transactionReceipt.js'
|
578
572
|
export {
|
579
573
|
type FormattedTransactionRequest,
|
580
|
-
type TransactionRequestFormatter,
|
581
574
|
defineTransactionRequest,
|
582
575
|
formatTransactionRequest,
|
583
576
|
} from './utils/formatters/transactionRequest.js'
|
package/src/types/chain.ts
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
-
import type { TransactionSerializable } from '../types/transaction.js'
|
2
|
-
import type { SerializeTransactionFn } from '../utils/transaction/serializeTransaction.js'
|
3
|
-
import type { Formatters } from './formatter.js'
|
4
|
-
import type { IsUndefined } from './utils.js'
|
5
1
|
import type { Chain as Chain_ } from '@wagmi/chains'
|
6
2
|
import type { Address } from 'abitype'
|
7
3
|
|
8
|
-
|
4
|
+
import type { Formatters } from './formatter.js'
|
5
|
+
import type { Serializers } from './serializer.js'
|
6
|
+
import type { IsUndefined } from './utils.js'
|
7
|
+
|
8
|
+
export type Chain<
|
9
|
+
TFormatters extends Formatters | undefined = Formatters | undefined,
|
10
|
+
TSerializers extends Serializers<TFormatters> | undefined =
|
11
|
+
| Serializers<TFormatters>
|
12
|
+
| undefined,
|
13
|
+
> = Chain_ & {
|
9
14
|
formatters?: TFormatters
|
10
|
-
serializers?:
|
11
|
-
transaction?: SerializeTransactionFn<TransactionSerializable>
|
12
|
-
}
|
15
|
+
serializers?: TSerializers
|
13
16
|
}
|
14
17
|
|
15
18
|
export type ChainContract = {
|
package/src/types/fee.ts
CHANGED
@@ -20,6 +20,7 @@ export type FeeValuesLegacy<TQuantity = bigint> = {
|
|
20
20
|
}
|
21
21
|
|
22
22
|
export type FeeValuesEIP1559<TQuantity = bigint> = {
|
23
|
+
/** Base fee per gas. */
|
23
24
|
gasPrice?: never
|
24
25
|
/** Total fee per gas in wei (gasPrice/baseFeePerGas + maxPriorityFeePerGas). */
|
25
26
|
maxFeePerGas: TQuantity
|
package/src/types/formatter.ts
CHANGED
@@ -1,23 +1,32 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
RpcBlock,
|
4
|
-
RpcTransaction,
|
5
|
-
RpcTransactionReceipt,
|
6
|
-
RpcTransactionRequest,
|
7
|
-
} from './rpc.js'
|
8
|
-
import type {
|
9
|
-
Transaction,
|
10
|
-
TransactionReceipt,
|
11
|
-
TransactionRequest,
|
12
|
-
} from './transaction.js'
|
1
|
+
import type { Chain } from './chain.js'
|
13
2
|
|
14
3
|
export type Formatter<TSource = any, TTarget = any> = (
|
15
|
-
value: TSource
|
4
|
+
value: TSource,
|
16
5
|
) => TTarget
|
17
6
|
|
18
7
|
export type Formatters = {
|
19
|
-
block?: Formatter
|
20
|
-
transaction?: Formatter
|
21
|
-
transactionReceipt?: Formatter
|
22
|
-
transactionRequest?: Formatter
|
8
|
+
block?: Formatter
|
9
|
+
transaction?: Formatter
|
10
|
+
transactionReceipt?: Formatter
|
11
|
+
transactionRequest?: Formatter
|
23
12
|
}
|
13
|
+
|
14
|
+
export type ExtractFormatterParameters<
|
15
|
+
TChain extends Chain | undefined,
|
16
|
+
TType extends keyof Formatters,
|
17
|
+
TFallback,
|
18
|
+
> = TChain extends Chain<infer _Formatters extends Formatters>
|
19
|
+
? _Formatters[TType] extends Formatter
|
20
|
+
? Parameters<_Formatters[TType]>[0]
|
21
|
+
: TFallback
|
22
|
+
: TFallback
|
23
|
+
|
24
|
+
export type ExtractFormatterReturnType<
|
25
|
+
TChain extends Chain | undefined,
|
26
|
+
TType extends keyof Formatters,
|
27
|
+
TFallback,
|
28
|
+
> = TChain extends Chain<infer _Formatters extends Formatters>
|
29
|
+
? _Formatters[TType] extends Formatter
|
30
|
+
? ReturnType<_Formatters[TType]>
|
31
|
+
: TFallback
|
32
|
+
: TFallback
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import type {
|
2
|
+
TransactionSerializable,
|
3
|
+
TransactionSerializableGeneric,
|
4
|
+
} from '../types/transaction.js'
|
5
|
+
import type { SerializeTransactionFn } from '../utils/transaction/serializeTransaction.js'
|
6
|
+
import type { Formatter, Formatters } from './formatter.js'
|
7
|
+
|
8
|
+
export type Serializers<
|
9
|
+
TFormatters extends Formatters | undefined = undefined,
|
10
|
+
> = {
|
11
|
+
transaction?: SerializeTransactionFn<
|
12
|
+
TFormatters extends Formatters
|
13
|
+
? TFormatters['transactionRequest'] extends Formatter
|
14
|
+
? TransactionSerializableGeneric &
|
15
|
+
Parameters<TFormatters['transactionRequest']>[0]
|
16
|
+
: TransactionSerializable
|
17
|
+
: TransactionSerializable
|
18
|
+
>
|
19
|
+
}
|
package/src/types/transaction.ts
CHANGED
@@ -70,6 +70,8 @@ export type TransactionBase<TQuantity = bigint, TIndex = number> = {
|
|
70
70
|
to: Address | null
|
71
71
|
/** Index of this transaction in the block or `null` if pending */
|
72
72
|
transactionIndex: TIndex | null
|
73
|
+
/** The type represented as hex. */
|
74
|
+
typeHex: Hex | null
|
73
75
|
/** ECDSA recovery ID */
|
74
76
|
v: TQuantity
|
75
77
|
/** Value in wei sent with this transaction */
|
package/src/types/utils.ts
CHANGED
@@ -122,20 +122,20 @@ export type MaybeUndefined<
|
|
122
122
|
> = TUndefinedish extends true ? T | undefined : T
|
123
123
|
|
124
124
|
/**
|
125
|
-
* @description
|
125
|
+
* @description Assigns the properties of U onto T.
|
126
126
|
*
|
127
127
|
* @example
|
128
|
-
*
|
129
|
-
* => { a:
|
128
|
+
* Assign<{ a: string, b: number }, { a: undefined, c: boolean }>
|
129
|
+
* => { a: undefined, b: number, c: boolean }
|
130
130
|
*/
|
131
|
-
export type
|
131
|
+
export type Assign<T, U> = {
|
132
132
|
[K in
|
133
133
|
keyof T as K extends keyof U
|
134
134
|
? U[K] extends void
|
135
135
|
? never
|
136
136
|
: K
|
137
137
|
: K]: K extends keyof U ? U[K] : T[K]
|
138
|
-
}
|
138
|
+
} & U
|
139
139
|
|
140
140
|
/**
|
141
141
|
* @description Makes nullable properties from T optional.
|
package/src/utils/chain.ts
CHANGED
@@ -21,10 +21,17 @@ export function assertCurrentChain({
|
|
21
21
|
}
|
22
22
|
|
23
23
|
export function defineChain<
|
24
|
-
|
25
|
-
|
26
|
-
>(
|
27
|
-
|
24
|
+
TChain extends Chain,
|
25
|
+
TFormatters extends Formatters,
|
26
|
+
>(
|
27
|
+
chain: TChain,
|
28
|
+
config?: Pick<Chain<TFormatters>, 'formatters' | 'serializers'>,
|
29
|
+
) {
|
30
|
+
return {
|
31
|
+
...chain,
|
32
|
+
formatters: config?.formatters,
|
33
|
+
serializers: config?.serializers,
|
34
|
+
}
|
28
35
|
}
|
29
36
|
|
30
37
|
export function getChainContractAddress({
|
@@ -1,26 +1,16 @@
|
|
1
1
|
import type { Block } from '../../types/block.js'
|
2
2
|
import type { Chain } from '../../types/chain.js'
|
3
|
-
import type {
|
3
|
+
import type { ExtractFormatterReturnType } from '../../types/formatter.js'
|
4
4
|
import type { RpcBlock } from '../../types/rpc.js'
|
5
5
|
|
6
|
-
import {
|
7
|
-
type ExtractFormatter,
|
8
|
-
type Formatted,
|
9
|
-
defineFormatter,
|
10
|
-
} from './format.js'
|
6
|
+
import { defineFormatter } from './formatter.js'
|
11
7
|
import { formatTransaction } from './transaction.js'
|
12
8
|
|
13
|
-
export type BlockFormatter<TChain extends Chain | undefined = Chain> =
|
14
|
-
TChain extends Chain
|
15
|
-
? ExtractFormatter<TChain, 'block', NonNullable<Formatters['block']>>
|
16
|
-
: Formatters['block']
|
17
|
-
|
18
9
|
export type FormattedBlock<
|
19
|
-
|
20
|
-
> =
|
10
|
+
TChain extends Chain | undefined = Chain | undefined,
|
11
|
+
> = ExtractFormatterReturnType<TChain, 'block', Block>
|
21
12
|
|
22
13
|
export function formatBlock(block: Partial<RpcBlock>) {
|
23
|
-
// TODO: Properly format transactions with a custom formatter
|
24
14
|
const transactions = block.transactions?.map((transaction) => {
|
25
15
|
if (typeof transaction === 'string') return transaction
|
26
16
|
return formatTransaction(transaction)
|
@@ -44,6 +34,4 @@ export function formatBlock(block: Partial<RpcBlock>) {
|
|
44
34
|
} as Block
|
45
35
|
}
|
46
36
|
|
47
|
-
export const defineBlock = /*#__PURE__*/ defineFormatter(
|
48
|
-
format: formatBlock,
|
49
|
-
})
|
37
|
+
export const defineBlock = /*#__PURE__*/ defineFormatter(formatBlock)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import type { Assign, Prettify } from '../../types/utils.js'
|
2
|
+
|
3
|
+
export function defineFormatter<TParameters, TReturnType>(
|
4
|
+
format: (_: TParameters) => TReturnType,
|
5
|
+
) {
|
6
|
+
return <
|
7
|
+
TOverrideParameters,
|
8
|
+
TOverrideReturnType,
|
9
|
+
TExclude extends (keyof TParameters)[] = [],
|
10
|
+
>({
|
11
|
+
exclude,
|
12
|
+
format: overrides,
|
13
|
+
}: {
|
14
|
+
exclude?: TExclude
|
15
|
+
format: (_: TOverrideParameters) => TOverrideReturnType
|
16
|
+
}) => {
|
17
|
+
return (args: TParameters & TOverrideParameters) => {
|
18
|
+
const formatted = format(args)
|
19
|
+
if (exclude) {
|
20
|
+
for (const key of exclude) {
|
21
|
+
delete (formatted as any)[key]
|
22
|
+
}
|
23
|
+
}
|
24
|
+
return {
|
25
|
+
...formatted,
|
26
|
+
...overrides(args),
|
27
|
+
} as Prettify<Assign<TReturnType, TOverrideReturnType>> & {
|
28
|
+
[K in TExclude[number]]: never
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
@@ -1,27 +1,13 @@
|
|
1
1
|
import type { Chain } from '../../types/chain.js'
|
2
|
-
import type {
|
2
|
+
import type { ExtractFormatterReturnType } from '../../types/formatter.js'
|
3
3
|
import type { RpcTransaction } from '../../types/rpc.js'
|
4
4
|
import type { Transaction } from '../../types/transaction.js'
|
5
5
|
import { hexToNumber } from '../encoding/fromHex.js'
|
6
|
-
|
7
|
-
import {
|
8
|
-
type ExtractFormatter,
|
9
|
-
type Formatted,
|
10
|
-
defineFormatter,
|
11
|
-
} from './format.js'
|
12
|
-
|
13
|
-
export type TransactionFormatter<TChain extends Chain | undefined = Chain> =
|
14
|
-
TChain extends Chain
|
15
|
-
? ExtractFormatter<
|
16
|
-
TChain,
|
17
|
-
'transaction',
|
18
|
-
NonNullable<Formatters['transaction']>
|
19
|
-
>
|
20
|
-
: Formatters['transaction']
|
6
|
+
import { defineFormatter } from './formatter.js'
|
21
7
|
|
22
8
|
export type FormattedTransaction<
|
23
|
-
|
24
|
-
> =
|
9
|
+
TChain extends Chain | undefined = Chain | undefined,
|
10
|
+
> = ExtractFormatterReturnType<TChain, 'transaction', Transaction>
|
25
11
|
|
26
12
|
export const transactionType = {
|
27
13
|
'0x0': 'legacy',
|
@@ -51,6 +37,7 @@ export function formatTransaction(transaction: Partial<RpcTransaction>) {
|
|
51
37
|
? Number(transaction.transactionIndex)
|
52
38
|
: null,
|
53
39
|
type: transaction.type ? transactionType[transaction.type] : undefined,
|
40
|
+
typeHex: transaction.type ? transaction.type : undefined,
|
54
41
|
value: transaction.value ? BigInt(transaction.value) : undefined,
|
55
42
|
v: transaction.v ? BigInt(transaction.v) : undefined,
|
56
43
|
}
|
@@ -67,6 +54,5 @@ export function formatTransaction(transaction: Partial<RpcTransaction>) {
|
|
67
54
|
return transaction_ as Transaction
|
68
55
|
}
|
69
56
|
|
70
|
-
export const defineTransaction =
|
71
|
-
|
72
|
-
})
|
57
|
+
export const defineTransaction =
|
58
|
+
/*#__PURE__*/ defineFormatter(formatTransaction)
|
@@ -1,30 +1,16 @@
|
|
1
1
|
import type { Chain } from '../../types/chain.js'
|
2
|
-
import type {
|
2
|
+
import type { ExtractFormatterReturnType } from '../../types/formatter.js'
|
3
3
|
import type { RpcTransactionReceipt } from '../../types/rpc.js'
|
4
4
|
import type { TransactionReceipt } from '../../types/transaction.js'
|
5
5
|
import { hexToNumber } from '../encoding/fromHex.js'
|
6
6
|
|
7
|
-
import {
|
8
|
-
type ExtractFormatter,
|
9
|
-
type Formatted,
|
10
|
-
defineFormatter,
|
11
|
-
} from './format.js'
|
7
|
+
import { defineFormatter } from './formatter.js'
|
12
8
|
import { formatLog } from './log.js'
|
13
9
|
import { transactionType } from './transaction.js'
|
14
10
|
|
15
|
-
export type TransactionReceiptFormatter<
|
16
|
-
TChain extends Chain | undefined = Chain,
|
17
|
-
> = TChain extends Chain
|
18
|
-
? ExtractFormatter<
|
19
|
-
TChain,
|
20
|
-
'transactionReceipt',
|
21
|
-
NonNullable<Formatters['transactionReceipt']>
|
22
|
-
>
|
23
|
-
: Formatters['transactionReceipt']
|
24
|
-
|
25
11
|
export type FormattedTransactionReceipt<
|
26
|
-
|
27
|
-
> =
|
12
|
+
TChain extends Chain | undefined = Chain | undefined,
|
13
|
+
> = ExtractFormatterReturnType<TChain, 'transactionReceipt', TransactionReceipt>
|
28
14
|
|
29
15
|
const statuses = {
|
30
16
|
'0x0': 'reverted',
|
@@ -69,6 +55,6 @@ export function formatTransactionReceipt(
|
|
69
55
|
} as TransactionReceipt
|
70
56
|
}
|
71
57
|
|
72
|
-
export const defineTransactionReceipt = /*#__PURE__*/ defineFormatter(
|
73
|
-
|
74
|
-
|
58
|
+
export const defineTransactionReceipt = /*#__PURE__*/ defineFormatter(
|
59
|
+
formatTransactionReceipt,
|
60
|
+
)
|
@@ -1,28 +1,13 @@
|
|
1
1
|
import type { Chain } from '../../types/chain.js'
|
2
|
-
import type {
|
2
|
+
import type { ExtractFormatterParameters } from '../../types/formatter.js'
|
3
3
|
import type { RpcTransactionRequest } from '../../types/rpc.js'
|
4
4
|
import type { TransactionRequest } from '../../types/transaction.js'
|
5
5
|
import { numberToHex } from '../encoding/toHex.js'
|
6
|
-
|
7
|
-
import {
|
8
|
-
type ExtractFormatter,
|
9
|
-
type Formatted,
|
10
|
-
defineFormatter,
|
11
|
-
} from './format.js'
|
12
|
-
|
13
|
-
export type TransactionRequestFormatter<
|
14
|
-
TChain extends Chain | undefined = Chain,
|
15
|
-
> = TChain extends Chain
|
16
|
-
? ExtractFormatter<
|
17
|
-
TChain,
|
18
|
-
'transactionRequest',
|
19
|
-
NonNullable<Formatters['transactionRequest']>
|
20
|
-
>
|
21
|
-
: Formatters['transactionRequest']
|
6
|
+
import { defineFormatter } from './formatter.js'
|
22
7
|
|
23
8
|
export type FormattedTransactionRequest<
|
24
|
-
|
25
|
-
> =
|
9
|
+
TChain extends Chain | undefined = Chain | undefined,
|
10
|
+
> = ExtractFormatterParameters<TChain, 'transactionRequest', TransactionRequest>
|
26
11
|
|
27
12
|
export function formatTransactionRequest(
|
28
13
|
transactionRequest: Partial<TransactionRequest>,
|
@@ -56,6 +41,6 @@ export function formatTransactionRequest(
|
|
56
41
|
} as RpcTransactionRequest
|
57
42
|
}
|
58
43
|
|
59
|
-
export const defineTransactionRequest = /*#__PURE__*/ defineFormatter(
|
60
|
-
|
61
|
-
|
44
|
+
export const defineTransactionRequest = /*#__PURE__*/ defineFormatter(
|
45
|
+
formatTransactionRequest,
|
46
|
+
)
|
package/src/utils/index.ts
CHANGED
@@ -118,32 +118,22 @@ export { size } from './data/size.js'
|
|
118
118
|
export { slice, sliceBytes, sliceHex } from './data/slice.js'
|
119
119
|
export { trim } from './data/trim.js'
|
120
120
|
export {
|
121
|
-
type BlockFormatter,
|
122
121
|
type FormattedBlock,
|
123
122
|
defineBlock,
|
124
123
|
formatBlock,
|
125
124
|
} from './formatters/block.js'
|
126
|
-
export {
|
127
|
-
type ExtractFormatter,
|
128
|
-
type Formatted,
|
129
|
-
defineFormatter,
|
130
|
-
format,
|
131
|
-
} from './formatters/format.js'
|
132
125
|
export {
|
133
126
|
type FormattedTransaction,
|
134
|
-
type TransactionFormatter,
|
135
127
|
defineTransaction,
|
136
128
|
formatTransaction,
|
137
129
|
transactionType,
|
138
130
|
} from './formatters/transaction.js'
|
139
131
|
export {
|
140
132
|
type FormattedTransactionReceipt,
|
141
|
-
type TransactionReceiptFormatter,
|
142
133
|
defineTransactionReceipt,
|
143
134
|
} from './formatters/transactionReceipt.js'
|
144
135
|
export {
|
145
136
|
type FormattedTransactionRequest,
|
146
|
-
type TransactionRequestFormatter,
|
147
137
|
defineTransactionRequest,
|
148
138
|
formatTransactionRequest,
|
149
139
|
} from './formatters/transactionRequest.js'
|
@@ -183,6 +173,7 @@ export { getCallError } from './errors/getCallError.js'
|
|
183
173
|
export { getContractError } from './errors/getContractError.js'
|
184
174
|
export { getEstimateGasError } from './errors/getEstimateGasError.js'
|
185
175
|
export { getTransactionError } from './errors/getTransactionError.js'
|
176
|
+
export { defineFormatter } from './formatters/formatter.js'
|
186
177
|
export { getEventSelector } from './hash/getEventSelector.js'
|
187
178
|
export { getFunctionSelector } from './hash/getFunctionSelector.js'
|
188
179
|
export { isHash } from './hash/isHash.js'
|
package/src/wallet.ts
CHANGED