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:AAIFAAAAAAAAAA0IAhIJCgcYGBERGAIBAAAACwAAAAAHZGlnaXRzOAAAAAAAAAAACAAAAAAGc2NhbGU4AAAAAAAF9eEAAAAAAAdzY2FsZTEyAAAAAOjUpRAAAAAAAAVhbHBoYQAAAAAAAAAAMgAAAAALYWxwaGFEaWdpdHMAAAAAAAAAAAIAAAAABGJldGEAAAAAAAK954AAAAAACmNvbW1pc3Npb24AAAAAAAAAC7gAAAAAGGNvbW1pc3Npb25TY2FsZURlbGltaXRlcgAAAAAAAA9CQAEAAAAIc2tld25lc3MAAAACAAAAAXgAAAABeQkAAGkAAAACCQAAaQAAAAIJAABkAAAAAgkAAGsAAAADBQAAAAdzY2FsZTEyBQAAAAF4BQAAAAF5CQAAawAAAAMFAAAAB3NjYWxlMTIFAAAAAXkFAAAAAXgAAAAAAAAAAAIAAAAAAAAAJxABAAAADWludmFyaWFudENhbGMAAAACAAAAAXgAAAABeQQAAAACc2sJAQAAAAhza2V3bmVzcwAAAAIFAAAAAXgFAAAAAXkJAABkAAAAAgkAAGsAAAADCQAAZAAAAAIFAAAAAXgFAAAAAXkFAAA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vUmVjaWV2ZSA8IG1pbkFtb3VudFRvUmVjZWl2ZQAAAACnlCU2", "height": 1705515, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6Fs8rzUuoHKgpMcMxR6uxFxNXzdSQ8fr9Y28V6UgPTkc Next: 2xmHXGqXj3Gjwu8aYgDJDWVua3bAetd3yvw97jNAJZfn Diff:
OldNewDifferences
3131 let dApp1TokenGet = getIntegerValue(addressFromStringValue(exchangers[0]), routingAssetsKeys[1])
3232 let dApp2TokenPay = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[2])
3333 let dApp2TokenGet = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[3])
34- let getFrom1TradeWithFee = if ((exchangersType[0] == "cpmm"))
34+ let getFrom1TradeWithFee = if ((exchangersType[0] == "flat"))
3535 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")
3842 }
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")
4944 let getFrom2TradeWithFee = if ((exchangersType[1] == "cpmm"))
5045 then {
51- let getFrom2Trade = fraction(dApp2TokenGet, getFrom1TradeWithFee, (getFrom1TradeWithFee + dApp2TokenPay))
52- fraction(getFrom2Trade, (commissionScaleDelimiter - commission), commissionScaleDelimiter)
46+ let getFrom2TradeWithoutFee = fraction(dApp2TokenGet, getFrom1TradeWithFee, (getFrom1TradeWithFee + dApp2TokenPay))
47+ fraction(getFrom2TradeWithoutFee, (commissionScaleDelimiter - commission), commissionScaleDelimiter)
5348 }
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)
6751 }
6852
6953
7054 @Callable(i)
7155 func routingTrade (exchangers,exchangersType,args1,args2,routingAssetsKeys,receiveAssetId,minAmountToReceive) = {
72- let $t041774251 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
73- let pmtAmount = $t041774251._1
74- let pmtAssetId = $t041774251._2
56+ let $t046454719 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
57+ let pmtAmount = $t046454719._1
58+ let pmtAssetId = $t046454719._2
7559 if (!(checkPossibilty(pmtAmount, minAmountToReceive, exchangers, exchangersType, routingAssetsKeys, args1, args2)))
7660 then throw("Check transaction possibilty: declined")
7761 else {
7862 let routingSize = size(exchangers)
7963 func exchangeFold (accumulated,exchanger) = {
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))
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))
8569 then $Tuple2(pmtAssetId, pmtAmount)
8670 else $Tuple2(assetsIdSend, amountsWithFee)
87- let pmtAssetIdRout = $t046224745._1
88- let pmtAmountRout = $t046224745._2
71+ let pmtAssetIdRout = $t050905213._1
72+ let pmtAmountRout = $t050905213._2
8973 if (((if ((exchangeCounter >= 0))
9074 then (routingSize > exchangeCounter)
9175 else false) == true))
9983 if ((inv == inv))
10084 then match inv {
10185 case inv: (Int, ByteVector) =>
102- let $t055145552 = inv
103- let amountWithFee = $t055145552._1
104- let assetIdSend = $t055145552._2
86+ let $t059826020 = inv
87+ let amountWithFee = $t059826020._1
88+ let assetIdSend = $t059826020._2
10589 $Tuple3((exchangeCounter + 1), amountWithFee, assetIdSend)
10690 case _ =>
10791 throw("Incorrect invoke result: expected amountWithFee and assetsIdSend")
11195 else accumulated
11296 }
11397
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
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
120104 else {
121- let $acc158545903 = exchangeFold($acc058545903, $list58545903[0])
122- if (($size58545903 == 1))
123- then $acc158545903
105+ let $acc163226371 = exchangeFold($acc063226371, $list63226371[0])
106+ if (($size63226371 == 1))
107+ then $acc163226371
124108 else {
125- let $acc258545903 = exchangeFold($acc158545903, $list58545903[1])
126- if (($size58545903 == 2))
127- then $acc258545903
109+ let $acc263226371 = exchangeFold($acc163226371, $list63226371[1])
110+ if (($size63226371 == 2))
111+ then $acc263226371
128112 else {
129- let $acc358545903 = exchangeFold($acc258545903, $list58545903[2])
130- if (($size58545903 == 3))
131- then $acc358545903
113+ let $acc363226371 = exchangeFold($acc263226371, $list63226371[2])
114+ if (($size63226371 == 3))
115+ then $acc363226371
132116 else {
133- let $acc458545903 = exchangeFold($acc358545903, $list58545903[3])
117+ let $acc463226371 = exchangeFold($acc363226371, $list63226371[3])
134118 throw("List size exceed 3")
135119 }
136120 }
137121 }
138122 }
139123 }
140- let exchangeCounter = $t058025903._1
141- let amountsWithFee = $t058025903._2
142- let assetsIdSend = $t058025903._3
124+ let exchangeCounter = $t062706371._1
125+ let amountsWithFee = $t062706371._2
126+ let assetsIdSend = $t062706371._3
143127 let amountToRecieve = assetBalance(this, receiveAssetId)
144128 if (if ((exchangeCounter == routingSize))
145129 then (amountToRecieve >= minAmountToReceive)
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let digits8 = 8
55
66 let scale8 = 100000000
77
88 let scale12 = 1000000000000
99
1010 let alpha = 50
1111
1212 let alphaDigits = 2
1313
1414 let beta = 46000000
1515
1616 let commission = 3000
1717
1818 let commissionScaleDelimiter = 1000000
1919
2020 func skewness (x,y) = (((fraction(scale12, x, y) + fraction(scale12, y, x)) / 2) / 10000)
2121
2222
2323 func invariantCalc (x,y) = {
2424 let sk = skewness(x, y)
2525 (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)))
2626 }
2727
2828
2929 func checkPossibilty (pmtAmount,minAmountToReceive,exchangers,exchangersType,routingAssetsKeys,args1,args2) = {
3030 let dApp1TokenPay = getIntegerValue(addressFromStringValue(exchangers[0]), routingAssetsKeys[0])
3131 let dApp1TokenGet = getIntegerValue(addressFromStringValue(exchangers[0]), routingAssetsKeys[1])
3232 let dApp2TokenPay = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[2])
3333 let dApp2TokenGet = getIntegerValue(addressFromStringValue(exchangers[1]), routingAssetsKeys[3])
34- let getFrom1TradeWithFee = if ((exchangersType[0] == "cpmm"))
34+ let getFrom1TradeWithFee = if ((exchangersType[0] == "flat"))
3535 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")
3842 }
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")
4944 let getFrom2TradeWithFee = if ((exchangersType[1] == "cpmm"))
5045 then {
51- let getFrom2Trade = fraction(dApp2TokenGet, getFrom1TradeWithFee, (getFrom1TradeWithFee + dApp2TokenPay))
52- fraction(getFrom2Trade, (commissionScaleDelimiter - commission), commissionScaleDelimiter)
46+ let getFrom2TradeWithoutFee = fraction(dApp2TokenGet, getFrom1TradeWithFee, (getFrom1TradeWithFee + dApp2TokenPay))
47+ fraction(getFrom2TradeWithoutFee, (commissionScaleDelimiter - commission), commissionScaleDelimiter)
5348 }
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)
6751 }
6852
6953
7054 @Callable(i)
7155 func routingTrade (exchangers,exchangersType,args1,args2,routingAssetsKeys,receiveAssetId,minAmountToReceive) = {
72- let $t041774251 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
73- let pmtAmount = $t041774251._1
74- let pmtAssetId = $t041774251._2
56+ let $t046454719 = $Tuple2(i.payments[0].amount, i.payments[0].assetId)
57+ let pmtAmount = $t046454719._1
58+ let pmtAssetId = $t046454719._2
7559 if (!(checkPossibilty(pmtAmount, minAmountToReceive, exchangers, exchangersType, routingAssetsKeys, args1, args2)))
7660 then throw("Check transaction possibilty: declined")
7761 else {
7862 let routingSize = size(exchangers)
7963 func exchangeFold (accumulated,exchanger) = {
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))
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))
8569 then $Tuple2(pmtAssetId, pmtAmount)
8670 else $Tuple2(assetsIdSend, amountsWithFee)
87- let pmtAssetIdRout = $t046224745._1
88- let pmtAmountRout = $t046224745._2
71+ let pmtAssetIdRout = $t050905213._1
72+ let pmtAmountRout = $t050905213._2
8973 if (((if ((exchangeCounter >= 0))
9074 then (routingSize > exchangeCounter)
9175 else false) == true))
9276 then {
9377 let exchangerAddress = addressFromStringValue(exchanger)
9478 let inv = if ((exchangersType[exchangeCounter] == "cpmm"))
9579 then invoke(exchangerAddress, "exchange", [args1[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)])
9680 else if ((exchangersType[exchangeCounter] == "flat"))
9781 then invoke(exchangerAddress, "exchange", [args1[exchangeCounter], args2[exchangeCounter]], [AttachedPayment(pmtAssetIdRout, pmtAmountRout)])
9882 else throw("Incorrect exchange type")
9983 if ((inv == inv))
10084 then match inv {
10185 case inv: (Int, ByteVector) =>
102- let $t055145552 = inv
103- let amountWithFee = $t055145552._1
104- let assetIdSend = $t055145552._2
86+ let $t059826020 = inv
87+ let amountWithFee = $t059826020._1
88+ let assetIdSend = $t059826020._2
10589 $Tuple3((exchangeCounter + 1), amountWithFee, assetIdSend)
10690 case _ =>
10791 throw("Incorrect invoke result: expected amountWithFee and assetsIdSend")
10892 }
10993 else throw("Strict value is not equal to itself.")
11094 }
11195 else accumulated
11296 }
11397
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
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
120104 else {
121- let $acc158545903 = exchangeFold($acc058545903, $list58545903[0])
122- if (($size58545903 == 1))
123- then $acc158545903
105+ let $acc163226371 = exchangeFold($acc063226371, $list63226371[0])
106+ if (($size63226371 == 1))
107+ then $acc163226371
124108 else {
125- let $acc258545903 = exchangeFold($acc158545903, $list58545903[1])
126- if (($size58545903 == 2))
127- then $acc258545903
109+ let $acc263226371 = exchangeFold($acc163226371, $list63226371[1])
110+ if (($size63226371 == 2))
111+ then $acc263226371
128112 else {
129- let $acc358545903 = exchangeFold($acc258545903, $list58545903[2])
130- if (($size58545903 == 3))
131- then $acc358545903
113+ let $acc363226371 = exchangeFold($acc263226371, $list63226371[2])
114+ if (($size63226371 == 3))
115+ then $acc363226371
132116 else {
133- let $acc458545903 = exchangeFold($acc358545903, $list58545903[3])
117+ let $acc463226371 = exchangeFold($acc363226371, $list63226371[3])
134118 throw("List size exceed 3")
135119 }
136120 }
137121 }
138122 }
139123 }
140- let exchangeCounter = $t058025903._1
141- let amountsWithFee = $t058025903._2
142- let assetsIdSend = $t058025903._3
124+ let exchangeCounter = $t062706371._1
125+ let amountsWithFee = $t062706371._2
126+ let assetsIdSend = $t062706371._3
143127 let amountToRecieve = assetBalance(this, receiveAssetId)
144128 if (if ((exchangeCounter == routingSize))
145129 then (amountToRecieve >= minAmountToReceive)
146130 else false)
147131 then [ScriptTransfer(i.caller, amountToRecieve, receiveAssetId)]
148132 else throw("routing != routingSize or amountToRecieve < minAmountToReceive")
149133 }
150134 }
151135
152136

github/deemru/w8io/026f985 
42.62 ms