Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish to prod #1531

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# backend

## 1.29.2

### Patch Changes

- ed867e5: add generalized erc4626 price handler
- 9d1a4b3: v3 on base and arbitrum

## 1.29.1

### Patch Changes
Expand Down
2 changes: 2 additions & 0 deletions config/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default <NetworkData>{
subgraphs: {
startDate: '2021-08-23',
balancer: `https://gateway-arbitrum.network.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/deployments/id/QmPbjY6L1NhPjpBv7wDTfG9EPx5FpCuBqeg1XxByzBTLcs`,
balancerV3: `https://gateway.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/deployments/id/QmS6suakkYyKgEtDmMjwpbUzzHNmju7Rh5hSteZbCtTfgV`,
balancerPoolsV3: `https://gateway.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/deployments/id/QmcxLe2iK1KcizhcdDggYyjL8HoNqFMeHLhscH49n1hZBW`,
cowAmm: `https://gateway-arbitrum.network.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/deployments/id/QmUDGSJXdMzG4ezDzf1LvXVb2igwY6rnaNFLC62ZJZ3Pbv`,
blocks: `https://gateway.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/subgraphs/id/JBnWrv9pvBvSi2pUZzba3VweGBTde6s44QvsDABP47Gt`,
gauge: `https://gateway-arbitrum.network.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/deployments/id/QmT3h6pogdPkxfWsBxKNtpq7kR9fqKaQ9jGxe7fZx7MUVE`,
Expand Down
2 changes: 2 additions & 0 deletions config/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default <NetworkData>{
subgraphs: {
startDate: '2023-07-10',
balancer: `https://gateway-arbitrum.network.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/deployments/id/QmRKBwBwPKtFz4mQp5jvH44USVprM4C77Nr4m77UGCbGv9`,
balancerV3: `https://gateway.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/deployments/id/QmWREXT4GScDzeudK7i7uRYc2D6mPaVyw863KtDUrNgZU1`,
balancerPoolsV3: `https://gateway.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/deployments/id/QmVmh7GAdYcGbKsbbkL7j42ciFEDTxrdtijUxYbhLs7jkv`,
cowAmm: `https://gateway.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/deployments/id/QmVRCjhFz7XXJoeJ5t4FdysN2JaBVdUCvpTVoMzXRNjA87`,
blocks: `https://gateway.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/subgraphs/id/6f2Z8rTvsBQinEMwRSBxbyg3BP2LTFiEA1hjPZxmy3xs`,
gauge: `https://gateway.thegraph.com/api/${env.THEGRAPH_API_KEY_BALANCER}/subgraphs/id/CfBvJNYsbKZdxXzaCtNc6dUbHH6TjDupprjKKo9gnmwg`,
Expand Down
29 changes: 29 additions & 0 deletions modules/network/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,34 @@ export const arbitrumNetworkConfig: NetworkConfig = {
name: 'sync-erc4626-unwrap-rate',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(60, 'minutes') : every(20, 'minutes'),
},
// V3 Jobs
{
name: 'add-pools-v3',
interval: every(2, 'minutes'),
},
{
name: 'sync-pools-v3',
interval: every(30, 'seconds'),
},
{
name: 'sync-join-exits-v3',
interval: every(1, 'minutes'),
},
{
name: 'sync-swaps-v3',
interval: every(1, 'minutes'),
},
{
name: 'sync-snapshots-v3',
interval: every(10, 'minutes'),
},
{
name: 'sync-hook-data',
interval: every(1, 'hours'),
},
{
name: 'sync-erc4626-unwrap-rate',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(60, 'minutes') : every(20, 'minutes'),
},
],
};
29 changes: 29 additions & 0 deletions modules/network/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,34 @@ export const baseNetworkConfig: NetworkConfig = {
name: 'sync-erc4626-unwrap-rate',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(60, 'minutes') : every(20, 'minutes'),
},
// V3 Jobs
{
name: 'add-pools-v3',
interval: every(2, 'minutes'),
},
{
name: 'sync-pools-v3',
interval: every(30, 'seconds'),
},
{
name: 'sync-join-exits-v3',
interval: every(1, 'minutes'),
},
{
name: 'sync-swaps-v3',
interval: every(1, 'minutes'),
},
{
name: 'sync-snapshots-v3',
interval: every(10, 'minutes'),
},
{
name: 'sync-hook-data',
interval: every(1, 'hours'),
},
{
name: 'sync-erc4626-unwrap-rate',
interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(60, 'minutes') : every(20, 'minutes'),
},
],
};
3 changes: 3 additions & 0 deletions modules/pool/lib/apr-data-sources/yb-tokens-apr.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export class YbTokensAprService implements PoolAprService {
});

