Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions x/clp/keeper/calculations.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ func CalculateWithdrawal(poolUnits sdk.Uint, nativeAssetDepth string,
//if asymmetry is 0 we don't need to swap
lpUnitsLeft := lpUnitsF.Sub(unitsToClaim)

return sdk.NewUintFromBigInt(withdrawNativeAssetAmount.RoundInt().BigInt()),
sdk.NewUintFromBigInt(withdrawExternalAssetAmount.RoundInt().BigInt()),
sdk.NewUintFromBigInt(lpUnitsLeft.RoundInt().BigInt()),
sdk.NewUintFromBigInt(swapAmount.RoundInt().BigInt())
return sdk.NewUintFromBigInt(withdrawNativeAssetAmount.TruncateInt().BigInt()),
sdk.NewUintFromBigInt(withdrawExternalAssetAmount.TruncateInt().BigInt()),
sdk.NewUintFromBigInt(lpUnitsLeft.TruncateInt().BigInt()),
sdk.NewUintFromBigInt(swapAmount.TruncateInt().BigInt())
}

// More details on the formula
Expand Down
120 changes: 60 additions & 60 deletions x/clp/keeper/calculations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1389,13 +1389,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.OneDec(),
swapResult: sdk.NewUint(181),
swapResult: sdk.NewUint(180),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(817),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(818),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand Down Expand Up @@ -1463,7 +1463,7 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(953),
ExternalAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(1097),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand Down Expand Up @@ -1494,7 +1494,7 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(908),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
Expand Down Expand Up @@ -1526,7 +1526,7 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(899),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
Expand All @@ -1553,13 +1553,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("0.2"),
swapResult: sdk.NewUint(109),
swapResult: sdk.NewUint(108),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(889),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(890),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1585,13 +1585,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("0.3"),
swapResult: sdk.NewUint(118),
swapResult: sdk.NewUint(117),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(880),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(881),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1617,13 +1617,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("0.4"),
swapResult: sdk.NewUint(127),
swapResult: sdk.NewUint(126),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(871),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(872),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1649,13 +1649,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("0.5"),
swapResult: sdk.NewUint(136),
swapResult: sdk.NewUint(135),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(862),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(863),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1681,13 +1681,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("0.6"),
swapResult: sdk.NewUint(145),
swapResult: sdk.NewUint(144),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(853),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(854),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1713,13 +1713,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("0.7"),
swapResult: sdk.NewUint(154),
swapResult: sdk.NewUint(153),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(844),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(845),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1745,13 +1745,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("0.8"),
swapResult: sdk.NewUint(163),
swapResult: sdk.NewUint(162),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(835),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(836),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1777,13 +1777,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("0.9"),
swapResult: sdk.NewUint(172),
swapResult: sdk.NewUint(171),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(826),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(827),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1809,13 +1809,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("1.0"),
swapResult: sdk.NewUint(181),
swapResult: sdk.NewUint(180),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(817),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(818),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1841,13 +1841,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("2.0"),
swapResult: sdk.NewUint(272),
swapResult: sdk.NewUint(270),
liquidityFee: sdk.NewUint(0),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(726),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(728),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1873,13 +1873,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("3.0"),
swapResult: sdk.NewUint(362),
swapResult: sdk.NewUint(359),
liquidityFee: sdk.NewUint(1),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(636),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(639),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1905,13 +1905,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("4.0"),
swapResult: sdk.NewUint(453),
swapResult: sdk.NewUint(449),
liquidityFee: sdk.NewUint(1),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(545),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(549),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1937,13 +1937,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("5.0"),
swapResult: sdk.NewUint(544),
swapResult: sdk.NewUint(539),
liquidityFee: sdk.NewUint(1),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(454),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(459),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -1969,13 +1969,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("6.0"),
swapResult: sdk.NewUint(635),
swapResult: sdk.NewUint(629),
liquidityFee: sdk.NewUint(1),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(363),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(369),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -2001,13 +2001,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("7.0"),
swapResult: sdk.NewUint(725),
swapResult: sdk.NewUint(718),
liquidityFee: sdk.NewUint(2),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(273),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(280),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -2033,13 +2033,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("8.0"),
swapResult: sdk.NewUint(816),
swapResult: sdk.NewUint(808),
liquidityFee: sdk.NewUint(2),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(182),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(190),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -2065,13 +2065,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("9.0"),
swapResult: sdk.NewUint(906),
swapResult: sdk.NewUint(898),
liquidityFee: sdk.NewUint(2),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(92),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(100),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand All @@ -2097,13 +2097,13 @@ func TestKeeper_SwapOneFromGenesis(t *testing.T) {
wBasis: sdk.NewInt(1000),
asymmetry: sdk.NewInt(10000),
pmtpCurrentRunningRate: sdk.MustNewDecFromStr("10.0"),
swapResult: sdk.NewUint(997),
swapResult: sdk.NewUint(988),
liquidityFee: sdk.NewUint(2),
priceImpact: sdk.ZeroUint(),
expectedPool: types.Pool{
ExternalAsset: &types.Asset{Symbol: "eth"},
NativeAssetBalance: sdk.NewUint(1098),
ExternalAssetBalance: sdk.NewUint(1),
NativeAssetBalance: sdk.NewUint(1097),
ExternalAssetBalance: sdk.NewUint(10),
PoolUnits: sdk.NewUint(998),
NativeCustody: sdk.ZeroUint(),
ExternalCustody: sdk.ZeroUint(),
Expand Down