-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/openzeppelin-contracts"] | ||
path = lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts | ||
[submodule "lib/chainlink"] | ||
path = lib/chainlink | ||
url = https://github.com/smartcontractkit/chainlink | ||
[submodule "lib/chainlink-ccip"] | ||
path = lib/chainlink-ccip | ||
url = https://github.com/smartcontractkit/chainlink-ccip | ||
[submodule "lib/ccip"] | ||
path = lib/ccip | ||
url = https://github.com/smartcontractkit/ccip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
TODO: provide architecture and a quick project overview | ||
|
||
`ERC1155Core.sol` contains the main logic. | ||
It's based on the (openzeppellin) ERC1155 non fungible fractionalized contract. | ||
To enable cross chain interoperability, we need to add burn and mint. A transfer from a chain 'A' to a chain 'B' consists of burning the supply in the chain 'A' and minting it on the chain 'B' ensuring "uniqueness" of our data on all chains. | ||
|
||
kudos to (@andrej)[https://x.com/andrej_dev] for the chainlink bootcamp <3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
[profile.default] | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
src = 'src' | ||
out = 'out' | ||
libs = ['lib'] | ||
solc = '0.8.24' | ||
cache = true | ||
force = true | ||
optimizer = true | ||
optimizer_runs = 200 | ||
evm_version = 'cancun' | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options |
Submodule chainlink-ccip
added at
424892
Submodule openzeppelin-contracts
added at
b72e3d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@openzeppelin/=lib/openzeppelin-contracts/ | ||
@chainlink/=lib/chainlink/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {ERC1155Supply, ERC1155} from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol"; | ||
import {OwnerIsCreator} from "@chainlink/contracts/src/v0.8/shared/access/OwnerIsCreator.sol"; | ||
|
||
/** | ||
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY. | ||
* THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE. | ||
* DO NOT USE THIS CODE IN PRODUCTION. | ||
*/ | ||
contract ERC1155Core is ERC1155Supply, OwnerIsCreator { | ||
address internal s_issuer; | ||
|
||
// Optional mapping for token URIs | ||
mapping(uint256 tokenId => string) private _tokenURIs; | ||
|
||
event SetIssuer(address indexed issuer); | ||
|
||
error ERC1155Core_CallerIsNotIssuerOrItself(address msgSender); | ||
|
||
modifier onlyIssuerOrItself() { | ||
if (msg.sender != address(this) && msg.sender != s_issuer) { | ||
revert ERC1155Core_CallerIsNotIssuerOrItself(msg.sender); | ||
} | ||
_; | ||
} | ||
|
||
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json | ||
constructor(string memory uri_) ERC1155(uri_) {} | ||
|
||
function setIssuer(address _issuer) external onlyOwner { | ||
s_issuer = _issuer; | ||
|
||
emit SetIssuer(_issuer); | ||
} | ||
|
||
function mint(address _to, uint256 _id, uint256 _amount, bytes memory _data, string memory _tokenUri) | ||
public | ||
onlyIssuerOrItself | ||
{ | ||
_mint(_to, _id, _amount, _data); | ||
_tokenURIs[_id] = _tokenUri; | ||
} | ||
|
||
function mintBatch( | ||
address _to, | ||
uint256[] memory _ids, | ||
uint256[] memory _amounts, | ||
bytes memory _data, | ||
string[] memory _tokenUris | ||
) public onlyIssuerOrItself { | ||
_mintBatch(_to, _ids, _amounts, _data); | ||
for (uint256 i = 0; i < _ids.length; ++i) { | ||
_tokenURIs[_ids[i]] = _tokenUris[i]; | ||
} | ||
} | ||
|
||
function burn(address account, uint256 id, uint256 amount) public onlyIssuerOrItself { | ||
if (account != _msgSender() && !isApprovedForAll(account, _msgSender())) { | ||
revert ERC1155MissingApprovalForAll(_msgSender(), account); | ||
} | ||
|
||
_burn(account, id, amount); | ||
} | ||
|
||
function burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) public onlyIssuerOrItself { | ||
if (account != _msgSender() && !isApprovedForAll(account, _msgSender())) { | ||
revert ERC1155MissingApprovalForAll(_msgSender(), account); | ||
} | ||
|
||
_burnBatch(account, ids, amounts); | ||
} | ||
|
||
function uri(uint256 tokenId) public view override returns (string memory) { | ||
string memory tokenURI = _tokenURIs[tokenId]; | ||
|
||
return bytes(tokenURI).length > 0 ? tokenURI : super.uri(tokenId); | ||
} | ||
|
||
function _setURI(uint256 tokenId, string memory tokenURI) internal { | ||
_tokenURIs[tokenId] = tokenURI; | ||
emit URI(uri(tokenId), tokenId); | ||
} | ||
} |