@latticexyz/faucet 0.0.7 → 2.0.0-main-9940fdb3
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 +21 -0
- package/dist/bin/faucet-server.js +3 -0
- package/dist/bin/faucet-server.js.map +1 -0
- package/dist/chunk-NZUDFSYM.js +2 -0
- package/dist/chunk-NZUDFSYM.js.map +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +44 -20
- package/src/createAppRouter.ts +42 -0
- package/src/createClient.ts +21 -0
- package/src/debug.ts +3 -0
- package/src/index.ts +2 -0
- package/README.md +0 -3
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.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as i}from"../chunk-NZUDFSYM.js";import"dotenv/config";import{z as r}from"zod";import n from"fastify";import{fastifyTRPCPlugin as s}from"@trpc/server/adapters/fastify";import{http as p,parseEther as a,isHex as m,createClient as c}from"viem";import{privateKeyToAccount as f}from"viem/accounts";var t=r.object({HOST:r.string().default("0.0.0.0"),PORT:r.coerce.number().positive().default(3002),RPC_HTTP_URL:r.string(),FAUCET_PRIVATE_KEY:r.string().refine(m),DRIP_AMOUNT_ETHER:r.string().default("1").transform(e=>a(e))}).parse(process.env,{errorMap:e=>({message:`Missing or invalid environment variable: ${e.path.join(".")}`})}),T=c({transport:p(t.RPC_HTTP_URL)}),R=f(t.FAUCET_PRIVATE_KEY),o=n({maxParamLength:5e3});await o.register(import("@fastify/cors"));o.register(s,{prefix:"/trpc",trpcOptions:{router:i(),createContext:async()=>({client:T,faucetAccount:R,dripAmount:t.DRIP_AMOUNT_ETHER})}});await o.listen({host:t.HOST,port:t.PORT});console.log(`faucet server listening on http://${t.HOST}:${t.PORT}`);
|
|
3
|
+
//# sourceMappingURL=faucet-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../bin/faucet-server.ts"],"sourcesContent":["#!/usr/bin/env node\nimport \"dotenv/config\";\nimport { z } from \"zod\";\nimport fastify from \"fastify\";\nimport { fastifyTRPCPlugin } from \"@trpc/server/adapters/fastify\";\nimport { ClientConfig, http, parseEther, isHex, createClient } from \"viem\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport { AppRouter, createAppRouter } from \"../src/createAppRouter\";\nimport { getChainId } from \"viem/actions\";\n\n// TODO: refine zod type to be either CHAIN_ID or RPC_HTTP_URL/RPC_WS_URL\nconst env = z\n .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 .parse(process.env, {\n errorMap: (issue) => ({\n message: `Missing or invalid environment variable: ${issue.path.join(\".\")}`,\n }),\n });\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// @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"],"mappings":";yCACA,MAAO,gBACP,OAAS,KAAAA,MAAS,MAClB,OAAOC,MAAa,UACpB,OAAS,qBAAAC,MAAyB,gCAClC,OAAuB,QAAAC,EAAM,cAAAC,EAAY,SAAAC,EAAO,gBAAAC,MAAoB,OACpE,OAAS,uBAAAC,MAA2B,gBAKpC,IAAMC,EAAMC,EACT,OAAO,CACN,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,OAAOC,CAAK,EAC3C,kBAAmBD,EAChB,OAAO,EACP,QAAQ,GAAG,EACX,UAAWE,GAAUC,EAAWD,CAAK,CAAC,CAC3C,CAAC,EACA,MAAM,QAAQ,IAAK,CAClB,SAAWE,IAAW,CACpB,QAAS,4CAA4CA,EAAM,KAAK,KAAK,GAAG,GAC1E,EACF,CAAC,EAEGC,EAASC,EAAa,CAC1B,UAAWC,EAAKR,EAAI,YAAY,CAClC,CAAC,EAEKS,EAAgBC,EAAoBV,EAAI,kBAAkB,EAG1DW,EAASC,EAAQ,CACrB,eAAgB,GAClB,CAAC,EAED,MAAMD,EAAO,SAAS,OAAO,eAAe,CAAC,EAG7CA,EAAO,SAASE,EAA8B,CAC5C,OAAQ,QACR,YAAa,CACX,OAAQC,EAAgB,EACxB,cAAe,UAAa,CAC1B,OAAAR,EACA,cAAAG,EACA,WAAYT,EAAI,iBAClB,EACF,CACF,CAAC,EAED,MAAMW,EAAO,OAAO,CAAE,KAAMX,EAAI,KAAM,KAAMA,EAAI,IAAK,CAAC,EACtD,QAAQ,IAAI,qCAAqCA,EAAI,QAAQA,EAAI,MAAM","names":["z","fastify","fastifyTRPCPlugin","http","parseEther","isHex","createClient","privateKeyToAccount","env","z","isHex","ether","parseEther","issue","client","createClient","http","faucetAccount","privateKeyToAccount","server","fastify","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 @@
|
|
|
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
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"dist/**/*",
|
|
10
|
-
"dist/*"
|
|
11
|
-
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"format": "prettier --config .prettierrc --ignore-path .prettierignore --write ."
|
|
3
|
+
"version": "2.0.0-main-9940fdb3",
|
|
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
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
"
|
|
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.6.0",
|
|
27
|
+
"zod": "^3.21.4"
|
|
24
28
|
},
|
|
25
|
-
"
|
|
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/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
package/src/index.ts
ADDED
package/README.md
DELETED