Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

152 Commits

Repository files navigation

LoopringSharp

WARNING! The API Is currently under construction and not ready for use

What is?

A C# NuGet Package wrapper around the Loopring API endpoints to greatly simplify communication. It should theoretically be as simple as importing the package, creating a singleton client, and off to the races.

The what api?

The Loopring API https://docs.loopring.io/

How be do?

Basically it's just

LoopringSharp.Clientclient=newLoopringSharp.Client("<apiKey>","<loopring private key>","<ethereum private key>",<accountid>,"<ethreum public address>","<api url>");

More explicitly:

LoopringSharp.Clientclient=newLoopringSharp.Client("pJ3sU5kJ489fLmrewslkreownsbTunMK9fcusikhK6tn5nEDY4vvkWg8PgV2R","0x444444444444444444444444444444444444444444444444444444444444444","0x5555555555555555555555555555555555555555555555555555555555555555",1,"0x6666666666666666666666666666666666666666","https://uat2.loopring.io/");varstorageId=awaitclient.StorageId(1);

The is also the simplified version:

LoopringSharp.Clientclient=newLoopringSharp.Client("<loopring private key>","<ethereum private key>","<api url>");

Which uses API calls within the constructor to gather the missing information.

The values above are stored in RAM, which means they could be read by specialist software. If you are making a secure app please use the LoopringSharp.SecureClient which doesn't store anything in memory.

For client applications (like say you want to make a windows charting application or similar), there are now two better alternatives: MetaMask and WalletConnect. You can instruct the API to connect to one of those two services in order to get the information it needs. This is very secure since the private wallet information is not stored in-memory but instead lives within a secure third party service that does all the transfer validation and signing.

LoopringAPI.Clientclient=newLoopringAPI.Client("<api url>");varstorageId=awaitclient.StorageId(1);

In the future, I'll look into adding WalletConnect support as well

Here's a list of all the Loopring API Endpoints and which ones have been implemented so far in LoopringSharp

Implemented?API CallEndpoint PathDescription
XTimestamp/api/v3/timestampReturns the relayer's current time in millisecond
XApiKey/api/v3/apiKeyGet the ApiKey associated with the user's account
XUpdateApiKey/api/v3/apiKeyRequest a new ApiKey for this user account
XStorageId/api/v3/storageIdFetches the next order id for a given sold token
XOrderDetails/api/v3/orderGets the details of one specific order using the hashId
XSubmitOrder/api/v3/orderSubmits a new exchange / swap order
XDeleteOrder/api/v3/orderCancels a open exchange / swap order
XOrdersDetails/api/v3/ordersGets a detailed list of multiple orders based on the filtering criteria
XGetMarkets/api/v3/exchange/marketsGet a list of all the markets available on the exchange
XGetTokens/api/v3/exchange/tokensReturns the configurations of all supported tokens, including Ether.
XExchangeInfo/api/v3/exchange/infoGets all sorts of properties about the exchange you're contacting
XGetDepth/api/v3/depthReturns the order book of a given trading pair.
XTicker/api/v3/tickerGets the price information for any crypto pair available to trade on Loopring
XGetCandlesticks/api/v3/candlestickReturn the candlestick data of a given trading pair.
XGetPrice/api/v3/priceFetches, for all the tokens supported by Loopring, their fiat price.
XGetTrades/api/v3/tradeQuery latest trades with specified market
XTransfer/api/v3/transferSend some tokens to anyone else on L2
XGetAccountInfo/api/v3/accountReturns data associated with the user's exchange account
XRequestNewL2PrivateKey/api/v3/accountGenerates a new L2 private key for your account. Does not return they key
XCreateInfo/api/v3/user/createInfoReturns a list of Ethereum transactions from users for exchange account registration.
XUpdateInfo/api/v3/user/updateInfoReturns a list Ethereum transactions from users for resetting exchange passwords.
XBallances/api/v3/user/balancesReturns user's Ether and token balances on exchange.
XGetDeposits/api/v3/user/depositsReturns a list of deposit records for the given user.
XGetWithdrawls/api/v3/user/withdrawalsGet user onchain withdrawal history.
Withdraw/api/v3/user/withdrawalsSubmit offchain withdraw request
XGetTransfers/api/v3/user/transfersGet user transfer list.
XGetTradeHistory/api/v3/user/tradesGet user trade history.
XOrderFee/api/v3/user/orderFeeReturns the fee rate of users placing orders in specific markets
XOrderUserRateAmount/api/v3/user/orderUserRateAmountThis API returns 2 minimum amounts, one is based on users fee rate, the other is based on the maximum fee bips which is 0.6%. In other words, if user wants to keep fee rate, the minimum order is higher, otherwise he needs to pay more but can place less amount orders.
XOffchainFeeapi/v3/user/offchainFeeReturns the fee amount
XGetAmmPools/api/v3/amm/poolsGet AMM pool configurations
XGetAmmPoolBalance/api/v3/amm/balanceGet AMM pool balance snapshot
JoinAmmPool/api/v3/amm/joinJoin into AMM pool
ExitAmmPool/api/v3/amm/exitExit an AMM pool
XAmmTransactions/api/v3/amm/user/transactionsReturn the user's AMM join/exit transactions
XAmmTrades/api/v3/amm/tradesget AMM pool trade transactions
XGetL2BlockInfo/api/v3/block/getBlockGet L2 block info by block id
XGetPendingRequests/api/v3/block/getPendingRequestsGet pending txs to be packed into next block

LoopringAPI.TestConsole

There is a test console in the project that shows off how to use some of the parts within the API. I was also using it for testing. The console is in .net 6 so be prepared for that (VS 2022 and C# 10)

The most important thing about the test console is that you need to run it for the first time and fill in the file as instructed in the error that gets thrown. LoopringSharp needs those Api Keys in order to run.

LoopringSharp.Layer2TransferExample

This is a windows forms app that basically sends crypto from your wallet to a destination of your choosing. The code is explained in detail in the comments so I encourage you to read through it and understand how it works. Be careful if selecting the real network (not the test net) as you will end up sending your own crypto to someone by mistake (hopefully to me :D)

Secure client

The regular client has a security flaw in it, in that it stores the apiKey, l2Pk and L1Pk in memory within itself, in order to facilitate easier API calls. This is great for server-side aplications where you have full control of the machine on which the code is running, so there's no risk of someone trying to extract those keys from RAM with a RAM editor.

However, if creating a client application which runs on the users's hardware or on the web, it is recommended to use the secure client

LoopringSharp.SecureClientclient=newLoopringSharp.SecureClient("https://uat2.loopring.io/");varstorageId=awaitclient.StorageId("<YOUR API KEY HERE>","<YOUR ACCOUNT ID HERE>",1);

The secure client does not accept the apiKey, l2Pk, l1Pk as properties, but rather requires them as parameters on every method that needs them. This means that the keys are not stored in memory within the API class and it is up to the developer to decide how they want to secure this very sensitive infomation.

The regular client also makes use of the SecureClient internally, just that it stores the three keys within itself so they are not provided every single time a method is called in the API, easing development a little.

Credits to

fudgey.eth - Creator of PoseidonSharp, without which it would be impossible to actually do transfers within this api. https://github.com/fudgebucket27/PoseidonSharp

Donations

Donations

About

A C# NugetPackage wrapper around the Loopring API endpoints to greatly simplify communication

Resources

Stars

13 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages