Skip to content

Commit

Permalink
Add in comptroller.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
davekaj committed Sep 20, 2019
1 parent dfb310e commit e9cc55b
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/mappings/comptroller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {BigDecimal} from '@graphprotocol/graph-ts'
import {
MarketEntered,
MarketExited,
NewCloseFactor,
NewCollateralFactor,
NewLiquidationIncentive,
NewMaxAssets,
NewPriceOracle
} from '../types/comptroller/Comptroller'

import {
Market,
Comptroller,
} from '../types/schema'

// TODO - uncomment when i am not testing with just REP
export function handleMarketEntered(event: MarketEntered): void {
// let id = event.params.cToken.toHexString()
// let market = Market.load(id)
// let previousUsers = market.usersEntered
// previousUsers.push(event.params.account)
// market.usersEntered = previousUsers
// market.save()
}

// TODO - uncomment when i am not testing with just REP
export function handleMarketExited(event: MarketExited): void {
// let id = event.params.cToken.toHexString()
// let market = Market.load(id)
// let previousUsers = market.usersEntered
// let i = previousUsers.indexOf(event.params.account)
// previousUsers.splice(i, 1)
// market.usersEntered = previousUsers
// market.save()
}


export function handleNewCloseFactor(event: NewCloseFactor): void {
let comptroller = Comptroller.load("1")
comptroller.closeFactor = event.params.newCloseFactorMantissa
comptroller.save()
}

// TODO - uncomment when i am not testing with just REP
export function handleNewCollateralFactor(event: NewCollateralFactor): void {
// let market = Market.load(event.params.cToken.toHexString())
// market.collateralFactor = event.params.newCollateralFactorMantissa as BigDecimal
// market.save()
}

// This should still be the first event.... weird
export function handleNewLiquidationIncentive(event: NewLiquidationIncentive): void {
let comptroller = Comptroller.load("1")
comptroller.liquidationIncentive = event.params.newLiquidationIncentiveMantissa
comptroller.save()
}

export function handleNewMaxAssets(event: NewMaxAssets): void {
let comptroller = Comptroller.load("1")
comptroller.maxAssets = event.params.newMaxAssets
comptroller.save()
}

export function handleNewPriceOracle(event: NewPriceOracle): void {
let comptroller = Comptroller.load("1")
// This is the first event used in this mapping, so we use it to create the entity
if (comptroller == null) {
comptroller = new Comptroller("1")
}
comptroller.priceOracle = event.params.newPriceOracle
comptroller.save()
}


0 comments on commit e9cc55b

Please sign in to comment.