diff --git a/.gitignore b/.gitignore index f12883c..76ee0a0 100644 --- a/.gitignore +++ b/.gitignore @@ -35,5 +35,8 @@ tests/.bin tests/*.json matchstick.yaml +# Local history vscode extension +.history + # Other src/helpers/constants.ts diff --git a/src/entities/network.ts b/src/entities/network.ts index 186ac56..442dc60 100644 --- a/src/entities/network.ts +++ b/src/entities/network.ts @@ -14,6 +14,8 @@ export function createOrLoadNetwork(): Network { network.totalAssets = BigInt.zero() network.totalEarnedAssets = BigInt.zero() network.vaultIds = [] + network.osTokenVaultIds = [] + network.oraclesConfigIpfsHash = '' network.assetsUsdRate = BigDecimal.zero() network.usdToDaiRate = BigDecimal.zero() network.usdToEurRate = BigDecimal.zero() diff --git a/src/mappings/keeper.ts b/src/mappings/keeper.ts index 3ff7339..1c488cd 100644 --- a/src/mappings/keeper.ts +++ b/src/mappings/keeper.ts @@ -55,7 +55,7 @@ import { getAllocatorLtvStatus, } from '../entities/allocator' import { createOrLoadNetwork, isGnosisNetwork } from '../entities/network' -import { Harvested, RewardsUpdated, ValidatorsApproval } from '../../generated/Keeper/Keeper' +import { ConfigUpdated, Harvested, RewardsUpdated, ValidatorsApproval } from '../../generated/Keeper/Keeper' import { convertSharesToAssets, getVaultStateUpdate, snapshotVault, updateVaultApy } from '../entities/vaults' import { createOrLoadV2Pool, getPoolStateUpdate, updatePoolApy } from '../entities/v2pool' import { createOrLoadOsTokenConfig } from '../entities/osTokenConfig' @@ -459,3 +459,25 @@ export function handleExitRequests(block: ethereum.Block): void { } log.info('[ExitRequests] Sync exit requests at block={}', [block.number.toString()]) } + +export function handleConfigUpdated(event: ConfigUpdated): void { + const configIpfsHash = event.params.configIpfsHash + const network = createOrLoadNetwork() + + let data: Bytes | null = ipfs.cat(configIpfsHash) + while (data === null) { + log.warning('[Keeper] ConfigUpdated ipfs.cat failed, retrying', []) + data = ipfs.cat(configIpfsHash) + } + const config = json.fromBytes(data as Bytes) + let osTokenVaultIds: Array = [] + let osTokenVaultsValue = config.toObject().get('os_token_vaults') + if (osTokenVaultsValue !== null) { + osTokenVaultIds = osTokenVaultsValue.toArray().map((id: JSONValue): string => id.toString().toLowerCase()) + } + + network.osTokenVaultIds = osTokenVaultIds + network.oraclesConfigIpfsHash = configIpfsHash + network.save() + log.info('[Keeper] ConfigUpdated configIpfsHash={}', [configIpfsHash]) +} diff --git a/src/schema.graphql b/src/schema.graphql index 0e3b575..5425e50 100644 --- a/src/schema.graphql +++ b/src/schema.graphql @@ -424,6 +424,12 @@ type Network @entity { "The non repeated addresses of all the vaults" vaultIds: [String!]! + "The non repeated addresses of all the vaults used for osToken rate calculation" + osTokenVaultIds: [String!]! + + "Oracles config ipfs hash" + oraclesConfigIpfsHash: String! + "The total number of non repeated vault allocators and osToken holders" usersCount: Int! } diff --git a/src/subgraph.template.yaml b/src/subgraph.template.yaml index b69dd2b..851c016 100644 --- a/src/subgraph.template.yaml +++ b/src/subgraph.template.yaml @@ -147,6 +147,8 @@ dataSources: handler: handleHarvested - event: ValidatorsApproval(indexed address,string) handler: handleValidatorsApproval + - event: ConfigUpdated(string) + handler: handleConfigUpdated blockHandlers: - handler: initialize filter: