Skip to content

Commit

Permalink
Merge pull request #51 from massalabs/learn-asc
Browse files Browse the repository at this point in the history
adds Learn-ASC section
  • Loading branch information
Adrien LF authored Jun 26, 2023
2 parents cca26fb + 2cf40f4 commit efc97ba
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/learn/architecture/basic-concepts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ These use cases exemplify the transformative potential of Autonomous Smart Contr
processes across various industries.

:::info
Learn more about Autonomous Smart Contracts [here](/docu-dev/docs/learn/autonomous-sc).
Learn more about Autonomous Smart Contracts [here](/docu-dev/docs/learn/asc/autonomous-smart-contract).
:::

## Storage costs
Expand Down
Binary file added docs/learn/asc/autonomous-sc.webp
Binary file not shown.
39 changes: 39 additions & 0 deletions docs/learn/asc/autonomous-smart-contract.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
id: autonomous-smart-contract
sidebar_label: Introduction
---

# Autonomous Smart Contracts

## Introduction

Massa Blockchain introduces a groundbreaking feature known as Autonomous Smart Contracts.
These smart contracts possess a unique capability: they can independently determine their own activation without any external actors.
By the end of this section, you will gain a fundamental understanding of:

- The limitations of current smart contracts on existing blockchains
- How Massa Blockchain overcomes these limitations by empowering pre-programmed execution
- The inner workings and mechanisms behind autonomous smart contracts
- The use cases enables by autonomous smart contracts

## Challenges with Existing Smart Contracts

In today's blockchain landscape, smart contracts face limitations when it comes to automating operations without external triggers.
While automation lies at the heart of numerous industries, particularly in the realm of modern finance, only
certain actions within decentralized finance (DeFi) protocols, such as lending and arbitration, are automated.
However, even these actions are typically executed by off-chain bots. The absence of external calls prevents smart contracts,
as they exist in current public blockchains, from performing automated operations.

Many decentralized protocols rely on recurrent triggers to ensure their smooth operation.
For example, in decentralized lending protocols, borrowers lock crypto assets as collateral when obtaining loans.
If the value of the collateralized asset drops below a specified threshold, the borrower's position becomes under-collateralized
and requires immediate action. To maintain the integrity of the protocol, such positions must be liquidated. Currently,
these liquidations are executed by organizations or individuals who run bots, often on centralized cloud services.

## The Need for a Reliable Automation Mechanism

The reliance on recurrent triggers is a prevalent requirement across numerous applications.
Consequently, significant time and effort have been invested in developing more dependable networks of bots to ensure
the timely execution of transactions.
However, since these solutions operate off-chain, there is no guarantee that the execution will be triggered effectively.
In cases where bots fail to execute transactions, decentralized protocols face risks, as do the applications built on top of them.
36 changes: 36 additions & 0 deletions docs/learn/asc/on-blockchain.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
id: massa-asc
sidebar_label: Autonomous Smart Contracts
---
# Massa's Autonomous Smart Contracts

Massa's Autonomous Smart Contracts address the challenges of reliability, sophistication, and centralization that plague dApps
seeking to offer automated smart-contract execution on behalf of their users.
These innovative smart contracts introduce the ability to self-wake, granting them the power to autonomously perform arbitrary operations.
For instance, they can be programmed to trigger specific calls when predefined exchange rate targets are met in a decentralized exchange.

## The Mechanism within Massa Network

![Autonomous SCs](./autonomous-sc.webp)

Standard operations are sent to an *operation pool* and are executed when they are included in a block. The cost of
execution is paid by the sender of the operation when the operation is executed.

Autonomous smart contracts works by emitting messages which will schedule the execution. Those messages are emitted
by smart contracts, through operations sent by users or by autonomous operations. Messages are then stored in an
*asynchronous pool*. Contrary to standard operations, the gas required by autonomous smart contracts is paid upfront.

The asynchronous pool is deterministic by nature as it’s filled with messages that ultimately come from operations
included in blocks, which are processed by every node of the network. The pool has a finite size and messages
are removed based on the fees and after a certain number of slots if they were not executed.

As for normal operations, the number of autonomous operations that can be executed is limited, through a maximum amount
of gas. In practice, it’s possible that your message isn’t executed at the slot that you want, but in a later slot,
when there is enough space to include your message. If you want your message to be included as soon as possible, the
fees needs to be higher than other messages (just like standard operations).

Messages are ordered using the following formula:

$(Reverse(Ratio(msg.fee, max(msg.max_gas,1))), emission\_slot, emission\_index),$

where $emission\_index$ is an index that differentiate multiple messages created in the same slot.
42 changes: 42 additions & 0 deletions docs/learn/asc/use-cases.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
id: use-cases
sidebar_label: Use-cases
---
# Use-cases & Applications

