1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let Scale6 = 1000000 |
---|
5 | 5 | | |
---|
6 | 6 | | let Scale6BigInt = toBigInt(Scale6) |
---|
7 | 7 | | |
---|
8 | 8 | | let ZeroBigInt = toBigInt(0) |
---|
9 | 9 | | |
---|
10 | 10 | | let Scale8 = 100000000 |
---|
11 | 11 | | |
---|
12 | 12 | | let Scale8BigInt = toBigInt(Scale8) |
---|
13 | 13 | | |
---|
14 | 14 | | let SEP = "__" |
---|
15 | 15 | | |
---|
16 | 16 | | let InScale = 1000000 |
---|
17 | 17 | | |
---|
18 | 18 | | let InDecimals = 6 |
---|
19 | 19 | | |
---|
20 | 20 | | let InScaleBigInt = toBigInt(InScale) |
---|
21 | 21 | | |
---|
22 | 22 | | let InAsset = base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p' |
---|
23 | 23 | | |
---|
24 | 24 | | let caller = Address(base58'3P5ji1wvrDLQxgK5c3cGbiSwiZfu5x1S3VR') |
---|
25 | 25 | | |
---|
26 | 26 | | let receiver = Address(base58'3P5ji1wvrDLQxgK5c3cGbiSwiZfu5x1S3VR') |
---|
27 | 27 | | |
---|
28 | 28 | | let wxSwapAddress = Address(base58'3P68zNiufsu1viZpu1aY3cdahRRKcvV5N93') |
---|
29 | 29 | | |
---|
30 | 30 | | let thisAddressStr = toString(this) |
---|
31 | 31 | | |
---|
32 | 32 | | func getBalance (asset) = if ((asset == unit)) |
---|
33 | 33 | | then wavesBalance(this).regular |
---|
34 | 34 | | else assetBalance(this, value(asset)) |
---|
35 | 35 | | |
---|
36 | 36 | | |
---|
37 | 37 | | func getAssetOrWaves (assetStr) = if ((assetStr == "WAVES")) |
---|
38 | 38 | | then unit |
---|
39 | 39 | | else fromBase58String(assetStr) |
---|
40 | 40 | | |
---|
41 | 41 | | |
---|
42 | 42 | | let inBalance = getBalance(InAsset) |
---|
43 | 43 | | |
---|
44 | 44 | | let inBalanceBigInt = toBigInt(inBalance) |
---|
45 | 45 | | |
---|
46 | 46 | | func getSwopPool (pool) = { |
---|
47 | 47 | | let assetIdAStr = getStringValue(pool, "A_asset_id") |
---|
48 | 48 | | let assetIdBStr = getStringValue(pool, "B_asset_id") |
---|
49 | 49 | | let assetIdA = getAssetOrWaves(assetIdAStr) |
---|
50 | 50 | | let assetIdB = getAssetOrWaves(assetIdBStr) |
---|
51 | 51 | | let balanceA = getIntegerValue(pool, "A_asset_balance") |
---|
52 | 52 | | let balanceB = getIntegerValue(pool, "B_asset_balance") |
---|
53 | 53 | | let outFee = (Scale6BigInt - toBigInt(getIntegerValue(pool, "commission"))) |
---|
54 | 54 | | $Tuple9(toBigInt(balanceA), toBigInt(balanceB), assetIdA, assetIdB, assetIdAStr, assetIdBStr, Scale6BigInt, outFee, pool) |
---|
55 | 55 | | } |
---|
56 | 56 | | |
---|
57 | 57 | | |
---|
58 | 58 | | func keyAdditionalBalance (assetId) = makeString(["%s%s", "stakedBalance", assetId], SEP) |
---|
59 | 59 | | |
---|
60 | 60 | | |
---|
61 | 61 | | func keyStakingAssetBalance (assetId) = makeString(["%s%s", "shareAssetBalance", assetId], SEP) |
---|
62 | 62 | | |
---|
63 | 63 | | |
---|
64 | 64 | | func getAdditionalBalanceOrZero (pool,assetId) = valueOrElse(getInteger(pool, keyAdditionalBalance(assetId)), 0) |
---|
65 | 65 | | |
---|
66 | 66 | | |
---|
67 | 67 | | func getStakingAssetBalanceOrZero (pool,assetId) = valueOrElse(getInteger(pool, keyStakingAssetBalance(assetId)), 0) |
---|
68 | 68 | | |
---|
69 | 69 | | |
---|
70 | 70 | | func getWxAccountBalance (pool,assetId) = { |
---|
71 | 71 | | let balanceOnPool = if ((assetId == "WAVES")) |
---|
72 | 72 | | then wavesBalance(pool).available |
---|
73 | 73 | | else assetBalance(pool, fromBase58String(assetId)) |
---|
74 | 74 | | let totalBalance = ((balanceOnPool + getAdditionalBalanceOrZero(pool, assetId)) - getStakingAssetBalanceOrZero(pool, assetId)) |
---|
75 | 75 | | max([0, totalBalance]) |
---|
76 | 76 | | } |
---|
77 | 77 | | |
---|
78 | 78 | | |
---|
79 | 79 | | func getWxPool (pool) = { |
---|
80 | 80 | | let assetIdAStr = getStringValue(pool, "%s__amountAsset") |
---|
81 | 81 | | let assetIdBStr = getStringValue(pool, "%s__priceAsset") |
---|
82 | 82 | | let assetIdA = getAssetOrWaves(assetIdAStr) |
---|
83 | 83 | | let assetIdB = getAssetOrWaves(assetIdBStr) |
---|
84 | 84 | | let balanceA = getWxAccountBalance(pool, assetIdAStr) |
---|
85 | 85 | | let balanceB = getWxAccountBalance(pool, assetIdBStr) |
---|
86 | 86 | | let protocolFee = getIntegerValue(wxSwapAddress, "%s__protocolFee") |
---|
87 | 87 | | let poolFee = getIntegerValue(wxSwapAddress, "%s__poolFee") |
---|
88 | 88 | | let inFee = (Scale6BigInt - fraction(toBigInt((protocolFee + poolFee)), Scale6BigInt, Scale8BigInt)) |
---|
89 | 89 | | $Tuple9(toBigInt(balanceA), toBigInt(balanceB), assetIdA, assetIdB, assetIdAStr, assetIdBStr, inFee, Scale6BigInt, wxSwapAddress) |
---|
90 | 90 | | } |
---|
91 | 91 | | |
---|
92 | 92 | | |
---|
93 | 93 | | func calcSwap (pmtAmount,tokenFrom,tokenTo,inFee,outFee) = { |
---|
94 | 94 | | let cleanAmount = fraction(pmtAmount, inFee, Scale6BigInt) |
---|
95 | 95 | | let amountWithoutFee = fraction(tokenTo, cleanAmount, (cleanAmount + tokenFrom)) |
---|
96 | 96 | | let amountWithFee = fraction(amountWithoutFee, outFee, Scale6BigInt) |
---|
97 | 97 | | amountWithFee |
---|
98 | 98 | | } |
---|
99 | 99 | | |
---|
100 | 100 | | |
---|
101 | 101 | | func estimateSwap (poolInfo,inAsset,inAmount) = { |
---|
102 | 102 | | let routeArgs = if ((inAsset == poolInfo._3)) |
---|
103 | 103 | | then $Tuple3(poolInfo._4, poolInfo._6, calcSwap(inAmount, poolInfo._1, poolInfo._2, poolInfo._7, poolInfo._8)) |
---|
104 | 104 | | else $Tuple3(poolInfo._3, poolInfo._5, calcSwap(inAmount, poolInfo._2, poolInfo._1, poolInfo._7, poolInfo._8)) |
---|
105 | 105 | | let dappArgs = if ((poolInfo._9 == wxSwapAddress)) |
---|
106 | 106 | | then $Tuple2("swap", [0, routeArgs._2, thisAddressStr]) |
---|
107 | 107 | | else $Tuple2("exchange", [1]) |
---|
108 | 108 | | $Tuple4(routeArgs._1, routeArgs._3, dappArgs._1, dappArgs._2) |
---|
109 | 109 | | } |
---|
110 | 110 | | |
---|
111 | 111 | | |
---|
112 | 112 | | func estimateRoute (pool1,pool2,pool3,pool1Reverse,pool2Reverse,pool3Reverse) = { |
---|
113 | 113 | | let a12 = if (pool1Reverse) |
---|
114 | 114 | | then pool1._2 |
---|
115 | 115 | | else pool1._1 |
---|
116 | 116 | | let a21 = if (pool1Reverse) |
---|
117 | 117 | | then pool1._1 |
---|
118 | 118 | | else pool1._2 |
---|
119 | 119 | | let a23 = if (pool2Reverse) |
---|
120 | 120 | | then pool2._2 |
---|
121 | 121 | | else pool2._1 |
---|
122 | 122 | | let a32 = if (pool2Reverse) |
---|
123 | 123 | | then pool2._1 |
---|
124 | 124 | | else pool2._2 |
---|
125 | 125 | | let a31 = if (pool3Reverse) |
---|
126 | 126 | | then pool3._2 |
---|
127 | 127 | | else pool3._1 |
---|
128 | 128 | | let a13 = if (pool3Reverse) |
---|
129 | 129 | | then pool3._1 |
---|
130 | 130 | | else pool3._2 |
---|
131 | 131 | | let aaDenominator = (a23 + fraction(fraction(a21, pool1._8, Scale6BigInt), pool2._7, Scale6BigInt)) |
---|
132 | 132 | | let aa13 = fraction(a12, a23, aaDenominator) |
---|
133 | 133 | | let aa31 = fraction(fraction(fraction(a21, a32, aaDenominator), pool2._7, Scale6BigInt), pool2._8, Scale6BigInt) |
---|
134 | 134 | | let aDenominator = (a31 + fraction(fraction(aa31, pool1._7, Scale6BigInt), pool1._8, Scale6BigInt)) |
---|
135 | 135 | | let a = fraction(aa13, a31, aDenominator) |
---|
136 | 136 | | let aa = fraction(fraction(fraction(aa31, a13, aDenominator), pool3._7, Scale6BigInt), pool3._8, Scale6BigInt) |
---|
137 | 137 | | let delta = fraction((sqrtBigInt(fraction(fraction(fraction(aa, a, InScaleBigInt), pool1._7, Scale6BigInt), pool1._8, Scale6BigInt), InDecimals, InDecimals, CEILING) - a), Scale6BigInt, pool1._7) |
---|
138 | 138 | | if ((ZeroBigInt >= delta)) |
---|
139 | 139 | | then $Tuple2(0, nil) |
---|
140 | 140 | | else { |
---|
141 | 141 | | let input = if ((delta > inBalanceBigInt)) |
---|
142 | 142 | | then inBalanceBigInt |
---|
143 | 143 | | else delta |
---|
144 | 144 | | let swap1 = estimateSwap(pool1, InAsset, input) |
---|
145 | 145 | | let swap2 = estimateSwap(pool2, swap1._1, swap1._2) |
---|
146 | 146 | | let swap3 = estimateSwap(pool3, swap2._1, swap2._2) |
---|
147 | 147 | | $Tuple2(toInt((swap3._2 - input)), [$Tuple5(pool1._9, swap1._3, swap1._4, InAsset, toInt(input)), $Tuple5(pool2._9, swap2._3, swap2._4, swap1._1, toInt(swap1._2)), $Tuple5(pool3._9, swap3._3, swap3._4, swap2._1, toInt(swap2._2))]) |
---|
148 | 148 | | } |
---|
149 | 149 | | } |
---|
150 | 150 | | |
---|
151 | 151 | | |
---|
152 | 152 | | func invokeSwap (args) = { |
---|
153 | 153 | | let currentBalance = getBalance(args._4) |
---|
154 | 154 | | let trimmedAmount = if ((args._5 > currentBalance)) |
---|
155 | 155 | | then currentBalance |
---|
156 | 156 | | else args._5 |
---|
157 | 157 | | let resultAmount = if ((args._4 == InAsset)) |
---|
158 | 158 | | then trimmedAmount |
---|
159 | 159 | | else if ((currentBalance > args._5)) |
---|
160 | 160 | | then currentBalance |
---|
161 | 161 | | else trimmedAmount |
---|
162 | 162 | | invoke(args._1, args._2, args._3, [AttachedPayment(args._4, resultAmount)]) |
---|
163 | 163 | | } |
---|
164 | 164 | | |
---|
165 | 165 | | |
---|
166 | 166 | | let swop_btcwxg_xtn = getSwopPool(Address(base58'3PACj2DLTw3uUhsUmT98zHU5M4hPufbHKav')) |
---|
167 | 167 | | |
---|
168 | 168 | | let swop_egg_waves = getSwopPool(Address(base58'3PNVFWopwCD9CgGXkpYWEY94oQ5XCAEXBmQ')) |
---|
169 | 169 | | |
---|
170 | 170 | | let swop_ethwxg_xtn = getSwopPool(Address(base58'3PNEC4YKqZiMMytFrYRVtpW2ujvi3aGXRPm')) |
---|
171 | 171 | | |
---|
172 | 172 | | let swop_nsbt_xtn = getSwopPool(Address(base58'3P2V63Xd6BviDkeMzxhUw2SJyojByRz8a8m')) |
---|
173 | 173 | | |
---|
174 | 174 | | let swop_pluto_xtn = getSwopPool(Address(base58'3PDSXwwA2xAtmxeo2bebDP3AA5ynZ2Krgnw')) |
---|
175 | 175 | | |
---|
176 | 176 | | let swop_pwr_xtn = getSwopPool(Address(base58'3P88KDKWHNKNdbZxe8FfAJP8coAhvfDtuzV')) |
---|
177 | 177 | | |
---|
178 | 178 | | let swop_puzzle_xtn = getSwopPool(Address(base58'3PBHyEwmERR1CEkrTNbPj2bgyisTfPRqfee')) |
---|
179 | 179 | | |
---|
180 | 180 | | let swop_puzzle_waves = getSwopPool(Address(base58'3PRFKemXs4rAJYGPccNtP63Kw2UzwEdH7sZ')) |
---|
181 | 181 | | |
---|
182 | 182 | | let swop_race_egg = getSwopPool(Address(base58'3P3Z8Gn665CJr14bTLv4d5USDBUQCTeeCaT')) |
---|
183 | 183 | | |
---|
184 | 184 | | let swop_surf_xtn = getSwopPool(Address(base58'3PLp9KrdrbWAvSFHGJVEaszUubquz3M6mfe')) |
---|
185 | 185 | | |
---|
186 | 186 | | let swop_swop_xtn = getSwopPool(Address(base58'3P27S9V36kw2McjWRZ37AxTx8iwkd7HXw6W')) |
---|
187 | 187 | | |
---|
188 | 188 | | let swop_swop_waves = getSwopPool(Address(base58'3PH8Np6jwuoikvkHL2qmdpFEHBR4UV5vwSq')) |
---|
189 | 189 | | |
---|
190 | 190 | | let swop_vires_xtn = getSwopPool(Address(base58'3PJ48P3p2wvWUjgQaQiZ2cFbr8qmxMokBGd')) |
---|
191 | 191 | | |
---|
192 | 192 | | let swop_waves_btcwxg = getSwopPool(Address(base58'3P8FVZgAJUAq32UEZtTw84qS4zLqEREiEiP')) |
---|
193 | 193 | | |
---|
194 | 194 | | let swop_waves_xtn = getSwopPool(Address(base58'3PHaNgomBkrvEL2QnuJarQVJa71wjw9qiqG')) |
---|
195 | 195 | | |
---|
196 | 196 | | let swop_waves_eurn = getSwopPool(Address(base58'3PK7Xe5BiedRyxHLuMQx5ey9riUQqvUths2')) |
---|
197 | 197 | | |
---|
198 | 198 | | let swop_waves_usdtppt = getSwopPool(Address(base58'3P2M9btqYdpENh1SkaHFDdc8XSjXHNiAXF5')) |
---|
199 | 199 | | |
---|
200 | 200 | | let swop_west_xtn = getSwopPool(Address(base58'3P6DLdJTP2EySq9MFdJu6beUevrQd2sVVBh')) |
---|
201 | 201 | | |
---|
202 | 202 | | let swop_wx_xtn = getSwopPool(Address(base58'3PKi4G3VX2k42ZSmNNrmvgdDH7JzRaUhY7R')) |
---|
203 | 203 | | |
---|
204 | 204 | | let swop_xtn_usdtwxg = getSwopPool(Address(base58'3PAunb4Dadc9rQM2VJNQBgQV3vrgF9z8Evq')) |
---|
205 | 205 | | |
---|
206 | 206 | | let wx_btcwxg_xtn = getWxPool(Address(base58'3PCBWDTA6jrFswd7gQgaE3Xk7gLM5RKofvp')) |
---|
207 | 207 | | |
---|
208 | 208 | | let wx_egg_waves = getWxPool(Address(base58'3PJkUhnAHMaBTjyc7FkBfHantNUy871kBBW')) |
---|
209 | 209 | | |
---|
210 | 210 | | let wx_egg_xtn = getWxPool(Address(base58'3P3Y38zymCHoTM6qcE9JcEA8rhaGTQbVMgu')) |
---|
211 | 211 | | |
---|
212 | 212 | | let wx_ethwxg_waves = getWxPool(Address(base58'3P3XGTN6s292g9iwYhs3TEqJqHiffQYojuE')) |
---|
213 | 213 | | |
---|
214 | 214 | | let wx_ethwxg_xtn = getWxPool(Address(base58'3PEMqetsaJDbYMw1XGovmE37FB8VUhGnX9A')) |
---|
215 | 215 | | |
---|
216 | 216 | | let wx_eurn_xtn = getWxPool(Address(base58'3P879DU3ycr2XWorD7rR5gSpn1CpYgHjgFT')) |
---|
217 | 217 | | |
---|
218 | 218 | | let wx_nsbt_waves = getWxPool(Address(base58'3PPR4zVfWP4w4rshP541aiFtPNQN2sNJwrY')) |
---|
219 | 219 | | |
---|
220 | 220 | | let wx_nsbt_xtn = getWxPool(Address(base58'3P97XQCT9VYMXBxasVpDsE7eZfQ6cR9eS9n')) |
---|
221 | 221 | | |
---|
222 | 222 | | let wx_pluto_waves = getWxPool(Address(base58'3P6ZipK8ydb4qHmufCquh98g9KW6EwaeJfk')) |
---|
223 | 223 | | |
---|
224 | 224 | | let wx_pluto_xtn = getWxPool(Address(base58'3PEkD5LuHGWhUfgBW1owZFxVydYoWjV6Jia')) |
---|
225 | 225 | | |
---|
226 | 226 | | let wx_puzzle_waves = getWxPool(Address(base58'3PQaYm4pbRVrNTTnL8pDJZTxhcmD4jRskrz')) |
---|
227 | 227 | | |
---|
228 | 228 | | let wx_puzzle_xtn = getWxPool(Address(base58'3P615yXeQ9Qu4qBM1QGimGzixyMS5W4Ktug')) |
---|
229 | 229 | | |
---|
230 | 230 | | let wx_pwr_waves = getWxPool(Address(base58'3PDi7Qq8pLQYvtKyTfQuqqPUWyhoYbU957t')) |
---|
231 | 231 | | |
---|
232 | 232 | | let wx_race_xtn = getWxPool(Address(base58'3P2nHbqMt7hiYKQjYLT3AEDteS4SYGeHTuc')) |
---|
233 | 233 | | |
---|
234 | 234 | | let wx_surf_waves = getWxPool(Address(base58'3PNnCngfvAzyvAQ1cEudZ3o6o3tFktsBVz5')) |
---|
235 | 235 | | |
---|
236 | 236 | | let wx_swaves_waves = getWxPool(Address(base58'3PDVaJDqCadWeBugf768XeKiXtCCLUrYMge')) |
---|
237 | 237 | | |
---|
238 | 238 | | let wx_swaves_xtn = getWxPool(Address(base58'3PEmxUzcCbsAcw6Q3VNLTWdd8bjc8KBUEDz')) |
---|
239 | 239 | | |
---|
240 | 240 | | let wx_swop_waves = getWxPool(Address(base58'3PA8nK44sopUpXNcCRTpPSH2F7yjvxzx5cw')) |
---|
241 | 241 | | |
---|
242 | 242 | | let wx_swop_xtn = getWxPool(Address(base58'3PCApn7kL3UMdCVYA2Ln2UcQvfnkFRL1qDC')) |
---|
243 | 243 | | |
---|
244 | 244 | | let wx_usdtppt_xtn = getWxPool(Address(base58'3P5kfoYW7jPa9zYoTkN6Z6z8xtw8JGhymYB')) |
---|
245 | 245 | | |
---|
246 | 246 | | let wx_vires_waves = getWxPool(Address(base58'3P7Z7X5kKXN4TpZ2SmqP2xyLGuotAqht1pU')) |
---|
247 | 247 | | |
---|
248 | 248 | | let wx_vires_xtn = getWxPool(Address(base58'3P5HjPowgipiVB3UvXphDiPvKs424WC9xQw')) |
---|
249 | 249 | | |
---|
250 | 250 | | let wx_waves_btcwxg = getWxPool(Address(base58'3PPQDcvXuwVToC2QNWzPwxmLxLzMw9Eoe8C')) |
---|
251 | 251 | | |
---|
252 | 252 | | let wx_waves_xtn = getWxPool(Address(base58'3PPZWgFNRKHLvM51pwS934C8VZ7d2F4Z58g')) |
---|
253 | 253 | | |
---|
254 | 254 | | let wx_waves_usdtppt = getWxPool(Address(base58'3PPeWowdyQLKwW9AExN5CgFa7X9ts7D4LkM')) |
---|
255 | 255 | | |
---|
256 | 256 | | let wx_waves_usdtwxg = getWxPool(Address(base58'3PKMVZ7kQeaREajYi8Yc25Ro6mcNw5D6QSa')) |
---|
257 | 257 | | |
---|
258 | 258 | | let wx_west_waves = getWxPool(Address(base58'3PCA7wkovBpAGgm5e6rZMXyXY97jUwVENWe')) |
---|
259 | 259 | | |
---|
260 | 260 | | let wx_west_xtn = getWxPool(Address(base58'3PFxchXqKNjgP1CcbgFZjHyrEj9xMbSeLU3')) |
---|
261 | 261 | | |
---|
262 | 262 | | let wx_wx_usdtwxg = getWxPool(Address(base58'3PHiXGo7NTRoC2KqkMZ1y9LaA2QSrroGs8y')) |
---|
263 | 263 | | |
---|
264 | 264 | | let wx_wx_waves = getWxPool(Address(base58'3PFzaH2ghpwANHFgjeva83N1yxzErELx2eh')) |
---|
265 | 265 | | |
---|
266 | 266 | | let wx_wx_xtn = getWxPool(Address(base58'3PCENpEKe8atwELZ7oCSmcdEfcRuKTrUx99')) |
---|
267 | 267 | | |
---|
268 | 268 | | let routes = [$Tuple6(wx_waves_xtn, wx_wx_waves, wx_wx_xtn, true, true, false), $Tuple6(swop_waves_xtn, wx_wx_waves, swop_wx_xtn, true, true, false), $Tuple6(wx_wx_xtn, wx_wx_waves, swop_waves_xtn, true, false, false), $Tuple6(wx_wx_xtn, wx_wx_waves, wx_waves_xtn, true, false, false), $Tuple6(swop_surf_xtn, wx_surf_waves, swop_waves_xtn, true, false, false), $Tuple6(wx_vires_xtn, wx_vires_waves, swop_waves_xtn, true, false, false), $Tuple6(wx_waves_xtn, wx_vires_waves, swop_vires_xtn, true, true, false), $Tuple6(wx_swaves_xtn, wx_swaves_waves, swop_waves_xtn, true, false, false), $Tuple6(swop_waves_xtn, wx_nsbt_waves, swop_nsbt_xtn, true, true, false), $Tuple6(wx_nsbt_xtn, wx_nsbt_waves, swop_waves_xtn, true, false, false), $Tuple6(swop_waves_xtn, swop_swop_waves, wx_swop_xtn, true, true, false), $Tuple6(swop_swop_xtn, wx_swop_waves, swop_waves_xtn, true, false, false), $Tuple6(wx_puzzle_xtn, wx_puzzle_waves, swop_waves_xtn, true, false, false), $Tuple6(swop_waves_xtn, swop_puzzle_waves, swop_puzzle_xtn, true, true, false), $Tuple6(swop_waves_xtn, wx_pluto_waves, wx_pluto_xtn, true, true, false), $Tuple6(swop_pluto_xtn, wx_pluto_waves, swop_waves_xtn, true, false, false), $Tuple6(swop_xtn_usdtwxg, wx_waves_usdtwxg, swop_waves_xtn, false, true, false), $Tuple6(wx_wx_xtn, wx_wx_usdtwxg, swop_xtn_usdtwxg, true, false, true), $Tuple6(wx_waves_xtn, wx_egg_waves, wx_egg_xtn, true, true, false), $Tuple6(wx_egg_xtn, swop_egg_waves, wx_waves_xtn, true, false, false), $Tuple6(wx_race_xtn, swop_race_egg, wx_egg_xtn, true, false, false), $Tuple6(wx_waves_xtn, wx_ethwxg_waves, swop_ethwxg_xtn, true, true, false), $Tuple6(wx_ethwxg_xtn, wx_ethwxg_waves, wx_waves_xtn, true, false, false), $Tuple6(wx_eurn_xtn, swop_waves_eurn, wx_waves_xtn, true, true, false), $Tuple6(wx_waves_xtn, wx_west_waves, swop_west_xtn, true, true, false), $Tuple6(wx_west_xtn, wx_west_waves, wx_waves_xtn, true, false, false), $Tuple6(wx_waves_xtn, swop_waves_btcwxg, swop_btcwxg_xtn, true, false, false), $Tuple6(wx_waves_xtn, wx_waves_btcwxg, wx_btcwxg_xtn, true, false, false), $Tuple6(swop_pwr_xtn, wx_pwr_waves, wx_waves_xtn, true, false, false), $Tuple6(wx_usdtppt_xtn, swop_waves_usdtppt, wx_waves_xtn, true, true, false), $Tuple6(wx_waves_xtn, wx_waves_usdtppt, wx_usdtppt_xtn, true, false, false), $Tuple6(wx_waves_xtn, wx_ethwxg_waves, wx_ethwxg_xtn, true, true, false), $Tuple6(wx_waves_xtn, wx_west_waves, wx_west_xtn, true, true, false), $Tuple6(wx_btcwxg_xtn, wx_waves_btcwxg, wx_waves_xtn, true, true, false), $Tuple6(wx_waves_xtn, wx_vires_waves, wx_vires_xtn, true, true, false), $Tuple6(wx_waves_xtn, wx_swaves_waves, wx_swaves_xtn, true, true, false), $Tuple6(wx_waves_xtn, wx_nsbt_waves, wx_nsbt_xtn, true, true, false), $Tuple6(wx_nsbt_xtn, wx_nsbt_waves, wx_waves_xtn, true, false, false), $Tuple6(wx_waves_xtn, wx_swop_waves, wx_swop_xtn, true, true, false), $Tuple6(wx_swop_xtn, wx_swop_waves, wx_waves_xtn, true, false, false)] |
---|
269 | 269 | | |
---|
270 | 270 | | @Callable(i) |
---|
271 | 271 | | func default () = if ((i.caller != caller)) |
---|
272 | 272 | | then throw(":D") |
---|
273 | 273 | | else { |
---|
274 | 274 | | func accumFunction (accum,next) = { |
---|
275 | 275 | | let estimation = estimateRoute(next._1, next._2, next._3, next._4, next._5, next._6) |
---|
276 | 276 | | $Tuple2((accum._1 :+ estimation._1), (accum._2 :+ estimation._2)) |
---|
277 | 277 | | } |
---|
278 | 278 | | |
---|
279 | 279 | | let fold = { |
---|
280 | 280 | | let $l = routes |
---|
281 | 281 | | let $s = size($l) |
---|
282 | 282 | | let $acc0 = $Tuple2(nil, nil) |
---|
283 | 283 | | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
284 | 284 | | then $a |
---|
285 | 285 | | else accumFunction($a, $l[$i]) |
---|
286 | 286 | | |
---|
287 | 287 | | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
288 | 288 | | then $a |
---|
289 | 289 | | else throw("List size exceeds 40") |
---|
290 | 290 | | |
---|
291 | 291 | | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20), 21), 22), 23), 24), 25), 26), 27), 28), 29), 30), 31), 32), 33), 34), 35), 36), 37), 38), 39), 40) |
---|
292 | 292 | | } |
---|
293 | 293 | | let maxSwapProfit = max(fold._1) |
---|
294 | 294 | | if ((0 >= maxSwapProfit)) |
---|
295 | 295 | | then throw("Estimate fail") |
---|
296 | 296 | | else { |
---|
297 | 297 | | let estimatedResult = fold._2[value(indexOf(fold._1, maxSwapProfit))] |
---|
298 | 298 | | let result1 = invokeSwap(estimatedResult[0]) |
---|
299 | 299 | | if ((result1 == result1)) |
---|
300 | 300 | | then { |
---|
301 | 301 | | let result2 = invokeSwap(estimatedResult[1]) |
---|
302 | 302 | | if ((result2 == result2)) |
---|
303 | 303 | | then { |
---|
304 | 304 | | let result3 = invokeSwap(estimatedResult[2]) |
---|
305 | 305 | | if ((result3 == result3)) |
---|
306 | 306 | | then { |
---|
307 | 307 | | let profit = (getBalance(InAsset) - inBalance) |
---|
308 | 308 | | let pureProfit = if (((i.fee % 10) > 0)) |
---|