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

Make the strategy more sensible #72

Merged
merged 17 commits into from
Sep 7, 2023
Merged
Changes from 4 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
@@ -1,13 +1,13 @@
{
"dev": {
"skill/valory/market_manager_abci/0.1.0": "bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi",
"skill/valory/decision_maker_abci/0.1.0": "bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy",
"skill/valory/trader_abci/0.1.0": "bafybeigjfwyknvwpevqqavbj57lncpdd3ehvg73vit4nflcu5e2ue4pd6e",
"skill/valory/decision_maker_abci/0.1.0": "bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva",
"skill/valory/trader_abci/0.1.0": "bafybeihcdi3ccfk5g24luowanzshx62mmvzgkodi5az3imjchsx3kioywa",
"contract/valory/market_maker/0.1.0": "bafybeiftimqgvrbval2lxp7au6y72amioo4gtcdth2dflrbwa47i6opyb4",
"agent/valory/trader/0.1.0": "bafybeigu6x25vtbu44tiovd3dd7eygwwf4q6lgnafdswzvhtw26xu66udu",
"service/valory/trader/0.1.0": "bafybeignuhovmv5sbeyodkmgohntokcnm55yrscjd7bybrlq3sng2ytmvy",
"agent/valory/trader/0.1.0": "bafybeidwaaelw6pjl4azfhbvr2k5reywazy244k3tj74fl523lswzhvgeq",
"service/valory/trader/0.1.0": "bafybeidvydnmhv3jr22peqds545dy2odwiyqp465fpsidlw7bmqionovca",
"contract/valory/erc20/0.1.0": "bafybeifjwr6rwklgg2uk2zkfysn55qqy7dfi4jx7sek6lzdup37fynhpxe",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiebb35mjfl54woxgu2coald56v3wfgglm26tbdizhmzautquxw6fa",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiauossubd7ikfyuml4kot4motcxnn2tbe7xubelc3ut4hdyanwfvu",
"contract/valory/mech/0.1.0": "bafybeie753wdqks6k4x5fqlpo7tgll2avutjcaodpwlptqvzefsi5xbvai",
"contract/valory/realitio/0.1.0": "bafybeigb722aznqhc5lsbt3dn4bpyaqe5hnl5onmnestqmzliwtvl3eaom",
"contract/valory/realitio_proxy/0.1.0": "bafybeibvndq6756qck7forgeavhdbn6ykgqs2ufyg7n5g6qdfpveatxuwy",
7 changes: 4 additions & 3 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
@@ -41,10 +41,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeifoihgilpfr76hc5skzspm6qehkwivx7ld2cy3veipcsi4gr2c7na
- valory/termination_abci:0.1.0:bafybeigcsls72uosoui2y5ppmnvsljjhnxakkeh3fdohklcg66aqq4g7xu
- valory/transaction_settlement_abci:0.1.0:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiebb35mjfl54woxgu2coald56v3wfgglm26tbdizhmzautquxw6fa
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiauossubd7ikfyuml4kot4motcxnn2tbe7xubelc3ut4hdyanwfvu
- valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi
- valory/decision_maker_abci:0.1.0:bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy
- valory/trader_abci:0.1.0:bafybeigjfwyknvwpevqqavbj57lncpdd3ehvg73vit4nflcu5e2ue4pd6e
- valory/decision_maker_abci:0.1.0:bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva
- valory/trader_abci:0.1.0:bafybeihcdi3ccfk5g24luowanzshx62mmvzgkodi5az3imjchsx3kioywa
default_ledger: ethereum
required_ledgers:
- ethereum
@@ -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
6 changes: 5 additions & 1 deletion packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeigu6x25vtbu44tiovd3dd7eygwwf4q6lgnafdswzvhtw26xu66udu
agent: valory/trader:0.1.0:bafybeidwaaelw6pjl4azfhbvr2k5reywazy244k3tj74fl523lswzhvgeq
number_of_agents: 4
deployment: {}
---
@@ -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
8 changes: 8 additions & 0 deletions packages/valory/skills/decision_maker_abci/behaviours/base.py
Original file line number Diff line number Diff line change
@@ -58,6 +58,14 @@
SAFE_GAS = 0


def remove_fraction_wei(amount: int, fraction: float) -> int:
"""Removes the given fraction from the given integer amount and returns the value as an integer."""
if 0 <= fraction <= 1:
keep_percentage = 1 - fraction
return int(amount * keep_percentage)
raise ValueError(f"The given fraction {fraction!r} is not in the range [0, 1].")


class DecisionMakerBaseBehaviour(BaseBehaviour, ABC):
"""Represents the base class for the decision-making FSM behaviour."""

Original file line number Diff line number Diff line change
@@ -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:
Original file line number Diff line number Diff line change
@@ -28,6 +28,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 (
MechInteractionResponse,
@@ -273,7 +274,7 @@ def _is_profitable(self, confidence: float, vote: int) -> bool:
"""Whether the decision is profitable or not."""
bet = self.synchronized_data.sampled_bet
bet_amount = self.params.get_bet_amount(confidence)
net_bet_amount = int(bet_amount * (1 - self.wei_to_native(bet.fee)))
net_bet_amount = remove_fraction_wei(bet_amount, self.wei_to_native(bet.fee))
num_shares, available_shares = self._calc_binary_shares(net_bet_amount, vote)
mech_price = self.synchronized_data.mech_price
bet_threshold = self.params.bet_threshold
17 changes: 17 additions & 0 deletions packages/valory/skills/decision_maker_abci/models.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 5 additions & 4 deletions packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
@@ -12,10 +12,10 @@ fingerprint:
README.md: bafybeia367zzdwndvlhw27rvnwodytjo3ms7gbc3q7mhrrjqjgfasnk47i
__init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a
behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky
behaviours/base.py: bafybeibrqxw7jdslsew226tss3p3s7fhj6rkwz6fig46zgnp54ijyspgly
behaviours/bet_placement.py: bafybeicdmayxmxvydechibri7z45wrx7n354eny4s5aval5mk2pqdszh64
behaviours/base.py: bafybeiaxgbkrrskfod55lhynd4ttkwrn6qwzugfmmwikzod4ar6pmjmcu4
behaviours/bet_placement.py: bafybeifwwvvwh4qgf3jkyvza4wfvjv63il2xewsklsjtpyanp23y6hg2aa
behaviours/blacklisting.py: bafybeicvespraci44y2dtddy4wi7cdhjuyk6crjs7ztnssm2rcrovha3hm
behaviours/decision_receive.py: bafybeiagj6ilqz7rfjaqa4b3rtunyhigtxhwkb4auylquq77ltjdczksj4
behaviours/decision_receive.py: bafybeihe73gjp2dv5czue4mxpxtcsssde7xwwh4fkouzozckkkfzaubnhy
behaviours/decision_request.py: bafybeifjlh5cfitjd6wjcvcgoji2bhsi4r5nzpqocotwprmn26eiphlmqq
behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm
behaviours/reedem.py: bafybeib25frcafu6iikppidwqqovwjkzkxif6m3f4crmklohpj6yixprsq
@@ -24,7 +24,7 @@ fingerprint:
dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm
fsm_specification.yaml: bafybeigrljw66oxyvn5wqecfgkcx7ozkjg7xuv75zcjmo25fft37qyed6y
handlers.py: bafybeihj33szgrcxnpd73s4nvluyxwwsvhjum2cuq3ilhhe6vfola3k7vy
models.py: bafybeibyfpucv2e6kltxpjkwobeg3u2ejrceba6cyuecuwbmpv4q7zmu3m
models.py: bafybeibqou3ryuszu2vbwdp5b7fkj5oxmflgh3z3a7tuajbdxgzdolgmee
payloads.py: bafybeifbnyviargcj5w5kbuuvc3o4y5sdogtuynd2b4ca4xsfbi3cqcwlm
redeem_info.py: bafybeie3s7syjr5dfwg33l4663zhkeiokvpulenndwboiyv4imzxr4bdyy
rounds.py: bafybeihpstybessozkb3hjxhf3gvf323zw4d575ihmxrsuzcyhqtbsruoq
@@ -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:
5 changes: 3 additions & 2 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi
- valory/termination_abci:0.1.0:bafybeigcsls72uosoui2y5ppmnvsljjhnxakkeh3fdohklcg66aqq4g7xu
- valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi
- valory/decision_maker_abci:0.1.0:bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiebb35mjfl54woxgu2coald56v3wfgglm26tbdizhmzautquxw6fa
- valory/decision_maker_abci:0.1.0:bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiauossubd7ikfyuml4kot4motcxnn2tbe7xubelc3ut4hdyanwfvu
behaviours:
main:
args: {}
@@ -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:
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ contracts: []
protocols: []
skills:
- valory/abstract_round_abci:0.1.0:bafybeif3cqkks5qx3lqi6nwwhebcirhazt2vidw3sueeqsyxvjeszjt3om
- valory/decision_maker_abci:0.1.0:bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy
- valory/decision_maker_abci:0.1.0:bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva
behaviours:
main:
args: {}