Skip to content

Commit

Permalink
Merge branch 'valory-xyz:main' into Test-for-staking
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravleen-Solulab authored Sep 2, 2024
2 parents ff28e36 + 8d0b2e3 commit f6bdd5b
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 45 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ jobs:
$CMD service deploy --name '${{ vars.SERVICE_NAME }}' --service-dir $SERVICE_PATH --service-ipfs-hash $IPFS_HASH --ingress-enabled true --keys '${{ vars.SERVICE_KEYS }}' --timeout 320
build-macos-pyinstaller:
runs-on: macos-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
arch: [ x64, arm64 ]
os: [ macos-14, macos-14-large ]

steps:
- uses: actions/checkout@v3
Expand All @@ -177,14 +177,23 @@ jobs:
- name: Install dependencies
run: poetry install

- name: Set arch environment variable for macos-latest-large
if: contains(matrix.os, 'large')
run: echo "OS_ARCH=x64" >> $GITHUB_ENV

- name: Set arch environment variable for other macOS versions
if: ${{ !contains(matrix.os, 'large') }}
run: echo "OS_ARCH=arm64" >> $GITHUB_ENV

- name: Build with PyInstaller
run: |
poetry run pyinstaller --collect-data eth_account --collect-all aea --collect-all autonomy --collect-all operate --collect-all aea_ledger_ethereum --collect-all aea_ledger_cosmos --collect-all aea_ledger_ethereum_flashbots --hidden-import aea_ledger_ethereum --hidden-import aea_ledger_cosmos --hidden-import aea_ledger_ethereum_flashbots --hidden-import grpc --hidden-import openapi_core --collect-all google.protobuf --collect-all openapi_core --collect-all openapi_spec_validator --collect-all asn1crypto --hidden-import py_ecc --hidden-import pytz --onefile pyinstaller/trader_bin.py --name trader_bin_${{ matrix.arch }}
poetry run pyinstaller --collect-data eth_account --collect-all aea --collect-all autonomy --collect-all operate --collect-all aea_ledger_ethereum --collect-all aea_ledger_cosmos --collect-all aea_ledger_ethereum_flashbots --hidden-import aea_ledger_ethereum --hidden-import aea_ledger_cosmos --hidden-import aea_ledger_ethereum_flashbots --hidden-import grpc --hidden-import openapi_core --collect-all google.protobuf --collect-all openapi_core --collect-all openapi_spec_validator --collect-all asn1crypto --hidden-import py_ecc --hidden-import pytz --onefile pyinstaller/trader_bin.py --name trader_bin_${{env.OS_ARCH}}
- name: Upload Release Assets
uses: actions/upload-artifact@v2
with:
name: trader_bin_${{ matrix.arch }}
path: dist/trader_bin_${{ matrix.arch }}
name: trader_bin_${{env.OS_ARCH}}
path: dist/trader_bin_${{env.OS_ARCH}}

