Skip to content

Commit

Permalink
take the non 0 bal rewards (#753)
Browse files Browse the repository at this point in the history
* take the non 0 bal rewards

* changeset
  • Loading branch information
franzns authored Aug 8, 2024
1 parent 3205019 commit a3ab47e
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-donuts-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'backend': patch
---

workaround for streamed BAL on mainnet
17 changes: 14 additions & 3 deletions modules/actions/pool/staking/sync-gauge-staking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ export const syncGaugeStakingForPools = async (
rewardsMulticallerV2,
);

// TODO remove this once we have a better solution
let duplicateId = '';
for (const rate of onchainRates) {
const duplicates = onchainRates.filter((r) => r.id === rate.id);
if (duplicates.length > 1) {
duplicateId = duplicates[0].id;
}
}
const filteredOnchainRates = onchainRates.filter(
(rate) => rate.id !== duplicateId || parseFloat(rate.rewardPerSecond) > 0,
);
// Prepare DB operations
const operations: any[] = [];

Expand Down Expand Up @@ -168,8 +179,8 @@ export const syncGaugeStakingForPools = async (
}

const dbStakingGauge = allDbStakingGauges.find((stakingGauge) => stakingGauge?.id === gauge.id);
const workingSupply = onchainRates.find(({ id }) => `${gauge.id}-${balAddress}` === id)?.workingSupply;
const totalSupply = onchainRates.find(({ id }) => id.includes(gauge.id))?.totalSupply;
const workingSupply = filteredOnchainRates.find(({ id }) => `${gauge.id}-${balAddress}` === id)?.workingSupply;
const totalSupply = filteredOnchainRates.find(({ id }) => id.includes(gauge.id))?.totalSupply;
if (
!dbStakingGauge ||
dbStakingGauge.status !== gauge.status ||
Expand Down Expand Up @@ -204,7 +215,7 @@ export const syncGaugeStakingForPools = async (
const allStakingGaugeRewards = allDbStakingGauges.map((gauge) => gauge?.rewards).flat();

// DB operations for gauge reward tokens
for (const { id, rewardPerSecond } of onchainRates) {
for (const { id, rewardPerSecond } of filteredOnchainRates) {
const [gaugeId, tokenAddress] = id.toLowerCase().split('-');
const token = prismaTokens.find((token) => token.address === tokenAddress);
if (!token) {
Expand Down
94 changes: 90 additions & 4 deletions modules/pool/pool-debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { userService } from '../user/user.service';
import { tokenService } from '../token/token.service';
import mainnet from '../../config/mainnet';
import { prisma } from '../../prisma/prisma-client';
import { CowAmmController } from '../controllers/cow-amm-controller';
import { ContentController } from '../controllers/content-controller';
import { chainToIdMap } from '../network/network-config';
describe('pool debugging', () => {
it('sync pools', async () => {
initRequestScopedContext();
Expand All @@ -15,11 +18,94 @@ describe('pool debugging', () => {
}, 5000000);

it('sync aprs', async () => {
// initRequestScopedContext();
// setRequestScopedContextValue('chainId', '1');
// //only do once before starting to debug
// // await poolService.syncAllPoolsFromSubgraph();
// // await poolService.reloadStakingForAllPools(['GAUGE'], 'MAINNET');
// // await CowAmmController().reloadPools('MAINNET');
// // await CowAmmController().syncSwaps('1');
// // await tokenService.updateTokenPrices(['MAINNET']);
// await poolService.updatePoolAprs('MAINNET');
// const aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91' },
// });
// console.log(aprs);
initRequestScopedContext();
setRequestScopedContextValue('chainId', '137');
//only do once before starting to debug
// await poolService.syncAllPoolsFromSubgraph();
await poolService.updatePoolAprs('POLYGON');
setRequestScopedContextValue('chainId', chainToIdMap['MAINNET']);

await poolService.syncStakingForPools(['MAINNET']);
await poolService.updatePoolAprs('MAINNET');
let aprs = await prisma.prismaPoolAprItem.findMany({
where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
});
expect(aprs[0].apr).toBeGreaterThan(0);

// aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
// });
// expect(aprs[0].apr).toBeGreaterThan(0);

// await poolService.syncChangedPools();
// aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
// });
// expect(aprs[0].apr).toBeGreaterThan(0);

// await ContentController().syncCategories();
// aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
// });
// expect(aprs[0].apr).toBeGreaterThan(0);

// await CowAmmController().addPools('1');
// aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
// });
// // expect(aprs[0].apr).toBeGreaterThan(0);

// await CowAmmController().syncJoinExits('1');
// aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
// });
// // expect(aprs[0].apr).toBeGreaterThan(0);

// await CowAmmController().syncPools('1');
// aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
// });
// // expect(aprs[0].apr).toBeGreaterThan(0);

// await CowAmmController().syncSnapshots('1');
// aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
// });
// // expect(aprs[0].apr).toBeGreaterThan(0);

// await CowAmmController().syncSwaps('1');
// aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
// });
// // expect(aprs[0].apr).toBeGreaterThan(0);

// await CowAmmController().updateSurplusAprs();
// aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
// });
// // expect(aprs[0].apr).toBeGreaterThan(0);

// await CowAmmController().updateVolumeAndFees('1');
// aprs = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91', type: 'NATIVE_REWARD' },
// });
// // expect(aprs[0].apr).toBeGreaterThan(0);
// await CowAmmController().updateVolumeAndFees('1');
// await CowAmmController().updateSurplusAprs();

// const aprs2 = await prisma.prismaPoolAprItem.findMany({
// where: { chain: 'MAINNET', poolId: '0xf08d4dea369c456d26a3168ff0024b904f2d8b91' },
// });
// console.log(aprs2);
}, 5000000);

it('get new apr items', async () => {
Expand Down

0 comments on commit a3ab47e

Please sign in to comment.