1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let free_to_borrom = addressFromStringValue("3PG7CHvBatHpChwm8reH74wfEwk1PHc8Rqy") |
---|
5 | 5 | | |
---|
6 | 6 | | let USDN_ASSET_ID = base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p' |
---|
7 | 7 | | |
---|
8 | 8 | | let boss = addressFromStringValue("3PRE5KH9oPGfFPs7fGnQcJ4wNshEDUPGj1t") |
---|
9 | 9 | | |
---|
10 | 10 | | let adminPublicKey = base58'Cr1ybL2JGg9GwJHA2JwqxBPfSW6Q7Jg4HvNrsEiCsHu6' |
---|
11 | 11 | | |
---|
12 | 12 | | func getPutGet (is_stable) = { |
---|
13 | 13 | | let putFunc = if ((is_stable == 1)) |
---|
14 | 14 | | then "putOneTknV2" |
---|
15 | 15 | | else "putOneTkn" |
---|
16 | 16 | | let getFunc = if ((is_stable == 1)) |
---|
17 | 17 | | then "getOneTknV2" |
---|
18 | 18 | | else "getOneTkn" |
---|
19 | 19 | | $Tuple2(putFunc, getFunc) |
---|
20 | 20 | | } |
---|
21 | 21 | | |
---|
22 | 22 | | |
---|
23 | 23 | | func getBalance (assetId) = match assetId { |
---|
24 | 24 | | case b: ByteVector => |
---|
25 | 25 | | assetBalance(this, b) |
---|
26 | 26 | | case _ => |
---|
27 | 27 | | wavesBalance(this).available |
---|
28 | 28 | | } |
---|
29 | 29 | | |
---|
30 | 30 | | |
---|
31 | 31 | | func getBase1 (data) = { |
---|
32 | 32 | | let p_data = split(data, "_") |
---|
33 | 33 | | let a = p_data[0] |
---|
34 | 34 | | let a2 = p_data[1] |
---|
35 | 35 | | let assetIn = p_data[2] |
---|
36 | 36 | | let amountIn = p_data[3] |
---|
37 | 37 | | let amount_1 = p_data[4] |
---|
38 | 38 | | let amount_2 = p_data[5] |
---|
39 | 39 | | let amount_3 = p_data[6] |
---|
40 | 40 | | $Tuple7(a, a2, assetIn, amountIn, amount_1, amount_2, amount_3) |
---|
41 | 41 | | } |
---|
42 | 42 | | |
---|
43 | 43 | | |
---|
44 | 44 | | func getBase2 (data) = { |
---|
45 | 45 | | let p_data = split(data, "_") |
---|
46 | 46 | | let p1 = p_data[0] |
---|
47 | 47 | | let lp1 = p_data[1] |
---|
48 | 48 | | let is_stable_1 = p_data[2] |
---|
49 | 49 | | let t = p_data[3] |
---|
50 | 50 | | $Tuple4(p1, lp1, is_stable_1, t) |
---|
51 | 51 | | } |
---|
52 | 52 | | |
---|
53 | 53 | | |
---|
54 | 54 | | func getAssetBytes (assetId) = if ((assetId == "WAVES")) |
---|
55 | 55 | | then unit |
---|
56 | 56 | | else fromBase58String(assetId) |
---|
57 | 57 | | |
---|
58 | 58 | | |
---|
59 | 59 | | func swap_wx (p,lp,asset,amount,putFunc1,getFunc1,a) = { |
---|
60 | 60 | | let put1 = invoke(Address(fromBase58String(p)), putFunc1, [1, false], [AttachedPayment(getAssetBytes(asset), amount)]) |
---|
61 | 61 | | if ((put1 == put1)) |
---|
62 | 62 | | then { |
---|
63 | 63 | | let lp1_assetid = fromBase58String(lp) |
---|
64 | 64 | | let lpBalance_1 = getBalance(lp1_assetid) |
---|
65 | 65 | | if ((lpBalance_1 == lpBalance_1)) |
---|
66 | 66 | | then { |
---|
67 | 67 | | let get1 = invoke(Address(fromBase58String(p)), getFunc1, [a, 1], [AttachedPayment(lp1_assetid, lpBalance_1)]) |
---|
68 | 68 | | if ((get1 == get1)) |
---|
69 | 69 | | then nil |
---|
70 | 70 | | else throw("Strict value is not equal to itself.") |
---|
71 | 71 | | } |
---|
72 | 72 | | else throw("Strict value is not equal to itself.") |
---|
73 | 73 | | } |
---|
74 | 74 | | else throw("Strict value is not equal to itself.") |
---|
75 | 75 | | } |
---|
76 | 76 | | |
---|
77 | 77 | | |
---|
78 | 78 | | func swap_swop (p,asset,amount,stable,est,min) = if ((stable == 1)) |
---|
79 | 79 | | then { |
---|
80 | 80 | | let swap1 = invoke(Address(fromBase58String(p)), "exchange", [est, min], [AttachedPayment(getAssetBytes(asset), amount)]) |
---|
81 | 81 | | if ((swap1 == swap1)) |
---|
82 | 82 | | then nil |
---|
83 | 83 | | else throw("Strict value is not equal to itself.") |
---|
84 | 84 | | } |
---|
85 | 85 | | else { |
---|
86 | 86 | | let swap2 = invoke(Address(fromBase58String(p)), "exchange", [1], [AttachedPayment(getAssetBytes(asset), amount)]) |
---|
87 | 87 | | if ((swap2 == swap2)) |
---|
88 | 88 | | then nil |
---|
89 | 89 | | else throw("Strict value is not equal to itself.") |
---|
90 | 90 | | } |
---|
91 | 91 | | |
---|
92 | 92 | | |
---|
93 | 93 | | func swap_puzzle (p,asset,amount,assetOut) = { |
---|
94 | 94 | | let swap = invoke(Address(fromBase58String(p)), "swap", [assetOut, 1], [AttachedPayment(getAssetBytes(asset), amount)]) |
---|
95 | 95 | | if ((swap == swap)) |
---|
96 | 96 | | then nil |
---|
97 | 97 | | else throw("Strict value is not equal to itself.") |
---|
98 | 98 | | } |
---|
99 | 99 | | |
---|
100 | 100 | | |
---|
101 | 101 | | func getMinToReceive (amountWithoutFee) = { |
---|
102 | 102 | | let amountWithFee = (amountWithoutFee - fraction(amountWithoutFee, 6, 1000)) |
---|
104 | 104 | | $Tuple2(amountWithFee, minToReceiveWithSleepage) |
---|
105 | 105 | | } |
---|
106 | 106 | | |
---|
107 | 107 | | |
---|
108 | 108 | | @Callable(i) |
---|
109 | 109 | | func borrow (amnt) = if (if ((i.caller != boss)) |
---|
110 | 110 | | then (i.caller != free_to_borrom) |
---|
111 | 111 | | else false) |
---|
112 | 112 | | then throw("you are not allowed to borrow!") |
---|
113 | 113 | | else { |
---|
114 | 114 | | let currentBal = getBalance(USDN_ASSET_ID) |
---|
115 | 115 | | if ((amnt > currentBal)) |
---|
116 | 116 | | then throw("You cannnot borrow that much") |
---|
117 | 117 | | else [ScriptTransfer(i.caller, amnt, USDN_ASSET_ID)] |
---|
118 | 118 | | } |
---|
119 | 119 | | |
---|
120 | 120 | | |
---|
121 | 121 | | |
---|
122 | 122 | | @Callable(i) |
---|
123 | 123 | | func y (data) = if (if ((i.caller != this)) |
---|
124 | 124 | | then (i.caller != boss) |
---|
125 | 125 | | else false) |
---|
126 | 126 | | then throw("you are not allowed to arb!") |
---|
127 | 127 | | else { |
---|
128 | 128 | | let data_array = split_4C(data, "|") |
---|
129 | 129 | | let $t037213807 = getBase1(data_array[0]) |
---|
130 | 130 | | let a = $t037213807._1 |
---|
131 | 131 | | let a2 = $t037213807._2 |
---|
132 | 132 | | let assetIn = $t037213807._3 |
---|
133 | 133 | | let amountIn = $t037213807._4 |
---|
134 | 134 | | let amount_1 = $t037213807._5 |
---|
135 | 135 | | let amount_2 = $t037213807._6 |
---|
136 | 136 | | let amount_3 = $t037213807._7 |
---|
137 | 137 | | let $t038123868 = getBase2(data_array[1]) |
---|
138 | 138 | | let p1 = $t038123868._1 |
---|
139 | 139 | | let lp1 = $t038123868._2 |
---|
140 | 140 | | let is_stable_1 = $t038123868._3 |
---|
141 | 141 | | let t1 = $t038123868._4 |
---|
142 | 142 | | let $t038733929 = getBase2(data_array[2]) |
---|
143 | 143 | | let p2 = $t038733929._1 |
---|
144 | 144 | | let lp2 = $t038733929._2 |
---|
145 | 145 | | let is_stable_2 = $t038733929._3 |
---|
146 | 146 | | let t2 = $t038733929._4 |
---|
147 | 147 | | let $t039343990 = getBase2(data_array[3]) |
---|
148 | 148 | | let p3 = $t039343990._1 |
---|
149 | 149 | | let lp3 = $t039343990._2 |
---|
150 | 150 | | let is_stable_3 = $t039343990._3 |
---|
151 | 151 | | let t3 = $t039343990._4 |
---|
152 | 152 | | let $t039964062 = getPutGet(value(parseInt(is_stable_1))) |
---|
153 | 153 | | let putFunc1 = $t039964062._1 |
---|
154 | 154 | | let getFunc1 = $t039964062._2 |
---|
155 | 155 | | let $t040674133 = getPutGet(value(parseInt(is_stable_2))) |
---|
156 | 156 | | let putFunc2 = $t040674133._1 |
---|
157 | 157 | | let getFunc2 = $t040674133._2 |
---|
158 | 158 | | let $t041384204 = getPutGet(value(parseInt(is_stable_3))) |
---|
159 | 159 | | let putFunc3 = $t041384204._1 |
---|
160 | 160 | | let getFunc3 = $t041384204._2 |
---|
161 | 161 | | let amount_bef_assetIn = getBalance(getAssetBytes(assetIn)) |
---|
162 | 162 | | if ((amount_bef_assetIn == amount_bef_assetIn)) |
---|
163 | 163 | | then { |
---|
164 | 164 | | let new_amountIn = if ((value(parseInt(amountIn)) > amount_bef_assetIn)) |
---|
165 | 165 | | then amount_bef_assetIn |
---|
166 | 166 | | else value(parseInt(amountIn)) |
---|
167 | 167 | | if ((new_amountIn == new_amountIn)) |
---|
168 | 168 | | then { |
---|
169 | 169 | | let $t044104540 = if (if ((t1 == "S")) |
---|
170 | 170 | | then (value(parseInt(is_stable_1)) == 1) |
---|
171 | 171 | | else false) |
---|
172 | 172 | | then getMinToReceive(value(parseInt(amount_1))) |
---|
173 | 173 | | else $Tuple2(0, 0) |
---|
174 | 174 | | let est_1 = $t044104540._1 |
---|
175 | 175 | | let min_1 = $t044104540._2 |
---|
176 | 176 | | let $t045454675 = if (if ((t2 == "S")) |
---|
177 | 177 | | then (value(parseInt(is_stable_2)) == 1) |
---|
178 | 178 | | else false) |
---|
179 | 179 | | then getMinToReceive(value(parseInt(amount_2))) |
---|
180 | 180 | | else $Tuple2(0, 0) |
---|
181 | 181 | | let est_2 = $t045454675._1 |
---|
182 | 182 | | let min_2 = $t045454675._2 |
---|
183 | 183 | | let $t046804810 = if (if ((t3 == "S")) |
---|
184 | 184 | | then (value(parseInt(is_stable_3)) == 1) |
---|
185 | 185 | | else false) |
---|
186 | 186 | | then getMinToReceive(value(parseInt(amount_3))) |
---|
187 | 187 | | else $Tuple2(0, 0) |
---|
188 | 188 | | let est_3 = $t046804810._1 |
---|
189 | 189 | | let min_3 = $t046804810._2 |
---|
190 | 190 | | let amount_bef_asset1 = getBalance(getAssetBytes(a)) |
---|
191 | 191 | | if ((amount_bef_asset1 == amount_bef_asset1)) |
---|
192 | 192 | | then { |
---|
193 | 193 | | let swap1 = if ((t1 == "W")) |
---|
194 | 194 | | then swap_wx(p1, lp1, assetIn, new_amountIn, putFunc1, getFunc1, a) |
---|
195 | 195 | | else if ((t1 == "S")) |
---|
196 | 196 | | then swap_swop(p1, assetIn, new_amountIn, value(parseInt(is_stable_1)), est_1, min_1) |
---|
197 | 197 | | else swap_puzzle(p1, assetIn, new_amountIn, a) |
---|
198 | 198 | | if ((swap1 == swap1)) |
---|
199 | 199 | | then { |
---|
200 | 200 | | let nb = (getBalance(getAssetBytes(a)) - amount_bef_asset1) |
---|
201 | 201 | | if ((nb == nb)) |
---|
202 | 202 | | then { |
---|
203 | 203 | | let amount_bef_asset2 = getBalance(getAssetBytes(a2)) |
---|
204 | 204 | | if ((amount_bef_asset2 == amount_bef_asset2)) |
---|
205 | 205 | | then { |
---|
206 | 206 | | let swap2 = if ((t2 == "W")) |
---|
207 | 207 | | then swap_wx(p2, lp2, a, nb, putFunc2, getFunc2, a2) |
---|
208 | 208 | | else if ((t2 == "S")) |
---|
209 | 209 | | then swap_swop(p2, a, nb, value(parseInt(is_stable_2)), est_2, min_2) |
---|
210 | 210 | | else swap_puzzle(p2, a, nb, a2) |
---|
211 | 211 | | if ((swap2 == swap2)) |
---|
212 | 212 | | then { |
---|
213 | 213 | | let nb2 = (getBalance(getAssetBytes(a2)) - amount_bef_asset2) |
---|
214 | 214 | | if ((nb2 == nb2)) |
---|
215 | 215 | | then { |
---|
216 | 216 | | let amount_bef_base_asset = getBalance(getAssetBytes(assetIn)) |
---|
217 | 217 | | if ((amount_bef_base_asset == amount_bef_base_asset)) |
---|
218 | 218 | | then { |
---|
219 | 219 | | let swap3 = if ((t3 == "W")) |
---|
220 | 220 | | then swap_wx(p3, lp3, a2, nb2, putFunc3, getFunc3, assetIn) |
---|
221 | 221 | | else if ((t3 == "S")) |
---|
222 | 222 | | then swap_swop(p3, a2, nb2, value(parseInt(is_stable_3)), est_3, min_3) |
---|
223 | 223 | | else swap_puzzle(p3, a2, nb2, assetIn) |
---|
224 | 224 | | if ((swap3 == swap3)) |
---|
225 | 225 | | then { |
---|
226 | 226 | | let nb3 = (getBalance(getAssetBytes(assetIn)) - amount_bef_base_asset) |
---|
227 | 227 | | if ((nb3 == nb3)) |
---|
228 | 228 | | then if ((nb3 > (new_amountIn + 50000))) |
---|
229 | 229 | | then [ScriptTransfer(i.caller, (nb3 - new_amountIn), getAssetBytes(assetIn))] |
---|
230 | 230 | | else throw(((((((((("origin amountIn = " + amountIn) + ", new_amountIn = ") + toString(new_amountIn)) + ", newBal_1: ") + toString(nb)) + ", newBal_2: ") + toString(nb2)) + ", newBal_3: ") + toString(nb3))) |
---|
231 | 231 | | else throw("Strict value is not equal to itself.") |
---|
232 | 232 | | } |
---|
233 | 233 | | else throw("Strict value is not equal to itself.") |
---|
234 | 234 | | } |
---|
235 | 235 | | else throw("Strict value is not equal to itself.") |
---|
236 | 236 | | } |
---|
237 | 237 | | else throw("Strict value is not equal to itself.") |
---|
238 | 238 | | } |
---|
239 | 239 | | else throw("Strict value is not equal to itself.") |
---|
240 | 240 | | } |
---|
241 | 241 | | else throw("Strict value is not equal to itself.") |
---|
242 | 242 | | } |
---|
243 | 243 | | else throw("Strict value is not equal to itself.") |
---|
244 | 244 | | } |
---|
245 | 245 | | else throw("Strict value is not equal to itself.") |
---|
246 | 246 | | } |
---|
247 | 247 | | else throw("Strict value is not equal to itself.") |
---|
248 | 248 | | } |
---|
249 | 249 | | else throw("Strict value is not equal to itself.") |
---|
250 | 250 | | } |
---|
251 | 251 | | else throw("Strict value is not equal to itself.") |
---|
252 | 252 | | } |
---|
253 | 253 | | |
---|
254 | 254 | | |
---|
255 | 255 | | @Verifier(tx) |
---|
256 | 256 | | func verify () = if (sigVerify_128Kb(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) |
---|
257 | 257 | | then true |
---|
258 | 258 | | else sigVerify_128Kb(tx.bodyBytes, tx.proofs[0], adminPublicKey) |
---|
259 | 259 | | |
---|