Skip to content

Commit

Permalink
Fix issue with using staticcall within pure functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vdrg committed Nov 19, 2024
1 parent cb03f03 commit 2c58bb3
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 1 deletion.

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

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

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

53 changes: 53 additions & 0 deletions e2e/packages/contracts/src/codegen/libraries/NumberSystemLib.sol

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

53 changes: 53 additions & 0 deletions e2e/packages/contracts/src/codegen/libraries/VectorSystemLib.sol

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

10 changes: 9 additions & 1 deletion packages/world/ts/node/render-solidity/renderSystemLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export function renderSystemLibrary(options: RenderSystemLibraryOptions) {
const camelCaseSystemLabel = systemLabel.charAt(0).toLowerCase() + systemLabel.slice(1);
const userTypeName = `${systemLabel}Type`;

// use view state mutability for pure functions (otherwise we can't use staticcall)
// TODO: a better alternative would be to actually just copy the pure function's code,
// as it is not really necessary to call the system
const functionsToRender = functions.map((fn) => ({
...fn,
stateMutability: fn.stateMutability === "pure" ? "view" : fn.stateMutability,
}));

return `
${renderedSolidityHeader}
Expand All @@ -65,7 +73,7 @@ export function renderSystemLibrary(options: RenderSystemLibraryOptions) {
${renderList(errors, ({ name, parameters }) => `error ${name}(${renderArguments(parameters)});`)}
${renderList(functions, (fn) => renderFunction(systemLabel, userTypeName, fn))}
${renderList(functionsToRender, (fn) => renderFunction(systemLabel, userTypeName, fn))}
// TODO: rename to callFrom?
function from(${userTypeName} systemId, address _from) internal pure returns (CallFromWrapper memory) {
Expand Down

0 comments on commit 2c58bb3

Please sign in to comment.