tx · GEyqwWqGD7fMumMS1mdxgm4Eu2w4GMbZNz8eDbGms79

3Mz9N7YPfZPWGd4yYaX6H53Gcgrq6ifYiH7:  -0.01400000 Waves

2020.10.20 14:10 [1228811] smart account 3Mz9N7YPfZPWGd4yYaX6H53Gcgrq6ifYiH7 > SELF 0.00000000 Waves

{ "type": 13, "id": "GEyqwWqGD7fMumMS1mdxgm4Eu2w4GMbZNz8eDbGms79", "fee": 1400000, "feeAssetId": null, "timestamp": 1603192287084, "version": 2, "chainId": 84, "sender": "3Mz9N7YPfZPWGd4yYaX6H53Gcgrq6ifYiH7", "senderPublicKey": "2M25DqL2W4rGFLCFadgATboS8EPqyWAN3DjH12AH5Kdr", "proofs": [ "5gK94hMic5tFbFxAs69DpZSJ6dHT6kDzLZhQCH4LJxhgXquFRVkTsoU63GvvvXkqQ99EPNuc7bwJotjsD6jWzDYV" ], "script": null, "height": 1228811, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Ej65HjZ7QwACCjJpmcyJcprMN6HJJ6jdAreoFKw34ygC Next: J8MDZxsXUWhDtmyYh9bbtAsKaHvHtatenzjNqfG3j7bw Full:
OldNewDifferences
1-{-# STDLIB_VERSION 3 #-}
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) = ((((toString(address) + "_WITHDRAW_") + toString(amountToSwapInKey)) + "_HEIGHT_") + toString(allowToWithdrawHeight))
23-
24-
25-@Callable(contextObj)
26-func swapUSDTtoUSDN () = {
27- let payment = match contextObj.payment {
28- case p: AttachedPayment =>
29- p
30- case _ =>
31- throw("Payment not attached")
32- }
33- let assetIdReceived = payment.assetId
34- let tokenReceiveAmount = payment.amount
35- let userAddress = contextObj.caller
36- let currentClientBalanceUSDT = match getInteger(this, (toString(userAddress) + "_balance")) {
37- case currentBalance: Int =>
38- value(getInteger(this, (toString(userAddress) + "_balance")))
39- case _ =>
40- 0
41- }
42- if ((assetIdReceived != idUSDT))
43- then throw("to swap USDT to USDN you need attach payment in USDT")
44- else if ((minimalAmountToSwapUSDT > tokenReceiveAmount))
45- then throw((("you can swap at least " + toString((minimalAmountToSwapUSDT / decimalPartUSDT))) + " tokens"))
46- else ScriptResult(WriteSet([DataEntry((toString(contextObj.caller) + "_balance"), (currentClientBalanceUSDT + tokenReceiveAmount))]), TransferSet([ScriptTransfer(contextObj.caller, tokenReceiveAmount, idUSDN)]))
47- }
48-
49-
50-
51-@Callable(contextObj)
52-func initializationUSDNtoUSDTswap () = {
53- let payment = match contextObj.payment {
54- case p: AttachedPayment =>
55- p
56- case _ =>
57- throw("Payment not attached")
58- }
59- let assetIdReceived = payment.assetId
60- let paymentAmount = payment.amount
61- let userAddress = contextObj.caller
62- let currentClientBalanceUSDT = match getInteger(this, (toString(userAddress) + "_balance")) {
63- case currentBalance: Int =>
64- getIntegerValue(this, (toString(userAddress) + "_balance"))
65- case _ =>
66- 0
67- }
68- if ((assetIdReceived != idUSDN))
69- then throw("to swap USDN to USDT you need attach payment in USDN")
70- else if (if ((paymentAmount > currentClientBalanceUSDT))
71- then true
72- else (minimalAmountToSwapUSDN > paymentAmount))
73- then throw("swap amount fail")
74- else {
75- let allowToWithDrawHeight = (height + withdrawDelay)
76- if (isDefined(getString(this, collectKey(contextObj.caller, paymentAmount, allowToWithDrawHeight))))
77- then throw("you have already started withdrawal process, wait next block")
78- else ScriptResult(WriteSet([DataEntry((toString(contextObj.caller) + "_balance"), (currentClientBalanceUSDT - paymentAmount)), DataEntry(collectKey(contextObj.caller, paymentAmount, allowToWithDrawHeight), "not_withdrawn")]), TransferSet(nil))
79- }
80- }
81-
82-
83-
84-@Callable(contextObj)
85-func swapUSDNtoUSDT (amountToSwapInKey,heightInKey) = {
86- let key = collectKey(contextObj.caller, amountToSwapInKey, heightInKey)
87- let withdrawnInfo = match getString(this, key) {
88- case withdrawnInfo: String =>
89- getStringValue(this, key)
90- case _ =>
91- throw(((("this key doesn't exists " + key) + " at address ") + toString(this)))
92- }
93- if (if ((height >= heightInKey))
94- then (withdrawnInfo == "not_withdrawn")
95- else false)
96- then ScriptResult(WriteSet([DataEntry(key, "withdrawn")]), TransferSet([ScriptTransfer(contextObj.caller, amountToSwapInKey, idUSDT)]))
97- else throw((("withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT"))
98- }
99-
100-
1+# no script

github/deemru/w8io/6500d08 
29.03 ms