Universal decentralized ERC20 tokens rewards contract. * One ERC20 token serves as a shares, and any number of other ERC20 tokens serve as rewards(assets). Rewards distribution are divided in periods, the only thing that shareholder needs to do in order to take part in distribution is prove to rewards contract that he possess certain amount of shares before period closes. Prove is made through allowing rewards contract to take shares from the shareholder, and then depositing it through a call to rewards contract. Proof is needed for every period. * When calculating rewards distribution, resulting amount is always rounded down. * In order to be able to deposit shares, user needs to create allowance for wallet contract, using standard ERC20 approve() function, so that contract can take shares from the user, when user makes a dpeosit. * Users can withdraw their shares at any moment, but only remaining shares will be used for rewards distribution. Users can withdraw their accumulated rewards at any moment. * State flow: 1. Period closed, next period started; 2. Reward assets registered for last closed preiod; 3. Rewards distributed for closed period; 4. Shares deposited into current period; 5. Repeat. * Note: all the non constant functions return false instead of throwing in case if state change didn't happen yet.
/contracts/reward/Rewards.sol

constructor

Rewards

inputs0address_store
inputs1bytes32_crate
event

AssetRegistered 0700b0f4

inputs0addressassetAddress
event

DepositStored 8df23d40

inputs0uint256_part
event

Error 9cf38cf2

inputs0addressself
inputs1uint256errorCode
event

PeriodClosed 3a273a33

event

WithdrawnRewardSuccess 9e059fe0

inputs0addressasset
inputs1addressaddr
inputs2uint256amountReward
event

WithdrawnSuccess 9733cd8d

inputs0addressaddr
inputs1uint256amount
inputs2uint256total
function

_emitAssetRegistered 77e9f6fc

inputs0addressassetAddress
function

_emitDepositStored d1ddb8b3

inputs0uint256_part
function

_emitError 06d44278

inputs0uint256e
function

_emitPeriodClosed 3e87a56d

function

_emitWithdrawn 670bcab1

inputs0addressaddr
inputs1uint256amount
inputs2uint256total
function

_emitWithdrawnReward 2f65fa59

inputs0addressasset
inputs1addressaddr
inputs2uint256amount
function, constant

assetBalanceInPeriod 43369c59

Returns amount of accumulated rewards assets in a period. Always 0 for active period.

inputs0address_assetAddress

rewards asset contract address.

inputs1uint256_period

period.

outputs0uint256
function

changeContractOwnership 557f4bc9

Prepares ownership pass. * Can only be called by current owner.

inputs0address_to

address of the next owner. 0x0 is not allowed.

outputs0bool
function

claimContractOwnership 4592cd1d

Finalize ownership pass. * Can only be called by pending owner.

outputs0bool
function

closePeriod 507a7328

Close current active period and start the new period. * Can only be done if period was active longer than minimum length.

outputs0uint256resultCode
function, constant

contractOwner ce606ee0

function, constant

contractsManager 53253d31

function, constant

depositBalance 956501bb

Returns shares amount deposited by a particular shareholder.

inputs0address_address

shareholder address.

outputs0uint256
function, constant

depositBalanceInPeriod cce53fc4

Returns proven amount of shares possessed by a shareholder in a period.

inputs0address_address

shareholder address.

inputs1uint256_period

period.

outputs0uint256
function

destroy 83197ef0

function

emitAssetRegistered b1a97052

inputs0addressassetAddress
function

emitDepositStored 1bc24083

inputs0uint256_part
function

emitError df26ca08

inputs0uint256error
function

emitPeriodClosed e29065d6

function

emitWithdrawn 1bbf65ef

inputs0addressaddr
inputs1uint256amount
inputs2uint256total
function

emitWithdrawnReward 3752f49a

inputs0addressasset
inputs1addressaddr
inputs2uint256amount
function, constant

getAssets 67e4ac2c

function, constant

getCloseInterval 9d3c7370

function, constant

getEventsHistory fff10aba

function, constant

getMaxSharesTransfer fe82b458

function, constant

getPeriodStartDate aef54664

inputs0uint256_period
function, constant

getRewardsLeft be0ab3cb

inputs0addressshareholder
function

init 46639dba

Sets ContractManager contract and period minimum length. Starts the first period. * Can be set only once.

inputs0address_contractsManager

contracts Manager contract address.

inputs1address_wallet
inputs2address_targetPlatform
inputs3uint256_closeIntervalDays

period minimum length, in days.

outputs0uint256
function, constant

isAuthorized fe9fbb80

inputs0addresskey
function, constant

isCalculatedFor 76807249

Check if shareholder have calculated rewards in a period.

inputs0address_assetAddress

rewards asset contract address.

inputs1address_address

shareholder address.

inputs2uint256_period

period.

outputs0bool
function, constant

isClosed d5c78a28

Check if period is closed or not.

inputs0uint256_period

period.

outputs0bool
function, constant

lastClosedPeriod 8632779c

Returns last closed period.

throws in case if there is no closed periods yet.

outputs0uint256
function, constant

lastPeriod d340ef8a

Returns current active period.

outputs0uint256
function, constant

lookupManager 4fe59012

Will crash if no manager in the system with given identifier.

Returns manager's address by its identifier (type).

inputs0bytes32_identifier

is a manager's identifier. 0x0 is not allowed.

function, constant

pendingContractOwner 5aa77d3c

function, constant

periodUnique 57bd8522

inputs0uint256_period
function, constant

periodsLength 6abe602d

function, constant

rewardsFor 0f09330b

Returns accumulated asset rewards available for withdrawal for shareholder.

inputs0address_assetAddress

rewards asset contract address.

inputs1address_address

shareholder address.

outputs0uint256
function

setCloseInterval d5309c60

inputs0uint256_closeInterval
function

setContractsManager 71d3b573

Setter for ContractsManager. Force overrides currect manager.

inputs0address_contractsManager

contracts manager. 0x0 is not allowed.

function

setEventsHistory 6521afd7

inputs0address_eventsHistory
function

setMaxSharesTransfer 896efbd6

inputs0uint256_maxSharesTransfer
function

storeDeposits 98af444e

outputs0uint256resultCode
function, constant

totalDepositInPeriod 9a24159b

Returns total proven amount of shares possessed by shareholders in a period.

inputs0uint256_period

period.

outputs0uint256
function

transferContractOwnership a843c51f

Direct ownership pass without change/claim pattern. Can be invoked only by current contract owner

inputs0address_to

the next contract owner

outputs0bool
function, constant

wallet 521eb273

Gets wallet address used to store tokens

outputs0address
function

withdrawAllRewardsTotal 590f8c93

Withdraw all accumulated rewards. * Withdrawals are made for caller and total amount.

outputs0uint256
function

withdrawReward 58d3232f

Withdraw accumulated reward of a specified rewards asset. * Withdrawal is made for caller and specified amount.

inputs0address_asset

registered rewards asset contract address.

inputs1uint256_amount

amount to withdraw.

outputs0uint256
function

withdrawRewardTotal f6b003e5

Withdraw accumulated reward of a specified rewards asset. * Withdrawal is made for caller and total amount.

inputs0address_asset

registered rewards asset contract address.

outputs0uint256
function

withdrawnTokens d8f9659b

inputs0address[]tokens
inputs1address_to