Skip to content

Commit

Permalink
codec hack
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Mar 20, 2023
1 parent 1302390 commit fdc16a4
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 62 deletions.
4 changes: 2 additions & 2 deletions proto/osmosis/cosmwasmpool/v1beta1/model/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "google/protobuf/timestamp.proto";

option go_package = "github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/model";

message PoolStoreModel {
message CosmWasmPool {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos_proto.implements_interface) = "PoolI";
Expand All @@ -19,4 +19,4 @@ message PoolStoreModel {
uint64 code_id = 4;
bytes instantiate_msg = 5
[ (gogoproto.moretags) = "yaml:\"instantiate_msg\"" ];
}
}
6 changes: 3 additions & 3 deletions x/cosmwasmpool/model/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (
)

func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&PoolStoreModel{}, "osmosis/cosmwasm-pool", nil)
cdc.RegisterConcrete(&CosmWasmPool{}, "osmosis/cosmwasm-pool", nil)
cdc.RegisterConcrete(&MsgCreateCosmWasmPool{}, "osmosis/cosmwasm-create-pool", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterInterface(
"osmosis.poolmanager.v1beta1.PoolI",
(*poolmanagertypes.PoolI)(nil),
&Pool{},
&CosmWasmPool{},
)
registry.RegisterInterface(
"osmosis.cosmwasmpool.v1beta1.CosmWasmExtension",
(*types.CosmWasmExtension)(nil),
&Pool{},
&CosmWasmPool{},
)

registry.RegisterImplementations(
Expand Down
8 changes: 4 additions & 4 deletions x/cosmwasmpool/model/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type Pool struct {
PoolStoreModel
CosmWasmPool
WasmKeeper types.WasmKeeper
}

Expand All @@ -25,7 +25,7 @@ var (
// NewCosmWasmPool creates a new CosmWasm pool with the specified parameters.
func NewCosmWasmPool(poolId uint64, codeId uint64, instantiateMsg []byte) Pool {
pool := Pool{
PoolStoreModel: PoolStoreModel{
CosmWasmPool: CosmWasmPool{
PoolAddress: gammtypes.NewPoolAddress(poolId).String(),
ContractAddress: "", // N.B. This is to be set in InitializePool()
PoolId: poolId,
Expand Down Expand Up @@ -56,7 +56,7 @@ func (p Pool) GetId() uint64 {

// String returns the json marshalled string of the pool
func (p Pool) String() string {
return p.PoolStoreModel.String()
return p.CosmWasmPool.String()
}

// GetSwapFee returns the swap fee of the pool.
Expand Down Expand Up @@ -124,7 +124,7 @@ func (p Pool) SetContractAddress(contractAddress string) {
}

func (p Pool) GetStoreModel() proto.Message {
return &p.PoolStoreModel
return &p.CosmWasmPool
}

// Set the wasm keeper.
Expand Down
92 changes: 46 additions & 46 deletions x/cosmwasmpool/model/pool.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 79 additions & 2 deletions x/cosmwasmpool/model/store_model.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,89 @@
package model

import "encoding/json"
import (
"encoding/json"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gogo/protobuf/proto"

"github.com/osmosis-labs/osmosis/v15/x/cosmwasmpool/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types"
)

var (
_ poolmanagertypes.PoolI = &CosmWasmPool{}
_ types.CosmWasmExtension = &CosmWasmPool{}
)

// String returns the json marshalled string of the pool
func (p PoolStoreModel) String() string {
func (p CosmWasmPool) String() string {
out, err := json.Marshal(p)
if err != nil {
panic(err)
}
return string(out)
}

// poolmanager.PoolI interface implementation

func (p CosmWasmPool) GetAddress() sdk.AccAddress {
panic("CosmWasmPool.GetAddress not implemented")
}

func (p CosmWasmPool) GetId() uint64 {
panic("CosmWasmPool.GetId not implemented")
}

func (p CosmWasmPool) GetSwapFee(ctx sdk.Context) sdk.Dec {
panic("CosmWasmPool.SwapFee not implemented")
}

func (p CosmWasmPool) GetExitFee(ctx sdk.Context) sdk.Dec {
panic("CosmWasmPool.GetExitFee not implemented")
}

func (p CosmWasmPool) IsActive(ctx sdk.Context) bool {
panic("CosmWasmPool.IsActive not implemented")
}

func (p CosmWasmPool) SpotPrice(ctx sdk.Context, baseAssetDenom string, quoteAssetDenom string) (sdk.Dec, error) {
panic("CosmWasmPool.SpotPrice not implemented")
}

func (p CosmWasmPool) GetTotalShares() sdk.Int {
panic("CosmWasmPool.GetTotalShares not implemented")
}

func (p CosmWasmPool) GetType() poolmanagertypes.PoolType {
panic("CosmWasmPool.GetType not implemented")
}

func (p CosmWasmPool) GetTotalPoolLiquidity(ctx sdk.Context) sdk.Coins {
panic("CosmWasmPool.GetTotalPoolLiquidity not implemented")
}

// types.CosmWasmExtension interface implementation

func (p CosmWasmPool) GetCodeId() uint64 {
panic("CosmWasmPool.GetType not implemented")
}

func (p CosmWasmPool) GetInstantiateMsg() []byte {
panic("CosmWasmPool.GetInstantiateMsg not implemented")
}

func (p CosmWasmPool) GetContractAddress() string {
panic("CosmWasmPool.GetContractAddress not implemented")
}

func (p CosmWasmPool) SetContractAddress(contractAddress string) {
panic("CosmWasmPool.SetContractAddress not implemented")
}

func (p CosmWasmPool) GetStoreModel() proto.Message {
panic("CosmWasmPool.GetStoreModel not implemented")
}

func (p CosmWasmPool) SetWasmKeeper(wasmKeeper types.WasmKeeper) {
panic("CosmWasmPool.SetWasmKeeeper not implemented")
}
4 changes: 2 additions & 2 deletions x/cosmwasmpool/pool_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *PoolModuleSuite) TestInitializePool() {
var (
defaultPoolId = uint64(1)
validTestPool = &model.Pool{
PoolStoreModel: model.PoolStoreModel{
CosmWasmPool: model.CosmWasmPool{
PoolAddress: gammtypes.NewPoolAddress(defaultPoolId).String(),
ContractAddress: "", // N.B.: to be set in InitializePool()
PoolId: defaultPoolId,
Expand Down Expand Up @@ -100,7 +100,7 @@ func (s *PoolModuleSuite) TestInitializePool() {
// Check that the pool's data is set
expectedPool := validTestPool
expectedPool.ContractAddress = tc.mockInstantiateReturn.contractAddress.String()
s.Require().Equal(expectedPool.PoolStoreModel, cosmWasmPool.PoolStoreModel)
s.Require().Equal(expectedPool.CosmWasmPool, cosmWasmPool.CosmWasmPool)
})
}
}
6 changes: 3 additions & 3 deletions x/cosmwasmpool/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (k Keeper) setPool(ctx sdk.Context, pool types.CosmWasmExtension) {
// getPoolById returns a concentratedPoolExtension that corresponds to the requested pool id. Returns error if pool id is not found.
func (k Keeper) getPoolById(ctx sdk.Context, poolId uint64) (types.CosmWasmExtension, error) {
store := ctx.KVStore(k.storeKey)
pool := model.PoolStoreModel{}
pool := model.CosmWasmPool{}
key := types.FormatPoolsPrefix(poolId)
found, err := osmoutils.Get(store, key, &pool)
if err != nil {
Expand All @@ -26,7 +26,7 @@ func (k Keeper) getPoolById(ctx sdk.Context, poolId uint64) (types.CosmWasmExten
return nil, types.PoolNotFoundError{PoolId: poolId}
}
return &model.Pool{
PoolStoreModel: pool,
WasmKeeper: k.wasmKeeper,
CosmWasmPool: pool,
WasmKeeper: k.wasmKeeper,
}, nil
}

0 comments on commit fdc16a4

Please sign in to comment.