tx · GNg83bYGYeVzNGCTkkY5pfv9w4gmXSSSj9hstpHakDgi 3Mzj8MyE3E3G55SLVE6Dgd6ew2uERLxiE4U: -0.01300000 Waves 2022.07.19 18:33 [2146821] smart account 3Mzj8MyE3E3G55SLVE6Dgd6ew2uERLxiE4U > SELF 0.00000000 Waves
{ "type": 13, "id": "GNg83bYGYeVzNGCTkkY5pfv9w4gmXSSSj9hstpHakDgi", "fee": 1300000, "feeAssetId": null, "timestamp": 1658244845153, "version": 1, "sender": "3Mzj8MyE3E3G55SLVE6Dgd6ew2uERLxiE4U", "senderPublicKey": "8E1ZoUTJyyA7ybXtP2NxUZKdAwvR1ruiQUxZD2bYJJMF", "proofs": [ "464E5Fum1ypuJjczmNH9RdZUYMtQPYaWBKr9i6sMWfSAXaxcNvRxna1H9TT9iTduJ8ZQ3VCYenrxbDi1552rZU5k" ], "script": "base64:BgIZCAISBAoCCAgSABIAEgQKAgEBEgMKAQgSABYADXdpdGhkcmF3RGVsYXkAtAsAD2RlY2ltYWxQYXJ0VVNETgDAhD0AD2RlY2ltYWxQYXJ0VVNEVADAhD0AF21pbmltYWxBbW91bnRUb1N3YXBVU0RUCQBoAgCQTgUPZGVjaW1hbFBhcnRVU0ROABdtaW5pbWFsQW1vdW50VG9Td2FwVVNETgkAaAIAkE4FD2RlY2ltYWxQYXJ0VVNEVAETa2V5TWFuYWdlclB1YmxpY0tleQACFCVzX19tYW5hZ2VyUHVibGljS2V5ARprZXlQZW5kaW5nTWFuYWdlclB1YmxpY0tleQACGyVzX19wZW5kaW5nTWFuYWdlclB1YmxpY0tleQEOa2V5VXNkdEFzc2V0SWQAAgglc19fVVNEVAEOa2V5VXNkbkFzc2V0SWQAAgglc19fVVNETgEWbWFuYWdlclB1YmxpY0tleU9yVW5pdAAEByRtYXRjaDAJAKIIAQkBE2tleU1hbmFnZXJQdWJsaWNLZXkAAwkAAQIFByRtYXRjaDACBlN0cmluZwQBcwUHJG1hdGNoMAkA2QQBBQFzAwkAAQIFByR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R4AQZ2ZXJpZnkABA90YXJnZXRQdWJsaWNLZXkEByRtYXRjaDAJARZtYW5hZ2VyUHVibGljS2V5T3JVbml0AAMJAAECBQckbWF0Y2gwAgpCeXRlVmVjdG9yBAJwawUHJG1hdGNoMAUCcGsDCQABAgUHJG1hdGNoMAIEVW5pdAgFAnR4D3NlbmRlclB1YmxpY0tleQkAAgECC01hdGNoIGVycm9yCQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAABQ90YXJnZXRQdWJsaWNLZXn6PZop", "chainId": 84, "height": 2146821, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: 4Sh1sWEgaRyo5KrvZiZhbGp6ri4p2j1sWLU9kjoYF89D Full:
Old | New | Differences | |
---|---|---|---|
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) = { | |
115 | + | let checkCaller = mustManager(i) | |
116 | + | if ((checkCaller == checkCaller)) | |
117 | + | then [StringEntry(keyUsdtAssetId(), usdtAssetId), StringEntry(keyUsdnAssetId(), usdnAssetId)] | |
118 | + | else throw("Strict value is not equal to itself.") | |
119 | + | } | |
120 | + | ||
121 | + | ||
122 | + | ||
123 | + | @Callable(invoke) | |
124 | + | func swapUSDTtoUSDN () = { | |
125 | + | let balanceKey = collectBalanceKeyWithFee(toString(invoke.caller)) | |
126 | + | let payment = value(invoke.payments[0]) | |
127 | + | if ((payment.assetId != fromBase58String(keyUsdtAssetId()))) | |
128 | + | then usdtToUsdnAssetError() | |
129 | + | else { | |
130 | + | let amount = payment.amount | |
131 | + | let fee = ((amount / 100) * 2) | |
132 | + | let currentClientBalanceUSDT = valueOrElse(getInteger(this, balanceKey), 0) | |
133 | + | if ((minimalAmountToSwapUSDT > amount)) | |
134 | + | then usdtToUsdnLowLimitError() | |
135 | + | else [IntegerEntry(balanceKey, (currentClientBalanceUSDT + amount)), ScriptTransfer(invoke.caller, (amount - fee), fromBase58String(keyUsdnAssetId()))] | |
136 | + | } | |
137 | + | } | |
138 | + | ||
139 | + | ||
140 | + | ||
141 | + | @Callable(invoke) | |
142 | + | func initializationUSDNtoUSDTswap () = { | |
143 | + | let payment = value(invoke.payments[0]) | |
144 | + | let address = toString(invoke.caller) | |
145 | + | if ((payment.assetId != fromBase58String(keyUsdnAssetId()))) | |
146 | + | then usdnToUsdtAssetError() | |
147 | + | else { | |
148 | + | let amount = payment.amount | |
149 | + | let balanceKey = collectBalanceKey(address) | |
150 | + | let balanceWithFeeKey = collectBalanceKeyWithFee(address) | |
151 | + | let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0) | |
152 | + | let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0) | |
153 | + | let userBalance = (currentClientBalance + currentClientBalanceWithFee) | |
154 | + | let data = currentWithdrawals(toString(invoke.caller), amount) | |
155 | + | let toWithdrawWithoutFee = valueOrErrorMessage(data[0], "Wrong 'currentWithdrawals' method!") | |
156 | + | let toWithdrawWithFee = valueOrErrorMessage(data[1], "Wrong 'currentWithdrawals' method!") | |
157 | + | let fee = valueOrErrorMessage(data[2], "Wrong 'currentWithdrawals' method!") | |
158 | + | let total = ((toWithdrawWithFee + toWithdrawWithoutFee) - fee) | |
159 | + | let allowToWithDrawHeight = (height + withdrawDelay) | |
160 | + | if (isDefined(getString(this, collectKey(toString(invoke.caller), amount, allowToWithDrawHeight)))) | |
161 | + | then throw("You have already started withdrawal process, wait next block.") | |
162 | + | else [IntegerEntry(balanceKey, (currentClientBalance - toWithdrawWithoutFee)), IntegerEntry(balanceWithFeeKey, (currentClientBalanceWithFee - toWithdrawWithFee)), StringEntry(collectKey(toString(invoke.caller), amount, allowToWithDrawHeight), makeString(["not_withdrawn", toString((amount - fee))], "_"))] | |
163 | + | } | |
164 | + | } | |
165 | + | ||
166 | + | ||
167 | + | ||
168 | + | @Callable(invoke) | |
169 | + | func swapUSDNtoUSDT (amount,heightInKey) = { | |
170 | + | let key = collectKey(toString(invoke.caller), amount, heightInKey) | |
171 | + | let withdrawnInfo = valueOrErrorMessage(getString(this, key), ((("This key doesn't exists " + key) + " at address ") + toString(this))) | |
172 | + | let toWithdraw = getListElementOrDefault(split(withdrawnInfo, "_"), 2, toString(amount)) | |
173 | + | if (if ((height >= heightInKey)) | |
174 | + | then contains(withdrawnInfo, "not_withdrawn") | |
175 | + | else false) | |
176 | + | then [DeleteEntry(key), ScriptTransfer(invoke.caller, valueOrErrorMessage(parseInt(toWithdraw), "Wrong withdraw data!"), fromBase58String(keyUsdtAssetId()))] | |
177 | + | else throw((("Withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT.")) | |
178 | + | } | |
179 | + | ||
180 | + | ||
181 | + | ||
182 | + | @Callable(i) | |
183 | + | func setManager (pendingManagerPublicKey) = { | |
184 | + | let checkCaller = mustManager(i) | |
185 | + | if ((checkCaller == checkCaller)) | |
186 | + | then { | |
187 | + | let checkManagerPublicKey = fromBase58String(pendingManagerPublicKey) | |
188 | + | if ((checkManagerPublicKey == checkManagerPublicKey)) | |
189 | + | then [StringEntry(keyPendingManagerPublicKey(), pendingManagerPublicKey)] | |
190 | + | else throw("Strict value is not equal to itself.") | |
191 | + | } | |
192 | + | else throw("Strict value is not equal to itself.") | |
193 | + | } | |
194 | + | ||
195 | + | ||
196 | + | ||
197 | + | @Callable(i) | |
198 | + | func confirmManager () = { | |
199 | + | let pm = pendingManagerPublicKeyOrUnit() | |
200 | + | let hasPM = if (isDefined(pm)) | |
201 | + | then true | |
202 | + | else throw("No pending manager") | |
203 | + | if ((hasPM == hasPM)) | |
204 | + | then { | |
205 | + | let checkPM = if ((i.callerPublicKey == value(pm))) | |
206 | + | then true | |
207 | + | else throw("You are not pending manager") | |
208 | + | if ((checkPM == checkPM)) | |
209 | + | then [StringEntry(keyManagerPublicKey(), toBase58String(value(pm))), DeleteEntry(keyPendingManagerPublicKey())] | |
210 | + | else throw("Strict value is not equal to itself.") | |
211 | + | } | |
212 | + | else throw("Strict value is not equal to itself.") | |
213 | + | } | |
214 | + | ||
215 | + | ||
216 | + | @Verifier(tx) | |
217 | + | func verify () = { | |
218 | + | let targetPublicKey = match managerPublicKeyOrUnit() { | |
219 | + | case pk: ByteVector => | |
220 | + | pk | |
221 | + | case _: Unit => | |
222 | + | tx.senderPublicKey | |
223 | + | case _ => | |
224 | + | throw("Match error") | |
225 | + | } | |
226 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
227 | + | } | |
228 | + |
github/deemru/w8io/026f985 24.84 ms ◑