forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move] reorganize examples directory
- Splitting the examples directory into several smaller directories with clearly defined themes - Added a README to each dir with brief descriptions of the examples (including teasers of some coming soon) - Minor cleanup/refactoring to prevent dependencies between example dirs
- Loading branch information
1 parent
2f50ab5
commit 6add802
Showing
25 changed files
with
459 additions
and
130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "Basics" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
Sui = { local = "../../framework" } | ||
|
||
[addresses] | ||
Basics = "0x0" | ||
|
||
[dev-addresses] | ||
Basics = "0x0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Basics | ||
|
||
Very basic examples to illustrate the nuts and bolts of programming in Sui. | ||
|
||
* Object: a heavily commented example of a custom object. | ||
* Sandwich: example of object exchange logic--combining ham and bread objects to produce a sandwich. |
2 changes: 1 addition & 1 deletion
2
...xamples/sources/CustomObjectTemplate.move → ...ility/examples/basics/sources/Object.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "DeFi" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
Sui = { local = "../../framework" } | ||
|
||
[addresses] | ||
DeFi = "0x0" | ||
|
||
[dev-addresses] | ||
DeFi = "0x0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# DeFi | ||
|
||
* Escrow: an atomic swap leveraging an escrow agent that is trusted for liveness, but not safety (i.e., the agent cannot steal the goods being swapped). | ||
* Uniswap 1.0-style DEX (coming soon). |
6 changes: 2 additions & 4 deletions
6
...rammability/framework/sources/Escrow.move → ...ability/examples/defi/sources/Escrow.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "FungibleTokens" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
Sui = { local = "../../framework" } | ||
|
||
[addresses] | ||
FungibleTokens = "0x0" | ||
|
||
[dev-addresses] | ||
FungibleTokens = "0x0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Fungible Tokens | ||
|
||
* MANAGED: a token managed by a treasurer trusted for minting and burning. This is how (e.g.) a fiat-backed stablecoin would work. | ||
* FIXED: a token with a fixed supply (coming soon). | ||
* ALGO: a token with an algorithmic issuance policy (coming soon). |
43 changes: 43 additions & 0 deletions
43
sui_programmability/examples/fungible_tokens/sources/MANAGED.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/// Example coin with a trusted manager responsible for minting/burning (e.g., a stablecoin) | ||
/// By convention, modules defining custom coin types use upper case names, in constrast to | ||
/// ordinary modules, which use camel case. | ||
module FungibleTokens::MANAGED { | ||
use Sui::Coin::{Self, Coin, TreasuryCap}; | ||
use Sui::Transfer; | ||
use Sui::TxContext::{Self, TxContext}; | ||
|
||
/// Name of the coin. By convention, this type has the same name as its parent module | ||
/// and has no fields. The full type of the coin defined by this module will be `COIN<MANAGED>`. | ||
struct MANAGED has drop {} | ||
|
||
/// Register the trusted currency to acquire its `TreasuryCap`. Because | ||
/// this is a module initializer, it ensures the currency only gets | ||
/// registered once. | ||
fun init(ctx: &mut TxContext) { | ||
// Get a treasury cap for the coin and give it to the transaction | ||
// sender | ||
let treasury_cap = Coin::create_currency<MANAGED>(MANAGED{}, ctx); | ||
Transfer::transfer(treasury_cap, TxContext::sender(ctx)) | ||
} | ||
|
||
/// Manager can mint new coins | ||
public fun mint(treasury_cap: &mut TreasuryCap<MANAGED>, amount: u64, ctx: &mut TxContext): Coin<MANAGED> { | ||
Coin::mint<MANAGED>(amount, treasury_cap, ctx) | ||
} | ||
|
||
/// Manager can burn coins | ||
public fun burn(treasury_cap: &mut TreasuryCap<MANAGED>, coin: Coin<MANAGED>, _ctx: &mut TxContext) { | ||
Coin::burn(coin, treasury_cap) | ||
} | ||
|
||
/// Manager can transfer the treasury capability to a new manager | ||
public fun transfer_cap(treasury_cap: TreasuryCap<MANAGED>, recipient: address, _ctx: &mut TxContext) { | ||
Coin::transfer_cap<MANAGED>(treasury_cap, recipient); | ||
} | ||
|
||
#[test_only] | ||
/// Wrapper of module initializer for testing | ||
public fun test_init(ctx: &mut TxContext) { | ||
init(ctx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "Games" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
Sui = { local = "../../framework" } | ||
|
||
[addresses] | ||
Games = "0x0" | ||
|
||
[dev-addresses] | ||
Games = "0x0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Games | ||
|
||
Examples of toy games built on top of Sui! | ||
|
||
* Tic Tac Toe: the pencil and paper classic, now on Sui. | ||
* Hero: an adventure game where an intrepid hero slays vicious boars with a magic sword and heals himself with potions. | ||
* Sea Hero: a permissionless mod of the Hero game where the hero can slay sea monsters to earn RUM tokens. | ||
* Sea Hero Helper: a permissionless mod of the economics of the Sea Hero game. A weak hero can request help from a stronger hero, who receives a share of the monster slaying reward. | ||
* Rock Paper Scissors (coming soon). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mmability/examples/sources/TicTacToe.move → ...ity/examples/games/sources/TicTacToe.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Examples::TicTacToe { | ||
module Games::TicTacToe { | ||
use Std::Option::{Self, Option}; | ||
use Std::Vector; | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
...bility/examples/tests/TicTacToeTests.move → .../examples/games/tests/TicTacToeTests.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.