From 4349c0fd9b3f088588cf2ed53a1bdb0b520d1b35 Mon Sep 17 00:00:00 2001 From: Adarsh Kumar Date: Mon, 9 Dec 2024 16:56:30 +0530 Subject: [PATCH 1/4] add div by zero check (#1051) --- x/amm/types/pool_calc_join_pool_no_swap_shares.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/amm/types/pool_calc_join_pool_no_swap_shares.go b/x/amm/types/pool_calc_join_pool_no_swap_shares.go index 900113413..54690ed8c 100644 --- a/x/amm/types/pool_calc_join_pool_no_swap_shares.go +++ b/x/amm/types/pool_calc_join_pool_no_swap_shares.go @@ -31,6 +31,10 @@ func MaximalExactRatioJoin(p *Pool, tokensIn sdk.Coins) (numShares sdkmath.Int, // Note: QuoInt implements floor division, unlike Quo // This is because it calls the native golang routine big.Int.Quo // https://pkg.go.dev/math/big#Int.Quo + // Division by zero check + if poolLiquidity.AmountOfNoDenomValidation(coin.Denom).IsZero() { + return numShares, remCoins, errors.New("pool liquidity is zero for denom: " + coin.Denom) + } shareRatio := sdkmath.LegacyNewDecFromBigInt(coin.Amount.BigInt()).QuoInt(poolLiquidity.AmountOfNoDenomValidation(coin.Denom)) if shareRatio.LT(minShareRatio) { minShareRatio = shareRatio From 0dfa83f70945a55856d7f63bb7c304acf23f95e7 Mon Sep 17 00:00:00 2001 From: Adarsh Kumar Date: Mon, 9 Dec 2024 22:36:50 +0530 Subject: [PATCH 2/4] Increase coverage for Amm keeper and types package (#1052) * increasse coverage for amm keepers * swap by denom test for out route * add more amm tests * increase coverage for amm types package --- x/amm/keeper/calc_in_route_spot_price_test.go | 3 +- x/amm/keeper/estimate_price_test.go | 50 ++++ x/amm/keeper/fee_test.go | 21 +- x/amm/keeper/keeper_create_pool_test.go | 57 +++++ x/amm/keeper/keeper_exit_pool_test.go | 57 +++++ x/amm/keeper/keeper_join_pool_no_swap_test.go | 91 ++++++++ .../keeper_swap_exact_amount_in_test.go | 74 +++++- .../keeper_swap_exact_amount_out_test.go | 59 +++++ x/amm/keeper/msg_server_swap_by_denom_test.go | 165 +++++++++++++ x/amm/types/amm_price_test.go | 144 ++++++++++++ x/amm/types/calc_exit_pool_test.go | 218 ++++++++++++++++++ x/amm/types/message_create_pool_test.go | 100 +++++++- x/amm/types/message_exit_pool_test.go | 34 ++- ...e_feed_multiple_external_liquidity_test.go | 132 +++++++++++ x/amm/types/message_join_pool_test.go | 31 ++- x/amm/types/message_swap_by_denom_test.go | 40 +++- .../message_swap_exact_amount_in_test.go | 53 ++++- .../message_swap_exact_amount_out_test.go | 55 ++++- ...pool_calc_join_pool_no_swap_shares_test.go | 87 +++++++ 19 files changed, 1452 insertions(+), 19 deletions(-) create mode 100644 x/amm/keeper/keeper_create_pool_test.go create mode 100644 x/amm/keeper/keeper_exit_pool_test.go create mode 100644 x/amm/keeper/keeper_join_pool_no_swap_test.go create mode 100644 x/amm/types/amm_price_test.go create mode 100644 x/amm/types/calc_exit_pool_test.go create mode 100644 x/amm/types/message_feed_multiple_external_liquidity_test.go create mode 100644 x/amm/types/pool_calc_join_pool_no_swap_shares_test.go diff --git a/x/amm/keeper/calc_in_route_spot_price_test.go b/x/amm/keeper/calc_in_route_spot_price_test.go index 7a255d49f..0966ac816 100644 --- a/x/amm/keeper/calc_in_route_spot_price_test.go +++ b/x/amm/keeper/calc_in_route_spot_price_test.go @@ -88,9 +88,10 @@ func (suite *AmmKeeperTestSuite) TestCalcInRouteSpotPrice() { tokenIn := sdk.NewCoin(ptypes.Elys, sdkmath.NewInt(100)) routes := []*types.SwapAmountInRoute{{PoolId: 1, TokenOutDenom: ptypes.BaseCurrency}} - spotPrice, _, _, _, _, _, _, _, err := suite.app.AmmKeeper.CalcInRouteSpotPrice(suite.ctx, tokenIn, routes, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec()) + spotPrice, _, _, totalDiscountedSwapFee, _, _, _, _, err := suite.app.AmmKeeper.CalcInRouteSpotPrice(suite.ctx, tokenIn, routes, sdkmath.LegacyZeroDec(), sdkmath.LegacyMustNewDecFromStr("0.1")) suite.Require().NoError(err) suite.Require().Equal(spotPrice.String(), sdkmath.LegacyOneDec().String()) + suite.Require().Equal(sdkmath.LegacyMustNewDecFromStr("0.1"), totalDiscountedSwapFee) routes = []*types.SwapAmountInRoute{ {PoolId: 1, TokenOutDenom: ptypes.BaseCurrency}, diff --git a/x/amm/keeper/estimate_price_test.go b/x/amm/keeper/estimate_price_test.go index 5bc1d60d2..93df0ed3f 100644 --- a/x/amm/keeper/estimate_price_test.go +++ b/x/amm/keeper/estimate_price_test.go @@ -32,6 +32,56 @@ func (suite *AmmKeeperTestSuite) TestEstimatePrice() { suite.Require().Equal(math.LegacyMustNewDecFromStr("0.000001000000000000"), price) }, }, + { + "Asset Info Not found for tokenInDenom", + func() { + suite.ResetSuite() + suite.SetupCoinPrices() + }, + func() { + suite.app.OracleKeeper.RemoveAssetInfo(suite.ctx, ptypes.BaseCurrency) + price := suite.app.AmmKeeper.GetTokenPrice(suite.ctx, ptypes.BaseCurrency, ptypes.BaseCurrency) + suite.Require().Equal(math.LegacyMustNewDecFromStr("0.000000000000000000"), price) + }, + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + tc.prerequisiteFunction() + tc.postValidateFunction() + }) + } +} + +func (suite *AmmKeeperTestSuite) TestCalculateUSDValue() { + testCases := []struct { + name string + prerequisiteFunction func() + postValidateFunction func() + }{ + { + "Success: get token value at oracle price", + func() { + suite.ResetSuite() + suite.SetupCoinPrices() + }, + func() { + value := suite.app.AmmKeeper.CalculateUSDValue(suite.ctx, ptypes.ATOM, math.NewInt(1000)) + suite.Require().Equal(value, math.LegacyMustNewDecFromStr("0.001")) + }, + }, + { + "Calculate Usd value for asset not found in AssetProfile", + func() { + suite.ResetSuite() + suite.SetupCoinPrices() + }, + func() { + value := suite.app.AmmKeeper.CalculateUSDValue(suite.ctx, "dummy", math.NewInt(1000)) + suite.Require().Equal(value.String(), math.LegacyZeroDec().String()) + }, + }, } for _, tc := range testCases { diff --git a/x/amm/keeper/fee_test.go b/x/amm/keeper/fee_test.go index 7db8db0e9..b99ba9cdd 100644 --- a/x/amm/keeper/fee_test.go +++ b/x/amm/keeper/fee_test.go @@ -33,6 +33,7 @@ func (suite *AmmKeeperTestSuite) TestOnCollectFee() { poolInitBalance sdk.Coins expRevenueBalance sdk.Coins expPass bool + useOracle bool }{ { desc: "multiple fees collected", @@ -40,6 +41,7 @@ func (suite *AmmKeeperTestSuite) TestOnCollectFee() { poolInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, expRevenueBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 1999)}, expPass: true, + useOracle: false, }, { desc: "zero fees collected", @@ -47,6 +49,7 @@ func (suite *AmmKeeperTestSuite) TestOnCollectFee() { poolInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, expRevenueBalance: sdk.Coins{}, expPass: true, + useOracle: false, }, { desc: "base currency fee collected", @@ -54,6 +57,15 @@ func (suite *AmmKeeperTestSuite) TestOnCollectFee() { poolInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, expRevenueBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 1000)}, expPass: true, + useOracle: false, + }, + { + desc: "fee collected after weight recovery fee deduction", + fee: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 1000)}, + poolInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + expRevenueBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 900)}, + expPass: true, + useOracle: true, }, } { suite.Run(tc.desc, func() { @@ -87,7 +99,7 @@ func (suite *AmmKeeperTestSuite) TestOnCollectFee() { RebalanceTreasury: treasuryAddr.String(), PoolParams: types.PoolParams{ SwapFee: sdkmath.LegacyZeroDec(), - UseOracle: false, + UseOracle: tc.useOracle, FeeDenom: ptypes.BaseCurrency, }, TotalShares: sdk.NewCoin(types.GetPoolShareDenom(1), sdkmath.ZeroInt()), @@ -149,6 +161,13 @@ func (suite *AmmKeeperTestSuite) TestSwapFeesToRevenueToken() { expRevenueBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 1000)}, expPass: true, }, + { + desc: "token not available in pools for swap", + fee: sdk.Coins{sdk.NewInt64Coin("dummy", 1000)}, + poolInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + expRevenueBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.BaseCurrency, 1000)}, + expPass: false, + }, } { suite.Run(tc.desc, func() { suite.SetupTest() diff --git a/x/amm/keeper/keeper_create_pool_test.go b/x/amm/keeper/keeper_create_pool_test.go new file mode 100644 index 000000000..4921a7702 --- /dev/null +++ b/x/amm/keeper/keeper_create_pool_test.go @@ -0,0 +1,57 @@ +package keeper_test + +import ( + "github.com/elys-network/elys/x/amm/types" + ptypes "github.com/elys-network/elys/x/parameter/types" + "github.com/stretchr/testify/require" +) + +func (suite *AmmKeeperTestSuite) TestCreatePool() { + // Define test cases + testCases := []struct { + name string + setup func() *types.MsgCreatePool + expectedErrMsg string + }{ + { + "asset profile not found", + func() *types.MsgCreatePool { + addr := suite.AddAccounts(1, nil) + suite.app.AssetprofileKeeper.RemoveEntry(suite.ctx, ptypes.BaseCurrency) + return &types.MsgCreatePool{ + Sender: addr[0].String(), + PoolParams: types.PoolParams{}, + PoolAssets: []types.PoolAsset{}, + } + }, + "asset profile not found for denom", + }, + { + "Balance pool Create Error", + func() *types.MsgCreatePool { + suite.ResetSuite() + addr := suite.AddAccounts(1, nil) + return &types.MsgCreatePool{ + Sender: addr[0].String(), + PoolParams: types.PoolParams{}, + PoolAssets: []types.PoolAsset{}, + } + }, + "swap_fee is nil", + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + msg := tc.setup() + poolId, err := suite.app.AmmKeeper.CreatePool(suite.ctx, msg) + if tc.expectedErrMsg != "" { + require.Error(suite.T(), err) + require.Contains(suite.T(), err.Error(), tc.expectedErrMsg) + } else { + require.NoError(suite.T(), err) + require.NotZero(suite.T(), poolId) + } + }) + } +} diff --git a/x/amm/keeper/keeper_exit_pool_test.go b/x/amm/keeper/keeper_exit_pool_test.go new file mode 100644 index 000000000..71c1957a4 --- /dev/null +++ b/x/amm/keeper/keeper_exit_pool_test.go @@ -0,0 +1,57 @@ +package keeper_test + +import ( + "cosmossdk.io/math" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + ptypes "github.com/elys-network/elys/x/parameter/types" +) + +func (suite *AmmKeeperTestSuite) TestExitPool() { + testCases := []struct { + name string + setup func() (sdk.AccAddress, uint64, math.Int, sdk.Coins, string, bool) + expectedErrMsg string + }{ + { + "pool does not exist", + func() (sdk.AccAddress, uint64, math.Int, sdk.Coins, string, bool) { + addr := suite.AddAccounts(1, nil) + return addr[0], 1, math.NewInt(100), sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(100))), "uatom", false + }, + "invalid pool id", + }, + { + "exiting more shares than available", + func() (sdk.AccAddress, uint64, math.Int, sdk.Coins, string, bool) { + suite.SetupCoinPrices() + addr := suite.AddAccounts(1, nil) + amount := sdkmath.NewInt(100000000000) + pool := suite.CreateNewAmmPool(addr[0], true, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10)) + return addr[0], 1, pool.TotalShares.Amount.Add(sdkmath.NewInt(10)), sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(100))), "uatom", false + }, + "Trying to exit >= the number of shares contained in the pool", + }, + { + "exiting negative shares", + func() (sdk.AccAddress, uint64, math.Int, sdk.Coins, string, bool) { + addr := suite.AddAccounts(1, nil) + return addr[0], 1, sdkmath.NewInt(1).Neg(), sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(100))), "uatom", false + }, + "Trying to exit a negative amount of shares", + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + exiter, poolId, inShares, minTokensOut, tokenOutDenom, isLiq := tc.setup() + _, err := suite.app.AmmKeeper.ExitPool(suite.ctx, exiter, poolId, inShares, minTokensOut, tokenOutDenom, isLiq) + if tc.expectedErrMsg != "" { + suite.Require().Error(err) + suite.Require().Contains(err.Error(), tc.expectedErrMsg) + } else { + suite.Require().NoError(err) + } + }) + } +} diff --git a/x/amm/keeper/keeper_join_pool_no_swap_test.go b/x/amm/keeper/keeper_join_pool_no_swap_test.go new file mode 100644 index 000000000..b597a0da2 --- /dev/null +++ b/x/amm/keeper/keeper_join_pool_no_swap_test.go @@ -0,0 +1,91 @@ +package keeper_test + +import ( + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/parameter/types" +) + +func (suite *AmmKeeperTestSuite) TestJoinPoolNoSwap() { + // Define test cases + testCases := []struct { + name string + setup func() (sdk.AccAddress, uint64, sdkmath.Int, sdk.Coins) + expectedErrMsg string + }{ + { + "pool does not exist", + func() (sdk.AccAddress, uint64, sdkmath.Int, sdk.Coins) { + return sdk.AccAddress([]byte("sender")), 1, sdkmath.NewInt(100), sdk.Coins{} + }, + "invalid pool id", + }, + { + "successful join pool No oracle", + func() (sdk.AccAddress, uint64, sdkmath.Int, sdk.Coins) { + suite.SetupCoinPrices() + addr := suite.AddAccounts(1, nil) + amount := sdkmath.NewInt(100000000000) + pool := suite.CreateNewAmmPool(addr[0], false, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), types.ATOM, amount.MulRaw(10), amount.MulRaw(10)) + return addr[0], 1, pool.TotalShares.Amount, sdk.Coins{sdk.NewCoin(types.ATOM, amount.MulRaw(10)), sdk.NewCoin(types.BaseCurrency, amount.MulRaw(10))} + }, + "", + }, + { + "successful join pool with oracle", + func() (sdk.AccAddress, uint64, sdkmath.Int, sdk.Coins) { + suite.SetupCoinPrices() + addr := suite.AddAccounts(1, nil) + amount := sdkmath.NewInt(100000000000) + pool := suite.CreateNewAmmPool(addr[0], true, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), types.ATOM, amount.MulRaw(10), amount.MulRaw(10)) + return addr[0], 2, pool.TotalShares.Amount, sdk.Coins{sdk.NewCoin(types.ATOM, amount.MulRaw(10))} + }, + "", + }, + { + "Needed LpLiquidity is more than tokenInMaxs", + func() (sdk.AccAddress, uint64, sdkmath.Int, sdk.Coins) { + addr := suite.AddAccounts(1, nil) + amount := sdkmath.NewInt(100) + share, _ := sdkmath.NewIntFromString("20000000000000000000000000000000") + return addr[0], 1, share, sdk.Coins{sdk.NewCoin(types.ATOM, amount), sdk.NewCoin(types.BaseCurrency, amount)} + }, + "TokenInMaxs is less than the needed LP liquidity to this JoinPoolNoSwap", + }, + { + "tokenInMaxs does not contain Needed LpLiquidity coins", + func() (sdk.AccAddress, uint64, sdkmath.Int, sdk.Coins) { + addr := suite.AddAccounts(1, nil) + amount := sdkmath.NewInt(100) + share, _ := sdkmath.NewIntFromString("20000000000000000000000000000000") + return addr[0], 1, share, sdk.Coins{sdk.NewCoin("nocoin", amount), sdk.NewCoin(types.BaseCurrency, amount)} + }, + "TokenInMaxs does not include all the tokens that are part of the target pool", + }, + { + "tokenInMaxs does not contain Needed LpLiquidity coins", + func() (sdk.AccAddress, uint64, sdkmath.Int, sdk.Coins) { + addr := suite.AddAccounts(1, nil) + amount := sdkmath.NewInt(100) + share, _ := sdkmath.NewIntFromString("20000000000000000000000000000000") + return addr[0], 1, share, sdk.Coins{sdk.NewCoin("nocoin", amount), sdk.NewCoin(types.ATOM, amount), sdk.NewCoin(types.BaseCurrency, amount)} + }, + "TokenInMaxs includes tokens that are not part of the target pool", + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + sender, poolId, shareOutAmount, tokenInMaxs := tc.setup() + tokenIn, sharesOut, err := suite.app.AmmKeeper.JoinPoolNoSwap(suite.ctx, sender, poolId, shareOutAmount, tokenInMaxs) + if tc.expectedErrMsg != "" { + suite.Require().Error(err) + suite.Require().Contains(err.Error(), tc.expectedErrMsg) + } else { + suite.Require().NoError(err) + suite.Require().True(tokenIn.IsAllLTE(tokenInMaxs)) + suite.Require().True(sharesOut.LTE(shareOutAmount)) + } + }) + } +} diff --git a/x/amm/keeper/keeper_swap_exact_amount_in_test.go b/x/amm/keeper/keeper_swap_exact_amount_in_test.go index 52cbf25a0..cadfad8cd 100644 --- a/x/amm/keeper/keeper_swap_exact_amount_in_test.go +++ b/x/amm/keeper/keeper_swap_exact_amount_in_test.go @@ -28,15 +28,16 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() { expPoolBalance sdk.Coins expTreasuryBalance sdk.Coins expPass bool + errMsg string }{ { - desc: "pool does not enough balance for out", + desc: "tokenIn is same as tokenOut", senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, poolInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 100)}, treasuryInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, swapFeeIn: sdkmath.LegacyZeroDec(), swapFeeOut: sdkmath.LegacyZeroDec(), - tokenIn: sdk.NewInt64Coin("uusda", 10000), + tokenIn: sdk.NewInt64Coin("uusdc", 10000), tokenOutMin: sdkmath.ZeroInt(), tokenOut: sdk.NewInt64Coin(ptypes.BaseCurrency, 10000), weightBalanceBonus: sdkmath.LegacyZeroDec(), @@ -47,6 +48,67 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() { expPoolBalance: sdk.Coins{}, expTreasuryBalance: sdk.Coins{}, expPass: false, + errMsg: "cannot trade the same denomination in and out", + }, + { + desc: "tokenOut is 0", + senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + poolInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 100)}, + treasuryInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + swapFeeIn: sdkmath.LegacyZeroDec(), + swapFeeOut: sdkmath.LegacyZeroDec(), + tokenIn: sdk.NewInt64Coin("uusda", 0), + tokenOutMin: sdkmath.ZeroInt(), + tokenOut: sdk.NewInt64Coin(ptypes.BaseCurrency, 10000), + weightBalanceBonus: sdkmath.LegacyZeroDec(), + isOraclePool: false, + useNewRecipient: false, + expSenderBalance: sdk.Coins{}, + expRecipientBalance: sdk.Coins{}, + expPoolBalance: sdk.Coins{}, + expTreasuryBalance: sdk.Coins{}, + expPass: false, + errMsg: "token out amount is zero", + }, + { + desc: "tokenOut is less than tokenOut minimum amount", + senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + poolInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + treasuryInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + swapFeeIn: sdkmath.LegacyNewDecWithPrec(1, 2), // 1% + swapFeeOut: sdkmath.LegacyZeroDec(), + tokenIn: sdk.NewInt64Coin("uusda", 10000), + tokenOutMin: sdkmath.NewInt(10000000), + tokenOut: sdk.NewInt64Coin(ptypes.BaseCurrency, 9802), + weightBalanceBonus: sdkmath.LegacyZeroDec(), + isOraclePool: false, + useNewRecipient: false, + expSenderBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 990000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1009802)}, + expRecipientBalance: sdk.Coins{}, + expPoolBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1010000), sdk.NewInt64Coin(ptypes.BaseCurrency, 990100)}, + expTreasuryBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + expPass: false, + errMsg: "token is less than the minimum amount", + }, + { + desc: "pool does not enough balance for out", + senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + poolInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 100)}, + treasuryInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + swapFeeIn: sdkmath.LegacyZeroDec(), + swapFeeOut: sdkmath.LegacyZeroDec(), + tokenIn: sdk.NewInt64Coin("uusda", 1000), + tokenOutMin: sdkmath.ZeroInt(), + tokenOut: sdk.NewInt64Coin(ptypes.BaseCurrency, 1000), + weightBalanceBonus: sdkmath.LegacyZeroDec(), + isOraclePool: false, + useNewRecipient: false, + expSenderBalance: sdk.Coins{}, + expRecipientBalance: sdk.Coins{}, + expPoolBalance: sdk.Coins{}, + expTreasuryBalance: sdk.Coins{}, + expPass: false, + errMsg: "token out amount is zero", }, { desc: "sender does not have enough balance for in", @@ -66,6 +128,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() { expPoolBalance: sdk.Coins{}, expTreasuryBalance: sdk.Coins{}, expPass: false, + errMsg: "insufficient funds", }, { desc: "successful execution with positive swap fee", @@ -85,6 +148,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() { expPoolBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1010000), sdk.NewInt64Coin(ptypes.BaseCurrency, 990100)}, expTreasuryBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, expPass: true, + errMsg: "", }, { desc: "successful execution with zero swap fee", @@ -104,6 +168,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() { expPoolBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1010000), sdk.NewInt64Coin(ptypes.BaseCurrency, 990100)}, expTreasuryBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, expPass: true, + errMsg: "", }, { desc: "successful execution with positive slippage on oracle pool", @@ -123,6 +188,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() { expPoolBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1009997), sdk.NewInt64Coin(ptypes.BaseCurrency, 990056)}, expTreasuryBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000003), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, expPass: true, + errMsg: "", }, { desc: "successful weight bonus & huge amount rebalance treasury", @@ -142,6 +208,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() { expPoolBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1010000), sdk.NewInt64Coin(ptypes.BaseCurrency, 990100)}, expTreasuryBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, expPass: true, + errMsg: "", }, { desc: "successful weight bonus & lack of rebalance treasury", @@ -161,6 +228,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() { expPoolBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1010000), sdk.NewInt64Coin(ptypes.BaseCurrency, 990100)}, expTreasuryBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 100)}, expPass: true, + errMsg: "", }, { desc: "new recipient address", @@ -180,6 +248,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() { expPoolBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1010000), sdk.NewInt64Coin(ptypes.BaseCurrency, 990100)}, expTreasuryBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 100)}, expPass: true, + errMsg: "", }, } { suite.Run(tc.desc, func() { @@ -246,6 +315,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() { tokenOut, err := suite.app.AmmKeeper.InternalSwapExactAmountIn(suite.ctx, sender, recipient, pool, tc.tokenIn, tc.tokenOut.Denom, tc.tokenOutMin, tc.swapFeeIn) if !tc.expPass { suite.Require().Error(err) + suite.Require().Contains(err.Error(), tc.errMsg) } else { suite.Require().NoError(err) suite.Require().Equal(tokenOut.String(), tc.tokenOut.Amount.String()) diff --git a/x/amm/keeper/keeper_swap_exact_amount_out_test.go b/x/amm/keeper/keeper_swap_exact_amount_out_test.go index a3fb49378..e71fcf186 100644 --- a/x/amm/keeper/keeper_swap_exact_amount_out_test.go +++ b/x/amm/keeper/keeper_swap_exact_amount_out_test.go @@ -27,7 +27,65 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountOut() { expPoolBalance sdk.Coins expTreasuryBalance sdk.Coins expPass bool + errMsg string }{ + { + desc: "tokenIn is same as tokenOut", + senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + poolInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 100)}, + treasuryInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + swapFeeOut: sdkmath.LegacyZeroDec(), + tokenIn: sdk.NewInt64Coin("uusdc", 10000), + tokenInMax: sdkmath.NewInt(10000000), + tokenOut: sdk.NewInt64Coin(ptypes.BaseCurrency, 10000), + weightBalanceBonus: sdkmath.LegacyZeroDec(), + isOraclePool: false, + useNewRecipient: false, + expSenderBalance: sdk.Coins{}, + expRecipientBalance: sdk.Coins{}, + expPoolBalance: sdk.Coins{}, + expTreasuryBalance: sdk.Coins{}, + expPass: false, + errMsg: "cannot trade the same denomination in and out", + }, + { + desc: "tokenIn is 0 corrosponsing to tokenOut", + senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + poolInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + treasuryInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + swapFeeOut: sdkmath.LegacyZeroDec(), + tokenIn: sdk.NewInt64Coin("uusda", 1000), + tokenInMax: sdkmath.NewInt(10000000), + tokenOut: sdk.NewInt64Coin(ptypes.BaseCurrency, 0), + weightBalanceBonus: sdkmath.LegacyZeroDec(), + isOraclePool: true, + useNewRecipient: false, + expSenderBalance: sdk.Coins{}, + expRecipientBalance: sdk.Coins{}, + expPoolBalance: sdk.Coins{}, + expTreasuryBalance: sdk.Coins{}, + expPass: false, + errMsg: "amount too low", + }, + { + desc: "MaxTokenIn is less than required tokenIn amount", + senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + poolInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + treasuryInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + swapFeeOut: sdkmath.LegacyZeroDec(), + tokenIn: sdk.NewInt64Coin("uusda", 10000), + tokenInMax: sdkmath.NewInt(10), + tokenOut: sdk.NewInt64Coin(ptypes.BaseCurrency, 9802), + weightBalanceBonus: sdkmath.LegacyZeroDec(), + isOraclePool: false, + useNewRecipient: false, + expSenderBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 990000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1009802)}, + expRecipientBalance: sdk.Coins{}, + expPoolBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1010000), sdk.NewInt64Coin(ptypes.BaseCurrency, 990100)}, + expTreasuryBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + expPass: false, + errMsg: "calculated amount is larger than max amount", + }, { desc: "pool does not enough balance for out", senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uusda", 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, @@ -237,6 +295,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountOut() { tokenInAmount, err := suite.app.AmmKeeper.InternalSwapExactAmountOut(suite.ctx, sender, recipient, pool, tc.tokenIn.Denom, tc.tokenInMax, tc.tokenOut, tc.swapFeeOut) if !tc.expPass { suite.Require().Error(err) + suite.Require().Contains(err.Error(), tc.errMsg) } else { suite.Require().NoError(err) suite.Require().Equal(tokenInAmount.String(), tc.tokenIn.Amount.String()) diff --git a/x/amm/keeper/msg_server_swap_by_denom_test.go b/x/amm/keeper/msg_server_swap_by_denom_test.go index d8fe7b4cd..2c6c2812e 100644 --- a/x/amm/keeper/msg_server_swap_by_denom_test.go +++ b/x/amm/keeper/msg_server_swap_by_denom_test.go @@ -21,6 +21,7 @@ func (suite *AmmKeeperTestSuite) TestMsgServerSwapByDenom() { tokenOut sdk.Coin expSenderBalance sdk.Coins expPass bool + errMsg string }{ { desc: "successful execution with positive swap fee", @@ -180,3 +181,167 @@ func (suite *AmmKeeperTestSuite) TestMsgServerSwapByDenom() { }) } } + +func (suite *AmmKeeperTestSuite) TestMsgServerSwapByDenomWithOutRoute() { + for _, tc := range []struct { + desc string + senderInitBalance sdk.Coins + swapFee sdkmath.LegacyDec + tokenOut sdk.Coin + tokenOutMax sdkmath.Int + tokenDenomIn string + expTokenIn sdk.Coin + expSenderBalance sdk.Coins + expPass bool + errMsg string + }{ + { + desc: "successful execution with positive swap fee", + senderInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + swapFee: sdkmath.LegacyNewDecWithPrec(1, 2), // 1% + tokenOut: sdk.NewInt64Coin(ptypes.Elys, 10000), + expTokenIn: sdk.NewInt64Coin(ptypes.BaseCurrency, 10204), + tokenOutMax: sdkmath.NewInt(1000000), + tokenDenomIn: ptypes.BaseCurrency, + expSenderBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1010000), sdk.NewInt64Coin(ptypes.BaseCurrency, 989796)}, + expPass: true, + }, + { + desc: "successful execution with zero swap fee", + senderInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)}, + swapFee: sdkmath.LegacyZeroDec(), + tokenOut: sdk.NewInt64Coin(ptypes.Elys, 10000), + expTokenIn: sdk.NewInt64Coin(ptypes.BaseCurrency, 10102), + tokenOutMax: sdkmath.NewInt(1000000), + tokenDenomIn: ptypes.BaseCurrency, + expSenderBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1010000), sdk.NewInt64Coin(ptypes.BaseCurrency, 989898)}, + expPass: true, + }, + } { + suite.Run(tc.desc, func() { + suite.SetupTest() + + // set asset profile + suite.app.AssetprofileKeeper.SetEntry(suite.ctx, assetprofiletypes.Entry{ + BaseDenom: ptypes.Elys, + Denom: ptypes.Elys, + Decimals: 6, + }) + + suite.app.AssetprofileKeeper.SetEntry(suite.ctx, assetprofiletypes.Entry{ + BaseDenom: ptypes.BaseCurrency, + Denom: ptypes.BaseCurrency, + Decimals: 6, + }) + + // bootstrap accounts + sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + poolAddr := types.NewPoolAddress(uint64(1)) + treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + poolAddr2 := types.NewPoolAddress(uint64(2)) + treasuryAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + poolCoins := sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)} + pool2Coins := sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin("uusdt", 1000000)} + + // bootstrap balances + err := suite.app.BankKeeper.MintCoins(suite.ctx, minttypes.ModuleName, tc.senderInitBalance) + suite.Require().NoError(err) + err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, minttypes.ModuleName, sender, tc.senderInitBalance) + suite.Require().NoError(err) + err = suite.app.BankKeeper.MintCoins(suite.ctx, minttypes.ModuleName, poolCoins) + suite.Require().NoError(err) + err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, minttypes.ModuleName, poolAddr, poolCoins) + suite.Require().NoError(err) + err = suite.app.BankKeeper.MintCoins(suite.ctx, minttypes.ModuleName, pool2Coins) + suite.Require().NoError(err) + err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, minttypes.ModuleName, poolAddr2, pool2Coins) + suite.Require().NoError(err) + + // execute function + suite.app.AmmKeeper.SetDenomLiquidity(suite.ctx, types.DenomLiquidity{ + Denom: ptypes.Elys, + Liquidity: sdkmath.NewInt(2000000), + }) + suite.app.AmmKeeper.SetDenomLiquidity(suite.ctx, types.DenomLiquidity{ + Denom: ptypes.BaseCurrency, + Liquidity: sdkmath.NewInt(1000000), + }) + suite.app.AmmKeeper.SetDenomLiquidity(suite.ctx, types.DenomLiquidity{ + Denom: "uusdt", + Liquidity: sdkmath.NewInt(1000000), + }) + + pool := types.Pool{ + PoolId: 1, + Address: poolAddr.String(), + RebalanceTreasury: treasuryAddr.String(), + PoolParams: types.PoolParams{ + SwapFee: tc.swapFee, + FeeDenom: ptypes.BaseCurrency, + }, + TotalShares: sdk.Coin{}, + PoolAssets: []types.PoolAsset{ + { + Token: poolCoins[0], + Weight: sdkmath.NewInt(10), + }, + { + Token: poolCoins[1], + Weight: sdkmath.NewInt(10), + }, + }, + TotalWeight: sdkmath.ZeroInt(), + } + pool2 := types.Pool{ + PoolId: 2, + Address: poolAddr2.String(), + RebalanceTreasury: treasuryAddr2.String(), + PoolParams: types.PoolParams{ + SwapFee: tc.swapFee, + FeeDenom: ptypes.BaseCurrency, + }, + TotalShares: sdk.Coin{}, + PoolAssets: []types.PoolAsset{ + { + Token: pool2Coins[0], + Weight: sdkmath.NewInt(10), + }, + { + Token: pool2Coins[1], + Weight: sdkmath.NewInt(10), + }, + }, + TotalWeight: sdkmath.ZeroInt(), + } + suite.app.AmmKeeper.SetPool(suite.ctx, pool) + suite.app.AmmKeeper.SetPool(suite.ctx, pool2) + suite.Require().True(suite.VerifyPoolAssetWithBalance(1)) + suite.Require().True(suite.VerifyPoolAssetWithBalance(2)) + + msgServer := keeper.NewMsgServerImpl(*suite.app.AmmKeeper) + resp, err := msgServer.SwapByDenom( + suite.ctx, + &types.MsgSwapByDenom{ + Sender: sender.String(), + Amount: tc.tokenOut, + MinAmount: sdk.Coin{}, + MaxAmount: sdk.NewCoin(tc.tokenOut.Denom, tc.tokenOutMax), + DenomIn: tc.tokenDenomIn, + DenomOut: tc.tokenOut.Denom, + }) + if !tc.expPass { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(tc.expTokenIn.String(), resp.Amount.String()) + suite.app.AmmKeeper.EndBlocker(suite.ctx) + suite.Require().True(suite.VerifyPoolAssetWithBalance(1)) + suite.Require().True(suite.VerifyPoolAssetWithBalance(2)) + + // check balance change on sender + balances := suite.app.BankKeeper.GetAllBalances(suite.ctx, sender) + suite.Require().Equal(tc.expSenderBalance.String(), balances.String()) + } + }) + } +} diff --git a/x/amm/types/amm_price_test.go b/x/amm/types/amm_price_test.go new file mode 100644 index 000000000..5dd07477c --- /dev/null +++ b/x/amm/types/amm_price_test.go @@ -0,0 +1,144 @@ +package types_test + +import ( + "testing" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/amm/types" + "github.com/elys-network/elys/x/amm/types/mocks" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestGetTokenARate(t *testing.T) { + ctx := sdk.Context{} + accKeeper := mocks.NewAccountedPoolKeeper(t) + + // Define test cases + testCases := []struct { + name string + setupMock func(oracleKeeper *mocks.OracleKeeper) + pool *types.Pool + tokenA string + tokenB string + expectedRate sdkmath.LegacyDec + expectedErrMsg string + }{ + { + "balancer pricing", + func(oracleKeeper *mocks.OracleKeeper) {}, + &types.Pool{ + PoolParams: types.PoolParams{UseOracle: false}, + PoolAssets: []types.PoolAsset{ + {Token: sdk.NewCoin("tokenA", sdkmath.NewInt(1500)), Weight: sdkmath.NewInt(1)}, + {Token: sdk.NewCoin("tokenB", sdkmath.NewInt(2000)), Weight: sdkmath.NewInt(1)}, + }, + }, + "tokenA", + "tokenB", + sdkmath.LegacyNewDec(4).Quo(sdkmath.LegacyNewDec(3)), + "", + }, + { + "oracle pricing", + func(oracleKeeper *mocks.OracleKeeper) { + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenA").Return(sdkmath.LegacyNewDec(10)) + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenB").Return(sdkmath.LegacyNewDec(5)) + }, + &types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + }, + "tokenA", + "tokenB", + sdkmath.LegacyNewDec(2), + "", + }, + { + "token price not set for tokenA", + func(oracleKeeper *mocks.OracleKeeper) { + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "unknownToken").Return(sdkmath.LegacyZeroDec()) + }, + &types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + }, + "unknownToken", + "tokenB", + sdkmath.LegacyZeroDec(), + "token price not set: unknownToken", + }, + { + "token price not set for tokenB", + func(oracleKeeper *mocks.OracleKeeper) { + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenA").Return(sdkmath.LegacyNewDec(5)) + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "unknownToken").Return(sdkmath.LegacyZeroDec()) + }, + &types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + }, + "tokenA", + "unknownToken", + sdkmath.LegacyZeroDec(), + "token price not set: unknownToken", + }, + { + "Success with oracle pricing", + func(oracleKeeper *mocks.OracleKeeper) { + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenA").Return(sdkmath.LegacyNewDec(5)) + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenB").Return(sdkmath.LegacyNewDec(2)) + }, + &types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + }, + "tokenA", + "tokenB", + sdkmath.LegacyNewDec(5).Quo(sdkmath.LegacyNewDec(2)), + "", + }, + { + "Success with oracle pricing", + func(oracleKeeper *mocks.OracleKeeper) { + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenA").Return(sdkmath.LegacyNewDec(5)) + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenB").Return(sdkmath.LegacyNewDec(2)) + }, + &types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + }, + "tokenA", + "tokenB", + sdkmath.LegacyNewDec(5).Quo(sdkmath.LegacyNewDec(2)), + "", + }, + { + "Success with oracle pricing with price less than 1", + func(oracleKeeper *mocks.OracleKeeper) { + // for 6 decimal tokens + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenA").Return(sdkmath.LegacyMustNewDecFromStr("0.0000002")) + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenB").Return(sdkmath.LegacyNewDec(1)) + }, + &types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + }, + "tokenA", + "tokenB", + sdkmath.LegacyMustNewDecFromStr("0.0000002"), + "", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + oracleKeeper := mocks.NewOracleKeeper(t) + tc.setupMock(oracleKeeper) + + rate, err := tc.pool.GetTokenARate(ctx, oracleKeeper, tc.pool, tc.tokenA, tc.tokenB, accKeeper) + if tc.expectedErrMsg != "" { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedErrMsg) + } else { + require.NoError(t, err) + require.Equal(t, tc.expectedRate, rate) + } + }) + } +} diff --git a/x/amm/types/calc_exit_pool_test.go b/x/amm/types/calc_exit_pool_test.go new file mode 100644 index 000000000..67c2e67f6 --- /dev/null +++ b/x/amm/types/calc_exit_pool_test.go @@ -0,0 +1,218 @@ +package types_test + +import ( + "testing" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/amm/types" + "github.com/elys-network/elys/x/amm/types/mocks" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestCalcExitValueWithoutSlippage(t *testing.T) { + ctx := sdk.Context{} + + // Define test cases + testCases := []struct { + name string + setupMock func(oracleKeeper *mocks.OracleKeeper, accKeeper *mocks.AccountedPoolKeeper) + pool types.Pool + exitingShares sdkmath.Int + tokenOutDenom string + expectedValue sdkmath.LegacyDec + expectedErrMsg string + }{ + { + "successful exit value calculation", + func(oracleKeeper *mocks.OracleKeeper, accKeeper *mocks.AccountedPoolKeeper) { + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenA").Return(sdkmath.LegacyNewDec(10)) + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenB").Return(sdkmath.LegacyNewDec(5)) + accKeeper.On("GetAccountedBalance", mock.Anything, mock.Anything, "tokenA").Return(sdkmath.NewInt(1000)) + accKeeper.On("GetAccountedBalance", mock.Anything, mock.Anything, "tokenB").Return(sdkmath.NewInt(2000)) + }, + types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + PoolAssets: []types.PoolAsset{ + {Token: sdk.NewCoin("tokenA", sdkmath.NewInt(1000)), Weight: sdkmath.NewInt(1)}, + {Token: sdk.NewCoin("tokenB", sdkmath.NewInt(2000)), Weight: sdkmath.NewInt(1)}, + }, + TotalShares: sdk.NewCoin("shares", sdkmath.NewInt(100)), + }, + sdkmath.NewInt(10), + "tokenA", + sdkmath.LegacyNewDec(2000), + "", + }, + { + "total shares is zero", + func(oracleKeeper *mocks.OracleKeeper, accKeeper *mocks.AccountedPoolKeeper) { + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenA").Return(sdkmath.LegacyNewDec(10)) + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenB").Return(sdkmath.LegacyNewDec(5)) + accKeeper.On("GetAccountedBalance", mock.Anything, mock.Anything, "tokenA").Return(sdkmath.NewInt(1000)) + accKeeper.On("GetAccountedBalance", mock.Anything, mock.Anything, "tokenB").Return(sdkmath.NewInt(2000)) + }, + types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + PoolAssets: []types.PoolAsset{ + {Token: sdk.NewCoin("tokenA", sdkmath.NewInt(1000)), Weight: sdkmath.NewInt(1)}, + {Token: sdk.NewCoin("tokenB", sdkmath.NewInt(2000)), Weight: sdkmath.NewInt(1)}, + }, + TotalShares: sdk.NewCoin("shares", sdkmath.ZeroInt()), + }, + sdkmath.NewInt(10), + "tokenA", + sdkmath.LegacyZeroDec(), + "amount too low", + }, + { + "exiting shares greater than total shares", + func(oracleKeeper *mocks.OracleKeeper, accKeeper *mocks.AccountedPoolKeeper) { + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenA").Return(sdkmath.LegacyNewDec(10)) + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenB").Return(sdkmath.LegacyNewDec(5)) + accKeeper.On("GetAccountedBalance", mock.Anything, mock.Anything, "tokenA").Return(sdkmath.NewInt(1000)) + accKeeper.On("GetAccountedBalance", mock.Anything, mock.Anything, "tokenB").Return(sdkmath.NewInt(2000)) + }, + types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + PoolAssets: []types.PoolAsset{ + {Token: sdk.NewCoin("tokenA", sdkmath.NewInt(1000)), Weight: sdkmath.NewInt(1)}, + {Token: sdk.NewCoin("tokenB", sdkmath.NewInt(2000)), Weight: sdkmath.NewInt(1)}, + }, + TotalShares: sdk.NewCoin("shares", sdkmath.NewInt(10)), + }, + sdkmath.NewInt(100), + "tokenA", + sdkmath.LegacyZeroDec(), + "shares is larger than the max amount", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + oracleKeeper := mocks.NewOracleKeeper(t) + accKeeper := mocks.NewAccountedPoolKeeper(t) + tc.setupMock(oracleKeeper, accKeeper) + + value, err := types.CalcExitValueWithoutSlippage(ctx, oracleKeeper, accKeeper, tc.pool, tc.exitingShares, tc.tokenOutDenom) + if tc.expectedErrMsg != "" { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedErrMsg) + } else { + require.NoError(t, err) + require.Equal(t, tc.expectedValue, value) + } + + oracleKeeper.AssertExpectations(t) + }) + } +} + +func TestCalcExitPool(t *testing.T) { + ctx := sdk.Context{} + + // Define test cases + testCases := []struct { + name string + setupMock func(oracleKeeper *mocks.OracleKeeper, accKeeper *mocks.AccountedPoolKeeper) + pool types.Pool + exitingShares sdkmath.Int + tokenOutDenom string + params types.Params + expectedCoins sdk.Coins + expectedBonus sdkmath.LegacyDec + expectedErrMsg string + }{ + { + "successful exit with oracle pricing", + func(oracleKeeper *mocks.OracleKeeper, accKeeper *mocks.AccountedPoolKeeper) { + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenA").Return(sdkmath.LegacyMustNewDecFromStr("0.00001")) + accKeeper.On("GetAccountedBalance", mock.Anything, mock.Anything, "tokenA").Return(sdkmath.NewInt(1000)) + }, + types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + PoolAssets: []types.PoolAsset{ + {Token: sdk.NewCoin("tokenA", sdkmath.NewInt(1000)), Weight: sdkmath.NewInt(1)}, + }, + TotalShares: sdk.NewCoin("shares", sdkmath.NewInt(100)), + }, + sdkmath.NewInt(10), + "tokenA", + types.Params{ + WeightBreakingFeeMultiplier: sdkmath.LegacyMustNewDecFromStr("0.0005"), + }, + sdk.Coins{sdk.NewCoin("tokenA", sdkmath.NewInt(100))}, + sdkmath.LegacyZeroDec(), + "", + }, + { + "exiting shares greater than total shares", + func(oracleKeeper *mocks.OracleKeeper, accKeeper *mocks.AccountedPoolKeeper) {}, + types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + TotalShares: sdk.NewCoin("shares", sdkmath.NewInt(10)), + }, + sdkmath.NewInt(20), + "tokenA", + types.Params{}, + sdk.Coins{}, + sdkmath.LegacyZeroDec(), + "shares is larger than the max amount", + }, + { + "exiting shares greater than total shares", + func(oracleKeeper *mocks.OracleKeeper, accKeeper *mocks.AccountedPoolKeeper) { + oracleKeeper.On("GetAssetPriceFromDenom", mock.Anything, "tokenA").Return(sdkmath.LegacyNewDec(0)) + }, + types.Pool{ + PoolParams: types.PoolParams{UseOracle: true}, + TotalShares: sdk.NewCoin("shares", sdkmath.NewInt(100)), + }, + sdkmath.NewInt(10), + "tokenA", + types.Params{}, + sdk.Coins{}, + sdkmath.LegacyZeroDec(), + "amount too low", + }, + { + "successful exit without oracle pricing", + func(oracleKeeper *mocks.OracleKeeper, accKeeper *mocks.AccountedPoolKeeper) {}, + types.Pool{ + PoolParams: types.PoolParams{UseOracle: false}, + PoolAssets: []types.PoolAsset{ + {Token: sdk.NewCoin("tokenA", sdkmath.NewInt(1000)), Weight: sdkmath.NewInt(1)}, + }, + TotalShares: sdk.NewCoin("shares", sdkmath.NewInt(100)), + }, + sdkmath.NewInt(10), + "", + types.Params{}, + sdk.Coins{sdk.NewCoin("tokenA", sdkmath.NewInt(100))}, + sdkmath.LegacyZeroDec(), + "", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + oracleKeeper := mocks.NewOracleKeeper(t) + accKeeper := mocks.NewAccountedPoolKeeper(t) + tc.setupMock(oracleKeeper, accKeeper) + + exitCoins, weightBalanceBonus, err := types.CalcExitPool(ctx, oracleKeeper, tc.pool, accKeeper, tc.exitingShares, tc.tokenOutDenom, tc.params) + if tc.expectedErrMsg != "" { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedErrMsg) + } else { + require.NoError(t, err) + require.Equal(t, tc.expectedCoins, exitCoins) + require.Equal(t, tc.expectedBonus, weightBalanceBonus) + } + + oracleKeeper.AssertExpectations(t) + accKeeper.AssertExpectations(t) + }) + } +} diff --git a/x/amm/types/message_create_pool_test.go b/x/amm/types/message_create_pool_test.go index 7fe57a709..9695e8736 100644 --- a/x/amm/types/message_create_pool_test.go +++ b/x/amm/types/message_create_pool_test.go @@ -1,9 +1,11 @@ package types_test import ( + "fmt" + "testing" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/elys-network/elys/testutil/sample" @@ -30,6 +32,30 @@ func TestMsgCreatePool_ValidateBasic(t *testing.T) { }, err: sdkerrors.ErrInvalidAddress, }, + { + name: "swap fee is negative, invalid params", + msg: types.MsgCreatePool{ + Sender: sample.AccAddress(), + PoolParams: types.PoolParams{ + SwapFee: sdkmath.LegacyNewDec(-1), + UseOracle: false, + FeeDenom: ptypes.BaseCurrency, + }, + PoolAssets: []types.PoolAsset{ + { + Token: sdk.NewCoin("uusdc", sdkmath.NewInt(10000000)), + Weight: sdkmath.NewInt(10), + ExternalLiquidityRatio: sdkmath.LegacyOneDec(), + }, + { + Token: sdk.NewCoin("uatom", sdkmath.NewInt(10000000)), + Weight: sdkmath.NewInt(10), + ExternalLiquidityRatio: sdkmath.LegacyOneDec(), + }, + }, + }, + err: types.ErrNegativeSwapFee, + }, { name: "pool assets must be exactly two", msg: types.MsgCreatePool{ @@ -48,6 +74,30 @@ func TestMsgCreatePool_ValidateBasic(t *testing.T) { }, err: types.ErrPoolAssetsMustBeTwo, }, + { + name: "Invalid Pool Assets", + msg: types.MsgCreatePool{ + Sender: sample.AccAddress(), + PoolParams: types.PoolParams{ + SwapFee: sdkmath.LegacyZeroDec(), + UseOracle: false, + FeeDenom: ptypes.BaseCurrency, + }, + PoolAssets: []types.PoolAsset{ + { + Token: sdk.NewCoin("uusdc", sdkmath.NewInt(10000000)), + Weight: sdkmath.NewInt(10), + ExternalLiquidityRatio: sdkmath.LegacyOneDec(), + }, + { + Token: sdk.NewCoin("uatom", sdkmath.NewInt(10000000)), + Weight: sdkmath.NewInt(-1), + ExternalLiquidityRatio: sdkmath.LegacyOneDec(), + }, + }, + }, + err: fmt.Errorf("invalid pool asset"), + }, { name: "valid address", msg: types.MsgCreatePool{ @@ -76,10 +126,56 @@ func TestMsgCreatePool_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + require.Contains(t, err.Error(), tt.err.Error()) return } require.NoError(t, err) }) } } + +func TestInitialLiquidity(t *testing.T) { + // Define test cases + testCases := []struct { + name string + msg types.MsgCreatePool + expectedCoins sdk.Coins + expectedPanic bool + }{ + { + "successful initial liquidity with sorted poolAssets", + types.MsgCreatePool{ + PoolAssets: []types.PoolAsset{ + {Token: sdk.NewCoin("tokenB", sdkmath.NewInt(2000))}, + {Token: sdk.NewCoin("tokenA", sdkmath.NewInt(1000))}, + }, + }, + sdk.Coins{ + sdk.NewCoin("tokenA", sdkmath.NewInt(1000)), + sdk.NewCoin("tokenB", sdkmath.NewInt(2000)), + }, + false, + }, + { + "empty pool assets", + types.MsgCreatePool{ + PoolAssets: []types.PoolAsset{}, + }, + sdk.Coins{}, + true, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + if tc.expectedPanic { + require.Panics(t, func() { + _ = tc.msg.InitialLiquidity() + }) + } else { + coins := tc.msg.InitialLiquidity() + require.Equal(t, tc.expectedCoins, coins) + } + }) + } +} diff --git a/x/amm/types/message_exit_pool_test.go b/x/amm/types/message_exit_pool_test.go index 95134086b..081df4080 100644 --- a/x/amm/types/message_exit_pool_test.go +++ b/x/amm/types/message_exit_pool_test.go @@ -1,9 +1,11 @@ package types_test import ( + "fmt" "testing" "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/elys-network/elys/testutil/sample" "github.com/elys-network/elys/x/amm/types" @@ -23,19 +25,47 @@ func TestMsgExitPool_ValidateBasic(t *testing.T) { ShareAmountIn: math.NewInt(100), }, err: sdkerrors.ErrInvalidAddress, - }, { + }, + { name: "valid address", msg: types.MsgExitPool{ Sender: sample.AccAddress(), ShareAmountIn: math.NewInt(100), }, }, + { + name: "Invalid Minimum Amounts Out", + msg: types.MsgExitPool{ + Sender: sample.AccAddress(), + ShareAmountIn: math.NewInt(100), + MinAmountsOut: sdk.Coins{sdk.Coin{Denom: "uusdc", Amount: math.NewInt(-100)}}, + }, + err: fmt.Errorf("negative coin amount"), + }, + { + name: "ShareAmount is Nil", + msg: types.MsgExitPool{ + Sender: sample.AccAddress(), + ShareAmountIn: math.Int{}, + MinAmountsOut: sdk.Coins{sdk.Coin{Denom: "uusdc", Amount: math.NewInt(100)}}, + }, + err: types.ErrInvalidShareAmountOut, + }, + { + name: "ShareAmount is Negative", + msg: types.MsgExitPool{ + Sender: sample.AccAddress(), + ShareAmountIn: math.NewInt(-100), + MinAmountsOut: sdk.Coins{sdk.Coin{Denom: "uusdc", Amount: math.NewInt(100)}}, + }, + err: types.ErrInvalidShareAmountOut, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + require.Contains(t, err.Error(), tt.err.Error()) return } require.NoError(t, err) diff --git a/x/amm/types/message_feed_multiple_external_liquidity_test.go b/x/amm/types/message_feed_multiple_external_liquidity_test.go new file mode 100644 index 000000000..c23e73732 --- /dev/null +++ b/x/amm/types/message_feed_multiple_external_liquidity_test.go @@ -0,0 +1,132 @@ +package types_test + +import ( + "testing" + + sdkmath "cosmossdk.io/math" + "github.com/elys-network/elys/testutil/sample" + "github.com/elys-network/elys/x/amm/types" + "github.com/stretchr/testify/require" +) + +func TestMsgFeedMultipleExternalLiquidity_ValidateBasic(t *testing.T) { + // Define test cases + testCases := []struct { + name string + msg types.MsgFeedMultipleExternalLiquidity + expectedErrMsg string + }{ + { + "Invalid address", + types.MsgFeedMultipleExternalLiquidity{ + Sender: "elys11", + Liquidity: []types.ExternalLiquidity{ + { + AmountDepthInfo: []types.AssetAmountDepth{ + {Asset: "tokenA", Depth: sdkmath.LegacyNewDec(1000), Amount: sdkmath.LegacyNewDec(500)}, + {Asset: "tokenB", Depth: sdkmath.LegacyNewDec(2000), Amount: sdkmath.LegacyNewDec(1000)}, + }, + }, + }, + }, + "invalid sender address", + }, + { + "valid message", + types.MsgFeedMultipleExternalLiquidity{ + Sender: sample.AccAddress(), + Liquidity: []types.ExternalLiquidity{ + { + AmountDepthInfo: []types.AssetAmountDepth{ + {Asset: "tokenA", Depth: sdkmath.LegacyNewDec(1000), Amount: sdkmath.LegacyNewDec(500)}, + {Asset: "tokenB", Depth: sdkmath.LegacyNewDec(2000), Amount: sdkmath.LegacyNewDec(1000)}, + }, + }, + }, + }, + "", + }, + { + "invalid asset denom", + types.MsgFeedMultipleExternalLiquidity{ + Sender: sample.AccAddress(), + Liquidity: []types.ExternalLiquidity{ + { + AmountDepthInfo: []types.AssetAmountDepth{ + {Asset: "invalid denom", Depth: sdkmath.LegacyNewDec(1000), Amount: sdkmath.LegacyNewDec(500)}, + }, + }, + }, + }, + "invalid denom: invalid denom", + }, + { + "negative depth", + types.MsgFeedMultipleExternalLiquidity{ + Sender: sample.AccAddress(), + Liquidity: []types.ExternalLiquidity{ + { + AmountDepthInfo: []types.AssetAmountDepth{ + {Asset: "tokenA", Depth: sdkmath.LegacyNewDec(-1000), Amount: sdkmath.LegacyNewDec(500)}, + }, + }, + }, + }, + "depth cannot be negative or nil", + }, + { + "negative amount", + types.MsgFeedMultipleExternalLiquidity{ + Sender: sample.AccAddress(), + Liquidity: []types.ExternalLiquidity{ + { + AmountDepthInfo: []types.AssetAmountDepth{ + {Asset: "tokenA", Depth: sdkmath.LegacyNewDec(1000), Amount: sdkmath.LegacyNewDec(-500)}, + }, + }, + }, + }, + "depth amount cannot be negative or nil", + }, + { + "nil depth", + types.MsgFeedMultipleExternalLiquidity{ + Sender: sample.AccAddress(), + Liquidity: []types.ExternalLiquidity{ + { + AmountDepthInfo: []types.AssetAmountDepth{ + {Asset: "tokenA", Depth: sdkmath.LegacyDec{}, Amount: sdkmath.LegacyNewDec(500)}, + }, + }, + }, + }, + "depth cannot be negative or nil", + }, + { + "nil amount", + types.MsgFeedMultipleExternalLiquidity{ + Sender: sample.AccAddress(), + Liquidity: []types.ExternalLiquidity{ + { + AmountDepthInfo: []types.AssetAmountDepth{ + {Asset: "tokenA", Depth: sdkmath.LegacyNewDec(1000), Amount: sdkmath.LegacyDec{}}, + }, + }, + }, + }, + "depth amount cannot be negative or nil", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := tc.msg.ValidateBasic() + if tc.expectedErrMsg != "" { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedErrMsg) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/amm/types/message_join_pool_test.go b/x/amm/types/message_join_pool_test.go index 399b444f0..5cfced70f 100644 --- a/x/amm/types/message_join_pool_test.go +++ b/x/amm/types/message_join_pool_test.go @@ -1,9 +1,11 @@ package types_test import ( + "fmt" "testing" "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/elys-network/elys/testutil/sample" "github.com/elys-network/elys/x/amm/types" @@ -29,12 +31,39 @@ func TestMsgJoinPool_ValidateBasic(t *testing.T) { ShareAmountOut: math.NewInt(100), }, }, + { + name: "Invalid Maximum Amounts in", + msg: types.MsgJoinPool{ + Sender: sample.AccAddress(), + ShareAmountOut: math.NewInt(100), + MaxAmountsIn: sdk.Coins{sdk.Coin{Denom: "uusdc", Amount: math.NewInt(-100)}}, + }, + err: fmt.Errorf("negative coin amount"), + }, + { + name: "ShareAmount is Nil", + msg: types.MsgJoinPool{ + Sender: sample.AccAddress(), + ShareAmountOut: math.Int{}, + MaxAmountsIn: sdk.Coins{sdk.Coin{Denom: "uusdc", Amount: math.NewInt(100)}}, + }, + err: types.ErrInvalidShareAmountOut, + }, + { + name: "ShareAmount is Negative", + msg: types.MsgJoinPool{ + Sender: sample.AccAddress(), + ShareAmountOut: math.NewInt(-100), + MaxAmountsIn: sdk.Coins{sdk.Coin{Denom: "uusdc", Amount: math.NewInt(100)}}, + }, + err: types.ErrInvalidShareAmountOut, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + require.Contains(t, err.Error(), tt.err.Error()) return } require.NoError(t, err) diff --git a/x/amm/types/message_swap_by_denom_test.go b/x/amm/types/message_swap_by_denom_test.go index f6d01a842..692afbed3 100644 --- a/x/amm/types/message_swap_by_denom_test.go +++ b/x/amm/types/message_swap_by_denom_test.go @@ -1,9 +1,12 @@ package types import ( + "fmt" + "testing" + + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" ptypes "github.com/elys-network/elys/x/parameter/types" - "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/elys-network/elys/testutil/sample" @@ -22,7 +25,8 @@ func TestMsgSwapByDenom_ValidateBasic(t *testing.T) { Sender: "invalid_address", }, err: sdkerrors.ErrInvalidAddress, - }, { + }, + { name: "valid address", msg: MsgSwapByDenom{ Sender: sample.AccAddress(), @@ -31,12 +35,42 @@ func TestMsgSwapByDenom_ValidateBasic(t *testing.T) { DenomOut: ptypes.BaseCurrency, }, }, + { + name: "Invalid Amount", + msg: MsgSwapByDenom{ + Sender: sample.AccAddress(), + Amount: sdk.Coin{Denom: ptypes.ATOM, Amount: sdkmath.NewInt(-10)}, + DenomIn: ptypes.ATOM, + DenomOut: ptypes.BaseCurrency, + }, + err: fmt.Errorf("negative coin amount"), + }, + { + name: "Invalid DenomIn", + msg: MsgSwapByDenom{ + Sender: sample.AccAddress(), + Amount: sdk.Coin{Denom: ptypes.ATOM, Amount: sdkmath.NewInt(10)}, + DenomIn: "invalid denom in", + DenomOut: ptypes.BaseCurrency, + }, + err: fmt.Errorf("invalid denom"), + }, + { + name: "Invalid Denomout", + msg: MsgSwapByDenom{ + Sender: sample.AccAddress(), + Amount: sdk.Coin{Denom: ptypes.ATOM, Amount: sdkmath.NewInt(10)}, + DenomIn: ptypes.ATOM, + DenomOut: "invalid denom out", + }, + err: fmt.Errorf("invalid denom"), + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + require.Contains(t, err.Error(), tt.err.Error()) return } require.NoError(t, err) diff --git a/x/amm/types/message_swap_exact_amount_in_test.go b/x/amm/types/message_swap_exact_amount_in_test.go index 3de28ffe4..920b9186f 100644 --- a/x/amm/types/message_swap_exact_amount_in_test.go +++ b/x/amm/types/message_swap_exact_amount_in_test.go @@ -1,10 +1,12 @@ package types_test import ( + "fmt" + "testing" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" ptypes "github.com/elys-network/elys/x/parameter/types" - "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/elys-network/elys/testutil/sample" @@ -24,7 +26,8 @@ func TestMsgSwapExactAmountIn_ValidateBasic(t *testing.T) { Sender: "invalid_address", }, err: sdkerrors.ErrInvalidAddress, - }, { + }, + { name: "valid address", msg: types.MsgSwapExactAmountIn{ Sender: sample.AccAddress(), @@ -34,12 +37,56 @@ func TestMsgSwapExactAmountIn_ValidateBasic(t *testing.T) { Recipient: "", }, }, + { + name: "Invalid recipient address", + msg: types.MsgSwapExactAmountIn{ + Sender: sample.AccAddress(), + Routes: nil, + TokenIn: sdk.Coin{Denom: ptypes.ATOM, Amount: math.NewInt(10)}, + TokenOutMinAmount: math.NewInt(1), + Recipient: "cosmos1invalid", + }, + err: sdkerrors.ErrInvalidAddress, + }, + { + name: "Invalid TokenOutDenom in route", + msg: types.MsgSwapExactAmountIn{ + Sender: sample.AccAddress(), + Routes: []types.SwapAmountInRoute{{TokenOutDenom: "invalid denom"}}, + TokenIn: sdk.Coin{Denom: ptypes.ATOM, Amount: math.NewInt(10)}, + TokenOutMinAmount: math.NewInt(1), + Recipient: sample.AccAddress(), + }, + err: fmt.Errorf("invalid denom"), + }, + { + name: "Invalid TokenIn", + msg: types.MsgSwapExactAmountIn{ + Sender: sample.AccAddress(), + Routes: []types.SwapAmountInRoute{{TokenOutDenom: "uusdc"}}, + TokenIn: sdk.Coin{Denom: ptypes.ATOM, Amount: math.NewInt(-10)}, + TokenOutMinAmount: math.NewInt(1), + Recipient: sample.AccAddress(), + }, + err: fmt.Errorf("negative coin amount"), + }, + { + name: "Invalid TokenIn amount", + msg: types.MsgSwapExactAmountIn{ + Sender: sample.AccAddress(), + Routes: []types.SwapAmountInRoute{{TokenOutDenom: "uusdc"}}, + TokenIn: sdk.Coin{Denom: ptypes.ATOM, Amount: math.NewInt(0)}, + TokenOutMinAmount: math.NewInt(1), + Recipient: sample.AccAddress(), + }, + err: fmt.Errorf("token in is zero"), + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + require.Contains(t, err.Error(), tt.err.Error()) return } require.NoError(t, err) diff --git a/x/amm/types/message_swap_exact_amount_out_test.go b/x/amm/types/message_swap_exact_amount_out_test.go index 8679173c7..d0b5ea327 100644 --- a/x/amm/types/message_swap_exact_amount_out_test.go +++ b/x/amm/types/message_swap_exact_amount_out_test.go @@ -1,10 +1,12 @@ package types_test import ( + "fmt" + "testing" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" ptypes "github.com/elys-network/elys/x/parameter/types" - "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/elys-network/elys/testutil/sample" @@ -24,22 +26,67 @@ func TestMsgSwapExactAmountOut_ValidateBasic(t *testing.T) { Sender: "invalid_address", }, err: sdkerrors.ErrInvalidAddress, - }, { + }, + { name: "valid address", msg: types.MsgSwapExactAmountOut{ Sender: sample.AccAddress(), Routes: nil, - TokenOut: sdk.Coin{ptypes.ATOM, math.NewInt(10)}, + TokenOut: sdk.Coin{Denom: ptypes.ATOM, Amount: math.NewInt(10)}, TokenInMaxAmount: math.NewInt(1), Recipient: "", }, }, + { + name: "Invalid recipient address", + msg: types.MsgSwapExactAmountOut{ + Sender: sample.AccAddress(), + Routes: nil, + TokenOut: sdk.Coin{Denom: ptypes.ATOM, Amount: math.NewInt(10)}, + TokenInMaxAmount: math.NewInt(1), + Recipient: "cosmos1invalid", + }, + err: sdkerrors.ErrInvalidAddress, + }, + { + name: "Invalid tokenInDenom in route", + msg: types.MsgSwapExactAmountOut{ + Sender: sample.AccAddress(), + Routes: []types.SwapAmountOutRoute{{TokenInDenom: "invalid denom"}}, + TokenOut: sdk.Coin{Denom: ptypes.ATOM, Amount: math.NewInt(10)}, + TokenInMaxAmount: math.NewInt(1), + Recipient: sample.AccAddress(), + }, + err: fmt.Errorf("invalid denom"), + }, + { + name: "Invalid tokenOut", + msg: types.MsgSwapExactAmountOut{ + Sender: sample.AccAddress(), + Routes: []types.SwapAmountOutRoute{{TokenInDenom: "uusdc"}}, + TokenOut: sdk.Coin{Denom: ptypes.ATOM, Amount: math.NewInt(-10)}, + TokenInMaxAmount: math.NewInt(1), + Recipient: sample.AccAddress(), + }, + err: fmt.Errorf("negative coin amount"), + }, + { + name: "Invalid tokenOut amount", + msg: types.MsgSwapExactAmountOut{ + Sender: sample.AccAddress(), + Routes: []types.SwapAmountOutRoute{{TokenInDenom: "uusdc"}}, + TokenOut: sdk.Coin{Denom: ptypes.ATOM, Amount: math.NewInt(0)}, + TokenInMaxAmount: math.NewInt(1), + Recipient: sample.AccAddress(), + }, + err: fmt.Errorf("token in is zero"), + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + require.Contains(t, err.Error(), tt.err.Error()) return } require.NoError(t, err) diff --git a/x/amm/types/pool_calc_join_pool_no_swap_shares_test.go b/x/amm/types/pool_calc_join_pool_no_swap_shares_test.go new file mode 100644 index 000000000..e619d8495 --- /dev/null +++ b/x/amm/types/pool_calc_join_pool_no_swap_shares_test.go @@ -0,0 +1,87 @@ +// pool_calc_join_pool_no_swap_shares_test.go +package types_test + +import ( + "testing" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/amm/types" + "github.com/stretchr/testify/require" +) + +func TestMaximalExactRatioJoin(t *testing.T) { + // Define test cases + testCases := []struct { + name string + pool *types.Pool + tokensIn sdk.Coins + expectedShares sdkmath.Int + expectedRem sdk.Coins + expectedErrMsg string + }{ + { + "successful join with exact ratio", + &types.Pool{ + TotalShares: sdk.NewCoin("shares", sdkmath.NewInt(1000)), + PoolAssets: []types.PoolAsset{ + {Token: sdk.NewCoin("tokenA", sdkmath.NewInt(1000))}, + {Token: sdk.NewCoin("tokenB", sdkmath.NewInt(2000))}, + }, + }, + sdk.Coins{ + sdk.NewCoin("tokenA", sdkmath.NewInt(100)), + sdk.NewCoin("tokenB", sdkmath.NewInt(200)), + }, + sdkmath.NewInt(100), + sdk.Coins{}, + "", + }, + { + "successful join with remaining coins", + &types.Pool{ + TotalShares: sdk.NewCoin("shares", sdkmath.NewInt(1000)), + PoolAssets: []types.PoolAsset{ + {Token: sdk.NewCoin("tokenA", sdkmath.NewInt(1000))}, + {Token: sdk.NewCoin("tokenB", sdkmath.NewInt(2000))}, + }, + }, + sdk.Coins{ + sdk.NewCoin("tokenA", sdkmath.NewInt(150)), + sdk.NewCoin("tokenB", sdkmath.NewInt(200)), + }, + sdkmath.NewInt(100), + sdk.Coins{ + sdk.NewCoin("tokenA", sdkmath.NewInt(50)), + }, + "", + }, + { + "unexpected error due to pool liquidity is zero for denom", + &types.Pool{ + TotalShares: sdk.NewCoin("shares", sdkmath.NewInt(1000)), + PoolAssets: []types.PoolAsset{}, + }, + sdk.Coins{ + sdk.NewCoin("tokenA", sdkmath.NewInt(100)), + }, + sdkmath.Int{}, + sdk.Coins{}, + "pool liquidity is zero for denom", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + shares, rem, err := types.MaximalExactRatioJoin(tc.pool, tc.tokensIn) + if tc.expectedErrMsg != "" { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedErrMsg) + } else { + require.NoError(t, err) + require.Equal(t, tc.expectedShares, shares) + require.Equal(t, tc.expectedRem, rem) + } + }) + } +} From 970f1b3851a01ab5ca506b1cee66d7e19c8807e8 Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Mon, 9 Dec 2024 18:15:07 +0100 Subject: [PATCH 3/4] =?UTF-8?q?Update=20chain=20ID=20references=20from=20'?= =?UTF-8?q?elystestnet-1'=20to=20'elysicstestnet-1'=E2=80=A6=20(#1049)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update chain ID references from 'elystestnet-1' to 'elysicstestnet-1' across multiple files - Changed the chain ID in configuration files, scripts, and documentation to reflect the new test network name. - Removed the 'network.md' and 'troubleshooting.md' files as they are no longer needed. - Ensured consistency in CLI command examples by updating the chain ID in various scripts and usage documentation. This update improves clarity and aligns with the current network naming conventions. * Refactor CLI commands and documentation for consistency and clarity - Removed redundant `keyring-backend=test` from multiple CLI commands across various scripts to streamline usage. - Updated command examples in documentation and scripts to remove unnecessary parameters, enhancing readability and usability. - Adjusted references to the `elysicstestnet-1` chain ID in scripts and documentation to ensure uniformity. - Improved the clarity of the `README.md` and other documentation files by refining command examples and descriptions. - Deleted obsolete files such as `genesis.json`, `config.yml`, and `readme.md` from the `chain` directory to clean up the repository structure. These changes enhance the user experience by providing clearer instructions and reducing potential confusion in command usage. * Remove testnet configuration file - Deleted the `testnet.yml` configuration file, which contained account details, token definitions, and other network parameters. - This cleanup helps streamline the repository by removing obsolete configurations that are no longer needed. --------- Co-authored-by: Abhinav Kumar <57705190+avkr003@users.noreply.github.com> --- architecture.md | 14 +- chain/genesis.json | 899 -------------------- chain/readme.md | 5 - config.yml | 455 ---------- configs/testnet.yml | 240 ------ network.md | 151 ---- readme.md | 51 +- scripts/examples/amm/amm.sh | 8 +- scripts/examples/commitment/commitment.sh | 4 +- scripts/examples/estaking/estaking.sh | 16 +- scripts/examples/estaking/snapshot_test.sh | 18 +- scripts/examples/incentive/incentive.sh | 4 +- scripts/examples/incentive/upgrade.sh | 30 +- scripts/examples/leveragelp/leveragelp.sh | 22 +- scripts/examples/masterchef/masterchef.sh | 12 +- scripts/examples/oracle/README.md | 114 +-- scripts/examples/stablestake/stablestake.sh | 4 +- scripts/examples/transferhook/README.md | 18 +- scripts/examples/transferhook/config.toml | 2 +- scripts/propose/propose.sh | 2 +- scripts/testing/variables.sh.example | 2 +- troubleshooting.md | 11 - x/commitment/spec/02_usage.md | 12 +- x/estaking/spec/02_usage.md | 16 +- x/perpetual/spec/03_usage.md | 24 +- x/stablestake/spec/03_usage.md | 4 +- 26 files changed, 176 insertions(+), 1962 deletions(-) delete mode 100644 chain/genesis.json delete mode 100644 chain/readme.md delete mode 100644 config.yml delete mode 100644 configs/testnet.yml delete mode 100644 network.md delete mode 100644 troubleshooting.md diff --git a/architecture.md b/architecture.md index 2b33192c1..618a043e5 100644 --- a/architecture.md +++ b/architecture.md @@ -50,21 +50,9 @@ The diagram below illustrates the architecture of Elys Network, outlining its va The interaction flow between layers is depicted with arrows. Data from the Core Components feeds into the Data Layer. The Liquidity Management layer uses this data to manage liquidity, which is then aggregated in the Pool Aggregation layer. Trading mechanisms utilize the pooled liquidity for various trading activities. The Revenue Model layer ensures economic incentives and sustainability of the system. -## Boilerplate Generation - -The boilerplate was generated using `ignite CLI`, which provides a convenient way to generate new chains, modules, messages, and more. The initial modules that are part of the repository include `AssetProfile` and few others, both of which were generated using the `ignite CLI`. - -`AssetProfile` requires all changes to go through governance proposals (i.e., adding, updating, or deleting an asset profile entry). Similarly, any modules that expose parameters must require governance proposals to update the module parameters. - -## Configuration File - -The repository also includes a `config.yml` file, which provides a convenient way to initiate the genesis account, set up a faucet for testnet, define initial validators, and override initial genesis states. Although `ignite` provides the network layer that allows for easy onboarding of new validators to a chain network, the `config.yml` file can be used to specify additional configurations. - -In the current `config.yml` file, additional denom metadata has been defined to allow for easy setting of the ELYS amount using any exponent (decimal precision) following the EVMOS good practices. The governance params have also been overridden to reduce the voting period to 20 seconds for local test purposes. Multiple `config.yml` files can be created for each environment (local, testnet, mainnet) with their specific parameters. - ## Denom Units -The `denom_units` property is an array of objects defined in the [config.yml](./config.yml) file, with each object defining a single denomination unit. Each unit object has three properties - `denom`, `exponent`, and `aliases`. +The `denom_units` property is an array of objects, with each object defining a single denomination unit. Each unit object has three properties - `denom`, `exponent`, and `aliases`. For the ELYS token, there are three denomination units defined with aliases: diff --git a/chain/genesis.json b/chain/genesis.json deleted file mode 100644 index 165fcdcec..000000000 --- a/chain/genesis.json +++ /dev/null @@ -1,899 +0,0 @@ -{ - "genesis_time": "2023-04-10T18:42:34Z", - "chain_id": "elystestnet-1", - "initial_height": "1", - "consensus_params": { - "block": { - "max_bytes": "22020096", - "max_gas": "-1", - "time_iota_ms": "1000" - }, - "evidence": { - "max_age_num_blocks": "100000", - "max_age_duration": "172800000000000", - "max_bytes": "1048576" - }, - "validator": { - "pub_key_types": ["ed25519"] - }, - "version": {} - }, - "app_hash": "", - "app_state": { - "assetprofile": { - "entryList": [ - { - "address": "", - "authority": "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", - "baseDenom": "uelys", - "decimals": "18", - "denom": "uelys", - "displayName": "ELYS", - "displaySymbol": "", - "externalSymbol": "", - "ibcChannelId": "", - "ibcCounterpartyChainId": "", - "ibcCounterpartyChannelId": "", - "ibcCounterpartyDenom": "", - "network": "", - "path": "", - "permissions": [], - "transferLimit": "", - "unitDenom": "" - }, - { - "address": "", - "authority": "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", - "baseDenom": "cusdc", - "decimals": "6", - "denom": "cusdc", - "displayName": "USDC", - "displaySymbol": "", - "externalSymbol": "", - "ibcChannelId": "", - "ibcCounterpartyChainId": "", - "ibcCounterpartyChannelId": "", - "ibcCounterpartyDenom": "", - "network": "", - "path": "", - "permissions": [], - "transferLimit": "", - "unitDenom": "" - }, - { - "address": "", - "authority": "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", - "baseDenom": "ueden", - "decimals": "18", - "denom": "ueden", - "displayName": "EDEN", - "displaySymbol": "", - "externalSymbol": "", - "ibcChannelId": "", - "ibcCounterpartyChainId": "", - "ibcCounterpartyChannelId": "", - "ibcCounterpartyDenom": "", - "network": "", - "path": "", - "permissions": [], - "transferLimit": "", - "unitDenom": "" - } - ], - "params": {} - }, - "auth": { - "params": { - "max_memo_characters": "256", - "tx_sig_limit": "7", - "tx_size_cost_per_byte": "10", - "sig_verify_cost_ed25519": "590", - "sig_verify_cost_secp256k1": "1000" - }, - "accounts": [ - { - "@type": "/cosmos.auth.v1beta1.BaseAccount", - "address": "elys1gpv36nyuw5a92hehea3jqaadss9smsqscr3lrp", - "pub_key": null, - "account_number": "0", - "sequence": "0" - }, - { - "@type": "/cosmos.auth.v1beta1.BaseAccount", - "address": "elys1arm80rgjzlczm526hs3eam6g3sjgz5r7snw9em", - "pub_key": null, - "account_number": "0", - "sequence": "0" - }, - { - "@type": "/cosmos.auth.v1beta1.BaseAccount", - "address": "elys1ch0eyje2nd4t865fgqza3re27t27lcvzx2q9f6", - "pub_key": null, - "account_number": "0", - "sequence": "0" - }, - { - "@type": "/cosmos.auth.v1beta1.BaseAccount", - "address": "elys1hcsm79x44af4eqxr79aua52tf9k33krkk087s7", - "pub_key": null, - "account_number": "0", - "sequence": "0" - }, - { - "@type": "/cosmos.auth.v1beta1.BaseAccount", - "address": "elys17wc3s7am5qgjk4pm0k96kg6laxq8hkyq8dfafd", - "pub_key": null, - "account_number": "0", - "sequence": "0" - }, - { - "@type": "/cosmos.auth.v1beta1.BaseAccount", - "address": "elys1cduy8wep22mdnsmml8w9gn94ek8hqnsdpf0jce", - "pub_key": null, - "account_number": "0", - "sequence": "0" - }, - { - "@type": "/cosmos.auth.v1beta1.BaseAccount", - "address": "elys1f0nduqlxdwyw9dc45c0lfmt237qpqdcepyuns6", - "pub_key": null, - "account_number": "0", - "sequence": "0" - }, - { - "@type": "/cosmos.auth.v1beta1.BaseAccount", - "address": "elys1ng8sen6z5xzcfjtyrsedpe43hglymq048x69us", - "pub_key": null, - "account_number": "0", - "sequence": "0" - } - ] - }, - "authz": { - "authorization": [] - }, - "bank": { - "params": { - "send_enabled": [], - "default_send_enabled": true - }, - "balances": [ - { - "address": "elys1gpv36nyuw5a92hehea3jqaadss9smsqscr3lrp", - "coins": [ - { - "denom": "ueden", - "amount": "25000000000000" - }, - { - "denom": "uelys", - "amount": "25000000000000" - } - ] - }, - { - "address": "elys1f0nduqlxdwyw9dc45c0lfmt237qpqdcepyuns6", - "coins": [ - { - "denom": "uelys", - "amount": "25000000000000" - } - ] - }, - { - "address": "elys1ng8sen6z5xzcfjtyrsedpe43hglymq048x69us", - "coins": [ - { - "denom": "uelys", - "amount": "25000000000000" - } - ] - }, - { - "address": "elys1hcsm79x44af4eqxr79aua52tf9k33krkk087s7", - "coins": [ - { - "denom": "ueden", - "amount": "25000000000000" - }, - { - "denom": "uelys", - "amount": "25000000000000" - } - ] - }, - { - "address": "elys1cduy8wep22mdnsmml8w9gn94ek8hqnsdpf0jce", - "coins": [ - { - "denom": "uelys", - "amount": "25000000000000" - } - ] - }, - { - "address": "elys1ch0eyje2nd4t865fgqza3re27t27lcvzx2q9f6", - "coins": [ - { - "denom": "ueden", - "amount": "25000000000000" - }, - { - "denom": "uelys", - "amount": "25000000000000" - } - ] - }, - { - "address": "elys1arm80rgjzlczm526hs3eam6g3sjgz5r7snw9em", - "coins": [ - { - "denom": "ueden", - "amount": "25000000000000" - }, - { - "denom": "uelys", - "amount": "25000000000000" - } - ] - }, - { - "address": "elys17wc3s7am5qgjk4pm0k96kg6laxq8hkyq8dfafd", - "coins": [ - { - "denom": "uelys", - "amount": "25000000000000" - } - ] - } - ], - "supply": [], - "denom_metadata": [ - { - "description": "Native Elys token definition", - "denom_units": [ - { - "denom": "uelys", - "exponent": 0, - "aliases": ["microelys"] - }, - { - "denom": "melys", - "exponent": 3, - "aliases": ["millielys"] - }, - { - "denom": "elys", - "exponent": 6, - "aliases": [] - } - ], - "base": "uelys", - "display": "elys", - "name": "elys", - "symbol": "elys", - "uri": "", - "uri_hash": "" - }, - { - "description": "Eden token definition", - "denom_units": [ - { - "denom": "ueden", - "exponent": 0, - "aliases": ["microeden"] - }, - { - "denom": "meden", - "exponent": 3, - "aliases": ["millieden"] - }, - { - "denom": "eden", - "exponent": 6, - "aliases": [] - } - ], - "base": "ueden", - "display": "eden", - "name": "eden", - "symbol": "eden", - "uri": "", - "uri_hash": "" - } - ] - }, - "capability": { - "index": "1", - "owners": [] - }, - "commitment": { - "params": { - "vesting_infos": [ - { - "base_denom": "ueden", - "epoch_identifier": "tenseconds", - "num_epochs": "10", - "vest_now_factor": "90", - "vesting_denom": "uelys" - } - ] - } - }, - "crisis": { - "constant_fee": { - "amount": "1000", - "denom": "uelys" - } - }, - "distribution": { - "delegator_starting_infos": [], - "delegator_withdraw_infos": [], - "fee_pool": { - "community_pool": [] - }, - "outstanding_rewards": [], - "params": { - "base_proposer_reward": "0.010000000000000000", - "bonus_proposer_reward": "0.040000000000000000", - "community_tax": "0.020000000000000000", - "withdraw_addr_enabled": true - }, - "previous_proposer": "", - "validator_accumulated_commissions": [], - "validator_current_rewards": [], - "validator_historical_rewards": [], - "validator_slash_events": [] - }, - "epochs": { - "epochs": [ - { - "currentEpoch": "0", - "currentEpochStartHeight": "0", - "duration": "168h", - "epochCountingStarted": false, - "identifier": "week" - }, - { - "currentEpoch": "0", - "currentEpochStartHeight": "0", - "duration": "24h", - "epochCountingStarted": false, - "identifier": "day" - }, - { - "currentEpoch": "0", - "currentEpochStartHeight": "0", - "duration": "1h", - "epochCountingStarted": false, - "identifier": "hour" - }, - { - "currentEpoch": "0", - "currentEpochStartHeight": "0", - "duration": "15s", - "epochCountingStarted": false, - "identifier": "band_epoch" - }, - { - "currentEpoch": "0", - "currentEpochStartHeight": "0", - "duration": "10s", - "epochCountingStarted": false, - "identifier": "tenseconds" - } - ] - }, - "evidence": { - "evidence": [] - }, - "feegrant": { - "allowances": [] - }, - "genutil": { - "gen_txs": [ - { - "body": { - "messages": [ - { - "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", - "description": { - "moniker": "shangrila", - "identity": "", - "website": "", - "security_contact": "", - "details": "" - }, - "commission": { - "rate": "0.100000000000000000", - "max_rate": "0.200000000000000000", - "max_change_rate": "0.010000000000000000" - }, - "min_self_delegation": "1", - "delegator_address": "elys17wc3s7am5qgjk4pm0k96kg6laxq8hkyq8dfafd", - "validator_address": "elysvaloper17wc3s7am5qgjk4pm0k96kg6laxq8hkyq0dzq5n", - "pubkey": { - "@type": "/cosmos.crypto.ed25519.PubKey", - "key": "BgGtbLzJNrHAOaUTpynWWUebzfEy088Dv02bs+YWNwU=" - }, - "value": { - "denom": "uelys", - "amount": "25000000000000" - } - } - ], - "memo": "86987eeff225699e67a6543de3622b8a986cce28@192.168.1.145:26656", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [ - { - "public_key": { - "@type": "/cosmos.crypto.secp256k1.PubKey", - "key": "AmSf4iYeyTD9T9e8ni8pqoPtPgJOkJ+2UI2dNqXyWQgw" - }, - "mode_info": { - "single": { - "mode": "SIGN_MODE_DIRECT" - } - }, - "sequence": "0" - } - ], - "fee": { - "amount": [], - "gas_limit": "200000", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [ - "TkM+24t8xnfUh+7N1gfs6yYbGbUskHj8jvTxK9xSy1dH77Dqu+yN8vzs6Y43HsN8qNGX0tJRwI98x1qXDFpotw==" - ] - }, - { - "body": { - "messages": [ - { - "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", - "description": { - "moniker": "euphoria", - "identity": "", - "website": "", - "security_contact": "", - "details": "" - }, - "commission": { - "rate": "0.100000000000000000", - "max_rate": "0.200000000000000000", - "max_change_rate": "0.010000000000000000" - }, - "min_self_delegation": "1", - "delegator_address": "elys1cduy8wep22mdnsmml8w9gn94ek8hqnsdpf0jce", - "validator_address": "elysvaloper1cduy8wep22mdnsmml8w9gn94ek8hqnsdffy098", - "pubkey": { - "@type": "/cosmos.crypto.ed25519.PubKey", - "key": "7oLaVT6iTH0zFHbQm12hLBdLm0sV9aVjQUou86mkLOc=" - }, - "value": { - "denom": "uelys", - "amount": "25000000000000" - } - } - ], - "memo": "61284a4d71cd3a33771640b42f40b2afda389a1e@5.101.138.254:26656", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [ - { - "public_key": { - "@type": "/cosmos.crypto.secp256k1.PubKey", - "key": "AtxEnc63zunFVfE0gNRjtAPm50pbZHMD/6lwTSgrSM+J" - }, - "mode_info": { - "single": { - "mode": "SIGN_MODE_DIRECT" - } - }, - "sequence": "0" - } - ], - "fee": { - "amount": [], - "gas_limit": "200000", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [ - "qNasuN80IcJ7wWrpriVUlZAIG9VEpQy7zkU+PjYHTEpJORYI5TWg7YyjvRGDCPviyhCmagbdpeg7IJ6+npe/xw==" - ] - }, - { - "body": { - "messages": [ - { - "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", - "description": { - "moniker": "utopia", - "identity": "", - "website": "", - "security_contact": "", - "details": "" - }, - "commission": { - "rate": "0.100000000000000000", - "max_rate": "0.200000000000000000", - "max_change_rate": "0.010000000000000000" - }, - "min_self_delegation": "1", - "delegator_address": "elys1f0nduqlxdwyw9dc45c0lfmt237qpqdcepyuns6", - "validator_address": "elysvaloper1f0nduqlxdwyw9dc45c0lfmt237qpqdcefyhwdy", - "pubkey": { - "@type": "/cosmos.crypto.ed25519.PubKey", - "key": "CKlVp8qJZaFtUQDy0wZ7f3mOKW3XZagw5og+kLb/GXA=" - }, - "value": { - "denom": "uelys", - "amount": "25000000000000" - } - } - ], - "memo": "ae22b82b1dc34fa0b1a64854168692310f562136@198.27.74.140:26656", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [ - { - "public_key": { - "@type": "/cosmos.crypto.secp256k1.PubKey", - "key": "A88QIXKW3V9N+XswYjDbrg+y1qTz3XPm/hA8vGKOhvJi" - }, - "mode_info": { - "single": { - "mode": "SIGN_MODE_DIRECT" - } - }, - "sequence": "0" - } - ], - "fee": { - "amount": [], - "gas_limit": "200000", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [ - "GqqBL1wPV4I/uTfkfUCMl5v8Uev1e9V5pYev9AkFn/BfIxil5eSXPwlcsepOj6aS6At7xs106BkxYcH1h6LSNg==" - ] - }, - { - "body": { - "messages": [ - { - "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", - "description": { - "moniker": "nirvana", - "identity": "", - "website": "", - "security_contact": "", - "details": "" - }, - "commission": { - "rate": "0.100000000000000000", - "max_rate": "0.200000000000000000", - "max_change_rate": "0.010000000000000000" - }, - "min_self_delegation": "1", - "delegator_address": "elys1ng8sen6z5xzcfjtyrsedpe43hglymq048x69us", - "validator_address": "elysvaloper1ng8sen6z5xzcfjtyrsedpe43hglymq040x3cpw", - "pubkey": { - "@type": "/cosmos.crypto.ed25519.PubKey", - "key": "fobiFP2mhB3xoB4uZkte5mo6yegTka7+o55tidSiNeY=" - }, - "value": { - "denom": "uelys", - "amount": "25000000000000" - } - } - ], - "memo": "cdf9ae8529aa00e6e6703b28f3dcfdd37e07b27c@37.187.154.66:26656", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [ - { - "public_key": { - "@type": "/cosmos.crypto.secp256k1.PubKey", - "key": "A0pQu7cWsY/8jrRhwwt9KoRv91gen3NjbQh9A3roTWkV" - }, - "mode_info": { - "single": { - "mode": "SIGN_MODE_DIRECT" - } - }, - "sequence": "0" - } - ], - "fee": { - "amount": [], - "gas_limit": "200000", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [ - "qSkYZwmnBgt81Izx6SxSIqDpF4TwEVzbxJlviIKws2lgxDr/Eg40XguUspwErG7GNAkWJ0qCT4cR/YuIt5jesQ==" - ] - } - ] - }, - "gov": { - "deposit_params": { - "max_deposit_period": "60s", - "min_deposit": [ - { - "amount": "10000000", - "denom": "uelys" - } - ] - }, - "deposits": [], - "proposals": [], - "starting_proposal_id": "1", - "tally_params": { - "quorum": "0.334000000000000000", - "threshold": "0.500000000000000000", - "veto_threshold": "0.334000000000000000" - }, - "votes": [], - "voting_params": { - "voting_period": "60s" - } - }, - "group": { - "group_members": [], - "group_policies": [], - "group_policy_seq": "0", - "group_seq": "0", - "groups": [], - "proposal_seq": "0", - "proposals": [], - "votes": [] - }, - "ibc": { - "channel_genesis": { - "ack_sequences": [], - "acknowledgements": [], - "channels": [], - "commitments": [], - "next_channel_sequence": "0", - "receipts": [], - "recv_sequences": [], - "send_sequences": [] - }, - "client_genesis": { - "clients": [], - "clients_consensus": [], - "clients_metadata": [], - "create_localhost": false, - "next_client_sequence": "0", - "params": { - "allowed_clients": ["06-solomachine", "07-tendermint"] - } - }, - "connection_genesis": { - "client_connection_paths": [], - "connections": [], - "next_connection_sequence": "0", - "params": { - "max_expected_time_per_block": "30000000000" - } - } - }, - "interchainaccounts": { - "controller_genesis_state": { - "active_channels": [], - "interchain_accounts": [], - "params": { - "controller_enabled": true - }, - "ports": [] - }, - "host_genesis_state": { - "active_channels": [], - "interchain_accounts": [], - "params": { - "allow_messages": ["*"], - "host_enabled": true - }, - "port": "icahost" - } - }, - "mint": { - "minter": { - "annual_provisions": "0.000000000000000000", - "inflation": "0.130000000000000000" - }, - "params": { - "blocks_per_year": "6311520", - "goal_bonded": "0.670000000000000000", - "inflation_max": "0.2", - "inflation_min": "0.07", - "inflation_rate_change": "0.07", - "mint_denom": "uelys" - } - }, - "oracle": { - "assetInfos": [], - "params": { - "ask_count": "4", - "band_channel_source": "channel-0", - "band_epoch": "band_epoch", - "client_id": "band_price_id", - "execute_gas": "600000", - "fee_limit": [ - { - "amount": "30", - "denom": "uband" - } - ], - "min_count": "3", - "module_admin": "elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w", - "multiplier": "18", - "oracle_script_id": "37", - "prepare_gas": "600000", - "price_expiry_time": "86400" - }, - "portId": "oracle", - "priceFeeders": [], - "prices": [] - }, - "params": null, - "slashing": { - "missed_blocks": [], - "params": { - "downtime_jail_duration": "600s", - "min_signed_per_window": "0.5", - "signed_blocks_window": "10000", - "slash_fraction_double_sign": "0.05", - "slash_fraction_downtime": "0.0001" - }, - "signing_infos": [] - }, - "staking": { - "delegations": [], - "exported": false, - "last_total_power": "0", - "last_validator_powers": [], - "params": { - "bond_denom": "uelys", - "historical_entries": 10000, - "max_entries": 7, - "max_validators": 100, - "min_commission_rate": "0.000000000000000000", - "unbonding_time": "1209600s" - }, - "redelegations": [], - "unbonding_delegations": [], - "validators": [] - }, - "tokenomics": { - "airdropList": [ - { - "amount": 9999999, - "authority": "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", - "intent": "AtomStakers" - }, - { - "amount": 9999999, - "authority": "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", - "intent": "RowanStakersLP" - }, - { - "amount": 9999999, - "authority": "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", - "intent": "Juno" - }, - { - "amount": 9999999, - "authority": "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", - "intent": "Osmo" - }, - { - "amount": 9999999, - "authority": "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", - "intent": "Evmos" - } - ], - "genesisInflation": { - "authority": "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", - "inflation": { - "communityFund": 9999999, - "icsStakingRewards": 9999999, - "lmRewards": 9999999, - "strategicReserve": 9999999, - "teamTokensVested": 9999999 - }, - "seedVesting": 9999999, - "strategicSalesVesting": 9999999 - }, - "params": {}, - "timeBasedInflationList": [ - { - "description": "1st Year Inflation", - "endBlockHeight": 6307200, - "inflation": { - "communityFund": 9999999, - "icsStakingRewards": 9999999, - "lmRewards": 9999999, - "strategicReserve": 9999999, - "teamTokensVested": 9999999 - }, - "startBlockHeight": 1 - }, - { - "description": "2nd Year Inflation", - "endBlockHeight": 12614401, - "inflation": { - "communityFund": 9999999, - "icsStakingRewards": 9999999, - "lmRewards": 9999999, - "strategicReserve": 9999999, - "teamTokensVested": 9999999 - }, - "startBlockHeight": 6307201 - }, - { - "description": "3rd Year Inflation", - "endBlockHeight": 18921602, - "inflation": { - "communityFund": 9999999, - "icsStakingRewards": 9999999, - "lmRewards": 9999999, - "strategicReserve": 9999999, - "teamTokensVested": 9999999 - }, - "startBlockHeight": 12614402 - } - ] - }, - "transfer": { - "denom_traces": [], - "params": { - "receive_enabled": true, - "send_enabled": true - }, - "port_id": "transfer" - }, - "upgrade": {}, - "vesting": {}, - "monitoringp": { - "params": { - "consumerUnbondingPeriod": 1814400, - "consumerRevisionHeight": 342442, - "consumerChainID": "spn-1", - "lastBlockHeight": 1, - "consumerConsensusState": { - "timestamp": "2023-04-10T18:42:00.127873353Z", - "nextValidatorsHash": "6C4F396575BACAFA414FC2FF164DDE5EDDFEF81926C60315D3CE1DECF21A0F26", - "root": { "hash": "hyT/XmcfP/nXMLZa+/oiDCTJ78pABleHqDpvnII+fU8=" } - } - } - } - } -} diff --git a/chain/readme.md b/chain/readme.md deleted file mode 100644 index 2cb040b06..000000000 --- a/chain/readme.md +++ /dev/null @@ -1,5 +0,0 @@ -This is a temporary directory for chain information for validator setup. it will be moved to the appropriate repository - -Contents: - -genesis.json diff --git a/config.yml b/config.yml deleted file mode 100644 index 9e9dc0928..000000000 --- a/config.yml +++ /dev/null @@ -1,455 +0,0 @@ -version: 1 -accounts: - - name: treasury - coins: - - 1000000000000uatom - - 1000000000000uinc - - 1000000000000uusdc - - 1000000000000uusdt - - 9000000000000000uelys - - 100000000ueden - mnemonic: olympic slide park figure frost benefit deer reform fly pull price airport submit monitor silk insect uphold convince pupil project ignore roof warfare slight - - name: seed - coins: - - 9000000000000000uelys - - name: cw - coins: - - 1000000000000uatom - - 9000000000000000uelys - - 1000000000000uusdc - - 1000000000000uusdt - mnemonic: wool diet nasty illness balcony life grunt truck verify later raise carpet describe victory snack sand struggle better smart purse miss bicycle copy orphan -build: - main: cmd/elysd -client: - openapi: - path: docs/static/openapi.yml -faucet: - name: seed - coins: - - 1000000000000000uelys -validators: - - name: treasury - bonded: 100000000uelys -genesis: - app_state: - crisis: - constant_fee: - denom: uelys - gov: - deposit_params: - max_deposit_period: 20s - min_deposit: - - amount: "10000000" - denom: uelys - params: - burn_proposal_deposit_prevote: false - burn_vote_quorum: false - burn_vote_veto: true - max_deposit_period: 20s - min_deposit: - - amount: "10000000" - denom: uelys - min_initial_deposit_ratio: "0.000000000000000000" - quorum: "0.334000000000000000" - threshold: "0.500000000000000000" - veto_threshold: "0.334000000000000000" - voting_period: 20s - tally_params: - quorum: "0.334000000000000000" - threshold: "0.500000000000000000" - veto_threshold: "0.334000000000000000" - voting_params: - voting_period: 20s - mint: - params: - mint_denom: uelys - inflation_rate_change: "0.0" - inflation_max: "0.0" - inflation_min: "0.0" - slashing: - params: - signed_blocks_window: "30000" - min_signed_per_window: "0.05" - downtime_jail_duration: 600s - slash_fraction_double_sign: "0.05" - slash_fraction_downtime: "0.0001" - staking: - params: - bond_denom: uelys - unbonding_time: 1209600s - estaking: - params: - eden_commit_val: "" - edenb_commit_val: "" - max_eden_reward_apr_stakers: "0.3" - eden_boost_apr: "1.0" - bank: - denom_metadata: - - base: uelys - denom_units: - - denom: uelys - exponent: 0 - aliases: - - microelys - - denom: melys - exponent: 3 - aliases: - - millielys - - denom: elys - exponent: 6 - aliases: [] - name: elys - symbol: elys - description: Native Elys token definition - display: elys - - base: ueden - denom_units: - - denom: ueden - exponent: 0 - aliases: - - microeden - - denom: meden - exponent: 3 - aliases: - - millieden - - denom: eden - exponent: 6 - aliases: [] - name: eden - symbol: eden - description: Eden token definition - display: eden - balances: - - address: elys1w9uac4zrf9z7qd604qxk2y4n74568lfl8vutz4 - coins: - - amount: "1000000000" - denom: uatom - - amount: "1000000000" - denom: ueden - - amount: "1000000000" - denom: uelys - - amount: "1000000000" - denom: uusdc - assetprofile: - entryList: - - address: "" - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - baseDenom: uelys - decimals: "6" - denom: uelys - displayName: ELYS - displaySymbol: "" - externalSymbol: "" - ibcChannelId: "" - ibcCounterpartyChainId: "" - ibcCounterpartyChannelId: "" - ibcCounterpartyDenom: "" - network: "" - path: "" - permissions: [] - transferLimit: "" - unitDenom: "" - commitEnabled: false - withdrawEnabled: true - - address: "" - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - baseDenom: uusdc - decimals: "6" - denom: uusdc - displayName: USDC - displaySymbol: "" - externalSymbol: "" - ibcChannelId: "" - ibcCounterpartyChainId: "" - ibcCounterpartyChannelId: "" - ibcCounterpartyDenom: "" - network: "" - path: "" - permissions: [] - transferLimit: "" - unitDenom: "" - commitEnabled: false - withdrawEnabled: true - - address: "" - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - baseDenom: ueden - decimals: "6" - denom: ueden - displayName: EDEN - displaySymbol: "" - externalSymbol: "" - ibcChannelId: "" - ibcCounterpartyChainId: "" - ibcCounterpartyChannelId: "" - ibcCounterpartyDenom: "" - network: "" - path: "" - permissions: [] - transferLimit: "" - unitDenom: "" - commitEnabled: true - withdrawEnabled: true - - address: "" - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - baseDenom: uedenb - decimals: "6" - denom: uedenb - displayName: EDEN-BOOST - displaySymbol: "" - externalSymbol: "" - ibcChannelId: "" - ibcCounterpartyChainId: "" - ibcCounterpartyChannelId: "" - ibcCounterpartyDenom: "" - network: "" - path: "" - permissions: [] - transferLimit: "" - unitDenom: "" - commitEnabled: true - withdrawEnabled: true - epochs: - epochs: - - identifier: week - duration: "168h" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: day - duration: "24h" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: twelvehours - duration: "12h" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: sixhours - duration: "6h" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: fourhours - duration: "4h" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: twohours - duration: "2h" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: hour - duration: "1h" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: halfhour - duration: "30m" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: band_epoch - duration: "15s" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: tenseconds - duration: "10s" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - commitment: - params: - vesting_infos: - - base_denom: ueden - vesting_denom: uelys - num_blocks: "100" - vest_now_factor: "90" - num_max_vestings: "10" - commitments: - - creator: elys1v30pe777dj9mgsnlv0j2c5wh05m0ya0nlhuv7t - committed_tokens: - - amount: "10000" - denom: ueden - - amount: "10000" - denom: uedenb - vesting_tokens: [] - tokenomics: - airdropList: - - intent: AtomStakers - amount: 9999999000000 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - - intent: RowanStakersLP - amount: 9999999000000 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - - intent: Juno - amount: 9999999000000 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - - intent: Osmo - amount: 9999999000000 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - - intent: Evmos - amount: 9999999000000 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - genesisInflation: - inflation: - lmRewards: 9999999000000 - icsStakingRewards: 9999999000000 - communityFund: 9999999000000 - strategicReserve: 9999999000000 - teamTokensVested: 9999999000000 - seedVesting: 9999999000000 - strategicSalesVesting: 9999999000000 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - timeBasedInflationList: - - startBlockHeight: 1 - endBlockHeight: 6307200 - description: 1st Year Inflation - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - inflation: - lmRewards: 9999999000000 - icsStakingRewards: 9999999000000 - communityFund: 9999999000000 - strategicReserve: 9999999000000 - teamTokensVested: 9999999000000 - - startBlockHeight: 6307201 - endBlockHeight: 12614401 - description: 2nd Year Inflation - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - inflation: - lmRewards: 9999999000000 - icsStakingRewards: 9999999000000 - communityFund: 9999999000000 - strategicReserve: 9999999000000 - teamTokensVested: 9999999000000 - - startBlockHeight: 12614402 - endBlockHeight: 18921602 - description: 3rd Year Inflation - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - inflation: - lmRewards: 9999999000000 - icsStakingRewards: 9999999000000 - communityFund: 9999999000000 - strategicReserve: 9999999000000 - teamTokensVested: 9999999000000 - oracle: - assetInfos: - - denom: "satoshi" - display: "BTC" - bandTicker: "BTC" - elysTicker: "BTC" - decimal: 9 - - denom: "wei" - display: "ETH" - bandTicker: "ETH" - elysTicker: "ETH" - decimal: 18 - - denom: "uatom" - display: "ATOM" - bandTicker: "ATOM" - elysTicker: "ATOM" - decimal: 6 - - denom: "uusdt" - display: "USDT" - bandTicker: "USDT" - elysTicker: "USDT" - decimal: 6 - - denom: "uusdc" - display: "USDC" - bandTicker: "USDC" - elysTicker: "USDC" - decimal: 6 - params: - ask_count: "4" - band_channel_source: "channel-0" - band_epoch: "band_epoch" - client_id: "band_price_id" - execute_gas: "600000" - fee_limit: - - amount: "30" - denom: "uband" - min_count: "3" - multiplier: "18" - oracle_script_id: "37" - prepare_gas: "600000" - price_expiry_time: "8640000000" - life_time_in_blocks: "1000000000" - portId: "oracle" - priceFeeders: - - feeder: "elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w" - is_active: true - - feeder: "elys1v30pe777dj9mgsnlv0j2c5wh05m0ya0nlhuv7t" - is_active: true - prices: - - asset: USDT - price: "1.00" - provider: elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w - source: elys - timestamp: "1694743319" - - asset: USDC - price: "1.00" - provider: elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w - source: elys - timestamp: "1694743319" - - asset: ATOM - price: "10.00" - provider: elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w - source: elys - timestamp: "1694743319" - burner: - params: - epochIdentifier: day - historyList: - - timestamp: "2023-04-21 14:57:03.612566186 +0000 UTC" - denom: "uelys" - amount: "1000000" - - timestamp: "2023-04-21 14:57:03.612566186 +0000 UTC" - denom: "ueden" - amount: "1000000" - parameter: - params: - min_commission_rate: "0.05" - max_voting_power: "1.00" - min_self_delegation: "1" - perpetual: - params: - leverage_max: "10" - borrow_interest_rate_max: "0.00000027" - borrow_interest_rate_min: "0.00000003" - borrow_interest_rate_increase: "0.000000000333333333" - borrow_interest_rate_decrease: "0.000000000333333333" - health_gain_factor: "0.000000022" - epoch_length: 1 - max_open_positions: 9999 - pool_open_threshold: "0.65" - force_close_fund_percentage: "1.0" - force_close_fund_address: "elys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrec2l" - incremental_borrow_interest_payment_fund_percentage: "0.35" - incremental_borrow_interest_payment_fund_address: "elys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrec2l" - safety_factor: "1.05" - incremental_borrow_interest_payment_enabled: true - whitelisting_enabled: false - invariant_check_epoch: day - take_profit_borrow_interest_rate_min: "0.00000003" - funding_fee_base_rate: "0.0003" - funding_fee_max_rate: "0.001" - funding_fee_min_rate: "-0.001" - funding_fee_collection_address: "elys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrec2l" - swap_fee: "0.001" - max_limit_order: 500 - stablestake: - params: - deposit_denom: "uusdc" - redemption_rate: "1.000000000000000000" - masterchef: - params: - supported_reward_denoms: - - denom: "uinc" - min_amount: "1000000" - reward_portion_for_lps: "0.6" - max_eden_reward_apr_lps: "0.5" - protocol_revenue_address: "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3" - chain_id: elystestnet-1 diff --git a/configs/testnet.yml b/configs/testnet.yml deleted file mode 100644 index d800bc63d..000000000 --- a/configs/testnet.yml +++ /dev/null @@ -1,240 +0,0 @@ -version: 1 -accounts: - - name: nirvana - address: elys1gpv36nyuw5a92hehea3jqaadss9smsqscr3lrp - coins: - - 25000000000000uelys - - 25000000000000ueden - - name: utopia - address: elys1arm80rgjzlczm526hs3eam6g3sjgz5r7snw9em - coins: - - 25000000000000uelys - - 25000000000000ueden - - name: shangrila - address: elys1ch0eyje2nd4t865fgqza3re27t27lcvzx2q9f6 - coins: - - 25000000000000uelys - - 25000000000000ueden - - name: euphoria - address: elys1hcsm79x44af4eqxr79aua52tf9k33krkk087s7 - coins: - - 25000000000000uelys - - 25000000000000ueden -client: - openapi: - path: docs/static/openapi.yml -faucet: - name: nirvana - coins: - - 10000000000000uelys - - 10000000000000ueden -genesis: - app_state: - crisis: - constant_fee: - denom: uelys - gov: - deposit_params: - max_deposit_period: 60s - min_deposit: - - amount: "10000000" - denom: uelys - voting_params: - voting_period: 60s - mint: - params: - mint_denom: uelys - inflation_rate_change: "0.0" - inflation_max: "0.0" - inflation_min: "0.0" - slashing: - params: - signed_blocks_window: "30000" - min_signed_per_window: "0.05" - downtime_jail_duration: 600s - slash_fraction_double_sign: "0.05" - slash_fraction_downtime: "0.0001" - staking: - params: - bond_denom: uelys - unbonding_time: 1209600s - bank: - denom_metadata: - - base: uelys - denom_units: - - denom: uelys - exponent: 0 - aliases: - - microelys - - denom: melys - exponent: 3 - aliases: - - millielys - - denom: elys - exponent: 6 - aliases: [] - name: elys - symbol: elys - description: Native Elys token definition - display: elys - - base: ueden - denom_units: - - denom: ueden - exponent: 0 - aliases: - - microeden - - denom: meden - exponent: 3 - aliases: - - millieden - - denom: eden - exponent: 6 - aliases: [] - name: eden - symbol: eden - description: Eden token definition - display: eden - assetprofile: - entryList: - - address: "" - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - baseDenom: uelys - decimals: "18" - denom: uelys - displayName: ELYS - displaySymbol: "" - externalSymbol: "" - ibcChannelId: "" - ibcCounterpartyChainId: "" - ibcCounterpartyChannelId: "" - ibcCounterpartyDenom: "" - network: "" - path: "" - permissions: [] - transferLimit: "" - unitDenom: "" - - address: "" - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - baseDenom: cusdc - decimals: "6" - denom: cusdc - displayName: USDC - displaySymbol: "" - externalSymbol: "" - ibcChannelId: "" - ibcCounterpartyChainId: "" - ibcCounterpartyChannelId: "" - ibcCounterpartyDenom: "" - network: "" - path: "" - permissions: [] - transferLimit: "" - unitDenom: "" - - address: "" - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - baseDenom: ueden - decimals: "18" - denom: ueden - displayName: EDEN - displaySymbol: "" - externalSymbol: "" - ibcChannelId: "" - ibcCounterpartyChainId: "" - ibcCounterpartyChannelId: "" - ibcCounterpartyDenom: "" - network: "" - path: "" - permissions: [] - transferLimit: "" - unitDenom: "" - epochs: - epochs: - - identifier: week - duration: "168h" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: day - duration: "24h" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: hour - duration: "1h" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: band_epoch - duration: "15s" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - - identifier: tenseconds - duration: "10s" - currentEpoch: "0" - currentEpochStartHeight: "0" - epochCountingStarted: false - commitment: - params: - vesting_infos: - - base_denom: ueden - vesting_denom: uelys - epoch_identifier: tenseconds - num_epochs: "10" - vest_now_factor: "90" - tokenomics: - airdropList: - - intent: AtomStakers - amount: 9999999 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - - intent: RowanStakersLP - amount: 9999999 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - - intent: Juno - amount: 9999999 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - - intent: Osmo - amount: 9999999 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - - intent: Evmos - amount: 9999999 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - genesisInflation: - inflation: - lmRewards: 9999999 - icsStakingRewards: 9999999 - communityFund: 9999999 - strategicReserve: 9999999 - teamTokensVested: 9999999 - seedVesting: 9999999 - strategicSalesVesting: 9999999 - authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 - timeBasedInflationList: - - startBlockHeight: 1 - endBlockHeight: 6307200 - description: 1st Year Inflation - inflation: - lmRewards: 9999999 - icsStakingRewards: 9999999 - communityFund: 9999999 - strategicReserve: 9999999 - teamTokensVested: 9999999 - - startBlockHeight: 6307201 - endBlockHeight: 12614401 - description: 2nd Year Inflation - inflation: - lmRewards: 9999999 - icsStakingRewards: 9999999 - communityFund: 9999999 - strategicReserve: 9999999 - teamTokensVested: 9999999 - - startBlockHeight: 12614402 - endBlockHeight: 18921602 - description: 3rd Year Inflation - inflation: - lmRewards: 9999999 - icsStakingRewards: 9999999 - communityFund: 9999999 - strategicReserve: 9999999 - teamTokensVested: 9999999 - chain_id: elystestnet-1 diff --git a/network.md b/network.md deleted file mode 100644 index 8e5ec0545..000000000 --- a/network.md +++ /dev/null @@ -1,151 +0,0 @@ -# Network Guide - -This section provides a step-by-step guide on how to launch a new network, such as a testnet, for Elys. The guide includes instructions on how to use Ignite commands to set up and configure the new network. - -
-Click to expand/collapse - -## Coordinator Configuration - -To publish the information about Elys chain as a coordinator, run the following command: - -``` -ignite network chain publish github.com/elys-network/elys --tag v0.1.0 --chain-id elystestnet-1 --account-balance 10000000000uelys -``` - -## Validator Configuration - -This documentation presupposes the validator node is currently operational on `Ubuntu 22.04.2 LTS`. - -### Prerequisites - -Before launching a validator node, a set of tools must be installed. - -To install the `build-essential` package, enter the following command: - -``` -sudo apt install build-essential -``` - -Install `go` version `1.20` - -``` -cd /tmp -wget https://go.dev/dl/go1.20.6.linux-amd64.tar.gz -sudo rm -rf /usr/local/go -sudo tar -C /usr/local -xzf go1.20.6.linux-amd64.tar.gz -``` - -Append the following line to the end of the `~/.bashrc` file: - -``` -export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin -``` - -Run the following command: - -``` -go version -``` - -This should return the following output: - -``` -go version go1.20.6 linux/amd64 -``` - -Install `ignite-cli` - -Enter the following command to install the `ignite-cli` command: - -``` -curl https://get.ignite.com/cli! | bash -``` - -Then run the following command: - -``` -ignite network -``` - -Install the latest version of Elys binary by running the following command: - -``` -curl https://get.ignite.com/elys-network/elys@latest! | sudo bash -``` - -Enter the following command to initialize the validator node and request to join the network: - -``` -ignite network chain init 12 -ignite network chain join 12 --amount 95000000uelys -``` - -The coordinator will then have to approve the validator requests with the following commands: - -``` -ignite network request list 12 -ignite network request approve 12 , -``` - -Once all the validators needed for the validator set are approved, to launch the chain use the following command: - -``` -ignite network chain launch 12 -``` - -Each validator is now ready to prepare their nodes for launch by using this command: - -``` -ignite network chain prepare 12 -``` - -The output of this command will show a command that a validator would use to launch their node such as: - -``` -elysd start --home $HOME/spn/12 2> elysd.log & -``` - -A systemd service can be created to auto-start the `elysd` service. - -Create the new file `/etc/systemd/system/elysd.service` with this content: - -``` -[Unit] -Description=Elysd Service -Wants=network.target -After=network.target - -[Service] -Environment=HOME=/home/ubuntu -Type=simple -Restart=on-failure -WorkingDirectory=/home/ubuntu -SyslogIdentifier=elysd.user-daemon -ExecStart=/home/ubuntu/go/bin/elysd start --home spn/12 2>&1 -ExecStop=/usr/bin/pkill elysd - -[Install] -WantedBy=multi-user.target -``` - -Then you can use those commands to enable and start the service: - -``` -sudo systemctl enable elysd.service -sudo systemctl start elysd.service -``` - -You can check the status of the service at any time using this command: - -``` -sudo systemctl status elysd.service -``` - -Or follow the service logs by using this command: - -``` -sudo journalctl -u elysd.service -f -``` - -
\ No newline at end of file diff --git a/readme.md b/readme.md index 59bc6f1fd..70ced8c55 100644 --- a/readme.md +++ b/readme.md @@ -2,13 +2,14 @@ **Elys** is a blockchain built using Cosmos SDK and CometBFT. It is designed to be a fast, scalable, and secure blockchain that can be used to build decentralized applications. -| Parameter | Value | -| ------------ | ------------------------------------------------------------------------ | -| Chain ID | elystestnet-1 | -| Denomination | uelys | -| Decimals | 6 (1 elys= 1000000uelys) | -| Version | [See latest version here](https://github.com/elys-network/elys/releases) | -| RPC Endpoint | https://rpc.testnet.elys.network:443 | +| Parameter | Value | +| -------------------- | ------------------------------------------------------------------------ | +| Chain Info | [See network details here](https://github.com/elys-network/networks) | +| Denomination | uelys | +| Decimals | 6 (1 elys= 1000000uelys) | +| Version | [See latest version here](https://github.com/elys-network/elys/releases) | +| TestNet RPC Endpoint | https://rpc.testnet.elys.network:443 | +| TestNet API Endpoint | https://api.testnet.elys.network:443 | ## Localnet Setup Guide @@ -89,9 +90,9 @@ sudo apt-get install --yes make In order to generate proto files, install the dependencies below: -* `buf` -* `clang-format` -* `protoc-gen-go-cosmos-orm`: `go install cosmossdk.io/orm/cmd/protoc-gen-go-cosmos-orm@latest` +- `buf` +- `clang-format` +- `protoc-gen-go-cosmos-orm`: `go install cosmossdk.io/orm/cmd/protoc-gen-go-cosmos-orm@latest` Then run the following command: @@ -162,40 +163,10 @@ You can also use the `make install` command to install the binary in the `bin` d -### With Ignite (Experimental) - -To install the latest version of Elys binary, execute the following command on your machine: - -``` -curl https://get.ignite.com/elys-network/elys@latest! | sudo bash -``` - -## Development - -You can use `ignite-cli` to get you started with your development environment. To install `ignite-cli`, execute the following command on your machine: - -``` -curl https://get.ignite.com/ignite/ignite-cli@latest! | sudo bash -``` - -### Initialize - -To initialize and serve your development environment, execute the following command: - -``` -ignite chain serve -r -``` - -`serve` command installs dependencies, builds, initializes, and starts Elys in development. The `-r` flag rebuilds the binary before starting the chain. - ## Validator Guide The validator guide is accessible [here](./validator.md). -## Network Launch - -The network guide is accessible [here](./network.md). - ## Architecture The architecture guide is accessible [here](./architecture.md). diff --git a/scripts/examples/amm/amm.sh b/scripts/examples/amm/amm.sh index 4f6c62c5b..d55f51ed5 100644 --- a/scripts/examples/amm/amm.sh +++ b/scripts/examples/amm/amm.sh @@ -2,15 +2,15 @@ TREASURY=$(elysd keys show -a treasury --keyring-backend=test) -elysd tx amm create-pool elysd tx amm create-pool 10uatom,10uusdt 10000uatom,10000uusdt --swap-fee=0.00 --exit-fee=0.00 --use-oracle=false --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm create-pool elysd tx amm create-pool 10uatom,10uusdt 10000uatom,10000uusdt --swap-fee=0.00 --exit-fee=0.00 --use-oracle=false --from=treasury --yes --gas=1000000 # single asset add-liquidity -elysd tx amm join-pool 1 2000uatom 90000000000000000 true --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm join-pool 1 2000uatom 90000000000000000 true --from=treasury --yes --gas=1000000 # multiple asset add-liquidity -elysd tx amm join-pool 1 2000uatom,2000uusdt 200000000000000000 true --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm join-pool 1 2000uatom,2000uusdt 200000000000000000 true --from=treasury --yes --gas=1000000 # swap -elysd tx amm swap-exact-amount-in 10uatom 1 1 uusdt --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm swap-exact-amount-in 10uatom 1 1 uusdt --from=treasury --yes --gas=1000000 elysd query commitment show-commitments $TREASURY elysd query bank balances $TREASURY diff --git a/scripts/examples/commitment/commitment.sh b/scripts/examples/commitment/commitment.sh index 14493d8da..8df458a77 100644 --- a/scripts/examples/commitment/commitment.sh +++ b/scripts/examples/commitment/commitment.sh @@ -14,5 +14,5 @@ elysd query commitment committed-tokens-locked $(elysd keys show -a treasury --k # - amount: "100000000" # denom: stablestake/share -elysd tx commitment commit-claimed-rewards 503544 ueden --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx commitment commit-claimed-rewards 1678547 uedenb --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 503544 ueden --from=treasury --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 1678547 uedenb --from=treasury --yes --gas=1000000 diff --git a/scripts/examples/estaking/estaking.sh b/scripts/examples/estaking/estaking.sh index 2e06c82ef..5c8b06e6a 100644 --- a/scripts/examples/estaking/estaking.sh +++ b/scripts/examples/estaking/estaking.sh @@ -12,20 +12,20 @@ VALIDATOR=elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs EDEN_VAL=elysvaloper1gnmpr8vvslp3shcq6e922xr0uq4aa2w5gdzht0 EDENB_VAL=elysvaloper1wajd6ekh9u37hyghyw4mme59qmjllzuyaceanm -elysd tx staking delegate $VALIDATOR 1000000000000uelys --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx staking delegate $VALIDATOR 1000000000000uelys --from=treasury --yes --gas=1000000 elysd query distribution rewards $TREASURY $VALIDATOR elysd query distribution rewards $TREASURY $EDEN_VAL elysd query distribution rewards $TREASURY $EDENB_VAL -elysd tx distribution withdraw-rewards $VALIDATOR --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx distribution withdraw-rewards $EDEN_VAL --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx distribution withdraw-rewards $EDENB_VAL --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx distribution withdraw-rewards $VALIDATOR --from=treasury --yes --gas=1000000 +elysd tx distribution withdraw-rewards $EDEN_VAL --from=treasury --yes --gas=1000000 +elysd tx distribution withdraw-rewards $EDENB_VAL --from=treasury --yes --gas=1000000 -elysd tx commitment commit-claimed-rewards 503544 ueden --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx commitment commit-claimed-rewards 1678547 uedenb --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 503544 ueden --from=treasury --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 1678547 uedenb --from=treasury --yes --gas=1000000 # Pay 10000 uusdc as gas fees -elysd tx staking delegate $VALIDATOR 1000uelys --fees=10000uusdc --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx staking delegate $VALIDATOR 1000uelys --fees=10000uusdc --from=treasury --yes --gas=1000000 elysd query estaking rewards $TREASURY -elysd tx estaking withdraw-all-rewards --from=validator --chain-id=elystestnet-1 +elysd tx estaking withdraw-all-rewards --from=validator diff --git a/scripts/examples/estaking/snapshot_test.sh b/scripts/examples/estaking/snapshot_test.sh index b37670052..61168df23 100644 --- a/scripts/examples/estaking/snapshot_test.sh +++ b/scripts/examples/estaking/snapshot_test.sh @@ -7,22 +7,22 @@ VALIDATOR=elysvaloper1dd34v384hdfqgajkg0jzp0y5k6qlvhltr73as2 EDEN_VAL=elysvaloper1gnmpr8vvslp3shcq6e922xr0uq4aa2w5gdzht0 EDENB_VAL=elysvaloper1wajd6ekh9u37hyghyw4mme59qmjllzuyaceanm -elysd tx staking delegate $VALIDATOR 10000000000000uelys --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx staking delegate $VALIDATOR 10000000000000uelys --from=validator --yes --gas=1000000 elysd query distribution rewards elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg $VALIDATOR elysd query distribution rewards elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg $EDEN_VAL elysd query distribution rewards elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg $EDENB_VAL -elysd tx estaking withdraw-all-rewards --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx estaking withdraw-all-rewards --from=validator --yes --gas=1000000 -elysd tx commitment commit-claimed-rewards 158762097 ueden --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx commitment commit-claimed-rewards 1066283235 uedenb --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx commitment uncommit-tokens 35235693 ueden --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx commitment commit-claimed-rewards 35235693 ueden --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx commitment uncommit-tokens 304152385 uedenb --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx commitment uncommit-tokens 70471386 ueden --from=validator --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 158762097 ueden --from=validator --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 1066283235 uedenb --from=validator --yes --gas=1000000 +elysd tx commitment uncommit-tokens 35235693 ueden --from=validator --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 35235693 ueden --from=validator --yes --gas=1000000 +elysd tx commitment uncommit-tokens 304152385 uedenb --from=validator --yes --gas=1000000 +elysd tx commitment uncommit-tokens 70471386 ueden --from=validator --yes --gas=1000000 elysd query commitment show-commitments elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg elysd query estaking rewards elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg -elysd tx estaking withdraw-all-rewards --from=validator --chain-id=elystestnet-1 +elysd tx estaking withdraw-all-rewards --from=validator elysd query incentive all-program-rewards elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg diff --git a/scripts/examples/incentive/incentive.sh b/scripts/examples/incentive/incentive.sh index afc2536d6..41cc32e0a 100644 --- a/scripts/examples/incentive/incentive.sh +++ b/scripts/examples/incentive/incentive.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash # Local test -elysd tx gov submit-proposal proposal.json --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx gov vote 1 Yes --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx gov submit-proposal proposal.json --from=treasury --yes --gas=1000000 +elysd tx gov vote 1 Yes --from=treasury --yes --gas=1000000 # Query pool daily rewards elysd query incentive pool-rewards "" diff --git a/scripts/examples/incentive/upgrade.sh b/scripts/examples/incentive/upgrade.sh index 3e890ff83..951ffb54f 100644 --- a/scripts/examples/incentive/upgrade.sh +++ b/scripts/examples/incentive/upgrade.sh @@ -2,28 +2,28 @@ # start old chain cd //elys -ignite chain serve --verbose --reset-once +elysd start # stake Elys token elysd query staking validators elysd keys add user1 --keyring-backend=test --recover # beef model palm pepper claim taste climb primary category gallery lava mimic future festival sign milk present toss basket reflect dignity frame scan hat -elysd tx bank send treasury elys1r8nfpk0t4g6r7542g99s8ymxwzpsg57alx7gue 1000000000000uelys --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes -elysd tx staking delegate elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs 100000000000uelys --from=user1 --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx bank send treasury elys1r8nfpk0t4g6r7542g99s8ymxwzpsg57alx7gue 1000000000000uelys --from=treasury --yes +elysd tx staking delegate elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs 100000000000uelys --from=user1 --yes --gas=1000000 # claim Eden reward and commit elysd keys show -a treasury --keyring-backend=test elysd query commitment show-commitments elys1r8nfpk0t4g6r7542g99s8ymxwzpsg57alx7gue -elysd tx incentive withdraw-rewards --from=user1 --keyring-backend=test --chain-id=elystestnet-1 --yes -elysd tx commitment commit-claimed-rewards 342464 ueden --from=user1 --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx incentive withdraw-rewards --from=user1 --yes +elysd tx commitment commit-claimed-rewards 342464 ueden --from=user1 --yes --gas=1000000 # create vesting from Eden to Elys -elysd tx commitment vest 1284240 ueden --from=user1 --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment vest 1284240 ueden --from=user1 --yes --gas=1000000 elysd query commitment show-commitments elys1r8nfpk0t4g6r7542g99s8ymxwzpsg57alx7gue # create liquidity pool -elysd tx amm create-pool 10uatom,10uusdc 100000000000uatom,10000000000uusdc --swap-fee=0.00 --exit-fee=0.00 --use-oracle=false --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx stablestake bond 19800000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm create-pool 10uatom,10uusdc 100000000000uatom,10000000000uusdc --swap-fee=0.00 --exit-fee=0.00 --use-oracle=false --from=treasury --yes --gas=1000000 +elysd tx stablestake bond 19800000000 --from=treasury --yes --gas=1000000 elysd query commitment show-commitments elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w # Migration proposal to "masterchef" version @@ -44,21 +44,21 @@ EDEN_VAL=elysvaloper1gnmpr8vvslp3shcq6e922xr0uq4aa2w5gdzht0 EDENB_VAL=elysvaloper1wajd6ekh9u37hyghyw4mme59qmjllzuyaceanm # estaking functionalities -elysd tx commitment commit-claimed-rewards 173430717 ueden --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 173430717 ueden --from=treasury --yes --gas=1000000 elysd query distribution rewards $TREASURY $EDEN_VAL elysd query commitment show-commitments $TREASURY elysd query staking delegations $TREASURY -elysd tx distribution withdraw-rewards $VALIDATOR --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx distribution withdraw-rewards $EDEN_VAL --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx distribution withdraw-rewards $EDENB_VAL --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx distribution withdraw-rewards $VALIDATOR --from=treasury --yes --gas=1000000 +elysd tx distribution withdraw-rewards $EDEN_VAL --from=treasury --yes --gas=1000000 +elysd tx distribution withdraw-rewards $EDENB_VAL --from=treasury --yes --gas=1000000 -elysd tx staking delegate elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs 100000000000uelys --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx staking delegate elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs 100000000000uelys --from=treasury --yes --gas=1000000 elysd query distribution rewards elys1r8nfpk0t4g6r7542g99s8ymxwzpsg57alx7gue $EDEN_VAL elysd query estaking params # masterchef functionalities elysd query masterchef user-pending-reward elys1r8nfpk0t4g6r7542g99s8ymxwzpsg57alx7gue -elysd tx masterchef claim-rewards --pool-ids=1 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx masterchef claim-rewards --pool-ids=32767 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx masterchef claim-rewards --pool-ids=1 --from=treasury --yes --gas=1000000 +elysd tx masterchef claim-rewards --pool-ids=32767 --from=treasury --yes --gas=1000000 diff --git a/scripts/examples/leveragelp/leveragelp.sh b/scripts/examples/leveragelp/leveragelp.sh index bc66d74f8..c8b199240 100644 --- a/scripts/examples/leveragelp/leveragelp.sh +++ b/scripts/examples/leveragelp/leveragelp.sh @@ -10,24 +10,24 @@ elysd query stablestake borrow-ratio elysd query stablestake params # Open amm pool -elysd tx amm create-pool 10uatom,10uusdc 10000000000uatom,10000000000uusdc --use-oracle=true --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm create-pool 10uatom,10uusdc 10000000000uatom,10000000000uusdc --use-oracle=true --from=treasury --yes --gas=1000000 # Put funds on stablestake -elysd tx stablestake bond 100000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx stablestake bond 100000000 --from=treasury --yes --gas=1000000 # Local test -elysd tx gov submit-proposal proposal.json --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx gov vote 1 Yes --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx gov vote 3 Yes --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx gov submit-proposal proposal.json --from=treasury --yes --gas=1000000 +elysd tx gov vote 1 Yes --from=treasury --yes --gas=1000000 +elysd tx gov vote 3 Yes --from=treasury --yes --gas=1000000 elysd query gov proposals # Open position -elysd tx leveragelp open 5.0 uusdc 5000000 1 0.0 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 --fees=250uelys +elysd tx leveragelp open 5.0 uusdc 5000000 1 0.0 --from=treasury --yes --gas=1000000 --fees=250uelys elysd tx leveragelp open [leverage] [collateral-asset] [collateral-amount] [amm-pool-id] [flags] # Close position -elysd tx leveragelp close 2 25000000000000000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx leveragelp close 1 500000000000000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx leveragelp close 2 25000000000000000000 --from=treasury --yes --gas=1000000 +elysd tx leveragelp close 1 500000000000000000 --from=treasury --yes --gas=1000000 elysd tx leveragelp close [position-id] [flags] # Query rewards @@ -35,7 +35,7 @@ elysd query leveragelp rewards $(elysd keys show -a treasury --keyring-backend=t # {"rewards":[{"position_id":"1","reward":[{"denom":"ueden","amount":"3086835"}]}],"total_rewards":[{"denom":"ueden","amount":"3086835"}]} # Claim rewards -elysd tx leveragelp claim-rewards 1 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx leveragelp claim-rewards 1 --from=treasury --yes --gas=1000000 elysd query commitment show-commitments $(elysd keys show -a treasury --keyring-backend=test) elysd query commitment committed-tokens-locked $(elysd keys show -a treasury --keyring-backend=test) @@ -86,11 +86,11 @@ pool: total_weight: "21474836480" # Open 50 USDC position -elysd tx leveragelp open 5 ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65 50000000 2 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 --node=https://rpc.testnet.elys.network:443 --fees=250uelys +elysd tx leveragelp open 5 ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65 50000000 2 --from=treasury --yes --gas=1000000 --node=https://rpc.testnet.elys.network:443 --fees=250uelys # Put pool 2 on leveragelp (Testnet) -elysd tx gov submit-proposal proposal.json --from=t2a --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 --node=https://rpc.testnet.elys.network:443 --fees=250uelys +elysd tx gov submit-proposal proposal.json --from=t2a --yes --gas=1000000 --node=https://rpc.testnet.elys.network:443 --fees=250uelys ``` { "title": "Enable ATOM/USDC pool (PoolId 2) on leveragelp", diff --git a/scripts/examples/masterchef/masterchef.sh b/scripts/examples/masterchef/masterchef.sh index 8ab9952b9..a96201f56 100644 --- a/scripts/examples/masterchef/masterchef.sh +++ b/scripts/examples/masterchef/masterchef.sh @@ -2,15 +2,15 @@ TREASURY=$(elysd keys show -a treasury --keyring-backend=test) -elysd tx amm create-pool 10uatom,10uusdc 20000000000uatom,20000000000uusdc --swap-fee=0.01 --exit-fee=0.00 --use-oracle=false --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm create-pool 10uatom,10uusdc 20000000000uatom,20000000000uusdc --swap-fee=0.01 --exit-fee=0.00 --use-oracle=false --from=treasury --yes --gas=1000000 # single asset add-liquidity -elysd tx amm join-pool 1 2000uatom 90000000000000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm join-pool 1 2000uatom 90000000000000000 --from=treasury --yes --gas=1000000 # multiple asset add-liquidity -elysd tx amm join-pool 1 20000000000uatom,20000000000uusdt 1000000000000000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm join-pool 1 20000000000uatom,20000000000uusdt 1000000000000000000 --from=treasury --yes --gas=1000000 # swap -elysd tx amm swap-exact-amount-in 10000000uatom 1 1 uusdc --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm swap-exact-amount-in 10000000uatom 1 1 uusdc --from=treasury --yes --gas=1000000 elysd query commitment show-commitments $TREASURY elysd query bank balances $TREASURY @@ -19,14 +19,14 @@ elysd query masterchef pool-info 1 elysd query masterchef params # Add external incentive -elysd tx masterchef add-external-incentive uinc 1 80 1080 1000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx masterchef add-external-incentive uinc 1 80 1080 1000000 --from=treasury --yes --gas=1000000 elysd query masterchef external-incentive 0 # Query pending rewards elysd query masterchef user-pending-reward $TREASURY # Claim rewards -elysd tx masterchef claim-rewards --pool-ids=1 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx masterchef claim-rewards --pool-ids=1 --from=treasury --yes --gas=1000000 # Test flow # - oracle setup without lifetime diff --git a/scripts/examples/oracle/README.md b/scripts/examples/oracle/README.md index aa5c7c444..5ca186e21 100644 --- a/scripts/examples/oracle/README.md +++ b/scripts/examples/oracle/README.md @@ -11,42 +11,39 @@ sh ./scripts/examples/oracle/start_band.sh ### Start elys chain -``` -ignite chain init -ignite chain serve --verbose -``` +```bash +elysd init my-node --chain-id elys -### Start relayer +# Add a key for alice (if not exists) +elysd keys add alice --keyring-backend test -#### Deposit balance to bandchain relayer account +# Add genesis account +elysd add-genesis-account alice 100000000stake --keyring-backend test -``` -ignite account show abc --address-prefix=band -bandd tx bank send validator band12zyg3xanvupc6upytvsghhlkl8l9cm2rtzn57q 1000000uband --keyring-backend=test --chain-id=band-test -y --broadcast-mode=block --node=http://localhost:26658 -bandd query bank balances band12zyg3xanvupc6upytvsghhlkl8l9cm2rtzn57q --node=http://localhost:26658 +# Generate genesis tx +elysd gentx alice 100000000stake --chain-id elys --keyring-backend test + +# Collect genesis txs +elysd collect-gentxs + +# Start the chain +elysd start ``` +### Start relayer + #### Configure and setup relayer -``` -rm -rf ~/.ignite/relayer +```bash +hermes config init +hermes keys add --chain band-test --mnemonic-file band_mnemonic.txt +hermes keys add --chain elys --mnemonic-file elys_mnemonic.txt -ignite relayer configure -a \ ---source-rpc "http://localhost:26658" \ ---source-port "oracle" \ ---source-gasprice "0.1uband" \ ---source-gaslimit 5000000 \ ---source-prefix "band" \ ---source-version "bandchain-1" \ ---target-rpc "http://localhost:26657" \ ---target-faucet "http://localhost:4500" \ ---target-port "oracle" \ ---target-gasprice "0.0stake" \ ---target-gaslimit 300000 \ ---target-prefix "elys" \ ---target-version "bandchain-1" +# Create hermes config file with appropriate settings +# Configure chains, ports, gas settings etc in ~/.hermes/config.toml -ignite relayer connect +# Start the relayer +hermes start ``` ### Send price request to bandchain @@ -79,33 +76,52 @@ result: # Test band oracle with public testnet -https://docs.ignite.com/v0.25.2/kb/band - ### Start local elys chain -ignite chain serve --verbose +```bash +elysd start +``` ### Setup relayer between local elys and public band testnet -``` -rm -rf ~/.ignite/relayer -ignite relayer configure -a \ ---source-rpc "https://rpc.laozi-testnet6.bandchain.org:443" \ ---source-faucet "https://laozi-testnet6.bandchain.org/faucet" \ ---source-port "oracle" \ ---source-gasprice "0.1uband" \ ---source-gaslimit 5000000 \ ---source-prefix "band" \ ---source-version "bandchain-1" \ ---target-rpc "http://localhost:26657" \ ---target-faucet "http://localhost:4500" \ ---target-port "oracle" \ ---target-gasprice "0.0stake" \ ---target-gaslimit 300000 \ ---target-prefix "elys" \ ---target-version "bandchain-1" - -ignite relayer connect +```bash +# Initialize Hermes config +hermes config init + +# Add the chains to your config file (~/.hermes/config.toml): +[[chains]] +id = 'band-laozi-testnet6' +rpc_addr = 'https://rpc.laozi-testnet6.bandchain.org:443' +grpc_addr = 'https://laozi-testnet6.bandchain.org:9090' +websocket_addr = 'wss://rpc.laozi-testnet6.bandchain.org/websocket' +rpc_timeout = '10s' +account_prefix = 'band' +key_name = 'band-relayer' +store_prefix = 'ibc' +gas_price = { price = 0.1, denom = 'uband' } +gas_limit = 5000000 + +[[chains]] +id = 'elys' +rpc_addr = 'http://localhost:26657' +grpc_addr = 'http://localhost:9090' +websocket_addr = 'ws://localhost:26657/websocket' +rpc_timeout = '10s' +account_prefix = 'elys' +key_name = 'elys-relayer' +store_prefix = 'ibc' +gas_price = { price = 0.0, denom = 'stake' } +gas_limit = 300000 + +# Add keys for both chains +hermes keys add --chain band-laozi-testnet6 --mnemonic-file band_mnemonic.txt +hermes keys add --chain elys --mnemonic-file elys_mnemonic.txt + +# Create the connection +hermes create connection --a-chain elys --b-chain band-laozi-testnet6 + +# Start the relayer +hermes start ``` ### Send price request to bandchain diff --git a/scripts/examples/stablestake/stablestake.sh b/scripts/examples/stablestake/stablestake.sh index 3d9bf6281..d59a8486d 100644 --- a/scripts/examples/stablestake/stablestake.sh +++ b/scripts/examples/stablestake/stablestake.sh @@ -20,8 +20,8 @@ elysd query stablestake borrow-ratio # total_borrow: "0" # total_deposit: "100000000" -elysd tx stablestake bond 100000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx stablestake bond 100000000 --from=treasury --yes --gas=1000000 # Testnet -elysd tx stablestake bond 112131 --from=t2a --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 --node=https://rpc.testnet.elys.network:443 --fees=250uelys +elysd tx stablestake bond 112131 --from=t2a --yes --gas=1000000 --node=https://rpc.testnet.elys.network:443 --fees=250uelys diff --git a/scripts/examples/transferhook/README.md b/scripts/examples/transferhook/README.md index 0f92d30de..c05dcf8fe 100644 --- a/scripts/examples/transferhook/README.md +++ b/scripts/examples/transferhook/README.md @@ -2,11 +2,11 @@ ### Start mars chain -ignite chain serve --verbose --reset-once -c ./scripts/examples/transferhook/mars.yml +marsd start ### Start elys chain -ignite chain serve --verbose --reset-once +elysd start ### Start relayer @@ -17,13 +17,13 @@ hermes --config ./scripts/examples/transferhook/config.toml keys delete --chain echo "attend copy blast obey agent clinic monkey blur doctor sibling impact stomach judge rubber actress forest wage silent sick key divide exotic junk velvet" > mars.txt hermes --config ./scripts/examples/transferhook/config.toml keys add --chain marstestnet-1 --mnemonic-file=mars.txt -hermes --config ./scripts/examples/transferhook/config.toml keys delete --chain elystestnet-1 --all +hermes --config ./scripts/examples/transferhook/config.toml keys delete --chain elysicstestnet-1 --all echo "olympic slide park figure frost benefit deer reform fly pull price airport submit monitor silk insect uphold convince pupil project ignore roof warfare slight" > elys.txt -hermes --config ./scripts/examples/transferhook/config.toml keys add --chain elystestnet-1 --mnemonic-file=elys.txt +hermes --config ./scripts/examples/transferhook/config.toml keys add --chain elysicstestnet-1 --mnemonic-file=elys.txt -hermes --config ./scripts/examples/transferhook/config.toml create connection --a-chain elystestnet-1 --b-chain marstestnet-1 +hermes --config ./scripts/examples/transferhook/config.toml create connection --a-chain elysicstestnet-1 --b-chain marstestnet-1 -hermes --config ./scripts/examples/transferhook/config.toml create channel --a-chain elystestnet-1 --a-port transfer --b-port transfer --a-connection connection-0 +hermes --config ./scripts/examples/transferhook/config.toml create channel --a-chain elysicstestnet-1 --a-port transfer --b-port transfer --a-connection connection-0 hermes --config ./scripts/examples/transferhook/config.toml start ``` @@ -34,18 +34,18 @@ hermes --config ./scripts/examples/transferhook/config.toml start elysd keys add acc1 --keyring-backend=test ACC1=elys1jfmgwygyf9u3sx6xm36xlxf85v977k5c7l8w3q -elysd tx ibc-transfer transfer transfer channel-0 $ACC1 10000uatom --chain-id=elystestnet-1 --from=treasury --keyring-backend=test -y --node=http://localhost:26657 +elysd tx ibc-transfer transfer transfer channel-0 $ACC1 10000uatom --from=treasury --keyring-backend=test -y --node=http://localhost:26657 elysd query bank balances $ACC1 --node=http://localhost:26659 ATOM_IBC=ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 elysd tx ibc-transfer transfer transfer channel-0 $ACC1 100$ATOM_IBC --chain-id=marstestnet-1 --from=acc1 --keyring-backend=test -y --node=http://localhost:26659 -elysd tx amm create-pool 10uatom,10uusdt 10000uatom,10000uusdt --swap-fee=0.00 --exit-fee=0.00 --use-oracle=false --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm create-pool 10uatom,10uusdt 10000uatom,10000uusdt --swap-fee=0.00 --exit-fee=0.00 --use-oracle=false --from=treasury --yes --gas=1000000 # swap with transferhook elysd tx ibc-transfer transfer transfer channel-0 '{"transferhook":{"receiver":"'$ACC1'","amm":{"action":"Swap","routes":[{"pool_id":1,"token_out_denom": "uusdt"}]}}}' 100$ATOM_IBC --chain-id=marstestnet-1 --from=acc1 --keyring-backend=test -y --node=http://localhost:26659 elysd query bank balances $ACC1 --node=http://localhost:26657 -elysd tx amm swap-exact-amount-in 10uatom 1 1 uusdt --from=acc1 --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx amm swap-exact-amount-in 10uatom 1 1 uusdt --from=acc1 --yes --gas=1000000 elysd query bank balances $ACC1 --node=http://localhost:26657 ``` diff --git a/scripts/examples/transferhook/config.toml b/scripts/examples/transferhook/config.toml index 83f7b566f..846482a03 100644 --- a/scripts/examples/transferhook/config.toml +++ b/scripts/examples/transferhook/config.toml @@ -111,7 +111,7 @@ trust_threshold = { numerator = '1', denominator = '3' } address_type = { derivation = 'cosmos' } [[chains]] -id = 'elystestnet-1' +id = 'elysicstestnet-1' rpc_addr = 'http://127.0.0.1:26657' grpc_addr = 'http://127.0.0.1:9090' websocket_addr = 'ws://127.0.0.1:26657/websocket' diff --git a/scripts/propose/propose.sh b/scripts/propose/propose.sh index b15fee29a..2b3ec4bc7 100755 --- a/scripts/propose/propose.sh +++ b/scripts/propose/propose.sh @@ -40,4 +40,4 @@ if [ ${#multipliers} -lt 1 ]; then fi echo "!! Submit update-pool-info proposal !!" -elysd tx incentive update-pool-info "$poolIds" "$multipliers" --title="title" --description="description" --deposit="10000000uelys" --from=treasury --chain-id=elystestnet-1 --broadcast-mode=block --yes --gas auto \ No newline at end of file +elysd tx incentive update-pool-info "$poolIds" "$multipliers" --title="title" --description="description" --deposit="10000000uelys" --from=treasury --yes --gas auto \ No newline at end of file diff --git a/scripts/testing/variables.sh.example b/scripts/testing/variables.sh.example index b38027f1c..68bbbf0be 100644 --- a/scripts/testing/variables.sh.example +++ b/scripts/testing/variables.sh.example @@ -76,7 +76,7 @@ VALIDATOR_ACCOUNT_PASSPHRASES=( VERSION="v0.6.0" BINARY="/tmp/elysd-060" PREVIOUS_UPGRADE_HEIGHT="818000" -CHAIN_ID="elystestnet-1" +CHAIN_ID="elysicstestnet-1" SNAPSHOT_URL="https://snapshots.polkachu.com/testnet-snapshots/elys/elys_991272.tar.lz4" SNAPSHOT_PATH="/tmp/elys_991272.tar.lz4" NEW_VERSION="v0.7.0" diff --git a/troubleshooting.md b/troubleshooting.md deleted file mode 100644 index 71fb32eeb..000000000 --- a/troubleshooting.md +++ /dev/null @@ -1,11 +0,0 @@ -# Ignite CLI - -**Ignite CLI** is the all-in-one platform to build, launch, and maintain any crypto application on a sovereign and secured blockchain. It is a developer-friendly interface to the Cosmos SDK, the world's most widely-used blockchain application framework. Ignite CLI generates boilerplate code for you, so you can focus on writing business logic. Latest version 0.27.1 targets Cosmos SDK v47.3 and 0.26.1 targets Cosmos SDK v0.46.x. - -## Troubleshooting -- Ignite uses placeholder to scaffold codes automatically. Once it gets broken, Ignite CLI won't work. So please be careful of those placeholders if you want to keep using Ignite CLI. -- Placeholder inserted in import section might get removed automatically after executing Ignite CLI scaffold function. Each placeholder has its tag like #1, #2, #3 etc. If you see placeholder #2 but don't see placeholder #1, it means it was removed by fault - developer or Ignite CLI itself. We should recover the missing placeholder to make Ignite CLI work again. - -## Learn more - -- [Ignite CLI Docs](https://docs.ignite.com/) diff --git a/x/commitment/spec/02_usage.md b/x/commitment/spec/02_usage.md index 6f7f226dd..b62af0428 100644 --- a/x/commitment/spec/02_usage.md +++ b/x/commitment/spec/02_usage.md @@ -24,37 +24,37 @@ elysd query commitment params ### Committing Tokens ```bash -elysd tx commitment commit-claimed-rewards 1000000000uelys --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 1000000000uelys --from=treasury --yes --gas=1000000 ``` ### Uncommitting Tokens ```bash -elysd tx commitment uncommit-tokens 500000000uelys --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment uncommit-tokens 500000000uelys --from=treasury --yes --gas=1000000 ``` ### Vesting Tokens ```bash -elysd tx commitment vest 100000000uelys --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment vest 100000000uelys --from=treasury --yes --gas=1000000 ``` ### Claiming Vested Tokens ```bash -elysd tx commitment claim-vesting --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment claim-vesting --from=treasury --yes --gas=1000000 ``` ### Staking Tokens ```bash VALIDATOR=elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs -elysd tx commitment stake 100000000uelys $VALIDATOR --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment stake 100000000uelys $VALIDATOR --from=treasury --yes --gas=1000000 ``` ### Unstaking Tokens ```bash VALIDATOR=elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs -elysd tx commitment unstake 50000000uelys $VALIDATOR --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment unstake 50000000uelys $VALIDATOR --from=treasury --yes --gas=1000000 ``` diff --git a/x/estaking/spec/02_usage.md b/x/estaking/spec/02_usage.md index b9bd1005a..c22c7997a 100644 --- a/x/estaking/spec/02_usage.md +++ b/x/estaking/spec/02_usage.md @@ -26,7 +26,7 @@ elysd query staking validators ```bash VALIDATOR=elysvaloper12tzylat4udvjj56uuhu3vj2n4vgp7cf9pwcqcs -elysd tx staking delegate $VALIDATOR 1000000000000uelys --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx staking delegate $VALIDATOR 1000000000000uelys --from=treasury --yes --gas=1000000 ``` ### Querying and Withdrawing Rewards @@ -36,22 +36,22 @@ elysd query distribution rewards $TREASURY $VALIDATOR elysd query distribution rewards $TREASURY $EDEN_VAL elysd query distribution rewards $TREASURY $EDENB_VAL -elysd tx distribution withdraw-rewards $VALIDATOR --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx distribution withdraw-rewards $EDEN_VAL --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx distribution withdraw-rewards $EDENB_VAL --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx distribution withdraw-rewards $VALIDATOR --from=treasury --yes --gas=1000000 +elysd tx distribution withdraw-rewards $EDEN_VAL --from=treasury --yes --gas=1000000 +elysd tx distribution withdraw-rewards $EDENB_VAL --from=treasury --yes --gas=1000000 ``` ### Committing Claimed Rewards ```bash -elysd tx commitment commit-claimed-rewards 503544 ueden --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 -elysd tx commitment commit-claimed-rewards 1678547 uedenb --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 503544 ueden --from=treasury --yes --gas=1000000 +elysd tx commitment commit-claimed-rewards 1678547 uedenb --from=treasury --yes --gas=1000000 ``` ### Delegating ```bash -elysd tx staking delegate $VALIDATOR 1000uelys --fees=10000uusdc --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx staking delegate $VALIDATOR 1000uelys --fees=10000uusdc --from=treasury --yes --gas=1000000 ``` ### Querying eStaking Rewards @@ -63,5 +63,5 @@ elysd query estaking rewards $TREASURY ### Withdrawing All Rewards ```bash -elysd tx estaking withdraw-all-rewards --from=validator --chain-id=elystestnet-1 +elysd tx estaking withdraw-all-rewards --from=validator ``` diff --git a/x/perpetual/spec/03_usage.md b/x/perpetual/spec/03_usage.md index 031d216fd..9230a4983 100644 --- a/x/perpetual/spec/03_usage.md +++ b/x/perpetual/spec/03_usage.md @@ -13,7 +13,7 @@ order: 3 To open a long position with infinite profitability: ```shell -elysd tx perpetual open long 5 uatom 100000000uusdc --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual open long 5 uatom 100000000uusdc --from=treasury --yes --gas=1000000 ``` #### Finite Profitability @@ -21,7 +21,7 @@ elysd tx perpetual open long 5 uatom 100000000uusdc --from=treasury --keyring-ba To open a short position with a specified take profit level: ```shell -elysd tx perpetual open short 5 uatom 100000000uusdc --take-profit 100 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual open short 5 uatom 100000000uusdc --take-profit 100 --from=treasury --yes --gas=1000000 ``` ### Close a Position @@ -29,7 +29,7 @@ elysd tx perpetual open short 5 uatom 100000000uusdc --take-profit 100 --from=tr To close an existing position: ```shell -elysd tx perpetual close 1 10000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual close 1 10000000 --from=treasury --yes --gas=1000000 ``` ### Manage Whitelist @@ -39,7 +39,7 @@ elysd tx perpetual close 1 10000000 --from=treasury --keyring-backend=test --cha To whitelist an address for trading in the perpetual module: ```shell -elysd tx perpetual whitelist ADDRESS --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual whitelist ADDRESS --from=treasury --yes --gas=1000000 ``` #### Dewhitelist an Address @@ -47,7 +47,7 @@ elysd tx perpetual whitelist ADDRESS --from=treasury --keyring-backend=test --ch To remove an address from the whitelist: ```shell -elysd tx perpetual dewhitelist ADDRESS --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual dewhitelist ADDRESS --from=treasury --yes --gas=1000000 ``` ### Update Module Parameters @@ -55,7 +55,7 @@ elysd tx perpetual dewhitelist ADDRESS --from=treasury --keyring-backend=test -- To update the parameters of the perpetual module: ```shell -elysd tx perpetual update-params [OPTIONS] --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual update-params [OPTIONS] --from=treasury --yes --gas=1000000 ``` ## Query Commands @@ -153,37 +153,37 @@ elysd query perpetual open-estimation [position] [leverage] [trading-asset] [col ### Open a Long Position ```shell -elysd tx perpetual open long 5 uatom 100000000uusdc --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual open long 5 uatom 100000000uusdc --from=treasury --yes --gas=1000000 ``` ### Open a Short Position with Take Profit ```shell -elysd tx perpetual open short 5 uatom 100000000uusdc --take-profit 100 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual open short 5 uatom 100000000uusdc --take-profit 100 --from=treasury --yes --gas=1000000 ``` ### Close a Position ```shell -elysd tx perpetual close 1 10000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual close 1 10000000 --from=treasury --yes --gas=1000000 ``` ### Whitelist an Address ```shell -elysd tx perpetual whitelist elys1qv4k64xr6nhcxgnzq0l8t8wy9s9d4s9d6w93lz --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual whitelist elys1qv4k64xr6nhcxgnzq0l8t8wy9s9d4s9d6w93lz --from=treasury --yes --gas=1000000 ``` ### Dewhitelist an Address ```shell -elysd tx perpetual dewhitelist elys1qv4k64xr6nhcxgnzq0l8t8wy9s9d4s9d6w93lz --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual dewhitelist elys1qv4k64xr6nhcxgnzq0l8t8wy9s9d4s9d6w93lz --from=treasury --yes --gas=1000000 ``` ### Update Parameters ```shell -elysd tx perpetual update-params --maxLeverage=10 --maintenanceMarginRatio=0.05 --fundingRateInterval=60 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx perpetual update-params --maxLeverage=10 --maintenanceMarginRatio=0.05 --fundingRateInterval=60 --from=treasury --yes --gas=1000000 ``` ### Query a Specific Position diff --git a/x/stablestake/spec/03_usage.md b/x/stablestake/spec/03_usage.md index aae3c4177..add9fed1f 100644 --- a/x/stablestake/spec/03_usage.md +++ b/x/stablestake/spec/03_usage.md @@ -21,11 +21,11 @@ elysd query stablestake borrow-ratio ### Bonding Tokens ```bash -elysd tx stablestake bond 1000000000000uusdc --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx stablestake bond 1000000000000uusdc --from=treasury --yes --gas=1000000 ``` ### Unbonding Tokens ```bash -elysd tx stablestake unbond 500000000000uusdc --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx stablestake unbond 500000000000uusdc --from=treasury --yes --gas=1000000 ``` From b7f03164485e612db6fedbd46fe2628887a5ed33 Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Mon, 9 Dec 2024 18:33:07 +0100 Subject: [PATCH 4/4] =?UTF-8?q?Update=20CancelPerpetualOrder=20to=20return?= =?UTF-8?q?=20all=20available=20balances=20to=20the=20o=E2=80=A6=20(#1053)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update CancelPerpetualOrder to return all available balances to the owner - Updated the CancelPerpetualOrder function to retrieve and send all available balances from the order address back to the owner, enhancing the balance management process. - This change ensures that users receive the full amount of their collateral and any other balances associated with the order upon cancellation. --- .../keeper/msg_server_perpetual_order.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/x/tradeshield/keeper/msg_server_perpetual_order.go b/x/tradeshield/keeper/msg_server_perpetual_order.go index 6049536b5..4b0638a53 100644 --- a/x/tradeshield/keeper/msg_server_perpetual_order.go +++ b/x/tradeshield/keeper/msg_server_perpetual_order.go @@ -179,11 +179,17 @@ func (k msgServer) CancelPerpetualOrder(goCtx context.Context, msg *types.MsgCan return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner") } - // send the collateral amount back to the owner - ownerAddress := sdk.MustAccAddressFromBech32(order.OwnerAddress) - err := k.Keeper.bank.SendCoins(ctx, order.GetOrderAddress(), ownerAddress, sdk.NewCoins(order.Collateral)) - if err != nil { - return nil, err + // Get all balances from the spot order address + orderAddress := order.GetOrderAddress() + balances := k.Keeper.bank.GetAllBalances(ctx, orderAddress) + + // Send all available balances back to the owner if there are any + if !balances.IsZero() { + ownerAddress := sdk.MustAccAddressFromBech32(order.OwnerAddress) + err := k.Keeper.bank.SendCoins(ctx, orderAddress, ownerAddress, balances) + if err != nil { + return nil, err + } } k.RemovePendingPerpetualOrder(ctx, msg.OrderId)