upload-assets:
needs: build-macos-pyinstaller
runs-on: ubuntu-latest
Expand Down
16 changes: 8 additions & 8 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"custom/valory/mike_strat/0.1.0": "bafybeihjiol7f4ch4piwfikurdtfwzsh6qydkbsztpbwbwb2yrqdqf726m",
"custom/jhehemann/kelly_criterion/0.1.0": "bafybeif55cu7cf6znyma7kxus4wxa2doarhau2xmndo57iegshxorivwmq",
"custom/w1kke/always_blue/0.1.0": "bafybeieshu32h3es2fslduuhr7nimuvh2vuibyeqdunzrcggaeohekg3jm",
"custom/valory/kelly_criterion_no_conf/0.1.0": "bafybeihnweebd6lxqtiat2mgspp5tpal4e2hntwdxvptkmbunpdxq2fple",
"custom/valory/kelly_criterion_no_conf/0.1.0": "bafybeibxfp27rzrfnp7sxq62vwv32pdvrijxi7vzg7ihukkaka3bwzrgae",
"contract/valory/market_maker/0.1.0": "bafybeiba25nt26ntjzkkpfyl2ngbjxrfd44ckg3znfhqm552725vb3gaka",
"contract/valory/realitio/0.1.0": "bafybeignaxfk7fjlfa4lioflwsfru2z5xln5cyvyew3if5oas2sgm5wuii",
"contract/valory/realitio/0.1.0": "bafybeietgux6kkhdquspy35qera7gjwwqwrremmoeatjzwwokjb2lzsata",
"contract/valory/realitio_proxy/0.1.0": "bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4",
"contract/valory/conditional_tokens/0.1.0": "bafybeibnzmqmeph4cj5vfh3s622mo2o5627vjjwc6bptrhj4dk65mzgvhe",
"contract/valory/agent_registry/0.1.0": "bafybeifsb2krg4qnr4nxdrhcdgpncfr5ra2nahebvn2f2yff7ebwe7ooae",
Expand All @@ -16,14 +16,14 @@
"contract/valory/staking_token/0.1.0": "bafybeig4fl35dn7d5gnprux2nwsqbirm7zkiujz3xvrwcjuktz6hkq4as4",
"contract/valory/relayer/0.1.0": "bafybeihzgjyvhtorugjw3yldznqsbwo3aqpxowm7k2nrvj6qtwpsc7jl7u",
"skill/valory/market_manager_abci/0.1.0": "bafybeiai6djelf6d4dkxgkv46l24q2gz7736b3jdhbxslvcydpvnvrse6e",
"skill/valory/decision_maker_abci/0.1.0": "bafybeigykiciajiq5za7szupck5jbj6z6dvnmoufdam7eyigpn4mr6c6bq",
"skill/valory/trader_abci/0.1.0": "bafybeid23zogdrlauifqprlogztejgb2yl3ohcvqcat7nab2hgvez4bzru",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeidcw2bzonvlgtyuv76zkutjs7qv5j4wgvi6azthqpyefds6i5cvdm",
"skill/valory/decision_maker_abci/0.1.0": "bafybeigh2ajmwscmgvl3t4wkwyeclszs5ujykm5omget7yap7zmwironkq",
"skill/valory/trader_abci/0.1.0": "bafybeie3njujc5zdwqncwwr3yhfm33cggtihxwrdjlzpgaom4zdnidy6ka",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibyverkghpxz7di3wgxdixwcofrxec35b4tb4ac5pebpseax76eby",
"skill/valory/staking_abci/0.1.0": "bafybeiduborfqevheegy3plk7bzhkl4fukwixvlb57tenijdepintubbdi",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeiepylk35n3faurvp7dskjkdovehftzfjrjxfkpekzuaovt5gojxne",
"agent/valory/trader/0.1.0": "bafybeigw6e7b5riiinbxa263q2k7qrk3zbejuabngdm2g4w2uu42qyyzsy",
"service/valory/trader/0.1.0": "bafybeigjc2g6dk26cfkjscg2qovlhjrqckw45tdfiikgqdg3xdxsllf2wm",
"service/valory/trader_pearl/0.1.0": "bafybeia2pb5efg3hxwpq7aa332puxyrpyvjkpnktsnjjaqw7ytutqifkvq"
"agent/valory/trader/0.1.0": "bafybeiexvarbsj25xevrtuqavwmgpvmz753a74im7su7jzamhhkuqjcl3y",
"service/valory/trader/0.1.0": "bafybeighrps33nlltr7gwdeaftkii3t2itwshvk5ulpazjyxdmed6gmbo4",
"service/valory/trader_pearl/0.1.0": "bafybeihqtqgohejyebrb4jvd2fgccuasmqk3gc456ylyfa7tcn6rucdrxm"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down
14 changes: 7 additions & 7 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contracts:
- valory/multisend:0.1.0:bafybeig5byt5urg2d2bsecufxe5ql7f4mezg3mekfleeh32nmuusx66p4y
- valory/mech:0.1.0:bafybeidwpijhdwj5abewa44k3tzxuanxykzmgnnffeq7re2rxp7pqbd2ou
- valory/conditional_tokens:0.1.0:bafybeibnzmqmeph4cj5vfh3s622mo2o5627vjjwc6bptrhj4dk65mzgvhe
- valory/realitio:0.1.0:bafybeignaxfk7fjlfa4lioflwsfru2z5xln5cyvyew3if5oas2sgm5wuii
- valory/realitio:0.1.0:bafybeietgux6kkhdquspy35qera7gjwwqwrremmoeatjzwwokjb2lzsata
- valory/realitio_proxy:0.1.0:bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4
- valory/agent_registry:0.1.0:bafybeifsb2krg4qnr4nxdrhcdgpncfr5ra2nahebvn2f2yff7ebwe7ooae
- valory/service_staking_token:0.1.0:bafybeieyfto5xwmvxiu52qxxudp2zaa22idrvw3jr6bytbok6bg3nylgqi
Expand All @@ -47,17 +47,17 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeiameewywqigpupy3u2iwnkfczeiiucue74x2l5lbge74rmw6bgaie
- valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq
- valory/transaction_settlement_abci:0.1.0:bafybeic3tccdjypuge2lewtlgprwkbb53lhgsgn7oiwzyrcrrptrbeyote
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeidcw2bzonvlgtyuv76zkutjs7qv5j4wgvi6azthqpyefds6i5cvdm
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibyverkghpxz7di3wgxdixwcofrxec35b4tb4ac5pebpseax76eby
- valory/market_manager_abci:0.1.0:bafybeiai6djelf6d4dkxgkv46l24q2gz7736b3jdhbxslvcydpvnvrse6e
- valory/decision_maker_abci:0.1.0:bafybeigykiciajiq5za7szupck5jbj6z6dvnmoufdam7eyigpn4mr6c6bq
- valory/trader_abci:0.1.0:bafybeid23zogdrlauifqprlogztejgb2yl3ohcvqcat7nab2hgvez4bzru
- valory/decision_maker_abci:0.1.0:bafybeigh2ajmwscmgvl3t4wkwyeclszs5ujykm5omget7yap7zmwironkq
- valory/trader_abci:0.1.0:bafybeie3njujc5zdwqncwwr3yhfm33cggtihxwrdjlzpgaom4zdnidy6ka
- valory/staking_abci:0.1.0:bafybeiduborfqevheegy3plk7bzhkl4fukwixvlb57tenijdepintubbdi
- valory/check_stop_trading_abci:0.1.0:bafybeiepylk35n3faurvp7dskjkdovehftzfjrjxfkpekzuaovt5gojxne
- valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e
customs:
- valory/mike_strat:0.1.0:bafybeihjiol7f4ch4piwfikurdtfwzsh6qydkbsztpbwbwb2yrqdqf726m
- valory/bet_amount_per_threshold:0.1.0:bafybeihufqu2ra7vud4h6g2nwahx7mvdido7ff6prwnib2tdlc4np7dw24
- valory/kelly_criterion_no_conf:0.1.0:bafybeihnweebd6lxqtiat2mgspp5tpal4e2hntwdxvptkmbunpdxq2fple
- valory/kelly_criterion_no_conf:0.1.0:bafybeibxfp27rzrfnp7sxq62vwv32pdvrijxi7vzg7ihukkaka3bwzrgae
- w1kke/always_blue:0.1.0:bafybeieshu32h3es2fslduuhr7nimuvh2vuibyeqdunzrcggaeohekg3jm
- jhehemann/kelly_criterion:0.1.0:bafybeif55cu7cf6znyma7kxus4wxa2doarhau2xmndo57iegshxorivwmq
default_ledger: ethereum
Expand Down Expand Up @@ -232,8 +232,8 @@ models:
refill_check_interval: ${int:10}
tool_punishment_multiplier: ${int:1}
contract_timeout: ${float:300.0}
file_hash_to_strategies_json: ${list:[["bafybeihufqu2ra7vud4h6g2nwahx7mvdido7ff6prwnib2tdlc4np7dw24",["bet_amount_per_threshold"]],["bafybeihnweebd6lxqtiat2mgspp5tpal4e2hntwdxvptkmbunpdxq2fple",["kelly_criterion_no_conf"]]]}
strategies_kwargs: ${list:[["bet_kelly_fraction",0.5],["floor_balance",500000000000000000],["bet_amount_per_threshold",{"0.0":0,"0.1":0,"0.2":0,"0.3":0,"0.4":0,"0.5":0,"0.6":60000000000000000,"0.7":90000000000000000,"0.8":100000000000000000,"0.9":1000000000000000000,"1.0":10000000000000000000}]]}
file_hash_to_strategies_json: ${list:[["bafybeihufqu2ra7vud4h6g2nwahx7mvdido7ff6prwnib2tdlc4np7dw24",["bet_amount_per_threshold"]],["bafybeibxfp27rzrfnp7sxq62vwv32pdvrijxi7vzg7ihukkaka3bwzrgae",["kelly_criterion_no_conf"]]]}
strategies_kwargs: ${list:[["bet_kelly_fraction",1.0],["floor_balance",500000000000000000],["bet_amount_per_threshold",{"0.0":0,"0.1":0,"0.2":0,"0.3":0,"0.4":0,"0.5":0,"0.6":60000000000000000,"0.7":90000000000000000,"0.8":100000000000000000,"0.9":1000000000000000000,"1.0":10000000000000000000}]]}
service_endpoint: ${str:https://trader.staging.autonolas.tech/}
rpc_sleep_time: ${int:10}
mech_interaction_sleep_time: ${int:10}
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/contracts/realitio/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
)

