Skip to content

Commit

Permalink
fix: decimals (#131)
Browse files Browse the repository at this point in the history
* chore: update contracts

* fix: cleanup

* fix: PT ABI

* fix: imports

* fix: format

* feat: deposits data

* fix: format

* fix: decimals
  • Loading branch information
matstyler authored Dec 20, 2023
1 parent a9bb5b1 commit 96c4d57
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
21 changes: 6 additions & 15 deletions src/mappings/amm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { updateAccountAssetBalance } from "../entities/AccountAsset"
import { getAsset } from "../entities/Asset"
import { getAssetAmount } from "../entities/AssetAmount"
import { getPoolPriceScale, getPoolLPToken } from "../entities/CurvePool"
import { getERC20TotalSupply } from "../entities/ERC20"
import { getERC20Decimals, getERC20TotalSupply } from "../entities/ERC20"
import { updateFutureDailyStats } from "../entities/FutureDailyStats"
import { createTransaction } from "../entities/Transaction"
import { AssetType, generateFeeClaimId } from "../utils"
Expand All @@ -25,7 +25,6 @@ import { generateTransactionId } from "../utils/idGenerators"
import { toPrecision } from "../utils/toPrecision"

const FEES_PRECISION = 10
const CURVE_LP_TOKEN_PRECISION = 18

export function handleAddLiquidity(event: AddLiquidity): void {
let eventTimestamp = event.block.timestamp
Expand Down Expand Up @@ -98,21 +97,13 @@ export function handleAddLiquidity(event: AddLiquidity): void {
lpPosition.pool = pool.id
lpPosition.save()

let fee = toPrecision(
event.params.fee,
FEES_PRECISION,
CURVE_LP_TOKEN_PRECISION
)
const ibtDecimals = getERC20Decimals(Address.fromString(ibtAddress))

let fee = toPrecision(event.params.fee, FEES_PRECISION, ibtDecimals)

let adminFee = fee
.times(
toPrecision(
pool.adminFeeRate,
FEES_PRECISION,
CURVE_LP_TOKEN_PRECISION
)
)
.div(BigInt.fromI32(10).pow(18 as u8))
.times(toPrecision(pool.adminFeeRate, FEES_PRECISION, ibtDecimals))
.div(BigInt.fromI32(10).pow(ibtDecimals as u8))

createTransaction({
id: generateTransactionId(
Expand Down
7 changes: 6 additions & 1 deletion src/mappings/lpVaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { ZERO_ADDRESS, ZERO_BI } from "../constants"
import { updateAccountAssetBalance } from "../entities/AccountAsset"
import { getAssetAmount } from "../entities/AssetAmount"
import { getERC20Decimals } from "../entities/ERC20"
import {
getTotalSupply,
getTotalAssets,
Expand Down Expand Up @@ -126,12 +127,16 @@ export function handleDeposit(event: Deposit): void {
event.params.shares
)

const underlyingDecimals = getERC20Decimals(underlyingAddress)

if (
lpVaultPosition.totalUnderlyingDeposit !== ZERO_BI &&
lpVaultPosition.totalMintedShares !== ZERO_BI
) {
lpVaultPosition.averageShareCost = lpVaultPosition
.totalUnderlyingDeposit!.times(BigInt.fromI32(10).pow(18 as u8))
.totalUnderlyingDeposit!.times(
BigInt.fromI32(10).pow(underlyingDecimals as u8)
)
.div(lpVaultPosition.totalMintedShares!)
}

Expand Down

0 comments on commit 96c4d57

Please sign in to comment.