Documentation
¶
Index ¶
- Variables
- func BuildAggregateCalldataCustom(calls []MCCall) []byte
- func BuildTryAggregateCalldataCustom(calls []MCCall) []byte
- func CallRaw(ctx context.Context, c *Client, method string, params ...any) ([]byte, error)
- func RPC[T any](ctx context.Context, c *Client, method string, params ...any) (T, error)
- func RPCWithRetry[T any](ctx context.Context, c *Client, method string, params ...any) (T, error)
- func Selector(sig string) []byte
- func Subscribe[T any](ctx context.Context, c *Client, topic string, params ...any) (<-chan *T, error)
- type AccessList
- type AccessTuple
- type BatchResult
- type Block
- type BlockHeader
- type Call
- type CallMsg
- type Client
- func (c *Client) Aggregate3(ctx context.Context, calls []Call, maxBatch int) ([]BatchResult, error)
- func (c *Client) BlockByHash(ctx context.Context, hash string) (*Block, error)
- func (c *Client) BlockByNumber(ctx context.Context, number uint64) (*Block, error)
- func (c *Client) BlockNumber(ctx context.Context) (uint64, error)
- func (c *Client) CallContract(ctx context.Context, msg *CallMsg, blockNumber uint64) ([]byte, error)
- func (c *Client) ChainID(ctx context.Context) (uint64, error)
- func (c *Client) Close() error
- func (c *Client) EstimateGas(ctx context.Context, msg *CallMsg) (uint64, error)
- func (c *Client) GasPrice(ctx context.Context) (uint64, error)
- func (c *Client) GetGasPrice() uint64
- func (c *Client) GetLogs(ctx context.Context, filter *FilterQuery) ([]Log, error)
- func (c *Client) GetNextNonce(ctx context.Context) (uint64, error)
- func (c *Client) GetTransactionCount(ctx context.Context, addr string, tag string) (uint64, error)
- func (c *Client) SendRawTransaction(ctx context.Context, rawTxHex string) (string, error)
- func (c *Client) SignDynamicFeeTx(tx *DynamicFeeTx) ([]byte, error)
- func (c *Client) SignTransaction(tx *LegacyTx) ([]byte, error)
- func (c *Client) Stats() (requests, errors uint64)
- func (c *Client) SubscribeNewHeads(ctx context.Context) (<-chan *BlockHeader, error)
- func (c *Client) TransactionReceipt(ctx context.Context, txHash string) (*Receipt, error)
- func (c *Client) TryAggregate(ctx context.Context, calls []Call, maxBatch int) ([]BatchResult, error)
- type ClientOption
- func WithGasCalculator(g *GasCalculator) ClientOption
- func WithGasMultiplier(multiplier float64) ClientOption
- func WithMaxConns(n int) ClientOption
- func WithMulticallAddress(addr string) ClientOption
- func WithMulticallMode(mode MulticallMode) ClientOption
- func WithNonceManager(n *NonceManager) ClientOption
- func WithPrivateKey(privateKeyHex string) ClientOption
- func WithWallet(w *Wallet) ClientOption
- type DynamicFeeTx
- type EventDecoder
- type EventParam
- type FilterQuery
- type GasCalculator
- func (gc *GasCalculator) CalculateNetProfit(grossProfitCents, gasLimit uint64, nativePriceCents uint64) int64
- func (gc *GasCalculator) EstimateGasCost(gasLimit uint64, nativePriceCents uint64) GasEstimate
- func (gc *GasCalculator) GetCurrentPrice() uint64
- func (gc *GasCalculator) GetRecommendedGasPrice() uint64
- func (gc *GasCalculator) IsProfitable(profitCents uint64, gasLimit uint64, nativePriceCents uint64) bool
- func (gc *GasCalculator) UpdatePrice(priceWei uint64)
- type GasEstimate
- type GasSample
- type LegacyTx
- type Log
- type MCCall
- type MulticallMode
- type NonceManager
- type PriceOracle
- type RPCError
- type Receipt
- type Result
- type Wallet
Constants ¶
This section is empty.
Variables ¶
var BSCStablecoins = map[string]int64{
"0x55d398326f99059fF775485246999027B3197955": 1_000_000,
"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d": 1_000_000,
"0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56": 1_000_000,
"0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3": 1_000_000,
"0x14016E85a25aeb13065688cAFB43044C2ef86784": 1_000_000,
"0x049d68029688eAbF473097a2fC38ef61633A3C7A": 1_000_000,
"0x5B6DcF557E2aBE2323c48445E8CC948910d8c2c9": 1_000_000,
}
Functions ¶
func BuildAggregateCalldataCustom ¶
Some BSC RPC nodes use non-standard ABI where element offsets = N*32 (sequential) instead of standard ABI relative offsets.
func RPCWithRetry ¶
RPCWithRetry executes a JSON-RPC call with automatic retry logic for transient errors.
Types ¶
type AccessList ¶
type AccessList []AccessTuple
type AccessTuple ¶
AccessTuple represents an EIP-2930 access list entry.
type BatchResult ¶
type BlockHeader ¶
type Call ¶
type Call struct {
Target fastabi.Address
Signature string
InputTypes []fastabi.ParamType
Inputs []any
OutputTypes []fastabi.ParamType
AllowFailure bool
}
Call defines a multicall request with ABI-typed parameters. Leave InputTypes/Inputs empty for functions with no arguments. Leave OutputTypes empty if you don't need decoding — raw bytes will be in ReturnData.
type Client ¶
type Client struct {
Wallet *Wallet
Nonce *NonceManager
Gas *GasCalculator
Oracle *PriceOracle
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(rpcURL, wsURL string, opts ...ClientOption) *Client
func (*Client) Aggregate3 ¶
Aggregate3 executes a batch of typed multicall requests. Calls are automatically split into batches of maxBatch size and run in parallel. If maxBatch <= 0, defaults to 100.
func (*Client) BlockByHash ¶
func (*Client) BlockByNumber ¶
func (*Client) CallContract ¶
func (*Client) EstimateGas ¶
func (*Client) GetGasPrice ¶
func (*Client) GetTransactionCount ¶
func (*Client) SendRawTransaction ¶
func (*Client) SignDynamicFeeTx ¶
func (c *Client) SignDynamicFeeTx(tx *DynamicFeeTx) ([]byte, error)
func (*Client) SubscribeNewHeads ¶
func (c *Client) SubscribeNewHeads(ctx context.Context) (<-chan *BlockHeader, error)
func (*Client) TransactionReceipt ¶
func (*Client) TryAggregate ¶
func (c *Client) TryAggregate(ctx context.Context, calls []Call, maxBatch int) ([]BatchResult, error)
TryAggregate executes a batch of typed multicall requests using tryAggregate. Unlike Aggregate3, individual call failures do not revert the entire batch. Calls are automatically split into batches of maxBatch size and run in parallel. If maxBatch <= 0, defaults to 100.
type ClientOption ¶
type ClientOption func(*Client)
func WithGasCalculator ¶
func WithGasCalculator(g *GasCalculator) ClientOption
func WithGasMultiplier ¶
func WithGasMultiplier(multiplier float64) ClientOption
func WithMaxConns ¶
func WithMaxConns(n int) ClientOption
func WithMulticallAddress ¶
func WithMulticallAddress(addr string) ClientOption
func WithMulticallMode ¶
func WithMulticallMode(mode MulticallMode) ClientOption
func WithNonceManager ¶
func WithNonceManager(n *NonceManager) ClientOption
func WithPrivateKey ¶
func WithPrivateKey(privateKeyHex string) ClientOption
func WithWallet ¶
func WithWallet(w *Wallet) ClientOption
type DynamicFeeTx ¶
type DynamicFeeTx struct {
ChainID uint64
Nonce uint64
MaxPriorityFeePerGas *big.Int
MaxFeePerGas *big.Int
Gas uint64
To *[20]byte
Value *big.Int
Data []byte
AccessList AccessList
V *big.Int
R *big.Int
S *big.Int
}
DynamicFeeTx represents an EIP-1559 dynamic fee transaction.
func (*DynamicFeeTx) Encode ¶
func (tx *DynamicFeeTx) Encode() []byte
func (*DynamicFeeTx) SigningHash ¶
func (tx *DynamicFeeTx) SigningHash() []byte
SigningHash returns the keccak256 of the EIP-1559 signing payload.
type EventDecoder ¶
type EventDecoder struct {
Signature string
Topic0 [32]byte
Inputs []EventParam
}
func ParseEvent ¶
func ParseEvent(sig string) (*EventDecoder, error)
type FilterQuery ¶
type GasCalculator ¶
type GasCalculator struct {
// contains filtered or unexported fields
}
GasCalculator computes gas costs for EVM transactions. Uses legacy gas pricing (not EIP-1559), suitable for BSC and similar chains.
func NewGasCalculator ¶
func NewGasCalculator(multiplier float64) *GasCalculator
func (*GasCalculator) CalculateNetProfit ¶
func (gc *GasCalculator) CalculateNetProfit(grossProfitCents, gasLimit uint64, nativePriceCents uint64) int64
CalculateNetProfit calculates profit minus gas costs (8x base price for worst-case).
func (*GasCalculator) EstimateGasCost ¶
func (gc *GasCalculator) EstimateGasCost(gasLimit uint64, nativePriceCents uint64) GasEstimate
func (*GasCalculator) GetCurrentPrice ¶
func (gc *GasCalculator) GetCurrentPrice() uint64
func (*GasCalculator) GetRecommendedGasPrice ¶
func (gc *GasCalculator) GetRecommendedGasPrice() uint64
GetRecommendedGasPrice returns a gas price for fast inclusion.
func (*GasCalculator) IsProfitable ¶
func (gc *GasCalculator) IsProfitable(profitCents uint64, gasLimit uint64, nativePriceCents uint64) bool
IsProfitable checks if profit after gas costs is positive.
func (*GasCalculator) UpdatePrice ¶
func (gc *GasCalculator) UpdatePrice(priceWei uint64)
type GasEstimate ¶
type LegacyTx ¶
type LegacyTx struct {
Nonce uint64
GasPrice *big.Int
Gas uint64
To *[20]byte
Value *big.Int
Data []byte
V *big.Int
R *big.Int
S *big.Int
ChainID uint64
}
LegacyTx represents an Ethereum legacy transaction with EIP-155 replay protection.
func (*LegacyTx) SigningHash ¶
SigningHash returns the keccak256 of the RLP-encoded signing payload (without V,R,S but with chainID for EIP-155).
type Log ¶
type Log struct {
Address string `json:"address"`
Topics []string `json:"topics"`
Data string `json:"data"`
BlockNumber string `json:"blockNumber"`
TransactionHash string `json:"transactionHash"`
TransactionIndex string `json:"transactionIndex"`
BlockHash string `json:"blockHash"`
LogIndex string `json:"logIndex"`
Removed bool `json:"removed"`
}
type MulticallMode ¶
type MulticallMode int
MulticallMode selects the ABI encoding strategy for multicall calls.
const ( // MulticallCustom uses custom ABI encoding with sequential element offsets. // Required for some BSC RPC nodes with non-standard ABI interpretation. MulticallCustom MulticallMode = iota // MulticallStandard uses standard ABI encoding via fastabi. MulticallStandard )
type NonceManager ¶
type NonceManager struct {
// contains filtered or unexported fields
}
NonceManager tracks the current nonce for an address. Uses optimistic local increment — fetches from RPC only on first use or after reset.
func NewNonceManager ¶
func NewNonceManager() *NonceManager
func (*NonceManager) Reset ¶
func (nm *NonceManager) Reset()
Reset forces a re-fetch from RPC on the next call. Call this after a transaction fails with nonce error.
type PriceOracle ¶
type PriceOracle struct {
// contains filtered or unexported fields
}
PriceOracle fetches token prices in USD from on-chain sources. Uses WBNB/USDT pool for BNB price, and stablecoin pegs for stable tokens.
func NewPriceOracle ¶
func NewPriceOracle(client *Client) *PriceOracle
func (*PriceOracle) IsStablecoin ¶
func (o *PriceOracle) IsStablecoin(addr fastabi.Address) bool
func (*PriceOracle) LastUpdate ¶
func (o *PriceOracle) LastUpdate() time.Time
func (*PriceOracle) PriceMicro ¶
func (o *PriceOracle) PriceMicro() int64
func (*PriceOracle) Start ¶
func (o *PriceOracle) Start(ctx context.Context)
func (*PriceOracle) TokenPriceMicro ¶
func (o *PriceOracle) TokenPriceMicro(addr fastabi.Address) int64
type RPCError ¶
type Receipt ¶
type Receipt struct {
TransactionHash string `json:"transactionHash"`
TransactionIndex string `json:"transactionIndex"`
BlockHash string `json:"blockHash"`
BlockNumber string `json:"blockNumber"`
From string `json:"from"`
To string `json:"to"`
GasUsed string `json:"gasUsed"`
CumulativeGasUsed string `json:"cumulativeGasUsed"`
Status string `json:"status"`
Logs []Log `json:"logs"`
}
type Wallet ¶
func NewWalletFromPrivateKey ¶
func (*Wallet) GetAddress ¶
func (*Wallet) PrivateKeyHex ¶
func (*Wallet) SignDynamicFeeTx ¶
func (w *Wallet) SignDynamicFeeTx(tx *DynamicFeeTx) ([]byte, error)
SignDynamicFeeTx signs an EIP-1559 dynamic fee transaction.