Destination – is a terminal WeiReceiver element, i.e. does not send money further. There are three basic types of destinations:

  • WeiFunds:

    • WeiFund

    • WeiFundWithPeriod

    • WeiFundWithPeriodSliding

  • WeiExpenses:

    • WeiAbsoluteExpense

    • WeiAbsoluteExpenseWithPeriod

    • WeiAbsoluteExpenseWithPeriodSliding

    • WeiRelativeExpense

    • WeiRelativeExpenseWithPeriod

    • WeiRelativeExpenseWithPeriodSliding

  • MoneyflowTable

Each destination has flush() and flushTo() functions, that will send collected funds to the owner or any address respectively.

1. WeiFund

WeiFund – is a destination that can accept any amount, until the cap is reached (if cap is set).

Funds can be used as a buffer between customer payments and the main money flow of an organization, or just to store money (e.g.: reserve fund of a corporation).

Fund can not be relative.

Unlike absolute expense, fund can accept less ETH than it needs.

TODO - add pic of a generic fund

WeiOneTimeFund / WeiInfiniteFund

WeiOneTimeFund has a cap only. You can pull ETH from it many times, and it will not affect the cap.WeiInfiniteFund has no cap, and it will keep consuming any amount of ETH forever.

JavaScript
Plain Text
WeiOneTimeFund fund = new WeiOneTimeFund(10*eth);
WeiInfiniteFund infiniteFund = new WeiInfiniteFund();
// 100 ETH is a maximum amount that we can send to the element in the current case
// Still fund needs only 10 ETH
fund.getTotalWeiNeeded(100*eth); // 10*eth
fund.getMinWeiNeeded(); // 0
fund.isNeedsMoney(); // true
infiniteFund.getTotalWeiNeeded(100*eth); // 100*eth
infiniteFund.getMinWeiNeeded(); // 0
infiniteFund.isNeedsMoney(); // true
// send 3 ETH
fund.processFunds.value(3*eth)(100*eth);
// send 3 ETH again
fund.processFunds.value(3*eth)(100*eth);
// now fund needs 4 more ETH
fund.getTotalWeiNeeded(100*eth); // 4*eth
fund.getMinWeiNeeded(); // 0
fund.isNeedsMoney(); // true
// send 3 ETH to infiniteFund
infiniteFund.processFunds.value(3*eth)(100*eth);
infiniteFund.getTotalWeiNeeded(100*eth); // 100*eth
infiniteFund.getMinWeiNeeded(); // 0
infiniteFund.isNeedsMoney(); // true
// flash
fund.flush();
// Flush was not affected to getTotalWeiNeeded
fund.getTotalWeiNeeded(100*eth); // 4*eth
fund.getMinWeiNeeded(); // 0
fund.isNeedsMoney(); // true
// flash
infiniteFund.flush();
// Flush was not affected to getTotalWeiNeeded
infiniteFund.getTotalWeiNeeded(100*eth); // 100*eth

WeiPeriodicFund / WeiPeriodicFundSliding

Periodic funds have a cap and a period. Imagine, we set cap to 10 ETH and period to 1 week:

uint periodHours = 24 * 7; // 1 week
WeiPeriodicFund fund = new WeiPeriodicFund(10*eth, periodHours);
WeiPeriodicFundSliding fundWithSliding = new WeiPeriodicFundSliding(10*eth, periodHours);
// 100 ETH is a maximum amount that we can send to the element in the current case
// Still fund needs only 10 ETH
uint totalNeed = fund.getTotalWeiNeeded(100*eth); // 10*eth
uint minNeeded = fund.getMinWeiNeeded(); // 0
uint isNeeded = fund.isNeedsMoney(); // true
// send 3 ETH to both funds
fund.processFunds.value(3*eth)(100*eth);
fundWithSliding.processFunds.value(3*eth)(100*eth);
// now fund needs 7 more ETH
totalNeeded = fund.getTotalWeiNeeded(100*eth); // 7*eth
minNeeded = fund.getMinWeiNeeded(); // 0
isNeeded = fund.isNeedsMoney(); // true
// 1 week is passed here
// fund needs 10 ETH only
totalNeeded = fund.getTotalWeiNeeded(100*eth); // 10*eth
// but fundWithSliding needs 17 ETH
totalNeeded = fundWithSliding.getTotalWeiNeeded(100*eth); // 17*eth

