1 | | - | {-# STDLIB_VERSION 6 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let a = "__" |
---|
5 | | - | |
---|
6 | | - | func b () = "%s__managerPublicKey" |
---|
7 | | - | |
---|
8 | | - | |
---|
9 | | - | func c () = "%s__pendingManagerPublicKey" |
---|
10 | | - | |
---|
11 | | - | |
---|
12 | | - | func d (e,f) = makeString(["%s%s%s", "withdrawDelay", e, f], a) |
---|
13 | | - | |
---|
14 | | - | |
---|
15 | | - | func g (e,f) = makeString(["%s%s%s", "depositFeePermille", e, f], a) |
---|
16 | | - | |
---|
17 | | - | |
---|
18 | | - | func h (e,f) = makeString(["%s%s%s", "withdrawFeePermille", e, f], a) |
---|
19 | | - | |
---|
20 | | - | |
---|
21 | | - | func i (e,f) = makeString(["%s%s%s", "minAmountDeposit", e, f], a) |
---|
22 | | - | |
---|
23 | | - | |
---|
24 | | - | func j (e,f) = makeString(["%s%s%s", "assetsPairStatus", e, f], a) |
---|
25 | | - | |
---|
26 | | - | |
---|
27 | | - | func k (e,f) = makeString(["%s%s%s", "minAmountWithdraw", e, f], a) |
---|
28 | | - | |
---|
29 | | - | |
---|
30 | | - | func l (e,f,m) = makeString(["%s%s%s%s", "balance", e, f, m], a) |
---|
31 | | - | |
---|
32 | | - | |
---|
33 | | - | func n (e,f) = makeString(["%s%s%s%s", "totalFeeCollected", "deposit", e, f], a) |
---|
34 | | - | |
---|
35 | | - | |
---|
36 | | - | func o (m,e,f,p) = makeString(["%s%s%s%s%s%d", "withdrawProcess", "inProgress", m, e, f, toString(p)], a) |
---|
37 | | - | |
---|
38 | | - | |
---|
39 | | - | func q (m,e,f,p) = makeString(["%s%s%s%s%s%d", "withdrawProcess", "done", m, e, f, toString(p)], a) |
---|
40 | | - | |
---|
41 | | - | |
---|
42 | | - | func r () = { |
---|
43 | | - | let s = getString(b()) |
---|
44 | | - | if ($isInstanceOf(s, "String")) |
---|
45 | | - | then { |
---|
46 | | - | let t = s |
---|
47 | | - | fromBase58String(t) |
---|
48 | | - | } |
---|
49 | | - | else if ($isInstanceOf(s, "Unit")) |
---|
50 | | - | then unit |
---|
51 | | - | else throw("Match error") |
---|
52 | | - | } |
---|
53 | | - | |
---|
54 | | - | |
---|
55 | | - | func u () = { |
---|
56 | | - | let s = getString(c()) |
---|
57 | | - | if ($isInstanceOf(s, "String")) |
---|
58 | | - | then { |
---|
59 | | - | let t = s |
---|
60 | | - | fromBase58String(t) |
---|
61 | | - | } |
---|
62 | | - | else if ($isInstanceOf(s, "Unit")) |
---|
63 | | - | then unit |
---|
64 | | - | else throw("Match error") |
---|
65 | | - | } |
---|
66 | | - | |
---|
67 | | - | |
---|
68 | | - | func v (w) = { |
---|
69 | | - | let x = throw("Permission denied.") |
---|
70 | | - | let s = r() |
---|
71 | | - | if ($isInstanceOf(s, "ByteVector")) |
---|
72 | | - | then { |
---|
73 | | - | let y = s |
---|
74 | | - | if ((w.callerPublicKey == y)) |
---|
75 | | - | then true |
---|
76 | | - | else x |
---|
77 | | - | } |
---|
78 | | - | else if ($isInstanceOf(s, "Unit")) |
---|
79 | | - | then if ((w.caller == this)) |
---|
80 | | - | then true |
---|
81 | | - | else x |
---|
82 | | - | else throw("Match error") |
---|
83 | | - | } |
---|
84 | | - | |
---|
85 | | - | |
---|
86 | | - | func z (A) = makeString(["otc_multiasset.ride:", A], " ") |
---|
87 | | - | |
---|
88 | | - | |
---|
89 | | - | func B (A) = throw(z(A)) |
---|
90 | | - | |
---|
91 | | - | |
---|
92 | | - | @Callable(w) |
---|
93 | | - | func registerAsset (e,f,C,D,E,F,G,H) = { |
---|
94 | | - | let I = v(w) |
---|
95 | | - | if ((I == I)) |
---|
96 | | - | then { |
---|
97 | | - | let J = d(e, f) |
---|
98 | | - | let K = g(e, f) |
---|
99 | | - | let L = h(e, f) |
---|
100 | | - | let M = i(e, f) |
---|
101 | | - | let N = k(e, f) |
---|
102 | | - | let O = j(e, f) |
---|
103 | | - | [IntegerEntry(J, C), IntegerEntry(K, D), IntegerEntry(L, E), IntegerEntry(M, F), IntegerEntry(N, G), IntegerEntry(O, H)] |
---|
104 | | - | } |
---|
105 | | - | else throw("Strict value is not equal to itself.") |
---|
106 | | - | } |
---|
107 | | - | |
---|
108 | | - | |
---|
109 | | - | |
---|
110 | | - | @Callable(w) |
---|
111 | | - | func swapAssetsAToB (f) = { |
---|
112 | | - | let P = value(w.payments[0]) |
---|
113 | | - | let e = toBase58String(value(P.assetId)) |
---|
114 | | - | let Q = fromBase58String(value(f)) |
---|
115 | | - | let m = toString(w.caller) |
---|
116 | | - | let F = valueOrErrorMessage(getInteger(i(e, f)), z("This asset pair does not exist.")) |
---|
117 | | - | let R = P.amount |
---|
118 | | - | let D = valueOrErrorMessage(getInteger(g(e, f)), z("The deposit fee for this pair of assets is not set.")) |
---|
119 | | - | let S = ((R / 1000) * D) |
---|
120 | | - | let T = valueOrElse(getInteger(l(e, f, m)), 0) |
---|
121 | | - | let U = valueOrElse(getInteger(n(e, f)), 0) |
---|
122 | | - | let H = valueOrErrorMessage(getInteger(j(e, f)), z("The asset pair status for this pair of assets is not set.")) |
---|
123 | | - | let V = if ((H == 0)) |
---|
124 | | - | then true |
---|
125 | | - | else B("The couple's deposit is blocked.") |
---|
126 | | - | if ((V == V)) |
---|
127 | | - | then { |
---|
128 | | - | let W = if ((R >= F)) |
---|
129 | | - | then true |
---|
130 | | - | else B("The deposit amount is less than the minimum.") |
---|
131 | | - | if ((W == W)) |
---|
132 | | - | then { |
---|
133 | | - | let X = ((T + R) - S) |
---|
134 | | - | let Y = if ((X > 0)) |
---|
135 | | - | then true |
---|
136 | | - | else B("The final balance is less than or equal to 0.") |
---|
137 | | - | if ((Y == Y)) |
---|
138 | | - | then [IntegerEntry(l(e, f, m), X), IntegerEntry(n(e, f), (U + S)), ScriptTransfer(w.caller, (R - S), Q)] |
---|
139 | | - | else throw("Strict value is not equal to itself.") |
---|
140 | | - | } |
---|
141 | | - | else throw("Strict value is not equal to itself.") |
---|
142 | | - | } |
---|
143 | | - | else throw("Strict value is not equal to itself.") |
---|
144 | | - | } |
---|
145 | | - | |
---|
146 | | - | |
---|
147 | | - | |
---|
148 | | - | @Callable(w) |
---|
149 | | - | func initializationSwapAssetsBToA (e) = { |
---|
150 | | - | let P = value(w.payments[0]) |
---|
151 | | - | let Z = P.amount |
---|
152 | | - | let f = toBase58String(value(P.assetId)) |
---|
153 | | - | let m = toString(w.caller) |
---|
154 | | - | let G = valueOrErrorMessage(getInteger(k(e, f)), z("The minimum withdrawal amount for this pair of assets is not set.")) |
---|
155 | | - | let aa = (height + valueOrErrorMessage(getInteger(d(e, f)), z("Withdrawal delay is not set for the specified pair."))) |
---|
156 | | - | let T = valueOrErrorMessage(getInteger(l(e, f, m)), z("This user balance does not exist.")) |
---|
157 | | - | let U = valueOrElse(getInteger(n(e, f)), 0) |
---|
158 | | - | let L = h(e, f) |
---|
159 | | - | let E = valueOrErrorMessage(getInteger(L), z("The withdrawal fee for this pair of assets is not set.")) |
---|
160 | | - | let S = ((Z / 1000) * E) |
---|
161 | | - | let X = (T - Z) |
---|
162 | | - | let Y = if ((X >= 0)) |
---|
163 | | - | then true |
---|
164 | | - | else B("Swap amount fail, amount is to small.") |
---|
165 | | - | if ((Y == Y)) |
---|
166 | | - | then { |
---|
167 | | - | let W = if ((Z >= G)) |
---|
168 | | - | then true |
---|
169 | | - | else B("The withdraw amount is less than the minimum.") |
---|
170 | | - | if ((W == W)) |
---|
171 | | - | then { |
---|
172 | | - | let ab = if ((getInteger(o(m, e, f, aa)) == unit)) |
---|
173 | | - | then true |
---|
174 | | - | else B("At this height, there is already an exchange of this pair.") |
---|
175 | | - | if ((ab == ab)) |
---|
176 | | - | then [IntegerEntry(l(e, f, m), X), IntegerEntry(o(m, e, f, aa), (Z - S)), IntegerEntry(n(e, f), (U + S))] |
---|
177 | | - | else throw("Strict value is not equal to itself.") |
---|
178 | | - | } |
---|
179 | | - | else throw("Strict value is not equal to itself.") |
---|
180 | | - | } |
---|
181 | | - | else throw("Strict value is not equal to itself.") |
---|
182 | | - | } |
---|
183 | | - | |
---|
184 | | - | |
---|
185 | | - | |
---|
186 | | - | @Callable(w) |
---|
187 | | - | func withdrawAsset (e,f,p) = { |
---|
188 | | - | let m = toString(w.caller) |
---|
189 | | - | let Z = valueOrErrorMessage(getInteger(o(m, e, f, p)), z("At this height, withdraw was not initialized with this pair of assets.")) |
---|
190 | | - | let Q = fromBase58String(value(e)) |
---|
191 | | - | let ac = if ((height >= p)) |
---|
192 | | - | then true |
---|
193 | | - | else B((("Withdrawal is possible after " + toString(p)) + " height or you have already withdrawn.")) |
---|
194 | | - | if ((ac == ac)) |
---|
195 | | - | then [DeleteEntry(o(m, e, f, p)), IntegerEntry(q(m, e, f, p), Z), ScriptTransfer(w.caller, Z, Q)] |
---|
196 | | - | else throw("Strict value is not equal to itself.") |
---|
197 | | - | } |
---|
198 | | - | |
---|
199 | | - | |
---|
200 | | - | |
---|
201 | | - | @Callable(w) |
---|
202 | | - | func withdrawFee (e,f) = { |
---|
203 | | - | let I = v(w) |
---|
204 | | - | if ((I == I)) |
---|
205 | | - | then { |
---|
206 | | - | let ad = valueOrElse(getInteger(n(e, f)), 0) |
---|
207 | | - | let ae = fromBase58String(value(e)) |
---|
208 | | - | [IntegerEntry(n(e, f), 0), ScriptTransfer(w.caller, ad, ae)] |
---|
209 | | - | } |
---|
210 | | - | else throw("Strict value is not equal to itself.") |
---|
211 | | - | } |
---|
212 | | - | |
---|
213 | | - | |
---|
214 | | - | |
---|
215 | | - | @Callable(w) |
---|
216 | | - | func setManager (af) = { |
---|
217 | | - | let I = v(w) |
---|
218 | | - | if ((I == I)) |
---|
219 | | - | then { |
---|
220 | | - | let ag = fromBase58String(af) |
---|
221 | | - | if ((ag == ag)) |
---|
222 | | - | then [StringEntry(c(), af)] |
---|
223 | | - | else throw("Strict value is not equal to itself.") |
---|
224 | | - | } |
---|
225 | | - | else throw("Strict value is not equal to itself.") |
---|
226 | | - | } |
---|
227 | | - | |
---|
228 | | - | |
---|
229 | | - | |
---|
230 | | - | @Callable(w) |
---|
231 | | - | func confirmManager () = { |
---|
232 | | - | let ah = u() |
---|
233 | | - | let ai = if (isDefined(ah)) |
---|
234 | | - | then true |
---|
235 | | - | else B("No pending manager.") |
---|
236 | | - | if ((ai == ai)) |
---|
237 | | - | then { |
---|
238 | | - | let aj = if ((w.callerPublicKey == value(ah))) |
---|
239 | | - | then true |
---|
240 | | - | else B("You are not pending manager.") |
---|
241 | | - | if ((aj == aj)) |
---|
242 | | - | then [StringEntry(b(), toBase58String(value(ah))), DeleteEntry(c())] |
---|
243 | | - | else throw("Strict value is not equal to itself.") |
---|
244 | | - | } |
---|
245 | | - | else throw("Strict value is not equal to itself.") |
---|
246 | | - | } |
---|
247 | | - | |
---|
248 | | - | |
---|
249 | | - | @Verifier(ak) |
---|
250 | | - | func al () = { |
---|
251 | | - | let am = { |
---|
252 | | - | let s = r() |
---|
253 | | - | if ($isInstanceOf(s, "ByteVector")) |
---|
254 | | - | then { |
---|
255 | | - | let y = s |
---|
256 | | - | y |
---|
257 | | - | } |
---|
258 | | - | else if ($isInstanceOf(s, "Unit")) |
---|
259 | | - | then ak.senderPublicKey |
---|
260 | | - | else throw("Match error") |
---|
261 | | - | } |
---|
262 | | - | sigVerify(ak.bodyBytes, ak.proofs[0], am) |
---|
263 | | - | } |
---|
264 | | - | |
---|
| 1 | + | # no script |
---|