Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate adjustment of total_supply in SRC6 examples #61

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions examples/src6-vault/multi_token_vault/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ impl SRC6 for Contract {
let (shares, share_asset, share_asset_vault_sub_id) = preview_deposit(underlying_asset, vault_sub_id, asset_amount);

_mint(receiver, share_asset, share_asset_vault_sub_id, shares);
storage
.total_supply
.insert(
share_asset,
storage
.total_supply
.get(share_asset)
.read() + shares,
);

let mut vault_info = storage.vault_info.get(share_asset).read();
vault_info.managed_assets = vault_info.managed_assets + asset_amount;
Expand Down Expand Up @@ -92,15 +83,6 @@ impl SRC6 for Contract {
let assets = preview_withdraw(share_asset_id, shares);

_burn(share_asset_id, share_asset_vault_sub_id, shares);
storage
.total_supply
.insert(
share_asset_id,
storage
.total_supply
.get(share_asset_id)
.read() - shares,
);

transfer(receiver, underlying_asset, assets);

Expand Down
12 changes: 5 additions & 7 deletions examples/src6-vault/single_token_single_sub_vault/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ impl SRC6 for Contract {
let shares = preview_deposit(asset_amount);

_mint(receiver, shares);
storage
.total_supply
.write(storage.total_supply.read() + shares);

storage
.managed_assets
Expand Down Expand Up @@ -89,9 +86,6 @@ impl SRC6 for Contract {
let assets = preview_withdraw(shares);

_burn(share_asset_id, shares);
storage
.total_supply
.write(storage.total_supply.read() - shares);

transfer(receiver, underlying_asset, assets);

Expand Down Expand Up @@ -150,7 +144,11 @@ impl SRC20 for Contract {

#[storage(read)]
fn total_supply(asset: AssetId) -> Option<u64> {
Some(storage.total_supply.read())
if asset == vault_assetid() {
Some(storage.total_supply.read())
} else {
None
}
}

#[storage(read)]
Expand Down
18 changes: 0 additions & 18 deletions examples/src6-vault/single_token_vault/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ impl SRC6 for Contract {
require(asset_amount != 0, "ZERO_ASSETS");

_mint(receiver, share_asset, share_asset_vault_sub_id, shares);
storage
.total_supply
.insert(
share_asset,
storage
.total_supply
.get(share_asset)
.read() + shares,
);

let mut vault_info = storage.vault_info.get(share_asset).read();
vault_info.managed_assets = vault_info.managed_assets + asset_amount;
Expand Down Expand Up @@ -99,15 +90,6 @@ impl SRC6 for Contract {
let assets = preview_withdraw(share_asset_id, shares);

_burn(share_asset_id, share_asset_vault_sub_id, shares);
storage
.total_supply
.insert(
share_asset_id,
storage
.total_supply
.get(share_asset_id)
.read() - shares,
);

transfer(receiver, underlying_asset, assets);

Expand Down
Loading