A little explanation might be needed. I mean mutual credit the way that it's defined here:
a type of alternative currency in which the currency used in a transaction can be created at the time of the transaction
Imagine you have a network of accounts. Each starts out at zero and any account can extend a limited line of credit to any other account. My total balance would just be the sum of what others "owe" to me, minus the sum of what I owe to others.
Lines of credit can be represented with a simple table. In pseudo-code for some kind of ORM:
type LineOfCredit struct {
IOURecipient string, // Account ID of IOU recipient
IOUIssuer string, // Account ID of IOU issuer
Owed int, // Amount owed to IOU recipient
Limit int, // Maximum IOU amount
}
To hopefully make the concept clearer: The "recipient" would generally be the person getting "paid" in a transaction; the "issuer" is the person "paying." For example:
- Persons A requests service from person B
- B agrees and extends a line of credit to A
- A issues IOU to B
These debts may or may not be settled in some real-world currency, at some point, but the idea is that they eventually cancel out one another, either directly or indirectly.
I'll use "$" to represent the currency, though, of course, the units are arbitrary. Imagine that...
- Bob owes $20 to Sally
- Sally owes $20 to Joe
- Joe owes $20 to Bob
It's clear that there's no actual debt here and they don't owe one another anything.
So, how would you detect these kinds of cycles in a balance sheet and then eliminate them? Is this a problem for graph theory? I imagine this can be represented as a directed network graph. My knowledge here is very limited, but I understand it's possible to detect cycles with Tarjan's strongly connected components algorithm, though that doesn't seem to offer much help, especially as those cycles get larger. I also thought that, maybe, shortest-paths could be crunched at the time of a transaction, with the reciprocals of outstanding "debts" represented as edge-weights/distances.
I think Ripple pay possibly did something like this, but I'm having trouble finding a precedent.