5 - Table

Last updated 2 months ago

(still under construction)

WeiTable is a WeiReceiver, that implements the composition of Destination and Splitter elements within a single contract. Instead of deploying many smart contracts you can use a single WeiTable to dramatically reduce gas usage.

WeiTable, as any moneyflow node, features a processFunds() function.

WeiTable has functions for working both with individual nodes and with all WeiTable entirely. IWeiReceiver functions are interpreted as referring to a node with id equal to zero. For example, weiTable.getMinWeiNeeded() is equal to weiTable.getMinWeiNeededAt(0).

Notable functions:

  • balanceAt() – get balance, that associated with node.

  • isNeedsMoneyAt() – returns true if node can receive ETH;

  • getMinWeiNeededAt() – returns a minimum amount of ETH, which node will accept;

  • getTotalWeiNeededAt() – returns a maximum amount of ETH, which node will accept;

  • addAbsoluteExpense() – create absolute expense node; it should be connected to a splitter in the weiTable

  • addRelativeExpense() – create relative expense node; it should be connected to a splitter in the weiTable

  • addTopdownSplitter() – create topdown splitter node; it should be connected to a splitter in the weiTable

  • addUnsortedSplitter() – create unsorted splitter node; it should be connected to a splitter in the weiTable

  • addChildAt() – connect a node to a splitter or 0-node

  • openAt() – make node acceptable for transfer amounts. By default, all nodes are open

  • closeAt() – make node non-acceptable for transfer amounts. If node is closed, needed amount is 0, and processFunds will revert.

  • flushToAt() – flush funds, that associated with node, to the specified address.

WeiTable is distinguished from the Destination by the fact that it have flushToAt() instead of flush()/flushTo().

Code example

Moneyflow table example.sol
WeiTable weiTable = new WeiTable();
weiTable.addAbsoluteExpense();
uint salaries = weiTable.getLastNodeId();
weiTable.addAbsoluteExpense(10*eth, false, false, 0);
uint employee1 = weiTable.getLastNodeId();
weiTable.addAbsoluteExpense(30*eth, false, false, 0);
uint employee2 = weiTable.getLastNodeId();
weiTable.addAbsoluteExpense(50*eth, false, false, 0);
uint employee3 = weiTable.getLastNodeId();
weiTable.addChildAt(salaries, employee1);
weiTable.addChildAt(salaries, employee2);
weiTable.addChildAt(salaries, employee3);
// check needs
weiTable.getTotalWeiNeeded(100*eth); // 90*eth
weiTable.getMinWeiNeeded(); // 90*eth
// send money
weiTable.processFunds.value(90*eth)(90*eth);
// check balances
weiTable.balanceAt(employee1); // 10*eth
weiTable.balanceAt(employee2); // 30*eth
weiTable.balanceAt(employee3); // 50*eth
// withdraw salary
weiTable.flushToAt(employee1, employee1_address);
weiTable.flushToAt(employee2, employee2_address);
weiTable.flushToAt(employee3, employee3_address);