Skip to content

Commit

Permalink
feat: add contract events
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChin committed Aug 10, 2024
1 parent b17eda8 commit faf8cdf
Show file tree
Hide file tree
Showing 11 changed files with 2,578 additions and 54 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 = "${TENDERLY_VIRTUAL_TESTNET_RPC_URL}/verify/etherscan" }
unknown_chain = { key = "${TENDERLY_ACCESS_KEY}", chain = 73571, url = "${VIRTUAL_OPTIMISM_RPC}/verify/etherscan" }
14 changes: 11 additions & 3 deletions frontend/app/api/createVault/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ export async function GET(request: NextRequest) {
),
});

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}`);

const { result, request: contractRequest } =
/* const { result, request: contractRequest } =
await publicClient.simulateContract({
account,
address: FACTORY_CONTRACT_ADDRESS,
Expand All @@ -50,8 +58,8 @@ export async function GET(request: NextRequest) {
),
],
});

*/
/* const tx = await walletClient.writeContract(contractRequest); */

return Response.json({ contractAddress: result });
return Response.json({ contractAddress: FACTORY_CONTRACT_ADDRESS });
}
29 changes: 25 additions & 4 deletions frontend/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@

import Image from "next/image";
import { ConnectButton } from "@rainbow-me/rainbowkit";
import { useWriteContract } from "wagmi";
import { FACTORY_ABI, FACTORY_CONTRACT_ADDRESS } from "@/utils/vaultConfig";
import { parseUnits, stringToBytes, toBytes } from "viem";
import { simulateContract } from "wagmi/actions";
import { config } from "@/utils/wagmi";

export default function Home() {
const { writeContractAsync } = useWriteContract();

const createVault = async () => {
const result = await simulateContract(config, {
address: FACTORY_CONTRACT_ADDRESS,
abi: FACTORY_ABI,
functionName: "createERC4626",
args: [
"0x4200000000000000000000000000000000000006",
"0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
parseUnits("125", 16),
parseUnits("130", 16),
"0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace" as `0x${string}`,
],
});

console.log(result);
};

return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex">
Expand All @@ -19,10 +43,7 @@ export default function Home() {
<ConnectButton />
</div>
</div>




<button onClick={createVault}>Transfer</button>
</main>
);
}
5 changes: 4 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
"start": "next start"
},
"dependencies": {
"@rainbow-me/rainbowkit": "^2.1.4",
"@tanstack/react-query": "^5.51.23",
"next": "14.2.5",
"react": "^18",
"react-dom": "^18",
"viem": "^2.19.3"
"viem": "2.x",
"wagmi": "^2.12.5"
},
"devDependencies": {
"@types/node": "^20",
Expand Down
2 changes: 1 addition & 1 deletion frontend/utils/vaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ export const FACTORY_ABI = [
stateMutability: "view",
type: "function",
},
];
] as const;
11 changes: 5 additions & 6 deletions frontend/utils/wagmi.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { getDefaultConfig } from "@rainbow-me/rainbowkit";
import { Chain, getDefaultConfig } from "@rainbow-me/rainbowkit";
import { arbitrum, optimism } from "wagmi/chains";

import { defineChain } from "viem";

export const virtualOptimism = defineChain({
export const virtualOptimism = {
id: 64122,
name: "Virtual Optimism",
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
Expand All @@ -16,11 +14,12 @@ export const virtualOptimism = defineChain({
},
blockExplorers: {
default: {
name: "Etherscan",
name: "Tenderly Explorer",
url: "https://dashboard.tenderly.co/0xchin/project/testnet/0010d143-1530-4dcb-b00d-1f300fefc9b1",
},
},
});
testnet: true,
} as const satisfies Chain;

export const config = getDefaultConfig({
appName: "RainbowKit demo",
Expand Down
Loading

0 comments on commit faf8cdf

Please sign in to comment.