Skip to content

Commit

Permalink
assets directory name changed
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelHardFork committed Mar 25, 2023
1 parent d3c7797 commit 8bac7d6
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 63 deletions.
14 changes: 7 additions & 7 deletions assets/eip-6774/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Reference implementations of ERC-N
# Reference implementations of ERC-6774

## Contract

**ERC-N implementations:**
**ERC-6774 implementations:**

- [IERC_N.sol](./contracts/IERC_N.sol): interface of `ERC_N`
- [ERC_N.sol](./contracts/ERC_N.sol): a simple and minimal implementation for one-to-one barter type
- [ERC_NMultiBarter.sol](./contracts/extensions/ERC_NMultiBarter.sol): an extensions of `ERC_N.sol` for barter several token belonging to the same contract
- [IERC6774.sol](./contracts/IERC6774.sol): interface of `ERC6774`
- [ERC6774.sol](./contracts/ERC6774.sol): a simple and minimal implementation for one-to-one barter type
- [ERC6774MultiBarter.sol](./contracts/extensions/ERC6774MultiBarter.sol): an extensions of `ERC6774.sol` for barter several token belonging to the same contract

**Mocks contracts:**

- [PermissionlessERC_N.sol](./contracts/mocks/PermissionlessERC_N.sol): an exemple of implementation of `ERC_N`
- [PermissionlessERC_NMultiBarter.sol](./contracts/mocks/PermissionlessERC_NMultiBarter.sol): an exemple of implementation of `ERC_NMultiBarter`
- [PermissionlessERC6774.sol](./contracts/mocks/PermissionlessERC6774.sol): an exemple of implementation of `ERC6774`
- [PermissionlessERC6774MultiBarter.sol](./contracts/mocks/PermissionlessERC6774MultiBarter.sol): an exemple of implementation of `ERC6774MultiBarter`

_These contract are used in `test`_

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {ERC721, IERC721} from "openzeppelin-contracts/contracts/token/ERC721/ERC
import {EIP712} from "openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol";
import {ECDSA} from "openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol";

import {IERC_N} from "./IERC_N.sol";
import {IERC6774} from "./IERC6774.sol";

