Skip to content

Commit

Permalink
feat: update meta struct with shouldRefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 20, 2023
1 parent 6fd4a84 commit ddfd271
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
18 changes: 13 additions & 5 deletions internal/fetcher/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,21 @@ func getHumanizedValue(balanceToken *bigNumber.Int, decimals int, humanizedPrice
** Prepare the multicall to get the basic informations for the V3 vaults
**********************************************************************************************/
func getV3VaultCalls(vault models.TVault) []ethereum.Call {
metadata := storage.GetStrategiesJsonMetadata(vault.ChainID)
lastUpdate := metadata.LastUpdate
shouldRefresh := metadata.ShouldRefresh

calls := []ethereum.Call{}
//For every loop we need at least to update theses
calls = append(calls, multicalls.GetPricePerShare(vault.Address.Hex(), vault.Address))
calls = append(calls, multicalls.GetTotalAssets(vault.Address.Hex(), vault.Address))
calls = append(calls, multicalls.GetDefaultQueue(vault.Address.Hex(), vault.Address))

if time.Since(vault.LastUpdate).Hours() > 1 || true {
if time.Since(lastUpdate).Hours() > 1 || shouldRefresh {
// If the last vault update was more than 1 hour ago, we will do a partial update
calls = append(calls, multicalls.GetShutdown(vault.Address.Hex(), vault.Address))
}
if time.Since(vault.LastUpdate).Hours() > 24 || true {
if time.Since(lastUpdate).Hours() > 24 || shouldRefresh {
// If the last vault update was more than 24 hour ago, we will do a full update
calls = append(calls, multicalls.GetAsset(vault.Address.Hex(), vault.Address))
calls = append(calls, multicalls.GetV3APIVersion(vault.Address.Hex(), vault.Address))
Expand All @@ -70,22 +74,26 @@ func getV3VaultCalls(vault models.TVault) []ethereum.Call {
** Prepare the multicall to get the basic informations for the V2 and earlier vaults
**********************************************************************************************/
func getV2VaultCalls(vault models.TVault) []ethereum.Call {
maxStrategiesPerVault := 20
metadata := storage.GetStrategiesJsonMetadata(vault.ChainID)
lastUpdate := metadata.LastUpdate
shouldRefresh := metadata.ShouldRefresh

calls := []ethereum.Call{}
maxStrategiesPerVault := 20

//For every loop we need at least to update theses
calls = append(calls, multicalls.GetPricePerShare(vault.Address.Hex(), vault.Address))
calls = append(calls, multicalls.GetTotalAssets(vault.Address.Hex(), vault.Address))
for i := 0; i < maxStrategiesPerVault; i++ {
calls = append(calls, multicalls.GetVaultWithdrawalQueue(vault.Address.Hex(), int64(i), vault.Address))
}
if time.Since(vault.LastUpdate).Hours() > 1 {
if time.Since(lastUpdate).Hours() > 1 || shouldRefresh {
// If the last vault update was more than 1 hour ago, we will do a partial update
calls = append(calls, multicalls.GetPerformanceFee(vault.Address.Hex(), vault.Address))
calls = append(calls, multicalls.GetManagementFee(vault.Address.Hex(), vault.Address))
calls = append(calls, multicalls.GetEmergencyShutdown(vault.Address.Hex(), vault.Address))
}
if time.Since(vault.LastUpdate).Hours() > 24 {
if time.Since(lastUpdate).Hours() > 24 || shouldRefresh {
// If the last vault update was more than 24 hour ago, we will do a full update
calls = append(calls, multicalls.GetAPIVersion(vault.Address.Hex(), vault.Address))
calls = append(calls, multicalls.GetV3APIVersion(vault.Address.Hex(), vault.Address))
Expand Down
3 changes: 0 additions & 3 deletions internal/fetcher/vaults.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package fetcher

import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/yearn/ydaemon/common/env"
"github.com/yearn/ydaemon/common/ethereum"
Expand Down Expand Up @@ -54,7 +52,6 @@ func fetchVaultsBasicInformations(
}
newVault := vault
newVault.ChainID = chainID
newVault.LastUpdate = time.Now()
if vault.Version == `3.0.0` {
newVault = handleV3VaultCalls(vault, response)
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/indexer/indexer.strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func watchNewStrategies(
return lastSyncedBlock, true, err
}
}
case `0.3.2`, `0.3.3`, `0.3.4`, `0.3.5`, `0.4.2`, `0.4.3`, `0.4.5`, `0.4.6`:
case `0.3.2`, `0.3.3`, `0.3.4`, `0.3.5`, `0.4.2`, `0.4.3`, `0.4.4`, `0.4.5`, `0.4.6`:
currentVault, _ := contracts.NewYvault043(vault.Address, client)
etherReader := ethereum.Reader{Backend: client}
contractABI, _ := contracts.Yvault043MetaData.GetAbi()
Expand Down
4 changes: 2 additions & 2 deletions internal/models/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type TERC20Token struct {
Type TTokenType `json:"type"`
Name string `json:"name"`
Symbol string `json:"symbol"`
DisplayName string `json:"display_name"`
DisplaySymbol string `json:"display_symbol"`
DisplayName string `json:"displayName"`
DisplaySymbol string `json:"displaySymbol"`
Description string `json:"description"`
Category string `json:"category"`
Icon string `json:"icon"`
Expand Down
3 changes: 0 additions & 3 deletions internal/models/vaults.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package models

import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/yearn/ydaemon/common/bigNumber"
)
Expand Down Expand Up @@ -63,7 +61,6 @@ type TVault struct {
LastActiveStrategies []common.Address `json:"lastActiveStrategies"` // The list of "active" strategies via their withdrawal queue
LastPricePerShare *bigNumber.Int `json:"lastPricePerShare"` // Price per share of the vault
LastTotalAssets *bigNumber.Int `json:"lastTotalAssets"` // Total assets locked in the vault
LastUpdate time.Time `json:"lastUpdate"` // When the vault was last updated

// Manual elements. They are manually set by the team
IsRetired bool `json:"isRetired"` // If the vault is retired or not
Expand Down
4 changes: 0 additions & 4 deletions internal/storage/elem.strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import (

// The _strategiesSyncMap is in JSON and contains the strategies informations
var _strategiesSyncMap = make(map[uint64]*sync.Map)

// The _strategiesMigratedSyncMap is never stored in JSON but used for internal caching
var _strategiesMigratedSyncMap = make(map[uint64]*sync.Map)

// The _strategiesJSONMetadataSyncMap is a sync map containing the last time the strategies were updated for a specific chainID
var _strategiesJSONMetadataSyncMap = sync.Map{}

/** 🔵 - Yearn *************************************************************************************
Expand Down

0 comments on commit ddfd271

Please sign in to comment.