tx · 9qKDy6o5GJH4sgpfChf8gyaBZe3tE1Gu3cmgwUxiEGmR

3N3CMNgGTwAsqzA7MCQguQ4VzhGAkK9AjJW:  -0.01400000 Waves

2020.10.23 16:25 [1233285] smart account 3N3CMNgGTwAsqzA7MCQguQ4VzhGAkK9AjJW > SELF 0.00000000 Waves

{ "type": 13, "id": "9qKDy6o5GJH4sgpfChf8gyaBZe3tE1Gu3cmgwUxiEGmR", "fee": 1400000, "feeAssetId": null, "timestamp": 1603459553187, "version": 1, "sender": "3N3CMNgGTwAsqzA7MCQguQ4VzhGAkK9AjJW", "senderPublicKey": "3yyQUAPNzCSuwYVYkSqF1tbLZg1JAVwuewyEn7AnhnG9", "proofs": [ "48RQsyQCCGWVnEt3m8e4iVYJyLubcxVHJyuvUKVQBNTmZoGhyoQFmFhfHmQkqFaqyaxq2CBcgC3BejKGs6sSBMAN" ], "script": "base64:AAIEAAAAAAAAABQIAhIAEgASBAoCAQESABIECgIIAQAAABMAAAAABFVTRFQCAAAALDVTaDlLZ2hma1p5aGp3dW9kb3ZEaEI2UGdoRFVHQkhpQVBaNE1rclBnS3RYAAAAAARVU0ROAgAAACwyNUZFcUVqUmtxSzZ5Q2tpVDdMejZTQVl6N2dVRkN0eGZDQ2huclZGRDVBVAAAAAAGaWRVU0ROCQACWQAAAAEFAAAABFVTRE4AAAAABmlkVVNEVAkAAlkAAAABBQAAAARVU0RUAAAAAA13aXRoZHJhd0RlbGF5AAAAAAAAAAACAAAAAA9kZWNpbWFsUGFydFVTRE4AAAAAAAAPQkAAAAAAD2RlY2ltYWxQYXJ0VVNEVAAAAAAAAA9CQAAAAAAXbWluaW1hbEFtb3VudFRvU3dhcFVTRFQJAABoAAAAAgAAAAAAAAAAZAUAAAAPZGVjaW1hbFBhcnRVU0ROAAAAABdtaW5pbWFsQW1vdW50VG9Td2FwVVNETgkAAGgAAAACAAAAAAAAAABkBQAAAA9kZWNpbWFsUGFydFVTRFQBAAAACmNvbGxlY3RLZXkAAAADAAAA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yRXJyb3JNZXNzYWdlAAAAAgkAAZEAAAACBQAAAARkYXRhAAAAAAAAAAABAgAAACJXcm9uZyAnY3VycmVudFdpdGhkcmF3YWxzJyBtZXRob2QhBAAAAANmZWUJAQAAABN2YWx1ZU9yRXJyb3JNZXNzYWdlAAAAAgkAAZEAAAACBQAAAARkYXRhAAAAAAAAAAACAgAAACJXcm9uZyAnY3VycmVudFdpdGhkcmF3YWxzJyBtZXRob2QhBAAAAAV0b3RhbAkAAGUAAAACCQAAZAAAAAIFAAAAEXRvV2l0aGRyYXdXaXRoRmVlBQAAABR0b1dpdGhkcmF3V2l0aG91dEZlZQUAAAADZmVlCQAAAgAAAAEJAAEsAAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAAAh7ImZlZSI6IAkAAaQAAAABBQAAAANmZWUCAAAAFywgInRvV2l0aGRyYXdXaXRoRmVlIjogCQABpAAAAAEFAAAAEXRvV2l0aGRyYXdXaXRoRmVlAgAAABosICJ0b1dpdGhkcmF3V2l0aG91dEZlZSI6IAkAAaQAAAABBQAAABR0b1dpdGhkcmF3V2l0aG91dEZlZQIAAAALLCAidG90YWwiOiAJAAGkAAAAAQUAAAAFdG90YWwCAAAAAX0AAAAA6sO2tw==", "chainId": 84, "height": 1233285, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 5iRrY61M52pxNhxZtoJPeJ4Ja57sQcutHNT8BzGnjChG Next: none Diff:
OldNewDifferences
1-{-# STDLIB_VERSION 3 #-}
1+{-# STDLIB_VERSION 4 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let USDT = "5Sh9KghfkZyhjwuodovDhB6PghDUGBHiAPZ4MkrPgKtX"
1717
1818 let minimalAmountToSwapUSDT = (100 * decimalPartUSDN)
1919
20-let minimalAmountToSwapUSDN = (50 * decimalPartUSDT)
20+let minimalAmountToSwapUSDN = (100 * decimalPartUSDT)
2121
22-func collectKey (address,amountToSwapInKey,allowToWithdrawHeight) = ((((toString(address) + "_WITHDRAW_") + toString(amountToSwapInKey)) + "_HEIGHT_") + toString(allowToWithdrawHeight))
22+func collectKey (address,amountToSwapInKey,allowToWithdrawHeight) = makeString([address, "WITHDRAW", toString(amountToSwapInKey), "HEIGHT", toString(allowToWithdrawHeight)], "_")
2323
2424
25-@Callable(contextObj)
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)
2673 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)]))
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+ }
4785 }
4886
4987
5088
51-@Callable(contextObj)
89+@Callable(invoke)
5290 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- }
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+ }
80112 }
81113
82114
83115
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)))
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."))
92126 }
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"))
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)) + "}"))
98143 }
99144
100145
Full:
OldNewDifferences
1-{-# STDLIB_VERSION 3 #-}
1+{-# STDLIB_VERSION 4 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let USDT = "5Sh9KghfkZyhjwuodovDhB6PghDUGBHiAPZ4MkrPgKtX"
55
66 let USDN = "25FEqEjRkqK6yCkiT7Lz6SAYz7gUFCtxfCChnrVFD5AT"
77
88 let idUSDN = fromBase58String(USDN)
99
1010 let idUSDT = fromBase58String(USDT)
1111
1212 let withdrawDelay = 2
1313
1414 let decimalPartUSDN = 1000000
1515
1616 let decimalPartUSDT = 1000000
1717
1818 let minimalAmountToSwapUSDT = (100 * decimalPartUSDN)
1919
20-let minimalAmountToSwapUSDN = (50 * decimalPartUSDT)
20+let minimalAmountToSwapUSDN = (100 * decimalPartUSDT)
2121
22-func collectKey (address,amountToSwapInKey,allowToWithdrawHeight) = ((((toString(address) + "_WITHDRAW_") + toString(amountToSwapInKey)) + "_HEIGHT_") + toString(allowToWithdrawHeight))
22+func collectKey (address,amountToSwapInKey,allowToWithdrawHeight) = makeString([address, "WITHDRAW", toString(amountToSwapInKey), "HEIGHT", toString(allowToWithdrawHeight)], "_")
2323
2424
25-@Callable(contextObj)
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)
2673 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)]))
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+ }
4785 }
4886
4987
5088
51-@Callable(contextObj)
89+@Callable(invoke)
5290 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- }
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+ }
80112 }
81113
82114
83115
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)))
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."))
92126 }
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"))
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)) + "}"))
98143 }
99144
100145

github/deemru/w8io/169f3d6 
39.86 ms