tempo.ts 0.11.1 → 0.12.1
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/CHANGELOG.md +67 -4
- package/README.md +3 -34
- package/dist/server/Handler.d.ts +14 -14
- package/dist/server/Handler.d.ts.map +1 -1
- package/dist/server/Handler.js +16 -17
- package/dist/server/Handler.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +51 -51
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +37 -37
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Actions/dex.d.ts +129 -129
- package/dist/wagmi/Actions/dex.d.ts.map +1 -1
- package/dist/wagmi/Actions/dex.js +73 -73
- package/dist/wagmi/Actions/dex.js.map +1 -1
- package/dist/wagmi/Actions/faucet.d.ts +9 -9
- package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
- package/dist/wagmi/Actions/faucet.js +7 -7
- package/dist/wagmi/Actions/faucet.js.map +1 -1
- package/dist/wagmi/Actions/fee.d.ts +17 -17
- package/dist/wagmi/Actions/fee.d.ts.map +1 -1
- package/dist/wagmi/Actions/fee.js +10 -10
- package/dist/wagmi/Actions/fee.js.map +1 -1
- package/dist/wagmi/Actions/nonce.d.ts +9 -79
- package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
- package/dist/wagmi/Actions/nonce.js +7 -89
- package/dist/wagmi/Actions/nonce.js.map +1 -1
- package/dist/wagmi/Actions/policy.d.ts +69 -70
- package/dist/wagmi/Actions/policy.d.ts.map +1 -1
- package/dist/wagmi/Actions/policy.js +43 -43
- package/dist/wagmi/Actions/policy.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +51 -51
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +31 -31
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Actions/token.d.ts +238 -238
- package/dist/wagmi/Actions/token.d.ts.map +1 -1
- package/dist/wagmi/Actions/token.js +136 -136
- package/dist/wagmi/Actions/token.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +2 -1
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +83 -22
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/nonce.d.ts +1 -52
- package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
- package/dist/wagmi/Hooks/nonce.js +1 -70
- package/dist/wagmi/Hooks/nonce.js.map +1 -1
- package/dist/wagmi/Hooks/policy.d.ts +0 -1
- package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
- package/dist/wagmi/Hooks/policy.js.map +1 -1
- package/dist/wagmi/KeyManager.d.ts +6 -3
- package/dist/wagmi/KeyManager.d.ts.map +1 -1
- package/dist/wagmi/KeyManager.js +9 -4
- package/dist/wagmi/KeyManager.js.map +1 -1
- package/package.json +3 -13
- package/src/server/Handler.test.ts +2 -2
- package/src/server/Handler.ts +16 -17
- package/src/wagmi/Actions/amm.ts +63 -63
- package/src/wagmi/Actions/dex.test.ts +1 -1
- package/src/wagmi/Actions/dex.ts +153 -153
- package/src/wagmi/Actions/faucet.ts +11 -11
- package/src/wagmi/Actions/fee.ts +20 -20
- package/src/wagmi/Actions/nonce.test.ts +1 -64
- package/src/wagmi/Actions/nonce.ts +10 -142
- package/src/wagmi/Actions/policy.ts +83 -85
- package/src/wagmi/Actions/reward.ts +64 -61
- package/src/wagmi/Actions/token.ts +287 -283
- package/src/wagmi/Connector.ts +105 -31
- package/src/wagmi/Hooks/dex.test.ts +1 -1
- package/src/wagmi/Hooks/fee.test.ts +0 -6
- package/src/wagmi/Hooks/nonce.test.ts +1 -66
- package/src/wagmi/Hooks/nonce.ts +1 -114
- package/src/wagmi/Hooks/policy.ts +0 -2
- package/src/wagmi/KeyManager.ts +18 -5
- package/dist/chains.d.ts +0 -73
- package/dist/chains.d.ts.map +0 -1
- package/dist/chains.js +0 -51
- package/dist/chains.js.map +0 -1
- package/dist/viem/Abis.d.ts +0 -2649
- package/dist/viem/Abis.d.ts.map +0 -1
- package/dist/viem/Abis.js +0 -1677
- package/dist/viem/Abis.js.map +0 -1
- package/dist/viem/Account.d.ts +0 -244
- package/dist/viem/Account.d.ts.map +0 -1
- package/dist/viem/Account.js +0 -382
- package/dist/viem/Account.js.map +0 -1
- package/dist/viem/Actions/account.d.ts +0 -40
- package/dist/viem/Actions/account.d.ts.map +0 -1
- package/dist/viem/Actions/account.js +0 -86
- package/dist/viem/Actions/account.js.map +0 -1
- package/dist/viem/Actions/amm.d.ts +0 -1991
- package/dist/viem/Actions/amm.d.ts.map +0 -1
- package/dist/viem/Actions/amm.js +0 -814
- package/dist/viem/Actions/amm.js.map +0 -1
- package/dist/viem/Actions/dex.d.ts +0 -3900
- package/dist/viem/Actions/dex.d.ts.map +0 -1
- package/dist/viem/Actions/dex.js +0 -1414
- package/dist/viem/Actions/dex.js.map +0 -1
- package/dist/viem/Actions/faucet.d.ts +0 -69
- package/dist/viem/Actions/faucet.d.ts.map +0 -1
- package/dist/viem/Actions/faucet.js +0 -73
- package/dist/viem/Actions/faucet.js.map +0 -1
- package/dist/viem/Actions/fee.d.ts +0 -360
- package/dist/viem/Actions/fee.d.ts.map +0 -1
- package/dist/viem/Actions/fee.js +0 -237
- package/dist/viem/Actions/fee.js.map +0 -1
- package/dist/viem/Actions/index.d.ts +0 -10
- package/dist/viem/Actions/index.d.ts.map +0 -1
- package/dist/viem/Actions/index.js +0 -10
- package/dist/viem/Actions/index.js.map +0 -1
- package/dist/viem/Actions/nonce.d.ts +0 -257
- package/dist/viem/Actions/nonce.d.ts.map +0 -1
- package/dist/viem/Actions/nonce.js +0 -228
- package/dist/viem/Actions/nonce.js.map +0 -1
- package/dist/viem/Actions/policy.d.ts +0 -1680
- package/dist/viem/Actions/policy.d.ts.map +0 -1
- package/dist/viem/Actions/policy.js +0 -875
- package/dist/viem/Actions/policy.js.map +0 -1
- package/dist/viem/Actions/reward.d.ts +0 -2422
- package/dist/viem/Actions/reward.d.ts.map +0 -1
- package/dist/viem/Actions/reward.js +0 -651
- package/dist/viem/Actions/reward.js.map +0 -1
- package/dist/viem/Actions/token.d.ts +0 -16007
- package/dist/viem/Actions/token.d.ts.map +0 -1
- package/dist/viem/Actions/token.js +0 -2936
- package/dist/viem/Actions/token.js.map +0 -1
- package/dist/viem/Addresses.d.ts +0 -9
- package/dist/viem/Addresses.d.ts.map +0 -1
- package/dist/viem/Addresses.js +0 -9
- package/dist/viem/Addresses.js.map +0 -1
- package/dist/viem/Chain.d.ts +0 -451
- package/dist/viem/Chain.d.ts.map +0 -1
- package/dist/viem/Chain.js +0 -96
- package/dist/viem/Chain.js.map +0 -1
- package/dist/viem/Decorator.d.ts +0 -2783
- package/dist/viem/Decorator.d.ts.map +0 -1
- package/dist/viem/Decorator.js +0 -137
- package/dist/viem/Decorator.js.map +0 -1
- package/dist/viem/Formatters.d.ts +0 -10
- package/dist/viem/Formatters.d.ts.map +0 -1
- package/dist/viem/Formatters.js +0 -104
- package/dist/viem/Formatters.js.map +0 -1
- package/dist/viem/P256.d.ts +0 -2
- package/dist/viem/P256.d.ts.map +0 -1
- package/dist/viem/P256.js +0 -2
- package/dist/viem/P256.js.map +0 -1
- package/dist/viem/Secp256k1.d.ts +0 -2
- package/dist/viem/Secp256k1.d.ts.map +0 -1
- package/dist/viem/Secp256k1.js +0 -2
- package/dist/viem/Secp256k1.js.map +0 -1
- package/dist/viem/Storage.d.ts +0 -24
- package/dist/viem/Storage.d.ts.map +0 -1
- package/dist/viem/Storage.js +0 -68
- package/dist/viem/Storage.js.map +0 -1
- package/dist/viem/TokenIds.d.ts +0 -2
- package/dist/viem/TokenIds.d.ts.map +0 -1
- package/dist/viem/TokenIds.js +0 -2
- package/dist/viem/TokenIds.js.map +0 -1
- package/dist/viem/Transaction.d.ts +0 -76
- package/dist/viem/Transaction.d.ts.map +0 -1
- package/dist/viem/Transaction.js +0 -176
- package/dist/viem/Transaction.js.map +0 -1
- package/dist/viem/Transport.d.ts +0 -33
- package/dist/viem/Transport.d.ts.map +0 -1
- package/dist/viem/Transport.js +0 -138
- package/dist/viem/Transport.js.map +0 -1
- package/dist/viem/WebAuthnP256.d.ts +0 -82
- package/dist/viem/WebAuthnP256.d.ts.map +0 -1
- package/dist/viem/WebAuthnP256.js +0 -97
- package/dist/viem/WebAuthnP256.js.map +0 -1
- package/dist/viem/WebCryptoP256.d.ts +0 -2
- package/dist/viem/WebCryptoP256.d.ts.map +0 -1
- package/dist/viem/WebCryptoP256.js +0 -2
- package/dist/viem/WebCryptoP256.js.map +0 -1
- package/dist/viem/index.d.ts +0 -26
- package/dist/viem/index.d.ts.map +0 -1
- package/dist/viem/index.js +0 -17
- package/dist/viem/index.js.map +0 -1
- package/dist/viem/internal/types.d.ts +0 -20
- package/dist/viem/internal/types.d.ts.map +0 -1
- package/dist/viem/internal/types.js +0 -2
- package/dist/viem/internal/types.js.map +0 -1
- package/dist/viem/internal/utils.d.ts +0 -14
- package/dist/viem/internal/utils.d.ts.map +0 -1
- package/dist/viem/internal/utils.js +0 -33
- package/dist/viem/internal/utils.js.map +0 -1
- package/src/chains.ts +0 -54
- package/src/viem/Abis.ts +0 -1688
- package/src/viem/Account.test.ts +0 -444
- package/src/viem/Account.ts +0 -601
- package/src/viem/Actions/account.test.ts +0 -414
- package/src/viem/Actions/account.ts +0 -106
- package/src/viem/Actions/amm.test.ts +0 -381
- package/src/viem/Actions/amm.ts +0 -1227
- package/src/viem/Actions/dex.test.ts +0 -1549
- package/src/viem/Actions/dex.ts +0 -2150
- package/src/viem/Actions/faucet.ts +0 -121
- package/src/viem/Actions/fee.test.ts +0 -259
- package/src/viem/Actions/fee.ts +0 -372
- package/src/viem/Actions/index.ts +0 -9
- package/src/viem/Actions/nonce.test.ts +0 -206
- package/src/viem/Actions/nonce.ts +0 -347
- package/src/viem/Actions/policy.test.ts +0 -534
- package/src/viem/Actions/policy.ts +0 -1335
- package/src/viem/Actions/reward.test.ts +0 -434
- package/src/viem/Actions/reward.ts +0 -944
- package/src/viem/Actions/token.test.ts +0 -3029
- package/src/viem/Actions/token.ts +0 -4458
- package/src/viem/Addresses.ts +0 -9
- package/src/viem/Chain.bench-d.ts +0 -12
- package/src/viem/Chain.test.ts +0 -168
- package/src/viem/Chain.ts +0 -157
- package/src/viem/Decorator.bench-d.ts +0 -11
- package/src/viem/Decorator.test.ts +0 -39
- package/src/viem/Decorator.ts +0 -3179
- package/src/viem/Formatters.ts +0 -164
- package/src/viem/P256.ts +0 -1
- package/src/viem/Secp256k1.ts +0 -1
- package/src/viem/Storage.ts +0 -110
- package/src/viem/TokenIds.ts +0 -1
- package/src/viem/Transaction.ts +0 -382
- package/src/viem/Transport.ts +0 -191
- package/src/viem/WebAuthnP256.ts +0 -146
- package/src/viem/WebCryptoP256.ts +0 -1
- package/src/viem/e2e.test.ts +0 -1602
- package/src/viem/index.ts +0 -30
- package/src/viem/internal/types.ts +0 -69
- package/src/viem/internal/utils.ts +0 -58
- package/src/wagmi/internal/types.ts +0 -16
package/src/viem/Formatters.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
// TODO: Find opportunities to make this file less duplicated + more simplified with Viem v3.
|
|
2
|
-
|
|
3
|
-
import * as Hex from 'ox/Hex'
|
|
4
|
-
import {
|
|
5
|
-
Transaction as ox_Transaction,
|
|
6
|
-
TransactionRequest as ox_TransactionRequest,
|
|
7
|
-
} from 'ox/tempo'
|
|
8
|
-
import {
|
|
9
|
-
type Chain,
|
|
10
|
-
type Account as viem_Account,
|
|
11
|
-
formatTransaction as viem_formatTransaction,
|
|
12
|
-
formatTransactionReceipt as viem_formatTransactionReceipt,
|
|
13
|
-
formatTransactionRequest as viem_formatTransactionRequest,
|
|
14
|
-
} from 'viem'
|
|
15
|
-
import { type Address, parseAccount } from 'viem/accounts'
|
|
16
|
-
import type { UnionOmit } from '../internal/types.js'
|
|
17
|
-
import type { Account } from './Account.js'
|
|
18
|
-
import type { GetFeeTokenParameter } from './internal/types.js'
|
|
19
|
-
import {
|
|
20
|
-
isTempo,
|
|
21
|
-
type Transaction,
|
|
22
|
-
type TransactionReceipt,
|
|
23
|
-
type TransactionReceiptRpc,
|
|
24
|
-
type TransactionRequest,
|
|
25
|
-
type TransactionRequestRpc,
|
|
26
|
-
type TransactionRpc,
|
|
27
|
-
} from './Transaction.js'
|
|
28
|
-
|
|
29
|
-
export function formatTransaction(
|
|
30
|
-
transaction: TransactionRpc,
|
|
31
|
-
): Transaction<bigint, number, boolean> {
|
|
32
|
-
if (!isTempo(transaction)) return viem_formatTransaction(transaction as never)
|
|
33
|
-
|
|
34
|
-
const {
|
|
35
|
-
feePayerSignature,
|
|
36
|
-
gasPrice: _,
|
|
37
|
-
nonce,
|
|
38
|
-
...tx
|
|
39
|
-
} = ox_Transaction.fromRpc(transaction as never) as ox_Transaction.Tempo
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
...tx,
|
|
43
|
-
accessList: tx.accessList!,
|
|
44
|
-
feePayerSignature: feePayerSignature
|
|
45
|
-
? {
|
|
46
|
-
r: Hex.fromNumber(feePayerSignature.r, { size: 32 }),
|
|
47
|
-
s: Hex.fromNumber(feePayerSignature.s, { size: 32 }),
|
|
48
|
-
v: BigInt(feePayerSignature.v ?? 27),
|
|
49
|
-
yParity: feePayerSignature.yParity,
|
|
50
|
-
}
|
|
51
|
-
: undefined,
|
|
52
|
-
nonce: Number(nonce),
|
|
53
|
-
typeHex:
|
|
54
|
-
ox_Transaction.toRpcType[
|
|
55
|
-
tx.type as keyof typeof ox_Transaction.toRpcType
|
|
56
|
-
],
|
|
57
|
-
type: tx.type as 'tempo',
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function formatTransactionReceipt(
|
|
62
|
-
receipt: TransactionReceiptRpc,
|
|
63
|
-
): TransactionReceipt {
|
|
64
|
-
return viem_formatTransactionReceipt(receipt as never)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
type Request<chain extends Chain | undefined> = UnionOmit<
|
|
68
|
-
TransactionRequest,
|
|
69
|
-
'feeToken'
|
|
70
|
-
> &
|
|
71
|
-
GetFeeTokenParameter<chain>
|
|
72
|
-
export function formatTransactionRequest<chain extends Chain | undefined>(
|
|
73
|
-
r: Request<chain>,
|
|
74
|
-
action?: string | undefined,
|
|
75
|
-
): TransactionRequestRpc {
|
|
76
|
-
const request = r as Request<chain> & {
|
|
77
|
-
account?: viem_Account | Address | undefined
|
|
78
|
-
}
|
|
79
|
-
const account = request.account
|
|
80
|
-
? parseAccount<Account | viem_Account | Address>(request.account)
|
|
81
|
-
: undefined
|
|
82
|
-
|
|
83
|
-
// Convert EIP-1559 transactions to Tempo transactions.
|
|
84
|
-
if (request.type === 'eip1559') (request as any).type = 'tempo'
|
|
85
|
-
|
|
86
|
-
// If the request is not a Tempo transaction, route to Viem formatter.
|
|
87
|
-
if (!isTempo(request))
|
|
88
|
-
return viem_formatTransactionRequest(
|
|
89
|
-
r as never,
|
|
90
|
-
action,
|
|
91
|
-
) as TransactionRequestRpc
|
|
92
|
-
|
|
93
|
-
if (action)
|
|
94
|
-
request.calls = request.calls ?? [
|
|
95
|
-
{
|
|
96
|
-
to:
|
|
97
|
-
r.to ||
|
|
98
|
-
(!r.data || r.data === '0x'
|
|
99
|
-
? '0x0000000000000000000000000000000000000000'
|
|
100
|
-
: undefined),
|
|
101
|
-
value: r.value,
|
|
102
|
-
data: r.data,
|
|
103
|
-
},
|
|
104
|
-
]
|
|
105
|
-
|
|
106
|
-
const rpc = ox_TransactionRequest.toRpc({
|
|
107
|
-
...request,
|
|
108
|
-
type: 'tempo',
|
|
109
|
-
} as never)
|
|
110
|
-
|
|
111
|
-
if (action === 'estimateGas') {
|
|
112
|
-
rpc.maxFeePerGas = undefined
|
|
113
|
-
rpc.maxPriorityFeePerGas = undefined
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// JSON-RPC accounts (wallets) don't support Tempo transactions yet,
|
|
117
|
-
// we will omit the type to attempt to make them compatible
|
|
118
|
-
// with the base transaction structure.
|
|
119
|
-
// TODO: `calls` will not be supported by a lot of JSON-RPC accounts (wallet),
|
|
120
|
-
// use `wallet_sendCalls` or sequential `eth_sendTransaction` to mimic the
|
|
121
|
-
// behavior of `calls`.
|
|
122
|
-
if (account?.type === 'json-rpc') {
|
|
123
|
-
if (rpc.calls?.length && rpc.calls.length > 1)
|
|
124
|
-
throw new Error(
|
|
125
|
-
'Batch calls are not supported with JSON-RPC accounts yet.',
|
|
126
|
-
)
|
|
127
|
-
rpc.type = undefined
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// We rely on `calls` for Tempo transactions.
|
|
131
|
-
// However, `calls` may not be supported by JSON-RPC accounts (wallets) yet,
|
|
132
|
-
// so we will not remove the `data`, `to`, and `value` fields to make it
|
|
133
|
-
// compatible with the base transaction structure.
|
|
134
|
-
if (account?.type !== 'json-rpc') {
|
|
135
|
-
rpc.to = undefined
|
|
136
|
-
rpc.data = undefined
|
|
137
|
-
rpc.value = undefined
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const [keyType, keyData] = (() => {
|
|
141
|
-
const type =
|
|
142
|
-
account && 'keyType' in account ? account.keyType : account?.source
|
|
143
|
-
if (!type) return [undefined, undefined]
|
|
144
|
-
if (type === 'webAuthn')
|
|
145
|
-
// TODO: derive correct bytes size of key data based on webauthn create metadata.
|
|
146
|
-
return ['webAuthn', `0x${'ff'.repeat(1400)}`]
|
|
147
|
-
if (['p256', 'secp256k1'].includes(type)) return [type, undefined]
|
|
148
|
-
return [undefined, undefined]
|
|
149
|
-
})()
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
...rpc,
|
|
153
|
-
...(keyType ? { keyType } : {}),
|
|
154
|
-
...(keyData ? { keyData } : {}),
|
|
155
|
-
...(request.feePayer
|
|
156
|
-
? {
|
|
157
|
-
feePayer:
|
|
158
|
-
typeof request.feePayer === 'object'
|
|
159
|
-
? parseAccount(request.feePayer)
|
|
160
|
-
: request.feePayer,
|
|
161
|
-
}
|
|
162
|
-
: {}),
|
|
163
|
-
} as never
|
|
164
|
-
}
|
package/src/viem/P256.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { randomPrivateKey } from 'ox/P256'
|
package/src/viem/Secp256k1.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { randomPrivateKey } from 'ox/Secp256k1'
|
package/src/viem/Storage.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { createStore, del, get, set } from 'idb-keyval'
|
|
2
|
-
import * as Json from 'ox/Json'
|
|
3
|
-
|
|
4
|
-
import type { MaybePromise } from '../internal/types.js'
|
|
5
|
-
import { normalizeValue } from './internal/utils.js'
|
|
6
|
-
|
|
7
|
-
export type Storage<
|
|
8
|
-
schema extends Record<string, unknown> = Record<string, unknown>,
|
|
9
|
-
> = {
|
|
10
|
-
getItem: <name extends keyof schema>(
|
|
11
|
-
name: name,
|
|
12
|
-
) => MaybePromise<schema[name] | null>
|
|
13
|
-
removeItem: <name extends keyof schema>(name: name) => MaybePromise<void>
|
|
14
|
-
setItem: <name extends keyof schema>(
|
|
15
|
-
name: name,
|
|
16
|
-
value: schema[name],
|
|
17
|
-
) => MaybePromise<void>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function from<schema extends Record<string, unknown>>(
|
|
21
|
-
storage: Storage,
|
|
22
|
-
options: { key?: string | undefined } = {},
|
|
23
|
-
): Storage<schema> {
|
|
24
|
-
const key = (name: any) => `${options.key ? `${options.key}:` : ''}${name}`
|
|
25
|
-
return {
|
|
26
|
-
getItem: (name) => storage.getItem(key(name)) as never,
|
|
27
|
-
removeItem: (name) => storage.removeItem(key(name)),
|
|
28
|
-
setItem: (name, value) => storage.setItem(key(name), value),
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export namespace from {
|
|
33
|
-
export type Options = {
|
|
34
|
-
key?: string | undefined
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function idb<schema extends Record<string, unknown>>() {
|
|
39
|
-
const store =
|
|
40
|
-
typeof indexedDB !== 'undefined'
|
|
41
|
-
? createStore('tempo.ts', 'store')
|
|
42
|
-
: undefined
|
|
43
|
-
return from<schema>({
|
|
44
|
-
async getItem(name) {
|
|
45
|
-
const value = await get(name, store)
|
|
46
|
-
if (value === null) return null
|
|
47
|
-
return value
|
|
48
|
-
},
|
|
49
|
-
async removeItem(name) {
|
|
50
|
-
await del(name, store)
|
|
51
|
-
},
|
|
52
|
-
async setItem(name, value) {
|
|
53
|
-
await set(name, normalizeValue(value), store)
|
|
54
|
-
},
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function localStorage<schema extends Record<string, unknown>>(
|
|
59
|
-
options: localStorage.Options = {},
|
|
60
|
-
) {
|
|
61
|
-
if (typeof window === 'undefined') return memory<schema>()
|
|
62
|
-
return from<schema>(
|
|
63
|
-
{
|
|
64
|
-
async getItem(name) {
|
|
65
|
-
const item = window.localStorage.getItem(name)
|
|
66
|
-
if (item === null) return null
|
|
67
|
-
try {
|
|
68
|
-
return Json.parse(item)
|
|
69
|
-
} catch {
|
|
70
|
-
return null
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
async removeItem(name) {
|
|
74
|
-
window.localStorage.removeItem(name)
|
|
75
|
-
},
|
|
76
|
-
async setItem(name, value) {
|
|
77
|
-
window.localStorage.setItem(name, Json.stringify(value))
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
options,
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export namespace localStorage {
|
|
85
|
-
export type Options = from.Options
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const store = new Map<string, any>()
|
|
89
|
-
export function memory<schema extends Record<string, unknown>>(
|
|
90
|
-
options: memory.Options = {},
|
|
91
|
-
) {
|
|
92
|
-
return from<schema>(
|
|
93
|
-
{
|
|
94
|
-
getItem(name) {
|
|
95
|
-
return store.get(name) ?? null
|
|
96
|
-
},
|
|
97
|
-
removeItem(name) {
|
|
98
|
-
store.delete(name)
|
|
99
|
-
},
|
|
100
|
-
setItem(name, value) {
|
|
101
|
-
store.set(name, value)
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
options,
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export namespace memory {
|
|
109
|
-
export type Options = from.Options
|
|
110
|
-
}
|
package/src/viem/TokenIds.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const pathUsd = 0n
|
package/src/viem/Transaction.ts
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
// TODO: Find opportunities to make this file less duplicated + more simplified with Viem v3.
|
|
2
|
-
|
|
3
|
-
import * as Hex from 'ox/Hex'
|
|
4
|
-
import * as Secp256k1 from 'ox/Secp256k1'
|
|
5
|
-
import * as Signature from 'ox/Signature'
|
|
6
|
-
import {
|
|
7
|
-
type AuthorizationTempo,
|
|
8
|
-
type KeyAuthorization,
|
|
9
|
-
type TransactionReceipt as ox_TransactionReceipt,
|
|
10
|
-
SignatureEnvelope,
|
|
11
|
-
TxEnvelopeTempo as TxTempo,
|
|
12
|
-
} from 'ox/tempo'
|
|
13
|
-
import {
|
|
14
|
-
type AccessList,
|
|
15
|
-
type Account,
|
|
16
|
-
type Address,
|
|
17
|
-
type FeeValuesEIP1559,
|
|
18
|
-
type ParseTransactionReturnType,
|
|
19
|
-
type TransactionBase,
|
|
20
|
-
type TransactionRequestBase,
|
|
21
|
-
type TransactionSerializableBase,
|
|
22
|
-
type TransactionSerializedGeneric,
|
|
23
|
-
getTransactionType as viem_getTransactionType,
|
|
24
|
-
parseTransaction as viem_parseTransaction,
|
|
25
|
-
type RpcTransaction as viem_RpcTransaction,
|
|
26
|
-
type RpcTransactionRequest as viem_RpcTransactionRequest,
|
|
27
|
-
type Signature as viem_Signature,
|
|
28
|
-
serializeTransaction as viem_serializeTransaction,
|
|
29
|
-
type Transaction as viem_Transaction,
|
|
30
|
-
type TransactionReceipt as viem_TransactionReceipt,
|
|
31
|
-
type TransactionRequest as viem_TransactionRequest,
|
|
32
|
-
type TransactionSerializable as viem_TransactionSerializable,
|
|
33
|
-
type TransactionSerialized as viem_TransactionSerialized,
|
|
34
|
-
type TransactionType as viem_TransactionType,
|
|
35
|
-
} from 'viem'
|
|
36
|
-
import type { ExactPartial, OneOf, PartialBy } from '../internal/types.js'
|
|
37
|
-
|
|
38
|
-
export type Transaction<
|
|
39
|
-
bigintType = bigint,
|
|
40
|
-
numberType = number,
|
|
41
|
-
pending extends boolean = false,
|
|
42
|
-
> = OneOf<
|
|
43
|
-
| viem_Transaction<bigintType, numberType, pending>
|
|
44
|
-
| TransactionTempo<bigintType, numberType, pending>
|
|
45
|
-
>
|
|
46
|
-
export type TransactionRpc<pending extends boolean = false> = OneOf<
|
|
47
|
-
| viem_RpcTransaction<pending>
|
|
48
|
-
| (Omit<
|
|
49
|
-
TransactionTempo<Hex.Hex, Hex.Hex, pending, '0x76'>,
|
|
50
|
-
'authorizationList' | 'keyAuthorization' | 'signature'
|
|
51
|
-
> & {
|
|
52
|
-
authorizationList?: AuthorizationTempo.ListRpc | undefined
|
|
53
|
-
keyAuthorization?: KeyAuthorization.Rpc | null | undefined
|
|
54
|
-
signature: SignatureEnvelope.SignatureEnvelopeRpc
|
|
55
|
-
})
|
|
56
|
-
>
|
|
57
|
-
|
|
58
|
-
export type TransactionTempo<
|
|
59
|
-
quantity = bigint,
|
|
60
|
-
index = number,
|
|
61
|
-
isPending extends boolean = boolean,
|
|
62
|
-
type = 'tempo',
|
|
63
|
-
> = PartialBy<
|
|
64
|
-
Omit<
|
|
65
|
-
TransactionBase<quantity, index, isPending>,
|
|
66
|
-
'data' | 'input' | 'value' | 'to'
|
|
67
|
-
>,
|
|
68
|
-
'r' | 's' | 'v' | 'yParity'
|
|
69
|
-
> & {
|
|
70
|
-
accessList: AccessList
|
|
71
|
-
authorizationList?: AuthorizationTempo.ListSigned<quantity, index> | undefined
|
|
72
|
-
calls: readonly TxTempo.Call<quantity>[]
|
|
73
|
-
chainId: index
|
|
74
|
-
feeToken?: Address | undefined
|
|
75
|
-
feePayerSignature?: viem_Signature | undefined
|
|
76
|
-
keyAuthorization?: KeyAuthorization.Signed<quantity, index> | null | undefined
|
|
77
|
-
nonceKey?: quantity | undefined
|
|
78
|
-
signature: SignatureEnvelope.SignatureEnvelope
|
|
79
|
-
type: type
|
|
80
|
-
validBefore?: index | undefined
|
|
81
|
-
validAfter?: index | undefined
|
|
82
|
-
} & FeeValuesEIP1559<quantity>
|
|
83
|
-
|
|
84
|
-
export type TransactionRequest<
|
|
85
|
-
bigintType = bigint,
|
|
86
|
-
numberType = number,
|
|
87
|
-
> = OneOf<
|
|
88
|
-
| viem_TransactionRequest<bigintType, numberType>
|
|
89
|
-
| TransactionRequestTempo<bigintType, numberType>
|
|
90
|
-
>
|
|
91
|
-
export type TransactionRequestRpc = OneOf<
|
|
92
|
-
viem_RpcTransactionRequest | TransactionRequestTempo<Hex.Hex, Hex.Hex, '0x76'>
|
|
93
|
-
>
|
|
94
|
-
|
|
95
|
-
export type TransactionReceipt<
|
|
96
|
-
quantity = bigint,
|
|
97
|
-
index = number,
|
|
98
|
-
status = 'success' | 'reverted',
|
|
99
|
-
type = TransactionType,
|
|
100
|
-
> = viem_TransactionReceipt<quantity, index, status, type> & {
|
|
101
|
-
feePayer?: Address | undefined
|
|
102
|
-
feeToken?: Address | undefined
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export type TransactionReceiptRpc = TransactionReceipt<
|
|
106
|
-
Hex.Hex,
|
|
107
|
-
Hex.Hex,
|
|
108
|
-
ox_TransactionReceipt.RpcStatus,
|
|
109
|
-
ox_TransactionReceipt.RpcType
|
|
110
|
-
>
|
|
111
|
-
|
|
112
|
-
export type TransactionRequestTempo<
|
|
113
|
-
quantity = bigint,
|
|
114
|
-
index = number,
|
|
115
|
-
type = 'tempo',
|
|
116
|
-
> = TransactionRequestBase<quantity, index, type> &
|
|
117
|
-
ExactPartial<FeeValuesEIP1559<quantity>> & {
|
|
118
|
-
accessList?: AccessList | undefined
|
|
119
|
-
keyAuthorization?: KeyAuthorization.Signed<quantity, index> | undefined
|
|
120
|
-
calls?: readonly TxTempo.Call<quantity>[] | undefined
|
|
121
|
-
feePayer?: Account | true | undefined
|
|
122
|
-
feeToken?: Address | bigint | undefined
|
|
123
|
-
nonceKey?: 'random' | quantity | undefined
|
|
124
|
-
validBefore?: index | undefined
|
|
125
|
-
validAfter?: index | undefined
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export type TransactionSerializable = OneOf<
|
|
129
|
-
viem_TransactionSerializable | TransactionSerializableTempo
|
|
130
|
-
>
|
|
131
|
-
|
|
132
|
-
export type TransactionSerializableTempo<
|
|
133
|
-
quantity = bigint,
|
|
134
|
-
index = number,
|
|
135
|
-
> = TransactionSerializableBase<quantity, index> &
|
|
136
|
-
ExactPartial<FeeValuesEIP1559<quantity>> & {
|
|
137
|
-
accessList?: AccessList | undefined
|
|
138
|
-
calls: readonly TxTempo.Call<quantity>[]
|
|
139
|
-
chainId: number
|
|
140
|
-
feeToken?: Address | bigint | undefined
|
|
141
|
-
feePayerSignature?: viem_Signature | null | undefined
|
|
142
|
-
keyAuthorization?: KeyAuthorization.Signed<quantity, index> | undefined
|
|
143
|
-
nonceKey?: quantity | undefined
|
|
144
|
-
signature?: SignatureEnvelope.SignatureEnvelope<quantity, index> | undefined
|
|
145
|
-
validBefore?: index | undefined
|
|
146
|
-
validAfter?: index | undefined
|
|
147
|
-
type?: 'tempo' | undefined
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export type TransactionSerialized<
|
|
151
|
-
type extends TransactionType = TransactionType,
|
|
152
|
-
> = viem_TransactionSerialized<type> | TransactionSerializedTempo
|
|
153
|
-
|
|
154
|
-
export type TransactionSerializedTempo = `0x76${string}`
|
|
155
|
-
|
|
156
|
-
export type TransactionType = viem_TransactionType | 'tempo'
|
|
157
|
-
|
|
158
|
-
export function getType(
|
|
159
|
-
transaction: Record<string, unknown>,
|
|
160
|
-
): Transaction['type'] {
|
|
161
|
-
if (
|
|
162
|
-
typeof transaction.calls !== 'undefined' ||
|
|
163
|
-
typeof transaction.feePayer !== 'undefined' ||
|
|
164
|
-
typeof transaction.feeToken !== 'undefined' ||
|
|
165
|
-
typeof transaction.nonceKey !== 'undefined' ||
|
|
166
|
-
typeof transaction.signature !== 'undefined' ||
|
|
167
|
-
typeof transaction.validBefore !== 'undefined' ||
|
|
168
|
-
typeof transaction.validAfter !== 'undefined'
|
|
169
|
-
)
|
|
170
|
-
return 'tempo' as never
|
|
171
|
-
if (transaction.type) return transaction.type as never
|
|
172
|
-
return viem_getTransactionType(transaction) as never
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export function isTempo(transaction: Record<string, unknown>) {
|
|
176
|
-
try {
|
|
177
|
-
const type = getType(transaction)
|
|
178
|
-
return type === 'tempo'
|
|
179
|
-
} catch {
|
|
180
|
-
return false
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function deserialize<
|
|
185
|
-
const serialized extends TransactionSerializedGeneric,
|
|
186
|
-
>(serializedTransaction: serialized): deserialize.ReturnValue<serialized> {
|
|
187
|
-
const type = Hex.slice(serializedTransaction, 0, 1)
|
|
188
|
-
if (type === '0x76') {
|
|
189
|
-
const from =
|
|
190
|
-
Hex.slice(serializedTransaction, -6) === '0xfeefeefeefee'
|
|
191
|
-
? Hex.slice(serializedTransaction, -26, -6)
|
|
192
|
-
: undefined
|
|
193
|
-
return {
|
|
194
|
-
...deserializeTempo(serializedTransaction as `0x76${string}`),
|
|
195
|
-
from,
|
|
196
|
-
} as never
|
|
197
|
-
}
|
|
198
|
-
return viem_parseTransaction(serializedTransaction) as never
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export declare namespace deserialize {
|
|
202
|
-
export type ReturnValue<
|
|
203
|
-
serialized extends
|
|
204
|
-
TransactionSerializedGeneric = TransactionSerializedGeneric,
|
|
205
|
-
> = serialized extends TransactionSerializedTempo
|
|
206
|
-
? TransactionSerializableTempo
|
|
207
|
-
: ParseTransactionReturnType<serialized>
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export async function serialize(
|
|
211
|
-
transaction: TransactionSerializable & {
|
|
212
|
-
feePayer?: Account | true | undefined
|
|
213
|
-
from?: Address | undefined
|
|
214
|
-
},
|
|
215
|
-
signature?:
|
|
216
|
-
| OneOf<SignatureEnvelope.SignatureEnvelope | viem_Signature>
|
|
217
|
-
| undefined,
|
|
218
|
-
) {
|
|
219
|
-
// If the transaction is not a Tempo transaction, route to Viem serializer.
|
|
220
|
-
if (!isTempo(transaction)) {
|
|
221
|
-
if (signature && 'type' in signature && signature.type !== 'secp256k1')
|
|
222
|
-
throw new Error(
|
|
223
|
-
'Unsupported signature type. Expected `secp256k1` but got `' +
|
|
224
|
-
signature.type +
|
|
225
|
-
'`.',
|
|
226
|
-
)
|
|
227
|
-
if (signature && 'type' in signature) {
|
|
228
|
-
const { r, s, yParity } = signature?.signature!
|
|
229
|
-
return viem_serializeTransaction(transaction as never, {
|
|
230
|
-
r: Hex.fromNumber(r, { size: 32 }),
|
|
231
|
-
s: Hex.fromNumber(s, { size: 32 }),
|
|
232
|
-
yParity,
|
|
233
|
-
})
|
|
234
|
-
}
|
|
235
|
-
return viem_serializeTransaction(transaction as never, signature)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const type = getType(transaction)
|
|
239
|
-
if (type === 'tempo')
|
|
240
|
-
return serializeTempo(
|
|
241
|
-
transaction as TransactionSerializableTempo,
|
|
242
|
-
signature,
|
|
243
|
-
)
|
|
244
|
-
|
|
245
|
-
throw new Error('Unsupported transaction type')
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
249
|
-
// Internal
|
|
250
|
-
|
|
251
|
-
/** @internal */
|
|
252
|
-
function deserializeTempo(
|
|
253
|
-
serializedTransaction: TransactionSerializedTempo,
|
|
254
|
-
): TransactionSerializableTempo {
|
|
255
|
-
const { feePayerSignature, nonce, ...tx } = TxTempo.deserialize(
|
|
256
|
-
serializedTransaction,
|
|
257
|
-
)
|
|
258
|
-
return {
|
|
259
|
-
...tx,
|
|
260
|
-
nonce: Number(nonce ?? 0n),
|
|
261
|
-
feePayerSignature: feePayerSignature
|
|
262
|
-
? {
|
|
263
|
-
r: Hex.fromNumber(feePayerSignature.r, { size: 32 }),
|
|
264
|
-
s: Hex.fromNumber(feePayerSignature.s, { size: 32 }),
|
|
265
|
-
yParity: feePayerSignature.yParity,
|
|
266
|
-
}
|
|
267
|
-
: feePayerSignature,
|
|
268
|
-
} satisfies TransactionSerializableTempo
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/** @internal */
|
|
272
|
-
async function serializeTempo(
|
|
273
|
-
transaction: TransactionSerializableTempo & {
|
|
274
|
-
feePayer?: Account | true | undefined
|
|
275
|
-
from?: Address | undefined
|
|
276
|
-
},
|
|
277
|
-
sig?: OneOf<SignatureEnvelope.SignatureEnvelope | viem_Signature> | undefined,
|
|
278
|
-
) {
|
|
279
|
-
const signature = (() => {
|
|
280
|
-
if (transaction.signature) return transaction.signature
|
|
281
|
-
if (sig && 'type' in sig) return sig as SignatureEnvelope.SignatureEnvelope
|
|
282
|
-
if (sig)
|
|
283
|
-
return SignatureEnvelope.from({
|
|
284
|
-
r: BigInt(sig.r!),
|
|
285
|
-
s: BigInt(sig.s!),
|
|
286
|
-
yParity: Number(sig.yParity!),
|
|
287
|
-
})
|
|
288
|
-
return undefined
|
|
289
|
-
})()
|
|
290
|
-
|
|
291
|
-
const { chainId, feePayer, feePayerSignature, nonce, ...rest } = transaction
|
|
292
|
-
|
|
293
|
-
const transaction_ox = {
|
|
294
|
-
...rest,
|
|
295
|
-
calls: rest.calls?.length
|
|
296
|
-
? rest.calls
|
|
297
|
-
: [
|
|
298
|
-
{
|
|
299
|
-
to:
|
|
300
|
-
rest.to ||
|
|
301
|
-
(!rest.data || rest.data === '0x'
|
|
302
|
-
? '0x0000000000000000000000000000000000000000'
|
|
303
|
-
: undefined),
|
|
304
|
-
value: rest.value,
|
|
305
|
-
data: rest.data,
|
|
306
|
-
},
|
|
307
|
-
],
|
|
308
|
-
chainId: Number(chainId),
|
|
309
|
-
feePayerSignature: feePayerSignature
|
|
310
|
-
? {
|
|
311
|
-
r: BigInt(feePayerSignature.r!),
|
|
312
|
-
s: BigInt(feePayerSignature.s!),
|
|
313
|
-
yParity: Number(feePayerSignature.yParity),
|
|
314
|
-
}
|
|
315
|
-
: feePayer
|
|
316
|
-
? null
|
|
317
|
-
: undefined,
|
|
318
|
-
type: 'tempo',
|
|
319
|
-
...(nonce ? { nonce: BigInt(nonce) } : {}),
|
|
320
|
-
} satisfies TxTempo.TxEnvelopeTempo
|
|
321
|
-
|
|
322
|
-
if (signature && typeof transaction.feePayer === 'object') {
|
|
323
|
-
const tx = TxTempo.from(transaction_ox, {
|
|
324
|
-
signature,
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
const sender = (() => {
|
|
328
|
-
if (transaction.from) return transaction.from
|
|
329
|
-
if (signature.type === 'secp256k1')
|
|
330
|
-
return Secp256k1.recoverAddress({
|
|
331
|
-
payload: TxTempo.getSignPayload(tx),
|
|
332
|
-
signature: signature.signature,
|
|
333
|
-
})
|
|
334
|
-
throw new Error('Unable to extract sender from transaction or signature.')
|
|
335
|
-
})()
|
|
336
|
-
|
|
337
|
-
const hash = TxTempo.getFeePayerSignPayload(tx, {
|
|
338
|
-
sender,
|
|
339
|
-
})
|
|
340
|
-
|
|
341
|
-
const feePayerSignature = await transaction.feePayer.sign!({
|
|
342
|
-
hash,
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
return TxTempo.serialize(tx, {
|
|
346
|
-
feePayerSignature: Signature.from(feePayerSignature),
|
|
347
|
-
})
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (feePayer === true) {
|
|
351
|
-
const serialized = TxTempo.serialize(transaction_ox, {
|
|
352
|
-
feePayerSignature: null,
|
|
353
|
-
signature,
|
|
354
|
-
})
|
|
355
|
-
// if the transaction is ready to be sent off (signed), add the sender
|
|
356
|
-
// and a fee marker to the serialized transaction, so the fee payer proxy
|
|
357
|
-
// can infer the sender address.
|
|
358
|
-
if (transaction.from && signature)
|
|
359
|
-
return Hex.concat(serialized, transaction.from, '0xfeefeefeefee')
|
|
360
|
-
return serialized
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return TxTempo.serialize(
|
|
364
|
-
// If we have specified a fee payer, the user will not be signing over the fee token.
|
|
365
|
-
// Defer the fee token signing to the fee payer.
|
|
366
|
-
{ ...transaction_ox, ...(feePayer ? { feeToken: undefined } : {}) },
|
|
367
|
-
{
|
|
368
|
-
feePayerSignature: undefined,
|
|
369
|
-
signature,
|
|
370
|
-
},
|
|
371
|
-
)
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Export types required for inference.
|
|
375
|
-
export {
|
|
376
|
-
/** @deprecated */
|
|
377
|
-
KeyAuthorization as z_KeyAuthorization,
|
|
378
|
-
/** @deprecated */
|
|
379
|
-
SignatureEnvelope as z_SignatureEnvelope,
|
|
380
|
-
/** @deprecated */
|
|
381
|
-
TxEnvelopeTempo as z_TxEnvelopeTempo,
|
|
382
|
-
} from 'ox/tempo'
|