Skip to content

Commit

Permalink
Merge pull request #135 from G7DAO/feat/reduce-ERC1155RoyalitySoulbou…
Browse files Browse the repository at this point in the history
…ndV1-size

refactor: Reduce ERC1155RoyalitySoulboundV1 size
  • Loading branch information
vasinl124 authored May 23, 2024
2 parents b374c50 + 74efc6f commit adf0ef0
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 270 deletions.
6 changes: 3 additions & 3 deletions constants/constructor-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ export const AvatarBoundArgs = {
baseURI: '',
contractURI: 'https://achievo.mypinata.cloud/ipfs/QmSDbeNWVY2CGUuLHni689L5eSrSG3iZHyTRZJWXX7GpjS',
revealURI: 'Qmdk4zHamwCyqSzuWNNYypuz4FXAGdApbky7SHNsXYYQg7',
compoundURI: 'https://api.achievo.xyz/v1/uri/avatar',
devWallet: 'DEPLOYER_WALLET',
gatingNftAddress: '0xD07180c423F9B8CF84012aA28cC174F3c433EE29',
itemsNftAddress: `CONTRACT_${CONTRACT_NAME.Items}`,
compoundURI: 'https://api.achievo.xyz/v1/uri/avatar',
mintNftGatingEnabled: true,
mintNFtWithoutGatingEnabled: true,
mintRandomItemEnabled: true,
Expand All @@ -159,10 +159,10 @@ export const AvatarBoundArgs = {
baseURI: '',
contractURI: 'https://achievo.mypinata.cloud/ipfs/QmSDbeNWVY2CGUuLHni689L5eSrSG3iZHyTRZJWXX7GpjS',
revealURI: 'QmZnvSyeKRQxWwcofVmq41BNCtHbBmomk8Ny8mtGRTjtzS',
compoundURI: 'https://staging-api.achievo.xyz/v1/uri/avatar',
devWallet: 'DEPLOYER_WALLET',
gatingNftAddress: '0x6E03Ea6c9aBBb78Dd761b9c71c06176c508488C3',
itemsNftAddress: `CONTRACT_${CONTRACT_NAME.Items}`,
compoundURI: 'https://staging-api.achievo.xyz/v1/uri/avatar',
mintNftGatingEnabled: true,
mintNFtWithoutGatingEnabled: true,
mintRandomItemEnabled: true,
Expand Down Expand Up @@ -514,4 +514,4 @@ export const EnglishAuctionsExtensionArgs = {
export const OffersExtensionArgs = {
MAINNET: {},
TESTNET: {},
};
};
2 changes: 1 addition & 1 deletion constants/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ export enum CONTRACT_UPGRADABLE_NAME {

export enum CONTRACT_EXTENSION_NAME {
DirectListingExtension = 'DirectListingExtension',
EnglishAuctionsExtension = 'EnglishAuctionsExtension'
EnglishAuctionsExtension = 'EnglishAuctionsExtension',
}
62 changes: 61 additions & 1 deletion constants/deployments/deployments-base-sepolia.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BUIDLArgs, ERC20Args, ERC20DecimalsAgs } from '@constants/constructor-args';
import { AvatarBoundV1Args, ERC20DecimalsAgs, ItemBoundArgs, LevelsBoundV1Args } from '@constants/constructor-args';
import { CONTRACT_TYPE, CONTRACT_UPGRADABLE_FILE_NAME, CONTRACT_UPGRADABLE_NAME } from '@constants/contract';
import { TENANT } from '@constants/tenant';

Expand All @@ -22,4 +22,64 @@ export const BASE_SEPOLIA_CONTRACTS: DeploymentContract[] = [
functionCalls: [],
args: ERC20DecimalsAgs.TESTNET,
},
{
contractFileName: CONTRACT_UPGRADABLE_FILE_NAME.Levels,
type: CONTRACT_TYPE.Levels,
name: CONTRACT_UPGRADABLE_NAME.Levels,
chain,
networkType,
tenants: [TENANT.Game7],
verify: true,
upgradable: true,
dependencies: [CONTRACT_UPGRADABLE_NAME.Items, CONTRACT_UPGRADABLE_NAME.Avatars],
args: LevelsBoundV1Args.TESTNET,
},
{
contractFileName: CONTRACT_UPGRADABLE_FILE_NAME.Avatars,
type: CONTRACT_TYPE.Avatars,
name: CONTRACT_UPGRADABLE_NAME.Avatars,
chain,
networkType,
tenants: [TENANT.Game7],
verify: true,
upgradable: true,
dependencies: [CONTRACT_UPGRADABLE_NAME.Items, CONTRACT_UPGRADABLE_NAME.Levels],
functionCalls: [
{
contractName: CONTRACT_UPGRADABLE_NAME.Avatars,
functionName: 'setDefaultItemId',
args: [10001],
},
{
contractName: CONTRACT_UPGRADABLE_NAME.Avatars,
functionName: 'setSpecialItemId',
args: [10002],
},
],
args: AvatarBoundV1Args.TESTNET,
},
{
contractFileName: CONTRACT_UPGRADABLE_FILE_NAME.ERC1155RoyaltiesSoulbound,
type: CONTRACT_TYPE.Items,
name: CONTRACT_UPGRADABLE_NAME.Items,
chain,
networkType,
tenants: [TENANT.Game7],
verify: true,
upgradable: true,
dependencies: [CONTRACT_UPGRADABLE_NAME.Avatars],
functionCalls: [
{
contractName: CONTRACT_UPGRADABLE_NAME.Items,
functionName: 'grantRole',
args: ['MINTER_ROLE', `CONTRACT_${CONTRACT_UPGRADABLE_NAME.Avatars}`],
},
{
contractName: CONTRACT_UPGRADABLE_NAME.Items,
functionName: 'grantRole',
args: ['MINTER_ROLE', `CONTRACT_${CONTRACT_UPGRADABLE_NAME.Levels}`],
},
],
args: ItemBoundArgs.TESTNET,
},
];
12 changes: 6 additions & 6 deletions contracts/libraries/LibItems.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ library LibItems {
string tierName;
}

struct TokenCreate {
uint256 tokenId;
string tokenUri;
}

enum RewardType {
ETHER,
ERC20,
Expand Down Expand Up @@ -57,7 +52,12 @@ library LibItems {
uint256 maxSupply; // 0 mean unlimited
}

struct TokenCreateWithRoyalty {
struct TokenCreateLegacy {
uint256 tokenId;
string tokenUri;
}

struct TokenCreate {
uint256 tokenId;
string tokenUri;
address receiver;
Expand Down
68 changes: 12 additions & 56 deletions contracts/soulbounds/ERC1155RoyaltiesSoulbound.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ERCWhitelistSignature } from "../ercs/ERCWhitelistSignature.sol";
import { LibItems } from "../libraries/LibItems.sol";

error InvalidSeed();
error MissingRole();

contract ERC1155RoyaltiesSoulbound is
ERC1155Burnable,
Expand Down Expand Up @@ -105,16 +106,20 @@ contract ERC1155RoyaltiesSoulbound is
if (_isPaused) _pause();
}

function getAllItems() public view returns (LibItems.TokenReturn[] memory) {
function getAllItems(address _owner) public view returns (LibItems.TokenReturn[] memory) {
bool isAdmin = hasRole(MINTER_ROLE, _msgSender());
if (!isAdmin && _owner != _msgSender()) {
revert MissingRole();
}
uint256 totalTokens = itemIds.length;
LibItems.TokenReturn[] memory tokenReturns = new LibItems.TokenReturn[](totalTokens);

uint index;
for (uint i = 0; i < totalTokens; i++) {
uint256 tokenId = itemIds[i];
uint256 amount = balanceOf(_msgSender(), tokenId);
uint256 amount = balanceOf(_owner, tokenId);

if (amount > 0) {
if (isAdmin || amount > 0) {
LibItems.TokenReturn memory tokenReturn = LibItems.TokenReturn({
tokenId: tokenId,
tokenUri: uri(tokenId),
Expand All @@ -134,35 +139,6 @@ contract ERC1155RoyaltiesSoulbound is
return returnsTruncated;
}

function getAllItemsAdmin(
address _owner
) public view onlyRole(MINTER_ROLE) returns (LibItems.TokenReturn[] memory) {
uint256 totalTokens = itemIds.length;
LibItems.TokenReturn[] memory tokenReturns = new LibItems.TokenReturn[](totalTokens);

uint index;
for (uint i = 0; i < totalTokens; i++) {
uint256 tokenId = itemIds[i];
uint256 amount = balanceOf(_owner, tokenId);

LibItems.TokenReturn memory tokenReturn = LibItems.TokenReturn({
tokenId: tokenId,
tokenUri: uri(tokenId),
amount: amount
});
tokenReturns[index] = tokenReturn;
index++;
}

// truncate the array
LibItems.TokenReturn[] memory returnsTruncated = new LibItems.TokenReturn[](index);
for (uint i = 0; i < index; i++) {
returnsTruncated[i] = tokenReturns[i];
}

return returnsTruncated;
}

function isTokenExist(uint256 _tokenId) public view returns (bool) {
if (!tokenExists[_tokenId]) {
revert("TokenNotExist");
Expand Down Expand Up @@ -215,6 +191,10 @@ contract ERC1155RoyaltiesSoulbound is
tokenUris[_token.tokenId] = _token.tokenUri;
}

if (_token.receiver != address(0)) {
_setTokenRoyalty(_token.tokenId, _token.receiver, uint96(_token.feeBasisPoints));
}

tokenExists[_token.tokenId] = true;

itemIds.push(_token.tokenId);
Expand All @@ -227,30 +207,6 @@ contract ERC1155RoyaltiesSoulbound is
}
}

function addNewTokenWithRoyalty(LibItems.TokenCreateWithRoyalty calldata _token) public onlyRole(DEV_CONFIG_ROLE) {
if (_token.receiver == address(0)) {
revert("ReceiverAddressZero");
}

if (bytes(_token.tokenUri).length > 0) {
tokenUris[_token.tokenId] = _token.tokenUri;
}

tokenExists[_token.tokenId] = true;

itemIds.push(_token.tokenId);

_setTokenRoyalty(_token.tokenId, _token.receiver, uint96(_token.feeBasisPoints));
}

function addNewTokensWithRoyalty(
LibItems.TokenCreateWithRoyalty[] calldata _tokens
) external onlyRole(DEV_CONFIG_ROLE) {
for (uint256 i = 0; i < _tokens.length; i++) {
addNewTokenWithRoyalty(_tokens[i]);
}
}

function updateTokenUri(uint256 _tokenId, string calldata _tokenUri) public onlyRole(DEV_CONFIG_ROLE) {
tokenUris[_tokenId] = _tokenUri;
}
Expand Down
67 changes: 12 additions & 55 deletions contracts/soulbounds/ERC1155Soulbound.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { Achievo1155Soulbound } from "../ercs/extensions/Achievo1155Soulbound.so
import { ERCWhitelistSignature } from "../ercs/ERCWhitelistSignature.sol";
import { LibItems } from "../libraries/LibItems.sol";

error MissingRole();

contract ERC1155Soulbound is
ERC1155Burnable,
ERC1155Supply,
Expand Down Expand Up @@ -103,16 +105,20 @@ contract ERC1155Soulbound is
if (_isPaused) _pause();
}

function getAllItems() public view returns (LibItems.TokenReturn[] memory) {
function getAllItems(address _owner) public view returns (LibItems.TokenReturn[] memory) {
bool isAdmin = hasRole(MINTER_ROLE, _msgSender());
if (!isAdmin && _owner != _msgSender()) {
revert MissingRole();
}
uint256 totalTokens = itemIds.length;
LibItems.TokenReturn[] memory tokenReturns = new LibItems.TokenReturn[](totalTokens);

uint index;
for (uint i = 0; i < totalTokens; i++) {
uint256 tokenId = itemIds[i];
uint256 amount = balanceOf(_msgSender(), tokenId);
uint256 amount = balanceOf(_owner, tokenId);

if (amount > 0) {
if (isAdmin || amount > 0) {
LibItems.TokenReturn memory tokenReturn = LibItems.TokenReturn({
tokenId: tokenId,
tokenUri: uri(tokenId),
Expand All @@ -132,35 +138,6 @@ contract ERC1155Soulbound is
return returnsTruncated;
}

function getAllItemsAdmin(
address _owner
) public view onlyRole(MINTER_ROLE) returns (LibItems.TokenReturn[] memory) {
uint256 totalTokens = itemIds.length;
LibItems.TokenReturn[] memory tokenReturns = new LibItems.TokenReturn[](totalTokens);

uint index;
for (uint i = 0; i < totalTokens; i++) {
uint256 tokenId = itemIds[i];
uint256 amount = balanceOf(_owner, tokenId);

LibItems.TokenReturn memory tokenReturn = LibItems.TokenReturn({
tokenId: tokenId,
tokenUri: uri(tokenId),
amount: amount
});
tokenReturns[index] = tokenReturn;
index++;
}

// truncate the array
LibItems.TokenReturn[] memory returnsTruncated = new LibItems.TokenReturn[](index);
for (uint i = 0; i < index; i++) {
returnsTruncated[i] = tokenReturns[i];
}

return returnsTruncated;
}

function isTokenExist(uint256 _tokenId) public view returns (bool) {
if (!tokenExists[_tokenId]) {
revert("TokenNotExist");
Expand All @@ -185,25 +162,13 @@ contract ERC1155Soulbound is
_unpause();
}

function addNewTokenWithRoyalty(LibItems.TokenCreateWithRoyalty calldata _token) public onlyRole(DEV_CONFIG_ROLE) {
if (_token.receiver == address(0)) {
revert("ReceiverAddressZero");
}

function addNewToken(LibItems.TokenCreate calldata _token) public onlyRole(DEV_CONFIG_ROLE) {
if (bytes(_token.tokenUri).length > 0) {
tokenUris[_token.tokenId] = _token.tokenUri;
}

tokenExists[_token.tokenId] = true;

itemIds.push(_token.tokenId);

_setTokenRoyalty(_token.tokenId, _token.receiver, uint96(_token.feeBasisPoints));
}

function addNewToken(LibItems.TokenCreate calldata _token) public onlyRole(DEV_CONFIG_ROLE) {
if (bytes(_token.tokenUri).length > 0) {
tokenUris[_token.tokenId] = _token.tokenUri;
if (_token.receiver != address(0)) {
_setTokenRoyalty(_token.tokenId, _token.receiver, uint96(_token.feeBasisPoints));
}

tokenExists[_token.tokenId] = true;
Expand All @@ -212,14 +177,6 @@ contract ERC1155Soulbound is
emit TokenAdded(_token.tokenId);
}

function addNewTokensWithRoyalty(
LibItems.TokenCreateWithRoyalty[] calldata _tokens
) external onlyRole(DEV_CONFIG_ROLE) {
for (uint256 i = 0; i < _tokens.length; i++) {
addNewTokenWithRoyalty(_tokens[i]);
}
}

function addNewTokens(LibItems.TokenCreate[] calldata _tokens) external onlyRole(DEV_CONFIG_ROLE) {
for (uint256 i = 0; i < _tokens.length; i++) {
addNewToken(_tokens[i]);
Expand Down
Loading

0 comments on commit adf0ef0

Please sign in to comment.