-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: benchmark updates, extrinsic type change
- replaced `u32` with `u64` for the `gas_limit` parameter in all extrinsics - updated benchmark tests trying to achieve similar gas cost for publishing modules and publishing bundles - tiny fixes in assets/move-projects
- Loading branch information
Showing
21 changed files
with
211 additions
and
131 deletions.
There are no files selected for viewing
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,10 @@ | ||
[package] | ||
name = "basic_coin" | ||
version = "0.0.0" | ||
|
||
[dependencies] | ||
MoveStdlib = { git = "https://github.com/eigerco/move-stdlib", rev = "main" } | ||
|
||
[addresses] | ||
std = "0x1" | ||
CafeAccount = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" |
68 changes: 68 additions & 0 deletions
68
pallet/src/assets/move-projects/basic_coin/sources/BasicCoin.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,68 @@ | ||
/// This module defines a minimal Coin and Balance. | ||
module CafeAccount::BasicCoin { | ||
use std::signer; | ||
|
||
/// Address of the owner of this module | ||
const MODULE_OWNER: address = @CafeAccount; | ||
|
||
/// Error codes | ||
const ENOT_MODULE_OWNER: u64 = 0; | ||
const EINSUFFICIENT_BALANCE: u64 = 1; | ||
const EALREADY_HAS_BALANCE: u64 = 2; | ||
|
||
struct Coin has store { | ||
value: u64 | ||
} | ||
|
||
/// Struct representing the balance of each address. | ||
struct Balance has key { | ||
coin: Coin | ||
} | ||
|
||
/// Publish an empty balance resource under `account`'s address. This function must be called before | ||
/// minting or transferring to the account. | ||
/// Making this function entry allows to call it directly in the transactions | ||
entry public fun publish_balance(account: &signer) { | ||
let empty_coin = Coin { value: 0 }; | ||
assert!(!exists<Balance>(signer::address_of(account)), EALREADY_HAS_BALANCE); | ||
move_to(account, Balance { coin: empty_coin }); | ||
} | ||
|
||
/// Mint `amount` tokens to `mint_addr`. Mint must be approved by the module owner. | ||
public fun mint(module_owner: &signer, mint_addr: address, amount: u64) acquires Balance { | ||
// Only the owner of the module can initialize this module | ||
assert!(signer::address_of(module_owner) == MODULE_OWNER, ENOT_MODULE_OWNER); | ||
|
||
// Deposit `amount` of tokens to `mint_addr`'s balance | ||
deposit(mint_addr, Coin { value: amount }); | ||
} | ||
|
||
/// Returns the balance of `owner`. | ||
public fun balance_of(owner: address): u64 acquires Balance { | ||
borrow_global<Balance>(owner).coin.value | ||
} | ||
|
||
/// Transfers `amount` of tokens from `from` to `to`. | ||
public fun transfer(from: &signer, to: address, amount: u64) acquires Balance { | ||
let check = withdraw(signer::address_of(from), amount); | ||
deposit(to, check); | ||
} | ||
|
||
/// Withdraw `amount` number of tokens from the balance under `addr`. | ||
fun withdraw(addr: address, amount: u64) : Coin acquires Balance { | ||
let balance = balance_of(addr); | ||
// balance must be greater than the withdraw amount | ||
assert!(balance >= amount, EINSUFFICIENT_BALANCE); | ||
let balance_ref = &mut borrow_global_mut<Balance>(addr).coin.value; | ||
*balance_ref = balance - amount; | ||
Coin { value: amount } | ||
} | ||
|
||
/// Deposit `amount` number of tokens to the balance under `addr`. | ||
fun deposit(addr: address, check: Coin) acquires Balance { | ||
let balance = balance_of(addr); | ||
let balance_ref = &mut borrow_global_mut<Balance>(addr).coin.value; | ||
let Coin { value } = check; | ||
*balance_ref = balance + value; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
pallet/src/assets/move-projects/basic_coin/sources/GetCoin.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,15 @@ | ||
script { | ||
use CafeAccount::BasicCoin; | ||
|
||
fun publish_balance(s: signer) { | ||
BasicCoin::publish_balance(&s); | ||
} | ||
} | ||
|
||
script { | ||
use CafeAccount::BasicCoin; | ||
|
||
fun mint_some(module_owner: signer, rx_addr: address, amount: u64) { | ||
BasicCoin::mint(&module_owner, rx_addr, amount); | ||
} | ||
} |
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
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
Oops, something went wrong.