/
main.go
executable file
·110 lines (97 loc) · 3.48 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"strconv"
"sync"
"time"
"github.com/go-co-op/gocron"
"github.com/yearn/ydaemon/common/ethereum"
"github.com/yearn/ydaemon/common/logs"
"github.com/yearn/ydaemon/internal"
"github.com/yearn/ydaemon/processes/apr"
"github.com/yearn/ydaemon/processes/initDailyBlock"
"github.com/yearn/ydaemon/processes/vaultsMigrations"
)
func processServer(chainID uint64) {
setStatusForChainID(chainID, `Loading`)
defer setStatusForChainID(chainID, `OK`)
scheduler := gocron.NewScheduler(time.UTC)
logs.Info(`Getting WS client for chain ` + strconv.FormatUint(chainID, 10))
ethereum.GetWSClient(chainID)
ethereum.InitBlockTimestamp(chainID)
internal.InitializeV2(chainID, nil, scheduler)
triggerInitializedStatus(chainID)
}
/**************************************************************************************************
** The version of the daemon is displayed on the server. The version is based on the latest git
** commit, trimmed to only show the first 7 characters of the commit hash.
**************************************************************************************************/
var version = ""
func getVersion() string {
if version == "" {
return "dev"
}
return version[:7]
}
/**************************************************************************************************
** Main entry point for the daemon, handling everything from initialization to running external
** processes.
**************************************************************************************************/
func main() {
initFlags()
summonDaemonsForAllChains(chains)
go listenToSignals()
var wg sync.WaitGroup
logs.Info(`Running external processes...`)
/** 🔵 - Yearn *************************************************************************************
** This section of the code is responsible for running external processes. Each process is associated
** with a specific chain ID and is run concurrently for efficiency. The processes include fetching
** and updating prices, initializing V2, building token lists, running vault migrations, initializing
** daily blocks, initializing APY, etc.
**
** The status of each process is tracked and updated for each chain ID. Once all processes for a
** chain ID have completed, the status is set to "OK".
**
** The server is ready to accept requests once all processes have completed.
**************************************************************************************************/
switch process {
case ProcessServer:
logs.Info(`Running yDaemon server process...`)
go NewRouter().Run(`:8080`)
go triggerTgMessage(`💛 - yDaemon v` + getVersion() + ` is ready to accept requests: https://ydaemon.yearn.fi/`)
for _, chainID := range chains {
go processServer(chainID)
}
logs.Success(`Server ready on port 8080 !`)
select {}
case ProcessVaultMigrations:
logs.Info(`Running yDaemon vault migrations process...`)
for _, chainID := range chains {
wg.Add(1)
go func(chainID uint64) {
vaultsMigrations.Run(chainID)
wg.Done()
}(chainID)
}
wg.Wait()
case ProcessInitDailyBlock:
logs.Info(`Running yDaemon DailyBlock Initializer process...`)
for _, chainID := range chains {
wg.Add(1)
go func(chainID uint64) {
initDailyBlock.Run(chainID)
wg.Done()
}(chainID)
}
wg.Wait()
case ProcessAPY:
logs.Info(`Running yDaemon APY Initializer process...`)
for _, chainID := range chains {
wg.Add(1)
go func(chainID uint64) {
apr.Run(chainID)
wg.Done()
}(chainID)
}
wg.Wait()
}
}