Cluster 2 -- Weeks 2 & 3
Concepts
Core concepts covered in this cluster
Intro to the CosmWasm Smart Contract / Template
Schema, Instantiate, Test, Execute, Query, Storage
Unit Testing (How & Why), Error Handling
CosmWasm / Anatomy / CosmWasm Plus Intro
Smart Contract Logic, Architecture, Mechanism, Design, Navigation, State, Security
Reference Materials
Smart Contracts
List of Cosmos SDK Modules
Crate CosmWasm
Sample CosmWasm Contracts
CosmWasm Plus
CosmWasm Contracts
Rust Resource
Anatomy of a Smart Contract
Developing a Smart Contract
HackAtom Seoul (Video)
Integration Testing
Schema
Testing
Unit Testing
Testing
Solidity vs. Rust CW
Assignments
1) Rust Concept Video
Create a 3-5 minute video explaining a core Rust concept that is used in Smart Contracts. Please use a code along approach with your editor on screen. You can choose whether or not you have your face on the video.
2) Code Journals
Mastery of a skill comes from immersing yourself in the study and use of it in many different ways.
For the Code Study Journal, you will need to complete 3 code journals per week for the first three weeks (due by Sunday midnight UTC). You will send these to GitHub-as prescribed for all Cohort work [NOTE: each journal entry should focus on 30-50 lines of code- meaning your total annotated should be between 90-150. If you end up doing a single contract that is 90-150 lines, that works for all 3 that week]
Here are the steps to complete each one:
Select a piece of code/ smart contract. To start there will be choices provided, or you can find a sample on your own- CW-Plus is a great resource you will learn to use during this course. It is a collection of CosmWasm smart contracts, many of which are production ready. The faster you get comfortable with CW Plus, the better off you will be.
You should annotate the code- in other words, make notes on the document explaining what is happening through the code.
What are the concepts (borrowing, ownership, vectors etc)
What is the organization?
What is the contract doing? What is the mechanism?
How could it be better? More efficient? Safer?
During the first month, you will make changes to the code that you think would make it better. Or write your own versions.
Once a month, we will ask you to make a video of your code study, and show an example of how you made the code better, test, compile, and deploy it on video.
We ask that you interpret and apply these instructions in the way you understand them. Not everyone will do so the same way. There are no wrong answers- the only way to fail this part is to not do it and ship on time.
Engagement through reading, thinking, and writing about code in this way leads to your own discovery of the how, what, where, when, why of smart contracts- architecture & mechanism .
We are interested in how YOU do this process.
Code Journal Example
use cosmwasm_std::Uint128; //You can comment on the side, like this
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use cw20::{Cw20ReceiveMsg, Denom};
pub use cw_controllers::ClaimsResponse;
use cw_utils::Duration;
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct InstantiateMsg {
/// denom of the token to stake
pub denom: Denom,
pub tokens_per_weight: Uint128,
pub min_bond: Uint128,
pub unbonding_period: Duration,
// admin can only add/remove hooks, not change other parameters
pub admin: Option<String>,
}
//YOU CAN ALSO BOLD/ CAPS AND COMMENT ABOVE A SECTION LIKE THIS.
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
/// Bond will bond all staking tokens sent with the message and update membership weight
Bond {},
/// Unbond will start the unbonding process for the given number of tokens.
/// The sender immediately loses weight from these tokens, and can claim them
/// back to his wallet after `unbonding_period`
Unbond { tokens: Uint128 },
/// Claim is used to claim your native tokens that you previously "unbonded"
/// after the contract-defined waiting period (eg. 1 week)
Claim {},
/ Hooks {},
Adding Additional Questions
Copy the questions below and provide the answer for each Code Journal you complete.
What are the concepts (borrowing, ownership, vectors etc)
What is the organization?
What is the contract doing? What is the mechanism?
How could it be better? More efficient? Safer?
The code could be safer and better if…..
For Clusters 1 & 2 you will make changes to the code that you think would make it better.
For Clusters 3-5, we will ask you to imitate the code in your own way and write your own as part of the process.
use cosmwasm_std::Uint128; You can comment on the side, like this
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use cw20::{Cw20ReceiveMsg, Denom};
pub use cw_controllers::ClaimsResponse;
use cw_utils::Duration;
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct InstantiateMsg {
/// denom of the token to stake
pub denom: Denom,
pub tokens_per_weight: Uint128,
pub min_bond: Uint128,
pub unbonding_period: Duration,
// admin can only add/remove hooks, not change other parameters
pub admin: Option<String>,
}
1) What are the concepts (borrowing, ownership, vectors etc)
The Concepts in the Code are… they are —---
2) What is the organization?
The code is organized……
3) What is the contract doing? What is the mechanism?
The contract is a staking contract and the mechanism…
4) How could it be better? More efficient? Safer?
The code could be safer and better if…..
During the first month, you will make changes to the code that you think would make it better.
After Cluster 2, we will ask you to imitate the code in your own way and write your own as part of the process.
3) Hacked Contracts from Class
Make sure you push your hacked code from class to the WBA Github with correct naming conventions.
Make ExecuteMsg::AddMessage require a fee of native tokens to add a message
Add a way to "Like" a message, this should also require a fee.
Verify both fee's being sent in are the correct amount and denom
Use a BankMsg::Send message to send the native tokens from a like to the user who added the original message
Last updated
