Skip to content

Commit ea9badf

Browse files
authored
add support 2 denoms (#206)
* add support for 2 denom(1 native, 1 ibc) * add TODO * add test two ibc fee denoms
1 parent e06bbc3 commit ea9badf

File tree

2 files changed

+71
-40
lines changed

2 files changed

+71
-40
lines changed

x/feeabs/ante/ante_test.go

+47-20
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,53 @@ func TestMempoolDecorator(t *testing.T) {
9393
false,
9494
nil,
9595
},
96-
// TODO: Add support for multiple denom fees(--fees 50ibc,50native)
97-
// {
98-
// "half native fee, half ibc fee, should pass",
99-
// sdk.NewCoins(sdk.NewInt64Coin("native", 500*int64(gasLimit)), sdk.NewInt64Coin("ibcfee", 500*int64(gasLimit))),
100-
// sdk.NewDecCoinsFromCoins(sdk.NewCoins(sdk.NewInt64Coin("native", 1000))...),
101-
// func(suite *AnteTestSuite) {
102-
// err := suite.feeabsKeeper.SetHostZoneConfig(suite.ctx, types.HostChainFeeAbsConfig{
103-
// IbcDenom: "ibcfee",
104-
// OsmosisPoolTokenDenomIn: "osmosis",
105-
// PoolId: 1,
106-
// Status: types.HostChainFeeAbsStatus_UPDATED,
107-
// MinSwapAmount: 0,
108-
// })
109-
// require.NoError(t, err)
110-
// suite.feeabsKeeper.SetTwapRate(suite.ctx, "ibcfee", math.LegacyNewDec(1))
111-
// suite.stakingKeeper.EXPECT().BondDenom(gomock.Any()).Return("native").MinTimes(1)
112-
// },
113-
// false,
114-
// nil,
115-
// },
96+
{
97+
"half native fee, half ibc fee, should pass",
98+
sdk.NewCoins(sdk.NewInt64Coin("native", 500*int64(gasLimit)), sdk.NewInt64Coin("ibcfee", 500*int64(gasLimit))),
99+
sdk.NewDecCoinsFromCoins(sdk.NewCoins(sdk.NewInt64Coin("native", 1000))...),
100+
func(suite *AnteTestSuite) {
101+
err := suite.feeabsKeeper.SetHostZoneConfig(suite.ctx, types.HostChainFeeAbsConfig{
102+
IbcDenom: "ibcfee",
103+
OsmosisPoolTokenDenomIn: "osmosis",
104+
PoolId: 1,
105+
Status: types.HostChainFeeAbsStatus_UPDATED,
106+
// MinSwapAmount: 0,
107+
})
108+
require.NoError(t, err)
109+
suite.feeabsKeeper.SetTwapRate(suite.ctx, "ibcfee", math.LegacyNewDec(1))
110+
suite.stakingKeeper.EXPECT().BondDenom(gomock.Any()).Return("native", nil).MinTimes(1)
111+
},
112+
false,
113+
nil,
114+
},
115+
{
116+
"3/4 ibc fee, 1/4 another ibc fee, should pass",
117+
sdk.NewCoins(sdk.NewInt64Coin("ibcfee", 750*int64(gasLimit)), sdk.NewInt64Coin("ibcfee2", 250*int64(gasLimit))),
118+
sdk.NewDecCoinsFromCoins(sdk.NewCoins(sdk.NewInt64Coin("native", 1000))...),
119+
func(suite *AnteTestSuite) {
120+
err := suite.feeabsKeeper.SetHostZoneConfig(suite.ctx, types.HostChainFeeAbsConfig{
121+
IbcDenom: "ibcfee",
122+
OsmosisPoolTokenDenomIn: "osmosis",
123+
PoolId: 1,
124+
Status: types.HostChainFeeAbsStatus_UPDATED,
125+
// MinSwapAmount: 0,
126+
})
127+
require.NoError(t, err)
128+
err = suite.feeabsKeeper.SetHostZoneConfig(suite.ctx, types.HostChainFeeAbsConfig{
129+
IbcDenom: "ibcfee2",
130+
OsmosisPoolTokenDenomIn: "osmosis",
131+
PoolId: 2,
132+
Status: types.HostChainFeeAbsStatus_UPDATED,
133+
// MinSwapAmount: 0,
134+
})
135+
require.NoError(t, err)
136+
suite.feeabsKeeper.SetTwapRate(suite.ctx, "ibcfee", math.LegacyNewDec(1))
137+
suite.feeabsKeeper.SetTwapRate(suite.ctx, "ibcfee2", math.LegacyNewDec(1))
138+
suite.stakingKeeper.EXPECT().BondDenom(gomock.Any()).Return("native", nil).MinTimes(1)
139+
},
140+
false,
141+
nil,
142+
},
116143
}
117144
for _, tc := range testCases {
118145
t.Run(tc.name, func(t *testing.T) {

x/feeabs/ante/decorate.go

+24-20
Original file line numberDiff line numberDiff line change
@@ -271,28 +271,32 @@ func (famfd FeeAbstrationMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk
271271
// Check if feeDenom is defined in feeabs
272272
// If so, replace the amount of feeDenom in feeCoins with the
273273
// corresponding amount of native denom that allow to pay fee
274-
// TODO: Support more fee token in feeRequired for fee-abstraction
275-
if feeCoinsNonZeroDenom.Len() == 1 {
276-
feeDenom := feeCoinsNonZeroDenom.GetDenomByIndex(0)
277-
hostChainConfig, found := famfd.feeabsKeeper.GetHostZoneConfig(ctx, feeDenom)
278-
if found {
279-
if hostChainConfig.Status == feeabstypes.HostChainFeeAbsStatus_FROZEN {
280-
return ctx, sdkerrors.Wrapf(feeabstypes.ErrHostZoneFrozen, "cannot deduct fee as host zone is frozen")
274+
// Support more fee tokens in feeRequired for fee-abstraction
275+
if feeCoinsNonZeroDenom.Len() > 0 {
276+
nativeCoinsFees := sdk.NewCoins()
277+
for _, feeCoin := range feeCoinsNonZeroDenom {
278+
feeDenom := feeCoin.Denom
279+
hostChainConfig, found := famfd.feeabsKeeper.GetHostZoneConfig(ctx, feeDenom)
280+
if found {
281+
if hostChainConfig.Status == feeabstypes.HostChainFeeAbsStatus_FROZEN {
282+
return ctx, sdkerrors.Wrapf(feeabstypes.ErrHostZoneFrozen, "cannot deduct fee as host zone is frozen")
283+
}
284+
285+
// if hostChainConfig.Status == feeabstypes.HostChainFeeAbsStatus_OUTDATED {
286+
// return ctx, sdkerrors.Wrapf(feeabstypes.ErrHostZoneOutdated, "cannot deduct fee as host zone is outdated")
287+
// }
288+
289+
nativeCoinFee, err := famfd.feeabsKeeper.CalculateNativeFromIBCCoins(ctx, sdk.NewCoins(feeCoin), hostChainConfig)
290+
if err != nil {
291+
return ctx, sdkerrors.Wrapf(errorstypes.ErrInsufficientFee, "unable to calculate native fee from ibc fee: %s", err)
292+
}
293+
nativeCoinsFees = nativeCoinsFees.Add(nativeCoinFee...)
294+
} else {
295+
nativeCoinsFees = nativeCoinsFees.Add(feeCoin)
281296
}
282-
283-
// if hostChainConfig.Status == feeabstypes.HostChainFeeAbsStatus_OUTDATED {
284-
// return ctx, sdkerrors.Wrapf(feeabstypes.ErrHostZoneOutdated, "cannot deduct fee as host zone is outdated")
285-
// }
286-
287-
nativeCoinsFees, err := famfd.feeabsKeeper.CalculateNativeFromIBCCoins(ctx, feeCoinsNonZeroDenom, hostChainConfig)
288-
if err != nil {
289-
return ctx, sdkerrors.Wrapf(errorstypes.ErrInsufficientFee, "unable to calculate native fees from ibc fees: %s", err)
290-
}
291-
fmt.Println("nativeCoinsFees", nativeCoinsFees)
292-
feeCoinsNonZeroDenom = nativeCoinsFees
293297
}
294-
} else if feeCoinsNonZeroDenom.Len() > 1 {
295-
return ctx, sdkerrors.Wrapf(errorstypes.ErrNotSupported, "should have only one fee denom in feeCoinsNonZeroDenom, got %d", feeCoinsNonZeroDenom.Len())
298+
fmt.Println("nativeCoinsFees", nativeCoinsFees)
299+
feeCoinsNonZeroDenom = nativeCoinsFees
296300
}
297301

298302
// After replace the feeCoinsNonZeroDenom, feeCoinsNonZeroDenom must be in denom subset of nonZeroCoinFeesReq

0 commit comments

Comments
 (0)