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

Fix/mech integration #216

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/packages.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"dev": {
"skill/valory/market_manager_abci/0.1.0": "bafybeib72jm7aznzhmtxnmwlpnse23xutnurexml57ovkn2zpr2gsmpvni",
"skill/valory/decision_maker_abci/0.1.0": "bafybeiatntrgxmsmzfsuksits4mezhcmldogn7bcoqy6fztalhjhv65g7m",
"skill/valory/trader_abci/0.1.0": "bafybeifjodxblb75batrffbcaeq6g4vlqz6o4bllsz6agtvcxukjfwu5wa",
"skill/valory/decision_maker_abci/0.1.0": "bafybeifharwkzhzh5ngtbky3zo55ik2eqjqrxxx4yqr4hiwmdoqyp2td54",
"skill/valory/trader_abci/0.1.0": "bafybeiboyjvttf75atsz7ci5qp4hlaxt5zuq6aa23olxekkcc5enbyew4a",
"contract/valory/market_maker/0.1.0": "bafybeihtjp5z2v6ax3fieu2hnwajlzlfpiadgmrsm24pd4rr2tjq33xt3i",
"agent/valory/trader/0.1.0": "bafybeigelmjanmd57y2dshhqll5jjja2xeizn4vjgsuwanqtlehespvnoe",
"service/valory/trader/0.1.0": "bafybeihjokemaaqkiih5p6aopahkthxghp57w2zhf5cqe2vndom5cl6dca",
"agent/valory/trader/0.1.0": "bafybeiexmyrslgxqnygcbir5ws26ltcjv5qo7e7plqapoo3j22xuqpfy64",
"service/valory/trader/0.1.0": "bafybeihn5f3w6n5j72imfdxrjwdxbzszqxgylhk6a4i6fm5wkotp4bldzu",
"contract/valory/erc20/0.1.0": "bafybeihy56fit7nc5e5f2h7bp7b2dvthibldyinynuxfzxvalhfo2zhvji",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeidtm6vd4pin35zwxiryzaagtwfkxgqtcevacbthoekgoi5yfsr4gm",
"contract/valory/mech/0.1.0": "bafybeid26bj6twv6he62gulrhixs2t2jsaxzhmpnysh3sywwankb74ngvu",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibyxyafhqaud5yhx2hfubowhwqups6hn6umvuunlq5o4h7ax44guu",
"contract/valory/mech/0.1.0": "bafybeihns2sdru2g562dh5rymc4owdj7ymkm4o6ld7ahed46f7vp2bj7om",
"contract/valory/realitio/0.1.0": "bafybeic5ie4oodetj4krdogydvbfxg4qggc3matpiflocah626tpevpreq",
"contract/valory/realitio_proxy/0.1.0": "bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4",
"contract/valory/conditional_tokens/0.1.0": "bafybeigucumqbsk74nj4rpm4p2cpiky4dj6uws7nfmgpimuviaxcamwqnu",
"contract/valory/agent_registry/0.1.0": "bafybeihciea74zyqtl7bsa7kv6wsudix7uh4ri64dlyufrxlm2e2xcqoeu",
"contract/valory/service_staking_token/0.1.0": "bafybeif2rfugwe6flohxe5p4y5so56saeq5blpnuckuhjwoh2m65dj3qhi",
"skill/valory/staking_abci/0.1.0": "bafybeidgivibaeant53uef3j2virsxlgr5kpd6lsenr7pjdhqktwbqxfye",
"contract/valory/transfer_nft_condition/0.1.0": "bafybeigj46jcovsrfrfymdr37fym25k5s4dbrek5pzhshewstxjds76uyu"
"contract/valory/transfer_nft_condition/0.1.0": "bafybeiab7p2jky5g6jjznpqkf4znyjp5ko466usgv5pntdlqi6uss456y4"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down
10 changes: 5 additions & 5 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ contracts:
- valory/market_maker:0.1.0:bafybeihtjp5z2v6ax3fieu2hnwajlzlfpiadgmrsm24pd4rr2tjq33xt3i
- valory/erc20:0.1.0:bafybeihy56fit7nc5e5f2h7bp7b2dvthibldyinynuxfzxvalhfo2zhvji
- valory/multisend:0.1.0:bafybeig5byt5urg2d2bsecufxe5ql7f4mezg3mekfleeh32nmuusx66p4y
- valory/mech:0.1.0:bafybeid26bj6twv6he62gulrhixs2t2jsaxzhmpnysh3sywwankb74ngvu
- valory/mech:0.1.0:bafybeihns2sdru2g562dh5rymc4owdj7ymkm4o6ld7ahed46f7vp2bj7om
- valory/conditional_tokens:0.1.0:bafybeigucumqbsk74nj4rpm4p2cpiky4dj6uws7nfmgpimuviaxcamwqnu
- valory/realitio:0.1.0:bafybeic5ie4oodetj4krdogydvbfxg4qggc3matpiflocah626tpevpreq
- valory/realitio_proxy:0.1.0:bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4
- valory/agent_registry:0.1.0:bafybeihciea74zyqtl7bsa7kv6wsudix7uh4ri64dlyufrxlm2e2xcqoeu
- valory/service_staking_token:0.1.0:bafybeif2rfugwe6flohxe5p4y5so56saeq5blpnuckuhjwoh2m65dj3qhi
- valory/transfer_nft_condition:0.1.0:bafybeigj46jcovsrfrfymdr37fym25k5s4dbrek5pzhshewstxjds76uyu
- valory/transfer_nft_condition:0.1.0:bafybeiab7p2jky5g6jjznpqkf4znyjp5ko466usgv5pntdlqi6uss456y4
protocols:
- open_aea/signing:1.0.0:bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi
- valory/abci:0.1.0:bafybeiaqmp7kocbfdboksayeqhkbrynvlfzsx4uy4x6nohywnmaig4an7u
Expand All @@ -44,10 +44,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeialc6wdfe56dirdx3pgyh2qaq74hpp3n3ues6e3zr7yoqwgnwsqyu
- valory/termination_abci:0.1.0:bafybeihmqrvnzhptap62nchvocmu7tzl5d2o6k4eitkaiuvo7qwvsaedua
- valory/transaction_settlement_abci:0.1.0:bafybeihaad5k6adwkqwc5pui243inep2kvw7k7pgwwqaykssyx7p64peyi
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeidtm6vd4pin35zwxiryzaagtwfkxgqtcevacbthoekgoi5yfsr4gm
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibyxyafhqaud5yhx2hfubowhwqups6hn6umvuunlq5o4h7ax44guu
- valory/market_manager_abci:0.1.0:bafybeib72jm7aznzhmtxnmwlpnse23xutnurexml57ovkn2zpr2gsmpvni
- valory/decision_maker_abci:0.1.0:bafybeiatntrgxmsmzfsuksits4mezhcmldogn7bcoqy6fztalhjhv65g7m
- valory/trader_abci:0.1.0:bafybeifjodxblb75batrffbcaeq6g4vlqz6o4bllsz6agtvcxukjfwu5wa
- valory/decision_maker_abci:0.1.0:bafybeifharwkzhzh5ngtbky3zo55ik2eqjqrxxx4yqr4hiwmdoqyp2td54
- valory/trader_abci:0.1.0:bafybeiboyjvttf75atsz7ci5qp4hlaxt5zuq6aa23olxekkcc5enbyew4a
- valory/staking_abci:0.1.0:bafybeidgivibaeant53uef3j2virsxlgr5kpd6lsenr7pjdhqktwbqxfye
default_ledger: ethereum
required_ledgers:
Expand Down
139 changes: 130 additions & 9 deletions packages/valory/contracts/mech/contract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2023 Valory AG
# Copyright 2023-2024 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,114 @@
FIVE_MINUTES = 300.0


partial_abis = [
[
{
"anonymous": False,
"inputs": [
{
"indexed": False,
"internalType": "uint256",
"name": "requestId",
"type": "uint256",
},
{
"indexed": False,
"internalType": "bytes",
"name": "data",
"type": "bytes",
},
],
"name": "Deliver",
"type": "event",
},
{
"anonymous": False,
"inputs": [
{
"indexed": True,
"internalType": "address",
"name": "sender",
"type": "address",
},
{
"indexed": False,
"internalType": "uint256",
"name": "requestId",
"type": "uint256",
},
{
"indexed": False,
"internalType": "bytes",
"name": "data",
"type": "bytes",
},
],
"name": "Request",
"type": "event",
},
],
[
{
"anonymous": False,
"inputs": [
{
"indexed": True,
"internalType": "address",
"name": "sender",
"type": "address",
},
{
"indexed": False,
"internalType": "uint256",
"name": "requestId",
"type": "uint256",
},
{
"indexed": False,
"internalType": "uint256",
"name": "requestIdWithNonce",
"type": "uint256",
},
{
"indexed": False,
"internalType": "bytes",
"name": "data",
"type": "bytes",
},
],
"name": "Request",
"type": "event",
},
{
"anonymous": False,
"inputs": [
{
"indexed": True,
"internalType": "address",
"name": "sender",
"type": "address",
},
{
"indexed": False,
"internalType": "uint256",
"name": "requestId",
"type": "uint256",
},
{
"indexed": False,
"internalType": "bytes",
"name": "data",
"type": "bytes",
},
],
"name": "Deliver",
"type": "event",
},
],
]


class Mech(Contract):
"""The Mech contract."""

Expand Down Expand Up @@ -96,14 +204,13 @@ def get_request_data(
def _process_event(
cls,
ledger_api: LedgerApi,
contract_address: str,
contract: Any,
tx_hash: HexStr,
event_name: str,
*args: Any,
) -> Optional[JSONLike]:
"""Process the logs of the given event."""
ledger_api = cast(EthereumApi, ledger_api)
contract = cls.get_instance(ledger_api, contract_address)
receipt: TxReceipt = ledger_api.api.eth.get_transaction_receipt(tx_hash)
event_method = getattr(contract.events, event_name)
logs: List[EventData] = list(event_method().process_receipt(receipt))
Expand Down Expand Up @@ -138,9 +245,16 @@ def process_request_event(
:param tx_hash: the hash of a request tx to be processed.
:return: a dictionary with the request id.
"""
return cls._process_event(
ledger_api, contract_address, tx_hash, "Request", "requestId", "data"
)
res = {}
for abi in partial_abis:
contract_instance = ledger_api.api.eth.contract(contract_address, abi=abi)
res = cls._process_event(
ledger_api, contract_instance, tx_hash, "Request", "requestId", "data"
)
if "error" not in res:
return res

return res
Comment on lines +248 to +257
Copy link
Collaborator

Choose a reason for hiding this comment

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

A process_mech_event can be extracted here, accepting the type of the request as an argument, to avoid code dup.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


@classmethod
def process_deliver_event(
Expand All @@ -157,9 +271,16 @@ def process_deliver_event(
:param tx_hash: the hash of a request tx to be processed.
:return: a dictionary with the request id and the data.
"""
return cls._process_event(
ledger_api, contract_address, tx_hash, "Deliver", "requestId", "data"
)
res = {}
for abi in partial_abis:
contract_instance = ledger_api.api.eth.contract(contract_address, abi=abi)
res = cls._process_event(
ledger_api, contract_instance, tx_hash, "Deliver", "requestId", "data"
)
if "error" not in res:
return res

return res

@classmethod
def get_block_number(
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/contracts/mech/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fingerprint:
README.md: bafybeibl4uw7rs6mwh7zuvdnqmj2o2xyr7nx5qk3w7torwx3jg6farn6ca
__init__.py: bafybeicx5pxh3cxnml2biuuoebvafvu5tvy6mgkzyjzuubuoeebb5yzjsm
build/mech.json: bafybeia3zf47nhljgahe4ijvw6mfcswhn6r5ntw572y63hbse7bvgsydaq
contract.py: bafybeifnpv6d7vwxayii4rsoauc6ymzujbxc5b4sqj56e544tapcjr32ji
contract.py: bafybeiexgja3hf2b3zyqjtelzzhv2vvtj655ivrzszkwqarhrapl6gfxim
fingerprint_ignore_patterns: []
contracts: []
class_name: Mech
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,50 @@
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
},
{
"internalType": "address",
"name": "operator",
"type": "address"
}
],
"name": "isApprovedForAll",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"internalType": "bool",
"name": "approved",
"type": "bool"
}
],
"name": "setApprovalForAll",
"outputs": [
],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "",
"deployedBytecode": "",
Expand Down
34 changes: 33 additions & 1 deletion packages/valory/contracts/transfer_nft_condition/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def build_order_tx(
))
return {"data": bytes.fromhex(data[2:])}


