Skip to content

Commit 586b72f

Browse files
committed
bumped dskit + fixed 0 payout backup prize claims
1 parent 924614c commit 586b72f

4 files changed

Lines changed: 48 additions & 84 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pt-classic",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"type": "module",
55
"private": true,
66
"scripts": {
@@ -15,7 +15,7 @@
1515
},
1616
"dependencies": {
1717
"@safe-global/safe-apps-provider": "0.18.3",
18-
"dskit-eth": "0.1.10",
18+
"dskit-eth": "0.2.4",
1919
"viem": "2.20.0"
2020
},
2121
"devDependencies": {

pnpm-lock.yaml

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,3 @@ export const pageTransition: { duration: number } = { duration: 100 }
5757

5858
export const transportSettings: Omit<TransportConfig, 'name' | 'key' | 'request' | 'type'> = { retryCount: 3, retryDelay: 500 }
5959
export const publicClientSettings: Omit<ClientConfig, 'chain' | 'transport'> = { batch: { multicall: { batchSize: 1_024 * 1_024 } } }
60-
61-
export const eventQuerySettings: { maxPageSizeInBlocks: bigint; paginationDelay: number } = {
62-
maxPageSizeInBlocks: 10_000_000n,
63-
paginationDelay: 0
64-
}

src/lib/utils/events.ts

Lines changed: 40 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,18 @@ import {
1515
formatSetSwapperEvent,
1616
formatTransferEvent
1717
} from './formatting'
18-
import { eventQuerySettings, prizeHook, prizePool, prizeVault, twabRewards } from '$lib/config'
19-
import { validateClientNetwork } from './providers'
18+
import { prizeHook, prizePool, prizeVault, twabRewards } from '$lib/config'
2019
import { get } from 'svelte/store'
2120
import type { ClaimedPrizeEvent, FlashEvent, PromotionCreatedEvent, RewardsClaimedEvent, SetSwapperEvent, TransferEvent } from '$lib/types'
22-
import type { AbiEvent, Address, GetLogsParameters, GetLogsReturnType } from 'viem'
23-
24-
const getPaginatedEvents = async <Event extends AbiEvent>(
25-
params: GetLogsParameters<Event, undefined, true, bigint, bigint | 'latest'> & {
26-
fromBlock: bigint
27-
toBlock: bigint | 'latest'
28-
args?: any
29-
}
30-
) => {
31-
const publicClient = get(clients).public
32-
validateClientNetwork(publicClient)
33-
34-
const events: GetLogsReturnType<Event, undefined, true, bigint, bigint, Event['name']> = []
35-
36-
const maxBlock = params.toBlock === 'latest' ? await publicClient.getBlockNumber() : params.toBlock
37-
38-
let fromBlock = params.fromBlock
39-
let toBlock = params.fromBlock + eventQuerySettings.maxPageSizeInBlocks - 1n
40-
41-
if (toBlock > maxBlock) {
42-
toBlock = maxBlock
43-
}
44-
45-
while (toBlock <= maxBlock) {
46-
const newEventsPage = await publicClient.getLogs<Event, undefined, true, bigint, bigint>({ ...params, fromBlock, toBlock })
47-
events.push(...newEventsPage)
48-
49-
fromBlock = toBlock + 1n
50-
51-
if (toBlock !== maxBlock && toBlock + eventQuerySettings.maxPageSizeInBlocks > maxBlock) {
52-
toBlock = maxBlock
53-
} else {
54-
toBlock += eventQuerySettings.maxPageSizeInBlocks
55-
}
21+
import type { Address } from 'viem'
5622

57-
await new Promise((resolve) => setTimeout(resolve, eventQuerySettings.paginationDelay))
58-
}
59-
60-
return events
61-
}
23+
export const getTransferEvents = async (
24+
address: Address,
25+
tokenAddress: Address,
26+
options?: { filter?: 'from' | 'to'; fromBlock?: bigint }
27+
) => {
28+
const dskitClient = get(clients).dskit
6229

63-
const getTransferEvents = async (address: Address, tokenAddress: Address, options?: { filter?: 'from' | 'to'; fromBlock?: bigint }) => {
6430
const transferEvent = {
6531
type: 'event',
6632
name: 'Transfer',
@@ -74,34 +40,34 @@ const getTransferEvents = async (address: Address, tokenAddress: Address, option
7440
const fromTransferEvents =
7541
options?.filter === 'to'
7642
? []
77-
: await getPaginatedEvents({
43+
: await dskitClient.event.query({
7844
address: tokenAddress,
7945
event: transferEvent,
8046
args: { from: address },
8147
fromBlock: options?.fromBlock ?? prizeVault.deployedAtBlock,
82-
toBlock: 'latest',
83-
strict: true
48+
toBlock: 'latest'
8449
})
8550

8651
const toTransferEvents =
8752
options?.filter === 'from'
8853
? []
89-
: await getPaginatedEvents({
54+
: await dskitClient.event.query({
9055
address: tokenAddress,
9156
event: transferEvent,
9257
args: { to: address },
9358
fromBlock: options?.fromBlock ?? prizeVault.deployedAtBlock,
94-
toBlock: 'latest',
95-
strict: true
59+
toBlock: 'latest'
9660
})
9761

9862
return [...fromTransferEvents, ...toTransferEvents]
9963
}
10064

101-
const getFlashEvents = async (beneficiary: Address, swapperAddresses: Address[], options?: { fromBlock?: bigint }) => {
65+
export const getFlashEvents = async (beneficiary: Address, swapperAddresses: Address[], options?: { fromBlock?: bigint }) => {
10266
if (!swapperAddresses.length) return []
10367

104-
const flashEvents = await getPaginatedEvents({
68+
const dskitClient = get(clients).dskit
69+
70+
const flashEvents = await dskitClient.event.query({
10571
address: swapperAddresses,
10672
event: {
10773
anonymous: false,
@@ -136,15 +102,16 @@ const getFlashEvents = async (beneficiary: Address, swapperAddresses: Address[],
136102
},
137103
args: { beneficiary },
138104
fromBlock: options?.fromBlock ?? prizeVault.deployedAtBlock,
139-
toBlock: 'latest',
140-
strict: true
105+
toBlock: 'latest'
141106
})
142107

143108
return flashEvents
144109
}
145110

146-
const getSetSwapperEvents = async (userAddress: Address, options?: { fromBlock?: bigint }) => {
147-
const setSwapperEvents = await getPaginatedEvents({
111+
export const getSetSwapperEvents = async (userAddress: Address, options?: { fromBlock?: bigint }) => {
112+
const dskitClient = get(clients).dskit
113+
114+
const setSwapperEvents = await dskitClient.event.query({
148115
address: prizeHook.address,
149116
event: {
150117
anonymous: false,
@@ -158,15 +125,16 @@ const getSetSwapperEvents = async (userAddress: Address, options?: { fromBlock?:
158125
},
159126
args: { account: userAddress },
160127
fromBlock: options?.fromBlock ?? prizeVault.deployedAtBlock,
161-
toBlock: 'latest',
162-
strict: true
128+
toBlock: 'latest'
163129
})
164130

165131
return setSwapperEvents
166132
}
167133

168-
const getPromotionCreatedEvents = async (options?: { fromBlock?: bigint }) => {
169-
const promotionCreatedEvents = await getPaginatedEvents({
134+
export const getPromotionCreatedEvents = async (options?: { fromBlock?: bigint }) => {
135+
const dskitClient = get(clients).dskit
136+
137+
const promotionCreatedEvents = await dskitClient.event.query({
170138
address: twabRewards.address,
171139
event: {
172140
anonymous: false,
@@ -187,15 +155,16 @@ const getPromotionCreatedEvents = async (options?: { fromBlock?: bigint }) => {
187155
token: twabRewards.tokenOptions.map((t) => t.address)
188156
},
189157
fromBlock: options?.fromBlock ?? prizeVault.deployedAtBlock,
190-
toBlock: 'latest',
191-
strict: true
158+
toBlock: 'latest'
192159
})
193160

194161
return promotionCreatedEvents
195162
}
196163

197-
const getRewardsClaimedEvents = async (userAddress: Address, options?: { fromBlock?: bigint }) => {
198-
const rewardsClaimedEvents = await getPaginatedEvents({
164+
export const getRewardsClaimedEvents = async (userAddress: Address, options?: { fromBlock?: bigint }) => {
165+
const dskitClient = get(clients).dskit
166+
167+
const rewardsClaimedEvents = await dskitClient.event.query({
199168
address: twabRewards.address,
200169
event: {
201170
anonymous: false,
@@ -212,15 +181,16 @@ const getRewardsClaimedEvents = async (userAddress: Address, options?: { fromBlo
212181
user: userAddress
213182
},
214183
fromBlock: options?.fromBlock ?? prizeVault.deployedAtBlock,
215-
toBlock: 'latest',
216-
strict: true
184+
toBlock: 'latest'
217185
})
218186

219187
return rewardsClaimedEvents
220188
}
221189

222-
const getClaimedPrizeEvents = async (userAddress: Address, options?: { fromBlock?: bigint }) => {
223-
const claimedPrizeEvents = await getPaginatedEvents({
190+
export const getClaimedPrizeEvents = async (userAddress: Address, options?: { fromBlock?: bigint }) => {
191+
const dskitClient = get(clients).dskit
192+
193+
const claimedPrizeEvents = await dskitClient.event.query({
224194
address: prizePool.address,
225195
event: {
226196
anonymous: false,
@@ -244,8 +214,7 @@ const getClaimedPrizeEvents = async (userAddress: Address, options?: { fromBlock
244214
recipient: userAddress
245215
},
246216
fromBlock: options?.fromBlock ?? prizeVault.deployedAtBlock,
247-
toBlock: 'latest',
248-
strict: true
217+
toBlock: 'latest'
249218
})
250219

251220
return claimedPrizeEvents
@@ -288,7 +257,9 @@ export const updateUserClaimedPrizeEvents = async (userAddress: Address, oldClai
288257
await getClaimedPrizeEvents(userAddress, {
289258
fromBlock: !!lastClaimedPrizeEvent ? BigInt(lastClaimedPrizeEvent.blockNumber) + 1n : undefined
290259
})
291-
).map(formatClaimedPrizeEvent)
260+
)
261+
.map(formatClaimedPrizeEvent)
262+
.filter((e) => e.args.payout !== '0')
292263

293264
const updatedUserClaimedPrizeEvents = [...oldClaimedPrizeEvents, ...newClaimedPrizeEvents]
294265
userClaimedPrizeEvents.set(updatedUserClaimedPrizeEvents)

0 commit comments

Comments
 (0)