Skip to content

Commit

Permalink
Merge pull request #37 from nayms/restrict_deposits_to_entities
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-fruitful authored Nov 21, 2022
2 parents 0ae7def + 6749c0a commit df3dfb0
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 192 deletions.
19 changes: 1 addition & 18 deletions src/diamonds/nayms/facets/TokenizedVaultFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract TokenizedVaultFacet is Modifiers {
* @param to token receiver
* @param tokenId Internal ID of the token
*/
function internalTransferFromEntity(
function internalTransfer(
bytes32 to,
bytes32 tokenId,
uint256 amount
Expand All @@ -55,23 +55,6 @@ contract TokenizedVaultFacet is Modifiers {
LibTokenizedVault._internalTransfer(senderEntityId, to, tokenId, amount);
}

/**
* @notice Internal transfer of `amount` tokens
* @dev Transfer tokens internally
* @param to token receiver
* @param tokenId Internal ID of the token
*/
function internalTransfer(
bytes32 to,
bytes32 tokenId,
uint256 amount
) external assertEntityAdmin(LibObject._getParent(LibHelpers._getSenderId())) {
// require(LibTokenizedVault._internalBalanceOf(senderId, tokenId) >= amount, "internalTransfer: insufficient balance");
bytes32 senderId = LibHelpers._getIdForAddress(msg.sender);
require(LibHelpers._stringToBytes32(LibConstants.STM_IDENTIFIER) != tokenId, "internalTransfer: can't transfer internal veNAYM");
LibTokenizedVault._internalTransfer(senderId, to, tokenId, amount);
}

function internalBurn(
bytes32 from,
bytes32 tokenId,
Expand Down
38 changes: 8 additions & 30 deletions src/diamonds/nayms/facets/TokenizedVaultIOFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LibTokenizedVault } from "../libs/LibTokenizedVault.sol";
import { LibTokenizedVaultIO } from "../libs/LibTokenizedVaultIO.sol";
import { LibEntity } from "../libs/LibEntity.sol";
import { LibAdmin } from "../libs/LibAdmin.sol";
import { LibObject } from "../libs/LibObject.sol";

/**
* @title Token Vault IO
Expand All @@ -16,42 +17,19 @@ import { LibAdmin } from "../libs/LibAdmin.sol";
*/
contract TokenizedVaultIOFacet is Modifiers {
/**
* @notice Deposit funds into Nayms platform entity
* @dev Deposit from an external account
* @param _receiverId Internal ID of the account receiving the deposited funds
* @notice Deposit funds into msg.sender's Nayms platform entity
* @dev Deposit from msg.sender to their associated entity
* @param _externalTokenAddress Token address
* @param _amount deposit amount
*/
function externalDepositToEntity(
bytes32 _receiverId,
address _externalTokenAddress,
uint256 _amount
) external {
// a user can only deposit an approved external ERC20 token
require(LibAdmin._isSupportedExternalTokenAddress(_externalTokenAddress), "extDeposit: invalid ERC20 token");

// a user can only deposit to a valid entity
require(LibEntity._isEntity(_receiverId), "extDeposit: invalid receiver");

LibTokenizedVaultIO._externalDeposit(_receiverId, _externalTokenAddress, _amount);
}

/**
* @notice Deposit funds into Nayms platform
* @dev Deposit from an external account
* @param _receiverId Internal ID of the account receiving the deposited funds
* @param _externalTokenAddress Token address
* @param _amount deposit amount
*/
function externalDeposit(
bytes32 _receiverId,
address _externalTokenAddress,
uint256 _amount
) external {
function externalDeposit(address _externalTokenAddress, uint256 _amount) external {
// a user can only deposit an approved external ERC20 token
require(LibAdmin._isSupportedExternalTokenAddress(_externalTokenAddress), "extDeposit: invalid ERC20 token");
// a user can only deposit to their valid entity
bytes32 entityId = LibObject._getParentFromAddress(msg.sender);
require(LibEntity._isEntity(entityId), "extDeposit: invalid receiver");

LibTokenizedVaultIO._externalDeposit(_receiverId, _externalTokenAddress, _amount);
LibTokenizedVaultIO._externalDeposit(entityId, _externalTokenAddress, _amount);
}

/**
Expand Down
12 changes: 0 additions & 12 deletions src/diamonds/nayms/interfaces/ITokenizedVaultFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ interface ITokenizedVaultFacet {
*/
function internalTokenSupply(bytes32 tokenId) external view returns (uint256);

/**
* @notice Internal transfer of `amount` tokens
* @dev Transfer tokens internally
* @param to token receiver
* @param tokenId Internal ID of the token
*/
function internalTransferFromEntity(
bytes32 to,
bytes32 tokenId,
uint256 amount
) external;

/**
* @notice Internal transfer of `amount` tokens
* @dev Transfer tokens internally
Expand Down
24 changes: 3 additions & 21 deletions src/diamonds/nayms/interfaces/ITokenizedVaultIOFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,12 @@ pragma solidity >=0.8.13;
*/
interface ITokenizedVaultIOFacet {
/**
* @notice Deposit funds into Nayms platform entity
* @dev Deposit from an external account
* @param _receiverId Internal ID of the account receiving the deposited funds
* @notice Deposit funds into msg.sender's Nayms platform entity
* @dev Deposit from msg.sender to their associated entity
* @param _externalTokenAddress Token address
* @param _amount deposit amount
*/
function externalDepositToEntity(
bytes32 _receiverId,
address _externalTokenAddress,
uint256 _amount
) external;

/**
* @notice Deposit funds into Nayms platform
* @dev Deposit from an external account
* @param _receiverId Internal ID of the account receiving the deposited funds
* @param _externalTokenAddress Token address
* @param _amount deposit amount
*/
function externalDeposit(
bytes32 _receiverId,
address _externalTokenAddress,
uint256 _amount
) external;
function externalDeposit(address _externalTokenAddress, uint256 _amount) external;

/**
* @notice Withdraw funds out of Nayms platform
Expand Down
Loading

0 comments on commit df3dfb0

Please sign in to comment.