tx · BrrPwBp1mQrE92yjfFyAgzAEuAy1qUW4E97RNWAFYqnY 3MxCNvgYGmRUBapjxYK6QJe93k3zGKmESW5: -0.01400000 Waves 2020.08.05 15:14 [1119101] smart account 3MxCNvgYGmRUBapjxYK6QJe93k3zGKmESW5 > SELF 0.00000000 Waves
{ "type": 13, "id": "BrrPwBp1mQrE92yjfFyAgzAEuAy1qUW4E97RNWAFYqnY", "fee": 1400000, "feeAssetId": null, "timestamp": 1596629696416, "version": 1, "sender": "3MxCNvgYGmRUBapjxYK6QJe93k3zGKmESW5", "senderPublicKey": "DUAUjNB9PvmJwZsXoeDa41DLxMj8tYAfSCr5NEzkuWku", "proofs": [ "3h2NGMcbtwK5pkPbFwag5GYk5JRMZWy1RoEFEu3srSGVUUWPnL8rv4JFSedgjYV5WUju9XjZ1EgHerLNHZwKk52j" ], "script": "base64:AAIDAAAAAAAAAAwIARIAEgASBAoCAQEAAAAJAAAAAARVU0RUAgAAACxETUplTTlYSlRFbmhCbVlyTEJkVktrWXg2R2ViMzdlOXBneUVjMjZSMUpLWgAAAAAEVVNETgIAAAAsN1lXVmJydld4Qm5UU1pHUk12UkJmcTV2cUFTOWtROFVmNXY1QlN4eWE2Wm8AAAAABmlkVVNETgkAAlkAAAABBQAAAARVU0ROAAAAAAZpZFVTRFQJAAJZAAAAAQUAAAAEVVNEVAAAAAANd2l0aGRyYXdEZWxheQAAAAAAAAAAAQAAAAAPZGVjaW1hbFBhcnRVU0ROAAAAAAAAD0JAAAAAAA9kZWNpbWFsUGFydFVTRFQAAAAAAAAPQkAAAAAAF21pbmltYWxBbW91bnRUb1N3YXBVU0RUCQAAaAAAAAIAAAAAAAABhqAFAAAAD2RlY2ltYWxQYXJ0VVNETgAAAAAXbWluaW1hbEFtb3VudFRvU3dhcFVTRE4JAABoAAAAAgAAAAAAAADDUAUAAAAPZGVjaW1hbFBhcnRVU0RUAAAAAwAAAApjb250ZXh0T2JqAQAAAA5zd2FwVVNEVHRvVVNETgAAAAAEAA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AAAIJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIFAAAAA2tleQIAAAAJd2l0aGRyYXduBQAAAANuaWwJAQAAAAtUcmFuc2ZlclNldAAAAAEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAACmNvbnRleHRPYmoAAAAGY2FsbGVyBQAAABFhbW91bnRUb1N3YXBJbktleQUAAAAGaWRVU0RUBQAAAANuaWwJAAACAAAAAQkAASwAAAACCQABLAAAAAICAAAAHXdpdGhkcmF3YWwgaXMgcG9zc2libGUgYWZ0ZXIgCQABpAAAAAEFAAAAC2hlaWdodEluS2V5AgAAACogaGVpZ2h0IG9yIHlvdSBoYXZlIGFscmVhZHkgd2l0aGRyYXduIFVTRFQAAAAA45j+gg==", "chainId": 84, "height": 1119101, "spentComplexity": 0 } View: original | compacted Prev: AZjGnbZw7ZCnJQtKYJWFb1koPB1b2hnMo4NGKWHX3EmM Next: none Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let USDT = "DMJeM9XJTEnhBmYrLBdVKkYx6Geb37e9pgyEc26R1JKZ" | |
5 | 5 | ||
6 | 6 | let USDN = "7YWVbrvWxBnTSZGRMvRBfq5vqAS9kQ8Uf5v5BSxya6Zo" | |
7 | 7 | ||
8 | 8 | let idUSDN = fromBase58String(USDN) | |
9 | 9 | ||
10 | 10 | let idUSDT = fromBase58String(USDT) | |
11 | 11 | ||
12 | 12 | let withdrawDelay = 1 | |
13 | 13 | ||
14 | 14 | let decimalPartUSDN = 1000000 | |
15 | 15 | ||
16 | 16 | let decimalPartUSDT = 1000000 | |
17 | 17 | ||
18 | 18 | let minimalAmountToSwapUSDT = (100000 * decimalPartUSDN) | |
19 | 19 | ||
20 | 20 | let minimalAmountToSwapUSDN = (50000 * decimalPartUSDT) | |
21 | 21 | ||
22 | 22 | @Callable(contextObj) | |
23 | 23 | func swapUSDTtoUSDN () = { | |
24 | 24 | let payment = match contextObj.payment { | |
25 | 25 | case p: AttachedPayment => | |
26 | 26 | p | |
27 | 27 | case _ => | |
28 | 28 | throw("Payment not attached") | |
29 | 29 | } | |
30 | 30 | let assetIdReceived = payment.assetId | |
31 | 31 | let tokenReceiveAmount = payment.amount | |
32 | 32 | let userAddress = contextObj.caller | |
33 | 33 | let currentClientBalanceUSDT = match getInteger(this, (toString(userAddress) + "_balance")) { | |
34 | 34 | case currentBalance: Int => | |
35 | 35 | value(getInteger(this, (toString(userAddress) + "_balance"))) | |
36 | 36 | case _ => | |
37 | 37 | 0 | |
38 | 38 | } | |
39 | 39 | if ((assetIdReceived != idUSDT)) | |
40 | 40 | then throw("to swap USDT to USDN you need attach payment in USDT") | |
41 | 41 | else if ((minimalAmountToSwapUSDT > tokenReceiveAmount)) | |
42 | 42 | then throw((("you can swap at least " + toString((minimalAmountToSwapUSDT / decimalPartUSDN))) + " tokens")) | |
43 | 43 | else ScriptResult(WriteSet([DataEntry((toString(contextObj.caller) + "_balance"), (currentClientBalanceUSDT + tokenReceiveAmount))]), TransferSet([ScriptTransfer(contextObj.caller, tokenReceiveAmount, idUSDN)])) | |
44 | 44 | } | |
45 | 45 | ||
46 | 46 | ||
47 | 47 | ||
48 | 48 | @Callable(contextObj) | |
49 | 49 | func initializationUSDNtoUSDTswap () = { | |
50 | 50 | let payment = match contextObj.payment { | |
51 | 51 | case p: AttachedPayment => | |
52 | 52 | p | |
53 | 53 | case _ => | |
54 | 54 | throw("Payment not attached") | |
55 | 55 | } | |
56 | 56 | let assetIdReceived = payment.assetId | |
57 | 57 | let paymentAmount = payment.amount | |
58 | 58 | let userAddress = contextObj.caller | |
59 | 59 | let currentClientBalanceUSDT = match getInteger(this, (toString(userAddress) + "_balance")) { | |
60 | 60 | case currentBalance: Int => | |
61 | 61 | getIntegerValue(this, (toString(userAddress) + "_balance")) | |
62 | 62 | case _ => | |
63 | 63 | 0 | |
64 | 64 | } | |
65 | 65 | if ((assetIdReceived != idUSDN)) | |
66 | 66 | then throw("to swap USDN to USDT you need attach payment in USDN") | |
67 | 67 | else if (if ((paymentAmount > currentClientBalanceUSDT)) | |
68 | 68 | then true | |
69 | 69 | else (minimalAmountToSwapUSDN > paymentAmount)) | |
70 | 70 | then throw("swap amount fail") | |
71 | 71 | else if (isDefined(getString(this, ((((toString(contextObj.caller) + "_WITHDRAW_") + toString(paymentAmount)) + "_HEIGHT_") + toString((height + withdrawDelay)))))) | |
72 | 72 | then throw("you have already started withdrawal process, wait next block") | |
73 | 73 | else ScriptResult(WriteSet([DataEntry((toString(contextObj.caller) + "_balance"), (currentClientBalanceUSDT - paymentAmount)), DataEntry(((((toString(contextObj.caller) + "_WITHDRAW_") + toString(paymentAmount)) + "_HEIGHT_") + toString((height + withdrawDelay))), "not_withdrawn")]), TransferSet(nil)) | |
74 | 74 | } | |
75 | 75 | ||
76 | 76 | ||
77 | 77 | ||
78 | 78 | @Callable(contextObj) | |
79 | 79 | func swapUSDNtoUSDT (amountToSwapInKey,heightInKey) = { | |
80 | 80 | let key = ((((toString(contextObj.caller) + "_WITHDRAW_") + toString(amountToSwapInKey)) + "_HEIGHT_") + toString(heightInKey)) | |
81 | 81 | let withdrawnInfo = match getString(this, key) { | |
82 | 82 | case withdrawnInfo: String => | |
83 | 83 | getStringValue(this, key) | |
84 | 84 | case _ => | |
85 | 85 | throw(((("this key doesn't exists " + key) + " at address ") + toString(this))) | |
86 | 86 | } | |
87 | 87 | if (if ((height >= heightInKey)) | |
88 | 88 | then (withdrawnInfo == "not_withdrawn") | |
89 | 89 | else false) | |
90 | 90 | then ScriptResult(WriteSet([DataEntry(key, "withdrawn")]), TransferSet([ScriptTransfer(contextObj.caller, amountToSwapInKey, idUSDT)])) | |
91 | 91 | else throw((("withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT")) | |
92 | 92 | } | |
93 | 93 | ||
94 | 94 |
github/deemru/w8io/169f3d6 23.38 ms ◑