Unverified Commit 5debecd3 authored by Hieu Vu's avatar Hieu Vu Committed by GitHub
Browse files

Revert fixed gas cost for v12 (#2808)

* remove fix gas constant & related test

* format
parent 8dfd9e27
Showing with 1 addition and 12 deletions
+1 -12
......@@ -97,13 +97,9 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountIn() {
spotPriceBefore, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenIn.Denom, test.param.tokenOutDenom)
suite.NoError(err, "test: %v", test.name)
prevGasConsumed := suite.Ctx.GasMeter().GasConsumed()
tokenOutAmount, err := keeper.SwapExactAmountIn(ctx, suite.TestAccs[0], poolId, test.param.tokenIn, test.param.tokenOutDenom, test.param.tokenOutMinAmount)
suite.NoError(err, "test: %v", test.name)
suite.True(tokenOutAmount.Equal(test.param.expectedTokenOut), "test: %v", test.name)
gasConsumedForSwap := suite.Ctx.GasMeter().GasConsumed() - prevGasConsumed
// We consume `types.GasFeeForSwap` directly, so the extra I/O operation mean we end up consuming more.
suite.Assert().Greater(gasConsumedForSwap, uint64(types.BalancerGasFeeForSwap))
suite.AssertEventEmitted(ctx, types.TypeEvtTokenSwapped, 1)
......@@ -205,15 +201,11 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountOut() {
spotPriceBefore, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenInDenom, test.param.tokenOut.Denom)
suite.NoError(err, "test: %v", test.name)
prevGasConsumed := suite.Ctx.GasMeter().GasConsumed()
tokenInAmount, err := keeper.SwapExactAmountOut(ctx, suite.TestAccs[0], poolId, test.param.tokenInDenom, test.param.tokenInMaxAmount, test.param.tokenOut)
suite.NoError(err, "test: %v", test.name)
suite.True(tokenInAmount.Equal(test.param.expectedTokenInAmount),
"test: %v\n expect_eq actual: %s, expected: %s",
test.name, tokenInAmount, test.param.expectedTokenInAmount)
gasConsumedForSwap := suite.Ctx.GasMeter().GasConsumed() - prevGasConsumed
// We consume `types.GasFeeForSwap` directly, so the extra I/O operation mean we end up consuming more.
suite.Assert().Greater(gasConsumedForSwap, uint64(types.BalancerGasFeeForSwap))
suite.AssertEventEmitted(ctx, types.TypeEvtTokenSwapped, 1)
......
......@@ -583,8 +583,6 @@ func (p *Pool) SwapInAmtGivenOut(
// ApplySwap.
func (p *Pool) applySwap(ctx sdk.Context, tokensIn sdk.Coins, tokensOut sdk.Coins) error {
// Fixed gas consumption per swap to prevent spam
ctx.GasMeter().ConsumeGas(types.BalancerGasFeeForSwap, "balancer swap computation")
// Also ensures that len(tokensIn) = 1 = len(tokensOut)
inPoolAsset, outPoolAsset, err := p.parsePoolAssetsCoins(tokensIn, tokensOut)
if err != nil {
......
......@@ -11,8 +11,7 @@ const (
OneShareExponent = 18
// Raise 10 to the power of SigFigsExponent to determine number of significant figures.
// i.e. SigFigExponent = 8 is 10^8 which is 100000000. This gives 8 significant figures.
SigFigsExponent = 8
BalancerGasFeeForSwap = 10_000
SigFigsExponent = 8
)
var (
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment