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

Audit changes #170

Merged
merged 60 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
32232dc
Merge pull request #133 from Brushfam/develop
Artemka374 Aug 31, 2023
df763a8
Update README.md
coreggon11 Sep 5, 2023
3680171
Change ZeroAddress errors on IsNotSet errors
prxgr4mm3r Sep 6, 2023
64d055e
fix small mistakes
prxgr4mm3r Sep 6, 2023
17aed69
Add producing an error when new_owner id None
prxgr4mm3r Sep 6, 2023
5088162
Fix inline docs
prxgr4mm3r Sep 6, 2023
baf92f1
remove approve method from PSP22
Artemka374 Sep 7, 2023
36e2a49
Fix inline docs
prxgr4mm3r Sep 7, 2023
7482cfd
emit PaymentReceived event in receive method
Artemka374 Sep 7, 2023
57d90f8
add check if the account is undelying wrapper
Artemka374 Sep 7, 2023
4e6e93d
add check if the account is undelying wrapper
Artemka374 Sep 8, 2023
c1c1fe1
add additional _max_supply to PSP22Internal and override it with cap …
Artemka374 Sep 8, 2023
d2f3a5a
use bool in reentrancy guard
Artemka374 Sep 8, 2023
6f94147
update docs
Artemka374 Sep 8, 2023
b48968d
fix validation
Artemka374 Sep 11, 2023
e5de183
remove release_all method
Artemka374 Sep 11, 2023
4e81921
add releasable method to payment_splitter
Artemka374 Sep 11, 2023
a0f48bc
update licenses
prxgr4mm3r Sep 11, 2023
dc91955
remove some code repetitions
Artemka374 Sep 11, 2023
36b4c5c
fix typo error in psp34 burnable
prxgr4mm3r Sep 11, 2023
7128b63
delet _ prefix where variable is not unused
prxgr4mm3r Sep 11, 2023
f73a53e
Remove redundant bindings in the codebase
prxgr4mm3r Sep 11, 2023
fbff63e
Move diamond contract out of upgradeability folder
prxgr4mm3r Sep 11, 2023
dcf5843
add _flash_fee_receiver method
Artemka374 Sep 12, 2023
64b5647
change error message
Artemka374 Sep 12, 2023
a50e930
Merge pull request #141 from Brushfam/oz/h-01
Artemka374 Sep 19, 2023
217e181
Merge pull request #138 from Brushfam/oz/h-02
Artemka374 Sep 19, 2023
1779288
Merge pull request #136 from Brushfam/oz/H-03
Artemka374 Sep 19, 2023
659d8ca
Merge pull request #140 from Brushfam/oz/m-02
Artemka374 Sep 19, 2023
f00ca11
Merge pull request #137 from Brushfam/oz/L-04
Artemka374 Sep 19, 2023
0fda946
Merge pull request #158 from Brushfam/oz/n-13
Artemka374 Sep 19, 2023
fa69377
Merge pull request #157 from Brushfam/oz/l-01
Artemka374 Sep 19, 2023
2c9b6e3
Merge pull request #156 from Brushfam/oz/n-08
Artemka374 Sep 19, 2023
714e186
Merge pull request #153 from Brushfam/oz/n-12
Artemka374 Sep 19, 2023
8be08d0
Merge pull request #151 from Brushfam/oz/n-09
Artemka374 Sep 19, 2023
0fd3190
Merge pull request #150 from Brushfam/oz/l-07
Artemka374 Sep 19, 2023
9c0554c
Merge pull request #146 from Brushfam/oz/l-02
Artemka374 Sep 19, 2023
3415a1a
Merge pull request #144 from Brushfam/oz/m-07
Artemka374 Sep 19, 2023
25d0d33
Merge pull request #139 from Brushfam/oz/m-05
Artemka374 Sep 19, 2023
25ddca2
Merge branch 'oz/audit' into oz/m-03
Artemka374 Sep 19, 2023
8bf6934
Merge pull request #142 from Brushfam/oz/m-03
Artemka374 Sep 19, 2023
c03e3a2
Merge pull request #143 from Brushfam/oz/n-05
Artemka374 Sep 19, 2023
1b5b570
Merge branch 'oz/audit' into oz/n-10
Artemka374 Sep 19, 2023
814ab18
Merge pull request #152 from Brushfam/oz/n-10
Artemka374 Sep 19, 2023
681733e
Merge branch 'oz/audit' into oz/m-09
Artemka374 Sep 19, 2023
add06f5
Merge pull request #145 from Brushfam/oz/m-09
Artemka374 Sep 19, 2023
86c482f
Merge branch 'oz/audit' into oz/update-licenses
Artemka374 Sep 19, 2023
9173392
Merge pull request #147 from Brushfam/oz/update-licenses
Artemka374 Sep 19, 2023
3977a5b
Merge branch 'main' into oz/audit
Artemka374 Sep 19, 2023
c4d5057
fix conflicts
Artemka374 Sep 19, 2023
bed24e8
apply fmt
Artemka374 Sep 19, 2023
4c69e14
fix build
Artemka374 Sep 19, 2023
0a760b3
update licenses
Artemka374 Sep 19, 2023
8b72efe
fix psp22_flashmint test
Artemka374 Sep 19, 2023
efee515
delete release_all tests
Artemka374 Sep 19, 2023
08d1056
fix unit tests
Artemka374 Sep 19, 2023
7ca72b0
fix build
Artemka374 Sep 20, 2023
4249d3e
fix build
Artemka374 Sep 20, 2023
bb77751
remove approve from tests
Artemka374 Sep 21, 2023
a251897
remove approve from tests
Artemka374 Sep 21, 2023
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
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<br/>
So, in other words, <a href="https://patron.works/">Patron</a> is an all-in-one contracts platform, which allows you to build and verify ink! smart contracts inside of an isolated environment, explore contract verification details.

## Important!
![OpenBrush](https://user-images.githubusercontent.com/88630083/218825486-accc2d8c-bc5c-4b92-a278-a5b9009fd6f5.png)

[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://Brushfam.github.io/openbrush-contracts)
Expand Down Expand Up @@ -133,10 +132,6 @@ but it must be fixed with this [issue](https://github.com/paritytech/ink/issues/
### Issues to be resolved before the library becomes production-ready:
* [Event's identifiers are based on the naming of the storage structure](https://github.com/Brushfam/openbrush-contracts/issues/2)

## Roadmap 🚗

Current OpenBrush Roadmap includes: https://docs.google.com/document/d/1b49juyKJN0W-UBHoJ4iS3P_I0Z5a94YoNLxylIf-As8

## Installation & Testing
To work with project you need to install ink! toolchain and NodeJS's dependencies.

Expand Down Expand Up @@ -166,8 +161,7 @@ After you can run tests by `npm run test` command. It will build all contracts r

### Was it audited?

Contracts in this repository have not yet been audited and contain several vulnerabilities due to the specific of the ink!.
Since ink! is audited now, OpenBrush is going to be audited after major breaking changes regarding switching to stable toolchain and adapting to latest ink! will be released.
OpenBrush was audited by OpenZeppelin team.

## License

Expand Down
23 changes: 3 additions & 20 deletions contracts/src/access/access_control/access_control.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Copyright (c) 2012-2022 Supercolony
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the"Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT

pub use crate::{
access_control,
Expand Down
23 changes: 3 additions & 20 deletions contracts/src/access/access_control/extensions/enumerable.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Copyright (c) 2012-2022 Supercolony
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the"Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT

pub use crate::{
access_control,
Expand Down
23 changes: 3 additions & 20 deletions contracts/src/access/access_control/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Copyright (c) 2012-2022 Supercolony
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the"Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT

pub mod extensions {
pub mod enumerable;
Expand Down
23 changes: 3 additions & 20 deletions contracts/src/access/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Copyright (c) 2012-2022 Supercolony
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the"Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT

#[cfg(feature = "access_control")]
pub mod access_control;
Expand Down
32 changes: 9 additions & 23 deletions contracts/src/access/ownable/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Copyright (c) 2012-2022 Supercolony
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the"Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT

pub use crate::{
ownable,
Expand Down Expand Up @@ -68,10 +51,13 @@ pub trait OwnableImpl: Storage<Data> + Internal {
}

#[modifiers(only_owner)]
fn transfer_ownership(&mut self, new_owner: AccountId) -> Result<(), OwnableError> {
fn transfer_ownership(&mut self, new_owner: Option<AccountId>) -> Result<(), OwnableError> {
let old_owner = self.data().owner.get_or_default();
self.data().owner.set(&Some(new_owner));
self._emit_ownership_transferred_event(old_owner, Some(new_owner));
if new_owner == None {
return Err(OwnableError::NewOwnerIsNotSet)
}
self.data().owner.set(&new_owner);
self._emit_ownership_transferred_event(old_owner, new_owner);
Ok(())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Copyright (c) 2012-2022 Supercolony
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the"Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT.

// Delegate calls were marked as a possible attack vector in ink!
// Therefore the proxy and diamond contracts will be disabled within OpenBrush until this is reimplemented in ink! 4.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Copyright (c) 2012-2022 Supercolony
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the"Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT

pub use crate::{
diamond,
Expand Down
10 changes: 10 additions & 0 deletions contracts/src/diamond/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT

pub mod diamond;

pub use diamond::*;
pub mod extensions {
pub mod diamond_loupe;
}
23 changes: 3 additions & 20 deletions contracts/src/finance/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Copyright (c) 2012-2022 Supercolony
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the"Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT

#[cfg(feature = "payment_splitter")]
pub mod payment_splitter;
51 changes: 20 additions & 31 deletions contracts/src/finance/payment_splitter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Copyright (c) 2012-2022 Supercolony
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the"Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT

pub use crate::{
payment_splitter,
Expand Down Expand Up @@ -56,6 +39,10 @@ pub trait PaymentSplitterImpl: Storage<Data> + Internal {
self.data().total_released.get_or_default()
}

fn releasable(&self, account: AccountId) -> Balance {
self._releasable(account)
}

fn shares(&self, account: AccountId) -> Balance {
self.data().shares.get(&account).unwrap_or(0)
}
Expand All @@ -69,7 +56,7 @@ pub trait PaymentSplitterImpl: Storage<Data> + Internal {
}

fn receive(&mut self) {
self._emit_payee_added_event(Self::env().caller(), Self::env().transferred_value())
self._emit_payment_received_event(Self::env().caller(), Self::env().transferred_value())
}

fn release(&mut self, account: AccountId) -> Result<(), PaymentSplitterError> {
Expand All @@ -88,16 +75,15 @@ pub trait Internal {
/// Inits an instance of `PaymentSplitter` where each account in `payees` is assigned the number of shares at
/// the matching position in the `shares` array.
///
/// All addresses in `payees` must be non-zero. Both arrays must have the same non-zero length, and there must be no
/// All addresses in `payees` must be set. Both arrays must have the same non-zero length, and there must be no
/// duplicates in `payees`.
///
/// Emits `PayeeAdded` on each account.
fn _init(&mut self, payees_and_shares: Vec<(AccountId, Balance)>) -> Result<(), PaymentSplitterError>;

fn _add_payee(&mut self, payee: AccountId, share: Balance) -> Result<(), PaymentSplitterError>;

/// Calls the `release` method for each `AccountId` in the `payees` vec.
fn _release_all(&mut self) -> Result<(), PaymentSplitterError>;
fn _releasable(&self, account: AccountId) -> Balance;

fn _release(&mut self, account: AccountId) -> Result<(), PaymentSplitterError>;
}
Expand Down Expand Up @@ -141,15 +127,18 @@ pub trait InternalImpl: Storage<Data> + Internal {
Ok(())
}

fn _release_all(&mut self) -> Result<(), PaymentSplitterError> {
let payees = self.data().payees.get_or_default();
let len = payees.len();
fn _releasable(&self, account: AccountId) -> Balance {
let total_received = Self::env()
.balance()
.checked_sub(Self::env().minimum_balance())
.unwrap_or_default();
let total_shares = self.data().total_shares.get_or_default();
let released = self.data().released.get(&account).unwrap_or_default();
let shares = self.data().shares.get(&account).unwrap_or_default();

for account in payees.iter().take(len) {
Internal::_release(self, *account)?;
}
let payment = total_received * shares / total_shares - released;

Ok(())
payment
}

fn _release(&mut self, account: AccountId) -> Result<(), PaymentSplitterError> {
Expand Down
24 changes: 3 additions & 21 deletions contracts/src/governance/extensions/governor_counting/data.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
// Copyright (c) 2023 Brushfam
// Copyright (c) 2012-2022 Supercolony
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the"Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) 2012-2022 Supercolony. All Rights Reserved.
// Copyright (c) 2023 Brushfam. All Rights Reserved.
// SPDX-License-Identifier: MIT

pub use crate::traits::governance::{
ProposalId,
Expand Down
Loading
Loading