From 2c161c5abfe991436f64159ca0459f5486deafeb Mon Sep 17 00:00:00 2001
From: Liam Monninger 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.
+diff --git a/book/book/index.html b/book/book/index.html index d297f08..e2f3cf2 100644 --- a/book/book/index.html +++ b/book/book/index.html @@ -30,6 +30,8 @@ + + @@ -149,6 +157,9 @@This book has an accompanying GitHub repository here. You can also navigate to it by clicking the icon on any page.
+
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.
+diff --git a/book/book/print.html b/book/book/print.html index e02d228..3524b61 100644 --- a/book/book/print.html +++ b/book/book/print.html @@ -31,6 +31,8 @@ + +This book has an accompanying GitHub repository here. You can also navigate to it by clicking the icon on any page.
+
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.
+
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.
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
.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.
@@ -338,14 +347,15 @@&
. &
and &mut
. mut
keyword during assignment, .e.g., let mut value = ...
will not compile.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.acquires
keyword is used to specify which resources a function acquires ownership of a resource during execution.#![allow(unused)] fn main() { module collection::collection { + use std::signer; struct Item has store, drop {} struct Collection has key, store { @@ -448,6 +458,13 @@
named_a
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 atexamples/move/hello_world
.+Learnings leveraged:
++
+- Basic Move syntax
+- Byte strings
+#![allow(unused)] fn main() { script { @@ -472,82 +489,170 @@
💻 HelloWorld<
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
.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
.++Learnings leveraged:
++
+- Basic Move syntax
+- Byte strings
+💻 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
.+Learnings leveraged:
++
+- Basic Move syntax
+- Vectors
+- BCS
+- Move idioms
+💻 ResourceRoulette
-A game of roulette on MoveVM. Place your address on an element in the vector. Contains methods
+public fun bid
andpublic fun spin
. Receive a payout if you placed your address on the correct cell. You can find it and instructions to run itexamples/move/resource_roulette
.A game of roulette on MoveVM. Place your address on an element in the vector. Contains methods
+public fun bid
andpublic fun spin
. Receive a payout if you placed your address on the correct cell. You can find it and instructions to run it atexamples/move/resource_roulette
.+Learnings leveraged:
++
+- Basic Move syntax
+- Signer and address types
+- Borrows
+- Initialization
+- Move idioms
+#![allow(unused)] fn main() { module resource_roulette::resource_roulette { use std::vector; + use std::signer; + + const ENO_UNAUTHORIZED_ADDRESS : u64 = 0; // ResourceRoulette struct representing the contract state - struct ResourceRoulette { + struct ResourceRoulette has key { bids: vector<vector<address>>, owner: address, + state : u64 } - struct RouletteWinnings { + struct RouletteWinnings has key { amount : u64 } // Initialization function for the ResourceRoulette contract - public entry fun init(account: &signer) { + public fun init(account: &signer) { + + assert!(signer::address_of(account) == @resource_roulette, ENO_UNAUTHORIZED_ADDRESS); let bids = vector::empty<vector<address>>(); let i = 0; - while i < 32 { - vector::push_back(&mut bids, vector::empty<address>()) + while (i < 32) { + vector::push_back(&mut bids, vector::empty<address>()); i = i + 1; }; - move_to<ResourceRoulette>(account, ResourceRoulette { + move_to(account, ResourceRoulette { bids, owner: @resource_roulette, + state : 17203943403948 }); } + // Initializes winnings for a signer + public fun init_winnings(account: &signer) { + move_to(account, RouletteWinnings { + amount: 0, + }); + } + // Bid function to allow signers to bid on a specific slot - public entry fun bid(sender: &signer, slot: u8) acquires ResourceRoulette { - let roulette = borrow_global_mut<ResourceRoulette>(@resource_roulette); - let bids_size = vector::length(&roulette.bids); - assert!(slot < bids_size, 99); - // assert bids size does not exceed 100 - assert!(bids_size < 100, 0); - - let slot_bids = vector::borrow_mut(&mut roulette.bids, slot); - vector::push_back(&mut slot_bids, signer::address_of(sender)); + public fun bid(account : &signer, slot: u8) acquires ResourceRoulette { + + if (!exists<RouletteWinnings>(signer::address_of(account))) { + init_winnings(account); + }; + + let self = borrow_global_mut<ResourceRoulette>(@resource_roulette); + roll_state(self); + let bids_size = vector::length(&self.bids); + assert!(slot < (bids_size as u8), 99); + let slot_bids = vector::borrow_mut(&mut self.bids, (slot as u64)); + vector::push_back(slot_bids, signer::address_of(account)); + } - public fun total_bid(): u64 acquires ResourceRoulette { + public fun total_bid() : u64 { // Make this more complex to support actual bidding - let roulette = borrow_global<ResourceRoulette>(@resource_roulette); - vector::length(&roulette.bids) + return 100 } - // Roll function to select a pseudorandom slot and pay out all signers who selected that slot - public entry fun spin(sender: &signer) acquires ResourceRoulette { - let roulette = ResourceRoulette::borrow_global_mut(); - assert!(singer::address_of(sender) == roulette.owner, 98); + // rolls state using xoroshiro prng + fun roll_state(self :&mut ResourceRoulette) { + let state = (self.state as u256); + let x = state; + let y = state >> 64; + + let t = x ^ y; + state = ((x << 55) | (x >> 9)) + y + t; + + y = y ^ x; + state = state + ((y << 14) | (y >> 50)) + x + t; + + state = state + t; + state = state % (2^128 - 1); + self.state = (state as u64); - let resource_vector_size = vector::length(&roulette.bids); - let winning_slot = (0x1000 % resource_vector_size) as u8; + } - let winners = vector::borrow(&roulette.bids, winning_slot); + public fun get_noise() : u64 { + 1 + } - let num_winners = vector::length(&winners_vec); - let balance_per_winner = total_bid() / num_winners as u64; + fun empty_bids(self : &mut ResourceRoulette){ - let mut i = 0; - while i < num_winners { - let winner = vector::borrow(&winners_vec, i); - let mut winnings = borrow_global_mut<RouletteWinnings>(winner); - winnings.amount = winnings.amount + balance_per_winner; + // empty the slots + let bids = vector::empty<vector<address>>(); + let i = 0; + while (i < 32) { + vector::push_back(&mut bids, vector::empty<address>()); i = i + 1; }; + self.bids = bids; } + // Roll function to select a pseudorandom slot and pay out all signers who selected that slot + public fun spin() acquires ResourceRoulette, RouletteWinnings { + + let self = borrow_global_mut<ResourceRoulette>(@resource_roulette); + + // get the winning slot + let bids_size = vector::length(&self.bids); + roll_state(self); + let winning_slot = (get_noise() * self.state % (bids_size as u64)) ; + + // pay out the winners + let winners = vector::borrow(&self.bids, winning_slot); + let num_winners = vector::length(winners); + + if (num_winners > 0){ + let balance_per_winner = total_bid()/( num_winners as u64); + let i = 0; + while (i < num_winners) { + let winner = vector::borrow(winners, i); + let winnings = borrow_global_mut<RouletteWinnings>(*winner); + winnings.amount = winnings.amount + balance_per_winner; + i = i + 1; + }; + }; + + empty_bids(self); + + } + + // tests... + } }
Movement Standard Library
@@ -873,6 +978,7 @@💻 MoveNav
use std::vector; use std::option; use std::debug; + use std::string; struct Graph { nodes: vector<Vector3>, @@ -897,7 +1003,7 @@💻 MoveNav
} struct NavigationType { - name: string, + name: string::String, speed: u8, } @@ -909,22 +1015,22 @@💻 MoveNav
if nav_type.name == "Walk" { debug::print("Walking at speed ", nav_type.speed); // Perform walking navigation logic - return option::None; + return option::none() } if nav_type.name == "Run" { debug::print("Running at speed ", nav_type.speed); // Perform running navigation logic - return option::None; + return option::none() } if nav_type.name == "Fly" { debug::print("Flying at speed ", nav_type.speed); // Perform flying navigation logic - return option::None; + return option::none() } else { debug::print("Unsupported navigation type"); - return option::None; + return option::none() } @@ -1148,9 +1254,52 @@Semi-automati
In many cases, you will find opportunities to automate the inspection of resources via
bash
,python
, and other scripts. As you develop any of these testing strategies, we encourage you to share them with us so that we might make improvements to our CLI's capabilities.+Share -{: .share-block} Share your semi-automated workflows with us!
Testing directives
+Movement provides several directives for testing which are important to understand.
++
#[test]
Marks a test function. Can be provided with arguments.
+When testing procedures that require signers, you will need set their values in the directive. Take the example below from 💻 ResourceRoulette
++#![allow(unused)] +fn main() { + #[test(account = @resource_roulette, bidder_one = @0x3)] +#[expected_failure(abort_code = FLAG_WINNER)] +public fun test_wins(account : &signer, bidder_one : &signer) acquires +}
Here our test expects both resource account, i.e.,
+resource_roulette
, and a bidder signer, i.e.,bidder_one
. We will discuss how these are used below.+
#[test_only]
Test only is used for defining symbols that will only be compiled when testing. It can be useful for creating mocks and stubs, test boundaries and more.
++
#[expect_failure]
Allows you to check if a routine aborts as expected, i.e., matching a certain error code.
+In addition to asserting intended failures, you can use this behavior to define more complex tests that are based on boundary conditions being crossed. The example below from 💻 Resource Roulette uses this pattern to test whether winners emerge from the pseudorandom spinner.
+#![allow(unused)] +fn main() { +#[test_only] +const BOUNDARY_WINNER : u64 = 1; + +// Under the current state rolling implementation this will work +// More robust testing would calculate system dynamics +#[test(account = @resource_roulette, bidder_one = @0x3)] +#[expected_failure(abort_code = FLAG_WINNER)] +public fun test_wins(account : &signer, bidder_one : &signer) acquires ResourceRoulette, RouletteWinnings { + + init(account); + let i : u64 = 0; + while (i < 1_000) { + bid(bidder_one, 7); + spin(); + + let winnings = borrow_global<RouletteWinnings>(signer::address_of(bidder_one)); + if (winnings.amount > 0) { + abort BOUNDARY_WINNER + }; + + i = i + 1; + }; + +} +}
Mocks, stubs, and state-based simulation
In order to simulate and control the behavior of dependencies or external systems during testing, you may whish to apply mocking, stubbing, and stated-based simulation strategies.
Mocks and stubs
@@ -1207,7 +1356,6 @@For
movement<
Contribution -{: .contributor-block} Help us develop mocking and stubbing tools for Movement.
Design Patterns
@@ -1752,7 +1900,9 @@Bugs
diff --git a/book/book/searchindex.js b/book/book/searchindex.js index ed20d7c..5d3021d 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#-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#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":57,"breadcrumbs":4,"title":2},"1":{"body":30,"breadcrumbs":10,"title":5},"10":{"body":47,"breadcrumbs":13,"title":6},"100":{"body":17,"breadcrumbs":7,"title":1},"101":{"body":21,"breadcrumbs":7,"title":1},"102":{"body":52,"breadcrumbs":7,"title":1},"103":{"body":0,"breadcrumbs":15,"title":5},"104":{"body":174,"breadcrumbs":11,"title":1},"105":{"body":58,"breadcrumbs":11,"title":1},"106":{"body":67,"breadcrumbs":11,"title":1},"107":{"body":40,"breadcrumbs":12,"title":2},"108":{"body":43,"breadcrumbs":12,"title":2},"109":{"body":62,"breadcrumbs":12,"title":2},"11":{"body":36,"breadcrumbs":13,"title":6},"110":{"body":43,"breadcrumbs":12,"title":2},"111":{"body":59,"breadcrumbs":13,"title":3},"112":{"body":12,"breadcrumbs":9,"title":2},"113":{"body":67,"breadcrumbs":9,"title":2},"114":{"body":119,"breadcrumbs":10,"title":3},"115":{"body":68,"breadcrumbs":9,"title":2},"116":{"body":13,"breadcrumbs":7,"title":1},"117":{"body":35,"breadcrumbs":7,"title":1},"118":{"body":35,"breadcrumbs":7,"title":1},"119":{"body":0,"breadcrumbs":10,"title":4},"12":{"body":45,"breadcrumbs":15,"title":8},"120":{"body":17,"breadcrumbs":7,"title":1},"121":{"body":235,"breadcrumbs":7,"title":1},"122":{"body":23,"breadcrumbs":7,"title":1},"123":{"body":0,"breadcrumbs":8,"title":2},"124":{"body":27,"breadcrumbs":8,"title":2},"125":{"body":22,"breadcrumbs":8,"title":2},"126":{"body":37,"breadcrumbs":9,"title":3},"127":{"body":146,"breadcrumbs":7,"title":1},"128":{"body":0,"breadcrumbs":9,"title":3},"129":{"body":12,"breadcrumbs":16,"title":10},"13":{"body":38,"breadcrumbs":10,"title":3},"130":{"body":18,"breadcrumbs":10,"title":4},"131":{"body":14,"breadcrumbs":10,"title":4},"132":{"body":16,"breadcrumbs":8,"title":2},"133":{"body":18,"breadcrumbs":6,"title":3},"134":{"body":15,"breadcrumbs":9,"title":3},"135":{"body":26,"breadcrumbs":7,"title":1},"136":{"body":15,"breadcrumbs":8,"title":2},"137":{"body":34,"breadcrumbs":7,"title":1},"138":{"body":52,"breadcrumbs":7,"title":1},"139":{"body":34,"breadcrumbs":7,"title":1},"14":{"body":63,"breadcrumbs":9,"title":2},"140":{"body":25,"breadcrumbs":7,"title":1},"141":{"body":11,"breadcrumbs":5,"title":1},"142":{"body":233,"breadcrumbs":6,"title":2},"143":{"body":0,"breadcrumbs":6,"title":2},"144":{"body":55,"breadcrumbs":7,"title":3},"145":{"body":48,"breadcrumbs":5,"title":1},"146":{"body":64,"breadcrumbs":5,"title":1},"147":{"body":12,"breadcrumbs":5,"title":1},"148":{"body":13,"breadcrumbs":6,"title":2},"149":{"body":11,"breadcrumbs":5,"title":1},"15":{"body":13,"breadcrumbs":9,"title":2},"150":{"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":37,"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":71,"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":49,"breadcrumbs":10,"title":1},"43":{"body":14,"breadcrumbs":10,"title":1},"44":{"body":168,"breadcrumbs":10,"title":1},"45":{"body":24,"breadcrumbs":11,"title":3},"46":{"body":62,"breadcrumbs":10,"title":2},"47":{"body":10,"breadcrumbs":10,"title":2},"48":{"body":34,"breadcrumbs":9,"title":1},"49":{"body":31,"breadcrumbs":9,"title":1},"5":{"body":91,"breadcrumbs":12,"title":5},"50":{"body":17,"breadcrumbs":9,"title":1},"51":{"body":30,"breadcrumbs":11,"title":3},"52":{"body":17,"breadcrumbs":9,"title":1},"53":{"body":20,"breadcrumbs":12,"title":6},"54":{"body":31,"breadcrumbs":14,"title":4},"55":{"body":76,"breadcrumbs":11,"title":1},"56":{"body":173,"breadcrumbs":16,"title":6},"57":{"body":116,"breadcrumbs":17,"title":7},"58":{"body":208,"breadcrumbs":12,"title":2},"59":{"body":132,"breadcrumbs":13,"title":3},"6":{"body":38,"breadcrumbs":11,"title":4},"60":{"body":139,"breadcrumbs":11,"title":1},"61":{"body":13,"breadcrumbs":14,"title":4},"62":{"body":21,"breadcrumbs":8,"title":1},"63":{"body":31,"breadcrumbs":9,"title":2},"64":{"body":86,"breadcrumbs":10,"title":3},"65":{"body":70,"breadcrumbs":9,"title":2},"66":{"body":0,"breadcrumbs":12,"title":3},"67":{"body":397,"breadcrumbs":12,"title":3},"68":{"body":27,"breadcrumbs":11,"title":2},"69":{"body":26,"breadcrumbs":10,"title":1},"7":{"body":35,"breadcrumbs":10,"title":3},"70":{"body":28,"breadcrumbs":10,"title":1},"71":{"body":9,"breadcrumbs":10,"title":1},"72":{"body":15,"breadcrumbs":8,"title":1},"73":{"body":87,"breadcrumbs":10,"title":3},"74":{"body":117,"breadcrumbs":9,"title":2},"75":{"body":36,"breadcrumbs":9,"title":2},"76":{"body":184,"breadcrumbs":8,"title":1},"77":{"body":27,"breadcrumbs":9,"title":2},"78":{"body":17,"breadcrumbs":12,"title":5},"79":{"body":97,"breadcrumbs":9,"title":2},"8":{"body":41,"breadcrumbs":9,"title":2},"80":{"body":37,"breadcrumbs":10,"title":3},"81":{"body":131,"breadcrumbs":8,"title":1},"82":{"body":17,"breadcrumbs":10,"title":2},"83":{"body":0,"breadcrumbs":14,"title":4},"84":{"body":10,"breadcrumbs":11,"title":1},"85":{"body":63,"breadcrumbs":11,"title":1},"86":{"body":28,"breadcrumbs":11,"title":1},"87":{"body":35,"breadcrumbs":11,"title":1},"88":{"body":11,"breadcrumbs":10,"title":5},"89":{"body":38,"breadcrumbs":9,"title":2},"9":{"body":24,"breadcrumbs":10,"title":3},"90":{"body":24,"breadcrumbs":8,"title":1},"91":{"body":17,"breadcrumbs":7,"title":1},"92":{"body":23,"breadcrumbs":7,"title":1},"93":{"body":0,"breadcrumbs":8,"title":2},"94":{"body":98,"breadcrumbs":7,"title":1},"95":{"body":130,"breadcrumbs":8,"title":2},"96":{"body":23,"breadcrumbs":7,"title":1},"97":{"body":0,"breadcrumbs":9,"title":3},"98":{"body":16,"breadcrumbs":8,"title":2},"99":{"body":43,"breadcrumbs":8,"title":2}},"docs":{"0":{"body":"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 .","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":"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":"100","title":"Encryption"},"101":{"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":"101","title":"Pseudonymization"},"102":{"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":"102","title":"DoS"},"103":{"body":"","breadcrumbs":"Week 3: M1 and DeFi Applications » Common Blockchain System Design Patterns » Common blockchain system design patterns","id":"103","title":"Common blockchain system design patterns"},"104":{"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":"104","title":"Oracles"},"105":{"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":"105","title":"Rollups"},"106":{"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":"106","title":"Tokenization"},"107":{"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":"107","title":"State Channels"},"108":{"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":"108","title":"Side Chains"},"109":{"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":"109","title":"Collaborative Governance"},"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":"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":"110","title":"Atomic Swaps"},"111":{"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":"111","title":"Proofs and Zero-Knowledge"},"112":{"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":"112","title":"Access Control"},"113":{"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":"113","title":"Signatures and certificates"},"114":{"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":"114","title":"ACLs, RBAC, and ABAC"},"115":{"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":"115","title":"Permissioned chains"},"116":{"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":"116","title":"DeFi"},"117":{"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":"117","title":"What is DeFi?"},"118":{"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":"118","title":"Why Decentralize?"},"119":{"body":"","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Financial Applications of Decentralized Systems","id":"119","title":"Financial Applications of Decentralized Systems"},"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":"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":"120","title":"Purchasing"},"121":{"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":"121","title":"Lending"},"122":{"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":"122","title":"Trading"},"123":{"body":"","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » DeFi Phenomena","id":"123","title":"DeFi Phenomena"},"124":{"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":"124","title":"Yield Farming"},"125":{"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":"125","title":"Flash Loans"},"126":{"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":"126","title":"Automated Market Making"},"127":{"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":"127","title":"Coins"},"128":{"body":"","breadcrumbs":"Week 3: M1 and DeFi Applications » DeFi » Important DeFi Algorithms","id":"128","title":"Important DeFi Algorithms"},"129":{"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":"129","title":"Constant Product Market Maker (CPMM) and Constant Mean Market Maker (CMMM)"},"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":"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":"130","title":"Fraud Proof and Binary Search"},"131":{"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":"131","title":"Modern Portfolio Theory (MPT)"},"132":{"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":"132","title":"Risk Models"},"133":{"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":"133","title":"Week 4: Projects"},"134":{"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":"134","title":"Project Requirements and Recommendations"},"135":{"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":"135","title":"Requirements"},"136":{"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":"136","title":"Project recommendations"},"137":{"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":"137","title":"dApps"},"138":{"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":"138","title":"Infrastructure"},"139":{"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":"139","title":"Bounties"},"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":"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":"140","title":"Contribute"},"141":{"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":"141","title":"Guidelines"},"142":{"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":"142","title":"Requirements Gathering"},"143":{"body":"","breadcrumbs":"Week 4: Projects » Guidelines » Pitching and presenting","id":"143","title":"Pitching and presenting"},"144":{"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":"144","title":"Crafting a paper and deck"},"145":{"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":"145","title":"The pitch"},"146":{"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":"146","title":"The presentation"},"147":{"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":"147","title":"Support"},"148":{"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":"148","title":"General outreach"},"149":{"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":"149","title":"Bugs"},"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":"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":"150","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. The signer type represents the sender of a transaction and is used for access control and authentication.","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 &. Reference 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 { 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 :: { (