-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (44 loc) · 1.4 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"context"
"fmt"
"os"
"brahma/common/config"
"brahma/common/db"
"brahma/common/logger"
"brahma/internal/api"
"brahma/internal/chain"
"brahma/internal/core"
"brahma/internal/repository"
)
func main() {
config, err := config.NewConfiguration()
if err != nil {
fmt.Printf("Failed to load configuration, %v", err)
os.Exit(1)
}
ctx := context.Background()
log := logger.NewLogger(config.GetLoggerConfig())
db := db.NewDatabase(ctx, config.GetDatabaseConfig(), log.Clone("db"))
if err = db.Connect(); err != nil {
log.Fatal("Failed to connect to database", "err", err)
}
if err = db.Migrate(); err != nil {
log.Fatal("Failed to run migrations", "err", err)
}
poolRepository := repository.NewPoolRepository(ctx, db)
uniswapPoolManager, err := chain.NewUniswapPoolManager(ctx, log.Clone("pool_manager"), config.GetChainConfig())
if err != nil {
log.Fatal("Failed to create uniswap pool manager", "err", err)
}
brahmaService := core.NewBrahmaService(log.Clone("core"), poolRepository, uniswapPoolManager)
// save passed pool addresses into database if not already exists
for _, poolAddress := range config.GetChainConfig().Pools {
brahmaService.AddPool(poolAddress)
}
if err = brahmaService.WatchBlocks(); err != nil {
log.Fatal("Failed to start watching blocks", "err", err)
}
server := api.NewServer(log, brahmaService, config.GetApiConfig())
server.Listen()
}