forked from Re2906/token-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjetton-wallet.fc
More file actions
151 lines (128 loc) · 3.79 KB
/
Copy pathjetton-wallet.fc
File metadata and controls
151 lines (128 loc) · 3.79 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#pragma version >=0.4.3;
#include "stdlib.fc";
#include "op-codes.fc";
struct JettonWalletData {
balance: Int;
owner: Address;
master: Address;
walletCode: Cell;
}
message(0xf8a7ea5) TokenTransfer {
queryId: Int as uint64;
amount: Int as coins;
destination: Address;
response_destination: Address;
custom_payload: Cell?;
forward_ton_amount: Int as coins;
forward_payload: Slice as remaining;
}
message(0x178d4519) TokenTransferInternal {
queryId: Int as uint64;
amount: Int as coins;
from: Address;
response_destination: Address;
forward_ton_amount: Int as coins;
forward_payload: Slice as remaining;
}
message(0x7362d09c) TokenNotification {
queryId: Int as uint64;
amount: Int as coins;
from: Address;
forward_payload: Slice as remaining;
}
message(0x595f07bc) TokenBurn {
queryId: Int as uint64;
amount: Int as coins;
owner: Address;
response_destination: Address;
}
message(0x7bdd97de) TokenBurnNotification {
queryId: Int as uint64;
amount: Int as coins;
owner: Address;
response_destination: Address?;
}
message(0xd53276db) TokenExcesses {
queryId: Int as uint64;
}
message TokenUpdateContent {
content: Cell;
}
contract JettonWallet {
var balance: Int;
var owner: Address;
var master: Address;
var minTonsForStorage: Int;
var gasConsumption: Int;
() init() {
self.balance = 0;
self.minTonsForStorage = 1000000; // 0.001 TON
self.gasConsumption = 100000; // 0.0001 TON
}
() check_owner() inline {
require(ctx.sender == self.owner, "Invalid sender");
}
receive(msg: TokenTransfer) {
let ctx: Context = context();
check_owner();
self.balance = self.balance - msg.amount;
require(self.balance >= 0, "Insufficient balance");
send(SendParameters {
to: msg.destination,
value: 0,
mode: SendRemainingValue,
bounce: true,
body: TokenNotification {
queryId: msg.queryId,
amount: msg.amount,
from: ctx.sender,
forward_payload: msg.forward_payload
}.toCell()
});
if (msg.response_destination != null) {
send(SendParameters {
to: msg.response_destination,
value: ctx.value,
bounce: false,
body: TokenExcesses {
queryId: msg.queryId
}.toCell(),
mode: SendIgnoreErrors
});
}
}
receive(msg: TokenBurn) {
let ctx: Context = context();
check_owner();
self.balance = self.balance - msg.amount;
require(self.balance >= 0, "Insufficient balance");
let fwdFee: Int = ctx.readForwardFee();
require(ctx.value > fwdFee + 2 * self.gasConsumption + self.minTonsForStorage, "Invalid value - Burn");
send(SendParameters {
to: self.master,
value: 0,
mode: SendRemainingValue,
bounce: true,
body: TokenBurnNotification {
queryId: msg.queryId,
amount: msg.amount,
owner: self.owner,
response_destination: self.owner
}.toCell()
});
}
bounced(src: bounced<TokenTransferInternal>) {
self.balance = self.balance + src.amount;
}
bounced(src: bounced<TokenBurnNotification>) {
self.balance = self.balance + src.amount;
}
get fun get_wallet_data(): JettonWalletData {
return JettonWalletData {
balance: self.balance,
owner: self.owner,
master: self.master,
walletCode: (initOf JettonDefaultWallet(self.master, self.owner)).code
};
}
}