Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SwayStar123 committed Oct 31, 2023
1 parent 2b7ebf3 commit 610bfca
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions standards/src_6/examples/simple_vault.sw
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ use std::{
call_frames::msg_asset_id,
context::msg_amount,
hash::Hash,
storage::{storage_map::*, storage_string::StorageString},
token::{transfer, mint, burn},
storage::{
storage_map::*,
storage_string::StorageString,
},
token::{
burn,
mint,
transfer,
},
};

use src_6::{SRC6, Deposit, Withdraw};
use src_6::{Deposit, SRC6, Withdraw};
use src_20::SRC20;
use std::string::String;

Expand Down Expand Up @@ -53,14 +60,14 @@ impl SRC6 for Contract {
fn managed_assets(asset: AssetId) -> u64 {
managed_assets(asset) // In this implementation managed_assets and max_withdrawable are the same. However in case of lending out of assets, managed_assets should be greater than max_withdrawable.
}

#[storage(read, write)]
fn deposit(receiver: Identity) -> u64 {
let assets = msg_amount();
let asset = msg_asset_id();
let shares = preview_deposit(asset, assets);
require(assets != 0, "ZERO_ASSETS");

let _ = _mint(receiver, asset.into(), shares); // Using the asset_id as the sub_id for shares.
storage.total_supply.insert(asset, storage.total_supply.get(asset).read() + shares);
after_deposit();
Expand All @@ -82,7 +89,7 @@ impl SRC6 for Contract {
require(shares != 0, "ZERO_SHARES");
require(msg_asset_id() == AssetId::new(ContractId::this(), asset.into()), "INVALID_ASSET_ID");
let assets = preview_withdraw(asset, shares);

_burn(asset.into(), shares);
storage.total_supply.insert(asset, storage.total_supply.get(asset).read() - shares);
after_withdraw();
Expand All @@ -105,7 +112,6 @@ impl SRC6 for Contract {
Option::Some(preview_deposit(asset, assets))
}


#[storage(read)]
fn convert_to_assets(asset: AssetId, shares: u64) -> Option<u64> {
Option::Some(preview_withdraw(asset, shares))
Expand Down Expand Up @@ -155,11 +161,7 @@ fn after_withdraw() {
}

#[storage(read, write)]
pub fn _mint(
recipient: Identity,
sub_id: SubId,
amount: u64,
) -> AssetId {
pub fn _mint(recipient: Identity, sub_id: SubId, amount: u64) -> AssetId {
let asset_id = AssetId::new(contract_id(), sub_id);
let supply = storage.total_supply.get(asset).try_read();
// Only increment the number of assets minted by this contract if it hasn't been minted before.
Expand All @@ -173,14 +175,11 @@ pub fn _mint(
}

#[storage(read, write)]
pub fn _burn(
sub_id: SubId,
amount: u64,
) {
pub fn _burn(sub_id: SubId, amount: u64) {
let asset_id = AssetId::new(contract_id(), sub_id);
require(this_balance(asset_id) >= amount, BurnError::NotEnoughTokens);
// If we pass the check above, we can assume it is safe to unwrap.
let supply = storage.total_supply.get(asset).try_read().unwrap();
storage.total_supply.insert(asset_id, supply - amount);
burn(sub_id, amount);
}
}

0 comments on commit 610bfca

Please sign in to comment.