github.com/gagliardetto/solana-go@v1.11.0/util.go (about)

     1  // Copyright 2020 dfuse Platform Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package solana
    16  
    17  import (
    18  	"math/big"
    19  )
    20  
    21  var _10b = big.NewInt(10)
    22  var decimalsBigInt = []*big.Int{
    23  	new(big.Int).Exp(_10b, big.NewInt(1), nil),
    24  	new(big.Int).Exp(_10b, big.NewInt(2), nil),
    25  	new(big.Int).Exp(_10b, big.NewInt(3), nil),
    26  	new(big.Int).Exp(_10b, big.NewInt(4), nil),
    27  	new(big.Int).Exp(_10b, big.NewInt(5), nil),
    28  	new(big.Int).Exp(_10b, big.NewInt(6), nil),
    29  	new(big.Int).Exp(_10b, big.NewInt(7), nil),
    30  	new(big.Int).Exp(_10b, big.NewInt(8), nil),
    31  	new(big.Int).Exp(_10b, big.NewInt(9), nil),
    32  	new(big.Int).Exp(_10b, big.NewInt(10), nil),
    33  	new(big.Int).Exp(_10b, big.NewInt(11), nil),
    34  	new(big.Int).Exp(_10b, big.NewInt(12), nil),
    35  	new(big.Int).Exp(_10b, big.NewInt(13), nil),
    36  	new(big.Int).Exp(_10b, big.NewInt(14), nil),
    37  	new(big.Int).Exp(_10b, big.NewInt(15), nil),
    38  	new(big.Int).Exp(_10b, big.NewInt(16), nil),
    39  	new(big.Int).Exp(_10b, big.NewInt(17), nil),
    40  	new(big.Int).Exp(_10b, big.NewInt(18), nil),
    41  }
    42  
    43  func DecimalsInBigInt(decimal uint32) *big.Int {
    44  	if decimal == 0 {
    45  		return big.NewInt(1)
    46  	}
    47  	var decimalsBig *big.Int
    48  	if decimal <= uint32(len(decimalsBigInt)) {
    49  		decimalsBig = decimalsBigInt[decimal-1]
    50  	} else {
    51  		decimalsBig = new(big.Int).Exp(_10b, big.NewInt(int64(decimal)), nil)
    52  	}
    53  	return decimalsBig
    54  }
    55  
    56  //
    57  //func foo(numerator, denomiator *big.Int) {
    58  //	quotient := new(big.Int).Quo(numerator, denomiator)
    59  //	remainder := new(big.Int).Rem(numerator, denomiator)
    60  //	gcd := new(big.Int).GCD(nil, nil, remainder, denomiator)
    61  //
    62  //}