@latticexyz/faucet 0.0.7 → 2.0.0-foundry-js-c7b0289b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-present Lattice Labs Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,30 @@
1
- # @latticexyz/registry
1
+ # faucet
2
2
 
3
- registry contract w/ deployments
3
+ A minimal Typescript faucet to drip native tokens on Ethereum chains
4
+
5
+ ## Usage
6
+
7
+ Install and run with:
8
+
9
+ ```sh
10
+ npm install @latticexyz/faucet@next
11
+ npm faucet-server
12
+ ```
13
+
14
+ or execute the package bin directly:
15
+
16
+ ```sh
17
+ npx @latticexyz/faucet@next
18
+ ```
19
+
20
+ ## Configuration
21
+
22
+ The faucet can configured with the following environment variables:
23
+
24
+ | Variable | Description | Default |
25
+ | -------------------- | ----------------------------------------------------- | --------- |
26
+ | `HOST` | Host that the indexer server listens on | `0.0.0.0` |
27
+ | `PORT` | Port that the indexer server listens on | `3002` |
28
+ | `RPC_HTTP_URL` | HTTP URL for Ethereum RPC | |
29
+ | `FAUCET_PRIVATE_KEY` | Private key of wallet to distribute faucet funds from | |
30
+ | `DRIP_AMOUNT_ETHER` | Drip amount in ether |
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import{a as s}from"../chunk-NZUDFSYM.js";import"dotenv/config";import d from"fastify";import{fastifyTRPCPlugin as u}from"@trpc/server/adapters/fastify";import{http as R,createClient as h}from"viem";import{privateKeyToAccount as l}from"viem/accounts";import{isHex as m,parseEther as f}from"viem";import{z as e,ZodError as T}from"zod";var c=e.object({HOST:e.string().default("0.0.0.0"),PORT:e.coerce.number().positive().default(3002),RPC_HTTP_URL:e.string(),FAUCET_PRIVATE_KEY:e.string().refine(m),DRIP_AMOUNT_ETHER:e.string().default("1").transform(t=>f(t))});function a(t){let o=t!==void 0?e.intersection(c,t):c;try{return o.parse(process.env)}catch(i){if(i instanceof T){let{_errors:A,...p}=i.format();console.error(`
3
+ Missing or invalid environment variables:
4
+
5
+ ${Object.keys(p).join(`
6
+ `)}
7
+ `),process.exit(1)}throw i}}var r=a(),v=h({transport:R(r.RPC_HTTP_URL)}),y=l(r.FAUCET_PRIVATE_KEY),n=d({maxParamLength:5e3});await n.register(import("@fastify/cors"));n.get("/healthz",(t,o)=>o.code(200).send());n.get("/readyz",(t,o)=>o.code(200).send());n.register(u,{prefix:"/trpc",trpcOptions:{router:s(),createContext:async()=>({client:v,faucetAccount:y,dripAmount:r.DRIP_AMOUNT_ETHER})}});await n.listen({host:r.HOST,port:r.PORT});console.log(`faucet server listening on http://${r.HOST}:${r.PORT}`);
8
+ //# sourceMappingURL=faucet-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../bin/faucet-server.ts","../../bin/parseEnv.ts"],"sourcesContent":["#!/usr/bin/env node\nimport \"dotenv/config\";\nimport fastify from \"fastify\";\nimport { fastifyTRPCPlugin } from \"@trpc/server/adapters/fastify\";\nimport { http, createClient } from \"viem\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport { AppRouter, createAppRouter } from \"../src/createAppRouter\";\nimport { parseEnv } from \"./parseEnv\";\n\nconst env = parseEnv();\n\nconst client = createClient({\n transport: http(env.RPC_HTTP_URL),\n});\n\nconst faucetAccount = privateKeyToAccount(env.FAUCET_PRIVATE_KEY);\n\n// @see https://fastify.dev/docs/latest/\nconst server = fastify({\n maxParamLength: 5000,\n});\n\nawait server.register(import(\"@fastify/cors\"));\n\n// k8s healthchecks\nserver.get(\"/healthz\", (req, res) => res.code(200).send());\nserver.get(\"/readyz\", (req, res) => res.code(200).send());\n\n// @see https://trpc.io/docs/server/adapters/fastify\nserver.register(fastifyTRPCPlugin<AppRouter>, {\n prefix: \"/trpc\",\n trpcOptions: {\n router: createAppRouter(),\n createContext: async () => ({\n client,\n faucetAccount,\n dripAmount: env.DRIP_AMOUNT_ETHER,\n }),\n },\n});\n\nawait server.listen({ host: env.HOST, port: env.PORT });\nconsole.log(`faucet server listening on http://${env.HOST}:${env.PORT}`);\n","import { isHex, parseEther } from \"viem\";\nimport { z, ZodError, ZodIntersection, ZodTypeAny } from \"zod\";\n\nconst commonSchema = z.object({\n HOST: z.string().default(\"0.0.0.0\"),\n PORT: z.coerce.number().positive().default(3002),\n RPC_HTTP_URL: z.string(),\n FAUCET_PRIVATE_KEY: z.string().refine(isHex),\n DRIP_AMOUNT_ETHER: z\n .string()\n .default(\"1\")\n .transform((ether) => parseEther(ether)),\n});\n\nexport function parseEnv<TSchema extends ZodTypeAny | undefined = undefined>(\n schema?: TSchema\n): z.infer<TSchema extends ZodTypeAny ? ZodIntersection<typeof commonSchema, TSchema> : typeof commonSchema> {\n const envSchema = schema !== undefined ? z.intersection(commonSchema, schema) : commonSchema;\n try {\n return envSchema.parse(process.env);\n } catch (error) {\n if (error instanceof ZodError) {\n const { _errors, ...invalidEnvVars } = error.format();\n console.error(`\\nMissing or invalid environment variables:\\n\\n ${Object.keys(invalidEnvVars).join(\"\\n \")}\\n`);\n process.exit(1);\n }\n throw error;\n }\n}\n"],"mappings":";yCACA,MAAO,gBACP,OAAOA,MAAa,UACpB,OAAS,qBAAAC,MAAyB,gCAClC,OAAS,QAAAC,EAAM,gBAAAC,MAAoB,OACnC,OAAS,uBAAAC,MAA2B,gBCLpC,OAAS,SAAAC,EAAO,cAAAC,MAAkB,OAClC,OAAS,KAAAC,EAAG,YAAAC,MAA6C,MAEzD,IAAMC,EAAeF,EAAE,OAAO,CAC5B,KAAMA,EAAE,OAAO,EAAE,QAAQ,SAAS,EAClC,KAAMA,EAAE,OAAO,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,EAC/C,aAAcA,EAAE,OAAO,EACvB,mBAAoBA,EAAE,OAAO,EAAE,OAAOF,CAAK,EAC3C,kBAAmBE,EAChB,OAAO,EACP,QAAQ,GAAG,EACX,UAAWG,GAAUJ,EAAWI,CAAK,CAAC,CAC3C,CAAC,EAEM,SAASC,EACdC,EAC2G,CAC3G,IAAMC,EAAYD,IAAW,OAAYL,EAAE,aAAaE,EAAcG,CAAM,EAAIH,EAChF,GAAI,CACF,OAAOI,EAAU,MAAM,QAAQ,GAAG,CACpC,OAASC,EAAP,CACA,GAAIA,aAAiBN,EAAU,CAC7B,GAAM,CAAE,QAAAO,EAAS,GAAGC,CAAe,EAAIF,EAAM,OAAO,EACpD,QAAQ,MAAM;AAAA;AAAA;AAAA,IAAoD,OAAO,KAAKE,CAAc,EAAE,KAAK;AAAA,GAAM;AAAA,CAAK,EAC9G,QAAQ,KAAK,CAAC,EAEhB,MAAMF,CACR,CACF,CDnBA,IAAMG,EAAMC,EAAS,EAEfC,EAASC,EAAa,CAC1B,UAAWC,EAAKJ,EAAI,YAAY,CAClC,CAAC,EAEKK,EAAgBC,EAAoBN,EAAI,kBAAkB,EAG1DO,EAASC,EAAQ,CACrB,eAAgB,GAClB,CAAC,EAED,MAAMD,EAAO,SAAS,OAAO,eAAe,CAAC,EAG7CA,EAAO,IAAI,WAAY,CAACE,EAAKC,IAAQA,EAAI,KAAK,GAAG,EAAE,KAAK,CAAC,EACzDH,EAAO,IAAI,UAAW,CAACE,EAAKC,IAAQA,EAAI,KAAK,GAAG,EAAE,KAAK,CAAC,EAGxDH,EAAO,SAASI,EAA8B,CAC5C,OAAQ,QACR,YAAa,CACX,OAAQC,EAAgB,EACxB,cAAe,UAAa,CAC1B,OAAAV,EACA,cAAAG,EACA,WAAYL,EAAI,iBAClB,EACF,CACF,CAAC,EAED,MAAMO,EAAO,OAAO,CAAE,KAAMP,EAAI,KAAM,KAAMA,EAAI,IAAK,CAAC,EACtD,QAAQ,IAAI,qCAAqCA,EAAI,QAAQA,EAAI,MAAM","names":["fastify","fastifyTRPCPlugin","http","createClient","privateKeyToAccount","isHex","parseEther","z","ZodError","commonSchema","ether","parseEnv","schema","envSchema","error","_errors","invalidEnvVars","env","parseEnv","client","createClient","http","faucetAccount","privateKeyToAccount","server","fastify","req","res","fastifyTRPCPlugin","createAppRouter"]}
@@ -0,0 +1,2 @@
1
+ import{z as i}from"zod";import{initTRPC as m}from"@trpc/server";import{formatEther as s,isHex as d}from"viem";import{sendTransaction as f}from"viem/actions";import a from"debug";var p=a("mud:faucet");function $(){let t=m.context().create();return t.router({drip:t.procedure.input(i.object({address:i.string().refine(d)})).mutation(async e=>{let{client:u,faucetAccount:o,dripAmount:r}=e.ctx,{address:n}=e.input,c=await f(u,{chain:null,account:o,to:n,value:r});return p(`Dripped ${s(r)} ETH from ${o.address} to ${n} (tx ${c})`),c})})}export{$ as a};
2
+ //# sourceMappingURL=chunk-NZUDFSYM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/createAppRouter.ts","../src/debug.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { initTRPC } from \"@trpc/server\";\nimport { Client, Hex, LocalAccount, formatEther, isHex } from \"viem\";\nimport { sendTransaction } from \"viem/actions\";\nimport { debug } from \"./debug\";\n\nexport type AppContext = {\n client: Client;\n faucetAccount: LocalAccount<string>;\n dripAmount: bigint;\n};\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function createAppRouter() {\n const t = initTRPC.context<AppContext>().create();\n\n return t.router({\n drip: t.procedure\n .input(\n z.object({\n address: z.string().refine(isHex),\n })\n )\n .mutation(async (opts): Promise<Hex> => {\n const { client, faucetAccount, dripAmount } = opts.ctx;\n\n const { address } = opts.input;\n const tx = await sendTransaction(client, {\n chain: null,\n account: faucetAccount,\n to: address,\n value: dripAmount,\n });\n\n debug(`Dripped ${formatEther(dripAmount)} ETH from ${faucetAccount.address} to ${address} (tx ${tx})`);\n\n return tx;\n }),\n });\n}\n\nexport type AppRouter = ReturnType<typeof createAppRouter>;\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:faucet\");\n"],"mappings":"AAAA,OAAS,KAAAA,MAAS,MAClB,OAAS,YAAAC,MAAgB,eACzB,OAAoC,eAAAC,EAAa,SAAAC,MAAa,OAC9D,OAAS,mBAAAC,MAAuB,eCHhC,OAAOC,MAAiB,QAEjB,IAAMC,EAAQD,EAAY,YAAY,EDWtC,SAASE,GAAkB,CAChC,IAAM,EAAIC,EAAS,QAAoB,EAAE,OAAO,EAEhD,OAAO,EAAE,OAAO,CACd,KAAM,EAAE,UACL,MACCC,EAAE,OAAO,CACP,QAASA,EAAE,OAAO,EAAE,OAAOC,CAAK,CAClC,CAAC,CACH,EACC,SAAS,MAAOC,GAAuB,CACtC,GAAM,CAAE,OAAAC,EAAQ,cAAAC,EAAe,WAAAC,CAAW,EAAIH,EAAK,IAE7C,CAAE,QAAAI,CAAQ,EAAIJ,EAAK,MACnBK,EAAK,MAAMC,EAAgBL,EAAQ,CACvC,MAAO,KACP,QAASC,EACT,GAAIE,EACJ,MAAOD,CACT,CAAC,EAED,OAAAI,EAAM,WAAWC,EAAYL,CAAU,cAAcD,EAAc,cAAcE,SAAeC,IAAK,EAE9FA,CACT,CAAC,CACL,CAAC,CACH","names":["z","initTRPC","formatEther","isHex","sendTransaction","createDebug","debug","createAppRouter","initTRPC","z","isHex","opts","client","faucetAccount","dripAmount","address","tx","sendTransaction","debug","formatEther"]}
@@ -0,0 +1,2 @@
1
+ import{a as o}from"../chunk-NZUDFSYM.js";import{createTRPCProxyClient as e,httpBatchLink as r}from"@trpc/client";function n({url:t}){return e({links:[r({url:t})]})}export{o as createAppRouter,n as createClient};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/createClient.ts"],"sourcesContent":["import { createTRPCProxyClient, httpBatchLink, CreateTRPCProxyClient } from \"@trpc/client\";\nimport type { AppRouter } from \"./createAppRouter\";\n\ntype CreateClientOptions = {\n /**\n * tRPC endpoint URL like `https://faucet.dev.linfra.xyz/trpc`.\n */\n url: string;\n};\n\n/**\n * Creates a tRPC client to talk to a MUD faucet.\n *\n * @param {CreateClientOptions} options See `CreateClientOptions`.\n * @returns {CreateTRPCProxyClient<AppRouter>} A typed tRPC client.\n */\nexport function createClient({ url }: CreateClientOptions): CreateTRPCProxyClient<AppRouter> {\n return createTRPCProxyClient<AppRouter>({\n links: [httpBatchLink({ url })],\n });\n}\n"],"mappings":"yCAAA,OAAS,yBAAAA,EAAuB,iBAAAC,MAA4C,eAgBrE,SAASC,EAAa,CAAE,IAAAC,CAAI,EAA0D,CAC3F,OAAOH,EAAiC,CACtC,MAAO,CAACC,EAAc,CAAE,IAAAE,CAAI,CAAC,CAAC,CAChC,CAAC,CACH","names":["createTRPCProxyClient","httpBatchLink","createClient","url"]}
package/package.json CHANGED
@@ -1,26 +1,50 @@
1
1
  {
2
2
  "name": "@latticexyz/faucet",
3
- "version": "0.0.7",
4
- "private": false,
5
- "license": "GPL-3.0",
6
- "main": "dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "files": [
9
- "dist/**/*",
10
- "dist/*"
11
- ],
12
- "scripts": {
13
- "format": "prettier --config .prettierrc --ignore-path .prettierignore --write ."
3
+ "version": "2.0.0-foundry-js-c7b0289b",
4
+ "description": "Faucet API for Lattice testnet",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/latticexyz/mud.git",
8
+ "directory": "packages/faucet"
14
9
  },
