tx · BP9noXNL359rtLEcABu2HgJQCDvwjYF7vKot7vLcVd5J 3ND1UEC8y7FViTVvjJgHP51WMEuQD2W57Lg: -0.01000000 Waves 2020.10.20 17:03 [1228981] smart account 3ND1UEC8y7FViTVvjJgHP51WMEuQD2W57Lg > SELF 0.00000000 Waves
{ "type": 13, "id": "BP9noXNL359rtLEcABu2HgJQCDvwjYF7vKot7vLcVd5J", "fee": 1000000, "feeAssetId": null, "timestamp": 1603202615878, "version": 2, "chainId": 84, "sender": "3ND1UEC8y7FViTVvjJgHP51WMEuQD2W57Lg", "senderPublicKey": "7nGyzQvY91xLa2mGkd6ar8kvVCZxG3vZBVZLgY6VD6p9", "proofs": [ "3hT84guS1aZkyTToYHnhL23nouAQgmqcydPtpY2GUoK1YjcGRTdb5FNffpJbbcsk34DHnZM2VjCdrBckeAFTyLeN" ], "script": "base64:AAIEAAAAAAAAAAwIAhIAEgASBAoCAQEAAAANAAAAAARVU0RUAgAAACwzRUptN1pOWlJqV25nalZRNnFqRlVlZjNpUlV5SlpvVDRWWW9DWWFlVmRxWgAAAAAEVVNETgIAAAAsMzdqVkhaSzJjZ2JOVEFrTUNMR2RyYnp2RzFyd01qVHJwRDJUR3praWN0d0wAAAAABmlkVVNETgkAAlkAAAABBQAAAARVU0ROAAAAAAZpZFVTRFQJAAJZAAAAAQUAAAAEVVNEVAAAAAANd2l0aGRyYXdEZWxheQAAAAAAAAAAAQAAAAAPZGVjaW1hbFBhcnRVU0ROAAAAAAAAD0JAAAAAAA9kZWNpbWFsUGFydFVTRFQAAAAAAAAPQkAAAAAAF21pbmltYWxBbW91bnRUb1N3YXBVU0RUCQAAaAAAAAIAAAAAAAAAJxAFAAAAD2RlY2ltYWxQYXJ0VVNETgAAAAAXbWluaW1hbEFtb3VudFRvU3dhcFVTRE4JAABoAAAAAgAAAAAAAAAnEAUAAAAPZGVjaW1hbFBhcnRVU0RUAQAAAApjb2xsZWN0S2V5AAAAAwAAAAdhZGRyZXNzAAAAEWFtb3Vud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zc2libGUgYWZ0ZXIgCQABpAAAAAEFAAAAC2hlaWdodEluS2V5AgAAACogaGVpZ2h0IG9yIHlvdSBoYXZlIGFscmVhZHkgd2l0aGRyYXduIFVTRFQAAAAAnNHtaw==", "height": 1228981, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: none Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 4 #-} | |
2 | + | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | + | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let USDT = "3EJm7ZNZRjWngjVQ6qjFUef3iRUyJZoT4VYoCYaeVdqZ" | |
5 | + | ||
6 | + | let USDN = "37jVHZK2cgbNTAkMCLGdrbzvG1rwMjTrpD2TGzkictwL" | |
7 | + | ||
8 | + | let idUSDN = fromBase58String(USDN) | |
9 | + | ||
10 | + | let idUSDT = fromBase58String(USDT) | |
11 | + | ||
12 | + | let withdrawDelay = 1 | |
13 | + | ||
14 | + | let decimalPartUSDN = 1000000 | |
15 | + | ||
16 | + | let decimalPartUSDT = 1000000 | |
17 | + | ||
18 | + | let minimalAmountToSwapUSDT = (10000 * decimalPartUSDN) | |
19 | + | ||
20 | + | let minimalAmountToSwapUSDN = (10000 * decimalPartUSDT) | |
21 | + | ||
22 | + | func collectKey (address,amountToSwapInKey,allowToWithdrawHeight) = makeString([toString(address), "WITHDRAW", toString(amountToSwapInKey), "HEIGHT", toString(allowToWithdrawHeight)], "_") | |
23 | + | ||
24 | + | ||
25 | + | func collectBalanceKey (address) = makeString([toString(address), "balance"], "_") | |
26 | + | ||
27 | + | ||
28 | + | func usdtToUsdnAssetError () = throw("To swap USDT to USDN you need attach payment in USDT") | |
29 | + | ||
30 | + | ||
31 | + | func usdtToUsdnLowLimitError () = throw((("you can swap at least " + toString((minimalAmountToSwapUSDT / decimalPartUSDT))) + " tokens")) | |
32 | + | ||
33 | + | ||
34 | + | @Callable(invoke) | |
35 | + | func swapUSDTtoUSDN () = { | |
36 | + | let balanceKey = collectBalanceKey(invoke.caller) | |
37 | + | let payment = valueOrErrorMessage(invoke.payments[0], "Payment is not attached!") | |
38 | + | if ((payment.assetId != idUSDT)) | |
39 | + | then usdtToUsdnAssetError() | |
40 | + | else { | |
41 | + | let amount = payment.amount | |
42 | + | let userAddress = invoke.caller | |
43 | + | let currentClientBalanceUSDT = valueOrElse(getInteger(this, balanceKey), 0) | |
44 | + | if ((minimalAmountToSwapUSDT > amount)) | |
45 | + | then usdtToUsdnLowLimitError() | |
46 | + | else [IntegerEntry(balanceKey, (currentClientBalanceUSDT + amount)), ScriptTransfer(invoke.caller, amount, idUSDN)] | |
47 | + | } | |
48 | + | } | |
49 | + | ||
50 | + | ||
51 | + | ||
52 | + | @Callable(invoke) | |
53 | + | func initializationUSDNtoUSDTswap () = { | |
54 | + | let payment = value(invoke.payments[0]) | |
55 | + | let assetIdReceived = payment.assetId | |
56 | + | let paymentAmount = payment.amount | |
57 | + | let userAddress = invoke.caller | |
58 | + | let balanceKey = collectBalanceKey(invoke.caller) | |
59 | + | let currentClientBalanceUSDT = match getInteger(this, balanceKey) { | |
60 | + | case currentBalance: Int => | |
61 | + | getIntegerValue(this, balanceKey) | |
62 | + | case _ => | |
63 | + | 0 | |
64 | + | } | |
65 | + | if ((assetIdReceived != idUSDN)) | |
66 | + | then throw("to swap USDN to USDT you need attach payment in USDN") | |
67 | + | else if (if ((paymentAmount > currentClientBalanceUSDT)) | |
68 | + | then true | |
69 | + | else (minimalAmountToSwapUSDN > paymentAmount)) | |
70 | + | then throw("swap amount fail") | |
71 | + | else { | |
72 | + | let allowToWithDrawHeight = (height + withdrawDelay) | |
73 | + | if (isDefined(getString(this, collectKey(invoke.caller, paymentAmount, allowToWithDrawHeight)))) | |
74 | + | then throw("you have already started withdrawal process, wait next block") | |
75 | + | else [IntegerEntry((toString(invoke.caller) + "_balance"), (currentClientBalanceUSDT - paymentAmount)), StringEntry(collectKey(invoke.caller, paymentAmount, allowToWithDrawHeight), "not_withdrawn")] | |
76 | + | } | |
77 | + | } | |
78 | + | ||
79 | + | ||
80 | + | ||
81 | + | @Callable(invoke) | |
82 | + | func swapUSDNtoUSDT (amountToSwapInKey,heightInKey) = { | |
83 | + | let key = collectKey(invoke.caller, amountToSwapInKey, heightInKey) | |
84 | + | let withdrawnInfo = match getString(this, key) { | |
85 | + | case withdrawnInfo: String => | |
86 | + | getStringValue(this, key) | |
87 | + | case _ => | |
88 | + | throw(((("this key doesn't exists " + key) + " at address ") + toString(this))) | |
89 | + | } | |
90 | + | if (if ((height >= heightInKey)) | |
91 | + | then (withdrawnInfo == "not_withdrawn") | |
92 | + | else false) | |
93 | + | then [StringEntry(key, "withdrawn"), ScriptTransfer(invoke.caller, amountToSwapInKey, idUSDT)] | |
94 | + | else throw((("withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT")) | |
95 | + | } | |
96 | + | ||
97 | + |
github/deemru/w8io/169f3d6 40.41 ms ◑