Skip to content

Commit

Permalink
Merge pull request #29 from valory-xyz/fix/service
Browse files Browse the repository at this point in the history
Fix service definition
  • Loading branch information
Adamantios authored Jul 27, 2023
2 parents b2df4f0 + 8e27e5a commit b070173
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 57 deletions.
53 changes: 42 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,22 @@ Trader is an autonomous service that performs bets on existing prediction market

autonomy packages sync --update-packages

## Testing the service against Gnosis Mainnet
## Testing the service against Gnosis Mainnet

- Prepare some environment variables:

```bash
export RPC_0=INSERT_YOUR_RPC
export RPC_1=INSERT_YOUR_RPC
export RPC_2=INSERT_YOUR_RPC
export RPC_3=INSERT_YOUR_RPC

export CHAIN_ID=100
export ALL_PARTICIPANTS='["YOUR_AGENT_ADDRESS"]'
export SAFE_CONTRACT_ADDRESS="YOUR_SAFE_ADDRESS"
export OMEN_CREATORS='["CREATOR_0", "CREATOR_1", ...]'

# Optional. The following example values bet a variable amount depending on the
# prediction confidence. Here, amounts vary between 0.03 xDAI (60% confidence)
# and 0.1 xDAI (100% confidence). Please, adjust these values accordingly.
export BET_AMOUNT_PER_THRESHOLD_000=0
export BET_AMOUNT_PER_THRESHOLD_000=0
export BET_AMOUNT_PER_THRESHOLD_010=0
export BET_AMOUNT_PER_THRESHOLD_020=0
export BET_AMOUNT_PER_THRESHOLD_030=0
Expand All @@ -72,19 +69,42 @@ Trader is an autonomous service that performs bets on existing prediction market
```

