Skip to content

Commit

Permalink
feat: add contract creation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChin committed Aug 10, 2024
1 parent faf8cdf commit 32bb208
Show file tree
Hide file tree
Showing 21 changed files with 1,931 additions and 68 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ arbitrum = "${ARBITRUM_RPC}"
[etherscan]
optimism = { key = "${OPTIMISM_ETHERSCAN_API_KEY}" }
arbitrum = { key = "${ARBITRUM_ETHERSCAN_API_KEY}" }
unknown_chain = { key = "${TENDERLY_ACCESS_KEY}", chain = 73571, url = "${VIRTUAL_OPTIMISM_RPC}/verify/etherscan" }
unknown_chain = { key = "${TENDERLY_ACCESS_KEY}", chain = 64122, url = "${VIRTUAL_OPTIMISM_RPC}/verify/etherscan" }
4 changes: 2 additions & 2 deletions frontend/app/api/createVault/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export async function GET(request: NextRequest) {
"https://opt-mainnet.g.alchemy.com/v2/YNob1yS6fZux6Fs44VAybG3JXP4k8QgN"
),
});

/*
const contract = getContract({
address: FACTORY_CONTRACT_ADDRESS,
abi: FACTORY_ABI,
// 1a. Insert a single client
client: { wallet: walletClient },
// 1b. Or public and/or wallet clients
});
}); */

console.log(process.env.PRIVATE_KEY);
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
Expand Down
16 changes: 16 additions & 0 deletions frontend/app/api/getVaults/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NextRequest } from "next/server";

export async function GET(request: NextRequest) {
const chainId = request.nextUrl.searchParams.get("chainId") || "10";

const vaults: { [key: number]: string[] } = {
[10]: [
"0xd582ac93a270b8B1c2761D0aFde400Cb334A55c5",
"0x71836DE191ec5622e514A0B3a22D71abd5Bc5448",
],
[42161]: ["0x4d13b7cb87d44796aa409615706caf07b8c01aaa"],
[64122]: [],
};

return Response.json({ vaults: vaults[parseInt(chainId)] });
}
82 changes: 59 additions & 23 deletions frontend/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,68 @@
@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) {
@layer base {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--card: 0 0% 100%;
--card-foreground: 222.2 84% 4.9%;
--popover: 0 0% 100%;
--popover-foreground: 222.2 84% 4.9%;
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;
--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;
--muted: 210 40% 96.1%;
--muted-foreground: 215.4 16.3% 46.9%;
--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% 11.2%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 210 40% 98%;
--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;
--ring: 222.2 84% 4.9%;
--radius: 0.5rem;
--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%;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
--card: 222.2 84% 4.9%;
--card-foreground: 210 40% 98%;
--popover: 222.2 84% 4.9%;
--popover-foreground: 210 40% 98%;
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 11.2%;
--secondary: 217.2 32.6% 17.5%;
--secondary-foreground: 210 40% 98%;
--muted: 217.2 32.6% 17.5%;
--muted-foreground: 215 20.2% 65.1%;
--accent: 217.2 32.6% 17.5%;
--accent-foreground: 210 40% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 210 40% 98%;
--border: 217.2 32.6% 17.5%;
--input: 217.2 32.6% 17.5%;
--ring: 212.7 26.8% 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 utilities {
.text-balance {
text-wrap: balance;
@layer base {
* {
@apply border-border;
}
}
body {
@apply bg-background text-foreground;
}
}
81 changes: 81 additions & 0 deletions frontend/app/hooks/useVault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { useReadContract, useReadContracts } from "wagmi";
import { VAULT_ABI } from "@/utils/vaultConfig";
import { erc20Abi } from "viem";

export const useVault = (address: `0x${string}`) => {
const assetAddress = useReadContract({
abi: VAULT_ABI,
address,
functionName: "asset",
});

const assetData = useReadContracts({
allowFailure: false,
contracts: [
{
address: assetAddress.data,
abi: erc20Abi,
functionName: "decimals",
},
{
address: assetAddress.data,
abi: erc20Abi,
functionName: "symbol",
},
],
});

const borrowedAssetAddress = useReadContract({
abi: VAULT_ABI,
address,
functionName: "borrowedAsset",
});

const borrowedAssetData = useReadContracts({
allowFailure: false,
contracts: [
{
address: borrowedAssetAddress.data,
abi: erc20Abi,
functionName: "decimals",
},
{
address: borrowedAssetAddress.data,
abi: erc20Abi,
functionName: "symbol",
},
],
});

const aaveData = useReadContracts({
allowFailure: false,
contracts: [
{
address: address,
abi: VAULT_ABI,
functionName: "getVaultAaveData",
},
],
});

if (aaveData.data) {
console.log(aaveData.data[0][0] - aaveData.data[0][1]);
}

return {
token: {
...{ address: assetAddress.data },
decimals: assetData.data ? assetData.data[0] : 0,
symbol: assetData.data ? assetData.data[1] : "",
},
debtToken: {
...{ address: borrowedAssetAddress.data },
decimals: borrowedAssetData.data ? borrowedAssetData.data[0] : 0,
symbol: borrowedAssetData.data ? borrowedAssetData.data[1] : "",
},
tvl: aaveData.data
? aaveData.data[0][0] - aaveData.data[0][1]
: parseInt("0").toFixed(2),
healthFactor: 0,
};
};
Loading

0 comments on commit 32bb208

Please sign in to comment.