-
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.
remove all cross dependency in accountedpool keeper
- Loading branch information
1 parent
fa3f3df
commit 2439e94
Showing
24 changed files
with
283 additions
and
80 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
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 |
---|---|---|
|
@@ -47,7 +47,6 @@ func IncentiveKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { | |
nil, | ||
nil, | ||
nil, | ||
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
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,80 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
simapp "github.com/elys-network/elys/app" | ||
ammtypes "github.com/elys-network/elys/x/amm/types" | ||
|
||
"github.com/elys-network/elys/x/accountedpool/types" | ||
margintypes "github.com/elys-network/elys/x/margin/types" | ||
ptypes "github.com/elys-network/elys/x/parameter/types" | ||
) | ||
|
||
func TestAccountedPoolUpdate(t *testing.T) { | ||
app := simapp.InitElysTestApp(true) | ||
ctx := app.BaseApp.NewContext(true, tmproto.Header{}) | ||
|
||
apk := app.AccountedPoolKeeper | ||
|
||
// Generate 1 random account with 1000stake balanced | ||
addr := simapp.AddTestAddrs(app, ctx, 1, sdk.NewInt(1000000)) | ||
|
||
// Initiate pool | ||
ammPool := ammtypes.Pool{ | ||
PoolId: 0, | ||
Address: addr[0].String(), | ||
PoolParams: ammtypes.PoolParams{}, | ||
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))}, | ||
}, | ||
TotalWeight: sdk.NewInt(100), | ||
RebalanceTreasury: addr[0].String(), | ||
} | ||
// Initiate pool | ||
accountedPool := types.AccountedPool{ | ||
PoolId: 0, | ||
TotalShares: ammPool.TotalShares, | ||
PoolAssets: []ammtypes.PoolAsset{}, | ||
TotalWeight: ammPool.TotalWeight, | ||
} | ||
|
||
for _, asset := range ammPool.PoolAssets { | ||
accountedPool.PoolAssets = append(accountedPool.PoolAssets, asset) | ||
} | ||
// Set accounted pool | ||
apk.SetAccountedPool(ctx, accountedPool) | ||
|
||
marginPool := margintypes.Pool{ | ||
AmmPoolId: 0, | ||
Health: sdk.NewDec(1), | ||
Enabled: true, | ||
Closed: false, | ||
InterestRate: sdk.NewDec(1), | ||
PoolAssets: []margintypes.PoolAsset{ | ||
{ | ||
Liabilities: sdk.NewInt(400), | ||
Custody: sdk.NewInt(0), | ||
AssetBalance: sdk.NewInt(100), | ||
UnsettledLiabilities: sdk.NewInt(0), | ||
BlockInterest: sdk.NewInt(0), | ||
AssetDenom: ptypes.USDC, | ||
}, | ||
{ | ||
Liabilities: sdk.NewInt(50), | ||
Custody: sdk.NewInt(0), | ||
AssetBalance: sdk.NewInt(0), | ||
UnsettledLiabilities: sdk.NewInt(0), | ||
BlockInterest: sdk.NewInt(0), | ||
AssetDenom: ptypes.ATOM, | ||
}, | ||
}, | ||
} | ||
// Update accounted pool | ||
apk.UpdateAccountedPool(ctx, ammPool, marginPool) | ||
|
||
} |
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,22 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/elys-network/elys/x/amm/types" | ||
) | ||
|
||
// SwapInAmtGivenOut is a mutative method for CalcOutAmtGivenIn, which includes the actual swap. | ||
func (k Keeper) SwapInAmtGivenOut( | ||
ctx sdk.Context, poolId uint64, oracleKeeper types.OracleKeeper, snapshot *types.Pool, | ||
tokensOut sdk.Coins, tokenInDenom string, swapFee sdk.Dec) ( | ||
tokenIn sdk.Coin, weightBalanceBonus sdk.Dec, err error, | ||
) { | ||
ammPool, found := k.GetPool(ctx, poolId) | ||
if !found { | ||
return sdk.Coin{}, sdk.ZeroDec(), fmt.Errorf("invalid pool: %d", poolId) | ||
} | ||
|
||
return ammPool.SwapInAmtGivenOut(ctx, oracleKeeper, snapshot, tokensOut, tokenInDenom, swapFee, k.accountedPoolKeeper) | ||
} |
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,25 @@ | ||
package keeper | ||
|
||
import ( | ||
fmt "fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/elys-network/elys/x/amm/types" | ||
) | ||
|
||
// SwapOutAmtGivenIn is a mutative method for CalcOutAmtGivenIn, which includes the actual swap. | ||
func (k Keeper) SwapOutAmtGivenIn( | ||
ctx sdk.Context, poolId uint64, | ||
oracleKeeper types.OracleKeeper, | ||
snapshot *types.Pool, | ||
tokensIn sdk.Coins, | ||
tokenOutDenom string, | ||
swapFee sdk.Dec, | ||
) (tokenOut sdk.Coin, weightBalanceBonus sdk.Dec, err error) { | ||
ammPool, found := k.GetPool(ctx, poolId) | ||
if !found { | ||
return sdk.Coin{}, sdk.ZeroDec(), fmt.Errorf("invalid pool: %d", poolId) | ||
} | ||
|
||
return ammPool.SwapOutAmtGivenIn(ctx, oracleKeeper, snapshot, tokensIn, tokenOutDenom, swapFee, k.accountedPoolKeeper) | ||
} |
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
Oops, something went wrong.