Skip to content

Commit

Permalink
Merge pull request #12 from cosmic-horizon/interchain_account
Browse files Browse the repository at this point in the history
Add game module spec
  • Loading branch information
dpdanpittman authored Sep 16, 2022
2 parents f6e61ac + 9f7682b commit b798e5b
Show file tree
Hide file tree
Showing 22 changed files with 6,723 additions and 2,064 deletions.
1 change: 0 additions & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
dbm "github.com/tendermint/tm-db"
)

// Setup initializes a new BitsongApp
func Setup(isCheckTx bool) *App {
db := dbm.NewMemDB()
app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{})
Expand Down
14 changes: 7 additions & 7 deletions cosmwasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Here's [installation guide](https://doc.rust-lang.org/cargo/getting-started/inst
cohod keys add signer --keyring-backend=test --home=$HOME/.cohod --recover
# pipe woman clutch absorb lonely cost credit math antique better thumb cook pave clarify hungry east garbage absent warfare song helmet anchor drift purity

cohod tx bank send validator $(cohod keys show -a signer --keyring-backend=test --home=$HOME/.cohod) 1000000stake --keyring-backend=test --home=$HOME/.cohod --broadcast-mode=block -y --chain-id=test
cohod tx bank send validator $(cohod keys show -a signer --keyring-backend=test --home=$HOME/.cohod) 1000000stake --keyring-backend=test --home=$HOME/.cohod --broadcast-mode=block -y --chain-id=qwoyn-1
```

## Build Contracts
Expand Down Expand Up @@ -47,7 +47,7 @@ cohod tx wasm store $WASM_FILE --from $FROM --chain-id $CHAIN_ID --gas auto --ga
Example command to upload Ship NFT wasm binary to local test node

```
cohod tx wasm store ./artifacts/ship_nft.wasm --from validator --chain-id test --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ -y
cohod tx wasm store ./artifacts/ship_nft.wasm --from validator --chain-id qwoyn-1 --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ -y
```

## Instantiate Contract
Expand All @@ -66,7 +66,7 @@ cohod tx wasm instantiate $CODE_ID $INSTANTIATE_MSG --from $FROM --label $LABEL
Example command to init Ship NFT contract on local test node

```
cohod tx wasm instantiate 1 '{"name":"Ship NFT","symbol":"SHIP","minter":"coho1x0fha27pejg5ajg8vnrqm33ck8tq6raafkwa9v","owner":"coho1x0fha27pejg5ajg8vnrqm33ck8tq6raafkwa9v"}' --from validator --label "Ship-NFT" --chain-id test --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ --no-admin -y
cohod tx wasm instantiate 1 '{"name":"Ship NFT","symbol":"SHIP","minter":"coho1x0fha27pejg5ajg8vnrqm33ck8tq6raafkwa9v","owner":"coho1x0fha27pejg5ajg8vnrqm33ck8tq6raafkwa9v"}' --from validator --label "Ship-NFT" --chain-id qwoyn-1 --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ --no-admin -y
```

## Get Contract Address
Expand Down Expand Up @@ -99,15 +99,15 @@ cohod tx wasm execute $CONTRACT_ADDRESS $EXECUTE_MSG --from $FROM --chain-id $CH
Example command to mint Ship NFT with token_id "1"

```
cohod tx wasm execute coho14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9snm4thc '{"mint":{"token_id":"1","owner":"coho1x0fha27pejg5ajg8vnrqm33ck8tq6raafkwa9v","extension":{"ship_type":10,"owner":"100"}}}' --from signer --chain-id test --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ -y
cohod tx wasm execute coho14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9snm4thc '{"mint":{"token_id":"1","owner":"coho1x0fha27pejg5ajg8vnrqm33ck8tq6raafkwa9v","extension":{"ship_type":10,"owner":"100"}}}' --from signer --chain-id qwoyn-1 --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ -y
```

## Transfer NFT

Example command to transfer minted Ship NFT with token_id "1"

```
cohod tx wasm execute coho14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9snm4thc '{"transfer_nft":{"token_id":"1","recipient":"coho1x0fha27pejg5ajg8vnrqm33ck8tq6raafkwa9v"}}' --from signer --chain-id test --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ -y
cohod tx wasm execute coho14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9snm4thc '{"transfer_nft":{"token_id":"1","recipient":"coho1x0fha27pejg5ajg8vnrqm33ck8tq6raafkwa9v"}}' --from signer --chain-id qwoyn-1 --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ -y
```

## Get NFT Info
Expand Down Expand Up @@ -147,7 +147,7 @@ cohod tx wasm execute $CONTRACT_ADDRESS $EXECUTE_MSG --from $FROM --chain-id $CH
Example command to update Ship NFT with token_id "1"

```
cohod tx wasm execute coho14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9snm4thc '{"update_nft":{"token_id":"1","extension":{"ship_type":20,"owner":"200"}}}' --from signer --chain-id test --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ -y
cohod tx wasm execute coho14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9snm4thc '{"update_nft":{"token_id":"1","extension":{"ship_type":20,"owner":"200"}}}' --from signer --chain-id qwoyn-1 --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ -y
```

## Transfer Ownership
Expand All @@ -166,5 +166,5 @@ cohod tx wasm execute $CONTRACT_ADDRESS $EXECUTE_MSG --from $FROM --chain-id $CH
Example command to transfer ownership to `coho1f0yhatqxayku7y00k448n43qwch320v4da2plx`

```
cohod tx wasm execute coho14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9snm4thc '{"transfer_ownership":{"owner":"coho1f0yhatqxayku7y00k448n43qwch320v4da2plx"}}' --from signer --chain-id test --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ -y
cohod tx wasm execute coho14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9snm4thc '{"transfer_ownership":{"owner":"coho1f0yhatqxayku7y00k448n43qwch320v4da2plx"}}' --from signer --chain-id qwoyn-1 --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.cohod/ -y
```
2 changes: 2 additions & 0 deletions proto/game/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "game/params.proto";
import "game/game.proto";
import "game/liquidity.proto";

option go_package = "github.com/cosmic-horizon/coho/x/game/types";

Expand All @@ -16,4 +17,5 @@ message GenesisState {
repeated string whitelisted_contracts = 3;
repeated Unbonding unbondings = 4 [ (gogoproto.nullable) = false ];
uint64 last_unbonding_id = 5;
Liquidity liquidity = 6 [ (gogoproto.nullable) = false ];
}
76 changes: 76 additions & 0 deletions proto/game/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,79 @@ message MsgSwap {
cosmos.base.v1beta1.Coin amount = 2 [ (gogoproto.nullable) = false ];
}
message MsgSwapResponse {}

message EventTransferModuleOwnership {
string origin_owner = 1;
string new_owner = 2;
}

message EventNftContractAddWhitelist {
string contract = 1;
}

message EventNftContractRemoveWhitelist {
string contract = 1;
}

message EventDepositNft {
string owner = 1;
string contract = 2;
uint64 token_id = 3;
}

message EventWithdrawNft {
string sender = 1;
string contract = 2;
uint64 token_id = 3;
string exec_msg = 4;
}

message EventDepositToken {
string sender = 1;
string amount = 2;
}

message EventWithdrawToken {
string sender = 1;
string amount = 2;
}

message EventStakeInGameToken {
string sender = 1;
string amount = 2;
}

message EventClaimInGameStakingReward {
string sender = 1;
string amount = 2;
uint64 reward_claim_time = 3;
}

message EventBeginUnstakeInGameToken {
string sender = 1;
string amount = 2;
uint64 completion_time = 3;
}

message EventCompleteUnstakeInGameToken {
string user = 1;
string amount = 2;
uint64 completion_time = 3;
uint64 unbonding_id = 4;
}

message EventAddLiquidity {
string sender = 1;
string amounts = 2;
}

message EventRemoveLiquidity {
string sender = 1;
string amounts = 2;
}

message EventSwap {
string sender = 1;
string in_amount = 2;
string out_amount = 3;
}
4 changes: 2 additions & 2 deletions x/game/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func GetCmdSignWithdrawUpdatedNft() *cobra.Command {

func GetCmdWithdrawUpdatedNft() *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw-updated-nft [contract] [tokenId] [execMsg] [flags]",
Use: "withdraw-updated-nft [contract] [tokenId] [execMsg] [signature] [flags]",
Long: "Withdraw updated nft",
Args: cobra.ExactArgs(4),
Example: fmt.Sprintf(
Expand Down Expand Up @@ -435,7 +435,7 @@ func GetCmdBeginUnstakeInGameToken() *cobra.Command {

func GetCmdClaimInGameStakingReward() *cobra.Command {
cmd := &cobra.Command{
Use: "claim-ingame-staking-reward [coin] [flags]",
Use: "claim-ingame-staking-reward [flags]",
Long: "Claim ingame staking reward",
Args: cobra.ExactArgs(0),
Example: fmt.Sprintf(
Expand Down
2 changes: 2 additions & 0 deletions x/game/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
k.SetParamSet(ctx, genState.Params)
k.SetLastUnbondingId(ctx, genState.LastUnbondingId)
k.SetLiquidity(ctx, genState.Liquidity)

for _, deposit := range genState.Deposits {
k.SetDeposit(ctx, deposit)
Expand All @@ -33,6 +34,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis.WhitelistedContracts = k.GetAllWhitelistedContracts(ctx)
genesis.Unbondings = k.GetAllUnbondings(ctx)
genesis.LastUnbondingId = k.GetLastUnbondingId(ctx)
genesis.Liquidity = k.GetLiquidity(ctx)

return genesis
}
9 changes: 9 additions & 0 deletions x/game/keeper/abci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"github.com/cosmic-horizon/coho/x/game/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -20,5 +21,13 @@ func (k Keeper) EndBlocker(ctx sdk.Context) {
continue
}
k.DeleteUnbonding(ctx, unbonding)

// emit event
ctx.EventManager().EmitTypedEvent(&types.EventCompleteUnstakeInGameToken{
User: unbonding.StakerAddress,
Amount: unbonding.Amount.String(),
CompletionTime: uint64(ctx.BlockTime().Unix()),
UnbondingId: unbonding.Id,
})
}
}
9 changes: 8 additions & 1 deletion x/game/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ func (k Keeper) AllDepositBalance(c context.Context, req *types.QueryAllDepositB
}

ctx := sdk.UnwrapSDKContext(c)
params := k.GetParamSet(ctx)
deposits := k.GetAllDeposits(ctx)
amount := sdk.ZeroInt()
for _, deposit := range deposits {
amount = amount.Add(deposit.Amount)
}
return &types.QueryAllDepositBalanceResponse{
Deposits: k.GetAllDeposits(ctx),
Deposits: deposits,
Amount: sdk.NewCoin(params.DepositDenom, amount),
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion x/game/keeper/ingame_unbonding.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (k Keeper) GetUserUnbondings(ctx sdk.Context, addr sdk.AccAddress) []types.
store := ctx.KVStore(k.storeKey)

unbondings := []types.Unbonding{}
it := store.Iterator(types.PrefixInGameUnbondingTimeKey, sdk.InclusiveEndBytes(types.InGameUnbondingUserPrefixKey(addr)))
it := sdk.KVStorePrefixIterator(store, types.InGameUnbondingUserPrefixKey(addr))
defer it.Close()

for ; it.Valid(); it.Next() {
Expand Down
Loading

0 comments on commit b798e5b

Please sign in to comment.