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

feat(erc721): implement erc-721 token standard #23

Merged
merged 69 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
9557057
add prototype for erc721
qalisander Mar 25, 2024
3bace8f
split events and errors in sol! macro
qalisander Mar 25, 2024
a551ccf
restructure same erc721 same as erc20
qalisander Mar 26, 2024
b732325
add arguments to documentation
qalisander Mar 26, 2024
6cd1d75
add events section to documentation
qalisander Mar 26, 2024
f797bc7
add balance test
qalisander Mar 28, 2024
6a7b2a9
create Error enum
qalisander Mar 28, 2024
5bf9e6d
add documentation for error's and event's fields
qalisander Mar 28, 2024
987b2f8
add mint_nft_and_check_balance test
qalisander Mar 28, 2024
6a7bcc0
add error_mint_second_nft test
qalisander Mar 28, 2024
903a960
add transfer_nft test
qalisander Mar 29, 2024
c45f61e
add error_transfer_nonexistent_nft test
qalisander Mar 29, 2024
9bf2d93
add approve_nft_transfer and transfer_approved_nft tests
qalisander Mar 29, 2024
1a19400
add error_not_approved_nft_transfer test
qalisander Mar 29, 2024
55c65a7
prefix internal functions with underscore
qalisander Apr 1, 2024
ff6716e
remove std deps
qalisander Apr 1, 2024
6cbaf5a
fix function and events links in documentation
qalisander Apr 1, 2024
3a360b5
add errors description to documentation
qalisander Apr 1, 2024
3ece161
rust fmt
qalisander Apr 1, 2024
2b0e865
add more error documentation
qalisander Apr 1, 2024
d0e3473
fix dbg attribute
qalisander Apr 2, 2024
9bcaa21
fix doc
qalisander Apr 2, 2024
be49bd4
use is_zero() instead of comparing to Address::ZERO
qalisander Apr 2, 2024
81028f8
add underscore for storage fields
qalisander Apr 2, 2024
1767a07
remove mention of erc-20
qalisander Apr 3, 2024
2d248a4
remove #[macro_use]
qalisander Apr 3, 2024
f1262fb
add unsafe TopLevelStorage implementation
qalisander Apr 3, 2024
f22ead5
Merge remote-tracking branch 'origin/main' into erc-721
qalisander Apr 4, 2024
2c31b12
use grip::test for erc721
qalisander Apr 4, 2024
33721da
fix U256 arg at _increase_balance
qalisander Apr 4, 2024
cc1269d
fix grammar
qalisander Apr 4, 2024
633ad3d
++
qalisander Apr 4, 2024
79456e3
++
qalisander Apr 4, 2024
894be05
++
qalisander Apr 4, 2024
72bbce6
++
qalisander Apr 4, 2024
d1006f4
++
qalisander Apr 4, 2024
984cc1d
++
qalisander Apr 4, 2024
4cbecea
++
qalisander Apr 4, 2024
d41d34f
++
qalisander Apr 4, 2024
df94d10
++
qalisander Apr 4, 2024
ee9dbe8
++
qalisander Apr 4, 2024
eff68a9
++
qalisander Apr 4, 2024
d59e0e7
++
qalisander Apr 5, 2024
b9b5c58
++
qalisander Apr 5, 2024
bd53b37
++
qalisander Apr 5, 2024
3060c46
++
qalisander Apr 5, 2024
02575a5
++
qalisander Apr 5, 2024
e921f4d
++
qalisander Apr 5, 2024
12cfdaa
++
qalisander Apr 5, 2024
fa43374
++
qalisander Apr 5, 2024
ccb3e2a
++
qalisander Apr 5, 2024
7a87057
++
qalisander Apr 5, 2024
500cf28
++
qalisander Apr 5, 2024
fe6ecf0
++
qalisander Apr 5, 2024
6e9461a
++
qalisander Apr 5, 2024
82b4173
++
qalisander Apr 5, 2024
5f2ab13
++
alexfertel Apr 5, 2024
b8f1a8f
++
alexfertel Apr 5, 2024
19cbeb1
++
alexfertel Apr 5, 2024
97be1b1
++
alexfertel Apr 5, 2024
a8577b1
++
alexfertel Apr 5, 2024
76aefdb
++
alexfertel Apr 5, 2024
cba6ff4
++
alexfertel Apr 5, 2024
45e0b53
++
qalisander Apr 5, 2024
4d631bd
++
alexfertel Apr 5, 2024
01d3660
++
alexfertel Apr 5, 2024
3a029e6
++
alexfertel Apr 5, 2024
b80a0fa
++
alexfertel Apr 5, 2024
b84eed2
lint(fmt): fix formatting
alexfertel Apr 5, 2024
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
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"
qalisander marked this conversation as resolved.
Show resolved Hide resolved

[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> {

Check warning on line 4 in contracts/src/arithmetic.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/src/arithmetic.rs#L4

warning: trait `AddAssignUnchecked` is never used --> contracts/src/arithmetic.rs:4:18 | 4 | pub(crate) trait AddAssignUnchecked<T> { | ^^^^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
Raw output
contracts/src/arithmetic.rs:4:18:w:warning: trait `AddAssignUnchecked` is never used
 --> contracts/src/arithmetic.rs:4:18
  |
4 | pub(crate) trait AddAssignUnchecked<T> {
  |                  ^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default


__END__
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> {

Check warning on line 15 in contracts/src/arithmetic.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/src/arithmetic.rs#L15

warning: trait `SubAssignUnchecked` is never used --> contracts/src/arithmetic.rs:15:18 | 15 | pub(crate) trait SubAssignUnchecked<T> { | ^^^^^^^^^^^^^^^^^^
Raw output
contracts/src/arithmetic.rs:15:18:w:warning: trait `SubAssignUnchecked` is never used
  --> contracts/src/arithmetic.rs:15:18
   |
15 | pub(crate) trait SubAssignUnchecked<T> {
   |                  ^^^^^^^^^^^^^^^^^^


__END__
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);
}
}
8 changes: 4 additions & 4 deletions contracts/src/erc20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl ERC20 {
value: U256,
) -> Result<bool, Error> {
let from = msg::sender();
if to == Address::ZERO {
if to.is_zero() {
return Err(Error::InvalidReceiver(ERC20InvalidReceiver {
receiver: Address::ZERO,
}));
Expand Down Expand Up @@ -200,7 +200,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 @@ -246,12 +246,12 @@ impl ERC20 {
to: Address,
value: U256,
) -> Result<bool, 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
Loading