Skip to content

Instantly share code, notes, and snippets.

@larry0x
Last active January 14, 2023 04:30
Show Gist options
  • Save larry0x/4e629d4f76bce7352c964a4260ed9c6b to your computer and use it in GitHub Desktop.
Save larry0x/4e629d4f76bce7352c964a4260ed9c6b to your computer and use it in GitHub Desktop.
package main
import (
"encoding/base64"
"encoding/json"
"fmt"
"time"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
customgovtypes "github.com/mars-protocol/hub/x/gov/types"
incentivestypes "github.com/mars-protocol/hub/x/incentives/types"
)
type StargateMsg struct {
TypeURL string `json:"type_url"`
Value string `json:"value"`
}
// the gov module account, which will be the executing authority of payloads
// in the proposal
const govModuleAcct = "mars10d07y265gmmuvt4z0w9aw880jnsr700j8l2urg"
var (
// the multisig's address
proposer = "mars1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faqtl66fc"
// the messages to be executed if the gov proposal passes
payload = []sdk.Msg{
&incentivestypes.MsgCreateSchedule{
Authority: govModuleAcct,
StartTime: time.Date(2023, time.January, 15, 0, 0, 0, 0, time.UTC),
EndTime: time.Date(2023, time.January, 16, 0, 0, 0, 0, time.UTC),
Amount: sdk.NewCoins(sdk.NewCoin("umars", sdk.NewInt(10_000_000))),
},
}
// metadata of the proposal
metadata = customgovtypes.ProposalMetadata{
Title: "[TEST] Create an incentives schedule",
Summary: "If passed, a staking incentive schedule will be created, starting at 2023-01-15 00:00:00 UTC, lasting for 1 day, releasing a total of 10 MARS to stakers.",
}
// initial deposit to be made
deposit = sdk.NewCoins()
)
func main() {
metadataBytes, err := json.Marshal(&metadata)
if err != nil {
panic(err)
}
msg, err := govv1.NewMsgSubmitProposal(payload, deposit, proposer, string(metadataBytes))
if err != nil {
panic(err)
}
any, err := codectypes.NewAnyWithValue(msg)
if err != nil {
panic(err)
}
stargateMsg := StargateMsg{
TypeURL: any.TypeUrl,
Value: base64.StdEncoding.EncodeToString(any.Value),
}
stargateMsgBytes, err := json.MarshalIndent(&stargateMsg, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(stargateMsgBytes))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment