Is the native stablecoin cycles a good idea to implement DeFi on DFINITY?

blockpunk
ICP League
Published in
10 min readJul 21, 2021

On June 17th,we held the fourth developer community call to discuss the features of stable gas token cycles on DFINITY, and the ideas of building stable coins such as WTC (packaged transferable cycles) to build Dfinity’s DeFi ecosystem.

Highlights

  • DFINITY’s ecosystem is growing rapidly. According to data from ic.rocks, the network has expanded to 18 subnets, running over 1,100 containers.
  • Cycles is the only DFINITY’s underlying blockchain token, similar in architecture to ETH on Ethereum, used to pay for gas.
  • The decentralized governance system NNS contains a price prediction machine that reflects the price of ICP, thereby regulating the ICP/Cycles exchange ratio to maintain gas stability.
  • Cycles is stable in value relative to fiat and can be used as a stable underlying in DeFi,even in fundraising. However, it can only be transferred between smart contracts and users can trade Cycles using packaging such as WTC.
  • Open finance on DFINITY will combine the decentralization of DeFi with the user experience of CeFi. In terms of code design and user experience, we should learn more from CeFi.

Updates of DFINITY ecosystem

We recommend developers and the community use https://ic.rocks/ to keep up with the latest developments of DFINITY ecosystem.

DFINITY has expanded to 18 subnets in the past month since its launch, and the 18 subnets are currently producing blocks at a rate of one block per second. Over 1,000 smart contracts have been deployed on multiple subnets at the same time, access to contract and transactions have never been affected. This is the initial verification of the unlimited scaling capability, and will be intelligently and dynamically scaled according to the demand of the network in the future.

In the browser you can also see the amount of nodes in each subnet and the amount of contracts. of contracts running on them, and these numbers are growing fast.We should also note that although DFINITY’s subnets are architecturally peer-to-peer with no bus design, DFINITY’s subnets have different types: “Application” is the application layer subnet, on which the contracts deployed by developers run. “Verified Application” is also the application layer subnet. Verified Application” is also the application layer subnet, but here the gas for running smart contracts is greatly reduced by official subsidies, and contracts can be deployed through proposals and grant applications to this subnet; “System” is the System” is the system layer subnet of DFINITY, where the core components of the network such as ICP ledger contracts, NNS governance system, etc. are deployed.

You can view the smart contracts that have been deployed on the DFINITY network on https://ic.rocks/canisters. As DFINITY smart contracts can run directly on the frontend, you can directly click on the arrow in the “URL” section. It’s a crazy rabbit hole and you might find some surprises!

You can view the smart contracts that have been deployed on DFINITY network on https://ic.rocks/canisters. As DFINITY smart contracts can run directly on the front-end, you can directly click on the arrow in the “URL” section to It’s a crazy rabbit hole and find some surprises!

In addition, you can check below everything that happens in DFINITY, transaction logs, governance proposals, deployment of contracts and neuron status.

cycles

There are two key tokens in the network, ICP and cycles, we have introduced that the ICP token is a smart contract deployed on the system subnet as a ledger. ETH acts as the underlying token driving smart contracts in Ethereum network, ICP is clearly more like an ERC-20 token, while cycles are more like the role played like ETH (but it is stable). Cycles are recorded at the bottom of the blockchain and are used to drive smart contracts on chain in architectural, while ICP is a governance token and used to generate cycles, so we can interpret cycles as the only native token.

Cycles are used to pay the cost of running applications in the Internet computer, including bandwidth, storage, computing, etc. The amount of cycles used is related to the cost of running WebAssembly instructions for smart contracts.

Why do we need cycles?

In blockchains like Ethereum, units of gas are often specified the quantity is measured by the amount of CPU computation cycles required for an instruction (You can also find the word cycles in many other systems), which is then converted to the number of underlying tokens based on the number of units of gas used versus the price of gas, less a certain amount of native assets such as ETH. Gas is just an intermediate parameter in this calculation.

However, DFINITY adds a token-swap relationship, gas is not only a measurable unit of operation, but also the underlying token called cycles. The ICP token as the upper tier can be used to swap cycles.

This is to achieve a stable gas fee: ICP can be destroyed to swap cycles, only need to adjust the exchange ratio between cycles and ICP in time to ensure the stability of the gas price, and a gas corresponds to a fixed amount of CPU cycles, the cost of each instruction remains stable, so the fee of the contract running on DFINITY is stable, will not change when the network is congested (at this time to start dynamic expansion) and ICP prices changes.

When using the Ethereum network, the high fees prevent many users from using, and also make it difficult for applications with weak financial attributes to survive, which is actually the imperfection of the underlying design, and DFINITY’s solution solves the above problems.

How to adjust the exchange ratio?

There is a class of proposal called “Exchange Rate” in DFINITY’s decentralized governance system NNS, which the neurons submit the fiat (XDR) price of ICPs from exchanges to the network every ten minutes.

The proposal can only be approved after it has been submitted and voted by other neurons. The system then will adjust the ICP/cycles exchange rate based on the ICP/XDR price, ensuring that one trillion (1T for short) cycles is worth the same as one XDR, which is a special drawing right under the International Monetary Fund, 1 XDR = $1.4.

Participating in NNS governance requires a pledge of ICPs. If a proposal is initiated but not passed, the initiator‘s ICPs will be deducted, and the community will be rewarded with a pledge of ICPs if they vote for the correct option and eventually pass. Thus, “Exchange Rate” can be thought of as a price prediction machine, with ICPs as collateral security.

