TipsWithFee
Inherits: ITipsWithFee, Initializable, IERC777Recipient
Logic to handle rewards that user can send to character and note.
The platform can set the commission ratio through the TipsWithFee contract,
and draw a commission from the user's tips.
For TipCharacter
User/Client should call send
erc777 token to the TipsWithFee contract, with fromCharacterId
,
toCharacterId
and receiver
(a platform account) encoded in the data
.
send
interface is
IERC777-send,
and parameters encode refers
AbiCoder-encode.
For TipCharacter4Note
User should call send
erc777 token to the TipsWithFee contract, with fromCharacterId
,
toCharacterId
, toNoteId
and receiver
encoded in the data
.
The platform account can set the commission ratio through setDefaultFeeFraction
, setFeeFraction4Character
and setFeeFraction4Note
.
State Variables
ERC1820_REGISTRY
IERC1820Registry public constant ERC1820_REGISTRY = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
TOKENS_RECIPIENT_INTERFACE_HASH
bytes32 public constant TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient");
_web3Entry
address internal _web3Entry;
_token
address internal _token;
_feeFractions
mapping(address => uint256) internal _feeFractions;
_feeFractions4Character
mapping(address => mapping(uint256 => uint256)) internal _feeFractions4Character;
_feeFractions4Note
mapping(address => mapping(uint256 => mapping(uint256 => uint256))) internal _feeFractions4Note;
Functions
onlyFeeReceiver
modifier onlyFeeReceiver(address feeReceiver);
validateFraction
modifier validateFraction(uint256 fraction);
initialize
Initialize the contract, setting web3Entry address and token address.
function initialize(address web3Entry_, address token_) external override initializer;
Parameters
Name | Type | Description |
---|---|---|
web3Entry_ | address | Address of web3Entry. |
token_ | address | Address of token. |
setDefaultFeeFraction
Changes 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
Changes the fee percentage of specific <receiver, character>.
If feeFraction4Character 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%. |
setFeeFraction4Note
Changes the fee percentage of specific <receiver, note>.
If feeFraction4Note is set, it will override feeFraction4Character and the default fee fraction.
function setFeeFraction4Note(address feeReceiver, uint256 characterId, uint256 noteId, uint256 fraction)
external
override
onlyFeeReceiver(feeReceiver)
validateFraction(fraction);
Parameters
Name | Type | Description |
---|---|---|
feeReceiver | address | The fee receiver address. |
characterId | uint256 | The character ID . |
noteId | uint256 | The note ID . |
fraction | uint256 | The percentage measured in basis points. Each basis point represents 0.01%. |
tokensReceived
Called by an {IERC777} token contract whenever tokens are being
moved or created into a registered account to
(this contract).
The userData/operatorData should be an abi encoded bytes of fromCharacterId
, toCharacter
and toNoteId
(optional) and receiver
(platform account), so the length of data is 96 or 128.
function tokensReceived(
address,
address from,
address to,
uint256 amount,
bytes calldata userData,
bytes calldata operatorData
) external override(IERC777Recipient);
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. |
getToken
Returns the address of mira token contract.
function getToken() external view override returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of mira token contract. |
getFeeFraction
Returns the fee percentage of specific <receiver, note>.
It will return the first non-zero value by priority feeFraction4Note, feeFraction4Character and defaultFeeFraction.
function getFeeFraction(address feeReceiver, uint256 characterId, uint256 noteId)
external
view
override
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
feeReceiver | address | The fee receiver address. |
characterId | uint256 | The character ID . |
noteId | uint256 | The note 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 noteId, uint256 tipAmount)
external
view
override
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
feeReceiver | address | The fee receiver address. |
characterId | uint256 | The character ID . |
noteId | uint256 | The note ID . |
tipAmount | uint256 |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The fee amount. |
_tipCharacter
Tips a character by transferring amount
tokens
from the fromCharacterId
account to toCharacterId
account.
Emits the TipCharacter
event.
User should call send
erc777 token to the Tips contract, with fromCharacterId
and toCharacterId
encoded in the data
.
send
interface is
IERC777-send,
and parameters encode refers
AbiCoder-encode.
Requirements:
- The
from
account must be the character owner of `fromCharacterId.
function _tipCharacter(
address from,
uint256 fromCharacterId,
uint256 toCharacterId,
address token,
uint256 amount,
address feeReceiver
) internal;
Parameters
Name | Type | Description |
---|---|---|
from | address | The caller's account who sends token. |
fromCharacterId | uint256 | The token ID of character that calls this contract. |
toCharacterId | uint256 | The token ID of character that will receive the token. |
token | address | Address of token. |
amount | uint256 | Amount of token. |
feeReceiver | address | Fee receiver address. |
_tipCharacterForNote
Tips a character's note by transferring amount
tokens
from the fromCharacterId
account to toCharacterId
account.
Emits the TipCharacterForNote
event.
User should call send
erc777 token to the Tips contract, with fromCharacterId
,
toCharacterId
and toNoteId
encoded in the data
.
Requirements:
- The
from
account must be the character owner of `fromCharacterId.
function _tipCharacterForNote(
address from,
uint256 fromCharacterId,
uint256 toCharacterId,
uint256 toNoteId,
address token,
uint256 amount,
address feeReceiver
) internal;
Parameters
Name | Type | Description |
---|---|---|
from | address | The caller's account who sends token. |
fromCharacterId | uint256 | The token ID of character that calls this contract. |
toCharacterId | uint256 | The token ID of character that will receive the token. |
toNoteId | uint256 | The note ID. |
token | address | Address of token. |
amount | uint256 | Amount of token. |
feeReceiver | address | Fee receiver address. |
_tip
function _tip(
address from,
uint256 fromCharacterId,
uint256 toCharacterId,
uint256 toNoteId,
address token,
uint256 amount,
address feeReceiver
) internal;
_getFeeFraction
function _getFeeFraction(address feeReceiver, uint256 characterId, uint256 noteId) internal view returns (uint256);
_getFeeAmount
function _getFeeAmount(address feeReceiver, uint256 characterId, uint256 noteId, uint256 tipAmount)
internal
view
returns (uint256);
_feeDenominator
Defaults to 10000 so fees are expressed in basis points.
function _feeDenominator() internal pure virtual returns (uint96);
Events
TipCharacter
Emitted when the assets are rewarded to a character.
event TipCharacter(
uint256 indexed fromCharacterId,
uint256 indexed toCharacterId,
address token,
uint256 amount,
uint256 fee,
address feeReceiver
);
TipCharacterForNote
Emitted when the assets are rewarded to a note.
event TipCharacterForNote(
uint256 indexed fromCharacterId,
uint256 indexed toCharacterId,
uint256 indexed toNoteId,
address token,
uint256 amount,
uint256 fee,
address feeReceiver
);