code.vegaprotocol.io/vega@v0.79.0/core/examples/nullchain/transactions.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package nullchain 17 18 import ( 19 "encoding/json" 20 "strconv" 21 "time" 22 23 dstypes "code.vegaprotocol.io/vega/core/datasource/common" 24 "code.vegaprotocol.io/vega/core/examples/nullchain/config" 25 vgrand "code.vegaprotocol.io/vega/libs/rand" 26 "code.vegaprotocol.io/vega/protos/vega" 27 v1 "code.vegaprotocol.io/vega/protos/vega/commands/v1" 28 datav1 "code.vegaprotocol.io/vega/protos/vega/data/v1" 29 walletpb "code.vegaprotocol.io/vega/protos/vega/wallet/v1" 30 ) 31 32 func MarketProposalTxn(now time.Time, oraclePubkey string) (*walletpb.SubmitTransactionRequest, string) { 33 reference := "ref-" + vgrand.RandomStr(10) 34 asset := config.NormalAsset 35 36 pubKey := dstypes.CreateSignerFromString(oraclePubkey, dstypes.SignerTypePubKey) 37 cmd := &walletpb.SubmitTransactionRequest_ProposalSubmission{ 38 ProposalSubmission: &v1.ProposalSubmission{ 39 Reference: reference, 40 Terms: &vega.ProposalTerms{ 41 ValidationTimestamp: now.Add(2 * time.Second).Unix(), 42 ClosingTimestamp: now.Add(10 * time.Second).Unix(), 43 EnactmentTimestamp: now.Add(15 * time.Second).Unix(), 44 Change: &vega.ProposalTerms_NewMarket{ 45 NewMarket: &vega.NewMarket{ 46 Changes: &vega.NewMarketConfiguration{ 47 Instrument: &vega.InstrumentConfiguration{ 48 Code: "CRYPTO:BTCUSD/NOV21", 49 Name: "NOV 2021 BTC vs USD future", 50 Product: &vega.InstrumentConfiguration_Future{ 51 Future: &vega.FutureProduct{ 52 SettlementAsset: asset, 53 QuoteName: "BTCUSD", 54 DataSourceSpecForSettlementData: &vega.DataSourceDefinition{ 55 SourceType: &vega.DataSourceDefinition_External{ 56 External: &vega.DataSourceDefinitionExternal{ 57 SourceType: &vega.DataSourceDefinitionExternal_Oracle{ 58 Oracle: &vega.DataSourceSpecConfiguration{ 59 Signers: []*datav1.Signer{pubKey.IntoProto()}, 60 Filters: []*datav1.Filter{ 61 { 62 Key: &datav1.PropertyKey{ 63 Name: "prices." + asset + ".value", 64 Type: datav1.PropertyKey_TYPE_INTEGER, 65 }, 66 Conditions: []*datav1.Condition{}, 67 }, 68 }, 69 }, 70 }, 71 }, 72 }, 73 }, 74 DataSourceSpecForTradingTermination: &vega.DataSourceDefinition{ 75 SourceType: &vega.DataSourceDefinition_External{ 76 External: &vega.DataSourceDefinitionExternal{ 77 SourceType: &vega.DataSourceDefinitionExternal_Oracle{ 78 Oracle: &vega.DataSourceSpecConfiguration{ 79 Signers: []*datav1.Signer{pubKey.IntoProto()}, 80 Filters: []*datav1.Filter{ 81 { 82 Key: &datav1.PropertyKey{ 83 Name: "trading.termination", 84 Type: datav1.PropertyKey_TYPE_BOOLEAN, 85 }, 86 Conditions: []*datav1.Condition{}, 87 }, 88 }, 89 }, 90 }, 91 }, 92 }, 93 }, 94 DataSourceSpecBinding: &vega.DataSourceSpecToFutureBinding{ 95 SettlementDataProperty: "prices." + asset + ".value", 96 TradingTerminationProperty: "trading.termination", 97 }, 98 }, 99 }, 100 }, 101 DecimalPlaces: 5, 102 Metadata: []string{"base:BTC", "quote:USD", "class:fx/crypto", "monthly", "sector:crypto"}, 103 RiskParameters: &vega.NewMarketConfiguration_Simple{ 104 Simple: &vega.SimpleModelParams{ 105 FactorLong: 0.15, 106 FactorShort: 0.25, 107 MaxMoveUp: 10, 108 MinMoveDown: -5, 109 ProbabilityOfTrading: 0.1, 110 }, 111 }, 112 LiquiditySlaParameters: &vega.LiquiditySLAParameters{ 113 PriceRange: "0.95", 114 CommitmentMinTimeFraction: "0.5", 115 PerformanceHysteresisEpochs: 4, 116 SlaCompetitionFactor: "0.5", 117 }, 118 LinearSlippageFactor: "0.1", 119 }, 120 }, 121 }, 122 }, 123 }, 124 } 125 126 return &walletpb.SubmitTransactionRequest{ 127 Command: cmd, 128 }, reference 129 } 130 131 func VoteTxn(proposalID string, vote vega.Vote_Value) *walletpb.SubmitTransactionRequest { 132 return &walletpb.SubmitTransactionRequest{ 133 Command: &walletpb.SubmitTransactionRequest_VoteSubmission{ 134 VoteSubmission: &v1.VoteSubmission{ 135 ProposalId: proposalID, 136 Value: vote, 137 }, 138 }, 139 } 140 } 141 142 func OrderTxn( 143 marketId string, 144 price, size uint64, 145 side vega.Side, 146 orderT vega.Order_Type, 147 expiresAt time.Time, 148 ) *walletpb.SubmitTransactionRequest { 149 cmd := &walletpb.SubmitTransactionRequest_OrderSubmission{ 150 OrderSubmission: &v1.OrderSubmission{ 151 MarketId: marketId, 152 Price: strconv.FormatUint(price, 10), 153 Size: size, 154 Side: side, 155 Type: orderT, 156 TimeInForce: vega.Order_TIME_IN_FORCE_GTT, 157 ExpiresAt: expiresAt.UnixNano(), 158 }, 159 } 160 161 return &walletpb.SubmitTransactionRequest{ 162 Command: cmd, 163 } 164 } 165 166 func OracleTxn(key, value string) *walletpb.SubmitTransactionRequest { 167 data := map[string]string{ 168 key: value, 169 } 170 171 b, _ := json.Marshal(data) 172 173 cmd := &walletpb.SubmitTransactionRequest_OracleDataSubmission{ 174 OracleDataSubmission: &v1.OracleDataSubmission{ 175 Source: v1.OracleDataSubmission_ORACLE_SOURCE_JSON, 176 Payload: b, 177 }, 178 } 179 180 return &walletpb.SubmitTransactionRequest{ 181 Command: cmd, 182 } 183 }