-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add fee abs module * fix tests * fix tests * fix tests * fix tests * feat: integrated feemarket * add fee abs keeper in HandlerOptions * fix tests * add logs * chore: updated anteHandler and postHandler * chore: use replace for feemarket in go.mod * chore: changed go version in docker file * fix : fix testing in antehandler * fix: fix lint issues * chore: updated antehandler * fix: fix lint issues * fix: fix lint issues * fix: lint issus * chore: updated ante and fix test cases * fix: gofumt errors * fix: golint issues * chore: updated postHandler * testing * chore: added test cases * fix * fix * fix: golint issues * fix : fix testcase * fix: fix lint issues * disable update tests * disable report test * fix: added response check in tests * fix * chore: added param subsace for feemarket * add unit tests * fix test * fix lint * remove comment * addressed review comments * fix * fix * fix * TODO in app.go * fix: golint error * add go mod * cheqd changes * go.mod * go mod * Temporarily disabled upgrade test runs + references * chore: added upgradeHandler and upgraded the store loader * add tests * chore: added denom resolver logic for feemarket * Revert "Merge branch 'develop' of https://github.com/cheqd/cheqd-node into ap/add-feeabs-mod" This reverts commit cf4689e, reversing changes made to 5b7e733. * Temporarily disabled upgrade test suite * gofumpt'ed * Bump gas adjustment --------- Co-authored-by: vishal <kannavish329@gmail.com> Co-authored-by: Tasos Derisiotis <50984242+Eengineer1@users.noreply.github.com> Co-authored-by: Vishal Potpelliwar <71565171+vishal-kanna@users.noreply.github.com>
- Loading branch information
1 parent
4bb9399
commit 0c060fc
Showing
12 changed files
with
814 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.