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

begin integrating MUD entrypoint #62

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
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
@@ -1 +1,2 @@
.DS_Store
mprocs.log
1 change: 0 additions & 1 deletion smart-gate/mprocs.log

This file was deleted.

7 changes: 7 additions & 0 deletions smart-storage-unit/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DEBUG=mud:*

VITE_CHAIN_ID=31337
RPC_URL=http://127.0.0.1:8545

# Anvil default account (0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc)
PRIVATE_KEY=0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba
15 changes: 15 additions & 0 deletions smart-storage-unit/mprocs.local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
procs:
client:
# Linking packages with `link:` causes issues with common dependencies like React and Wagmi.
# So instead, we're using `file:` for these.
#
# But installing packages with `file:` means Vite doesn't detect file changes.
# So we have to manually restart Vite when we want to rebuild, but we also have to
# skip the cache with `--force`. Not great, but this is the best we've got for now.
shell: pnpm nodemon --exec "vite --force" --watch "../mud"
contracts:
shell: pnpm mud dev-contracts --rpc ${RPC_URL}
anvil:
shell: anvil --load-state anvil-state.json
explorer:
shell: pnpm explorer --chainId=$VITE_CHAIN_ID
1 change: 0 additions & 1 deletion smart-storage-unit/mprocs.log

This file was deleted.

19 changes: 16 additions & 3 deletions smart-storage-unit/mprocs.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
procs:
client:
cwd: packages/client
shell: pnpm run dev
shell: pnpm nodemon --exec "vite --force" --watch "../mud"
anvil:
# Forks the Docker instance of Anvil running at :8546
cwd: packages/contracts
shell: anvil --base-fee 0 --block-time 2 --fork-url http://127.0.0.1:8546
contracts:
cwd: packages/contracts
shell: pnpm mud dev-contracts --rpc http://127.0.0.1:8545 --worldAddress 0x8a791620dd6260079bf849dc5567adc3f2fdc318
shell: pnpm mud dev-contracts --rpc http://127.0.0.1:8546 --worldAddress 0x8a791620dd6260079bf849dc5567adc3f2fdc318
explorer:
cwd: packages/contracts
shell: pnpm explorer
shell: pnpm explorer
deploy-factory:
cwd: ../coinbase-smart-wallet
shell: make deploy-local
deploy-bundler:
cwd: ../alto
shell: pnpm ts-node scripts/localDeployer/index.ts
deploy-paymaster:
cwd: ../quarry-paymaster/packages/contracts
shell: pnpm mud deploy --salt 0x && pnpm fund:paymaster:local && pnpm fund:issuer:local
env:
# Anvil default account (0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266)
PRIVATE_KEY: "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
3 changes: 1 addition & 2 deletions smart-storage-unit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"scripts": {
"build": "pnpm recursive run build",
"dev": "mprocs",
"dev:client": "pnpm --filter 'client' run dev",
"dev:contracts": "pnpm --filter 'contracts' dev",
"dev:local": "env $(grep -v '#' .env | xargs) mprocs --config mprocs.local.yaml",
"foundry:up": "curl -L https://foundry.paradigm.xyz | bash && bash $HOME/.foundry/bin/foundryup",
"prepare": "(forge --version || pnpm foundry:up)",
"test": "pnpm recursive run test"
Expand Down
8 changes: 8 additions & 0 deletions smart-storage-unit/packages/client/.env
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
VITE_CHAIN_ID=31337

#ITEM OUT FOR SELLING : LENS
VITE_ITEM_OUT_ID=112603025077760770783264636189502217226733230421932850697496331082050661822826
#ITEM IN FOR BUYING : SALT
VITE_ITEM_IN_ID=70505200487489129491533272716910408603753256595363780714882065332876101173161

#SMART ASSEMBLY ID
VITE_SMARTASSEMBLY_ID=17614304337475056394242299294383532840873792487945557467064313427436901763824
11 changes: 11 additions & 0 deletions smart-storage-unit/packages/client/alto.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"entrypoints": "0x0000000071727De22E5E9d8BAf0edAc6f37da032,0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"executor-private-keys": "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6",
"utility-private-key": "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6",
"rpc-url": "http://127.0.0.1:8545",
"port": 4337,
"safe-mode": false,
"enable-instant-bundling-endpoint": true,
"min-executor-balance": "10000000000000000",
"polling-interval": 100
}
23 changes: 10 additions & 13 deletions smart-storage-unit/packages/client/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>a minimal MUD client</title>
</head>

