Skip to content

Commit

Permalink
Merge pull request #108 from valory-xyz/refactor/profitability
Browse files Browse the repository at this point in the history
Refactor profitability decision
  • Loading branch information
Adamantios authored Oct 13, 2023
2 parents ddb6055 + bbb4159 commit 6f3ab9f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
12 changes: 6 additions & 6 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": "bafybeigmy3g2klkzdhttti2ouxf575ua5y7ajmh4a3yfpukeukqxjky47m",
"skill/valory/decision_maker_abci/0.1.0": "bafybeibijhfe2owjeioofnyfbwmla36dksm7rh2tq7acwpdg4sbzoglt6q",
"skill/valory/trader_abci/0.1.0": "bafybeic25p753rteoq6nxrj2hx7sowjkg2v3vjmomeufbfc6gpyrth34wa",
"skill/valory/decision_maker_abci/0.1.0": "bafybeihtydxuzyd35cq23xoxbytpxebpbn3rsyqf4bt6z4sleflqck6riy",
"skill/valory/trader_abci/0.1.0": "bafybeignhbqiajnhec7xipsibm3vpjovxboaak3n3kd2ozc27sjaw7733m",
"contract/valory/market_maker/0.1.0": "bafybeif4mm2s3gxtvp227yypkcnna5ftec7vajcftvtbdmqddh7nprah5m",
"agent/valory/trader/0.1.0": "bafybeidlzrnqm4i6255lilhmufdu3tfjvstxr37slfi73c3s3satcbqmgi",
"service/valory/trader/0.1.0": "bafybeifowg6z52r6xucwhqipcohuxylr6nqsv4e4cdeuio3benhtmf3frm",
"contract/valory/erc20/0.1.0": "bafybeig53maqwplpbzd63niffnslqcwsr3wse6lytwg772373s33mbpmaa",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiglmk6oe2yjsnx73w52c5qx4jbtxfzaf5qvzs2xfsyna3p3agg234",
"agent/valory/trader/0.1.0": "bafybeibpafgfqxva32x4y22zsw6pjur43xcbirjizlornqwvl5vykopdgy",
"service/valory/trader/0.1.0": "bafybeiadxvczqasdeukfmt2c2h66z4dxtgeyzinio7cm4alm2meboh65ye",
"contract/valory/erc20/0.1.0": "bafybeibysifjwhlcn7nntsjkowdmja53ed6urfzypi6sxfc7chtheecvpi",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeigfkdkpkrktw4wippon6al7vreg3qh7xax33xafomepy6xrv5paa4",
"contract/valory/mech/0.1.0": "bafybeifaavuqr2bz7nypapjwkufc5c6vwxm5ifucmtd3w7sh42tne35nga",
"contract/valory/realitio/0.1.0": "bafybeic3wihpzz4deguslpzlnsgrlrabclq3njwuagyaiiv6rzqujfrs6e",
"contract/valory/realitio_proxy/0.1.0": "bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4",
Expand Down
8 changes: 4 additions & 4 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contracts:
- valory/gnosis_safe_proxy_factory:0.1.0:bafybeigxqwbd6wds57ecsfkl2hf4z4vbz5gokex6nutu5zcdpw6irh573y
- valory/service_registry:0.1.0:bafybeiebuuhs7fmigfh4c5dvzt6rbm5ekwrcnz7zouyjey7yyyqmpa6dyu
- valory/market_maker:0.1.0:bafybeif4mm2s3gxtvp227yypkcnna5ftec7vajcftvtbdmqddh7nprah5m
- valory/erc20:0.1.0:bafybeig53maqwplpbzd63niffnslqcwsr3wse6lytwg772373s33mbpmaa
- valory/erc20:0.1.0:bafybeibysifjwhlcn7nntsjkowdmja53ed6urfzypi6sxfc7chtheecvpi
- valory/multisend:0.1.0:bafybeig5byt5urg2d2bsecufxe5ql7f4mezg3mekfleeh32nmuusx66p4y
- valory/mech:0.1.0:bafybeifaavuqr2bz7nypapjwkufc5c6vwxm5ifucmtd3w7sh42tne35nga
- valory/conditional_tokens:0.1.0:bafybeif5jwc6owfe6brmqq5sfnhrwo2ajdtt4glrmyhlqxcvtkyofahwsa
Expand All @@ -41,10 +41,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeicpxn2khtaesuf4cq6ypwdmdmonlqroj2q2i6cxvpizc2y4cw66pe
- valory/termination_abci:0.1.0:bafybeieqm46zuccaagnko3qlw6p3nvoohdrfgvpmw467r5lyil2dqrzjsy
- valory/transaction_settlement_abci:0.1.0:bafybeia6cdxdlqrcwk2maw25fo7dafzd2p3rs7syropvufophk2pitzbwy
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiglmk6oe2yjsnx73w52c5qx4jbtxfzaf5qvzs2xfsyna3p3agg234
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeigfkdkpkrktw4wippon6al7vreg3qh7xax33xafomepy6xrv5paa4
- valory/market_manager_abci:0.1.0:bafybeigmy3g2klkzdhttti2ouxf575ua5y7ajmh4a3yfpukeukqxjky47m
- valory/decision_maker_abci:0.1.0:bafybeibijhfe2owjeioofnyfbwmla36dksm7rh2tq7acwpdg4sbzoglt6q
- valory/trader_abci:0.1.0:bafybeic25p753rteoq6nxrj2hx7sowjkg2v3vjmomeufbfc6gpyrth34wa
- valory/decision_maker_abci:0.1.0:bafybeihtydxuzyd35cq23xoxbytpxebpbn3rsyqf4bt6z4sleflqck6riy
- valory/trader_abci:0.1.0:bafybeignhbqiajnhec7xipsibm3vpjovxboaak3n3kd2ozc27sjaw7733m
default_ledger: ethereum
required_ledgers:
- ethereum
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/contracts/erc20/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fingerprint:
README.md: bafybeifmfma6rglvpa22odtozyosnp5mwljum64utxip2wgmezuhnjjjyi
__init__.py: bafybeia2k2vmq7lmd3uchmm6jmzj7ebqkogk5aolpw4nwsawnkgqfobltm
build/ERC20.json: bafybeiemn5b5nszuss7xj6lmvmjuendltp6wz7ubihdvd7c6wqw4bohbpa
contract.py: bafybeib257slx7p53emy7rrs6tpkbbzrfuv6gwvviuy27hboynqjsxbsj4
contract.py: bafybeigk7vgluyhpr65rllw4z5jrozjmrlufkxsfvnicuvpr5l5k3vmm6u
fingerprint_ignore_patterns: []
contracts: []
class_name: ERC20
Expand Down
2 changes: 1 addition & 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:bafybeidlzrnqm4i6255lilhmufdu3tfjvstxr37slfi73c3s3satcbqmgi
agent: valory/trader:0.1.0:bafybeibpafgfqxva32x4y22zsw6pjur43xcbirjizlornqwvl5vykopdgy
number_of_agents: 4
deployment: {}
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@


ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"
SLIPPAGE = 1.05


