Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Jul 15, 2024
1 parent 0782472 commit 1adf1ac
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
34 changes: 34 additions & 0 deletions trade.renegade.fi/app/api/get-logs/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { chain } from "@/lib/viem"
import { NextRequest } from "next/server"
import { createPublicClient, http, parseAbiItem } from "viem"

// Necessary because public RPC does not support getting logs
export const viemClient = createPublicClient({
chain,
transport: http(process.env.NEXT_PUBLIC_RPC_URL),
})

export async function GET(req: NextRequest) {
try {
const blinderShare = BigInt(
req.nextUrl.searchParams.get("blinderShare") || "0"
)
if (!blinderShare) {
throw new Error("Blinder share is required")
}
const logs = await viemClient.getLogs({
address: process.env.NEXT_PUBLIC_DARKPOOL_CONTRACT,
event: parseAbiItem(
"event WalletUpdated(uint256 indexed wallet_blinder_share)"
),
args: {
wallet_blinder_share: BigInt(blinderShare?.toString() || "0"),
},
fromBlock: BigInt(process.env.FROM_BLOCK || 0),
})
return new Response(JSON.stringify({ logs: logs.length }))
} catch (error) {
console.error(error)
return new Response(JSON.stringify({ error }), { status: 500 })
}
}
4 changes: 2 additions & 2 deletions trade.renegade.fi/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import LazyDatadog from "@/app/(desktop)/telemetry"
import { OrderToaster } from "@/app/order-toaster"
import { TaskToaster } from "@/app/task-toaster"
import { AppProvider } from "@/contexts/App/app-context"
import { chain, sdkViemClient } from "@/lib/viem"
import { chain, viemClient } from "@/lib/viem"
import { menuAnatomy } from "@chakra-ui/anatomy"
import { CacheProvider } from "@chakra-ui/next-js"
import {
Expand Down Expand Up @@ -204,7 +204,7 @@ export const renegadeConfig = createSDKConfig({
priceReporterUrl: process.env.NEXT_PUBLIC_PRICE_REPORTER_URL,
relayerUrl: process.env.NEXT_PUBLIC_RENEGADE_RELAYER_HOSTNAME,
ssr: true,
viemClient: sdkViemClient,
viemClient,
})

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
Text,
} from "@chakra-ui/react"
import { useConfig } from "@renegade-fi/react"
import { connect } from "@renegade-fi/react/actions"
import { connect, getSkRoot } from "@renegade-fi/react/actions"
import { CircleHelp, Unplug } from "lucide-react"
import { toast } from "sonner"
import { useLocalStorage } from "usehooks-ts"
Expand Down Expand Up @@ -66,7 +66,17 @@ export function DefaultStep() {
throw new Error("Invalid signature")
}
config.setState((x) => ({ ...x, seed: data }))
const res = await connect(config)
const skRoot = getSkRoot(config)
const blinderShare = config.utils.derive_blinder_share(skRoot)

// Check if WalletUpdated events exist onchain
const logs = await fetch(`/api/get-logs?blinderShare=${blinderShare}`)
.then((res) => res.json())
.then((data) => data.logs)

const res = await connect(config, {
isCreateWallet: logs === 0,
})
if (res?.job) {
const { isLookup, job } = res
toast.promise(job, {
Expand Down
6 changes: 0 additions & 6 deletions trade.renegade.fi/lib/viem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,3 @@ export const viemClient = createPublicClient({
chain,
transport: http(),
})

// Necessary because public RPC does not support getting logs
export const sdkViemClient = createPublicClient({
chain,
transport: http(process.env.NEXT_PUBLIC_RPC_URL),
})

0 comments on commit 1adf1ac

Please sign in to comment.