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

Solucion Reto DNFT keeper opensea #50

Open
wants to merge 6 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
41 changes: 41 additions & 0 deletions Contracts/BlueDragon.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract BlueDragon is ERC721, ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
string[] uriData = [
"https://gateway.pinata.cloud/ipfs/QmTyf3WE89ezETCcrZpRvTaF1zjyUhwXP4fqC3tkCNn9jr",
"https://gateway.pinata.cloud/ipfs/QmSiZ4XE9an72QdmaHfmFMJ3TxjZUmXHCLFkCzXTiZY2EL",
"https://gateway.pinata.cloud/ipfs/Qmeh1GwaygAhDediixrkrwRVDdkpxmrjnX13MNXTrt1hPj"
];
Counters.Counter private _tokenIdCounter;

constructor() ERC721("BlueDragon", "BLD") {}

function safeMint(address to, string memory uri) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
}

// The following functions are overrides required by Solidity.

function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}

function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
}
66 changes: 66 additions & 0 deletions Contracts/BlueDragonDNFT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract BlueDragon is ERC721, ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
string[] uriData = [
"https://gateway.pinata.cloud/ipfs/QmTyf3WE89ezETCcrZpRvTaF1zjyUhwXP4fqC3tkCNn9jr",
"https://gateway.pinata.cloud/ipfs/QmSiZ4XE9an72QdmaHfmFMJ3TxjZUmXHCLFkCzXTiZY2EL",
"https://gateway.pinata.cloud/ipfs/Qmeh1GwaygAhDediixrkrwRVDdkpxmrjnX13MNXTrt1hPj"
];
Counters.Counter private _tokenIdCounter;

constructor() ERC721("BlueDragon", "BLD") {}

function safeMint(address to) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
_setTokenURI(tokenId, uriData[0]);
}
function changeNumber(uint256 _tokenId) public {
if (numberStage(_tokenId) >= 2) {
_setTokenURI(_tokenId, uriData[0]);
return;
}
uint256 newVal = numberStage(_tokenId) + 1; // Get the current number and add 1
string memory newUri = uriData[newVal]; // store the new URI
_setTokenURI(_tokenId, newUri);// Update the URI
}

// determine the stage of the Nft
function numberStage(uint256 _tokenId) public view returns (uint256) {
string memory _uri = tokenURI(_tokenId);
if (compareStrings(_uri, uriData[0])) {// Dragon 1
return 0;
}
if (compareStrings(_uri, uriData[1])) { // Dragon 2
return 1;
}
return 2; // Dragon 3
}
// helper function to compare strings
function compareStrings(string memory a, string memory b) public pure returns (bool) {
return (keccak256(abi.encodePacked((a))) ==
keccak256(abi.encodePacked((b))));
}
// The following functions are overrides required by Solidity.

function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}

function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
}
92 changes: 92 additions & 0 deletions Contracts/BlueDragonDNFTKeeper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

import "@chainlink/contracts/src/v0.8/KeeperCompatible.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract NFTDinamic is ERC721, ERC721URIStorage, KeeperCompatibleInterface {
using Counters for Counters.Counter;

Counters.Counter public tokenIdCounter;

// Metadata information for each stage of the NFT on IPFS.
string[] IpfsUri = [
"https://gateway.pinata.cloud/ipfs/QmTyf3WE89ezETCcrZpRvTaF1zjyUhwXP4fqC3tkCNn9jr",
"https://gateway.pinata.cloud/ipfs/QmSiZ4XE9an72QdmaHfmFMJ3TxjZUmXHCLFkCzXTiZY2EL",
"https://gateway.pinata.cloud/ipfs/Qmeh1GwaygAhDediixrkrwRVDdkpxmrjnX13MNXTrt1hPj"
];

uint256 lastTimeStamp;
uint256 interval;

constructor(uint256 _interval) ERC721("BlueDragon", "BLD") {
interval = _interval;
lastTimeStamp = block.timestamp;
}
function checkUpkeep(bytes calldata /* checkData */) external view override returns (bool upkeepNeeded, bytes memory /* performData */) {
uint256 tokenId = tokenIdCounter.current() - 1;
bool done;
if (numberStage(tokenId) >= 2) {
done = true;
}
upkeepNeeded = !done && ((block.timestamp - lastTimeStamp) > interval);
}

function performUpkeep(bytes calldata /* performData */) external override {
if ((block.timestamp - lastTimeStamp) > interval) {
lastTimeStamp = block.timestamp;
uint256 tokenId = tokenIdCounter.current() - 1;
changeNumber(tokenId);
}
// We don't use the performData in this example. The performData is generated by the Keeper's call to your checkUpkeep function
}

function safeMint(address to) public {
uint256 tokenId = tokenIdCounter.current();
tokenIdCounter.increment();
_safeMint(to, tokenId);
_setTokenURI(tokenId, IpfsUri[0]);
}

function changeNumber(uint256 _tokenId) public {
if (numberStage(_tokenId) >= 2) {
return;
}
// Get the current number and add 1
uint256 newVal = numberStage(_tokenId) + 1;
// store the new URI
string memory newUri = IpfsUri[newVal];
// Update the URI
_setTokenURI(_tokenId, newUri);
}

// determine the stage of number
function numberStage(uint256 _tokenId) public view returns (uint256) {
string memory _uri = tokenURI(_tokenId);
if (compareStrings(_uri, IpfsUri[0])) { // Dragon 1
return 0;
}
if (compareStrings(_uri, IpfsUri[1])) { // Dragon 2
return 1;
}
// Dragon 3
return 2;
}

// helper function to compare strings
function compareStrings(string memory a, string memory b) public pure returns (bool) {
return (keccak256(abi.encodePacked((a))) ==
keccak256(abi.encodePacked((b))));
}

// The following functions is an override required by Solidity.
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}

// The following functions is an override required by Solidity.
function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) {
return super.tokenURI(tokenId);
}
}
112 changes: 0 additions & 112 deletions DNFT.sol

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 0 additions & 15 deletions Metadata templates/creciendo.json

This file was deleted.

15 changes: 0 additions & 15 deletions Metadata templates/florecida.json

This file was deleted.

15 changes: 0 additions & 15 deletions Metadata templates/semilla.json

This file was deleted.

15 changes: 15 additions & 0 deletions Metadata/draco1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Dragon 1",
"description": "watercolor painting of a small blue dragon in a rock",
"image": "https://gateway.pinata.cloud/ipfs/QmcQfjjg4nn4c3p9b7MYhY9bDpWgZFbfED1Q4L5kmSzegU",
"attributes": [
{
"trait-type": "EtapaDraco",
"value": 1
},
{
"trait-type": "ColorDraco",
"value": "azul"
}
]
}
Loading