Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add comment and getAllLogs #36

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/mev/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions pkg/types/pendingtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"math/big"
"strings"

"github.com/KyberNetwork/tradinglib/pkg/mev"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -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
}
Loading