diff --git a/script/DeploySplitFees.sol b/script/DeploySplitFees.sol new file mode 100644 index 00000000..e8b5a423 --- /dev/null +++ b/script/DeploySplitFees.sol @@ -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(); + } + +} diff --git a/script/mint-rewards/DeployMintRewards.sol b/script/mint-rewards/DeployMintRewards.sol new file mode 100644 index 00000000..a42a11c6 --- /dev/null +++ b/script/mint-rewards/DeployMintRewards.sol @@ -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(); + } + +} diff --git a/src/core/SplitWallet.sol b/src/core/SplitWallet.sol index 1b4648a6..a3728fd3 100644 --- a/src/core/SplitWallet.sol +++ b/src/core/SplitWallet.sol @@ -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"); diff --git a/src/module/SplitFeesModule.sol b/src/module/SplitFeesModule.sol index 53be2be3..0d5db9ba 100644 --- a/src/module/SplitFeesModule.sol +++ b/src/module/SplitFeesModule.sol @@ -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); @@ -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( diff --git a/test/module/SplitFeeModule.t.sol b/test/module/SplitFeeModule.t.sol index 23160e69..a89d264c 100644 --- a/test/module/SplitFeeModule.t.sol +++ b/test/module/SplitFeeModule.t.sol @@ -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; @@ -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]; @@ -90,6 +92,7 @@ contract SplitFeesModuleTest is Test { break; } } + console.log("split wallet created: ", splitWallet); token = new MockCurrency(); } @@ -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; @@ -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"); } @@ -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 { @@ -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); } /*////////////////////////////////////////////////////////////// @@ -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); diff --git a/test/module/SplitWallet.t.sol b/test/module/SplitWallet.t.sol index 9a773db0..092e8c14 100644 --- a/test/module/SplitWallet.t.sol +++ b/test/module/SplitWallet.t.sol @@ -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; @@ -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]; @@ -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); } }