Skip to content

Commit

Permalink
Small tweaks to NFT game (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Jan 8, 2025
1 parent 58cae35 commit 8d52457
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 45 deletions.
66 changes: 34 additions & 32 deletions poetry.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from prediction_market_agent_tooling.gtypes import xDai, xdai_type
from prediction_market_agent_tooling.loggers import logger
from prediction_market_agent_tooling.markets.omen.omen import OMEN_TINY_BET_AMOUNT

from prediction_market_agent.utils import APIKeys

Expand All @@ -12,7 +11,6 @@ class MicrochainAgentKeys(APIKeys):
SENDING_XDAI_CAP: xDai | None = xdai_type(0.1)
# Double check to not transfer NFTs during testing.
ENABLE_NFT_TRANSFER: bool = False
RECEIVER_MINIMUM_AMOUNT: xDai = OMEN_TINY_BET_AMOUNT

def cap_sending_xdai(self, amount: xDai) -> xDai:
if self.SENDING_XDAI_CAP is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from prediction_market_agent.db.agent_communication import (
fetch_count_unprocessed_transactions,
fetch_unseen_transactions,
get_message_minimum_value,
)
from prediction_market_agent.db.long_term_memory_table_handler import (
LongTermMemories,
Expand Down Expand Up @@ -88,7 +89,7 @@ def send_message_via_wallet(
def send_message_part(nft_agent: type[DeployableAgentNFTGameAbstract]) -> None:
message = st.text_area("Write a message to the agent")
keys = MicrochainAgentKeys()
default_value = keys.RECEIVER_MINIMUM_AMOUNT
default_value = get_message_minimum_value()
amount_to_send = st.number_input(
"Value in xDai",
min_value=default_value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ def max_supply(self, web3: Web3 | None = None) -> int:
n_tokens: int = self.call("MAX_SUPPLY", web3=web3)
return n_tokens

def token_ids_owned_by(
self, owner: ChecksumAddress, web3: Web3 | None = None
) -> list[int]:
token_ids = list(range(self.max_supply(web3=web3)))
return [
token_id
for token_id in token_ids
if self.ownerOf(tokenId=token_id, web3=web3) == owner
]


@cache
def get_nft_token_factory_max_supply() -> int:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
TREASURY_SAFE_ADDRESS,
)
from prediction_market_agent.agents.microchain_agent.nft_treasury_game.contracts_nft_treasury_game import (
ContractNFTFactoryOnGnosisChain,
get_nft_token_factory_max_supply,
)
from prediction_market_agent.db.agent_communication import get_treasury_tax_ratio


class DeployableAgentNFTGameAbstract(DeployableMicrochainAgentAbstract):
Expand Down Expand Up @@ -188,6 +190,9 @@ def get_initial_system_prompt(cls) -> str:
def nft_treasury_game_base_prompt(wallet_address: ChecksumAddress) -> str:
keys = MicrochainAgentKeys()
n_nft_keys = get_nft_token_factory_max_supply()
nft_token_ids_owned = ContractNFTFactoryOnGnosisChain().token_ids_owned_by(
wallet_address
)
other_agents_keys_formatted = ", ".join(
x.wallet_address
for x in DEPLOYED_NFT_AGENTS
Expand All @@ -202,13 +207,17 @@ def nft_treasury_game_base_prompt(wallet_address: ChecksumAddress) -> str:
- Address of the NFT contract is {NFT_TOKEN_FACTORY}, there are {n_nft_keys} keys, with token_id {list(range(n_nft_keys))}.
- You can own multiple NFT keys.
- You can use the NFT functions to interact with the NFT keys, for example figuring out how many keys you own or who owns what key.
- You currently own NFT keys with token_ids {nft_token_ids_owned}.
- Before accepting to transfer any NFT key, consider how much is the treasury worth at the moment.
- The agent or person who gets enough of keys, can transfer the resources from the treasury.
- Wallet balance and holding NFT keys are two different things, you can have a lot of xDai, but no NFT keys and vice versa, you can have a lot of NFT keys, but no xDai.
- The agents can communicate with each other using the messages functions by sending a message to their wallet address.
- Sending a message costs you a fee.
- Receiving messages will pay you a fee, but part of that fee goes to the treasury, which is good for you.
- Receiving messages will pay you a fee, but part of that fee goes as a tax to the treasury, which is good for you.
- Treasury tax rate is currently {get_treasury_tax_ratio() * 100:.2f}%, for example, if someone sends you 10 xDai, you would receive {(1 - get_treasury_tax_ratio()) * 10:.2f} xDai.
- If you have unseen incoming messages, always process them first, unless you are processing some message at the moment.
- Regularly check balances of your wallet and the treasury.
- Keep in mind that you are able to send, and others agents are able to send at max {keys.SENDING_XDAI_CAP} xDai.
- Regularly check balances of your wallet and the treasury, but not too often, keep doing other stuff as well!
- Keep in mind that you are able to send, and others agents are able to send at max {keys.SENDING_XDAI_CAP} xDai, however people can send you as much as they want.
"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
from prediction_market_agent.db.agent_communication import (
fetch_count_unprocessed_transactions,
get_message_minimum_value,
pop_message,
send_message,
)
Expand Down Expand Up @@ -43,11 +44,11 @@ class SendPaidMessageToAnotherAgent(Function):
@property
def description(self) -> str:
return f"""Use {SendPaidMessageToAnotherAgent.__name__} to send a message to an another agent, given his wallet address.
You need to send a fee of at least {MicrochainAgentKeys().RECEIVER_MINIMUM_AMOUNT} xDai for other agent to read the message."""
You need to send a fee of at least {get_message_minimum_value()} xDai for other agent to read the message."""

@property
def example_args(self) -> list[str]:
return ["0x123", "Hello!", f"{MicrochainAgentKeys().RECEIVER_MINIMUM_AMOUNT}"]
return ["0x123", "Hello!", f"{get_message_minimum_value()}"]

def __call__(self, address: str, message: str, fee: float) -> str:
keys = MicrochainAgentKeys()
Expand All @@ -62,9 +63,6 @@ def __call__(self, address: str, message: str, fee: float) -> str:


class ReceiveMessage(Function):
# Percentage of message value that goes to the treasury.
TREASURY_ACCUMULATION_PERCENTAGE = 0.7

@staticmethod
def get_count_unseen_messages() -> int:
keys = MicrochainAgentKeys()
Expand Down
14 changes: 13 additions & 1 deletion prediction_market_agent/db/agent_communication.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from functools import cache

from eth_typing import ChecksumAddress
from prediction_market_agent_tooling.config import APIKeys as APIKeys_PMAT
from prediction_market_agent_tooling.gtypes import HexBytes, Wei
from prediction_market_agent_tooling.gtypes import HexBytes, Wei, xDai
from prediction_market_agent_tooling.tools.contract import (
AgentCommunicationContract,
ContractOnGnosisChain,
Expand Down Expand Up @@ -64,3 +66,13 @@ def send_message(
amount_wei=amount_wei,
web3=ContractOnGnosisChain.get_web3(),
)


@cache
def get_message_minimum_value() -> xDai:
return AgentCommunicationContract().minimum_message_value()


@cache
def get_treasury_tax_ratio() -> float:
return AgentCommunicationContract().ratio_given_to_treasury()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ poetry = "^1.7.1"
poetry-plugin-export = "^1.6.0"
functions-framework = "^3.5.0"
cron-validator = "^1.0.8"
prediction-market-agent-tooling = { version = "^0.57.9", extras = ["langchain", "google"] }
prediction-market-agent-tooling = { version = "^0.57.10", extras = ["langchain", "google"] }
pydantic-settings = "^2.1.0"
autoflake = "^2.2.1"
isort = "^5.13.2"
Expand Down

0 comments on commit 8d52457

Please sign in to comment.