TipsWithConfig
Inherits: ITipsWithConfig, Initializable, ReentrancyGuard
Logic to handle the periodical tips that user can send to character periodically.
User can set config for a specific character, and anyone can collect the tip by config id.
For setTipsConfig4Character
User can set the tips config for a specific character.
For collectTips4Character
Anyone can collect the tip by config id, and it will transfer all available tokens
from the fromCharacterId account to the toCharacterId account.
State Variables
_web3Entry
address internal _web3Entry;
_tipsConfigIndex
uint256 internal _tipsConfigIndex;
_tipsConfigs
mapping(uint256 tipsConfigId => TipsConfig) internal _tipsConfigs;
_tipsConfigIds
mapping(uint256 fromCharacterId => mapping(uint256 toCharacterId => uint256 tipsConfigId)) internal
_tipsConfigIds;
_feeFractions
mapping(address feeReceiver => uint256 fraction) internal _feeFractions;
_feeFractions4Character
mapping(address feeReceiver => mapping(uint256 characterId => uint256 fraction)) internal
_feeFractions4Character;
Functions
onlyFeeReceiver
modifier onlyFeeReceiver(address feeReceiver);
validateFraction
modifier validateFraction(uint256 fraction);
initialize
Initialize the contract, setting web3Entry address.
function initialize(address web3Entry_) external override initializer;
Parameters
| Name | Type | Description |
|---|---|---|
web3Entry_ | address | Address of web3Entry. |
setDefaultFeeFraction
Sets the default fee percentage of specific receiver.
The feeReceiver can be a platform account.
function setDefaultFeeFraction(address feeReceiver, uint256 fraction)
external
override
onlyFeeReceiver(feeReceiver)
validateFraction(fraction);
Parameters
| Name | Type | Description |
|---|---|---|
feeReceiver | address | The fee receiver address. |
fraction | uint256 | The percentage measured in basis points. Each basis point represents 0.01%. |
setFeeFraction4Character
Sets the fee percentage of specific <receiver, character>.
If this is set, it will override the default fee fraction.
function setFeeFraction4Character(address feeReceiver, uint256 characterId, uint256 fraction)
external
override
onlyFeeReceiver(feeReceiver)
validateFraction(fraction);
Parameters
| Name | Type | Description |
|---|---|---|
feeReceiver | address | The fee receiver address. |
characterId | uint256 | The character ID. |
fraction | uint256 | The percentage measured in basis points. Each basis point represents 0.01%. |
setTipsConfig4Character
Sets the tips config of specific <fromCharacter, toCharacter>.
Emits a {SetTipsConfig4Character} event.
If the tips config of specific <fromCharacter, toCharacter> is already, it will try to collect the tips first, and then override the tips config.
function setTipsConfig4Character(
uint256 fromCharacterId,
uint256 toCharacterId,
address token,
uint256 amount,
uint256 startTime,
uint256 endTime,
uint256 interval,
address feeReceiver
) external override;
Parameters
| Name | Type | Description |
|---|---|---|
fromCharacterId | uint256 | The token ID of character that would send the reward. |
toCharacterId | uint256 | The token ID of character that would receive the reward. |
token | address | The token address. |
amount | uint256 | The amount of token. |
startTime | uint256 | The start time of tips. |
endTime | uint256 | The end time of tips. |
interval | uint256 | The interval of tips. |
feeReceiver | address | The fee receiver address. |
cancelTips4Character
Cancels the tips config.
Emits a {CancelTips4Character} event.
It will try to collect the tips first, and then delete the tips config.
function cancelTips4Character(uint256 tipConfigId) external override;
Parameters
| Name | Type | Description |
|---|---|---|
tipConfigId | uint256 | The tip config ID to cancel. |
collectTips4Character
Collects all unredeemed token from the fromCharacter to the toCharacter.
Emits a {CollectTips4Character} event if collects successfully.
It will transfer all unredeemed token from the fromCharacter to the toCharacter.
function collectTips4Character(uint256 tipConfigId)
external
override
nonReentrant
returns (uint256 collectedAmount);
Parameters
| Name | Type | Description |
|---|---|---|
tipConfigId | uint256 | The tip config ID. |
Returns
| Name | Type | Description |
|---|---|---|
collectedAmount | uint256 | The amount of token collected. |
getFeeFraction
Returns the fee percentage of specific <receiver, note>.
It will return the first non-zero value by priority feeFraction4Character and defaultFeeFraction.
function getFeeFraction(address feeReceiver, uint256 characterId)
external
view
override
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
feeReceiver | address | The fee receiver address. |
characterId | uint256 | The character ID . |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | fraction The percentage measured in basis points. Each basis point represents 0.01%. |
getFeeAmount
Returns how much the fee is owed by <feeFraction, tipAmount>.
function getFeeAmount(address feeReceiver, uint256 characterId, uint256 tipAmount)
external
view
override
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
feeReceiver | address | The fee receiver address. |
characterId | uint256 | The character ID . |
tipAmount | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The fee amount. |
getTipsConfigId
Return the tips config Id.
function getTipsConfigId(uint256 fromCharacterId, uint256 toCharacterId)
external
view
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
fromCharacterId | uint256 | The token ID of character that initiated a reward. |
toCharacterId | uint256 | The token ID of character that would receive the reward. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | uint256 Returns tips config ID. |
getTipsConfig
Return the tips config.
function getTipsConfig(uint256 tipConfigId)
external
view
override
returns (TipsConfig memory config);
Parameters
| Name | Type | Description |
|---|---|---|
tipConfigId | uint256 | The tip config ID. |
getWeb3Entry
Returns the address of web3Entry contract.
function getWeb3Entry() external view override returns (address);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address | The address of web3Entry contract. |
_collectTips4Character
function _collectTips4Character(uint256 tipConfigId) internal returns (uint256);
_getTipsConfigId
function _getTipsConfigId(uint256 fromCharacterId, uint256 toCharacterId)
internal
view
returns (uint256);
_getAvailableRoundAndAmount
function _getAvailableRoundAndAmount(TipsConfig memory config)
internal
view
returns (uint256, uint256);
_getFeeFraction
function _getFeeFraction(address feeReceiver, uint256 characterId)
internal
view
returns (uint256);
_getFeeAmount
function _getFeeAmount(address feeReceiver, uint256 characterId, uint256 tipAmount)
internal
view
returns (uint256);
_getTipRound
function _getTipRound(uint256 startTime, uint256 endTime, uint256 interval)
internal
pure
returns (uint256);
_feeDenominator
Defaults to 10000 so fees are expressed in basis points.
function _feeDenominator() internal pure virtual returns (uint96);
Events
SetTipsConfig4Character
Emitted when a user set a tip with periodical config.
event SetTipsConfig4Character(
uint256 indexed tipConfigId,
uint256 indexed fromCharacterId,
uint256 indexed toCharacterId,
address token,
uint256 amount,
uint256 startTime,
uint256 endTime,
uint256 interval,
address feeReceiver,
uint256 totalRound
);
Parameters
| Name | Type | Description |
|---|---|---|
tipConfigId | uint256 | The tip config id. |
fromCharacterId | uint256 | The token ID of character that initiated a reward. |
toCharacterId | uint256 | The token ID of character that would receive the reward. |
token | address | Address of token to reward. |
amount | uint256 | The amount of tokens to reward each round. |
startTime | uint256 | The start time of tip. |
endTime | uint256 | The end time of tip. |
interval | uint256 | The interval of tip. |
feeReceiver | address | The fee receiver address. |
totalRound | uint256 | The total round of tip. |
CancelTips4Character
Emitted when a periodical config is canceled.
event CancelTips4Character(uint256 indexed tipConfigId);
Parameters
| Name | Type | Description |
|---|---|---|
tipConfigId | uint256 | The tip config id. |
CollectTips4Character
Emitted when a user collect a tip with periodical config.
event CollectTips4Character(
uint256 indexed tipConfigId,
uint256 indexed fromCharacterId,
uint256 indexed toCharacterId,
address token,
uint256 amount,
uint256 fee,
address feeReceiver,
uint256 currentRound
);
Parameters
| Name | Type | Description |
|---|---|---|
tipConfigId | uint256 | The tip config id. |
fromCharacterId | uint256 | The token ID of character that initiated a reward. |
toCharacterId | uint256 | The token ID of character that would receive the reward. |
token | address | Address of token to reward. |
amount | uint256 | Actual amount of tokens to reward. |
fee | uint256 | Actual amount of fee. |
feeReceiver | address | The fee receiver address. |
currentRound | uint256 | The current round of tip. |