Testing Laminar Flow Synthetic Assets & Margin Trading Protocols

Ruitao Su
Laminar
Published in
10 min readNov 11, 2019

The Laminar Flow synthetic asset, margin trading, and money market protocols are now deployed on Ethereum testnet and ready for you to experiment with. Launch of the Laminar Flow protocols on Ethereum will mark our first step of bridging on-and-off chain liquidity and users.

The road ahead will include building a Flowchain based on Substrate to enable high-performance trading for the masses and connecting with the Polkadot network to enable cross-chain communications. Our Ethereum implementation will primarily serve as a value gateway, allowing us to leverage the functionality and contribute liquidity to the DeFi ecosystem there. The two will be integrated to leverage the best of both worlds, providing a better trading experience, bringing more liquidity on-chain, and empowering more open finance applications.

We will be showcasing our protocols and trading platform at the 2019 Singapore Fintech Festival next week. Come visit us at booth 1K14 Nov 11–15 at Singapore Expo.

You are welcome to review our code, ask questions and provide feedback.

Key Features

The Laminar Flow Protocols on testnet is focused on delivering the following features:

  1. You can trade long and short EURUSD, USDJPY, XAUUSD, and APPLUSD pairs
  2. You can mint synthetic assets including Euro (fEUR), JPY (fJPY), Gold (fXAU), and Apple Stock (fAAPL) with DAI
  3. You can deposit these assets to earn interests
  4. You can become a liquidity provider and set up your spread and rules trustlessly

Each asset has its live price feed from selected sources, and each liquidity pool (set up by a liquidity provider) would have its own spread, supported margin pairs and leverages.

On Kovan initial deployment, the following margin pairs are available to trade:

  • Long and short 10x EURUSD
  • Long and short 20x USDJPY
  • Long and short 20x XAUUSD
  • Long and short 5x APPLUSD

The Flow Exchange Web App

We have built a web application so that you can test the functionalities of the protocols. This is a work in progress that will improve significantly as we progress. Please kindly excuse bugs, and provide feedback to help us improve.

Check out the Flow Exchange DApp

Synthetic Asset exchange sneak peek

Margin Trading sneak peek

GraphQL

Developers can build applications on top of the Laminar Flow Protocols. Participants like Liquidity Providers and Liquidators can also build queries and bots to optimize their performances. We have built the Laminar Flow Protocol Subgraph for you to query the synthetic assets, margin positions, liquidity pools, and other useful information.

The Source Code

Here is a collection of Solidity source code that includes:

  • The Synthetic Asset contracts
  • The Flow Token contract
  • The Margin Trading contracts
  • The Money Market contract
  • The Liquidity Pool contracts
  • The Price Oracle contracts

Find the source code report and documentation below to learn the specifics and start building on top of it

The Contracts on Kovan

Here is a list of addresses of deployed contracts outlined above. We will continue to develop and improve the protocols, and new contracts would be deployed as we progress. You can find the latest deployment here.

Synthetic Asset Protocol contract

Flow Token contracts

Margin Trading contract

Margin Trading Pair/Position contracts

Money Market contracts

Price Oracle contract

Liquidity Pool contracts

External contracts

Get Started with Laminar Flow

To start using and interacting with the above app and contracts, you will need to get Kovan test ETH and DAI tokens. Follow this guide to use Ethereum testnet for Laminar Flow Protocols before proceeding.

Contract Walkthrough Guide

The following examples will guide you through using the Laminar Flow contracts to mint and redeem Euro synthetic asset — fEUR, deposit fEUR to earn interest and conduct margin trades for EUR with 10x leverage. We will use Etherscan and Remix together with your Metamask extension to interact with the contracts.

Set up to use the Synthetic Asset contract

The synthetic asset contract is the management contract for minting fTokens, redeeming DAI, depositing fTokens to earn interest, etc.

