diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index 0d14ac321..63cbdfcf2 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -185,6 +185,7 @@ models: realitio_proxy_address: ${str:0xAB16D643bA051C11962DA645f74632d3130c81E2} realitio_address: ${str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${int:5} + slippage: ${float:0.01} --- public_id: valory/p2p_libp2p_client:0.1.0 type: connection diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 66c6c4cc7..5d1a90e9f 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -102,6 +102,7 @@ type: skill realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2} realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} + slippage: ${SLIPPAGE:float:0.01} benchmark_tool: &id005 args: log_dir: ${LOG_DIR:str:/benchmarks} @@ -164,6 +165,7 @@ type: skill realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2} realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} + slippage: ${SLIPPAGE:float:0.01} benchmark_tool: *id005 2: models: @@ -224,6 +226,7 @@ type: skill realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2} realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} + slippage: ${SLIPPAGE:float:0.01} benchmark_tool: *id005 3: models: @@ -284,6 +287,7 @@ type: skill realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2} realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} + slippage: ${SLIPPAGE:float:0.01} benchmark_tool: *id005 --- public_id: valory/ledger:0.19.0 diff --git a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py index de97764e4..fa7b027f7 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py @@ -31,6 +31,7 @@ from packages.valory.skills.decision_maker_abci.behaviours.base import ( DecisionMakerBaseBehaviour, WaitableConditionType, + remove_fraction_wei, ) from packages.valory.skills.decision_maker_abci.models import MultisendBatch from packages.valory.skills.decision_maker_abci.payloads import MultisigTxPayload @@ -199,7 +200,7 @@ def _calc_buy_amount(self) -> WaitableConditionType: ) return False - self.buy_amount = int(buy_amount) + self.buy_amount = remove_fraction_wei(buy_amount, self.params.slippage) return True def _build_buy_tx(self) -> WaitableConditionType: diff --git a/packages/valory/skills/decision_maker_abci/models.py b/packages/valory/skills/decision_maker_abci/models.py index 8bc558e9a..4b861687c 100644 --- a/packages/valory/skills/decision_maker_abci/models.py +++ b/packages/valory/skills/decision_maker_abci/models.py @@ -120,6 +120,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # 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) + # 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 = self._ensure("slippage", kwargs, float) super().__init__(*args, **kwargs) @property @@ -134,6 +137,20 @@ def prompt_template(self) -> PromptTemplate: """Get the prompt template as a string `PromptTemplate`.""" return PromptTemplate(self._prompt_template) + @property + def slippage(self) -> float: + """Get the slippage.""" + return self._slippage + + @slippage.setter + def slippage(self, slippage: float) -> None: + """Set the slippage.""" + if slippage < 0 or slippage > 1: + raise ValueError( + f"The configured slippage {slippage!r} is not in the range [0, 1]." + ) + self._slippage = slippage + def get_bet_amount(self, confidence: float) -> int: """Get the bet amount given a prediction's confidence.""" threshold = round(confidence, 1) diff --git a/packages/valory/skills/decision_maker_abci/skill.yaml b/packages/valory/skills/decision_maker_abci/skill.yaml index 24c9f8205..5231cadbd 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -180,6 +180,7 @@ models: realitio_proxy_address: '0xAB16D643bA051C11962DA645f74632d3130c81E2' realitio_address: '0x79e32aE03fb27B07C89c0c568F80287C01ca2E57' redeeming_batch_size: 5 + slippage: 0.01 class_name: DecisionMakerParams mech_response: args: diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 7e0d119a4..2b4d8b499 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -167,6 +167,7 @@ models: realitio_proxy_address: '0xAB16D643bA051C11962DA645f74632d3130c81E2' realitio_address: '0x79e32aE03fb27B07C89c0c568F80287C01ca2E57' redeeming_batch_size: 5 + slippage: 0.01 class_name: TraderParams network_subgraph: args: