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

Certora #9

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
Prev Previous commit
Next Next commit
refactor: reintroduce permissions
  • Loading branch information
sakulstra committed Sep 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit a59b175d57a3386af1e7a8fb01a0a1eaae83f24c
10 changes: 5 additions & 5 deletions src/periphery/contracts/static-a-token/StataTokenV2.sol
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import {ERC20Upgradeable, ERC20PermitUpgradeable} from 'openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/ERC20PermitUpgradeable.sol';
import {IERC20Metadata} from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol';
import {PausableUpgradeable} from 'openzeppelin-contracts-upgradeable/contracts/utils/PausableUpgradeable.sol';
import {IPermissionlessRescuable, PermissionlessRescuable} from 'solidity-utils/contracts/utils/PermissionlessRescuable.sol';
import {IRescuable, Rescuable} from 'solidity-utils/contracts/utils/Rescuable.sol';
import {IRescuableBase, RescuableBase} from 'solidity-utils/contracts/utils/RescuableBase.sol';
import {IERC20Permit} from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol';

@@ -24,7 +24,7 @@ contract StataTokenV2 is
ERC20AaveLMUpgradeable,
ERC4626StataTokenUpgradeable,
PausableUpgradeable,
PermissionlessRescuable,
Rescuable,
IStataTokenV2
{
using Math for uint256;
@@ -59,9 +59,9 @@ contract StataTokenV2 is
else _unpause();
}

/// @inheritdoc IPermissionlessRescuable
function whoShouldReceiveFunds() public view override returns (address) {
return IAToken(address(aToken())).RESERVE_TREASURY_ADDRESS();
/// @inheritdoc IRescuable
function whoCanRescue() public view override returns (address) {
return POOL_ADDRESSES_PROVIDER.getACLAdmin();
}

/// @inheritdoc IRescuableBase
25 changes: 21 additions & 4 deletions tests/periphery/static-a-token/StataTokenV2Rescuable.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.10;

import {IRescuable} from 'solidity-utils/contracts/utils/Rescuable.sol';
import {IAToken} from '../../../src/periphery/contracts/static-a-token/StataTokenV2.sol';
import {IERC20} from 'openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol';
import {BaseTest} from './TestBase.sol';

contract StataTokenV2RescuableTest is BaseTest {
@@ -12,14 +14,28 @@ contract StataTokenV2RescuableTest is BaseTest {
uint256 amount
);

function test_rescuable_shouldRevertForInvalidCaller() external {
deal(tokenList.usdx, address(stataTokenV2), 1 ether);
vm.expectRevert('ONLY_RESCUE_GUARDIAN');
IRescuable(address(stataTokenV2)).emergencyTokenTransfer(
tokenList.usdx,
address(this),
1 ether
);
}

function test_rescuable_shouldTransferAssetsToCollector() external {
deal(tokenList.usdx, address(stataTokenV2), 1 ether);
stataTokenV2.emergencyTokenTransfer(tokenList.usdx, 1 ether);
vm.startPrank(poolAdmin);
stataTokenV2.emergencyTokenTransfer(tokenList.usdx, address(this), 1 ether);
assertEq(IERC20(tokenList.usdx).balanceOf(address(this)), 1 ether);
}

function test_rescuable_shouldWorkForAToken() external {
_fundAToken(1 ether, address(stataTokenV2));
stataTokenV2.emergencyTokenTransfer(aToken, 1 ether);
vm.startPrank(poolAdmin);
stataTokenV2.emergencyTokenTransfer(aToken, address(this), 1 ether);
assertApproxEqAbs(IERC20(aToken).balanceOf(address(this)), 1 ether, 1);
}

function test_rescuable_shouldNotCauseInsolvency(uint256 donation, uint256 stake) external {
@@ -31,7 +47,8 @@ contract StataTokenV2RescuableTest is BaseTest {
address treasury = IAToken(aToken).RESERVE_TREASURY_ADDRESS();

vm.expectEmit(true, true, true, true);
emit ERC20Rescued(address(this), aToken, treasury, donation);
stataTokenV2.emergencyTokenTransfer(aToken, donation + stake);
emit ERC20Rescued(poolAdmin, aToken, address(this), donation);
vm.startPrank(poolAdmin);
stataTokenV2.emergencyTokenTransfer(aToken, address(this), donation + stake);
}
}