removing all hard coded decimals from fixedRateExchange

This commit is contained in:
Jamie Hewitt 2023-05-04 12:16:11 +01:00
parent e414dcd1df
commit 0db13e04e9

View File

@ -72,10 +72,14 @@ export function handleRateChange(event: ExchangeRateChanged): void {
newExchangeUpdate.tx = event.transaction.hash.toHex() newExchangeUpdate.tx = event.transaction.hash.toHex()
newExchangeUpdate.block = event.block.number.toI32() newExchangeUpdate.block = event.block.number.toI32()
newExchangeUpdate.exchangeId = fixedRateId newExchangeUpdate.exchangeId = fixedRateId
const baseToken = getToken(
Address.fromString(fixedRateExchange.baseToken),
false
)
fixedRateExchange.price = weiToDecimal( fixedRateExchange.price = weiToDecimal(
event.params.newRate.toBigDecimal(), event.params.newRate.toBigDecimal(),
BigInt.fromI32(18).toI32() BigInt.fromI32(baseToken.decimals).toI32()
) )
newExchangeUpdate.newPrice = fixedRateExchange.price newExchangeUpdate.newPrice = fixedRateExchange.price
@ -182,6 +186,10 @@ export function handleSwap(event: Swapped): void {
Address.fromString(fixedRateExchange.baseToken), Address.fromString(fixedRateExchange.baseToken),
false false
) )
const dataToken = getToken(
Address.fromString(fixedRateExchange.datatoken),
false
)
swap.baseTokenAmount = weiToDecimal( swap.baseTokenAmount = weiToDecimal(
event.params.baseTokenSwappedAmount.toBigDecimal(), event.params.baseTokenSwappedAmount.toBigDecimal(),
@ -189,7 +197,7 @@ export function handleSwap(event: Swapped): void {
) )
swap.dataTokenAmount = weiToDecimal( swap.dataTokenAmount = weiToDecimal(
event.params.datatokenSwappedAmount.toBigDecimal(), event.params.datatokenSwappedAmount.toBigDecimal(),
BigInt.fromI32(18).toI32() BigInt.fromI32(dataToken.decimals).toI32()
) )
// Track fees // Track fees
@ -238,12 +246,16 @@ export function handlePublishMarketFeeChanged(
event.address event.address
) )
const fixedRateExchange = getFixedRateExchange(fixedRateId) const fixedRateExchange = getFixedRateExchange(fixedRateId)
const baseToken = getToken(
Address.fromString(fixedRateExchange.baseToken),
false
)
if (fixedRateExchange) { if (fixedRateExchange) {
fixedRateExchange.publishMarketFeeAddress = fixedRateExchange.publishMarketFeeAddress =
event.params.newMarketCollector.toHexString() event.params.newMarketCollector.toHexString()
fixedRateExchange.publishMarketSwapFee = weiToDecimal( fixedRateExchange.publishMarketSwapFee = weiToDecimal(
event.params.swapFee.toBigDecimal(), event.params.swapFee.toBigDecimal(),
BigInt.fromI32(18).toI32() BigInt.fromI32(baseToken.decimals).toI32()
) )
fixedRateExchange.save() fixedRateExchange.save()
} }