Skip to content

Commit

Permalink
Move wasm-bindings code out of app (#1673)
Browse files Browse the repository at this point in the history
* refactor wasmbing

* refactor in wasmbinding/test

* change wasmbinding file path in simapp test

* README in wasmbinding

* minor

* remove Why Osmosis from README (#1690)

* Fix make format (#1693)

## What is the purpose of the change

Fixes `make format`, needed `mvdan.cc` added to tools directory.

## Brief Changelog

* Add mvdan.cc/gofumpt to tools folder
* Restrict it to only run on `app/ x/ ante/`, it has this annoying problem that it cannot run on the entire root folder because it reads the `.git` folder. It inherits the problem from `gofmt` that it cannot ignore a particular directory.

## Testing and Verifying

This change is a trivial rework / code cleanup without any test coverage.

## Documentation and Release Note

  - Does this pull request introduce a new feature or user-facing behavior changes? no
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? no
  - How is the feature or change documented? Should land into contributing.md once its here

* Delete unused simulator code (#1671)

* Delete unused simulator code

* Add hourly epochs to the x/epochs DefaultGenesis

* Add changelog

* Delete the unused x/gamm/simulation folder

* Fix epochs module tests for updated DefaultGenesis

* update CHANGELOG

* minor

Co-authored-by: alpo <62043214+AlpinYukseloglu@users.noreply.github.com>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 6, 2022
1 parent f21e29e commit 1a00f91
Show file tree
Hide file tree
Showing 24 changed files with 360 additions and 360 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1671](https://github.com/osmosis-labs/osmosis/pull/1671) Add hourly epochs to `x/epochs` DefaultGenesis.
* [#1665](https://github.com/osmosis-labs/osmosis/pull/1665) Delete app/App interface, instead use simapp.App
* [#1630](https://github.com/osmosis-labs/osmosis/pull/1630) Delete the v043_temp module, now that we're on an updated SDK version.

* [#1667](https://github.com/osmosis-labs/osmosis/pull/1673) Move wasm-bindings code out of app .

### Features

Expand Down
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

0 comments on commit 1a00f91

Please sign in to comment.