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
10 changes: 5 additions & 5 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,7 +275,7 @@ jobs:
env:
IMAGE_TAG: v${{ needs.build-and-publish.outputs.package-version }}

deploy-billboard-clear-auction-and-distribute-tax-dev:
deploy-billboard-clear-auctions-dev:
runs-on: 'ubuntu-latest'
environment: 'dev'
needs: build-and-publish
Expand All @@ -286,7 +286,7 @@ jobs:

- name: re-deploy Lambda to dev
run: |
aws lambda update-function-code --function-name billboard-clear-auction-and-distribute-tax-dev \
aws lambda update-function-code --function-name billboard-clear-auctions-dev \
--image-uri ${{ steps.login-ecr.outputs.registry }}/$ECR_REPOSITORY:$IMAGE_TAG
env:
IMAGE_TAG: v${{ needs.build-and-publish.outputs.package-version }}
Expand Down
158 changes: 0 additions & 158 deletions handlers/clear-auction-and-distribute-tax.ts

This file was deleted.

76 changes: 76 additions & 0 deletions handlers/clear-auctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { SimulateContractErrorType } from 'viem'
import { Context, APIGatewayProxyResult, APIGatewayEvent } from 'aws-lambda'

import {
billboardContract,
publicClient,
walletClient,
} from '../lib/billboard/index.js'

type RequestBody = {
accessToken: string // to access this API
tokenIds: string[] // bigint
epochs: string[] // bigint
}

export const handler = async (
event: APIGatewayEvent,
context: Context
): Promise<APIGatewayProxyResult> => {
console.log(`Event: ${JSON.stringify(event, null, 2)}`)
console.log(`Context: ${JSON.stringify(context, null, 2)}`)

const { tokenIds, epochs, accessToken } = (
event.body ? JSON.parse(event.body) : {}
robertu7 marked this conversation as resolved.
Show resolved Hide resolved
) as RequestBody
console.log(new Date(), `from input:`, {
tokenIds: tokenIds,
epochs: epochs,
})

if (accessToken !== process.env.ACCESS_TOKEN) {
return {
statusCode: 403,
body: JSON.stringify({ message: 'invalid access token' }),
}
}

try {
const clearAuctionsResult = await publicClient.simulateContract({
...billboardContract,
functionName: 'clearAuctions',
args: [tokenIds.map((i) => BigInt(i)), epochs.map((i) => BigInt(i))],
})
await walletClient.writeContract(clearAuctionsResult.request)

const bidders = clearAuctionsResult.result.map((r) => r[0])
robertu7 marked this conversation as resolved.
Show resolved Hide resolved
const prices = clearAuctionsResult.result.map((r) => r[1])
const taxes = clearAuctionsResult.result.map((r) => r[2])

const data = {
tokenIds,
epochs,
bidders,
prices,
taxes,
}
return {
statusCode: 200,
body: JSON.stringify({ message: 'done.', data }),
}
} catch (err) {
const error = err as SimulateContractErrorType
robertu7 marked this conversation as resolved.
Show resolved Hide resolved
console.error(error.name, err)

const data = {
name: error.name,
message: error.message,
cause: error.cause,
}

return {
statusCode: 500,
body: JSON.stringify({ data, message: error.name }),
}
}
}
Loading
Loading