Skip to content

Commit

Permalink
add shared _handleBucketTakeLPAwarded handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Sep 19, 2023
1 parent d8289f0 commit 1a4aafb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 47 deletions.
25 changes: 24 additions & 1 deletion src/mappings/base/base-pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, BigInt, Bytes, ethereum, log } from "@graphprotocol/graph-ts"
import { Account, AddQuoteToken, BondWithdrawn, Bucket, BucketBankruptcy, Flashloan, Lend, LoanStamped, MoveQuoteToken, Pool, PositionLend, RemoveQuoteToken, ReserveAuctionKick, ReserveAuctionTake, Token, TransferLP, UpdateInterestRate } from "../../../generated/schema"
import { Account, AddQuoteToken, BondWithdrawn, Bucket, BucketBankruptcy, BucketTakeLPAwarded, Flashloan, Lend, LoanStamped, MoveQuoteToken, Pool, PositionLend, RemoveQuoteToken, ReserveAuctionKick, ReserveAuctionTake, Token, TransferLP, UpdateInterestRate } from "../../../generated/schema"
import {
AddQuoteToken as AddQuoteTokenERC20Event,
MoveQuoteToken as MoveQuoteTokenERC20Event,
Expand All @@ -25,6 +25,7 @@ import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "../../ut
import { saveOrRemovePositionLend } from "../../utils/position"
import { decreaseAllowances, increaseAllowances, loadOrCreateAllowances, revokeAllowances, saveOrRemoveAllowances } from "../../utils/pool/lp-allowances"
import { approveTransferors, loadOrCreateTransferors, revokeTransferors, saveOrRemoveTranserors } from "../../utils/pool/lp-transferors"
import { loadOrCreateBucketTake } from "../../utils/pool/liquidation"


/*******************************/
Expand Down Expand Up @@ -590,6 +591,28 @@ export function _handleBondWithdrawn(event: ethereum.Event, kicker: Address, rec
entity.save()
}

// emitted along with BucketTake
export function _handleBucketTakeLPAwarded(event: ethereum.Event, kicker: Address, taker: Address, lpAwardedKicker: BigInt, lpAwardedTaker: BigInt): void {
const lpAwardedId = event.transaction.hash.concatI32(event.logIndex.toI32());
const bucketTakeLpAwarded = new BucketTakeLPAwarded(lpAwardedId)
bucketTakeLpAwarded.taker = taker
bucketTakeLpAwarded.pool = addressToBytes(event.address)
bucketTakeLpAwarded.kicker = kicker
bucketTakeLpAwarded.lpAwardedTaker = wadToDecimal(lpAwardedTaker)
bucketTakeLpAwarded.lpAwardedKicker = wadToDecimal(lpAwardedKicker)

bucketTakeLpAwarded.blockNumber = event.block.number
bucketTakeLpAwarded.blockTimestamp = event.block.timestamp
bucketTakeLpAwarded.transactionHash = event.transaction.hash
bucketTakeLpAwarded.save()

// since this is emitted immediately before BucketTakeEvent, create BucketTake entity to associate it with this LP award
const bucketTakeId = event.transaction.hash.concatI32(event.logIndex.toI32() + 1)
const bucketTake = loadOrCreateBucketTake(bucketTakeId)
bucketTake.lpAwarded = lpAwardedId
bucketTake.save()
}

/*******************************/
/*** Reserves Event Handlers ***/
/*******************************/
Expand Down
21 changes: 2 additions & 19 deletions src/mappings/erc-20-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 { _handleAddQuoteToken, _handleApproveLPTransferors, _handleBondWithdrawn, _handleBucketBankruptcy, _handleDecreaseLPAllowance, _handleFlashLoan, _handleIncreaseLPAllowance, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleRevokeLPAllowance, _handleRevokeLPTransferors, _handleTransferLP } from "./base/base-pool"
import { _handleAddQuoteToken, _handleApproveLPTransferors, _handleBondWithdrawn, _handleBucketBankruptcy, _handleBucketTakeLPAwarded, _handleDecreaseLPAllowance, _handleFlashLoan, _handleIncreaseLPAllowance, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleRevokeLPAllowance, _handleRevokeLPTransferors, _handleTransferLP } from "./base/base-pool"


/*******************************/
Expand Down Expand Up @@ -514,24 +514,7 @@ export function handleBucketTake(event: BucketTakeEvent): void {
export function handleBucketTakeLPAwarded(
event: BucketTakeLPAwardedEvent
): void {
const lpAwardedId = event.transaction.hash.concatI32(event.logIndex.toI32());
const bucketTakeLpAwarded = new BucketTakeLPAwarded(lpAwardedId)
bucketTakeLpAwarded.taker = event.params.taker
bucketTakeLpAwarded.pool = addressToBytes(event.address)
bucketTakeLpAwarded.kicker = event.params.kicker
bucketTakeLpAwarded.lpAwardedTaker = wadToDecimal(event.params.lpAwardedTaker)
bucketTakeLpAwarded.lpAwardedKicker = wadToDecimal(event.params.lpAwardedKicker)

bucketTakeLpAwarded.blockNumber = event.block.number
bucketTakeLpAwarded.blockTimestamp = event.block.timestamp
bucketTakeLpAwarded.transactionHash = event.transaction.hash
bucketTakeLpAwarded.save()

// since this is emitted immediately before BucketTakeEvent, create BucketTake entity to associate it with this LP award
const bucketTakeId = event.transaction.hash.concatI32(event.logIndex.toI32() + 1)
const bucketTake = loadOrCreateBucketTake(bucketTakeId)
bucketTake.lpAwarded = lpAwardedId
bucketTake.save()
_handleBucketTakeLPAwarded(event, event.params.kicker, event.params.taker, event.params.lpAwardedKicker, event.params.lpAwardedTaker)
}

export function handleTake(event: TakeEvent): void {
Expand Down
21 changes: 2 additions & 19 deletions src/mappings/erc-721-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { getBorrowerInfoERC721Pool, getLoanId, loadOrCreateLoan, saveOrRemoveLoa
import { getLiquidationAuctionId, loadOrCreateLiquidationAuction, updateLiquidationAuction, getAuctionStatus, loadOrCreateBucketTake, getAuctionInfoERC721Pool } from "../utils/pool/liquidation"
import { updatePool, addLiquidationToPool, getLenderInfoERC721Pool } from "../utils/pool/pool"
import { lpbValueInQuote } from "../utils/pool/lend"
import { _handleAddQuoteToken, _handleApproveLPTransferors, _handleBondWithdrawn, _handleBucketBankruptcy, _handleDecreaseLPAllowance, _handleFlashLoan, _handleIncreaseLPAllowance, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleRevokeLPAllowance, _handleRevokeLPTransferors, _handleTransferLP } from "./base/base-pool"
import { _handleAddQuoteToken, _handleApproveLPTransferors, _handleBondWithdrawn, _handleBucketBankruptcy, _handleBucketTakeLPAwarded, _handleDecreaseLPAllowance, _handleFlashLoan, _handleIncreaseLPAllowance, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleRevokeLPAllowance, _handleRevokeLPTransferors, _handleTransferLP } from "./base/base-pool"


/*******************************/
Expand Down Expand Up @@ -718,24 +718,7 @@ export function handleBucketTake(event: BucketTakeEvent): void {

// identical to ERC20Pool
export function handleBucketTakeLPAwarded(event: BucketTakeLPAwardedEvent): void {
const lpAwardedId = event.transaction.hash.concatI32(event.logIndex.toI32());
const bucketTakeLpAwarded = new BucketTakeLPAwarded(lpAwardedId)
bucketTakeLpAwarded.taker = event.params.taker
bucketTakeLpAwarded.pool = addressToBytes(event.address)
bucketTakeLpAwarded.kicker = event.params.kicker
bucketTakeLpAwarded.lpAwardedTaker = wadToDecimal(event.params.lpAwardedTaker)
bucketTakeLpAwarded.lpAwardedKicker = wadToDecimal(event.params.lpAwardedKicker)

bucketTakeLpAwarded.blockNumber = event.block.number
bucketTakeLpAwarded.blockTimestamp = event.block.timestamp
bucketTakeLpAwarded.transactionHash = event.transaction.hash
bucketTakeLpAwarded.save()

// since this is emitted immediately before BucketTakeEvent, create BucketTake entity to associate it with this LP award
const bucketTakeId = event.transaction.hash.concatI32(event.logIndex.toI32() + 1)
const bucketTake = loadOrCreateBucketTake(bucketTakeId)
bucketTake.lpAwarded = lpAwardedId
bucketTake.save()
_handleBucketTakeLPAwarded(event, event.params.kicker, event.params.taker, event.params.lpAwardedKicker, event.params.lpAwardedTaker)
}

export function handleTake(event: TakeEvent): void {
Expand Down
8 changes: 0 additions & 8 deletions src/utils/pool/lp-allowances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,3 @@ export function saveOrRemoveAllowances(entity: LPAllowanceList): void {
entity.save()
}
}

export function saveOrRemoveTranserors(entity: LPTransferorList): void {
if (entity.transferors.length == 0) {
store.remove('LPTransferorList', entity.id.toHexString())
} else {
entity.save()
}
}

0 comments on commit 1a4aafb

Please sign in to comment.