Skip to content

Commit

Permalink
SRC-6 example contract does not update managed assets (#122)
Browse files Browse the repository at this point in the history
* Update SRC-6 example with decrementation of managed assets

* Update CHANGELOG

* Fix link on CHANGELOG.md

* Update CHANGELOG to resolve markdown error with duplicate headers

* Write to storage
  • Loading branch information
bitzoic authored Jul 9, 2024
1 parent b0e99a6 commit 3acac2b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ Description of the upcoming release here.

### Added Unreleased

- Something new here 1
- Something new here 2
- Something new here

### Changed Unreleased

Expand All @@ -22,8 +21,9 @@ Description of the upcoming release here.
### Fixed Unreleased

- [#121](https://github.com/FuelLabs/sway-standards/pull/121) Fixes the `deposit` function in the SRC-6 standard, uses try_read instead of read in order to allow first time deposits to a vault.
- [#122](https://github.com/FuelLabs/sway-standards/pull/122) Fixes the SRC-6 example contract from a critical bug where the contract can be drained.

#### Breaking Unreleased
### Breaking Unreleased

- Some breaking change here 1
- Some breaking change here 2
Expand Down
4 changes: 4 additions & 0 deletions examples/src6-vault/multi_asset_vault/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ impl SRC6 for Contract {
require(msg_asset_id() == share_asset_id, "INVALID_ASSET_ID");
let assets = preview_withdraw(share_asset_id, shares);

let mut vault_info = storage.vault_info.get(share_asset_id).read();
vault_info.managed_assets = vault_info.managed_assets - shares;
storage.vault_info.insert(share_asset_id, vault_info);

_burn(share_asset_id, share_asset_vault_sub_id, shares);

transfer(receiver, underlying_asset, assets);
Expand Down
4 changes: 4 additions & 0 deletions examples/src6-vault/single_asset_single_sub_vault/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ impl SRC6 for Contract {
require(msg_asset_id() == share_asset_id, "INVALID_ASSET_ID");
let assets = preview_withdraw(shares);

storage
.managed_assets
.write(storage.managed_assets.read() - shares);

_burn(share_asset_id, shares);

transfer(receiver, underlying_asset, assets);
Expand Down
4 changes: 4 additions & 0 deletions examples/src6-vault/single_asset_vault/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ impl SRC6 for Contract {
require(msg_asset_id() == share_asset_id, "INVALID_ASSET_ID");
let assets = preview_withdraw(share_asset_id, shares);

let mut vault_info = storage.vault_info.get(share_asset_id).read();
vault_info.managed_assets = vault_info.managed_assets - shares;
storage.vault_info.insert(share_asset_id, vault_info);

_burn(share_asset_id, share_asset_vault_sub_id, shares);

transfer(receiver, underlying_asset, assets);
Expand Down

0 comments on commit 3acac2b

Please sign in to comment.