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 negative total shares and holders count #595

Merged
merged 4 commits into from
Jun 18, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install node
uses: actions/setup-node@v1
with:
node-version: 16
node-version: 18
- name: Install
run: yarn --frozen-lockfile
- name: Codegen
Expand All @@ -28,7 +28,7 @@ jobs:
- name: Install node
uses: actions/setup-node@v1
with:
node-version: 16
node-version: 18
- name: Install
run: yarn --frozen-lockfile
- name: Lint
Expand Down
16 changes: 13 additions & 3 deletions src/mappings/poolController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
hexToBigInt,
getBalancerSnapshot,
} from './helpers/misc';
import { ONE_BD, ProtocolFeeType, ZERO_ADDRESS, ZERO_BD } from './helpers/constants';
import { ONE_BD, ProtocolFeeType, VAULT_ADDRESS, ZERO_ADDRESS, ZERO_BD } from './helpers/constants';
import { updateAmpFactor } from './helpers/stable';
import { getPoolTokenManager, getPoolTokens } from './helpers/pools';
import {
Expand Down Expand Up @@ -678,11 +678,21 @@ export function handleTransfer(event: Transfer): void {
poolShareFrom.save();
}

if (poolShareTo !== null && poolShareTo.balance.notEqual(ZERO_BD) && poolShareToBalance.equals(ZERO_BD)) {
if (
poolShareTo !== null &&
poolShareTo.balance.notEqual(ZERO_BD) &&
poolShareToBalance.equals(ZERO_BD) &&
poolShareTo.userAddress != VAULT_ADDRESS.toHex()
) {
pool.holdersCount = pool.holdersCount.plus(BigInt.fromI32(1));
}

if (poolShareFrom !== null && poolShareFrom.balance.equals(ZERO_BD) && poolShareFromBalance.notEqual(ZERO_BD)) {
if (
poolShareFrom !== null &&
poolShareFrom.balance.equals(ZERO_BD) &&
poolShareFromBalance.notEqual(ZERO_BD) &&
poolShareFrom.userAddress != VAULT_ADDRESS.toHex()
) {
pool.holdersCount = pool.holdersCount.minus(BigInt.fromI32(1));
}

Expand Down
2 changes: 1 addition & 1 deletion src/mappings/poolFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from './helpers/misc';
import { updatePoolWeights } from './helpers/weighted';

import { BigInt, Address, Bytes, ethereum, log } from '@graphprotocol/graph-ts';
import { BigInt, Address, Bytes, ethereum } from '@graphprotocol/graph-ts';

import { PoolCreated } from '../types/WeightedPoolFactory/WeightedPoolFactory';
import { AaveLinearPoolCreated } from '../types/AaveLinearPoolV3Factory/AaveLinearPoolV3Factory';
Expand Down
1 change: 1 addition & 0 deletions src/mappings/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ export function handleAnswerUpdated(event: AnswerUpdated): void {
} else if (oracle && oracle.divisor !== null && oracle.decimals) {
const updatedAnswer = answer
.times(BigInt.fromString('10').pow(oracle.decimals as u8))
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.div(BigInt.fromString(oracle.divisor!));
token.latestFXPrice = scaleDown(updatedAnswer, 8);
} else {
Expand Down
24 changes: 5 additions & 19 deletions src/mappings/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
getTradePairSnapshot,
getTradePair,
getBalancerSnapshot,
bytesToAddress,
getPoolShare,
} from './helpers/misc';
import { updatePoolWeights } from './helpers/weighted';
Expand Down Expand Up @@ -273,24 +272,11 @@ function handlePoolJoined(event: PoolBalanceChanged): void {
pool.save();

// This amount will also be transferred to the vault,
// causing the vault's 'user shares' to incorrectly increase,
// so we need to negate it. We do so by processing a mock transfer event
// from the vault to the zero address
const mockEvent = new Transfer(
bytesToAddress(pool.address),
event.logIndex,
event.transactionLogIndex,
event.logType,
event.block,
event.transaction,
[
new ethereum.EventParam('from', ethereum.Value.fromAddress(VAULT_ADDRESS)),
new ethereum.EventParam('to', ethereum.Value.fromAddress(ZERO_ADDRESS)),
new ethereum.EventParam('value', ethereum.Value.fromUnsignedBigInt(preMintedBpt)),
],
event.receipt
);
handleTransfer(mockEvent);
// causing the vault's 'user shares' to incorrectly
// increase, so we need to subtract it.
const vaultPoolShare = getPoolShare(poolId, VAULT_ADDRESS);
vaultPoolShare.balance = vaultPoolShare.balance.minus(tokenToDecimal(preMintedBpt, 18));
vaultPoolShare.save();
}

updatePoolLiquidity(poolId, event.block.number, event.block.timestamp);
Expand Down
Loading