Skip to content

Commit a2ca81b

Browse files
committed
wip: POC around supporting EIP-5792 with viem
1 parent 663bd51 commit a2ca81b

File tree

21 files changed

+3739
-189
lines changed

21 files changed

+3739
-189
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VITE_PRIVY_APP_ID=<privy_app_id>
2+
VITE_PRIVY_CLIENT_ID=<privy_app_secret>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"env": {
3+
"VITE_PRIVY_APP_ID": "cmdisgoa00075js0j9m0720ah",
4+
"VITE_PRIVY_CLIENT_ID": "client-WY6NwHTKdBr537W6x1ZK38ZohDVFkbsBSYssDZJP4BXQx"
5+
}
6+
}

examples/wallet-actions/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Aave React SDK + Privy Wallet
2+
3+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/aave/aave-v4-sdk/tree/main/examples/react-privy)

examples/wallet-actions/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/lens.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css">
8+
<title>Aave React SDK + Privy Wallet</title>
9+
</head>
10+
<body>
11+
<main id="root"></main>
12+
<script type="module" src="/src/main.tsx"></script>
13+
</body>
14+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "react-privy",
3+
"description": "Aave React SDK + Privy Wallet",
4+
"private": true,
5+
"version": "0.0.0",
6+
"type": "module",
7+
"scripts": {
8+
"dev": "vite"
9+
},
10+
"dependencies": {
11+
"@aave/react": "workspace:*",
12+
"react": "^19.1.0",
13+
"react-dom": "^19.1.0",
14+
"viem": "^2.37.5",
15+
"wagmi": "^2.15.6"
16+
},
17+
"devDependencies": {
18+
"@types/react": "^19.1.8",
19+
"@types/react-dom": "^19.1.6",
20+
"@vitejs/plugin-react-swc": "^3.7.2",
21+
"typescript": "^5.6.3",
22+
"vite": "^5.4.9"
23+
}
24+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Suspense } from 'react';
2+
import { SupplyForm } from './SupplyForm';
3+
import { walletClient } from './wallet';
4+
5+
export function App() {
6+
return (
7+
<Suspense fallback={<p>Loading...</p>}>
8+
<h1>Aave React SDK + Privy Wallet</h1>
9+
<p>
10+
This example lets you supply GHO on the Core Hub in Aave v4 using a
11+
Privy-embedded or connected wallet.
12+
</p>
13+
<SupplyForm walletClient={walletClient} />
14+
</Suspense>
15+
);
16+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { bigDecimal, evmAddress, reserveId, useSupply } from '@aave/react';
2+
import { useState } from 'react';
3+
import type { WalletClient } from 'viem';
4+
import { useExecutionPlan } from './useExecutionPlan';
5+
6+
const RESERVE_ID = reserveId(
7+
'MTIzNDU2Nzg5OjoweEJhOTdjNUU1MmNkNUJDM0Q3OTUwQWU3MDc3OUY4RmZFOTJkNDBDZEM6OjY=',
8+
);
9+
10+
type SupplyFormProps = {
11+
walletClient: WalletClient;
12+
};
13+
14+
export function SupplyForm({ walletClient }: SupplyFormProps) {
15+
const [status, setStatus] = useState<string>('');
16+
17+
const handler = useExecutionPlan(walletClient);
18+
const [supply, { loading, error }] = useSupply(handler);
19+
20+
const submit = async (e: React.FormEvent<HTMLFormElement>) => {
21+
e.preventDefault();
22+
23+
const amount = e.currentTarget.amount.value as string;
24+
if (!amount) {
25+
setStatus('Please enter an amount');
26+
return;
27+
}
28+
29+
const result = await supply({
30+
reserve: RESERVE_ID,
31+
amount: {
32+
erc20: {
33+
value: bigDecimal(amount),
34+
},
35+
},
36+
sender: evmAddress(walletClient.account!.address),
37+
});
38+
39+
if (result.isOk()) {
40+
setStatus('Supply successful!');
41+
} else {
42+
setStatus('Supply failed!');
43+
}
44+
};
45+
46+
return (
47+
<form onSubmit={submit}>
48+
<label
49+
style={{
50+
marginBottom: '5px',
51+
}}
52+
>
53+
<strong style={{ display: 'block' }}>Amount:</strong>
54+
<input
55+
name='amount'
56+
type='number'
57+
step='0.000000000000000001'
58+
defaultValue='1'
59+
disabled={loading}
60+
style={{ width: '100%', padding: '8px' }}
61+
placeholder='Amount to supply (in token units)'
62+
/>
63+
<small style={{ color: '#666' }}>
64+
Human-friendly amount (e.g. 1.23, 4.56, 7.89)
65+
</small>
66+
</label>
67+
68+
<button type='submit' disabled={loading}>
69+
Supply
70+
</button>
71+
72+
{status && <p style={{ marginBottom: '10px' }}>{status}</p>}
73+
74+
{error && <p style={{ color: '#f44336' }}>Error: {error.toString()}</p>}
75+
</form>
76+
);
77+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { AaveClient, staging } from '@aave/react';
2+
3+
export const client = AaveClient.create({
4+
environment: staging,
5+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { AaveProvider } from '@aave/react';
2+
import { createRoot } from 'react-dom/client';
3+
import { App } from './App';
4+
import { client } from './client';
5+
6+
createRoot(document.getElementById('root')!).render(
7+
<AaveProvider client={client}>
8+
<App />
9+
</AaveProvider>,
10+
);

0 commit comments

Comments
 (0)