Skip to content

Commit

Permalink
adding vault specific events
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffywu committed Jul 18, 2022
1 parent cfc5f4b commit ee11fe2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
4 changes: 4 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,10 @@ type StrategyVaultMaturity @entity {
"Any insolvency to this vault maturity (if any)"
insolvency: BigInt

"Asset cash remaining for accounts to withdraw post settlement"
remainingSettledAssetCash: BigInt
"Strategy tokens remaining for accounts to withdraw post settlement"
remainingSettledStrategyTokens: BigInt

"All strategy vault accounts in this maturity"
accounts: [StrategyVaultAccount!] @derivedFrom(field: "strategyVaultMaturity")
Expand Down
55 changes: 53 additions & 2 deletions src/vaults.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Address, ByteArray, ethereum, BigInt } from "@graphprotocol/graph-ts";
import { Notional, VaultPauseStatus, VaultUpdated } from "../generated/NotionalVaults/Notional";
import { Notional, VaultPauseStatus, VaultSettledAssetsRemaining, VaultUpdated } from "../generated/NotionalVaults/Notional";
import { IStrategyVault } from '../generated/NotionalVaults/IStrategyVault';
import { StrategyVault, StrategyVaultAccount, StrategyVaultCapacity, StrategyVaultDirectory, StrategyVaultMaturity, StrategyVaultTrade } from "../generated/schema";
import { VaultBorrowCapacityChange, VaultEnterPosition, VaultExitPostMaturity, VaultExitPreMaturity, VaultRepaySecondaryBorrow, VaultRollPosition, VaultSecondaryBorrow, VaultStateUpdate, VaultUpdateSecondaryBorrowCapacity } from "../generated/Notional/Notional";
import { ProtocolInsolvency, VaultBorrowCapacityChange, VaultEnterPosition, VaultExitPostMaturity, VaultExitPreMaturity, VaultFeeAccrued, VaultRepaySecondaryBorrow, VaultRollPosition, VaultSecondaryBorrow, VaultShortfall, VaultStateUpdate, VaultUpdateSecondaryBorrowCapacity } from "../generated/Notional/Notional";
import { updateMarkets } from "./markets";
import { updateNTokenPortfolio } from "./accounts";
import { getNToken } from "./notional";
Expand Down Expand Up @@ -419,4 +419,55 @@ export function handleVaultRepaySecondaryBorrow(event: VaultRepaySecondaryBorrow
// updateVaultState(vault, maturity, event);
updateVaultMarkets(vault, event)
updateVaultAccount(vault, event.params.account, event);
}

export function handleVaultFeeAccrued(event: VaultFeeAccrued): void {
// TODO: need to emit maturity
let maturity = 0;
let vaultMaturity = getVaultMaturity(event.params.vault.toHexString(), maturity)
vaultMaturity.totalNTokenFeesAccrued = vaultMaturity.totalNTokenFeesAccrued.plus(event.params.nTokenFee)
vaultMaturity.totalReserveFeesAccrued = vaultMaturity.totalReserveFeesAccrued.plus(event.params.reserveFee)
vaultMaturity.lastUpdateBlockNumber = event.block.number.toI32();
vaultMaturity.lastUpdateTimestamp = event.block.timestamp.toI32();
vaultMaturity.lastUpdateBlockHash = event.block.hash;
vaultMaturity.lastUpdateTransactionHash = event.transaction.hash;
vaultMaturity.save()
}

export function handleVaultSettledAssetsRemaining(event: VaultSettledAssetsRemaining): void {
let vaultMaturity = getVaultMaturity(event.params.vault.toHexString(), event.params.maturity.toI32())
vaultMaturity.remainingSettledAssetCash = event.params.remainingAssetCash;
vaultMaturity.remainingSettledStrategyTokens = event.params.remainingStrategyTokens;

vaultMaturity.lastUpdateBlockNumber = event.block.number.toI32();
vaultMaturity.lastUpdateTimestamp = event.block.timestamp.toI32();
vaultMaturity.lastUpdateBlockHash = event.block.hash;
vaultMaturity.lastUpdateTransactionHash = event.transaction.hash;
vaultMaturity.save()
}

export function handleVaultShortfall(event: VaultShortfall): void {
// TODO: need to emit maturity
let maturity = 0;
let vaultMaturity = getVaultMaturity(event.params.vault.toHexString(), maturity)
vaultMaturity.shortfall = event.params.shortfall;

vaultMaturity.lastUpdateBlockNumber = event.block.number.toI32();
vaultMaturity.lastUpdateTimestamp = event.block.timestamp.toI32();
vaultMaturity.lastUpdateBlockHash = event.block.hash;
vaultMaturity.lastUpdateTransactionHash = event.transaction.hash;
vaultMaturity.save()
}

export function handleVaultInsolvency(event: ProtocolInsolvency): void {
// TODO: need to emit maturity
let maturity = 0;
let vaultMaturity = getVaultMaturity(event.params.vault.toHexString(), maturity)
vaultMaturity.insolvency = event.params.shortfall

vaultMaturity.lastUpdateBlockNumber = event.block.number.toI32();
vaultMaturity.lastUpdateTimestamp = event.block.timestamp.toI32();
vaultMaturity.lastUpdateBlockHash = event.block.hash;
vaultMaturity.lastUpdateTransactionHash = event.transaction.hash;
vaultMaturity.save()
}
20 changes: 9 additions & 11 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ dataSources:
handler: handleVaultEnterPosition
- event: VaultSecondaryBorrow(indexed address,indexed address,indexed uint16,uint256,uint256)
handler: handleVaultSecondaryBorrow
# - event: VaultFeeAccrued(indexed address,indexed uint16,int256,int256)
# handler: handleVaultUpdated
- event: VaultFeeAccrued(indexed address,indexed uint16,int256,int256)
handler: handleVaultFeeAccrued
# Account Exit Events
- event: VaultExitPostMaturity(indexed address,indexed address,indexed uint256)
handler: handleVaultExitPostMaturity
Expand All @@ -348,19 +348,17 @@ dataSources:
# handler: handleVaultUpdated
# - event: VaultLiquidatorProfit(indexed address,indexed address,indexed address,uint256,bool)
# handler: handleVaultUpdated
# # Vault Level Events
# - event: VaultSettledAssetsRemaining(indexed address,indexed uint256,int256,uint256)
# handler: handleVaultUpdated
# - event: VaultSettled(indexed address,indexed uint256,int256,uint256,uint256,uint256,int256)
# handler: handleVaultUpdated
# Vault Level Events
- event: VaultSettledAssetsRemaining(indexed address,indexed uint256,int256,uint256)
handler: handleVaultSettledAssetsRemaining
# - event: VaultRedeemStrategyToken(indexed address,indexed uint256,int256,uint256)
# handler: handleVaultUpdated
# - event: VaultMintStrategyToken(indexed address,indexed uint256,uint256,uint256)
# handler: handleVaultUpdated
# - event: VaultShortfall(indexed address,indexed uint16,int256)
# handler: handleVaultUpdated
# - event: ProtocolInsolvency(indexed address,indexed uint16,int256)
# handler: handleVaultUpdated
- event: VaultShortfall(indexed address,indexed uint16,int256)
handler: handleVaultShortfall
- event: ProtocolInsolvency(indexed address,indexed uint16,int256)
handler: handleVaultInsolvency
# Generic Vault Event
- event: VaultStateUpdate(indexed address,indexed uint256,int256,uint256,uint256,uint256)
handler: handleVaultStateUpdate
Expand Down

0 comments on commit ee11fe2

Please sign in to comment.