Last active
October 20, 2023 11:57
-
-
Save WietseWind/b7e89a2b1e61e9e7147b04de2795f12b to your computer and use it in GitHub Desktop.
Xumm Fee Calc 2.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sample output: | |
>> xumm2.6-feecalc-as-is.js | |
┌──────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐ | |
│ (index) │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ | |
├──────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ | |
│ input │ 10 │ 12 │ 24 │ 100 │ 500 │ 1200 │ 10000 │ 20000 │ 50000 │ | |
│ -------- │ '-----' │ '-----' │ '-----' │ '-----' │ '-----' │ '-----' │ '-----' │ '-----' │ '-----' │ | |
│ base │ '12' │ '12' │ '24' │ '100' │ '500' │ '1200' │ '10000' │ '20000' │ '50000' │ | |
│ medium │ '14' │ '14' │ '28' │ '118' │ '592' │ '1419' │ '11715' │ '23200' │ '56498' │ | |
│ high │ '21' │ '21' │ '43' │ '179' │ '892' │ '2134' │ '17101' │ '32800' │ '73425' │ | |
└──────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘ | |
>> xumm2.6-feecalc-nearest-of-5[...]-pow.js | |
┌──────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐ | |
│ (index) │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ | |
├──────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ | |
│ input │ 10 │ 12 │ 24 │ 100 │ 500 │ 1200 │ 10000 │ 20000 │ 50000 │ | |
│ -------- │ '-----' │ '-----' │ '-----' │ '-----' │ '-----' │ '-----' │ '-----' │ '-----' │ '-----' │ | |
│ base │ '12' │ '12' │ '24' │ '100' │ '500' │ '1200' │ '10000' │ '20000' │ '50000' │ | |
│ medium │ '15' │ '15' │ '30' │ '150' │ '600' │ '1500' │ '15000' │ '25000' │ '60000' │ | |
│ high │ '25' │ '25' │ '45' │ '200' │ '900' │ '2500' │ '20000' │ '35000' │ '75000' │ | |
└──────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const f = [ | |
10, | |
12, | |
24, | |
100, | |
500, | |
1200, | |
10000, | |
20000, | |
50000, | |
883520, | |
] | |
const feecalc = (basefees, level) => { | |
let toppercentage = 0 | |
switch (level) { | |
case 'medium': | |
toppercentage = 4 | |
break; | |
case 'high': | |
toppercentage = 8 | |
break | |
} | |
return basefees.map(basefee => { | |
const fee = Math.max(12, Number(basefee)) | |
const multiplier = toppercentage > 0 | |
? 100 + Math.pow(toppercentage, 2.1 - (0.000005 * fee)) | |
: 100 | |
return String(Math.round(fee / 100 * multiplier)) | |
}) | |
} | |
console.table({ | |
input: f, | |
'--------': f.map(f => '-----'), | |
base: feecalc(f, 'base'), | |
medium: feecalc(f, 'medium'), | |
high: feecalc(f, 'high'), | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const f = [ | |
10, | |
12, | |
24, | |
100, | |
500, | |
1200, | |
10000, | |
20000, | |
50000, | |
883520, | |
] | |
const feecalc = (basefees, level) => { | |
let toppercentage = 0 | |
switch (level) { | |
case 'medium': | |
toppercentage = 4 | |
break; | |
case 'high': | |
toppercentage = 8 | |
break | |
} | |
return basefees.map(basefee => { | |
const fee = Math.max(12, Number(basefee)) | |
const nearest = level === 'base' | |
? 1 | |
: 0.5 * Math.pow(10, String(fee).length - 1) | |
const multiplier = toppercentage > 0 | |
? 100 + Math.pow(toppercentage, 2.1 - (0.000005 * fee)) | |
: 100 | |
return String( | |
Math.ceil( | |
(fee / 100 * multiplier) / nearest | |
) * nearest | |
) | |
}) | |
} | |
console.table({ | |
input: f, | |
'--------': f.map(f => '-----'), | |
base: feecalc(f, 'base'), | |
medium: feecalc(f, 'medium'), | |
high: feecalc(f, 'high'), | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment