Documentation
¶
Overview ¶
Package onchain executes verified, journaled EVM transaction templates.
Index ¶
- Constants
- Variables
- func Allowed(id uint64) bool
- func BatchAllowed(ctx context.Context, rpc codeReader, chain uint64, agent string) (bool, error)
- func BatchMatches(in journal.OnchainIntent, tx *ChainTx) bool
- func Hex(v *big.Int) string
- func IsBatchNotMined(err error) bool
- func LocateBatch(ctx context.Context, in journal.OnchainIntent, b journal.Batch, ...) (string, error)
- func Quantity(s string) (*big.Int, error)
- func RPCURL(getenv func(string) string, chain uint64) (string, error)
- func ReceiptWait(chain uint64, getenv func(string) string) time.Duration
- func ValidAddress(a string) bool
- type BatchLocator
- type BatchSender
- type ChainTx
- type Executor
- func (x Executor) Execute(ctx context.Context, in journal.OnchainIntent) error
- func (x Executor) ExecuteBatch(ctx context.Context, in journal.OnchainIntent, sender BatchSender, ...) error
- func (x Executor) ExecuteSequential(ctx context.Context, in journal.OnchainIntent, start int) error
- func (x Executor) Wait(ctx context.Context, chain uint64, hash string) (bool, error)
- func (x Executor) WaitBatch(ctx context.Context, in journal.OnchainIntent, b journal.Batch, ...) (string, error)
- type HTTPRPC
- func (r HTTPRPC) Balance(ctx context.Context, c uint64, a string) (*big.Int, error)
- func (r HTTPRPC) BlockNumber(ctx context.Context, c uint64) (uint64, error)
- func (r HTTPRPC) Call(ctx context.Context, c uint64, to, data string) (*big.Int, error)
- func (r HTTPRPC) Code(ctx context.Context, c uint64, address string) (string, error)
- func (r HTTPRPC) Estimate(ctx context.Context, c uint64, from string, ...) (*big.Int, error)
- func (r HTTPRPC) FindNonceTx(ctx context.Context, c uint64, sender string, nonce, fromBlock uint64) (*ChainTx, error)
- func (r HTTPRPC) FullReceipt(ctx context.Context, c uint64, hash string) (*TxReceipt, error)
- func (r HTTPRPC) GasPrice(ctx context.Context, c uint64) (*big.Int, error)
- func (r HTTPRPC) HasBaseFee(ctx context.Context, c uint64) (bool, error)
- func (r HTTPRPC) HasCode(ctx context.Context, c uint64, address string) (bool, error)
- func (r HTTPRPC) Nonces(ctx context.Context, c uint64, sender string) (uint64, uint64, error)
- func (r HTTPRPC) Receipt(ctx context.Context, c uint64, hash string) (*bool, error)
- func (r HTTPRPC) TokenBalances(ctx context.Context, chain uint64, wallet string, tokens []string) ([]*big.Int, error)
- func (r HTTPRPC) TokenDetails(ctx context.Context, chain uint64, wallet string, tokens []string) ([]TokenMetadata, error)
- func (r HTTPRPC) VerifyBatchTransaction(ctx context.Context, in journal.OnchainIntent, b journal.Batch, hash string) error
- func (r HTTPRPC) VerifyTransaction(ctx context.Context, chain uint64, hash, sender string, ...) error
- type Journal
- type Log
- type RPC
- type Sender
- type SwapFill
- type TokenMetadata
- type TxReceipt
Constants ¶
const PrivyKernelImplementation = "0xd6CEDDe84be40893d153Be9d467CD6aD37875b28"
Privy's wallet_sendCalls delegates an EOA to this Kernel implementation. Kernel implementation used for Privy's EIP-7702 wallet delegation.
Variables ¶
var ErrBalance = errors.New("INSUFFICIENT_BALANCE")
var ErrGas = errors.New("INSUFFICIENT_GAS")
var ErrNoFill = errors.New("receipts show no fill to the recipient")
ErrNoFill reports receipts that do not show what the recipient received.
var ErrNoRPC = errors.New("no RPC endpoint for chain")
ErrNoRPC reports a chain with no configured endpoint.
var ErrNonceBeforeBlock = errors.New("nonce used before the batch was submitted")
ErrNonceBeforeBlock reports that a nonce was consumed before the batch's recorded start block, so that transaction cannot be the batch.
var ErrNotBroadcast = errors.New("not broadcast")
ErrNotBroadcast wraps failures that provably happened before the current step was handed to Privy. Combined with the journal state it tells callers whether nothing (state "failed", no hashes) or only earlier, confirmed steps reached the chain.
var ErrReceiptUpstream = errors.New("receipt lookup failed after broadcast; run status to retry")
var ErrReverted = errors.New("transaction reverted")
var ErrUnknown = errors.New("OUTCOME_UNKNOWN: reconcile transaction receipt; never resubmit")
Functions ¶
func Allowed ¶
Allowed reports whether id is a plausible EVM chain ID. Real support is decided by the backend (active swap markets) and by RPCURL; every RPC response is also checked against eth_chainId.
func BatchAllowed ¶
BatchAllowed fails closed on RPC errors and checks the actual delegate code, including an already-delegated agent's target rather than assuming Kernel.
func BatchMatches ¶
func BatchMatches(in journal.OnchainIntent, tx *ChainTx) bool
BatchMatches reports whether an on-chain transaction is exactly the agent's batch: a zero-value self-call to execute(batch mode, abi.encode(Execution[])) whose decoded calls equal the journaled templates in order (target, value, calldata) with nothing extra.
func IsBatchNotMined ¶
IsBatchNotMined reports a lookup that found no matching mined batch yet.
func LocateBatch ¶
func LocateBatch(ctx context.Context, in journal.OnchainIntent, b journal.Batch, locator BatchLocator) (string, error)
LocateBatch returns the hash of the mined agent transaction carrying the intent's batch, searching from the reserved nonce. errBatchNotMined means no matching transaction is mined yet; any other error is a lookup failure or a mismatch, both of which must leave the intent unresolved.
func RPCURL ¶
RPCURL requires OKU_RPC_URL_<CHAINID>. The chain-config networks package does not publish RPC endpoints.
func ReceiptWait ¶
ReceiptWait bounds how long submit waits for a receipt to reach the chain's confirmation depth: inclusion plus depth blocks with a 2x margin, at least two minutes.
func ValidAddress ¶
Types ¶
type BatchLocator ¶
type BatchLocator interface {
Nonces(ctx context.Context, chain uint64, sender string) (latest, pending uint64, err error)
BlockNumber(ctx context.Context, chain uint64) (uint64, error)
FindNonceTx(ctx context.Context, chain uint64, sender string, nonce, fromBlock uint64) (*ChainTx, error)
}
BatchLocator finds the agent's transaction at a nonce on chain.
type BatchSender ¶
type BatchSender interface {
SendCalls(context.Context, string, uint64, []privy.Call) (string, error)
}
BatchSender submits an atomic wallet_sendCalls batch and returns Privy's transaction ID.
type Executor ¶
type Executor struct {
// Getenv reads confirmation overrides when sizing receipt waits.
Getenv func(string) string
RPC RPC
Sender Sender
Journal Journal
WalletID string
Poll time.Duration
}
func (Executor) Execute ¶
Execute sends ordered already-verified templates, never retrying an ambiguous broadcast. Each hash is durably appended before the first receipt read. Every failure before a step is handed to Privy closes the intent as failed and is wrapped in ErrNotBroadcast; after a handoff, ambiguity stays unknown.
func (Executor) ExecuteBatch ¶
func (x Executor) ExecuteBatch(ctx context.Context, in journal.OnchainIntent, sender BatchSender, locator BatchLocator) error
ExecuteBatch sends every template as one atomic wallet_sendCalls batch (EIP-7702). Before the handoff it records the agent nonce and block, so the batch can be found on chain later; Privy returns no chain hash. Failures before the handoff close the intent (ErrNotBroadcast); afterwards the batch is located by nonce, its calldata is checked to contain every journaled call, and its receipt decides confirmed or failed.
func (Executor) ExecuteSequential ¶
ExecuteSequential resumes only at a durably recorded boundary. A sending record with no confirmed cursor must not be replayed after a crash.
type HTTPRPC ¶
HTTPRPC uses public chain endpoints unless OKU_RPC_URL_<CHAINID> overrides.
func (HTTPRPC) BlockNumber ¶
BlockNumber returns the latest block number.
func (HTTPRPC) FindNonceTx ¶
func (r HTTPRPC) FindNonceTx(ctx context.Context, c uint64, sender string, nonce, fromBlock uint64) (*ChainTx, error)
FindNonceTx returns sender's mined transaction with the given nonce, found by binary-searching the block where the account nonce passed it (from fromBlock). It returns nil when that nonce is not mined yet. Requires an RPC that serves historical account state for the searched range.
func (HTTPRPC) FullReceipt ¶
FullReceipt returns the receipt of hash with its logs, nil if not mined.
func (HTTPRPC) HasBaseFee ¶
func (HTTPRPC) TokenBalances ¶
func (HTTPRPC) TokenDetails ¶
func (HTTPRPC) VerifyBatchTransaction ¶
func (r HTTPRPC) VerifyBatchTransaction(ctx context.Context, in journal.OnchainIntent, b journal.Batch, hash string) error
VerifyBatchTransaction checks a user-supplied hash is the intent's batch.
func (HTTPRPC) VerifyTransaction ¶
func (r HTTPRPC) VerifyTransaction(ctx context.Context, chain uint64, hash, sender string, t journal.OnchainTemplate) error
VerifyTransaction rejects hashes that do not identify the exact journaled call.
type Log ¶
type Log struct {
Address string `json:"address"`
Topics []string `json:"topics"`
Data string `json:"data"`
}
Log is one receipt event.
type RPC ¶
type RPC interface {
Balance(context.Context, uint64, string) (*big.Int, error)
Call(context.Context, uint64, string, string) (*big.Int, error)
GasPrice(context.Context, uint64) (*big.Int, error)
Receipt(context.Context, uint64, string) (*bool, error)
}
RPC is the chain-read boundary. A missing receipt returns nil without error.
type SwapFill ¶
type SwapFill struct {
Received *big.Int
Gas *big.Int
// Source is transfer_logs (ERC-20 Transfer events to the recipient) or
// router_event (OkuRouter's amountOut, used for native output).
Source string
}
SwapFill is what a swap's receipts show the recipient received.
func MeasureSwapFill ¶
func MeasureSwapFill(receipts []*TxReceipt, router, outToken, recipient string, native bool) (*SwapFill, error)
MeasureSwapFill reads the amount of outToken ("native" or an address) that recipient received from every successful receipt of a swap, and the total gas paid. router is the chain's OkuRouter.
type TokenMetadata ¶
type TxReceipt ¶
type TxReceipt struct {
TransactionHash string `json:"transactionHash"`
Status string `json:"status"`
GasUsed string `json:"gasUsed"`
EffectiveGasPrice string `json:"effectiveGasPrice"`
// L1Fee is the separately charged data fee of OP Stack chains.
L1Fee string `json:"l1Fee"`
Logs []Log `json:"logs"`
}
TxReceipt is the subset of a transaction receipt used to measure a fill.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package onchaintest provides test helpers for onchain batch fixtures.
|
Package onchaintest provides test helpers for onchain batch fixtures. |