Skip to content

Commit

Permalink
Move all superfluid-related code to SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
philogicae committed Jan 31, 2025
1 parent e2f6efc commit cae2281
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 80 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [
"aiodns==3.2",
"aiohttp==3.10.11",
"aleph-message>=0.6",
"aleph-sdk-python>=1.3,<2",
"aleph-sdk-python @ git+https://github.com/aleph-im/aleph-sdk-python.git@add-manage-flow-superfluid",
"base58==2.1.1", # Needed now as default with _load_account changement
"py-sr25519-bindings==0.2", # Needed for DOT signatures
"pygments==2.19.1",
Expand Down
24 changes: 13 additions & 11 deletions src/aleph_client/commands/instance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
from aleph.sdk.client.vm_client import VmClient
from aleph.sdk.client.vm_confidential_client import VmConfidentialClient
from aleph.sdk.conf import load_main_configuration, settings
from aleph.sdk.evm_utils import get_chains_with_holding, get_chains_with_super_token
from aleph.sdk.evm_utils import (
FlowUpdate,
get_chains_with_holding,
get_chains_with_super_token,
)
from aleph.sdk.exceptions import (
ForgottenMessageError,
InsufficientFundsError,
Expand Down Expand Up @@ -52,7 +56,6 @@
fetch_vm_info,
find_crn_of_vm,
)
from aleph_client.commands.instance.superfluid import FlowUpdate, update_flow
from aleph_client.commands.node import NodeInfo, _fetch_nodes
from aleph_client.commands.utils import (
filter_only_valid_messages,
Expand Down Expand Up @@ -217,9 +220,9 @@ async def create(
if is_stream and isinstance(account, ETHAccount):
if account.CHAIN != payment_chain:
account.switch_chain(payment_chain)
if account.superfluid_connector and hasattr(account.superfluid_connector, "can_start_flow"):
if account.has_superfluid_connector:
try: # Quick check with theoretical min price
account.superfluid_connector.can_start_flow(FLOW_INSTANCE_PRICE_PER_SECOND) # 0.055/h
account.can_start_flow(FLOW_INSTANCE_PRICE_PER_SECOND) # 0.055/h
except Exception as e:
echo(e)
raise typer.Exit(code=1)
Expand Down Expand Up @@ -535,14 +538,13 @@ async def create(
price: PriceResponse = await client.get_program_price(item_hash)
ceil_factor = 10**18
required_tokens = ceil(Decimal(price.required_tokens) * ceil_factor) / ceil_factor
if isinstance(account, ETHAccount) and account.superfluid_connector:
if isinstance(account, ETHAccount) and account.has_superfluid_connector:
try: # Double check with effective price
account.superfluid_connector.can_start_flow(FLOW_INSTANCE_PRICE_PER_SECOND) # Min for 0.11/h
account.can_start_flow(FLOW_INSTANCE_PRICE_PER_SECOND) # Min for 0.11/h
except Exception as e:
echo(e)
raise typer.Exit(code=1)
flow_hash = await update_flow(
account=account,
flow_hash = await account.manage_flow(
receiver=crn.stream_reward_address,
flow=Decimal(required_tokens),
update_type=FlowUpdate.INCREASE,
Expand Down Expand Up @@ -706,9 +708,9 @@ async def delete(
if payment and payment.type == PaymentType.superfluid and payment.receiver and isinstance(account, ETHAccount):
if account.CHAIN != payment.chain:
account.switch_chain(payment.chain)
if account.superfluid_connector and price:
flow_hash = await update_flow(
account, payment.receiver, Decimal(price.required_tokens), FlowUpdate.REDUCE
if account.has_superfluid_connector and price:
flow_hash = await account.manage_flow(
payment.receiver, Decimal(price.required_tokens), FlowUpdate.REDUCE
)
if flow_hash:
echo(f"Flow {flow_hash} has been deleted.")
Expand Down
68 changes: 0 additions & 68 deletions src/aleph_client/commands/instance/superfluid.py

This file was deleted.

0 comments on commit cae2281

Please sign in to comment.