tx · 2rCUWBZDNrvUc83bqhawD9kSHmjkzTT8Hc8369YEpX6g

3ND8yJ3MEGfKY4DCfSATfrLsYLaNfDm5TNC:  -0.01000000 Waves

2020.11.09 15:03 [1257776] smart account 3ND8yJ3MEGfKY4DCfSATfrLsYLaNfDm5TNC > SELF 0.00000000 Waves

{ "type": 13, "id": "2rCUWBZDNrvUc83bqhawD9kSHmjkzTT8Hc8369YEpX6g", "fee": 1000000, "feeAssetId": null, "timestamp": 1604923446447, "version": 2, "chainId": 84, "sender": "3ND8yJ3MEGfKY4DCfSATfrLsYLaNfDm5TNC", "senderPublicKey": "9J24eH9fu7ZRimzCwPctkYHcfmYchM8KuBgenPhrcdHP", "proofs": [ "5wDGa9UXhzXHaY2Krh9nLXpn27YwdBSo92FVKsuzwVwjD9XGKkTuNNSzhi4ysrQ3rMZjgedeYH3QYoTv8UWy2kid" ], "script": "base64:AAIEAAAAAAAAABQIAhIAEgASBAoCAQESABIECgIIAQAAABMAAAAABFVTRFQCAAAALEI3Zlg2a0JBUVJpYVRoQTF0YzFYNDNNU0VDOVdvSmNRZmJDTWltZlJTaXM2AAAAAARVU0ROAgAAACxGcTdtWkVDWGViU01IclV4WGFGY0NQRFpCRExkc0Y3MzI2NlpraUNiajh6NgAAAAAGaWRVU0ROCQACWQAAAAEFAAAABFVTRE4AAAAABmlkVVNEVAkAAlkAAAABBQAAAARVU0RUAAAAAA13aXRoZHJhd0RlbGF5AAAAAAAAAAABAAAAAA9kZWNpbWFsUGFydFVTRE4AAAAAAAAPQkAAAAAAD2RlY2ltYWxQYXJ0VVNEVAAAAAAAAA9CQAAAAAAXbWluaW1hbEFtb3VudFRvU3dhcFVTRFQJAABoAAAAAgAAAAAAAAAnEAUAAAAPZGVjaW1hbFBhcnRVU0ROAAAAABdtaW5pbWFsQW1vdW50VG9Td2FwVVNETgkAAGgAAAACAAAAAAAAACcQBQAAAA9kZWNpbWFsUGFydFVTRFQBAAAACmNvbGxlY3RLZXkAAAADAAAAB2FkZH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3JNZXNzYWdlAAAAAgkAAZEAAAACBQAAAARkYXRhAAAAAAAAAAABAgAAACJXcm9uZyAnY3VycmVudFdpdGhkcmF3YWxzJyBtZXRob2QhBAAAAANmZWUJAQAAABN2YWx1ZU9yRXJyb3JNZXNzYWdlAAAAAgkAAZEAAAACBQAAAARkYXRhAAAAAAAAAAACAgAAACJXcm9uZyAnY3VycmVudFdpdGhkcmF3YWxzJyBtZXRob2QhBAAAAAV0b3RhbAkAAGUAAAACCQAAZAAAAAIFAAAAEXRvV2l0aGRyYXdXaXRoRmVlBQAAABR0b1dpdGhkcmF3V2l0aG91dEZlZQUAAAADZmVlCQAAAgAAAAEJAAEsAAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAAAh7ImZlZSI6IAkAAaQAAAABBQAAAANmZWUCAAAAFywgInRvV2l0aGRyYXdXaXRoRmVlIjogCQABpAAAAAEFAAAAEXRvV2l0aGRyYXdXaXRoRmVlAgAAABosICJ0b1dpdGhkcmF3V2l0aG91dEZlZSI6IAkAAaQAAAABBQAAABR0b1dpdGhkcmF3V2l0aG91dEZlZQIAAAALLCAidG90YWwiOiAJAAGkAAAAAQUAAAAFdG90YWwCAAAAAX0AAAAA1ab+VA==", "height": 1257776, "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 = "B7fX6kBAQRiaThA1tc1X43MSEC9WoJcQfbCMimfRSis6"
5+
6+let USDN = "Fq7mZECXebSMHrUxXaFcCPDZBDLdsF73266ZkiCbj8z6"
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([address, "WITHDRAW", toString(amountToSwapInKey), "HEIGHT", toString(allowToWithdrawHeight)], "_")
23+
24+
25+func collectBalanceKey (address) = makeString([address, "balance"], "_")
26+
27+
28+func collectBalanceKeyWithFee (address) = makeString([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+func abs (n) = if ((0 > n))
41+ then (n * -1)
42+ else n
43+
44+
45+func getWithoutFeeWithdraw (amount,balanceWithoutFee) = min([amount, balanceWithoutFee])
46+
47+
48+func getListElementOrDefault (list,index,default) = if ((size(list) > index))
49+ then list[index]
50+ else default
51+
52+
53+func currentWithdrawals (address,amount) = {
54+ let balanceKey = collectBalanceKey(address)
55+ let balanceWithFeeKey = collectBalanceKeyWithFee(address)
56+ let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0)
57+ let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0)
58+ let userBalance = (currentClientBalance + currentClientBalanceWithFee)
59+ if (if ((amount > userBalance))
60+ then true
61+ else (minimalAmountToSwapUSDN > amount))
62+ then throw("Swap amount fail, amount is to small or to big.")
63+ else {
64+ let toWithdrawWithoutFee = getWithoutFeeWithdraw(amount, currentClientBalance)
65+ let toWithdrawWithFee = (amount - toWithdrawWithoutFee)
66+ let fee = ((toWithdrawWithFee / 100) * 1)
67+[toWithdrawWithoutFee, toWithdrawWithFee, fee]
68+ }
69+ }
70+
71+
72+@Callable(invoke)
73+func swapUSDTtoUSDN () = {
74+ let balanceKey = collectBalanceKeyWithFee(toString(invoke.caller))
75+ let payment = value(invoke.payments[0])
76+ if ((payment.assetId != idUSDT))
77+ then usdtToUsdnAssetError()
78+ else {
79+ let amount = payment.amount
80+ let currentClientBalanceUSDT = valueOrElse(getInteger(this, balanceKey), 0)
81+ if ((minimalAmountToSwapUSDT > amount))
82+ then usdtToUsdnLowLimitError()
83+ else [IntegerEntry(balanceKey, (currentClientBalanceUSDT + amount)), ScriptTransfer(invoke.caller, amount, idUSDN)]
84+ }
85+ }
86+
87+
88+
89+@Callable(invoke)
90+func initializationUSDNtoUSDTswap () = {
91+ let payment = value(invoke.payments[0])
92+ let address = toString(invoke.caller)
93+ if ((payment.assetId != idUSDN))
94+ then usdnToUsdtAssetError()
95+ else {
96+ let amount = payment.amount
97+ let balanceKey = collectBalanceKey(address)
98+ let balanceWithFeeKey = collectBalanceKeyWithFee(address)
99+ let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0)
100+ let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0)
101+ let userBalance = (currentClientBalance + currentClientBalanceWithFee)
102+ let data = currentWithdrawals(toString(invoke.caller), amount)
103+ let toWithdrawWithoutFee = valueOrErrorMessage(data[0], "Wrong 'currentWithdrawals' method!")
104+ let toWithdrawWithFee = valueOrErrorMessage(data[1], "Wrong 'currentWithdrawals' method!")
105+ let fee = valueOrErrorMessage(data[2], "Wrong 'currentWithdrawals' method!")
106+ let total = ((toWithdrawWithFee + toWithdrawWithoutFee) - fee)
107+ let allowToWithDrawHeight = (height + withdrawDelay)
108+ if (isDefined(getString(this, collectKey(toString(invoke.caller), amount, allowToWithDrawHeight))))
109+ then throw("You have already started withdrawal process, wait next block.")
110+ else [IntegerEntry(balanceKey, (currentClientBalance - toWithdrawWithoutFee)), IntegerEntry(balanceWithFeeKey, (currentClientBalanceWithFee - toWithdrawWithFee)), StringEntry(collectKey(toString(invoke.caller), amount, allowToWithDrawHeight), makeString(["not_withdrawn", toString((amount - fee))], "_"))]
111+ }
112+ }
113+
114+
115+
116+@Callable(invoke)
117+func swapUSDNtoUSDT (amount,heightInKey) = {
118+ let key = collectKey(toString(invoke.caller), amount, heightInKey)
119+ let withdrawnInfo = valueOrErrorMessage(getString(this, key), ((("This key doesn't exists " + key) + " at address ") + toString(this)))
120+ let toWithdraw = getListElementOrDefault(split(withdrawnInfo, "_"), 2, toString(amount))
121+ if (if ((height >= heightInKey))
122+ then contains(withdrawnInfo, "not_withdrawn")
123+ else false)
124+ then [DeleteEntry(key), ScriptTransfer(invoke.caller, valueOrErrorMessage(parseInt(toWithdraw), "Wrong withdraw data!"), idUSDT)]
125+ else throw((("Withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT."))
126+ }
127+
128+
129+
130+@Callable(invoke)
131+func getWithdrawalFee () = throw("{\"fee\": 1}")
132+
133+
134+
135+@Callable(invoke)
136+func getWithdrawalData (address,amount) = {
137+ let data = currentWithdrawals(address, amount)
138+ let toWithdrawWithoutFee = valueOrErrorMessage(data[0], "Wrong 'currentWithdrawals' method!")
139+ let toWithdrawWithFee = valueOrErrorMessage(data[1], "Wrong 'currentWithdrawals' method!")
140+ let fee = valueOrErrorMessage(data[2], "Wrong 'currentWithdrawals' method!")
141+ let total = ((toWithdrawWithFee + toWithdrawWithoutFee) - fee)
142+ throw((((((((("{\"fee\": " + toString(fee)) + ", \"toWithdrawWithFee\": ") + toString(toWithdrawWithFee)) + ", \"toWithdrawWithoutFee\": ") + toString(toWithdrawWithoutFee)) + ", \"total\": ") + toString(total)) + "}"))
143+ }
144+
145+

github/deemru/w8io/fabc49c 
16.03 ms