From 5b610e78e04220c50017dfab6064d17d86bd0db2 Mon Sep 17 00:00:00 2001 From: Mike Hathaway Date: Tue, 17 Oct 2023 11:27:18 -0400 Subject: [PATCH] Flashloan test (#74) * fit typo; make addressToBytes consistent in lpb management * add flashloan tests --------- Co-authored-by: Mike --- tests/erc-20-pool.test.ts | 18 ++++++++++++++++-- tests/utils/erc-20-pool-utils.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/tests/erc-20-pool.test.ts b/tests/erc-20-pool.test.ts index 12ae23b..11a2677 100644 --- a/tests/erc-20-pool.test.ts +++ b/tests/erc-20-pool.test.ts @@ -10,8 +10,8 @@ import { logStore, } from "matchstick-as/assembly/index" import { Address, BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts" -import { handleAddCollateral, handleAddQuoteToken, handleBucketBankruptcy, handleBucketTake, handleBucketTakeLPAwarded, handleDrawDebt, handleKick, handleMoveQuoteToken, handleRepayDebt, handleReserveAuctionKick, handleReserveAuctionTake, handleTake, handleUpdateInterestRate } from "../src/mappings/erc-20-pool" -import { createAddCollateralEvent, createAddQuoteTokenEvent, createBucketBankruptcyEvent, createBucketTakeEvent, createBucketTakeLPAwardedEvent, createDrawDebtEvent, createKickEvent, createMoveQuoteTokenEvent, createRepayDebtEvent, createReserveAuctionKickEvent, createReserveAuctionTakeEvent, createTakeEvent, createUpdateInterestRateEvent } from "./utils/erc-20-pool-utils" +import { handleAddCollateral, handleAddQuoteToken, handleBucketBankruptcy, handleBucketTake, handleBucketTakeLPAwarded, handleDrawDebt, handleFlashloan, handleKick, handleMoveQuoteToken, handleRepayDebt, handleReserveAuctionKick, handleReserveAuctionTake, handleTake, handleUpdateInterestRate } from "../src/mappings/erc-20-pool" +import { createAddCollateralEvent, createAddQuoteTokenEvent, createBucketBankruptcyEvent, createBucketTakeEvent, createBucketTakeLPAwardedEvent, createDrawDebtEvent, createFlashLoanEvent, createKickEvent, createMoveQuoteTokenEvent, createRepayDebtEvent, createReserveAuctionKickEvent, createReserveAuctionTakeEvent, createTakeEvent, createUpdateInterestRateEvent } from "./utils/erc-20-pool-utils" import { assertBucketUpdate, assertLendUpdate, @@ -1638,4 +1638,18 @@ describe("ERC20Pool assertions", () => { ) }) + test("FlashLoan", () => { + // mock parameters + const poolAddress = Address.fromString("0x0000000000000000000000000000000000000001") + const reciever = Address.fromString("0x0000000000000000000000000000000000000002") + const token = Address.fromString("0x0000000000000000000000000000000000000012") + const amount = BigInt.fromString("567529276179422528643") // 567.529276179422528643 * 1e18 + + const flashLoanEvent = createFlashLoanEvent(poolAddress, reciever, token, amount) + handleFlashloan(flashLoanEvent) + + assert.entityCount("Flashloan", 1) + + }) + }) diff --git a/tests/utils/erc-20-pool-utils.ts b/tests/utils/erc-20-pool-utils.ts index b6e1df4..b72aa0a 100644 --- a/tests/utils/erc-20-pool-utils.ts +++ b/tests/utils/erc-20-pool-utils.ts @@ -8,6 +8,7 @@ import { BucketTake, BucketTakeLPAwarded, DrawDebt, + Flashloan, Kick, KickReserveAuction, MoveQuoteToken, @@ -256,6 +257,31 @@ export function createDrawDebtEvent( return drawDebtEvent } +export function createFlashLoanEvent( + pool: Address, + reciever: Address, + token: Address, + amount: BigInt +): Flashloan { + let flashLoanEvent = changetype(newMockEvent()) + + flashLoanEvent.parameters = new Array() + + flashLoanEvent.parameters.push( + new ethereum.EventParam("reciever", ethereum.Value.fromAddress(reciever)) + ) + flashLoanEvent.parameters.push( + new ethereum.EventParam("token", ethereum.Value.fromAddress(token)) + ) + flashLoanEvent.parameters.push( + new ethereum.EventParam("amount", ethereum.Value.fromUnsignedBigInt(amount)) + ) + + flashLoanEvent.address = pool + + return flashLoanEvent +} + export function createKickEvent( pool: Address, kicker: Address,