Skip to content

Commit

Permalink
Merge branch 'main' into chore/bump
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/packages.json
#	packages/valory/agents/trader/aea-config.yaml
#	packages/valory/services/trader/service.yaml
#	packages/valory/skills/trader_abci/skill.yaml
#	packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml
  • Loading branch information
Adamantios committed Nov 17, 2023
2 parents 9fc3451 + a38477b commit aea30aa
Show file tree
Hide file tree
Showing 16 changed files with 322 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ ce811dab0e95cdd63ea00e1ed8207801f464d773:packages/valory/contracts/service_staki
61e62bd62dcaae666f1bf25981d068e360d32322:packages/valory/skills/staking_abci/skill.yaml:generic-api-key:78
b520b0c67a9ae55ba501e1e9a99abfc0738e8d49:packages/valory/skills/staking_abci/skill.yaml:generic-api-key:78
61e62bd62dcaae666f1bf25981d068e360d32322:packages/valory/skills/staking_abci/skill.yaml:generic-api-key:78
4063acab1bf2654eeaa6fca86bfbc3f6ab57e399:packages/valory/services/trader/service.yaml:generic-api-key:9
10 changes: 5 additions & 5 deletions packages/packages.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"dev": {
"skill/valory/market_manager_abci/0.1.0": "bafybeihmz35htfojgocmmilhnve7cofdnqsb2sf3lnegefrvrcavux2gt4",
"skill/valory/decision_maker_abci/0.1.0": "bafybeia6hnoitsqqxjvkyxunaxtn6unktq35ej2omszf5g7daalhjnhz4u",
"skill/valory/trader_abci/0.1.0": "bafybeiewpgyx2n3cu2ji2llwfh7jfhr6ehmmclsh6kxowjc22whvrdbdae",
"skill/valory/decision_maker_abci/0.1.0": "bafybeihgh6fhhct4vyondradugbzb2h7fy4t7mzal35hfndhnyuy55nkui",
"skill/valory/trader_abci/0.1.0": "bafybeibth5damuje6bo7j6j3j4tgjdq2kk2vrmzmh4yeadlac7vztyeg6i",
"contract/valory/market_maker/0.1.0": "bafybeih4r35d3plsjw56ham6xvi6dn4semmuihc53lh3qofpwj242rnjkq",
"agent/valory/trader/0.1.0": "bafybeibt2ocowviekka55i3lyqqlgdach6jqh7mziui6wzswkwex6s3uga",
"service/valory/trader/0.1.0": "bafybeiboq3f57mg5wb65k5jsplipxnaxq7llufg2bqqsmhyuxszthkfxxa",
"agent/valory/trader/0.1.0": "bafybeiagh5kd4g7nletllq6ab25u3bfcx2dnjrzec7q56c6eqd3ts6bo74",
"service/valory/trader/0.1.0": "bafybeifqppgopytve2qe2bgz7vpgbk6dbvrydh3oyz5iuohtuqtiww3xru",
"contract/valory/erc20/0.1.0": "bafybeidpjppgs7jlig2gdpdr3a6q3etbejpxrifjhzlcufpo5zf23dqv7y",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeic4zu3sf4r4fkdvtsbcijwja54ewb6ereu4e4662ozyibmgrfpdse",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeievurlx6ef2h7fpu6defynfihedsfhhrx5ta7eomk6sq2knx2fkya",
"contract/valory/mech/0.1.0": "bafybeigjn4q6mxal2hxzjyzldl4t4aykkpxjnbsgnli2c3xwf6binkmn74",
"contract/valory/realitio/0.1.0": "bafybeiamgkwwqhray4fs2hlipwxkq7mosmi7ev7jut4vneetaaycc4ruji",
"contract/valory/realitio_proxy/0.1.0": "bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4",
Expand Down
10 changes: 7 additions & 3 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeiergfseqtmsphdimzjijxezqyyhigktvqriw2xb4dyujim6s5dr4a
- valory/termination_abci:0.1.0:bafybeia73cl2vqj2uawt5lnoej3fzlhhum72i2p6ld4bbudd67lxb7f3cu
- valory/transaction_settlement_abci:0.1.0:bafybeifqase6vqfrakahogdl4h2hpxntug5ckioicfqlw2og5tn6htru3q
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeic4zu3sf4r4fkdvtsbcijwja54ewb6ereu4e4662ozyibmgrfpdse
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeievurlx6ef2h7fpu6defynfihedsfhhrx5ta7eomk6sq2knx2fkya
- valory/market_manager_abci:0.1.0:bafybeihmz35htfojgocmmilhnve7cofdnqsb2sf3lnegefrvrcavux2gt4
- valory/decision_maker_abci:0.1.0:bafybeia6hnoitsqqxjvkyxunaxtn6unktq35ej2omszf5g7daalhjnhz4u
- valory/trader_abci:0.1.0:bafybeiewpgyx2n3cu2ji2llwfh7jfhr6ehmmclsh6kxowjc22whvrdbdae
- valory/decision_maker_abci:0.1.0:bafybeihgh6fhhct4vyondradugbzb2h7fy4t7mzal35hfndhnyuy55nkui
- valory/trader_abci:0.1.0:bafybeibth5damuje6bo7j6j3j4tgjdq2kk2vrmzmh4yeadlac7vztyeg6i
- valory/staking_abci:0.1.0:bafybeiasziqxldcdaeqwjtyue5xyskeygrddrw5dwlg3zua4b56adakkna
default_ledger: ethereum
required_ledgers:
Expand Down Expand Up @@ -191,6 +191,8 @@ models:
realitio_proxy_address: ${str:0xAB16D643bA051C11962DA645f74632d3130c81E2}
realitio_address: ${str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57}
event_filtering_batch_size: ${int:5000}
reduce_factor: ${float:0.25}
max_filtering_retries: ${int:6}
redeeming_batch_size: ${int:5}
slippage: ${float:0.01}
policy_epsilon: ${float:0.1}
Expand All @@ -200,6 +202,8 @@ models:
"stabilityai-stable-diffusion-xl-beta-v2-2-2", "stabilityai-stable-diffusion-512-v2-1",
"stabilityai-stable-diffusion-768-v2-1"]}
staking_contract_address: ${str:0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C}
agent_balance_threshold: ${int:10000000000000000}
refill_check_interval: ${int:10}
---
public_id: valory/p2p_libp2p_client:0.1.0
type: connection
Expand Down
18 changes: 17 additions & 1 deletion packages/valory/services/trader/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: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeibt2ocowviekka55i3lyqqlgdach6jqh7mziui6wzswkwex6s3uga
agent: valory/trader:0.1.0:bafybeiagh5kd4g7nletllq6ab25u3bfcx2dnjrzec7q56c6eqd3ts6bo74
number_of_agents: 4
deployment: {}
---
Expand Down Expand Up @@ -105,6 +105,8 @@ type: skill
realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2}
realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57}
event_filtering_batch_size: ${EVENT_FILTERING_BATCH_SIZE:int:5000}
reduce_factor: ${REDUCE_FACTOR:float:0.25}
max_filtering_retries: ${MAX_FILTERING_RETRIES:int:6}
redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:1}
slippage: ${SLIPPAGE:float:0.01}
policy_epsilon: ${POLICY_EPSILON:float:0.1}
Expand All @@ -114,6 +116,8 @@ type: skill
"stabilityai-stable-diffusion-xl-beta-v2-2-2", "stabilityai-stable-diffusion-512-v2-1",
"stabilityai-stable-diffusion-768-v2-1"]}
staking_contract_address: ${STAKING_CONTRACT_ADDRESS:str:0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C}
agent_balance_threshold: ${AGENT_BALANCE_THRESHOLD:int:10000000000000000}
refill_check_interval: ${REFILL_CHECK_INTERVAL:int:10}
benchmark_tool: &id005
args:
log_dir: ${LOG_DIR:str:/benchmarks}
Expand Down Expand Up @@ -179,6 +183,8 @@ type: skill
realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2}
realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57}
event_filtering_batch_size: ${EVENT_FILTERING_BATCH_SIZE:int:5000}
reduce_factor: ${REDUCE_FACTOR:float:0.25}
max_filtering_retries: ${MAX_FILTERING_RETRIES:int:6}
redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:1}
slippage: ${SLIPPAGE:float:0.01}
policy_epsilon: ${POLICY_EPSILON:float:0.1}
Expand All @@ -188,6 +194,8 @@ type: skill
"stabilityai-stable-diffusion-xl-beta-v2-2-2", "stabilityai-stable-diffusion-512-v2-1",
"stabilityai-stable-diffusion-768-v2-1"]}
staking_contract_address: ${STAKING_CONTRACT_ADDRESS:str:0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C}
agent_balance_threshold: ${AGENT_BALANCE_THRESHOLD:int:10000000000000000}
refill_check_interval: ${REFILL_CHECK_INTERVAL:int:10}
benchmark_tool: *id005
2:
models:
Expand Down Expand Up @@ -251,6 +259,8 @@ type: skill
realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2}
realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57}
event_filtering_batch_size: ${EVENT_FILTERING_BATCH_SIZE:int:5000}
reduce_factor: ${REDUCE_FACTOR:float:0.25}
max_filtering_retries: ${MAX_FILTERING_RETRIES:int:6}
redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:1}
slippage: ${SLIPPAGE:float:0.01}
policy_epsilon: ${POLICY_EPSILON:float:0.1}
Expand All @@ -260,6 +270,8 @@ type: skill
"stabilityai-stable-diffusion-xl-beta-v2-2-2", "stabilityai-stable-diffusion-512-v2-1",
"stabilityai-stable-diffusion-768-v2-1"]}
staking_contract_address: ${STAKING_CONTRACT_ADDRESS:str:0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C}
agent_balance_threshold: ${AGENT_BALANCE_THRESHOLD:int:10000000000000000}
refill_check_interval: ${REFILL_CHECK_INTERVAL:int:10}
benchmark_tool: *id005
3:
models:
Expand Down Expand Up @@ -323,6 +335,8 @@ type: skill
realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2}
realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57}
event_filtering_batch_size: ${EVENT_FILTERING_BATCH_SIZE:int:5000}
reduce_factor: ${REDUCE_FACTOR:float:0.25}
max_filtering_retries: ${MAX_FILTERING_RETRIES:int:6}
redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:1}
slippage: ${SLIPPAGE:float:0.01}
policy_epsilon: ${POLICY_EPSILON:float:0.1}
Expand All @@ -332,6 +346,8 @@ type: skill
"stabilityai-stable-diffusion-xl-beta-v2-2-2", "stabilityai-stable-diffusion-512-v2-1",
"stabilityai-stable-diffusion-768-v2-1"]}
staking_contract_address: ${STAKING_CONTRACT_ADDRESS:str:0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C}
agent_balance_threshold: ${AGENT_BALANCE_THRESHOLD:int:10000000000000000}
refill_check_interval: ${REFILL_CHECK_INTERVAL:int:10}
benchmark_tool: *id005
---
public_id: valory/ledger:0.19.0
Expand Down
89 changes: 63 additions & 26 deletions packages/valory/skills/decision_maker_abci/behaviours/reedem.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,10 @@ def _check_already_redeemed(self) -> WaitableConditionType:
self.redeeming_progress.check_to_block = self.latest_block_number
self.redeeming_progress.check_started = True

