From 72ac2f0badc1ff4b50b27147541fdc140e241ff6 Mon Sep 17 00:00:00 2001 From: Mike Hathaway Date: Mon, 21 Aug 2023 19:16:38 -0400 Subject: [PATCH] Directory Cleanups (#59) * move mappings files into mappings directory * move mock functions into new mock-contract-calls file --------- Co-authored-by: Mike --- src/{ => mappings}/ajna-token.ts | 10 +- src/{ => mappings}/burn-wrapped-ajna.ts | 8 +- src/{ => mappings}/erc-20-pool-factory.ts | 18 +- src/{ => mappings}/erc-20-pool.ts | 34 +- src/{ => mappings}/erc-721-pool-factory.ts | 22 +- src/{ => mappings}/erc-721-pool.ts | 34 +- src/{ => mappings}/grant-fund.ts | 22 +- src/{ => mappings}/position-manager.ts | 18 +- src/{ => mappings}/rewards-manager.ts | 8 +- subgraph.yaml | 18 +- tests/erc-20-pool-factory.test.ts | 3 +- tests/erc-20-pool.test.ts | 16 +- tests/erc-721-pool.test.ts | 5 +- tests/grant-fund.test.ts | 4 +- tests/position-manager.test.ts | 5 +- tests/rewards-manager.test.ts | 2 +- tests/utils/common.ts | 412 +-------------------- tests/utils/mock-contract-calls.ts | 409 ++++++++++++++++++++ tests/utils/position-manager-utils.ts | 4 +- 19 files changed, 528 insertions(+), 524 deletions(-) rename src/{ => mappings}/ajna-token.ts (89%) rename src/{ => mappings}/burn-wrapped-ajna.ts (71%) rename src/{ => mappings}/erc-20-pool-factory.ts (86%) rename src/{ => mappings}/erc-20-pool.ts (97%) rename src/{ => mappings}/erc-721-pool-factory.ts (89%) rename src/{ => mappings}/erc-721-pool.ts (98%) rename src/{ => mappings}/grant-fund.ts (97%) rename src/{ => mappings}/position-manager.ts (95%) rename src/{ => mappings}/rewards-manager.ts (93%) create mode 100644 tests/utils/mock-contract-calls.ts diff --git a/src/ajna-token.ts b/src/mappings/ajna-token.ts similarity index 89% rename from src/ajna-token.ts rename to src/mappings/ajna-token.ts index 10257f3..788eb63 100644 --- a/src/ajna-token.ts +++ b/src/mappings/ajna-token.ts @@ -2,15 +2,15 @@ import { Bytes } from "@graphprotocol/graph-ts" import { DelegateChanged as DelegateChangedEvent, DelegateVotesChanged as DelegateVotesChangedEvent, -} from "../generated/AjnaToken/AjnaToken" +} from "../../generated/AjnaToken/AjnaToken" import { Account, DelegateChanged, DelegateVotesChanged, -} from "../generated/schema" -import { loadOrCreateAccount } from "./utils/account" -import { addressToBytes, bigIntToBytes, wadToDecimal } from "./utils/convert" -import { addDelegator, removeDelegator } from "./utils/grants/voter" +} from "../../generated/schema" +import { loadOrCreateAccount } from "../utils/account" +import { addressToBytes, bigIntToBytes, wadToDecimal } from "../utils/convert" +import { addDelegator, removeDelegator } from "../utils/grants/voter" export function handleDelegateChanged(event: DelegateChangedEvent): void { let entity = new DelegateChanged( diff --git a/src/burn-wrapped-ajna.ts b/src/mappings/burn-wrapped-ajna.ts similarity index 71% rename from src/burn-wrapped-ajna.ts rename to src/mappings/burn-wrapped-ajna.ts index 7e41a85..3dc30c6 100644 --- a/src/burn-wrapped-ajna.ts +++ b/src/mappings/burn-wrapped-ajna.ts @@ -1,9 +1,9 @@ import { Transfer as TransferEvent -} from "../generated/BurnWrappedAjna/BurnWrappedAjna" -import { BurnWrap } from "../generated/schema" -import { ZERO_ADDRESS } from "./utils/constants" -import { addressToBytes, wadToDecimal } from "./utils/convert" +} from "../../generated/BurnWrappedAjna/BurnWrappedAjna" +import { BurnWrap } from "../../generated/schema" +import { ZERO_ADDRESS } from "../utils/constants" +import { addressToBytes, wadToDecimal } from "../utils/convert" export function handleTransfer( event: TransferEvent diff --git a/src/erc-20-pool-factory.ts b/src/mappings/erc-20-pool-factory.ts similarity index 86% rename from src/erc-20-pool-factory.ts rename to src/mappings/erc-20-pool-factory.ts index 92c6acc..1b7e8f8 100644 --- a/src/erc-20-pool-factory.ts +++ b/src/mappings/erc-20-pool-factory.ts @@ -1,13 +1,13 @@ -import { PoolCreated as PoolCreatedEvent } from "../generated/ERC20PoolFactory/ERC20PoolFactory" -import { PoolCreated, Token } from "../generated/schema" -import { ERC20Pool } from "../generated/templates" -import { ERC20Pool as ERC20PoolContract } from "../generated/templates/ERC20Pool/ERC20Pool" +import { PoolCreated as PoolCreatedEvent } from "../../generated/ERC20PoolFactory/ERC20PoolFactory" +import { PoolCreated, Token } from "../../generated/schema" +import { ERC20Pool } from "../../generated/templates" +import { ERC20Pool as ERC20PoolContract } from "../../generated/templates/ERC20Pool/ERC20Pool" -import { ONE_BI, ZERO_BI } from "./utils/constants" -import { addressToBytes, wadToDecimal } from "./utils/convert" -import { getTokenDecimals, getTokenName, getTokenSymbol, getTokenTotalSupply } from "./utils/token-erc20" -import { getRatesAndFees, loadOrCreatePool } from "./utils/pool/pool" -import { loadOrCreateFactory } from "./utils/pool/pool-factory" +import { ONE_BI, ZERO_BI } from "../utils/constants" +import { addressToBytes, wadToDecimal } from "../utils/convert" +import { getTokenDecimals, getTokenName, getTokenSymbol, getTokenTotalSupply } from "../utils/token-erc20" +import { getRatesAndFees, loadOrCreatePool } from "../utils/pool/pool" +import { loadOrCreateFactory } from "../utils/pool/pool-factory" import { Bytes } from "@graphprotocol/graph-ts" export function handlePoolCreated(event: PoolCreatedEvent): void { diff --git a/src/erc-20-pool.ts b/src/mappings/erc-20-pool.ts similarity index 97% rename from src/erc-20-pool.ts rename to src/mappings/erc-20-pool.ts index 86b5553..cefa083 100644 --- a/src/erc-20-pool.ts +++ b/src/mappings/erc-20-pool.ts @@ -28,7 +28,7 @@ import { Take as TakeEvent, TransferLP as TransferLPEvent, UpdateInterestRate as UpdateInterestRateEvent -} from "../generated/templates/ERC20Pool/ERC20Pool" +} from "../../generated/templates/ERC20Pool/ERC20Pool" import { AddCollateral, AuctionSettle, @@ -51,22 +51,22 @@ import { Settle, Take, Token -} from "../generated/schema" - -import { ZERO_BD, ONE_BI, TEN_BI, ZERO_BI } from "./utils/constants" -import { addressToBytes, wadToDecimal } from "./utils/convert" -import { loadOrCreateAccount, updateAccountLends, updateAccountLoans, updateAccountPools, updateAccountKicks, updateAccountTakes, updateAccountSettles, updateAccountReserveAuctions } from "./utils/account" -import { getBucketId, getBucketInfo, loadOrCreateBucket, updateBucketLends } from "./utils/pool/bucket" -import { getLendId, loadOrCreateLend } from "./utils/pool/lend" -import { getBorrowerInfo, getLoanId, loadOrCreateLoan } from "./utils/pool/loan" -import { getLiquidationAuctionId, getAuctionInfoERC20Pool, loadOrCreateLiquidationAuction, updateLiquidationAuction, getAuctionStatus, loadOrCreateBucketTake } from "./utils/pool/liquidation" -import { getBurnInfo, updatePool, addLiquidationToPool, addReserveAuctionToPool } from "./utils/pool/pool" -import { lpbValueInQuote } from "./utils/pool/lend" -import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "./utils/pool/reserve-auction" -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, _handleInterestRateEvent, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleTransferLP } from "./mappings/base/base-pool" +} from "../../generated/schema" + +import { ZERO_BD, ONE_BI, TEN_BI, ZERO_BI } from "../utils/constants" +import { addressToBytes, wadToDecimal } from "../utils/convert" +import { loadOrCreateAccount, updateAccountLends, updateAccountLoans, updateAccountPools, updateAccountKicks, updateAccountTakes, updateAccountSettles, updateAccountReserveAuctions } from "../utils/account" +import { getBucketId, getBucketInfo, loadOrCreateBucket, updateBucketLends } from "../utils/pool/bucket" +import { getLendId, loadOrCreateLend } from "../utils/pool/lend" +import { getBorrowerInfo, getLoanId, loadOrCreateLoan } from "../utils/pool/loan" +import { getLiquidationAuctionId, getAuctionInfoERC20Pool, loadOrCreateLiquidationAuction, updateLiquidationAuction, getAuctionStatus, loadOrCreateBucketTake } from "../utils/pool/liquidation" +import { getBurnInfo, updatePool, addLiquidationToPool, addReserveAuctionToPool } from "../utils/pool/pool" +import { lpbValueInQuote } from "../utils/pool/lend" +import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "../utils/pool/reserve-auction" +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, _handleInterestRateEvent, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleTransferLP } from "./base/base-pool" export function handleAddCollateral(event: AddCollateralEvent): void { const addCollateral = new AddCollateral( diff --git a/src/erc-721-pool-factory.ts b/src/mappings/erc-721-pool-factory.ts similarity index 89% rename from src/erc-721-pool-factory.ts rename to src/mappings/erc-721-pool-factory.ts index 7a44619..20e4dd8 100644 --- a/src/erc-721-pool-factory.ts +++ b/src/mappings/erc-721-pool-factory.ts @@ -1,14 +1,14 @@ -import { PoolCreated as PoolCreatedEvent } from "../generated/ERC721PoolFactory/ERC721PoolFactory" -import { PoolCreated, Token } from "../generated/schema" -import { ERC721Pool } from "../generated/templates" -import { ERC721Pool as ERC721PoolContract } from "../generated/templates/ERC721Pool/ERC721Pool" - -import { ONE_BI, ZERO_BI } from "./utils/constants" -import { addressToBytes, wadToDecimal } from "./utils/convert" -import { loadOrCreateFactory } from "./utils/pool/pool-factory" -import { getPoolSubsetHash, getRatesAndFees, loadOrCreatePool } from "./utils/pool/pool" -import { getTokenName as getTokenNameERC721, getTokenSymbol as getTokenSymbolERC721} from "./utils/token-erc721" -import { getTokenDecimals, getTokenName, getTokenSymbol, getTokenTotalSupply } from "./utils/token-erc20" +import { PoolCreated as PoolCreatedEvent } from "../../generated/ERC721PoolFactory/ERC721PoolFactory" +import { PoolCreated, Token } from "../../generated/schema" +import { ERC721Pool } from "../../generated/templates" +import { ERC721Pool as ERC721PoolContract } from "../../generated/templates/ERC721Pool/ERC721Pool" + +import { ONE_BI, ZERO_BI } from "../utils/constants" +import { addressToBytes, wadToDecimal } from "../utils/convert" +import { loadOrCreateFactory } from "../utils/pool/pool-factory" +import { getPoolSubsetHash, getRatesAndFees, loadOrCreatePool } from "../utils/pool/pool" +import { getTokenName as getTokenNameERC721, getTokenSymbol as getTokenSymbolERC721} from "../utils/token-erc721" +import { getTokenDecimals, getTokenName, getTokenSymbol, getTokenTotalSupply } from "../utils/token-erc20" import { BigInt, ByteArray, Bytes, ethereum } from "@graphprotocol/graph-ts" export function handlePoolCreated(event: PoolCreatedEvent): void { diff --git a/src/erc-721-pool.ts b/src/mappings/erc-721-pool.ts similarity index 98% rename from src/erc-721-pool.ts rename to src/mappings/erc-721-pool.ts index aadd2de..0d06e8f 100644 --- a/src/erc-721-pool.ts +++ b/src/mappings/erc-721-pool.ts @@ -27,7 +27,7 @@ import { Take as TakeEvent, TransferLP as TransferLPEvent, UpdateInterestRate as UpdateInterestRateEvent -} from "../generated/templates/ERC721Pool/ERC721Pool" +} from "../../generated/templates/ERC721Pool/ERC721Pool" import { AddCollateralNFT, AuctionNFTSettle, @@ -51,22 +51,22 @@ import { Token, ReserveAuctionTake, Lend -} from "../generated/schema" - -import { findAndRemoveTokenIds, getWadCollateralFloorTokens, incrementTokenTxCount } from "./utils/token-erc721" -import { loadOrCreateAccount, updateAccountLends, updateAccountLoans, updateAccountPools, updateAccountKicks, updateAccountTakes, updateAccountSettles, updateAccountReserveAuctions } from "./utils/account" -import { getBucketId, getBucketInfo, loadOrCreateBucket, updateBucketLends } from "./utils/pool/bucket" -import { addressToBytes, bigIntArrayToIntArray, decimalToWad, wadToDecimal } from "./utils/convert" -import { ZERO_BD, ONE_BI, TEN_BI, ONE_BD, ONE_WAD_BI, EXP_18_BD, ZERO_BI } from "./utils/constants" -import { getLendId, loadOrCreateLend } from "./utils/pool/lend" -import { getBorrowerInfoERC721Pool, getLoanId, loadOrCreateLoan } from "./utils/pool/loan" -import { getLiquidationAuctionId, loadOrCreateLiquidationAuction, updateLiquidationAuction, getAuctionStatus, loadOrCreateBucketTake, getAuctionInfoERC721Pool } from "./utils/pool/liquidation" -import { getBurnInfo, updatePool, addLiquidationToPool, addReserveAuctionToPool, getLenderInfoERC721Pool } from "./utils/pool/pool" -import { lpbValueInQuote } from "./utils/pool/lend" -import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "./utils/pool/reserve-auction" -import { _handleAddQuoteToken, _handleInterestRateEvent, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleTransferLP } from "./mappings/base/base-pool" -import { decreaseAllowances, increaseAllowances, loadOrCreateAllowances, revokeAllowances } from "./utils/pool/lp-allowances" -import { loadOrCreateTransferors, revokeTransferors } from "./utils/pool/lp-transferors" +} from "../../generated/schema" + +import { findAndRemoveTokenIds, getWadCollateralFloorTokens, incrementTokenTxCount } from "../utils/token-erc721" +import { loadOrCreateAccount, updateAccountLends, updateAccountLoans, updateAccountPools, updateAccountKicks, updateAccountTakes, updateAccountSettles, updateAccountReserveAuctions } from "../utils/account" +import { getBucketId, getBucketInfo, loadOrCreateBucket, updateBucketLends } from "../utils/pool/bucket" +import { addressToBytes, bigIntArrayToIntArray, decimalToWad, wadToDecimal } from "../utils/convert" +import { ZERO_BD, ONE_BI, TEN_BI, ONE_BD, ONE_WAD_BI, EXP_18_BD, ZERO_BI } from "../utils/constants" +import { getLendId, loadOrCreateLend } from "../utils/pool/lend" +import { getBorrowerInfoERC721Pool, getLoanId, loadOrCreateLoan } from "../utils/pool/loan" +import { getLiquidationAuctionId, loadOrCreateLiquidationAuction, updateLiquidationAuction, getAuctionStatus, loadOrCreateBucketTake, getAuctionInfoERC721Pool } from "../utils/pool/liquidation" +import { getBurnInfo, updatePool, addLiquidationToPool, addReserveAuctionToPool, getLenderInfoERC721Pool } from "../utils/pool/pool" +import { lpbValueInQuote } from "../utils/pool/lend" +import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "../utils/pool/reserve-auction" +import { _handleAddQuoteToken, _handleInterestRateEvent, _handleMoveQuoteToken, _handleRemoveQuoteToken, _handleTransferLP } from "./base/base-pool" +import { decreaseAllowances, increaseAllowances, loadOrCreateAllowances, revokeAllowances } from "../utils/pool/lp-allowances" +import { loadOrCreateTransferors, revokeTransferors } from "../utils/pool/lp-transferors" /*******************************/ diff --git a/src/grant-fund.ts b/src/mappings/grant-fund.ts similarity index 97% rename from src/grant-fund.ts rename to src/mappings/grant-fund.ts index e4b8399..5e5f653 100644 --- a/src/grant-fund.ts +++ b/src/mappings/grant-fund.ts @@ -8,7 +8,7 @@ import { ProposalExecuted as ProposalExecutedEvent, DistributionPeriodStarted as DistributionPeriodStartedEvent, VoteCast as VoteCastEvent -} from "../generated/GrantFund/GrantFund" +} from "../../generated/GrantFund/GrantFund" import { DelegateRewardClaimed, DistributionPeriod, @@ -24,16 +24,16 @@ import { ScreeningVote, VoteCast, DistributionPeriodVote -} from "../generated/schema" - -import { NEG_ONE_BD, THREE_PERCENT_BI, ZERO_BD, ZERO_BI } from './utils/constants' -import { addressArrayToBytesArray, addressToBytes, bigIntArrayToBigDecimalArray, bigIntToBytes, bytesToBigInt, wadToDecimal } from "./utils/convert" -import { getProposalParamsId, getProposalsInSlate, loadOrCreateProposal } from './utils/grants/proposal' -import { getCurrentDistributionId, getCurrentStage, loadOrCreateDistributionPeriod } from './utils/grants/distribution' -import { getFundingStageVotingPower, getFundingVoteId, getFundingVotingPowerUsed, getScreeningStageVotingPower, getScreeningVoteId, loadOrCreateDistributionPeriodVote, loadOrCreateFundingVote, loadOrCreateScreeningVote } from './utils/grants/voter' -import { getTreasury, loadOrCreateGrantFund } from './utils/grants/fund' -import { loadOrCreateAccount } from './utils/account' -import { wmul } from './utils/math' +} from "../../generated/schema" + +import { NEG_ONE_BD, THREE_PERCENT_BI, ZERO_BD, ZERO_BI } from '../utils/constants' +import { addressArrayToBytesArray, addressToBytes, bigIntArrayToBigDecimalArray, bigIntToBytes, bytesToBigInt, wadToDecimal } from "../utils/convert" +import { getProposalParamsId, getProposalsInSlate, loadOrCreateProposal } from '../utils/grants/proposal' +import { getCurrentDistributionId, getCurrentStage, loadOrCreateDistributionPeriod } from '../utils/grants/distribution' +import { getFundingStageVotingPower, getFundingVoteId, getFundingVotingPowerUsed, getScreeningStageVotingPower, getScreeningVoteId, loadOrCreateDistributionPeriodVote, loadOrCreateFundingVote, loadOrCreateScreeningVote } from '../utils/grants/voter' +import { getTreasury, loadOrCreateGrantFund } from '../utils/grants/fund' +import { loadOrCreateAccount } from '../utils/account' +import { wmul } from '../utils/math' export function handleDelegateRewardClaimed( event: DelegateRewardClaimedEvent diff --git a/src/position-manager.ts b/src/mappings/position-manager.ts similarity index 95% rename from src/position-manager.ts rename to src/mappings/position-manager.ts index 8f0084c..b5b6549 100644 --- a/src/position-manager.ts +++ b/src/mappings/position-manager.ts @@ -8,7 +8,7 @@ import { MoveLiquidity as MoveLiquidityEvent, RedeemPosition as RedeemPositionEvent, Transfer as TransferEvent -} from "../generated/PositionManager/PositionManager" +} from "../../generated/PositionManager/PositionManager" import { Approval, ApprovalForAll, @@ -21,14 +21,14 @@ import { Position, RedeemPosition, Transfer -} from "../generated/schema" -import { getBucketId } from "./utils/pool/bucket" -import { getDepositTime, lpbValueInQuote } from "./utils/pool/lend" -import { ONE_BI, ZERO_BD } from "./utils/constants" -import { addressToBytes, bigIntArrayToIntArray, wadToDecimal } from "./utils/convert" -import { getLendId, loadOrCreateLend } from "./utils/pool/lend" -import { deletePosition, getPoolForToken, loadOrCreateLPToken, loadOrCreatePosition } from "./utils/position" -import { getLenderInfo } from "./utils/pool/pool" +} from "../../generated/schema" +import { getBucketId } from "../utils/pool/bucket" +import { getDepositTime, lpbValueInQuote } from "../utils/pool/lend" +import { ONE_BI, ZERO_BD } from "../utils/constants" +import { addressToBytes, bigIntArrayToIntArray, wadToDecimal } from "../utils/convert" +import { getLendId, loadOrCreateLend } from "../utils/pool/lend" +import { deletePosition, getPoolForToken, loadOrCreateLPToken, loadOrCreatePosition } from "../utils/position" +import { getLenderInfo } from "../utils/pool/pool" export function handleApproval(event: ApprovalEvent): void { const approval = new Approval( diff --git a/src/rewards-manager.ts b/src/mappings/rewards-manager.ts similarity index 93% rename from src/rewards-manager.ts rename to src/mappings/rewards-manager.ts index e8f1048..01a0710 100644 --- a/src/rewards-manager.ts +++ b/src/mappings/rewards-manager.ts @@ -4,16 +4,16 @@ import { Stake as StakeEvent, Unstake as UnstakeEvent, UpdateExchangeRates as UpdateExchangeRatesEvent -} from "../generated/RewardsManager/RewardsManager" +} from "../../generated/RewardsManager/RewardsManager" import { ClaimRewards, MoveStakedLiquidity, Stake, Unstake, UpdateExchangeRates -} from "../generated/schema" -import { bigIntArrayToIntArray, wadToDecimal } from "./utils/convert" -import { getPoolForToken } from "./utils/position" +} from "../../generated/schema" +import { bigIntArrayToIntArray, wadToDecimal } from "../utils/convert" +import { getPoolForToken } from "../utils/position" export function handleClaimRewards(event: ClaimRewardsEvent): void { let entity = new ClaimRewards( diff --git a/subgraph.yaml b/subgraph.yaml index 4fd3d6a..f7ceaa0 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -45,7 +45,7 @@ dataSources: handler: handleRedeemPosition - event: Transfer(indexed address,indexed address,indexed uint256) handler: handleTransfer - file: ./src/position-manager.ts + file: ./src/mappings/position-manager.ts network: goerli - kind: ethereum name: ERC20PoolFactory @@ -71,7 +71,7 @@ dataSources: eventHandlers: - event: PoolCreated(address) handler: handlePoolCreated - file: ./src/erc-20-pool-factory.ts + file: ./src/mappings/erc-20-pool-factory.ts network: goerli - kind: ethereum name: RewardsManager @@ -106,7 +106,7 @@ dataSources: handler: handleUnstake - event: UpdateExchangeRates(indexed address,indexed address,uint256[],uint256) handler: handleUpdateExchangeRates - file: ./src/rewards-manager.ts + file: ./src/mappings/rewards-manager.ts network: goerli - kind: ethereum name: ERC721PoolFactory @@ -134,7 +134,7 @@ dataSources: eventHandlers: - event: PoolCreated(address) handler: handlePoolCreated - file: ./src/erc-721-pool-factory.ts + file: ./src/mappings/erc-721-pool-factory.ts network: goerli - kind: ethereum name: GrantFund @@ -172,7 +172,7 @@ dataSources: handler: handleDistributionPeriodStarted - event: VoteCast(indexed address,uint256,uint8,uint256,string) handler: handleVoteCast - file: ./src/grant-fund.ts + file: ./src/mappings/grant-fund.ts network: goerli - kind: ethereum name: AjnaToken @@ -196,7 +196,7 @@ dataSources: handler: handleDelegateChanged - event: DelegateVotesChanged(indexed address,uint256,uint256) handler: handleDelegateVotesChanged - file: ./src/ajna-token.ts + file: ./src/mappings/ajna-token.ts - kind: ethereum name: BurnWrappedAjna network: goerli @@ -216,7 +216,7 @@ dataSources: eventHandlers: - event: Transfer(indexed address,indexed address,uint256) handler: handleTransfer - file: ./src/burn-wrapped-ajna.ts + file: ./src/mappings/burn-wrapped-ajna.ts templates: - kind: ethereum name: ERC20Pool @@ -316,7 +316,7 @@ templates: handler: handleTransferLP - event: UpdateInterestRate(uint256,uint256) handler: handleUpdateInterestRate - file: ./src/erc-20-pool.ts + file: ./src/mappings/erc-20-pool.ts network: goerli - kind: ethereum name: ERC721Pool @@ -423,5 +423,5 @@ templates: handler: handleTransferLP - event: UpdateInterestRate(uint256,uint256) handler: handleUpdateInterestRate - file: ./src/erc-721-pool.ts + file: ./src/mappings/erc-721-pool.ts network: goerli diff --git a/tests/erc-20-pool-factory.test.ts b/tests/erc-20-pool-factory.test.ts index cb4b3f8..881e4b8 100644 --- a/tests/erc-20-pool-factory.test.ts +++ b/tests/erc-20-pool-factory.test.ts @@ -9,7 +9,8 @@ import { dataSourceMock } from "matchstick-as/assembly/index" import { Address, BigInt, dataSource } from "@graphprotocol/graph-ts" -import { createPool, mockGetRatesAndFees } from "./utils/common" +import { createPool } from "./utils/common" +import { mockGetRatesAndFees } from "./utils/mock-contract-calls" import { FIVE_PERCENT_BI, MAX_PRICE, ONE_BI, ZERO_BI } from "../src/utils/constants" diff --git a/tests/erc-20-pool.test.ts b/tests/erc-20-pool.test.ts index a3ce94d..3e15ec7 100644 --- a/tests/erc-20-pool.test.ts +++ b/tests/erc-20-pool.test.ts @@ -10,25 +10,15 @@ 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/erc-20-pool" +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 { assertBucketUpdate, assertLendUpdate, assertPoolUpdate, - createPool, - mockGetAuctionInfo, - mockGetAuctionStatus, - mockGetBorrowerInfo, - mockGetBucketInfo, - mockGetBurnInfo, - mockGetCurrentBurnEpoch, - mockGetDebtInfo, - mockGetLPBValueInQuote, - mockGetRatesAndFees, - mockPoolInfoUtilsPoolUpdateCalls, - mockTokenBalance + createPool } from "./utils/common" +import { mockGetAuctionInfo, mockGetAuctionStatus, mockGetBorrowerInfo, mockGetBucketInfo, mockGetBurnInfo, mockGetCurrentBurnEpoch, mockGetDebtInfo, mockGetLPBValueInQuote, mockGetLenderInfo, mockGetRatesAndFees, mockPoolInfoUtilsPoolUpdateCalls, mockTokenBalance } from "./utils/mock-contract-calls" import { BucketInfo, getBucketId } from "../src/utils/pool/bucket" import { addressToBytes, wadToDecimal } from "../src/utils/convert" import { FIVE_PERCENT_BI, MAX_PRICE, MAX_PRICE_BI, MAX_PRICE_INDEX, ONE_BI, ONE_PERCENT_BI, ONE_WAD_BI, TWO_BI, ZERO_ADDRESS, ZERO_BD, ZERO_BI } from "../src/utils/constants" diff --git a/tests/erc-721-pool.test.ts b/tests/erc-721-pool.test.ts index abb48d0..63bcc87 100644 --- a/tests/erc-721-pool.test.ts +++ b/tests/erc-721-pool.test.ts @@ -11,11 +11,12 @@ import { } from "matchstick-as/assembly/index" import { Address, BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts" import { Account, Lend, Loan } from "../generated/schema" -import { handleAddCollateralNFT, handleAddQuoteToken, handleDrawDebtNFT, handleRepayDebt, handleMergeOrRemoveCollateralNFT, handleRemoveCollateral, handleKick, handleAuctionNFTSettle, handleSettle, handleTake, handleBucketTakeLPAwarded, handleBucketTake, handleTransferLP } from "../src/erc-721-pool" +import { handleAddCollateralNFT, handleAddQuoteToken, handleDrawDebtNFT, handleRepayDebt, handleMergeOrRemoveCollateralNFT, handleRemoveCollateral, handleKick, handleAuctionNFTSettle, handleSettle, handleTake, handleBucketTakeLPAwarded, handleBucketTake, handleTransferLP } from "../src/mappings/erc-721-pool" import { createAddCollateralNFTEvent, createAddQuoteTokenEvent, createDrawDebtNFTEvent, createRepayDebtEvent, createMergeOrRemoveCollateralNFTEvent, createRemoveCollateralEvent, createKickEvent, createAuctionNFTSettleEvent, createSettleEvent, createTakeEvent, createBucketTakeEvent, createBucketTakeLPAwardedEvent, createTransferLPEvent } from "./utils/erc-721-pool-utils" import { FIVE_PERCENT_BI, MAX_PRICE, MAX_PRICE_BI, MAX_PRICE_INDEX, ONE_BI, ONE_PERCENT_BI, ONE_WAD_BI, TWO_BI, ZERO_ADDRESS, ZERO_BD, ZERO_BI } from "../src/utils/constants" -import { assertBucketUpdate, assertLendUpdate, create721Pool, createAndHandleAddQuoteTokenEvent, createPool, mockGetAuctionInfo, mockGetAuctionStatus, mockGetBorrowerInfo, mockGetBucketInfo, mockGetDebtInfo, mockGetLPBValueInQuote, mockGetLenderInfo, mockGetRatesAndFees, mockPoolInfoUtilsPoolUpdateCalls, mockTokenBalance } from "./utils/common" +import { assertBucketUpdate, assertLendUpdate, create721Pool, createAndHandleAddQuoteTokenEvent, createPool } from "./utils/common" +import { mockGetAuctionInfo, mockGetAuctionStatus, mockGetBorrowerInfo, mockGetBucketInfo, mockGetDebtInfo, mockGetLPBValueInQuote, mockGetLenderInfo, mockGetRatesAndFees, mockPoolInfoUtilsPoolUpdateCalls, mockTokenBalance } from "./utils/mock-contract-calls" import { BucketInfo, getBucketId } from "../src/utils/pool/bucket" import { addressToBytes, wadToDecimal } from "../src/utils/convert" import { DebtInfo } from "../src/utils/pool/pool" diff --git a/tests/grant-fund.test.ts b/tests/grant-fund.test.ts index e94ed84..7efb964 100644 --- a/tests/grant-fund.test.ts +++ b/tests/grant-fund.test.ts @@ -16,7 +16,7 @@ import { handleDistributionPeriodStarted, handleVoteCast, handleFundedSlateUpdated, -} from "../src/grant-fund"; +} from "../src/mappings/grant-fund"; import { createDelegateRewardClaimedEvent, createFundTreasuryEvent, @@ -38,7 +38,7 @@ import { ZERO_BI, } from "../src/utils/constants"; import { addressToBytes, bigIntToBytes, decimalToWad, wadToDecimal } from "../src/utils/convert"; -import { mockGetDistributionId, mockGetFundedProposalSlate, mockGetTreasury, mockGetVotesFunding, mockGetVotesScreening } from "./utils/common"; +import { mockGetDistributionId, mockGetFundedProposalSlate, mockGetTreasury, mockGetVotesFunding, mockGetVotesScreening } from "./utils/mock-contract-calls"; import { getDistributionPeriodVoteId, getFundingVoteId, getScreeningVoteId } from "../src/utils/grants/voter"; // Tests structure (matchstick-as >=0.5.0) diff --git a/tests/position-manager.test.ts b/tests/position-manager.test.ts index d8b7124..1ac4e5d 100644 --- a/tests/position-manager.test.ts +++ b/tests/position-manager.test.ts @@ -10,10 +10,11 @@ import { beforeEach } from "matchstick-as/assembly/index" import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts" -import { handleApproval, handleBurn, handleMemorializePosition, handleMint, handleMoveLiquidity, handleRedeemPosition } from "../src/position-manager" +import { handleApproval, handleBurn, handleMemorializePosition, handleMint, handleMoveLiquidity, handleRedeemPosition } from "../src/mappings/position-manager" import { assertPosition, createApprovalEvent, createBurnEvent, createMemorializePositionEvent, createMintEvent, createMoveLiquidityEvent, createRedeemPositionEvent, mintPosition } from "./utils/position-manager-utils" import { bigIntToBytes, wadToDecimal } from "../src/utils/convert" -import { create721Pool, mockGetLPBValueInQuote, mockGetLenderInfo, mockGetPoolKey, mockGetTokenName, mockGetTokenSymbol } from "./utils/common" +import { create721Pool } from "./utils/common" +import { mockGetLPBValueInQuote, mockGetLenderInfo, mockGetPoolKey, mockGetTokenName, mockGetTokenSymbol } from "./utils/mock-contract-calls" import { Lend } from "../generated/schema" import { getLendId } from "../src/utils/pool/lend" import { getBucketId } from "../src/utils/pool/bucket" diff --git a/tests/rewards-manager.test.ts b/tests/rewards-manager.test.ts index 8ec2447..964571a 100644 --- a/tests/rewards-manager.test.ts +++ b/tests/rewards-manager.test.ts @@ -7,7 +7,7 @@ import { afterAll } from "matchstick-as/assembly/index" import { Address, BigInt } from "@graphprotocol/graph-ts" -import { handleClaimRewards } from "../src/rewards-manager" +import { handleClaimRewards } from "../src/mappings/rewards-manager" import { createClaimRewardsEvent } from "./utils/rewards-manager-utils" // Tests structure (matchstick-as >=0.5.0) diff --git a/tests/utils/common.ts b/tests/utils/common.ts index 26d9c53..2e78c1d 100644 --- a/tests/utils/common.ts +++ b/tests/utils/common.ts @@ -1,8 +1,8 @@ import { Address, BigInt, Bytes, ethereum, dataSource, log, BigDecimal } from "@graphprotocol/graph-ts" import { assert, createMockedFunction } from "matchstick-as" -import { handlePoolCreated } from "../../src/erc-20-pool-factory" -import { handlePoolCreated as handleERC721PoolCreated } from "../../src/erc-721-pool-factory" +import { handlePoolCreated } from "../../src/mappings/erc-20-pool-factory" +import { handlePoolCreated as handleERC721PoolCreated } from "../../src/mappings/erc-721-pool-factory" import { createPoolCreatedEvent } from "./erc-20-pool-factory-utils" import { createERC721PoolFactoryPoolCreatedEvent } from "./erc-721-pool-factory-utils" @@ -15,7 +15,8 @@ import { AuctionInfo, AuctionStatus } from "../../src/utils/pool/liquidation" import { BorrowerInfo } from "../../src/utils/pool/loan" import { wdiv, wmin, wmul } from "../../src/utils/math" import { createAddQuoteTokenEvent } from "./erc-721-pool-utils" -import { handleAddQuoteToken } from "../../src/erc-721-pool" +import { handleAddQuoteToken } from "../../src/mappings/erc-721-pool" +import { mockGetBucketInfo, mockGetBurnInfo, mockGetERC721TokenInfo, mockGetLPBValueInQuote, mockGetRatesAndFees, mockGetTokenInfo, mockPoolInfoUtilsPoolUpdateCalls } from "./mock-contract-calls" /*************************/ /*** Bucket Assertions ***/ @@ -258,102 +259,9 @@ export function assertPoolUpdate(params: PoolUpdatedParams): void { ) } -/*********************************/ -/*** Grant Fund Mock Functions ***/ -/*********************************/ - -// mock burnInfo contract calls -export function mockGetDistributionId(grantFund: Address, expectedDistributionId: BigInt): void { - createMockedFunction(grantFund, 'getDistributionId', 'getDistributionId():(uint24)') - .withArgs([]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedDistributionId), - ]) -} - -export function mockGetVotesScreening(grantFund: Address, distributionId: BigInt, voter: Address, expectedVotes: BigInt): void { - createMockedFunction(grantFund, 'getVotesScreening', 'getVotesScreening(uint24,address):(uint256)') - .withArgs([ - ethereum.Value.fromUnsignedBigInt(distributionId), - ethereum.Value.fromAddress(voter) - ]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedVotes), - ]) -} - -export function mockGetVotesFunding(grantFund: Address, distributionId: BigInt, voter: Address, expectedVotes: BigInt): void { - createMockedFunction(grantFund, 'getVotesFunding', 'getVotesFunding(uint24,address):(uint256)') - .withArgs([ - ethereum.Value.fromUnsignedBigInt(distributionId), - ethereum.Value.fromAddress(voter) - ]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedVotes), - ]) -} - -export function mockGetTreasury(grantFund: Address, expectedTreasury: BigInt): void { - createMockedFunction(grantFund, 'treasury', 'treasury():(uint256)') - .withArgs([]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedTreasury), - ]) -} - -export function mockGetFundedProposalSlate(grantFund: Address, slateHash: Bytes, expectedProposals: Array): void { - createMockedFunction(grantFund, 'getFundedProposalSlate', 'getFundedProposalSlate(bytes32):(uint256[])') - .withArgs([ - ethereum.Value.fromFixedBytes(slateHash) - ]) - .returns([ - ethereum.Value.fromUnsignedBigIntArray(expectedProposals), - ]) -} - -/*******************************/ -/*** Position Mock Functions ***/ -/*******************************/ - -export function mockGetTokenName(tokenContract: Address, expectedName: String): void { - createMockedFunction( - tokenContract, - 'name', - 'name():(string)' - ) - .withArgs([]) - .returns([ - ethereum.Value.fromString(expectedName), - ]) -} - -export function mockGetTokenSymbol(tokenContract: Address, expectedSymbol: String): void { - createMockedFunction( - tokenContract, - 'symbol', - 'symbol():(string)' - ) - .withArgs([]) - .returns([ - ethereum.Value.fromString(expectedSymbol), - ]) -} - -export function mockGetPoolKey(tokenId: BigInt, expectedPoolAddress: Address): void { - createMockedFunction( - positionManagerAddressTable.get(dataSource.network())!, - 'poolKey', - 'poolKey(uint256):(address)' - ) - .withArgs([ethereum.Value.fromUnsignedBigInt(tokenId)]) - .returns([ - ethereum.Value.fromAddress(expectedPoolAddress), - ]) -} - -/***************************/ -/*** Pool Mock Functions ***/ -/***************************/ +/*************************/ +/*** Utility Functions ***/ +/*************************/ // TODO: add mockGetRatesAndFees to this function // create a pool entity and save it to the store @@ -409,312 +317,6 @@ export function create721Pool(pool: Address, collateral: Address, quote: Address handleERC721PoolCreated(newPoolCreatedEvent) } -export function mockGetBorrowerInfo(pool: Address, borrower: Address, expectedInfo: BorrowerInfo): void { - createMockedFunction(pool, 'borrowerInfo', 'borrowerInfo(address):(uint256,uint256,uint256)') - .withArgs([ethereum.Value.fromAddress(borrower)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedInfo.t0debt), - ethereum.Value.fromUnsignedBigInt(expectedInfo.collateral), - ethereum.Value.fromUnsignedBigInt(expectedInfo.t0Np) - ]) -} - -// mock getBucketInfo contract calls -export function mockGetBucketInfo(pool: Address, bucketIndex: BigInt, expectedInfo: BucketInfo): void { - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'bucketInfo', 'bucketInfo(address,uint256):(uint256,uint256,uint256,uint256,uint256,uint256)') - .withArgs([ethereum.Value.fromAddress(pool), ethereum.Value.fromUnsignedBigInt(bucketIndex)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(123456789)), - ethereum.Value.fromUnsignedBigInt(expectedInfo.quoteTokens), - ethereum.Value.fromUnsignedBigInt(expectedInfo.collateral), - ethereum.Value.fromUnsignedBigInt(expectedInfo.lpb), - ethereum.Value.fromUnsignedBigInt(expectedInfo.scale), - ethereum.Value.fromUnsignedBigInt(expectedInfo.exchangeRate) - ]) -} - -export function mockGetDebtInfo(pool: Address, expectInfo: DebtInfo): void { - createMockedFunction(pool, 'debtInfo', 'debtInfo():(uint256,uint256,uint256,uint256)') - .returns([ - ethereum.Value.fromUnsignedBigInt(expectInfo.pendingDebt), - ethereum.Value.fromUnsignedBigInt(expectInfo.accruedDebt), - ethereum.Value.fromUnsignedBigInt(expectInfo.liquidationDebt), - ethereum.Value.fromUnsignedBigInt(expectInfo.t0Debt2ToCollateral) - ]) -} - -export function mockGetRatesAndFees(pool: Address, expectedLenderInterestMargin: BigInt, borrowRate: BigInt): void { - // return Maths.max(Maths.wdiv(interestRate_, 52 * 1e18), 0.0005 * 1e18); - const expectedBorrowFeeRate = wmin(wdiv(borrowRate, BigInt.fromString("52000000000000000000")), BigInt.fromString("500000000000000")); - // return Maths.min(Maths.wdiv(interestRate_, 365 * 1e18), 0.1 * 1e18); - const expectedDepositFeeRate = wmin(wdiv(borrowRate, BigInt.fromString("365000000000000000000")), BigInt.fromString("100000000000000000")); - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'lenderInterestMargin', 'lenderInterestMargin(address):(uint256)') - .withArgs([ethereum.Value.fromAddress(pool)]) - .returns([ethereum.Value.fromUnsignedBigInt(expectedLenderInterestMargin)]) - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'borrowFeeRate', 'borrowFeeRate(address):(uint256)') - .withArgs([ethereum.Value.fromAddress(pool)]) - .returns([ethereum.Value.fromUnsignedBigInt(expectedBorrowFeeRate)]) - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'unutilizedDepositFeeRate', 'unutilizedDepositFeeRate(address):(uint256)') - .withArgs([ethereum.Value.fromAddress(pool)]) - .returns([ethereum.Value.fromUnsignedBigInt(expectedDepositFeeRate)]) -} - -// mock getLPBValueInQuote contract calls -export function mockGetLPBValueInQuote(pool: Address, lpb: BigInt, bucketIndex: BigInt, expectedValue: BigInt): void { - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'lpToQuoteTokens', 'lpToQuoteTokens(address,uint256,uint256):(uint256)') - .withArgs([ethereum.Value.fromAddress(pool), ethereum.Value.fromUnsignedBigInt(lpb), ethereum.Value.fromUnsignedBigInt(bucketIndex)]) - .returns([ethereum.Value.fromUnsignedBigInt(expectedValue)]) -} - -export function mockGetLenderInfo(pool: Address, bucketIndex: BigInt, lender: Address, expectedLPB: BigInt, expectedDepositTime: BigInt): void { - createMockedFunction(pool, 'lenderInfo', 'lenderInfo(uint256,address):(uint256,uint256)') - .withArgs([ethereum.Value.fromUnsignedBigInt(bucketIndex), ethereum.Value.fromAddress(lender)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedLPB), - ethereum.Value.fromUnsignedBigInt(expectedDepositTime) - ]) -} - -// mock getPoolLoansInfo contract calls -export function mockGetPoolLoansInfo(pool: Address, expectedInfo: LoansInfo): void { - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'poolLoansInfo', 'poolLoansInfo(address):(uint256,uint256,address,uint256,uint256)') - .withArgs([ethereum.Value.fromAddress(pool)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedInfo.poolSize), - ethereum.Value.fromUnsignedBigInt(expectedInfo.loansCount), - ethereum.Value.fromAddress(expectedInfo.maxBorrower), - ethereum.Value.fromUnsignedBigInt(expectedInfo.pendingInflator), - ethereum.Value.fromUnsignedBigInt(expectedInfo.pendingInterestFactor) - ]) -} - -// mock getPoolPricesInfo contract calls -export function mockGetPoolPricesInfo(pool: Address, expectedInfo: PoolPricesInfo): void { - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'poolPricesInfo', 'poolPricesInfo(address):(uint256,uint256,uint256,uint256,uint256,uint256)') - .withArgs([ethereum.Value.fromAddress(pool)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedInfo.hpb), - ethereum.Value.fromUnsignedBigInt(expectedInfo.hpbIndex), - ethereum.Value.fromUnsignedBigInt(expectedInfo.htp), - ethereum.Value.fromUnsignedBigInt(expectedInfo.htpIndex), - ethereum.Value.fromUnsignedBigInt(expectedInfo.lup), - ethereum.Value.fromUnsignedBigInt(expectedInfo.lupIndex) - ]) -} - -// mock getMomp contract calls -export function mockGetPoolMomp(pool: Address, expectedInfo: BigInt): void { - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'momp', 'momp(address):(uint256)') - .withArgs([ethereum.Value.fromAddress(pool)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedInfo) - ]) -} - -// mock getPoolReserves contract calls -export function mockGetPoolReserves(pool: Address, expectedInfo: ReservesInfo): void { - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'poolReservesInfo', 'poolReservesInfo(address):(uint256,uint256,uint256,uint256,uint256)') - .withArgs([ethereum.Value.fromAddress(pool)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedInfo.reserves), - ethereum.Value.fromUnsignedBigInt(expectedInfo.claimableReserves), - ethereum.Value.fromUnsignedBigInt(expectedInfo.claimableReservesRemaining), - ethereum.Value.fromUnsignedBigInt(expectedInfo.reserveAuctionPrice), - ethereum.Value.fromUnsignedBigInt(expectedInfo.reserveAuctionTimeRemaining) - ]) -} - -// mock getPoolUtilizationInfo contract calls -export function mockGetPoolUtilizationInfo(pool: Address, expectedInfo: PoolUtilizationInfo): void { - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'poolUtilizationInfo', 'poolUtilizationInfo(address):(uint256,uint256,uint256,uint256)') - .withArgs([ethereum.Value.fromAddress(pool)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedInfo.minDebtAmount), - ethereum.Value.fromUnsignedBigInt(expectedInfo.collateralization), - ethereum.Value.fromUnsignedBigInt(expectedInfo.actualUtilization), - ethereum.Value.fromUnsignedBigInt(expectedInfo.targetUtilization) - ]) -} - -// mock auctionInfo contract calls -export function mockGetAuctionInfo(borrower: Address, pool: Address, expectedInfo: AuctionInfo): void { - createMockedFunction(pool, 'auctionInfo', 'auctionInfo(address):(address,uint256,uint256,uint256,uint256,uint256,address,address,address,bool)') - .withArgs([ethereum.Value.fromAddress(borrower)]) - .returns([ - ethereum.Value.fromAddress(expectedInfo.kicker), - ethereum.Value.fromUnsignedBigInt(expectedInfo.bondFactor), - ethereum.Value.fromUnsignedBigInt(expectedInfo.bondSize), - ethereum.Value.fromUnsignedBigInt(expectedInfo.kickTime), - ethereum.Value.fromUnsignedBigInt(expectedInfo.kickMomp), - ethereum.Value.fromUnsignedBigInt(expectedInfo.neutralPrice), - ethereum.Value.fromAddress(expectedInfo.head), - ethereum.Value.fromAddress(expectedInfo.next), - ethereum.Value.fromAddress(expectedInfo.prev), - ethereum.Value.fromBoolean(expectedInfo.alreadyTaken) - ]) -} - -// mock auctionStatus poolInfoUtils calls -export function mockGetAuctionStatus(pool: Address, borrower: Address, expectedInfo: AuctionStatus): void { - createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, - 'auctionStatus', 'auctionStatus(address,address):(uint256,uint256,uint256,bool,uint256,uint256)') - .withArgs([ethereum.Value.fromAddress(pool), ethereum.Value.fromAddress(borrower)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedInfo.kickTime), - ethereum.Value.fromUnsignedBigInt(expectedInfo.collateral), - ethereum.Value.fromUnsignedBigInt(expectedInfo.debtToCover), - ethereum.Value.fromBoolean(expectedInfo.isCollateralized), - ethereum.Value.fromUnsignedBigInt(expectedInfo.price), - ethereum.Value.fromUnsignedBigInt(expectedInfo.neutralPrice) - ]) -} - -// mock currentBurnEpoch contract calls -export function mockGetCurrentBurnEpoch(pool: Address, expectedEpoch: BigInt): void { - createMockedFunction(pool, 'currentBurnEpoch', 'currentBurnEpoch():(uint256)') - .withArgs([]) - .returns([ethereum.Value.fromUnsignedBigInt(expectedEpoch)]) -} - -// mock burnInfo contract calls -export function mockGetBurnInfo(pool: Address, burnEpoch: BigInt, expectedInfo: BurnInfo): void { - createMockedFunction(pool, 'burnInfo', 'burnInfo(uint256):(uint256,uint256,uint256)') - .withArgs([ethereum.Value.fromUnsignedBigInt(burnEpoch)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedInfo.timestamp), - ethereum.Value.fromUnsignedBigInt(expectedInfo.totalInterest), - ethereum.Value.fromUnsignedBigInt(expectedInfo.totalBurned) - ]) -} - -export function mockGetTokenInfo(token: Address, expectedName: string, expectedSymbol: string, expectedDecimals: BigInt, expectedTotalSupply: BigInt): void { - createMockedFunction(token, 'name', 'name():(string)') - .withArgs([]) - .returns([ethereum.Value.fromString(expectedName)]) - createMockedFunction(token, 'symbol', 'symbol():(string)') - .withArgs([]) - .returns([ethereum.Value.fromString(expectedSymbol)]) - createMockedFunction(token, 'decimals', 'decimals():(uint8)') - .withArgs([]) - .returns([ethereum.Value.fromUnsignedBigInt(expectedDecimals)]) - createMockedFunction(token, 'totalSupply', 'totalSupply():(uint256)') - .withArgs([]) - .returns([ethereum.Value.fromUnsignedBigInt(expectedTotalSupply)]) -} - -export function mockGetERC721TokenInfo(token: Address, expectedName: string, expectedSymbol: string): void { - createMockedFunction(token, 'name', 'name():(string)') - .withArgs([]) - .returns([ethereum.Value.fromString(expectedName)]) - createMockedFunction(token, 'symbol', 'symbol():(string)') - .withArgs([]) - .returns([ethereum.Value.fromString(expectedSymbol)]) -} - -export function mockDepositUpToIndex(pool: Address, index: BigInt, expectedInfo: BigInt): void { - createMockedFunction(pool, 'depositUpToIndex', 'depositUpToIndex(uint256):(uint256)') - .withArgs([ethereum.Value.fromUnsignedBigInt(index)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedInfo) - ]) -} - -export class PoolMockParams { - // loans info mock params - poolSize: BigInt - debt: BigInt - loansCount: BigInt - maxBorrower: Address - inflator: BigInt - // prices info mock params - hpb: BigInt - hpbIndex: BigInt - htp: BigInt - htpIndex: BigInt - lup: BigInt - lupIndex: BigInt - momp: BigInt - // reserves info mock params - reserves: BigInt - claimableReserves: BigInt - claimableReservesRemaining: BigInt - currentBurnEpoch: BigInt - reserveAuctionPrice: BigInt - reserveAuctionTimeRemaining: BigInt - // utilization info mock params - minDebtAmount: BigInt - collateralization: BigInt - actualUtilization: BigInt - targetUtilization: BigInt -} -// mock all pool poolInfoUtilis contract calls -export function mockPoolInfoUtilsPoolUpdateCalls(pool: Address, params: PoolMockParams): void { - const expectedPoolLoansInfo = new LoansInfo( - params.poolSize, - params.loansCount, - params.maxBorrower, - params.inflator, - ONE_BI - ) - mockGetPoolLoansInfo(pool, expectedPoolLoansInfo) - - const expectedPoolDebtInfo = new DebtInfo(params.debt, ZERO_BI, ZERO_BI, ZERO_BI) - mockGetDebtInfo(pool, expectedPoolDebtInfo) - - const expectedPoolPricesInfo = new PoolPricesInfo( - params.hpb, - params.hpbIndex, - params.htp, - params.htpIndex, - params.lup, - params.lupIndex - ) - mockGetPoolPricesInfo(pool, expectedPoolPricesInfo) - - mockGetPoolMomp(pool, params.momp) - - const expectedPoolReservesInfo = new ReservesInfo( - params.reserves, - params.claimableReserves, - params.claimableReservesRemaining, - params.reserveAuctionPrice, - params.reserveAuctionTimeRemaining - ) - mockGetPoolReserves(pool, expectedPoolReservesInfo) - - const expectedPoolUtilizationInfo = new PoolUtilizationInfo( - params.minDebtAmount, - params.collateralization, - params.actualUtilization, - params.targetUtilization - ) - mockGetPoolUtilizationInfo(pool, expectedPoolUtilizationInfo) - - mockGetRatesAndFees( - pool, - BigInt.fromString("850000000000000000"), // 0.85 * 1e18 - BigInt.fromString("50000000000000000"), // 0.05 * 1e18 - ) - - mockDepositUpToIndex(pool, params.lupIndex, wmul(params.poolSize, params.actualUtilization)) -} - -/****************************/ -/*** Token Mock Functions ***/ -/****************************/ - -export function mockTokenBalance(tokenAddress: Address, address: Address, expectedBalance: BigInt): void { - createMockedFunction(tokenAddress, 'balanceOf', 'balanceOf(address):(uint256)') - .withArgs([ethereum.Value.fromAddress(address)]) - .returns([ - ethereum.Value.fromUnsignedBigInt(expectedBalance), - ]) -} - -/*************************/ -/*** Utility Functions ***/ -/*************************/ - // CURRENTLY ERC721 POOLS ONLY export function createAndHandleAddQuoteTokenEvent(poolAddress: Address, lender: Address, index: BigInt, price: BigDecimal, amount: BigInt, lpAwarded: BigInt, lup: BigInt, logIndex: BigInt): void { // mock required contract calls diff --git a/tests/utils/mock-contract-calls.ts b/tests/utils/mock-contract-calls.ts new file mode 100644 index 0000000..f55fefa --- /dev/null +++ b/tests/utils/mock-contract-calls.ts @@ -0,0 +1,409 @@ +import { Address, BigInt, Bytes, ethereum, dataSource, log, BigDecimal } from "@graphprotocol/graph-ts" +import { createMockedFunction } from "matchstick-as" + +import { BucketInfo } from "../../src/utils/pool/bucket" +import { positionManagerAddressTable, poolInfoUtilsAddressTable, ZERO_BI, ONE_BI } from "../../src/utils/constants" +import { BurnInfo, DebtInfo, LoansInfo, PoolPricesInfo, PoolUtilizationInfo, ReservesInfo } from "../../src/utils/pool/pool" +import { AuctionInfo, AuctionStatus } from "../../src/utils/pool/liquidation" +import { BorrowerInfo } from "../../src/utils/pool/loan" +import { wdiv, wmin, wmul } from "../../src/utils/math" + + +/*********************************/ +/*** Grant Fund Mock Functions ***/ +/*********************************/ + +// mock burnInfo contract calls +export function mockGetDistributionId(grantFund: Address, expectedDistributionId: BigInt): void { + createMockedFunction(grantFund, 'getDistributionId', 'getDistributionId():(uint24)') + .withArgs([]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedDistributionId), + ]) +} + +export function mockGetVotesScreening(grantFund: Address, distributionId: BigInt, voter: Address, expectedVotes: BigInt): void { + createMockedFunction(grantFund, 'getVotesScreening', 'getVotesScreening(uint24,address):(uint256)') + .withArgs([ + ethereum.Value.fromUnsignedBigInt(distributionId), + ethereum.Value.fromAddress(voter) + ]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedVotes), + ]) +} + +export function mockGetVotesFunding(grantFund: Address, distributionId: BigInt, voter: Address, expectedVotes: BigInt): void { + createMockedFunction(grantFund, 'getVotesFunding', 'getVotesFunding(uint24,address):(uint256)') + .withArgs([ + ethereum.Value.fromUnsignedBigInt(distributionId), + ethereum.Value.fromAddress(voter) + ]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedVotes), + ]) +} + +export function mockGetTreasury(grantFund: Address, expectedTreasury: BigInt): void { + createMockedFunction(grantFund, 'treasury', 'treasury():(uint256)') + .withArgs([]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedTreasury), + ]) +} + +export function mockGetFundedProposalSlate(grantFund: Address, slateHash: Bytes, expectedProposals: Array): void { + createMockedFunction(grantFund, 'getFundedProposalSlate', 'getFundedProposalSlate(bytes32):(uint256[])') + .withArgs([ + ethereum.Value.fromFixedBytes(slateHash) + ]) + .returns([ + ethereum.Value.fromUnsignedBigIntArray(expectedProposals), + ]) +} + +/*******************************/ +/*** Position Mock Functions ***/ +/*******************************/ + +export function mockGetTokenName(tokenContract: Address, expectedName: String): void { + createMockedFunction( + tokenContract, + 'name', + 'name():(string)' + ) + .withArgs([]) + .returns([ + ethereum.Value.fromString(expectedName), + ]) +} + +export function mockGetTokenSymbol(tokenContract: Address, expectedSymbol: String): void { + createMockedFunction( + tokenContract, + 'symbol', + 'symbol():(string)' + ) + .withArgs([]) + .returns([ + ethereum.Value.fromString(expectedSymbol), + ]) +} + +export function mockGetPoolKey(tokenId: BigInt, expectedPoolAddress: Address): void { + createMockedFunction( + positionManagerAddressTable.get(dataSource.network())!, + 'poolKey', + 'poolKey(uint256):(address)' + ) + .withArgs([ethereum.Value.fromUnsignedBigInt(tokenId)]) + .returns([ + ethereum.Value.fromAddress(expectedPoolAddress), + ]) +} + +/***************************/ +/*** Pool Mock Functions ***/ +/***************************/ + +export function mockGetBorrowerInfo(pool: Address, borrower: Address, expectedInfo: BorrowerInfo): void { + createMockedFunction(pool, 'borrowerInfo', 'borrowerInfo(address):(uint256,uint256,uint256)') + .withArgs([ethereum.Value.fromAddress(borrower)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedInfo.t0debt), + ethereum.Value.fromUnsignedBigInt(expectedInfo.collateral), + ethereum.Value.fromUnsignedBigInt(expectedInfo.t0Np) + ]) +} + +// mock getBucketInfo contract calls +export function mockGetBucketInfo(pool: Address, bucketIndex: BigInt, expectedInfo: BucketInfo): void { + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'bucketInfo', 'bucketInfo(address,uint256):(uint256,uint256,uint256,uint256,uint256,uint256)') + .withArgs([ethereum.Value.fromAddress(pool), ethereum.Value.fromUnsignedBigInt(bucketIndex)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(123456789)), + ethereum.Value.fromUnsignedBigInt(expectedInfo.quoteTokens), + ethereum.Value.fromUnsignedBigInt(expectedInfo.collateral), + ethereum.Value.fromUnsignedBigInt(expectedInfo.lpb), + ethereum.Value.fromUnsignedBigInt(expectedInfo.scale), + ethereum.Value.fromUnsignedBigInt(expectedInfo.exchangeRate) + ]) +} + +export function mockGetDebtInfo(pool: Address, expectInfo: DebtInfo): void { + createMockedFunction(pool, 'debtInfo', 'debtInfo():(uint256,uint256,uint256,uint256)') + .returns([ + ethereum.Value.fromUnsignedBigInt(expectInfo.pendingDebt), + ethereum.Value.fromUnsignedBigInt(expectInfo.accruedDebt), + ethereum.Value.fromUnsignedBigInt(expectInfo.liquidationDebt), + ethereum.Value.fromUnsignedBigInt(expectInfo.t0Debt2ToCollateral) + ]) +} + +export function mockGetRatesAndFees(pool: Address, expectedLenderInterestMargin: BigInt, borrowRate: BigInt): void { + // return Maths.max(Maths.wdiv(interestRate_, 52 * 1e18), 0.0005 * 1e18); + const expectedBorrowFeeRate = wmin(wdiv(borrowRate, BigInt.fromString("52000000000000000000")), BigInt.fromString("500000000000000")); + // return Maths.min(Maths.wdiv(interestRate_, 365 * 1e18), 0.1 * 1e18); + const expectedDepositFeeRate = wmin(wdiv(borrowRate, BigInt.fromString("365000000000000000000")), BigInt.fromString("100000000000000000")); + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'lenderInterestMargin', 'lenderInterestMargin(address):(uint256)') + .withArgs([ethereum.Value.fromAddress(pool)]) + .returns([ethereum.Value.fromUnsignedBigInt(expectedLenderInterestMargin)]) + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'borrowFeeRate', 'borrowFeeRate(address):(uint256)') + .withArgs([ethereum.Value.fromAddress(pool)]) + .returns([ethereum.Value.fromUnsignedBigInt(expectedBorrowFeeRate)]) + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'unutilizedDepositFeeRate', 'unutilizedDepositFeeRate(address):(uint256)') + .withArgs([ethereum.Value.fromAddress(pool)]) + .returns([ethereum.Value.fromUnsignedBigInt(expectedDepositFeeRate)]) +} + +// mock getLPBValueInQuote contract calls +export function mockGetLPBValueInQuote(pool: Address, lpb: BigInt, bucketIndex: BigInt, expectedValue: BigInt): void { + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'lpToQuoteTokens', 'lpToQuoteTokens(address,uint256,uint256):(uint256)') + .withArgs([ethereum.Value.fromAddress(pool), ethereum.Value.fromUnsignedBigInt(lpb), ethereum.Value.fromUnsignedBigInt(bucketIndex)]) + .returns([ethereum.Value.fromUnsignedBigInt(expectedValue)]) +} + +export function mockGetLenderInfo(pool: Address, bucketIndex: BigInt, lender: Address, expectedLPB: BigInt, expectedDepositTime: BigInt): void { + createMockedFunction(pool, 'lenderInfo', 'lenderInfo(uint256,address):(uint256,uint256)') + .withArgs([ethereum.Value.fromUnsignedBigInt(bucketIndex), ethereum.Value.fromAddress(lender)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedLPB), + ethereum.Value.fromUnsignedBigInt(expectedDepositTime) + ]) +} + +// mock getPoolLoansInfo contract calls +export function mockGetPoolLoansInfo(pool: Address, expectedInfo: LoansInfo): void { + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'poolLoansInfo', 'poolLoansInfo(address):(uint256,uint256,address,uint256,uint256)') + .withArgs([ethereum.Value.fromAddress(pool)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedInfo.poolSize), + ethereum.Value.fromUnsignedBigInt(expectedInfo.loansCount), + ethereum.Value.fromAddress(expectedInfo.maxBorrower), + ethereum.Value.fromUnsignedBigInt(expectedInfo.pendingInflator), + ethereum.Value.fromUnsignedBigInt(expectedInfo.pendingInterestFactor) + ]) +} + +// mock getPoolPricesInfo contract calls +export function mockGetPoolPricesInfo(pool: Address, expectedInfo: PoolPricesInfo): void { + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'poolPricesInfo', 'poolPricesInfo(address):(uint256,uint256,uint256,uint256,uint256,uint256)') + .withArgs([ethereum.Value.fromAddress(pool)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedInfo.hpb), + ethereum.Value.fromUnsignedBigInt(expectedInfo.hpbIndex), + ethereum.Value.fromUnsignedBigInt(expectedInfo.htp), + ethereum.Value.fromUnsignedBigInt(expectedInfo.htpIndex), + ethereum.Value.fromUnsignedBigInt(expectedInfo.lup), + ethereum.Value.fromUnsignedBigInt(expectedInfo.lupIndex) + ]) +} + +// mock getMomp contract calls +export function mockGetPoolMomp(pool: Address, expectedInfo: BigInt): void { + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'momp', 'momp(address):(uint256)') + .withArgs([ethereum.Value.fromAddress(pool)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedInfo) + ]) +} + +// mock getPoolReserves contract calls +export function mockGetPoolReserves(pool: Address, expectedInfo: ReservesInfo): void { + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'poolReservesInfo', 'poolReservesInfo(address):(uint256,uint256,uint256,uint256,uint256)') + .withArgs([ethereum.Value.fromAddress(pool)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedInfo.reserves), + ethereum.Value.fromUnsignedBigInt(expectedInfo.claimableReserves), + ethereum.Value.fromUnsignedBigInt(expectedInfo.claimableReservesRemaining), + ethereum.Value.fromUnsignedBigInt(expectedInfo.reserveAuctionPrice), + ethereum.Value.fromUnsignedBigInt(expectedInfo.reserveAuctionTimeRemaining) + ]) +} + +// mock getPoolUtilizationInfo contract calls +export function mockGetPoolUtilizationInfo(pool: Address, expectedInfo: PoolUtilizationInfo): void { + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'poolUtilizationInfo', 'poolUtilizationInfo(address):(uint256,uint256,uint256,uint256)') + .withArgs([ethereum.Value.fromAddress(pool)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedInfo.minDebtAmount), + ethereum.Value.fromUnsignedBigInt(expectedInfo.collateralization), + ethereum.Value.fromUnsignedBigInt(expectedInfo.actualUtilization), + ethereum.Value.fromUnsignedBigInt(expectedInfo.targetUtilization) + ]) +} + +// mock auctionInfo contract calls +export function mockGetAuctionInfo(borrower: Address, pool: Address, expectedInfo: AuctionInfo): void { + createMockedFunction(pool, 'auctionInfo', 'auctionInfo(address):(address,uint256,uint256,uint256,uint256,uint256,address,address,address,bool)') + .withArgs([ethereum.Value.fromAddress(borrower)]) + .returns([ + ethereum.Value.fromAddress(expectedInfo.kicker), + ethereum.Value.fromUnsignedBigInt(expectedInfo.bondFactor), + ethereum.Value.fromUnsignedBigInt(expectedInfo.bondSize), + ethereum.Value.fromUnsignedBigInt(expectedInfo.kickTime), + ethereum.Value.fromUnsignedBigInt(expectedInfo.kickMomp), + ethereum.Value.fromUnsignedBigInt(expectedInfo.neutralPrice), + ethereum.Value.fromAddress(expectedInfo.head), + ethereum.Value.fromAddress(expectedInfo.next), + ethereum.Value.fromAddress(expectedInfo.prev), + ethereum.Value.fromBoolean(expectedInfo.alreadyTaken) + ]) +} + +// mock auctionStatus poolInfoUtils calls +export function mockGetAuctionStatus(pool: Address, borrower: Address, expectedInfo: AuctionStatus): void { + createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, + 'auctionStatus', 'auctionStatus(address,address):(uint256,uint256,uint256,bool,uint256,uint256)') + .withArgs([ethereum.Value.fromAddress(pool), ethereum.Value.fromAddress(borrower)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedInfo.kickTime), + ethereum.Value.fromUnsignedBigInt(expectedInfo.collateral), + ethereum.Value.fromUnsignedBigInt(expectedInfo.debtToCover), + ethereum.Value.fromBoolean(expectedInfo.isCollateralized), + ethereum.Value.fromUnsignedBigInt(expectedInfo.price), + ethereum.Value.fromUnsignedBigInt(expectedInfo.neutralPrice) + ]) +} + +// mock currentBurnEpoch contract calls +export function mockGetCurrentBurnEpoch(pool: Address, expectedEpoch: BigInt): void { + createMockedFunction(pool, 'currentBurnEpoch', 'currentBurnEpoch():(uint256)') + .withArgs([]) + .returns([ethereum.Value.fromUnsignedBigInt(expectedEpoch)]) +} + +// mock burnInfo contract calls +export function mockGetBurnInfo(pool: Address, burnEpoch: BigInt, expectedInfo: BurnInfo): void { + createMockedFunction(pool, 'burnInfo', 'burnInfo(uint256):(uint256,uint256,uint256)') + .withArgs([ethereum.Value.fromUnsignedBigInt(burnEpoch)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedInfo.timestamp), + ethereum.Value.fromUnsignedBigInt(expectedInfo.totalInterest), + ethereum.Value.fromUnsignedBigInt(expectedInfo.totalBurned) + ]) +} + +export function mockGetTokenInfo(token: Address, expectedName: string, expectedSymbol: string, expectedDecimals: BigInt, expectedTotalSupply: BigInt): void { + createMockedFunction(token, 'name', 'name():(string)') + .withArgs([]) + .returns([ethereum.Value.fromString(expectedName)]) + createMockedFunction(token, 'symbol', 'symbol():(string)') + .withArgs([]) + .returns([ethereum.Value.fromString(expectedSymbol)]) + createMockedFunction(token, 'decimals', 'decimals():(uint8)') + .withArgs([]) + .returns([ethereum.Value.fromUnsignedBigInt(expectedDecimals)]) + createMockedFunction(token, 'totalSupply', 'totalSupply():(uint256)') + .withArgs([]) + .returns([ethereum.Value.fromUnsignedBigInt(expectedTotalSupply)]) +} + +export function mockGetERC721TokenInfo(token: Address, expectedName: string, expectedSymbol: string): void { + createMockedFunction(token, 'name', 'name():(string)') + .withArgs([]) + .returns([ethereum.Value.fromString(expectedName)]) + createMockedFunction(token, 'symbol', 'symbol():(string)') + .withArgs([]) + .returns([ethereum.Value.fromString(expectedSymbol)]) +} + +export function mockDepositUpToIndex(pool: Address, index: BigInt, expectedInfo: BigInt): void { + createMockedFunction(pool, 'depositUpToIndex', 'depositUpToIndex(uint256):(uint256)') + .withArgs([ethereum.Value.fromUnsignedBigInt(index)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedInfo) + ]) +} + +export class PoolMockParams { + // loans info mock params + poolSize: BigInt + debt: BigInt + loansCount: BigInt + maxBorrower: Address + inflator: BigInt + // prices info mock params + hpb: BigInt + hpbIndex: BigInt + htp: BigInt + htpIndex: BigInt + lup: BigInt + lupIndex: BigInt + momp: BigInt + // reserves info mock params + reserves: BigInt + claimableReserves: BigInt + claimableReservesRemaining: BigInt + currentBurnEpoch: BigInt + reserveAuctionPrice: BigInt + reserveAuctionTimeRemaining: BigInt + // utilization info mock params + minDebtAmount: BigInt + collateralization: BigInt + actualUtilization: BigInt + targetUtilization: BigInt +} +// mock all pool poolInfoUtilis contract calls +export function mockPoolInfoUtilsPoolUpdateCalls(pool: Address, params: PoolMockParams): void { + const expectedPoolLoansInfo = new LoansInfo( + params.poolSize, + params.loansCount, + params.maxBorrower, + params.inflator, + ONE_BI + ) + mockGetPoolLoansInfo(pool, expectedPoolLoansInfo) + + const expectedPoolDebtInfo = new DebtInfo(params.debt, ZERO_BI, ZERO_BI, ZERO_BI) + mockGetDebtInfo(pool, expectedPoolDebtInfo) + + const expectedPoolPricesInfo = new PoolPricesInfo( + params.hpb, + params.hpbIndex, + params.htp, + params.htpIndex, + params.lup, + params.lupIndex + ) + mockGetPoolPricesInfo(pool, expectedPoolPricesInfo) + + mockGetPoolMomp(pool, params.momp) + + const expectedPoolReservesInfo = new ReservesInfo( + params.reserves, + params.claimableReserves, + params.claimableReservesRemaining, + params.reserveAuctionPrice, + params.reserveAuctionTimeRemaining + ) + mockGetPoolReserves(pool, expectedPoolReservesInfo) + + const expectedPoolUtilizationInfo = new PoolUtilizationInfo( + params.minDebtAmount, + params.collateralization, + params.actualUtilization, + params.targetUtilization + ) + mockGetPoolUtilizationInfo(pool, expectedPoolUtilizationInfo) + + mockGetRatesAndFees( + pool, + BigInt.fromString("850000000000000000"), // 0.85 * 1e18 + BigInt.fromString("50000000000000000"), // 0.05 * 1e18 + ) + + mockDepositUpToIndex(pool, params.lupIndex, wmul(params.poolSize, params.actualUtilization)) +} + +/****************************/ +/*** Token Mock Functions ***/ +/****************************/ + +export function mockTokenBalance(tokenAddress: Address, address: Address, expectedBalance: BigInt): void { + createMockedFunction(tokenAddress, 'balanceOf', 'balanceOf(address):(uint256)') + .withArgs([ethereum.Value.fromAddress(address)]) + .returns([ + ethereum.Value.fromUnsignedBigInt(expectedBalance), + ]) +} diff --git a/tests/utils/position-manager-utils.ts b/tests/utils/position-manager-utils.ts index d7cba5b..7db4e04 100644 --- a/tests/utils/position-manager-utils.ts +++ b/tests/utils/position-manager-utils.ts @@ -10,8 +10,8 @@ import { RedeemPosition, Transfer } from "../../generated/PositionManager/PositionManager" -import { mockGetPoolKey, mockGetTokenName, mockGetTokenSymbol } from "./common" -import { handleMint } from "../../src/position-manager" +import { mockGetPoolKey, mockGetTokenName, mockGetTokenSymbol } from "./mock-contract-calls" +import { handleMint } from "../../src/mappings/position-manager" import { bigIntToBytes } from "../../src/utils/convert" export function createApprovalEvent(