Browse Source

Update fee tables

feature/sql-semaphore1
Eduard S 4 years ago
parent
commit
fe23361037
5 changed files with 593 additions and 552 deletions
  1. +275
    -269
      common/fee.go
  2. +35
    -9
      common/fee_test.go
  3. +257
    -257
      db/migrations/0001.sql
  4. +8
    -2
      db/statedb/txprocessors.go
  5. +18
    -15
      test/til/sets.go

+ 275
- 269
common/fee.go

@ -1,6 +1,7 @@
package common package common
import ( import (
"fmt"
"math" "math"
"math/big" "math/big"
) )
@ -21,13 +22,12 @@ type FeeSelector uint8
func (f FeeSelector) Percentage() float64 { func (f FeeSelector) Percentage() float64 {
if f == 0 { if f == 0 {
return 0 return 0
//nolint:gomnd
} else if f <= 32 { //nolint:gomnd
return math.Pow(10, -24+(float64(f)/2)) //nolint:gomnd
} else if f <= 223 { //nolint:gomnd
return math.Pow(10, -8+(0.041666666666667*(float64(f)-32))) //nolint:gomnd
} else if f < 32 { //nolint:gomnd
return math.Pow(2, -60.0+float64(f)*(-8.0-(-60.0))/32.0) //nolint:gomnd
} else if f < 192 { //nolint:gomnd
return math.Pow(2, -8.0+(float64(f)-32.0)*(0.0-(-8.0))/160.0) //nolint:gomnd
} else { } else {
return math.Pow(10, float64(f)-224) //nolint:gomnd
return math.Pow(2, (float64(f) - 192.0)) //nolint:gomnd
} }
} }
@ -40,273 +40,279 @@ var FeePlan = [MaxFeePlan]float64{}
// CalcFeeAmount calculates the fee amount in tokens from an amount and // CalcFeeAmount calculates the fee amount in tokens from an amount and
// feeSelector (fee index). // feeSelector (fee index).
func CalcFeeAmount(amount *big.Int, feeSel FeeSelector) *big.Int {
feeAmount := new(big.Int).Mul(amount, FeeFactorLsh79[int(feeSel)])
return feeAmount.Rsh(feeAmount, 79)
func CalcFeeAmount(amount *big.Int, feeSel FeeSelector) (*big.Int, error) {
feeAmount := new(big.Int).Mul(amount, FeeFactorLsh60[int(feeSel)])
if feeSel < 192 { //nolint:gomnd
feeAmount.Rsh(feeAmount, 60)
}
if feeAmount.BitLen() > 128 { //nolint:gomnd
return nil, fmt.Errorf("FeeAmount overflow (feeAmount doesn't fit in 128 bits)")
}
return feeAmount, nil
} }
func init() { func init() {
setFeeFactorLsh79(&FeeFactorLsh79)
setFeeFactorLsh60(&FeeFactorLsh60)
} }
// FeeFactorLsh79 is the feeFactor << 79
var FeeFactorLsh79 [256]*big.Int
// FeeFactorLsh60 is the feeFactor << 60
var FeeFactorLsh60 [256]*big.Int
func setFeeFactorLsh79(feeFactorLsh79 *[256]*big.Int) {
feeFactorLsh79[0], _ = new(big.Int).SetString("0", 10)
feeFactorLsh79[1], _ = new(big.Int).SetString("1", 10)
feeFactorLsh79[2], _ = new(big.Int).SetString("6", 10)
feeFactorLsh79[3], _ = new(big.Int).SetString("19", 10)
feeFactorLsh79[4], _ = new(big.Int).SetString("60", 10)
feeFactorLsh79[5], _ = new(big.Int).SetString("191", 10)
feeFactorLsh79[6], _ = new(big.Int).SetString("604", 10)
feeFactorLsh79[7], _ = new(big.Int).SetString("1911", 10)
feeFactorLsh79[8], _ = new(big.Int).SetString("6044", 10)
feeFactorLsh79[9], _ = new(big.Int).SetString("19114", 10)
feeFactorLsh79[10], _ = new(big.Int).SetString("60446", 10)
feeFactorLsh79[11], _ = new(big.Int).SetString("191147", 10)
feeFactorLsh79[12], _ = new(big.Int).SetString("604462", 10)
feeFactorLsh79[13], _ = new(big.Int).SetString("1911479", 10)
feeFactorLsh79[14], _ = new(big.Int).SetString("6044629", 10)
feeFactorLsh79[15], _ = new(big.Int).SetString("19114795", 10)
feeFactorLsh79[16], _ = new(big.Int).SetString("60446290", 10)
feeFactorLsh79[17], _ = new(big.Int).SetString("191147955", 10)
feeFactorLsh79[18], _ = new(big.Int).SetString("604462909", 10)
feeFactorLsh79[19], _ = new(big.Int).SetString("1911479556", 10)
feeFactorLsh79[20], _ = new(big.Int).SetString("6044629098", 10)
feeFactorLsh79[21], _ = new(big.Int).SetString("19114795560", 10)
feeFactorLsh79[22], _ = new(big.Int).SetString("60446290980", 10)
feeFactorLsh79[23], _ = new(big.Int).SetString("191147955608", 10)
feeFactorLsh79[24], _ = new(big.Int).SetString("604462909807", 10)
feeFactorLsh79[25], _ = new(big.Int).SetString("1911479556084", 10)
feeFactorLsh79[26], _ = new(big.Int).SetString("6044629098073", 10)
feeFactorLsh79[27], _ = new(big.Int).SetString("19114795560840", 10)
feeFactorLsh79[28], _ = new(big.Int).SetString("60446290980731", 10)
feeFactorLsh79[29], _ = new(big.Int).SetString("191147955608404", 10)
feeFactorLsh79[30], _ = new(big.Int).SetString("604462909807314", 10)
feeFactorLsh79[31], _ = new(big.Int).SetString("1911479556084045", 10)
feeFactorLsh79[32], _ = new(big.Int).SetString("6044629098073146", 10)
feeFactorLsh79[33], _ = new(big.Int).SetString("6653288015630616", 10)
feeFactorLsh79[34], _ = new(big.Int).SetString("7323235338466790", 10)
feeFactorLsh79[35], _ = new(big.Int).SetString("8060642451758603", 10)
feeFactorLsh79[36], _ = new(big.Int).SetString("8872302163198820", 10)
feeFactorLsh79[37], _ = new(big.Int).SetString("9765691276621298", 10)
feeFactorLsh79[38], _ = new(big.Int).SetString("10749039466425620", 10)
feeFactorLsh79[39], _ = new(big.Int).SetString("11831405087254648", 10)
feeFactorLsh79[40], _ = new(big.Int).SetString("13022758617264914", 10)
feeFactorLsh79[41], _ = new(big.Int).SetString("14334074503647984", 10)
feeFactorLsh79[42], _ = new(big.Int).SetString("15777432256460256", 10)
feeFactorLsh79[43], _ = new(big.Int).SetString("17366127722012378", 10)
feeFactorLsh79[44], _ = new(big.Int).SetString("19114795560840448", 10)
feeFactorLsh79[45], _ = new(big.Int).SetString("21039544058494708", 10)
feeFactorLsh79[46], _ = new(big.Int).SetString("23158103510989148", 10)
feeFactorLsh79[47], _ = new(big.Int).SetString("25489989551801104", 10)
feeFactorLsh79[48], _ = new(big.Int).SetString("28056682924947216", 10)
feeFactorLsh79[49], _ = new(big.Int).SetString("30881827360160752", 10)
feeFactorLsh79[50], _ = new(big.Int).SetString("33991447372945972", 10)
feeFactorLsh79[51], _ = new(big.Int).SetString("37414187995827888", 10)
feeFactorLsh79[52], _ = new(big.Int).SetString("41181578649142096", 10)
feeFactorLsh79[53], _ = new(big.Int).SetString("45328323582075176", 10)
feeFactorLsh79[54], _ = new(big.Int).SetString("49892621559424256", 10)
feeFactorLsh79[55], _ = new(big.Int).SetString("54916517738950528", 10)
feeFactorLsh79[56], _ = new(big.Int).SetString("60446290980731456", 10)
feeFactorLsh79[57], _ = new(big.Int).SetString("66532880156306032", 10)
feeFactorLsh79[58], _ = new(big.Int).SetString("73232353384667904", 10)
feeFactorLsh79[59], _ = new(big.Int).SetString("80606424517586032", 10)
feeFactorLsh79[60], _ = new(big.Int).SetString("88723021631988016", 10)
feeFactorLsh79[61], _ = new(big.Int).SetString("97656912766212992", 10)
feeFactorLsh79[62], _ = new(big.Int).SetString("107490394664256192", 10)
feeFactorLsh79[63], _ = new(big.Int).SetString("118314050872546240", 10)
feeFactorLsh79[64], _ = new(big.Int).SetString("130227586172649136", 10)
feeFactorLsh79[65], _ = new(big.Int).SetString("143340745036479856", 10)
feeFactorLsh79[66], _ = new(big.Int).SetString("157774322564602240", 10)
feeFactorLsh79[67], _ = new(big.Int).SetString("173661277220123776", 10)
feeFactorLsh79[68], _ = new(big.Int).SetString("191147955608404480", 10)
feeFactorLsh79[69], _ = new(big.Int).SetString("210395440584946624", 10)
feeFactorLsh79[70], _ = new(big.Int).SetString("231581035109891488", 10)
feeFactorLsh79[71], _ = new(big.Int).SetString("254899895518011040", 10)
feeFactorLsh79[72], _ = new(big.Int).SetString("280566829249471584", 10)
feeFactorLsh79[73], _ = new(big.Int).SetString("308818273601607552", 10)
feeFactorLsh79[74], _ = new(big.Int).SetString("339914473729459712", 10)
feeFactorLsh79[75], _ = new(big.Int).SetString("374141879958278144", 10)
feeFactorLsh79[76], _ = new(big.Int).SetString("411815786491420928", 10)
feeFactorLsh79[77], _ = new(big.Int).SetString("453283235820751744", 10)
feeFactorLsh79[78], _ = new(big.Int).SetString("498926215594241536", 10)
feeFactorLsh79[79], _ = new(big.Int).SetString("549165177389505280", 10)
feeFactorLsh79[80], _ = new(big.Int).SetString("604462909807314560", 10)
feeFactorLsh79[81], _ = new(big.Int).SetString("665328801563060352", 10)
feeFactorLsh79[82], _ = new(big.Int).SetString("732323533846679040", 10)
feeFactorLsh79[83], _ = new(big.Int).SetString("806064245175860224", 10)
feeFactorLsh79[84], _ = new(big.Int).SetString("887230216319880192", 10)
feeFactorLsh79[85], _ = new(big.Int).SetString("976569127662129920", 10)
feeFactorLsh79[86], _ = new(big.Int).SetString("1074903946642562048", 10)
feeFactorLsh79[87], _ = new(big.Int).SetString("1183140508725462528", 10)
feeFactorLsh79[88], _ = new(big.Int).SetString("1302275861726491392", 10)
feeFactorLsh79[89], _ = new(big.Int).SetString("1433407450364798464", 10)
feeFactorLsh79[90], _ = new(big.Int).SetString("1577743225646022400", 10)
feeFactorLsh79[91], _ = new(big.Int).SetString("1736612772201237760", 10)
feeFactorLsh79[92], _ = new(big.Int).SetString("1911479556084044800", 10)
feeFactorLsh79[93], _ = new(big.Int).SetString("2103954405849466368", 10)
feeFactorLsh79[94], _ = new(big.Int).SetString("2315810351098914816", 10)
feeFactorLsh79[95], _ = new(big.Int).SetString("2548998955180110336", 10)
feeFactorLsh79[96], _ = new(big.Int).SetString("2805668292494715904", 10)
feeFactorLsh79[97], _ = new(big.Int).SetString("3088182736016075264", 10)
feeFactorLsh79[98], _ = new(big.Int).SetString("3399144737294597120", 10)
feeFactorLsh79[99], _ = new(big.Int).SetString("3741418799582781440", 10)
feeFactorLsh79[100], _ = new(big.Int).SetString("4118157864914209280", 10)
feeFactorLsh79[101], _ = new(big.Int).SetString("4532832358207517184", 10)
feeFactorLsh79[102], _ = new(big.Int).SetString("4989262155942415360", 10)
feeFactorLsh79[103], _ = new(big.Int).SetString("5491651773895053312", 10)
feeFactorLsh79[104], _ = new(big.Int).SetString("6044629098073145344", 10)
feeFactorLsh79[105], _ = new(big.Int).SetString("6653288015630603264", 10)
feeFactorLsh79[106], _ = new(big.Int).SetString("7323235338466789376", 10)
feeFactorLsh79[107], _ = new(big.Int).SetString("8060642451758603264", 10)
feeFactorLsh79[108], _ = new(big.Int).SetString("8872302163198801920", 10)
feeFactorLsh79[109], _ = new(big.Int).SetString("9765691276621297664", 10)
feeFactorLsh79[110], _ = new(big.Int).SetString("10749039466425620480", 10)
feeFactorLsh79[111], _ = new(big.Int).SetString("11831405087254624256", 10)
feeFactorLsh79[112], _ = new(big.Int).SetString("13022758617264914432", 10)
feeFactorLsh79[113], _ = new(big.Int).SetString("14334074503647985664", 10)
feeFactorLsh79[114], _ = new(big.Int).SetString("15777432256460224512", 10)
feeFactorLsh79[115], _ = new(big.Int).SetString("17366127722012377088", 10)
feeFactorLsh79[116], _ = new(big.Int).SetString("19114795560840450048", 10)
feeFactorLsh79[117], _ = new(big.Int).SetString("21039544058494664704", 10)
feeFactorLsh79[118], _ = new(big.Int).SetString("23158103510989152256", 10)
feeFactorLsh79[119], _ = new(big.Int).SetString("25489989551801102336", 10)
feeFactorLsh79[120], _ = new(big.Int).SetString("28056682924947156992", 10)
feeFactorLsh79[121], _ = new(big.Int).SetString("30881827360160751616", 10)
feeFactorLsh79[122], _ = new(big.Int).SetString("33991447372945973248", 10)
feeFactorLsh79[123], _ = new(big.Int).SetString("37414187995827814400", 10)
feeFactorLsh79[124], _ = new(big.Int).SetString("41181578649142091776", 10)
feeFactorLsh79[125], _ = new(big.Int).SetString("45328323582075174912", 10)
feeFactorLsh79[126], _ = new(big.Int).SetString("49892621559424155648", 10)
feeFactorLsh79[127], _ = new(big.Int).SetString("54916517738950524928", 10)
feeFactorLsh79[128], _ = new(big.Int).SetString("60446290980731453440", 10)
feeFactorLsh79[129], _ = new(big.Int).SetString("66532880156306030592", 10)
feeFactorLsh79[130], _ = new(big.Int).SetString("73232353384667897856", 10)
feeFactorLsh79[131], _ = new(big.Int).SetString("80606424517586026496", 10)
feeFactorLsh79[132], _ = new(big.Int).SetString("88723021631988023296", 10)
feeFactorLsh79[133], _ = new(big.Int).SetString("97656912766212980736", 10)
feeFactorLsh79[134], _ = new(big.Int).SetString("107490394664256208896", 10)
feeFactorLsh79[135], _ = new(big.Int).SetString("118314050872546246656", 10)
feeFactorLsh79[136], _ = new(big.Int).SetString("130227586172649144320", 10)
feeFactorLsh79[137], _ = new(big.Int).SetString("143340745036479856640", 10)
feeFactorLsh79[138], _ = new(big.Int).SetString("157774322564602232832", 10)
feeFactorLsh79[139], _ = new(big.Int).SetString("173661277220123770880", 10)
feeFactorLsh79[140], _ = new(big.Int).SetString("191147955608404492288", 10)
feeFactorLsh79[141], _ = new(big.Int).SetString("210395440584946647040", 10)
feeFactorLsh79[142], _ = new(big.Int).SetString("231581035109891506176", 10)
feeFactorLsh79[143], _ = new(big.Int).SetString("254899895518011031552", 10)
feeFactorLsh79[144], _ = new(big.Int).SetString("280566829249471578112", 10)
feeFactorLsh79[145], _ = new(big.Int).SetString("308818273601607499776", 10)
feeFactorLsh79[146], _ = new(big.Int).SetString("339914473729459748864", 10)
feeFactorLsh79[147], _ = new(big.Int).SetString("374141879958278111232", 10)
feeFactorLsh79[148], _ = new(big.Int).SetString("411815786491420934144", 10)
feeFactorLsh79[149], _ = new(big.Int).SetString("453283235820751683584", 10)
feeFactorLsh79[150], _ = new(big.Int).SetString("498926215594241556480", 10)
feeFactorLsh79[151], _ = new(big.Int).SetString("549165177389505314816", 10)
feeFactorLsh79[152], _ = new(big.Int).SetString("604462909807314599936", 10)
feeFactorLsh79[153], _ = new(big.Int).SetString("665328801563060338688", 10)
feeFactorLsh79[154], _ = new(big.Int).SetString("732323533846678994944", 10)
feeFactorLsh79[155], _ = new(big.Int).SetString("806064245175860330496", 10)
feeFactorLsh79[156], _ = new(big.Int).SetString("887230216319880134656", 10)
feeFactorLsh79[157], _ = new(big.Int).SetString("976569127662129774592", 10)
feeFactorLsh79[158], _ = new(big.Int).SetString("1074903946642561957888", 10)
feeFactorLsh79[159], _ = new(big.Int).SetString("1183140508725462433792", 10)
feeFactorLsh79[160], _ = new(big.Int).SetString("1302275861726491312128", 10)
feeFactorLsh79[161], _ = new(big.Int).SetString("1433407450364798566400", 10)
feeFactorLsh79[162], _ = new(big.Int).SetString("1577743225646022393856", 10)
feeFactorLsh79[163], _ = new(big.Int).SetString("1736612772201237577728", 10)
feeFactorLsh79[164], _ = new(big.Int).SetString("1911479556084044922880", 10)
feeFactorLsh79[165], _ = new(big.Int).SetString("2103954405849466404864", 10)
feeFactorLsh79[166], _ = new(big.Int).SetString("2315810351098914930688", 10)
feeFactorLsh79[167], _ = new(big.Int).SetString("2548998955180110643200", 10)
feeFactorLsh79[168], _ = new(big.Int).SetString("2805668292494716043264", 10)
feeFactorLsh79[169], _ = new(big.Int).SetString("3088182736016075390976", 10)
feeFactorLsh79[170], _ = new(big.Int).SetString("3399144737294597488640", 10)
feeFactorLsh79[171], _ = new(big.Int).SetString("3741418799582781374464", 10)
feeFactorLsh79[172], _ = new(big.Int).SetString("4118157864914209210368", 10)
feeFactorLsh79[173], _ = new(big.Int).SetString("4532832358207517097984", 10)
feeFactorLsh79[174], _ = new(big.Int).SetString("4989262155942415302656", 10)
feeFactorLsh79[175], _ = new(big.Int).SetString("5491651773895053148160", 10)
feeFactorLsh79[176], _ = new(big.Int).SetString("6044629098073145999360", 10)
feeFactorLsh79[177], _ = new(big.Int).SetString("6653288015630603124736", 10)
feeFactorLsh79[178], _ = new(big.Int).SetString("7323235338466790211584", 10)
feeFactorLsh79[179], _ = new(big.Int).SetString("8060642451758603304960", 10)
feeFactorLsh79[180], _ = new(big.Int).SetString("8872302163198802395136", 10)
feeFactorLsh79[181], _ = new(big.Int).SetString("9765691276621298794496", 10)
feeFactorLsh79[182], _ = new(big.Int).SetString("10749039466425620627456", 10)
feeFactorLsh79[183], _ = new(big.Int).SetString("11831405087254623813632", 10)
feeFactorLsh79[184], _ = new(big.Int).SetString("13022758617264913645568", 10)
feeFactorLsh79[185], _ = new(big.Int).SetString("14334074503647983566848", 10)
feeFactorLsh79[186], _ = new(big.Int).SetString("15777432256460225511424", 10)
feeFactorLsh79[187], _ = new(big.Int).SetString("17366127722012377874432", 10)
feeFactorLsh79[188], _ = new(big.Int).SetString("19114795560840447655936", 10)
feeFactorLsh79[189], _ = new(big.Int).SetString("21039544058494662475776", 10)
feeFactorLsh79[190], _ = new(big.Int).SetString("23158103510989150355456", 10)
feeFactorLsh79[191], _ = new(big.Int).SetString("25489989551801103286272", 10)
feeFactorLsh79[192], _ = new(big.Int).SetString("28056682924947158335488", 10)
feeFactorLsh79[193], _ = new(big.Int).SetString("30881827360160754958336", 10)
feeFactorLsh79[194], _ = new(big.Int).SetString("33991447372945971740672", 10)
feeFactorLsh79[195], _ = new(big.Int).SetString("37414187995827814793216", 10)
feeFactorLsh79[196], _ = new(big.Int).SetString("41181578649142095249408", 10)
feeFactorLsh79[197], _ = new(big.Int).SetString("45328323582075170979840", 10)
feeFactorLsh79[198], _ = new(big.Int).SetString("49892621559424153026560", 10)
feeFactorLsh79[199], _ = new(big.Int).SetString("54916517738950525190144", 10)
feeFactorLsh79[200], _ = new(big.Int).SetString("60446290980731462090752", 10)
feeFactorLsh79[201], _ = new(big.Int).SetString("66532880156306033344512", 10)
feeFactorLsh79[202], _ = new(big.Int).SetString("73232353384667900018688", 10)
feeFactorLsh79[203], _ = new(big.Int).SetString("80606424517586030952448", 10)
feeFactorLsh79[204], _ = new(big.Int).SetString("88723021631988017659904", 10)
feeFactorLsh79[205], _ = new(big.Int).SetString("97656912766212987944960", 10)
feeFactorLsh79[206], _ = new(big.Int).SetString("107490394664256189497344", 10)
feeFactorLsh79[207], _ = new(big.Int).SetString("118314050872546242330624", 10)
feeFactorLsh79[208], _ = new(big.Int).SetString("130227586172649140649984", 10)
feeFactorLsh79[209], _ = new(big.Int).SetString("143340745036479844057088", 10)
feeFactorLsh79[210], _ = new(big.Int).SetString("157774322564602238337024", 10)
feeFactorLsh79[211], _ = new(big.Int).SetString("173661277220123782938624", 10)
feeFactorLsh79[212], _ = new(big.Int).SetString("191147955608404493336576", 10)
feeFactorLsh79[213], _ = new(big.Int).SetString("210395440584946633146368", 10)
feeFactorLsh79[214], _ = new(big.Int).SetString("231581035109891511943168", 10)
feeFactorLsh79[215], _ = new(big.Int).SetString("254899895518011024474112", 10)
feeFactorLsh79[216], _ = new(big.Int).SetString("280566829249471583354880", 10)
feeFactorLsh79[217], _ = new(big.Int).SetString("308818273601607516028928", 10)
feeFactorLsh79[218], _ = new(big.Int).SetString("339914473729459734183936", 10)
feeFactorLsh79[219], _ = new(big.Int).SetString("374141879958278114377728", 10)
feeFactorLsh79[220], _ = new(big.Int).SetString("411815786491420902162432", 10)
feeFactorLsh79[221], _ = new(big.Int).SetString("453283235820751760130048", 10)
feeFactorLsh79[222], _ = new(big.Int).SetString("498926215594241513488384", 10)
feeFactorLsh79[223], _ = new(big.Int).SetString("549165177389505251901440", 10)
feeFactorLsh79[224], _ = new(big.Int).SetString("604462909807314587353088", 10)
feeFactorLsh79[225], _ = new(big.Int).SetString("6044629098073145873530880", 10)
feeFactorLsh79[226], _ = new(big.Int).SetString("60446290980731458735308800", 10)
feeFactorLsh79[227], _ = new(big.Int).SetString("604462909807314587353088000", 10)
feeFactorLsh79[228], _ = new(big.Int).SetString("6044629098073145873530880000", 10)
feeFactorLsh79[229], _ = new(big.Int).SetString("60446290980731458735308800000", 10)
feeFactorLsh79[230], _ = new(big.Int).SetString("604462909807314587353088000000", 10)
feeFactorLsh79[231], _ = new(big.Int).SetString("6044629098073145873530880000000", 10)
feeFactorLsh79[232], _ = new(big.Int).SetString("60446290980731458735308800000000", 10)
feeFactorLsh79[233], _ = new(big.Int).SetString("604462909807314587353088000000000", 10)
feeFactorLsh79[234], _ = new(big.Int).SetString("6044629098073145873530880000000000", 10)
feeFactorLsh79[235], _ = new(big.Int).SetString("60446290980731458735308800000000000", 10)
feeFactorLsh79[236], _ = new(big.Int).SetString("604462909807314587353088000000000000", 10)
feeFactorLsh79[237], _ = new(big.Int).SetString("6044629098073145873530880000000000000", 10)
feeFactorLsh79[238], _ = new(big.Int).SetString("60446290980731458735308800000000000000", 10)
feeFactorLsh79[239], _ = new(big.Int).SetString("604462909807314587353088000000000000000", 10)
feeFactorLsh79[240], _ = new(big.Int).SetString("6044629098073145873530880000000000000000", 10)
feeFactorLsh79[241], _ = new(big.Int).SetString("60446290980731458735308800000000000000000", 10)
feeFactorLsh79[242], _ = new(big.Int).SetString("604462909807314587353088000000000000000000", 10)
feeFactorLsh79[243], _ = new(big.Int).SetString("6044629098073145873530880000000000000000000", 10)
feeFactorLsh79[244], _ = new(big.Int).SetString("60446290980731458735308800000000000000000000", 10)
feeFactorLsh79[245], _ = new(big.Int).SetString("604462909807314587353088000000000000000000000", 10)
feeFactorLsh79[246], _ = new(big.Int).SetString("6044629098073145873530880000000000000000000000", 10)
feeFactorLsh79[247], _ = new(big.Int).SetString("60446290980731458735308800000000000000000000000", 10)
feeFactorLsh79[248], _ = new(big.Int).SetString("604462909807314587353088000000000000000000000000", 10)
feeFactorLsh79[249], _ = new(big.Int).SetString("6044629098073145873530880000000000000000000000000", 10)
feeFactorLsh79[250], _ = new(big.Int).SetString("60446290980731458735308800000000000000000000000000", 10)
feeFactorLsh79[251], _ = new(big.Int).SetString("604462909807314587353088000000000000000000000000000", 10)
feeFactorLsh79[252], _ = new(big.Int).SetString("6044629098073145873530880000000000000000000000000000", 10)
feeFactorLsh79[253], _ = new(big.Int).SetString("60446290980731458735308800000000000000000000000000000", 10)
feeFactorLsh79[254], _ = new(big.Int).SetString("604462909807314587353088000000000000000000000000000000", 10)
feeFactorLsh79[255], _ = new(big.Int).SetString("6044629098073145873530880000000000000000000000000000000", 10)
func setFeeFactorLsh60(feeFactorLsh60 *[256]*big.Int) {
feeFactorLsh60[0], _ = new(big.Int).SetString("0", 10)
feeFactorLsh60[1], _ = new(big.Int).SetString("3", 10)
feeFactorLsh60[2], _ = new(big.Int).SetString("9", 10)
feeFactorLsh60[3], _ = new(big.Int).SetString("29", 10)
feeFactorLsh60[4], _ = new(big.Int).SetString("90", 10)
feeFactorLsh60[5], _ = new(big.Int).SetString("279", 10)
feeFactorLsh60[6], _ = new(big.Int).SetString("861", 10)
feeFactorLsh60[7], _ = new(big.Int).SetString("2655", 10)
feeFactorLsh60[8], _ = new(big.Int).SetString("8192", 10)
feeFactorLsh60[9], _ = new(big.Int).SetString("25267", 10)
feeFactorLsh60[10], _ = new(big.Int).SetString("77935", 10)
feeFactorLsh60[11], _ = new(big.Int).SetString("240387", 10)
feeFactorLsh60[12], _ = new(big.Int).SetString("741455", 10)
feeFactorLsh60[13], _ = new(big.Int).SetString("2286960", 10)
feeFactorLsh60[14], _ = new(big.Int).SetString("7053950", 10)
feeFactorLsh60[15], _ = new(big.Int).SetString("21757357", 10)
feeFactorLsh60[16], _ = new(big.Int).SetString("67108864", 10)
feeFactorLsh60[17], _ = new(big.Int).SetString("206992033", 10)
feeFactorLsh60[18], _ = new(big.Int).SetString("638450708", 10)
feeFactorLsh60[19], _ = new(big.Int).SetString("1969251187", 10)
feeFactorLsh60[20], _ = new(big.Int).SetString("6074000999", 10)
feeFactorLsh60[21], _ = new(big.Int).SetString("18734780191", 10)
feeFactorLsh60[22], _ = new(big.Int).SetString("57785961645", 10)
feeFactorLsh60[23], _ = new(big.Int).SetString("178236271212", 10)
feeFactorLsh60[24], _ = new(big.Int).SetString("549755813888", 10)
feeFactorLsh60[25], _ = new(big.Int).SetString("1695678735018", 10)
feeFactorLsh60[26], _ = new(big.Int).SetString("5230188203117", 10)
feeFactorLsh60[27], _ = new(big.Int).SetString("16132105731538", 10)
feeFactorLsh60[28], _ = new(big.Int).SetString("49758216191607", 10)
feeFactorLsh60[29], _ = new(big.Int).SetString("153475319327371", 10)
feeFactorLsh60[30], _ = new(big.Int).SetString("473382597799226", 10)
feeFactorLsh60[31], _ = new(big.Int).SetString("1460111533771401", 10)
feeFactorLsh60[32], _ = new(big.Int).SetString("4503599627370496", 10)
feeFactorLsh60[33], _ = new(big.Int).SetString("4662418725241772", 10)
feeFactorLsh60[34], _ = new(big.Int).SetString("4826838566504035", 10)
feeFactorLsh60[35], _ = new(big.Int).SetString("4997056660946426", 10)
feeFactorLsh60[36], _ = new(big.Int).SetString("5173277483525749", 10)
feeFactorLsh60[37], _ = new(big.Int).SetString("5355712719992597", 10)
feeFactorLsh60[38], _ = new(big.Int).SetString("5544581521179432", 10)
feeFactorLsh60[39], _ = new(big.Int).SetString("5740110766256133", 10)
feeFactorLsh60[40], _ = new(big.Int).SetString("5942535335269230", 10)
feeFactorLsh60[41], _ = new(big.Int).SetString("6152098391292193", 10)
feeFactorLsh60[42], _ = new(big.Int).SetString("6369051672525772", 10)
feeFactorLsh60[43], _ = new(big.Int).SetString("6593655794699191", 10)
feeFactorLsh60[44], _ = new(big.Int).SetString("6826180564135515", 10)
feeFactorLsh60[45], _ = new(big.Int).SetString("7066905301857248", 10)
feeFactorLsh60[46], _ = new(big.Int).SetString("7316119179121470", 10)
feeFactorLsh60[47], _ = new(big.Int).SetString("7574121564787630", 10)
feeFactorLsh60[48], _ = new(big.Int).SetString("7841222384935199", 10)
feeFactorLsh60[49], _ = new(big.Int).SetString("8117742495163242", 10)
feeFactorLsh60[50], _ = new(big.Int).SetString("8404014066019092", 10)
feeFactorLsh60[51], _ = new(big.Int).SetString("8700380982019120", 10)
feeFactorLsh60[52], _ = new(big.Int).SetString("9007199254740992", 10)
feeFactorLsh60[53], _ = new(big.Int).SetString("9324837450483544", 10)
feeFactorLsh60[54], _ = new(big.Int).SetString("9653677133008070", 10)
feeFactorLsh60[55], _ = new(big.Int).SetString("9994113321892852", 10)
feeFactorLsh60[56], _ = new(big.Int).SetString("10346554967051498", 10)
feeFactorLsh60[57], _ = new(big.Int).SetString("10711425439985194", 10)
feeFactorLsh60[58], _ = new(big.Int).SetString("11089163042358864", 10)
feeFactorLsh60[59], _ = new(big.Int).SetString("11480221532512266", 10)
feeFactorLsh60[60], _ = new(big.Int).SetString("11885070670538460", 10)
feeFactorLsh60[61], _ = new(big.Int).SetString("12304196782584386", 10)
feeFactorLsh60[62], _ = new(big.Int).SetString("12738103345051544", 10)
feeFactorLsh60[63], _ = new(big.Int).SetString("13187311589398382", 10)
feeFactorLsh60[64], _ = new(big.Int).SetString("13652361128271030", 10)
feeFactorLsh60[65], _ = new(big.Int).SetString("14133810603714496", 10)
feeFactorLsh60[66], _ = new(big.Int).SetString("14632238358242940", 10)
feeFactorLsh60[67], _ = new(big.Int).SetString("15148243129575260", 10)
feeFactorLsh60[68], _ = new(big.Int).SetString("15682444769870398", 10)
feeFactorLsh60[69], _ = new(big.Int).SetString("16235484990326484", 10)
feeFactorLsh60[70], _ = new(big.Int).SetString("16808028132038184", 10)
feeFactorLsh60[71], _ = new(big.Int).SetString("17400761964038240", 10)
feeFactorLsh60[72], _ = new(big.Int).SetString("18014398509481984", 10)
feeFactorLsh60[73], _ = new(big.Int).SetString("18649674900967100", 10)
feeFactorLsh60[74], _ = new(big.Int).SetString("19307354266016140", 10)
feeFactorLsh60[75], _ = new(big.Int).SetString("19988226643785704", 10)
feeFactorLsh60[76], _ = new(big.Int).SetString("20693109934102996", 10)
feeFactorLsh60[77], _ = new(big.Int).SetString("21422850879970388", 10)
feeFactorLsh60[78], _ = new(big.Int).SetString("22178326084717744", 10)
feeFactorLsh60[79], _ = new(big.Int).SetString("22960443065024532", 10)
feeFactorLsh60[80], _ = new(big.Int).SetString("23770141341076920", 10)
feeFactorLsh60[81], _ = new(big.Int).SetString("24608393565168772", 10)
feeFactorLsh60[82], _ = new(big.Int).SetString("25476206690103088", 10)
feeFactorLsh60[83], _ = new(big.Int).SetString("26374623178796784", 10)
feeFactorLsh60[84], _ = new(big.Int).SetString("27304722256542060", 10)
feeFactorLsh60[85], _ = new(big.Int).SetString("28267621207428992", 10)
feeFactorLsh60[86], _ = new(big.Int).SetString("29264476716485880", 10)
feeFactorLsh60[87], _ = new(big.Int).SetString("30296486259150520", 10)
feeFactorLsh60[88], _ = new(big.Int).SetString("31364889539740816", 10)
feeFactorLsh60[89], _ = new(big.Int).SetString("32470969980652968", 10)
feeFactorLsh60[90], _ = new(big.Int).SetString("33616056264076368", 10)
feeFactorLsh60[91], _ = new(big.Int).SetString("34801523928076480", 10)
feeFactorLsh60[92], _ = new(big.Int).SetString("36028797018963968", 10)
feeFactorLsh60[93], _ = new(big.Int).SetString("37299349801934200", 10)
feeFactorLsh60[94], _ = new(big.Int).SetString("38614708532032280", 10)
feeFactorLsh60[95], _ = new(big.Int).SetString("39976453287571408", 10)
feeFactorLsh60[96], _ = new(big.Int).SetString("41386219868205992", 10)
feeFactorLsh60[97], _ = new(big.Int).SetString("42845701759940776", 10)
feeFactorLsh60[98], _ = new(big.Int).SetString("44356652169435488", 10)
feeFactorLsh60[99], _ = new(big.Int).SetString("45920886130049064", 10)
feeFactorLsh60[100], _ = new(big.Int).SetString("47540282682153840", 10)
feeFactorLsh60[101], _ = new(big.Int).SetString("49216787130337544", 10)
feeFactorLsh60[102], _ = new(big.Int).SetString("50952413380206176", 10)
feeFactorLsh60[103], _ = new(big.Int).SetString("52749246357593568", 10)
feeFactorLsh60[104], _ = new(big.Int).SetString("54609444513084120", 10)
feeFactorLsh60[105], _ = new(big.Int).SetString("56535242414857984", 10)
feeFactorLsh60[106], _ = new(big.Int).SetString("58528953432971760", 10)
feeFactorLsh60[107], _ = new(big.Int).SetString("60592972518301040", 10)
feeFactorLsh60[108], _ = new(big.Int).SetString("62729779079481632", 10)
feeFactorLsh60[109], _ = new(big.Int).SetString("64941939961305936", 10)
feeFactorLsh60[110], _ = new(big.Int).SetString("67232112528152736", 10)
feeFactorLsh60[111], _ = new(big.Int).SetString("69603047856152960", 10)
feeFactorLsh60[112], _ = new(big.Int).SetString("72057594037927936", 10)
feeFactorLsh60[113], _ = new(big.Int).SetString("74598699603868352", 10)
feeFactorLsh60[114], _ = new(big.Int).SetString("77229417064064608", 10)
feeFactorLsh60[115], _ = new(big.Int).SetString("79952906575142816", 10)
feeFactorLsh60[116], _ = new(big.Int).SetString("82772439736411984", 10)
feeFactorLsh60[117], _ = new(big.Int).SetString("85691403519881552", 10)
feeFactorLsh60[118], _ = new(big.Int).SetString("88713304338870912", 10)
feeFactorLsh60[119], _ = new(big.Int).SetString("91841772260098192", 10)
feeFactorLsh60[120], _ = new(big.Int).SetString("95080565364307680", 10)
feeFactorLsh60[121], _ = new(big.Int).SetString("98433574260675088", 10)
feeFactorLsh60[122], _ = new(big.Int).SetString("101904826760412352", 10)
feeFactorLsh60[123], _ = new(big.Int).SetString("105498492715187056", 10)
feeFactorLsh60[124], _ = new(big.Int).SetString("109218889026168304", 10)
feeFactorLsh60[125], _ = new(big.Int).SetString("113070484829715968", 10)
feeFactorLsh60[126], _ = new(big.Int).SetString("117057906865943520", 10)
feeFactorLsh60[127], _ = new(big.Int).SetString("121185945036602080", 10)
feeFactorLsh60[128], _ = new(big.Int).SetString("125459558158963264", 10)
feeFactorLsh60[129], _ = new(big.Int).SetString("129883879922611968", 10)
feeFactorLsh60[130], _ = new(big.Int).SetString("134464225056305472", 10)
feeFactorLsh60[131], _ = new(big.Int).SetString("139206095712305920", 10)
feeFactorLsh60[132], _ = new(big.Int).SetString("144115188075855872", 10)
feeFactorLsh60[133], _ = new(big.Int).SetString("149197399207736800", 10)
feeFactorLsh60[134], _ = new(big.Int).SetString("154458834128129216", 10)
feeFactorLsh60[135], _ = new(big.Int).SetString("159905813150285632", 10)
feeFactorLsh60[136], _ = new(big.Int).SetString("165544879472823968", 10)
feeFactorLsh60[137], _ = new(big.Int).SetString("171382807039763104", 10)
feeFactorLsh60[138], _ = new(big.Int).SetString("177426608677741952", 10)
feeFactorLsh60[139], _ = new(big.Int).SetString("183683544520196384", 10)
feeFactorLsh60[140], _ = new(big.Int).SetString("190161130728615360", 10)
feeFactorLsh60[141], _ = new(big.Int).SetString("196867148521350176", 10)
feeFactorLsh60[142], _ = new(big.Int).SetString("203809653520824704", 10)
feeFactorLsh60[143], _ = new(big.Int).SetString("210996985430374272", 10)
feeFactorLsh60[144], _ = new(big.Int).SetString("218437778052336608", 10)
feeFactorLsh60[145], _ = new(big.Int).SetString("226140969659431936", 10)
feeFactorLsh60[146], _ = new(big.Int).SetString("234115813731887040", 10)
feeFactorLsh60[147], _ = new(big.Int).SetString("242371890073204160", 10)
feeFactorLsh60[148], _ = new(big.Int).SetString("250919116317926528", 10)
feeFactorLsh60[149], _ = new(big.Int).SetString("259767759845223936", 10)
feeFactorLsh60[150], _ = new(big.Int).SetString("268928450112610944", 10)
feeFactorLsh60[151], _ = new(big.Int).SetString("278412191424611840", 10)
feeFactorLsh60[152], _ = new(big.Int).SetString("288230376151711744", 10)
feeFactorLsh60[153], _ = new(big.Int).SetString("298394798415473600", 10)
feeFactorLsh60[154], _ = new(big.Int).SetString("308917668256258432", 10)
feeFactorLsh60[155], _ = new(big.Int).SetString("319811626300571264", 10)
feeFactorLsh60[156], _ = new(big.Int).SetString("331089758945647936", 10)
feeFactorLsh60[157], _ = new(big.Int).SetString("342765614079526208", 10)
feeFactorLsh60[158], _ = new(big.Int).SetString("354853217355483904", 10)
feeFactorLsh60[159], _ = new(big.Int).SetString("367367089040392768", 10)
feeFactorLsh60[160], _ = new(big.Int).SetString("380322261457230720", 10)
feeFactorLsh60[161], _ = new(big.Int).SetString("393734297042700352", 10)
feeFactorLsh60[162], _ = new(big.Int).SetString("407619307041649408", 10)
feeFactorLsh60[163], _ = new(big.Int).SetString("421993970860748544", 10)
feeFactorLsh60[164], _ = new(big.Int).SetString("436875556104673216", 10)
feeFactorLsh60[165], _ = new(big.Int).SetString("452281939318863872", 10)
feeFactorLsh60[166], _ = new(big.Int).SetString("468231627463774080", 10)
feeFactorLsh60[167], _ = new(big.Int).SetString("484743780146408320", 10)
feeFactorLsh60[168], _ = new(big.Int).SetString("501838232635853056", 10)
feeFactorLsh60[169], _ = new(big.Int).SetString("519535519690447872", 10)
feeFactorLsh60[170], _ = new(big.Int).SetString("537856900225221888", 10)
feeFactorLsh60[171], _ = new(big.Int).SetString("556824382849223680", 10)
feeFactorLsh60[172], _ = new(big.Int).SetString("576460752303423488", 10)
feeFactorLsh60[173], _ = new(big.Int).SetString("596789596830947200", 10)
feeFactorLsh60[174], _ = new(big.Int).SetString("617835336512516864", 10)
feeFactorLsh60[175], _ = new(big.Int).SetString("639623252601142528", 10)
feeFactorLsh60[176], _ = new(big.Int).SetString("662179517891295872", 10)
feeFactorLsh60[177], _ = new(big.Int).SetString("685531228159052416", 10)
feeFactorLsh60[178], _ = new(big.Int).SetString("709706434710967808", 10)
feeFactorLsh60[179], _ = new(big.Int).SetString("734734178080785536", 10)
feeFactorLsh60[180], _ = new(big.Int).SetString("760644522914461440", 10)
feeFactorLsh60[181], _ = new(big.Int).SetString("787468594085400704", 10)
feeFactorLsh60[182], _ = new(big.Int).SetString("815238614083298816", 10)
feeFactorLsh60[183], _ = new(big.Int).SetString("843987941721497088", 10)
feeFactorLsh60[184], _ = new(big.Int).SetString("873751112209346432", 10)
feeFactorLsh60[185], _ = new(big.Int).SetString("904563878637727744", 10)
feeFactorLsh60[186], _ = new(big.Int).SetString("936463254927548160", 10)
feeFactorLsh60[187], _ = new(big.Int).SetString("969487560292816640", 10)
feeFactorLsh60[188], _ = new(big.Int).SetString("1003676465271706112", 10)
feeFactorLsh60[189], _ = new(big.Int).SetString("1039071039380895744", 10)
feeFactorLsh60[190], _ = new(big.Int).SetString("1075713800450443776", 10)
feeFactorLsh60[191], _ = new(big.Int).SetString("1113648765698447360", 10)
feeFactorLsh60[192], _ = new(big.Int).SetString("1", 10)
feeFactorLsh60[193], _ = new(big.Int).SetString("2", 10)
feeFactorLsh60[194], _ = new(big.Int).SetString("4", 10)
feeFactorLsh60[195], _ = new(big.Int).SetString("8", 10)
feeFactorLsh60[196], _ = new(big.Int).SetString("16", 10)
feeFactorLsh60[197], _ = new(big.Int).SetString("32", 10)
feeFactorLsh60[198], _ = new(big.Int).SetString("64", 10)
feeFactorLsh60[199], _ = new(big.Int).SetString("128", 10)
feeFactorLsh60[200], _ = new(big.Int).SetString("256", 10)
feeFactorLsh60[201], _ = new(big.Int).SetString("512", 10)
feeFactorLsh60[202], _ = new(big.Int).SetString("1024", 10)
feeFactorLsh60[203], _ = new(big.Int).SetString("2048", 10)
feeFactorLsh60[204], _ = new(big.Int).SetString("4096", 10)
feeFactorLsh60[205], _ = new(big.Int).SetString("8192", 10)
feeFactorLsh60[206], _ = new(big.Int).SetString("16384", 10)
feeFactorLsh60[207], _ = new(big.Int).SetString("32768", 10)
feeFactorLsh60[208], _ = new(big.Int).SetString("65536", 10)
feeFactorLsh60[209], _ = new(big.Int).SetString("131072", 10)
feeFactorLsh60[210], _ = new(big.Int).SetString("262144", 10)
feeFactorLsh60[211], _ = new(big.Int).SetString("524288", 10)
feeFactorLsh60[212], _ = new(big.Int).SetString("1048576", 10)
feeFactorLsh60[213], _ = new(big.Int).SetString("2097152", 10)
feeFactorLsh60[214], _ = new(big.Int).SetString("4194304", 10)
feeFactorLsh60[215], _ = new(big.Int).SetString("8388608", 10)
feeFactorLsh60[216], _ = new(big.Int).SetString("16777216", 10)
feeFactorLsh60[217], _ = new(big.Int).SetString("33554432", 10)
feeFactorLsh60[218], _ = new(big.Int).SetString("67108864", 10)
feeFactorLsh60[219], _ = new(big.Int).SetString("134217728", 10)
feeFactorLsh60[220], _ = new(big.Int).SetString("268435456", 10)
feeFactorLsh60[221], _ = new(big.Int).SetString("536870912", 10)
feeFactorLsh60[222], _ = new(big.Int).SetString("1073741824", 10)
feeFactorLsh60[223], _ = new(big.Int).SetString("2147483648", 10)
feeFactorLsh60[224], _ = new(big.Int).SetString("4294967296", 10)
feeFactorLsh60[225], _ = new(big.Int).SetString("8589934592", 10)
feeFactorLsh60[226], _ = new(big.Int).SetString("17179869184", 10)
feeFactorLsh60[227], _ = new(big.Int).SetString("34359738368", 10)
feeFactorLsh60[228], _ = new(big.Int).SetString("68719476736", 10)
feeFactorLsh60[229], _ = new(big.Int).SetString("137438953472", 10)
feeFactorLsh60[230], _ = new(big.Int).SetString("274877906944", 10)
feeFactorLsh60[231], _ = new(big.Int).SetString("549755813888", 10)
feeFactorLsh60[232], _ = new(big.Int).SetString("1099511627776", 10)
feeFactorLsh60[233], _ = new(big.Int).SetString("2199023255552", 10)
feeFactorLsh60[234], _ = new(big.Int).SetString("4398046511104", 10)
feeFactorLsh60[235], _ = new(big.Int).SetString("8796093022208", 10)
feeFactorLsh60[236], _ = new(big.Int).SetString("17592186044416", 10)
feeFactorLsh60[237], _ = new(big.Int).SetString("35184372088832", 10)
feeFactorLsh60[238], _ = new(big.Int).SetString("70368744177664", 10)
feeFactorLsh60[239], _ = new(big.Int).SetString("140737488355328", 10)
feeFactorLsh60[240], _ = new(big.Int).SetString("281474976710656", 10)
feeFactorLsh60[241], _ = new(big.Int).SetString("562949953421312", 10)
feeFactorLsh60[242], _ = new(big.Int).SetString("1125899906842624", 10)
feeFactorLsh60[243], _ = new(big.Int).SetString("2251799813685248", 10)
feeFactorLsh60[244], _ = new(big.Int).SetString("4503599627370496", 10)
feeFactorLsh60[245], _ = new(big.Int).SetString("9007199254740992", 10)
feeFactorLsh60[246], _ = new(big.Int).SetString("18014398509481984", 10)
feeFactorLsh60[247], _ = new(big.Int).SetString("36028797018963968", 10)
feeFactorLsh60[248], _ = new(big.Int).SetString("72057594037927936", 10)
feeFactorLsh60[249], _ = new(big.Int).SetString("144115188075855872", 10)
feeFactorLsh60[250], _ = new(big.Int).SetString("288230376151711744", 10)
feeFactorLsh60[251], _ = new(big.Int).SetString("576460752303423488", 10)
feeFactorLsh60[252], _ = new(big.Int).SetString("1152921504606846976", 10)
feeFactorLsh60[253], _ = new(big.Int).SetString("2305843009213693952", 10)
feeFactorLsh60[254], _ = new(big.Int).SetString("4611686018427387904", 10)
feeFactorLsh60[255], _ = new(big.Int).SetString("9223372036854775808", 10)
} }

+ 35
- 9
common/fee_test.go

@ -1,29 +1,55 @@
package common package common
import ( import (
"fmt"
"math/big" "math/big"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestFeePercentage(t *testing.T) {
assert.InEpsilon(t, 2.68E-18, FeeSelector(1).Percentage(), 0.002)
assert.InEpsilon(t, 6.76E-14, FeeSelector(10).Percentage(), 0.002)
assert.InEpsilon(t, 3.91E-03, FeeSelector(32).Percentage(), 0.002)
assert.InEpsilon(t, 7.29E-03, FeeSelector(50).Percentage(), 0.002)
assert.InEpsilon(t, 4.12E-02, FeeSelector(100).Percentage(), 0.002)
assert.InEpsilon(t, 2.33E-01, FeeSelector(150).Percentage(), 0.002)
assert.InEpsilon(t, 1.00E+00, FeeSelector(192).Percentage(), 0.002)
assert.InEpsilon(t, 2.56E+02, FeeSelector(200).Percentage(), 0.002)
assert.InEpsilon(t, 2.88E+17, FeeSelector(250).Percentage(), 0.002)
}
func TestCalcFeeAmount(t *testing.T) { func TestCalcFeeAmount(t *testing.T) {
v := big.NewInt(1000) v := big.NewInt(1000)
feeAmount := CalcFeeAmount(v, FeeSelector(225)) // 1000%
assert.Equal(t, "10000", feeAmount.String())
feeAmount, err := CalcFeeAmount(v, FeeSelector(195)) // 800%
assert.Nil(t, err)
assert.Equal(t, "8000", feeAmount.String())
feeAmount = CalcFeeAmount(v, FeeSelector(224)) // 100%
feeAmount, err = CalcFeeAmount(v, FeeSelector(192)) // 100%
assert.Nil(t, err)
assert.Equal(t, "1000", feeAmount.String()) assert.Equal(t, "1000", feeAmount.String())
feeAmount = CalcFeeAmount(v, FeeSelector(200)) // 10%
assert.Equal(t, "100", feeAmount.String())
feeAmount, err = CalcFeeAmount(v, FeeSelector(172)) // 50%
assert.Nil(t, err)
assert.Equal(t, "500", feeAmount.String())
feeAmount = CalcFeeAmount(v, FeeSelector(193)) // 5.11%
assert.Equal(t, "51", feeAmount.String())
feeAmount, err = CalcFeeAmount(v, FeeSelector(126)) // 10.2%
assert.Nil(t, err)
assert.Equal(t, "101", feeAmount.String())
feeAmount = CalcFeeAmount(v, FeeSelector(176)) // 1%
feeAmount, err = CalcFeeAmount(v, FeeSelector(60)) // 1.03%
assert.Nil(t, err)
assert.Equal(t, "10", feeAmount.String()) assert.Equal(t, "10", feeAmount.String())
feeAmount = CalcFeeAmount(v, FeeSelector(152)) // 0.1%
feeAmount, err = CalcFeeAmount(v, FeeSelector(31)) // 0.127%
assert.Nil(t, err)
assert.Equal(t, "1", feeAmount.String()) assert.Equal(t, "1", feeAmount.String())
} }
func TestFeePrintSQLSwitch(t *testing.T) {
for i := 0; i < 256; i++ {
f := FeeSelector(i).Percentage()
fmt.Printf(" WHEN $1 = %03d THEN %.6e\n", i, f)
}
}

+ 257
- 257
db/migrations/0001.sql

@ -170,262 +170,262 @@ $BODY$
DECLARE perc NUMERIC; DECLARE perc NUMERIC;
BEGIN BEGIN
SELECT CASE SELECT CASE
WHEN $1 = 0 THEN 0
WHEN $1 = 1 THEN 3.162278e-24
WHEN $1 = 2 THEN 1.000000e-23
WHEN $1 = 3 THEN 3.162278e-23
WHEN $1 = 4 THEN 1.000000e-22
WHEN $1 = 5 THEN 3.162278e-22
WHEN $1 = 6 THEN 1.000000e-21
WHEN $1 = 7 THEN 3.162278e-21
WHEN $1 = 8 THEN 1.000000e-20
WHEN $1 = 9 THEN 3.162278e-20
WHEN $1 = 10 THEN 1.000000e-19
WHEN $1 = 11 THEN 3.162278e-19
WHEN $1 = 12 THEN 1.000000e-18
WHEN $1 = 13 THEN 3.162278e-18
WHEN $1 = 14 THEN 1.000000e-17
WHEN $1 = 15 THEN 3.162278e-17
WHEN $1 = 16 THEN 1.000000e-16
WHEN $1 = 17 THEN 3.162278e-16
WHEN $1 = 18 THEN 1.000000e-15
WHEN $1 = 19 THEN 3.162278e-15
WHEN $1 = 20 THEN 1.000000e-14
WHEN $1 = 21 THEN 3.162278e-14
WHEN $1 = 22 THEN 1.000000e-13
WHEN $1 = 23 THEN 3.162278e-13
WHEN $1 = 24 THEN 1.000000e-12
WHEN $1 = 25 THEN 3.162278e-12
WHEN $1 = 26 THEN 1.000000e-11
WHEN $1 = 27 THEN 3.162278e-11
WHEN $1 = 28 THEN 1.000000e-10
WHEN $1 = 29 THEN 3.162278e-10
WHEN $1 = 30 THEN 1.000000e-09
WHEN $1 = 31 THEN 3.162278e-09
WHEN $1 = 32 THEN 1.000000e-08
WHEN $1 = 33 THEN 1.100694e-08
WHEN $1 = 34 THEN 1.211528e-08
WHEN $1 = 35 THEN 1.333521e-08
WHEN $1 = 36 THEN 1.467799e-08
WHEN $1 = 37 THEN 1.615598e-08
WHEN $1 = 38 THEN 1.778279e-08
WHEN $1 = 39 THEN 1.957342e-08
WHEN $1 = 40 THEN 2.154435e-08
WHEN $1 = 41 THEN 2.371374e-08
WHEN $1 = 42 THEN 2.610157e-08
WHEN $1 = 43 THEN 2.872985e-08
WHEN $1 = 44 THEN 3.162278e-08
WHEN $1 = 45 THEN 3.480701e-08
WHEN $1 = 46 THEN 3.831187e-08
WHEN $1 = 47 THEN 4.216965e-08
WHEN $1 = 48 THEN 4.641589e-08
WHEN $1 = 49 THEN 5.108970e-08
WHEN $1 = 50 THEN 5.623413e-08
WHEN $1 = 51 THEN 6.189658e-08
WHEN $1 = 52 THEN 6.812921e-08
WHEN $1 = 53 THEN 7.498942e-08
WHEN $1 = 54 THEN 8.254042e-08
WHEN $1 = 55 THEN 9.085176e-08
WHEN $1 = 56 THEN 1.000000e-07
WHEN $1 = 57 THEN 1.100694e-07
WHEN $1 = 58 THEN 1.211528e-07
WHEN $1 = 59 THEN 1.333521e-07
WHEN $1 = 60 THEN 1.467799e-07
WHEN $1 = 61 THEN 1.615598e-07
WHEN $1 = 62 THEN 1.778279e-07
WHEN $1 = 63 THEN 1.957342e-07
WHEN $1 = 64 THEN 2.154435e-07
WHEN $1 = 65 THEN 2.371374e-07
WHEN $1 = 66 THEN 2.610157e-07
WHEN $1 = 67 THEN 2.872985e-07
WHEN $1 = 68 THEN 3.162278e-07
WHEN $1 = 69 THEN 3.480701e-07
WHEN $1 = 70 THEN 3.831187e-07
WHEN $1 = 71 THEN 4.216965e-07
WHEN $1 = 72 THEN 4.641589e-07
WHEN $1 = 73 THEN 5.108970e-07
WHEN $1 = 74 THEN 5.623413e-07
WHEN $1 = 75 THEN 6.189658e-07
WHEN $1 = 76 THEN 6.812921e-07
WHEN $1 = 77 THEN 7.498942e-07
WHEN $1 = 78 THEN 8.254042e-07
WHEN $1 = 79 THEN 9.085176e-07
WHEN $1 = 80 THEN 1.000000e-06
WHEN $1 = 81 THEN 1.100694e-06
WHEN $1 = 82 THEN 1.211528e-06
WHEN $1 = 83 THEN 1.333521e-06
WHEN $1 = 84 THEN 1.467799e-06
WHEN $1 = 85 THEN 1.615598e-06
WHEN $1 = 86 THEN 1.778279e-06
WHEN $1 = 87 THEN 1.957342e-06
WHEN $1 = 88 THEN 2.154435e-06
WHEN $1 = 89 THEN 2.371374e-06
WHEN $1 = 90 THEN 2.610157e-06
WHEN $1 = 91 THEN 2.872985e-06
WHEN $1 = 92 THEN 3.162278e-06
WHEN $1 = 93 THEN 3.480701e-06
WHEN $1 = 94 THEN 3.831187e-06
WHEN $1 = 95 THEN 4.216965e-06
WHEN $1 = 96 THEN 4.641589e-06
WHEN $1 = 97 THEN 5.108970e-06
WHEN $1 = 98 THEN 5.623413e-06
WHEN $1 = 99 THEN 6.189658e-06
WHEN $1 = 100 THEN 6.812921e-06
WHEN $1 = 101 THEN 7.498942e-06
WHEN $1 = 102 THEN 8.254042e-06
WHEN $1 = 103 THEN 9.085176e-06
WHEN $1 = 104 THEN 1.000000e-05
WHEN $1 = 105 THEN 1.100694e-05
WHEN $1 = 106 THEN 1.211528e-05
WHEN $1 = 107 THEN 1.333521e-05
WHEN $1 = 108 THEN 1.467799e-05
WHEN $1 = 109 THEN 1.615598e-05
WHEN $1 = 110 THEN 1.778279e-05
WHEN $1 = 111 THEN 1.957342e-05
WHEN $1 = 112 THEN 2.154435e-05
WHEN $1 = 113 THEN 2.371374e-05
WHEN $1 = 114 THEN 2.610157e-05
WHEN $1 = 115 THEN 2.872985e-05
WHEN $1 = 116 THEN 3.162278e-05
WHEN $1 = 117 THEN 3.480701e-05
WHEN $1 = 118 THEN 3.831187e-05
WHEN $1 = 119 THEN 4.216965e-05
WHEN $1 = 120 THEN 4.641589e-05
WHEN $1 = 121 THEN 5.108970e-05
WHEN $1 = 122 THEN 5.623413e-05
WHEN $1 = 123 THEN 6.189658e-05
WHEN $1 = 124 THEN 6.812921e-05
WHEN $1 = 125 THEN 7.498942e-05
WHEN $1 = 126 THEN 8.254042e-05
WHEN $1 = 127 THEN 9.085176e-05
WHEN $1 = 128 THEN 1.000000e-04
WHEN $1 = 129 THEN 1.100694e-04
WHEN $1 = 130 THEN 1.211528e-04
WHEN $1 = 131 THEN 1.333521e-04
WHEN $1 = 132 THEN 1.467799e-04
WHEN $1 = 133 THEN 1.615598e-04
WHEN $1 = 134 THEN 1.778279e-04
WHEN $1 = 135 THEN 1.957342e-04
WHEN $1 = 136 THEN 2.154435e-04
WHEN $1 = 137 THEN 2.371374e-04
WHEN $1 = 138 THEN 2.610157e-04
WHEN $1 = 139 THEN 2.872985e-04
WHEN $1 = 140 THEN 3.162278e-04
WHEN $1 = 141 THEN 3.480701e-04
WHEN $1 = 142 THEN 3.831187e-04
WHEN $1 = 143 THEN 4.216965e-04
WHEN $1 = 144 THEN 4.641589e-04
WHEN $1 = 145 THEN 5.108970e-04
WHEN $1 = 146 THEN 5.623413e-04
WHEN $1 = 147 THEN 6.189658e-04
WHEN $1 = 148 THEN 6.812921e-04
WHEN $1 = 149 THEN 7.498942e-04
WHEN $1 = 150 THEN 8.254042e-04
WHEN $1 = 151 THEN 9.085176e-04
WHEN $1 = 152 THEN 1.000000e-03
WHEN $1 = 153 THEN 1.100694e-03
WHEN $1 = 154 THEN 1.211528e-03
WHEN $1 = 155 THEN 1.333521e-03
WHEN $1 = 156 THEN 1.467799e-03
WHEN $1 = 157 THEN 1.615598e-03
WHEN $1 = 158 THEN 1.778279e-03
WHEN $1 = 159 THEN 1.957342e-03
WHEN $1 = 160 THEN 2.154435e-03
WHEN $1 = 161 THEN 2.371374e-03
WHEN $1 = 162 THEN 2.610157e-03
WHEN $1 = 163 THEN 2.872985e-03
WHEN $1 = 164 THEN 3.162278e-03
WHEN $1 = 165 THEN 3.480701e-03
WHEN $1 = 166 THEN 3.831187e-03
WHEN $1 = 167 THEN 4.216965e-03
WHEN $1 = 168 THEN 4.641589e-03
WHEN $1 = 169 THEN 5.108970e-03
WHEN $1 = 170 THEN 5.623413e-03
WHEN $1 = 171 THEN 6.189658e-03
WHEN $1 = 172 THEN 6.812921e-03
WHEN $1 = 173 THEN 7.498942e-03
WHEN $1 = 174 THEN 8.254042e-03
WHEN $1 = 175 THEN 9.085176e-03
WHEN $1 = 176 THEN 1.000000e-02
WHEN $1 = 177 THEN 1.100694e-02
WHEN $1 = 178 THEN 1.211528e-02
WHEN $1 = 179 THEN 1.333521e-02
WHEN $1 = 180 THEN 1.467799e-02
WHEN $1 = 181 THEN 1.615598e-02
WHEN $1 = 182 THEN 1.778279e-02
WHEN $1 = 183 THEN 1.957342e-02
WHEN $1 = 184 THEN 2.154435e-02
WHEN $1 = 185 THEN 2.371374e-02
WHEN $1 = 186 THEN 2.610157e-02
WHEN $1 = 187 THEN 2.872985e-02
WHEN $1 = 188 THEN 3.162278e-02
WHEN $1 = 189 THEN 3.480701e-02
WHEN $1 = 190 THEN 3.831187e-02
WHEN $1 = 191 THEN 4.216965e-02
WHEN $1 = 192 THEN 4.641589e-02
WHEN $1 = 193 THEN 5.108970e-02
WHEN $1 = 194 THEN 5.623413e-02
WHEN $1 = 195 THEN 6.189658e-02
WHEN $1 = 196 THEN 6.812921e-02
WHEN $1 = 197 THEN 7.498942e-02
WHEN $1 = 198 THEN 8.254042e-02
WHEN $1 = 199 THEN 9.085176e-02
WHEN $1 = 200 THEN 1.000000e-01
WHEN $1 = 201 THEN 1.100694e-01
WHEN $1 = 202 THEN 1.211528e-01
WHEN $1 = 203 THEN 1.333521e-01
WHEN $1 = 204 THEN 1.467799e-01
WHEN $1 = 205 THEN 1.615598e-01
WHEN $1 = 206 THEN 1.778279e-01
WHEN $1 = 207 THEN 1.957342e-01
WHEN $1 = 208 THEN 2.154435e-01
WHEN $1 = 209 THEN 2.371374e-01
WHEN $1 = 210 THEN 2.610157e-01
WHEN $1 = 211 THEN 2.872985e-01
WHEN $1 = 212 THEN 3.162278e-01
WHEN $1 = 213 THEN 3.480701e-01
WHEN $1 = 214 THEN 3.831187e-01
WHEN $1 = 215 THEN 4.216965e-01
WHEN $1 = 216 THEN 4.641589e-01
WHEN $1 = 217 THEN 5.108970e-01
WHEN $1 = 218 THEN 5.623413e-01
WHEN $1 = 219 THEN 6.189658e-01
WHEN $1 = 220 THEN 6.812921e-01
WHEN $1 = 221 THEN 7.498942e-01
WHEN $1 = 222 THEN 8.254042e-01
WHEN $1 = 223 THEN 9.085176e-01
WHEN $1 = 224 THEN 1.000000e+00
WHEN $1 = 225 THEN 1.000000e+01
WHEN $1 = 226 THEN 1.000000e+02
WHEN $1 = 227 THEN 1.000000e+03
WHEN $1 = 228 THEN 1.000000e+04
WHEN $1 = 229 THEN 1.000000e+05
WHEN $1 = 230 THEN 1.000000e+06
WHEN $1 = 231 THEN 1.000000e+07
WHEN $1 = 232 THEN 1.000000e+08
WHEN $1 = 233 THEN 1.000000e+09
WHEN $1 = 234 THEN 1.000000e+10
WHEN $1 = 235 THEN 1.000000e+11
WHEN $1 = 236 THEN 1.000000e+12
WHEN $1 = 237 THEN 1.000000e+13
WHEN $1 = 238 THEN 1.000000e+14
WHEN $1 = 239 THEN 1.000000e+15
WHEN $1 = 240 THEN 1.000000e+16
WHEN $1 = 241 THEN 1.000000e+17
WHEN $1 = 242 THEN 1.000000e+18
WHEN $1 = 243 THEN 1.000000e+19
WHEN $1 = 244 THEN 1.000000e+20
WHEN $1 = 245 THEN 1.000000e+21
WHEN $1 = 246 THEN 1.000000e+22
WHEN $1 = 247 THEN 1.000000e+23
WHEN $1 = 248 THEN 1.000000e+24
WHEN $1 = 249 THEN 1.000000e+25
WHEN $1 = 250 THEN 1.000000e+26
WHEN $1 = 251 THEN 1.000000e+27
WHEN $1 = 252 THEN 1.000000e+28
WHEN $1 = 253 THEN 1.000000e+29
WHEN $1 = 254 THEN 1.000000e+30
WHEN $1 = 255 THEN 1.000000e+31
WHEN $1 = 000 THEN 0.000000e+00
WHEN $1 = 001 THEN 2.675309e-18
WHEN $1 = 002 THEN 8.251782e-18
WHEN $1 = 003 THEN 2.545198e-17
WHEN $1 = 004 THEN 7.850462e-17
WHEN $1 = 005 THEN 2.421414e-16
WHEN $1 = 006 THEN 7.468660e-16
WHEN $1 = 007 THEN 2.303650e-15
WHEN $1 = 008 THEN 7.105427e-15
WHEN $1 = 009 THEN 2.191613e-14
WHEN $1 = 010 THEN 6.759860e-14
WHEN $1 = 011 THEN 2.085026e-13
WHEN $1 = 012 THEN 6.431099e-13
WHEN $1 = 013 THEN 1.983622e-12
WHEN $1 = 014 THEN 6.118327e-12
WHEN $1 = 015 THEN 1.887150e-11
WHEN $1 = 016 THEN 5.820766e-11
WHEN $1 = 017 THEN 1.795370e-10
WHEN $1 = 018 THEN 5.537677e-10
WHEN $1 = 019 THEN 1.708053e-09
WHEN $1 = 020 THEN 5.268356e-09
WHEN $1 = 021 THEN 1.624983e-08
WHEN $1 = 022 THEN 5.012133e-08
WHEN $1 = 023 THEN 1.545953e-07
WHEN $1 = 024 THEN 4.768372e-07
WHEN $1 = 025 THEN 1.470767e-06
WHEN $1 = 026 THEN 4.536465e-06
WHEN $1 = 027 THEN 1.399237e-05
WHEN $1 = 028 THEN 4.315837e-05
WHEN $1 = 029 THEN 1.331186e-04
WHEN $1 = 030 THEN 4.105940e-04
WHEN $1 = 031 THEN 1.266445e-03
WHEN $1 = 032 THEN 3.906250e-03
WHEN $1 = 033 THEN 4.044004e-03
WHEN $1 = 034 THEN 4.186615e-03
WHEN $1 = 035 THEN 4.334256e-03
WHEN $1 = 036 THEN 4.487103e-03
WHEN $1 = 037 THEN 4.645340e-03
WHEN $1 = 038 THEN 4.809158e-03
WHEN $1 = 039 THEN 4.978752e-03
WHEN $1 = 040 THEN 5.154328e-03
WHEN $1 = 041 THEN 5.336095e-03
WHEN $1 = 042 THEN 5.524272e-03
WHEN $1 = 043 THEN 5.719085e-03
WHEN $1 = 044 THEN 5.920768e-03
WHEN $1 = 045 THEN 6.129563e-03
WHEN $1 = 046 THEN 6.345722e-03
WHEN $1 = 047 THEN 6.569503e-03
WHEN $1 = 048 THEN 6.801176e-03
WHEN $1 = 049 THEN 7.041019e-03
WHEN $1 = 050 THEN 7.289320e-03
WHEN $1 = 051 THEN 7.546378e-03
WHEN $1 = 052 THEN 7.812500e-03
WHEN $1 = 053 THEN 8.088007e-03
WHEN $1 = 054 THEN 8.373230e-03
WHEN $1 = 055 THEN 8.668512e-03
WHEN $1 = 056 THEN 8.974206e-03
WHEN $1 = 057 THEN 9.290681e-03
WHEN $1 = 058 THEN 9.618316e-03
WHEN $1 = 059 THEN 9.957505e-03
WHEN $1 = 060 THEN 1.030866e-02
WHEN $1 = 061 THEN 1.067219e-02
WHEN $1 = 062 THEN 1.104854e-02
WHEN $1 = 063 THEN 1.143817e-02
WHEN $1 = 064 THEN 1.184154e-02
WHEN $1 = 065 THEN 1.225913e-02
WHEN $1 = 066 THEN 1.269144e-02
WHEN $1 = 067 THEN 1.313901e-02
WHEN $1 = 068 THEN 1.360235e-02
WHEN $1 = 069 THEN 1.408204e-02
WHEN $1 = 070 THEN 1.457864e-02
WHEN $1 = 071 THEN 1.509276e-02
WHEN $1 = 072 THEN 1.562500e-02
WHEN $1 = 073 THEN 1.617601e-02
WHEN $1 = 074 THEN 1.674646e-02
WHEN $1 = 075 THEN 1.733702e-02
WHEN $1 = 076 THEN 1.794841e-02
WHEN $1 = 077 THEN 1.858136e-02
WHEN $1 = 078 THEN 1.923663e-02
WHEN $1 = 079 THEN 1.991501e-02
WHEN $1 = 080 THEN 2.061731e-02
WHEN $1 = 081 THEN 2.134438e-02
WHEN $1 = 082 THEN 2.209709e-02
WHEN $1 = 083 THEN 2.287634e-02
WHEN $1 = 084 THEN 2.368307e-02
WHEN $1 = 085 THEN 2.451825e-02
WHEN $1 = 086 THEN 2.538289e-02
WHEN $1 = 087 THEN 2.627801e-02
WHEN $1 = 088 THEN 2.720471e-02
WHEN $1 = 089 THEN 2.816408e-02
WHEN $1 = 090 THEN 2.915728e-02
WHEN $1 = 091 THEN 3.018551e-02
WHEN $1 = 092 THEN 3.125000e-02
WHEN $1 = 093 THEN 3.235203e-02
WHEN $1 = 094 THEN 3.349292e-02
WHEN $1 = 095 THEN 3.467405e-02
WHEN $1 = 096 THEN 3.589682e-02
WHEN $1 = 097 THEN 3.716272e-02
WHEN $1 = 098 THEN 3.847326e-02
WHEN $1 = 099 THEN 3.983002e-02
WHEN $1 = 100 THEN 4.123462e-02
WHEN $1 = 101 THEN 4.268876e-02
WHEN $1 = 102 THEN 4.419417e-02
WHEN $1 = 103 THEN 4.575268e-02
WHEN $1 = 104 THEN 4.736614e-02
WHEN $1 = 105 THEN 4.903651e-02
WHEN $1 = 106 THEN 5.076577e-02
WHEN $1 = 107 THEN 5.255603e-02
WHEN $1 = 108 THEN 5.440941e-02
WHEN $1 = 109 THEN 5.632815e-02
WHEN $1 = 110 THEN 5.831456e-02
WHEN $1 = 111 THEN 6.037102e-02
WHEN $1 = 112 THEN 6.250000e-02
WHEN $1 = 113 THEN 6.470406e-02
WHEN $1 = 114 THEN 6.698584e-02
WHEN $1 = 115 THEN 6.934809e-02
WHEN $1 = 116 THEN 7.179365e-02
WHEN $1 = 117 THEN 7.432544e-02
WHEN $1 = 118 THEN 7.694653e-02
WHEN $1 = 119 THEN 7.966004e-02
WHEN $1 = 120 THEN 8.246924e-02
WHEN $1 = 121 THEN 8.537752e-02
WHEN $1 = 122 THEN 8.838835e-02
WHEN $1 = 123 THEN 9.150536e-02
WHEN $1 = 124 THEN 9.473229e-02
WHEN $1 = 125 THEN 9.807301e-02
WHEN $1 = 126 THEN 1.015315e-01
WHEN $1 = 127 THEN 1.051121e-01
WHEN $1 = 128 THEN 1.088188e-01
WHEN $1 = 129 THEN 1.126563e-01
WHEN $1 = 130 THEN 1.166291e-01
WHEN $1 = 131 THEN 1.207420e-01
WHEN $1 = 132 THEN 1.250000e-01
WHEN $1 = 133 THEN 1.294081e-01
WHEN $1 = 134 THEN 1.339717e-01
WHEN $1 = 135 THEN 1.386962e-01
WHEN $1 = 136 THEN 1.435873e-01
WHEN $1 = 137 THEN 1.486509e-01
WHEN $1 = 138 THEN 1.538931e-01
WHEN $1 = 139 THEN 1.593201e-01
WHEN $1 = 140 THEN 1.649385e-01
WHEN $1 = 141 THEN 1.707550e-01
WHEN $1 = 142 THEN 1.767767e-01
WHEN $1 = 143 THEN 1.830107e-01
WHEN $1 = 144 THEN 1.894646e-01
WHEN $1 = 145 THEN 1.961460e-01
WHEN $1 = 146 THEN 2.030631e-01
WHEN $1 = 147 THEN 2.102241e-01
WHEN $1 = 148 THEN 2.176376e-01
WHEN $1 = 149 THEN 2.253126e-01
WHEN $1 = 150 THEN 2.332582e-01
WHEN $1 = 151 THEN 2.414841e-01
WHEN $1 = 152 THEN 2.500000e-01
WHEN $1 = 153 THEN 2.588162e-01
WHEN $1 = 154 THEN 2.679434e-01
WHEN $1 = 155 THEN 2.773924e-01
WHEN $1 = 156 THEN 2.871746e-01
WHEN $1 = 157 THEN 2.973018e-01
WHEN $1 = 158 THEN 3.077861e-01
WHEN $1 = 159 THEN 3.186402e-01
WHEN $1 = 160 THEN 3.298770e-01
WHEN $1 = 161 THEN 3.415101e-01
WHEN $1 = 162 THEN 3.535534e-01
WHEN $1 = 163 THEN 3.660214e-01
WHEN $1 = 164 THEN 3.789291e-01
WHEN $1 = 165 THEN 3.922920e-01
WHEN $1 = 166 THEN 4.061262e-01
WHEN $1 = 167 THEN 4.204482e-01
WHEN $1 = 168 THEN 4.352753e-01
WHEN $1 = 169 THEN 4.506252e-01
WHEN $1 = 170 THEN 4.665165e-01
WHEN $1 = 171 THEN 4.829682e-01
WHEN $1 = 172 THEN 5.000000e-01
WHEN $1 = 173 THEN 5.176325e-01
WHEN $1 = 174 THEN 5.358867e-01
WHEN $1 = 175 THEN 5.547847e-01
WHEN $1 = 176 THEN 5.743492e-01
WHEN $1 = 177 THEN 5.946036e-01
WHEN $1 = 178 THEN 6.155722e-01
WHEN $1 = 179 THEN 6.372803e-01
WHEN $1 = 180 THEN 6.597540e-01
WHEN $1 = 181 THEN 6.830201e-01
WHEN $1 = 182 THEN 7.071068e-01
WHEN $1 = 183 THEN 7.320428e-01
WHEN $1 = 184 THEN 7.578583e-01
WHEN $1 = 185 THEN 7.845841e-01
WHEN $1 = 186 THEN 8.122524e-01
WHEN $1 = 187 THEN 8.408964e-01
WHEN $1 = 188 THEN 8.705506e-01
WHEN $1 = 189 THEN 9.012505e-01
WHEN $1 = 190 THEN 9.330330e-01
WHEN $1 = 191 THEN 9.659363e-01
WHEN $1 = 192 THEN 1.000000e+00
WHEN $1 = 193 THEN 2.000000e+00
WHEN $1 = 194 THEN 4.000000e+00
WHEN $1 = 195 THEN 8.000000e+00
WHEN $1 = 196 THEN 1.600000e+01
WHEN $1 = 197 THEN 3.200000e+01
WHEN $1 = 198 THEN 6.400000e+01
WHEN $1 = 199 THEN 1.280000e+02
WHEN $1 = 200 THEN 2.560000e+02
WHEN $1 = 201 THEN 5.120000e+02
WHEN $1 = 202 THEN 1.024000e+03
WHEN $1 = 203 THEN 2.048000e+03
WHEN $1 = 204 THEN 4.096000e+03
WHEN $1 = 205 THEN 8.192000e+03
WHEN $1 = 206 THEN 1.638400e+04
WHEN $1 = 207 THEN 3.276800e+04
WHEN $1 = 208 THEN 6.553600e+04
WHEN $1 = 209 THEN 1.310720e+05
WHEN $1 = 210 THEN 2.621440e+05
WHEN $1 = 211 THEN 5.242880e+05
WHEN $1 = 212 THEN 1.048576e+06
WHEN $1 = 213 THEN 2.097152e+06
WHEN $1 = 214 THEN 4.194304e+06
WHEN $1 = 215 THEN 8.388608e+06
WHEN $1 = 216 THEN 1.677722e+07
WHEN $1 = 217 THEN 3.355443e+07
WHEN $1 = 218 THEN 6.710886e+07
WHEN $1 = 219 THEN 1.342177e+08
WHEN $1 = 220 THEN 2.684355e+08
WHEN $1 = 221 THEN 5.368709e+08
WHEN $1 = 222 THEN 1.073742e+09
WHEN $1 = 223 THEN 2.147484e+09
WHEN $1 = 224 THEN 4.294967e+09
WHEN $1 = 225 THEN 8.589935e+09
WHEN $1 = 226 THEN 1.717987e+10
WHEN $1 = 227 THEN 3.435974e+10
WHEN $1 = 228 THEN 6.871948e+10
WHEN $1 = 229 THEN 1.374390e+11
WHEN $1 = 230 THEN 2.748779e+11
WHEN $1 = 231 THEN 5.497558e+11
WHEN $1 = 232 THEN 1.099512e+12
WHEN $1 = 233 THEN 2.199023e+12
WHEN $1 = 234 THEN 4.398047e+12
WHEN $1 = 235 THEN 8.796093e+12
WHEN $1 = 236 THEN 1.759219e+13
WHEN $1 = 237 THEN 3.518437e+13
WHEN $1 = 238 THEN 7.036874e+13
WHEN $1 = 239 THEN 1.407375e+14
WHEN $1 = 240 THEN 2.814750e+14
WHEN $1 = 241 THEN 5.629500e+14
WHEN $1 = 242 THEN 1.125900e+15
WHEN $1 = 243 THEN 2.251800e+15
WHEN $1 = 244 THEN 4.503600e+15
WHEN $1 = 245 THEN 9.007199e+15
WHEN $1 = 246 THEN 1.801440e+16
WHEN $1 = 247 THEN 3.602880e+16
WHEN $1 = 248 THEN 7.205759e+16
WHEN $1 = 249 THEN 1.441152e+17
WHEN $1 = 250 THEN 2.882304e+17
WHEN $1 = 251 THEN 5.764608e+17
WHEN $1 = 252 THEN 1.152922e+18
WHEN $1 = 253 THEN 2.305843e+18
WHEN $1 = 254 THEN 4.611686e+18
WHEN $1 = 255 THEN 9.223372e+18
END INTO perc; END INTO perc;
RETURN perc; RETURN perc;
END; END;
@ -617,4 +617,4 @@ DROP TABLE batch;
DROP TABLE coordinator; DROP TABLE coordinator;
DROP TABLE block; DROP TABLE block;
-- drop sequences -- drop sequences
DROP SEQUENCE tx_item_id;
DROP SEQUENCE tx_item_id;

+ 8
- 2
db/statedb/txprocessors.go

@ -603,7 +603,10 @@ func (s *StateDB) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx, coll
if !tx.IsL1 { if !tx.IsL1 {
// compute fee and subtract it from the accSender // compute fee and subtract it from the accSender
fee := common.CalcFeeAmount(tx.Amount, *tx.Fee)
fee, err := common.CalcFeeAmount(tx.Amount, *tx.Fee)
if err != nil {
return err
}
feeAndAmount := new(big.Int).Add(tx.Amount, fee) feeAndAmount := new(big.Int).Add(tx.Amount, fee)
accSender.Balance = new(big.Int).Sub(accSender.Balance, feeAndAmount) accSender.Balance = new(big.Int).Sub(accSender.Balance, feeAndAmount)
@ -743,7 +746,10 @@ func (s *StateDB) applyExit(coordIdxsMap map[common.TokenID]common.Idx, collecte
if !tx.IsL1 { if !tx.IsL1 {
// compute fee and subtract it from the accSender // compute fee and subtract it from the accSender
fee := common.CalcFeeAmount(tx.Amount, *tx.Fee)
fee, err := common.CalcFeeAmount(tx.Amount, *tx.Fee)
if err != nil {
return nil, false, err
}
feeAndAmount := new(big.Int).Add(tx.Amount, fee) feeAndAmount := new(big.Int).Add(tx.Amount, fee)
acc.Balance = new(big.Int).Sub(acc.Balance, feeAndAmount) acc.Balance = new(big.Int).Sub(acc.Balance, feeAndAmount)

+ 18
- 15
test/til/sets.go

@ -2,6 +2,9 @@ package til
// sets of instructions to be used in tests of other packages // sets of instructions to be used in tests of other packages
// NOTE: FeeSelector(126) ~ 10%
// NOTE: FeeSelector(100) ~ 4%
// SetBlockchain0 contains a set of transactions simulated to be from the smart contract // SetBlockchain0 contains a set of transactions simulated to be from the smart contract
var SetBlockchain0 = ` var SetBlockchain0 = `
// Set containing Blockchain transactions // Set containing Blockchain transactions
@ -67,7 +70,7 @@ Transfer(1) A-M: 5 (1)
Transfer(1) A-N: 5 (1) Transfer(1) A-N: 5 (1)
Transfer(1) A-O: 5 (1) Transfer(1) A-O: 5 (1)
Transfer(1) B-C: 3 (1) Transfer(1) B-C: 3 (1)
Transfer(1) C-A: 10 (200)
Transfer(1) C-A: 10 (126)
Transfer(1) D-A: 5 (1) Transfer(1) D-A: 5 (1)
Transfer(1) D-Z: 5 (1) Transfer(1) D-Z: 5 (1)
Transfer(1) D-Y: 5 (1) Transfer(1) D-Y: 5 (1)
@ -82,7 +85,7 @@ Transfer(1) G-K: 3 (1)
Transfer(1) H-K: 3 (2) Transfer(1) H-K: 3 (2)
Transfer(1) H-K: 3 (1) Transfer(1) H-K: 3 (1)
Transfer(1) H-K: 3 (1) Transfer(1) H-K: 3 (1)
Transfer(0) B-C: 50 (192)
Transfer(0) B-C: 50 (100)
> batchL1 > batchL1
> block > block
@ -142,7 +145,7 @@ Transfer(1) W-J: 3 (1)
Transfer(1) W-A: 5 (1) Transfer(1) W-A: 5 (1)
Transfer(1) W-Z: 5 (1) Transfer(1) W-Z: 5 (1)
Transfer(1) X-B: 5 (1) Transfer(1) X-B: 5 (1)
Transfer(1) X-C: 10 (200)
Transfer(1) X-C: 10 (126)
Transfer(1) X-D: 5 (1) Transfer(1) X-D: 5 (1)
Transfer(1) X-E: 5 (1) Transfer(1) X-E: 5 (1)
Transfer(1) Y-B: 5 (1) Transfer(1) Y-B: 5 (1)
@ -262,8 +265,8 @@ CreateAccountDeposit(0) D: 800
CreateAccountCoordinator(1) B CreateAccountCoordinator(1) B
Transfer(1) A-B: 200 (200)
Transfer(0) B-C: 100 (200)
Transfer(1) A-B: 200 (126)
Transfer(0) B-C: 100 (126)
// close Block:0, Batch:6 // close Block:0, Batch:6
> batchL1 // forge L1User{1}, forge L1Coord{2}, forge L2{2} > batchL1 // forge L1User{1}, forge L1Coord{2}, forge L2{2}
@ -277,10 +280,10 @@ Transfer(0) B-C: 100 (200)
Deposit(0) C: 500 Deposit(0) C: 500
DepositTransfer(0) C-D: 400, 100 DepositTransfer(0) C-D: 400, 100
Transfer(0) A-B: 100 (200)
Transfer(0) C-A: 50 (200)
Transfer(1) B-C: 100 (200)
Exit(0) A: 100 (200)
Transfer(0) A-B: 100 (126)
Transfer(0) C-A: 50 (126)
Transfer(1) B-C: 100 (126)
Exit(0) A: 100 (126)
ForceTransfer(0) D-B: 200 ForceTransfer(0) D-B: 200
ForceExit(0) B: 100 ForceExit(0) B: 100
@ -295,8 +298,8 @@ ForceExit(0) B: 100
// C(0): 45, C(1): 100 // C(0): 45, C(1): 100
// D(0): 800 // D(0): 800
Transfer(0) D-A: 300 (200)
Transfer(0) B-D: 100 (200)
Transfer(0) D-A: 300 (126)
Transfer(0) B-D: 100 (126)
// close Block:1, Batch:0 // close Block:1, Batch:0
> batchL1 // freeze L1User{nil}, forge L1User{4}, forge L2{1} > batchL1 // freeze L1User{nil}, forge L1User{4}, forge L2{1}
@ -317,10 +320,10 @@ CreateAccountCoordinator(0) F
var SetPoolL2MinimumFlow0 = ` var SetPoolL2MinimumFlow0 = `
Type: PoolL2 Type: PoolL2
PoolTransfer(0) A-B: 100 (200)
PoolTransferToEthAddr(0) D-F: 100 (200)
PoolExit(0) A: 100 (200)
PoolTransferToEthAddr(1) A-B: 100 (200)
PoolTransfer(0) A-B: 100 (126)
PoolTransferToEthAddr(0) D-F: 100 (126)
PoolExit(0) A: 100 (126)
PoolTransferToEthAddr(1) A-B: 100 (126)
// Expected balances: // Expected balances:
// Coord(0): 105, Coord(1): 40 // Coord(0): 105, Coord(1): 40

Loading…
Cancel
Save