Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(billboard): add /qf-finalize and remove clear-auction-and-distribute-tax handler #147

Merged
merged 9 commits into from
Sep 3, 2024
22 changes: 3 additions & 19 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Build & Deploy

on:
pull_request:
branches: [ main, master, develop, stage ]
types: [ closed ]
branches: [main, master, develop, stage]
types: [closed]

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down Expand Up @@ -258,7 +258,7 @@ jobs:
--image-uri ${{ steps.login-ecr.outputs.registry }}/$ECR_REPOSITORY:$IMAGE_TAG
env:
IMAGE_TAG: v${{ needs.build-and-publish.outputs.package-version }}

deploy-daily-summary-email-dev:
runs-on: 'ubuntu-latest'
environment: 'dev'
Expand All @@ -275,22 +275,6 @@ jobs:
env:
IMAGE_TAG: v${{ needs.build-and-publish.outputs.package-version }}

deploy-billboard-clear-auction-and-distribute-tax-dev:
runs-on: 'ubuntu-latest'
environment: 'dev'
needs: build-and-publish
steps:
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: re-deploy Lambda to dev
run: |
aws lambda update-function-code --function-name billboard-clear-auction-and-distribute-tax-dev \
--image-uri ${{ steps.login-ecr.outputs.registry }}/$ECR_REPOSITORY:$IMAGE_TAG
env:
IMAGE_TAG: v${{ needs.build-and-publish.outputs.package-version }}

deploy-check-nomad-badge-dev:
runs-on: 'ubuntu-latest'
environment: 'dev'
Expand Down
1 change: 0 additions & 1 deletion bin/qf-calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ async function main() {
fromBlock,
toBlock,
amountTotal,
write_gist: true, // for server side running output;
})
console.log(new Date(), 'res:', res)
}
Expand Down
158 changes: 0 additions & 158 deletions handlers/clear-auction-and-distribute-tax.ts

This file was deleted.

80 changes: 61 additions & 19 deletions handlers/qf-calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { formatUnits } from 'viem'
import * as d3 from 'd3-array'
import {
calculateQFScore,
finalizeQFScore,
MattersBillboardS3Bucket,
isProd,
s3FilePathPrefix,
Expand All @@ -12,7 +13,7 @@ import {
sendQfNotifications, // sendQfNotificationNEmails,
} from '../lib/qf-notify.js'
import { s3GetFile } from '../lib/utils/aws.js'
import { SLACK_MESSAGE_STATE, Slack } from '../lib/utils/slack.js'
// import { SLACK_MESSAGE_STATE, Slack } from '../lib/utils/slack.js'

const ACCESS_TOKEN = `${process.env.ACCESS_TOKEN}`

Expand All @@ -35,7 +36,7 @@ export const handler = async (
console.log(`Context: ${JSON.stringify(context, null, 2)}`)
// const forceRun = !!("forceRun" in ((event?.queryStringParameters as any) || {}));

const slack = new Slack()
// const slack = new Slack()
const { method, path } = ((event?.requestContext as any)?.http as any) || {}
const queryStringParameters = (event?.queryStringParameters as any) || {}
const {
Expand All @@ -58,6 +59,7 @@ export const handler = async (
event?.forceRun ||
(path === '/qf-calculator' && accept?.startsWith('application/json')) ||
(path === '/send-notifications' && accept) ||
(path === '/qf-finalize' && accept) ||
(path === '/get-rounds' && accept)
)
) {
Expand Down Expand Up @@ -161,20 +163,20 @@ export const handler = async (
amountTotal,
6
)} USDT to ${sent?.length ?? 0} authors`
if (Array.isArray(sent) && sent?.length > 0) {
await slack.sendStripeAlert({
data: {
amountTotal,
sent: sent.length,
distrib: sent.map(
({ userName, displayName, amount }: any) =>
`${displayName} @${userName} ${amount} USDT`
),
},
message,
state: SLACK_MESSAGE_STATE.successful,
})
}
// if (Array.isArray(sent) && sent?.length > 0) {
// await slack.sendStripeAlert({
// data: {
// amountTotal,
// sent: sent.length,
// distrib: sent.map(
// ({ userName, displayName, amount }: any) =>
// `${displayName} @${userName} ${amount} USDT`
// ),
// },
// message,
// state: SLACK_MESSAGE_STATE.successful,
// })
// }
return {
statusCode: 200,
body: message,
Expand All @@ -191,11 +193,11 @@ export const handler = async (
path === '/qf-calculator' &&
accept?.startsWith('application/json')
) {
const { fromTime, toTime, fromBlock, toBlock, amountTotal, finalize } = (
const { fromBlock, toBlock, amountTotal, finalize } = (
event?.forceRun ? event : queryStringParameters
) as InputBodyParameters

const { root, gist_url } =
const { root } =
(await calculateQFScore({
// fromTime, toTime,
fromBlock: BigInt(fromBlock),
Expand All @@ -218,7 +220,47 @@ export const handler = async (
body: JSON.stringify({
message: 'done.',
root, // tree
gist_url,
}),
}
} else if (
method === 'POST' &&
path === '/qf-finalize' &&
accept?.startsWith('application/json')
) {
const { fromBlock, toBlock } = (
event?.forceRun ? event : queryStringParameters
) as InputBodyParameters

if (!fromBlock || !toBlock) {
return {
statusCode: 400,
body: JSON.stringify({
message: 'bad parameters, fromBlock and toBlock are required.',
}),
}
}

const { root } =
(await finalizeQFScore({
fromBlock: BigInt(fromBlock),
toBlock: BigInt(toBlock),
})) || {}

if (!root) {
return {
statusCode: 400,
body: JSON.stringify({
message: 'bad parameters, no tree root, check logs for details.',
}),
}
}

return {
statusCode: 200,
headers: { 'content-type': 'application/json; charset=utf-8' },
body: JSON.stringify({
message: 'done.',
root,
}),
}
}
Expand Down
Loading
Loading