Skip to content

Commit

Permalink
Better vault lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed May 23, 2024
1 parent 725ee63 commit 9ca6780
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/mapping/vault.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { handleVaultInitialized as handleInitialized } from "../vault-lifecycle"
export { handleVaultInitialized as handleInitialized, handleUpgradeStrat as handleUpgradeStrat } from "../vault-lifecycle"
export { handleVaultTransfer as handleTransfer } from "../vault-interaction"
22 changes: 12 additions & 10 deletions src/vault-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ import { log } from "matchstick-as"

export function handleVaultCreated(event: VaultCreated): void {
// start watching the vault events
log.debug("Vault created: {}", [event.params.proxy.toHexString()])

const vaultAddress = event.params.proxy
log.debug("Vault created: {}", [vaultAddress.toHexString()])

// test if we are creating a vault or a strategy
const vaultContract = BeefyVaultV7Contract.bind(vaultAddress)
const strategyRes = vaultContract.try_strategy()
// proxy also creates the strategies
if (strategyRes.reverted) {
log.warning("`strategy()` method does not exist on contract: {}. It's not a vault", [vaultAddress.toHexString()])
return
}

const vault = getBeefyVault(vaultAddress)
vault.save()

Expand All @@ -32,14 +41,7 @@ export function handleVaultInitialized(event: ethereum.Event): void {
}

const vaultContract = BeefyVaultV7Contract.bind(vaultAddress)
const strategyRes = vaultContract.try_strategy()
// proxy also creates the strategies
if (strategyRes.reverted) {
log.error("Vault strategy call reverted: {}", [vaultAddress.toHexString()])
store.remove("BeefyVault", vault.id.toHexString())
return
}
const strategyAddress = strategyRes.value
const strategyAddress = vaultContract.strategy()

vault.isInitialized = true
vault.strategy = strategyAddress
Expand Down

0 comments on commit 9ca6780

Please sign in to comment.