Skip to content

Commit

Permalink
Fix onchain data to handle broken rates.
Browse files Browse the repository at this point in the history
  • Loading branch information
johngrantuk committed Aug 25, 2023
1 parent 20f8cc7 commit 3693895
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions test/lib/onchainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,14 @@ export async function getOnChainBalances(
);

multiPool.call(`${pool.id}.targets`, pool.address, 'getTargets');
multiPool.call(
`${pool.id}.rate`,
pool.address,
'getWrappedTokenRate'
);
// AaveLinear pools with version === 1 rates will still work
if (pool.poolType === 'AaveLinear' && pool.poolTypeVersion === 1) {
multiPool.call(
`${pool.id}.rate`,
pool.address,
'getWrappedTokenRate'
);
}
} else if (pool.poolType.toString().includes('Gyro')) {
multiPool.call(
`${pool.id}.swapFee`,
Expand Down Expand Up @@ -252,19 +255,24 @@ export async function getOnChainBalances(
);
}

const wrappedIndex = subgraphPools[index].wrappedIndex;
if (
wrappedIndex === undefined ||
onchainData.rate === undefined
subgraphPools[index].poolType === 'AaveLinear' &&
subgraphPools[index].poolTypeVersion === 1
) {
console.error(
`Linear Pool Missing WrappedIndex or PriceRate: ${poolId}`
);
return;
const wrappedIndex = subgraphPools[index].wrappedIndex;
if (
wrappedIndex === undefined ||
onchainData.rate === undefined
) {
console.error(
`Linear Pool Missing WrappedIndex or PriceRate: ${poolId}`
);
return;
}
// Update priceRate of wrappedToken
subgraphPools[index].tokens[wrappedIndex].priceRate =
formatFixed(onchainData.rate, 18);
}
// Update priceRate of wrappedToken
subgraphPools[index].tokens[wrappedIndex].priceRate =
formatFixed(onchainData.rate, 18);
}

subgraphPools[index].swapFee = formatFixed(swapFee, 18);
Expand Down

0 comments on commit 3693895

Please sign in to comment.