Skip to content

Commit

Permalink
feat: Tipping post action introduced
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 09175f7 commit a7a8050
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions contracts/actions/post/TippingPostAction.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: UNLICENSED
// Copyright (C) 2024 Lens Labs. All Rights Reserved.
pragma solidity ^0.8.0;

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 {IFeed} from "./../../core/interfaces/IFeed.sol";

contract TippingPostAction is BasePostAction {
using SafeERC20 for IERC20;

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

constructor(
address actionHub
) BasePostAction(actionHub) {}

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

function _execute(
address originalMsgSender,
address feed,
uint256 postId,
KeyValue[] calldata params
) internal override returns (bytes memory) {
address erc20Token;
uint256 tipAmount;
for (uint256 i = 0; i < params.length; i++) {
if (params[i].key == TIP_AMOUNT_PARAM_KEY) {
tipAmount = abi.decode(params[i].value, (uint256));
} else if (params[i].key == TIP_TOKEN_PARAM_KEY) {
erc20Token = abi.decode(params[i].value, (address));
}
}
require(tipAmount > 0);
address account = IFeed(feed).getPostAuthor(postId);
IERC20(erc20Token).safeTransferFrom(originalMsgSender, account, tipAmount);
return abi.encode(account);
}
}

0 comments on commit a7a8050

Please sign in to comment.