Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: additional test cases for TestCalcJoinPoolShares (multi-coin swap) #1713

Merged
merged 10 commits into from
Jun 10, 2022
53 changes: 53 additions & 0 deletions x/gamm/pool-models/balancer/amm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,59 @@ func TestCalcJoinPoolShares(t *testing.T) {
expectShares: sdk.NewInt(2499999968800),
expectLiq: sdk.NewCoins(sdk.NewInt64Coin("uosmo", 50_000)),
},
{
name: "swap equal weights with zero swap fee",
swapFee: sdk.MustNewDecFromStr("0"),
poolAssets: []balancer.PoolAsset{
{
Token: sdk.NewInt64Coin("uosmo", 1_000_000_000_000),
Weight: sdk.NewInt(100),
},
{
Token: sdk.NewInt64Coin("uatom", 1_000_000_000_000),
Weight: sdk.NewInt(100),
},
},
tokensIn: sdk.NewCoins(
sdk.NewInt64Coin("uosmo", 25_000),
sdk.NewInt64Coin("uatom", 25_000),
),
expectErr: false,
// Raises liquidity perfectly by 25_000 / 1_000_000_000_000. Initial number of pool shares = 100 * 10**18 = 10**20
// Expected increase = liquidity_increase_ratio * initial number of pool shares = (25_000 / 1_000_000_000_000) * 10**20 = 2500000000000.0 = 2.5 * 10**12
expectShares: sdk.NewInt(2.5e12),
expectLiq: sdk.NewCoins(
sdk.NewInt64Coin("uosmo", 25_000),
sdk.NewInt64Coin("uatom", 25_000),
),
},
{
name: "swap equal weights with 0.001 swap fee",
swapFee: sdk.MustNewDecFromStr("0.001"),
poolAssets: []balancer.PoolAsset{
{
Token: sdk.NewInt64Coin("uosmo", 1_000_000_000_000),
Weight: sdk.NewInt(100),
},
{
Token: sdk.NewInt64Coin("uatom", 1_000_000_000_000),
Weight: sdk.NewInt(100),
},
},
tokensIn: sdk.NewCoins(
sdk.NewInt64Coin("uosmo", 25_000),
sdk.NewInt64Coin("uatom", 25_000),
),
expectErr: false,
// TODO: Verify expectShares value using manual calculation using the
// following as reference:
// https://github.com/osmosis-labs/osmosis/blob/6125f81d1ad95c73e03d86c3d5e96ceef3f8c12f/x/gamm/pool-models/balancer/amm_test.go#L348-L357
expectShares: sdk.NewInt(2500000000000),
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
expectLiq: sdk.NewCoins(
sdk.NewInt64Coin("uosmo", 25_000),
sdk.NewInt64Coin("uatom", 25_000),
),
},
{
name: "equal weights with 0.001 swap fee",
swapFee: sdk.MustNewDecFromStr("0.001"),
Expand Down