tx · HJHQZ9ZMheJgCnthmmwiJhLjXWx6TB3ka7ohjnVR5FEM 3Mr3o7NWg8ALfPQBqSbDPAVxmRHmwrw7DSS: -0.01000000 Waves 2020.10.20 17:24 [1228999] smart account 3Mr3o7NWg8ALfPQBqSbDPAVxmRHmwrw7DSS > SELF 0.00000000 Waves
{ "type": 13, "id": "HJHQZ9ZMheJgCnthmmwiJhLjXWx6TB3ka7ohjnVR5FEM", "fee": 1000000, "feeAssetId": null, "timestamp": 1603203880902, "version": 2, "chainId": 84, "sender": "3Mr3o7NWg8ALfPQBqSbDPAVxmRHmwrw7DSS", "senderPublicKey": "7Cr1Tgm1DSS9JcrtDJRQveCL3U4e2F4NbszS8aCi5SHQ", "proofs": [ "26WgGrPhDy3XzKyLmhxvaXjhJ2yQvonBsvick1MUc949zh2gw1UkTJwbzKdN6jyP5Vj4eioSGtZWRCVZqn1KfNwF" ], "script": "base64:AAIEAAAAAAAAAAwIAhIAEgASBAoCAQEAAAAOAAAAAARVU0RUAgAAACwzRUptN1pOWlJqV25nalZRNnFqRlVlZjNpUlV5SlpvVDRWWW9DWWFlVmRxWgAAAAAEVVNETgIAAAAsMzdqVkhaSzJjZ2JOVEFrTUNMR2RyYnp2RzFyd01qVHJwRDJUR3praWN0d0wAAAAABmlkVVNETgkAAlkAAAABBQAAAARVU0ROAAAAAAZpZFVTRFQJAAJZAAAAAQUAAAAEVVNEVAAAAAANd2l0aGRyYXdEZWxheQAAAAAAAAAAAQAAAAAPZGVjaW1hbFBhcnRVU0ROAAAAAAAAD0JAAAAAAA9kZWNpbWFsUGFydFVTRFQAAAAAAAAPQkAAAAAAF21pbmltYWxBbW91bnRUb1N3YXBVU0RUCQAAaAAAAAIAAAAAAAAAJxAFAAAAD2RlY2ltYWxQYXJ0VVNETgAAAAAXbWluaW1hbEFtb3VudFRvU3dhcFVTRE4JAABoAAAAAgAAAAAAAAAnEAUAAAAPZGVjaW1hbFBhcnRVU0RUAQAAAApjb2xsZWN0S2V5AAAAAw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A25pbAkAAAIAAAABCQABLAAAAAIJAAEsAAAAAgIAAAAdd2l0aGRyYXdhbCBpcyBwb3NzaWJsZSBhZnRlciAJAAGkAAAAAQUAAAALaGVpZ2h0SW5LZXkCAAAAKiBoZWlnaHQgb3IgeW91IGhhdmUgYWxyZWFkeSB3aXRoZHJhd24gVVNEVAAAAABwANWw", "height": 1228999, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: none Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 4 #-} | |
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) = makeString([toString(address), "WITHDRAW", toString(amountToSwapInKey), "HEIGHT", toString(allowToWithdrawHeight)], "_") | |
23 | + | ||
24 | + | ||
25 | + | func collectBalanceKey (address) = makeString([toString(address), "balance"], "_") | |
26 | + | ||
27 | + | ||
28 | + | func collectBalanceKeyWithFee (address) = makeString([toString(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 usdtToUsdnLowLimitError () = throw((("you can swap at least " + toString((minimalAmountToSwapUSDT / decimalPartUSDT))) + " tokens")) | |
35 | + | ||
36 | + | ||
37 | + | @Callable(invoke) | |
38 | + | func swapUSDTtoUSDN () = { | |
39 | + | let balanceKey = collectBalanceKeyWithFee(invoke.caller) | |
40 | + | let payment = value(invoke.payments[0]) | |
41 | + | if ((payment.assetId != idUSDT)) | |
42 | + | then usdtToUsdnAssetError() | |
43 | + | else { | |
44 | + | let amount = payment.amount | |
45 | + | let currentClientBalanceUSDT = valueOrElse(getInteger(this, balanceKey), 0) | |
46 | + | if ((minimalAmountToSwapUSDT > amount)) | |
47 | + | then usdtToUsdnLowLimitError() | |
48 | + | else [IntegerEntry(balanceKey, (currentClientBalanceUSDT + amount)), ScriptTransfer(invoke.caller, amount, idUSDN)] | |
49 | + | } | |
50 | + | } | |
51 | + | ||
52 | + | ||
53 | + | ||
54 | + | @Callable(invoke) | |
55 | + | func initializationUSDNtoUSDTswap () = { | |
56 | + | let payment = value(invoke.payments[0]) | |
57 | + | let assetIdReceived = payment.assetId | |
58 | + | let paymentAmount = payment.amount | |
59 | + | let userAddress = invoke.caller | |
60 | + | let balanceKey = collectBalanceKey(invoke.caller) | |
61 | + | let currentClientBalanceUSDT = match getInteger(this, balanceKey) { | |
62 | + | case currentBalance: Int => | |
63 | + | getIntegerValue(this, balanceKey) | |
64 | + | case _ => | |
65 | + | 0 | |
66 | + | } | |
67 | + | if ((assetIdReceived != idUSDN)) | |
68 | + | then throw("to swap USDN to USDT you need attach payment in USDN") | |
69 | + | else if (if ((paymentAmount > currentClientBalanceUSDT)) | |
70 | + | then true | |
71 | + | else (minimalAmountToSwapUSDN > paymentAmount)) | |
72 | + | then throw("swap amount fail") | |
73 | + | else { | |
74 | + | let allowToWithDrawHeight = (height + withdrawDelay) | |
75 | + | if (isDefined(getString(this, collectKey(invoke.caller, paymentAmount, allowToWithDrawHeight)))) | |
76 | + | then throw("you have already started withdrawal process, wait next block") | |
77 | + | else [IntegerEntry((toString(invoke.caller) + "_balance"), (currentClientBalanceUSDT - paymentAmount)), StringEntry(collectKey(invoke.caller, paymentAmount, allowToWithDrawHeight), "not_withdrawn")] | |
78 | + | } | |
79 | + | } | |
80 | + | ||
81 | + | ||
82 | + | ||
83 | + | @Callable(invoke) | |
84 | + | func swapUSDNtoUSDT (amountToSwapInKey,heightInKey) = { | |
85 | + | let key = collectKey(invoke.caller, amountToSwapInKey, heightInKey) | |
86 | + | let withdrawnInfo = match getString(this, key) { | |
87 | + | case withdrawnInfo: String => | |
88 | + | getStringValue(this, key) | |
89 | + | case _ => | |
90 | + | throw(((("this key doesn't exists " + key) + " at address ") + toString(this))) | |
91 | + | } | |
92 | + | if (if ((height >= heightInKey)) | |
93 | + | then (withdrawnInfo == "not_withdrawn") | |
94 | + | else false) | |
95 | + | then [DeleteEntry(key), ScriptTransfer(invoke.caller, amountToSwapInKey, idUSDT)] | |
96 | + | else throw((("withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT")) | |
97 | + | } | |
98 | + | ||
99 | + |
github/deemru/w8io/fabc49c 17.79 ms ◑