tx · 6GpqWv48cT7ZpySQw5Zy1iWWTLu8xgkEYHdkFCQ36LNX 3NAG1m2jZspP4mUqX2MGTDaUgSa4hfcyqkB: -0.01000000 Waves 2020.10.20 16:09 [1228927] smart account 3NAG1m2jZspP4mUqX2MGTDaUgSa4hfcyqkB > SELF 0.00000000 Waves
{ "type": 13, "id": "6GpqWv48cT7ZpySQw5Zy1iWWTLu8xgkEYHdkFCQ36LNX", "fee": 1000000, "feeAssetId": null, "timestamp": 1603199430105, "version": 2, "chainId": 84, "sender": "3NAG1m2jZspP4mUqX2MGTDaUgSa4hfcyqkB", "senderPublicKey": "DaqVYwTA2yseum9bqh7yApEpP6xzKFtDEbui9wLGTEz8", "proofs": [ "62XJYNtetMoZ8y7hpiwZmMuj8Tv45hwx3f6ZxYYydyjZJZV73o4CvWsa58dtTr631H7qmSBaRF2pQfHag7W1vPTe" ], "script": "base64:AAIEAAAAAAAAAAwIAhIAEgASBAoCAQEAAAAKAAAAAARVU0RUAgAAACwzRUptN1pOWlJqV25nalZRNnFqRlVlZjNpUlV5SlpvVDRWWW9DWWFlVmRxWgAAAAAEVVNETgIAAAAsMzdqVkhaSzJjZ2JOVEFrTUNMR2RyYnp2RzFyd01qVHJwRDJUR3praWN0d0wAAAAABmlkVVNETgkAAlkAAAABBQAAAARVU0ROAAAAAAZpZFVTRFQJAAJZAAAAAQUAAAAEVVNEVAAAAAANd2l0aGRyYXdEZWxheQAAAAAAAAAAAQAAAAAPZGVjaW1hbFBhcnRVU0ROAAAAAAAAD0JAAAAAAA9kZWNpbWFsUGFydFVTRFQAAAAAAAAPQkAAAAAAF21pbmltYWxBbW91bnRUb1N3YXBVU0RUCQAAaAAAAAIAAAAAAAAAJxAFAAAAD2RlY2ltYWxQYXJ0VVNETgAAAAAXbWluaW1hbEFtb3VudFRvU3dhcFVTRE4JAABoAAAAAgAAAAAAAAAnEAUAAAAPZGVjaW1hbFBhcnRVU0RUAQAAAApjb2xsZWN0S2V5AAAAAwAAAAdhZGRyZ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AAAAAIAAAARYW1vdW50VG9Td2FwSW5LZXkAAAALaGVpZ2h0SW5LZXkEAAAAA2tleQkBAAAACmNvbGxlY3RLZXkAAAADCAUAAAAKY29udGV4dE9iagAAAAZjYWxsZXIFAAAAEWFtb3VudFRvU3dhcEluS2V5BQAAAAtoZWlnaHRJbktleQQAAAANd2l0aGRyYXduSW5mbwQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAANd2l0aGRyYXduSW5mbwUAAAAHJG1hdGNoMAkBAAAAEUBleHRyTmF0aXZlKDEwNTMpAAAAAgUAAAAEdGhpcwUAAAADa2V5CQAAAgAAAAEJAAEsAAAAAgkAASwAAAACCQABLAAAAAICAAAAGHRoaXMga2V5IGRvZXNuJ3QgZXhpc3RzIAUAAAADa2V5AgAAAA0gYXQgYWRkcmVzcyAgCQAEJQAAAAEFAAAABHRoaXMDAwkAAGcAAAACBQAAAAZoZWlnaHQFAAAAC2hlaWdodEluS2V5CQAAAAAAAAIFAAAADXdpdGhkcmF3bkluZm8CAAAADW5vdF93aXRoZHJhd24HCQAETAAAAAIJAQAAAAtTdHJpbmdFbnRyeQAAAAIFAAAAA2tleQIAAAAJd2l0aGRyYXduCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAApjb250ZXh0T2JqAAAABmNhbGxlcgUAAAARYW1vdW50VG9Td2FwSW5LZXkFAAAABmlkVVNEVAUAAAADbmlsCQAAAgAAAAEJAAEsAAAAAgkAASwAAAACAgAAAB13aXRoZHJhd2FsIGlzIHBvc3NpYmxlIGFmdGVyIAkAAaQAAAABBQAAAAtoZWlnaHRJbktleQIAAAAqIGhlaWdodCBvciB5b3UgaGF2ZSBhbHJlYWR5IHdpdGhkcmF3biBVU0RUAAAAAAsgO3c=", "height": 1228927, "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) = ((((toString(address) + "_WITHDRAW_") + toString(amountToSwapInKey)) + "_HEIGHT_") + toString(allowToWithdrawHeight)) | |
23 | + | ||
24 | + | ||
25 | + | @Callable(contextObj) | |
26 | + | func swapUSDTtoUSDN () = { | |
27 | + | let payment = value(contextObj.payments[0]) | |
28 | + | let assetIdReceived = payment.assetId | |
29 | + | let tokenReceiveAmount = payment.amount | |
30 | + | let userAddress = contextObj.caller | |
31 | + | let currentClientBalanceUSDT = valueOrElse(getInteger(this, (toString(userAddress) + "_balance")), 0) | |
32 | + | if ((assetIdReceived != idUSDT)) | |
33 | + | then throw("to swap USDT to USDN you need attach payment in USDT") | |
34 | + | else if ((minimalAmountToSwapUSDT > tokenReceiveAmount)) | |
35 | + | then throw((("you can swap at least " + toString((minimalAmountToSwapUSDT / decimalPartUSDT))) + " tokens")) | |
36 | + | else [IntegerEntry((toString(contextObj.caller) + "_balance"), (currentClientBalanceUSDT + tokenReceiveAmount)), ScriptTransfer(contextObj.caller, tokenReceiveAmount, idUSDN)] | |
37 | + | } | |
38 | + | ||
39 | + | ||
40 | + | ||
41 | + | @Callable(contextObj) | |
42 | + | func initializationUSDNtoUSDTswap () = { | |
43 | + | let payment = value(contextObj.payments[0]) | |
44 | + | let assetIdReceived = payment.assetId | |
45 | + | let paymentAmount = payment.amount | |
46 | + | let userAddress = contextObj.caller | |
47 | + | let currentClientBalanceUSDT = match getInteger(this, (toString(userAddress) + "_balance")) { | |
48 | + | case currentBalance: Int => | |
49 | + | getIntegerValue(this, (toString(userAddress) + "_balance")) | |
50 | + | case _ => | |
51 | + | 0 | |
52 | + | } | |
53 | + | if ((assetIdReceived != idUSDN)) | |
54 | + | then throw("to swap USDN to USDT you need attach payment in USDN") | |
55 | + | else if (if ((paymentAmount > currentClientBalanceUSDT)) | |
56 | + | then true | |
57 | + | else (minimalAmountToSwapUSDN > paymentAmount)) | |
58 | + | then throw("swap amount fail") | |
59 | + | else { | |
60 | + | let allowToWithDrawHeight = (height + withdrawDelay) | |
61 | + | if (isDefined(getString(this, collectKey(contextObj.caller, paymentAmount, allowToWithDrawHeight)))) | |
62 | + | then throw("you have already started withdrawal process, wait next block") | |
63 | + | else [IntegerEntry((toString(contextObj.caller) + "_balance"), (currentClientBalanceUSDT - paymentAmount)), StringEntry(collectKey(contextObj.caller, paymentAmount, allowToWithDrawHeight), "not_withdrawn")] | |
64 | + | } | |
65 | + | } | |
66 | + | ||
67 | + | ||
68 | + | ||
69 | + | @Callable(contextObj) | |
70 | + | func swapUSDNtoUSDT (amountToSwapInKey,heightInKey) = { | |
71 | + | let key = collectKey(contextObj.caller, amountToSwapInKey, heightInKey) | |
72 | + | let withdrawnInfo = match getString(this, key) { | |
73 | + | case withdrawnInfo: String => | |
74 | + | getStringValue(this, key) | |
75 | + | case _ => | |
76 | + | throw(((("this key doesn't exists " + key) + " at address ") + toString(this))) | |
77 | + | } | |
78 | + | if (if ((height >= heightInKey)) | |
79 | + | then (withdrawnInfo == "not_withdrawn") | |
80 | + | else false) | |
81 | + | then [StringEntry(key, "withdrawn"), ScriptTransfer(contextObj.caller, amountToSwapInKey, idUSDT)] | |
82 | + | else throw((("withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT")) | |
83 | + | } | |
84 | + | ||
85 | + |
github/deemru/w8io/026f985 12.98 ms ◑