-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support single side liquidity addition & add example scripts for test
- Loading branch information
Showing
12 changed files
with
272 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
TREASURY=$(elysd keys show -a treasury --keyring-backend=test) | ||
|
||
elysd tx amm create-pool 10uatom,10uusdt 10000uatom,10000uusdt 0.00 0.00 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 | ||
|
||
# single asset add-liquidity | ||
elysd tx amm join-pool 0 2000uatom 90000000000000000 true --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 | ||
# multiple asset add-liquidity | ||
elysd tx amm join-pool 0 2000uatom,2000uusdt 200000000000000000 true --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 | ||
|
||
# swap | ||
elysd tx amm swap-exact-amount-in 10uatom 1 0 uusdt --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 | ||
|
||
elysd query commitment show-commitments $TREASURY | ||
elysd query bank balances $TREASURY | ||
elysd query amm show-pool 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package types | ||
|
||
import ( | ||
"errors" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// calcPoolOutGivenSingleIn - balance pAo. | ||
func (p *Pool) calcSingleAssetJoin(tokenIn sdk.Coin, spreadFactor sdk.Dec, tokenInPoolAsset PoolAsset, totalShares sdk.Int) (numShares sdk.Int, err error) { | ||
totalWeight := p.TotalWeight | ||
if totalWeight.IsZero() { | ||
return sdk.ZeroInt(), errors.New("pool misconfigured, total weight = 0") | ||
} | ||
normalizedWeight := sdk.NewDecFromInt(tokenInPoolAsset.Weight).Quo(sdk.NewDecFromInt(totalWeight)) | ||
return calcPoolSharesOutGivenSingleAssetIn( | ||
sdk.NewDecFromInt(tokenInPoolAsset.Token.Amount), | ||
normalizedWeight, | ||
sdk.NewDecFromInt(totalShares), | ||
sdk.NewDecFromInt(tokenIn.Amount), | ||
spreadFactor, | ||
).TruncateInt(), nil | ||
} | ||
|
||
// CalcJoinPoolShares calculates the number of shares created to join pool with the provided amount of `tokenIn`. | ||
// The input tokens must either be: | ||
// - a single token | ||
// - contain exactly the same tokens as the pool contains | ||
// | ||
// It returns the number of shares created, the amount of coins actually joined into the pool | ||
// (in case of not being able to fully join), or an error. | ||
func (p *Pool) CalcSingleAssetJoinPoolShares(tokensIn sdk.Coins) (numShares sdk.Int, tokensJoined sdk.Coins, err error) { | ||
// get all 'pool assets' (aka current pool liquidity + balancer weight) | ||
poolAssetsByDenom, err := GetPoolAssetsByDenom(p.GetAllPoolAssets()) | ||
if err != nil { | ||
return sdk.ZeroInt(), sdk.NewCoins(), err | ||
} | ||
|
||
err = EnsureDenomInPool(poolAssetsByDenom, tokensIn) | ||
if err != nil { | ||
return sdk.ZeroInt(), sdk.NewCoins(), err | ||
} | ||
|
||
// ensure that there aren't too many or too few assets in `tokensIn` | ||
if tokensIn.Len() != 1 { | ||
return sdk.ZeroInt(), sdk.NewCoins(), errors.New("pool only supports LP'ing with one asset") | ||
} | ||
|
||
// 2) Single token provided, so do single asset join and exit. | ||
totalShares := p.GetTotalShares() | ||
numShares, err = p.calcSingleAssetJoin(tokensIn[0], p.PoolParams.SwapFee, poolAssetsByDenom[tokensIn[0].Denom], totalShares.Amount) | ||
if err != nil { | ||
return sdk.ZeroInt(), sdk.NewCoins(), err | ||
} | ||
// we join all the tokens. | ||
tokensJoined = tokensIn | ||
return numShares, tokensJoined, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.