Skip to content

Commit

Permalink
adding net cash to exit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffywu committed Aug 22, 2022
1 parent 88a27bf commit c929e61
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
12 changes: 12 additions & 0 deletions abi/Notional.json
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,12 @@
"internalType": "uint256",
"name": "maturity",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "underlyingToReceiver",
"type": "uint256"
}
],
"name": "VaultExitPostMaturity",
Expand Down Expand Up @@ -1071,6 +1077,12 @@
"internalType": "uint256",
"name": "vaultSharesToRedeem",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "underlyingToReceiver",
"type": "uint256"
}
],
"name": "VaultExitPreMaturity",
Expand Down
25 changes: 21 additions & 4 deletions src/vaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, ByteArray, ethereum, BigInt } from "@graphprotocol/graph-ts"
import { Address, ByteArray, ethereum, BigInt, dataSource } from "@graphprotocol/graph-ts"
import {
Notional,
VaultPauseStatus,
Expand Down Expand Up @@ -488,14 +488,30 @@ export function handleVaultExitPreMaturity(event: VaultExitPreMaturity): void {
// No nToken Fee to update
updateVaultMarkets(vault, event)
let accountAfter = updateVaultAccount(vault, event.params.account, event)
setVaultTrade(vault.id, accountBefore, accountAfter, "ExitPreMaturity", event, null)
let netUnderlyingCash: BigInt | null;
// Prior to this block on goerli, the underlyingToReceiver was not part of the event
if (dataSource.network() === "goerli" && event.block.number.lt(BigInt.fromI32(7454321))) {
netUnderlyingCash = null
} else {
netUnderlyingCash = event.params.underlyingToReceiver.neg()
}
setVaultTrade(vault.id, accountBefore, accountAfter, "ExitPreMaturity", event, netUnderlyingCash)
}

export function handleVaultExitPostMaturity(event: VaultExitPostMaturity): void {
let vault = getVault(event.params.vault.toHexString())
let accountBefore = getVaultAccount(vault.id, event.params.account.toHexString())
let accountAfter = updateVaultAccount(vault, event.params.account, event)
setVaultTrade(vault.id, accountBefore, accountAfter, "ExitPostMaturity", event, null)

let netUnderlyingCash: BigInt | null;
// Prior to this block on goerli, the underlyingToReceiver was not part of the event
if (dataSource.network() === "goerli" && event.block.number.lt(BigInt.fromI32(7454321))) {
netUnderlyingCash = null
} else {
netUnderlyingCash = event.params.underlyingToReceiver.neg()
}

setVaultTrade(vault.id, accountBefore, accountAfter, "ExitPostMaturity", event, netUnderlyingCash)
}

export function handleVaultStateUpdate(event: VaultStateUpdate): void {
Expand Down Expand Up @@ -538,14 +554,15 @@ export function handleDeleverageAccount(event: VaultDeleverageAccount): void {
let vault = getVault(event.params.vault.toHexString())
let accountBefore = getVaultAccount(vault.id, event.params.account.toHexString())
let accountAfter = updateVaultAccount(vault, event.params.account, event)
setVaultTrade(vault.id, accountBefore, accountAfter, "DeleverageAccount", event, null)
setVaultTrade(vault.id, accountBefore, accountAfter, "DeleverageAccount", event, event.params.fCashRepaid)
}

export function handleUpdateLiquidator(event: VaultLiquidatorProfit): void {
if (event.params.transferSharesToLiquidator) {
let vault = getVault(event.params.vault.toHexString())
let accountBefore = getVaultAccount(vault.id, event.params.liquidator.toHexString())
let accountAfter = updateVaultAccount(vault, event.params.liquidator, event)
// NOTE: deposit amount is not logged here, it is logged on the deleverage account event instead
setVaultTrade(vault.id, accountBefore, accountAfter, "TransferFromDeleverage", event, null)
}
}
Expand Down
4 changes: 2 additions & 2 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ dataSources:
- event: VaultFeeAccrued(indexed address,indexed uint16,indexed uint256,int256,int256)
handler: handleVaultFeeAccrued
# Account Exit Events
- event: VaultExitPostMaturity(indexed address,indexed address,indexed uint256)
- event: VaultExitPostMaturity(indexed address,indexed address,indexed uint256,uint256)
handler: handleVaultExitPostMaturity
- event: VaultExitPreMaturity(indexed address,indexed address,indexed uint256,uint256,uint256)
- event: VaultExitPreMaturity(indexed address,indexed address,indexed uint256,uint256,uint256,uint256)
handler: handleVaultExitPreMaturity
- event: VaultRepaySecondaryBorrow(indexed address,indexed address,indexed uint16,uint256,uint256,uint256)
handler: handleVaultRepaySecondaryBorrow
Expand Down

0 comments on commit c929e61

Please sign in to comment.