diff --git a/src/mapping/tokenization/tokenization-v3.ts b/src/mapping/tokenization/tokenization-v3.ts index e3600ce..3d049e6 100644 --- a/src/mapping/tokenization/tokenization-v3.ts +++ b/src/mapping/tokenization/tokenization-v3.ts @@ -191,6 +191,7 @@ function tokenMint( ): void { let aToken = getOrInitSubToken(event.address); let poolReserve = getOrInitReserve(aToken.underlyingAssetAddress, event); + const userBalanceChange = value.minus(balanceIncrease); poolReserve.totalATokenSupply = poolReserve.totalATokenSupply.plus(userBalanceChange); @@ -219,7 +220,7 @@ function tokenMint( onBehalf.toHexString() != '0x5ba7fd868c40c16f7aDfAe6CF87121E13FC2F7a0'.toLowerCase() && onBehalf.toHexString() != '0x8A020d92D6B119978582BE4d3EdFdC9F7b28BF31'.toLowerCase() && onBehalf.toHexString() != '0x053D55f9B5AF8694c503EB288a1B7E552f590710'.toLowerCase() && - onBehalf.toHexString() != '0x464C71f6c2F760DdA6093dCB91C24c39e5d6e18c'.toLowerCase() + onBehalf.toHexString() != '0x464C71f6c2F760DdA6093dCB91C24c39e5d6e18c'.toLowerCase() ) { let userReserve = getOrInitUserReserve(onBehalf, aToken.underlyingAssetAddress, event); let calculatedAmount = rayDiv(userBalanceChange, index); @@ -283,8 +284,8 @@ export function handleBalanceTransfer(event: BalanceTransfer): void { let balanceTransferValue = event.params.value; const network = dataSource.network(); const v301UpdateBlock = getUpdateBlock(network); - if (v301UpdateBlock !== -1 && event.block.number.toU32() > v301UpdateBlock) { - balanceTransferValue = balanceTransferValue.times(event.params.index); + if (event.block.number.toU32() > v301UpdateBlock) { + balanceTransferValue = rayMul(balanceTransferValue, event.params.index); } tokenBurn(event, event.params.from, balanceTransferValue, BigInt.fromI32(0), event.params.index); diff --git a/src/utils/converters.ts b/src/utils/converters.ts index 1a36432..fb71ff4 100644 --- a/src/utils/converters.ts +++ b/src/utils/converters.ts @@ -193,17 +193,15 @@ export function generateSymbol(description: string): string { } /** - * Gets the block number at which the given market was updated to v3.0.1. - * Returns -1 if the market was not updated. + * Returns the block number at which the given market was updated to v3.0.1. + * This is needed due to an updated interpretation of `BalanceTransfer` events + * All market deployments not listed use updated version by default * @param network * @returns block number */ export function getUpdateBlock(network: string): u32 { - let updateBlock = -1; - if (network === 'mainnet' || network === 'andromeda') { - // these markets were deployed with v3.0.1 - updateBlock = 0; - } else if (network === 'optimism') { + let updateBlock = 0; + if (network === 'optimism') { updateBlock = 775471; } else if (network === 'polygon') { updateBlock = 42535602;