n_retries = 0
from_block = self.redeeming_progress.check_from_block
batch_size = self.params.event_filtering_batch_size
for from_block in range(
self.redeeming_progress.check_from_block,
self.redeeming_progress.check_to_block,
batch_size,
):
while from_block < self.redeeming_progress.check_to_block:
max_to_block = from_block + batch_size
to_block = min(max_to_block, self.redeeming_progress.check_to_block)
result = yield from self._conditional_tokens_interact(
Expand All @@ -428,16 +426,33 @@ def _check_already_redeemed(self) -> WaitableConditionType:
to_block=to_block,
**kwargs,
)
if not result:

if not result and n_retries == self.params.max_filtering_retries:
err = "Skipping the redeeming round as the RPC is misbehaving."
self.context.logger.error(err)
return False

if not result:
n_retries += 1
keep_fraction = (1 - self.params.reduce_factor) ** n_retries
step = int(batch_size * keep_fraction)
msg = f"Repeating this call with a decreased batch size of {step}."
self.context.logger.warning(msg)
from_block += step
continue

self.redeeming_progress.payouts.update(self.payouts_batch)
self.redeeming_progress.check_from_block = to_block
from_block += batch_size

return True

def _clean_redeem_info(self) -> Generator:
def _clean_redeem_info(self) -> WaitableConditionType:
"""Clean the redeeming information based on whether any positions have already been redeemed."""
yield from self.wait_for_condition_with_sleep(self._check_already_redeemed)
success = yield from self._check_already_redeemed()
if not success:
return False

