tx · J5b4bNh5jk7ZntukHhZyMEX3rug9fYDwyucLH2Lqhy8p 3N4revPn12feiSAyC78tAZEJfsyprVYPzsL: -0.05000000 Waves 2022.02.18 10:10 [1928742] smart account 3N4revPn12feiSAyC78tAZEJfsyprVYPzsL > SELF 0.00000000 Waves
{ "type": 13, "id": "J5b4bNh5jk7ZntukHhZyMEX3rug9fYDwyucLH2Lqhy8p", "fee": 5000000, "feeAssetId": null, "timestamp": 1645168244627, "version": 2, "chainId": 84, "sender": "3N4revPn12feiSAyC78tAZEJfsyprVYPzsL", "senderPublicKey": "5smGxL7bfeRokaN53Z31Y72dF2Lkr5Cg1kuWRV3gniNe", "proofs": [ "3VWBv3NhoaX2bapFLFxKvPbXGHVxM919j42HJuiKu7Yh5FU83REqkvj2efdGX9jxHYJEX3MbSq8kg6YgTKNY7RCi" ], "script": "base64:AAIFAAAAAAAAABgIAhIECgIBARIECgIBARIICgYBAQEIAQEAAAAZAAAAAAtzdHJBc3NldElkQQIAAAAsMzROOVljRUVUTFduOTNxWVE2NEVzUDF4ODl0U3J1SlU0NFJyRU1TWFhFUEoAAAAAC3N0ckFzc2V0SWRCAgAAACxERzJ4RmtQZER3S1VvQmt6R0FoUXRMcFNHemZYTGlDWVBFemVLSDJBZDI0cAAAAAAIYXNzZXRJZEEDCQAAAAAAAAIFAAAAC3N0ckFzc2V0SWRBAgAAAAVXQVZFUwUAAAAEdW5pdAkAAlkAAAABBQAAAAtzdHJBc3NldElkQQAAAAAIYXNzZXRJZEIDCQAAAAAAAAIFAAAAC3N0ckFzc2V0SWRCAgAAAAVXQVZFUwUAAAAEdW5pdAkAAlkAAAABBQAAAAtzdHJBc3NldElkQgAAAAADZmVlAAAAAAAAAAH0AAAAAA1mZWVHb3Zlcm5hbmNlAAAAAAAAAADIAAAAAAlmZWVTY2FsZTYAAAAAAAAPQkAAAAAABnNjYWxlMwAAAAAAAAAD6AAAAAAGc2NhbGU4AAAAAAAF9eEAAAAAAAdzY2FsZTEyAAAAAOj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AAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXl9/Cm7", "height": 1928742, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 47fQxWfxcvz3FfiTjtKH7HBUSyBRp4xoEW8dXaDjLjBB Next: 9ecKwtM6oUtrNgrTgpfSHkPFAFMnmSVBxbn9yWxhNngW Diff:
Old | New | Differences | |
---|---|---|---|
133 | 133 | let sk = skewnessBigInt(x, y) | |
134 | 134 | let xy = toBigInt((x + y)) | |
135 | 135 | let firstpow = pow(toBigInt(sk), digits12, toBigInt(alpha), alphaDigits, digits12, CEILING) | |
136 | - | let secondpow = pow(fraction(toBigInt(x), toBigInt(y), toBigInt(scale8)), 0, toBigInt(5), 1, (digits8 / 2), DOWN) | |
136 | + | let secpowfraction = fraction(toBigInt(x), toBigInt(y), toBigInt(scale8)) | |
137 | + | let secondpow = pow(secpowfraction, 0, toBigInt(5), 1, (digits8 / 2), DOWN) | |
137 | 138 | let thirdpow = pow(toBigInt((sk - betaBigInt)), digits12, toBigInt(alpha), alphaDigits, digits12, DOWN) | |
138 | 139 | let fractionFirst = toInt(fraction(xy, toBigInt(scale12), firstpow)) | |
139 | 140 | let fractionSecond = (2 * toInt(fraction(secondpow, thirdpow, toBigInt(scale12)))) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let strAssetIdA = "34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ" | |
5 | 5 | ||
6 | 6 | let strAssetIdB = "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p" | |
7 | 7 | ||
8 | 8 | let assetIdA = if ((strAssetIdA == "WAVES")) | |
9 | 9 | then unit | |
10 | 10 | else fromBase58String(strAssetIdA) | |
11 | 11 | ||
12 | 12 | let assetIdB = if ((strAssetIdB == "WAVES")) | |
13 | 13 | then unit | |
14 | 14 | else fromBase58String(strAssetIdB) | |
15 | 15 | ||
16 | 16 | let fee = 500 | |
17 | 17 | ||
18 | 18 | let feeGovernance = 200 | |
19 | 19 | ||
20 | 20 | let feeScale6 = 1000000 | |
21 | 21 | ||
22 | 22 | let scale3 = 1000 | |
23 | 23 | ||
24 | 24 | let scale8 = 100000000 | |
25 | 25 | ||
26 | 26 | let scale12 = 1000000000000 | |
27 | 27 | ||
28 | 28 | let slippageScale3 = 1000 | |
29 | 29 | ||
30 | 30 | let digits8 = 8 | |
31 | 31 | ||
32 | 32 | let digits12 = 12 | |
33 | 33 | ||
34 | 34 | let dAppThreshold = 50 | |
35 | 35 | ||
36 | 36 | let dAppThresholdScale2 = 100 | |
37 | 37 | ||
38 | 38 | let exchangeRatioLimitMin = 90000000 | |
39 | 39 | ||
40 | 40 | let exchangeRatioLimitMax = 110000000 | |
41 | 41 | ||
42 | 42 | let alpha = 50 | |
43 | 43 | ||
44 | 44 | let alphaDigits = 2 | |
45 | 45 | ||
46 | 46 | let beta = 46000000 | |
47 | 47 | ||
48 | 48 | let betaBigInt = 460000000000 | |
49 | 49 | ||
50 | 50 | func skewness (x,y) = (((fraction(scale12, x, y) + fraction(scale12, y, x)) / 2) / 10000) | |
51 | 51 | ||
52 | 52 | ||
53 | 53 | func skewnessBigInt (x,y) = ((fraction(scale12, x, y) + fraction(scale12, y, x)) / 2) | |
54 | 54 | ||
55 | 55 | ||
56 | 56 | func invariantCalc (x,y) = { | |
57 | 57 | let sk = skewness(x, y) | |
58 | 58 | let xy = (x + y) | |
59 | 59 | let firstpow = pow(sk, digits8, alpha, alphaDigits, digits8, CEILING) | |
60 | 60 | let secondpow = pow(fraction(x, y, scale8), 0, 5, 1, (digits8 / 2), DOWN) | |
61 | 61 | let thirdpow = pow((sk - beta), digits8, alpha, alphaDigits, digits8, DOWN) | |
62 | 62 | let firstsum = fraction(xy, scale8, firstpow) | |
63 | 63 | let secondsum = (2 * fraction(secondpow, thirdpow, scale8)) | |
64 | 64 | (firstsum + secondsum) | |
65 | 65 | } | |
66 | 66 | ||
67 | 67 | ||
68 | 68 | func calculateSendAmount (balanceA,balanceB,amountToSendEstimated,minTokenReceiveAmount,tokenReceiveAmount,tokenId) = { | |
69 | 69 | let slippageValue = (scale8 - ((scale8 * 1) / 10000000)) | |
70 | 70 | let deltaBetweenMaxAndMinSendValue = (amountToSendEstimated - minTokenReceiveAmount) | |
71 | 71 | let x = (balanceA + tokenReceiveAmount) | |
72 | 72 | let y = (balanceB + tokenReceiveAmount) | |
73 | 73 | let invariant = invariantCalc(balanceA, balanceB) | |
74 | 74 | let invariantNew = if ((tokenId == strAssetIdA)) | |
75 | 75 | then invariantCalc(x, (balanceB - amountToSendEstimated)) | |
76 | 76 | else if ((tokenId == strAssetIdB)) | |
77 | 77 | then invariantCalc((balanceA - amountToSendEstimated), y) | |
78 | 78 | else throw("Wrong asset in payment") | |
79 | 79 | let invariantEstimatedRatio = fraction(scale8, invariant, invariantNew) | |
80 | 80 | func getStepAmount (acc,step) = if ((acc == -1)) | |
81 | 81 | then { | |
82 | 82 | let amountToSend = (amountToSendEstimated - ((step * deltaBetweenMaxAndMinSendValue) / 5)) | |
83 | 83 | let stepInvariant = if ((tokenId == strAssetIdA)) | |
84 | 84 | then invariantCalc(x, (balanceB - amountToSend)) | |
85 | 85 | else invariantCalc((balanceA - amountToSend), y) | |
86 | 86 | if ((stepInvariant > invariant)) | |
87 | 87 | then amountToSend | |
88 | 88 | else -1 | |
89 | 89 | } | |
90 | 90 | else acc | |
91 | 91 | ||
92 | 92 | let stepAmount = { | |
93 | 93 | let $l = [1, 2, 3, 4, 5] | |
94 | 94 | let $s = size($l) | |
95 | 95 | let $acc0 = -1 | |
96 | 96 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
97 | 97 | then $a | |
98 | 98 | else getStepAmount($a, $l[$i]) | |
99 | 99 | ||
100 | 100 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
101 | 101 | then $a | |
102 | 102 | else throw("List size exceeds 5") | |
103 | 103 | ||
104 | 104 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5) | |
105 | 105 | } | |
106 | 106 | if ((0 > stepAmount)) | |
107 | 107 | then throw("something went wrong while working with amountToSend") | |
108 | 108 | else if (if ((invariantEstimatedRatio > slippageValue)) | |
109 | 109 | then (invariantNew > invariant) | |
110 | 110 | else false) | |
111 | 111 | then amountToSendEstimated | |
112 | 112 | else stepAmount | |
113 | 113 | } | |
114 | 114 | ||
115 | 115 | ||
116 | 116 | @Callable(i) | |
117 | 117 | func invariantCalcc (x,y) = { | |
118 | 118 | let sk = skewness(x, y) | |
119 | 119 | let xy = (x + y) | |
120 | 120 | let firstpow = pow(sk, digits8, alpha, alphaDigits, digits8, CEILING) | |
121 | 121 | let secondpow = pow(fraction(x, y, scale8), 0, 5, 1, (digits8 / 2), DOWN) | |
122 | 122 | let thirdpow = pow((sk - beta), digits8, alpha, alphaDigits, digits8, DOWN) | |
123 | 123 | let fractionFirst = fraction(xy, scale8, firstpow) | |
124 | 124 | let fractionSecond = fraction(secondpow, thirdpow, scale8) | |
125 | 125 | let invariant = (fractionFirst + (2 * fractionSecond)) | |
126 | 126 | [IntegerEntry("invariant", invariant)] | |
127 | 127 | } | |
128 | 128 | ||
129 | 129 | ||
130 | 130 | ||
131 | 131 | @Callable(i) | |
132 | 132 | func invariantCalccBigInt (x,y) = { | |
133 | 133 | let sk = skewnessBigInt(x, y) | |
134 | 134 | let xy = toBigInt((x + y)) | |
135 | 135 | let firstpow = pow(toBigInt(sk), digits12, toBigInt(alpha), alphaDigits, digits12, CEILING) | |
136 | - | let secondpow = pow(fraction(toBigInt(x), toBigInt(y), toBigInt(scale8)), 0, toBigInt(5), 1, (digits8 / 2), DOWN) | |
136 | + | let secpowfraction = fraction(toBigInt(x), toBigInt(y), toBigInt(scale8)) | |
137 | + | let secondpow = pow(secpowfraction, 0, toBigInt(5), 1, (digits8 / 2), DOWN) | |
137 | 138 | let thirdpow = pow(toBigInt((sk - betaBigInt)), digits12, toBigInt(alpha), alphaDigits, digits12, DOWN) | |
138 | 139 | let fractionFirst = toInt(fraction(xy, toBigInt(scale12), firstpow)) | |
139 | 140 | let fractionSecond = (2 * toInt(fraction(secondpow, thirdpow, toBigInt(scale12)))) | |
140 | 141 | let invariant = (fractionFirst + fractionSecond) | |
141 | 142 | [IntegerEntry("invariant", invariant)] | |
142 | 143 | } | |
143 | 144 | ||
144 | 145 | ||
145 | 146 | ||
146 | 147 | @Callable(i) | |
147 | 148 | func exchange (balanceA,balanceB,pmtAmount,pmtAssetId,estimatedAmountToReceive,minAmountToReceive) = { | |
148 | 149 | let amount = calculateSendAmount(balanceA, balanceB, estimatedAmountToReceive, minAmountToReceive, pmtAmount, pmtAssetId) | |
149 | 150 | let governanceReward = fraction(amount, feeGovernance, feeScale6) | |
150 | 151 | let amountMinusFee = fraction(amount, (feeScale6 - fee), feeScale6) | |
151 | 152 | ([IntegerEntry("sendAmount", amount), IntegerEntry("sendAmountWithComission", amountMinusFee), IntegerEntry("invariant", invariantCalc(balanceA, balanceB))] ++ (if ((pmtAssetId == strAssetIdA)) | |
152 | 153 | then [IntegerEntry("invariantNew", invariantCalc((balanceA + pmtAmount), (balanceB - amount)))] | |
153 | 154 | else [IntegerEntry("invariantNew", invariantCalc((balanceA - amount), (balanceB + pmtAmount)))])) | |
154 | 155 | } | |
155 | 156 | ||
156 | 157 | ||
157 | 158 | @Verifier(tx) | |
158 | 159 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
159 | 160 |
github/deemru/w8io/169f3d6 52.95 ms ◑