diff --git a/src/DebtVault.sol b/src/DebtVault.sol index d1d305e..44c8ad5 100644 --- a/src/DebtVault.sol +++ b/src/DebtVault.sol @@ -34,7 +34,8 @@ contract DebtVault is MetaTxModule, ReentrancyGuard, DebtVaultInvariantStorage, constructor( address forwarderIrrevocable ) MetaTxModule(forwarderIrrevocable) { - + // Disable the possibility to initialize the implementation + _disableInitializers(); } /** @@ -94,6 +95,10 @@ contract DebtVault is MetaTxModule, ReentrancyGuard, DebtVaultInvariantStorage, __ValidationModule_init_unchained(); } + function _claimDividend(uint256 time){ + + } + /** * @notice claim your payment * @param time provide the date where you want to receive your payment @@ -136,6 +141,48 @@ contract DebtVault is MetaTxModule, ReentrancyGuard, DebtVaultInvariantStorage, _transferDividend(time, sender, senderDividend); } + /** + * @notice claim your payment + * @param time provide the date where you want to receive your payment + */ + function claimDividendBatch(uint256 time) public nonReentrant() { + // Check if the claim is activated + if(!segragatedClaim[time]){ + revert claimNotActivated(); + } + address sender = _msgSender(); + // At the beginning since no external call to do + if (claimedDividend[sender][time]){ + revert dividendAlreadyClaimed(); + } + // External call to the CMTAT to retrieve the total supply and the sender balance + (uint256 senderBalance, uint256 TokenTotalSupply) = CMTAT_TOKEN.snapshotInfo(time, sender); + if (senderBalance == 0){ + revert noDividendToClaim(); + } + /** + SenderBalance = 300 + totalSupply = 900 + Dividend total supply= 200 + If POINTS_MULTIPLIER = 100, then + 300 * 100 / 900 = 30000 / 900 = 33 (33.333333333) + dividend = 200 * 33 / 100 = 66 + Other formule + dividend = (300 * 200) / 900 = 60000 / 900 = 600/9 = 66.6 = 66 + */ + //uint256 partShare = (senderBalance * POINTS_MULTIPLIER) / TokenTotalSupply; + //uint256 dividendTotalSupply = segragatedDividend[time]; + //uint256 dividend = (dividendTotalSupply * partShare) / POINTS_MULTIPLIER; + + uint256 senderDividend = _computeDividend(time, senderBalance, TokenTotalSupply); + + // Transfer restriction + if (!ValidationModule._operateOnTransfer(address(this), sender, senderDividend)) { + revert Errors.CMTAT_InvalidTransfer(address(this), sender, senderDividend); + } + _transferDividend(time, sender, senderDividend); + } + /** * @notice deposit an amount to pay the dividends. * @param time provide the date where you want to perform a deposit diff --git a/test/RuleEngineIntegration.t.sol b/test/RuleEngineIntegration.t.sol index 579ad66..bc8901c 100644 --- a/test/RuleEngineIntegration.t.sol +++ b/test/RuleEngineIntegration.t.sol @@ -24,7 +24,7 @@ contract RuleEngineIntegration is RuleWhitelistInvariantStorage, Test, HelperCon uint256 ADDRESS2_BALANCE_INIT = 32; uint256 ADDRESS3_BALANCE_INIT = 33; - uint256 tokenBalance = 5000; + uint256 tokenBalance = 5000; // Arrange function setUp() public { vm.prank(DEFAULT_ADMIN_ADDRESS);