Giter Club home page Giter Club logo

code-samples's Introduction

code-samples

Collection of Paradex code samples, snippets and benchmarks

Examples

Benchmarks

Order signing benchmarks

On MacBook Pro 2021, M1 Pro

Go: 1430 signs/sec - Go `gnark-crypto`
Java: 182 signs/sec - JVM `StarknetCurve` (1)
Java: 8 signs/sec - C++ `crypto-cpp`
Python: 182 signs/sec - Rust `starknet-crypto-py`
Python: 8 signs/sec - C++ `crypto-cpp-py`
TypeScript: 50 signs/sec - JavaScript `starknet.js`

(1) Reference: java/paradex/StarknetCurve.groovy

Running on your machine

Examples and benchmarks for signing orders.

Python

To run it directly, you will need Python 3.9+.

cd python
python3.9 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python bench_order_sign.py

Go

cd go
go test -bench .

Java

cd java
groovy order.groovy bench

TypeScript

cd typescript
yarn run bench

Ethereum and Starknet Keys

Ethereum (L1) private key is used to sign a message. Generated signature is deterministic and can only be generated by the owner of the Ethereum private key.

This signature is then used to generate Starknet (L2) private key (also referred to as Paradex private key).

Starknet (L2) private key can used to deduce Starknet public key. L2 private key is also used to generate auth, onboarding and order signatures.

Auth endpoint also requires providing the Ethereum address which is derived from the Ethereum private key in examples of some languages.

During the onboarding process, an Account Contract is deployed on Starknet with the Starknet public key. This account contract address is used to identify token and perpetual balances on chain.

On UI, after connecting with your Ethereum wallet, you will be able to click on the truncated L2 address (top right) and view you L1 and L2 address. As well as copy the L2 private key to clipboard.

To get complete understanding of this, please refer to Onboarding & Wallets section in Paradex documentation.

code-samples's People

Contributors

amayvs avatar dependabot[bot] avatar taiyangc avatar tazman7 avatar sv avatar aweaver89 avatar guillermolunar7 avatar luccamordente avatar mdantonio avatar sergeyvolynkin avatar varunjain15 avatar

Stargazers

Andrew avatar Arnold avatar Suresh avatar qqq avatar Zhi Wei Fan avatar Meghdad avatar  avatar

Watchers

 avatar  avatar Kostas Georgiou avatar

code-samples's Issues

some issue with dll module

suggest to use all pure python module
not c module

return cpp_hash(left, right)

File "C:\Python310\lib\site-packages\crypto_cpp_py\cpp_bindings.py", line 103, in cpp_hash
AttributeError: 'CustomStarknetChainId' object has no attribute 'to_bytes'

Mainnet config missing from Python SDK

Hey,

I had to add the mainnet chain ID to get it to work in production. Otherwise, it was failing to sign orders.

In starknet_utils.py:

class CustomStarknetChainId(Enum):
    PRIVATE_SN_TESTNET = int_from_bytes(b"PRIVATE_SN_POTC_SEPOLIA")
    # I added this line
    PRIVATE_SN_PARACLEAR_MAINNET = int_from_bytes(b"PRIVATE_SN_PARACLEAR_MAINNET")

How to get Chain ID for Starknet’s main network?

Hello Paradex Team,

Could you please clarify how to get Chain ID for Starknet’s main network?

below your example with hardcoded value for SEPOLIA:

BigInteger chainID = new BigInteger('7693264728749915528729180568779831130134670232771119425')

    // Chain ID - PRIVATE_SN_POTC_SEPOLIA
    BigInteger chainID = new BigInteger('7693264728749915528729180568779831130134670232771119425')
    String chainIdHex = '0x' + chainID.toString(16).toUpperCase()

deposit_to_paraclear

deposit_to_paraclear

starknet_py.net.client_errors.ClientError: Client failed with code 400: {"code": "StarknetErrorCode.UNINITIALIZED_CONTRACT", "message": "Contract with address 0xxxx is not deployed."}.

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.