for (const pool of poolsWithYbTokensExpanded) {
if (pool.address === '0x43026d483f42fb35efe03c20b251142d022783f2') {
console.log('found');
}
if (!pool.dynamicData) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { TokenPriceHandler } from '../../token-types';
import { PrismaTokenWithTypes } from '../../../../prisma/prisma-types';
import { timestampRoundedUpToNearestHour } from '../../../common/time';
import { prisma } from '../../../../prisma/prisma-client';
import _ from 'lodash';
import { tokenAndPrice, updatePrices } from './price-handler-helper';
import { Chain } from '@prisma/client';

export class ERC4626PriceHandlerService implements TokenPriceHandler {
public readonly exitIfFails = false;
public readonly id = 'ERC4626PriceHandlerService';

private getAcceptedTokens(tokens: PrismaTokenWithTypes[]): PrismaTokenWithTypes[] {
return tokens.filter((token) => token.types.includes('ERC4626'));
}

public async updatePricesForTokens(tokens: PrismaTokenWithTypes[]): Promise<PrismaTokenWithTypes[]> {
const acceptedTokens = this.getAcceptedTokens(tokens);

const tokenAndPrices: tokenAndPrice[] = [];
const timestamp = timestampRoundedUpToNearestHour();

// Group tokens by chain
const tokensByChain = _.groupBy(acceptedTokens, 'chain');

const updatedTokens: PrismaTokenWithTypes[] = [];
for (const chain in tokensByChain) {
// Use existing rates for erc4626 tokens);

const erc4626TokensForChain = tokensByChain[chain];
if (!erc4626TokensForChain.length) {
continue;
}

// Fetch rates for aave tokens
const underlying = erc4626TokensForChain
.map((token) => token.underlyingTokenAddress)
.filter((address) => address !== null);

const underlyingPrices = await prisma.prismaTokenCurrentPrice.findMany({
where: { tokenAddress: { in: _.uniq(underlying) }, chain: chain as Chain },
});

const underlyingMap = _.zipObject(
underlyingPrices.map((p) => p.tokenAddress),
underlyingPrices,
);

const rateMap = _.zipObject(
erc4626TokensForChain.map((token) => token.address),
erc4626TokensForChain.map((token) => Number(token.unwrapRate)),
);

for (const erc4626Token of erc4626TokensForChain) {
const dbToken = acceptedTokens.find((t) => t.address === erc4626Token.address);
const underlying = erc4626Token.underlyingTokenAddress;
if (!dbToken || !underlying || !underlyingMap[underlying]) {
console.error(
`ERC4626PriceHandlerService: Underlying price for ERC4626 ${erc4626Token.symbol} (underlying address: ${erc4626Token.underlyingTokenAddress}) on ${chain} not found`,
);
continue;
}
try {
const price = Number((rateMap[erc4626Token.address] * underlyingMap[underlying].price).toFixed(2));

updatedTokens.push(dbToken);
tokenAndPrices.push({
address: erc4626Token.address,
chain: erc4626Token.chain,
price,
});
} catch (e: any) {
console.error('ERC4626 price failed for', erc4626Token.address, chain, e.message);
}
}
}

await updatePrices(this.id, tokenAndPrices, timestamp);

return updatedTokens;
}
}
2 changes: 2 additions & 0 deletions modules/token/lib/token-price.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import { MorphoPriceHandlerService } from './token-price-handlers/morpho-price-h
import { RektTokensHandlerService } from './token-price-handlers/rekt-tokens-handler.service';
import config from '../../../config';
import { BeetsPriceHandlerService } from './token-price-handlers/beets-price-handler.service';
import { ERC4626PriceHandlerService } from './token-price-handlers/erc4626-price-handler.service';

export class TokenPriceService {
cache: CacheClass<string, any> = new Cache<string, any>();
private readonly priceHandlers: TokenPriceHandler[] = [
new RektTokensHandlerService(),
new ERC4626PriceHandlerService(),
new FbeetsPriceHandlerService(),
new BeetsPriceHandlerService(),
new ClqdrPriceHandlerService(),
Expand Down
8 changes: 4 additions & 4 deletions modules/token/token.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ describe('Token service', () => {
await tokenService.updateTokenPrices(['SONIC']);
const prices = await tokenService.getCurrentTokenPrices(['SONIC']);

console.log(prices.find((price) => price.tokenAddress === '0x2d0e0814e62d80056181f5cd932274405966e4f0'));
console.log(prices.find((price) => price.tokenAddress === '0x541fd749419ca806a8bc7da8ac23d346f2df8b77'));
}, 500000);

test('sync tokens from pool tokens', async () => {
initRequestScopedContext();
setRequestScopedContextValue('chainId', '34443');
await tokenService.syncTokenContentData();
});
setRequestScopedContextValue('chainId', '146');
await tokenService.syncTokenContentData('SONIC');
}, 1000000);

test('get tokens', async () => {
initRequestScopedContext();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backend",
"version": "1.29.1",
"version": "1.29.2",
"description": "Backend service for Beethoven X and Balancer",
"repository": "https://github.com/balancer/backend",
"author": "Beethoven X",
Expand Down
3 changes: 3 additions & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { chainIdToChain } from '../modules/network/chain-id-to-chain';
import { backsyncSwaps } from './subgraph-syncing/backsync-swaps';
import { poolService } from '../modules/pool/pool.service';
import { initRequestScopedContext, setRequestScopedContextValue } from '../modules/context/request-scoped-context';
import { tokenService } from '../modules/token/token.service';

// TODO needed?
const sftmxController = SftmxController();
Expand Down Expand Up @@ -140,6 +141,8 @@ async function run(job: string = process.argv[2], chainId: string = process.argv
initRequestScopedContext();
setRequestScopedContextValue('chainId', chainId);
return poolService.updatePoolAprs(chain);
} else if (job === 'update-prices') {
return tokenService.updateTokenPrices([chain]);
}
// Maintenance
else if (job === 'sync-fx-quote-tokens') {
Expand Down
Loading