Suppose you hire me to build a FOMO3D clone for you, and offer me 10% of all profits forever. I don't have an appetite for risk, so I want to receive DAI. Can this be done entirely in solidity?
What it does
This project is a frontend that lets you deploy a SplitterConverter with a list of receivers, their percentage shares, and the desired currency they each want. Then, send ETH and/or DAI to the deployed contract address. When someone calls withdraw() on the contract, the ETH and DAI are converted and split according to the parameters passed in when the contract was deployed
How I built it
I started building just a front end for an existing payment splitting contract that could only handle ETH. I finished that the first night, and decided to do a clean-room rewrite of the payment splitting contract to make it handle ETH and DAI as input and send ETH or any token as output. I used Kyber network for the conversion, wrote the frontend with react and material-ui.
Challenges I ran into
CloneFactory worked fine for a while, but randomly just stopped working, and I had to rewrite my frontend to deploy the regular contract instead of a clone. Ropsten is kinda slow sometimes and it sucks waiting for txns to confirm.
I really wanted to make the contract be able to handle any token as input and not just DAI and ETH. I tried to use oracalize so that when a user calls the withdraw() function, oracalize would retrieve all the token addresses that have a nonzero balance for the splitter contract, and then convert those using kyber as well. But no matter what, oracalize always returned 0 in the callback on ropsten. I spent a lot of time trying to make this work, but oh well. I also tried to use chainlink but I got stuck and the devs told me that the architecture isn't suitable for this type of thing.
Accomplishments that I'm proud of
It works! Send ETH and DAI in, and get your desired currency out, split at the percentage you want. You could use this for royalties, profit sharing, or even for yourself. Set it up for 50/50 ETH/DAI and then give the deployed contract address out to people who owe you money. Now, you're automatically insulated from volatility in 50% of your funds.
What I learned
Remix is amazing! Kyber is super cool and works quite well. Oracalize seems to have issus on Ropsten.
What's next for SplitterConverter
Clean up of the hacky code, get it audited, add a backup withdraw function that will just split the ETH and DAI contained in the contract and send it out without conversion, which is useful in case Kyber network breaks or something. Also need to make some UI changes to let people withdraw using an already deployed contract.