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

feat(modules): standalone erc20 with own store #3070

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5ea8fbb
create sol files for erc20
TamaraRingas Aug 27, 2024
b72c749
Merge branch 'main' of https://github.com/latticexyz/mud into tr/erc2…
TamaraRingas Aug 27, 2024
35a50e5
add errors interface
TamaraRingas Aug 27, 2024
fc51ac3
add events interface
TamaraRingas Aug 27, 2024
65fcbc0
move interfaces to separate directory
TamaraRingas Aug 27, 2024
54d86f1
update comments
TamaraRingas Aug 27, 2024
c4b6ba4
create new package
TamaraRingas Aug 27, 2024
a9e6fdd
update README
TamaraRingas Aug 27, 2024
32950eb
update README
TamaraRingas Aug 27, 2024
64ef67a
rm old test file
TamaraRingas Aug 27, 2024
ecb042b
update package.json
TamaraRingas Aug 27, 2024
66f8e76
rm old changelog
TamaraRingas Aug 27, 2024
a479aae
update package.json
TamaraRingas Aug 27, 2024
752c0e4
undo prev commit
TamaraRingas Aug 27, 2024
2d4e264
mv changelog to correct directory
TamaraRingas Aug 27, 2024
b44c3ab
add mud config
TamaraRingas Aug 27, 2024
81b5a5f
update config
TamaraRingas Aug 27, 2024
5ac39db
rm gas-report.json
TamaraRingas Aug 27, 2024
3048dbe
update lockfile
TamaraRingas Aug 27, 2024
6ec5cce
update .gitignore
TamaraRingas Aug 27, 2024
ec94712
move interfaces into root of src directory
TamaraRingas Aug 28, 2024
9bce23f
add world/ to .gitignore
TamaraRingas Aug 28, 2024
2d15c54
rename MUDERC20 table to Token
TamaraRingas Aug 28, 2024
dea487a
remove dynamicId implementation & set vars in constructor
TamaraRingas Aug 28, 2024
19c29ab
remove dynamicId implementation & set vars in constructor
TamaraRingas Aug 28, 2024
af1c568
tablegen
TamaraRingas Aug 28, 2024
5de4e04
add view functions
TamaraRingas Aug 28, 2024
a4adf6f
update natspec
TamaraRingas Aug 28, 2024
6a6e22b
make Token a singleton table
TamaraRingas Aug 28, 2024
c0441ce
update getters to use a singleton table
TamaraRingas Aug 28, 2024
e0a1fff
update lockfile
TamaraRingas Aug 28, 2024
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
5 changes: 0 additions & 5 deletions .changeset/clean-worms-walk.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/ten-foxes-shave.md

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/changeset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Changeset

on:
pull_request:
paths:
- ".changeset/*.md"

jobs:
changeset:
Expand Down
15 changes: 4 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,15 @@ yarn.lock
lerna-debug.log
yarn-error.log
.turbo
.attest
.tstrace

.env*

