tx · Ca66mpEXSrbvRDtuvEMVGJ2SQ3GRfcrBy7rJXboDTjtS

3N11gzZic4yASFhatzjC8zvLnpNhDo2B1Rv:  -0.01000000 Waves

2023.10.07 15:53 [2788236] smart account 3N11gzZic4yASFhatzjC8zvLnpNhDo2B1Rv > SELF 0.00000000 Waves

{ "type": 13, "id": "Ca66mpEXSrbvRDtuvEMVGJ2SQ3GRfcrBy7rJXboDTjtS", "fee": 1000000, "feeAssetId": null, "timestamp": 1696683191340, "version": 2, "chainId": 84, "sender": "3N11gzZic4yASFhatzjC8zvLnpNhDo2B1Rv", "senderPublicKey": "EnUXxxhBK8wUfh1FveDYv9G5HBMXop6YwZWzVrBrLo2i", "proofs": [ "5EASWq5sgkZxuhZFdCyaC4kQN5dEVu3MEzrnYNXMw2wtGFuBVQg1W9xrhd8DMRZMw5ULCTKhUZtthj37kjL8rg3X" ], "script": "base64:BgIJCAISBQoDAQEYBAELd3JpdGVTdHJpbmcCA2tleQtzdHJpbmdWYWx1ZQkBC1N0cmluZ0VudHJ5AgUDa2V5BQtzdHJpbmdWYWx1ZQENc3BsaXRDZm1tSnNvbgEFZW50cnkJALUJAgUFZW50cnkCAS8BF2NhbGNFeGNlc3NBbW91bnRQZXJDZm1tAgpkaWZmZXJlbmNlC251bWJlckNmbW1zBAhxdW90aWVudAkAaQIFCmRpZmZlcmVuY2UFC251bWJlckNmbW1zBBZ0b3RhbERpc3RyaWJ1dGVkQW1vdW50CQBoAgUIcXVvdGllbnQFC251bWJlckNmbW1zBA9yZW1haW5pbmdBbW91bnQJAGUCBQpkaWZmZXJlbmNlBRZ0b3RhbERpc3RyaWJ1dGVkQW1vdW50AwkAZgIFD3JlbWFpbmluZ0Ftb3VudAAACQCUCgIFCHF1b3RpZW50BQ9yZW1haW5pbmdBbW91bnQJAJQKAgUIcXVvdGllbnQAAAEaZGlzdHJpYnV0ZUFkZGl0aW9uYWxUb2tlbnMCBXN3YXBzBGRpZmYECnRvdGFsU3dhcHMJAJADAQUFc3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wcwkAuQkCBQ1hZGp1c3RlZFN3YXBzAgEsBQNuaWwBAnR4AQZ2ZXJpZnkACQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAACAUCdHgPc2VuZGVyUHVibGljS2V5IJu4Tg==", "height": 2788236, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3KojrtqfHoJe5euPC8h4gvhNLqnDSfti6yXYZXrxvWeJ Next: GCWgDzrBFEqFBNMmL57vUrn5y7ow2tbAmFnFqcmRZJmU Diff:
OldNewDifferences
77 func splitCfmmJson (entry) = split(entry, "/")
88
99
10-func distributeDifference (swaps,diff) = {
10+func calcExcessAmountPerCfmm (difference,numberCfmms) = {
11+ let quotient = (difference / numberCfmms)
12+ let totalDistributedAmount = (quotient * numberCfmms)
13+ let remainingAmount = (difference - totalDistributedAmount)
14+ if ((remainingAmount > 0))
15+ then $Tuple2(quotient, remainingAmount)
16+ else $Tuple2(quotient, 0)
17+ }
18+
19+
20+func distributeAdditionalTokens (swaps,diff) = {
1121 let totalSwaps = size(swaps)
22+ let $t020722147 = calcExcessAmountPerCfmm(diff, totalSwaps)
23+ let quotient = $t020722147._1
24+ let remainingAmount = $t020722147._2
1225 func adjustAmounts (accum,next) = {
13- let $t0596638 = accum
14- let adjustedSwaps = $t0596638._1
15- let remainingDiff = $t0596638._2
26+ let $t022202262 = accum
27+ let adjustedSwaps = $t022202262._1
28+ let remainingDiff = $t022202262._2
1629 let item = splitCfmmJson(next)
1730 let inputAmount = parseInt(item[2])
1831 match inputAmount {
1932 case input: Int =>
20- let amountToAdjust = {
21- let remainDiff = (remainingDiff / ((totalSwaps - size(adjustedSwaps)) + 1))
22- match remainDiff {
23- case x: Int =>
24- if ((remainingDiff > 0))
25- then min([input, x])
26- else if ((0 > remainingDiff))
27- then max([(-(input) + 1), x])
28- else 0
29- case _ =>
30- throw("Wrong datatype")
31- }
32- }
33- let newInputAmount = max([1, (input + amountToAdjust)])
34- let newItem = ((((item[0] + "/") + item[1]) + "/") + toString(newInputAmount))
35- $Tuple2((adjustedSwaps :+ newItem), (remainingDiff - (amountToAdjust * ((totalSwaps - size(adjustedSwaps)) + 1))))
33+ let amountToAdjust = if ((remainingDiff > 0))
34+ then ((input + quotient) + 1)
35+ else (input + quotient)
36+ let newItem = ((((item[0] + "/") + item[1]) + "/") + toString(amountToAdjust))
37+ let newRemainingDiff = if ((remainingDiff > 0))
38+ then (remainingDiff - 1)
39+ else remainingDiff
40+ $Tuple2((adjustedSwaps :+ newItem), newRemainingDiff)
3641 case _ =>
3742 throw("Input has wrong datatype!")
3843 }
4045
4146 let $l = swaps
4247 let $s = size($l)
43- let $acc0 = $Tuple2(nil, diff)
48+ let $acc0 = $Tuple2(nil, remainingAmount)
4449 func $f0_1 ($a,$i) = if (($i >= $s))
4550 then $a
4651 else adjustAmounts($a, $l[$i])
5661 @Callable(i)
5762 func call (predeterminedAmount,availableAmount,swaps) = {
5863 let diff = (availableAmount - predeterminedAmount)
59- let adjustedSwaps = if ((diff != 0))
60- then distributeDifference(swaps, diff)._1
64+ let adjustedSwaps = if ((diff > 0))
65+ then distributeAdditionalTokens(swaps, diff)._1
6166 else swaps
6267 [writeString("swaps", makeString(swaps, ",")), writeString("adjustedSwaps", makeString(adjustedSwaps, ","))]
6368 }
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 func writeString (key,stringValue) = StringEntry(key, stringValue)
55
66
77 func splitCfmmJson (entry) = split(entry, "/")
88
99
10-func distributeDifference (swaps,diff) = {
10+func calcExcessAmountPerCfmm (difference,numberCfmms) = {
11+ let quotient = (difference / numberCfmms)
12+ let totalDistributedAmount = (quotient * numberCfmms)
13+ let remainingAmount = (difference - totalDistributedAmount)
14+ if ((remainingAmount > 0))
15+ then $Tuple2(quotient, remainingAmount)
16+ else $Tuple2(quotient, 0)
17+ }
18+
19+
20+func distributeAdditionalTokens (swaps,diff) = {
1121 let totalSwaps = size(swaps)
22+ let $t020722147 = calcExcessAmountPerCfmm(diff, totalSwaps)
23+ let quotient = $t020722147._1
24+ let remainingAmount = $t020722147._2
1225 func adjustAmounts (accum,next) = {
13- let $t0596638 = accum
14- let adjustedSwaps = $t0596638._1
15- let remainingDiff = $t0596638._2
26+ let $t022202262 = accum
27+ let adjustedSwaps = $t022202262._1
28+ let remainingDiff = $t022202262._2
1629 let item = splitCfmmJson(next)
1730 let inputAmount = parseInt(item[2])
1831 match inputAmount {
1932 case input: Int =>
20- let amountToAdjust = {
21- let remainDiff = (remainingDiff / ((totalSwaps - size(adjustedSwaps)) + 1))
22- match remainDiff {
23- case x: Int =>
24- if ((remainingDiff > 0))
25- then min([input, x])
26- else if ((0 > remainingDiff))
27- then max([(-(input) + 1), x])
28- else 0
29- case _ =>
30- throw("Wrong datatype")
31- }
32- }
33- let newInputAmount = max([1, (input + amountToAdjust)])
34- let newItem = ((((item[0] + "/") + item[1]) + "/") + toString(newInputAmount))
35- $Tuple2((adjustedSwaps :+ newItem), (remainingDiff - (amountToAdjust * ((totalSwaps - size(adjustedSwaps)) + 1))))
33+ let amountToAdjust = if ((remainingDiff > 0))
34+ then ((input + quotient) + 1)
35+ else (input + quotient)
36+ let newItem = ((((item[0] + "/") + item[1]) + "/") + toString(amountToAdjust))
37+ let newRemainingDiff = if ((remainingDiff > 0))
38+ then (remainingDiff - 1)
39+ else remainingDiff
40+ $Tuple2((adjustedSwaps :+ newItem), newRemainingDiff)
3641 case _ =>
3742 throw("Input has wrong datatype!")
3843 }
3944 }
4045
4146 let $l = swaps
4247 let $s = size($l)
43- let $acc0 = $Tuple2(nil, diff)
48+ let $acc0 = $Tuple2(nil, remainingAmount)
4449 func $f0_1 ($a,$i) = if (($i >= $s))
4550 then $a
4651 else adjustAmounts($a, $l[$i])
4752
4853 func $f0_2 ($a,$i) = if (($i >= $s))
4954 then $a
5055 else throw("List size exceeds 40")
5156
5257 $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)
5358 }
5459
5560
5661 @Callable(i)
5762 func call (predeterminedAmount,availableAmount,swaps) = {
5863 let diff = (availableAmount - predeterminedAmount)
59- let adjustedSwaps = if ((diff != 0))
60- then distributeDifference(swaps, diff)._1
64+ let adjustedSwaps = if ((diff > 0))
65+ then distributeAdditionalTokens(swaps, diff)._1
6166 else swaps
6267 [writeString("swaps", makeString(swaps, ",")), writeString("adjustedSwaps", makeString(adjustedSwaps, ","))]
6368 }
6469
6570
6671 @Verifier(tx)
6772 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
6873

github/deemru/w8io/169f3d6 
28.98 ms