tx · AkDPVGtjTXBVAg3XDDHEjcyzDUzwZNdyXE3EqCBVGAGB 3NCD7sCFocnQuSL6gaDqWD9Noq9RCwjCup4: -0.01400000 Waves 2020.10.22 21:52 [1232163] smart account 3NCD7sCFocnQuSL6gaDqWD9Noq9RCwjCup4 > SELF 0.00000000 Waves
{ "type": 13, "id": "AkDPVGtjTXBVAg3XDDHEjcyzDUzwZNdyXE3EqCBVGAGB", "fee": 1400000, "feeAssetId": null, "timestamp": 1603392738206, "version": 1, "sender": "3NCD7sCFocnQuSL6gaDqWD9Noq9RCwjCup4", "senderPublicKey": "HuNwRHF9iwGdZDspJ7V7eY2akXjp5fWmTprKuM97CATY", "proofs": [ "KpP3Md1Zw2nf53kxu79PSAxAQteT5FZ2z1Kg3n7q86AMivnrJeeFGyoG89XBMk9X7VoUNyDjbM8KRfLaH5rye7e" ], "script": "base64:AAIEAAAAAAAAAA8IAhIAEgASABIAEgMKAQEAAAAQAAAAAAhJZFRva2VuQQkBAAAAEUBleHRyTmF0aXZlKDEwNTMpAAAAAgUAAAAEdGhpcwIAAAANYXNzZXRJZFRva2VuQQAAAAAISWRUb2tlbkIJAQAAABFAZXh0ck5hdGl2ZSgxMDUzKQAAAAIFAAAABHRoaXMCAAAADWFzc2V0SWRUb2tlbkIAAAAADGFtb3VudFRva2VuQgkBAAAAEUBleHRyTmF0aXZlKDEwNTApAAAAAgUAAAAEdGhpcwIAAAAMYW1vdW50VG9rZW5CAAAAAAxhbW91bnRUb2tlbkEJAQAAABFAZXh0ck5hdGl2ZSgxMDUwKQAAAAIFAAAABHRoaXMCAAAADGFtb3VudFRva2VuQQAAAAARYXNzZXRJZFRva2VuU2hhcmUJAQAAABFAZXh0ck5hdGl2ZSgxMDUyKQAAAAIFAAAABHRoaXMCAAAADnNoYXJlX3Rva2VuX2lkAAAAABB0b2tlblNoYXJlU3VwcGx5CQEAAAARQGV4dHJOYXRpdmUoMTA1MCkAAAACBQAAAAR0aGlzAgAAABJzaGFyZV90b2tlbl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AAAA1hc3NldElkVG9rZW5CCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACAgAAAAxhbW91bnRUb2tlbkEJAABkAAAAAgUAAAAMYW1vdW50VG9rZW5BBQAAABJ0b2tlblJlY2VpdmVBbW91bnQJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAICAAAADGFtb3VudFRva2VuQgkAAGUAAAACBQAAAAxhbW91bnRUb2tlbkIFAAAAD3Rva2VuU2VuZEFtb3VudAkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgIAAAAOZXhjaGFuZ2VfY291bnQJAABkAAAAAgUAAAAFY291bnQAAAAAAAAAAAEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAACmNvbnRleHRPYmoAAAAGY2FsbGVyBQAAAA90b2tlblNlbmRBbW91bnQFAAAAC2Fzc2V0SWRTZW50BQAAAANuaWwJAAACAAAAAQIAAAAUQXNzZXQgaXMgbm90IGFsbG93ZWQAAAAA2SK/xA==", "chainId": 84, "height": 1232163, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3FUGuFpzbYabvBrmuP7MrXCJY6eQydXzPvJdb1BCu4YJ Next: none Diff:
Old | New | Differences | |
---|---|---|---|
5 | 5 | ||
6 | 6 | let IdTokenB = getStringValue(this, "assetIdTokenB") | |
7 | 7 | ||
8 | - | let | |
8 | + | let amountTokenB = getIntegerValue(this, "amountTokenB") | |
9 | 9 | ||
10 | - | let | |
10 | + | let amountTokenA = getIntegerValue(this, "amountTokenA") | |
11 | 11 | ||
12 | - | let | |
12 | + | let assetIdTokenShare = getBinaryValue(this, "share_token_id") | |
13 | 13 | ||
14 | 14 | let tokenShareSupply = getIntegerValue(this, "share_token_supply") | |
15 | 15 | ||
16 | - | let comission = | |
16 | + | let comission = 500 | |
17 | 17 | ||
18 | - | let comissionScaleDelimiter = | |
18 | + | let comissionScaleDelimiter = 1000000 | |
19 | 19 | ||
20 | - | let version = "2.0.0" | |
21 | - | ||
22 | - | let invariant = getIntegerValue(this, "invariant") | |
20 | + | let version = "1.0.0" | |
23 | 21 | ||
24 | 22 | let scaleValue8 = 100000000 | |
25 | - | ||
26 | - | let scaleValue8Digits = 8 | |
27 | - | ||
28 | - | let scaleValue12 = 1000000000000 | |
29 | 23 | ||
30 | 24 | let ratioThresholdMax = 100000000 | |
31 | 25 | ||
32 | 26 | let ratioThresholdMin = 99999000 | |
33 | 27 | ||
34 | - | let alpha = 50 | |
35 | - | ||
36 | - | let alphaDigits = 2 | |
37 | - | ||
38 | - | let betta = 46 | |
39 | - | ||
40 | - | let bettaDigits = 2 | |
41 | - | ||
42 | - | func skeweness (x,y) = ((fraction(scaleValue8, x, y) + fraction(scaleValue8, y, x)) / 2) | |
43 | - | ||
44 | - | ||
45 | - | func invariantCalc (x,y) = { | |
46 | - | let sk = skeweness(x, y) | |
47 | - | (fraction((x + y), pow(sk, scaleValue8Digits, -(alpha), alphaDigits, 8, HALFDOWN), scaleValue8) + (2 * fraction(fraction(pow(x, 0, 5, 1, scaleValue8Digits, HALFDOWN), pow(y, 0, 5, 1, scaleValue8Digits, HALFDOWN), (scaleValue8 * scaleValue8)), pow((sk - ((betta * scaleValue8) / 100)), 0, alpha, alphaDigits, scaleValue8Digits, HALFDOWN), scaleValue12))) | |
48 | - | } | |
49 | - | ||
28 | + | let scaleValue8Digits = 8 | |
50 | 29 | ||
51 | 30 | func assetId (asset) = if ((asset == "WAVES")) | |
52 | 31 | then unit | |
53 | 32 | else fromBase58String(asset) | |
54 | 33 | ||
55 | 34 | ||
56 | - | func calculateHowManySendTokenA (amountToSendEstimated,minTokenRecieveAmount,amountTokenA,amountTokenB,tokenReceiveAmount) = { | |
57 | - | let slippageValue = (scaleValue8 - ((scaleValue8 * 1) / 10000)) | |
58 | - | let invariantEstimatedRatio = fraction(invariant, scaleValue8, invariantCalc((amountTokenA - amountToSendEstimated), (amountTokenB + tokenReceiveAmount))) | |
59 | - | if (if ((invariantEstimatedRatio > slippageValue)) | |
60 | - | then (scaleValue8 > invariantEstimatedRatio) | |
61 | - | else false) | |
62 | - | then ((amountToSendEstimated * (comissionScaleDelimiter - comission)) / comissionScaleDelimiter) | |
63 | - | else throw("price has changed dramatically. err2") | |
64 | - | } | |
65 | - | ||
66 | - | ||
67 | - | func calculateHowManySendTokenB (amountToSendEstimated,minTokenRecieveAmount,amountTokenA,amountTokenB,tokenReceiveAmount) = { | |
68 | - | let slippageValue = (scaleValue8 - ((scaleValue8 * 1) / 10000)) | |
69 | - | let invariantEstimatedRatio = fraction(invariant, scaleValue8, invariantCalc((amountTokenA + tokenReceiveAmount), (amountTokenB - amountToSendEstimated))) | |
70 | - | if (if ((invariantEstimatedRatio > slippageValue)) | |
71 | - | then (scaleValue8 > invariantEstimatedRatio) | |
72 | - | else false) | |
73 | - | then ((amountToSendEstimated * (comissionScaleDelimiter - comission)) / comissionScaleDelimiter) | |
74 | - | else throw("price has changed dramatically. err2") | |
75 | - | } | |
76 | - | ||
77 | - | ||
78 | 35 | let assetIdTokenA = assetId(IdTokenA) | |
79 | 36 | ||
80 | 37 | let assetIdTokenB = assetId(IdTokenB) | |
81 | - | ||
82 | - | let assetIdTokenShare = fromBase58String(IdTokenShare) | |
83 | 38 | ||
84 | 39 | @Callable(contextObj) | |
85 | 40 | func fund () = { | |
128 | 83 | case _ => | |
129 | 84 | throw("Match error") | |
130 | 85 | } | |
131 | - | let invariantCalcualated = invariantCalc(tokenReceiveAmountA, tokenReceiveAmountB) | |
132 | - | [IntegerEntry("amountTokenA", tokenReceiveAmountA), IntegerEntry("amountTokenB", tokenReceiveAmountB), StringEntry("assetIdTokenA", assetIdTokenStringA), StringEntry("assetIdTokenB", assetIdTokenStringB), IntegerEntry("invariant", invariantCalcualated), IntegerEntry("exchange_count", 0), BooleanEntry("status", true), IntegerEntry("comission", comission), IntegerEntry("comissionScaleDelimiter", comissionScaleDelimiter), StringEntry("version", version), Issue(shareTokenName, shareTokenName, shareTokenInitialAmount, digitsInShareToken, true), ScriptTransfer(contextObj.caller, shareTokenInitialAmount, shareTokenAssetId), StringEntry("share_token_id", toBase58String(shareTokenAssetId)), IntegerEntry("share_token_supply", shareTokenInitialAmount)] | |
86 | + | [IntegerEntry("amountTokenA", tokenReceiveAmountA), IntegerEntry("amountTokenB", tokenReceiveAmountB), StringEntry("assetIdTokenA", assetIdTokenStringA), StringEntry("assetIdTokenB", assetIdTokenStringB), IntegerEntry("exchange_count", 0), BooleanEntry("status", true), IntegerEntry("comission", comission), IntegerEntry("comissionScaleDelimiter", comissionScaleDelimiter), StringEntry("version", version), Issue(shareTokenName, shareTokenName, shareTokenInitialAmount, digitsInShareToken, true), ScriptTransfer(contextObj.caller, shareTokenInitialAmount, shareTokenAssetId), BinaryEntry("share_token_id", shareTokenAssetId), IntegerEntry("share_token_supply", shareTokenInitialAmount)] | |
133 | 87 | } | |
134 | 88 | } | |
135 | 89 | ||
136 | 90 | ||
137 | 91 | ||
138 | 92 | @Callable(contextObj) | |
139 | - | func | |
93 | + | func replenishment () = { | |
140 | 94 | let paymentA = value(contextObj.payments[0]) | |
141 | 95 | let paymentB = value(contextObj.payments[1]) | |
142 | 96 | let assetIdReceivedA = paymentA.assetId | |
143 | 97 | let tokenReceiveAmountA = paymentA.amount | |
144 | 98 | let assetIdReceivedB = paymentB.assetId | |
145 | 99 | let tokenReceiveAmountB = paymentB.amount | |
146 | - | let invariantCalcualated = invariantCalc((dAppTokensAmountA + tokenReceiveAmountA), (dAppTokensAmountB + tokenReceiveAmountB)) | |
100 | + | let dAppTokensAmountA = getIntegerValue(this, "amountTokenA") | |
101 | + | let dAppTokensAmountB = getIntegerValue(this, "amountTokenB") | |
147 | 102 | if (if ((assetIdReceivedA != assetIdTokenA)) | |
148 | 103 | then true | |
149 | 104 | else (assetIdReceivedB != assetIdTokenB)) | |
150 | 105 | then throw("incorrect assets") | |
151 | 106 | else { | |
152 | - | let tokenRatio = (fraction(tokenReceiveAmountA, (1000000000000 * | |
153 | - | if (!(if ((tokenRatio > | |
154 | - | then ( | |
107 | + | let tokenRatio = (fraction(tokenReceiveAmountA, (1000000000000 * 100000), dAppTokensAmountA) / fraction(dAppTokensAmountB, 1000000000000, tokenReceiveAmountB)) | |
108 | + | if (!(if ((tokenRatio > 99990)) | |
109 | + | then (100010 > tokenRatio) | |
155 | 110 | else false)) | |
156 | 111 | then throw("incorrect assets amount") | |
157 | 112 | else { | |
158 | 113 | let shareTokenToPayAmount = fraction(tokenReceiveAmountA, tokenShareSupply, dAppTokensAmountA) | |
159 | 114 | if ((shareTokenToPayAmount == 0)) | |
160 | 115 | then throw("you try replansish with very small amount") | |
161 | - | else [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenA", (dAppTokensAmountA + tokenReceiveAmountA)), IntegerEntry("amountTokenB", (dAppTokensAmountB + tokenReceiveAmountB)) | |
116 | + | else [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenA", (dAppTokensAmountA + tokenReceiveAmountA)), IntegerEntry("amountTokenB", (dAppTokensAmountB + tokenReceiveAmountB))] | |
162 | 117 | } | |
163 | 118 | } | |
164 | 119 | } | |
166 | 121 | ||
167 | 122 | ||
168 | 123 | @Callable(contextObj) | |
169 | - | func replanishmentWithOneToken ( | |
124 | + | func replanishmentWithOneToken () = { | |
170 | 125 | let payment = value(contextObj.payments[0]) | |
171 | 126 | let assetIdReceived = payment.assetId | |
172 | 127 | let tokenReceiveAmount = payment.amount | |
173 | 128 | if ((assetIdReceived == assetIdTokenA)) | |
174 | 129 | then { | |
175 | - | let newAmountTokenA = (dAppTokensAmountA + tokenReceiveAmount) | |
176 | - | let newInvariant = invariantCalc(newAmountTokenA, dAppTokensAmountB) | |
177 | - | let priceAtoBwith8digits = fraction(newAmountTokenA, scaleValue8, dAppTokensAmountB) | |
178 | - | let isCorrectPriceRation = fraction(tokenBamountWithOldInvariantNewPrice, priceAtoBwith8digits, tokenAamountWithOldInvariantNewPrice) | |
179 | - | if (if ((isCorrectPriceRation > ratioThresholdMax)) | |
180 | - | then true | |
181 | - | else (ratioThresholdMin > isCorrectPriceRation)) | |
182 | - | then throw("incorrect function args: price") | |
183 | - | else { | |
184 | - | let calculatedInvariantWithNewPrice = invariantCalc(tokenAamountWithOldInvariantNewPrice, tokenBamountWithOldInvariantNewPrice) | |
185 | - | let isCorrectInvariantRation = fraction(calculatedInvariantWithNewPrice, scaleValue8, invariant) | |
186 | - | if (if ((isCorrectInvariantRation > ratioThresholdMax)) | |
187 | - | then true | |
188 | - | else (ratioThresholdMin > isCorrectInvariantRation)) | |
189 | - | then throw("incorrect function args: invariant") | |
190 | - | else { | |
191 | - | let newTokenShareSupply = fraction(tokenBamountWithOldInvariantNewPrice, tokenShareSupply, dAppTokensAmountB) | |
192 | - | let shareTokenToPayAmount = (newTokenShareSupply - tokenShareSupply) | |
193 | - | [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenA", newAmountTokenA), IntegerEntry("invariant", newInvariant)] | |
194 | - | } | |
195 | - | } | |
130 | + | let newAmountTokenA = (amountTokenA + tokenReceiveAmount) | |
131 | + | let priceAtoBwith8digits = fraction(newAmountTokenA, scaleValue8, amountTokenB) | |
132 | + | let tokenAmountBNewPriceOldInvariant = pow(fraction(amountTokenA, amountTokenB, priceAtoBwith8digits), 0, 5, 1, 0, HALFDOWN) | |
133 | + | let newTokenShareSupply = fraction(amountTokenB, tokenShareSupply, tokenAmountBNewPriceOldInvariant) | |
134 | + | let shareTokenToPayAmount = (newTokenShareSupply - tokenShareSupply) | |
135 | + | [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenA", newAmountTokenA)] | |
196 | 136 | } | |
197 | 137 | else if ((assetIdReceived == assetIdTokenB)) | |
198 | 138 | then { | |
199 | - | let newAmountTokenB = (dAppTokensAmountB + tokenReceiveAmount) | |
200 | - | let newInvariant = invariantCalc(dAppTokensAmountA, newAmountTokenB) | |
201 | - | let priceAtoBwith8digits = fraction(dAppTokensAmountA, scaleValue8, newAmountTokenB) | |
202 | - | let isCorrectPriceRation = fraction(tokenBamountWithOldInvariantNewPrice, priceAtoBwith8digits, tokenAamountWithOldInvariantNewPrice) | |
203 | - | if (if ((isCorrectPriceRation > ratioThresholdMax)) | |
204 | - | then true | |
205 | - | else (ratioThresholdMin > isCorrectPriceRation)) | |
206 | - | then throw("incorrect function args: price") | |
207 | - | else { | |
208 | - | let calculatedInvariantWithNewPrice = invariantCalc(tokenAamountWithOldInvariantNewPrice, tokenBamountWithOldInvariantNewPrice) | |
209 | - | let isCorrectInvariantRation = fraction(calculatedInvariantWithNewPrice, scaleValue8, invariant) | |
210 | - | if (if ((isCorrectInvariantRation > ratioThresholdMax)) | |
211 | - | then true | |
212 | - | else (ratioThresholdMin > isCorrectInvariantRation)) | |
213 | - | then throw("incorrect function args: invariant") | |
214 | - | else { | |
215 | - | let newTokenShareSupply = fraction(tokenBamountWithOldInvariantNewPrice, tokenShareSupply, dAppTokensAmountB) | |
216 | - | let shareTokenToPayAmount = (newTokenShareSupply - tokenShareSupply) | |
217 | - | [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenB", newAmountTokenB), IntegerEntry("invariant", newInvariant)] | |
218 | - | } | |
219 | - | } | |
139 | + | let newAmountTokenB = (amountTokenB + tokenReceiveAmount) | |
140 | + | let priceAtoBwith8digits = fraction(amountTokenA, scaleValue8, newAmountTokenB) | |
141 | + | let tokenAmountBNewPriceOldInvariant = pow(fraction(amountTokenA, amountTokenB, priceAtoBwith8digits), 0, 5, 1, 0, HALFDOWN) | |
142 | + | let newTokenShareSupply = fraction(amountTokenB, tokenShareSupply, tokenAmountBNewPriceOldInvariant) | |
143 | + | let shareTokenToPayAmount = (newTokenShareSupply - tokenShareSupply) | |
144 | + | [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenB", newAmountTokenB)] | |
220 | 145 | } | |
221 | 146 | else throw("incorrect assets in payment") | |
222 | 147 | } | |
225 | 150 | ||
226 | 151 | @Callable(contextObj) | |
227 | 152 | func withdraw () = { | |
153 | + | let dAppTokensAmountA = getIntegerValue(this, "amountTokenA") | |
154 | + | let dAppTokensAmountB = getIntegerValue(this, "amountTokenB") | |
228 | 155 | let payment = value(contextObj.payments[0]) | |
229 | 156 | let assetIdReceived = payment.assetId | |
230 | 157 | let tokenReceiveAmount = payment.amount | |
233 | 160 | else { | |
234 | 161 | let tokensToPayA = fraction(tokenReceiveAmount, dAppTokensAmountA, tokenShareSupply) | |
235 | 162 | let tokensToPayB = fraction(tokenReceiveAmount, dAppTokensAmountB, tokenShareSupply) | |
236 | - | let invariantCalcualated = invariantCalc((dAppTokensAmountA - tokensToPayA), (dAppTokensAmountB - tokensToPayB)) | |
237 | - | [IntegerEntry("amountTokenA", (dAppTokensAmountA - tokensToPayA)), IntegerEntry("amountTokenB", (dAppTokensAmountB - tokensToPayB)), IntegerEntry("share_token_supply", (tokenShareSupply - tokenReceiveAmount)), ScriptTransfer(contextObj.caller, tokensToPayA, assetIdTokenA), ScriptTransfer(contextObj.caller, tokensToPayB, assetIdTokenB), Burn(assetIdTokenShare, tokenReceiveAmount), IntegerEntry("invariant", invariantCalcualated)] | |
163 | + | [ScriptTransfer(contextObj.caller, tokensToPayA, assetIdTokenA), ScriptTransfer(contextObj.caller, tokensToPayB, assetIdTokenB), IntegerEntry("amountTokenA", (dAppTokensAmountA - tokensToPayA)), IntegerEntry("amountTokenB", (dAppTokensAmountB - tokensToPayB)), IntegerEntry("share_token_supply", (tokenShareSupply - tokenReceiveAmount)), Burn(assetIdTokenShare, tokenReceiveAmount)] | |
238 | 164 | } | |
239 | 165 | } | |
240 | 166 | ||
241 | 167 | ||
242 | 168 | ||
243 | 169 | @Callable(contextObj) | |
244 | - | func exchanger (amountToSendEstimated,minTokenRecieveAmount) = { | |
245 | - | let amountTokenB = getIntegerValue(this, "amountTokenB") | |
246 | - | let amountTokenA = getIntegerValue(this, "amountTokenA") | |
170 | + | func exchanger (minTokenRecieve) = { | |
247 | 171 | let payment = value(contextObj.payments[0]) | |
248 | 172 | let assetIdReceived = payment.assetId | |
249 | 173 | let tokenReceiveAmount = payment.amount | |
250 | - | let count = match getInteger(this, "exchange_count") { | |
251 | - | case i: Int => | |
252 | - | (value(getInteger(this, "exchange_count")) + i) | |
253 | - | case _ => | |
254 | - | 0 | |
255 | - | } | |
174 | + | let count = value(getInteger(this, "exchange_count")) | |
256 | 175 | if ((assetIdReceived == assetIdTokenB)) | |
257 | 176 | then { | |
258 | - | let tokenSendAmount = calculateHowManySendTokenA(amountToSendEstimated, minTokenRecieveAmount, amountTokenA, amountTokenB, tokenReceiveAmount) | |
259 | - | let assetIdSent = assetIdTokenA | |
260 | - | [IntegerEntry("amountTokenA", (amountTokenA - tokenSendAmount)), IntegerEntry("amountTokenB", (amountTokenB + tokenReceiveAmount)), IntegerEntry("exchange_count", (count + 1)), IntegerEntry("invariant", invariantCalc((amountTokenA - tokenSendAmount), (amountTokenB + tokenReceiveAmount))), ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)] | |
177 | + | let tokenSendAmount = ((fraction(amountTokenA, tokenReceiveAmount, (tokenReceiveAmount + amountTokenB)) * (comissionScaleDelimiter - comission)) / comissionScaleDelimiter) | |
178 | + | if ((minTokenRecieve > tokenSendAmount)) | |
179 | + | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") | |
180 | + | else { | |
181 | + | let assetIdSent = assetIdTokenA | |
182 | + | [IntegerEntry("amountTokenA", (amountTokenA - tokenSendAmount)), IntegerEntry("amountTokenB", (amountTokenB + tokenReceiveAmount)), IntegerEntry("exchange_count", (count + 1)), ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)] | |
183 | + | } | |
261 | 184 | } | |
262 | 185 | else if ((assetIdReceived == assetIdTokenA)) | |
263 | 186 | then { | |
264 | - | let tokenSendAmount = calculateHowManySendTokenB(amountToSendEstimated, minTokenRecieveAmount, amountTokenA, amountTokenB, tokenReceiveAmount) | |
265 | - | let assetIdSent = assetIdTokenB | |
266 | - | [IntegerEntry("amountTokenA", (amountTokenA + tokenReceiveAmount)), IntegerEntry("amountTokenB", (amountTokenB - tokenSendAmount)), IntegerEntry("exchange_count", (count + 1)), IntegerEntry("invariant", invariantCalc((amountTokenA + tokenReceiveAmount), (amountTokenB - tokenSendAmount))), ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)] | |
187 | + | let tokenSendAmount = ((fraction(amountTokenB, tokenReceiveAmount, (tokenReceiveAmount + amountTokenA)) * (comissionScaleDelimiter - comission)) / comissionScaleDelimiter) | |
188 | + | if ((minTokenRecieve > tokenSendAmount)) | |
189 | + | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") | |
190 | + | else { | |
191 | + | let assetIdSent = assetIdTokenB | |
192 | + | [IntegerEntry("amountTokenA", (amountTokenA + tokenReceiveAmount)), IntegerEntry("amountTokenB", (amountTokenB - tokenSendAmount)), IntegerEntry("exchange_count", (count + 1)), ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)] | |
193 | + | } | |
267 | 194 | } | |
268 | 195 | else throw("Asset is not allowed") | |
269 | 196 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let IdTokenA = getStringValue(this, "assetIdTokenA") | |
5 | 5 | ||
6 | 6 | let IdTokenB = getStringValue(this, "assetIdTokenB") | |
7 | 7 | ||
8 | - | let | |
8 | + | let amountTokenB = getIntegerValue(this, "amountTokenB") | |
9 | 9 | ||
10 | - | let | |
10 | + | let amountTokenA = getIntegerValue(this, "amountTokenA") | |
11 | 11 | ||
12 | - | let | |
12 | + | let assetIdTokenShare = getBinaryValue(this, "share_token_id") | |
13 | 13 | ||
14 | 14 | let tokenShareSupply = getIntegerValue(this, "share_token_supply") | |
15 | 15 | ||
16 | - | let comission = | |
16 | + | let comission = 500 | |
17 | 17 | ||
18 | - | let comissionScaleDelimiter = | |
18 | + | let comissionScaleDelimiter = 1000000 | |
19 | 19 | ||
20 | - | let version = "2.0.0" | |
21 | - | ||
22 | - | let invariant = getIntegerValue(this, "invariant") | |
20 | + | let version = "1.0.0" | |
23 | 21 | ||
24 | 22 | let scaleValue8 = 100000000 | |
25 | - | ||
26 | - | let scaleValue8Digits = 8 | |
27 | - | ||
28 | - | let scaleValue12 = 1000000000000 | |
29 | 23 | ||
30 | 24 | let ratioThresholdMax = 100000000 | |
31 | 25 | ||
32 | 26 | let ratioThresholdMin = 99999000 | |
33 | 27 | ||
34 | - | let alpha = 50 | |
35 | - | ||
36 | - | let alphaDigits = 2 | |
37 | - | ||
38 | - | let betta = 46 | |
39 | - | ||
40 | - | let bettaDigits = 2 | |
41 | - | ||
42 | - | func skeweness (x,y) = ((fraction(scaleValue8, x, y) + fraction(scaleValue8, y, x)) / 2) | |
43 | - | ||
44 | - | ||
45 | - | func invariantCalc (x,y) = { | |
46 | - | let sk = skeweness(x, y) | |
47 | - | (fraction((x + y), pow(sk, scaleValue8Digits, -(alpha), alphaDigits, 8, HALFDOWN), scaleValue8) + (2 * fraction(fraction(pow(x, 0, 5, 1, scaleValue8Digits, HALFDOWN), pow(y, 0, 5, 1, scaleValue8Digits, HALFDOWN), (scaleValue8 * scaleValue8)), pow((sk - ((betta * scaleValue8) / 100)), 0, alpha, alphaDigits, scaleValue8Digits, HALFDOWN), scaleValue12))) | |
48 | - | } | |
49 | - | ||
28 | + | let scaleValue8Digits = 8 | |
50 | 29 | ||
51 | 30 | func assetId (asset) = if ((asset == "WAVES")) | |
52 | 31 | then unit | |
53 | 32 | else fromBase58String(asset) | |
54 | 33 | ||
55 | 34 | ||
56 | - | func calculateHowManySendTokenA (amountToSendEstimated,minTokenRecieveAmount,amountTokenA,amountTokenB,tokenReceiveAmount) = { | |
57 | - | let slippageValue = (scaleValue8 - ((scaleValue8 * 1) / 10000)) | |
58 | - | let invariantEstimatedRatio = fraction(invariant, scaleValue8, invariantCalc((amountTokenA - amountToSendEstimated), (amountTokenB + tokenReceiveAmount))) | |
59 | - | if (if ((invariantEstimatedRatio > slippageValue)) | |
60 | - | then (scaleValue8 > invariantEstimatedRatio) | |
61 | - | else false) | |
62 | - | then ((amountToSendEstimated * (comissionScaleDelimiter - comission)) / comissionScaleDelimiter) | |
63 | - | else throw("price has changed dramatically. err2") | |
64 | - | } | |
65 | - | ||
66 | - | ||
67 | - | func calculateHowManySendTokenB (amountToSendEstimated,minTokenRecieveAmount,amountTokenA,amountTokenB,tokenReceiveAmount) = { | |
68 | - | let slippageValue = (scaleValue8 - ((scaleValue8 * 1) / 10000)) | |
69 | - | let invariantEstimatedRatio = fraction(invariant, scaleValue8, invariantCalc((amountTokenA + tokenReceiveAmount), (amountTokenB - amountToSendEstimated))) | |
70 | - | if (if ((invariantEstimatedRatio > slippageValue)) | |
71 | - | then (scaleValue8 > invariantEstimatedRatio) | |
72 | - | else false) | |
73 | - | then ((amountToSendEstimated * (comissionScaleDelimiter - comission)) / comissionScaleDelimiter) | |
74 | - | else throw("price has changed dramatically. err2") | |
75 | - | } | |
76 | - | ||
77 | - | ||
78 | 35 | let assetIdTokenA = assetId(IdTokenA) | |
79 | 36 | ||
80 | 37 | let assetIdTokenB = assetId(IdTokenB) | |
81 | - | ||
82 | - | let assetIdTokenShare = fromBase58String(IdTokenShare) | |
83 | 38 | ||
84 | 39 | @Callable(contextObj) | |
85 | 40 | func fund () = { | |
86 | 41 | let paymentA = value(contextObj.payments[0]) | |
87 | 42 | let paymentB = value(contextObj.payments[1]) | |
88 | 43 | let assetIdReceivedA = paymentA.assetId | |
89 | 44 | let tokenReceiveAmountA = paymentA.amount | |
90 | 45 | let assetIdReceivedB = paymentB.assetId | |
91 | 46 | let tokenReceiveAmountB = paymentB.amount | |
92 | 47 | let digitTokenA = match assetIdReceivedA { | |
93 | 48 | case p: Unit => | |
94 | 49 | 8 | |
95 | 50 | case p: ByteVector => | |
96 | 51 | value(assetInfo(p)).decimals | |
97 | 52 | case _ => | |
98 | 53 | throw("Match error") | |
99 | 54 | } | |
100 | 55 | let digitTokenB = match assetIdReceivedB { | |
101 | 56 | case p: Unit => | |
102 | 57 | 8 | |
103 | 58 | case p: ByteVector => | |
104 | 59 | value(assetInfo(p)).decimals | |
105 | 60 | case _ => | |
106 | 61 | throw("Match error") | |
107 | 62 | } | |
108 | 63 | if (isDefined(getBoolean(this, "status"))) | |
109 | 64 | then throw("already active") | |
110 | 65 | else { | |
111 | 66 | let shareTokenName = ("ShareT_" + takeRight(toString(this), 5)) | |
112 | 67 | let digitsInShareToken = ((digitTokenA + digitTokenB) / 2) | |
113 | 68 | let shareTokenInitialAmount = fraction(pow(tokenReceiveAmountA, digitTokenA, 5, 1, digitTokenA, HALFDOWN), pow(tokenReceiveAmountB, digitTokenB, 5, 1, digitTokenB, HALFDOWN), pow(10, 0, digitsInShareToken, 0, 0, HALFDOWN)) | |
114 | 69 | let shareTokenAssetId = calculateAssetId(Issue(shareTokenName, shareTokenName, shareTokenInitialAmount, digitsInShareToken, true)) | |
115 | 70 | let assetIdTokenStringA = match assetIdReceivedA { | |
116 | 71 | case t: Unit => | |
117 | 72 | "WAVES" | |
118 | 73 | case t: ByteVector => | |
119 | 74 | toBase58String(value(assetIdReceivedA)) | |
120 | 75 | case _ => | |
121 | 76 | throw("Match error") | |
122 | 77 | } | |
123 | 78 | let assetIdTokenStringB = match assetIdReceivedB { | |
124 | 79 | case t: Unit => | |
125 | 80 | "WAVES" | |
126 | 81 | case t: ByteVector => | |
127 | 82 | toBase58String(value(assetIdReceivedB)) | |
128 | 83 | case _ => | |
129 | 84 | throw("Match error") | |
130 | 85 | } | |
131 | - | let invariantCalcualated = invariantCalc(tokenReceiveAmountA, tokenReceiveAmountB) | |
132 | - | [IntegerEntry("amountTokenA", tokenReceiveAmountA), IntegerEntry("amountTokenB", tokenReceiveAmountB), StringEntry("assetIdTokenA", assetIdTokenStringA), StringEntry("assetIdTokenB", assetIdTokenStringB), IntegerEntry("invariant", invariantCalcualated), IntegerEntry("exchange_count", 0), BooleanEntry("status", true), IntegerEntry("comission", comission), IntegerEntry("comissionScaleDelimiter", comissionScaleDelimiter), StringEntry("version", version), Issue(shareTokenName, shareTokenName, shareTokenInitialAmount, digitsInShareToken, true), ScriptTransfer(contextObj.caller, shareTokenInitialAmount, shareTokenAssetId), StringEntry("share_token_id", toBase58String(shareTokenAssetId)), IntegerEntry("share_token_supply", shareTokenInitialAmount)] | |
86 | + | [IntegerEntry("amountTokenA", tokenReceiveAmountA), IntegerEntry("amountTokenB", tokenReceiveAmountB), StringEntry("assetIdTokenA", assetIdTokenStringA), StringEntry("assetIdTokenB", assetIdTokenStringB), IntegerEntry("exchange_count", 0), BooleanEntry("status", true), IntegerEntry("comission", comission), IntegerEntry("comissionScaleDelimiter", comissionScaleDelimiter), StringEntry("version", version), Issue(shareTokenName, shareTokenName, shareTokenInitialAmount, digitsInShareToken, true), ScriptTransfer(contextObj.caller, shareTokenInitialAmount, shareTokenAssetId), BinaryEntry("share_token_id", shareTokenAssetId), IntegerEntry("share_token_supply", shareTokenInitialAmount)] | |
133 | 87 | } | |
134 | 88 | } | |
135 | 89 | ||
136 | 90 | ||
137 | 91 | ||
138 | 92 | @Callable(contextObj) | |
139 | - | func | |
93 | + | func replenishment () = { | |
140 | 94 | let paymentA = value(contextObj.payments[0]) | |
141 | 95 | let paymentB = value(contextObj.payments[1]) | |
142 | 96 | let assetIdReceivedA = paymentA.assetId | |
143 | 97 | let tokenReceiveAmountA = paymentA.amount | |
144 | 98 | let assetIdReceivedB = paymentB.assetId | |
145 | 99 | let tokenReceiveAmountB = paymentB.amount | |
146 | - | let invariantCalcualated = invariantCalc((dAppTokensAmountA + tokenReceiveAmountA), (dAppTokensAmountB + tokenReceiveAmountB)) | |
100 | + | let dAppTokensAmountA = getIntegerValue(this, "amountTokenA") | |
101 | + | let dAppTokensAmountB = getIntegerValue(this, "amountTokenB") | |
147 | 102 | if (if ((assetIdReceivedA != assetIdTokenA)) | |
148 | 103 | then true | |
149 | 104 | else (assetIdReceivedB != assetIdTokenB)) | |
150 | 105 | then throw("incorrect assets") | |
151 | 106 | else { | |
152 | - | let tokenRatio = (fraction(tokenReceiveAmountA, (1000000000000 * | |
153 | - | if (!(if ((tokenRatio > | |
154 | - | then ( | |
107 | + | let tokenRatio = (fraction(tokenReceiveAmountA, (1000000000000 * 100000), dAppTokensAmountA) / fraction(dAppTokensAmountB, 1000000000000, tokenReceiveAmountB)) | |
108 | + | if (!(if ((tokenRatio > 99990)) | |
109 | + | then (100010 > tokenRatio) | |
155 | 110 | else false)) | |
156 | 111 | then throw("incorrect assets amount") | |
157 | 112 | else { | |
158 | 113 | let shareTokenToPayAmount = fraction(tokenReceiveAmountA, tokenShareSupply, dAppTokensAmountA) | |
159 | 114 | if ((shareTokenToPayAmount == 0)) | |
160 | 115 | then throw("you try replansish with very small amount") | |
161 | - | else [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenA", (dAppTokensAmountA + tokenReceiveAmountA)), IntegerEntry("amountTokenB", (dAppTokensAmountB + tokenReceiveAmountB)) | |
116 | + | else [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenA", (dAppTokensAmountA + tokenReceiveAmountA)), IntegerEntry("amountTokenB", (dAppTokensAmountB + tokenReceiveAmountB))] | |
162 | 117 | } | |
163 | 118 | } | |
164 | 119 | } | |
165 | 120 | ||
166 | 121 | ||
167 | 122 | ||
168 | 123 | @Callable(contextObj) | |
169 | - | func replanishmentWithOneToken ( | |
124 | + | func replanishmentWithOneToken () = { | |
170 | 125 | let payment = value(contextObj.payments[0]) | |
171 | 126 | let assetIdReceived = payment.assetId | |
172 | 127 | let tokenReceiveAmount = payment.amount | |
173 | 128 | if ((assetIdReceived == assetIdTokenA)) | |
174 | 129 | then { | |
175 | - | let newAmountTokenA = (dAppTokensAmountA + tokenReceiveAmount) | |
176 | - | let newInvariant = invariantCalc(newAmountTokenA, dAppTokensAmountB) | |
177 | - | let priceAtoBwith8digits = fraction(newAmountTokenA, scaleValue8, dAppTokensAmountB) | |
178 | - | let isCorrectPriceRation = fraction(tokenBamountWithOldInvariantNewPrice, priceAtoBwith8digits, tokenAamountWithOldInvariantNewPrice) | |
179 | - | if (if ((isCorrectPriceRation > ratioThresholdMax)) | |
180 | - | then true | |
181 | - | else (ratioThresholdMin > isCorrectPriceRation)) | |
182 | - | then throw("incorrect function args: price") | |
183 | - | else { | |
184 | - | let calculatedInvariantWithNewPrice = invariantCalc(tokenAamountWithOldInvariantNewPrice, tokenBamountWithOldInvariantNewPrice) | |
185 | - | let isCorrectInvariantRation = fraction(calculatedInvariantWithNewPrice, scaleValue8, invariant) | |
186 | - | if (if ((isCorrectInvariantRation > ratioThresholdMax)) | |
187 | - | then true | |
188 | - | else (ratioThresholdMin > isCorrectInvariantRation)) | |
189 | - | then throw("incorrect function args: invariant") | |
190 | - | else { | |
191 | - | let newTokenShareSupply = fraction(tokenBamountWithOldInvariantNewPrice, tokenShareSupply, dAppTokensAmountB) | |
192 | - | let shareTokenToPayAmount = (newTokenShareSupply - tokenShareSupply) | |
193 | - | [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenA", newAmountTokenA), IntegerEntry("invariant", newInvariant)] | |
194 | - | } | |
195 | - | } | |
130 | + | let newAmountTokenA = (amountTokenA + tokenReceiveAmount) | |
131 | + | let priceAtoBwith8digits = fraction(newAmountTokenA, scaleValue8, amountTokenB) | |
132 | + | let tokenAmountBNewPriceOldInvariant = pow(fraction(amountTokenA, amountTokenB, priceAtoBwith8digits), 0, 5, 1, 0, HALFDOWN) | |
133 | + | let newTokenShareSupply = fraction(amountTokenB, tokenShareSupply, tokenAmountBNewPriceOldInvariant) | |
134 | + | let shareTokenToPayAmount = (newTokenShareSupply - tokenShareSupply) | |
135 | + | [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenA", newAmountTokenA)] | |
196 | 136 | } | |
197 | 137 | else if ((assetIdReceived == assetIdTokenB)) | |
198 | 138 | then { | |
199 | - | let newAmountTokenB = (dAppTokensAmountB + tokenReceiveAmount) | |
200 | - | let newInvariant = invariantCalc(dAppTokensAmountA, newAmountTokenB) | |
201 | - | let priceAtoBwith8digits = fraction(dAppTokensAmountA, scaleValue8, newAmountTokenB) | |
202 | - | let isCorrectPriceRation = fraction(tokenBamountWithOldInvariantNewPrice, priceAtoBwith8digits, tokenAamountWithOldInvariantNewPrice) | |
203 | - | if (if ((isCorrectPriceRation > ratioThresholdMax)) | |
204 | - | then true | |
205 | - | else (ratioThresholdMin > isCorrectPriceRation)) | |
206 | - | then throw("incorrect function args: price") | |
207 | - | else { | |
208 | - | let calculatedInvariantWithNewPrice = invariantCalc(tokenAamountWithOldInvariantNewPrice, tokenBamountWithOldInvariantNewPrice) | |
209 | - | let isCorrectInvariantRation = fraction(calculatedInvariantWithNewPrice, scaleValue8, invariant) | |
210 | - | if (if ((isCorrectInvariantRation > ratioThresholdMax)) | |
211 | - | then true | |
212 | - | else (ratioThresholdMin > isCorrectInvariantRation)) | |
213 | - | then throw("incorrect function args: invariant") | |
214 | - | else { | |
215 | - | let newTokenShareSupply = fraction(tokenBamountWithOldInvariantNewPrice, tokenShareSupply, dAppTokensAmountB) | |
216 | - | let shareTokenToPayAmount = (newTokenShareSupply - tokenShareSupply) | |
217 | - | [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenB", newAmountTokenB), IntegerEntry("invariant", newInvariant)] | |
218 | - | } | |
219 | - | } | |
139 | + | let newAmountTokenB = (amountTokenB + tokenReceiveAmount) | |
140 | + | let priceAtoBwith8digits = fraction(amountTokenA, scaleValue8, newAmountTokenB) | |
141 | + | let tokenAmountBNewPriceOldInvariant = pow(fraction(amountTokenA, amountTokenB, priceAtoBwith8digits), 0, 5, 1, 0, HALFDOWN) | |
142 | + | let newTokenShareSupply = fraction(amountTokenB, tokenShareSupply, tokenAmountBNewPriceOldInvariant) | |
143 | + | let shareTokenToPayAmount = (newTokenShareSupply - tokenShareSupply) | |
144 | + | [Reissue(assetIdTokenShare, shareTokenToPayAmount, true), ScriptTransfer(contextObj.caller, shareTokenToPayAmount, assetIdTokenShare), IntegerEntry("share_token_supply", (tokenShareSupply + shareTokenToPayAmount)), IntegerEntry("amountTokenB", newAmountTokenB)] | |
220 | 145 | } | |
221 | 146 | else throw("incorrect assets in payment") | |
222 | 147 | } | |
223 | 148 | ||
224 | 149 | ||
225 | 150 | ||
226 | 151 | @Callable(contextObj) | |
227 | 152 | func withdraw () = { | |
153 | + | let dAppTokensAmountA = getIntegerValue(this, "amountTokenA") | |
154 | + | let dAppTokensAmountB = getIntegerValue(this, "amountTokenB") | |
228 | 155 | let payment = value(contextObj.payments[0]) | |
229 | 156 | let assetIdReceived = payment.assetId | |
230 | 157 | let tokenReceiveAmount = payment.amount | |
231 | 158 | if ((assetIdTokenShare != assetIdReceived)) | |
232 | 159 | then throw(("you need to attach share token for this dApp " + toBase58String(assetIdTokenShare))) | |
233 | 160 | else { | |
234 | 161 | let tokensToPayA = fraction(tokenReceiveAmount, dAppTokensAmountA, tokenShareSupply) | |
235 | 162 | let tokensToPayB = fraction(tokenReceiveAmount, dAppTokensAmountB, tokenShareSupply) | |
236 | - | let invariantCalcualated = invariantCalc((dAppTokensAmountA - tokensToPayA), (dAppTokensAmountB - tokensToPayB)) | |
237 | - | [IntegerEntry("amountTokenA", (dAppTokensAmountA - tokensToPayA)), IntegerEntry("amountTokenB", (dAppTokensAmountB - tokensToPayB)), IntegerEntry("share_token_supply", (tokenShareSupply - tokenReceiveAmount)), ScriptTransfer(contextObj.caller, tokensToPayA, assetIdTokenA), ScriptTransfer(contextObj.caller, tokensToPayB, assetIdTokenB), Burn(assetIdTokenShare, tokenReceiveAmount), IntegerEntry("invariant", invariantCalcualated)] | |
163 | + | [ScriptTransfer(contextObj.caller, tokensToPayA, assetIdTokenA), ScriptTransfer(contextObj.caller, tokensToPayB, assetIdTokenB), IntegerEntry("amountTokenA", (dAppTokensAmountA - tokensToPayA)), IntegerEntry("amountTokenB", (dAppTokensAmountB - tokensToPayB)), IntegerEntry("share_token_supply", (tokenShareSupply - tokenReceiveAmount)), Burn(assetIdTokenShare, tokenReceiveAmount)] | |
238 | 164 | } | |
239 | 165 | } | |
240 | 166 | ||
241 | 167 | ||
242 | 168 | ||
243 | 169 | @Callable(contextObj) | |
244 | - | func exchanger (amountToSendEstimated,minTokenRecieveAmount) = { | |
245 | - | let amountTokenB = getIntegerValue(this, "amountTokenB") | |
246 | - | let amountTokenA = getIntegerValue(this, "amountTokenA") | |
170 | + | func exchanger (minTokenRecieve) = { | |
247 | 171 | let payment = value(contextObj.payments[0]) | |
248 | 172 | let assetIdReceived = payment.assetId | |
249 | 173 | let tokenReceiveAmount = payment.amount | |
250 | - | let count = match getInteger(this, "exchange_count") { | |
251 | - | case i: Int => | |
252 | - | (value(getInteger(this, "exchange_count")) + i) | |
253 | - | case _ => | |
254 | - | 0 | |
255 | - | } | |
174 | + | let count = value(getInteger(this, "exchange_count")) | |
256 | 175 | if ((assetIdReceived == assetIdTokenB)) | |
257 | 176 | then { | |
258 | - | let tokenSendAmount = calculateHowManySendTokenA(amountToSendEstimated, minTokenRecieveAmount, amountTokenA, amountTokenB, tokenReceiveAmount) | |
259 | - | let assetIdSent = assetIdTokenA | |
260 | - | [IntegerEntry("amountTokenA", (amountTokenA - tokenSendAmount)), IntegerEntry("amountTokenB", (amountTokenB + tokenReceiveAmount)), IntegerEntry("exchange_count", (count + 1)), IntegerEntry("invariant", invariantCalc((amountTokenA - tokenSendAmount), (amountTokenB + tokenReceiveAmount))), ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)] | |
177 | + | let tokenSendAmount = ((fraction(amountTokenA, tokenReceiveAmount, (tokenReceiveAmount + amountTokenB)) * (comissionScaleDelimiter - comission)) / comissionScaleDelimiter) | |
178 | + | if ((minTokenRecieve > tokenSendAmount)) | |
179 | + | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") | |
180 | + | else { | |
181 | + | let assetIdSent = assetIdTokenA | |
182 | + | [IntegerEntry("amountTokenA", (amountTokenA - tokenSendAmount)), IntegerEntry("amountTokenB", (amountTokenB + tokenReceiveAmount)), IntegerEntry("exchange_count", (count + 1)), ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)] | |
183 | + | } | |
261 | 184 | } | |
262 | 185 | else if ((assetIdReceived == assetIdTokenA)) | |
263 | 186 | then { | |
264 | - | let tokenSendAmount = calculateHowManySendTokenB(amountToSendEstimated, minTokenRecieveAmount, amountTokenA, amountTokenB, tokenReceiveAmount) | |
265 | - | let assetIdSent = assetIdTokenB | |
266 | - | [IntegerEntry("amountTokenA", (amountTokenA + tokenReceiveAmount)), IntegerEntry("amountTokenB", (amountTokenB - tokenSendAmount)), IntegerEntry("exchange_count", (count + 1)), IntegerEntry("invariant", invariantCalc((amountTokenA + tokenReceiveAmount), (amountTokenB - tokenSendAmount))), ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)] | |
187 | + | let tokenSendAmount = ((fraction(amountTokenB, tokenReceiveAmount, (tokenReceiveAmount + amountTokenA)) * (comissionScaleDelimiter - comission)) / comissionScaleDelimiter) | |
188 | + | if ((minTokenRecieve > tokenSendAmount)) | |
189 | + | then throw("Price has changed dramaticaly. Receiving token amount don't satisfy specified price level") | |
190 | + | else { | |
191 | + | let assetIdSent = assetIdTokenB | |
192 | + | [IntegerEntry("amountTokenA", (amountTokenA + tokenReceiveAmount)), IntegerEntry("amountTokenB", (amountTokenB - tokenSendAmount)), IntegerEntry("exchange_count", (count + 1)), ScriptTransfer(contextObj.caller, tokenSendAmount, assetIdSent)] | |
193 | + | } | |
267 | 194 | } | |
268 | 195 | else throw("Asset is not allowed") | |
269 | 196 | } | |
270 | 197 | ||
271 | 198 |
github/deemru/w8io/169f3d6 43.96 ms ◑