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/audit points #184

Merged
merged 3 commits into from
Jun 8, 2023
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
10 changes: 5 additions & 5 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"contract/valory/keep3r_v1_library/0.1.0": "bafybeiguyavczsaebbh5docth3o6e36b24s46jynhvysewnk3hqim3a4qe",
"contract/valory/keep3r_test_job/0.1.0": "bafybeibwxwdzws5ahlb7soxxoxxa7byhhoo6vyfn3hqds4m7y2ectsawbm",
"contract/valory/keep3r_v1/0.1.0": "bafybeie4oivgk6ip4pgkrdcw2p4puxms6g5zs3pdhn7dytizayxoeiji5m",
"skill/valory/keep3r_job_abci/0.1.0": "bafybeihx6tt5oygfl2jzu2nobhqdyhbpivahvueo4evgn5wx6hqhfvstym",
"skill/valory/keep3r_abci/0.1.0": "bafybeifumgn6ful7556q7sduopb5dxjqeblusmsjs6szpgru5owcyfleyy",
"agent/valory/keep3r_bot/0.1.0": "bafybeiddsgqvjctqiruoacb7ynlatqm3uqk2w5wy7xmubjoizl5234ipkm",
"skill/valory/keep3r_job_abci/0.1.0": "bafybeifvmw4pjfg7fxka7drr75ylyyorpudw2aoq5ahdjzbq2colgdzsly",
"skill/valory/keep3r_abci/0.1.0": "bafybeiansgj6kn27xze3v7p7s6tklwyoshhgywi3kfudd74nxdo2lnp4su",
"agent/valory/keep3r_bot/0.1.0": "bafybeidhut7yja7jtebe2b3nqbl5ld7nsr64igt74f5dmhjwymuwlhy4fa",
"contract/valory/keep3r_job/0.1.0": "bafybeiajy32pvqdzbecg2obmlnzdg756srtsmfzn4ujl5ybclx4hfvceli",
"contract/valory/keep3r_v2/0.1.0": "bafybeifdya376uvb22otbkneinifqn5br3kjhmojqa42wsen2klt47477e",
"contract/valory/deposit_manager_job/0.1.0": "bafybeic42aa5nsnpgomshy3jfs4sbkl76f3avl6liqbos4frewjsdf473y",
"contract/valory/phuture_harvesting_job/0.1.0": "bafybeiadbv3duxjv72l6oaxbrt47y62skzl6mcnphqzsdmctbfuolbplti",
"contract/valory/keep3r_my_job/0.1.0": "bafybeihusyezmkz5htukocahbde5rqqyk3yhwmmygbuax37crbpbr4gkoy",
"service/valory/keep3r_bot/0.1.0": "bafybeic4sydscbrxit3ldkjlydyo3uof5rzte4foxxrdw25unpbx7rsbvi",
"service/valory/keep3r_bot_goerli/0.1.0": "bafybeiduw5w4utzb4oalipssgkodt36ywh4towyasn6su5mlhlj5ujcgc4",
"service/valory/keep3r_bot/0.1.0": "bafybeihedjd4sz6pcqjj4ovyliccjeiywghc2lm2g3vc2pjh4k25dn5u7m",
"service/valory/keep3r_bot_goerli/0.1.0": "bafybeid7zdfcqi44eyhzellkbrtmdq7v4jxlu24tz2ny7mhvipu2gaqrui",
"contract/valory/yearn_factory_harvest_job/0.1.0": "bafybeiddtfwxnejyyiagfmz7q6isue2j5kskiluxk2z2hgbumjjiqshy2e",
"protocol/valory/ledger_api/1.0.0": "bafybeigpn6ysm53qkcllkzgdwc5xxpxz32xn2zoux3phdm2i3yty2i3thu",
"connection/valory/ledger/0.19.0": "bafybeigvml36q4ic2tstc25xli5qw7hacykyudkuywfmc7qjb5kwfzhkka",
Expand Down
5 changes: 3 additions & 2 deletions packages/valory/agents/keep3r_bot/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ protocols:
skills:
- valory/abstract_abci:0.1.0:bafybeiet34ju7typtkqyfn572sacef5krrsb6d4vpfnviqi6kzunje3xny
- valory/abstract_round_abci:0.1.0:bafybeiadrj2jzptjh6jals7rc7tp6vbv64fll5d5ich4tlr6t7eh5nqflq
- valory/keep3r_abci:0.1.0:bafybeifumgn6ful7556q7sduopb5dxjqeblusmsjs6szpgru5owcyfleyy
- valory/keep3r_job_abci:0.1.0:bafybeihx6tt5oygfl2jzu2nobhqdyhbpivahvueo4evgn5wx6hqhfvstym
- valory/keep3r_abci:0.1.0:bafybeiansgj6kn27xze3v7p7s6tklwyoshhgywi3kfudd74nxdo2lnp4su
- valory/keep3r_job_abci:0.1.0:bafybeifvmw4pjfg7fxka7drr75ylyyorpudw2aoq5ahdjzbq2colgdzsly
- valory/registration_abci:0.1.0:bafybeickxljqvum42oei3vntqbtsd77nevoxdv5ypy43hlous2bnsefpi4
- valory/reset_pause_abci:0.1.0:bafybeifrjlalgcbb6zknkgxomfvgfqzmgi56hvcnjfplhlvrfou43epima
- valory/termination_abci:0.1.0:bafybeif2rm6wu2royxfeu4uefm6z323vrt5w5bawbqf3b3abaenpkrmyqi
Expand Down Expand Up @@ -240,6 +240,7 @@ models:
manual_gas_limit: ${int:5000000}
multisend_address: ${str:0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761}
raise_on_failed_simulation: ${bool:false}
slippage_tolerance: ${float:0.05}
curve_pool_contract_address: ${str:0x21410232B484136404911780bC32756D5d1a9Fa9}
use_flashbots: ${bool:false}
termination_sleep: 900
Expand Down
7 changes: 6 additions & 1 deletion packages/valory/services/keep3r_bot/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: bafybeig26ntff2vdtmum3crflwqrybmonwdxahvlrst2brnazbo3mjvtqu
fingerprint_ignore_patterns: []
agent: valory/keep3r_bot:0.1.0:bafybeiddsgqvjctqiruoacb7ynlatqm3uqk2w5wy7xmubjoizl5234ipkm
agent: valory/keep3r_bot:0.1.0:bafybeidhut7yja7jtebe2b3nqbl5ld7nsr64igt74f5dmhjwymuwlhy4fa
number_of_agents: 1
deployment:
tendermint:
Expand Down Expand Up @@ -36,6 +36,7 @@ extra:
on_chain_service_id: ${ON_CHAIN_SERVICE_ID:int:null}
share_tm_config_on_startup: ${USE_ACN:bool:false}
sleep_time: ${SLEEP_TIME:int:3}
slippage_tolerance: ${SLIPPAGE_TOLERANCE:float:0.05}
use_termination: ${USE_TERMINATION:bool:false}
use_flashbots: ${USE_FLASHBOTS:bool:true}
reset_tendermint_after: ${RESET_TENDERMINT_AFTER:int:2}
Expand Down Expand Up @@ -63,6 +64,7 @@ extra:
use_flashbots: ${USE_FLASHBOTS:bool:true}
reset_tendermint_after: ${RESET_TENDERMINT_AFTER:int:2}
supported_jobs_to_package_hash: ${JOBS_TO_HASH:list:[]}
slippage_tolerance: ${SLIPPAGE_TOLERANCE:float:0.05}
keep3r_v1_contract_address: ${KEEP3R_V1_ADDRESS:str:0x1cEB5cB57C4D4E2b2433641b95Dd330A33185A44}
keep3r_v2_contract_address: ${KEEP3R_V2_ADDRESS:str:0xeb02addCfD8B773A5FFA6B9d1FE99c566f8c44CC}
use_v2: ${USE_KEEPER_V2:bool:true}
Expand All @@ -86,6 +88,7 @@ extra:
share_tm_config_on_startup: ${USE_ACN:bool:true}
use_flashbots: ${USE_FLASHBOTS:bool:true}
supported_jobs_to_package_hash: ${JOBS_TO_HASH:list:[]}
slippage_tolerance: ${SLIPPAGE_TOLERANCE:float:0.05}
reset_tendermint_after: ${RESET_TENDERMINT_AFTER:int:2}
keep3r_v1_contract_address: ${KEEP3R_V1_ADDRESS:str:0x1cEB5cB57C4D4E2b2433641b95Dd330A33185A44}
keep3r_v2_contract_address: ${KEEP3R_V2_ADDRESS:str:0xeb02addCfD8B773A5FFA6B9d1FE99c566f8c44CC}
Expand All @@ -110,6 +113,7 @@ extra:
sleep_time: ${SLEEP_TIME:int:3}
use_termination: ${USE_TERMINATION:bool:false}
supported_jobs_to_package_hash: ${JOBS_TO_HASH:list:[]}
slippage_tolerance: ${SLIPPAGE_TOLERANCE:float:0.05}
reset_tendermint_after: ${RESET_TENDERMINT_AFTER:int:2}
keep3r_v1_contract_address: ${KEEP3R_V1_ADDRESS:str:0x1cEB5cB57C4D4E2b2433641b95Dd330A33185A44}
keep3r_v2_contract_address: ${KEEP3R_V2_ADDRESS:str:0xeb02addCfD8B773A5FFA6B9d1FE99c566f8c44CC}
Expand All @@ -133,6 +137,7 @@ extra:
use_termination: ${USE_TERMINATION:bool:false}
use_flashbots: ${USE_FLASHBOTS:bool:true}
sleep_time: ${SLEEP_TIME:int:3}
slippage_tolerance: ${SLIPPAGE_TOLERANCE:float:0.05}
reset_tendermint_after: ${RESET_TENDERMINT_AFTER:int:2}
supported_jobs_to_package_hash: ${JOBS_TO_HASH:list:[]}
keep3r_v1_contract_address: ${KEEP3R_V1_ADDRESS:str:0x1cEB5cB57C4D4E2b2433641b95Dd330A33185A44}
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/keep3r_bot_goerli/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: bafybeiblcg3qti2cyz4ytufdkmqzcm6svbo5cwgsu2srjovvljdi35iz6i
fingerprint_ignore_patterns: []
agent: valory/keep3r_bot:0.1.0:bafybeiddsgqvjctqiruoacb7ynlatqm3uqk2w5wy7xmubjoizl5234ipkm
agent: valory/keep3r_bot:0.1.0:bafybeidhut7yja7jtebe2b3nqbl5ld7nsr64igt74f5dmhjwymuwlhy4fa
number_of_agents: 4
deployment:
tendermint:
Expand Down
3 changes: 2 additions & 1 deletion packages/valory/skills/keep3r_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contracts: []
protocols: []
skills:
- valory/abstract_round_abci:0.1.0:bafybeiadrj2jzptjh6jals7rc7tp6vbv64fll5d5ich4tlr6t7eh5nqflq
- valory/keep3r_job_abci:0.1.0:bafybeihx6tt5oygfl2jzu2nobhqdyhbpivahvueo4evgn5wx6hqhfvstym
- valory/keep3r_job_abci:0.1.0:bafybeifvmw4pjfg7fxka7drr75ylyyorpudw2aoq5ahdjzbq2colgdzsly
- valory/registration_abci:0.1.0:bafybeickxljqvum42oei3vntqbtsd77nevoxdv5ypy43hlous2bnsefpi4
- valory/reset_pause_abci:0.1.0:bafybeifrjlalgcbb6zknkgxomfvgfqzmgi56hvcnjfplhlvrfou43epima
- valory/termination_abci:0.1.0:bafybeif2rm6wu2royxfeu4uefm6z323vrt5w5bawbqf3b3abaenpkrmyqi
Expand Down Expand Up @@ -136,6 +136,7 @@ models:
supported_jobs_to_package_hash:
- - '0xaed599aadfee8e32cedb59db2b1120d33a7bacfd'
- '0xaed599aadfee8e32cedb59db2b1120d33a7bacfd'
slippage_tolerance: 0.05
tendermint_check_sleep_delay: 3
tendermint_com_url: http://localhost:8080
tendermint_max_retries: 5
Expand Down
28 changes: 14 additions & 14 deletions packages/valory/skills/keep3r_job_abci/behaviours.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,10 +925,10 @@ def _get_gas_spent(self) -> Generator[None, None, str]:
"""Get the gas spent for the latest unbonding interval."""
keeper_address = self.synchronized_data.safe_contract_address
bonding_asset = self.params.k3pr_address
latest_unbonding_event = yield from self._get_latest_unbonding_event(
unbonding_events = yield from self._get_unbonding_events(
keeper_address, bonding_asset
)
if latest_unbonding_event is None or latest_unbonding_event == self._NO_EVENT:
if unbonding_events is None or len(unbonding_events) == 0:
# something went wrong, the keeper MUST have unbonded if we have reached this point
return CalculateSpentGasRound.ERROR_PAYLOAD

Expand All @@ -939,15 +939,18 @@ def _get_gas_spent(self) -> Generator[None, None, str]:
# something went wrong
return CalculateSpentGasRound.ERROR_PAYLOAD

# we start from the block the block in which the last withdraw event happened, or from the first block if we have
# never withdrawn
# the goal is to calculate the gas spent between the last two unbonding events
# we start from the block in which the last unbonding event happened
# in case there is no withdraw event, we start from block 0
# in case there is a withdraw event, we start from second to last unbonding event
# the fact that there is a withdraw event means that the keeper has already unbonded at least twice
from_block = (
0
if latest_withdraw_event == self._NO_EVENT
else latest_withdraw_event["block_number"]
else unbonding_events[-2]["block_number"]
)
# we end at the block in which the last unbonding event happened
to_block = latest_unbonding_event["block_number"]
to_block = unbonding_events[-1]["block_number"]

transactions = yield from self._get_safe_txs(
keeper_address, from_block, to_block
Expand Down Expand Up @@ -987,9 +990,9 @@ def _get_latest_withdrawal_event(
# events are sorted by block number
return withdrawal_events[-1]

def _get_latest_unbonding_event(
def _get_unbonding_events(
self, keeper_address: str, bonding_asset: str
) -> Generator[None, None, Optional[Dict]]:
) -> Generator[None, None, Optional[List[Dict]]]:
"""Get unbonding events"""
unbonding_events = yield from self.read_keep3r(
"get_unbonding_events",
Expand All @@ -1000,13 +1003,9 @@ def _get_latest_unbonding_event(
# something went wrong
return None

if len(unbonding_events) == 0:
# return the empty dict to indicate no unbondings
return self._NO_EVENT

# return the latest unbonding event
# events are sorted by block number
return unbonding_events[-1]
return unbonding_events

def _get_safe_txs(
self, safe_address: str, from_block: int, to_block: int
Expand Down Expand Up @@ -1092,7 +1091,8 @@ def get_tx(self) -> Generator[None, None, str]:
if min_eth_amount is None:
# something went wrong
return SwapAndDisburseRewardsRound.ERROR_PAYLOAD

# apply slippage tolerance
min_eth_amount = int(min_eth_amount * (1 - self.params.slippage_tolerance))
multisend_txs: List[Dict[str, Any]] = []
# 1. get the withdraw transaction
withdraw_tx = yield from self._get_withdraw_tx(
Expand Down
7 changes: 5 additions & 2 deletions packages/valory/skills/keep3r_job_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Any, Dict, List, Type

from aea.configurations.data_types import PublicId
from aea.exceptions import enforce

from packages.valory.skills.abstract_round_abci.base import AbciApp
from packages.valory.skills.abstract_round_abci.models import ApiSpecs, BaseParams
Expand Down Expand Up @@ -89,9 +90,11 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
"curve_pool_contract_address", kwargs, str
)
self.agent_surplus_share = self._ensure("agent_surplus_share", kwargs, float)
self.slippage_tolerance: float = self._ensure(
"slippage_tolerance", kwargs, float
)
multisend_address = kwargs.get("multisend_address", None)
if multisend_address is None:
raise ValueError("Multisend address not specified!")
enforce(multisend_address is not None, "Multisend address not specified!")
self.multisend_address = multisend_address
super().__init__(*args, **kwargs)

Expand Down
5 changes: 3 additions & 2 deletions packages/valory/skills/keep3r_job_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
README.md: bafybeidq32yfua6bopvzlo7xwpfdiz4bwr7txkv4vo4vxmjmvdthkr2cwe
__init__.py: bafybeifr6ekniqkhuvkyfw3xktsntjvjjye5vfyir2i5zrzc3bcud5vvqa
behaviours.py: bafybeibpesvx2rcxswmotx2jbog2l4wxgfc23vonvw64x2qfbx45pjzxse
behaviours.py: bafybeif42ubq7yhfyclavz5r37u776spsbxyqlwypi3sbul3gbdhygdqva
dialogues.py: bafybeidfvafboay732zd7ez4yblojbzohujfwtp3e5elit7ztenepk6q3a
dynamic_package_loader.py: bafybeifdp6ym6jjjqbcu4qcg5vkh2kksvowryvrfcjbklvhvs36653troe
fsm_specification.yaml: bafybeihjvacl6sclfyrntgqoxexfxjq2kfjeyc6whpo4wciynrs3plclxm
handlers.py: bafybeiflkitcwl4b4glto7xaf7oykdsutbsyr62fwzh4ycy6grvblnypya
io_/__init__.py: bafybeifxgmmwjqzezzn3e6keh2bfo4cyo7y5dq2ept3stfmgglbrzfl5rq
io_/loader.py: bafybeidbnhostvbufwc4z2ulcgzw3weyps4obpnofkuglaehz2jpwstpbq
models.py: bafybeidz7o7j5y3paczwsfabqd3xyg2xca2wi6milyeyq7mssrekddkcuu
models.py: bafybeibssadyunjcvjowon33lft4f3qxsoo5cmc2v6sjlyt4rtyet3nxhy
payloads.py: bafybeih4nbp77gimv4h3bcg3e7mutpb6h64ptzc3f5zmvw7kfpib3r2rs4
rounds.py: bafybeiausofail75f3ebjafjnibp6fhvmiangvk6bpm44yiee7p2knr4me
tests/__init__.py: bafybeicw6vp5sxxwr5p3dns6of2px4qizw4q2s55ozf5cu5uamfh3tlrby
Expand Down Expand Up @@ -149,6 +149,7 @@ models:
supported_jobs_to_package_hash:
- - '0xaed599aadfee8e32cedb59db2b1120d33a7bacfd'
- '0xaed599aadfee8e32cedb59db2b1120d33a7bacfd'
slippage_tolerance: 0.05
tendermint_check_sleep_delay: 3
tendermint_com_url: http://localhost:8080
tendermint_max_retries: 5
Expand Down