From 1a4aafb44e2f2ad84aabb17755ea32413ddbdd63 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 19 Sep 2023 14:02:40 -0400 Subject: [PATCH] add shared _handleBucketTakeLPAwarded handler --- src/mappings/base/base-pool.ts | 25 ++++++++++++++++++++++++- src/mappings/erc-20-pool.ts | 21 ++------------------- src/mappings/erc-721-pool.ts | 21 ++------------------- src/utils/pool/lp-allowances.ts | 8 -------- 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/mappings/base/base-pool.ts b/src/mappings/base/base-pool.ts index 4aff0fc..d14adba 100644 --- a/src/mappings/base/base-pool.ts +++ b/src/mappings/base/base-pool.ts @@ -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, @@ -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" /*******************************/ @@ -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 ***/ /*******************************/ diff --git a/src/mappings/erc-20-pool.ts b/src/mappings/erc-20-pool.ts index df9b045..1ce54e7 100644 --- a/src/mappings/erc-20-pool.ts +++ b/src/mappings/erc-20-pool.ts @@ -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" /*******************************/ @@ -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 { diff --git a/src/mappings/erc-721-pool.ts b/src/mappings/erc-721-pool.ts index 8f6514b..77f91cb 100644 --- a/src/mappings/erc-721-pool.ts +++ b/src/mappings/erc-721-pool.ts @@ -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" /*******************************/ @@ -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 { diff --git a/src/utils/pool/lp-allowances.ts b/src/utils/pool/lp-allowances.ts index fba2b91..2cde22f 100644 --- a/src/utils/pool/lp-allowances.ts +++ b/src/utils/pool/lp-allowances.ts @@ -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() - } -} \ No newline at end of file