# We don't want projects created from templates to ignore their lockfiles, but we don't
# want to check them in here, so we'll ignore them from the root.
templates/*/pnpm-lock.yaml

# mud test data
.env

test-data/world-logs-bulk-*.json
test-data/world-logs-query.json

# mud artifacts
.mud

# sqlite indexer data
*.db
*.db-journal
.attest
.tstrace
2 changes: 2 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
*.db
*.db-journal
7 changes: 1 addition & 6 deletions examples/local-explorer/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
indexer.db
node_modules

# mud artifacts
.mud
# sqlite indexer data
*.db
*.db-journal
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build": "turbo run build",
"changelog:generate": "bun scripts/changelog.ts",
"clean": "turbo run clean",
"dev": "TSUP_SKIP_DTS=true turbo run dev --concurrency 100 --filter=!@latticexyz/explorer",
"dev": "TSUP_SKIP_DTS=true turbo run dev --concurrency 100",
"dist-tag-rm": "pnpm recursive exec -- sh -c 'npm dist-tag rm $(cat package.json | jq -r \".name\") $TAG || true'",
"docs:generate:api": "bun scripts/render-api-docs.ts",
"foundryup": "curl -L https://foundry.paradigm.xyz | bash && bash ~/.foundry/bin/foundryup",
Expand Down
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"test:ci": "pnpm run test"
},
"dependencies": {
"@ark/util": "catalog:",
"@aws-sdk/client-kms": "^3.556.0",
"@latticexyz/abi-ts": "workspace:*",
"@latticexyz/common": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tablegen } from "@latticexyz/store/codegen";
import { buildSystemsManifest, worldgen } from "@latticexyz/world/node";
import { worldgen } from "@latticexyz/world/node";
import { World as WorldConfig } from "@latticexyz/world";
import { forge } from "@latticexyz/common/foundry";
import { execa } from "execa";
Expand All @@ -21,7 +21,7 @@ export async function build({
foundryProfile = process.env.FOUNDRY_PROFILE,
}: BuildOptions): Promise<void> {
await Promise.all([tablegen({ rootDir, config }), worldgen({ rootDir, config })]);

await forge(["build"], { profile: foundryProfile });
await buildSystemsManifest({ rootDir, config });
await execa("mud", ["abi-ts"], { stdio: "inherit" });
}
6 changes: 1 addition & 5 deletions packages/cli/src/deploy/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,12 @@ export type System = DeterministicContract & {
readonly allowedAddresses: readonly Hex[];
readonly allowedSystemIds: readonly Hex[];
// world registration
// TODO: replace this with system manifest data
readonly worldFunctions: readonly WorldFunction[];
// human readable ABIs to register onchain
readonly abi: readonly string[];
readonly worldAbi: readonly string[];
};

export type DeployedSystem = Omit<
System,
"label" | "namespaceLabel" | "abi" | "worldAbi" | "prepareDeploy" | "deployedBytecodeSize" | "allowedSystemIds"
"label" | "namespaceLabel" | "abi" | "prepareDeploy" | "deployedBytecodeSize" | "allowedSystemIds"
> & {
address: Address;
};
Expand Down
25 changes: 10 additions & 15 deletions packages/cli/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, Address, Chain, Client, Hex, Transport, stringToHex } from "viem";
import { Account, Address, Chain, Client, Hex, Transport } from "viem";
import { ensureDeployer } from "./ensureDeployer";
import { deployWorld } from "./deployWorld";
import { ensureTables } from "./ensureTables";
Expand All @@ -15,7 +15,7 @@ import { ensureContractsDeployed } from "./ensureContractsDeployed";
import { randomBytes } from "crypto";
import { ensureWorldFactory } from "./ensureWorldFactory";
import { Table } from "@latticexyz/config";
import { ensureResourceTags } from "./ensureResourceTags";
import { ensureResourceLabels } from "./ensureResourceLabels";

type DeployOptions = {
client: Client<Transport, Chain | undefined, Account>;
Expand Down Expand Up @@ -90,10 +90,14 @@ export async function deploy({
throw new Error(`Unsupported World version: ${worldDeploy.worldVersion}`);
}

const resources = [
...tables.map((table) => ({ resourceId: table.tableId, label: table.label })),
...systems.map((system) => ({ resourceId: system.systemId, label: system.label })),
];
const namespaceTxs = await ensureNamespaceOwner({
client,
worldDeploy,
resourceIds: [...tables.map(({ tableId }) => tableId), ...systems.map(({ systemId }) => systemId)],
resourceIds: resources.map(({ resourceId }) => resourceId),
});

debug("waiting for all namespace registration transactions to confirm");
Expand Down Expand Up @@ -125,22 +129,13 @@ export async function deploy({
worldDeploy,
modules,
});

const tableTags = tables.map(({ tableId: resourceId, label }) => ({ resourceId, tag: "label", value: label }));
const systemTags = systems.flatMap(({ systemId: resourceId, label, abi, worldAbi }) => [
{ resourceId, tag: "label", value: label },
{ resourceId, tag: "abi", value: abi.join("\n") },
{ resourceId, tag: "worldAbi", value: worldAbi.join("\n") },
]);

const tagTxs = await ensureResourceTags({
const labelTxs = await ensureResourceLabels({
client,
worldDeploy,
tags: [...tableTags, ...systemTags],
valueToHex: stringToHex,
resources,
});

const txs = [...tableTxs, ...systemTxs, ...functionTxs, ...moduleTxs, ...tagTxs];
const txs = [...tableTxs, ...systemTxs, ...functionTxs, ...moduleTxs, ...labelTxs];

// wait for each tx separately/serially, because parallelizing results in RPC errors
debug("waiting for all transactions to confirm");
Expand Down
66 changes: 66 additions & 0 deletions packages/cli/src/deploy/ensureResourceLabels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Hex, Client, Transport, Chain, Account, stringToHex, BaseError, hexToString } from "viem";
import { WorldDeploy } from "./common";
import { debug } from "./debug";
import { hexToResource, writeContract } from "@latticexyz/common";
import { isDefined } from "@latticexyz/common/utils";
import metadataConfig from "@latticexyz/world-module-metadata/mud.config";
import metadataAbi from "@latticexyz/world-module-metadata/out/IMetadataSystem.sol/IMetadataSystem.abi.json" assert { type: "json" };
import { getTableValue } from "./getTableValue";

type LabeledResource = {
readonly resourceId: Hex;
readonly label: string;
};

export async function ensureResourceLabels({
client,
worldDeploy,
resources,
}: {
readonly client: Client<Transport, Chain | undefined, Account>;
readonly worldDeploy: WorldDeploy;
readonly resources: readonly LabeledResource[];
}): Promise<readonly Hex[]> {
const currentLabels = await Promise.all(
resources.map(async (resource) => {
const { value } = await getTableValue({
client,
worldDeploy,
table: metadataConfig.tables.metadata__ResourceTag,
key: { resource: resource.resourceId, tag: stringToHex("label", { size: 32 }) },
});
return hexToString(value);
}),
);

const resourcesToSet = resources.filter((resource, i) => resource.label !== currentLabels[i]);
if (resourcesToSet.length === 0) {
return [];
}

debug("setting", resources.length, "resource labels");
return (
await Promise.all(
resourcesToSet.map(async ({ resourceId, label }) => {
const resource = hexToResource(resourceId);
// TODO: move to resourceToDebugString
const resourceString = `${resource.type}:${resource.namespace}:${resource.name}`;
debug(`setting resource label for ${resourceString} to ${label}`);
try {
return await writeContract(client, {
chain: client.chain ?? null,
address: worldDeploy.address,
abi: metadataAbi,
// TODO: replace with batchCall (https://github.com/latticexyz/mud/issues/1645)
functionName: "metadata__setResourceTag",
args: [resourceId, stringToHex("label", { size: 32 }), stringToHex(label)],
});
} catch (error) {
debug(
`failed to set resource label for ${resourceString}, skipping\n ${error instanceof BaseError ? error.shortMessage : error}`,
);
}
}),
)
).filter(isDefined);
}
70 changes: 0 additions & 70 deletions packages/cli/src/deploy/ensureResourceTags.ts

This file was deleted.

46 changes: 0 additions & 46 deletions packages/cli/src/deploy/getRecord.ts

This file was deleted.

Loading
Loading