forked from tact-lang/tact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rugpull.tact
86 lines (71 loc) · 2.31 KB
/
rugpull.tact
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
76
77
78
79
80
81
82
83
84
85
86
import "@stdlib/stoppable";
struct RugParams {
investment: Int;
returns: Int;
fee: Int;
}
contract RugPull with OwnableTransferable, Stoppable {
// Parameters
owner: Address;
investment: Int;
returns: Int;
fee: Int;
balance: Int;
rugpulled: Bool;
stopped: Bool;
// Queue
queueStart: Int;
queueEnd: Int;
queue: map<Int, Address>;
init(owner: Address, investment: Int, returns: Int, fee: Int) {
self.owner = owner;
self.rugpulled = false;
self.queueStart = 0;
self.queueEnd = 0;
self.balance = 0;
self.investment = investment;
self.returns = returns;
self.fee = fee;
self.stopped = false;
}
receive() {
// Must not be stopped stop
self.requireNotStopped();
// Forward everything to owner if rugpulled
if (self.rugpulled) {
send(SendParameters{value: 0, to: self.owner, mode: SendRemainingBalance });
return;
}
// Check if value ok
let ctx: Context = context();
require(ctx.value >= (self.investment + self.fee), "Invalid value");
// Add to queue
self.queue.set(self.queueEnd, ctx.sender);
self.queueEnd = self.queueEnd + 1;
self.balance = self.balance + self.investment;
// Perform payouts
while((self.balance > self.returns) && (self.queueEnd - self.queueStart > 0)) {
let investor: Address = self.queue.get(self.queueStart)!!;
self.balance = self.balance - self.returns;
self.queueStart = self.queueStart + 1;
self.sendPayout(investor, self.returns);
}
}
receive("withdraw") {
self.requireOwner();
if (!self.rugpulled) {
nativeReserve(self.balance, ReserveExact);
}
send(SendParameters{value: 0, to: self.owner, mode: SendRemainingBalance });
}
receive("rugpull") {
self.rugpulled = true;
send(SendParameters{value: 0, to: self.owner, mode: SendRemainingBalance });
}
fun sendPayout(to: Address, value: Int) {
send(SendParameters{value: value, to: to, mode: SendIgnoreErrors });
}
get fun params(): RugParams {
return RugParams{investment: self.investment, returns: self.returns, fee: self.fee};
}
}