Skip to content

Commit

Permalink
feat: use opinit/launch
Browse files Browse the repository at this point in the history
  • Loading branch information
kjessec committed May 3, 2024
1 parent fbf1746 commit 8fb6e25
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 10 deletions.
125 changes: 125 additions & 0 deletions cmd/minitiad/launch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package main

import (
"encoding/json"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/initia-labs/OPinit/contrib/launchtools"
"github.com/initia-labs/OPinit/contrib/launchtools/steps"
"github.com/initia-labs/initia/app/params"
minitiaapp "github.com/initia-labs/miniwasm/app"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"os"
)

// DefaultLaunchStepFactories is a list of default launch step factories.
var DefaultLaunchStepFactories = []launchtools.LauncherStepFuncFactory[launchtools.Input]{
steps.InitializeConfig,
steps.InitializeRPCHelpers,

// Initialize genesis
steps.InitializeGenesis,

// Add system keys to the keyring
steps.InitializeKeyring,

// Run the app
steps.RunApp,

// MINIWASM: Store/Instantiate cw721 and ics721 contracts
StoreAndInstantiateNFTContracts,

// Establish IBC channels for fungible and NFT transfer
// MINIWASM: Use wasm contract addresses for srcPort, dstPort, channelVersion
steps.EstablishIBCChannelsWithNFTTransfer(func() (string, string, string) {
return "wasm." + wasmkeeper.BuildContractAddressClassic(2, 1).String(),
"nft-transfer",
"ics721-1"
}),

// Enable the oracle
steps.EnableOracle,

// Create OP Bridge, using open channel states
steps.InitializeOpBridge,

// Cleanup
steps.StopApp,
}

func LaunchCommand(ac appCreator, enc params.EncodingConfig, mbm module.BasicManager) *cobra.Command {
return launchtools.LaunchCmd(
ac.newApp,
func(denom string) map[string]json.RawMessage {
return minitiaapp.NewDefaultGenesisState(enc.Codec, mbm, denom)
},
DefaultLaunchStepFactories,
)
}

// StoreAndInstantiateNFTContracts stores and instantiates cw721 and ics721 contracts
func StoreAndInstantiateNFTContracts(input launchtools.Input) launchtools.LauncherStepFunc {
return func(ctx launchtools.Launcher) error {
ctx.Logger().Info("Storing and instantiating cw721 and ics721 contracts")

cw721, err := os.ReadFile("contrib/wasm/cw721_base.wasm")
if err != nil {
return errors.Wrapf(err, "failed to read cw721_base.wasm")
}

ics721, err := os.ReadFile("contrib/wasm/ics721_base.wasm")
if err != nil {
return errors.Wrapf(err, "failed to read ics721_base.wasm")
}

msgs := []sdk.Msg{
&wasmtypes.MsgStoreCode{
Sender: input.SystemKeys.Validator.Address,
WASMByteCode: cw721,
InstantiatePermission: nil,
},
&wasmtypes.MsgStoreCode{
Sender: input.SystemKeys.Validator.Address,
WASMByteCode: ics721,
InstantiatePermission: nil,
},
&wasmtypes.MsgInstantiateContract{
Sender: input.SystemKeys.Validator.Address,
Admin: input.SystemKeys.Validator.Address,
CodeID: 2,
Label: "ics721",
Msg: []byte(`{"cw721_base_code_id":1}`),
Funds: nil,
},
}

for i, msg := range msgs {
ctx.Logger().Info(
"Broadcasting tx to store and instantiate cw721 and ics721 contracts",
"step", i+1,
)

res, err := ctx.GetRPCHelperL2().BroadcastTxAndWait(
input.SystemKeys.Validator.Address,
input.SystemKeys.Validator.Mnemonic,
10000000,
sdk.NewCoins(sdk.NewInt64Coin(input.L2Config.Denom, 1500000)),
msg,
)

if err != nil {
return errors.Wrapf(err, "failed to store and instantiate nft contracts")
}

ctx.Logger().Info(
"Successfully stored and instantiated cw721 and ics721 contracts",
"tx_hash", res.Hash,
)
}

return nil
}
}
5 changes: 4 additions & 1 deletion cmd/minitiad/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
sdkConfig.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix)
sdkConfig.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix)
sdkConfig.SetAddressVerifier(wasmtypes.VerifyAddressLen())
sdkConfig.Seal()
//sdkConfig.Seal()

encodingConfig := minitiaapp.MakeEncodingConfig()
basicManager := minitiaapp.BasicManager()
Expand Down Expand Up @@ -166,6 +166,9 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, b
txCommand(),
keys.Commands(),
)

// add launch commands
rootCmd.AddCommand(LaunchCommand(a, encodingConfig, basicManager))
}

func addModuleInitFlags(startCmd *cobra.Command) {
Expand Down
Binary file added contrib/wasm/cw721_base.wasm
Binary file not shown.
Binary file added contrib/wasm/ics721_base.wasm
Binary file not shown.
30 changes: 29 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ require (
google.golang.org/protobuf v1.33.0
)

require github.com/initia-labs/minimove v0.2.8

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
Expand All @@ -69,12 +71,18 @@ require (
github.com/99designs/keyring v1.2.2 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/aws/aws-sdk-go v1.44.224 // indirect
github.com/IGLOU-EU/go-wildcard v1.0.3 // indirect
github.com/aptos-labs/serde-reflection/serde-generate/runtime/golang v0.0.0-20231213012317-73b6bbf74833 // indirect
github.com/avast/retry-go/v4 v4.5.1 // indirect
github.com/aws/aws-sdk-go v1.44.312 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
github.com/celestiaorg/go-square v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
Expand All @@ -87,12 +95,16 @@ require (
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft-db v0.10.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.1.2 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/cosmos/relayer/v2 v2.5.2 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/creachadair/atomicfile v0.3.1 // indirect
github.com/creachadair/tomledit v0.0.24 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand All @@ -106,6 +118,8 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/emicklei/dot v1.6.1 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/ethereum/go-ethereum v1.13.14 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -116,13 +130,16 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-github/v43 v43.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.7 // indirect
Expand All @@ -144,14 +161,19 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/initia-labs/OPinit/api v0.2.6 // indirect
github.com/initia-labs/kvindexer/submodules/move-nft v0.1.1 // indirect
github.com/initia-labs/kvindexer/submodules/move-pair v0.1.0 // indirect
github.com/initia-labs/movevm v0.2.7 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/jsternberg/zap-logfmt v1.3.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
Expand All @@ -166,6 +188,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
Expand All @@ -186,10 +209,13 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/strangelove-ventures/cometbft-client v0.1.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
Expand All @@ -201,6 +227,7 @@ require (
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/net v0.24.0 // indirect
Expand All @@ -220,6 +247,7 @@ require (
gotest.tools/v3 v3.5.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v1.1.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

Expand Down
Loading

0 comments on commit 8fb6e25

Please sign in to comment.