tx · 6Fs8rzUuoHKgpMcMxR6uxFxNXzdSQ8fr9Y28V6UgPTkc 3N6qtbZbSPVcvJ1pk87e9ahdsZTjHN8e5mL: -0.01000000 Waves 2021.09.12 20:18 [1700124] smart account 3N6qtbZbSPVcvJ1pk87e9ahdsZTjHN8e5mL > SELF 0.00000000 Waves
{ "type": 13, "id": "6Fs8rzUuoHKgpMcMxR6uxFxNXzdSQ8fr9Y28V6UgPTkc", "fee": 1000000, "feeAssetId": null, "timestamp": 1631467137699, "version": 2, "chainId": 84, "sender": "3N6qtbZbSPVcvJ1pk87e9ahdsZTjHN8e5mL", "senderPublicKey": "EYAKsFBespqQveBrfmX29rsehBJrSwQ3B6yN4ADyw8Kx", "proofs": [ "62m96gY6HZHoETdECaSqdSkvUec3tx22XZD1uwMZZrQtQDZEfibKoTxi4dwLYDrbW1CmtqddTojnfoNccoWfaTUX" ], "script": "base64:AAIFAAAAAAAAAA0IAhIJCgcYGBERGAIBAAAACwAAAAAHZGlnaXRzOAAAAAAAAAAACAAAAAAGc2NhbGU4AAAAAAAF9eEAAAAAAAdzY2FsZTEyAAAAAOjUpRAAAAAAAAVhbHBoYQAAAAAAAAAAMgAAAAALYWxwaGFEaWdpdHMAAAAAAAAAAAIAAAAABGJldGEAAAAAAAK954AAAAAACmNvbW1pc3Npb24AAAAAAAAAC7gAAAAAGGNvbW1pc3Npb25TY2FsZURlbGltaXRlcgAAAAAAAA9CQAEAAAAIc2tld25lc3MAAAACAAAAAXgAAAABeQkAAGkAAAACCQAAaQAAAAIJAABkAAAAAgkAAGsAAAADBQAAAAdzY2FsZTEyBQAAAAF4BQAAAAF5CQAAawAAAAMFAAAAB3NjYWxlMTIFAAAAAXkFAAAAAXgAAAAAAAAAAAIAAAAAAAAAJxABAAAADWludmFyaWFudENhbGMAAAACAAAAAXgAAAABeQQAAAACc2sJAQAAAAhza2V3bmVzcwAAAAIFAAAAAXgFAAAAAXkJAABkAAAAAgkAAGsAAAADCQAAZAAAAAIFAAAAAXg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udFRvUmVjaWV2ZQkAA/AAAAACBQAAAAR0aGlzBQAAAA5yZWNlaXZlQXNzZXRJZAMDCQAAAAAAAAIFAAAAD2V4Y2hhbmdlQ291bnRlcgUAAAALcm91dGluZ1NpemUJAABnAAAAAgUAAAAPYW1vdW50VG9SZWNpZXZlBQAAABJtaW5BbW91bnRUb1JlY2VpdmUHCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAAAABmNhbGxlcgUAAAAPYW1vdW50VG9SZWNpZXZlBQAAAA5yZWNlaXZlQXNzZXRJZAUAAAADbmlsCQAAAgAAAAECAAAAPnJvdXRpbmcgIT0gcm91dGluZ1NpemUgb3IgYW1vdW50VG9SZWNpZXZlIDwgbWluQW1vdW50VG9SZWNlaXZlAAAAAK9crnk=", "height": 1700124, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 7X3LFxdPQt1bxd5JsemCmswSPgD2rUyJy6aBmT426SSi Next: 79UEBDqghBiBhmkUSbBN98tYqtzwWgC579ysBhdx5vvH Diff:
Old | New | Differences | |
---|---|---|---|
13 | 13 | ||
14 | 14 | let beta = 46000000 | |
15 | 15 | ||
16 | + | let commission = 3000 | |
17 | + | ||
18 | + | let commissionScaleDelimiter = 1000000 | |
19 | + | ||
16 | 20 | func skewness (x,y) = (((fraction(scale12, x, y) + fraction(scale12, y, x)) / 2) / 10000) | |
17 | 21 | ||
18 | 22 | ||
23 | 27 | ||
24 | 28 | ||
25 | 29 | func checkPossibilty (pmtAmount,minAmountToReceive,exchangers,exchangersType,routingAssetsKeys,args1,args2) = { | |
26 | - | let commission = 3000 | |
27 | - | let commissionScaleDelimiter = 1000000 | |
28 | 30 | let dApp1TokenPay = getIntegerValue(addressFromStringValue(exchangers[0]), routingAssetsKeys[0]) | |
29 | 31 | let dApp1TokenGet = getIntegerValue(addressFromStringValue(exchangers[0]), routingAssetsKeys[1]) | |
30 | 32 | let dApp2TokenPay = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[2]) | |
38 | 40 | then { | |
39 | 41 | let invariant = invariantCalc(dApp1TokenPay, dApp1TokenGet) | |
40 | 42 | let minAmountToReceive1 = args2[0] | |
41 | - | let invariantNew = invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - | |
43 | + | let invariantNew = invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1)) | |
42 | 44 | if ((invariantNew >= invariant)) | |
43 | 45 | then minAmountToReceive1 | |
44 | 46 | else throw("Flat contract: invariantNew < invariant") | |
67 | 69 | ||
68 | 70 | @Callable(i) | |
69 | 71 | func routingTrade (exchangers,exchangersType,args1,args2,routingAssetsKeys,receiveAssetId,minAmountToReceive) = { | |
70 | - | let $ | |
71 | - | let pmtAmount = $ | |
72 | - | let pmtAssetId = $ | |
72 | + | let $t041774251 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
73 | + | let pmtAmount = $t041774251._1 | |
74 | + | let pmtAssetId = $t041774251._2 | |
73 | 75 | if (!(checkPossibilty(pmtAmount, minAmountToReceive, exchangers, exchangersType, routingAssetsKeys, args1, args2))) | |
74 | 76 | then throw("Check transaction possibilty: declined") | |
75 | 77 | else { | |
76 | 78 | let routingSize = size(exchangers) | |
77 | 79 | func exchangeFold (accumulated,exchanger) = { | |
78 | - | let $t041214184 = accumulated | |
79 | - | let exchangeCounter = $t041214184._1 | |
80 | - | let amountsWithFee = $t041214184._2 | |
81 | - | let assetsIdSend = $t041214184._3 | |
82 | - | if ((exchangeCounter == 0)) | |
80 | + | let $t045504613 = accumulated | |
81 | + | let exchangeCounter = $t045504613._1 | |
82 | + | let amountsWithFee = $t045504613._2 | |
83 | + | let assetsIdSend = $t045504613._3 | |
84 | + | let $t046224745 = if ((exchangeCounter == 0)) | |
85 | + | then $Tuple2(pmtAssetId, pmtAmount) | |
86 | + | else $Tuple2(assetsIdSend, amountsWithFee) | |
87 | + | let pmtAssetIdRout = $t046224745._1 | |
88 | + | let pmtAmountRout = $t046224745._2 | |
89 | + | if (((if ((exchangeCounter >= 0)) | |
90 | + | then (routingSize > exchangeCounter) | |
91 | + | else false) == true)) | |
83 | 92 | then { | |
84 | 93 | let exchangerAddress = addressFromStringValue(exchanger) | |
85 | 94 | let inv = if ((exchangersType[exchangeCounter] == "cpmm")) | |
86 | - | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter]], [AttachedPayment( | |
95 | + | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)]) | |
87 | 96 | else if ((exchangersType[exchangeCounter] == "flat")) | |
88 | - | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter], args2[exchangeCounter]], [AttachedPayment( | |
97 | + | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter], args2[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)]) | |
89 | 98 | else throw("Incorrect exchange type") | |
90 | 99 | if ((inv == inv)) | |
91 | 100 | then match inv { | |
92 | 101 | case inv: (Int, ByteVector) => | |
93 | - | let $ | |
94 | - | let amountWithFee = $ | |
95 | - | let assetIdSend = $ | |
102 | + | let $t055145552 = inv | |
103 | + | let amountWithFee = $t055145552._1 | |
104 | + | let assetIdSend = $t055145552._2 | |
96 | 105 | $Tuple3((exchangeCounter + 1), amountWithFee, assetIdSend) | |
97 | 106 | case _ => | |
98 | 107 | throw("Incorrect invoke result: expected amountWithFee and assetsIdSend") | |
99 | 108 | } | |
100 | 109 | else throw("Strict value is not equal to itself.") | |
101 | 110 | } | |
102 | - | else if (if ((exchangeCounter > 0)) | |
103 | - | then (routingSize > exchangeCounter) | |
104 | - | else false) | |
105 | - | then { | |
106 | - | let exchangerAddress = addressFromStringValue(exchanger) | |
107 | - | let $t052645330 = $Tuple2(assetsIdSend, amountsWithFee) | |
108 | - | let pmtAssetIdRout = $t052645330._1 | |
109 | - | let pmtAmountRout = $t052645330._2 | |
110 | - | let inv = if ((exchangersType[exchangeCounter] == "cpmm")) | |
111 | - | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)]) | |
112 | - | else if ((exchangersType[exchangeCounter] == "flat")) | |
113 | - | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter], args2[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)]) | |
114 | - | else throw("Incorrect exchange type") | |
115 | - | if ((inv == inv)) | |
116 | - | then match inv { | |
117 | - | case inv: (Int, ByteVector) => | |
118 | - | let $t059355973 = inv | |
119 | - | let amountWithFee = $t059355973._1 | |
120 | - | let assetIdSend = $t059355973._2 | |
121 | - | $Tuple3((exchangeCounter + 1), amountWithFee, assetIdSend) | |
122 | - | case _ => | |
123 | - | throw("Incorrect invoke result: expected amountWithFee and assetsIdSend") | |
124 | - | } | |
125 | - | else throw("Strict value is not equal to itself.") | |
126 | - | } | |
127 | - | else accumulated | |
111 | + | else accumulated | |
128 | 112 | } | |
129 | 113 | ||
130 | - | let $ | |
131 | - | let $ | |
132 | - | let $ | |
133 | - | let $ | |
134 | - | if (($ | |
135 | - | then $ | |
114 | + | let $t058025903 = { | |
115 | + | let $list58545903 = exchangers | |
116 | + | let $size58545903 = size($list58545903) | |
117 | + | let $acc058545903 = $Tuple3(0, 0, base58'') | |
118 | + | if (($size58545903 == 0)) | |
119 | + | then $acc058545903 | |
136 | 120 | else { | |
137 | - | let $ | |
138 | - | if (($ | |
139 | - | then $ | |
121 | + | let $acc158545903 = exchangeFold($acc058545903, $list58545903[0]) | |
122 | + | if (($size58545903 == 1)) | |
123 | + | then $acc158545903 | |
140 | 124 | else { | |
141 | - | let $ | |
142 | - | if (($ | |
143 | - | then $ | |
125 | + | let $acc258545903 = exchangeFold($acc158545903, $list58545903[1]) | |
126 | + | if (($size58545903 == 2)) | |
127 | + | then $acc258545903 | |
144 | 128 | else { | |
145 | - | let $ | |
146 | - | if (($ | |
147 | - | then $ | |
129 | + | let $acc358545903 = exchangeFold($acc258545903, $list58545903[2]) | |
130 | + | if (($size58545903 == 3)) | |
131 | + | then $acc358545903 | |
148 | 132 | else { | |
149 | - | let $ | |
133 | + | let $acc458545903 = exchangeFold($acc358545903, $list58545903[3]) | |
150 | 134 | throw("List size exceed 3") | |
151 | 135 | } | |
152 | 136 | } | |
153 | 137 | } | |
154 | 138 | } | |
155 | 139 | } | |
156 | - | let exchangeCounter = $ | |
157 | - | let amountsWithFee = $ | |
158 | - | let assetsIdSend = $ | |
140 | + | let exchangeCounter = $t058025903._1 | |
141 | + | let amountsWithFee = $t058025903._2 | |
142 | + | let assetsIdSend = $t058025903._3 | |
159 | 143 | let amountToRecieve = assetBalance(this, receiveAssetId) | |
160 | 144 | if (if ((exchangeCounter == routingSize)) | |
161 | 145 | then (amountToRecieve >= minAmountToReceive) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let digits8 = 8 | |
5 | 5 | ||
6 | 6 | let scale8 = 100000000 | |
7 | 7 | ||
8 | 8 | let scale12 = 1000000000000 | |
9 | 9 | ||
10 | 10 | let alpha = 50 | |
11 | 11 | ||
12 | 12 | let alphaDigits = 2 | |
13 | 13 | ||
14 | 14 | let beta = 46000000 | |
15 | 15 | ||
16 | + | let commission = 3000 | |
17 | + | ||
18 | + | let commissionScaleDelimiter = 1000000 | |
19 | + | ||
16 | 20 | func skewness (x,y) = (((fraction(scale12, x, y) + fraction(scale12, y, x)) / 2) / 10000) | |
17 | 21 | ||
18 | 22 | ||
19 | 23 | func invariantCalc (x,y) = { | |
20 | 24 | let sk = skewness(x, y) | |
21 | 25 | (fraction((x + y), scale8, pow(sk, digits8, alpha, alphaDigits, digits8, CEILING)) + (2 * fraction(pow(fraction(x, y, scale8), 0, 5, 1, (digits8 / 2), DOWN), pow((sk - beta), digits8, alpha, alphaDigits, digits8, DOWN), scale8))) | |
22 | 26 | } | |
23 | 27 | ||
24 | 28 | ||
25 | 29 | func checkPossibilty (pmtAmount,minAmountToReceive,exchangers,exchangersType,routingAssetsKeys,args1,args2) = { | |
26 | - | let commission = 3000 | |
27 | - | let commissionScaleDelimiter = 1000000 | |
28 | 30 | let dApp1TokenPay = getIntegerValue(addressFromStringValue(exchangers[0]), routingAssetsKeys[0]) | |
29 | 31 | let dApp1TokenGet = getIntegerValue(addressFromStringValue(exchangers[0]), routingAssetsKeys[1]) | |
30 | 32 | let dApp2TokenPay = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[2]) | |
31 | 33 | let dApp2TokenGet = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[3]) | |
32 | 34 | let getFrom1TradeWithFee = if ((exchangersType[0] == "cpmm")) | |
33 | 35 | then { | |
34 | 36 | let getFrom1Trade = fraction(dApp1TokenGet, pmtAmount, (pmtAmount + dApp1TokenPay)) | |
35 | 37 | fraction(getFrom1Trade, (commissionScaleDelimiter - commission), commissionScaleDelimiter) | |
36 | 38 | } | |
37 | 39 | else if ((exchangersType[0] == "flat")) | |
38 | 40 | then { | |
39 | 41 | let invariant = invariantCalc(dApp1TokenPay, dApp1TokenGet) | |
40 | 42 | let minAmountToReceive1 = args2[0] | |
41 | - | let invariantNew = invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - | |
43 | + | let invariantNew = invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1)) | |
42 | 44 | if ((invariantNew >= invariant)) | |
43 | 45 | then minAmountToReceive1 | |
44 | 46 | else throw("Flat contract: invariantNew < invariant") | |
45 | 47 | } | |
46 | 48 | else throw("Incorrect exchange type") | |
47 | 49 | let getFrom2TradeWithFee = if ((exchangersType[1] == "cpmm")) | |
48 | 50 | then { | |
49 | 51 | let getFrom2Trade = fraction(dApp2TokenGet, getFrom1TradeWithFee, (getFrom1TradeWithFee + dApp2TokenPay)) | |
50 | 52 | fraction(getFrom2Trade, (commissionScaleDelimiter - commission), commissionScaleDelimiter) | |
51 | 53 | } | |
52 | 54 | else if ((exchangersType[1] == "flat")) | |
53 | 55 | then { | |
54 | 56 | let invariant = invariantCalc(dApp2TokenPay, dApp2TokenGet) | |
55 | 57 | let minAmountToReceive2 = args2[1] | |
56 | 58 | let invariantNew = invariantCalc((dApp2TokenPay + getFrom1TradeWithFee), (dApp2TokenGet - minAmountToReceive2)) | |
57 | 59 | if ((invariantNew >= invariant)) | |
58 | 60 | then minAmountToReceive2 | |
59 | 61 | else throw("Flat contract: invariantNew < invariant") | |
60 | 62 | } | |
61 | 63 | else throw("Incorrect exchange type") | |
62 | 64 | if ((getFrom2TradeWithFee >= minAmountToReceive)) | |
63 | 65 | then true | |
64 | 66 | else false | |
65 | 67 | } | |
66 | 68 | ||
67 | 69 | ||
68 | 70 | @Callable(i) | |
69 | 71 | func routingTrade (exchangers,exchangersType,args1,args2,routingAssetsKeys,receiveAssetId,minAmountToReceive) = { | |
70 | - | let $ | |
71 | - | let pmtAmount = $ | |
72 | - | let pmtAssetId = $ | |
72 | + | let $t041774251 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
73 | + | let pmtAmount = $t041774251._1 | |
74 | + | let pmtAssetId = $t041774251._2 | |
73 | 75 | if (!(checkPossibilty(pmtAmount, minAmountToReceive, exchangers, exchangersType, routingAssetsKeys, args1, args2))) | |
74 | 76 | then throw("Check transaction possibilty: declined") | |
75 | 77 | else { | |
76 | 78 | let routingSize = size(exchangers) | |
77 | 79 | func exchangeFold (accumulated,exchanger) = { | |
78 | - | let $t041214184 = accumulated | |
79 | - | let exchangeCounter = $t041214184._1 | |
80 | - | let amountsWithFee = $t041214184._2 | |
81 | - | let assetsIdSend = $t041214184._3 | |
82 | - | if ((exchangeCounter == 0)) | |
80 | + | let $t045504613 = accumulated | |
81 | + | let exchangeCounter = $t045504613._1 | |
82 | + | let amountsWithFee = $t045504613._2 | |
83 | + | let assetsIdSend = $t045504613._3 | |
84 | + | let $t046224745 = if ((exchangeCounter == 0)) | |
85 | + | then $Tuple2(pmtAssetId, pmtAmount) | |
86 | + | else $Tuple2(assetsIdSend, amountsWithFee) | |
87 | + | let pmtAssetIdRout = $t046224745._1 | |
88 | + | let pmtAmountRout = $t046224745._2 | |
89 | + | if (((if ((exchangeCounter >= 0)) | |
90 | + | then (routingSize > exchangeCounter) | |
91 | + | else false) == true)) | |
83 | 92 | then { | |
84 | 93 | let exchangerAddress = addressFromStringValue(exchanger) | |
85 | 94 | let inv = if ((exchangersType[exchangeCounter] == "cpmm")) | |
86 | - | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter]], [AttachedPayment( | |
95 | + | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)]) | |
87 | 96 | else if ((exchangersType[exchangeCounter] == "flat")) | |
88 | - | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter], args2[exchangeCounter]], [AttachedPayment( | |
97 | + | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter], args2[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)]) | |
89 | 98 | else throw("Incorrect exchange type") | |
90 | 99 | if ((inv == inv)) | |
91 | 100 | then match inv { | |
92 | 101 | case inv: (Int, ByteVector) => | |
93 | - | let $ | |
94 | - | let amountWithFee = $ | |
95 | - | let assetIdSend = $ | |
102 | + | let $t055145552 = inv | |
103 | + | let amountWithFee = $t055145552._1 | |
104 | + | let assetIdSend = $t055145552._2 | |
96 | 105 | $Tuple3((exchangeCounter + 1), amountWithFee, assetIdSend) | |
97 | 106 | case _ => | |
98 | 107 | throw("Incorrect invoke result: expected amountWithFee and assetsIdSend") | |
99 | 108 | } | |
100 | 109 | else throw("Strict value is not equal to itself.") | |
101 | 110 | } | |
102 | - | else if (if ((exchangeCounter > 0)) | |
103 | - | then (routingSize > exchangeCounter) | |
104 | - | else false) | |
105 | - | then { | |
106 | - | let exchangerAddress = addressFromStringValue(exchanger) | |
107 | - | let $t052645330 = $Tuple2(assetsIdSend, amountsWithFee) | |
108 | - | let pmtAssetIdRout = $t052645330._1 | |
109 | - | let pmtAmountRout = $t052645330._2 | |
110 | - | let inv = if ((exchangersType[exchangeCounter] == "cpmm")) | |
111 | - | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)]) | |
112 | - | else if ((exchangersType[exchangeCounter] == "flat")) | |
113 | - | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter], args2[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)]) | |
114 | - | else throw("Incorrect exchange type") | |
115 | - | if ((inv == inv)) | |
116 | - | then match inv { | |
117 | - | case inv: (Int, ByteVector) => | |
118 | - | let $t059355973 = inv | |
119 | - | let amountWithFee = $t059355973._1 | |
120 | - | let assetIdSend = $t059355973._2 | |
121 | - | $Tuple3((exchangeCounter + 1), amountWithFee, assetIdSend) | |
122 | - | case _ => | |
123 | - | throw("Incorrect invoke result: expected amountWithFee and assetsIdSend") | |
124 | - | } | |
125 | - | else throw("Strict value is not equal to itself.") | |
126 | - | } | |
127 | - | else accumulated | |
111 | + | else accumulated | |
128 | 112 | } | |
129 | 113 | ||
130 | - | let $ | |
131 | - | let $ | |
132 | - | let $ | |
133 | - | let $ | |
134 | - | if (($ | |
135 | - | then $ | |
114 | + | let $t058025903 = { | |
115 | + | let $list58545903 = exchangers | |
116 | + | let $size58545903 = size($list58545903) | |
117 | + | let $acc058545903 = $Tuple3(0, 0, base58'') | |
118 | + | if (($size58545903 == 0)) | |
119 | + | then $acc058545903 | |
136 | 120 | else { | |
137 | - | let $ | |
138 | - | if (($ | |
139 | - | then $ | |
121 | + | let $acc158545903 = exchangeFold($acc058545903, $list58545903[0]) | |
122 | + | if (($size58545903 == 1)) | |
123 | + | then $acc158545903 | |
140 | 124 | else { | |
141 | - | let $ | |
142 | - | if (($ | |
143 | - | then $ | |
125 | + | let $acc258545903 = exchangeFold($acc158545903, $list58545903[1]) | |
126 | + | if (($size58545903 == 2)) | |
127 | + | then $acc258545903 | |
144 | 128 | else { | |
145 | - | let $ | |
146 | - | if (($ | |
147 | - | then $ | |
129 | + | let $acc358545903 = exchangeFold($acc258545903, $list58545903[2]) | |
130 | + | if (($size58545903 == 3)) | |
131 | + | then $acc358545903 | |
148 | 132 | else { | |
149 | - | let $ | |
133 | + | let $acc458545903 = exchangeFold($acc358545903, $list58545903[3]) | |
150 | 134 | throw("List size exceed 3") | |
151 | 135 | } | |
152 | 136 | } | |
153 | 137 | } | |
154 | 138 | } | |
155 | 139 | } | |
156 | - | let exchangeCounter = $ | |
157 | - | let amountsWithFee = $ | |
158 | - | let assetsIdSend = $ | |
140 | + | let exchangeCounter = $t058025903._1 | |
141 | + | let amountsWithFee = $t058025903._2 | |
142 | + | let assetsIdSend = $t058025903._3 | |
159 | 143 | let amountToRecieve = assetBalance(this, receiveAssetId) | |
160 | 144 | if (if ((exchangeCounter == routingSize)) | |
161 | 145 | then (amountToRecieve >= minAmountToReceive) | |
162 | 146 | else false) | |
163 | 147 | then [ScriptTransfer(i.caller, amountToRecieve, receiveAssetId)] | |
164 | 148 | else throw("routing != routingSize or amountToRecieve < minAmountToReceive") | |
165 | 149 | } | |
166 | 150 | } | |
167 | 151 | ||
168 | 152 |
github/deemru/w8io/026f985 55.17 ms ◑