From 74b8e320a69966a676fe84921d190c6e093a1b81 Mon Sep 17 00:00:00 2001 From: Makoto Inoue <2630+makoto@users.noreply.github.com> Date: Wed, 22 May 2024 11:46:51 +0100 Subject: [PATCH 1/3] Add ENS_GRAPH_URI --- .gitignore | 1 + README.md | 18 ++++++++++++++++++ src/index.ts | 9 +++++---- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 4238780..f303a98 100644 --- a/.gitignore +++ b/.gitignore @@ -169,3 +169,4 @@ dist # wrangler project .dev.vars +.wrangler diff --git a/README.md b/README.md new file mode 100644 index 0000000..9e0ed0f --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# ens-faucet-worker + +Testnet faucet cloudflaire worker for ENS testnet users + +## Dev setup + +- `gh repo clone ensdomains/ens-faucet-worker` +- `touch .dev.vars` +- Add ENS_GRAPH_URI +- `pnpm install` +- `yarn start` + +## Deployment + +``` +wrangler secret put ENS_GRAPH_URI +yarn deploy +``` \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 1ca525c..180c395 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { makeResponseFunc } from "./helpers"; export interface Env { USED_ADDRESS_KV: KVNamespace; RELAYER_AUTH: string; + ENS_GRAPH_URI: string; } type JsonRPC = { @@ -60,7 +61,7 @@ const query = ({ type DomainArray = { id: string }[]; // check mainnet for if address has ownership of a name -const checkHasName = async (address: string) => { +const checkHasName = async (g: string, address: string) => { const gqlQuery = `{ account(id: "${address.toLowerCase()}") { domains(first: 1) { @@ -75,7 +76,7 @@ const checkHasName = async (address: string) => { } }`; const data = await fetch( - "https://api.thegraph.com/subgraphs/name/ensdomains/ens", + ENS_GRAPH_URI, { method: "POST", headers: { @@ -111,7 +112,7 @@ export default { ctx: ExecutionContext ): Promise { const url = new URL(request.url); - + console.log({env}) const { makeResponse, makeRpcResponse } = makeResponseFunc( request.headers.get("origin") || "" ); @@ -214,7 +215,7 @@ export default { const hasClaimed = addressLastUsed && Date.now() - addressLastUsed < claimInterval; - const hasName = await checkHasName(address); + const hasName = await checkHasName(env.ENS_GRAPH_URI, address); if (body.method === "faucet_getAddress") { if (hasClaimed) { From f74c66293b7ed33c45226a42479795e5a9b374f1 Mon Sep 17 00:00:00 2001 From: Makoto Inoue <2630+makoto@users.noreply.github.com> Date: Wed, 22 May 2024 11:48:39 +0100 Subject: [PATCH 2/3] Remove console.log --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 180c395..4422b96 100644 --- a/src/index.ts +++ b/src/index.ts @@ -112,7 +112,6 @@ export default { ctx: ExecutionContext ): Promise { const url = new URL(request.url); - console.log({env}) const { makeResponse, makeRpcResponse } = makeResponseFunc( request.headers.get("origin") || "" ); From 89b01bb584ad75c85fc18968ed16b75f41a01539 Mon Sep 17 00:00:00 2001 From: Makoto Inoue <2630+makoto@users.noreply.github.com> Date: Wed, 22 May 2024 13:24:54 +0100 Subject: [PATCH 3/3] Remove sepolia --- src/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4422b96..189fee6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,15 +26,13 @@ const SUPPORTED_METHODS = [ "faucet_getAddress", "faucet_request", ] as const; -const SUPPORTED_NETWORKS = ["goerli", "sepolia"] as const; +const SUPPORTED_NETWORKS = ["sepolia"] as const; const CLAIM_INTERVAL_MAP: Record = { - goerli: 1000 * 60 * 60 * 24 * 7, // 1 week sepolia: 1000 * 60 * 60 * 24 * 30, // 1 month }; const CLAIM_AMOUNT_MAP: Record = { - goerli: 500000000000000000n, // 0.5 ETH sepolia: 250000000000000000n, // 0.25 ETH }; @@ -120,7 +118,7 @@ export default { const network = paths.length === 0 - ? "goerli" + ? "sepolia" : SUPPORTED_NETWORKS.find((n) => n === paths[0]); if (!network) return makeResponse("Not Found", 404);