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

Mint rewards deploy #189

Open
wants to merge 3 commits into
base: dev
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
28 changes: 28 additions & 0 deletions script/DeploySplitFees.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pragma solidity ^0.8.20;

import {Script} from "forge-std/Script.sol";
import "lib/forge-std/src/console.sol";

import {SplitFeesCore} from "src/core/SplitFeesCore.sol";
import {SplitFeesModule} from "src/module/SplitFeesModule.sol";

contract DeploySplitFeesScript is Script {

function run() external {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
address deployerAddress = vm.addr(deployerPrivateKey);
vm.startBroadcast(deployerPrivateKey);
address[] memory modules = new address[](1);
bytes[] memory moduleData = new bytes[](1);
modules[0] = address(new SplitFeesModule());
moduleData[0] = "";

SplitFeesCore splitFeesCore = new SplitFeesCore(deployerAddress, modules, moduleData);

console.log("SplitFeesCore deployed: ", address(splitFeesCore));
console.log("Split Wallet implementation: ", splitFeesCore.splitWalletImplementation());

vm.stopBroadcast();
}

}
34 changes: 34 additions & 0 deletions script/mint-rewards/DeployMintRewards.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pragma solidity ^0.8.20;

import {Script} from "forge-std/Script.sol";
import "lib/forge-std/src/console.sol";
import {SplitFeesCore} from "src/core/SplitFeesCore.sol";

import {SplitWallet} from "src/core/SplitWallet.sol";
import {SplitFeesModule} from "src/module/SplitFeesModule.sol";

contract DeployTWCloneFactoryScript is Script {

address createX = 0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed;
SplitFeesCore splitCore;
SplitFeesModule splitModule;

function run() external {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
address deployerAddress = vm.addr(deployerPrivateKey);
vm.startBroadcast(deployerPrivateKey);

bytes32 salt = keccak256(abi.encode("thirdweb-1"));

splitCore = new SplitFeesCore{salt: salt}(deployerAddress, new address[](0), new bytes[](0));
splitModule = new SplitFeesModule();
console.log("split core deployed: ", address(splitCore));
console.log("split module deployed: ", address(splitModule));

splitCore.installModule(address(splitModule), new bytes(0));
console.log("split module installed");

vm.stopBroadcast();
}

}
2 changes: 2 additions & 0 deletions src/core/SplitWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ contract SplitWallet is Ownable {
_;
}

receive() external payable {}

