-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelloWorld.solpp
75 lines (57 loc) · 2.25 KB
/
HelloWorld.solpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pragma soliditypp ^0.4.3;
contract Social {
mapping(address=>mapping(address=>uint)) public balances;
mapping(address=>uint) public reserve;
mapping(address=>uint8) public hasMinted;
tokenId token = tokenId("tti_5649544520544f4b454e6e40");
uint public factor = 3000000000000000;
event buyEvent(address indexed addr, address indexed vftid, uint256 value, tokenId tid);
event sellEvent(address indexed addr, address indexed vftid, uint256 value, tokenId tid);
event mintEvent(address indexed addr);
constructor() public {}
onMessage mint() {
require(hasMinted[msg.sender] == 0, "Address has already mint VFT");
hasMinted[msg.sender] = 1;
reserve[msg.sender] = 1000;
emit mintEvent(msg.sender);
}
onMessage buyVFT(address vftid) payable {
require(reserve[vftid] > 0, "Not enough VFT");
uint price = calculatePrice(vftid, 1);
require(msg.amount >= price, "Price is not equal to sended amount");
reserve[vftid]--;
balances[vftid][msg.sender]++;
emit buyEvent(msg.sender, vftid, price, token);
}
onMessage sellVFT(address vftid) {
require(balances[vftid][msg.sender] > 0, "Not enough VFT");
uint price = calculatePrice(vftid, 0);
reserve[vftid]++;
balances[vftid][msg.sender]--;
msg.sender.transfer(token, price);
emit sellEvent(msg.sender, vftid, price, token);
}
getter getReserve(address vftid) returns(uint) {
return reserve[vftid];
}
getter getBuyPrice(address vftid) returns(uint) {
return calculatePrice(vftid, 1);
}
getter getSellPrice(address vftid) returns(uint) {
return calculatePrice(vftid, 0);
}
getter getBalance(address vftid, address holder) returns(uint) {
return balances[vftid][holder];
}
function calculatePrice(address vftid, int forBuy) public view returns(uint) {
uint postCirculating = 1000 - reserve[vftid];
if(forBuy == 1) {
if(reserve[vftid] <= 0) return 0;
postCirculating++;
} else {
if(reserve[vftid] >= 1000) return 0;
postCirculating--;
}
return 3000000000000000 * (postCirculating * postCirculating);
}
}