-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: rename TradeTrustTokenImpl to TradeTrustTokenStandard * refactor: rename test files token names * refactor: rename init function to token name * refactor: move pausable and registry access into base * feat: restructure the codebase fix: remove extensions * test: separate mint, burn and restore tests * test: remove mint, burn and restore tests from TradeTrustToken.test.ts * test: refactor deployTokenFixtureRunner * test: add interface support test in all extension bases * test: update tests * feat: update contract testnet addresses * feat: add mainnet contract addresses * fix: gap
- Loading branch information
Showing
33 changed files
with
1,007 additions
and
577 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; | ||
import "./SBTUpgradeable.sol"; | ||
import "../interfaces/ITitleEscrow.sol"; | ||
import "../interfaces/ITitleEscrowFactory.sol"; | ||
import "../interfaces/TradeTrustTokenErrors.sol"; | ||
import "../interfaces/ITradeTrustSBT.sol"; | ||
|
||
abstract contract TradeTrustSBT is SBTUpgradeable, PausableUpgradeable, TradeTrustTokenErrors, ITradeTrustSBT { | ||
function __TradeTrustSBT_init(string memory name, string memory symbol) internal onlyInitializing { | ||
__SBT_init(name, symbol); | ||
__Pausable_init(); | ||
} | ||
|
||
function supportsInterface(bytes4 interfaceId) | ||
public | ||
view | ||
virtual | ||
override(SBTUpgradeable, IERC165Upgradeable) | ||
returns (bool) | ||
{ | ||
return interfaceId == type(ITradeTrustSBT).interfaceId || SBTUpgradeable.supportsInterface(interfaceId); | ||
} | ||
|
||
function onERC721Received( | ||
address, /* _operator */ | ||
address, /* _from */ | ||
uint256, /* _tokenId */ | ||
bytes memory /* _data */ | ||
) public pure override returns (bytes4) { | ||
return IERC721Receiver.onERC721Received.selector; | ||
} | ||
|
||
function _registryTransferTo(address to, uint256 tokenId) internal { | ||
this.transferFrom(address(this), to, tokenId); | ||
} | ||
|
||
function _beforeTokenTransfer( | ||
address from, | ||
address to, | ||
uint256 tokenId | ||
) internal virtual override whenNotPaused { | ||
super._beforeTokenTransfer(from, to, tokenId); | ||
} | ||
|
||
function genesis() public view virtual override returns (uint256); | ||
|
||
function titleEscrowFactory() public view virtual override returns (ITitleEscrowFactory); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "./TradeTrustSBT.sol"; | ||
import "./RegistryAccess.sol"; | ||
import "../interfaces/ITradeTrustTokenBurnable.sol"; | ||
|
||
abstract contract TradeTrustTokenBurnable is TradeTrustSBT, RegistryAccess, ITradeTrustTokenBurnable { | ||
address internal constant BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD; | ||
|
||
function supportsInterface(bytes4 interfaceId) | ||
public | ||
view | ||
virtual | ||
override(TradeTrustSBT, RegistryAccess) | ||
returns (bool) | ||
{ | ||
return interfaceId == type(ITradeTrustTokenBurnable).interfaceId || super.supportsInterface(interfaceId); | ||
} | ||
|
||
function burn(uint256 tokenId) external virtual override whenNotPaused onlyRole(ACCEPTER_ROLE) { | ||
_burnTitle(tokenId); | ||
} | ||
|
||
function _burnTitle(uint256 tokenId) internal virtual { | ||
address titleEscrow = titleEscrowFactory().getAddress(address(this), tokenId); | ||
ITitleEscrow(titleEscrow).shred(); | ||
|
||
// Burning token to 0xdead instead to show a differentiate state as address(0) is used for unminted tokens | ||
_registryTransferTo(BURN_ADDRESS, tokenId); | ||
} | ||
|
||
function _beforeTokenTransfer( | ||
address from, | ||
address to, | ||
uint256 tokenId | ||
) internal virtual override { | ||
if (to == BURN_ADDRESS && ownerOf(tokenId) != address(this)) { | ||
revert TokenNotSurrendered(); | ||
} | ||
super._beforeTokenTransfer(from, to, tokenId); | ||
} | ||
} |
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,41 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "./TradeTrustSBT.sol"; | ||
import "./RegistryAccess.sol"; | ||
import "../interfaces/ITradeTrustTokenMintable.sol"; | ||
|
||
abstract contract TradeTrustTokenMintable is TradeTrustSBT, RegistryAccess, ITradeTrustTokenMintable { | ||
function supportsInterface(bytes4 interfaceId) | ||
public | ||
view | ||
virtual | ||
override(TradeTrustSBT, RegistryAccess) | ||
returns (bool) | ||
{ | ||
return interfaceId == type(ITradeTrustTokenMintable).interfaceId || super.supportsInterface(interfaceId); | ||
} | ||
|
||
function mint( | ||
address beneficiary, | ||
address holder, | ||
uint256 tokenId | ||
) external virtual override whenNotPaused onlyRole(MINTER_ROLE) returns (address) { | ||
return _mintTitle(beneficiary, holder, tokenId); | ||
} | ||
|
||
function _mintTitle( | ||
address beneficiary, | ||
address holder, | ||
uint256 tokenId | ||
) internal virtual returns (address) { | ||
if (_exists(tokenId)) { | ||
revert TokenExists(); | ||
} | ||
|
||
address newTitleEscrow = titleEscrowFactory().create(tokenId); | ||
_safeMint(newTitleEscrow, tokenId, abi.encode(beneficiary, holder)); | ||
|
||
return newTitleEscrow; | ||
} | ||
} |
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,32 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "./TradeTrustSBT.sol"; | ||
import "./RegistryAccess.sol"; | ||
import "../interfaces/ITradeTrustTokenRestorable.sol"; | ||
|
||
abstract contract TradeTrustTokenRestorable is TradeTrustSBT, RegistryAccess, ITradeTrustTokenRestorable { | ||
function supportsInterface(bytes4 interfaceId) | ||
public | ||
view | ||
virtual | ||
override(TradeTrustSBT, RegistryAccess) | ||
returns (bool) | ||
{ | ||
return interfaceId == type(ITradeTrustTokenRestorable).interfaceId || super.supportsInterface(interfaceId); | ||
} | ||
|
||
function restore(uint256 tokenId) external virtual override whenNotPaused onlyRole(RESTORER_ROLE) returns (address) { | ||
if (!_exists(tokenId)) { | ||
revert InvalidTokenId(); | ||
} | ||
if (ownerOf(tokenId) != address(this)) { | ||
revert TokenNotSurrendered(); | ||
} | ||
|
||
address titleEscrow = titleEscrowFactory().getAddress(address(this), tokenId); | ||
_registryTransferTo(titleEscrow, tokenId); | ||
|
||
return titleEscrow; | ||
} | ||
} |
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,12 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol"; | ||
import "./ISBTUpgradeable.sol"; | ||
import "./ITitleEscrowFactory.sol"; | ||
|
||
interface ITradeTrustSBT is IERC721ReceiverUpgradeable, ISBTUpgradeable { | ||
function genesis() external view returns (uint256); | ||
|
||
function titleEscrowFactory() external view returns (ITitleEscrowFactory); | ||
} |
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,22 +1,14 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol"; | ||
import "./ISBTUpgradeable.sol"; | ||
import "./ITitleEscrowFactory.sol"; | ||
|
||
interface ITradeTrustToken is IERC721ReceiverUpgradeable, ISBTUpgradeable { | ||
function genesis() external view returns (uint256); | ||
|
||
function titleEscrowFactory() external view returns (ITitleEscrowFactory); | ||
|
||
function burn(uint256 tokenId) external; | ||
|
||
function restore(uint256 tokenId) external returns (address); | ||
|
||
function mint( | ||
address beneficiary, | ||
address holder, | ||
uint256 tokenId | ||
) external returns (address); | ||
} | ||
import "./ITradeTrustSBT.sol"; | ||
import "./ITradeTrustTokenRestorable.sol"; | ||
import "./ITradeTrustTokenBurnable.sol"; | ||
import "./ITradeTrustTokenMintable.sol"; | ||
|
||
interface ITradeTrustToken is | ||
ITradeTrustTokenMintable, | ||
ITradeTrustTokenBurnable, | ||
ITradeTrustTokenRestorable, | ||
ITradeTrustSBT | ||
{} |
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,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
interface ITradeTrustTokenBurnable { | ||
function burn(uint256 tokenId) external; | ||
} |
Oops, something went wrong.