Skip to content

Commit

Permalink
misc: Actions refactored to follow the new ActionHub imposed interface
Browse files Browse the repository at this point in the history
Co-authored-by: Victor Naumik <[email protected]>
  • Loading branch information
donosonaumczuk and vicnaum committed Dec 23, 2024
1 parent ff25ce2 commit 09175f7
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 79 deletions.
22 changes: 15 additions & 7 deletions contracts/actions/account/TippingAccountAction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,36 @@
// Copyright (C) 2024 Lens Labs. All Rights Reserved.
pragma solidity ^0.8.0;

import {IAccountAction} from "./../../core/interfaces/IAccountAction.sol";
import {BaseAccountAction} from "./base/BaseAccountAction.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {KeyValue} from "./../../core/types/Types.sol";

contract TippingAccountAction is IAccountAction {
contract TippingAccountAction is BaseAccountAction {
using SafeERC20 for IERC20;

// keccak256("lens.actions.account.TippingAccountAction.param.key.tipAmount");
bytes32 immutable TIP_AMOUNT_PARAM_KEY = 0x9c3dd1983546cd2f985b2e6692b416f4157648b3750ffc5bdf5a6365061d9bd9;
// keccak256("lens.actions.account.TippingAccountAction.param.key.tipToken");
bytes32 immutable TIP_TOKEN_PARAM_KEY = 0xae0b2bf062e67ee8e231397eadff68e32752f185a8cb19379ed8cfa87ae7bd08;

function configure(
constructor(
address actionHub
) BaseAccountAction(actionHub) {}

function _configure(
address, /* originalMsgSender */
address, /* account */
KeyValue[] calldata /* params */
) external pure override returns (bytes memory) {
) internal pure override returns (bytes memory) {
revert(); // Configuration not needed for tipping.
}

function execute(address account, KeyValue[] calldata params) external override returns (bytes memory) {
function _execute(
address originalMsgSender,
address account,
KeyValue[] calldata params
) internal override returns (bytes memory) {
address erc20Token;
uint256 tipAmount;
for (uint256 i = 0; i < params.length; i++) {
Expand All @@ -33,8 +42,7 @@ contract TippingAccountAction is IAccountAction {
}
}
require(tipAmount > 0);
IERC20(erc20Token).safeTransferFrom(msg.sender, account, tipAmount);
emit Lens_AccountAction_Executed(account, params);
IERC20(erc20Token).safeTransferFrom(originalMsgSender, account, tipAmount);
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
// Copyright (C) 2024 Lens Labs. All Rights Reserved.
pragma solidity ^0.8.0;

import {KeyValue} from "./../../core/types/Types.sol";
import {BaseAction} from "./BaseAction.sol";
import {IAccountAction} from "./ActionHub.sol";
import {KeyValue} from "./../../../core/types/Types.sol";
import {BaseAction} from "./../../base/BaseAction.sol";
import {IAccountAction} from "./../../../dashboard/actions/ActionHub.sol";

abstract contract BaseAccountAction is BaseAction, IAccountAction {
constructor(
address actionHub
) BaseAction(actionHub) {}

function configure(
address originalMsgSender,
address account,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
// Copyright (C) 2024 Lens Labs. All Rights Reserved.
pragma solidity ^0.8.0;

import {KeyValue} from "./../../core/types/Types.sol";
import {BaseAction} from "./BaseAction.sol";
import {IPostAction} from "./ActionHub.sol";
import {KeyValue} from "./../../../core/types/Types.sol";
import {BaseAction} from "./../../base/BaseAction.sol";
import {IPostAction} from "./../../../dashboard/actions/ActionHub.sol";

abstract contract BasePostAction is BaseAction, IPostAction {
constructor(
address actionHub
) BaseAction(actionHub) {}

function configure(
address originalMsgSender,
address feed,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (C) 2024 Lens Labs. All Rights Reserved.
pragma solidity ^0.8.0;

import {IPostAction} from "./../../core/interfaces/IPostAction.sol";
import {IPostAction} from "./../../../dashboard/actions/ActionHub.sol";

/**
* @notice A storage struct containing all data regarding a post's collect action.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Copyright (C) 2024 Lens Labs. All Rights Reserved.
pragma solidity ^0.8.0;

import "./../../core/base/LensERC721.sol";
import "./../../../core/base/LensERC721.sol";
import {IERC7572} from "./IERC7572.sol";
import {IFeed} from "./../../core/interfaces/IFeed.sol";
import {ITokenURIProvider} from "./../../core/interfaces/ITokenURIProvider.sol";
import {IFeed} from "./../../../core/interfaces/IFeed.sol";
import {ITokenURIProvider} from "./../../../core/interfaces/ITokenURIProvider.sol";

/**
* @notice A contract that represents a Lens Collected Post.
Expand Down Expand Up @@ -56,7 +56,9 @@ contract LensCollectedPost is LensERC721, IERC7572 {
return _contractURI;
}

function tokenURI(uint256 /*tokenId*/ ) public view override returns (string memory) {
function tokenURI(
uint256 /*tokenId*/
) public view override returns (string memory) {
if (_isImmutable) {
return _contentURISnapshot;
} else {
Expand All @@ -71,7 +73,9 @@ contract LensCollectedPost is LensERC721, IERC7572 {

// Disabling integrated LensERC721 tokenURIProvider
// TODO: Is this approach more favorable than deploying the LensCollectedPostTokenURIProvider over and over?
function _beforeTokenURIProviderSet(ITokenURIProvider /* tokenURIProvider */ ) internal pure override {
function _beforeTokenURIProviderSet(
ITokenURIProvider /* tokenURIProvider */
) internal pure override {
revert();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
pragma solidity ^0.8.0;

import {ISimpleCollectAction, CollectActionData, CollectActionData} from "./ISimpleCollectAction.sol";
import {IFeed} from "./../../core/interfaces/IFeed.sol";
import {IGraph} from "./../../core/interfaces/IGraph.sol";
import {IFeed} from "./../../../core/interfaces/IFeed.sol";
import {IGraph} from "./../../../core/interfaces/IGraph.sol";

import {LensCollectedPost} from "./LensCollectedPost.sol";
import {BasePostAction} from "./../base/BasePostAction.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {KeyValue} from "./../../core/types/Types.sol";
import {KeyValue} from "./../../../core/types/Types.sol";

contract SimpleCollectAction is ISimpleCollectAction {
contract SimpleCollectAction is ISimpleCollectAction, BasePostAction {
using SafeERC20 for IERC20;

struct CollectActionStorage {
Expand Down Expand Up @@ -76,12 +77,17 @@ contract SimpleCollectAction is ISimpleCollectAction {
address currency; // (Optional, but required if amount > 0) Default: address(0)
}

function configure(
constructor(
address actionHub
) BasePostAction(actionHub) {}

function _configure(
address originalMsgSender,
address feed,
uint256 postId,
KeyValue[] calldata params
) external override returns (bytes memory) {
_validateSenderIsAuthor(msg.sender, feed, postId);
) internal override returns (bytes memory) {
_validateSenderIsAuthor(originalMsgSender, feed, postId);

CollectActionConfigureParams memory configData = _extractConfigurationFromParams(params);
_validateConfigureParams(configData);
Expand Down Expand Up @@ -111,28 +117,26 @@ contract SimpleCollectAction is ISimpleCollectAction {
}
}
bytes memory encodedStoredData = abi.encode(storedData);
emit Lens_PostAction_Configured(feed, postId, params, encodedStoredData);
return encodedStoredData;
}

function execute(
function _execute(
address originalMsgSender,
address feed,
uint256 postId,
KeyValue[] calldata params
) external override returns (bytes memory) {
) internal override returns (bytes memory) {
CollectActionExecutionParams memory expectedParams = _extractCollectActionExecutionParams(params);

CollectActionData storage storedData = $collectDataStorage().collectData[feed][postId];
storedData.currentCollects++;

_validateCollect(feed, postId, expectedParams);
_validateCollect(originalMsgSender, feed, postId, expectedParams);

_processCollect(feed, postId);
_processCollect(originalMsgSender, feed, postId);

// TODO: Might want to move inside _processCollect?
LensCollectedPost(storedData.collectionAddress).mint(msg.sender, storedData.currentCollects);

emit Lens_PostAction_Executed(feed, postId, params, "");
LensCollectedPost(storedData.collectionAddress).mint(originalMsgSender, storedData.currentCollects);
return "";
}

Expand All @@ -146,7 +150,9 @@ contract SimpleCollectAction is ISimpleCollectAction {
}
}

function _validateConfigureParams(CollectActionConfigureParams memory configData) internal virtual {
function _validateConfigureParams(
CollectActionConfigureParams memory configData
) internal virtual {
if (configData.amount == 0) {
require(configData.currency == address(0), "Invalid currency");
} else {
Expand All @@ -156,7 +162,7 @@ contract SimpleCollectAction is ISimpleCollectAction {
revert("Invalid params");
}
if (configData.followerOnlyGraph != address(0)) {
// Check if the Graph supports isFollowing() interface
// Check if the Graph supports isFollowing() interface with two random addresses
IGraph(configData.followerOnlyGraph).isFollowing(address(this), msg.sender);
}
}
Expand All @@ -181,6 +187,7 @@ contract SimpleCollectAction is ISimpleCollectAction {
}

function _validateCollect(
address originalMsgSender,
address feed,
uint256 postId,
CollectActionExecutionParams memory expectedParams
Expand All @@ -203,7 +210,7 @@ contract SimpleCollectAction is ISimpleCollectAction {

if (data.followerOnlyGraph != address(0)) {
require(
IGraph(data.followerOnlyGraph).isFollowing(msg.sender, IFeed(feed).getPostAuthor(postId)),
IGraph(data.followerOnlyGraph).isFollowing(originalMsgSender, IFeed(feed).getPostAuthor(postId)),
"Not following"
);
}
Expand All @@ -219,23 +226,21 @@ contract SimpleCollectAction is ISimpleCollectAction {
}
}

function _processCollect(address feed, uint256 postId) internal virtual {
function _processCollect(address originalMsgSender, address feed, uint256 postId) internal virtual {
CollectActionData storage data = $collectDataStorage().collectData[feed][postId];

uint256 amount = data.amount;
address currency = data.currency;
address recipient = data.recipient;

if (amount > 0) {
IERC20(currency).safeTransferFrom(msg.sender, recipient, amount);
IERC20(currency).safeTransferFrom(originalMsgSender, recipient, amount);
}
}

function _extractConfigurationFromParams(KeyValue[] calldata params)
internal
pure
returns (CollectActionConfigureParams memory)
{
function _extractConfigurationFromParams(
KeyValue[] calldata params
) internal pure returns (CollectActionConfigureParams memory) {
CollectActionConfigureParams memory configData = CollectActionConfigureParams({
amount: 0,
collectLimit: 0,
Expand Down Expand Up @@ -266,11 +271,9 @@ contract SimpleCollectAction is ISimpleCollectAction {
return configData;
}

function _extractCollectActionExecutionParams(KeyValue[] calldata params)
internal
pure
returns (CollectActionExecutionParams memory)
{
function _extractCollectActionExecutionParams(
KeyValue[] calldata params
) internal pure returns (CollectActionExecutionParams memory) {
CollectActionExecutionParams memory executionParams =
CollectActionExecutionParams({amount: 0, currency: address(0)});

Expand Down
15 changes: 0 additions & 15 deletions contracts/core/interfaces/IAccountAction.sol

This file was deleted.

15 changes: 0 additions & 15 deletions contracts/core/interfaces/IPostAction.sol

This file was deleted.

0 comments on commit 09175f7

Please sign in to comment.