Skip to content

Commit

Permalink
refactor: simplify types
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaaa committed May 21, 2024
1 parent 8aa75a7 commit b0d0313
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 51 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/commands/abigen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function abigenHandler(opts: Options) {

const systems = await getSystems({ client, worldDeploy });

systems.map(abigen);
systems.map((system) => abigen(system.functions.map((func) => func.systemFunctionSignature)));
}

export default commandModule;
54 changes: 4 additions & 50 deletions packages/world/ts/node/render-solidity/abigen.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,8 @@
import { Abi, Address, Hex } from "viem";
import { Abi } from "viem";

type DeterministicContract = {
readonly prepareDeploy: (
deployer: Address,
libraries: readonly Library[],
) => {
readonly address: Address;
readonly bytecode: Hex;
};
readonly deployedBytecodeSize: number;
readonly abi: Abi;
};

type Library = DeterministicContract & {
/**
* Path to library source file, e.g. `src/libraries/SomeLib.sol`
*/
path: string;
/**
* Library name, e.g. `SomeLib`
*/
name: string;
};

// map over each and decode signature
type WorldFunction = {
readonly signature: string;
readonly selector: Hex;
readonly systemId: Hex;
readonly systemFunctionSignature: string;
readonly systemFunctionSelector: Hex;
};

type System = DeterministicContract & {
readonly namespace: string;
readonly name: string;
readonly systemId: Hex;
readonly allowAll: boolean;
readonly allowedAddresses: readonly Hex[];
readonly allowedSystemIds: readonly Hex[];
readonly functions: readonly WorldFunction[];
};

type DeployedSystem = Omit<System, "abi" | "prepareDeploy" | "deployedBytecodeSize" | "allowedSystemIds"> & {
address: Address;
};

export function abigen(system: DeployedSystem): Abi {
const abi = system.functions.map((func) => {
const match = func.systemFunctionSignature.match(/^([a-zA-Z_]\w*)\((.*)\)$/);
export function abigen(systemFunctionSignatures: readonly string[]): Abi {
const abi = systemFunctionSignatures.map((systemFunctionSignature) => {
const match = systemFunctionSignature.match(/^([a-zA-Z_]\w*)\((.*)\)$/);
if (!match) {
throw new Error("Invalid signature");
}
Expand Down

0 comments on commit b0d0313

Please sign in to comment.