Coder Social home page Coder Social logo

v2-action-signing-python's Introduction

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

Usage

  1. Install package: pip install lyra_v2_action_signing

  2. Sign an order

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

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

action = SignedAction(
    subaccount_id=30769,
    owner=SMART_CONTRACT_WALLET_ADDRESS, # from Protocol Constants table in docs.lyra.finance
    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. Create venv and run pip install -e ., this reflects changes in package immediately in venv
  2. Install dev related packages with pip install -r requirements-dev.txt

v2-action-signing-python's People

Contributors

joshpwrk avatar

Watchers

earthtojake avatar DomRom avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.