-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Tipping post action introduced
Co-authored-by: Victor Naumik <[email protected]>
- Loading branch information
1 parent
09175f7
commit a7a8050
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |