Skip to content

Commit

Permalink
Merge pull request #107 from morpho-org/post-cantina
Browse files Browse the repository at this point in the history
build(lib): remove solmate
  • Loading branch information
MerlinEgalite authored Dec 21, 2023
2 parents cc55aea + 5099d1c commit 8aaa009
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 45 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/transmissions11/solmate
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
Expand Down
1 change: 0 additions & 1 deletion lib/solmate
Submodule solmate deleted from e0e9ff
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"url": "https://github.com/morpho-org/universal-rewards-distributor/issues"
},
"scripts": {
"postinstall": "husky install && forge install",
"prepare": "husky install && forge install",
"build": "FOUNDRY_PROFILE=build forge build",
"test": "FOUNDRY_PROFILE=test forge test",
"lint": "forge fmt --check",
Expand Down
6 changes: 3 additions & 3 deletions src/UniversalRewardsDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {PendingRoot, IUniversalRewardsDistributorStaticTyping} from "./interface

import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {EventsLib} from "./libraries/EventsLib.sol";
import {SafeTransferLib, ERC20} from "../lib/solmate/src/utils/SafeTransferLib.sol";
import {SafeERC20, IERC20} from "../lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";

import {MerkleProof} from "../lib/openzeppelin-contracts/contracts/utils/cryptography/MerkleProof.sol";

Expand All @@ -16,7 +16,7 @@ import {MerkleProof} from "../lib/openzeppelin-contracts/contracts/utils/cryptog
/// permissionless Merkle trees. It is largely inspired by Morpho's current rewards distributor:
/// https://github.com/morpho-dao/morpho-v1/blob/main/src/common/rewards-distribution/RewardsDistributor.sol
contract UniversalRewardsDistributor is IUniversalRewardsDistributorStaticTyping {
using SafeTransferLib for ERC20;
using SafeERC20 for IERC20;

/* STORAGE */

Expand Down Expand Up @@ -130,7 +130,7 @@ contract UniversalRewardsDistributor is IUniversalRewardsDistributorStaticTyping

claimed[account][reward] = claimable;

ERC20(reward).safeTransfer(account, amount);
IERC20(reward).safeTransfer(account, amount);

emit EventsLib.Claimed(account, reward, amount);
}
Expand Down
7 changes: 1 addition & 6 deletions src/UrdFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ contract UrdFactory {
bytes32 initialIpfsHash,
bytes32 salt
) public returns (UniversalRewardsDistributor urd) {
urd = new UniversalRewardsDistributor{salt: salt}(
initialOwner,
initialTimelock,
initialRoot,
initialIpfsHash
);
urd = new UniversalRewardsDistributor{salt: salt}(initialOwner, initialTimelock, initialRoot, initialIpfsHash);

isUrd[address(urd)] = true;

Expand Down
43 changes: 12 additions & 31 deletions test/UniversalRewardsDistributorTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {PendingRoot, IUniversalRewardsDistributor} from "../src/interfaces/IUniv

import {ErrorsLib} from "../src/libraries/ErrorsLib.sol";

import {MockERC20} from "../lib/solmate/src/test/utils/mocks/MockERC20.sol";
import {ERC20Mock} from "../lib/openzeppelin-contracts/contracts/mocks/ERC20Mock.sol";
import {UniversalRewardsDistributor} from "../src/UniversalRewardsDistributor.sol";
import {EventsLib} from "../src/libraries/EventsLib.sol";

Expand All @@ -17,8 +17,8 @@ contract UniversalRewardsDistributorTest is Test {
bytes32 internal constant SALT = bytes32(0);

Merkle merkle = new Merkle();
MockERC20 internal token1;
MockERC20 internal token2;
ERC20Mock internal token1;
ERC20Mock internal token2;
IUniversalRewardsDistributor internal distributionWithoutTimeLock;
IUniversalRewardsDistributor internal distributionWithTimeLock;
address owner = _addrFromHashedString("Owner");
Expand All @@ -29,26 +29,17 @@ contract UniversalRewardsDistributorTest is Test {
uint256 DEFAULT_TIMELOCK = 1 days;

function setUp() public {
distributionWithoutTimeLock = IUniversalRewardsDistributor(
address(
new UniversalRewardsDistributor(
owner, 0, bytes32(0), bytes32(0)
)
)
);
token1 = new MockERC20("Token1", "TKN1", 18);
token2 = new MockERC20("Token2", "TKN2", 18);
distributionWithoutTimeLock =
IUniversalRewardsDistributor(address(new UniversalRewardsDistributor(owner, 0, bytes32(0), bytes32(0))));
token1 = new ERC20Mock();
token2 = new ERC20Mock();

vm.startPrank(owner);
distributionWithoutTimeLock.setRootUpdater(updater, true);

vm.warp(block.timestamp + 1);
distributionWithTimeLock = IUniversalRewardsDistributor(
address(
new UniversalRewardsDistributor(
owner, DEFAULT_TIMELOCK, bytes32(0), bytes32(0)
)
)
address(new UniversalRewardsDistributor(owner, DEFAULT_TIMELOCK, bytes32(0), bytes32(0)))
);
distributionWithTimeLock.setRootUpdater(updater, true);
vm.stopPrank();
Expand All @@ -65,11 +56,7 @@ contract UniversalRewardsDistributorTest is Test {
function testDistributionConstructor(address randomCreator) public {
vm.prank(randomCreator);
IUniversalRewardsDistributor distributor = IUniversalRewardsDistributor(
address(
new UniversalRewardsDistributor(
randomCreator, DEFAULT_TIMELOCK, DEFAULT_ROOT, DEFAULT_IPFS_HASH
)
)
address(new UniversalRewardsDistributor(randomCreator, DEFAULT_TIMELOCK, DEFAULT_ROOT, DEFAULT_IPFS_HASH))
);

PendingRoot memory pendingRoot = distributor.pendingRoot();
Expand All @@ -91,9 +78,7 @@ contract UniversalRewardsDistributorTest is Test {
vm.prank(randomCreator);
vm.expectEmit(address(urdAddress));
emit EventsLib.OwnerSet(randomCreator);
new UniversalRewardsDistributor{salt: SALT}(
randomCreator, DEFAULT_TIMELOCK, DEFAULT_ROOT, DEFAULT_IPFS_HASH
);
new UniversalRewardsDistributor{salt: SALT}(randomCreator, DEFAULT_TIMELOCK, DEFAULT_ROOT, DEFAULT_IPFS_HASH);
}

function testDistributionConstructorEmitsRootSet(bytes32 randomRoot, bytes32 randomIpfsHash) public {
Expand All @@ -106,9 +91,7 @@ contract UniversalRewardsDistributorTest is Test {
vm.prank(owner);
vm.expectEmit(address(urdAddress));
emit EventsLib.RootSet(randomRoot, randomIpfsHash);
new UniversalRewardsDistributor{salt: SALT}(
owner, DEFAULT_TIMELOCK, randomRoot, randomIpfsHash
);
new UniversalRewardsDistributor{salt: SALT}(owner, DEFAULT_TIMELOCK, randomRoot, randomIpfsHash);
}

function testDistributionConstructorEmitsTimelockSet(uint256 timelock) public {
Expand All @@ -120,9 +103,7 @@ contract UniversalRewardsDistributorTest is Test {
vm.prank(owner);
vm.expectEmit(address(urdAddress));
emit EventsLib.TimelockSet(timelock);
new UniversalRewardsDistributor{salt: SALT}(
owner, timelock, DEFAULT_ROOT, DEFAULT_IPFS_HASH
);
new UniversalRewardsDistributor{salt: SALT}(owner, timelock, DEFAULT_ROOT, DEFAULT_IPFS_HASH);
}

function testSubmitRootWithoutTimelockAsRandomCallerShouldRevert(address randomCaller) public {
Expand Down

0 comments on commit 8aaa009

Please sign in to comment.