Skip to content

Commit

Permalink
fix: only entity admin can pay dividend
Browse files Browse the repository at this point in the history
  • Loading branch information
amarinkovic committed Dec 12, 2022
1 parent 84c260c commit 2e34d37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/diamonds/nayms/facets/TokenizedVaultFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ contract TokenizedVaultFacet is Modifiers {
* @param amount the mamount of the dividend token to be distributed to NAYMS token holders.
*/
function payDividendFromEntity(bytes32 guid, uint256 amount) external {
bytes32 senderId = LibHelpers._getIdForAddress(msg.sender);
bytes32 entityId = LibObject._getParent(senderId);
bytes32 entityId = LibObject._getParentFromAddress(msg.sender);
bytes32 dividendTokenId = LibEntity._getEntityInfo(entityId).assetId;

require(LibACL._isInGroup(LibHelpers._getIdForAddress(msg.sender), entityId, LibHelpers._stringToBytes32(LibConstants.GROUP_ENTITY_ADMINS)), "not the entity's admin");
require(LibTokenizedVault._internalBalanceOf(entityId, dividendTokenId) >= amount, "payDividendFromEntity: insufficient balance");

LibTokenizedVault._payDividend(guid, entityId, entityId, dividendTokenId, amount);
Expand Down
18 changes: 17 additions & 1 deletion test/T03TokenizedVault.t.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.13;

import { MockAccounts } from "./utils/users/MockAccounts.sol";
import { D03ProtocolDefaults, console2, LibAdmin, LibConstants, LibHelpers, LibObject } from "./defaults/D03ProtocolDefaults.sol";
import { AppStorage, Entity, FeeRatio, MarketInfo, TradingCommissions, TradingCommissionsBasisPoints } from "src/diamonds/nayms/AppStorage.sol";
import { LibFeeRouter } from "src/diamonds/nayms/libs/LibFeeRouter.sol";
import { IDiamondCut } from "src/diamonds/nayms/INayms.sol";
import { TradingCommissionsFixture, TradingCommissionsConfig } from "test/fixtures/TradingCommissionsFixture.sol";
import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol";

contract T03TokenizedVaultTest is D03ProtocolDefaults {
contract T03TokenizedVaultTest is D03ProtocolDefaults, MockAccounts {
using FixedPointMathLib for uint256;

bytes32 internal nWETH;
Expand Down Expand Up @@ -239,6 +240,21 @@ contract T03TokenizedVaultTest is D03ProtocolDefaults {
assertEq(nayms.internalTokenSupply(nWETH), naymsWethInternalTokenSupply - 100, "nayms burned internal WETH");
}

function testOnlyEntityAdminCanPayDividend() public {
bytes32 acc0EntityId = nayms.getEntity(account0Id);
nayms.enableEntityTokenization(acc0EntityId, "E1");
nayms.startTokenSale(acc0EntityId, 1 ether, 1 ether);

bytes32 acc9Id = LibHelpers._addressToBytes32(account9);
nayms.setEntity(acc9Id, acc0EntityId);

writeTokenBalance(account0, naymsAddress, wethAddress, depositAmount);
nayms.externalDeposit(wethAddress, 1 ether);
vm.prank(account9);
vm.expectRevert("not the entity's admin");
nayms.payDividendFromEntity(bytes32("0x1"), 1 ether);
}

function testPayDividendsWithZeroParticipationTokenSupply() public {
bytes32 acc0EntityId = nayms.getEntity(account0Id);

Expand Down

0 comments on commit 2e34d37

Please sign in to comment.