Skip to content

Commit

Permalink
chore: use base and trading currency terms instead in margin (#193)
Browse files Browse the repository at this point in the history
* chore: use base and trading currency terms instead in margin

* chore: rename it in other modules as well

* fix: minor

* fix: minor
  • Loading branch information
cosmic-vagabond authored Sep 15, 2023
1 parent efafc3e commit e3b65b5
Show file tree
Hide file tree
Showing 73 changed files with 748 additions and 721 deletions.
6 changes: 3 additions & 3 deletions x/accountedpool/keeper/accounted_pool_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestAccountedPoolUpdate(t *testing.T) {
TotalShares: sdk.NewCoin("lp-token", sdk.NewInt(100)),
PoolAssets: []ammtypes.PoolAsset{
{Token: sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100))},
{Token: sdk.NewCoin(ptypes.USDC, sdk.NewInt(1000))},
{Token: sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(1000))},
},
TotalWeight: sdk.NewInt(100),
RebalanceTreasury: addr[0].String(),
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestAccountedPoolUpdate(t *testing.T) {
AssetBalance: sdk.NewInt(100),
UnsettledLiabilities: sdk.NewInt(0),
BlockInterest: sdk.NewInt(0),
AssetDenom: ptypes.USDC,
AssetDenom: ptypes.BaseCurrency,
},
{
Liabilities: sdk.NewInt(0),
Expand All @@ -82,7 +82,7 @@ func TestAccountedPoolUpdate(t *testing.T) {
require.Equal(t, found, true)
require.Equal(t, apool.PoolId, (uint64)(0))

usdcBalance := apk.GetAccountedBalance(ctx, (uint64)(0), ptypes.USDC)
usdcBalance := apk.GetAccountedBalance(ctx, (uint64)(0), ptypes.BaseCurrency)
require.Equal(t, usdcBalance, sdk.NewInt(1000+400+100))
atomBalance := apk.GetAccountedBalance(ctx, (uint64)(0), ptypes.ATOM)
require.Equal(t, atomBalance, sdk.NewInt(100))
Expand Down
3 changes: 2 additions & 1 deletion x/amm/client/cli/query_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/elys-network/elys/testutil/nullify"
"github.com/elys-network/elys/x/amm/client/cli"
"github.com/elys-network/elys/x/amm/types"
ptypes "github.com/elys-network/elys/x/parameter/types"
)

// Prevent strconv unused error
Expand All @@ -42,7 +43,7 @@ func networkWithPoolObjects(t *testing.T, n int) (*network.Network, []types.Pool
StakingFeePortion: sdk.ZeroDec(),
WeightRecoveryFeePortion: sdk.ZeroDec(),
ThresholdWeightDifference: sdk.ZeroDec(),
FeeDenom: "uusdc",
FeeDenom: ptypes.BaseCurrency,
},
}
nullify.Fill(&pool)
Expand Down
71 changes: 36 additions & 35 deletions x/amm/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/elys-network/elys/x/amm/keeper"
"github.com/elys-network/elys/x/amm/types"
ptypes "github.com/elys-network/elys/x/parameter/types"
)