class DecisionReceiveBehaviour(DecisionMakerBaseBehaviour):
Expand Down Expand Up @@ -286,14 +287,19 @@ def _is_profitable(self, confidence: float, vote: int) -> bool:
bet_threshold = 0

potential_net_profit = num_shares - net_bet_amount - bet_threshold
is_profitable = potential_net_profit >= 0 and num_shares <= available_shares
shares_out = self.wei_to_native(num_shares)
available_in = self.wei_to_native(available_shares)
shares_out_of = f"{shares_out} / {available_in}"
is_profitable = potential_net_profit >= 0

if num_shares > available_shares * SLIPPAGE:
self.context.logger.warning(
"Kindly contemplate reducing your bet amount, as the pool's liquidity is low compared to your bet. "
"Consequently, this situation entails a higher level of risk as the obtained number of shares, "
"and therefore the potential net profit, will be lower than if the pool had higher liquidity!"
)

self.context.logger.info(
f"The current liquidity of the market is {bet.scaledLiquidityMeasure} xDAI. "
f"The potential net profit is {self.wei_to_native(potential_net_profit)} xDAI "
f"from buying {shares_out_of} shares for the option {bet.get_outcome(vote)}.\n"
f"from buying {self.wei_to_native(num_shares)} shares for the option {bet.get_outcome(vote)}.\n"
f"Decision for profitability of this market: {is_profitable}."
)

