Skip to content

Commit

Permalink
DEV-2046/AMM & DEV-2060/ORACLE (#859)
Browse files Browse the repository at this point in the history
* Pools should not be created with more than two assets

* oracle endpoints were fixed
  • Loading branch information
fenriz07 authored Oct 15, 2024
1 parent 7ef0816 commit 29001f5
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 67 deletions.
4 changes: 2 additions & 2 deletions proto/elys/oracle/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ service Query {
}
// Queries a Price by asset.
rpc Price(QueryGetPriceRequest) returns (QueryGetPriceResponse) {
option (google.api.http).get = "/elys-network/elys/oracle/price";
option (google.api.http).get = "/elys-network/elys/oracle/price/{asset}";
}
// Queries a list of Price items.
rpc PriceAll(QueryAllPriceRequest) returns (QueryAllPriceResponse) {
option (google.api.http).get = "/elys-network/elys/oracle/price";
option (google.api.http).get = "/elys-network/elys/oracle/prices";
}
// Queries a PriceFeeder by feeder.
rpc PriceFeeder(QueryGetPriceFeederRequest) returns (QueryGetPriceFeederResponse) {
Expand Down
1 change: 1 addition & 0 deletions x/amm/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
ErrExitFeeShouldNotExceedTwoPercent = errors.Register(ModuleName, 110, "exit fee should not exceed 2%")
ErrFeeShouldNotBeNegative = errors.Register(ModuleName, 111, "fee should not be negative")
ErrInvalidShareAmountOut = errors.Register(ModuleName, 112, "invalid share amount out")
ErrPoolAssetsMustBeTwo = errors.Register(ModuleName, 113, "pool assets must be exactly two")
)

const (
Expand Down
4 changes: 4 additions & 0 deletions x/amm/types/message_create_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (msg *MsgCreatePool) ValidateBasic() error {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err)
}

if len(msg.PoolAssets) != 2 {
return ErrPoolAssetsMustBeTwo
}

if msg.PoolParams == nil {
return ErrPoolParamsShouldNotBeNil
}
Expand Down
37 changes: 36 additions & 1 deletion x/amm/types/message_create_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,32 @@ func TestMsgCreatePool_ValidateBasic(t *testing.T) {
},
},
err: sdkerrors.ErrInvalidAddress,
}, {
},
{
name: "pool assets must be exactly two",
msg: types.MsgCreatePool{
Sender: sample.AccAddress(),
PoolParams: &types.PoolParams{
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
UseOracle: false,
WeightBreakingFeeMultiplier: sdk.ZeroDec(),
WeightBreakingFeeExponent: sdk.NewDecWithPrec(25, 1), // 2.5
ExternalLiquidityRatio: sdk.NewDec(1),
WeightRecoveryFeePortion: sdk.NewDecWithPrec(10, 2), // 10%
ThresholdWeightDifference: sdk.ZeroDec(),
FeeDenom: ptypes.BaseCurrency,
},
PoolAssets: []types.PoolAsset{
{
Token: sdk.NewCoin("uatom", sdk.NewInt(10000000)),
Weight: sdk.NewInt(10),
},
},
},
err: types.ErrPoolAssetsMustBeTwo,
},
{
name: "valid address",
msg: types.MsgCreatePool{
Sender: sample.AccAddress(),
Expand All @@ -49,6 +74,16 @@ func TestMsgCreatePool_ValidateBasic(t *testing.T) {
ThresholdWeightDifference: sdk.ZeroDec(),
FeeDenom: ptypes.BaseCurrency,
},
PoolAssets: []types.PoolAsset{
{
Token: sdk.NewCoin("uusdc", sdk.NewInt(10000000)),
Weight: sdk.NewInt(10),
},
{
Token: sdk.NewCoin("uatom", sdk.NewInt(10000000)),
Weight: sdk.NewInt(10),
},
},
},
},
}
Expand Down
122 changes: 61 additions & 61 deletions x/oracle/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 39 additions & 3 deletions x/oracle/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 29001f5

Please sign in to comment.