function transferETH(uint256 amount) external payable onlySplitFees {
(bool success,) = splitFees.call{value: amount}("");
require(success, "Failed to send Ether");
Expand Down
20 changes: 14 additions & 6 deletions src/module/SplitFeesModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ contract SplitFeesModule is Module, BeforeDistributeCallback, AfterWithdrawCallb
EVENTS
//////////////////////////////////////////////////////////////*/

event SplitCreated(address indexed splitWallet, address[] recipients, uint256[] allocations, address controller);
event SplitCreated(
address indexed splitWallet,
address[] recipients,
uint256[] allocations,
address controller,
address referenceContract
);
event SplitsUpdated(address indexed splitWallet, address[] recipients, uint256[] allocations, address controller);
event ControllerUpdated(address indexed splitWallet, address controller);
event SplitsDistributed(address indexed splitWallet, address token, uint256 amount);
Expand Down Expand Up @@ -145,17 +151,19 @@ contract SplitFeesModule is Module, BeforeDistributeCallback, AfterWithdrawCallb
//////////////////////////////////////////////////////////////*/

// Core contract calls this in constructor
function createSplit(address[] memory _recipients, uint256[] memory _allocations, address _controller)
external
validateSplits(_recipients, _allocations, _controller)
{
function createSplit(
address[] memory _recipients,
uint256[] memory _allocations,
address _controller,
address _referenceContract
) external validateSplits(_recipients, _allocations, _controller) {
Split memory _split = _setSplits(_recipients, _allocations, _controller);
address splitWalletImplementation = SplitFeesCore(payable(address(this))).splitWalletImplementation();

address splitWallet = LibClone.clone(splitWalletImplementation);
_splitFeesStorage().splits[splitWallet] = _split;

emit SplitCreated(splitWallet, _recipients, _allocations, _controller);
emit SplitCreated(splitWallet, _recipients, _allocations, _controller, _referenceContract);
}

function updateSplit(
Expand Down
21 changes: 14 additions & 7 deletions test/module/SplitFeeModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ contract SplitFeesModuleTest is Test {
address public recipient1 = address(0x4);
address public recipient2 = address(0x5);

address public referenceContract = address(0x6);

// Constants
address private constant NATIVE_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

Expand All @@ -75,12 +77,12 @@ contract SplitFeesModuleTest is Test {

vm.recordLogs();
vm.prank(owner);
SplitFeesModule(address(splitFeesCore)).createSplit(recipients, allocations, owner);
SplitFeesModule(address(splitFeesCore)).createSplit(recipients, allocations, owner, referenceContract);

// Retrieve the splitWallet address from the event logs
Vm.Log[] memory entries = vm.getRecordedLogs();

bytes32 SplitCreatedTopic = keccak256("SplitCreated(address,address[],uint256[],address)");
bytes32 SplitCreatedTopic = keccak256("SplitCreated(address,address[],uint256[],address,address)");

for (uint256 i = 0; i < entries.length; i++) {
Vm.Log memory log = entries[i];
Expand All @@ -90,6 +92,7 @@ contract SplitFeesModuleTest is Test {
break;
}
}
console.log("split wallet created: ", splitWallet);

token = new MockCurrency();
}
Expand All @@ -115,12 +118,12 @@ contract SplitFeesModuleTest is Test {

vm.recordLogs();
vm.prank(owner);
SplitFeesModule(address(splitFeesCore)).createSplit(recipients, allocations, owner);
SplitFeesModule(address(splitFeesCore)).createSplit(recipients, allocations, owner, referenceContract);

// Get the splitWallet address from the SplitCreated event
Vm.Log[] memory entries = vm.getRecordedLogs();

bytes32 SplitCreatedTopic = keccak256("SplitCreated(address,address[],uint256[],address)");
bytes32 SplitCreatedTopic = keccak256("SplitCreated(address,address[],uint256[],address,address)");

address newSplitWallet;

Expand All @@ -133,7 +136,7 @@ contract SplitFeesModuleTest is Test {
}
}

address splitFees = SplitWallet(newSplitWallet).splitFees();
address splitFees = SplitWallet(payable(newSplitWallet)).splitFees();

assertEq(splitFees, address(splitFeesCore), "splitWallet splitFees incorrect");
}
Expand All @@ -148,7 +151,7 @@ contract SplitFeesModuleTest is Test {

// Expect revert
vm.expectRevert(abi.encodeWithSelector(SplitFeesModule.SplitFeesTooFewRecipients.selector));
SplitFeesModule(address(splitFeesCore)).createSplit(recipients, allocations, owner);
SplitFeesModule(address(splitFeesCore)).createSplit(recipients, allocations, owner, referenceContract);
}

function test_revert_createSplit_LengthMismatch() public {
Expand All @@ -163,7 +166,7 @@ contract SplitFeesModuleTest is Test {
vm.prank(owner);

vm.expectRevert(abi.encodeWithSelector(SplitFeesModule.SplitFeesLengthMismatch.selector));
SplitFeesModule(address(splitFeesCore)).createSplit(recipients, allocations, owner);
SplitFeesModule(address(splitFeesCore)).createSplit(recipients, allocations, owner, referenceContract);
}

/*//////////////////////////////////////////////////////////////
Expand All @@ -181,6 +184,10 @@ contract SplitFeesModuleTest is Test {
newAllocations[0] = 70;
newAllocations[1] = 30;

Split memory asd = SplitFeesModule(address(splitFeesCore)).getSplit(splitWallet);
console.log("controller of split wallet: ", asd.controller);
console.log("owner: ", owner);

vm.prank(owner);
vm.expectEmit(true, true, true, true);
emit SplitsUpdated(splitWallet, newRecipients, newAllocations, owner);
Expand Down
10 changes: 6 additions & 4 deletions test/module/SplitWallet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ contract SplitFeesModuleTest is Test {
address public recipient1 = address(0x4);
address public recipient2 = address(0x5);

address public referenceContract = address(0x6);

// Constants
address private constant NATIVE_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

Expand All @@ -67,12 +69,12 @@ contract SplitFeesModuleTest is Test {

vm.recordLogs();
vm.prank(owner);
SplitFeesModule(address(splitFeesCore)).createSplit(recipients, allocations, owner);
SplitFeesModule(address(splitFeesCore)).createSplit(recipients, allocations, owner, referenceContract);

// Retrieve the splitWallet address from the event logs
Vm.Log[] memory entries = vm.getRecordedLogs();

bytes32 SplitCreatedTopic = keccak256("SplitCreated(address,address[],uint256[],address)");
bytes32 SplitCreatedTopic = keccak256("SplitCreated(address,address[],uint256[],address,address)");

for (uint256 i = 0; i < entries.length; i++) {
Vm.Log memory log = entries[i];
Expand Down Expand Up @@ -184,10 +186,10 @@ contract SplitFeesModuleTest is Test {

function test_revert_notSplitFees() public {
vm.expectRevert(abi.encodeWithSelector(SplitWallet.OnlySplitFees.selector));
SplitWallet(splitWallet).transferETH(10 ether);
SplitWallet(payable(splitWallet)).transferETH(10 ether);

vm.expectRevert(abi.encodeWithSelector(SplitWallet.OnlySplitFees.selector));
SplitWallet(splitWallet).transferERC20(address(token), 10 ether);
SplitWallet(payable(splitWallet)).transferERC20(address(token), 10 ether);
}

}