@classmethod
def balance_of(
cls,
Expand All @@ -86,3 +85,36 @@ def balance_of(
int(did, 16)
).call()
return dict(data=balance)

@classmethod
def is_approved_for_all(
cls,
ledger_api: LedgerApi,
contract_address: str,
account: str,
operator: str,
) -> JSONLike:
"""Get the balance of an address."""
contract_instance = cls.get_instance(ledger_api, contract_address)
is_approved = contract_instance.functions.isApprovedForAll(
Web3.to_checksum_address(account),
Web3.to_checksum_address(operator),
).call()
return dict(data=is_approved)

@classmethod
def build_set_approval_for_all_tx(
cls,
ledger_api: LedgerApi,
contract_address: str,
operator: str,
approved: bool,
) -> Dict[str, bytes]:
"""Build an TransferNftCondition approval."""
contract_instance = cls.get_instance(ledger_api, contract_address)
data = contract_instance.encodeABI("setApprovalForAll", args=(
Web3.to_checksum_address(operator),
approved,
))
return {"data": bytes.fromhex(data[2:])}

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
README.md: bafybeidiaep6cpoqlabnajvsgegpt72hqnbtozayicaxclzxzftopvlw5u
__init__.py: bafybeigz4j3ow7nagttswpbrpajnxqtxrl35oznejzxwi6bhfdeltnab5i
build/TransferNFTCondition.json: bafybeicovauoyn5bulnmz3ulkee56s46viemw3vpy7fk3zi4isol2jkdca
contract.py: bafybeiamwqz5tln7xknhoogsev36c3vhi4u4aovbwmowvpavhmzbtp7ywy
build/TransferNFTCondition.json: bafybeigxqddrgr4tuyhxyt5zblgnhwgpn4szjvyu5kvznslw4xfi7x2pp4
contract.py: bafybeibievlshamdrcanb7rd4625jhmvmdwspovpnyudshahjiq4vzvyrm
fingerprint_ignore_patterns: []
contracts: []
class_name: TransferNftCondition
Expand Down
Loading
Loading