Skip to content

Commit

Permalink
Merge pull request #149 from notional-labs/minh/sdk47
Browse files Browse the repository at this point in the history
bump sdk 47
  • Loading branch information
GNaD13 authored Aug 3, 2023
2 parents 791a799 + 422c883 commit 1ff2732
Show file tree
Hide file tree
Showing 106 changed files with 7,248 additions and 2,497 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/interchaintest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,38 @@ on:
- main

jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
-
name: Check out the repo
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
id: build_push_image
uses: docker/build-push-action@v3
with:
file: Dockerfile
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/notional-labs/fee-abstraction-ictest:latest
test-basic:
runs-on: ubuntu-latest
needs: build-and-push-image
steps:
- name: Set up Go 1.19
uses: actions/setup-go@v3
Expand All @@ -19,9 +49,12 @@ jobs:
uses: actions/checkout@v3

- run: make ictest-basic
env:
BRANCH_CI: "latest"

test-ibc:
runs-on: ubuntu-latest
needs: build-and-push-image
steps:
- name: Set up Go 1.19
uses: actions/setup-go@v3
Expand All @@ -32,8 +65,12 @@ jobs:
uses: actions/checkout@v3

- run: make ictest-ibc
env:
BRANCH_CI: "latest"

test-packet-forward:
runs-on: ubuntu-latest
needs: build-and-push-image
steps:
- name: Set up Go 1.19
uses: actions/setup-go@v3
Expand All @@ -44,4 +81,6 @@ jobs:
uses: actions/checkout@v3

- run: make ictest-packet-forward
env:
BRANCH_CI: "latest"

16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ endif

LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::')
TM_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8
BUILDDIR ?= $(CURDIR)/build
Expand Down Expand Up @@ -64,7 +64,7 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=feeapp \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TM_VERSION)
-X github.com/cometbft/cometbft/version.TMCoreSemVer=$(TM_VERSION)

ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
Expand Down Expand Up @@ -93,6 +93,9 @@ install: go.sum
build:
go build $(BUILD_FLAGS) -o bin/feeappd ./cmd/feeappd

docker-build-debug:
@DOCKER_BUILDKIT=1 docker build -t feeapp:debug -f Dockerfile .

###############################################################################
### Interchain test ###
###############################################################################
Expand All @@ -117,18 +120,13 @@ ictest-all: ictest-basic ictest-ibc ictest-packet-forward
###############################################################################
### Proto ###
###############################################################################

protoVer=0.11.6
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
containerProtoGen=fa-proto-gen-$(protoVer)
containerProtoFmt=fa-proto-fmt-$(protoVer)
PROTO_BUILDER_IMAGE=ghcr.io/cosmos/proto-builder

proto-all: proto-format proto-gen

proto-gen:
@echo "Generating Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \
sh ./scripts/protocgen.sh; fi
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(PROTO_BUILDER_IMAGE) sh ./scripts/protocgen.sh

proto-format:
@echo "Formatting Protobuf files"
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ We modified `MempoolFeeDecorator` so that it can handle ibc-osmosis as fee. If t
We have an account to manage the ibc-osmosis user used to pay for tx fee. The collected osmosis fee is sent to that account instead of community pool account.

#### Swap accumulated ibc-tokens fee
##### Swap with Osmosis's tokens
We use osmosis's ibc hook feature to do this. We basically ibc transfer to the osmosis crosschain swap contract with custom memo to swap the osmosis fee back to customer chain's native-token and ibc transfer back to the customer chain.
Fee-abstraction will use osmosis's Cross chain Swap (XCS) feature to do this. We basically ibc transfer to the osmosis crosschain swap contract with custom memo to swap the osmosis fee back to customer chain's native-token and ibc transfer back to the customer chain.

##### Swap with others ibc-tokens
We use [``packet-forward-middleware``](https://github.com/strangelove-ventures/packet-forward-middleware) to do this. The ibc-tokens will be transferred to the host chain with the specific MEMO to forwarding transfer to osmosis crosschain swap contract. After that, Osmosis chain will swap to customer chain's native-token and ibc transfer back to the customer chain.
Current version of fee-abstraction working with XCSv2

## Resources
- Main repo: https://github.com/notional-labs/fee-abstraction
Expand Down
19 changes: 10 additions & 9 deletions ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package ante

import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
errorstypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v4/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
Expand All @@ -19,13 +20,13 @@ type HandlerOptions struct {

func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
if opts.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return nil, sdkerrors.Wrap(errorstypes.ErrLogic, "account keeper is required for AnteHandler")
}
if opts.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return nil, sdkerrors.Wrap(errorstypes.ErrLogic, "bank keeper is required for AnteHandler")
}
if opts.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, sdkerrors.Wrap(errorstypes.ErrLogic, "sign mode handler is required for ante builder")
}

