2022.10.22 06:09 [3348434] smart account 3PHg3cFSY9dVBo6ar6HTfjZfSU2ApSQjkn3 > SELF 0.00000000 Waves
{ "type": 13, "id": "GheWQRa88TTqaBKYzUD2thtNH6VKwDDQERizrfkvcHFZ", "fee": 1000000, "feeAssetId": null, "timestamp": 1666408196398, "version": 2, "chainId": 87, "sender": "3PHg3cFSY9dVBo6ar6HTfjZfSU2ApSQjkn3", "senderPublicKey": "7FqincpDp6zjTKPa3mHNvh5fTPS3aJ4JonwFHwphjn8y", "proofs": [ "4V5bcFp6GZJtfHZ8nzX77rLd28fMF5LN6DMTxEhjP9oQLHRnzDw9YC8NkT2u1v3ysjqVN1U4CWKXxSunLJfvL2r7" ], "script": "base64:AAIFAAAAAAAAAAIIAgAAAAAAAAAAAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAQAAAAHJG1hdGNoMAUAAAACdHgDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAE1RyYW5zZmVyVHJhbnNhY3Rpb24EAAAAAnR0BQAAAAckbWF0Y2gwCQAAAAAAAAIIBQAAAAJ0dAAAAAlyZWNpcGllbnQJAQAAAAdBZGRyZXNzAAAAAQkAAlkAAAABAgAAACMzUERqYzM1NzJCMzYzU0dHYzNudEUzMkFLZ3VmUHB0alZLZgkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXmwi3gL", "height": 3348434, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: EdJ3peUuC1rekPbq2pjQNkAKqBDtyGFHT4uA62sTZjwZ Next: 9SSpt4vAubJ59os7dF6JNJTcyMWZsRCKhTYdNdbzC86Z Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let main = "main_asset" | |
5 | 4 | ||
6 | - | let l = "lp_asset_" | |
7 | - | ||
8 | - | let aa1 = "pool__" | |
9 | - | ||
10 | - | let sa = "STAKING_AMOUNT_" | |
11 | - | ||
12 | - | let la = "LEASE_AMOUNT_" | |
13 | - | ||
14 | - | let ix = "ID_" | |
15 | - | ||
16 | - | let rateFee = "percentage_rate_fee" | |
17 | - | ||
18 | - | let deposit_height = "Deposit_Height_Of_" | |
19 | - | ||
20 | - | let D8 = 100000000 | |
21 | - | ||
22 | - | let D6 = 1000000 | |
23 | - | ||
24 | - | let D10 = 10000000000 | |
25 | - | ||
26 | - | func getAddressIfValid (address) = toString(valueOrErrorMessage(addressFromString(address), (("Can't parse " + address) + " as address"))) | |
27 | - | ||
28 | - | ||
29 | - | func getAssetIfValid (assetId) = toBase58String(valueOrErrorMessage(value(assetInfo(fromBase58String(assetId))).id, (("Asset Id: " + assetId) + " is invalid."))) | |
30 | - | ||
31 | - | ||
32 | - | func getAmountBlockAsset (assetId) = match getInteger(this, assetId) { | |
33 | - | case i: Int => | |
34 | - | i | |
35 | - | case _ => | |
36 | - | 0 | |
37 | - | } | |
38 | - | ||
39 | - | ||
40 | - | func getAssetName (assetId) = match assetInfo(assetId) { | |
41 | - | case asset: Asset => | |
42 | - | asset.name | |
43 | - | case _ => | |
44 | - | throw("Can't find asset") | |
45 | - | } | |
46 | - | ||
47 | - | ||
48 | - | let ac = "activate" | |
49 | - | ||
50 | - | let poolAc = "activate_pools" | |
51 | - | ||
52 | - | let swapAc = "activate_swap" | |
53 | - | ||
54 | - | let liquidityAc = "activate_liquidity" | |
55 | - | ||
56 | - | let bcD = "block_distribuition" | |
57 | - | ||
58 | - | let total_locked = "Total_Tokens_Locked_" | |
59 | - | ||
60 | - | let usdn = "usdn_asset" | |
61 | - | ||
62 | - | let usdt = "usdt_asset" | |
63 | - | ||
64 | - | let usdc = "usdc_asset" | |
65 | - | ||
66 | - | let ngnn = "ngnn_asset" | |
67 | - | ||
68 | - | let eurn = "eurn_asset" | |
69 | - | ||
70 | - | let waves = "WAVES" | |
71 | - | ||
72 | - | let aWaves = "accept_waves" | |
73 | - | ||
74 | - | let WAVES = unit | |
75 | - | ||
76 | - | func kp (asset1,asset2) = (((aa1 + asset1) + "_") + asset2) | |
77 | - | ||
78 | - | ||
79 | - | func validPoolK (key) = match getInteger(this, key) { | |
80 | - | case i: Int => | |
81 | - | i | |
82 | - | case _ => | |
83 | - | false | |
84 | - | } | |
85 | - | ||
86 | - | ||
87 | - | func kpAddress (address,key) = match getInteger(this, ((key + "_") + address)) { | |
88 | - | case t: Int => | |
89 | - | t | |
90 | - | case _ => | |
91 | - | 0 | |
92 | - | } | |
93 | - | ||
94 | - | ||
95 | - | func poolAA (address,key,asset) = match getInteger(this, ((((address + "_") + key) + "_") + asset)) { | |
96 | - | case a: Int => | |
97 | - | a | |
98 | - | case _ => | |
99 | - | 0 | |
100 | - | } | |
101 | - | ||
102 | - | ||
103 | - | func assetP (key,asset) = match getInteger(this, ((key + "_") + asset)) { | |
104 | - | case a: Int => | |
105 | - | a | |
106 | - | case _ => | |
107 | - | 1 | |
108 | - | } | |
109 | - | ||
110 | - | ||
111 | - | func pkey (Asset1,Asset2,address) = (((deposit_height + kp(Asset1, Asset2)) + "_") + address) | |
112 | - | ||
113 | - | ||
114 | - | func lpBlocked (address,key) = match getInteger(this, ((("STAKE_LP_" + address) + "_") + key)) { | |
115 | - | case a: Int => | |
116 | - | a | |
117 | - | case _ => | |
118 | - | 0 | |
119 | - | } | |
120 | - | ||
121 | - | ||
122 | - | func adminVerification () = match getString(this, "admin") { | |
123 | - | case t: String => | |
124 | - | Address(fromBase58String(t)) | |
125 | - | case _ => | |
126 | - | this | |
127 | - | } | |
128 | - | ||
129 | - | ||
130 | - | func validateAsset (assetS,stringAsset,acWaves) = if (if ((assetS == WAVES)) | |
131 | - | then (stringAsset == waves) | |
132 | - | else false) | |
133 | - | then if (acWaves) | |
134 | - | then true | |
135 | - | else throw("The smart contract does not currently support Waves.") | |
136 | - | else if ((assetS == fromBase58String(stringAsset))) | |
137 | - | then true | |
138 | - | else false | |
139 | - | ||
140 | - | ||
141 | - | func totalAssetPool (key,assetLp) = match getInteger(this, key) { | |
142 | - | case a: Int => | |
143 | - | a | |
144 | - | case _ => | |
145 | - | if (assetLp) | |
146 | - | then (1 * D8) | |
147 | - | else 1 | |
148 | - | } | |
149 | - | ||
150 | - | ||
151 | - | func valid (assetPay,pair1,pair2) = { | |
152 | - | let pair1_58 = if ((pair1 == waves)) | |
153 | - | then WAVES | |
154 | - | else fromBase58String(pair1) | |
155 | - | let pair2_58 = if ((pair2 == waves)) | |
156 | - | then WAVES | |
157 | - | else fromBase58String(pair2) | |
158 | - | if ((assetPay == pair1_58)) | |
159 | - | then pair2_58 | |
160 | - | else pair1_58 | |
161 | - | } | |
162 | - | ||
163 | - | ||
164 | - | @Callable(i) | |
165 | - | func constructor (MainAssetId,UsdnAssetId,UsdtAssetId,UsdcAssetId,NgnnAssetId,EurnAssetId,percentageRateSwap,blockDistribution,acceptWaves) = { | |
166 | - | let keyPoolUsdtWaves = kp(UsdtAssetId, waves) | |
167 | - | if (if ((i.caller == this)) | |
168 | - | then true | |
169 | - | else (i.caller == adminVerification())) | |
170 | - | then if ((valueOrElse(getInteger(this, keyPoolUsdtWaves), 0) == 0)) | |
171 | - | then { | |
172 | - | let keyPoolUsdnUsdt = kp(UsdnAssetId, UsdtAssetId) | |
173 | - | let keyPoolUsdnUsdc = kp(UsdnAssetId, UsdcAssetId) | |
174 | - | let keyPoolUsdnNgnn = kp(UsdnAssetId, NgnnAssetId) | |
175 | - | let keyPoolUsdnWaves = kp(UsdnAssetId, waves) | |
176 | - | let keyPoolUsdnMainAsset = kp(UsdnAssetId, MainAssetId) | |
177 | - | let keyPoolUsdnEurn = kp(UsdnAssetId, EurnAssetId) | |
178 | - | let keyPoolUsdcUsdt = kp(UsdcAssetId, UsdtAssetId) | |
179 | - | let keyPoolUsdcNgnn = kp(UsdcAssetId, NgnnAssetId) | |
180 | - | let keyPoolUsdcWaves = kp(UsdcAssetId, waves) | |
181 | - | let keyPoolUsdcMainAsset = kp(UsdcAssetId, MainAssetId) | |
182 | - | let keyPoolUsdcEurn = kp(UsdcAssetId, EurnAssetId) | |
183 | - | let keyPoolUsdtNgnn = kp(UsdtAssetId, NgnnAssetId) | |
184 | - | let keyPoolUsdtMainAsset = kp(UsdtAssetId, MainAssetId) | |
185 | - | let keyPoolUsdtEurn = kp(UsdtAssetId, EurnAssetId) | |
186 | - | let keyPoolNgnnWaves = kp(NgnnAssetId, waves) | |
187 | - | let keyPoolNgnnMainAsset = kp(NgnnAssetId, MainAssetId) | |
188 | - | let keyPoolNgnnEurn = kp(NgnnAssetId, EurnAssetId) | |
189 | - | let keyPoolMainWaves = kp(MainAssetId, waves) | |
190 | - | let keyPoolMainEurn = kp(MainAssetId, EurnAssetId) | |
191 | - | let keyPoolEurnWaves = kp(EurnAssetId, waves) | |
192 | - | [StringEntry(main, MainAssetId), StringEntry(usdn, UsdnAssetId), StringEntry(usdc, UsdcAssetId), StringEntry(usdt, UsdtAssetId), StringEntry(ngnn, NgnnAssetId), BooleanEntry(aWaves, acceptWaves), IntegerEntry(rateFee, percentageRateSwap), BooleanEntry(ac, true), BooleanEntry(swapAc, false), BooleanEntry(poolAc, false), BooleanEntry(liquidityAc, false), IntegerEntry(bcD, blockDistribution), IntegerEntry(keyPoolUsdnUsdt, 1), IntegerEntry(keyPoolUsdnWaves, 1), IntegerEntry(keyPoolUsdnUsdc, 1), IntegerEntry(keyPoolUsdnNgnn, 1), IntegerEntry(keyPoolUsdnMainAsset, 1), IntegerEntry(keyPoolUsdcUsdt, 1), IntegerEntry(keyPoolUsdcNgnn, 1), IntegerEntry(keyPoolUsdcWaves, 1), IntegerEntry(keyPoolUsdtMainAsset, 1), IntegerEntry(keyPoolUsdtNgnn, 1), IntegerEntry(keyPoolUsdtWaves, 1), IntegerEntry(keyPoolNgnnWaves, 1), IntegerEntry(keyPoolNgnnMainAsset, 1), IntegerEntry(keyPoolMainWaves, 1), IntegerEntry(keyPoolEurnWaves, 1), IntegerEntry(keyPoolMainEurn, 1), IntegerEntry(keyPoolNgnnEurn, 1), IntegerEntry(keyPoolUsdcEurn, 1), IntegerEntry(keyPoolUsdnEurn, 1), IntegerEntry(keyPoolUsdtEurn, 1), IntegerEntry(keyPoolUsdcMainAsset, 1), StringEntry(eurn, EurnAssetId)] | |
193 | - | } | |
194 | - | else throw("Smart Contract has been started") | |
195 | - | else throw("Only the Admin itself can invoke this function") | |
196 | - | } | |
197 | - | ||
198 | - | ||
199 | - | ||
200 | - | @Callable(i) | |
201 | - | func activate (v) = if (if ((i.caller == this)) | |
202 | - | then true | |
203 | - | else (i.caller == adminVerification())) | |
204 | - | then [BooleanEntry(ac, v)] | |
205 | - | else throw("Only the Admin itself can invoke this function") | |
206 | - | ||
207 | - | ||
208 | - | ||
209 | - | @Callable(i) | |
210 | - | func maintenance (pools,swap,stake) = if (if ((i.caller == this)) | |
211 | - | then true | |
212 | - | else (i.caller == adminVerification())) | |
213 | - | then [BooleanEntry(poolAc, pools), BooleanEntry(swapAc, swap), BooleanEntry(liquidityAc, stake)] | |
214 | - | else throw("Only the Admin itself can invoke this function") | |
215 | - | ||
216 | - | ||
217 | - | ||
218 | - | @Callable(i) | |
219 | - | func percentualRateFeeSwapEdit (rate) = if (if ((i.caller == this)) | |
220 | - | then true | |
221 | - | else (i.caller == adminVerification())) | |
222 | - | then [IntegerEntry(rateFee, rate)] | |
223 | - | else throw("Only the Admin itself can invoke this function") | |
224 | - | ||
225 | - | ||
226 | - | ||
227 | - | @Callable(i) | |
228 | - | func acceptWaves (activate) = if (if ((i.caller == this)) | |
229 | - | then true | |
230 | - | else (i.caller == adminVerification())) | |
231 | - | then [BooleanEntry(aWaves, activate)] | |
232 | - | else throw("Only the Admin itself can invoke this function") | |
233 | - | ||
234 | - | ||
235 | - | ||
236 | - | @Callable(i) | |
237 | - | func blockDistribution (newValue) = if (if ((i.caller == this)) | |
238 | - | then true | |
239 | - | else (i.caller == adminVerification())) | |
240 | - | then [IntegerEntry(bcD, newValue)] | |
241 | - | else throw("Only the Admin itself can invoke this function") | |
242 | - | ||
243 | - | ||
244 | - | ||
245 | - | @Callable(i) | |
246 | - | func addAdmin (address) = if (if ((i.caller == this)) | |
247 | - | then true | |
248 | - | else (i.caller == adminVerification())) | |
249 | - | then [StringEntry("admin", address)] | |
250 | - | else throw("Only the Admin itself can invoke this function") | |
251 | - | ||
252 | - | ||
253 | - | ||
254 | - | @Callable(i) | |
255 | - | func lpAssetCreateForPairPool (asset1,asset2,Name,customName) = { | |
256 | - | let nameAsset1 = if ((asset1 == waves)) | |
257 | - | then waves | |
258 | - | else getAssetName(fromBase58String(asset1)) | |
259 | - | let nameAsset2 = if ((asset2 == waves)) | |
260 | - | then waves | |
261 | - | else getAssetName(fromBase58String(asset2)) | |
262 | - | let name = if (customName) | |
263 | - | then Name | |
264 | - | else ((nameAsset1 + "_") + nameAsset2) | |
265 | - | let key = validPoolK(kp(asset1, asset2)) | |
266 | - | if (if ((i.caller == this)) | |
267 | - | then true | |
268 | - | else (i.caller == adminVerification())) | |
269 | - | then if ((key != false)) | |
270 | - | then { | |
271 | - | let assetLpCreate = Issue(name, ((("LP asset for pool liquidity in AxAi Swap pair " + asset1) + "_") + asset2), (1 * D8), 8, true) | |
272 | - | let idAssetLp = calculateAssetId(assetLpCreate) | |
273 | - | [StringEntry((l + kp(asset1, asset2)), toBase58String(idAssetLp)), assetLpCreate] | |
274 | - | } | |
275 | - | else throw("Invalid Pool Key. Try inverting the assets") | |
276 | - | else throw("Only the Admin itself can invoke this function") | |
277 | - | } | |
278 | - | ||
279 | - | ||
280 | - | ||
281 | - | @Callable(i) | |
282 | - | func deposit (pool,Asset1,Asset2) = { | |
283 | - | let power = getBooleanValue(this, ac) | |
284 | - | let liquidityPower = getBooleanValue(this, liquidityAc) | |
285 | - | let MainAsset = getStringValue(this, main) | |
286 | - | let lpAssetId = if (pool) | |
287 | - | then getStringValue(this, (l + kp(Asset1, Asset2))) | |
288 | - | else MainAsset | |
289 | - | if (power) | |
290 | - | then if (!(liquidityPower)) | |
291 | - | then if ((i.payments[0].assetId != fromBase58String(lpAssetId))) | |
292 | - | then throw((("Invalid asset! Kindly Deposit Only " + MainAsset) + " or valid asset lp")) | |
293 | - | else if (!(pool)) | |
294 | - | then { | |
295 | - | let currentKey = toBase58String(i.caller.bytes) | |
296 | - | let currentAmount = match getInteger(this, currentKey) { | |
297 | - | case a: Int => | |
298 | - | a | |
299 | - | case _ => | |
300 | - | 0 | |
301 | - | } | |
302 | - | let h = if ((currentAmount == 0)) | |
303 | - | then height | |
304 | - | else valueOrElse(getIntegerValue(this, (deposit_height + currentKey)), height) | |
305 | - | let newAmount = (currentAmount + i.payments[0].amount) | |
306 | - | let useramount = IntegerEntry(currentKey, newAmount) | |
307 | - | let userdepositheight = IntegerEntry((deposit_height + currentKey), h) | |
308 | - | let previouslockbalance = match getInteger(this, "Total_Tokens_Locked:") { | |
309 | - | case a: Int => | |
310 | - | a | |
311 | - | case _ => | |
312 | - | 0 | |
313 | - | } | |
314 | - | let totaltoken = (previouslockbalance + i.payments[0].amount) | |
315 | - | let TLV = IntegerEntry("Total_Tokens_Locked:", totaltoken) | |
316 | - | [useramount, userdepositheight, TLV] | |
317 | - | } | |
318 | - | else { | |
319 | - | let poolKey = kp(Asset1, Asset2) | |
320 | - | let key = validPoolK(poolKey) | |
321 | - | if ((key != false)) | |
322 | - | then { | |
323 | - | let currentKey = toBase58String(i.caller.bytes) | |
324 | - | let currentAmount = match getInteger(this, ((("STAKE_LP_" + currentKey) + "_") + poolKey)) { | |
325 | - | case a: Int => | |
326 | - | a | |
327 | - | case _ => | |
328 | - | 0 | |
329 | - | } | |
330 | - | let h = if ((currentAmount == 0)) | |
331 | - | then height | |
332 | - | else valueOrElse(getIntegerValue(this, ((((deposit_height + "_") + currentKey) + "_") + poolKey)), height) | |
333 | - | let newAmount = (currentAmount + i.payments[0].amount) | |
334 | - | let useramount = IntegerEntry(((("STAKE_LP_" + currentKey) + "_") + poolKey), newAmount) | |
335 | - | let userdepositheight = IntegerEntry(((((deposit_height + "_") + currentKey) + "_") + poolKey), height) | |
336 | - | let previouslockbalance = match getInteger(this, ("Total_Tokens_LP_Locked_" + poolKey)) { | |
337 | - | case a: Int => | |
338 | - | a | |
339 | - | case _ => | |
340 | - | 0 | |
341 | - | } | |
342 | - | let totaltoken = (previouslockbalance + i.payments[0].amount) | |
343 | - | let TLV = IntegerEntry(("Total_Tokens_LP_Locked_" + poolKey), totaltoken) | |
344 | - | [useramount, userdepositheight, TLV] | |
345 | - | } | |
346 | - | else throw("Invalid Pool key.") | |
347 | - | } | |
348 | - | else throw("liquidity is currently under maintenance.") | |
349 | - | else throw("dApp is currently under maintenance.") | |
350 | - | } | |
351 | - | ||
352 | - | ||
353 | - | ||
354 | - | @Callable(i) | |
355 | - | func remove (pool,Asset1,Asset2,amount) = { | |
356 | - | let power = getBooleanValue(this, ac) | |
357 | - | let liquidityPower = getBooleanValue(this, liquidityAc) | |
358 | - | let pmt = i.payments[0] | |
359 | - | let MainAsset = fromBase58String(getStringValue(this, main)) | |
360 | - | if (power) | |
361 | - | then if (!(liquidityPower)) | |
362 | - | then { | |
363 | - | let currentKey = toBase58String(i.caller.bytes) | |
364 | - | let currentAmount = match if (pool) | |
365 | - | then getIntegerValue(this, ((("STAKE_LP_" + currentKey) + "_") + kp(Asset1, Asset2))) | |
366 | - | else getIntegerValue(this, currentKey) { | |
367 | - | case a: Int => | |
368 | - | a | |
369 | - | case _ => | |
370 | - | 0 | |
371 | - | } | |
372 | - | let swapheightkeyname = if (pool) | |
373 | - | then ((((deposit_height + "_") + currentKey) + "_") + kp(Asset1, Asset2)) | |
374 | - | else (deposit_height + currentKey) | |
375 | - | let previouslockbalance = if (pool) | |
376 | - | then getIntegerValue(this, ("Total_Tokens_LP_Locked_" + kp(Asset1, Asset2))) | |
377 | - | else getIntegerValue(this, "Total_Tokens_Locked:") | |
378 | - | let totaltoken = (previouslockbalance - amount) | |
379 | - | let diff = (height - getIntegerValue(this, swapheightkeyname)) | |
380 | - | let bcd = getIntegerValue(this, bcD) | |
381 | - | let reward = ((diff * bcd) * D8) | |
382 | - | let feeCalc = (reward / (previouslockbalance / amount)) | |
383 | - | if ((0 > amount)) | |
384 | - | then throw(if (pool) | |
385 | - | then (((("Can't withdraw negative " + Asset1) + "/") + Asset2) + " amount") | |
386 | - | else "Can't withdraw negative AxAi amount") | |
387 | - | else { | |
388 | - | let newAmount = (currentAmount - amount) | |
389 | - | if ((0 > newAmount)) | |
390 | - | then throw(if (pool) | |
391 | - | then (((("Not enough Asset Lp " + Asset1) + "/") + Asset2) + " balance") | |
392 | - | else "Not enough AxAi balance") | |
393 | - | else [IntegerEntry(if (pool) | |
394 | - | then ((("STAKE_LP_" + currentKey) + "_") + kp(Asset1, Asset2)) | |
395 | - | else currentKey, newAmount), IntegerEntry(if (pool) | |
396 | - | then ("Total_Tokens_LP_Locked_" + kp(Asset1, Asset2)) | |
397 | - | else "Total_Tokens_Locked:", totaltoken), ScriptTransfer(i.caller, amount, if (pool) | |
398 | - | then fromBase58String(getStringValue(this, (l + kp(Asset1, Asset2)))) | |
399 | - | else MainAsset), ScriptTransfer(i.caller, feeCalc, MainAsset)] | |
400 | - | } | |
401 | - | } | |
402 | - | else throw("liquidity is currently under maintenance.") | |
403 | - | else throw("dApp is currently under maintenance.") | |
404 | - | } | |
405 | - | ||
406 | - | ||
407 | - | ||
408 | - | @Callable(i) | |
409 | - | func addLiquidity (Asset1,Asset2) = { | |
410 | - | let power = getBooleanValue(this, ac) | |
411 | - | let poolActivate = getBooleanValue(this, poolAc) | |
412 | - | let acWaves = getBooleanValue(this, aWaves) | |
413 | - | let key = validPoolK(kp(Asset1, Asset2)) | |
414 | - | let asset1 = i.payments[0].assetId | |
415 | - | let asset2 = i.payments[1].assetId | |
416 | - | let USDN = fromBase58String(getStringValue(this, usdn)) | |
417 | - | let USDC = fromBase58String(getStringValue(this, usdc)) | |
418 | - | let USDT = fromBase58String(getStringValue(this, usdt)) | |
419 | - | let NGNN = fromBase58String(getStringValue(this, ngnn)) | |
420 | - | let EURN = fromBase58String(getStringValue(this, eurn)) | |
421 | - | let MainAsset = fromBase58String(getStringValue(this, main)) | |
422 | - | let lpAssetId = getStringValue(this, (l + kp(Asset1, Asset2))) | |
423 | - | let totalAsset1Pool = if ((2 > totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset1), false))) | |
424 | - | then i.payments[0].amount | |
425 | - | else totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset1), false) | |
426 | - | let totalAsset2Pool = if ((2 > totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset1), false))) | |
427 | - | then i.payments[1].amount | |
428 | - | else totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset2), false) | |
429 | - | let totalLp = totalAssetPool(lpAssetId, true) | |
430 | - | let priceLpAsset = ((totalAsset1Pool + totalAsset2Pool) / totalLp) | |
431 | - | let quantityAsset2 = (i.payments[0].amount * (totalAsset2Pool / totalAsset1Pool)) | |
432 | - | let rateTop = (i.payments[1].amount + ((i.payments[1].amount * 2) / 100)) | |
433 | - | let rateBottom = (i.payments[1].amount - ((i.payments[1].amount * 2) / 100)) | |
434 | - | let Validate = if (if (if ((i.payments[1].amount == quantityAsset2)) | |
435 | - | then true | |
436 | - | else (rateTop > i.payments[1].amount)) | |
437 | - | then true | |
438 | - | else (i.payments[1].amount > rateBottom)) | |
439 | - | then true | |
440 | - | else false | |
441 | - | if (power) | |
442 | - | then if (!(poolActivate)) | |
443 | - | then if (if (if (!((asset1 == asset2))) | |
444 | - | then validateAsset(asset1, Asset1, acWaves) | |
445 | - | else false) | |
446 | - | then validateAsset(asset2, Asset2, acWaves) | |
447 | - | else false) | |
448 | - | then if (if (if (if (if (if (if (if ((asset1 == USDN)) | |
449 | - | then true | |
450 | - | else (asset1 == USDC)) | |
451 | - | then true | |
452 | - | else (asset1 == USDT)) | |
453 | - | then true | |
454 | - | else (asset1 == NGNN)) | |
455 | - | then true | |
456 | - | else (asset1 == MainAsset)) | |
457 | - | then true | |
458 | - | else (asset1 == WAVES)) | |
459 | - | then true | |
460 | - | else (asset1 == EURN)) | |
461 | - | then if (if (if (if (if (if ((asset2 == USDN)) | |
462 | - | then true | |
463 | - | else (asset2 == USDC)) | |
464 | - | then true | |
465 | - | else (asset2 == USDT)) | |
466 | - | then true | |
467 | - | else (asset2 == NGNN)) | |
468 | - | then true | |
469 | - | else (asset2 == MainAsset)) | |
470 | - | then true | |
471 | - | else (asset2 == WAVES)) | |
472 | - | then true | |
473 | - | else (asset2 == EURN) | |
474 | - | else false) | |
475 | - | then if ((key != false)) | |
476 | - | then if (Validate) | |
477 | - | then { | |
478 | - | let currentKey = toBase58String(i.caller.bytes) | |
479 | - | let currentAmount = kpAddress(currentKey, kp(Asset1, Asset2)) | |
480 | - | let currentAmountAsset1 = poolAA(currentKey, kp(Asset1, Asset2), Asset1) | |
481 | - | let currentAmountAsset2 = poolAA(currentKey, kp(Asset1, Asset2), Asset2) | |
482 | - | let asset1pool = assetP(kp(Asset1, Asset2), Asset1) | |
483 | - | let asset2pool = assetP(kp(Asset1, Asset2), Asset2) | |
484 | - | let receiveLp = if ((totalAsset1Pool == i.payments[0].amount)) | |
485 | - | then (1 * D8) | |
486 | - | else toInt((((toBigInt(i.payments[0].amount) * toBigInt(D8)) + (toBigInt(i.payments[1].amount) * toBigInt(D8))) / (((toBigInt(totalAsset1Pool) * toBigInt(D8)) + (toBigInt(totalAsset2Pool) * toBigInt(D8))) / toBigInt(totalLp)))) | |
487 | - | let newcurrentAmountAsset1 = (currentAmountAsset1 + i.payments[0].amount) | |
488 | - | let newcurrentAmountAsset2 = (currentAmountAsset2 + i.payments[1].amount) | |
489 | - | let newcurrentAmount = (currentAmount + receiveLp) | |
490 | - | let newasset1pool = (asset1pool + i.payments[0].amount) | |
491 | - | let newasset2pool = (asset2pool + i.payments[1].amount) | |
492 | - | [Reissue(fromBase58String(lpAssetId), receiveLp, true), ScriptTransfer(Address(i.caller.bytes), receiveLp, fromBase58String(lpAssetId)), IntegerEntry(pkey(Asset1, Asset2, currentKey), height), IntegerEntry(((((currentKey + "_") + kp(Asset1, Asset2)) + "_") + Asset1), newcurrentAmountAsset1), IntegerEntry(((((currentKey + "_") + kp(Asset1, Asset2)) + "_") + Asset2), newcurrentAmountAsset2), IntegerEntry(((kp(Asset1, Asset2) + "_") + currentKey), newcurrentAmount), IntegerEntry(((kp(Asset1, Asset2) + "_") + Asset1), newasset1pool), IntegerEntry(((kp(Asset1, Asset2) + "_") + Asset2), newasset2pool), IntegerEntry(Asset1, (getAmountBlockAsset(Asset1) + i.payments[0].amount)), IntegerEntry(Asset2, (getAmountBlockAsset(Asset2) + i.payments[1].amount)), IntegerEntry(lpAssetId, (getAmountBlockAsset(lpAssetId) + receiveLp))] | |
493 | - | } | |
494 | - | else throw(((((("Payment of invalid 1/1 amounts to the Pool. Try Asset2: {value:" + toString((i.payments[0].amount * (totalAsset2Pool / totalAsset1Pool)))) + "} Received: ") + toString(i.payments[1].amount)) + " Validate: ") + toString(Validate))) | |
495 | - | else throw("Invalid Pool Key.") | |
496 | - | else throw("Invalid Asset1 or Asset2!") | |
497 | - | else throw("Asset1 cannot be equal to Asset2") | |
498 | - | else throw("liquidity is currently under maintenance.") | |
499 | - | else throw("dApp is currently under maintenance.") | |
500 | - | } | |
501 | - | ||
502 | - | ||
503 | - | ||
504 | - | @Callable(i) | |
505 | - | func removeLiquidity (Asset1,Asset2,Amount) = { | |
506 | - | let currentKey = toBase58String(i.caller.bytes) | |
507 | - | let power = getBooleanValue(this, ac) | |
508 | - | let poolActivate = getBooleanValue(this, poolAc) | |
509 | - | let acWaves = getBooleanValue(this, aWaves) | |
510 | - | let poolKey = kp(Asset1, Asset2) | |
511 | - | let key = validPoolK(poolKey) | |
512 | - | let asset1 = if ((Asset1 == waves)) | |
513 | - | then if (acWaves) | |
514 | - | then WAVES | |
515 | - | else throw("The smart contract does not currently support Waves.") | |
516 | - | else fromBase58String(Asset1) | |
517 | - | let asset2 = if ((Asset2 == waves)) | |
518 | - | then if (acWaves) | |
519 | - | then WAVES | |
520 | - | else throw("The smart contract does not currently support Waves.") | |
521 | - | else fromBase58String(Asset2) | |
522 | - | let USDN = fromBase58String(getStringValue(this, usdn)) | |
523 | - | let USDC = fromBase58String(getStringValue(this, usdc)) | |
524 | - | let USDT = fromBase58String(getStringValue(this, usdt)) | |
525 | - | let NGNN = fromBase58String(getStringValue(this, ngnn)) | |
526 | - | let MainAsset = fromBase58String(getStringValue(this, main)) | |
527 | - | let EURN = fromBase58String(getStringValue(this, eurn)) | |
528 | - | let lpAssetId = getStringValue(this, (l + kp(Asset1, Asset2))) | |
529 | - | let currentAmount = kpAddress(currentKey, kp(Asset1, Asset2)) | |
530 | - | let amountLpBlocked = lpBlocked(currentKey, poolKey) | |
531 | - | let totalLP = totalAssetPool(lpAssetId, true) | |
532 | - | let totalAsset1Pool = totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset1), false) | |
533 | - | let totalAsset2Pool = totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset2), false) | |
534 | - | if (power) | |
535 | - | then if (!(poolActivate)) | |
536 | - | then if (!((Asset1 == Asset2))) | |
537 | - | then if (if (if (if (if (if (if (if ((asset1 == USDN)) | |
538 | - | then true | |
539 | - | else (asset1 == USDC)) | |
540 | - | then true | |
541 | - | else (asset1 == USDT)) | |
542 | - | then true | |
543 | - | else (asset1 == NGNN)) | |
544 | - | then true | |
545 | - | else (asset1 == MainAsset)) | |
546 | - | then true | |
547 | - | else (asset1 == WAVES)) | |
548 | - | then true | |
549 | - | else (asset1 == EURN)) | |
550 | - | then if (if (if (if (if (if ((asset2 == USDN)) | |
551 | - | then true | |
552 | - | else (asset2 == USDC)) | |
553 | - | then true | |
554 | - | else (asset2 == USDT)) | |
555 | - | then true | |
556 | - | else (asset2 == NGNN)) | |
557 | - | then true | |
558 | - | else (asset2 == MainAsset)) | |
559 | - | then true | |
560 | - | else (asset2 == WAVES)) | |
561 | - | then true | |
562 | - | else (asset2 == EURN) | |
563 | - | else false) | |
564 | - | then if ((key != false)) | |
565 | - | then if (!((currentAmount == 0))) | |
566 | - | then if (((currentAmount - amountLpBlocked) >= Amount)) | |
567 | - | then if (if ((totalAsset1Pool > 2)) | |
568 | - | then true | |
569 | - | else (totalAsset2Pool > 2)) | |
570 | - | then { | |
571 | - | let receiveAsset1 = (toInt(((fraction(toBigInt(i.payments[0].amount), toBigInt(D8), toBigInt(totalLP)) * toBigInt(totalAsset1Pool)) / toBigInt(D8))) - 1) | |
572 | - | let receiveAsset2 = (toInt(((fraction(toBigInt(i.payments[0].amount), toBigInt(D8), toBigInt(totalLP)) * toBigInt(totalAsset2Pool)) / toBigInt(D8))) - 1) | |
573 | - | let asset1pool = assetP(kp(Asset1, Asset2), Asset1) | |
574 | - | let asset2pool = assetP(kp(Asset1, Asset2), Asset2) | |
575 | - | let currentAmountAsset1 = poolAA(currentKey, kp(Asset1, Asset2), Asset1) | |
576 | - | let currentAmountAsset2 = poolAA(currentKey, kp(Asset1, Asset2), Asset2) | |
577 | - | let newcurrentAmountAsset1 = (currentAmountAsset1 - receiveAsset1) | |
578 | - | let newcurrentAmountAsset2 = (currentAmountAsset2 - receiveAsset2) | |
579 | - | let newcurrentAmount = (currentAmount - Amount) | |
580 | - | let newasset1pool = (asset1pool - receiveAsset1) | |
581 | - | let newasset2pool = (asset2pool - receiveAsset2) | |
582 | - | if ((i.payments[0].assetId == fromBase58String(lpAssetId))) | |
583 | - | then if ((Amount == i.payments[0].amount)) | |
584 | - | then [Burn(fromBase58String(lpAssetId), Amount), ScriptTransfer(Address(i.caller.bytes), receiveAsset1, asset1), ScriptTransfer(Address(i.caller.bytes), receiveAsset2, asset2), IntegerEntry(pkey(Asset1, Asset2, currentKey), height), IntegerEntry(((((currentKey + "_") + kp(Asset1, Asset2)) + "_") + Asset1), newcurrentAmountAsset1), IntegerEntry(((((currentKey + "_") + kp(Asset1, Asset2)) + "_") + Asset2), newcurrentAmountAsset2), IntegerEntry(((kp(Asset1, Asset2) + "_") + currentKey), newcurrentAmount), IntegerEntry(((kp(Asset1, Asset2) + "_") + Asset1), newasset1pool), IntegerEntry(((kp(Asset1, Asset2) + "_") + Asset2), newasset2pool), IntegerEntry(Asset1, (getAmountBlockAsset(Asset1) - receiveAsset1)), IntegerEntry(Asset2, (getAmountBlockAsset(Asset2) - receiveAsset2)), IntegerEntry(lpAssetId, (getAmountBlockAsset(lpAssetId) - Amount))] | |
585 | - | else throw(("Withdrawal amount lower than asset lp amount. Your Lp amount available: " + toString(Amount))) | |
586 | - | else throw("Requires an lp asset as payment to remove locked amounts.") | |
587 | - | } | |
588 | - | else throw("Pool has no liquidity.") | |
589 | - | else throw(("Amount to be withdrawn greater than the amount available for withdrawal. Available: " + toString(Amount))) | |
590 | - | else throw("You have no locked values in the pool") | |
591 | - | else throw("Invalid Pool Key.") | |
592 | - | else throw("Invalid Asset1 or Asset2!") | |
593 | - | else throw("Asset1 cannot be equal to Asset2") | |
594 | - | else throw("liquidity is currently under maintenance.") | |
595 | - | else throw("dApp is currently under maintenance.") | |
596 | - | } | |
597 | - | ||
598 | - | ||
599 | - | ||
600 | - | @Callable(i) | |
601 | - | func swap (Asset1,Asset2) = { | |
602 | - | let currentKey = toBase58String(i.caller.bytes) | |
603 | - | let acWaves = getBooleanValue(this, aWaves) | |
604 | - | let power = getBooleanValue(this, ac) | |
605 | - | let swapActivate = getBooleanValue(this, swapAc) | |
606 | - | let poolKey = kp(Asset1, Asset2) | |
607 | - | let key = validPoolK(poolKey) | |
608 | - | let asset1 = i.payments[0].assetId | |
609 | - | let USDN = fromBase58String(getStringValue(this, usdn)) | |
610 | - | let USDC = fromBase58String(getStringValue(this, usdc)) | |
611 | - | let USDT = fromBase58String(getStringValue(this, usdt)) | |
612 | - | let NGNN = fromBase58String(getStringValue(this, ngnn)) | |
613 | - | let MainAsset = fromBase58String(getStringValue(this, main)) | |
614 | - | let EURN = fromBase58String(getStringValue(this, eurn)) | |
615 | - | let lpAssetId = getStringValue(this, (l + kp(Asset1, Asset2))) | |
616 | - | let totalAsset1 = totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset1), false) | |
617 | - | let totalAsset2 = totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset2), false) | |
618 | - | let feeRatePercentual = getIntegerValue(this, rateFee) | |
619 | - | let prAsset1 = (toBigInt(i.payments[0].amount) * fraction(toBigInt(D8), toBigInt(totalAsset2), toBigInt(totalAsset1))) | |
620 | - | let priceAsset1 = toInt(((prAsset1 - ((prAsset1 / toBigInt(feeRatePercentual)) * toBigInt(100))) / toBigInt(D8))) | |
621 | - | let prAsset2 = (toBigInt(i.payments[0].amount) * fraction(toBigInt(D8), toBigInt(totalAsset1), toBigInt(totalAsset2))) | |
622 | - | let priceAsset2 = toInt(((prAsset2 - ((prAsset2 / toBigInt(feeRatePercentual)) * toBigInt(100))) / toBigInt(D8))) | |
623 | - | let sendValue = if (if ((asset1 == WAVES)) | |
624 | - | then (Asset1 == waves) | |
625 | - | else false) | |
626 | - | then priceAsset1 | |
627 | - | else if ((asset1 == fromBase58String(Asset1))) | |
628 | - | then priceAsset1 | |
629 | - | else priceAsset2 | |
630 | - | let assetUpdatePay = if ((asset1 == WAVES)) | |
631 | - | then waves | |
632 | - | else if ((asset1 == fromBase58String(Asset1))) | |
633 | - | then Asset1 | |
634 | - | else Asset2 | |
635 | - | let assetUpdateSwap = if ((asset1 == WAVES)) | |
636 | - | then waves | |
637 | - | else if ((asset1 == fromBase58String(Asset1))) | |
638 | - | then Asset2 | |
639 | - | else Asset1 | |
640 | - | let assetSendSwap = valid(i.payments[0].assetId, Asset1, Asset2) | |
641 | - | let n1s = (assetP(kp(Asset1, Asset2), assetUpdateSwap) - sendValue) | |
642 | - | let nw = (getAmountBlockAsset(assetUpdateSwap) - sendValue) | |
643 | - | let newUpda = if ((0 > n1s)) | |
644 | - | then 0 | |
645 | - | else n1s | |
646 | - | let newUpdateSwap = if ((0 > nw)) | |
647 | - | then 0 | |
648 | - | else nw | |
649 | - | let D = match i.payments[0].assetId { | |
650 | - | case o: Unit => | |
651 | - | pow(10, 0, 8, 0, 0, HALFUP) | |
652 | - | case x: ByteVector => | |
653 | - | pow(10, 0, value(assetInfo(x)).decimals, 0, 0, HALFUP) | |
654 | - | case _ => | |
655 | - | throw("Match error") | |
656 | - | } | |
657 | - | if (power) | |
658 | - | then if (!(swapActivate)) | |
659 | - | then if (if (!((Asset1 == Asset2))) | |
660 | - | then if (validateAsset(asset1, Asset1, acWaves)) | |
661 | - | then true | |
662 | - | else validateAsset(asset1, Asset2, acWaves) | |
663 | - | else false) | |
664 | - | then if (if (if (if (if (if (if ((asset1 == USDN)) | |
665 | - | then true | |
666 | - | else (asset1 == USDC)) | |
667 | - | then true | |
668 | - | else (asset1 == USDT)) | |
669 | - | then true | |
670 | - | else (asset1 == NGNN)) | |
671 | - | then true | |
672 | - | else (asset1 == MainAsset)) | |
673 | - | then true | |
674 | - | else (asset1 == EURN)) | |
675 | - | then true | |
676 | - | else (asset1 == WAVES)) | |
677 | - | then if ((key != false)) | |
678 | - | then if ((i.payments[1].assetId == MainAsset)) | |
679 | - | then if ((i.payments[1].amount == 300000)) | |
680 | - | then if (if ((totalAsset1 > 2)) | |
681 | - | then true | |
682 | - | else (totalAsset2 > 2)) | |
683 | - | then [ScriptTransfer(Address(i.caller.bytes), if ((0 > sendValue)) | |
684 | - | then D | |
685 | - | else sendValue, assetSendSwap), IntegerEntry(assetUpdateSwap, newUpdateSwap), IntegerEntry(((kp(Asset1, Asset2) + "_") + assetUpdateSwap), newUpda), IntegerEntry(((kp(Asset1, Asset2) + "_") + assetUpdatePay), (assetP(kp(Asset1, Asset2), assetUpdatePay) + i.payments[0].amount)), IntegerEntry(assetUpdatePay, (getAmountBlockAsset(assetUpdatePay) + i.payments[0].amount)), IntegerEntry(toBase58String(MainAsset), (getAmountBlockAsset(toBase58String(MainAsset)) + i.payments[1].amount))] | |
686 | - | else throw("Pool has no liquidity.") | |
687 | - | else throw("Swap denied! 0.003 AxAi is required for the swap fee.") | |
688 | - | else throw("Invalid rate asset") | |
689 | - | else throw("Invalid Swap Key.") | |
690 | - | else throw("Invalid Asset1 or Asset2!") | |
691 | - | else throw("Asset1 cannot be equal to Asset2") | |
692 | - | else throw("Swap is currently under maintenance.") | |
693 | - | else throw("dApp is currently under maintenance.") | |
694 | - | } | |
695 | 5 | ||
696 | 6 | ||
697 | 7 | @Verifier(tx) | |
698 | 8 | func verify () = match tx { | |
699 | - | case order: Order => | |
700 | - | true | |
701 | - | case e: ExchangeTransaction => | |
702 | - | true | |
703 | 9 | case tt: TransferTransaction => | |
704 | - | (tt.recipient == Address(fromBase58String( | |
10 | + | (tt.recipient == Address(fromBase58String("3PDjc3572B363SGGc3ntE32AKgufPptjVKf"))) | |
705 | 11 | case _ => | |
706 | 12 | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
707 | 13 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let main = "main_asset" | |
5 | 4 | ||
6 | - | let l = "lp_asset_" | |
7 | - | ||
8 | - | let aa1 = "pool__" | |
9 | - | ||
10 | - | let sa = "STAKING_AMOUNT_" | |
11 | - | ||
12 | - | let la = "LEASE_AMOUNT_" | |
13 | - | ||
14 | - | let ix = "ID_" | |
15 | - | ||
16 | - | let rateFee = "percentage_rate_fee" | |
17 | - | ||
18 | - | let deposit_height = "Deposit_Height_Of_" | |
19 | - | ||
20 | - | let D8 = 100000000 | |
21 | - | ||
22 | - | let D6 = 1000000 | |
23 | - | ||
24 | - | let D10 = 10000000000 | |
25 | - | ||
26 | - | func getAddressIfValid (address) = toString(valueOrErrorMessage(addressFromString(address), (("Can't parse " + address) + " as address"))) | |
27 | - | ||
28 | - | ||
29 | - | func getAssetIfValid (assetId) = toBase58String(valueOrErrorMessage(value(assetInfo(fromBase58String(assetId))).id, (("Asset Id: " + assetId) + " is invalid."))) | |
30 | - | ||
31 | - | ||
32 | - | func getAmountBlockAsset (assetId) = match getInteger(this, assetId) { | |
33 | - | case i: Int => | |
34 | - | i | |
35 | - | case _ => | |
36 | - | 0 | |
37 | - | } | |
38 | - | ||
39 | - | ||
40 | - | func getAssetName (assetId) = match assetInfo(assetId) { | |
41 | - | case asset: Asset => | |
42 | - | asset.name | |
43 | - | case _ => | |
44 | - | throw("Can't find asset") | |
45 | - | } | |
46 | - | ||
47 | - | ||
48 | - | let ac = "activate" | |
49 | - | ||
50 | - | let poolAc = "activate_pools" | |
51 | - | ||
52 | - | let swapAc = "activate_swap" | |
53 | - | ||
54 | - | let liquidityAc = "activate_liquidity" | |
55 | - | ||
56 | - | let bcD = "block_distribuition" | |
57 | - | ||
58 | - | let total_locked = "Total_Tokens_Locked_" | |
59 | - | ||
60 | - | let usdn = "usdn_asset" | |
61 | - | ||
62 | - | let usdt = "usdt_asset" | |
63 | - | ||
64 | - | let usdc = "usdc_asset" | |
65 | - | ||
66 | - | let ngnn = "ngnn_asset" | |
67 | - | ||
68 | - | let eurn = "eurn_asset" | |
69 | - | ||
70 | - | let waves = "WAVES" | |
71 | - | ||
72 | - | let aWaves = "accept_waves" | |
73 | - | ||
74 | - | let WAVES = unit | |
75 | - | ||
76 | - | func kp (asset1,asset2) = (((aa1 + asset1) + "_") + asset2) | |
77 | - | ||
78 | - | ||
79 | - | func validPoolK (key) = match getInteger(this, key) { | |
80 | - | case i: Int => | |
81 | - | i | |
82 | - | case _ => | |
83 | - | false | |
84 | - | } | |
85 | - | ||
86 | - | ||
87 | - | func kpAddress (address,key) = match getInteger(this, ((key + "_") + address)) { | |
88 | - | case t: Int => | |
89 | - | t | |
90 | - | case _ => | |
91 | - | 0 | |
92 | - | } | |
93 | - | ||
94 | - | ||
95 | - | func poolAA (address,key,asset) = match getInteger(this, ((((address + "_") + key) + "_") + asset)) { | |
96 | - | case a: Int => | |
97 | - | a | |
98 | - | case _ => | |
99 | - | 0 | |
100 | - | } | |
101 | - | ||
102 | - | ||
103 | - | func assetP (key,asset) = match getInteger(this, ((key + "_") + asset)) { | |
104 | - | case a: Int => | |
105 | - | a | |
106 | - | case _ => | |
107 | - | 1 | |
108 | - | } | |
109 | - | ||
110 | - | ||
111 | - | func pkey (Asset1,Asset2,address) = (((deposit_height + kp(Asset1, Asset2)) + "_") + address) | |
112 | - | ||
113 | - | ||
114 | - | func lpBlocked (address,key) = match getInteger(this, ((("STAKE_LP_" + address) + "_") + key)) { | |
115 | - | case a: Int => | |
116 | - | a | |
117 | - | case _ => | |
118 | - | 0 | |
119 | - | } | |
120 | - | ||
121 | - | ||
122 | - | func adminVerification () = match getString(this, "admin") { | |
123 | - | case t: String => | |
124 | - | Address(fromBase58String(t)) | |
125 | - | case _ => | |
126 | - | this | |
127 | - | } | |
128 | - | ||
129 | - | ||
130 | - | func validateAsset (assetS,stringAsset,acWaves) = if (if ((assetS == WAVES)) | |
131 | - | then (stringAsset == waves) | |
132 | - | else false) | |
133 | - | then if (acWaves) | |
134 | - | then true | |
135 | - | else throw("The smart contract does not currently support Waves.") | |
136 | - | else if ((assetS == fromBase58String(stringAsset))) | |
137 | - | then true | |
138 | - | else false | |
139 | - | ||
140 | - | ||
141 | - | func totalAssetPool (key,assetLp) = match getInteger(this, key) { | |
142 | - | case a: Int => | |
143 | - | a | |
144 | - | case _ => | |
145 | - | if (assetLp) | |
146 | - | then (1 * D8) | |
147 | - | else 1 | |
148 | - | } | |
149 | - | ||
150 | - | ||
151 | - | func valid (assetPay,pair1,pair2) = { | |
152 | - | let pair1_58 = if ((pair1 == waves)) | |
153 | - | then WAVES | |
154 | - | else fromBase58String(pair1) | |
155 | - | let pair2_58 = if ((pair2 == waves)) | |
156 | - | then WAVES | |
157 | - | else fromBase58String(pair2) | |
158 | - | if ((assetPay == pair1_58)) | |
159 | - | then pair2_58 | |
160 | - | else pair1_58 | |
161 | - | } | |
162 | - | ||
163 | - | ||
164 | - | @Callable(i) | |
165 | - | func constructor (MainAssetId,UsdnAssetId,UsdtAssetId,UsdcAssetId,NgnnAssetId,EurnAssetId,percentageRateSwap,blockDistribution,acceptWaves) = { | |
166 | - | let keyPoolUsdtWaves = kp(UsdtAssetId, waves) | |
167 | - | if (if ((i.caller == this)) | |
168 | - | then true | |
169 | - | else (i.caller == adminVerification())) | |
170 | - | then if ((valueOrElse(getInteger(this, keyPoolUsdtWaves), 0) == 0)) | |
171 | - | then { | |
172 | - | let keyPoolUsdnUsdt = kp(UsdnAssetId, UsdtAssetId) | |
173 | - | let keyPoolUsdnUsdc = kp(UsdnAssetId, UsdcAssetId) | |
174 | - | let keyPoolUsdnNgnn = kp(UsdnAssetId, NgnnAssetId) | |
175 | - | let keyPoolUsdnWaves = kp(UsdnAssetId, waves) | |
176 | - | let keyPoolUsdnMainAsset = kp(UsdnAssetId, MainAssetId) | |
177 | - | let keyPoolUsdnEurn = kp(UsdnAssetId, EurnAssetId) | |
178 | - | let keyPoolUsdcUsdt = kp(UsdcAssetId, UsdtAssetId) | |
179 | - | let keyPoolUsdcNgnn = kp(UsdcAssetId, NgnnAssetId) | |
180 | - | let keyPoolUsdcWaves = kp(UsdcAssetId, waves) | |
181 | - | let keyPoolUsdcMainAsset = kp(UsdcAssetId, MainAssetId) | |
182 | - | let keyPoolUsdcEurn = kp(UsdcAssetId, EurnAssetId) | |
183 | - | let keyPoolUsdtNgnn = kp(UsdtAssetId, NgnnAssetId) | |
184 | - | let keyPoolUsdtMainAsset = kp(UsdtAssetId, MainAssetId) | |
185 | - | let keyPoolUsdtEurn = kp(UsdtAssetId, EurnAssetId) | |
186 | - | let keyPoolNgnnWaves = kp(NgnnAssetId, waves) | |
187 | - | let keyPoolNgnnMainAsset = kp(NgnnAssetId, MainAssetId) | |
188 | - | let keyPoolNgnnEurn = kp(NgnnAssetId, EurnAssetId) | |
189 | - | let keyPoolMainWaves = kp(MainAssetId, waves) | |
190 | - | let keyPoolMainEurn = kp(MainAssetId, EurnAssetId) | |
191 | - | let keyPoolEurnWaves = kp(EurnAssetId, waves) | |
192 | - | [StringEntry(main, MainAssetId), StringEntry(usdn, UsdnAssetId), StringEntry(usdc, UsdcAssetId), StringEntry(usdt, UsdtAssetId), StringEntry(ngnn, NgnnAssetId), BooleanEntry(aWaves, acceptWaves), IntegerEntry(rateFee, percentageRateSwap), BooleanEntry(ac, true), BooleanEntry(swapAc, false), BooleanEntry(poolAc, false), BooleanEntry(liquidityAc, false), IntegerEntry(bcD, blockDistribution), IntegerEntry(keyPoolUsdnUsdt, 1), IntegerEntry(keyPoolUsdnWaves, 1), IntegerEntry(keyPoolUsdnUsdc, 1), IntegerEntry(keyPoolUsdnNgnn, 1), IntegerEntry(keyPoolUsdnMainAsset, 1), IntegerEntry(keyPoolUsdcUsdt, 1), IntegerEntry(keyPoolUsdcNgnn, 1), IntegerEntry(keyPoolUsdcWaves, 1), IntegerEntry(keyPoolUsdtMainAsset, 1), IntegerEntry(keyPoolUsdtNgnn, 1), IntegerEntry(keyPoolUsdtWaves, 1), IntegerEntry(keyPoolNgnnWaves, 1), IntegerEntry(keyPoolNgnnMainAsset, 1), IntegerEntry(keyPoolMainWaves, 1), IntegerEntry(keyPoolEurnWaves, 1), IntegerEntry(keyPoolMainEurn, 1), IntegerEntry(keyPoolNgnnEurn, 1), IntegerEntry(keyPoolUsdcEurn, 1), IntegerEntry(keyPoolUsdnEurn, 1), IntegerEntry(keyPoolUsdtEurn, 1), IntegerEntry(keyPoolUsdcMainAsset, 1), StringEntry(eurn, EurnAssetId)] | |
193 | - | } | |
194 | - | else throw("Smart Contract has been started") | |
195 | - | else throw("Only the Admin itself can invoke this function") | |
196 | - | } | |
197 | - | ||
198 | - | ||
199 | - | ||
200 | - | @Callable(i) | |
201 | - | func activate (v) = if (if ((i.caller == this)) | |
202 | - | then true | |
203 | - | else (i.caller == adminVerification())) | |
204 | - | then [BooleanEntry(ac, v)] | |
205 | - | else throw("Only the Admin itself can invoke this function") | |
206 | - | ||
207 | - | ||
208 | - | ||
209 | - | @Callable(i) | |
210 | - | func maintenance (pools,swap,stake) = if (if ((i.caller == this)) | |
211 | - | then true | |
212 | - | else (i.caller == adminVerification())) | |
213 | - | then [BooleanEntry(poolAc, pools), BooleanEntry(swapAc, swap), BooleanEntry(liquidityAc, stake)] | |
214 | - | else throw("Only the Admin itself can invoke this function") | |
215 | - | ||
216 | - | ||
217 | - | ||
218 | - | @Callable(i) | |
219 | - | func percentualRateFeeSwapEdit (rate) = if (if ((i.caller == this)) | |
220 | - | then true | |
221 | - | else (i.caller == adminVerification())) | |
222 | - | then [IntegerEntry(rateFee, rate)] | |
223 | - | else throw("Only the Admin itself can invoke this function") | |
224 | - | ||
225 | - | ||
226 | - | ||
227 | - | @Callable(i) | |
228 | - | func acceptWaves (activate) = if (if ((i.caller == this)) | |
229 | - | then true | |
230 | - | else (i.caller == adminVerification())) | |
231 | - | then [BooleanEntry(aWaves, activate)] | |
232 | - | else throw("Only the Admin itself can invoke this function") | |
233 | - | ||
234 | - | ||
235 | - | ||
236 | - | @Callable(i) | |
237 | - | func blockDistribution (newValue) = if (if ((i.caller == this)) | |
238 | - | then true | |
239 | - | else (i.caller == adminVerification())) | |
240 | - | then [IntegerEntry(bcD, newValue)] | |
241 | - | else throw("Only the Admin itself can invoke this function") | |
242 | - | ||
243 | - | ||
244 | - | ||
245 | - | @Callable(i) | |
246 | - | func addAdmin (address) = if (if ((i.caller == this)) | |
247 | - | then true | |
248 | - | else (i.caller == adminVerification())) | |
249 | - | then [StringEntry("admin", address)] | |
250 | - | else throw("Only the Admin itself can invoke this function") | |
251 | - | ||
252 | - | ||
253 | - | ||
254 | - | @Callable(i) | |
255 | - | func lpAssetCreateForPairPool (asset1,asset2,Name,customName) = { | |
256 | - | let nameAsset1 = if ((asset1 == waves)) | |
257 | - | then waves | |
258 | - | else getAssetName(fromBase58String(asset1)) | |
259 | - | let nameAsset2 = if ((asset2 == waves)) | |
260 | - | then waves | |
261 | - | else getAssetName(fromBase58String(asset2)) | |
262 | - | let name = if (customName) | |
263 | - | then Name | |
264 | - | else ((nameAsset1 + "_") + nameAsset2) | |
265 | - | let key = validPoolK(kp(asset1, asset2)) | |
266 | - | if (if ((i.caller == this)) | |
267 | - | then true | |
268 | - | else (i.caller == adminVerification())) | |
269 | - | then if ((key != false)) | |
270 | - | then { | |
271 | - | let assetLpCreate = Issue(name, ((("LP asset for pool liquidity in AxAi Swap pair " + asset1) + "_") + asset2), (1 * D8), 8, true) | |
272 | - | let idAssetLp = calculateAssetId(assetLpCreate) | |
273 | - | [StringEntry((l + kp(asset1, asset2)), toBase58String(idAssetLp)), assetLpCreate] | |
274 | - | } | |
275 | - | else throw("Invalid Pool Key. Try inverting the assets") | |
276 | - | else throw("Only the Admin itself can invoke this function") | |
277 | - | } | |
278 | - | ||
279 | - | ||
280 | - | ||
281 | - | @Callable(i) | |
282 | - | func deposit (pool,Asset1,Asset2) = { | |
283 | - | let power = getBooleanValue(this, ac) | |
284 | - | let liquidityPower = getBooleanValue(this, liquidityAc) | |
285 | - | let MainAsset = getStringValue(this, main) | |
286 | - | let lpAssetId = if (pool) | |
287 | - | then getStringValue(this, (l + kp(Asset1, Asset2))) | |
288 | - | else MainAsset | |
289 | - | if (power) | |
290 | - | then if (!(liquidityPower)) | |
291 | - | then if ((i.payments[0].assetId != fromBase58String(lpAssetId))) | |
292 | - | then throw((("Invalid asset! Kindly Deposit Only " + MainAsset) + " or valid asset lp")) | |
293 | - | else if (!(pool)) | |
294 | - | then { | |
295 | - | let currentKey = toBase58String(i.caller.bytes) | |
296 | - | let currentAmount = match getInteger(this, currentKey) { | |
297 | - | case a: Int => | |
298 | - | a | |
299 | - | case _ => | |
300 | - | 0 | |
301 | - | } | |
302 | - | let h = if ((currentAmount == 0)) | |
303 | - | then height | |
304 | - | else valueOrElse(getIntegerValue(this, (deposit_height + currentKey)), height) | |
305 | - | let newAmount = (currentAmount + i.payments[0].amount) | |
306 | - | let useramount = IntegerEntry(currentKey, newAmount) | |
307 | - | let userdepositheight = IntegerEntry((deposit_height + currentKey), h) | |
308 | - | let previouslockbalance = match getInteger(this, "Total_Tokens_Locked:") { | |
309 | - | case a: Int => | |
310 | - | a | |
311 | - | case _ => | |
312 | - | 0 | |
313 | - | } | |
314 | - | let totaltoken = (previouslockbalance + i.payments[0].amount) | |
315 | - | let TLV = IntegerEntry("Total_Tokens_Locked:", totaltoken) | |
316 | - | [useramount, userdepositheight, TLV] | |
317 | - | } | |
318 | - | else { | |
319 | - | let poolKey = kp(Asset1, Asset2) | |
320 | - | let key = validPoolK(poolKey) | |
321 | - | if ((key != false)) | |
322 | - | then { | |
323 | - | let currentKey = toBase58String(i.caller.bytes) | |
324 | - | let currentAmount = match getInteger(this, ((("STAKE_LP_" + currentKey) + "_") + poolKey)) { | |
325 | - | case a: Int => | |
326 | - | a | |
327 | - | case _ => | |
328 | - | 0 | |
329 | - | } | |
330 | - | let h = if ((currentAmount == 0)) | |
331 | - | then height | |
332 | - | else valueOrElse(getIntegerValue(this, ((((deposit_height + "_") + currentKey) + "_") + poolKey)), height) | |
333 | - | let newAmount = (currentAmount + i.payments[0].amount) | |
334 | - | let useramount = IntegerEntry(((("STAKE_LP_" + currentKey) + "_") + poolKey), newAmount) | |
335 | - | let userdepositheight = IntegerEntry(((((deposit_height + "_") + currentKey) + "_") + poolKey), height) | |
336 | - | let previouslockbalance = match getInteger(this, ("Total_Tokens_LP_Locked_" + poolKey)) { | |
337 | - | case a: Int => | |
338 | - | a | |
339 | - | case _ => | |
340 | - | 0 | |
341 | - | } | |
342 | - | let totaltoken = (previouslockbalance + i.payments[0].amount) | |
343 | - | let TLV = IntegerEntry(("Total_Tokens_LP_Locked_" + poolKey), totaltoken) | |
344 | - | [useramount, userdepositheight, TLV] | |
345 | - | } | |
346 | - | else throw("Invalid Pool key.") | |
347 | - | } | |
348 | - | else throw("liquidity is currently under maintenance.") | |
349 | - | else throw("dApp is currently under maintenance.") | |
350 | - | } | |
351 | - | ||
352 | - | ||
353 | - | ||
354 | - | @Callable(i) | |
355 | - | func remove (pool,Asset1,Asset2,amount) = { | |
356 | - | let power = getBooleanValue(this, ac) | |
357 | - | let liquidityPower = getBooleanValue(this, liquidityAc) | |
358 | - | let pmt = i.payments[0] | |
359 | - | let MainAsset = fromBase58String(getStringValue(this, main)) | |
360 | - | if (power) | |
361 | - | then if (!(liquidityPower)) | |
362 | - | then { | |
363 | - | let currentKey = toBase58String(i.caller.bytes) | |
364 | - | let currentAmount = match if (pool) | |
365 | - | then getIntegerValue(this, ((("STAKE_LP_" + currentKey) + "_") + kp(Asset1, Asset2))) | |
366 | - | else getIntegerValue(this, currentKey) { | |
367 | - | case a: Int => | |
368 | - | a | |
369 | - | case _ => | |
370 | - | 0 | |
371 | - | } | |
372 | - | let swapheightkeyname = if (pool) | |
373 | - | then ((((deposit_height + "_") + currentKey) + "_") + kp(Asset1, Asset2)) | |
374 | - | else (deposit_height + currentKey) | |
375 | - | let previouslockbalance = if (pool) | |
376 | - | then getIntegerValue(this, ("Total_Tokens_LP_Locked_" + kp(Asset1, Asset2))) | |
377 | - | else getIntegerValue(this, "Total_Tokens_Locked:") | |
378 | - | let totaltoken = (previouslockbalance - amount) | |
379 | - | let diff = (height - getIntegerValue(this, swapheightkeyname)) | |
380 | - | let bcd = getIntegerValue(this, bcD) | |
381 | - | let reward = ((diff * bcd) * D8) | |
382 | - | let feeCalc = (reward / (previouslockbalance / amount)) | |
383 | - | if ((0 > amount)) | |
384 | - | then throw(if (pool) | |
385 | - | then (((("Can't withdraw negative " + Asset1) + "/") + Asset2) + " amount") | |
386 | - | else "Can't withdraw negative AxAi amount") | |
387 | - | else { | |
388 | - | let newAmount = (currentAmount - amount) | |
389 | - | if ((0 > newAmount)) | |
390 | - | then throw(if (pool) | |
391 | - | then (((("Not enough Asset Lp " + Asset1) + "/") + Asset2) + " balance") | |
392 | - | else "Not enough AxAi balance") | |
393 | - | else [IntegerEntry(if (pool) | |
394 | - | then ((("STAKE_LP_" + currentKey) + "_") + kp(Asset1, Asset2)) | |
395 | - | else currentKey, newAmount), IntegerEntry(if (pool) | |
396 | - | then ("Total_Tokens_LP_Locked_" + kp(Asset1, Asset2)) | |
397 | - | else "Total_Tokens_Locked:", totaltoken), ScriptTransfer(i.caller, amount, if (pool) | |
398 | - | then fromBase58String(getStringValue(this, (l + kp(Asset1, Asset2)))) | |
399 | - | else MainAsset), ScriptTransfer(i.caller, feeCalc, MainAsset)] | |
400 | - | } | |
401 | - | } | |
402 | - | else throw("liquidity is currently under maintenance.") | |
403 | - | else throw("dApp is currently under maintenance.") | |
404 | - | } | |
405 | - | ||
406 | - | ||
407 | - | ||
408 | - | @Callable(i) | |
409 | - | func addLiquidity (Asset1,Asset2) = { | |
410 | - | let power = getBooleanValue(this, ac) | |
411 | - | let poolActivate = getBooleanValue(this, poolAc) | |
412 | - | let acWaves = getBooleanValue(this, aWaves) | |
413 | - | let key = validPoolK(kp(Asset1, Asset2)) | |
414 | - | let asset1 = i.payments[0].assetId | |
415 | - | let asset2 = i.payments[1].assetId | |
416 | - | let USDN = fromBase58String(getStringValue(this, usdn)) | |
417 | - | let USDC = fromBase58String(getStringValue(this, usdc)) | |
418 | - | let USDT = fromBase58String(getStringValue(this, usdt)) | |
419 | - | let NGNN = fromBase58String(getStringValue(this, ngnn)) | |
420 | - | let EURN = fromBase58String(getStringValue(this, eurn)) | |
421 | - | let MainAsset = fromBase58String(getStringValue(this, main)) | |
422 | - | let lpAssetId = getStringValue(this, (l + kp(Asset1, Asset2))) | |
423 | - | let totalAsset1Pool = if ((2 > totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset1), false))) | |
424 | - | then i.payments[0].amount | |
425 | - | else totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset1), false) | |
426 | - | let totalAsset2Pool = if ((2 > totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset1), false))) | |
427 | - | then i.payments[1].amount | |
428 | - | else totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset2), false) | |
429 | - | let totalLp = totalAssetPool(lpAssetId, true) | |
430 | - | let priceLpAsset = ((totalAsset1Pool + totalAsset2Pool) / totalLp) | |
431 | - | let quantityAsset2 = (i.payments[0].amount * (totalAsset2Pool / totalAsset1Pool)) | |
432 | - | let rateTop = (i.payments[1].amount + ((i.payments[1].amount * 2) / 100)) | |
433 | - | let rateBottom = (i.payments[1].amount - ((i.payments[1].amount * 2) / 100)) | |
434 | - | let Validate = if (if (if ((i.payments[1].amount == quantityAsset2)) | |
435 | - | then true | |
436 | - | else (rateTop > i.payments[1].amount)) | |
437 | - | then true | |
438 | - | else (i.payments[1].amount > rateBottom)) | |
439 | - | then true | |
440 | - | else false | |
441 | - | if (power) | |
442 | - | then if (!(poolActivate)) | |
443 | - | then if (if (if (!((asset1 == asset2))) | |
444 | - | then validateAsset(asset1, Asset1, acWaves) | |
445 | - | else false) | |
446 | - | then validateAsset(asset2, Asset2, acWaves) | |
447 | - | else false) | |
448 | - | then if (if (if (if (if (if (if (if ((asset1 == USDN)) | |
449 | - | then true | |
450 | - | else (asset1 == USDC)) | |
451 | - | then true | |
452 | - | else (asset1 == USDT)) | |
453 | - | then true | |
454 | - | else (asset1 == NGNN)) | |
455 | - | then true | |
456 | - | else (asset1 == MainAsset)) | |
457 | - | then true | |
458 | - | else (asset1 == WAVES)) | |
459 | - | then true | |
460 | - | else (asset1 == EURN)) | |
461 | - | then if (if (if (if (if (if ((asset2 == USDN)) | |
462 | - | then true | |
463 | - | else (asset2 == USDC)) | |
464 | - | then true | |
465 | - | else (asset2 == USDT)) | |
466 | - | then true | |
467 | - | else (asset2 == NGNN)) | |
468 | - | then true | |
469 | - | else (asset2 == MainAsset)) | |
470 | - | then true | |
471 | - | else (asset2 == WAVES)) | |
472 | - | then true | |
473 | - | else (asset2 == EURN) | |
474 | - | else false) | |
475 | - | then if ((key != false)) | |
476 | - | then if (Validate) | |
477 | - | then { | |
478 | - | let currentKey = toBase58String(i.caller.bytes) | |
479 | - | let currentAmount = kpAddress(currentKey, kp(Asset1, Asset2)) | |
480 | - | let currentAmountAsset1 = poolAA(currentKey, kp(Asset1, Asset2), Asset1) | |
481 | - | let currentAmountAsset2 = poolAA(currentKey, kp(Asset1, Asset2), Asset2) | |
482 | - | let asset1pool = assetP(kp(Asset1, Asset2), Asset1) | |
483 | - | let asset2pool = assetP(kp(Asset1, Asset2), Asset2) | |
484 | - | let receiveLp = if ((totalAsset1Pool == i.payments[0].amount)) | |
485 | - | then (1 * D8) | |
486 | - | else toInt((((toBigInt(i.payments[0].amount) * toBigInt(D8)) + (toBigInt(i.payments[1].amount) * toBigInt(D8))) / (((toBigInt(totalAsset1Pool) * toBigInt(D8)) + (toBigInt(totalAsset2Pool) * toBigInt(D8))) / toBigInt(totalLp)))) | |
487 | - | let newcurrentAmountAsset1 = (currentAmountAsset1 + i.payments[0].amount) | |
488 | - | let newcurrentAmountAsset2 = (currentAmountAsset2 + i.payments[1].amount) | |
489 | - | let newcurrentAmount = (currentAmount + receiveLp) | |
490 | - | let newasset1pool = (asset1pool + i.payments[0].amount) | |
491 | - | let newasset2pool = (asset2pool + i.payments[1].amount) | |
492 | - | [Reissue(fromBase58String(lpAssetId), receiveLp, true), ScriptTransfer(Address(i.caller.bytes), receiveLp, fromBase58String(lpAssetId)), IntegerEntry(pkey(Asset1, Asset2, currentKey), height), IntegerEntry(((((currentKey + "_") + kp(Asset1, Asset2)) + "_") + Asset1), newcurrentAmountAsset1), IntegerEntry(((((currentKey + "_") + kp(Asset1, Asset2)) + "_") + Asset2), newcurrentAmountAsset2), IntegerEntry(((kp(Asset1, Asset2) + "_") + currentKey), newcurrentAmount), IntegerEntry(((kp(Asset1, Asset2) + "_") + Asset1), newasset1pool), IntegerEntry(((kp(Asset1, Asset2) + "_") + Asset2), newasset2pool), IntegerEntry(Asset1, (getAmountBlockAsset(Asset1) + i.payments[0].amount)), IntegerEntry(Asset2, (getAmountBlockAsset(Asset2) + i.payments[1].amount)), IntegerEntry(lpAssetId, (getAmountBlockAsset(lpAssetId) + receiveLp))] | |
493 | - | } | |
494 | - | else throw(((((("Payment of invalid 1/1 amounts to the Pool. Try Asset2: {value:" + toString((i.payments[0].amount * (totalAsset2Pool / totalAsset1Pool)))) + "} Received: ") + toString(i.payments[1].amount)) + " Validate: ") + toString(Validate))) | |
495 | - | else throw("Invalid Pool Key.") | |
496 | - | else throw("Invalid Asset1 or Asset2!") | |
497 | - | else throw("Asset1 cannot be equal to Asset2") | |
498 | - | else throw("liquidity is currently under maintenance.") | |
499 | - | else throw("dApp is currently under maintenance.") | |
500 | - | } | |
501 | - | ||
502 | - | ||
503 | - | ||
504 | - | @Callable(i) | |
505 | - | func removeLiquidity (Asset1,Asset2,Amount) = { | |
506 | - | let currentKey = toBase58String(i.caller.bytes) | |
507 | - | let power = getBooleanValue(this, ac) | |
508 | - | let poolActivate = getBooleanValue(this, poolAc) | |
509 | - | let acWaves = getBooleanValue(this, aWaves) | |
510 | - | let poolKey = kp(Asset1, Asset2) | |
511 | - | let key = validPoolK(poolKey) | |
512 | - | let asset1 = if ((Asset1 == waves)) | |
513 | - | then if (acWaves) | |
514 | - | then WAVES | |
515 | - | else throw("The smart contract does not currently support Waves.") | |
516 | - | else fromBase58String(Asset1) | |
517 | - | let asset2 = if ((Asset2 == waves)) | |
518 | - | then if (acWaves) | |
519 | - | then WAVES | |
520 | - | else throw("The smart contract does not currently support Waves.") | |
521 | - | else fromBase58String(Asset2) | |
522 | - | let USDN = fromBase58String(getStringValue(this, usdn)) | |
523 | - | let USDC = fromBase58String(getStringValue(this, usdc)) | |
524 | - | let USDT = fromBase58String(getStringValue(this, usdt)) | |
525 | - | let NGNN = fromBase58String(getStringValue(this, ngnn)) | |
526 | - | let MainAsset = fromBase58String(getStringValue(this, main)) | |
527 | - | let EURN = fromBase58String(getStringValue(this, eurn)) | |
528 | - | let lpAssetId = getStringValue(this, (l + kp(Asset1, Asset2))) | |
529 | - | let currentAmount = kpAddress(currentKey, kp(Asset1, Asset2)) | |
530 | - | let amountLpBlocked = lpBlocked(currentKey, poolKey) | |
531 | - | let totalLP = totalAssetPool(lpAssetId, true) | |
532 | - | let totalAsset1Pool = totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset1), false) | |
533 | - | let totalAsset2Pool = totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset2), false) | |
534 | - | if (power) | |
535 | - | then if (!(poolActivate)) | |
536 | - | then if (!((Asset1 == Asset2))) | |
537 | - | then if (if (if (if (if (if (if (if ((asset1 == USDN)) | |
538 | - | then true | |
539 | - | else (asset1 == USDC)) | |
540 | - | then true | |
541 | - | else (asset1 == USDT)) | |
542 | - | then true | |
543 | - | else (asset1 == NGNN)) | |
544 | - | then true | |
545 | - | else (asset1 == MainAsset)) | |
546 | - | then true | |
547 | - | else (asset1 == WAVES)) | |
548 | - | then true | |
549 | - | else (asset1 == EURN)) | |
550 | - | then if (if (if (if (if (if ((asset2 == USDN)) | |
551 | - | then true | |
552 | - | else (asset2 == USDC)) | |
553 | - | then true | |
554 | - | else (asset2 == USDT)) | |
555 | - | then true | |
556 | - | else (asset2 == NGNN)) | |
557 | - | then true | |
558 | - | else (asset2 == MainAsset)) | |
559 | - | then true | |
560 | - | else (asset2 == WAVES)) | |
561 | - | then true | |
562 | - | else (asset2 == EURN) | |
563 | - | else false) | |
564 | - | then if ((key != false)) | |
565 | - | then if (!((currentAmount == 0))) | |
566 | - | then if (((currentAmount - amountLpBlocked) >= Amount)) | |
567 | - | then if (if ((totalAsset1Pool > 2)) | |
568 | - | then true | |
569 | - | else (totalAsset2Pool > 2)) | |
570 | - | then { | |
571 | - | let receiveAsset1 = (toInt(((fraction(toBigInt(i.payments[0].amount), toBigInt(D8), toBigInt(totalLP)) * toBigInt(totalAsset1Pool)) / toBigInt(D8))) - 1) | |
572 | - | let receiveAsset2 = (toInt(((fraction(toBigInt(i.payments[0].amount), toBigInt(D8), toBigInt(totalLP)) * toBigInt(totalAsset2Pool)) / toBigInt(D8))) - 1) | |
573 | - | let asset1pool = assetP(kp(Asset1, Asset2), Asset1) | |
574 | - | let asset2pool = assetP(kp(Asset1, Asset2), Asset2) | |
575 | - | let currentAmountAsset1 = poolAA(currentKey, kp(Asset1, Asset2), Asset1) | |
576 | - | let currentAmountAsset2 = poolAA(currentKey, kp(Asset1, Asset2), Asset2) | |
577 | - | let newcurrentAmountAsset1 = (currentAmountAsset1 - receiveAsset1) | |
578 | - | let newcurrentAmountAsset2 = (currentAmountAsset2 - receiveAsset2) | |
579 | - | let newcurrentAmount = (currentAmount - Amount) | |
580 | - | let newasset1pool = (asset1pool - receiveAsset1) | |
581 | - | let newasset2pool = (asset2pool - receiveAsset2) | |
582 | - | if ((i.payments[0].assetId == fromBase58String(lpAssetId))) | |
583 | - | then if ((Amount == i.payments[0].amount)) | |
584 | - | then [Burn(fromBase58String(lpAssetId), Amount), ScriptTransfer(Address(i.caller.bytes), receiveAsset1, asset1), ScriptTransfer(Address(i.caller.bytes), receiveAsset2, asset2), IntegerEntry(pkey(Asset1, Asset2, currentKey), height), IntegerEntry(((((currentKey + "_") + kp(Asset1, Asset2)) + "_") + Asset1), newcurrentAmountAsset1), IntegerEntry(((((currentKey + "_") + kp(Asset1, Asset2)) + "_") + Asset2), newcurrentAmountAsset2), IntegerEntry(((kp(Asset1, Asset2) + "_") + currentKey), newcurrentAmount), IntegerEntry(((kp(Asset1, Asset2) + "_") + Asset1), newasset1pool), IntegerEntry(((kp(Asset1, Asset2) + "_") + Asset2), newasset2pool), IntegerEntry(Asset1, (getAmountBlockAsset(Asset1) - receiveAsset1)), IntegerEntry(Asset2, (getAmountBlockAsset(Asset2) - receiveAsset2)), IntegerEntry(lpAssetId, (getAmountBlockAsset(lpAssetId) - Amount))] | |
585 | - | else throw(("Withdrawal amount lower than asset lp amount. Your Lp amount available: " + toString(Amount))) | |
586 | - | else throw("Requires an lp asset as payment to remove locked amounts.") | |
587 | - | } | |
588 | - | else throw("Pool has no liquidity.") | |
589 | - | else throw(("Amount to be withdrawn greater than the amount available for withdrawal. Available: " + toString(Amount))) | |
590 | - | else throw("You have no locked values in the pool") | |
591 | - | else throw("Invalid Pool Key.") | |
592 | - | else throw("Invalid Asset1 or Asset2!") | |
593 | - | else throw("Asset1 cannot be equal to Asset2") | |
594 | - | else throw("liquidity is currently under maintenance.") | |
595 | - | else throw("dApp is currently under maintenance.") | |
596 | - | } | |
597 | - | ||
598 | - | ||
599 | - | ||
600 | - | @Callable(i) | |
601 | - | func swap (Asset1,Asset2) = { | |
602 | - | let currentKey = toBase58String(i.caller.bytes) | |
603 | - | let acWaves = getBooleanValue(this, aWaves) | |
604 | - | let power = getBooleanValue(this, ac) | |
605 | - | let swapActivate = getBooleanValue(this, swapAc) | |
606 | - | let poolKey = kp(Asset1, Asset2) | |
607 | - | let key = validPoolK(poolKey) | |
608 | - | let asset1 = i.payments[0].assetId | |
609 | - | let USDN = fromBase58String(getStringValue(this, usdn)) | |
610 | - | let USDC = fromBase58String(getStringValue(this, usdc)) | |
611 | - | let USDT = fromBase58String(getStringValue(this, usdt)) | |
612 | - | let NGNN = fromBase58String(getStringValue(this, ngnn)) | |
613 | - | let MainAsset = fromBase58String(getStringValue(this, main)) | |
614 | - | let EURN = fromBase58String(getStringValue(this, eurn)) | |
615 | - | let lpAssetId = getStringValue(this, (l + kp(Asset1, Asset2))) | |
616 | - | let totalAsset1 = totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset1), false) | |
617 | - | let totalAsset2 = totalAssetPool(((kp(Asset1, Asset2) + "_") + Asset2), false) | |
618 | - | let feeRatePercentual = getIntegerValue(this, rateFee) | |
619 | - | let prAsset1 = (toBigInt(i.payments[0].amount) * fraction(toBigInt(D8), toBigInt(totalAsset2), toBigInt(totalAsset1))) | |
620 | - | let priceAsset1 = toInt(((prAsset1 - ((prAsset1 / toBigInt(feeRatePercentual)) * toBigInt(100))) / toBigInt(D8))) | |
621 | - | let prAsset2 = (toBigInt(i.payments[0].amount) * fraction(toBigInt(D8), toBigInt(totalAsset1), toBigInt(totalAsset2))) | |
622 | - | let priceAsset2 = toInt(((prAsset2 - ((prAsset2 / toBigInt(feeRatePercentual)) * toBigInt(100))) / toBigInt(D8))) | |
623 | - | let sendValue = if (if ((asset1 == WAVES)) | |
624 | - | then (Asset1 == waves) | |
625 | - | else false) | |
626 | - | then priceAsset1 | |
627 | - | else if ((asset1 == fromBase58String(Asset1))) | |
628 | - | then priceAsset1 | |
629 | - | else priceAsset2 | |
630 | - | let assetUpdatePay = if ((asset1 == WAVES)) | |
631 | - | then waves | |
632 | - | else if ((asset1 == fromBase58String(Asset1))) | |
633 | - | then Asset1 | |
634 | - | else Asset2 | |
635 | - | let assetUpdateSwap = if ((asset1 == WAVES)) | |
636 | - | then waves | |
637 | - | else if ((asset1 == fromBase58String(Asset1))) | |
638 | - | then Asset2 | |
639 | - | else Asset1 | |
640 | - | let assetSendSwap = valid(i.payments[0].assetId, Asset1, Asset2) | |
641 | - | let n1s = (assetP(kp(Asset1, Asset2), assetUpdateSwap) - sendValue) | |
642 | - | let nw = (getAmountBlockAsset(assetUpdateSwap) - sendValue) | |
643 | - | let newUpda = if ((0 > n1s)) | |
644 | - | then 0 | |
645 | - | else n1s | |
646 | - | let newUpdateSwap = if ((0 > nw)) | |
647 | - | then 0 | |
648 | - | else nw | |
649 | - | let D = match i.payments[0].assetId { | |
650 | - | case o: Unit => | |
651 | - | pow(10, 0, 8, 0, 0, HALFUP) | |
652 | - | case x: ByteVector => | |
653 | - | pow(10, 0, value(assetInfo(x)).decimals, 0, 0, HALFUP) | |
654 | - | case _ => | |
655 | - | throw("Match error") | |
656 | - | } | |
657 | - | if (power) | |
658 | - | then if (!(swapActivate)) | |
659 | - | then if (if (!((Asset1 == Asset2))) | |
660 | - | then if (validateAsset(asset1, Asset1, acWaves)) | |
661 | - | then true | |
662 | - | else validateAsset(asset1, Asset2, acWaves) | |
663 | - | else false) | |
664 | - | then if (if (if (if (if (if (if ((asset1 == USDN)) | |
665 | - | then true | |
666 | - | else (asset1 == USDC)) | |
667 | - | then true | |
668 | - | else (asset1 == USDT)) | |
669 | - | then true | |
670 | - | else (asset1 == NGNN)) | |
671 | - | then true | |
672 | - | else (asset1 == MainAsset)) | |
673 | - | then true | |
674 | - | else (asset1 == EURN)) | |
675 | - | then true | |
676 | - | else (asset1 == WAVES)) | |
677 | - | then if ((key != false)) | |
678 | - | then if ((i.payments[1].assetId == MainAsset)) | |
679 | - | then if ((i.payments[1].amount == 300000)) | |
680 | - | then if (if ((totalAsset1 > 2)) | |
681 | - | then true | |
682 | - | else (totalAsset2 > 2)) | |
683 | - | then [ScriptTransfer(Address(i.caller.bytes), if ((0 > sendValue)) | |
684 | - | then D | |
685 | - | else sendValue, assetSendSwap), IntegerEntry(assetUpdateSwap, newUpdateSwap), IntegerEntry(((kp(Asset1, Asset2) + "_") + assetUpdateSwap), newUpda), IntegerEntry(((kp(Asset1, Asset2) + "_") + assetUpdatePay), (assetP(kp(Asset1, Asset2), assetUpdatePay) + i.payments[0].amount)), IntegerEntry(assetUpdatePay, (getAmountBlockAsset(assetUpdatePay) + i.payments[0].amount)), IntegerEntry(toBase58String(MainAsset), (getAmountBlockAsset(toBase58String(MainAsset)) + i.payments[1].amount))] | |
686 | - | else throw("Pool has no liquidity.") | |
687 | - | else throw("Swap denied! 0.003 AxAi is required for the swap fee.") | |
688 | - | else throw("Invalid rate asset") | |
689 | - | else throw("Invalid Swap Key.") | |
690 | - | else throw("Invalid Asset1 or Asset2!") | |
691 | - | else throw("Asset1 cannot be equal to Asset2") | |
692 | - | else throw("Swap is currently under maintenance.") | |
693 | - | else throw("dApp is currently under maintenance.") | |
694 | - | } | |
695 | 5 | ||
696 | 6 | ||
697 | 7 | @Verifier(tx) | |
698 | 8 | func verify () = match tx { | |
699 | - | case order: Order => | |
700 | - | true | |
701 | - | case e: ExchangeTransaction => | |
702 | - | true | |
703 | 9 | case tt: TransferTransaction => | |
704 | - | (tt.recipient == Address(fromBase58String( | |
10 | + | (tt.recipient == Address(fromBase58String("3PDjc3572B363SGGc3ntE32AKgufPptjVKf"))) | |
705 | 11 | case _ => | |
706 | 12 | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
707 | 13 | } | |
708 | 14 |
github/deemru/w8io/786bc32 63.15 ms ◑