evm-booking

EVM smart contract for ERC20 backed time slot booking
Info | Log | Files | Refs | README

contract.texi (2100B)


      1 @chapter Smart contract
      2 
      3 When the smart contract is published, it is bound to:
      4 
      5 @itemize
      6 @item The ERC20 token that will be used to spend serial units.
      7 @item The amount of serial units.
      8 @item Timestamp until when serial units can be reserved and spent.
      9 @end itemize
     10 
     11 The supply of the ERC20 token will be read and stored, and used to calculate shares for collective use.
     12 
     13 @strong{The supply of the ERC20 token must not change after binding it to the contract}.
     14 
     15 
     16 @section Interface
     17 
     18 The contract interface consists of three main methods.
     19 
     20 @table @code
     21 @item consume
     22 Will spend serial units in the contract, and invoke @code{ERC20.transferFrom} to cover those units.
     23 @item share
     24 Reserve serial units for collective use. Requires all token holders to collectively deposit a corresponding share of the total supply. 
     25 @item deposit(For)
     26 Manually synchronise deposits to cover the time currently reserved for collective use.
     27 @end table
     28 
     29 
     30 @section Expiration
     31 
     32 After expiration, the shares of the collective use are considered finalized, and can be read out from the contract.
     33 
     34 
     35 @section Raw output
     36 
     37 The @code{raw} method returns the bit field representing the state of individual serial slots.
     38 
     39 
     40 @subsection Example
     41 
     42 Let the total of time slots be 50.
     43 
     44 Slots (inclusive, zero-indexed) 13-30 have been @emph{spent} (@code{consume}) and 249-255 have been @emph{reserved} (@code{share}).
     45 
     46 Calling @code{raw(11, 257)} will yield a virtual bit field (lowest index left) as follows:
     47 
     48 @verbatim
     49 00111111 11111111 11110000 00000000 (bytes 0-4)
     50 [...]
     51 00000000 00000011 11111000 00000000 (bytes 28-31)
     52 0 (bit 257)
     53 @end verbatim
     54 
     55 The ABI encoded return value will be, grouped by word:
     56 
     57 @verbatim
     58 0000000000000000000000000000000000000000000000000000000000000020
     59 0000000000000000000000000000000000000000000000000000000000000021
     60 008f300000000000000000000000000000000000000000ffffffffffffffff3f
     61 0000000000000000000000000000000000000000000000000000000000000000
     62 @end verbatim
     63 
     64 The bit field is read word for word, then byte-for-byte from right to left.
     65 
     66 Note how it merges both the @emph{spent} and @emph{reserved} slots.