Skip to content
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

Ens graph uri #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,4 @@ dist
# wrangler project

.dev.vars
.wrangler
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
14 changes: 6 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { makeResponseFunc } from "./helpers";
export interface Env {
USED_ADDRESS_KV: KVNamespace;
RELAYER_AUTH: string;
ENS_GRAPH_URI: string;
}

type JsonRPC = {
Expand All @@ -25,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<SupportedNetwork, number> = {
goerli: 1000 * 60 * 60 * 24 * 7, // 1 week
sepolia: 1000 * 60 * 60 * 24 * 30, // 1 month
};

const CLAIM_AMOUNT_MAP: Record<SupportedNetwork, bigint> = {
goerli: 500000000000000000n, // 0.5 ETH
sepolia: 250000000000000000n, // 0.25 ETH
};

Expand All @@ -60,7 +59,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) {
Expand All @@ -75,7 +74,7 @@ const checkHasName = async (address: string) => {
}
}`;
const data = await fetch(
"https://api.thegraph.com/subgraphs/name/ensdomains/ens",
ENS_GRAPH_URI,
{
method: "POST",
headers: {
Expand Down Expand Up @@ -111,7 +110,6 @@ export default {
ctx: ExecutionContext
): Promise<Response> {
const url = new URL(request.url);

const { makeResponse, makeRpcResponse } = makeResponseFunc(
request.headers.get("origin") || ""
);
Expand All @@ -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);

Expand Down Expand Up @@ -214,7 +212,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) {
Expand Down