1. Approve Synthetic Asset Protocol contract to move DAI

  • Set up Remix to approve, refer to the Set up Remix section in the testnet setup guide.
  • Expand the approve function
  • spender as Synthetic Asset contract address 0x117A85ebadBd933b576c6c2cfc6B160E380BC13d
  • amount = 2000000000000000000000000 as 2,000,000 DAI. You can approve a large amount that you don’t have to approve for every interaction.
  • Click the Transact button, and confirm the transaction on your Metamask. See example transaction here

2. Go to the Contract — Write Contract section of the Synthetic Asset contract on Etherscan.

3. Click the Connect to web3 button, essentially connecting to your Metamask. Ensure your Metamask is connected to Kovan testnet.

Mint Synthetic EUR — fEUR with DAI

The process of minting $100 worth of fEUR requires 10% additional collateral by default to counter price fluctuation and ensure stability. Each liquidity pool can set a higher ratio for additional security.

When a user deposits $100, the additional $10 will be put up by the liquidity pool, which is managed by the contracts automatically. If the price of EUR goes up, the liquidity pool may lose a portion of the $10 collateral, see more details here. The pools are willing to take the risks for the spread they will earn at each trade, and for their hedging strategies to make the business case.

  1. Assume that you have followed the above instruction and is on the write contract tab of the Synthetic asset contract.
  2. Use the mint function
  • token as fEUR address = 0x99D46D56b4f17BeFbE95673161aBDa45a0c29bf8
  • pool as chosen liquidity pool 1 = 0x8b205c597602ebf442857D4714d996B343fFa20c
  • baseTokenAmount as how much DAI would like to deposit to generate fEUR = 200000000000000000000 as 200 DAI

3. Click the Write button, and confirm the transaction on your Metamask. See example transaction here

4. Result: In the Event Logs, you can see the price at the time of minting from the first event PriceUpdated, with the exchange rate at 1.1049 and the last event Minted showing 180.47 fEUR minted.

Note: the actual price for buying/selling fTokens needs to add/substrate the spread from the chosen liquidity pool.

Return fEUR to redeem DAI

Regardless of how you obtain the fEUR (either you’ve minted it, or bought it from an exchange), you can redeem its DAI collateral via the synthetic asset protocol contract. This essentially reduces the supply of fEUR.

  1. Assume that you have followed the above instruction and is on the write contract tab of the Synthetic asset contract
  2. Use the redeem function
  • token as fEUR address = 0x99D46D56b4f17BeFbE95673161aBDa45a0c29bf8
  • pool as chosen liquidity pool 1 = 0x8b205c597602ebf442857D4714d996B343fFa20c
  • flowTokenAmount as how much fEUR you would like to return to redeem DAI = 20000000000000000000 as 20 fEUR

3. Click the Write button, and confirm the transaction on your Metamask. See example transaction here

4. Result: In the Event Logs, you can see the first event PriceUpdated with the exchange rate at 1.105, and the last event Redeemed with 22.0337 DAI returned to your account

Deposit fEUR to earn interest

The Synthetic Asset contract is connected to a Money Market contract behind the scenes, to manage the funds in the liquidity pool and in collateral. The money market would deposit a portion of the funds into the selected money market (with Compound being the default one for this version) to earn interest, which further improves liquidity. This facility is also open to individual fToken holders to make a deposit and earn interests.

  1. Assume that you have followed the above instruction and is on the write contract tab of the Synthetic asset contract.
  2. Use the deposit function
  • token as fEUR address = 0x99D46D56b4f17BeFbE95673161aBDa45a0c29bf8
  • flowTokenAmount as how much fEUR you would like to deposit = 50000000000000000000 as 50 fEUR

3. Click the Write button, and confirm the transaction on your Metamask. See example transaction here

4. Result: the DAI collateral for your 50 fEUR is now earning interest in money market

Withdraw fEUR and pocket earnings

If you withdraw immediately after deposit, you may not earn any interest.

  1. Assume that you have followed the above instruction and is on the write contract tab of the Synthetic asset contract.
  2. Use the withdraw function
  • token as fEUR address = 0x99D46D56b4f17BeFbE95673161aBDa45a0c29bf8
  • flowTokenAmount as how much fEUR you would like to withdraw = 50000000000000000000 as 50 fEUR

