From f0727d858db662f37a0f0c9ab6b26b1368eca35f Mon Sep 17 00:00:00 2001 From: Mike Hathaway Date: Wed, 20 Sep 2023 10:05:34 -0400 Subject: [PATCH] Test and Update Allowances and Transferors (#71) * add base methods for lpb management * reorg erc20 pool; abstract additional method * reorganize erc20-pool * add _handleBondWithdrawn * wip allowances test * fix issues with allowance mappings * fix revokeAllowances; expand tests * remove stale approval lists * add shared _handleBucketTakeLPAwarded handler * remove comments --------- Co-authored-by: Mike --- src/mappings/base/base-pool.ts | 68 ++++++++----- src/mappings/erc-20-pool.ts | 27 +----- src/mappings/erc-721-pool.ts | 31 +----- src/utils/pool/lp-allowances.ts | 24 ++++- src/utils/pool/lp-transferors.ts | 17 +++- tests/erc-721-pool.test.ts | 127 +++++++++++++++++++++++- tests/utils/erc-721-pool-utils.ts | 154 ++++++++++++++++++++++++++++++ 7 files changed, 367 insertions(+), 81 deletions(-) diff --git a/src/mappings/base/base-pool.ts b/src/mappings/base/base-pool.ts index a9194cb..edcf82b 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, @@ -23,8 +23,9 @@ 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" +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" /*******************************/ @@ -506,70 +507,67 @@ export function _handleTransferLP(erc20Event: TransferLPERC20Event | null, erc72 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 lpTransferorList = loadOrCreateTransferors(poolId, addressToBytes(lender)) + approveTransferors(lpTransferorList, transferors) const pool = Pool.load(poolId)! pool.txCount = pool.txCount.plus(ONE_BI) // save entities to the store pool.save() - entity.save() + lpTransferorList.save() } -export function _handleDecreaseLPAllowance(event: ethereum.Event, spender: Address, indexes: BigInt[], amounts: BigInt[]): void { +export function _handleDecreaseLPAllowance(event: ethereum.Event, owner: Address, 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 lpAllowanceList = loadOrCreateAllowances(poolId, addressToBytes(owner), addressToBytes(spender)) + decreaseAllowances(lpAllowanceList, indexes, amounts) const pool = Pool.load(poolId)! pool.txCount = pool.txCount.plus(ONE_BI) // save entities to the store pool.save() - entity.save() + saveOrRemoveAllowances(lpAllowanceList) } -export function _handleIncreaseLPAllowance(event: ethereum.Event, spender: Address, indexes: BigInt[], amounts: BigInt[]): void { +export function _handleIncreaseLPAllowance(event: ethereum.Event, owner: Address, 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 lpAllowanceList = loadOrCreateAllowances(poolId, addressToBytes(owner), addressToBytes(spender)) + increaseAllowances(lpAllowanceList, indexes, amounts) const pool = Pool.load(poolId)! pool.txCount = pool.txCount.plus(ONE_BI) // save entities to the store pool.save() - entity.save() + lpAllowanceList.save() } -export function _handleRevokeLPAllowance(event: ethereum.Event, spender: Address, indexes: BigInt[]): void { +export function _handleRevokeLPAllowance(event: ethereum.Event, owner: Address, 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 lpAllowanceList = loadOrCreateAllowances(poolId, owner, spender) + revokeAllowances(lpAllowanceList, indexes) const pool = Pool.load(poolId)! pool.txCount = pool.txCount.plus(ONE_BI) // save entities to the store pool.save() - entity.save() + saveOrRemoveAllowances(lpAllowanceList) } 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 lpTransferorList = loadOrCreateTransferors(poolId, lender) + revokeTransferors(lpTransferorList, transferors) const pool = Pool.load(poolId)! pool.txCount = pool.txCount.plus(ONE_BI) // save entities to the store pool.save() - entity.save() + saveOrRemoveTranserors(lpTransferorList) } /**********************************/ @@ -591,6 +589,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 00b490d..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 { @@ -704,15 +687,15 @@ export function handleApproveLPTransferors( } export function handleDecreaseLPAllowance(event: DecreaseLPAllowanceEvent): void { - _handleDecreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) + _handleDecreaseLPAllowance(event, event.params.owner, 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) + _handleIncreaseLPAllowance(event, event.params.owner, event.params.spender, event.params.indexes, event.params.amounts) } export function handleRevokeLPAllowance(event: RevokeLPAllowanceEvent): void { - _handleRevokeLPAllowance(event, event.params.spender, event.params.indexes) + _handleRevokeLPAllowance(event, event.params.owner, event.params.spender, event.params.indexes) } export function handleRevokeLPTransferors( diff --git a/src/mappings/erc-721-pool.ts b/src/mappings/erc-721-pool.ts index 8d4a332..ab2ec73 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" /*******************************/ @@ -161,12 +161,10 @@ export function handleRepayDebt(event: RepayDebtEvent): void { repayDebt.save() } -// identical to ERC20Pool export function handleFlashloan(event: FlashloanEvent): void { _handleFlashLoan(event, event.params.token, event.params.receiver, event.params.amount) } -// identical to ERC20Pool export function handleLoanStamped(event: LoanStampedEvent): void { _handleLoanStamped(event, event.params.borrower) } @@ -524,7 +522,6 @@ export function handleSettle(event: SettleEvent): void { settle.save() } -// TODO: can this be abstracted? export function handleKick(event: KickEvent): void { const kick = new Kick( event.transaction.hash.concatI32(event.logIndex.toI32()) @@ -716,26 +713,8 @@ export function handleBucketTake(event: BucketTakeEvent): void { takerLend.save() } -// 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 { @@ -834,15 +813,15 @@ export function handleApproveLPTransferors( } export function handleDecreaseLPAllowance(event: DecreaseLPAllowanceEvent): void { - _handleDecreaseLPAllowance(event, event.params.spender, event.params.indexes, event.params.amounts) + _handleDecreaseLPAllowance(event, event.params.owner, 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) + _handleIncreaseLPAllowance(event, event.params.owner, event.params.spender, event.params.indexes, event.params.amounts) } export function handleRevokeLPAllowance(event: RevokeLPAllowanceEvent): void { - _handleRevokeLPAllowance(event, event.params.spender, event.params.indexes) + _handleRevokeLPAllowance(event, event.params.owner, event.params.spender, event.params.indexes) } export function handleRevokeLPTransferors( diff --git a/src/utils/pool/lp-allowances.ts b/src/utils/pool/lp-allowances.ts index 5b12bed..2cde22f 100644 --- a/src/utils/pool/lp-allowances.ts +++ b/src/utils/pool/lp-allowances.ts @@ -1,4 +1,4 @@ -import { BigInt, Bytes } from "@graphprotocol/graph-ts" +import { BigInt, Bytes, store } from "@graphprotocol/graph-ts" import { LPAllowance, LPAllowanceList } from "../../../generated/schema"; import { wadToDecimal } from "../convert"; @@ -27,17 +27,20 @@ export function increaseAllowances(entity: LPAllowanceList, indexes: Array const indexToRemove = entityAllowances.indexOf(aid) if (indexToRemove != -1) entityAllowances.splice(indexToRemove, 1) + + // remove allowance from the store + store.remove('LPAllowance', aid.toHexString()) } } entity.allowances = entityAllowances -} \ No newline at end of file +} + +export function saveOrRemoveAllowances(entity: LPAllowanceList): void { + if (entity.allowances.length == 0) { + store.remove('LPAllowanceList', entity.id.toHexString()) + } else { + entity.save() + } +} diff --git a/src/utils/pool/lp-transferors.ts b/src/utils/pool/lp-transferors.ts index bf9aa9b..f2f9e44 100644 --- a/src/utils/pool/lp-transferors.ts +++ b/src/utils/pool/lp-transferors.ts @@ -1,5 +1,6 @@ -import { Address, Bytes } from "@graphprotocol/graph-ts" -import { LPTransferorList, Pool } from "../../../generated/schema"; +import { Address, Bytes, store } from "@graphprotocol/graph-ts" +import { LPTransferorList} from "../../../generated/schema"; +import { addressToBytes } from "../convert"; export function getTransferorId(poolId: Bytes, lenderId: Bytes): Bytes { return poolId.concat(Bytes.fromUTF8('|' + lenderId.toString())); @@ -21,7 +22,7 @@ export function approveTransferors(entity: LPTransferorList, transferorsApproved // iterate through newly-approved transferors, pushing each transfer if not already there const entityTransferors = entity.transferors for (var i=0; i=0.5.0) // https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0 @@ -1510,6 +1512,127 @@ describe("Describe entity assertions", () => { } }) + test("LPB Allowance and Transferors", () => { + const poolAddress = Address.fromString("0x0000000000000000000000000000000000000001") + const expectedPoolAddress = addressToBytes(poolAddress) + const lender = Address.fromString("0x0000000000000000000000000000000000000003") + const spender = Address.fromString("0x0000000000000000000000000000000000000005") + const transferors = [Address.fromString("0x0000000000000000000000000000000000000005")] + const indexes = [BigInt.fromI32(234), BigInt.fromI32(345), BigInt.fromI32(456), BigInt.fromI32(567), BigInt.fromI32(789)] + let amounts = [BigInt.fromI32(1000), BigInt.fromI32(1000), BigInt.fromI32(1000), BigInt.fromI32(1000), BigInt.fromI32(1000)] + const expectedLenderAddress = addressToBytes(lender) + const expectedSpenderAddress = addressToBytes(spender) + + /******************************************/ + /*** Approve Transferors and Allowances ***/ + /******************************************/ + + // _handleApproveLPTransferors + const newApproveLPTransferorsEvent = createApproveLPTransferorsEvent(poolAddress, lender, transferors) + handleApproveLPTransferors(newApproveLPTransferorsEvent) + + // _handleIncreaseLPAllowance + const newIncreaseLPAllowanceEvent = createIncreaseLPAllowanceEvent(poolAddress, lender, spender, indexes, amounts) + handleIncreaseLPAllowance(newIncreaseLPAllowanceEvent) + + // _handleDecreaseLPAllowance + // cut the allowance in half for each bucket index + amounts = [BigInt.fromI32(500), BigInt.fromI32(500), BigInt.fromI32(500), BigInt.fromI32(500), BigInt.fromI32(500)] + const newDecreaseLPAllowanceEvent = createDecreaseLPAllowanceEvent(poolAddress, lender, spender, indexes, amounts) + handleDecreaseLPAllowance(newDecreaseLPAllowanceEvent) + + /********************/ + /*** Assert State ***/ + /********************/ + + // check entities have been stored + assert.entityCount("LPTransferorList", 1) + assert.entityCount("LPAllowance", 5) + assert.entityCount("LPAllowanceList", 1) + assert.entityCount("Pool", 2) + + // check LPTransferorList state + const lpTransferorListId = getTransferorId(expectedPoolAddress, expectedLenderAddress) + assert.fieldEquals( + "LPTransferorList", + `${lpTransferorListId.toHexString()}`, + "pool", + `${expectedPoolAddress.toHexString()}` + ) + assert.fieldEquals( + "LPTransferorList", + `${lpTransferorListId.toHexString()}`, + "lender", + `${lender.toHexString()}` + ) + assert.fieldEquals( + "LPTransferorList", + `${lpTransferorListId.toHexString()}`, + "transferors", + "[0x0000000000000000000000000000000000000005]" + ) + + // check LPAllowanceList state + const lpAllowanceListId = getAllowancesId(expectedPoolAddress, expectedLenderAddress, expectedSpenderAddress) + assert.fieldEquals( + "LPAllowanceList", + `${lpAllowanceListId.toHexString()}`, + "pool", + `${expectedPoolAddress.toHexString()}` + ) + assert.fieldEquals( + "LPAllowanceList", + `${lpAllowanceListId.toHexString()}`, + "lender", + `${lender.toHexString()}` + ) + assert.fieldEquals( + "LPAllowanceList", + `${lpAllowanceListId.toHexString()}`, + "spender", + `${spender.toHexString()}` + ) + + // check each LPAllowance entities state + for (let i = 0; i < indexes.length; i++) { + const allowanceId = getAllowanceId(lpAllowanceListId, indexes[i]) + assert.fieldEquals( + "LPAllowance", + `${allowanceId.toHexString()}`, + "index", + `${indexes[i]}` + ) + assert.fieldEquals( + "LPAllowance", + `${allowanceId.toHexString()}`, + "amount", + `${wadToDecimal(BigInt.fromI32(500))}` + ) + } + + /************************/ + /*** Revoke Approvals ***/ + /************************/ + + // _handleRevokeLPAllowance + const newRevokedLPAllowanceEvent = createRevokeLPAllowanceEvent(poolAddress, lender, spender, indexes) + handleRevokeLPAllowance(newRevokedLPAllowanceEvent) + + // _handleRevokeLPTransferors + const newRevokedLPTransferorsEvent = createRevokeLPTransferorsEvent(poolAddress, lender, transferors) + handleRevokeLPTransferors(newRevokedLPTransferorsEvent) + + /********************/ + /*** Assert State ***/ + /********************/ + + // check entities have been stored + assert.entityCount("LPTransferorList", 0) + assert.entityCount("LPAllowance", 0) + assert.entityCount("LPAllowanceList", 0) + assert.entityCount("Pool", 2) + }) + // TODO: finish implementing once a mergeOrRemoveCollateralNFT calldata becomes available test("MergeOrRemoveCollateralNFT", () => { // check entity is unavailable prior to storage diff --git a/tests/utils/erc-721-pool-utils.ts b/tests/utils/erc-721-pool-utils.ts index 7b14d09..851fa3e 100644 --- a/tests/utils/erc-721-pool-utils.ts +++ b/tests/utils/erc-721-pool-utils.ts @@ -3,17 +3,22 @@ import { ethereum, Address, BigInt, Bytes } from "@graphprotocol/graph-ts" import { AddCollateralNFT, AddQuoteToken, + ApproveLPTransferors, AuctionNFTSettle, BucketBankruptcy, BucketTake, BucketTakeLPAwarded, + DecreaseLPAllowance, DrawDebtNFT, Flashloan, + IncreaseLPAllowance, Kick, KickReserveAuction, MergeOrRemoveCollateralNFT, RemoveCollateral, RepayDebt, + RevokeLPAllowance, + RevokeLPTransferors, ReserveAuction, Settle, Take, @@ -128,6 +133,155 @@ export function createAuctionNFTSettleEvent( return auctionNftSettleEvent } +export function createApproveLPTransferorsEvent( + pool: Address, + lender: Address, + transferors: Array
+): ApproveLPTransferors { + let approveLPTransferorsEvent = changetype(newMockEvent()) + + approveLPTransferorsEvent.parameters = new Array() + + approveLPTransferorsEvent.parameters.push( + new ethereum.EventParam("lender", ethereum.Value.fromAddress(lender)) + ) + approveLPTransferorsEvent.parameters.push( + new ethereum.EventParam( + "transferors", + ethereum.Value.fromAddressArray(transferors) + ) + ) + + // update transaction target to the expected pool address + approveLPTransferorsEvent.address = pool + + return approveLPTransferorsEvent +} + +export function createDecreaseLPAllowanceEvent( + pool: Address, + owner: Address, + spender: Address, + indexes: Array, + amounts: Array +): DecreaseLPAllowance { + let decreaseLPAllowanceEvent = changetype(newMockEvent()) + + decreaseLPAllowanceEvent.parameters = new Array() + + decreaseLPAllowanceEvent.parameters.push( + new ethereum.EventParam("owner", ethereum.Value.fromAddress(owner)) + ) + decreaseLPAllowanceEvent.parameters.push( + new ethereum.EventParam("spender", ethereum.Value.fromAddress(spender)) + ) + decreaseLPAllowanceEvent.parameters.push( + new ethereum.EventParam( + "indexes", + ethereum.Value.fromUnsignedBigIntArray(indexes) + ) + ) + decreaseLPAllowanceEvent.parameters.push( + new ethereum.EventParam( + "amounts", + ethereum.Value.fromUnsignedBigIntArray(amounts) + ) + ) + + // update transaction to expected addresses + decreaseLPAllowanceEvent.address = pool + + return decreaseLPAllowanceEvent +} + +export function createIncreaseLPAllowanceEvent( + pool: Address, + owner: Address, + spender: Address, + indexes: Array, + amounts: Array +): IncreaseLPAllowance { + let increaseLPAllowanceEvent = changetype(newMockEvent()) + + increaseLPAllowanceEvent.parameters = new Array() + + increaseLPAllowanceEvent.parameters.push( + new ethereum.EventParam("owner", ethereum.Value.fromAddress(owner)) + ) + increaseLPAllowanceEvent.parameters.push( + new ethereum.EventParam("spender", ethereum.Value.fromAddress(spender)) + ) + increaseLPAllowanceEvent.parameters.push( + new ethereum.EventParam( + "indexes", + ethereum.Value.fromUnsignedBigIntArray(indexes) + ) + ) + increaseLPAllowanceEvent.parameters.push( + new ethereum.EventParam( + "amounts", + ethereum.Value.fromUnsignedBigIntArray(amounts) + ) + ) + // update transaction to expected addresses + increaseLPAllowanceEvent.address = pool + + return increaseLPAllowanceEvent +} + +export function createRevokeLPAllowanceEvent( + pool: Address, + owner: Address, + spender: Address, + indexes: Array +): RevokeLPAllowance { + let revokeLPAllowanceEvent = changetype(newMockEvent()) + + revokeLPAllowanceEvent.parameters = new Array() + + revokeLPAllowanceEvent.parameters.push( + new ethereum.EventParam("owner", ethereum.Value.fromAddress(owner)) + ) + revokeLPAllowanceEvent.parameters.push( + new ethereum.EventParam("spender", ethereum.Value.fromAddress(spender)) + ) + revokeLPAllowanceEvent.parameters.push( + new ethereum.EventParam( + "indexes", + ethereum.Value.fromUnsignedBigIntArray(indexes) + ) + ) + // update transaction target to the expected pool address + revokeLPAllowanceEvent.address = pool + + return revokeLPAllowanceEvent +} + +export function createRevokeLPTransferorsEvent( + pool: Address, + lender: Address, + transferors: Array
+): RevokeLPTransferors { + let revokeLPTransferorsEvent = changetype(newMockEvent()) + + revokeLPTransferorsEvent.parameters = new Array() + + revokeLPTransferorsEvent.parameters.push( + new ethereum.EventParam("lender", ethereum.Value.fromAddress(lender)) + ) + revokeLPTransferorsEvent.parameters.push( + new ethereum.EventParam( + "transferors", + ethereum.Value.fromAddressArray(transferors) + ) + ) + + // update transaction target to the expected pool address + revokeLPTransferorsEvent.address = pool + + return revokeLPTransferorsEvent +} + export function createBucketBankruptcyEvent( pool: Address, index: BigInt,