Skip to content

Commit

Permalink
feat: remove multicall for supply + bean
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean committed Oct 21, 2024
1 parent 11bfd96 commit d23c2eb
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions projects/ui/src/state/bean/pools/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ export const useFetchPools = () => {
];
const lpMulticall = makeLPMulticall(beanstalk.address, poolsArr);

const [priceResult, poolsResult, _lpResults] = await Promise.all([
const [priceResult, beanTotalSupply, totalDeltaB, _lpResults] = await Promise.all([
beanstalkPrice.price(),
multicall(config, {
contracts: priceAndBeanCalls,
allowFailure: true,
}),
BEAN.getContract().totalSupply().then(tokenResult(BEAN)),
beanstalk.totalDeltaB().then(tokenResult(BEAN)),
// fetch [poolDeltaB, totalSupply] for each pool, in chunks of 20
Promise.all(
lpMulticall.calls.map((lpCall) =>
Expand All @@ -59,18 +57,19 @@ export const useFetchPools = () => {
).then((result) => chunkArray(result.flat(), lpMulticall.chunkSize)),
]);

console.debug(`${pageContext} MULTICALL RESULTS: `, {
console.debug(`${pageContext} FETCH: `, {
lpMulticall,
priceResult,
priceAndBeanCalls,
_lpResults,
poolsResult,
beanTotalSupply,
totalDeltaB,
});

const [beanTotalSupply, totalDeltaB] = [
extract(poolsResult[0], 'bean.totalSupply'),
extract(poolsResult[1], 'totalDeltaB'),
];
// const [beanTotalSupply, totalDeltaB] = [
// extract(poolsResult[0], 'bean.totalSupply'),
// extract(poolsResult[1], 'totalDeltaB'),
// ];

const lpResults = _lpResults.reduce<Record<string, LPResultType>>(
(prev, [_deltaB, _supply], i) => {
Expand Down Expand Up @@ -137,7 +136,7 @@ export const useFetchPools = () => {
}

if (beanTotalSupply) {
dispatch(updateSupply(transform(beanTotalSupply, 'bnjs', BEAN)));
dispatch(updateSupply(beanTotalSupply));
}

if (totalDeltaB) {
Expand Down Expand Up @@ -215,17 +214,6 @@ function makeTotalDeltaBMulticall(
};
}

function makePriceMulticall(
address: string
): ContractFunctionParameters<typeof BEANSTALK_ABI_SNIPPETS.price> {
return {
address: address as `0x${string}`,
abi: BEANSTALK_ABI_SNIPPETS.price,
functionName: 'price',
args: [],
};
}

function makeLPMulticall(
beanstalkAddress: string,
pools: Pool[]
Expand Down

0 comments on commit d23c2eb

Please sign in to comment.