From bf56fadae95f7c2bcd687dbca346b4c7a4b9912e Mon Sep 17 00:00:00 2001 From: bitzoic Date: Mon, 8 Jul 2024 18:53:14 +0800 Subject: [PATCH 1/5] Update SRC-6 example with decrementation of managed assets --- examples/src6-vault/multi_asset_vault/src/main.sw | 3 +++ examples/src6-vault/single_asset_single_sub_vault/src/main.sw | 4 ++++ examples/src6-vault/single_asset_vault/src/main.sw | 3 +++ 3 files changed, 10 insertions(+) diff --git a/examples/src6-vault/multi_asset_vault/src/main.sw b/examples/src6-vault/multi_asset_vault/src/main.sw index 26d3428..d515e89 100644 --- a/examples/src6-vault/multi_asset_vault/src/main.sw +++ b/examples/src6-vault/multi_asset_vault/src/main.sw @@ -81,6 +81,9 @@ 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; + _burn(share_asset_id, share_asset_vault_sub_id, shares); transfer(receiver, underlying_asset, assets); diff --git a/examples/src6-vault/single_asset_single_sub_vault/src/main.sw b/examples/src6-vault/single_asset_single_sub_vault/src/main.sw index fedd56d..51c2c48 100644 --- a/examples/src6-vault/single_asset_single_sub_vault/src/main.sw +++ b/examples/src6-vault/single_asset_single_sub_vault/src/main.sw @@ -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); diff --git a/examples/src6-vault/single_asset_vault/src/main.sw b/examples/src6-vault/single_asset_vault/src/main.sw index 16d1d76..cd80a56 100644 --- a/examples/src6-vault/single_asset_vault/src/main.sw +++ b/examples/src6-vault/single_asset_vault/src/main.sw @@ -82,6 +82,9 @@ 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; + _burn(share_asset_id, share_asset_vault_sub_id, shares); transfer(receiver, underlying_asset, assets); From 0b92700b7e43c941e2960f7663ffe1d592566c5c Mon Sep 17 00:00:00 2001 From: bitzoic Date: Mon, 8 Jul 2024 18:53:34 +0800 Subject: [PATCH 2/5] Update CHANGELOG --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b99f637..81d3092 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +Description of the upcoming release here. + +### Added + +- Something new here + +### Changed + +- Something new here + +### Fixed + +- [#122](https://github.com/FuelLabs/sway-standards/pull/107) Fixes the SRC-6 example contract from a critical bug where the contract can be drained. + ## [Version 0.5.1] Description of the upcoming release here. From a6b94d06c0ad2cf8e7614aec8e213a7c49c1be9d Mon Sep 17 00:00:00 2001 From: bitzoic Date: Mon, 8 Jul 2024 18:56:18 +0800 Subject: [PATCH 3/5] Fix link on CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81d3092..1525854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ Description of the upcoming release here. ### Fixed -- [#122](https://github.com/FuelLabs/sway-standards/pull/107) Fixes the SRC-6 example contract from a critical bug where the contract can be drained. +- [#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. ## [Version 0.5.1] From 8480bb98a4b1cbb995632779ef880a0a1c8f3834 Mon Sep 17 00:00:00 2001 From: bitzoic Date: Mon, 8 Jul 2024 18:58:01 +0800 Subject: [PATCH 4/5] Update CHANGELOG to resolve markdown error with duplicate headers --- CHANGELOG.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1525854..fe83724 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,15 +9,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Description of the upcoming release here. -### Added +### Added Unreleased - Something new here -### Changed +### Changed Unreleased - Something new here -### Fixed +### Fixed Unreleased - [#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. @@ -25,26 +25,26 @@ Description of the upcoming release here. Description of the upcoming release here. -### Added +### Added v0.5.1 - [#107](https://github.com/FuelLabs/sway-standards/pull/107): Adds the `proxy_owner()` function to the SRC-14 standard. - [#104](https://github.com/FuelLabs/sway-standards/pull/104): Adds the CHANGELOG.md file to Sway-Standards. - [#110](https://github.com/FuelLabs/sway-standards/pull/110) Adds the `proxy_target()` function to the SRC-14 standard. - [#103](https://github.com/FuelLabs/sway-standards/pull/103): Adds Sway-Standards to the [docs hub](https://docs.fuel.network/docs/sway-standards/). -### Changed +### Changed v0.5.1 - [#103](https://github.com/FuelLabs/sway-standards/pull/103) Removes standards in the `./SRC` folder in favor of `./docs`. - [#106](https://github.com/FuelLabs/sway-standards/pull/106) Updates links from the Sway Book to Docs Hub. -### Fixed +### Fixed v0.5.1 - [#107](https://github.com/FuelLabs/sway-standards/pull/107) resolves the conflict when SRC-5's `owner()` function is used in both the proxy and target contract in the SRC-14 standard. - [#99](https://github.com/FuelLabs/sway-standards/pull/99) Fixes links and typos in the SRC-14 standard. - [#112](https://github.com/FuelLabs/sway-standards/pull/112) Fixes inline documentation code in the SRC-3 standard. - [#115](https://github.com/FuelLabs/sway-standards/pull/115) Hotfixes the Cargo.toml version to the v0.5.1 release. -#### Breaking +#### Breaking v0.5.1 - [#110](https://github.com/FuelLabs/sway-standards/pull/110) Breaks the `SRC14` abi by adding the `proxy_target()` function. This will need to be added to any SRC14 implementation. The new abi is as follows: From d97c9dd6903e9b02308fd71a7413337e9b64c566 Mon Sep 17 00:00:00 2001 From: bitzoic Date: Mon, 8 Jul 2024 21:23:58 +0800 Subject: [PATCH 5/5] Write to storage --- examples/src6-vault/multi_asset_vault/src/main.sw | 1 + examples/src6-vault/single_asset_vault/src/main.sw | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/src6-vault/multi_asset_vault/src/main.sw b/examples/src6-vault/multi_asset_vault/src/main.sw index d515e89..b555976 100644 --- a/examples/src6-vault/multi_asset_vault/src/main.sw +++ b/examples/src6-vault/multi_asset_vault/src/main.sw @@ -83,6 +83,7 @@ impl SRC6 for Contract { 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); diff --git a/examples/src6-vault/single_asset_vault/src/main.sw b/examples/src6-vault/single_asset_vault/src/main.sw index cd80a56..86b5655 100644 --- a/examples/src6-vault/single_asset_vault/src/main.sw +++ b/examples/src6-vault/single_asset_vault/src/main.sw @@ -84,6 +84,7 @@ impl SRC6 for Contract { 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);