<body>
<div id="react-root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>

</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>a minimal MUD client</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/mount.tsx"></script>
</body>
</html>
42 changes: 29 additions & 13 deletions smart-storage-unit/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,47 @@
"type": "module",
"scripts": {
"build": "vite build",
"dev": "wait-port localhost:8545 && vite",
"dev": "vite",
"preview": "vite preview",
"test": "tsc --noEmit"
},
"dependencies": {
"@latticexyz/common": "2.2.14",
"@latticexyz/dev-tools": "2.2.14",
"@latticexyz/react": "2.2.14",
"@latticexyz/schema-type": "2.2.14",
"@latticexyz/store-sync": "2.2.14",
"@latticexyz/utils": "2.2.14",
"@latticexyz/world": "2.2.14",
"@eveworld/types": "^0.0.5",
"@eveworld/ui-components": "^0.0.6",
"@eveworld/utils": "^0.0.5",
"@latticexyz/common": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@latticexyz/config": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@latticexyz/entrykit": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@latticexyz/explorer": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@latticexyz/protocol-parser": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@latticexyz/schema-type": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@latticexyz/stash": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@latticexyz/store": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@latticexyz/store-sync": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@latticexyz/world": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@latticexyz/world-modules": "2.2.15-entrykit-1c24e4739090d185171d9f8e4a257735e4710b70",
"@tanstack/react-query": "^5.56.2",
"fast-deep-equal": "^3.1.3",
"nodemon": "^3.1.7",
"contracts": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rxjs": "7.5.5",
"viem": "2.21.6"
"tailwindcss": "^3.4.12",
"tailwind-merge": "^2.5.2",
"viem": "2.21.19",
"wagmi": "2.12.11"
},
"devDependencies": {
"@types/react": "18.2.22",
"@types/react-dom": "18.2.7",
"@vitejs/plugin-react": "^3.1.0",
"autoprefixer": "^10.4.20",
"eslint-plugin-react": "7.31.11",
"eslint-plugin-react-hooks": "4.6.0",
"vite": "^4.2.1",
"wait-port": "^1.0.4"
"postcss": "^8.4.47",
"vite": "^4.5.5",
"vite-plugin-svgr": "3.3.0",
"wait-port": "^1.1.0"
}
}
6 changes: 6 additions & 0 deletions smart-storage-unit/packages/client/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
76 changes: 56 additions & 20 deletions smart-storage-unit/packages/client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
import { useMUD } from "./MUDContext";

const styleUnset = { all: "unset" } as const;

