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

Feat/staking #3

Merged
merged 19 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 39 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ Ensure your machine satisfies the requirements:

## Resource Requirements

- You need ETH and USDC in one of your wallets. We recommend having $10 worth of ETH and USDC on Etherum.
- You need ETH and USDC in one of your wallets. We recommend having $10 worth of ETH and USDC on Etherum.
- You need 3 RPCs for your agent instance for respectively Ethereum, Optimism, and Base. You can use the following public ones:

```bash
Ethereum RPC: https://virtual.mainnet.rpc.tenderly.co/4b1b935c-2ad1-4f63-88c4-f74eaae37123

Optimism RPC: https://virtual.optimism.rpc.tenderly.co/2ba819d3-6ee1-4075-a145-6eaaeb58e5b7
Optimism RPC: https://virtual.optimism.rpc.tenderly.co/f31a1efd-d795-4d0b-97a6-f57887ecfb3f

Base RPC: https://virtual.base.rpc.tenderly.co/a5594f32-3ec3-4ea5-8a91-6d5d7d9e290b
```
- Finally, you will need your Tenderly Access Key, Tenderly account Slug, and Tenderly Project Slug. Get one at https://dashboard.tenderly.co/. Refer to the Tenderly Documentation for more info https://docs.tenderly.co/account/projects.
- You will need your Tenderly Access Key, Tenderly account Slug, and Tenderly Project Slug. Get one at https://dashboard.tenderly.co/. Refer to the Tenderly Documentation for more info https://docs.tenderly.co/account/projects.




