From 387a8209970c52acfe666e76040450850b928e16 Mon Sep 17 00:00:00 2001 From: "Miao, ZhiCheng" Date: Fri, 30 Aug 2024 16:22:02 +0300 Subject: [PATCH] cleanup --- packages/ethereum-contracts/CHANGELOG.md | 4 - .../contracts/utils/TrustedMacrosVanilla.sol | 27 ----- .../foundry/utils/TrustedMacrosVanilla.t.sol | 98 ------------------- 3 files changed, 129 deletions(-) delete mode 100644 packages/ethereum-contracts/contracts/utils/TrustedMacrosVanilla.sol delete mode 100644 packages/ethereum-contracts/test/foundry/utils/TrustedMacrosVanilla.t.sol diff --git a/packages/ethereum-contracts/CHANGELOG.md b/packages/ethereum-contracts/CHANGELOG.md index 4d231830ab..82dac18b5f 100644 --- a/packages/ethereum-contracts/CHANGELOG.md +++ b/packages/ethereum-contracts/CHANGELOG.md @@ -84,10 +84,6 @@ Note: this will NOT break any deployed contracts, only affects undeployed Super - FlowNFT hooks can't revert with outofgas anymore -### Added - -- New utility: TrustedMacrosVanilla trusted forwarder. - ## [v1.9.0] - 2024-01-09 ### Breaking diff --git a/packages/ethereum-contracts/contracts/utils/TrustedMacrosVanilla.sol b/packages/ethereum-contracts/contracts/utils/TrustedMacrosVanilla.sol deleted file mode 100644 index f6d590b277..0000000000 --- a/packages/ethereum-contracts/contracts/utils/TrustedMacrosVanilla.sol +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: AGPLv3 -pragma solidity 0.8.19; - -import { IUserDefinedMacro } from "../interfaces/utils/IUserDefinedMacro.sol"; -import { ISuperfluid } from "../interfaces/superfluid/ISuperfluid.sol"; -import { ForwarderBase } from "../utils/ForwarderBase.sol"; - - -/** - * @dev This is a trusted forwarder with high degree of extensibility through permission-less and user-defined "macro - * contracts". This is a vanilla version without EIP-712 support. - */ -contract TrustedMacrosVanilla is ForwarderBase { - constructor(ISuperfluid host) ForwarderBase(host) {} - - function simulateMacro(IUserDefinedMacro m, bytes memory params) public view - returns (ISuperfluid.Operation[] memory operations) - { - operations = m.executeMacro(_host, params); - } - - function runMacro(IUserDefinedMacro m, bytes memory params) external returns (bool) - { - ISuperfluid.Operation[] memory operations = simulateMacro(m, params); - return _forwardBatchCall(operations); - } -} diff --git a/packages/ethereum-contracts/test/foundry/utils/TrustedMacrosVanilla.t.sol b/packages/ethereum-contracts/test/foundry/utils/TrustedMacrosVanilla.t.sol deleted file mode 100644 index 76064778bd..0000000000 --- a/packages/ethereum-contracts/test/foundry/utils/TrustedMacrosVanilla.t.sol +++ /dev/null @@ -1,98 +0,0 @@ -// SPDX-License-Identifier: AGPLv3 -pragma solidity 0.8.19; - -import { ISuperfluid, BatchOperation } from "../../../contracts/interfaces/superfluid/ISuperfluid.sol"; -import { ISuperToken } from "../../../contracts/superfluid/SuperToken.sol"; -import { IConstantFlowAgreementV1 } from "../../../contracts/interfaces/agreements/IConstantFlowAgreementV1.sol"; -import { TrustedMacrosVanilla, IUserDefinedMacro } from "../../../contracts/utils/TrustedMacrosVanilla.sol"; -import { FoundrySuperfluidTester, SuperTokenV1Library } from "../FoundrySuperfluidTester.sol"; - - -contract DummyMacro is IUserDefinedMacro { - function executeMacro(ISuperfluid, bytes memory) override external pure - returns (ISuperfluid.Operation[] memory operations) - { - operations = new ISuperfluid.Operation[](0); - } -} - -contract NautyMacro { - uint naughtyCounter; - - function executeMacro(ISuperfluid, bytes memory) external - returns (ISuperfluid.Operation[] memory operation) - { - naughtyCounter++; - } -} - -contract GoodMacro is IUserDefinedMacro { - function executeMacro(ISuperfluid host, bytes memory params) external view - returns (ISuperfluid.Operation[] memory operations) - { - // host-agnostic deployment. alternatively, you may hard code cfa too - IConstantFlowAgreementV1 cfa = IConstantFlowAgreementV1(address(host.getAgreementClass( - keccak256("org.superfluid-finance.agreements.ConstantFlowAgreement.v1") - ))); - // parse params - (ISuperToken token, int96 flowRate, address[] memory recipients) = - abi.decode(params, (ISuperToken, int96, address[])); - // construct batch operations - operations = new ISuperfluid.Operation[](recipients.length); - // Build batch call operations here - for (uint i = 0; i < recipients.length; ++i) { - bytes memory callData = abi.encodeCall(cfa.createFlow, - (token, - recipients[i], - flowRate, - new bytes(0) // placeholder - )); - operations[i] = ISuperfluid.Operation({ - operationType : BatchOperation.OPERATION_TYPE_SUPERFLUID_CALL_AGREEMENT, // type - target: address(cfa), - data: abi.encode(callData, new bytes(0)) - }); - } - } -} - -contract TrustedMacrosVanillaTest is FoundrySuperfluidTester { - TrustedMacrosVanilla internal trustedMacros; - - constructor() FoundrySuperfluidTester(5) { - } - - function setUp() public override { - super.setUp(); - trustedMacros = new TrustedMacrosVanilla(sf.host); - vm.startPrank(address(sf.governance.owner())); - sf.governance.enableTrustedForwarder(sf.host, ISuperToken(address(0)), address(trustedMacros)); - vm.stopPrank(); - } - - function testDummyMacro() external { - DummyMacro m = new DummyMacro(); - trustedMacros.runMacro(m, new bytes(0)); - } - - function testNaugtyMacro() external { - NautyMacro m = new NautyMacro(); - vm.expectRevert(); - // Note: need to cast the naughty macro - trustedMacros.runMacro(IUserDefinedMacro(address(m)), new bytes(0)); - } - - function testGoodMacro() external { - GoodMacro m = new GoodMacro(); - address[] memory recipients = new address[](2); - recipients[0] = bob; - recipients[1] = carol; - vm.startPrank(admin); - // NOTE! This is different from abi.encode(superToken, int96(42), [bob, carol]), - // which is a fixed array: address[2]. - trustedMacros.runMacro(m, abi.encode(superToken, int96(42), recipients)); - assertEq(sf.cfa.getNetFlow(superToken, bob), 42); - assertEq(sf.cfa.getNetFlow(superToken, carol), 42); - vm.stopPrank(); - } -}