Skip to content

Commit 0da7dfa

Browse files
committed
refactor: Rename contractAddress to tokenAddress in Balance Subscriptions
- Update Prisma schema, migration, and database indexes - Modify TypeScript interfaces and schemas across services and routes - Ensure consistent naming for token-related address fields - Update worker and database interaction methods
1 parent fa79d26 commit 0da7dfa

File tree

10 files changed

+32
-31
lines changed

10 files changed

+32
-31
lines changed

sdk/src/services/BalanceSubscriptionsService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class BalanceSubscriptionsService {
2525
/**
2626
* A contract or wallet address
2727
*/
28-
contractAddress?: string;
28+
tokenAddress?: string;
2929
/**
3030
* A contract or wallet address
3131
*/
@@ -76,7 +76,7 @@ export class BalanceSubscriptionsService {
7676
/**
7777
* A contract or wallet address
7878
*/
79-
contractAddress?: string;
79+
tokenAddress?: string;
8080
/**
8181
* A contract or wallet address
8282
*/
@@ -118,7 +118,7 @@ export class BalanceSubscriptionsService {
118118
/**
119119
* A contract or wallet address
120120
*/
121-
contractAddress?: string;
121+
tokenAddress?: string;
122122
/**
123123
* A contract or wallet address
124124
*/
@@ -172,7 +172,7 @@ export class BalanceSubscriptionsService {
172172
* A chain ID ("137") or slug ("polygon-amoy-testnet"). Chain ID is preferred.
173173
*/
174174
chain?: string;
175-
contractAddress?: (string | null);
175+
tokenAddress?: (string | null);
176176
/**
177177
* A contract or wallet address
178178
*/
@@ -201,7 +201,7 @@ export class BalanceSubscriptionsService {
201201
/**
202202
* A contract or wallet address
203203
*/
204-
contractAddress?: string;
204+
tokenAddress?: string;
205205
/**
206206
* A contract or wallet address
207207
*/

src/prisma/migrations/20250210081712_balance_subscriptions/migration.sql renamed to src/prisma/migrations/20250210192030_balance_subscriptions/migration.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ALTER TABLE "configuration" ADD COLUMN "balanceSubscriptionsCronSchedule" TE
55
CREATE TABLE "balance_subscriptions" (
66
"id" TEXT NOT NULL,
77
"chainId" TEXT NOT NULL,
8-
"contractAddress" TEXT,
8+
"tokenAddress" TEXT,
99
"walletAddress" TEXT NOT NULL,
1010
"config" JSONB NOT NULL,
1111
"webhookId" INTEGER,
@@ -20,7 +20,7 @@ CREATE TABLE "balance_subscriptions" (
2020
CREATE INDEX "balance_subscriptions_chainId_idx" ON "balance_subscriptions"("chainId");
2121

2222
-- CreateIndex
23-
CREATE INDEX "balance_subscriptions_contractAddress_idx" ON "balance_subscriptions"("contractAddress");
23+
CREATE INDEX "balance_subscriptions_tokenAddress_idx" ON "balance_subscriptions"("tokenAddress");
2424

2525
-- CreateIndex
2626
CREATE INDEX "balance_subscriptions_walletAddress_idx" ON "balance_subscriptions"("walletAddress");

src/prisma/schema.prisma

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ model ContractEventLogs {
290290
}
291291

292292
model BalanceSubscriptions {
293-
id String @id @default(uuid())
294-
chainId String
295-
contractAddress String? /// optional for ERC20 balances, if null then native balance
296-
walletAddress String
293+
id String @id @default(uuid())
294+
chainId String
295+
tokenAddress String? /// optional for ERC20 balances, if null then native balance
296+
walletAddress String
297297
298298
config Json
299299
@@ -305,7 +305,7 @@ model BalanceSubscriptions {
305305
deletedAt DateTime?
306306
307307
@@index([chainId])
308-
@@index([contractAddress])
308+
@@index([tokenAddress])
309309
@@index([walletAddress])
310310
@@map("balance_subscriptions")
311311
}

src/server/routes/balance-subscriptions/add.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const webhookIdSchema = Type.Object({
3737
const requestBodySchema = Type.Intersect([
3838
Type.Object({
3939
chain: chainIdOrSlugSchema,
40-
contractAddress: Type.Optional(AddressSchema),
40+
tokenAddress: Type.Optional(AddressSchema),
4141
walletAddress: AddressSchema,
4242
config: balanceSubscriptionConfigSchema,
4343
}),
@@ -67,7 +67,7 @@ export async function addBalanceSubscriptionRoute(fastify: FastifyInstance) {
6767
},
6868
},
6969
handler: async (request, reply) => {
70-
const { chain, contractAddress, walletAddress, config } = request.body;
70+
const { chain, tokenAddress, walletAddress, config } = request.body;
7171
const chainId = await getChainIdFromChain(chain);
7272

7373
let finalWebhookId: number | undefined;
@@ -121,7 +121,7 @@ export async function addBalanceSubscriptionRoute(fastify: FastifyInstance) {
121121
// Create the balance subscription
122122
const balanceSubscription = await createBalanceSubscription({
123123
chainId: chainId.toString(),
124-
contractAddress: contractAddress?.toLowerCase(),
124+
tokenAddress: tokenAddress?.toLowerCase(),
125125
walletAddress: walletAddress.toLowerCase(),
126126
config,
127127
webhookId: finalWebhookId,

src/server/routes/balance-subscriptions/update.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const requestBodySchema = Type.Object({
1717
description: "The ID of the balance subscription to update.",
1818
}),
1919
chain: Type.Optional(chainIdOrSlugSchema),
20-
contractAddress: Type.Optional(Type.Union([AddressSchema, Type.Null()])),
20+
tokenAddress: Type.Optional(Type.Union([AddressSchema, Type.Null()])),
2121
walletAddress: Type.Optional(AddressSchema),
2222
config: Type.Optional(balanceSubscriptionConfigSchema),
2323
webhookId: Type.Optional(
@@ -56,7 +56,7 @@ export async function updateBalanceSubscriptionRoute(fastify: FastifyInstance) {
5656
const {
5757
balanceSubscriptionId,
5858
chain,
59-
contractAddress,
59+
tokenAddress,
6060
walletAddress,
6161
config,
6262
webhookId,
@@ -69,7 +69,7 @@ export async function updateBalanceSubscriptionRoute(fastify: FastifyInstance) {
6969
const balanceSubscription = await updateBalanceSubscription({
7070
id: balanceSubscriptionId,
7171
chainId: chainId?.toString(),
72-
contractAddress,
72+
tokenAddress,
7373
walletAddress,
7474
config,
7575
webhookId,

src/server/schemas/balance-subscription.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ import { balanceSubscriptionConfigSchema, balanceSubscriptionConfigZodSchema } f
77
interface BalanceSubscriptionWithWebhook {
88
id: string;
99
chainId: string;
10-
contractAddress: string | null;
10+
tokenAddress: string | null;
1111
walletAddress: string;
1212
config: Prisma.JsonValue;
1313
webhookId: number | null;
1414
webhook: Webhooks | null;
1515
createdAt: Date;
1616
updatedAt: Date;
17+
deletedAt: Date | null;
1718
}
1819

1920
export const balanceSubscriptionSchema = Type.Object({
2021
id: Type.String(),
2122
chain: chainIdOrSlugSchema,
22-
contractAddress: Type.Optional(AddressSchema),
23+
tokenAddress: Type.Optional(AddressSchema),
2324
walletAddress: AddressSchema,
2425
config: balanceSubscriptionConfigSchema,
2526
webhook: Type.Optional(
@@ -37,7 +38,7 @@ export function toBalanceSubscriptionSchema(subscription: BalanceSubscriptionWit
3738
return {
3839
id: subscription.id,
3940
chain: subscription.chainId,
40-
contractAddress: subscription.contractAddress ?? undefined,
41+
tokenAddress: subscription.tokenAddress ?? undefined,
4142
walletAddress: subscription.walletAddress,
4243
config: balanceSubscriptionConfigZodSchema.parse(subscription.config),
4344
webhook: subscription.webhookId && subscription.webhook

src/shared/db/balance-subscriptions/create-balance-subscription.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import type { BalanceSubscriptionConfig } from "../../schemas/balance-subscripti
44

55
interface CreateBalanceSubscriptionParams {
66
chainId: string;
7-
contractAddress?: string;
7+
tokenAddress?: string;
88
walletAddress: string;
99
config: BalanceSubscriptionConfig;
1010
webhookId?: number;
1111
}
1212

1313
export async function createBalanceSubscription({
1414
chainId,
15-
contractAddress,
15+
tokenAddress,
1616
walletAddress,
1717
config,
1818
webhookId,
@@ -21,7 +21,7 @@ export async function createBalanceSubscription({
2121
const existingSubscription = await prisma.balanceSubscriptions.findFirst({
2222
where: {
2323
chainId,
24-
contractAddress,
24+
tokenAddress,
2525
walletAddress,
2626
deletedAt: null,
2727
},
@@ -47,7 +47,7 @@ export async function createBalanceSubscription({
4747
return await prisma.balanceSubscriptions.create({
4848
data: {
4949
chainId,
50-
contractAddress,
50+
tokenAddress,
5151
walletAddress,
5252
config: config as Prisma.InputJsonValue,
5353
webhookId,

src/shared/db/balance-subscriptions/update-balance-subscription.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { BalanceSubscriptionConfig } from "../../schemas/balance-subscripti
55
interface UpdateBalanceSubscriptionParams {
66
id: string;
77
chainId?: string;
8-
contractAddress?: string | null;
8+
tokenAddress?: string | null;
99
walletAddress?: string;
1010
config?: BalanceSubscriptionConfig;
1111
webhookId?: number | null;
@@ -14,7 +14,7 @@ interface UpdateBalanceSubscriptionParams {
1414
export async function updateBalanceSubscription({
1515
id,
1616
chainId,
17-
contractAddress,
17+
tokenAddress,
1818
walletAddress,
1919
config,
2020
webhookId,
@@ -26,7 +26,7 @@ export async function updateBalanceSubscription({
2626
},
2727
data: {
2828
...(chainId && { chainId }),
29-
...(contractAddress !== undefined && { contractAddress }),
29+
...(tokenAddress !== undefined && { tokenAddress }),
3030
...(walletAddress && { walletAddress: walletAddress.toLowerCase() }),
3131
...(config && { config: config as Prisma.InputJsonValue }),
3232
...(webhookId !== undefined && { webhookId }),

src/shared/schemas/webhooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type BackendWalletBalanceWebhookParams = {
2525
export interface BalanceSubscriptionWebhookParams {
2626
subscriptionId: string;
2727
chainId: string;
28-
contractAddress: string | null;
28+
tokenAddress: string | null;
2929
walletAddress: string;
3030
balance: string;
3131
config: z.infer<typeof balanceSubscriptionConfigZodSchema>;

src/worker/tasks/balance-subscription-worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const handler: Processor<string, void, string> = async (job: Job<string>) => {
7070
const currentBalanceResponse = await getWalletBalance({
7171
address: subscription.walletAddress,
7272
client: thirdwebClient,
73-
tokenAddress: subscription.contractAddress ?? undefined, // get ERC20 balance if contract address is provided
73+
tokenAddress: subscription.tokenAddress ?? undefined, // get ERC20 balance if token address is provided
7474
chain,
7575
});
7676

@@ -92,7 +92,7 @@ const handler: Processor<string, void, string> = async (job: Job<string>) => {
9292
const webhookBody: BalanceSubscriptionWebhookParams = {
9393
subscriptionId: subscription.id,
9494
chainId: subscription.chainId,
95-
contractAddress: subscription.contractAddress,
95+
tokenAddress: subscription.tokenAddress,
9696
walletAddress: subscription.walletAddress,
9797
balance: currentBalance.toString(),
9898
config: parseBalanceSubscriptionConfig(subscription.config),

0 commit comments

Comments
 (0)