tx · 4b3HoiU2gePZJeFgYUMUdzvUnVEynZhXB2ZCPpLxQnuV 3N1FWHMYZ9QJDkUaMPxexydkBqiUxEk3J6o: -0.01400000 Waves 2020.11.10 10:56 [1258966] smart account 3N1FWHMYZ9QJDkUaMPxexydkBqiUxEk3J6o > SELF 0.00000000 Waves
{ "type": 13, "id": "4b3HoiU2gePZJeFgYUMUdzvUnVEynZhXB2ZCPpLxQnuV", "fee": 1400000, "feeAssetId": null, "timestamp": 1604995000929, "version": 1, "sender": "3N1FWHMYZ9QJDkUaMPxexydkBqiUxEk3J6o", "senderPublicKey": "oH6E3DnZcMibsYC4VB7KvfemJfz3koDVwZ5Z3pXGpCN", "proofs": [ "5SyjKQV7XjvgomYxHARwoMBoGEMYHkGgJngZXPf7mKVnN8SeG3y6djykaHKAGkaZMawc5zCn9jjaXUq1BqH16qa3" ], "script": "base64:AAIEAAAAAAAAAAwIAhIAEgASBAoCAQEAAAATAAAAAARVU0RUAgAAACw1U2g5S2doZmtaeWhqd3VvZG92RGhCNlBnaERVR0JIaUFQWjRNa3JQZ0t0WAAAAAAEVVNETgIAAAAsMjVGRXFFalJrcUs2eUNraVQ3THo2U0FZejdnVUZDdHhmQ0NobnJWRkQ1QVQAAAAABmlkVVNETgkAAlkAAAABBQAAAARVU0ROAAAAAAZpZFVTRFQJAAJZAAAAAQUAAAAEVVNEVAAAAAANd2l0aGRyYXdEZWxheQAAAAAAAAAAAgAAAAAPZGVjaW1hbFBhcnRVU0ROAAAAAAAAD0JAAAAAAA9kZWNpbWFsUGFydFVTRFQAAAAAAAAPQkAAAAAAF21pbmltYWxBbW91bnRUb1N3YXBVU0RUCQAAaAAAAAIAAAAAAAAAJxAFAAAAD2RlY2ltYWxQYXJ0VVNETgAAAAAXbWluaW1hbEFtb3VudFRvU3dhcFVTRE4JAABoAAAAAgAAAAAAAAAnEAUAAAAPZGVjaW1hbFBhcnRVU0RUAQAAAApjb2xsZWN0S2V5AAAAAwAAAAdhZGRyZXNzAAAAEW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cwQAAAAKdG9XaXRoZHJhdwkBAAAAF2dldExpc3RFbGVtZW50T3JEZWZhdWx0AAAAAwkABLUAAAACBQAAAA13aXRoZHJhd25JbmZvAgAAAAFfAAAAAAAAAAACCQABpAAAAAEFAAAABmFtb3VudAMDCQAAZwAAAAIFAAAABmhlaWdodAUAAAALaGVpZ2h0SW5LZXkJAQAAAAhjb250YWlucwAAAAIFAAAADXdpdGhkcmF3bkluZm8CAAAADW5vdF93aXRoZHJhd24HCQAETAAAAAIJAQAAAAtEZWxldGVFbnRyeQAAAAEFAAAAA2tleQkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCAUAAAAGaW52b2tlAAAABmNhbGxlcgkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEtgAAAAEFAAAACnRvV2l0aGRyYXcCAAAAFFdyb25nIHdpdGhkcmF3IGRhdGEhBQAAAAZpZFVTRFQFAAAAA25pbAkAAAIAAAABCQABLAAAAAIJAAEsAAAAAgIAAAAdV2l0aGRyYXdhbCBpcyBwb3NzaWJsZSBhZnRlciAJAAGkAAAAAQUAAAALaGVpZ2h0SW5LZXkCAAAAKyBoZWlnaHQgb3IgeW91IGhhdmUgYWxyZWFkeSB3aXRoZHJhd24gVVNEVC4AAAAAAG/iKg==", "chainId": 84, "height": 1258966, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3ME835z4bBUvt9SCcmSsNdsy4TS7V5M5i6Fa6eDuyv3i Next: none Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let a = "5Sh9KghfkZyhjwuodovDhB6PghDUGBHiAPZ4MkrPgKtX" | |
19 | 19 | ||
20 | 20 | let i = (10000 * g) | |
21 | 21 | ||
22 | - | func j (k,l,m) = ( | |
22 | + | func j (k,l,m) = makeString([k, "WITHDRAW", toString(l), "HEIGHT", toString(m)], "_") | |
23 | 23 | ||
24 | 24 | ||
25 | - | @Callable(n) | |
25 | + | func n (k) = makeString([k, "balance"], "_") | |
26 | + | ||
27 | + | ||
28 | + | func o (k) = makeString([k, "balance_with_fee"], "_") | |
29 | + | ||
30 | + | ||
31 | + | func p () = throw("To swap USDT to USDN you need attach payment in USDT") | |
32 | + | ||
33 | + | ||
34 | + | func q () = throw("To swap USDN to USDT you need attach payment in USDN") | |
35 | + | ||
36 | + | ||
37 | + | func r () = throw((("you can swap at least " + toString((h / g))) + " tokens")) | |
38 | + | ||
39 | + | ||
40 | + | func s (t) = if ((0 > t)) | |
41 | + | then (t * -1) | |
42 | + | else t | |
43 | + | ||
44 | + | ||
45 | + | func u (v,w) = min([v, w]) | |
46 | + | ||
47 | + | ||
48 | + | func x (y,z,A) = if ((size(y) > z)) | |
49 | + | then y[z] | |
50 | + | else A | |
51 | + | ||
52 | + | ||
53 | + | func B (k,v) = { | |
54 | + | let C = n(k) | |
55 | + | let D = o(k) | |
56 | + | let E = valueOrElse(getInteger(this, C), 0) | |
57 | + | let F = valueOrElse(getInteger(this, D), 0) | |
58 | + | let G = (E + F) | |
59 | + | if (if ((v > G)) | |
60 | + | then true | |
61 | + | else (i > v)) | |
62 | + | then throw("Swap amount fail, amount is to small or to big.") | |
63 | + | else { | |
64 | + | let H = u(v, E) | |
65 | + | let I = (v - H) | |
66 | + | let J = ((I / 100) * 1) | |
67 | + | [H, I, J] | |
68 | + | } | |
69 | + | } | |
70 | + | ||
71 | + | ||
72 | + | @Callable(K) | |
26 | 73 | func swapUSDTtoUSDN () = { | |
27 | - | let o = { | |
28 | - | let p = n.payment | |
29 | - | if ($isInstanceOf(p, "AttachedPayment")) | |
30 | - | then { | |
31 | - | let q = p | |
32 | - | q | |
33 | - | } | |
34 | - | else throw("Payment not attached") | |
35 | - | } | |
36 | - | let r = o.assetId | |
37 | - | let s = o.amount | |
38 | - | let t = n.caller | |
39 | - | let u = { | |
40 | - | let p = getInteger(this, (toString(t) + "_balance")) | |
41 | - | if ($isInstanceOf(p, "Int")) | |
42 | - | then { | |
43 | - | let v = p | |
44 | - | value(getInteger(this, (toString(t) + "_balance"))) | |
45 | - | } | |
46 | - | else 0 | |
47 | - | } | |
48 | - | if ((r != d)) | |
49 | - | then throw("to swap USDT to USDN you need attach payment in USDT") | |
50 | - | else if ((h > s)) | |
51 | - | then throw((("you can swap at least " + toString((h / g))) + " tokens")) | |
52 | - | else ScriptResult(WriteSet([DataEntry((toString(n.caller) + "_balance"), (u + s))]), TransferSet([ScriptTransfer(n.caller, s, c)])) | |
74 | + | let C = o(toString(K.caller)) | |
75 | + | let L = value(K.payments[0]) | |
76 | + | if ((L.assetId != d)) | |
77 | + | then p() | |
78 | + | else { | |
79 | + | let v = L.amount | |
80 | + | let J = ((v / 100) * 1) | |
81 | + | let M = valueOrElse(getInteger(this, C), 0) | |
82 | + | if ((h > v)) | |
83 | + | then r() | |
84 | + | else [IntegerEntry(C, (M + v)), ScriptTransfer(K.caller, (v - J), c)] | |
85 | + | } | |
53 | 86 | } | |
54 | 87 | ||
55 | 88 | ||
56 | 89 | ||
57 | - | @Callable( | |
90 | + | @Callable(K) | |
58 | 91 | func initializationUSDNtoUSDTswap () = { | |
59 | - | let o = { | |
60 | - | let p = n.payment | |
61 | - | if ($isInstanceOf(p, "AttachedPayment")) | |
62 | - | then { | |
63 | - | let q = p | |
64 | - | q | |
65 | - | } | |
66 | - | else throw("Payment not attached") | |
67 | - | } | |
68 | - | let r = o.assetId | |
69 | - | let w = o.amount | |
70 | - | let t = n.caller | |
71 | - | let u = { | |
72 | - | let p = getInteger(this, (toString(t) + "_balance")) | |
73 | - | if ($isInstanceOf(p, "Int")) | |
74 | - | then { | |
75 | - | let v = p | |
76 | - | getIntegerValue(this, (toString(t) + "_balance")) | |
77 | - | } | |
78 | - | else 0 | |
79 | - | } | |
80 | - | if ((r != c)) | |
81 | - | then throw("to swap USDN to USDT you need attach payment in USDN") | |
82 | - | else if (if ((w > u)) | |
83 | - | then true | |
84 | - | else (i > w)) | |
85 | - | then throw("swap amount fail") | |
86 | - | else { | |
87 | - | let x = (height + e) | |
88 | - | if (isDefined(getString(this, j(n.caller, w, x)))) | |
89 | - | then throw("you have already started withdrawal process, wait next block") | |
90 | - | else ScriptResult(WriteSet([DataEntry((toString(n.caller) + "_balance"), (u - w)), DataEntry(j(n.caller, w, x), "not_withdrawn")]), TransferSet(nil)) | |
91 | - | } | |
92 | + | let L = value(K.payments[0]) | |
93 | + | let k = toString(K.caller) | |
94 | + | if ((L.assetId != c)) | |
95 | + | then q() | |
96 | + | else { | |
97 | + | let v = L.amount | |
98 | + | let C = n(k) | |
99 | + | let D = o(k) | |
100 | + | let E = valueOrElse(getInteger(this, C), 0) | |
101 | + | let F = valueOrElse(getInteger(this, D), 0) | |
102 | + | let G = (E + F) | |
103 | + | let N = B(toString(K.caller), v) | |
104 | + | let H = valueOrErrorMessage(N[0], "Wrong 'currentWithdrawals' method!") | |
105 | + | let I = valueOrErrorMessage(N[1], "Wrong 'currentWithdrawals' method!") | |
106 | + | let J = valueOrErrorMessage(N[2], "Wrong 'currentWithdrawals' method!") | |
107 | + | let O = ((I + H) - J) | |
108 | + | let P = (height + e) | |
109 | + | if (isDefined(getString(this, j(toString(K.caller), v, P)))) | |
110 | + | then throw("You have already started withdrawal process, wait next block.") | |
111 | + | else [IntegerEntry(C, (E - H)), IntegerEntry(D, (F - I)), StringEntry(j(toString(K.caller), v, P), makeString(["not_withdrawn", toString((v - J))], "_"))] | |
112 | + | } | |
92 | 113 | } | |
93 | 114 | ||
94 | 115 | ||
95 | 116 | ||
96 | - | @Callable(n) | |
97 | - | func swapUSDNtoUSDT (l,y) = { | |
98 | - | let z = j(n.caller, l, y) | |
99 | - | let A = { | |
100 | - | let p = getString(this, z) | |
101 | - | if ($isInstanceOf(p, "String")) | |
102 | - | then { | |
103 | - | let A = p | |
104 | - | getStringValue(this, z) | |
105 | - | } | |
106 | - | else throw(((("this key doesn't exists " + z) + " at address ") + toString(this))) | |
107 | - | } | |
108 | - | if (if ((height >= y)) | |
109 | - | then (A == "not_withdrawn") | |
117 | + | @Callable(K) | |
118 | + | func swapUSDNtoUSDT (v,Q) = { | |
119 | + | let R = j(toString(K.caller), v, Q) | |
120 | + | let S = valueOrErrorMessage(getString(this, R), ((("This key doesn't exists " + R) + " at address ") + toString(this))) | |
121 | + | let T = x(split(S, "_"), 2, toString(v)) | |
122 | + | if (if ((height >= Q)) | |
123 | + | then contains(S, "not_withdrawn") | |
110 | 124 | else false) | |
111 | - | then | |
112 | - | else throw(((" | |
125 | + | then [DeleteEntry(R), ScriptTransfer(K.caller, valueOrErrorMessage(parseInt(T), "Wrong withdraw data!"), d)] | |
126 | + | else throw((("Withdrawal is possible after " + toString(Q)) + " height or you have already withdrawn USDT.")) | |
113 | 127 | } | |
114 | 128 | ||
115 | 129 |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let a = "5Sh9KghfkZyhjwuodovDhB6PghDUGBHiAPZ4MkrPgKtX" | |
5 | 5 | ||
6 | 6 | let b = "25FEqEjRkqK6yCkiT7Lz6SAYz7gUFCtxfCChnrVFD5AT" | |
7 | 7 | ||
8 | 8 | let c = fromBase58String(b) | |
9 | 9 | ||
10 | 10 | let d = fromBase58String(a) | |
11 | 11 | ||
12 | 12 | let e = 2 | |
13 | 13 | ||
14 | 14 | let f = 1000000 | |
15 | 15 | ||
16 | 16 | let g = 1000000 | |
17 | 17 | ||
18 | 18 | let h = (10000 * f) | |
19 | 19 | ||
20 | 20 | let i = (10000 * g) | |
21 | 21 | ||
22 | - | func j (k,l,m) = ( | |
22 | + | func j (k,l,m) = makeString([k, "WITHDRAW", toString(l), "HEIGHT", toString(m)], "_") | |
23 | 23 | ||
24 | 24 | ||
25 | - | @Callable(n) | |
25 | + | func n (k) = makeString([k, "balance"], "_") | |
26 | + | ||
27 | + | ||
28 | + | func o (k) = makeString([k, "balance_with_fee"], "_") | |
29 | + | ||
30 | + | ||
31 | + | func p () = throw("To swap USDT to USDN you need attach payment in USDT") | |
32 | + | ||
33 | + | ||
34 | + | func q () = throw("To swap USDN to USDT you need attach payment in USDN") | |
35 | + | ||
36 | + | ||
37 | + | func r () = throw((("you can swap at least " + toString((h / g))) + " tokens")) | |
38 | + | ||
39 | + | ||
40 | + | func s (t) = if ((0 > t)) | |
41 | + | then (t * -1) | |
42 | + | else t | |
43 | + | ||
44 | + | ||
45 | + | func u (v,w) = min([v, w]) | |
46 | + | ||
47 | + | ||
48 | + | func x (y,z,A) = if ((size(y) > z)) | |
49 | + | then y[z] | |
50 | + | else A | |
51 | + | ||
52 | + | ||
53 | + | func B (k,v) = { | |
54 | + | let C = n(k) | |
55 | + | let D = o(k) | |
56 | + | let E = valueOrElse(getInteger(this, C), 0) | |
57 | + | let F = valueOrElse(getInteger(this, D), 0) | |
58 | + | let G = (E + F) | |
59 | + | if (if ((v > G)) | |
60 | + | then true | |
61 | + | else (i > v)) | |
62 | + | then throw("Swap amount fail, amount is to small or to big.") | |
63 | + | else { | |
64 | + | let H = u(v, E) | |
65 | + | let I = (v - H) | |
66 | + | let J = ((I / 100) * 1) | |
67 | + | [H, I, J] | |
68 | + | } | |
69 | + | } | |
70 | + | ||
71 | + | ||
72 | + | @Callable(K) | |
26 | 73 | func swapUSDTtoUSDN () = { | |
27 | - | let o = { | |
28 | - | let p = n.payment | |
29 | - | if ($isInstanceOf(p, "AttachedPayment")) | |
30 | - | then { | |
31 | - | let q = p | |
32 | - | q | |
33 | - | } | |
34 | - | else throw("Payment not attached") | |
35 | - | } | |
36 | - | let r = o.assetId | |
37 | - | let s = o.amount | |
38 | - | let t = n.caller | |
39 | - | let u = { | |
40 | - | let p = getInteger(this, (toString(t) + "_balance")) | |
41 | - | if ($isInstanceOf(p, "Int")) | |
42 | - | then { | |
43 | - | let v = p | |
44 | - | value(getInteger(this, (toString(t) + "_balance"))) | |
45 | - | } | |
46 | - | else 0 | |
47 | - | } | |
48 | - | if ((r != d)) | |
49 | - | then throw("to swap USDT to USDN you need attach payment in USDT") | |
50 | - | else if ((h > s)) | |
51 | - | then throw((("you can swap at least " + toString((h / g))) + " tokens")) | |
52 | - | else ScriptResult(WriteSet([DataEntry((toString(n.caller) + "_balance"), (u + s))]), TransferSet([ScriptTransfer(n.caller, s, c)])) | |
74 | + | let C = o(toString(K.caller)) | |
75 | + | let L = value(K.payments[0]) | |
76 | + | if ((L.assetId != d)) | |
77 | + | then p() | |
78 | + | else { | |
79 | + | let v = L.amount | |
80 | + | let J = ((v / 100) * 1) | |
81 | + | let M = valueOrElse(getInteger(this, C), 0) | |
82 | + | if ((h > v)) | |
83 | + | then r() | |
84 | + | else [IntegerEntry(C, (M + v)), ScriptTransfer(K.caller, (v - J), c)] | |
85 | + | } | |
53 | 86 | } | |
54 | 87 | ||
55 | 88 | ||
56 | 89 | ||
57 | - | @Callable( | |
90 | + | @Callable(K) | |
58 | 91 | func initializationUSDNtoUSDTswap () = { | |
59 | - | let o = { | |
60 | - | let p = n.payment | |
61 | - | if ($isInstanceOf(p, "AttachedPayment")) | |
62 | - | then { | |
63 | - | let q = p | |
64 | - | q | |
65 | - | } | |
66 | - | else throw("Payment not attached") | |
67 | - | } | |
68 | - | let r = o.assetId | |
69 | - | let w = o.amount | |
70 | - | let t = n.caller | |
71 | - | let u = { | |
72 | - | let p = getInteger(this, (toString(t) + "_balance")) | |
73 | - | if ($isInstanceOf(p, "Int")) | |
74 | - | then { | |
75 | - | let v = p | |
76 | - | getIntegerValue(this, (toString(t) + "_balance")) | |
77 | - | } | |
78 | - | else 0 | |
79 | - | } | |
80 | - | if ((r != c)) | |
81 | - | then throw("to swap USDN to USDT you need attach payment in USDN") | |
82 | - | else if (if ((w > u)) | |
83 | - | then true | |
84 | - | else (i > w)) | |
85 | - | then throw("swap amount fail") | |
86 | - | else { | |
87 | - | let x = (height + e) | |
88 | - | if (isDefined(getString(this, j(n.caller, w, x)))) | |
89 | - | then throw("you have already started withdrawal process, wait next block") | |
90 | - | else ScriptResult(WriteSet([DataEntry((toString(n.caller) + "_balance"), (u - w)), DataEntry(j(n.caller, w, x), "not_withdrawn")]), TransferSet(nil)) | |
91 | - | } | |
92 | + | let L = value(K.payments[0]) | |
93 | + | let k = toString(K.caller) | |
94 | + | if ((L.assetId != c)) | |
95 | + | then q() | |
96 | + | else { | |
97 | + | let v = L.amount | |
98 | + | let C = n(k) | |
99 | + | let D = o(k) | |
100 | + | let E = valueOrElse(getInteger(this, C), 0) | |
101 | + | let F = valueOrElse(getInteger(this, D), 0) | |
102 | + | let G = (E + F) | |
103 | + | let N = B(toString(K.caller), v) | |
104 | + | let H = valueOrErrorMessage(N[0], "Wrong 'currentWithdrawals' method!") | |
105 | + | let I = valueOrErrorMessage(N[1], "Wrong 'currentWithdrawals' method!") | |
106 | + | let J = valueOrErrorMessage(N[2], "Wrong 'currentWithdrawals' method!") | |
107 | + | let O = ((I + H) - J) | |
108 | + | let P = (height + e) | |
109 | + | if (isDefined(getString(this, j(toString(K.caller), v, P)))) | |
110 | + | then throw("You have already started withdrawal process, wait next block.") | |
111 | + | else [IntegerEntry(C, (E - H)), IntegerEntry(D, (F - I)), StringEntry(j(toString(K.caller), v, P), makeString(["not_withdrawn", toString((v - J))], "_"))] | |
112 | + | } | |
92 | 113 | } | |
93 | 114 | ||
94 | 115 | ||
95 | 116 | ||
96 | - | @Callable(n) | |
97 | - | func swapUSDNtoUSDT (l,y) = { | |
98 | - | let z = j(n.caller, l, y) | |
99 | - | let A = { | |
100 | - | let p = getString(this, z) | |
101 | - | if ($isInstanceOf(p, "String")) | |
102 | - | then { | |
103 | - | let A = p | |
104 | - | getStringValue(this, z) | |
105 | - | } | |
106 | - | else throw(((("this key doesn't exists " + z) + " at address ") + toString(this))) | |
107 | - | } | |
108 | - | if (if ((height >= y)) | |
109 | - | then (A == "not_withdrawn") | |
117 | + | @Callable(K) | |
118 | + | func swapUSDNtoUSDT (v,Q) = { | |
119 | + | let R = j(toString(K.caller), v, Q) | |
120 | + | let S = valueOrErrorMessage(getString(this, R), ((("This key doesn't exists " + R) + " at address ") + toString(this))) | |
121 | + | let T = x(split(S, "_"), 2, toString(v)) | |
122 | + | if (if ((height >= Q)) | |
123 | + | then contains(S, "not_withdrawn") | |
110 | 124 | else false) | |
111 | - | then | |
112 | - | else throw(((" | |
125 | + | then [DeleteEntry(R), ScriptTransfer(K.caller, valueOrErrorMessage(parseInt(T), "Wrong withdraw data!"), d)] | |
126 | + | else throw((("Withdrawal is possible after " + toString(Q)) + " height or you have already withdrawn USDT.")) | |
113 | 127 | } | |
114 | 128 | ||
115 | 129 |
github/deemru/w8io/026f985 31.03 ms ◑