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

v3 [DO NOT MERGE] #855

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
THIRDWEB_API_SECRET_KEY="test"
POSTGRES_CONNECTION_URL="postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable"
POSTGRES_CONNECTION_URL="postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable&timezone=utc"
ADMIN_WALLET_ADDRESS="test"
ENCRYPTION_PASSWORD="test"
ENABLE_KEYPAIR_AUTH="true"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated SDK
sdk/replacement_log.txt

.cursor

# Logs
logs
*.log
Expand Down
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

1 change: 0 additions & 1 deletion .yarnrc

This file was deleted.

76 changes: 18 additions & 58 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,71 +1,31 @@
FROM node:18.20-slim AS base

WORKDIR /app

# Upgrade packages
RUN apt-get -y update && \
apt-get -y upgrade && \
apt-get -y install libssl-dev

##############################
##############################
##############################
##############################
FROM oven/bun:1 AS base
WORKDIR /usr/src/app

# Generate cert for local https
FROM base AS certs

WORKDIR /app/src/https

RUN apt-get -y install openssl

WORKDIR /usr/src/app/src/https
RUN apt-get update && apt-get install -y openssl
RUN openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 \
-subj "/C=US/ST=State/L=City/O=Organization/OU=Unit/CN=localhost" \
-passout pass:thirdweb-engine && \
chmod 600 key.pem cert.pem

##############################
##############################
##############################
##############################

FROM base AS build

# Install Python3-Pip
RUN apt-get -y install python3-pip

# Copy the entire project directory
COPY . .

# Install dependencies for both development and production (May need devDependencies to build)
# Build the project
# Prune dev dependencies from the packages
RUN yarn install --frozen-lockfile --production=false --network-timeout 1000000 && \
yarn build && \
yarn copy-files && \
yarn install --frozen-lockfile --production=true --network-timeout 1000000

##############################
##############################
##############################
##############################

FROM base AS prod

EXPOSE 3005
# Install dependencies
FROM base AS install
RUN mkdir -p /temp/prod
COPY package.json bun.lock /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# Final image
FROM base AS release
ARG ENGINE_VERSION
ENV ENGINE_VERSION=${ENGINE_VERSION}
ENV NODE_ENV="production" \
PATH=/app/node_modules/.bin:$PATH

