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

AgentRegister for AgentCommunication #24

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

Conversation

kongzii
Copy link
Collaborator

@kongzii kongzii commented Feb 12, 2025

No description provided.

@@ -46,39 +97,43 @@ contract AgentCommunication is Ownable {
return (amountForTreasury, amountForAgent);
}

// We don't add `onlyRegisteredAgent` modifier here, because anyone should be able to send a message to an agent
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Everything is guarded by onlyRegisteredAgent, except for this, because I guess we still want to be able to send messages from Streamlit UI to agents

Comment on lines +20 to +21
mapping(address => bool) public registeredAgents;
address[] private registeredAgentsList;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using EnumerableMap (https://docs.openzeppelin.com/contracts/5.x/api/utils#EnumerableMap) instead of mapping + list, more efficient.

Comment on lines +121 to 128
function getAtIndex(uint256 idx)
public
view
onlyRegisteredAgent
returns (DoubleEndedStructQueue.MessageContainer memory)
{
return DoubleEndedStructQueue.at(queues[agentAddress], idx);
return DoubleEndedStructQueue.at(queues[msg.sender], idx);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say reading should be allowed, as it's not modifying state. Messares are public.
Popping (on the other hand) should be guarded (as you implemented).

}
}

contract AgentCommunication is AgentRegistry {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for coupling these 2 contracts?
In my head, it would make more sense that AgentCommunication receives an AgentRegistry instance (actually the Interface) via constructor arg, and then operate on that.
This way, we keep the contracts independent of each other, since one handles registry and the other handles messaging. Wdty?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried this approach initially but had some errors with it. I'll try it once more and post them here, maybe you will be able to help. (I like it like that more as well)

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, happy to huddle or help async.
What I had in mind (hopefully works) is something like this

contract AgentRegistry {
[...]
}
contract AgentCommunication is Ownable {

IAgentRegistry public agentRegistry;

constructor(IAgentRegistry agentRegistry) Ownable(msg.sender) {
    agentRegistry = agentRegistry
}

// setter - onlyOwner

}

see also https://github.com/seer-pm/demo/blob/4310c1e2b995f675b9a8ef11f9a4f79ed044ecc4/contracts/src/trade/LiquidityManager.sol#L16

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