Skip to content

Commit

Permalink
fix: default unordered ICA channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockwarr committed Jan 9, 2025
1 parent a8a21b0 commit 7938496
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion proto/nolus/tax/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ message MsgUpdateParams {
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
message MsgUpdateParamsResponse {}
4 changes: 2 additions & 2 deletions x/interchaintxs/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (k Keeper) RegisterInterchainAccount(goCtx context.Context, msg *ictxtypes.
resp, err := k.icaControllerMsgServer.RegisterInterchainAccount(ctx, &icacontrollertypes.MsgRegisterInterchainAccount{
Owner: icaOwner,
ConnectionId: msg.ConnectionId,
Version: "", // FIXME: empty version string doesn't look good
Ordering: channeltypes.ORDERED, // TODO: make it configurable or use UNORDERED after contracts upgrade
Version: "", // FIXME: empty version string doesn't look good
Ordering: channeltypes.UNORDERED,
})
if err != nil {
k.Logger(ctx).Debug("RegisterInterchainAccount: failed to RegisterInterchainAccount:", "error", err, "owner", icaOwner, "msg", &msg)
Expand Down
22 changes: 12 additions & 10 deletions x/tax/keeper/custom_tx_fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,44 +94,46 @@ func getFeeParamBasedOnDenom(feeParams []*types.DexFeeParams, feeCoins sdk.Coins
correctFeeParam = findDenom(*feeParam, feeCoins)
// if there is a match then we ensure this feeParam with correct profit
// smart contrat addresses will be used. This is in case of multiple supported DEXes.
if isFeeParamValid(correctFeeParam) {
if correctFeeParam != nil {
return correctFeeParam, nil
}
}

return nil, errors.Wrapf(types.ErrInvalidFeeDenom, "no fee param found for denoms: %s", feeCoins)
}

func isFeeParamValid(feeParam *types.DexFeeParams) bool {
if feeParam == nil {
func validateFeeParam(profitAddress string, pair *types.DenomPrice) bool {
if profitAddress == "" {
return false
}
if feeParam.ProfitAddress == "" || feeParam.AcceptedDenomsMinPrices == nil {
if pair.Denom == "" || pair.MinPrice <= 0 {
return false
}
return true
}

func findDenom(feeParam types.DexFeeParams, feeCoins sdk.Coins) *types.DexFeeParams {
for _, denom := range feeParam.AcceptedDenomsMinPrices {
func findDenom(feeParams types.DexFeeParams, feeCoins sdk.Coins) *types.DexFeeParams {
for _, denom := range feeParams.AcceptedDenomsMinPrices {
if ok, _ := feeCoins.Find(denom.Denom); ok {
// fees should be sorted(biggest to smallest), so on the first match, we conclude that this is the current dex's fee param
// We need this check since denoms for the same token but from different dexes are different (because the channel differs)
//
// * Examples:
// Osmo from dex1 would have denom ibc/72...
// Osmo from dex2 would have denom ibc/2a...
return &feeParam
if validateFeeParam(feeParams.ProfitAddress, denom) {
return &feeParams
}
}
}
return nil
}

func denomMinPrice(denom string, feeParam types.DexFeeParams) (float64, error) {
var price float64
for _, acceptedDenoms := range feeParam.AcceptedDenomsMinPrices {
if acceptedDenoms.Denom == denom {
price = float64(acceptedDenoms.MinPrice)
for _, denomMinPrice := range feeParam.AcceptedDenomsMinPrices {
if denomMinPrice.Denom == denom {
price = float64(denomMinPrice.MinPrice)
return price, nil
}
}
Expand Down
1 change: 0 additions & 1 deletion x/tax/keeper/custom_tx_fee_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

var (
// The bytes below represent this string: {"prices":[{"amount":{"amount":"20000000","ticker":"OSMO"},"amount_quote":{"amount":"4248067","ticker":"USDC"}},{"amount":{"amount":"2000000000","ticker":"NLS"},"amount_quote":{"amount":"10452150388158391","ticker":"USDC"}}]}.
osmoDenom = "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9y"
osmoAxlUSDCDenom = "ibc/5DE4FCAF68AE40F81F738C857C0D95F7C1BC47B00FA1026E85C1DD92524D4A11"
feeAmount = int64(1_000_000_000)
Expand Down

0 comments on commit 7938496

Please sign in to comment.