tx · 5x3gcY8wMKQKkuUjoiv6Cd2E65zYjYFvYZ39C2Yx6x1U

3Mw9HVbxqhtTC1athVZN78y9q7yswTfC9uY:  -0.01300000 Waves

2022.07.19 13:40 [2146525] smart account 3Mw9HVbxqhtTC1athVZN78y9q7yswTfC9uY > SELF 0.00000000 Waves

{ "type": 13, "id": "5x3gcY8wMKQKkuUjoiv6Cd2E65zYjYFvYZ39C2Yx6x1U", "fee": 1300000, "feeAssetId": null, "timestamp": 1658227281745, "version": 1, "sender": "3Mw9HVbxqhtTC1athVZN78y9q7yswTfC9uY", "senderPublicKey": "9zQTLWGeZfMtVNfMpmWVqFT2atbrkfKxE56ze2BeAWxf", "proofs": [ "whr3JczxDGkDshU991SrULeBmjrQjMq4vw7siMNMFeMP4zE9yqXjnyEz24yR6kkrJKB4WTJp4v4GR7jfbQXMZU3" ], "script": "base64:BgIZCAISBAoCCAgSABIAEgQKAgEBEgMKAQgSABYADXdpdGhkcmF3RGVsYXkAtAsAD2RlY2ltYWxQYXJ0VVNETgDAhD0AD2RlY2ltYWxQYXJ0VVNEVADAhD0AF21pbmltYWxBbW91bnRUb1N3YXBVU0RUCQBoAgCQTgUPZGVjaW1hbFBhcnRVU0ROABdtaW5pbWFsQW1vdW50VG9Td2FwVVNETgkAaAIAkE4FD2RlY2ltYWxQYXJ0VVNEVAETa2V5TWFuYWdlclB1YmxpY0tleQACFCVzX19tYW5hZ2VyUHVibGljS2V5ARprZXlQZW5kaW5nTWFuYWdlclB1YmxpY0tleQACGyVzX19wZW5kaW5nTWFuYWdlclB1YmxpY0tleQEOa2V5VXNkdEFzc2V0SWQAAgglc19fVVNEVAEOa2V5VXNkbkFzc2V0SWQAAgglc19fVVNETgEWbWFuYWdlclB1YmxpY0tleU9yVW5pdAAEByRtYXRjaDAJAKIIAQkBE2tleU1hbmFnZXJQdWJsaWNLZXkAAwkAAQIFByRtYXRjaDACBlN0cmluZwQBcwUHJG1hdGNoMAkA2QQBBQFzAwkAAQIFByRtYXRja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ACBFVuaXQIBQJ0eA9zZW5kZXJQdWJsaWNLZXkJAAIBAgtNYXRjaCBlcnJvcgkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAkA2QQBAiwyQ2JkOG96RzdBMVJ5Uk5DM25OblpnSHU3UnU0SzNKQ2ZweVBraHFyOXp4catoGU4=", "chainId": 84, "height": 2146525, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: none Full:
OldNewDifferences
1-# no script
1+{-# STDLIB_VERSION 6 #-}
2+{-# SCRIPT_TYPE ACCOUNT #-}
3+{-# CONTENT_TYPE DAPP #-}
4+let withdrawDelay = 1460
5+
6+let decimalPartUSDN = 1000000
7+
8+let decimalPartUSDT = 1000000
9+
10+let minimalAmountToSwapUSDT = (10000 * decimalPartUSDN)
11+
12+let minimalAmountToSwapUSDN = (10000 * decimalPartUSDT)
13+
14+func keyManagerPublicKey () = "%s__managerPublicKey"
15+
16+
17+func keyPendingManagerPublicKey () = "%s__pendingManagerPublicKey"
18+
19+
20+func keyUsdtAssetId () = "%s__USDT"
21+
22+
23+func keyUsdnAssetId () = "%s__USDN"
24+
25+
26+func managerPublicKeyOrUnit () = match getString(keyManagerPublicKey()) {
27+ case s: String =>
28+ fromBase58String(s)
29+ case _: Unit =>
30+ unit
31+ case _ =>
32+ throw("Match error")
33+}
34+
35+
36+func pendingManagerPublicKeyOrUnit () = match getString(keyPendingManagerPublicKey()) {
37+ case s: String =>
38+ fromBase58String(s)
39+ case _: Unit =>
40+ unit
41+ case _ =>
42+ throw("Match error")
43+}
44+
45+
46+func collectKey (address,amountToSwapInKey,allowToWithdrawHeight) = makeString([address, "WITHDRAW", toString(amountToSwapInKey), "HEIGHT", toString(allowToWithdrawHeight)], "_")
47+
48+
49+func collectBalanceKey (address) = makeString([address, "balance"], "_")
50+
51+
52+func collectBalanceKeyWithFee (address) = makeString([address, "balance_with_fee"], "_")
53+
54+
55+func usdtToUsdnAssetError () = throw("To swap USDT to USDN you need attach payment in USDT")
56+
57+
58+func usdnToUsdtAssetError () = throw("To swap USDN to USDT you need attach payment in USDN")
59+
60+
61+func usdtToUsdnLowLimitError () = throw((("you can swap at least " + toString((minimalAmountToSwapUSDT / decimalPartUSDT))) + " tokens"))
62+
63+
64+func abs (n) = if ((0 > n))
65+ then (n * -1)
66+ else n
67+
68+
69+func getWithoutFeeWithdraw (amount,balanceWithoutFee) = min([amount, balanceWithoutFee])
70+
71+
72+func getListElementOrDefault (list,index,default) = if ((size(list) > index))
73+ then list[index]
74+ else default
75+
76+
77+func currentWithdrawals (address,amount) = {
78+ let balanceKey = collectBalanceKey(address)
79+ let balanceWithFeeKey = collectBalanceKeyWithFee(address)
80+ let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0)
81+ let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0)
82+ let userBalance = (currentClientBalance + currentClientBalanceWithFee)
83+ if (if ((amount > userBalance))
84+ then true
85+ else (minimalAmountToSwapUSDN > amount))
86+ then throw("Swap amount fail, amount is to small or to big.")
87+ else {
88+ let toWithdrawWithoutFee = getWithoutFeeWithdraw(amount, currentClientBalance)
89+ let toWithdrawWithFee = (amount - toWithdrawWithoutFee)
90+ let fee = ((toWithdrawWithFee / 100) * 2)
91+[toWithdrawWithoutFee, toWithdrawWithFee, fee]
92+ }
93+ }
94+
95+
96+func mustManager (i) = {
97+ let pd = throw("Permission denied")
98+ match managerPublicKeyOrUnit() {
99+ case pk: ByteVector =>
100+ if ((i.callerPublicKey == pk))
101+ then true
102+ else pd
103+ case _: Unit =>
104+ if ((i.caller == this))
105+ then true
106+ else pd
107+ case _ =>
108+ throw("Match error")
109+ }
110+ }
111+
112+
113+@Callable(i)
114+func constructor (usdtAssetId,usdnAssetId) = [StringEntry(keyUsdtAssetId(), usdtAssetId), StringEntry(keyUsdnAssetId(), usdnAssetId)]
115+
116+
117+
118+@Callable(invoke)
119+func swapUSDTtoUSDN () = {
120+ let balanceKey = collectBalanceKeyWithFee(toString(invoke.caller))
121+ let payment = value(invoke.payments[0])
122+ if ((payment.assetId != fromBase58String(keyUsdtAssetId())))
123+ then usdtToUsdnAssetError()
124+ else {
125+ let amount = payment.amount
126+ let fee = ((amount / 100) * 2)
127+ let currentClientBalanceUSDT = valueOrElse(getInteger(this, balanceKey), 0)
128+ if ((minimalAmountToSwapUSDT > amount))
129+ then usdtToUsdnLowLimitError()
130+ else [IntegerEntry(balanceKey, (currentClientBalanceUSDT + amount)), ScriptTransfer(invoke.caller, (amount - fee), fromBase58String(keyUsdnAssetId()))]
131+ }
132+ }
133+
134+
135+
136+@Callable(invoke)
137+func initializationUSDNtoUSDTswap () = {
138+ let payment = value(invoke.payments[0])
139+ let address = toString(invoke.caller)
140+ if ((payment.assetId != fromBase58String(keyUsdnAssetId())))
141+ then usdnToUsdtAssetError()
142+ else {
143+ let amount = payment.amount
144+ let balanceKey = collectBalanceKey(address)
145+ let balanceWithFeeKey = collectBalanceKeyWithFee(address)
146+ let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0)
147+ let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0)
148+ let userBalance = (currentClientBalance + currentClientBalanceWithFee)
149+ let data = currentWithdrawals(toString(invoke.caller), amount)
150+ let toWithdrawWithoutFee = valueOrErrorMessage(data[0], "Wrong 'currentWithdrawals' method!")
151+ let toWithdrawWithFee = valueOrErrorMessage(data[1], "Wrong 'currentWithdrawals' method!")
152+ let fee = valueOrErrorMessage(data[2], "Wrong 'currentWithdrawals' method!")
153+ let total = ((toWithdrawWithFee + toWithdrawWithoutFee) - fee)
154+ let allowToWithDrawHeight = (height + withdrawDelay)
155+ if (isDefined(getString(this, collectKey(toString(invoke.caller), amount, allowToWithDrawHeight))))
156+ then throw("You have already started withdrawal process, wait next block.")
157+ else [IntegerEntry(balanceKey, (currentClientBalance - toWithdrawWithoutFee)), IntegerEntry(balanceWithFeeKey, (currentClientBalanceWithFee - toWithdrawWithFee)), StringEntry(collectKey(toString(invoke.caller), amount, allowToWithDrawHeight), makeString(["not_withdrawn", toString((amount - fee))], "_"))]
158+ }
159+ }
160+
161+
162+
163+@Callable(invoke)
164+func swapUSDNtoUSDT (amount,heightInKey) = {
165+ let key = collectKey(toString(invoke.caller), amount, heightInKey)
166+ let withdrawnInfo = valueOrErrorMessage(getString(this, key), ((("This key doesn't exists " + key) + " at address ") + toString(this)))
167+ let toWithdraw = getListElementOrDefault(split(withdrawnInfo, "_"), 2, toString(amount))
168+ if (if ((height >= heightInKey))
169+ then contains(withdrawnInfo, "not_withdrawn")
170+ else false)
171+ then [DeleteEntry(key), ScriptTransfer(invoke.caller, valueOrErrorMessage(parseInt(toWithdraw), "Wrong withdraw data!"), fromBase58String(keyUsdtAssetId()))]
172+ else throw((("Withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT."))
173+ }
174+
175+
176+
177+@Callable(i)
178+func setManager (pendingManagerPublicKey) = {
179+ let checkCaller = mustManager(i)
180+ if ((checkCaller == checkCaller))
181+ then {
182+ let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey)
183+ if ((checkManagerPublicKey == checkManagerPublicKey))
184+ then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)]
185+ else throw("Strict value is not equal to itself.")
186+ }
187+ else throw("Strict value is not equal to itself.")
188+ }
189+
190+
191+
192+@Callable(i)
193+func confirmManager () = {
194+ let pm = pendingManagerPublicKeyOrUnit()
195+ let hasPM = if (isDefined(pm))
196+ then true
197+ else throw("No pending manager")
198+ if ((hasPM == hasPM))
199+ then {
200+ let checkPM = if ((i.callerPublicKey == value(pm)))
201+ then true
202+ else throw("You are not pending manager")
203+ if ((checkPM == checkPM))
204+ then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())]
205+ else throw("Strict value is not equal to itself.")
206+ }
207+ else throw("Strict value is not equal to itself.")
208+ }
209+
210+
211+@Verifier(tx)
212+func verify () = {
213+ let targetPublicKey = match managerPublicKeyOrUnit() {
214+ case pk: ByteVector =>
215+ pk
216+ case _: Unit =>
217+ tx.senderPublicKey
218+ case _ =>
219+ throw("Match error")
220+ }
221+ sigVerify(tx.bodyBytes, tx.proofs[0], fromBase58String("2Cbd8ozG7A1RyRNC3nNnZgHu7Ru4K3JCfpyPkhqr9zxq"))
222+ }
223+

github/deemru/w8io/169f3d6 
20.94 ms