From 727ef4f5364b02a980485072427fc0fdbd16515f Mon Sep 17 00:00:00 2001
From: Liam Monninger
The Movement logo
We are actively working on a new edition of this booklet in response to changes in our audience and to address issues stemming from the outdated nature of the original guide.
+Welcome to Building with Movement! Over the course of this booklet, we will be addressing topics related to developing for the Movement blockchain.
This booklet was originally developed for a month-long hackathon, and so has content covering four weeks. While we think this pacing is nice, the book is concise enough to do in far less time and resumable enough to spread out over more time.
By the end of this book, you will have the skills to build for the Movement blockchain and the contextual awareness to understand its advantages.
diff --git a/book/book/index.html b/book/book/index.html index 94a4eaa..6b8d108 100644 --- a/book/book/index.html +++ b/book/book/index.html @@ -159,6 +159,16 @@We are actively working on a new edition of this booklet in response to changes in our audience and to address issues stemming from the outdated nature of the original guide.
+Welcome to Building with Movement! Over the course of this booklet, we will be addressing topics related to developing for the Movement blockchain.
This booklet was originally developed for a month-long hackathon, and so has content covering four weeks. While we think this pacing is nice, the book is concise enough to do in far less time and resumable enough to spread out over more time.
By the end of this book, you will have the skills to build for the Movement blockchain and the contextual awareness to understand its advantages.
diff --git a/book/book/print.html b/book/book/print.html index b9b9bcd..d6a9bb7 100644 --- a/book/book/print.html +++ b/book/book/print.html @@ -157,6 +157,16 @@We are actively working on a new edition of this booklet in response to changes in our audience and to address issues stemming from the outdated nature of the original guide.
+Welcome to Building with Movement! Over the course of this booklet, we will be addressing topics related to developing for the Movement blockchain.
This booklet was originally developed for a month-long hackathon, and so has content covering four weeks. While we think this pacing is nice, the book is concise enough to do in far less time and resumable enough to spread out over more time.
By the end of this book, you will have the skills to build for the Movement blockchain and the contextual awareness to understand its advantages.
@@ -172,7 +182,7 @@This section is intended to orient the reader on the history of the language and various Move virtual machine implementations.
The Move programming language was originally developed by Facebook's Libra project, now known as Diem, to facilitate the creation of smart contracts on its blockchain platform. The language takes its name from the underlying concept of moving resources rather than copying them, aligning with the principles of resource-oriented programming. Move was designed to address the unique challenges of blockchain development, such as security, efficiency, and scalability. Its origins can be traced back to the vision of creating a blockchain-based financial infrastructure that would be accessible to billions of people around the world. Today, Move continues to evolve as an open-source language, with a growing ecosystem and community supporting its development and adoption.
+The Move programming language was originally developed by Facebook's Libra project, now known as Diem, to facilitate the creation of smart contracts on its blockchain platform. The language takes its name from the underlying concept of moving resources rather than copying them, aligning with the principles of resource-oriented programming. Move was designed to address the unique challenges of blockchain development, such as security, efficiency, and scalability.
Resource-orientation is a fundamental concept in programming languages like Move that greatly benefits the blockchain ecosystem. By aligning with the principles of resource-oriented programming, the blockchain can enhance security, efficiency, and reliability of smart contracts.
Resource-oriented programming languages like Move implement access restrictions at all levels of code execution. From the top-level contract to individual functions, access to resources is strictly controlled. This granular access control minimizes the risk of unauthorized operations and ensures that only authorized parties can interact with specific resources, promoting secure and auditable transactions on the blockchain.
Type linearity is a crucial aspect of resource-oriented programming that enforces the linear use of resources. In Move, resources have linear types, meaning they can only be consumed or moved, not duplicated. This feature prevents resource duplication, reduces memory consumption, and eliminates the risk of double-spending, ensuring the integrity and accuracy of transactions on the blockchain.
-Double-spending is a significant concern in decentralized systems where digital assets are involved. Resource-oriented programming, like Move, mitigates the risk of double-spending by enforcing strict ownership and borrowing rules. Resources can only be moved or consumed once, preventing malicious actors from creating multiple transactions using the same resource and effectively eliminating the possibility of double-spending attacks.
-Virtual machines play a crucial role in the blockchain ecosystem, particularly in executing and enforcing the logic of smart contracts. They ensure that all nodes on the blockchain network run the same logic, enabling verification and consensus among participants.
-Smart contracts are self-executing agreements with predefined conditions encoded in code. In the blockchain context, smart contracts are executed by nodes across the network. Virtual machines, such as the Move Virtual Machine (Move VM) used in the Move programming language, ensure that all nodes interpret and execute the smart contract code uniformly. This guarantees that the same logic is executed across the network, promoting trust and enabling reliable transaction execution.
-Verification is a critical aspect of the blockchain ecosystem. Nodes need to agree on the validity of transactions and smart contract execution. Virtual machines facilitate this verification process by providing a standardized environment where nodes can discuss and agree upon the execution of the same logic. By achieving consensus on the outcomes, nodes can ensure the integrity and consistency of the blockchain.
-The virtual machine acts as an execution environment for smart contracts and other blockchain operations. It ensures that the same logic applied to a smart contract on one node is identical to the logic applied on every other node. This consistency is essential for achieving consensus and maintaining the immutability of the blockchain. Virtual machines, such as the Move VM, enforce the rules and protocols defined by the blockchain platform, allowing for secure and reliable execution of smart contracts.
-Several implementations of the Move virtual machine exist, including the Move VM, Aptos VM, and Sui VM. These implementations provide alternative approaches to executing Move code and offer flexibility and compatibility with different blockchain platforms and ecosystems. Each implementation has its own characteristics, optimizations, and use cases, catering to diverse blockchain development requirements.
-The transaction processing speed (TPS) of the underlying blockchain is a primary limitation on smart contract complexity. Higher TPS allows for more intricate and computationally intensive smart contracts to be executed within a given time frame.
-Movement facilitates a theoretical maximum TPS of 160,000 by combining the technologies of Move and Avalanche Snowball consensus. This scalability enhancement enables more sophisticated and resource-intensive smart contracts to be processed efficiently.
-In addition to its high TPS, Movement provides developer-friendly features via its Aptos-based VM and an ergonomic standard library .
+++linear type: a type with an enforced the restriction that variables or values of the type can be used exactly once. In other words, each linear value has a unique owner or consumer, and it must be used or consumed linearly without duplication or uncontrolled consumption.
+
f(a) -> g(a) -> h(a)
+
+++non-linear type: a type without an enforced the restriction that variables or values of the type can be used exactly once. Variables or values of non-linear types can be used or accessed multiple times without restrictions.
+
f(a) ->
+ g(a)
+ + h(a) ->
+ c(a)
+ + k(a)
+ + p(a)
+
+Type linearity is a crucial aspect of resource-oriented programming that enforces the linear use of resources. In Move, resources generally have linear types, meaning they can only be consumed or moved, not duplicated. This feature prevents resource duplication, reduces memory consumption, and eliminates the risk of double-spending, ensuring the integrity and accuracy of transactions on the blockchain.
+The resource-orientation and type-linearity of the Move programming language play a significant role in avoiding common smart contract vulnerabilities. Here's how these features address specific vulnerabilities:
+Reentrancy Attacks: In a reentrancy attack, a malicious contract calls back into the calling contract before the first execution completes, potentially leading to unexpected behavior or loss of funds. Move's resource-orientation ensures that resources (which include digital assets) cannot be duplicated and are used in a linear fashion. This linearity means that once a resource is moved, it cannot be accessed again within the same transaction, thereby mitigating reentrancy risks.
+Integer Overflow and Underflow: These occur when an operation attempts to create a numerical value outside the range that can be represented with a given number of bits. Move's type system can enforce range checks on numeric values, reducing the risk of overflow and underflow errors.
+Unintended Ether Loss: In Ethereum, contracts can be accidentally destroyed with ether still inside, leading to permanent loss of funds. Move's resource model can prevent this by ensuring that resources are accounted for at all times, making it much harder to lose them accidentally.
+Frozen Ether: Ether can become frozen in a contract due to bugs. Move's stronger guarantees about the state and its manipulation help avoid such scenarios, as the language is designed to make the effects of code more predictable and transparent.
+Timestamp Dependence and Miner Manipulation: Some contracts rely on block timestamps, which can be slightly manipulated by miners. Move's approach to resources and transactions doesn't inherently solve this, but its more predictable environment can help developers avoid relying on such external and manipulable factors.
+Short Address/Parameter Attack: This happens due to inconsistent handling of input data length. Move's strong typing and explicit resource management can help avoid this by enforcing correct input handling and data lengths.
+Denial of Service (DoS) via Block Gas Limit: Attackers might stuff blocks with expensive computations to exhaust a contract's gas. While this is more of a systemic issue, Move's efficiency and predictability in resource handling can mitigate some of the risks.
+Unknown Function Calls: In Ethereum, sending Ether to unknown functions can lead to vulnerabilities. Move's explicit resource accounting can help avoid such scenarios by making it clear where and how resources are flowing.
+Move’s focus on safety, predictability, and explicit resource management addresses these vulnerabilities effectively, helping developers write safer smart contracts. This is particularly crucial in blockchain environments, where contract bugs and vulnerabilities can lead to significant financial losses and are often irreversible due to the immutable nature of blockchain technology.
This section examines tooling and provides setup instructions for working with the Movement blockchain and the various examples in covered in this booklet.
The budding Move ecosystem sports a variety of developer friendly tools. As we list off tools that will be relevant to this booklet, keep in mind that there are number of projects we have not included.
As previously discussed, there are several virtual machine implementations available for Move development--each of with is paired with particular blockchain. Besides the Movement VM
, the most well-known Move virtual machines are Move VM
, Aptos VM
, and Sui VM
As previously discussed, there are several popular virtual machine implementations available for Move development--each of with is paired with particular blockchain. Besides the Movement VM
, the most well-known Move virtual machines are Move VM
, Aptos VM
, and Sui VM
We provide a comparison of these different virtual machines in our docs.
-When selecting a virtual machine for development its important to consider performance, ease of use, and stability. Aptos VM
built upon the original and stable Move VM
to provide an improved developer experience. The Movement VM
builds upon Aptos VM
to provide improved performance.
When selecting a virtual machine for development it's important to consider performance, ease of use, and stability. Aptos VM
built upon the original and stable Move VM
to provide an improved developer experience. The Movement VM
builds upon Aptos VM
to provide improved performance.
There are three CLIs worth note in the Move language development space. All support building, testing, deploying, and running smart contracts.
+There are three CLIs worthy of note in the Move language development space. All support building, testing, deploying, and running smart contracts.
move
: the original CLI for Move development. aptos
: the CLI for Aptos development.movement
: our very own CLI.aptos
: the CLI for Aptos development.movement
: our very own CLI which is currently compatible with the Aptos CLI.In this booklet we will be working with move
and movement
.
In this booklet we will be working with movement
. If you ever need help working with movement
you can run movement --help
or movement <command> --help
for more information.
Move has a package manager, movey. However, generally we will recommend adding dependencies directly to your Move.toml
file.
You can manage Move dependencies by adding them directly to your Move.toml
file.
[package]
name = "hello_world"
version = "0.0.0"
[dependencies]
-# MoveNursery = { git = "https://github.com/move-language/move.git", subdir = "language/move-stdlib/nursery", rev = "main" }
-MovementFramework = { git = "https://github.com/movemntdev/movement-subnet.git", subdir = "vm/aptos-vm/aptos-move/aptos-framework", rev = "main" }
+AptosFramework = { git = "https://github.com/movemntdev/aptos-core.git", subdir = "aptos-vm/aptos-move/aptos-framework", rev = "testnet" }
[addresses]
std = "0x1"
hello_blockchain = "_"
+Our version of the AptosFramework is slightly different from the upstream at https://github.com/aptos-labas/aptos-core.git. Please be mindful that, while our goal is to support the latest version of the Aptos Framework, we may occasionally lag behind the upstream--resulting in incompatibilities.
There are several useful development enviroments for Move. This book will be geared towards using VsCode because of the its developer container features and its Move analyzer. However, syntax highlighting has been implemented for other IDEs including Vim.
We'll be using the move
and movement
CLIs; no package manager; and VsCode most-often running the movement-dev
Docker container from public.ecr.aws/c4i6k4r8/movement-dev.
We'll be using the move
and movement
CLIs; no package manager; and VsCode most-often running the movement-dev
Docker container from (mvlbs/m1)[https://hub.docker.com/repository/docker/mvlbs/m1/general].
To get started...
move
, movement-dev
, anchor
, or solidity
devcontainers.Alternatively, when working with movement-dev
you may:
docker image pull public.ecr.aws/c4i6k4r8/movement-dev
-docker run -it -v "$(pwd):/workspace" public.ecr.aws/c4i6k4r8/movement-dev /bin/bash
+docker image pull mvlbs/m1
+docker run -it -v "$(pwd):/workspace" mvlbs/m1 /bin/bash
-We will also occasionally use Rust and Python to complete various programming examples.
-We will also discuss using our proxy service with the JavaScript. The movement-dev
developer container provides an easy start place for this alternative means of interacting with the subnet.
+We will also occasionally use Rust, TypeScript, and Python to complete various programming examples.
Basic Move Syntax
This section treats with basic Move syntax, comparing the language to Rust. This is merely intended to provide some guidance for booklet participants. More comprehensive guides can be found at move-book.com and move-language.github.io.
Allocation and the Move Memory Model
@@ -278,7 +315,7 @@ Expressions and Control Flow
Expressions
-Move use a similar expression-orientation to Rusts. Block returns are possible.
+Move uses a similar expression-orientation to Rust. Expressions are evaluated to produce a value. Expressions can be used in many places, including:
#![allow(unused)]
fn main() {
fun eight() : u8 {
@@ -383,6 +420,7 @@ Misc. syntax
- The
public
keyword in Move indicates that a function can be invoked from outside the current module.
+- The
entry
keyword is used to declare functions that can be called via the RPC.
- The
native
keyword is used to declare functions that are implemented in the blockchain runtime or in an external module.
- There are VM specific directives; in Movement we will address
#[inline]
, #[view]
, #[test_only]
, and #[test]
.
@@ -424,9 +462,10 @@ Scripts
}
}
Scripts can only have one function in their body.
+Within the context of movement
, we will not be using scripts--instead preferring the module construct.
Building
-When developing for modules in move you will typically need to manually publish the module before being able to run. The exception to this rule is when using movement
to run unit tests. movement move publish
will handle both the building and publication of modules in your current working directory. If you simply want to build the module to inspect its bytecode run movement move build
.
-Below is an example bash script for publishing and running a function in a module end-to-end using the Movement CLI.
+When developing modules in Move you will need to publish the module before being able to run. The exception to this rule is when using movement
to run unit tests. movement move publish
will handle both the building and publication of modules in your current working directory. If you simply want to build the module to inspect its bytecode run movement move build
.
+Below is an example bash script for publishing and running a function in a module end-to-end using the Movement CLI drawn from 💻 hello_blockchain
.
#!/bin/bash -e
# Function to echo text as cyan with emoji
@@ -456,17 +495,20 @@ Building
finish "Queryed resourced for account!"
named_addresses
-Within aptos_framework
, you will be able to use named addresses. These will be replaced at compile time whether they are in the adrress position in a module <my_address_name>::my_module
or marked with an @<my_address_name>
.
+The Move build system enables the usage of named addresses to simplify addressing schemes. These will be replaced at compile time whether they are in the adrress position in a module <my_address_name>::my_module
or marked with an @<my_address_name>
elsewhere.
In your Move.toml
, you may specify these addresses as below.
[addresses]
std = "0x1"
<my_address_name> = "_"
You may then specify them when compiling using --<my_address_name>=<my_value>
.
+Additional complexities that emerge when using named addresses are well documented in Diem's original documentation of the Move language.
+💻 resource_roulette
dev-addresses
+Resource roulette currently has a value in the [addresses]
block that is better suited to [dev-addresses]
. Find it an test the module.
Debugging Basic Smart Contracts
This section introduces a few basic smart contracts from this repository as a starting point for programming activites.
-💻 HelloWorld
-Is a very simple program for MoveVM
. You can find it at examples/move/hello_world
.
+💻 hello_world
+This very simple program for Movement Move VM
. You can find it at examples/movement/hello_world
prints values to debug console. Note the differences in encodings between the b""
and string::utf8
versions of the string.
Learnings leveraged:
@@ -476,38 +518,45 @@ 💻 HelloWorld<
#![allow(unused)]
fn main() {
-script {
- use std::debug;
- // use std::vector;
- fun debug_script(account : signer) {
-
- // Encode the "Hello, world!" as a byte string.
- let hello = b"Hello, world!";
-
- // Print the byte string as a vector<u8> by passing a reference to the byte string.
- debug::print<vector<u8>>(&hello);
+module hello_world::hello_world {
+
+ use std::string;
+ use std::signer;
+ use aptos_std::debug;
+
+ #[test(account = @0x1)]
+ public entry fun hello_world(account: signer) {
+ let addr = signer::address_of(&account);
+ debug::print<address>(&addr);
+ let message = b"Hello, world!";
+ debug::print(&message);
+ let str_message = string::utf8(message);
+ debug::print(&str_message);
}
+
}
}
-To run...
-move sandbox run sources/hello_world_script.move --signers 0xf
+To test run...
+move move run
+> [debug] @0x1
> [debug] 0x48656c6c6f2c20776f726c6421
+> [debug] "Hello, world!"
-Double-check the output hex...
+If you want to double-check the output hex...
echo 48656c6c6f2c20776f726c6421 | xxd -r - p
-💻 Fib
-The obligatory Move program that computes the nth Fibonacci number. We will refer to this later when we do 💻 MulticontractFib. You can find it and instructions to run it examples/move/fib
.
+💻 fib
+The obligatory Move program that computes the nth Fibonacci number. We will refer to this later when we do 💻 MulticontractFib. You can find it and instructions to run it examples/movement/fib
.
Learnings leveraged:
- Basic Move syntax
-- Byte strings
+- Move recursion.
-💻 DataStructures
-From scratch implementation of a priority queue, a couple variations of a hash map, and a binary tree. This may be a useful reference point for building more challenging projects that require custom data strucures. You can find it at examples/move/data_structures
.
+💻 data_structures
+From scratch implementation of a priority queue, a couple variations of a hash map, and a binary tree. This may be a useful reference point for building more challenging projects that require custom data strucures. You can find it at examples/movement/data_structures
.
Learnings leveraged:
@@ -517,8 +566,8 @@ 💻 DataStr
- Move idioms
-💻 ResourceRoulette
-A game of roulette on MoveVM. Place your address on an element in the vector. Contains methods public fun bid
and public fun spin
. Receive a payout if you placed your address on the correct cell. You can find it and instructions to run it at examples/move/resource_roulette
.
+💻 resource_roulette
+A game of roulette on MoveVM. Place your address on an element in the vector. Contains methods public fun bid
and public fun spin
. Receive a payout if you placed your address on the correct cell. You can find it and instructions to run it at examples/movement/resource_roulette
.
Learnings leveraged:
@@ -664,48 +713,61 @@ 💻 Reso
}
}
-This section examines the standard library and framework that ships with Movement. Both are based on their Aptos namesakes.
+This section examines the Move standard library and Aptos framework. These are the most common starting points in M1 development.
Disclaimer: there are many more useful modules in the standard library and framework. We will discuss some of them in this course and encourage you to explore them as you go.
-std::debug
and aptos_std::debug
Prints to a message to the console using a VM native
func. The associated [debug]
outputs are easiest to view when unit testing.
aptos_std::debug
aptos_std::debug::print
serializes and prints a Move value to the console using a VM native
func. The associated [debug]
outputs are easiest to view when unit testing.
aptos_std::debug::print_stack_trace
prints the current stack.
The below is an example demonstrating print string nuances in 💻 hello_world
.
#![allow(unused)] fn main() { -module debug_demo::message { +module hello_world::hello_world { + use std::string; use std::signer; use aptos_std::debug; - struct MessageHolder has key { - message: string::String, - } - - - public entry fun set_message(account: signer, message_bytes: vector<u8>) - acquires MessageHolder { - debug::print_stack_trace(); - let message = string::utf8(message_bytes); - let account_addr = signer::address_of(&account); - if (!exists<MessageHolder>(account_addr)) { - move_to(&account, MessageHolder { - message, - }); - } else { - let old_message_holder = borrow_global_mut<MessageHolder>(account_addr); - old_message_holder.message = message; - } - } - + #[test(account = @0x1)] - fun sender_can_set_message(account: signer) acquires MessageHolder { + public entry fun sender_can_set_message(account: signer) { let addr = signer::address_of(&account); debug::print<address>(&addr); - set_message(account, b"Hello, Blockchain"); + let message = b"Hello, world!"; + debug::print(&message); + let str_message = string::utf8(message); + debug::print(&str_message); } } }
std::vector
and aptos_std::big_vector
A useful dynamically size collection with an aptos_std::
counterpart optimized for a large number of elements.
The below is an example of searching through std::vector
in open addressing hash map implementation from 💻 data_structures
.
#![allow(unused)] +fn main() { +public fun find<K, V>(map: &OaHashMap<K, V>, key: &K) : &Option<Entry<K, V>> { + + let index = compute_hash_index(key, map.size); + let count = 0; + loop { + let option_value = vector::borrow(&map.entries, index % map.size); + if (option::is_none(option_value)) { + return option_value + } else { + let entry = option::borrow(option_value); + if (key_equals(&entry.key, key)) { + return option_value + } + }; + index = index + 1; + count = count + 1; + if (count > map.size) { + abort ENO_BUFFER_EXHAUSTED + } + } + +} +}
aptos_std::table
An associative array.
-#![allow(unused)] @@ -735,12 +797,58 @@
std::option
< assert!(!option::contains(&some_other, &5), 3); } }
aptos_framwork::resource_account
A resource account is used to manage resources independent of an account managed by a user. This is is useful for building things like liquidity providers which we will discuss later in the course.
-A game of roulette on MoveVM. Place your address on an element in the vector. Contains methods public fun bid
and public fun spin
. Receive a payout if you placed your address on the correct cell, but only when cash out. Balances are tracked in a aptos_std::table
. You can find it and instructions to run it examples/movement/resource_roulette
.
A tiny key value store for vector<u8>
files. Implements store
and load
functionality using a aptos_framework::resource_account
and a aptos_std::table
. You can find it and instructions to run it examples/movement/mini_fs
.
aptos_framework::account
One of the most notable features of the aptos_framework
is its resource accounts. Per Aptos, "a resource account is a developer feature used to manage resources independent of an account managed by a user, specifically publishing modules and automatically signing for transactions." In some ways, you can think of a resource account as an administrator or service account. In most large projects, you will want to use resource accounts to--in the least--manage deployments.
Using resource accounts takes some practice. We encourage you to closely consider the code in 💻 mini_dex
to get a better sense of how to use resource accounts.
+#![allow(unused)] +fn main() { +public entry fun initialize_lp_account( + minidx_admin: &signer, + lp_coin_metadata_serialized: vector<u8>, + lp_coin_code: vector<u8> +) { + assert!(signer::address_of(minidx_admin) == @mini_dex, EInvalidAccount); + + let (lp_acc, signer_cap) = + account::create_resource_account(minidx_admin, b"LP_CREATOR_SEED"); + aptos_framework::code::publish_package_txn( + &lp_acc, + lp_coin_metadata_serialized, + vector[lp_coin_code] + ); + move_to(minidx_admin, CapabilityStorage { signer_cap }); +} +}
For many common coin and NFT operations, the Aptos framework provides a set of methods that will manage capabilities. For example, the below is a snippet from an aptos-core
example demonstrating how to initialize a coin:
+#![allow(unused)] +fn main() { +/// initialize the module and store the signer cap, mint cap and burn cap within +fun init_module(account: &signer) { + // store the capabilities within `ModuleData` + let resource_signer_cap = resource_account::retrieve_resource_account_cap(account, @source_addr); + let (burn_cap, freeze_cap, mint_cap) = coin::initialize<ChloesCoin>( + account, + string::utf8(b"Chloe's Coin"), + string::utf8(b"CCOIN"), + 8, + false, + ); + move_to(account, ModuleData { + resource_signer_cap, + burn_cap, + mint_cap, + }); + + // destroy freeze cap because we aren't using it + coin::destroy_freeze_cap(freeze_cap); + + // regsiter the resource account with both coins so it has a CoinStore to store those coins + coin::register<AptosCoin>(account); + coin::register<ChloesCoin>(account); +} +}
However, you will also often have to define your own capabilities. In the Aptos Framework, you will usually find it most idiomatic and convenient to use use aptos_framework::account::SignerCapability
for this.
Review 💻 mini_dex
for an example of how to use SignerCapability
to manage unique capabilities. As a challenge, design your own simple module including resource account logic and a SignerCapability
.
This week treats with more advanced concepts in the Move language and focuses our Move development efforts on the Movement blockchain. This is also intended as an opportunity to practice and revisit concepts from Week 1.
The MSL specification provides for more advanced type-level constructs. For ambitious developers, these may be powerful contribution objectives!
This section examines the safety features of Move in greater and more theoretical detail. There are no programming exercises designed for this section. It is primarily intended to motivate the usage of Move language in the context of blockchain.
-The Move Language was inspired by linear logic, a formal system of logic that was developed by Jean-Yves Girard in 1987. In linear logic, formulas were regarded as resources which could only be used once. Similarly, in the Move language, resources can only be moved between storage locations, never copied or dropped.
-Move's type system enables special safety guarantees for resources. It ensures that move resources can not be duplicated, reused, or implicitly discarded. Attempts to duplicate, reuse, or implicitly discard a resource will result in a bytecode verification error. Notwithstanding these unique safeguards, resources in the Move language possess the characteristics of regular program values. They can be stored in data structures, passed as arguments to procedures, and utilized in similar ways.
-+#![allow(unused)] -fn main() { -module 0x42::LinearLogicExample { - use std::vector; - use std::debug; - - struct Token has drop { - value: u8, - } - - fun use_token(token: Token) { - debug::print<vector<u8>>("Using token."); - // Perform operations with the token... - } - - public fun main() { - let token: Token; - - token = Token { value: 10 }; - - debug::print<vector<u8>>(b"Before use:"); - debug::print<u8>(token.value); - - use_token(token); - - debug::print<u8>(token.value); - // Attempting to access `token` here would result in a compile-time error - } -} -}
🚧 Under renovation. Please check back later.
@@ -1102,38 +1176,7 @@
Long before blockchain technology, American cryptographer and programmer, Nick Szabo, proposed the idea of the smart contracts in 1996. At the time of his proposal, the distributed ledger did not exist, and thus his idea could be not built upon. The first cryptocurrency, Bitcoin, was created in 2008, which helped to motivate the development of smart contracts. In 2013, Ethereum became the first platform to host smart contracts. Now, there are plenty of platforms that are used to bring Szabo's idea to life.
-When it comes to implementing smart contracts, resource orientation plays a crucial role in ensuring security, efficiency, and reliability. Resource-oriented programming languages, such as Move, have emerged as a powerful tool for developing smart contracts on blockchain platforms. Move, specifically designed for the Libra blockchain, places a strong emphasis on resource-oriented programming principles, which have proven to be highly beneficial in the context of smart contracts. Here's why resource orientation is important in languages like Move:
-Security and Safety: Smart contracts often handle valuable digital assets, and any vulnerability or flaw in the contract's code can lead to disastrous consequences, including financial losses. Resource-oriented programming in Move enforces strict ownership and borrowing rules, ensuring that resources are properly managed and protected. The language's type system guarantees the absence of common vulnerabilities like reentrancy and enables static verification of contracts, minimizing the risk of critical bugs and making smart contracts more secure.
-Efficient Resource Management: In traditional programming languages, objects or data structures are often copied or cloned when passed between functions or contracts. This can lead to unnecessary memory consumption and performance bottlenecks. Resource-oriented programming in Move takes a different approach. Resources are moved between functions or contracts, rather than being copied, ensuring efficient use of memory and reducing the risk of unintended side effects. Move's ownership model allows for fine-grained control over resource lifecycles, enabling optimized resource management within smart contracts.
-Immutable and Transparent State: Blockchain technology inherently involves a distributed and immutable ledger that maintains the state of smart contracts. Resource-oriented programming aligns well with these characteristics, as Move enforces immutability for resources. Once a resource is created, its state cannot be modified directly, ensuring the integrity and consistency of the contract's data. This immutability also contributes to the transparency of the blockchain, as the entire history of resource states can be audited and verified by any participant.
-Concurrent and Parallel Execution: In decentralized blockchain networks, multiple transactions can be executed concurrently, requiring smart contracts to handle concurrent access to shared resources. Resource-oriented programming provides a solid foundation for handling concurrent execution. Move's borrowing mechanism allows for controlled and safe concurrent access to resources, preventing data races and ensuring deterministic execution. This capability enables scalable and efficient execution of smart contracts in a distributed environment.
-Upgradeability and Evolution: Smart contracts often need to evolve and adapt over time to incorporate new features, fix bugs, or address changing business requirements. Resource-oriented programming facilitates upgradability by decoupling the contract's data from its logic. By defining the behavior of resources separately from the contract's code, Move allows for smooth migration and upgrade of contracts while preserving the integrity of existing data and ensuring backward compatibility.
-Resource orientation in languages like Move plays a pivotal role in the development of secure, efficient, and reliable smart contracts. By enforcing ownership and borrowing rules, enabling efficient resource management, ensuring immutability and transparency of state, supporting concurrent execution, and facilitating upgradability, Move empowers developers to build robust and future-proof smart contracts on the blockchain.
-We've implemented a multi-contract fibonacci number computation in Solidity, Anchor, and Movement to illustrate the benefits of the move language and Movement. We encourage to run and compare the source for each. We've included devcontainers for Solidity and Anchor in the associated repo.
-Solidity is high-level, object-oriented programming language used to implement smart contracts. It is the primary programming language used on the Ethereum blockchain.
-To work with the Solidity implementation, use the solidity
devcontainer and work from the examples/solidity/multicontract_fib
directory.
Anchor is Solana's Sealevel runtime framework. It provides several developer tools for writing smart contracts in order to simplify the process and help developers to focus on their product.
-To work with the Anchor implementation, use the anchor
devcontainer and work from the examples/anchor/multicontract_fib
directory.
This is us!
-To work with the Anchor implementation, use the movement
devcontainer and work from the examples/movement/multicontract_fib
directory.
🚧 Under renovation. Please check back later.
This section examines testing strategies for Move smart contracts on Movement. We will cover both automated and manual strategies for testing functionality.
movement<
Help us develop mocking and stubbing tools for Movement.
Design Patterns
-Ville Sundell has already provided an expert overview of useful design patterns in Move. As this book improves, we may include some of our own here. However, for now, we defer to Ville.
+🚧 Under renovation. Please check back later.
Smart Contracts development and staging
-Development
-When building smart contracts for movement
you can use both the move
client and movement
itself.
-move
-The move
CLI is a suitable tool for early and primitive development. You will not have access to the same onchain resources as when working with the movement
CLI, such as access to our DEX. However, you will be able to use the move sandbox
to build and run contracts.
-To make sure you are building with out standard library, include the following in your Move.toml
.
-[package]
-name = "hello_world"
-version = "0.0.0"
-
-[dependencies]
-# MoveNursery = { git = "https://github.com/move-language/move.git", subdir = "language/move-stdlib/nursery", rev = "main" }
-MovementFramework = { git = "https://github.com/movemntdev/movement-subnet.git", subdir = "vm/aptos-vm/aptos-move/aptos-framework", rev = "main" }
-
-[addresses]
-std = "0x1"
-hello_blockchain = "_"
-
-movement
-The movement
CLI provides an aptos
-like interface for running Move language scripts and modules. For more details see the movement
CLI docs.
-When using movement
in its default configuration, you will test and run contracts against our testnet. This is ideal for most Movement development.
-Staging
-The best way to publicly stage smart contracts for Movement is simply to us a movement
CLI. If you are interested in a more private staging environment, you may use the movement
CLI with the provided movement
devcontainer to compose and stage against a local network.
-
-Contribution
-{: .contributor-block}
-Help us develop better tools for movement staging!
-
+🚧 Under renovation. Please check back later.
Week 3: M1 and DeFi Applications
M1 is Movement's first L1. This week is be all about building applications, particular DeFi applications, with Movement.
Deploying on M1
@@ -1569,7 +1586,7 @@ ACLs, RBAC, and ABAC
Access Control Lists (ACLs), Role-Based Access Control (RBAC), and Attribute-Based Access Control (ABAC) are common frameworks used to manage and enforce access control policies in blockchain applications. ACLs define permissions based on a list of entities and their associated access rights. RBAC assigns permissions to roles, allowing for more centralized management of access control. ABAC grants access based on attributes, such as user attributes or environmental conditions. Each framework has its strengths and can be tailored to meet specific access control requirements in a blockchain application.
-A common pattern in Move and Movement development is to assert a contract owner. Using named addresses, @named_address
.
+A rudimentary pattern in Move and Movement development is to assert a contract owner. Using named addresses, @named_address
.
#![allow(unused)]
fn main() {
script owner_address::important_script {
diff --git a/book/book/searchindex.js b/book/book/searchindex.js
index 916c2e3..88efa97 100644
--- a/book/book/searchindex.js
+++ b/book/book/searchindex.js
@@ -1 +1 @@
-Object.assign(window.search, {"doc_urls":["Prologue.html#building-with-movement","week_1/week_1.html#week-1-introduction-to-move-and-movement","week_1/Inro_to_move.html#introduction-to-move-and-movement","week_1/Inro_to_move.html#libradiem","week_1/Inro_to_move.html#resource-orientation-and-the-blockchain","week_1/Inro_to_move.html#stack-model-programming-and-function-ownership","week_1/Inro_to_move.html#access-restriction-all-the-way-down","week_1/Inro_to_move.html#type-linearity-and-ownership","week_1/Inro_to_move.html#double-spending","week_1/Inro_to_move.html#virtual-machines-and-the-blockchain","week_1/Inro_to_move.html#smart-contracts-nodes-running-the-same-logic","week_1/Inro_to_move.html#verification-nodes-talking-about-running-the-same-logic","week_1/Inro_to_move.html#virtual-machine-makes-sure-the-same-logic-is-the-same-logic","week_1/Inro_to_move.html#move-virtual-machines","week_1/Inro_to_move.html#limitations-and-movement","week_1/Developer_setup.html#developer-setup","week_1/Developer_setup.html#the-move-ecosystem","week_1/Developer_setup.html#virtual-machines","week_1/Developer_setup.html#clis","week_1/Developer_setup.html#package-managers","week_1/Developer_setup.html#ide","week_1/Developer_setup.html#our-setup","week_1/Basic_move_syntax.html#basic-move-syntax","week_1/Basic_move_syntax.html#allocation-and-the-move-memory-model","week_1/Basic_move_syntax.html#expressions-and-control-flow","week_1/Basic_move_syntax.html#expressions","week_1/Basic_move_syntax.html#if","week_1/Basic_move_syntax.html#while-and-loop","week_1/Basic_move_syntax.html#types","week_1/Basic_move_syntax.html#primitives","week_1/Basic_move_syntax.html#abilities","week_1/Basic_move_syntax.html#generic-and-behavior","week_1/Basic_move_syntax.html#resources-references-and-mutation","week_1/Basic_move_syntax.html#misc-syntax","week_1/Module_and_build_system.html#modules-and-build-system","week_1/Module_and_build_system.html#packages","week_1/Module_and_build_system.html#program-types","week_1/Module_and_build_system.html#modules","week_1/Module_and_build_system.html#scripts","week_1/Module_and_build_system.html#building","week_1/Module_and_build_system.html#named_addresses","week_1/Debugging_basics.html#debugging-basic-smart-contracts","week_1/Debugging_basics.html#-helloworld","week_1/Debugging_basics.html#-fib","week_1/Debugging_basics.html#-datastructures","week_1/Debugging_basics.html#-resourceroulette","week_1/Movement_standard_library.html#movement-standard-library","week_1/Movement_standard_library.html#stddebug-and-aptos_stddebug","week_1/Movement_standard_library.html#stdvector-and-aptos_stdbig_vector","week_1/Movement_standard_library.html#aptos_stdtable","week_1/Movement_standard_library.html#stdoption","week_1/Movement_standard_library.html#aptos_framworkresource_account","week_1/Movement_standard_library.html#-resourceroulette-pt-2","week_1/Movement_standard_library.html#-minifs","week_2/week_2.html#week-2-advanced-move-and-move-for-movement","week_2/Generics.html#generics-type-constraints-and-polymorphism","week_2/Generics.html#generics","week_2/Generics.html#move-does-not-support-subtyping-or-composable-type-constraints","week_2/Generics.html#the-four-type-abilities-copy-drop-store-and-key","week_2/Generics.html#storage-polymorphism","week_2/Generics.html#unused-and-phantom-types","week_2/Generics.html#-movenav","week_2/Generics.html#the-future-of-move-type-programming","week_2/Safety.html#safety","week_2/Safety.html#linear-logic","week_2/Safety.html#move-type-system","week_2/Safety.html#the-move-prover","week_2/Intro_smart_contracts.html#introduction-to-smart-contracts","week_2/Intro_smart_contracts.html#origins-of-smart-contracts","week_2/Intro_smart_contracts.html#comparison--multicontractfib","week_2/Intro_smart_contracts.html#solidity","week_2/Intro_smart_contracts.html#anchor","week_2/Intro_smart_contracts.html#movement","week_2/Testing.html#testing","week_2/Testing.html#movement-profile-configuration","week_2/Testing.html#automated-testing","week_2/Testing.html#manual-testing","week_2/Testing.html#with-movement","week_2/Testing.html#semi-automation","week_2/Testing.html#testing-directives","week_2/Testing.html#test","week_2/Testing.html#test_only","week_2/Testing.html#expect_failure","week_2/Testing.html#mocks-stubs-and-state-based-simulation","week_2/Testing.html#mocks-and-stubs","week_2/Testing.html#state-based-simulation","week_2/Testing.html#for-movement","week_2/Design_patterns.html#design-patterns","week_2/Development_staging.html#smart-contracts-development-and-staging","week_2/Development_staging.html#development","week_2/Development_staging.html#move","week_2/Development_staging.html#movement","week_2/Development_staging.html#staging","week_3/week_3.html#week-3-m1-and-defi-applications","week_3/Deploying_on_M1.html#deploying-on-m1","week_3/Deploying_on_M1.html#-multicontractfib","week_3/Security.html#security","week_3/Security.html#m1","week_3/Security.html#attack-surface","week_3/Security.html#blockchain","week_3/Security.html#smart-contracts","week_3/Security.html#dapps","week_3/Security.html#handling-user-data","week_3/Security.html#data-minimization","week_3/Security.html#access-control","week_3/Security.html#encryption","week_3/Security.html#pseudonymization","week_3/Security.html#dos","week_3/Common_blockchain_system_design_patterns.html#common-blockchain-system-design-patterns","week_3/Common_blockchain_system_design_patterns.html#oracles","week_3/Common_blockchain_system_design_patterns.html#rollups","week_3/Common_blockchain_system_design_patterns.html#tokenization","week_3/Common_blockchain_system_design_patterns.html#state-channels","week_3/Common_blockchain_system_design_patterns.html#side-chains","week_3/Common_blockchain_system_design_patterns.html#collaborative-governance","week_3/Common_blockchain_system_design_patterns.html#atomic-swaps","week_3/Common_blockchain_system_design_patterns.html#proofs-and-zero-knowledge","week_3/Access_control.html#access-control","week_3/Access_control.html#signatures-and-certificates","week_3/Access_control.html#acls-rbac-and-abac","week_3/Access_control.html#permissioned-chains","week_3/DeFi.html#defi","week_3/DeFi.html#what-is-defi","week_3/DeFi.html#why-decentralize","week_3/DeFi.html#financial-applications-of-decentralized-systems","week_3/DeFi.html#purchasing","week_3/DeFi.html#lending","week_3/DeFi.html#trading","week_3/DeFi.html#defi-phenomena","week_3/DeFi.html#yield-farming","week_3/DeFi.html#flash-loans","week_3/DeFi.html#automated-market-making","week_3/DeFi.html#coins","week_3/DeFi.html#important-defi-algorithms","week_3/DeFi.html#constant-product-market-maker-cpmm-and-constant-mean-market-maker-cmmm","week_3/DeFi.html#fraud-proof-and-binary-search","week_3/DeFi.html#modern-portfolio-theory-mpt","week_3/DeFi.html#risk-models","week_4/week_4.html#week-4-projects","week_4/Project_requirements_and_recommendations.html#project-requirements-and-recommendations","week_4/Project_requirements_and_recommendations.html#requirements","week_4/Project_requirements_and_recommendations.html#project-recommendations","week_4/Project_requirements_and_recommendations.html#dapps","week_4/Project_requirements_and_recommendations.html#infrastructure","week_4/Project_requirements_and_recommendations.html#bounties","week_4/Project_requirements_and_recommendations.html#contribute","week_4/Guidelines.html#guidelines","week_4/Guidelines.html#requirements-gathering","week_4/Guidelines.html#pitching-and-presenting","week_4/Guidelines.html#crafting-a-paper-and-deck","week_4/Guidelines.html#the-pitch","week_4/Guidelines.html#the-presentation","week_4/Guidelines.html#support","week_4/Guidelines.html#general-outreach","week_4/Guidelines.html#bugs","week_4/Next_steps.html#next-steps"],"index":{"documentStore":{"docInfo":{"0":{"body":89,"breadcrumbs":4,"title":2},"1":{"body":30,"breadcrumbs":10,"title":5},"10":{"body":47,"breadcrumbs":13,"title":6},"100":{"body":130,"breadcrumbs":8,"title":2},"101":{"body":23,"breadcrumbs":7,"title":1},"102":{"body":0,"breadcrumbs":9,"title":3},"103":{"body":16,"breadcrumbs":8,"title":2},"104":{"body":43,"breadcrumbs":8,"title":2},"105":{"body":17,"breadcrumbs":7,"title":1},"106":{"body":21,"breadcrumbs":7,"title":1},"107":{"body":52,"breadcrumbs":7,"title":1},"108":{"body":0,"breadcrumbs":15,"title":5},"109":{"body":174,"breadcrumbs":11,"title":1},"11":{"body":36,"breadcrumbs":13,"title":6},"110":{"body":58,"breadcrumbs":11,"title":1},"111":{"body":67,"breadcrumbs":11,"title":1},"112":{"body":40,"breadcrumbs":12,"title":2},"113":{"body":43,"breadcrumbs":12,"title":2},"114":{"body":62,"breadcrumbs":12,"title":2},"115":{"body":43,"breadcrumbs":12,"title":2},"116":{"body":59,"breadcrumbs":13,"title":3},"117":{"body":12,"breadcrumbs":9,"title":2},"118":{"body":67,"breadcrumbs":9,"title":2},"119":{"body":119,"breadcrumbs":10,"title":3},"12":{"body":45,"breadcrumbs":15,"title":8},"120":{"body":68,"breadcrumbs":9,"title":2},"121":{"body":13,"breadcrumbs":7,"title":1},"122":{"body":35,"breadcrumbs":7,"title":1},"123":{"body":35,"breadcrumbs":7,"title":1},"124":{"body":0,"breadcrumbs":10,"title":4},"125":{"body":17,"breadcrumbs":7,"title":1},"126":{"body":235,"breadcrumbs":7,"title":1},"127":{"body":23,"breadcrumbs":7,"title":1},"128":{"body":0,"breadcrumbs":8,"title":2},"129":{"body":27,"breadcrumbs":8,"title":2},"13":{"body":38,"breadcrumbs":10,"title":3},"130":{"body":22,"breadcrumbs":8,"title":2},"131":{"body":37,"breadcrumbs":9,"title":3},"132":{"body":146,"breadcrumbs":7,"title":1},"133":{"body":0,"breadcrumbs":9,"title":3},"134":{"body":12,"breadcrumbs":16,"title":10},"135":{"body":18,"breadcrumbs":10,"title":4},"136":{"body":14,"breadcrumbs":10,"title":4},"137":{"body":16,"breadcrumbs":8,"title":2},"138":{"body":18,"breadcrumbs":6,"title":3},"139":{"body":15,"breadcrumbs":9,"title":3},"14":{"body":63,"breadcrumbs":9,"title":2},"140":{"body":26,"breadcrumbs":7,"title":1},"141":{"body":15,"breadcrumbs":8,"title":2},"142":{"body":34,"breadcrumbs":7,"title":1},"143":{"body":52,"breadcrumbs":7,"title":1},"144":{"body":34,"breadcrumbs":7,"title":1},"145":{"body":25,"breadcrumbs":7,"title":1},"146":{"body":11,"breadcrumbs":5,"title":1},"147":{"body":233,"breadcrumbs":6,"title":2},"148":{"body":0,"breadcrumbs":6,"title":2},"149":{"body":55,"breadcrumbs":7,"title":3},"15":{"body":13,"breadcrumbs":9,"title":2},"150":{"body":48,"breadcrumbs":5,"title":1},"151":{"body":64,"breadcrumbs":5,"title":1},"152":{"body":12,"breadcrumbs":5,"title":1},"153":{"body":13,"breadcrumbs":6,"title":2},"154":{"body":11,"breadcrumbs":5,"title":1},"155":{"body":10,"breadcrumbs":7,"title":2},"16":{"body":17,"breadcrumbs":9,"title":2},"17":{"body":64,"breadcrumbs":9,"title":2},"18":{"body":31,"breadcrumbs":8,"title":1},"19":{"body":42,"breadcrumbs":9,"title":2},"2":{"body":11,"breadcrumbs":10,"title":3},"20":{"body":21,"breadcrumbs":8,"title":1},"21":{"body":80,"breadcrumbs":8,"title":1},"22":{"body":22,"breadcrumbs":11,"title":3},"23":{"body":68,"breadcrumbs":12,"title":4},"24":{"body":0,"breadcrumbs":11,"title":3},"25":{"body":13,"breadcrumbs":9,"title":1},"26":{"body":42,"breadcrumbs":8,"title":0},"27":{"body":23,"breadcrumbs":9,"title":1},"28":{"body":0,"breadcrumbs":9,"title":1},"29":{"body":40,"breadcrumbs":9,"title":1},"3":{"body":68,"breadcrumbs":8,"title":1},"30":{"body":68,"breadcrumbs":9,"title":1},"31":{"body":55,"breadcrumbs":10,"title":2},"32":{"body":82,"breadcrumbs":11,"title":3},"33":{"body":28,"breadcrumbs":10,"title":2},"34":{"body":8,"breadcrumbs":11,"title":3},"35":{"body":59,"breadcrumbs":9,"title":1},"36":{"body":25,"breadcrumbs":10,"title":2},"37":{"body":26,"breadcrumbs":9,"title":1},"38":{"body":22,"breadcrumbs":9,"title":1},"39":{"body":146,"breadcrumbs":9,"title":1},"4":{"body":23,"breadcrumbs":10,"title":3},"40":{"body":28,"breadcrumbs":9,"title":1},"41":{"body":11,"breadcrumbs":13,"title":4},"42":{"body":56,"breadcrumbs":10,"title":1},"43":{"body":21,"breadcrumbs":10,"title":1},"44":{"body":32,"breadcrumbs":10,"title":1},"45":{"body":271,"breadcrumbs":10,"title":1},"46":{"body":24,"breadcrumbs":11,"title":3},"47":{"body":62,"breadcrumbs":10,"title":2},"48":{"body":10,"breadcrumbs":10,"title":2},"49":{"body":34,"breadcrumbs":9,"title":1},"5":{"body":91,"breadcrumbs":12,"title":5},"50":{"body":31,"breadcrumbs":9,"title":1},"51":{"body":17,"breadcrumbs":9,"title":1},"52":{"body":30,"breadcrumbs":11,"title":3},"53":{"body":17,"breadcrumbs":9,"title":1},"54":{"body":20,"breadcrumbs":12,"title":6},"55":{"body":31,"breadcrumbs":14,"title":4},"56":{"body":76,"breadcrumbs":11,"title":1},"57":{"body":173,"breadcrumbs":16,"title":6},"58":{"body":116,"breadcrumbs":17,"title":7},"59":{"body":208,"breadcrumbs":12,"title":2},"6":{"body":38,"breadcrumbs":11,"title":4},"60":{"body":132,"breadcrumbs":13,"title":3},"61":{"body":141,"breadcrumbs":11,"title":1},"62":{"body":13,"breadcrumbs":14,"title":4},"63":{"body":21,"breadcrumbs":8,"title":1},"64":{"body":31,"breadcrumbs":9,"title":2},"65":{"body":86,"breadcrumbs":10,"title":3},"66":{"body":74,"breadcrumbs":9,"title":2},"67":{"body":0,"breadcrumbs":12,"title":3},"68":{"body":397,"breadcrumbs":12,"title":3},"69":{"body":27,"breadcrumbs":11,"title":2},"7":{"body":35,"breadcrumbs":10,"title":3},"70":{"body":26,"breadcrumbs":10,"title":1},"71":{"body":28,"breadcrumbs":10,"title":1},"72":{"body":9,"breadcrumbs":10,"title":1},"73":{"body":15,"breadcrumbs":8,"title":1},"74":{"body":87,"breadcrumbs":10,"title":3},"75":{"body":117,"breadcrumbs":9,"title":2},"76":{"body":36,"breadcrumbs":9,"title":2},"77":{"body":184,"breadcrumbs":8,"title":1},"78":{"body":25,"breadcrumbs":9,"title":2},"79":{"body":7,"breadcrumbs":9,"title":2},"8":{"body":41,"breadcrumbs":9,"title":2},"80":{"body":45,"breadcrumbs":8,"title":1},"81":{"body":13,"breadcrumbs":8,"title":1},"82":{"body":83,"breadcrumbs":8,"title":1},"83":{"body":17,"breadcrumbs":12,"title":5},"84":{"body":97,"breadcrumbs":9,"title":2},"85":{"body":37,"breadcrumbs":10,"title":3},"86":{"body":129,"breadcrumbs":8,"title":1},"87":{"body":17,"breadcrumbs":10,"title":2},"88":{"body":0,"breadcrumbs":14,"title":4},"89":{"body":10,"breadcrumbs":11,"title":1},"9":{"body":24,"breadcrumbs":10,"title":3},"90":{"body":63,"breadcrumbs":11,"title":1},"91":{"body":28,"breadcrumbs":11,"title":1},"92":{"body":35,"breadcrumbs":11,"title":1},"93":{"body":11,"breadcrumbs":10,"title":5},"94":{"body":38,"breadcrumbs":9,"title":2},"95":{"body":24,"breadcrumbs":8,"title":1},"96":{"body":17,"breadcrumbs":7,"title":1},"97":{"body":23,"breadcrumbs":7,"title":1},"98":{"body":0,"breadcrumbs":8,"title":2},"99":{"body":98,"breadcrumbs":7,"title":1}},"docs":{"0":{"body":"The Movement logo Welcome to Building with Movement ! Over the course of this booklet, we will be addressing topics related to developing for the Movement blockchain. This booklet was originally developed for a month-long hackathon, and so has content covering four weeks. While we think this pacing is nice, the book is concise enough to do in far less time and resumable enough to spread out over more time. By the end of this book, you will have the skills to build for the Movement blockchain and the contextual awareness to understand its advantages. If you are looking for in-depth documentation of Movement or the movement CLI please head to docs.movementlabs.xyz . This book has an accompanying GitHub repository here. You can also navigate to it by clicking the icon on any page. If you run into any issues, please use our Help Desk to file a bug report, request support, or search for additional documentation. We will attempt to provide timely support, prioritizing hackathon participants.","breadcrumbs":"Building with Movement » Building with Movement","id":"0","title":"Building with Movement"},"1":{"body":"This week kicks off our exploration of the Move language and Movement ecosystem. We will begin by introducing Move, setting up an appropriate developer environment, and covering the basics of the Move language. Many of the topics concerning the move language will be revisited in greater depth during Week 2.","breadcrumbs":"Week 1: Introduction to Move and Movement » Week 1: Introduction to Move and Movement","id":"1","title":"Week 1: Introduction to Move and Movement"},"10":{"body":"Smart contracts are self-executing agreements with predefined conditions encoded in code. In the blockchain context, smart contracts are executed by nodes across the network. Virtual machines, such as the Move Virtual Machine (Move VM) used in the Move programming language, ensure that all nodes interpret and execute the smart contract code uniformly. This guarantees that the same logic is executed across the network, promoting trust and enabling reliable transaction execution.","breadcrumbs":"Week 1: Introduction to Move and Movement » Introduction to Move » Smart Contracts: Nodes Running the Same Logic","id":"10","title":"Smart Contracts: Nodes Running the Same Logic"},"100":{"body":"Environment Smart contracts rely on the execution environment in which they run. Insecure environments can expose smart contracts to attacks, such as sandbox escapes or unauthorized access to system resources. External dependencies Smart contracts often interact with external systems or data sources. These dependencies can introduce security risks, such as malicious data feeds or vulnerabilities in the connected systems. Code vulnerabilities Flaws in the code of smart contracts can lead to various vulnerabilities, including reentrancy attacks, integer overflow/underflow, and logic errors. These vulnerabilities can be exploited to manipulate contract behavior or steal funds. Thankfully, thanks to its type-system, resource-orientation, and linear programming model, the Move language makes it difficult to publish code with many of the common smart contract vulnerabilities. Upgradability The ability to upgrade smart contracts introduces potential security risks. Unauthorized or malicious upgrades can compromise the integrity of the contract or introduce vulnerabilities that can be exploited. Thankfully, the Move language introduces the concept of modules, which are self-contained units of code that encapsulate the functionality of smart contracts. Unlike traditional smart contracts, Move modules can be upgraded without disrupting the entire system or requiring complex migration processes.","breadcrumbs":"Week 3: M1 and DeFi Applications » Security » Smart contracts","id":"100","title":"Smart contracts"},"101":{"body":"Integration risks Decentralized applications (dApps) often integrate with external services or APIs. Insecure integration points can expose dApps to security risks, such as unauthorized data access or injection of malicious code.","breadcrumbs":"Week 3: M1 and DeFi Applications » Security » dApps","id":"101","title":"dApps"},"102":{"body":"","breadcrumbs":"Week 3: M1 and DeFi Applications » Security » Handling User Data","id":"102","title":"Handling User Data"},"103":{"body":"Blockchain applications should follow the principle of data minimization, collecting only the necessary data and avoiding the storage of sensitive information that is not required for the application's functionality.","breadcrumbs":"Week 3: M1 and DeFi Applications » Security » Data minimization","id":"103","title":"Data minimization"},"104":{"body":"Proper access control mechanisms should be implemented to ensure that only authorized individuals or entities can access sensitive user data. This includes authentication, authorization, and secure role-based access control. Move uses an account-based ownership model where each account has its own address and associated permissions. Access control can be enforced at the account level, ensuring that only authorized users can perform specific actions.","breadcrumbs":"Week 3: M1 and DeFi Applications » Security » Access control","id":"104","title":"Access control"},"105":{"body":"Sensitive user data stored in the blockchain or associated systems should be encrypted to protect it from unauthorized access. Encryption algorithms and protocols should be carefully chosen and implemented.","breadcrumbs":"Week 3: M1 and DeFi Applications » Security » Encryption","id":"105","title":"Encryption"},"106":{"body":"To enhance privacy, blockchain applications can pseudonymize user data by replacing personally identifiable information with pseudonyms or cryptographic identifiers. This makes it difficult to directly link user identities to their data.","breadcrumbs":"Week 3: M1 and DeFi Applications » Security » Pseudonymization","id":"106","title":"Pseudonymization"},"107":{"body":"Denial-of-Service (DoS) attacks aim to disrupt the availability of a blockchain application or the entire network by overwhelming the system with an excessive amount of requests or by exploiting vulnerabilities in the network's infrastructure. DoS attacks can result in service unavailability or degradation, impacting the application's functionality and user experience. Implementing robust DoS mitigation strategies is essential to protect against such attacks. As mentioned above, Avalanche's adaptive security approach it difficult to successfully deny network service.","breadcrumbs":"Week 3: M1 and DeFi Applications » Security » DoS","id":"107","title":"DoS"},"108":{"body":"","breadcrumbs":"Week 3: M1 and DeFi Applications » Common Blockchain System Design Patterns » Common blockchain system design patterns","id":"108","title":"Common blockchain system design patterns"},"109":{"body":"Oracles play a crucial role in blockchain applications by providing a bridge between the blockchain and the external world. They are trusted entities or mechanisms that bring off-chain data onto the blockchain, making it accessible to smart contracts and decentralized applications. Oracles enable the blockchain to interact with real-world events, data feeds, APIs, and other external systems. By leveraging oracles, blockchain applications can access and process external information in a reliable and secure manner. We built 💻 NewsMoves, examples/movement/new_moves, as a toy oracle contract that allows a trusted entity to write the latest Google news articles onto the blockchain. Please checkout the directory to publish the contract and run the Python data entity. module news_moves::news_moves { use std::signer; use std::vector; // Struct representing a news article entry struct Article has copy { timestamp: u64, title: vector, content: vector, } // NewsMoves struct representing the contract state struct NewsMoves { articles: vector, } // Initialization function for the NewsMoves contract public fun init() { move_to(@news_moves, NewsMoves { articles: vector::empty(), }); } public fun update( account: &signer, timestamp: u64, title: vector, content: vector, ) acquires NewsMoves { // update the contract at the account let account_addr = signer::address_of(account); let self = borrow_global_mut(account_addr); // add the new article vector::push_back(&mut self.articles, Article { timestamp: timestamp, title: title, content: content, }); } // Function to get the latest news article from the contract public fun getLatestArticle(): Article { // Get the latest article from the contrac let moves = borrow_global(@news_moves); let len = vector::length(&articles); assert(len > 0, 98); // Ensure there is at least one article let latestArticleIndex = len - 1; *moves.articles[latestArticleIndex] } }","breadcrumbs":"Week 3: M1 and DeFi Applications » Common Blockchain System Design Patterns » Oracles","id":"109","title":"Oracles"},"11":{"body":"Verification is a critical aspect of the blockchain ecosystem. Nodes need to agree on the validity of transactions and smart contract execution. Virtual machines facilitate this verification process by providing a standardized environment where nodes can discuss and agree upon the execution of the same logic. By achieving consensus on the outcomes, nodes can ensure the integrity and consistency of the blockchain.","breadcrumbs":"Week 1: Introduction to Move and Movement » Introduction to Move » Verification: Nodes Talking About Running the Same Logic","id":"11","title":"Verification: Nodes Talking About Running the Same Logic"},"110":{"body":"Rollups are a layer 2 scaling solution for blockchains that aim to improve scalability and reduce transaction costs. They work by aggregating multiple transactions off-chain and then submitting a summary or proof of those transactions to the main chain. This reduces the burden on the main chain, allowing for faster and more efficient processing. Rollups can significantly increase transaction throughput and enable complex applications to run smoothly on the blockchain while maintaining a high level of security. We added a toy dispute mechanism 💻 NewsMoves, examples/movement/new_moves to demonstrate how part of a rollup could implemented.","breadcrumbs":"Week 3: M1 and DeFi Applications » Common Blockchain System Design Patterns » Rollups","id":"110","title":"Rollups"},"111":{"body":"Tokenization is the process of representing real-world or digital assets as tokens on a blockchain. It enables the creation of digital representations (tokens) that can be owned, transferred, and managed on the blockchain. Tokenization has broad applications, ranging from representing physical assets like real estate or artwork to creating digital assets like utility tokens or security tokens. By tokenizing assets, blockchain-based systems can provide increased liquidity, fractional ownership, and facilitate seamless transferability of assets in a secure and transparent manner. We implement a toy tokenization scheme and separately used our framework's aptos_token_objects to augment 💻 NewsMoves, examples/movement/new_moves and demonstrate Movement token utilities.","breadcrumbs":"Week 3: M1 and DeFi Applications » Common Blockchain System Design Patterns » Tokenization","id":"111","title":"Tokenization"},"112":{"body":"State channels are a scalability solution in blockchain that allows off-chain execution of transactions between participants. They enable fast and low-cost transactions by keeping most of the interactions off-chain, while the final state is settled on the main blockchain. State channels are particularly useful for frequent and fast interactions, such as microtransactions or gaming applications, as they reduce congestion and improve transaction throughput.","breadcrumbs":"Week 3: M1 and DeFi Applications » Common Blockchain System Design Patterns » State Channels","id":"112","title":"State Channels"},"113":{"body":"Side chains are separate blockchains that are connected to the main blockchain, often referred to as the \"main chain\" or \"parent chain.\" They provide an additional layer of scalability and flexibility by allowing specific use cases or applications to operate on their own chain while still being interoperable with the main chain. Side chains can handle transactions and smart contracts independently, reducing the load on the main chain and enabling specialized functionalities.","breadcrumbs":"Week 3: M1 and DeFi Applications » Common Blockchain System Design Patterns » Side Chains","id":"113","title":"Side Chains"},"114":{"body":"Collaborative governance refers to the process of making collective decisions and managing blockchain networks through the participation and collaboration of multiple stakeholders. It involves mechanisms such as voting, consensus-building, and community-driven decision-making to govern the rules, upgrades, and overall direction of a blockchain network. Collaborative governance aims to ensure inclusivity, transparency, and alignment of interests among network participants. aptos_framework::aptos_governance provides a host of out of the box tools for handling proposals, dynamic voting systems, and member rewards. Using it you can implement a DAO and tests in a about a thousand lines of code.","breadcrumbs":"Week 3: M1 and DeFi Applications » Common Blockchain System Design Patterns » Collaborative Governance","id":"114","title":"Collaborative Governance"},"115":{"body":"Atomic swaps are a mechanism that allows the exchange of different cryptocurrencies or digital assets between two parties without the need for an intermediary or trusted third party. It enables secure peer-to-peer transactions directly between participants, ensuring that either the entire transaction is executed or none of it occurs. Atomic swaps enhance interoperability and facilitate decentralized exchanges by eliminating the need for centralized intermediaries.","breadcrumbs":"Week 3: M1 and DeFi Applications » Common Blockchain System Design Patterns » Atomic Swaps","id":"115","title":"Atomic Swaps"},"116":{"body":"Zero-knowledge proofs are cryptographic techniques that enable a party to prove knowledge of certain information without revealing the actual information itself. They allow for privacy-preserving transactions and interactions on the blockchain, where participants can validate the correctness of a statement or the possession of certain data without disclosing sensitive details. Zero-knowledge proofs enhance confidentiality and confidentiality in blockchain applications, ensuring that privacy-sensitive information remains secure while still being verifiable. At Movement, we're working on a Zero-Knowledge VM powered by the Move Prover.","breadcrumbs":"Week 3: M1 and DeFi Applications » Common Blockchain System Design Patterns » Proofs and Zero-Knowledge","id":"116","title":"Proofs and Zero-Knowledge"},"117":{"body":"This section briefly covers some considerations of blockchain access control and highlights places where Movement and this repo may be helpful.","breadcrumbs":"Week 3: M1 and DeFi Applications » Access Control » Access Control","id":"117","title":"Access Control"},"118":{"body":"Signatures and certificates play a crucial role in access control on the blockchain. They enable authentication and ensure that only authorized entities can perform specific actions or access certain resources. Signatures provide proof of ownership and authenticity, while certificates verify the identity and permissions of participants. By utilizing strong cryptographic signatures and certificates, blockchain applications can establish secure and tamper-proof access control mechanisms. Avalanche uses Transport Layer Security, TLS, to protect node-to-node communications from eavesdroppers. The Avalanche virtual machine uses elliptic curve cryptography, specifically secp256k1, for its signatures on the blockchain, and signs all messages.","breadcrumbs":"Week 3: M1 and DeFi Applications » Access Control » Signatures and certificates","id":"118","title":"Signatures and certificates"},"119":{"body":"Access Control Lists (ACLs), Role-Based Access Control (RBAC), and Attribute-Based Access Control (ABAC) are common frameworks used to manage and enforce access control policies in blockchain applications. ACLs define permissions based on a list of entities and their associated access rights. RBAC assigns permissions to roles, allowing for more centralized management of access control. ABAC grants access based on attributes, such as user attributes or environmental conditions. Each framework has its strengths and can be tailored to meet specific access control requirements in a blockchain application. A common pattern in Move and Movement development is to assert a contract owner. Using named addresses, @named_address. script owner_address::important_script { const ERNO_OWNER_ONLY : u64 = 0 fun do_important_thing(signer : address){ assert!(signer == @owner_address, ERNO_OWNER_ONLY); // do thing... } } Manipulation of addresses often serves as the basis for Movement access control mechanisms. The Move language provides host of unique safe ways to implement access controls for resources. aptos_framework::aptos_governance provides an easy to use module for governance which can allow for decentralized managed of these control lists.","breadcrumbs":"Week 3: M1 and DeFi Applications » Access Control » ACLs, RBAC, and ABAC","id":"119","title":"ACLs, RBAC, and ABAC"},"12":{"body":"The virtual machine acts as an execution environment for smart contracts and other blockchain operations. It ensures that the same logic applied to a smart contract on one node is identical to the logic applied on every other node. This consistency is essential for achieving consensus and maintaining the immutability of the blockchain. Virtual machines, such as the Move VM, enforce the rules and protocols defined by the blockchain platform, allowing for secure and reliable execution of smart contracts.","breadcrumbs":"Week 1: Introduction to Move and Movement » Introduction to Move » Virtual Machine: Makes Sure the Same Logic is the Same Logic","id":"12","title":"Virtual Machine: Makes Sure the Same Logic is the Same Logic"},"120":{"body":"Permissioned chains are blockchain networks that restrict participation to authorized entities only. Unlike public or permissionless blockchains, permissioned chains require participants to obtain explicit permission or be part of a predefined set of trusted entities. Permissioned chains are often employed in enterprise or consortium settings, where privacy, confidentiality, and control over network participants are paramount. By leveraging permissioned chains, blockchain applications can enforce stricter access control and maintain a trusted network environment. While the Movement testnet is not a permissioned chain, our virtual machines strong access controls--due to the Move language--make it easy to restrict access to select resources.","breadcrumbs":"Week 3: M1 and DeFi Applications » Access Control » Permissioned chains","id":"120","title":"Permissioned chains"},"121":{"body":"This section treats with a general overview DeFi problems and solution, and the faculties of Movement M1 to help create these solutions.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » DeFi","id":"121","title":"DeFi"},"122":{"body":"Decentralized Finance (DeFi) refers to a category of financial applications and platforms built on blockchain networks that aim to provide open, permissionless, and decentralized alternatives to traditional financial systems. DeFi leverages the transparency, immutability, and programmability of blockchain technology to enable financial activities without the need for intermediaries or centralized authorities.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » What is DeFi?","id":"122","title":"What is DeFi?"},"123":{"body":"Decentralization in DeFi brings several advantages, including increased transparency, censorship resistance, improved accessibility, and reduced reliance on trusted third parties. By removing intermediaries and enabling peer-to-peer transactions, decentralization can enhance efficiency, reduce costs, and empower individuals to have more control over their financial activities.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Why Decentralize?","id":"123","title":"Why Decentralize?"},"124":{"body":"","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Financial Applications of Decentralized Systems","id":"124","title":"Financial Applications of Decentralized Systems"},"125":{"body":"Decentralized systems allow for the direct peer-to-peer purchase of digital assets, cryptocurrencies, and other goods or services without the need for intermediaries or central authorities.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Purchasing","id":"125","title":"Purchasing"},"126":{"body":"DeFi platforms enable individuals to lend and borrow funds directly from other users through smart contracts, removing the need for traditional financial intermediaries such as banks. Check out examples/movement/gimme_mini for a toy implementation of both a direct and peer-pooled lending platform. // example supply function from gimme_mini direct lending platform\npublic fun supply( account: &signer, market_obj: Object, underlying_fa: FungibleAsset\n): FungibleAsset acquires Vault, Market { assert!( fungible_asset::asset_metadata(&underlying_fa) == fungible_asset::store_metadata(market_obj), ERR_MARKET_MISMATCH ); let underlying_amount = fungible_asset::amount(&underlying_fa); // update market fungible store fungible_asset::deposit(market_obj, underlying_fa); // mint ctoken let ctoken_amount = underlying_to_ctoken(market_obj, underlying_amount); let market = borrow_global_mut(object::object_address(&market_obj)); let ctoken = fungible_asset::mint(&market.ctoken_mint_ref, ctoken_amount); // update user vault init_vault_if_not_exists(account); let vault = borrow_global_mut(signer::address_of(account)); if (!vector::contains(&vault.collaterals, &market_obj)) { vector::push_back(&mut vault.collaterals, market_obj); }; ctoken\n} module peer_pooled_lend::peer_pooled_lend { use std::signer; friend mini_lend::LoanOfficer; /// Lends funds to liquidity pool. /// 1. LoanOfficer will... /// 1. Check if account has enough funds to lend. /// 2. Check for suspicious activity. /// 2. If account has enough funds to lend... /// 1. MiniLend will transfer funds from account to liquidity pool. public fun lend(account : signer, amount : u64){ // ... } /// Allows lender to seek repayment from liquidity pool. /// 1. LoanOfficer will... /// 1. Determine whether account is lender. /// 2. Determine loan period is up. /// 2. If the account is a valid lender and the loan period is up... /// 1. MiniLend will transfer funds from liquidity pool to account or self-collateralize. public fun seek_repayment(account : signer, amount : u64){ // ... } /// Borrows funds from liquidity pool. /// 1. LoanOfficer will... /// 1. Check if account has enough collateral /// 2. Check account credit. /// 3. If account has enough collateral and credit... /// 2. If account has enough collateral and credit... /// 1. MiniLend will borrow funds from liquidity pool /// 3. Whether or not the account will successully borrow funds, run the audit function. public fun borrow(account : signer, amount : u64){ // ... } public fun repay(account : signer, amount : u64){ // ... } /// Looks over loan tables and dispatches events to manage loans /// Anyone can call this function enabling decentralized book keeping. public fun audit(account : signer){ // ... } }","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Lending","id":"126","title":"Lending"},"127":{"body":"Decentralized exchanges (DEXs) facilitate trustless trading of digital assets directly between users, eliminating the need for centralized order books and custody of funds by intermediaries. Movement has an ready-made DEX.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Trading","id":"127","title":"Trading"},"128":{"body":"","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » DeFi Phenomena","id":"128","title":"DeFi Phenomena"},"129":{"body":"Yield farming involves leveraging various DeFi protocols to maximize returns on cryptocurrencies or digital assets by providing liquidity, staking, or participating in other activities to earn additional rewards. Check out examples/movement/yield_gardner for a toy implementation of a yield farmer.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Yield Farming","id":"129","title":"Yield Farming"},"13":{"body":"Several implementations of the Move virtual machine exist, including the Move VM, Aptos VM, and Sui VM. These implementations provide alternative approaches to executing Move code and offer flexibility and compatibility with different blockchain platforms and ecosystems. Each implementation has its own characteristics, optimizations, and use cases, catering to diverse blockchain development requirements.","breadcrumbs":"Week 1: Introduction to Move and Movement » Introduction to Move » Move Virtual Machines","id":"13","title":"Move Virtual Machines"},"130":{"body":"Flash loans are uncollateralized loans that allow users to borrow funds temporarily for specific transactions within a single blockchain transaction. They exploit the composability and fast transaction finality of smart contracts.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Flash Loans","id":"130","title":"Flash Loans"},"131":{"body":"Automated market makers (AMMs) are decentralized protocols that use mathematical formulas to determine asset prices and provide liquidity for trading. They have revolutionized liquidity provision in DeFi by eliminating the need for order books and enabling continuous trading. Check out examples/movement/gimme_mini for a toy implementation of a lending platform built atop the liquidswap AMM.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Automated Market Making","id":"131","title":"Automated Market Making"},"132":{"body":"Coins are typically created and recorded on the blockchain through a consensus mechanism, ensuring their authenticity and immutability. They can be transferred between participants on the network, used for transactions, and sometimes serve additional purposes such as voting rights or access to certain functionalities within decentralized applications (dApps) built on the blockchain. Coins play a fundamental role in enabling economic activity and incentivizing participation within the blockchain ecosystem. Movement provides built-in utilties to easily create and managed coins at varying levels of abstraction. // A managed coin.\n//:!:>sun\nmodule sun_coin::sun_coin { struct SunCoin {} fun init_module(sender: &signer) { aptos_framework::managed_coin::initialize( sender, b\"Sun Coin\", b\"SUN\", 6, false, ); }\n}\n//<:!:sun // Handling coin transactions\nscript { use aptos_framework::coin; use std::vector; // There are two ways to approach this problem // 1. Withdraw the total then distribute the pieces by breaking it up or // 2. Transfer for each amount individually fun main(sender: &signer, split : vector, amount: u64) { let i = 0; let len = vector::length(split); let coins = coin::withdraw(sender, amount); while (i < len) { let coins_pt = coin::extract(&mut coins, amount / len); coin::deposit( vector::borrow(split, i), coins_pt ); }; }\n} Stablecoins are a type of coin that aims to maintain a stable value, typically pegged to a fiat currency like the US Dollar or a basket of assets. They provide price stability, making them suitable for various use cases within the decentralized finance ecosystem.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Coins","id":"132","title":"Coins"},"133":{"body":"","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Important DeFi Algorithms","id":"133","title":"Important DeFi Algorithms"},"134":{"body":"These algorithms are used in AMMs to maintain liquidity and determine prices based on the constant product or mean principles.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Constant Product Market Maker (CPMM) and Constant Mean Market Maker (CMMM)","id":"134","title":"Constant Product Market Maker (CPMM) and Constant Mean Market Maker (CMMM)"},"135":{"body":"These algorithms enhance security in DeFi protocols by detecting and mitigating potential fraud or malicious activities. Binary search is often used to optimize search and validation processes.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Fraud Proof and Binary Search","id":"135","title":"Fraud Proof and Binary Search"},"136":{"body":"MPT is applied in DeFi to optimize asset allocation and portfolio management, considering risk, returns, and correlations among different assets.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Modern Portfolio Theory (MPT)","id":"136","title":"Modern Portfolio Theory (MPT)"},"137":{"body":"DeFi relies on various risk models and methodologies to assess and manage risks associated with lending, borrowing, and other financial activities in decentralized systems.","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Risk Models","id":"137","title":"Risk Models"},"138":{"body":"Week 4 is all about building projects. If you're reading through this notebook outside of our hackathon, we hope you find the resources useful for building your first Movement project.","breadcrumbs":"Week 4: Projects » Week 4: Projects","id":"138","title":"Week 4: Projects"},"139":{"body":"In this section we discuss project requirements and recommendations. Many of the recommendations involve working on technologies that we're keen on developing and incubating for Movement!","breadcrumbs":"Week 4: Projects » Project Requirements and Recommendations » Project Requirements and Recommendations","id":"139","title":"Project Requirements and Recommendations"},"14":{"body":"The transaction processing speed (TPS) of the underlying blockchain is a primary limitation on smart contract complexity. Higher TPS allows for more intricate and computationally intensive smart contracts to be executed within a given time frame. Movement facilitates a theoretical maximum TPS of 160,000 by combining the technologies of Move and Avalanche Snowball consensus. This scalability enhancement enables more sophisticated and resource-intensive smart contracts to be processed efficiently. In addition to its high TPS, Movement provides developer-friendly features via its Aptos-based VM and an ergonomic standard library .","breadcrumbs":"Week 1: Introduction to Move and Movement » Introduction to Move » Limitations and Movement","id":"14","title":"Limitations and Movement"},"140":{"body":"For all hackathon participants, we expect... a pitch deck, a paper, links to source developed during the hackathon. We've included templates for LaTeX and PPT in the templates/presentation folder. You will make five minute pitches using your deck at the end of the hackathon.","breadcrumbs":"Week 4: Projects » Project Requirements and Recommendations » Requirements","id":"140","title":"Requirements"},"141":{"body":"There are a variety of ways to use and contribute to the Movement ecosystem. These include dApp development, infrastructure development, bounties, and direct contributions to our software.","breadcrumbs":"Week 4: Projects » Project Requirements and Recommendations » Project recommendations","id":"141","title":"Project recommendations"},"142":{"body":"The content of this course should have prepared you to work on dApps such as the following. Continue with 💻 GimmeMini, examples/movement/gimme_mini Continue with 💻 MiniDex, examples/movement/mini_dex. Create a mini oracle provider, rollup provider, or validator set management system. You may wish to continue from 💻 NewsMoves examples/movement/new_moves Decentralized Twitter clone. You may fish to continue from 💻 MyFirstDapp examples/movement/my_first_dapp.","breadcrumbs":"Week 4: Projects » Project Requirements and Recommendations » dApps","id":"142","title":"dApps"},"143":{"body":"We're all about continuing to build out the Movement ecosystem to empower more awesome developers like you. At the time of writing, the following are all things we have a close eye on. Connect a new wallet! Right now we only support Pontem on testnet. Create an L2 that allows us to deposit levered funds in another protocol. Create a framework for borrowing funds against an asset. Create a framework that allows for customizable liquidity strategies. Build integrations with Perp . Develop a stable swap with another subnet","breadcrumbs":"Week 4: Projects » Project Requirements and Recommendations » Infrastructure","id":"143","title":"Infrastructure"},"144":{"body":"We've also put together a zealy.io community. Some of our bounties include. Report UI/UX bug Report backend bug Deploy App with 100 unique smart contract interactions Community Award To 3 Most used dApps Screenshot using App Deploy project from Aptos / Sui Contribute to Champions","breadcrumbs":"Week 4: Projects » Project Requirements and Recommendations » Bounties","id":"144","title":"Bounties"},"145":{"body":"We welcome contributions to our source, including the movement-hack repo from which this book is sourced. Generally speaking we encourage you to... Develop new starter code and example modules. Submit PRs against open issues. Improve documentation.","breadcrumbs":"Week 4: Projects » Project Requirements and Recommendations » Contribute","id":"145","title":"Contribute"},"146":{"body":"This section outlines some best practices for the project and Movement success, as well as how to get in touch with the team for support.","breadcrumbs":"Week 4: Projects » Guidelines » Guidelines","id":"146","title":"Guidelines"},"147":{"body":"Requirements gathering is a critical phase in the software development process that involves capturing, analyzing, and documenting the needs and expectations of stakeholders. It lays the foundation for a successful project by ensuring a clear understanding of what needs to be built. Here are some steps for successful requirements gathering: Identify Stakeholders: Identify and involve all relevant stakeholders, including clients, end-users, subject matter experts, and other project team members. Each stakeholder brings unique perspectives and insights into the project requirements. Define the Scope: Clearly define the scope of the project by outlining its objectives, boundaries, and limitations. This helps set realistic expectations and ensures that the requirements gathering process remains focused. Conduct Interviews and Workshops: Engage in one-on-one interviews and group workshops with stakeholders to gather their input, understand their needs, and identify any existing challenges or pain points. Encourage open and honest communication to capture comprehensive requirements. Document Requirements: Document the gathered requirements in a structured manner, ensuring clarity, completeness, and traceability. Use techniques such as use cases, user stories, functional and non-functional requirements, and process flows to capture different aspects of the system. Validate and Verify: Validate the gathered requirements by reviewing them with stakeholders to ensure accuracy and alignment with their expectations. Seek their feedback and address any concerns or discrepancies. Verify the requirements against the project objectives and constraints. Prioritize Requirements: Prioritize the requirements based on their importance, urgency, and impact on project success. Collaborate with stakeholders to establish a clear understanding of the most critical and high-priority features. Iterate and Refine: Requirements gathering is an iterative process. Continuously refine and iterate the requirements based on feedback, changing project needs, and evolving stakeholder requirements. Regularly communicate and collaborate with stakeholders to ensure ongoing alignment. Remember, successful requirements gathering involves effective communication, active listening, and collaboration with stakeholders throughout the process. By following these steps, developers can gather comprehensive and accurate requirements that form a solid foundation for successful software development. If you require further assistance or guidance, feel free to reach out to Movement Labs using the contact information below in Support .","breadcrumbs":"Week 4: Projects » Guidelines » Requirements Gathering","id":"147","title":"Requirements Gathering"},"148":{"body":"","breadcrumbs":"Week 4: Projects » Guidelines » Pitching and presenting","id":"148","title":"Pitching and presenting"},"149":{"body":"Crafting a concise and visually appealing pitch deck is crucial for effectively presenting your small blockchain project at the end of a hackathon. Structure your deck to highlight the problem your project solves, the solution you've developed, the target market, and the unique value it offers. Emphasize the key features and benefits of your project, along with any notable achievements during the hackathon. Use clear and concise language, visual aids, and a consistent design to enhance the overall presentation. We've provided a templates for LaTeX and PPT in presentations/templates.","breadcrumbs":"Week 4: Projects » Guidelines » Crafting a paper and deck","id":"149","title":"Crafting a paper and deck"},"15":{"body":"This section examines tooling and provides setup instructions for working with the Movement blockchain and the various examples in covered in this booklet.","breadcrumbs":"Week 1: Introduction to Move and Movement » Developer Setup » Developer Setup","id":"15","title":"Developer Setup"},"150":{"body":"During the pitch, focus on delivering a compelling and concise message that captures the attention of the judges and participants. Clearly articulate the problem your project addresses, the solution it provides, and how it leverages blockchain technology. Highlight the practical applications, benefits, and potential market opportunities of your project. Demonstrate how your project differentiates itself from existing solutions and how it aligns with the hackathon's theme or challenges. Be confident, enthusiastic, and passionate about your project, conveying the potential impact and value it brings.","breadcrumbs":"Week 4: Projects » Guidelines » The pitch","id":"150","title":"The pitch"},"151":{"body":"When delivering your presentation, aim for clarity, professionalism, and effective communication. Begin with a concise and attention-grabbing introduction to hook the audience. Provide a brief overview of your project's development process, focusing on the key milestones achieved during the hackathon. Showcase any live demos, prototypes, or working features of your project, demonstrating its functionality and value proposition. Highlight the technical aspects of your project, such as the blockchain technology used, any smart contracts implemented, and the scalability or security measures in place. Conclude your presentation with a compelling call-to-action, inviting the judges and participants to engage with your project and explore its potential.","breadcrumbs":"Week 4: Projects » Guidelines » The presentation","id":"151","title":"The presentation"},"152":{"body":"We're happy to support all developers on Movement. Whatever your problems, needs or desires, we hope we can help out.","breadcrumbs":"Week 4: Projects » Guidelines » Support","id":"152","title":"Support"},"153":{"body":"For general questions, comments, and concerns please email liam@movementlabs.xyz or open up a new discussion in movemntdev/movement-hack .","breadcrumbs":"Week 4: Projects » Guidelines » General outreach","id":"153","title":"General outreach"},"154":{"body":"If you believe you've identified a bug, please create an issue in movemntdev/movement-hack . We will triage accordingly.","breadcrumbs":"Week 4: Projects » Guidelines » Bugs","id":"154","title":"Bugs"},"155":{"body":"Now that you've completed this book and your projects, we invite you to provide your feedback and stay in touch!","breadcrumbs":"Week 4: Projects » Next Steps » Next Steps","id":"155","title":"Next Steps"},"16":{"body":"The budding Move ecosystem sports a variety of developer friendly tools. As we list off tools that will be relevant to this booklet, keep in mind that there are number of projects we have not included.","breadcrumbs":"Week 1: Introduction to Move and Movement » Developer Setup » The Move ecosystem","id":"16","title":"The Move ecosystem"},"17":{"body":"As previously discussed, there are several virtual machine implementations available for Move development--each of with is paired with particular blockchain. Besides the Movement VM, the most well-known Move virtual machines are Move VM, Aptos VM, and Sui VM We provide a comparison of these different virtual machines in our docs . When selecting a virtual machine for development its important to consider performance, ease of use, and stability. Aptos VM built upon the original and stable Move VM to provide an improved developer experience. The Movement VM builds upon Aptos VM to provide improved performance.","breadcrumbs":"Week 1: Introduction to Move and Movement » Developer Setup » Virtual machines","id":"17","title":"Virtual machines"},"18":{"body":"There are three CLIs worth note in the Move language development space. All support building, testing, deploying, and running smart contracts. move : the original CLI for Move development. aptos: the CLI for Aptos development. movement : our very own CLI. In this booklet we will be working with move and movement.","breadcrumbs":"Week 1: Introduction to Move and Movement » Developer Setup » CLIs","id":"18","title":"CLIs"},"19":{"body":"Move has a package manager, movey . However, generally we will recommend adding dependencies directly to your Move.toml file. [package]\nname = \"hello_world\"\nversion = \"0.0.0\" [dependencies]\n# MoveNursery = { git = \"https://github.com/move-language/move.git\", subdir = \"language/move-stdlib/nursery\", rev = \"main\" }\nMovementFramework = { git = \"https://github.com/movemntdev/movement-subnet.git\", subdir = \"vm/aptos-vm/aptos-move/aptos-framework\", rev = \"main\" } [addresses]\nstd = \"0x1\"\nhello_blockchain = \"_\"","breadcrumbs":"Week 1: Introduction to Move and Movement » Developer Setup » Package managers","id":"19","title":"Package managers"},"2":{"body":"This section is intended to orient the reader on the history of the language and various Move virtual machine implementations.","breadcrumbs":"Week 1: Introduction to Move and Movement » Introduction to Move » Introduction to Move and Movement","id":"2","title":"Introduction to Move and Movement"},"20":{"body":"There are several useful development enviroments for Move. This book will be geared towards using VsCode because of the its developer container features and its Move analyzer . However, syntax highlighting has been implemented for other IDEs including Vim .","breadcrumbs":"Week 1: Introduction to Move and Movement » Developer Setup » IDE","id":"20","title":"IDE"},"21":{"body":"We'll be using the move and movement CLIs; no package manager; and VsCode most-often running the movement-dev Docker container from public.ecr.aws/c4i6k4r8/movement-dev . To get started... Clone the repo from which this book originates: https://github.com/movemntdev/movement-hack Open the repo in VsCode. Based on the advice provided for a given project, reopen the repo in one of move, movement-dev, anchor, or solidity devcontainers . Alternatively, when working with movement-dev you may: docker image pull public.ecr.aws/c4i6k4r8/movement-dev\ndocker run -it -v \"$(pwd):/workspace\" public.ecr.aws/c4i6k4r8/movement-dev /bin/bash We will also occasionally use Rust and Python to complete various programming examples. We will also discuss using our proxy service with the JavaScript. The movement-dev developer container provides an easy start place for this alternative means of interacting with the subnet .","breadcrumbs":"Week 1: Introduction to Move and Movement » Developer Setup » Our Setup","id":"21","title":"Our Setup"},"22":{"body":"This section treats with basic Move syntax, comparing the language to Rust. This is merely intended to provide some guidance for booklet participants. More comprehensive guides can be found at move-book.com and move-language.github.io .","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » Basic Move Syntax","id":"22","title":"Basic Move Syntax"},"23":{"body":"Move's resource-oriented language model leads to a unique memory model: Resources in Move are allocated and deallocated implicitly based on their defined lifespan and ownership semantics. This ensures proper resource management without the need for explicit memory allocation or deallocation. Resources are created and stored on the blockchain as part of a transaction, providing a persistent and tamper-resistant storage mechanism. Global storage in Move allows for the storage of resource data that can be accessed across multiple transactions and smart contracts. While function ownership in Move is similar to Rust, it is less permissive and closer to being purely linear--restricting the set of possible borrows.","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » Allocation and the Move Memory Model","id":"23","title":"Allocation and the Move Memory Model"},"24":{"body":"","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » Expressions and Control Flow","id":"24","title":"Expressions and Control Flow"},"25":{"body":"Move use a similar expression-orientation to Rusts. Block returns are possible. fun eight() : u8 { 8\n}","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » Expressions","id":"25","title":"Expressions"},"26":{"body":"Branching in Move is accomplished via if and else statements. There is not an else if statement. if (a) { debug::print(&0);\n} else { debug::print(&99);\n}; if is an expression. let value = if (true) { 8 } else {0}; // value set to 8 Move syntax for expressions and control flow shares similarities with Rust. Basic control flow constructs like if, while, and loop are present in Move as well. However, Move has a more limited set of expressions and control flow features compared to Rust.","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » if","id":"26","title":"if"},"27":{"body":"Move supports while and loop looping constructs. while loops while condition is true. loop loops infinitely. There is no for loop, both while and loop are roughly equally used as replacements. // example of while loop\nwhile (i < 10) { Vector::push_back(&mut a, i); i = i + 1;\n};","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » while and loop","id":"27","title":"while and loop"},"28":{"body":"","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » Types","id":"28","title":"Types"},"29":{"body":"Move has the primitive types boolean, u8, u64, u128, address, and signer. Move also supports hex- and byte-string literals. let byte_val = b\"hello, world!\"; // byte string\nlet hex_val = x\"48656C6C6F210A\"; // hex string Integers can be type cast with the as keyword. signer represents the sender of a transaction and is used for access control and authentication. signer can be converted to address with signer::address_of.","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » Primitives","id":"29","title":"Primitives"},"3":{"body":"The Move programming language was originally developed by Facebook's Libra project, now known as Diem, to facilitate the creation of smart contracts on its blockchain platform. The language takes its name from the underlying concept of moving resources rather than copying them, aligning with the principles of resource-oriented programming. Move was designed to address the unique challenges of blockchain development, such as security, efficiency, and scalability. Its origins can be traced back to the vision of creating a blockchain-based financial infrastructure that would be accessible to billions of people around the world. Today, Move continues to evolve as an open-source language, with a growing ecosystem and community supporting its development and adoption.","breadcrumbs":"Week 1: Introduction to Move and Movement » Introduction to Move » Libra/Diem","id":"3","title":"Libra/Diem"},"30":{"body":"Type abilities in Move specify certain primitive memory behaviors and constraints for types. These abilities are perhaps most similar to different pointer types in Rust. copy: The copy ability allows for the type's value to be copied. drop: The drop ability enables the necessary cleanup actions when the type goes out of scope. store: The store ability allows the type's value to be stored inside a struct in global storage. key: The key ability allows the type's value to be used as a unique identifier or index in the global storage of the Move blockchain. Conditional abilities allow types to have different behaviors based on conditions.","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » Abilities","id":"30","title":"Abilities"},"31":{"body":"Move supports generics for structs and functions. It's possible to achieve polymorphic behavior with generics and phantom types. Often you will want to nest generic structures inside of resources to achieve polymorphism. See the LiquidityPool generic structure below for an example. // polymorphic coin fee obtainment from liquidswap.\n/// Get fee for specific pool.\npublic fun get_fee(): u64 acquires LiquidityPool { assert!(coin_helper::is_sorted(), ERR_WRONG_PAIR_ORDERING); assert!(exists>(@liquidswap_pool_account), ERR_POOL_DOES_NOT_EXIST); let pool = borrow_global>(@liquidswap_pool_account); pool.fee\n}","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » Generic and behavior","id":"31","title":"Generic and behavior"},"32":{"body":"You can create a reference with & and &mut. You cannot use the mut keyword during assignment, .e.g., let mut value = ... will not compile. Global storage operators move_to, move_from, borrow_global_mut, borrow_global, and exists in Move enable reading from and writing to resources stored in the blockchain's global storage. The acquires keyword is used to specify which resources a function acquires ownership of a resource during execution. module collection::collection { use std::signer; struct Item has store, drop {} struct Collection has key, store { items: vector- } public fun add_item(account: &signer) acquires Collection { let collection = borrow_global_mut
(signer::address_of(account)); vector::push_back(&mut collection.items, Item {}); }\n} Move allows the creation of read-only references to resources, ensuring that functions cannot modify them. Here's a small code snippet demonstrating the use of Move syntax:","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » Resources, References, and Mutation","id":"32","title":"Resources, References, and Mutation"},"33":{"body":"The public keyword in Move indicates that a function can be invoked from outside the current module. The native keyword is used to declare functions that are implemented in the blockchain runtime or in an external module. There are VM specific directives; in Movement we will address #[inline], #[view], #[test_only], and #[test].","breadcrumbs":"Week 1: Introduction to Move and Movement » Basic Move Syntax » Misc. syntax","id":"33","title":"Misc. syntax"},"34":{"body":"This section treats with the basic functionality of the module and build system for Move.","breadcrumbs":"Week 1: Introduction to Move and Movement » Module and Build System » Modules and Build System","id":"34","title":"Modules and Build System"},"35":{"body":"A folder with a Move.toml and compilable move code is a package. Packages may define external dependencies, which can be local or store at a remote repository. All Move clients used herein will automatically fetch and compile dependencies. When using movement, we will also define package addresses in the Move.toml. [package]\nname = \"hello_world\"\nversion = \"0.0.0\" [dependencies]\n# MoveNursery = { git = \"https://github.com/move-language/move.git\", subdir = \"language/move-stdlib/nursery\", rev = \"main\" }\nMovementFramework = { git = \"https://github.com/movemntdev/movement-subnet.git\", subdir = \"vm/aptos-vm/aptos-move/aptos-framework\", rev = \"main\" } [addresses]\nstd = \"0x1\"\nhello_blockchain = \"_\"","breadcrumbs":"Week 1: Introduction to Move and Movement » Module and Build System » Packages","id":"35","title":"Packages"},"36":{"body":"Move has two different types of program: modules and scripts . As a general rule, you should use scripts for short proofs of concept or as an entrypoint, see Script Based Design . You can define multiple scripts and modules in the same file.","breadcrumbs":"Week 1: Introduction to Move and Movement » Module and Build System » Program types","id":"36","title":"Program types"},"37":{"body":"Modules are great for code reuse. They can be reference and linked. A module takes the following form. module :: { (