Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPB event updates and remove RewardsManager #67

Merged
merged 5 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ type LPTransferorList @entity {

# represents a LP allowance for a single bucket
type LPAllowance @entity {
id: Bytes! # LPAllowances.id + '|' + $index
id: Bytes! # LPAllowanceList.id + '|' + $index
index: Int! # bucket index where an allowance has been granted
amount: BigDecimal! # size of the allowance (measured in LP)
}

# updated upon Increase/Decrease/RevokeLPAllowance
type LPAllowances @entity {
type LPAllowanceList @entity {
id: Bytes! # $poolAddress + '|' + $lender + '|' + $spender
pool: Pool! # pool in which LP allowances have been granted
lender: Bytes! # address of the lender who has granted an allowance
Expand Down
74 changes: 74 additions & 0 deletions src/mappings/base/base-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { incrementTokenTxCount as incrementTokenTxCountERC20Pool } from "../../u
import { incrementTokenTxCount as incrementTokenTxCountERC721Pool } from "../../utils/token-erc721"
import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "../../utils/pool/reserve-auction"
import { saveOrRemovePositionLend } from "../../utils/position"
import { decreaseAllowances, increaseAllowances, loadOrCreateAllowances, revokeAllowances } from "../../utils/pool/lp-allowances"
import { approveTransferors, loadOrCreateTransferors, revokeTransferors } from "../../utils/pool/lp-transferors"


/*******************************/
Expand Down Expand Up @@ -498,6 +500,78 @@ export function _handleTransferLP(erc20Event: TransferLPERC20Event | null, erc72
transferLP.save()
}

/*************************************/
/*** LPB Management Event Handlers ***/
/*************************************/

export function _handleApproveLPTransferors(event: ethereum.Event, lender: Address, transferors: Address[]): void {
const poolId = addressToBytes(event.address)
const entity = loadOrCreateTransferors(poolId, lender)
approveTransferors(entity, transferors)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
}

export function _handleDecreaseLPAllowance(event: ethereum.Event, spender: Address, indexes: BigInt[], amounts: BigInt[]): void {
const poolId = addressToBytes(event.address)
const lender = event.transaction.from
const entity = loadOrCreateAllowances(poolId, lender, spender)
decreaseAllowances(entity, indexes, amounts)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
}

export function _handleIncreaseLPAllowance(event: ethereum.Event, spender: Address, indexes: BigInt[], amounts: BigInt[]): void {
const poolId = addressToBytes(event.address)
const lender = event.transaction.from
const entity = loadOrCreateAllowances(poolId, lender, spender)
increaseAllowances(entity, indexes, amounts)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
}

export function _handleRevokeLPAllowance(event: ethereum.Event, spender: Address, indexes: BigInt[]): void {
const poolId = addressToBytes(event.address)
const lender = event.transaction.from
const entity = loadOrCreateAllowances(poolId, lender, spender)
revokeAllowances(entity, indexes)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
}

export function _handleRevokeLPTransferors(event: ethereum.Event, lender: Address, transferors: Address[]): void {
const poolId = addressToBytes(event.address)
const entity = loadOrCreateTransferors(poolId, lender)
revokeTransferors(entity, transferors)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
}

/*******************************/
/*** Reserves Event Handlers ***/
/*******************************/
Expand Down
137 changes: 50 additions & 87 deletions src/mappings/erc-20-pool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigInt, Bytes, dataSource, log } from "@graphprotocol/graph-ts"
import { log } from "@graphprotocol/graph-ts"

import {
AddCollateral as AddCollateralEvent,
Expand Down Expand Up @@ -56,9 +56,7 @@ import { getLiquidationAuctionId, getAuctionInfoERC20Pool, loadOrCreateLiquidati
import { updatePool, addLiquidationToPool } from "../utils/pool/pool"
import { lpbValueInQuote } from "../utils/pool/lend"
import { incrementTokenTxCount } from "../utils/token-erc20"
import { approveTransferors, loadOrCreateTransferors, revokeTransferors } from "../utils/pool/lp-transferors"
import { loadOrCreateAllowances, increaseAllowances, decreaseAllowances, revokeAllowances } from "../utils/pool/lp-allowances"
import { _handleAddQuoteToken, _handleBucketBankruptcy, _handleFlashLoan, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleTransferLP } from "./base/base-pool"
import { _handleAddQuoteToken, _handleApproveLPTransferors, _handleBucketBankruptcy, _handleDecreaseLPAllowance, _handleFlashLoan, _handleIncreaseLPAllowance, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleRevokeLPAllowance, _handleRevokeLPTransferors, _handleTransferLP } from "./base/base-pool"

export function handleAddCollateral(event: AddCollateralEvent): void {
const addCollateral = new AddCollateral(
Expand Down Expand Up @@ -128,16 +126,6 @@ export function handleAddQuoteToken(event: AddQuoteTokenEvent): void {
_handleAddQuoteToken(event, null)
}

export function handleApproveLPTransferors(
event: ApproveLPTransferorsEvent
): void {
const poolId = addressToBytes(event.address)
const entity = loadOrCreateTransferors(poolId, event.params.lender)
approveTransferors(entity, event.params.transferors)

entity.save()
}

// ERC20Pool only
// emitted in conjunction with Settle
export function handleAuctionSettle(event: AuctionSettleEvent): void {
Expand Down Expand Up @@ -331,21 +319,6 @@ export function handleBucketTakeLPAwarded(
bucketTake.save()
}

export function handleDecreaseLPAllowance(event: DecreaseLPAllowanceEvent): void {
const poolId = addressToBytes(event.address)
const lender = event.transaction.from
const entity = loadOrCreateAllowances(poolId, lender, event.params.spender)
decreaseAllowances(entity, event.params.indexes, event.params.amounts)

const pool = Pool.load(poolId)
if (pool != null) {
pool.txCount = pool.txCount.plus(ONE_BI)
pool.save()
}

entity.save()
}

export function handleDrawDebt(event: DrawDebtEvent): void {
const drawDebt = new DrawDebt(
event.transaction.hash.concatI32(event.logIndex.toI32())
Expand Down Expand Up @@ -401,21 +374,6 @@ export function handleFlashloan(event: FlashloanEvent): void {
_handleFlashLoan(event, event.params.token, event.params.receiver, event.params.amount)
}

export function handleIncreaseLPAllowance(event: IncreaseLPAllowanceEvent): void {
const poolId = addressToBytes(event.address)
const lender = event.transaction.from
const entity = loadOrCreateAllowances(poolId, lender, event.params.spender)
increaseAllowances(entity, event.params.indexes, event.params.amounts)

const pool = Pool.load(poolId)
if (pool != null) {
pool.txCount = pool.txCount.plus(ONE_BI)
pool.save()
}

entity.save()
}

export function handleKick(event: KickEvent): void {
const kick = new Kick(
event.transaction.hash.concatI32(event.logIndex.toI32())
Expand Down Expand Up @@ -617,49 +575,6 @@ export function handleRepayDebt(event: RepayDebtEvent): void {
repayDebt.save()
}

export function handleReserveAuctionKick(event: KickReserveAuctionEvent): void {
_handleReserveAuctionKick(event, event.params.currentBurnEpoch, event.params.claimableReservesRemaining, event.params.auctionPrice)
}

export function handleReserveAuctionTake(event: ReserveAuctionEvent): void {
_handleReserveAuctionTake(event, event.params.currentBurnEpoch, event.params.claimableReservesRemaining, event.params.auctionPrice)
}

export function handleResetInterestRate(event: ResetInterestRateEvent): void {
_handleInterestRateEvent(event.address, event, event.params.newRate);
}

export function handleRevokeLPAllowance(event: RevokeLPAllowanceEvent): void {
const poolId = addressToBytes(event.address)
const lender = event.transaction.from
const entity = loadOrCreateAllowances(poolId, lender, event.params.spender)
revokeAllowances(entity, event.params.indexes)

const pool = Pool.load(poolId)
if (pool != null) {
pool.txCount = pool.txCount.plus(ONE_BI)
pool.save()
}

entity.save()
}

export function handleRevokeLPTransferors(
event: RevokeLPTransferorsEvent
): void {
const poolId = addressToBytes(event.address)
const entity = loadOrCreateTransferors(poolId, event.params.lender)
revokeTransferors(entity, event.params.transferors)

const pool = Pool.load(poolId)
if (pool != null) {
pool.txCount = pool.txCount.plus(ONE_BI)
pool.save()
}

entity.save()
}

export function handleTake(event: TakeEvent): void {
const take = new Take(
event.transaction.hash.concatI32(event.logIndex.toI32())
Expand Down Expand Up @@ -779,11 +694,59 @@ export function handleSettle(event: SettleEvent): void {
settle.save()
}

/*************************************/
/*** LPB Management Event Handlers ***/
/*************************************/

export function handleApproveLPTransferors(
event: ApproveLPTransferorsEvent
): void {
_handleApproveLPTransferors(event, event.params.lender, event.params.transferors)
}

export function handleDecreaseLPAllowance(event: DecreaseLPAllowanceEvent): void {
_handleDecreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts)
}

export function handleIncreaseLPAllowance(event: IncreaseLPAllowanceEvent): void {
_handleIncreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts)
}

export function handleRevokeLPAllowance(event: RevokeLPAllowanceEvent): void {
_handleRevokeLPAllowance(event, event.params.spender, event.params.indexes)
}

export function handleRevokeLPTransferors(
event: RevokeLPTransferorsEvent
): void {
_handleRevokeLPTransferors(event, event.params.lender, event.params.transferors)
}

export function handleTransferLP(event: TransferLPEvent): void {
event = changetype<TransferLPEvent | null>(event)!
_handleTransferLP(event, null)
}

/***************************/
/*** Pool Event Handlers ***/
/***************************/

export function handleResetInterestRate(event: ResetInterestRateEvent): void {
_handleInterestRateEvent(event.address, event, event.params.newRate);
}

export function handleUpdateInterestRate(event: UpdateInterestRateEvent): void {
_handleInterestRateEvent(event.address, event, event.params.newRate);
}

/*******************************/
/*** Reserves Event Handlers ***/
/*******************************/

export function handleReserveAuctionKick(event: KickReserveAuctionEvent): void {
_handleReserveAuctionKick(event, event.params.currentBurnEpoch, event.params.claimableReservesRemaining, event.params.auctionPrice)
}

export function handleReserveAuctionTake(event: ReserveAuctionEvent): void {
_handleReserveAuctionTake(event, event.params.currentBurnEpoch, event.params.claimableReservesRemaining, event.params.auctionPrice)
}
Loading