4. Click the Write button, and confirm the transaction on your Metamask. See example transaction here

5. Result: 50 fEUR is returned to your address, plus tiny bit of interest in 0.0003089 DAI.

Set up to use the Margin Trading Protocol contract

The margin trading contract is the management contact for open and closing margin positions, etc.

1. Approve Margin Trading Protocol contract to move DAI

  • Set up Remix to approve, refer to the Set up Remix section in the testnet setup guide.
  • Expand the approve function
  • spender as Margin Trading contract address 0x813fE903Ff23481F078fe9784d41a54E2F689f9B
  • amount = 20000000000000000000000000 as 20,000,000 DAI. You can approve a large amount so that you don’t have to approve for every interaction.
  • Click the Transact button, and Confirm the transaction on your Metamask. See example transaction here

2. Go to the Contract — Write Contract section of the Margin Trading contract on Etherscan.

3. Click the Connect to web3 button, essentially connecting to your Metamask. Ensure your Metamask is connected to Kovan testnet.

Trade 10x Long EURUSD

To open a $100 10x long EURUSD position, the user put in $100, and the liquidity pool put in the equivalent amount of $100. This essentially gives the cover for price fluctuation of 10% (1/leverage). Either side could win or lose that margin amount, see more details here.

  1. Assume that you have followed the above instruction and is on the write contract tab of the Margin Trading contract.
  2. Use the openPosition function
  • pair as l10USDEUR address = 0xf2E9Cdf8E75870bf8D804d0DF03f1D524aa9978E
  • pool as chosen liquidity pool 1 = 0x8b205c597602ebf442857D4714d996B343fFa20c
  • baseTokenAmount as the amount to put into the trade = 100000000000000000000 as 100 DAI (1 DAI as reserved liquidation fee + 99 DAI for the trade).

3. Click the Write button, and confirm the transaction on your Metamask. See example transaction here

4. Result: see the Event Logs on Etherscan, in the last event OpenPosition, see data in Num forms

  • positionId = 0, baseTokenAmount, openPrice = 1.1085156, and closeSpread = 0.3%. The opening price, close spread coupled with the current price can be used for calculating potential profit/loss.

Close a Margin Position

  1. Assume that you have followed the above instruction and is on the write contract tab of the Margin Trading contract.
  2. Use the closePosition function
  • pair as l10USDEUR address = 0xf2E9Cdf8E75870bf8D804d0DF03f1D524aa9978E
  • positionId = 0

3. Click the Write button, and confirm the transaction on your Metamask.
See example transaction here

4. Result: see the last event ClosePosition in the Event Logs on Etherscan, the data fields in Num are

  • positionId, price = 1.1014856 (lower than the open price, hence I lost a few bucks), ownerAmount = 93.7164 as the amount returned to the user, liquidityPoolAmount = 106.27 as the amount returned to the pool. The loss of the user is the gain of the liquidity pool and vice versa.

This concludes the walkthrough of synthetic asset and margin trading interactions with the protocols. We will introduce how to deploy your own liquidity pool and other features of the protocols in the following posts. Stay tuned.

What’s Next

We will be undergoing both financial and security audits, that more details and reports will be released as we progress. Ethereum mainnet Alpha is planned for Q1 2020.

Meanwhile, we have already started designing and developing the Flowchain as a specialized high-performance trading chain using Substrate within the Polkadot ecosystem. More updates will be available in a couple of weeks.

Get Updates from Laminar

Official Website: https://laminar.one
Twitter: https://twitter.com/LaminarProtocol
LinkedIn:https://www.linkedin.com/company/laminar-protocols

About Laminar

Laminar is a financial institute backed decentralized finance protocol company. It aims to create an open finance platform that will provide better access to trading instruments, and enable developers to build more open financial services. Laminar’s Flow Protocols bring both synthetic assets and margin trading on the blockchain. It helps to solve the challenges of opaque pricing and price manipulation in the current financial markets, bridges on- and off-chain parties, and ultimately boosts on-chain trading liquidity, exposure, and variety.

--

--