Address Contract Partially Verified
Address
0x66be1bc6C6aF47900BBD4F3711801bE6C2c6CB32
Balance
1918.78 ETH
Nonce
3275
Code Size
7694 bytes
Creator
0x1D075f1F...65B2 at tx 0x950a7668...7f587a
Indexed Transactions
0
Contract Bytecode
7694 bytes
0x6080604052600436106101f95760003560e01c8063585166611161010d578063b74e452b116100a0578063d93be4331161006f578063d93be433146106c2578063e7ee6ad6146106ec578063efbe1c1c14610716578063f0da93441461072b578063f2c298be14610740576101f9565b8063b74e452b14610649578063cce7ec131461065e578063d55ec6971461068a578063d6febde81461069f576101f9565b806395d89b41116100dc57806395d89b41146105f5578063a6f2ae3a146101f9578063aaaadb581461060a578063b3bb8cd414610634576101f9565b8063585166611461055057806370a0823114610565578063729fc61314610598578063757b0884146105cb576101f9565b806318160ddd116101905780633ef7c6871161015f5780633ef7c68714610413578063402e912f14610461578063489b3fee146104765780634c54e1b5146104a95780634e71d92d1461053b576101f9565b806318160ddd14610385578063274806e01461039a578063313ce567146103d35780633ccfd60b146103fe576101f9565b8063116134ee116101cc578063116134ee146102ec57806312fa6feb1461030157806316f0115b1461032a57806317604f711461033f576101f9565b8063018a25e81461020357806303314efa1461022a57806306fdde031461023f5780630ddeb632146102c9575b6102016107b0565b005b34801561020f57600080fd5b506102186107f5565b60408051918252519081900360200190f35b34801561023657600080fd5b5061021861089c565b34801561024b57600080fd5b506102546108a2565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561028e578181015183820152602001610276565b50505050905090810190601f1680156102bb5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610201600480360360408110156102df57600080fd5b50803590602001356108d0565b3480156102f857600080fd5b5061021861095f565b34801561030d57600080fd5b50610316610965565b604080519115158252519081900360200190f35b34801561033657600080fd5b5061021861096e565b34801561034b57600080fd5b506103696004803603602081101561036257600080fd5b5035610974565b604080516001600160a01b039092168252519081900360200190f35b34801561039157600080fd5b5061021861098f565b3480156103a657600080fd5b50610218600480360360408110156103bd57600080fd5b506001600160a01b0381351690602001356109ac565b3480156103df57600080fd5b506103e86109c9565b6040805160ff9092168252519081900360200190f35b34801561040a57600080fd5b506102016109ce565b34801561041f57600080fd5b50610428610a06565b6040518082610c8080838360005b8381101561044e578181015183820152602001610436565b5050505090500191505060405180910390f35b34801561046d57600080fd5b50610218610a4b565b34801561048257600080fd5b506104286004803603602081101561049957600080fd5b50356001600160a01b0316610a51565b3480156104b557600080fd5b506104dc600480360360208110156104cc57600080fd5b50356001600160a01b0316610aad565b604080519c8d5260208d019b909b528b8b019990995296151560608b015294151560808a015260a089019390935260c088019190915260e087015261010086015261012085015261014084015261016083015251908190036101800190f35b34801561054757600080fd5b50610201610b07565b34801561055c57600080fd5b50610218610c6a565b34801561057157600080fd5b506102186004803603602081101561058857600080fd5b50356001600160a01b0316610c70565b3480156105a457600080fd5b50610218600480360360208110156105bb57600080fd5b50356001600160a01b0316610ca5565b3480156105d757600080fd5b50610218600480360360208110156105ee57600080fd5b5035610d43565b34801561060157600080fd5b50610254610d57565b34801561061657600080fd5b506102186004803603602081101561062d57600080fd5b5035610d76565b34801561064057600080fd5b50610218610d88565b34801561065557600080fd5b50610218610d8e565b6102016004803603604081101561067457600080fd5b506001600160a01b038135169060200135610d94565b34801561069657600080fd5b50610201610e27565b610201600480360360408110156106b557600080fd5b5080359060200135610f77565b3480156106ce57600080fd5b50610369600480360360208110156106e557600080fd5b5035610ffa565b3480156106f857600080fd5b506102186004803603602081101561070f57600080fd5b5035611015565b34801561072257600080fd5b50610218611022565b34801561073757600080fd5b50610218611028565b6102016004803603602081101561075657600080fd5b81019060208101813564010000000081111561077157600080fd5b82018360208201111561078357600080fd5b803590602001918460018302840111640100000000831117156107a557600080fd5b50909250905061102e565b6107b86112d4565b156107e657333214156107d5576107cf33346113e8565b506107e1565b6107df3334611445565b505b6107f3565b6107f33334600080611494565b565b6001546009546000916001600160a01b031690636deba2289061082690670de0b6b3a764000063ffffffff61183d16565b670de0b6b3a76400006040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561086a57600080fd5b505afa15801561087e573d6000803e3d6000fd5b505050506040513d602081101561089457600080fd5b505190505b90565b60095481565b60405180604001604052806012815260200171151a1a5c9908119b1bdbdc88135d5d1d585b60721b81525081565b333214610918576040805162461bcd60e51b8152602060048201526011602482015270736f7272792068756d616e73206f6e6c7960781b604482015290519081900360640190fd5b6109206112d4565b156109355761092f33346113e8565b5061095b565b6000828152601160205260409020546001600160a01b031661095933348484611494565b505b5050565b600d5481565b60045460ff1681565b600a5481565b6011602052600090815260409020546001600160a01b031681565b60045460009060ff16156109a557506000610899565b5060095490565b600560209081526000928352604080842090915290825290205481565b601281565b60006109d93361184d565b90508015610a0357333214156109f9576109f333826113e8565b50610a03565b61095b3382611445565b50565b610a0e611d5b565b60005b6064811015610a4757600b548101600090815260066020526040902054828260648110610a3a57fe5b6020020152600101610a11565b5090565b60075481565b610a59611d5b565b60005b6064811015610aa6576001600160a01b0383166000908152600560209081526040808320600b5485018452909152902054828260648110610a9957fe5b6020020152600101610a5c565b505b919050565b600f60205260009081526040902080546001820154600283015460038401546004850154600586015460068701546007880154600889015460098a0154600a909a015498999798969760ff8088169861010090980416968c565b333214610b4f576040805162461bcd60e51b8152602060048201526011602482015270736f7272792068756d616e73206f6e6c7960781b604482015290519081900360640190fd5b610b576112d4565b610b92576040805162461bcd60e51b81526020600482015260076024820152661b9bdd081e595d60ca1b604482015290519081900360640190fd5b336000818152600f6020526040902060030154610100900460ff1615610bf1576040805162461bcd60e51b815260206004820152600f60248201526e185b1c9958591e4818db185a5b5959608a1b604482015290519081900360640190fd5b610bfa816118ea565b6007546001600160a01b0382166000908152600f6020526040812060060154600a54919291610c2e9163ffffffff6119eb16565b81610c3557fe5b6001600160a01b0384166000908152600f60205260409020600301805461ff00191661010017905504905061095982826113e8565b600e5481565b60045460009060ff1615610c8657506000610aa8565b506001600160a01b03166000908152600f602052604090206005015490565b6001600160a01b0381166000908152600f602052604081206006810154600790910154828115610d1c575b600b54821015610d1c576001600160a01b0385166000908152600560209081526040808320858452909152902054610d0f90829063ffffffff61183d16565b9050600182019150610cd0565b8215610d3757610d32838263ffffffff611a1316565b610d3a565b60005b95945050505050565b607781600a8110610d5057fe5b0154905081565b6040518060400160405280600381526020016233464d60e81b81525081565b60066020526000908152604090205481565b600c5481565b600b5481565b333214610ddc576040805162461bcd60e51b8152602060048201526011602482015270736f7272792068756d616e73206f6e6c7960781b604482015290519081900360640190fd5b610de46112d4565b15610df35761092f33346113e8565b6001600160a01b0382166000908152600f602052604090206003015460ff16610e1b57600091505b61095b33348385611494565b333214610e6f576040805162461bcd60e51b8152602060048201526011602482015270736f7272792068756d616e73206f6e6c7960781b604482015290519081900360640190fd5b336000818152600f602052604090206003015460ff16610e8e57600080fd5b6001600160a01b0381166000908152600f6020526040902060090154600a11610eb657600080fd5b6001600160a01b0381166000908152600f6020526040902060090154607790600a8110610edf57fe5b01546001600160a01b0382166000908152600f60205260409020600a015410610a03576001600160a01b0381166000908152600f6020526040902060090154610f309060019063ffffffff61183d16565b6001600160a01b0382166000818152600f6020526040808220600901849055517f082e58bd2e7f7268b36ef0ce2331f7bfd29c08979529cbe85f06375fcecd43729190a350565b333214610fbf576040805162461bcd60e51b8152602060048201526011602482015270736f7272792068756d616e73206f6e6c7960781b604482015290519081900360640190fd5b610fc76112d4565b15610fd65761092f33346113e8565b6000828152601060205260409020546001600160a01b031661095933348484611494565b6010602052600090815260409020546001600160a01b031681565b60128160658110610d5057fe5b60035481565b60085481565b333214611076576040805162461bcd60e51b8152602060048201526011602482015270736f7272792068756d616e73206f6e6c7960781b604482015290519081900360640190fd5b6002546040516379614c5f60e11b8152602060048201908152602482018490526000926001600160a01b03169163f2c298be9186918691908190604401848480828437600083820152604051601f909101601f191690920195506020945090925050508083038186803b1580156110ec57600080fd5b505afa158015611100573d6000803e3d6000fd5b505050506040513d602081101561111657600080fd5b5051905033662386f26fc1000034101561116d576040805162461bcd60e51b81526020600482015260136024820152721a5b9cdd59999a58da595b9d08185b5bdd5b9d606a1b604482015290519081900360640190fd5b6000828152601160205260409020546001600160a01b0316156111c9576040805162461bcd60e51b815260206004820152600f60248201526e1b985b59481c9959da5cdd195c9959608a1b604482015290519081900360640190fd5b6001600160a01b0381166000908152600f602052604090206003015460ff1661127357600e8054600190810182556001600160a01b0383166000818152600f6020818152604080842060038101805460ff19168817905587548155600901958655955483526010815285832080546001600160a01b03191685179055838352529154925190917f082e58bd2e7f7268b36ef0ce2331f7bfd29c08979529cbe85f06375fcecd437291a35b6001600160a01b0381166000818152600f602090815260408083206001018690558583526011909152902080546001600160a01b03191690911790556112cd7383d0d842e6db3b020f384a2af11bd14787bec8e734611445565b5050505050565b60045460009060ff166113de5742600c54146113de5742600c81905560009062015180900490506000809054906101000a90046001600160a01b03166001600160a01b031663957aa58c6040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561134a57600080fd5b505af115801561135e573d6000803e3d6000fd5b505050506040513d602081101561137457600080fd5b505161138c576004805460ff19166001179055426003555b80600b5410156113dc57600b546000908152600660205260409020546007546113ba9163ffffffff611a1316565b600755600b80546000908152600660205260408120558054600101905561138c565b505b5060045460ff1690565b60405160009083906001600160a01b0382169084908481818185875af1925050503d8060008114611435576040519150601f19603f3d011682016040523d82523d6000602084013e61143a565b606091505b509095945050505050565b600080839050828160405161145990611d7a565b6001600160a01b039091168152604051908190036020019082f080158015611485573d6000803e3d6000fd5b50600193505050505b92915050565b61149d846118ea565b633b9aca008310156114e05760405162461bcd60e51b8152600401808060200182810382526021815260200180611db96021913960400191505060405180910390fd5b69021e19e0c9bab2400000831115611530576040805162461bcd60e51b815260206004820152600e60248201526d6e6f20766974616c696b2c206e6f60901b604482015290519081900360640190fd5b606482111561153e57606491505b60006012836065811061154d57fe5b0154670de0b6b3a7640000019050600081611579670de0b6b3a7640000876119eb90919063ffffffff16565b8161158057fe5b0490506000600160009054906101000a90046001600160a01b03166001600160a01b03166310a76c2e600854846040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b1580156115e857600080fd5b505afa1580156115fc573d6000803e3d6000fd5b505050506040513d602081101561161257600080fd5b50519050600085156116245781611627565b60005b600b5460085491925087016000190190611641908561183d565b600855600954611657908463ffffffff61183d16565b600955600081815260066020526040902054611679908363ffffffff61183d16565b60008281526006602052604090205560075461169b908363ffffffff61183d16565b6007556001600160a01b0389166000908152600f60205260409020600401546116ca908963ffffffff61183d16565b6001600160a01b038a166000908152600f602052604090206004810191909155600501546116fe908463ffffffff61183d16565b6001600160a01b038a166000908152600f60205260409020600581019190915560060154611732908363ffffffff61183d16565b6001600160a01b038a166000908152600f60209081526040808320600601939093556005815282822084835290522054611772908363ffffffff61183d16565b6001600160a01b038a1660009081526005602090815260408083208584529091529020556117a08887611a28565b6117ab898985611b73565b600b5460408051848152602081018a905281516001600160a01b038d16927f4b9622a7ffcb20551847f4dd71b5b98c4267e10d7d338a6c7fb7b26d45d854e0928290030190a36040805184815290516001600160a01b038b16916000917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a3505050505050505050565b8181018281101561148e57600080fd5b60008061185983611bf0565b6001600160a01b0384166000908152600f6020526040812060020154919250611888838363ffffffff61183d16565b905080156118e2576001600160a01b0385166000908152600f602052604081206002810191909155600801546118c590849063ffffffff61183d16565b6001600160a01b0386166000908152600f60205260409020600801555b949350505050565b6001600160a01b0381166000908152600f60205260408120600701549081156119c7575b600b5482101561197e576001600160a01b038316600090815260056020908152604080832085845290915290205461194d90829063ffffffff61183d16565b6001600160a01b0384166000908152600560209081526040808320868452909152812055600190920191905061190e565b6001600160a01b0383166000908152600f60205260409020600601546119aa908263ffffffff611a1316565b6001600160a01b0384166000908152600f60205260409020600601555b5050600b546001600160a01b039091166000908152600f6020526040902060070155565b6000826119fa5750600061148e565b5081810281838281611a0857fe5b041461148e57600080fd5b600082821115611a2257600080fd5b50900390565b6001600160a01b0381166000908152600f60205260409020600301546005830490600a84049060ff1615611b36576001600160a01b0383166000908152600f6020526040812060090154611a8390600663ffffffff61183d16565b905060006064611a99878463ffffffff6119eb16565b81611aa057fe5b6001600160a01b0387166000908152600f60205260409020600201549190049150611ad1908263ffffffff61183d16565b6001600160a01b0386166000908152600f602052604090206002810191909155600a0154611b05908263ffffffff61183d16565b6001600160a01b0386166000908152600f60205260409020600a0155611b31848263ffffffff611a1316565b935050505b611b54739933ad4d38702cdc28c5db2f421f1f02cf53078082611445565b506112cd7383d0d842e6db3b020f384a2af11bd14787bec8e783611445565b60006014611b8884600363ffffffff6119eb16565b81611b8f57fe5b04905060006064611ba785603763ffffffff6119eb16565b81611bae57fe5b0490506000611bbe868486611c48565b9050611be582611bd983600a5461183d90919063ffffffff16565b9063ffffffff61183d16565b600a55505050505050565b6001600160a01b0381166000908152600f602052604081206008810154600590910154600d5461148e9291670de0b6b3a764000091611c349163ffffffff6119eb16565b81611c3b57fe5b049063ffffffff611a1316565b6009546000908190611c6885670de0b6b3a764000063ffffffff6119eb16565b81611c6f57fe5b049050611c8781600d5461183d90919063ffffffff16565b600d556000670de0b6b3a7640000611ca5838663ffffffff6119eb16565b81611cac57fe5b049050611cfd600f6000886001600160a01b03166001600160a01b0316815260200190815260200160002060080154611bd983670de0b6b3a7640000611c3489600d546119eb90919063ffffffff16565b6001600160a01b0387166000908152600f6020526040902060080155600954611d5190670de0b6b3a764000090611d3b90859063ffffffff6119eb16565b81611d4257fe5b8791900463ffffffff611a1316565b9695505050505050565b60405180610c8001604052806064906020820280388339509192915050565b603280611d878339019056fe60806040526040516032380380603283398181016040526020811015602357600080fd5b50516001600160a01b038116fffe706f636b6574206c696e743a206e6f7420612076616c69642063757272656e6379a265627a7a7231582078f7dc0663f1419e97d7fc0c07346c894c816feeb9b5dae00925b35d680d542464736f6c63430005100032
Verified Source Code Partial Match
Compiler: v0.5.16+commit.9c3226ce
EVM: istanbul
Optimization: Yes (200 runs)
ThreeFMutual.sol 727 lines
pragma solidity 0.5.16;
contract ThreeFMutual {
using SafeMath for *;
//*********
// STRUCTS
//*********
struct Player {
uint256 id; // agent id
bytes32 name; // agent name
uint256 ref; // referral vault
bool isAgent; // referral activated
bool claimed; // insurance claimed
uint256 eth; // eth player has paid
uint256 shares; // shares
uint256 units; // uints of insurance
uint256 plyrLastSeen; // last day player played
uint256 mask; // player mask
uint256 level; // agent level
uint256 accumulatedRef; // accumulated referral income
}
//***************
// EXTERNAL DATA
//***************
VAT vat = VAT(0x35D1b3F3D7966A1DFe207aa4514C12a259A0492B);
Underwriter underwriter = Underwriter(0xE58cDe3CbEeCC8d9306f482729084B909Afa2357);
Agency agency = Agency(0x7Bc360ebD65eFa503FF189A0F81f61f85D310Ec3);
address payable constant private hakka = address(0x83D0D842e6DB3B020f384a2af11bD14787BEC8E7);
address payable constant private IIP = address(0x9933AD4D38702cdC28C5DB2F421F1F02CF530780);
uint256 public end;
bool public ended;
//******************
// GLOBAL VARIABLES
//******************
mapping(address => mapping(uint256 => uint256)) public unitToExpirePlayer;
mapping(uint256 => uint256) public unitToExpire; // unit of insurance due at day x
uint256 public issuedInsurance; // all issued insurance
uint256 public ethOfShare; // virtual eth pointer
uint256 public shares; // total share
uint256 public pool; // eth gonna pay to beneficiary
uint256 public today; // today's date
uint256 public _now; // current time
uint256 public mask; // global mask
uint256 public agents; // number of agent
// player data
mapping(address => Player) public player; // player data
mapping(uint256 => address) public agentxID_; // return agent address by id
mapping(bytes32 => address) public agentxName_; // return agent address by name
// constant parameters
uint256 constant maxInsurePeriod = 100;
uint256 constant maxLevel = 10;
// rate of buying x day insurance
uint256[101] public rate =
[0,
1000000000000000000,
1990000000000000000,
2970100000000000000,
3940399000000000000,
4900995010000000000,
5851985059900000000,
6793465209301000000,
7725530557207990000,
8648275251635910100,
9561792499119550999,
10466174574128355489,
11361512828387071934,
12247897700103201215,
13125418723102169203,
13994164535871147511,
14854222890512436036,
15705680661607311676,
16548623854991238559,
17383137616441326173,
18209306240276912911,
19027213177874143782,
19836941046095402344,
20638571635634448321,
21432185919278103838,
22217864060085322800,
22995685419484469572,
23765728565289624876,
24528071279636728627,
25282790566840361341,
26029962661171957728,
26769663034560238151,
27501966404214635769,
28226946740172489411,
28944677272770764517,
29655230500043056872,
30358678195042626303,
31055091413092200040,
31744540498961278040,
32427095093971665260,
33102824143031948607,
33771795901601629121,
34434077942585612830,
35089737163159756702,
35738839791528159135,
36381451393612877544,
37017636879676748769,
37647460510879981281,
38270985905771181468,
38888276046713469653,
39499393286246334956,
40104399353383871606,
40703355359850032890,
41296321806251532561,
41883358588189017235,
42464525002307127063,
43039879752284055792,
43609480954761215234,
44173386145213603082,
44731652283761467051,
45284335760923852380,
45831492403314613856,
46373177479281467717,
46909445704488653040,
47440351247443766510,
47965947734969328845,
48486288257619635557,
49001425375043439201,
49511411121293004809,
50016297010080074761,
50516134039979274013,
51010972699579481273,
51500862972583686460,
51985854342857849595,
52465995799429271099,
52941335841434978388,
53411922483020628604,
53877803258190422318,
54339025225608518095,
54795634973352432914,
55247678623618908585,
55695201837382719499,
56138249819008892304,
56576867320818803381,
57011098647610615347,
57440987661134509194,
57866577784523164102,
58287912006677932461,
58705032886611153136,
59117982557745041605,
59526802732167591189,
59931534704845915277,
60332219357797456124,
60728897164219481563,
61121608192577286747,
61510392110651513880,
61895288189544998741,
62276335307649548754,
62653571954573053266,
63027036235027322733,
63396765872677049506];
// threshold of agent upgrade
uint256[10] public requirement =
[0,
73890560989306501,
200855369231876674,
545981500331442382,
1484131591025766010,
4034287934927351160,
10966331584284585813,
29809579870417282259,
81030839275753838749,
220264657948067161559];
//******************
// EVENT
//******************
event UPGRADE (address indexed agent, uint256 indexed level);
event BUYINSURANCE(address indexed buyer, uint256 indexed start, uint256 unit, uint256 date);
//******************
// MODIFIER
//******************
modifier isHuman() {
require(msg.sender == tx.origin, "sorry humans only");
_;
}
//******************
// CORE FUNCTIONS
//******************
/**
* @dev Constructor
* @notice Initialize the time
*/
constructor() public {
_now = now;
today = _now / 1 days;
}
/**
* @dev Ticker
* @notice It is called everytime when a player interacts with this contract
* @return true if MakerDAO has been shut down, false otherwise
*/
function tick()
internal
returns(bool)
{
if(!ended) {
if (_now != now) {
_now = now;
uint256 _today = _now / 1 days; // the current day as soon as ticker is called
//check MakerDAO status
if(vat.live() == 0) {
ended = true;
end = now;
}
// calculate the outdated issuedInsurance
while (today < _today) {
issuedInsurance = issuedInsurance.sub(unitToExpire[today]);
unitToExpire[today] = 0;
today += 1;
}
}
}
return ended;
}
/**
* @dev Register
* @notice Register a name by a human player
*/
function register(string calldata _nameString)
external
payable
isHuman()
{
bytes32 _name = agency.register(_nameString);
address _agent = msg.sender;
require(msg.value >= 10000000000000000, "insufficient amount");
require(agentxName_[_name] == address(0), "name registered");
if(!player[_agent].isAgent){
agents += 1;
player[_agent].isAgent = true;
player[_agent].id = agents;
player[_agent].level = 1;
agentxID_[agents] = _agent;
emit UPGRADE(_agent,player[_agent].level);
}
// set name active for the player
player[_agent].name = _name;
agentxName_[_name] = _agent;
sendContract(hakka, msg.value);
}
/**
* @dev Upgrade
* @notice Upgrade when a player's referral bonus meet the requirement
*/
function upgrade()
external
isHuman()
{
address _agent = msg.sender;
require(player[_agent].isAgent);
require(player[_agent].level < maxLevel);
if(player[_agent].accumulatedRef >= requirement[player[_agent].level]) {
player[_agent].level = (1).add(player[_agent].level);
emit UPGRADE(_agent,player[_agent].level);
}
}
//using address for referral
function buy(address payable _agent, uint256 _date)
isHuman()
public
payable
{
// ticker
if(tick()){
sendHuman(msg.sender, msg.value);
return;
}
// validate agent
if(!player[_agent].isAgent){
_agent = address(0);
}
buyCore(msg.sender, msg.value, _date, _agent);
}
//using ID for referral
function buy(uint256 _agentId, uint256 _date)
isHuman()
public
payable
{
// ticker
if(tick()){
sendHuman(msg.sender, msg.value);
return;
}
//query agent
address payable _agent = address(uint160(agentxID_[_agentId]));
buyCore(msg.sender, msg.value, _date, _agent);
}
//using name for referral
function buy(bytes32 _agentName, uint256 _date)
isHuman()
public
payable
{
// ticker
if(tick()){
sendHuman(msg.sender, msg.value);
return;
}
//query agent
address payable _agent = address(uint160(agentxName_[_agentName]));
buyCore(msg.sender, msg.value, _date, _agent);
}
// contract wallets, sorry insurance only for human
function buy()
public
payable
{
// ticker
if(tick()) {
if(msg.sender == tx.origin)
sendHuman(msg.sender, msg.value);
else
sendContract(msg.sender, msg.value);
return;
}
buyCore(msg.sender, msg.value, 0, address(0));
}
// fallback
function () external payable {
buy();
}
/**
* @dev Core part of buying
*/
function buyCore(address _buyer, uint256 _eth, uint256 _date, address payable _agent) internal {
updatePlayerUnit(_buyer);
require(_eth >= 1000000000, "pocket lint: not a valid currency");
require(_eth <= 10000000000000000000000, "no vitalik, no");
if(_date > maxInsurePeriod){
_date = maxInsurePeriod;
}
uint256 _rate = rate[_date] + 1000000000000000000;
uint256 ethToBuyShare = _eth.mul(1000000000000000000) / _rate;
//-- ethToBuyShare is a virtual amount used to represent the eth player paid for buying shares
//which is usually different from _eth
// get value of shares and insurances can be bought
uint256 _share = underwriter.mintShare(ethOfShare, ethToBuyShare);
uint256 _unit = (_date == 0)? 0: _share;
uint256 newDate = today + _date - 1;
// update global data
ethOfShare = ethOfShare.add(ethToBuyShare);
shares = shares.add(_share);
unitToExpire[newDate] = unitToExpire[newDate].add(_unit);
issuedInsurance = issuedInsurance.add(_unit);
// update player data
player[_buyer].eth = player[_buyer].eth.add(_eth);
player[_buyer].shares = player[_buyer].shares.add(_share);
player[_buyer].units = player[_buyer].units.add(_unit);
unitToExpirePlayer[_buyer][newDate] = unitToExpirePlayer[_buyer][newDate].add(_unit);
distributeEx(_eth, _agent);
distributeIn(_buyer, _eth, _share);
emit BUYINSURANCE(_buyer, today, _unit, _date);
emit Transfer(address(0), _buyer, _share);
}
/**
* @dev Update player's units of insurance
*/
function updatePlayerUnit(address _player) internal {
uint256 _today = player[_player].plyrLastSeen;
uint256 expiredUnit = 0;
if(_today != 0){
while(_today < today){
expiredUnit = expiredUnit.add(unitToExpirePlayer[_player][_today]);
unitToExpirePlayer[_player][_today] = 0;
_today += 1;
}
player[_player].units = player[_player].units.sub(expiredUnit);
}
player[_player].plyrLastSeen = today;
}
/**
* @dev pay external stakeholder
*/
function distributeEx(uint256 _eth, address payable _agent) internal {
// 20% to external
uint256 ex = _eth / 5 ;
// 10% to IIP
uint256 _iip = _eth / 10;
if(player[_agent].isAgent){
uint256 refRate = player[_agent].level.add(6);
uint256 _ref = _eth.mul(refRate) / 100;
player[_agent].ref = player[_agent].ref.add(_ref);
player[_agent].accumulatedRef = player[_agent].accumulatedRef.add(_ref);
ex = ex.sub(_ref);
}
sendContract(IIP, _iip);
sendContract(hakka, ex);
}
/**
* @dev Distribute to internal
*/
function distributeIn(address _buyer, uint256 _eth, uint256 _shares) internal {
// 15% to share holder
uint256 _div = _eth.mul(3) / 20;
// 55% to insurance pool
uint256 _pool = _eth.mul(55) / 100;
// distribute dividend share and collect dust
uint256 _dust = updateMasks(_buyer, _div, _shares);
// add eth to pool
pool = pool.add(_dust).add(_pool);
}
function updateMasks(address _player, uint256 _div, uint256 _shares)
private
returns(uint256)
{
// calculate profit per share & global mask based on this buy: (dust goes to pool)
uint256 _ppt = _div.mul(1000000000000000000) / shares;
mask = mask.add(_ppt);
// calculate player earning from their own buy (only based on the shares
// they just bought). & update player earnings mask
uint256 _pearn = (_ppt.mul(_shares)) / 1000000000000000000;
player[_player].mask = (((mask.mul(_shares)) / 1000000000000000000).sub(_pearn)).add(player[_player].mask);
// calculate & return dust
return(_div.sub( _ppt.mul(shares) / 1000000000000000000));
}
/**
* @dev Submit a claim from a beneficiary
*/
function claim()
isHuman()
public
{
require(tick(), "not yet"); // MakerDAO shutdown!
address payable beneficiary = msg.sender;
require(!player[beneficiary].claimed, "already claimed");
updatePlayerUnit(beneficiary);
uint256 amount = pool.mul(player[beneficiary].units) / issuedInsurance;
player[beneficiary].claimed = true;
sendHuman(beneficiary, amount);
}
/**
* @dev Withdraw dividends and ref
*/
function withdraw()
public
{
// get player earnings
uint256 _eth;
_eth = withdrawEarnings(msg.sender);
// pay
if (_eth > 0) {
if(msg.sender == tx.origin)
sendHuman(msg.sender, _eth);
else
sendContract(msg.sender, _eth);
}
}
function withdrawEarnings(address _player)
private
returns(uint256)
{
uint256 _div = calcUnMaskedEarnings(_player); //dividend
uint256 _ref = player[_player].ref; // referral
uint256 _earnings = _div.add(_ref);
if (_earnings > 0) {
player[_player].ref = 0;
player[_player].mask = _div.add(player[_player].mask);
}
return(_earnings);
}
function calcUnMaskedEarnings(address _player)
private
view
returns(uint256)
{
return (mask.mul(player[_player].shares) / 1000000000000000000).sub(player[_player].mask);
}
//******************
// GETTERS
//******************
/**
* @dev Return the price buyer will pay for next 1 individual share.
* @return Price for next share bought (in wei format)
*/
function getBuyPrice() external view returns(uint256) {
return underwriter.burnShare(shares.add(1000000000000000000), 1000000000000000000);
}
/**
* @dev Get the units of insurance of player
* @return Amount of existing units of insurance
*/
function getCurrentUnit(address _player)
external
view
returns(uint256)
{
uint256 _unit = player[_player].units;
uint256 _today = player[_player].plyrLastSeen;
uint256 expiredUnit = 0;
if(_today != 0) {
while(_today < today){
expiredUnit = expiredUnit.add(unitToExpirePlayer[_player][_today]);
_today += 1;
}
}
return _unit == 0 ? 0 : _unit.sub(expiredUnit);
}
/**
* @dev Get the list of units of insurace going to expire of a player
* @return List of units of insurance going to expire from a player
*/
function getExpiringUnitListPlayer(address _player)
external
view
returns(uint256[maxInsurePeriod] memory expiringUnitList)
{
for(uint256 i=0; i<maxInsurePeriod; i++) {
expiringUnitList[i] = unitToExpirePlayer[_player][today+i];
}
return expiringUnitList;
}
/**
* @dev Get the list of units of insurace going to expire
* @return List of units of insurance going to expire
*/
function getExpiringUnitList()
external
view
returns(uint256[maxInsurePeriod] memory expiringUnitList)
{
for(uint256 i=0; i<maxInsurePeriod; i++){
expiringUnitList[i] = unitToExpire[today+i];
}
return expiringUnitList;
}
//******************
// ERC20
//******************
string public constant name = "Third Floor Mutual";
string public constant symbol = "3FM";
uint8 public constant decimals = 18;
function totalSupply() external view returns(uint256) {
if(ended) return 0;
return shares;
}
function balanceOf(address who) external view returns(uint256) {
if(ended) return 0;
return player[who].shares;
}
event Transfer(address indexed from, address indexed to, uint256 amount);
//******************
// send eth
//******************
function sendHuman(address to, uint256 amount) internal returns(bool success) {
address payable recipient = address(uint160(to));
(success, ) = recipient.call.value(amount)("");
}
function sendContract(address to, uint256 amount) internal returns(bool success) {
address payable recipient = address(uint160(to));
(new SafeSend).value(amount)(recipient);
return true;
}
}
contract VAT {
function live() external returns(uint256);
}
contract SafeSend {
constructor(address payable to) public payable {
selfdestruct(to);
}
}
contract Underwriter {
function mintShare(uint256 _curEth, uint256 _newEth) external pure returns (uint256);
function burnShare(uint256 _curShares, uint256 _sellShares) external pure returns (uint256);
function shares(uint256 _eth) public pure returns(uint256);
function eth(uint256 _shares) public pure returns(uint256);
}
contract Agency {
function register(string memory _input) public pure returns(bytes32);
}
library SafeMath {
function mul(uint256 a, uint256 b)
internal
pure
returns (uint256 c)
{
if (a == 0) return 0;
c = a * b;
require(c / a == b);
}
function sub(uint256 a, uint256 b)
internal
pure
returns (uint256 c)
{
require(b <= a);
c = a - b;
}
function add(uint256 a, uint256 b)
internal
pure
returns (uint256 c)
{
c = a + b;
require(c >= a);
}
function sqrt(uint256 x)
internal
pure
returns (uint256 y)
{
uint256 z = add(x >> 1, 1);
y = x;
while (z < y)
{
y = z;
z = ((add((x / z), z)) / 2);
}
}
function sq(uint256 x)
internal
pure
returns (uint256)
{
return (mul(x,x));
}
function pwr(uint256 x, uint256 y) internal pure returns(uint256 z) {
z = 1;
while(y != 0){
if(y % 2 == 1)
z = mul(z,x);
x = sq(x);
y = y / 2;
}
return z;
}
}
Read Contract
_now 0xb3bb8cd4 → uint256
agents 0x58516661 → uint256
agentxID_ 0xd93be433 → address
agentxName_ 0x17604f71 → address
balanceOf 0x70a08231 → uint256
decimals 0x313ce567 → uint8
end 0xefbe1c1c → uint256
ended 0x12fa6feb → bool
ethOfShare 0xf0da9344 → uint256
getBuyPrice 0x018a25e8 → uint256
getCurrentUnit 0x729fc613 → uint256
getExpiringUnitList 0x3ef7c687 → uint256[100]
getExpiringUnitListPlayer 0x489b3fee → uint256[100]
issuedInsurance 0x402e912f → uint256
mask 0x116134ee → uint256
name 0x06fdde03 → string
player 0x4c54e1b5 → uint256, bytes32, uint256, bool, bool, uint256, uint256, uint256, uint256, uint256, uint256, uint256
pool 0x16f0115b → uint256
rate 0xe7ee6ad6 → uint256
requirement 0x757b0884 → uint256
shares 0x03314efa → uint256
symbol 0x95d89b41 → string
today 0xb74e452b → uint256
totalSupply 0x18160ddd → uint256
unitToExpire 0xaaaadb58 → uint256
unitToExpirePlayer 0x274806e0 → uint256
Write Contract 8 functions
These functions modify contract state and require a wallet transaction to execute.
buy 0x0ddeb632
bytes32 _agentName
uint256 _date
buy 0xa6f2ae3a
No parameters
buy 0xcce7ec13
address _agent
uint256 _date
buy 0xd6febde8
uint256 _agentId
uint256 _date
claim 0x4e71d92d
No parameters
register 0xf2c298be
string _nameString
upgrade 0xd55ec697
No parameters
withdraw 0x3ccfd60b
No parameters
Token Balances (1)
View Transfers →Recent Transactions
No transactions found for this address