sigGasConsumer := opts.SigGasConsumer
Expand All @@ -35,20 +36,20 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(),
ante.NewRejectExtensionOptionsDecorator(),
ante.RejectExtensionOptionsDecorator{},
NewMempoolFeeDecorator(opts.BypassMinFeeMsgTypes),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(opts.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper),
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(opts.AccountKeeper),
ante.NewValidateSigCountDecorator(opts.AccountKeeper),
ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler),
ante.NewIncrementSequenceDecorator(opts.AccountKeeper),
ibcante.NewAnteDecorator(opts.IBCkeeper),
ibcante.NewRedundantRelayDecorator(opts.IBCkeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
12 changes: 6 additions & 6 deletions ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import (
"fmt"
"testing"

tmrand "github.com/cometbft/cometbft/libs/rand"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/stretchr/testify/suite"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/notional-labs/fee-abstraction/v2/app"
apphelpers "github.com/notional-labs/fee-abstraction/v2/app/helpers"
"github.com/notional-labs/fee-abstraction/v4/app"
apphelpers "github.com/notional-labs/fee-abstraction/v4/app/helpers"
)

type IntegrationTestSuite struct {
Expand All @@ -41,7 +41,7 @@ func (s *IntegrationTestSuite) SetupTest() {
Height: 1,
})

encodingConfig := simapp.MakeTestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry)

Expand Down
9 changes: 5 additions & 4 deletions ante/fee.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package ante

import (
tmstrings "github.com/cometbft/cometbft/libs/strings"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
tmstrings "github.com/tendermint/tendermint/libs/strings"
sdkerrors "cosmossdk.io/errors"
errorstypes "github.com/cosmos/cosmos-sdk/types/errors"
)

const maxBypassMinFeeMsgGasUsage = uint64(200_000)
Expand All @@ -29,7 +30,7 @@ func NewMempoolFeeDecorator(bypassMsgTypes []string) MempoolFeeDecorator {
func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
return ctx, sdkerrors.Wrap(errorstypes.ErrTxDecode, "Tx must be a FeeTx")
}

feeCoins := feeTx.GetFee()
Expand All @@ -54,7 +55,7 @@ func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b
}

if !feeCoins.IsAnyGTE(requiredFees) {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees)
return ctx, sdkerrors.Wrapf(errorstypes.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
ibcclienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

"github.com/notional-labs/fee-abstraction/v2/ante"
"github.com/notional-labs/fee-abstraction/v4/ante"
)

func (s *IntegrationTestSuite) TestMempoolFeeDecorator() {
Expand Down
21 changes: 11 additions & 10 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "cosmossdk.io/errors"
errorstypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v4/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

feeabsante "github.com/notional-labs/fee-abstraction/v2/x/feeabs/ante"
feeabskeeper "github.com/notional-labs/fee-abstraction/v2/x/feeabs/keeper"
feeabsante "github.com/notional-labs/fee-abstraction/v4/x/feeabs/ante"
feeabskeeper "github.com/notional-labs/fee-abstraction/v4/x/feeabs/keeper"
)

// HandlerOptions extends the SDK's AnteHandler options by requiring the IBC
Expand All @@ -24,15 +25,15 @@ type HandlerOptions struct {
// signer.
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
return nil, sdkerrors.Wrap(errorstypes.ErrLogic, "account keeper is required for ante builder")
}

if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
return nil, sdkerrors.Wrap(errorstypes.ErrLogic, "bank keeper is required for ante builder")
}

if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, sdkerrors.Wrap(errorstypes.ErrLogic, "sign mode handler is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
Expand All @@ -42,7 +43,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewRejectExtensionOptionsDecorator(),
ante.RejectExtensionOptionsDecorator{},
feeabsante.NewFeeAbstrationMempoolFeeDecorator(options.FeeAbskeeper),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
Expand All @@ -55,7 +56,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
Loading

0 comments on commit 1ff2732

Please sign in to comment.