From 6f2330700b0ee60c380a6894fee7fb029db2f5f1 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 12 Sep 2023 13:17:52 -0400 Subject: [PATCH 1/5] add base methods for lpb management --- src/mappings/base/base-pool.ts | 61 ++++++++++++++++++++ src/mappings/erc-20-pool.ts | 100 +++++++++++++++++---------------- src/mappings/erc-721-pool.ts | 100 +++++++++++++++++---------------- 3 files changed, 165 insertions(+), 96 deletions(-) diff --git a/src/mappings/base/base-pool.ts b/src/mappings/base/base-pool.ts index 865f887..1dfba86 100644 --- a/src/mappings/base/base-pool.ts +++ b/src/mappings/base/base-pool.ts @@ -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 { loadOrCreateTransferors, revokeTransferors } from "../../utils/pool/lp-transferors" /*******************************/ @@ -498,6 +500,65 @@ export function _handleTransferLP(erc20Event: TransferLPERC20Event | null, erc72 transferLP.save() } +/*************************************/ +/*** LPB Management Event Handlers ***/ +/*************************************/ + +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 ***/ /*******************************/ diff --git a/src/mappings/erc-20-pool.ts b/src/mappings/erc-20-pool.ts index c4086da..d28d041 100644 --- a/src/mappings/erc-20-pool.ts +++ b/src/mappings/erc-20-pool.ts @@ -58,7 +58,7 @@ 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, _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( @@ -332,18 +332,19 @@ export function handleBucketTakeLPAwarded( } 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() + // 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() + _handleDecreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) } export function handleDrawDebt(event: DrawDebtEvent): void { @@ -402,18 +403,19 @@ export function handleFlashloan(event: FlashloanEvent): void { } 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() + // 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() + _handleIncreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) } export function handleKick(event: KickEvent): void { @@ -630,34 +632,36 @@ export function handleResetInterestRate(event: ResetInterestRateEvent): void { } 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() + // 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() + _handleRevokeLPAllowance(event, event.params.spender, event.params.indexes) } 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() + // 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() + _handleRevokeLPTransferors(event, event.params.lender, event.params.transferors) } export function handleTake(event: TakeEvent): void { diff --git a/src/mappings/erc-721-pool.ts b/src/mappings/erc-721-pool.ts index 1a60006..cf6358a 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, _handleBucketBankruptcy, _handleFlashLoan, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleTransferLP } from "./base/base-pool" +import { _handleAddQuoteToken, _handleBucketBankruptcy, _handleDecreaseLPAllowance, _handleFlashLoan, _handleIncreaseLPAllowance, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleRevokeLPAllowance, _handleRevokeLPTransferors, _handleTransferLP } from "./base/base-pool" import { decreaseAllowances, increaseAllowances, loadOrCreateAllowances, revokeAllowances } from "../utils/pool/lp-allowances" import { loadOrCreateTransferors, revokeTransferors } from "../utils/pool/lp-transferors" @@ -844,67 +844,71 @@ export function handleTake(event: TakeEvent): void { // identical to ERC20Pool 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() + // 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() + _handleDecreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) } // identical to ERC20Pool 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() + // 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() + _handleIncreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) } // identical to ERC20Pool 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() + // 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() + _handleRevokeLPAllowance(event, event.params.spender, event.params.indexes) } // identical to ERC20Pool 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() + // 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() + _handleRevokeLPTransferors(event, event.params.lender, event.params.transferors) } export function handleTransferLP(event: TransferLPEvent): void { From ea9d65de777ab0c0fef46b282410516c6fe873e1 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 12 Sep 2023 13:33:20 -0400 Subject: [PATCH 2/5] reorg erc20 pool; abstract additional method --- src/mappings/base/base-pool.ts | 15 +++- src/mappings/erc-20-pool.ts | 138 ++++++++++++--------------------- src/mappings/erc-721-pool.ts | 85 +++++--------------- 3 files changed, 84 insertions(+), 154 deletions(-) diff --git a/src/mappings/base/base-pool.ts b/src/mappings/base/base-pool.ts index 1dfba86..94cd2c0 100644 --- a/src/mappings/base/base-pool.ts +++ b/src/mappings/base/base-pool.ts @@ -24,7 +24,7 @@ import { incrementTokenTxCount as incrementTokenTxCountERC721Pool } from "../../ import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "../../utils/pool/reserve-auction" import { saveOrRemovePositionLend } from "../../utils/position" import { decreaseAllowances, increaseAllowances, loadOrCreateAllowances, revokeAllowances } from "../../utils/pool/lp-allowances" -import { loadOrCreateTransferors, revokeTransferors } from "../../utils/pool/lp-transferors" +import { approveTransferors, loadOrCreateTransferors, revokeTransferors } from "../../utils/pool/lp-transferors" /*******************************/ @@ -504,6 +504,19 @@ export function _handleTransferLP(erc20Event: TransferLPERC20Event | null, erc72 /*** 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 diff --git a/src/mappings/erc-20-pool.ts b/src/mappings/erc-20-pool.ts index d28d041..ee32ffd 100644 --- a/src/mappings/erc-20-pool.ts +++ b/src/mappings/erc-20-pool.ts @@ -57,8 +57,7 @@ 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, _handleDecreaseLPAllowance, _handleFlashLoan, _handleIncreaseLPAllowance, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleRevokeLPAllowance, _handleRevokeLPTransferors, _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( @@ -128,16 +127,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 { @@ -331,22 +320,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() - _handleDecreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) -} - export function handleDrawDebt(event: DrawDebtEvent): void { const drawDebt = new DrawDebt( event.transaction.hash.concatI32(event.logIndex.toI32()) @@ -402,22 +375,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() - _handleIncreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) -} - export function handleKick(event: KickEvent): void { const kick = new Kick( event.transaction.hash.concatI32(event.logIndex.toI32()) @@ -619,51 +576,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() - _handleRevokeLPAllowance(event, event.params.spender, event.params.indexes) -} - -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() - _handleRevokeLPTransferors(event, event.params.lender, event.params.transferors) -} - export function handleTake(event: TakeEvent): void { const take = new Take( event.transaction.hash.concatI32(event.logIndex.toI32()) @@ -783,11 +695,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(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) +} diff --git a/src/mappings/erc-721-pool.ts b/src/mappings/erc-721-pool.ts index cf6358a..7a165aa 100644 --- a/src/mappings/erc-721-pool.ts +++ b/src/mappings/erc-721-pool.ts @@ -57,9 +57,6 @@ import { getLiquidationAuctionId, loadOrCreateLiquidationAuction, updateLiquidat import { updatePool, addLiquidationToPool, getLenderInfoERC721Pool } from "../utils/pool/pool" import { lpbValueInQuote } from "../utils/pool/lend" import { _handleAddQuoteToken, _handleBucketBankruptcy, _handleDecreaseLPAllowance, _handleFlashLoan, _handleIncreaseLPAllowance, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleRevokeLPAllowance, _handleRevokeLPTransferors, _handleTransferLP } from "./base/base-pool" -import { decreaseAllowances, increaseAllowances, loadOrCreateAllowances, revokeAllowances } from "../utils/pool/lp-allowances" -import { loadOrCreateTransferors, revokeTransferors } from "../utils/pool/lp-transferors" - /*******************************/ /*** Borrower Event Handlers ***/ @@ -842,54 +839,25 @@ export function handleTake(event: TakeEvent): void { /*** LPB Management Event Handlers ***/ /*************************************/ +// TODO: add to 721 schema +// export function handleApproveLPTransferors( +// event: ApproveLPTransferorsEvent +// ): void { +// _handleApproveLPTransferors(event, event.params.lender, event.params.transferors) +// } + // identical to ERC20Pool 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() _handleDecreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) } // identical to ERC20Pool 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() _handleIncreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) } // identical to ERC20Pool 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() _handleRevokeLPAllowance(event, event.params.spender, event.params.indexes) } @@ -897,17 +865,6 @@ export function handleRevokeLPAllowance(event: RevokeLPAllowanceEvent): void { 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() _handleRevokeLPTransferors(event, event.params.lender, event.params.transferors) } @@ -916,20 +873,6 @@ export function handleTransferLP(event: TransferLPEvent): void { _handleTransferLP(null, event) } -/*******************************/ -/*** Reserves Event Handlers ***/ -/*******************************/ - -// identical to ERC20Pool -export function handleReserveAuctionKick(event: KickReserveAuctionEvent): void { - _handleReserveAuctionKick(event, event.params.currentBurnEpoch, event.params.claimableReservesRemaining, event.params.auctionPrice) -} - -// identical to ERC20Pool -export function handleReserveAuctionTake(event: ReserveAuctionEvent): void { - _handleReserveAuctionTake(event, event.params.currentBurnEpoch, event.params.claimableReservesRemaining, event.params.auctionPrice) -} - /***************************/ /*** Pool Event Handlers ***/ /***************************/ @@ -943,3 +886,17 @@ export function handleResetInterestRate(event: ResetInterestRateEvent): void { export function handleUpdateInterestRate(event: UpdateInterestRateEvent): void { _handleInterestRateEvent(event.address, event, event.params.newRate); } + +/*******************************/ +/*** Reserves Event Handlers ***/ +/*******************************/ + +// identical to ERC20Pool +export function handleReserveAuctionKick(event: KickReserveAuctionEvent): void { + _handleReserveAuctionKick(event, event.params.currentBurnEpoch, event.params.claimableReservesRemaining, event.params.auctionPrice) +} + +// identical to ERC20Pool +export function handleReserveAuctionTake(event: ReserveAuctionEvent): void { + _handleReserveAuctionTake(event, event.params.currentBurnEpoch, event.params.claimableReservesRemaining, event.params.auctionPrice) +} \ No newline at end of file From d02acc0de00adeedf9c64027a48dc14e59b4342f Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 12 Sep 2023 14:15:12 -0400 Subject: [PATCH 3/5] cleanups & add approveTransferors to 721 pool --- src/mappings/erc-20-pool.ts | 3 +-- src/mappings/erc-721-pool.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/mappings/erc-20-pool.ts b/src/mappings/erc-20-pool.ts index ee32ffd..b1f9a0e 100644 --- a/src/mappings/erc-20-pool.ts +++ b/src/mappings/erc-20-pool.ts @@ -1,4 +1,4 @@ -import { BigInt, Bytes, dataSource, log } from "@graphprotocol/graph-ts" +import { log } from "@graphprotocol/graph-ts" import { AddCollateral as AddCollateralEvent, @@ -56,7 +56,6 @@ 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 { _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 { diff --git a/src/mappings/erc-721-pool.ts b/src/mappings/erc-721-pool.ts index 7a165aa..c37aa2e 100644 --- a/src/mappings/erc-721-pool.ts +++ b/src/mappings/erc-721-pool.ts @@ -1,7 +1,8 @@ -import { ByteArray, Bytes, ethereum, log } from "@graphprotocol/graph-ts" +import { ByteArray, Bytes, ethereum } from "@graphprotocol/graph-ts" import { AddCollateralNFT as AddCollateralNFTEvent, AddQuoteToken as AddQuoteTokenEvent, + ApproveLPTransferors as ApproveLPTransferorsEvent, AuctionNFTSettle as AuctionNFTSettleEvent, BucketBankruptcy as BucketBankruptcyEvent, BucketTake as BucketTakeEvent, @@ -56,7 +57,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, _handleBucketBankruptcy, _handleDecreaseLPAllowance, _handleFlashLoan, _handleIncreaseLPAllowance, _handleInterestRateEvent, _handleLoanStamped, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleReserveAuctionKick, _handleReserveAuctionTake, _handleRevokeLPAllowance, _handleRevokeLPTransferors, _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" /*******************************/ /*** Borrower Event Handlers ***/ @@ -839,12 +840,11 @@ export function handleTake(event: TakeEvent): void { /*** LPB Management Event Handlers ***/ /*************************************/ -// TODO: add to 721 schema -// export function handleApproveLPTransferors( -// event: ApproveLPTransferorsEvent -// ): void { -// _handleApproveLPTransferors(event, event.params.lender, event.params.transferors) -// } +export function handleApproveLPTransferors( + event: ApproveLPTransferorsEvent +): void { + _handleApproveLPTransferors(event, event.params.lender, event.params.transferors) +} // identical to ERC20Pool export function handleDecreaseLPAllowance(event: DecreaseLPAllowanceEvent): void { From dfbc52d8c963a6fc8965f85790314c743fb69f1c Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 12 Sep 2023 14:36:11 -0400 Subject: [PATCH 4/5] rename LPAllowances to LPAllowanceList --- schema.graphql | 4 ++-- src/mappings/erc-721-pool.ts | 10 +--------- src/utils/pool/lp-allowances.ts | 16 ++++++++-------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/schema.graphql b/schema.graphql index 335d87b..cfe1bda 100644 --- a/schema.graphql +++ b/schema.graphql @@ -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 diff --git a/src/mappings/erc-721-pool.ts b/src/mappings/erc-721-pool.ts index c37aa2e..383924b 100644 --- a/src/mappings/erc-721-pool.ts +++ b/src/mappings/erc-721-pool.ts @@ -846,22 +846,18 @@ export function handleApproveLPTransferors( _handleApproveLPTransferors(event, event.params.lender, event.params.transferors) } -// identical to ERC20Pool export function handleDecreaseLPAllowance(event: DecreaseLPAllowanceEvent): void { _handleDecreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) } -// identical to ERC20Pool export function handleIncreaseLPAllowance(event: IncreaseLPAllowanceEvent): void { _handleIncreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) } -// identical to ERC20Pool export function handleRevokeLPAllowance(event: RevokeLPAllowanceEvent): void { _handleRevokeLPAllowance(event, event.params.spender, event.params.indexes) } -// identical to ERC20Pool export function handleRevokeLPTransferors( event: RevokeLPTransferorsEvent ): void { @@ -877,12 +873,10 @@ export function handleTransferLP(event: TransferLPEvent): void { /*** Pool Event Handlers ***/ /***************************/ -// identical to ERC20Pool export function handleResetInterestRate(event: ResetInterestRateEvent): void { _handleInterestRateEvent(event.address, event, event.params.newRate); } -// identical to ERC20Pool export function handleUpdateInterestRate(event: UpdateInterestRateEvent): void { _handleInterestRateEvent(event.address, event, event.params.newRate); } @@ -891,12 +885,10 @@ export function handleUpdateInterestRate(event: UpdateInterestRateEvent): void { /*** Reserves Event Handlers ***/ /*******************************/ -// identical to ERC20Pool export function handleReserveAuctionKick(event: KickReserveAuctionEvent): void { _handleReserveAuctionKick(event, event.params.currentBurnEpoch, event.params.claimableReservesRemaining, event.params.auctionPrice) } -// identical to ERC20Pool export function handleReserveAuctionTake(event: ReserveAuctionEvent): void { _handleReserveAuctionTake(event, event.params.currentBurnEpoch, event.params.claimableReservesRemaining, event.params.auctionPrice) -} \ No newline at end of file +} diff --git a/src/utils/pool/lp-allowances.ts b/src/utils/pool/lp-allowances.ts index b6c47b2..5b12bed 100644 --- a/src/utils/pool/lp-allowances.ts +++ b/src/utils/pool/lp-allowances.ts @@ -1,5 +1,5 @@ -import { Address, BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts" -import { LPAllowance, LPAllowances } from "../../../generated/schema"; +import { BigInt, Bytes } from "@graphprotocol/graph-ts" +import { LPAllowance, LPAllowanceList } from "../../../generated/schema"; import { wadToDecimal } from "../convert"; export function getAllowancesId(poolId: Bytes, lenderId: Bytes, spenderId: Bytes): Bytes { @@ -10,11 +10,11 @@ export function getAllowanceId(allowancesId: Bytes, index: BigInt): Bytes { return allowancesId.concat(Bytes.fromUTF8('|' + index.toString())) } -export function loadOrCreateAllowances(poolId: Bytes, lenderId: Bytes, spenderId: Bytes): LPAllowances { +export function loadOrCreateAllowances(poolId: Bytes, lenderId: Bytes, spenderId: Bytes): LPAllowanceList { let id = getAllowancesId(poolId, lenderId, spenderId) - let entity = LPAllowances.load(id) + let entity = LPAllowanceList.load(id) if (entity == null) { - entity = new LPAllowances(id) as LPAllowances + entity = new LPAllowanceList(id) as LPAllowanceList entity.pool = poolId entity.lender = lenderId entity.spender = spenderId @@ -23,7 +23,7 @@ export function loadOrCreateAllowances(poolId: Bytes, lenderId: Bytes, spenderId return entity; } -export function increaseAllowances(entity: LPAllowances, indexes: Array, amounts: Array): void { +export function increaseAllowances(entity: LPAllowanceList, indexes: Array, amounts: Array): void { const id = entity.id; const entityAllowances = entity.allowances; for (var i=0; i, entity.allowances = entityAllowances } -export function decreaseAllowances(entity: LPAllowances, indexes: Array, amounts: Array): void { +export function decreaseAllowances(entity: LPAllowanceList, indexes: Array, amounts: Array): void { const id = entity.id; const entityAllowances = entity.allowances; for (var i=0; i, entity.allowances = entityAllowances } -export function revokeAllowances(entity: LPAllowances, indexes: Array): void { +export function revokeAllowances(entity: LPAllowanceList, indexes: Array): void { const id = entity.id; const entityAllowances = entity.allowances; for (var i=0; i Date: Tue, 12 Sep 2023 16:11:10 -0400 Subject: [PATCH 5/5] remove rewards manager --- networks.json | 20 ----- schema.graphql | 87 ------------------ src/mappings/rewards-manager.ts | 97 --------------------- subgraph.yaml | 35 -------- tests/rewards-manager.test.ts | 80 ----------------- tests/utils/rewards-manager-utils.ts | 126 --------------------------- 6 files changed, 445 deletions(-) delete mode 100644 src/mappings/rewards-manager.ts delete mode 100644 tests/rewards-manager.test.ts delete mode 100644 tests/utils/rewards-manager-utils.ts diff --git a/networks.json b/networks.json index 1caa143..3db6a57 100644 --- a/networks.json +++ b/networks.json @@ -12,10 +12,6 @@ "address": "0x0000000000000000000000000000000000000000", "startBlock": 17622995 }, - "RewardsManager": { - "address": "0x0000000000000000000000000000000000000000", - "startBlock": 17622995 - }, "GrantFund": { "address": "0x0000000000000000000000000000000000000000", "startBlock": 17622995 @@ -42,10 +38,6 @@ "address": "0x0000000000000000000000000000000000000000", "startBlock": 46312499 }, - "RewardsManager": { - "address": "0x0000000000000000000000000000000000000000", - "startBlock": 46312499 - }, "GrantFund": { "address": "0x0000000000000000000000000000000000000000", "startBlock": 46312499 @@ -72,10 +64,6 @@ "address": "0x23E2EFF19bd50BfCF0364B7dCA01004D5cce41f9", "startBlock": 9289397 }, - "RewardsManager": { - "address": "0x994dE190dd763Af3126FcC8EdC139275937d800b", - "startBlock": 9289397 - }, "GrantFund": { "address": "0x881b4dFF6C72babA6f5eA60f34A61410c1EA1ec2", "startBlock": 9297080 @@ -102,10 +90,6 @@ "address": "0x0000000000000000000000000000000000000000", "startBlock": 38580888 }, - "RewardsManager": { - "address": "0x0000000000000000000000000000000000000000", - "startBlock": 38580888 - }, "GrantFund": { "address": "0x0000000000000000000000000000000000000000", "startBlock": 38580888 @@ -132,10 +116,6 @@ "address": "0x6548dF23A854f72335902e58a1e59B50bb3f11F1", "startBlock": 0 }, - "RewardsManager": { - "address": "0xdF7403003a16c49ebA5883bB5890d474794cea5a", - "startBlock": 0 - }, "GrantFund": { "address": "0x0b3A0ea1Fc7207d3e3ed9973025dA9d0e8fb0F3f", "startBlock": 0 diff --git a/schema.graphql b/schema.graphql index cfe1bda..1613cf3 100644 --- a/schema.graphql +++ b/schema.graphql @@ -777,93 +777,6 @@ type RedeemPosition @entity(immutable: true) { transactionHash: Bytes! } - # # # # # # # # # # # # # # # - # REWARDS MANAGER ENTITIES # - # # # # # # # # # # # # # # # - -type StakedPosition @entity { - id: Bytes! # byte encoded tokenId - position: Position! # pointer to associated Position entity - epochs: [EpochReward!]! # list of EpochRewards associated to a staked position - stakedEpoch: Int! # epoch in which the position was staked - lastClaimedEpoch: Int! # last epoch which the position staked or claimed rewards in - # lpAtStakeTime: BigDecimal! # the amount of LPB associated with a given index TODO: store information per index? - # rateAtStakeTime: BigDecimal! # the exchange rate at a given index at stake time -} - -type EpochReward @entity { - id: Bytes! # byte encoded epoch + '|' + $StakedPosition.id - rewardsClaimed: BigDecimal! # ajna tokens claimed in this epoch - updateRewardsClaimed: BigDecimal! - totalRewardsClaimed: BigDecimal! -} - -# TODO: is this entity necessary? if so referenced by index in stakedposition list -# house state tracking information about a staked position in a single bucket index -type StakedLiquidity @entity { - id: Bytes! # $lendId + '|' + $StakedPosition.id - lpAtStakeTime: BigDecimal! # the amount of LPB associated with a given index - rateAtStakeTime: BigDecimal! # the exchange rate at a given index at stake time -} - - # # # # # # # # # # # # # # - # REWARDS MANAGER EVENTS # - # # # # # # # # # # # # # # - -type ClaimRewards @entity(immutable: true) { - id: Bytes! - owner: Bytes! # address - pool: Pool! - tokenId: BigInt! # uint256 - epochsClaimed: [BigInt!]! # uint256[] - amount: BigDecimal! # uint256 - blockNumber: BigInt! - blockTimestamp: BigInt! - transactionHash: Bytes! -} - -type MoveStakedLiquidity @entity(immutable: true) { - id: Bytes! - tokenId: BigInt! # uint256 - pool: Pool! - fromIndexes: [Int!]! # uint256 - toIndexes: [Int!]! # uint256 - blockNumber: BigInt! - blockTimestamp: BigInt! - transactionHash: Bytes! -} - -type Stake @entity(immutable: true) { - id: Bytes! - owner: Bytes! # address - pool: Pool! - tokenId: BigInt! # uint256 - blockNumber: BigInt! - blockTimestamp: BigInt! - transactionHash: Bytes! -} - -type Unstake @entity(immutable: true) { - id: Bytes! - owner: Bytes! # address - pool: Pool! - tokenId: BigInt! # uint256 - blockNumber: BigInt! - blockTimestamp: BigInt! - transactionHash: Bytes! -} - -type UpdateExchangeRates @entity(immutable: true) { - id: Bytes! - caller: Bytes! # address - pool: Pool! - indexesUpdated: [BigInt!]! # uint256[] - rewardsClaimed: BigInt! # uint256 - blockNumber: BigInt! - blockTimestamp: BigInt! - transactionHash: Bytes! -} - # # # # # # # # # # # # # GRANT FUND ENTITIES # # # # # # # # # # # # # diff --git a/src/mappings/rewards-manager.ts b/src/mappings/rewards-manager.ts deleted file mode 100644 index 01a0710..0000000 --- a/src/mappings/rewards-manager.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { - ClaimRewards as ClaimRewardsEvent, - MoveStakedLiquidity as MoveStakedLiquidityEvent, - Stake as StakeEvent, - Unstake as UnstakeEvent, - UpdateExchangeRates as UpdateExchangeRatesEvent -} from "../../generated/RewardsManager/RewardsManager" -import { - ClaimRewards, - MoveStakedLiquidity, - Stake, - Unstake, - UpdateExchangeRates -} from "../../generated/schema" -import { bigIntArrayToIntArray, wadToDecimal } from "../utils/convert" -import { getPoolForToken } from "../utils/position" - -export function handleClaimRewards(event: ClaimRewardsEvent): void { - let entity = new ClaimRewards( - event.transaction.hash.concatI32(event.logIndex.toI32()) - ) - entity.owner = event.params.owner - entity.pool = event.params.ajnaPool - entity.tokenId = event.params.tokenId - entity.epochsClaimed = event.params.epochsClaimed - entity.amount = wadToDecimal(event.params.amount) - - entity.blockNumber = event.block.number - entity.blockTimestamp = event.block.timestamp - entity.transactionHash = event.transaction.hash - - entity.save() -} - -export function handleMoveStakedLiquidity(event: MoveStakedLiquidityEvent): void { - let entity = new MoveStakedLiquidity( - event.transaction.hash.concatI32(event.logIndex.toI32()) - ) - entity.tokenId = event.params.tokenId - entity.pool = getPoolForToken(entity.tokenId) - entity.fromIndexes = bigIntArrayToIntArray(event.params.fromIndexes) - entity.toIndexes = bigIntArrayToIntArray(event.params.toIndexes) - - entity.blockNumber = event.block.number - entity.blockTimestamp = event.block.timestamp - entity.transactionHash = event.transaction.hash - - entity.save() -} - -export function handleStake(event: StakeEvent): void { - let entity = new Stake( - event.transaction.hash.concatI32(event.logIndex.toI32()) - ) - entity.owner = event.params.owner - entity.pool = event.params.ajnaPool - entity.tokenId = event.params.tokenId - - entity.blockNumber = event.block.number - entity.blockTimestamp = event.block.timestamp - entity.transactionHash = event.transaction.hash - - entity.save() -} - -export function handleUnstake(event: UnstakeEvent): void { - let entity = new Unstake( - event.transaction.hash.concatI32(event.logIndex.toI32()) - ) - entity.owner = event.params.owner - entity.pool = event.params.ajnaPool - entity.tokenId = event.params.tokenId - - entity.blockNumber = event.block.number - entity.blockTimestamp = event.block.timestamp - entity.transactionHash = event.transaction.hash - - entity.save() -} - -export function handleUpdateExchangeRates( - event: UpdateExchangeRatesEvent -): void { - let entity = new UpdateExchangeRates( - event.transaction.hash.concatI32(event.logIndex.toI32()) - ) - entity.caller = event.params.caller - entity.pool = event.params.ajnaPool - entity.indexesUpdated = event.params.indexesUpdated - entity.rewardsClaimed = event.params.rewardsClaimed - - entity.blockNumber = event.block.number - entity.blockTimestamp = event.block.timestamp - entity.transactionHash = event.transaction.hash - - entity.save() -} diff --git a/subgraph.yaml b/subgraph.yaml index 285e943..02d7d08 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -73,41 +73,6 @@ dataSources: handler: handlePoolCreated file: ./src/mappings/erc-20-pool-factory.ts network: goerli - - kind: ethereum - name: RewardsManager - source: - abi: RewardsManager - address: "0x994dE190dd763Af3126FcC8EdC139275937d800b" - startBlock: 9289397 - mapping: - kind: ethereum/events - apiVersion: 0.0.7 - language: wasm/assemblyscript - entities: - - ClaimRewards - - MoveStakedLiquidity - - Stake - - Unstake - - UpdateExchangeRates - abis: - - name: RewardsManager - file: ./abis/RewardsManager.json - - name: PositionManager - file: ./abis/PositionManager.json - eventHandlers: - - event: ClaimRewards(indexed address,indexed address,indexed - uint256,uint256[],uint256) - handler: handleClaimRewards - - event: MoveStakedLiquidity(uint256,uint256[],uint256[]) - handler: handleMoveStakedLiquidity - - event: Stake(indexed address,indexed address,indexed uint256) - handler: handleStake - - event: Unstake(indexed address,indexed address,indexed uint256) - handler: handleUnstake - - event: UpdateExchangeRates(indexed address,indexed address,uint256[],uint256) - handler: handleUpdateExchangeRates - file: ./src/mappings/rewards-manager.ts - network: goerli - kind: ethereum name: ERC721PoolFactory source: diff --git a/tests/rewards-manager.test.ts b/tests/rewards-manager.test.ts deleted file mode 100644 index 964571a..0000000 --- a/tests/rewards-manager.test.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { - assert, - describe, - test, - clearStore, - beforeAll, - afterAll -} from "matchstick-as/assembly/index" -import { Address, BigInt } from "@graphprotocol/graph-ts" -import { handleClaimRewards } from "../src/mappings/rewards-manager" -import { createClaimRewardsEvent } from "./utils/rewards-manager-utils" - -// Tests structure (matchstick-as >=0.5.0) -// https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0 - -describe("Describe entity assertions", () => { - beforeAll(() => { - let owner = Address.fromString("0x0000000000000000000000000000000000000001") - let ajnaPool = Address.fromString( - "0x0000000000000000000000000000000000000001" - ) - let tokenId = BigInt.fromI32(234) - let epochsClaimed = [BigInt.fromI32(234)] - let amount = BigInt.fromString("234000000000000000000") // 234 * 1e18 - let newClaimRewardsEvent = createClaimRewardsEvent( - owner, - ajnaPool, - tokenId, - epochsClaimed, - amount - ) - handleClaimRewards(newClaimRewardsEvent) - }) - - afterAll(() => { - clearStore() - }) - - // For more test scenarios, see: - // https://thegraph.com/docs/en/developer/matchstick/#write-a-unit-test - - test("ClaimRewards created and stored", () => { - assert.entityCount("ClaimRewards", 1) - - // 0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000 is the default address used in newMockEvent() function - assert.fieldEquals( - "ClaimRewards", - "0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000", - "owner", - "0x0000000000000000000000000000000000000001" - ) - assert.fieldEquals( - "ClaimRewards", - "0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000", - "pool", - "0x0000000000000000000000000000000000000001" - ) - assert.fieldEquals( - "ClaimRewards", - "0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000", - "tokenId", - "234" - ) - assert.fieldEquals( - "ClaimRewards", - "0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000", - "epochsClaimed", - "[234]" - ) - assert.fieldEquals( - "ClaimRewards", - "0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000", - "amount", - "234" - ) - - // More assert options: - // https://thegraph.com/docs/en/developer/matchstick/#asserts - }) -}) diff --git a/tests/utils/rewards-manager-utils.ts b/tests/utils/rewards-manager-utils.ts deleted file mode 100644 index cc2f8f3..0000000 --- a/tests/utils/rewards-manager-utils.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { newMockEvent } from "matchstick-as" -import { ethereum, Address, BigInt } from "@graphprotocol/graph-ts" -import { - ClaimRewards, - Stake, - Unstake, - UpdateExchangeRates -} from "../../generated/RewardsManager/RewardsManager" - -export function createClaimRewardsEvent( - owner: Address, - ajnaPool: Address, - tokenId: BigInt, - epochsClaimed: Array, - amount: BigInt -): ClaimRewards { - let claimRewardsEvent = changetype(newMockEvent()) - - claimRewardsEvent.parameters = new Array() - - claimRewardsEvent.parameters.push( - new ethereum.EventParam("owner", ethereum.Value.fromAddress(owner)) - ) - claimRewardsEvent.parameters.push( - new ethereum.EventParam("ajnaPool", ethereum.Value.fromAddress(ajnaPool)) - ) - claimRewardsEvent.parameters.push( - new ethereum.EventParam( - "tokenId", - ethereum.Value.fromUnsignedBigInt(tokenId) - ) - ) - claimRewardsEvent.parameters.push( - new ethereum.EventParam( - "epochsClaimed", - ethereum.Value.fromUnsignedBigIntArray(epochsClaimed) - ) - ) - claimRewardsEvent.parameters.push( - new ethereum.EventParam("amount", ethereum.Value.fromUnsignedBigInt(amount)) - ) - - return claimRewardsEvent -} - -export function createStakeEvent( - owner: Address, - ajnaPool: Address, - tokenId: BigInt -): Stake { - let stakeEvent = changetype(newMockEvent()) - - stakeEvent.parameters = new Array() - - stakeEvent.parameters.push( - new ethereum.EventParam("owner", ethereum.Value.fromAddress(owner)) - ) - stakeEvent.parameters.push( - new ethereum.EventParam("ajnaPool", ethereum.Value.fromAddress(ajnaPool)) - ) - stakeEvent.parameters.push( - new ethereum.EventParam( - "tokenId", - ethereum.Value.fromUnsignedBigInt(tokenId) - ) - ) - - return stakeEvent -} - -export function createUnstakeEvent( - owner: Address, - ajnaPool: Address, - tokenId: BigInt -): Unstake { - let unstakeEvent = changetype(newMockEvent()) - - unstakeEvent.parameters = new Array() - - unstakeEvent.parameters.push( - new ethereum.EventParam("owner", ethereum.Value.fromAddress(owner)) - ) - unstakeEvent.parameters.push( - new ethereum.EventParam("ajnaPool", ethereum.Value.fromAddress(ajnaPool)) - ) - unstakeEvent.parameters.push( - new ethereum.EventParam( - "tokenId", - ethereum.Value.fromUnsignedBigInt(tokenId) - ) - ) - - return unstakeEvent -} - -export function createUpdateExchangeRatesEvent( - caller: Address, - ajnaPool: Address, - indexesUpdated: Array, - rewardsClaimed: BigInt -): UpdateExchangeRates { - let updateExchangeRatesEvent = changetype(newMockEvent()) - - updateExchangeRatesEvent.parameters = new Array() - - updateExchangeRatesEvent.parameters.push( - new ethereum.EventParam("caller", ethereum.Value.fromAddress(caller)) - ) - updateExchangeRatesEvent.parameters.push( - new ethereum.EventParam("ajnaPool", ethereum.Value.fromAddress(ajnaPool)) - ) - updateExchangeRatesEvent.parameters.push( - new ethereum.EventParam( - "indexesUpdated", - ethereum.Value.fromUnsignedBigIntArray(indexesUpdated) - ) - ) - updateExchangeRatesEvent.parameters.push( - new ethereum.EventParam( - "rewardsClaimed", - ethereum.Value.fromUnsignedBigInt(rewardsClaimed) - ) - ) - - return updateExchangeRatesEvent -}