15
- "devDependencies": {
16
- "@vercel/node": "^1.12.1",
17
- "ethers": "^5.4.7",
18
- "ts-dedent": "^2.2.0",
19
- "ts-node": "^10.3.0",
20
- "typescript": "^4.4.4"
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": "./dist/src/index.js"
14
+ },
15
+ "types": "src/index.ts",
16
+ "bin": {
17
+ "faucet-server": "./dist/bin/faucet-server.js"
21
18
  },
22
19
  "dependencies": {
23
- "ethers": "^5.5.2"
20
+ "@fastify/cors": "^8.3.0",
21
+ "@trpc/client": "10.34.0",
22
+ "@trpc/server": "10.34.0",
23
+ "debug": "^4.3.4",
24
+ "dotenv": "^16.0.3",
25
+ "fastify": "^4.21.0",
26
+ "viem": "1.14.0",
27
+ "zod": "^3.21.4"
24
28
  },
25
- "gitHead": "d1174a7252a268928c6d7dc535a2bd00cf744025"
26
- }
29
+ "devDependencies": {
30
+ "@types/debug": "^4.1.7",
31
+ "tsup": "^6.7.0",
32
+ "tsx": "^3.12.6",
33
+ "vitest": "0.31.4"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f",
39
+ "scripts": {
40
+ "build": "pnpm run build:js",
41
+ "build:js": "tsup",
42
+ "clean": "pnpm run clean:js",
43
+ "clean:js": "rimraf dist",
44
+ "dev": "tsup --watch",
45
+ "lint": "eslint .",
46
+ "start": "tsx bin/faucet-server",
47
+ "test": "tsc --noEmit --skipLibCheck",
48
+ "test:ci": "pnpm run test"
49
+ }
50
+ }
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import { initTRPC } from "@trpc/server";
3
+ import { Client, Hex, LocalAccount, formatEther, isHex } from "viem";
4
+ import { sendTransaction } from "viem/actions";
5
+ import { debug } from "./debug";
6
+
7
+ export type AppContext = {
8
+ client: Client;
9
+ faucetAccount: LocalAccount<string>;
10
+ dripAmount: bigint;
11
+ };
12
+
13
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
14
+ export function createAppRouter() {
15
+ const t = initTRPC.context<AppContext>().create();
16
+
17
+ return t.router({
18
+ drip: t.procedure
19
+ .input(
20
+ z.object({
21
+ address: z.string().refine(isHex),
22
+ })
23
+ )
24
+ .mutation(async (opts): Promise<Hex> => {
25
+ const { client, faucetAccount, dripAmount } = opts.ctx;
26
+
27
+ const { address } = opts.input;
28
+ const tx = await sendTransaction(client, {
29
+ chain: null,
30
+ account: faucetAccount,
31
+ to: address,
32
+ value: dripAmount,
33
+ });
34
+
35
+ debug(`Dripped ${formatEther(dripAmount)} ETH from ${faucetAccount.address} to ${address} (tx ${tx})`);
36
+
37
+ return tx;
38
+ }),
39
+ });
40
+ }
41
+
42
+ export type AppRouter = ReturnType<typeof createAppRouter>;
@@ -0,0 +1,21 @@
1
+ import { createTRPCProxyClient, httpBatchLink, CreateTRPCProxyClient } from "@trpc/client";
2
+ import type { AppRouter } from "./createAppRouter";
3
+
4
+ type CreateClientOptions = {
5
+ /**
6
+ * tRPC endpoint URL like `https://faucet.dev.linfra.xyz/trpc`.
7
+ */
8
+ url: string;
9
+ };
10
+
11
+ /**
12
+ * Creates a tRPC client to talk to a MUD faucet.
13
+ *
14
+ * @param {CreateClientOptions} options See `CreateClientOptions`.
15
+ * @returns {CreateTRPCProxyClient<AppRouter>} A typed tRPC client.
16
+ */
17
+ export function createClient({ url }: CreateClientOptions): CreateTRPCProxyClient<AppRouter> {
18
+ return createTRPCProxyClient<AppRouter>({
19
+ links: [httpBatchLink({ url })],
20
+ });
21
+ }
package/src/debug.ts ADDED
@@ -0,0 +1,3 @@
1
+ import createDebug from "debug";
2
+
3
+ export const debug = createDebug("mud:faucet");
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./createAppRouter";
2
+ export * from "./createClient";