diff --git a/packages/packages.json b/packages/packages.json index 27ad03efb..4c3cd1983 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -12,13 +12,13 @@ "contract/valory/service_staking_token/0.1.0": "bafybeid44l7qekvkwkvmfl4kcqchnaktttacp7lbx464mzqqs5cnefj35e", "contract/valory/transfer_nft_condition/0.1.0": "bafybeicgpoag2lymofz3vnen76q7gtig5hzimn32o57php4uerr6t25em4", "skill/valory/market_manager_abci/0.1.0": "bafybeidygkw7mwhbk3ry3au5c5265vms5eti375v5jthd4be5dfnnoache", - "skill/valory/decision_maker_abci/0.1.0": "bafybeibvq365gs7ibi7bkzoqyiirdcbpros2q7z3zpsqxhbcfy5d77y7je", - "skill/valory/trader_abci/0.1.0": "bafybeibss6panq224ec5eecn2jh5lqzyvptahnlrtxcfz6gvej5mdtdqei", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibcuvrm5fvmh7nuee4tmbof6debprdqzhvhdpzp2dbddtwva4wz3y", + "skill/valory/decision_maker_abci/0.1.0": "bafybeignpcrzh2kc6ocr5egdzqhz4ngu5nribh3iqrlyuqcfp6gazmj37e", + "skill/valory/trader_abci/0.1.0": "bafybeigs5lfin2xbs2ecmli6gqsi2aqmzzi35ka3j5xuqq75p5jd2rryxe", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeihisayejfjykvocyk36lgfkiwskqc5i5fma4efevt6rvke6nwsfqy", "skill/valory/staking_abci/0.1.0": "bafybeicrp3dbvxcb2wa7kdgpkxu7aqji5fwq6icwcfw7anfcpqv26irsr4", "skill/valory/check_stop_trading_abci/0.1.0": "bafybeiedpw6gudh7ddrcfpggnbxmbfaqn57a5geg645c2ymuzwy3rtckii", - "agent/valory/trader/0.1.0": "bafybeieqcfsz3bgh5kkw5fg3zb7laznfv57riclspqfe4eooi4wkq5ds2e", - "service/valory/trader/0.1.0": "bafybeieqm5hdfk22mnqtw4onc3oyqccu6yydop7hdrmuqsucja7vvv55bq" + "agent/valory/trader/0.1.0": "bafybeidhvaty4exupd4x2d757qprcnsnlxaqworv5co33zi2ibat3nlmri", + "service/valory/trader/0.1.0": "bafybeibrj3mit6ntdwtlb3m4iymvlrdlpg53sfncu7bzcbal7yqqvy523i" }, "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 b777d25e9..1ca32a3a4 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -43,10 +43,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeidw4mbx3os3hmv7ley7b3g3gja7ydpitr7mxbjpwzxin2mzyt5yam - valory/termination_abci:0.1.0:bafybeihq6qtbwt6i53ayqym63vhjexkcppy26gguzhhjqywfmiuqghvv44 - valory/transaction_settlement_abci:0.1.0:bafybeigtzlk4uakmd54rxnznorcrstsr52kta474lgrnvx5ovr546vj7sq -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibcuvrm5fvmh7nuee4tmbof6debprdqzhvhdpzp2dbddtwva4wz3y +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeihisayejfjykvocyk36lgfkiwskqc5i5fma4efevt6rvke6nwsfqy - valory/market_manager_abci:0.1.0:bafybeidygkw7mwhbk3ry3au5c5265vms5eti375v5jthd4be5dfnnoache -- valory/decision_maker_abci:0.1.0:bafybeibvq365gs7ibi7bkzoqyiirdcbpros2q7z3zpsqxhbcfy5d77y7je -- valory/trader_abci:0.1.0:bafybeibss6panq224ec5eecn2jh5lqzyvptahnlrtxcfz6gvej5mdtdqei +- valory/decision_maker_abci:0.1.0:bafybeignpcrzh2kc6ocr5egdzqhz4ngu5nribh3iqrlyuqcfp6gazmj37e +- valory/trader_abci:0.1.0:bafybeigs5lfin2xbs2ecmli6gqsi2aqmzzi35ka3j5xuqq75p5jd2rryxe - valory/staking_abci:0.1.0:bafybeicrp3dbvxcb2wa7kdgpkxu7aqji5fwq6icwcfw7anfcpqv26irsr4 - valory/check_stop_trading_abci:0.1.0:bafybeiedpw6gudh7ddrcfpggnbxmbfaqn57a5geg645c2ymuzwy3rtckii - valory/mech_interact_abci:0.1.0:bafybeib3aytq2a5hk6vjsak3eznuilndx4p53utdylbyhcmt6ty7kk6euq diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index f267fc119..058c2348e 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:bafybeieqcfsz3bgh5kkw5fg3zb7laznfv57riclspqfe4eooi4wkq5ds2e +agent: valory/trader:0.1.0:bafybeidhvaty4exupd4x2d757qprcnsnlxaqworv5co33zi2ibat3nlmri number_of_agents: 4 deployment: {} --- diff --git a/packages/valory/skills/decision_maker_abci/behaviours/base.py b/packages/valory/skills/decision_maker_abci/behaviours/base.py index 36784a714..d009e305d 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/base.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/base.py @@ -65,7 +65,6 @@ WaitableConditionType = Generator[None, None, bool] - # setting the safe gas to 0 means that all available gas will be used # which is what we want in most cases # more info here: https://safe-docs.dev.gnosisdev.com/safe/docs/contracts_tx_execution/ diff --git a/packages/valory/skills/decision_maker_abci/behaviours/order_subscription.py b/packages/valory/skills/decision_maker_abci/behaviours/order_subscription.py index eac6e4e8a..50bd2b2c0 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/order_subscription.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/order_subscription.py @@ -65,6 +65,8 @@ def __init__(self, **kwargs: Any) -> None: self.approval_tx: str = "" self.balance: int = 0 self.agreement_id: str = "" + self.credits_per_req: int = 0 + self.pending_reqs: int = 0 def _get_condition_ids( self, agreement_id_seed: str, did_doc: Dict[str, Any] @@ -251,15 +253,59 @@ def _prepare_approval_tx( ) return True + def _get_pending_requests(self) -> Generator[None, None, bool]: + """Get the required balance for the subscription.""" + result = yield from self._mech_contract_interact( + contract_callable="get_pending_requests", + data_key="pending_requests", + placeholder="pending_reqs", + sender_address=self.synchronized_data.safe_contract_address, + ) + if not result: + self.context.logger.info("Could not get the pending requests.") + return False + + return result + + def _get_nevermined_price(self) -> Generator[None, None, bool]: + """Get the price of the subscription.""" + result = yield from self._mech_contract_interact( + contract_callable="get_price", + data_key="price", + placeholder="credits_per_req", + ) + if not result: + self.context.logger.info("Could not get the price.") + return False + + return result + def _should_purchase(self) -> Generator[None, None, bool]: """Check if the subscription should be purchased.""" if not self.params.use_nevermined: self.context.logger.info("Nevermined subscriptions are turned off.") return False - has_balance = yield from self._has_positive_nft_balance() - # in case there is no balance on the safe, we purchase - return not has_balance + result = yield from self._get_nevermined_price() + if not result: + return False + + result = yield from self._get_pending_requests() + if not result: + return False + + result = yield from self._get_nft_balance( + self.token_address, + self.synchronized_data.safe_contract_address, + zero_x_transformer(no_did_prefixed(self.did)), + ) + if not result: + self.context.logger.warning("Failed to get balance") + return False + + credits_required = (self.pending_reqs + 1) * self.credits_per_req + + return credits_required > self.balance def get_payload_content(self) -> Generator[None, None, str]: """Get the payload.""" diff --git a/packages/valory/skills/decision_maker_abci/skill.yaml b/packages/valory/skills/decision_maker_abci/skill.yaml index 4630ee44f..8e1250ba1 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -12,14 +12,14 @@ fingerprint: README.md: bafybeia367zzdwndvlhw27rvnwodytjo3ms7gbc3q7mhrrjqjgfasnk47i __init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky - behaviours/base.py: bafybeicg37b76cic7zuy2uvskhl7ohgv74o74w2fjbojwydhvh3hrywoz4 + behaviours/base.py: bafybeidmbu5ymqjbxhnb6nu5zx3tnc77gq7tzwitjo7eq65hhpga3sj23q behaviours/bet_placement.py: bafybeib7jgq7iyfoyj3ur3xkj6knh7t7vr32kc743ztyjskkdevyh6l75q behaviours/blacklisting.py: bafybeid2kwsrq3ityeqsixalpaxwwiduo3lvqs5uzqhw5yfccqz5hqm6im behaviours/claim_subscription.py: bafybeihv5dg74deifzk46ppdwcvz6lgamgl6m7qr6sgqv2zie35j2576ca behaviours/decision_receive.py: bafybeid35xch5vsuuvtebu2yqedzeybbvc3kbt4d7q62efevhribmzg5gq behaviours/decision_request.py: bafybeibtvdjisudxyj677b7yctxnyo3tnrqdugevbfs27fmqnbo23cfexe behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm - behaviours/order_subscription.py: bafybeifygejified3yoza3gy4g7ina6m4lmz4pp2abtwfuwrmiwznnvrua + behaviours/order_subscription.py: bafybeie47vysxtchiicqfqa3gwwq4s7542wqpmywdswvd6jsgwba6v6fxq behaviours/randomness.py: bafybeidmr33teizrs4uxlo5tdz766ds6os4pe5lttstm7jpmhgmjz5ti3q behaviours/reedem.py: bafybeihwe4azke5zbdu4rhhsx3bmjgnkagwkuowyowvkure2do2rg4ainy behaviours/round_behaviour.py: bafybeidrks62unrnoyp3jnbz2nozgnittfntyknymuuja7jwcsjuap4fve diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 7891429a4..b0f0d2cca 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:bafybeigtzlk4uakmd54rxnznorcrstsr52kta474lgrnvx5ovr546vj7sq - valory/termination_abci:0.1.0:bafybeihq6qtbwt6i53ayqym63vhjexkcppy26gguzhhjqywfmiuqghvv44 - valory/market_manager_abci:0.1.0:bafybeidygkw7mwhbk3ry3au5c5265vms5eti375v5jthd4be5dfnnoache -- valory/decision_maker_abci:0.1.0:bafybeibvq365gs7ibi7bkzoqyiirdcbpros2q7z3zpsqxhbcfy5d77y7je -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibcuvrm5fvmh7nuee4tmbof6debprdqzhvhdpzp2dbddtwva4wz3y +- valory/decision_maker_abci:0.1.0:bafybeignpcrzh2kc6ocr5egdzqhz4ngu5nribh3iqrlyuqcfp6gazmj37e +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeihisayejfjykvocyk36lgfkiwskqc5i5fma4efevt6rvke6nwsfqy - valory/staking_abci:0.1.0:bafybeicrp3dbvxcb2wa7kdgpkxu7aqji5fwq6icwcfw7anfcpqv26irsr4 - valory/check_stop_trading_abci:0.1.0:bafybeiedpw6gudh7ddrcfpggnbxmbfaqn57a5geg645c2ymuzwy3rtckii - valory/mech_interact_abci:0.1.0:bafybeib3aytq2a5hk6vjsak3eznuilndx4p53utdylbyhcmt6ty7kk6euq diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml index 960e65895..14aaaa5c7 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:bafybeih3enhagoql7kzpeyzzu2scpkif6y3ubakpralfnwxcvxexdyvy5i -- valory/decision_maker_abci:0.1.0:bafybeibvq365gs7ibi7bkzoqyiirdcbpros2q7z3zpsqxhbcfy5d77y7je +- valory/decision_maker_abci:0.1.0:bafybeignpcrzh2kc6ocr5egdzqhz4ngu5nribh3iqrlyuqcfp6gazmj37e - valory/staking_abci:0.1.0:bafybeicrp3dbvxcb2wa7kdgpkxu7aqji5fwq6icwcfw7anfcpqv26irsr4 - valory/mech_interact_abci:0.1.0:bafybeib3aytq2a5hk6vjsak3eznuilndx4p53utdylbyhcmt6ty7kk6euq behaviours: