viem 2.57.14 → 2.57.16
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 +58 -0
- package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
- package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
- package/_cjs/actions/public/estimateGas.js +5 -2
- package/_cjs/actions/public/estimateGas.js.map +1 -1
- package/_cjs/actions/public/fillTransaction.js +2 -0
- package/_cjs/actions/public/fillTransaction.js.map +1 -1
- package/_cjs/actions/public/getFilterChanges.js +1 -0
- package/_cjs/actions/public/getFilterChanges.js.map +1 -1
- package/_cjs/actions/public/getFilterLogs.js +1 -0
- package/_cjs/actions/public/getFilterLogs.js.map +1 -1
- package/_cjs/actions/public/watchBlockNumber.js +3 -1
- package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/_cjs/actions/public/watchBlocks.js +20 -8
- package/_cjs/actions/public/watchBlocks.js.map +1 -1
- package/_cjs/actions/public/watchContractEvent.js +10 -3
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/actions/public/watchEvent.js +5 -0
- package/_cjs/actions/public/watchEvent.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +3 -2
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/actions/wallet/sendTransaction.js +4 -2
- package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/_cjs/actions/wallet/sendTransactionSync.js +48 -7
- package/_cjs/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_cjs/chains/definitions/hashKeyChain.js +4 -4
- package/_cjs/chains/definitions/hashKeyChain.js.map +1 -1
- package/_cjs/chains/definitions/hashkeyChainTestnet.js +4 -4
- package/_cjs/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_cjs/chains/definitions/turkchain.js +26 -0
- package/_cjs/chains/definitions/turkchain.js.map +1 -0
- package/_cjs/chains/definitions/zksync.js +1 -1
- package/_cjs/chains/definitions/zksync.js.map +1 -1
- package/_cjs/chains/index.js +4 -2
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/createClient.js.map +1 -1
- package/_cjs/clients/transports/fallback.js +5 -0
- package/_cjs/clients/transports/fallback.js.map +1 -1
- package/_cjs/errors/node.js +10 -4
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/typedData.js +4 -2
- package/_cjs/errors/typedData.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +5 -4
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/Account.js +85 -12
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Gateway.js +195 -0
- package/_cjs/tempo/Gateway.js.map +1 -0
- package/_cjs/tempo/GatewayDecorator.js +168 -0
- package/_cjs/tempo/GatewayDecorator.js.map +1 -0
- package/_cjs/tempo/Transaction.js +2 -1
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/actions/ai.js +69 -0
- package/_cjs/tempo/actions/ai.js.map +1 -0
- package/_cjs/tempo/actions/bucket.js +85 -0
- package/_cjs/tempo/actions/bucket.js.map +1 -0
- package/_cjs/tempo/actions/compute.js +165 -0
- package/_cjs/tempo/actions/compute.js.map +1 -0
- package/_cjs/tempo/actions/gateway.js +8 -0
- package/_cjs/tempo/actions/gateway.js.map +1 -0
- package/_cjs/tempo/actions/index.js +6 -1
- package/_cjs/tempo/actions/index.js.map +1 -1
- package/_cjs/tempo/actions/kv.js +44 -0
- package/_cjs/tempo/actions/kv.js.map +1 -0
- package/_cjs/tempo/chainConfig.js +4 -12
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/index.js +4 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/tempo/internal/ndjson.js +43 -0
- package/_cjs/tempo/internal/ndjson.js.map +1 -0
- package/_cjs/tempo/internal/relay/feePayer.js +18 -5
- package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
- package/_cjs/utils/abi/decodeEventLog.js +57 -7
- package/_cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/_cjs/utils/abi/getAbiItem.js +27 -6
- package/_cjs/utils/abi/getAbiItem.js.map +1 -1
- package/_cjs/utils/abi/parseEventLogs.js +27 -4
- package/_cjs/utils/abi/parseEventLogs.js.map +1 -1
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js +9 -2
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_cjs/utils/authorization/verifyAuthorization.js +14 -4
- package/_cjs/utils/authorization/verifyAuthorization.js.map +1 -1
- package/_cjs/utils/buildRequest.js +4 -0
- package/_cjs/utils/buildRequest.js.map +1 -1
- package/_cjs/utils/ccip.js +134 -28
- package/_cjs/utils/ccip.js.map +1 -1
- package/_cjs/utils/ccipTunnel.js +5 -1
- package/_cjs/utils/ccipTunnel.js.map +1 -1
- package/_cjs/utils/ens/localBatchGatewayRequest.js +55 -5
- package/_cjs/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_cjs/utils/hash/toSignatureHash.js +10 -1
- package/_cjs/utils/hash/toSignatureHash.js.map +1 -1
- package/_cjs/utils/internal/http.js +79 -0
- package/_cjs/utils/internal/http.js.map +1 -0
- package/_cjs/utils/nonceManager.js.map +1 -1
- package/_cjs/utils/rpc/http.js +9 -76
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_cjs/utils/rpc/socket.js +20 -9
- package/_cjs/utils/rpc/socket.js.map +1 -1
- package/_cjs/utils/transaction/assertRequest.js +2 -2
- package/_cjs/utils/transaction/assertRequest.js.map +1 -1
- package/_cjs/utils/transaction/assertTransaction.js +2 -2
- package/_cjs/utils/transaction/assertTransaction.js.map +1 -1
- package/_cjs/utils/transaction/parseTransaction.js +21 -7
- package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
- package/_cjs/utils/typedData.js +19 -6
- package/_cjs/utils/typedData.js.map +1 -1
- package/_cjs/zksync/actions/finalizeWithdrawal.js +4 -2
- package/_cjs/zksync/actions/finalizeWithdrawal.js.map +1 -1
- package/_cjs/zksync/actions/isWithdrawalFinalized.js +4 -5
- package/_cjs/zksync/actions/isWithdrawalFinalized.js.map +1 -1
- package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
- package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
- package/_esm/actions/public/estimateGas.js +10 -5
- package/_esm/actions/public/estimateGas.js.map +1 -1
- package/_esm/actions/public/fillTransaction.js +2 -0
- package/_esm/actions/public/fillTransaction.js.map +1 -1
- package/_esm/actions/public/getFilterChanges.js +1 -0
- package/_esm/actions/public/getFilterChanges.js.map +1 -1
- package/_esm/actions/public/getFilterLogs.js +1 -0
- package/_esm/actions/public/getFilterLogs.js.map +1 -1
- package/_esm/actions/public/watchBlockNumber.js +5 -1
- package/_esm/actions/public/watchBlockNumber.js.map +1 -1
- package/_esm/actions/public/watchBlocks.js +28 -8
- package/_esm/actions/public/watchBlocks.js.map +1 -1
- package/_esm/actions/public/watchContractEvent.js +15 -5
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/actions/public/watchEvent.js +11 -2
- package/_esm/actions/public/watchEvent.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +3 -2
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/actions/wallet/sendTransaction.js +6 -2
- package/_esm/actions/wallet/sendTransaction.js.map +1 -1
- package/_esm/actions/wallet/sendTransactionSync.js +59 -8
- package/_esm/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_esm/chains/definitions/hashKeyChain.js +4 -4
- package/_esm/chains/definitions/hashKeyChain.js.map +1 -1
- package/_esm/chains/definitions/hashkeyChainTestnet.js +4 -4
- package/_esm/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_esm/chains/definitions/turkchain.js +23 -0
- package/_esm/chains/definitions/turkchain.js.map +1 -0
- package/_esm/chains/definitions/zksync.js +1 -1
- package/_esm/chains/definitions/zksync.js.map +1 -1
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/createClient.js.map +1 -1
- package/_esm/clients/transports/fallback.js +8 -0
- package/_esm/clients/transports/fallback.js.map +1 -1
- package/_esm/errors/node.js +10 -4
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/typedData.js +5 -2
- package/_esm/errors/typedData.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/Account.js +122 -11
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Gateway.js +294 -0
- package/_esm/tempo/Gateway.js.map +1 -0
- package/_esm/tempo/GatewayDecorator.js +207 -0
- package/_esm/tempo/GatewayDecorator.js.map +1 -0
- package/_esm/tempo/Transaction.js +2 -0
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/actions/ai.js +132 -0
- package/_esm/tempo/actions/ai.js.map +1 -0
- package/_esm/tempo/actions/bucket.js +181 -0
- package/_esm/tempo/actions/bucket.js.map +1 -0
- package/_esm/tempo/actions/compute.js +424 -0
- package/_esm/tempo/actions/compute.js.map +1 -0
- package/_esm/tempo/actions/gateway.js +22 -0
- package/_esm/tempo/actions/gateway.js.map +1 -0
- package/_esm/tempo/actions/index.js +10 -0
- package/_esm/tempo/actions/index.js.map +1 -1
- package/_esm/tempo/actions/kv.js +124 -0
- package/_esm/tempo/actions/kv.js.map +1 -0
- package/_esm/tempo/chainConfig.js +13 -15
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/index.js +9 -0
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/tempo/internal/ndjson.js +45 -0
- package/_esm/tempo/internal/ndjson.js.map +1 -0
- package/_esm/tempo/internal/relay/feePayer.js +24 -7
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/utils/abi/decodeEventLog.js +69 -7
- package/_esm/utils/abi/decodeEventLog.js.map +1 -1
- package/_esm/utils/abi/getAbiItem.js +34 -6
- package/_esm/utils/abi/getAbiItem.js.map +1 -1
- package/_esm/utils/abi/parseEventLogs.js +43 -10
- package/_esm/utils/abi/parseEventLogs.js.map +1 -1
- package/_esm/utils/authorization/recoverAuthorizationAddress.js +11 -2
- package/_esm/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_esm/utils/authorization/verifyAuthorization.js +15 -4
- package/_esm/utils/authorization/verifyAuthorization.js.map +1 -1
- package/_esm/utils/buildRequest.js +6 -0
- package/_esm/utils/buildRequest.js.map +1 -1
- package/_esm/utils/ccip.js +163 -31
- package/_esm/utils/ccip.js.map +1 -1
- package/_esm/utils/ccipTunnel.js +5 -1
- package/_esm/utils/ccipTunnel.js.map +1 -1
- package/_esm/utils/ens/localBatchGatewayRequest.js +69 -4
- package/_esm/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_esm/utils/hash/toSignatureHash.js +11 -1
- package/_esm/utils/hash/toSignatureHash.js.map +1 -1
- package/_esm/utils/internal/http.js +83 -0
- package/_esm/utils/internal/http.js.map +1 -0
- package/_esm/utils/nonceManager.js.map +1 -1
- package/_esm/utils/rpc/http.js +12 -78
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_esm/utils/rpc/socket.js +24 -9
- package/_esm/utils/rpc/socket.js.map +1 -1
- package/_esm/utils/transaction/assertRequest.js +2 -2
- package/_esm/utils/transaction/assertRequest.js.map +1 -1
- package/_esm/utils/transaction/assertTransaction.js +2 -2
- package/_esm/utils/transaction/assertTransaction.js.map +1 -1
- package/_esm/utils/transaction/parseTransaction.js +24 -7
- package/_esm/utils/transaction/parseTransaction.js.map +1 -1
- package/_esm/utils/typedData.js +25 -8
- package/_esm/utils/typedData.js.map +1 -1
- package/_esm/zksync/actions/finalizeWithdrawal.js +5 -2
- package/_esm/zksync/actions/finalizeWithdrawal.js.map +1 -1
- package/_esm/zksync/actions/isWithdrawalFinalized.js +5 -5
- package/_esm/zksync/actions/isWithdrawalFinalized.js.map +1 -1
- package/_types/account-abstraction/utils/formatters/userOperationReceipt.d.ts.map +1 -1
- package/_types/actions/public/estimateGas.d.ts.map +1 -1
- package/_types/actions/public/fillTransaction.d.ts.map +1 -1
- package/_types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/_types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/_types/actions/public/watchBlockNumber.d.ts +6 -2
- package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
- package/_types/actions/public/watchBlocks.d.ts +7 -2
- package/_types/actions/public/watchBlocks.d.ts.map +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/actions/public/watchEvent.d.ts.map +1 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransactionSync.d.ts.map +1 -1
- package/_types/chains/definitions/hashKeyChain.d.ts +4 -4
- package/_types/chains/definitions/hashkeyChainTestnet.d.ts +4 -4
- package/_types/chains/definitions/turkchain.d.ts +53 -0
- package/_types/chains/definitions/turkchain.d.ts.map +1 -0
- package/_types/chains/definitions/zksync.d.ts +1 -1
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/createClient.d.ts +6 -0
- package/_types/clients/createClient.d.ts.map +1 -1
- package/_types/clients/transports/fallback.d.ts.map +1 -1
- package/_types/errors/node.d.ts.map +1 -1
- package/_types/errors/typedData.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +77 -4
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Gateway.d.ts +337 -0
- package/_types/tempo/Gateway.d.ts.map +1 -0
- package/_types/tempo/GatewayDecorator.d.ts +635 -0
- package/_types/tempo/GatewayDecorator.d.ts.map +1 -0
- package/_types/tempo/Relay.d.ts +1 -1
- package/_types/tempo/Relay.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts +2 -0
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/actions/ai.d.ts +145 -0
- package/_types/tempo/actions/ai.d.ts.map +1 -0
- package/_types/tempo/actions/bucket.d.ts +210 -0
- package/_types/tempo/actions/bucket.d.ts.map +1 -0
- package/_types/tempo/actions/compute.d.ts +628 -0
- package/_types/tempo/actions/compute.d.ts.map +1 -0
- package/_types/tempo/actions/gateway.d.ts +25 -0
- package/_types/tempo/actions/gateway.d.ts.map +1 -0
- package/_types/tempo/actions/index.d.ts +10 -0
- package/_types/tempo/actions/index.d.ts.map +1 -1
- package/_types/tempo/actions/kv.d.ts +167 -0
- package/_types/tempo/actions/kv.d.ts.map +1 -0
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +11 -0
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/tempo/internal/ndjson.d.ts +9 -0
- package/_types/tempo/internal/ndjson.d.ts.map +1 -0
- package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
- package/_types/tempo/internal/relay/utils.d.ts +8 -8
- package/_types/utils/abi/decodeEventLog.d.ts +13 -1
- package/_types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/_types/utils/abi/getAbiItem.d.ts.map +1 -1
- package/_types/utils/abi/parseEventLogs.d.ts.map +1 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts +2 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts.map +1 -1
- package/_types/utils/authorization/verifyAuthorization.d.ts.map +1 -1
- package/_types/utils/buildRequest.d.ts.map +1 -1
- package/_types/utils/ccip.d.ts +24 -4
- package/_types/utils/ccip.d.ts.map +1 -1
- package/_types/utils/ccipTunnel.d.ts.map +1 -1
- package/_types/utils/ens/localBatchGatewayRequest.d.ts +26 -0
- package/_types/utils/ens/localBatchGatewayRequest.d.ts.map +1 -1
- package/_types/utils/hash/toSignatureHash.d.ts +1 -1
- package/_types/utils/hash/toSignatureHash.d.ts.map +1 -1
- package/_types/utils/internal/http.d.ts +16 -0
- package/_types/utils/internal/http.d.ts.map +1 -0
- package/_types/utils/nonceManager.d.ts +15 -1
- package/_types/utils/nonceManager.d.ts.map +1 -1
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/_types/utils/rpc/socket.d.ts.map +1 -1
- package/_types/utils/transaction/parseTransaction.d.ts.map +1 -1
- package/_types/utils/typedData.d.ts.map +1 -1
- package/account-abstraction/utils/formatters/userOperationReceipt.ts +1 -0
- package/actions/public/estimateGas.ts +12 -5
- package/actions/public/fillTransaction.ts +2 -0
- package/actions/public/getFilterChanges.ts +1 -0
- package/actions/public/getFilterLogs.ts +1 -0
- package/actions/public/watchBlockNumber.ts +11 -2
- package/actions/public/watchBlocks.ts +46 -14
- package/actions/public/watchContractEvent.ts +22 -4
- package/actions/public/watchEvent.ts +17 -1
- package/actions/wallet/prepareTransactionRequest.ts +6 -2
- package/actions/wallet/sendTransaction.ts +9 -3
- package/actions/wallet/sendTransactionSync.ts +74 -12
- package/chains/definitions/hashKeyChain.ts +4 -4
- package/chains/definitions/hashkeyChainTestnet.ts +4 -4
- package/chains/definitions/turkchain.ts +23 -0
- package/chains/definitions/zksync.ts +1 -1
- package/chains/index.ts +1 -0
- package/clients/createClient.ts +6 -0
- package/clients/transports/fallback.ts +11 -0
- package/errors/node.ts +11 -5
- package/errors/typedData.ts +5 -2
- package/errors/version.ts +1 -1
- package/index.ts +2 -0
- package/package.json +5 -1
- package/tempo/Account.ts +202 -16
- package/tempo/Gateway.ts +477 -0
- package/tempo/GatewayDecorator.ts +909 -0
- package/tempo/Relay.ts +1 -1
- package/tempo/Transaction.ts +3 -0
- package/tempo/actions/ai.ts +250 -0
- package/tempo/actions/bucket.ts +324 -0
- package/tempo/actions/compute.ts +894 -0
- package/tempo/actions/gateway.ts +33 -0
- package/tempo/actions/index.ts +10 -0
- package/tempo/actions/kv.ts +229 -0
- package/tempo/chainConfig.ts +13 -15
- package/tempo/index.ts +12 -0
- package/tempo/internal/ndjson.ts +51 -0
- package/tempo/internal/relay/feePayer.ts +30 -7
- package/utils/abi/decodeEventLog.ts +97 -10
- package/utils/abi/getAbiItem.ts +35 -5
- package/utils/abi/parseEventLogs.ts +48 -11
- package/utils/authorization/recoverAuthorizationAddress.ts +18 -2
- package/utils/authorization/verifyAuthorization.ts +12 -7
- package/utils/buildRequest.ts +4 -0
- package/utils/ccip.ts +199 -33
- package/utils/ccipTunnel.ts +5 -1
- package/utils/ens/localBatchGatewayRequest.ts +82 -4
- package/utils/hash/toSignatureHash.ts +12 -2
- package/utils/internal/http.ts +92 -0
- package/utils/nonceManager.ts +16 -1
- package/utils/rpc/http.ts +12 -86
- package/utils/rpc/socket.ts +28 -15
- package/utils/transaction/assertRequest.ts +2 -2
- package/utils/transaction/assertTransaction.ts +2 -2
- package/utils/transaction/parseTransaction.ts +32 -7
- package/utils/typedData.ts +31 -8
- package/zksync/actions/finalizeWithdrawal.ts +5 -2
- package/zksync/actions/isWithdrawalFinalized.ts +5 -5
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as Gateway from '../Gateway.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reads the Gateway's free discovery document: chain, currencies, prices,
|
|
5
|
+
* limits, and models.
|
|
6
|
+
*
|
|
7
|
+
* @experimental
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
12
|
+
*
|
|
13
|
+
* const capabilities = await Actions.gateway.getCapabilities(Gateway.from())
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param gateway - Gateway connection.
|
|
17
|
+
* @param parameters - Parameters.
|
|
18
|
+
* @returns The Gateway capabilities.
|
|
19
|
+
*/
|
|
20
|
+
export async function getCapabilities(
|
|
21
|
+
gateway: Gateway.Gateway,
|
|
22
|
+
parameters: getCapabilities.Parameters = {},
|
|
23
|
+
): Promise<getCapabilities.ReturnValue> {
|
|
24
|
+
return Gateway.getCapabilities(gateway, parameters)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export declare namespace getCapabilities {
|
|
28
|
+
type Parameters = Gateway.getCapabilities.Options
|
|
29
|
+
|
|
30
|
+
type ReturnValue = Gateway.Capabilities
|
|
31
|
+
|
|
32
|
+
type ErrorType = Gateway.request.ErrorType
|
|
33
|
+
}
|
package/tempo/actions/index.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
// biome-ignore lint/performance/noBarrelFile: _
|
|
2
2
|
export * as accessKey from './accessKey.js'
|
|
3
3
|
export * as accounts from './accounts.js'
|
|
4
|
+
/** @experimental */
|
|
5
|
+
export * as ai from './ai.js'
|
|
4
6
|
export * as amm from './amm.js'
|
|
7
|
+
/** @experimental */
|
|
8
|
+
export * as bucket from './bucket.js'
|
|
5
9
|
export * as channel from './channel.js'
|
|
10
|
+
/** @experimental */
|
|
11
|
+
export * as compute from './compute.js'
|
|
6
12
|
export * as dex from './dex.js'
|
|
7
13
|
export * as earn from './earn.js'
|
|
8
14
|
export * as faucet from './faucet.js'
|
|
9
15
|
export * as fee from './fee.js'
|
|
16
|
+
/** @experimental */
|
|
17
|
+
export * as gateway from './gateway.js'
|
|
18
|
+
/** @experimental */
|
|
19
|
+
export * as kv from './kv.js'
|
|
10
20
|
export * as nonce from './nonce.js'
|
|
11
21
|
export * as policy from './policy.js'
|
|
12
22
|
export * as propAmm from './propAmm.js'
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import * as Gateway from '../Gateway.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Entry in a Gateway key-value store.
|
|
5
|
+
*
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
export type Entry = {
|
|
9
|
+
/** Expiry as a Unix timestamp in milliseconds. */
|
|
10
|
+
expiresAt: number
|
|
11
|
+
/** Key. */
|
|
12
|
+
key: string
|
|
13
|
+
/** JSON value. Validate it before use. */
|
|
14
|
+
value: unknown
|
|
15
|
+
/** Version, incremented on every write. */
|
|
16
|
+
version: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Deletes a key from the app's key-value store. Paid per request.
|
|
21
|
+
*
|
|
22
|
+
* @experimental
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
27
|
+
*
|
|
28
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
29
|
+
*
|
|
30
|
+
* const { deleted } = await Actions.kv.delete(gateway, { key: 'counter' })
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param gateway - Gateway connection.
|
|
34
|
+
* @param parameters - Parameters.
|
|
35
|
+
* @returns Whether the key existed.
|
|
36
|
+
*/
|
|
37
|
+
// biome-ignore lint/correctness/noUnusedVariables: exported as delete
|
|
38
|
+
async function delete_(
|
|
39
|
+
gateway: Gateway.Gateway,
|
|
40
|
+
parameters: delete_.Parameters,
|
|
41
|
+
): Promise<delete_.ReturnValue> {
|
|
42
|
+
const { key, signal } = parameters
|
|
43
|
+
const response = await Gateway.request(gateway, {
|
|
44
|
+
body: JSON.stringify({ key }),
|
|
45
|
+
path: '/kv/delete',
|
|
46
|
+
signal,
|
|
47
|
+
})
|
|
48
|
+
return (await response.json()) as delete_.ReturnValue
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare namespace delete_ {
|
|
52
|
+
type Parameters = {
|
|
53
|
+
/** Key. */
|
|
54
|
+
key: string
|
|
55
|
+
/** Signal to abort the request. */
|
|
56
|
+
signal?: AbortSignal | undefined
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type ReturnValue = {
|
|
60
|
+
/** Whether the key existed. */
|
|
61
|
+
deleted: boolean
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type ErrorType = Gateway.request.ErrorType
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { delete_ as delete }
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Reads a key from the app's key-value store. Returns `null` when the key does
|
|
71
|
+
* not exist or expired. Paid per request.
|
|
72
|
+
*
|
|
73
|
+
* @experimental
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
78
|
+
*
|
|
79
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
80
|
+
*
|
|
81
|
+
* const entry = await Actions.kv.get(gateway, { key: 'counter' })
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @param gateway - Gateway connection.
|
|
85
|
+
* @param parameters - Parameters.
|
|
86
|
+
* @returns The entry, or `null`.
|
|
87
|
+
*/
|
|
88
|
+
export async function get(
|
|
89
|
+
gateway: Gateway.Gateway,
|
|
90
|
+
parameters: get.Parameters,
|
|
91
|
+
): Promise<get.ReturnValue> {
|
|
92
|
+
const { key, signal } = parameters
|
|
93
|
+
const response = await Gateway.request(gateway, {
|
|
94
|
+
body: JSON.stringify({ key }),
|
|
95
|
+
path: '/kv/get',
|
|
96
|
+
signal,
|
|
97
|
+
})
|
|
98
|
+
return (await response.json()) as get.ReturnValue
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export declare namespace get {
|
|
102
|
+
type Parameters = {
|
|
103
|
+
/** Key. */
|
|
104
|
+
key: string
|
|
105
|
+
/** Signal to abort the request. */
|
|
106
|
+
signal?: AbortSignal | undefined
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type ReturnValue = Entry | null
|
|
110
|
+
|
|
111
|
+
type ErrorType = Gateway.request.ErrorType
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Lists entries in the app's key-value store by key prefix, in key order. Paid
|
|
116
|
+
* per request.
|
|
117
|
+
*
|
|
118
|
+
* @experimental
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
123
|
+
*
|
|
124
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
125
|
+
*
|
|
126
|
+
* const { cursor, entries } = await Actions.kv.list(gateway, {
|
|
127
|
+
* prefix: 'settings/',
|
|
128
|
+
* })
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @param gateway - Gateway connection.
|
|
132
|
+
* @param parameters - Parameters.
|
|
133
|
+
* @returns A page of entries and the next cursor.
|
|
134
|
+
*/
|
|
135
|
+
export async function list(
|
|
136
|
+
gateway: Gateway.Gateway,
|
|
137
|
+
parameters: list.Parameters = {},
|
|
138
|
+
): Promise<list.ReturnValue> {
|
|
139
|
+
const { cursor, limit, prefix, signal } = parameters
|
|
140
|
+
const response = await Gateway.request(gateway, {
|
|
141
|
+
body: JSON.stringify({ cursor, limit, prefix }),
|
|
142
|
+
path: '/kv/list',
|
|
143
|
+
signal,
|
|
144
|
+
})
|
|
145
|
+
return (await response.json()) as list.ReturnValue
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export declare namespace list {
|
|
149
|
+
type Parameters = {
|
|
150
|
+
/** Cursor from a previous page. */
|
|
151
|
+
cursor?: string | undefined
|
|
152
|
+
/** Maximum entries per page. */
|
|
153
|
+
limit?: number | undefined
|
|
154
|
+
/** Key prefix. */
|
|
155
|
+
prefix?: string | undefined
|
|
156
|
+
/** Signal to abort the request. */
|
|
157
|
+
signal?: AbortSignal | undefined
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
type ReturnValue = {
|
|
161
|
+
/** Cursor of the next page, or `null` on the last page. */
|
|
162
|
+
cursor: string | null
|
|
163
|
+
/** Entries on this page. */
|
|
164
|
+
entries: readonly Entry[]
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
type ErrorType = Gateway.request.ErrorType
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Writes a JSON value to the app's key-value store. Paid per request.
|
|
172
|
+
*
|
|
173
|
+
* Pass `ifVersion` to write conditionally: `null` creates the key only if it
|
|
174
|
+
* does not exist, and a version replaces the value only if it is still that
|
|
175
|
+
* version. A failed condition throws `Gateway.VersionConflictError`.
|
|
176
|
+
*
|
|
177
|
+
* @experimental
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* import { Actions, Gateway } from 'viem/tempo'
|
|
182
|
+
*
|
|
183
|
+
* const gateway = Gateway.from({ fetch: mppx.fetch })
|
|
184
|
+
*
|
|
185
|
+
* const entry = await Actions.kv.set(gateway, {
|
|
186
|
+
* ifVersion: null,
|
|
187
|
+
* key: 'counter',
|
|
188
|
+
* value: { count: 1 },
|
|
189
|
+
* })
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @param gateway - Gateway connection.
|
|
193
|
+
* @param parameters - Parameters.
|
|
194
|
+
* @returns The written entry.
|
|
195
|
+
*/
|
|
196
|
+
export async function set(
|
|
197
|
+
gateway: Gateway.Gateway,
|
|
198
|
+
parameters: set.Parameters,
|
|
199
|
+
): Promise<set.ReturnValue> {
|
|
200
|
+
const { ifVersion, key, signal, ttl, value } = parameters
|
|
201
|
+
const response = await Gateway.request(gateway, {
|
|
202
|
+
body: JSON.stringify({ ifVersion, key, ttl, value }),
|
|
203
|
+
path: '/kv/set',
|
|
204
|
+
signal,
|
|
205
|
+
})
|
|
206
|
+
return (await response.json()) as set.ReturnValue
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export declare namespace set {
|
|
210
|
+
type Parameters = {
|
|
211
|
+
/**
|
|
212
|
+
* Write condition: `null` creates the key only if it does not exist; a
|
|
213
|
+
* version replaces the value only if it is still that version.
|
|
214
|
+
*/
|
|
215
|
+
ifVersion?: number | null | undefined
|
|
216
|
+
/** Key. */
|
|
217
|
+
key: string
|
|
218
|
+
/** Signal to abort the request. */
|
|
219
|
+
signal?: AbortSignal | undefined
|
|
220
|
+
/** Time to live in seconds. Without it, the entry is kept for the Gateway's longest retention (`limits.retentionSeconds`). */
|
|
221
|
+
ttl?: number | undefined
|
|
222
|
+
/** JSON-serializable value. */
|
|
223
|
+
value: unknown
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
type ReturnValue = Entry
|
|
227
|
+
|
|
228
|
+
type ErrorType = Gateway.request.ErrorType
|
|
229
|
+
}
|
package/tempo/chainConfig.ts
CHANGED
|
@@ -36,7 +36,8 @@ import * as Concurrent from './internal/concurrent.js'
|
|
|
36
36
|
import { transactionReplacement } from './internal/replacement.js'
|
|
37
37
|
import * as Transaction from './Transaction.js'
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
/** Default distance, in seconds, of a generated expiring nonce `validBefore`. Stays under the 300-second limit to allow for clock skew. */
|
|
40
|
+
const expiringNonceExpiry = 270
|
|
40
41
|
|
|
41
42
|
// TODO: casting to satisfy viem – viem v3 to have more flexible serializer type.
|
|
42
43
|
const serializeTransaction = ((transaction, signature) =>
|
|
@@ -165,7 +166,8 @@ export const chainConfig = {
|
|
|
165
166
|
!request.feePayerSignature &&
|
|
166
167
|
!approved
|
|
167
168
|
) {
|
|
168
|
-
// The fill omits the fee payer's signature and fee token (85 bytes), which count toward intrinsic gas
|
|
169
|
+
// The fill omits the fee payer's signature and fee token (85 bytes), which count toward intrinsic gas,
|
|
170
|
+
// and, from T14, the cold access (2,600 gas) of the fee payer's account.
|
|
169
171
|
request.gas = (request.gas ?? 0n) + feePayerGas
|
|
170
172
|
if (request.keyAuthorization?.signature.type === 'webAuthn')
|
|
171
173
|
request.gas = (request.gas ?? 0n) + 20_000n
|
|
@@ -259,11 +261,12 @@ export const chainConfig = {
|
|
|
259
261
|
request.nonce = 0
|
|
260
262
|
} else if (useExpiringNonce) {
|
|
261
263
|
request.nonceKey = maxUint256
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
264
|
+
// A random discriminator keeps otherwise identical expiring transactions distinct.
|
|
265
|
+
// 48 bits stay within `Number.MAX_SAFE_INTEGER`.
|
|
266
|
+
request.nonce ??= Hex.toNumber(Hex.random(6))
|
|
265
267
|
if (typeof request.validBefore === 'undefined')
|
|
266
|
-
request.validBefore =
|
|
268
|
+
request.validBefore =
|
|
269
|
+
Math.floor(Date.now() / 1000) + expiringNonceExpiry
|
|
267
270
|
} else if (
|
|
268
271
|
typeof request.nonceKey !== 'undefined' &&
|
|
269
272
|
// Nonce key 0 is the protocol nonce, so core fills it like an Ethereum nonce.
|
|
@@ -506,14 +509,6 @@ function getSimulationKey(
|
|
|
506
509
|
return { keyData: '0x0578' as const, keyType: 'webAuthn' as const }
|
|
507
510
|
}
|
|
508
511
|
|
|
509
|
-
/** Returns random past seconds to distinguish otherwise-identical expiring transactions. */
|
|
510
|
-
function randomValidAfter(): number {
|
|
511
|
-
const now = BigInt(Math.floor(Date.now() / 1_000))
|
|
512
|
-
const latest = now - 60n
|
|
513
|
-
if (latest <= 0n) return 0
|
|
514
|
-
return Number(BigInt(Hex.random(8)) % latest)
|
|
515
|
-
}
|
|
516
|
-
|
|
517
512
|
/** Selects a deterministic minimum-cardinality owner quorum. */
|
|
518
513
|
function selectOwners(config: AccountConfig.Config) {
|
|
519
514
|
const owners = [...config.owners].sort(
|
|
@@ -533,5 +528,8 @@ function selectOwners(config: AccountConfig.Config) {
|
|
|
533
528
|
)
|
|
534
529
|
}
|
|
535
530
|
|
|
536
|
-
/**
|
|
531
|
+
/**
|
|
532
|
+
* Intrinsic gas reserved for what `eth_fillTransaction` estimates without: the fee payer's signature and
|
|
533
|
+
* fee token, and, from T14, one cold access (2,600 gas) of the fee payer's account. Earlier forks refund the unused gas.
|
|
534
|
+
*/
|
|
537
535
|
const feePayerGas = 5_000n
|
package/tempo/index.ts
CHANGED
|
@@ -72,6 +72,18 @@ export * as ExecutionError from './ExecutionError.js'
|
|
|
72
72
|
export * as Expiry from './Expiry.js'
|
|
73
73
|
export * from './errors.js'
|
|
74
74
|
export * as Formatters from './Formatters.js'
|
|
75
|
+
/**
|
|
76
|
+
* Wallet-paid inference, object storage, sandboxed compute, and key-value state
|
|
77
|
+
* on a Tempo Gateway.
|
|
78
|
+
* @experimental
|
|
79
|
+
*/
|
|
80
|
+
export * as Gateway from './Gateway.js'
|
|
81
|
+
export {
|
|
82
|
+
/** @experimental */
|
|
83
|
+
type Decorator as GatewayActions,
|
|
84
|
+
/** @experimental */
|
|
85
|
+
decorator as gatewayActions,
|
|
86
|
+
} from './GatewayDecorator.js'
|
|
75
87
|
export * as Hardfork from './Hardfork.js'
|
|
76
88
|
/** Client-side storage for pending key authorizations, backed by a `Store`. */
|
|
77
89
|
export * as KeyAuthorizationManager from './KeyAuthorizationManager.js'
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as Gateway from '../Gateway.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reads a Gateway NDJSON stream, one event per line. An `error` event throws a
|
|
5
|
+
* {@link Gateway.RequestError}. Stopping early cancels the response body, so
|
|
6
|
+
* the Gateway stops the upstream work.
|
|
7
|
+
*/
|
|
8
|
+
export async function* read<event extends { type: string }>(
|
|
9
|
+
response: Response,
|
|
10
|
+
): AsyncGenerator<event> {
|
|
11
|
+
if (!response.body) return
|
|
12
|
+
|
|
13
|
+
const reader = response.body.getReader()
|
|
14
|
+
const decoder = new TextDecoder()
|
|
15
|
+
let buffer = ''
|
|
16
|
+
let done = false
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
for (;;) {
|
|
20
|
+
const result = await reader.read()
|
|
21
|
+
done = result.done
|
|
22
|
+
const value = result.value
|
|
23
|
+
buffer += decoder.decode(value, { stream: !done })
|
|
24
|
+
|
|
25
|
+
const lines = buffer.split('\n')
|
|
26
|
+
buffer = done ? '' : (lines.pop() ?? '')
|
|
27
|
+
|
|
28
|
+
for (const line of lines) {
|
|
29
|
+
if (!line.trim()) continue
|
|
30
|
+
|
|
31
|
+
const event = JSON.parse(line) as event & {
|
|
32
|
+
code?: string
|
|
33
|
+
detail?: string
|
|
34
|
+
}
|
|
35
|
+
if (event.type === 'error')
|
|
36
|
+
throw new Gateway.RequestError({
|
|
37
|
+
code: event.code ?? 'upstream_failed',
|
|
38
|
+
detail: event.detail ?? '',
|
|
39
|
+
status: 502,
|
|
40
|
+
url: response.url,
|
|
41
|
+
})
|
|
42
|
+
yield event
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (done) return
|
|
46
|
+
}
|
|
47
|
+
} finally {
|
|
48
|
+
if (!done) await reader.cancel().catch(() => {})
|
|
49
|
+
reader.releaseLock()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -19,6 +19,7 @@ import { getBlockNumber } from '../../../actions/public/getBlockNumber.js'
|
|
|
19
19
|
import { readContract } from '../../../actions/public/readContract.js'
|
|
20
20
|
import { type Client, createClient } from '../../../clients/createClient.js'
|
|
21
21
|
import { http } from '../../../clients/transports/http.js'
|
|
22
|
+
import { maxUint256 } from '../../../constants/number.js'
|
|
22
23
|
import * as AccessKey from '../../actions/accessKey.js'
|
|
23
24
|
import type * as Relay from '../../Relay.js'
|
|
24
25
|
import * as Transaction from '../../Transaction.js'
|
|
@@ -180,7 +181,10 @@ export function create(options: Relay.feePayer.Options): Relay.Plugin {
|
|
|
180
181
|
// Bound before validation so the validated envelope is the one signed, and returned signatures expire.
|
|
181
182
|
const signs = !!options.account && !external && !defer
|
|
182
183
|
if (signs && filled.validBefore == null)
|
|
183
|
-
filled.validBefore = Validity.generate({
|
|
184
|
+
filled.validBefore = Validity.generate({
|
|
185
|
+
nonceKey: filled.nonceKey,
|
|
186
|
+
validity,
|
|
187
|
+
})
|
|
184
188
|
|
|
185
189
|
const sponsored =
|
|
186
190
|
external ||
|
|
@@ -835,27 +839,37 @@ const defaultValidity = 3_600
|
|
|
835
839
|
/** Granularity, in seconds, of a generated `validBefore`, so identical fill retries share one sign payload. */
|
|
836
840
|
const validityStep = 300
|
|
837
841
|
|
|
842
|
+
/** Headroom, in seconds, that generated expiring windows leave under the protocol limit. */
|
|
843
|
+
const skew = 30
|
|
844
|
+
|
|
838
845
|
/** Bounds on how long a returned fee-payer signature stays valid on chain. */
|
|
839
846
|
namespace Validity {
|
|
840
|
-
/** Returns a `validBefore` rounded down to the generation step, then extended by
|
|
847
|
+
/** Returns a `validBefore` rounded down to the generation step, then extended by the window's limit. */
|
|
841
848
|
export function generate(options: generate.Options) {
|
|
842
|
-
|
|
843
|
-
const
|
|
849
|
+
// Generated expiring windows stay under the protocol limit to allow for clock skew against the node.
|
|
850
|
+
const max =
|
|
851
|
+
options.nonceKey === maxUint256
|
|
852
|
+
? Math.min(limit(options), Transaction.expiringNonceMaxExpiry - skew)
|
|
853
|
+
: limit(options)
|
|
854
|
+
// A step of at most a tenth of the limit keeps every generated window at least 90% of it.
|
|
855
|
+
const step = Math.min(validityStep, Math.ceil(max / 10))
|
|
844
856
|
const time = Math.floor(Date.now() / 1_000)
|
|
845
|
-
return time - (time % step) +
|
|
857
|
+
return time - (time % step) + max
|
|
846
858
|
}
|
|
847
859
|
|
|
848
860
|
export declare namespace generate {
|
|
849
861
|
type Options = {
|
|
862
|
+
/** Nonce lane of the transaction. An expiring nonce lane caps the window at the protocol limit. */
|
|
863
|
+
nonceKey?: bigint | undefined
|
|
850
864
|
/** Longest validity window, in seconds. */
|
|
851
865
|
validity: number
|
|
852
866
|
}
|
|
853
867
|
}
|
|
854
868
|
|
|
855
|
-
/** Throws unless `validBefore` is a future time within
|
|
869
|
+
/** Throws unless `validBefore` is a future time within the window's limit that opens after `validAfter`. */
|
|
856
870
|
export function assert(window: assert.Window, options: assert.Options) {
|
|
857
871
|
const { validAfter, validBefore } = window
|
|
858
|
-
const {
|
|
872
|
+
const validity = limit({ nonceKey: window.nonceKey, ...options })
|
|
859
873
|
const time = Math.floor(Date.now() / 1_000)
|
|
860
874
|
if (
|
|
861
875
|
validBefore === undefined ||
|
|
@@ -875,6 +889,8 @@ namespace Validity {
|
|
|
875
889
|
export declare namespace assert {
|
|
876
890
|
/** Validity window of the transaction being co-signed, in unix seconds. */
|
|
877
891
|
type Window = {
|
|
892
|
+
/** Nonce lane. An expiring nonce lane caps the window at the protocol limit. */
|
|
893
|
+
nonceKey?: bigint | undefined
|
|
878
894
|
/** Earliest inclusion time. */
|
|
879
895
|
validAfter?: number | null | undefined
|
|
880
896
|
/** Latest inclusion time. */
|
|
@@ -886,6 +902,13 @@ namespace Validity {
|
|
|
886
902
|
validity: number
|
|
887
903
|
}
|
|
888
904
|
}
|
|
905
|
+
|
|
906
|
+
/** Returns `validity`, capped at the protocol limit for expiring nonce lanes. */
|
|
907
|
+
function limit(options: generate.Options) {
|
|
908
|
+
const { nonceKey, validity } = options
|
|
909
|
+
if (nonceKey !== maxUint256) return validity
|
|
910
|
+
return Math.min(validity, Transaction.expiringNonceMaxExpiry)
|
|
911
|
+
}
|
|
889
912
|
}
|
|
890
913
|
|
|
891
914
|
/** Facts of one sponsorship commitment, emitted at fee-payer signing time. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Abi, AbiParameter } from 'abitype'
|
|
1
|
+
import type { Abi, AbiEvent, AbiParameter } from 'abitype'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
AbiDecodingDataSizeTooSmallError,
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
DecodeLogTopicsMismatch,
|
|
13
13
|
type DecodeLogTopicsMismatchErrorType,
|
|
14
14
|
} from '../../errors/abi.js'
|
|
15
|
+
import { BaseError } from '../../errors/base.js'
|
|
15
16
|
import { PositionOutOfBoundsError } from '../../errors/cursor.js'
|
|
16
17
|
import type { ErrorType } from '../../errors/utils.js'
|
|
17
18
|
import type {
|
|
@@ -84,6 +85,7 @@ export type DecodeEventLogReturnType<
|
|
|
84
85
|
|
|
85
86
|
export type DecodeEventLogErrorType =
|
|
86
87
|
| AbiDecodingDataSizeTooSmallErrorType
|
|
88
|
+
| AbiEventAmbiguityErrorType
|
|
87
89
|
| AbiEventSignatureEmptyTopicsErrorType
|
|
88
90
|
| AbiEventSignatureNotFoundErrorType
|
|
89
91
|
| DecodeAbiParametersErrorType
|
|
@@ -107,23 +109,81 @@ export function decodeEventLog<
|
|
|
107
109
|
const {
|
|
108
110
|
abi,
|
|
109
111
|
data,
|
|
112
|
+
eventName,
|
|
110
113
|
strict: strict_,
|
|
111
114
|
topics,
|
|
112
115
|
} = parameters as DecodeEventLogParameters
|
|
113
116
|
|
|
114
117
|
const strict = strict_ ?? true
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const abiItem = abi.find(
|
|
119
|
-
(x) =>
|
|
120
|
-
x.type === 'event' &&
|
|
121
|
-
signature === toEventSelector(formatAbiItem(x) as EventDefinition),
|
|
118
|
+
const events = abi.filter(
|
|
119
|
+
(item): item is AbiEvent => item.type === 'event' && 'name' in item,
|
|
122
120
|
)
|
|
121
|
+
// Anonymous events omit the signature topic, so `topics[0]` is an indexed
|
|
122
|
+
// argument. A signature match still wins when the log has one.
|
|
123
|
+
const signature = topics[0]
|
|
124
|
+
const bySelector = signature
|
|
125
|
+
? events.find(
|
|
126
|
+
(item) =>
|
|
127
|
+
!item.anonymous &&
|
|
128
|
+
signature === toEventSelector(formatAbiItem(item) as EventDefinition),
|
|
129
|
+
)
|
|
130
|
+
: undefined
|
|
131
|
+
const candidates = bySelector
|
|
132
|
+
? [bySelector]
|
|
133
|
+
: anonymousCandidates(events, topics.length, eventName)
|
|
123
134
|
|
|
124
|
-
if (
|
|
135
|
+
if (candidates.length > 1)
|
|
136
|
+
throw new AbiEventAmbiguityError(candidates.map((item) => item.name))
|
|
137
|
+
const abiItem = candidates[0]
|
|
138
|
+
if (!abiItem) {
|
|
139
|
+
if (!signature) throw new AbiEventSignatureEmptyTopicsError({ docsPath })
|
|
125
140
|
throw new AbiEventSignatureNotFoundError(signature, { docsPath })
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return decodeMatchedEventLog({
|
|
144
|
+
abiItem,
|
|
145
|
+
argTopics: abiItem.anonymous ? topics : topics.slice(1),
|
|
146
|
+
data,
|
|
147
|
+
strict,
|
|
148
|
+
}) as DecodeEventLogReturnType<abi, eventName, topics, data, strict>
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function anonymousCandidates(
|
|
152
|
+
events: readonly AbiEvent[],
|
|
153
|
+
topicCount: number,
|
|
154
|
+
eventName: string | undefined,
|
|
155
|
+
) {
|
|
156
|
+
// Nothing in a log identifies an anonymous event, so any log with the same
|
|
157
|
+
// topic count fits it. Anonymous events are only considered when requested:
|
|
158
|
+
// `eventName` names one, or every event in the ABI is anonymous. Otherwise a
|
|
159
|
+
// log from another contract is decoded as the anonymous event.
|
|
160
|
+
const requested = (() => {
|
|
161
|
+
if (eventName) return events.filter((item) => item.name === eventName)
|
|
162
|
+
if (events.every((item) => item.anonymous)) return events
|
|
163
|
+
return []
|
|
164
|
+
})()
|
|
165
|
+
// `eventName` does not skip the arity check, or a same-name overload with
|
|
166
|
+
// extra topics is guessed.
|
|
167
|
+
return requested.filter(
|
|
168
|
+
(item) => item.anonymous && indexedCount(item) === topicCount,
|
|
169
|
+
)
|
|
170
|
+
}
|
|
126
171
|
|
|
172
|
+
function indexedCount(item: AbiEvent) {
|
|
173
|
+
return item.inputs?.filter((input) => input.indexed).length ?? 0
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function decodeMatchedEventLog({
|
|
177
|
+
abiItem,
|
|
178
|
+
argTopics,
|
|
179
|
+
data,
|
|
180
|
+
strict,
|
|
181
|
+
}: {
|
|
182
|
+
abiItem: AbiEvent
|
|
183
|
+
argTopics: readonly Hex[]
|
|
184
|
+
data: Hex | undefined
|
|
185
|
+
strict: boolean
|
|
186
|
+
}): DecodeEventLogReturnType {
|
|
127
187
|
const { name, inputs } = abiItem
|
|
128
188
|
const isUnnamed = inputs?.some((x) => !('name' in x && x.name))
|
|
129
189
|
|
|
@@ -216,7 +276,7 @@ export function decodeEventLog<
|
|
|
216
276
|
return {
|
|
217
277
|
eventName: name,
|
|
218
278
|
args: Object.values(args).length > 0 ? args : undefined,
|
|
219
|
-
} as
|
|
279
|
+
} as DecodeEventLogReturnType
|
|
220
280
|
}
|
|
221
281
|
|
|
222
282
|
function decodeTopic({ param, value }: { param: AbiParameter; value: Hex }) {
|
|
@@ -230,3 +290,30 @@ function decodeTopic({ param, value }: { param: AbiParameter; value: Hex }) {
|
|
|
230
290
|
const decodedArg = decodeAbiParameters([param], value) || []
|
|
231
291
|
return decodedArg[0]
|
|
232
292
|
}
|
|
293
|
+
|
|
294
|
+
/** Error type thrown when an anonymous event log matches more than one event. */
|
|
295
|
+
export type AbiEventAmbiguityErrorType = AbiEventAmbiguityError & {
|
|
296
|
+
name: 'AbiEventAmbiguityError'
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Thrown by {@link decodeEventLog} when an anonymous event log fits more than
|
|
300
|
+
* one requested anonymous event with the same number of indexed inputs.
|
|
301
|
+
*/
|
|
302
|
+
export class AbiEventAmbiguityError extends BaseError {
|
|
303
|
+
constructor(eventNames: readonly string[]) {
|
|
304
|
+
// `eventName` cannot choose between overloads that share a name, so those
|
|
305
|
+
// need an ABI narrowed to one event.
|
|
306
|
+
const distinct = new Set(eventNames).size === eventNames.length
|
|
307
|
+
super('Ambiguous anonymous event log.', {
|
|
308
|
+
docsPath,
|
|
309
|
+
metaMessages: [
|
|
310
|
+
`Matched ${eventNames.map((name) => `\`${name}\``).join(', ')}.`,
|
|
311
|
+
'These events take the same number of indexed topics.',
|
|
312
|
+
distinct
|
|
313
|
+
? 'Pass `eventName` to choose one.'
|
|
314
|
+
: 'Pass an `abi` that holds only the event to decode.',
|
|
315
|
+
],
|
|
316
|
+
name: 'AbiEventAmbiguityError',
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
}
|