Ton
125 строк · 3.2 Кб
1;;
2;; Related contracts
3;;
4
5_ get_proxy() method_id {
6load_base_data();
7return ctx_proxy;
8}
9
10_ get_owner() method_id {
11load_base_data();
12return ctx_owner;
13}
14
15_ get_controller() method_id {
16load_base_data();
17return ctx_controller;
18}
19
20;;
21;; Balances for controller
22;;
23
24_ get_unowned() method_id {
25load_base_data();
26var [balance, extra] = get_balance();
27return max(balance - owned_balance(), 0);
28}
29
30_ get_available() method_id {
31load_base_data();
32return ctx_balance - ctx_balance_sent;
33}
34
35;;
36;; Pool and staking status
37;;
38
39_ get_staking_status() method_id {
40load_base_data();
41load_validator_data();
42
43var querySent = proxy_stored_query_id != 0;
44var unlocked = (proxy_stake_until == 0) | (proxy_stake_until < now());
45var until_val = proxy_stake_until;
46if ((proxy_stake_at != 0) & (proxy_stake_until != 0)) {
47until_val = lockup_lift_time(proxy_stake_at, proxy_stake_until);
48unlocked = unlocked & (until_val < now());
49}
50return (proxy_stake_at, until_val, proxy_stake_sent, querySent, unlocked, ctx_locked);
51}
52
53_ get_pool_status() method_id {
54load_base_data();
55load_member(owner_id());
56return (ctx_balance, ctx_balance_sent, ctx_balance_pending_deposits, ctx_balance_pending_withdraw, ctx_balance_withdraw);
57}
58
59;;
60;; Params
61;;
62_ get_params() method_id {
63load_base_data();
64var (enabled, udpates_enabled, min_stake, deposit_fee, withdraw_fee, pool_fee, receipt_price) = ctx_extras;
65return (enabled, udpates_enabled, min_stake, deposit_fee, withdraw_fee, pool_fee, receipt_price);
66}
67
68;;
69;; Members
70;;
71
72_ get_member_balance(slice address) method_id {
73load_base_data();
74load_member(parse_work_addr(address));
75
76member_update_balance();
77return (ctx_member_balance, ctx_member_pending_deposit, ctx_member_pending_withdraw, ctx_member_withdraw);
78}
79
80_ get_members_raw() method_id {
81load_base_data();
82return ctx_nominators;
83}
84
85_ get_members() method_id {
86load_base_data();
87
88;; Init with owner
89load_member(owner_id());
90member_update_balance();
91var list = nil;
92list = cons([ctx_owner, ctx_member_balance, ctx_member_pending_deposit, ctx_member_pending_withdraw, ctx_member_withdraw], list);
93
94;; Iterate all members
95var id = -1;
96do {
97(id, var cs, var f) = ctx_nominators.udict_get_next?(256, id);
98
99;; NOTE: One line condition doesn't work
100if (f) {
101if (id != owner_id()) {
102;; For some reason loading member from slice doesn't work
103load_member(id);
104member_update_balance();
105list = cons([serialize_work_addr(id), ctx_member_balance, ctx_member_pending_deposit, ctx_member_pending_withdraw, ctx_member_withdraw], list);
106}
107}
108} until (~ f);
109
110return list;
111}
112
113_ get_member(slice address) method_id {
114load_base_data();
115load_member(parse_work_addr(address));
116member_update_balance();
117return (ctx_member_balance, ctx_member_pending_deposit, ctx_member_pending_withdraw, ctx_member_withdraw);
118}
119
120_ supported_interfaces() method_id {
121return (
122123515602279859691144772641439386770278, ;; org.ton.introspection.v0
123256184278959413194623484780286929323492 ;; com.tonwhales.nominators:v0
124);
125}