diff --git a/packages/packages.json b/packages/packages.json index 2fed3098d..c750358c0 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -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", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index cfbd813fd..d694808e9 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -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 @@ -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: diff --git a/packages/valory/contracts/mech/contract.py b/packages/valory/contracts/mech/contract.py index 387448ac7..83929a02f 100644 --- a/packages/valory/contracts/mech/contract.py +++ b/packages/valory/contracts/mech/contract.py @@ -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. @@ -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.""" @@ -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)) @@ -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 @classmethod def process_deliver_event( @@ -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( diff --git a/packages/valory/contracts/mech/contract.yaml b/packages/valory/contracts/mech/contract.yaml index 501a28279..db90e3c53 100644 --- a/packages/valory/contracts/mech/contract.yaml +++ b/packages/valory/contracts/mech/contract.yaml @@ -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 diff --git a/packages/valory/contracts/transfer_nft_condition/build/TransferNFTCondition.json b/packages/valory/contracts/transfer_nft_condition/build/TransferNFTCondition.json index efb696034..ddfe15e47 100644 --- a/packages/valory/contracts/transfer_nft_condition/build/TransferNFTCondition.json +++ b/packages/valory/contracts/transfer_nft_condition/build/TransferNFTCondition.json @@ -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": "", diff --git a/packages/valory/contracts/transfer_nft_condition/contract.py b/packages/valory/contracts/transfer_nft_condition/contract.py index 1fee90e96..b20b37ad4 100644 --- a/packages/valory/contracts/transfer_nft_condition/contract.py +++ b/packages/valory/contracts/transfer_nft_condition/contract.py @@ -70,7 +70,6 @@ def build_order_tx( )) return {"data": bytes.fromhex(data[2:])} - @classmethod def balance_of( cls, @@ -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:])} + diff --git a/packages/valory/contracts/transfer_nft_condition/contract.yaml b/packages/valory/contracts/transfer_nft_condition/contract.yaml index 740beafda..6d14d34b2 100644 --- a/packages/valory/contracts/transfer_nft_condition/contract.yaml +++ b/packages/valory/contracts/transfer_nft_condition/contract.yaml @@ -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 diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 27639cba3..473a5a769 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -7,7 +7,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeigelmjanmd57y2dshhqll5jjja2xeizn4vjgsuwanqtlehespvnoe +agent: valory/trader:0.1.0:bafybeiexmyrslgxqnygcbir5ws26ltcjv5qo7e7plqapoo3j22xuqpfy64 number_of_agents: 4 deployment: {} --- @@ -120,9 +120,9 @@ type: skill ["escrow_payment_condition_address", "0x9dDC4F1Ea5b94C138A23b60EC48c0d01d172629a"], ["lock_payment_condition_address", "0xDE85A368Ee6f374d236500d176814365370778dA"], ["transfer_nft_condition_address", "0xbBa4A25262745a55f020D0a3E9a82c25bb6F4979"], - ["token_address", "0x0000000000000000000000000000000000000000"], ["order_address", + ["token_address", "0x80A9b55F8604acC26dF2Ac6e07F9dC5B0eAa05Ce"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], ["nft_amount", "100"], ["payment_token", - "0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], + "0x0000000000000000000000000000000000000000"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], ["price", "1000000000000000000"]]} benchmark_tool: &id004 args: @@ -215,9 +215,9 @@ type: skill ["escrow_payment_condition_address", "0x9dDC4F1Ea5b94C138A23b60EC48c0d01d172629a"], ["lock_payment_condition_address", "0xDE85A368Ee6f374d236500d176814365370778dA"], ["transfer_nft_condition_address", "0xbBa4A25262745a55f020D0a3E9a82c25bb6F4979"], - ["token_address", "0x0000000000000000000000000000000000000000"], ["order_address", + ["token_address", "0x80A9b55F8604acC26dF2Ac6e07F9dC5B0eAa05Ce"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], ["nft_amount", "100"], ["payment_token", - "0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], + "0x0000000000000000000000000000000000000000"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], ["price", "1000000000000000000"]]} benchmark_tool: *id004 2: @@ -308,9 +308,9 @@ type: skill ["escrow_payment_condition_address", "0x9dDC4F1Ea5b94C138A23b60EC48c0d01d172629a"], ["lock_payment_condition_address", "0xDE85A368Ee6f374d236500d176814365370778dA"], ["transfer_nft_condition_address", "0xbBa4A25262745a55f020D0a3E9a82c25bb6F4979"], - ["token_address", "0x0000000000000000000000000000000000000000"], ["order_address", + ["token_address", "0x80A9b55F8604acC26dF2Ac6e07F9dC5B0eAa05Ce"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], ["nft_amount", "100"], ["payment_token", - "0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], + "0x0000000000000000000000000000000000000000"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], ["price", "1000000000000000000"]]} benchmark_tool: *id004 3: @@ -401,9 +401,9 @@ type: skill ["escrow_payment_condition_address", "0x9dDC4F1Ea5b94C138A23b60EC48c0d01d172629a"], ["lock_payment_condition_address", "0xDE85A368Ee6f374d236500d176814365370778dA"], ["transfer_nft_condition_address", "0xbBa4A25262745a55f020D0a3E9a82c25bb6F4979"], - ["token_address", "0x0000000000000000000000000000000000000000"], ["order_address", + ["token_address", "0x80A9b55F8604acC26dF2Ac6e07F9dC5B0eAa05Ce"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], ["nft_amount", "100"], ["payment_token", - "0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], + "0x0000000000000000000000000000000000000000"], ["order_address", "0xc7751eff5396a846e7bc83ac31d3cb7d37cb49e4"], ["price", "1000000000000000000"]]} benchmark_tool: *id004 --- diff --git a/packages/valory/skills/decision_maker_abci/behaviours/base.py b/packages/valory/skills/decision_maker_abci/behaviours/base.py index aa5df3865..d46268aed 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/base.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/base.py @@ -99,6 +99,23 @@ def __init__(self, **kwargs: Any) -> None: self._policy: Optional[EGreedyPolicy] = None self._inflight_strategy_req: Optional[str] = None + @property + def subscription_params(self) -> Dict[str, Any]: + """Get the subscription params.""" + return self.params.mech_to_subscription_params + + @property + def did(self) -> str: + """Get the did.""" + subscription_params = self.subscription_params + return subscription_params["did"] + + @property + def token_address(self) -> str: + """Get the token address.""" + subscription_params = self.subscription_params + return subscription_params["token_address"] + def strategy_exec(self, strategy: str) -> Optional[Tuple[str, str]]: """Get the executable strategy file's content.""" return self.shared_state.strategies_executables.get(strategy, None) @@ -574,17 +591,6 @@ def __init__(self, **kwargs: Any) -> None: super().__init__(**kwargs) self.balance: int = 0 - @property - def subscription_params(self) -> Dict[str, Any]: - """Get the subscription params.""" - return self.params.mech_to_subscription_params - - @property - def did(self) -> str: - """Get the did.""" - subscription_params = self.subscription_params - return subscription_params["did"] - @property def escrow_payment_condition_address(self) -> str: """Get the escrow payment address.""" @@ -603,12 +609,6 @@ def transfer_nft_condition_address(self) -> str: subscription_params = self.subscription_params return subscription_params["transfer_nft_condition_address"] - @property - def token_address(self) -> str: - """Get the token address.""" - subscription_params = self.subscription_params - return subscription_params["token_address"] - @property def order_address(self) -> str: """Get the order address.""" diff --git a/packages/valory/skills/decision_maker_abci/behaviours/decision_request.py b/packages/valory/skills/decision_maker_abci/behaviours/decision_request.py index d2ceb1f36..6e1e84785 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/decision_request.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/decision_request.py @@ -32,6 +32,9 @@ from packages.valory.contracts.erc20.contract import ERC20 from packages.valory.contracts.gnosis_safe.contract import GnosisSafeContract +from packages.valory.contracts.transfer_nft_condition.contract import ( + TransferNftCondition, +) from packages.valory.protocols.contract_api import ContractApiMessage from packages.valory.skills.abstract_round_abci.base import get_name from packages.valory.skills.abstract_round_abci.io_.store import SupportedFiletype @@ -55,6 +58,7 @@ METADATA_FILENAME = "metadata.json" V1_HEX_PREFIX = "f01" Ox = "0x" +APPROVE_MECH = True @dataclass @@ -160,11 +164,75 @@ def _send_metadata_to_ipfs( def _get_price(self) -> WaitableConditionType: """Get the price of the mech request.""" + if self.params.use_nevermined: + # when we use nevermined, we don't need to pay for the mech request + self.price = 0 + return True result = yield from self._mech_contract_interact( "get_price", "price", get_name(DecisionRequestBehaviour.price) ) return result + def _is_approved_for_all(self) -> Generator[None, None, Optional[bool]]: + """Check whether the mech is approved to spend the mech subscription.""" + response_msg = yield from self.get_contract_api_response( + performative=ContractApiMessage.Performative.GET_STATE, # type: ignore + contract_address=self.token_address, + contract_id=str(TransferNftCondition.contract_id), + contract_callable="is_approved_for_all", + account=self.synchronized_data.safe_contract_address, + operator=self.params.mech_agent_address, + ) + if response_msg.performative != ContractApiMessage.Performative.STATE: + self.context.logger.info( + f"Could not get `TransferNftCondition.is_approved_for_all`: {response_msg}" + ) + return None + + return response_msg.state.body.get("data") + + def _check_nevermined_subscription(self) -> WaitableConditionType: + """Approve the mech to spend the mech subscription.""" + if not self.params.use_nevermined: + # do nothing if we don't use nevermined + return True + + is_approved_for_all = yield from self._is_approved_for_all() + if is_approved_for_all is None: + # something went wrong when checking the mech approval + return False + if is_approved_for_all: + # the mech is already approved to spend the mech subscription + self.context.logger.info( + "The mech is already approved to spend the mech subscription." + ) + return True + + response_msg = yield from self.get_contract_api_response( + performative=ContractApiMessage.Performative.GET_STATE, # type: ignore + contract_address=self.token_address, + contract_id=str(TransferNftCondition.contract_id), + contract_callable="build_set_approval_for_all_tx", + operator=self.params.mech_agent_address, + approved=APPROVE_MECH, + ) + + if response_msg.performative != ContractApiMessage.Performative.STATE: + self.context.logger.info(f"Could not build withdraw tx: {response_msg}") + return False + + data = response_msg.state.body.get("data") + if data is None: + self.context.logger.info(f"Could not build withdraw tx: {response_msg}") + return False + + batch = MultisendBatch( + to=self.token_address, + data=HexBytes(data), + ) + self.multisend_batches.append(batch) + return True + def _build_unwrap_tx(self) -> WaitableConditionType: """Exchange wxDAI to xDAI.""" response_msg = yield from self.get_contract_api_response( @@ -286,6 +354,7 @@ def _prepare_safe_tx(self) -> Generator[None, None, str]: self._send_metadata_to_ipfs, self._get_price, self._check_unwrap, + self._check_nevermined_subscription, self._build_request_data, ): yield from self.wait_for_condition_with_sleep(step) diff --git a/packages/valory/skills/decision_maker_abci/skill.yaml b/packages/valory/skills/decision_maker_abci/skill.yaml index 2b0f9479c..29f366cac 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -12,12 +12,12 @@ fingerprint: README.md: bafybeia367zzdwndvlhw27rvnwodytjo3ms7gbc3q7mhrrjqjgfasnk47i __init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky - behaviours/base.py: bafybeigel7rznswltgzvsdsdhi3afjfhwpapab52cggjtnxxpbr7oz2pre + behaviours/base.py: bafybeigoxverx6e75jdzj54hsfyzgunofuy5nll5lbn52gxeyzo7jw6vyy behaviours/bet_placement.py: bafybeib7jgq7iyfoyj3ur3xkj6knh7t7vr32kc743ztyjskkdevyh6l75q behaviours/blacklisting.py: bafybeic7o2jzmhbamdcebbdjeie3dkm7y2wq7xutpeshqmrt2hdq65vlai behaviours/claim_subscription.py: bafybeihv5dg74deifzk46ppdwcvz6lgamgl6m7qr6sgqv2zie35j2576ca behaviours/decision_receive.py: bafybeig4gmlad7epkaao6nsfqya3zqhllt4hwiijtarcczmokxekxehrcu - behaviours/decision_request.py: bafybeicpvpsdbcfvtiapnprp4j45exy5atyshfwgzksj3jptstlv6kgiwy + behaviours/decision_request.py: bafybeico22ps3u7olsny5c2efki4x2tub726s4mpnqnsx7oyzv4yd5fa4y behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm behaviours/order_subscription.py: bafybeifygejified3yoza3gy4g7ina6m4lmz4pp2abtwfuwrmiwznnvrua behaviours/randomness.py: bafybeidmr33teizrs4uxlo5tdz766ds6os4pe5lttstm7jpmhgmjz5ti3q @@ -62,12 +62,12 @@ 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/transfer_nft_condition:0.1.0:bafybeigj46jcovsrfrfymdr37fym25k5s4dbrek5pzhshewstxjds76uyu +- valory/transfer_nft_condition:0.1.0:bafybeiab7p2jky5g6jjznpqkf4znyjp5ko466usgv5pntdlqi6uss456y4 protocols: - valory/contract_api:1.0.0:bafybeidgu7o5llh26xp3u3ebq3yluull5lupiyeu6iooi2xyymdrgnzq5i - valory/ledger_api:1.0.0:bafybeihdk6psr4guxmbcrc26jr2cbgzpd5aljkqvpwo64bvaz7tdti2oni diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 898eded3c..e64efc1d3 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -25,8 +25,8 @@ skills: - valory/transaction_settlement_abci:0.1.0:bafybeihaad5k6adwkqwc5pui243inep2kvw7k7pgwwqaykssyx7p64peyi - valory/termination_abci:0.1.0:bafybeihmqrvnzhptap62nchvocmu7tzl5d2o6k4eitkaiuvo7qwvsaedua - valory/market_manager_abci:0.1.0:bafybeib72jm7aznzhmtxnmwlpnse23xutnurexml57ovkn2zpr2gsmpvni -- valory/decision_maker_abci:0.1.0:bafybeiatntrgxmsmzfsuksits4mezhcmldogn7bcoqy6fztalhjhv65g7m -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeidtm6vd4pin35zwxiryzaagtwfkxgqtcevacbthoekgoi5yfsr4gm +- valory/decision_maker_abci:0.1.0:bafybeifharwkzhzh5ngtbky3zo55ik2eqjqrxxx4yqr4hiwmdoqyp2td54 +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibyxyafhqaud5yhx2hfubowhwqups6hn6umvuunlq5o4h7ax44guu - valory/staking_abci:0.1.0:bafybeidgivibaeant53uef3j2virsxlgr5kpd6lsenr7pjdhqktwbqxfye behaviours: main: diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml index c03e52cc2..4c7d63a28 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml @@ -21,7 +21,7 @@ protocols: - valory/ledger_api:1.0.0:bafybeihdk6psr4guxmbcrc26jr2cbgzpd5aljkqvpwo64bvaz7tdti2oni skills: - valory/abstract_round_abci:0.1.0:bafybeidyrcd4hxl4gq7xhkcd546wkidebbvt6vnomxmrdsja6shkpysh5u -- valory/decision_maker_abci:0.1.0:bafybeiatntrgxmsmzfsuksits4mezhcmldogn7bcoqy6fztalhjhv65g7m +- valory/decision_maker_abci:0.1.0:bafybeifharwkzhzh5ngtbky3zo55ik2eqjqrxxx4yqr4hiwmdoqyp2td54 - valory/staking_abci:0.1.0:bafybeidgivibaeant53uef3j2virsxlgr5kpd6lsenr7pjdhqktwbqxfye behaviours: main: