Skip to content

Commit

Permalink
Directory Cleanups (#59)
Browse files Browse the repository at this point in the history
* move mappings files into mappings directory

* move mock functions into new mock-contract-calls file

---------

Co-authored-by: Mike <[email protected]>
  • Loading branch information
MikeHathaway and Mike authored Aug 21, 2023
1 parent 4508c3d commit 72ac2f0
Show file tree
Hide file tree
Showing 19 changed files with 528 additions and 524 deletions.
10 changes: 5 additions & 5 deletions src/ajna-token.ts → src/mappings/ajna-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
34 changes: 17 additions & 17 deletions src/erc-20-pool.ts → src/mappings/erc-20-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
34 changes: 17 additions & 17 deletions src/erc-721-pool.ts → src/mappings/erc-721-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"


/*******************************/
Expand Down
22 changes: 11 additions & 11 deletions src/grant-fund.ts → src/mappings/grant-fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/position-manager.ts → src/mappings/position-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions src/rewards-manager.ts → src/mappings/rewards-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 9 additions & 9 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion tests/erc-20-pool-factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading

0 comments on commit 72ac2f0

Please sign in to comment.