Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ConfigUpdated handler #83

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ tests/.bin
tests/*.json
matchstick.yaml

# Local history vscode extension
.history

# Other
src/helpers/constants.ts
2 changes: 2 additions & 0 deletions src/entities/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 23 additions & 1 deletion src/mappings/keeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<string> = []
let osTokenVaultsValue = config.toObject().get('os_token_vaults')
if (osTokenVaultsValue !== null) {
osTokenVaultIds = osTokenVaultsValue.toArray().map<string>((id: JSONValue): string => id.toString().toLowerCase())
}

network.osTokenVaultIds = osTokenVaultIds
network.oraclesConfigIpfsHash = configIpfsHash
network.save()
log.info('[Keeper] ConfigUpdated configIpfsHash={}', [configIpfsHash])
}
6 changes: 6 additions & 0 deletions src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
Expand Down
2 changes: 2 additions & 0 deletions src/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ dataSources:
handler: handleHarvested
- event: ValidatorsApproval(indexed address,string)
handler: handleValidatorsApproval
- event: ConfigUpdated(string)
handler: handleConfigUpdated
blockHandlers:
- handler: initialize
filter:
Expand Down