├── .DS_Store ├── donations.png ├── LoopringAPI ├── loopringsharp.png ├── Enums │ ├── Side.cs │ ├── FillTypes.cs │ ├── WalletService.cs │ ├── TransferTypes.cs │ ├── WithdrawalTypes.cs │ ├── TradeChannel.cs │ ├── Status.cs │ ├── OrderType.cs │ ├── EthSignType.cs │ ├── LegalCurrencies.cs │ ├── OrderStatus.cs │ ├── Intervals.cs │ └── OffChainRequestType.cs ├── Models │ ├── Results │ │ ├── Account.cs │ │ ├── StorageId.cs │ │ ├── ExchangeInfo.cs │ │ ├── OffchainFee.cs │ │ ├── OrderFee.cs │ │ ├── AmmPoolTrades.cs │ │ ├── L2BlockInfo.cs │ │ ├── TradeHistory.cs │ │ ├── AmmPoolBalance.cs │ │ ├── PendingRequest.cs │ │ ├── OrderUserRateAmount.cs │ │ ├── AmmPoolConfiguration.cs │ │ ├── AmmJoinExitTransactions.cs │ │ ├── Balance.cs │ │ ├── OrderResult.cs │ │ ├── Depth.cs │ │ ├── Ticker.cs │ │ ├── OperationResult.cs │ │ └── OrderDetails.cs │ ├── Fee.cs │ ├── ApiResults │ │ ├── ApiTimestampResult.cs │ │ ├── ApiMarketsGetResult.cs │ │ ├── ApiTickersResult.cs │ │ ├── ApiCandlestickResult.cs │ │ ├── ApiTransferResult.cs │ │ ├── ApiTradesResult.cs │ │ ├── ApiOffchainFeeResult.cs │ │ ├── ApiInfoGetResult.cs │ │ ├── ApiOrdersGetResult.cs │ │ ├── ApiAmmPoolConfigurationResult.cs │ │ ├── ApiTransfersGetResult.cs │ │ ├── ApiDepositsGetResult.cs │ │ ├── ApiWithdrawlsGetResult.cs │ │ ├── ApiOrderFeeResult.cs │ │ ├── ApiAmmPoolTradesResult.cs │ │ ├── ApiTradeHistoryResult.cs │ │ ├── ApiApiKeyResult.cs │ │ ├── ApiOrderSubmitResult.cs │ │ ├── ApiAmmJoinExitTransactionsResult.cs │ │ ├── ApiOrderUserRateAmountResult.cs │ │ ├── ApiDepthResult.cs │ │ ├── ApiStorageIdResult.cs │ │ ├── ApiAmmPoolBalanceResult.cs │ │ ├── ApiAccountResult.cs │ │ ├── ApiBalance.cs │ │ ├── ApiL2BlockInfoResult.cs │ │ ├── ApiOrderGetResult.cs │ │ ├── ApiDepositTransaction.cs │ │ ├── ApiExchangeInfoResult.cs │ │ ├── ApiTransferData.cs │ │ ├── ApiWithdrawlTransaction.cs │ │ └── ApiPendingRequestsResult.cs │ ├── FeeInfo.cs │ ├── PublicKey.cs │ ├── Validity.cs │ ├── TypedDataModels │ │ ├── Type.cs │ │ ├── DualBaseModel.cs │ │ ├── TransferTypedData.cs │ │ └── AccountUpdateTypedData.cs │ ├── GasAmount.cs │ ├── Token.cs │ ├── Price.cs │ ├── OrderAmounts.cs │ ├── CounterFactualInfo.cs │ ├── AmmPoolTokens.cs │ ├── PendingRequestOrderBlockInfo.cs │ ├── TokenVolume.cs │ ├── AmmPoolPrecisions.cs │ ├── FeeRate.cs │ ├── OrderInfo.cs │ ├── Volumes.cs │ ├── AmmTransferData.cs │ ├── Market.cs │ ├── OffFeeInfo.cs │ ├── Trade.cs │ ├── TokenBlockInfo.cs │ ├── TokenAmount.cs │ ├── Candlestick.cs │ ├── AmmTradeData.cs │ ├── AmmPoolInfo.cs │ ├── OrderBlockInfo.cs │ ├── TokenConfig.cs │ ├── ApiRequests │ │ ├── ApiUpdateEDDSARequest.cs │ │ ├── ApiTransferRequest.cs │ │ └── ApiSubmitOrderRequest.cs │ ├── ApiTransaction.cs │ ├── AmmTransactionData.cs │ ├── Requests │ │ ├── DualInvestmentModel.cs │ │ ├── UpdateAccountRequest.cs │ │ └── TransferRequest.cs │ └── TransactionBlockInfo.cs ├── Helpers │ ├── PoseidonHelper.cs │ └── Constants.cs └── LoopringSharp.csproj ├── LoopringAPI.TestConsole ├── .DS_Store ├── ApiKeys.cs └── LoopringSharp.TestConsole.csproj ├── LoopringSharp.WalletConnect ├── WalletConnect │ ├── Events │ │ ├── IEvent.cs │ │ ├── IEventProvider.cs │ │ ├── Model │ │ │ ├── JsonRpcRequestEvent.cs │ │ │ ├── JsonRpcResponseEvent.cs │ │ │ └── GenericEvent.cs │ │ ├── EventFactory.cs │ │ ├── EventHandlerMap.cs │ │ ├── EventManager.cs │ │ └── EventDelegator.cs │ ├── Models │ │ ├── IEventSource.cs │ │ ├── Ethereum │ │ │ ├── EthChain.cs │ │ │ ├── Types │ │ │ │ ├── EvmIgnoreAttribute.cs │ │ │ │ ├── EvmTypeAttribute.cs │ │ │ │ ├── EvmTypeInfo.cs │ │ │ │ ├── EIP712Domain.cs │ │ │ │ └── EvmTypedData.cs │ │ │ ├── NativeCurrency.cs │ │ │ ├── EthResponse.cs │ │ │ ├── EthChainData.cs │ │ │ ├── TransactionData.cs │ │ │ ├── EthSignTypedDataV4.cs │ │ │ ├── EthSign.cs │ │ │ ├── EthGenericRequest.cs │ │ │ ├── EthPersonalSign.cs │ │ │ ├── WalletAddEthChain.cs │ │ │ ├── EthSendTransaction.cs │ │ │ ├── EthSignTransaction.cs │ │ │ └── EthSignTypedData.cs │ │ ├── WCSessionRequestResponse.cs │ │ ├── InternalEvent.cs │ │ ├── EncryptedPayload.cs │ │ ├── ErrorResponse.cs │ │ ├── WCSessionData.cs │ │ ├── NetworkMessage.cs │ │ ├── ClientMeta.cs │ │ ├── WCSessionUpdate.cs │ │ ├── Address.cs │ │ ├── JsonRpcRequest.cs │ │ ├── WcSessionRequest.cs │ │ ├── WCSessionRequestRequest.cs │ │ ├── JsonRpcResponse.cs │ │ └── SavedSession.cs │ ├── Network │ │ ├── ICipher.cs │ │ ├── MessageReceivedEventArgs.cs │ │ ├── ITransport.cs │ │ ├── TransportFactory.cs │ │ ├── DefaultBridge.cs │ │ └── AESCipher.cs │ ├── Utils │ │ ├── RpcPayloadId.cs │ │ └── Hex.cs │ ├── WalletConnectServer.cs │ └── WebsocketTransport.cs ├── LoopringSharp.WalletConnect.csproj ├── EDDSAHelper.cs ├── WalletConnectClient.cs └── WalletConnectSecretClient.cs ├── LoopringSharp.DualInvestment.AzureFunction ├── Program.cs ├── Properties │ └── launchSettings.json ├── host.json ├── LoopringSharp.DualInvestment.AzureFunction.csproj └── .gitignore ├── LoopringSharp.MetaMask ├── LoopringSharp.MetaMask.csproj ├── MetamaskApiController.cs ├── EDDSAHelper.cs ├── MetamaskClient.cs ├── Metamask.cs └── Constants.cs ├── __blobstorage__ ├── bfecf779-9cef-4949-9054-9d8e3b269f5c └── 64ef6ad9-91a6-4561-8f4b-cb67a0e0113b ├── LoopringAPI.OneButtonPayExample ├── LoopringSharp.Layer2TransferExample.csproj ├── Program.cs ├── TransferForm.resx └── TransferForm.cs ├── LoopringAPI.UnitTests ├── LoopringSharp.UnitTests.csproj └── ClientTests.cs ├── __azurite_db_queue_extent__.json ├── __azurite_db_blob_extent__.json ├── __azurite_db_table__.json ├── __azurite_db_queue__.json ├── LoopringSharp.sln ├── __azurite_db_blob__.json └── .gitignore /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taranasus/LoopringSharp/HEAD/.DS_Store -------------------------------------------------------------------------------- /donations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taranasus/LoopringSharp/HEAD/donations.png -------------------------------------------------------------------------------- /LoopringAPI/loopringsharp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taranasus/LoopringSharp/HEAD/LoopringAPI/loopringsharp.png -------------------------------------------------------------------------------- /LoopringAPI.TestConsole/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taranasus/LoopringSharp/HEAD/LoopringAPI.TestConsole/.DS_Store -------------------------------------------------------------------------------- /LoopringAPI/Enums/Side.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum Side 4 | { 5 | SELL, 6 | BUY 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/Account.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Account : ApiAccountResult 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/StorageId.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class StorageId : ApiStorageIdResult 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/ExchangeInfo.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ExchangeInfo : ApiExchangeInfoResult 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/OffchainFee.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class OffchainFee : ApiOffchainFeeResult 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /LoopringAPI/Enums/FillTypes.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum FillTypes 4 | { 5 | dex, 6 | amm 7 | } 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Enums/WalletService.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum WalletService 4 | { 5 | MetaMask, 6 | WalletConnect 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Fee.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Fee:OffFeeInfo 4 | { 5 | public double discount { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /LoopringAPI/Enums/TransferTypes.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum TransferTypes 4 | { 5 | transfer, 6 | transfer_red 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /LoopringAPI/Enums/WithdrawalTypes.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum WithdrawalTypes 4 | { 5 | force_withdrawal, 6 | offchain_withdrawal 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /LoopringAPI/Enums/TradeChannel.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum TradeChannel 4 | { 5 | ORDER_BOOK, 6 | AMM_POOL, 7 | MIXED 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiTimestampResult.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ApiTimestampResult 4 | { 5 | public long timestamp { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Events/IEvent.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Events 2 | { 3 | public interface IEvent 4 | { 5 | void SetData(T data); 6 | } 7 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/FeeInfo.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class FeeInfo 4 | { 5 | public string type { get; set; } 6 | public string fee { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /LoopringAPI/Models/PublicKey.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class PublicKey 4 | { 5 | public string x { get; set; } 6 | public string y { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Validity.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Validity 4 | { 5 | public long start { get; set; } 6 | public long end { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/IEventSource.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models 2 | { 3 | public interface IEventSource 4 | { 5 | string Event { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /LoopringAPI/Enums/Status.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum Status 4 | { 5 | received, 6 | processing, 7 | processed, 8 | failed 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/TypedDataModels/Type.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Type 4 | { 5 | public string name { get; set; } 6 | public string type { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/EthChain.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models.Ethereum 2 | { 3 | public class EthChain 4 | { 5 | public string chainId; 6 | } 7 | } -------------------------------------------------------------------------------- /LoopringAPI/Enums/OrderType.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum OrderType 4 | { 5 | AMM, 6 | LIMIT_ORDER, 7 | MAKER_ONLY, 8 | TAKER_ONLY 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/GasAmount.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class GasAmount 4 | { 5 | public string distribution { get; set; } 6 | public string deposit { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Token.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Token 4 | { 5 | public int tokenId { get; set; } 6 | public string volume { get; set; } 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /LoopringSharp.DualInvestment.AzureFunction/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Hosting; 2 | 3 | var host = new HostBuilder() 4 | .ConfigureFunctionsWorkerDefaults() 5 | .Build(); 6 | 7 | host.Run(); 8 | 9 | -------------------------------------------------------------------------------- /LoopringAPI/Enums/EthSignType.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum EthSignType 4 | { 5 | ILLEGAL = 0, 6 | INVALID = 1, 7 | EIP_712 = 2, 8 | ETH_SIGN = 3, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Enums/LegalCurrencies.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum LegalCurrencies 4 | { 5 | USD, 6 | CNY, 7 | JPY, 8 | EUR, 9 | GBP, 10 | HKD 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Events/IEventProvider.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Events 2 | { 3 | public interface IEventProvider 4 | { 5 | void PropagateEvent(string topic, string responseJson); 6 | } 7 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/OrderFee.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class OrderFee : ApiOrderFeeResult 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/WCSessionRequestResponse.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models 2 | { 3 | public class WCSessionRequestResponse : JsonRpcResponse 4 | { 5 | public WCSessionData result; 6 | } 7 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/AmmPoolTrades.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class AmmPoolTrades : ApiAmmPoolTradesResult 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/L2BlockInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class L2BlockInfo : ApiL2BlockInfoResult 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/TradeHistory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class TradeHistory : ApiTradeHistoryResult 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiMarketsGetResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiMarketsGetResult 6 | { 7 | public List markets { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiTickersResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiTickersResult 6 | { 7 | public List> tickers { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/AmmPoolBalance.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class AmmPoolBalance : ApiAmmPoolBalanceResult 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/PendingRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class PendingRequest : ApiPendingRequestsResult 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/Types/EvmIgnoreAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WalletConnectSharp.Core.Models.Ethereum.Types 4 | { 5 | public class EvmIgnoreAttribute : Attribute 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/Price.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Price 4 | { 5 | public string symbol { get; set; } 6 | public string price { get; set; } 7 | public long updatedAt { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LoopringAPI/Enums/OrderStatus.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum OrderStatus 4 | { 5 | processing, 6 | processed, 7 | cancelling, 8 | cancelled, 9 | expired, 10 | failed 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiCandlestickResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiCandlestickResult 6 | { 7 | public List> candlesticks { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/OrderUserRateAmount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class OrderUserRateAmount : ApiOrderUserRateAmountResult 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/OrderAmounts.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class OrderAmounts 4 | { 5 | public string minimum { get; set; } 6 | public string maximum { get; set; } 7 | public string dust { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/AmmPoolConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class AmmPoolConfiguration : ApiAmmPoolConfigurationResult 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/InternalEvent.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models 4 | { 5 | public class InternalEvent 6 | { 7 | [JsonProperty("event")] 8 | public string @event; 9 | } 10 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Events/Model/JsonRpcRequestEvent.cs: -------------------------------------------------------------------------------- 1 | using WalletConnectSharp.Core.Models; 2 | 3 | namespace WalletConnectSharp.Core.Events.Response 4 | { 5 | public class JsonRpcRequestEvent : GenericEvent where T : JsonRpcRequest 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/EncryptedPayload.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models 2 | { 3 | public class EncryptedPayload 4 | { 5 | public string iv; 6 | 7 | public string hmac; 8 | 9 | public string data; 10 | } 11 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/NativeCurrency.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models.Ethereum 2 | { 3 | public class NativeCurrency 4 | { 5 | public string name; 6 | public string symbol; 7 | public int decimals; 8 | } 9 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/AmmJoinExitTransactions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class AmmJoinExitTransactions : ApiAmmJoinExitTransactionsResult 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Events/Model/JsonRpcResponseEvent.cs: -------------------------------------------------------------------------------- 1 | using WalletConnectSharp.Core.Models; 2 | 3 | namespace WalletConnectSharp.Core.Events.Request 4 | { 5 | public class JsonRpcResponseEvent : GenericEvent where T : JsonRpcResponse 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiTransferResult.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ApiTransferResult 4 | { 5 | public string hash { get; set; } 6 | public string status { get; set; } 7 | public bool isIdempotent { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LoopringSharp.DualInvestment.AzureFunction/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "LoopringSharp.DualInvestment.AzureFunction": { 4 | "commandName": "Project", 5 | "commandLineArgs": "--port 7189", 6 | "launchBrowser": false 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiTradesResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiTradesResult 6 | { 7 | public long totalNum { get; set; } 8 | public List> trades { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/CounterFactualInfo.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class CounterFactualInfo 4 | { 5 | public string walletFactory { get; set; } 6 | public string walletOwner { get; set; } 7 | public string walletSalt { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LoopringAPI/Enums/Intervals.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum Intervals 4 | { 5 | min1, 6 | min5, 7 | min15, 8 | min30, 9 | hr1, 10 | hr2, 11 | hr4, 12 | hr12, 13 | d1, 14 | w1 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiOffchainFeeResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiOffchainFeeResult 6 | { 7 | public string gasPrice { get; set; } 8 | public List fees { get; set; } 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /LoopringAPI/Models/AmmPoolTokens.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class AmmPoolTokens 8 | { 9 | public List pooled { get; set; } 10 | public int lp { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiInfoGetResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiInfoGetResult 6 | { 7 | public long totalNum { get; set; } 8 | public List transactions { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiOrdersGetResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiOrdersGetResult 6 | { 7 | public long totalNum { get; set; } 8 | public List orders { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/PendingRequestOrderBlockInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class PendingRequestOrderBlockInfo : OrderBlockInfo 8 | { 9 | public int? fillS { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LoopringAPI/Models/TokenVolume.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class TokenVolume 8 | { 9 | public int tokenId { get; set; } 10 | public string volume { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LoopringAPI/Models/AmmPoolPrecisions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class AmmPoolPrecisions 8 | { 9 | public int price { get; set; } 10 | public int amount { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiAmmPoolConfigurationResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class ApiAmmPoolConfigurationResult 8 | { 9 | public List pools { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiTransfersGetResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiTransfersGetResult 6 | { 7 | public long totalNum { get; set; } 8 | public List transactions { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringSharp.DualInvestment.AzureFunction/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "logging": { 4 | "applicationInsights": { 5 | "samplingSettings": { 6 | "isEnabled": true, 7 | "excludedTypes": "Request" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiDepositsGetResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiDepositsGetResult 6 | { 7 | public long totalNum { get; set; } 8 | public List transactions { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiWithdrawlsGetResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiWithdrawlsGetResult 6 | { 7 | public long totalNum { get; set; } 8 | public List transactions { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiOrderFeeResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class ApiOrderFeeResult 8 | { 9 | public FeeRate feeRate { get; set; } 10 | public string gasPrice { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LoopringAPI/Models/FeeRate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class FeeRate 8 | { 9 | public string symbol { get; set; } 10 | public int makerRate { get; set; } 11 | public int takerRate { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiAmmPoolTradesResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class ApiAmmPoolTradesResult 8 | { 9 | public int totalNum { get; set; } 10 | public List trades { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiTradeHistoryResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class ApiTradeHistoryResult 8 | { 9 | public long totalNum { get; set; } 10 | public List> trades { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiApiKeyResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiApiKeyResult 6 | { 7 | public string apiKey { get; set; } 8 | } 9 | 10 | public class ApiPriceResult 11 | { 12 | public List prices { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiOrderSubmitResult.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ApiOrderSubmitResult 4 | { 5 | public string hash { get; set; } 6 | public string clientOrderId { get; set; } 7 | public string status { get; set; } 8 | public bool isIdempotent { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LoopringAPI/Models/OrderInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class OrderInfo 8 | { 9 | public string minAmount { get; set; } 10 | public long makerRate { get; set; } 11 | public long takerRate { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Volumes.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Volumes 4 | { 5 | public string baseAmount { get; set; } 6 | public string quoteAmount { get; set; } 7 | public string baseFilled { get; set; } 8 | public string quoteFilled { get; set; } 9 | public string fee { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/EthResponse.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models.Ethereum 4 | { 5 | public class EthResponse : JsonRpcResponse 6 | { 7 | [JsonProperty] 8 | private string result; 9 | 10 | [JsonIgnore] 11 | public string Result => result; 12 | } 13 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiAmmJoinExitTransactionsResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class ApiAmmJoinExitTransactionsResult 8 | { 9 | public int totalNum { get; set; } 10 | public List transactions { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/ErrorResponse.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models 2 | { 3 | public class ErrorResponse 4 | { 5 | //keep for json deserialization 6 | private string message; 7 | 8 | public ErrorResponse(string message) => this.message = message; 9 | 10 | public string Message => message; 11 | } 12 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/WCSessionData.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models 2 | { 3 | public class WCSessionData 4 | { 5 | public string peerId; 6 | public ClientMeta peerMeta; 7 | public bool approved; 8 | public int chainId; 9 | public int networkId; 10 | public string[] accounts; 11 | } 12 | } -------------------------------------------------------------------------------- /LoopringSharp.MetaMask/LoopringSharp.MetaMask.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /__blobstorage__/bfecf779-9cef-4949-9054-9d8e3b269f5c: -------------------------------------------------------------------------------- 1 | {"Last":"0001-01-01T00:00:00","Next":"2024-01-01T00:00:00+00:00","LastUpdated":"2023-05-05T21:36:23.668875+01:00"}{"Last":"2023-05-05T21:37:54.29563+01:00","Next":"2024-01-01T00:00:00+00:00","LastUpdated":"2023-05-05T21:37:54.29563+01:00"}{"Last":"2023-05-05T21:40:58.926964+01:00","Next":"2024-01-01T00:00:00+00:00","LastUpdated":"2023-05-05T21:40:58.926964+01:00"} -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/EthChainData.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models.Ethereum 2 | { 3 | public class EthChainData : EthChain 4 | { 5 | public string[] blockExplorerUrls; 6 | public string chainName; 7 | public string[] iconUrls; 8 | public NativeCurrency nativeCurrency; 9 | public string[] rpcUrls; 10 | } 11 | } -------------------------------------------------------------------------------- /LoopringAPI/Enums/OffChainRequestType.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public enum OffChainRequestType 4 | { 5 | Order = 0, 6 | OffchainWithdrawl = 1, 7 | UpdateAccount = 2, 8 | Transfer = 3, 9 | FastOffchainWithdrawl = 4, 10 | OpenAccount = 5, 11 | AMMExit = 6, 12 | Deposit = 7, 13 | AMMJoin = 8 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /LoopringAPI/Models/AmmTransferData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class AmmTransferData 8 | { 9 | public int tokenId { get; set; } 10 | public string amount { get; set; } 11 | public string actualAmount { get; set; } 12 | public string feeAmount { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiOrderUserRateAmountResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class ApiOrderUserRateAmountResult 8 | { 9 | public string gasPrice { get; set; } 10 | public List amounts {get;set;} 11 | public long cacheOverdueAt { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Market.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Market 4 | { 5 | public string market { get; set; } 6 | public int baseTokenId { get; set; } 7 | public int quoteTokenId { get; set; } 8 | public int precisionForPrice { get; set; } 9 | public int orderbookAggLevels { get; set; } 10 | public bool enabled { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LoopringAPI/Models/OffFeeInfo.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class OffFeeInfo 4 | { 5 | public string token { get; set; } 6 | public string fee { get; set; } 7 | public decimal normalziedFee 8 | { 9 | get 10 | { 11 | return decimal.Parse(fee) / 1000000000000000000m; 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/Types/EvmTypeAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WalletConnectSharp.Core.Models.Ethereum.Types 4 | { 5 | public class EvmTypeAttribute : Attribute 6 | { 7 | public string TypeName { get; } 8 | 9 | public EvmTypeAttribute(string typename) 10 | { 11 | TypeName = typename; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /__blobstorage__/64ef6ad9-91a6-4561-8f4b-cb67a0e0113b: -------------------------------------------------------------------------------- 1 | {"Last":"2023-05-06T06:30:26.706672+01:00","Next":"2024-01-01T00:00:00+00:00","LastUpdated":"2023-05-06T06:30:26.706672+01:00"}{"Last":"2023-05-06T06:43:07.045272+01:00","Next":"2024-01-01T00:00:00+00:00","LastUpdated":"2023-05-06T06:43:07.045272+01:00"}{"Last":"2023-05-06T07:01:57.441278+01:00","Next":"2024-01-01T00:00:00+00:00","LastUpdated":"2023-05-06T07:01:57.441278+01:00"} -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/Types/EvmTypeInfo.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models.Ethereum.Types 2 | { 3 | public class EvmTypeInfo 4 | { 5 | public string name; 6 | public string type; 7 | 8 | public EvmTypeInfo(string name, string type) 9 | { 10 | this.name = name; 11 | this.type = type; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiDepthResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiDepthResult 6 | { 7 | public long version { get; set; } 8 | public long timestamp { get; set; } 9 | public string market { get; set; } 10 | public List> bids { get; set; } 11 | public List> asks { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Trade.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Trade 4 | { 5 | public long TradeTimestamp { get; set; } 6 | public long RecordId { get; set; } 7 | public Side Side { get; set; } 8 | public decimal Volume { get; set; } 9 | public decimal Price { get; set; } 10 | public string Market { get; set; } 11 | public float Fees { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/TransactionData.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models.Ethereum 2 | { 3 | public class TransactionData 4 | { 5 | public string from; 6 | public string to; 7 | public string data; 8 | public string gas; 9 | public string gasPrice; 10 | public string value; 11 | public string nonce; 12 | public int chainId; 13 | } 14 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/TokenBlockInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class TokenBlockInfo 8 | { 9 | public int? tokenId { get; set; } 10 | public string tokenAddress { get; set; } 11 | public string nftData { get; set; } 12 | 13 | public string nftId { get; set; } 14 | public string amount { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/LoopringSharp.WalletConnect.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiStorageIdResult.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ApiStorageIdResult 4 | { 5 | public int orderId { get; set; } 6 | public int offchainId { get; set; } 7 | public Side side { get; set; } 8 | public decimal Volume { get; set; } 9 | public decimal Price { get; set; } 10 | public string Market { get; set; } 11 | public decimal Fee { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LoopringAPI/Models/TokenAmount.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class TokenAmount 8 | { 9 | public string tokenSymbol { get; set; } 10 | public decimal discount { get; set; } 11 | public OrderInfo baseOrderInfo { get; set; } 12 | public OrderInfo userOrderInfo { get; set; } 13 | public OrderAmounts marketOrderInfo { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Network/ICipher.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using System.Threading.Tasks; 3 | using WalletConnectSharp.Core.Models; 4 | 5 | namespace WalletConnectSharp.Core.Network 6 | { 7 | public interface ICipher 8 | { 9 | Task EncryptWithKey(byte[] key, string data, Encoding encoding = null); 10 | 11 | Task DecryptWithKey(byte[] key, EncryptedPayload encryptedData, Encoding encoding = null); 12 | } 13 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiAmmPoolBalanceResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class ApiAmmPoolBalanceResult 8 | { 9 | public string poolName { get; set; } 10 | public string poolAddress { get; set; } 11 | 12 | public List pooled { get; set; } 13 | public TokenVolume lp { get; set; } 14 | public bool risky { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/NetworkMessage.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models 4 | { 5 | public class NetworkMessage 6 | { 7 | [JsonProperty("topic")] 8 | public string Topic; 9 | 10 | [JsonProperty("type")] 11 | public string Type; 12 | 13 | [JsonProperty("payload")] 14 | public string Payload; 15 | 16 | [JsonProperty("silent")] 17 | public bool Silent; 18 | } 19 | } -------------------------------------------------------------------------------- /LoopringAPI/Helpers/PoseidonHelper.cs: -------------------------------------------------------------------------------- 1 | using PoseidonSharp; 2 | using System.Numerics; 3 | 4 | namespace LoopringSharp 5 | { 6 | public static class PoseidonHelper 7 | { 8 | public static BigInteger GetPoseidonHash(BigInteger[] inputs) 9 | { 10 | var poseidonHasher = new Poseidon(inputs.Length + 1, 6, 53, "poseidon", 5, _securityTarget: 128); 11 | return poseidonHasher.CalculatePoseidonHash(inputs); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/Balance.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Balance 4 | { 5 | public string token { get; set; } 6 | public decimal total { get; set; } 7 | public decimal locked { get; set; } 8 | public BalancePending pending { get; set; } 9 | public class BalancePending 10 | { 11 | public decimal widthdraw { get; set; } 12 | public decimal deposit { get; set; } 13 | } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /LoopringAPI.TestConsole/ApiKeys.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LoopringSharp.TestConsole 8 | { 9 | public class ApiKeys 10 | { 11 | public string l1Pk { get; set; } 12 | public string l2Pk { get; set; } 13 | public string accountId { get; set; } 14 | public string ethAddress { get; set; } 15 | public string apiUrl { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiAccountResult.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ApiAccountResult 4 | { 5 | public int accountId { get; set; } 6 | public string owner { get; set; } 7 | public bool frozen { get; set; } 8 | public PublicKey publicKey { get; set; } 9 | public string tags { get; set; } 10 | public int nonce { get; set; } 11 | public string keyNonce { get; set; } 12 | public string keySeed { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Candlestick.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Candlestick 4 | { 5 | public string startTime { get; set; } 6 | public long numberOfTransactions { get; set; } 7 | public decimal open { get; set; } 8 | public decimal close { get; set; } 9 | public decimal high { get; set; } 10 | public decimal low { get; set; } 11 | public decimal baseTokenVolume { get; set; } 12 | public decimal quoteTokenVolume { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/ClientMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace WalletConnectSharp.Core.Models 5 | { 6 | [Serializable] 7 | public class ClientMeta 8 | { 9 | [JsonProperty("description")] 10 | public string Description; 11 | 12 | [JsonProperty("url")] 13 | public string URL; 14 | 15 | [JsonProperty("icons")] 16 | public string[] Icons; 17 | 18 | [JsonProperty("name")] 19 | public string Name; 20 | } 21 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Events/Model/GenericEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WalletConnectSharp.Core.Events 4 | { 5 | public class GenericEvent : IEvent 6 | { 7 | public T Response { get; private set; } 8 | 9 | public void SetData(T response) 10 | { 11 | if (Response != null) 12 | { 13 | throw new ArgumentException("Response was already set"); 14 | } 15 | 16 | Response = response; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/EthSignTypedDataV4.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models.Ethereum 4 | { 5 | public sealed class EthSignTypedDataV4 : JsonRpcRequest 6 | { 7 | [JsonProperty("params")] 8 | private string[] _parameters; 9 | 10 | public EthSignTypedDataV4(string address, string data) 11 | { 12 | this.Method = "eth_signTypedData_v4"; 13 | this._parameters = new string[] { address, data }; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiBalance.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ApiBalance 4 | { 5 | public int accountId { get; set; } 6 | public int tokenId { get; set; } 7 | public string total { get; set; } 8 | public string locked { get; set; } 9 | public ApiBalancePending pending { get; set; } 10 | public class ApiBalancePending 11 | { 12 | public string withdraw { get; set; } 13 | public string deposit { get; set; } 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/WCSessionUpdate.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models 4 | { 5 | public class WCSessionUpdate : JsonRpcRequest 6 | { 7 | public override string Method 8 | { 9 | get { return "wc_sessionUpdate"; } 10 | } 11 | 12 | [JsonProperty("params")] 13 | public WCSessionData[] parameters; 14 | 15 | public WCSessionUpdate(WCSessionData data) 16 | { 17 | this.parameters = new[] {data}; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/AmmTradeData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class AmmTradeData 8 | { 9 | public int accountId { get; set; } 10 | public string orderHash { get; set; } 11 | public string market { get; set; } 12 | public string side { get; set; } 13 | public string size { get; set; } 14 | public decimal price { get; set; } 15 | public string feeAmount { get; set; } 16 | public long createdAt { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Network/MessageReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using WalletConnectSharp.Core.Models; 3 | 4 | namespace WalletConnectSharp.Core.Network 5 | { 6 | public class MessageReceivedEventArgs : EventArgs 7 | { 8 | public NetworkMessage Message { get; private set; } 9 | 10 | public ITransport Source { get; private set; } 11 | 12 | public MessageReceivedEventArgs(NetworkMessage message, ITransport source) 13 | { 14 | Message = message; 15 | Source = source; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/EthSign.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models.Ethereum 4 | { 5 | public sealed class EthSign : JsonRpcRequest 6 | { 7 | [JsonProperty("params")] 8 | private string[] _parameters; 9 | 10 | [JsonIgnore] 11 | public string[] Parameters => _parameters; 12 | 13 | public EthSign(string hexData, string address) : base() 14 | { 15 | this.Method = "eth_sign"; 16 | this._parameters = new[] {address, hexData}; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Address.cs: -------------------------------------------------------------------------------- 1 | namespace WalletConnectSharp.Core.Models 2 | { 3 | public class Address 4 | { 5 | public string _address; 6 | 7 | public Address(string address) 8 | { 9 | this._address = address; 10 | } 11 | 12 | public static implicit operator string(Address address) => address._address; 13 | public static explicit operator Address(string address) => new Address(address); 14 | 15 | public override string ToString() 16 | { 17 | return _address; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/EthGenericRequest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models.Ethereum 4 | { 5 | public sealed class EthGenericRequest : JsonRpcRequest 6 | { 7 | [JsonProperty("params")] 8 | private T[] _parameters; 9 | 10 | [JsonIgnore] 11 | public T[] Parameters => _parameters; 12 | 13 | public EthGenericRequest(string jsonRpcMethodName, params T[] data) : base() 14 | { 15 | this.Method = jsonRpcMethodName; 16 | this._parameters = data; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /LoopringAPI.OneButtonPayExample/LoopringSharp.Layer2TransferExample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WinExe 5 | net6.0-windows 6 | enable 7 | true 8 | enable 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /LoopringAPI.OneButtonPayExample/Program.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp.OneButtonPayExample 2 | { 3 | internal static class Program 4 | { 5 | /// 6 | /// The main entry point for the application. 7 | /// 8 | [STAThread] 9 | static void Main() 10 | { 11 | // To customize application configuration such as set high DPI settings or default font, 12 | // see https://aka.ms/applicationconfiguration. 13 | ApplicationConfiguration.Initialize(); 14 | Application.Run(new TransferForm()); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiL2BlockInfoResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Numerics; 4 | using System.Text; 5 | 6 | namespace LoopringSharp 7 | { 8 | public class ApiL2BlockInfoResult 9 | { 10 | public int blockId { get; set; } 11 | public int blockSize { get; set; } 12 | public string exchange { get; set; } 13 | public string txHash { get; set; } 14 | public string status { get; set; } 15 | public BigInteger createdAt { get; set; } 16 | public List transactions { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/EthPersonalSign.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models.Ethereum 4 | { 5 | public sealed class EthPersonalSign : JsonRpcRequest 6 | { 7 | [JsonProperty("params")] 8 | private string[] _parameters; 9 | 10 | [JsonIgnore] 11 | public string[] Parameters => _parameters; 12 | 13 | public EthPersonalSign(string hexData, string address) : base() 14 | { 15 | this.Method = "personal_sign"; 16 | this._parameters = new[] {address, hexData}; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiOrderGetResult.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ApiOrderGetResult 4 | { 5 | public string hash { get; set; } 6 | public string clientOrderId { get; set; } 7 | public string side { get; set; } 8 | public string market { get; set; } 9 | public string price { get; set; } 10 | public Volumes volumes { get; set; } 11 | public Validity validity { get; set; } 12 | public string orderType { get; set; } 13 | public string tradeChannel { get; set; } 14 | public string status { get; set; } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/WalletAddEthChain.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models.Ethereum 4 | { 5 | public class WalletAddEthChain : JsonRpcRequest 6 | { 7 | [JsonProperty("params")] 8 | private EthChainData[] _parameters; 9 | 10 | [JsonIgnore] 11 | public EthChainData[] Parameters => _parameters; 12 | 13 | public WalletAddEthChain(EthChainData chainData) : base() 14 | { 15 | this.Method = "wallet_addEthereumChain"; 16 | this._parameters = new[] { chainData }; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/AmmPoolInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class AmmPoolInfo 8 | { 9 | public string name { get; set; } 10 | public string market { get; set; } 11 | public string address { get; set; } 12 | public string version { get; set; } 13 | public AmmPoolTokens tokens { get; set; } 14 | public int feeBips { get; set; } 15 | public AmmPoolPrecisions precisions { get; set; } 16 | public string createdAt { get; set; } 17 | public int status { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /LoopringAPI.TestConsole/LoopringSharp.TestConsole.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | preview 9 | 10 | 11 | 12 | 13 | PreserveNewest 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/EthSendTransaction.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models.Ethereum 4 | { 5 | public sealed class EthSendTransaction : JsonRpcRequest 6 | { 7 | [JsonProperty("params")] 8 | private TransactionData[] _parameters; 9 | 10 | [JsonIgnore] 11 | public TransactionData[] Parameters => _parameters; 12 | 13 | public EthSendTransaction(params TransactionData[] transactionDatas) : base() 14 | { 15 | this.Method = "eth_sendTransaction"; 16 | this._parameters = transactionDatas; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/EthSignTransaction.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models.Ethereum 4 | { 5 | public sealed class EthSignTransaction : JsonRpcRequest 6 | { 7 | [JsonProperty("params")] 8 | private TransactionData[] _parameters; 9 | 10 | [JsonIgnore] 11 | public TransactionData[] Parameters => _parameters; 12 | 13 | public EthSignTransaction(params TransactionData[] transactionDatas) : base() 14 | { 15 | this.Method = "eth_signTransaction"; 16 | this._parameters = transactionDatas; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/OrderResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class OrderResult 6 | { 7 | public OrderResult(ApiOrderSubmitResult aosr) 8 | { 9 | hash = aosr.hash; 10 | clientOrderId = aosr.clientOrderId; 11 | status = (OrderStatus)Enum.Parse(typeof(OrderStatus), aosr.status, true); 12 | isIdempotent = aosr.isIdempotent; 13 | } 14 | 15 | public string hash { get; set; } 16 | public string clientOrderId { get; set; } 17 | public OrderStatus status { get; set; } 18 | public bool isIdempotent { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Utils/RpcPayloadId.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WalletConnectSharp.Core.Utils 4 | { 5 | public class RpcPayloadId 6 | { 7 | private static readonly Random rng = new Random(); 8 | private static readonly DateTime UnixEpoch = 9 | new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 10 | 11 | public static long Generate() 12 | { 13 | var date = (long)((DateTime.UtcNow - UnixEpoch).TotalMilliseconds) * (10L * 10L * 10L); 14 | var extra = (long)Math.Floor(rng.NextDouble() * (10.0 * 10.0 * 10.0)); 15 | return date + extra; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/Depth.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class Depth 6 | { 7 | public long version { get; set; } 8 | public long timestamp { get; set; } 9 | public string market { get; set; } 10 | public List bids { get; set; } 11 | public List asks { get; set; } 12 | 13 | public class Position 14 | { 15 | public float price { get; set; } 16 | public decimal size { get; set; } 17 | public decimal volume { get; set; } 18 | public decimal numberOfOrdersAgregated { get; set; } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LoopringAPI/Models/TypedDataModels/DualBaseModel.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class DualBaseModel 4 | { 5 | public string ProductId { get; set; } 6 | public string Base { get; set; } 7 | public string Quote { get; set; } 8 | public string Currency { get; set; } 9 | public long CreateTime { get; set; } 10 | public long ExpireTime { get; set; } 11 | public string Strike { get; set; } 12 | public bool Expired { get; set; } 13 | public string DualType { get; set; } 14 | public double Ratio { get; set; } 15 | public string Profit { get; set; } 16 | public string BaseSize { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LoopringAPI.UnitTests/LoopringSharp.UnitTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiDepositTransaction.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiDepositTransaction 6 | { 7 | public long id { get; set; } 8 | public string hash { get; set; } 9 | public string symbol { get; set; } 10 | public BigInteger amount { get; set; } 11 | public string txHash { get; set; } 12 | public string status { get; set; } 13 | public string progress { get; set; } 14 | public long timestamp { get; set; } 15 | public long blockNum { get; set; } 16 | public long updatedAt { get; set; } 17 | public long blockId { get; set; } 18 | public long indexInBlock { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /LoopringAPI/Models/OrderBlockInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class OrderBlockInfo 8 | { 9 | public int? storageID { get; set; } 10 | public int? accountID { get; set; } 11 | public string amountS { get; set; } 12 | public string amountB { get; set; } 13 | public int? tokenS { get; set; } 14 | public int? tokenB { get; set; } 15 | public int? validUntil { get; set; } 16 | public string taker { get; set; } 17 | public int? feeBips { get; set; } 18 | 19 | public bool? isAmm { get; set; } 20 | public string nftData { get; set; } 21 | public int? fills { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LoopringAPI/Models/TokenConfig.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class TokenConfig 4 | { 5 | public string type { get; set; } 6 | public int tokenId { get; set; } 7 | public string symbol { get; set; } 8 | public string name { get; set; } 9 | public string address { get; set; } 10 | public int decimals { get; set; } 11 | public int precision { get; set; } 12 | public int precisionForOrder { get; set; } 13 | public OrderAmounts orderAmounts { get; set; } 14 | public OrderAmounts luckyTokenAmounts { get; set; } 15 | public string fastWithdrawLimit { get; set; } 16 | public GasAmount gasAmmounts { get; set; } 17 | public bool enabled { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiRequests/ApiUpdateEDDSARequest.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ApiUpdateEDDSARequest 4 | { 5 | public string exchange { get; set; } 6 | public string owner { get; set; } //eth public key 7 | public long accountId { get; set; } 8 | public PublicKey publicKey { get; set; } 9 | public Token maxFee { get; set; } 10 | public long validUntil { get; set; } 11 | public long nonce { get; set; } 12 | public string keySeed { get; set; } 13 | public CounterFactualInfo counterFactualInfo { get; set; } 14 | public string eddsaSignature { get; set; } 15 | public string ecdsaSignature { get; set; } 16 | public string hashApproved { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiTransaction.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiTransaction 6 | { 7 | public long id { get; set; } 8 | public string hash { get; set; } 9 | public string owner { get; set; } 10 | public string txHash { get; set; } 11 | public string feeTokenSymbol { get; set; } 12 | public string feeAmount { get; set; } 13 | public string status { get; set; } 14 | public string progress { get; set; } 15 | public long timestamp { get; set; } 16 | public long blockNum { get; set; } 17 | public long updatedAt { get; set; } 18 | public long blockId { get; set; } 19 | public long indexInBlock { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LoopringAPI/Models/AmmTransactionData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LoopringSharp 6 | { 7 | public class AmmTransactionData 8 | { 9 | public string hash { get; set; } 10 | public string txType { get; set; } 11 | public string txStatus { get; set; } 12 | public string ammPoolAddress { get; set; } 13 | public string ammLayerType { get; set; } 14 | public List poolTokens { get; set; } 15 | public AmmTransferData lpToken { get; set; } 16 | public long createdAt { get; set; } 17 | public long updatedAt { get; set; } 18 | public int blockId { get; set; } 19 | public int indexInBlock { get; set; } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiExchangeInfoResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiExchangeInfoResult 6 | { 7 | public int chainId { get; set; } 8 | public string exchangeAddress { get; set; } 9 | public string depositAddress { get; set; } 10 | public List onchainFees { get; set; } 11 | public List openAccountFees { get; set; } 12 | public List updateFees { get; set; } 13 | public List transferFees { get; set; } 14 | public List withdrawalFees { get; set; } 15 | public List fastWithdrawalFees { get; set; } 16 | public List ammExitFees { get; set; } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/Types/EIP712Domain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using WalletConnectSharp.Core.Models.Ethereum.Types; 3 | 4 | namespace WalletConnectSharp.Core.Models 5 | { 6 | public class EIP712Domain 7 | { 8 | public string name; 9 | public string version; 10 | 11 | [EvmIgnore] 12 | public int chainId; 13 | 14 | [EvmType("address")] 15 | public string verifyingContract; 16 | 17 | public EIP712Domain(string name, string version, int chainId, string verifyingContract) 18 | { 19 | this.name = name; 20 | this.version = version; 21 | this.chainId = chainId; 22 | this.verifyingContract = verifyingContract; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/Ticker.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class Ticker 4 | { 5 | public string PairId { get; set; } 6 | public string TimeStamp { get; set; } 7 | public string BaseTokenVolume { get; set; } 8 | public string QuoteTokenVolume { get; set; } 9 | public string OpenPrice { get; set; } 10 | public string HeighestPrice { get; set; } 11 | public string LowestPrice { get; set; } 12 | public string ClosingPrice { get; set; } 13 | public string NumberOfTrades { get; set; } 14 | public float HighestBidPrice { get; set; } 15 | public float LowestAskPrice { get; set; } 16 | public string BaseFeeAmmount { get; set; } 17 | public string QuoteFeeAmount { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/EthSignTypedData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using Newtonsoft.Json; 5 | using WalletConnectSharp.Core.Models.Ethereum.Types; 6 | 7 | namespace WalletConnectSharp.Core.Models.Ethereum 8 | { 9 | public sealed class EthSignTypedData : JsonRpcRequest 10 | { 11 | [JsonProperty("params")] 12 | private string[] _parameters; 13 | 14 | public EthSignTypedData(string address, T data, EIP712Domain domain) 15 | { 16 | this.Method = "eth_signTypedData"; 17 | 18 | var typeData = new EvmTypedData(data, domain); 19 | var encodedTypeData = JsonConvert.SerializeObject(typeData); 20 | 21 | this._parameters = new string[] { address, encodedTypeData }; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/Requests/DualInvestmentModel.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class DualInvestmentModel 4 | { 5 | public int accountId { get; set; } 6 | public string baseProfit { get; set; } 7 | public Token buyToken { get; set; } 8 | public string clientOrderId { get; set; } 9 | public string eddsaSignature { get; set; } 10 | public string exchange { get; set; } 11 | public long expireTime { get; set; } 12 | public string fee { get; set; } 13 | public bool fillAmountBOrS { get; set; } 14 | public int maxFeeBips { get; set; } 15 | public string productId { get; set; } 16 | public Token sellToken { get; set; } 17 | public string settleRatio { get; set; } 18 | public int storageId { get; set; } 19 | public long validUntil { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/OperationResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class OperationResult 6 | { 7 | public OperationResult(ApiTransferResult apiTransfer) 8 | { 9 | hash = apiTransfer.hash; 10 | isIdempotent = apiTransfer.isIdempotent; 11 | status = (Status)Enum.Parse(typeof(Status), apiTransfer.status, true); 12 | } 13 | 14 | public ApiTransferResult ToApiTransferResult() 15 | { 16 | return new ApiTransferResult() 17 | { 18 | hash = hash, 19 | isIdempotent = isIdempotent, 20 | status = status.ToString() 21 | }; 22 | } 23 | 24 | public string hash { get; set; } 25 | public Status status { get; set; } 26 | public bool isIdempotent { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Network/ITransport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using WalletConnectSharp.Core.Events.Request; 4 | using WalletConnectSharp.Core.Events.Response; 5 | using WalletConnectSharp.Core.Models; 6 | 7 | namespace WalletConnectSharp.Core.Network 8 | { 9 | public interface ITransport : IDisposable 10 | { 11 | bool Connected { get; } 12 | 13 | event EventHandler MessageReceived; 14 | 15 | Task Open(string bridgeURL); 16 | 17 | Task Close(); 18 | 19 | Task SendMessage(NetworkMessage message); 20 | 21 | Task Subscribe(string topic); 22 | 23 | Task Subscribe(string topic, EventHandler> callback) where T : JsonRpcResponse; 24 | 25 | Task Subscribe(string topic, EventHandler> callback) where T : JsonRpcRequest; 26 | } 27 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiTransferData.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiTransferData 6 | { 7 | public long id { get; set; } 8 | public string hash { get; set; } 9 | public string txType { get; set; } 10 | public string symbol { get; set; } 11 | public BigInteger amount { get; set; } 12 | public string senderAddress { get; set; } 13 | public int receiver { get; set; } 14 | public string receiverAddress { get; set; } 15 | public string feeTokenSymbol { get; set; } 16 | public BigInteger feeAmount { get; set; } 17 | public string status { get; set; } 18 | public string progress { get; set; } 19 | public long timestamp { get; set; } 20 | public long updatedAt { get; set; } 21 | public string memo { get; set; } 22 | public long blockId { get; set; } 23 | public long indexInBlock { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiWithdrawlTransaction.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class ApiWithdrawlTransaction 6 | { 7 | public long id { get; set; } 8 | public string txType { get; set; } 9 | public string hash { get; set; } 10 | public string symbol { get; set; } 11 | public BigInteger amount { get; set; } 12 | public string txHash { get; set; } 13 | public string feeTokenSymbol { get; set; } 14 | public BigInteger feeAmount { get; set; } 15 | public string status { get; set; } 16 | public string progress { get; set; } 17 | public long timestamp { get; set; } 18 | public long blockNum { get; set; } 19 | public long updatedAt { get; set; } 20 | public string distributedHash { get;set; } 21 | public int requestId { get; set; } 22 | public string fastStatus { get; set; } 23 | public long blockId { get; set; } 24 | public long indexInBlock { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/JsonRpcRequest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using WalletConnectSharp.Core.Utils; 3 | 4 | namespace WalletConnectSharp.Core.Models 5 | { 6 | public class JsonRpcRequest : IEventSource 7 | { 8 | [JsonProperty] 9 | private long id; 10 | [JsonProperty] 11 | private string jsonrpc = "2.0"; 12 | 13 | [JsonProperty("method")] 14 | public virtual string Method { get; protected set; } 15 | 16 | public JsonRpcRequest() 17 | { 18 | if (this.id == 0) 19 | { 20 | this.id = RpcPayloadId.Generate(); 21 | } 22 | } 23 | 24 | [JsonIgnore] 25 | public long ID 26 | { 27 | get { return id; } 28 | } 29 | 30 | [JsonIgnore] 31 | public string JsonRPC 32 | { 33 | get { return jsonrpc; } 34 | } 35 | 36 | [JsonIgnore] 37 | public string Event 38 | { 39 | get { return Method; } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/WcSessionRequest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models 4 | { 5 | public class WcSessionRequest : JsonRpcRequest 6 | { 7 | public override string Method 8 | { 9 | get { return "wc_sessionRequest"; } 10 | } 11 | 12 | [JsonProperty("params")] 13 | public WcSessionRequestRequestParams[] parameters; 14 | 15 | public WcSessionRequest(ClientMeta clientMeta, string clientId, int chainId = 1) 16 | { 17 | this.parameters = new[] 18 | { 19 | new WcSessionRequestRequestParams() 20 | { 21 | peerId = clientId, 22 | chainId = chainId, 23 | peerMeta = clientMeta 24 | } 25 | }; 26 | } 27 | 28 | public class WcSessionRequestRequestParams 29 | { 30 | public string peerId; 31 | public ClientMeta peerMeta; 32 | public int chainId; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/WCSessionRequestRequest.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models 4 | { 5 | public class WcSessionRequestRequest : JsonRpcRequest 6 | { 7 | public override string Method 8 | { 9 | get { return "wc_sessionRequest"; } 10 | } 11 | 12 | [JsonProperty("params")] 13 | public WcSessionRequestRequestParams[] parameters; 14 | 15 | public WcSessionRequestRequest(ClientMeta clientMeta, string clientId, int chainId = 1) 16 | { 17 | this.parameters = new[] 18 | { 19 | new WcSessionRequestRequestParams() 20 | { 21 | peerId = clientId, 22 | chainId = chainId, 23 | peerMeta = clientMeta 24 | } 25 | }; 26 | } 27 | 28 | public class WcSessionRequestRequestParams 29 | { 30 | public string peerId; 31 | public ClientMeta peerMeta; 32 | public int chainId; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiRequests/ApiTransferRequest.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ApiTransferRequest 4 | { 5 | // ESSENTIAL TRANSFER INFO 6 | public string exchange { get; set; } 7 | public int payerId { get; set; } 8 | public string payerAddr { get; set; } 9 | public int payeeId { get; set; } = 0; // Default of 0 if unknown is fine 10 | public string payeeAddr { get; set; } 11 | public Token token { get; set; } 12 | public Token maxFee { get; set; } 13 | public int storageId { get; set; } 14 | public int validUntil { get; set; } 15 | 16 | // ESSENTIAL AUTHENTICATION AND VALIDATION INFO 17 | public string ecdsaSignature { get; set; } 18 | public string eddsaSignature { get; set; } 19 | 20 | // OPTIONAL TRANSFER INFO 21 | public string memo { get; set; } 22 | public string clientId { get; set; } 23 | public string hashApproved { get; set; } // ????? 24 | 25 | // FOR FUTURE USE PROBABLY 26 | public CounterFactualInfo counterFactualInfo { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LoopringSharp.MetaMask/MetamaskApiController.cs: -------------------------------------------------------------------------------- 1 | using EmbedIO; 2 | using EmbedIO.Routing; 3 | using EmbedIO.WebApi; 4 | using System.Threading.Tasks; 5 | 6 | namespace LoopringSharp.MetaMask 7 | { 8 | public sealed class MetamaskApiController : WebApiController 9 | { 10 | [Route(HttpVerbs.Get, "/sign/{id?}")] 11 | public async Task GetSign(string id) 12 | => (await Sign(id).ConfigureAwait(false)) 13 | ?? throw HttpException.NotFound(); 14 | 15 | public async Task Sign(string id) 16 | { 17 | MetamaskServer.eddsa = id; 18 | return id; 19 | } 20 | 21 | [Route(HttpVerbs.Get, "/signatureaddress/{id?}")] 22 | public async Task GetSignatureAddress(string id) 23 | => (await SignatureAddress(id).ConfigureAwait(false)) 24 | ?? throw HttpException.NotFound(); 25 | 26 | public async Task SignatureAddress(string address) 27 | { 28 | MetamaskServer.eddsa = address.Split('|')[0]; 29 | MetamaskServer.ethAddress = address.Split('|')[1]; 30 | return address; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/EDDSAHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace LoopringSharp.WalletConnect 4 | { 5 | public static partial class EDDSAHelper 6 | { 7 | public static (string secretKey, string ethAddress, string publicKeyX, string publicKeyY) GetL2PKFromWalletConnect(string exchangeAddress, int nonce) 8 | { 9 | var sign = EDDSASignWalletConnect(exchangeAddress, nonce); 10 | // We're only interested in the secret key for signing packages. Which ironically is the simplest one to get... 11 | return (sign.secretKey, sign.ethAddress, sign.publicKeyX, sign.publicKeyY); 12 | } 13 | 14 | public static (string publicKeyX, string publicKeyY, string secretKey, string ethAddress) EDDSASignWalletConnect(string exchangeAddress, int nextNonce, bool skipPublicKeyCalculation = false) 15 | { 16 | // Requesting metamask to sign our package so we can tare it apart and get our public and secret keys 17 | var rawKey = WalletConnectServer.L2Authenticate(exchangeAddress, nextNonce); 18 | return LoopringSharp.EDDSAHelper.RipKeyAppart(rawKey, skipPublicKeyCalculation); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Requests/UpdateAccountRequest.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class UpdateAccountRequest 4 | { 5 | public string exchange { get; set; } 6 | public string owner { get; set; } //eth public key 7 | public long accountId { get; set; } 8 | public Token maxFee { get; set; } 9 | public long validUntil { get; set; } 10 | public long nonce { get; set; } 11 | public string PublicKeyX { get; set; } 12 | public string PublicKeyY { get; set; } 13 | 14 | public ApiUpdateEDDSARequest GetUpdateEDDSARequest(CounterFactualInfo counterFactualInfo) 15 | { 16 | return new ApiUpdateEDDSARequest() 17 | { 18 | exchange = exchange, 19 | owner = owner, 20 | accountId = accountId, 21 | maxFee = maxFee, 22 | validUntil = validUntil, 23 | nonce = nonce, 24 | counterFactualInfo = counterFactualInfo, 25 | publicKey = new PublicKey() 26 | { 27 | x = PublicKeyX, 28 | y = PublicKeyY, 29 | } 30 | }; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Events/EventFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace WalletConnectSharp.Core.Events 5 | { 6 | public class EventFactory 7 | { 8 | private static EventFactory _instance; 9 | 10 | private Dictionary _eventProviders = new Dictionary(); 11 | 12 | public static EventFactory Instance 13 | { 14 | get 15 | { 16 | if (_instance == null) 17 | { 18 | _instance = new EventFactory(); 19 | } 20 | return _instance; 21 | } 22 | } 23 | 24 | public void Register(IEventProvider provider) 25 | { 26 | Type t = typeof(T); 27 | 28 | if (_eventProviders.ContainsKey(t)) 29 | return; 30 | 31 | _eventProviders.Add(t, provider); 32 | } 33 | 34 | public IEventProvider ProviderFor() 35 | { 36 | Type t = typeof(T); 37 | if (_eventProviders.ContainsKey(t)) 38 | return _eventProviders[t]; 39 | 40 | return null; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/TransactionBlockInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Numerics; 4 | using System.Text; 5 | 6 | namespace LoopringSharp 7 | { 8 | public class TransactionBlockInfo 9 | { 10 | public string txType { get; set; } 11 | public int? accountId { get; set; } 12 | public string owner { get; set; } 13 | 14 | public TokenBlockInfo token { get;set;} 15 | public TokenBlockInfo toToken { get; set; } 16 | public TokenBlockInfo fee { get; set; } 17 | public BigInteger? validUntil { get; set; } 18 | public int? toAccountId { get; set; } 19 | public string toAccountAddress { get; set; } 20 | public int? storageId { get; set; } 21 | public OrderBlockInfo orderA { get; set; } 22 | public OrderBlockInfo orderB { get; set; } 23 | public bool? valid { get; set; } 24 | public int? nonce { get; set; } 25 | public int? minterAccountId { get; set; } 26 | public string minter { get; set; } 27 | public TokenBlockInfo nftToken { get; set; } 28 | public string nftType { get; set; } 29 | public string fromAddress { get; set; } 30 | public string toAddress { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LoopringSharp.MetaMask/EDDSAHelper.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp.MetaMask 2 | { 3 | public static partial class EDDSAHelper 4 | { 5 | public static (string publicKeyX, string publicKeyY, string secretKey, string ethAddress) EDDSASignMetamask(string exchangeAddress, string apiUrl, bool skipPublicKeyCalculation = false, bool nextNonce = false) 6 | { 7 | // Requesting metamask to sign our package so we can tare it apart and get our public and secret keys 8 | var rawKey = MetamaskServer.L2Authenticate("We need you to sign this message in Metamask in order to access your Layer 2 wallet", exchangeAddress, apiUrl, nextNonce); 9 | return LoopringSharp.EDDSAHelper.RipKeyAppart(rawKey, skipPublicKeyCalculation); 10 | } 11 | 12 | public static (string secretKey, string ethAddress, string publicKeyX, string publicKeyY) GetL2PKFromMetaMask(string exchangeAddress, string apiUrl) 13 | { 14 | var sign = EDDSASignMetamask(exchangeAddress, apiUrl, true); 15 | // We're only interested in the secret key for signing packages. Which ironically is the simplest one to get... 16 | return (sign.secretKey, sign.ethAddress, sign.publicKeyX, sign.publicKeyY); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /__azurite_db_queue_extent__.json: -------------------------------------------------------------------------------- 1 | {"filename":"/Users/justinpopa/Documents/Repos/LoopringSharp/__azurite_db_queue_extent__.json","collections":[{"name":"$EXTENTS_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"id":{"name":"id","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$EXTENTS_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]}],"databaseVersion":1.5,"engineVersion":1.5,"autosave":true,"autosaveInterval":5000,"autosaveHandle":null,"throttledSaves":true,"options":{"autosave":true,"autosaveInterval":5000,"serializationMethod":"normal","destructureDelimiter":"$<\n"},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"} -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Utils/Hex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.RegularExpressions; 3 | 4 | namespace WalletConnectSharp.Core.Utils 5 | { 6 | public static class Hex 7 | { 8 | public static string ToHex(this byte[] data, bool includeDashes = false) 9 | { 10 | var b = BitConverter.ToString(data); 11 | return includeDashes ? b : b.Replace("-", ""); 12 | } 13 | 14 | public static bool IsHex(this string str, int? length = null) 15 | { 16 | string pattern = @"/^0x[0-9A-Fa-f]*$/"; 17 | 18 | if (!Regex.Match(str, pattern).Success) 19 | { 20 | return false; 21 | } 22 | 23 | if (length != null && str.Length != 2 + 2 * length) 24 | { 25 | return false; 26 | } 27 | 28 | return true; 29 | } 30 | 31 | public static byte[] FromHex(this string hex) 32 | { 33 | int NumberChars = hex.Length; 34 | byte[] bytes = new byte[NumberChars / 2]; 35 | for (int i = 0; i < NumberChars; i += 2) 36 | bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16); 37 | return bytes; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiResults/ApiPendingRequestsResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Numerics; 4 | using System.Text; 5 | 6 | namespace LoopringSharp 7 | { 8 | public class ApiPendingRequestsResult 9 | { 10 | public string txType { get; set; } 11 | public int? accountId { get; set; } 12 | public string owner { get; set; } 13 | public TokenBlockInfo token { get; set; } 14 | public TokenBlockInfo toToken { get; set; } 15 | public TokenBlockInfo fee { get; set; } 16 | public BigInteger? validUntil { get; set; } 17 | public int? toAccountId { get; set; } 18 | public string toAccountAddress { get; set; } 19 | public int? storageId { get; set; } 20 | public PendingRequestOrderBlockInfo orderA { get; set; } 21 | public PendingRequestOrderBlockInfo orderB { get; set; } 22 | public bool? valid { get; set; } 23 | public int? nonce { get; set; } 24 | public int? minterAccountId { get; set; } 25 | public string minter { get; set; } 26 | public TokenBlockInfo nftToken { get; set; } 27 | public string nftType { get; set; } 28 | public string fromAddress { get; set; } 29 | public string toAddress { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LoopringAPI/Models/TypedDataModels/TransferTypedData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Numerics; 3 | 4 | namespace LoopringSharp 5 | { 6 | public class TransferTypedData 7 | { 8 | public Domain domain { get; set; } 9 | public Message message { get; set; } 10 | public string primaryType { get; set; } 11 | public Types types { get; set; } 12 | 13 | public class Domain 14 | { 15 | public BigInteger chainId { get; set; } 16 | public string name { get; set; } 17 | public string verifyingContract { get; set; } 18 | public string version { get; set; } 19 | } 20 | 21 | public class Message 22 | { 23 | public string from { get; set; } 24 | public string to { get; set; } 25 | public int tokenID { get; set; } 26 | public string amount { get; set; } 27 | public int feeTokenID { get; set; } 28 | public string maxFee { get; set; } 29 | public int validUntil { get; set; } 30 | public int storageID { get; set; } 31 | } 32 | 33 | public class Types 34 | { 35 | public List EIP712Domain { get; set; } 36 | public List Transfer { get; set; } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Results/OrderDetails.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class OrderDetails 6 | { 7 | public OrderDetails(ApiOrderGetResult result) 8 | { 9 | hash = result.hash; 10 | clientOrderId = result.clientOrderId; 11 | side = (Side)Enum.Parse(typeof(Side), result.side, true); 12 | market = result.market; 13 | price = result.price; 14 | volumes = result.volumes; 15 | validity= result.validity; 16 | orderType = (OrderType)Enum.Parse(typeof(OrderType), result.orderType, true); 17 | tradeChannel = (TradeChannel)Enum.Parse(typeof(TradeChannel), result.tradeChannel, true); 18 | status = (OrderStatus)Enum.Parse(typeof(OrderStatus), result.status, true); 19 | } 20 | public string hash { get; set; } 21 | public string clientOrderId { get; set; } 22 | public Side side { get; set; } 23 | public string market { get; set; } 24 | public string price { get; set; } 25 | public Volumes volumes { get; set; } 26 | public Validity validity { get; set; } 27 | public OrderType orderType { get; set; } 28 | public TradeChannel tradeChannel { get; set; } 29 | public OrderStatus status { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LoopringAPI/Models/TypedDataModels/AccountUpdateTypedData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Numerics; 3 | 4 | namespace LoopringSharp 5 | { 6 | public class AccountUpdateTypedData 7 | { 8 | public Domain domain { get; set; } 9 | public Message message { get; set; } 10 | public string primaryType { get; set; } 11 | public Types types { get; set; } 12 | 13 | public class Domain 14 | { 15 | public BigInteger chainId { get; set; } 16 | public string name { get; set; } 17 | public string verifyingContract { get; set; } 18 | public string version { get; set; } 19 | } 20 | 21 | public class Message 22 | { 23 | public string owner { get; set; } 24 | public long accountID { get; set; } 25 | public int feeTokenID { get; set; } 26 | public string maxFee { get; set; } 27 | public string publicKey { get; set; } // this seemed like jut pubkey y so screw it! 28 | public long validUntil { get; set; } 29 | public long nonce { get; set; } 30 | } 31 | 32 | public class Types 33 | { 34 | public List EIP712Domain { get; set; } 35 | public List AccountUpdate { get; set; } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Network/TransportFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using WalletConnectSharp.Core.Events; 3 | 4 | namespace WalletConnectSharp.Core.Network 5 | { 6 | public class TransportFactory 7 | { 8 | private static TransportFactory _instance; 9 | 10 | public static TransportFactory Instance 11 | { 12 | get 13 | { 14 | if (_instance == null) 15 | _instance = new TransportFactory(); 16 | return _instance; 17 | } 18 | } 19 | 20 | private TransportFactory() {} 21 | 22 | private Func _defaultBuilder; 23 | 24 | public ITransport BuildDefaultTransport(EventDelegator eventDelegator) 25 | { 26 | if (_defaultBuilder != null) 27 | { 28 | return _defaultBuilder(eventDelegator); 29 | } 30 | 31 | return null; 32 | } 33 | 34 | public void RegisterDefaultTransport(Func builder) 35 | { 36 | if (this._defaultBuilder != null) 37 | { 38 | throw new ArgumentException("A Default Transport has already been defined!"); 39 | } 40 | 41 | this._defaultBuilder = builder; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /LoopringSharp.DualInvestment.AzureFunction/LoopringSharp.DualInvestment.AzureFunction.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net7.0 4 | v4 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | PreserveNewest 17 | 18 | 19 | PreserveNewest 20 | Never 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /LoopringAPI/Models/ApiRequests/ApiSubmitOrderRequest.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp 2 | { 3 | public class ApiSubmitOrderRequest 4 | { 5 | public string exchange { get; set; } 6 | public int accountId { get; set; } 7 | public int storageId { get; set; } 8 | public Token sellToken { get; set; } 9 | public Token buyToken { get; set; } 10 | public bool allOrNone { get; set; } = true; // Currently only supports true 11 | public bool fillAmountBOrS { get; set; } // Wat? 12 | public long validUntil { get; set; } // It's a timestamp 13 | public int maxFeeBips { get; set; } = 20; // Maximum order fee that the user can accept, value range (in ten thousandths) 1 ~ 63. WAT??? 14 | public string eddsaSignature { get; set; } 15 | 16 | // And now for the optionals 17 | public string clientOrderId { get; set; } 18 | public string orderType { get; set; } // AMM, LIMIT_ORDER, MAKER_ONLY, TAKER_ONLY 19 | public string tradeChannel { get; set; } // ORDER_BOOK, AMM_POOL, MIXED 20 | public string taker { get; set; } // {Used by the P2P order which user specify the taker, so far its} WAAAAAAAAAAAAAAAT????? 21 | public string poolAddress { get; set; } // The AMM pool address if order type is AMM 22 | public string affiliate { get; set; } // This one is very interesting from a profitability standpoint @.@ 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /LoopringAPI/Models/Requests/TransferRequest.cs: -------------------------------------------------------------------------------- 1 | using static LoopringSharp.ApiTransferRequest; 2 | 3 | namespace LoopringSharp 4 | { 5 | public class TransferRequest 6 | { 7 | // ESSENTIAL TRANSFER INFO 8 | public string exchange { get; set; } 9 | public int payerId { get; set; } 10 | public string payerAddr { get; set; } 11 | public int payeeId { get; set; } = 0; // Default of 0 if unknown is fine 12 | public string payeeAddr { get; set; } 13 | public Token token { get; set; } 14 | public Token maxFee { get; set; } 15 | public int storageId { get; set; } 16 | public int validUnitl { get; set; } 17 | public string tokenName { get; set; } 18 | public string tokenFeeName { get; set; } 19 | 20 | 21 | public ApiTransferRequest GetApiTransferRequest(string memo, string clientId, CounterFactualInfo counterFactualInfo) 22 | { 23 | return new ApiTransferRequest() 24 | { 25 | exchange = exchange, 26 | payerId = payerId, 27 | payerAddr = payerAddr, 28 | payeeId = payeeId, 29 | payeeAddr = payeeAddr, 30 | token = token, 31 | maxFee = maxFee, 32 | storageId = storageId, 33 | validUntil = validUnitl, 34 | clientId = clientId, 35 | memo = memo, 36 | 37 | counterFactualInfo = counterFactualInfo 38 | }; 39 | } 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/JsonRpcResponse.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace WalletConnectSharp.Core.Models 4 | { 5 | public class JsonRpcResponse : IEventSource 6 | { 7 | [JsonProperty] 8 | private long id; 9 | 10 | [JsonProperty] 11 | private string jsonrpc = "2.0"; 12 | 13 | [JsonProperty] 14 | private JsonRpcError error; 15 | 16 | [JsonIgnore] 17 | public JsonRpcError Error 18 | { 19 | get { return error; } 20 | } 21 | 22 | [JsonIgnore] 23 | public bool IsError 24 | { 25 | get { return error != null; } 26 | } 27 | 28 | [JsonIgnore] 29 | public long ID 30 | { 31 | get { return id; } 32 | } 33 | 34 | [JsonIgnore] 35 | public string JsonRPC 36 | { 37 | get { return jsonrpc; } 38 | } 39 | 40 | public class JsonRpcError 41 | { 42 | [JsonProperty] 43 | private int? code; 44 | 45 | [JsonProperty] 46 | private string message; 47 | 48 | [JsonIgnore] 49 | public int? Code 50 | { 51 | get { return code; } 52 | } 53 | 54 | [JsonIgnore] 55 | public string Message 56 | { 57 | get { return message; } 58 | } 59 | } 60 | 61 | [JsonIgnore] 62 | public string Event 63 | { 64 | get { return "response:" + ID; } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Events/EventHandlerMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace WalletConnectSharp.Core.Events 5 | { 6 | public class EventHandlerMap 7 | { 8 | private Dictionary> mapping = 9 | new Dictionary>(); 10 | 11 | private EventHandler BeforeEventExecuted; 12 | 13 | public EventHandlerMap(EventHandler callbackBeforeExecuted) 14 | { 15 | if (callbackBeforeExecuted == null) 16 | { 17 | callbackBeforeExecuted = CallbackBeforeExecuted; 18 | } 19 | 20 | this.BeforeEventExecuted = callbackBeforeExecuted; 21 | } 22 | 23 | private void CallbackBeforeExecuted(object sender, TEventArgs e) 24 | { 25 | } 26 | 27 | public EventHandler this[string topic] 28 | { 29 | get 30 | { 31 | if (!mapping.ContainsKey(topic)) 32 | { 33 | mapping.Add(topic, BeforeEventExecuted); 34 | } 35 | 36 | return mapping[topic]; 37 | } 38 | set 39 | { 40 | if (mapping.ContainsKey(topic)) 41 | { 42 | mapping.Remove(topic); 43 | } 44 | 45 | mapping.Add(topic, value); 46 | } 47 | } 48 | 49 | public bool Contains(string topic) 50 | { 51 | return mapping.ContainsKey(topic); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Events/EventManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace WalletConnectSharp.Core.Events 6 | { 7 | public class EventManager : IEventProvider where TEventArgs : IEvent, new() 8 | { 9 | private static EventManager _instance; 10 | 11 | public EventHandlerMap EventTriggers; 12 | 13 | public static EventManager Instance 14 | { 15 | get 16 | { 17 | if (_instance == null) 18 | { 19 | _instance = new EventManager(); 20 | } 21 | 22 | return _instance; 23 | } 24 | } 25 | 26 | private EventManager() 27 | { 28 | EventTriggers = new EventHandlerMap(CallbackBeforeExecuted); 29 | 30 | EventFactory.Instance.Register(this); 31 | } 32 | 33 | private void CallbackBeforeExecuted(object sender, TEventArgs e) 34 | { 35 | } 36 | 37 | public void PropagateEvent(string topic, string responseJson) 38 | { 39 | if (EventTriggers.Contains(topic)) 40 | { 41 | var eventTrigger = EventTriggers[topic]; 42 | 43 | if (eventTrigger != null) 44 | { 45 | var response = JsonConvert.DeserializeObject(responseJson); 46 | var eventArgs = new TEventArgs(); 47 | eventArgs.SetData(response); 48 | eventTrigger(this, eventArgs); 49 | } 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /__azurite_db_blob_extent__.json: -------------------------------------------------------------------------------- 1 | {"filename":"/Users/justinpopa/Documents/Repos/LoopringSharp/__azurite_db_blob_extent__.json","collections":[{"name":"$EXTENTS_COLLECTION$","data":[{"id":"bfecf779-9cef-4949-9054-9d8e3b269f5c","locationId":"Default","path":"bfecf779-9cef-4949-9054-9d8e3b269f5c","size":366,"lastModifiedInMS":1683318983660,"meta":{"revision":4,"created":1683318983660,"version":0,"updated":1683319290044},"$loki":1,"LastModifyInMS":1683319290044},{"id":"64ef6ad9-91a6-4561-8f4b-cb67a0e0113b","locationId":"Default","path":"64ef6ad9-91a6-4561-8f4b-cb67a0e0113b","size":381,"lastModifiedInMS":1683351037956,"meta":{"revision":2,"created":1683351037956,"version":0,"updated":1683353105782},"$loki":2,"LastModifyInMS":1683353105782}],"idIndex":[1,2],"binaryIndices":{"id":{"name":"id","dirty":false,"values":[1,0]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$EXTENTS_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":2,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]}],"databaseVersion":1.5,"engineVersion":1.5,"autosave":true,"autosaveInterval":5000,"autosaveHandle":null,"throttledSaves":true,"options":{"autosave":true,"autosaveInterval":5000,"serializationMethod":"normal","destructureDelimiter":"$<\n"},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"} -------------------------------------------------------------------------------- /__azurite_db_table__.json: -------------------------------------------------------------------------------- 1 | {"filename":"/Users/justinpopa/Documents/Repos/LoopringSharp/__azurite_db_table__.json","collections":[{"name":"$TABLES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"account":{"name":"account","dirty":false,"values":[]},"table":{"name":"table","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$TABLES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]},{"name":"$SERVICES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{},"constraints":null,"uniqueNames":["accountName"],"transforms":{},"objType":"$SERVICES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]}],"databaseVersion":1.5,"engineVersion":1.5,"autosave":true,"autosaveInterval":5000,"autosaveHandle":null,"throttledSaves":true,"options":{"autosave":true,"autosaveInterval":5000,"serializationMethod":"normal","destructureDelimiter":"$<\n"},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"} -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Network/DefaultBridge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace WalletConnectSharp.Core.Network 5 | { 6 | public static class DefaultBridge 7 | { 8 | public static string Domain = "walletconnect.org"; 9 | 10 | public static string MainBridge = "https://bridge.walletconnect.org"; 11 | 12 | public const string AlphaNumeric = "abcdefghijklmnopqrstuvwxyz0123456789"; 13 | 14 | public static readonly string[] Bridges = 15 | AlphaNumeric.Select(c => "https://" + c + ".bridge.walletconnect.org").ToArray(); 16 | 17 | private static string ExtractHostname(string url) 18 | { 19 | var hostname = url.IndexOf("//") > -1 ? url.Split('/')[2] : url.Split('/')[0]; 20 | hostname = hostname.Split(':')[0]; 21 | hostname = hostname.Split('?')[0]; 22 | 23 | return hostname; 24 | } 25 | 26 | private static string ExtractRootDomain(string url) 27 | { 28 | var items = ExtractHostname(url).Split('.').ToArray(); 29 | return string.Join(".", items.Skip(items.Length - 2)); 30 | } 31 | 32 | private static string[] _bridgeCache = null; 33 | 34 | public static string[] AllBridges 35 | { 36 | get 37 | { 38 | return _bridgeCache ?? 39 | (_bridgeCache = Enumerable.Empty().Append(MainBridge).Concat(Bridges).ToArray()); 40 | } 41 | } 42 | 43 | public static string ChooseRandomBridge(string[] possibleBridges = null) 44 | { 45 | if (possibleBridges == null) 46 | { 47 | possibleBridges = AllBridges; 48 | } 49 | 50 | var random = new Random(); 51 | return possibleBridges[random.Next(possibleBridges.Length)]; 52 | } 53 | 54 | public static string GetBridgeUrl(string url) 55 | { 56 | if (ExtractRootDomain(url) == Domain) 57 | return ChooseRandomBridge(); 58 | return url; 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /LoopringAPI/LoopringSharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | True 6 | 0.3.4 7 | 0.3.4 8 | 0.3.4 9 | Taranasus 10 | Taranasus 11 | A library to help you connect with the Loopring API https://docs.loopring.io/ 12 | https://github.com/taranasus/LoopringSharp 13 | loopringsharp.png 14 | README.md 15 | https://github.com/taranasus/LoopringSharp 16 | git 17 | loopring;loopringsharp;csharp;c#;loopring c#;loopring#;loopringapi;loopring api;layer2;l2 18 | Removed the metamask and wallet connect stuff from the base package as it's not relevant here 19 | LICENSE.txt 20 | True 21 | 22 | 23 | 24 | 25 | 26 | 27 | Always 28 | 29 | 30 | 31 | 32 | True 33 | \ 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | True 46 | \ 47 | 48 | 49 | -------------------------------------------------------------------------------- /__azurite_db_queue__.json: -------------------------------------------------------------------------------- 1 | {"filename":"/Users/justinpopa/Documents/Repos/LoopringSharp/__azurite_db_queue__.json","collections":[{"name":"$SERVICES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{},"constraints":null,"uniqueNames":["accountName"],"transforms":{},"objType":"$SERVICES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]},{"name":"$QUEUES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"accountName":{"name":"accountName","dirty":false,"values":[]},"name":{"name":"name","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$QUEUES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]},{"name":"$MESSAGES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"accountName":{"name":"accountName","dirty":false,"values":[]},"queueName":{"name":"queueName","dirty":false,"values":[]},"messageId":{"name":"messageId","dirty":false,"values":[]},"visibleTime":{"name":"visibleTime","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$MESSAGES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]}],"databaseVersion":1.5,"engineVersion":1.5,"autosave":true,"autosaveInterval":5000,"autosaveHandle":null,"throttledSaves":true,"options":{"autosave":true,"autosaveInterval":5000,"serializationMethod":"normal","destructureDelimiter":"$<\n"},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"} -------------------------------------------------------------------------------- /LoopringAPI.OneButtonPayExample/TransferForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | text/microsoft-resx 50 | 51 | 52 | 2.0 53 | 54 | 55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 56 | 57 | 58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 59 | 60 | -------------------------------------------------------------------------------- /LoopringAPI/Helpers/Constants.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Security.Cryptography; 3 | 4 | namespace LoopringSharp 5 | { 6 | public static class Constants 7 | { 8 | public static Dictionary TokenIDMapper = new Dictionary(); 9 | 10 | public static string OffchainFeeUrl = "api/v3/user/offchainFee"; 11 | public static string CreateInfoUrl = "api/v3/user/createInfo"; 12 | public static string UpdateInfoUrl = "api/v3/user/updateInfo"; 13 | public static string BalancesUrl = "api/v3/user/balances"; 14 | public static string DepositsUrl = "/api/v3/user/deposits"; 15 | public static string WithdrawlsUrl = "/api/v3/user/withdrawals"; 16 | public static string TransfersUrl = "/api/v3/user/transfers"; 17 | public static string TradeHistoryUrl = "api/v3/user/trades"; 18 | public static string OrderFeeUrl = "api/v3/user/orderFee"; 19 | public static string OrderUserRateAmountUrl = "api/v3/user/orderUserRateAmount"; 20 | public static string StorageIdUrl = "api/v3/storageId"; 21 | public static string TickerUrl = "api/v3/ticker"; 22 | public static string TimestampUrl = "api/v3/timestamp"; 23 | public static string TransferUrl = "api/v3/transfer"; 24 | public static string ApiKeyUrl = "api/v3/apiKey"; 25 | 26 | public static string OrderUrl = "api/v3/order"; 27 | public static string OrdersUrl = "api/v3/orders"; 28 | public static string AccountUrl = "api/v3/account"; 29 | public static string MarketsUrl = "api/v3/exchange/markets"; 30 | public static string TokensUrl = "api/v3/exchange/tokens"; 31 | public static string InfoUrl = "api/v3/exchange/info"; 32 | public static string DepthUrl = "api/v3/depth"; 33 | public static string DepthMixUrl = "api/v3/mix/depth"; 34 | public static string CandlestickUrl = "api/v3/candlestick"; 35 | public static string PriceUrl = "api/v3/price"; 36 | public static string TradeUrl = "api/v3/trade"; 37 | 38 | public static string L2BlockInfoUrl = "api/v3/block/getBlock"; 39 | public static string PendingRequestsUrl = "api/v3/block/getPendingRequests"; 40 | 41 | public static string AmmPoolTradesUrl = "api/v3/amm/trades"; 42 | public static string AmmJoinExitTransactionsUrl = "/api/v3/amm/user/transactions"; 43 | public static string AmmPoolConfigurationUrl = "api/v3/amm/pools"; 44 | public static string AmmPoolBalanceUrl = "api/v3/amm/balance"; 45 | 46 | public static string EIP721DomainName = "Loopring Protocol"; 47 | public static string EIP721DomainVersion = "3.6.0"; 48 | 49 | public static string HttpHeaderAPIKeyName = "X-API-KEY"; 50 | public static string HttpHeaderAPISigName = "X-API-SIG"; 51 | 52 | public static string DualInvestmentInfoUrl = "api/v3/dual/infos"; 53 | public static string DualInvestmentOrder = "api/v3/dual/order"; 54 | 55 | 56 | 57 | public static string WalletConnectHTML = @" 58 | 59 | 60 | WalletConnect Details 61 | 62 | 63 | 64 |

For wallet connect, scan this CR code or paste the bellow code into your wallet

65 |
66 |

|--|--|

67 | 68 | 69 | "; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Events/EventDelegator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | using WalletConnectSharp.Core.Events.Request; 5 | using WalletConnectSharp.Core.Events.Response; 6 | using WalletConnectSharp.Core.Models; 7 | 8 | namespace WalletConnectSharp.Core.Events 9 | { 10 | public class EventDelegator : IDisposable 11 | { 12 | private Dictionary> Listeners = new Dictionary>(); 13 | 14 | public void ListenForGenericResponse(object id, EventHandler> callback) 15 | { 16 | ListenFor("response:" + id, callback); 17 | } 18 | 19 | public void ListenForResponse(object id, EventHandler> callback) where T : JsonRpcResponse 20 | { 21 | ListenFor("response:" + id, callback); 22 | } 23 | 24 | public void ListenFor(string eventId, EventHandler> callback) 25 | { 26 | EventManager>.Instance.EventTriggers[eventId] += callback; 27 | 28 | SubscribeProvider(eventId, EventFactory.Instance.ProviderFor()); 29 | } 30 | 31 | public void ListenFor(string eventId, EventHandler> callback) where T : JsonRpcResponse 32 | { 33 | EventManager>.Instance.EventTriggers[eventId] += callback; 34 | 35 | SubscribeProvider(eventId, EventFactory.Instance.ProviderFor()); 36 | } 37 | 38 | public void ListenFor(string eventId, EventHandler> callback) where T : JsonRpcRequest 39 | { 40 | EventManager>.Instance.EventTriggers[eventId] += callback; 41 | 42 | SubscribeProvider(eventId, EventFactory.Instance.ProviderFor()); 43 | } 44 | 45 | private void SubscribeProvider(string eventId, IEventProvider provider) 46 | { 47 | List listProvider; 48 | if (!Listeners.ContainsKey(eventId)) 49 | { 50 | //Debug.Log("Adding new EventProvider list for " + eventId); 51 | listProvider = new List(); 52 | Listeners.Add(eventId, listProvider); 53 | } 54 | else 55 | { 56 | listProvider = Listeners[eventId]; 57 | } 58 | listProvider.Add(provider); 59 | } 60 | 61 | public bool Trigger(string topic, T obj) 62 | { 63 | return Trigger(topic, JsonConvert.SerializeObject(obj)); 64 | } 65 | 66 | 67 | public bool Trigger(string topic, string json) 68 | { 69 | if (Listeners.ContainsKey(topic)) 70 | { 71 | var providerList = Listeners[topic]; 72 | 73 | for (int i = 0; i < providerList.Count; i++) 74 | { 75 | var provider = providerList[i]; 76 | 77 | provider.PropagateEvent(topic, json); 78 | } 79 | 80 | return providerList.Count > 0; 81 | } 82 | 83 | return false; 84 | } 85 | 86 | public void Dispose() 87 | { 88 | Clear(); 89 | } 90 | 91 | public void Clear() 92 | { 93 | Listeners.Clear(); 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/Ethereum/Types/EvmTypedData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Runtime.Serialization; 5 | 6 | namespace WalletConnectSharp.Core.Models.Ethereum.Types 7 | { 8 | public class EvmTypedData 9 | { 10 | public static readonly Dictionary TypeMap = new Dictionary() 11 | { 12 | {typeof(Address), "address"}, 13 | {typeof(bool), "bool"}, 14 | {typeof(int), "uint32"}, 15 | {typeof(long), "int64"}, 16 | {typeof(uint), "uint32"}, 17 | {typeof(ulong), "uint64"}, 18 | {typeof(short), "int16"}, 19 | {typeof(ushort), "uint16"}, 20 | {typeof(byte), "int8"}, 21 | {typeof(sbyte), "uint8"}, 22 | {typeof(string), "string"}, 23 | }; 24 | 25 | public Dictionary types = new Dictionary(); 26 | public string primaryType; 27 | public EIP712Domain domain; 28 | public T message; 29 | 30 | public EvmTypedData(T data, EIP712Domain domain) 31 | { 32 | this.message = data; 33 | this.domain = domain; 34 | this.primaryType = typeof(T).Name; 35 | 36 | AddTypeData(typeof(EIP712Domain)); 37 | AddTypeData(typeof(T)); 38 | } 39 | 40 | public void AddTypeData(Type type) 41 | { 42 | var tname = type.Name; 43 | if (types.ContainsKey(tname)) 44 | return; 45 | 46 | List infos = new List(); 47 | BindingFlags bindingFlags = BindingFlags.Public | 48 | BindingFlags.NonPublic | 49 | BindingFlags.Instance; 50 | 51 | foreach (var field in type.GetFields(bindingFlags)) 52 | { 53 | string name = field.Name; 54 | var fieldType = field.FieldType; 55 | var evmType = (EvmTypeAttribute)field.GetCustomAttribute(typeof(EvmTypeAttribute), true); 56 | var shouldIgnore = (EvmIgnoreAttribute) field.GetCustomAttribute(typeof(EvmIgnoreAttribute), true); 57 | 58 | if (shouldIgnore != null) 59 | continue; 60 | 61 | 62 | string typeName; 63 | if (evmType != null) 64 | { 65 | typeName = evmType.TypeName; 66 | } 67 | else if (TypeMap.ContainsKey(fieldType)) 68 | { 69 | typeName = TypeMap[fieldType]; 70 | } 71 | else if ( 72 | (type.IsValueType && !type.IsPrimitive) || 73 | (type.IsClass) 74 | ) 75 | { 76 | AddTypeData(fieldType); 77 | typeName = fieldType.Name; 78 | } 79 | else 80 | { 81 | throw new SerializationException("Field " + name + " has no valid EVM type mapping. Try adding a [EvmType(\"...\")] to this field"); 82 | } 83 | 84 | var typeInfo = new EvmTypeInfo(name, typeName); 85 | 86 | infos.Add(typeInfo); 87 | } 88 | 89 | types.Add(tname, infos.ToArray()); 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/WalletConnectServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using WalletConnectSharp; 5 | using WalletConnectSharp.Core; 6 | using WalletConnectSharp.Core.Utils; 7 | using WalletConnectSharp.Core.Network; 8 | using WalletConnectSharp.Core.Models; 9 | using System.Threading.Tasks; 10 | using System.Threading; 11 | using Nethereum.Web3; 12 | using WalletConnectSharp.Core.Models.Ethereum; 13 | 14 | namespace LoopringSharp.WalletConnect 15 | { 16 | public static class WalletConnectServer 17 | { 18 | private static WalletConnectSession walletConnect; 19 | private static bool isWaitingForConnection = false; 20 | 21 | public static string Connect() 22 | { 23 | var metadata = new ClientMeta() 24 | { 25 | Description = "This is a test of the Nethereum.WalletConnect feature", 26 | Icons = new[] { "https://app.warriders.com/favicon.ico" }, 27 | Name = "WalletConnect Test", 28 | URL = "https://app.warriders.com" 29 | }; 30 | TransportFactory.Instance.RegisterDefaultTransport((eventDelegator) => new WebsocketTransport(eventDelegator)); 31 | walletConnect = new WalletConnectSession(metadata); 32 | Task.Run(async () => 33 | { 34 | isWaitingForConnection = true; 35 | try 36 | { 37 | await walletConnect.Connect(); 38 | } 39 | catch (Exception ex) 40 | { 41 | walletConnect = null; 42 | throw ex; 43 | } 44 | isWaitingForConnection = false; 45 | }); 46 | return walletConnect.URI; 47 | } 48 | 49 | public static string GetEthAddress() 50 | { 51 | if (walletConnect == null) 52 | { 53 | throw new Exception("You must first run the Connect() method and give the resulting stirng to the user so they can allow the connection"); 54 | } 55 | 56 | while (isWaitingForConnection) 57 | { 58 | Thread.Sleep(100); 59 | } 60 | 61 | while (!walletConnect.Connected) 62 | { 63 | Thread.Sleep(100); 64 | } 65 | 66 | return walletConnect.Accounts[0]; 67 | } 68 | 69 | public static (string eddsa, string ethAddress) L2Authenticate(string exchangeAddress, int nonce) 70 | { 71 | if (walletConnect == null) 72 | { 73 | throw new Exception("You must first run the Connect() method and give the resulting stirng to the user so they can allow the connection"); 74 | } 75 | 76 | while (isWaitingForConnection) 77 | { 78 | Thread.Sleep(100); 79 | } 80 | 81 | while (!walletConnect.Connected) 82 | { 83 | Thread.Sleep(100); 84 | } 85 | 86 | string hexData = "Sign this message to access Loopring Exchange: " + exchangeAddress + " with key nonce: " + nonce; 87 | string address = walletConnect.Accounts[0]; 88 | 89 | var result = walletConnect.EthSign(address, hexData).Result; 90 | return (result, address); 91 | } 92 | public static async Task Sign(string serializedData, string signatureMethod, string ethAddress) 93 | { 94 | var result = await walletConnect.EthSignTypedDataV4(ethAddress, serializedData); 95 | return result; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /LoopringSharp.MetaMask/MetamaskClient.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace LoopringSharp.MetaMask 4 | { 5 | public class MetamaskClient : LoopringSharp.Client 6 | { 7 | MetamaskSecureClient _metamaskClient; 8 | public MetamaskClient(string apiUrl) : base(apiUrl, GetL2Details(apiUrl)) 9 | { 10 | _metamaskClient = new MetamaskSecureClient(apiUrl); 11 | } 12 | 13 | /// 14 | /// Send some tokens to anyone else on L2 15 | /// 16 | /// The basic transaction details needed in order to actually do a transaction 17 | /// (Optional)And do you want the transaction to contain a reference. From loopring's perspective, this is just a text field 18 | /// (Optional)A user-defined id. It's similar to the memo field? Again the original documentation is not very clear 19 | /// (Optional)Not entirely sure. Official documentation says: field.UpdateAccountRequestV3.counterFactualInfo 20 | /// An object containing the status of the transfer at the end of the request 21 | /// Gets thrown when there's a problem getting info from the Loopring API endpoint 22 | public virtual OperationResult Transfer(TransferRequest request, string memo, string clientId, CounterFactualInfo counterFactualInfo = null) 23 | { 24 | return _metamaskClient.Transfer(_apiKey, _loopringPrivateKey, _ethPrivateKey, request, memo, clientId, counterFactualInfo); 25 | } 26 | 27 | /// 28 | /// Send some tokens to anyone else on L2 29 | /// 30 | /// The loopring address that's doing the receiving 31 | /// What token is being sent 32 | /// And how much of that token are we sending 33 | /// In what token are we paying the fee 34 | /// (Optional)And do you want the transaction to contain a reference. From loopring's perspective, this is just a text field 35 | /// An object containing the status of the transfer at the end of the request 36 | public virtual OperationResult Transfer(string toAddress, string token, decimal value, string feeToken, string memo) 37 | { 38 | return _metamaskClient.Transfer(_apiKey, _loopringPrivateKey, _ethPrivateKey, _accountId, _ethAddress, toAddress, token, value, feeToken, memo); 39 | } 40 | 41 | /// 42 | /// WARNING!!! This has a fee asociated with it. Make a OffchainFee request of type OffChainRequestType.UpdateAccount to see what the fee is. 43 | /// Updates the EDDSA key associated with the specified account, making the previous one invalid in the process. 44 | /// 45 | /// The token in which the fee should be paid for this operation 46 | /// Returns the hash and status of your requested operation 47 | public virtual OperationResult RequestNewL2PrivateKey(string feeToken) 48 | { 49 | return _metamaskClient.UpdateAccount(_apiKey, _ethPrivateKey, _loopringPrivateKey, _accountId, feeToken, _ethAddress, ExchangeInfo().exchangeAddress); 50 | } 51 | 52 | private static (string secretKey, string ethAddress, string publicKeyX, string publicKeyY) GetL2Details(string apiUrl) 53 | { 54 | var l2Auth = EDDSAHelper.GetL2PKFromMetaMask(LoopringSharp.SecureClient.ExchangeInfo(apiUrl).exchangeAddress, apiUrl); 55 | return l2Auth; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/WebsocketTransport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Websocket.Client; 3 | using WalletConnectSharp.Core.Network; 4 | using WalletConnectSharp.Core.Models; 5 | using System.Threading.Tasks; 6 | using WalletConnectSharp.Core.Events; 7 | using System.Net.WebSockets; 8 | using Newtonsoft.Json; 9 | using WalletConnectSharp.Core.Events.Request; 10 | using WalletConnectSharp.Core.Events.Response; 11 | 12 | namespace LoopringSharp.WalletConnect 13 | { 14 | public class WebsocketTransport : ITransport 15 | { 16 | private WebsocketClient client; 17 | private EventDelegator _eventDelegator; 18 | 19 | public WebsocketTransport(EventDelegator eventDelegator) 20 | { 21 | this._eventDelegator = eventDelegator; 22 | } 23 | 24 | public void Dispose() 25 | { 26 | if (client != null) 27 | client.Dispose(); 28 | } 29 | 30 | public bool Connected 31 | { 32 | get 33 | { 34 | return client.NativeClient.State == WebSocketState.Open; 35 | } 36 | } 37 | 38 | public event EventHandler MessageReceived; 39 | public async Task Open(string url) 40 | { 41 | if (url.StartsWith("https")) 42 | url = url.Replace("https", "wss"); 43 | else if (url.StartsWith("http")) 44 | url = url.Replace("http", "ws"); 45 | 46 | if (client != null) 47 | return; 48 | 49 | client = new WebsocketClient(new Uri(url)); 50 | 51 | client.MessageReceived.Subscribe(OnMessageReceived); 52 | client.DisconnectionHappened.Subscribe(delegate (DisconnectionInfo info) { client.Reconnect(); }); 53 | 54 | //TODO Log this 55 | /*client.ReconnectionHappened.Subscribe(delegate(ReconnectionInfo info) 56 | { 57 | Console.WriteLine(info.Type); 58 | });*/ 59 | 60 | await client.Start(); 61 | } 62 | 63 | private async void OnMessageReceived(ResponseMessage responseMessage) 64 | { 65 | var json = responseMessage.Text; 66 | 67 | var msg = JsonConvert.DeserializeObject(json); 68 | 69 | await SendMessage(new NetworkMessage() 70 | { 71 | Payload = "", 72 | Type = "ack", 73 | Silent = true, 74 | Topic = msg.Topic 75 | }); 76 | 77 | 78 | if (this.MessageReceived != null) 79 | MessageReceived(this, new MessageReceivedEventArgs(msg, this)); 80 | } 81 | 82 | public async Task Close() 83 | { 84 | await client.Stop(WebSocketCloseStatus.NormalClosure, ""); 85 | } 86 | 87 | public async Task SendMessage(NetworkMessage message) 88 | { 89 | var finalJson = JsonConvert.SerializeObject(message); 90 | 91 | await this.client.SendInstant(finalJson); 92 | } 93 | 94 | public async Task Subscribe(string topic) 95 | { 96 | await SendMessage(new NetworkMessage() 97 | { 98 | Payload = "", 99 | Type = "sub", 100 | Silent = true, 101 | Topic = topic 102 | }); 103 | } 104 | 105 | public async Task Subscribe(string topic, EventHandler> callback) where T : JsonRpcResponse 106 | { 107 | await Subscribe(topic); 108 | 109 | _eventDelegator.ListenFor(topic, callback); 110 | } 111 | 112 | public async Task Subscribe(string topic, EventHandler> callback) where T : JsonRpcRequest 113 | { 114 | await Subscribe(topic); 115 | 116 | _eventDelegator.ListenFor(topic, callback); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /LoopringSharp.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32002.185 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LoopringSharp", "LoopringAPI\LoopringSharp.csproj", "{47C53B0C-ACDA-4DF8-B835-70F2FCC5DF62}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LoopringSharp.TestConsole", "LoopringAPI.TestConsole\LoopringSharp.TestConsole.csproj", "{F3B0E70B-3D69-42A1-AB86-55B0BE4FC5F8}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LoopringSharp.Layer2TransferExample", "LoopringAPI.OneButtonPayExample\LoopringSharp.Layer2TransferExample.csproj", "{F82E405D-D04E-430C-9100-9F899B9B1954}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LoopringSharp.UnitTests", "LoopringAPI.UnitTests\LoopringSharp.UnitTests.csproj", "{0AD5A558-B81E-448D-B588-744A5AF814F6}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoopringSharp.MetaMask", "LoopringSharp.MetaMask\LoopringSharp.MetaMask.csproj", "{6972545C-9819-42B5-B7BD-116AFD001B05}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoopringSharp.WalletConnect", "LoopringSharp.WalletConnect\LoopringSharp.WalletConnect.csproj", "{BF3D356C-E986-4A1A-ADAD-15D3C36B6FAC}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoopringSharp.DualInvestment.AzureFunction", "LoopringSharp.DualInvestment.AzureFunction\LoopringSharp.DualInvestment.AzureFunction.csproj", "{6AECD03B-1C79-4700-A574-93FEECF3D18E}" 19 | EndProject 20 | Global 21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 22 | Debug|Any CPU = Debug|Any CPU 23 | Release|Any CPU = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {47C53B0C-ACDA-4DF8-B835-70F2FCC5DF62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {47C53B0C-ACDA-4DF8-B835-70F2FCC5DF62}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {47C53B0C-ACDA-4DF8-B835-70F2FCC5DF62}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {47C53B0C-ACDA-4DF8-B835-70F2FCC5DF62}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {F3B0E70B-3D69-42A1-AB86-55B0BE4FC5F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {F3B0E70B-3D69-42A1-AB86-55B0BE4FC5F8}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {F3B0E70B-3D69-42A1-AB86-55B0BE4FC5F8}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {F3B0E70B-3D69-42A1-AB86-55B0BE4FC5F8}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {F82E405D-D04E-430C-9100-9F899B9B1954}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {F82E405D-D04E-430C-9100-9F899B9B1954}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {F82E405D-D04E-430C-9100-9F899B9B1954}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {F82E405D-D04E-430C-9100-9F899B9B1954}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {0AD5A558-B81E-448D-B588-744A5AF814F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {0AD5A558-B81E-448D-B588-744A5AF814F6}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {0AD5A558-B81E-448D-B588-744A5AF814F6}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {0AD5A558-B81E-448D-B588-744A5AF814F6}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {6972545C-9819-42B5-B7BD-116AFD001B05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {6972545C-9819-42B5-B7BD-116AFD001B05}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {6972545C-9819-42B5-B7BD-116AFD001B05}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {6972545C-9819-42B5-B7BD-116AFD001B05}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {BF3D356C-E986-4A1A-ADAD-15D3C36B6FAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {BF3D356C-E986-4A1A-ADAD-15D3C36B6FAC}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {BF3D356C-E986-4A1A-ADAD-15D3C36B6FAC}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {BF3D356C-E986-4A1A-ADAD-15D3C36B6FAC}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {6AECD03B-1C79-4700-A574-93FEECF3D18E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {6AECD03B-1C79-4700-A574-93FEECF3D18E}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {6AECD03B-1C79-4700-A574-93FEECF3D18E}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {6AECD03B-1C79-4700-A574-93FEECF3D18E}.Release|Any CPU.Build.0 = Release|Any CPU 54 | EndGlobalSection 55 | GlobalSection(SolutionProperties) = preSolution 56 | HideSolutionNode = FALSE 57 | EndGlobalSection 58 | GlobalSection(ExtensibilityGlobals) = postSolution 59 | SolutionGuid = {EB065C43-E5DB-4CBB-9C0A-6F610041D0D4} 60 | EndGlobalSection 61 | EndGlobal 62 | -------------------------------------------------------------------------------- /LoopringSharp.MetaMask/Metamask.cs: -------------------------------------------------------------------------------- 1 | using EmbedIO; 2 | using EmbedIO.Actions; 3 | using EmbedIO.Files; 4 | using EmbedIO.Security; 5 | using EmbedIO.WebApi; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Collections.Specialized; 9 | using System.IO; 10 | using System.Net.Http; 11 | using System.Text; 12 | 13 | namespace LoopringSharp.MetaMask 14 | { 15 | public static class MetamaskServer 16 | { 17 | private static WebServer server; 18 | public static string eddsa; 19 | public static string ethAddress; 20 | 21 | public static (string eddsa, string ethAddress) L2Authenticate(string userMessage, string exchangeAddress, string apiUrl, bool nextNonce) 22 | { 23 | string nonceModifier = "- 1"; 24 | if (nextNonce) 25 | nonceModifier = "+ 0"; 26 | 27 | File.WriteAllText(Directory.GetCurrentDirectory() + "/l2au.html", 28 | Constants.MetaMaskAuthTemplate.Replace("||--||", apiUrl + LoopringSharp.Constants.AccountUrl + "?owner=") 29 | .Replace("|-|-|-|", exchangeAddress) 30 | .Replace("|---------|", userMessage) 31 | .Replace("|--|--|--|", nonceModifier)); ; 32 | 33 | eddsa = null; 34 | ethAddress = null; 35 | 36 | ServerInitiator("/l2au.html"); 37 | 38 | // Wait for authentication to finish 39 | while (eddsa == null) 40 | { 41 | System.Threading.Thread.Sleep(100); 42 | } 43 | 44 | CloseServer(); 45 | 46 | File.Delete(Directory.GetCurrentDirectory() + "/l2au.html"); 47 | 48 | return (eddsa.Replace("\"", ""), ethAddress); 49 | } 50 | 51 | public static string Sign(string dataGram, string signatureMethod, string userMessage) 52 | { 53 | string htmlPage = Constants.MetaMaskSignatureTemplate.Replace("||||||", "\"" + dataGram.Replace("\"", "\\\"") + "\""); 54 | htmlPage = htmlPage.Replace("|-----|", signatureMethod); 55 | htmlPage = htmlPage.Replace("|---------|", userMessage); 56 | File.WriteAllText(Directory.GetCurrentDirectory() + "/sign.html", htmlPage); 57 | 58 | eddsa = null; 59 | 60 | ServerInitiator("/sign.html"); 61 | 62 | // Wait for authentication to finish 63 | while (eddsa == null) 64 | { 65 | System.Threading.Thread.Sleep(100); 66 | } 67 | 68 | CloseServer(); 69 | 70 | File.Delete(Directory.GetCurrentDirectory() + "/sign.html"); 71 | 72 | if (signatureMethod == "eth_signTypedData_v4") 73 | return eddsa.Replace("\"", "") + "02"; 74 | else 75 | return eddsa.Replace("\"", ""); 76 | } 77 | 78 | private static void ServerInitiator(string page) 79 | { 80 | if (server == null) 81 | { 82 | server = new WebServer(o => o 83 | .WithUrlPrefix(Constants.MetaMaskWebServerUrl) 84 | .WithMode(HttpListenerMode.EmbedIO)) 85 | .WithIPBanning(o => o 86 | .WithMaxRequestsPerSecond() 87 | .WithRegexRules("HTTP exception 404")) 88 | .WithLocalSessionManager() 89 | .WithCors( 90 | // Origins, separated by comma without last slash 91 | "http://unosquare.github.io,http://run.plnkr.co", 92 | // Allowed headers 93 | "content-type, accept", 94 | // Allowed methods 95 | "post") 96 | .WithWebApi("/api", m => m 97 | .WithController()) 98 | .WithStaticFolder("/", Directory.GetCurrentDirectory(), true, m => m 99 | .WithContentCaching(true)) // Add static files after other modules to avoid conflicts 100 | .WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" }))); 101 | 102 | server.RunAsync(); 103 | } 104 | 105 | var browser = new System.Diagnostics.Process() 106 | { 107 | StartInfo = new System.Diagnostics.ProcessStartInfo(Constants.MetaMaskWebServerUrl + page) { UseShellExecute = true } 108 | }; 109 | browser.Start(); 110 | } 111 | 112 | private static void CloseServer() 113 | { 114 | server.Dispose(); 115 | server = null; 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnectClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Threading.Tasks; 5 | using System.Web; 6 | 7 | namespace LoopringSharp.WalletConnect 8 | { 9 | public class WalletConnectClient : LoopringSharp.Client 10 | { 11 | WalletConnectSecretClient _walletConnectClient; 12 | public WalletConnectClient(string apiUrl) : base(apiUrl, GetEthereumAddress()) 13 | { 14 | _walletConnectClient = new WalletConnectSecretClient(apiUrl); 15 | } 16 | 17 | /// 18 | /// Send some tokens to anyone else on L2 19 | /// 20 | /// The basic transaction details needed in order to actually do a transaction 21 | /// (Optional)And do you want the transaction to contain a reference. From loopring's perspective, this is just a text field 22 | /// (Optional)A user-defined id. It's similar to the memo field? Again the original documentation is not very clear 23 | /// (Optional)Not entirely sure. Official documentation says: field.UpdateAccountRequestV3.counterFactualInfo 24 | /// An object containing the status of the transfer at the end of the request 25 | /// Gets thrown when there's a problem getting info from the Loopring API endpoint 26 | public virtual OperationResult Transfer(TransferRequest request, string memo, string clientId, CounterFactualInfo counterFactualInfo = null) 27 | { 28 | return _walletConnectClient.Transfer(_apiKey, _loopringPrivateKey, _ethPrivateKey, request, memo, clientId, counterFactualInfo); 29 | } 30 | 31 | /// 32 | /// Send some tokens to anyone else on L2 33 | /// 34 | /// The loopring address that's doing the receiving 35 | /// What token is being sent 36 | /// And how much of that token are we sending 37 | /// In what token are we paying the fee 38 | /// (Optional)And do you want the transaction to contain a reference. From loopring's perspective, this is just a text field 39 | /// An object containing the status of the transfer at the end of the request 40 | public virtual OperationResult Transfer(string toAddress, string token, decimal value, string feeToken, string memo) 41 | { 42 | return _walletConnectClient.Transfer(_apiKey, _loopringPrivateKey, _ethPrivateKey, _accountId, _ethAddress, toAddress, token, value, feeToken, memo); 43 | } 44 | 45 | /// 46 | /// WARNING!!! This has a fee asociated with it. Make a OffchainFee request of type OffChainRequestType.UpdateAccount to see what the fee is. 47 | /// Updates the EDDSA key associated with the specified account, making the previous one invalid in the process. 48 | /// 49 | /// The token in which the fee should be paid for this operation 50 | /// Returns the hash and status of your requested operation 51 | public virtual OperationResult RequestNewL2PrivateKey(string feeToken) 52 | { 53 | return _walletConnectClient.UpdateAccount(_apiKey, _ethPrivateKey, _loopringPrivateKey, _accountId, feeToken, _ethAddress, ExchangeInfo().exchangeAddress); 54 | } 55 | 56 | private static (string secretKey, string ethAddress, string publicKeyX, string publicKeyY) GetEthereumAddress() 57 | { 58 | // TODO: THIS NEEDS REFACTORING INTO RETURNING ALL THAT INFO NOT JUST ETH ADDRESS 59 | 60 | string connectURi = WalletConnectServer.Connect(); 61 | Debug.WriteLine("Connection: " + connectURi); 62 | Console.WriteLine("WalletConnect CODE: " + connectURi); 63 | File.WriteAllText("walletconnect.html", 64 | Constants.WalletConnectHTML.Replace("|----|", $"https://api.qrserver.com/v1/create-qr-code/?data={HttpUtility.UrlEncode(connectURi)}!&size=400x400") 65 | .Replace("|--|--|", connectURi)); 66 | var browser = new System.Diagnostics.Process() 67 | { 68 | StartInfo = new System.Diagnostics.ProcessStartInfo(Directory.GetCurrentDirectory() + "/walletconnect.html") { UseShellExecute = true } 69 | }; 70 | browser.Start(); 71 | 72 | File.Delete("walletconnect.html"); 73 | browser.Kill(); 74 | 75 | return (null, null, null, null); 76 | //return WalletConnectServer.GetEthAddress(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Network/AESCipher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using WalletConnectSharp.Core.Models; 8 | using WalletConnectSharp.Core.Utils; 9 | 10 | namespace WalletConnectSharp.Core.Network 11 | { 12 | public class AESCipher : ICipher 13 | { 14 | public async Task EncryptWithKey(byte[] key, string message, Encoding encoding = null) 15 | { 16 | if (encoding == null) 17 | encoding = Encoding.UTF8; 18 | 19 | byte[] data = encoding.GetBytes(message); 20 | 21 | //Encrypt with AES/CBC/PKCS7Padding 22 | using (MemoryStream ms = new MemoryStream()) 23 | { 24 | using (AesManaged ciphor = new AesManaged()) 25 | { 26 | ciphor.Mode = CipherMode.CBC; 27 | ciphor.Padding = PaddingMode.PKCS7; 28 | ciphor.KeySize = 256; 29 | 30 | byte[] iv = ciphor.IV; 31 | 32 | using (CryptoStream cs = new CryptoStream(ms, ciphor.CreateEncryptor(key, iv), 33 | CryptoStreamMode.Write)) 34 | { 35 | await cs.WriteAsync(data, 0, data.Length); 36 | } 37 | 38 | byte[] encryptedContent = ms.ToArray(); 39 | 40 | using (HMACSHA256 hmac = new HMACSHA256(key)) 41 | { 42 | hmac.Initialize(); 43 | 44 | byte[] toSign = new byte[iv.Length + encryptedContent.Length]; 45 | 46 | //copy our 2 array into one 47 | Buffer.BlockCopy(encryptedContent, 0, toSign, 0,encryptedContent.Length); 48 | Buffer.BlockCopy(iv, 0, toSign, encryptedContent.Length, iv.Length); 49 | 50 | byte[] signature = hmac.ComputeHash(toSign); 51 | 52 | string ivHex = iv.ToHex(); 53 | string dataHex = encryptedContent.ToHex(); 54 | string hmacHex = signature.ToHex(); 55 | 56 | return new EncryptedPayload() 57 | { 58 | data = dataHex, 59 | hmac = hmacHex, 60 | iv = ivHex 61 | }; 62 | } 63 | } 64 | } 65 | } 66 | 67 | public async Task DecryptWithKey(byte[] key, EncryptedPayload encryptedData, Encoding encoding = null) 68 | { 69 | if (encoding == null) 70 | encoding = Encoding.UTF8; 71 | 72 | byte[] rawData = encryptedData.data.FromHex(); 73 | byte[] iv = encryptedData.iv.FromHex(); 74 | byte[] hmacReceived = encryptedData.hmac.FromHex(); 75 | 76 | using (HMACSHA256 hmac = new HMACSHA256(key)) 77 | { 78 | hmac.Initialize(); 79 | 80 | byte[] toSign = new byte[iv.Length + rawData.Length]; 81 | 82 | //copy our 2 array into one 83 | Buffer.BlockCopy(rawData, 0, toSign, 0,rawData.Length); 84 | Buffer.BlockCopy(iv, 0, toSign, rawData.Length, iv.Length); 85 | 86 | byte[] signature = hmac.ComputeHash(toSign); 87 | 88 | if (!signature.SequenceEqual(hmacReceived)) 89 | throw new InvalidDataException("HMAC Provided does not match expected"); //Ignore 90 | } 91 | 92 | using (AesManaged cryptor = new AesManaged()) 93 | { 94 | cryptor.Mode = CipherMode.CBC; 95 | cryptor.Padding = PaddingMode.PKCS7; 96 | cryptor.KeySize = 256; 97 | 98 | cryptor.IV = iv; 99 | cryptor.Key = key; 100 | 101 | ICryptoTransform decryptor = cryptor.CreateDecryptor(cryptor.Key, cryptor.IV); 102 | 103 | using (MemoryStream ms = new MemoryStream(rawData)) 104 | { 105 | using (MemoryStream sink = new MemoryStream()) 106 | { 107 | using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read)) 108 | { 109 | int read = 0; 110 | byte[] buffer = new byte[1024]; 111 | do 112 | { 113 | read = await cs.ReadAsync(buffer, 0, buffer.Length); 114 | 115 | if (read > 0) 116 | await sink.WriteAsync(buffer, 0, read); 117 | } while (read > 0); 118 | 119 | await cs.FlushAsync(); 120 | 121 | return encoding.GetString(sink.ToArray()); 122 | } 123 | } 124 | } 125 | } 126 | } 127 | } 128 | } -------------------------------------------------------------------------------- /LoopringAPI.UnitTests/ClientTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.IO; 5 | 6 | namespace LoopringSharp.UnitTests 7 | { 8 | [TestClass] 9 | public class ClientTests 10 | { 11 | public string url; 12 | public string privateKey; 13 | public ClientTests() 14 | { 15 | ApiKeys apiKeys = ReadConfigFile(false); 16 | url = apiKeys.apiUrl; 17 | privateKey = apiKeys.l1Pk; 18 | } 19 | 20 | [TestMethod] 21 | public void TestGetTradeSuccess() 22 | { 23 | //arrange 24 | Client client = new Client(url, privateKey); 25 | 26 | //act 27 | var result = client.GetTrades("LRC-ETH",20,new FillTypes[] {FillTypes.dex, FillTypes.amm }); 28 | 29 | //assert 30 | Assert.IsNotNull(result); 31 | Assert.AreEqual("LRC-ETH", result[0].Market); 32 | } 33 | 34 | [TestMethod] 35 | public void TestGetTradeMarketNotExists() 36 | { 37 | //arrange 38 | Client client = new Client(url, privateKey); 39 | 40 | //act 41 | var result = client.GetTrades("CPP-RCS"); 42 | 43 | Assert.IsNotNull(result); 44 | Assert.AreEqual(0, result.Count); 45 | } 46 | 47 | [TestMethod] 48 | public void TestCreateInfoSuccess() 49 | { 50 | //arrange 51 | Client client = new Client(url, privateKey); 52 | 53 | //act 54 | var result = client.CreateInfo(); 55 | 56 | //assert 57 | Assert.IsNotNull(result); 58 | Assert.IsTrue(result.Count > 0); 59 | } 60 | 61 | [TestMethod] 62 | public void TestUpdateInfoSuccess() 63 | { 64 | //arrange 65 | Client client = new Client(url, privateKey); 66 | 67 | //act 68 | var result = client.UpdateInfo(); 69 | 70 | //assert 71 | Assert.IsNotNull(result); 72 | Assert.IsTrue(result.Count > 0); 73 | } 74 | 75 | [TestMethod] 76 | public void GetDepositsSuccess() 77 | { 78 | //arrange 79 | Client client = new Client(url, privateKey); 80 | 81 | //act 82 | var result = client.GetDeposits(); 83 | 84 | //assert 85 | Assert.IsNotNull(result); 86 | Assert.IsTrue(result.Count > 0); 87 | } 88 | 89 | [TestMethod] 90 | public void GetWithdrawlsSuccess() 91 | { 92 | //arrange 93 | Client client = new Client(url, privateKey); 94 | 95 | //act 96 | var result = client.GetWithdrawls(); 97 | 98 | //assert 99 | Assert.IsNotNull(result); 100 | Assert.IsTrue(result.Count > 0); 101 | } 102 | 103 | [TestMethod] 104 | public void GetTransfersSuccess() 105 | { 106 | //arrange 107 | Client client = new Client(url, privateKey); 108 | 109 | //act 110 | var result = client.GetTransfers(); 111 | 112 | //assert 113 | Assert.IsNotNull(result); 114 | Assert.IsTrue(result.Count > 0); 115 | } 116 | 117 | [TestMethod] 118 | public void TestClassGeneration() 119 | { 120 | //arrange 121 | Client client = new Client(url.TrimEnd('/'), privateKey); 122 | Assert.IsTrue(client!=null); 123 | } 124 | 125 | static ApiKeys ReadConfigFile(bool prod) 126 | { 127 | ApiKeys result; 128 | string filename = "apiKeys.json"; 129 | if (prod) 130 | { 131 | filename = "apiKeysProd.json"; 132 | } 133 | 134 | if (!File.Exists(filename)) 135 | { 136 | result = new ApiKeys() 137 | { 138 | l1Pk = "", 139 | l2Pk = "", 140 | accountId = "", 141 | apiUrl = "", 142 | ethAddress = "" 143 | }; 144 | File.WriteAllText(filename, JsonConvert.SerializeObject(result, Formatting.Indented)); 145 | } 146 | result = JsonConvert.DeserializeObject(File.ReadAllText(filename)) ?? new ApiKeys(); 147 | 148 | if (string.IsNullOrWhiteSpace(result.l2Pk)) 149 | { 150 | Console.WriteLine("WARNING! You need to fill in the details in the appKeys.json file, otherwise this application will not work. FILE IS HERE: " + Directory.GetCurrentDirectory() + "\\" + filename); 151 | throw new Exception("WARNING! You need to fill in the details in the appKeys.json file, otherwise this application will not work. FILE IS HERE: " + Directory.GetCurrentDirectory() + "\\" + filename); 152 | } 153 | return result; 154 | } 155 | } 156 | public class ApiKeys 157 | { 158 | public string l1Pk { get; set; } 159 | public string l2Pk { get; set; } 160 | public string accountId { get; set; } 161 | public string ethAddress { get; set; } 162 | public string apiUrl { get; set; } 163 | } 164 | } -------------------------------------------------------------------------------- /LoopringSharp.DualInvestment.AzureFunction/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # Azure Functions localsettings file 5 | local.settings.json 6 | 7 | # User-specific files 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # DNX 47 | project.lock.json 48 | project.fragment.lock.json 49 | artifacts/ 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # NCrunch 117 | _NCrunch_* 118 | .*crunch*.local.xml 119 | nCrunchTemp_* 120 | 121 | # MightyMoose 122 | *.mm.* 123 | AutoTest.Net/ 124 | 125 | # Web workbench (sass) 126 | .sass-cache/ 127 | 128 | # Installshield output folder 129 | [Ee]xpress/ 130 | 131 | # DocProject is a documentation generator add-in 132 | DocProject/buildhelp/ 133 | DocProject/Help/*.HxT 134 | DocProject/Help/*.HxC 135 | DocProject/Help/*.hhc 136 | DocProject/Help/*.hhk 137 | DocProject/Help/*.hhp 138 | DocProject/Help/Html2 139 | DocProject/Help/html 140 | 141 | # Click-Once directory 142 | publish/ 143 | 144 | # Publish Web Output 145 | *.[Pp]ublish.xml 146 | *.azurePubxml 147 | # TODO: Comment the next line if you want to checkin your web deploy settings 148 | # but database connection strings (with potential passwords) will be unencrypted 149 | #*.pubxml 150 | *.publishproj 151 | 152 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 153 | # checkin your Azure Web App publish settings, but sensitive information contained 154 | # in these scripts will be unencrypted 155 | PublishScripts/ 156 | 157 | # NuGet Packages 158 | *.nupkg 159 | # The packages folder can be ignored because of Package Restore 160 | **/packages/* 161 | # except build/, which is used as an MSBuild target. 162 | !**/packages/build/ 163 | # Uncomment if necessary however generally it will be regenerated when needed 164 | #!**/packages/repositories.config 165 | # NuGet v3's project.json files produces more ignoreable files 166 | *.nuget.props 167 | *.nuget.targets 168 | 169 | # Microsoft Azure Build Output 170 | csx/ 171 | *.build.csdef 172 | 173 | # Microsoft Azure Emulator 174 | ecf/ 175 | rcf/ 176 | 177 | # Windows Store app package directories and files 178 | AppPackages/ 179 | BundleArtifacts/ 180 | Package.StoreAssociation.xml 181 | _pkginfo.txt 182 | 183 | # Visual Studio cache files 184 | # files ending in .cache can be ignored 185 | *.[Cc]ache 186 | # but keep track of directories ending in .cache 187 | !*.[Cc]ache/ 188 | 189 | # Others 190 | ClientBin/ 191 | ~$* 192 | *~ 193 | *.dbmdl 194 | *.dbproj.schemaview 195 | *.jfm 196 | *.pfx 197 | *.publishsettings 198 | node_modules/ 199 | orleans.codegen.cs 200 | 201 | # Since there are multiple workflows, uncomment next line to ignore bower_components 202 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 203 | #bower_components/ 204 | 205 | # RIA/Silverlight projects 206 | Generated_Code/ 207 | 208 | # Backup & report files from converting an old project file 209 | # to a newer Visual Studio version. Backup files are not needed, 210 | # because we have git ;-) 211 | _UpgradeReport_Files/ 212 | Backup*/ 213 | UpgradeLog*.XML 214 | UpgradeLog*.htm 215 | 216 | # SQL Server files 217 | *.mdf 218 | *.ldf 219 | 220 | # Business Intelligence projects 221 | *.rdl.data 222 | *.bim.layout 223 | *.bim_*.settings 224 | 225 | # Microsoft Fakes 226 | FakesAssemblies/ 227 | 228 | # GhostDoc plugin setting file 229 | *.GhostDoc.xml 230 | 231 | # Node.js Tools for Visual Studio 232 | .ntvs_analysis.dat 233 | 234 | # Visual Studio 6 build log 235 | *.plg 236 | 237 | # Visual Studio 6 workspace options file 238 | *.opt 239 | 240 | # Visual Studio LightSwitch build output 241 | **/*.HTMLClient/GeneratedArtifacts 242 | **/*.DesktopClient/GeneratedArtifacts 243 | **/*.DesktopClient/ModelManifest.xml 244 | **/*.Server/GeneratedArtifacts 245 | **/*.Server/ModelManifest.xml 246 | _Pvt_Extensions 247 | 248 | # Paket dependency manager 249 | .paket/paket.exe 250 | paket-files/ 251 | 252 | # FAKE - F# Make 253 | .fake/ 254 | 255 | # JetBrains Rider 256 | .idea/ 257 | *.sln.iml 258 | 259 | # CodeRush 260 | .cr/ 261 | 262 | # Python Tools for Visual Studio (PTVS) 263 | __pycache__/ 264 | *.pyc 265 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnect/Models/SavedSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace WalletConnectSharp.Core.Models 5 | { 6 | public class SavedSession 7 | { 8 | public string ClientID { get; } 9 | public string BridgeURL { get; } 10 | public string Key { get; } 11 | public byte[] KeyRaw { get; } 12 | public string PeerID { get; } 13 | public int NetworkID { get; } 14 | public string[] Accounts { get; } 15 | public int ChainID { get; } 16 | public ClientMeta DappMeta { get; } 17 | 18 | public ClientMeta WalletMeta { get; } 19 | 20 | public SavedSession(string clientID, string bridgeURL, string key, byte[] keyRaw, string peerID, int networkID, string[] accounts, int chainID, ClientMeta dappMeta, ClientMeta walletMeta) 21 | { 22 | ClientID = clientID; 23 | BridgeURL = bridgeURL; 24 | Key = key; 25 | KeyRaw = keyRaw; 26 | PeerID = peerID; 27 | NetworkID = networkID; 28 | Accounts = accounts; 29 | ChainID = chainID; 30 | DappMeta = dappMeta; 31 | WalletMeta = walletMeta; 32 | } 33 | 34 | private sealed class SavedSessionEqualityComparer : IEqualityComparer 35 | { 36 | public bool Equals(SavedSession x, SavedSession y) 37 | { 38 | if (ReferenceEquals(x, y)) return true; 39 | if (ReferenceEquals(x, null)) return false; 40 | if (ReferenceEquals(y, null)) return false; 41 | if (x.GetType() != y.GetType()) return false; 42 | return x.ClientID == y.ClientID && x.BridgeURL == y.BridgeURL && x.Key == y.Key && Equals(x.KeyRaw, y.KeyRaw) && x.PeerID == y.PeerID && x.NetworkID == y.NetworkID && Equals(x.Accounts, y.Accounts) && x.ChainID == y.ChainID && Equals(x.DappMeta, y.DappMeta) && Equals(x.WalletMeta, y.WalletMeta); 43 | } 44 | 45 | public int GetHashCode(SavedSession obj) 46 | { 47 | unchecked 48 | { 49 | var hashCode = (obj.ClientID != null ? obj.ClientID.GetHashCode() : 0); 50 | hashCode = (hashCode * 397) ^ (obj.BridgeURL != null ? obj.BridgeURL.GetHashCode() : 0); 51 | hashCode = (hashCode * 397) ^ (obj.Key != null ? obj.Key.GetHashCode() : 0); 52 | hashCode = (hashCode * 397) ^ (obj.KeyRaw != null ? obj.KeyRaw.GetHashCode() : 0); 53 | hashCode = (hashCode * 397) ^ (obj.PeerID != null ? obj.PeerID.GetHashCode() : 0); 54 | hashCode = (hashCode * 397) ^ obj.NetworkID; 55 | hashCode = (hashCode * 397) ^ (obj.Accounts != null ? obj.Accounts.GetHashCode() : 0); 56 | hashCode = (hashCode * 397) ^ obj.ChainID; 57 | hashCode = (hashCode * 397) ^ (obj.DappMeta != null ? obj.DappMeta.GetHashCode() : 0); 58 | hashCode = (hashCode * 397) ^ (obj.WalletMeta != null ? obj.WalletMeta.GetHashCode() : 0); 59 | return hashCode; 60 | } 61 | } 62 | } 63 | 64 | public static IEqualityComparer SavedSessionComparer { get; } = new SavedSessionEqualityComparer(); 65 | 66 | protected bool Equals(SavedSession other) 67 | { 68 | return ClientID == other.ClientID && BridgeURL == other.BridgeURL && Key == other.Key && Equals(KeyRaw, other.KeyRaw) && PeerID == other.PeerID && NetworkID == other.NetworkID && Equals(Accounts, other.Accounts) && ChainID == other.ChainID && Equals(DappMeta, other.DappMeta) && Equals(WalletMeta, other.WalletMeta); 69 | } 70 | 71 | public override bool Equals(object obj) 72 | { 73 | if (ReferenceEquals(null, obj)) return false; 74 | if (ReferenceEquals(this, obj)) return true; 75 | if (obj.GetType() != this.GetType()) return false; 76 | return Equals((SavedSession) obj); 77 | } 78 | 79 | public override int GetHashCode() 80 | { 81 | unchecked 82 | { 83 | var hashCode = (ClientID != null ? ClientID.GetHashCode() : 0); 84 | hashCode = (hashCode * 397) ^ (BridgeURL != null ? BridgeURL.GetHashCode() : 0); 85 | hashCode = (hashCode * 397) ^ (Key != null ? Key.GetHashCode() : 0); 86 | hashCode = (hashCode * 397) ^ (KeyRaw != null ? KeyRaw.GetHashCode() : 0); 87 | hashCode = (hashCode * 397) ^ (PeerID != null ? PeerID.GetHashCode() : 0); 88 | hashCode = (hashCode * 397) ^ NetworkID; 89 | hashCode = (hashCode * 397) ^ (Accounts != null ? Accounts.GetHashCode() : 0); 90 | hashCode = (hashCode * 397) ^ ChainID; 91 | hashCode = (hashCode * 397) ^ (DappMeta != null ? DappMeta.GetHashCode() : 0); 92 | hashCode = (hashCode * 397) ^ (WalletMeta != null ? WalletMeta.GetHashCode() : 0); 93 | return hashCode; 94 | } 95 | } 96 | 97 | public static bool operator ==(SavedSession session, SavedSession other) 98 | { 99 | bool isStatNull = object.ReferenceEquals(session, null); 100 | bool isOtherNull = object.ReferenceEquals(other, null); 101 | 102 | return !isOtherNull && !isStatNull && session.Equals(other); 103 | } 104 | 105 | public static bool operator !=(SavedSession session, SavedSession other) 106 | { 107 | bool isSessionNull = object.ReferenceEquals(session, null); 108 | bool isOtherNull = object.ReferenceEquals(other, null); 109 | 110 | return isOtherNull == isSessionNull && !isSessionNull ? !session.Equals(other) : isOtherNull != isSessionNull; 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /LoopringAPI.OneButtonPayExample/TransferForm.cs: -------------------------------------------------------------------------------- 1 | using LoopringSharp; 2 | 3 | namespace LoopringSharp.OneButtonPayExample 4 | { 5 | public partial class TransferForm : Form 6 | { 7 | public TransferForm() 8 | { 9 | InitializeComponent(); 10 | } 11 | 12 | MetaMask.MetamaskClient client; 13 | 14 | // When user selects a network to connect to 15 | private void cbEnvironment_SelectedIndexChanged(object sender, EventArgs e) 16 | { 17 | // Take their selection, remove the extra text leaving only the url, and send that to the LoopringSharp Client 18 | // Since only the URL was provided and no other info, the client will attempt to make contact with the users's MetaMask in order 19 | // To get the necesairy info 20 | // The url of the exchange you will be interacting with Which wallet connecrtion method are we using? 21 | client = new MetaMask.MetamaskClient(cbEnvironment.SelectedItem.ToString().Split(" | ")[1]); 22 | 23 | // Clear the textboxes in case this is a reload 24 | cbPaymentFeeToken.Items.Clear(); 25 | cbPaymentToken.Items.Clear(); 26 | 27 | // Change the connection lable to show which network we are connected to 28 | connectionStatus.Text = "Connected: " + cbEnvironment.SelectedItem.ToString(); 29 | 30 | // Use the LoopringSharp to get all the available tokens that can be transfered 31 | var tokenOptions = client.GetTokens(); 32 | // Get the tokens from above and add them as payment options 33 | cbPaymentToken.Items.AddRange(tokenOptions.Select(s => s.symbol).ToArray()); 34 | // Set the LRC token as the default option 35 | cbPaymentToken.SelectedIndex = 1; 36 | 37 | // Enable all the UI items in case they are disabled. 38 | cbPaymentToken.Enabled = true; 39 | tbPayeeAddress.Enabled = true; 40 | cbPaymentFeeToken.Enabled = true; 41 | nudPaymentAmmount.Enabled = true; 42 | btnMakePayment.Enabled = true; 43 | 44 | // Bring the form to the front; 45 | this.WindowState = FormWindowState.Minimized; 46 | this.Show(); 47 | this.WindowState = FormWindowState.Normal; 48 | this.Focus(); 49 | } 50 | 51 | private void cbPaymentToken_SelectedIndexChanged(object sender, EventArgs e) 52 | { 53 | // A different payment token was selected! 54 | if (cbPaymentFeeToken.Items.Count == 0) 55 | { 56 | // Use the LoopringSharp to get all the tokens that we're allowed to pay transaction fees in 57 | // Type of action you'll do // Token you'll be doing it in // The ammount for that token 58 | var feeTokens = client.OffchainFee(OffChainRequestType.Transfer, cbPaymentToken.SelectedItem.ToString(), nudPaymentAmmount.Value.ToString()); 59 | // Add those tokens to the payment token combobox 60 | cbPaymentFeeToken.Items.AddRange(feeTokens.fees.Select(s => s.token).ToArray()); 61 | // Select the first token as the default 62 | cbPaymentFeeToken.SelectedIndex = 0; 63 | } 64 | // Make another call to get the feel values for the transfer token 65 | SetTransferTokenFee(); 66 | } 67 | 68 | private void cbPaymentFeeToken_SelectedIndexChanged(object sender, EventArgs e) 69 | { 70 | SetTransferTokenFee(); 71 | } 72 | 73 | void SetTransferTokenFee() 74 | { 75 | // Get which item we've selected from the dropdown list 76 | var selectedItem = cbPaymentFeeToken.Items[cbPaymentFeeToken.SelectedIndex].ToString(); 77 | // Get the fee tokens agian from the API 78 | // Type of action you'll do // Token you'll be doing it in // The ammount for that token 79 | var feeTokens = client.OffchainFee(OffChainRequestType.Transfer, cbPaymentToken.SelectedItem.ToString(), nudPaymentAmmount.Value.ToString()); 80 | // For the token that the user has selected, display it's resepctive fee on the screen 81 | lbTransactionFee.Text = "Transfer Fee: " 82 | + feeTokens.fees.Where(w => w.token == selectedItem).FirstOrDefault().normalziedFee + " " 83 | + feeTokens.fees.Where(w => w.token == selectedItem).FirstOrDefault().token; 84 | } 85 | 86 | private void btnMakePayment_Click(object sender, EventArgs e) 87 | { 88 | // Request the transfer to be made, using the user's inputed details 89 | // Who you paying Which currency you are paying in How much you are paying Which currency you are paying the fee in Message attached to payment 90 | var result = client.Transfer(tbPayeeAddress.Text, cbPaymentToken.SelectedItem.ToString(), nudPaymentAmmount.Value, cbPaymentFeeToken.SelectedItem.ToString(), tbMemo.Text); 91 | 92 | // Endpoint not yet implemented 93 | //var status = client.Transfers().Result; 94 | 95 | //while(status.status != OrderStatus.processed) 96 | //{ 97 | // System.Threading.Thread.Sleep(100); 98 | //} 99 | 100 | // Bring the form to the front; 101 | this.WindowState = FormWindowState.Minimized; 102 | this.Show(); 103 | this.WindowState = FormWindowState.Normal; 104 | this.Focus(); 105 | MessageBox.Show("Thanks for the monye honey! I will use it to buy skittles!"); 106 | } 107 | 108 | private void label2_Click(object sender, EventArgs e) 109 | { 110 | 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /LoopringSharp.MetaMask/Constants.cs: -------------------------------------------------------------------------------- 1 | namespace LoopringSharp.MetaMask 2 | { 3 | public static class Constants 4 | { 5 | public static string MetaMaskWebServerUrl = "http://localhost:42069"; 6 | public static string MetaMaskAuthTemplate = @" 7 | 8 | 9 | Title of the document 10 | 11 | 12 | 13 | 14 |

|---------|

15 | 16 | 17 | 18 | "; 79 | public static string MetaMaskSignatureTemplate = @" 80 | 81 | 82 | Title of the document 83 | 84 | 85 | 86 | 87 |

|---------|

88 | 89 | 90 | 91 | "; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /__azurite_db_blob__.json: -------------------------------------------------------------------------------- 1 | {"filename":"/Users/justinpopa/Documents/Repos/LoopringSharp/__azurite_db_blob__.json","collections":[{"name":"$SERVICES_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{},"constraints":null,"uniqueNames":["accountName"],"transforms":{},"objType":"$SERVICES_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]},{"name":"$CONTAINERS_COLLECTION$","data":[{"accountName":"devstoreaccount1","name":"azure-webjobs-hosts","properties":{"etag":"\"0x1DB269AB7D9BAE0\"","lastModified":"2023-05-05T20:36:23.648Z","leaseStatus":"unlocked","leaseState":"available","hasImmutabilityPolicy":false,"hasLegalHold":false},"meta":{"revision":0,"created":1683318983649,"version":0},"$loki":1}],"idIndex":null,"binaryIndices":{"accountName":{"name":"accountName","dirty":false,"values":[0]},"name":{"name":"name","dirty":false,"values":[0]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$CONTAINERS_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":1,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]},{"name":"$BLOBS_COLLECTION$","data":[{"deleted":false,"accountName":"devstoreaccount1","containerName":"azure-webjobs-hosts","name":"locks/justinsmacbookair-1401864190/Host.Functions.dualinvestment.Listener","properties":{"creationTime":"2023-05-05T20:36:23.653Z","lastModified":"2023-05-05T20:36:23.653Z","etag":"\"0x200D6C6808A32A0\"","contentLength":0,"contentType":"application/octet-stream","contentMD5":{"type":"Buffer","data":[212,29,140,217,143,0,178,4,233,128,9,152,236,248,66,126]},"blobType":"BlockBlob","leaseStatus":"locked","leaseState":"leased","serverEncrypted":true,"accessTier":"Hot","accessTierInferred":true,"accessTierChangeTime":"2023-05-05T20:36:23.653Z","leaseDuration":"fixed"},"snapshot":"","isCommitted":true,"persistency":{"id":"bfecf779-9cef-4949-9054-9d8e3b269f5c","offset":0,"count":0},"meta":{"revision":260,"created":1683318983660,"version":0,"updated":1683360576894},"$loki":1,"leaseId":"d5e1d78a-ad82-435b-bc65-58ebacd799f7","leaseExpireTime":"2023-05-06T08:09:51.893Z","leaseDurationSeconds":15},{"deleted":false,"metadata":{"FunctionInstance":"0000000000000000000000001D985B33"},"accountName":"devstoreaccount1","containerName":"azure-webjobs-hosts","name":"locks/justinsmacbookair-1401864190/host","properties":{"creationTime":"2023-05-05T20:36:28.235Z","lastModified":"2023-05-06T08:07:30.580Z","etag":"\"0x22919B07C4FC2A0\"","contentLength":0,"contentType":"application/octet-stream","contentMD5":{"type":"Buffer","data":[212,29,140,217,143,0,178,4,233,128,9,152,236,248,66,126]},"blobType":"BlockBlob","leaseStatus":"locked","leaseState":"leased","serverEncrypted":true,"accessTier":"Hot","accessTierInferred":true,"accessTierChangeTime":"2023-05-05T20:36:28.235Z","leaseDuration":"fixed"},"snapshot":"","isCommitted":true,"persistency":{"id":"bfecf779-9cef-4949-9054-9d8e3b269f5c","offset":114,"count":0},"meta":{"revision":189,"created":1683318988241,"version":0,"updated":1683360450581},"$loki":3,"leaseId":"0000000000000000000000001D985B33","leaseExpireTime":"2023-05-06T08:07:45.509Z","leaseDurationSeconds":15},{"deleted":false,"accountName":"devstoreaccount1","containerName":"azure-webjobs-hosts","name":"timers/justinsmacbookair-1401864190/Host.Functions.dualinvestment/status","properties":{"creationTime":"2023-05-06T06:05:05.778Z","lastModified":"2023-05-06T06:05:05.778Z","etag":"\"0x24B7323C9B62220\"","contentLength":127,"contentType":"application/octet-stream","contentMD5":{"type":"Buffer","data":[179,179,81,161,226,186,234,82,237,1,240,206,253,159,41,74]},"blobType":"BlockBlob","leaseStatus":"unlocked","leaseState":"available","serverEncrypted":true,"accessTier":"Hot","accessTierInferred":true,"accessTierChangeTime":"2023-05-06T06:05:05.778Z"},"snapshot":"","isCommitted":true,"persistency":{"id":"64ef6ad9-91a6-4561-8f4b-cb67a0e0113b","offset":254,"count":127},"meta":{"revision":0,"created":1683353105783,"version":0},"$loki":8}],"idIndex":[1,3,8],"binaryIndices":{"accountName":{"name":"accountName","dirty":false,"values":[0,1,2]},"containerName":{"name":"containerName","dirty":false,"values":[0,1,2]},"name":{"name":"name","dirty":false,"values":[0,1,2]},"snapshot":{"name":"snapshot","dirty":false,"values":[0,1,2]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$BLOBS_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":8,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]},{"name":"$BLOCKS_COLLECTION$","data":[],"idIndex":null,"binaryIndices":{"accountName":{"name":"accountName","dirty":false,"values":[]},"containerName":{"name":"containerName","dirty":false,"values":[]},"blobName":{"name":"blobName","dirty":false,"values":[]},"name":{"name":"name","dirty":false,"values":[]}},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"$BLOCKS_COLLECTION$","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"disableFreeze":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[],"dirtyIds":[]}],"databaseVersion":1.5,"engineVersion":1.5,"autosave":true,"autosaveInterval":5000,"autosaveHandle":null,"throttledSaves":true,"options":{"autosave":true,"autosaveInterval":5000,"serializationMethod":"normal","destructureDelimiter":"$<\n"},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | 352 | LoopringSharp.DualInvestment.AzureFunction/AccountDetails.cs 353 | -------------------------------------------------------------------------------- /LoopringSharp.WalletConnect/WalletConnectSecretClient.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Linq; 3 | using System.Numerics; 4 | using System.Threading.Tasks; 5 | 6 | namespace LoopringSharp.WalletConnect 7 | { 8 | public class WalletConnectSecretClient : LoopringSharp.SecureClient 9 | { 10 | string _apiUrl; 11 | public WalletConnectSecretClient(string apiUrl) : base(apiUrl) 12 | { 13 | 14 | } 15 | 16 | /// 17 | /// Send some tokens to anyone else on L2 18 | /// 19 | /// Your Loopring API Key 20 | /// Loopring Private Key 21 | /// Ethereum Private Key 22 | /// The basic transaction details needed in order to actually do a transaction 23 | /// (Optional)And do you want the transaction to contain a reference. From loopring's perspective, this is just a text field 24 | /// (Optional)A user-defined id. It's similar to the memo field? Again the original documentation is not very clear 25 | /// (Optional)Not entirely sure. Official documentation says: field.UpdateAccountRequestV3.counterFactualInfo 26 | /// An object containing the status of the transfer at the end of the request 27 | /// Gets thrown when there's a problem getting info from the Loopring API endpoint 28 | public override OperationResult Transfer(string apiKey, string l2Pk, string l1Pk, TransferRequest request, string memo, string clientId, CounterFactualInfo counterFactualInfo) 29 | { 30 | if (string.IsNullOrWhiteSpace(apiKey)) 31 | throw new System.Exception("Transfer REQUIRES a valid Loopring wallet apiKey"); 32 | if (string.IsNullOrWhiteSpace(l2Pk)) 33 | throw new System.Exception("Transfer REQUIRES a valid Loopring Wallet Layer 2 Private key"); 34 | 35 | var account = GetAccountInfo(request.payerAddr); 36 | 37 | BigInteger[] inputs = { 38 | Utils.ParseHexUnsigned(request.exchange), 39 | (BigInteger)request.payerId, 40 | (BigInteger)request.payeeId, 41 | (BigInteger)request.token.tokenId, 42 | BigInteger.Parse(request.token.volume), 43 | (BigInteger)request.maxFee.tokenId, 44 | BigInteger.Parse(request.maxFee.volume), 45 | Utils.ParseHexUnsigned(request.payeeAddr), 46 | 0, 47 | 0, 48 | (BigInteger)request.validUnitl, 49 | (BigInteger)request.storageId 50 | }; 51 | var apiRequest = request.GetApiTransferRequest(memo, clientId, counterFactualInfo); 52 | apiRequest.eddsaSignature = LoopringSharp.EDDSAHelper.EDDSASign(inputs, l2Pk); 53 | 54 | var typedData = ECDSAHelper.GenerateTransferTypedData(ExchangeInfo().chainId, apiRequest); 55 | apiRequest.ecdsaSignature = WalletConnectServer.Sign(JsonConvert.SerializeObject(typedData.Item2), "eth_signTypedData_v4", request.payerAddr) + "02"; 56 | 57 | (string, string)[] headers = { (LoopringSharp.Constants.HttpHeaderAPIKeyName, apiKey), (LoopringSharp.Constants.HttpHeaderAPISigName, apiRequest.ecdsaSignature) }; 58 | var apiresult = JsonConvert.DeserializeObject( 59 | Utils.Http(_apiUrl + LoopringSharp.Constants.TransferUrl, null, headers, "post", JsonConvert.SerializeObject(apiRequest))); 60 | return new OperationResult(apiresult); 61 | } 62 | 63 | /// 64 | /// 65 | /// 66 | /// User's current eth private key 67 | /// User's current loopring private key 68 | /// A UpdateAccountRequest object containing all the needed information for this request 69 | /// (Optional)Not entirely sure. Official documentation says: field.UpdateAccountRequestV3.counterFactualInfo 70 | /// 71 | public virtual OperationResult UpdateAccount(string l2Pk, string l1Pk, UpdateAccountRequest req, CounterFactualInfo counterFactualInfo) 72 | { 73 | var apiRequest = req.GetUpdateEDDSARequest(counterFactualInfo); 74 | 75 | BigInteger[] inputs = { 76 | Utils.ParseHexUnsigned(apiRequest.exchange), 77 | (BigInteger)apiRequest.accountId, 78 | (BigInteger)apiRequest.maxFee.tokenId , 79 | BigInteger.Parse(apiRequest.maxFee.volume), 80 | Utils.ParseHexUnsigned(apiRequest.publicKey.x), 81 | Utils.ParseHexUnsigned(apiRequest.publicKey.y), 82 | (BigInteger)apiRequest.validUntil, 83 | (BigInteger)apiRequest.nonce 84 | }; 85 | 86 | apiRequest.eddsaSignature = LoopringSharp.EDDSAHelper.EDDSASign(inputs, l2Pk); 87 | 88 | var typedData = ECDSAHelper.GenerateAccountUpdateTypedData(ExchangeInfo().chainId, apiRequest); 89 | apiRequest.ecdsaSignature = WalletConnectServer.Sign(JsonConvert.SerializeObject(typedData.Item2), "eth_signTypedData_v4", req.owner).Result + "02"; 90 | 91 | (string, string)[] headers = { (LoopringSharp.Constants.HttpHeaderAPISigName, apiRequest.ecdsaSignature) }; 92 | var apiresult = JsonConvert.DeserializeObject( 93 | Utils.Http(_apiUrl + LoopringSharp.Constants.AccountUrl, null, headers, "post", JsonConvert.SerializeObject(apiRequest))); 94 | return new OperationResult(apiresult); 95 | } 96 | 97 | /// 98 | /// WARNING!!! This has a fee asociated with it. Make a OffchainFee request of type OffChainRequestType.UpdateAccount to see what the fee is. 99 | /// Updates the EDDSA key associated with the specified account, making the previous one invalid in the process. 100 | /// 101 | /// User's current API Key 102 | /// User's current eth private key 103 | /// User's current loopring private key 104 | /// User's account id 105 | /// The token in which the fee should be paid for this operation 106 | /// User's public wallet address 107 | /// Exchange's public address 108 | /// Returns the hash and status of your requested operation 109 | public virtual OperationResult UpdateAccount(string apiKey, string l1Pk, string l2Pk, int accountId, string feeToken, string ethPublicAddress, string exchangeAddress) 110 | { 111 | var newNonce = (GetAccountInfo(ethPublicAddress)).nonce; 112 | (string publicKeyX, string publicKeyY, string secretKey, string ethAddress) keys; 113 | 114 | keys = EDDSAHelper.EDDSASignWalletConnect(exchangeAddress, newNonce); 115 | l1Pk = WalletService.WalletConnect.ToString(); 116 | 117 | var feeamountresult = OffchainFee(apiKey, accountId, OffChainRequestType.UpdateAccount, feeToken, "0"); 118 | var feeamount = feeamountresult.fees.Where(w => w.token == feeToken).First().fee; 119 | 120 | UpdateAccountRequest req = new UpdateAccountRequest() 121 | { 122 | accountId = accountId, 123 | exchange = ExchangeInfo().exchangeAddress, 124 | maxFee = new Token() 125 | { 126 | tokenId = GetTokenId(feeToken), 127 | volume = feeamount 128 | }, 129 | nonce = newNonce, 130 | owner = ethPublicAddress, 131 | validUntil = 1700000000, 132 | PublicKeyX = keys.publicKeyX, 133 | PublicKeyY = keys.publicKeyY 134 | }; 135 | 136 | return UpdateAccount(l2Pk, l1Pk, req, null); 137 | } 138 | } 139 | } 140 | --------------------------------------------------------------------------------