How to use Cycles?

In the official page nns.ic0.app , you can select “CANISTERS” to redeem cycles using ICP on the graphical page. Users can also manage cycles using the official cycles wallet. Each project will automatically create a wallet to manage cycles. The cycles wallet can convert ICPs to cycles, charge cycles to containers, or send cycles between containers, and can also manage permissions on the cycles wallet for containers

Each instance of an actor under DFINITY, i.e. the software container, has a balance of cycles, which can be queried using balance(). Different instances can send or receive cycles via messages. Use add(amount) to send cycles, as running the send function requires cycles, so here we need some additional number of cycles.

The recipient needs to send the accepted message accept(amount) to receive the cycles after an instance sending cycels, then they can set the amount of cycles to be accepted or rejected, and will call refunded() at the end of the send request to return the remaining cycles to the sender.

available() indicates the amount of cycles available, which includes the amount of cycles accepted so far in both balance and accepted.

As the underlying native token, cycles can only be held by smart contracts, and cycles are not available to the users addresses with 64-bit strings. Only smart contracts can create cycles wallets to send, receive, and use cycles. One smart contract can recharge cycles for another smart contract, and developers use a smart contract that implements a dedicated cycles management contract to provide gas to multiple smart contracts.

Implement stablecoin WTC with contract wrapped cycles

We can learn from WETH to wrap the underlying native token cycles into a standard fungible token via smart contracts, such as the Wrapped Trillion Cycles (wrapped trillion cycles) implemented by wtctoken.com, the value of a trillion cycels is equal to 1 XDR which is $1.40.

The WTC contract accepts ICP tokens from the users and sends back the wrapped WTC tokens via the ICP/cycles rate, where the user can exchange a native stable coin on the chain; it can also accept cycels from other contracts and return them directly to WTC, where the contract can store or sell its unused cycles as WTCs can be stored or sold.

Cycle‘s inspiration

WTC inspires developers a lot, encouraging them to make better use of cycles, the native stable coin among smart contracts. Cycles will be the main medium for transactions between smart contracts, such as charging a fee for calling the interface, creating an exchange channel between smart contracts with tokens deployed, or even helping token contracts to implement meta-transactions, i.e. paying for formalities with their own tokens. The packaging of cycles results in on-chain transactions.

The wrapped cycles can produce native stable coin, which can be used directly in DeFi such as lending and fundraising, and in the design of DEX and AMM, the wrapped cycles can be considered as stable coins. There is a simple DEX model where wrapped cycles are used as relays, and all tokens and wrapped cycels are used to create separate AMMs, and transactions of different tokens are executed through the relays of cycles, similar to the earliest design of Bancor.

To make the idea be true, there is a large demand and supply of cycles, better liquidity, more ecologies running in the DFINITY network, and more use of ICPs for cycles. Cycles will then act as qualified.

Not only DeFi, cycles can also be used for payment between smart contracts. For example, if we create a container for users in a decentralized chat software such as opeanchat to store personal information and chat logs, we can add a method to the personal data container to call the desensitized personal data, and other dapps calling this interface will need to pay additional cycles. This actually creates a data mart and uses cycles to pay for the interface call, and the cycles can be sold as wrapped cycels.

This helps infrastructures make profit without even issuing their own tokens, just charging for the interface calls, which is an unprecedented capability.

Defi implementation on DFINITY

DeFi is the foundation and the crown of the decentralized ecosystem, and so far the part we value most.

We have talked a lot about atomicity, composability, and security in previous sessions. In the last session we mentioned that there is a big difference between DFINITY and other blockchains like Ethereum on atomicity. We need to focus more on the atomicity of consistent data rather than the atomicity of the transaction operation itself.

Therefore, when implementing DeFi, the design of DFINITY will appear very differently from Ethereum, instead it is more like CeFi. We can even directly migrate some CeFi that are already running on the Internet to DFINITY, like order book exchanges. And since the DFINITY network itself is highly decentralized, we can get both the great user experience and performance of CeFi, and the decentralization and composability of DeFi.

New open financial services will be born on DFINITY, such as the possibility to abandon operations such as apporve when implementing an exchange and use the way to top up in CEX and then perform high performance order book transactions in the contract. While retaining the excellent user experience of centralization, no one can control your assets.

Build an exchange

On a centralized Internet architecture, someone has implemented an exchange with the actor programming model. It is easy to migrate applications from centralized world to DFINITY. The decentralization feature makes it convenient for exchange developers to implement such exchanges.

We can solve the atomicity problem by using container layering. We can put all interactions into a container that handles transactions, and put the database that needs to ensure consistency into another container, while adding features such as transaction management. For the other applications calling the interface, the whole process still presents atomicity.

The decentralized architecture of DFINITY also brings a lot of simplification in development.In the past, when using a centralized server to develop CEX, there was a possibility of failure when writing data to the database, which required a lot of extra management. In DFINITY, the storage in the smart contract is memory level, once the message is submitted, there is no possibility of physical write failure, the data must be stored persistently. This is a characteristic of decentralized systems, because there is a consensus in the network that there will be no partial write failures and partial write successes.

Therefore, it is rather easier to implement an exchange using an actor on DFINITY than on a centralized architecture. This greatly reduces the complexity.

We expect to see more open finance fusing CeFi and DeFi running on DFINIT in the future.

--

--

blockpunk
ICP League

Co-founder of ICP League & Ourea Group, obsessed with Social Tokens, DAO & NFT.