Skip to content

Commit

Permalink
hotfix: add max fee and max priority fee
Browse files Browse the repository at this point in the history
  • Loading branch information
Divya-Solulab committed Nov 27, 2024
1 parent ce05876 commit 1b657b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
1 change: 0 additions & 1 deletion operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,6 @@ def update_service(
) -> Service:
"""Update a service."""

self.logger.info("-----Entering update local service-----")
old_service = self.load_or_create(hash=old_hash)
new_service = self.load_or_create(
hash=new_hash, service_template=service_template
Expand Down
26 changes: 17 additions & 9 deletions run_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
# this means default values will be used
"FEE_HISTORY_PERCENTILE": "50",
"DEFAULT_PRIORITY_FEE": "2000000",
"MAX_PRIORITY_FEE_PER_GAS": "",
"MAX_FEE_PER_GAS": "",
"MAX_PRIORITY_FEE_PER_GAS": "3000000",
"MAX_FEE_PER_GAS": "20000000",
}
},
}
Expand All @@ -115,6 +115,7 @@
"mode":"mode"
}
ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"
DEFAULT_MAX_FEE = 20000000

def estimate_priority_fee(
web3_object: Web3,
Expand Down Expand Up @@ -457,7 +458,7 @@ def get_service_template(config: OptimusConfig) -> ServiceTemplate:
home_chain_id = "10" if config.staking_chain == "optimism" else "34443"
return ServiceTemplate({
"name": "Optimus",
"hash": "bafybeicsbfw2g6gp3fyp434qgqjcy6gwe4fgz4kjhgg4gy5bb7lpt5w6n4",
"hash": "bafybeiazaphqrn65tvscbubjvuh6mzmodqp3inwayjmye2jjweu3uea7wi",

"description": "Optimus",
"image": "https://gateway.autonolas.tech/ipfs/bafybeiaakdeconw7j5z76fgghfdjmsr6tzejotxcwnvmp3nroaw3glgyve",
Expand Down Expand Up @@ -668,10 +669,19 @@ def calculate_fund_requirement(rpc, fee_history_blocks: int, gas_amount: int, fe

def fetch_agent_fund_requirement(chain_id, rpc, fee_history_blocks: int = 500000) -> int:
gas_amount = 50_000_000
if chain_id == '34443':
return DEFAULT_MAX_FEE * gas_amount

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 chain_id == '34443':
return DEFAULT_MAX_FEE * gas_amount
return calculate_fund_requirement(rpc, fee_history_blocks, gas_amount)

def main() -> None:
Expand Down Expand Up @@ -732,8 +742,6 @@ def main() -> None:
if chain_config.ledger_config.rpc is not None:
os.environ["CUSTOM_CHAIN_RPC"] = chain_config.ledger_config.rpc
os.environ["OPEN_AUTONOMY_SUBGRAPH_URL"] = "https://subgraph.autonolas.tech/subgraphs/name/autonolas-staging"
os.environ["MAX_PRIORITY_FEE_PER_GAS"] = chain_metadata["gasParams"]["MAX_PRIORITY_FEE_PER_GAS"]
os.environ["MAX_FEE_PER_GAS"] = chain_metadata["gasParams"]["MAX_FEE_PER_GAS"]

service_exists = manager._get_on_chain_state(chain_config) != OnChainState.NON_EXISTENT

Expand Down Expand Up @@ -770,7 +778,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 @@ -895,7 +903,7 @@ def main() -> None:

manager.fund_service(hash=service.hash, chain_id=chain_id, safe_fund_treshold=safe_fund_threshold, safe_topup=safe_topup, agent_fund_threshold=agent_fund_requirement, agent_topup=agent_fund_requirement)

if usdc_investment_fund_requirement > 0:
if usdc_investment_fund_requirement > 0 and not service_exists:
usdc_balance = get_erc20_balance(ledger_api, usdc_address, address)
# transfer all the usdc balance into the service safe
manager.fund_service_erc20(
Expand Down
3 changes: 1 addition & 2 deletions staking_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
def staking_report(config: dict) -> None:
try:
_print_section_header("Performance")
_print_subsection_header("Staking")
operator_address = load_operator_safe_balance(OPERATE_HOME)
if not operator_address:
print("Error: Operator address could not be loaded.")
Expand All @@ -64,9 +63,9 @@ def staking_report(config: dict) -> None:
None
)
if not chain_data:
print("No staking configuration found where 'use_staking' is true.")
return

_print_subsection_header("Staking")
rpc = chain_data.get("ledger_config", {}).get("rpc")
if not rpc:
print("Error: RPC endpoint not found in ledger configuration.")
Expand Down

0 comments on commit 1b657b6

Please sign in to comment.