Autonomous smart contracts offers a wide range of compelling use-cases that were either impossible, too costly, or risky to do with benchmark are met.

Here are some of the best use cases for autonomous smart contracts:

1. **Decentralized Finance (DeFi)**: Autonomous smart contracts can revolutionize DeFi applications by enabling automated and self-executing actions. Some notable use cases include:
- Automated liquidations: Smart contracts can automatically trigger the liquidation of under-collateralized positions in lending protocols when predetermined thresholds are breached.
- Yield farming strategies: Contracts can autonomously perform yield farming strategies, automatically swapping and reinvesting tokens based on predefined conditions.
- Dynamic portfolio rebalancing: Smart contracts can automatically adjust portfolio allocations based on market conditions, ensuring desired asset ratios are maintained.

2. **Supply Chain Management**: Autonomous smart contracts have the potential to streamline supply chain processes by automating specific actions triggered by predefined conditions. Key use cases include:
- Automatic inventory management: Contracts can initiate purchase orders or trigger production when inventory levels reach predefined thresholds, ensuring optimal stock levels.
- Quality control and compliance: Smart contracts can autonomously perform quality checks and audits based on predefined criteria, ensuring compliance with standards and regulations.

3. **Insurance Claims**: Autonomous smart contracts can revolutionize the insurance industry by automating claims processes. Notable use cases include:
- Instant claims settlement: Contracts can automatically trigger claim payments when specific conditions, such as verified damage or loss, are met, accelerating the claims settlement process.
- Parametric insurance: Smart contracts can leverage external data feeds, such as weather or seismic information, to autonomously determine and process claims without human intervention.

4. **Gaming and NFTs**: Autonomous smart contracts can bring enhanced functionality and interactivity, and cost-reduction in on-chain execution, to gaming and non-fungible token (NFT) platforms. Key use cases include:
- Dynamic NFTs: Contracts can imbue NFTs with evolving characteristics or abilities based on predefined conditions, creating captivating and unique gaming experiences.
- Automated auctions: Contracts can autonomously initiate and manage auctions for rare items, with bidding and settlement executed automatically when predetermined criteria are met.

5. **Decentralized Autonomous Organizations (DAOs)**: Autonomous smart contracts are instrumental in enabling self-governance and decision-making within DAOs. Notable use cases include:
- Voting and governance: Contracts can autonomously trigger voting processes based on predefined conditions, empowering token holders to participate in important decision-making. There are various applications for this: from voting in local communities to democratic processes in corporate governance.
- Automated fund management: Smart contracts can autonomously allocate funds, distribute dividends, or trigger investments based on predefined rules and performance metrics.

6. **Real Estate Transactions**: Smart contracts can streamline various aspects of real estate transactions, increasing efficiency and reducing the need for intermediaries. Key use cases include:
- Escrow and payment automation: Contracts can securely hold funds in escrow and automatically release them when specific conditions, such as successful property transfer or completion of milestones, are met.
- Streamlined rental agreements: Contracts can automate rental payments, manage security deposits, and enforce the terms and conditions stipulated in the agreement.

These examples illustrate just a few of the many compelling use cases for autonomous smart contracts.
The self wake-up functionality empowers automated processes, reduces reliance on intermediaries, and enhances efficiency and
transparency across diverse industries.

## Going further

If you want to go further and start coding your own autonomous smart contract, head to the [Build section](/docs/build/home).
8 changes: 0 additions & 8 deletions docs/learn/autonomous-sc.mdx

This file was deleted.

2 changes: 1 addition & 1 deletion docs/tutorial/trading-bot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sidebar_label: Trading bot

# Autonomous Trading Bot

This video is a great example of how to use Massa's [autonomous smart contracts](/docs/learn/autonomous-sc) to build a trading bot that will automatically buy and sell tokens on the [Dusa](https://dusa.io) decentralized exchange (DEX).
This video is a great example of how to use Massa's [autonomous smart contracts](/docs/learn/asc/autonomous-smart-contract) to build a trading bot that will automatically buy and sell tokens on the [Dusa](https://dusa.io) decentralized exchange (DEX).

This tutorial covers all the tooling required to build a decentralized application on the Massa blockchain, from the smart contract to the front-end interface, making it a great way to get started with Massa.

Expand Down
20 changes: 20 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ const sidebars = {
type: "doc",
id: "learn/architecture/storage-costs",
},
{
type: "html",
value: "<hr/>",
},
{
type: "html",
value: "<span class='menu__link'><b><small>Autonomous Smart Contract</small></b></span>"
},
{
type: "doc",
id: "learn/asc/autonomous-smart-contract",
},
{
type: "doc",
id: "learn/asc/massa-asc",
},
{
type: "doc",
id: "learn/asc/use-cases",
},
],
tutorialSidebar: [
{
Expand Down

0 comments on commit efc97ba

Please sign in to comment.