Skip to content

Commit

Permalink
Add ConfigUpdated handler (#83)
Browse files Browse the repository at this point in the history
* Add ConfigUpdated handler

* Add oraclesConfigIpfsHash
  • Loading branch information
evgeny-stakewise authored Nov 19, 2024
1 parent 28593ba commit ccdca4a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
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

0 comments on commit ccdca4a

Please sign in to comment.