Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
On-Chain income splitter and distributor
copy icon
0xSplits
• version 1.0.0
Token
ERC20
Finance
Payments
Fees
ETH
Audited

On-Chain income splitter and distributor

Audited

Set and perform payment splits in either ETH or Tokens. Can be used for royalty splits or automated payment splits. Accepts both ETH and ERC20 tokens. Splits can be updated and transferred. Whenever a Split receives income, each recipient gets their share.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

0xSplits

Recent Use

🍞 0x0cff saved
🥐 0x18d8 saved
🥖 0xbb00 downloaded
🥨 0x4209 saved
🥯 0x4209 downloaded
🥞 0x30f2 downloaded
🧀 0x30f2 saved
🍖 0x34f9 downloaded
🍗 0x17fd downloaded
🥩 0xB5AB downloaded

Last Publish

9/26/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
createSplit(uint32[],uint32,address) :
This function creates a new split contract, which is a type of wallet contract that allows multiple users to share ownership of a single wallet. The function takes in an array of addresses (accounts), an array of uint32s (percentAllocations), a uint32 (distributorFee), and an address (controller). It first calculates a hash of the split using the _hashSplit() function, which is used to ensure that the split is unique. If the controller address is 0, then the split is cloned deterministically using the walletImplementation address and the splitHash. If the controller address is not 0, then the split is cloned using the walletImplementation address and the controller address is set to the controller address provided. The splitHash is then stored in the splits mapping and an event is emitted to indicate that the split has been created. (autogenerated documentation)
predictImmutableSplitAddress(uint32[],uint32) :
This function is used to predict the address of an immutable split contract. It takes in an array of addresses (accounts), an array of uint32 (percentAllocations) and a uint32 (distributorFee) as input parameters. It first calculates a hash of the split using the _hashSplit() function, which takes in the same input parameters. It then uses the Clones.predictDeterministicAddress() function to predict the address of the immutable split contract using the walletImplementation and the splitHash as parameters. The function returns the address of the immutable split contract. (autogenerated documentation)
updateSplit(address,uint32[],uint32) :
This function allows the Split Controller to update the details of a given split. The split is identified by its address, and the new details are passed in as calldata parameters. The accounts parameter is an array of addresses that will receive the split funds, the percentAllocations parameter is an array of integers representing the percentage of the split funds each account will receive, and the distributorFee parameter is an integer representing the percentage of the split funds that will be taken as a fee. The function checks that the split controller is authorized to update the split, and that the new details are valid. If both of these conditions are met, the function calls the _updateSplit function to update the split with the new details. (autogenerated documentation)
transferControl(address,address) :
This function is used to transfer control of a split contract from one address to another. It takes two parameters, the address of the split contract and the address of the new controller. It first checks that the caller is the current controller of the split contract, and that the new controller is a valid address. If these checks pass, it sets the newPotentialController of the split contract to the new controller address and emits an InitiateControlTransfer event. (autogenerated documentation)
cancelControlTransfer(address) :
This function is used to cancel a control transfer of a split. It is an external function that can only be called by the split controller of the split in question. It takes the address of the split as an argument. The function deletes the new potential controller from the splits mapping and emits an event to notify that the control transfer has been cancelled. (autogenerated documentation)
acceptControl(address) :
This function is used to transfer control of a split (identified by its address) from its current controller to a new controller. It is an external function that overrides the onlySplitNewPotentialController function. The function first deletes the newPotentialController property from the split object in the splits mapping. It then emits a ControlTransfer event, passing in the split address, the current controller address, and the new controller address. Finally, it sets the controller address of the split to the new controller address. (autogenerated documentation)
makeSplitImmutable(address) :
This function is used to make a split immutable. It does this by deleting the newPotentialController field from the split, and then emitting a ControlTransfer event with the split address, the current controller address, and a zero address. This sets the controller address to zero, making the split immutable. (autogenerated documentation)
distributeETH(address,uint32[],uint32,address) :
This function is used to distribute ETH to a set of accounts based on a given set of percentages. The function takes in five parameters: the split address, an array of accounts, an array of percent allocations, a distributor fee, and a distributor address. The function first checks to make sure that the split, accounts, and percent allocations are valid, and then it distributes the ETH to the accounts based on the given percentages. The distributor fee is taken out of the total amount of ETH being distributed, and the remaining ETH is sent to the distributor address. (autogenerated documentation)
updateAndDistributeETH(address,uint32[],uint32,address) :
This function is used to update and distribute ETH from a split contract. It takes in five parameters: the address of the split contract, an array of addresses of the accounts to receive the ETH, an array of uint32s representing the percent allocations for each account, a uint32 representing the distributor fee, and an address of the distributor. The function first calls the _updateSplit() function, which updates the split contract with the new accounts, percent allocations, and distributor fee. It then calls the _distributeETH() function, which distributes the ETH from the split contract to the accounts according to the percent allocations, taking into account the distributor fee. The ETH is sent to the distributor address. (autogenerated documentation)
distributeERC20(address,uint32[],uint32,address) :
This function is used to distribute ERC20 tokens to a set of accounts based on a given set of percentages. The function takes in the address of the split, the ERC20 token to be distributed, an array of accounts to receive the tokens, an array of percentages to allocate the tokens, a distributor fee, and the address of the distributor. It first checks to make sure that the split, accounts, percentages, and distributor fee are valid. It then calls the _validSplitHash function to generate a hash of the split, accounts, percentages, and distributor fee. Finally, it calls the _distributeERC20 function to distribute the ERC20 tokens to the accounts based on the given percentages, with the distributor receiving the distributor fee. (autogenerated documentation)
updateAndDistributeERC20(address,uint32[],uint32,address) :
This function is used to update and distribute ERC20 tokens from a given split address. It takes in the split address, the ERC20 token, an array of accounts, an array of percent allocations, a distributor fee, and a distributor address as parameters. The function first calls the _updateSplit() function to update the split with the given accounts, percent allocations, and distributor fee. It then calls the _distributeERC20() function to distribute the ERC20 tokens to the given accounts according to the percent allocations, with the distributor address receiving the distributor fee. (autogenerated documentation)
withdraw(address,uint256) :
This function allows a user to withdraw ETH and ERC20 tokens from their account. It takes in an address, the amount of ETH to withdraw, and an array of ERC20 tokens to withdraw. It then creates an array of token amounts to withdraw and stores the amount of ETH to withdraw in a variable. It then calls the _withdraw() and _withdrawERC20() functions to withdraw the ETH and ERC20 tokens respectively. Finally, it emits an event with the account address, the amount of ETH withdrawn, the tokens withdrawn, and the amounts of each token withdrawn. (autogenerated documentation)
getHash(address) :
This function is used to retrieve the hash associated with a given address split. It takes in an address split as an argument and returns the corresponding hash as a bytes32 value. The function works by accessing the splits mapping, which stores the address split as the key and the associated hash as the value. The function then returns the value associated with the given address split. (autogenerated documentation)
getController(address) :
This function is used to retrieve the address of the controller associated with a given split. The function takes in an address of a split as an argument and returns the address of the controller associated with that split. The function works by accessing the splits mapping, which stores the address of the controller associated with each split. The function then returns the address of the controller associated with the split address that was passed in as an argument. (autogenerated documentation)
getNewPotentialController(address) :
This function is used to retrieve the address of the new potential controller of a given split. It takes in the address of the split as an argument and returns the address of the new potential controller. The function is marked as external and view, meaning that it does not modify the state of the contract and can be called from outside of the contract. The address of the new potential controller is stored in the splits mapping, which is a key-value store that maps split addresses to their associated data. (autogenerated documentation)
getETHBalance(address) :
This function is used to get the ETH balance of a given account. It does this by first looking up the account in the ethBalances mapping and returning the value associated with it. If the account is not found in the ethBalances mapping, the function then checks the splits mapping to see if the account has a hash associated with it. If it does, the function returns the balance of the account. If the account is not found in either mapping, the function returns 0. (autogenerated documentation)
getERC20Balance(address) :
This function is used to get the balance of an ERC20 token for a given account. It does this by first looking up the balance of the account in the erc20Balances array, which stores the balance of the account for each token. It then checks if the account has any pending splits, which are stored in the splits array. If there are any pending splits, the function will then call the balanceOf() function of the token to get the balance of the account. Finally, it returns the sum of the two values as the balance of the account for the given token. (autogenerated documentation)
_getSum(uint32[]) :
This function is an internal function that takes an array of uint32 numbers as an argument and returns the sum of all the numbers in the array. It does this by looping through the array and adding each number to the sum variable. The loop is unchecked, meaning that it will not throw an error if the index is out of bounds. (autogenerated documentation)
_hashSplit(uint32[],uint32) :
This function is an internal pure function that takes in an array of addresses, an array of uint32s, and a uint32 as parameters. It returns a bytes32. The function works by taking the parameters and encoding them into a single bytes32 using the abi.encodePacked() function. This bytes32 is then hashed using the keccak256() function, and the resulting hash is returned. (autogenerated documentation)
_updateSplit(address,uint32[],uint32) :
This function updates a split in the Splits contract. It takes in an address for the split, an array of addresses for the accounts, an array of uint32 for the percent allocations, and a uint32 for the distributor fee. It then calculates a hash of the split using the _hashSplit() function, and stores the hash in the splits mapping. Finally, it emits an UpdateSplit event. (autogenerated documentation)
_validSplitHash(address,uint32[],uint32) :
This function is used to validate a split hash. It takes in an address split, an array of addresses (accounts), an array of uint32 (percentAllocations), and a uint32 (distributorFee) as parameters. It then calculates a hash using the _hashSplit() function, which takes in the same parameters. It then compares the calculated hash to the hash stored in the splits mapping. If the hashes do not match, the function reverts with an InvalidSplit__InvalidHash error. (autogenerated documentation)
_distributeETH(address,uint32[],uint32,address) :
This function is used to distribute ETH from a split wallet to a set of accounts. The function takes in the address of the split wallet, an array of addresses to which the ETH should be distributed, an array of percentages that indicate how much ETH should be allocated to each address, a fee that should be taken from the total amount of ETH to be distributed, and an address for the fee to be sent to. The function first calculates the total amount of ETH to be distributed by subtracting 1 from the main balance of the split wallet and adding the proxy balance. It then emits an event to indicate that ETH is being distributed from the split wallet. If a fee is specified, the function calculates the fee amount and subtracts it from the total amount of ETH to be distributed. The function then iterates through the array of addresses and allocates the ETH to each address according to the specified percentages. Finally, if there is any ETH left in the proxy balance, the function sends it to the main balance of the split wallet. (autogenerated documentation)
_distributeERC20(address,uint32[],uint32,address) :
This function is used to distribute ERC20 tokens from a split wallet address to a set of accounts. The function takes in the split wallet address, the ERC20 token to be distributed, an array of accounts to receive the tokens, an array of percentages to allocate the tokens to each account, a distributor fee, and the address of the distributor. The function first calculates the amount of tokens to be split by subtracting 1 from the main balance and the proxy balance of the split wallet address. It then emits an event to log the distribution of the tokens. If a distributor fee is specified, the function calculates the amount of tokens to be allocated to the distributor and subtracts it from the amount to be split. The function then iterates through the array of accounts and allocates the tokens to each account based on the percentage allocations specified. Finally, if there is a proxy balance, the function sends the tokens to the main wallet address. (autogenerated documentation)
_scaleAmountByPercentage(uint256,uint256) :
This function takes in two uint256 values, an amount and a scaledPercent, and returns a scaledAmount. It works by first multiplying the amount by the scaledPercent, and then dividing the result by the PERCENTAGE_SCALE constant. This allows the function to scale the amount by the given percentage. (autogenerated documentation)
_withdraw(address) :
This function is an internal function that allows users to withdraw their ETH balance from an account. It takes an address as an argument and returns the amount of ETH withdrawn. The function subtracts 1 from the ETH balance of the account and sets the balance to 1. It then sends the withdrawn amount to the account using the safeTransferETH function. (autogenerated documentation)
_withdrawERC20(address) :
This function is used to withdraw ERC20 tokens from an account. It takes two parameters, an address of the account from which the tokens are to be withdrawn, and an ERC20 token. The function then subtracts 1 from the erc20Balances array for the specified token and account, and then calls the token's safeTransfer function to transfer the withdrawn amount to the specified account. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i on-chain-income-splitter-and-distributor
copy icon

Recent Use

🍞 0x0cff saved
🥐 0x18d8 saved
🥖 0xbb00 downloaded
🥨 0x4209 saved
🥯 0x4209 downloaded
🥞 0x30f2 downloaded
🧀 0x30f2 saved
🍖 0x34f9 downloaded
🍗 0x17fd downloaded
🥩 0xB5AB downloaded

Last Publish

9/26/2022

Version

1.0.0

Creator

0xSplits

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.