Skip to content

Commit

Permalink
change 7 and 30 days swap apr to use snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Dec 4, 2024
1 parent fe549d3 commit b6daf57
Show file tree
Hide file tree
Showing 18 changed files with 289 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-windows-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'backend': patch
---

change 7 and 30 days swap apr to use snapshots
46 changes: 28 additions & 18 deletions apps/worker/job-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,6 @@ const setupJobHandlers = async (name: string, chainId: string, res: any, next: N
next,
);
break;
case 'update-pool-apr':
await runIfNotAlreadyRunning(
name,
chainId,
() => {
const chain = chainIdToChain[chainId];
return poolService.updatePoolAprs(chain);
},
res,
next,
);
break;
case 'load-on-chain-data-for-pools-with-active-updates':
await runIfNotAlreadyRunning(
name,
Expand Down Expand Up @@ -296,6 +284,34 @@ const setupJobHandlers = async (name: string, chainId: string, res: any, next: N
next,
);
break;
// APRs
case 'sync-merkl':
await runIfNotAlreadyRunning(name, chainId, () => AprsController().syncMerkl(), res, next);
break;
case 'update-7-30-days-swap-apr':
await runIfNotAlreadyRunning(
name,
chainId,
() => AprsController().update7And30DaysSwapAprs(chain),
res,
next,
);
break;
case 'update-surplus-aprs':
await runIfNotAlreadyRunning(name, chainId, () => CowAmmController().updateSurplusAprs(), res, next);
break;
case 'update-pool-apr':
await runIfNotAlreadyRunning(
name,
chainId,
() => {
const chain = chainIdToChain[chainId];
return poolService.updatePoolAprs(chain);
},
res,
next,
);
break;
// V3 Jobs
case 'add-pools-v3':
await runIfNotAlreadyRunning(name, chainId, () => PoolController().addPoolsV3(chain), res, next);
Expand Down Expand Up @@ -365,12 +381,6 @@ const setupJobHandlers = async (name: string, chainId: string, res: any, next: N
case 'update-cow-amm-volume-and-fees':
await runIfNotAlreadyRunning(name, chainId, () => CowAmmController().updateVolumeAndFees(chain), res, next);
break;
case 'update-surplus-aprs':
await runIfNotAlreadyRunning(name, chainId, () => CowAmmController().updateSurplusAprs(), res, next);
break;
case 'sync-merkl':
await runIfNotAlreadyRunning(name, chainId, () => AprsController().syncMerkl(), res, next);
break;
case 'sync-categories':
await runIfNotAlreadyRunning(name, chainId, () => ContentController().syncCategories(), res, next);
break;
Expand Down
12 changes: 12 additions & 0 deletions modules/controllers/aprs-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Chain } from '@prisma/client';
import { syncMerklRewards } from '../actions/aprs/merkl';
import { SwapFeeFromSnapshotsAprService } from '../pool/lib/apr-data-sources/swap-fee-apr-from-snapshots.service';
import { prisma } from '../../prisma/prisma-client';

export function AprsController(tracer?: any) {
// Setup tracing
Expand All @@ -7,5 +10,14 @@ export function AprsController(tracer?: any) {
async syncMerkl() {
return await syncMerklRewards();
},
async update7And30DaysSwapAprs(chain: Chain) {
const service = new SwapFeeFromSnapshotsAprService();
const pools = await prisma.prismaPool.findMany({
where: { chain },
include: { tokens: true },
});
await service.updateAprForPools(pools);
return 'Done';
},
};
}
8 changes: 6 additions & 2 deletions modules/network/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from 'ethers';
import { DeploymentEnv, NetworkConfig } from './network-config-types';
import { tokenService } from '../token/token.service';
import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/nested-pool-apr.service';
import { SwapFeeFromEventsAprService } from '../pool/lib/apr-data-sources/';
import { SwapFeeAprService } from '../pool/lib/apr-data-sources/';
import { GaugeAprService } from '../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { UserSyncGaugeBalanceService } from '../user/lib/user-sync-gauge-balance.service';
import { every } from '../../apps/scheduler/intervals';
Expand All @@ -22,7 +22,7 @@ export const arbitrumNetworkConfig: NetworkConfig = {
poolAprServices: [
new YbTokensAprService(arbitrumNetworkData.ybAprConfig, arbitrumNetworkData.chain.prismaId),
new BoostedPoolAprService(),
new SwapFeeFromEventsAprService(),
new SwapFeeAprService(),
new GaugeAprService(tokenService, [arbitrumNetworkData.bal!.address]),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService(), new UserSyncAuraBalanceService()],
Expand Down Expand Up @@ -54,6 +54,10 @@ export const arbitrumNetworkConfig: NetworkConfig = {
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-7-30-days-swap-apr',
interval: every(8, 'hours'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
Expand Down
9 changes: 7 additions & 2 deletions modules/network/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BigNumber, ethers } from 'ethers';
import { DeploymentEnv, NetworkConfig, NetworkData } from './network-config-types';
import { tokenService } from '../token/token.service';
import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/nested-pool-apr.service';
import { SwapFeeFromEventsAprService } from '../pool/lib/apr-data-sources/';
import { SwapFeeAprService } from '../pool/lib/apr-data-sources/';
import { GaugeAprService } from '../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { UserSyncGaugeBalanceService } from '../user/lib/user-sync-gauge-balance.service';
import { every } from '../../apps/scheduler/intervals';
Expand All @@ -22,7 +22,7 @@ export const avalancheNetworkConfig: NetworkConfig = {
poolAprServices: [
new YbTokensAprService(avalancheNetworkData.ybAprConfig, avalancheNetworkData.chain.prismaId),
new BoostedPoolAprService(),
new SwapFeeFromEventsAprService(),
new SwapFeeAprService(),
new GaugeAprService(tokenService, [avalancheNetworkData.bal!.address]),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService(), new UserSyncAuraBalanceService()],
Expand Down Expand Up @@ -54,6 +54,11 @@ export const avalancheNetworkConfig: NetworkConfig = {
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-7-30-days-swap-apr',
interval: every(8, 'hours'),
},

{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
Expand Down
8 changes: 6 additions & 2 deletions modules/network/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from 'ethers';
import { DeploymentEnv, NetworkConfig, NetworkData } from './network-config-types';
import { tokenService } from '../token/token.service';
import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/nested-pool-apr.service';
import { SwapFeeFromEventsAprService } from '../pool/lib/apr-data-sources/';
import { SwapFeeAprService } from '../pool/lib/apr-data-sources/';
import { GaugeAprService } from '../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { UserSyncGaugeBalanceService } from '../user/lib/user-sync-gauge-balance.service';
import { every } from '../../apps/scheduler/intervals';
Expand All @@ -22,7 +22,7 @@ export const baseNetworkConfig: NetworkConfig = {
poolAprServices: [
new YbTokensAprService(baseNetworkData.ybAprConfig, baseNetworkData.chain.prismaId),
new BoostedPoolAprService(),
new SwapFeeFromEventsAprService(),
new SwapFeeAprService(),
new GaugeAprService(tokenService, [baseNetworkData.bal!.address]),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService(), new UserSyncAuraBalanceService()],
Expand Down Expand Up @@ -54,6 +54,10 @@ export const baseNetworkConfig: NetworkConfig = {
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-7-30-days-swap-apr',
interval: every(8, 'hours'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
Expand Down
8 changes: 6 additions & 2 deletions modules/network/fantom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers';
import { DeploymentEnv, NetworkConfig, NetworkData } from './network-config-types';
import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/nested-pool-apr.service';
import { SwapFeeFromEventsAprService } from '../pool/lib/apr-data-sources/';
import { SwapFeeAprService } from '../pool/lib/apr-data-sources/';
import { MasterchefFarmAprService } from '../pool/lib/apr-data-sources/fantom/masterchef-farm-apr.service';
import { ReliquaryFarmAprService } from '../pool/lib/apr-data-sources/fantom/reliquary-farm-apr.service';
import { UserSyncMasterchefFarmBalanceService } from '../user/lib/user-sync-masterchef-farm-balance.service';
Expand All @@ -23,7 +23,7 @@ export const fantomNetworkConfig: NetworkConfig = {
poolAprServices: [
new YbTokensAprService(fantomNetworkData.ybAprConfig, fantomNetworkData.chain.prismaId),
new BoostedPoolAprService(),
new SwapFeeFromEventsAprService(),
new SwapFeeAprService(),
new MasterchefFarmAprService(fantomNetworkData.beets!.address),
new ReliquaryFarmAprService(fantomNetworkData.beets!.address),
new BeetswarsGaugeVotingAprService(),
Expand Down Expand Up @@ -65,6 +65,10 @@ export const fantomNetworkConfig: NetworkConfig = {
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-7-30-days-swap-apr',
interval: every(8, 'hours'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
Expand Down
8 changes: 6 additions & 2 deletions modules/network/fraxtal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from 'ethers';
import { DeploymentEnv, NetworkConfig } from './network-config-types';
import { tokenService } from '../token/token.service';
import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/nested-pool-apr.service';
import { SwapFeeFromEventsAprService } from '../pool/lib/apr-data-sources/';
import { SwapFeeAprService } from '../pool/lib/apr-data-sources/';
import { GaugeAprService } from '../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { UserSyncGaugeBalanceService } from '../user/lib/user-sync-gauge-balance.service';
import { every } from '../../apps/scheduler/intervals';
Expand All @@ -22,7 +22,7 @@ export const fraxtalNetworkConfig: NetworkConfig = {
poolAprServices: [
new YbTokensAprService(fraxtalNetworkData.ybAprConfig, fraxtalNetworkData.chain.prismaId),
new BoostedPoolAprService(),
new SwapFeeFromEventsAprService(),
new SwapFeeAprService(),
new GaugeAprService(tokenService, [fraxtalNetworkData.bal!.address]),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService(), new UserSyncAuraBalanceService()],
Expand Down Expand Up @@ -54,6 +54,10 @@ export const fraxtalNetworkConfig: NetworkConfig = {
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-7-30-days-swap-apr',
interval: every(8, 'hours'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
Expand Down
8 changes: 6 additions & 2 deletions modules/network/gnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from 'ethers';
import { DeploymentEnv, NetworkConfig, NetworkData } from './network-config-types';
import { tokenService } from '../token/token.service';
import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/nested-pool-apr.service';
import { SwapFeeFromEventsAprService } from '../pool/lib/apr-data-sources/';
import { SwapFeeAprService } from '../pool/lib/apr-data-sources/';
import { GaugeAprService } from '../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { UserSyncGaugeBalanceService } from '../user/lib/user-sync-gauge-balance.service';
import { every } from '../../apps/scheduler/intervals';
Expand All @@ -22,7 +22,7 @@ export const gnosisNetworkConfig: NetworkConfig = {
poolAprServices: [
new YbTokensAprService(gnosisNetworkData.ybAprConfig, gnosisNetworkData.chain.prismaId),
new BoostedPoolAprService(),
new SwapFeeFromEventsAprService(),
new SwapFeeAprService(),
new GaugeAprService(tokenService, [gnosisNetworkData.bal!.address]),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService(), new UserSyncAuraBalanceService()],
Expand Down Expand Up @@ -54,6 +54,10 @@ export const gnosisNetworkConfig: NetworkConfig = {
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-7-30-days-swap-apr',
interval: every(8, 'hours'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
Expand Down
16 changes: 10 additions & 6 deletions modules/network/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { tokenService } from '../token/token.service';
import {
BoostedPoolAprService,
SwapFeeAprService,
SwapFeeFromEventsAprService,
GaugeAprService,
YbTokensAprService,
VeBalProtocolAprService,
Expand All @@ -28,7 +27,7 @@ export const mainnetNetworkConfig: NetworkConfig = {
poolAprServices: [
new YbTokensAprService(data.ybAprConfig, data.chain.prismaId),
new BoostedPoolAprService(),
new SwapFeeFromEventsAprService(),
new SwapFeeAprService(),
new GaugeAprService(tokenService, [data.bal!.address]),
new VeBalProtocolAprService(data.rpcUrl),
new VeBalVotingAprService(),
Expand Down Expand Up @@ -63,10 +62,6 @@ export const mainnetNetworkConfig: NetworkConfig = {
name: 'update-liquidity-for-active-pools',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
Expand Down Expand Up @@ -163,6 +158,15 @@ export const mainnetNetworkConfig: NetworkConfig = {
name: 'sync-erc4626-reviews',
interval: every(1, 'hours'),
},
// APRs
{
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-7-30-days-swap-apr',
interval: every(8, 'hours'),
},
{
name: 'update-surplus-aprs',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(1, 'minutes'),
Expand Down
8 changes: 6 additions & 2 deletions modules/network/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from 'ethers';
import { DeploymentEnv, NetworkConfig } from './network-config-types';
import { tokenService } from '../token/token.service';
import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/nested-pool-apr.service';
import { SwapFeeFromEventsAprService } from '../pool/lib/apr-data-sources';
import { SwapFeeAprService } from '../pool/lib/apr-data-sources';
import { GaugeAprService } from '../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { UserSyncGaugeBalanceService } from '../user/lib/user-sync-gauge-balance.service';
import { every } from '../../apps/scheduler/intervals';
Expand All @@ -21,7 +21,7 @@ export const modeNetworkConfig: NetworkConfig = {
poolAprServices: [
new YbTokensAprService(modeNetworkData.ybAprConfig, modeNetworkData.chain.prismaId),
new BoostedPoolAprService(),
new SwapFeeFromEventsAprService(),
new SwapFeeAprService(),
new GaugeAprService(tokenService, [modeNetworkData.bal!.address]),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
Expand Down Expand Up @@ -53,6 +53,10 @@ export const modeNetworkConfig: NetworkConfig = {
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-7-30-days-swap-apr',
interval: every(8, 'hours'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
Expand Down
8 changes: 6 additions & 2 deletions modules/network/optimism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from 'ethers';
import { DeploymentEnv, NetworkConfig, NetworkData } from './network-config-types';
import { tokenService } from '../token/token.service';
import { BoostedPoolAprService } from '../pool/lib/apr-data-sources/nested-pool-apr.service';
import { SwapFeeFromEventsAprService } from '../pool/lib/apr-data-sources/';
import { SwapFeeAprService } from '../pool/lib/apr-data-sources/';
import { GaugeAprService } from '../pool/lib/apr-data-sources/ve-bal-gauge-apr.service';
import { UserSyncGaugeBalanceService } from '../user/lib/user-sync-gauge-balance.service';
import { every } from '../../apps/scheduler/intervals';
Expand All @@ -22,7 +22,7 @@ export const optimismNetworkConfig: NetworkConfig = {
poolAprServices: [
new YbTokensAprService(optimismNetworkData.ybAprConfig, optimismNetworkData.chain.prismaId),
new BoostedPoolAprService(),
new SwapFeeFromEventsAprService(),
new SwapFeeAprService(),
new GaugeAprService(tokenService, [optimismNetworkData.beets!.address, optimismNetworkData.bal!.address]),
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService(), new UserSyncAuraBalanceService()],
Expand Down Expand Up @@ -54,6 +54,10 @@ export const optimismNetworkConfig: NetworkConfig = {
name: 'update-pool-apr',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(6, 'minutes') : every(2, 'minutes'),
},
{
name: 'update-7-30-days-swap-apr',
interval: every(8, 'hours'),
},
{
name: 'load-on-chain-data-for-pools-with-active-updates',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(4, 'minutes') : every(1, 'minutes'),
Expand Down
Loading

0 comments on commit b6daf57

Please sign in to comment.