Skip to main content

Python SDK for Flexvaults - manage deposits, withdrawals, locks, and transfers

Project description

flexvaults-sdk

Python SDK for Flexvaults - manage deposits, withdrawals, locks, and transfers on the accounting module.

Installation

pip install flexvaults-sdk

Quick Start

import asyncio
from flexvaults import FlexvaultsClient, DepositQuoteRequest

async def main():
    async with FlexvaultsClient(base_url="https://api.example.com") as client:
        # Get a deposit quote
        quote = await client.get_deposit_quote(
            DepositQuoteRequest(
                user_address="0xYourAddress",
                token_id="0xTokenId",
                amount=1000000,
            )
        )
        print(f"Deposit to: {quote.deposit_address}")

asyncio.run(main())

Direct SIWE Private Reads

Private read endpoints such as balances and locked funds use the backend's direct SIWE flow. The Python SDK exposes the raw helpers and token setters rather than a hosted auth-code wrapper.

import asyncio
from flexvaults import FlexvaultsClient

async def main():
    async with FlexvaultsClient(base_url="https://api.example.com") as client:
        domain = await client.get_siwe_domain()
        nonce = await client.get_siwe_nonce("0xYourAddress")

        # Build and sign the SIWE message in your app, then submit it here.
        login = await client.authenticate_private_reads(
            siwe_message="your signed-in message",
            signature="0xYourSignature",
        )

        balance = await client.get_balance("0xTokenId")
        print(domain.domain, nonce.nonce, login.address, balance.balance)

asyncio.run(main())

EIP-712 Signing

from eth_account import Account
from flexvaults import (
    sign_lock_message,
    LockNonceResponse,
    SignLockParams,
    LockMessage,
    get_accounting_contract,
    create_lock_expiry,
)

account = Account.from_key("0xYourPrivateKey")

signature = sign_lock_message(
    SignLockParams(
        account=account,
        network="testnet",
        verifying_contract=get_accounting_contract("testnet"),
        message=LockMessage(
            user_address=account.address,
            service_address="0xServiceAddress",
            token_id="0xTokenId",
            amount=1000000,
            expiry=create_lock_expiry(60),
            nonce=0,
        ),
    )
)

API Reference

Client

  • FlexvaultsClient(base_url, timeout=30.0, headers=None) - Main API client
    • get_deposit_quote(request) - Get deposit quote
    • include_deposit(request) - Include deposit proof
    • get_balance(token_id) - Get token balance for the authenticated user
    • get_batch_balances(request) - Get multiple token balances
    • get_token_info(token_id) - Get token information
    • lock_funds(request) - Lock funds for a service
    • get_lock_nonce(user_address) - Get next create-lock nonce
    • get_modify_lock_nonce(user_address) - Get next modify-lock nonce
    • modify_lock(request) - Modify an existing lock (add funds and/or extend expiry)
    • unlock_funds(request) - Unlock specific lock
    • unlock_all_expired(request) - Unlock all expired locks
    • get_locked_funds(service_address=None) - Get locked funds for the authenticated user
    • get_total_locked_balance(token_id) - Get total locked balance for the authenticated user
    • get_expired_locks() - Get expired locks for the authenticated user
    • transfer_funds(request) - Transfer tokens (requires nonce)
    • get_transfer_nonce(user_address) - Get next transfer nonce
    • transfer_locked_funds(request) - Transfer locked tokens
    • get_transfer_locked_nonce(service_address) - Get next transfer-from-lock nonce
    • request_withdrawal(request) - Request withdrawal
    • get_withdrawal_nonce(user_address) - Get next withdrawal nonce
    • get_pending_withdrawals(user_address) - Get pending withdrawals
    • get_withdrawal_info(index) - Get withdrawal info
    • get_siwe_domain() - Get the direct SIWE auth domain
    • get_siwe_nonce(user_address) - Get a SIWE login nonce
    • login_with_siwe(siwe_message, signature) - Exchange a signed SIWE message for tokens
    • authenticate_private_reads(siwe_message, signature) - Login and store X-SIWE-Token
    • set_private_read_token(token) / clear_private_read_token() - Manage X-SIWE-Token
    • set_bearer_token(token) / clear_bearer_token() - Manage bearer auth headers

Signing

  • sign_lock_message(params) - Sign lock message
  • sign_modify_lock_message(params) - Sign modify lock message
  • sign_transfer_message(params) - Sign transfer message
  • sign_transfer_locked_message(params) - Sign transfer locked message
  • sign_withdraw_message(params) - Sign withdrawal message
  • create_lock_expiry(minutes_from_now=60) - Create expiry timestamp

Utilities

  • format_token_amount(amount, decimals=18) - Format wei to human-readable
  • parse_token_amount(amount, decimals=18) - Parse human-readable to wei
  • shorten_address(address, chars=4) - Shorten Ethereum address
  • format_timestamp(timestamp) - Format Unix timestamp to readable string
  • is_expired(expiry) - Check if timestamp is expired
  • format_time_remaining(expiry_timestamp) - Format time remaining
  • format_relative_time(timestamp) - Format relative time (e.g., "5m ago")

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flexvaults_sdk-0.1.13.tar.gz (100.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flexvaults_sdk-0.1.13-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file flexvaults_sdk-0.1.13.tar.gz.

File metadata

  • Download URL: flexvaults_sdk-0.1.13.tar.gz
  • Upload date:
  • Size: 100.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for flexvaults_sdk-0.1.13.tar.gz
Algorithm Hash digest
SHA256 fc3ad5f39c9eff0f2288fc26e254d93da745520ee0a6eb20581403837f4ed271
MD5 54a214226d64859a356d02097146d51d
BLAKE2b-256 12dfa7ec88cf5ba719c301fab1d6820b1b30bd88021ced17d3cb5962544f9de1

See more details on using hashes here.

File details

Details for the file flexvaults_sdk-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: flexvaults_sdk-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for flexvaults_sdk-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 ec8e6ad300eafe53eb0a93dec05140221b41f0b9ef3821028ace747ac32bf409
MD5 0f1f38c0d5ea28bf859b02672186aa11
BLAKE2b-256 e21848bc8d372e7a625169ae7a16c7a7861d20a41b12de015633643064d03055

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page