Skip to content

Commit

Permalink
chore: Update submodules (SC-5140) (#36)
Browse files Browse the repository at this point in the history
* chore: update submodules

* fix: update erc20 permit references and tests

* chore: update submodules

* fix: address PR comments
  • Loading branch information
vbidin authored Mar 15, 2022
1 parent d45de5e commit cc9fcb8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 33 deletions.
14 changes: 7 additions & 7 deletions contracts/RevenueDistributionToken.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.7;

import { ERC20Permit } from "../modules/erc20/contracts/ERC20Permit.sol";
import { ERC20 } from "../modules/erc20/contracts/ERC20.sol";
import { ERC20Helper } from "../modules/erc20-helper/src/ERC20Helper.sol";

import { IRevenueDistributionToken } from "./interfaces/IRevenueDistributionToken.sol";

contract RevenueDistributionToken is IRevenueDistributionToken, ERC20Permit {
contract RevenueDistributionToken is IRevenueDistributionToken, ERC20 {

uint256 public immutable override precision; // Precision of rates, equals max deposit amounts before rounding errors occur

Expand Down Expand Up @@ -37,11 +37,11 @@ contract RevenueDistributionToken is IRevenueDistributionToken, ERC20Permit {
}

constructor(string memory name_, string memory symbol_, address owner_, address asset_, uint256 precision_)
ERC20Permit(name_, symbol_, ERC20Permit(asset_).decimals())
ERC20(name_, symbol_, ERC20(asset_).decimals())
{
require((owner = owner_) != address(0), "RDT:C:OWNER_ZERO_ADDRESS");

asset = asset_; // Don't need to check zero address as ERC20Permit(asset_).decimals() will fail in ERC20Permit constructor.
asset = asset_; // Don't need to check zero address as ERC20(asset_).decimals() will fail in ERC20 constructor.
precision = precision_;
}

Expand Down Expand Up @@ -74,7 +74,7 @@ contract RevenueDistributionToken is IRevenueDistributionToken, ERC20Permit {
freeAssets = freeAssets_ = totalAssets();

// Calculate slope, update timestamp and period finish.
issuanceRate = issuanceRate_ = (ERC20Permit(asset).balanceOf(address(this)) - freeAssets_) * precision / vestingPeriod_;
issuanceRate = issuanceRate_ = (ERC20(asset).balanceOf(address(this)) - freeAssets_) * precision / vestingPeriod_;
vestingPeriodFinish = (lastUpdated = block.timestamp) + vestingPeriod_;

emit VestingScheduleUpdated(msg.sender, vestingPeriodFinish, issuanceRate);
Expand All @@ -98,7 +98,7 @@ contract RevenueDistributionToken is IRevenueDistributionToken, ERC20Permit {
)
external virtual override nonReentrant returns (uint256 shares_)
{
ERC20Permit(asset).permit(msg.sender, address(this), assets_, deadline_, v_, r_, s_);
ERC20(asset).permit(msg.sender, address(this), assets_, deadline_, v_, r_, s_);
_mint(shares_ = previewDeposit(assets_), assets_, receiver_, msg.sender);
}

Expand All @@ -119,7 +119,7 @@ contract RevenueDistributionToken is IRevenueDistributionToken, ERC20Permit {
{
require((assets_ = previewMint(shares_)) <= maxAssets_, "RDT:MWP:INSUFFICIENT_PERMIT");

ERC20Permit(asset).permit(msg.sender, address(this), maxAssets_, deadline_, v_, r_, s_);
ERC20(asset).permit(msg.sender, address(this), maxAssets_, deadline_, v_, r_, s_);
_mint(shares_, assets_, receiver_, msg.sender);
}

Expand Down
5 changes: 3 additions & 2 deletions contracts/interfaces/IRevenueDistributionToken.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.7;

import { IERC20 } from "../../modules/erc20/contracts/interfaces/IERC20.sol";

import { IERC4626 } from "./IERC4626.sol";
import { IERC20Permit } from "../../modules/erc20/contracts/interfaces/IERC20Permit.sol";

/// @title A token that represents ownership of future revenues distributed linearly over time.
interface IRevenueDistributionToken is IERC4626, IERC20Permit {
interface IRevenueDistributionToken is IERC20, IERC4626 {

/**************/
/*** Events ***/
Expand Down
12 changes: 6 additions & 6 deletions contracts/test/ERC20.t.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.7;

import { ERC20Permit } from "../../modules/erc20/contracts/ERC20Permit.sol";
import { ERC20PermitUser } from "../../modules/erc20/contracts/test/accounts/ERC20User.sol";
import { ERC20Test } from "../../modules/erc20/contracts/test/ERC20.t.sol";
import { ERC20PermitTest } from "../../modules/erc20/contracts/test/ERC20Permit.t.sol";
import { ERC20 } from "../../modules/erc20/contracts/ERC20.sol";
import { ERC20User } from "../../modules/erc20/contracts/test/accounts/ERC20User.sol";
import { ERC20BaseTest } from "../../modules/erc20/contracts/test/ERC20.t.sol";
import { ERC20PermitTest } from "../../modules/erc20/contracts/test/ERC20.t.sol";
import { MockERC20 } from "../../modules/erc20/contracts/test/mocks/MockERC20.sol";

import { RevenueDistributionToken as RDT } from "../RevenueDistributionToken.sol";

import { MockERC20_RDT } from "./mocks/MockERC20.RDT.sol"; // Required for mint/burn tests

contract RDT_ERC20Test is ERC20Test {
contract RDT_ERC20Test is ERC20BaseTest {

function setUp() override public {
address asset = address(new MockERC20("MockToken", "MT", 18));
Expand All @@ -25,7 +25,7 @@ contract RDT_ERC20PermitTest is ERC20PermitTest {
function setUp() override public {
super.setUp();
address asset = address(new MockERC20("MockToken", "MT", 18));
token = ERC20Permit(address(new RDT("Token", "TKN", address(this), asset, 1e30)));
token = ERC20(address(new RDT("Token", "TKN", address(this), asset, 1e30)));
}

function test_domainSeparator() external override {
Expand Down
28 changes: 14 additions & 14 deletions contracts/test/RevenueDistributionToken.t.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.7;

import { TestUtils } from "../../modules/contract-test-utils/contracts/test.sol";
import { MockERC20, MockERC20Permit } from "../../modules/erc20/contracts/test/mocks/MockERC20.sol";
import { TestUtils } from "../../modules/contract-test-utils/contracts/test.sol";
import { MockERC20 } from "../../modules/erc20/contracts/test/mocks/MockERC20.sol";

import { MockRevertingERC20 } from "./mocks/MockRevertingERC20.sol";

Expand All @@ -14,7 +14,7 @@ import { RevenueDistributionToken as RDT } from "../RevenueDistributionToken.sol
contract ConstructorTest is TestUtils {

function test_constructor_ownerZeroAddress() external {
MockERC20Permit asset = new MockERC20Permit("MockToken", "MT", 18);
MockERC20 asset = new MockERC20("MockToken", "MT", 18);

vm.expectRevert("RDT:C:OWNER_ZERO_ADDRESS");
RDT rdToken = new RDT("Revenue Distribution Token", "RDT", address(0), address(asset), 1e30);
Expand All @@ -26,8 +26,8 @@ contract ConstructorTest is TestUtils {

contract DepositAndMintWithPermitTest is TestUtils {

MockERC20Permit asset;
RDT rdToken;
MockERC20 asset;
RDT rdToken;

uint256 stakerPrivateKey = 1;
uint256 notStakerPrivateKey = 2;
Expand All @@ -41,7 +41,7 @@ contract DepositAndMintWithPermitTest is TestUtils {
address notStaker;

function setUp() public virtual {
asset = new MockERC20Permit("MockToken", "MT", 18);
asset = new MockERC20("MockToken", "MT", 18);
rdToken = new RDT("Revenue Distribution Token", "RDT", address(this), address(asset), 1e30);

staker = vm.addr(stakerPrivateKey);
Expand All @@ -58,7 +58,7 @@ contract DepositAndMintWithPermitTest is TestUtils {

vm.startPrank(staker);

vm.expectRevert(bytes("ERC20Permit:INVALID_SIGNATURE"));
vm.expectRevert(bytes("ERC20:P:MALLEABLE"));
rdToken.depositWithPermit(depositAmount, staker, deadline, 17, r, s);

rdToken.depositWithPermit(depositAmount, staker, deadline, v, r, s);
Expand All @@ -72,7 +72,7 @@ contract DepositAndMintWithPermitTest is TestUtils {

vm.startPrank(staker);

vm.expectRevert(bytes("ERC20Permit:INVALID_SIGNATURE"));
vm.expectRevert(bytes("ERC20:P:INVALID_SIGNATURE"));
rdToken.depositWithPermit(depositAmount, staker, deadline, v, r, s);

( v, r, s ) = _getValidPermitSignature(depositAmount, staker, address(rdToken), stakerPrivateKey, deadline);
Expand All @@ -91,7 +91,7 @@ contract DepositAndMintWithPermitTest is TestUtils {

vm.warp(deadline + 1);

vm.expectRevert(bytes("ERC20Permit:EXPIRED"));
vm.expectRevert(bytes("ERC20:P:EXPIRED"));
rdToken.depositWithPermit(depositAmount, staker, deadline, v, r, s);

vm.warp(deadline);
Expand All @@ -109,7 +109,7 @@ contract DepositAndMintWithPermitTest is TestUtils {

rdToken.depositWithPermit(depositAmount, staker, deadline, v, r, s);

vm.expectRevert(bytes("ERC20Permit:INVALID_SIGNATURE"));
vm.expectRevert(bytes("ERC20:P:INVALID_SIGNATURE"));
rdToken.depositWithPermit(depositAmount, staker, deadline, v, r, s);
}

Expand Down Expand Up @@ -165,7 +165,7 @@ contract DepositAndMintWithPermitTest is TestUtils {

vm.startPrank(staker);

vm.expectRevert(bytes("ERC20Permit:INVALID_SIGNATURE"));
vm.expectRevert(bytes("ERC20:P:MALLEABLE"));
rdToken.mintWithPermit(mintAmount, staker, maxAssets, deadline, 17, r, s);

rdToken.mintWithPermit(mintAmount, staker, maxAssets, deadline, v, r, s);
Expand All @@ -181,7 +181,7 @@ contract DepositAndMintWithPermitTest is TestUtils {

vm.startPrank(staker);

vm.expectRevert(bytes("ERC20Permit:INVALID_SIGNATURE"));
vm.expectRevert(bytes("ERC20:P:INVALID_SIGNATURE"));
rdToken.mintWithPermit(mintAmount, staker, maxAssets, deadline, v, r, s);

( v, r, s ) = _getValidPermitSignature(maxAssets, staker, address(rdToken), stakerPrivateKey, deadline);
Expand All @@ -202,7 +202,7 @@ contract DepositAndMintWithPermitTest is TestUtils {

vm.warp(deadline + 1);

vm.expectRevert(bytes("ERC20Permit:EXPIRED"));
vm.expectRevert(bytes("ERC20:P:EXPIRED"));
rdToken.mintWithPermit(mintAmount, staker, maxAssets, deadline, v, r, s);

vm.warp(deadline);
Expand Down Expand Up @@ -240,7 +240,7 @@ contract DepositAndMintWithPermitTest is TestUtils {

rdToken.mintWithPermit(mintAmount, staker, maxAssets, deadline, v, r, s);

vm.expectRevert(bytes("ERC20Permit:INVALID_SIGNATURE"));
vm.expectRevert(bytes("ERC20:P:INVALID_SIGNATURE"));
rdToken.mintWithPermit(mintAmount, staker, maxAssets, deadline, v, r, s);
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/test/accounts/Staker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ pragma solidity ^0.8.7;

import { TestUtils } from "../../../modules/contract-test-utils/contracts/test.sol";

import { ERC20PermitUser } from "../../../modules/erc20/contracts/test/accounts/ERC20User.sol";
import { ERC20User } from "../../../modules/erc20/contracts/test/accounts/ERC20User.sol";
import { MockERC20 } from "../../../modules/erc20/contracts/test/mocks/MockERC20.sol";

import { IRevenueDistributionToken as IRDT } from "../../interfaces/IRevenueDistributionToken.sol";

contract Staker is ERC20PermitUser {
contract Staker is ERC20User {

function rdToken_deposit(address token_, uint256 assets_) external returns (uint256 shares_) {
shares_ = IRDT(token_).deposit(assets_, address(this));
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ solc_version = '0.8.7' # Override for the solc version (setting this ignores `
offline = true # Disable downloading of missing solc version(s)
optimizer = true # Enable or disable the solc optimizer
optimizer_runs = 200 # The number of optimizer runs
verbosity = 2 # The verbosity of tests
verbosity = 3 # The verbosity of tests

[local]
fuzz_runs = 100
Expand Down

0 comments on commit cc9fcb8

Please sign in to comment.