From c3e9ca2583e20d80d3e5a9db6ede40948186b5d5 Mon Sep 17 00:00:00 2001 From: Divya-Solulab Date: Fri, 27 Sep 2024 21:21:03 +0530 Subject: [PATCH] fix: formatters --- packages/packages.json | 8 +- .../valory/agents/optimus/aea-config.yaml | 4 +- packages/valory/services/optimus/service.yaml | 2 +- .../liquidity_trader_abci/behaviours.py | 130 ++++++++++++------ .../skills/liquidity_trader_abci/models.py | 2 +- .../skills/liquidity_trader_abci/rounds.py | 5 +- .../skills/liquidity_trader_abci/skill.yaml | 6 +- packages/valory/skills/optimus_abci/models.py | 2 +- .../valory/skills/optimus_abci/skill.yaml | 4 +- 9 files changed, 101 insertions(+), 62 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index 22d24f9..eaf0ac6 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -8,10 +8,10 @@ "contract/valory/merkl_distributor/0.1.0": "bafybeihaqsvmncuzmwv2r6iuzc5t7ur6ugdhephz7ydftypksjidpsylbq", "contract/valory/staking_token/0.1.0": "bafybeifrvtkofw5c26b3irm6izqfdpik6vpjhm6hqwcdzx333h6vhdanai", "contract/valory/staking_activity_checker/0.1.0": "bafybeibjzsi2r5b6xd4iwl4wbwldptnynryzsdpifym4mkv32ynswx22ou", - "skill/valory/liquidity_trader_abci/0.1.0": "bafybeig5brc3h4mbquq6jvc6ygzydcuwk5aefxmgskytkzz6gxp2ukeigi", - "skill/valory/optimus_abci/0.1.0": "bafybeibrnhpcr6l4p5fmxspqkqkxg2pyxmbiwbwxb44qweucz73mmdwb34", - "agent/valory/optimus/0.1.0": "bafybeib3sapx5oxymxgcdkshct2qxwns3njl5zimo7swqrfgz6su6rxch4", - "service/valory/optimus/0.1.0": "bafybeidldvltwmftt6vl26nvqiolsv5pawgtyairiha4itbx3r7uayozey" + "skill/valory/liquidity_trader_abci/0.1.0": "bafybeibb37nibvq6ceseuptyqid6oevdr5taywmt5xrnyv4aom2yuboszy", + "skill/valory/optimus_abci/0.1.0": "bafybeiddcr6ynnhmpdxojtyf7inervcqjbar3wlujgauwvd27tuv2mctqe", + "agent/valory/optimus/0.1.0": "bafybeif57cip6khg67sczuw5rb77uzmuwmxdsmrzn2m44up2phktrill54", + "service/valory/optimus/0.1.0": "bafybeic2mihsbjf4cmgnztgcyvx3hluuicc6tgeja6dthflptgrur7b5iq" }, "third_party": { "protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi", diff --git a/packages/valory/agents/optimus/aea-config.yaml b/packages/valory/agents/optimus/aea-config.yaml index 36ed50e..b9f4494 100644 --- a/packages/valory/agents/optimus/aea-config.yaml +++ b/packages/valory/agents/optimus/aea-config.yaml @@ -35,8 +35,8 @@ protocols: skills: - valory/abstract_abci:0.1.0:bafybeidz54kvxhbdmpruzguuzzq7bjg4pekjb5amqobkxoy4oqknnobopu - valory/abstract_round_abci:0.1.0:bafybeiajjzuh6vf23crp55humonknirvv2f4s3dmdlfzch6tc5ow52pcgm -- valory/liquidity_trader_abci:0.1.0:bafybeig5brc3h4mbquq6jvc6ygzydcuwk5aefxmgskytkzz6gxp2ukeigi -- valory/optimus_abci:0.1.0:bafybeibrnhpcr6l4p5fmxspqkqkxg2pyxmbiwbwxb44qweucz73mmdwb34 +- valory/liquidity_trader_abci:0.1.0:bafybeibb37nibvq6ceseuptyqid6oevdr5taywmt5xrnyv4aom2yuboszy +- valory/optimus_abci:0.1.0:bafybeiddcr6ynnhmpdxojtyf7inervcqjbar3wlujgauwvd27tuv2mctqe - valory/registration_abci:0.1.0:bafybeiffipsowrqrkhjoexem7ern5ob4fabgif7wa6gtlszcoaop2e3oey - valory/reset_pause_abci:0.1.0:bafybeif4lgvbzsmzljesxbphycdv52ka7qnihyjrjpfaseclxadcmm6yiq - valory/termination_abci:0.1.0:bafybeiekkpo5qef5zaeagm3si6v45qxcojvtjqe4a5ceccvk4q7k3xi3bi diff --git a/packages/valory/services/optimus/service.yaml b/packages/valory/services/optimus/service.yaml index 04cec37..123bf69 100644 --- a/packages/valory/services/optimus/service.yaml +++ b/packages/valory/services/optimus/service.yaml @@ -6,7 +6,7 @@ aea_version: '>=1.0.0, <2.0.0' license: Apache-2.0 fingerprint: {} fingerprint_ignore_patterns: [] -agent: valory/optimus:0.1.0:bafybeib3sapx5oxymxgcdkshct2qxwns3njl5zimo7swqrfgz6su6rxch4 +agent: valory/optimus:0.1.0:bafybeif57cip6khg67sczuw5rb77uzmuwmxdsmrzn2m44up2phktrill54 number_of_agents: 1 deployment: {} --- diff --git a/packages/valory/skills/liquidity_trader_abci/behaviours.py b/packages/valory/skills/liquidity_trader_abci/behaviours.py index 94950ef..b853323 100644 --- a/packages/valory/skills/liquidity_trader_abci/behaviours.py +++ b/packages/valory/skills/liquidity_trader_abci/behaviours.py @@ -24,7 +24,18 @@ from abc import ABC from collections import defaultdict from enum import Enum -from typing import Any, Callable, Dict, Generator, List, Optional, Set, Tuple, Type, Union, cast +from typing import ( + Any, + Callable, + Dict, + Generator, + List, + Optional, + Set, + Tuple, + Type, + cast, +) from urllib.parse import urlencode from aea.configurations.data_types import PublicId @@ -103,7 +114,7 @@ HTTP_OK = [200, 201] UTF8 = "utf-8" STAKING_CHAIN = "optimism" -CAMPAIGN_TYPES = [1,2] +CAMPAIGN_TYPES = [1, 2] INTEGRATOR = "valory" WAITING_PERIOD_FOR_BALANCE_TO_REFLECT = 5 WaitableConditionType = Generator[None, None, Any] @@ -515,9 +526,11 @@ def _is_staking_kpi_met(self) -> Generator[None, None, Optional[bool]]: ) return None - multisig_nonces_since_last_cp = yield from self._get_multisig_nonces_since_last_cp( + multisig_nonces_since_last_cp = ( + yield from self._get_multisig_nonces_since_last_cp( chain=STAKING_CHAIN, multisig=self.params.safe_contract_addresses.get(STAKING_CHAIN), + ) ) if multisig_nonces_since_last_cp is None: return None @@ -773,7 +786,10 @@ def async_act(self) -> Generator: ), ) ) - if multisig_nonces_since_last_cp is not None and min_num_of_safe_tx_required is not None: + if ( + multisig_nonces_since_last_cp is not None + and min_num_of_safe_tx_required is not None + ): num_of_tx_left_to_meet_kpi = ( min_num_of_safe_tx_required - multisig_nonces_since_last_cp ) @@ -781,7 +797,7 @@ def async_act(self) -> Generator: self.context.logger.info( f"Number of tx left to meet KPI: {num_of_tx_left_to_meet_kpi}" ) - self.context.logger.info(f"Preparing vanity tx..") + self.context.logger.info("Preparing vanity tx..") vanity_tx_hex = yield from self._prepare_vanity_tx( chain=STAKING_CHAIN ) @@ -1290,7 +1306,7 @@ def _get_top_tokens_by_value(self) -> Generator[None, None, Optional[List[Any]]] "balance": balance, } ) - + # Fetch prices for tokens with balance greater than zero token_prices = yield from self._fetch_token_prices(token_balances) @@ -1309,13 +1325,15 @@ def _get_top_tokens_by_value(self) -> Generator[None, None, Optional[List[Any]]] # Sort tokens by value in descending order and add the highest ones token_balances.sort(key=lambda x: x["value"], reverse=True) - + tokens = [] for token_data in token_balances: if token_data["value"] > self.params.min_swap_amount_threshold: tokens.append(token_data) if len(tokens) == 2: - self.context.logger.info(f"Tokens selected for bridging/swapping: {tokens}") + self.context.logger.info( + f"Tokens selected for bridging/swapping: {tokens}" + ) break if len(tokens) < 2: @@ -1559,7 +1577,10 @@ def _build_bridge_swap_actions( # If either of the token to swap and destination token match, we need to check which token don't match and build the bridge swap action based on this assessment. if source_token0_chain == dest_chain or source_token1_chain == dest_chain: - if source_token0_address not in [dest_token0_address, dest_token1_address] or source_token0_chain != dest_chain: + if ( + source_token0_address not in [dest_token0_address, dest_token1_address] + or source_token0_chain != dest_chain + ): # for example :- from_tokens = [usdc, xdai], to_tokens = [xdai, weth], then the pair to be created is [usdc, weth] to_token = ( dest_token1_address @@ -1583,7 +1604,10 @@ def _build_bridge_swap_actions( } bridge_swap_actions.append(bridge_swap_action) - if source_token1_address not in [dest_token0_address, dest_token1_address] or source_token1_chain != dest_chain: + if ( + source_token1_address not in [dest_token0_address, dest_token1_address] + or source_token1_chain != dest_chain + ): to_token = ( dest_token0_address if source_token0_address == dest_token1_address @@ -1877,7 +1901,7 @@ def get_next_event(self) -> Generator[None, None, Tuple[str, Dict, Optional[Dict self.current_pool = current_pool self.store_current_pool() self.context.logger.info("Exit was successful! Removing current pool") - #when we exit the pool, it may take time to reflect the balance of our assets + # when we exit the pool, it may take time to reflect the balance of our assets yield from self.sleep(WAITING_PERIOD_FOR_BALANCE_TO_REFLECT) # If last action was Claim Rewards and it was successful we update the list of assets and the last_reward_claimed_timestamp @@ -2086,7 +2110,9 @@ def get_enter_pool_tx_hash( self._get_balance(chain, assets[1], positions), ] if any(amount == 0 or amount is None for amount in max_amounts_in): - self.context.logger.error(f"Insufficient balance for entering pool: {max_amounts_in}") + self.context.logger.error( + f"Insufficient balance for entering pool: {max_amounts_in}" + ) return None, None, None tx_hash, contract_address = yield from pool.enter( @@ -2316,28 +2342,34 @@ def get_exit_pool_tx_hash( def get_transaction_data_for_route( self, positions, action ) -> Generator[None, None, Dict]: + """Prepares the bridge swap actions""" bridge_and_swap_actions = {} routes = yield from self._fetch_routes(positions, action) if not routes: return {} for route in routes: - steps = route.get("steps", []) - all_steps_successful = True - bridge_and_swap_actions["actions"] = [] + all_steps_successful = True + bridge_and_swap_actions["actions"] = [] step_transactions = yield from self._get_step_transactions_data(route) total_gas_cost = 0 total_fee = 0 - total_fee += sum(float(tx_info.get("fee",0)) for tx_info in step_transactions) - total_gas_cost += sum(float(tx_info.get("gas_cost", 0)) for tx_info in step_transactions) - from_amount_usd = float(route.get("fromAmountUSD",0)) - to_amount_usd = float(route.get("toAmountUSD",0)) - is_profitable = self._is_route_profitable(from_amount_usd, to_amount_usd, total_fee, total_gas_cost) + total_fee += sum( + float(tx_info.get("fee", 0)) for tx_info in step_transactions + ) + total_gas_cost += sum( + float(tx_info.get("gas_cost", 0)) for tx_info in step_transactions + ) + from_amount_usd = float(route.get("fromAmountUSD", 0)) + to_amount_usd = float(route.get("toAmountUSD", 0)) + is_profitable = self._is_route_profitable( + from_amount_usd, to_amount_usd, total_fee, total_gas_cost + ) if not is_profitable: - self.context.logger.info(f"Switching to next route.") + self.context.logger.info("Switching to next route.") continue - + for tx_info in step_transactions: multisend_tx_hash = yield from self._build_multisend_tx(tx_info) if not multisend_tx_hash: @@ -2374,11 +2406,13 @@ def get_transaction_data_for_route( f"Simulation successful for bridge/swap tx: {tx_info.get('source_token_symbol')}({tx_info.get('from_chain')}) --> {tx_info.get('target_token_symbol')}({tx_info.get('to_chain')}). Tool used: {tx_info.get('tool')}" ) - payload_string = yield from self._build_safe_tx(from_chain, multisend_tx_hash, multisend_address) + payload_string = yield from self._build_safe_tx( + from_chain, multisend_tx_hash, multisend_address + ) if not payload_string: all_steps_successful = False break - + bridge_and_swap_actions["actions"].append( { "action": Action.BRIDGE_SWAP.value, @@ -2389,7 +2423,9 @@ def get_transaction_data_for_route( "to_token": tx_info.get("target_token"), "to_token_symbol": tx_info.get("target_token_symbol"), "payload": payload_string, - "safe_address": self.params.safe_contract_addresses.get(from_chain), + "safe_address": self.params.safe_contract_addresses.get( + from_chain + ), } ) @@ -2402,7 +2438,9 @@ def get_transaction_data_for_route( self.context.logger.error("NONE OF THE ROUTES WERE SUCCESSFUL!") return {} - def _build_safe_tx(self, from_chain, multisend_tx_hash, multisend_address) -> Generator[None, None, Optional[str]]: + def _build_safe_tx( + self, from_chain, multisend_tx_hash, multisend_address + ) -> Generator[None, None, Optional[str]]: safe_address = self.params.safe_contract_addresses.get(from_chain) safe_tx_hash = yield from self.contract_interact( performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore @@ -2478,7 +2516,9 @@ def _build_multisend_tx(self, tx_info) -> Generator[None, None, Optional[str]]: return multisend_tx_hash - def _get_step_transactions_data(self, route: Dict[str, Any]) -> Generator[None, None, Optional[List[Any]]]: + def _get_step_transactions_data( + self, route: Dict[str, Any] + ) -> Generator[None, None, Optional[List[Any]]]: step_transactions = [] steps = route.get("steps", []) for step in steps: @@ -2507,9 +2547,9 @@ def _get_step_transactions_data(self, route: Dict[str, Any]) -> Generator[None, step["action"]["toAddress"] = self.params.safe_contract_addresses.get( to_chain ) - tx_info = yield from self._get_step_transaction(step) + tx_info = yield from self._get_step_transaction(step) step_transactions.append(tx_info) - + return step_transactions def _get_step_transaction( @@ -2578,14 +2618,8 @@ def _get_step_transaction( gas_costs = estimate.get("gasCosts", []) fee = 0 gas_cost = 0 - fee += sum( - float(fee_cost.get("amountUSD", 0)) - for fee_cost in fee_costs - ) - gas_cost += sum( - float(gas_cost.get("amountUSD", 0)) - for gas_cost in gas_costs - ) + fee += sum(float(fee_cost.get("amountUSD", 0)) for fee_cost in fee_costs) + gas_cost += sum(float(gas_cost.get("amountUSD", 0)) for gas_cost in gas_costs) return { "source_token": source_token, @@ -2599,11 +2633,13 @@ def _get_step_transaction( "tool": tool, "data": data, "tx_hash": tx_hash, - "fee" : fee, - "gas_cost": gas_cost + "fee": fee, + "gas_cost": gas_cost, } - - def _fetch_routes(self, positions, action) -> Generator[None, None, Optional[Dict[str, Any]]]: + + def _fetch_routes( + self, positions, action + ) -> Generator[None, None, Optional[Dict[str, Any]]]: """Get transaction data for route from LiFi API""" from_chain = action.get("from_chain") to_chain = action.get("to_chain") @@ -2676,7 +2712,13 @@ def _fetch_routes(self, positions, action) -> Generator[None, None, Optional[Dic return routes - def _is_route_profitable(self, from_amount_usd: float, to_amount_usd: float, total_fee: float, total_gas_cost: float) -> bool: + def _is_route_profitable( + self, + from_amount_usd: float, + to_amount_usd: float, + total_fee: float, + total_gas_cost: float, + ) -> bool: """Check if the route is profitable""" allowed_fee_percentage = self.params.max_fee_percentage * 100 allowed_gas_percentage = self.params.max_gas_percentage * 100 @@ -2693,10 +2735,10 @@ def _is_route_profitable(self, from_amount_usd: float, to_amount_usd: float, tot fee_percentage > allowed_fee_percentage or gas_percentage > allowed_gas_percentage ): - self.context.logger.error(f"Route is not profitable!") + self.context.logger.error("Route is not profitable!") return False - self.context.logger.info(f"Route is profitable!") + self.context.logger.info("Route is profitable!") return True def _simulate_execution_bundle( diff --git a/packages/valory/skills/liquidity_trader_abci/models.py b/packages/valory/skills/liquidity_trader_abci/models.py index eb1d8e3..f25fbf2 100644 --- a/packages/valory/skills/liquidity_trader_abci/models.py +++ b/packages/valory/skills/liquidity_trader_abci/models.py @@ -25,7 +25,7 @@ from time import time from typing import Any, Dict, List, Optional -from aea.skills.base import Model, SkillContext +from aea.skills.base import Model from packages.valory.skills.abstract_round_abci.models import BaseParams from packages.valory.skills.abstract_round_abci.models import ( diff --git a/packages/valory/skills/liquidity_trader_abci/rounds.py b/packages/valory/skills/liquidity_trader_abci/rounds.py index 0c8c948..cc35b9f 100644 --- a/packages/valory/skills/liquidity_trader_abci/rounds.py +++ b/packages/valory/skills/liquidity_trader_abci/rounds.py @@ -416,10 +416,7 @@ class FailedMultiplexerRound(DegenerateRound): class LiquidityTraderAbciApp(AbciApp[Event]): - """ - LiquidityTraderAbciApp - - """ + """LiquidityTraderAbciApp""" initial_round_cls: AppState = CallCheckpointRound initial_states: Set[AppState] = { diff --git a/packages/valory/skills/liquidity_trader_abci/skill.yaml b/packages/valory/skills/liquidity_trader_abci/skill.yaml index 0efa478..b89c79a 100644 --- a/packages/valory/skills/liquidity_trader_abci/skill.yaml +++ b/packages/valory/skills/liquidity_trader_abci/skill.yaml @@ -7,16 +7,16 @@ license: Apache-2.0 aea_version: '>=1.0.0, <2.0.0' fingerprint: __init__.py: bafybeia7bn2ahqqwkf63ptje6rfnftuwrsp33sswgpcbh5osbesxxr6g4m - behaviours.py: bafybeigxzq7pbtmqwb37bz2cbndoeiehuodnbtx6dv34wrg26gnqnu23mu + behaviours.py: bafybeiaktfldwuypicsiqbyxjulesfxhfbbjzu6p7bwtpvfwx2cdyweqmq dialogues.py: bafybeiay23otskx2go5xhtgdwfw2kd6rxd62sxxdu3njv7hageorl5zxzm fsm_specification.yaml: bafybeiabbiulb7k6xkjysulmy6o4ugnhxlpp5jiaeextvwj65q4ttadoeq handlers.py: bafybeidxw2lvgiifmo4siobpwuwbxscuifrdo3gnkjyn6bgexotj5f7zf4 - models.py: bafybeiarqylk2bps7u35dfprufxalzcfjz2rdaxlmb5pxi5pmqdrejrs34 + models.py: bafybeiahzdqz6megfdtiskfnh2hxukkhvp7lpjbif47druqsdnlpnzijnq payloads.py: bafybeihi42vbsr2xyhzsp55tl6mqecqyy52jrhwjfw4trvrjlhfxuyaz3u pool_behaviour.py: bafybeiaheuesscgqzwjbpyrezgwpdbdfurlmfwbc462qv6rblwwxlx5dpm pools/balancer.py: bafybeigznhgv7ylo5dvlhxcqikhiuqlqtnx3ikv4tszyvkl2lpcuqgoa5u pools/uniswap.py: bafybeigmqptgmjaxscszohfusgxsexqyx4awuyw7p4g5l7k2qpeyq7vdcu - rounds.py: bafybeiby4imfhqadx5pgrb34c3mluysqbboldpsppg5bsh7k7pqxbkqryq + rounds.py: bafybeidorqqosfidfxqwwegjjifzuqapl65ndpdnakolhlwawf57moopli strategies/simple_strategy.py: bafybeiasu2nchowx6leksjllpuum4ckezxoj4o2m4sstavblplvvutmvzm strategy_behaviour.py: bafybeidk6sorg47kuuubamcccksi65x3txldyo7y2hm5opbye2ghmz2ljy fingerprint_ignore_patterns: [] diff --git a/packages/valory/skills/optimus_abci/models.py b/packages/valory/skills/optimus_abci/models.py index 9f724bb..5f3b152 100644 --- a/packages/valory/skills/optimus_abci/models.py +++ b/packages/valory/skills/optimus_abci/models.py @@ -28,9 +28,9 @@ from packages.valory.skills.abstract_round_abci.tests.data.dummy_abci.models import ( RandomnessApi as BaseRandomnessApi, ) +from packages.valory.skills.liquidity_trader_abci.models import Coingecko from packages.valory.skills.liquidity_trader_abci.models import ( Params as LiquidityTraderParams, - Coingecko ) from packages.valory.skills.liquidity_trader_abci.models import ( SharedState as BaseSharedState, diff --git a/packages/valory/skills/optimus_abci/skill.yaml b/packages/valory/skills/optimus_abci/skill.yaml index df46367..dc0e05d 100644 --- a/packages/valory/skills/optimus_abci/skill.yaml +++ b/packages/valory/skills/optimus_abci/skill.yaml @@ -12,7 +12,7 @@ fingerprint: dialogues.py: bafybeiafoomno5pn6qrx43jxf2opxkil5eg4nod6jhd5oqwwplfz4x6dke fsm_specification.yaml: bafybeiehe6ps7xi7i7tu4mduid7vbvszhsiu5juyard24i3nhtqgljpcza handlers.py: bafybeife4nrwqiwrx2ucza3vk6t5inpkncuewehtdnitax4lmqq2ptoona - models.py: bafybeicbr3lfurtfvr3by6xp5a3zzj245o37efhumus4qacjjcqezlyceq + models.py: bafybeibxpw4zmigtel3emgbz2jz6xgsfx7eavxvhqrqftwcsul6lwcpjou fingerprint_ignore_patterns: [] connections: [] contracts: [] @@ -22,7 +22,7 @@ skills: - valory/registration_abci:0.1.0:bafybeiffipsowrqrkhjoexem7ern5ob4fabgif7wa6gtlszcoaop2e3oey - valory/reset_pause_abci:0.1.0:bafybeif4lgvbzsmzljesxbphycdv52ka7qnihyjrjpfaseclxadcmm6yiq - valory/termination_abci:0.1.0:bafybeiekkpo5qef5zaeagm3si6v45qxcojvtjqe4a5ceccvk4q7k3xi3bi -- valory/liquidity_trader_abci:0.1.0:bafybeig5brc3h4mbquq6jvc6ygzydcuwk5aefxmgskytkzz6gxp2ukeigi +- valory/liquidity_trader_abci:0.1.0:bafybeibb37nibvq6ceseuptyqid6oevdr5taywmt5xrnyv4aom2yuboszy - valory/transaction_settlement_abci:0.1.0:bafybeielv6eivt2z6nforq43xewl2vmpfwpdu2s2vfogobziljnwsclmlm behaviours: main: