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

fix: getUpdateBlock to handle BalancerTransfer event change #128

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions src/mapping/tokenization/tokenization-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions src/utils/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down