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

Add maker callback #44

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"solidity.formatter": "prettier"
}
49 changes: 39 additions & 10 deletions contracts/JoepegExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {IJoepegExchange} from "./interfaces/IJoepegExchange.sol";
import {ITransferManagerNFT} from "./interfaces/ITransferManagerNFT.sol";
import {ITransferSelectorNFT} from "./interfaces/ITransferSelectorNFT.sol";
import {IWAVAX} from "./interfaces/IWAVAX.sol";
import {ICallbackRecipient} from "./interfaces/ICallbackRecipient.sol";

// Joepeg libraries
import {OrderTypes} from "./libraries/OrderTypes.sol";
Expand Down Expand Up @@ -56,6 +57,8 @@ contract JoepegExchange is
mapping(address => mapping(uint256 => bool))
private _isUserOrderNonceExecutedOrCancelled;

mapping(address => bool) public isAllowedCallbackRecipient;

event CancelAllOrders(address indexed user, uint256 newMinNonce);
event CancelMultipleOrders(address indexed user, uint256[] orderNonces);
event NewCurrencyManager(address indexed currencyManager);
Expand All @@ -64,6 +67,10 @@ contract JoepegExchange is
event NewProtocolFeeRecipient(address indexed protocolFeeRecipient);
event NewRoyaltyFeeManager(address indexed royaltyFeeManager);
event NewTransferSelectorNFT(address indexed transferSelectorNFT);
event NewCallbackRecipientUpdate(
address indexed callbackRecipient,
bool isAllowed
);

event RoyaltyPayment(
address indexed collection,
Expand Down Expand Up @@ -448,6 +455,16 @@ contract JoepegExchange is
takerAsk.minPercentageToAsk
);

if (isAllowedCallbackRecipient[makerBid.signer]) {
ICallbackRecipient(makerBid.signer).saleCallback(
bidHash,
takerAsk.taker,
tokenId,
takerAsk.price,
takerAsk.params
);
}

emit TakerAsk(
bidHash,
makerBid.nonce,
Expand Down Expand Up @@ -555,6 +572,20 @@ contract JoepegExchange is
emit NewTransferSelectorNFT(_transferSelectorNFT);
}

/**
* @notice Update callback recipient
* @param _callbackRecipient The address of the callback recipient
* @param _isAllowed Whether the callback recipient is allowed or not
*/
function setCallbackRecipientAllowed(
address _callbackRecipient,
bool _isAllowed
) external onlyOwner {
isAllowedCallbackRecipient[_callbackRecipient] = _isAllowed;

emit NewCallbackRecipientUpdate(_callbackRecipient, _isAllowed);
}

/**
* @notice Check whether user order nonce is executed or cancelled
* @param user address of user
Expand Down Expand Up @@ -633,9 +664,9 @@ contract JoepegExchange is
// Match orders
for (uint256 i; i < trades.length; ++i) {
bool status = _matchAskWithTakerBidUsingAVAXAndWAVAXIgnoringExpiredAsks(
trades[i].takerBid,
trades[i].makerAsk
);
trades[i].takerBid,
trades[i].makerAsk
);
transferStatus[i] = status;
}

Expand Down Expand Up @@ -862,14 +893,12 @@ contract JoepegExchange is
}

/**
* @notice Check whether the maker order has expired or not
* @param makerOrder maker order
* @notice Check whether the maker order has expired or not
* @param makerOrder maker order
*/
function _checkMakerOrderNotExpired(OrderTypes.MakerOrder calldata makerOrder)
internal
view
returns (bool)
{
function _checkMakerOrderNotExpired(
OrderTypes.MakerOrder calldata makerOrder
) internal view returns (bool) {
return
!_isUserOrderNonceExecutedOrCancelled[makerOrder.signer][
makerOrder.nonce
Expand Down
2 changes: 1 addition & 1 deletion contracts/TransferManagerERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract TransferManagerERC721 is ITransferManagerNFT, Initializable {
address from,
address to,
uint256 tokenId,
uint256 amount
uint256
) external override {
require(msg.sender == joepegExchange, "Transfer: Only JoepegExchange");
// https://docs.openzeppelin.com/contracts/2.x/api/token/erc721#IERC721-safeTransferFrom
Expand Down
2 changes: 1 addition & 1 deletion contracts/TransferManagerNonCompliantERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract TransferManagerNonCompliantERC721 is
address from,
address to,
uint256 tokenId,
uint256 amount
uint256
) external override {
require(msg.sender == joepegExchange, "Transfer: Only JoepegExchange");
IERC721(collection).transferFrom(from, to, tokenId);
Expand Down
12 changes: 12 additions & 0 deletions contracts/interfaces/ICallbackRecipient.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ICallbackRecipient {
function saleCallback(
bytes32 orderHash,
address taker,
uint256 nftId,
uint256 price,
bytes calldata params
) external;
}
2 changes: 1 addition & 1 deletion contracts/mocks/ERC1155Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract ERC1155Token is
* @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
* exchange. The royalty amount is denominated and should be payed in that same unit of exchange.
*/
function royaltyInfo(uint256 _tokenId, uint256 _salePrice)
function royaltyInfo(uint256, uint256 _salePrice)
external
view
override
Expand Down
9 changes: 2 additions & 7 deletions contracts/mocks/ERC721Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ contract ERC721Token is ERC721("Sample NFT", "NFT"), Ownable, IERC2981 {
return newTokenId;
}

function tokenURI(uint256 tokenId)
public
pure
override
returns (string memory)
{
function tokenURI(uint256) public pure override returns (string memory) {
return
"https://ikzttp.mypinata.cloud/ipfs/QmQFkLSQysj94s5GvTHPyzTxrawwtjgiiYS2TBLgrvw8CW/5629";
}
Expand All @@ -43,7 +38,7 @@ contract ERC721Token is ERC721("Sample NFT", "NFT"), Ownable, IERC2981 {
* @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
* exchange. The royalty amount is denominated and should be payed in that same unit of exchange.
*/
function royaltyInfo(uint256 _tokenId, uint256 _salePrice)
function royaltyInfo(uint256, uint256 _salePrice)
external
view
override
Expand Down
7 changes: 1 addition & 6 deletions contracts/mocks/ERC721WithoutRoyaltyToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ contract ERC721WithoutRoyaltyToken is ERC721("Sample NFT", "NFT"), Ownable {
return newTokenId;
}

function tokenURI(uint256 tokenId)
public
pure
override
returns (string memory)
{
function tokenURI(uint256) public pure override returns (string memory) {
return
"https://ikzttp.mypinata.cloud/ipfs/QmQFkLSQysj94s5GvTHPyzTxrawwtjgiiYS2TBLgrvw8CW/5629";
}
Expand Down
38 changes: 38 additions & 0 deletions contracts/mocks/MockCallbackReceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {ICallbackRecipient} from "../interfaces/ICallbackRecipient.sol";

contract MockCallbackReceiver is ICallbackRecipient {
/// @dev bytes4(keccak256("isValidSignature(bytes32,bytes)")
bytes4 internal constant MAGIC_VALUE = 0x1626ba7e;

event CallbackCalled();

function saleCallback(
bytes32,
address,
uint256,
uint256,
bytes calldata
) external override {
emit CallbackCalled();
}

function isValidSignature(bytes32, bytes memory)
external
pure
returns (bytes4)
{
return MAGIC_VALUE;
}

function onERC721Received(
address,
address,
uint256,
bytes memory
) external pure returns (bytes4) {
return MockCallbackReceiver.onERC721Received.selector;
}
}
Loading