COPY --from=certs /app/src/https ./dist/https
COPY --from=build /app/package.json .
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/src/prisma/* ./src/prisma/
COPY --from=build /app/dist ./dist
ENV NODE_ENV="production"

# Replace the schema path in the package.json file
RUN sed -i 's_"schema": "./src/prisma/schema.prisma"_"schema": "./dist/prisma/schema.prisma"_g' package.json
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=certs /usr/src/app/src/https ./src/https
COPY . .

ENTRYPOINT [ "yarn", "start"]
USER bun
EXPOSE 3005
ENTRYPOINT [ "bun", "run", "src/index.ts" ]
2,118 changes: 2,118 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from "drizzle-kit";

const databaseUrl = process.env.POSTGRES_CONNECTION_URL;

if (!databaseUrl) {
throw new Error("DATABASE_URL environment variable is not set");
}

export default defineConfig({
out: "./drizzle",
schema: "./src/db/schema.ts",
dialect: "postgresql",
dbCredentials: {
url: databaseUrl,
},
});
142 changes: 142 additions & 0 deletions drizzle/0000_broad_blacklash.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
CREATE TABLE "address_subscriptions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"chainId" text NOT NULL,
"address" text NOT NULL,
"conditions" jsonb[],
"webhookId" uuid,
"createdAt" timestamp with time zone DEFAULT now() NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "configuration" (
"id" text PRIMARY KEY DEFAULT 'default' NOT NULL,
"chainOverrides" json DEFAULT '[]'::json NOT NULL,
"webhookAuthBearerToken" text,
"authDomain" text DEFAULT 'thirdweb.com' NOT NULL,
"authEoaEncryptedJson" text NOT NULL,
"accessControlAllowOrigin" json DEFAULT '["https://thirdweb.com","https://embed.ipfscdn.io"]'::json NOT NULL,
"ipAllowlist" json[],
"mtlsCertificateEncrypted" text,
"mtlsPrivateKeyEncrypted" text,
"walletProviderConfigs" json DEFAULT '{}'::json NOT NULL
);
--> statement-breakpoint
CREATE TABLE "eoa_credentials" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"type" text NOT NULL,
"label" text NOT NULL,
"data" json NOT NULL,
"isDefault" boolean DEFAULT false NOT NULL,
"createdAt" timestamp with time zone DEFAULT now() NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "eoas" (
"address" text PRIMARY KEY NOT NULL,
"type" text NOT NULL,
"encryptedJson" text,
"label" text NOT NULL,
"credentialId" uuid,
"platformIdentifiers" jsonb,
"createdAt" timestamp with time zone DEFAULT now() NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "keypairs" (
"hash" text PRIMARY KEY NOT NULL,
"publicKey" text NOT NULL,
"algorithm" text NOT NULL,
"label" text,
"createdAt" timestamp with time zone DEFAULT now() NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "permissions" (
"accountAddress" text PRIMARY KEY NOT NULL,
"permissions" text NOT NULL,
"label" text
);
--> statement-breakpoint
CREATE TABLE "relayers" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"label" text,
"chainId" text NOT NULL,
"accountAddress" text NOT NULL,
"allowedContracts" jsonb DEFAULT '[]'::jsonb,
"allowedForwarders" jsonb DEFAULT '[]'::jsonb
);
--> statement-breakpoint
CREATE TABLE "smart_accounts" (
"address" text NOT NULL,
"signerAddress" text NOT NULL,
"label" text NOT NULL,
"factoryAddress" text NOT NULL,
"entrypointAddress" text NOT NULL,
"accountSalt" text,
"createdAt" timestamp with time zone DEFAULT now() NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone,
CONSTRAINT "smart_accounts_address_signerAddress_pk" PRIMARY KEY("address","signerAddress")
);
--> statement-breakpoint
CREATE TABLE "tokens" (
"id" text PRIMARY KEY NOT NULL,
"tokenMask" text NOT NULL,
"accountAddress" text NOT NULL,
"isAccessToken" boolean NOT NULL,
"label" text,
"createdAt" timestamp with time zone DEFAULT now() NOT NULL,
"expiresAt" timestamp with time zone NOT NULL,
"revokedAt" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "transactions" (
"id" text NOT NULL,
"batchIndex" integer NOT NULL,
"chainId" text NOT NULL,
"from" text,
"transactionParams" jsonb NOT NULL,
"transactionHash" text,
"confirmedAt" timestamp with time zone,
"confirmedAtBlockNumber" text,
"enrichedData" jsonb DEFAULT '[]'::jsonb NOT NULL,
"executionParams" jsonb NOT NULL,
"executionResult" jsonb,
"createdAt" timestamp with time zone DEFAULT now() NOT NULL,
"errorMessage" text,
"cancelledAt" timestamp with time zone,
CONSTRAINT "transactions_id_batchIndex_pk" PRIMARY KEY("id","batchIndex")
);
--> statement-breakpoint
CREATE TABLE "webhooks" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"label" text,
"url" text NOT NULL,
"secret" text NOT NULL,
"eventType" text NOT NULL,
"createdAt" timestamp with time zone DEFAULT now() NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"revokedAt" timestamp with time zone
);
--> statement-breakpoint
ALTER TABLE "address_subscriptions" ADD CONSTRAINT "address_subscriptions_webhookId_webhooks_id_fk" FOREIGN KEY ("webhookId") REFERENCES "public"."webhooks"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "eoas" ADD CONSTRAINT "eoas_credentialId_eoa_credentials_id_fk" FOREIGN KEY ("credentialId") REFERENCES "public"."eoa_credentials"("id") ON DELETE set null ON UPDATE cascade;--> statement-breakpoint
ALTER TABLE "smart_accounts" ADD CONSTRAINT "smart_accounts_signerAddress_eoas_address_fk" FOREIGN KEY ("signerAddress") REFERENCES "public"."eoas"("address") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "address_subscriptions_deleted_at_not_null_idx" ON "address_subscriptions" USING btree ("deletedAt") WHERE "address_subscriptions"."deletedAt" IS NOT NULL;--> statement-breakpoint
CREATE INDEX "address_subscriptions_webhook_id_idx" ON "address_subscriptions" USING btree ("webhookId");--> statement-breakpoint
CREATE INDEX "address_subscriptions_chainId_idx" ON "address_subscriptions" USING btree ("chainId");--> statement-breakpoint
CREATE INDEX "address_subscriptions_address_idx" ON "address_subscriptions" USING btree ("address");--> statement-breakpoint
CREATE INDEX "eoa_credentials_type_idx" ON "eoa_credentials" USING btree ("type");--> statement-breakpoint
CREATE UNIQUE INDEX "eoa_credentials_type_is_default_key" ON "eoa_credentials" USING btree ("type") WHERE "eoa_credentials"."isDefault" IS TRUE;--> statement-breakpoint
CREATE INDEX "eoa_credentials_deleted_at_not_null_idx" ON "eoa_credentials" USING btree ("deletedAt") WHERE "eoa_credentials"."deletedAt" IS NOT NULL;--> statement-breakpoint
CREATE INDEX "eoas_deleted_at_not_null_idx" ON "eoas" USING btree ("deletedAt") WHERE "eoas"."deletedAt" IS NOT NULL;--> statement-breakpoint
CREATE INDEX "smart_accounts_signer_address_idx" ON "smart_accounts" USING btree ("signerAddress");--> statement-breakpoint
CREATE INDEX "smart_accounts_deleted_at_not_null_idx" ON "smart_accounts" USING btree ("deletedAt") WHERE "smart_accounts"."deletedAt" IS NOT NULL;--> statement-breakpoint
CREATE INDEX "transaction_hash_idx" ON "transactions" USING btree ("transactionHash");--> statement-breakpoint
CREATE INDEX "from_idx" ON "transactions" USING btree ("from");--> statement-breakpoint
CREATE INDEX "execution_params_idx" ON "transactions" USING gin ("executionParams");--> statement-breakpoint
CREATE INDEX "execution_result_idx" ON "transactions" USING gin ("executionResult");
Loading