Skip to content

Commit 375c5b3

Browse files
feat: chain abstraction multibridge (#699)
* chore: add missing eip155 testnet chains * chore: remove unused chain * Show USDC balance in wallet * chore: add loading indicator * chore: add multibridge dapp with checks wallet side * chore: add loader * fix: padding * fix: format * chore: add multibridge request and multibrdige utils * fix: chains * chore: load bridging request * fix: typo * chore: implement amount multiplier * chore: dapp improvements * chore: add performance measurements * chore: add custom logic for bridge tx check
1 parent f3256d9 commit 375c5b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+7555
-33
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Binary file not shown.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
:root {
6+
--foreground-rgb: 0, 0, 0;
7+
--background-start-rgb: 214, 219, 220;
8+
--background-end-rgb: 255, 255, 255;
9+
}
10+
11+
@media (prefers-color-scheme: dark) {
12+
:root {
13+
--foreground-rgb: 255, 255, 255;
14+
--background-start-rgb: 0, 0, 0;
15+
--background-end-rgb: 0, 0, 0;
16+
}
17+
}
18+
19+
@layer utilities {
20+
.text-balance {
21+
text-wrap: balance;
22+
}
23+
}
24+
25+
@layer base {
26+
:root {
27+
--background: 0 0% 100%;
28+
--foreground: 240 10% 3.9%;
29+
--card: 0 0% 100%;
30+
--card-foreground: 240 10% 3.9%;
31+
--popover: 0 0% 100%;
32+
--popover-foreground: 240 10% 3.9%;
33+
--primary: 240 5.9% 10%;
34+
--primary-foreground: 0 0% 98%;
35+
--secondary: 240 4.8% 95.9%;
36+
--secondary-foreground: 240 5.9% 10%;
37+
--muted: 240 4.8% 95.9%;
38+
--muted-foreground: 240 3.8% 46.1%;
39+
--accent: 240 4.8% 95.9%;
40+
--accent-foreground: 240 5.9% 10%;
41+
--destructive: 0 84.2% 60.2%;
42+
--destructive-foreground: 0 0% 98%;
43+
--border: 240 5.9% 90%;
44+
--input: 240 5.9% 90%;
45+
--ring: 240 10% 3.9%;
46+
--chart-1: 12 76% 61%;
47+
--chart-2: 173 58% 39%;
48+
--chart-3: 197 37% 24%;
49+
--chart-4: 43 74% 66%;
50+
--chart-5: 27 87% 67%;
51+
--radius: 0.5rem;
52+
}
53+
.dark {
54+
--background: 240 10% 3.9%;
55+
--foreground: 0 0% 98%;
56+
--card: 240 10% 3.9%;
57+
--card-foreground: 0 0% 98%;
58+
--popover: 240 10% 3.9%;
59+
--popover-foreground: 0 0% 98%;
60+
--primary: 0 0% 98%;
61+
--primary-foreground: 240 5.9% 10%;
62+
--secondary: 240 3.7% 15.9%;
63+
--secondary-foreground: 0 0% 98%;
64+
--muted: 240 3.7% 15.9%;
65+
--muted-foreground: 240 5% 64.9%;
66+
--accent: 240 3.7% 15.9%;
67+
--accent-foreground: 0 0% 98%;
68+
--destructive: 0 62.8% 30.6%;
69+
--destructive-foreground: 0 0% 98%;
70+
--border: 240 3.7% 15.9%;
71+
--input: 240 3.7% 15.9%;
72+
--ring: 240 4.9% 83.9%;
73+
--chart-1: 220 70% 50%;
74+
--chart-2: 160 60% 45%;
75+
--chart-3: 30 80% 55%;
76+
--chart-4: 280 65% 60%;
77+
--chart-5: 340 75% 55%;
78+
}
79+
}
80+
81+
@layer base {
82+
* {
83+
@apply border-border;
84+
}
85+
body {
86+
@apply bg-background text-foreground;
87+
}
88+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use client";
2+
import { config } from "@/config";
3+
import { tokenAddresses } from "@/consts/tokens";
4+
import { erc20Abi, Hex } from "viem";
5+
import { getAccount, getWalletClient } from "wagmi/actions";
6+
7+
export default function useSendUsdc() {
8+
const sendUsdcAsync = async (address: Hex, amount: number) => {
9+
const client = await getWalletClient(config);
10+
const account = getAccount(config);
11+
const chain = account.chain?.id;
12+
if (!chain) {
13+
throw new Error("Chain undefined");
14+
}
15+
const contract = tokenAddresses[chain];
16+
if (!chain) {
17+
throw new Error("Cant send on specified chain");
18+
}
19+
const tx = await client.writeContract({
20+
abi: erc20Abi,
21+
address: contract, // arbitrum usdc
22+
functionName: "transfer",
23+
args: [address, BigInt(amount)],
24+
});
25+
return tx;
26+
};
27+
return { sendUsdcAsync };
28+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type { Metadata } from "next";
2+
import { Inter as FontSans } from "next/font/google";
3+
import "./globals.css";
4+
import { cookieToInitialState } from "wagmi";
5+
import { config } from "@/config";
6+
import AppKitProvider from "@/context";
7+
import { Toaster } from "@/components/ui/toaster";
8+
import { headers } from "next/headers";
9+
import { cn } from "@/lib/utils";
10+
import { ThemeProvider } from "@/components/theme-provider";
11+
12+
const fontSans = FontSans({
13+
subsets: ["latin"],
14+
variable: "--font-sans",
15+
});
16+
17+
export const metadata: Metadata = {
18+
title: "Chain Abstraction Demo",
19+
description: "Demo dapp for chain abstraction UX demonstration",
20+
};
21+
22+
export default function RootLayout({
23+
children,
24+
}: Readonly<{
25+
children: React.ReactNode;
26+
}>) {
27+
const initialState = cookieToInitialState(config, headers().get("cookie"));
28+
29+
return (
30+
<html lang="en" suppressHydrationWarning>
31+
<head />
32+
<body
33+
className={cn(
34+
"min-h-screen bg-background font-sans antialiased pt-12 pb-24 mt-12 overflow-y-auto",
35+
fontSans.variable
36+
)}
37+
>
38+
<AppKitProvider initialState={initialState}>
39+
<ThemeProvider
40+
attribute="class"
41+
defaultTheme="dark"
42+
disableTransitionOnChange
43+
>
44+
<div className="flex items-center justify-center min-h-screen">
45+
{children}
46+
</div>
47+
</ThemeProvider>
48+
</AppKitProvider>
49+
<Toaster />
50+
</body>
51+
</html>
52+
);
53+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Card, CardContent, CardHeader } from "@/components/ui/card";
2+
import Transfer from "./transfer";
3+
4+
export default function Home() {
5+
return (
6+
<main>
7+
<div>
8+
<Card>
9+
<CardHeader>
10+
<w3m-button />
11+
</CardHeader>
12+
<CardContent>
13+
<Transfer></Transfer>
14+
</CardContent>
15+
</Card>
16+
</div>
17+
</main>
18+
);
19+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"use client";
2+
import { Button } from "@/components/ui/button";
3+
import useSendUsdc from "./hooks/useSendUsdc";
4+
import { useAccount } from "wagmi";
5+
import { useState } from "react";
6+
import { useToast } from "@/hooks/use-toast";
7+
import { Loader2 } from "lucide-react";
8+
9+
const sendToAddress = "0x81D8C68Be5EcDC5f927eF020Da834AA57cc3Bd24";
10+
const sendAmount = 6000000;
11+
12+
export default function Transfer() {
13+
const { sendUsdcAsync } = useSendUsdc();
14+
const { isConnected, chain } = useAccount();
15+
const [isLoading, setIsLoading] = useState(false);
16+
const { toast } = useToast();
17+
18+
const onButtonClick = async () => {
19+
try {
20+
setIsLoading(true);
21+
const res = await sendUsdcAsync(sendToAddress, sendAmount);
22+
console.log("Transaction completed", res);
23+
toast({
24+
title: "Transaction completed",
25+
description: res,
26+
});
27+
} catch (error) {
28+
console.log(error);
29+
toast({
30+
variant: "destructive",
31+
title: "Uh oh! Something went wrong.",
32+
description: "There was a problem with your request.",
33+
});
34+
} finally {
35+
setIsLoading(false);
36+
}
37+
};
38+
39+
return (
40+
<>
41+
{isConnected ? (
42+
<Button onClick={onButtonClick} disabled={isLoading}>
43+
{isLoading ? (
44+
<>
45+
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> Sending...
46+
</>
47+
) : (
48+
<>Perform action with USDC on {chain?.name}</>
49+
)}
50+
</Button>
51+
) : null}
52+
</>
53+
);
54+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "new-york",
4+
"rsc": true,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.ts",
8+
"css": "app/globals.css",
9+
"baseColor": "zinc",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/lib/utils",
16+
"ui": "@/components/ui",
17+
"lib": "@/lib",
18+
"hooks": "@/hooks"
19+
}
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use client";
2+
3+
import * as React from "react";
4+
import { ThemeProvider as NextThemesProvider } from "next-themes";
5+
import { type ThemeProviderProps } from "next-themes/dist/types";
6+
7+
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
8+
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
9+
}

0 commit comments

Comments
 (0)