trustlines-protocol / contracts

Smart contracts for the Trustlines Protocol
https://trustlines.network/
Other
26 stars 6 forks source link

CurrencyNetwork Protocol #1

Closed ice09 closed 6 years ago

ice09 commented 7 years ago

The CurrencyNetwork Protocol contract provides the main functionality of the Trustlines network. It stores all Trustlines between users and implements multi-hop transfers, which allow for transfers rippling through the Trustlines network between users not knowing each other (but through a path of friends).

The CurrencyNetwork in its final state will be upgradeable, so that inevitable bugs can be fixed. The storage has to stay though all updates in the lifecycle of the CurrencyNetwork.

API

.init
.transfer(to, value,    via_obj)
.transferFrom(from, to, value, via_obj)         
.approve(spender, value)        
.allowance(owner, spender)                  
.updateCreditLine(receiver, creditlimit, interestrate, governance_address)          
.acceptCreditLine(hash)                     
.cashCheque(signed_message, via_obj)                    
.prepareTransfer(from, to, amount or via_obj)   

via_obj:    [max_fee, [hops, ]]

Events

event Approval(address _owner, address _spender, uint256 _value);
event Transfer(address _from, address _to, uint _value);
event CreditlineUpdateRequest(address _creditor, address _debtor, uint32 _value);
event CreditlineUpdate(address _creditor, address _debtor, uint32 _value); 
event PathPrepared(address _sender, address _receiver, uint32 _value);
// must be deactivated due to gas costs
event BalanceUpdate(address _from, address _to, int256 _value);

functions

prepare

Prepare a path between two UserAccounts, msg.sender and _to. This path is valid one day after preparation. The path is calculated by a system of federated relay servers off-chain.

prepareFrom

NOTE: check if necessary to support this function

Prepare a path between two UserAccounts, _from and _to. This path is valid one day after preparation. The path is calculated by a system of federated relay servers off-chain.

cashCheque

Create a Cheque which is signed by UserAccount _from and can be redeemed by _to. The Cheque has an expiry date which is set in _expiresOn. These values are hashed and must be signed by _from.

transfer (with prepared Path)

Transfer amount value of CurrencyNetwork currency to recipient _to. This transfer is not a direct transfer of msg.sender to _to, but uses the a prepared path which exists from msg.sender to recipient _to in the CurrencyNetwork.

NOTE: A Path has to be prepared before this method can be used.

transfer (including pre-calculated path)

Transfer amount value of CurrencyNetwork currency to recipient _to, with maxFee maximum fees and using the submitted pre-calulated path.

NOTE: A Path has to be prepared before this method can be used.

function logic

internal function _transfer

Internal function which does the actual transfer of the currency value for 1 hop (from _sender to _receiver).

NOTE: A Trustline must exist between the two addresses.

function logic

transferFrom (with prepared Path)

Transfer amount value of CurrencyNetwork currency from sender _from to recipient _to. This transfer is not a direct transfer of msg.sender to _to, but uses the a prepared path which exists from msg.sender to recipient _to in the CurrencyNetwork.

NOTE: A Path has to be prepared before this method can be used.

updateCreditline

with modifier: notSender(_debtor): no self update possible

The msg.sender (the creditor) wants to update the Creditline with the debtor. This function only stores the request for the Creditline update. The key for the request proposal is msg.sender, debtor, value. For this (sha3) value the current date is stored. The debtor has to accept the Creditline update by calling acceptCreditline.

acceptCreditline

The msg.sender (the debtor) wants to accept the Creditline update request by _creditor.

function logic

Subtask

ice09 commented 7 years ago

moved to description.

berndbohmeier commented 6 years ago

outdated, closed and new issues are pen for the missing features