tx · Hdr2qht6YgFPXdN3fvAwRQhRZQq7LZRt5cDfuzKK2ehC 3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq: -0.01100000 Waves 2024.07.15 10:18 [3194838] smart account 3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq > SELF 0.00000000 Waves
{ "type": 13, "id": "Hdr2qht6YgFPXdN3fvAwRQhRZQq7LZRt5cDfuzKK2ehC", "fee": 1100000, "feeAssetId": null, "timestamp": 1721027930313, "version": 1, "sender": "3N6LHjfGb6Fgcy7YsVcNxGyPTj49XbQAijq", "senderPublicKey": "2u2wYYcVBQv43Cc71zkhHPPitkqgg6dqTZ3nUMvYJ1uq", "proofs": [ "4sYSRTsUsfARdBz2APngBpKiCf6tEDupdH36c6eH91hhRo5iEmWL9tkw3QiPfadVHvLcEABHyd8XFPCpE4jB9xqJ" ], "script": "base64:BgIQCAISBQoDAQgIEgUKAwEICBkAA1NFUAICX18ACGZlZVNjYWxlCQC2AgEAgMLXLwEPZ2V0U3RyaW5nT3JGYWlsAQNrZXkJARN2YWx1ZU9yRXJyb3JNZXNzYWdlAgkAnQgCBQR0aGlzBQNrZXkJAKwCAgIVTm8gZGF0YSBmb3IgdGhpcy5rZXk9BQNrZXkADHBvb2xEaXNhYmxlZAkAAgECDVBvb2wgZGlzYWJsZWQADHBvb2xOb3RFeGlzdAkAAgECEVBvb2wgaXMgbm90IGV4aXN0AA5zbGlwcGFnZVRvb0JpZwkAAgECE1NsaXBwYWdlIGlzIHRvbyBiaWcBE2tleU1hbmFnZXJQdWJsaWNLZXkAAhQlc19fbWFuYWdlclB1YmxpY0tleQEWa2V5TWFuYWdlclZhdWx0QWRkcmVzcwACFyVzX19tYW5hZ2VyVmF1bHRBZGRyZXNzAQJmYwACEyVzX19mYWN0b3J5Q29udHJhY3QAD2ZhY3RvcnlDb250cmFjdAkBEUBleHRyTmF0aXZlKDEwNjIpAQkBD2dldFN0cmluZ09yRmFpbAEJAQJmYwABC3Byb3RvY29s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GljS2V5lOXcVg==", "chainId": 84, "height": 3194838, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: EtVYfFaBUbs2evGPSU4RvB9nEUHYpAzej2tNzNm6ijmM Next: 4mAEE6mkGF31F2dz8awaZhAakdKKC1Xv3dWeoB8AAyR3 Diff:
Old | New | Differences | |
---|---|---|---|
177 | 177 | let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0)) | |
178 | 178 | then toBigInt(1) | |
179 | 179 | else feePoolAmountCalc | |
180 | - | let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
181 | - | let res = { | |
180 | + | let cleanAmountIn = if ((isReverse == true)) | |
181 | + | then ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
182 | + | else (toBigInt(amountIn) - feePoolAmount) | |
183 | + | let totalGetRaw = { | |
182 | 184 | let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse, toInt(feePoolAmount)], nil) | |
183 | 185 | if ($isInstanceOf(@, "Int")) | |
184 | 186 | then @ | |
185 | 187 | else throw(($getType(@) + " couldn't be cast to Int")) | |
186 | 188 | } | |
187 | - | $Tuple2(nil, res) | |
189 | + | let newTotalGet = if ((isReverse == true)) | |
190 | + | then totalGetRaw | |
191 | + | else { | |
192 | + | let feeProtocolFromGetCalc = fraction(toBigInt(totalGetRaw), toBigInt(prFee), feeScale) | |
193 | + | let feeProtocolAmountFromGet = if ((toInt(feeProtocolFromGetCalc) == 0)) | |
194 | + | then toInt(toBigInt(1)) | |
195 | + | else toInt(feeProtocolFromGetCalc) | |
196 | + | (totalGetRaw - feeProtocolAmountFromGet) | |
197 | + | } | |
198 | + | $Tuple2(nil, newTotalGet) | |
188 | 199 | } | |
189 | 200 | ||
190 | 201 | ||
191 | 202 | ||
192 | 203 | @Callable(i) | |
193 | 204 | func swap (amountOutMin,assetOutRaw,addressTo) = { | |
194 | - | let assetOut = if ((assetOutRaw == "")) | |
195 | - | then "WAVES" | |
196 | - | else assetOutRaw | |
197 | - | let pmt = value(i.payments[0]) | |
198 | - | let assetIn = if ((pmt.assetId == unit)) | |
199 | - | then "WAVES" | |
200 | - | else toBase58String(value(pmt.assetId)) | |
201 | - | let amountIn = value(pmt.amount) | |
202 | - | let $t051305208 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
203 | - | let poolAdr = $t051305208._1 | |
204 | - | let isReverse = $t051305208._2 | |
205 | - | let $t052115263 = getSwapFees(toString(poolAdr)) | |
206 | - | let plFee = $t052115263._1 | |
207 | - | let prFee = $t052115263._2 | |
208 | - | let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
209 | - | let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale) | |
210 | - | let addressTo_a = addressFromStringValue(addressTo) | |
211 | - | let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0)) | |
212 | - | then toBigInt(1) | |
213 | - | else feeProtocolAmountCalc | |
214 | - | let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0)) | |
215 | - | then toBigInt(1) | |
216 | - | else feePoolAmountCalc | |
217 | - | let cleanAmountIn = if ((isReverse == true)) | |
218 | - | then ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
219 | - | else (toBigInt(amountIn) - feePoolAmount) | |
220 | 205 | let checks = [if ((size(i.payments) == 1)) | |
221 | 206 | then true | |
222 | 207 | else throw("exactly 1 payment are expected")] | |
223 | 208 | if ((checks == checks)) | |
224 | 209 | then { | |
210 | + | let assetOut = if ((assetOutRaw == "")) | |
211 | + | then "WAVES" | |
212 | + | else assetOutRaw | |
213 | + | let pmt = value(i.payments[0]) | |
214 | + | let assetIn = if ((pmt.assetId == unit)) | |
215 | + | then "WAVES" | |
216 | + | else toBase58String(value(pmt.assetId)) | |
217 | + | let amountIn = value(pmt.amount) | |
218 | + | let $t059165994 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
219 | + | let poolAdr = $t059165994._1 | |
220 | + | let isReverse = $t059165994._2 | |
221 | + | let $t059976049 = getSwapFees(toString(poolAdr)) | |
222 | + | let plFee = $t059976049._1 | |
223 | + | let prFee = $t059976049._2 | |
224 | + | let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
225 | + | let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale) | |
226 | + | let addressTo_a = addressFromStringValue(addressTo) | |
227 | + | let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0)) | |
228 | + | then toBigInt(1) | |
229 | + | else feeProtocolAmountCalc | |
230 | + | let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0)) | |
231 | + | then toBigInt(1) | |
232 | + | else feePoolAmountCalc | |
233 | + | let cleanAmountIn = if ((isReverse == true)) | |
234 | + | then ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
235 | + | else (toBigInt(amountIn) - feePoolAmount) | |
225 | 236 | let assetInAttachedPayment = stringToAssetId(assetIn) | |
226 | 237 | let totalGetRaw = { | |
227 | 238 | let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, toString(this), toInt(feePoolAmount)], [AttachedPayment(assetInAttachedPayment, toInt(cleanAmountIn))]) | |
229 | 240 | then @ | |
230 | 241 | else throw(($getType(@) + " couldn't be cast to Int")) | |
231 | 242 | } | |
232 | - | let $ | |
243 | + | let $t072077801 = if ((isReverse == true)) | |
233 | 244 | then $Tuple2([ScriptTransfer(feeCollectorAddress, toInt(feeProtocolAmount), assetInAttachedPayment)], totalGetRaw) | |
234 | 245 | else { | |
235 | 246 | let feeProtocolFromGetCalc = fraction(toBigInt(totalGetRaw), toBigInt(prFee), feeScale) | |
238 | 249 | else toInt(feeProtocolFromGetCalc) | |
239 | 250 | $Tuple2([ScriptTransfer(feeCollectorAddress, feeProtocolAmountFromGet, stringToAssetId(assetOut))], (totalGetRaw - feeProtocolAmountFromGet)) | |
240 | 251 | } | |
241 | - | let protocolFeeActions = $ | |
242 | - | let newTotalGet = $ | |
252 | + | let protocolFeeActions = $t072077801._1 | |
253 | + | let newTotalGet = $t072077801._2 | |
243 | 254 | $Tuple2((protocolFeeActions ++ [ScriptTransfer(poolAdr, toInt(feePoolAmount), assetInAttachedPayment), ScriptTransfer(addressTo_a, newTotalGet, stringToAssetId(assetOut))]), newTotalGet) | |
244 | 255 | } | |
245 | 256 | else throw("Strict value is not equal to itself.") |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | 6 | let feeScale = toBigInt(100000000) | |
7 | 7 | ||
8 | 8 | func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), ("No data for this.key=" + key)) | |
9 | 9 | ||
10 | 10 | ||
11 | 11 | let poolDisabled = throw("Pool disabled") | |
12 | 12 | ||
13 | 13 | let poolNotExist = throw("Pool is not exist") | |
14 | 14 | ||
15 | 15 | let slippageTooBig = throw("Slippage is too big") | |
16 | 16 | ||
17 | 17 | func keyManagerPublicKey () = "%s__managerPublicKey" | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | func keyManagerVaultAddress () = "%s__managerVaultAddress" | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | func fc () = "%s__factoryContract" | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | let factoryContract = addressFromStringValue(getStringOrFail(fc())) | |
27 | 27 | ||
28 | 28 | func protocolFee () = makeString(["%s", "protocolFee"], SEP) | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func poolFee () = makeString(["%s", "poolFee"], SEP) | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func getStringOrFailFromAddress (address,key) = valueOrErrorMessage(getString(address, key), makeString(["mandatory ", toString(address), ".", key, " is not defined"], "")) | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | let keyFeeCollectorAddress = "%s__feeCollectorAddress" | |
38 | 38 | ||
39 | 39 | let feeCollectorAddress = addressFromStringValue(getStringOrFailFromAddress(factoryContract, keyFeeCollectorAddress)) | |
40 | 40 | ||
41 | 41 | func getManagerVaultAddressOrThis () = match getString(keyManagerVaultAddress()) { | |
42 | 42 | case s: String => | |
43 | 43 | addressFromStringValue(s) | |
44 | 44 | case _ => | |
45 | 45 | this | |
46 | 46 | } | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func asInt (val) = match val { | |
50 | 50 | case valInt: Int => | |
51 | 51 | valInt | |
52 | 52 | case _ => | |
53 | 53 | throw("fail to cast into Int") | |
54 | 54 | } | |
55 | 55 | ||
56 | 56 | ||
57 | 57 | func dataMappingPoolAssets (internalAmountAssetStr,internalPriceAssetStr) = makeString(["%d%d", toString(internalAmountAssetStr), toString(internalPriceAssetStr)], SEP) | |
58 | 58 | ||
59 | 59 | ||
60 | 60 | func managerPublicKeyOrUnit () = { | |
61 | 61 | let managerVaultAddress = getManagerVaultAddressOrThis() | |
62 | 62 | match getString(managerVaultAddress, keyManagerPublicKey()) { | |
63 | 63 | case s: String => | |
64 | 64 | fromBase58String(s) | |
65 | 65 | case _: Unit => | |
66 | 66 | unit | |
67 | 67 | case _ => | |
68 | 68 | throw("Match error") | |
69 | 69 | } | |
70 | 70 | } | |
71 | 71 | ||
72 | 72 | ||
73 | 73 | func isManager (i) = match managerPublicKeyOrUnit() { | |
74 | 74 | case pk: ByteVector => | |
75 | 75 | (i.callerPublicKey == pk) | |
76 | 76 | case _: Unit => | |
77 | 77 | (i.caller == this) | |
78 | 78 | case _ => | |
79 | 79 | throw("Match error") | |
80 | 80 | } | |
81 | 81 | ||
82 | 82 | ||
83 | 83 | func mustManager (i) = if (isManager(i)) | |
84 | 84 | then true | |
85 | 85 | else throw("permission denied") | |
86 | 86 | ||
87 | 87 | ||
88 | 88 | func getAccBalance (assetId) = if ((assetId == "WAVES")) | |
89 | 89 | then wavesBalance(this).available | |
90 | 90 | else assetBalance(this, fromBase58String(assetId)) | |
91 | 91 | ||
92 | 92 | ||
93 | 93 | func stringToAssetId (assetIdString) = if ((assetIdString == "WAVES")) | |
94 | 94 | then unit | |
95 | 95 | else fromBase58String(assetIdString) | |
96 | 96 | ||
97 | 97 | ||
98 | 98 | func getSwapFees (poolAddressStr) = { | |
99 | 99 | let poolFeeDefault = value(getInteger(this, poolFee())) | |
100 | 100 | let protocolFeeDefault = value(getInteger(this, protocolFee())) | |
101 | 101 | match invoke(factoryContract, "getSwapFeeREADONLY", [poolAddressStr], nil) { | |
102 | 102 | case fees: (Int, Int) => | |
103 | 103 | $Tuple2(fees._1, fees._2) | |
104 | 104 | case _ => | |
105 | 105 | $Tuple2(poolFeeDefault, protocolFeeDefault) | |
106 | 106 | } | |
107 | 107 | } | |
108 | 108 | ||
109 | 109 | ||
110 | 110 | func getPoolAddressAndCheckPoolStatus (assetIn,assetOut) = { | |
111 | 111 | let lpNonReverse = { | |
112 | 112 | let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetIn, assetOut], nil) | |
113 | 113 | if ($isInstanceOf(@, "String")) | |
114 | 114 | then @ | |
115 | 115 | else unit | |
116 | 116 | } | |
117 | 117 | let lpReverse = { | |
118 | 118 | let @ = invoke(factoryContract, "getLpAssetFromPoolAssetsREADONLY", [assetOut, assetIn], nil) | |
119 | 119 | if ($isInstanceOf(@, "String")) | |
120 | 120 | then @ | |
121 | 121 | else unit | |
122 | 122 | } | |
123 | 123 | let $t031283587 = if ((lpNonReverse != unit)) | |
124 | 124 | then { | |
125 | 125 | let pool = { | |
126 | 126 | let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpNonReverse)], nil) | |
127 | 127 | if ($isInstanceOf(@, "String")) | |
128 | 128 | then @ | |
129 | 129 | else throw(($getType(@) + " couldn't be cast to String")) | |
130 | 130 | } | |
131 | 131 | $Tuple2(false, pool) | |
132 | 132 | } | |
133 | 133 | else if ((lpReverse != unit)) | |
134 | 134 | then { | |
135 | 135 | let pool = { | |
136 | 136 | let @ = invoke(factoryContract, "getPoolAddressFromLpAssetREADONLY", [value(lpReverse)], nil) | |
137 | 137 | if ($isInstanceOf(@, "String")) | |
138 | 138 | then @ | |
139 | 139 | else throw(($getType(@) + " couldn't be cast to String")) | |
140 | 140 | } | |
141 | 141 | $Tuple2(true, pool) | |
142 | 142 | } | |
143 | 143 | else poolNotExist | |
144 | 144 | let isReverse = $t031283587._1 | |
145 | 145 | let pool = $t031283587._2 | |
146 | 146 | let poolStatus = { | |
147 | 147 | let @ = invoke(factoryContract, "getPoolStatusREADONLY", [pool], nil) | |
148 | 148 | if ($isInstanceOf(@, "Int")) | |
149 | 149 | then @ | |
150 | 150 | else throw(($getType(@) + " couldn't be cast to Int")) | |
151 | 151 | } | |
152 | 152 | let check = if ((poolStatus == 1)) | |
153 | 153 | then true | |
154 | 154 | else poolDisabled | |
155 | 155 | if ((check == check)) | |
156 | 156 | then { | |
157 | 157 | let poolAdr = addressFromStringValue(valueOrElse(pool, "")) | |
158 | 158 | $Tuple2(poolAdr, isReverse) | |
159 | 159 | } | |
160 | 160 | else throw("Strict value is not equal to itself.") | |
161 | 161 | } | |
162 | 162 | ||
163 | 163 | ||
164 | 164 | @Callable(i) | |
165 | 165 | func swapCalculateREADONLY (amountIn,assetIn,assetOut) = { | |
166 | 166 | let $t039834061 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
167 | 167 | let poolAdr = $t039834061._1 | |
168 | 168 | let isReverse = $t039834061._2 | |
169 | 169 | let $t040654117 = getSwapFees(toString(poolAdr)) | |
170 | 170 | let plFee = $t040654117._1 | |
171 | 171 | let prFee = $t040654117._2 | |
172 | 172 | let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
173 | 173 | let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale) | |
174 | 174 | let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0)) | |
175 | 175 | then toBigInt(1) | |
176 | 176 | else feeProtocolAmountCalc | |
177 | 177 | let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0)) | |
178 | 178 | then toBigInt(1) | |
179 | 179 | else feePoolAmountCalc | |
180 | - | let cleanAmountIn = ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
181 | - | let res = { | |
180 | + | let cleanAmountIn = if ((isReverse == true)) | |
181 | + | then ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
182 | + | else (toBigInt(amountIn) - feePoolAmount) | |
183 | + | let totalGetRaw = { | |
182 | 184 | let @ = invoke(poolAdr, "calculateAmountOutForSwapREADONLY", [toInt(cleanAmountIn), isReverse, toInt(feePoolAmount)], nil) | |
183 | 185 | if ($isInstanceOf(@, "Int")) | |
184 | 186 | then @ | |
185 | 187 | else throw(($getType(@) + " couldn't be cast to Int")) | |
186 | 188 | } | |
187 | - | $Tuple2(nil, res) | |
189 | + | let newTotalGet = if ((isReverse == true)) | |
190 | + | then totalGetRaw | |
191 | + | else { | |
192 | + | let feeProtocolFromGetCalc = fraction(toBigInt(totalGetRaw), toBigInt(prFee), feeScale) | |
193 | + | let feeProtocolAmountFromGet = if ((toInt(feeProtocolFromGetCalc) == 0)) | |
194 | + | then toInt(toBigInt(1)) | |
195 | + | else toInt(feeProtocolFromGetCalc) | |
196 | + | (totalGetRaw - feeProtocolAmountFromGet) | |
197 | + | } | |
198 | + | $Tuple2(nil, newTotalGet) | |
188 | 199 | } | |
189 | 200 | ||
190 | 201 | ||
191 | 202 | ||
192 | 203 | @Callable(i) | |
193 | 204 | func swap (amountOutMin,assetOutRaw,addressTo) = { | |
194 | - | let assetOut = if ((assetOutRaw == "")) | |
195 | - | then "WAVES" | |
196 | - | else assetOutRaw | |
197 | - | let pmt = value(i.payments[0]) | |
198 | - | let assetIn = if ((pmt.assetId == unit)) | |
199 | - | then "WAVES" | |
200 | - | else toBase58String(value(pmt.assetId)) | |
201 | - | let amountIn = value(pmt.amount) | |
202 | - | let $t051305208 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
203 | - | let poolAdr = $t051305208._1 | |
204 | - | let isReverse = $t051305208._2 | |
205 | - | let $t052115263 = getSwapFees(toString(poolAdr)) | |
206 | - | let plFee = $t052115263._1 | |
207 | - | let prFee = $t052115263._2 | |
208 | - | let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
209 | - | let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale) | |
210 | - | let addressTo_a = addressFromStringValue(addressTo) | |
211 | - | let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0)) | |
212 | - | then toBigInt(1) | |
213 | - | else feeProtocolAmountCalc | |
214 | - | let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0)) | |
215 | - | then toBigInt(1) | |
216 | - | else feePoolAmountCalc | |
217 | - | let cleanAmountIn = if ((isReverse == true)) | |
218 | - | then ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
219 | - | else (toBigInt(amountIn) - feePoolAmount) | |
220 | 205 | let checks = [if ((size(i.payments) == 1)) | |
221 | 206 | then true | |
222 | 207 | else throw("exactly 1 payment are expected")] | |
223 | 208 | if ((checks == checks)) | |
224 | 209 | then { | |
210 | + | let assetOut = if ((assetOutRaw == "")) | |
211 | + | then "WAVES" | |
212 | + | else assetOutRaw | |
213 | + | let pmt = value(i.payments[0]) | |
214 | + | let assetIn = if ((pmt.assetId == unit)) | |
215 | + | then "WAVES" | |
216 | + | else toBase58String(value(pmt.assetId)) | |
217 | + | let amountIn = value(pmt.amount) | |
218 | + | let $t059165994 = getPoolAddressAndCheckPoolStatus(assetIn, assetOut) | |
219 | + | let poolAdr = $t059165994._1 | |
220 | + | let isReverse = $t059165994._2 | |
221 | + | let $t059976049 = getSwapFees(toString(poolAdr)) | |
222 | + | let plFee = $t059976049._1 | |
223 | + | let prFee = $t059976049._2 | |
224 | + | let feeProtocolAmountCalc = fraction(toBigInt(amountIn), toBigInt(prFee), feeScale) | |
225 | + | let feePoolAmountCalc = fraction(toBigInt(amountIn), toBigInt(plFee), feeScale) | |
226 | + | let addressTo_a = addressFromStringValue(addressTo) | |
227 | + | let feeProtocolAmount = if ((toInt(feeProtocolAmountCalc) == 0)) | |
228 | + | then toBigInt(1) | |
229 | + | else feeProtocolAmountCalc | |
230 | + | let feePoolAmount = if ((toInt(feePoolAmountCalc) == 0)) | |
231 | + | then toBigInt(1) | |
232 | + | else feePoolAmountCalc | |
233 | + | let cleanAmountIn = if ((isReverse == true)) | |
234 | + | then ((toBigInt(amountIn) - feeProtocolAmount) - feePoolAmount) | |
235 | + | else (toBigInt(amountIn) - feePoolAmount) | |
225 | 236 | let assetInAttachedPayment = stringToAssetId(assetIn) | |
226 | 237 | let totalGetRaw = { | |
227 | 238 | let @ = invoke(poolAdr, "calculateAmountOutForSwapAndSendTokens", [toInt(cleanAmountIn), isReverse, amountOutMin, toString(this), toInt(feePoolAmount)], [AttachedPayment(assetInAttachedPayment, toInt(cleanAmountIn))]) | |
228 | 239 | if ($isInstanceOf(@, "Int")) | |
229 | 240 | then @ | |
230 | 241 | else throw(($getType(@) + " couldn't be cast to Int")) | |
231 | 242 | } | |
232 | - | let $ | |
243 | + | let $t072077801 = if ((isReverse == true)) | |
233 | 244 | then $Tuple2([ScriptTransfer(feeCollectorAddress, toInt(feeProtocolAmount), assetInAttachedPayment)], totalGetRaw) | |
234 | 245 | else { | |
235 | 246 | let feeProtocolFromGetCalc = fraction(toBigInt(totalGetRaw), toBigInt(prFee), feeScale) | |
236 | 247 | let feeProtocolAmountFromGet = if ((toInt(feeProtocolFromGetCalc) == 0)) | |
237 | 248 | then toInt(toBigInt(1)) | |
238 | 249 | else toInt(feeProtocolFromGetCalc) | |
239 | 250 | $Tuple2([ScriptTransfer(feeCollectorAddress, feeProtocolAmountFromGet, stringToAssetId(assetOut))], (totalGetRaw - feeProtocolAmountFromGet)) | |
240 | 251 | } | |
241 | - | let protocolFeeActions = $ | |
242 | - | let newTotalGet = $ | |
252 | + | let protocolFeeActions = $t072077801._1 | |
253 | + | let newTotalGet = $t072077801._2 | |
243 | 254 | $Tuple2((protocolFeeActions ++ [ScriptTransfer(poolAdr, toInt(feePoolAmount), assetInAttachedPayment), ScriptTransfer(addressTo_a, newTotalGet, stringToAssetId(assetOut))]), newTotalGet) | |
244 | 255 | } | |
245 | 256 | else throw("Strict value is not equal to itself.") | |
246 | 257 | } | |
247 | 258 | ||
248 | 259 | ||
249 | 260 | @Verifier(tx) | |
250 | 261 | func verify () = { | |
251 | 262 | let targetPublicKey = match managerPublicKeyOrUnit() { | |
252 | 263 | case pk: ByteVector => | |
253 | 264 | pk | |
254 | 265 | case _: Unit => | |
255 | 266 | tx.senderPublicKey | |
256 | 267 | case _ => | |
257 | 268 | throw("Match error") | |
258 | 269 | } | |
259 | 270 | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) | |
260 | 271 | } | |
261 | 272 |
github/deemru/w8io/026f985 98.05 ms ◑