Skip to content

Commit

Permalink
Merge branch 'main' into feature/erc20-burnable
Browse files Browse the repository at this point in the history
  • Loading branch information
bidzyyys authored Apr 5, 2024
2 parents 3557267 + 484dbd9 commit 4a1640e
Show file tree
Hide file tree
Showing 7 changed files with 1,192 additions and 13 deletions.
19 changes: 11 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ alloy-sol-types = { version = "0.3.1", default-features = false }
stylus-sdk = { version = "0.4.3", default-features = false }
stylus-proc = { version = "0.4.3", default-features = false }
mini-alloc = "0.4.2"
derive_more = "0.99.17"

[dev-dependencies]
grip = { path = "../lib/grip" }
rand = "0.8.5"
once_cell = "1.19.0"

[features]
default = []
Expand Down
24 changes: 24 additions & 0 deletions contracts/src/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use alloy_primitives::U256;
use stylus_sdk::storage::{StorageGuardMut, StorageUint};

pub(crate) trait AddAssignUnchecked<T> {
fn add_assign_unchecked(&mut self, rhs: T);
}

impl<'a> AddAssignUnchecked<U256> for StorageGuardMut<'a, StorageUint<256, 4>> {
fn add_assign_unchecked(&mut self, rhs: U256) {
let new_balance = self.get() + rhs;
self.set(new_balance);
}
}

pub(crate) trait SubAssignUnchecked<T> {
fn sub_assign_unchecked(&mut self, rhs: T);
}

impl<'a> SubAssignUnchecked<U256> for StorageGuardMut<'a, StorageUint<256, 4>> {
fn sub_assign_unchecked(&mut self, rhs: U256) {
let new_balance = self.get() - rhs;
self.set(new_balance);
}
}
7 changes: 3 additions & 4 deletions contracts/src/erc20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl ERC20 {
value: U256,
) -> Result<bool, Error> {
let owner = msg::sender();
if spender == Address::ZERO {
if spender.is_zero() {
return Err(Error::InvalidSpender(ERC20InvalidSpender {
spender: Address::ZERO,
}));
Expand Down Expand Up @@ -250,7 +250,6 @@ impl ERC20 {
let spender = msg::sender();
self._spend_allowance(from, spender, value)?;
self._transfer(from, to, value)?;

Ok(true)
}
}
Expand Down Expand Up @@ -283,12 +282,12 @@ impl ERC20 {
to: Address,
value: U256,
) -> Result<(), Error> {
if from == Address::ZERO {
if from.is_zero() {
return Err(Error::InvalidSender(ERC20InvalidSender {
sender: Address::ZERO,
}));
}
if to == Address::ZERO {
if to.is_zero() {
return Err(Error::InvalidReceiver(ERC20InvalidReceiver {
receiver: Address::ZERO,
}));
Expand Down
Loading

0 comments on commit 4a1640e

Please sign in to comment.