2. WeiExpense

WeiExpense – is a destination that accepts only getTotalWeiNeeded() amount of ETH. TODO - add pic

WeiExpense example.sol
uint neededWei = 5*eth;
uint periodInHours = 24;
WeiAbsoluteExpense absoluteExpense = new WeiAbsoluteExpense(neededWei);
WeiAbsoluteExpenseWithPeriod absoluteExpenseWithPeriod = new WeiAbsoluteExpenseWithPeriod(neededWei, periodInHours);
WeiAbsoluteExpenseWithPeriodSliding absoluteExpenseWithPeriodSliding = new WeiAbsoluteExpenseWithPeriodSliding(neededWei, periodInHours);
absoluteExpense.getTotalWeiNeeded(100*eth); // 5*eth
absoluteExpense.getMinWeiNeeded(); // 5*eth
absoluteExpense.isNeedsMoney(); // true
absoluteExpenseWithPeriod.getTotalWeiNeeded(100*eth); // 5*eth
absoluteExpenseWithPeriodSliding.getTotalWeiNeeded(100*eth); // 5*eth
// SEND MONEY
absoluteExpense.processFunds.value(5*eth)(5*eth);
absoluteExpenseWithPeriod.processFunds.value(5*eth)(5*eth);
absoluteExpenseWithPeriodSliding.processFunds.value(5*eth)(5*eth);
// AND THEN
absoluteExpense.getTotalWeiNeeded(100*eth); // 0
absoluteExpenseWithPeriod.getTotalWeiNeeded(100*eth); // 0
absoluteExpenseWithPeriodSliding.getTotalWeiNeeded(100*eth); // 0
// TWO PERIODS PASSED
absoluteExpense.getTotalWeiNeeded(100*eth); // 0
absoluteExpenseWithPeriod.getTotalWeiNeeded(100*eth); // 5*eth
absoluteExpenseWithPeriodSliding.getTotalWeiNeeded(100*eth); // 10*eth
uint partsPerMillion = 50000;
uint periodInHours = 24;
WeiRelativeExpense relativeExpense = new WeiRelativeExpense(partsPerMillion);
WeiRelativeExpenseWithPeriod relativeExpenseWithPeriod = new WeiRelativeExpenseWithPeriod(partsPerMillion, periodInHours);
WeiRelativeExpenseWithPeriodSliding relativeExpenseWithPeriodSliding = new WeiRelativeExpenseWithPeriodSliding(partsPerMillion, periodInHours);
relativeExpense.getTotalWeiNeeded(100*eth); // 5*eth
relativeExpense.getMinWeiNeeded(); // 0
relativeExpense.isNeedsMoney(); // true
relativeExpenseWithPeriod.getTotalWeiNeeded(100*eth); // 5*eth
relativeExpenseWithPeriodSliding.getTotalWeiNeeded(100*eth); // 5*eth
// SEND MONEY
relativeExpense.processFunds.value(5*eth)(100*eth);
relativeExpenseWithPeriod.processFunds.value(5*eth)(100*eth);
relativeExpenseWithPeriodSliding.processFunds.value(5*eth)(100*eth);
// AND THEN
relativeExpense.getTotalWeiNeeded(100*eth); // 5*eth
relativeExpenseWithPeriod.getTotalWeiNeeded(100*eth); // 0
relativeExpenseWithPeriodSliding.getTotalWeiNeeded(100*eth); // 0
// TWO PERIODS PASSED
relativeExpense.getTotalWeiNeeded(100*eth); // 5*eth
relativeExpenseWithPeriod.getTotalWeiNeeded(100*eth); // 5*eth
relativeExpenseWithPeriodSliding.getTotalWeiNeeded(100*eth); // 10*eth