DeFi using Acala and Laminar
Using Acala’s Mandala Network and Laminar’s Flow Exchange
7 min readAug 1, 2020
Acala
- Node: Run an Acala Network full-node on Mandala Testnet using Docker by following these two simple steps https://github.com/AcalaNetwork/Acala/wiki/4.-Maintainers. Another approach (not recommended) is to fork https://github.com/AcalaNetwork/Acala, clone your fork, fetching the latest version in branch ‘master’, installing submodules into orml/ folder, and build and run a Docker container based on the Docker image with the following commands.
git clone git@github.com:<YOUR_GITHUB_USERNAME/Acala.git
git remote add upstream https://github.com/AcalaNetwork/Acala
cd Acala
git pull --rebase upstream master
git submodule update --init --recursive
docker build --tag acala:latest .
docker images
docker run --detach --name acala-latest acala:latest
docker ps -a
docker exec -it acala-latest bash
/usr/local/bin/acala --dev --execution=native -lruntime=debug
- Accounts (Substrate-based): Created an account on the Acala Mandala Testnet chain by connecting to it at https://polkadot.js.org/apps/#/settings and creating and exporting an account at https://polkadot.js.org/apps/#/account. Use the same account for LaminarChain. Import the account into the Polkadot.js Extension and used it to connect to the Acala Mandala Testnet chain at https://apps.acala.network/.
- Accounts (Ethereum-based): Ethereum accounts may also be imported using MetaMask browser extension. Switch MetaMask to Kovan testnet. Load an account that has a Kovan Ether balance.
- Tokens (Substrate-based): Request ACA (to pay for fees) tokens for an account by running
!drip <MY_ACCOUNT_ADDRESS>
in the #acala-faucet channel in the Polkadot DeFI on Discord group https://discord.gg/Z4JtEmM
- Tokens (Ethereum-based): Obtain Kovan Testnet ETH from a faucet https://faucet.kovan.network/. Obtain Kovan Testnet Compound’s DAI ERC-20 tokens from https://app.compound.finance/ in the DAI deposit section by enabling Kovan Testnet ETH as collateral, borrowing DAI using that collateral, and then swapping them using Acala Network or Laminar (for Flow Network
F___
tokens). Note: This functionality is incomplete.
- Wallet (Cross-Chain/Mint renBTC) https://apps.acala.network/wallet: Acala tab: Used to view balances, transfer tokens between accounts, air dropped tokens (ACA, KAR), and view cross-chain transaction history. Account, transaction, and Acala Mandala Testnet chain details may also be viewed using Subscan https://acala-testnet.subscan.io.
- Wallet > Cross-Chain tab > [aUSD sub-tab] Used to transfer Acala’s stablecoin aUSD from the Acala Mandala Testnet chain to other chains on the Polkadot Network (e.g. LaminarChain). Click “Transfer” button calls and runs the logic of the
transfer
extrinsic of Acala’s Currencies runtime module, which is part of the ORML (Open Runtime Module Library) https://github.com/open-web3-stack/open-runtime-module-library/blob/c41cfebacc1342ae2e401f85affe48f65708da50/currencies/src/lib.rs#L148, which is a submodule of the Acala repository. Go to the Laminar Flow Exchange https://flow.laminar.one/dashboard, which is connected to the separate LaminarChain, connect the same account from Polkadot.js Extension, and verify that your account on the LaminarChain has the amount of aUSD (ACA Dollar) stablecoin that you transferred from the Acala Mandala Testnet chain.
- Wallet > Cross-Chain tab > [renBTC sub-tab] Used to mint renBTC (type of Bitcoin provided by Ren) using your XBTC (type of Bitcoin provided by the ChainX protocol) that may then be used as collateral on the Acala Network. It may be necessary to first Swap some tokens in exchange for XBTC using https://apps.acala.network/swap (e.g. aUSD to XBTC).
- Self Serviced Loan (Honzon/Loans) https://apps.acala.network/loan: Used to create a loan to borrow some Acala’s stablecoin aUSD in exchange for the locking/depositing collateral (e.g. DOT) at the current exchange rate. It is important to perform risk management and observe the Liquidation Price avoid borrowing more than your risk appetite to minimise the risk of being liquidated incase the value of your collateral decreases. Clicking the “Confirm” button calls and runs the logic of the
adjust_loan
extrinsic of Acala’s Honzon runtime module https://github.com/AcalaNetwork/Acala/blob/master/modules/honzon/src/lib.rs#L87 and theadjust_position
extrinsic of Acala’s Loans runtime module https://github.com/AcalaNetwork/Acala/blob/master/modules/loans/src/lib.rs#L148
- Swap (DeX) https://apps.acala.network/swap: Used to swap between currencies (e.g. swap aUSD to DOT). Clicking the “Swap” button calls
swapCurrencies
in Acala’s acala-dapp front-end repository, which calls and runs the logic of theswap_currency
extrinsic of the Acala’s DEX (Decentralised Exchange) runtime module https://github.com/AcalaNetwork/Acala/blob/master/modules/dex/src/lib.rs#L240
- Deposit & Earn (DeX) https://apps.acala.network/deposit: Used to deposit collateral in exchange for the liquidity of Acala’s stablecoin aUSD (e.g. deposit ACA in exchange for aUSD) that is transferrable to all chains of the Polkadot network. Clicking the “Deposit” button calls
addLiquidity
in acala-dapp, which calls theadd_liquidity
extrinsic of the Acala’s DEX runtime module https://github.com/AcalaNetwork/Acala/blob/master/modules/dex/src/lib.rs#L278
- Liquid DOT (Homa) https://apps.acala.network/homa: Used to stake DOT tokens in exchange for minting derivative L-DOT tokens at the current exchange rate using the Homa Protocol. Clicking the “Stake” button calls the
mint
extrinsic of Acala’s Homa runtime module https://github.com/AcalaNetwork/Acala/blob/master/modules/homa/src/lib.rs#L25 and thebond
extrinsic of Acala’s Staking Pool runtime module https://github.com/AcalaNetwork/Acala/blob/master/modules/staking_pool/src/lib.rs#L166
- Governance: Used to propose and vote on motions to change the Acala Mandala network protocol. Example: If a community member created a motion requesting users to be able to swap a token like aUSD for the same aUSD, the community could vote on whether to change the protocol to allow that. It would require the Acala Mandala network chain to be upgraded to incorporate Substrate’s Democracy runtime module https://github.com/paritytech/substrate/tree/master/frame/democracy
- Auctions: It will use the Auctions runtime module https://github.com/open-web3-stack/open-runtime-module-library/tree/c41cfebacc1342ae2e401f85affe48f65708da50/auction for opening auctions (active between specified block numbers) and allowing anyone to place bids on-chain and validate the bid at the end of the auction. Wiki: https://github.com/AcalaNetwork/Acala/wiki/6.-Auctions. Example: https://github.com/open-web3-stack/guardian/tree/master/packages/example-guardian
Laminar
- Node: LaminarChain node setup https://github.com/laminar-protocol/laminar-chain#building--running-laminarchain
- Accounts (Substrate-based): Use the same account address you created on Acala Mandala Testnet for the LaminarChain Testnet. The LaminarChain’s endpoint is https://github.com/laminar-protocol/flow-exchange/blob/master/src/services/Api.ts#L42. Import the account into the Polkadot.js Extension and used it to connect to the LaminarChain chain at https://flow.laminar.one/
- Tokens: Request LAMI (to pay for fees) tokens for an account by running
!drip <MY_ACCOUNT_ADDRESS>
in the #laminar-faucet channel in the Polkadot DeFI on Discord group https://discord.gg/Z4JtEmM - Dashboard https://flow.laminar.one/dashboard: Used to view LAMI token balance (used for fees), aUSD stablecoin balance that we transferred from the Acala Mandala network (provide cross-chain liquidity), and synthetic asset balances for FX (Foreign Exchange) trading. Click “Transfer” next to aUSD allows transfers back to the Acala Mandala Testnet network from the LaminarChain Testnet .
- Margin Trading https://flow.laminar.one/margin: Used for opening/closing margin trading positions on Contract for Differences (CFD) symbol pairs (e.g. ETHUSD) using a Liquidity Pool of a Liquidity Provider (e.g. Laminar).
- Margin Trading > Basic: Click “Fast Buy/Sell” to quickly Buy/Sell a leveraged (x2 — x20) position on a symbol pair.
- Margin Trading > Detailed: Alternatively click anywhere else on the row of a symbol pair to open a Trading View (e.g. https://flow.laminar.one/margin/0/AUDUSD) that displays a Price Chart, System Risk Parameters, Position/Order History, and Buy/Sell section.
- Swap (Synthetic Asset Trading) https://flow.laminar.one/swap: Used to swap between aUSD stablecoin and FX (Foreign Exchange) and commodities (e.g. Gold, Oil) synthetic assets (e.g. FXAU, which represents the XAU currency code for Gold ounces, or FAUD, which represents the AUD currency code for Australian Dollars) at the current exchange rate offered by a Liquidity Provider (e.g. Laminar), and vice versa. It uses obtains off-chain FX and commodities data for its different
CurrencyId
’s using Oracles for different Laminar Data Providers https://github.com/laminar-protocol/laminar-chain/blob/master/runtime/src/lib.rs#L597, by feeding values using Acala’s ORML Oracle runtime module https://github.com/open-web3-stack/open-runtime-module-library/blob/203ad9730c4118ca81900a4a26d9c5b65f870347/oracle/src/lib.rs#L152.
- Liquidity Provider > [Margin tab] https://flow.laminar.one/provider/margin: Used for risk management to show the safety of the margin level of different Liquidity Providers. It calls the
enp_and_ell
.extrinsic of the Margin Protocol runtime module of the LaminarChain https://github.com/laminar-protocol/laminar-chain/blob/master/modules/margin-protocol/src/lib.rs#L1513 to calculate the ENP (Equity to Net Position ratio) and ELL (Equity to Longest Leg ratio) of a Liquidity Provider’s liquidity pool https://github.com/laminar-protocol/laminar-chain#the-collateralized-margin-trading-protocol. It is based on the overall risk of margin traders that use the Margin Trading services to open long (Buy) or short (Sell) positions and borrow (leverage) from a Liquidity Pool with a risk exposure that may trigger a margin call and impact the safety of the Liquidity Pool if they did not reduce their risk (e.g. by depositing more aUSD or reducing their position before liquidation) and prevent their account balance being liquidated.
Acala Mandala Address: 5DHcRs9udMCKtEmJEABY2HpECyTHHxgLL85pFFzN72SatAoQ
References
- Mandala Festival Season 3 #MandalaFest3 https://github.com/AcalaNetwork/Acala/wiki/W.-Contribution-&-Rewards#mandala-festival-season-3-