Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move wasm-bindings code out of app #1673

Merged
merged 12 commits into from
Jun 6, 2022
2 changes: 1 addition & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import (
bech32ibctypes "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/types"
bech32ics20keeper "github.com/osmosis-labs/bech32-ibc/x/bech32ics20/keeper"

owasm "github.com/osmosis-labs/osmosis/v7/app/wasm"
_ "github.com/osmosis-labs/osmosis/v7/client/docs/statik"
owasm "github.com/osmosis-labs/osmosis/v7/wasmbinding"
epochskeeper "github.com/osmosis-labs/osmosis/v7/x/epochs/keeper"
epochstypes "github.com/osmosis-labs/osmosis/v7/x/epochs/types"
gammkeeper "github.com/osmosis-labs/osmosis/v7/x/gamm/keeper"
Expand Down
2 changes: 1 addition & 1 deletion simapp/params.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"op_reflect_contract_path": "../app/wasm/testdata/reflect.wasm"
"op_reflect_contract_path": "../wasmbinding/testdata/reflect.wasm"
}
4 changes: 2 additions & 2 deletions app/wasm/README.md → wasmbinding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This package provides first class support for:
- Minting / controlling of new native tokens
- Swap

### Command line interface (CLI)
## Command line interface (CLI)

- Commands

Expand All @@ -26,7 +26,7 @@ This package provides first class support for:
osmosisd query wasm -h
```

### Tests
## Tests

This contains a few high level tests that `x/wasm` is properly
integrated.
Expand Down
2 changes: 1 addition & 1 deletion app/wasm/bindings/msg.go → wasmbinding/bindings/msg.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasmbindings
package bindings

import sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down
2 changes: 1 addition & 1 deletion app/wasm/bindings/pool.go → wasmbinding/bindings/pool.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasmbindings
package bindings

import sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasmbindings
package bindings

import (
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasmbindings
package bindings

import (
"math"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasmbindings
package bindings

import (
"encoding/json"
Expand Down
30 changes: 15 additions & 15 deletions app/wasm/message_plugin.go → wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasm
package wasmbinding

import (
"encoding/json"
Expand All @@ -9,7 +9,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"

wasmbindings "github.com/osmosis-labs/osmosis/v7/app/wasm/bindings"
"github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings"
gammkeeper "github.com/osmosis-labs/osmosis/v7/x/gamm/keeper"
gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types"

Expand Down Expand Up @@ -41,7 +41,7 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre
if msg.Custom != nil {
// only handle the happy path where this is really creating / minting / swapping ...
// leave everything else for the wrapped version
var contractMsg wasmbindings.OsmosisMsg
var contractMsg bindings.OsmosisMsg
if err := json.Unmarshal(msg.Custom, &contractMsg); err != nil {
return nil, nil, sdkerrors.Wrap(err, "osmosis msg")
}
Expand All @@ -64,15 +64,15 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre
return m.wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg)
}

func (m *CustomMessenger) createDenom(ctx sdk.Context, contractAddr sdk.AccAddress, createDenom *wasmbindings.CreateDenom) ([]sdk.Event, [][]byte, error) {
func (m *CustomMessenger) createDenom(ctx sdk.Context, contractAddr sdk.AccAddress, createDenom *bindings.CreateDenom) ([]sdk.Event, [][]byte, error) {
err := PerformCreateDenom(m.tokenFactory, m.bank, ctx, contractAddr, createDenom)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "perform create denom")
}
return nil, nil, nil
}

func PerformCreateDenom(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, createDenom *wasmbindings.CreateDenom) error {
func PerformCreateDenom(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, createDenom *bindings.CreateDenom) error {
if createDenom == nil {
return wasmvmtypes.InvalidRequest{Err: "create denom null create denom"}
}
Expand All @@ -96,15 +96,15 @@ func PerformCreateDenom(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper,
return nil
}

func (m *CustomMessenger) mintTokens(ctx sdk.Context, contractAddr sdk.AccAddress, mint *wasmbindings.MintTokens) ([]sdk.Event, [][]byte, error) {
func (m *CustomMessenger) mintTokens(ctx sdk.Context, contractAddr sdk.AccAddress, mint *bindings.MintTokens) ([]sdk.Event, [][]byte, error) {
err := PerformMint(m.tokenFactory, m.bank, ctx, contractAddr, mint)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "perform mint")
}
return nil, nil, nil
}

func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, mint *wasmbindings.MintTokens) error {
func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, mint *bindings.MintTokens) error {
if mint == nil {
return wasmvmtypes.InvalidRequest{Err: "mint token null mint"}
}
Expand Down Expand Up @@ -132,15 +132,15 @@ func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk
return nil
}

func (m *CustomMessenger) changeAdmin(ctx sdk.Context, contractAddr sdk.AccAddress, changeAdmin *wasmbindings.ChangeAdmin) ([]sdk.Event, [][]byte, error) {
func (m *CustomMessenger) changeAdmin(ctx sdk.Context, contractAddr sdk.AccAddress, changeAdmin *bindings.ChangeAdmin) ([]sdk.Event, [][]byte, error) {
err := ChangeAdmin(m.tokenFactory, ctx, contractAddr, changeAdmin)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "failed to change admin")
}
return nil, nil, nil
}

func ChangeAdmin(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, changeAdmin *wasmbindings.ChangeAdmin) error {
func ChangeAdmin(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, changeAdmin *bindings.ChangeAdmin) error {
if changeAdmin == nil {
return wasmvmtypes.InvalidRequest{Err: "changeAdmin is nil"}
}
Expand All @@ -162,15 +162,15 @@ func ChangeAdmin(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk
return nil
}

func (m *CustomMessenger) burnTokens(ctx sdk.Context, contractAddr sdk.AccAddress, burn *wasmbindings.BurnTokens) ([]sdk.Event, [][]byte, error) {
func (m *CustomMessenger) burnTokens(ctx sdk.Context, contractAddr sdk.AccAddress, burn *bindings.BurnTokens) ([]sdk.Event, [][]byte, error) {
err := PerformBurn(m.tokenFactory, ctx, contractAddr, burn)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "perform burn")
}
return nil, nil, nil
}

func PerformBurn(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, burn *wasmbindings.BurnTokens) error {
func PerformBurn(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, burn *bindings.BurnTokens) error {
if burn == nil {
return wasmvmtypes.InvalidRequest{Err: "burn token null mint"}
}
Expand All @@ -193,7 +193,7 @@ func PerformBurn(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk
return nil
}

func (m *CustomMessenger) swapTokens(ctx sdk.Context, contractAddr sdk.AccAddress, swap *wasmbindings.SwapMsg) ([]sdk.Event, [][]byte, error) {
func (m *CustomMessenger) swapTokens(ctx sdk.Context, contractAddr sdk.AccAddress, swap *bindings.SwapMsg) ([]sdk.Event, [][]byte, error) {
_, err := PerformSwap(m.gammKeeper, ctx, contractAddr, swap)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "perform swap")
Expand All @@ -202,7 +202,7 @@ func (m *CustomMessenger) swapTokens(ctx sdk.Context, contractAddr sdk.AccAddres
}

// PerformSwap can be used both for the real swap, and the EstimateSwap query
func PerformSwap(keeper *gammkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, swap *wasmbindings.SwapMsg) (*wasmbindings.SwapAmount, error) {
func PerformSwap(keeper *gammkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, swap *bindings.SwapMsg) (*bindings.SwapAmount, error) {
if swap == nil {
return nil, wasmvmtypes.InvalidRequest{Err: "gamm perform swap null swap"}
}
Expand All @@ -229,7 +229,7 @@ func PerformSwap(keeper *gammkeeper.Keeper, ctx sdk.Context, contractAddr sdk.Ac
if err != nil {
return nil, sdkerrors.Wrap(err, "gamm perform swap exact amount in")
}
return &wasmbindings.SwapAmount{Out: &tokenOutAmount}, nil
return &bindings.SwapAmount{Out: &tokenOutAmount}, nil
} else if swap.Amount.ExactOut != nil {
routes := []gammtypes.SwapAmountOutRoute{{
PoolId: swap.First.PoolId,
Expand All @@ -255,7 +255,7 @@ func PerformSwap(keeper *gammkeeper.Keeper, ctx sdk.Context, contractAddr sdk.Ac
if err != nil {
return nil, sdkerrors.Wrap(err, "gamm perform swap exact amount out")
}
return &wasmbindings.SwapAmount{In: &tokenInAmount}, nil
return &bindings.SwapAmount{In: &tokenInAmount}, nil
} else {
return nil, wasmvmtypes.UnsupportedRequest{Kind: "must support either Swap.ExactIn or Swap.ExactOut"}
}
Expand Down
18 changes: 9 additions & 9 deletions app/wasm/queries.go → wasmbinding/queries.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasm
package wasmbinding

import (
"fmt"
Expand All @@ -7,7 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

wasmbindings "github.com/osmosis-labs/osmosis/v7/app/wasm/bindings"
"github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings"
gammkeeper "github.com/osmosis-labs/osmosis/v7/x/gamm/keeper"
gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types"
tokenfactorykeeper "github.com/osmosis-labs/osmosis/v7/x/tokenfactory/keeper"
Expand All @@ -26,22 +26,22 @@ func NewQueryPlugin(gk *gammkeeper.Keeper, tfk *tokenfactorykeeper.Keeper) *Quer
}
}

func (qp QueryPlugin) GetDenomAdmin(ctx sdk.Context, denom string) (*wasmbindings.DenomAdminResponse, error) {
func (qp QueryPlugin) GetDenomAdmin(ctx sdk.Context, denom string) (*bindings.DenomAdminResponse, error) {
metadata, err := qp.tokenFactoryKeeper.GetAuthorityMetadata(ctx, denom)
if err != nil {
return nil, fmt.Errorf("failed to get admin for denom: %s", denom)
}

return &wasmbindings.DenomAdminResponse{Admin: metadata.Admin}, nil
return &bindings.DenomAdminResponse{Admin: metadata.Admin}, nil
}

func (qp QueryPlugin) GetPoolState(ctx sdk.Context, poolID uint64) (*wasmbindings.PoolAssets, error) {
func (qp QueryPlugin) GetPoolState(ctx sdk.Context, poolID uint64) (*bindings.PoolAssets, error) {
poolData, err := qp.gammKeeper.GetPoolAndPoke(ctx, poolID)
if err != nil {
return nil, sdkerrors.Wrap(err, "gamm get pool")
}

return &wasmbindings.PoolAssets{
return &bindings.PoolAssets{
Assets: poolData.GetTotalPoolLiquidity(ctx),
Shares: sdk.Coin{
Denom: gammtypes.GetPoolShareDenom(poolID),
Expand All @@ -50,7 +50,7 @@ func (qp QueryPlugin) GetPoolState(ctx sdk.Context, poolID uint64) (*wasmbinding
}, nil
}

func (qp QueryPlugin) GetSpotPrice(ctx sdk.Context, spotPrice *wasmbindings.SpotPrice) (*sdk.Dec, error) {
func (qp QueryPlugin) GetSpotPrice(ctx sdk.Context, spotPrice *bindings.SpotPrice) (*sdk.Dec, error) {
if spotPrice == nil {
return nil, wasmvmtypes.InvalidRequest{Err: "gamm spot price null"}
}
Expand All @@ -77,7 +77,7 @@ func (qp QueryPlugin) GetSpotPrice(ctx sdk.Context, spotPrice *wasmbindings.Spot
return &price, nil
}

func (qp QueryPlugin) EstimateSwap(ctx sdk.Context, estimateSwap *wasmbindings.EstimateSwap) (*wasmbindings.SwapAmount, error) {
func (qp QueryPlugin) EstimateSwap(ctx sdk.Context, estimateSwap *bindings.EstimateSwap) (*bindings.SwapAmount, error) {
if estimateSwap == nil {
return nil, wasmvmtypes.InvalidRequest{Err: "gamm estimate swap null"}
}
Expand All @@ -92,7 +92,7 @@ func (qp QueryPlugin) EstimateSwap(ctx sdk.Context, estimateSwap *wasmbindings.E
return nil, sdkerrors.Wrap(err, "gamm estimate swap sender address")
}

if estimateSwap.Amount == (wasmbindings.SwapAmount{}) {
if estimateSwap.Amount == (bindings.SwapAmount{}) {
return nil, wasmvmtypes.InvalidRequest{Err: "gamm estimate swap empty swap"}
}

Expand Down
4 changes: 2 additions & 2 deletions app/wasm/query_plugin.go → wasmbinding/query_plugin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasm
package wasmbinding

import (
"encoding/json"
Expand All @@ -8,7 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

bindings "github.com/osmosis-labs/osmosis/v7/app/wasm/bindings"
"github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings"
)

func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessage) ([]byte, error) {
Expand Down
Loading