func (suite *KeeperTestSuite) TestExecuteSwapRequests() {
Expand All @@ -20,170 +21,170 @@ func (suite *KeeperTestSuite) TestExecuteSwapRequests() {
}{
{
desc: "single swap request",
senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uelys", 1000000), sdk.NewInt64Coin("uusdc", 1000000)},
senderInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)},
swapMsgs: []sdk.Msg{
&types.MsgSwapExactAmountIn{
Sender: sender.String(),
Routes: []types.SwapAmountInRoute{
{
PoolId: 1,
TokenOutDenom: "uusdc",
TokenOutDenom: ptypes.BaseCurrency,
},
},
TokenIn: sdk.NewInt64Coin("uelys", 10000),
TokenIn: sdk.NewInt64Coin(ptypes.Elys, 10000),
TokenOutMinAmount: sdk.ZeroInt(),
},
},
expSwapOrder: []uint64{0},
},
{
desc: "two requests with opposite direction",
senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uelys", 1000000), sdk.NewInt64Coin("uusdc", 1000000)},
senderInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)},
swapMsgs: []sdk.Msg{
&types.MsgSwapExactAmountIn{
Sender: sender.String(),
Routes: []types.SwapAmountInRoute{
{
PoolId: 1,
TokenOutDenom: "uusdc",
TokenOutDenom: ptypes.BaseCurrency,
},
},
TokenIn: sdk.NewInt64Coin("uelys", 10000),
TokenIn: sdk.NewInt64Coin(ptypes.Elys, 10000),
TokenOutMinAmount: sdk.ZeroInt(),
},
&types.MsgSwapExactAmountIn{
Sender: sender.String(),
Routes: []types.SwapAmountInRoute{
{
PoolId: 1,
TokenOutDenom: "uelys",
TokenOutDenom: ptypes.Elys,
},
},
TokenIn: sdk.NewInt64Coin("uusdc", 8000),
TokenIn: sdk.NewInt64Coin(ptypes.BaseCurrency, 8000),
TokenOutMinAmount: sdk.ZeroInt(),
},
},
expSwapOrder: []uint64{1, 0},
},
{
desc: "three requests",
senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uelys", 1000000), sdk.NewInt64Coin("uusdc", 1000000)},
senderInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)},
swapMsgs: []sdk.Msg{
&types.MsgSwapExactAmountIn{
Sender: sender.String(),
Routes: []types.SwapAmountInRoute{
{
PoolId: 1,
TokenOutDenom: "uusdc",
TokenOutDenom: ptypes.BaseCurrency,
},
},
TokenIn: sdk.NewInt64Coin("uelys", 11000),
TokenIn: sdk.NewInt64Coin(ptypes.Elys, 11000),
TokenOutMinAmount: sdk.ZeroInt(),
},
&types.MsgSwapExactAmountIn{
Sender: sender.String(),
Routes: []types.SwapAmountInRoute{
{
PoolId: 1,
TokenOutDenom: "uelys",
TokenOutDenom: ptypes.Elys,
},
},
TokenIn: sdk.NewInt64Coin("uusdc", 8000),
TokenIn: sdk.NewInt64Coin(ptypes.BaseCurrency, 8000),
TokenOutMinAmount: sdk.ZeroInt(),
},
&types.MsgSwapExactAmountIn{
Sender: sender.String(),
Routes: []types.SwapAmountInRoute{
{
PoolId: 1,
TokenOutDenom: "uelys",
TokenOutDenom: ptypes.Elys,
},
},
TokenIn: sdk.NewInt64Coin("uusdc", 1000),
TokenIn: sdk.NewInt64Coin(ptypes.BaseCurrency, 1000),
TokenOutMinAmount: sdk.ZeroInt(),
},
},
expSwapOrder: []uint64{1, 0, 2},
},
{
desc: "three requests combining different swap msg types",
senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uelys", 1000000), sdk.NewInt64Coin("uusdc", 1000000)},
senderInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)},
swapMsgs: []sdk.Msg{
&types.MsgSwapExactAmountIn{
Sender: sender.String(),
Routes: []types.SwapAmountInRoute{
{
PoolId: 1,
TokenOutDenom: "uusdc",
TokenOutDenom: ptypes.BaseCurrency,
},
},
TokenIn: sdk.NewInt64Coin("uelys", 11000),
TokenIn: sdk.NewInt64Coin(ptypes.Elys, 11000),
TokenOutMinAmount: sdk.ZeroInt(),
},
&types.MsgSwapExactAmountOut{
Sender: sender.String(),
Routes: []types.SwapAmountOutRoute{
{
PoolId: 1,
TokenInDenom: "uusdc",
TokenInDenom: ptypes.BaseCurrency,
},
},
TokenOut: sdk.NewInt64Coin("uelys", 8000),
TokenOut: sdk.NewInt64Coin(ptypes.Elys, 8000),
TokenInMaxAmount: sdk.NewInt(1000000),
},
&types.MsgSwapExactAmountIn{
Sender: sender.String(),
Routes: []types.SwapAmountInRoute{
{
PoolId: 1,
TokenOutDenom: "uelys",
TokenOutDenom: ptypes.Elys,
},
},
TokenIn: sdk.NewInt64Coin("uusdc", 1000),
TokenIn: sdk.NewInt64Coin(ptypes.BaseCurrency, 1000),
TokenOutMinAmount: sdk.ZeroInt(),
},
},
expSwapOrder: []uint64{2, 1, 0},
},
{
desc: "three requests combining different swap msg types",
senderInitBalance: sdk.Coins{sdk.NewInt64Coin("uelys", 1000000), sdk.NewInt64Coin("uusdc", 1000000)},
senderInitBalance: sdk.Coins{sdk.NewInt64Coin(ptypes.Elys, 1000000), sdk.NewInt64Coin(ptypes.BaseCurrency, 1000000)},
swapMsgs: []sdk.Msg{
&types.MsgSwapExactAmountIn{
Sender: sender.String(),
Routes: []types.SwapAmountInRoute{
{
PoolId: 1,
TokenOutDenom: "uusdc",
TokenOutDenom: ptypes.BaseCurrency,
},
},
TokenIn: sdk.NewInt64Coin("uelys", 11000),
TokenIn: sdk.NewInt64Coin(ptypes.Elys, 11000),
TokenOutMinAmount: sdk.ZeroInt(),
},
&types.MsgSwapExactAmountOut{
Sender: sender.String(),
Routes: []types.SwapAmountOutRoute{
{
PoolId: 1,
TokenInDenom: "uusdc",
TokenInDenom: ptypes.BaseCurrency,
},
},
TokenOut: sdk.NewInt64Coin("uelys", 8000),
TokenOut: sdk.NewInt64Coin(ptypes.Elys, 8000),
TokenInMaxAmount: sdk.NewInt(1000000),
},
&types.MsgSwapExactAmountIn{
Sender: sender.String(),
Routes: []types.SwapAmountInRoute{
{
PoolId: 1,
TokenOutDenom: "uelys",
TokenOutDenom: ptypes.Elys,
},
{
PoolId: 2,
TokenOutDenom: "uusdt",
},
},
TokenIn: sdk.NewInt64Coin("uusdc", 1000),
TokenIn: sdk.NewInt64Coin(ptypes.BaseCurrency, 1000),
TokenOutMinAmount: sdk.ZeroInt(),
},
},
Expand All @@ -198,8 +199,8 @@ func (suite *KeeperTestSuite) TestExecuteSwapRequests() {
treasuryAddr := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
treasuryAddr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
poolCoins := sdk.Coins{sdk.NewInt64Coin("uelys", 1000000), sdk.NewInt64Coin("uusdc", 1000000)}
pool2Coins := sdk.Coins{sdk.NewInt64Coin("uelys", 1000000), sdk.NewInt64Coin("uusdt", 1000000)}
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)
Expand All @@ -217,11 +218,11 @@ func (suite *KeeperTestSuite) TestExecuteSwapRequests() {

// execute function
suite.app.AmmKeeper.SetDenomLiquidity(suite.ctx, types.DenomLiquidity{
Denom: "uelys",
Denom: ptypes.Elys,
Liquidity: sdk.NewInt(2000000),
})
suite.app.AmmKeeper.SetDenomLiquidity(suite.ctx, types.DenomLiquidity{
Denom: "uusdc",
Denom: ptypes.BaseCurrency,
Liquidity: sdk.NewInt(1000000),
})
suite.app.AmmKeeper.SetDenomLiquidity(suite.ctx, types.DenomLiquidity{
Expand All @@ -235,7 +236,7 @@ func (suite *KeeperTestSuite) TestExecuteSwapRequests() {
RebalanceTreasury: treasuryAddr.String(),
PoolParams: types.PoolParams{
SwapFee: sdk.ZeroDec(),
FeeDenom: "uusdc",
FeeDenom: ptypes.BaseCurrency,
},
TotalShares: sdk.Coin{},
PoolAssets: []types.PoolAsset{
Expand All @@ -256,7 +257,7 @@ func (suite *KeeperTestSuite) TestExecuteSwapRequests() {
RebalanceTreasury: treasuryAddr2.String(),
PoolParams: types.PoolParams{
SwapFee: sdk.ZeroDec(),
FeeDenom: "uusdc",
FeeDenom: ptypes.BaseCurrency,
},
TotalShares: sdk.Coin{},
PoolAssets: []types.PoolAsset{
Expand Down
4 changes: 2 additions & 2 deletions x/amm/keeper/apply_exit_pool_state_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestWithdrawCommitedLPTokenFromCommitmentModule(t *testing.T) {

// Create a pool
// Mint 100000USDC
usdcToken := sdk.NewCoins(sdk.NewCoin(ptypes.USDC, sdk.NewInt(100000)))
usdcToken := sdk.NewCoins(sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000)))

err = app.BankKeeper.MintCoins(ctx, types.ModuleName, usdcToken)
require.NoError(t, err)
Expand All @@ -45,7 +45,7 @@ func TestWithdrawCommitedLPTokenFromCommitmentModule(t *testing.T) {
},
{
Weight: sdk.NewInt(50),
Token: sdk.NewCoin(ptypes.USDC, sdk.NewInt(10000)),
Token: sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(10000)),
},
}

Expand Down
Loading

0 comments on commit e3b65b5

Please sign in to comment.