-
Notifications
You must be signed in to change notification settings - Fork 7
Feat/user positions #7
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
Open
foodaka
wants to merge
5
commits into
main
Choose a base branch
from
feat/user-positions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5f7175d
feat: user positions
foodaka 3dd4430
chore: cleanup
foodaka 26d99f8
Update examples/user-positions/src/App.tsx
foodaka ed4ab09
Merge branch 'main' into feat/user-positions
foodaka b21d0d1
Merge branch 'main' into feat/user-positions
juangm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # query for user positions on aave v3 | ||
|
|
||
| [](https://stackblitz.com/github/aave/aave-sdk/tree/main/examples/user-positions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <link rel="icon" type="image/svg+xml" href="/lens.svg" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"> | ||
| <title>query for user positions on aave v3</title> | ||
| </head> | ||
| <body> | ||
| <main id="root"></main> | ||
| <script type="module" src="/src/main.tsx"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "user-positions", | ||
| "description": "query for user positions on aave v3", | ||
| "private": true, | ||
| "version": "0.0.0", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite" | ||
| }, | ||
| "dependencies": { | ||
| "@aave/react": "workspace:*", | ||
| "react": "^19.1.0", | ||
| "react-dom": "^19.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^19.1.8", | ||
| "@types/react-dom": "^19.1.6", | ||
| "@vitejs/plugin-react-swc": "^3.7.2", | ||
| "typescript": "^5.6.3", | ||
| "vite": "^5.4.9" | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,238 @@ | ||
| import { AaveProvider, useUserSupplies, useUserBorrows, evmAddress, chainId, useAaveMarkets, ZERO_ADDRESS } from '@aave/react'; | ||
| import { client } from './client'; | ||
|
|
||
| // TODO: change to your address or any address you want to query | ||
| const user = evmAddress("ZERO_ADDRESS"); | ||
|
|
||
| function UserPositions() { | ||
| const { data: markets, loading: marketsLoading } = useAaveMarkets({ | ||
| chainIds: [chainId(1), chainId(8453)], | ||
| }); | ||
|
|
||
| const marketAddresses = markets?.map(market => ({ | ||
| address: market.address, | ||
| chainId: market.chain.chainId, | ||
| })) || []; | ||
|
|
||
| const { data: userSupplies, loading: userSuppliesLoading } = useUserSupplies({ | ||
| markets: marketAddresses, | ||
| user, | ||
| }); | ||
|
|
||
| const { data: userBorrows, loading: userBorrowsLoading } = useUserBorrows({ | ||
| markets: marketAddresses, | ||
| user, | ||
| }); | ||
|
|
||
| if (userSuppliesLoading || userBorrowsLoading || marketsLoading) { | ||
| return <p>Loading positions...</p>; | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <header> | ||
| <h1>👻 Aave V3 User Positions</h1> | ||
| <p>Address: {user}</p> | ||
| </header> | ||
|
|
||
| <div style={{ padding: '20px', fontFamily: 'Arial, sans-serif' }}> | ||
| <h2>Supply Positions ({userSupplies?.length || 0})</h2> | ||
|
|
||
| {userSupplies?.map((position, index) => ( | ||
| <div key={index} style={{ | ||
| border: '1px solid #ddd', | ||
| borderRadius: '8px', | ||
| padding: '16px', | ||
| margin: '16px 0', | ||
| backgroundColor: '#f9f9f9' | ||
| }}> | ||
| <div style={{ display: 'flex', alignItems: 'center', marginBottom: '12px' }}> | ||
| <img | ||
| src={position.currency.imageUrl} | ||
| alt={position.currency.symbol} | ||
| style={{ width: '32px', height: '32px', marginRight: '12px' }} | ||
| /> | ||
| <div style={{ flex: 1 }}> | ||
| <h3 style={{ margin: '0', color: '#333' }}> | ||
| {position.currency.name} ({position.currency.symbol}) | ||
| </h3> | ||
| <p style={{ margin: '0', color: '#666', fontSize: '14px' }}> | ||
| {position.market.name} | ||
| </p> | ||
| </div> | ||
| <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}> | ||
| <img | ||
| src={position.market.chain.icon} | ||
| alt={position.market.chain.name} | ||
| style={{ width: '20px', height: '20px' }} | ||
| /> | ||
| <div style={{ textAlign: 'right' }}> | ||
| <p style={{ margin: '0', fontWeight: 'bold', fontSize: '14px', color: '#333' }}> | ||
| {position.market.chain.name} | ||
| </p> | ||
| <p style={{ margin: '0', fontSize: '12px', color: '#666' }}> | ||
| Chain ID: {position.market.chain.chainId} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '16px' }}> | ||
| <div> | ||
| <p style={{ margin: '4px 0', fontWeight: 'bold', color: '#333' }}>Balance</p> | ||
| <p style={{ margin: '4px 0', fontSize: '18px' }}> | ||
| {parseFloat(position.balance.amount.value).toFixed(6)} {position.currency.symbol} | ||
| </p> | ||
| <p style={{ margin: '4px 0', color: '#666' }}> | ||
| ${parseFloat(position.balance.usd).toFixed(2)} USD | ||
| </p> | ||
| </div> | ||
|
|
||
| <div> | ||
| <p style={{ margin: '4px 0', fontWeight: 'bold', color: '#333' }}>Supply APY</p> | ||
| <p style={{ margin: '4px 0', fontSize: '18px', color: '#00a86b' }}> | ||
| {(parseFloat(position.apy.value) * 100).toFixed(2)}% | ||
| </p> | ||
| </div> | ||
|
|
||
| <div> | ||
| <p style={{ margin: '4px 0', fontWeight: 'bold', color: '#333' }}>Token Price</p> | ||
| <p style={{ margin: '4px 0', fontSize: '18px' }}> | ||
| ${parseFloat(position.balance.usdPerToken).toLocaleString()} | ||
| </p> | ||
| </div> | ||
|
|
||
| <div> | ||
| <p style={{ margin: '4px 0', fontWeight: 'bold', color: '#333' }}>Collateral Status</p> | ||
| <div style={{ display: 'flex', gap: '8px', alignItems: 'center' }}> | ||
| <span style={{ | ||
| padding: '4px 8px', | ||
| borderRadius: '4px', | ||
| fontSize: '12px', | ||
| backgroundColor: position.canBeCollateral ? '#e8f5e8' : '#f5e8e8', | ||
| color: position.canBeCollateral ? '#2d5016' : '#5d1a1a' | ||
| }}> | ||
| {position.canBeCollateral ? '✅ Can Collateralize' : '❌ Cannot Collateralize'} | ||
| </span> | ||
| {position.isCollateral && ( | ||
| <span style={{ | ||
| padding: '4px 8px', | ||
| borderRadius: '4px', | ||
| fontSize: '12px', | ||
| backgroundColor: '#e3f2fd', | ||
| color: '#1565c0' | ||
| }}> | ||
| 🔒 Used as Collateral | ||
| </span> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ))} | ||
|
|
||
| {userSupplies?.length === 0 && ( | ||
| <p style={{ textAlign: 'center', color: '#666', fontStyle: 'italic' }}> | ||
| No supply positions found for this address. | ||
| </p> | ||
| )} | ||
|
|
||
| <h2>Borrow Positions ({userBorrows?.length || 0})</h2> | ||
|
|
||
| {userBorrows?.map((position, index) => ( | ||
| <div key={index} style={{ | ||
| border: '1px solid #ddd', | ||
| borderRadius: '8px', | ||
| padding: '16px', | ||
| margin: '16px 0', | ||
| backgroundColor: '#fff9f9' | ||
| }}> | ||
| <div style={{ display: 'flex', alignItems: 'center', marginBottom: '12px' }}> | ||
| <img | ||
| src={position.currency.imageUrl} | ||
| alt={position.currency.symbol} | ||
| style={{ width: '32px', height: '32px', marginRight: '12px' }} | ||
| /> | ||
| <div style={{ flex: 1 }}> | ||
| <h3 style={{ margin: '0', color: '#333' }}> | ||
| {position.currency.name} ({position.currency.symbol}) | ||
| </h3> | ||
| <p style={{ margin: '0', color: '#666', fontSize: '14px' }}> | ||
| {position.market.name} | ||
| </p> | ||
| </div> | ||
| <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}> | ||
| <img | ||
| src={position.market.chain.icon} | ||
| alt={position.market.chain.name} | ||
| style={{ width: '20px', height: '20px' }} | ||
| /> | ||
| <div style={{ textAlign: 'right' }}> | ||
| <p style={{ margin: '0', fontWeight: 'bold', fontSize: '14px', color: '#333' }}> | ||
| {position.market.chain.name} | ||
| </p> | ||
| <p style={{ margin: '0', fontSize: '12px', color: '#666' }}> | ||
| Chain ID: {position.market.chain.chainId} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '16px' }}> | ||
| <div> | ||
| <p style={{ margin: '4px 0', fontWeight: 'bold', color: '#333' }}>Debt Amount</p> | ||
| <p style={{ margin: '4px 0', fontSize: '18px' }}> | ||
| {parseFloat(position.debt.amount.value).toFixed(6)} {position.currency.symbol} | ||
| </p> | ||
| <p style={{ margin: '4px 0', color: '#666' }}> | ||
| ${parseFloat(position.debt.usd).toFixed(2)} USD | ||
| </p> | ||
| </div> | ||
|
|
||
| <div> | ||
| <p style={{ margin: '4px 0', fontWeight: 'bold', color: '#333' }}>Borrow APY</p> | ||
| <p style={{ margin: '4px 0', fontSize: '18px', color: '#d73527' }}> | ||
| {(parseFloat(position.apy.value) * 100).toFixed(2)}% | ||
| </p> | ||
| </div> | ||
|
|
||
| <div> | ||
| <p style={{ margin: '4px 0', fontWeight: 'bold', color: '#333' }}>Token Price</p> | ||
| <p style={{ margin: '4px 0', fontSize: '18px' }}> | ||
| ${parseFloat(position.debt.usdPerToken).toLocaleString()} | ||
| </p> | ||
| </div> | ||
|
|
||
| <div> | ||
| <p style={{ margin: '4px 0', fontWeight: 'bold', color: '#333' }}>Borrow Type</p> | ||
| <span style={{ | ||
| padding: '4px 8px', | ||
| borderRadius: '4px', | ||
| fontSize: '12px', | ||
| backgroundColor: '#ffe8e8', | ||
| color: '#8b0000' | ||
| }}> | ||
| 📉 Borrowed Debt | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ))} | ||
|
|
||
| {userBorrows?.length === 0 && ( | ||
| <p style={{ textAlign: 'center', color: '#666', fontStyle: 'italic' }}> | ||
| No borrow positions found for this address. | ||
| </p> | ||
| )} | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export function App() { | ||
| return ( | ||
| <AaveProvider client={client}> | ||
| <UserPositions /> | ||
| </AaveProvider> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { AaveClient, staging } from '@aave/react'; | ||
|
|
||
| export const client = AaveClient.create({ | ||
| environment: staging, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { StrictMode } from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
|
|
||
| import { App } from './App'; | ||
|
|
||
| createRoot(document.getElementById('root')!).render( | ||
| <StrictMode> | ||
| <App /> | ||
| </StrictMode>, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /// <reference types="vite/client" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ESNext", | ||
| "useDefineForClassFields": true, | ||
| "lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
| "jsx": "react-jsx", | ||
| "module": "ESNext", | ||
| "moduleResolution": "Bundler", | ||
| "strict": true, | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "esModuleInterop": true, | ||
| "noEmit": true, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": true, | ||
| "noImplicitReturns": true, | ||
| "skipLibCheck": true | ||
| }, | ||
| "include": ["src", "vite.config.ts"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import react from '@vitejs/plugin-react-swc'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [react()], | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.