Skip to content

Commit

Permalink
wrote getters
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffywu committed Jul 18, 2022
1 parent f07b6a3 commit 7320926
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 44 deletions.
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ type StrategyVaultTrade @entity {
blockNumber: Int!
timestamp: Int!
transactionHash: Bytes!
transactionOrigin: Bytes!

vaultTradeType: VaultTradeType!
isVaultAction: Boolean!
Expand Down
79 changes: 79 additions & 0 deletions src/vaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { ethereum } from "@graphprotocol/graph-ts";
import { StrategyVault, StrategyVaultAccount, StrategyVaultCapacity, StrategyVaultMaturity, StrategyVaultTrade } from "../generated/schema";

function getVault(id: string): StrategyVault {
let entity = StrategyVault.load(id);
if (entity == null) {
entity = new StrategyVault(id);
}
return entity as StrategyVault
}

function getVaultAccount(vault: string, account: string): StrategyVaultAccount {
let id = vault + ":" + account
let entity = StrategyVaultAccount.load(id);
if (entity == null) {
entity = new StrategyVaultAccount(id);
entity.strategyVault = vault
entity.account = account
}

return entity as StrategyVaultAccount
}

function getVaultMaturity(vault: string, maturity: i32): StrategyVaultMaturity {
let id = vault + ":" + maturity.toString()
let entity = StrategyVaultMaturity.load(id);
if (entity == null) {
entity = new StrategyVaultMaturity(id);
entity.strategyVault = vault
entity.maturity = maturity
}

return entity as StrategyVaultMaturity
}

function getVaultCapacity(vault: string): StrategyVaultCapacity {
let id = vault
let entity = StrategyVaultCapacity.load(id);
if (entity == null) {
entity = new StrategyVaultCapacity(id);
entity.strategyVault = vault
}

return entity as StrategyVaultCapacity
}

function getVaultTrade(
vault: string,
maturity: i32,
account: string,
event: ethereum.Event
): StrategyVaultTrade {
let id = (
vault + ':'
+ maturity.toString() + ':'
+ account.toString() + ':'
+ event.transaction.hash.toHexString() + ':'
+ event.logIndex.toString()
);

let entity = new StrategyVaultTrade(id);
entity.blockHash = event.block.hash;
entity.blockNumber = event.block.number.toI32();
entity.timestamp = event.block.timestamp.toI32();
entity.transactionHash = event.transaction.hash;
entity.transactionOrigin = event.transaction.from;
entity.isVaultAction = vault == account
entity.strategyVaultMaturity = vault + ":" + maturity.toString()
if (vault != account) {
entity.strategyVaultAccount = vault + ":" + account
}

return entity
}

export function handleVaultUpdated()
export function handleVaultPauseStatus()
export function handleVaultUpdateSecondaryBorrowCapacity()
export function handleVaultBorrowCapacityChange()
114 changes: 70 additions & 44 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -293,53 +293,79 @@ dataSources:
handler: handleTreasuryManagerChanged
- event: ReserveBufferUpdated(uint16,uint256)
handler: handleReserveBufferUpdated
# Strategy Vaults
file: ./src/notional.ts
- kind: ethereum/contract
name: Notional Vaults
network: {{networkName}}
source:
address: '{{ notional }}'
abi: Notional
startBlock: {{startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- StrategyVault
- StrategyVaultAccount
- StrategyVaultMaturity
- StrategyVaultTrade
- StrategyVaultHistoricalValue
- StrategyVaultCapacity
abis:
- name: Notional
file: ./abi/Notional.json
- name: ERC20
file: ./abi/ERC20.json
blockHandlers:
- handler: handleBlockUpdates
eventHandlers:
# Vault Configuration
- event: VaultUpdated(indexed address,bool,uint80);
handler: handleVaultUpdated
- event: VaultPauseStatus(indexed address,bool);
handler: handleVaultUpdated
handler: handleVaultPauseStatus
- event: VaultUpdateSecondaryBorrowCapacity(indexed address,indexed uint16,uint80);
handler: handleVaultUpdated
# Account Entry Events
- event: VaultEnterPosition(indexed address,indexed address,indexed uint256,uint256);
handler: handleVaultUpdated
- event: VaultEnterMaturity(indexed address,indexed uint256,indexed address,uint256,uint256,uint256);
handler: handleVaultUpdated
- event: VaultFeeAccrued(indexed address,indexed uint16,int256,int256);
handler: handleVaultUpdated
- event: VaultSecondaryBorrow(indexed address,indexed address,indexed uint16,uint256,uint256);
handler: handleVaultUpdated
# Account Exit Events
- event: VaultExitPostMaturity(indexed address,indexed address,indexed uint256);
handler: handleVaultUpdated
- event: VaultExitPreMaturity(indexed address,indexed address,indexed uint256,uint256,uint256);
handler: handleVaultUpdated
- event: VaultRepaySecondaryBorrow(indexed address,indexed address,indexed uint16,uint256,uint256);
handler: handleVaultUpdated
# Account Other Events
- event: VaultRollPosition(indexed address,indexed address,indexed uint256,uint256);
handler: handleVaultUpdated
- event: VaultDeleverageAccount(indexed address,indexed address,uint256,int256);
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
- 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
# Generic Vault Event
- event: VaultStateUpdate(indexed address,indexed uint256,int256,uint256,uint256,uint256);
handler: handleVaultUpdated
handler: handleVaultUpdateSecondaryCapacity
# # Account Entry Events
# - event: VaultEnterPosition(indexed address,indexed address,indexed uint256,uint256);
# handler: handleVaultUpdated
# - event: VaultEnterMaturity(indexed address,indexed uint256,indexed address,uint256,uint256,uint256);
# handler: handleVaultUpdated
# - event: VaultFeeAccrued(indexed address,indexed uint16,int256,int256);
# handler: handleVaultUpdated
# - event: VaultSecondaryBorrow(indexed address,indexed address,indexed uint16,uint256,uint256);
# handler: handleVaultUpdated
# # Account Exit Events
# - event: VaultExitPostMaturity(indexed address,indexed address,indexed uint256);
# handler: handleVaultUpdated
# - event: VaultExitPreMaturity(indexed address,indexed address,indexed uint256,uint256,uint256);
# handler: handleVaultUpdated
# - event: VaultRepaySecondaryBorrow(indexed address,indexed address,indexed uint16,uint256,uint256);
# handler: handleVaultUpdated
# # Account Other Events
# - event: VaultRollPosition(indexed address,indexed address,indexed uint256,uint256);
# handler: handleVaultUpdated
# - event: VaultDeleverageAccount(indexed address,indexed address,uint256,int256);
# 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
# - 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
# # Generic Vault Event
# - event: VaultStateUpdate(indexed address,indexed uint256,int256,uint256,uint256,uint256);
# handler: handleVaultUpdated
- event: VaultBorrowCapacityChange(indexed address,indexed uint16,uint256);
handler: handleVaultUpdated
file: ./src/notional.ts
handler: handleVaultBorrowCapacityChange
file: ./src/vaults.ts

0 comments on commit 7320926

Please sign in to comment.