MARKET_FEE = 2.0
UNIT_SEPARATOR = "␟"
UNIT_SEPARATOR = chr(9247)


def format_answers(answers: List[str]) -> str:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/contracts/realitio/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeictahkgfmlqv5kksvj6klmxtmjdpeq4sp3x7dp2yr5x4kmzbcihse
build/Realitio.json: bafybeiagi7zoeoy5s7duhg4oeuekj2s6z5mad2z6g2pn3n5elsvze25qiu
contract.py: bafybeigaof2tb7fcxfjm7ibuoi4su26vaaw6smq767paty56zufklbzqp4
contract.py: bafybeih7u7cpfqn3htwribajjfhka6ilhww7lx4w5qqls6b3gxevaevfoa
fingerprint_ignore_patterns: []
class_name: RealitioContract
contract_interface_paths:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeidog73nvs6bfta5pmaxufwly6pc52knbnxqlwcwka4cpnyneeykqi
kelly_criterion_no_conf.py: bafybeiffkggwm23e7rfek5skvxd455sjxosjstkabrteyld7bgxuyz6bo4
kelly_criterion_no_conf.py: bafybeifrdnpes4jbhnkesuuk5pktyz2udlx4d5yr73ebgqpzpiqywixhom
fingerprint_ignore_patterns: []
entry_point: kelly_criterion_no_conf.py
callable: run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

