Skip to content

Commit

Permalink
Merge dev -> main rewards updates and distribution 7. (#778)
Browse files Browse the repository at this point in the history
* Update sendtag pricing to 2/4/8/16

* Update app test snaps

* update directions for snapshot (#761)

* Alter Distributions to support new distribution requirements

* Prep Distribitor for V2 by renaming to V1

* DistributorV2

* Distribution 7

* Fix distribution summary view

* rewards landing

* Update Distribution Seven

* Update Activity Metric View to include verification values

* Rewards Activity Page

* Rewards Activity Header

* Rewards Activity Distribution Select

* rewards activity distribution requirements card

* Add Cards for Rewards Activity Perks

* Add cards for activity rewards multipliers

* Rewards Claimable Card

* Add data to rewards landing page

* fix sendtag referrer, prioritize referrer code

* fix restore script

* fix snaplet restore

* Revert changes to already applied migration

* Fix migration order

* Monthly Rewards tweaks

* Fix rounding errors in distributor with hack

* More Send Rewards Tweaks

* And More Rewards Tweaks

* Fix preview ci env. point db to staging

---------

Co-authored-by: Brandon Young <brandon@envoymobile.com>
Co-authored-by: Big Boss <bigboss@metalrodeo.xyz>
Co-authored-by: youngkidwarrior <victor@she.energy>
Co-authored-by: Tawnee <tawnee.a@proton.me>
  • Loading branch information
5 people authored Oct 20, 2024
1 parent a504eaa commit 29e5a2b
Show file tree
Hide file tree
Showing 33 changed files with 3,911 additions and 1,641 deletions.
68 changes: 14 additions & 54 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,47 +297,7 @@ jobs:
with:
name: nextjs-build
path: ${{ github.workspace }}/apps/next/.next
# - name: Get Supabase Database Branch
# if: github.base_ref == 'dev'
# uses: 0xbigboss/supabase-branch-gh-action@v1
# id: supabase-branch
# with:
# supabase-access-token: ${{ secrets.SUPABASE_EXPERIMENTAL_ACCESS_TOKEN }}
# supabase-project-id: ${{ secrets.STAGING_SUPABASE_PROJECT_ID }}
# wait-for-migrations: false # Optional. Default is false.
# timeout: 60 # Optional. Default is 60.
# - name: Add SMS provider to Supabase branch
# if: github.base_ref == 'dev'
# uses: 0xbigboss/supabase-manager-script-gh-action@v1
# id: add-sms-provider
# with:
# supabase-access-token: ${{ secrets.SUPABASE_EXPERIMENTAL_ACCESS_TOKEN }}
# script: |
# const parentAuthConfig = await supabaseManager.projectsConfig.getV1AuthConfig({
# ref: process.env.SUPABASE_PARENT_PROJECT_ID,
# });

# core.info('Enabling Twilio verify external phone auth provider');

# await supabaseManager.projectsConfig.updateV1AuthConfig({
# ref: process.env.SUPABASE_PROJECT_ID,
# requestBody: {
# external_phone_enabled: true,
# sms_provider: parentAuthConfig.sms_provider,
# sms_twilio_verify_account_sid:
# parentAuthConfig.sms_twilio_verify_account_sid,
# sms_twilio_verify_auth_token: parentAuthConfig.sms_twilio_verify_auth_token,
# sms_twilio_verify_message_service_sid:
# parentAuthConfig.sms_twilio_verify_message_service_sid,
# },
# });

# core.info('Done');

# return "success";
# env:
# SUPABASE_PROJECT_ID: ${{ steps.supabase-branch.outputs.project_ref }}
# SUPABASE_PARENT_PROJECT_ID: ${{ steps.supabase-branch.outputs.parent_project_ref }}
- name: Extract branch name
id: extract-branch
uses: ./.github/actions/extract-branch
Expand All @@ -352,34 +312,34 @@ jobs:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
public-hostname: ${{ steps.public-hostname.outputs.public-hostname }}
deploy-preview-extra-args: >-
-e SUPABASE_DB_URL="postgresql://${{steps.supabase-branch.outputs.db_user}}.${{steps.supabase-branch.outputs.project_ref}}:${{steps.supabase-branch.outputs.db_pass}}@fly-0-iad.pooler.supabase.com:${{steps.supabase-branch.outputs.db_port}}/postgres"
-e SUPABASE_JWT_SECRET="${{steps.supabase-branch.outputs.jwt_secret}}"
-e SUPABASE_SERVICE_ROLE="${{ steps.supabase-branch.outputs.service_role_key }}"
-e NEXT_PUBLIC_SUPABASE_URL="https://${{ steps.supabase-branch.outputs.project_ref }}.supabase.co"
-e NEXT_PUBLIC_SUPABASE_PROJECT_ID="${{steps.supabase-branch.outputs.project_ref}}"
-e NEXT_PUBLIC_SUPABASE_GRAPHQL_URL="${{steps.supabase-branch.outputs.graphql_url}}"
-e SUPABASE_DB_URL="${{ secrets.STAGING_SUPABASE_DB_URL }}"
-e SUPABASE_JWT_SECRET="${{ secrets.STAGING_SUPABASE_JWT_SECRET }}"
-e SUPABASE_SERVICE_ROLE="${{ secrets.STAGING_SUPABASE_SERVICE_ROLE }}"
-e NEXT_PUBLIC_SUPABASE_URL="https://${{ secrets.STAGING_SUPABASE_PROJECT_ID }}.supabase.co"
-e NEXT_PUBLIC_SUPABASE_PROJECT_ID="${{ secrets.STAGING_SUPABASE_PROJECT_ID }}"
-e NEXT_PUBLIC_SUPABASE_GRAPHQL_URL="https://${{ secrets.STAGING_SUPABASE_PROJECT_ID }}.supabase.co/graphql"
-e NEXT_PUBLIC_BASE_CHAIN_ID="84532"
-e NEXT_PUBLIC_MAINNET_CHAIN_ID="11155111"
-e NEXT_PUBLIC_BASE_RPC_URL="${{ secrets.BASE_SEPOLIA_RPC_URL }}"
-e NEXT_PUBLIC_MAINNET_RPC_URL="https://ethereum-sepolia-rpc.publicnode.com"
-e NEXT_PUBLIC_SUPABASE_ANON_KEY="${{ steps.supabase-branch.outputs.anon_key }}"
-e NEXT_PUBLIC_SUPABASE_ANON_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVncXRvdWxleGh2YWhldnN5c3VxIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTMwOTE5MzUsImV4cCI6MjAwODY2NzkzNX0.RL8W-jw2rsDhimYl8KklF2B9bNTPQ-Kj5zZA0XlufUA"
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_GIT_COMMIT_SHA: ${{ github.sha }}
VERCEL_GIT_COMMIT_REF: ${{ github.head_ref }}
VERCEL_GIT_PULL_REQUEST_ID: ${{ github.event.pull_request.number }}
SUPABASE_DB_URL: postgresql://${{steps.supabase-branch.outputs.db_user}}.${{steps.supabase-branch.outputs.project_ref}}:${{steps.supabase-branch.outputs.db_pass}}@fly-0-iad.pooler.supabase.com:${{steps.supabase-branch.outputs.db_port}}/postgres
SUPABASE_JWT_SECRET: ${{steps.supabase-branch.outputs.jwt_secret}}
SUPABASE_SERVICE_ROLE: ${{ steps.supabase-branch.outputs.service_role_key }}
NEXT_PUBLIC_SUPABASE_URL: https://${{ steps.supabase-branch.outputs.project_ref }}.supabase.co
NEXT_PUBLIC_SUPABASE_PROJECT_ID: ${{steps.supabase-branch.outputs.project_ref}}
NEXT_PUBLIC_SUPABASE_GRAPHQL_URL: ${{steps.supabase-branch.outputs.graphql_url}}
SUPABASE_DB_URL: ${{ secrets.STAGING_SUPABASE_DB_URL }}
SUPABASE_JWT_SECRET: ${{ secrets.STAGING_SUPABASE_JWT_SECRET }}
SUPABASE_SERVICE_ROLE: ${{ secrets.STAGING_SUPABASE_SERVICE_ROLE }}
NEXT_PUBLIC_SUPABASE_URL: https://${{ secrets.STAGING_SUPABASE_PROJECT_ID }}.supabase.co
NEXT_PUBLIC_SUPABASE_PROJECT_ID: ${{ secrets.STAGING_SUPABASE_PROJECT_ID }}
NEXT_PUBLIC_SUPABASE_GRAPHQL_URL: https://${{ secrets.STAGING_SUPABASE_PROJECT_ID }}.supabase.co/graphql
NEXT_PUBLIC_BASE_CHAIN_ID: 84532
NEXT_PUBLIC_MAINNET_CHAIN_ID: 11155111
NEXT_PUBLIC_BASE_RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }}
NEXT_PUBLIC_MAINNET_RPC_URL: https://ethereum-sepolia-rpc.publicnode.com
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ steps.supabase-branch.outputs.anon_key }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVncXRvdWxleGh2YWhldnN5c3VxIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTMwOTE5MzUsImV4cCI6MjAwODY2NzkzNX0.RL8W-jw2rsDhimYl8KklF2B9bNTPQ-Kj5zZA0XlufUA
- name: Vercel Deploy Preview
if: github.base_ref != 'dev'
id: vercel-deploy-preview
Expand Down
4 changes: 1 addition & 3 deletions apps/distributor/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Send Token Distributor

