Skip to content

Commit

Permalink
Merge pull request #55 from Racks-Labs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yond1994 authored Dec 20, 2023
2 parents d6e0a5d + 0194161 commit f43884f
Show file tree
Hide file tree
Showing 23 changed files with 9,186 additions and 12,263 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/twenty-adults-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"erc721l": patch
---

udpate depencies and refactor E7L standard
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 20.x
cache: "npm"
registry-url: https://registry.npmjs.org/

Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install Dependencies
run: npm i

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Send a Slack notification if a publish happens
if: steps.changesets.outputs.published == 'true'
# You can do something when a publish happens.
run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!"
6 changes: 3 additions & 3 deletions contracts/E7L_basic.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "./ERC721Linkable.sol";
Expand All @@ -23,10 +23,10 @@ contract E7LBasic is ERC721Linkable {
uint256 parentTokenId,
IERC721
) external {
_linkToken(tokenId, parentTokenId, parentContract);
_safeLinkToken(tokenId, parentTokenId, parentContract);
}

function unlinkToken(uint256 tokenId) external {
_unlinkToken(tokenId);
_safeUnlinkToken(tokenId);
}
}
132 changes: 86 additions & 46 deletions contracts/ERC721Linkable.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
Expand Down Expand Up @@ -31,56 +31,93 @@ abstract contract ERC721Linkable is ERC721, IERC721Linkable {
function tokenInfo(
uint256 tokenId
) public view virtual override returns (LinkableToken memory) {
require(_exists(tokenId) == true, "ERC721: invalid token ID");
require(_ownerOf(tokenId) != address(0), "ERC721: invalid token ID");

return _tokensInfo[tokenId];
}

function isLinked(uint256 tokenId) public view virtual returns (bool) {
return address(_tokensInfo[tokenId].parentContract) != address(0);
}

function isSynced(uint256 tokenId) public view virtual returns (bool) {
LinkableToken memory token = _tokensInfo[tokenId];

return
token.parentContract.ownerOf(token.parentTokenId) ==
_ownerOf(tokenId);
}

/**
* @notice functions that links a tokenId from erc721linkable token to
* @notice functions that links a tokenId form erc721linkable token to
* another tokenId of the parent ERC721 contract
* emits link event
*/
function _linkToken(
function _safeLinkToken(
uint256 tokenId,
uint256 parentTokenId,
IERC721 parentContract
) internal {
LinkableToken storage token = _tokensInfo[tokenId];
require(
ERC721(address(parentContract)).supportsInterface(
type(IERC721).interfaceId
),
"ERC721Linkable: parent contract does not support ERC721 interface"
);

require(_ownerOf(tokenId) != address(0), "ERC721: invalid token ID");
require(
parentContract.supportsInterface(type(IERC721).interfaceId) == true,
"ERC721Linkable: parentContract is not IERC721"
_isAuthorized(this.ownerOf(tokenId), _msgSender(), tokenId),
"ERC721: caller is not token owner nor approved"
);
require(
super.ownerOf(tokenId) == parentContract.ownerOf(parentTokenId),
"ERC721Linkable: token owners do not match"
);
require(
address(token.parentContract) == address(0),
isLinked(tokenId) == false,
"ERC721Linkable: token is already linked"
);
require(
_isApprovedOrOwner(_msgSender(), tokenId),
"ERC721: caller is not token owner nor approved"
);

_linkToken(tokenId, parentTokenId, parentContract);
}

/**
* @notice internal functions that links a tokenId form erc721linkable token to a tokenIf from the parent ERC721 contract
*/
function _linkToken(
uint256 tokenId,
uint256 parentTokenId,
IERC721 parentContract
) internal {
LinkableToken storage token = _tokensInfo[tokenId];

token.parentTokenId = parentTokenId;
token.parentContract = parentContract;

emit Link(tokenId, parentTokenId, parentContract);
}

/**
* @notice functions that unlinks a linked tokenId from erc721linkable token
* emits unlink event
*/
function _unlinkToken(uint256 tokenId) internal {
LinkableToken storage token = _tokensInfo[tokenId];

function _safeUnlinkToken(uint256 tokenId) internal {
require(
_isApprovedOrOwner(_msgSender(), tokenId),
_isAuthorized(this.ownerOf(tokenId), _msgSender(), tokenId),
"ERC721: caller is not token owner nor approved"
);

_unlinkToken(tokenId);
}

/**
* @notice functions that unlinks a linked tokenId from erc721linkable token
* emits unlink event
*/
function _unlinkToken(uint256 tokenId) internal {
LinkableToken storage token = _tokensInfo[tokenId];

token.parentTokenId = 0;
token.parentContract = IERC721(address(0));
emit Unlink(tokenId);
Expand All @@ -94,47 +131,50 @@ abstract contract ERC721Linkable is ERC721, IERC721Linkable {
LinkableToken memory token = _tokensInfo[tokenId];

require(
super.ownerOf(tokenId) !=
token.parentContract.ownerOf(
_tokensInfo[tokenId].parentTokenId
),
isSynced(tokenId) == false,
"ERC721Linkable: token already synced"
);
_safeTransfer(
super.ownerOf(tokenId),
token.parentContract.ownerOf(_tokensInfo[tokenId].parentTokenId),
tokenId,
""

require(isLinked(tokenId), "ERC721Linkable: token not linked");

address ownerOfParentToken = token.parentContract.ownerOf(
token.parentTokenId
);
address ownerOfToken = _ownerOf(tokenId);

if (ownerOfParentToken == address(0)) {
/// @dev use burn instead of transfer to have a correct accounting of
/// the total supply and burned tokens
_burn(tokenId);
delete _tokensInfo[tokenId];
} else {
_transfer(ownerOfToken, ownerOfParentToken, tokenId);
}
}

/**
* @dev override of _beforeTokenTransfer hook to only allow transfers to the owner
* of the linked tokenId of the parent contract
*/
function _beforeTokenTransfer(
address from,
function _update(
address to,
uint256 tokenId,
uint256 batchSize
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId, batchSize);

LinkableToken memory token = _tokensInfo[tokenId];

if (_exists(tokenId)) {
require(
address(_tokensInfo[tokenId].parentContract) != address(0),
"ERC721Linkable: cannot transfer token because is not linked"
);
require(
from == super.ownerOf(tokenId) &&
to ==
token.parentContract.ownerOf(
_tokensInfo[tokenId].parentTokenId
),
"ERC721Linkable: invalid address. Use syncToken()"
);
address auth
) internal virtual override returns (address) {
if (_ownerOf(tokenId) != address(0)) {
LinkableToken memory token = _tokensInfo[tokenId];

if (isLinked(tokenId)) {
bool isTheLegitimateOwner = to ==
token.parentContract.ownerOf(token.parentTokenId);

require(
isTheLegitimateOwner,
"ERC721Linkable: the 'to' address is not the legitimate owner"
);
}
}

return super._update(to, tokenId, auth);
}
}
2 changes: 1 addition & 1 deletion contracts/IERC721Linkable.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;

Expand Down
4 changes: 3 additions & 1 deletion contracts/IMRC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ pragma solidity ^0.8.7;
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";

interface IMRC is IERC721Enumerable {
function walletOfOwner(address account) external view returns (uint256[] memory);
function walletOfOwner(
address account
) external view returns (uint256[] memory);
}
2 changes: 1 addition & 1 deletion contracts/Linkable.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/upgradeable/E7LProxy.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/upgradeable/E7LUpgradeable_basic.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "./ERC721LinkableUpgradeable.sol";
Expand All @@ -25,7 +25,7 @@ contract E7LUpgradeableBasic is ERC721LinkableUpgradeable {
uint256 parentTokenId,
IERC721
) external {
_linkToken(tokenId, parentTokenId, parentContract);
_safeLinkToken(tokenId, parentTokenId, parentContract);
}

function unlinkToken(uint256 tokenId) external {
Expand Down
Loading

0 comments on commit f43884f

Please sign in to comment.