Skip to content

Commit 8ad8dbf

Browse files
add topaz testnet details; update user schema to support multiple smart accounts (#148)
* add treasure topaz testnet support * add support for multiple user smart accounts * upgrade knip * lowercase wallet addresses * add changesets * Fix for check if launcher is being used * upgrade dependencies * upgrade dependencies * update connect modal styling * rename new user identifier columns --------- Co-authored-by: Wyatt Mufson <[email protected]>
1 parent 07b211f commit 8ad8dbf

File tree

31 files changed

+1939
-1451
lines changed

31 files changed

+1939
-1451
lines changed

.changeset/heavy-eels-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@treasure-dev/tdk-core": minor
3+
---
4+
5+
Updated format of JWT user context payload

.changeset/sweet-apples-exercise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@treasure-dev/tdk-core": minor
3+
---
4+
5+
Added Treasure Topaz testnet details

.changeset/tidy-penguins-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@treasure-dev/auth": patch
3+
---
4+
5+
Added ability to specify context type when generating JWT

apps/api/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ THIRDWEB_CLIENT_ID=
1010
THIRDWEB_ENGINE_URL=
1111
THIRDWEB_ENGINE_ACCESS_TOKEN=
1212
THIRDWEB_SECRET_KEY=
13-
THIRDWEB_ECOSYSTEM_ID=ecosystem.treasure
13+
THIRDWEB_ECOSYSTEM_ID=ecosystem.treasure-dev
1414
THIRDWEB_ECOSYSTEM_PARTNER_ID=
1515
TREASURE_AUTH_KMS_KEY=
1616
TROVE_API_URL=https://trove-api-dev.treasure.lol
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- DropIndex
2+
DROP INDEX "public"."user_address_key";
3+
4+
-- DropIndex
5+
DROP INDEX "public"."user_email_key";
6+
7+
-- AlterTable
8+
ALTER TABLE "public"."user" DROP COLUMN "address",
9+
DROP COLUMN "email",
10+
ADD COLUMN "external_user_id" TEXT,
11+
ADD COLUMN "external_wallet_address" VARCHAR(42);
12+
13+
-- AlterTable
14+
ALTER TABLE "public"."user_profile" ADD COLUMN "email" TEXT;
15+
16+
-- CreateTable
17+
CREATE TABLE "public"."user_smart_account" (
18+
"id" TEXT NOT NULL,
19+
"chain_id" INTEGER NOT NULL,
20+
"address" VARCHAR(42) NOT NULL,
21+
"initial_email" TEXT,
22+
"initial_wallet_address" VARCHAR(42) NOT NULL,
23+
"user_id" TEXT NOT NULL,
24+
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
25+
"updated_at" TIMESTAMP(3) NOT NULL,
26+
27+
CONSTRAINT "user_smart_account_pkey" PRIMARY KEY ("id")
28+
);
29+
30+
-- CreateIndex
31+
CREATE INDEX "user_smart_account_user_id_idx" ON "public"."user_smart_account"("user_id");
32+
33+
-- CreateIndex
34+
CREATE UNIQUE INDEX "user_smart_account_chain_id_address_key" ON "public"."user_smart_account"("chain_id", "address");
35+
36+
-- CreateIndex
37+
CREATE UNIQUE INDEX "user_external_user_id_key" ON "public"."user"("external_user_id");
38+
39+
-- CreateIndex
40+
CREATE UNIQUE INDEX "user_external_wallet_address_key" ON "public"."user"("external_wallet_address");
41+
42+
-- CreateIndex
43+
CREATE UNIQUE INDEX "user_profile_email_key" ON "public"."user_profile"("email");
44+
45+
-- AddForeignKey
46+
ALTER TABLE "public"."user_smart_account" ADD CONSTRAINT "user_smart_account_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

apps/api/prisma/schema.prisma

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,20 @@ model User {
8282
id String @id @default(cuid())
8383
8484
// Fields
85-
address String @unique @map("address") @db.VarChar(42)
86-
email String? @unique
87-
banned Boolean @default(false)
88-
comment String?
85+
// Identifiers
86+
externalUserId String? @unique @map("external_user_id")
87+
externalWalletAddress String? @unique @map("external_wallet_address") @db.VarChar(42)
88+
89+
// Status
8990
lastLoginAt DateTime? @map("last_login_at")
9091
92+
// Notes
93+
banned Boolean @default(false)
94+
comment String?
95+
9196
// Relations
9297
profile UserProfile?
98+
smartAccounts UserSmartAccount[]
9399
socialAccounts UserSocialAccount[]
94100
notificationSettings UserNotificationSettings[]
95101
@@ -101,11 +107,38 @@ model User {
101107
@@schema("public")
102108
}
103109

110+
model UserSmartAccount {
111+
// Primary key
112+
id String @id @default(cuid())
113+
114+
// Fields
115+
chainId Int @map("chain_id")
116+
address String @db.VarChar(42)
117+
initialEmail String? @map("initial_email") // Email address used to create the smart account, if applicable
118+
initialWalletAddress String @map("initial_wallet_address") @db.VarChar(42) // Wallet address used to create the smart account (either EOA or ecosystem wallet)
119+
120+
// Relations
121+
userId String @map("user_id")
122+
user User @relation(fields: [userId], references: [id])
123+
124+
// Computed
125+
createdAt DateTime @default(now()) @map("created_at")
126+
updatedAt DateTime @updatedAt @map("updated_at")
127+
128+
@@unique([chainId, address])
129+
@@index([userId])
130+
@@map("user_smart_account")
131+
@@schema("public")
132+
}
133+
104134
model UserProfile {
105135
// Primary key
106136
id String @id @default(cuid())
107137
108138
// Fields
139+
// Contact
140+
email String? @unique
141+
109142
// TreasureTag
110143
tag String?
111144
discriminant Int? @db.SmallInt
@@ -135,7 +168,7 @@ model UserProfile {
135168
legacyEmail String? @map("legacy_email")
136169
legacyEmailVerifiedAt DateTime? @map("legacy_email_verified_at")
137170
138-
// Other
171+
// Status
139172
testnetFaucetLastUsedAt DateTime? @map("testnet_faucet_last_used_at")
140173
141174
// Relations

apps/api/src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { PrismaClient } from "@prisma/client";
44
import * as Sentry from "@sentry/node";
55
import { Engine } from "@thirdweb-dev/engine";
66
import { createAuth } from "@treasure-dev/auth";
7-
import { TREASURE_RUBY_CHAIN_DEFINITION } from "@treasure-dev/tdk-core";
7+
import {
8+
TREASURE_RUBY_CHAIN_DEFINITION,
9+
TREASURE_TOPAZ_CHAIN_DEFINITION,
10+
} from "@treasure-dev/tdk-core";
811
import { http, createConfig, fallback } from "@wagmi/core";
912
import {
1013
arbitrum,
@@ -74,6 +77,7 @@ const main = async () => {
7477
mainnet,
7578
sepolia,
7679
defineChain(TREASURE_RUBY_CHAIN_DEFINITION),
80+
defineChain(TREASURE_TOPAZ_CHAIN_DEFINITION),
7781
],
7882
transports: {
7983
[arbitrum.id]: fallback([
@@ -106,6 +110,12 @@ const main = async () => {
106110
),
107111
http(),
108112
]),
113+
[TREASURE_TOPAZ_CHAIN_DEFINITION.id]: fallback([
114+
http(
115+
`https://${TREASURE_TOPAZ_CHAIN_DEFINITION.id}.rpc.thirdweb.com/${env.THIRDWEB_CLIENT_ID}`,
116+
),
117+
http(),
118+
]),
109119
},
110120
}),
111121
};

0 commit comments

Comments
 (0)