Skip to content

Commit

Permalink
Merge pull request #6 from crossnft-labs/feature/pay-for-nft-minting
Browse files Browse the repository at this point in the history
Feature/pay for nft minting
  • Loading branch information
cross-nft-labs authored Dec 6, 2023
2 parents a617d51 + 1c24562 commit bd31612
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 28 deletions.
72 changes: 66 additions & 6 deletions contracts/CrossNftDestinationMinter.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,82 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {MyNFT} from "./MyNFT.sol";

contract CrossNftDestinationMinter is CCIPReceiver {
MyNFT nft;
contract MyNFT is ERC721URIStorage, OwnerIsCreator {
// string constant TOKEN_URI =
// "https://ipfs.io/ipfs/QmYuKY45Aq87LeL1R5dhb1hqHLp6ZFbJaCP8jxqKM1MX6y/babe_ruth_1.json";
uint256 internal tokenId;

constructor() ERC721("MyNFT", "MNFT"){}

function mint(address to, string memory TOKEN_URI) public onlyOwner {
_safeMint(to, tokenId);
_setTokenURI(tokenId, TOKEN_URI);
unchecked {
tokenId++;
}
}
}
contract CrossNftDestinationMinter is CCIPReceiver, OwnerIsCreator{
MyNFT public nft;
uint256 price;

event MintCallSuccessfull();
mapping(uint64 => bool) public whitelistedSourceChains;
mapping(address => bool) public whitelistedSenders;

event MintCallSuccessfull();

constructor(address router, address nftAddress) CCIPReceiver(router) {
nft = MyNFT(nftAddress);
error SourceChainNotWhitelisted(uint64 sourceChainSelector);
error SenderNotWhitelisted(address sender);

modifier onlyWhitelistedSourceChain(uint64 _sourceChainSelector) {
if (!whitelistedSourceChains[_sourceChainSelector])
revert SourceChainNotWhitelisted(_sourceChainSelector);
_;
}

modifier onlyWhitelistedSenders(address _sender) {
if (!whitelistedSenders[_sender]) revert SenderNotWhitelisted(_sender);
_;
}

constructor(address router, uint256 _price) CCIPReceiver(router) {
nft = new MyNFT();
price = _price;
}

function whitelistSourceChain(
uint64 _sourceChainSelector
) external onlyOwner {
whitelistedSourceChains[_sourceChainSelector] = true;
}

function denylistSourceChain(
uint64 _sourceChainSelector
) external onlyOwner {
whitelistedSourceChains[_sourceChainSelector] = false;
}

function whitelistSender(address _sender) external onlyOwner {
whitelistedSenders[_sender] = true;
}

function denySender(address _sender) external onlyOwner {
whitelistedSenders[_sender] = false;
}
function _ccipReceive(
Client.Any2EVMMessage memory message
) internal override {
) internal
onlyWhitelistedSourceChain(message.sourceChainSelector)
onlyWhitelistedSenders(abi.decode(message.sender, (address)))
override
{
require(message.destTokenAmounts[0].amount >= price, "Not enough CCIP-BnM for mint");
(bool success, ) = address(nft).call(message.data);
require(success);
emit MintCallSuccessfull();
Expand Down
2 changes: 1 addition & 1 deletion contracts/CrossNftSourceMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract CrossNftSourceMinter is OwnerIsCreator{
// Build the CCIP Message
Client.EVM2AnyMessage memory message = Client.EVM2AnyMessage({
receiver: abi.encode(_receiver),
data: abi.encodeWithSignature("mint(address, _metadataURL)", msg.sender),
data: abi.encodeWithSignature("mint(address, string)", msg.sender, _metadataURL),
tokenAmounts: tokenAmounts,
extraArgs: Client._argsToBytes(
Client.EVMExtraArgsV1({gasLimit: 200_000, strict: false})
Expand Down
21 changes: 0 additions & 21 deletions contracts/MyNFT.sol

This file was deleted.

0 comments on commit bd31612

Please sign in to comment.