Repository: osmosis-labs/osmosis
Pull request #5252 (2023-05-22 02:01:27)

chore(deps): bump github.com/spf13/cast from 1.5.0 to 1.5.1
Bumps [github.com/spf13/cast](https://github.com/spf13/cast) from 1.5.0 to 1.5.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/spf13/cast/releases">github.com/spf13/cast's releases</a>.</em></p>
<blockquote>
<h2>v1.5.1</h2>
<h2>What's Changed</h2>
<ul>
<li>Correction of hugo URL error by <a href="https://github.com/qwxingzhe"><code>@​qwxingzhe</code></a> in <a href="https://redirect.github.com/spf13/cast/pull/164">spf13/cast#164</a></li>
<li>Improve CI by <a href="https://github.com/sagikazarmark"><code>@​sagikazarmark</code></a> in <a href="https://redirect.github.com/spf13/cast/pull/167">spf13/cast#167</a></li>
<li>Bump github.com/frankban/quicktest from 1.14.3 to 1.14.4 by <a href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a href="https://redirect.github.com/spf13/cast/pull/168">spf13/cast#168</a></li>
<li>Add more integer to boolean conversions by <a href="https://github.com/yveshield"><code>@​yveshield</code></a> in <a href="https://redirect.github.com/spf13/cast/pull/153">spf13/cast#153</a></li>
<li>Pull the 2006-01-02 layout to the top when checking by <a href="https://github.com/bep"><code>@​bep</code></a> in <a href="https://redirect.github.com/spf13/cast/pull/187">spf13/cast#187</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/qwxingzhe"><code>@​qwxingzhe</code></a> made their first contribution in <a href="https://redirect.github.com/spf13/cast/pull/164">spf13/cast#164</a></li>
<li><a href="https://github.com/sagikazarmark"><code>@​sagikazarmark</code></a> made their first contribution in <a href="https://redirect.github.com/spf13/cast/pull/167">spf13/cast#167</a></li>
<li><a href="https://github.com/dependabot"><code>@​dependabot</code></a> made their first contribution in <a href="https://redirect.github.com/spf13/cast/pull/168">spf13/cast#168</a></li>
<li><a href="https://github.com/yveshield"><code>@​yveshield</code></a> made their first contribution in <a href="https://redirect.github.com/spf13/cast/pull/153">spf13/cast#153</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/spf13/cast/compare/v1.5.0...v1.5.1">https://github.com/spf13/cast/compare/v1.5.0...v1.5.1</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/spf13/cast/commit/bbed5559a59db54120dda79106f85f9ec0afb038"><code>bbed555</code></a> Pull the 2006-01-02 layout to the top when checking</li>
<li><a href="https://github.com/spf13/cast/commit/ba0a5b63c8972d97f400e6d235d07a2f52532f01"><code>ba0a5b6</code></a> Merge pull request <a href="https://redirect.github.com/spf13/cast/issues/153">#153</a> from yveshield/more-int-to-bool</li>
<li><a href="https://github.com/spf13/cast/commit/7ef7a1881934b25b73c11590fd9d3228aea33561"><code>7ef7a18</code></a> Bump github.com/frankban/quicktest from 1.14.3 to 1.14.4</li>
<li><a href="https://github.com/spf13/cast/commit/5959a756aff427b5c40c9932cd4c5296b77cbc1b"><code>5959a75</code></a> Merge pull request <a href="https://redirect.github.com/spf13/cast/issues/167">#167</a> from spf13/improve-ci</li>
<li><a href="https://github.com/spf13/cast/commit/1f57725177b9879b28f14ca4714679163c4e27dd"><code>1f57725</code></a> Merge pull request <a href="https://redirect.github.com/spf13/cast/issues/164">#164</a> from qwxingzhe/patch-1</li>
<li><a href="https://github.com/spf13/cast/commit/111af0b83989e6796f75cf356ae4febda185b6d1"><code>111af0b</code></a> chore: improve badges in readme</li>
<li><a href="https://github.com/spf13/cast/commit/cb4b5fb39691151d77c436ad606dfc7fbb9c56a4"><code>cb4b5fb</code></a> ci: add a name to the build</li>
<li><a href="https://github.com/spf13/cast/commit/b7b9986f2c2e97d7aee51342d4efe6ff7cb1a59e"><code>b7b9986</code></a> ci: add dependabot config</li>
<li><a href="https://github.com/spf13/cast/commit/c9c46a17924c84b0cacac50d0523ed70e41e0a41"><code>c9c46a1</code></a> ci: add Go 1.19 and 1.20 to the build matrix</li>
<li><a href="https://github.com/spf13/cast/commit/160eccf352f68a06342e3c7963f56910b4f82944"><code>160eccf</code></a> ci: general ci improvements</li>
<li>Additional commits viewable in <a href="https://github.com/spf13/cast/compare/v1.5.0...v1.5.1">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/spf13/cast&package-manager=go_modules&previous-version=1.5.0&new-version=1.5.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/go.mod b/go.mod
index a7c88a282..85d0f29b8 100644
--- a/go.mod
+++ b/go.mod
@@ -25,13 +25,13 @@ require (
 	github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20230331072320-5d6f6cfa2627
 	github.com/pkg/errors v0.9.1
 	github.com/rakyll/statik v0.1.7
-	github.com/spf13/cast v1.5.0
+	github.com/spf13/cast v1.5.1
 	github.com/spf13/cobra v1.7.0
 	github.com/spf13/pflag v1.0.5
 	github.com/spf13/viper v1.15.0
 	github.com/strangelove-ventures/async-icq/v4 v4.0.0-rc0
 	github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.5
-	github.com/stretchr/testify v1.8.2
+	github.com/stretchr/testify v1.8.3
 	github.com/tendermint/tendermint v0.34.26
 	github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b
 	github.com/tidwall/btree v1.6.0
diff --git a/go.sum b/go.sum
index 85fb44ff8..f59f480a0 100644
--- a/go.sum
+++ b/go.sum
@@ -1114,8 +1114,8 @@ github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B
 github.com/spf13/afero v1.9.3 h1:41FoI0fD7OR7mGcKE/aOiLkGreyf8ifIOQmJANWogMk=
 github.com/spf13/afero v1.9.3/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
 github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
-github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
-github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
+github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
+github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
 github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
 github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
 github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
@@ -1158,8 +1158,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
 github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
-github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
 github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
+github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
 github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
 github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=


Test patch:
diff --git a/x/gamm/keeper/export_test.go b/x/gamm/keeper/export_test.go
index 2a15cdbaa..ff9e5bd1a 100644
--- a/x/gamm/keeper/export_test.go
+++ b/x/gamm/keeper/export_test.go
@@ -29,3 +29,7 @@ func (k Keeper) UnmarshalPoolLegacy(bz []byte) (poolmanagertypes.PoolI, error) {
 	var acc poolmanagertypes.PoolI
 	return acc, k.cdc.UnmarshalInterface(bz, &acc)
 }
+
+func GetMaximalNoSwapLPAmount(ctx sdk.Context, pool types.CFMMPoolI, shareOutAmount sdk.Int) (neededLpLiquidity sdk.Coins, err error) {
+	return getMaximalNoSwapLPAmount(ctx, pool, shareOutAmount)
+}
diff --git a/x/gamm/keeper/pool_test.go b/x/gamm/keeper/pool_test.go
index 37de1be79..e4eec2b7d 100644
--- a/x/gamm/keeper/pool_test.go
+++ b/x/gamm/keeper/pool_test.go
@@ -518,6 +518,227 @@ func (s *KeeperTestSuite) TestSetStableSwapScalingFactors() {
 	}
 }
 
+func (suite *KeeperTestSuite) TestGetMaximalNoSwapLPAmount() {
+	tests := map[string]struct {
+		poolId              uint64
+		shareOutAmount      sdk.Int
+		expectedLpLiquidity sdk.Coins
+		err				error
+	}{
+		"Balancer pool: Share ratio is zero": {
+			poolId: suite.prepareCustomBalancerPool(defaultAcctFunds, defaultPoolAssets, balancer.PoolParams{
+				SwapFee: defaultSpreadFactor,
+				ExitFee: defaultZeroExitFee,
+			}),
+			shareOutAmount: sdk.ZeroInt(),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Balancer pool: Share ratio is negative": {
+			poolId: suite.prepareCustomBalancerPool(defaultAcctFunds, defaultPoolAssets, balancer.PoolParams{
+				SwapFee: defaultSpreadFactor,
+				ExitFee: defaultZeroExitFee,
+			}),
+			shareOutAmount: sdk.NewInt(-1),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Balancer pool: Pass": {
+			poolId: suite.prepareCustomBalancerPool(defaultAcctFunds, defaultPoolAssets, balancer.PoolParams{
+				SwapFee: defaultSpreadFactor,
+				ExitFee: defaultZeroExitFee,
+			}),
+
+			// totalShare:   100_000_000_000_000_000_000
+			// shareOutAmount: 8_000_000_000_000_000_000
+			// shareRatio = shareOutAmount/totalShare = 0.08
+			// Amount of tokens in poolAssets:
+			// 		- defaultPoolAssets[1].Token.Amount: 10000
+			//  	- defaultPoolAssets[0].Token.Amount: 10000
+			shareOutAmount: sdk.NewInt(8_000_000_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultPoolAssets[1].Token.Denom, 800),
+				sdk.NewInt64Coin(defaultPoolAssets[0].Token.Denom, 800),
+			},
+		},
+
+		"Balancer pool: Pass with ceiling result": {
+			poolId: suite.prepareCustomBalancerPool(defaultAcctFunds, defaultPoolAssets, balancer.PoolParams{
+				SwapFee: defaultSpreadFactor,
+				ExitFee: defaultZeroExitFee,
+			}),
+
+			// totalShare:   100_000_000_000_000_000_000
+			// shareOutAmount: 8_888_000_000_000_000_000
+			// shareRatio = shareOutAmount/totalShare = 0.08888
+			// Amount of tokens in poolAssets:
+			// 		- defaultPoolAssets[1].Token.Amount: 10000
+			//  	- defaultPoolAssets[0].Token.Amount: 10000
+			shareOutAmount: sdk.NewInt(8_888_000_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultPoolAssets[1].Token.Denom, 889),
+				sdk.NewInt64Coin(defaultPoolAssets[0].Token.Denom, 889),
+			},
+		},
+
+		"Stableswap pool: Share ratio is zero with even two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.ZeroInt(),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Stableswap pool: Share ratio is zero with uneven two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount.QuoRaw(2)), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.ZeroInt(),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Stableswap pool: Share ratio is negative with even two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.NewInt(-1),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Stableswap pool: Share ratio is negative with uneven two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount.QuoRaw(2)), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.NewInt(-1),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Stableswap pool: Pass with even two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.NewInt(8_000_000_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultAcctFunds[1].Denom, 800000),
+				sdk.NewInt64Coin(defaultAcctFunds[2].Denom, 800000),
+			},
+		},
+
+		"Stableswap pool: Pass with even two-asset, ceiling result": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			// totalShare:   100_000_000_000_000_000_000
+			// shareOutAmount: 8_888_888_000_000_000_000
+			// shareRatio = shareOutAmount/totalShare = 0.08888888
+			// Amount of tokens in liquidity:
+			// 		- defaultAcctFunds[1].Amount: 10000000
+			//  	- defaultAcctFunds[2].Amount: 10000000
+			shareOutAmount: sdk.NewInt(8_888_888_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultAcctFunds[1].Denom, 888889),
+				sdk.NewInt64Coin(defaultAcctFunds[2].Denom, 888889),
+			},
+		},
+
+		"Stableswap pool: Pass with uneven two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount.QuoRaw(2)), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.NewInt(8_000_000_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultAcctFunds[1].Denom, 400000),
+				sdk.NewInt64Coin(defaultAcctFunds[2].Denom, 800000),
+			},
+		},
+
+		"Stableswap pool: Pass with uneven two-asset, ceiling result": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount.QuoRaw(2)), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			// totalShare:   100_000_000_000_000_000_000
+			// shareOutAmount: 8_888_888_000_000_000_000
+			// shareRatio = shareOutAmount/totalShare = 0.08888888
+			// Amount of tokens in liquidity:
+			// 		- defaultAcctFunds[1].Amount: 10000000
+			//  	- defaultAcctFunds[2].Amount: 5000000
+			shareOutAmount: sdk.NewInt(8_888_888_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultAcctFunds[1].Denom, 444445),
+				sdk.NewInt64Coin(defaultAcctFunds[2].Denom, 888889),
+			},
+		},
+	}
+	for name, tc := range tests {
+		suite.Run(name, func() {
+			k := suite.App.GAMMKeeper
+
+			pool, err := k.GetPoolAndPoke(suite.Ctx, tc.poolId)
+			suite.Require().NoError(err)
+			suite.Require().Equal(tc.poolId, pool.GetId())
+
+			neededLpLiquidity, err := keeper.GetMaximalNoSwapLPAmount(suite.Ctx, pool, tc.shareOutAmount)
+			if tc.err != nil {
+				suite.Require().Error(err)
+				msgError := fmt.Sprintf("Too few shares out wanted. (debug: getMaximalNoSwapLPAmount share ratio is zero or negative): %s", tc.err)
+				suite.Require().EqualError(err, msgError)
+			} else {
+				suite.Require().NoError(err)
+				suite.Require().Equal(neededLpLiquidity, tc.expectedLpLiquidity)
+			}
+
+		})
+	}
+}
+
 func (suite *KeeperTestSuite) TestGetTotalPoolShares() {
 	tests := map[string]struct {
 		sharesJoined   sdk.Int