This is a singleton Fastify app that analyzes Ethereum mainnet blocks for Send token transfers and re-calculates the distribution shares for each Send token holder.
Expand All @@ -20,7 +19,7 @@ if (err.error) {

// send post request to distributor running at localhost:3050

const response = await fetch('http://localhost:3050/distributor', {
const response = await fetch('http://localhost:3050/distributor/v2', {
method: 'POST',
body: JSON.stringify({ id: 1 }),
headers: {
Expand All @@ -32,7 +31,6 @@ const response = await fetch('http://localhost:3050/distributor', {
// get the response body
const body = await response.json()
console.log(body)

```

## Getting Started with [Fastify-CLI](https://www.npmjs.com/package/fastify-cli)
Expand Down
37 changes: 31 additions & 6 deletions apps/distributor/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import express, { type Request, type Response, Router } from 'express'
import pino from 'pino'
import { DistributorWorker } from './distributor'
import { DistributorV1Worker } from './distributor'
import { StandardMerkleTree } from '@openzeppelin/merkle-tree'
import { selectAll } from 'app/utils/supabase/selectAll'
import { supabaseAdmin } from './supabase'
import { DistributorV2Worker } from './distributorv2'

const logger = pino({
level: process.env.LOG_LEVEL || 'info',
// ...other Pino options
})

// Initialize DistributorWorker
const distributorWorker = new DistributorWorker(logger)
const distributorV1Worker = new DistributorV1Worker(logger, false)
const distributorV2Worker = new DistributorV2Worker(logger)

// Initialize Express app
const app = express()
Expand All @@ -25,10 +27,17 @@ app.get('/', (req, res) => {

const distributorRouter = Router()

distributorRouter.get('/', async (req: Request, res: Response) => {
distributorRouter.get('/v1', async (req: Request, res: Response) => {
res.json({
distributor: true,
...distributorWorker.toJSON(),
...distributorV1Worker.toJSON(),
})
})

distributorRouter.get('/v2', async (req: Request, res: Response) => {
res.json({
distributor: true,
...distributorV2Worker.toJSON(),
})
})

Expand Down Expand Up @@ -97,11 +106,11 @@ distributorRouter.post('/merkle', checkAuthorization, async (req: Request, res:
res.json(result)
})

distributorRouter.post('/', checkAuthorization, async (req, res) => {
distributorRouter.post('/v1', checkAuthorization, async (req, res) => {
const { id } = req.body as { id: string }
logger.info({ id }, 'Received request to calculate distribution')
try {
await distributorWorker.calculateDistribution(id)
await distributorV1Worker.calculateDistribution(id)
} catch (err) {
logger.error(err, 'Error while calculating distribution')
res.status(500).json({
Expand All @@ -117,6 +126,22 @@ distributorRouter.post('/', checkAuthorization, async (req, res) => {
})
})

distributorRouter.post('/v2', checkAuthorization, async (req, res) => {
const { id } = req.body as { id: string }
logger.info({ id }, 'Received request to calculate distribution')
try {
await distributorV2Worker.calculateDistribution(id)
} catch (err) {
logger.error(err, 'Error while calculating distribution')
throw err
}

res.json({
distributor: true,
id: id,
})
})

app.use('/distributor', distributorRouter)

export default app
Expand Down
12 changes: 6 additions & 6 deletions apps/distributor/src/distributor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import request from 'supertest'
import app from './app'
import { supabaseAdmin } from './supabase'
import pino from 'pino'
import { DistributorWorker } from './distributor'
import { DistributorV1Worker } from './distributor'
import type { Tables } from '@my/supabase/database.types'

describe('Root Route', () => {
Expand All @@ -20,19 +20,19 @@ describe('Root Route', () => {

describe('Distributor Route', () => {
it('should reject unauthorized requests', async () => {
const res = await request(app).post('/distributor')
const res = await request(app).post('/distributor/v1')

expect(res.statusCode).toBe(401)
expect(res.body).toEqual('Unauthorized')
})

it('should handle authorization correctly', async () => {
const res = await request(app).get('/distributor')
const res = await request(app).get('/distributor/v1')

expect(res.statusCode).toBe(200)
expect(res.body).toMatchObject({
distributor: true,
running: true,
running: false,
})
})

Expand All @@ -58,7 +58,7 @@ describe('Distributor Route', () => {
expect(distribution).toBeDefined()

const res = await request(app)
.post('/distributor')
.post('/distributor/v1')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${process.env.SUPABASE_SERVICE_ROLE}`)
.send({ id: distribution.number })
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('Distributor Worker', () => {
const logger = pino({
level: 'silent',
})
const distributor = new DistributorWorker(logger, false)
const distributor = new DistributorV1Worker(logger, false)
await distributor.calculateDistribution('4')

const expectedShares = [
Expand Down
2 changes: 1 addition & 1 deletion apps/distributor/src/distributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const jsonBigint = (key, value) => {
return value
}

export class DistributorWorker {
export class DistributorV1Worker {
private log: Logger
private running: boolean
private id: string
Expand Down
Loading

0 comments on commit 29e5a2b

Please sign in to comment.