Skip to content
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
2 changes: 1 addition & 1 deletion config/xlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default <NetworkData>{
},
rpcUrl: 'https://rpc.xlayer.tech',
rpcMaxBlockRange: 100,
acceptableSGLag: 30, // ~1min
acceptableSGLag: 90,
protocolToken: 'bal',
balancer: {
v2: {
Expand Down
34 changes: 32 additions & 2 deletions modules/actions/lbp/sync-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ViemClient } from '../../sources/types';
import { eventsRepository } from '../../repositories/events/events-repository';
import { lbpCallsV3 } from '../../sources/contracts/pool-type-dynamic-data/lbp-calls-v3';
import { prismaBulkExecuteOperations } from '../../../prisma/prisma-util';
import { getPoolsSubgraphClient } from '../../sources/subgraphs';

/**
* Fetches new weights and updates pool tokens
Expand All @@ -14,6 +15,7 @@ export const syncData = async (
chain: Chain,
client: ViemClient,
vaultAddress: string,
poolsSubgraphClient: ReturnType<typeof getPoolsSubgraphClient>,
eventRepo = eventsRepository,
): Promise<void> => {
const [pools, tokens, dynamicDataMap] = await Promise.all([
Expand All @@ -23,7 +25,7 @@ export const syncData = async (
type: PrismaPoolType.LIQUIDITY_BOOTSTRAPPING,
protocolVersion: 3,
},
select: { id: true, version: true, typeData: true },
select: { id: true, version: true, typeData: true, factory: true },
}),
prisma.prismaPoolToken
.findMany({
Expand Down Expand Up @@ -68,6 +70,29 @@ export const syncData = async (

const updates = Object.keys(onchainData).flatMap((id) => onchainData[id].poolToken);

const subgraphPools = await poolsSubgraphClient.getAllPools({
id_in: pools.map((pool) => pool.id),
});

// compare version and factory of subgraph pools and db pools and update the db if different.
const factoryVersionUpdates = subgraphPools
.filter((subgraphPool) => {
const dbPool = pools.find((pool) => pool.id === subgraphPool.id);
if (!dbPool) return false;
if (dbPool.version !== subgraphPool.factory.version) return true;
if (dbPool.factory !== subgraphPool.factory.id) return true;
return false;
})
.map((pool) =>
prisma.prismaPool.update({
where: { id_chain: { id: pool.id, chain } },
data: {
version: pool.factory.version,
factory: pool.factory.id,
},
}),
);

const operations = updates
// Check if the weights are different
.filter((update) => {
Expand Down Expand Up @@ -131,7 +156,12 @@ export const syncData = async (
}),
);

await prismaBulkExecuteOperations([...operations, ...swapEnabledUpdates, ...holdersUpdates]);
await prismaBulkExecuteOperations([
...operations,
...swapEnabledUpdates,
...holdersUpdates,
...factoryVersionUpdates,
]);

return;
};
18 changes: 16 additions & 2 deletions modules/controllers/lbp-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,28 @@ import { PoolWithMappedJsonFields } from '../../prisma/prisma-types';
import { LBPoolData, FixedLBPData } from '../pool/pool-data';
import { priceChartData } from '../pool/lbp/price-chart-data';
import { priceChartDataFixedLBP } from '../pool/lbp/fixed-lbp-price-chart-data';
import { getPoolsSubgraphClient, getV3JoinedSubgraphClient, getVaultSubgraphClient } from '../sources/subgraphs';

export const LBPController = {
async syncData(chain: Chain) {
const client = getViemClient(chain);
const vaultAddress = config[chain].balancer.v3.vaultAddress;

const {
subgraphs: { balancerV3, balancerPoolsV3 },
balancer: {
v3: { vaultAddress },
},
} = config[chain];

if (!vaultAddress) return;
// Guard against unconfigured chains
if (!balancerV3 || !balancerPoolsV3) {
throw new Error(`Chain not configured: ${chain}`);
}

const poolsSubgraphClient = getPoolsSubgraphClient(balancerPoolsV3, chain);

await syncData(chain, client, vaultAddress);
await syncData(chain, client, vaultAddress, poolsSubgraphClient);
},
async syncDataFixedLBP(chain: Chain) {
const client = getViemClient(chain);
Expand Down
3 changes: 3 additions & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ async function run(job: string = process.argv[2], chainId: string = process.argv
} else if (job === 'sync-lbps') {
await LBPController.syncData(chain);
return 'OK';
} else if (job === 'reload-lbps') {
await LBPController.reloadLbps(chain);
return 'OK';
} else if (job === 'sync-token-yields') {
await TokenYieldsController().fetchAndStoreAllYields();
return 'OK';
Expand Down
Loading