Replace the above placeholders with their respective actual values:
- `RPC_i`: RPC endpoint per agent (you can get an RPC endpoint, e.g. [here](https://getblock.io/)).
- `RPC_0`: RPC endpoint for the agent (you can get an RPC endpoint, e.g. [here](https://getblock.io/)).
- `CHAIN_ID`: identifier of the chain on which the service is running.
- `ALL_PARTICIPANTS`: list of all the agent addresses participating in the service.
You need to obtain at least one Gnosis address to associate it with an agent of the service.
This demo is for running the service with a single agent.
In case you want to run it with more agents, please edit the keys generation command below,
and replace the `--n 1` argument in the `build` command with the number of your agents.
- `SAFE_CONTRACT_ADDRESS`: address of the agents' multisig wallet.
In case you want to run it with more agents, please obtain more addresses, edit the keys' generation command below,
and replace the `--n 1` argument in the `autonomy deploy build` command below with the number of your agents.
- `SAFE_CONTRACT_ADDRESS`: address of the agents' multisig wallet \*.
- `OMEN_CREATORS`: addresses of the market creator(s) that the service will track
for placing bets on Omen.
- `BET_AMOUNT_PER_THRESHOLD_X`: amount (wei) to bet when the prediction returned by the AI Mech surpasses a threshold of `X`% confidence.
- `BET_THRESHOLD`: threshold (wei) for placing a bet. That is, a bet will only be placed if `expected_return - bet_fees >= BET_THRESHOLD`. [See below](#some-notes-on-the-service).
- `PROMPT_TEMPLATE`: prompt to be used with the prediction AI Mech. Please keep it as a single line including the placeholders `@{question}`, `@{yes}` and `@{no}`.

\* The trader agent runs as part of a **trader service**,
which is an [autonomous service](https://docs.autonolas.network/open-autonomy/get_started/what_is_an_agent_service/)
that is represented on-chain in the Autonolas protocol by a Safe multisig,
corresponding to the variable `SAFE_CONTRACT_ADDRESS`.
Follow the next steps to compute the **Safe address** corresponding to your agent address:

- Visit https://registry.olas.network/services/mint and connect to the Gnosis network. For this demo, we recommend connecting using a wallet with a Gnosis EOA account that you own.
- In the field *"Owner address"* input a Gnosis address for which you will be able to sign later using a supported wallet. If you want to use the address you are connected to, click on *"Prefill Address"*.
- Click on *"Generate Hash & File"* and enter the value corresponding to the `service/valory/trader/0.1.0` key in `packages.json`
- In the field *"Canonical agent Ids"* enter the number `12`
- In the field *"No. of slots to canonical agent Ids"* enter the number `1`
- In the field *"Cost of agent instance bond (wei)"* enter the number `10000000000000000`
- In the field *"Threshold"* enter the number `1`
- Press the *"Submit"* button. Your wallet will ask you to approve the transaction. Once the transaction is settled, you should see a message indicating that the service NFT has been minted successfully. You should also see that the service is in _Pre-Registration_ state.
- Next, you can navigate to https://registry.olas.network/services#my-services, select your service and go through the steps:
1. Activate registration
2. Register agents: here, you must use the same public key that you use in the `ALL_PARTICIPANTS` value.
3. This is the last step. A transaction for the safe deployment is already prepared and needs to be executed.
- After completing the process you will be able to retrieve the value for the variable `SAFE_CONTRACT_ADDRESS` from the field *"Safe contract address"* as shown in an example below

<img src="/img/safe_address_screenshot.png" alt="Safe address field]" width="500"/>

- Fetch the service

```bash
Expand Down Expand Up @@ -126,4 +146,15 @@ Please take into consideration the following:
- If the service does not have enough funds for placing a bet, you will see an `Event.INSUFICIENT_FUNDS` in the service logs.
- If the service determines that a bet is not profitable (i.e., `expected_return - bet_fees < BET_THRESHOLD`), you will see an `Event.UNPROFITABLE` in the service logs, and the service will transition into the blacklisting round. This round blacklists a bet for a predetermined amount of time. This can be adjusted by using the `BLACKLISTING_DURATION` environment variable.
- For simplicity, the current implementation considers `expected_return = bet_amount`, although this calculation might be refined.
- When assigning `BET_THRESHOLD` take into consideration that fees (at the time of writing this guide) are in the range of 0.02 xDAI. See for example [here](https://api.thegraph.com/subgraphs/name/protofire/omen-xdai/graphql?query=%7B%0A++fixedProductMarketMakers%28%0A++++where%3A+%7B%0A++++++creator_in%3A+%5B%220x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec%22%5D%2C%0A++++++outcomeSlotCount%3A+2%2C%0A++++++isPendingArbitration%3A+false%0A++++%7D%2C%0A++++orderBy%3A+creationTimestamp%0A++++orderDirection%3A+desc%0A++%29%7B%0A++++fee%0A++%7D%0A%7D). We urge you to keep an eye on these fees, as they might vary.
- When assigning `BET_THRESHOLD` take into consideration that fees (at the time of writing this guide) are in the range of 0.02 xDAI. See, for example, [here](https://api.thegraph.com/subgraphs/name/protofire/omen-xdai/graphql?query=%7B%0A++fixedProductMarketMakers%28%0A++++where%3A+%7B%0A++++++creator_in%3A+%5B%220x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec%22%5D%2C%0A++++++outcomeSlotCount%3A+2%2C%0A++++++isPendingArbitration%3A+false%0A++++%7D%2C%0A++++orderBy%3A+creationTimestamp%0A++++orderDirection%3A+desc%0A++%29%7B%0A++++fee%0A++%7D%0A%7D). We urge you to keep an eye on these fees, as they might vary.
- The trader service can be run as a multi-agent system. If you want to explore this option, extra environment variables need to be defined, i.e. in the case of 4 agents
```bash
export RPC_0=INSERT_YOUR_RPC
export RPC_1=INSERT_YOUR_RPC
export RPC_2=INSERT_YOUR_RPC
export RPC_3=INSERT_YOUR_RPC
export ALL_PARTICIPANTS='["AGENT_ADDRESS_0,AGENT_ADDRESS_1,AGENT_ADDRESS_2,AGENT_ADDRESS_3"]'
```
where `RPC_i` is the RPC endpoint for agent `AGENT_ADDRESS_i`
Binary file added img/safe_address_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"skill/valory/trader_abci/0.1.0": "bafybeibrtiywxhpvan5gmx5aj2heaxr7amqcuqxfmaonqjjmz6ywkwxnpq",
"contract/valory/market_maker/0.1.0": "bafybeig3b2wfngntdypnixi2gphuqz3o6w7zba2rq6n6kepwdmth2mx3ni",
"agent/valory/trader/0.1.0": "bafybeiawub2ykqda63ovtnt3m3wdkvqejvdebmen3wcjcfsigxhvpgmqwq",
"service/valory/trader/0.1.0": "bafybeicgjqgkf2wv54rows3lw4qxnaqnxannumuonh6vahb3ldlzu7cyhi",
"service/valory/trader/0.1.0": "bafybeiean2j7qg5v5t7ehtsezshps3mp7ilewl6jijuxhyukpf23tvwv5u",
"contract/valory/erc20/0.1.0": "bafybeict775c7iytqbhiv2tq6pdwtpyzr3p2wls3duvmrl3acee7pietwy",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeifwytl5rwyleswor7rddo7lslvrsd74ikjnv5owy5cqgtrndehoye",
"contract/valory/mech/0.1.0": "bafybeib3syh35usqjtqapqjjvobnkcxllkpjbxcb67g3vp3f566qsbhqgq"
Expand Down
90 changes: 45 additions & 45 deletions packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type: skill
finalize_timeout: ${FINALIZE_TIMEOUT:float:60.0}
genesis_config: &id002
genesis_time: ${GENESIS_TIME:str:'2023-07-12T00:00:00.000000000Z'}
chain_id: ${CHAIN_ID:str:chain-c4daS1}
chain_id: ${GENESIS_CHAIN_ID:str:chain-c4daS1}
consensus_params:
block:
max_bytes: ${BLOCK_MAX_BYTES:str:'22020096'}
Expand All @@ -41,34 +41,34 @@ type: skill
pub_key_types: ${PUB_KEY_TYPES:list:["ed25519"]}
version: ${VERSION:dict:{}}
voting_power: ${VOTING_POWER:str:'10'}
init_fallback_gas: ${INIT_FALLBACK_GAS:0}
keeper_allowed_retries: ${KEEPER_ALLOWED_RETRIES:3}
init_fallback_gas: ${INIT_FALLBACK_GAS:int:0}
keeper_allowed_retries: ${KEEPER_ALLOWED_RETRIES:int:3}
keeper_timeout: ${KEEPER_TIMEOUT:float:30.0}
max_attempts: ${MAX_ATTEMPTS:10}
max_healthcheck: ${MAX_HEALTHCHECK:120}
max_attempts: ${MAX_ATTEMPTS:int:10}
max_healthcheck: ${MAX_HEALTHCHECK:int:120}
multisend_address: ${MULTISEND_ADDRESS:str:0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761}
on_chain_service_id: ${ON_CHAIN_SERVICE_ID:int:null}
reset_tendermint_after: ${RESET_TM_AFTER:int:2}
retry_attempts: ${RETRY_ATTEMPTS:400}
retry_timeout: ${RETRY_TIMEOUT:3}
retry_attempts: ${RETRY_ATTEMPTS:int:400}
retry_timeout: ${RETRY_TIMEOUT:int:3}
reset_pause_duration: ${RESET_PAUSE_DURATION:int:10}
request_retry_delay: ${REQUEST_RETRY_DELAY:float:1.0}
request_timeout: ${REQUEST_TIMEOUT:float:10.0}
round_timeout_seconds: ${ROUND_TIMEOUT:float:350.0}
service_id: ${SERVICE_ID:str:trader}
service_registry_address: ${SERVICE_REGISTRY_ADDRESS:str:0x9338b5153AE39BB89f50468E608eD9d764B755fD}
share_tm_config_on_startup: ${USE_ACN:bool:false}
sleep_time: ${SLEEP_TIME:1}
tendermint_check_sleep_delay: ${TM_CHECK_SLEEP_DELAY:3}
sleep_time: ${SLEEP_TIME:int:1}
tendermint_check_sleep_delay: ${TM_CHECK_SLEEP_DELAY:int:3}
tendermint_com_url: ${TENDERMINT_COM_URL:str:http://localhost:8080}
tendermint_max_retries: ${TM_MAX_RETRIES:5}
tendermint_max_retries: ${TM_MAX_RETRIES:int:5}
tendermint_url: ${TENDERMINT_URL:str:http://localhost:26657}
tendermint_p2p_url: ${TM_P2P_ENDPOINT_NODE_0:str:node0:26656}
termination_sleep: ${TERMINATION_SLEEP:int:900}
tx_timeout: ${TX_TIMEOUT:float:10.0}
use_termination: ${USE_TERMINATION:bool:false}
validate_timeout: ${VALIDATE_TIMEOUT:1205}
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:1205}
validate_timeout: ${VALIDATE_TIMEOUT:int:1205}
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:int:1205}
creator_per_subgraph: &id003
omen_subgraph: ${OMEN_CREATORS:list:["0x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec"]}
slot_count: ${SLOT_COUNT:int:2}
Expand Down Expand Up @@ -108,34 +108,34 @@ type: skill
drand_public_key: ${DRAND_PUBLIC_KEY:str:868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31}
finalize_timeout: ${FINALIZE_TIMEOUT:float:60.0}
genesis_config: *id002
init_fallback_gas: ${INIT_FALLBACK_GAS:0}
keeper_allowed_retries: ${KEEPER_ALLOWED_RETRIES:3}
init_fallback_gas: ${INIT_FALLBACK_GAS:int:0}
keeper_allowed_retries: ${KEEPER_ALLOWED_RETRIES:int:3}
keeper_timeout: ${KEEPER_TIMEOUT:float:30.0}
max_attempts: ${MAX_ATTEMPTS:10}
max_healthcheck: ${MAX_HEALTHCHECK:120}
max_attempts: ${MAX_ATTEMPTS:int:10}
max_healthcheck: ${MAX_HEALTHCHECK:int:120}
multisend_address: ${MULTISEND_ADDRESS:str:0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761}
on_chain_service_id: ${ON_CHAIN_SERVICE_ID:int:null}
reset_tendermint_after: ${RESET_TM_AFTER:int:2}
retry_attempts: ${RETRY_ATTEMPTS:400}
retry_timeout: ${RETRY_TIMEOUT:3}
retry_attempts: ${RETRY_ATTEMPTS:int:400}
retry_timeout: ${RETRY_TIMEOUT:int:3}
reset_pause_duration: ${RESET_PAUSE_DURATION:int:10}
request_retry_delay: ${REQUEST_RETRY_DELAY:float:1.0}
request_timeout: ${REQUEST_TIMEOUT:float:10.0}
round_timeout_seconds: ${ROUND_TIMEOUT:float:350.0}
service_id: ${SERVICE_ID:str:trader}
service_registry_address: ${SERVICE_REGISTRY_ADDRESS:str:0x9338b5153AE39BB89f50468E608eD9d764B755fD}
share_tm_config_on_startup: ${USE_ACN:bool:false}
sleep_time: ${SLEEP_TIME:1}
tendermint_check_sleep_delay: ${TM_CHECK_SLEEP_DELAY:3}
sleep_time: ${SLEEP_TIME:int:1}
tendermint_check_sleep_delay: ${TM_CHECK_SLEEP_DELAY:int:3}
tendermint_com_url: ${TENDERMINT_COM_URL:str:http://localhost:8080}
tendermint_max_retries: ${TM_MAX_RETRIES:5}
tendermint_max_retries: ${TM_MAX_RETRIES:int:5}
tendermint_url: ${TENDERMINT_URL:str:http://localhost:26657}
tendermint_p2p_url: ${TM_P2P_ENDPOINT_NODE_1:str:node1:26656}
termination_sleep: ${TERMINATION_SLEEP:int:900}
tx_timeout: ${TX_TIMEOUT:float:10.0}
use_termination: ${USE_TERMINATION:bool:false}
validate_timeout: ${VALIDATE_TIMEOUT:1205}
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:1205}
validate_timeout: ${VALIDATE_TIMEOUT:int:1205}
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:int:1205}
creator_per_subgraph: *id003
slot_count: ${SLOT_COUNT:int:2}
opening_margin: ${OPENING_MARGIN:int:300}
Expand All @@ -161,34 +161,34 @@ type: skill
drand_public_key: ${DRAND_PUBLIC_KEY:str:868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31}
finalize_timeout: ${FINALIZE_TIMEOUT:float:60.0}
genesis_config: *id002
init_fallback_gas: ${INIT_FALLBACK_GAS:0}
keeper_allowed_retries: ${KEEPER_ALLOWED_RETRIES:3}
init_fallback_gas: ${INIT_FALLBACK_GAS:int:0}
keeper_allowed_retries: ${KEEPER_ALLOWED_RETRIES:int:3}
keeper_timeout: ${KEEPER_TIMEOUT:float:30.0}
max_attempts: ${MAX_ATTEMPTS:10}
max_healthcheck: ${MAX_HEALTHCHECK:120}
max_attempts: ${MAX_ATTEMPTS:int:10}
max_healthcheck: ${MAX_HEALTHCHECK:int:120}
multisend_address: ${MULTISEND_ADDRESS:str:0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761}
on_chain_service_id: ${ON_CHAIN_SERVICE_ID:int:null}
reset_tendermint_after: ${RESET_TM_AFTER:int:2}
retry_attempts: ${RETRY_ATTEMPTS:400}
retry_timeout: ${RETRY_TIMEOUT:3}
retry_attempts: ${RETRY_ATTEMPTS:int:400}
retry_timeout: ${RETRY_TIMEOUT:int:3}
reset_pause_duration: ${RESET_PAUSE_DURATION:int:10}
request_retry_delay: ${REQUEST_RETRY_DELAY:float:1.0}
request_timeout: ${REQUEST_TIMEOUT:float:10.0}
round_timeout_seconds: ${ROUND_TIMEOUT:float:350.0}
service_id: ${SERVICE_ID:str:trader}
service_registry_address: ${SERVICE_REGISTRY_ADDRESS:str:0x9338b5153AE39BB89f50468E608eD9d764B755fD}
share_tm_config_on_startup: ${USE_ACN:bool:false}
sleep_time: ${SLEEP_TIME:1}
tendermint_check_sleep_delay: ${TM_CHECK_SLEEP_DELAY:3}
sleep_time: ${SLEEP_TIME:int:1}
tendermint_check_sleep_delay: ${TM_CHECK_SLEEP_DELAY:int:3}
tendermint_com_url: ${TENDERMINT_COM_URL:str:http://localhost:8080}
tendermint_max_retries: ${TM_MAX_RETRIES:5}
tendermint_max_retries: ${TM_MAX_RETRIES:int:5}
tendermint_url: ${TENDERMINT_URL:str:http://localhost:26657}
tendermint_p2p_url: ${TM_P2P_ENDPOINT_NODE_2:str:node2:26656}
termination_sleep: ${TERMINATION_SLEEP:int:900}
tx_timeout: ${TX_TIMEOUT:float:10.0}
use_termination: ${USE_TERMINATION:bool:false}
validate_timeout: ${VALIDATE_TIMEOUT:1205}
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:1205}
validate_timeout: ${VALIDATE_TIMEOUT:int:1205}
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:int:1205}
creator_per_subgraph: *id003
slot_count: ${SLOT_COUNT:int:2}
opening_margin: ${OPENING_MARGIN:int:300}
Expand All @@ -214,34 +214,34 @@ type: skill
drand_public_key: ${DRAND_PUBLIC_KEY:str:868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31}
finalize_timeout: ${FINALIZE_TIMEOUT:float:60.0}
genesis_config: *id002
init_fallback_gas: ${INIT_FALLBACK_GAS:0}
keeper_allowed_retries: ${KEEPER_ALLOWED_RETRIES:3}
init_fallback_gas: ${INIT_FALLBACK_GAS:int:0}
keeper_allowed_retries: ${KEEPER_ALLOWED_RETRIES:int:3}
keeper_timeout: ${KEEPER_TIMEOUT:float:30.0}
max_attempts: ${MAX_ATTEMPTS:10}
max_healthcheck: ${MAX_HEALTHCHECK:120}
max_attempts: ${MAX_ATTEMPTS:int:10}
max_healthcheck: ${MAX_HEALTHCHECK:int:120}
multisend_address: ${MULTISEND_ADDRESS:str:0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761}
on_chain_service_id: ${ON_CHAIN_SERVICE_ID:int:null}
reset_tendermint_after: ${RESET_TM_AFTER:int:2}
retry_attempts: ${RETRY_ATTEMPTS:400}
retry_timeout: ${RETRY_TIMEOUT:3}
retry_attempts: ${RETRY_ATTEMPTS:int:400}
retry_timeout: ${RETRY_TIMEOUT:int:3}
reset_pause_duration: ${RESET_PAUSE_DURATION:int:10}
request_retry_delay: ${REQUEST_RETRY_DELAY:float:1.0}
request_timeout: ${REQUEST_TIMEOUT:float:10.0}
round_timeout_seconds: ${ROUND_TIMEOUT:float:350.0}
service_id: ${SERVICE_ID:str:trader}
service_registry_address: ${SERVICE_REGISTRY_ADDRESS:str:0x9338b5153AE39BB89f50468E608eD9d764B755fD}
share_tm_config_on_startup: ${USE_ACN:bool:false}
sleep_time: ${SLEEP_TIME:1}
tendermint_check_sleep_delay: ${TM_CHECK_SLEEP_DELAY:3}
sleep_time: ${SLEEP_TIME:int:1}
tendermint_check_sleep_delay: ${TM_CHECK_SLEEP_DELAY:int:3}
tendermint_com_url: ${TENDERMINT_COM_URL:str:http://localhost:8080}
tendermint_max_retries: ${TM_MAX_RETRIES:5}
tendermint_max_retries: ${TM_MAX_RETRIES:int:5}
tendermint_url: ${TENDERMINT_URL:str:http://localhost:26657}
tendermint_p2p_url: ${TM_P2P_ENDPOINT_NODE_3:str:node3:26656}
termination_sleep: ${TERMINATION_SLEEP:int:900}
tx_timeout: ${TX_TIMEOUT:float:10.0}
use_termination: ${USE_TERMINATION:bool:false}
validate_timeout: ${VALIDATE_TIMEOUT:1205}
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:1205}
validate_timeout: ${VALIDATE_TIMEOUT:int:1205}
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:int:1205}
creator_per_subgraph: *id003
slot_count: ${SLOT_COUNT:int:2}
opening_margin: ${OPENING_MARGIN:int:300}
Expand Down

0 comments on commit b070173

Please sign in to comment.