Skip to content

Commit 5ea6438

Browse files
authored
initial commit (#678)
1 parent 7850e53 commit 5ea6438

Some content is hidden

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

51 files changed

+10161
-0
lines changed
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.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "default",
4+
"rsc": true,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.ts",
8+
"css": "src/app/globals.css",
9+
"baseColor": "slate",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/lib/utils"
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
import tseslint from "typescript-eslint";
4+
import pluginReact from "eslint-plugin-react";
5+
6+
7+
export default [
8+
{files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
9+
{languageOptions: { globals: globals.browser }},
10+
pluginJs.configs.recommended,
11+
...tseslint.configs.recommended,
12+
pluginReact.configs.flat.recommended,
13+
];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {};
3+
4+
export default nextConfig;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "dca-dapp-demo",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "next build",
8+
"start": "next start",
9+
"lint": "next lint",
10+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,md}\""
11+
},
12+
"dependencies": {
13+
"@hookform/resolvers": "^3.9.0",
14+
"@radix-ui/react-label": "^2.1.0",
15+
"@radix-ui/react-progress": "^1.1.0",
16+
"@radix-ui/react-select": "^2.1.1",
17+
"@radix-ui/react-slot": "^1.1.0",
18+
"@radix-ui/react-tabs": "^1.1.0",
19+
"@radix-ui/react-toast": "^1.2.1",
20+
"@shadcn/ui": "^0.0.4",
21+
"@tanstack/react-query": "5.24.8",
22+
"@wagmi/connectors": "5.1.2",
23+
"@wagmi/core": "2.13.1",
24+
"@walletconnect/ethereum-provider": "2.14.0",
25+
"@walletconnect/utils": "2.14.0",
26+
"@web3modal/wagmi": "5.1.0",
27+
"@web3modal/wallet": "5.1.0",
28+
"autoprefixer": "10.4.18",
29+
"axios": "1.7.2",
30+
"bs58": "^6.0.0",
31+
"class-variance-authority": "^0.7.0",
32+
"clsx": "2.1.0",
33+
"lucide-react": "^0.427.0",
34+
"next": "14.2.5",
35+
"next-themes": "^0.3.0",
36+
"permissionless": "0.1.31",
37+
"pino-pretty": "^11.2.2",
38+
"react": "^18",
39+
"react-dom": "^18",
40+
"react-hook-form": "^7.52.2",
41+
"sonner": "1.4.3",
42+
"tailwind-merge": "2.2.1",
43+
"tailwindcss-animate": "^1.0.7",
44+
"vaul": "0.9.0",
45+
"viem": "2.17.8",
46+
"wagmi": "2.12.2",
47+
"zod": "3.22.4"
48+
},
49+
"devDependencies": {
50+
"@eslint/js": "^9.9.0",
51+
"@types/node": "^20",
52+
"@types/react": "^18",
53+
"@types/react-dom": "^18",
54+
"eslint": "^9.9.0",
55+
"eslint-config-next": "14.2.5",
56+
"eslint-config-prettier": "^9.1.0",
57+
"eslint-plugin-prettier": "^5.2.1",
58+
"eslint-plugin-react": "^7.35.0",
59+
"globals": "^15.9.0",
60+
"postcss": "^8",
61+
"prettier": "^3.3.3",
62+
"tailwindcss": "^3.4.1",
63+
"typescript": "^5",
64+
"typescript-eslint": "^8.2.0"
65+
}
66+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('postcss-load-config').Config} */
2+
const config = {
3+
plugins: {
4+
tailwindcss: {},
5+
},
6+
};
7+
8+
export default config;
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import {
2+
abi as donutContractAbi,
3+
address as donutContractAddress,
4+
} from "@/utils/DonutContract";
5+
import { executeActionsWithECDSAAndCosignerPermissions } from "@/utils/ERC7715PermissionsAsyncUtils";
6+
import { CoSignerApiError } from "@/utils/WalletConnectCosigner";
7+
import { NextResponse } from "next/server";
8+
import { encodeFunctionData, parseEther } from "viem";
9+
import { GrantPermissionsReturnType } from "viem/experimental";
10+
import { sepolia } from "viem/chains";
11+
import { DCAFormSchemaType } from "@/schema/DCAFormSchema";
12+
13+
export async function POST(request: Request) {
14+
const {
15+
strategy,
16+
permissions,
17+
pci,
18+
}: {
19+
strategy: DCAFormSchemaType;
20+
permissions: GrantPermissionsReturnType;
21+
pci: string;
22+
} = await request.json();
23+
const APPLICATION_PRIVATE_KEY = process.env
24+
.NEXT_PUBLIC_APPLICATION_PRIVATE_KEY as `0x${string}`;
25+
26+
try {
27+
if (!APPLICATION_PRIVATE_KEY) {
28+
return NextResponse.json(
29+
{ message: "No application signer" },
30+
{ status: 400 },
31+
);
32+
}
33+
if (!strategy) {
34+
return NextResponse.json(
35+
{ message: "No strategy provider" },
36+
{ status: 400 },
37+
);
38+
}
39+
if (!permissions) {
40+
return NextResponse.json(
41+
{ message: "No permissions provider" },
42+
{ status: 400 },
43+
);
44+
}
45+
if (!pci) {
46+
return NextResponse.json({ message: "No pci provider" }, { status: 400 });
47+
}
48+
49+
const purchaseDonutCallData = encodeFunctionData({
50+
abi: donutContractAbi,
51+
functionName: "purchase",
52+
args: [1],
53+
});
54+
const purchaseDonutCallDataExecution = [
55+
{
56+
target: donutContractAddress as `0x${string}`,
57+
value: parseEther("0.0001"),
58+
callData: purchaseDonutCallData,
59+
},
60+
];
61+
executeActionsWithECDSAAndCosignerPermissions({
62+
ecdsaPrivateKey: APPLICATION_PRIVATE_KEY,
63+
pci,
64+
permissions,
65+
chain: sepolia,
66+
actions: purchaseDonutCallDataExecution,
67+
});
68+
69+
return NextResponse.json(
70+
{ message: "Asset sucessfully purchased." },
71+
{ status: 200 },
72+
);
73+
} catch (e) {
74+
console.log("Error interacting with contract:", e);
75+
let errorMessage = "Error making move";
76+
if (e instanceof CoSignerApiError) {
77+
errorMessage = e.message;
78+
} else if (typeof e === "string") {
79+
errorMessage = e;
80+
} else {
81+
try {
82+
errorMessage = JSON.stringify(e, null, 2);
83+
} catch {
84+
errorMessage = Object.prototype.toString.call(e);
85+
}
86+
}
87+
console.log("Error message:", errorMessage);
88+
89+
return NextResponse.json(
90+
{ message: errorMessage, error: errorMessage },
91+
{ status: 500 },
92+
);
93+
}
94+
}

0 commit comments

Comments
 (0)