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

feat: add fee abs module #780

Merged
merged 63 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
cf56c42
add fee abs module
atheeshp Aug 19, 2024
5a90925
fix tests
atheeshp Aug 27, 2024
e355a38
fix tests
atheeshp Aug 27, 2024
dcf202d
fix tests
atheeshp Aug 27, 2024
291ad7f
fix tests
atheeshp Aug 27, 2024
89c3505
feat: integrated feemarket
vishal-kanna Aug 27, 2024
321ae23
add fee abs keeper in HandlerOptions
atheeshp Aug 27, 2024
5d403ad
fix tests
atheeshp Aug 28, 2024
2c0ae04
add logs
atheeshp Aug 28, 2024
defe327
chore: updated anteHandler and postHandler
vishal-kanna Aug 28, 2024
5e33e65
chore: use replace for feemarket in go.mod
vishal-kanna Aug 28, 2024
d5667f0
chore: changed go version in docker file
vishal-kanna Aug 29, 2024
8684ce9
fix : fix testing in antehandler
vishal-kanna Aug 29, 2024
ea06beb
fix: fix lint issues
vishal-kanna Aug 29, 2024
d09e816
chore: updated antehandler
vishal-kanna Aug 29, 2024
adcd9f3
fix: fix lint issues
vishal-kanna Aug 29, 2024
e2f6a74
fix: fix lint issues
vishal-kanna Aug 29, 2024
f016460
fix: lint issus
vishal-kanna Aug 29, 2024
36202e4
chore: updated ante and fix test cases
vishal-kanna Aug 30, 2024
945b3cc
fix: gofumt errors
vishal-kanna Aug 30, 2024
74089c2
fix: golint issues
vishal-kanna Aug 30, 2024
4256d7f
chore: updated postHandler
vishal-kanna Aug 30, 2024
acd8d74
testing
vishal-kanna Sep 3, 2024
4779b6a
chore: added test cases
vishal-kanna Sep 4, 2024
9557978
fix
vishal-kanna Sep 4, 2024
044bc3d
fix
vishal-kanna Sep 4, 2024
b2b8502
fix: golint issues
vishal-kanna Sep 4, 2024
e2866fb
fix : fix testcase
vishal-kanna Sep 5, 2024
9bcd0cb
fix: fix lint issues
vishal-kanna Sep 5, 2024
64c505d
disable update tests
vishal-kanna Sep 5, 2024
b05f6ee
disable report test
vishal-kanna Sep 5, 2024
9af6f82
fix: added response check in tests
vishal-kanna Sep 5, 2024
6181458
fix
vishal-kanna Sep 5, 2024
33403e1
chore: added param subsace for feemarket
vishal-kanna Sep 6, 2024
9a5c9d8
add unit tests
atheeshp Sep 6, 2024
98d86ea
fix test
atheeshp Sep 9, 2024
358cdb0
fix lint
atheeshp Sep 9, 2024
3827e97
remove comment
atheeshp Sep 9, 2024
05fa0ec
addressed review comments
vishal-kanna Sep 10, 2024
281af5e
chore: merged feemarket integration PR
vishal-kanna Sep 10, 2024
0c5a67b
fix
vishal-kanna Sep 10, 2024
1fd19a2
fix
vishal-kanna Sep 10, 2024
cb727e6
fix
vishal-kanna Sep 10, 2024
611e181
TODO in app.go
vishal-kanna Sep 10, 2024
af939e1
fix: golint error
vishal-kanna Sep 10, 2024
3bb51c1
add go mod
atheeshp Sep 11, 2024
b4c7afe
Merge branch 'vishal/integrate-antehandler' of github.com:cheqd/cheqd…
atheeshp Sep 11, 2024
999d9bb
cheqd changes
atheeshp Sep 17, 2024
2a1528a
go.mod
atheeshp Sep 17, 2024
98e903b
go mod
atheeshp Sep 17, 2024
15b751a
Temporarily disabled upgrade test runs + references
Eengineer1 Sep 18, 2024
9a64ed4
chore: added upgradeHandler and upgraded the store loader
vishal-kanna Sep 19, 2024
bd49157
Merge branch 'vishal/integrate-antehandler' of https://github.com/che…
vishal-kanna Sep 19, 2024
6ea0b87
add tests
atheeshp Sep 19, 2024
985acee
Merge branch 'vishal/integrate-antehandler' into ap/add-feeabs-mod
Eengineer1 Sep 19, 2024
1971cc2
chore: added denom resolver logic for feemarket
vishal-kanna Sep 20, 2024
5b7e733
Merge branch 'develop' into ap/add-feeabs-mod
vishal-kanna Sep 20, 2024
cf4689e
Merge branch 'develop' of https://github.com/cheqd/cheqd-node into ap…
vishal-kanna Sep 20, 2024
9d928b9
Revert "Merge branch 'develop' of https://github.com/cheqd/cheqd-node…
Eengineer1 Sep 24, 2024
4684112
Merge branch 'develop' into ap/add-feeabs-mod
Eengineer1 Sep 24, 2024
80e6c46
Temporarily disabled upgrade test suite
Eengineer1 Sep 24, 2024
1a50b17
gofumpt'ed
Eengineer1 Sep 24, 2024
23fdff8
Bump gas adjustment
Eengineer1 Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions ante/ante_feeabs_feemarket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package ante

