Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move pool utils into pools directory #39

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/erc-20-pool-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
} from "./utils/constants"
import { addressToBytes, wadToDecimal } from "./utils/convert"
import { getTokenDecimals, getTokenName, getTokenSymbol, getTokenTotalSupply } from "./utils/token-erc20"
import { getRatesAndFees } from "./utils/pool"
import { loadOrCreateFactory } from "./utils/pool-factory"
import { getRatesAndFees } from "./utils/pool/pool"
import { loadOrCreateFactory } from "./utils/pool/pool-factory"

export function handlePoolCreated(event: PoolCreatedEvent): void {
const poolCreated = new PoolCreated(
Expand Down
16 changes: 8 additions & 8 deletions src/erc-20-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ import {
import { ZERO_BD, ONE_BI, TEN_BI } from "./utils/constants"
import { addressToBytes, bigIntArrayToIntArray, wadToDecimal } from "./utils/convert"
import { loadOrCreateAccount, updateAccountLends, updateAccountLoans, updateAccountPools, updateAccountKicks, updateAccountTakes, updateAccountSettles, updateAccountReserveAuctions } from "./utils/account"
import { getBucketId, getBucketInfo, loadOrCreateBucket } from "./utils/bucket"
import { getLendId, loadOrCreateLend } from "./utils/lend"
import { getBorrowerInfo, getLoanId, loadOrCreateLoan } from "./utils/loan"
import { getLiquidationAuctionId, getAuctionInfoERC20Pool, loadOrCreateLiquidationAuction, updateLiquidationAuction, getAuctionStatus, loadOrCreateBucketTake } from "./utils/liquidation"
import { getBurnInfo, updatePool, addLiquidationToPool, addReserveAuctionToPool, getLenderInfo, getRatesAndFees, calculateLendRate } from "./utils/pool"
import { getBucketId, getBucketInfo, loadOrCreateBucket } 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, getLenderInfo, getRatesAndFees, calculateLendRate } from "./utils/pool/pool"
import { lpbValueInQuote } from "./utils/common"
import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "./utils/reserve-auction"
import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "./utils/pool/reserve-auction"
import { incrementTokenTxCount } from "./utils/token-erc20"
import { approveTransferors, loadOrCreateTransferors, revokeTransferors } from "./utils/lp-transferors"
import { loadOrCreateAllowances, increaseAllowances, decreaseAllowances, revokeAllowances } from "./utils/lp-allowances"
import { approveTransferors, loadOrCreateTransferors, revokeTransferors } from "./utils/pool/lp-transferors"
import { loadOrCreateAllowances, increaseAllowances, decreaseAllowances, revokeAllowances } from "./utils/pool/lp-allowances"

export function handleAddCollateral(event: AddCollateralEvent): void {
const addCollateral = new AddCollateral(
Expand Down
2 changes: 1 addition & 1 deletion src/erc-721-pool-factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PoolCreated as PoolCreatedEvent } from "../generated/ERC721PoolFactory/ERC721PoolFactory"
import { Pool, PoolCreated, Token } from "../generated/schema"
import { ONE_BI } from "./utils/constants"
import { loadOrCreateFactory } from "./utils/pool-factory"
import { loadOrCreateFactory } from "./utils/pool/pool-factory"

export function handlePoolCreated(event: PoolCreatedEvent): void {
const poolCreated = new PoolCreated(
Expand Down
4 changes: 2 additions & 2 deletions src/position-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import {
RedeemPosition,
Transfer
} from "../generated/schema"
import { getBucketId } from "./utils/bucket"
import { getBucketId } from "./utils/pool/bucket"
import { lpbValueInQuote } from "./utils/common"
import { ONE_BI, ZERO_BD } from "./utils/constants"
import { addressToBytes, bigIntArrayToIntArray, wadToDecimal } from "./utils/convert"
import { getLendId, loadOrCreateLend } from "./utils/lend"
import { getLendId, loadOrCreateLend } from "./utils/pool/lend"
import { deletePosition, getPoolForToken, loadOrCreateLPToken, loadOrCreatePosition } from "./utils/position"

export function handleApproval(event: ApprovalEvent): void {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/bucket.ts → src/utils/pool/bucket.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Address, BigDecimal, BigInt, Bytes, dataSource, log } from "@graphprotocol/graph-ts"

import { Bucket } from "../../generated/schema"
import { PoolInfoUtils } from '../../generated/templates/ERC20Pool/PoolInfoUtils'
import { Bucket } from "../../../generated/schema"
import { PoolInfoUtils } from '../../../generated/templates/ERC20Pool/PoolInfoUtils'

import { poolInfoUtilsAddressTable, ONE_BD, ZERO_BD } from "./constants"
import { indexToPrice, wadToDecimal } from "./convert"
import { poolInfoUtilsAddressTable, ONE_BD, ZERO_BD } from "../constants"
import { indexToPrice, wadToDecimal } from "../convert"

export function getBucketId(pool: Bytes, index: u32): Bytes {
return pool.concat(Bytes.fromUTF8('#' + index.toString()))
Expand Down
4 changes: 2 additions & 2 deletions src/utils/lend.ts → src/utils/pool/lend.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigInt, Bytes } from "@graphprotocol/graph-ts"
import { Lend } from "../../generated/schema"
import { Lend } from "../../../generated/schema"

import { ZERO_BD, ZERO_BI } from "./constants"
import { ZERO_BD, ZERO_BI } from "../constants"


export function getLendId(bucketId: Bytes, accountId: Bytes): Bytes {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/liquidation.ts → src/utils/pool/liquidation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Address, BigDecimal, BigInt, Bytes, Value, dataSource } from "@graphprotocol/graph-ts"

import { LiquidationAuction, Kick, Loan, Pool, BucketTake } from "../../generated/schema"
import { ERC20Pool } from '../../generated/templates/ERC20Pool/ERC20Pool'
import { LiquidationAuction, Kick, Loan, Pool, BucketTake } from "../../../generated/schema"
import { ERC20Pool } from '../../../generated/templates/ERC20Pool/ERC20Pool'

import { wadToDecimal } from "./convert"
import { ONE_BI, ZERO_ADDRESS, ZERO_BD, ZERO_BI, poolInfoUtilsAddressTable } from "./constants"
import { PoolInfoUtils } from "../../generated/templates/ERC20Pool/PoolInfoUtils"
import { wadToDecimal } from "../convert"
import { ONE_BI, ZERO_ADDRESS, ZERO_BD, ZERO_BI, poolInfoUtilsAddressTable } from "../constants"
import { PoolInfoUtils } from "../../../generated/templates/ERC20Pool/PoolInfoUtils"

export function getLiquidationAuctionId(poolId: Bytes, loanId: Bytes, kickBlock: BigInt): Bytes {
return poolId.concat(Bytes.fromUTF8('|' + loanId.toString() + '|' + kickBlock.toString()))
Expand Down
8 changes: 4 additions & 4 deletions src/utils/loan.ts → src/utils/pool/loan.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Address, BigDecimal, BigInt, Bytes, dataSource } from "@graphprotocol/graph-ts"
import { PoolInfoUtils } from "../../generated/templates/ERC20Pool/PoolInfoUtils"
import { PoolInfoUtils } from "../../../generated/templates/ERC20Pool/PoolInfoUtils"

import { Loan } from "../../generated/schema"
import { poolInfoUtilsAddressTable, ZERO_BD, ZERO_BI } from "./constants"
import { ERC20Pool } from '../../generated/templates/ERC20Pool/ERC20Pool'
import { Loan } from "../../../generated/schema"
import { poolInfoUtilsAddressTable, ZERO_BD, ZERO_BI } from "../constants"
import { ERC20Pool } from '../../../generated/templates/ERC20Pool/ERC20Pool'

export function getLoanId(poolId: Bytes, accountId: Bytes): Bytes {
return poolId.concat(Bytes.fromUTF8('|').concat(accountId))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts"
import { LPAllowance, LPAllowances } from "../../generated/schema";
import { wadToDecimal } from "./convert";
import { LPAllowance, LPAllowances } from "../../../generated/schema";
import { wadToDecimal } from "../convert";

export function getAllowancesId(poolId: Bytes, lenderId: Bytes, spenderId: Bytes): Bytes {
return poolId.concat(Bytes.fromUTF8('|' + lenderId.toString() + '|' + spenderId.toString()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, Bytes } from "@graphprotocol/graph-ts"
import { LPTransferorList, Pool } from "../../generated/schema";
import { LPTransferorList, Pool } from "../../../generated/schema";

export function getTransferorId(poolId: Bytes, lenderId: Bytes): Bytes {
return poolId.concat(Bytes.fromUTF8('|' + lenderId.toString()));
Expand Down
4 changes: 2 additions & 2 deletions src/utils/pool-factory.ts → src/utils/pool/pool-factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address } from "@graphprotocol/graph-ts"
import { PoolFactory } from "../../generated/schema"
import { PoolFactory } from "../../../generated/schema"

import { ZERO_BI } from "./constants"
import { ZERO_BI } from "../constants"

export function loadOrCreateFactory(address: Address, poolType: string): PoolFactory {
let factory = PoolFactory.load(address)
Expand Down
16 changes: 8 additions & 8 deletions src/utils/pool.ts → src/utils/pool/pool.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BigDecimal, BigInt, Bytes, Address, dataSource } from '@graphprotocol/graph-ts'

import { LiquidationAuction, Pool, ReserveAuction, Token } from "../../generated/schema"
import { ERC20Pool } from '../../generated/templates/ERC20Pool/ERC20Pool'
import { PoolInfoUtils } from '../../generated/templates/ERC20Pool/PoolInfoUtils'

import { poolInfoUtilsAddressTable, TEN_BI } from "./constants"
import { decimalToWad, wadToDecimal } from './convert'
import { getTokenBalance } from './token-erc20'
import { wmul, wdiv } from './math'
import { LiquidationAuction, Pool, ReserveAuction, Token } from "../../../generated/schema"
import { ERC20Pool } from '../../../generated/templates/ERC20Pool/ERC20Pool'
import { PoolInfoUtils } from '../../../generated/templates/ERC20Pool/PoolInfoUtils'

import { poolInfoUtilsAddressTable, TEN_BI } from "../constants"
import { decimalToWad, wadToDecimal } from '../convert'
import { getTokenBalance } from '../token-erc20'
import { wmul, wdiv } from '../math'

export function getPoolAddress(poolId: Bytes): Address {
return Address.fromBytes(poolId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts"
import { Pool, ReserveAuction } from "../../generated/schema"
import { EXP_18_BD, ONE_BI, ZERO_BD, ZERO_BI } from "./constants"
import { Pool, ReserveAuction } from "../../../generated/schema"
import { EXP_18_BD, ONE_BI, ZERO_BD, ZERO_BI } from "../constants"

export function getReserveAuctionId(poolId: Bytes, burnEpoch: BigInt): Bytes {
return poolId.concat(Bytes.fromUTF8('|' + burnEpoch.toHexString()))
Expand Down
12 changes: 6 additions & 6 deletions tests/erc-20-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import {
mockPoolInfoUtilsPoolUpdateCalls,
mockTokenBalance
} from "./utils/common"
import { BucketInfo, getBucketId } from "../src/utils/bucket"
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, ZERO_ADDRESS, ZERO_BD, ZERO_BI } from "../src/utils/constants"
import { Account, Lend, Loan, Pool } from "../generated/schema"
import { getLendId } from "../src/utils/lend"
import { BorrowerInfo, getLoanId } from "../src/utils/loan"
import { AuctionInfo, AuctionStatus, getLiquidationAuctionId } from "../src/utils/liquidation"
import { BurnInfo, DebtInfo } from "../src/utils/pool"
import { getReserveAuctionId } from "../src/utils/reserve-auction"
import { getLendId } from "../src/utils/pool/lend"
import { BorrowerInfo, getLoanId } from "../src/utils/pool/loan"
import { AuctionInfo, AuctionStatus, getLiquidationAuctionId } from "../src/utils/pool/liquidation"
import { BurnInfo, DebtInfo } from "../src/utils/pool/pool"
import { getReserveAuctionId } from "../src/utils/pool/reserve-auction"
import { wdiv, wmul } from "../src/utils/math"

// Tests structure (matchstick-as >=0.5.0)
Expand Down
4 changes: 2 additions & 2 deletions tests/position-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { assertPosition, createApprovalEvent, createBurnEvent, createMemorialize
import { bigIntToBytes, wadToDecimal } from "../src/utils/convert"
import { mockGetLPBValueInQuote, mockGetPoolKey, mockGetTokenName, mockGetTokenSymbol } from "./utils/common"
import { Lend } from "../generated/schema"
import { getLendId, loadOrCreateLend } from "../src/utils/lend"
import { getBucketId } from "../src/utils/bucket"
import { getLendId, loadOrCreateLend } from "../src/utils/pool/lend"
import { getBucketId } from "../src/utils/pool/bucket"
import { ZERO_BI } from "../src/utils/constants"

// Tests structure (matchstick-as >=0.5.0)
Expand Down
8 changes: 4 additions & 4 deletions tests/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { assert, createMockedFunction } from "matchstick-as"
import { handlePoolCreated } from "../../src/erc-20-pool-factory"
import { createPoolCreatedEvent } from "./erc-20-pool-factory-utils"

import { BucketInfo } from "../../src/utils/bucket"
import { BucketInfo } from "../../src/utils/pool/bucket"
import { wadToDecimal } from "../../src/utils/convert"
import { positionManagerAddressTable, poolInfoUtilsAddressTable, ZERO_BI, ONE_BI } from "../../src/utils/constants"
import { BurnInfo, DebtInfo, LoansInfo, PoolPricesInfo, PoolUtilizationInfo, ReservesInfo } from "../../src/utils/pool"
import { AuctionInfo, AuctionStatus } from "../../src/utils/liquidation"
import { BorrowerInfo } from "../../src/utils/loan"
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 } from "../../src/utils/math"

/*************************/
Expand Down
Loading