export const App = () => {
const {
network: { tables, useStore },
systemCalls: { addTask, toggleTask, deleteTask },
} = useMUD();

const tasks = useStore((state) => {
const records = Object.values(state.getRecords(tables.Tasks));
records.sort((a, b) => Number(a.value.createdAt - b.value.createdAt));
return records;
});

return (
<>
</>
);
import { AccountButton, useSessionClient } from "@latticexyz/entrykit/internal";
import { useSyncProgress } from "./mud/useSyncProgress";
import { Explorer } from "./Explorer";
import { ReactNode } from "react";
import { Header, EveButton } from "@eveworld/ui-components";
import { abbreviateAddress } from "@eveworld/utils";
import SetRatio from "./components/SetRatio";
import Execute from "./components/Execute";
import { WalletClient } from "viem";
import { SmartCharacter } from "@eveworld/types";

export type Props = {
children?: ReactNode;
};

export function App({ children }: Props) {
const { isLive, message, percentage } = useSyncProgress();

const { data: sessionClient } = useSessionClient();

return (
<div className="bg-crude-5 w-screen min-h-screen">
<div className="flex flex-col align-center max-w-[560px] mx-auto pb-6 min-h-screen h-full">
<Header
connected={isLive}
// eslint-disable-next-line @typescript-eslint/no-empty-function
handleDisconnect={() => {}}
walletClient={sessionClient as unknown as WalletClient}
smartCharacter={undefined as unknown as SmartCharacter}
/>

<AccountButton />

{isLive ? (
<div className="grid">
<div className="text-xl font-bold">
Smart Assembly:{" "}
{abbreviateAddress(import.meta.env.VITE_SMARTASSEMBLY_ID)}
</div>
<div className="text-xs">
Change this smart assembly ID in the .env file
</div>

<SetRatio />
<Execute />
</div>
) : (
<div className="tabular-nums">
{message} ({percentage.toFixed(1)}%)…
</div>
)}
</div>

<Explorer />
</div>
);
}
26 changes: 26 additions & 0 deletions smart-storage-unit/packages/client/src/Explorer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEntryKitConfig } from "@latticexyz/entrykit/internal";
import { useState } from "react";
import { twMerge } from "tailwind-merge";

export function Explorer() {
const [open, setOpen] = useState(false);
const { chain, worldAddress } = useEntryKitConfig();
const explorerUrl = chain.blockExplorers?.worldsExplorer?.url;
if (!explorerUrl) return null;

return (
<div className="fixed bottom-0 inset-x-0 flex flex-col opacity-80 transition hover:opacity-100">
<button
type="button"
onClick={() => setOpen(!open)}
className="outline-none text-right p-2 leading-none text-white"
>
{open ? "Close" : "Explore"}
</button>
<iframe
src={`${explorerUrl}/${worldAddress}`}
className={twMerge("transition-all", open ? "h-[50vh]" : "h-0")}
/>
</div>
);
}
21 changes: 0 additions & 21 deletions smart-storage-unit/packages/client/src/MUDContext.tsx

This file was deleted.

9 changes: 9 additions & 0 deletions smart-storage-unit/packages/client/src/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import worldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";

export const chainId = parseInt(import.meta.env.VITE_CHAIN_ID) || 31337;
export const url = new URL(window.location.href);

// export const directions = ["North", "East", "South", "West"] as const;
// export type Direction = (typeof directions)[number];

export { worldAbi };
55 changes: 55 additions & 0 deletions smart-storage-unit/packages/client/src/components/Execute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { useRef } from "react";
import { EveButton, EveInput } from "@eveworld/ui-components";
import { createSystemCalls } from "../mud/createSystemCalls";

const Execute = React.memo(function Execute() {
const { execute, calculateOutput } = createSystemCalls();

const handleEdit = (
refString: React.MutableRefObject<number>,
eventString: number
): void => {
refString.current = eventString;
};

const qtyInValueRef = useRef(0);

return (
<>
<div className="Quantum-Container my-4">
<div>Step 2: Execute transaction</div>

<EveInput
inputType="numerical"
defaultValue={qtyInValueRef.current.toString()}
fieldName={`Quantity In`}
onChange={(str) => handleEdit(qtyInValueRef, str as number)}
></EveInput>

<EveButton
className="mr-2"
typeClass="tertiary"
onClick={async (event) => {
event.preventDefault();
calculateOutput(qtyInValueRef.current);
}}
>
Calculate Output
</EveButton>

<EveButton
className="mr-2 mt-4"
typeClass="primary"
onClick={async (event) => {
event.preventDefault();
execute(qtyInValueRef.current);
}}
>
Execute
</EveButton>
</div>
</>
);
});

export default Execute;
Loading