-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add working end-to-end flow (#34)
Co-authored-by: Benjamin A <[email protected]>
- Loading branch information
Showing
56 changed files
with
1,507 additions
and
3,056 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
contracts/broadcast/SimpleAccountFactory.s.sol/84531/dry-run/run-1699546943.json
Large diffs are not rendered by default.
Oops, something went wrong.
14 changes: 7 additions & 7 deletions
14
contracts/broadcast/SimpleAccountFactory.s.sol/84531/dry-run/run-latest.json
Large diffs are not rendered by default.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
contracts/broadcast/SimpleAccountFactory.s.sol/84531/run-1699546986.json
Large diffs are not rendered by default.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
contracts/broadcast/SimpleAccountFactory.s.sol/84531/run-1699547004.json
Large diffs are not rendered by default.
Oops, something went wrong.
38 changes: 19 additions & 19 deletions
38
contracts/broadcast/SimpleAccountFactory.s.sol/84531/run-latest.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 @@ | ||
# forge script DeploySimpleAccountFactory --private-key $PRIVATE_KEY --rpc-url https://goerli.base.org/ --etherscan-api-key $ETHERSCAN_API_KEY --verify --slow --broadcast |
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
STACKUP_BUNDLER_API_KEY="" | ||
RELAYER_PRIVATE_KEY="" |
This file contains 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,2 @@ | ||
STACKUP_BUNDLER_API_KEY="9e0f13b10e97cbc4609b356ba3cb10f066225df054eb8dfd4bf0ba54aec9f650" | ||
RELAYER_PRIVATE_KEY="0xa641a081f7667ae1761619d690911324847f968cbfc4e9d03291a8b3b5f0caa1" |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
/** @type {import('next').NextConfig} */ | ||
|
||
const fs = require('fs'); | ||
module.exports = { | ||
reactStrictMode: false, | ||
env: { | ||
STACKUP_BUNDLER_API_KEY: process.env.STACKUP_BUNDLER_API_KEY, | ||
}, | ||
webpack: (config) => { | ||
config.resolve.fallback = { fs: false, net: false, tls: false }; | ||
config.resolve.fallback = { fs: false, net: false, tls: false }; | ||
return config; | ||
}, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,20 +1,5 @@ | ||
import { Box, Flex } from "@radix-ui/themes"; | ||
import SessionList from "@/components/SessionList"; | ||
import WCInput from "@/components/WCInput"; | ||
import PassKey from "@/components/PassKey"; | ||
import { SendTransaction } from "@/components/SendTransaction"; | ||
import HomePage from "@/components/HomePage"; | ||
|
||
export default async function Home() { | ||
return ( | ||
<Flex align="center" direction="column"> | ||
<Box> | ||
<h1>Hocus Pocus XYZ</h1> | ||
<br /> | ||
<WCInput /> | ||
<SessionList /> | ||
<PassKey /> | ||
<SendTransaction /> | ||
</Box> | ||
</Flex> | ||
); | ||
return <HomePage />; | ||
} |
This file contains 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,59 @@ | ||
import { stringify } from "viem"; | ||
import fs from "fs"; | ||
|
||
export async function GET(req: Request) { | ||
const searchParams = new URL(req.url).searchParams; | ||
const ids = searchParams.get("ids"); | ||
const currencies = searchParams.get("currencies"); | ||
|
||
const { isCached, priceCached } = getFromCache(ids, currencies); | ||
if (isCached) { | ||
return Response.json(JSON.parse(priceCached)); | ||
} | ||
|
||
const price = await fetch( | ||
`https://api.coingecko.com/api/v3/simple/price?ids=${ids}&vs_currencies=${currencies}`, | ||
); | ||
|
||
const priceJson = await price.json(); | ||
|
||
saveToCache(ids, currencies, priceJson); | ||
|
||
return Response.json(JSON.parse(stringify(priceJson))); | ||
} | ||
|
||
function saveToCache( | ||
ids: string | null, | ||
currencies: string | null, | ||
priceJson: Response | null, | ||
): void { | ||
const key = `${ids}-${currencies}`; | ||
// create cache folder if not exist | ||
if (!fs.existsSync("./cache")) { | ||
fs.mkdirSync("./cache"); | ||
} | ||
// save to local files | ||
fs.writeFileSync(`./cache/${key}.json`, JSON.stringify({ ...priceJson, timestamp: Date.now() })); | ||
} | ||
|
||
function getFromCache( | ||
ids: string | null, | ||
currencies: string | null, | ||
): { isCached: boolean; priceCached: string } { | ||
const key = `${ids}-${currencies}`; | ||
// retrieve from local files | ||
try { | ||
const priceCached = fs.readFileSync(`./cache/${key}.json`, "utf8"); | ||
const priceCachedJson = JSON.parse(priceCached); | ||
|
||
const timestamp = priceCachedJson.timestamp; | ||
const now = Date.now(); | ||
// cache for 1 minute | ||
if (now - timestamp > 1 * 60 * 1000) { | ||
return { isCached: false, priceCached: "" }; | ||
} | ||
return { isCached: true, priceCached }; | ||
} catch (e) { | ||
return { isCached: false, priceCached: "" }; | ||
} | ||
} |
This file contains 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,21 @@ | ||
import { PUBLIC_CLIENT } from "@/constants/client"; | ||
import { FACTORY_ABI, FACTORY_ADDRESS } from "@/constants/factory"; | ||
import { Hex, stringify, toHex } from "viem"; | ||
|
||
export async function GET(_req: Request, { params }: { params: { id: Hex } }) { | ||
const { id } = params; | ||
if (!id) { | ||
return Response.json(JSON.parse(stringify({ error: "id is required" }))); | ||
} | ||
|
||
const user = await PUBLIC_CLIENT.readContract({ | ||
address: FACTORY_ADDRESS, | ||
abi: FACTORY_ABI, | ||
functionName: "getUser", | ||
args: [BigInt(id)], | ||
}); | ||
|
||
const balance = await PUBLIC_CLIENT.getBalance({ address: user.account }); | ||
|
||
return Response.json(JSON.parse(stringify({ ...user, id: toHex(user.id), balance }))); | ||
} |
Oops, something went wrong.