Skip to content

Commit

Permalink
filter on query
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Nov 29, 2023
1 parent 6ecaa5b commit 4e4f049
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 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);
8 changes: 7 additions & 1 deletion 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 @@ -140,6 +144,9 @@ export class VeBalVotingListService {
const { votingGauges, errors } = await this.fetchVotingGauges(addressChunk);
syncErrors.push(...errors);

if (addressChunk.includes('0xd639e7fae7a8d0233d416bfd5da2ae4f917d2e77')) {
console.log(`found`);
}
/*
We avoid saving gauges in specialVotingGaugeAddresses because they require special handling
*/
Expand Down Expand Up @@ -177,7 +184,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 4e4f049

Please sign in to comment.