circles-transfer
v0.1.0
Published
Find maximum flow and transitive transfers steps in a trust graph
Downloads
3
Readme
Circles Transfer
Utility module for Circles to find the Maximum flow and necessary transitive transfers steps in a trust graph with multiple tokens.
Requirements
- NodeJS
Installation
npm i @circles/transfer
Usage
import findTransitiveTransfer from '@circles/transfer';
// Define a weighted trust graph between trusted tokens. Each edge describes
// how much ("capacity") of what token ("token") can be sent from which node
// ("from") to which ("to"):
const nodes = [
'A',
'B',
'C',
'D',
];
const edges = [
{
from: 'A',
to: 'B',
token: 'A',
capacity: 10,
},
{
from: 'B',
to: 'C',
token: 'B',
capacity: 7,
},
{
from: 'B',
to: 'C',
token: 'C',
capacity: 5,
},
...
];
// Find required transfer steps to send transfer transitively between two nodes:
const { transferSteps, maxFlowValue } = findTransitiveTransfer({
nodes,
edges,
from: 'A',
to: 'D',
value: 5,
});
// ... we get the maximum possible value:
console.log(`Can send max. ${maxFlowValue} between A and D`);
// ... and finally the transfer steps:
transferSteps.forEach(({ step, from, to, value, token }) => {
console.log(`${step}.: Send ${value} of ${token} from ${from} to ${to}`);
});
Development
circles-transfer
is a JavaScript module written in JavaScript, tested with Jest, transpiled with Babel and bundled with Rollup.
// Install dependencies
npm install
// Run test suite
npm run test
npm run test:watch
// Check code formatting
npm run lint
// Build it!
npm run build
License
GNU Affero General Public License v3.0 AGPL-3.0