Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Mar 18, 2024
1 parent 8b95cf7 commit f8b4c0f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
49 changes: 48 additions & 1 deletion src/DebtVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ contract DebtVault is MetaTxModule, ReentrancyGuard, DebtVaultInvariantStorage,
constructor(
address forwarderIrrevocable
) MetaTxModule(forwarderIrrevocable) {

// Disable the possibility to initialize the implementation
_disableInitializers();
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/RuleEngineIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f8b4c0f

Please sign in to comment.