Skip to content

Commit

Permalink
Merge pull request #19 from ajna-finance/lendrate-bugfix
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
EdNoepel authored Jun 1, 2023
2 parents 85f3950 + 94c00b2 commit b81cd18
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/erc-20-pool-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
ONE_BI,
ZERO_BI,
ZERO_BD,
ONE_WAD_BD,
ZERO_ADDRESS,
ONE_BD,
erc20FactoryNetworkLookUpTable
} from "./utils/constants"
import { addressToBytes, wadToDecimal } from "./utils/convert"
import { getTokenDecimals, getTokenName, getTokenSymbol, getTokenTotalSupply } from "./utils/token-erc20"
import { wmul } from "./utils/math"

export function handlePoolCreated(event: PoolCreatedEvent): void {
const poolCreated = new PoolCreated(
Expand Down Expand Up @@ -98,7 +98,7 @@ export function handlePoolCreated(event: PoolCreatedEvent): void {
pool.feeRate = wadToDecimal(interestRateResults.value1)
pool.inflator = ONE_BD
pool.borrowRate = wadToDecimal(interestRateResults.value0)
pool.lendRate = wadToDecimal(interestRateResults.value0.times(lenderInterestMargin))
pool.lendRate = wadToDecimal(wmul(interestRateResults.value0, lenderInterestMargin))
pool.pledgedCollateral = ZERO_BD
pool.totalInterestEarned = ZERO_BD // updated on ReserveAuction
pool.txCount = ZERO_BI
Expand Down Expand Up @@ -131,9 +131,9 @@ export function handlePoolCreated(event: PoolCreatedEvent): void {

// utilization information
pool.minDebtAmount = ZERO_BD
pool.collateralization = ONE_WAD_BD
pool.collateralization = ONE_BD
pool.actualUtilization = ZERO_BD
pool.targetUtilization = ONE_WAD_BD
pool.targetUtilization = ONE_BD

// liquidation information
pool.totalBondEscrowed = ZERO_BD
Expand Down
4 changes: 2 additions & 2 deletions src/utils/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Address, BigDecimal, BigInt, Bytes, dataSource, log } from "@graphproto
import { Bucket } from "../../generated/schema"
import { PoolInfoUtils } from '../../generated/templates/ERC20Pool/PoolInfoUtils'

import { poolInfoUtilsNetworkLookUpTable, ONE_BD, ONE_BI, ZERO_BD, ZERO_BI, ONE_WAD_BD } from "./constants"
import { poolInfoUtilsNetworkLookUpTable, ONE_BD, ZERO_BD } from "./constants"
import { indexToPrice, wadToDecimal } from "./convert"

export function getBucketId(pool: Bytes, index: u32): Bytes {
Expand Down Expand Up @@ -58,7 +58,7 @@ export function loadOrCreateBucket(poolId: Bytes, bucketId: Bytes, index: u32):
bucket.poolAddress = poolId.toHexString()
bucket.collateral = ZERO_BD
bucket.deposit = ZERO_BD
bucket.exchangeRate = ONE_WAD_BD
bucket.exchangeRate = ONE_BD
bucket.lpb = ZERO_BD
}
return bucket
Expand Down
1 change: 0 additions & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const ONE_WAD_BI = BigInt.fromString("1000000000000000000")
export const ZERO_BD = BigDecimal.zero()
export const EXP_18_BD = BigDecimal.fromString('1000000000000000000')
export const ONE_BD = BigDecimal.fromString('1')
export const ONE_WAD_BD = EXP_18_BD

// max price of the pool is 1_004_968_987.606512354182109771 * 1e18
export const MAX_PRICE = BigDecimal.fromString(`${1_004_968_987.606512354182109771}`)
Expand Down
1 change: 1 addition & 0 deletions src/utils/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export function updatePool(pool: Pool): void {
pool.quoteTokenBalance = wadToDecimal(unnormalizedTokenBalance.times(scaleFactor))
token = Token.load(pool.collateralToken)!
scaleFactor = TEN_BI.pow(18 - token.decimals as u8)
unnormalizedTokenBalance = getTokenBalance(Address.fromBytes(pool.collateralToken), poolAddress)
pool.collateralBalance = wadToDecimal(unnormalizedTokenBalance.times(scaleFactor))

// update lend rate, since lender interest margin changes irrespective of borrow rate
Expand Down

0 comments on commit b81cd18

Please sign in to comment.