payout_so_far = sum(self.redeeming_progress.payouts.values())
if payout_so_far > 0:
self.trades = {
Expand All @@ -449,6 +464,8 @@ def _clean_redeem_info(self) -> Generator:
msg = f"The total payout so far has been {self.wei_to_native(payout_so_far)} wxDAI."
self.context.logger.info(msg)

return True

def _realitio_interact(
self, contract_callable: str, data_key: str, placeholder: str, **kwargs: Any
) -> WaitableConditionType:
Expand Down Expand Up @@ -528,12 +545,10 @@ def get_claim_params(self) -> WaitableConditionType:
)
self.redeeming_progress.claim_started = True

n_retries = 0
from_block = self.redeeming_progress.claim_from_block
batch_size = self.params.event_filtering_batch_size
for from_block in range(
self.redeeming_progress.claim_from_block,
self.redeeming_progress.claim_to_block,
batch_size,
):
while from_block < self.redeeming_progress.claim_to_block:
max_to_block = from_block + batch_size
to_block = min(max_to_block, self.redeeming_progress.claim_to_block)
result = yield from self._realitio_interact(
Expand All @@ -544,18 +559,29 @@ def get_claim_params(self) -> WaitableConditionType:
to_block=to_block,
question_id=self.current_question_id,
)
if not result:

