From 4e4f049a22cbb27821841944baf69585a9a5216c Mon Sep 17 00:00:00 2001 From: franz Date: Wed, 29 Nov 2023 10:57:31 +0100 Subject: [PATCH 1/2] filter on query --- modules/vebal/debug-voting-list.spec.ts | 7 +++++-- modules/vebal/vebal-voting-list.service.ts | 8 +++++++- modules/vebal/voting-gauges.repository.spec.ts | 11 +++-------- modules/vebal/voting-gauges.repository.ts | 1 - 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/modules/vebal/debug-voting-list.spec.ts b/modules/vebal/debug-voting-list.spec.ts index 21874ed6e..b131011dc 100644 --- a/modules/vebal/debug-voting-list.spec.ts +++ b/modules/vebal/debug-voting-list.spec.ts @@ -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", @@ -315,6 +317,7 @@ it('Uses streamer-v1-map to find gauges (that use streamer instead of recipient) "relativeWeightCap": undefined, "stakingGaugeId": "0xfaad21203a7856889cb6eb644ab6864e7253107a", }, - ] + ], + } `); }, 1000_000); diff --git a/modules/vebal/vebal-voting-list.service.ts b/modules/vebal/vebal-voting-list.service.ts index 3f78e2061..1275fcbde 100644 --- a/modules/vebal/vebal-voting-list.service.ts +++ b/modules/vebal/vebal-voting-list.service.ts @@ -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, @@ -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 */ @@ -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); diff --git a/modules/vebal/voting-gauges.repository.spec.ts b/modules/vebal/voting-gauges.repository.spec.ts index 941705780..7f35f11d5 100644 --- a/modules/vebal/voting-gauges.repository.spec.ts +++ b/modules/vebal/voting-gauges.repository.spec.ts @@ -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 () => { diff --git a/modules/vebal/voting-gauges.repository.ts b/modules/vebal/voting-gauges.repository.ts index 78d16a8c7..cd252b8f9 100644 --- a/modules/vebal/voting-gauges.repository.ts +++ b/modules/vebal/voting-gauges.repository.ts @@ -138,7 +138,6 @@ export class VotingGaugesRepository { } async saveVotingGauge(gauge: VotingGauge) { - if (!this.isValidForVotingList(gauge)) return; try { const upsertFields = { id: gauge.gaugeAddress, From f9b26cda6b8b844554a9c5e269c8bc38415c72b0 Mon Sep 17 00:00:00 2001 From: franz Date: Thu, 30 Nov 2023 15:21:10 +0100 Subject: [PATCH 2/2] remove logging --- modules/vebal/vebal-voting-list.service.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/vebal/vebal-voting-list.service.ts b/modules/vebal/vebal-voting-list.service.ts index 1275fcbde..29f81a405 100644 --- a/modules/vebal/vebal-voting-list.service.ts +++ b/modules/vebal/vebal-voting-list.service.ts @@ -143,10 +143,6 @@ export class VeBalVotingListService { for (const addressChunk of chunks) { 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 */