Skip to content

Commit

Permalink
Merge pull request #541 from beethovenxfi/fix/filter-votinggauges-on-…
Browse files Browse the repository at this point in the history
…query

filter on query
  • Loading branch information
franzns authored Nov 30, 2023
2 parents e9c0cd0 + f9b26cd commit 8bd6c6a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
7 changes: 5 additions & 2 deletions modules/vebal/debug-voting-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ it('Uses streamer-v1-map to find gauges (that use streamer instead of recipient)
const savedGauges = await repository.saveVotingGauges(fetchedVotingGauges);

expect(savedGauges).toMatchInlineSnapshot(`
[
{
"saveErrors": [],
"votingGaugesWithStakingGaugeId": [
{
"addedTimestamp": 1657479716,
"gaugeAddress": "0xcf5938ca6d9f19c73010c7493e19c02acfa8d24d",
Expand All @@ -315,6 +317,7 @@ it('Uses streamer-v1-map to find gauges (that use streamer instead of recipient)
"relativeWeightCap": undefined,
"stakingGaugeId": "0xfaad21203a7856889cb6eb644ab6864e7253107a",
},
]
],
}
`);
}, 1000_000);
6 changes: 4 additions & 2 deletions modules/vebal/vebal-voting-list.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ export class VeBalVotingListService {
}

public async getValidVotingGauges() {
// A gauge should be included in the voting list when:
// - it is alive (not killed)
// - it is killed and has valid votes (the users should be able to reallocate votes)
const gaugesWithStaking = await prisma.prismaVotingGauge.findMany({
where: {
stakingGaugeId: { not: null },
OR: [{ status: 'ACTIVE' }, { relativeWeight: { not: '0' } }],
},
select: {
id: true,
Expand Down Expand Up @@ -139,7 +143,6 @@ export class VeBalVotingListService {
for (const addressChunk of chunks) {
const { votingGauges, errors } = await this.fetchVotingGauges(addressChunk);
syncErrors.push(...errors);

/*
We avoid saving gauges in specialVotingGaugeAddresses because they require special handling
*/
Expand Down Expand Up @@ -177,7 +180,6 @@ export class VeBalVotingListService {
const gaugesWithMissingData = votingGauges
.filter((gauge) => !veGauges.includes(gauge.gaugeAddress))
.filter((gauge) => !gauge.isInSubgraph)
.filter(this.votingGauges.isValidForVotingList)
// Ignore old Vebal gauge address
.filter((gauge) => gauge.gaugeAddress !== oldVeBalAddress);

Expand Down
11 changes: 3 additions & 8 deletions modules/vebal/voting-gauges.repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,14 @@ it('successfully saves onchain gauges', async () => {
describe('When staking gauge is not found ', () => {
beforeEach(() => prismaMock.prismaPoolStakingGauge.findFirst.mockResolvedValue(null));

it('throws when gauge is valid for voting (not killed)', async () => {
it('has errors when gauge is valid for voting (not killed)', async () => {
const repository = new VotingGaugesRepository(prismaMock);

const votingGauge = aVotingGauge({ network: Chain.MAINNET, isKilled: false });

let error: Error = EmptyError;
try {
await repository.saveVotingGauges([votingGauge]);
} catch (e) {
error = e as Error;
}
const { votingGaugesWithStakingGaugeId, saveErrors } = await repository.saveVotingGauges([votingGauge]);

expect(error.message).toContain('VotingGauge not found in PrismaPoolStakingGauge:');
expect(saveErrors.length).toBe(1);
});

it('does not throw when gauge is valid for voting (killed with no votes)', async () => {
Expand Down
1 change: 0 additions & 1 deletion modules/vebal/voting-gauges.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export class VotingGaugesRepository {
}

async saveVotingGauge(gauge: VotingGauge) {
if (!this.isValidForVotingList(gauge)) return;
try {
const upsertFields = {
id: gauge.gaugeAddress,
Expand Down

0 comments on commit 8bd6c6a

Please sign in to comment.