• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nayms / contracts-v3 / 13414110264

19 Feb 2025 01:47PM UTC coverage: 93.483% (-0.05%) from 93.534%
13414110264

push

github

amarinkovic
feat: just claim rebasing interest

286 of 363 branches covered (78.79%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

2 existing lines in 1 file now uncovered.

1421 of 1463 relevant lines covered (97.13%)

1219.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.96
/src/facets/TokenizedVaultFacet.sol
1
// SPDX-License-Identifier: MIT
2
pragma solidity 0.8.20;
3

4
import { Modifiers } from "../shared/Modifiers.sol";
5
import { LibConstants as LC } from "../libs/LibConstants.sol";
6
import { LibTokenizedVault } from "../libs/LibTokenizedVault.sol";
7
import { LibObject } from "../libs/LibObject.sol";
8
import { LibEntity } from "../libs/LibEntity.sol";
9
import { LibAdmin } from "../libs/LibAdmin.sol";
10
import { ReentrancyGuard } from "../utils/ReentrancyGuard.sol";
11

12
/**
13
 * @title Token Vault
14
 * @notice Vault for keeping track of platform tokens
15
 * @dev Used for internal platform token transfers
16
 * @dev Adaptation of ERC-1155 that uses AppStorage and aligns with Nayms ACL implementation.
17
 * https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/token/ERC1155
18
 */
19
contract TokenizedVaultFacet is Modifiers, ReentrancyGuard {
20
    /**
21
     * @notice Gets balance of an account within platform
22
     * @dev Internal balance for given account
23
     * @param ownerId Internal ID of the account
24
     * @param tokenId Internal ID of the asset
25
     * @return current balance
26
     */
27
    function internalBalanceOf(bytes32 ownerId, bytes32 tokenId) external view returns (uint256) {
28
        return LibTokenizedVault._internalBalanceOf(ownerId, tokenId);
4,981✔
29
    }
30

31
    /**
32
     * @notice Current supply for the asset
33
     * @dev Total supply of platform asset
34
     * @param tokenId Internal ID of the asset
35
     * @return total supply
36
     */
37
    function internalTokenSupply(bytes32 tokenId) external view returns (uint256) {
38
        return LibTokenizedVault._internalTokenSupply(tokenId);
1,062✔
39
    }
40

41
    /**
42
     * @notice Internal transfer of `amount` tokens from the entity associated with the sender
43
     * @dev Transfer tokens internally
44
     * @param to token receiver
45
     * @param tokenId Internal ID of the token
46
     * @param amount being transferred
47
     */
48
    function internalTransferFromEntity(
49
        bytes32 to,
50
        bytes32 tokenId,
51
        uint256 amount
52
    ) external notLocked nonReentrant assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_INTERNAL_TRANSFER_FROM_ENTITY) {
53
        bytes32 senderEntityId = LibObject._getParentFromAddress(msg.sender);
316✔
54
        LibTokenizedVault._internalTransfer(senderEntityId, to, tokenId, amount);
316✔
55
    }
56

57
    /**
58
     * @notice Internal transfer of `amount` tokens `from` -> `to`
59
     * @dev Transfer tokens internally between two IDs
60
     * @param from token sender
61
     * @param to token receiver
62
     * @param tokenId Internal ID of the token
63
     * @param amount being transferred
64
     */
65
    function wrapperInternalTransferFrom(bytes32 from, bytes32 to, bytes32 tokenId, uint256 amount) external notLocked nonReentrant assertERC20Wrapper(tokenId) {
66
        LibTokenizedVault._internalTransfer(from, to, tokenId, amount);
2✔
67
    }
68

69
    /**
70
     *
71
     * @param from @notice Internal burn of `amount` of `tokenId` tokens of `from` userId
72
     * @param tokenId tokenID to be burned internally
73
     * @param amount to be burned
74
     */
75
    function internalBurn(bytes32 from, bytes32 tokenId, uint256 amount) external notLocked assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_ADMINS) {
76
        LibTokenizedVault._internalBurn(from, tokenId, amount);
1✔
77
    }
78

79
    /**
80
     * @notice Get withdrawable dividend amount
81
     * @dev Dividend available for an entity to withdraw
82
     * @param ownerId Unique ID of the entity
83
     * @param tokenId Unique ID of token
84
     * @param dividendTokenId Unique ID of dividend token
85
     * @return _entityPayout accumulated dividend
86
     */
87
    function getWithdrawableDividend(bytes32 ownerId, bytes32 tokenId, bytes32 dividendTokenId) external view returns (uint256) {
88
        return LibTokenizedVault._getWithdrawableDividend(ownerId, tokenId, dividendTokenId);
1,049✔
89
    }
90

91
    /**
92
     * @notice Withdraw available dividend
93
     * @dev Transfer dividends to the entity
94
     * @param ownerId Unique ID of the dividend receiver
95
     * @param tokenId Unique ID of token
96
     * @param dividendTokenId Unique ID of dividend token
97
     */
98
    function withdrawDividend(bytes32 ownerId, bytes32 tokenId, bytes32 dividendTokenId) external notLocked {
99
        LibTokenizedVault._withdrawDividend(ownerId, tokenId, dividendTokenId);
259✔
100
    }
101

