Loopring Dev Docs
  • Introduction
  • Endpoints
  • SDK
    • SDK Guides
    • Test Mock Data
      • Mock Account
      • Mock provider
      • Mock ERC20 Token Map
      • Mock AMM MAP
      • Mock EIP712 Typed Data
      • Mock Generate eddsaKey
  • Glossary
  • 🗳️Loopring Account
    • Introduction
    • SDK Guides
      • Setup a Loopring Account
      • Unlock Account (Login)
    • API References
      • Get Account info
        • Sample code
      • Update EddsaKey
        • Sample code
      • Get apiKey
        • Sample code
      • Update apiKey
        • Sample code
  • 🎨CounterFactual NFT
    • Introduction
      • Compute NFT Address API
      • When to deploy counterfactual NFT contracts?
    • SDK Guides
      • Deposit NFT
      • Create Collection
      • Mint Counterfactual NFT
      • Transfer NFT
      • Deploy NFT
      • Withdraw NFT
      • Trade NFT
        • Validate NFT Order
      • Meta & IPFS
    • API References
      • NFT Collection
        • Create collection
          • Sample code
        • Edit collection
          • Sample code
        • Delete collection
          • Sample code
        • List owned collections
          • Sample code
        • List user's NFTs under one collection
          • Sample code
        • List user's NFT balances group by Collection ID
          • Sample code
        • List all NFTs of a collection
          • Sample code
        • Get collection by Collection ID
          • Sample code
        • Get collections by contract address
          • Sample code
      • Get NFT Assets
        • Sample code
      • Get NFT Balances
        • Sample code
      • Mint NFT
        • Sample code
      • Transfer NFT
        • Sample code
      • Validate NFT Order
        • Sample code
      • Trade NFT
        • Sample code
      • Deploy NFT TokenAddress
        • Sample code
      • Withdraw NFT
        • Sample code
      • Get NFT Transactions
        • Sample code
      • Get NFT Trade History
        • Sample code
      • Get AvailableBroker
        • Sample code
      • Get NFT Info
        • Sample code
      • Get NFT Data
        • Sample code
      • Get NFT Holders
        • Sample code
  • 🪙ERC20 Tokens
    • Introduction
    • SDK Guides
      • Transfer ERC20
      • Withdraw ERC20
      • Deposit ERC20
      • Order ERC20
    • API References
      • Get Assets
        • Sample code
      • Transfer
        • Sample code
      • Submit Order
        • Sample code
      • Cancel Order
        • Sample code
      • Withdraw
        • Sample code
      • Get Transactions
        • Sample code
      • Get Orders
        • Sample code
      • Get Trade History
        • Sample code
  • 🔬Resources
    • Advanced
      • UpdateAccount with custom seed
      • Pay payee updateAccount fee
      • Common error and solutions
      • Submit erc20 order
    • Common Info
      • Get relayer current time
        • Sample code
      • Get exchange info
        • Sample code
      • Get token info
        • Sample code
      • Get markets info
        • Sample code
    • Error codes
    • Fees
      • GET ERC20 Offchain Fee
        • Sample code
      • GET ERC20 Order Fee
        • Sample code
      • GET NFT Offchain Fee
        • Sample code
      • GET NFT Order Fee
        • Sample code
      • SDK Fees
    • Layer 2 block info
      • Get pending transactions
    • Request signing
      • Special API Request Signatures
      • Off-chain Request Signatures
      • Extra ECDSA authentic in header
    • Signature
      • ECDSA signature
        • ECDSA key generation
        • ECDSA sign
        • ECDSA verify signature
      • EdDSA signature
        • EdDSA key generation
        • EdDSA sign
        • EdDSA verify signature
      • SDK Signature
        • Mock Signature
    • Smart Contracts
    • Storage Id
      • Sample code
    • WebSocket
      • Account Notification
      • Order Notification
      • Orderbook Notification
      • Trade Notification
      • Ticker Notification
      • Candlestick Notification
      • AMM Pool Snapshot Notification
      • Block Generation Notification
    • Loopring Smart Wallet
      • Signature and verification
Powered by GitBook
On this page
  • How to use tradeCost
  • 1. Query api/v3/exchange/tokens to get the dust value of orderAmounts for both LRC and ETH
  • 2. Query api/v3/user/orderUserRateAmount to get the tradeCost value.
  • 3. Set maxAllowBips = 50% as the maxFeeBips can't exceed 50%
  • 4. Set slippage as the slippage value user configured in UI (for example 0.1%)
  • 5. Caculate minCostLRC and minCostETH as below
  • 6. Caculate the cost by considering slippage
  • 7. Cacluate the minimum quantity user has to set
  • 8. Caculate the previous minimum token amount per calling api/v3/user/orderUserRateAmount (existing logic)
  • 9.Caculate the new maxFeeBips and start trading

Was this helpful?

  1. Resources
  2. Advanced

Submit erc20 order

How to use tradeCost

To support small quantity trading, we introduce an additional concept "tradeCost", which is the minimum gas fee when a trade transaction is uplink to Ethereum.

Let's take LRC-ETH trading as an example.

Below are the steps:

1. Query api/v3/exchange/tokens to get the dust value of orderAmounts for both LRC and ETH

The dust value is the minimum value to pass Relayer check. Any amount less than "dust" can't be traded. In this case, we will get both minTOkenLRC and minTokenETH after getting dust value. If user wants to convert LRC to ETH, the set LRC amount can't be less than minTokenLRC and the converted ETH amount can't be less than minTokenETH.

2. Query api/v3/user/orderUserRateAmount to get the tradeCost value.

The parameters to call this interface are "accountId" and "market=LRC-ETH". In this example, we will get two tradeCost values for LRC and ETH as tradeCostLRC and tradeCostETH.

3. Set maxAllowBips = 50% as the maxFeeBips can't exceed 50%

4. Set slippage as the slippage value user configured in UI (for example 0.1%)

5. Caculate minCostLRC and minCostETH as below

minCostLRC = max(minTokenLRC, tradeCostLRC/maxAllowBips)
minCostETH = max(minTokenETH, tradeCostETH/maxAllowBips)

6. Caculate the cost by considering slippage

minCostLRCSlip = minCostLRC/(1-slippage)
minCostETHSlip = minCostETH/(1-slippage)

7. Cacluate the minimum quantity user has to set

tradeCostSellLRC = max(tradeCostSellLRC, minTokenLRC) * 1.1
tradeCostSellETH = max(tradeCostSellETH, minTokenETH) * 1.1

Here we add additonally 10% tolerance.

8. Caculate the previous minimum token amount per calling api/v3/user/orderUserRateAmount (existing logic)

This is the threshold to distinguish small quantity trading and normal trading We will get two values (configSellLRC and configSellETH) which are used for previous trading quantity limit (Per USD 100) caculation

9.Caculate the new maxFeeBips and start trading

Let's take LRC->ETH as the example User inputs the amount of LRC to convert, amount = sellLRC

if sellLRC >= configSellLRC then 
	// Normal trading case, stay with previous logic
	maxFeeBips=63 (the default value for maxFeeBips)
	Trade 
else if sellLRC < tradeCostSellLRC then 
	// Really too small to support
	Prompt user the amount is too small to support
	Exit
else 
	// This is what we call as small quantity 
	costRate = Ceil(tradeCostETH/minbuyETH) 
	maxFeeBips = max(costRate, takerRate)
	Trade 
End If 
PreviousCommon error and solutionsNextCommon Info

Last updated 2 years ago

Was this helpful?

🔬