Skip to content

Commit

Permalink
Speedrun leaderboard (#180)
Browse files Browse the repository at this point in the history
* shovel config

* bump starting block

* pull in ownership transfers

* leaderboard queries

* doc

* listen on speedruns transfer

* rm ownership transfer events from shovel config / test
  • Loading branch information
psugihara authored Jun 20, 2024
1 parent b3b0e72 commit 5c8bc6a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 257 deletions.
19 changes: 9 additions & 10 deletions server/shovel-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
PGColumnType,
IndexStatment
} from '@indexsupply/shovel-config'
import { Problems, Bodies, Solver } from './contracts'
import { AnybodyProblem, Speedruns } from './contracts'
import { ethers } from 'ethers'
import { camelToSnakeCase } from './src/util'

Expand Down Expand Up @@ -55,14 +55,14 @@ const STARTING_BLOCK = {
// mainnet: BigInt('2067803')
sepolia: BigInt('5716600'),
garnet: BigInt('2067803'),
base_sepolia: BigInt('11258000')
base_sepolia: BigInt('11476234')
}

// n.b. sources must match ABI in contracts to correctly sync
export const sources: KnownSource[] = [baseSepolia]

const contracts = Object.fromEntries(
[Problems, Bodies, Solver].map((contract) => {
[AnybodyProblem, Speedruns].map((contract) => {
const abi = contract.abi.abi
return [
contract.abi.contractName,
Expand Down Expand Up @@ -153,16 +153,15 @@ async function integrationFor(
if (process.env.OUTPUT) {
;(async function main() {
let integrations = await Promise.all([
integrationFor('Problems', 'Transfer', [
integrationFor('Speedruns', 'Transfer', [
['block_num DESC', 'tx_idx DESC', 'log_idx DESC']
]),
integrationFor('Bodies', 'Transfer', [
['block_num DESC', 'tx_idx DESC', 'log_idx DESC']
integrationFor('AnybodyProblem', 'RunCreated'),
integrationFor('AnybodyProblem', 'RunSolved', [
['accumulative_time ASC']
]),
integrationFor('Solver', 'Solved'),
integrationFor('Bodies', 'bodyBorn'),
integrationFor('Problems', 'bodyAdded'),
integrationFor('Problems', 'bodyRemoved')
integrationFor('AnybodyProblem', 'LevelCreated'),
integrationFor('AnybodyProblem', 'LevelSolved', [['time ASC']])
])

const config = makeConfig({
Expand Down
7 changes: 4 additions & 3 deletions server/shovel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ describe('shovel sanity test', () => {
// public | problems_body_removed | 0

expect(rows).toBeDefined()
expect(rowCount).toBeGreaterThanOrEqual(6)
expect(rowCount).toBeGreaterThanOrEqual(7)

const tablesWithRows = rows.filter((row) => row.rows_n > 0)
expect(tablesWithRows.length).toBeGreaterThanOrEqual(5)
// TODO: uncomment when there's data
// const tablesWithRows = rows.filter((row) => row.rows_n > 0)
// expect(tablesWithRows.length).toBeGreaterThanOrEqual(5)
})
})
12 changes: 6 additions & 6 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Chain, sources } from '../shovel-config'
import { publish, addSubscriber, unsubscribe } from './publish'
import { cors } from 'hono/cors'

// This is a read-only API server that serves the leaderboard state, including all problems and owners.
// This is a read-only API server that serves the leaderboard state.
// It uses Server Sent Events (SSE) to push updates to the client.

// Design notes:
Expand All @@ -31,11 +31,11 @@ async function setupListener() {
await publish()
})
for (const source of sources) {
db.query(`LISTEN "${source.name}-problems_transfer"`)
db.query(`LISTEN "${source.name}-problems_body_added"`)
db.query(`LISTEN "${source.name}-problems_body_removed"`)
db.query(`LISTEN "${source.name}-solver_solved"`)
db.query(`LISTEN "${source.name}-bodies_transfer"`)
db.query(`LISTEN "${source.name}-anybody_problem_level_created"`)
db.query(`LISTEN "${source.name}-anybody_problem_level_solved"`)
db.query(`LISTEN "${source.name}-anybody_problem_run_created"`)
db.query(`LISTEN "${source.name}-anybody_problem_run_solved"`)
db.query(`LISTEN "${source.name}-speedruns_transfer"`)
}

await Promise.all(
Expand Down
Loading

0 comments on commit 5c8bc6a

Please sign in to comment.