Agent-A sells a good-U to agent-B for u EUR;
Agent-B pays agent-A by owing u EUR (due to agent-A);
Agent-B has a debt of u EUR due to agent-A.
Then
Agent-C sells a good-V to agent-A for v EUR;
If v = u
Agent-A pays agent-C by transferring the agent-B debt of u EUR;
Agent-B has a debt of u EUR due to agent-C;
Agent-A does not have any debt due to agent-C.
If v > u
Agent-A partly pays agent-C by transferring the agent-B debt of u EUR, and by owing v-u EUR (due to agent-C);
Agent-B has a debt of u EUR due to agent-C;
Agent-A has a debt of v-u EUR due to agent-C.
If v < u
Agent-A splits the agent-B debt of u EUR into 2 debts: one debt of v EUR and another debt of u-v EUR;
Agent-A pays agent-C by transferring the agent-B debt of v EUR;
Agent-B has a debt of v EUR due to agent-C;
Agent-B has a debt of u-v EUR due to agent-A;
Agent-A does not have any debt due to agent-C.
Alice sells a good/service to Barry for 100 EUR;
Barry pays Alice by owing 100 EUR (due to Alice);
Barry has a debt of 100 EUR due to Alice.
Then
Calum sells a good/service to Alice for 100 EUR;
Alice pays Calum by owing 100 EUR (due to Calum);
Alice has a debt of 100 EUR due to Calum.
Then
Barry sells a good/service to Calum for 100 EUR;
Calum pays Barry by owing 100 EUR (due to Barry);
Calum has a debt of 100 EUR due to Barry.
Then
the system finds out that there is a loop:
- Barry has a debt of 100 EUR due to Alice;
- Alice has a debt of 100 EUR due to Calum;
- Calum has a debt of 100 EUR due to Barry;
and therefore the system can simply clear the three debts. You can see it as if the system would borrow 100 EUR to Barry, so Barry can give these 100 EUR to Alice to pay his debt, then Alice can give these 100 EUR to Calum to pay her bebt, then Calum can give these 100 EUR to Barry to pay his debt, and finally Barry can give the 100 EUR back to the system!