contract ERC_N is ERC721, EIP712, IERC_N {
contract ERC6774 is ERC721, EIP712, IERC6774 {
using ECDSA for bytes32;

error BarterNotEnabled(address tokenAddr);
Expand Down Expand Up @@ -51,20 +51,20 @@ contract ERC_N is ERC721, EIP712, IERC_N {
PUBLIC FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////////////*/

/// @dev See {IERC_N-barter}
/// @dev See {IERC6774-barter}
function barter(
BarterTerms memory data,
bytes memory signature
) external onlyExchangeable(data.bid.tokenAddr) {
IERC_N(data.bid.tokenAddr).transferFor(data, msg.sender, signature);
IERC6774(data.bid.tokenAddr).transferFor(data, msg.sender, signature);

// transfer ask token
if (!_isApprovedOrOwner(msg.sender, data.ask.tokenId))
revert NotOwnerNorApproved(msg.sender, data.ask.tokenId);
_transfer(msg.sender, data.owner, data.ask.tokenId);
}

/// @dev See {IERC_N-transferFor}
/// @dev See {IERC6774-transferFor}
function transferFor(
BarterTerms memory data,
address to,
Expand All @@ -88,12 +88,12 @@ contract ERC_N is ERC721, EIP712, IERC_N {
GETTERS
////////////////////////////////////////////////////////////////////////////////////////////////*/

/// @dev See {IERC_N-nonce}
/// @dev See {IERC6774-nonce}
function nonce(address account) external view returns (uint256) {
return _nonces[account];
}

/// @dev See {IERC_N-isBarterable}
/// @dev See {IERC6774-isBarterable}
function isBarterable(address tokenAddr) external view returns (bool) {
return _barterables[tokenAddr];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.13;

interface IERC_N {
interface IERC6774 {
/**
* @dev Emitted when a `tokenAddr` is settled as barterable (`barterable` == true)
* or stopped from being barterable (`barterable` == false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

pragma solidity ^0.8.13;

import {ERC_N, IERC_N} from "../ERC_N.sol";
import {ERC6774, IERC6774} from "../ERC6774.sol";

contract ERC_NMultiBarter is ERC_N {
contract ERC6774MultiBarter is ERC6774 {
struct MultiComponant {
address tokenAddr;
uint256[] tokenIds;
Expand All @@ -27,7 +27,7 @@ contract ERC_NMultiBarter is ERC_N {
constructor(
string memory _name,
string memory _symbol
) ERC_N(_name, _symbol) {
) ERC6774(_name, _symbol) {
MULTI_COMPONANT_TYPEHASH = keccak256(
abi.encodePacked(
"MultiComponant(address tokenAddr,uint256[] tokenIds)"
Expand All @@ -48,7 +48,7 @@ contract ERC_NMultiBarter is ERC_N {
MultiBarterTerms memory data,
bytes memory signature
) external onlyExchangeable(data.bid.tokenAddr) {
ERC_NMultiBarter(data.bid.tokenAddr).transferFor(
ERC6774MultiBarter(data.bid.tokenAddr).transferFor(
data,
msg.sender,
signature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

pragma solidity ^0.8.13;

import {ERC_N} from "../ERC_N.sol";
import {ERC6774} from "../ERC6774.sol";

contract PermissionlessERC_N is ERC_N {
contract PermissionlessERC6774 is ERC6774 {
string internal ipfsHash;

constructor(
string memory _name,
string memory _symbol,
string memory _ipfsHash
) ERC_N(_name, _symbol) {
) ERC6774(_name, _symbol) {
ipfsHash = _ipfsHash;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

pragma solidity ^0.8.13;

import {ERC_NMultiBarter} from "../extensions/ERC_NMultiBarter.sol";
import {ERC6774MultiBarter} from "../extensions/ERC6774MultiBarter.sol";

contract PermissionlessERC_NMultiBarter is ERC_NMultiBarter {
contract PermissionlessERC6774MultiBarter is ERC6774MultiBarter {
string internal ipfsHash;

constructor(
string memory _name,
string memory _symbol,
string memory _ipfsHash
) ERC_NMultiBarter(_name, _symbol) {
) ERC6774MultiBarter(_name, _symbol) {
ipfsHash = _ipfsHash;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ pragma solidity ^0.8.13;
import "forge-std/Test.sol";

import {Utils} from "./Utils.t.sol";
import {PermissionlessERC_NMultiBarter} from "../contracts/mocks/PermissionlessERC_NMultiBarter.sol";
import {IERC_N} from "../contracts/IERC_N.sol";
import {PermissionlessERC6774MultiBarter} from "../contracts/mocks/PermissionlessERC6774MultiBarter.sol";
import {IERC6774} from "../contracts/IERC6774.sol";

contract ERCN_test is Test, Utils {
contract ERC6774_test is Test, Utils {
using stdStorage for StdStorage;

// tokens
PermissionlessERC_NMultiBarter internal ticket;
PermissionlessERC6774MultiBarter internal ticket;
address internal TICKET;
PermissionlessERC_NMultiBarter internal discount;
PermissionlessERC6774MultiBarter internal discount;
address internal DISCOUNT;

// users and their private keys
Expand All @@ -29,9 +29,9 @@ contract ERCN_test is Test, Utils {

function setUp() public {
// deploy tokens
ticket = new PermissionlessERC_NMultiBarter("Ticket", "00", "");
ticket = new PermissionlessERC6774MultiBarter("Ticket", "00", "");
TICKET = address(ticket);
discount = new PermissionlessERC_NMultiBarter("Discount", "01", "");
discount = new PermissionlessERC6774MultiBarter("Discount", "01", "");
DISCOUNT = address(discount);

// enable barters
Expand Down Expand Up @@ -67,7 +67,7 @@ contract ERCN_test is Test, Utils {
discount.mint(USER2, 12);

(
IERC_N.BarterTerms memory data,
IERC6774.BarterTerms memory data,
bytes memory signature
) = workaround_User1Ask(DISCOUNT, 12);

Expand All @@ -86,7 +86,7 @@ contract ERCN_test is Test, Utils {
discount.mint(USER2, 12);

(
IERC_N.BarterTerms memory data,
IERC6774.BarterTerms memory data,
bytes memory signature
) = workaround_User1Ask(DISCOUNT, 12);

Expand Down Expand Up @@ -121,7 +121,7 @@ contract ERCN_test is Test, Utils {
ticket.mint(USER2, 50);

(
IERC_N.BarterTerms memory data,
IERC6774.BarterTerms memory data,
bytes memory signature
) = workaround_User1Ask(TICKET, 50);

Expand All @@ -138,7 +138,7 @@ contract ERCN_test is Test, Utils {
ticket.enableBarterWith(TICKET);

(
IERC_N.BarterTerms memory data,
IERC6774.BarterTerms memory data,
bytes memory signature
) = workaround_User1Ask(TICKET, 50);

Expand All @@ -154,7 +154,7 @@ contract ERCN_test is Test, Utils {
discount.mint(USER2, 12);

(
IERC_N.BarterTerms memory data,
IERC6774.BarterTerms memory data,
bytes memory signature
) = workaround_User1Ask(DISCOUNT, 12);

Expand Down Expand Up @@ -189,7 +189,7 @@ contract ERCN_test is Test, Utils {
function test_barter_CannotUseAnExpiredSignature() public {
vm.warp(1000);
(
IERC_N.BarterTerms memory data,
IERC6774.BarterTerms memory data,
bytes32 structHash
) = workaround_CreateBarterTerms({
bidTokenAddr: TICKET,
Expand Down Expand Up @@ -232,7 +232,7 @@ contract ERCN_test is Test, Utils {
discount.mint(USER4, 4);

(
PermissionlessERC_NMultiBarter.MultiBarterTerms memory data,
PermissionlessERC6774MultiBarter.MultiBarterTerms memory data,
bytes memory signature
) = workaround_User3Ask();

Expand Down Expand Up @@ -269,7 +269,7 @@ contract ERCN_test is Test, Utils {
discount.mint(USER4, 4);

(
PermissionlessERC_NMultiBarter.MultiBarterTerms memory data,
PermissionlessERC6774MultiBarter.MultiBarterTerms memory data,
bytes memory signature
) = workaround_User4TryWithEmptyBid();

Expand All @@ -284,9 +284,9 @@ contract ERCN_test is Test, Utils {
function workaround_User1Ask(
address tokenAddr,
uint256 tokenId
) internal view returns (IERC_N.BarterTerms memory, bytes memory) {
) internal view returns (IERC6774.BarterTerms memory, bytes memory) {
(
IERC_N.BarterTerms memory data,
IERC6774.BarterTerms memory data,
bytes32 structHash
) = workaround_CreateBarterTerms({
bidTokenAddr: TICKET,
Expand Down Expand Up @@ -315,7 +315,7 @@ contract ERCN_test is Test, Utils {
internal
view
returns (
PermissionlessERC_NMultiBarter.MultiBarterTerms memory data,
PermissionlessERC6774MultiBarter.MultiBarterTerms memory data,
bytes memory
)
{
Expand Down Expand Up @@ -356,7 +356,7 @@ contract ERCN_test is Test, Utils {
internal
view
returns (
PermissionlessERC_NMultiBarter.MultiBarterTerms memory data,
PermissionlessERC6774MultiBarter.MultiBarterTerms memory data,
bytes memory
)
{
Expand Down
34 changes: 15 additions & 19 deletions assets/eip-6774/test/Utils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

pragma solidity ^0.8.13;

import {PermissionlessERC_NMultiBarter} from "../contracts/mocks/PermissionlessERC_NMultiBarter.sol";
import {IERC_N} from "../contracts/IERC_N.sol";
import {ERC_NMultiBarter} from "../contracts/extensions/ERC_NMultiBarter.sol";
import {PermissionlessERC6774MultiBarter} from "../contracts/mocks/PermissionlessERC6774MultiBarter.sol";
import {IERC6774} from "../contracts/IERC6774.sol";
import {ERC6774MultiBarter} from "../contracts/extensions/ERC6774MultiBarter.sol";

contract Utils {
bytes32 internal constant EIP712_TYPEHASH =
Expand Down Expand Up @@ -82,19 +82,15 @@ contract Utils {
internal
pure
returns (
PermissionlessERC_NMultiBarter.BarterTerms memory data,
PermissionlessERC6774MultiBarter.BarterTerms memory data,
bytes32 structHash
)
{
PermissionlessERC_NMultiBarter.Componant memory bid = IERC_N.Componant({
tokenAddr: bidTokenAddr,
tokenId: bidTokenId
});
PermissionlessERC_NMultiBarter.Componant memory ask = IERC_N.Componant({
tokenAddr: askTokenAddr,
tokenId: askTokenId
});
data = IERC_N.BarterTerms(bid, ask, nonce, owner, deadline);
PermissionlessERC6774MultiBarter.Componant memory bid = IERC6774
.Componant({tokenAddr: bidTokenAddr, tokenId: bidTokenId});
PermissionlessERC6774MultiBarter.Componant memory ask = IERC6774
.Componant({tokenAddr: askTokenAddr, tokenId: askTokenId});
data = IERC6774.BarterTerms(bid, ask, nonce, owner, deadline);

bytes32 bidStructHash = keccak256(
abi.encode(COMPONANT_TYPEHASH, bidTokenAddr, bidTokenId)
Expand Down Expand Up @@ -126,21 +122,21 @@ contract Utils {
internal
pure
returns (
PermissionlessERC_NMultiBarter.MultiBarterTerms memory data,
PermissionlessERC6774MultiBarter.MultiBarterTerms memory data,
bytes32 structHash
)
{
PermissionlessERC_NMultiBarter.MultiComponant
memory bid = ERC_NMultiBarter.MultiComponant({
PermissionlessERC6774MultiBarter.MultiComponant
memory bid = ERC6774MultiBarter.MultiComponant({
tokenAddr: bidTokenAddr,
tokenIds: bidTokenIds
});
PermissionlessERC_NMultiBarter.MultiComponant
memory ask = ERC_NMultiBarter.MultiComponant({
PermissionlessERC6774MultiBarter.MultiComponant
memory ask = ERC6774MultiBarter.MultiComponant({
tokenAddr: askTokenAddr,
tokenIds: askTokenIds
});
data = ERC_NMultiBarter.MultiBarterTerms(
data = ERC6774MultiBarter.MultiBarterTerms(
bid,
ask,
nonce,
Expand Down

0 comments on commit 8bac7d6

Please sign in to comment.