Skip to content

Commit

Permalink
(partially automated) cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benleb committed Jun 28, 2023
1 parent d4cd74c commit ff99a83
Show file tree
Hide file tree
Showing 14 changed files with 486 additions and 127 deletions.
436 changes: 436 additions & 0 deletions go.sum

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions internal/collections/collectiondb.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (cs *CollectionDB) Addresses() []common.Address {
return addresses
}

// OpenseaSlugs returns a slice of slugs for collections with enabled listings.
func (cs *CollectionDB) OpenseaSlugsAndAddresses() map[string]common.Address {
// OpenSeaSlugsAndAddresses returns a slice-to-address map of collections with enabled listings.
func (cs *CollectionDB) OpenSeaSlugsAndAddresses() map[string]common.Address {
// slugs := make([]string, 0)
slugAddresses := make(map[string]common.Address)

Expand All @@ -45,7 +45,7 @@ func (cs *CollectionDB) OpenseaSlugsAndAddresses() map[string]common.Address {
return slugAddresses
}

// OpenseaSlugs returns a slice of slugs for collections with enabled listings.
// GetCollectionForSlug returns a collections for the given slug.
func (cs *CollectionDB) GetCollectionForSlug(slug string) *Collection {
for _, c := range cs.Collections {
if c.OpenseaSlug == slug {
Expand All @@ -56,7 +56,7 @@ func (cs *CollectionDB) GetCollectionForSlug(slug string) *Collection {
return nil
}

// OpenseaSlugs returns a slice of slugs for collections with enabled listings.
// OpenseaAddressToSlug returns a collectionAddressto-slug map of collections with enabled listings.
func (cs *CollectionDB) OpenseaAddressToSlug() map[common.Address]string {
// slugs := make([]string, 0)
slugAddresses := make(map[common.Address]string)
Expand All @@ -74,7 +74,7 @@ func (cs *CollectionDB) OpenseaAddressToSlug() map[common.Address]string {
func (cs *CollectionDB) OpenseaSlugs() []string {
slugs := make([]string, 0)

for s := range cs.OpenseaSlugsAndAddresses() {
for s := range cs.OpenSeaSlugsAndAddresses() {
slugs = append(slugs, s)
}

Expand All @@ -84,7 +84,7 @@ func (cs *CollectionDB) OpenseaSlugs() []string {
func (cs *CollectionDB) OpenseaSlugAddresses() []common.Address {
addresses := make([]common.Address, 0)

for _, a := range cs.OpenseaSlugsAndAddresses() {
for _, a := range cs.OpenSeaSlugsAndAddresses() {
addresses = append(addresses, a)
}

Expand Down
36 changes: 4 additions & 32 deletions internal/const.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package internal

import (
"bufio"
"os"
"time"

"github.com/charmbracelet/log"
"github.com/ethereum/go-ethereum/common"
"github.com/spf13/viper"
)

const (
Expand All @@ -31,6 +29,10 @@ var (
ENSContractAddress = common.HexToAddress("0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85")
ENSNameWrapperContractAddress = common.HexToAddress("0xd4416b13d2b3a9abae7acd5d6c2bbdbe25686401")

// manifold.
ManifoldERC721CreatorCore = common.HexToAddress("0x5133522ea5A0494EcB83F26311A095DDD7a9D4b6")
ManifoldERC1155CreatorCore = common.HexToAddress("0xE9FF7CA11280553Af56d04Ecb8Be6B8c4468DCB2")

// loan stuff.
NFTfiContractAddress = common.HexToAddress("0x5660E206496808F7b5cDB8C56A696a96AE5E9b23")
NFTLoanTicketV2ContractAddress = common.HexToAddress("0x0E258c84Df0f8728ae4A6426EA5FD163Eb6b9D1B")
Expand Down Expand Up @@ -63,36 +65,6 @@ var (
ReportCaller: false,
ReportTimestamp: false,
})

fileLogger = map[string]*log.Logger{}
)

// LoFi is the logger used to log to the log file with caller and timestamp reporting.
func LoFi(filePath string) *log.Logger {
if filePath == "" {
filePath = viper.GetString("log.log_file")
}

if loFi, ok := fileLogger[filePath]; ok {
return loFi
}

f, err := os.Create(filePath)
if err != nil {
BaseLogger.Error(err)
}

w := bufio.NewWriter(f)

loFi := log.NewWithOptions(w, log.Options{
TimeFormat: time.RFC3339,
ReportCaller: true,
ReportTimestamp: true,
})

// defer f.Close()

fileLogger[filePath] = loFi

return loFi
}
14 changes: 7 additions & 7 deletions internal/degendb/degendata/degendata.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func LoadOpenseaRanks(gb *gloomberg.Gloomberg) error {
slug := strings.TrimSuffix(rFile.Name(), "_opensea.json")
filePath := path.Join(ddPathRanks, rFile.Name())

address, ok := gb.CollectionDB.OpenseaSlugsAndAddresses()[slug]
address, ok := gb.CollectionDB.OpenSeaSlugsAndAddresses()[slug]
if !ok {
if addr, err := gb.Rueidi.GetAddressForOSSlug(context.Background(), slug); err == nil && addr != "" {
address = common.HexToAddress(addr)
Expand Down Expand Up @@ -82,14 +82,14 @@ func LoadOpenseaRanks(gb *gloomberg.Gloomberg) error {

continue
}
defer ranksFile.Close()

ranksBytes, err := io.ReadAll(ranksFile)
if err != nil {
log.Errorf("failed to read content from file: %s", err)

continue
}
ranksFile.Close()

// parse json to structs
err = json.Unmarshal(ranksBytes, &ranksOpensea)
Expand All @@ -100,17 +100,17 @@ func LoadOpenseaRanks(gb *gloomberg.Gloomberg) error {
}

// validate
for token_id, rank := range ranksOpensea {
for tokenId, rank := range ranksOpensea {
if rank.Rank <= 0 {
gbl.Log.Debugf("%s | rank is <=0 for %s", style.AlmostWhiteStyle.Render(slug), style.AlmostWhiteStyle.Render(fmt.Sprint(token_id)))
gb.PrDModf("ddb", "%s | rank is <=0 for %s", style.AlmostWhiteStyle.Render(slug), style.AlmostWhiteStyle.Render(fmt.Sprint(token_id)))
gbl.Log.Debugf("%s | rank is <=0 for %s", style.AlmostWhiteStyle.Render(slug), style.AlmostWhiteStyle.Render(fmt.Sprint(tokenId)))
gb.PrDModf("ddb", "%s | rank is <=0 for %s", style.AlmostWhiteStyle.Render(slug), style.AlmostWhiteStyle.Render(fmt.Sprint(tokenId)))

continue
}

if rank.Score <= 0 {
gbl.Log.Debugf("%s | score is <=0 for %s", style.AlmostWhiteStyle.Render(slug), style.AlmostWhiteStyle.Render(fmt.Sprint(token_id)))
gb.PrDModf("ddb", "%s | score is <=0 for %s", style.AlmostWhiteStyle.Render(slug), style.AlmostWhiteStyle.Render(fmt.Sprint(token_id)))
gbl.Log.Debugf("%s | score is <=0 for %s", style.AlmostWhiteStyle.Render(slug), style.AlmostWhiteStyle.Render(fmt.Sprint(tokenId)))
gb.PrDModf("ddb", "%s | score is <=0 for %s", style.AlmostWhiteStyle.Render(slug), style.AlmostWhiteStyle.Render(fmt.Sprint(tokenId)))

continue
}
Expand Down
15 changes: 7 additions & 8 deletions internal/nemo/gloomberg/marmot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import (
"github.com/benleb/gloomberg/internal/gbl"
)

// marmot is a simple task runner/scheduler.
//
// example usage
//
// gb.CreatePeriodicTask("testing", 5*time.Second, func(gb *gloomberg.Gloomberg) {
// log.Printf("testing tasks lol! %+v", len(gb.Ranks))
// })
//
// gb.CreateScheduledTask("testing", time.Now().Add(17*time.Second), func(gb *gloomberg.Gloomberg) {
// log.Printf("testing scheduled tasks lol! %+v", len(gb.Ranks))
// })
// gb.CreatePeriodicTask("testing", 5*time.Second, func(gb *gloomberg.Gloomberg) {
// log.Printf("testing tasks lol! %+v", len(gb.Ranks))
// })
//
// gb.CreateScheduledTask("testing", time.Now().Add(17*time.Second), func(gb *gloomberg.Gloomberg) {
// log.Printf("testing scheduled tasks lol! %+v", len(gb.Ranks))
// })

// marmot is a simple task runner/scheduler.
type marmot struct {
gb *Gloomberg

Expand Down
2 changes: 1 addition & 1 deletion internal/nemo/gloomberg/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s *Stats) UpdateBalances() (*wallet.Wallets, error) {
balanceTotalWei = big.NewInt(0).Add(balanceTotalWei, balance.BalanceBlurPool)
}

gbl.Log.Debugf("%s: %6.3fΞ total || %6.3f ETH | %6.3f WETH | %6.3f BlurPool", balanceTotalWei, balance.Account, utils.WeiToEther(balance.BalanceETH), utils.WeiToEther(balance.BalanceWETH), utils.WeiToEther(balance.BalanceBlurPool))
gbl.Log.Debugf("%s: %6.3fΞ total || %6.3f ETH | %6.3f WETH | %6.3f BlurPool", balance.Account, balanceTotalWei, utils.WeiToEther(balance.BalanceETH), utils.WeiToEther(balance.BalanceWETH), utils.WeiToEther(balance.BalanceBlurPool))

(*s.wallets)[walletAddress].BalanceBefore = (*s.wallets)[walletAddress].Balance
(*s.wallets)[walletAddress].Balance = balanceTotalWei
Expand Down
8 changes: 4 additions & 4 deletions internal/nemo/osmodels/osmodels.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
type EventType string

const (
ItemListed EventType = "item_listed"
ItemSold EventType = "item_sold"
ItemReceivedBid EventType = "item_received_bid"
ItemReceivedOffer EventType = "item_received_offer"
ItemListed EventType = "item_listed"
ItemSold EventType = "item_sold"
ItemReceivedBid EventType = "item_received_bid"
// ItemReceivedOffer EventType = "item_received_offer".
ItemMetadataUpdated EventType = "item_metadata_updated"

CollectionOffer EventType = "collection_offer"
Expand Down
22 changes: 12 additions & 10 deletions internal/nemo/provider/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ func (pp *Pool) ReconnectProviders() {
// store the current queueLogs channel
queueLogs := pp.queueLogs

// reconnect to the providers
if pool, err := FromConfig(providerConfig); err != nil {
gbl.Log.Fatal("❌ running provider failed, exiting")
} else if pool != nil {
pp = pool
}
gbl.Log.Infof("🔌 trying to re-connect: %+v", providerConfig)

//// reconnect to the providers
// if pool, err := FromConfig(providerConfig); err != nil {
// gbl.Log.Fatal("❌ running provider failed, exiting")
// } else if pool != nil {
// pp = pool
//}

// restore the queueLogs channel
pp.queueLogs = queueLogs
Expand Down Expand Up @@ -245,7 +247,7 @@ func (pp *Pool) Subscribe(queueLogs chan types.Log) (uint64, error) {
for _, provider := range availableProvider {
// subscribe to all logs with "Tranfer" or "TransferSingle" as first topic
if _, err := provider.subscribeToAllTransfers(pp.queueLogs); err != nil {
gbl.Log.Warnf("subscribe to topic TransferSingle via node %d failed: %s", provider.Name, err)
gbl.Log.Warnf("subscribe to topic TransferSingle via node %s failed: %s", provider.Name, err)
} else {
subscribedTo++
gbl.Log.Infof("✍️ subscribed to all transfer topics via node %s", style.Bold(provider.Name))
Expand Down Expand Up @@ -278,7 +280,7 @@ func (pp *Pool) SubscribeToEverything(queueLogs chan types.Log) (uint64, error)
for _, provider := range availableProvider {
// subscribe to all logs with "Tranfer" or "TransferSingle" as first topic
if _, err := provider.subscribeTo(pp.queueLogs, [][]common.Hash{}, []common.Address{}); err != nil {
gbl.Log.Warnf("subscribe to everything via node %d failed: %s", provider.Name, err)
gbl.Log.Warnf("subscribe to everything via node %s failed: %s", provider.Name, err)
} else {
subscribedTo++
gbl.Log.Infof("✍️ subscribed to everything via node %s", style.Bold(provider.Name))
Expand Down Expand Up @@ -344,7 +346,7 @@ func (pp *Pool) SubscribeToTopics(queueLogs chan types.Log, topics [][]common.Ha
for _, provider := range availableProvider {
// subscribe to all logs with "Tranfer" or "TransferSingle" as first topic
if _, err := provider.subscribeTo(pp.queueLogs, topics, nil); err != nil {
gbl.Log.Warnf("subscribe to topic TransferSingle via node %d failed: %s", provider.Name, err)
gbl.Log.Warnf("subscribe to topic TransferSingle via node %s failed: %s", provider.Name, err)
} else {
subscribedTo++
gbl.Log.Infof("✍️ subscribed to all transfer topics via node %s", style.Bold(provider.Name))
Expand All @@ -370,7 +372,7 @@ func (pp *Pool) SubscribeToEverythingPending(queuePendingTx chan *types.Transact
for _, provider := range availableProvider {
// subscribe to all logs with "Tranfer" or "TransferSingle" as first topic
if _, err := provider.GethClient.SubscribeFullPendingTransactions(context.TODO(), queuePendingTx); err != nil {
gbl.Log.Warnf("subscribe to pending transactions via node %d failed: %s", provider.Name, err)
gbl.Log.Warnf("subscribe to pending transactions via node %s failed: %s", provider.Name, err)
} else {
subscribedTo++
gbl.Log.Infof("✍️ subscribed to pending transactions via node %s", style.Bold(provider.Name))
Expand Down
2 changes: 1 addition & 1 deletion internal/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func SendMessageViaTelegram(message string, chatID int64, imageURI string, reply
// send telegram message
msg, err := sendTelegramMessageWithMarkup(chatID, message, imageURI, replyToMessageID, replyMarkup)
if err != nil {
gbl.Log.Warnf("❌ failed to send telegram message: %s | chatID: '%s' | imageURI: '%s' | msgTelegram: '%s'", err, chatID, imageURI, message)
gbl.Log.Warnf("❌ failed to send telegram message: %s | chatID: '%d' | imageURI: '%s' | msgTelegram: '%s'", err, chatID, imageURI, message)

return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/rueidica/rueidica.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (r *Rueidica) getCachedNumber(ctx context.Context, address common.Address,
case err != nil:
gbl.Log.Errorf("rueidis | error getting cached number: %s", err)
default:
gbl.Log.Debugf("rueidis | found number: %s -> %f", keyFunc(address), cachedNumber)
gbl.Log.Debugf("rueidis | found number: %s -> %s", keyFunc(address), cachedNumber)
}

num, err := strconv.ParseFloat(cachedNumber, 64)
Expand Down
8 changes: 0 additions & 8 deletions internal/style/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,3 @@ func FormatTokenInfo(tokenID *big.Int, collectionName string, primaryStyle lipgl

return tokenInfo
}

func GetNodeColor(eventType int) lipgloss.Color {
if eventType == 3 {
return "#20293d"
}

return ""
}
12 changes: 6 additions & 6 deletions internal/trapri/listings.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ func FormatListing(gb *gloomberg.Gloomberg, event *osmodels.ItemListedEvent) {
// seller address
sellerAddress := common.HexToAddress(event.Payload.Maker.Address)

// parse price
// parse amountPaid
priceWeiRaw, _, err := big.ParseFloat(event.Payload.BasePrice, 10, 64, big.ToNearestEven)
if err != nil {
gbl.Log.Errorf("❌ error parsing price: %s", err.Error())
gbl.Log.Errorf("❌ error parsing amountPaid: %s", err.Error())

return
}

priceWei, _ := priceWeiRaw.Int(nil)
price := price.NewPrice(priceWei)
amountPaid := price.NewPrice(priceWei)

// collection
collection := tokencollections.GetCollection(gb, contractAddress, tokenID)
Expand All @@ -70,7 +70,7 @@ func FormatListing(gb *gloomberg.Gloomberg, event *osmodels.ItemListedEvent) {
Tx: nil,
TxReceipt: nil,
From: sellerAddress,
AmountPaid: price.Wei(),
AmountPaid: amountPaid.Wei(),
TotalTokens: int64(event.Payload.Quantity),
Marketplace: &marketplace.OpenSea,
Action: totra.Listing,
Expand Down Expand Up @@ -119,11 +119,11 @@ func FormatListing(gb *gloomberg.Gloomberg, event *osmodels.ItemListedEvent) {

osLink := style.TerminalLink(event.Payload.Item.Permalink, event.Payload.Item.Permalink)

go notify.SendMessageViaTelegram(fmt.Sprintf("lawless listing: %s \n price: %s url: %s", tokenName, fmt.Sprintf("%5.3f", price.Ether()), osLink), viper.GetInt64("notifications.manifold.dakma"), "", 0, nil)
go notify.SendMessageViaTelegram(fmt.Sprintf("lawless listing: %s \n amountPaid: %s url: %s", tokenName, fmt.Sprintf("%5.3f", amountPaid.Ether()), osLink), viper.GetInt64("notifications.manifold.dakma"), "", 0, nil)

highlightMessage := strings.Builder{}
highlightMessage.WriteString("\n")
highlightMessage.WriteString(fmt.Sprintf(" lawless %s | %5.3fΞ | %s\n", tokenName, price.Ether(), osLink))
highlightMessage.WriteString(fmt.Sprintf(" lawless %s | %5.3fΞ | %s\n", tokenName, amountPaid.Ether(), osLink))
highlightMessage.WriteString("\n")

fmt.Println(highlightMessage.String()) //nolint:forbidigo
Expand Down
Loading

0 comments on commit ff99a83

Please sign in to comment.