Skip to main content

v2-action-signing-python

Python package to sign the following on-chain self-custodial requests:

  1. order
  2. RFQ quote
  3. RFQ execution
  4. transfer positions

Although the below actions are supported by the SDK, we recommend you use the UX developer portal (https://docs.derive.xyz/docs/onboard-via-interface):

  1. create subaccount
  2. deposit
  3. withdrawal
  4. transfer collateral

⚠️ Warning: Note, the owner address and the X-LyraWallet is the Derive wallet address of the user. This is NOT your original EOA, but the smart contract wallet on the Derive Chain. To find it in the website go to Home -> Developers -> "Derive Wallet".

Usage

  1. Install package: pip install derive_action_signing

  2. Sign an order

from web3 import Web3
from derive_action_signing import SignedAction, TradeModuleData, utils

session_key_wallet = Web3().eth.account.from_key("0x2ae8be44db8a590d20bffbe3b6872df9b569147d3bf6801a35a28281a4816bbd")

action = SignedAction(
    subaccount_id=30769,
    # The Derive wallet address (not "owner") of account. This is NOT your original EOA, but the smart contract wallet on the Derive Chain. To find it in the website go to Home -> Developers -> "Derive Wallet".
    owner=SMART_CONTRACT_WALLET_ADDRESS,
    signer=session_key_wallet.address,
    signature_expiry_sec=utils.MAX_INT_32,
    nonce=utils.get_action_nonce(),
    module_address=TRADE_MODULE_ADDRESS, # from Protocol Constants table in docs.lyra.finance
    module_data=TradeModuleData(
        asset=instrument_ticker["base_asset_address"],
        sub_id=int(instrument_ticker["base_asset_sub_id"]),
        limit_price=Decimal("100"),
        amount=Decimal("1"),
        max_fee=Decimal("1000"),
        recipient_id=30769,
        is_bid=True,
    ),
    DOMAIN_SEPARATOR=DOMAIN_SEPARATOR, # from Protocol Constants table in docs.derive.xyz
    ACTION_TYPEHASH=ACTION_TYPEHASH, # from Protocol Constants table in docs.derive.xyz
)

action.sign(session_key_wallet.key)

For full signing examples see examples/ in https://github.com/derivexyz/v2-action-signing-python/tree/master/examples.

Acknowledgements

Thank you 8baller for building a full Python client for the v2 API. Much of the signing logic in the repo was used to inform this package: https://github.com/8ball030/lyra_client

Developers

  1. Install Poetry: curl -sSL https://install.python-poetry.org | python3 -
  2. poetry install
  3. poetry shell (activate venv)
  4. pytest

Download files

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

Source Distribution

derive_action_signing-0.0.11.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

derive_action_signing-0.0.11-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file derive_action_signing-0.0.11.tar.gz.

File metadata

  • Download URL: derive_action_signing-0.0.11.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.2.0

File hashes

Hashes for derive_action_signing-0.0.11.tar.gz
Algorithm Hash digest
SHA256 96e49a4a27e0357b0803843a9c9a42e19c9c582c3db5ac0a23621d7df93784c9
MD5 65b587217498e1d5eff11fae3041028d
BLAKE2b-256 bae4c5ec31d82f3b87d0a5732e81ae9d5b6c96d4ab8066d24eb6acaa74de600a

See more details on using hashes here.

File details

Details for the file derive_action_signing-0.0.11-py3-none-any.whl.

File metadata

File hashes

Hashes for derive_action_signing-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 3b8c3ee7b3928ef874a9ac57cae6f7e376eeda56312c8ae0b043d47f35213c84
MD5 84f48ba78a442f4472197e9a7688d145
BLAKE2b-256 da5c9aae29cd09371a5cb45974e0a4ba4625e477b7f49e58bf3573e21edea23d

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