-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmain.go
executable file
·112 lines (98 loc) · 4.62 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
111
112
package internal
import (
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/go-co-op/gocron"
"github.com/yearn/ydaemon/common/logs"
"github.com/yearn/ydaemon/internal/fetcher"
"github.com/yearn/ydaemon/internal/indexer"
"github.com/yearn/ydaemon/internal/models"
"github.com/yearn/ydaemon/internal/storage"
"github.com/yearn/ydaemon/processes/apr"
"github.com/yearn/ydaemon/processes/initDailyBlock"
"github.com/yearn/ydaemon/processes/prices"
"github.com/yearn/ydaemon/processes/risks"
)
var STRATLIST = []models.TStrategy{}
func initStakingPools(chainID uint64) {
/**********************************************************************************************
** Start the Staking Indexing process and schedule it to run every hour. This indexer
** will fetch the relevent data for the OP Staking contracts as well as thoose responsible
** for the APR calculations.
**********************************************************************************************/
indexer.IndexStakingPools(chainID)
indexer.IndexVeYFIStakingContract(chainID)
indexer.IndexJuicedStakingContract(chainID)
indexer.IndexV3StakingContract(chainID)
logs.Success(chainID, `-`, `InitStakingPools ✅`)
}
func initVaults(chainID uint64) (
map[common.Address]models.TVaultsFromRegistry,
map[common.Address]models.TVault,
map[common.Address]models.TERC20Token,
) {
/** 🔵 - Yearn *************************************************************************************
** InitializeV2 is only called on initialization. It's first job is to retrieve the initial data:
** - The registries vaults
** - The vaults
** - The strategies
** - The tokens
**************************************************************************************************/
indexer.IndexYearnXPoolTogetherVaults(chainID)
registries := indexer.IndexNewVaults(chainID)
logs.Success(chainID, `-`, `InitRegistries ✅`, len(registries))
vaultMap := fetcher.RetrieveAllVaults(chainID, registries)
logs.Success(chainID, `-`, `InitVaults ✅`, len(vaultMap))
tokenMap := fetcher.RetrieveAllTokens(chainID, vaultMap)
logs.Success(chainID, `-`, `InitTokens ✅`, len(tokenMap))
return registries, vaultMap, tokenMap
}
func initStrategies(chainID uint64, vaultMap map[common.Address]models.TVault) {
/** 🔵 - Yearn *************************************************************************************
** initStrategies is only called on initialization. It's first job is to retrieve the strategies
** and then to schedule the retrieval of the strategies every 3 hours
**************************************************************************************************/
strategiesMap := indexer.IndexNewStrategies(chainID, vaultMap)
fetcher.RetrieveAllStrategies(chainID, strategiesMap)
logs.Success(chainID, `-`, `InitStrategies ✅`, len(strategiesMap))
}
func InitializeV2(chainID uint64, wg *sync.WaitGroup, scheduler *gocron.Scheduler) {
if wg != nil {
defer wg.Done()
}
var vaultMap map[common.Address]models.TVault
var tokenMap map[common.Address]models.TERC20Token
scheduler.Every(2).Hours().StartImmediately().Do(func() {
_, vaultMap, tokenMap = initVaults(chainID)
risks.RetrieveAvailableRiskScores(chainID)
risks.RetrieveAllRiskScores(chainID, vaultMap)
initStakingPools(chainID)
initStrategies(chainID, vaultMap)
/**********************************************************************************************
** Retrieving prices and strategies for all the given token and strategies on that chain.
** This is done in parallel to speed up the process and reduce the time it takes to complete.
** The scheduler is used to retrieve the strategies every 15 minutes.
** Computing APRS
**********************************************************************************************/
prices.RetrieveAllPrices(chainID, tokenMap)
logs.Success(chainID, `-`, `RetrieveAllPrices ✅`)
apr.ComputeChainAPY(chainID)
logs.Success(chainID, `-`, `ComputeChainAPY ✅`)
})
scheduler.Every(1).Days().At("01:00").StartImmediately().Do(func() {
risks.RetrieveAvailableRiskScores(chainID)
risks.RetrieveAllRiskScores(chainID, vaultMap)
})
scheduler.Every(30).Minute().WaitForSchedule().Do(func() {
currentTokenMap, _ := storage.ListERC20(chainID)
prices.RetrieveAllPrices(chainID, currentTokenMap)
apr.ComputeChainAPY(chainID)
})
/**********************************************************************************************
** Do some background work
**********************************************************************************************/
scheduler.Every(10).Hours().StartImmediately().At("12:10").Do(func() {
initDailyBlock.Run(chainID)
})
scheduler.StartAsync()
}