diff --git a/README.md b/README.md index e66c803..1c2b039 100644 --- a/README.md +++ b/README.md @@ -14,29 +14,26 @@ - Then the resulting balances after one tax period of those two trading would be 1080 Sarafu while the remaining non-active users would be 980 Sarafu. If this behaviour continued in the next tax period, with the same two users only trading (with no net balance changes), they would have 1158.39999968 Sarafu and those users that are not trading would have their balances further reduced to 960.40 Sarafu. If this continued on ~forever those two active trading users would have the entire token supply and the non-trading users would eventually reach a zero balance. - this example calculation for 3 tax periods can be found here: https://gitlab.com/grassrootseconomics/cic-docs/-/blob/master/demurrage-redist-sarafu.ods +## Nomenclature -## Variables - -* Inputs to Constructor (Set only once during contract deployment can't be changed ) - * `Demurrage` aka Decay amount: A percentage of token supply that will be charged once per minute and evenly redistributed to _active_ users every Demurrage Period (minutes) - * Demurrage Period (minutes)- aka `period`: The number of minutes over which a user must be _active_ to receive tax-redistibution. - * Inflated Balance: The inflated balance of each user is stored for bookkeeping. - * Number of Decimals: Resolution on token (TODO) (Default 6) - * Minimum Activity Volume: (TODO) the minimum transaction amount to be considered active - * Sink Token Address: Rounding errors and if no one trades the tax goes to this address +* `Demurrage` aka Decay amount: A percentage of token supply that will be charged once per minute and evenly redistributed to _active_ users every Demurrage Period (minutes) +* Base balance: The inflated balance of each user is stored for bookkeeping. +* Sink Token Address: Rounding errors and if no one trades the tax goes to this address +* Demurrage Period (minutes)- aka `period`: The number of minutes over which a user must be _active_ to receive tax-redistibution. ## Ownership * Contract creator is owner -* Ownership can be transferred (also to ownership void contract "no more changes can be made") +* Ownership can be transferred ## Mint -* Owner can add minters +* Owner can add minters and remove - A faucet contract would be a minter and choose the amount of tokens to mint and distribute to new _validated_ users. - The interface says the amount and is at the caller's discretion per contract call. _validation_ is outside of this contract. +* A minter can remove itself * Minters can mint any amount @@ -49,7 +46,6 @@ - e.g. a `demurrage` after the 2nd minute would be give a `demurrageModifier = (1-0.02)^2 = 0.9604`. * All client-facing values (_balance output_ , _transfer inputs_) are adjusted with `demurrageModifier`. - e.g. `_balance output_ = user_balance - user_balance * demurrageModifier` -* Edge case: `approve` call, which may be called on either side of a period. ## Redistribution @@ -62,27 +58,39 @@ - Check if user has participated in `period`. (_active_ user heartbeat) - Each _active_ user balance in the `period` is increased by `(total supply at end of period * demurrageModifier ) / number_of_active_participants` via minting - Participation field is zeroed out for that user. -* Fractions must be rounded down (TODO) - - Remainder is "dust" and should be sent to a dedicated "sink" token address (TODO) - - If no one is _active_ all taxes go to the same sink address +* Fractions must be rounded down + - Remainder is "dust" and should be sent to a dedicated Sink Token Address. + - If no one is _active_ all taxes go to the Sink Token Address. ## Data structures -* One word per account: - - bits 000-159: value - - bits 160-255: period - - (we have more room here in case we want to cram something else in) -* One word per redistribution period: - - bits 000-055: period - - bits 056-215: supply - - bits 216-253: participant count - - bits 254: Set if individual redistribution amounts are fractions (TODO) - - bits 255: Set if "dust" has been transferred to sink (TODO) +* One word per `account`: + - bits 000-071: value + - bits 072-103: period + - bits 104-255: (Unused) +* One word per `redistributions` period: + - bits 000-031: period + - bits 032-103: supply + - bits 104-139: participant count + - bits 140-159: demurrage modifier + - bits 160-254: (Unused) + - bits 255: Set if individual redistribution amounts are fractions +* One word for the `demurrageModifier` (should be replaced with 2 x uint128 instead): + - bits 000-127: Accumulated demurrage modifier from last calculation + - bits 128-255: Period of last calculated demurrage modifier + +### Notes + +Accumulated demurrage modifier in `demurrageModifier` is 128 bit, but will be _truncated_ do 20 bits in `redistributions`. The 128 bit resolution is to used to reduce the impact of fractional drift of the long-term accumulation of the demurrage modifier. However, the demurrage snapshot values used in `redistributions` are parts-per-million and can be fully contained within a 20-bit value. ## QA * Basic python tests in place -* How to determine and generate test vectors, and how to adapt them to scripts. +* How to determine and generate sufficient test vectors, and how to adapt them to scripts. * Audit sources? + +## Known issues + +* A `transferFrom` following an `approve` call, when called across period thresholds, may fail if margin to demurraged amount is insufficient. diff --git a/python/sarafu_token/data/RedistributedDemurrageToken.bin b/python/sarafu_token/data/RedistributedDemurrageToken.bin index c47baf9..c9df816 100644 --- a/python/sarafu_token/data/RedistributedDemurrageToken.bin +++ b/python/sarafu_token/data/RedistributedDemurrageToken.bin @@ -1 +1 @@ -60e06040523480156200001157600080fd5b50604051620033c2380380620033c2833981810160405281019062000037919062000416565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506001600960008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055504260808181525050603c82620001079190620006dd565b60a08181525050856001908051906020019062000126929190620002af565b5084600290805190602001906200013f929190620002af565b508360ff16600381905550620f42406d04ee2d6d415b85acef8100000000620001699190620006dd565b6006819055507001000000000000000000000000000000006006600082825417925050819055508260c0818152505080600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000620001fe6000620f4240600060016200024e640100000000026401000000009004565b905060078190806001815401808255809150506001900390600052602060002001600090919091909150558460ff16600a6200023b9190620005a0565b60058190555050505050505050620008dd565b600080608c620fffff86169060020a02600102811790506068640fffffffff87169060020a0260010281179050602068ffffffffffffffffff85169060020a026001028117905063ffffffff83166001028117905080915050949350505050565b828054620002bd90620007bf565b90600052602060002090601f016020900481019282620002e157600085556200032d565b82601f10620002fc57805160ff19168380011785556200032d565b828001600101855582156200032d579182015b828111156200032c5782518255916020019190600101906200030f565b5b5090506200033c919062000340565b5090565b5b808211156200035b57600081600090555060010162000341565b5090565b600062000376620003708462000512565b620004de565b9050828152602081018484840111156200038f57600080fd5b6200039c84828562000789565b509392505050565b600081519050620003b5816200088f565b92915050565b600082601f830112620003cd57600080fd5b8151620003df8482602086016200035f565b91505092915050565b600081519050620003f981620008a9565b92915050565b6000815190506200041081620008c3565b92915050565b60008060008060008060c087890312156200043057600080fd5b600087015167ffffffffffffffff8111156200044b57600080fd5b6200045989828a01620003bb565b965050602087015167ffffffffffffffff8111156200047757600080fd5b6200048589828a01620003bb565b95505060406200049889828a01620003ff565b9450506060620004ab89828a01620003e8565b9350506080620004be89828a01620003e8565b92505060a0620004d189828a01620003a4565b9150509295509295509295565b6000604051905081810181811067ffffffffffffffff8211171562000508576200050762000853565b5b8060405250919050565b600067ffffffffffffffff82111562000530576200052f62000853565b5b601f19601f8301169050602081019050919050565b6000808291508390505b600185111562000597578086048111156200056f576200056e620007f5565b5b60018516156200057f5780820291505b80810290506200058f8562000882565b94506200054f565b94509492505050565b6000620005ad8262000772565b9150620005ba8362000772565b9250620005e97fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8484620005f1565b905092915050565b600082620006035760019050620006d6565b81620006135760009050620006d6565b81600181146200062c576002811462000637576200066d565b6001915050620006d6565b60ff8411156200064c576200064b620007f5565b5b8360020a915084821115620006665762000665620007f5565b5b50620006d6565b5060208310610133831016604e8410600b8410161715620006a75782820a905083811115620006a157620006a0620007f5565b5b620006d6565b620006b6848484600162000545565b92509050818404811115620006d057620006cf620007f5565b5b81810290505b9392505050565b6000620006ea8262000772565b9150620006f78362000772565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615620007335762000732620007f5565b5b828202905092915050565b60006200074b8262000752565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b83811015620007a95780820151818401526020810190506200078c565b83811115620007b9576000848401525b50505050565b60006002820490506001821680620007d857607f821691505b60208210811415620007ef57620007ee62000824565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000600282049050919050565b6200089a816200073e565b8114620008a657600080fd5b50565b620008b48162000772565b8114620008c057600080fd5b50565b620008ce816200077c565b8114620008da57600080fd5b50565b60805160a05160c051612a766200094c60003960008181610a1401528181610b7c01528181610cfb015281816116e701528181611cfc0152611d34015260008181610f98015281816116410152611782015260008181610fc4015281816117a301526117e80152612a766000f3fe608060405234801561001057600080fd5b506004361061022e576000357c0100000000000000000000000000000000000000000000000000000000900480636d5055a611610142578063a9059cbb116100ca578063e3ab207a11610099578063e3ab207a1461070d578063e54d63f71461073d578063e80952951461076d578063eda4e6d61461078b578063fc958aed146107a95761022e565b8063a9059cbb1461065f578063b470aade1461068f578063bf4c16f1146106ad578063d2ae3991146106dd5761022e565b80638da5cb5b116101115780638da5cb5b146105a55780638f1df6bc146105c357806395d89b41146105e1578063983b2d56146105ff5780639da7d8ba1461062f5761022e565b80636d5055a6146104f75780636ffa8a051461052757806370a0823114610557578063731f237c146105875761022e565b8063313ce567116101c5578063449a52f811610194578063449a52f8146104195780634abfbba214610449578063573cc507146104795780636787a9be146104975780636a2d094e146104c75761022e565b8063313ce5671461036b57806335b16eb81461038957806340452d91146103b957806340fc89f5146103e95761022e565b8063216ea5ec11610201578063216ea5ec146102bd578063229ba197146102ed57806323b872dd1461030b578063313334871461033b5761022e565b806306fdde0314610233578063095ea7b31461025157806318160ddd146102815780631989c6a81461029f575b600080fd5b61023b6107c7565b604051610248919061268f565b60405180910390f35b61026b60048036038101906102669190612416565b610855565b6040516102789190612659565b60405180910390f35b610289610979565b6040516102969190612711565b60405180910390f35b6102a761097f565b6040516102b49190612711565b60405180910390f35b6102d760048036038101906102d291906124cd565b61098c565b6040516102e49190612711565b60405180910390f35b6102f5610a12565b6040516103029190612711565b60405180910390f35b610325600480360381019061032091906123c7565b610a36565b6040516103329190612659565b60405180910390f35b610355600480360381019061035091906124cd565b610b60565b6040516103629190612711565b60405180910390f35b610373610c11565b6040516103809190612711565b60405180910390f35b6103a3600480360381019061039e919061239e565b610c17565b6040516103b09190612659565b60405180910390f35b6103d360048036038101906103ce919061247b565b610e3d565b6040516103e09190612674565b60405180910390f35b61040360048036038101906103fe9190612452565b610e61565b6040516104109190612711565b60405180910390f35b610433600480360381019061042e9190612416565b610e92565b6040516104409190612659565b60405180910390f35b610463600480360381019061045e919061247b565b610f94565b6040516104709190612711565b60405180910390f35b610481610ff4565b60405161048e9190612711565b60405180910390f35b6104b160048036038101906104ac919061247b565b610ffa565b6040516104be9190612711565b60405180910390f35b6104e160048036038101906104dc919061247b565b611040565b6040516104ee9190612711565b60405180910390f35b610511600480360381019061050c919061239e565b611061565b60405161051e9190612711565b60405180910390f35b610541600480360381019061053c9190612452565b6110c9565b60405161054e9190612711565b60405180910390f35b610571600480360381019061056c919061239e565b6110fc565b60405161057e9190612711565b60405180910390f35b61058f611194565b60405161059c9190612659565b60405180910390f35b6105ad611274565b6040516105ba919061263e565b60405180910390f35b6105cb611298565b6040516105d89190612659565b60405180910390f35b6105e9611429565b6040516105f6919061268f565b60405180910390f35b6106196004803603810190610614919061239e565b6114b7565b6040516106269190612659565b60405180910390f35b61064960048036038101906106449190612452565b611573565b6040516106569190612711565b60405180910390f35b61067960048036038101906106749190612416565b61159f565b6040516106869190612659565b60405180910390f35b61069761163f565b6040516106a49190612711565b60405180910390f35b6106c760048036038101906106c2919061247b565b611663565b6040516106d49190612711565b60405180910390f35b6106f760048036038101906106f2919061247b565b61167f565b6040516107049190612711565b60405180910390f35b61072760048036038101906107229190612452565b6116b7565b6040516107349190612711565b60405180910390f35b610757600480360381019061075291906124cd565b6116cb565b6040516107649190612711565b60405180910390f35b61077561177c565b6040516107829190612711565b60405180910390f35b6107936117e6565b6040516107a09190612711565b60405180910390f35b6107b161180a565b6040516107be9190612711565b60405180910390f35b600180546107d4906128e2565b80601f0160208091040260200160405190810160405280929190818152602001828054610800906128e2565b801561084d5780601f106108225761010080835404028352916020019161084d565b820191906000526020600020905b81548152906001019060200180831161083057829003601f168201915b505050505081565b600080610860611298565b5061086a33610c17565b5061087483610ffa565b905080600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546109029190612748565b925050819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040516109669190612711565b60405180910390a3600191505092915050565b60045481565b6000600780549050905090565b6000806000808514156109d4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109cb906126b1565b60405180910390fd5b8385106109e057600080fd5b84846109ec919061279e565b915084826109fa91906127cf565b90508084610a089190612829565b9250505092915050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000806000610a43611298565b50610a4d33610c17565b50610a5784610ffa565b915081600a60008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610ae257600080fd5b610aed868684611810565b90508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef86604051610b4c9190612711565b60405180910390a380925050509392505050565b6000806000620f424091506d04ee2d6d415b85acef81000000007f0000000000000000000000000000000000000000000000000000000000000000610ba5919061279e565b905060005b84811015610bec57620f42408284610bc291906127cf565b610bcc919061279e565b83610bd79190612829565b92508080610be490612914565b915050610baa565b50620f42408583610bfd91906127cf565b610c07919061279e565b9250505092915050565b60035481565b600080600080600080600080610c2c89611061565b91506000821480610c445750610c4061177c565b8210155b15610c59576000975050505050505050610e38565b6007600183610c689190612829565b81548110610c9f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549650610cb587610e61565b94506000851415610cd0576000975050505050505050610e38565b610cd987611573565b9550610ce4876110c9565b90506d04ee2d6d415b85acef8100000000620f42407f0000000000000000000000000000000000000000000000000000000000000000610d24919061279e565b8688610d30919061279e565b610d3a91906127cf565b610d44919061279e565b9350620f42408185610d5691906127cf565b610d60919061279e565b92507fffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffffff600102600860008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282541692505081905550610ddc89846118a2565b50818973ffffffffffffffffffffffffffffffffffffffff167f9a2a887706623ad3ff7fc85652deeceabe9fe1e00466c597972079ee91ea40d385604051610e249190612711565b60405180910390a360019750505050505050505b919050565b60078181548110610e4d57600080fd5b906000526020600020016000915090505481565b60006068710fffffffff00000000000000000000000000600102831660019004908060020a82049150509050919050565b600080600960003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610eeb57600080fd5b610ef3611298565b508290508260046000828254610f099190612748565b92505081905550610f1a84826118a2565b508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fab8530f87dc9b59234c4623bf917212bb2536d647574c8e7e5da92c2ede0c9f885604051610f789190612711565b60405180910390a3610f88611a14565b50600191505092915050565b60007f000000000000000000000000000000000000000000000000000000000000000082610fc291906127cf565b7f0000000000000000000000000000000000000000000000000000000000000000610fed9190612748565b9050919050565b60055481565b6000611007600654611663565b620f42406d04ee2d6d415b85acef81000000008461102591906127cf565b61102f91906127cf565b611039919061279e565b9050919050565b6000603c82426110509190612829565b61105a919061279e565b9050919050565b600060486cffffffff000000000000000000600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546001900416908060020a82049150509050919050565b6000608c73fffff00000000000000000000000000000000000600102831660019004908060020a82049150509050919050565b60008060008060008061110e87611b0b565b945061111b600654611663565b935061112860065461167f565b925061113560065461167f565b61113d61177c565b6111479190612829565b90506111538482610b60565b9150620f42406d04ee2d6d415b85acef810000000061117291906127cf565b828661117e91906127cf565b611188919061279e565b95505050505050919050565b60008060008060006111a461177c565b93506111b160065461167f565b846111bc9190612829565b925060008314156111d4576000945050505050611271565b6111df600654611663565b91506111eb8284610b60565b905060006006819055506fffffffffffffffffffffffffffffffff81166006600082825417925050819055506080849060020a026006600082825417925050819055508183857fa0717e54e02bd9829db5e6e998aec0ae9de796b8d150a3cc46a92ab869697755846040516112609190612711565b60405180910390a460019450505050505b90565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008060008060008060008060008060006112b1611b63565b995060006001028a14156112d25760009a5050505050505050505050611426565b6112db8a6116b7565b97506001886112ea9190612748565b90506112f588610f94565b91506112ff611194565b5061130b600654611663565b945061131682611040565b9250600083111561134b576d04ee2d6d415b85acef810000000061133a86856116cb565b611344919061279e565b9350611368565b6d04ee2d6d415b85acef810000000085611365919061279e565b93505b61137760008560045484611c82565b985060078990806001815401808255809150506001900390600052602060002001600090919091909150556113ab8a610e61565b965060008714156113c6576113bf8a611ce3565b95506113e0565b6113d28760045461098c565b95506113de8689611ed6565b505b7f55d243082e019fce4009ccea5368b92e436c17586a1e793c7deda16df4e5d6758160405161140f9190612711565b60405180910390a160019a50505050505050505050505b90565b60028054611436906128e2565b80601f0160208091040260200160405190810160405280929190818152602001828054611462906128e2565b80156114af5780601f10611484576101008083540402835291602001916114af565b820191906000526020600020905b81548152906001019060200180831161149257829003601f168201915b505050505081565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461151257600080fd5b6001600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b600060206cffffffffffffffffff00000000600102831660019004908060020a82049150509050919050565b60008060006115ac611298565b506115b633610c17565b506115c084610ffa565b91506115cd338684611810565b90508473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8660405161162c9190612711565b60405180910390a3809250505092915050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60006fffffffffffffffffffffffffffffffff82169050919050565b600060807fffffffffffffffffffffffffffffffff000000000000000000000000000000008316908060020a82049150509050919050565b600063ffffffff8260019004169050919050565b6000806000620f424091506d04ee2d6d415b85acef81000000007f0000000000000000000000000000000000000000000000000000000000000000611710919061279e565b905060005b8481101561175757620f4240828461172d91906127cf565b611737919061279e565b836117429190612748565b9250808061174f90612914565b915050611715565b50620f4240858361176891906127cf565b611772919061279e565b9250505092915050565b600060017f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000426117cd9190612829565b6117d7919061279e565b6117e19190612748565b905090565b7f000000000000000000000000000000000000000000000000000000000000000081565b60065481565b60008061181d858461200c565b5061182884846118a2565b5061183161177c565b9050600554831015801561184d57508061184a86611061565b14155b801561188557508373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614155b15611896576118948582612153565b505b60019150509392505050565b600080600080600860008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460019004905060008514156119035760009350505050611a0e565b61190c86611b0b565b9250848361191a9190612748565b91508273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161161198a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611981906126f1565b60405180910390fd5b7f0fffffffffffffffffffffffffffffffffffffffffffff0000000000000000008116905068ffffffffffffffffff82168117905080600102600860008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600193505050505b92915050565b60008060076001600780549050611a2b9190612829565b81548110611a62577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001546001900490507fffffffffffffffffffffffffffffffffffffff000000000000000000ffffffff8116905060206004549060020a02811790508060010260076001600780549050611abe9190612829565b81548110611af5577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200181905550600191505090565b600068ffffffffffffffffff600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460019004169050919050565b600080600060076001600780549050611b7c9190612829565b81548110611bb3577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020015491503073ffffffffffffffffffffffffffffffffffffffff1663e80952956040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b158015611c2257600080fd5b505afa158015611c36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c5a91906124a4565b9050611c65826116b7565b8111611c7957600060010292505050611c7f565b81925050505b90565b600080608c620fffff86169060020a02600102811790506068640fffffffff87169060020a0260010281179050602068ffffffffffffffffff85169060020a026001028117905063ffffffff83166001028117905080915050949350505050565b6000806000806000611cf486611573565b9350620f42407f000000000000000000000000000000000000000000000000000000000000000085611d2691906127cf565b611d30919061279e565b91507f0000000000000000000000000000000000000000000000000000000000000000620f424083611d6291906127cf565b611d6c919061279e565b905083811015611e8457611d7f866116b7565b92507ffffffffffffffffffffffffffffff000000000ffffffffffffffffffffffffff6001026007600185611db49190612829565b81548110611deb577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001600082825416925050819055507f80000000000000000000000000000000000001000000000000000000000000006001026007600185611e359190612829565b81548110611e6c577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001600082825417925050819055505b611ec9600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166d04ee2d6d415b85acef810000000084611ec4919061279e565b6118a2565b5081945050505050919050565b6000806000841415611eec576000915050612006565b7f80000000000000000000000000000000000000000000000000000000000000006001026007600185611f1f9190612829565b81548110611f56577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160008282541792505081905550611fc66007600185611f7f9190612829565b81548110611fb6577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154611573565b9050611fff600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168583611ffa9190612829565b6118a2565b5060019150505b92915050565b600080600080600860008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054600190049050600085141561206d576000935050505061214d565b61207686611b0b565b9250848310156120bb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120b2906126d1565b60405180910390fd5b84836120c79190612829565b91507f0fffffffffffffffffffffffffffffffffffffffffffff0000000000000000008116905068ffffffffffffffffff82168117905080600102600860008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600193505050505b92915050565b60007fffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffffff600102600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825416925050819055506048829060020a02600102600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254179250508190555061222461222f565b506001905092915050565b600080600080600760016007805490506122499190612829565b81548110612280577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549250600161229884610e61565b6122a29190612748565b9050826001900491507ffffffffffffffffffffffffffffff000000000ffffffffffffffffffffffffff821691506068640fffffffff82169060020a028217915081600102600760016007805490506122fb9190612829565b81548110612332577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001819055506001935050505090565b600081359050612359816129fb565b92915050565b60008135905061236e81612a12565b92915050565b60008135905061238381612a29565b92915050565b60008151905061239881612a29565b92915050565b6000602082840312156123b057600080fd5b60006123be8482850161234a565b91505092915050565b6000806000606084860312156123dc57600080fd5b60006123ea8682870161234a565b93505060206123fb8682870161234a565b925050604061240c86828701612374565b9150509250925092565b6000806040838503121561242957600080fd5b60006124378582860161234a565b925050602061244885828601612374565b9150509250929050565b60006020828403121561246457600080fd5b60006124728482850161235f565b91505092915050565b60006020828403121561248d57600080fd5b600061249b84828501612374565b91505092915050565b6000602082840312156124b657600080fd5b60006124c484828501612389565b91505092915050565b600080604083850312156124e057600080fd5b60006124ee85828601612374565b92505060206124ff85828601612374565b9150509250929050565b6125128161285d565b82525050565b6125218161286f565b82525050565b6125308161287b565b82525050565b60006125418261272c565b61254b8185612737565b935061255b8185602086016128af565b612564816129ea565b840191505092915050565b600061257c601183612737565b91507f4552525f4e554d50415254535f5a45524f0000000000000000000000000000006000830152602082019050919050565b60006125bc600d83612737565b91507f4552525f4f5645525350454e44000000000000000000000000000000000000006000830152602082019050919050565b60006125fc600d83612737565b91507f4552525f574f554c4457524150000000000000000000000000000000000000006000830152602082019050919050565b612638816128a5565b82525050565b60006020820190506126536000830184612509565b92915050565b600060208201905061266e6000830184612518565b92915050565b60006020820190506126896000830184612527565b92915050565b600060208201905081810360008301526126a98184612536565b905092915050565b600060208201905081810360008301526126ca8161256f565b9050919050565b600060208201905081810360008301526126ea816125af565b9050919050565b6000602082019050818103600083015261270a816125ef565b9050919050565b6000602082019050612726600083018461262f565b92915050565b600081519050919050565b600082825260208201905092915050565b6000612753826128a5565b915061275e836128a5565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156127935761279261295d565b5b828201905092915050565b60006127a9826128a5565b91506127b4836128a5565b9250826127c4576127c361298c565b5b828204905092915050565b60006127da826128a5565b91506127e5836128a5565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561281e5761281d61295d565b5b828202905092915050565b6000612834826128a5565b915061283f836128a5565b9250828210156128525761285161295d565b5b828203905092915050565b600061286882612885565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b838110156128cd5780820151818401526020810190506128b2565b838111156128dc576000848401525b50505050565b600060028204905060018216806128fa57607f821691505b6020821081141561290e5761290d6129bb565b5b50919050565b600061291f826128a5565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156129525761295161295d565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b612a048161285d565b8114612a0f57600080fd5b50565b612a1b8161287b565b8114612a2657600080fd5b50565b612a32816128a5565b8114612a3d57600080fd5b5056fea264697066735822122012e9ed085ca83069d0ec935bb2fb378e48d4b9e93ce05314108c6fc2f5f7814b64736f6c63430008000033 \ No newline at end of file +60e06040523480156200001157600080fd5b506040516200356538038062003565833981810160405281019062000037919062000443565b33600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600160096000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555085600490805190602001906200010a929190620002dc565b50846005908051906020019062000123929190620002dc565b508360ff166006819055504260808181525050603c826200014591906200070a565b60a08181525050620f42406d04ee2d6d415b85acef81000000006200016b91906200070a565b6002819055507001000000000000000000000000000000006002600082825417925050819055508260c081815250506000620001bf6000620f42406000600162000250640100000000026401000000009004565b9050600081908060018154018082558091505060019003906000526020600020016000909190919091505581600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508460ff16600a6200023d9190620005cd565b600881905550505050505050506200090a565b60008073fffff00000000000000000000000000000000000608c60ff16869060020a021660010281179050710fffffffff00000000000000000000000000606860ff16879060020a0216600102811790506cffffffffffffffffff00000000602060ff16859060020a02166001028117905063ffffffff83166001028117905080915050949350505050565b828054620002ea90620007ec565b90600052602060002090601f0160209004810192826200030e57600085556200035a565b82601f106200032957805160ff19168380011785556200035a565b828001600101855582156200035a579182015b82811115620003595782518255916020019190600101906200033c565b5b5090506200036991906200036d565b5090565b5b80821115620003885760008160009055506001016200036e565b5090565b6000620003a36200039d846200053f565b6200050b565b905082815260208101848484011115620003bc57600080fd5b620003c9848285620007b6565b509392505050565b600081519050620003e281620008bc565b92915050565b600082601f830112620003fa57600080fd5b81516200040c8482602086016200038c565b91505092915050565b6000815190506200042681620008d6565b92915050565b6000815190506200043d81620008f0565b92915050565b60008060008060008060c087890312156200045d57600080fd5b600087015167ffffffffffffffff8111156200047857600080fd5b6200048689828a01620003e8565b965050602087015167ffffffffffffffff811115620004a457600080fd5b620004b289828a01620003e8565b9550506040620004c589828a016200042c565b9450506060620004d889828a0162000415565b9350506080620004eb89828a0162000415565b92505060a0620004fe89828a01620003d1565b9150509295509295509295565b6000604051905081810181811067ffffffffffffffff8211171562000535576200053462000880565b5b8060405250919050565b600067ffffffffffffffff8211156200055d576200055c62000880565b5b601f19601f8301169050602081019050919050565b6000808291508390505b6001851115620005c4578086048111156200059c576200059b62000822565b5b6001851615620005ac5780820291505b8081029050620005bc85620008af565b94506200057c565b94509492505050565b6000620005da826200079f565b9150620005e7836200079f565b9250620006167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84846200061e565b905092915050565b60008262000630576001905062000703565b8162000640576000905062000703565b816001811462000659576002811462000664576200069a565b600191505062000703565b60ff84111562000679576200067862000822565b5b8360020a91508482111562000693576200069262000822565b5b5062000703565b5060208310610133831016604e8410600b8410161715620006d45782820a905083811115620006ce57620006cd62000822565b5b62000703565b620006e3848484600162000572565b92509050818404811115620006fd57620006fc62000822565b5b81810290505b9392505050565b600062000717826200079f565b915062000724836200079f565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161562000760576200075f62000822565b5b828202905092915050565b600062000778826200077f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b83811015620007d6578082015181840152602081019050620007b9565b83811115620007e6576000848401525b50505050565b600060028204905060018216806200080557607f821691505b602082108114156200081c576200081b62000851565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000600282049050919050565b620008c7816200076b565b8114620008d357600080fd5b50565b620008e1816200079f565b8114620008ed57600080fd5b50565b620008fb81620007a9565b81146200090757600080fd5b50565b60805160a05160c051612bec6200097960003960008181610a8901528181610ce401528181610e63015281816118c301528181611e850152611ebd0152600081816111460152818161181a015261195e0152600081816111720152818161197f01526119c40152612bec6000f3fe608060405234801561001057600080fd5b5060043610610244576000357c0100000000000000000000000000000000000000000000000000000000900480636a2d094e1161014d5780639da7d8ba116100d5578063e3ab207a11610099578063e3ab207a14610783578063e54d63f7146107b3578063e8095295146107e3578063eda4e6d614610801578063fc958aed1461081f57610244565b80639da7d8ba146106a5578063a9059cbb146106d5578063b470aade14610705578063bf4c16f114610723578063d2ae39911461075357610244565b8063731f237c1161011c578063731f237c146105fd5780638da5cb5b1461061b5780638f1df6bc1461063957806395d89b4114610657578063983b2d561461067557610244565b80636a2d094e1461053d5780636d5055a61461056d5780636ffa8a051461059d57806370a08231146105cd57610244565b8063313ce567116101d0578063449a52f81161019f578063449a52f81461045f57806347a505171461048f5780634abfbba2146104bf578063573cc507146104ef5780636787a9be1461050d57610244565b8063313ce567146103b157806335b16eb8146103cf57806340452d91146103ff57806340fc89f51461042f57610244565b8063216ea5ec11610217578063216ea5ec146102d3578063229ba1971461030357806323b872dd146103215780633092afd514610351578063313334871461038157610244565b806306fdde0314610249578063095ea7b31461026757806318160ddd146102975780631989c6a8146102b5575b600080fd5b61025161083d565b60405161025e9190612805565b60405180910390f35b610281600480360381019061027c919061258c565b6108cb565b60405161028e91906127cf565b60405180910390f35b61029f6109ef565b6040516102ac9190612887565b60405180910390f35b6102bd6109f5565b6040516102ca9190612887565b60405180910390f35b6102ed60048036038101906102e89190612643565b610a01565b6040516102fa9190612887565b60405180910390f35b61030b610a87565b6040516103189190612887565b60405180910390f35b61033b6004803603810190610336919061253d565b610aab565b60405161034891906127cf565b60405180910390f35b61036b60048036038101906103669190612514565b610bd5565b60405161037891906127cf565b60405180910390f35b61039b60048036038101906103969190612643565b610cc8565b6040516103a89190612887565b60405180910390f35b6103b9610d79565b6040516103c69190612887565b60405180910390f35b6103e960048036038101906103e49190612514565b610d7f565b6040516103f691906127cf565b60405180910390f35b610419600480360381019061041491906125f1565b610f93565b60405161042691906127ea565b60405180910390f35b610449600480360381019061044491906125c8565b610fb7565b6040516104569190612887565b60405180910390f35b6104796004803603810190610474919061258c565b610fe8565b60405161048691906127cf565b60405180910390f35b6104a960048036038101906104a49190612514565b6110ea565b6040516104b69190612887565b60405180910390f35b6104d960048036038101906104d491906125f1565b611142565b6040516104e69190612887565b60405180910390f35b6104f76111a2565b6040516105049190612887565b60405180910390f35b610527600480360381019061052291906125f1565b6111a8565b6040516105349190612887565b60405180910390f35b610557600480360381019061055291906125f1565b6111ee565b6040516105649190612887565b60405180910390f35b61058760048036038101906105829190612514565b61120f565b6040516105949190612887565b60405180910390f35b6105b760048036038101906105b291906125c8565b61127a565b6040516105c49190612887565b60405180910390f35b6105e760048036038101906105e29190612514565b6112ad565b6040516105f49190612887565b60405180910390f35b610605611345565b60405161061291906127cf565b60405180910390f35b61062361144a565b60405161063091906127b4565b60405180910390f35b610641611470565b60405161064e91906127cf565b60405180910390f35b61065f611601565b60405161066c9190612805565b60405180910390f35b61068f600480360381019061068a9190612514565b61168f565b60405161069c91906127cf565b60405180910390f35b6106bf60048036038101906106ba91906125c8565b61174c565b6040516106cc9190612887565b60405180910390f35b6106ef60048036038101906106ea919061258c565b611778565b6040516106fc91906127cf565b60405180910390f35b61070d611818565b60405161071a9190612887565b60405180910390f35b61073d600480360381019061073891906125f1565b61183c565b60405161074a9190612887565b60405180910390f35b61076d600480360381019061076891906125f1565b611858565b60405161077a9190612887565b60405180910390f35b61079d600480360381019061079891906125c8565b611893565b6040516107aa9190612887565b60405180910390f35b6107cd60048036038101906107c89190612643565b6118a7565b6040516107da9190612887565b60405180910390f35b6107eb611958565b6040516107f89190612887565b60405180910390f35b6108096119c2565b6040516108169190612887565b60405180910390f35b6108276119e6565b6040516108349190612887565b60405180910390f35b6004805461084a90612a58565b80601f016020809104026020016040519081016040528092919081815260200182805461087690612a58565b80156108c35780601f10610898576101008083540402835291602001916108c3565b820191906000526020600020905b8154815290600101906020018083116108a657829003601f168201915b505050505081565b6000806108d6611470565b506108e033610d7f565b506108ea836111a8565b905080600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461097891906128be565b925050819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040516109dc9190612887565b60405180910390a3600191505092915050565b60075481565b60008080549050905090565b600080600080851415610a49576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a4090612827565b60405180910390fd5b838510610a5557600080fd5b8484610a619190612914565b91508482610a6f9190612945565b90508084610a7d919061299f565b9250505092915050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000806000610ab8611470565b50610ac233610d7f565b50610acc846111a8565b915081600a60008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610b5757600080fd5b610b628686846119ec565b90508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef86604051610bc19190612887565b60405180910390a380925050509392505050565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480610c5e57503373ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b610c6757600080fd5b6000600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b6000806000620f424091506d04ee2d6d415b85acef81000000007f0000000000000000000000000000000000000000000000000000000000000000610d0d9190612914565b905060005b84811015610d5457620f42408284610d2a9190612945565b610d349190612914565b83610d3f919061299f565b92508080610d4c90612a8a565b915050610d12565b50620f42408583610d659190612945565b610d6f9190612914565b9250505092915050565b60065481565b600080600080600080600080610d948961120f565b91506000821480610dac5750610da8611958565b8210155b15610dc1576000975050505050505050610f8e565b6000600183610dd0919061299f565b81548110610e07577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549650610e1d87610fb7565b94506000851415610e38576000975050505050505050610f8e565b610e418761174c565b9550610e4c8761127a565b90506d04ee2d6d415b85acef8100000000620f42407f0000000000000000000000000000000000000000000000000000000000000000610e8c9190612914565b8688610e989190612914565b610ea29190612945565b610eac9190612914565b9350620f42408185610ebe9190612945565b610ec89190612914565b92506cffffffff00000000000000000019600102600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282541692505081905550610f328984611a7e565b50818973ffffffffffffffffffffffffffffffffffffffff167f9a2a887706623ad3ff7fc85652deeceabe9fe1e00466c597972079ee91ea40d385604051610f7a9190612887565b60405180910390a360019750505050505050505b919050565b60008181548110610fa357600080fd5b906000526020600020016000915090505481565b6000606860ff16710fffffffff00000000000000000000000000836001900416908060020a82049150509050919050565b600080600960003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661104157600080fd5b611049611470565b50829050826007600082825461105f91906128be565b925050819055506110708482611a7e565b508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fab8530f87dc9b59234c4623bf917212bb2536d647574c8e7e5da92c2ede0c9f8856040516110ce9190612887565b60405180910390a36110de611bda565b50600191505092915050565b600068ffffffffffffffffff600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460019004169050919050565b60007f0000000000000000000000000000000000000000000000000000000000000000826111709190612945565b7f000000000000000000000000000000000000000000000000000000000000000061119b91906128be565b9050919050565b60085481565b60006111b560025461183c565b620f42406d04ee2d6d415b85acef8100000000846111d39190612945565b6111dd9190612945565b6111e79190612914565b9050919050565b6000603c82426111fe919061299f565b6112089190612914565b9050919050565b6000604860ff166cffffffff000000000000000000600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546001900416908060020a82049150509050919050565b6000608c60ff1673fffff00000000000000000000000000000000000836001900416908060020a82049150509050919050565b6000806000806000806112bf876110ea565b94506112cc60025461183c565b93506112d9600254611858565b92506112e6600254611858565b6112ee611958565b6112f8919061299f565b90506113048482610cc8565b9150620f42406d04ee2d6d415b85acef81000000006113239190612945565b828661132f9190612945565b6113399190612914565b95505050505050919050565b6000806000806000611355611958565b9350611362600254611858565b8461136d919061299f565b92506000831415611385576000945050505050611447565b61139060025461183c565b915061139c8284610cc8565b905060006002819055506fffffffffffffffffffffffffffffffff81166002600082825417925050819055507fffffffffffffffffffffffffffffffff00000000000000000000000000000000608060ff16859060020a02166002600082825417925050819055508183857fa0717e54e02bd9829db5e6e998aec0ae9de796b8d150a3cc46a92ab869697755846040516114369190612887565b60405180910390a460019450505050505b90565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000806000806000806000806000806000611489611cc2565b995060006001028a14156114aa5760009a50505050505050505050506115fe565b6114b38a611893565b97506001886114c291906128be565b90506114cd88611142565b91506114d7611345565b506114e360025461183c565b94506114ee826111ee565b92506000831115611523576d04ee2d6d415b85acef810000000061151286856118a7565b61151c9190612914565b9350611540565b6d04ee2d6d415b85acef81000000008561153d9190612914565b93505b61154f60008560075484611de0565b985060008990806001815401808255809150506001900390600052602060002001600090919091909150556115838a610fb7565b9650600087141561159e576115978a611e6c565b95506115b8565b6115aa87600754610a01565b95506115b6868961205f565b505b7f55d243082e019fce4009ccea5368b92e436c17586a1e793c7deda16df4e5d675816040516115e79190612887565b60405180910390a160019a50505050505050505050505b90565b6005805461160e90612a58565b80601f016020809104026020016040519081016040528092919081815260200182805461163a90612a58565b80156116875780601f1061165c57610100808354040283529160200191611687565b820191906000526020600020905b81548152906001019060200180831161166a57829003601f168201915b505050505081565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146116eb57600080fd5b6001600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b6000602060ff166cffffffffffffffffff00000000836001900416908060020a82049150509050919050565b6000806000611785611470565b5061178f33610d7f565b50611799846111a8565b91506117a63386846119ec565b90508473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040516118059190612887565b60405180910390a3809250505092915050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60006fffffffffffffffffffffffffffffffff82169050919050565b6000608060ff167fffffffffffffffffffffffffffffffff000000000000000000000000000000008316908060020a82049150509050919050565b600063ffffffff8260019004169050919050565b6000806000620f424091506d04ee2d6d415b85acef81000000007f00000000000000000000000000000000000000000000000000000000000000006118ec9190612914565b905060005b8481101561193357620f424082846119099190612945565b6119139190612914565b8361191e91906128be565b9250808061192b90612a8a565b9150506118f1565b50620f424085836119449190612945565b61194e9190612914565b9250505092915050565b600060017f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000426119a9919061299f565b6119b39190612914565b6119bd91906128be565b905090565b7f000000000000000000000000000000000000000000000000000000000000000081565b60025481565b6000806119f98584612195565b50611a048484611a7e565b50611a0d611958565b90506008548310158015611a29575080611a268661120f565b14155b8015611a6157508373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614155b15611a7257611a7085826122c6565b505b60019150509392505050565b600080600080600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546001900490506000851415611adf5760009350505050611bd4565b611ae8866110ea565b92508483611af691906128be565b91508273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1611611b66576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b5d90612867565b60405180910390fd5b68ffffffffffffffffff198116905068ffffffffffffffffff82168117905080600102600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600193505050505b92915050565b60008060006001600080549050611bf1919061299f565b81548110611c28577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001546001900490506cffffffffffffffffff000000001981169050602060ff166007549060020a02811790508060010260006001600080549050611c75919061299f565b81548110611cac577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200181905550600191505090565b6000806000806001600080549050611cda919061299f565b81548110611d11577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020015491503073ffffffffffffffffffffffffffffffffffffffff1663e80952956040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b158015611d8057600080fd5b505afa158015611d94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611db8919061261a565b9050611dc382611893565b8111611dd757600060010292505050611ddd565b81925050505b90565b60008073fffff00000000000000000000000000000000000608c60ff16869060020a021660010281179050710fffffffff00000000000000000000000000606860ff16879060020a0216600102811790506cffffffffffffffffff00000000602060ff16859060020a02166001028117905063ffffffff83166001028117905080915050949350505050565b6000806000806000611e7d8661174c565b9350620f42407f000000000000000000000000000000000000000000000000000000000000000085611eaf9190612945565b611eb99190612914565b91507f0000000000000000000000000000000000000000000000000000000000000000620f424083611eeb9190612945565b611ef59190612914565b90508381101561200d57611f0886611893565b9250710fffffffff00000000000000000000000000196001026000600185611f30919061299f565b81548110611f67577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160008282541692505081905550606860ff1660019060020a027f8000000000000000000000000000000000000000000000000000000000000000176001026000600185611fbe919061299f565b81548110611ff5577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001600082825417925050819055505b612052600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166d04ee2d6d415b85acef81000000008461204d9190612914565b611a7e565b5081945050505050919050565b600080600084141561207557600091505061218f565b7f800000000000000000000000000000000000000000000000000000000000000060010260006001856120a8919061299f565b815481106120df577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020016000828254179250508190555061214f6000600185612108919061299f565b8154811061213f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020015461174c565b9050612188600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168583612183919061299f565b611a7e565b5060019150505b92915050565b600080600080600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460019004905060008514156121f657600093505050506122c0565b6121ff866110ea565b925084831015612244576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161223b90612847565b60405180910390fd5b8483612250919061299f565b915068ffffffffffffffffff198116905068ffffffffffffffffff82168117905080600102600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600193505050505b92915050565b60006cffffffff00000000000000000019600102600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825416925050819055506cffffffff000000000000000000604860ff16839060020a0216600102600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825417925050819055506123976123a2565b506001905092915050565b600080600080600060016000805490506123bc919061299f565b815481106123f3577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549250600161240b84610fb7565b61241591906128be565b905082600190049150710fffffffff000000000000000000000000001982169150710fffffffff00000000000000000000000000606860ff16829060020a0216821791508160010260006001600080549050612471919061299f565b815481106124a8577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001819055506001935050505090565b6000813590506124cf81612b71565b92915050565b6000813590506124e481612b88565b92915050565b6000813590506124f981612b9f565b92915050565b60008151905061250e81612b9f565b92915050565b60006020828403121561252657600080fd5b6000612534848285016124c0565b91505092915050565b60008060006060848603121561255257600080fd5b6000612560868287016124c0565b9350506020612571868287016124c0565b9250506040612582868287016124ea565b9150509250925092565b6000806040838503121561259f57600080fd5b60006125ad858286016124c0565b92505060206125be858286016124ea565b9150509250929050565b6000602082840312156125da57600080fd5b60006125e8848285016124d5565b91505092915050565b60006020828403121561260357600080fd5b6000612611848285016124ea565b91505092915050565b60006020828403121561262c57600080fd5b600061263a848285016124ff565b91505092915050565b6000806040838503121561265657600080fd5b6000612664858286016124ea565b9250506020612675858286016124ea565b9150509250929050565b612688816129d3565b82525050565b612697816129e5565b82525050565b6126a6816129f1565b82525050565b60006126b7826128a2565b6126c181856128ad565b93506126d1818560208601612a25565b6126da81612b60565b840191505092915050565b60006126f26011836128ad565b91507f4552525f4e554d50415254535f5a45524f0000000000000000000000000000006000830152602082019050919050565b6000612732600d836128ad565b91507f4552525f4f5645525350454e44000000000000000000000000000000000000006000830152602082019050919050565b6000612772600d836128ad565b91507f4552525f574f554c4457524150000000000000000000000000000000000000006000830152602082019050919050565b6127ae81612a1b565b82525050565b60006020820190506127c9600083018461267f565b92915050565b60006020820190506127e4600083018461268e565b92915050565b60006020820190506127ff600083018461269d565b92915050565b6000602082019050818103600083015261281f81846126ac565b905092915050565b60006020820190508181036000830152612840816126e5565b9050919050565b6000602082019050818103600083015261286081612725565b9050919050565b6000602082019050818103600083015261288081612765565b9050919050565b600060208201905061289c60008301846127a5565b92915050565b600081519050919050565b600082825260208201905092915050565b60006128c982612a1b565b91506128d483612a1b565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561290957612908612ad3565b5b828201905092915050565b600061291f82612a1b565b915061292a83612a1b565b92508261293a57612939612b02565b5b828204905092915050565b600061295082612a1b565b915061295b83612a1b565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561299457612993612ad3565b5b828202905092915050565b60006129aa82612a1b565b91506129b583612a1b565b9250828210156129c8576129c7612ad3565b5b828203905092915050565b60006129de826129fb565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b83811015612a43578082015181840152602081019050612a28565b83811115612a52576000848401525b50505050565b60006002820490506001821680612a7057607f821691505b60208210811415612a8457612a83612b31565b5b50919050565b6000612a9582612a1b565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612ac857612ac7612ad3565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b612b7a816129d3565b8114612b8557600080fd5b50565b612b91816129f1565b8114612b9c57600080fd5b50565b612ba881612a1b565b8114612bb357600080fd5b5056fea2646970667358221220c1bcabc8b6ec1af4be064490954fb126988eba461c8f88ad8e6afa39b6b1610764736f6c63430008000033 \ No newline at end of file diff --git a/python/sarafu_token/data/RedistributedDemurrageToken.json b/python/sarafu_token/data/RedistributedDemurrageToken.json index 5d5f6e7..b677ce1 100644 --- a/python/sarafu_token/data/RedistributedDemurrageToken.json +++ b/python/sarafu_token/data/RedistributedDemurrageToken.json @@ -1 +1 @@ -[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint256","name":"_taxLevelMinute","type":"uint256"},{"internalType":"uint256","name":"_periodMinutes","type":"uint256"},{"internalType":"address","name":"_defaultSinkAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"_foo","type":"bytes32"}],"name":"Debug","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_period","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_periodCount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_oldAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newAmount","type":"uint256"}],"name":"Decayed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_minter","type":"address"},{"indexed":true,"internalType":"address","name":"_beneficiary","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_period","type":"uint256"}],"name":"Period","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_account","type":"address"},{"indexed":true,"internalType":"uint256","name":"_period","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Redistribution","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"accountPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"actualPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"addMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"applyDemurrage","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"applyRedistributionOnAccount","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"changePeriod","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"uint256","name":"_period","type":"uint256"}],"name":"decayBy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_target","type":"uint256"}],"name":"demurrageCycles","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"demurrageModifier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_periodCount","type":"uint256"}],"name":"getPeriodTimeDelta","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"uint256","name":"_period","type":"uint256"}],"name":"growBy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumParticipantSpend","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_beneficiary","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"mintTo","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"periodDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"periodStart","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"redistributionCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"redistributions","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_numParts","type":"uint256"},{"internalType":"uint256","name":"_sumWhole","type":"uint256"}],"name":"remainder","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"taxLevel","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"toBaseAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_demurrage","type":"uint256"}],"name":"toDemurrageAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"_demurrage","type":"uint256"}],"name":"toDemurragePeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"redistribution","type":"bytes32"}],"name":"toRedistributionDemurrageModifier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"redistribution","type":"bytes32"}],"name":"toRedistributionParticipants","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"redistribution","type":"bytes32"}],"name":"toRedistributionPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"redistribution","type":"bytes32"}],"name":"toRedistributionSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] +[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint256","name":"_taxLevelMinute","type":"uint256"},{"internalType":"uint256","name":"_periodMinutes","type":"uint256"},{"internalType":"address","name":"_defaultSinkAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"_foo","type":"bytes32"}],"name":"Debug","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_period","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_periodCount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_oldAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newAmount","type":"uint256"}],"name":"Decayed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_minter","type":"address"},{"indexed":true,"internalType":"address","name":"_beneficiary","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_period","type":"uint256"}],"name":"Period","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_account","type":"address"},{"indexed":true,"internalType":"uint256","name":"_period","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Redistribution","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"accountPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"actualPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"addMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"applyDemurrage","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"applyRedistributionOnAccount","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"baseBalanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"changePeriod","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"uint256","name":"_period","type":"uint256"}],"name":"decayBy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_target","type":"uint256"}],"name":"demurrageCycles","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"demurrageModifier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_periodCount","type":"uint256"}],"name":"getPeriodTimeDelta","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"uint256","name":"_period","type":"uint256"}],"name":"growBy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumParticipantSpend","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_beneficiary","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"mintTo","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"periodDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"periodStart","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"redistributionCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"redistributions","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_numParts","type":"uint256"},{"internalType":"uint256","name":"_sumWhole","type":"uint256"}],"name":"remainder","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"removeMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"taxLevel","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"toBaseAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_demurrage","type":"uint256"}],"name":"toDemurrageAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"_demurrage","type":"uint256"}],"name":"toDemurragePeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"redistribution","type":"bytes32"}],"name":"toRedistributionDemurrageModifier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"redistribution","type":"bytes32"}],"name":"toRedistributionParticipants","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"redistribution","type":"bytes32"}],"name":"toRedistributionPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"redistribution","type":"bytes32"}],"name":"toRedistributionSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] diff --git a/python/setup.cfg b/python/setup.cfg index b1db9ce..d335c2a 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = sarafu-token -version = 0.0.1a1 +version = 0.0.1a2 description = ERC20 token with redistributed continual demurrage author = Louis Holbrook author_email = dev@holbrook.no diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py index e1a07a9..712fc59 100644 --- a/python/tests/test_basic.py +++ b/python/tests/test_basic.py @@ -111,7 +111,33 @@ class Test(unittest.TestCase): balance = self.contract.functions.balanceOf(self.w3.eth.accounts[1]).call() self.assertEqual(balance, int(2000 * 0.98)) - + + def test_minter_control(self): + with self.assertRaises(eth_tester.exceptions.TransactionFailed): + tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[2], 1024).transact({'from': self.w3.eth.accounts[1]}) + + with self.assertRaises(eth_tester.exceptions.TransactionFailed): + tx_hash = self.contract.functions.addMinter(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[1]}) + + tx_hash = self.contract.functions.addMinter(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[0]}) + r = self.w3.eth.getTransactionReceipt(tx_hash) + self.assertEqual(r.status, 1) + + with self.assertRaises(eth_tester.exceptions.TransactionFailed): + tx_hash = self.contract.functions.addMinter(self.w3.eth.accounts[2]).transact({'from': self.w3.eth.accounts[1]}) + + tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[2], 1024).transact({'from': self.w3.eth.accounts[1]}) + + with self.assertRaises(eth_tester.exceptions.TransactionFailed): + tx_hash = self.contract.functions.addMinter(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[2]}) + + tx_hash = self.contract.functions.removeMinter(self.w3.eth.accounts[1]).transact({'from': self.w3.eth.accounts[1]}) + r = self.w3.eth.getTransactionReceipt(tx_hash) + self.assertEqual(r.status, 1) + + with self.assertRaises(eth_tester.exceptions.TransactionFailed): + tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[2], 1024).transact({'from': self.w3.eth.accounts[1]}) + def test_base_amount(self): tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 1000).transact() r = self.w3.eth.getTransactionReceipt(tx_hash) diff --git a/python/tests/test_pure.py b/python/tests/test_pure.py index 54665e2..b49c3fd 100644 --- a/python/tests/test_pure.py +++ b/python/tests/test_pure.py @@ -60,20 +60,21 @@ class Test(unittest.TestCase): pass + @unittest.skip('this function has been removed from contract') def test_tax_period(self): t = self.contract.functions.taxLevel().call() logg.debug('taxlevel {}'.format(t)) - a = self.contract.functions.toTaxPeriodAmount(1000000, 0).call() + a = self.contract.functions.toDemurrageAmount(1000000, 0).call() self.assertEqual(a, 1000000) - a = self.contract.functions.toTaxPeriodAmount(1000000, 1).call() + a = self.contract.functions.toDemurrageAmount(1000000, 1).call() self.assertEqual(a, 980000) - a = self.contract.functions.toTaxPeriodAmount(1000000, 2).call() + a = self.contract.functions.toDemurrageAmount(1000000, 2).call() self.assertEqual(a, 960400) - a = self.contract.functions.toTaxPeriodAmount(980000, 1).call() + a = self.contract.functions.toDemurrageAmount(980000, 1).call() self.assertEqual(a, 960400) diff --git a/python/tests/test_redistribution.py b/python/tests/test_redistribution.py index 26ccfb2..ea33db5 100644 --- a/python/tests/test_redistribution.py +++ b/python/tests/test_redistribution.py @@ -71,6 +71,9 @@ class Test(unittest.TestCase): # TODO: check receipt log outputs def test_redistribution_storage(self): + redistribution = self.contract.functions.redistributions(0).call(); + self.assertEqual(redistribution.hex(), '000000000000000000000000f424000000000000000000000000000000000001') + self.contract.functions.mintTo(self.w3.eth.accounts[1], 1000000).transact() self.contract.functions.mintTo(self.w3.eth.accounts[2], 1000000).transact() diff --git a/solidity/Makefile b/solidity/Makefile index 082d118..d3303fb 100644 --- a/solidity/Makefile +++ b/solidity/Makefile @@ -11,6 +11,6 @@ test: all python ../python/tests/test_redistribution.py install: all - cp -v RedistributedDemurrageToken.{json,bin} ../python/eth_address_declarator/data/ + cp -v RedistributedDemurrageToken.{json,bin} ../python/sarafu_token/data/ .PHONY: test install diff --git a/solidity/RedistributedDemurrageToken.sol b/solidity/RedistributedDemurrageToken.sol index 76d25a6..67480dd 100644 --- a/solidity/RedistributedDemurrageToken.sol +++ b/solidity/RedistributedDemurrageToken.sol @@ -2,51 +2,121 @@ pragma solidity > 0.6.11; // SPDX-License-Identifier: GPL-3.0-or-later -// TODO: assign bitmask values to contants contract RedistributedDemurrageToken { + // Redistribution bit field, with associated shifts and masks + // (Uses sub-byte boundaries) + bytes32[] public redistributions; // uint1(isFractional) | uint95(unused) | uint20(demurrageModifier) | uint36(participants) | uint72(value) | uint32(period) + uint8 constant shiftRedistributionPeriod = 0; + uint256 constant maskRedistributionPeriod = 0x00000000000000000000000000000000000000000000000000000000ffffffff; // (1 << 32) - 1 + uint8 constant shiftRedistributionValue = 32; + uint256 constant maskRedistributionValue = 0x00000000000000000000000000000000000000ffffffffffffffffff00000000; // ((1 << 72) - 1) << 32 + uint8 constant shiftRedistributionParticipants = 104; + uint256 constant maskRedistributionParticipants = 0x00000000000000000000000000000fffffffff00000000000000000000000000; // ((1 << 36) - 1) << 104 + uint8 constant shiftRedistributionDemurrage = 140; + uint256 constant maskRedistributionDemurrage = 0x000000000000000000000000fffff00000000000000000000000000000000000; // ((1 << 20) - 1) << 140 + uint8 constant shiftRedistributionIsFractional = 255; + uint256 constant maskRedistributionIsFractional = 0x8000000000000000000000000000000000000000000000000000000000000000; // 1 << 255 + + // Account bit field, with associated shifts and masks + // Mirrors structure of redistributions for consistency + mapping (address => bytes32) account; // uint152(unused) | uint32(period) | uint72(value) + uint8 constant shiftAccountValue = 0; + uint256 constant maskAccountValue = 0x0000000000000000000000000000000000000000000000ffffffffffffffffff; // (1 << 72) - 1 + uint8 constant shiftAccountPeriod = 72; + uint256 constant maskAccountPeriod = 0x00000000000000000000000000000000000000ffffffff000000000000000000; // ((1 << 32) - 1) << 72 + + + // TODO: use 2 x uint128 instead + // Demurrage cache bit field, with associated shifts and masks + uint256 public demurrageModifier; // PPM uint128(block) | uint128(periodppm) + uint8 constant shiftDemurrageValue = 0; + uint256 constant maskDemurrageValue = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff; + uint8 constant shiftDemurragePeriod = 128; + uint256 constant maskDemurragePeriod = 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000; + + // Implements EIP172 address public owner; + + // Implements ERC20 string public name; + + // Implements ERC20 string public symbol; + + // Implements ERC20 uint256 public decimals; + + // Implements ERC20 uint256 public totalSupply; + + // Minimum amount of (demurraged) tokens an account must spend to participate in redistribution for a particular period uint256 public minimumParticipantSpend; + + // 128 bit resolution of the demurrage divisor + // (this constant x 1000000 is contained within 128 bits) uint256 constant ppmDivider = 100000000000000000000000000000000; - uint256 public immutable periodStart; // timestamp - uint256 public immutable periodDuration; // duration in SECONDS - uint256 public immutable taxLevel; // PPM per MINUTE - uint256 public demurrageModifier; // PPM uint128(block) | uint128(ppm) + // Timestamp of start of periods (time which contract constructor was called) + uint256 public immutable periodStart; - bytes32[] public redistributions; // uint1(isFractional) | uint95(unused) | uint20(demurrageModifier) | uint36(participants) | uint72(value) | uint32(period) - mapping (address => bytes32) account; // uint152(unused) | uint32(period) | uint72(value) + // Duration of a single redistribution period in seconds + uint256 public immutable periodDuration; + + // Demurrage in ppm per minute + uint256 public immutable taxLevel; + + // Addresses allowed to mint new tokens mapping (address => bool) minter; + + // Storage for ERC20 approve/transferFrom methods mapping (address => mapping (address => uint256 ) ) allowance; // holder -> spender -> amount (amount is subject to demurrage) - address sinkAddress; // receives redistribuion remainders + // Address to send unallocated redistribution tokens + address sinkAddress; + // Implements ERC20 event Transfer(address indexed _from, address indexed _to, uint256 _value); + + // Implements ERC20 event Approval(address indexed _owner, address indexed _spender, uint256 _value); + + // New tokens minted event Mint(address indexed _minter, address indexed _beneficiary, uint256 _value); - event Debug(bytes32 _foo); + + // New demurrage cache milestone calculated event Decayed(uint256 indexed _period, uint256 indexed _periodCount, uint256 indexed _oldAmount, uint256 _newAmount); + + // When a new period threshold has been crossed event Period(uint256 _period); + + // Redistribution applied on a single eligible account event Redistribution(address indexed _account, uint256 indexed _period, uint256 _value); + // Temporary event used in development, will be removed on prod + event Debug(bytes32 _foo); + constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _taxLevelMinute, uint256 _periodMinutes, address _defaultSinkAddress) public { + // ACL setup owner = msg.sender; minter[owner] = true; - periodStart = block.timestamp; - periodDuration = _periodMinutes * 60; + + // ERC20 setup name = _name; symbol = _symbol; decimals = _decimals; + + // Demurrage setup + periodStart = block.timestamp; + periodDuration = _periodMinutes * 60; demurrageModifier = ppmDivider * 1000000; // Represents 38 decimal places demurrageModifier |= (1 << 128); taxLevel = _taxLevelMinute; // Represents 38 decimal places - sinkAddress = _defaultSinkAddress; bytes32 initialRedistribution = toRedistribution(0, 1000000, 0, 1); redistributions.push(initialRedistribution); + + // Misc settings + sinkAddress = _defaultSinkAddress; minimumParticipantSpend = 10 ** uint256(_decimals); } @@ -57,7 +127,14 @@ contract RedistributedDemurrageToken { return true; } - /// ERC20 + // Given address will no longer be allowed to call the mintTo() function + function removeMinter(address _minter) public returns (bool) { + require(msg.sender == owner || _minter == msg.sender); + minter[_minter] = false; + return true; + } + + /// Implements ERC20 function balanceOf(address _account) public view returns (uint256) { uint256 baseBalance; uint256 anchorDemurrageAmount; @@ -78,7 +155,7 @@ contract RedistributedDemurrageToken { /// Balance unmodified by demurrage function baseBalanceOf(address _account) public view returns (uint256) { - return uint256(account[_account]) & 0xffffffffffffffffff; + return uint256(account[_account]) & maskAccountValue; } /// Increases base balance for a single account @@ -96,8 +173,8 @@ contract RedistributedDemurrageToken { oldBalance = baseBalanceOf(_account); newBalance = oldBalance + _delta; require(uint160(newBalance) > uint160(oldBalance), 'ERR_WOULDWRAP'); // revert if increase would result in a wrapped value - workAccount &= 0xfffffffffffffffffffffffffffffffffffffffffffff000000000000000000; - workAccount |= newBalance & 0xffffffffffffffffff; + workAccount &= (~maskAccountValue); + workAccount |= (newBalance & maskAccountValue); account[_account] = bytes32(workAccount); return true; } @@ -117,8 +194,8 @@ contract RedistributedDemurrageToken { oldBalance = baseBalanceOf(_account); require(oldBalance >= _delta, 'ERR_OVERSPEND'); // overspend guard newBalance = oldBalance - _delta; - workAccount &= 0xfffffffffffffffffffffffffffffffffffffffffffff000000000000000000; - workAccount |= newBalance & 0xffffffffffffffffff; + workAccount &= (~maskAccountValue); + workAccount |= (newBalance & maskAccountValue); account[_account] = bytes32(workAccount); return true; } @@ -144,31 +221,31 @@ contract RedistributedDemurrageToken { function toRedistribution(uint256 _participants, uint256 _demurrageModifierPpm, uint256 _value, uint256 _period) private pure returns(bytes32) { bytes32 redistribution; - redistribution |= bytes32((_demurrageModifierPpm & 0x0fffff) << 140); - redistribution |= bytes32((_participants & 0x0fffffffff) << 104); - redistribution |= bytes32((_value & 0xffffffffffffffffff) << 32); - redistribution |= bytes32(_period & 0xffffffff); + redistribution |= bytes32((_demurrageModifierPpm << shiftRedistributionDemurrage) & maskRedistributionDemurrage); + redistribution |= bytes32((_participants << shiftRedistributionParticipants) & maskRedistributionParticipants); + redistribution |= bytes32((_value << shiftRedistributionValue) & maskRedistributionValue); + redistribution |= bytes32(_period & maskRedistributionPeriod); return redistribution; } // Serializes the demurrage period part of the redistribution word function toRedistributionPeriod(bytes32 redistribution) public pure returns (uint256) { - return uint256(redistribution) & 0xffffffff; + return uint256(redistribution) & maskRedistributionPeriod; } // Serializes the supply part of the redistribution word function toRedistributionSupply(bytes32 redistribution) public pure returns (uint256) { - return uint256(redistribution & 0x00000000000000000000000000000000000000ffffffffffffffffff00000000) >> 32; + return (uint256(redistribution) & maskRedistributionValue) >> shiftRedistributionValue; } // Serializes the number of participants part of the redistribution word function toRedistributionParticipants(bytes32 redistribution) public pure returns (uint256) { - return uint256(redistribution & 0x00000000000000000000000000000fffffffff00000000000000000000000000) >> 104; + return (uint256(redistribution) & maskRedistributionParticipants) >> shiftRedistributionParticipants; } // Serializes the number of participants part of the redistribution word function toRedistributionDemurrageModifier(bytes32 redistribution) public pure returns (uint256) { - return uint256(redistribution & 0x000000000000000000000000fffff00000000000000000000000000000000000) >> 140; + return (uint256(redistribution) & maskRedistributionDemurrage) >> shiftRedistributionDemurrage; } // Client accessor to the redistributions array length @@ -185,8 +262,8 @@ contract RedistributedDemurrageToken { currentRedistribution = redistributions[redistributions.length-1]; participants = toRedistributionParticipants(currentRedistribution) + 1; tmpRedistribution = uint256(currentRedistribution); - tmpRedistribution &= 0xfffffffffffffffffffffffffffff000000000ffffffffffffffffffffffffff; - tmpRedistribution |= (participants & 0x0fffffffff) << 104; + tmpRedistribution &= (~maskRedistributionParticipants); + tmpRedistribution |= ((participants << shiftRedistributionParticipants) & maskRedistributionParticipants); redistributions[redistributions.length-1] = bytes32(tmpRedistribution); @@ -198,8 +275,8 @@ contract RedistributedDemurrageToken { uint256 currentRedistribution; currentRedistribution = uint256(redistributions[redistributions.length-1]); - currentRedistribution &= 0xffffffffffffffffffffffffffffffffffffff000000000000000000ffffffff; - currentRedistribution |= totalSupply << 32; + currentRedistribution &= (~maskRedistributionValue); + currentRedistribution |= (totalSupply << shiftRedistributionValue); redistributions[redistributions.length-1] = bytes32(currentRedistribution); return true; @@ -225,13 +302,13 @@ contract RedistributedDemurrageToken { // Deserialize the pemurrage period for the given account is participating in function accountPeriod(address _account) public view returns (uint256) { - return (uint256(account[_account]) & 0x00000000000000000000000000000000000000ffffffff000000000000000000) >> 72; + return (uint256(account[_account]) & maskAccountPeriod) >> shiftAccountPeriod; } // Save the given demurrage period as the currently participation period for the given address function registerAccountPeriod(address _account, uint256 _period) private returns (bool) { - account[_account] &= 0xffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffffff; - account[_account] |= bytes32(_period << 72); + account[_account] &= bytes32(~maskAccountPeriod); + account[_account] |= bytes32((_period << shiftAccountPeriod) & maskAccountPeriod); incrementRedistributionParticipants(); return true; } @@ -268,11 +345,11 @@ contract RedistributedDemurrageToken { if (truncatedResult < redistributionSupply) { redistributionPeriod = toRedistributionPeriod(_redistribution); // since we reuse period here, can possibly be optimized by passing period instead - redistributions[redistributionPeriod-1] &= 0xfffffffffffffffffffffffffffff000000000ffffffffffffffffffffffffff; // just to be safe, zero out all participant count data, in this case there will be only one - redistributions[redistributionPeriod-1] |= 0x8000000000000000000000000000000000000100000000000000000000000000; + redistributions[redistributionPeriod-1] &= bytes32(~maskRedistributionParticipants); // just to be safe, zero out all participant count data, in this case there will be only one + redistributions[redistributionPeriod-1] |= bytes32(maskRedistributionIsFractional | (1 << shiftRedistributionParticipants)); } - increaseBaseBalance(sinkAddress, unit / ppmDivider); //truncatedResult); + increaseBaseBalance(sinkAddress, unit / ppmDivider); return unit; } @@ -285,8 +362,8 @@ contract RedistributedDemurrageToken { return false; } - // is this needed? - redistributions[_period-1] |= 0x8000000000000000000000000000000000000000000000000000000000000000; + // TODO: is this needed? + redistributions[_period-1] |= bytes32(maskRedistributionIsFractional); periodSupply = toRedistributionSupply(redistributions[_period-1]); increaseBaseBalance(sinkAddress, periodSupply - _remainder); @@ -294,14 +371,17 @@ contract RedistributedDemurrageToken { } + // Deserialize demurrage amount from demurrage bitfield function toDemurrageAmount(uint256 _demurrage) public pure returns (uint256) { - return _demurrage & 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff; + return _demurrage & maskDemurrageValue; } + // Deserialize demurrage period from demurrage bitfield function toDemurragePeriod(uint256 _demurrage) public pure returns (uint256) { - return (_demurrage & 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000) >> 128; + return (_demurrage & maskDemurragePeriod) >> shiftDemurragePeriod; } + // Calculate and cache the demurrage value corresponding to the (period of the) time of the method call function applyDemurrage() public returns (bool) { uint256 epochPeriodCount; uint256 periodCount; @@ -316,8 +396,8 @@ contract RedistributedDemurrageToken { lastDemurrageAmount = toDemurrageAmount(demurrageModifier); newDemurrageAmount = decayBy(lastDemurrageAmount, periodCount); demurrageModifier = 0; - demurrageModifier |= (newDemurrageAmount & 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff); - demurrageModifier |= (epochPeriodCount << 128); + demurrageModifier |= (newDemurrageAmount & maskDemurrageValue); + demurrageModifier |= ((epochPeriodCount << shiftDemurragePeriod) & maskDemurragePeriod); emit Decayed(epochPeriodCount, periodCount, lastDemurrageAmount, newDemurrageAmount); return true; } @@ -334,7 +414,6 @@ contract RedistributedDemurrageToken { // Recalculate the demurrage modifier for the new period // After this, all REPORTED balances will have been reduced by the corresponding ratio (but the effecive totalsupply stays the same) - //function applyTax() public returns (uint256) { function changePeriod() public returns (bool) { bytes32 currentRedistribution; bytes32 nextRedistribution; @@ -380,11 +459,11 @@ contract RedistributedDemurrageToken { return true; } + // Reverse a value reduced by demurrage by the given period to its original value function growBy(uint256 _value, uint256 _period) public view returns (uint256) { uint256 valueFactor; uint256 truncatedTaxLevel; - // TODO: if can't get to work, reverse the iteration from current period. valueFactor = 1000000; truncatedTaxLevel = taxLevel / ppmDivider; @@ -395,12 +474,11 @@ contract RedistributedDemurrageToken { } // Calculate a value reduced by demurrage by the given period - // TODO: higher precision + // TODO: higher precision if possible function decayBy(uint256 _value, uint256 _period) public view returns (uint256) { uint256 valueFactor; uint256 truncatedTaxLevel; - // TODO: if can't get to work, reverse the iteration from current period. valueFactor = 1000000; truncatedTaxLevel = taxLevel / ppmDivider; @@ -436,7 +514,8 @@ contract RedistributedDemurrageToken { baseValue = ((supply / participants) * (taxLevel / 1000000)) / ppmDivider; value = (baseValue * demurrage) / 1000000; - account[_account] &= bytes32(0xffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffffff); + // zero out period for the account + account[_account] &= bytes32(~maskAccountPeriod); increaseBaseBalance(_account, value); emit Redistribution(_account, period, value); @@ -469,7 +548,6 @@ contract RedistributedDemurrageToken { changePeriod(); applyRedistributionOnAccount(msg.sender); - // TODO: Prefer to truncate the result, instead it seems to round to nearest :/ baseValue = toBaseAmount(_value); result = transferBase(msg.sender, _to, baseValue); emit Transfer(msg.sender, _to, _value);