v2-action-signing-python
Python package to sign the following on-chain self-custodial requests:
- order
- RFQ quote
- RFQ execution
- 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):
- create subaccount
- deposit
- withdrawal
- 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
-
Install package:
pip install derive_action_signing -
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
- Install Poetry: curl -sSL https://install.python-poetry.org | python3 -
poetry installpoetry shell(activate venv)pytest
Note: If you encounter issues with eth-typing compatibility when running tests, use:
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 pytest
This prevents loading of web3's pytest plugin which has compatibility issues with eth-typing v5.
Metadata
Release files for derive_action_signing 0.0.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| derive_action_signing-0.0.13.tar.gz | 7.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| derive_action_signing-0.0.13-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.7 kB
Release files / derive_action_signing-0.0.13.tar.gz
| Download URL | derive_action_signing-0.0.13.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
753b3766e4c836d4cc4b36e076b14e4b9ebf28843a6192312459f718f0236d60
|
|
BLAKE2b-256 checksum How to use checksums |
20d87023679883924dca36c12f432c6f0a5f4ffa38913794b5819fe5944ceb1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.9.23 Linux/6.11.0-1018-azure
|
Release files / derive_action_signing-0.0.13-py3-none-any.whl
| Download URL | derive_action_signing-0.0.13-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b5fb8ad9d4888a09441da9fc97d66fc0c909d1d1268c54a65c4e8bbd141d6598
|
|
BLAKE2b-256 checksum How to use checksums |
ad0e7726d103c0ac291349f135210215476e41fb534f9b93b9a1d623f79d8c2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.9.23 Linux/6.11.0-1018-azure
|