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/strategy selection #7

Merged
merged 9 commits into from
Dec 10, 2024
Merged
10 changes: 10 additions & 0 deletions operate/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,16 @@ def _build_docker(
# "SKILL_TRADER_ABCI_MODELS_PARAMS_ARGS_MECH_REQUEST_PRICE=10000000000000000" # noqa
# ) # noqa

# temporary fix: remove extra volume
for service_name, service_data in deployment["services"].items():
if "abci" in service_name:
# Access the volumes list in this service
volumes = service_data.get("volumes", [])

# Remove './data:/data:Z' if it's in the volumes list
if "./data:/data:Z" in volumes:
volumes.remove("./data:/data:Z")

with (build / DOCKER_COMPOSE_YAML).open("w", encoding="utf-8") as stream:
yaml_dump(data=deployment, stream=stream)

Expand Down
5 changes: 5 additions & 0 deletions report.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def generate_report():
usdc_balance_formatted = safe_info.get('usdc_balance_formatted', 'N/A')
_print_status("USDC Balance", usdc_balance_formatted)

# Check for OLAS balance on Staking chain
if chain_name.lower() == optimus_config.staking_chain:
olas_balance_formatted = safe_info.get('olas_balance_formatted', 'N/A')
_print_status("OLAS Balance", olas_balance_formatted)

# Low balance check
safe_threshold_wei = chain_config.get("chain_data", {}).get("user_params", {}).get("fund_requirements", {}).get("safe")
if safe_threshold_wei:
Expand Down
27 changes: 21 additions & 6 deletions run_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from dataclasses import dataclass
from pathlib import Path
from decimal import Decimal, ROUND_UP
from enum import Enum

import requests
import yaml
Expand Down Expand Up @@ -94,6 +95,11 @@
DEFAULT_MAX_FEE = 20000000
use_default_max_fee = True

class Strategy(Enum):
"""Strategy type"""
MerklPoolSearchStrategy = "merkl_pools_search"
BalancerPoolSearchStrategy = "balancer_pools_search"

def estimate_priority_fee(
web3_object: Web3,
block_number: int,
Expand Down Expand Up @@ -136,7 +142,7 @@ def get_masked_input(prompt: str) -> str:
password = ""
sys.stdout.write(prompt)
sys.stdout.flush()

fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
Expand Down Expand Up @@ -176,6 +182,7 @@ class OptimusConfig(LocalResource):
staking_chain: t.Optional[str] = None
principal_chain: t.Optional[str] = None
investment_funding_requirements: t.Optional[Dict[str, Any]] = None
selected_strategies: t.Optional[list[str]] = None

@classmethod
def from_json(cls, obj: t.Dict) -> "LocalResource":
Expand Down Expand Up @@ -391,6 +398,9 @@ def configure_local_config() -> OptimusConfig:

print()

if optimus_config.selected_strategies is None:
optimus_config.selected_strategies = [Strategy.MerklPoolSearchStrategy.value, Strategy.BalancerPoolSearchStrategy.value]

optimus_config.store()
return optimus_config

Expand Down Expand Up @@ -425,7 +435,7 @@ def get_service_template(config: OptimusConfig) -> ServiceTemplate:
home_chain_id = "34443"
return ServiceTemplate({
"name": "Optimus",
"hash": "bafybeiazaphqrn65tvscbubjvuh6mzmodqp3inwayjmye2jjweu3uea7wi",
"hash": "bafybeierrvod33ljm2lmuzmdc4bdyke57jlylpa3dwvnnbxsdu7z23f5um",

"description": "Optimus",
"image": "https://gateway.autonolas.tech/ipfs/bafybeiaakdeconw7j5z76fgghfdjmsr6tzejotxcwnvmp3nroaw3glgyve",
Expand Down Expand Up @@ -608,8 +618,12 @@ def fetch_agent_fund_requirement(chain_id, rpc, fee_history_blocks: int = 500000

return calculate_fund_requirement(rpc, fee_history_blocks, gas_amount)

def fetch_operator_fund_requirement(chain_id, rpc, fee_history_blocks: int = 500000) -> int:
gas_amount = 30_000_000
def fetch_operator_fund_requirement(chain_id, rpc, service_exists: bool = True, fee_history_blocks: int = 500000) -> int:
if service_exists:
gas_amount = 5_000_000
else:
gas_amount = 30_000_000

if use_default_max_fee:
return DEFAULT_MAX_FEE * gas_amount

Expand Down Expand Up @@ -695,7 +709,7 @@ def main() -> None:
if agent_fund_requirement is None:
agent_fund_requirement = chain_config.chain_data.user_params.fund_requirements.agent

operational_fund_req = fetch_operator_fund_requirement(chain_id, chain_config.ledger_config.rpc)
operational_fund_req = fetch_operator_fund_requirement(chain_id, chain_config.ledger_config.rpc, service_exists)
if operational_fund_req is None:
operational_fund_req = chain_metadata.get("operationalFundReq")

Expand Down Expand Up @@ -860,7 +874,8 @@ def main() -> None:
"MIN_SWAP_AMOUNT_THRESHOLD": optimus_config.min_swap_amount_threshold,
"ALLOWED_CHAINS": json.dumps(optimus_config.allowed_chains),
"TARGET_INVESTMENT_CHAINS": json.dumps(optimus_config.target_investment_chains),
"INITIAL_ASSETS": json.dumps(initial_assets)
"INITIAL_ASSETS": json.dumps(initial_assets),
"SELECTED_STRATEGIES": json.dumps(optimus_config.selected_strategies)
}
apply_env_vars(env_vars)
print("Skipping local deployment")
Expand Down
21 changes: 19 additions & 2 deletions wallet_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(message)s')

USDC_ABI = [{
TOKEN_ABI = [{
"constant": True,
"inputs": [{"name": "_owner", "type": "address"}],
"name": "balanceOf",
"outputs": [{"name": "balance", "type": "uint256"}],
"type": "function"
}]

OLAS_ADDRESS = "0xcfD1D50ce23C46D3Cf6407487B2F8934e96DC8f9"

def load_config():
try:
optimus_config = load_local_config()
Expand Down Expand Up @@ -69,13 +71,22 @@ def get_balance(web3, address):

def get_usdc_balance(web3, address, chain_name):
try:
usdc_contract = web3.eth.contract(address=USDC_ADDRESS, abi=USDC_ABI)
usdc_contract = web3.eth.contract(address=USDC_ADDRESS, abi=TOKEN_ABI)
balance = usdc_contract.functions.balanceOf(address).call()
return Decimal(balance) / Decimal(1e6) # USDC has 6 decimal places
except Exception as e:
print(f"Error getting USDC balance for address {address}: {e}")
return Decimal(0)

def get_olas_balance(web3, address, chain_name):
try:
olas_address = OLAS_ADDRESS[chain_name]
olas_contract = web3.eth.contract(address=OLAS_ADDRESS, abi=TOKEN_ABI)
balance = olas_contract.functions.balanceOf(address).call()
return Decimal(balance) / Decimal(1e18) # OLAS has 18 decimal places
except Exception as e:
print(f"Error getting OLAS balance for address {address}: {e}")
return Decimal(0)
class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, Decimal):
Expand Down Expand Up @@ -148,6 +159,12 @@ def save_wallet_info():
safe_balances[chain_name]["usdc_balance"] = usdc_balance
safe_balances[chain_name]["usdc_balance_formatted"] = f"{usdc_balance:.2f} USDC"

# Get USDC balance for Principal Chain
if chain_name.lower() == optimus_config.staking_chain:
olas_balance = get_olas_balance(web3, safe_address, chain_name.lower())
safe_balances[chain_name]["olas_balance"] = usdc_balance
safe_balances[chain_name]["olas_balance_formatted"] = f"{olas_balance:.6f} OLAS"

except Exception as e:
print(f"An error occurred while processing chain ID {chain_id}: {e}")
continue
Expand Down
Loading