Skip to content

Commit

Permalink
feat: apply a slippage to the minOutcomeTokensToBuy
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantios committed Sep 6, 2023
1 parent 4e65968 commit d4f496c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions packages/valory/skills/decision_maker_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d4f496c

Please sign in to comment.