This example can be run directly or with Docker.
You will need a private key of the Ethereum account that will control your linora account. Refer to how to export an account's private key on MetaMask.
Remember to replace the value of ETHEREUM_PRIVATE_KEY below with your own private key.
All commands below are to be run from examples directory.
To run it directly, ensure Python 3.9+ is installed.
python3.9 -m venv .venv # create Python 3.9 virtual env
source .venv/bin/activate
pip install -r requirements.txt # (.venv)
ETHEREUM_PRIVATE_KEY=private_key python onboarding.py # (.venv)In order to fetch the L2 account details against the given L1 / Ethereum private key, you can run below script
# pre-req: create venv
ETHEREUM_PRIVATE_KEY=private_key python fetch_l2_account_details.pyMake sure you have pre-installed Docker.
Build the Docker image and run the Docker container.
docker build -t example .
docker run -it --rm \
-e ETHEREUM_PRIVATE_KEY=private_key \
exampleWhat this example does:
- Generates and onboards a new linora account based on your Ethereum private key
- Retrieves a JWT to be used to make requests to private endpoints of the API
- Makes a request to the private GET /orders endpoint using the JWT
Refer to the main function under onboarding.py for the main flow that consists of:
- Onboarding
- Getting a JWT
- Calling a private endpoint
Once you have onboarded, if you would rather use your L2 information directly, be sure to skip over the Initialize Ethereum account and Generate linora account functions in the script. If you simply plug in your L2 private key in place of the eth_private_key_hex variable, you will actually be generating a separate account that isn't actually usable.
Why?
These functions are a part of a deterministic process to generate L2 data. When you use your L1 private key (as expected), it will generate the same L2 data to be used every time. However, if you give the program something different it's going to generate separate L2 data which is going to point to a separate account. Any info you try to pull this way will show as if the account is completely blank.
That being said, once you've onboarded and generated the L2 data (even just from the UI), you can plug the L2 account and private key directly into the other functions calling private endpoints which will authenticate correctly just as if you had started with the L1 private key.
What this example does:
- Withdraws from linora (Paraclear Contract) to L1 token bridge contract
- Waits for transaction to be accepted on L1 (Ethereum)
- Withdraw from L1 token bridge contract to L1 wallet
Refer to the main function under withdraw.py for the main flow that consists of:
- Withdraw from linora (Paraclear Contract)
- Wait for transaction to be accepted on L1
- Note: Poll for transaction receipt can take up to 12 hours
- Withdraw from L1 bridge
Note: L1 gas fees may fluctuate, adjust maxFeePerGas and maxPriorityFeePerGas accordingly
ABI for any L1 contract can be sourced from Etherscan. Steps:
- Go to Goerli Etherscan
- Search for contract address (or
https://goerli.etherscan.io/address/<address>) - Click on
Contracttab - Click on
Read as Proxytab - Click on ABI for the implementation contract link
- Navigate to
Contract ABIsection - Save the ABI to a JSON file
Note: Contracts must be deployed with source code verification on Etherscan.
Script to transfer all USDC tokens from one L2 account to another L2 account on linora (Paraclear Contract).
# pre-req: create venv
OLD_linora_ACCOUNT_PRIVATE_KEY=private_key NEW_linora_ACCOUNT_PRIVATE_KEY=private_key python transfer_l2_usdc.pyWhat this example does:
- Withdraws from linora (Paraclear Contract) to L2 Contract (old)
- Triggers transfer of USDC tokens from L2 Contract (old) to L2 Contract (new)
- Deposits to linora (Paraclear Contract) from L2 Contract (new)
- Ensure both accounts have previously onboarded via the onboarding example or UI:
OLD_linora_ACCOUNT_PRIVATE_KEY(L2 Private Key of old account)NEW_linora_ACCOUNT_PRIVATE_KEY(L2 Private Key of new account)
- Remove default amount from transfer_l2_usdc.py to transfer all USDC balance
- Default: 100 USDC
- Please note:
- Script only transfers free USDC tokens
- It will not realize any PnLs or close any open positions