tx · Gp8F5a2A9udVEu5dHErfM4c4QihomHcKo41sKHmt81YA 3N4xbosJ1BLfiKpkdu5jL7vsU6zAXCWbbeR: -0.01000000 Waves 2020.12.18 13:49 [1314026] smart account 3N4xbosJ1BLfiKpkdu5jL7vsU6zAXCWbbeR > SELF 0.00000000 Waves
{ "type": 13, "id": "Gp8F5a2A9udVEu5dHErfM4c4QihomHcKo41sKHmt81YA", "fee": 1000000, "feeAssetId": null, "timestamp": 1608288597032, "version": 2, "chainId": 84, "sender": "3N4xbosJ1BLfiKpkdu5jL7vsU6zAXCWbbeR", "senderPublicKey": "DR5QMLxxNPMwoYsJb8QiQVovbyvvZ2GuxeNcjAzxspLH", "proofs": [ "3f849JUo5gMazSPq3YKJTTkrrAYE7Y1FiYGSGAaFPM7CT5iKMqKh3vQUeDW4ZD97eprAXaBZKoSFjLEryPXjS8bH" ], "script": "base64:AAIEAAAAAAAAAAwIAhIAEgASBAoCAQEAAAATAAAAAARVU0RUAgAAACw2RFVlWTlnOTVVTjJNRXZLVUcySGQxckhSWnZvUDNISnF5bVpuNFpzdWNQcwAAAAAEVVNETgIAAAAsMjRtSFpMWmMyYlpIcW5VTFRacFdiRUVvZzNTZlNWenJkNXY0YnJ6OXFEN1QAAAAABmlkVVNETgkAAlkAAAABBQAAAARVU0ROAAAAAAZpZFVTRFQJAAJZAAAAAQUAAAAEVVNEVAAAAAANd2l0aGRyYXdEZWxheQAAAAAAAAAAAQAAAAAPZGVjaW1hbFBhcnRVU0ROAAAAAAAAD0JAAAAAAA9kZWNpbWFsUGFydFVTRFQAAAAAAAAPQkAAAAAAF21pbmltYWxBbW91bnRUb1N3YXBVU0RUCQAAaAAAAAIAAAAAAAAAJxAFAAAAD2RlY2ltYWxQYXJ0VVNETgAAAAAXbWluaW1hbEFtb3VudFRvU3dhcFVTRE4JAABoAAAAAgAAAAAAAAAnEAUAAAAPZGVjaW1hbFBhcnRVU0RUAQAAAApjb2xsZWN0S2V5AAAAAwAAAAdhZGRyZXNz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AEdGhpcwQAAAAKdG9XaXRoZHJhdwkBAAAAF2dldExpc3RFbGVtZW50T3JEZWZhdWx0AAAAAwkABLUAAAACBQAAAA13aXRoZHJhd25JbmZvAgAAAAFfAAAAAAAAAAACCQABpAAAAAEFAAAABmFtb3VudAMDCQAAZwAAAAIFAAAABmhlaWdodAUAAAALaGVpZ2h0SW5LZXkJAQAAAAhjb250YWlucwAAAAIFAAAADXdpdGhkcmF3bkluZm8CAAAADW5vdF93aXRoZHJhd24HCQAETAAAAAIJAQAAAAtEZWxldGVFbnRyeQAAAAEFAAAAA2tleQkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCAUAAAAGaW52b2tlAAAABmNhbGxlcgkBAAAAE3ZhbHVlT3JFcnJvck1lc3NhZ2UAAAACCQAEtgAAAAEFAAAACnRvV2l0aGRyYXcCAAAAFFdyb25nIHdpdGhkcmF3IGRhdGEhBQAAAAZpZFVTRFQFAAAAA25pbAkAAAIAAAABCQABLAAAAAIJAAEsAAAAAgIAAAAdV2l0aGRyYXdhbCBpcyBwb3NzaWJsZSBhZnRlciAJAAGkAAAAAQUAAAALaGVpZ2h0SW5LZXkCAAAAKyBoZWlnaHQgb3IgeW91IGhhdmUgYWxyZWFkeSB3aXRoZHJhd24gVVNEVC4AAAAAAW2sPg==", "height": 1314026, "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 = "6DUeY9g95UN2MEvKUG2Hd1rHRZvoP3HJqymZn4ZsucPs" | |
5 | + | ||
6 | + | let USDN = "24mHZLZc2bZHqnULTZpWbEEog3SfSVzrd5v4brz9qD7T" | |
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([address, "WITHDRAW", toString(amountToSwapInKey), "HEIGHT", toString(allowToWithdrawHeight)], "_") | |
23 | + | ||
24 | + | ||
25 | + | func collectBalanceKey (address) = makeString([address, "balance"], "_") | |
26 | + | ||
27 | + | ||
28 | + | func collectBalanceKeyWithFee (address) = makeString([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 usdnToUsdtAssetError () = throw("To swap USDN to USDT you need attach payment in USDN") | |
35 | + | ||
36 | + | ||
37 | + | func usdtToUsdnLowLimitError () = throw((("you can swap at least " + toString((minimalAmountToSwapUSDT / decimalPartUSDT))) + " tokens")) | |
38 | + | ||
39 | + | ||
40 | + | func abs (n) = if ((0 > n)) | |
41 | + | then (n * -1) | |
42 | + | else n | |
43 | + | ||
44 | + | ||
45 | + | func getWithoutFeeWithdraw (amount,balanceWithoutFee) = min([amount, balanceWithoutFee]) | |
46 | + | ||
47 | + | ||
48 | + | func getListElementOrDefault (list,index,default) = if ((size(list) > index)) | |
49 | + | then list[index] | |
50 | + | else default | |
51 | + | ||
52 | + | ||
53 | + | func currentWithdrawals (address,amount) = { | |
54 | + | let balanceKey = collectBalanceKey(address) | |
55 | + | let balanceWithFeeKey = collectBalanceKeyWithFee(address) | |
56 | + | let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0) | |
57 | + | let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0) | |
58 | + | let userBalance = (currentClientBalance + currentClientBalanceWithFee) | |
59 | + | if (if ((amount > userBalance)) | |
60 | + | then true | |
61 | + | else (minimalAmountToSwapUSDN > amount)) | |
62 | + | then throw("Swap amount fail, amount is to small or to big.") | |
63 | + | else { | |
64 | + | let toWithdrawWithoutFee = getWithoutFeeWithdraw(amount, currentClientBalance) | |
65 | + | let toWithdrawWithFee = (amount - toWithdrawWithoutFee) | |
66 | + | let fee = ((toWithdrawWithFee / 100) * 2) | |
67 | + | [toWithdrawWithoutFee, toWithdrawWithFee, fee] | |
68 | + | } | |
69 | + | } | |
70 | + | ||
71 | + | ||
72 | + | @Callable(invoke) | |
73 | + | func swapUSDTtoUSDN () = { | |
74 | + | let balanceKey = collectBalanceKeyWithFee(toString(invoke.caller)) | |
75 | + | let payment = value(invoke.payments[0]) | |
76 | + | if ((payment.assetId != idUSDT)) | |
77 | + | then usdtToUsdnAssetError() | |
78 | + | else { | |
79 | + | let amount = payment.amount | |
80 | + | let fee = ((amount / 100) * 2) | |
81 | + | let currentClientBalanceUSDT = valueOrElse(getInteger(this, balanceKey), 0) | |
82 | + | if ((minimalAmountToSwapUSDT > amount)) | |
83 | + | then usdtToUsdnLowLimitError() | |
84 | + | else [IntegerEntry(balanceKey, (currentClientBalanceUSDT + amount)), ScriptTransfer(invoke.caller, (amount - fee), idUSDN)] | |
85 | + | } | |
86 | + | } | |
87 | + | ||
88 | + | ||
89 | + | ||
90 | + | @Callable(invoke) | |
91 | + | func initializationUSDNtoUSDTswap () = { | |
92 | + | let payment = value(invoke.payments[0]) | |
93 | + | let address = toString(invoke.caller) | |
94 | + | if ((payment.assetId != idUSDN)) | |
95 | + | then usdnToUsdtAssetError() | |
96 | + | else { | |
97 | + | let amount = payment.amount | |
98 | + | let balanceKey = collectBalanceKey(address) | |
99 | + | let balanceWithFeeKey = collectBalanceKeyWithFee(address) | |
100 | + | let currentClientBalance = valueOrElse(getInteger(this, balanceKey), 0) | |
101 | + | let currentClientBalanceWithFee = valueOrElse(getInteger(this, balanceWithFeeKey), 0) | |
102 | + | let userBalance = (currentClientBalance + currentClientBalanceWithFee) | |
103 | + | let data = currentWithdrawals(toString(invoke.caller), amount) | |
104 | + | let toWithdrawWithoutFee = valueOrErrorMessage(data[0], "Wrong 'currentWithdrawals' method!") | |
105 | + | let toWithdrawWithFee = valueOrErrorMessage(data[1], "Wrong 'currentWithdrawals' method!") | |
106 | + | let fee = valueOrErrorMessage(data[2], "Wrong 'currentWithdrawals' method!") | |
107 | + | let total = ((toWithdrawWithFee + toWithdrawWithoutFee) - fee) | |
108 | + | let allowToWithDrawHeight = (height + withdrawDelay) | |
109 | + | if (isDefined(getString(this, collectKey(toString(invoke.caller), amount, allowToWithDrawHeight)))) | |
110 | + | then throw("You have already started withdrawal process, wait next block.") | |
111 | + | else [IntegerEntry(balanceKey, (currentClientBalance - toWithdrawWithoutFee)), IntegerEntry(balanceWithFeeKey, (currentClientBalanceWithFee - toWithdrawWithFee)), StringEntry(collectKey(toString(invoke.caller), amount, allowToWithDrawHeight), makeString(["not_withdrawn", toString((amount - fee))], "_"))] | |
112 | + | } | |
113 | + | } | |
114 | + | ||
115 | + | ||
116 | + | ||
117 | + | @Callable(invoke) | |
118 | + | func swapUSDNtoUSDT (amount,heightInKey) = { | |
119 | + | let key = collectKey(toString(invoke.caller), amount, heightInKey) | |
120 | + | let withdrawnInfo = valueOrErrorMessage(getString(this, key), ((("This key doesn't exists " + key) + " at address ") + toString(this))) | |
121 | + | let toWithdraw = getListElementOrDefault(split(withdrawnInfo, "_"), 2, toString(amount)) | |
122 | + | if (if ((height >= heightInKey)) | |
123 | + | then contains(withdrawnInfo, "not_withdrawn") | |
124 | + | else false) | |
125 | + | then [DeleteEntry(key), ScriptTransfer(invoke.caller, valueOrErrorMessage(parseInt(toWithdraw), "Wrong withdraw data!"), idUSDT)] | |
126 | + | else throw((("Withdrawal is possible after " + toString(heightInKey)) + " height or you have already withdrawn USDT.")) | |
127 | + | } | |
128 | + | ||
129 | + |
github/deemru/w8io/169f3d6 20.86 ms ◑