Skip to content

Commit

Permalink
resolve some req changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SwayStar123 committed Nov 30, 2023
1 parent a49f725 commit e82ed1a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/src_6/simple_vault/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ license = "Apache-2.0"
name = "simple_vault"

[dependencies]
src_20 = { path = "../../../standards/src_20" }
src_6 = { path = "../../../standards/src_6" }
src_20 = { path = "../../../standards/src_20" }
16 changes: 3 additions & 13 deletions examples/src_6/simple_vault/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ impl SRC6 for Contract {
#[storage(read)]
fn managed_assets(asset: AssetId, sub_id: SubId) -> u64 {
let vault_share_asset = vault_asset_id(asset, sub_id).0;
managed_assets(vault_share_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.
// 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.
managed_assets(vault_share_asset)
}

#[storage(read, write)]
fn deposit(receiver: Identity, sub_id: SubId) -> u64 {
let assets = msg_amount();
let asset_amount = msg_amount();
let asset = msg_asset_id();
let (shares, share_asset, share_asset_sub_id) = preview_deposit(asset, sub_id, assets);
require(assets != 0, "ZERO_ASSETS");
Expand All @@ -61,8 +62,6 @@ impl SRC6 for Contract {
vault_info.managed_assets = vault_info.managed_assets + assets;
storage.vault_info.insert(share_asset, vault_info);

after_deposit();

log(Deposit {
caller: msg_sender().unwrap(),
receiver: receiver,
Expand All @@ -87,7 +86,6 @@ impl SRC6 for Contract {

_burn(share_asset_id, share_asset_sub_id, shares);
storage.total_supply.insert(asset, storage.total_supply.get(asset).read() - shares);
after_withdraw();

transfer(receiver, asset, assets);

Expand Down Expand Up @@ -200,14 +198,6 @@ fn preview_withdraw(share_asset_id: AssetId, shares: u64) -> u64 {
}
}

fn after_deposit() {
// Does nothing, only for demonstration purposes.
}

fn after_withdraw() {
// Does nothing, only for demonstration purposes.
}

#[storage(read, write)]
pub fn _mint(
recipient: Identity,
Expand Down
7 changes: 2 additions & 5 deletions standards/src_6/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset=".docs/src-5-logo-dark-theme.png">
<img alt="SRC-5 logo" width="400px" src=".docs/src-5-logo-light-theme.png">
<source media="(prefers-color-scheme: dark)" srcset=".docs/src-6-logo-dark-theme.png">
<img alt="SRC-6 logo" width="400px" src=".docs/src-6-logo-light-theme.png">
</picture>
</p>

Expand All @@ -27,7 +27,6 @@ Method that allows depositing of the underlying asset in exchange for shares of
This function takes the receiver's identity and the sub_id of the sub vault as an argument and returns the amount of shares minted to the receiver.

MUST revert if any AssetId other than the underlying is forwarded.
MUST mint `preview_deposit(deposited_assets)` amount of shares to `receiver`.
MUST increase `managed_assets` by `deposited_assets` (through any means including `std::context::this_balance(ASSET_ID)` if applicable).
MUST increase `total_supply` of the share's AssetId by newly minted shares.
MUST increase `total_assets` by one if the the AssetId is minted for the first time.
Expand All @@ -39,9 +38,7 @@ This function takes the asset's AssetId, the sub_id of the sub vault, and the re
The AssetId of the asset, and the AssetId of the shares MUST be one-to-one, meaning every deposited AssetId shall have a unique corresponding shares AssetId.

MUST revert if any AssetId other than the AssetId corresponding to the deposited asset is forwarded.
MUST send `preview_withdraw(redeemed_shares)` amount of assets to `receiver`.
MUST burn the received shares.
MUST reduce `managed_assets` by `preview_withdraw(redeemed_shares)`.
MUST reduce `total_supply` of the shares's AssetId by amount of burnt shares.
MUST emit a `Withdraw` log.

Expand Down

0 comments on commit e82ed1a

Please sign in to comment.