Skip to content

Commit

Permalink
Merge pull request #1587 from ReflectiveChimp/feat/sort-vaults
Browse files Browse the repository at this point in the history
Sort vaults by contract address
  • Loading branch information
ReflectiveChimp authored Dec 10, 2024
2 parents 60409de + 44918ce commit 27aca1b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/api/stats/getMultichainVaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,27 @@ async function updateMultichainVaults() {
}

function buildFromChains() {
multichainVaults = Object.values(vaultsByChain).flat();
multichainVaults = sortBy(Object.values(vaultsByChain).flat(), v => v.earnContractAddress.toLowerCase());
vaultsByID = keyBy(multichainVaults, 'id');

Object.keys(vaultsByChain).forEach(chain => serviceEventBus.emit(`vaults/${chain}/ready`));
serviceEventBus.emit('vaults/updated');
}

function buildFromGovChains() {
multichainGovVaults = Object.values(govVaultsByChain).flat();
multichainGovVaults = sortBy(Object.values(govVaultsByChain).flat(), v =>
v.earnContractAddress.toLowerCase()
);
govVaultsById = keyBy(multichainGovVaults, 'id');

Object.keys(multichainGovVaults).forEach(chain => serviceEventBus.emit(`gov-vaults/${chain}/ready`));
serviceEventBus.emit('gov-vaults/updated');
}

function buildFromCowChains() {
multichainCowVaults = Object.values(cowVaultsByChain).flat();
multichainCowVaults = sortBy(Object.values(cowVaultsByChain).flat(), v =>
v.earnContractAddress.toLowerCase()
);
cowVaultsById = keyBy(multichainCowVaults, 'id');

Object.keys(multichainCowVaults).forEach(chain => serviceEventBus.emit(`cow-vaults/${chain}/ready`));
Expand All @@ -190,15 +194,15 @@ async function updateChainVaults(chain) {
const vaults = await getVaults(endpoint);
vaults.forEach(vault => (vault.chain = chain));

let chainVaults = vaults.filter(vault => vault.type === 'standard');
let chainVaults: Vault[] = vaults.filter(vault => vault.type === 'standard');
chainVaults = await getStrategies(chainVaults, chain);
chainVaults = await getLastHarvests(chainVaults, chain);
chainVaults = await fetchChainVaultsPpfs(chainVaults, chain);

let govVaults = vaults.filter(vault => vault.type === 'gov');
let govVaults: GovVault[] = vaults.filter(vault => vault.type === 'gov');
govVaults = await getGovVaultsTotalSupply(govVaults, chain);

let cowVaults = vaults.filter(vault => vault.type === 'cowcentrated');
let cowVaults: CowVault[] = vaults.filter(vault => vault.type === 'cowcentrated');
cowVaults = await getStrategies(cowVaults, chain);
cowVaults = await getLastHarvests(cowVaults, chain);

Expand All @@ -210,9 +214,9 @@ async function updateChainVaults(chain) {
}
}

vaultsByChain[chain] = chainVaults;
govVaultsByChain[chain] = govVaults;
cowVaultsByChain[chain] = cowVaults;
vaultsByChain[chain] = sortBy(chainVaults, v => v.earnContractAddress.toLowerCase());
govVaultsByChain[chain] = sortBy(govVaults, v => v.earnContractAddress.toLowerCase());
cowVaultsByChain[chain] = sortBy(cowVaults, v => v.earnContractAddress.toLowerCase());

if (LOG_PER_CHAIN) {
console.log(`> updated vaults on ${chain} - ${chainVaults.length}`);
Expand Down
1 change: 1 addition & 0 deletions src/api/vaults/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type GovVault = {
retiredAt?: number | undefined;
totalSupply: number;
chain: ApiChain;
lastHarvest?: number; // for CLM Pools only (copied from CLM base)
};

export type CowVault = {
Expand Down
3 changes: 1 addition & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ const MULTICHAIN_ENDPOINTS: Partial<Record<ApiChain, string>> = {
sei: SEI_VAULTS_ENDPOINT,
rootstock: ROOTSTOCK_VAULTS_ENDPOINT,
scroll: SCROLL_VAULTS_ENDPOINT,
// lisk: LISK_VAULTS_ENDPOINT,
lisk: LISK_VAULTS_ENDPOINT,
} as const;

Expand Down Expand Up @@ -380,5 +379,5 @@ export {
SCROLL_VAULTS_ENDPOINT,
LISK_RPC,
LISK_CHAIN_ID,
// LISK_VAULTS_ENDPOINT,
LISK_VAULTS_ENDPOINT,
};

0 comments on commit 27aca1b

Please sign in to comment.