From 1fa9b612f2fe7836862088f06a213c4363fe9038 Mon Sep 17 00:00:00 2001 From: ilin Date: Fri, 20 Sep 2024 22:44:44 +0100 Subject: [PATCH 1/2] add requestDeposit router invariant --- test/recon-core/Properties.sol | 1 + test/recon-core/SharedStorage.sol | 2 + test/recon-core/targets/RouterFunctions.sol | 57 +++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/test/recon-core/Properties.sol b/test/recon-core/Properties.sol index 4014ba1d..dc9a463f 100644 --- a/test/recon-core/Properties.sol +++ b/test/recon-core/Properties.sol @@ -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)] diff --git a/test/recon-core/SharedStorage.sol b/test/recon-core/SharedStorage.sol index 0c979f17..a28afdb1 100644 --- a/test/recon-core/SharedStorage.sol +++ b/test/recon-core/SharedStorage.sol @@ -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 + mapping(address => uint256) sumOfDepositRequestsRouter; } diff --git a/test/recon-core/targets/RouterFunctions.sol b/test/recon-core/targets/RouterFunctions.sol index c3264e95..818015a3 100644 --- a/test/recon-core/targets/RouterFunctions.sol +++ b/test/recon-core/targets/RouterFunctions.sol @@ -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))) { + 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 From a2212cd5677be6cd0365e57946a383a87c9477bb Mon Sep 17 00:00:00 2001 From: John Doe Date: Thu, 3 Oct 2024 13:53:34 +0200 Subject: [PATCH 2/2] Gg/request redeem router target (#416) * Router request redeem target function implementation * Improve invariant expectation for tranche token * A new fix of the invariant --- test/recon-core/Properties.sol | 4 +-- test/recon-core/SharedStorage.sol | 1 + test/recon-core/targets/RouterFunctions.sol | 39 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/test/recon-core/Properties.sol b/test/recon-core/Properties.sol index dc9a463f..2116900a 100644 --- a/test/recon-core/Properties.sol +++ b/test/recon-core/Properties.sol @@ -302,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)] ); } } diff --git a/test/recon-core/SharedStorage.sol b/test/recon-core/SharedStorage.sol index a28afdb1..484dd790 100644 --- a/test/recon-core/SharedStorage.sol +++ b/test/recon-core/SharedStorage.sol @@ -186,4 +186,5 @@ abstract contract SharedStorage { mapping(address => uint256) sumOfExecutedLockedDepositRequests; // stores request data coming through the router mapping(address => uint256) sumOfDepositRequestsRouter; + mapping(address => uint256) sumOfRedeemRequestsRouter; } diff --git a/test/recon-core/targets/RouterFunctions.sol b/test/recon-core/targets/RouterFunctions.sol index 818015a3..f61541e1 100644 --- a/test/recon-core/targets/RouterFunctions.sol +++ b/test/recon-core/targets/RouterFunctions.sol @@ -176,6 +176,45 @@ abstract contract RouterFunctions is BaseTargetFunctions, Properties { } } + 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