Details on how Starcoin upgrades Stdlib with on-chain governance

Smart Contracts: Starcoin vs ETH

1.Languages used by smart contracts

2. Smart contract invocation and storage

Smart Contract Upgrade: Starcoin vs ETH

Contract upgrade solution: Starcoin vs ETH

1.PENDING

2. ACTIVE

3. AGREED

4.QUEUED

5.EXECTABLE

6. ETRACTED

7. Upgrade complete

Stdlib upgrade practice

1.Write the code in stdlib

/// Anyone can mint DummyToken, amount should < 10000
public fun mint(_account: &signer, amount: u128) : Token<DummyToken> acquires SharedMintCapability{
assert(amount <= 10000, Errors::invalid_argument(EMINT_TOO_MUCH));
let cap = borrow_global<SharedMintCapability>(token_address());
Token::mint_with_capability(&cap.cap, amount)
}

// Add new function here
public fun Mymint(_account: &signer) : Token<DummyToken> acquires SharedMintCapability{
let cap = borrow_global<SharedMintCapability>(token_address());
Token::mint_with_capability(&cap.cap, 100)
}

/// Return the token address.
public fun token_address(): address {
Token::token_address<DummyToken>()
}
public(script) fun mint(sender: signer, amount: u128){
let token = DummyToken::mint(&sender, amount);
let sender_addr = Signer::address_of(&sender);
if(Account::is_accept_token<DummyToken>(sender_addr)){
Account::do_accept_token<DummyToken>(&sender);
};
Account::deposit(sender_addr, token);
}

//Add the new script function here
public(script) fun Mymint(sender:signer){
let token = DummyToken::Mymint(&sender);
let sender_addr = Signer::address_of(&sender);
if(Account::is_accept_token<DummyToken>(sender_addr)){
Account::do_accept_token<DummyToken>(&sender);
};
Account::deposit(sender_addr, token);
}

2. Prepare the compiled binary Module

Execute
dev compile -s 0x1 path/to/DummyToken.move

Result
{
"ok": [
"path/to/DummyToken.mv",
"path/to/DummyTokenScripts.mv"
]
}
Execute
dev package -n MymintUpgrade -o storage path/to/DummyToken*

Result
{
"ok": {
"file": "path/to/storage/MymintUpgrade.blob",
"package_hash": "0x6e54935144115233c9decb255d3bcd5f14c7b9d82c968c5f3a0cb1b14f18bce8"
}
}

3. Prepare the account number and balance

Default account acquisition
dev get-coin -v 6000000STC
Transfer method
account transfer -s 0x0000000000000000000000000a550c18 -r <Account Receipt Identifier> -v 60000000000000000 -b

4. submit proposal Enter PENDING

Submit a Proposal
dev module-proposal -s <account address> -m <module path> -v <version> -e false

5. Query the status of the proposal

dev call --function 0x1::Dao::proposal_info -t 0x1::STC::STC -t 0x1::UpgradeModuleDaoProposal::UpgradeModuleV2 --arg <proposal address>
dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::UpgradeModuleDaoProposal::UpgradeModuleV2 --arg <proposal address> --arg <proposal_id>
Results:
{
"ok": [
<state_num>
]
}

6. wait for community debate Enter ACTIVE

Acceleration time
dev sleep -t 3600000
Generate blocks (effective time)
dev gen-block
Execute
dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::UpgradeModuleDaoProposal::UpgradeModuleV2 --arg <proposal address> --arg <proposal_id>
Result
{
"ok": [
2
]
}
Change to ACTIVE state

7. Community Voting Enter AGREED

Vote
account execute-function -s <account address> --function 0x1::DaoVoteScripts::cast_vote -t 0x1::STC::STC -t 0x1::UpgradeModuleDaoProposal::UpgradeModuleV2 --arg <proposal address> --arg <proposal_id> --arg true --arg 59000000000000000u128

8. AGREED proposals are placed in the update queue into QUEUED

dev module-queue -s <account address> -a <proposal address> -i <proposal_id>

9. public-period wait Enter EXECTABLE

Acceleration time
dev sleep -t 3600000
Generate blocks (effective time)
dev gen-block

10. submit the upgrade plan Enter ETRACTED

dev module-plan -i <proposal_id> -a <proposal address>  -s <account address>

11. Commit the code to Upgrade complete

dev module_exe -m path/to/storage/MymintUpgrade.blob -s <account address>

12. Complete the contract upgrade process

13. Verification of upgrade

Execute to get DummyToken 100
account execute-function --function 0x1::DummyTokenScripts::Mymint -b -s <account address>
ViewDummyToken:
account show <account address>
Result
"balances": {
"0x00000000000000000000000000000001::DummyToken::DummyToken": 100,
"0x00000000000000000000000000000001::STC::STC": 9999645054
}

--

--

--

Starcoin is a proof-of-work blockchain that enables secure smart contracts to power services in decentralized finance, gaming and NFTs.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Amun DeFi Review: Automating Portfolios to Take the Guesswork Out of Investing

CCM—The first legally issued game virtual currency logs into Uniswap

OHM vs TOAD

Top-5 Bitcoin Hardware Wallets of 2017–2018 (+ Altcoin Supported)

Galactic Blue Index Report #31

Introducing the Showcase Incentivized Community Program

YIELD App acts as corporate treasurer for gaming platform Lepricon

Galactic Blue Index Report #32

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Starcoin

Starcoin

Starcoin is a proof-of-work blockchain that enables secure smart contracts to power services in decentralized finance, gaming and NFTs.

More from Medium

Transfer ownership of Collateral Reserve

Introducing upCRO: The newest upToken by Rootkit Finance

CRYPTO SYZYGY : AMA Session With OortDigital

Enecuum — How to stake Enecuum with stake2earn