Skip to content

Commit

Permalink
chore: add subgraph things for zenbull-netting
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkaroraa committed Feb 3, 2023
1 parent 62a6bcb commit e5f20f5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/subgraph/config/goerli-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@
"ZenEmergencyShutdown": "0x14386333EFa3354c1cF39A38a9c9E372A4bC8c36",
"ZenEmergencyShutdown-start-block": 8145337,
"FlashZen": "0x3876aF971560FD4c4ba3FB18632AcC0570B745b1",
"FlashZen-start-block": 8145337
"FlashZen-start-block": 8145337,
"ZenBullNetting": "0x30ba683c45c8b14601ec32759134b7662cef7d93",
"ZenBullNetting-start-block": 8413668
}
29 changes: 27 additions & 2 deletions packages/subgraph/src/bullStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import {
Strategy,
FullRebalance as FullRebalanceSchema
} from "../generated/schema"
import * as WETH9 from "../generated/Weth/Weth"
import { Address, BigInt, ByteArray, Bytes, ethereum, log } from "@graphprotocol/graph-ts"
import { EthDeposited, ZenBullWithdrawn } from '../generated/ZenBullNetting/ZenBullNetting'
import { BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts"
import { loadOrCreateStrategy } from "./util"
import { AUCTION_BULL, FLASH_BULL_ADDR, WETH } from "./constants"

Expand Down Expand Up @@ -320,3 +320,28 @@ function findFlashBullEthDeposited(event: FlashDeposit): BigInt {

return event.params.ethDeposited.minus(returnedAmount)
}

export function handleNettingDeposit(event: EthDeposited): void {
const userTx = loadOrCreateTx(`${event.transaction.hash.toHex()}-${event.logIndex.toString()}`)

userTx.ethAmount = event.params.ethAmount
userTx.bullAmount = event.params.zenBullAmount
userTx.user = event.params.depositor
userTx.owner = event.params.depositor
userTx.type = 'OTC_DEPOSIT'
userTx.timestamp = event.block.timestamp
userTx.excessEth = event.params.refundedETH
userTx.save()
}

export function handleNettingWithdraw(event: ZenBullWithdrawn): void {
const userTx = loadOrCreateTx(`${event.transaction.hash.toHex()}-${event.logIndex.toString()}`)

userTx.bullAmount = event.params.zenBullAmount
userTx.ethAmount = event.params.ethAmount
userTx.user = event.params.withdrawer
userTx.owner = event.params.withdrawer
userTx.type = 'OTC_WITHDRAW'
userTx.timestamp = event.block.timestamp
userTx.save()
}
22 changes: 22 additions & 0 deletions packages/subgraph/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,28 @@ dataSources:
- event: Transfer(indexed address,indexed address,uint256)
handler: handleTransfer
file: ./src/bullStrategy.ts
- kind: ethereum/contract
name: ZenBullNetting
network: {{network}}
source:
address: "{{ZenBullNetting}}"
abi: ZenBullNetting
startBlock: {{ZenBullNetting-start-block}}
mapping:
kind: ethereum/events
apiVersion: 0.0.7
language: wasm/assemblyscript
entities:
- Strategy
abis:
- name: ZenBullNetting
file: ./abis/ZenBullNetting.json
eventHandlers:
- event: EthDeposited(indexed address,uint256,uint256,indexed uint256,uint256)
handler: handleNettingDeposit
- event: ZenBullWithdrawn(indexed address,uint256,uint256,indexed uint256)
handler: handleNettingWithdraw
file: ./src/bullStrategy.ts
- kind: ethereum/contract
name: ZenAuction
network: {{network}}
Expand Down

0 comments on commit e5f20f5

Please sign in to comment.