## Run the Service
Expand All @@ -49,6 +51,40 @@ chmod +x run_service.sh
```
When prompted, add the corresponding RPCs (you can copy-paste the ones in the section above) and Tenderly info, send funds to the prompted address and you're good to go!

### Creating a local user account

For your own asset's protection, when run for the first time, the agent will setup for you a new local user account. For this purpose, you will be asked to
enter and confirm a password as below.
For future runs of the agent, please make sure to store the given password on a safe side file of your choice.
```bash
Creating a new local user account...
Please enter a password:
Please confirm your password:
Creating the main wallet...
```

## Staking

The agent will need your answer on staking. If you plan to run it as a non staking agent, please answer _n_ to the question below. Otherwise, please answer _y_ and, consequently when prompted, fund your agent with the required number of Olas.

```bash
Do you want to stake your service? (y/n):
```

This version of Optimus comes with only one staking program with a min OLAS requirement of 40.00 OLAS. The script will check that your owner address meets the minimum required OLAS on the Gnosis Chain.


### Notes:

- Staking is currently in a testing phase, so the number of trader agents that can be staked might be limited.
- Within each staking period (24hrs) staking happens after the agent has reached its staking KPIs. In the current agent's version, this takes approxiamtely 45 minutes of activity.
- In case a service is stopped and remains inactive beyond the specified _maxAllowedInactivity_ time (2 staking periods, 48hrs), it faces eviction from the staking program, ceasing to accrue additional rewards.


## Wallet Password

Finally, the agent will prompt you to setup your wallet password. Please be mindful of storing it in a secure space, for future use.

### Service is Running

Once the command has completed, i.e. the service is running, you can see the live logs with:
Expand Down Expand Up @@ -121,6 +157,3 @@ Execute the following steps in a PowerShell terminal:
8. Open [Docker Desktop](https://www.docker.com/products/docker-desktop/) and leave it opened in the background.

Now, open a Git Bash terminal and follow the instructions in the "[Run the script](#run-the-script)" section as well as the subsequent sections. You might need to install Microsoft Visual C++ 14.0 or greater.



13 changes: 2 additions & 11 deletions operate/ledger/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,13 @@
"pearl_beta": "0xeF44Fb0842DDeF59D37f85D61A1eF492bbA6135d",
},
ChainType.OPTIMISM: {
"pearl_alpha": "0xEE9F19b5DF06c7E8Bfc7B28745dcf944C504198A",
"pearl_beta": "0xeF44Fb0842DDeF59D37f85D61A1eF492bbA6135d",
},
ChainType.BASE: {
"pearl_alpha": "0xEE9F19b5DF06c7E8Bfc7B28745dcf944C504198A",
"pearl_beta": "0xeF44Fb0842DDeF59D37f85D61A1eF492bbA6135d",
},
ChainType.ETHEREUM: {
"pearl_alpha": "0xEE9F19b5DF06c7E8Bfc7B28745dcf944C504198A",
"pearl_beta": "0xeF44Fb0842DDeF59D37f85D61A1eF492bbA6135d",
"optimus_alpha": "0x88996bbdE7f982D93214881756840cE2c77C4992",
},
}

OLAS = {
ChainType.GNOSIS: "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f",
ChainType.OPTIMISM: "0x01B8b6384298D4848E3BE63D4C9D17830EeE488A",
ChainType.OPTIMISM: "0xFC2E6e6BCbd49ccf3A5f029c79984372DcBFE527",
ChainType.BASE: "0x54330d28ca3357F294334BDC454a032e7f353416",
ChainType.ETHEREUM: "0x0001A500A6B18995B03f44bb040A5fFc28E45CB0",
}
34 changes: 16 additions & 18 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def deploy_service_onchain_from_safe_single_chain( # pylint: disable=too-many-s
self,
hash: str,
chain_id: str,
fallback_staking_params: t.Optional[t.Dict] = None,
) -> None:
"""
Deploy as service on-chain
Expand Down Expand Up @@ -428,15 +429,10 @@ def deploy_service_onchain_from_safe_single_chain( # pylint: disable=too-many-s
staking_params = sftxb.get_staking_params(
staking_contract=STAKING[ledger_config.chain][user_params.staking_program_id],
)
else: # TODO fix this - using pearl beta params
staking_params = dict(
agent_ids=[25],
service_registry="0x9338b5153AE39BB89f50468E608eD9d764B755fD", # nosec
staking_token="0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f", # nosec
service_registry_token_utility="0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8", # nosec
min_staking_deposit=20000000000000000000,
activity_checker="0x155547857680A6D51bebC5603397488988DEb1c8" # nosec
)
elif fallback_staking_params is not None:
staking_params = fallback_staking_params
else:
raise ValueError("Staking params are required!")

if user_params.use_staking:
self.logger.info("Checking staking compatibility")
Expand Down Expand Up @@ -470,20 +466,23 @@ def deploy_service_onchain_from_safe_single_chain( # pylint: disable=too-many-s
f"address: {safe}; required olas: {required_olas}; your balance: {balance}"
)

agent_id = (
staking_params["agent_ids"] and staking_params["agent_ids"][0]
or fallback_staking_params["agent_ids"][0]
)
on_chain_hash = self._get_on_chain_hash(chain_config=chain_config)
is_first_mint = self._get_on_chain_state(chain_config=chain_config) == OnChainState.NON_EXISTENT
is_update = (
(not is_first_mint)
and (on_chain_hash is not None)
and (on_chain_hash != service.hash or current_agent_id != staking_params["agent_ids"][0])
and (on_chain_hash != service.hash or current_agent_id != agent_id)
)

if is_update:
self._terminate_service_on_chain_from_safe(
hash=hash,
chain_id=chain_id
)

# Update service
if self._get_on_chain_state(chain_config=chain_config) == OnChainState.PRE_REGISTRATION:
self.logger.info("Updating service")
Expand All @@ -492,7 +491,7 @@ def deploy_service_onchain_from_safe_single_chain( # pylint: disable=too-many-s
.add(
sftxb.get_mint_tx_data(
package_path=service.service_path,
agent_id=staking_params["agent_ids"][0],
agent_id=agent_id,
number_of_slots=service.helper.config.number_of_agents,
cost_of_bond=(
staking_params["min_staking_deposit"]
Expand Down Expand Up @@ -537,7 +536,7 @@ def deploy_service_onchain_from_safe_single_chain( # pylint: disable=too-many-s
.add(
sftxb.get_mint_tx_data(
package_path=service.service_path,
agent_id=staking_params["agent_ids"][0],
agent_id=agent_id,
number_of_slots=service.helper.config.number_of_agents,
cost_of_bond=(
staking_params["min_staking_deposit"]
Expand Down Expand Up @@ -574,7 +573,6 @@ def deploy_service_onchain_from_safe_single_chain( # pylint: disable=too-many-s
if user_params.use_staking:
token_utility = staking_params["service_registry_token_utility"]
olas_token = staking_params["staking_token"]
agent_id = staking_params["agent_ids"][0]
self.logger.info(
f"Approving OLAS as bonding token from {safe} to {token_utility}"
)
Expand Down Expand Up @@ -621,7 +619,6 @@ def deploy_service_onchain_from_safe_single_chain( # pylint: disable=too-many-s

if self._get_on_chain_state(chain_config=chain_config) == OnChainState.ACTIVE_REGISTRATION:
cost_of_bond = user_params.cost_of_bond
agent_id = staking_params["agent_ids"][0]
if user_params.use_staking:
token_utility = staking_params["service_registry_token_utility"]
olas_token = staking_params["staking_token"]
Expand Down Expand Up @@ -747,6 +744,7 @@ def _terminate_service_on_chain_from_safe(self, hash: str, chain_id: str) -> Non
keys = service.keys
instances = [key.address for key in keys]
wallet = self.wallet_manager.load(ledger_config.type)
chain_type = ChainType.from_id(int(chain_id))

# TODO fixme
os.environ["CUSTOM_CHAIN_RPC"] = ledger_config.rpc
Expand Down Expand Up @@ -808,7 +806,7 @@ def _terminate_service_on_chain_from_safe(self, hash: str, chain_id: str) -> Non
owner_key=str(
self.keys_manager.get(key=current_safe_owners[0]).private_key # TODO allow multiple owners
), # noqa: E800
new_owner_address=wallet.safe if wallet.safe else wallet.crypto.address # TODO it should always be safe address
new_owner_address=wallet.safes[chain_type] if wallet.safes[chain_type] else wallet.crypto.address # TODO it should always be safe address
) # noqa: E800

def _get_current_staking_program(self, chain_data, ledger_config, sftxb) -> t.Optional[str]:
Expand Down Expand Up @@ -1149,7 +1147,7 @@ def deploy_service_locally(self, hash: str, force: bool = True, chain_id: str =
deployment.start(use_docker=use_docker)
return deployment

def stop_service_locally(self, hash: str, delete: bool = False) -> Deployment:
def stop_service_locally(self, hash: str, delete: bool = False, use_docker: bool = False) -> Deployment:
"""
Stop service locally

Expand All @@ -1158,7 +1156,7 @@ def stop_service_locally(self, hash: str, delete: bool = False) -> Deployment:
:return: Deployment instance
"""
deployment = self.load_or_create(hash=hash).deployment
deployment.stop()
deployment.stop(use_docker)
if delete:
deployment.delete()
return deployment
Expand Down
1 change: 1 addition & 0 deletions operate/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class ConfigurationTemplate(TypedDict):
use_staking: bool
cost_of_bond: int
fund_requirements: FundRequirementsTemplate
fallback_chain_params: t.Optional[t.Dict]


ConfigurationTemplates = t.Dict[str, ConfigurationTemplate]
Expand Down
Loading
Loading