@latticexyz/faucet 2.2.18-8d0ce55e964e646a1c804c401df01c4deb866f30 → 2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2
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/dist/bin/faucet-server.cjs +126 -0
- package/dist/bin/faucet-server.cjs.map +1 -0
- package/dist/bin/faucet-server.d.cts +1 -0
- package/dist/bin/faucet-server.js +66 -4
- package/dist/bin/faucet-server.js.map +1 -1
- package/dist/chunk-FX3HLBCB.js +40 -0
- package/dist/{chunk-LVBDKFIB.js.map → chunk-FX3HLBCB.js.map} +1 -1
- package/dist/index.cjs +86 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +51 -0
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -3
- package/dist/chunk-LVBDKFIB.js +0 -2
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/bin/faucet-server.ts
|
|
27
|
+
var import_config = require("dotenv/config");
|
|
28
|
+
var import_fastify = __toESM(require("fastify"), 1);
|
|
29
|
+
var import_fastify2 = require("@trpc/server/adapters/fastify");
|
|
30
|
+
var import_viem3 = require("viem");
|
|
31
|
+
var import_accounts = require("viem/accounts");
|
|
32
|
+
|
|
33
|
+
// src/createAppRouter.ts
|
|
34
|
+
var import_zod = require("zod");
|
|
35
|
+
var import_server = require("@trpc/server");
|
|
36
|
+
var import_viem = require("viem");
|
|
37
|
+
var import_common = require("@latticexyz/common");
|
|
38
|
+
|
|
39
|
+
// src/debug.ts
|
|
40
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
41
|
+
var debug = (0, import_debug.default)("mud:faucet");
|
|
42
|
+
var error = (0, import_debug.default)("mud:faucet");
|
|
43
|
+
debug.log = console.debug.bind(console);
|
|
44
|
+
error.log = console.error.bind(console);
|
|
45
|
+
|
|
46
|
+
// src/createAppRouter.ts
|
|
47
|
+
function createAppRouter() {
|
|
48
|
+
const t = import_server.initTRPC.context().create();
|
|
49
|
+
return t.router({
|
|
50
|
+
drip: t.procedure.input(
|
|
51
|
+
import_zod.z.object({
|
|
52
|
+
address: import_zod.z.string().refine(import_viem.isHex)
|
|
53
|
+
})
|
|
54
|
+
).mutation(async (opts) => {
|
|
55
|
+
const { client, faucetAccount, dripAmount } = opts.ctx;
|
|
56
|
+
const { address } = opts.input;
|
|
57
|
+
const tx = await (0, import_common.sendTransaction)(client, {
|
|
58
|
+
chain: null,
|
|
59
|
+
account: faucetAccount,
|
|
60
|
+
to: address,
|
|
61
|
+
value: dripAmount
|
|
62
|
+
});
|
|
63
|
+
debug(`Dripped ${(0, import_viem.formatEther)(dripAmount)} ETH from ${faucetAccount.address} to ${address} (tx ${tx})`);
|
|
64
|
+
return tx;
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/bin/parseEnv.ts
|
|
70
|
+
var import_viem2 = require("viem");
|
|
71
|
+
var import_zod2 = require("zod");
|
|
72
|
+
var commonSchema = import_zod2.z.object({
|
|
73
|
+
HOST: import_zod2.z.string().default("0.0.0.0"),
|
|
74
|
+
PORT: import_zod2.z.coerce.number().positive().default(3002),
|
|
75
|
+
RPC_HTTP_URL: import_zod2.z.string(),
|
|
76
|
+
FAUCET_PRIVATE_KEY: import_zod2.z.string().refine(import_viem2.isHex),
|
|
77
|
+
DRIP_AMOUNT_ETHER: import_zod2.z.string().default("1").transform((ether) => (0, import_viem2.parseEther)(ether))
|
|
78
|
+
});
|
|
79
|
+
function parseEnv(schema) {
|
|
80
|
+
const envSchema = schema !== void 0 ? import_zod2.z.intersection(commonSchema, schema) : commonSchema;
|
|
81
|
+
try {
|
|
82
|
+
return envSchema.parse(process.env);
|
|
83
|
+
} catch (error2) {
|
|
84
|
+
if (error2 instanceof import_zod2.ZodError) {
|
|
85
|
+
const { ...invalidEnvVars } = error2.format();
|
|
86
|
+
console.error(`
|
|
87
|
+
Missing or invalid environment variables:
|
|
88
|
+
|
|
89
|
+
${Object.keys(invalidEnvVars).join("\n ")}
|
|
90
|
+
`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
throw error2;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/bin/faucet-server.ts
|
|
98
|
+
(async () => {
|
|
99
|
+
const env = parseEnv();
|
|
100
|
+
const client = (0, import_viem3.createClient)({
|
|
101
|
+
transport: (0, import_viem3.http)(env.RPC_HTTP_URL)
|
|
102
|
+
});
|
|
103
|
+
const faucetAccount = (0, import_accounts.privateKeyToAccount)(env.FAUCET_PRIVATE_KEY);
|
|
104
|
+
const server = (0, import_fastify.default)({
|
|
105
|
+
maxParamLength: 5e3,
|
|
106
|
+
logger: true
|
|
107
|
+
});
|
|
108
|
+
await server.register(import("@fastify/compress"));
|
|
109
|
+
await server.register(import("@fastify/cors"));
|
|
110
|
+
server.get("/healthz", (req, res) => res.code(200).send());
|
|
111
|
+
server.get("/readyz", (req, res) => res.code(200).send());
|
|
112
|
+
server.register(import_fastify2.fastifyTRPCPlugin, {
|
|
113
|
+
prefix: "/trpc",
|
|
114
|
+
trpcOptions: {
|
|
115
|
+
router: createAppRouter(),
|
|
116
|
+
createContext: async () => ({
|
|
117
|
+
client,
|
|
118
|
+
faucetAccount,
|
|
119
|
+
dripAmount: env.DRIP_AMOUNT_ETHER
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
await server.listen({ host: env.HOST, port: env.PORT });
|
|
124
|
+
console.log(`faucet server listening on http://${env.HOST}:${env.PORT}`);
|
|
125
|
+
})();
|
|
126
|
+
//# sourceMappingURL=faucet-server.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bin/faucet-server.ts","../../src/createAppRouter.ts","../../src/debug.ts","../../src/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 \"../createAppRouter\";\nimport { parseEnv } from \"./parseEnv\";\n\n// Workaround for:\n// Top-level await is currently not supported with the \"cjs\" output format\n(async (): Promise<void> => {\n const env = parseEnv();\n\n const client = createClient({\n transport: http(env.RPC_HTTP_URL),\n });\n\n const faucetAccount = privateKeyToAccount(env.FAUCET_PRIVATE_KEY);\n\n // @see https://fastify.dev/docs/latest/\n const server = fastify({\n maxParamLength: 5000,\n logger: true,\n });\n\n await server.register(import(\"@fastify/compress\"));\n await server.register(import(\"@fastify/cors\"));\n\n // k8s healthchecks\n server.get(\"/healthz\", (req, res) => res.code(200).send());\n server.get(\"/readyz\", (req, res) => res.code(200).send());\n\n // @see https://trpc.io/docs/server/adapters/fastify\n server.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\n await server.listen({ host: env.HOST, port: env.PORT });\n console.log(`faucet server listening on http://${env.HOST}:${env.PORT}`);\n})();\n","import { z } from \"zod\";\nimport { initTRPC } from \"@trpc/server\";\nimport { Client, Hex, LocalAccount, formatEther, isHex } from \"viem\";\nimport { sendTransaction } from \"@latticexyz/common\";\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\");\nexport const error = createDebug(\"mud:faucet\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\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 { ...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":"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","names":["import_fastify","import_viem","createDebug","import_viem","import_zod","error","fastify"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -1,8 +1,70 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
createAppRouter
|
|
4
|
+
} from "../chunk-FX3HLBCB.js";
|
|
5
|
+
|
|
6
|
+
// src/bin/faucet-server.ts
|
|
7
|
+
import "dotenv/config";
|
|
8
|
+
import fastify from "fastify";
|
|
9
|
+
import { fastifyTRPCPlugin } from "@trpc/server/adapters/fastify";
|
|
10
|
+
import { http, createClient } from "viem";
|
|
11
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
12
|
+
|
|
13
|
+
// src/bin/parseEnv.ts
|
|
14
|
+
import { isHex, parseEther } from "viem";
|
|
15
|
+
import { z, ZodError } from "zod";
|
|
16
|
+
var commonSchema = z.object({
|
|
17
|
+
HOST: z.string().default("0.0.0.0"),
|
|
18
|
+
PORT: z.coerce.number().positive().default(3002),
|
|
19
|
+
RPC_HTTP_URL: z.string(),
|
|
20
|
+
FAUCET_PRIVATE_KEY: z.string().refine(isHex),
|
|
21
|
+
DRIP_AMOUNT_ETHER: z.string().default("1").transform((ether) => parseEther(ether))
|
|
22
|
+
});
|
|
23
|
+
function parseEnv(schema) {
|
|
24
|
+
const envSchema = schema !== void 0 ? z.intersection(commonSchema, schema) : commonSchema;
|
|
25
|
+
try {
|
|
26
|
+
return envSchema.parse(process.env);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (error instanceof ZodError) {
|
|
29
|
+
const { ...invalidEnvVars } = error.format();
|
|
30
|
+
console.error(`
|
|
3
31
|
Missing or invalid environment variables:
|
|
4
32
|
|
|
5
|
-
${Object.keys(
|
|
6
|
-
|
|
7
|
-
|
|
33
|
+
${Object.keys(invalidEnvVars).join("\n ")}
|
|
34
|
+
`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/bin/faucet-server.ts
|
|
42
|
+
(async () => {
|
|
43
|
+
const env = parseEnv();
|
|
44
|
+
const client = createClient({
|
|
45
|
+
transport: http(env.RPC_HTTP_URL)
|
|
46
|
+
});
|
|
47
|
+
const faucetAccount = privateKeyToAccount(env.FAUCET_PRIVATE_KEY);
|
|
48
|
+
const server = fastify({
|
|
49
|
+
maxParamLength: 5e3,
|
|
50
|
+
logger: true
|
|
51
|
+
});
|
|
52
|
+
await server.register(import("@fastify/compress"));
|
|
53
|
+
await server.register(import("@fastify/cors"));
|
|
54
|
+
server.get("/healthz", (req, res) => res.code(200).send());
|
|
55
|
+
server.get("/readyz", (req, res) => res.code(200).send());
|
|
56
|
+
server.register(fastifyTRPCPlugin, {
|
|
57
|
+
prefix: "/trpc",
|
|
58
|
+
trpcOptions: {
|
|
59
|
+
router: createAppRouter(),
|
|
60
|
+
createContext: async () => ({
|
|
61
|
+
client,
|
|
62
|
+
faucetAccount,
|
|
63
|
+
dripAmount: env.DRIP_AMOUNT_ETHER
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
await server.listen({ host: env.HOST, port: env.PORT });
|
|
68
|
+
console.log(`faucet server listening on http://${env.HOST}:${env.PORT}`);
|
|
69
|
+
})();
|
|
8
70
|
//# sourceMappingURL=faucet-server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/faucet-server.ts","../../src/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 \"../createAppRouter\";\nimport { parseEnv } from \"./parseEnv\";\n\
|
|
1
|
+
{"version":3,"sources":["../../src/bin/faucet-server.ts","../../src/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 \"../createAppRouter\";\nimport { parseEnv } from \"./parseEnv\";\n\n// Workaround for:\n// Top-level await is currently not supported with the \"cjs\" output format\n(async (): Promise<void> => {\n const env = parseEnv();\n\n const client = createClient({\n transport: http(env.RPC_HTTP_URL),\n });\n\n const faucetAccount = privateKeyToAccount(env.FAUCET_PRIVATE_KEY);\n\n // @see https://fastify.dev/docs/latest/\n const server = fastify({\n maxParamLength: 5000,\n logger: true,\n });\n\n await server.register(import(\"@fastify/compress\"));\n await server.register(import(\"@fastify/cors\"));\n\n // k8s healthchecks\n server.get(\"/healthz\", (req, res) => res.code(200).send());\n server.get(\"/readyz\", (req, res) => res.code(200).send());\n\n // @see https://trpc.io/docs/server/adapters/fastify\n server.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\n await server.listen({ host: env.HOST, port: env.PORT });\n console.log(`faucet server listening on http://${env.HOST}:${env.PORT}`);\n})();\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 { ...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":";;;;;;AACA,OAAO;AACP,OAAO,aAAa;AACpB,SAAS,yBAAyB;AAClC,SAAS,MAAM,oBAAoB;AACnC,SAAS,2BAA2B;;;ACLpC,SAAS,OAAO,kBAAkB;AAClC,SAAS,GAAG,gBAA6C;AAEzD,IAAM,eAAe,EAAE,OAAO;AAAA,EAC5B,MAAM,EAAE,OAAO,EAAE,QAAQ,SAAS;AAAA,EAClC,MAAM,EAAE,OAAO,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI;AAAA,EAC/C,cAAc,EAAE,OAAO;AAAA,EACvB,oBAAoB,EAAE,OAAO,EAAE,OAAO,KAAK;AAAA,EAC3C,mBAAmB,EAChB,OAAO,EACP,QAAQ,GAAG,EACX,UAAU,CAAC,UAAU,WAAW,KAAK,CAAC;AAC3C,CAAC;AAEM,SAAS,SACd,QAC2G;AAC3G,QAAM,YAAY,WAAW,SAAY,EAAE,aAAa,cAAc,MAAM,IAAI;AAChF,MAAI;AACF,WAAO,UAAU,MAAM,QAAQ,GAAG;AAAA,EACpC,SAAS,OAAO;AACd,QAAI,iBAAiB,UAAU;AAC7B,YAAM,EAAE,GAAG,eAAe,IAAI,MAAM,OAAO;AAC3C,cAAQ,MAAM;AAAA;AAAA;AAAA,IAAoD,OAAO,KAAK,cAAc,EAAE,KAAK,MAAM,CAAC;AAAA,CAAI;AAC9G,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,UAAM;AAAA,EACR;AACF;;;CDjBC,YAA2B;AAC1B,QAAM,MAAM,SAAS;AAErB,QAAM,SAAS,aAAa;AAAA,IAC1B,WAAW,KAAK,IAAI,YAAY;AAAA,EAClC,CAAC;AAED,QAAM,gBAAgB,oBAAoB,IAAI,kBAAkB;AAGhE,QAAM,SAAS,QAAQ;AAAA,IACrB,gBAAgB;AAAA,IAChB,QAAQ;AAAA,EACV,CAAC;AAED,QAAM,OAAO,SAAS,OAAO,mBAAmB,CAAC;AACjD,QAAM,OAAO,SAAS,OAAO,eAAe,CAAC;AAG7C,SAAO,IAAI,YAAY,CAAC,KAAK,QAAQ,IAAI,KAAK,GAAG,EAAE,KAAK,CAAC;AACzD,SAAO,IAAI,WAAW,CAAC,KAAK,QAAQ,IAAI,KAAK,GAAG,EAAE,KAAK,CAAC;AAGxD,SAAO,SAAS,mBAA8B;AAAA,IAC5C,QAAQ;AAAA,IACR,aAAa;AAAA,MACX,QAAQ,gBAAgB;AAAA,MACxB,eAAe,aAAa;AAAA,QAC1B;AAAA,QACA;AAAA,QACA,YAAY,IAAI;AAAA,MAClB;AAAA,IACF;AAAA,EACF,CAAC;AAED,QAAM,OAAO,OAAO,EAAE,MAAM,IAAI,MAAM,MAAM,IAAI,KAAK,CAAC;AACtD,UAAQ,IAAI,qCAAqC,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;AACzE,GAAG;","names":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/createAppRouter.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { initTRPC } from "@trpc/server";
|
|
4
|
+
import { formatEther, isHex } from "viem";
|
|
5
|
+
import { sendTransaction } from "@latticexyz/common";
|
|
6
|
+
|
|
7
|
+
// src/debug.ts
|
|
8
|
+
import createDebug from "debug";
|
|
9
|
+
var debug = createDebug("mud:faucet");
|
|
10
|
+
var error = createDebug("mud:faucet");
|
|
11
|
+
debug.log = console.debug.bind(console);
|
|
12
|
+
error.log = console.error.bind(console);
|
|
13
|
+
|
|
14
|
+
// src/createAppRouter.ts
|
|
15
|
+
function createAppRouter() {
|
|
16
|
+
const t = initTRPC.context().create();
|
|
17
|
+
return t.router({
|
|
18
|
+
drip: t.procedure.input(
|
|
19
|
+
z.object({
|
|
20
|
+
address: z.string().refine(isHex)
|
|
21
|
+
})
|
|
22
|
+
).mutation(async (opts) => {
|
|
23
|
+
const { client, faucetAccount, dripAmount } = opts.ctx;
|
|
24
|
+
const { address } = opts.input;
|
|
25
|
+
const tx = await sendTransaction(client, {
|
|
26
|
+
chain: null,
|
|
27
|
+
account: faucetAccount,
|
|
28
|
+
to: address,
|
|
29
|
+
value: dripAmount
|
|
30
|
+
});
|
|
31
|
+
debug(`Dripped ${formatEther(dripAmount)} ETH from ${faucetAccount.address} to ${address} (tx ${tx})`);
|
|
32
|
+
return tx;
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
createAppRouter
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=chunk-FX3HLBCB.js.map
|
|
@@ -1 +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 \"@latticexyz/common\";\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\");\nexport const error = createDebug(\"mud:faucet\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n"],"mappings":"AAAA,
|
|
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 \"@latticexyz/common\";\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\");\nexport const error = createDebug(\"mud:faucet\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n"],"mappings":";AAAA,SAAS,SAAS;AAClB,SAAS,gBAAgB;AACzB,SAAoC,aAAa,aAAa;AAC9D,SAAS,uBAAuB;;;ACHhC,OAAO,iBAAiB;AAEjB,IAAM,QAAQ,YAAY,YAAY;AACtC,IAAM,QAAQ,YAAY,YAAY;AAG7C,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO;AAGtC,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO;;;ADI/B,SAAS,kBAAkB;AAChC,QAAM,IAAI,SAAS,QAAoB,EAAE,OAAO;AAEhD,SAAO,EAAE,OAAO;AAAA,IACd,MAAM,EAAE,UACL;AAAA,MACC,EAAE,OAAO;AAAA,QACP,SAAS,EAAE,OAAO,EAAE,OAAO,KAAK;AAAA,MAClC,CAAC;AAAA,IACH,EACC,SAAS,OAAO,SAAuB;AACtC,YAAM,EAAE,QAAQ,eAAe,WAAW,IAAI,KAAK;AAEnD,YAAM,EAAE,QAAQ,IAAI,KAAK;AACzB,YAAM,KAAK,MAAM,gBAAgB,QAAQ;AAAA,QACvC,OAAO;AAAA,QACP,SAAS;AAAA,QACT,IAAI;AAAA,QACJ,OAAO;AAAA,MACT,CAAC;AAED,YAAM,WAAW,YAAY,UAAU,CAAC,aAAa,cAAc,OAAO,OAAO,OAAO,QAAQ,EAAE,GAAG;AAErG,aAAO;AAAA,IACT,CAAC;AAAA,EACL,CAAC;AACH;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
createAppRouter: () => createAppRouter,
|
|
34
|
+
createClient: () => createClient
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
|
|
38
|
+
// src/createAppRouter.ts
|
|
39
|
+
var import_zod = require("zod");
|
|
40
|
+
var import_server = require("@trpc/server");
|
|
41
|
+
var import_viem = require("viem");
|
|
42
|
+
var import_common = require("@latticexyz/common");
|
|
43
|
+
|
|
44
|
+
// src/debug.ts
|
|
45
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
46
|
+
var debug = (0, import_debug.default)("mud:faucet");
|
|
47
|
+
var error = (0, import_debug.default)("mud:faucet");
|
|
48
|
+
debug.log = console.debug.bind(console);
|
|
49
|
+
error.log = console.error.bind(console);
|
|
50
|
+
|
|
51
|
+
// src/createAppRouter.ts
|
|
52
|
+
function createAppRouter() {
|
|
53
|
+
const t = import_server.initTRPC.context().create();
|
|
54
|
+
return t.router({
|
|
55
|
+
drip: t.procedure.input(
|
|
56
|
+
import_zod.z.object({
|
|
57
|
+
address: import_zod.z.string().refine(import_viem.isHex)
|
|
58
|
+
})
|
|
59
|
+
).mutation(async (opts) => {
|
|
60
|
+
const { client, faucetAccount, dripAmount } = opts.ctx;
|
|
61
|
+
const { address } = opts.input;
|
|
62
|
+
const tx = await (0, import_common.sendTransaction)(client, {
|
|
63
|
+
chain: null,
|
|
64
|
+
account: faucetAccount,
|
|
65
|
+
to: address,
|
|
66
|
+
value: dripAmount
|
|
67
|
+
});
|
|
68
|
+
debug(`Dripped ${(0, import_viem.formatEther)(dripAmount)} ETH from ${faucetAccount.address} to ${address} (tx ${tx})`);
|
|
69
|
+
return tx;
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/createClient.ts
|
|
75
|
+
var import_client = require("@trpc/client");
|
|
76
|
+
function createClient({ url }) {
|
|
77
|
+
return (0, import_client.createTRPCProxyClient)({
|
|
78
|
+
links: [(0, import_client.httpBatchLink)({ url })]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
createAppRouter,
|
|
84
|
+
createClient
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/createAppRouter.ts","../src/debug.ts","../src/createClient.ts"],"sourcesContent":["export * from \"./createAppRouter\";\nexport * from \"./createClient\";\n","import { z } from \"zod\";\nimport { initTRPC } from \"@trpc/server\";\nimport { Client, Hex, LocalAccount, formatEther, isHex } from \"viem\";\nimport { sendTransaction } from \"@latticexyz/common\";\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\");\nexport const error = createDebug(\"mud:faucet\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAClB,oBAAyB;AACzB,kBAA8D;AAC9D,oBAAgC;;;ACHhC,mBAAwB;AAEjB,IAAM,YAAQ,aAAAA,SAAY,YAAY;AACtC,IAAM,YAAQ,aAAAA,SAAY,YAAY;AAG7C,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO;AAGtC,MAAM,MAAM,QAAQ,MAAM,KAAK,OAAO;;;ADI/B,SAAS,kBAAkB;AAChC,QAAM,IAAI,uBAAS,QAAoB,EAAE,OAAO;AAEhD,SAAO,EAAE,OAAO;AAAA,IACd,MAAM,EAAE,UACL;AAAA,MACC,aAAE,OAAO;AAAA,QACP,SAAS,aAAE,OAAO,EAAE,OAAO,iBAAK;AAAA,MAClC,CAAC;AAAA,IACH,EACC,SAAS,OAAO,SAAuB;AACtC,YAAM,EAAE,QAAQ,eAAe,WAAW,IAAI,KAAK;AAEnD,YAAM,EAAE,QAAQ,IAAI,KAAK;AACzB,YAAM,KAAK,UAAM,+BAAgB,QAAQ;AAAA,QACvC,OAAO;AAAA,QACP,SAAS;AAAA,QACT,IAAI;AAAA,QACJ,OAAO;AAAA,MACT,CAAC;AAED,YAAM,eAAW,yBAAY,UAAU,CAAC,aAAa,cAAc,OAAO,OAAO,OAAO,QAAQ,EAAE,GAAG;AAErG,aAAO;AAAA,IACT,CAAC;AAAA,EACL,CAAC;AACH;;;AEvCA,oBAA4E;AAgBrE,SAAS,aAAa,EAAE,IAAI,GAA0D;AAC3F,aAAO,qCAAiC;AAAA,IACtC,OAAO,KAAC,6BAAc,EAAE,IAAI,CAAC,CAAC;AAAA,EAChC,CAAC;AACH;","names":["createDebug"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as _trpc_server from '@trpc/server';
|
|
2
|
+
import { Client, LocalAccount } from 'viem';
|
|
3
|
+
import { CreateTRPCProxyClient } from '@trpc/client';
|
|
4
|
+
|
|
5
|
+
type AppContext = {
|
|
6
|
+
client: Client;
|
|
7
|
+
faucetAccount: LocalAccount<string>;
|
|
8
|
+
dripAmount: bigint;
|
|
9
|
+
};
|
|
10
|
+
declare function createAppRouter(): _trpc_server.CreateRouterInner<_trpc_server.RootConfig<{
|
|
11
|
+
ctx: AppContext;
|
|
12
|
+
meta: object;
|
|
13
|
+
errorShape: _trpc_server.DefaultErrorShape;
|
|
14
|
+
transformer: _trpc_server.DefaultDataTransformer;
|
|
15
|
+
}>, {
|
|
16
|
+
drip: _trpc_server.BuildProcedure<"mutation", {
|
|
17
|
+
_config: _trpc_server.RootConfig<{
|
|
18
|
+
ctx: AppContext;
|
|
19
|
+
meta: object;
|
|
20
|
+
errorShape: _trpc_server.DefaultErrorShape;
|
|
21
|
+
transformer: _trpc_server.DefaultDataTransformer;
|
|
22
|
+
}>;
|
|
23
|
+
_meta: object;
|
|
24
|
+
_ctx_out: AppContext;
|
|
25
|
+
_input_in: {
|
|
26
|
+
address: string;
|
|
27
|
+
};
|
|
28
|
+
_input_out: {
|
|
29
|
+
address: `0x${string}`;
|
|
30
|
+
};
|
|
31
|
+
_output_in: typeof _trpc_server.unsetMarker;
|
|
32
|
+
_output_out: typeof _trpc_server.unsetMarker;
|
|
33
|
+
}, `0x${string}`>;
|
|
34
|
+
}>;
|
|
35
|
+
type AppRouter = ReturnType<typeof createAppRouter>;
|
|
36
|
+
|
|
37
|
+
type CreateClientOptions = {
|
|
38
|
+
/**
|
|
39
|
+
* tRPC endpoint URL like `https://faucet.dev.linfra.xyz/trpc`.
|
|
40
|
+
*/
|
|
41
|
+
url: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Creates a tRPC client to talk to a MUD faucet.
|
|
45
|
+
*
|
|
46
|
+
* @param {CreateClientOptions} options See `CreateClientOptions`.
|
|
47
|
+
* @returns {CreateTRPCProxyClient<AppRouter>} A typed tRPC client.
|
|
48
|
+
*/
|
|
49
|
+
declare function createClient({ url }: CreateClientOptions): CreateTRPCProxyClient<AppRouter>;
|
|
50
|
+
|
|
51
|
+
export { type AppContext, type AppRouter, createAppRouter, createClient };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
createAppRouter
|
|
3
|
+
} from "./chunk-FX3HLBCB.js";
|
|
4
|
+
|
|
5
|
+
// src/createClient.ts
|
|
6
|
+
import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
|
|
7
|
+
function createClient({ url }) {
|
|
8
|
+
return createTRPCProxyClient({
|
|
9
|
+
links: [httpBatchLink({ url })]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
createAppRouter,
|
|
14
|
+
createClient
|
|
15
|
+
};
|
|
2
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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":"
|
|
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":";;;;;AAAA,SAAS,uBAAuB,qBAA4C;AAgBrE,SAAS,aAAa,EAAE,IAAI,GAA0D;AAC3F,SAAO,sBAAiC;AAAA,IACtC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AAAA,EAChC,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latticexyz/faucet",
|
|
3
|
-
"version": "2.2.18-
|
|
3
|
+
"version": "2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2",
|
|
4
4
|
"description": "Faucet API for Lattice testnet",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,7 +10,16 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"exports": {
|
|
13
|
-
".":
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"require": "./dist/index.cjs",
|
|
20
|
+
"types": "./dist/index.d.cts"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
14
23
|
},
|
|
15
24
|
"typesVersions": {
|
|
16
25
|
"*": {
|
|
@@ -35,7 +44,7 @@
|
|
|
35
44
|
"dotenv": "^16.0.3",
|
|
36
45
|
"fastify": "^4.21.0",
|
|
37
46
|
"zod": "3.23.8",
|
|
38
|
-
"@latticexyz/common": "2.2.18-
|
|
47
|
+
"@latticexyz/common": "2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2"
|
|
39
48
|
},
|
|
40
49
|
"devDependencies": {
|
|
41
50
|
"@types/debug": "^4.1.7",
|
package/dist/chunk-LVBDKFIB.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{z as u}from"zod";import{initTRPC as m}from"@trpc/server";import{formatEther as d,isHex as f}from"viem";import{sendTransaction as l}from"@latticexyz/common";import p from"debug";var t=p("mud:faucet"),s=p("mud:faucet");t.log=console.debug.bind(console);s.log=console.error.bind(console);function h(){let e=m.context().create();return e.router({drip:e.procedure.input(u.object({address:u.string().refine(f)})).mutation(async o=>{let{client:a,faucetAccount:r,dripAmount:n}=o.ctx,{address:c}=o.input,i=await l(a,{chain:null,account:r,to:c,value:n});return t(`Dripped ${d(n)} ETH from ${r.address} to ${c} (tx ${i})`),i})})}export{h as a};
|
|
2
|
-
//# sourceMappingURL=chunk-LVBDKFIB.js.map
|