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/factory supports parameter within struct #1343

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Jds-23
Copy link

@Jds-23 Jds-23 commented Dec 16, 2024

[Not Complete Yet]
@typedarray

Copy link
Collaborator

@typedarray typedarray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start, left some in-progress comments

@@ -6,6 +6,21 @@ const llamaFactoryEventAbiItem = parseAbiItem(
"event LlamaInstanceCreated(address indexed deployer, string indexed name, address llamaCore, address llamaExecutor, address llamaPolicy, uint256 chainId)",
);

const FactoryEventSimpleParamsAbiItem = parseAbiItem([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think you need to use parseAbi here because there are multiple items
  2. We use camelCase for most identifiers

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. In case of function/event with struct, parseAbiItem can be used https://viem.sh/docs/abi/parseAbiItem#parameters . As parseAbiItem was already in use, I preferred to stick to it.
  2. Refactored, camelCase all the way. 🫡

Comment on lines +18 to +23
const parameterParts = parameter.split(".");

let offset = 0;

parameter = parameterParts[0]!;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an explicit validation check that this exists, like if (parameter === undefined) throw new Error(...) like on line 53.

Also, I think these lines should be below where we build the address and eventSelector.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the check, but I think these lines should be before building the address and eventSelector. As there's the possibility of parameter being undefined, the building of the address and eventSelector will be unnecessary. 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, we just generally try to group concerns for readability, eg first parse address, then parse selector, then event, then parameter.

Another nit - we avoid re-assigning function parameters like you're doing with parameter here, would prefer something like

const firstParameterSegment = parameterSegments[0];

"struct MarketParams {address loanToken; address collateralToken; address oracle; address irm; uint256 lltv;}",
]);

const FactoryEventWithDynamicChildParamsAbiItem = parseAbiItem([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also include a test case where a struct/array is one of the indexed arguments and the user attempts to use one of its properties as the child address parameter. I think we'll have to validate against this - the address is not actually available in the event body because the value gets hashed and then stored as one of the topics.

Comment on lines +18 to +23
const parameterParts = parameter.split(".");

let offset = 0;

parameter = parameterParts[0]!;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, we just generally try to group concerns for readability, eg first parse address, then parse selector, then event, then parameter.

Another nit - we avoid re-assigning function parameters like you're doing with parameter here, would prefer something like

const firstParameterSegment = parameterSegments[0];

"struct ChildInfo { address childAddress; string name; uint256 initialValue; uint256 creationTime; address creator; }",
]);

const factoryEventWithDynamicChildParamsAbiItem2 = parseAbiItem([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which of the fields here is dynamic? This one still looks static to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants