Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions apps/staking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
"version": "0.0.2",
"private": true,
"scripts": {
"start": "npx tsx ./src/index.ts",
"build": "tsc",
"clean": "rm -rf dist",
"dev": "npx tsx watch ./src/index.ts",
"test": "vitest",
"lint": "tsc --noEmit && eslint \"src/**/*.ts*\""
"lint": "tsc --noEmit && eslint \"src/**/*.ts*\"",
"start": "node ./dist/index.js",
"test": "vitest"
},
"jest": {
"preset": "jest-presets/jest/node"
},
"dependencies": {
"@audius/eth": "0.1.0",
"@audius/eth": "1.0.0",
"@audius/sdk": "10.0.0",
"@pedalboard/basekit": "*",
"@pedalboard/logger": "*",
Expand Down
4 changes: 3 additions & 1 deletion apps/staking/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import dotenv from 'dotenv'

dotenv.config()

const PORT = 6000

export type SharedData = {
ethRpcEndpoint: string
viemClient: PublicClient<HttpTransport, typeof mainnet>
Expand All @@ -27,7 +29,7 @@ const main = async () => {
chain: mainnet,
transport: http(process.env.eth_rpc_endpoint!)
}),
port: process.env.port ? parseInt(process.env.port) : 6000
port: PORT
}
await new App<SharedData>({ appData: sharedData })
.task(async (app: App<SharedData>) => {
Expand Down
6 changes: 3 additions & 3 deletions apps/staking/src/routes/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { NextFunction, Request, Response } from 'express'
import { App } from '@pedalboard/basekit'
import { SharedData } from '..'

export const health = (app: App<SharedData>) => async (
req: Request,
export const health = (_app: App<SharedData>) => async (
_req: Request,
res: Response,
next: NextFunction
) => {
res.send({ status: 'up', port: app.viewAppData().port })
res.send({ status: 'ok' })
next()
}
29 changes: 21 additions & 8 deletions apps/staking/src/routes/initRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@ import { NextFunction, Request, Response } from 'express'
import { App } from '@pedalboard/basekit'
import { SharedData } from '..'
import { ClaimsManager } from '@audius/eth'
import { PublicClient } from 'viem'

export const initRound = (app: App<SharedData>) => async (
req: Request,
res: Response,
next: NextFunction
) => {
const { viemClient } = app.viewAppData()
const claimsManager = new ClaimsManager(viemClient as PublicClient)

const latestBlock = Number((await viemClient.getBlock()).number)
const lastFundedBlockNumber = Number(await claimsManager.getLastFundedBlock())
const fundingRoundBlockDiff = Number(await claimsManager.getFundingRoundBlockDiff())
const [latestBlock, lastFundedBlockNumber, fundingRoundBlockDiff] =
await Promise.all([
viemClient.getBlock().then((b) => Number(b.number)),
viemClient
.readContract({
abi: ClaimsManager.abi,
address: ClaimsManager.address,
functionName: 'getLastFundedBlock'
})
.then(Number),
viemClient
.readContract({
abi: ClaimsManager.abi,
address: ClaimsManager.address,
functionName: 'getFundingRoundBlockDiff'
})
.then(Number)
])

const blockDiff = latestBlock - lastFundedBlockNumber

if (lastFundedBlockNumber < latestBlock - 1.1 * fundingRoundBlockDiff) {
Expand All @@ -23,7 +37,7 @@ export const initRound = (app: App<SharedData>) => async (
lastFundedBlockNumber,
latestBlock,
fundingRoundBlockDiff,
blockDiff,
blockDiff
})
next()
return
Expand All @@ -34,8 +48,7 @@ export const initRound = (app: App<SharedData>) => async (
lastFundedBlockNumber,
latestBlock,
fundingRoundBlockDiff,
blockDiff,
blockDiff
})
next()
}

32 changes: 30 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading