Blockchain

Innovate DeFi with CosmWasm in Tgrade

Photo by Clark Tibbs on Unsplash

You may have been on one of our workshops to introduce you to writing smart contracts to deploy to CosmWasm, or curious about CosmWasm and writing smart contracts where you don’t have to worry about oscillating gas prices and the speed of the network?

The chances are that you are dreaming up the next big DeFi thing, Teppanyaki? Samosa? Pakora? or ??? Confio, the team behind CosmWasm, have testnet Coralnet running to let you try your ideas out.

You have tried out some of the samples, had a go at your own and are getting comfortable with the syntax, how to put a smart contract together, and becoming confident about deploying.

The next steps might be to look at some “oven ready” smart contracts in our github under the cosmwasm-plus directory that you can look at for inspiration or to base your new DeFi product on?

Photo by Mark Potterton on Unsplash

Inspiration to build DeFi

If you are stuck on what to build, you could try a version of an ERC1400 as a new security token or ERC2222 as a fund distribution contract to handle debt instruments cashflows? Can you find inspiration in the traditional markets?

How about a Contract for Difference (CFD)? How would this work in DeFi?

The key feature of the CFD is that the buyer does not need the full amount of capital to buy an asset, but is trading on the difference between the opening and the closing price of the contract.

For example Alice buys a CFD as she expects the price of DAI to go up against ETH, let’s say that 1 ETH buys 339 DAI and Alice expects this to 424 (an increase of 25%). Alice enters a contract to buy 100 ETH/DAI and if she is right and the price moves to 424, she would make (42,400–33,900) 8,500 DAI. If the price dropped to 275 then she would lose 6,400.

The strategy Alice is following is risky as it uses leverage, and this must be offset by margin or collateral to ensure that either Alice pays if the markets move against her or Bob pays if Alice is right.

How can we translate this into a smart contract? The challenge is to ensure that both parties will honour the contract in a trustless environment. If we ask both parties to lockup too much collateral it will not be too attractive for either side. The way to think of the leverage and margin is to look at the potential losses each party might incur and this would require both Bob and Alice to pledge the amount should the price change by a given percentage, say, 25% and there is a daily process which uses a reference price to determine the margin. There is a margin buffer of 15% so that if the price has moved towards the buffer then either Alice or Bob need to pledge further tokens to cover the agreement. If the party needing to pledge failed to do so then the contract is liquidated in preference to the other party.

⏭ The first step is that the contract is opened between Alice and Bob. Both Alice and Bob would put up the initial amount which is 25% of the nominal value of DAI, 8,475 to the contract.

⏭ There is a daily margin process where the price is obtained from an oracle and the amounts calculated. Let’s say the price has moved to 380, Bob is covered as it is below the 15% buffer.

⏭ In the event that the buffer is reached with the daily margin process, now the price is 400 and Bob needs to pledge further tokens to increase his margin. If Bob fails to do this then the contract is closed and Alice receives Bob’s margin of DAI 8,475 and her pledged tokens.

⏭ At the end of the contract the final price is sourced from the oracle and the difference is calculated and the payout is either to Alice or Bob depending on whether the price has gone above or below the initial price. In our example, if the price has gone to 300 the Bob is paid, if it goes to 400 then Alice is paid.

The CFD example is a rough outline but we hope this will inspire you to sketch out how a smart contract could work to model the CFD or to explore other potential DeFi products and be part of the innovative Tgrade chain

Photo by Robynne Hu on Unsplash

Confio’s plans for DeFi

We launch an incentivised testnet in Q4 2020, and Tgrade, our mainnet, launch in Q1/2021.

You have a couple of months to experiment and make sure your smart contracts are rock solid. You then deploy it to Tgrade which is running a CosmWasm engine and then tell the world about it.

What is our long term vision?

Our plans for Tgrade are to build out a DeFi platform that innovates and we have plans to develop the governance frameworks to enable self-sovereign DeFi markets to grow which are compliant with REGULATIONS.

Why do we think the future of DeFi is regulated? Simple, the regulators will not ignore DeFi forever, and secondly DeFi volumes are in the low billions, whereas the regulated markets volumes measure in thousands of trillions. A big barrier to regulated institutions in the blockchain space are the lack of regulations.

Need some help? Want to find out when our next workshops are?

The documentation is here

If you have questions https://docs.cosmwasm.com/chat

If you missed a workshop and want to watch again click here

Future Workshops → Follow #workshop channel at CosmWasm Discord

TgradeFinance

Author TgradeFinance

More posts by TgradeFinance

Leave a Reply