102
    /**
103
     * @notice Withdraws a user's available dividends.
104
     * @dev Dividends can be available in more than one dividend denomination. This method will withdraw all available dividends in the different dividend denominations.
105
     * @param ownerId Unique ID of the dividend receiver
106
     * @param tokenId Unique ID of token
107
     */
108
    function withdrawAllDividends(bytes32 ownerId, bytes32 tokenId) external notLocked {
109
        LibTokenizedVault._withdrawAllDividends(ownerId, tokenId);
2✔
110
    }
111

112
    /**
113
     * @notice Pay `amount` of dividends
114
     * @dev Transfer dividends to the entity
115
     * @param guid Globally unique identifier of a dividend distribution.
116
     * @param amount the amount of the dividend token to be distributed to NAYMS token holders.
117
     */
118
    function payDividendFromEntity(
119
        bytes32 guid,
120
        uint256 amount
121
    ) external notLocked assertPrivilege(LibObject._getParentFromAddress(msg.sender), LC.GROUP_PAY_DIVIDEND_FROM_ENTITY) {
122
        bytes32 entityId = LibObject._getParentFromAddress(msg.sender);
777✔
123
        bytes32 dividendTokenId = LibEntity._getEntityInfo(entityId).assetId;
777✔
124

125
        require(LibTokenizedVault._internalBalanceOf(entityId, dividendTokenId) >= amount, "payDividendFromEntity: insufficient balance");
777✔
126

127
        // note: The from and to are both entityId. In the case where a dividend is paid to an entity that was not tokenized to have participation tokens, the dividend payment
128
        // will go to the user's entity.
129
        LibTokenizedVault._payDividend(guid, entityId, entityId, dividendTokenId, amount);
776✔
130
    }
131

132
    /**
133
     * @notice Get the amount of tokens that an entity has for sale in the marketplace.
134
     * @param _entityId  Unique platform ID of the entity.
135
     * @param _tokenId The ID assigned to an external token.
136
     * @return amount of tokens that the entity has for sale in the marketplace.
137
     */
138
    function getLockedBalance(bytes32 _entityId, bytes32 _tokenId) external view returns (uint256 amount) {
139
        amount = LibTokenizedVault._getLockedBalance(_entityId, _tokenId);
37✔
140
    }
141

142
    /**
143
     * @notice Get the amount of tokens that an entity has available (deposited, but not locked)
144
     * @param _entityId  Unique platform ID of the entity.
145
     * @param _tokenId The ID assigned to an external token.
146
     * @return amount of tokens that the entity has available
147
     */
148
    function getAvailableBalance(bytes32 _entityId, bytes32 _tokenId) external view returns (uint256) {
149
        return LibTokenizedVault._getAvailableBalance(_entityId, _tokenId);
1✔
150
    }
151

152
    /**
153
     * @notice A system admin can transfer funds from an ID to another one.
154
     *
155
     * @param _fromId Unique platform ID to send the funds from.
156
     * @param _toId The ID to transfer funds to.
157
     * @param _tokenId The ID assigned to an external token.
158
     * @param _amount The amount of internal tokens to transfer.
159
     */
160
    function internalTransferBySystemAdmin(
161
        bytes32 _fromId,
162
        bytes32 _toId,
163
        bytes32 _tokenId,
164
        uint256 _amount
165
    ) external assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_ADMINS) {
UNCOV
166
        LibTokenizedVault._internalTransfer(_fromId, _toId, _tokenId, _amount);
×
167
    }
168

169
    /**
170
     * @notice Get the total amount of dividends paid to a cell.
171
     * @param _tokenId The entity ID of the cell. In otherwords, the participation token ID.
172
     * @param _dividendDenominationId The ID of the dividend token that the dividends were paid in.
173
     */
174
    function totalDividends(bytes32 _tokenId, bytes32 _dividendDenominationId) external view returns (uint256) {
UNCOV
175
        return LibTokenizedVault._totalDividends(_tokenId, _dividendDenominationId);
×
176
    }
177

178
    /**
179
     * @notice Get the unclaimed accrued rebasing interest
180
     * @param _tokenId Rebasing token ID
181
     */
182
    function accruedInterest(bytes32 _tokenId) external view returns (uint256) {
183
        return LibTokenizedVault._accruedInterest(_tokenId);
3✔
184
    }
185

186
    /**
187
     * @notice Distribute the accrued interest as dividends
188
     * @param _tokenId Rebasing token ID
189
     * @param _amount Amount to distribute
190
     * @param _guid The ID of the dividend token that the dividends were paid in.
191
     */
192
    function distributeAccruedInterest(bytes32 _tokenId, uint256 _amount, bytes32 _guid) external assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_MANAGERS) {
193
        // The _claimRebasingInterest method verifies the token is valid, and that there is available interest.
194
        // No need to do it again.
195
        LibTokenizedVault._claimRebasingInterest(_tokenId, _amount);
4✔
196
        LibTokenizedVault._payDividend(_guid, LibAdmin._getSystemId(), _tokenId, _tokenId, _amount);
2✔
197
    }
198

199
    function claimRebasingInterest(bytes32 _tokenId, uint256 _amount) external assertPrivilege(LibAdmin._getSystemId(), LC.GROUP_SYSTEM_MANAGERS) {
NEW
200
        LibTokenizedVault._claimRebasingInterest(_tokenId, _amount);
×
201
    }
202
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc