Skip to content

Commit

Permalink
Merge branch 'main' into alvrs/splice-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Sep 19, 2023
2 parents ce03439 + b554071 commit ec9b7fc
Show file tree
Hide file tree
Showing 35 changed files with 260 additions and 237 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-seals-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/dev-tools": minor
---

Improved rendering of transactions that make calls via World's `call` and `callFrom` methods
5 changes: 5 additions & 0 deletions .changeset/thin-rice-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-indexer": patch
---

Added README and refactored handling of common environment variables
5 changes: 5 additions & 0 deletions .changeset/twelve-monkeys-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/faucet": patch
---

Added README
4 changes: 2 additions & 2 deletions examples/minimal/packages/client-phaser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"zustand": "^4.3.8"
},
"devDependencies": {
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@types/react": "18.2.22",
"@types/react-dom": "18.2.7",
"@types/styled-components": "^5.1.26",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.46.1",
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal/packages/client-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"viem": "1.6.0"
},
"devDependencies": {
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@types/react": "18.2.22",
"@types/react-dom": "18.2.7",
"@vitejs/plugin-react": "^3.1.0",
"eslint-plugin-react": "7.31.11",
"eslint-plugin-react-hooks": "4.6.0",
Expand Down
30 changes: 15 additions & 15 deletions examples/minimal/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions packages/cli/contracts/src/codegen/Tables.sol

This file was deleted.

13 changes: 0 additions & 13 deletions packages/cli/contracts/src/codegen/Types.sol

This file was deleted.

4 changes: 2 additions & 2 deletions packages/dev-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"zustand": "^4.3.7"
},
"devDependencies": {
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@types/react": "18.2.22",
"@types/react-dom": "18.2.7",
"@types/ws": "^8.5.4",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.23",
Expand Down
18 changes: 16 additions & 2 deletions packages/dev-tools/src/actions/WriteSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decodeEventLog, AbiEventSignatureNotFoundError } from "viem";
import { decodeEventLog, AbiEventSignatureNotFoundError, decodeFunctionData, Hex } from "viem";
import { twMerge } from "tailwind-merge";
import { isDefined } from "@latticexyz/common/utils";
import { PendingIcon } from "../icons/PendingIcon";
Expand Down Expand Up @@ -56,6 +56,17 @@ export function WriteSummary({ write }: Props) {
.filter(isDefined)
: null;

let functionName = write.request.functionName;
let functionArgs = write.request.args;
if (functionName === "call" || functionName === "callFrom") {
const functionSelectorAndArgs: Hex = write.request?.args?.length
? (write.request.args[write.request.args.length - 1] as Hex)
: `0x`;
const functionData = decodeFunctionData({ abi: worldAbi, data: functionSelectorAndArgs });
functionName = functionData.functionName;
functionArgs = functionData.args;
}

return (
<details
onToggle={(event) => {
Expand All @@ -73,7 +84,10 @@ export function WriteSummary({ write }: Props) {
)}
>
<div className="flex-1 font-mono text-white whitespace-nowrap overflow-hidden text-ellipsis">
{write.request.functionName}({write.request.args?.map((value) => serialize(value)).join(", ")})
{functionName}({functionArgs?.map((value) => serialize(value)).join(", ")}){" "}
{write.request.functionName !== functionName ? (
<span className="text-xs text-white/40">via {write.request.functionName}</span>
) : null}
</div>
{transactionReceipt.status === "fulfilled" ? (
<a
Expand Down
30 changes: 30 additions & 0 deletions packages/faucet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# faucet

A minimal Typescript faucet to drip native tokens on Ethereum chains

## Usage

Install and run with:

```sh
npm install @latticexyz/faucet@next
npm faucet-server
```

or execute the package bin directly:

```sh
npx @latticexyz/faucet@next
```

## Configuration

The faucet can configured with the following environment variables:

| Variable | Description | Default |
| -------------------- | ----------------------------------------------------- | --------- |
| `HOST` | Host that the indexer server listens on | `0.0.0.0` |
| `PORT` | Port that the indexer server listens on | `3001` |
| `RPC_HTTP_URL` | HTTP URL for Ethereum RPC | |
| `FAUCET_PRIVATE_KEY` | Private key of wallet to distribute faucet funds from | |
| `DRIP_AMOUNT_ETHER` | Drip amount in ether |
4 changes: 1 addition & 3 deletions packages/faucet/bin/faucet-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import "dotenv/config";
import { z } from "zod";
import fastify from "fastify";
import { fastifyTRPCPlugin } from "@trpc/server/adapters/fastify";
import { ClientConfig, http, parseEther, isHex, createClient } from "viem";
import { http, parseEther, isHex, createClient } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { AppRouter, createAppRouter } from "../src/createAppRouter";
import { getChainId } from "viem/actions";

// TODO: refine zod type to be either CHAIN_ID or RPC_HTTP_URL/RPC_WS_URL
const env = z
.object({
HOST: z.string().default("0.0.0.0"),
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"@testing-library/react-hooks": "^8.0.1",
"@types/react": "^18.2.6",
"@types/react": "18.2.22",
"@vitejs/plugin-react": "^4.0.0",
"eslint-plugin-react": "7.31.11",
"eslint-plugin-react-hooks": "4.6.0",
Expand Down
53 changes: 53 additions & 0 deletions packages/store-indexer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# store-indexer

A minimal Typescript indexer for [MUD Store](https://mud.dev/store) events (built on [store-sync](https://npmjs.com/package/@latticexyz/store-sync))

## Usage

Install and run with:

```sh
npm install @latticexyz/store-indexer

npm sqlite-indexer
# or
npm postgres-indexer
```

or execute the one of the package bins directly:

```sh
npx -p @latticexyz/store-indexer sqlite-indexer
# or
npx -p @latticexyz/store-indexer postgres-indexer
```

## Configuration

Each indexer can be configured with environment variables.

### Common environment variables

| Variable | Description | Default |
| ------------------ | ---------------------------------------------------------- | --------- |
| `HOST` | Host that the indexer server listens on | `0.0.0.0` |
| `PORT` | Port that the indexer server listens on | `3001` |
| `RPC_HTTP_URL` | HTTP URL for Ethereum RPC to fetch data from | |
| `RPC_WS_URL` | WebSocket URL for Ethereum RPC to fetch data from | |
| `START_BLOCK` | Block number to start indexing from | `0` |
| `MAX_BLOCK_RANGE` | Maximum number of blocks to fetch from the RPC per request | `1000` |
| `POLLING_INTERVAL` | How often to poll for new blocks (in milliseconds) | `1000` |

Note that you only need one of `RPC_HTTP_URL` or `RPC_WS_URL`, but we recommend both. The WebSocket URL will be prioritized and fall back to the HTTP URL if there are any connection issues.

### Postgres indexer environment variables

| Variable | Description | Default |
| -------------- | ----------------------- | ------- |
| `DATABASE_URL` | Postgres connection URL | |

### SQLite indexer environment variables

| Variable | Description | Default |
| ----------------- | ------------------------ | ------------ |
| `SQLITE_FILENAME` | SQLite database filename | `indexer.db` |
30 changes: 30 additions & 0 deletions packages/store-indexer/bin/parseEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { isDefined } from "@latticexyz/common/utils";
import { z, ZodIntersection, ZodTypeAny } from "zod";

const commonSchema = z.intersection(
z.object({
HOST: z.string().default("0.0.0.0"),
PORT: z.coerce.number().positive().default(3001),
START_BLOCK: z.coerce.bigint().nonnegative().default(0n),
MAX_BLOCK_RANGE: z.coerce.bigint().positive().default(1000n),
POLLING_INTERVAL: z.coerce.number().positive().default(1000),
}),
z
.object({
RPC_HTTP_URL: z.string(),
RPC_WS_URL: z.string(),
})
.partial()
.refine((values) => Object.values(values).some(isDefined))
);

export function parseEnv<TSchema extends ZodTypeAny | undefined = undefined>(
schema?: TSchema
): z.infer<TSchema extends ZodTypeAny ? ZodIntersection<typeof commonSchema, TSchema> : typeof commonSchema> {
const envSchema = schema !== undefined ? z.intersection(commonSchema, schema) : commonSchema;
return envSchema.parse(process.env, {
errorMap: (issue) => ({
message: `Missing or invalid environment variable: ${issue.path.join(".")}`,
}),
});
}
29 changes: 6 additions & 23 deletions packages/store-indexer/bin/postgres-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,13 @@ import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import { cleanDatabase, postgresStorage, schemaVersion } from "@latticexyz/store-sync/postgres";
import { createStoreSync } from "@latticexyz/store-sync";
import { parseEnv } from "./parseEnv";

const env = z
.intersection(
z.object({
HOST: z.string().default("0.0.0.0"),
PORT: z.coerce.number().positive().default(3001),
DATABASE_URL: z.string(),
START_BLOCK: z.coerce.bigint().nonnegative().default(0n),
MAX_BLOCK_RANGE: z.coerce.bigint().positive().default(1000n),
POLLING_INTERVAL: z.coerce.number().positive().default(1000),
}),
z
.object({
RPC_HTTP_URL: z.string(),
RPC_WS_URL: z.string(),
})
.partial()
.refine((values) => Object.values(values).some(isDefined))
)
.parse(process.env, {
errorMap: (issue) => ({
message: `Missing or invalid environment variable: ${issue.path.join(".")}`,
}),
});
const env = parseEnv(
z.object({
DATABASE_URL: z.string(),
})
);

const transports: Transport[] = [
// prefer WS when specified
Expand Down
29 changes: 6 additions & 23 deletions packages/store-indexer/bin/sqlite-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,13 @@ import { chainState, schemaVersion, syncToSqlite } from "@latticexyz/store-sync/
import { createQueryAdapter } from "../src/sqlite/createQueryAdapter";
import { isDefined } from "@latticexyz/common/utils";
import { combineLatest, filter, first } from "rxjs";
import { parseEnv } from "./parseEnv";

const env = z
.intersection(
z.object({
HOST: z.string().default("0.0.0.0"),
PORT: z.coerce.number().positive().default(3001),
SQLITE_FILENAME: z.string().default("indexer.db"),
START_BLOCK: z.coerce.bigint().nonnegative().default(0n),
MAX_BLOCK_RANGE: z.coerce.bigint().positive().default(1000n),
POLLING_INTERVAL: z.coerce.number().positive().default(1000),
}),
z
.object({
RPC_HTTP_URL: z.string(),
RPC_WS_URL: z.string(),
})
.partial()
.refine((values) => Object.values(values).some(isDefined))
)
.parse(process.env, {
errorMap: (issue) => ({
message: `Missing or invalid environment variable: ${issue.path.join(".")}`,
}),
});
const env = parseEnv(
z.object({
SQLITE_FILENAME: z.string().default("indexer.db"),
})
);

const transports: Transport[] = [
// prefer WS when specified
Expand Down
Loading

0 comments on commit ec9b7fc

Please sign in to comment.