Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add requestDeposit router invariant #414

Open
wants to merge 2 commits into
base: router-invariants
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/recon-core/Properties.sol
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ abstract contract Properties is Setup, Asserts, ERC7540CentrifugeProperties {
== (
mintedByCurrencyPayout[address(token)] + sumOfDepositRequests[address(token)]
+ sumOfTransfersIn[address(token)] + sumOfExecutedLockedDepositRequests[address(token)]
+ sumOfDepositRequestsRouter[address(token)]
// Minus Claimed Redemptions and TransfersOut
- sumOfClaimedRedemptions[address(token)] - sumOfClaimedDepositCancelations[address(token)]
- sumOfTransfersOut[address(token)]
Expand Down
2 changes: 2 additions & 0 deletions test/recon-core/SharedStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,6 @@ abstract contract SharedStorage {
mapping(address => uint256) sumOfLockedDepositRequests;
mapping(address => uint256) sumOfUnlockedDepositRequests;
mapping(address => uint256) sumOfExecutedLockedDepositRequests;
// stores request data coming through the router
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is clear just from the name

Suggested change
// stores request data coming through the router

mapping(address => uint256) sumOfDepositRequestsRouter;
}
57 changes: 57 additions & 0 deletions test/recon-core/targets/RouterFunctions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,63 @@ abstract contract RouterFunctions is BaseTargetFunctions, Properties {
}
}

// === request Deposit === //
function router_requestDeposit(uint256 assets) public {
address owner = actor;
address controller = actor; // TODO: test with different address wen multi-actor supported

uint256 balanceOfEscrowB4 = token.balanceOf(address(escrow));
uint256 balanceOfRouterEscrowB4 = token.balanceOf(address(routerEscrow));
uint256 balanceOfOwnerB4 = token.balanceOf(owner);
assets = between(assets, 0, _getTokenAndBalanceForVault());

bool hasReverted;

token.approve(address(vault), assets); // owner = self -> allow to transfer tokens - need to test edge cacse
// without allowance

try router.requestDeposit(address(vault), assets, controller, owner, 0) {
// TODO: test topup
sumOfDepositRequestsRouter[address(token)] += assets;
requestDepositAssets[actor][address(token)] += assets;
} catch {
hasReverted = true;
}

if (!poolManager.isAllowedAsset(poolId, address(token))) {
// TODO: Ensure this works via actor switch
t(hasReverted, "Router-x Must Revert");
}

// If not member
(bool isMember,) = restrictionManager.isMember(address(trancheToken), controller);
if (!isMember) {
t(hasReverted, "LP-1 Must Revert");
}
if (restrictionManager.isFrozen(address(trancheToken), controller) == true) {
t(hasReverted, "LP-2 Must Revert");
}
if (!poolManager.isAllowedAsset(poolId, address(token))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a duplicate of Line:145

t(hasReverted, "LP-3 Must Revert");
}

// After Balances and Checks
uint256 balanceOfEscrowAfter = token.balanceOf(address(escrow));
uint256 balanceOfOwnerAfter = token.balanceOf(owner);
uint256 balanceOfRouterEscrowAfter = token.balanceOf(address(routerEscrow));

// NOTE: We only enforce the check if the tx didn't revert
if (!hasReverted) {
uint256 deltaEscrow = balanceOfEscrowAfter - balanceOfEscrowB4;
uint256 deltaOwner = balanceOfOwnerB4 - balanceOfOwnerAfter;
uint256 deltaRouterEscrow = balanceOfRouterEscrowB4 - balanceOfRouterEscrowAfter;

eq(deltaEscrow, assets, "Router-x");
eq(deltaOwner, assets, "Router-x");
eq(deltaRouterEscrow, 0, "Router-x");
}
}

// TODO: once we have multi actor support, include receiver != controller case
function router_claimDeposit(address sender) public {
// Bal b4
Expand Down
Loading