TipsWithConfig

Git Source

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

NameTypeDescription
web3Entry_addressAddress 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

NameTypeDescription
feeReceiveraddressThe fee receiver address.
fractionuint256The 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

NameTypeDescription
feeReceiveraddressThe fee receiver address.
characterIduint256The character ID.
fractionuint256The 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

NameTypeDescription
fromCharacterIduint256The token ID of character that would send the reward.
toCharacterIduint256The token ID of character that would receive the reward.
tokenaddressThe token address.
amountuint256The amount of token.
startTimeuint256The start time of tips.
endTimeuint256The end time of tips.
intervaluint256The interval of tips.
feeReceiveraddressThe 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

NameTypeDescription
tipConfigIduint256The 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

NameTypeDescription
tipConfigIduint256The tip config ID.

Returns

NameTypeDescription
collectedAmountuint256The 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

NameTypeDescription
feeReceiveraddressThe fee receiver address.
characterIduint256The character ID .

Returns

NameTypeDescription
<none>uint256fraction 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

NameTypeDescription
feeReceiveraddressThe fee receiver address.
characterIduint256The character ID .
tipAmountuint256

Returns

NameTypeDescription
<none>uint256The fee amount.

getTipsConfigId

Return the tips config Id.

function getTipsConfigId(uint256 fromCharacterId, uint256 toCharacterId) external view returns (uint256);

Parameters

NameTypeDescription
fromCharacterIduint256The token ID of character that initiated a reward.
toCharacterIduint256The token ID of character that would receive the reward.

Returns

NameTypeDescription
<none>uint256uint256 Returns tips config ID.

getTipsConfig

Return the tips config.

function getTipsConfig(uint256 tipConfigId) external view override returns (TipsConfig memory config);

Parameters

NameTypeDescription
tipConfigIduint256The tip config ID.

getWeb3Entry

Returns the address of web3Entry contract.

function getWeb3Entry() external view override returns (address);

Returns

NameTypeDescription
<none>addressThe 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
);

CancelTips4Character

Emitted when a periodical config is canceled.

event CancelTips4Character(uint256 indexed tipConfigId);

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
);