Commit a79ea870 authored by mattverse's avatar mattverse
Browse files

WIP

parent d52aa162
Showing with 26 additions and 31 deletions
+26 -31
......@@ -48,13 +48,13 @@ func (s *KeeperTestHelper) PrepareBalancerPool() uint64 {
ExitFee: sdk.NewDec(0),
})
spotPrice, err := s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "foo", "bar")
spotPrice, err := s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "bar", "foo")
s.NoError(err)
s.Equal(sdk.NewDec(2).String(), spotPrice.String())
spotPrice, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "bar", "baz")
spotPrice, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "baz", "bar")
s.NoError(err)
s.Equal(sdk.NewDecWithPrec(15, 1).String(), spotPrice.String())
spotPrice, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "baz", "foo")
spotPrice, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "foo", "baz")
s.NoError(err)
oneThird := sdk.NewDec(1).Quo(sdk.NewDec(3))
sp := oneThird.MulInt(gammtypes.SpotPriceSigFigs).RoundInt().ToDec().QuoInt(gammtypes.SpotPriceSigFigs)
......
......@@ -5,7 +5,7 @@ go 1.18
require (
github.com/CosmWasm/wasmd v0.28.0-osmo-v12
github.com/cosmos/cosmos-proto v1.0.0-alpha7
github.com/cosmos/cosmos-sdk v0.46.1
github.com/cosmos/cosmos-sdk v0.46.2
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/iavl v0.19.1
github.com/cosmos/ibc-go/v3 v3.3.0
......
......@@ -140,6 +140,7 @@ func TestQuerySpotPrice(t *testing.T) {
queryCustom(t, ctx, osmosis, reflect, query, &resp)
price, err := strconv.ParseFloat(resp.Price, 64)
fmt.Println(price)
require.NoError(t, err)
uosmo, err := poolFunds[0].Amount.ToDec().Float64()
......
......@@ -256,8 +256,8 @@ func (suite *KeeperTestSuite) TestQueryBalancerPoolSpotPrice() {
name: "valid request for foo/bar",
req: &types.QuerySpotPriceRequest{
PoolId: poolID,
BaseAssetDenom: "foo",
QuoteAssetDenom: "bar",
BaseAssetDenom: "bar",
QuoteAssetDenom: "foo",
},
result: sdk.NewDec(2).String(),
},
......@@ -265,8 +265,8 @@ func (suite *KeeperTestSuite) TestQueryBalancerPoolSpotPrice() {
name: "valid request for bar/baz",
req: &types.QuerySpotPriceRequest{
PoolId: poolID,
BaseAssetDenom: "bar",
QuoteAssetDenom: "baz",
BaseAssetDenom: "baz",
QuoteAssetDenom: "bar",
},
result: sdk.NewDecWithPrec(15, 1).String(),
},
......@@ -274,8 +274,8 @@ func (suite *KeeperTestSuite) TestQueryBalancerPoolSpotPrice() {
name: "valid request for baz/foo",
req: &types.QuerySpotPriceRequest{
PoolId: poolID,
BaseAssetDenom: "baz",
QuoteAssetDenom: "foo",
BaseAssetDenom: "foo",
QuoteAssetDenom: "baz",
},
result: sdk.MustNewDecFromStr("0.333333330000000000").String(),
},
......
......@@ -4,6 +4,7 @@ import (
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v12/x/gamm/types"
......@@ -91,7 +92,7 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleMultihopSwapExactAmountIn()
pool, err := keeper.GetPoolAndPoke(suite.Ctx, route.PoolId)
suite.NoError(err, "test: %v", test.name)
sp, err := pool.SpotPrice(suite.Ctx, tokenInDenom, route.TokenOutDenom)
sp, err := pool.SpotPrice(suite.Ctx, route.TokenOutDenom, tokenInDenom)
suite.NoError(err, "test: %v", test.name)
dec = dec.Mul(sp)
}
......
......@@ -202,7 +202,7 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountOut() {
ctx := suite.Ctx
if test.expectPass {
spotPriceBefore, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenInDenom, test.param.tokenOut.Denom)
spotPriceBefore, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenOut.Denom, test.param.tokenInDenom)
suite.NoError(err, "test: %v", test.name)
prevGasConsumed := suite.Ctx.GasMeter().GasConsumed()
......@@ -217,7 +217,7 @@ func (suite *KeeperTestSuite) TestBalancerPoolSimpleSwapExactAmountOut() {
suite.AssertEventEmitted(ctx, types.TypeEvtTokenSwapped, 1)
spotPriceAfter, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenInDenom, test.param.tokenOut.Denom)
spotPriceAfter, err := keeper.CalculateSpotPrice(ctx, poolId, test.param.tokenOut.Denom, test.param.tokenInDenom)
suite.NoError(err, "test: %v", test.name)
// Ratio of the token out should be between the before spot price and after spot price.
......
......@@ -626,8 +626,8 @@ func (p Pool) SpotPrice(ctx sdk.Context, baseAsset, quoteAsset string) (spotPric
// spot_price = (Base_supply / Weight_base) / (Quote_supply / Weight_quote)
// spot_price = (weight_quote / weight_base) * (base_supply / quote_supply)
invWeightRatio := quote.Weight.ToDec().Quo(base.Weight.ToDec())
supplyRatio := base.Token.Amount.ToDec().Quo(quote.Token.Amount.ToDec())
invWeightRatio := base.Weight.ToDec().Quo(quote.Weight.ToDec())
supplyRatio := quote.Token.Amount.ToDec().Quo(base.Token.Amount.ToDec())
spotPrice = supplyRatio.Mul(invWeightRatio)
return spotPrice, err
......
......@@ -644,33 +644,33 @@ func (suite *KeeperTestSuite) TestBalancerSpotPrice() {
baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 100),
quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 200),
expectError: false,
expectedOutput: sdk.MustNewDecFromStr("0.500000000000000000"),
expectedOutput: sdk.MustNewDecFromStr("2.000000000000000000"),
},
{
name: "2:1 ratio",
baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 200),
quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 100),
expectError: false,
expectedOutput: sdk.MustNewDecFromStr("2.000000000000000000"),
expectedOutput: sdk.MustNewDecFromStr("0.500000000000000000"),
},
{
name: "rounding after sigfig ratio",
baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 220),
quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 115),
baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 115),
quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 220),
expectError: false,
expectedOutput: sdk.MustNewDecFromStr("1.913043480000000000"), // ans is 1.913043478260869565, rounded is 1.91304348
},
{
name: "check number of sig figs",
baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 100),
quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 300),
baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 300),
quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 100),
expectError: false,
expectedOutput: sdk.MustNewDecFromStr("0.333333330000000000"),
},
{
name: "check number of sig figs high sizes",
baseDenomPoolInput: sdk.NewInt64Coin(baseDenom, 343569192534),
quoteDenomPoolInput: sdk.NewCoin(quoteDenom, sdk.MustNewDecFromStr("186633424395479094888742").TruncateInt()),
baseDenomPoolInput: sdk.NewCoin(baseDenom, sdk.MustNewDecFromStr("186633424395479094888742").TruncateInt()),
quoteDenomPoolInput: sdk.NewInt64Coin(quoteDenom, 343569192534),
expectError: false,
expectedOutput: sdk.MustNewDecFromStr("0.000000000001840877"),
},
......
......@@ -263,7 +263,6 @@ func (s *IntegrationTestSuite) TestNewBeginUnlockPeriodLockCmd() {
false, &sdk.TxResponse{}, 0,
},
}
fmt.Println(testCases[0].args)
for _, tc := range testCases {
tc := tc
......
......@@ -37,7 +37,6 @@ func (suite *KeeperTestSuite) measureAvgAndMaxLockGas(
runningTotal += lockGas
if lockGas > maxGas {
maxGas = lockGas
// fmt.Println(suite.Ctx.GasMeter().String())
}
}
avg = runningTotal / uint64(numIterations)
......
package gov_test
import (
"fmt"
"github.com/tendermint/tendermint/crypto/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
......@@ -147,7 +145,6 @@ func (suite *KeeperTestSuite) TestHandleSetSuperfluidAssetsProposal() {
// check assets
resp, err = suite.querier.AllAssets(sdk.WrapSDKContext(suite.ctx), &types.AllAssetsRequest{})
fmt.Println(resp)
suite.Require().NoError(err)
suite.Require().Equal(resp.Assets, action.expectedAssets)
}
......
......@@ -2,7 +2,6 @@ package twap_test
import (
"fmt"
"math"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
......@@ -555,7 +554,6 @@ func (s *TestSuite) TestAccumulatorOverflow() {
var accumulatorVal sdk.Dec
fmt.Println(time.Duration(math.Pow(2, 128)))
if test.panics {
s.Require().Panics(func() {
// accumulator value is calculated via spot price * time delta
......
......@@ -8,7 +8,7 @@ type AmmInterface interface {
// CalculateSpotPrice returns the spot price of the quote asset in terms of the base asset,
// using the specified pool.
// E.g. if pool 1 traded 2 atom for 3 osmo, the quote asset was atom, and the base asset was osmo,
// this would return 1.5. (Meaning that 1 atom costs 1.5 osmo)
// this would return 0.66667. (Meaning that 1 osmo costs 0.666667 atom)
CalculateSpotPrice(
ctx sdk.Context,
poolID uint64,
......
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