tx · 79UEBDqghBiBhmkUSbBN98tYqtzwWgC579ysBhdx5vvH 3N6qtbZbSPVcvJ1pk87e9ahdsZTjHN8e5mL: -0.01000000 Waves 2021.09.16 13:59 [1705515] smart account 3N6qtbZbSPVcvJ1pk87e9ahdsZTjHN8e5mL > SELF 0.00000000 Waves
{ "type": 13, "id": "79UEBDqghBiBhmkUSbBN98tYqtzwWgC579ysBhdx5vvH", "fee": 1000000, "feeAssetId": null, "timestamp": 1631789962564, "version": 2, "chainId": 84, "sender": "3N6qtbZbSPVcvJ1pk87e9ahdsZTjHN8e5mL", "senderPublicKey": "EYAKsFBespqQveBrfmX29rsehBJrSwQ3B6yN4ADyw8Kx", "proofs": [ "5eUAyfHkd7dxtNLewLubt1dmQSMk8kKL1vPLhAfUC48ad8ULVzNQP8Uy8eggFm1xtxqv2eALtYgaickwogETyXa" ], "script": "base64:AAIFAAAAAAAAAA0IAhIJCgcYGBERGAIBAAAACwAAAAAHZGlnaXRzOAAAAAAAAAAACAAAAAAGc2NhbGU4AAAAAAAF9eEAAAAAAAdzY2FsZTEyAAAAAOjUpRAAAAAAAAVhbHBoYQAAAAAAAAAAMgAAAAALYWxwaGFEaWdpdHMAAAAAAAAAAAIAAAAABGJldGEAAAAAAAK954AAAAAACmNvbW1pc3Npb24AAAAAAAAAC7gAAAAAGGNvbW1pc3Npb25TY2FsZURlbGltaXRlcgAAAAAAAA9CQAEAAAAIc2tld25lc3MAAAACAAAAAXgAAAABeQkAAGkAAAACCQAAaQAAAAIJAABkAAAAAgkAAGsAAAADBQAAAAdzY2FsZTEyBQAAAAF4BQAAAAF5CQAAawAAAAMFAAAAB3NjYWxlMTIFAAAAAXkFAAAAAXgAAAAAAAAAAAIAAAAAAAAAJxABAAAADWludmFyaWFudENhbGMAAAACAAAAAXgAAAABeQQAAAACc2sJAQAAAAhza2V3bmVzcwAAAAIFAAAAAXgFAAAAAXkJAABkAAAAAgkAAGsAAAADCQAAZAAAAAIFAAAAAXgFAAAAAXkFAAAAB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UmVjaWV2ZSA8IG1pbkFtb3VudFRvUmVjZWl2ZQAAAACnlCU2", "height": 1705515, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6Fs8rzUuoHKgpMcMxR6uxFxNXzdSQ8fr9Y28V6UgPTkc Next: 2xmHXGqXj3Gjwu8aYgDJDWVua3bAetd3yvw97jNAJZfn Diff:
Old | New | Differences | |
---|---|---|---|
31 | 31 | let dApp1TokenGet = getIntegerValue(addressFromStringValue(exchangers[0]), routingAssetsKeys[1]) | |
32 | 32 | let dApp2TokenPay = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[2]) | |
33 | 33 | let dApp2TokenGet = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[3]) | |
34 | - | let getFrom1TradeWithFee = if ((exchangersType[0] == " | |
34 | + | let getFrom1TradeWithFee = if ((exchangersType[0] == "flat")) | |
35 | 35 | then { | |
36 | - | let getFrom1Trade = fraction(dApp1TokenGet, pmtAmount, (pmtAmount + dApp1TokenPay)) | |
37 | - | fraction(getFrom1Trade, (commissionScaleDelimiter - commission), commissionScaleDelimiter) | |
36 | + | let invariant = invariantCalc(dApp1TokenPay, dApp1TokenGet) | |
37 | + | let minAmountToReceive1 = args2[0] | |
38 | + | let invariantNew = (((invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1)) + invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1))) + invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1))) + invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1))) | |
39 | + | if ((invariantNew >= invariant)) | |
40 | + | then minAmountToReceive1 | |
41 | + | else throw("Flat contract: invariantNew < invariant") | |
38 | 42 | } | |
39 | - | else if ((exchangersType[0] == "flat")) | |
40 | - | then { | |
41 | - | let invariant = invariantCalc(dApp1TokenPay, dApp1TokenGet) | |
42 | - | let minAmountToReceive1 = args2[0] | |
43 | - | let invariantNew = invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1)) | |
44 | - | if ((invariantNew >= invariant)) | |
45 | - | then minAmountToReceive1 | |
46 | - | else throw("Flat contract: invariantNew < invariant") | |
47 | - | } | |
48 | - | else throw("Incorrect exchange type") | |
43 | + | else throw("Incorrect exchange type") | |
49 | 44 | let getFrom2TradeWithFee = if ((exchangersType[1] == "cpmm")) | |
50 | 45 | then { | |
51 | - | let | |
52 | - | fraction( | |
46 | + | let getFrom2TradeWithoutFee = fraction(dApp2TokenGet, getFrom1TradeWithFee, (getFrom1TradeWithFee + dApp2TokenPay)) | |
47 | + | fraction(getFrom2TradeWithoutFee, (commissionScaleDelimiter - commission), commissionScaleDelimiter) | |
53 | 48 | } | |
54 | - | else if ((exchangersType[1] == "flat")) | |
55 | - | then { | |
56 | - | let invariant = invariantCalc(dApp2TokenPay, dApp2TokenGet) | |
57 | - | let minAmountToReceive2 = args2[1] | |
58 | - | let invariantNew = invariantCalc((dApp2TokenPay + getFrom1TradeWithFee), (dApp2TokenGet - minAmountToReceive2)) | |
59 | - | if ((invariantNew >= invariant)) | |
60 | - | then minAmountToReceive2 | |
61 | - | else throw("Flat contract: invariantNew < invariant") | |
62 | - | } | |
63 | - | else throw("Incorrect exchange type") | |
64 | - | if ((getFrom2TradeWithFee >= minAmountToReceive)) | |
65 | - | then true | |
66 | - | else false | |
49 | + | else throw("Incorrect exchange type") | |
50 | + | (getFrom2TradeWithFee >= minAmountToReceive) | |
67 | 51 | } | |
68 | 52 | ||
69 | 53 | ||
70 | 54 | @Callable(i) | |
71 | 55 | func routingTrade (exchangers,exchangersType,args1,args2,routingAssetsKeys,receiveAssetId,minAmountToReceive) = { | |
72 | - | let $ | |
73 | - | let pmtAmount = $ | |
74 | - | let pmtAssetId = $ | |
56 | + | let $t046454719 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
57 | + | let pmtAmount = $t046454719._1 | |
58 | + | let pmtAssetId = $t046454719._2 | |
75 | 59 | if (!(checkPossibilty(pmtAmount, minAmountToReceive, exchangers, exchangersType, routingAssetsKeys, args1, args2))) | |
76 | 60 | then throw("Check transaction possibilty: declined") | |
77 | 61 | else { | |
78 | 62 | let routingSize = size(exchangers) | |
79 | 63 | func exchangeFold (accumulated,exchanger) = { | |
80 | - | let $ | |
81 | - | let exchangeCounter = $ | |
82 | - | let amountsWithFee = $ | |
83 | - | let assetsIdSend = $ | |
84 | - | let $ | |
64 | + | let $t050185081 = accumulated | |
65 | + | let exchangeCounter = $t050185081._1 | |
66 | + | let amountsWithFee = $t050185081._2 | |
67 | + | let assetsIdSend = $t050185081._3 | |
68 | + | let $t050905213 = if ((exchangeCounter == 0)) | |
85 | 69 | then $Tuple2(pmtAssetId, pmtAmount) | |
86 | 70 | else $Tuple2(assetsIdSend, amountsWithFee) | |
87 | - | let pmtAssetIdRout = $ | |
88 | - | let pmtAmountRout = $ | |
71 | + | let pmtAssetIdRout = $t050905213._1 | |
72 | + | let pmtAmountRout = $t050905213._2 | |
89 | 73 | if (((if ((exchangeCounter >= 0)) | |
90 | 74 | then (routingSize > exchangeCounter) | |
91 | 75 | else false) == true)) | |
99 | 83 | if ((inv == inv)) | |
100 | 84 | then match inv { | |
101 | 85 | case inv: (Int, ByteVector) => | |
102 | - | let $ | |
103 | - | let amountWithFee = $ | |
104 | - | let assetIdSend = $ | |
86 | + | let $t059826020 = inv | |
87 | + | let amountWithFee = $t059826020._1 | |
88 | + | let assetIdSend = $t059826020._2 | |
105 | 89 | $Tuple3((exchangeCounter + 1), amountWithFee, assetIdSend) | |
106 | 90 | case _ => | |
107 | 91 | throw("Incorrect invoke result: expected amountWithFee and assetsIdSend") | |
111 | 95 | else accumulated | |
112 | 96 | } | |
113 | 97 | ||
114 | - | let $ | |
115 | - | let $ | |
116 | - | let $ | |
117 | - | let $ | |
118 | - | if (($ | |
119 | - | then $ | |
98 | + | let $t062706371 = { | |
99 | + | let $list63226371 = exchangers | |
100 | + | let $size63226371 = size($list63226371) | |
101 | + | let $acc063226371 = $Tuple3(0, 0, base58'') | |
102 | + | if (($size63226371 == 0)) | |
103 | + | then $acc063226371 | |
120 | 104 | else { | |
121 | - | let $ | |
122 | - | if (($ | |
123 | - | then $ | |
105 | + | let $acc163226371 = exchangeFold($acc063226371, $list63226371[0]) | |
106 | + | if (($size63226371 == 1)) | |
107 | + | then $acc163226371 | |
124 | 108 | else { | |
125 | - | let $ | |
126 | - | if (($ | |
127 | - | then $ | |
109 | + | let $acc263226371 = exchangeFold($acc163226371, $list63226371[1]) | |
110 | + | if (($size63226371 == 2)) | |
111 | + | then $acc263226371 | |
128 | 112 | else { | |
129 | - | let $ | |
130 | - | if (($ | |
131 | - | then $ | |
113 | + | let $acc363226371 = exchangeFold($acc263226371, $list63226371[2]) | |
114 | + | if (($size63226371 == 3)) | |
115 | + | then $acc363226371 | |
132 | 116 | else { | |
133 | - | let $ | |
117 | + | let $acc463226371 = exchangeFold($acc363226371, $list63226371[3]) | |
134 | 118 | throw("List size exceed 3") | |
135 | 119 | } | |
136 | 120 | } | |
137 | 121 | } | |
138 | 122 | } | |
139 | 123 | } | |
140 | - | let exchangeCounter = $ | |
141 | - | let amountsWithFee = $ | |
142 | - | let assetsIdSend = $ | |
124 | + | let exchangeCounter = $t062706371._1 | |
125 | + | let amountsWithFee = $t062706371._2 | |
126 | + | let assetsIdSend = $t062706371._3 | |
143 | 127 | let amountToRecieve = assetBalance(this, receiveAssetId) | |
144 | 128 | if (if ((exchangeCounter == routingSize)) | |
145 | 129 | 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 | 16 | let commission = 3000 | |
17 | 17 | ||
18 | 18 | let commissionScaleDelimiter = 1000000 | |
19 | 19 | ||
20 | 20 | func skewness (x,y) = (((fraction(scale12, x, y) + fraction(scale12, y, x)) / 2) / 10000) | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | func invariantCalc (x,y) = { | |
24 | 24 | let sk = skewness(x, y) | |
25 | 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))) | |
26 | 26 | } | |
27 | 27 | ||
28 | 28 | ||
29 | 29 | func checkPossibilty (pmtAmount,minAmountToReceive,exchangers,exchangersType,routingAssetsKeys,args1,args2) = { | |
30 | 30 | let dApp1TokenPay = getIntegerValue(addressFromStringValue(exchangers[0]), routingAssetsKeys[0]) | |
31 | 31 | let dApp1TokenGet = getIntegerValue(addressFromStringValue(exchangers[0]), routingAssetsKeys[1]) | |
32 | 32 | let dApp2TokenPay = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[2]) | |
33 | 33 | let dApp2TokenGet = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[3]) | |
34 | - | let getFrom1TradeWithFee = if ((exchangersType[0] == " | |
34 | + | let getFrom1TradeWithFee = if ((exchangersType[0] == "flat")) | |
35 | 35 | then { | |
36 | - | let getFrom1Trade = fraction(dApp1TokenGet, pmtAmount, (pmtAmount + dApp1TokenPay)) | |
37 | - | fraction(getFrom1Trade, (commissionScaleDelimiter - commission), commissionScaleDelimiter) | |
36 | + | let invariant = invariantCalc(dApp1TokenPay, dApp1TokenGet) | |
37 | + | let minAmountToReceive1 = args2[0] | |
38 | + | let invariantNew = (((invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1)) + invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1))) + invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1))) + invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1))) | |
39 | + | if ((invariantNew >= invariant)) | |
40 | + | then minAmountToReceive1 | |
41 | + | else throw("Flat contract: invariantNew < invariant") | |
38 | 42 | } | |
39 | - | else if ((exchangersType[0] == "flat")) | |
40 | - | then { | |
41 | - | let invariant = invariantCalc(dApp1TokenPay, dApp1TokenGet) | |
42 | - | let minAmountToReceive1 = args2[0] | |
43 | - | let invariantNew = invariantCalc((dApp1TokenPay + pmtAmount), (dApp1TokenGet - minAmountToReceive1)) | |
44 | - | if ((invariantNew >= invariant)) | |
45 | - | then minAmountToReceive1 | |
46 | - | else throw("Flat contract: invariantNew < invariant") | |
47 | - | } | |
48 | - | else throw("Incorrect exchange type") | |
43 | + | else throw("Incorrect exchange type") | |
49 | 44 | let getFrom2TradeWithFee = if ((exchangersType[1] == "cpmm")) | |
50 | 45 | then { | |
51 | - | let | |
52 | - | fraction( | |
46 | + | let getFrom2TradeWithoutFee = fraction(dApp2TokenGet, getFrom1TradeWithFee, (getFrom1TradeWithFee + dApp2TokenPay)) | |
47 | + | fraction(getFrom2TradeWithoutFee, (commissionScaleDelimiter - commission), commissionScaleDelimiter) | |
53 | 48 | } | |
54 | - | else if ((exchangersType[1] == "flat")) | |
55 | - | then { | |
56 | - | let invariant = invariantCalc(dApp2TokenPay, dApp2TokenGet) | |
57 | - | let minAmountToReceive2 = args2[1] | |
58 | - | let invariantNew = invariantCalc((dApp2TokenPay + getFrom1TradeWithFee), (dApp2TokenGet - minAmountToReceive2)) | |
59 | - | if ((invariantNew >= invariant)) | |
60 | - | then minAmountToReceive2 | |
61 | - | else throw("Flat contract: invariantNew < invariant") | |
62 | - | } | |
63 | - | else throw("Incorrect exchange type") | |
64 | - | if ((getFrom2TradeWithFee >= minAmountToReceive)) | |
65 | - | then true | |
66 | - | else false | |
49 | + | else throw("Incorrect exchange type") | |
50 | + | (getFrom2TradeWithFee >= minAmountToReceive) | |
67 | 51 | } | |
68 | 52 | ||
69 | 53 | ||
70 | 54 | @Callable(i) | |
71 | 55 | func routingTrade (exchangers,exchangersType,args1,args2,routingAssetsKeys,receiveAssetId,minAmountToReceive) = { | |
72 | - | let $ | |
73 | - | let pmtAmount = $ | |
74 | - | let pmtAssetId = $ | |
56 | + | let $t046454719 = $Tuple2(i.payments[0].amount, i.payments[0].assetId) | |
57 | + | let pmtAmount = $t046454719._1 | |
58 | + | let pmtAssetId = $t046454719._2 | |
75 | 59 | if (!(checkPossibilty(pmtAmount, minAmountToReceive, exchangers, exchangersType, routingAssetsKeys, args1, args2))) | |
76 | 60 | then throw("Check transaction possibilty: declined") | |
77 | 61 | else { | |
78 | 62 | let routingSize = size(exchangers) | |
79 | 63 | func exchangeFold (accumulated,exchanger) = { | |
80 | - | let $ | |
81 | - | let exchangeCounter = $ | |
82 | - | let amountsWithFee = $ | |
83 | - | let assetsIdSend = $ | |
84 | - | let $ | |
64 | + | let $t050185081 = accumulated | |
65 | + | let exchangeCounter = $t050185081._1 | |
66 | + | let amountsWithFee = $t050185081._2 | |
67 | + | let assetsIdSend = $t050185081._3 | |
68 | + | let $t050905213 = if ((exchangeCounter == 0)) | |
85 | 69 | then $Tuple2(pmtAssetId, pmtAmount) | |
86 | 70 | else $Tuple2(assetsIdSend, amountsWithFee) | |
87 | - | let pmtAssetIdRout = $ | |
88 | - | let pmtAmountRout = $ | |
71 | + | let pmtAssetIdRout = $t050905213._1 | |
72 | + | let pmtAmountRout = $t050905213._2 | |
89 | 73 | if (((if ((exchangeCounter >= 0)) | |
90 | 74 | then (routingSize > exchangeCounter) | |
91 | 75 | else false) == true)) | |
92 | 76 | then { | |
93 | 77 | let exchangerAddress = addressFromStringValue(exchanger) | |
94 | 78 | let inv = if ((exchangersType[exchangeCounter] == "cpmm")) | |
95 | 79 | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)]) | |
96 | 80 | else if ((exchangersType[exchangeCounter] == "flat")) | |
97 | 81 | then invoke(exchangerAddress, "exchange", [args1[exchangeCounter], args2[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)]) | |
98 | 82 | else throw("Incorrect exchange type") | |
99 | 83 | if ((inv == inv)) | |
100 | 84 | then match inv { | |
101 | 85 | case inv: (Int, ByteVector) => | |
102 | - | let $ | |
103 | - | let amountWithFee = $ | |
104 | - | let assetIdSend = $ | |
86 | + | let $t059826020 = inv | |
87 | + | let amountWithFee = $t059826020._1 | |
88 | + | let assetIdSend = $t059826020._2 | |
105 | 89 | $Tuple3((exchangeCounter + 1), amountWithFee, assetIdSend) | |
106 | 90 | case _ => | |
107 | 91 | throw("Incorrect invoke result: expected amountWithFee and assetsIdSend") | |
108 | 92 | } | |
109 | 93 | else throw("Strict value is not equal to itself.") | |
110 | 94 | } | |
111 | 95 | else accumulated | |
112 | 96 | } | |
113 | 97 | ||
114 | - | let $ | |
115 | - | let $ | |
116 | - | let $ | |
117 | - | let $ | |
118 | - | if (($ | |
119 | - | then $ | |
98 | + | let $t062706371 = { | |
99 | + | let $list63226371 = exchangers | |
100 | + | let $size63226371 = size($list63226371) | |
101 | + | let $acc063226371 = $Tuple3(0, 0, base58'') | |
102 | + | if (($size63226371 == 0)) | |
103 | + | then $acc063226371 | |
120 | 104 | else { | |
121 | - | let $ | |
122 | - | if (($ | |
123 | - | then $ | |
105 | + | let $acc163226371 = exchangeFold($acc063226371, $list63226371[0]) | |
106 | + | if (($size63226371 == 1)) | |
107 | + | then $acc163226371 | |
124 | 108 | else { | |
125 | - | let $ | |
126 | - | if (($ | |
127 | - | then $ | |
109 | + | let $acc263226371 = exchangeFold($acc163226371, $list63226371[1]) | |
110 | + | if (($size63226371 == 2)) | |
111 | + | then $acc263226371 | |
128 | 112 | else { | |
129 | - | let $ | |
130 | - | if (($ | |
131 | - | then $ | |
113 | + | let $acc363226371 = exchangeFold($acc263226371, $list63226371[2]) | |
114 | + | if (($size63226371 == 3)) | |
115 | + | then $acc363226371 | |
132 | 116 | else { | |
133 | - | let $ | |
117 | + | let $acc463226371 = exchangeFold($acc363226371, $list63226371[3]) | |
134 | 118 | throw("List size exceed 3") | |
135 | 119 | } | |
136 | 120 | } | |
137 | 121 | } | |
138 | 122 | } | |
139 | 123 | } | |
140 | - | let exchangeCounter = $ | |
141 | - | let amountsWithFee = $ | |
142 | - | let assetsIdSend = $ | |
124 | + | let exchangeCounter = $t062706371._1 | |
125 | + | let amountsWithFee = $t062706371._2 | |
126 | + | let assetsIdSend = $t062706371._3 | |
143 | 127 | let amountToRecieve = assetBalance(this, receiveAssetId) | |
144 | 128 | if (if ((exchangeCounter == routingSize)) | |
145 | 129 | then (amountToRecieve >= minAmountToReceive) | |
146 | 130 | else false) | |
147 | 131 | then [ScriptTransfer(i.caller, amountToRecieve, receiveAssetId)] | |
148 | 132 | else throw("routing != routingSize or amountToRecieve < minAmountToReceive") | |
149 | 133 | } | |
150 | 134 | } | |
151 | 135 | ||
152 | 136 |
github/deemru/w8io/026f985 42.62 ms ◑