Expand Down
10 changes: 5 additions & 5 deletions packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ fingerprint:
README.md: bafybeia367zzdwndvlhw27rvnwodytjo3ms7gbc3q7mhrrjqjgfasnk47i
__init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a
behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky
behaviours/base.py: bafybeiato4qxnc2kjjdtttvqdna7dp4c5evlb6cus7h6eci7tj73tqnpey
behaviours/bet_placement.py: bafybeifwwvvwh4qgf3jkyvza4wfvjv63il2xewsklsjtpyanp23y6hg2aa
behaviours/base.py: bafybeidny4y4w4jbjbp5d5qivur6jm37fnuik4mqzchzshiuvpozxe7vwy
behaviours/bet_placement.py: bafybeiauzdizqawjgzc3ugx33vuh726e25juhacqdr7c6uztpn6tra5dva
behaviours/blacklisting.py: bafybeicvespraci44y2dtddy4wi7cdhjuyk6crjs7ztnssm2rcrovha3hm
behaviours/decision_receive.py: bafybeid54jwjs4lulcl2n2w7taxne3wqgsey6ppaidwr2up6bztyf35ghm
behaviours/decision_request.py: bafybeidlyl2ojmpfs2zkewoacraya2cbampo4ynqbqaocsoq7v2nif3ahi
behaviours/decision_receive.py: bafybeibfnucc444uqcythgsn4cawluubbi4u4q7ab4aqc4ts3lu4qnvhdq
behaviours/decision_request.py: bafybeiajbv3t6w4vz3u3bbqzaufjfi2znwsly4cvf55farwvp7y7c2jefm
behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm
behaviours/reedem.py: bafybeiccrnttqwf5vuf3lr55k5c6tsqsrekoypoag5gntyimjhbmuokkga
behaviours/round_behaviour.py: bafybeig4tdktyu6hapoqymnxh2bgpds547st6a44heue657wkctwe4gjvm
Expand Down Expand Up @@ -46,7 +46,7 @@ connections: []
contracts:
- valory/gnosis_safe:0.1.0:bafybeibt7arvjzz4ah24omst74f4sfjpzrdef76yti6ml7dopsauhdzeci
- valory/market_maker:0.1.0:bafybeif4mm2s3gxtvp227yypkcnna5ftec7vajcftvtbdmqddh7nprah5m
- valory/erc20:0.1.0:bafybeig53maqwplpbzd63niffnslqcwsr3wse6lytwg772373s33mbpmaa
- valory/erc20:0.1.0:bafybeibysifjwhlcn7nntsjkowdmja53ed6urfzypi6sxfc7chtheecvpi
- valory/multisend:0.1.0:bafybeig5byt5urg2d2bsecufxe5ql7f4mezg3mekfleeh32nmuusx66p4y
- valory/mech:0.1.0:bafybeifaavuqr2bz7nypapjwkufc5c6vwxm5ifucmtd3w7sh42tne35nga
- valory/conditional_tokens:0.1.0:bafybeif5jwc6owfe6brmqq5sfnhrwo2ajdtt4glrmyhlqxcvtkyofahwsa
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeia6cdxdlqrcwk2maw25fo7dafzd2p3rs7syropvufophk2pitzbwy
- valory/termination_abci:0.1.0:bafybeieqm46zuccaagnko3qlw6p3nvoohdrfgvpmw467r5lyil2dqrzjsy
- valory/market_manager_abci:0.1.0:bafybeigmy3g2klkzdhttti2ouxf575ua5y7ajmh4a3yfpukeukqxjky47m
- valory/decision_maker_abci:0.1.0:bafybeibijhfe2owjeioofnyfbwmla36dksm7rh2tq7acwpdg4sbzoglt6q
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiglmk6oe2yjsnx73w52c5qx4jbtxfzaf5qvzs2xfsyna3p3agg234
- valory/decision_maker_abci:0.1.0:bafybeihtydxuzyd35cq23xoxbytpxebpbn3rsyqf4bt6z4sleflqck6riy
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeigfkdkpkrktw4wippon6al7vreg3qh7xax33xafomepy6xrv5paa4
behaviours:
main:
args: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contracts: []
protocols: []
skills:
- valory/abstract_round_abci:0.1.0:bafybeid7neqpxxe4ualp23gxgrtpf6r5u3myr2mmc4uvwameyqshfdoydq
- valory/decision_maker_abci:0.1.0:bafybeibijhfe2owjeioofnyfbwmla36dksm7rh2tq7acwpdg4sbzoglt6q
- valory/decision_maker_abci:0.1.0:bafybeihtydxuzyd35cq23xoxbytpxebpbn3rsyqf4bt6z4sleflqck6riy
behaviours:
main:
args: {}
Expand Down

0 comments on commit 6f3ab9f

Please sign in to comment.