Skip to content

Commit

Permalink
Implement popMessageAtIndex in AgentComm contract (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Jan 27, 2025
1 parent d08609e commit 7bba967
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 155 deletions.
177 changes: 30 additions & 147 deletions prediction_market_agent_tooling/abis/agentcommunication.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,17 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "MessageNotSentByAgent",
"type": "error"
},
{ "inputs": [], "name": "MessageNotSentByAgent", "type": "error" },
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
{ "internalType": "address", "name": "owner", "type": "address" }
],
"name": "OwnableInvalidOwner",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
{ "internalType": "address", "name": "account", "type": "address" }
],
"name": "OwnableUnauthorizedAccount",
"type": "error"
Expand Down Expand Up @@ -94,11 +82,7 @@
},
{
"inputs": [
{
"internalType": "uint256",
"name": "newValue",
"type": "uint256"
}
{ "internalType": "uint256", "name": "newValue", "type": "uint256" }
],
"name": "adjustMinimumValueForSendingMessage",
"outputs": [],
Expand All @@ -107,60 +91,26 @@
},
{
"inputs": [
{
"internalType": "address",
"name": "agentAddress",
"type": "address"
}
{ "internalType": "address", "name": "agentAddress", "type": "address" }
],
"name": "countMessages",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "agentAddress",
"type": "address"
},
{
"internalType": "uint256",
"name": "idx",
"type": "uint256"
}
{ "internalType": "address", "name": "agentAddress", "type": "address" },
{ "internalType": "uint256", "name": "idx", "type": "uint256" }
],
"name": "getAtIndex",
"outputs": [
{
"components": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "recipient",
"type": "address"
},
{
"internalType": "bytes",
"name": "message",
"type": "bytes"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
{ "internalType": "address", "name": "sender", "type": "address" },
{ "internalType": "address", "name": "recipient", "type": "address" },
{ "internalType": "bytes", "name": "message", "type": "bytes" },
{ "internalType": "uint256", "name": "value", "type": "uint256" }
],
"internalType": "struct DoubleEndedStructQueue.MessageContainer",
"name": "",
Expand All @@ -173,74 +123,37 @@
{
"inputs": [],
"name": "minimumValueForSendingMessageInWei",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "pctToTreasuryInBasisPoints",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "agentAddress",
"type": "address"
}
{ "internalType": "address", "name": "agentAddress", "type": "address" },
{ "internalType": "uint256", "name": "idx", "type": "uint256" }
],
"name": "popNextMessage",
"name": "popMessageAtIndex",
"outputs": [
{
"components": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "recipient",
"type": "address"
},
{
"internalType": "bytes",
"name": "message",
"type": "bytes"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
{ "internalType": "address", "name": "sender", "type": "address" },
{ "internalType": "address", "name": "recipient", "type": "address" },
{ "internalType": "bytes", "name": "message", "type": "bytes" },
{ "internalType": "uint256", "name": "value", "type": "uint256" }
],
"internalType": "struct DoubleEndedStructQueue.MessageContainer",
"name": "",
Expand All @@ -251,25 +164,11 @@
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "queues",
"outputs": [
{
"internalType": "uint128",
"name": "_begin",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "_end",
"type": "uint128"
}
{ "internalType": "uint128", "name": "_begin", "type": "uint128" },
{ "internalType": "uint128", "name": "_end", "type": "uint128" }
],
"stateMutability": "view",
"type": "function"
Expand All @@ -283,16 +182,8 @@
},
{
"inputs": [
{
"internalType": "address",
"name": "agentAddress",
"type": "address"
},
{
"internalType": "bytes",
"name": "message",
"type": "bytes"
}
{ "internalType": "address", "name": "agentAddress", "type": "address" },
{ "internalType": "bytes", "name": "message", "type": "bytes" }
],
"name": "sendMessage",
"outputs": [],
Expand All @@ -314,11 +205,7 @@
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
{ "internalType": "address", "name": "newOwner", "type": "address" }
],
"name": "transferOwnership",
"outputs": [],
Expand All @@ -329,13 +216,9 @@
"inputs": [],
"name": "treasury",
"outputs": [
{
"internalType": "address payable",
"name": "",
"type": "address"
}
{ "internalType": "address payable", "name": "", "type": "address" }
],
"stateMutability": "view",
"type": "function"
}
]
]
15 changes: 8 additions & 7 deletions prediction_market_agent_tooling/tools/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ class AgentCommunicationContract(ContractOnGnosisChain, OwnableContract):
)

address: ChecksumAddress = Web3.to_checksum_address(
"0xc566Cb829Ed7aC097D17a38011A40Ad2DC25Dd82"
"0xe9dd78FF297DbaAbe5D0E45aE554a4B561935DE9"
)

def minimum_message_value(self, web3: Web3 | None = None) -> xDai:
Expand Down Expand Up @@ -691,28 +691,29 @@ def pop_message(
self,
api_keys: APIKeys,
agent_address: ChecksumAddress,
index: int = 0,
web3: Web3 | None = None,
) -> MessageContainer:
"""
Retrieves and removes the first message from the agent's message queue.
Retrieves and removes message at specified index from the agent's message queue.
This method first retrieves the message at the front of the queue without removing it,
allowing us to return the message content directly. The actual removal of the message
from the queue is performed by sending a transaction to the contract, which executes
the `popNextMessage` function. The transaction receipt is not used to obtain the message
the `popMessageAtIndex` function. The transaction receipt is not used to obtain the message
content, as it only contains event data, not the returned struct.
"""

# Peek first element before popping.
# Peek the element before popping.
message_container = self.get_at_index(
agent_address=agent_address, idx=0, web3=web3
agent_address=agent_address, idx=index, web3=web3
)

# Next, pop that element and discard the transaction receipt.
self.send(
api_keys=api_keys,
function_name="popNextMessage",
function_params=[agent_address],
function_name="popMessageAtIndex",
function_params=[agent_address, index],
web3=web3,
)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "prediction-market-agent-tooling"
version = "0.57.13"
version = "0.57.14"
description = "Tools to benchmark, deploy and monitor prediction market agents."
authors = ["Gnosis"]
readme = "README.md"
Expand Down

0 comments on commit 7bba967

Please sign in to comment.