26 | | - | let user_credit = tryGetInteger((("usdn_" + toString(i.originCaller)) + "_credit")) |
---|
27 | | - | let deposit_amount = i.payments[0].amount |
---|
28 | | - | let new_user_credit = (user_credit + deposit_amount) |
---|
29 | | - | let all_credit = tryGetInteger("usdn_all_credit") |
---|
30 | | - | let new_all_credit = (all_credit + deposit_amount) |
---|
31 | | - | let transaction_block = match transactionHeightById(i.transactionId) { |
---|
32 | | - | case a: Int => |
---|
33 | | - | a |
---|
34 | | - | case _ => |
---|
35 | | - | throw("Error block number") |
---|
36 | | - | } |
---|
37 | | - | let res = invoke(Address(vires_dapp), "usdN_stake", nil, [AttachedPayment(usdn, deposit_amount)]) |
---|
38 | | - | if ((res == res)) |
---|
39 | | - | then { |
---|
40 | | - | let vires_res = match res { |
---|
41 | | - | case r: List[Any] => |
---|
42 | | - | r |
---|
43 | | - | case _ => |
---|
44 | | - | throw() |
---|
45 | | - | } |
---|
46 | | - | if ((vires_res == vires_res)) |
---|
47 | | - | then [IntegerEntry((("usdn_" + toString(i.originCaller)) + "_credit"), new_user_credit), IntegerEntry((("usdn_" + toString(i.originCaller)) + "_block"), transaction_block), IntegerEntry("usdn_all_credit", new_all_credit), IntegerEntry("usdn_all_block", transaction_block)] |
---|
48 | | - | else throw("Strict value is not equal to itself.") |
---|
49 | | - | } |
---|
50 | | - | else throw("Strict value is not equal to itself.") |
---|
| 12 | + | let currentLiquidity = valueOrElse(getInteger(this, toString(i.originCaller)), 0) |
---|
| 13 | + | [IntegerEntry(toString(i.originCaller), (currentLiquidity + i.payments[0].amount))] |
---|
59 | | - | let user_credit = tryGetInteger((("usdc_" + toString(i.originCaller)) + "_credit")) |
---|
60 | | - | let deposit_amount = i.payments[0].amount |
---|
61 | | - | let new_user_credit = (user_credit + deposit_amount) |
---|
62 | | - | let all_credit = tryGetInteger("usdc_all_credit") |
---|
63 | | - | let new_all_credit = (all_credit + deposit_amount) |
---|
64 | | - | let transaction_block = match transactionHeightById(i.transactionId) { |
---|
65 | | - | case a: Int => |
---|
66 | | - | a |
---|
67 | | - | case _ => |
---|
68 | | - | throw("Error block number") |
---|
69 | | - | } |
---|
70 | | - | let res = invoke(Address(vires_dapp), "usdC_stake", nil, [AttachedPayment(usdc, deposit_amount)]) |
---|
71 | | - | if ((res == res)) |
---|
72 | | - | then { |
---|
73 | | - | let vires_res = match res { |
---|
74 | | - | case r: List[Any] => |
---|
75 | | - | r |
---|
76 | | - | case _ => |
---|
77 | | - | throw("Incorrect invoke result") |
---|
78 | | - | } |
---|
79 | | - | if ((vires_res == vires_res)) |
---|
80 | | - | then [IntegerEntry((("usdc_" + toString(i.originCaller)) + "_credit"), new_user_credit), IntegerEntry((("usdc_" + toString(i.originCaller)) + "_block"), transaction_block), IntegerEntry("usdc_all_credit", new_all_credit), IntegerEntry("usdc_all_block", transaction_block)] |
---|
81 | | - | else throw("Strict value is not equal to itself.") |
---|
82 | | - | } |
---|
83 | | - | else throw("Strict value is not equal to itself.") |
---|
| 29 | + | let currentLiquidity = valueOrElse(getInteger(this, toString(i.originCaller)), 0) |
---|
| 30 | + | [IntegerEntry(toString(i.originCaller), (currentLiquidity + i.payments[0].amount))] |
---|
89 | | - | func sell_usdn_ticket (amount) = { |
---|
90 | | - | let user_credit = tryGetInteger((("usdn_" + toString(i.originCaller)) + "_credit")) |
---|
91 | | - | if ((amount > user_credit)) |
---|
92 | | - | then throw(("sorry you can't withdraw this amount, because u=you have only " + toString(user_credit))) |
---|
93 | | - | else { |
---|
94 | | - | let new_user_credit = (user_credit - amount) |
---|
95 | | - | let all_credit = tryGetInteger("usdn_all_credit") |
---|
96 | | - | let new_all_credit = (all_credit - amount) |
---|
97 | | - | let transaction_block = match transactionHeightById(i.transactionId) { |
---|
98 | | - | case a: Int => |
---|
99 | | - | a |
---|
100 | | - | case _ => |
---|
101 | | - | throw("Error block number") |
---|
102 | | - | } |
---|
103 | | - | let res = invoke(Address(vires_dapp), "usdN_cancelStake", [amount], nil) |
---|
104 | | - | if ((res == res)) |
---|
105 | | - | then { |
---|
106 | | - | let vires_res = match res { |
---|
107 | | - | case r: List[Any] => |
---|
108 | | - | r |
---|
109 | | - | case _ => |
---|
110 | | - | throw("Incorrect invoke result") |
---|
111 | | - | } |
---|
112 | | - | if ((vires_res == vires_res)) |
---|
113 | | - | then [IntegerEntry((("usdn_" + toString(i.originCaller)) + "_credit"), new_user_credit), IntegerEntry((("usdn_" + toString(i.originCaller)) + "_block"), transaction_block), IntegerEntry("usdn_all_credit", new_all_credit), IntegerEntry("usdn_all_block", transaction_block)] |
---|
114 | | - | else throw("Strict value is not equal to itself.") |
---|
115 | | - | } |
---|
116 | | - | else throw("Strict value is not equal to itself.") |
---|
117 | | - | } |
---|
118 | | - | } |
---|
| 36 | + | func usdC_cancelStake (amount) = if ((getIntegerValue(this, toString(i.originCaller)) >= amount)) |
---|
| 37 | + | then [ScriptTransfer(i.originCaller, amount, usdC)] |
---|
| 38 | + | else throw("too big amount") |
---|
120 | | - | |
---|
121 | | - | |
---|
122 | | - | @Callable(i) |
---|
123 | | - | func sell_usdc_ticket (amount) = { |
---|
124 | | - | let user_credit = tryGetInteger((("usdc_" + toString(i.originCaller)) + "_credit")) |
---|
125 | | - | if ((amount > user_credit)) |
---|
126 | | - | then throw(("sorry you can't withdraw this amount, because u=you have only " + toString(user_credit))) |
---|
127 | | - | else { |
---|
128 | | - | let new_user_credit = (user_credit - amount) |
---|
129 | | - | let all_credit = tryGetInteger("usdc_all_credit") |
---|
130 | | - | let new_all_credit = (all_credit - amount) |
---|
131 | | - | let transaction_block = match transactionHeightById(i.transactionId) { |
---|
132 | | - | case a: Int => |
---|
133 | | - | a |
---|
134 | | - | case _ => |
---|
135 | | - | throw("Error block number") |
---|
136 | | - | } |
---|
137 | | - | let res = invoke(Address(vires_dapp), "usdC_cancelStake", [amount], nil) |
---|
138 | | - | if ((res == res)) |
---|
139 | | - | then { |
---|
140 | | - | let vires_res = match res { |
---|
141 | | - | case r: List[Any] => |
---|
142 | | - | r |
---|
143 | | - | case _ => |
---|
144 | | - | throw("Incorrect invoke result") |
---|
145 | | - | } |
---|
146 | | - | if ((vires_res == vires_res)) |
---|
147 | | - | then [IntegerEntry((("usdc_" + toString(i.originCaller)) + "_credit"), new_user_credit), IntegerEntry((("usdc_" + toString(i.originCaller)) + "_block"), transaction_block), IntegerEntry("usdc_all_credit", new_all_credit), IntegerEntry("usdc_all_block", transaction_block)] |
---|
148 | | - | else throw("Strict value is not equal to itself.") |
---|
149 | | - | } |
---|
150 | | - | else throw("Strict value is not equal to itself.") |
---|
151 | | - | } |
---|
152 | | - | } |
---|
153 | | - | |
---|
154 | | - | |
---|
155 | | - | |
---|
156 | | - | @Callable(i) |
---|
157 | | - | func usdn_calc_profit_amount () = if ((toString(i.originCaller) != admin_wallet)) |
---|
158 | | - | then throw("Sorry! you are not allowed to use this funaction") |
---|
159 | | - | else { |
---|
160 | | - | let usdn_profit_last_block = tryGetInteger("usdn_profit_last_block") |
---|
161 | | - | let usdn_profit_last_amount = tryGetInteger("usdn_profit_last_amount") |
---|
162 | | - | let transaction_block = match transactionHeightById(i.transactionId) { |
---|
163 | | - | case a: Int => |
---|
164 | | - | a |
---|
165 | | - | case _ => |
---|
166 | | - | throw("Error block number") |
---|
167 | | - | } |
---|
168 | | - | let alfark = (transaction_block - usdn_profit_last_block) |
---|
169 | | - | if ((alfark_testnet > alfark)) |
---|
170 | | - | then throw((("Please try again after " + toString((alfark_testnet - alfark))) + " block")) |
---|
171 | | - | else { |
---|
172 | | - | let usdn_balance = assetBalance(this, usdn) |
---|
173 | | - | [IntegerEntry("usdn_profit_last_block", transaction_block), IntegerEntry("usdn_profit_last_amount", usdn_balance)] |
---|
174 | | - | } |
---|
175 | | - | } |
---|
176 | | - | |
---|
177 | | - | |
---|
178 | | - | |
---|
179 | | - | @Callable(i) |
---|
180 | | - | func usdn_send_profit_amount () = { |
---|
181 | | - | let usdn_profit_last_amount = tryGetInteger("usdn_profit_last_amount") |
---|
182 | | - | if ((0 >= usdn_profit_last_amount)) |
---|
183 | | - | then throw(("you dont have profit amount " + toString(usdn_profit_last_amount))) |
---|
184 | | - | else { |
---|
185 | | - | let transfer = ScriptTransfer(addressFromStringValue(admin_wallet), usdn_profit_last_amount, usdn) |
---|
186 | | - | [transfer] |
---|
187 | | - | } |
---|
188 | | - | } |
---|
189 | | - | |
---|
190 | | - | |
---|
191 | | - | |
---|
192 | | - | @Callable(i) |
---|
193 | | - | func usdc_calc_profit_amount () = if ((toString(i.originCaller) != admin_wallet)) |
---|
194 | | - | then throw("Sorry! you are not allowed to use this funaction") |
---|
195 | | - | else { |
---|
196 | | - | let usdc_profit_last_block = tryGetInteger("usdc_profit_last_block") |
---|
197 | | - | let usdc_profit_last_amount = tryGetInteger("usdc_profit_last_amount") |
---|
198 | | - | let transaction_block = match transactionHeightById(i.transactionId) { |
---|
199 | | - | case a: Int => |
---|
200 | | - | a |
---|
201 | | - | case _ => |
---|
202 | | - | throw("Error block number") |
---|
203 | | - | } |
---|
204 | | - | let alfark = (transaction_block - usdc_profit_last_block) |
---|
205 | | - | if ((alfark_testnet > alfark)) |
---|
206 | | - | then throw((("Please try again after " + toString((alfark_testnet - alfark))) + " block")) |
---|
207 | | - | else { |
---|
208 | | - | let usdc_balance = assetBalance(this, usdc) |
---|
209 | | - | [IntegerEntry("usdc_profit_last_block", transaction_block), IntegerEntry("usdc_profit_last_amount", usdc_balance)] |
---|
210 | | - | } |
---|
211 | | - | } |
---|
212 | | - | |
---|
213 | | - | |
---|
214 | | - | |
---|
215 | | - | @Callable(i) |
---|
216 | | - | func usdc_send_profit_amount () = { |
---|
217 | | - | let usdc_profit_last_amount = tryGetInteger("usdc_profit_last_amount") |
---|
218 | | - | if ((0 >= usdc_profit_last_amount)) |
---|
219 | | - | then throw(("you dont have profit amount " + toString(usdc_profit_last_amount))) |
---|
220 | | - | else { |
---|
221 | | - | let transfer = ScriptTransfer(addressFromStringValue(admin_wallet), usdc_profit_last_amount, usdc) |
---|
222 | | - | [transfer] |
---|
223 | | - | } |
---|
224 | | - | } |
---|
225 | | - | |
---|
226 | | - | |
---|
227 | | - | @Verifier(tx) |
---|
228 | | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|