Skip to content

Commit

Permalink
Merge branch 'main' of github.com:G7DAO/achievo-contracts into feat/a…
Browse files Browse the repository at this point in the history
…dd-g7-mainnet
  • Loading branch information
ogarciarevett committed Oct 20, 2024
2 parents 9bd93f3 + 85eaabd commit d8f2232
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
19 changes: 17 additions & 2 deletions contracts/soulbounds/RewardsNative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,24 @@ contract RewardsNative is
return _decodeData(_data);
}

function createTokenAndDepositRewards(
function _dangerous_createTokenAndDepositRewards(
LibRewards.RewardToken calldata _token
) public payable onlyRole(DEV_CONFIG_ROLE) {
_createTokenAndDepositRewards(_token);
}

function _dangerous_createMultipleTokensAndDepositRewards(
LibRewards.RewardToken[] calldata _tokens
) external payable onlyRole(DEV_CONFIG_ROLE) {
// Create tokens and deposit rewards
for (uint256 i = 0; i < _tokens.length; i++) {
_createTokenAndDepositRewards(_tokens[i]);
}
}

function createTokenAndDepositRewards(
LibRewards.RewardToken calldata _token
) public payable onlyRole(MANAGER_ROLE) {
uint256 _ethRequired = _calculateETHRequiredForToken(_token);

if (msg.value < _ethRequired) {
Expand All @@ -161,7 +176,7 @@ contract RewardsNative is

function createMultipleTokensAndDepositRewards(
LibRewards.RewardToken[] calldata _tokens
) external payable onlyRole(DEV_CONFIG_ROLE) {
) external payable onlyRole(MANAGER_ROLE) {
uint256 totalETHRequired;

// Calculate the total ETH required for all tokens
Expand Down
14 changes: 11 additions & 3 deletions contracts/upgradeables/soulbounds/ERC1155RoyaltiesSoulboundV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,16 @@ contract ERC1155RoyaltiesSoulboundV2 is
address to,
uint256[] memory tokenIds,
uint256[] memory amounts,
bool soulbound
bool[] memory soulbounds
) external onlyRole(MINTER_ROLE) whenNotPaused {
if (tokenIds.length != amounts.length) {
revert("InvalidInput");
}

if (tokenIds.length != soulbounds.length) {
revert("InvalidInput");
}

for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 _id = tokenIds[i];
uint256 _amount = amounts[i];
Expand All @@ -394,12 +402,12 @@ contract ERC1155RoyaltiesSoulboundV2 is
revert("TokenMintPaused");
}

if (soulbound) {
if (soulbounds[i]) {
_soulbound(to, _id, _amount);
}

_mint(to, _id, _amount, "");
emit MintedId(to, _id, _amount, soulbound);
emit MintedId(to, _id, _amount, soulbounds[i]);
}
}

Expand Down
34 changes: 21 additions & 13 deletions test/hardhatTests/rewardsNative.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('RewardsNative', function () {

describe('Token Management', function () {
it('Should add a new token', async function () {
const { rewardsNative, devWallet } = await loadFixture(deployRewardsFixture);
const { rewardsNative, devWallet, managerWallet } = await loadFixture(deployRewardsFixture);
const rewardToken = {
tokenId: 1,
maxSupply: 100,
Expand All @@ -79,8 +79,9 @@ describe('RewardsNative', function () {
};

const rewardNativeWithDev = rewardsNative.connect(devWallet);
const rewardNativeWithManager = rewardsNative.connect(managerWallet);

const tx = await rewardNativeWithDev.createTokenAndDepositRewards(rewardToken, {
const tx = await rewardNativeWithManager.createTokenAndDepositRewards(rewardToken, {
value: ethers.parseEther('10'),
});

Expand All @@ -93,7 +94,7 @@ describe('RewardsNative', function () {
});

it('Should revert when adding a duplicate token', async function () {
const { rewardsNative, devWallet } = await loadFixture(deployRewardsFixture);
const { rewardsNative, devWallet, managerWallet } = await loadFixture(deployRewardsFixture);
const rewardToken = {
tokenId: 1,
maxSupply: 100,
Expand All @@ -102,20 +103,21 @@ describe('RewardsNative', function () {
};

await rewardsNative
.connect(devWallet)
.connect(managerWallet)
.createTokenAndDepositRewards(rewardToken, { value: ethers.parseEther('10') });

await expect(
rewardsNative
.connect(devWallet)
.connect(managerWallet)
.createTokenAndDepositRewards(rewardToken, { value: ethers.parseEther('10') })
).to.be.revertedWithCustomError(rewardsNative, 'DupTokenId');
});
});

describe('Minting', function () {
it('Should mint a token', async function () {
const { rewardsNative, minterWallet, user1, devWallet } = await loadFixture(deployRewardsFixture);
const { rewardsNative, minterWallet, user1, devWallet, managerWallet } =
await loadFixture(deployRewardsFixture);
const rewardToken = {
tokenId: 1,
maxSupply: 100,
Expand All @@ -125,8 +127,9 @@ describe('RewardsNative', function () {

const rewardNativeWithDev = rewardsNative.connect(devWallet);
const rewardNativeWithMinter = rewardsNative.connect(minterWallet);
const rewardNativeWithManager = rewardsNative.connect(managerWallet);

await rewardNativeWithDev.createTokenAndDepositRewards(rewardToken, { value: ethers.parseEther('10') });
await rewardNativeWithManager.createTokenAndDepositRewards(rewardToken, { value: ethers.parseEther('10') });

const data = ethers.AbiCoder.defaultAbiCoder().encode(
['address', 'uint256', 'uint256[]'],
Expand All @@ -139,7 +142,8 @@ describe('RewardsNative', function () {
});

it('Should revert when minting exceeds max supply', async function () {
const { rewardsNative, devWallet, minterWallet, user1 } = await loadFixture(deployRewardsFixture);
const { rewardsNative, devWallet, minterWallet, user1, managerWallet } =
await loadFixture(deployRewardsFixture);
const rewardToken = {
tokenId: 1,
maxSupply: 1,
Expand All @@ -149,8 +153,11 @@ describe('RewardsNative', function () {

const rewardNativeWithDev = rewardsNative.connect(devWallet);
const rewardNativeWithMinter = rewardsNative.connect(minterWallet);
const rewardNativeWithManager = rewardsNative.connect(managerWallet);

await rewardNativeWithDev.createTokenAndDepositRewards(rewardToken, { value: ethers.parseEther('0.1') });
await rewardNativeWithManager.createTokenAndDepositRewards(rewardToken, {
value: ethers.parseEther('0.1'),
});

const data = ethers.AbiCoder.defaultAbiCoder().encode(
['address', 'uint256', 'uint256[]'],
Expand Down Expand Up @@ -182,8 +189,9 @@ describe('RewardsNative', function () {
const rewardNativeWithDev = rewardsNative.connect(devWallet);
const rewardNativeWithMinter = rewardsNative.connect(minterWallet);
const rewardNativeWithUser1 = rewardsNative.connect(user1);
const rewardNativeWithManager = rewardsNative.connect(managerWallet);

await rewardNativeWithDev.createTokenAndDepositRewards(rewardToken, { value: rewardAmount });
await rewardNativeWithManager.createTokenAndDepositRewards(rewardToken, { value: rewardAmount });

const data = ethers.AbiCoder.defaultAbiCoder().encode(
['address', 'uint256', 'uint256[]'],
Expand Down Expand Up @@ -255,7 +263,7 @@ describe('RewardsNative', function () {
.createTokenAndDepositRewards(rewardToken, { value: ethers.parseEther('10') })
)
.to.be.revertedWithCustomError(rewardsNative, 'AccessControlUnauthorizedAccount')
.withArgs(user1.address, await rewardsNative.DEV_CONFIG_ROLE());
.withArgs(user1.address, await rewardsNative.MANAGER_ROLE());
});

it('Should allow only minter to mint new tokens', async function () {
Expand Down Expand Up @@ -324,7 +332,7 @@ describe('RewardsNative', function () {
const rewardNativeWithMinter = rewardsNative.connect(minterWallet);
const rewardNativeWithManager = rewardsNative.connect(managerWallet);

await rewardNativeWithDev.createTokenAndDepositRewards(rewardToken, { value: ethers.parseEther('10') });
await rewardNativeWithManager.createTokenAndDepositRewards(rewardToken, { value: ethers.parseEther('10') });
await rewardNativeWithManager.updateTokenMintPaused(rewardToken.tokenId, true);

const data = ethers.AbiCoder.defaultAbiCoder().encode(
Expand Down Expand Up @@ -354,7 +362,7 @@ describe('RewardsNative', function () {
const rewardNativeWithManager = rewardsNative.connect(managerWallet);
const rewardNativeWithUser1 = rewardsNative.connect(user1);

await rewardNativeWithDev.createTokenAndDepositRewards(rewardToken, { value: ethers.parseEther('10') });
await rewardNativeWithManager.createTokenAndDepositRewards(rewardToken, { value: ethers.parseEther('10') });

const data = ethers.AbiCoder.defaultAbiCoder().encode(
['address', 'uint256', 'uint256[]'],
Expand Down

0 comments on commit d8f2232

Please sign in to comment.