"""This module contains the kelly criterion strategy without confidence factor in the formula."""

from typing import Dict, Any, List, Union
from typing import Dict, Any, List, Union, Optional

REQUIRED_FIELDS = frozenset(
{
Expand All @@ -31,6 +31,7 @@
"selected_type_tokens_in_pool",
"other_tokens_in_pool",
"bet_fee",
"weighted_accuracy",
"floor_balance",
}
)
Expand All @@ -53,6 +54,30 @@ def remove_irrelevant_fields(kwargs: Dict[str, Any]) -> Dict[str, Any]:
return {key: value for key, value in kwargs.items() if key in ALL_FIELDS}


def get_adjusted_kelly_amount(
kelly_bet_amount: float,
weighted_accuracy: Optional[float],
static_kelly_fraction: float,
error: list,
):
"""This function adjusts the kelly bet amount based on the weighted accuracy metric
of the selected tool to make the prediction. Default use-case: it uses the static kelly fraction
"""
if weighted_accuracy is None:
error.append(
f"No weighted accuracy information for this tool. Using static fraction."
)
return int(kelly_bet_amount * static_kelly_fraction)
# weighted_accuracy must be always between [0, 1]
if not (0 <= weighted_accuracy <= 1):
error.append(
f"Wrong value for the weighted accuracy {weighted_accuracy}. Accepted range [0, 1]. Using static fraction"
)
return int(kelly_bet_amount * static_kelly_fraction)
dynamic_kelly_fraction = static_kelly_fraction + weighted_accuracy
return int(kelly_bet_amount * dynamic_kelly_fraction)


def calculate_kelly_bet_amount_no_conf(
x: int, y: int, p: float, b: int, f: float
) -> int:
Expand Down Expand Up @@ -104,6 +129,7 @@ def get_bet_amount_kelly( # pylint: disable=too-many-arguments
selected_type_tokens_in_pool: int,
other_tokens_in_pool: int,
bet_fee: int,
weighted_accuracy: float,
floor_balance: int,
max_bet: int = DEFAULT_MAX_BET,
) -> Dict[str, Union[int, List[str]]]:
Expand Down Expand Up @@ -139,7 +165,12 @@ def get_bet_amount_kelly( # pylint: disable=too-many-arguments

info.append(f"Kelly bet amount: {wei_to_native(kelly_bet_amount)} xDAI")
info.append(f"Bet kelly fraction: {bet_kelly_fraction}")
adj_kelly_bet_amount = int(kelly_bet_amount * bet_kelly_fraction)
info.append(
f"Applying dynamic kelly fraction to all bets. Weighted accuracy of the tool={weighted_accuracy}"
)
adj_kelly_bet_amount = get_adjusted_kelly_amount(
kelly_bet_amount, weighted_accuracy, bet_kelly_fraction, error
)
info.append(
f"Adjusted Kelly bet amount: {wei_to_native(adj_kelly_bet_amount)} xDAI"
)
Expand Down
Loading

0 comments on commit f6bdd5b

Please # to comment.