tx · GCWgDzrBFEqFBNMmL57vUrn5y7ow2tbAmFnFqcmRZJmU

3N11gzZic4yASFhatzjC8zvLnpNhDo2B1Rv:  -0.01000000 Waves

2023.10.08 22:46 [2790094] smart account 3N11gzZic4yASFhatzjC8zvLnpNhDo2B1Rv > SELF 0.00000000 Waves

{ "type": 13, "id": "GCWgDzrBFEqFBNMmL57vUrn5y7ow2tbAmFnFqcmRZJmU", "fee": 1000000, "feeAssetId": null, "timestamp": 1696794368927, "version": 2, "chainId": 84, "sender": "3N11gzZic4yASFhatzjC8zvLnpNhDo2B1Rv", "senderPublicKey": "EnUXxxhBK8wUfh1FveDYv9G5HBMXop6YwZWzVrBrLo2i", "proofs": [ "3wmzERFxyg8j2PPdS69XDNj6gtR9cc1pSdTKKSvPuVikRQB4HXVzArofr4CvvFaWXYQZk6m7J872uD2o9tK9FDf5" ], "script": "base64:BgIJCAISBQoDAQEYBwELd3JpdGVTdHJpbmcCA2tleQtzdHJpbmdWYWx1ZQkBC1N0cmluZ0VudHJ5AgUDa2V5BQtzdHJpbmdWYWx1ZQENc3BsaXRDZm1tSnNvbgEFZW50cnkJALUJAgUFZW50cnkCAS8BH2NhbGNFeGNlc3NBbW91bnRQZXJDZm1tUG9zaXRpdmUCCmRpZmZlcmVuY2ULbnVtYmVyQ2ZtbXMECHF1b3RpZW50CQBuBAUKZGlmZmVyZW5jZQABBQtudW1iZXJDZm1tcwUERE9XTgQWdG90YWxEaXN0cmlidXRlZEFtb3VudAkAaAIFCHF1b3RpZW50BQtudW1iZXJDZm1tcwQPcmVtYWluaW5nQW1vdW50CQBlAgUKZGlmZmVyZW5jZQUWdG90YWxEaXN0cmlidXRlZEFtb3VudAMJAGYCBQ9yZW1haW5pbmdBbW91bnQAAAkAlAoCBQhxdW90aWVudAUPcmVtYWluaW5nQW1vdW50CQCUCgIFCHF1b3RpZW50AAABH2NhbGNFeGNlc3NBbW91bnRQZXJDZm1tTmVnYXRpdmUCCmRpZmZlcmVuY2ULbnVtYmVy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VABYAFwAYABkAGgAbABwAHQAeAB8AIAAhACIAIwAkACUAJgAnACgEDWFkanVzdGVkU3dhcHMIBQskdDA0NTY5NDY2MAJfMQQOcmVtYWluaW5nRGlmZnMIBQskdDA0NTY5NDY2MAJfMgQLJHQwNDY2NDQ3NDQJARhkaXN0cmlidXRlUmVtYWluaW5nRGlmZnMCBQ5yZW1haW5pbmdEaWZmcwUNYWRqdXN0ZWRTd2FwcwQKZmluYWxTd2FwcwgFCyR0MDQ2NjQ0NzQ0Al8xBAVkaWZmcwgFCyR0MDQ2NjQ0NzQ0Al8yBQpmaW5hbFN3YXBzAQFpAQRjYWxsAxNwcmVkZXRlcm1pbmVkQW1vdW50D2F2YWlsYWJsZUFtb3VudAVzd2FwcwQEZGlmZgkAZQIFD2F2YWlsYWJsZUFtb3VudAUTcHJlZGV0ZXJtaW5lZEFtb3VudAQNYWRqdXN0ZWRTd2FwcwMJAGYCBQRkaWZmAAAICQEaZGlzdHJpYnV0ZUFkZGl0aW9uYWxUb2tlbnMCBQVzd2FwcwUEZGlmZgJfMQMJAGYCAAAFBGRpZmYJARhkaXN0cmlidXRlTmVnYXRpdmVUb2tlbnMCBQVzd2FwcwUEZGlmZgUFc3dhcHMJAMwIAgkBC3dyaXRlU3RyaW5nAgIFc3dhcHMJALkJAgUFc3dhcHMCASwJAMwIAgkBC3dyaXRlU3RyaW5nAgINYWRqdXN0ZWRTd2FwcwkAuQkCBQ1hZGp1c3RlZFN3YXBzAgEsBQNuaWwBAnR4AQZ2ZXJpZnkACQD0AwMIBQJ0eAlib2R5Qnl0ZXMJAJEDAggFAnR4BnByb29mcwAACAUCdHgPc2VuZGVyUHVibGljS2V5aZ0JyA==", "height": 2790094, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Ca66mpEXSrbvRDtuvEMVGJ2SQ3GRfcrBy7rJXboDTjtS Next: none Diff:
OldNewDifferences
77 func splitCfmmJson (entry) = split(entry, "/")
88
99
10-func calcExcessAmountPerCfmm (difference,numberCfmms) = {
11- let quotient = (difference / numberCfmms)
10+func calcExcessAmountPerCfmmPositive (difference,numberCfmms) = {
11+ let quotient = fraction(difference, 1, numberCfmms, DOWN)
1212 let totalDistributedAmount = (quotient * numberCfmms)
1313 let remainingAmount = (difference - totalDistributedAmount)
1414 if ((remainingAmount > 0))
1717 }
1818
1919
20+func calcExcessAmountPerCfmmNegative (difference,numberCfmms) = {
21+ let quotient = fraction(difference, 1, numberCfmms, DOWN)
22+ let totalDistributedAmount = (quotient * numberCfmms)
23+ let remainingAmount = (difference - totalDistributedAmount)
24+ if ((0 > remainingAmount))
25+ then $Tuple2(quotient, remainingAmount)
26+ else $Tuple2(quotient, 0)
27+ }
28+
29+
2030 func distributeAdditionalTokens (swaps,diff) = {
2131 let totalSwaps = size(swaps)
22- let $t020722147 = calcExcessAmountPerCfmm(diff, totalSwaps)
23- let quotient = $t020722147._1
24- let remainingAmount = $t020722147._2
32+ let $t012211304 = calcExcessAmountPerCfmmPositive(diff, totalSwaps)
33+ let quotient = $t012211304._1
34+ let remainingAmount = $t012211304._2
2535 func adjustAmounts (accum,next) = {
26- let $t022202262 = accum
27- let adjustedSwaps = $t022202262._1
28- let remainingDiff = $t022202262._2
36+ let $t013771419 = accum
37+ let adjustedSwaps = $t013771419._1
38+ let remainingDiff = $t013771419._2
2939 let item = splitCfmmJson(next)
3040 let inputAmount = parseInt(item[2])
3141 match inputAmount {
5868 }
5969
6070
71+func distributeRemainingDiffs (remainingDiff,swaps) = {
72+ func distributeProportional (accum,next) = {
73+ let $t022692308 = accum
74+ let adjustedSwaps = $t022692308._1
75+ let remainDiff = $t022692308._2
76+ let item = splitCfmmJson(next)
77+ let inputAmount = parseInt(item[2])
78+ let inputAmountCheck = match inputAmount {
79+ case input: Int =>
80+ input
81+ case _ =>
82+ throw("Input amount has the wrong data type")
83+ }
84+ let maxSubtractable = if ((inputAmountCheck > 4))
85+ then fraction(inputAmountCheck, 3, 4)
86+ else 0
87+ let $t027063320 = if (if ((remainDiff == 0))
88+ then true
89+ else (maxSubtractable == 0))
90+ then $Tuple2(remainDiff, 0)
91+ else if (((remainDiff + maxSubtractable) > 0))
92+ then {
93+ let remainingSubtractable = (remainDiff + maxSubtractable)
94+ $Tuple2(0, (maxSubtractable - remainingSubtractable))
95+ }
96+ else if ((0 > (remainDiff + maxSubtractable)))
97+ then $Tuple2((remainDiff + maxSubtractable), maxSubtractable)
98+ else $Tuple2(0, maxSubtractable)
99+ let newRemainingDiff = $t027063320._1
100+ let subtractableAmount = $t027063320._2
101+ let amountToAdjust = (inputAmountCheck - subtractableAmount)
102+ let newItem = ((((item[0] + "/") + item[1]) + "/") + toString(amountToAdjust))
103+ $Tuple2((adjustedSwaps :+ newItem), newRemainingDiff)
104+ }
105+
106+ let $l = swaps
107+ let $s = size($l)
108+ let $acc0 = $Tuple2(nil, remainingDiff)
109+ func $f0_1 ($a,$i) = if (($i >= $s))
110+ then $a
111+ else distributeProportional($a, $l[$i])
112+
113+ func $f0_2 ($a,$i) = if (($i >= $s))
114+ then $a
115+ else throw("List size exceeds 40")
116+
117+ $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)
118+ }
119+
120+
121+func distributeNegativeTokens (swaps,diff) = {
122+ let totalSwaps = size(swaps)
123+ let $t036853768 = calcExcessAmountPerCfmmNegative(diff, totalSwaps)
124+ let quotient = $t036853768._1
125+ let remainingAmount = $t036853768._2
126+ func adjustAmounts (accum,next) = {
127+ let $t038413883 = accum
128+ let adjustedSwaps = $t038413883._1
129+ let remainingDiff = $t038413883._2
130+ let item = splitCfmmJson(next)
131+ let inputAmount = parseInt(item[2])
132+ match inputAmount {
133+ case input: Int =>
134+ let $t040204370 = if (((input + quotient) >= 1))
135+ then if (if ((remainingDiff > 0))
136+ then (((input + quotient) - 1) >= 1)
137+ else false)
138+ then $Tuple2(((input + quotient) - 1), (remainingDiff - 1))
139+ else $Tuple2((input + quotient), remainingDiff)
140+ else $Tuple2(input, (remainingDiff + quotient))
141+ let amountToAdjust = $t040204370._1
142+ let newRemainingDiff = $t040204370._2
143+ let newItem = ((((item[0] + "/") + item[1]) + "/") + toString(amountToAdjust))
144+ $Tuple2((adjustedSwaps :+ newItem), newRemainingDiff)
145+ case _ =>
146+ throw("Input has wrong datatype!")
147+ }
148+ }
149+
150+ let $t045694660 = {
151+ let $l = swaps
152+ let $s = size($l)
153+ let $acc0 = $Tuple2(nil, remainingAmount)
154+ func $f0_1 ($a,$i) = if (($i >= $s))
155+ then $a
156+ else adjustAmounts($a, $l[$i])
157+
158+ func $f0_2 ($a,$i) = if (($i >= $s))
159+ then $a
160+ else throw("List size exceeds 40")
161+
162+ $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)
163+ }
164+ let adjustedSwaps = $t045694660._1
165+ let remainingDiffs = $t045694660._2
166+ let $t046644744 = distributeRemainingDiffs(remainingDiffs, adjustedSwaps)
167+ let finalSwaps = $t046644744._1
168+ let diffs = $t046644744._2
169+ finalSwaps
170+ }
171+
172+
61173 @Callable(i)
62174 func call (predeterminedAmount,availableAmount,swaps) = {
63175 let diff = (availableAmount - predeterminedAmount)
64176 let adjustedSwaps = if ((diff > 0))
65177 then distributeAdditionalTokens(swaps, diff)._1
66- else swaps
178+ else if ((0 > diff))
179+ then distributeNegativeTokens(swaps, diff)
180+ else swaps
67181 [writeString("swaps", makeString(swaps, ",")), writeString("adjustedSwaps", makeString(adjustedSwaps, ","))]
68182 }
69183
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 calcExcessAmountPerCfmm (difference,numberCfmms) = {
11- let quotient = (difference / numberCfmms)
10+func calcExcessAmountPerCfmmPositive (difference,numberCfmms) = {
11+ let quotient = fraction(difference, 1, numberCfmms, DOWN)
1212 let totalDistributedAmount = (quotient * numberCfmms)
1313 let remainingAmount = (difference - totalDistributedAmount)
1414 if ((remainingAmount > 0))
1515 then $Tuple2(quotient, remainingAmount)
1616 else $Tuple2(quotient, 0)
1717 }
1818
1919
20+func calcExcessAmountPerCfmmNegative (difference,numberCfmms) = {
21+ let quotient = fraction(difference, 1, numberCfmms, DOWN)
22+ let totalDistributedAmount = (quotient * numberCfmms)
23+ let remainingAmount = (difference - totalDistributedAmount)
24+ if ((0 > remainingAmount))
25+ then $Tuple2(quotient, remainingAmount)
26+ else $Tuple2(quotient, 0)
27+ }
28+
29+
2030 func distributeAdditionalTokens (swaps,diff) = {
2131 let totalSwaps = size(swaps)
22- let $t020722147 = calcExcessAmountPerCfmm(diff, totalSwaps)
23- let quotient = $t020722147._1
24- let remainingAmount = $t020722147._2
32+ let $t012211304 = calcExcessAmountPerCfmmPositive(diff, totalSwaps)
33+ let quotient = $t012211304._1
34+ let remainingAmount = $t012211304._2
2535 func adjustAmounts (accum,next) = {
26- let $t022202262 = accum
27- let adjustedSwaps = $t022202262._1
28- let remainingDiff = $t022202262._2
36+ let $t013771419 = accum
37+ let adjustedSwaps = $t013771419._1
38+ let remainingDiff = $t013771419._2
2939 let item = splitCfmmJson(next)
3040 let inputAmount = parseInt(item[2])
3141 match inputAmount {
3242 case input: Int =>
3343 let amountToAdjust = if ((remainingDiff > 0))
3444 then ((input + quotient) + 1)
3545 else (input + quotient)
3646 let newItem = ((((item[0] + "/") + item[1]) + "/") + toString(amountToAdjust))
3747 let newRemainingDiff = if ((remainingDiff > 0))
3848 then (remainingDiff - 1)
3949 else remainingDiff
4050 $Tuple2((adjustedSwaps :+ newItem), newRemainingDiff)
4151 case _ =>
4252 throw("Input has wrong datatype!")
4353 }
4454 }
4555
4656 let $l = swaps
4757 let $s = size($l)
4858 let $acc0 = $Tuple2(nil, remainingAmount)
4959 func $f0_1 ($a,$i) = if (($i >= $s))
5060 then $a
5161 else adjustAmounts($a, $l[$i])
5262
5363 func $f0_2 ($a,$i) = if (($i >= $s))
5464 then $a
5565 else throw("List size exceeds 40")
5666
5767 $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)
5868 }
5969
6070
71+func distributeRemainingDiffs (remainingDiff,swaps) = {
72+ func distributeProportional (accum,next) = {
73+ let $t022692308 = accum
74+ let adjustedSwaps = $t022692308._1
75+ let remainDiff = $t022692308._2
76+ let item = splitCfmmJson(next)
77+ let inputAmount = parseInt(item[2])
78+ let inputAmountCheck = match inputAmount {
79+ case input: Int =>
80+ input
81+ case _ =>
82+ throw("Input amount has the wrong data type")
83+ }
84+ let maxSubtractable = if ((inputAmountCheck > 4))
85+ then fraction(inputAmountCheck, 3, 4)
86+ else 0
87+ let $t027063320 = if (if ((remainDiff == 0))
88+ then true
89+ else (maxSubtractable == 0))
90+ then $Tuple2(remainDiff, 0)
91+ else if (((remainDiff + maxSubtractable) > 0))
92+ then {
93+ let remainingSubtractable = (remainDiff + maxSubtractable)
94+ $Tuple2(0, (maxSubtractable - remainingSubtractable))
95+ }
96+ else if ((0 > (remainDiff + maxSubtractable)))
97+ then $Tuple2((remainDiff + maxSubtractable), maxSubtractable)
98+ else $Tuple2(0, maxSubtractable)
99+ let newRemainingDiff = $t027063320._1
100+ let subtractableAmount = $t027063320._2
101+ let amountToAdjust = (inputAmountCheck - subtractableAmount)
102+ let newItem = ((((item[0] + "/") + item[1]) + "/") + toString(amountToAdjust))
103+ $Tuple2((adjustedSwaps :+ newItem), newRemainingDiff)
104+ }
105+
106+ let $l = swaps
107+ let $s = size($l)
108+ let $acc0 = $Tuple2(nil, remainingDiff)
109+ func $f0_1 ($a,$i) = if (($i >= $s))
110+ then $a
111+ else distributeProportional($a, $l[$i])
112+
113+ func $f0_2 ($a,$i) = if (($i >= $s))
114+ then $a
115+ else throw("List size exceeds 40")
116+
117+ $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)
118+ }
119+
120+
121+func distributeNegativeTokens (swaps,diff) = {
122+ let totalSwaps = size(swaps)
123+ let $t036853768 = calcExcessAmountPerCfmmNegative(diff, totalSwaps)
124+ let quotient = $t036853768._1
125+ let remainingAmount = $t036853768._2
126+ func adjustAmounts (accum,next) = {
127+ let $t038413883 = accum
128+ let adjustedSwaps = $t038413883._1
129+ let remainingDiff = $t038413883._2
130+ let item = splitCfmmJson(next)
131+ let inputAmount = parseInt(item[2])
132+ match inputAmount {
133+ case input: Int =>
134+ let $t040204370 = if (((input + quotient) >= 1))
135+ then if (if ((remainingDiff > 0))
136+ then (((input + quotient) - 1) >= 1)
137+ else false)
138+ then $Tuple2(((input + quotient) - 1), (remainingDiff - 1))
139+ else $Tuple2((input + quotient), remainingDiff)
140+ else $Tuple2(input, (remainingDiff + quotient))
141+ let amountToAdjust = $t040204370._1
142+ let newRemainingDiff = $t040204370._2
143+ let newItem = ((((item[0] + "/") + item[1]) + "/") + toString(amountToAdjust))
144+ $Tuple2((adjustedSwaps :+ newItem), newRemainingDiff)
145+ case _ =>
146+ throw("Input has wrong datatype!")
147+ }
148+ }
149+
150+ let $t045694660 = {
151+ let $l = swaps
152+ let $s = size($l)
153+ let $acc0 = $Tuple2(nil, remainingAmount)
154+ func $f0_1 ($a,$i) = if (($i >= $s))
155+ then $a
156+ else adjustAmounts($a, $l[$i])
157+
158+ func $f0_2 ($a,$i) = if (($i >= $s))
159+ then $a
160+ else throw("List size exceeds 40")
161+
162+ $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)
163+ }
164+ let adjustedSwaps = $t045694660._1
165+ let remainingDiffs = $t045694660._2
166+ let $t046644744 = distributeRemainingDiffs(remainingDiffs, adjustedSwaps)
167+ let finalSwaps = $t046644744._1
168+ let diffs = $t046644744._2
169+ finalSwaps
170+ }
171+
172+
61173 @Callable(i)
62174 func call (predeterminedAmount,availableAmount,swaps) = {
63175 let diff = (availableAmount - predeterminedAmount)
64176 let adjustedSwaps = if ((diff > 0))
65177 then distributeAdditionalTokens(swaps, diff)._1
66- else swaps
178+ else if ((0 > diff))
179+ then distributeNegativeTokens(swaps, diff)
180+ else swaps
67181 [writeString("swaps", makeString(swaps, ",")), writeString("adjustedSwaps", makeString(adjustedSwaps, ","))]
68182 }
69183
70184
71185 @Verifier(tx)
72186 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
73187

github/deemru/w8io/169f3d6 
36.04 ms