Skip to content

Commit

Permalink
Consolidate (#2135)
Browse files Browse the repository at this point in the history
* removed duplicated page

* removed duplicate

* fix: links

* moved article to blogpost
  • Loading branch information
gagdiez authored Jul 11, 2024
1 parent d5bb002 commit 56c60bf
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
---
id: use-cases
title: Use cases for Chain Signatures
sidebar_label: Use cases
authors: [bucanero]
slug: chain-signatures-use-cases
tags: [docusaurus, updates]
hide_table_of_contents: true
---


*Chain signatures enable you to implement multichain and cross-chain workflows in a simple way. Lets take a look at a few possible use cases*

Chain signatures enable you to implement multichain and cross-chain workflows in a simple way.
Take a look at a few possible use cases:
<!-- truncate -->

---

## Trade Blockchain assets without transactions

Expand Down
6 changes: 6 additions & 0 deletions blog/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ thisisjoshford:
title: DevX PM
url: https://github.com/thisisjoshford
image_url: https://github.com/thisisjoshford.png

bucanero:
name: Damian
title: Docs Maintainer
url: https://github.com/bucanero
image_url: https://github.com/bucanero.png
12 changes: 0 additions & 12 deletions docs/1.concepts/abstraction/chain-signatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ This unlocks the next level of blockchain interoperability by giving ownership o
![chain-signatures](/docs/assets/welcome-pages/chain-signatures-overview.png)
_Diagram of a chain signature in NEAR_

:::info Looking for code?
To get started using Chain Signatures in your project see **[Create a Chain Signature](../../2.build/1.chain-abstraction/chain-signatures.md)**.
:::

:::caution
This technology is currently in `alpha` and should only be used in a `testnet` environment.
:::
Expand Down Expand Up @@ -50,10 +46,6 @@ It is important to note that this allows us to discover the **public address** o
In practice, the external address is deterministically derived using the NEAR address (`example.near`), the path (`ethereum-1`) and the MPC service's public key
:::

:::info
See [**Create a Chain Signature - how the derivation is implemented**](../../2.build/1.chain-abstraction/chain-signatures.md#1-deriving-the-foreign-address) for an example implementation
:::

<hr class="subsection" />

### Multichain Smart Contract
Expand All @@ -80,10 +72,6 @@ NEAR smart contracts are currently unable to halt execution and await the comple

</details>

:::info
See [**Create a Chain Signature - requesting the signature**](../../2.build/1.chain-abstraction/chain-signatures.md#3-requesting-the-signature) for an example implementation
:::

<hr class="subsection" />

### Multi-Party Computation Service
Expand Down
27 changes: 20 additions & 7 deletions docs/1.concepts/abstraction/meta-tx.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
---
id: meta-transactions
title: Meta Transactions
sidebar_label: NEP-366
---

# Meta Transactions

[NEP-366](https://github.com/near/NEPs/pull/366) introduced the concept of meta
transactions to Near Protocol. This feature allows users to execute transactions
on NEAR without owning any gas or tokens. In order to enable this, users
construct and sign transactions off-chain. A third party (the relayer) is used
to cover the fees of submitting and executing the transaction.

---

## Overview

![Flow chart of meta
transactions](https://raw.githubusercontent.com/near/NEPs/003e589e6aba24fc70dd91c9cf7ef0007ca50735/neps/assets/nep-0366/NEP-DelegateAction.png)
_Credits for the diagram go to the NEP authors Alexander Fadeev and Egor
Uleyskiy._


The graphic shows an example use case for meta transactions. Alice owns an
amount of the fungible token `$FT`. She wants to transfer some to John. To do
that, she needs to call `ft_transfer("john", 10)` on an account named `FT`.
Expand All @@ -43,12 +43,11 @@ receipt is forwarded to the account from `Alice`, which will unpacked the
etc. If all checks are successful, a new action receipt with the inner actions
as body is sent to `FT`. There, the `ft_transfer` call finally executes.

---

## Relayer

Meta transactions only work with a [relayer](relayers.md). This is an application layer
concept, implemented off-chain. Think of it as a server that accepts a
`SignedDelegateAction`, does some checks on them and eventually forwards it
inside a transaction to the blockchain network.
Meta transactions only work with a [relayer](relayers.md), an off-chain service. Think of it as a server that accepts a `SignedDelegateAction`, does some checks on them and eventually forwards it inside a transaction to the network.

A relayer may choose to offer their service for free but that's not going to be
financially viable long-term. But they could easily have the user pay using
Expand All @@ -73,6 +72,8 @@ without compensation if Alice somehow reduces her $FT balance in just the right
moment. Some level of trust between the relayer and its user is therefore
required.

---

## Limitations

### Single receiver
Expand All @@ -81,19 +82,25 @@ A meta transaction, like a normal transaction, can only have one receiver. It's
possible to chain additional receipts afterwards. But crucially, there is no
atomicity guarantee and no roll-back mechanism.

<hr class="subsection" />

### Accounts must be initialized

Any transaction, including meta transactions, must use NONCEs to avoid replay
attacks. The NONCE must be chosen by Alice and compared to a NONCE stored on
chain. This NONCE is stored on the access key information that gets initialized
when creating an account.

---

## Constraints on the actions inside a meta transaction

A transaction is only allowed to contain one single delegate action. Nested
delegate actions are disallowed and so are delegate actions next to each other
in the same receipt.

---

## Gas costs for meta transactions

Meta transactions challenge the traditional ways of charging gas for actions.
Expand All @@ -118,6 +125,8 @@ consequence is that the implicit costs paid at the relayer's shard are
the delegate action. This might be surprising but hopefully with this
explanation it makes sense now!

---

## Gas refunds in meta transactions

Gas refund receipts work exactly like for normal transaction. At every step, the
Expand All @@ -127,6 +136,8 @@ remaining gas is also refunded at the original purchasing price. The gas refunds
go to the signer of the original transaction, in this case the relayer. This is
only fair, since the relayer also paid for it.

---

## Balance refunds in meta transactions

Unlike gas refunds, the protocol sends balance refunds to the predecessor
Expand All @@ -146,6 +157,8 @@ something relayer implementations must be aware of since there is a financial
incentive for Alice to submit meta transactions that have high balances attached
but will fail on Bob's shard.

---

## Function access keys in meta transactions

Function access keys can limit the allowance, the receiving contract, and the
Expand Down
6 changes: 3 additions & 3 deletions docs/1.concepts/protocol/account-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: NEAR Accounts
sidebar_label: Overview
---

Users participate in the NEAR ecosystem through their NEAR accounts. These accounts are identified by a [unique address](./account-id.md), can optionally hold a [smart contract](./smart-contract.md), and are controlled through [Access Keys](./access-keys.md).
Users participate in the NEAR ecosystem through their NEAR accounts. These accounts are identified by a [unique address](./account-id.md), can optionally hold a [smart contract](../../2.build/2.smart-contracts/what-is.md), and are controlled through [Access Keys](./access-keys.md).

By signing [transactions](./transactions.md) with their account, users can:

Expand Down Expand Up @@ -32,8 +32,8 @@ NEAR implements two types of accounts IDs: **named accounts** such as `alice.nea
#### [Permissions Through Access Keys](access-keys.md)
NEAR accounts can have multiple [keys](access-keys.md), each with their own set of permissions. This allows to easily swap keys if one gets compromised, and to use keys as authorization tokens for third-parties.

#### [Simple to Develop Smart Contracts](smart-contract.md)
NEAR accounts can optionally hold a simple program, known as a [smart contract](smart-contract.md). In NEAR, developers can create smart contracts using languages such as Javascript or Rust.
#### [Simple to Develop Smart Contracts](../../2.build/2.smart-contracts/what-is.md)
NEAR accounts can optionally hold a simple program, known as a [smart contract](../../2.build/2.smart-contracts/what-is.md). In NEAR, developers can create smart contracts using languages such as Javascript or Rust.

---

Expand Down
2 changes: 1 addition & 1 deletion docs/1.concepts/protocol/gas.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The cost of calling a function will depend on how complex the function is, but w
:::

:::tip Deploying a Contract**
Note that this covers the cost of uploading and writing bytes to storage, but does **not** cover the cost of [holding these bytes in storage](./smart-contract.md#contracts-storage)
Note that this covers the gas cost of uploading and writing bytes to storage, but does **not** cover the cost of holding them in storage (which is `1Ⓝ ~ 100kb`).
:::

<details className="info">
Expand Down
57 changes: 0 additions & 57 deletions docs/1.concepts/protocol/smart-contract.md

This file was deleted.

6 changes: 1 addition & 5 deletions docs/2.build/1.chain-abstraction/chain-signatures.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: chain-signatures
title: Chain Signatures
title: Implementing Chain Signatures
---

import Tabs from '@theme/Tabs';
Expand All @@ -15,8 +15,6 @@ This unlocks the next level of blockchain interoperability by giving ownership o

This guide will take you through a step by step process for creating a Chain Signature.

⭐️ For a deep dive into the concepts of Chain Signatures see [What are Chain Signatures?](/concepts/abstraction/chain-signatures)

⭐️ For complete examples of a NEAR account performing transactions in other chains:

- [CLI script](https://github.com/mattlockyer/mpc-script)
Expand All @@ -25,8 +23,6 @@ This guide will take you through a step by step process for creating a Chain Sig

:::



---

## Create a Chain Signature
Expand Down
40 changes: 35 additions & 5 deletions docs/2.build/2.smart-contracts/what-is.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ Smart contracts are pieces of **executable code** that live in a NEAR account. T

![img](/docs/assets/welcome-pages/contracts-landing.png)

Developers can choose between using Javascript or Rust to write smart contracts in NEAR. Indistinctly from the language chosen, the contract will be compiled into WebAssembly, from which point it can be deployed and executed on the NEAR platform.

<details>

<summary> New to Smart Contract Development? </summary>

Do not worry if you don't know how smart-contract blockchains work. As a developer, it is sufficient to understand that NEAR smart-contracts:
1. Have **limited** computational resources.
2. Interact with other contracts in an **asynchronous** way.
3. Deal with **real money**, for which security must be a top concern.

:::info HTTP Requests and Smart Contracts

Smart contracts **cannot perform HTTP requests**, meaning they can't fetch data from outside the NEAR network.

:::
</details>

---

Expand All @@ -32,6 +34,34 @@ Storing 100kb costs 1Ⓝ, so deploying a contract generally costs only a few $NE

---

## What can they do?

Smart contracts have **complete control over the account**, and thus can perform **any action on its behalf**. For example, contracts can:
- Transfer $NEAR Tokens
- Call methods on other contracts
- Create new accounts and deploy contracts on them
- Update their own code

Besides, smart contracts can store data in the account's storage. This allows contract's to create almost any type of application, from simple games to complex financial systems.

:::danger What contracts cannot do
- Smart contracts cannot **access the internet**, so they cannot make HTTP requests or access external data
- Smart contracts cannot **execute automatically**, they need to be called by an external account
:::

---

## What are they used for?
Smart contracts are useful to create **decentralized applications**. Some traditional examples include:
- [Decentralized Autonomous Organizations](https://dev.near.org/nearcatalog.near/widget/Index?cat=dao), where users create and vote proposals
- [Marketplaces](https://dev.near.org/nearcatalog.near/widget/Index?cat=marketplaces), where users create and commercialize digital art pieces
- [Decentralized exchanges](https://dev.near.org/nearcatalog.near/widget/Index?cat=exchanges), where users can trade different currencies
- [And many more...](https://dev.near.org/nearcatalog.near/widget/Index)

For instance, you can easily create a crowdfunding contract that accepts $NEAR. If the goal is met in time, the creator can claim the funds. Otherwise, the backers are refunded.

---

## Development flow

Just like any piece of software, smart contracts have a development flow - starting with its creation and ending with monitoring it, all of which we cover in our documentation.
Expand Down
2 changes: 0 additions & 2 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const sidebar = {
items: [
"concepts/protocol/account-id",
"concepts/protocol/access-keys",
"concepts/protocol/smartcontract",
]
},
{
Expand Down Expand Up @@ -91,7 +90,6 @@ const sidebar = {
{
"Chain Signatures": [
"concepts/abstraction/chain-signatures",
"concepts/abstraction/signatures/use-cases",
'build/chain-abstraction/chain-signatures',
'build/chain-abstraction/nft-chain-keys',
]
Expand Down
4 changes: 2 additions & 2 deletions website/src/css/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ h4 {
}

article {
margin: 2rem 1.5rem 2rem 3rem;
margin: 2rem 2rem 2rem 3rem;
}

.menu {
Expand Down Expand Up @@ -365,7 +365,7 @@ iframe+em {

@media (max-width: 1140px) {
article {
margin: 0.5rem 1.5rem;
margin: 1.5rem 1.5rem 1.5rem 2rem;
}
}

Expand Down

0 comments on commit 56c60bf

Please sign in to comment.