Skip to content

Commit

Permalink
Merge pull request #116 from dvilelaf/fix/token-addresses
Browse files Browse the repository at this point in the history
Fix/token addresses
  • Loading branch information
dvilelaf authored Dec 20, 2024
2 parents 84b97d3 + bb7cc6f commit 6ad3ef1
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 21 deletions.
7 changes: 4 additions & 3 deletions packages/dvilela/agents/memeooorr/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contracts:
- valory/gnosis_safe:0.1.0:bafybeiaw4yr7ubqlp63iz5wxqep3a5fokqs3kqva7sp2nsqg355zzucqgm
- valory/gnosis_safe_proxy_factory:0.1.0:bafybeidkqhw7smq4kbqryodom6maj7gubc5nbxwm4vi343xbkqxx3brjtm
- valory/multisend:0.1.0:bafybeig5byt5urg2d2bsecufxe5ql7f4mezg3mekfleeh32nmuusx66p4y
- dvilela/meme_factory:0.1.0:bafybeibkuiylm2qiivyrlue6opw3jxuyrh55f3r6lx5bqk7lnx6uc4yasu
- dvilela/meme_factory:0.1.0:bafybeigdnngracdis2shkn5hua3ufrnqo5qettmuvqbviculbsimwa4lzi
- dvilela/service_registry:0.1.0:bafybeie2rrgzcjehlp2feff6bhkuindxzrnuwxe2jcrsy2thcdtrsp2o24
protocols:
- open_aea/signing:1.0.0:bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi
Expand All @@ -41,8 +41,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeigh2vkt74jrad5gtsczrgqcuhcqe7jkgjy7jdw56yamlzwwnaymjy
- valory/registration_abci:0.1.0:bafybeib3n6vqkfbrcubcbliebjnuwyywdinxkbzt76n6gbn2kg7ace47dq
- valory/reset_pause_abci:0.1.0:bafybeihkj6lmaypspyxe5qqrjgnolyck62pyvqoylr24ab6ue4steqcw7e
- dvilela/memeooorr_abci:0.1.0:bafybeigegmsisv4p4pvswa4o4ee3jkzolhkq2zxjbzc5whmzlc4czcmm3a
- dvilela/memeooorr_chained_abci:0.1.0:bafybeiaeiey7apjsxzlewmsleh7oz5u565qrrax27ra53ukjvyxz7lafkm
- dvilela/memeooorr_abci:0.1.0:bafybeic6iw6x7rcbnueptuols5notwwnojfnuoduwtqjq6j2r435ukct7m
- dvilela/memeooorr_chained_abci:0.1.0:bafybeic7cs5xfbevl6wjvbw5ok6u5pfzhjso46gg5k6y57re5zmy7etmju
default_ledger: ethereum
required_ledgers:
- ethereum
Expand Down Expand Up @@ -220,6 +220,7 @@ models:
twitter_username: ${str:null}
service_registry_address_base: ${str:0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE}
service_registry_address_celo: ${str:0xE3607b00E75f6405248323A9417ff6b39B244b50}
meme_subgraph_url: ${str:https://agentsfun-indexer-production.up.railway.app}
---
public_id: valory/http_server:0.22.0:bafybeicblltx7ha3ulthg7bzfccuqqyjmihhrvfeztlgrlcoxhr7kf6nbq
type: connection
Expand Down
2 changes: 2 additions & 0 deletions packages/dvilela/contracts/meme_factory/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ def get_events( # pylint: disable=too-many-arguments

events += new_events

_logger.info(f"Got {len(events)} {event_name} events")

if event_name == "Summoned":
return dict(
events=[
Expand Down
2 changes: 1 addition & 1 deletion packages/dvilela/contracts/meme_factory/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fingerprint:
README.md: bafybeies3iafkjwo4xvqtqpdxvood7pf2wgto4t76dqswy55rya7vl5zgu
__init__.py: bafybeiddslgyschgiuwsfiovqgxqqbkazdy6h3d4swwnq3tvpqaxzy37si
build/MemeBase.json: bafybeibr3pkkofhukwqjuqxuxsb52g2xlquzhu5uv6xqo527s2zzmp3cq4
contract.py: bafybeifxtrg4j2e2nbwgsz5u2vhs4b3woipn7iq5xoxhpvm5qzb3p3rcge
contract.py: bafybeiaussmgr2ffnget7jnibl5rdqcx5h7mmlc2zh3ku6tgiaioibjccu
fingerprint_ignore_patterns: []
contracts: []
class_name: MemeFactoryContract
Expand Down
3 changes: 2 additions & 1 deletion packages/dvilela/services/memeooorr/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeiaekcmielp6mb4qvmo2twwkpmoun36bqajrh7wnnkcpdnia45ycl4
fingerprint_ignore_patterns: []
agent: dvilela/memeooorr:0.1.0:bafybeigfxu7enol76ycvbbm7pzxjw3t72habr6rvldxhumtejm3s73omau
agent: dvilela/memeooorr:0.1.0:bafybeihvhv6jbq7b6r2eyi7ez3vdr4omf4ocqmsz36vv4zhz2o6qnry7ya
number_of_agents: 1
deployment:
agent:
Expand Down Expand Up @@ -97,6 +97,7 @@ extra:
twitter_username: ${TWIKIT_USERNAME:str:null}
service_registry_address_base: ${SERVICE_REGISTRY_ADDRESS_BASE:str:0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE}
service_registry_address_celo: ${SERVICE_REGISTRY_ADDRESS_CELO:str:0xE3607b00E75f6405248323A9417ff6b39B244b50}
meme_subgraph_url: ${MEME_SUBGRAPH_URL:str:https://agentsfun-indexer-production.up.railway.app}
---
public_id: valory/ledger:0.19.0
type: connection
Expand Down
93 changes: 90 additions & 3 deletions packages/dvilela/skills/memeooorr_abci/behaviour_classes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def get_meme_available_actions(

available_actions = copy(AVAILABLE_ACTIONS)

is_unleashed = meme_data["unleash_time"] != 0
is_unleashed = meme_data.get("unleash_time", 0) != 0

# We can unleash if it has not been unleashed
if is_unleashed:
Expand All @@ -284,7 +284,10 @@ def get_meme_available_actions(
available_actions.remove("heart")

# We should not heart if we have already hearted
if "heart" in available_actions and meme_data["token_address"] in hearted_memes:
if (
"heart" in available_actions
and meme_data.get("token_address", None) in hearted_memes
):
available_actions.remove("heart")

# We use 47.5 to be on the safe side
Expand All @@ -295,7 +298,7 @@ def get_meme_available_actions(
available_actions.remove("burn")

# We can collect if we have hearted this token
if meme_data["token_address"] not in hearted_memes:
if meme_data.get("token_address", None) not in hearted_memes:
available_actions.remove("collect")

return available_actions
Expand Down Expand Up @@ -461,6 +464,7 @@ def get_meme_coins_from_chain(self) -> Generator[None, None, Optional[List]]:
"""Get a list of meme coins"""
self.context.logger.info("Getting meme tokens from the chain")

# Summons
# Use the contract api to interact with the factory contract
response_msg = yield from self.get_contract_api_response(
performative=ContractApiMessage.Performative.GET_STATE, # type: ignore
Expand All @@ -480,6 +484,89 @@ def get_meme_coins_from_chain(self) -> Generator[None, None, Optional[List]]:

tokens = cast(list, response_msg.state.body.get("tokens", None))

# Unleashes
# Use the contract api to interact with the factory contract
response_msg = yield from self.get_contract_api_response(
performative=ContractApiMessage.Performative.GET_STATE, # type: ignore
contract_address=self.get_meme_factory_address(),
contract_id=str(MemeFactoryContract.contract_id),
contract_callable="get_events",
event_name="Unleashed",
from_block=self.get_meme_factory_deployment_block(),
chain_id=self.get_chain_id(),
)

# Check that the response is what we expect
if response_msg.performative != ContractApiMessage.Performative.STATE:
self.context.logger.error(
f"Could not get the memecoin summon events: {response_msg}"
)
return None

unleash_events = cast(list, response_msg.state.body.get("events", None))

# Add token addresses
for event in unleash_events:
for token in tokens:
if token["token_nonce"] == event["token_nonce"]:
token["token_address"] = event["token_address"]

# Load previously hearted memes
db_data = yield from self._read_kv(keys=("hearted_memes",))

if db_data is None:
self.context.logger.error("Error while loading the database")
hearted_memes: List[str] = []
else:
hearted_memes = db_data["hearted_memes"] or []

for token in tokens:
token["available_actions"] = self.get_meme_available_actions(
token, hearted_memes
)

return tokens

def get_meme_coins_from_subgraph(self) -> Generator[None, None, Optional[List]]:
"""Get a list of meme coins"""
self.context.logger.info("Getting meme tokens from the subgraph")

headers = {
"Content-Type": "application/json",
}

query = {"query": TOKENS_QUERY}

response = yield from self.get_http_response( # type: ignore
method="POST",
url=self.params.meme_subgraph_url,
headers=headers,
content=json.dumps(query).encode(),
)

if response.status_code != HTTP_OK: # type: ignore
self.context.logger.error(
f"Error getting agents from subgraph: {response}" # type: ignore
)
return None

response_json = json.loads(response.body)
tokens = [
{
"block_number": int(t["blockNumber"]),
"chain": t["chain"],
"token_address": t["id"].split("-")[1],
"liquidity": int(t["liquidity"]),
"heart_count": int(t["heartCount"]),
"is_unleashed": t["isUnleashed"],
"lp_pair_address": t["lpPairAddress"],
"owner": t["owner"],
"timestamp": t["timestamp"],
}
for t in response_json["data"]["memeTokens"]["items"]
if t["chain"] == self.get_chain_id()
]

# Load previously hearted memes
db_data = yield from self._read_kv(keys=("hearted_memes",))

Expand Down
1 change: 1 addition & 0 deletions packages/dvilela/skills/memeooorr_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
self.meme_factory_deployment_block_celo = self._ensure(
"meme_factory_deployment_block_celo", kwargs, int
)
self.meme_subgraph_url = self._ensure("meme_subgraph_url", kwargs, str)

super().__init__(*args, **kwargs)
7 changes: 4 additions & 3 deletions packages/dvilela/skills/memeooorr_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeidorrnxjv4n4ngovxnu4mzod46kyrdncfmli4hapqeqnzp7imq7hm
behaviour_classes/__init__.py: bafybeicjks4kxsb2r6a4armmaqxyxngwm3pouegq3fycm37rbe7otiwsre
behaviour_classes/base.py: bafybeiesc42ytwwnteik7ht3xbsvpszdjlfatn6vndmwu336gmpfc7okwa
behaviour_classes/base.py: bafybeib26og4iiwb322svawmmaiqytvkrdv6nelcbpiqyia3nlwxaj5vpi
behaviour_classes/chain.py: bafybeigxfwko3rofqlzyjjhgeo6yabxseqngo2uz5muyfk3f2jjpgdrsli
behaviour_classes/db.py: bafybeieuhjes2gsiidepjxcojgnn3swx2znem5uwvz7rwkxpwls3dmlxf4
behaviour_classes/llm.py: bafybeifdhipccrdtfx5vay2sfd7vss4iovwtyeefuz5vrjewjbyatk35c4
Expand All @@ -17,7 +17,7 @@ fingerprint:
dialogues.py: bafybeiaygigeleloplgrsg2sovv463uvzk3zc2tupgazn4ak2vqcangksu
fsm_specification.yaml: bafybeif4kr2lnj4ppaaxveej2a3gq2gul6gicu2rar2yeyhg4mspqsikxy
handlers.py: bafybeibnnxjczbaeqzxvg4s5mmrogzhgpswwwwpmw6gds6mltgrq27r67y
models.py: bafybeid5kwqwuxj3chu2ijkf4cily2bu3en2czqwhkf7kkzt7l5acov5du
models.py: bafybeidwapsmqst3jw3ahsl4o2lfsapcyn4ojsqn3gz5nvivpsykc4sefy
payloads.py: bafybeibyukr3aewwlbx6c6xe43j6nhgdqwqdgbemswrsvnqp3ftqodvvmi
prompts.py: bafybeiguzllaoupwzyiob6iufx77czkj6a7xe3mdporjtrfnm5m4grzhbe
rounds.py: bafybeiezr7wrjl7k3ojvjqdbpp6vs7u2lmgwdjuhi62sy4hedpe4euwswq
Expand All @@ -30,7 +30,7 @@ connections:
- valory/http_server:0.22.0:bafybeihpgu56ovmq4npazdbh6y6ru5i7zuv6wvdglpxavsckyih56smu7m
contracts:
- valory/gnosis_safe:0.1.0:bafybeiaw4yr7ubqlp63iz5wxqep3a5fokqs3kqva7sp2nsqg355zzucqgm
- dvilela/meme_factory:0.1.0:bafybeibkuiylm2qiivyrlue6opw3jxuyrh55f3r6lx5bqk7lnx6uc4yasu
- dvilela/meme_factory:0.1.0:bafybeigdnngracdis2shkn5hua3ufrnqo5qettmuvqbviculbsimwa4lzi
- dvilela/service_registry:0.1.0:bafybeie2rrgzcjehlp2feff6bhkuindxzrnuwxe2jcrsy2thcdtrsp2o24
protocols:
- valory/srr:0.1.0:bafybeihrixgptxuqpf2s4nujypwlv5aed2nboozq5kl4c26cxw6r7si2x4
Expand Down Expand Up @@ -164,6 +164,7 @@ models:
twitter_username: dummy_twitter_name
service_registry_address_base: '0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE'
service_registry_address_celo: '0xE3607b00E75f6405248323A9417ff6b39B244b50'
meme_subgraph_url: https://agentsfun-indexer-production.up.railway.app
class_name: Params
requests:
args: {}
Expand Down
3 changes: 2 additions & 1 deletion packages/dvilela/skills/memeooorr_chained_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeihkj6lmaypspyxe5qqrjgnolyck62pyvqoylr24ab6ue4steqcw7e
- valory/transaction_settlement_abci:0.1.0:bafybeigh2vkt74jrad5gtsczrgqcuhcqe7jkgjy7jdw56yamlzwwnaymjy
- valory/termination_abci:0.1.0:bafybeifi2uodnrjsrivj53g3sjutocmyusbx6mlsb6oanqdyt2mfbyvusy
- dvilela/memeooorr_abci:0.1.0:bafybeigegmsisv4p4pvswa4o4ee3jkzolhkq2zxjbzc5whmzlc4czcmm3a
- dvilela/memeooorr_abci:0.1.0:bafybeic6iw6x7rcbnueptuols5notwwnojfnuoduwtqjq6j2r435ukct7m
behaviours:
main:
args: {}
Expand Down Expand Up @@ -156,6 +156,7 @@ models:
twitter_username: dummy_twitter_name
service_registry_address_base: '0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE'
service_registry_address_celo: '0xE3607b00E75f6405248323A9417ff6b39B244b50'
meme_subgraph_url: https://agentsfun-indexer-production.up.railway.app
class_name: Params
randomness_api:
args:
Expand Down
10 changes: 5 additions & 5 deletions packages/packages.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"dev": {
"contract/dvilela/meme_factory/0.1.0": "bafybeibkuiylm2qiivyrlue6opw3jxuyrh55f3r6lx5bqk7lnx6uc4yasu",
"contract/dvilela/meme_factory/0.1.0": "bafybeigdnngracdis2shkn5hua3ufrnqo5qettmuvqbviculbsimwa4lzi",
"contract/dvilela/service_registry/0.1.0": "bafybeie2rrgzcjehlp2feff6bhkuindxzrnuwxe2jcrsy2thcdtrsp2o24",
"connection/dvilela/twikit/0.1.0": "bafybeibglc42u6krxzzhdsnixhdwblefcolhulzckyfmek4hg4chvgpwza",
"skill/dvilela/memeooorr_abci/0.1.0": "bafybeigegmsisv4p4pvswa4o4ee3jkzolhkq2zxjbzc5whmzlc4czcmm3a",
"skill/dvilela/memeooorr_chained_abci/0.1.0": "bafybeiaeiey7apjsxzlewmsleh7oz5u565qrrax27ra53ukjvyxz7lafkm",
"agent/dvilela/memeooorr/0.1.0": "bafybeigfxu7enol76ycvbbm7pzxjw3t72habr6rvldxhumtejm3s73omau",
"service/dvilela/memeooorr/0.1.0": "bafybeie5xgroxr7ie2okpd3oph4mir3pd3v4v6hdcasfe2g4qnneauetom"
"skill/dvilela/memeooorr_abci/0.1.0": "bafybeic6iw6x7rcbnueptuols5notwwnojfnuoduwtqjq6j2r435ukct7m",
"skill/dvilela/memeooorr_chained_abci/0.1.0": "bafybeic7cs5xfbevl6wjvbw5ok6u5pfzhjso46gg5k6y57re5zmy7etmju",
"agent/dvilela/memeooorr/0.1.0": "bafybeihvhv6jbq7b6r2eyi7ez3vdr4omf4ocqmsz36vv4zhz2o6qnry7ya",
"service/dvilela/memeooorr/0.1.0": "bafybeiamfoix3qumef6nyl67fobb5bi2y3mun2lxedah3cj2k37qqlhbwm"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down
12 changes: 8 additions & 4 deletions scripts/test_subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
def get_meme_coins_from_subgraph():
"""Get a list of meme coins"""

url = "https://agentsfun-indexer-production-6ab5.up.railway.app"
url = "https://agentsfun-indexer-production.up.railway.app"

query = {"query": TOKENS_QUERY}

Expand All @@ -79,17 +79,21 @@ def get_meme_coins_from_subgraph():

# Handle HTTP errors
if response.status_code != HTTP_OK:
print(f"Error while pulling the memes from subgraph: {response.body!r}")
print(f"Error while pulling the memes from subgraph: {response}")
return []

# Load the response
response_json = response.json()
meme_coins = [
{
"token_address": t["id"],
"block_number": int(t["blockNumber"]),
"chain": t["chain"],
"token_address": t["id"].split("-")[1],
"liquidity": int(t["liquidity"]),
"heart_count": int(t["heartCount"]),
"is_unleashed": t["isUnleashed"],
"lp_pair_address": t["lpPairAddress"],
"owner": t["owner"],
"timestamp": t["timestamp"],
}
for t in response_json["data"]["memeTokens"]["items"]
Expand Down Expand Up @@ -141,4 +145,4 @@ def get_memeooorr_handles_from_subgraph():
return handles


print(get_memeooorr_handles_from_subgraph())
print(get_meme_coins_from_subgraph())

0 comments on commit 6ad3ef1

Please sign in to comment.