@@ -4,22 +4,20 @@ import { PrismaClient } from "@prisma/client";
44import * as Sentry from "@sentry/node" ;
55import { Engine } from "@thirdweb-dev/engine" ;
66import { createAuth } from "@treasure-dev/auth" ;
7+ import { http , type Transport , createConfig , fallback } from "@wagmi/core" ;
78import {
8- TREASURE_CHAIN_DEFINITION ,
9- TREASURE_TOPAZ_CHAIN_DEFINITION ,
10- } from "@treasure-dev/tdk-core" ;
11- import { http , createConfig , fallback } from "@wagmi/core" ;
12- import {
9+ abstract ,
1310 arbitrum ,
1411 arbitrumSepolia ,
1512 base ,
1613 baseSepolia ,
1714 mainnet ,
1815 sepolia ,
16+ treasure ,
17+ treasureTopaz ,
1918} from "@wagmi/core/chains" ;
2019import { createThirdwebClient , getUser } from "thirdweb" ;
2120import { createAuth as createThirdwebAuth } from "thirdweb/auth" ;
22- import { defineChain } from "viem" ;
2321
2422import { withAuth } from "./middleware/auth" ;
2523import { withChain } from "./middleware/chain" ;
@@ -35,6 +33,18 @@ import type { TdkApiContext } from "./types";
3533import { app } from "./utils/app" ;
3634import { getEnv } from "./utils/env" ;
3735
36+ const WAGMI_CONFIG_CHAINS = [
37+ abstract ,
38+ arbitrum ,
39+ arbitrumSepolia ,
40+ base ,
41+ baseSepolia ,
42+ mainnet ,
43+ sepolia ,
44+ treasure ,
45+ treasureTopaz ,
46+ ] as const ;
47+
3848const main = async ( ) => {
3949 const env = await getEnv ( ) ;
4050 const client = createThirdwebClient ( { secretKey : env . THIRDWEB_SECRET_KEY } ) ;
@@ -62,64 +72,20 @@ const main = async () => {
6272 accessToken : env . THIRDWEB_ENGINE_ACCESS_TOKEN ,
6373 } ) ,
6474 wagmiConfig : createConfig ( {
65- chains : [
66- arbitrum ,
67- arbitrumSepolia ,
68- mainnet ,
69- sepolia ,
70- base ,
71- baseSepolia ,
72- defineChain ( TREASURE_CHAIN_DEFINITION ) ,
73- defineChain ( TREASURE_TOPAZ_CHAIN_DEFINITION ) ,
74- ] ,
75- transports : {
76- [ arbitrum . id ] : fallback ( [
77- http (
78- `https://${ arbitrum . id } .rpc.thirdweb.com/${ env . THIRDWEB_CLIENT_ID } ` ,
79- ) ,
80- http ( ) ,
81- ] ) ,
82- [ arbitrumSepolia . id ] : fallback ( [
83- http (
84- `https://${ arbitrumSepolia . id } .rpc.thirdweb.com/${ env . THIRDWEB_CLIENT_ID } ` ,
85- ) ,
86- http ( ) ,
87- ] ) ,
88- [ mainnet . id ] : fallback ( [
89- http (
90- `https://${ mainnet . id } .rpc.thirdweb.com/${ env . THIRDWEB_CLIENT_ID } ` ,
91- ) ,
92- http ( ) ,
93- ] ) ,
94- [ sepolia . id ] : fallback ( [
95- http (
96- `https://${ sepolia . id } .rpc.thirdweb.com/${ env . THIRDWEB_CLIENT_ID } ` ,
97- ) ,
98- http ( ) ,
99- ] ) ,
100- [ base . id ] : fallback ( [
101- http ( `https://${ base . id } .rpc.thirdweb.com/${ env . THIRDWEB_CLIENT_ID } ` ) ,
102- http ( ) ,
103- ] ) ,
104- [ baseSepolia . id ] : fallback ( [
105- http (
106- `https://${ baseSepolia . id } .rpc.thirdweb.com/${ env . THIRDWEB_CLIENT_ID } ` ,
107- ) ,
108- http ( ) ,
109- ] ) ,
110- [ TREASURE_CHAIN_DEFINITION . id ] : fallback ( [
111- http (
112- `https://${ TREASURE_CHAIN_DEFINITION . id } .rpc.thirdweb.com/${ env . THIRDWEB_CLIENT_ID } ` ,
113- ) ,
114- http ( ) ,
115- ] ) ,
116- [ TREASURE_TOPAZ_CHAIN_DEFINITION . id ] : fallback ( [
117- http (
118- `https://${ TREASURE_TOPAZ_CHAIN_DEFINITION . id } .rpc.thirdweb.com/${ env . THIRDWEB_CLIENT_ID } ` ,
119- ) ,
120- http ( ) ,
121- ] ) ,
122- } ,
75+ chains : WAGMI_CONFIG_CHAINS ,
76+ transports : WAGMI_CONFIG_CHAINS . reduce (
77+ ( acc , chain ) => {
78+ acc [ chain . id ] = fallback ( [
79+ http (
80+ `https://${ chain . id } .rpc.thirdweb.com/${ env . THIRDWEB_CLIENT_ID } ` ,
81+ { batch : true } ,
82+ ) ,
83+ http ( undefined , { batch : true } ) ,
84+ ] ) ;
85+ return acc ;
86+ } ,
87+ { } as Record < keyof typeof WAGMI_CONFIG_CHAINS , Transport > ,
88+ ) ,
12389 } ) ,
12490 getThirdwebUser : async ( { ecosystemWalletAddress } ) =>
12591 getUser ( {
0 commit comments