Splitmatic is a port of Splitwise, in solidity.
It is intended to be a learning project, does not try to be feature complete.
It includes:
- A Solidity library for core logic
- Access control (therefore separation of concerns)
- Utilization of
approve
function from ERC20. - Tests, written in Typescript
- A Github action for tests:
- Participants can be added to the group by other participants anytime.
- Participants have nicknames, persisted by the contract.
- Payments are done with a ERC20 token, which is determined on contract creation.
-
Participants enter any spending by supplying an array of charges, which represents the actual value every participant received from the spending.
-
If an actor with more debt than expenditure decides to settle, the difference is transferred to the contract.
-
If an actor with more expenditure than debt decides to settle, the amount is transferred from contract to that actor's account. If the funds are insufficient, the actor gets whatever they can, with the remaining due amount is still in effect.
For an example, you can check this document out.
- Separating the core logic from the access control benefitted the readability of the contract, at the same time allowing us to apply the DRY principle. Also, the core logic does not interact with the
ERC20
token at all. - An account holds
debt
andowed
together, which are strictly non-decreasing on everyspend
action. In this way, we can follow everybody's financial situation cheaply, without rememberingN^2
information. When a person spends,debt
andowed
fields can increase at the same time.
yarn
npx hardhat test