Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: chain abstraction multibridge #699

Merged
merged 16 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions advanced/dapps/chain-abstraction-demo/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions advanced/dapps/chain-abstraction-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions advanced/dapps/chain-abstraction-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

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.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Binary file not shown.
88 changes: 88 additions & 0 deletions advanced/dapps/chain-abstraction-demo/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

@layer utilities {
.text-balance {
text-wrap: balance;
}
}

@layer base {
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
--card: 0 0% 100%;
--card-foreground: 240 10% 3.9%;
--popover: 0 0% 100%;
--popover-foreground: 240 10% 3.9%;
--primary: 240 5.9% 10%;
--primary-foreground: 0 0% 98%;
--secondary: 240 4.8% 95.9%;
--secondary-foreground: 240 5.9% 10%;
--muted: 240 4.8% 95.9%;
--muted-foreground: 240 3.8% 46.1%;
--accent: 240 4.8% 95.9%;
--accent-foreground: 240 5.9% 10%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;
--border: 240 5.9% 90%;
--input: 240 5.9% 90%;
--ring: 240 10% 3.9%;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
--chart-4: 43 74% 66%;
--chart-5: 27 87% 67%;
--radius: 0.5rem;
}
.dark {
--background: 240 10% 3.9%;
--foreground: 0 0% 98%;
--card: 240 10% 3.9%;
--card-foreground: 0 0% 98%;
--popover: 240 10% 3.9%;
--popover-foreground: 0 0% 98%;
--primary: 0 0% 98%;
--primary-foreground: 240 5.9% 10%;
--secondary: 240 3.7% 15.9%;
--secondary-foreground: 0 0% 98%;
--muted: 240 3.7% 15.9%;
--muted-foreground: 240 5% 64.9%;
--accent: 240 3.7% 15.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;
--border: 240 3.7% 15.9%;
--input: 240 3.7% 15.9%;
--ring: 240 4.9% 83.9%;
--chart-1: 220 70% 50%;
--chart-2: 160 60% 45%;
--chart-3: 30 80% 55%;
--chart-4: 280 65% 60%;
--chart-5: 340 75% 55%;
}
}

@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}
28 changes: 28 additions & 0 deletions advanced/dapps/chain-abstraction-demo/app/hooks/useSendUsdc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use client";
import { config } from "@/config";
import { tokenAddresses } from "@/consts/tokens";
import { erc20Abi, Hex } from "viem";
import { getAccount, getWalletClient } from "wagmi/actions";

export default function useSendUsdc() {
const sendUsdcAsync = async (address: Hex, amount: number) => {
const client = await getWalletClient(config);
const account = getAccount(config);
const chain = account.chain?.id;
if (!chain) {
throw new Error("Chain undefined");
}
const contract = tokenAddresses[chain];
if (!chain) {
throw new Error("Cant send on specified chain");
}
const tx = await client.writeContract({
abi: erc20Abi,
address: contract, // arbitrum usdc
functionName: "transfer",
args: [address, BigInt(amount)],
});
return tx;
};
return { sendUsdcAsync };
}
53 changes: 53 additions & 0 deletions advanced/dapps/chain-abstraction-demo/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Metadata } from "next";
import { Inter as FontSans } from "next/font/google";
import "./globals.css";
import { cookieToInitialState } from "wagmi";
import { config } from "@/config";
import AppKitProvider from "@/context";
import { Toaster } from "@/components/ui/toaster";
import { headers } from "next/headers";
import { cn } from "@/lib/utils";
import { ThemeProvider } from "@/components/theme-provider";

const fontSans = FontSans({
subsets: ["latin"],
variable: "--font-sans",
});

export const metadata: Metadata = {
title: "Chain Abstraction Demo",
description: "Demo dapp for chain abstraction UX demonstration",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const initialState = cookieToInitialState(config, headers().get("cookie"));

return (
<html lang="en" suppressHydrationWarning>
<head />
<body
className={cn(
"min-h-screen bg-background font-sans antialiased pt-12 pb-24 mt-12 overflow-y-auto",
fontSans.variable
)}
>
<AppKitProvider initialState={initialState}>
<ThemeProvider
attribute="class"
defaultTheme="dark"
disableTransitionOnChange
>
<div className="flex items-center justify-center min-h-screen">
{children}
</div>
</ThemeProvider>
</AppKitProvider>
<Toaster />
</body>
</html>
);
}
19 changes: 19 additions & 0 deletions advanced/dapps/chain-abstraction-demo/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import Transfer from "./transfer";

export default function Home() {
return (
<main>
<div>
<Card>
<CardHeader>
<w3m-button />
</CardHeader>
<CardContent>
<Transfer></Transfer>
</CardContent>
</Card>
</div>
</main>
);
}
54 changes: 54 additions & 0 deletions advanced/dapps/chain-abstraction-demo/app/transfer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use client";
import { Button } from "@/components/ui/button";
import useSendUsdc from "./hooks/useSendUsdc";
import { useAccount } from "wagmi";
import { useState } from "react";
import { useToast } from "@/hooks/use-toast";
import { Loader2 } from "lucide-react";

const sendToAddress = "0x81D8C68Be5EcDC5f927eF020Da834AA57cc3Bd24";
const sendAmount = 6000000;

export default function Transfer() {
const { sendUsdcAsync } = useSendUsdc();
const { isConnected, chain } = useAccount();
const [isLoading, setIsLoading] = useState(false);
const { toast } = useToast();

const onButtonClick = async () => {
try {
setIsLoading(true);
const res = await sendUsdcAsync(sendToAddress, sendAmount);
console.log("Transaction completed", res);
toast({
title: "Transaction completed",
description: res,
});
} catch (error) {
console.log(error);
toast({
variant: "destructive",
title: "Uh oh! Something went wrong.",
description: "There was a problem with your request.",
});
} finally {
setIsLoading(false);
}
};

return (
<>
{isConnected ? (
<Button onClick={onButtonClick} disabled={isLoading}>
{isLoading ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> Sending...
</>
) : (
<>Perform action with USDC on {chain?.name}</>
)}
</Button>
) : null}
</>
);
}
20 changes: 20 additions & 0 deletions advanced/dapps/chain-abstraction-demo/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "app/globals.css",
"baseColor": "zinc",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use client";

import * as React from "react";
import { ThemeProvider as NextThemesProvider } from "next-themes";
import { type ThemeProviderProps } from "next-themes/dist/types";

export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
}
Loading