The X7TreasurySplitterV3 contract is an implementation of a contract that allows for the distribution of funds among multiple recipients, referred to as "outlets." Each outlet has a corresponding recipient address and a share of the funds to be distributed. The contract is owned by a specific address, which has the ability to modify the behavior of the contract.
The contract has several functions:
takeBalance This function divides the current balance of the contract among the various outlet recipients.
takeCurrentBalance This function transfers the entire current balance of the contract to the outlet associated with the caller's address.
divvyUp: This function distributes the balance of the contract among the outlets according to their respective shares.
pushAll: This function allows the owner to transfer the entire balance of the contract to a specified address.
The outletBalance mapping stores the current balance for each outlet. The outletRecipient mapping stores the address of the recipient for each outlet. The outletShare mapping stores the percentage of the total balance that should be distributed to each outlet.
The outletLookup mapping allows for looking up the outlet corresponding to a given recipient address.
The outletFrozen mapping stores a boolean value indicating whether or not an outlet is frozen, which means that it cannot receive any more funds.
These mappings and their corresponding functions allow for the flexible distribution of funds among the outlets and their recipients.
The OutletRecipientSet event is emitted when the recipient for an outlet is changed. This event includes the outlet, the old recipient address, and the new recipient address.
The SharesSet event is emitted when the shares of the outlets are modified. This event includes the old and new shares for the OTHER_SLOT1, OTHER_SLOT2, and REWARD_POOL outlets.
The OutletRecipientFrozen event is emitted when the recipient for an outlet is frozen, which means that it can no longer receive any more funds.
These events allow for tracking changes to the outlets, their recipients, and the distribution of funds in the contract.
This is the constructor function of the X7TreasurySplitterV3 contract. It is called when the contract is deployed and sets up the initial state of the contract.
The function then sets the initial shares for each outlet. The REWARD_POOL outlet is set to 6000 shares, the OTHER_SLOT1 outlet is set to 15000 shares, and the OTHER_SLOT2 outlet is set to 30000 shares.
The function then sets the initial authorization and recipients for each outlet. The REWARD_POOL outlet is set to have an empty recipient, and the OTHER_SLOT1 and OTHER_SLOT2 outlets are set to have specific recipient addresses.
This constructor function initializes the outlets and their corresponding recipients and shares, as well as the authorization and control of these outlets.
receive() external payable {}
The receive function is a built-in function in the Solidity programming language that allows a contract to receive ether. It is a fallback function that is called when the contract receives an ether transfer.
The payable keyword indicates that the function is able to receive ether. The external keyword indicates that the function can be called from external contracts. The receive function does not have any arguments or a return value.
The receive function is often used in combination with the transfer or send functions to transfer ether to a contract.
The receive function is usually implemented to perform some action when the contract receives ether, such as storing the ether in a balance or distributing it among multiple recipients.
The divvyUp function is a public function of the X7TreasurySplitterV3 contract that distributes the contract's balance among the various outlets.
The function first calculates the new amount of ether that has been received by the contract since the last time the function was called, by subtracting the reservedETH variable from the contract's current balance. If the new amount of ether is greater than zero, the function proceeds to distribute it among the outlets.
The function distributes the new ether to each outlet based on their respective shares, which are stored in the outletShare mapping. The shares are expressed as a percentage of the total balance, and are divided by 100000 to get the fractional value. For example, if the PROFITSHARE outlet has a share of 7000 and the new amount of ether is 10, the outlet would receive 0.7 ether.
The function then sets the reservedETH variable to the contract's current balance, to keep track of the amount of ether that has been distributed.
This function allows for the automatic distribution of the contract's balance among the outlets based on their respective shares.
The freezeOutlet function is a public function of the X7TreasurySplitterV3 contract that allows the owner of to freeze the outlet.
The function takes an Outlet enum value outlet as an argument. It performs the following actions:
It checks that the outlet is not OTHER_SLOT1 or OTHER_SLOT2, using an if statement.
It checks that the outlet is not already frozen.
It sets the outletFrozen mapping for the outlet to true.
This function allows the owner to freeze an outlet, subject to certain restrictions. It is used to temporarily disable certain outlets from receiving new funds.
The setOtherSlotRecipient function is a public function of the X7TreasurySplitterV3 contract that allows the contract owner to set the recipient of the OTHER_SLOT1, OTHER_SLOT2, or REWARD_POOL outlets.
The function takes an Outlet enum value outlet and an address recipient as arguments. It performs the following actions:
It checks that the outlet is either OTHER_SLOT1, OTHER_SLOT2, or REWARD_POOL, using an if statement.
It checks that the outlet is not frozen, using the outletFrozen mapping.
It saves the current recipient address of the outlet in a local variable oldRecipient.
It sets the outletLookup mapping for the recipient address to the outlet value.
It sets the outletRecipient mapping for the outlet to the recipient address.
It emits an OutletRecipientSet event, passing the outlet, the old recipient address, and the new recipient address as arguments.
This function allows the contract owner to set the recipient of the OTHER_SLOT1, OTHER_SLOT2, or REWARD_POOL outlets, subject to certain restrictions.
This function allows the owner of the contract to set the percentage shares for the OTHER_SLOT1, OTHER_SLOT2, or REWARD_POOL outlets. It requires that the sum of the three shares is 51000 (equivalent to 51%). The function first calls the divvyUp() function to redistribute the existing balance according to the new shares. Then, it updates the values of the outletShare mapping for the relevant outlets and emits an event to record the change. It also requires that the outletFrozen value for these outlets is false, indicating that they are not currently frozen and can be changed.
This function allows the recipient of one of the outlets to withdraw their balance from the contract. It first checks that the sender is the recipient of an outlet by looking up the outlet associated with the sender's address in the outletLookup mapping. If the sender is not the recipient of an outlet, it will throw an error. If the sender is the recipient of an outlet, it will first call the divvyUp function to redistribute the contract's balance among the outlets based on their share percentages. Then it calls the _sendBalance function, passing in the outlet associated with the sender's address, to transfer the balance of the outlet to the sender's address.
The takeCurrentBalance function allows the recipient of an outlet to take the balance of that outlet. To do so, the function looks up the outlet associated with the caller's address using the outletLookup mapping. If the outlet is not NONE, it calls the _sendBalance function with the outlet as an argument. The _sendBalance function is responsible for transferring the balance of the outlet to the recipient.
Note that the takeCurrentBalance function does not call the divvyUp function, which means that the balance of the outlet is not updated to reflect any new ETH that has been received by the contract. This means that the balance that is transferred to the recipient may not include any ETH that has been received by the contract since the last time the balance was distributed.
Is responsible for distributing the balance of the contract among the various outlets specified in the Outlet enum. The function first calls divvyUp, which updates the balance of each outlet based on the distribution of shares specified in the outletShare mapping. It then calls _sendBalance for each outlet, which sends the balance of the outlet to its corresponding recipient.
It's worth noting that this function can only be called by the contract's owner, as it is not marked with the external visibility modifier. This means that only the contract owner can initiate the distribution of the contract's balance.
This function ia a way for the contract owner to retrieve any WETH (wrapped ETH) that is stuck in the contract and distribute it to the outlets.
The function first retrieves the address of the WETH contract by calling the rescueWETH() function. Then, it calls the withdraw() function on the WETH contract to transfer the balance of WETH that is held by this contract back to the owner of the contract. After that, the function calls the pushAll() function to distribute the WETH balance among the outlets.
It is important to note that this function can only be called by the contract owner, as it is marked with the public visibility modifier, but not the external modifier. This means that it can only be called internally within the contract, and not from an external contract or from a user's wallet.
The function rescueTokens first checks if the provided token address matches the address of WETH (Wrapped ETH). If the token address matches WETH, the function calls the rescueWETH function. If the provided token address is not WETH, the function transfers the entire balance of the specified token from the contract to a designated recipient OTHER_SLOT2.
The _sendBalance function is an internal function that is used to send the balance of a given outlet to its recipient. The function takes an Outlet as an argument and retrieves the recipient's address using the outletRecipient mapping. It then checks if the recipient's address is the zero address (0x0), in which case it simply returns without sending any funds.
If the recipient's address is not the zero address, the function calculates the amount of ETH to send by looking up the balance for the given outlet in the outletBalance mapping. It then sets the balance for the outlet to 0 and subtracts the amount of ETH to be sent from the reserved balance.
Finally, the function sends the calculated amount of ETH to the recipient using the call function. If the call function returns false, indicating that the transaction failed, the function restores the balance for the outlet and the reserved balance to their original values before returning.