Skip to content

Commit

Permalink
fix(app): fix initialization of transferKeeper for x/rollapp (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Nov 17, 2024
1 parent c0774fc commit b8a69b8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
8 changes: 4 additions & 4 deletions app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
// 10^18 multiplier
var EXP = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))

// Default sender for amm messages
var sender = sdk.MustAccAddressFromBech32(alice)
// Default Sender for amm messages
var Sender = sdk.MustAccAddressFromBech32(alice)

var DefaultAcctFunds sdk.Coins = sdk.NewCoins(
sdk.NewCoin("adym", EXP.Mul(sdk.NewInt(1_000_000))),
Expand Down Expand Up @@ -45,9 +45,9 @@ var DefaultPoolAssets = []balancer.PoolAsset{
// This is the generic method called by other PreparePool wrappers
// It funds the sender account with DefaultAcctFunds
func (s *KeeperTestHelper) PrepareCustomPool(assets []balancer.PoolAsset, params balancer.PoolParams) uint64 {
s.FundAcc(sender, DefaultAcctFunds)
s.FundAcc(Sender, DefaultAcctFunds)

msg := balancer.NewMsgCreateBalancerPool(sender, params, assets, "")
msg := balancer.NewMsgCreateBalancerPool(Sender, params, assets, "")
poolId, err := s.App.PoolManagerKeeper.CreatePool(s.Ctx, msg)
s.NoError(err)
return poolId
Expand Down
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ func (a *AppKeepers) InitKeepers(
a.BankKeeper,
a.ScopedTransferKeeper,
)
a.RollappKeeper.SetTransferKeeper(a.TransferKeeper)

a.DelayedAckKeeper = *delayedackkeeper.NewKeeper(
appCodec,
Expand Down
14 changes: 8 additions & 6 deletions x/gamm/amm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ func (s *KeeperTestSuite) SetupTest() {

func (s *KeeperTestSuite) TestSwapsRevenue() {
// Create a pool with 100_000 DYM and 100_000 FOO
fooDenom := "ibc/A88EE35932B15B981676EFA6700342EDEF63C41C9EE1265EA5BEDAE0A6518CEA"
poolCoins := sdk.NewCoins(
sdk.NewCoin("adym", apptesting.EXP.Mul(sdk.NewInt(100_000))),
sdk.NewCoin("foo", apptesting.EXP.Mul(sdk.NewInt(100_000))),
sdk.NewCoin(fooDenom, apptesting.EXP.Mul(sdk.NewInt(100_000))),
)

testCases := []struct {
Expand Down Expand Up @@ -78,14 +79,15 @@ func (s *KeeperTestSuite) TestSwapsRevenue() {
params.TakerFee = tc.takerFee
s.App.GAMMKeeper.SetParams(s.Ctx, params)

s.FundAcc(apptesting.Sender, apptesting.DefaultAcctFunds.Add(sdk.NewCoin(fooDenom, apptesting.EXP.Mul(sdk.NewInt(1_000_000)))))
poolId := s.PrepareCustomPoolFromCoins(poolCoins, balancer.PoolParams{
SwapFee: tc.swapFee,
ExitFee: sdk.ZeroDec(),
})

// join pool
addr := sample.Acc()
s.FundAcc(addr, apptesting.DefaultAcctFunds)
s.FundAcc(addr, apptesting.DefaultAcctFunds.Add(sdk.NewCoin(fooDenom, apptesting.EXP.Mul(sdk.NewInt(1_000_000)))))
shares, _ := s.RunBasicJoin(poolId, addr.String())

// check position
Expand All @@ -94,21 +96,21 @@ func (s *KeeperTestSuite) TestSwapsRevenue() {
position, err := pool.CalcExitPoolCoinsFromShares(s.Ctx, shares, sdk.ZeroDec())
s.Require().NoError(err)
liquidity := pool.GetTotalPoolLiquidity(s.Ctx)
spot, err := s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "foo", "adym")
spot, err := s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, fooDenom, "adym")
s.Require().NoError(err)
s.T().Logf("positionBefore: %s, liquidity: %s, spot: %s", position, liquidity, spot)

// swap tokens (swap 5 DYM for FOO) and vice versa
s.RunBasicSwap(poolId, addr.String(), sdk.NewCoin("adym", apptesting.EXP.Mul(sdk.NewInt(5))), "foo")
s.RunBasicSwap(poolId, addr.String(), sdk.NewCoin("foo", apptesting.EXP.Mul(sdk.NewInt(5))), "adym")
s.RunBasicSwap(poolId, addr.String(), sdk.NewCoin("adym", apptesting.EXP.Mul(sdk.NewInt(5))), fooDenom)
s.RunBasicSwap(poolId, addr.String(), sdk.NewCoin(fooDenom, apptesting.EXP.Mul(sdk.NewInt(5))), "adym")

// check position
p, _ = s.App.GAMMKeeper.GetPool(s.Ctx, poolId)
pool = p.(*balancer.Pool) // nolint: errcheck
liquidity = pool.GetTotalPoolLiquidity(s.Ctx)
positionAfter, err := pool.CalcExitPoolCoinsFromShares(s.Ctx, shares, sdk.ZeroDec())
s.Require().NoError(err)
spot, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, "foo", "adym")
spot, err = s.App.GAMMKeeper.CalculateSpotPrice(s.Ctx, poolId, fooDenom, "adym")
s.Require().NoError(err)
s.T().Logf("positionAfterSwap: %s, liquidity: %s, spot: %s", positionAfter, liquidity, spot)

Expand Down
4 changes: 4 additions & 0 deletions x/rollapp/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (k *Keeper) SetCanonicalClientKeeper(kk CanonicalLightClientKeeper) {
k.canonicalClientKeeper = kk
}

func (k *Keeper) SetTransferKeeper(transferKeeper TransferKeeper) {
k.transferKeeper = transferKeeper
}

/* -------------------------------------------------------------------------- */
/* Hooks */
/* -------------------------------------------------------------------------- */
Expand Down

0 comments on commit b8a69b8

Please sign in to comment.