Skip to content

Commit

Permalink
Update lib, small improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed May 15, 2024
1 parent 1867176 commit c22d91d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/RuleEngine
Submodule RuleEngine added at a5516c
25 changes: 20 additions & 5 deletions src/public/IncomeVaultOpen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,35 @@ import "CMTAT/modules/wrapper/controllers/ValidationModule.sol";
* @title public function
*/
abstract contract IncomeVaultOpen is ReentrancyGuardUpgradeable, ValidationModule , IncomeVaultInternal {

enum TIME_ERROR_CODE {OK, CLAIM_NOT_ACTIVATED, TOO_LATE_TO_WITHDRAW, TOO_EARLY_TO_WITHDRAW}
/**
* @notice validate if a time is valid
*/
function validateTime(uint256 time) public view{
if(!segregatedClaim[time]){
revert IncomeVault_ClaimNotActivated();
TIME_ERROR_CODE code = validateTimeCode(time);
if(code == TIME_ERROR_CODE.OK){
return;
}else if(code == TIME_ERROR_CODE.CLAIM_NOT_ACTIVATED){
revert IncomeVault_ClaimNotActivated();
}
if(block.timestamp > timeLimitToWithdraw + time){
else if(code == TIME_ERROR_CODE.TOO_LATE_TO_WITHDRAW){
revert IncomeVault_TooLateToWithdraw(block.timestamp);
}else if (code == TIME_ERROR_CODE.TOO_EARLY_TO_WITHDRAW){
revert IncomeVault_TooEarlyToWithdraw(block.timestamp);
}
}

function validateTimeCode(uint256 time) public view returns(TIME_ERROR_CODE code){
if(!segregatedClaim[time]){
return TIME_ERROR_CODE.CLAIM_NOT_ACTIVATED;
}
if(block.timestamp > timeLimitToWithdraw + time){
return TIME_ERROR_CODE.TOO_LATE_TO_WITHDRAW;
}
if(block.timestamp < time){
revert IncomeVault_TooEarlyToWithdraw(block.timestamp);
return TIME_ERROR_CODE.TOO_EARLY_TO_WITHDRAW;
}
return TIME_ERROR_CODE.OK;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions test/RuleEngineIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ contract RuleEngineIntegration is RuleWhitelistInvariantStorage, Test, HelperCon
FLAG
);

// specific arrange
vm.prank(DEFAULT_ADMIN_ADDRESS);
ruleEngineMock = new RuleEngine(DEFAULT_ADMIN_ADDRESS, ZERO_ADDRESS);
vm.prank(DEFAULT_ADMIN_ADDRESS);
ruleEngineMock.addRuleValidation(ruleWhitelist);

// Token payment
tokenPayment = new CMTAT_STANDALONE(
ZERO_ADDRESS,
Expand All @@ -66,7 +60,7 @@ contract RuleEngineIntegration is RuleWhitelistInvariantStorage, Test, HelperCon
"CMTAT_info",
FLAG
);

// IncomeVault deployment
Options memory opts;
opts.constructorData = abi.encode(ZERO_ADDRESS);
address proxy = Upgrades.deployTransparentProxy(
Expand All @@ -82,6 +76,12 @@ contract RuleEngineIntegration is RuleWhitelistInvariantStorage, Test, HelperCon
);
debtVault = IncomeVault(proxy);

// specific arrange
vm.prank(DEFAULT_ADMIN_ADDRESS);
ruleEngineMock = new RuleEngine(DEFAULT_ADMIN_ADDRESS, ZERO_ADDRESS, address(proxy));
vm.prank(DEFAULT_ADMIN_ADDRESS);
ruleEngineMock.addRuleValidation(ruleWhitelist);

// We set the Rule Engine
vm.prank(DEFAULT_ADMIN_ADDRESS);
debtVault.setRuleEngine(ruleEngineMock);
Expand Down

0 comments on commit c22d91d

Please sign in to comment.