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 all commits
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
5 changes: 3 additions & 2 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 Expand Up @@ -301,8 +302,8 @@ abstract contract Properties is Setup, Asserts, ERC7540CentrifugeProperties {
return trancheToken.balanceOf(address(escrow))
== (
sumOfFullfilledDeposits[address(trancheToken)] + sumOfRedeemRequests[address(trancheToken)]
- sumOfClaimedDeposits[address(trancheToken)] - sumOfClaimedRedeemCancelations[address(trancheToken)]
- sumOfClaimedRequests[address(trancheToken)]
+ sumOfRedeemRequestsRouter[address(trancheToken)] - sumOfClaimedDeposits[address(trancheToken)]
- sumOfClaimedRedeemCancelations[address(trancheToken)] - sumOfClaimedRequests[address(trancheToken)]
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/recon-core/SharedStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,7 @@ 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;
mapping(address => uint256) sumOfRedeemRequestsRouter;
}
96 changes: 96 additions & 0 deletions test/recon-core/targets/RouterFunctions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,102 @@ 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");
}
}

function router_requestRedeem(uint256 shares) public {
address owner = actor;
address controller = actor;

uint256 balanceOfEscrowB4 = trancheToken.balanceOf(address(escrow));
uint256 balanceOfRouterEscrowB4 = trancheToken.balanceOf(address(routerEscrow));
uint256 balanceOfOwnerB4 = trancheToken.balanceOf(owner);
shares = between(shares, 0, balanceOfOwnerB4);

bool hasReverted;

trancheToken.approve(address(vault), shares);

try router.requestRedeem(address(vault), shares, controller, owner, 0) {
sumOfRedeemRequestsRouter[address(trancheToken)] += shares;
requestRedeemShares[actor][address(trancheToken)] += shares;
} catch {
hasReverted = true;
}
if (restrictionManager.isFrozen(address(trancheToken), controller)) {
t(hasReverted, "Router-Redeem-Frozen Must Revert");
}
// After Balances and Checks
uint256 balanceOfEscrowAfter = trancheToken.balanceOf(address(escrow));
uint256 balanceOfOwnerAfter = trancheToken.balanceOf(owner);
uint256 balanceOfRouterEscrowAfter = trancheToken.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, shares, "Router-x");
eq(deltaOwner, shares, "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