{"modulePath":"github.com/0xsequence/ethkit","version":"v1.47.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package ethfinalizer\n\nPackage ethfinalizer implements a wallet adapter for guaranteeing transaction inclusion on a specific chain.\n\nThis fixes \"nonce too low\" issues that can happen if reorgs occur or if you trust your node's reported nonces.\n\n## Types\n\n```go\ntype Chain interface {\n\tChainID() *big.Int\n\tIsEIP1559() bool\n\n\tLatestNonce(ctx context.Context, address common.Address) (uint64, error)\n\tPendingNonce(ctx context.Context, address common.Address) (uint64, error)\n\n\tSend(ctx context.Context, transaction *types.Transaction) error\n\n\tGasPrice(ctx context.Context) (*big.Int, error)\n\tBaseFee(ctx context.Context) (*big.Int, error)\n\tPriorityFee(ctx context.Context) (*big.Int, error)\n\n\tSubscribe(ctx context.Context) (\u003c-chan Diff, error)\n}\n```\nChain is a provider for a chain where transactions will be sent.\n\n```go\nfunc NewEthkitChain(options EthkitChainOptions) (Chain, error)\n```\nNewEthkitChain creates a Chain using ethkit components.\n\n```go\ntype Diff struct {\n\tRemoved, Added map[common.Hash]struct{}\n}\n```\n\n```go\ntype EthkitChainOptions struct {\n\tChainID   *big.Int\n\tIsEIP1559 bool\n\n\t// Provider is an ethkit Provider, required.\n\tProvider *ethrpc.Provider\n\t// Monitor is a running ethkit Monitor, required.\n\tMonitor *ethmonitor.Monitor\n\t// GasGauge is a running ethkit GasGauge, required only for non-EIP-1559 chains.\n\tGasGauge *ethgas.GasGauge\n\t// GasGaugeSpeed defaults to GasGaugeSpeedDefault (GasGaugeSpeedFast), unused for EIP-1559 chains.\n\tGasGaugeSpeed GasGaugeSpeed\n\t// Logger is used to log chain behaviour, optional.\n\tLogger *slog.Logger\n\n\tPriorityFee *big.Int\n}\n```\n\n```go\nfunc (o EthkitChainOptions) IsValid() error\n```\n\n```go\ntype Event[T any] struct {\n\t// Removed is the transaction that was reorged, nil if this was a mining event.\n\tRemoved *Transaction[T]\n\t// Added is the transaction that was mined, may be nil if a reorg occurred and the reorged transaction was never replaced.\n\tAdded *Transaction[T]\n}\n```\nEvent describes when a Transaction is mined or reorged.\n\n  - Transaction mined: Removed is nil, Added is not nil.\n  - Transaction reorged: Removed is not nil, Added may or may not be nil.\n\nType parameters:\n\n  - T: transaction metadata type\n\n```go\ntype Finalizer[T any] struct {\n\tFinalizerOptions[T]\n\t// contains filtered or unexported fields\n}\n```\nFinalizer is a wallet adapter for guaranteeing transaction inclusion on a specific chain.\n\nType parameters:\n\n  - T: transaction metadata type\n\n```go\nfunc NewFinalizer[T any](options FinalizerOptions[T]) (*Finalizer[T], error)\n```\nNewFinalizer creates a new Finalizer with FinalizerOptions which must be Run.\n\nType parameters:\n\n  - T: transaction metadata type\n\n```go\nfunc (f *Finalizer[T]) IsRunning() bool\n```\n\n```go\nfunc (f *Finalizer[T]) Run(ctx context.Context) error\n```\n\n```go\nfunc (f *Finalizer[T]) Send(ctx context.Context, transaction *types.Transaction, metadata T) (*types.Transaction, error)\n```\nSend sends an unsigned transaction on chain.\n\nmetadata is optional transaction data that is stored in the mempool and reappears in events. It is not sent on chain. A signed transaction is returned. This may or may not be the final transaction included on chain.\n\n```go\nfunc (f *Finalizer[T]) Subscribe(ctx context.Context) \u003c-chan Event[T]\n```\nSubscribe returns a channel for receiving transaction mining and reorg events.\n\nThe finalizer must be running to receive events.\n\n```go\ntype FinalizerOptions[T any] struct {\n\t// Wallet is the local wallet to manage. Set exactly one of Wallet or Signer.\n\tWallet *ethwallet.Wallet\n\t// Signer signs transactions, including replacements, using the operation context.\n\tSigner Signer\n\t// Chain is the provider for the chain where transactions will be sent, required.\n\t// See NewEthkitChain for an implementation using ethkit components.\n\tChain Chain\n\t// Mempool stores transactions that this finalizer creates, required.\n\t// See NewMemoryMempool for a minimal in-memory implementation.\n\tMempool Mempool[T]\n\t// Logger is used to log finalizer behaviour, optional.\n\tLogger *slog.Logger\n\n\t// PollInterval is the period between chain state checks.\n\t// Required, must be positive.\n\tPollInterval time.Duration\n\t// PollTimeout is the time limit for operations while checking chain state.\n\t// Required, must be positive.\n\tPollTimeout time.Duration\n\t// RetryDelay is the minimum time to wait before retrying a transaction.\n\t// Required, must be positive.\n\tRetryDelay time.Duration\n\n\t// FeeMargin is the percentage added on top of the estimated gas price.\n\tFeeMargin int\n\t// PriceBump is the percentage increase when replacing pending transactions.\n\t// Recommended to be at least 15, 10 is the default chosen by go-ethereum.\n\tPriceBump int\n\n\t// NonceStuckTimeout is the period after which the finalizer is considered stuck on a nonce.\n\tNonceStuckTimeout time.Duration\n\t// TransactionStuckTimeout is the period after which a transaction is considered stuck.\n\tTransactionStuckTimeout time.Duration\n\t// OnStuck is called when the finalizer is stuck.\n\tOnStuck func(first, latest *Status[T])\n\t// OnUnstuck is called when the finalizer is unstuck.\n\tOnUnstuck func()\n\n\t// SubscriptionBuffer is the size of the buffer for transaction events.\n\tSubscriptionBuffer int\n}\n```\nFinalizerOptions defines finalizer options.\n\nType parameters:\n\n  - T: transaction metadata type\n\n```go\nfunc (o FinalizerOptions[T]) IsValid() error\n```\n\n```go\ntype GasGaugeSpeed int\n```\n\n```go\nconst (\n\tGasGaugeSpeedDefault GasGaugeSpeed = iota\n\tGasGaugeSpeedSlow\n\tGasGaugeSpeedStandard\n\tGasGaugeSpeedFast\n\tGasGaugeSpeedInstant\n)\n```\n\n```go\ntype Mempool[T any] interface {\n\t// Nonce is the next available nonce for the wallet on the chain.\n\tNonce(ctx context.Context) (uint64, error)\n\n\t// Commit persists the signed transaction with its metadata in the store.\n\t// The transaction must be persisted with timestamps of the first and latest submissions.\n\t// If the transaction already exists in the mempool, the latest timestamp must be updated.\n\tCommit(ctx context.Context, transaction *types.Transaction, metadata T) error\n\n\t// SetError sets the error for a previously committed transaction.\n\tSetError(ctx context.Context, transaction common.Hash, err error) error\n\n\t// Transactions returns the transactions for the specified hashes which are signed by this specific wallet for this specific chain.\n\tTransactions(ctx context.Context, hashes map[common.Hash]struct{}) (map[common.Hash]*Transaction[T], error)\n\n\t// PriciestTransactions returns, by nonce, the most expensive transactions signed by this specific wallet for this specific chain, with a minimum nonce and a latest timestamp.\n\tPriciestTransactions(ctx context.Context, fromNonce uint64, before time.Time) (map[uint64]*Transaction[T], error)\n\n\t// Status returns the statuses for the first and latest transactions for a given nonce.\n\tStatus(ctx context.Context, nonce uint64) (*Status[T], *Status[T], error)\n}\n```\nMempool is a complete local store of all transactions signed by a specific wallet for a specific chain that have been sent, but not necessarily included on chain.\n\n```go\nfunc NewMemoryMempool[T any]() Mempool[T]\n```\nNewMemoryMempool creates a minimal in-memory Mempool.\n\n```go\ntype Signer interface {\n\tAddress() common.Address\n\tSignTransaction(context.Context, *types.Transaction, *big.Int) (*types.Transaction, error)\n}\n```\nSigner signs transactions without requiring access to private key material. Implementations must respect cancellation and return a transaction signed by Address.\n\n```go\nfunc NewWalletSigner(wallet *ethwallet.Wallet) Signer\n```\nNewWalletSigner adapts a local wallet to Signer. A nil wallet returns a nil Signer.\n\n```go\ntype Status[T any] struct {\n\tTransaction *Transaction[T]\n\t// Time is when the transaction was first committed.\n\tTime time.Time\n\t// Error is the most recent error from sending the transaction on chain.\n\tError error\n}\n```\nStatus is the result of sending a Transaction on chain.\n\nType parameters:\n\n  - T: transaction metadata type\n\n```go\ntype Transaction[T any] struct {\n\t*types.Transaction\n\n\tMetadata T\n}\n```\nTransaction is a transaction with metadata of type T.\n\nType parameters:\n\n  - T: metadata type\n\n","path":"github.com/0xsequence/ethkit/ethfinalizer","name":"ethfinalizer","synopsis":"Package ethfinalizer implements a wallet adapter for guaranteeing transaction inclusion on a specific chain.","isRedistributable":true}