if not result and n_retries == self.params.max_filtering_retries:
err = "Skipping redeeming for the current position as the RPC is misbehaving."
self.context.logger.error(err)
return False

if not result:
n_retries += 1
keep_fraction = (1 - self.params.reduce_factor) ** n_retries
step = int(batch_size * keep_fraction)
msg = f"Repeating this call with a decreased batch size of {step}."
self.context.logger.warning(msg)
from_block += step
continue

self.redeeming_progress.answered.extend(self.claim_params_batch)
self.redeeming_progress.claim_from_block = to_block
from_block += batch_size

return True

def _build_claim_data(self) -> WaitableConditionType:
"""Prepare the safe tx to claim the winnings."""
if not self.redeeming_progress.claim_finished:
yield from self.wait_for_condition_with_sleep(self.get_claim_params)

claim_params = self.redeeming_progress.claim_params
if claim_params is None:
self.context.logger.error(
Expand Down Expand Up @@ -603,7 +629,7 @@ def _build_redeem_data(self) -> WaitableConditionType:
self.multisend_batches.append(batch)
return True

def _prepare_single_redeem(self) -> Generator:
def _prepare_single_redeem(self) -> WaitableConditionType:
"""Prepare a multisend transaction for a single redeeming action."""
yield from self.wait_for_condition_with_sleep(self._check_already_resolved)
steps = []
Expand All @@ -614,13 +640,19 @@ def _prepare_single_redeem(self) -> Generator:
yield from self.wait_for_condition_with_sleep(self._get_history_hash)
if not self.is_history_hash_null:
# 2. claim the winnings if claiming has not been done yet
if not self.redeeming_progress.claim_finished:
success = yield from self.get_claim_params()
if not success:
return False
steps.append(self._build_claim_data)

# 3. we always redeem the position
steps.append(self._build_redeem_data)
for build_step in steps:
yield from self.wait_for_condition_with_sleep(build_step)

return True

def _process_candidate(
self, redeem_candidate: Trade
) -> Generator[None, None, bool]:
Expand All @@ -646,7 +678,10 @@ def _process_candidate(
self.context.logger.info("Position's redeeming amount is dust.")
return False

yield from self._prepare_single_redeem()
success = yield from self._prepare_single_redeem()
if not success:
return False

self._expected_winnings += self.current_claimable_amount
return True

Expand Down Expand Up @@ -735,15 +770,17 @@ def async_act(self) -> Generator:
self._load_progress()

if not self.redeeming_progress.check_finished:
yield from self._clean_redeem_info()
success = yield from self._clean_redeem_info()

agent = self.context.agent_address
redeem_tx_hex = yield from self._prepare_safe_tx()
tx_submitter = policy = utilized_tools = None
if redeem_tx_hex is not None:
tx_submitter = self.matching_round.auto_round_id()
policy = self.policy.serialize()
utilized_tools = json.dumps(self.utilized_tools)
tx_submitter = policy = utilized_tools = redeem_tx_hex = None

if success:
redeem_tx_hex = yield from self._prepare_safe_tx()
if redeem_tx_hex is not None:
tx_submitter = self.matching_round.auto_round_id()
policy = self.policy.serialize()
utilized_tools = json.dumps(self.utilized_tools)

payload = RedeemPayload(
agent, tx_submitter, redeem_tx_hex, policy, utilized_tools
Expand Down
22 changes: 14 additions & 8 deletions packages/valory/skills/decision_maker_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,26 +197,32 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
check_prompt_template(self.prompt_template)
multisend_address = kwargs.get("multisend_address", None)
enforce(multisend_address is not None, "Multisend address not specified!")
self.multisend_address = multisend_address
self.dust_threshold = self._ensure("dust_threshold", kwargs, int)
self.conditional_tokens_address = self._ensure(
self.multisend_address: str = multisend_address
self.dust_threshold: int = self._ensure("dust_threshold", kwargs, int)
self.conditional_tokens_address: str = self._ensure(
"conditional_tokens_address", kwargs, str
)
self.realitio_proxy_address = self._ensure(
self.realitio_proxy_address: str = self._ensure(
"realitio_proxy_address", kwargs, str
)
self.realitio_address = self._ensure("realitio_address", kwargs, str)
self.realitio_address: str = self._ensure("realitio_address", kwargs, str)
# this is the maximum batch size that will be used when filtering blocks for events.
# increasing this number allows for faster filtering operations,
# but also increases the chances of getting a timeout error from the RPC
self.event_filtering_batch_size = self._ensure(
self.event_filtering_batch_size: int = self._ensure(
"event_filtering_batch_size", kwargs, int
)
self.reduce_factor: float = self._ensure("reduce_factor", kwargs, float)
self.max_filtering_retries: int = self._ensure(
"max_filtering_retries", kwargs, int
)
# this is the max number of redeeming operations that will be batched on a single multisend transaction.
# increasing this number equals fewer fees but more chances for the transaction to fail
self.redeeming_batch_size = self._ensure("redeeming_batch_size", kwargs, int)
self.redeeming_batch_size: int = self._ensure(
"redeeming_batch_size", kwargs, int
)
# a slippage in the range of [0, 1] to apply to the `minOutcomeTokensToBuy` when buying shares on a fpmm
self._slippage = 0.0
self._slippage: float = 0.0
self.slippage: float = self._ensure("slippage", kwargs, float)
self.epsilon: float = self._ensure("policy_epsilon", kwargs, float)
self.agent_registry_address: str = self._ensure(
Expand Down
Loading

0 comments on commit aea30aa

Please sign in to comment.