tx · 89GMYyqTFG1YxNE81JHxnRb9KEb53Niv6P4srhuA8Lm8 3MpVFGJWgiGyh5LmE1nxNLsjjtSL3Bgh9NV: -0.01400000 Waves 2019.08.30 17:20 [654107] smart account 3MpVFGJWgiGyh5LmE1nxNLsjjtSL3Bgh9NV > SELF 0.00000000 Waves
{ "type": 13, "id": "89GMYyqTFG1YxNE81JHxnRb9KEb53Niv6P4srhuA8Lm8", "fee": 1400000, "feeAssetId": null, "timestamp": 1567174819746, "version": 1, "sender": "3MpVFGJWgiGyh5LmE1nxNLsjjtSL3Bgh9NV", "senderPublicKey": "854p8BYzrj6yBPRPmfQur3oF1Rjc1AJ548qRp5FT5kDa", "proofs": [ "5ymZG6VzmhDjKu1fq2stXwUVyhmbkUDgeRoSCbKcS7cGeTojpoz3K8ZotSjFXkQqgAbQ2LD1jVN5RhUz4FcXiDCz" ], "script": "base64:AAIDAAAAAAAAAAAAAAAEAAAAAAVvd25lcgEAAAAaAVRFbm0V+EOCq2NTOJsSE2133z0GcAjjvP8AAAAADWFzc2V0SWRUb2tlbkEBAAAAIEMzbeDGHf4oU+zuHGjXevUoBPuFN8LOz9CQD8ug/yo1AAAAAA1hc3NldElkVG9rZW5CAQAAACCqoUHYIr+9N/tCdWkhfZ3SevjX3HPTosOWNfoRj9syOgAAAAAJY29taXNzaW9uAAAAAAAAAAAKAAAABAAAAApjb250ZXh0T2JqAQAAAARmdW5kAAAAAAQAAAAHcGF5bWVudAQAAAAHJG1hdGNoMAgFAAAACmNvbnRleHRPYmoAAAAHcGF5bWVudAMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAPQXR0YWNoZWRQYXltZW50BAAAAAFwBQAAAAckbWF0Y2gwBQAAAAFwCQAAAgAAAAECAAAAFFBheW1lbnQgbm90IGF0dGFjaGVkBAAAAA9hc3NldElkUmVjZWl2ZWQIBQAAAAdwYXltZW50AAAAB2Fzc2V0SWQEAAAAEnRva2VuUmVjZWl2ZUFtb3VudAgFAAAAB3BheW1lbnQ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JRGF0YUVudHJ5AAAAAgIAAAAMYW1vdW50VG9rZW5CAgAAAAl3aXRoZHJhd24FAAAAA25pbAkBAAAAC1RyYW5zZmVyU2V0AAAAAQkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCAUAAAAKY29udGV4dE9iagAAAAZjYWxsZXIFAAAADUJhbGFuY2VUb2tlbkEFAAAADWFzc2V0SWRUb2tlbkEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAACmNvbnRleHRPYmoAAAAGY2FsbGVyBQAAAA1CYWxhbmNlVG9rZW5CBQAAAA1hc3NldElkVG9rZW5CBQAAAANuaWwJAAACAAAAAQIAAAAdWW91IGFyZSBub3QgZXhjaGFuZ2VyJ3Mgb3duZXIAAAABAAAACmNvbnRleHRPYmoBAAAABnZlcmlmeQAAAAAGZGcRyg==", "chainId": 84, "height": 654107, "spentComplexity": 0 } View: original | compacted Prev: 9ns78H1h3uZ9rdJd1AJbnoGEANuwT1uZ26Jq1tiA9yYm Next: 51u5HK2FbdLwMZRWusEJ4j7mQkLirLcBxD3M7zA1Rc2B Diff:
Old | New | Differences | |
---|---|---|---|
75 | 75 | } | |
76 | 76 | let assetIdReceived = payment.assetId | |
77 | 77 | let tokenReceiveAmount = payment.amount | |
78 | + | let count = match getInteger(this, "exchange_count") { | |
79 | + | case i: Int => | |
80 | + | value(getInteger(this, "exchange_count")) | |
81 | + | case _ => | |
82 | + | 0 | |
83 | + | } | |
78 | 84 | if ((assetIdReceived == assetIdTokenB)) | |
79 | 85 | then { | |
80 | 86 | let tokenSendAmount = ((fraction(amountTokenA, tokenReceiveAmount, (tokenReceiveAmount + amountTokenB)) * (100 - comission)) / 100) | |
82 | 88 | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") | |
83 | 89 | else { | |
84 | 90 | let assetIdSent = assetIdTokenA | |
85 | - | ScriptResult(WriteSet([DataEntry("amountTokenA", (amountTokenA - tokenSendAmount)), DataEntry("amountTokenB", (amountTokenB + tokenReceiveAmount))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) | |
91 | + | ScriptResult(WriteSet([DataEntry("amountTokenA", (amountTokenA - tokenSendAmount)), DataEntry("amountTokenB", (amountTokenB + tokenReceiveAmount)), DataEntry("exchange_count", (count + 1))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) | |
86 | 92 | } | |
87 | 93 | } | |
88 | 94 | else if ((assetIdReceived == assetIdTokenA)) | |
92 | 98 | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") | |
93 | 99 | else { | |
94 | 100 | let assetIdSent = assetIdTokenB | |
95 | - | ScriptResult(WriteSet([DataEntry("amountTokenA", (amountTokenA + tokenReceiveAmount)), DataEntry("amountTokenB", (amountTokenB - tokenSendAmount))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) | |
101 | + | ScriptResult(WriteSet([DataEntry("amountTokenA", (amountTokenA + tokenReceiveAmount)), DataEntry("amountTokenB", (amountTokenB - tokenSendAmount)), DataEntry("exchange_count", (count + 1))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) | |
96 | 102 | } | |
97 | 103 | } | |
98 | 104 | else throw("Asset is not allowed") |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let owner = base58'3MvFCghS4jJ7E5QuJfKa4LwCoHJiAcsDQrA' | |
5 | 5 | ||
6 | 6 | let assetIdTokenA = base58'5XKoQDZphxtgtXxm36qhXrYo1F6mRLa9M8QHUDPWQ4mi' | |
7 | 7 | ||
8 | 8 | let assetIdTokenB = base58'CV4vfjkevn3aJ4tKaMn9gPHugYztu6RhDw2ete34SxiV' | |
9 | 9 | ||
10 | 10 | let comission = 10 | |
11 | 11 | ||
12 | 12 | @Callable(contextObj) | |
13 | 13 | func fund () = { | |
14 | 14 | let payment = match contextObj.payment { | |
15 | 15 | case p: AttachedPayment => | |
16 | 16 | p | |
17 | 17 | case _ => | |
18 | 18 | throw("Payment not attached") | |
19 | 19 | } | |
20 | 20 | let assetIdReceived = payment.assetId | |
21 | 21 | let tokenReceiveAmount = payment.amount | |
22 | 22 | if ((assetIdReceived == assetIdTokenA)) | |
23 | 23 | then WriteSet([DataEntry("amountTokenA", tokenReceiveAmount), DataEntry("fundA", true)]) | |
24 | 24 | else if (if ((assetIdReceived == assetIdTokenB)) | |
25 | 25 | then !(isDefined(getBoolean(this, "fundB"))) | |
26 | 26 | else false) | |
27 | 27 | then WriteSet([DataEntry("amountTokenB", tokenReceiveAmount), DataEntry("fundB", true)]) | |
28 | 28 | else throw("already funded or you try to fund with incorrect asset") | |
29 | 29 | } | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | ||
33 | 33 | @Callable(contextObj) | |
34 | 34 | func replenishment () = { | |
35 | 35 | let payment = match contextObj.payment { | |
36 | 36 | case p: AttachedPayment => | |
37 | 37 | p | |
38 | 38 | case _ => | |
39 | 39 | throw("Payment not attached") | |
40 | 40 | } | |
41 | 41 | let assetIdReceived = payment.assetId | |
42 | 42 | let tokenReceiveAmount = payment.amount | |
43 | 43 | if (if ((assetIdReceived == assetIdTokenA)) | |
44 | 44 | then isDefined(getBoolean(this, "fundA")) | |
45 | 45 | else false) | |
46 | 46 | then { | |
47 | 47 | let amountTokenA = getIntegerValue(this, "amountTokenA") | |
48 | 48 | WriteSet([DataEntry("amountTokenA", (amountTokenA + tokenReceiveAmount))]) | |
49 | 49 | } | |
50 | 50 | else if (if ((assetIdReceived == assetIdTokenB)) | |
51 | 51 | then isDefined(getBoolean(this, "fundB")) | |
52 | 52 | else false) | |
53 | 53 | then { | |
54 | 54 | let amountTokenB = getIntegerValue(this, "amountTokenB") | |
55 | 55 | WriteSet([DataEntry("amountTokenA", (amountTokenB + tokenReceiveAmount))]) | |
56 | 56 | } | |
57 | 57 | else throw("there was an error in the replenishment") | |
58 | 58 | } | |
59 | 59 | ||
60 | 60 | ||
61 | 61 | ||
62 | 62 | @Callable(contextObj) | |
63 | 63 | func exchanger (minTokenRecieve) = if (if ((0 > comission)) | |
64 | 64 | then true | |
65 | 65 | else (comission > 100)) | |
66 | 66 | then throw("incorrect comission value") | |
67 | 67 | else { | |
68 | 68 | let amountTokenB = getIntegerValue(this, "amountTokenB") | |
69 | 69 | let amountTokenA = getIntegerValue(this, "amountTokenA") | |
70 | 70 | let payment = match contextObj.payment { | |
71 | 71 | case p: AttachedPayment => | |
72 | 72 | p | |
73 | 73 | case _ => | |
74 | 74 | throw("Payment not attached") | |
75 | 75 | } | |
76 | 76 | let assetIdReceived = payment.assetId | |
77 | 77 | let tokenReceiveAmount = payment.amount | |
78 | + | let count = match getInteger(this, "exchange_count") { | |
79 | + | case i: Int => | |
80 | + | value(getInteger(this, "exchange_count")) | |
81 | + | case _ => | |
82 | + | 0 | |
83 | + | } | |
78 | 84 | if ((assetIdReceived == assetIdTokenB)) | |
79 | 85 | then { | |
80 | 86 | let tokenSendAmount = ((fraction(amountTokenA, tokenReceiveAmount, (tokenReceiveAmount + amountTokenB)) * (100 - comission)) / 100) | |
81 | 87 | if ((minTokenRecieve > tokenSendAmount)) | |
82 | 88 | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") | |
83 | 89 | else { | |
84 | 90 | let assetIdSent = assetIdTokenA | |
85 | - | ScriptResult(WriteSet([DataEntry("amountTokenA", (amountTokenA - tokenSendAmount)), DataEntry("amountTokenB", (amountTokenB + tokenReceiveAmount))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) | |
91 | + | ScriptResult(WriteSet([DataEntry("amountTokenA", (amountTokenA - tokenSendAmount)), DataEntry("amountTokenB", (amountTokenB + tokenReceiveAmount)), DataEntry("exchange_count", (count + 1))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) | |
86 | 92 | } | |
87 | 93 | } | |
88 | 94 | else if ((assetIdReceived == assetIdTokenA)) | |
89 | 95 | then { | |
90 | 96 | let tokenSendAmount = ((fraction(amountTokenB, tokenReceiveAmount, (tokenReceiveAmount + amountTokenA)) * (100 - comission)) / 100) | |
91 | 97 | if ((minTokenRecieve > tokenSendAmount)) | |
92 | 98 | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") | |
93 | 99 | else { | |
94 | 100 | let assetIdSent = assetIdTokenB | |
95 | - | ScriptResult(WriteSet([DataEntry("amountTokenA", (amountTokenA + tokenReceiveAmount)), DataEntry("amountTokenB", (amountTokenB - tokenSendAmount))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) | |
101 | + | ScriptResult(WriteSet([DataEntry("amountTokenA", (amountTokenA + tokenReceiveAmount)), DataEntry("amountTokenB", (amountTokenB - tokenSendAmount)), DataEntry("exchange_count", (count + 1))]), TransferSet([ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)])) | |
96 | 102 | } | |
97 | 103 | } | |
98 | 104 | else throw("Asset is not allowed") | |
99 | 105 | } | |
100 | 106 | ||
101 | 107 | ||
102 | 108 | ||
103 | 109 | @Callable(contextObj) | |
104 | 110 | func withdraw () = { | |
105 | 111 | let BalanceTokenA = assetBalance(this, assetIdTokenA) | |
106 | 112 | let BalanceTokenB = assetBalance(this, assetIdTokenB) | |
107 | 113 | if ((contextObj.caller.bytes == owner)) | |
108 | 114 | then ScriptResult(WriteSet([DataEntry("amountTokenA", "withdrawn"), DataEntry("amountTokenB", "withdrawn")]), TransferSet([ScriptTransfer(contextObj.caller, BalanceTokenA, assetIdTokenA), ScriptTransfer(contextObj.caller, BalanceTokenB, assetIdTokenB)])) | |
109 | 115 | else throw("You are not exchanger's owner") | |
110 | 116 | } | |
111 | 117 | ||
112 | 118 | ||
113 | 119 | @Verifier(contextObj) | |
114 | 120 | func verify () = true | |
115 | 121 |
github/deemru/w8io/026f985 28.24 ms ◑