github.com/InjectiveLabs/sdk-go@v1.53.0/chain/insurance/types/insurance.go (about)

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"cosmossdk.io/math"
     8  	"github.com/ethereum/go-ethereum/common"
     9  
    10  	oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types"
    11  )
    12  
    13  var (
    14  	InsuranceFundInitialSupply                = math.NewIntWithDecimal(1, 18)
    15  	InsuranceFundProtocolOwnedLiquiditySupply = math.NewIntWithDecimal(1, 16)
    16  	InsuranceFundCreatorSupply                = InsuranceFundInitialSupply.Sub(InsuranceFundProtocolOwnedLiquiditySupply)
    17  )
    18  
    19  func NewInsuranceFund(
    20  	marketID common.Hash,
    21  	depositDenom, poolTokenDenom string,
    22  	redemptionNoticePeriodDuration time.Duration,
    23  	ticker, oracleBase, oracleQuote string, oracleType oracletypes.OracleType, expiry int64,
    24  ) *InsuranceFund {
    25  
    26  	return &InsuranceFund{
    27  		DepositDenom:                   depositDenom,
    28  		InsurancePoolTokenDenom:        poolTokenDenom,
    29  		RedemptionNoticePeriodDuration: redemptionNoticePeriodDuration,
    30  		Balance:                        math.ZeroInt(),
    31  		TotalShare:                     math.ZeroInt(),
    32  		MarketId:                       marketID.Hex(),
    33  		MarketTicker:                   ticker,
    34  		OracleBase:                     oracleBase,
    35  		OracleQuote:                    oracleQuote,
    36  		OracleType:                     oracleType,
    37  		Expiry:                         expiry,
    38  	}
    39  
    40  }
    41  
    42  func (fund InsuranceFund) ShareDenom() string {
    43  	return fund.InsurancePoolTokenDenom
    44  }
    45  
    46  func (fund *InsuranceFund) AddTotalShare(shares math.Int) {
    47  	fund.TotalShare = fund.TotalShare.Add(shares)
    48  }
    49  
    50  func (fund *InsuranceFund) SubTotalShare(shares math.Int) {
    51  	fund.TotalShare = fund.TotalShare.Sub(shares)
    52  }
    53  
    54  func ShareDenomFromId(id uint64) string {
    55  	return fmt.Sprintf("share%d", id)
    56  }