Splitter
TierraDAO Explanation
Contract Overview
The Splitter
contract is an Ownable
contract that allows the owner to set two receivers and their respective percentages for splitting funds. It supports splitting both ERC20 tokens and Bera. When Bera is sent to the contract, it is automatically split and forwarded to the configured receivers based on the defined percentages.
Events
Sent(address indexed sender, address indexed receiver, address indexed token, uint amount)
Emitted when funds are split and sent to a receiver.
sender
: The address of the sender.receiver
: The address of the receiver.token
: The address of the token being sent (oraddress(0)
for Bera).amount
: The amount of tokens or Bera sent.
State Variables
receiver1:
address
The address of the first receiver (e.g., vault).
Can be set by the owner using the
set
function.
receiver2:
address
The address of the second receiver (e.g., TRR buyback).
Can be set by the owner using the
set
function.
percentage1:
uint8
The percentage of funds to be sent to
receiver1
.Default value is
70
.Can be set by the owner using the
set
function.
percentage2:
uint8
The percentage of funds to be sent to
receiver2
.Default value is
30
.Can be set by the owner using the
set
function.
Functions
Admin Functions
set(address _receiver1, address _receiver2, uint8 _percentage1, uint8 _percentage2)
Allows the owner to set the receivers and their respective percentages.
Reverts if the caller is not the owner.
Parameters:
_receiver1
: The address of the first receiver._receiver2
: The address of the second receiver._percentage1
: The percentage of funds to send toreceiver1
._percentage2
: The percentage of funds to send toreceiver2
.
Public Functions
split(address token, uint amount)
Splits the specified amount of ERC20 tokens between
receiver1
andreceiver2
based on the configured percentages.If
amount
is0
, the function splits the entire balance of the sender.Emits two
Sent
events, one for each receiver.Parameters:
token
: The address of the ERC20 token to split.amount
: The amount of tokens to split (or0
to split the sender's entire balance).
Fallback Function
receive() external payable
Fallback function that automatically splits incoming Bera between
receiver1
andreceiver2
based on the configured percentages.Emits two
Sent
events, one for each receiver.Uses
call
to forward Bera to the receivers.
Last updated