github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/exchange/5_MsgInstantExpiryFuturesMarketLaunch/example.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  	"fmt"
     7  	"os"
     8  
     9  	"cosmossdk.io/math"
    10  
    11  	exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
    12  	oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types"
    13  	exchangeclient "github.com/InjectiveLabs/sdk-go/client/exchange"
    14  
    15  	"github.com/InjectiveLabs/sdk-go/client"
    16  	chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
    17  	"github.com/InjectiveLabs/sdk-go/client/common"
    18  	rpchttp "github.com/cometbft/cometbft/rpc/client/http"
    19  )
    20  
    21  func main() {
    22  	network := common.LoadNetwork("testnet", "lb")
    23  	tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
    24  	if err != nil {
    25  		panic(err)
    26  	}
    27  
    28  	senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
    29  		os.Getenv("HOME")+"/.injectived",
    30  		"injectived",
    31  		"file",
    32  		"inj-user",
    33  		"12345678",
    34  		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
    35  		false,
    36  	)
    37  
    38  	if err != nil {
    39  		panic(err)
    40  	}
    41  
    42  	clientCtx, err := chainclient.NewClientContext(
    43  		network.ChainId,
    44  		senderAddress.String(),
    45  		cosmosKeyring,
    46  	)
    47  
    48  	if err != nil {
    49  		panic(err)
    50  	}
    51  
    52  	clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
    53  
    54  	chainClient, err := chainclient.NewChainClient(
    55  		clientCtx,
    56  		network,
    57  		common.OptionGasPrices(client.DefaultGasPriceWithDenom),
    58  	)
    59  	if err != nil {
    60  		panic(err)
    61  	}
    62  
    63  	exchangeClient, err := exchangeclient.NewExchangeClient(network)
    64  	if err != nil {
    65  		panic(err)
    66  	}
    67  
    68  	ctx := context.Background()
    69  	marketsAssistant, err := chainclient.NewMarketsAssistantInitializedFromChain(ctx, exchangeClient)
    70  	if err != nil {
    71  		panic(err)
    72  	}
    73  
    74  	quoteToken := marketsAssistant.AllTokens()["USDC"]
    75  	minPriceTickSize := math.LegacyMustNewDecFromStr("0.01")
    76  	minQuantityTickSize := math.LegacyMustNewDecFromStr("0.001")
    77  
    78  	chainMinPriceTickSize := minPriceTickSize.Mul(math.LegacyNewDecFromIntWithPrec(math.NewInt(1), int64(quoteToken.Decimals)))
    79  	chainMinQuantityTickSize := minQuantityTickSize
    80  
    81  	msg := &exchangetypes.MsgInstantExpiryFuturesMarketLaunch{
    82  		Sender:                 senderAddress.String(),
    83  		Ticker:                 "INJ/USDC FUT",
    84  		QuoteDenom:             quoteToken.Denom,
    85  		OracleBase:             "INJ",
    86  		OracleQuote:            "USDC",
    87  		OracleScaleFactor:      6,
    88  		OracleType:             oracletypes.OracleType_Band,
    89  		Expiry:                 2000000000,
    90  		MakerFeeRate:           math.LegacyMustNewDecFromStr("-0.0001"),
    91  		TakerFeeRate:           math.LegacyMustNewDecFromStr("0.001"),
    92  		InitialMarginRatio:     math.LegacyMustNewDecFromStr("0.33"),
    93  		MaintenanceMarginRatio: math.LegacyMustNewDecFromStr("0.095"),
    94  		MinPriceTickSize:       chainMinPriceTickSize,
    95  		MinQuantityTickSize:    chainMinQuantityTickSize,
    96  	}
    97  
    98  	// AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
    99  	response, err := chainClient.AsyncBroadcastMsg(msg)
   100  
   101  	if err != nil {
   102  		panic(err)
   103  	}
   104  
   105  	str, _ := json.MarshalIndent(response, "", " ")
   106  	fmt.Print(string(str))
   107  }