import (
"fmt"

feeabskeeper "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/keeper"
feeabstypes "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/types"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"

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

// DenomResolverImpl is Gaia's implementation of x/feemarket's DenomResolver
type DenomResolverImpl struct {
FeeabsKeeper feeabskeeper.Keeper
StakingKeeper feeabstypes.StakingKeeper
}

var _ feemarkettypes.DenomResolver = &DenomResolverImpl{}

// ConvertToDenom converts any given coin to the native denom of the chain or the other way around.
// Return error if neither of coin.Denom and denom is the native denom of the chain.
// If the denom is the bond denom, convert `coin` to the native denom. return error if coin.Denom is not in the allowed list
// If the denom is not the bond denom, convert the `coin` to the given denom. return error if denom is not in the allowed list
func (r *DenomResolverImpl) ConvertToDenom(ctx sdk.Context, coin sdk.DecCoin, denom string) (sdk.DecCoin, error) {
bondDenom := r.StakingKeeper.BondDenom(ctx)
fmt.Println("Here>>>>>>>>>>>>>>>> ConvertToDenom and bondDenom and denom", bondDenom, denom, coin)
if denom != bondDenom && coin.Denom != bondDenom {
return sdk.DecCoin{}, ErrNeitherNativeDenom(coin.Denom, denom)
}
var amount sdk.Coins
var hostZoneConfig feeabstypes.HostChainFeeAbsConfig
var found bool
var err error

if denom == bondDenom {

fmt.Println("Here<<<<<<<<<<<<<<<<<<< in if statement")
hostZoneConfig, found = r.FeeabsKeeper.GetHostZoneConfig(ctx, coin.Denom)
if !found {
return sdk.DecCoin{}, ErrDenomNotRegistered(coin.Denom)
}
amount, err = r.getIBCCoinFromNative(ctx, sdk.NewCoins(sdk.NewCoin(coin.
Denom, coin.Amount.TruncateInt())), hostZoneConfig)
} else if coin.Denom == bondDenom {
fmt.Println("here in elseif>>>>>>>>>>", coin.Denom, bondDenom)
hostZoneConfig, found := r.FeeabsKeeper.GetHostZoneConfig(ctx, denom)
if !found {
return sdk.DecCoin{}, ErrDenomNotRegistered(denom)
}
amount, err = r.FeeabsKeeper.CalculateNativeFromIBCCoins(ctx, sdk.NewCoins(sdk.NewCoin(denom, coin.Amount.TruncateInt())), hostZoneConfig)
}

if err != nil {
return sdk.DecCoin{}, err
}
fmt.Println(">>>>>>>>>>>>>>>>>>>", sdk.NewDecCoinFromDec(denom, amount[0].Amount.ToLegacyDec()))
return sdk.NewDecCoinFromDec(denom, amount[0].Amount.ToLegacyDec()), nil
}

// ExtraDenoms should be all denoms that have been registered via governance(host zone)
func (r *DenomResolverImpl) ExtraDenoms(ctx sdk.Context) ([]string, error) {
allHostZoneConfigs, err := r.FeeabsKeeper.GetAllHostZoneConfig(ctx)
if err != nil {
return nil, err
}
denoms := make([]string, 0, len(allHostZoneConfigs))
for _, hostZoneConfig := range allHostZoneConfigs {
denoms = append(denoms, hostZoneConfig.IbcDenom)
}
return denoms, nil
}

// //////////////////////////////////////
// Helper functions for DenomResolver //
// //////////////////////////////////////

func (r *DenomResolverImpl) getIBCCoinFromNative(ctx sdk.Context, nativeCoins sdk.Coins, chainConfig feeabstypes.HostChainFeeAbsConfig) (coins sdk.Coins, err error) {
if len(nativeCoins) != 1 {
return sdk.Coins{}, ErrExpectedOneCoin(len(nativeCoins))
}

nativeCoin := nativeCoins[0]

twapRate, err := r.FeeabsKeeper.GetTwapRate(ctx, chainConfig.IbcDenom)
if err != nil {
return sdk.Coins{}, err
}

// Divide native amount by twap rate to get IBC amount
ibcAmount := nativeCoin.Amount.ToLegacyDec().Quo(twapRate).RoundInt()
ibcCoin := sdk.NewCoin(chainConfig.IbcDenom, ibcAmount)

// Verify the resulting IBC coin
err = r.verifyIBCCoins(ctx, sdk.NewCoins(ibcCoin))
if err != nil {
return sdk.Coins{}, err
}

return sdk.NewCoins(ibcCoin), nil
}

// return err if IBC token isn't in allowed_list
func (r *DenomResolverImpl) verifyIBCCoins(ctx sdk.Context, ibcCoins sdk.Coins) error {
if ibcCoins.Len() != 1 {
return feeabstypes.ErrInvalidIBCFees
}

ibcDenom := ibcCoins[0].Denom
if r.FeeabsKeeper.HasHostZoneConfig(ctx, ibcDenom) {
return nil
}
return feeabstypes.ErrUnsupportedDenom.Wrapf("unsupported denom: %s", ibcDenom)
}
17 changes: 17 additions & 0 deletions ante/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ante

import (
"fmt"
)

func ErrNeitherNativeDenom(coinDenom, denom string) error {
return fmt.Errorf("neither of coin.Denom %s and denom %s is the native denom of the chain", coinDenom, denom)
}

func ErrDenomNotRegistered(denom string) error {
return fmt.Errorf("denom %s not registered in host zone", denom)
}

func ErrExpectedOneCoin(count int) error {
return fmt.Errorf("expected exactly one native coin, got %d", count)
}
2 changes: 2 additions & 0 deletions ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

type BankKeeper interface {
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin

SendCoins(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
Expand Down
Loading
Loading