Skip to content

Commit

Permalink
Merge pull request #350 from 0xsend/deploy-main
Browse files Browse the repository at this point in the history
Deploy main
  • Loading branch information
0xBigBoss authored Apr 24, 2024
2 parents 8e17324 + 16a1f9a commit 418665b
Show file tree
Hide file tree
Showing 42 changed files with 1,434 additions and 1,377 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,29 +339,3 @@ jobs:
Vercel Unique URL: [${{ steps.vercel-deploy-preview.outputs.deployment-url }}](${{ steps.vercel-deploy-preview.outputs.deployment-url }})
Vercel Preview URL: [${{ steps.public-hostname.outputs.public-hostname }}](https://${{ steps.public-hostname.outputs.public-hostname }}/)
Last Commit: ${{ github.event.pull_request.head.sha }}
deploy-staging:
if: github.ref == 'refs/heads/dev'
needs: [cache-deps]
uses: ./.github/workflows/deploy-staging.yml
secrets:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
STAGING_SUPABASE_PROJECT_ID: ${{ secrets.STAGING_SUPABASE_PROJECT_ID }}
STAGING_SUPABASE_DB_PASSWORD: ${{ secrets.STAGING_SUPABASE_DB_PASSWORD }}
CI_QA_NOTIFICATION_URL: ${{ secrets.CI_QA_NOTIFICATION_URL }}

deploy-production:
if: github.ref == 'refs/heads/main'
needs: [cache-deps]
uses: ./.github/workflows/deploy-production.yml
secrets:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
PRODUCTION_SUPABASE_PROJECT_ID: ${{ secrets.PRODUCTION_SUPABASE_PROJECT_ID }}
PRODUCTION_SUPABASE_DB_PASSWORD: ${{ secrets.PRODUCTION_SUPABASE_DB_PASSWORD }}
CI_QA_NOTIFICATION_URL: ${{ secrets.CI_QA_NOTIFICATION_URL }}
3 changes: 3 additions & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Deploy Production

on:
push:
branches: [main]
workflow_dispatch:
workflow_call:
secrets:
Expand Down Expand Up @@ -36,6 +38,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
ref: main
- name: Deploy
uses: ./.github/actions/deploy
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Deploy Staging

on:
push:
branches: [dev]
workflow_dispatch:
workflow_call:
secrets:
Expand Down Expand Up @@ -36,6 +38,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
ref: dev
- name: Deploy
uses: ./.github/actions/deploy
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!.yarn/releases
!.yarn/sdks
!.yarn/versions
bun.lockb

# expo
**/.expo/*
Expand Down
38 changes: 35 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ Here is a quick peek at the send stack. Quickly jump to any of the submodules by
</code>
</pre>

<details padding="1rem 0">
<details style="padding: 1rem 0">
<summary style="font-size:20px;font-weight: bold;"><h2 style="display:inline;padding:0 1rem;">Thinking in Send</h2></summary>

Here are some things to keep in mind about thee SEND philosophy when contributing
<ul>

<ul>
<li>
Simplicity over complexity (K.I.S.S)
</li>
Expand Down Expand Up @@ -93,6 +94,37 @@ See [yarn package manager](https://yarnpkg.com/). We are using Yarn 4 with works
corepack enable
```

<details style="padding: 0.5rem 0">
<summary style="font-size:16px;font-weight: bold;"><h4 style="display:inline;padding:0 0.5rem;">Issues</h4></summary>

If you are running a M1, M2 or M3 Mac this may cause some issues.

###### Failing to install `better-sqlite3`

If you get the following error:

`error: libtool: file: Release/obj.target/sqlite3/gen/sqlite3/sqlite3.0 is not an object file (not allowed in a library)`

See the following [issue](https://github.com/TryGhost/node-sqlite3/issues/1538)
for instructions on how to solve it, essentially setting the following values
solves the issue:

```sh
export LDFLAGS="-L/opt/homebrew/opt/sqlite/lib"
export CPPFLAGS="-I/opt/homebrew/opt/sqlite/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/sqlite/lib/pkgconfig"
```

Ensure these are added to `.env.local` in the following way, so they work in tilt:

```
LDFLAGS=-L/opt/homebrew/opt/sqlite/lib
CPPFLAGS=-I/opt/homebrew/opt/sqlite/include
PKG_CONFIG_PATH=/opt/homebrew/opt/sqlite/lib/pkgconfig
```

</details>

#### [Turborepo](https://turbo.build/repo/docs/installing#install-globally)

```console
Expand Down Expand Up @@ -131,7 +163,7 @@ brew bundle
</details>

<details style="padding: 1rem 0">
<summary style="font-size:20px;font-weight:bold;"><h2 style="display:inline;padding:0 1rem;">Your First Build<h2></summary>
<summary style="font-size:20px;font-weight:bold;"><h2 style="display:inline;padding:0 1rem;">Your First Build</h2></summary>

<h3 style="font-size:20px;font-weight:bold;">Build Steps</h3>

Expand Down
6 changes: 3 additions & 3 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,14 @@ local_resource(
docker run --rm \
--name aa-bundler \
--add-host=host.docker.internal:host-gateway \
-p 3030:3030 \
-p 127.0.0.1:3030:3030 \
-v ./keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266:/app/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
-v ./etc/aa-bundler:/app/etc/aa-bundler \
-v ./apps/aabundler/etc:/app/etc/aabundler \
-e "DEBUG={bundler_debug}" \
-e "DEBUG_COLORS=true" \
docker.io/0xbigboss/bundler:0.7.0 \
--port 3030 \
--config /app/etc/aa-bundler/aa-bundler.config.json \
--config /app/etc/aabundler/aabundler.config.json \
--mnemonic /app/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--network http://host.docker.internal:8546 \
--entryPoint 0x0000000071727De22E5E9d8BAf0edAc6f37da032 \
Expand Down
43 changes: 43 additions & 0 deletions apps/aabundler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Account Abstraction Bundler

The account abstraction bundler is responsible for writing user operations onchain via the Entrypoint contract.

## Usage

```shell
docker run --rm \
--name aa-bundler \
--add-host=host.docker.internal:host-gateway \
-p 127.0.0.1:3030:3030 \
-v ./keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266:/app/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
-v ./etc/aabundler:/app/etc/aabundler \
-e "DEBUG=aa.rpc" \
-e "DEBUG_COLORS=true" \
accountabstraction/bundler:0.7.0 \
--port 3030 \
--config /app/etc/aabundler/aabundler.config.json \
--mnemonic /app/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--network http://host.docker.internal:8546 \
--entryPoint 0x0000000071727De22E5E9d8BAf0edAc6f37da032 \
--beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
```

## Configuration

The bundler is configured via a JSON file or command line arguments. Below is an example configuration file.

```json
{
"gasFactor": "1",
"minBalance": "50000000000000",
"maxBundleGas": 5e6,
"minStake": "50000000000000",
"minUnstakeDelay": 86400,
"autoBundleInterval": 2,
"autoBundleMempoolSize": 10,
"mnemonic": "/app/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"network": "http://host.docker.internal:8546",
"entryPoint": "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
"beneficiary": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
}
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gasFactor": "1",
"gasFactor": "1.1",
"minBalance": "1",
"maxBundleGas": 5e6,
"minStake": "1",
Expand Down
2 changes: 1 addition & 1 deletion apps/distributor/src/distributor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe('Distributor Worker', () => {
}))

const logger = pino({
level: 'debug',
level: 'silent',
})
const distributor = new DistributorWorker(logger, false)
await distributor.calculateDistribution('4')
Expand Down
6 changes: 2 additions & 4 deletions apps/next/pages/activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HomeLayout } from 'app/features/home/layout.web'
import Head from 'next/head'
import { userProtectedGetSSP } from 'utils/userProtected'
import type { NextPageWithLayout } from './_app'
import { ButtonOption, TopNav } from 'app/components/TopNav'
import { TopNav } from 'app/components/TopNav'

export const Page: NextPageWithLayout = () => {
return (
Expand All @@ -22,9 +22,7 @@ export const getServerSideProps = userProtectedGetSSP(async () => {
})

Page.getLayout = (children) => (
<HomeLayout TopNav={<TopNav header="Activity" button={ButtonOption.NONE} />}>
{children}
</HomeLayout>
<HomeLayout TopNav={<TopNav header="Activity" />}>{children}</HomeLayout>
)

export default Page
55 changes: 55 additions & 0 deletions docs/testing-send-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Testing the Send Flow

Send app is p2p future cash app. It allows users to send ERC-20 tokens, a kind of cryptocurrency, to each other.

We will be convering how to test the send flow in localnet, a forked version of the [Base](https://base.org/) chain.

## Setup

Let's start by setting up the localnet.

- Reset your database and project
- `tilt down`

- Start your project
- `tilt up`
- Wait until the [NextJS server](http://localhost:10350/r/next%3Aweb/overview) is running.

- Seed your database with some data
- `yarn snaplet:seed` or by clicking the `snaplet seed` button in the Tilt UI.

- Again, ensure there are no errors in the tilt UI. If not, try again.

## Send App

Send app is a [React Native](https://reactnative.dev/) app built using a UI library called [Tamagui](https://tamagui.dev). It is built on top [React Native Web](https://necolas.github.io/react-native-web/) and [Expo](https://docs.expo.dev/) to allow for cross platform development.

For this guide, we will only focus on the React Native part of the app and it's interaction with localnet.

### Sending Tokens

Let's start by sending tokens to another user.

- Open the [Send app](http://localhost:3000/)
- Commplete the onboarding flow
1. Enter your phone number (123456 is fine for localnet.)
2. Enter one-time password (OTP). The code is `123456` for localnet.

At this point, you have created a supabase user, not a Send account. The app should redirect you to onboarding to open your Send account.

3. Create your passkey.

**What's happening:** This opens your Send account which is a smart contract wallet that holds your tokens onchain. It pre-approves a USDC paymaster allowing for transacting onchain without actually holding any ether. Initially, the smart account has only one approved signer, the passkey.

4. Grab some tokens from the secret shop.

**Note:** On testnet, we operate a faucet that gives you tokens for free. On [Base mainnet](https://basescan.org/), you must follow the deposit flow to fund your Send account.
- Visit a profile of another user
1. Open the [Send app](http://localhost:3000/activity)
2. Search for another user
3. Click on their profile
- Click on the `Send` button
- Enter the amount of tokens you want to send
- Click on the `Send` button

At this point, there should have been a transaction on the localnet blockchain. You can inspect it in our local block explorer [Otterscan](http://localhost:5101/) by pasting the transaction hash in the search bar. Or by clicking, `View on Otterscan` in the button.
40 changes: 24 additions & 16 deletions packages/api/src/routers/tag.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { TRPCError } from '@trpc/server'
import {
getPriceInWei,
getSenderSafeReceivedEvents,
} from 'app/features/account/sendtag/checkout/checkout-utils'
import { getPriceInWei } from 'app/features/account/sendtag/checkout/checkout-utils'
import { supabaseAdmin } from 'app/utils/supabase/admin'
import { baseMainnetClient } from '@my/wagmi'
import debug from 'debug'
import { isAddressEqual } from 'viem'
import { z } from 'zod'
import { createTRPCRouter, protectedProcedure } from '../trpc'
import { hexToPgBase16 } from 'app/utils/hexToPgBase16'
import { pgBase16ToHex } from 'app/utils/pgBase16ToHex'

const log = debug('api:routers:tag')

Expand Down Expand Up @@ -110,31 +109,40 @@ export const tagRouter = createTRPCRouter({
})
}

// validate transaction is payment for tags
const eventLogs = await getSenderSafeReceivedEvents({
publicClient: baseMainnetClient,
sender: receipt.from,
}).catch((error) => {
log('get events error', error)
const { data, error } = await supabase
.from('send_revenues_safe_receives')
.select('*')
.eq('tx_hash', hexToPgBase16(txHash as `0x${string}`))
.single()

if (error) {
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: error.message,
})
})

const eventLog = eventLogs.find((e) => e.transactionHash === txHash)
}

if (eventLog === undefined) {
if (data === null) {
log('transaction is not a payment for tags', `txHash=${txHash}`)
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'Transaction is not a payment for tags.',
})
}

const { sender, value } = eventLog.args
const { sender: senderPgB16, v } = data

if (!senderPgB16 || !v) {
log('no sender or v found', `txHash=${txHash}`)
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'No sender or v found. Please try again.',
})
}

const sender = pgBase16ToHex(senderPgB16 as `\\x${string}`)
if (!value || value !== ethAmount) {
if (!v || BigInt(v) !== ethAmount) {
log('transaction is not a payment for tags or incorrect amount', `txHash=${txHash}`)
throw new TRPCError({
code: 'BAD_REQUEST',
Expand Down
Loading

0 comments on commit 418665b

Please sign in to comment.