tx · 4B3eHchj6qFtX7DkuH6C6J19BpvWrPzu38TsAAKPM5HG

3N7eFm96RcvhVADP9smB7uGYWJ51GBnZxuk:  -0.01000000 Waves

2020.10.20 19:37 [1229134] smart account 3N7eFm96RcvhVADP9smB7uGYWJ51GBnZxuk > SELF 0.00000000 Waves

{ "type": 13, "id": "4B3eHchj6qFtX7DkuH6C6J19BpvWrPzu38TsAAKPM5HG", "fee": 1000000, "feeAssetId": null, "timestamp": 1603211868354, "version": 2, "chainId": 84, "sender": "3N7eFm96RcvhVADP9smB7uGYWJ51GBnZxuk", "senderPublicKey": "9HGWwGPcnqmbhHN8KaJj8uHagiQzbvPSKR8co89C81CZ", "proofs": [ "4u5SCG8RaXevQPk2QmRCKAYxpYfYPEXopfCn7fKg6TBKqN7nL1Eb7kYENwqXEYXEi3uuM6Wzo3AiKEroULnF7cDm" ], "script": "base64:AAIEAAAAAAAAAAwIAhIAEgASBAoCAQEAAAAPAAAAAARVU0RUAgAAACwzRUptN1pOWlJqV25nalZRNnFqRlVlZjNpUlV5SlpvVDRWWW9DWWFlVmRxWgAAAAAEVVNETgIAAAAsMzdqVkhaSzJjZ2JOVEFrTUNMR2RyYnp2RzFyd01qVHJwRDJUR3praWN0d0wAAAAABmlkVVNETgkAAlkAAAABBQAAAARVU0ROAAAAAAZpZFVTRFQJAAJZAAAAAQUAAAAEVVNEVAAAAAANd2l0aGRyYXdEZWxheQAAAAAAAAAAAQAAAAAPZGVjaW1hbFBhcnRVU0ROAAAAAAAAD0JAAAAAAA9kZWNpbWFsUGFydFVTRFQAAAAAAAAPQkAAAAAAF21pbmltYWxBbW91bnRUb1N3YXBVU0RUCQAAaAAAAAIAAAAAAAAAJxAFAAAAD2RlY2ltYWxQYXJ0VVNETgAAAAAXbWluaW1hbEFtb3VudFRvU3dhcFVTRE4JAABoAAAAAgAAAAAAAAAnEAUAAAAPZGVjaW1hbFBhcnRVU0RUAQAAAApjb2xsZWN0S2V5AAAAAwAAAAdhZGRyZXNzAAAA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VU0RUAAAAAGetUCY=", "height": 1229134, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: none Full:
OldNewDifferences
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 collectBalanceKeyWithFee (address) = makeString([toString(address), "balance_with_fee"], "_")
29+
30+
31+func usdtToUsdnAssetError () = throw("To swap USDT to USDN you need attach payment in USDT")
32+
33+
34+func usdnToUsdtAssetError () = throw("To swap USDN to USDT you need attach payment in USDN")
35+
36+
37+func usdtToUsdnLowLimitError () = throw((("you can swap at least " + toString((minimalAmountToSwapUSDT / decimalPartUSDT))) + " tokens"))
38+
39+
40+@Callable(invoke)
41+func swapUSDTtoUSDN () = {
42+ let balanceKey = collectBalanceKeyWithFee(invoke.caller)
43+ let payment = value(invoke.payments[0])
44+ if ((payment.assetId != idUSDT))
45+ then usdtToUsdnAssetError()
46+ else {
47+ let amount = payment.amount
48+ let currentClientBalanceUSDT = valueOrElse(getInteger(this, balanceKey), 0)
49+ if ((minimalAmountToSwapUSDT > amount))
50+ then usdtToUsdnLowLimitError()
51+ else [IntegerEntry(balanceKey, (currentClientBalanceUSDT + amount)), ScriptTransfer(invoke.caller, amount, idUSDN)]
52+ }
53+ }
54+
55+
56+
57+@Callable(invoke)
58+func initializationUSDNtoUSDTswap () = {
59+ let payment = value(invoke.payments[0])
60+ if ((payment.assetId != idUSDN))
61+ then usdnToUsdtAssetError()
62+ else {
63+ let amount = payment.amount
64+ let userAddress = invoke.caller
65+ let balanceKey = collectBalanceKey(invoke.caller)
66+ let balanceWithFeeKey = collectBalanceKeyWithFee(invoke.caller)
67+ let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0)
68+ let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0)
69+ let userBalance = (currentClientBalance + currentClientBalanceWithFee)
70+ let userBalanceAfterWithdraw = max([(currentClientBalance - amount), 0])
71+ let userBalanceWithFeeAfterWithdraw = max([(currentClientBalanceWithFee + min([(currentClientBalance - amount), 0]))])
72+ let fee = (((currentClientBalanceWithFee - userBalanceWithFeeAfterWithdraw) / 100) * 99)
73+ if (if ((amount > userBalance))
74+ then true
75+ else (minimalAmountToSwapUSDN > amount))
76+ then throw("swap amount fail")
77+ else {
78+ let allowToWithDrawHeight = (height + withdrawDelay)
79+ if (isDefined(getString(this, collectKey(invoke.caller, amount, allowToWithDrawHeight))))
80+ then throw("You have already started withdrawal process, wait next block.")
81+ else [IntegerEntry(balanceKey, userBalanceAfterWithdraw), IntegerEntry(balanceWithFeeKey, userBalanceWithFeeAfterWithdraw), StringEntry(collectKey(invoke.caller, amount, allowToWithDrawHeight), makeString(["not_withdrawn", toString((amount - fee))], "_"))]
82+ }
83+ }
84+ }
85+
86+
87+
88+@Callable(invoke)
89+func swapUSDNtoUSDT (amount,heightInKey) = {
90+ let key = collectKey(invoke.caller, amount, heightInKey)
91+ let withdrawnInfo = valueOrErrorMessage(getString(this, key), ((("This key doesn't exists " + key) + " at address ") + toString(this)))
92+ let toWithdraw = valueOrElse(split(withdrawnInfo, "_")[2], toString(amount))
93+ if (if ((height >= heightInKey))
94+ then contains(withdrawnInfo, "not_withdrawn")
95+ else false)
96+ then [DeleteEntry(key), ScriptTransfer(invoke.caller, valueOrErrorMessage(parseInt(toWithdraw), "Wrong withdraw data!"), idUSDT)]
97+ else throw((("withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT"))
98+ }
99+
100+

github/deemru/w8io/026f985 
25.19 ms