Skip to content

Commit 0421e33

Browse files
committed
caching twab queries for same-timestamp tiers
1 parent 5d9bcd8 commit 0421e33

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

utils/params.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Address } from "viem"
66

77
export const getAllParams = async (chainId: number, rpcUrl: string, prizePoolAddress: Address, vaultAddress: Address, userAddresses: Address[], options?: { multicallBatchSize?: number }) => {
88
const params: { [tier: number]: `0x${string}` } = {}
9+
const cachedTwabs: { [startTimestamp: number]: Awaited<ReturnType<typeof getTwabs>> } = {}
910

1011
const client = getClient(chainId, rpcUrl, options)
1112

@@ -15,7 +16,12 @@ export const getAllParams = async (chainId: number, rpcUrl: string, prizePoolAdd
1516
await Promise.all(Object.keys(tierInfo).map(async (_tier) => {
1617
const tier = parseInt(_tier)
1718
const vaultPortion = await getVaultPortion(client, prizePoolAddress, vaultAddress, { start: tierInfo[tier].startTwabDrawId, end: prizePoolInfo.lastAwardedDrawId })
18-
const { vaultTwab, userTwabs } = await getTwabs(client, prizePoolInfo.twabControllerAddress, vaultAddress, userAddresses, { start: tierInfo[tier].startTwabTimestamp, end: prizePoolInfo.lastAwardedDrawClosedAt })
19+
20+
const startTwabTimestamp = tierInfo[tier].startTwabTimestamp
21+
if(cachedTwabs[startTwabTimestamp] === undefined) {
22+
cachedTwabs[startTwabTimestamp] = await getTwabs(client, prizePoolInfo.twabControllerAddress, vaultAddress, userAddresses, { start: startTwabTimestamp, end: prizePoolInfo.lastAwardedDrawClosedAt })
23+
}
24+
const { vaultTwab, userTwabs } = cachedTwabs[startTwabTimestamp]
1925

2026
const encodedParams = encodeParams({
2127
winningRandomNumber: prizePoolInfo.randomNumber,

0 commit comments

Comments
 (0)