diff --git a/pkg/mev/pkg.go b/pkg/mev/pkg.go index 0b8cb19..ab33010 100644 --- a/pkg/mev/pkg.go +++ b/pkg/mev/pkg.go @@ -72,6 +72,10 @@ type IBundleSender interface { } type IGasBundleEstimator interface { + // EstimateBundleGas is used to estimate the gas for a bundle of transactions + // Note that this method is expected only works with custom ethereum node which + // supports estimate bundles gas via CallMsgs, + // and using eth_estimateGasBundle method. EstimateBundleGas( ctx context.Context, messages []ethereum.CallMsg, diff --git a/pkg/types/pendingtx.go b/pkg/types/pendingtx.go index 91c1e39..be139c2 100644 --- a/pkg/types/pendingtx.go +++ b/pkg/types/pendingtx.go @@ -2,6 +2,7 @@ package types import ( "math/big" + "strings" "github.com/KyberNetwork/tradinglib/pkg/mev" "github.com/ethereum/go-ethereum/common" @@ -78,3 +79,30 @@ type MinedBlock struct { BlockTime int64 `json:"block_time"` Transactions []Transaction `json:"transactions"` } + +func (m Message) GetAllLogs() []*types.Log { + logs := m.InternalTx.getLogs() + return logs +} + +func (c CallFrame) getLogs() []*types.Log { + results := c.Logs + for index := range c.Calls { + results = append(results, c.Calls[index].getLogs()...) + } + return results +} + +// GetRelatedPools returns all pools related to the log +// A pool might appear from log.Address, or log.Topics. +// Currently, support univ2, balancer poolType. +// Others should be dig and update this function if needed. +func GetRelatedPools(log *types.Log) []string { + pools := make([]string, 0, len(log.Topics)+1) + for _, topic := range log.Topics { + pools = append(pools, strings.ToLower(topic.Hex())) + } + pools = append(pools, strings.ToLower(log.Address.Hex())) + + return pools +}